@gajae-code/coding-agent 0.11.6 → 0.11.8

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 (259) hide show
  1. package/CHANGELOG.md +92 -0
  2. package/dist/types/capability/index.d.ts +10 -20
  3. package/dist/types/capability/types.d.ts +3 -0
  4. package/dist/types/cli/args.d.ts +0 -2
  5. package/dist/types/commands/daemon.d.ts +2 -2
  6. package/dist/types/commands/sdk.d.ts +20 -2
  7. package/dist/types/config/keybindings.d.ts +34 -4
  8. package/dist/types/config/model-profile-activation.d.ts +4 -3
  9. package/dist/types/config/model-profile-contract.d.ts +38 -0
  10. package/dist/types/config/settings-schema.d.ts +70 -7
  11. package/dist/types/edit/modes/patch.d.ts +13 -0
  12. package/dist/types/edit/path-mutation-lock.d.ts +15 -0
  13. package/dist/types/eval/py/executor.d.ts +1 -1
  14. package/dist/types/eval/py/runner-artifact.d.ts +8 -0
  15. package/dist/types/eval/py/tool-bridge.d.ts +1 -2
  16. package/dist/types/gjc-runtime/repository-binding.d.ts +63 -0
  17. package/dist/types/gjc-runtime/ultragoal-guard.d.ts +6 -5
  18. package/dist/types/gjc-runtime/ultragoal-receipt-freshness.d.ts +20 -0
  19. package/dist/types/gjc-runtime/ultragoal-runtime.d.ts +43 -5
  20. package/dist/types/main.d.ts +32 -1
  21. package/dist/types/modes/components/btw-panel.d.ts +1 -0
  22. package/dist/types/modes/components/model-selector.d.ts +2 -0
  23. package/dist/types/modes/components/runtime-mcp-add-wizard.d.ts +2 -1
  24. package/dist/types/modes/components/tool-status-header.d.ts +4 -2
  25. package/dist/types/modes/components/welcome.d.ts +2 -0
  26. package/dist/types/modes/controllers/btw-controller.d.ts +5 -0
  27. package/dist/types/modes/controllers/command-controller.d.ts +2 -0
  28. package/dist/types/modes/controllers/selector-controller.d.ts +2 -1
  29. package/dist/types/modes/interactive-mode.d.ts +7 -2
  30. package/dist/types/modes/prompt-action-autocomplete.d.ts +6 -1
  31. package/dist/types/modes/prompt-suggestion-controller.d.ts +35 -0
  32. package/dist/types/modes/shared/agent-wire/workflow-gate-broker.d.ts +2 -2
  33. package/dist/types/modes/types.d.ts +4 -0
  34. package/dist/types/modes/utils/hotkeys-markdown.d.ts +2 -1
  35. package/dist/types/runtime-mcp/content-limits.d.ts +7 -0
  36. package/dist/types/runtime-mcp/manager.d.ts +1 -1
  37. package/dist/types/runtime-mcp/oauth-flow.d.ts +0 -5
  38. package/dist/types/runtime-mcp/plugin-network-boundary.d.ts +14 -0
  39. package/dist/types/sdk/broker/broker.d.ts +2 -0
  40. package/dist/types/sdk/broker/lifecycle.d.ts +6 -0
  41. package/dist/types/sdk/bus/chat-daemon-control.d.ts +6 -1
  42. package/dist/types/sdk/bus/config-commands.d.ts +2 -2
  43. package/dist/types/sdk/bus/config.d.ts +2 -0
  44. package/dist/types/sdk/bus/conversation-store.d.ts +1 -0
  45. package/dist/types/sdk/bus/index.d.ts +26 -1
  46. package/dist/types/sdk/bus/lifecycle-commands.d.ts +5 -4
  47. package/dist/types/sdk/bus/notification-orchestration.d.ts +1 -0
  48. package/dist/types/sdk/bus/notification-service.d.ts +34 -0
  49. package/dist/types/sdk/bus/prompt-reconciliation.d.ts +105 -0
  50. package/dist/types/sdk/bus/telegram-daemon-contract.d.ts +18 -3
  51. package/dist/types/sdk/bus/telegram-daemon-control.d.ts +5 -1
  52. package/dist/types/sdk/bus/telegram-daemon.d.ts +189 -4
  53. package/dist/types/sdk/bus/telegram-reference.d.ts +2 -0
  54. package/dist/types/sdk/bus/topic-registry.d.ts +88 -2
  55. package/dist/types/sdk/client/discovery.d.ts +2 -0
  56. package/dist/types/sdk/client/liveness.d.ts +7 -0
  57. package/dist/types/sdk/host/control/operations.d.ts +1 -1
  58. package/dist/types/sdk/host/host.d.ts +1 -1
  59. package/dist/types/sdk/host/query/handlers.d.ts +9 -0
  60. package/dist/types/sdk/index.d.ts +2 -0
  61. package/dist/types/sdk/prompt-status.d.ts +88 -0
  62. package/dist/types/sdk/session-directory.d.ts +1 -1
  63. package/dist/types/sdk/startup-capability.d.ts +3 -0
  64. package/dist/types/sdk/transport/auth-preface.d.ts +9 -0
  65. package/dist/types/sdk/transport/index.d.ts +12 -0
  66. package/dist/types/sdk/transport/relay.d.ts +43 -0
  67. package/dist/types/sdk/transport/serve-cli.d.ts +4 -0
  68. package/dist/types/sdk/transport/socket.d.ts +7 -0
  69. package/dist/types/sdk/transport/stdio.d.ts +3 -0
  70. package/dist/types/session/agent-session.d.ts +30 -5
  71. package/dist/types/session/btw-contract.d.ts +16 -0
  72. package/dist/types/session/internal/managed-session-scope.d.ts +32 -9
  73. package/dist/types/session/internal/managed-session-storage.d.ts +27 -10
  74. package/dist/types/session/internal/native-publish-outcome.d.ts +48 -0
  75. package/dist/types/session/session-manager.d.ts +25 -4
  76. package/dist/types/session/session-storage.d.ts +18 -0
  77. package/dist/types/setup/credential-import.d.ts +5 -1
  78. package/dist/types/setup/provider-onboarding.d.ts +2 -0
  79. package/dist/types/ssh/utils.d.ts +1 -0
  80. package/dist/types/task/discovery.d.ts +3 -1
  81. package/dist/types/task/index.d.ts +3 -1
  82. package/dist/types/task/receipt.d.ts +2 -0
  83. package/dist/types/task/types.d.ts +94 -0
  84. package/dist/types/tools/ask.d.ts +454 -174
  85. package/dist/types/tools/fetch.d.ts +5 -8
  86. package/dist/types/tools/image-gen.d.ts +63 -1
  87. package/dist/types/tools/index.d.ts +4 -0
  88. package/dist/types/tools/skill-discovery.d.ts +7 -0
  89. package/dist/types/tools/sqlite-reader.d.ts +7 -0
  90. package/dist/types/utils/prompt-suggestion.d.ts +33 -0
  91. package/dist/types/utils/shell-snapshot.d.ts +12 -0
  92. package/dist/types/web/insane/bridge.d.ts +1 -0
  93. package/dist/types/web/insane/url-guard.d.ts +17 -0
  94. package/package.json +8 -8
  95. package/scripts/capture-platform-shortcut-labels-showcase.ts +342 -0
  96. package/scripts/dogfood-repository-binding.ts +209 -0
  97. package/scripts/generate-sdk-operation-inventory.ts +4 -0
  98. package/scripts/run-test-manifest.ts +4 -4
  99. package/src/capability/index.ts +50 -42
  100. package/src/capability/types.ts +3 -0
  101. package/src/cli/args.ts +2 -92
  102. package/src/cli/notify-cli.ts +5 -38
  103. package/src/cli/setup-cli.ts +10 -4
  104. package/src/cli.ts +52 -9
  105. package/src/commands/daemon.ts +22 -5
  106. package/src/commands/sdk.ts +44 -11
  107. package/src/config/keybindings.ts +158 -25
  108. package/src/config/model-profile-activation.ts +7 -18
  109. package/src/config/model-profile-contract.ts +161 -0
  110. package/src/config/model-profiles.ts +18 -0
  111. package/src/config/model-registry.ts +11 -1
  112. package/src/config/settings-schema.ts +73 -7
  113. package/src/coordinator-mcp/model-preset.ts +21 -74
  114. package/src/defaults/gjc/skills/deep-interview/SKILL.md +2 -2
  115. package/src/defaults/gjc/skills/ralplan/SKILL.md +3 -1
  116. package/src/defaults/gjc/skills/ultragoal/SKILL.md +42 -1
  117. package/src/discovery/ssh.ts +12 -1
  118. package/src/edit/index.ts +3 -6
  119. package/src/edit/modes/patch.ts +38 -1
  120. package/src/edit/modes/replace.ts +42 -0
  121. package/src/edit/path-mutation-lock.ts +112 -0
  122. package/src/eval/py/executor.ts +30 -11
  123. package/src/eval/py/kernel.ts +1 -21
  124. package/src/eval/py/prelude.py +2 -2
  125. package/src/eval/py/runner-artifact.ts +84 -0
  126. package/src/eval/py/tool-bridge.ts +34 -18
  127. package/src/extensibility/gjc-plugins/runtime-adapters.ts +2 -1
  128. package/src/extensibility/plugins/marketplace/fetcher.ts +191 -7
  129. package/src/gjc-runtime/launch-tmux.ts +1 -1
  130. package/src/gjc-runtime/managed-owner-supervisor.ts +83 -4
  131. package/src/gjc-runtime/ralplan-runtime.ts +75 -3
  132. package/src/gjc-runtime/repository-binding.ts +267 -0
  133. package/src/gjc-runtime/session-state-sidecar.ts +25 -9
  134. package/src/gjc-runtime/tmux-owner-isolation.ts +2 -1
  135. package/src/gjc-runtime/tmux-sessions.ts +45 -6
  136. package/src/gjc-runtime/ultragoal-guard.ts +93 -15
  137. package/src/gjc-runtime/ultragoal-receipt-freshness.ts +103 -0
  138. package/src/gjc-runtime/ultragoal-runtime.ts +456 -31
  139. package/src/gjc-runtime/workflow-manifest.generated.json +58 -0
  140. package/src/gjc-runtime/workflow-manifest.ts +23 -0
  141. package/src/internal-urls/docs-index.generated.ts +12 -10
  142. package/src/internal-urls/local-protocol.ts +64 -21
  143. package/src/internal-urls/mcp-protocol.ts +73 -11
  144. package/src/main.ts +111 -37
  145. package/src/modes/DESIGN.md +5 -0
  146. package/src/modes/acp/acp-agent.ts +50 -16
  147. package/src/modes/action-registry.ts +1 -1
  148. package/src/modes/components/btw-panel.ts +82 -16
  149. package/src/modes/components/model-selector.ts +73 -11
  150. package/src/modes/components/plan-preview-overlay.ts +1 -1
  151. package/src/modes/components/runtime-mcp-add-wizard.ts +5 -0
  152. package/src/modes/components/tool-status-header.ts +25 -4
  153. package/src/modes/components/welcome.ts +22 -18
  154. package/src/modes/controllers/btw-controller.ts +119 -36
  155. package/src/modes/controllers/command-controller.ts +97 -54
  156. package/src/modes/controllers/event-controller.ts +10 -0
  157. package/src/modes/controllers/input-controller.ts +38 -2
  158. package/src/modes/controllers/runtime-mcp-command-controller.ts +29 -6
  159. package/src/modes/controllers/selector-controller.ts +149 -63
  160. package/src/modes/interactive-mode.ts +57 -34
  161. package/src/modes/prompt-action-autocomplete.ts +32 -13
  162. package/src/modes/prompt-suggestion-controller.ts +96 -0
  163. package/src/modes/shared/agent-wire/workflow-gate-broker.ts +2 -2
  164. package/src/modes/types.ts +4 -0
  165. package/src/modes/utils/hotkeys-markdown.ts +64 -36
  166. package/src/modes/utils/ui-helpers.ts +5 -3
  167. package/src/prompts/agents/architect.md +0 -1
  168. package/src/prompts/agents/critic.md +0 -1
  169. package/src/prompts/system/btw-user.md +3 -8
  170. package/src/prompts/system/prompt-suggestion-system.md +32 -0
  171. package/src/prompts/system/system-prompt.md +6 -4
  172. package/src/prompts/tools/cron.md +3 -1
  173. package/src/prompts/tools/skill-discovery.md +1 -0
  174. package/src/runtime-mcp/client.ts +41 -55
  175. package/src/runtime-mcp/content-limits.ts +71 -0
  176. package/src/runtime-mcp/json-rpc.ts +23 -9
  177. package/src/runtime-mcp/manager.ts +51 -53
  178. package/src/runtime-mcp/oauth-flow.ts +0 -72
  179. package/src/runtime-mcp/plugin-network-boundary.ts +101 -0
  180. package/src/runtime-mcp/transports/http.ts +63 -22
  181. package/src/sdk/broker/broker.ts +34 -20
  182. package/src/sdk/broker/lifecycle.ts +185 -36
  183. package/src/sdk/bus/chat-daemon-control.ts +19 -5
  184. package/src/sdk/bus/config-commands.ts +2 -2
  185. package/src/sdk/bus/config.ts +9 -1
  186. package/src/sdk/bus/conversation-store.ts +40 -6
  187. package/src/sdk/bus/index.ts +244 -70
  188. package/src/sdk/bus/lifecycle-commands.ts +63 -10
  189. package/src/sdk/bus/lifecycle-control-runtime.ts +11 -2
  190. package/src/sdk/bus/lifecycle-orchestrator.ts +32 -1
  191. package/src/sdk/bus/notification-orchestration.ts +12 -0
  192. package/src/sdk/bus/notification-service.ts +68 -20
  193. package/src/sdk/bus/prompt-reconciliation.ts +239 -0
  194. package/src/sdk/bus/recent-activity.ts +90 -26
  195. package/src/sdk/bus/telegram-daemon-contract.ts +18 -3
  196. package/src/sdk/bus/telegram-daemon-control.ts +147 -35
  197. package/src/sdk/bus/telegram-daemon.ts +2463 -450
  198. package/src/sdk/bus/telegram-reference.ts +20 -2
  199. package/src/sdk/bus/topic-registry.ts +451 -12
  200. package/src/sdk/cli/session-cli.ts +15 -2
  201. package/src/sdk/client/discovery.ts +19 -3
  202. package/src/sdk/client/liveness.ts +49 -0
  203. package/src/sdk/host/control/dispatch.ts +1 -1
  204. package/src/sdk/host/control/operations.ts +1 -1
  205. package/src/sdk/host/host.ts +2 -6
  206. package/src/sdk/host/query/handlers.ts +70 -5
  207. package/src/sdk/index.ts +12 -0
  208. package/src/sdk/prompt-status.ts +97 -0
  209. package/src/sdk/protocol/operation-inventory.generated.json +58 -0
  210. package/src/sdk/protocol/operation-registry.ts +18 -4
  211. package/src/sdk/session-directory.ts +5 -1
  212. package/src/sdk/session.ts +31 -5
  213. package/src/sdk/startup-capability.ts +9 -1
  214. package/src/sdk/transport/auth-preface.ts +82 -0
  215. package/src/sdk/transport/index.ts +18 -0
  216. package/src/sdk/transport/relay.ts +252 -0
  217. package/src/sdk/transport/serve-cli.ts +105 -0
  218. package/src/sdk/transport/socket.ts +197 -0
  219. package/src/sdk/transport/stdio.ts +17 -0
  220. package/src/session/agent-session.ts +292 -154
  221. package/src/session/blob-store.ts +25 -7
  222. package/src/session/btw-contract.ts +59 -0
  223. package/src/session/internal/managed-session-scope.ts +1163 -137
  224. package/src/session/internal/managed-session-storage.ts +397 -234
  225. package/src/session/internal/native-publish-outcome.ts +266 -0
  226. package/src/session/session-manager.ts +620 -403
  227. package/src/session/session-storage.ts +128 -11
  228. package/src/setup/credential-import.ts +28 -3
  229. package/src/setup/provider-onboarding.ts +30 -1
  230. package/src/setup/provider-presets.json +2 -1
  231. package/src/slash-commands/builtin-registry.ts +1 -1
  232. package/src/ssh/utils.ts +14 -0
  233. package/src/task/discovery.ts +8 -2
  234. package/src/task/gjc-command.ts +2 -2
  235. package/src/task/index.ts +121 -15
  236. package/src/task/receipt.ts +3 -0
  237. package/src/task/types.ts +34 -3
  238. package/src/tools/ask.ts +199 -89
  239. package/src/tools/ast-edit.ts +2 -2
  240. package/src/tools/bash-pty-selection.ts +2 -2
  241. package/src/tools/browser/screenshot-format.ts +6 -1
  242. package/src/tools/cron.ts +1 -1
  243. package/src/tools/fetch.ts +13 -131
  244. package/src/tools/image-gen.ts +476 -23
  245. package/src/tools/index.ts +4 -0
  246. package/src/tools/read.ts +2 -0
  247. package/src/tools/render-utils.ts +7 -1
  248. package/src/tools/skill-discovery.ts +39 -3
  249. package/src/tools/sqlite-reader.ts +63 -5
  250. package/src/utils/edit-mode.ts +2 -2
  251. package/src/utils/pasted-image-path.ts +15 -6
  252. package/src/utils/prompt-suggestion.ts +265 -0
  253. package/src/utils/shell-snapshot.ts +173 -63
  254. package/src/utils/sixel.ts +3 -3
  255. package/src/web/insane/bridge.ts +5 -1
  256. package/src/web/insane/url-guard.ts +140 -27
  257. package/src/web/scrapers/docs-rs.ts +30 -5
  258. package/src/web/scrapers/types.ts +19 -49
  259. package/src/web/scrapers/utils.ts +12 -26
