@codexhost/cli-win32-x64 0.29.2 → 0.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/README.md +1 -1
  2. package/app/codexhost-distribution.json +1 -1
  3. package/app/console-server.mjs +40 -15
  4. package/app/console-web.js +49 -24
  5. package/app/desktop-controller.mjs +53 -28
  6. package/app/host-runtime.mjs +2616 -1978
  7. package/app/plugins/antigravity/plugin.mjs +40 -15
  8. package/app/plugins/claude-code/plugin.mjs +40 -15
  9. package/app/plugins/codebuddy/plugin.mjs +514 -109
  10. package/app/plugins/codex-usage/plugin.mjs +58 -33
  11. package/app/plugins/copilot/plugin.mjs +40 -15
  12. package/app/plugins/cursor-cli/plugin.mjs +40 -15
  13. package/app/plugins/deepseek-harness/plugin.mjs +40 -15
  14. package/app/plugins/devin/plugin.mjs +40 -15
  15. package/app/plugins/grok/plugin.mjs +40 -15
  16. package/app/plugins/hermes/plugin.mjs +40 -15
  17. package/app/plugins/kimi-code/plugin.mjs +40 -15
  18. package/app/plugins/kiro-cli/plugin.mjs +40 -15
  19. package/app/plugins/omp/plugin.mjs +40 -15
  20. package/app/plugins/opencode/plugin.mjs +40 -15
  21. package/app/plugins/pi/plugin.mjs +40 -15
  22. package/app/plugins/qoder/plugin.mjs +40 -15
  23. package/app/plugins/qoder-cn/plugin.mjs +40 -15
  24. package/app/plugins/qwen-code/plugin.mjs +40 -15
  25. package/app/plugins/workbuddy/plugin.mjs +548 -112
  26. package/app/plugins/zcode/plugin.mjs +40 -15
  27. package/app/renderer-extension.js +52 -27
  28. package/app/web/assets/abnfDiagram-XWFEHMT6-BdinLox4.js +1 -0
  29. package/app/web/assets/architectureDiagram-CSQXQB3N-DgPBbtvP.js +36 -0
  30. package/app/web/assets/blockDiagram-BEDRHYPZ-B4ENdwtZ.js +140 -0
  31. package/app/web/assets/bpmnIcons-APHXDYXF-ByGoYv9M.js +1 -0
  32. package/app/web/assets/c4Diagram-M2UUVUY5-DA6Owfyu.js +38 -0
  33. package/app/web/assets/chunk-2Q5K7J3B-Dvh3qOmo.js +1 -0
  34. package/app/web/assets/chunk-3GCGMST5-VIkqueym.js +1 -0
  35. package/app/web/assets/chunk-5VM5RSS4-DTYof_OI.js +15 -0
  36. package/app/web/assets/chunk-7U7NFRK5-Dp7s2dg0.js +88 -0
  37. package/app/web/assets/chunk-CNRTWJTD-TKBKxZLU.js +1 -0
  38. package/app/web/assets/chunk-D5HYT7QG-BRZDovSS.js +1 -0
  39. package/app/web/assets/chunk-EBZ3SEQC-C9USZ3tT.js +2 -0
  40. package/app/web/assets/chunk-JWPE2WC7-BrdvVNVo.js +1 -0
  41. package/app/web/assets/chunk-KTR4FSNJ-C7qwjGba.js +1 -0
  42. package/app/web/assets/chunk-XXDRQBXY-DlSrRuwN.js +1 -0
  43. package/app/web/assets/classDiagram-v2-KXABOMEV-BFvB4kwX.js +217 -0
  44. package/app/web/assets/cose-bilkent-JH36ORCC-UyCAqNvj.js +1 -0
  45. package/app/web/assets/cynefin-EF2NZ3EQ-CwawUbjJ.js +141 -0
  46. package/app/web/assets/cynefinDiagram-NJNITYFG-BaWEIQJ0.js +62 -0
  47. package/app/web/assets/cytoscape.esm-Cm0uQArZ.js +332 -0
  48. package/app/web/assets/d3-scale-4DPf7zan.js +1 -0
  49. package/app/web/assets/dagre-KIHZ2IZ3-B7ENIjLG.js +4 -0
  50. package/app/web/assets/diagram-7YQZDPLS-CxRMU8xq.js +41 -0
  51. package/app/web/assets/diagram-QBROCOUO-qo7sxm4K.js +200 -0
  52. package/app/web/assets/diagram-RJJCUUZO-CQiGMCMe.js +30 -0
  53. package/app/web/assets/diagram-WERXNKYE-D0Jps1As.js +24 -0
  54. package/app/web/assets/diagram-YHHI257C-p4AB8cqK.js +3 -0
  55. package/app/web/assets/diagram-YR4HJLHV-Bh6JKT04.js +24 -0
  56. package/app/web/assets/ebnfDiagram-N527522P-DRac0k4W.js +1 -0
  57. package/app/web/assets/elk-O5DQBFGD-CWTz5SZP.js +27 -0
  58. package/app/web/assets/erDiagram-K3K3BIDK-DE3w4BEY.js +99 -0
  59. package/app/web/assets/flowDiagram-Z6JWZHQI-NYs8bi5t.js +213 -0
  60. package/app/web/assets/ganttDiagram-3PRQTZWP-Bspp9btW.js +292 -0
  61. package/app/web/assets/gitGraphDiagram-VXDFKS5L-ByGW1uvv.js +106 -0
  62. package/app/web/assets/graph-D8UmR1vK.js +1 -0
  63. package/app/web/assets/grid-E2QIVN74-CegebiIw.js +1 -0
  64. package/app/web/assets/{index-aSHN2MIG.css → index-BbmB5VLj.css} +1 -1
  65. package/app/web/assets/{index-0TnaYwHS.js → index-DFPOGLS4.js} +80 -80
  66. package/app/web/assets/infoDiagram-EZ3ZOAHP-CexmsdZx.js +2 -0
  67. package/app/web/assets/ishikawaDiagram-S3EKX5GW-BbWqKhg6.js +70 -0
  68. package/app/web/assets/journeyDiagram-POQNLL5X-27YlCe-1.js +139 -0
  69. package/app/web/assets/kanban-definition-BH5XI6FM-BAhOdeck.js +89 -0
  70. package/app/web/assets/langs/{graphql-ChAeyPkT.js → graphql-D6Z3qcRW.js} +1 -1
  71. package/app/web/assets/langs/{http-BvreBIbD.js → http-XiU9G9In.js} +1 -1
  72. package/app/web/assets/langs/{php-D8omCIuJ.js → php-DL3xwS-7.js} +1 -1
  73. package/app/web/assets/langs/{rst-Do7RLLCS.js → rst-DudRVJ9g.js} +1 -1
  74. package/app/web/assets/langs/{ruby-rH_O_vse.js → ruby-_FqsfqJi.js} +1 -1
  75. package/app/web/assets/langs/{svelte-xZy73wAj.js → svelte-ClsVJoBT.js} +1 -1
  76. package/app/web/assets/langs/{vue-C4DW8agZ.js → vue-BiKMXCyK.js} +1 -1
  77. package/app/web/assets/mermaid.core-sGgCbv5y.js +314 -0
  78. package/app/web/assets/mindmap-definition-WVAN44T4-CsMIX0Lj.js +98 -0
  79. package/app/web/assets/pegDiagram-D4NLKWP3-Cs3LXqn_.js +1 -0
  80. package/app/web/assets/pieDiagram-36ENHN4W-DdQsQX9I.js +39 -0
  81. package/app/web/assets/quadrantDiagram-ZQUDMS73-D1jOKqx_.js +7 -0
  82. package/app/web/assets/railroadDiagram-JIZHGYPL-XulrgX5n.js +1 -0
  83. package/app/web/assets/render-VIF2ZAQL-CSsGw-0I.js +2 -0
  84. package/app/web/assets/requirementDiagram-AXW2TVFA-CT66GXLN.js +84 -0
  85. package/app/web/assets/sankeyDiagram-FBCJTAIF-CNRKebNY.js +40 -0
  86. package/app/web/assets/sequenceDiagram-3LA2ROMG-DVl5y64e.js +169 -0
  87. package/app/web/assets/sizeCapture-2Q2CQKSF-Kg0XxSga.js +1 -0
  88. package/app/web/assets/stateDiagram-v2-ATKHQDJO-DYQnfMsS.js +291 -0
  89. package/app/web/assets/swimlanes-YQL5WMAO-Chqt7pxD.js +1 -0
  90. package/app/web/assets/swimlanesDiagram-UCCPES4V-BfREktNP.js +8 -0
  91. package/app/web/assets/timeline-definition-7Z437IG3-aHFxjIT6.js +120 -0
  92. package/app/web/assets/usecaseDiagram-RDK6N6HP-DsC5tFe4.js +370 -0
  93. package/app/web/assets/vendor-BKfNgqAm.js +666 -0
  94. package/app/web/assets/vennDiagram-SHRQU5PJ-C65oZxFn.js +34 -0
  95. package/app/web/assets/wardleyDiagram-F3OXNVQS-HTkq7DT0.js +78 -0
  96. package/app/web/assets/xychartDiagram-GDYJKCDI-p1LpQ9MH.js +7 -0
  97. package/app/web/codexhost-settings.js +39 -39
  98. package/app/web/index.html +3 -3
  99. package/app/web/plugins/deepseek-ai__dsh-api-remotes/client.js +65 -65
  100. package/app/web/plugins/deepseek-ai__dsh-api-session-controller/client.js +8 -8
  101. package/app/web/plugins/deepseek-ai__dsh-client-locale/client.js +1 -1
  102. package/app/web/plugins/deepseek-ai__dsh-client-ui-chat/client.js +17 -17
  103. package/app/web/plugins/deepseek-ai__dsh-client-ui-codexhost/client.js +16 -16
  104. package/app/web/plugins/deepseek-ai__dsh-client-ui-conversation/client.js +16 -16
  105. package/app/web/plugins/deepseek-ai__dsh-client-ui-layout/client.js +3 -3
  106. package/app/web/plugins/deepseek-ai__dsh-client-ui-permission-presets/client.js +1 -1
  107. package/app/web/plugins/deepseek-ai__dsh-client-ui-plan/client.js +1 -1
  108. package/app/web/plugins/deepseek-ai__dsh-client-ui-sidebar-documentpreview/client.js +9 -9
  109. package/app/web/plugins/deepseek-ai__dsh-client-ui-tool/client.js +18 -18
  110. package/app/web/plugins/deepseek-ai__dsh-client-ui-user-questions/client.js +1 -1
  111. package/app/web/plugins/deepseek-ai__dsh-client-ui-workspace/client.js +14 -14
  112. package/app/web-modules/licenses/DSH-THIRD_PARTY_NOTICES.md +1 -1
  113. package/app/web-modules/server.mjs +348 -118
  114. package/bin/codexhost.exe +0 -0
  115. package/libexec/codexhost-node-repl.exe +0 -0
  116. package/libexec/codexhost-screenshot.exe +0 -0
  117. package/libexec/codexhost-shell.exe +0 -0
  118. package/libexec/codexhost-shim.exe +0 -0
  119. package/libexec/codexhost-updater.exe +0 -0
  120. package/package.json +1 -1
  121. package/app/web/assets/vendor-C9g2bw8s.js +0 -410
