Compare commits

...

12 Commits

Author SHA1 Message Date
Kit Langton 8965ca5dd1 Merge branch 'v2' into skill-attachments 2026-08-07 23:33:06 -04:00
Kit Langton c9e9bb808c fix(tui): preserve leading skill attachments 2026-08-07 23:31:50 -04:00
Kit Langton 9b7b402737 feat(server): run modal sandboxes on the vm runtime (#41177) 2026-08-07 23:21:05 -04:00
Kit Langton 7dd275a196 refactor(core): simplify skill attachment admission 2026-08-07 23:20:33 -04:00
Kit Langton 405ea2fcc8 fix: preserve skill attachment semantics 2026-08-07 23:13:41 -04:00
James Long 5e6370363b fix(tui): refine provider failure presentation (#41179) 2026-08-07 23:11:32 -04:00
Kit Langton 574b11617d feat(tui): autocomplete inline skills 2026-08-07 23:01:33 -04:00
Kit Langton dd6020656e fix(merman): tighten flowchart spacing (#41191) 2026-08-07 23:00:44 -04:00
Kit Langton 8c758e443b fix(core): reuse shared patch diff (#41186) 2026-08-07 22:50:59 -04:00
Kit Langton 56ef6eee24 feat: attach skills to prompts 2026-08-07 22:47:39 -04:00
Kit Langton 0df6aed6ca fix(merman): derive neutral diagram palette (#41181) 2026-08-07 22:43:58 -04:00
Kit Langton aa05fd23b3 refactor(core): remove legacy account runtime schemas (#41173) 2026-08-07 22:40:53 -04:00
48 changed files with 1148 additions and 327 deletions
+14 -2
View File
@@ -1,4 +1,4 @@
import { Cause, Context, Effect, Layer } from "effect"
import { Cause, Context, Effect, Layer, Option, Schema } from "effect"
import {
FetchHttpClient,
Headers,
@@ -198,8 +198,20 @@ const responseBody = (body: string | void, request: HttpClientRequest.HttpClient
return { body: redacted.slice(0, BODY_LIMIT), bodyTruncated: true }
}
const decodeProviderBody = Schema.decodeUnknownOption(
Schema.fromJsonString(
Schema.Struct({
message: Schema.optionalKey(Schema.String),
error: Schema.optionalKey(Schema.Struct({ message: Schema.optionalKey(Schema.String) })),
}),
),
)
const providerMessage = (status: number, body: { readonly body?: string }) => {
if (body.body && body.body.length <= 500) return `Provider request failed with HTTP ${status}: ${body.body}`
if (body.body && body.body.length <= 500) {
const decoded = Option.getOrUndefined(decodeProviderBody(body.body))
return `Provider request failed with HTTP ${status}: ${decoded?.error?.message ?? decoded?.message ?? body.body}`
}
return `Provider request failed with HTTP ${status}`
}
+2
View File
@@ -180,6 +180,7 @@ export type Endpoint5_12Input = {
readonly text: string
readonly files?: ReadonlyArray<PromptInput.FileAttachment> | undefined
readonly agents?: ReadonlyArray<AgentAttachment> | undefined
readonly skills?: ReadonlyArray<PromptInput.SkillAttachment> | undefined
readonly metadata?: { readonly [x: string]: unknown } | undefined
readonly delivery?: "steer" | "queue" | undefined
readonly resume?: boolean | undefined
@@ -196,6 +197,7 @@ export type Endpoint5_13Input = {
readonly model?: Model.Ref | undefined
readonly files?: ReadonlyArray<PromptInput.FileAttachment> | undefined
readonly agents?: ReadonlyArray<AgentAttachment> | undefined
readonly skills?: ReadonlyArray<PromptInput.SkillAttachment> | undefined
readonly delivery?: "steer" | "queue" | undefined
readonly resume?: boolean | undefined
}
@@ -412,6 +412,7 @@ const Endpoint5_12 = (raw: RawClient["server.session"]) => (input: Endpoint5_12I
text: input["text"],
files: input["files"],
agents: input["agents"],
skills: input["skills"],
metadata: input["metadata"],
delivery: input["delivery"],
resume: input["resume"],
@@ -434,6 +435,7 @@ const Endpoint5_13 = (raw: RawClient["server.session"]) => (input: Endpoint5_13I
model: input["model"],
files: input["files"],
agents: input["agents"],
skills: input["skills"],
delivery: input["delivery"],
resume: input["resume"],
},
@@ -615,6 +615,7 @@ export function make(options: ClientOptions) {
text: input["text"],
files: input["files"],
agents: input["agents"],
skills: input["skills"],
metadata: input["metadata"],
delivery: input["delivery"],
resume: input["resume"],
@@ -638,6 +639,7 @@ export function make(options: ClientOptions) {
model: input["model"],
files: input["files"],
agents: input["agents"],
skills: input["skills"],
delivery: input["delivery"],
resume: input["resume"],
},
@@ -1080,6 +1080,8 @@ export type PromptFileAttachment = {
export type PromptAgentAttachment = { name: string; mention?: PromptMention }
export type PromptSkillAttachment = { id: string; name: string; text: string; mention?: PromptMention }
export type SessionMessageAssistantText = { type: "text"; text: string; state?: SessionMessageProviderState }
export type SessionMessageAssistantReasoning = {
@@ -1565,6 +1567,7 @@ export type SessionMessageUser = {
text: string
files?: Array<PromptFileAttachment>
agents?: Array<PromptAgentAttachment>
skills?: Array<PromptSkillAttachment>
type: "user"
}
@@ -1572,6 +1575,7 @@ export type SessionPendingUserData = {
text: string
files?: Array<PromptFileAttachment>
agents?: Array<PromptAgentAttachment>
skills?: Array<PromptSkillAttachment>
metadata?: { [x: string]: JsonValue }
}
@@ -1579,6 +1583,7 @@ export type SessionPendingUserData1 = {
text: string
files?: Array<PromptFileAttachment>
agents?: Array<PromptAgentAttachment>
skills?: Array<PromptSkillAttachment>
metadata?: { [x: string]: any }
}
@@ -2579,6 +2584,12 @@ export type SessionImportInput = {
readonly name: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly skills?: ReadonlyArray<{
readonly id: string
readonly name: string
readonly text: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly type: "user"
}
| {
@@ -2824,6 +2835,12 @@ export type SessionImportInput = {
readonly name: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly skills?: ReadonlyArray<{
readonly id: string
readonly name: string
readonly text: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly type: "user"
}
| {
@@ -3069,6 +3086,12 @@ export type SessionImportInput = {
readonly name: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly skills?: ReadonlyArray<{
readonly id: string
readonly name: string
readonly text: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly type: "user"
}
| {
@@ -3320,6 +3343,10 @@ export type SessionPromptInput = {
readonly name: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly skills?: ReadonlyArray<{
readonly id: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly metadata?: { readonly [x: string]: JsonValue }
readonly delivery?: "steer" | "queue" | null
readonly resume?: boolean | null
@@ -3337,6 +3364,10 @@ export type SessionPromptInput = {
readonly name: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly skills?: ReadonlyArray<{
readonly id: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly metadata?: { readonly [x: string]: JsonValue }
readonly delivery?: "steer" | "queue" | null
readonly resume?: boolean | null
@@ -3354,6 +3385,10 @@ export type SessionPromptInput = {
readonly name: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly skills?: ReadonlyArray<{
readonly id: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly metadata?: { readonly [x: string]: JsonValue }
readonly delivery?: "steer" | "queue" | null
readonly resume?: boolean | null
@@ -3371,10 +3406,35 @@ export type SessionPromptInput = {
readonly name: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly skills?: ReadonlyArray<{
readonly id: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly metadata?: { readonly [x: string]: JsonValue }
readonly delivery?: "steer" | "queue" | null
readonly resume?: boolean | null
}["agents"]
readonly skills?: {
readonly id?: string | null
readonly text: string
readonly files?: ReadonlyArray<{
readonly uri: string
readonly name?: string
readonly description?: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly agents?: ReadonlyArray<{
readonly name: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly skills?: ReadonlyArray<{
readonly id: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly metadata?: { readonly [x: string]: JsonValue }
readonly delivery?: "steer" | "queue" | null
readonly resume?: boolean | null
}["skills"]
readonly metadata?: {
readonly id?: string | null
readonly text: string
@@ -3388,6 +3448,10 @@ export type SessionPromptInput = {
readonly name: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly skills?: ReadonlyArray<{
readonly id: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly metadata?: { readonly [x: string]: JsonValue }
readonly delivery?: "steer" | "queue" | null
readonly resume?: boolean | null
@@ -3405,6 +3469,10 @@ export type SessionPromptInput = {
readonly name: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly skills?: ReadonlyArray<{
readonly id: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly metadata?: { readonly [x: string]: JsonValue }
readonly delivery?: "steer" | "queue" | null
readonly resume?: boolean | null
@@ -3422,6 +3490,10 @@ export type SessionPromptInput = {
readonly name: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly skills?: ReadonlyArray<{
readonly id: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly metadata?: { readonly [x: string]: JsonValue }
readonly delivery?: "steer" | "queue" | null
readonly resume?: boolean | null
@@ -3448,6 +3520,10 @@ export type SessionCommandInput = {
readonly name: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly skills?: ReadonlyArray<{
readonly id: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly delivery?: "steer" | "queue" | null
readonly resume?: boolean | null
}["id"]
@@ -3467,6 +3543,10 @@ export type SessionCommandInput = {
readonly name: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly skills?: ReadonlyArray<{
readonly id: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly delivery?: "steer" | "queue" | null
readonly resume?: boolean | null
}["command"]
@@ -3486,6 +3566,10 @@ export type SessionCommandInput = {
readonly name: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly skills?: ReadonlyArray<{
readonly id: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly delivery?: "steer" | "queue" | null
readonly resume?: boolean | null
}["arguments"]
@@ -3505,6 +3589,10 @@ export type SessionCommandInput = {
readonly name: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly skills?: ReadonlyArray<{
readonly id: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly delivery?: "steer" | "queue" | null
readonly resume?: boolean | null
}["agent"]
@@ -3524,6 +3612,10 @@ export type SessionCommandInput = {
readonly name: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly skills?: ReadonlyArray<{
readonly id: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly delivery?: "steer" | "queue" | null
readonly resume?: boolean | null
}["model"]
@@ -3543,6 +3635,10 @@ export type SessionCommandInput = {
readonly name: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly skills?: ReadonlyArray<{
readonly id: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly delivery?: "steer" | "queue" | null
readonly resume?: boolean | null
}["files"]
@@ -3562,9 +3658,36 @@ export type SessionCommandInput = {
readonly name: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly skills?: ReadonlyArray<{
readonly id: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly delivery?: "steer" | "queue" | null
readonly resume?: boolean | null
}["agents"]
readonly skills?: {
readonly id?: string | null
readonly command: string
readonly arguments?: string | null
readonly agent?: string | null
readonly model?: { readonly id: string; readonly providerID: string; readonly variant?: string } | null
readonly files?: ReadonlyArray<{
readonly uri: string
readonly name?: string
readonly description?: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly agents?: ReadonlyArray<{
readonly name: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly skills?: ReadonlyArray<{
readonly id: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly delivery?: "steer" | "queue" | null
readonly resume?: boolean | null
}["skills"]
readonly delivery?: {
readonly id?: string | null
readonly command: string
@@ -3581,6 +3704,10 @@ export type SessionCommandInput = {
readonly name: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly skills?: ReadonlyArray<{
readonly id: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly delivery?: "steer" | "queue" | null
readonly resume?: boolean | null
}["delivery"]
@@ -3600,6 +3727,10 @@ export type SessionCommandInput = {
readonly name: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly skills?: ReadonlyArray<{
readonly id: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly delivery?: "steer" | "queue" | null
readonly resume?: boolean | null
}["resume"]
-101
View File
@@ -1,101 +0,0 @@
export * as Account from "./account"
import { Schema } from "effect"
import type { HttpClientError } from "effect/unstable/http"
export const ID = Schema.String.pipe(Schema.brand("AccountID"))
export type ID = Schema.Schema.Type<typeof ID>
export const OrgID = Schema.String.pipe(Schema.brand("OrgID"))
export type OrgID = Schema.Schema.Type<typeof OrgID>
export const AccessToken = Schema.String.pipe(Schema.brand("AccessToken"))
export type AccessToken = Schema.Schema.Type<typeof AccessToken>
export const RefreshToken = Schema.String.pipe(Schema.brand("RefreshToken"))
export type RefreshToken = Schema.Schema.Type<typeof RefreshToken>
export const DeviceCode = Schema.String.pipe(Schema.brand("DeviceCode"))
export type DeviceCode = Schema.Schema.Type<typeof DeviceCode>
export const UserCode = Schema.String.pipe(Schema.brand("UserCode"))
export type UserCode = Schema.Schema.Type<typeof UserCode>
export class Info extends Schema.Class<Info>("Account")({
id: ID,
email: Schema.String,
url: Schema.String,
active_org_id: Schema.NullOr(OrgID),
}) {}
export class Org extends Schema.Class<Org>("Org")({
id: OrgID,
name: Schema.String,
}) {}
export class AccountRepoError extends Schema.TaggedErrorClass<AccountRepoError>()("AccountRepoError", {
message: Schema.String,
cause: Schema.optional(Schema.Defect()),
}) {}
export class AccountServiceError extends Schema.TaggedErrorClass<AccountServiceError>()("AccountServiceError", {
message: Schema.String,
cause: Schema.optional(Schema.Defect()),
}) {}
export class AccountTransportError extends Schema.TaggedErrorClass<AccountTransportError>()("AccountTransportError", {
method: Schema.String,
url: Schema.String,
description: Schema.optional(Schema.String),
cause: Schema.optional(Schema.Defect()),
}) {
static fromHttpClientError(error: HttpClientError.TransportError): AccountTransportError {
return new AccountTransportError({
method: error.request.method,
url: error.request.url,
description: error.description,
cause: error.cause,
})
}
override get message(): string {
return [
`Could not reach ${this.method} ${this.url}.`,
`This failed before the server returned an HTTP response.`,
this.description,
`Check your network, proxy, or VPN configuration and try again.`,
]
.filter(Boolean)
.join("\n")
}
}
export type AccountError = AccountRepoError | AccountServiceError | AccountTransportError
export class Login extends Schema.Class<Login>("Login")({
code: DeviceCode,
user: UserCode,
url: Schema.String,
server: Schema.String,
expiry: Schema.Duration,
interval: Schema.Duration,
}) {}
export class PollSuccess extends Schema.TaggedClass<PollSuccess>()("PollSuccess", {
email: Schema.String,
}) {}
export class PollPending extends Schema.TaggedClass<PollPending>()("PollPending", {}) {}
export class PollSlow extends Schema.TaggedClass<PollSlow>()("PollSlow", {}) {}
export class PollExpired extends Schema.TaggedClass<PollExpired>()("PollExpired", {}) {}
export class PollDenied extends Schema.TaggedClass<PollDenied>()("PollDenied", {}) {}
export class PollError extends Schema.TaggedClass<PollError>()("PollError", {
cause: Schema.Defect(),
}) {}
export const PollResult = Schema.Union([PollSuccess, PollPending, PollSlow, PollExpired, PollDenied, PollError])
export type PollResult = Schema.Schema.Type<typeof PollResult>
+7 -10
View File
@@ -1,24 +1,21 @@
import { sqliteTable, text, integer, primaryKey } from "drizzle-orm/sqlite-core"
import { Account } from "../account"
import { Timestamps } from "../database/schema.sql"
export const AccountTable = sqliteTable("account", {
id: text().$type<Account.ID>().primaryKey(),
id: text().primaryKey(),
email: text().notNull(),
url: text().notNull(),
access_token: text().$type<Account.AccessToken>().notNull(),
refresh_token: text().$type<Account.RefreshToken>().notNull(),
access_token: text().notNull(),
refresh_token: text().notNull(),
token_expiry: integer(),
...Timestamps,
})
export const AccountStateTable = sqliteTable("account_state", {
id: integer().primaryKey(),
active_account_id: text()
.$type<Account.ID>()
.references(() => AccountTable.id, { onDelete: "set null" }),
active_org_id: text().$type<Account.OrgID>(),
active_account_id: text().references(() => AccountTable.id, { onDelete: "set null" }),
active_org_id: text(),
})
// LEGACY
@@ -27,8 +24,8 @@ export const ControlAccountTable = sqliteTable(
{
email: text().notNull(),
url: text().notNull(),
access_token: text().$type<Account.AccessToken>().notNull(),
refresh_token: text().$type<Account.RefreshToken>().notNull(),
access_token: text().notNull(),
refresh_token: text().notNull(),
token_expiry: integer(),
active: integer({ mode: "boolean" })
.notNull()
+3
View File
@@ -11,6 +11,7 @@ import { Provider } from "@opencode-ai/schema/provider"
import { AbsolutePath } from "@opencode-ai/schema/schema"
import { Session } from "@opencode-ai/schema/session"
import { SessionMessage } from "@opencode-ai/schema/session-message"
import { Skill } from "@opencode-ai/schema/skill"
import { Workspace } from "@opencode-ai/schema/workspace"
import { WebSearch } from "@opencode-ai/schema/websearch"
import { DateTime, Effect, Scope, Stream } from "effect"
@@ -296,6 +297,7 @@ export function fromPromise(plugin: Plugin) {
...input,
sessionID: Session.ID.make(input.sessionID),
id: input.id == null ? undefined : SessionMessage.ID.make(input.id),
skills: input.skills?.map((skill) => ({ ...skill, id: Skill.ID.make(skill.id) })),
delivery: input.delivery ?? undefined,
resume: input.resume ?? undefined,
}),
@@ -310,6 +312,7 @@ export function fromPromise(plugin: Plugin) {
id: input.id == null ? undefined : SessionMessage.ID.make(input.id),
agent: input.agent == null ? undefined : Agent.ID.make(input.agent),
model: input.model == null ? undefined : model(input.model),
skills: input.skills?.map((skill) => ({ ...skill, id: Skill.ID.make(skill.id) })),
arguments: input.arguments ?? undefined,
delivery: input.delivery ?? undefined,
resume: input.resume ?? undefined,
+30 -4
View File
@@ -218,10 +218,11 @@ export interface Interface {
text: string
files?: PromptInput.Prompt["files"]
agents?: PromptInput.Prompt["agents"]
skills?: PromptInput.Prompt["skills"]
metadata?: Record<string, unknown>
delivery?: SessionPending.Delivery
resume?: boolean
}) => Effect.Effect<SessionPending.User, NotFoundError | PromptConflictError | AttachmentError>
}) => Effect.Effect<SessionPending.User, NotFoundError | PromptConflictError | AttachmentError | SkillNotFoundError>
/** Generates text from current Session context without admitting input or mutating history. */
readonly generate: (input: {
sessionID: SessionSchema.ID
@@ -236,11 +237,17 @@ export interface Interface {
model?: Model.Ref
files?: PromptInput.Prompt["files"]
agents?: PromptInput.Prompt["agents"]
skills?: PromptInput.Prompt["skills"]
delivery?: SessionPending.Delivery
resume?: boolean
}) => Effect.Effect<
SessionPending.User,
NotFoundError | PromptConflictError | AttachmentError | Command.NotFoundError | Command.EvaluationError
| NotFoundError
| PromptConflictError
| AttachmentError
| SkillNotFoundError
| Command.NotFoundError
| Command.EvaluationError
>
readonly shell: (input: {
id?: Event.ID
@@ -567,9 +574,11 @@ const layer = Layer.effect(
// Resolved lazily so prompt admission only boots location services when an
// image attachment actually needs the resizer.
const image = Image.Service.pipe(Effect.provide(locations.get(session.location)))
const skills = Skill.Service.pipe(Effect.provide(locations.get(session.location)))
const prompt = yield* resolvePrompt(
{ text: input.text, files: input.files, agents: input.agents },
{ text: input.text, files: input.files, agents: input.agents, skills: input.skills },
image,
skills,
).pipe(Effect.provideService(FSUtil.Service, fs))
const messageID = input.id ?? SessionMessage.ID.create()
const admittedInput = SessionPending.Message.make({
@@ -635,6 +644,7 @@ const layer = Layer.effect(
text: evaluated.text,
files: input.files,
agents: input.agents,
skills: input.skills,
delivery: input.delivery,
resume: input.resume,
})
@@ -897,12 +907,28 @@ function synthesizeTerminalShellInfo(started: ShellSchema.Info): ShellSchema.Inf
const resolvePrompt = Effect.fn("Session.resolvePrompt")(function* (
input: PromptInput.Prompt,
image: Effect.Effect<Image.Interface>,
skills: Effect.Effect<Skill.Interface>,
) {
const fs = yield* FSUtil.Service
const files = input.files
? yield* Effect.forEach(input.files, (file) => materializeAttachment(fs, file, image), { concurrency: 8 })
: undefined
return Prompt.make({ text: input.text, agents: input.agents, files })
const requested = input.skills
const selected = yield* Effect.gen(function* () {
if (!requested?.length) return undefined
const available = yield* (yield* skills).list()
return yield* Effect.forEach(requested, (attachment) => {
const skill = available.find((item) => item.id === attachment.id)
if (!skill) return Effect.fail(new SkillNotFoundError({ skill: attachment.id }))
return Effect.succeed({
id: skill.id,
name: skill.name,
text: Skill.toModelOutput(skill, []),
mention: attachment.mention,
})
})
})
return Prompt.make({ text: input.text, agents: input.agents, files, skills: selected?.length ? selected : undefined })
})
const MAX_ATTACHMENT_BYTES = 20 * 1024 * 1024
+2 -1
View File
@@ -124,7 +124,8 @@ const serialize = (message: SessionMessage.Info) => {
(file) =>
`[Attached ${file.mime}: ${file.name ?? (file.source.type === "uri" ? file.source.uri : "inline attachment")}]`,
) ?? []
return [`[User]: ${message.text}`, ...files].join("\n")
const skills = message.skills?.map((skill) => `[Attached skill: ${skill.name}]\n${skill.text}`) ?? []
return [`[User]: ${message.text}`, ...skills, ...files].join("\n")
}
if (message.type === "assistant") {
return message.content
+1
View File
@@ -453,6 +453,7 @@ const layer = Layer.effectDiscard(
text: input.data.text,
files: input.data.files,
agents: input.data.agents,
skills: input.data.skills,
time: { created: event.created },
}
: {
@@ -184,6 +184,7 @@ function toLLMMessage(message: SessionMessage.Info, model: Model.Ref, providerMe
return []
case "user":
const content = [
...(message.skills ?? []).map((skill) => Message.text(skill.text)),
...(message.text === "" ? [] : [Message.text(message.text)]),
...(message.files ?? []).flatMap(attachmentContent),
]
+9
View File
@@ -2,6 +2,7 @@ export * as SessionTransfer from "./transfer"
import { SessionTransfer } from "@opencode-ai/schema/session-transfer"
import { Tool } from "@opencode-ai/schema/tool"
import { Skill } from "@opencode-ai/schema/skill"
import { eq, isNotNull, isNull, ne, or } from "drizzle-orm"
import { Context, DateTime, Effect, Layer, Schema } from "effect"
import path from "path"
@@ -219,6 +220,14 @@ function sanitizeMessage(message: SessionMessage.Info): SessionMessage.Info {
? { ...agent.mention, text: redact("agent-mention", String(index), agent.mention.text) }
: undefined,
})),
skills: message.skills?.map((skill, index) => ({
...skill,
name: Skill.Name.make(redact("skill-name", String(index), skill.name)),
text: redact("skill", String(index), skill.text),
mention: skill.mention
? { ...skill.mention, text: redact("skill-mention", String(index), skill.mention.text) }
: undefined,
})),
}
if (message.type === "synthetic")
return {
+19
View File
@@ -38,6 +38,25 @@ export { Event } from "@opencode-ai/schema/skill"
export const available = (skills: ReadonlyArray<Info>, agent: Agent.Info) =>
skills.filter((skill) => Permission.evaluate("skill", skill.id, agent.permissions).effect !== "deny")
export const toModelOutput = (skill: Info, files: ReadonlyArray<string>) => {
const directory = path.dirname(skill.location)
return [
`<skill_content name="${skill.name}">`,
`# Skill: ${skill.name}`,
"",
skill.content.trim(),
"",
`Base directory for this skill: ${directory}`,
"Relative paths in this skill (e.g., scripts/, reference/) are relative to this base directory.",
"Note: file list is sampled.",
"",
"<skill_files>",
...files.map((file) => `<file>${file}</file>`),
"</skill_files>",
"</skill_content>",
].join("\n")
}
const Frontmatter = Schema.Struct({
name: Schema.String.pipe(Schema.optional),
description: Schema.String.pipe(Schema.optional),
+9 -15
View File
@@ -3,7 +3,6 @@ export * as PatchTool from "./patch"
import type { Context as PluginContext } from "@opencode-ai/plugin/effect/plugin"
import { ToolFailure } from "@opencode-ai/ai"
import { FileDiff } from "@opencode-ai/schema/file-diff"
import { createTwoFilesPatch, diffLines } from "diff"
import { Effect, Result, Schema } from "effect"
import path from "path"
import { Bom } from "@opencode-ai/util/bom"
@@ -15,6 +14,7 @@ import { Location } from "../../location"
import { Patch } from "@opencode-ai/util/patch"
import { Permission } from "../../permission"
import DESCRIPTION from "../patch.txt"
import { fileDiff } from "./file-diff"
export const name = "patch"
@@ -353,22 +353,16 @@ function errorMessage(error: unknown) {
function patchFile(change: Prepared, after = change.after): typeof FileDiff.Info.Type {
const target = (change.type === "update" ? change.moveTarget : undefined)?.resource ?? change.target.resource
const patch = trimDiff(createTwoFilesPatch(change.target.absolute, change.target.absolute, change.before, after))
const counts =
change.type === "delete"
? { additions: 0, deletions: change.before.split("\n").length }
: diffLines(change.before, after).reduce(
(result, item) => ({
additions: result.additions + (item.added ? (item.count ?? 0) : 0),
deletions: result.deletions + (item.removed ? (item.count ?? 0) : 0),
}),
{ additions: 0, deletions: 0 },
)
const diff = fileDiff(
change.target.absolute,
change.before,
after,
change.type === "add" ? "added" : change.type === "delete" ? "deleted" : "modified",
)
return {
...diff,
file: target,
patch,
status: change.type === "add" ? "added" : change.type === "delete" ? "deleted" : "modified",
...counts,
patch: trimDiff(diff.patch),
}
}
+1 -20
View File
@@ -26,25 +26,6 @@ export const description = [
"The skill ID must match one of the available skills in the instructions.",
].join("\n")
export const toModelOutput = (skill: Skill.Info, files: ReadonlyArray<string>) => {
const directory = path.dirname(skill.location)
return [
`<skill_content name="${skill.name}">`,
`# Skill: ${skill.name}`,
"",
skill.content.trim(),
"",
`Base directory for this skill: ${directory}`,
"Relative paths in this skill (e.g., scripts/, reference/) are relative to this base directory.",
"Note: file list is sampled.",
"",
"<skill_files>",
...files.map((file) => `<file>${file}</file>`),
"</skill_files>",
"</skill_content>",
].join("\n")
}
const unableToLoad = (name: string, error?: unknown) =>
new ToolFailure({ message: `Unable to load skill ${name}`, error })
@@ -88,7 +69,7 @@ export const Plugin = {
return {
name: skill.name,
directory,
output: toModelOutput(skill, files),
output: Skill.toModelOutput(skill, files),
}
}).pipe(Effect.mapError((error) => unableToLoad(input.id, error)))
}).pipe(
@@ -3,7 +3,8 @@ import { Message } from "@opencode-ai/ai"
import { Model } from "@opencode-ai/core/model"
import { Provider } from "@opencode-ai/core/provider"
import { SessionMessage } from "@opencode-ai/core/session/message"
import { AgentAttachment, Base64, FileAttachment } from "@opencode-ai/schema/prompt"
import { AgentAttachment, Base64, FileAttachment, SkillAttachment } from "@opencode-ai/schema/prompt"
import { Skill } from "@opencode-ai/schema/skill"
import { toLLMMessages } from "@opencode-ai/core/session/runner/to-llm-message"
import { Agent } from "@opencode-ai/core/agent"
import { Shell } from "@opencode-ai/schema/shell"
@@ -184,6 +185,40 @@ Recent work
})
})
test("lowers selected skill instructions with the original user prompt", () => {
const messages = toLLMMessages(
[
SessionMessage.User.make({
id: id("user-skill"),
type: "user",
text: "Design this API",
skills: [
SkillAttachment.make({
id: Skill.ID.make("api-design"),
name: Skill.Name.make("API design"),
text: "Start from the ideal call site.",
}),
],
time: { created },
}),
],
model,
)
expect(messages).toHaveLength(1)
expect(messages[0]).toMatchObject({
id: id("user-skill"),
role: "user",
content: [
{
type: "text",
text: "Start from the ideal call site.",
},
{ type: "text", text: "Design this API" },
],
})
})
test("decodes inline text attachment content", () => {
const messages = toLLMMessages(
[
+36
View File
@@ -15,6 +15,7 @@ import { SessionExecution } from "@opencode-ai/core/session/execution"
import { SessionMessage } from "@opencode-ai/core/session/message"
import { SessionProjector } from "@opencode-ai/core/session/projector"
import { SessionStore } from "@opencode-ai/core/session/store"
import { SessionPending } from "@opencode-ai/core/session/pending"
import { Skill } from "@opencode-ai/core/skill"
import { testEffect } from "./lib/effect"
@@ -55,6 +56,41 @@ const it = testEffect(
)
describe("Session.skill", () => {
it.effect("attaches a resolved skill snapshot to a normal prompt", () =>
Effect.gen(function* () {
const sessions = yield* Session.Service
const database = yield* Database.Service
const bus = yield* Bus.Service
const session = yield* sessions.create({ location })
const id = SessionMessage.ID.make("msg_skill_attachment")
yield* sessions.prompt({
id,
sessionID: session.id,
text: "Apply this guidance",
skills: [{ id: Skill.ID.make("effect"), mention: { start: 20, end: 27, text: "/effect" } }],
resume: false,
})
yield* SessionPending.promote(database.db, bus, session.id, "steer")
expect(yield* sessions.messages({ sessionID: session.id })).toContainEqual(
expect.objectContaining({
id,
type: "user",
text: "Apply this guidance",
skills: [
{
id: "effect",
name: "Effect",
text: expect.stringContaining("Use Effect"),
mention: { start: 20, end: 27, text: "/effect" },
},
],
}),
)
}),
)
it.effect("projects the caller-supplied message ID", () =>
Effect.gen(function* () {
const sessions = yield* Session.Service
+25 -2
View File
@@ -215,7 +215,7 @@ describe("PatchTool", () => {
file: "remove.txt",
status: "deleted",
additions: 0,
deletions: 2,
deletions: 1,
patch: expect.stringContaining("-remove"),
},
],
@@ -248,6 +248,29 @@ describe("PatchTool", () => {
),
)
it.live("counts deleted lines with and without a trailing newline", () =>
withTempTool((directory, registry) =>
Effect.gen(function* () {
yield* Effect.promise(() =>
Promise.all([
fs.writeFile(path.join(directory, "trailing.txt"), "remove\n"),
fs.writeFile(path.join(directory, "unterminated.txt"), "remove"),
]),
)
const settled = yield* executeTool(
registry,
call("*** Begin Patch\n*** Delete File: trailing.txt\n*** Delete File: unterminated.txt\n*** End Patch"),
)
expect(settled.status).toBe("completed")
if (settled.status !== "completed") return
expect(settled.output.files).toMatchObject([
{ file: "trailing.txt", additions: 0, deletions: 1 },
{ file: "unterminated.txt", additions: 0, deletions: 1 },
])
}),
),
)
it.live("serializes concurrent patch transactions", () =>
withTempTool((directory, registry) => {
const target = path.join(directory, "concurrent.txt")
@@ -446,7 +469,7 @@ describe("PatchTool", () => {
{
file: "renamed/dir/name.txt",
status: "modified",
patch: expect.stringContaining("-old content\n+new content"),
patch: expect.stringContaining(`Index: ${source}`),
},
],
})
+5 -5
View File
@@ -108,9 +108,9 @@ describe("SkillTool", () => {
}),
).toMatchObject({
status: "completed",
content: [{ type: "text", text: SkillTool.toModelOutput(info, [reference]) }],
content: [{ type: "text", text: Skill.toModelOutput(info, [reference]) }],
})
expect(SkillTool.toModelOutput(info, [reference])).toContain(`Base directory for this skill: ${directory}`)
expect(Skill.toModelOutput(info, [reference])).toContain(`Base directory for this skill: ${directory}`)
expect(
yield* executeTool(registry, {
sessionID,
@@ -119,8 +119,8 @@ describe("SkillTool", () => {
}),
).toEqual({
status: "completed",
output: { name: "Effect", directory, output: SkillTool.toModelOutput(info, [reference]) },
content: [{ type: "text", text: SkillTool.toModelOutput(info, [reference]) }],
output: { name: "Effect", directory, output: Skill.toModelOutput(info, [reference]) },
content: [{ type: "text", text: Skill.toModelOutput(info, [reference]) }],
metadata: { name: "Effect", directory },
})
expect(assertions).toMatchObject([
@@ -171,7 +171,7 @@ describe("SkillTool", () => {
}),
).toMatchObject({
status: "completed",
content: [{ type: "text", text: SkillTool.toModelOutput(flat, []) }],
content: [{ type: "text", text: Skill.toModelOutput(flat, []) }],
})
}).pipe(Effect.provide(skillToolLayer))
}),
+139 -14
View File
@@ -198,13 +198,13 @@ describe("FlowchartDiagram", () => {
B --> A`)
expectDiagram(output).toEqualDiagram(`
╭──────────────
╭───╮ ╭─┴─╮
│ A ├─────────▶│ B │
╰───╯ ╰───╯
╭───────────╮
│ │
│ │
▼ │
╭───╮ ╭─┴─╮
│ A ├──────▶│ B │
╰───╯ ╰───╯
`)
})
@@ -599,7 +599,7 @@ flowchart LR
const output = renderFlowchartDiagram(content)
expect(diagram.edges).toEqual([{ from: "Build", to: "Ship", label: "", style: "thick" }])
expect(output).toContain("━━━━━━━━━▶")
expect(output).toContain("━━━━━━▶")
})
test("parses and renders Mermaid dashed edges", () => {
@@ -611,7 +611,7 @@ flowchart LR
const output = renderFlowchartDiagram(content)
expect(diagram.edges).toEqual([{ from: "Build", to: "Ship", label: "", style: "dashed" }])
expect(output).toContain("─────────▶")
expect(output).toContain("──────▶")
})
test("paints horizontal and vertical dashed routes with solid terminal cells", () => {
@@ -689,11 +689,11 @@ graph LR
`)
expectDiagram(output).toEqualDiagram(`
╭───────╮
╭────────╮ ╭─────╮ ├───────┤
│ Client ├─────────▶│ API ├─────────▶│ Cache │
╰────────╯ ╰─────╯ ├───────┤
╰───────╯
╭───────╮
╭────────╮ ╭─────╮ ├───────┤
│ Client ├──────▶│ API ├──────▶│ Cache │
╰────────╯ ╰─────╯ ├───────┤
╰───────╯
`)
})
@@ -1062,6 +1062,131 @@ flowchart LR
}
})
test.each(["TD", "BT", "LR", "RL"] as const)(
"keeps parallel top-level subgraphs in the same rank for %s diagrams",
(direction) => {
const layout = layoutFlowchartDiagram(`flowchart ${direction}
subgraph source [Source]
A[A]
end
subgraph left [Left]
B[B]
end
subgraph right [Right]
C[C]
end
A --> B
A --> C`)
const source = layout.subgraphBounds.get("source")!
const left = layout.subgraphBounds.get("left")!
const right = layout.subgraphBounds.get("right")!
const leftNode = layout.bounds.get("B")!
const rightNode = layout.bounds.get("C")!
const horizontal = direction === "LR" || direction === "RL"
const reversed = direction === "BT" || direction === "RL"
const start = (bound: typeof source) => {
const value = horizontal ? bound.left : bound.top
const size = horizontal ? bound.width : bound.height
return reversed ? -(value + size) : value
}
const size = (bound: typeof source) => (horizontal ? bound.width : bound.height)
expect(horizontal ? leftNode.centerX : leftNode.centerY).toBe(horizontal ? rightNode.centerX : rightNode.centerY)
expect(Math.min(start(left), start(right))).toBeGreaterThanOrEqual(start(source) + size(source))
},
)
test.each(["TD", "BT", "LR", "RL"] as const)(
"separates oversized parallel subgraph labels across %s diagrams",
(direction) => {
const horizontal = direction === "LR" || direction === "RL"
const label = horizontal ? "one<br/>two<br/>three<br/>four<br/>five" : "A very very wide downstream subgraph title"
const layout = layoutFlowchartDiagram(`flowchart ${direction}
subgraph source [Source]
A[A]
end
subgraph left [${label}]
B[B]
end
subgraph right [Right]
C[C]
end
A --> B
A --> C`)
const left = layout.subgraphBounds.get("left")!
const right = layout.subgraphBounds.get("right")!
const overlap =
left.left < right.left + right.width &&
left.left + left.width > right.left &&
left.top < right.top + right.height &&
left.top + left.height > right.top
expect(overlap).toBe(false)
},
)
test.each(["TD", "BT", "LR", "RL"] as const)(
"ranks nested order-only subgraph dependencies for %s diagrams",
(direction) => {
const layout = layoutFlowchartDiagram(`flowchart ${direction}
subgraph first [First]
subgraph firstInner [First inner]
A[A]
end
end
subgraph second [Second]
subgraph secondInner [Second inner]
B[B]
end
end
firstInner ~~~ secondInner`)
const first = layout.subgraphBounds.get("first")!
const second = layout.subgraphBounds.get("second")!
const horizontal = direction === "LR" || direction === "RL"
const reversed = direction === "BT" || direction === "RL"
const start = (bound: typeof first) => {
const value = horizontal ? bound.left : bound.top
const size = horizontal ? bound.width : bound.height
return reversed ? -(value + size) : value
}
const size = horizontal ? first.width : first.height
expect(start(second)).toBeGreaterThanOrEqual(start(first) + size)
},
)
test.each(["TD", "BT", "LR", "RL"] as const)(
"ranks cyclic top-level subgraphs as one downstream component for %s diagrams",
(direction) => {
const layout = layoutFlowchartDiagram(`flowchart ${direction}
subgraph source [Source]
A[A]
end
subgraph first [First]
B[B]
end
subgraph second [Second]
C[C]
end
A --> B
B --> C
C --> B`)
const source = layout.subgraphBounds.get("source")!
const first = layout.subgraphBounds.get("first")!
const second = layout.subgraphBounds.get("second")!
const horizontal = direction === "LR" || direction === "RL"
const reversed = direction === "BT" || direction === "RL"
const start = (bound: typeof source) => {
const value = horizontal ? bound.left : bound.top
const size = horizontal ? bound.width : bound.height
return reversed ? -(value + size) : value
}
const size = (bound: typeof source) => (horizontal ? bound.width : bound.height)
expect(Math.min(start(first), start(second))).toBeGreaterThanOrEqual(start(source) + size(source))
},
)
test("moves subgraph labels away from crossing routes", () => {
const output = renderFlowchartDiagram(`
flowchart TD
+142 -45
View File
@@ -27,7 +27,7 @@ import type {
export const DEFAULT_MIN_NODE_GAP = 5
export const DEFAULT_MIN_BRANCH_LABEL_GAP = 12
export const DEFAULT_MIN_RANK_GAP = 10
export const DEFAULT_MIN_RANK_GAP = 7
export const DEFAULT_MIN_VERTICAL_RANK_GAP = 4
export const COMPACT_MIN_RANK_GAP = 4
export const COMPACT_MIN_VERTICAL_RANK_GAP = 2
@@ -511,19 +511,79 @@ function collectSubgraphNodeIds(diagram: FlowchartDiagram, subgraphId: string):
return nodeIds
}
function rankGraphComponents(ids: readonly string[], outgoing: ReadonlyMap<string, ReadonlySet<string>>): Map<string, number> {
const reachable = new Map<string, Set<string>>()
for (const id of ids) {
const seen = new Set<string>()
const queue = [id]
for (let index = 0; index < queue.length; index++) {
const current = queue[index]!
if (seen.has(current)) continue
seen.add(current)
queue.push(...(outgoing.get(current) ?? []))
}
reachable.set(id, seen)
}
const componentById = new Map<string, number>()
const components: string[][] = []
for (const id of ids) {
if (componentById.has(id)) continue
const component = ids.filter(
(candidate) => !componentById.has(candidate) && reachable.get(id)!.has(candidate) && reachable.get(candidate)!.has(id),
)
const componentIndex = components.length
components.push(component)
for (const member of component) componentById.set(member, componentIndex)
}
const componentOutgoing = new Map(components.map((_, index) => [index, new Set<number>()]))
const incoming = new Map(components.map((_, index) => [index, 0]))
for (const [from, targets] of outgoing) {
const fromComponent = componentById.get(from)!
for (const to of targets) {
const toComponent = componentById.get(to)!
if (fromComponent === toComponent || componentOutgoing.get(fromComponent)!.has(toComponent)) continue
componentOutgoing.get(fromComponent)!.add(toComponent)
incoming.set(toComponent, incoming.get(toComponent)! + 1)
}
}
const componentRanks = new Map<number, number>()
const queue = components.map((_, index) => index).filter((index) => incoming.get(index) === 0)
for (const component of queue) componentRanks.set(component, 0)
for (let index = 0; index < queue.length; index++) {
const component = queue[index]!
for (const to of componentOutgoing.get(component)!) {
componentRanks.set(to, Math.max(componentRanks.get(to) ?? 0, componentRanks.get(component)! + 1))
incoming.set(to, incoming.get(to)! - 1)
if (incoming.get(to) === 0) queue.push(to)
}
}
return new Map(ids.map((id) => [id, componentRanks.get(componentById.get(id)!) ?? 0]))
}
function separateTopLevelItems(
diagram: FlowchartDiagram,
nodeBounds: Map<string, FlowchartNodeBounds>,
subgraphBounds: ReadonlyMap<string, FlowchartSubgraphBounds>,
gap: number,
): void {
): boolean {
const hasLocalDirection = (diagram.subgraphs ?? []).some(
(subgraph) => subgraph.direction && subgraph.direction !== diagram.direction,
)
const coveredNodeIds = new Set<string>()
const items: { id: string; bounds: FlowchartBounds; nodeIds: Set<string>; rank: number }[] = []
const itemByEndpoint = new Map<string, string>()
for (const subgraph of diagram.subgraphs ?? []) {
const subgraphs = diagram.subgraphs ?? []
const subgraphById = new Map(subgraphs.map((subgraph) => [subgraph.id, subgraph]))
const topLevelSubgraphId = (id: string): string => {
let current = subgraphById.get(id)
while (current?.parentId) current = subgraphById.get(current.parentId)
return current?.id ?? id
}
for (const subgraph of subgraphs) {
if (subgraph.parentId) continue
const bounds = subgraphBounds.get(subgraph.id)
const nodeIds = collectSubgraphNodeIds(diagram, subgraph.id)
@@ -535,6 +595,7 @@ function separateTopLevelItems(
itemByEndpoint.set(nodeId, subgraph.id)
}
}
for (const subgraph of subgraphs) itemByEndpoint.set(subgraph.id, topLevelSubgraphId(subgraph.id))
for (const node of diagram.nodes) {
if (coveredNodeIds.has(node.id)) continue
@@ -543,12 +604,19 @@ function separateTopLevelItems(
items.push({ id: node.id, bounds, nodeIds: new Set([node.id]), rank: 0 })
itemByEndpoint.set(node.id, node.id)
}
if (items.length < 2) return
if (items.length < 2) return false
const horizontal = isHorizontalDirection(diagram.direction)
const moveItem = (item: (typeof items)[number], dx: number, dy: number): void => {
for (const nodeId of item.nodeIds) {
const bounds = nodeBounds.get(nodeId)
if (bounds) translateBounds(bounds, dx, dy)
}
}
if (hasLocalDirection) {
items.sort((a, b) => (horizontal ? a.bounds.left - b.bounds.left : a.bounds.top - b.bounds.top))
let cursor: number | undefined
let moved = false
for (const item of items) {
const start = horizontal ? item.bounds.left : item.bounds.top
const size = horizontal ? item.bounds.width : item.bounds.height
@@ -557,42 +625,31 @@ function separateTopLevelItems(
continue
}
const shift = cursor - start
for (const nodeId of item.nodeIds) {
const bounds = nodeBounds.get(nodeId)
if (bounds) translateBounds(bounds, horizontal ? shift : 0, horizontal ? 0 : shift)
}
moved ||= shift !== 0
moveItem(item, horizontal ? shift : 0, horizontal ? 0 : shift)
cursor = start + shift + size + gap
}
return
return moved
}
const topLevelIds = new Set(
(diagram.subgraphs ?? []).filter((subgraph) => !subgraph.parentId).map((subgraph) => subgraph.id),
)
const topLevelIds = new Set(subgraphs.filter((subgraph) => !subgraph.parentId).map((subgraph) => subgraph.id))
const rankedItems = items.filter((item) => topLevelIds.has(item.id))
if (rankedItems.length < 2) return
if (rankedItems.length < 2) return false
const itemById = new Map(rankedItems.map((item) => [item.id, item]))
const outgoing = new Map(rankedItems.map((item) => [item.id, new Set<string>()]))
const incoming = new Map(rankedItems.map((item) => [item.id, 0]))
for (const edge of diagram.edges) {
const from = itemByEndpoint.get(edge.from)
const to = itemByEndpoint.get(edge.to)
if (!from || !to || from === to || !itemById.has(from) || !itemById.has(to) || outgoing.get(from)!.has(to)) continue
outgoing.get(from)!.add(to)
incoming.set(to, incoming.get(to)! + 1)
}
const queue = rankedItems.filter((item) => incoming.get(item.id) === 0)
for (let index = 0; index < queue.length; index++) {
const item = queue[index]!
for (const to of outgoing.get(item.id)!) {
const downstream = itemById.get(to)!
downstream.rank = Math.max(downstream.rank, item.rank + 1)
incoming.set(to, incoming.get(to)! - 1)
if (incoming.get(to) === 0) queue.push(downstream)
}
}
const ranks = rankGraphComponents(
rankedItems.map((item) => item.id),
outgoing,
)
for (const item of rankedItems) item.rank = ranks.get(item.id)!
const reversed = diagram.direction === "RL" || diagram.direction === "BT"
const primaryStart = (item: (typeof items)[number]): number => {
@@ -600,28 +657,54 @@ function separateTopLevelItems(
const size = horizontal ? item.bounds.width : item.bounds.height
return reversed ? -(start + size) : start
}
rankedItems.sort((a, b) => a.rank - b.rank || primaryStart(a) - primaryStart(b))
const itemsByRank = Map.groupBy(rankedItems, (item) => item.rank)
const rankKeys = [...itemsByRank.keys()].sort((a, b) => a - b)
let cursor: number | undefined
for (const item of rankedItems) {
const start = primaryStart(item)
const size = horizontal ? item.bounds.width : item.bounds.height
let moved = false
for (const rank of rankKeys) {
const rankItems = itemsByRank.get(rank)!
const start = Math.min(...rankItems.map(primaryStart))
const end = Math.max(
...rankItems.map((item) => primaryStart(item) + (horizontal ? item.bounds.width : item.bounds.height)),
)
if (cursor === undefined) {
cursor = start + size + gap
cursor = end + gap
continue
}
const shift = Math.max(0, cursor - start)
if (shift > 0) {
for (const nodeId of item.nodeIds) {
const bounds = nodeBounds.get(nodeId)
if (bounds) {
const offset = reversed ? -shift : shift
translateBounds(bounds, horizontal ? offset : 0, horizontal ? 0 : offset)
}
moved = true
for (const item of rankItems) {
const offset = reversed ? -shift : shift
moveItem(item, horizontal ? offset : 0, horizontal ? 0 : offset)
}
}
cursor = start + shift + size + gap
cursor = end + shift + gap
}
for (const rank of rankKeys) {
const rankItems = itemsByRank
.get(rank)!
.toSorted((a, b) =>
horizontal ? a.bounds.top - b.bounds.top : a.bounds.left - b.bounds.left,
)
let crossCursor: number | undefined
for (const item of rankItems) {
const start = horizontal ? item.bounds.top : item.bounds.left
const size = horizontal ? item.bounds.height : item.bounds.width
if (crossCursor === undefined) {
crossCursor = start + size + gap
continue
}
const shift = Math.max(0, crossCursor - start)
if (shift > 0) {
moved = true
moveItem(item, horizontal ? 0 : shift, horizontal ? shift : 0)
}
crossCursor = start + shift + size + gap
}
}
return moved
}
function layoutSubgraphs(
@@ -676,13 +759,27 @@ function layoutFlowchartWithDirection(
const bounds = layoutRankedNodes(diagram, direction, sizes, minNodeGap, requestedMinRankGap)
layoutLocalSubgraphDirections(diagram, bounds, sizes, minNodeGap, requestedMinRankGap)
let routes = routeFlowchartEdges(diagram, bounds, (edge) => edgeDirection(diagram, edge))
let subgraphBounds = layoutSubgraphs(diagram, bounds, routes)
separateTopLevelItems(diagram, bounds, subgraphBounds, Math.max(1, Math.floor(requestedMinRankGap / 2)))
routes = routeFlowchartEdges(diagram, bounds, (edge) => edgeDirection(diagram, edge))
subgraphBounds = layoutSubgraphs(diagram, bounds, routes)
routes = routeFlowchartEdges(diagram, bounds, (edge) => edgeDirection(diagram, edge), subgraphBounds)
subgraphBounds = layoutSubgraphs(diagram, bounds, routes)
const subgraphs = diagram.subgraphs ?? []
let subgraphBounds = new Map<string, FlowchartSubgraphBounds>()
let routes: FlowchartEdgeRoute[]
if (subgraphs.length === 0) {
routes = routeFlowchartEdges(diagram, bounds, (edge) => edgeDirection(diagram, edge))
} else {
routes = routeFlowchartEdges(diagram, bounds, (edge) => edgeDirection(diagram, edge))
subgraphBounds = layoutSubgraphs(diagram, bounds, routes)
const moved = separateTopLevelItems(
diagram,
bounds,
subgraphBounds,
Math.max(1, Math.floor(requestedMinRankGap / 2)),
)
if (moved) {
routes = routeFlowchartEdges(diagram, bounds, (edge) => edgeDirection(diagram, edge))
subgraphBounds = layoutSubgraphs(diagram, bounds, routes)
}
routes = routeFlowchartEdges(diagram, bounds, (edge) => edgeDirection(diagram, edge), subgraphBounds)
subgraphBounds = layoutSubgraphs(diagram, bounds, routes)
}
const allBounds = [...bounds.values(), ...subgraphBounds.values(), ...routeRenderBounds(routes)]
const dx = Math.max(0, -Math.min(0, ...allBounds.map((bound) => bound.left)))
const dy = Math.max(0, -Math.min(0, ...allBounds.map((bound) => bound.top)))
+51
View File
@@ -0,0 +1,51 @@
import { describe, expect, test } from "bun:test"
import { RGBA } from "@opentui/core"
import { createOpenCodeDiagramPalette } from "./palette.js"
type Rgb = readonly [number, number, number]
const rgb = (value: Rgb) => RGBA.fromInts(...value)
describe("OpenCode diagram palette", () => {
test.each(
[
{
name: "dark theme",
text: [230, 232, 240],
subdued: [114, 120, 138],
secondary: [172, 176, 189],
muted: [149, 154, 169],
},
{
name: "light theme",
text: [32, 35, 43],
subdued: [119, 125, 138],
secondary: [76, 80, 91],
muted: [93, 98, 110],
},
] satisfies ReadonlyArray<{
name: string
text: Rgb
subdued: Rgb
secondary: Rgb
muted: Rgb
}>,
)("derives a controlled neutral ladder for a $name", ({ text, subdued, secondary, muted }) => {
const primary = rgb(text)
const info = RGBA.fromInts(40, 120, 220)
const background = RGBA.fromInts(10, 20, 30)
const palette = createOpenCodeDiagramPalette({
text: primary,
subdued: rgb(subdued),
info,
background,
})
expect(palette.text).toBe(primary)
expect(palette.primary).toBe(primary)
expect(palette.secondary.equals(rgb(secondary))).toBe(true)
expect(palette.muted.equals(rgb(muted))).toBe(true)
expect(palette.warning).toBe(info)
expect(palette.background).toBe(background)
})
})
+20
View File
@@ -0,0 +1,20 @@
import type { RGBA } from "@opentui/core"
import { blendColor } from "./core/color/style.js"
export interface OpenCodeDiagramPaletteInput {
readonly text: RGBA
readonly subdued: RGBA
readonly info: RGBA
readonly background: RGBA
}
export function createOpenCodeDiagramPalette(input: OpenCodeDiagramPaletteInput) {
return {
text: input.text,
primary: input.text,
secondary: blendColor(input.text, input.subdued, 0.5),
muted: blendColor(input.text, input.subdued, 0.7),
warning: input.info,
background: input.background,
}
}
+6 -7
View File
@@ -1,5 +1,6 @@
import { Plugin } from "@opencode-ai/plugin/tui"
import { createMermaidCodeBlockRenderer } from "./markdown.js"
import { createOpenCodeDiagramPalette } from "./palette.js"
export default Plugin.define({
id: "opencode.merman",
@@ -7,14 +8,12 @@ export default Plugin.define({
context.markdown.registerCodeBlockRenderer(
"mermaid",
createMermaidCodeBlockRenderer(context.renderer, () => ({
colors: {
text: context.theme.markdown.text,
primary: context.theme.text.default,
secondary: context.theme.text.subdued,
muted: context.theme.border.default,
warning: context.theme.text.feedback.info.default,
colors: createOpenCodeDiagramPalette({
text: context.theme.text.default,
subdued: context.theme.text.subdued,
info: context.theme.text.feedback.info.default,
background: context.theme.background.default,
},
}),
})),
)
},
+1
View File
@@ -347,6 +347,7 @@ export const makeSessionGroup = <I extends HttpApiMiddleware.AnyId, S>(sessionLo
model: Model.Ref.pipe(Schema.optional),
files: PromptInput.Prompt.fields.files,
agents: PromptInput.Prompt.fields.agents,
skills: PromptInput.Prompt.fields.skills,
delivery: SessionPending.Delivery.pipe(Schema.optional),
resume: Schema.Boolean.pipe(Schema.optional),
}),
+8
View File
@@ -3,6 +3,7 @@ export * as PromptInput from "./prompt-input.js"
import { Schema } from "effect"
import { AgentAttachment, PromptMention } from "./prompt.js"
import { optional, statics } from "./schema.js"
import { Skill } from "./skill.js"
export interface FileAttachment extends Schema.Schema.Type<typeof FileAttachment> {}
export const FileAttachment = Schema.Struct({
@@ -19,8 +20,15 @@ export const FileAttachment = Schema.Struct({
)
export interface Prompt extends Schema.Schema.Type<typeof Prompt> {}
export interface SkillAttachment extends Schema.Schema.Type<typeof SkillAttachment> {}
export const SkillAttachment = Schema.Struct({
id: Skill.ID,
mention: PromptMention.pipe(optional),
}).annotate({ identifier: "PromptInput.SkillAttachment" })
export const Prompt = Schema.Struct({
text: Schema.String,
files: Schema.Array(FileAttachment).pipe(optional),
agents: Schema.Array(AgentAttachment).pipe(optional),
skills: Schema.Array(SkillAttachment).pipe(optional),
}).annotate({ identifier: "PromptInput" })
+12 -1
View File
@@ -1,6 +1,7 @@
import { Schema } from "effect"
import { optional } from "./schema.js"
import { statics } from "./schema.js"
import { Skill } from "./skill.js"
export interface PromptMention extends Schema.Schema.Type<typeof PromptMention> {}
export const PromptMention = Schema.Struct({
@@ -52,21 +53,31 @@ export const AgentAttachment = Schema.Struct({
mention: PromptMention.pipe(optional),
}).annotate({ identifier: "Prompt.AgentAttachment" })
export interface SkillAttachment extends Schema.Schema.Type<typeof SkillAttachment> {}
export const SkillAttachment = Schema.Struct({
id: Skill.ID,
name: Skill.Name,
text: Schema.String,
mention: PromptMention.pipe(optional),
}).annotate({ identifier: "Prompt.SkillAttachment" })
export interface Prompt extends Schema.Schema.Type<typeof Prompt> {}
export const Prompt = Schema.Struct({
text: Schema.String,
files: Schema.Array(FileAttachment).pipe(optional),
agents: Schema.Array(AgentAttachment).pipe(optional),
skills: Schema.Array(SkillAttachment).pipe(optional),
})
.annotate({ identifier: "Prompt" })
.pipe(
statics((schema) => ({
equivalence: Schema.toEquivalence(schema),
fromUserMessage: (input: Pick<Prompt, "text" | "files" | "agents">) =>
fromUserMessage: (input: Pick<Prompt, "text" | "files" | "agents" | "skills">) =>
schema.make({
text: input.text,
...(input.files === undefined ? {} : { files: input.files }),
...(input.agents === undefined ? {} : { agents: input.agents }),
...(input.skills === undefined ? {} : { skills: input.skills }),
}),
})),
)
+1
View File
@@ -58,6 +58,7 @@ export const User = Schema.Struct({
text: Prompt.fields.text,
files: Prompt.fields.files,
agents: Prompt.fields.agents,
skills: Prompt.fields.skills,
type: Schema.tag("user"),
}).annotate({ identifier: "Session.Message.User" })
+8
View File
@@ -313,6 +313,7 @@ export const SessionHandler = HttpApiBuilder.group(Api, "server.session", (handl
text: ctx.payload.text,
files: ctx.payload.files,
agents: ctx.payload.agents,
skills: ctx.payload.skills,
metadata: ctx.payload.metadata,
delivery: ctx.payload.delivery,
resume: ctx.payload.resume,
@@ -337,6 +338,9 @@ export const SessionHandler = HttpApiBuilder.group(Api, "server.session", (handl
Effect.catchTag("Session.AttachmentError", (error) =>
Effect.fail(new InvalidRequestError({ message: error.message, field: "files" })),
),
Effect.catchTag("Session.SkillNotFoundError", (error) =>
Effect.fail(new InvalidRequestError({ message: `Skill not found: ${error.skill}`, field: "skills" })),
),
),
}
}),
@@ -355,6 +359,7 @@ export const SessionHandler = HttpApiBuilder.group(Api, "server.session", (handl
model: ctx.payload.model,
files: ctx.payload.files,
agents: ctx.payload.agents,
skills: ctx.payload.skills,
delivery: ctx.payload.delivery,
resume: ctx.payload.resume,
})
@@ -394,6 +399,9 @@ export const SessionHandler = HttpApiBuilder.group(Api, "server.session", (handl
Effect.catchTag("Session.AttachmentError", (error) =>
Effect.fail(new InvalidRequestError({ message: error.message, field: "files" })),
),
Effect.catchTag("Session.SkillNotFoundError", (error) =>
Effect.fail(new InvalidRequestError({ message: `Skill not found: ${error.skill}`, field: "skills" })),
),
),
}
}),
+36 -11
View File
@@ -13,15 +13,30 @@ trap 'rm -f -- "$pidfile"' EXIT
"$@"
`
// Modal's VM runtime accepts process-group signals without delivering them
// (kill(-pgid) returns 0 and nothing dies; direct-pid signals work), so the
// group is enumerated from /proc and each member is signalled directly. The
// second pass catches children forked between scan and signal.
const KILL = `
pidfile=$1
sig=$2
i=0
while [ ! -s "$1" ] && [ "$i" -lt 250 ]; do sleep 0.02; i=$((i + 1)); done
if [ -s "$1" ]; then
pid=$(cat "$1")
/bin/kill "-$2" "-$pid" 2>/dev/null || true
else
exit 47
fi
while [ ! -s "$pidfile" ] && [ "$i" -lt 250 ]; do sleep 0.02; i=$((i + 1)); done
[ -s "$pidfile" ] || exit 47
target=$(cat "$pidfile")
pass=0
while [ "$pass" -lt 2 ]; do
for stat in /proc/[0-9]*/stat; do
[ -e "$stat" ] || continue
pid=\${stat#/proc/}
pid=\${pid%/stat}
set -- $(sed "s/.*) //" "$stat" 2>/dev/null)
if [ "\${3:-}" = "$target" ]; then
/bin/kill "-$sig" "$pid" 2>/dev/null || true
fi
done
pass=$((pass + 1))
done
`
export interface ModalImageSpec {
@@ -54,7 +69,15 @@ export const createModalSandbox = async (options: ModalSandboxOptions) => {
const app = await client.apps.fromName(options.app, { createIfMissing: true })
const imageSpec = options.image ?? ubuntuImage
const image = client.images.fromRegistry(imageSpec.registry).dockerfileCommands([...imageSpec.dockerfileCommands])
const sandbox = await client.sandboxes.create(app, image, options.sandbox)
// Always Modal's Full-VM runtime (beta, enabled per account): a real kernel
// with real device nodes, so workspaces can run Docker and other
// kernel-dependent workloads. Costs versus gVisor, measured Aug 2026:
// per-exec floor ~285-535ms versus ~90-165ms, and filesystem snapshots only
// (no memory snapshots — acceptable; fs-snapshot is the persistence design).
const sandbox = await client.sandboxes.create(app, image, {
...options.sandbox,
experimentalOptions: { ...options.sandbox?.experimentalOptions, vm_runtime: true },
})
return {
driver: makeModalDriver(sandbox),
sandbox,
@@ -64,12 +87,14 @@ export const createModalSandbox = async (options: ModalSandboxOptions) => {
/**
* Adapts Modal exec to the Environment driver. Files intentionally has no native
* overrides: Modal exec and filesystem tools share the same roughly 175ms floor,
* so the derived exec defaults are the simplest implementation with no measured loss.
* overrides: exec latency dominates payload work (VM runtime floor measured
* ~285-535ms per exec, Aug 2026), so the derived exec defaults are the simplest
* implementation with no measured loss.
*
* Modal cannot signal a ContainerProcess. Each command therefore starts a new
* process group and records its leader in a unique pid file; kill runs a second
* sandbox command that signals that group. Pid files are removed best-effort.
* sandbox command that enumerates that group from /proc and signals each member
* directly (see KILL). Pid files are removed best-effort.
*/
export const makeModalDriver = (sandbox: Sandbox): Driver => {
const spawn = Effect.fnUntraced(function* (command: Command) {
+1
View File
@@ -12,6 +12,7 @@ export function generateSyntax(theme: ResolvedThemeTokens, mode: Mode) {
rule(["prompt"], theme.hue.accent[step]),
rule(["extmark.file"], feedback.warning.default, { bold: true }),
rule(["extmark.agent"], theme.categorical[0][step], { bold: true }),
rule(["extmark.skill"], theme.categorical[1][step], { bold: true }),
// V1 migration preserves its selected/inverse foreground in this action state.
rule(["extmark.paste"], theme.text.action.primary.focused, {
background: feedback.warning.default,
-9
View File
@@ -1154,15 +1154,6 @@ function App(props: { pair?: DialogPairCredentials }) {
}
})
event.on("session.execution.failed", (evt, { workspace }) => {
if (workspace !== (location.current?.workspaceID ?? data.location.default().workspaceID)) return
toast.show({
variant: "error",
message: evt.data.error.message,
duration: 5000,
})
})
// Suppress the full-screen overlay for transient startup and event-stream retry states.
// Initial connection gets a longer grace period; retries surface more quickly.
const [showReconnecting, setShowReconnecting] = createSignal(false)
@@ -19,8 +19,9 @@ import { Locale } from "../../util/locale"
import type { PromptInfo, PromptPartRef } from "../../prompt/history"
import { useFrecency } from "../../prompt/frecency"
import { Keymap } from "../../context/keymap"
import { displayCharAt, mentionTriggerIndex } from "../../prompt/display"
import { displayCharAt, mentionTriggerIndex, slashTriggerIndex } from "../../prompt/display"
import type { FileSystemEntry } from "@opencode-ai/client"
import { Skill } from "@opencode-ai/schema/skill"
import { stringWidth } from "../../util/string-width"
import { parseFileLineRange, stripFileLineRange } from "../../prompt/parse"
import { moveSelection, revealSelectionOffset } from "../../ui/select-controller"
@@ -39,6 +40,7 @@ export type AutocompleteOption = {
isDirectory?: boolean
onSelect?: () => void
path?: string
kind?: "skill"
}
export function Autocomplete(props: {
@@ -51,6 +53,8 @@ export function Autocomplete(props: {
ref: (ref: AutocompleteRef) => void
fileStyleId: number
agentStyleId: number
skillStyleId: number
hasSkill: (id: string) => boolean
promptPartTypeId: () => number
}) {
const editor = useEditorContext()
@@ -140,14 +144,17 @@ export function Autocomplete(props: {
text: string,
part:
| { type: "file"; value: NonNullable<PromptInfo["files"]>[number]; path?: string }
| { type: "agent"; value: NonNullable<PromptInfo["agents"]>[number] },
| { type: "agent"; value: NonNullable<PromptInfo["agents"]>[number] }
| { type: "skill"; value: NonNullable<PromptInfo["skills"]>[number] },
) {
if (part.type === "skill" && props.hasSkill(part.value.id)) return
const input = props.input()
const currentCursorOffset = input.cursorOffset
const charAfterCursor = displayCharAt(props.value, currentCursorOffset)
const needsSpace = charAfterCursor !== " "
const append = "@" + text + (needsSpace ? " " : "")
const prefix = part.type === "skill" ? "/" : "@"
const append = prefix + text + (needsSpace ? " " : "")
input.cursorOffset = store.index
const startCursor = input.logicalCursor
@@ -157,11 +164,12 @@ export function Autocomplete(props: {
input.deleteRange(startCursor.row, startCursor.col, endCursor.row, endCursor.col)
input.insertText(append)
const virtualText = "@" + text
const virtualText = prefix + text
const extmarkStart = store.index
const extmarkEnd = extmarkStart + stringWidth(virtualText)
const styleId = part.type === "file" ? props.fileStyleId : props.agentStyleId
const styleId =
part.type === "file" ? props.fileStyleId : part.type === "skill" ? props.skillStyleId : props.agentStyleId
const extmarkId = input.extmarks.create({
start: extmarkStart,
@@ -195,6 +203,20 @@ export function Autocomplete(props: {
return
}
if (part.type === "skill") {
const skills = (draft.skills ??= [])
if (skills.some((skill) => skill.id === part.value.id)) return
if (part.value.mention) {
part.value.mention.start = extmarkStart
part.value.mention.end = extmarkEnd
part.value.mention.text = virtualText
}
const index = skills.length
skills.push(part.value)
props.setExtmark({ type: "skill", index }, extmarkId)
return
}
const agents = (draft.agents ??= [])
if (part.value.mention) {
part.value.mention.start = extmarkStart
@@ -433,7 +455,12 @@ export function Autocomplete(props: {
results.push({
display: "/" + skill.id,
description: skill.description,
onSelect: () => insertSlash(skill.id),
kind: "skill",
onSelect: () =>
insertPart(skill.id, {
type: "skill",
value: { id: Skill.ID.make(skill.id), mention: { start: 0, end: 0, text: "" } },
}),
})
}
@@ -463,7 +490,11 @@ export function Autocomplete(props: {
// it shouldn't be additionally sorted by fuzzysort as it will loose the results
const fileOptions: AutocompleteOption[] = store.visible === "@" ? fileSearch.options : []
const nonFileOptions: AutocompleteOption[] =
store.visible === "@" ? [...referenceAliasesValue, ...agentsValue, ...mcpResources()] : [...commandsValue]
store.visible === "@"
? [...referenceAliasesValue, ...agentsValue, ...mcpResources()]
: store.index === 0
? [...commandsValue]
: commandsValue.filter((item) => item.kind === "skill")
if (!searchValue) {
return [...nonFileOptions, ...fileOptions]
@@ -520,7 +551,7 @@ export function Autocomplete(props: {
function select() {
const selected = options()[store.selected]
if (!selected) return
hide()
hide(true)
selected.onSelect?.()
}
@@ -608,14 +639,18 @@ export function Autocomplete(props: {
})
}
function hide() {
const text = props.input().plainText
if (store.visible === "/" && !text.endsWith(" ") && text.startsWith("/")) {
const cursor = props.input().logicalCursor
props.input().deleteRange(0, 0, cursor.row, cursor.col)
function hide(removeToken = false) {
if (removeToken && store.visible === "/") {
const input = props.input()
const cursorOffset = input.cursorOffset
input.cursorOffset = store.index
const start = input.logicalCursor
input.cursorOffset = cursorOffset
const end = input.logicalCursor
input.deleteRange(start.row, start.col, end.row, end.col)
// Sync the prompt store immediately since onContentChange is async
props.setPrompt((draft) => {
draft.text = props.input().plainText
draft.text = input.plainText
})
}
setStore("visible", false)
@@ -640,9 +675,7 @@ export function Autocomplete(props: {
// Typed text before the trigger
props.input().cursorOffset <= store.index ||
// There is a space between the trigger and the cursor
props.input().getTextRange(store.index, props.input().cursorOffset).match(/\s/) ||
// "/<command>" is not the sole content
(store.visible === "/" && value.match(/^\S+\s+\S+\s*$/))
props.input().getTextRange(store.index, props.input().cursorOffset).match(/\s/)
) {
hide()
}
@@ -653,10 +686,10 @@ export function Autocomplete(props: {
const offset = props.input().cursorOffset
if (offset === 0) return
// Check for "/" at position 0 - reopen slash commands
if (value.startsWith("/") && !value.slice(0, offset).match(/\s/)) {
const slash = slashTriggerIndex(value, offset)
if (slash !== undefined) {
show("/")
setStore("index", 0)
setStore("index", slash)
return
}
+46 -5
View File
@@ -29,6 +29,7 @@ import { parseSlashHead } from "../../prompt/parse"
import { stringWidth } from "../../util/string-width"
import { createStore, produce, unwrap } from "solid-js/store"
import { emptyPrompt, usePromptHistory, type PromptInfo, type PromptPartRef } from "../../prompt/history"
import { Skill } from "@opencode-ai/schema/skill"
import { computePromptTraits } from "../../prompt/traits"
import { expandPastedTextPlaceholders, expandTrackedPastedText } from "../../prompt/part"
import { usePromptStash } from "../../prompt/stash"
@@ -273,6 +274,7 @@ export function Prompt(props: PromptProps) {
}
const fileStyleId = syntax().getStyleId("extmark.file")!
const agentStyleId = syntax().getStyleId("extmark.agent")!
const skillStyleId = syntax().getStyleId("extmark.skill")!
const pasteStyleId = syntax().getStyleId("extmark.paste")!
let promptPartTypeId = 0
const event = useEvent()
@@ -493,12 +495,29 @@ export function Prompt(props: PromptProps) {
<DialogSkill
location={currentLocation.current}
onSelect={(skill) => {
input.setText(`/${skill} `)
setStore("prompt", {
...emptyPrompt(),
text: `/${skill} `,
if (store.prompt.skills?.some((item) => item.id === skill)) return
const text = `/${skill}`
const start = input.cursorOffset
input.insertText(text + " ")
const extmarkId = input.extmarks.create({
start,
end: start + promptOffsetWidth(text),
virtual: true,
styleId: skillStyleId,
typeId: promptPartTypeId,
})
input.gotoBufferEnd()
setStore(
produce((draft) => {
draft.prompt.text = input.plainText
const skills = (draft.prompt.skills ??= [])
const index = skills.length
skills.push({
id: Skill.ID.make(skill),
mention: { start, end: start + promptOffsetWidth(text), text },
})
draft.extmarkToPart.set(extmarkId, { type: "skill", index })
}),
)
}}
/>
))
@@ -639,6 +658,11 @@ export function Prompt(props: PromptProps) {
ref: { type: "agent" as const, index },
styleId: agentStyleId,
})),
...(prompt.skills ?? []).map((part, index) => ({
mention: part.mention,
ref: { type: "skill" as const, index },
styleId: skillStyleId,
})),
...prompt.pasted.map((part, index) => ({
mention: part.source,
ref: { type: "pasted" as const, index },
@@ -671,6 +695,7 @@ export function Prompt(props: PromptProps) {
const newMap = new Map<number, PromptPartRef>()
const files: NonNullable<PromptInfo["files"]> = []
const agents: NonNullable<PromptInfo["agents"]> = []
const skills: NonNullable<PromptInfo["skills"]> = []
const pasted: PromptInfo["pasted"] = []
for (const extmark of allExtmarks) {
@@ -696,6 +721,16 @@ export function Prompt(props: PromptProps) {
newMap.set(extmark.id, { type: "agent", index })
continue
}
if (ref.type === "skill") {
const part = draft.prompt.skills?.[ref.index]
if (!part?.mention) continue
part.mention.start = extmark.start
part.mention.end = extmark.end
const index = skills.length
skills.push(part)
newMap.set(extmark.id, { type: "skill", index })
continue
}
const part = draft.prompt.pasted[ref.index]
if (!part) continue
part.source.start = extmark.start
@@ -708,6 +743,7 @@ export function Prompt(props: PromptProps) {
draft.extmarkToPart = newMap
draft.prompt.files = files
draft.prompt.agents = agents
draft.prompt.skills = skills
draft.prompt.pasted = pasted
}),
)
@@ -983,6 +1019,7 @@ export function Prompt(props: PromptProps) {
)
const slashHead = parseSlashHead(inputText, /\s/)
const isSkill =
!(store.prompt.skills?.length ?? 0) &&
slashHead !== undefined &&
(data.location.skill.list(currentLocation.ref) ?? []).some(
(skill) => skill.slash === true && skill.id === slashHead.name,
@@ -1080,6 +1117,7 @@ export function Prompt(props: PromptProps) {
model,
files: store.prompt.files,
agents: store.prompt.agents,
skills: store.prompt.skills?.length ? store.prompt.skills : undefined,
delivery,
})
.catch((error) => {
@@ -1146,6 +1184,7 @@ export function Prompt(props: PromptProps) {
text: inputText,
files: store.prompt.files,
agents: store.prompt.agents,
skills: store.prompt.skills?.length ? store.prompt.skills : undefined,
delivery,
})
.then(
@@ -1685,6 +1724,8 @@ export function Prompt(props: PromptProps) {
value={store.prompt.text}
fileStyleId={fileStyleId}
agentStyleId={agentStyleId}
skillStyleId={skillStyleId}
hasSkill={(id) => store.prompt.skills?.some((skill) => skill.id === id) ?? false}
promptPartTypeId={() => promptPartTypeId}
/>
</>
+73 -22
View File
@@ -21,6 +21,7 @@ import {
isExitCommand,
isCompactCommand,
mentionTriggerIndex,
slashTriggerIndex,
isNewCommand,
movePromptHistory,
promptCopy,
@@ -50,7 +51,7 @@ export const TEXTAREA_MIN_ROWS = 1
const TEXTAREA_MAX_ROWS = 6
export const PROMPT_MAX_ROWS = TEXTAREA_MAX_ROWS + AUTOCOMPLETE_ROWS - 1 + AUTOCOMPLETE_BOTTOM_ROWS
type Mention = Extract<RunPromptPart, { type: "file" | "agent" }>
type Mention = Extract<RunPromptPart, { type: "file" | "agent" | "skill" }>
type Auto = RunFooterMenuItem & {
kind: "mention"
@@ -65,7 +66,12 @@ type SlashOption = RunFooterMenuItem & {
action?: "skill-menu" | "editor" | "settings"
}
type PromptOption = Auto | SlashOption
type SkillOption = RunFooterMenuItem & {
kind: "skill"
id: string
}
type PromptOption = Auto | SlashOption | SkillOption
type MenuMode = false | "mention" | "slash"
@@ -124,12 +130,9 @@ function emptyPrompt(shell: boolean): RunPrompt {
}
function slashQuery(text: string, cursor: number) {
const head = parseSlashHead(text.slice(0, cursor))
if (!head || head.end !== cursor) {
return
}
return head.name
const at = slashTriggerIndex(text, cursor)
if (at === undefined) return
return { at, value: displaySlice(text, at + 1, cursor) }
}
function parseSlashCommand(text: string, commands: RunCommand[] | undefined) {
@@ -382,10 +385,18 @@ export function createPromptState(input: PromptInput): PromptState {
)
const mentionOptions = createMemo(() => [...agents(), ...files(), ...references()])
const skillCommands = createMemo(() => (input.commands() ?? []).filter((item) => item.source === "skill"))
const skillOptions = createMemo<SkillOption[]>(() =>
skillCommands().map((item) => ({
kind: "skill",
id: item.name,
display: `/${item.name}`,
description: item.description,
})),
)
const hasSkillsCommand = createMemo(() =>
(input.commands() ?? []).some((item) => item.source !== "skill" && item.name === "skills"),
)
const slashOptions = createMemo<SlashOption[]>(() => {
const slashOptions = createMemo<Array<SlashOption | SkillOption>>(() => {
const builtins = [
{
kind: "slash",
@@ -417,6 +428,7 @@ export function createPromptState(input: PromptInput): PromptState {
}
return [
...skillOptions(),
...(showSkillMenu
? [
{
@@ -443,7 +455,7 @@ export function createPromptState(input: PromptInput): PromptState {
].sort((a, b) => a.display.localeCompare(b.display))
})
const options = createMemo<PromptOption[]>(() => {
const mixed: PromptOption[] = mode() === "slash" ? slashOptions() : mentionOptions()
const mixed: PromptOption[] = mode() === "slash" ? (at() === 0 ? slashOptions() : skillOptions()) : mentionOptions()
if (!query()) {
return mixed
}
@@ -459,7 +471,11 @@ export function createPromptState(input: PromptInput): PromptState {
return fuzzysort
.go(next, mixed, {
keys: [(item) => (item.kind === "mention" ? item.value : item.name).trimEnd(), "display", "description"],
keys: [
(item) => (item.kind === "mention" ? item.value : item.kind === "skill" ? item.id : item.name).trimEnd(),
"display",
"description",
],
})
.map((item) => item.obj)
})
@@ -516,13 +532,15 @@ export function createPromptState(input: PromptInput): PromptState {
const prev =
part.type === "agent"
? (part.source?.value ?? "@" + part.name)
: (part.source?.text.value ?? "@" + (part.filename ?? ""))
: part.type === "skill"
? (part.source?.value ?? "/" + part.id)
: (part.source?.text.value ?? "@" + (part.filename ?? ""))
if (text !== prev) {
continue
}
const copy = structuredClone(part)
if (copy.type === "agent") {
if (copy.type === "agent" || copy.type === "skill") {
copy.source = {
start: item.start,
end: item.end,
@@ -558,7 +576,7 @@ export function createPromptState(input: PromptInput): PromptState {
const restoreParts = (value: RunPromptPart[]) => {
clearParts()
parts = value
.filter((item): item is Mention => item.type === "file" || item.type === "agent")
.filter((item): item is Mention => item.type === "file" || item.type === "agent" || item.type === "skill")
.map((item) => structuredClone(item))
if (!area || area.isDestroyed || type === 0) {
return
@@ -566,8 +584,8 @@ export function createPromptState(input: PromptInput): PromptState {
const box = area
parts.forEach((item, idx) => {
const start = item.type === "agent" ? item.source?.start : item.source?.text.start
const end = item.type === "agent" ? item.source?.end : item.source?.text.end
const start = item.type === "file" ? item.source?.text.start : item.source?.start
const end = item.type === "file" ? item.source?.text.end : item.source?.end
if (start === undefined || end === undefined) {
return
}
@@ -627,16 +645,16 @@ export function createPromptState(input: PromptInput): PromptState {
return
}
setAt(0)
setQuery(slash)
setAt(slash.at)
setQuery(slash.value)
return
}
if (slash !== undefined) {
setAt(0)
setAt(slash.at)
menu.reset()
setMode("slash")
setQuery(slash)
setQuery(slash.value)
return
}
@@ -782,7 +800,7 @@ export function createPromptState(input: PromptInput): PromptState {
}
const cursor = area.cursorOffset
const startOffset = mode() === "slash" ? 0 : at()
const startOffset = at()
area.cursorOffset = startOffset
const start = area.logicalCursor
area.cursorOffset = cursor
@@ -828,6 +846,39 @@ export function createPromptState(input: PromptInput): PromptState {
return
}
if (next.kind === "skill") {
if (parts.some((part) => part.type === "skill" && part.id === next.id)) {
cancelAutocomplete()
return
}
const cursor = area.cursorOffset
const tail = displayCharAt(area.plainText, cursor)
const append = `/${next.id}${tail === " " ? "" : " "}`
area.cursorOffset = at()
const start = area.logicalCursor
area.cursorOffset = cursor
const end = area.logicalCursor
area.deleteRange(start.row, start.col, end.row, end.col)
area.insertText(append)
const text = `/${next.id}`
const startOffset = at()
const endOffset = startOffset + stringWidth(text)
const part: Extract<RunPromptPart, { type: "skill" }> = {
type: "skill",
id: next.id,
source: { start: startOffset, end: endOffset, value: text },
}
const id = area.extmarks.create({ start: startOffset, end: endOffset, virtual: true, typeId: type })
marks.set(id, parts.length)
parts.push(part)
hide()
syncDraft()
scheduleRows()
area.focus()
return
}
if (next.kind === "slash") {
if (next.action === "editor") {
void openEditor({
@@ -1193,7 +1244,7 @@ export function createPromptState(input: PromptInput): PromptState {
}
const parsed =
command || next.mode === "shell" || isNewCommand(next.text)
command || next.parts.some((part) => part.type === "skill") || next.mode === "shell" || isNewCommand(next.text)
? undefined
: parseSlashCommand(next.text, input.commands())
if (parsed?.type === "pending") {
+5 -5
View File
@@ -2,7 +2,7 @@ import type { RunPromptPart } from "./types"
import { realignPromptMentions } from "../prompt/mention"
import { parseSlashHead } from "../prompt/parse"
type Mention = Extract<RunPromptPart, { type: "file" | "agent" }>
type Mention = Extract<RunPromptPart, { type: "file" | "agent" | "skill" }>
export function resolveEditorSlashValue(text: string) {
const head = parseSlashHead(text)
@@ -17,13 +17,13 @@ export function realignEditorPromptParts(content: string, parts: RunPromptPart[]
const matches = realignPromptMentions(
content,
parts.map((part) => {
if (part.type !== "file" && part.type !== "agent") return
if (part.type !== "file" && part.type !== "agent" && part.type !== "skill") return
return promptPartMention(part)
}),
)
return parts.flatMap((part, index) => {
if (part.type !== "file" && part.type !== "agent") return [part]
if (part.type !== "file" && part.type !== "agent" && part.type !== "skill") return [part]
const mention = promptPartMention(part)
if (!mention?.text) return [part]
const match = matches[index]
@@ -32,13 +32,13 @@ export function realignEditorPromptParts(content: string, parts: RunPromptPart[]
}
function promptPartMention(part: Mention) {
const source = part.type === "agent" ? part.source : part.source?.text
const source = part.type === "file" ? part.source?.text : part.source
if (!source) return
return { start: source.start, end: source.end, text: source.value }
}
function updatePromptPart(part: Mention, start: number, end: number, text: string): Mention {
if (part.type === "agent") {
if (part.type === "agent" || part.type === "skill") {
return {
...part,
source: {
+1 -1
View File
@@ -7,7 +7,7 @@
// the current browse position. When the user arrows up at cursor offset 0,
// the current draft is saved and history begins. Arrowing past the end
// restores the draft.
export { displayCharAt, displaySlice, mentionTriggerIndex } from "../prompt/display"
export { displayCharAt, displaySlice, mentionTriggerIndex, slashTriggerIndex } from "../prompt/display"
import { stringWidth } from "../util/string-width"
import type { RunPrompt } from "./types"
+24 -3
View File
@@ -288,6 +288,21 @@ function promptAgents(next: SessionTurnInput) {
)
}
function promptSkills(next: SessionTurnInput) {
return next.prompt.parts.flatMap((part) =>
part.type === "skill"
? [
{
id: part.id,
mention: part.source
? { start: part.source.start, end: part.source.end, text: part.source.value }
: undefined,
},
]
: [],
)
}
function streamPartKey(messageID: string, partID: string) {
return `${messageID}\u0000${partID}`
}
@@ -358,12 +373,12 @@ const catalogEvents = new Set([
// briefly so the output commit renders inside it.
const SHELL_OUTPUT_GRACE_MS = 1500
function skillCommit(messageID: string, name: string): StreamCommit {
function skillCommit(messageID: string, name: string, skillID = messageID): StreamCommit {
return {
kind: "system",
source: "system",
messageID,
partID: `skill:${messageID}`,
partID: `skill:${skillID}`,
text: `→ Skill "${name}"`,
phase: "start",
}
@@ -637,7 +652,10 @@ export async function createSessionTransport(input: StreamInput): Promise<Sessio
state.messageIDs.add(message.id)
if (!render) return
if (reuseVisibleWait && waiting) return
write([{ kind: "user", source: "system", text: message.text, phase: "start", messageID: message.id }])
write([
...(message.skills ?? []).map((skill) => skillCommit(message.id, skill.name, skill.id)),
{ kind: "user", source: "system", text: message.text, phase: "start", messageID: message.id },
])
return
}
if (message.type === "skill") {
@@ -1618,6 +1636,7 @@ export async function createSessionTransport(input: StreamInput): Promise<Sessio
const command = next.prompt.command
const attachments = await prepareAttachments(next, command ? "command" : "prompt", input.readTextFile)
const agents = promptAgents(next)
const skills = promptSkills(next)
if (!command) {
input.trace?.write("send.prompt", { sessionID: input.sessionID, messageID, delivery })
return client.session.prompt(
@@ -1627,6 +1646,7 @@ export async function createSessionTransport(input: StreamInput): Promise<Sessio
text: [next.prompt.text, ...attachments.text].join("\n\n"),
files: attachments.files.length ? attachments.files : undefined,
agents: agents.length ? agents : undefined,
skills: skills.length ? skills : undefined,
delivery,
},
{ signal: next.signal },
@@ -1646,6 +1666,7 @@ export async function createSessionTransport(input: StreamInput): Promise<Sessio
model: selected,
files: attachments.files.length ? attachments.files : undefined,
agents: agents.length ? agents : undefined,
skills: skills.length ? skills : undefined,
delivery,
},
{ signal: next.signal },
+1
View File
@@ -47,6 +47,7 @@ export type RunPromptPart =
}
}
| { type: "agent"; name: string; source?: { start: number; end: number; value: string } }
| { type: "skill"; id: string; source?: { start: number; end: number; value: string } }
export type RunCommand = {
name: string
+10 -1
View File
@@ -1,9 +1,14 @@
import type { Prompt, PromptInput } from "@opencode-ai/schema"
import { Skill } from "@opencode-ai/schema/skill"
import type { Types } from "effect"
export type EditablePromptInput = Types.DeepMutable<PromptInput.Prompt>
export function projectedPromptInput(input: Pick<Prompt, "text" | "files" | "agents">): EditablePromptInput {
type ProjectedPrompt = Pick<Prompt, "text" | "files" | "agents"> & {
readonly skills?: ReadonlyArray<{ readonly id: string; readonly mention?: PromptInput.SkillAttachment["mention"] }>
}
export function projectedPromptInput(input: ProjectedPrompt): EditablePromptInput {
return {
text: input.text,
files: input.files?.map((file) => ({
@@ -16,5 +21,9 @@ export function projectedPromptInput(input: Pick<Prompt, "text" | "files" | "age
name: agent.name,
mention: agent.mention ? { ...agent.mention } : undefined,
})),
skills: input.skills?.map((skill) => ({
id: Skill.ID.make(skill.id),
mention: skill.mention ? { ...skill.mention } : undefined,
})),
}
}
+11
View File
@@ -48,3 +48,14 @@ export function mentionTriggerIndex(value: string, offset = promptOffsetWidth(va
return promptOffsetWidth(text.slice(0, index))
}
}
export function slashTriggerIndex(value: string, offset = promptOffsetWidth(value)) {
const text = displaySlice(value, 0, offset)
for (let index = text.lastIndexOf("/"); index >= 0; index = text.lastIndexOf("/", index - 1)) {
const before = index === 0 ? undefined : text[index - 1]
const query = text.slice(index)
if (before !== undefined && !/\s/.test(before)) continue
if (/\s/.test(query) || query.slice(1).includes("/")) return
return promptOffsetWidth(text.slice(0, index))
}
}
+4 -4
View File
@@ -1,7 +1,7 @@
import path from "path"
import { onMount } from "solid-js"
import { createStore, produce, unwrap } from "solid-js/store"
import type { SessionPromptInput } from "@opencode-ai/client"
import type { PromptInput } from "@opencode-ai/schema"
import type { Types } from "effect"
import { createSimpleContext } from "../context/helper"
import { useTuiPaths } from "../context/runtime"
@@ -16,17 +16,17 @@ export type PastedText = {
}
}
export type PromptInfo = Types.DeepMutable<Pick<SessionPromptInput, "text" | "files" | "agents">> & {
export type PromptInfo = Types.DeepMutable<Pick<PromptInput.Prompt, "text" | "files" | "agents" | "skills">> & {
pasted: PastedText[]
mode?: "normal" | "shell"
}
export type PromptPartRef = {
type: "file" | "agent" | "pasted"
type: "file" | "agent" | "skill" | "pasted"
index: number
}
export const emptyPrompt = (): PromptInfo => ({ text: "", files: [], agents: [], pasted: [] })
export const emptyPrompt = (): PromptInfo => ({ text: "", files: [], agents: [], skills: [], pasted: [] })
export const MAX_HISTORY_ENTRIES = 50
+4
View File
@@ -54,9 +54,11 @@ export function realignPromptMentions(
export function realignPromptInputMentions(content: string, input: PromptInput.Prompt): EditablePromptInput {
const files = input.files ?? []
const agents = input.agents ?? []
const skills = input.skills ?? []
const mentions = realignPromptMentions(content, [
...files.map((file) => file.mention),
...agents.map((agent) => agent.mention),
...skills.map((skill) => skill.mention),
])
const align = <T extends { mention?: PromptMention }>(items: readonly T[] | undefined, offset = 0) =>
items?.flatMap((item, index) => {
@@ -69,6 +71,7 @@ export function realignPromptInputMentions(content: string, input: PromptInput.P
text: content,
files: align(input.files),
agents: align(input.agents, files.length),
skills: align(input.skills, files.length + agents.length),
}
}
@@ -91,6 +94,7 @@ export function expandPromptInputPastedText(
text: expandTrackedPastedText(input.text, ranges),
files: input.files?.map((file) => ({ ...file, mention: shift(file.mention) })),
agents: input.agents?.map((agent) => ({ ...agent, mention: shift(agent.mention) })),
skills: input.skills?.map((skill) => ({ ...skill, mention: shift(skill.mention) })),
}
}
+31 -16
View File
@@ -1631,21 +1631,13 @@ function AssistantFooter(props: { message: SessionMessageAssistant }) {
const interrupted = createMemo(() => props.message.error?.message === "Step interrupted")
return (
<>
<Show when={props.message.error && !interrupted()}>
<box
border={["left"]}
paddingTop={1}
paddingBottom={1}
paddingLeft={2}
backgroundColor={theme.background.default}
customBorderChars={SplitBorder.customBorderChars}
borderColor={theme.text.feedback.error.default}
>
<text fg={theme.text.subdued}>{errorMessage(props.message.error)}</text>
<Show when={props.message.error && !interrupted() && !props.message.retry}>
<box paddingLeft={3}>
<text fg={theme.text.feedback.error.default}>Error: {errorMessage(props.message.error)}</text>
</box>
</Show>
<AssistantRetry retry={props.message.retry} />
<box paddingLeft={3} marginTop={props.message.error && !interrupted() ? 1 : 0}>
<box paddingLeft={3} marginTop={props.message.retry || (props.message.error && !interrupted()) ? 1 : 0}>
<text>
<span style={{ fg: props.message.error ? theme.text.subdued : local.agent.color(props.message.agent) }}>
{Locale.titlecase(props.message.agent)}
@@ -1919,6 +1911,7 @@ function UserMessage(props: { message: SessionMessageUser }) {
const data = useData()
const local = useLocal()
const files = createMemo(() => props.message.files ?? [])
const skills = createMemo(() => props.message.skills ?? [])
const themes = useThemes()
const theme = useTheme("elevated")
const mode = themes.mode
@@ -1934,7 +1927,7 @@ function UserMessage(props: { message: SessionMessageUser }) {
}
return (
<Show when={props.message.text.trim() || files().length}>
<Show when={props.message.text.trim() || files().length || skills().length}>
<box
border={["left"]}
borderColor={delivery() ? theme.border.default : color()}
@@ -1979,6 +1972,28 @@ function UserMessage(props: { message: SessionMessageUser }) {
flexShrink={0}
>
<text fg={theme.text.default}>{props.message.text}</text>
<Show when={skills().length}>
<box flexDirection="row" paddingTop={1} gap={1} flexWrap="wrap">
<For each={skills()}>
{(skill) => (
<text fg={theme.text.default}>
<span
style={{
bg: theme.hue.accent[mode() === "light" ? 700 : 200],
fg: theme.background.default,
bold: true,
}}
>
{" skill "}
</span>
<span style={{ bg: theme.raise(theme.background.default), fg: theme.text.subdued }}>
{` ${skill.name} `}
</span>
</text>
)}
</For>
</box>
</Show>
<Show when={files().length}>
<box flexDirection="row" paddingTop={1} gap={1} flexWrap="wrap">
<For each={files()}>
@@ -2045,9 +2060,9 @@ function AssistantRetry(props: { retry: SessionMessageAssistant["retry"] }) {
return (
<Show when={props.retry}>
{(retry) => (
<box paddingLeft={3} marginTop={1}>
<text fg={theme.text.subdued}>
Retry attempt {retry().attempt} scheduled: {retry().error.message} [{retry().error.type}]
<box paddingLeft={3}>
<text fg={theme.text.feedback.warning.default}>
Retry attempt {retry().attempt} scheduled: {retry().error.message}
</text>
</box>
)}
@@ -1262,6 +1262,44 @@ test("direct footer tags skill slash submissions with their catalog source", asy
}
})
test("direct footer submits a selected leading skill as a prompt attachment", async () => {
const submits: RunPrompt[] = []
const app = await renderFooter({
commands: [command({ name: "formatter", description: "Apply formatter fixes", source: "skill" })],
onSubmit(prompt) {
submits.push(prompt)
return true
},
})
try {
await app.renderOnce()
"/forma".split("").forEach((key) => app.mockInput.pressKey(key))
await app.renderOnce()
app.mockInput.pressEnter()
await app.renderOnce()
"src".split("").forEach((key) => app.mockInput.pressKey(key))
app.mockInput.pressEnter()
await app.renderOnce()
expect(submits).toEqual([
{
text: "/formatter src",
parts: [
{
type: "skill",
id: "formatter",
source: { start: 0, end: 10, value: "/formatter" },
},
],
delivery: "steer",
},
])
} finally {
app.cleanup()
}
})
// OpenTUI currently segfaults Bun while tearing down this composer-to-skill-panel transition.
// Re-enable after the upstream renderer teardown fix lands.
test.skip("direct footer skill picker inserts an editable bound skill command", async () => {
@@ -2749,7 +2749,7 @@ describe("V2 mini transport", () => {
variant: undefined,
prompt: {
messageID: "msg_cmd",
text: "/deploy prod",
text: "/deploy prod /api-design",
parts: [
{
type: "file",
@@ -2757,6 +2757,11 @@ describe("V2 mini transport", () => {
filename: "mentioned.txt",
source: { type: "file", text: { start: 8, end: 12, value: "prod" } },
},
{
type: "skill",
id: "api-design",
source: { start: 13, end: 24, value: "/api-design" },
},
],
command: { name: "deploy", arguments: "prod" },
},
@@ -2779,6 +2784,7 @@ describe("V2 mini transport", () => {
mention: { start: 8, end: 12, text: "prod" },
},
],
skills: [{ id: "api-design", mention: { start: 13, end: 24, text: "/api-design" } }],
delivery: "steer",
})
// Selection rides the command payload; no separate client-side switch.
@@ -2851,6 +2857,75 @@ describe("V2 mini transport", () => {
await transport.close()
})
test("sends inline skill attachments with a normal prompt", async () => {
const events = feed()
events.push(connected())
const client = sdk({ streams: [events] })
const ui = footer()
const transport = await createSessionTransport({
sdk: client,
sessionID: "ses_1",
thinking: false,
footer: ui.api,
})
let request: Parameters<OpenCodeClient["session"]["prompt"]>[0] | undefined
spyOn(client.session, "prompt").mockImplementation((input) => {
request = input
queueMicrotask(() => {
events.push({
id: "evt_prompted",
created: 0,
type: "session.input.promoted",
durable: durable("ses_1"),
data: { sessionID: "ses_1", inputID: "msg_skill_attachment" },
})
events.push({
id: "evt_settled",
created: 0,
type: "session.execution.succeeded",
durable: durable("ses_1"),
data: { sessionID: "ses_1" },
})
})
return ok({
id: input.id ?? "msg_skill_attachment",
sessionID: "ses_1",
type: "user" as const,
data: { text: input.text },
delivery: "steer" as const,
timeCreated: 2,
})
})
await transport.runPromptTurn({
agent: undefined,
model: undefined,
variant: undefined,
prompt: {
messageID: "msg_skill_attachment",
text: "Review this /api-design",
parts: [
{
type: "skill",
id: "api-design",
source: { start: 12, end: 23, value: "/api-design" },
},
],
},
files: [],
includeFiles: false,
})
expect(request).toMatchObject({
sessionID: "ses_1",
id: "msg_skill_attachment",
text: "Review this /api-design",
skills: [{ id: "api-design", mention: { start: 12, end: 23, text: "/api-design" } }],
delivery: "steer",
})
await transport.close()
})
test("refreshes catalogs on connection and location-scoped invalidations", async () => {
const events = feed()
events.push(connected())
+11 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, test } from "bun:test"
import { displayCharAt, displaySlice, mentionTriggerIndex } from "../../src/prompt/display"
import { displayCharAt, displaySlice, mentionTriggerIndex, slashTriggerIndex } from "../../src/prompt/display"
describe("prompt display", () => {
test("uses display-width offsets for mentions", () => {
@@ -30,4 +30,14 @@ describe("prompt display", () => {
expect(mentionTriggerIndex("foo@bar.com")).toBeUndefined()
expect(mentionTriggerIndex("中文 @src file")).toBeUndefined()
})
test("finds slash attachments at token boundaries", () => {
expect(slashTriggerIndex("/")).toBe(0)
expect(slashTriggerIndex("Review this /api-design")).toBe(12)
expect(slashTriggerIndex("中文 /api-design")).toBe(5)
expect(slashTriggerIndex("Review /api design")).toBeUndefined()
expect(slashTriggerIndex("Review /tmp/file.ts")).toBeUndefined()
expect(slashTriggerIndex("https://opencode.ai/docs")).toBeUndefined()
expect(slashTriggerIndex("src/prompt/index.ts")).toBeUndefined()
})
})