GeezerVison is showing github.com — fix(kiro): compaction is refused when Kiro does not advertise _kiro/s… · pingdotgg/t3code@8b23382
File treeExpand file treeCollapse file tree Open diff view settings apps/server/src/orchestration-v2/Adapters
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Adapters/KiroAdapterV2.test.ts +34-6Lines changed: 34 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -18,6 +18,7 @@ import { | 18 | 18 | } from "@t3tools/contracts"; | 19 | 19 | import { resolveSelfInvocation } from "@t3tools/shared/nodeRuntime"; | 20 | 20 | import { htmlRenderFromToolItem } from "@t3tools/shared/toolOutput"; | | 21 | +import * as Cause from "effect/Cause"; | 21 | 22 | import * as DateTime from "effect/DateTime"; | 22 | 23 | import * as Deferred from "effect/Deferred"; | 23 | 24 | import * as Effect from "effect/Effect"; | @@ -38,8 +39,11 @@ import type * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSession | 38 | 39 | import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; | 39 | 40 | import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderSessions"; | 40 | 41 | import { | | 42 | + ProviderAdapterTurnStartError, | 41 | 43 | type ProviderAdapterV2Error, | 42 | 44 | type ProviderAdapterV2Event, | | 45 | + type ProviderAdapterV2TurnInput, | | 46 | + ProviderCompactionUnsupportedError, | 43 | 47 | ProviderAdapterV2RuntimePolicy, | 44 | 48 | } from "@t3tools/provider-core/server/ProviderAdapter"; | 45 | 49 | import { | @@ -316,6 +320,8 @@ const runKiroScript = Effect.fn("runKiroScript")(function* (input: { | 316 | 320 | model: string, | 317 | 321 | options?: ModelSelection["options"], | 318 | 322 | ) => Effect.Effect<void, ProviderAdapterV2Error>; | | 323 | + /** Runs T3's compact action as turn `ordinal`. */ | | 324 | + readonly compact: (ordinal: number) => Effect.Effect<void, ProviderAdapterV2Error>; | 319 | 325 | readonly interrupt: ( | 320 | 326 | providerTurnId: ProviderTurnId, | 321 | 327 | ) => Effect.Effect<void, ProviderAdapterV2Error>; | @@ -390,10 +396,15 @@ const runKiroScript = Effect.fn("runKiroScript")(function* (input: { | 390 | 396 | }); | 391 | 397 | const providerThread = yield* session.ensureThread({ threadId, modelSelection, runtimePolicy }); | 392 | 398 | const now = yield* DateTime.now; | 393 | | - const startTurnOn = (ordinal: number, model: string, options?: ModelSelection["options"]) => { | | 399 | + const turnInput = ( | | 400 | + ordinal: number, | | 401 | + model: string, | | 402 | + options?: ModelSelection["options"], | | 403 | + text = "Say hello", | | 404 | + ): ProviderAdapterV2TurnInput => { | 394 | 405 | const suffix = `${threadId}:${ordinal}`; | 395 | 406 | const turnSelection = { instanceId, model, ...(options === undefined ? {} : { options }) }; | 396 | | - return session.startTurn({ | | 407 | + return { | 397 | 408 | appThread: { | 398 | 409 | createdBy: "user", | 399 | 410 | creationSource: "web", | @@ -428,17 +439,26 @@ const runKiroScript = Effect.fn("runKiroScript")(function* (input: { | 428 | 439 | createdBy: "user", | 429 | 440 | creationSource: "web", | 430 | 441 | messageId: MessageId.make(`message:${suffix}`), | 431 | | - text: "Say hello", | | 442 | + text, | 432 | 443 | attachments: [], | 433 | 444 | }, | 434 | 445 | modelSelection: turnSelection, | 435 | 446 | runtimePolicy, | 436 | | - }); | | 447 | + }; | 437 | 448 | }; | | 449 | + const startTurnOn = (ordinal: number, model: string, options?: ModelSelection["options"]) => | | 450 | + session.startTurn(turnInput(ordinal, model, options)); | | 451 | + const compact = (ordinal: number) => | | 452 | + session.compactThread === undefined | | 453 | + ? Effect.die("Kiro adapter does not offer compactThread") | | 454 | + : session.compactThread( | | 455 | + turnInput(ordinal, modelSelection.model, input.options, "/compact"), | | 456 | + ); | 438 | 457 | yield* input.drive({ | 439 | 458 | events: session.events, | 440 | 459 | startTurn: startTurnOn(1, modelSelection.model, input.options), | 441 | 460 | startTurnOn, | | 461 | + compact, | 442 | 462 | interrupt: (providerTurnId) => session.interruptTurn({ providerThread, providerTurnId }), | 443 | 463 | respond: (requestId, decision) => session.respondToRuntimeRequest({ requestId, decision }), | 444 | 464 | }); | @@ -460,7 +480,7 @@ const terminalStatus = (events: ReadonlyArray<ProviderAdapterV2Event>) => { | 460 | 480 | }; | 461 | 481 |
| 462 | 482 | describe("KiroAdapterV2", () => { | 463 | | - it.effect("opens a session on a deployment that advertises no Kiro extensions", () => | | 483 | + it.effect("opens a session and refuses compaction on a deployment with no Kiro extensions", () => | 464 | 484 | runKiroScript({ | 465 | 485 | scenario: "no-extensions", | 466 | 486 | frames: [ | @@ -476,10 +496,18 @@ describe("KiroAdapterV2", () => { | 476 | 496 | }), | 477 | 497 | answer("session/prompt", { stopReason: "end_turn" }), | 478 | 498 | ], | 479 | | - drive: ({ events, startTurn }) => | | 499 | + drive: ({ events, startTurn, compact }) => | 480 | 500 | Effect.gen(function* () { | 481 | 501 | yield* startTurn; | 482 | 502 | assert.equal(terminalStatus(yield* collectTurn(events)), "completed"); | | 503 | + // `_kiro/session/compact` is not advertised, so T3 must not send it. | | 504 | + const compacted = yield* Effect.exit(compact(2)); | | 505 | + const error = Exit.isFailure(compacted) ? Cause.squash(compacted.cause) : undefined; | | 506 | + assert.instanceOf(error, ProviderAdapterTurnStartError); | | 507 | + assert.instanceOf( | | 508 | + (error as ProviderAdapterTurnStartError).cause, | | 509 | + ProviderCompactionUnsupportedError, | | 510 | + ); | 483 | 511 | }), | 484 | 512 | }).pipe(Effect.provide(testLayer), Effect.scoped), | 485 | 513 | ); | |
Collapse file Copy file name to clipboardExpand all lines: packages/provider-acp/src/server/adapter.ts +21-9Lines changed: 21 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -512,11 +512,19 @@ export interface AcpAdapterV2Flavor { | 512 | 512 | nativeTurnId: string, | 513 | 513 | ) => NonNullable<EffectAcpSchema.ForkSessionRequest["_meta"]>; | 514 | 514 | }; | 515 | | - /** Compacts with the agent's own request, for agents that answer a `/compact` prompt as chat. */ | 516 | | - readonly compactSession?: ( | 517 | | - runtime: AcpSessionRuntime.AcpSessionRuntime["Service"], | 518 | | - sessionId: string, | 519 | | - ) => Effect.Effect<void, EffectAcpErrors.AcpError>; | | 515 | + /** | | 516 | + * Compacts with the agent's own request, for agents that answer a `/compact` prompt as chat. | | 517 | + * Compaction is refused when `supported` rejects the running agent's `initialize` result. | | 518 | + */ | | 519 | + readonly compactSession?: { | | 520 | + readonly supported: ( | | 521 | + initializeResult: AcpSessionRuntime.AcpSessionRuntimeStartResult["initializeResult"], | | 522 | + ) => boolean; | | 523 | + readonly compact: ( | | 524 | + runtime: AcpSessionRuntime.AcpSessionRuntime["Service"], | | 525 | + sessionId: string, | | 526 | + ) => Effect.Effect<void, EffectAcpErrors.AcpError>; | | 527 | + }; | 520 | 528 | readonly runtimeHarness?: string; | 521 | 529 | readonly registerExtensions?: ( | 522 | 530 | context: AcpAdapterV2ExtensionContext, | @@ -8276,11 +8284,15 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( | 8276 | 8284 | } | 8277 | 8285 | } | 8278 | 8286 | // Checked after activation: a loaded session advertises its own commands. | | 8287 | + const compactionSetup = yield* Ref.get(activeSessionSetup); | 8279 | 8288 | if ( | 8280 | | - flavor.compactViaAdvertisedCommand === true && | 8281 | 8289 | isCompactionMessage(turnInput.message) && | 8282 | | - (yield* Ref.get(advertisedCommandNames)).get(requestedSessionId)?.has("compact") !== | 8283 | | - true | | 8290 | + ((flavor.compactViaAdvertisedCommand === true && | | 8291 | + (yield* Ref.get(advertisedCommandNames)).get(requestedSessionId)?.has("compact") !== | | 8292 | + true) || | | 8293 | + (flavor.compactSession !== undefined && | | 8294 | + (compactionSetup === null || | | 8295 | + !flavor.compactSession.supported(compactionSetup.initializeResult)))) | 8284 | 8296 | ) { | 8285 | 8297 | return yield* new ProviderAdapter.ProviderCompactionUnsupportedError({ | 8286 | 8298 | driver, | @@ -8550,7 +8562,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( | 8550 | 8562 | runtime.prompt({ prompt: promptParts!.prompt }, promptOptions), | 8551 | 8563 | ) | 8552 | 8564 | : Deferred.succeed(context.promptDispatched, undefined).pipe( | 8553 | | - Effect.andThen(compactSession(runtime, requestedSessionId)), | | 8565 | + Effect.andThen(compactSession.compact(runtime, requestedSessionId)), | 8554 | 8566 | Effect.as({ stopReason: "end_turn" } satisfies EffectAcpSchema.PromptResponse), | 8555 | 8567 | ) | 8556 | 8568 | ).pipe( | |
Collapse file Copy file name to clipboardExpand all lines: packages/provider-kiro/src/server/adapter.ts +31-19Lines changed: 31 additions & 19 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -93,25 +93,37 @@ const KiroProviderCapabilitiesV2 = { | 93 | 93 | const KiroCompactResult = Schema.Struct({ success: Schema.Boolean }); | 94 | 94 | const decodeKiroCompactResult = Schema.decodeUnknownOption(KiroCompactResult); | 95 | 95 |
| 96 | | -/** Kiro answers a `/compact` prompt as chat, so T3 compacts with Kiro's own request. */ | 97 | | -const compactKiroSession = ( | 98 | | - runtime: AcpSessionRuntime.AcpSessionRuntime["Service"], | 99 | | - sessionId: string, | 100 | | -) => | 101 | | - runtime.request(KIRO_COMPACT_METHOD, { sessionId }).pipe( | 102 | | - Effect.flatMap((result) => | 103 | | - Option.exists(decodeKiroCompactResult(result), (decoded) => decoded.success) | 104 | | - ? Effect.void | 105 | | - : Effect.fail( | 106 | | - new EffectAcpErrors.AcpRequestError({ | 107 | | - code: -32603, | 108 | | - errorMessage: "Kiro could not compact the conversation.", | 109 | | - method: KIRO_COMPACT_METHOD, | 110 | | - data: result, | 111 | | - }), | 112 | | - ), | | 96 | +const decodeKiroExtensionMethods = Schema.decodeUnknownOption( | | 97 | + Schema.Struct({ kiro: Schema.Struct({ extensionMethods: Schema.Array(Schema.String) }) }), | | 98 | +); | | 99 | + | | 100 | +/** | | 101 | + * Kiro answers a `/compact` prompt as chat, so T3 compacts with Kiro's own request, | | 102 | + * on deployments whose `initialize` result lists it among Kiro's extension methods. | | 103 | + */ | | 104 | +const kiroCompactSession = { | | 105 | + supported: ( | | 106 | + initializeResult: AcpSessionRuntime.AcpSessionRuntimeStartResult["initializeResult"], | | 107 | + ) => | | 108 | + Option.exists(decodeKiroExtensionMethods(initializeResult.agentCapabilities?._meta), (meta) => | | 109 | + meta.kiro.extensionMethods.includes(KIRO_COMPACT_METHOD), | 113 | 110 | ), | 114 | | - ); | | 111 | + compact: (runtime: AcpSessionRuntime.AcpSessionRuntime["Service"], sessionId: string) => | | 112 | + runtime.request(KIRO_COMPACT_METHOD, { sessionId }).pipe( | | 113 | + Effect.flatMap((result) => | | 114 | + Option.exists(decodeKiroCompactResult(result), (decoded) => decoded.success) | | 115 | + ? Effect.void | | 116 | + : Effect.fail( | | 117 | + new EffectAcpErrors.AcpRequestError({ | | 118 | + code: -32603, | | 119 | + errorMessage: "Kiro could not compact the conversation.", | | 120 | + method: KIRO_COMPACT_METHOD, | | 121 | + data: result, | | 122 | + }), | | 123 | + ), | | 124 | + ), | | 125 | + ), | | 126 | +}; | 115 | 127 |
| 116 | 128 | const KiroSteerResult = Schema.Struct({ queued: Schema.Literal(true), messageId: Schema.String }); | 117 | 129 | const decodeKiroSteerResult = Schema.decodeUnknownOption(KiroSteerResult); | @@ -568,7 +580,7 @@ function makeKiroAcpAdapterFlavor(options: KiroAdapterV2Options): AcpAdapterV2Fl | 568 | 580 | cancelAfterPromptStarts: { isStart: isKiroPromptActivity, bound: KIRO_CANCEL_HOLD_BOUND }, | 569 | 581 | permissionDisposition: kiroPermissionDisposition, | 570 | 582 | approvalOptions: kiroApprovalOptions, | 571 | | - compactSession: compactKiroSession, | | 583 | + compactSession: kiroCompactSession, | 572 | 584 | steering: kiroSteering, | 573 | 585 | forkFromTurn: kiroForkFromTurn, | 574 | 586 | // Kiro V3 advertises `promptCapabilities.image`; the shared adapter reads it. | |
Collapse file Copy file name to clipboardExpand all lines: packages/provider-kiro/src/server/status.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -90,7 +90,7 @@ const snapshot = ( | 90 | 90 | enabled: settings.enabled, | 91 | 91 | checkedAt, | 92 | 92 | models: kiroModels(settings, listed, agents), | 93 | | - // `/compact` runs `_kiro/session/compact`; see compactKiroSession. | | 93 | + // `/compact` runs `_kiro/session/compact`; see kiroCompactSession. | 94 | 94 | slashCommands: [COMPACT_SLASH_COMMAND], | 95 | 95 | probe, | 96 | 96 | }); | |
|