@@ -20858,15 +20858,15 @@ var threadOwnershipListResultSchema = external_exports.object({
20858
20858
  threads: external_exports.array(threadOwnershipSchema).min(1).max(THREAD_OWNERSHIP_LIST_MAX_LENGTH)
20859
20859
  }).strict().superRefine(({ threads }, context) => {
20860
20860
  const seen = /* @__PURE__ */ new Set();
20861
- for (const [index, thread2] of threads.entries()) {
20862
- if (seen.has(thread2.threadId)) {
20861
+ for (const [index, thread3] of threads.entries()) {
20862
+ if (seen.has(thread3.threadId)) {
20863
20863
  context.addIssue({
20864
20864
  code: "custom",
20865
20865
  message: "Thread ownership-list results must be unique",
20866
20866
  path: ["threads", index, "threadId"]
20867
20867
  });
20868
20868
  }
20869
- seen.add(thread2.threadId);
20869
+ seen.add(thread3.threadId);
20870
20870
  }
20871
20871
  });
20872
20872
  var threadSteeringInspectParamsSchema = external_exports.object({
@@ -21602,6 +21602,29 @@ var productTelemetryHeartbeatSchema = external_exports.object({
21602
21602
  message: "Telemetry heartbeat must contain at least one countable field"
21603
21603
  });
21604
21604
 
21605
+ // ../../shared-contracts/dist/native-codex-goal.js
21606
+ var NATIVE_CODEX_GOAL_METHOD = "codexhost/thread/goal";
21607
+ var NATIVE_CODEX_GOAL_MAX_OBJECTIVE_CHARS = 4e3;
21608
+ var thread = { threadId: hostThreadIdSchema };
21609
+ var nativeCodexGoalRequestSchema = external_exports.discriminatedUnion("action", [
21610
+ external_exports.strictObject({ ...thread, action: external_exports.enum(["get", "pause", "resume", "clear"]) }),
21611
+ external_exports.strictObject({
21612
+ ...thread,
21613
+ action: external_exports.enum(["create", "edit"]),
21614
+ objective: external_exports.string().trim().min(1).refine((objective) => Array.from(objective).length <= NATIVE_CODEX_GOAL_MAX_OBJECTIVE_CHARS, `A goal objective can have up to ${NATIVE_CODEX_GOAL_MAX_OBJECTIVE_CHARS} characters.`)
21615
+ })
21616
+ ]);
21617
+ var nativeCodexGoalResultSchema = external_exports.object({
21618
+ goal: external_exports.object({
21619
+ threadId: hostThreadIdSchema,
21620
+ objective: external_exports.string(),
21621
+ status: external_exports.enum(["active", "paused", "blocked", "usageLimited", "budgetLimited", "complete"]),
21622
+ tokenBudget: external_exports.int().positive().nullable().default(null),
21623
+ tokensUsed: external_exports.int().nonnegative(),
21624
+ timeUsedSeconds: external_exports.int().nonnegative()
21625
+ }).nullable()
21626
+ });
21627
+
21605
21628
  // ../../shared-contracts/dist/client-channel.js
21606
21629
  var CLIENT_CHANNEL_VERSION = 1;
21607
21630
  var CLIENT_REQUEST_LIMIT_BYTES = 128 * 1024 * 1024;
@@ -21614,10 +21637,12 @@ var CLIENT_CHANNEL_METHODS = [
21614
21637
  "codexhost/harness/display-settings/capabilities",
21615
21638
  "codexhost/harness/preferences/get",
21616
21639
  "codexhost/harness/preferences/patch",
21640
+ "experimentalFeature/list",
21617
21641
  "thread/list",
21618
21642
  "thread/metadata/update",
21619
21643
  "codexhost/thread/catalog/read",
21620
21644
  "thread/read",
21645
+ NATIVE_CODEX_GOAL_METHOD,
21621
21646
  "thread/resume",
21622
21647
  "thread/fork",
21623
21648
  "thread/turns/list",
@@ -23515,7 +23540,7 @@ var identity = external_exports.string().min(1).max(REMOTE_IDENTITY_MAX_LENGTH);
23515
23540
  var target = {
23516
23541
  hostId: identity.regex(/^(?:remote-(?:ssh(?:-|:)|control:)|remote-peer:[a-zA-Z0-9_-]{1,64}$)/u)
23517
23542
  };
23518
- var thread = { ...target, threadId: identity };
23543
+ var thread2 = { ...target, threadId: identity };
23519
23544
  var text = external_exports.string().min(1).max(8e3);
23520
23545
  var input2 = { text, requestId: identity };
23521
23546
  var remoteDeliveryReplySchema = external_exports.discriminatedUnion("accepted", [
@@ -23566,7 +23591,7 @@ var remoteSessionOperationSchema = external_exports.discriminatedUnion("kind", [
23566
23591
  serviceTier: external_exports.enum(["priority", "ultrafast"]).optional(),
23567
23592
  reasoningEffort: identity.optional()
23568
23593
  }),
23569
- external_exports.strictObject({ kind: external_exports.literal("status"), ...thread }),
23594
+ external_exports.strictObject({ kind: external_exports.literal("status"), ...thread2 }),
23570
23595
  external_exports.strictObject({
23571
23596
  kind: external_exports.literal("list"),
23572
23597
  ...target,
@@ -23576,7 +23601,7 @@ var remoteSessionOperationSchema = external_exports.discriminatedUnion("kind", [
23576
23601
  }),
23577
23602
  external_exports.strictObject({
23578
23603
  kind: external_exports.literal("read"),
23579
- ...thread,
23604
+ ...thread2,
23580
23605
  page: external_exports.strictObject({
23581
23606
  cursor: external_exports.string().min(1).max(8192).nullable(),
23582
23607
  epoch: identity.optional(),
@@ -23586,10 +23611,10 @@ var remoteSessionOperationSchema = external_exports.discriminatedUnion("kind", [
23586
23611
  message: "A history continuation requires its connection epoch"
23587
23612
  }).optional()
23588
23613
  }),
23589
- external_exports.strictObject({ kind: external_exports.literal("usage"), ...thread, epoch: identity }),
23614
+ external_exports.strictObject({ kind: external_exports.literal("usage"), ...thread2, epoch: identity }),
23590
23615
  external_exports.strictObject({
23591
23616
  kind: external_exports.literal("configure"),
23592
- ...thread,
23617
+ ...thread2,
23593
23618
  epoch: identity,
23594
23619
  modelId: identity.optional(),
23595
23620
  serviceTier: harnessModelServiceTierSchema.optional(),
@@ -23600,15 +23625,15 @@ var remoteSessionOperationSchema = external_exports.discriminatedUnion("kind", [
23600
23625
  }),
23601
23626
  external_exports.strictObject({
23602
23627
  kind: external_exports.literal("prompt"),
23603
- ...thread,
23628
+ ...thread2,
23604
23629
  epoch: identity,
23605
23630
  text,
23606
23631
  requestId: identity.optional()
23607
23632
  }),
23608
- external_exports.strictObject({ kind: external_exports.literal("queue"), ...thread, epoch: identity }),
23633
+ external_exports.strictObject({ kind: external_exports.literal("queue"), ...thread2, epoch: identity }),
23609
23634
  external_exports.strictObject({
23610
23635
  kind: external_exports.literal("delivery"),
23611
- ...thread,
23636
+ ...thread2,
23612
23637
  epoch: identity,
23613
23638
  action: external_exports.discriminatedUnion("kind", [
23614
23639
  external_exports.strictObject({ kind: external_exports.literal("enqueue"), ...input2 }),
@@ -23622,17 +23647,17 @@ var remoteSessionOperationSchema = external_exports.discriminatedUnion("kind", [
23622
23647
  external_exports.strictObject({ kind: external_exports.literal("sendNow"), itemId: identity })
23623
23648
  ])
23624
23649
  }),
23625
- external_exports.strictObject({ kind: external_exports.literal("interrupt"), ...thread, epoch: identity, turnId: identity }),
23650
+ external_exports.strictObject({ kind: external_exports.literal("interrupt"), ...thread2, epoch: identity, turnId: identity }),
23626
23651
  external_exports.strictObject({
23627
23652
  kind: external_exports.literal("rename"),
23628
- ...thread,
23653
+ ...thread2,
23629
23654
  epoch: identity,
23630
23655
  name: external_exports.string().min(1).max(512)
23631
23656
  }),
23632
- external_exports.strictObject({ kind: external_exports.literal("archive"), ...thread, epoch: identity, archived: external_exports.boolean() }),
23657
+ external_exports.strictObject({ kind: external_exports.literal("archive"), ...thread2, epoch: identity, archived: external_exports.boolean() }),
23633
23658
  external_exports.strictObject({
23634
23659
  kind: external_exports.literal("respond"),
23635
- ...thread,
23660
+ ...thread2,
23636
23661
  epoch: identity,
23637
23662
  requestId: external_exports.union([identity, external_exports.number().int()]),
23638
23663
  result: external_exports.record(external_exports.string(), external_exports.unknown())
@@ -24627,7 +24652,8 @@ var CODEBUDDY_CAPABILITIES = {
24627
24652
  permissionModeScope: "live"
24628
24653
  },
24629
24654
  history: { fork: true, forkAcrossCwd: false, rollbackLastTurn: true },
24630
- subagents: { observe: true, readTranscript: true }
24655
+ subagents: { observe: true, readTranscript: true },
24656
+ autonomousTurns: { observe: true }
24631
24657
  };
24632
24658
  function capabilitiesForProfile(profile = CODEBUDDY_RUNTIME_PROFILE) {
24633
24659
  return {
@@ -25892,6 +25918,52 @@ function snapshotFromHistory(contents, ref, cwd, profile = CODEBUDDY_RUNTIME_PRO
25892
25918
  });
25893
25919
  return { turns };
25894
25920
  }
25921
+ function compactionEvidenceForTurn(contents, snapshot, turnKey, beforeItems, profile = CODEBUDDY_RUNTIME_PROFILE) {
25922
+ if (!nativeCommandsEnabled(profile))
25923
+ return [];
25924
+ const turnIndex = snapshot.turns.findIndex((turn) => turn.nativeTurnRef.nativeTurnKey === turnKey);
25925
+ if (turnIndex < 0)
25926
+ return [];
25927
+ const history = nativeDisplayHistoryRows(contents);
25928
+ const start = history.findIndex((row) => row.type === "message" && row.role === "user" && text2(row.id) === turnKey);
25929
+ if (start < 0)
25930
+ return [];
25931
+ const turnKeys = new Set(snapshot.turns.map((turn) => turn.nativeTurnRef.nativeTurnKey));
25932
+ const attributable = /* @__PURE__ */ new Set();
25933
+ for (let index = start - 1; index >= 0; index -= 1) {
25934
+ const row = history[index];
25935
+ if (!row || !isNativeCompactionSummary(row))
25936
+ break;
25937
+ attributable.add(`compact-${text2(row.id)}`);
25938
+ }
25939
+ let nextTurn = history.length;
25940
+ for (let index = start + 1; index < history.length; index += 1) {
25941
+ const row = history[index];
25942
+ if (row?.type === "message" && row.role === "user" && turnKeys.has(text2(row.id))) {
25943
+ nextTurn = index;
25944
+ break;
25945
+ }
25946
+ }
25947
+ let bodyEnd = nextTurn - 1;
25948
+ if (nextTurn < history.length) {
25949
+ while (bodyEnd > start && isNativeCompactionSummary(history[bodyEnd] ?? {}))
25950
+ bodyEnd -= 1;
25951
+ }
25952
+ for (let index = start + 1; index <= bodyEnd; index += 1) {
25953
+ const row = history[index];
25954
+ if (!row)
25955
+ continue;
25956
+ const data = record3(row.providerData);
25957
+ if (isNativeCompactionSummary(row) || row.role === "assistant" && (data.agent === "compact" || data.isCompactInternal === true)) {
25958
+ attributable.add(`compact-${text2(row.id)}`);
25959
+ }
25960
+ }
25961
+ const candidates = [
25962
+ ...turnIndex > 0 ? snapshot.turns[turnIndex - 1]?.items ?? [] : [],
25963
+ ...snapshot.turns[turnIndex]?.items ?? []
25964
+ ];
25965
+ return candidates.filter(({ item }) => item.type === "contextCompaction" && !beforeItems.has(item.itemId) && attributable.has(item.itemId));
25966
+ }
25895
25967
  function usageCount(value) {
25896
25968
  return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : null;
25897
25969
  }
@@ -30280,6 +30352,31 @@ var CodeBuddyCopyCleanup = class {
30280
30352
  };
30281
30353
 
30282
30354
  // dist/acp-client.js
30355
+ var sessionEndCarrier = "codexhost.codebuddy/sessionEnd";
30356
+ function carrySessionEnd(message) {
30357
+ if (!("method" in message) || message.method !== "session/update")
30358
+ return message;
30359
+ const params = record3(message.params);
30360
+ const update = record3(params.update);
30361
+ if (update.sessionUpdate !== "session_end")
30362
+ return message;
30363
+ return {
30364
+ ...message,
30365
+ params: {
30366
+ ...params,
30367
+ update: { sessionUpdate: "session_info_update", _meta: { [sessionEndCarrier]: update } }
30368
+ }
30369
+ };
30370
+ }
30371
+ function restoreSessionEnd(notification) {
30372
+ const update = notification.update;
30373
+ if (update.sessionUpdate !== "session_info_update" || !update._meta?.[sessionEndCarrier])
30374
+ return notification;
30375
+ return {
30376
+ ...notification,
30377
+ update: update._meta[sessionEndCarrier]
30378
+ };
30379
+ }
30283
30380
  var CodeBuddyAcpClient = class {
30284
30381
  options;
30285
30382
  operationTimeoutMs;
@@ -30330,7 +30427,7 @@ var CodeBuddyAcpClient = class {
30330
30427
  this.#connection = new ClientSideConnection(() => ({
30331
30428
  sessionUpdate: async (notification) => {
30332
30429
  if (!this.#closing && !this.#failure)
30333
- options.handlers.update(notification);
30430
+ options.handlers.update(restoreSessionEnd(notification));
30334
30431
  },
30335
30432
  requestPermission: (request) => !this.#exitFailure && !this.#closing && !this.#failure ? options.handlers.permission(request) : Promise.resolve({ outcome: { outcome: "cancelled" } }),
30336
30433
  extMethod: async (method, params) => {
@@ -30340,13 +30437,24 @@ var CodeBuddyAcpClient = class {
30340
30437
  return { outcome: "cancelled" };
30341
30438
  return options.handlers.question(params);
30342
30439
  }
30343
- }), ndJsonStream2(Writable.toWeb(this.#child.stdin), Readable2.toWeb(this.#copyCleanup?.protocolOutput(this.#child.stdout) ?? (invocation.arguments.includes("--serve") ? codeBuddyAcpOutput(this.#child.stdout) : this.#child.stdout))));
30440
+ }), this.#protocolStream(invocation.arguments.includes("--serve")));
30344
30441
  void this.#connection.closed.then(() => {
30345
30442
  this.#fault(new CodeBuddyError("processExited", "ACP connection closed"));
30346
30443
  }).catch((error62) => {
30347
30444
  this.#fault(error62);
30348
30445
  });
30349
30446
  }
30447
+ #protocolStream(serve) {
30448
+ const stream = ndJsonStream2(Writable.toWeb(this.#child.stdin), Readable2.toWeb(this.#copyCleanup?.protocolOutput(this.#child.stdout) ?? (serve ? codeBuddyAcpOutput(this.#child.stdout) : this.#child.stdout)));
30449
+ return {
30450
+ writable: stream.writable,
30451
+ readable: stream.readable.pipeThrough(new TransformStream({
30452
+ transform: (message, controller) => {
30453
+ controller.enqueue(carrySessionEnd(message));
30454
+ }
30455
+ }))
30456
+ };
30457
+ }
30350
30458
  #fault(error62) {
30351
30459
  if (this.#closing || this.#failure)
30352
30460
  return;
@@ -31582,6 +31690,125 @@ var CodeBuddySessionImport = class {
31582
31690
  }
31583
31691
  };
31584
31692
 
31693
+ // dist/session.js
31694
+ import { randomUUID as randomUUID3 } from "node:crypto";
31695
+
31696
+ // dist/autonomous.js
31697
+ import { Buffer as Buffer3 } from "node:buffer";
31698
+ function readUnsolicitedTurn(update) {
31699
+ if (update.sessionUpdate !== "session_info_update")
31700
+ return;
31701
+ const announcement = record3(record3(update._meta)["codebuddy.ai/unsolicitedTurn"]);
31702
+ return announcement.reason === "background_drain" ? text2(announcement.requestId) || void 0 : void 0;
31703
+ }
31704
+ var AutonomousBufferBudget = class {
31705
+ #frames = 0;
31706
+ #bytes = 0;
31707
+ hold(value) {
31708
+ const bytes = Buffer3.byteLength(JSON.stringify(value), "utf8");
31709
+ if (this.#frames >= 2048 || this.#bytes + bytes > 4 * 1024 * 1024)
31710
+ throw new CodeBuddyError("protocolError", "Native autonomous Turn output exceeded its buffer bound");
31711
+ this.#frames += 1;
31712
+ this.#bytes += bytes;
31713
+ return bytes;
31714
+ }
31715
+ release(frames, bytes) {
31716
+ this.#frames -= frames;
31717
+ this.#bytes -= bytes;
31718
+ }
31719
+ };
31720
+ var CodeBuddyAutonomousFrames = class {
31721
+ budget;
31722
+ #frames = [];
31723
+ #bytes = 0;
31724
+ constructor(budget) {
31725
+ this.budget = budget;
31726
+ }
31727
+ push(frame) {
31728
+ this.#bytes += this.budget.hold(frame);
31729
+ this.#frames.push(frame);
31730
+ }
31731
+ drain() {
31732
+ this.budget.release(this.#frames.length, this.#bytes);
31733
+ this.#bytes = 0;
31734
+ return this.#frames.splice(0);
31735
+ }
31736
+ };
31737
+ var CodeBuddyAutonomousTurns = class {
31738
+ #rounds = [];
31739
+ #budget = new AutonomousBufferBudget();
31740
+ #open;
31741
+ #announcements = 0;
31742
+ get announcements() {
31743
+ return this.#announcements;
31744
+ }
31745
+ announce(requestId) {
31746
+ if (this.#open)
31747
+ throw new CodeBuddyError("protocolError", "Native autonomous Turns overlapped");
31748
+ const announcementBytes = this.#budget.hold({
31749
+ sessionUpdate: "session_info_update",
31750
+ requestId
31751
+ });
31752
+ const identity2 = Promise.withResolvers();
31753
+ const round = {
31754
+ frames: new CodeBuddyAutonomousFrames(this.#budget),
31755
+ identity: identity2.promise,
31756
+ resolveIdentity: identity2.resolve,
31757
+ announcementBytes,
31758
+ ended: false,
31759
+ started: false
31760
+ };
31761
+ this.#announcements += 1;
31762
+ this.#rounds.push(round);
31763
+ this.#open = round;
31764
+ return round;
31765
+ }
31766
+ /** IDs can be reused or change during admission; the connection interval owns the end. */
31767
+ end(requestId) {
31768
+ const round = this.#open;
31769
+ if (!round)
31770
+ return;
31771
+ round.terminalBytes = this.#budget.hold({ sessionUpdate: "session_end", requestId });
31772
+ round.ended = true;
31773
+ this.#open = void 0;
31774
+ return round;
31775
+ }
31776
+ start(round, turnId) {
31777
+ round.started = true;
31778
+ round.resolveIdentity(turnId);
31779
+ }
31780
+ owner() {
31781
+ return this.#open;
31782
+ }
31783
+ hasRounds() {
31784
+ return this.#rounds.length > 0;
31785
+ }
31786
+ interactionIdentity(round, request) {
31787
+ const bytes = this.#budget.hold(request);
31788
+ return round.identity.finally(() => this.#budget.release(1, bytes));
31789
+ }
31790
+ next() {
31791
+ return this.#rounds.find((round) => !round.started);
31792
+ }
31793
+ finish(round) {
31794
+ const index = this.#rounds.indexOf(round);
31795
+ if (index < 0)
31796
+ return;
31797
+ round.frames.drain();
31798
+ this.#budget.release(1, round.announcementBytes);
31799
+ if (round.terminalBytes !== void 0)
31800
+ this.#budget.release(1, round.terminalBytes);
31801
+ this.#rounds.splice(index, 1);
31802
+ if (this.#open === round)
31803
+ this.#open = void 0;
31804
+ round.resolveIdentity(void 0);
31805
+ }
31806
+ close() {
31807
+ for (const round of [...this.#rounds])
31808
+ this.finish(round);
31809
+ }
31810
+ };
31811
+
31585
31812
  // dist/interactions.js
31586
31813
  var CodeBuddyInteractions = class {
31587
31814
  emit;
@@ -32124,6 +32351,7 @@ var CodeBuddySession = class {
32124
32351
  #ref;
32125
32352
  #state = {};
32126
32353
  #active;
32354
+ #autonomous = new CodeBuddyAutonomousTurns();
32127
32355
  #busy = false;
32128
32356
  #closed = false;
32129
32357
  #closing;
@@ -32194,22 +32422,7 @@ var CodeBuddySession = class {
32194
32422
  }
32195
32423
  return;
32196
32424
  }
32197
- if (this.#replay)
32198
- return;
32199
- if ((text2(record3(update._meta)["codebuddy.ai/parentToolCallId"]) || !this.#active?.output.hasItem(`tool-${text2(update.toolCallId)}`)) && this.subagents.update(update))
32200
- return;
32201
- if (update.sessionUpdate === "config_option_update" && this.#config)
32202
- this.#apply(configuration(update.configOptions, this.profile));
32203
- if (update.sessionUpdate === "usage_update" && typeof update.used === "number" && typeof update.size === "number" && update.size > 0) {
32204
- this.#context = {
32205
- contextUsedTokens: update.used,
32206
- contextWindowTokens: update.size,
32207
- contextUsagePercent: update.used / update.size * 100
32208
- };
32209
- this.#emitUsage();
32210
- void this.refreshUsage();
32211
- }
32212
- this.#active?.output.update(update);
32425
+ this.#dispatchUpdate(update);
32213
32426
  } catch (error62) {
32214
32427
  if (this.#replay)
32215
32428
  this.#replay.fault ??= { error: error62 };
@@ -32217,8 +32430,12 @@ var CodeBuddySession = class {
32217
32430
  this.#onFault(error62);
32218
32431
  }
32219
32432
  },
32220
- permission: (request) => generation === this.#generation && !this.#closed && !this.#fault && !this.#replay && this.#active && !this.#active.cancelled && request.sessionId === this.#ref?.nativeSessionId ? this.#interactions.permission(this.#active.command.turnId, request) : Promise.resolve({ outcome: { outcome: "cancelled" } }),
32221
- question: (params) => generation === this.#generation && !this.#closed && !this.#fault && !this.#replay && this.#active && !this.#active.cancelled && params.sessionId === this.#ref?.nativeSessionId ? this.#interactions.question(this.#active.command.turnId, params) : Promise.resolve({ outcome: "cancelled" })
32433
+ permission: (request) => generation !== this.#generation || request.sessionId !== this.#ref?.nativeSessionId ? Promise.resolve({ outcome: { outcome: "cancelled" } }) : this.#interactionTurn(request, (turnId) => this.#interactions.permission(turnId, request), {
32434
+ outcome: { outcome: "cancelled" }
32435
+ }),
32436
+ question: (params) => generation !== this.#generation || params.sessionId !== this.#ref?.nativeSessionId ? Promise.resolve({ outcome: "cancelled" }) : this.#interactionTurn(params, (turnId) => this.#interactions.question(turnId, params), {
32437
+ outcome: "cancelled"
32438
+ })
32222
32439
  }
32223
32440
  });
32224
32441
  }
@@ -32265,31 +32482,40 @@ var CodeBuddySession = class {
32265
32482
  const saved = this.input.kind === "resume" && record3(this.input.nativeRef.locator).codebuddyDerived === 1 ? record3(record3(this.input.nativeRef.locator).configuration) : {};
32266
32483
  if (this.input.kind === "resume")
32267
32484
  this.#ref = this.input.nativeRef;
32268
- const opened = await this.#openClient();
32269
- this.#ref = nativeSessionRefSchema.parse({
32270
- harnessId: this.profile.harnessId,
32271
- nativeSessionId: opened.sessionId,
32272
- formatVersion: 1,
32273
- ...this.#ref?.locator || this.capabilities.history.fork ? {
32274
- locator: {
32275
- ...record3(this.#ref?.locator),
32276
- ...this.capabilities.history.fork ? { boundCwd: codeBuddyCanonicalCwd(this.input.cwd) } : {}
32277
- }
32278
- } : {}
32279
- });
32280
- this.#apply(configuration(opened.configOptions, this.profile), false);
32281
- if (this.input.kind === "create" && this.input.executionPolicy === "unattended-full-access") {
32282
- await this.#configure("mode", "fullAccess");
32283
- } else if (this.input.permissionModeId || text2(saved.mode))
32284
- await this.#configure("mode", this.input.permissionModeId ?? text2(saved.mode));
32285
- if (this.input.model || text2(saved.model))
32286
- await this.#configure("model", this.input.model?.id ?? text2(saved.model));
32287
- if (this.input.thinkingOptionId || text2(saved.thinking))
32288
- await this.#configure("thought_level", this.input.thinkingOptionId ?? text2(saved.thinking));
32289
- if (this.#fault || this.#closed)
32290
- throw new CodeBuddyError("invalidState", "Native Session failed while opening");
32291
- this.initialState = { ...this.#state };
32292
- this.initialUsage = this.#usage;
32485
+ const replay = {};
32486
+ this.#replay = replay;
32487
+ const generation = this.#generation;
32488
+ try {
32489
+ const opened = await this.#openClient();
32490
+ this.#ref = nativeSessionRefSchema.parse({
32491
+ harnessId: this.profile.harnessId,
32492
+ nativeSessionId: opened.sessionId,
32493
+ formatVersion: 1,
32494
+ ...this.#ref?.locator || this.capabilities.history.fork ? {
32495
+ locator: {
32496
+ ...record3(this.#ref?.locator),
32497
+ ...this.capabilities.history.fork ? { boundCwd: codeBuddyCanonicalCwd(this.input.cwd) } : {}
32498
+ }
32499
+ } : {}
32500
+ });
32501
+ this.#apply(configuration(opened.configOptions, this.profile), false);
32502
+ if (this.input.kind === "create" && this.input.executionPolicy === "unattended-full-access") {
32503
+ await this.#configure("mode", "fullAccess");
32504
+ } else if (this.input.permissionModeId || text2(saved.mode))
32505
+ await this.#configure("mode", this.input.permissionModeId ?? text2(saved.mode));
32506
+ if (this.input.model || text2(saved.model))
32507
+ await this.#configure("model", this.input.model?.id ?? text2(saved.model));
32508
+ if (this.input.thinkingOptionId || text2(saved.thinking))
32509
+ await this.#configure("thought_level", this.input.thinkingOptionId ?? text2(saved.thinking));
32510
+ this.#assertClient(generation);
32511
+ if (!this.profile.staticCommandCatalog && replay.commands)
32512
+ this.#commands = replay.commands;
32513
+ this.initialState = { ...this.#state };
32514
+ this.initialUsage = this.#usage;
32515
+ } finally {
32516
+ this.#replay = void 0;
32517
+ }
32518
+ this.#flushAutonomous();
32293
32519
  }
32294
32520
  #emit(event) {
32295
32521
  event = configureSubagentEvent(event, this.#subagentConfiguration());
@@ -32314,6 +32540,140 @@ var CodeBuddySession = class {
32314
32540
  if (historical || !complete)
32315
32541
  this.#emit({ type: "usage.history", complete });
32316
32542
  }
32543
+ /** Routes one native frame to the Host Turn, a native drain round, or its buffer. */
32544
+ #dispatchUpdate(update) {
32545
+ const unsolicited = readUnsolicitedTurn(update);
32546
+ if (unsolicited) {
32547
+ this.#autonomous.announce(unsolicited);
32548
+ this.#flushAutonomous();
32549
+ return;
32550
+ }
32551
+ if (update.sessionUpdate === "session_end") {
32552
+ const round = this.#autonomous.end(text2(record3(update._meta)["codebuddy.ai/requestId"]));
32553
+ if (!round)
32554
+ return;
32555
+ if (round.started)
32556
+ void this.#finishAutonomous(round);
32557
+ else
32558
+ this.#flushAutonomous();
32559
+ return;
32560
+ }
32561
+ const route = this.#autonomous.owner();
32562
+ if (route?.started) {
32563
+ if (!this.#replay)
32564
+ this.#applyUpdate(update);
32565
+ return;
32566
+ }
32567
+ if (route) {
32568
+ route.frames.push(update);
32569
+ return;
32570
+ }
32571
+ if (this.#replay)
32572
+ return;
32573
+ this.#applyUpdate(update);
32574
+ }
32575
+ /** An announced native interval owns Interactions before the prior prompt's finally runs. */
32576
+ #interactionTurn(request, run, cancelled) {
32577
+ if (this.#closed || this.#fault)
32578
+ return Promise.resolve(cancelled);
32579
+ const round = this.#autonomous.owner();
32580
+ if (round) {
32581
+ let identity2;
32582
+ try {
32583
+ identity2 = this.#autonomous.interactionIdentity(round, request);
32584
+ } catch (error62) {
32585
+ if (this.#replay)
32586
+ this.#replay.fault ??= { error: error62 };
32587
+ else
32588
+ this.#onFault(error62);
32589
+ return Promise.resolve(cancelled);
32590
+ }
32591
+ return identity2.then((turnId) => {
32592
+ const active3 = this.#active;
32593
+ return turnId && active3?.autonomous?.round === round && !active3.cancelled && !active3.done ? run(turnId) : cancelled;
32594
+ });
32595
+ }
32596
+ const active2 = this.#active;
32597
+ return active2 && !this.#replay && !active2.cancelled && !active2.autonomous && !active2.promptSettled ? run(active2.command.turnId) : Promise.resolve(cancelled);
32598
+ }
32599
+ /** Frames of the active Turn, including a native drain Turn that now owns the Session. */
32600
+ #applyUpdate(update) {
32601
+ if ((text2(record3(update._meta)["codebuddy.ai/parentToolCallId"]) || !this.#active?.output.hasItem(`tool-${text2(update.toolCallId)}`)) && this.subagents.update(update))
32602
+ return;
32603
+ if (update.sessionUpdate === "config_option_update" && this.#config)
32604
+ this.#apply(configuration(update.configOptions, this.profile));
32605
+ if (update.sessionUpdate === "usage_update" && typeof update.used === "number" && typeof update.size === "number" && update.size > 0) {
32606
+ this.#context = {
32607
+ contextUsedTokens: update.used,
32608
+ contextWindowTokens: update.size,
32609
+ contextUsagePercent: update.used / update.size * 100
32610
+ };
32611
+ this.#emitUsage();
32612
+ void this.refreshUsage();
32613
+ }
32614
+ if (!this.#active?.cancelled)
32615
+ this.#active?.output.update(update);
32616
+ }
32617
+ #flushAutonomous() {
32618
+ if (this.#active || this.#replay || this.#closed || this.#fault)
32619
+ return;
32620
+ const round = this.#autonomous.next();
32621
+ if (!round)
32622
+ return;
32623
+ this.#startAutonomous(round);
32624
+ try {
32625
+ for (const frame of round.frames.drain())
32626
+ this.#applyUpdate(frame);
32627
+ } catch (error62) {
32628
+ this.#onFault(error62);
32629
+ return;
32630
+ }
32631
+ if (round.ended)
32632
+ void this.#finishAutonomous(round);
32633
+ }
32634
+ #startAutonomous(round) {
32635
+ const turnId = hostTurnIdSchema.parse(randomUUID3());
32636
+ const completion = Promise.withResolvers();
32637
+ const active2 = {
32638
+ command: { type: "turn.start", turnId, input: [] },
32639
+ output: new CodeBuddyTurnOutput(turnId, this.input.cwd, (event) => this.#emit(event), this.profile),
32640
+ completion: completion.promise,
32641
+ nativeCommand: false,
32642
+ cancelled: false,
32643
+ done: false,
32644
+ autonomous: { round },
32645
+ settle: () => completion.resolve(void 0)
32646
+ };
32647
+ this.#active = active2;
32648
+ this.#autonomous.start(round, turnId);
32649
+ this.subagents.begin(turnId);
32650
+ this.#emit({ type: "turn.autonomous.started", turnId, input: [] });
32651
+ this.#emit({ type: "turn.started", turnId });
32652
+ }
32653
+ /** Completes the live interval without assigning persisted identity or inferring success. */
32654
+ async #finishAutonomous(round) {
32655
+ const active2 = this.#active;
32656
+ if (!active2?.autonomous || active2.autonomous.round !== round || active2.done)
32657
+ return;
32658
+ try {
32659
+ const outcome = { status: active2.cancelled ? "cancelled" : "succeeded" };
32660
+ if (active2.cancelled) {
32661
+ const recovery = (async () => {
32662
+ await this.#retireClient();
32663
+ if (this.#closed || this.#fault)
32664
+ return;
32665
+ await this.#resumeClient();
32666
+ })();
32667
+ void recovery.catch(() => {
32668
+ });
32669
+ await bounded(Promise.race([recovery, active2.completion]), 3e4, "ACP autonomous cancel recovery");
32670
+ }
32671
+ if (!active2.done && !this.#closed && !this.#fault)
32672
+ this.#finish(active2, outcome);
32673
+ } catch (error62) {
32674
+ this.#onFault(error62);
32675
+ }
32676
+ }
32317
32677
  #apply(config2, emit = true) {
32318
32678
  if (this.#state.effectiveModel && this.#state.effectiveModel.id !== config2.state.effectiveModel?.id) {
32319
32679
  this.#context = {};
@@ -32365,6 +32725,9 @@ var CodeBuddySession = class {
32365
32725
  }
32366
32726
  }
32367
32727
  async #snapshot(historyTimeout) {
32728
+ return (await this.#snapshotWithHistory(historyTimeout)).snapshot;
32729
+ }
32730
+ async #snapshotWithHistory(historyTimeout) {
32368
32731
  if (!this.#ref)
32369
32732
  throw new CodeBuddyError("invalidState", "Session is not open");
32370
32733
  const read = this.#history(this.#ref);
@@ -32376,7 +32739,7 @@ var CodeBuddySession = class {
32376
32739
  this.#hasTurn = true;
32377
32740
  this.#usage = historyUsage(history);
32378
32741
  this.#meterHistory(history, false);
32379
- return { ...this.subagents.project(snapshot), state: this.#state };
32742
+ return { snapshot: { ...this.subagents.project(snapshot), state: this.#state }, history };
32380
32743
  }
32381
32744
  /** Read persisted request usage without waiting for the ACP prompt (including tool waits). */
32382
32745
  async refreshUsage() {
@@ -32411,7 +32774,7 @@ var CodeBuddySession = class {
32411
32774
  async #readSnapshot() {
32412
32775
  if (this.#closed || this.#fault)
32413
32776
  return failure2("invalidState", "Session is closed or faulted", this.profile);
32414
- if (this.#busy || this.#active)
32777
+ if (this.#busy || this.#replay || this.#active && (!this.#active.autonomous || this.#active.cancelled))
32415
32778
  return failure2("sessionBusy", "Session is executing an operation", this.profile);
32416
32779
  this.#busy = true;
32417
32780
  try {
@@ -32432,6 +32795,14 @@ var CodeBuddySession = class {
32432
32795
  return failure2("unsupported", "Command is not available in this Session", this.profile);
32433
32796
  return this.#execute(command, invocation);
32434
32797
  }
32798
+ /** ACP `session/cancel` carries only the Session ID; send it only while this Turn owns execution. */
32799
+ #ownsNativeExecution(active2) {
32800
+ if (active2.done || this.#needsResume)
32801
+ return false;
32802
+ if (active2.autonomous)
32803
+ return !active2.autonomous.round.ended && this.#autonomous.owner() === active2.autonomous.round;
32804
+ return !active2.promptSettled && !this.#autonomous.hasRounds();
32805
+ }
32435
32806
  async #execute(command, invocation) {
32436
32807
  if (this.#closed || this.#fault)
32437
32808
  return failure2("invalidState", "Session is closed or faulted", this.profile);
@@ -32443,27 +32814,29 @@ var CodeBuddySession = class {
32443
32814
  const active2 = this.#active;
32444
32815
  if (!active2 || active2.command.turnId !== command.turnId || !this.#ref)
32445
32816
  return failure2("invalidRequest", "Turn is not active", this.profile);
32446
- if (!active2.cancelled) {
32447
- active2.cancelled = true;
32448
- const generation = this.#generation;
32449
- try {
32450
- const requested = this.#client.cancel(this.#ref.nativeSessionId);
32451
- this.#interactions.close();
32452
- await requested;
32453
- } catch (error62) {
32454
- if (generation === this.#generation) {
32455
- if (this.#active === active2)
32456
- this.#onFault(error62);
32457
- return { ok: false, error: nativeError(error62, this.profile) };
32458
- }
32459
- }
32460
- if (this.#active === active2 && !this.#closed) {
32461
- void bounded(active2.completion, 3e4, "ACP cancel acknowledgement").catch((error62) => {
32462
- if (this.#active === active2 && !this.#needsResume)
32463
- this.#onFault(error62);
32464
- });
32817
+ if (active2.cancelled)
32818
+ return { ok: true, value: { cancellationRequested: true } };
32819
+ if (!this.#ownsNativeExecution(active2))
32820
+ return failure2("invalidState", "Turn is already completing", this.profile);
32821
+ active2.cancelled = true;
32822
+ const generation = this.#generation;
32823
+ try {
32824
+ const requested = this.#client.cancel(this.#ref.nativeSessionId);
32825
+ this.#interactions.close();
32826
+ await requested;
32827
+ } catch (error62) {
32828
+ if (generation === this.#generation) {
32829
+ if (this.#active === active2)
32830
+ this.#onFault(error62);
32831
+ return { ok: false, error: nativeError(error62, this.profile) };
32465
32832
  }
32466
32833
  }
32834
+ if (this.#active === active2 && !this.#closed) {
32835
+ void bounded(active2.completion, 3e4, "ACP cancel acknowledgement").catch((error62) => {
32836
+ if (this.#active === active2 && (active2.autonomous || !this.#needsResume))
32837
+ this.#onFault(error62);
32838
+ });
32839
+ }
32467
32840
  return { ok: true, value: { cancellationRequested: true } };
32468
32841
  }
32469
32842
  if (this.#busy || this.#active && (this.#active.cancelled || command.type !== "model.select" && command.type !== "thinking.select"))
@@ -32473,8 +32846,14 @@ var CodeBuddySession = class {
32473
32846
  if (command.type === "turn.start" || command.type === "command.execute") {
32474
32847
  if (!command.turnId.trim() || command.type === "turn.start" && (!command.input.length || command.input.some((item) => item.type !== "text") || !command.input.map((item) => item.text).join("").trim()))
32475
32848
  return failure2("invalidRequest", "A nonempty text prompt is required", this.profile);
32476
- if (this.#needsResume)
32849
+ const drainBefore = this.#autonomous.announcements;
32850
+ if (this.#needsResume) {
32477
32851
  await this.#resumeClient();
32852
+ if (this.#closed || this.#fault)
32853
+ return failure2("invalidState", "Session is closed or faulted", this.profile);
32854
+ if (this.#active || this.#autonomous.announcements !== drainBefore)
32855
+ return failure2("sessionBusy", "Session is executing an operation", this.profile);
32856
+ }
32478
32857
  const nativeCommand = command.type === "command.execute" || nativeCommandsEnabled(this.profile) && this.#commands.commands.some((entry) => entry.invocation === invocation);
32479
32858
  if (command.type === "command.execute") {
32480
32859
  const parsed = commandPrompt(command, this.#commands, this.profile);
@@ -32487,14 +32866,12 @@ var CodeBuddySession = class {
32487
32866
  };
32488
32867
  }
32489
32868
  const snapshot = await this.#snapshot();
32490
- const before = new Set(snapshot.turns.map((turn) => turn.nativeTurnRef.nativeTurnKey));
32491
- const beforeItems = new Set(snapshot.turns.flatMap((turn) => turn.items.map((snapshot2) => snapshot2.item.itemId)));
32492
32869
  if (this.#closed || this.#fault)
32493
32870
  return failure2("invalidState", "Session closed before Turn start", this.profile);
32871
+ if (this.#active || this.#autonomous.announcements !== drainBefore)
32872
+ return failure2("sessionBusy", "Session is executing an operation", this.profile);
32494
32873
  const active2 = {
32495
32874
  command,
32496
- before,
32497
- beforeItems,
32498
32875
  output: new CodeBuddyTurnOutput(command.turnId, this.input.cwd, (event) => this.#emit(event), this.profile),
32499
32876
  nativeCommand,
32500
32877
  cancelled: false,
@@ -32504,11 +32881,16 @@ var CodeBuddySession = class {
32504
32881
  this.#active = active2;
32505
32882
  this.subagents.begin(command.turnId);
32506
32883
  this.#emit({ type: "turn.started", turnId: command.turnId });
32507
- active2.completion = this.#run(active2);
32884
+ active2.completion = this.#run(active2, new Set(snapshot.turns.map((turn) => turn.nativeTurnRef.nativeTurnKey)), new Set(snapshot.turns.flatMap((turn) => turn.items.map(({ item }) => item.itemId))), drainBefore);
32508
32885
  return { ok: true, value: { turnId: command.turnId } };
32509
32886
  }
32510
- if (this.#needsResume)
32887
+ if (this.#needsResume) {
32511
32888
  await this.#resumeClient();
32889
+ if (this.#closed || this.#fault)
32890
+ return failure2("invalidState", "Session is closed or faulted", this.profile);
32891
+ if (this.#active && (this.#active.cancelled || command.type !== "model.select" && command.type !== "thinking.select"))
32892
+ return failure2("sessionBusy", "Session is executing an operation", this.profile);
32893
+ }
32512
32894
  await this.#configure(command.type === "model.select" ? "model" : command.type === "thinking.select" ? "thought_level" : "mode", command.type === "model.select" ? command.model.id : command.type === "thinking.select" ? command.thinkingOptionId : command.permissionModeId);
32513
32895
  return { ok: true, value: { completed: true } };
32514
32896
  } catch (error62) {
@@ -32517,12 +32899,14 @@ var CodeBuddySession = class {
32517
32899
  this.#busy = false;
32518
32900
  }
32519
32901
  }
32520
- async #run(active2) {
32902
+ async #run(active2, before, beforeItems, drainBefore) {
32521
32903
  let cancellationConfirmed = false;
32522
32904
  try {
32523
32905
  if (!this.#ref)
32524
32906
  throw new CodeBuddyError("invalidState", "Session is not open");
32525
- const response = await this.#client.prompt(this.#ref.nativeSessionId, active2.command.input.map((item) => item.text).join("\n"));
32907
+ const response = await this.#client.prompt(this.#ref.nativeSessionId, active2.command.input.map((item) => item.text).join("\n")).finally(() => {
32908
+ active2.promptSettled = true;
32909
+ });
32526
32910
  if (active2.done || this.#closed)
32527
32911
  return;
32528
32912
  const stop = response.stopReason, meta3 = record3(response._meta);
@@ -32534,39 +32918,42 @@ var CodeBuddySession = class {
32534
32918
  };
32535
32919
  if (outcome.status === "cancelled") {
32536
32920
  active2.cancelled = true;
32537
- ++this.#generation;
32538
- this.#interactions.close();
32539
32921
  try {
32540
- await this.#client.close();
32922
+ await this.#retireClient();
32541
32923
  } catch (error62) {
32542
32924
  this.#onFault(error62);
32543
32925
  return;
32544
32926
  }
32545
32927
  if (active2.done || this.#closed)
32546
32928
  return;
32547
- this.#needsResume = true;
32548
32929
  cancellationConfirmed = true;
32549
32930
  }
32550
- const snapshot = await this.#snapshot(cancellationConfirmed ? 1e3 : void 0);
32931
+ const { snapshot, history } = await this.#snapshotWithHistory(cancellationConfirmed ? 1e3 : void 0);
32551
32932
  if (active2.done || this.#closed)
32552
32933
  return;
32553
- const added = snapshot.turns.filter((turn) => !active2.before.has(turn.nativeTurnRef.nativeTurnKey));
32554
- if (added.length > 1 || !active2.nativeCommand && outcome.status === "succeeded" && added.length !== 1)
32555
- throw new CodeBuddyError("protocolError", "Could not identify exactly one persisted Native Turn");
32556
- const nativeTurnRef = added[0]?.nativeTurnRef;
32557
- if (response.userMessageId && nativeTurnRef?.nativeTurnKey !== response.userMessageId)
32934
+ const drainOverlapped = this.#autonomous.announcements !== drainBefore;
32935
+ const userMessageId = text2(response.userMessageId);
32936
+ const added = snapshot.turns.filter((turn) => !before.has(turn.nativeTurnRef.nativeTurnKey));
32937
+ const persisted = userMessageId ? added.find((turn) => turn.nativeTurnRef.nativeTurnKey === userMessageId) : !drainOverlapped && added.length === 1 ? added[0] : void 0;
32938
+ if (userMessageId && !persisted)
32558
32939
  throw new CodeBuddyError("protocolError", "ACP terminal and native history disagree on Turn identity");
32559
- active2.output.confirmCompaction(snapshot.turns.flatMap((turn) => turn.items).filter((snapshot2) => !active2.beforeItems.has(snapshot2.item.itemId)));
32940
+ if (!persisted && !active2.nativeCommand && outcome.status === "succeeded")
32941
+ throw new CodeBuddyError("protocolError", "Could not identify exactly one persisted Native Turn");
32942
+ const compactionItems = persisted ? compactionEvidenceForTurn(history, snapshot, persisted.nativeTurnRef.nativeTurnKey, beforeItems, this.profile) : drainOverlapped ? [] : snapshot.turns.flatMap((turn) => turn.items).filter(({ item }) => !beforeItems.has(item.itemId));
32943
+ active2.output.confirmCompaction(compactionItems);
32560
32944
  if (active2.nativeCommand)
32561
- active2.output.replayCommandResult((added[0]?.items ?? []).filter(({ item }) => !this.subagents.hasItem(item.itemId)));
32945
+ active2.output.replayCommandResult((persisted?.items ?? []).filter(({ item }) => !this.subagents.hasItem(item.itemId)));
32946
+ const nativeTurnRef = persisted?.nativeTurnRef;
32947
+ if (nativeTurnRef)
32948
+ this.#hasTurn = true;
32562
32949
  const compactCommand = outcome.status !== "cancelled" && active2.nativeCommand && /^\/compact(?:\s|$)/u.test(active2.command.input.map((item) => item.text).join("\n").trim());
32563
- const persisted = compactCommand ? added[0]?.outcome : void 0;
32564
- if (compactCommand && (!persisted || persisted.status === "unknown"))
32950
+ const persistedOutcome = compactCommand ? persisted?.outcome : void 0;
32951
+ if (compactCommand && (!persistedOutcome || persistedOutcome.status === "unknown"))
32565
32952
  throw new CodeBuddyError("protocolError", "Native compaction terminal outcome was not persisted");
32566
- const terminalOutcome = persisted && persisted.status !== "unknown" ? persisted : outcome;
32953
+ const terminalOutcome = persistedOutcome && persistedOutcome.status !== "unknown" ? persistedOutcome : outcome;
32567
32954
  this.#finish(active2, {
32568
32955
  ...terminalOutcome,
32569
- ...added[0]?.checkpoint ? { checkpoint: added[0].checkpoint } : {}
32956
+ ...persisted?.checkpoint ? { checkpoint: persisted.checkpoint } : {}
32570
32957
  }, nativeTurnRef);
32571
32958
  if (this.#usage)
32572
32959
  this.#emitUsage();
@@ -32575,6 +32962,13 @@ var CodeBuddySession = class {
32575
32962
  this.#finish(active2, cancellationConfirmed ? { status: "cancelled" } : { status: "failed", error: nativeError(error62, this.profile) });
32576
32963
  }
32577
32964
  }
32965
+ async #retireClient() {
32966
+ ++this.#generation;
32967
+ this.#interactions.close();
32968
+ this.#autonomous.close();
32969
+ await this.#client.close();
32970
+ this.#needsResume = true;
32971
+ }
32578
32972
  /** Runs only under the native operation gate, after the old process has exited. */
32579
32973
  async #resumeClient() {
32580
32974
  const replay = {};
@@ -32590,8 +32984,11 @@ var CodeBuddySession = class {
32590
32984
  if (!this.profile.staticCommandCatalog)
32591
32985
  this.#commands = replay.commands ?? { commands: [] };
32592
32986
  this.#needsResume = false;
32987
+ this.#replay = void 0;
32988
+ this.#flushAutonomous();
32593
32989
  } catch (error62) {
32594
32990
  ++this.#generation;
32991
+ this.#autonomous.close();
32595
32992
  try {
32596
32993
  await candidate?.close();
32597
32994
  } catch (closeError) {
@@ -32606,6 +33003,9 @@ var CodeBuddySession = class {
32606
33003
  if (active2.done)
32607
33004
  return;
32608
33005
  active2.done = true;
33006
+ active2.settle?.();
33007
+ if (active2.autonomous)
33008
+ this.#autonomous.finish(active2.autonomous.round);
32609
33009
  this.subagents.finish(outcome);
32610
33010
  this.#interactions.close();
32611
33011
  active2.output.finish(outcome.status, outcome.status === "failed" ? outcome.error : void 0);
@@ -32613,15 +33013,19 @@ var CodeBuddySession = class {
32613
33013
  type: "turn.completed",
32614
33014
  turnId: active2.command.turnId,
32615
33015
  outcome,
33016
+ ...active2.autonomous ? { ephemeral: true } : {},
32616
33017
  ...nativeTurnRef ? { nativeTurnRef } : {}
32617
33018
  });
32618
33019
  if (this.#active === active2)
32619
33020
  this.#active = void 0;
33021
+ this.#flushAutonomous();
32620
33022
  }
32621
33023
  #onFault(error62) {
32622
33024
  if (this.#fault || this.#closed)
32623
33025
  return;
32624
33026
  this.#fault = nativeError(error62, this.profile);
33027
+ this.#replay = void 0;
33028
+ this.#autonomous.close();
32625
33029
  if (this.#active)
32626
33030
  this.#finish(this.#active, { status: "failed", error: this.#fault });
32627
33031
  this.#interactions.close();
@@ -32636,6 +33040,7 @@ var CodeBuddySession = class {
32636
33040
  }
32637
33041
  async #close() {
32638
33042
  this.#closed = true;
33043
+ this.#autonomous.close();
32639
33044
  this.#interactions.close();
32640
33045
  try {
32641
33046
  await this.#client.close();
@@ -32874,7 +33279,7 @@ function createCodeBuddyInstallation(environment) {
32874
33279
 
32875
33280
  // ../../harness-broker/dist/client.js
32876
33281
  import { execFile as execFile4 } from "node:child_process";
32877
- import { randomUUID as randomUUID3 } from "node:crypto";
33282
+ import { randomUUID as randomUUID4 } from "node:crypto";
32878
33283
  import { lstat as lstat4, readFile as readFile5 } from "node:fs/promises";
32879
33284
  import net, {} from "node:net";
32880
33285
 
@@ -33743,7 +34148,7 @@ var BrokerConnection = class _BrokerConnection {
33743
34148
  throw new Error("Aqua Harness broker request limit exceeded");
33744
34149
  }
33745
34150
  this.#inputSequence += 1;
33746
- const id2 = randomUUID3();
34151
+ const id2 = randomUUID4();
33747
34152
  const response = new Promise((resolve, reject) => {
33748
34153
  const timeout = setTimeout(() => {
33749
34154
  this.#pending.delete(id2);