From d8c7d7e0ec4a3bb50df9fd72f5b0ed4dfe17b42e Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 5 Nov 2026 20:04:24 +0000 Subject: [PATCH 1/5] test(kiro): reproduce skills missing from Kiro menus (#31645) These tests reproduce pingdotgg/t3code#31645 and fail on main: - KiroProvider: a Kiro session's available_commands_update with a `_meta.kiro.type: "skill"` command never reaches the instance snapshot, so `skills` stays empty. - KiroAdapterV2: a turn starting with `$probe-skill rest` reaches Kiro's session/prompt unchanged (wrapped in T3 instructions) instead of as the `/probe-skill rest` command Kiro runs. AI-assisted; verified with the tests and tools listed above. --- .../Adapters/KiroAdapterV2.test.ts | 71 +++++- apps/server/src/provider/KiroProvider.test.ts | 212 ++++++++++++++++-- 2 files changed, 258 insertions(+), 25 deletions(-) diff --git a/apps/server/src/orchestration-v2/Adapters/KiroAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/KiroAdapterV2.test.ts index 30304449c0f0..7c49ce34693f 100644 --- a/apps/server/src/orchestration-v2/Adapters/KiroAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/KiroAdapterV2.test.ts @@ -307,6 +307,12 @@ const runKiroScript = Effect.fn("runKiroScript")(function* (input: { readonly wrapCancel?: ( send: AcpSessionRuntime.AcpSessionRuntime["Service"]["cancel"], ) => AcpSessionRuntime.AcpSessionRuntime["Service"]["cancel"]; + /** Wraps the runtime's `session/prompt` send. */ + readonly wrapPrompt?: ( + send: AcpSessionRuntime.AcpSessionRuntime["Service"]["prompt"], + ) => AcpSessionRuntime.AcpSessionRuntime["Service"]["prompt"]; + /** The user's message text for every turn. */ + readonly text?: string; readonly drive: (session: { readonly events: Stream.Stream; readonly startTurn: Effect.Effect; @@ -360,11 +366,11 @@ const runKiroScript = Effect.fn("runKiroScript")(function* (input: { fileSystem, ...(input.replayGate === undefined ? {} : { replayGate: input.replayGate }), })(runtimeInput).pipe( - Effect.map((runtime) => - input.wrapCancel === undefined - ? runtime - : { ...runtime, cancel: input.wrapCancel(runtime.cancel) }, - ), + Effect.map((runtime) => ({ + ...runtime, + ...(input.wrapCancel === undefined ? {} : { cancel: input.wrapCancel(runtime.cancel) }), + ...(input.wrapPrompt === undefined ? {} : { prompt: input.wrapPrompt(runtime.prompt) }), + })), ), ...(input.testHooks === undefined ? {} : { testHooks: input.testHooks }), }); @@ -428,7 +434,7 @@ const runKiroScript = Effect.fn("runKiroScript")(function* (input: { createdBy: "user", creationSource: "web", messageId: MessageId.make(`message:${suffix}`), - text: "Say hello", + text: input.text ?? "Say hello", attachments: [], }, modelSelection: turnSelection, @@ -831,6 +837,59 @@ describe("KiroAdapterV2", () => { ); }); +describe("KiroAdapterV2 skills", () => { + // Shaped like kiro-cli 2.37.1's second `available_commands_update` after + // `session/new` with `~/.kiro/skills/probe-skill/SKILL.md` installed. + const skillCommands = update({ + sessionUpdate: "available_commands_update", + availableCommands: [ + { + name: "probe-skill", + description: "A probe skill that checks skill discovery over ACP.", + input: { hint: "optional context" }, + _meta: { + kiro: { + type: "skill", + resource: { resourceType: "skill", source: { origin: "user" } }, + originalName: "probe-skill", + }, + }, + }, + ], + }); + + // Kiro runs a command only from a leading `/name`; T3's `$` picker inserts `$name`. + it.effect("sends a $ skill mention as the /command Kiro runs", () => { + const sent: Array = []; + return runKiroScript({ + scenario: "skill-mention", + text: "$probe-skill rest", + frames: [ + ...openSessionFrames({ + initialize: KIRO_V3_INITIALIZE, + configOptions: [modeOption, autopilotOption("on")], + }), + skillCommands, + turnPrompt, + answer("session/prompt", { stopReason: "end_turn" }), + ...closeSession, + ], + wrapPrompt: (send) => (payload, options) => { + for (const block of payload.prompt) { + if (block.type === "text") sent.push(block.text); + } + return send(payload, options); + }, + drive: ({ events, startTurn }) => + Effect.gen(function* () { + yield* startTurn; + assert.equal(terminalStatus(yield* collectTurn(events)), "completed"); + assert.deepEqual(sent, ["/probe-skill rest"]); + }), + }).pipe(Effect.provide(testLayer), Effect.scoped); + }); +}); + describe("KiroAdapterV2 agents", () => { // A user agent from `~/.kiro/agents` whose config sets `"model": "claude-sonnet-4.5"`. const agentModeOption = (currentValue: string) => ({ diff --git a/apps/server/src/provider/KiroProvider.test.ts b/apps/server/src/provider/KiroProvider.test.ts index 1877c131e315..fe4c66a4843d 100644 --- a/apps/server/src/provider/KiroProvider.test.ts +++ b/apps/server/src/provider/KiroProvider.test.ts @@ -1,7 +1,24 @@ import * as NodeCrypto from "@effect/platform-node/NodeCrypto"; import * as NodeServices from "@effect/platform-node/NodeServices"; import { assert, describe, it } from "@effect/vitest"; +import { + MessageId, + NodeId, + ProjectId, + ProviderInstanceId, + ProviderSessionId, + RunAttemptId, + RunId, + ThreadId, +} from "@t3tools/contracts"; +import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; +import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderSessions"; +import { ProviderAdapterV2RuntimePolicy } from "@t3tools/provider-core/server/ProviderAdapter"; +import * as ProviderEventLoggers from "@t3tools/provider-core/server/ProviderEventLoggers"; +import { KiroDriver } from "@t3tools/provider-kiro/server"; import { KiroSettings } from "@t3tools/provider-kiro/settings"; +import * as TestProviderHost from "@t3tools/provider-testing/TestProviderHost"; +import * as DateTime from "effect/DateTime"; import * as Deferred from "effect/Deferred"; import type * as Duration from "effect/Duration"; import * as Effect from "effect/Effect"; @@ -58,12 +75,15 @@ const decodeRequest = Schema.decodeUnknownSync( Schema.Struct({ id: Schema.Union([Schema.String, Schema.Number]), method: Schema.String }), ), ); +const KIRO_SESSION_ID = "sess_kiro-skills"; /** * A `kiro-cli acp` that answers `initialize` and `_kiro/config/template` and - * fails anything else, so a probe that opened a session would fail. + * fails anything else, so a probe that opened a session would fail. Given + * `afterSessionNew`, it also opens sessions, sends those updates right after + * `session/new`, and answers each prompt with one line of text. */ -const acpProcess = (template: unknown) => +const acpProcess = (template: unknown, afterSessionNew?: ReadonlyArray) => Effect.gen(function* () { const output = yield* Queue.unbounded(); const exited = yield* Deferred.make(); @@ -71,34 +91,53 @@ const acpProcess = (template: unknown) => Effect.andThen(Queue.shutdown(output)), Effect.asVoid, ); - const reply = (line: string) => { + let pending = ""; + const send = (message: object) => + Queue.offer(output, encoder.encode(`${JSON.stringify({ jsonrpc: "2.0", ...message })}\n`)); + const sessionUpdate = (update: unknown) => + send({ + method: "session/update", + params: { sessionId: KIRO_SESSION_ID, update }, + }); + const reply = Effect.fnUntraced(function* (line: string) { const request = decodeRequest(line); + const sessions = afterSessionNew !== undefined; + if (sessions && request.method === "session/new") { + yield* send({ id: request.id, result: { sessionId: KIRO_SESSION_ID } }); + yield* Effect.forEach(afterSessionNew, sessionUpdate); + return; + } + if (sessions && request.method === "session/prompt") { + yield* sessionUpdate({ + sessionUpdate: "agent_message_chunk", + content: { type: "text", text: "ok" }, + }); + yield* send({ id: request.id, result: { stopReason: "end_turn" } }); + return; + } const response = request.method === "initialize" ? { result: { protocolVersion: 1, agentCapabilities: {}, authMethods: [] } } : request.method === "_kiro/config/template" ? { result: template } : { error: { code: -32601, message: `${request.method} is not scripted` } }; - return Queue.offer( - output, - encoder.encode(`${JSON.stringify({ jsonrpc: "2.0", id: request.id, ...response })}\n`), - ); - }; + yield* send({ id: request.id, ...response }); + }); return ChildProcessSpawner.makeHandle({ pid: ChildProcessSpawner.ProcessId(900_000_003), exitCode: Deferred.await(exited), isRunning: Deferred.isDone(exited).pipe(Effect.map((done) => !done)), kill: () => terminate, unref: Effect.succeed(Effect.void), - stdin: Sink.forEach((bytes: Uint8Array) => - Effect.forEach( - new TextDecoder() - .decode(bytes) - .split("\n") - .filter((line) => line.trim().length > 0), + stdin: Sink.forEach((bytes: Uint8Array) => { + // A prompt can arrive split across writes. + const lines = (pending + new TextDecoder().decode(bytes)).split("\n"); + pending = lines.pop() ?? ""; + return Effect.forEach( + lines.filter((line) => line.trim().length > 0), reply, - ), - ), + ); + }), stdout: Stream.fromQueue(output), stderr: Stream.empty, all: Stream.empty, @@ -108,13 +147,17 @@ const acpProcess = (template: unknown) => }); /** Answers `kiro-cli` invocations by their arguments and records which ran. */ -function kiroCli(outputs: Record, template?: unknown) { +function kiroCli( + outputs: Record, + template?: unknown, + afterSessionNew?: ReadonlyArray, +) { const invoked: Array = []; const spawner = ChildProcessSpawner.make((command) => { const args = ChildProcess.isStandardCommand(command) ? command.args.join(" ") : ""; invoked.push(args); - return args === KIRO_ACP_ARGS && template !== undefined - ? acpProcess(template) + return args === KIRO_ACP_ARGS && (template !== undefined || afterSessionNew !== undefined) + ? acpProcess(template, afterSessionNew) : Effect.succeed(processHandle(outputs[args] ?? { stdout: "", code: 127 })); }); return { invoked, spawner }; @@ -484,4 +527,135 @@ describe("KiroProvider", () => { ); }), ); + + // Shaped like kiro-cli 2.37.1's second `available_commands_update` after + // `session/new` with `~/.kiro/skills/probe-skill/SKILL.md` installed. + it.effect("lists the skills a Kiro session advertises", () => + Effect.gen(function* () { + const cli = kiroCli( + { + "--version": { stdout: "kiro-cli 2.37.1\n", code: 0 }, + "whoami --format json": { stdout: "", code: 2 }, + }, + undefined, + [ + { + sessionUpdate: "available_commands_update", + availableCommands: [ + { + name: "probe-skill", + description: "A probe skill that checks skill discovery over ACP.", + input: { hint: "optional context" }, + _meta: { + kiro: { + type: "skill", + resource: { resourceType: "skill", source: { origin: "user" } }, + originalName: "probe-skill", + }, + }, + }, + ], + }, + ], + ); + yield* Effect.gen(function* () { + const instanceId = ProviderInstanceId.make("kiro"); + const instance = yield* KiroDriver.create({ + instanceId, + displayName: "Kiro", + accentColor: undefined, + enabled: true, + environment: [], + config: settings, + }); + const threadId = ThreadId.make("thread-kiro-skills"); + const modelSelection = { instanceId, model: "default" }; + const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + runtimeMode: "full-access", + interactionMode: "default", + cwd: "/workspace", + }); + const session = yield* instance.orchestrationAdapter.openSession({ + threadId, + providerSessionId: ProviderSessionId.make("provider-session-kiro-skills"), + modelSelection, + runtimePolicy, + }); + const providerThread = yield* session.ensureThread({ + threadId, + modelSelection, + runtimePolicy, + }); + const now = yield* DateTime.now; + yield* session.startTurn({ + appThread: { + createdBy: "user", + creationSource: "web", + id: threadId, + projectId: ProjectId.make("project-kiro-skills"), + title: "Kiro skills", + providerInstanceId: instanceId, + modelSelection, + runtimeMode: runtimePolicy.runtimeMode, + interactionMode: "default", + branch: null, + worktreePath: null, + activeProviderThreadId: providerThread.id, + lineage: { parentThreadId: null, relationshipToParent: null, rootThreadId: threadId }, + forkedFrom: null, + createdAt: now, + updatedAt: now, + archivedAt: null, + settledOverride: null, + settledAt: null, + lastVisitedAt: null, + deletedAt: null, + }, + threadId, + runId: RunId.make("run-kiro-skills"), + runOrdinal: 1, + providerTurnOrdinal: 1, + attemptId: RunAttemptId.make("attempt-kiro-skills"), + rootNodeId: NodeId.make("node-kiro-skills"), + providerThread, + message: { + createdBy: "user", + creationSource: "web", + messageId: MessageId.make("message-kiro-skills"), + text: "Say hello", + attachments: [], + }, + modelSelection, + runtimePolicy, + }); + // The turn's reply follows the session's command update. + yield* session.events.pipe( + Stream.takeUntil((event) => event.type === "turn.terminal"), + Stream.runDrain, + ); + const snapshot = yield* instance.snapshot.getSnapshot; + assert.deepEqual( + snapshot.skills.map((skill) => ({ name: skill.name, enabled: skill.enabled })), + [{ name: "probe-skill", enabled: true }], + ); + }).pipe( + Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, cli.spawner), + Effect.scoped, + ); + }).pipe( + Effect.provide( + TestProviderHost.layer().pipe( + Layer.provideMerge(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)), + Layer.provideMerge(IdAllocator.layer), + Layer.provideMerge(McpProviderSessions.layer), + Layer.provideMerge( + Layer.succeed( + ProviderEventLoggers.ProviderEventLoggers, + ProviderEventLoggers.NoOpProviderEventLoggers, + ), + ), + ), + ), + ), + ); }); From d4917d14be2493de2d82868a0f623022cb8dad02 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 5 Nov 2026 20:10:05 +0000 Subject: [PATCH 2/5] fix(kiro): Kiro skills show in the / and $ menus Kiro sends a session's skills only as `available_commands_update` entries with `_meta.kiro.type: "skill"`, and the Kiro flavor ignored that update, so the composer's `/` and `$` menus never listed them. Kiro also runs a command only from a leading `/name`, while T3's picker inserts `$name`. Each Kiro instance now keeps the latest advertised skills in a SubscriptionRef. The adapter writes it from `onAvailableCommandsUpdate`; the driver adds it to every status check and republishes it through `enrichSnapshot`, so a later check no longer clears it. Names are bounded, deduped and given an `acp://skill/` path like ACP registry skills. `rewriteUserText` turns a leading `$name` into `/name` only for an advertised skill; other `$` text is sent unchanged. Fixes pingdotgg/t3code#31645 AI-assisted; verified with the tests and tools listed above. --- packages/provider-kiro/src/server/adapter.ts | 21 +++++- packages/provider-kiro/src/server/driver.ts | 19 ++++++ .../provider-kiro/src/server/skills.test.ts | 39 +++++++++++ packages/provider-kiro/src/server/skills.ts | 67 +++++++++++++++++++ 4 files changed, 144 insertions(+), 2 deletions(-) create mode 100644 packages/provider-kiro/src/server/skills.test.ts create mode 100644 packages/provider-kiro/src/server/skills.ts diff --git a/packages/provider-kiro/src/server/adapter.ts b/packages/provider-kiro/src/server/adapter.ts index 6815b60e8f22..def27c6b5d66 100644 --- a/packages/provider-kiro/src/server/adapter.ts +++ b/packages/provider-kiro/src/server/adapter.ts @@ -15,6 +15,7 @@ import type * as Path from "effect/Path"; import * as Schema from "effect/Schema"; import type * as Scope from "effect/Scope"; import * as Stream from "effect/Stream"; +import * as SubscriptionRef from "effect/SubscriptionRef"; import type * as ChildProcessSpawner from "effect/process/ChildProcessSpawner"; import type * as EffectAcpSchema from "effect-acp/compat"; import * as EffectAcpErrors from "effect-acp/errors"; @@ -50,6 +51,12 @@ import { kiroPermissionDisposition, makeKiroAcpRuntime, } from "./acpSupport.ts"; +import { + type KiroSkills, + kiroSkillCommandText, + kiroSkillsFromCommands, + makeKiroSkills, +} from "./skills.ts"; export const KIRO_PROVIDER = ProviderDriverKind.make("kiro"); /** T3's slug for "Kiro default", and Kiro's documented default model id. */ @@ -193,6 +200,8 @@ export interface KiroAdapterV2Options { * default). Absent, it is `auto`. */ readonly defaultModel?: Effect.Effect; + /** Where the adapter records the skills Kiro sessions advertise; the driver publishes them. */ + readonly skills?: KiroSkills; /** Replaces the `kiro-cli` launch (replay tests). Kiro's session setup still applies. */ readonly makeRuntime?: ( input: AcpAdapterV2RuntimeInput, @@ -523,7 +532,10 @@ function kiroPromptFailure(cause: unknown) { }); } -function makeKiroAcpAdapterFlavor(options: KiroAdapterV2Options): AcpAdapterV2Flavor { +function makeKiroAcpAdapterFlavor( + options: KiroAdapterV2Options, + skills: KiroSkills, +): AcpAdapterV2Flavor { const makeRuntime = options.makeRuntime ?? ((input: AcpAdapterV2RuntimeInput) => { @@ -549,6 +561,9 @@ function makeKiroAcpAdapterFlavor(options: KiroAdapterV2Options): AcpAdapterV2Fl normalizeSessionUpdate: (notification) => stripSteeringNote(normalizeKiroSessionUpdate(notification)), extractSubagentUpdate: extractKiroSubagentUpdate, + onAvailableCommandsUpdate: (commands) => + SubscriptionRef.set(skills, kiroSkillsFromCommands(commands)), + rewriteUserText: (text) => kiroSkillCommandText(skills, text), // See applyKiroModelSelection: `model` arrives after session/new. modelOptionArrivesLate: true, applyModelSelection: applyKiroModelSelection( @@ -581,7 +596,7 @@ export const makeKiroAdapterV2 = Effect.fn("makeKiroAdapterV2")(function* ( ) { return yield* makeAcpAdapterV2({ instanceId: options.instanceId, - flavor: makeKiroAcpAdapterFlavor(options), + flavor: makeKiroAcpAdapterFlavor(options, options.skills ?? (yield* makeKiroSkills())), selfInvocation: options.selfInvocation, ...(options.nativeLogging === undefined ? {} : { nativeLogging: options.nativeLogging }), ...(options.testHooks === undefined ? {} : { testHooks: options.testHooks }), @@ -601,6 +616,7 @@ export type KiroAdapterV2DriverEnv = /** `defaultModel` reads Kiro's id for "Kiro default" from the provider snapshot. */ export const makeKiroAdapterV2Driver = ( defaultModel: Effect.Effect, + skills: KiroSkills, ): ProviderAdapterDriver => ({ driverKind: KIRO_PROVIDER, configSchema: KiroSettings, @@ -617,6 +633,7 @@ export const makeKiroAdapterV2Driver = ( environment: yield* mergeProviderInstanceEnvironment(input.environment, hostEnvironment), selfInvocation, defaultModel, + skills, nativeLogging: (threadId) => makeNativeLogger({ nativeEventLogger: providerEventLoggers.native, diff --git a/packages/provider-kiro/src/server/driver.ts b/packages/provider-kiro/src/server/driver.ts index b0cfaa0248ec..87d48be74f37 100644 --- a/packages/provider-kiro/src/server/driver.ts +++ b/packages/provider-kiro/src/server/driver.ts @@ -4,6 +4,8 @@ import * as HostProcess from "@t3tools/shared/HostProcess"; import * as SecureRandom from "effect/crypto/SecureRandom"; import * as Effect from "effect/Effect"; import * as Schema from "effect/Schema"; +import * as Stream from "effect/Stream"; +import * as SubscriptionRef from "effect/SubscriptionRef"; import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner"; import type * as ProviderHost from "@t3tools/provider-core/server/ProviderHost"; @@ -29,6 +31,7 @@ import { checkKiroProviderStatus, kiroDefaultModelId, } from "./status.ts"; +import { makeKiroSkills } from "./skills.ts"; const DRIVER_KIND = ProviderDriverKind.make("kiro"); const decodeKiroSettings = Schema.decodeSync(KiroSettings); @@ -97,6 +100,8 @@ export const KiroDriver: ProviderDriver = { }); const effectiveConfig = { ...config, enabled } satisfies KiroSettings; const snapshotSettings = yield* makeProviderSnapshotSettingsSource(effectiveConfig); + // Kiro lists skills only to a running session, so a status check keeps the latest list. + const skills = yield* makeKiroSkills(); const snapshot = yield* makeManagedServerProvider>({ resolveMaintenance: () => Effect.succeed(MAINTENANCE), getSettings: snapshotSettings.getSettings, @@ -106,9 +111,22 @@ export const KiroDriver: ProviderDriver = { buildInitialKiroProviderSnapshot(settings.provider).pipe(Effect.map(stampIdentity)), checkProvider: checkKiroProviderStatus(effectiveConfig, processEnv).pipe( Effect.map(stampIdentity), + Effect.flatMap((checked) => + SubscriptionRef.get(skills).pipe( + Effect.map((current) => ({ ...checked, skills: current })), + ), + ), Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner), Effect.provideService(SecureRandom.SecureRandom, crypto), ), + enrichSnapshot: ({ getSnapshot, publishSnapshot }) => + SubscriptionRef.changes(skills).pipe( + Stream.runForEach((current) => + getSnapshot.pipe( + Effect.flatMap((snapshot) => publishSnapshot({ ...snapshot, skills: current })), + ), + ), + ), }).pipe( Effect.mapError( (cause) => @@ -125,6 +143,7 @@ export const KiroDriver: ProviderDriver = { // "Kiro default" selects the default the snapshot read from Kiro's model list. const orchestrationAdapter = yield* makeKiroAdapterV2Driver( snapshot.getSnapshot.pipe(Effect.map((current) => kiroDefaultModelId(current.models))), + skills, ) .create({ instanceId, displayName, accentColor, environment, enabled, config }) .pipe( diff --git a/packages/provider-kiro/src/server/skills.test.ts b/packages/provider-kiro/src/server/skills.test.ts new file mode 100644 index 000000000000..b776d53cf776 --- /dev/null +++ b/packages/provider-kiro/src/server/skills.test.ts @@ -0,0 +1,39 @@ +import { assert, describe, it } from "@effect/vitest"; +import * as Effect from "effect/Effect"; +import * as SubscriptionRef from "effect/SubscriptionRef"; + +import { kiroSkillCommandText, kiroSkillsFromCommands, makeKiroSkills } from "./skills.ts"; + +const skill = (name: string) => ({ + name, + description: `${name} skill`, + _meta: { kiro: { type: "skill" } }, +}); + +describe("kiroSkillsFromCommands", () => { + it("keeps only skill commands, once each", () => { + const skills = kiroSkillsFromCommands([ + skill("deploy"), + skill("Deploy"), + { name: "reviewer", description: "", _meta: { kiro: { type: "custom-agent" } } }, + { name: "compact", description: "Compact the conversation" }, + ]); + assert.deepEqual( + skills.map(({ name, path }) => ({ name, path })), + [{ name: "deploy", path: "acp://skill/deploy" }], + ); + }); +}); + +describe("kiroSkillCommandText", () => { + it.effect("rewrites only a leading mention of an advertised skill", () => + Effect.gen(function* () { + const skills = yield* makeKiroSkills(); + yield* SubscriptionRef.set(skills, kiroSkillsFromCommands([skill("deploy")])); + assert.equal(yield* kiroSkillCommandText(skills, " $deploy now"), "/deploy now"); + assert.equal(yield* kiroSkillCommandText(skills, "$deployer now"), "$deployer now"); + assert.equal(yield* kiroSkillCommandText(skills, "$25 please"), "$25 please"); + assert.equal(yield* kiroSkillCommandText(skills, "run $deploy"), "run $deploy"); + }), + ); +}); diff --git a/packages/provider-kiro/src/server/skills.ts b/packages/provider-kiro/src/server/skills.ts new file mode 100644 index 000000000000..c32e2f44f6ec --- /dev/null +++ b/packages/provider-kiro/src/server/skills.ts @@ -0,0 +1,67 @@ +import type { ServerProviderSkill } from "@t3tools/contracts"; +import * as Effect from "effect/Effect"; +import * as Option from "effect/Option"; +import * as Schema from "effect/Schema"; +import * as SubscriptionRef from "effect/SubscriptionRef"; +import type * as EffectAcpSchema from "effect-acp/compat"; + +const MAX_SKILLS = 128; +const MAX_NAME_LENGTH = 128; +const MAX_DESCRIPTION_LENGTH = 1_024; +// Anchored and unambiguous (`\s*` then a literal `$`), so it scans the text once. +const LEADING_MENTION = /^\s*\$(\S+)/; + +/** + * The skills the instance's latest Kiro session advertised. Kiro reports them + * only as `available_commands_update` entries with `_meta.kiro.type: "skill"`. + */ +export type KiroSkills = SubscriptionRef.SubscriptionRef>; + +export const makeKiroSkills = (): Effect.Effect => + SubscriptionRef.make>([]); + +const decodeKiroSkillMeta = Schema.decodeUnknownOption( + Schema.Struct({ kiro: Schema.Struct({ type: Schema.Literal("skill") }) }), +); + +export function kiroSkillsFromCommands( + commands: ReadonlyArray, +): ReadonlyArray { + const seen = new Set(); + const skills: Array = []; + for (const command of commands) { + if (skills.length === MAX_SKILLS) break; + if (Option.isNone(decodeKiroSkillMeta(command._meta))) continue; + const { name } = command; + if (name.length === 0 || name.length > MAX_NAME_LENGTH || name !== name.trim()) continue; + const key = name.toLowerCase(); + if (seen.has(key)) continue; + seen.add(key); + const description = command.description.trim().slice(0, MAX_DESCRIPTION_LENGTH); + skills.push({ + name, + ...(description ? { description } : {}), + path: `acp://skill/${encodeURIComponent(name)}`, + scope: "agent", + enabled: true, + }); + } + return skills; +} + +/** + * Kiro runs a command only from a leading `/name`, while T3's `$` picker + * inserts `$name`. Only advertised skills are rewritten, so `$25` stays text. + */ +export const kiroSkillCommandText = (skills: KiroSkills, text: string): Effect.Effect => { + const match = LEADING_MENTION.exec(text); + const name = match?.[1]; + if (match === null || name === undefined) return Effect.succeed(text); + return SubscriptionRef.get(skills).pipe( + Effect.map((current) => + current.some((skill) => skill.name === name) + ? `/${name}${text.slice(match[0].length)}` + : text, + ), + ); +}; From 85654bfb99ff23366185d2da9547e0ec06a0045b Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 5 Nov 2026 20:25:10 +0000 Subject: [PATCH 3/5] fix(kiro): keep Kiro skills across sessions Kiro sends several available_commands_update notifications per session, and the first carries only custom agents. Each one replaced the instance's skill list, so the menus blanked on every session start, a `$skill` first message could go out unrewritten, and one session's skills replaced another's. The instance store now merges each update's skills by case-insensitive name (a newer entry replaces the older one in place, new ones append up to the existing cap) and publishes only when something changed. The menus and the `$name` -> `/name` rewrite both read that store. The Kiro guide gains a short Skills section. AI-assisted; verified with the tests and tools listed above. --- .../Adapters/KiroAdapterV2.test.ts | 41 ++++++++++++++ docs/user/providers-kiro.md | 8 +++ packages/provider-kiro/src/server/adapter.ts | 6 +-- packages/provider-kiro/src/server/driver.ts | 2 +- .../provider-kiro/src/server/skills.test.ts | 53 +++++++++++++------ packages/provider-kiro/src/server/skills.ts | 35 ++++++++++-- 6 files changed, 122 insertions(+), 23 deletions(-) diff --git a/apps/server/src/orchestration-v2/Adapters/KiroAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/KiroAdapterV2.test.ts index 7c49ce34693f..3638566cfe73 100644 --- a/apps/server/src/orchestration-v2/Adapters/KiroAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/KiroAdapterV2.test.ts @@ -888,6 +888,47 @@ describe("KiroAdapterV2 skills", () => { }), }).pipe(Effect.provide(testLayer), Effect.scoped); }); + + // Kiro also sends updates without skills, such as a session's first, agents-only one. + it.effect("keeps advertised skills through an update without skills", () => { + const sent: Array = []; + return runKiroScript({ + scenario: "skill-mention-after-agents-update", + text: "$probe-skill rest", + frames: [ + ...openSessionFrames({ + initialize: KIRO_V3_INITIALIZE, + configOptions: [modeOption, autopilotOption("on")], + }), + skillCommands, + update({ + sessionUpdate: "available_commands_update", + availableCommands: [ + { + name: "reviewer", + description: "Reviews changes", + _meta: { kiro: { type: "custom-agent" } }, + }, + ], + }), + turnPrompt, + answer("session/prompt", { stopReason: "end_turn" }), + ...closeSession, + ], + wrapPrompt: (send) => (payload, options) => { + for (const block of payload.prompt) { + if (block.type === "text") sent.push(block.text); + } + return send(payload, options); + }, + drive: ({ events, startTurn }) => + Effect.gen(function* () { + yield* startTurn; + assert.equal(terminalStatus(yield* collectTurn(events)), "completed"); + assert.deepEqual(sent, ["/probe-skill rest"]); + }), + }).pipe(Effect.provide(testLayer), Effect.scoped); + }); }); describe("KiroAdapterV2 agents", () => { diff --git a/docs/user/providers-kiro.md b/docs/user/providers-kiro.md index 6b94ca14f2e5..94342f3637e9 100644 --- a/docs/user/providers-kiro.md +++ b/docs/user/providers-kiro.md @@ -38,6 +38,14 @@ not listed yet. Refresh the Kiro provider after adding or removing an agent. The thread's model still applies when an agent sets its own `model`. An agent that was removed leaves the thread on Kiro's current agent. +## Skills + +Kiro skills from `~/.kiro/skills` and the project's `.kiro/skills` appear in the `/` and `$` menus +once a Kiro session has started on this server, for example after the first message in a Kiro +thread. Kiro runs a skill only when it starts the message, so put the skill first. A skill you add +later appears after a Kiro session reports it, and one you remove stays listed until the server +restarts. + ## Permission Modes Kiro asks before tool calls such as writes and commands, and T3 Code answers by the permission mode: diff --git a/packages/provider-kiro/src/server/adapter.ts b/packages/provider-kiro/src/server/adapter.ts index def27c6b5d66..ee5f92b2c11c 100644 --- a/packages/provider-kiro/src/server/adapter.ts +++ b/packages/provider-kiro/src/server/adapter.ts @@ -15,7 +15,6 @@ import type * as Path from "effect/Path"; import * as Schema from "effect/Schema"; import type * as Scope from "effect/Scope"; import * as Stream from "effect/Stream"; -import * as SubscriptionRef from "effect/SubscriptionRef"; import type * as ChildProcessSpawner from "effect/process/ChildProcessSpawner"; import type * as EffectAcpSchema from "effect-acp/compat"; import * as EffectAcpErrors from "effect-acp/errors"; @@ -54,8 +53,8 @@ import { import { type KiroSkills, kiroSkillCommandText, - kiroSkillsFromCommands, makeKiroSkills, + recordKiroSkills, } from "./skills.ts"; export const KIRO_PROVIDER = ProviderDriverKind.make("kiro"); @@ -561,8 +560,7 @@ function makeKiroAcpAdapterFlavor( normalizeSessionUpdate: (notification) => stripSteeringNote(normalizeKiroSessionUpdate(notification)), extractSubagentUpdate: extractKiroSubagentUpdate, - onAvailableCommandsUpdate: (commands) => - SubscriptionRef.set(skills, kiroSkillsFromCommands(commands)), + onAvailableCommandsUpdate: (commands) => recordKiroSkills(skills, commands), rewriteUserText: (text) => kiroSkillCommandText(skills, text), // See applyKiroModelSelection: `model` arrives after session/new. modelOptionArrivesLate: true, diff --git a/packages/provider-kiro/src/server/driver.ts b/packages/provider-kiro/src/server/driver.ts index 87d48be74f37..a4e7db7c5588 100644 --- a/packages/provider-kiro/src/server/driver.ts +++ b/packages/provider-kiro/src/server/driver.ts @@ -100,7 +100,7 @@ export const KiroDriver: ProviderDriver = { }); const effectiveConfig = { ...config, enabled } satisfies KiroSettings; const snapshotSettings = yield* makeProviderSnapshotSettingsSource(effectiveConfig); - // Kiro lists skills only to a running session, so a status check keeps the latest list. + // Kiro lists skills only to a running session, so status checks keep what sessions advertised. const skills = yield* makeKiroSkills(); const snapshot = yield* makeManagedServerProvider>({ resolveMaintenance: () => Effect.succeed(MAINTENANCE), diff --git a/packages/provider-kiro/src/server/skills.test.ts b/packages/provider-kiro/src/server/skills.test.ts index b776d53cf776..212876baa43b 100644 --- a/packages/provider-kiro/src/server/skills.test.ts +++ b/packages/provider-kiro/src/server/skills.test.ts @@ -2,34 +2,57 @@ import { assert, describe, it } from "@effect/vitest"; import * as Effect from "effect/Effect"; import * as SubscriptionRef from "effect/SubscriptionRef"; -import { kiroSkillCommandText, kiroSkillsFromCommands, makeKiroSkills } from "./skills.ts"; +import { kiroSkillCommandText, makeKiroSkills, recordKiroSkills } from "./skills.ts"; const skill = (name: string) => ({ name, description: `${name} skill`, _meta: { kiro: { type: "skill" } }, }); +const agent = (name: string) => ({ + name, + description: "", + _meta: { kiro: { type: "custom-agent" } }, +}); -describe("kiroSkillsFromCommands", () => { - it("keeps only skill commands, once each", () => { - const skills = kiroSkillsFromCommands([ - skill("deploy"), - skill("Deploy"), - { name: "reviewer", description: "", _meta: { kiro: { type: "custom-agent" } } }, - { name: "compact", description: "Compact the conversation" }, - ]); - assert.deepEqual( - skills.map(({ name, path }) => ({ name, path })), - [{ name: "deploy", path: "acp://skill/deploy" }], - ); - }); +describe("recordKiroSkills", () => { + it.effect("keeps only skill commands, once each", () => + Effect.gen(function* () { + const skills = yield* makeKiroSkills(); + yield* recordKiroSkills(skills, [ + skill("deploy"), + skill("Deploy"), + agent("reviewer"), + { name: "compact", description: "Compact the conversation" }, + ]); + assert.deepEqual( + (yield* SubscriptionRef.get(skills)).map(({ name, path }) => ({ name, path })), + [{ name: "deploy", path: "acp://skill/deploy" }], + ); + }), + ); + + it.effect("keeps skills from earlier sessions and updates without skills", () => + Effect.gen(function* () { + const skills = yield* makeKiroSkills(); + yield* recordKiroSkills(skills, [skill("deploy-a")]); + yield* recordKiroSkills(skills, [skill("deploy-b")]); + const merged = yield* SubscriptionRef.get(skills); + yield* recordKiroSkills(skills, [agent("reviewer")]); + assert.strictEqual(yield* SubscriptionRef.get(skills), merged); + assert.deepEqual( + merged.map(({ name }) => name), + ["deploy-a", "deploy-b"], + ); + }), + ); }); describe("kiroSkillCommandText", () => { it.effect("rewrites only a leading mention of an advertised skill", () => Effect.gen(function* () { const skills = yield* makeKiroSkills(); - yield* SubscriptionRef.set(skills, kiroSkillsFromCommands([skill("deploy")])); + yield* recordKiroSkills(skills, [skill("deploy")]); assert.equal(yield* kiroSkillCommandText(skills, " $deploy now"), "/deploy now"); assert.equal(yield* kiroSkillCommandText(skills, "$deployer now"), "$deployer now"); assert.equal(yield* kiroSkillCommandText(skills, "$25 please"), "$25 please"); diff --git a/packages/provider-kiro/src/server/skills.ts b/packages/provider-kiro/src/server/skills.ts index c32e2f44f6ec..f8d95266dd7e 100644 --- a/packages/provider-kiro/src/server/skills.ts +++ b/packages/provider-kiro/src/server/skills.ts @@ -12,8 +12,9 @@ const MAX_DESCRIPTION_LENGTH = 1_024; const LEADING_MENTION = /^\s*\$(\S+)/; /** - * The skills the instance's latest Kiro session advertised. Kiro reports them - * only as `available_commands_update` entries with `_meta.kiro.type: "skill"`. + * Every skill the instance's Kiro sessions have advertised since the server + * started. Kiro reports them only as `available_commands_update` entries with + * `_meta.kiro.type: "skill"`, and some updates carry none. */ export type KiroSkills = SubscriptionRef.SubscriptionRef>; @@ -24,7 +25,7 @@ const decodeKiroSkillMeta = Schema.decodeUnknownOption( Schema.Struct({ kiro: Schema.Struct({ type: Schema.Literal("skill") }) }), ); -export function kiroSkillsFromCommands( +function kiroSkillsFromCommands( commands: ReadonlyArray, ): ReadonlyArray { const seen = new Set(); @@ -49,6 +50,34 @@ export function kiroSkillsFromCommands( return skills; } +function mergeKiroSkills( + current: ReadonlyArray, + incoming: ReadonlyArray, +): Option.Option> { + let merged: Array | undefined; + for (const skill of incoming) { + const list = merged ?? current; + const key = skill.name.toLowerCase(); + const index = list.findIndex((existing) => existing.name.toLowerCase() === key); + const existing = list[index]; + if (existing === undefined && list.length === MAX_SKILLS) continue; + if (existing?.name === skill.name && existing.description === skill.description) continue; + merged ??= [...current]; + if (existing === undefined) merged.push(skill); + else merged[index] = skill; + } + return Option.fromUndefinedOr(merged); +} + +/** Adds an update's skills, replacing same-named ones in place; publishes only on a change. */ +export const recordKiroSkills = ( + skills: KiroSkills, + commands: ReadonlyArray, +): Effect.Effect => + SubscriptionRef.updateSome(skills, (current) => + mergeKiroSkills(current, kiroSkillsFromCommands(commands)), + ); + /** * Kiro runs a command only from a leading `/name`, while T3's `$` picker * inserts `$name`. Only advertised skills are rewritten, so `$25` stays text. From 29495d5349eabb962486b7f7d3841dc7f52b4a9d Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 5 Nov 2026 20:41:26 +0000 Subject: [PATCH 4/5] fix(kiro): list only Kiro's global skills Kiro also advertises a project's `.kiro/skills` (origin "workspace" with a root), and the instance-wide store offered and rewrote those in every other project. The store now records only skills Kiro does not scope to a workspace, and the user guide says project skills are not listed. The skill tests now wait for the skill to reach the store or the instance snapshot before acting, instead of relying on replay order or reading the snapshot after the turn. AI-assisted; verified with the tests and tools listed above. --- .../Adapters/KiroAdapterV2.test.ts | 189 ++++++++++-------- apps/server/src/provider/KiroProvider.test.ts | 18 +- docs/user/providers-kiro.md | 10 +- .../provider-kiro/src/server/skills.test.ts | 26 ++- packages/provider-kiro/src/server/skills.ts | 34 +++- packages/provider-kiro/src/testing.ts | 1 + 6 files changed, 180 insertions(+), 98 deletions(-) diff --git a/apps/server/src/orchestration-v2/Adapters/KiroAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/KiroAdapterV2.test.ts index 3638566cfe73..84c027d447eb 100644 --- a/apps/server/src/orchestration-v2/Adapters/KiroAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/KiroAdapterV2.test.ts @@ -29,6 +29,7 @@ import * as Option from "effect/Option"; import * as Path from "effect/Path"; import * as Schema from "effect/Schema"; import * as Stream from "effect/Stream"; +import * as SubscriptionRef from "effect/SubscriptionRef"; import * as TestClock from "effect/testing/TestClock"; import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner"; import type * as EffectAcpSchema from "effect-acp/compat"; @@ -57,8 +58,10 @@ import { KIRO_PROVIDER, kiroApprovalOptions, kiroAutopilotValue, + type KiroSkills, kiroPermissionDisposition, makeKiroAdapterV2, + makeKiroSkills, } from "@t3tools/provider-kiro/testing"; const testLayer = Layer.mergeAll( @@ -313,6 +316,8 @@ const runKiroScript = Effect.fn("runKiroScript")(function* (input: { ) => AcpSessionRuntime.AcpSessionRuntime["Service"]["prompt"]; /** The user's message text for every turn. */ readonly text?: string; + /** Where the adapter records advertised skills. */ + readonly skills?: KiroSkills; readonly drive: (session: { readonly events: Stream.Stream; readonly startTurn: Effect.Effect; @@ -373,6 +378,7 @@ const runKiroScript = Effect.fn("runKiroScript")(function* (input: { })), ), ...(input.testHooks === undefined ? {} : { testHooks: input.testHooks }), + ...(input.skills === undefined ? {} : { skills: input.skills }), }); // Held frames must not outlive a failed drive and wedge teardown. yield* Effect.addFinalizer(() => Effect.sync(() => input.replayGate?.releaseAll())); @@ -838,97 +844,116 @@ describe("KiroAdapterV2", () => { }); describe("KiroAdapterV2 skills", () => { + const userSkill = (name: string) => ({ + name, + description: "A probe skill that checks skill discovery over ACP.", + input: { hint: "optional context" }, + _meta: { + kiro: { + type: "skill", + resource: { resourceType: "skill", source: { origin: "user" } }, + originalName: name, + }, + }, + }); // Shaped like kiro-cli 2.37.1's second `available_commands_update` after // `session/new` with `~/.kiro/skills/probe-skill/SKILL.md` installed. const skillCommands = update({ sessionUpdate: "available_commands_update", - availableCommands: [ - { - name: "probe-skill", - description: "A probe skill that checks skill discovery over ACP.", - input: { hint: "optional context" }, - _meta: { - kiro: { - type: "skill", - resource: { resourceType: "skill", source: { origin: "user" } }, - originalName: "probe-skill", - }, - }, - }, - ], + availableCommands: [userSkill("probe-skill")], }); + const recordPrompts = (sent: Array) => + ((send) => (payload, options) => { + for (const block of payload.prompt) { + if (block.type === "text") sent.push(block.text); + } + return send(payload, options); + }) satisfies NonNullable[0]["wrapPrompt"]>; + + // The store holds the session's updates in order, so seeing `name` means every earlier one landed. + const awaitSkill = (skills: KiroSkills, name: string) => + SubscriptionRef.changes(skills).pipe( + Stream.takeUntil((current) => current.some((skill) => skill.name === name)), + Stream.runDrain, + ); + // Kiro runs a command only from a leading `/name`; T3's `$` picker inserts `$name`. - it.effect("sends a $ skill mention as the /command Kiro runs", () => { - const sent: Array = []; - return runKiroScript({ - scenario: "skill-mention", - text: "$probe-skill rest", - frames: [ - ...openSessionFrames({ - initialize: KIRO_V3_INITIALIZE, - configOptions: [modeOption, autopilotOption("on")], - }), - skillCommands, - turnPrompt, - answer("session/prompt", { stopReason: "end_turn" }), - ...closeSession, - ], - wrapPrompt: (send) => (payload, options) => { - for (const block of payload.prompt) { - if (block.type === "text") sent.push(block.text); - } - return send(payload, options); - }, - drive: ({ events, startTurn }) => - Effect.gen(function* () { - yield* startTurn; - assert.equal(terminalStatus(yield* collectTurn(events)), "completed"); - assert.deepEqual(sent, ["/probe-skill rest"]); - }), - }).pipe(Effect.provide(testLayer), Effect.scoped); - }); + it.effect("sends a $ skill mention as the /command Kiro runs", () => + Effect.gen(function* () { + const sent: Array = []; + const skills = yield* makeKiroSkills(); + yield* runKiroScript({ + scenario: "skill-mention", + text: "$probe-skill rest", + skills, + frames: [ + ...openSessionFrames({ + initialize: KIRO_V3_INITIALIZE, + configOptions: [modeOption, autopilotOption("on")], + }), + skillCommands, + turnPrompt, + answer("session/prompt", { stopReason: "end_turn" }), + ...closeSession, + ], + wrapPrompt: recordPrompts(sent), + drive: ({ events, startTurn }) => + Effect.gen(function* () { + yield* awaitSkill(skills, "probe-skill"); + yield* startTurn; + assert.equal(terminalStatus(yield* collectTurn(events)), "completed"); + assert.deepEqual(sent, ["/probe-skill rest"]); + }), + }); + }).pipe(Effect.provide(testLayer), Effect.scoped), + ); // Kiro also sends updates without skills, such as a session's first, agents-only one. - it.effect("keeps advertised skills through an update without skills", () => { - const sent: Array = []; - return runKiroScript({ - scenario: "skill-mention-after-agents-update", - text: "$probe-skill rest", - frames: [ - ...openSessionFrames({ - initialize: KIRO_V3_INITIALIZE, - configOptions: [modeOption, autopilotOption("on")], - }), - skillCommands, - update({ - sessionUpdate: "available_commands_update", - availableCommands: [ - { - name: "reviewer", - description: "Reviews changes", - _meta: { kiro: { type: "custom-agent" } }, - }, - ], - }), - turnPrompt, - answer("session/prompt", { stopReason: "end_turn" }), - ...closeSession, - ], - wrapPrompt: (send) => (payload, options) => { - for (const block of payload.prompt) { - if (block.type === "text") sent.push(block.text); - } - return send(payload, options); - }, - drive: ({ events, startTurn }) => - Effect.gen(function* () { - yield* startTurn; - assert.equal(terminalStatus(yield* collectTurn(events)), "completed"); - assert.deepEqual(sent, ["/probe-skill rest"]); - }), - }).pipe(Effect.provide(testLayer), Effect.scoped); - }); + it.effect("keeps advertised skills through an update without skills", () => + Effect.gen(function* () { + const sent: Array = []; + const skills = yield* makeKiroSkills(); + yield* runKiroScript({ + scenario: "skill-mention-after-agents-update", + text: "$probe-skill rest", + skills, + frames: [ + ...openSessionFrames({ + initialize: KIRO_V3_INITIALIZE, + configOptions: [modeOption, autopilotOption("on")], + }), + skillCommands, + update({ + sessionUpdate: "available_commands_update", + availableCommands: [ + { + name: "reviewer", + description: "Reviews changes", + _meta: { kiro: { type: "custom-agent" } }, + }, + ], + }), + // Changes the store after the agents-only update, so the test can see it was handled. + update({ + sessionUpdate: "available_commands_update", + availableCommands: [userSkill("later-skill")], + }), + turnPrompt, + answer("session/prompt", { stopReason: "end_turn" }), + ...closeSession, + ], + wrapPrompt: recordPrompts(sent), + drive: ({ events, startTurn }) => + Effect.gen(function* () { + yield* awaitSkill(skills, "later-skill"); + yield* startTurn; + assert.equal(terminalStatus(yield* collectTurn(events)), "completed"); + assert.deepEqual(sent, ["/probe-skill rest"]); + }), + }); + }).pipe(Effect.provide(testLayer), Effect.scoped), + ); }); describe("KiroAdapterV2 agents", () => { diff --git a/apps/server/src/provider/KiroProvider.test.ts b/apps/server/src/provider/KiroProvider.test.ts index fe4c66a4843d..a9e41ea934ce 100644 --- a/apps/server/src/provider/KiroProvider.test.ts +++ b/apps/server/src/provider/KiroProvider.test.ts @@ -24,6 +24,7 @@ import type * as Duration from "effect/Duration"; import * as Effect from "effect/Effect"; import * as Fiber from "effect/Fiber"; import * as Layer from "effect/Layer"; +import * as Option from "effect/Option"; import * as Queue from "effect/Queue"; import * as Schema from "effect/Schema"; import * as Sink from "effect/Sink"; @@ -568,6 +569,14 @@ describe("KiroProvider", () => { environment: [], config: settings, }); + // Subscribed before the session opens, so the publish cannot slip past it. + const advertised = yield* instance.snapshot.streamChanges.pipe( + Stream.takeUntil((snapshot) => + snapshot.skills.some(({ name }) => name === "probe-skill"), + ), + Stream.runLast, + Effect.forkChild({ startImmediately: true }), + ); const threadId = ThreadId.make("thread-kiro-skills"); const modelSelection = { instanceId, model: "default" }; const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ @@ -628,15 +637,16 @@ describe("KiroProvider", () => { modelSelection, runtimePolicy, }); - // The turn's reply follows the session's command update. yield* session.events.pipe( Stream.takeUntil((event) => event.type === "turn.terminal"), Stream.runDrain, ); - const snapshot = yield* instance.snapshot.getSnapshot; + const snapshot = yield* Fiber.join(advertised); assert.deepEqual( - snapshot.skills.map((skill) => ({ name: skill.name, enabled: skill.enabled })), - [{ name: "probe-skill", enabled: true }], + Option.map(snapshot, ({ skills }) => + skills.map((skill) => ({ name: skill.name, enabled: skill.enabled })), + ), + Option.some([{ name: "probe-skill", enabled: true }]), ); }).pipe( Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, cli.spawner), diff --git a/docs/user/providers-kiro.md b/docs/user/providers-kiro.md index 94342f3637e9..dab61d925d8c 100644 --- a/docs/user/providers-kiro.md +++ b/docs/user/providers-kiro.md @@ -40,11 +40,11 @@ leaves the thread on Kiro's current agent. ## Skills -Kiro skills from `~/.kiro/skills` and the project's `.kiro/skills` appear in the `/` and `$` menus -once a Kiro session has started on this server, for example after the first message in a Kiro -thread. Kiro runs a skill only when it starts the message, so put the skill first. A skill you add -later appears after a Kiro session reports it, and one you remove stays listed until the server -restarts. +Your Kiro skills in `~/.kiro/skills` appear in the `/` and `$` menus once a Kiro session has started +on this server, for example after the first message in a Kiro thread. Skills in a project's +`.kiro/skills` are not listed in the menus. Kiro runs a skill only when it starts the message, so +put the skill first. A skill you add later appears after a Kiro session reports it, and one you +remove stays listed until the server restarts. ## Permission Modes diff --git a/packages/provider-kiro/src/server/skills.test.ts b/packages/provider-kiro/src/server/skills.test.ts index 212876baa43b..99f590c7c215 100644 --- a/packages/provider-kiro/src/server/skills.test.ts +++ b/packages/provider-kiro/src/server/skills.test.ts @@ -4,10 +4,15 @@ import * as SubscriptionRef from "effect/SubscriptionRef"; import { kiroSkillCommandText, makeKiroSkills, recordKiroSkills } from "./skills.ts"; -const skill = (name: string) => ({ +const skill = (name: string, source?: { readonly origin: string; readonly root?: string }) => ({ name, description: `${name} skill`, - _meta: { kiro: { type: "skill" } }, + _meta: { + kiro: { + type: "skill", + ...(source === undefined ? {} : { resource: { resourceType: "skill", source } }), + }, + }, }); const agent = (name: string) => ({ name, @@ -32,6 +37,23 @@ describe("recordKiroSkills", () => { }), ); + // Shaped like kiro-cli 3.0.0, which lists `/.kiro/skills` beside `~/.kiro/skills`. + it.effect("leaves out skills Kiro scopes to a workspace", () => + Effect.gen(function* () { + const skills = yield* makeKiroSkills(); + yield* recordKiroSkills(skills, [ + skill("project-skill", { origin: "workspace", root: "/abs/project/path" }), + skill("user-skill", { origin: "user" }), + ]); + assert.deepEqual( + (yield* SubscriptionRef.get(skills)).map(({ name }) => name), + ["user-skill"], + ); + assert.equal(yield* kiroSkillCommandText(skills, "$project-skill x"), "$project-skill x"); + assert.equal(yield* kiroSkillCommandText(skills, "$user-skill x"), "/user-skill x"); + }), + ); + it.effect("keeps skills from earlier sessions and updates without skills", () => Effect.gen(function* () { const skills = yield* makeKiroSkills(); diff --git a/packages/provider-kiro/src/server/skills.ts b/packages/provider-kiro/src/server/skills.ts index f8d95266dd7e..e17222f8e304 100644 --- a/packages/provider-kiro/src/server/skills.ts +++ b/packages/provider-kiro/src/server/skills.ts @@ -12,9 +12,9 @@ const MAX_DESCRIPTION_LENGTH = 1_024; const LEADING_MENTION = /^\s*\$(\S+)/; /** - * Every skill the instance's Kiro sessions have advertised since the server - * started. Kiro reports them only as `available_commands_update` entries with - * `_meta.kiro.type: "skill"`, and some updates carry none. + * Every global skill the instance's Kiro sessions have advertised since the + * server started. Kiro reports them only as `available_commands_update` entries + * with `_meta.kiro.type: "skill"`, and some updates carry none. */ export type KiroSkills = SubscriptionRef.SubscriptionRef>; @@ -22,9 +22,33 @@ export const makeKiroSkills = (): Effect.Effect => SubscriptionRef.make>([]); const decodeKiroSkillMeta = Schema.decodeUnknownOption( - Schema.Struct({ kiro: Schema.Struct({ type: Schema.Literal("skill") }) }), + Schema.Struct({ + kiro: Schema.Struct({ + type: Schema.Literal("skill"), + resource: Schema.optional( + Schema.Struct({ + source: Schema.optional( + Schema.Struct({ + origin: Schema.optional(Schema.Unknown), + root: Schema.optional(Schema.Unknown), + }), + ), + }), + ), + }), + }), ); +// The store is shared by every project, so a skill Kiro scopes to one workspace stays out. +const isKiroGlobalSkill = (meta: unknown) => + Option.match(decodeKiroSkillMeta(meta), { + onNone: () => false, + onSome: ({ kiro }) => { + const source = kiro.resource?.source; + return source?.origin !== "workspace" && source?.root === undefined; + }, + }); + function kiroSkillsFromCommands( commands: ReadonlyArray, ): ReadonlyArray { @@ -32,7 +56,7 @@ function kiroSkillsFromCommands( const skills: Array = []; for (const command of commands) { if (skills.length === MAX_SKILLS) break; - if (Option.isNone(decodeKiroSkillMeta(command._meta))) continue; + if (!isKiroGlobalSkill(command._meta)) continue; const { name } = command; if (name.length === 0 || name.length > MAX_NAME_LENGTH || name !== name.trim()) continue; const key = name.toLowerCase(); diff --git a/packages/provider-kiro/src/testing.ts b/packages/provider-kiro/src/testing.ts index 3f18a713ad8c..1eced470f298 100644 --- a/packages/provider-kiro/src/testing.ts +++ b/packages/provider-kiro/src/testing.ts @@ -5,6 +5,7 @@ export { kiroPermissionDisposition, makeKiroAcpRuntime, } from "./server/acpSupport.ts"; +export { type KiroSkills, makeKiroSkills } from "./server/skills.ts"; export { checkKiroProviderStatus, kiroAgentDescriptor, From 2252f00ba841eba61b32cabc977f0397515730f0 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 10 Nov 2026 21:33:41 +0000 Subject: [PATCH 5/5] test(kiro): drop adapter test the skills unit test already covers AI-assisted; verified with the tests and tools listed above. --- .../Adapters/KiroAdapterV2.test.ts | 46 ------------------- 1 file changed, 46 deletions(-) diff --git a/apps/server/src/orchestration-v2/Adapters/KiroAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/KiroAdapterV2.test.ts index 84c027d447eb..15910cf1f527 100644 --- a/apps/server/src/orchestration-v2/Adapters/KiroAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/KiroAdapterV2.test.ts @@ -908,52 +908,6 @@ describe("KiroAdapterV2 skills", () => { }); }).pipe(Effect.provide(testLayer), Effect.scoped), ); - - // Kiro also sends updates without skills, such as a session's first, agents-only one. - it.effect("keeps advertised skills through an update without skills", () => - Effect.gen(function* () { - const sent: Array = []; - const skills = yield* makeKiroSkills(); - yield* runKiroScript({ - scenario: "skill-mention-after-agents-update", - text: "$probe-skill rest", - skills, - frames: [ - ...openSessionFrames({ - initialize: KIRO_V3_INITIALIZE, - configOptions: [modeOption, autopilotOption("on")], - }), - skillCommands, - update({ - sessionUpdate: "available_commands_update", - availableCommands: [ - { - name: "reviewer", - description: "Reviews changes", - _meta: { kiro: { type: "custom-agent" } }, - }, - ], - }), - // Changes the store after the agents-only update, so the test can see it was handled. - update({ - sessionUpdate: "available_commands_update", - availableCommands: [userSkill("later-skill")], - }), - turnPrompt, - answer("session/prompt", { stopReason: "end_turn" }), - ...closeSession, - ], - wrapPrompt: recordPrompts(sent), - drive: ({ events, startTurn }) => - Effect.gen(function* () { - yield* awaitSkill(skills, "later-skill"); - yield* startTurn; - assert.equal(terminalStatus(yield* collectTurn(events)), "completed"); - assert.deepEqual(sent, ["/probe-skill rest"]); - }), - }); - }).pipe(Effect.provide(testLayer), Effect.scoped), - ); }); describe("KiroAdapterV2 agents", () => {