@@ -7,6 +7,13 @@ import type { NativeExactUnlinkResult } from "@gajae-code/natives";
7
7
  import * as native from "@gajae-code/natives";
8
8
  import { resolveEquivalentPath } from "@gajae-code/utils";
9
9
 
10
+ import {
11
+ isModelProfileError,
12
+ type ModelProfileErrorDetails,
13
+ validateModelProfileName,
14
+ } from "../../config/model-profile-contract";
15
+ import { mergeModelProfiles } from "../../config/model-profiles";
16
+ import { ModelsConfigFile } from "../../config/model-registry";
10
17
  import {
11
18
  ensureLaunchWorktree,
12
19
  ensureReusableNodeModules,
@@ -326,14 +333,36 @@ function serializeCleanupIdentity(identity: CleanupIdentity): BrokerCleanupIdent
326
333
  };
327
334
  }
328
335
 
329
- const fail = (code: string, message: string, cleanup?: CleanupEvidence): BrokerResponse => ({
336
+ const fail = (
337
+ code: string,
338
+ message: string,
339
+ cleanup?: CleanupEvidence,
340
+ details?: ModelProfileErrorDetails,
341
+ ): BrokerResponse => ({
330
342
  ok: false,
331
- error: { code: code as never, message, ...(cleanup ? { cleanup } : {}) },
343
+ error: { code: code as never, message, ...(details ? { details } : {}), ...(cleanup ? { cleanup } : {}) },
332
344
  });
333
345
  function text(value: unknown): string | undefined {
334
346
  return typeof value === "string" && value ? value : undefined;
335
347
  }
336
348
 
349
+ function validateBrokerModelPreset(agentDir: string, requestedProfile: string): string | BrokerResponse {
350
+ const modelsConfigFile = ModelsConfigFile.relocate(path.join(agentDir, "models.yml"));
351
+ modelsConfigFile.invalidate();
352
+ const loaded = modelsConfigFile.tryLoad();
353
+ const profiles = mergeModelProfiles(loaded.status === "ok" ? loaded.value.profiles : undefined);
354
+ try {
355
+ return validateModelProfileName(requestedProfile, profiles, loaded.status === "error" ? loaded.error : undefined);
356
+ } catch (error) {
357
+ if (isModelProfileError(error)) return fail(error.code, error.message, undefined, error.details);
358
+ throw error;
359
+ }
360
+ }
361
+
362
+ export function validateBrokerModelPresetForTest(agentDir: string, requestedProfile: string): string | BrokerResponse {
363
+ return validateBrokerModelPreset(agentDir, requestedProfile);
364
+ }
365
+
337
366
  function readinessTimeout(input: Input): number | BrokerResponse {
338
367
  const value = input.readinessTimeoutMs;
339
368
  if (value === undefined) return READY_TIMEOUT_MS;
@@ -624,7 +653,7 @@ type ReadyAuthority = {
624
653
  };
625
654
  type ReadinessResult =
626
655
  | { kind: "ready"; authority: ReadyAuthority }
627
- | { kind: "startup_failed"; message: string }
656
+ | { kind: "startup_failed"; failure: SdkStartupFailure }
628
657
  | { kind: "child_exited" }
629
658
  | { kind: "timeout" };
630
659
  const processIncarnationReadersForTest = new WeakMap<Broker, (pid: number) => string | undefined>();
@@ -797,19 +826,25 @@ function isLifecycleTranscriptEvidence(value: unknown): value is LifecycleTransc
797
826
  function isSdkStartupFailure(value: unknown): value is SdkStartupFailure {
798
827
  if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
799
828
  const failure = value as Record<string, unknown>;
800
- return (
801
- Object.keys(failure).length === 3 &&
802
- (failure.phase === "registration" || failure.phase === "startup") &&
803
- (failure.reason === "disabled" ||
804
- failure.reason === "ineligible" ||
805
- failure.reason === "factory_absent" ||
806
- failure.reason === "runner_absent" ||
807
- failure.reason === "pending" ||
808
- failure.reason === "failed") &&
809
- typeof failure.message === "string" &&
810
- Buffer.byteLength(failure.message) > 0 &&
811
- Buffer.byteLength(failure.message) <= 512
812
- );
829
+ const keys = Object.keys(failure);
830
+ if (
831
+ !keys.every(
832
+ key => key === "phase" || key === "reason" || key === "message" || key === "code" || key === "details",
833
+ ) ||
834
+ (failure.phase !== "registration" && failure.phase !== "startup") ||
835
+ (failure.reason !== "disabled" &&
836
+ failure.reason !== "ineligible" &&
837
+ failure.reason !== "factory_absent" &&
838
+ failure.reason !== "runner_absent" &&
839
+ failure.reason !== "pending" &&
840
+ failure.reason !== "failed") ||
841
+ typeof failure.message !== "string" ||
842
+ Buffer.byteLength(failure.message) === 0 ||
843
+ Buffer.byteLength(failure.message) > 512
844
+ )
845
+ return false;
846
+ if (failure.code === undefined && failure.details === undefined) return keys.length === 3;
847
+ return keys.length === 5 && isModelProfileError(failure);
813
848
  }
814
849
 
815
850
  function isLifecycleFailureArtifact(value: unknown): value is LifecycleFailureArtifact {
@@ -818,8 +853,14 @@ function isLifecycleFailureArtifact(value: unknown): value is LifecycleFailureAr
818
853
  if (!isEffectMarker(record)) return false;
819
854
  const artifact = value as LifecycleFailureArtifact;
820
855
  return (
821
- Object.keys(record).length === (artifact.transcript === undefined ? 7 : 8) &&
822
- isSdkStartupFailure({ phase: artifact.phase, reason: artifact.reason, message: artifact.message }) &&
856
+ Object.keys(record).length ===
857
+ 7 + (artifact.code === undefined ? 0 : 2) + (artifact.transcript === undefined ? 0 : 1) &&
858
+ isSdkStartupFailure({
859
+ phase: artifact.phase,
860
+ reason: artifact.reason,
861
+ message: artifact.message,
862
+ ...(artifact.code === undefined ? {} : { code: artifact.code, details: artifact.details }),
863
+ }) &&
823
864
  isRollbackResult(artifact.rollback) &&
824
865
  (artifact.transcript === undefined || isLifecycleTranscriptEvidence(artifact.transcript))
825
866
  );
@@ -865,6 +906,8 @@ export async function writeSessionLifecycleFailure(
865
906
  ...(transcript ? { transcript } : {}),
866
907
  };
867
908
  const bytes = Buffer.from(canonicalJson(artifact), "utf8");
909
+ if (bytes.length > MAX_LIFECYCLE_METADATA_BYTES)
910
+ throw new Error("Lifecycle startup failure exceeds the metadata size ceiling.");
868
911
  const target = lifecycleFailurePath(root, id, effectMarker);
869
912
  const temporary = path.join(directory, `.${id}.lifecycle.failure.${effectMarker}.${randomUUID()}.tmp`);
870
913
  let published = false;
@@ -1241,6 +1284,10 @@ function validateLifecycleMetadataReplay(cleanup: CleanupEvidence): BrokerRespon
1241
1284
  if (!current) continue;
1242
1285
  if (!sameLifecycleCleanupIdentity(current.identity, file.identity))
1243
1286
  return fail("terminal_uncertain", "Lifecycle metadata candidate lacks exact replay authority.");
1287
+ // A completed file's recorded retained quarantine is receipt-bound durable
1288
+ // evidence; anything else that remains is an active survivor.
1289
+ if (file.completed && file.detachedPath && path.resolve(candidate) === path.resolve(file.detachedPath))
1290
+ continue;
1244
1291
  activeCandidates++;
1245
1292
  }
1246
1293
  if (file.completed && activeCandidates > 0)
@@ -1289,7 +1336,21 @@ function lifecycleMetadataReplayAbsent(cleanup: CleanupEvidence): boolean {
1289
1336
  const id = cleanup.sessionId!;
1290
1337
  const required = new Set<string>([lifecycleMarkerPath(root, id), lifecycleReadyPath(root, id)]);
1291
1338
  for (const file of files) for (const candidate of lifecycleCleanupCandidates(file)) required.add(candidate);
1292
- return [...required].every(absentLifecyclePath);
1339
+ for (const candidate of required) {
1340
+ if (absentLifecyclePath(candidate)) continue;
1341
+ // A completed file's recorded retained quarantine is durable evidence, not a
1342
+ // survivor — accept it only at its receipt-bound path and identity.
1343
+ const owner = files.find(
1344
+ file =>
1345
+ file.completed === true &&
1346
+ file.detachedPath !== undefined &&
1347
+ path.resolve(file.detachedPath) === path.resolve(candidate),
1348
+ );
1349
+ if (!owner) return false;
1350
+ const current = captureLifecycleFile(candidate, true, true);
1351
+ if (!current || !sameLifecycleCleanupIdentity(current.identity, owner.identity)) return false;
1352
+ }
1353
+ return true;
1293
1354
  }
1294
1355
 
1295
1356
  /**
@@ -1552,16 +1613,28 @@ async function reconcileLifecycleCleanup(
1552
1613
  const candidates = lifecycleCleanupCandidates(file);
1553
1614
  if (file.completed) {
1554
1615
  for (const candidate of candidates) {
1616
+ let stat: ReturnType<typeof fsSync.lstatSync>;
1555
1617
  try {
1556
- fsSync.lstatSync(candidate);
1557
- return fail(
1558
- "terminal_uncertain",
1559
- "Lifecycle cleanup receipt marks a target complete while an authorized candidate remains.",
1560
- );
1618
+ stat = fsSync.lstatSync(candidate);
1561
1619
  } catch (error) {
1562
- if ((error as NodeJS.ErrnoException).code !== "ENOENT")
1563
- return fail("terminal_uncertain", "Lifecycle cleanup completion could not be safely inspected.");
1620
+ if ((error as NodeJS.ErrnoException).code === "ENOENT") continue;
1621
+ return fail("terminal_uncertain", "Lifecycle cleanup completion could not be safely inspected.");
1622
+ }
1623
+ // A completed file's recorded retained quarantine is durable evidence,
1624
+ // not a survivor — accept it only at its receipt-bound path and identity.
1625
+ if (
1626
+ file.detachedPath &&
1627
+ path.resolve(candidate) === path.resolve(file.detachedPath) &&
1628
+ stat.isFile() &&
1629
+ !stat.isSymbolicLink()
1630
+ ) {
1631
+ const current = captureLifecycleFile(candidate, true, true);
1632
+ if (current && sameLifecycleCleanupIdentity(current.identity, file.identity)) continue;
1564
1633
  }
1634
+ return fail(
1635
+ "terminal_uncertain",
1636
+ "Lifecycle cleanup receipt marks a target complete while an authorized candidate remains.",
1637
+ );
1565
1638
  }
1566
1639
  continue;
1567
1640
  }
@@ -1631,6 +1704,22 @@ async function reconcileLifecycleCleanup(
1631
1704
  quarantineName: path.basename(currentFile.plannedPath),
1632
1705
  });
1633
1706
  if (!result.ok) {
1707
+ if (result.code === "cleanup_pending" && result.detachedPath === currentFile.plannedPath) {
1708
+ // Typed retained authority: the native verified the exact identity-bound
1709
+ // detach and retained the quarantine as durable evidence. Record the
1710
+ // evidence and advance — never claim a terminal byte deletion.
1711
+ const lifecycleFiles = activeCleanup.lifecycleFiles!.map((candidate, candidateIndex) =>
1712
+ candidateIndex === index
1713
+ ? { ...candidate, detachedPath: result.detachedPath, completed: true as const }
1714
+ : candidate,
1715
+ );
1716
+ activeCleanup = { ...activeCleanup, lifecycleFiles };
1717
+ await broker.ledger.transition(identity, "effect_started", {
1718
+ response: fail("cleanup_pending", "Lifecycle cleanup completion was durably reconciled.", activeCleanup),
1719
+ });
1720
+ lifecycleCleanupHooksForTest.get(broker)?.();
1721
+ continue;
1722
+ }
1634
1723
  const lifecycleFiles = activeCleanup.lifecycleFiles!.map((candidate, candidateIndex) =>
1635
1724
  candidateIndex === index && result.detachedPath
1636
1725
  ? { ...candidate, detachedPath: result.detachedPath }
@@ -1665,6 +1754,22 @@ async function readSessionLifecycleFailure(
1665
1754
  ?.artifact;
1666
1755
  }
1667
1756
 
1757
+ export async function readSessionLifecycleFailureForTest(
1758
+ root: string,
1759
+ id: string,
1760
+ expected: { pid: number; effectMarker: string; incarnation: string },
1761
+ ): Promise<SdkStartupFailure | undefined> {
1762
+ const artifact = await readSessionLifecycleFailure(root, id, expected);
1763
+ return artifact
1764
+ ? {
1765
+ phase: artifact.phase,
1766
+ reason: artifact.reason,
1767
+ message: artifact.message,
1768
+ ...(artifact.code === undefined ? {} : { code: artifact.code, details: artifact.details }),
1769
+ }
1770
+ : undefined;
1771
+ }
1772
+
1668
1773
  async function hasDurableProcessIdentity(
1669
1774
  root: string,
1670
1775
  id: string,
@@ -2056,14 +2161,14 @@ async function waitForReady(
2056
2161
  ): Promise<ReadinessResult> {
2057
2162
  while (timing.now() < deadline) {
2058
2163
  const startupFailure = await readSessionLifecycleFailure(root, id, expected);
2059
- if (startupFailure) return { kind: "startup_failed", message: startupFailure.message };
2164
+ if (startupFailure) return { kind: "startup_failed", failure: startupFailure };
2060
2165
  if (
2061
2166
  observeProcess(expected.pid, expected.incarnation, value => processIncarnationForBroker(broker, value)) ===
2062
2167
  "exited"
2063
2168
  ) {
2064
2169
  const finalStartupFailure = await readSessionLifecycleFailure(root, id, expected);
2065
2170
  return finalStartupFailure
2066
- ? { kind: "startup_failed", message: finalStartupFailure.message }
2171
+ ? { kind: "startup_failed", failure: finalStartupFailure }
2067
2172
  : { kind: "child_exited" };
2068
2173
  }
2069
2174
  try {
@@ -2191,6 +2296,8 @@ async function launchInput(
2191
2296
  const requested = sessionId(input);
2192
2297
  if (requested !== undefined && !isCanonicalSessionId(requested))
2193
2298
  return fail("invalid_input", "sessionId must be a canonical safe identifier.");
2299
+ if (input.modelPreset !== undefined && (typeof input.modelPreset !== "string" || input.modelPreset.length === 0))
2300
+ return fail("invalid_input", "modelPreset must be a non-empty exact profile ID.");
2194
2301
  const modelPreset = text(input.modelPreset);
2195
2302
 
2196
2303
  if (operation === "session.create")
@@ -2615,6 +2722,11 @@ async function executeLifecycleResponse(
2615
2722
 
2616
2723
  const launch = await launchInput(broker, operation, input);
2617
2724
  if ("ok" in launch) return launch;
2725
+ if (launch.modelPreset) {
2726
+ const validatedModelPreset = validateBrokerModelPreset(broker.settings.agentDir, launch.modelPreset);
2727
+ if (typeof validatedModelPreset !== "string") return validatedModelPreset;
2728
+ launch.modelPreset = validatedModelPreset;
2729
+ }
2618
2730
  if (!hasProcessIncarnationAuthority())
2619
2731
  return fail(
2620
2732
  "incarnation_unavailable",
@@ -2768,7 +2880,12 @@ async function executeLifecycleResponse(
2768
2880
  `Session ${launch.id} did not become ready and its spawned process could not be verified dead.`,
2769
2881
  );
2770
2882
  return readiness.kind === "startup_failed"
2771
- ? fail("spawn_failed", readiness.message)
2883
+ ? fail(
2884
+ readiness.failure.code ?? "spawn_failed",
2885
+ readiness.failure.message,
2886
+ undefined,
2887
+ readiness.failure.details,
2888
+ )
2772
2889
  : readiness.kind === "child_exited"
2773
2890
  ? fail("spawn_failed", `Session ${launch.id} exited before registering readiness.`)
2774
2891
  : fail(
@@ -3043,11 +3160,26 @@ async function executeLifecycleResponse(
3043
3160
  `Unable to delete saved session artifacts: ${error instanceof Error ? error.message : String(error)}`,
3044
3161
  );
3045
3162
  }
3046
- if (deleted.kind === "artifacts_removed") {
3163
+ const retainedArtifactsCleanup =
3164
+ deleted.kind === "cleanup_pending" &&
3165
+ deleted.phase === "artifacts" &&
3166
+ deleted.detachedArtifactsPath !== undefined &&
3167
+ cleanupTarget.plannedArtifactsPath !== undefined &&
3168
+ (deleted.detachedArtifactsPath === cleanupTarget.plannedArtifactsPath ||
3169
+ deleted.detachedArtifactsPath === `${cleanupTarget.plannedArtifactsPath}.removing`);
3170
+ if (deleted.kind === "artifacts_removed" || retainedArtifactsCleanup) {
3047
3171
  const transcriptPhaseCleanup = {
3048
3172
  ...preauthorizedCleanup,
3049
3173
  phase: "transcript" as const,
3050
3174
  artifactsRemoved: true,
3175
+ ...(deleted.kind === "cleanup_pending" && deleted.phase === "artifacts"
3176
+ ? {
3177
+ detachedArtifactsPath: deleted.detachedArtifactsPath,
3178
+ ...(deleted.artifactsIdentity
3179
+ ? { artifactsIdentity: serializeCleanupIdentity(deleted.artifactsIdentity) }
3180
+ : {}),
3181
+ }
3182
+ : {}),
3051
3183
  ...(preauthorizedCleanup.artifactTree
3052
3184
  ? { artifactTree: { ...preauthorizedCleanup.artifactTree, completed: true as const } }
3053
3185
  : {}),
@@ -3068,7 +3200,14 @@ async function executeLifecycleResponse(
3068
3200
  artifactsRemoved: true,
3069
3201
  });
3070
3202
  }
3071
- if (deleted.kind === "cleanup_pending")
3203
+ if (
3204
+ deleted.kind === "cleanup_pending" &&
3205
+ !(
3206
+ deleted.phase === "transcript" &&
3207
+ deleted.detachedTranscriptPath !== undefined &&
3208
+ deleted.detachedTranscriptPath === cleanupTarget.plannedTranscriptPath
3209
+ )
3210
+ )
3072
3211
  return fail(
3073
3212
  "cleanup_pending",
3074
3213
  `Saved session cleanup is pending in ${deleted.phase}: ${deleted.error.message}`,
@@ -3323,6 +3462,9 @@ export async function executeLifecycle(
3323
3462
  phase: evidence.artifact.phase,
3324
3463
  reason: evidence.artifact.reason,
3325
3464
  message: evidence.artifact.message,
3465
+ ...(evidence.artifact.code === undefined
3466
+ ? {}
3467
+ : { code: evidence.artifact.code, details: evidence.artifact.details }),
3326
3468
  rollback: {
3327
3469
  endpointGeneration: evidence.artifact.rollback.endpointGeneration,
3328
3470
  fenced: evidence.artifact.rollback.fenced,
@@ -3387,11 +3529,18 @@ export async function executeLifecycle(
3387
3529
  : startupFailure && cleanupProof
3388
3530
  ? {
3389
3531
  ok: false,
3390
- error: {
3391
- code: "spawn_failed",
3392
- message: "No ready SDK endpoint remains available.",
3393
- endpoint: "unavailable",
3394
- },
3532
+ error: startupFailure.code
3533
+ ? {
3534
+ code: startupFailure.code,
3535
+ message: startupFailure.message,
3536
+ details: startupFailure.details!,
3537
+ endpoint: "unavailable" as const,
3538
+ }
3539
+ : {
3540
+ code: "spawn_failed",
3541
+ message: "No ready SDK endpoint remains available.",
3542
+ endpoint: "unavailable" as const,
3543
+ },
3395
3544
  ...(durableEffects ? { durableEffects } : {}),
3396
3545
  startupFailure,
3397
3546
  }
@@ -27,11 +27,16 @@ export type ChatDaemonAction = "stop" | "reload";
27
27
  * Generation 6 carries the retained managed filesystem authority boundary.
28
28
  * Generation 7 restores macOS daemon signaling (kill(2) with a start-time
29
29
  * incarnation recheck) so a live/hung owner can be replaced without an external
30
- * `kill -9`.
30
+ * `kill -9`. Generation 8 adopts Windows expected-identity ACL verification and
31
+ * repair for shared native authority. Generation 9 refreshes the shared native
32
+ * authority declaration contract with bounded frame-delivery acknowledgement.
33
+ * Generation 11 accepts typed retained exact-unlink cleanup authority — a
34
+ * concrete detached quarantine plus a proven-absent canonical lock pathname —
35
+ * when deleting an observed owner-lock lease.
31
36
  */
32
37
  export const CHAT_DAEMON_GENERATIONS: Readonly<Record<ChatDaemonKind, number>> = {
33
- discord: 7,
34
- slack: 7,
38
+ discord: 11,
39
+ slack: 11,
35
40
  };
36
41
 
37
42
  export function chatDaemonGeneration(kind: ChatDaemonKind): number {
@@ -937,10 +942,19 @@ async function ownsChatDaemonOwnerLock(lock: string, lease: ChatDaemonOwnerLockL
937
942
  /** Deletes only the exact lease observed by this contender; a successor is retained. */
938
943
  function unlinkExactChatDaemonOwnerLock(lock: string, lease: ChatDaemonOwnerLockLease): boolean {
939
944
  try {
940
- return native.exactUnlink(lock, {
945
+ const removed = native.exactUnlink(lock, {
941
946
  ...lease,
942
947
  quarantineName: `.gjc-delete-chat-daemon-lock-${crypto.randomUUID()}`,
943
- }).ok;
948
+ });
949
+ if (removed.ok) return true;
950
+ // Accept only typed retained authority: a concrete detached quarantine plus
951
+ // a proven-absent canonical lock pathname. Anything else stays fail-closed.
952
+ return (
953
+ removed.code === "cleanup_pending" &&
954
+ typeof removed.detachedPath === "string" &&
955
+ removed.detachedPath.length > 0 &&
956
+ !fs.existsSync(lock)
957
+ );
944
958
  } catch {
945
959
  return false;
946
960
  }
@@ -5,8 +5,8 @@
5
5
  * removed), but the user can still adjust per-surface behaviour from inside a
6
6
  * session thread with small slash commands:
7
7
  *
8
- * - `/verbose` switch the mirror to bounded tool-owned summaries + provider-displayable reasoning summaries
9
- * - `/lean` switch back to lean (assistant text + tool names)
8
+ * - `/verbose` switch the mirror to per-turn assistant text + tool summaries + reasoning summaries
9
+ * - `/lean` settled assistant answer at idle + immediate ask lead-ins (no intermediate tool-turn flood)
10
10
  * - `/verbosity lean|verbose`
11
11
  * - `/redact on|off` toggle redaction of streamed content
12
12
  *
@@ -540,6 +540,8 @@ export interface RedactableAction {
540
540
  question?: string;
541
541
  options?: string[];
542
542
  summary?: string;
543
+ /** Optional zero-based recommendation into the authoritative raw options. */
544
+ recommendedIndex?: number;
543
545
  }
544
546
 
545
547
  /**
@@ -563,6 +565,12 @@ export function buildRedactedAction(
563
565
  // Asks stay fully readable/answerable even under redaction.
564
566
  if (action.kind === "ask") return action;
565
567
 
566
- const { summary: _summary, question: _question, options: _options, ...base } = action;
568
+ const {
569
+ summary: _summary,
570
+ question: _question,
571
+ options: _options,
572
+ recommendedIndex: _recommendedIndex,
573
+ ...base
574
+ } = action;
567
575
  return base;
568
576
  }
@@ -92,6 +92,7 @@ export class ConversationStore<T extends ConversationRecord> {
92
92
  readonly #pidAlive: (pid: number) => boolean;
93
93
  readonly #sleep: (ms: number) => Promise<void>;
94
94
  readonly #lockTimeoutMs: number;
95
+ readonly #platform: NodeJS.Platform;
95
96
 
96
97
  constructor(input: {
97
98
  agentDir: string;
@@ -104,6 +105,7 @@ export class ConversationStore<T extends ConversationRecord> {
104
105
  pidAlive?: (pid: number) => boolean;
105
106
  sleep?: (ms: number) => Promise<void>;
106
107
  lockTimeoutMs?: number;
108
+ platform?: NodeJS.Platform;
107
109
  }) {
108
110
  this.#file = conversationStorePath(input.agentDir, input.kind, input.fileName);
109
111
  this.#directory = path.dirname(this.#file);
@@ -114,6 +116,7 @@ export class ConversationStore<T extends ConversationRecord> {
114
116
  this.#pidAlive = input.pidAlive ?? defaultPidAlive;
115
117
  this.#sleep = input.sleep ?? (async ms => await Bun.sleep(ms));
116
118
  this.#lockTimeoutMs = input.lockTimeoutMs ?? 1_000;
119
+ this.#platform = input.platform ?? process.platform;
117
120
  }
118
121
 
119
122
  get filePath(): string {
@@ -325,12 +328,7 @@ export class ConversationStore<T extends ConversationRecord> {
325
328
  await handle.close();
326
329
  }
327
330
  await this.#fs.rename(temporary, this.#file);
328
- const directory = await this.#fs.open(this.#directory, "r");
329
- try {
330
- await directory.sync();
331
- } finally {
332
- await directory.close();
333
- }
331
+ await syncParentDirectory(this.#fs, this.#directory, this.#platform);
334
332
  } catch (error) {
335
333
  await this.#fs.unlink(temporary).catch(() => undefined);
336
334
  throw error;
@@ -342,6 +340,42 @@ function isMissing(error: unknown): error is NodeJS.ErrnoException {
342
340
  return isRecord(error) && error.code === "ENOENT";
343
341
  }
344
342
 
343
+ async function syncParentDirectory(
344
+ fs: ConversationStoreFs,
345
+ directory: string,
346
+ platform: NodeJS.Platform,
347
+ ): Promise<void> {
348
+ let handle: ConversationStoreFileHandle;
349
+ try {
350
+ handle = await fs.open(directory, "r");
351
+ } catch (error) {
352
+ if (platform === "win32" && isUnsupportedDirectoryBarrierError(error)) return;
353
+ throw error;
354
+ }
355
+ let syncError: unknown;
356
+ try {
357
+ await handle.sync();
358
+ } catch (error) {
359
+ if (!(platform === "win32" && isUnsupportedDirectoryBarrierError(error))) syncError = error;
360
+ }
361
+ let closeError: unknown;
362
+ try {
363
+ await handle.close();
364
+ } catch (error) {
365
+ closeError = error;
366
+ }
367
+ if (syncError && closeError)
368
+ throw new AggregateError([syncError, closeError], "Parent directory sync and close failed");
369
+ if (syncError) throw syncError;
370
+ if (closeError) throw closeError;
371
+ }
372
+
373
+ function isUnsupportedDirectoryBarrierError(error: unknown): boolean {
374
+ return (
375
+ isRecord(error) &&
376
+ (error.code === "EINVAL" || error.code === "ENOTSUP" || error.code === "EOPNOTSUPP" || error.code === "EPERM")
377
+ );
378
+ }
345
379
  function isAlreadyExists(error: unknown): error is NodeJS.ErrnoException {
346
380
  return isRecord(error) && error.code === "EEXIST";
347
381
  }