ai4ai 0.0.3 → 0.0.6

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 (184) hide show
  1. package/README.md +6 -0
  2. package/README.zh-CN.md +6 -0
  3. package/claude-plugin/.claude-plugin/plugin.json +1 -1
  4. package/claude-plugin/dist/adapters/claude/adapter.d.ts +10 -1
  5. package/claude-plugin/dist/adapters/claude/adapter.js +35 -10
  6. package/claude-plugin/dist/adapters/claude/journal.d.ts +8 -0
  7. package/claude-plugin/dist/adapters/claude/journal.js +4 -1
  8. package/claude-plugin/dist/adapters/claude/plugin.js +254 -107
  9. package/claude-plugin/dist/adapters/claude/worker.js +30 -8
  10. package/claude-plugin/dist/adapters/codex/adapter.d.ts +26 -19
  11. package/claude-plugin/dist/adapters/codex/adapter.js +283 -187
  12. package/claude-plugin/dist/adapters/codex/app-server.js +1 -1
  13. package/claude-plugin/dist/adapters/codex/control.d.ts +36 -1
  14. package/claude-plugin/dist/adapters/codex/control.js +74 -4
  15. package/claude-plugin/dist/adapters/codex/native-handoff.d.ts +60 -0
  16. package/claude-plugin/dist/adapters/codex/native-handoff.js +138 -0
  17. package/claude-plugin/dist/adapters/codex/runner.js +35 -32
  18. package/claude-plugin/dist/adapters/codex/tui-daemon-watch.js +60 -49
  19. package/claude-plugin/dist/adapters/declarations.d.ts +0 -1
  20. package/claude-plugin/dist/adapters/declarations.js +0 -1
  21. package/claude-plugin/dist/adapters/dsh/adapter.d.ts +39 -2
  22. package/claude-plugin/dist/adapters/dsh/adapter.js +164 -37
  23. package/claude-plugin/dist/adapters/dsh/plugin.d.ts +3 -1
  24. package/claude-plugin/dist/adapters/dsh/plugin.js +33 -22
  25. package/claude-plugin/dist/adapters/executors.d.ts +25 -2
  26. package/claude-plugin/dist/adapters/executors.js +58 -4
  27. package/claude-plugin/dist/adapters/external.d.ts +21 -0
  28. package/claude-plugin/dist/adapters/external.js +128 -18
  29. package/claude-plugin/dist/adapters/opencode/adapter.d.ts +13 -2
  30. package/claude-plugin/dist/adapters/opencode/adapter.js +53 -10
  31. package/claude-plugin/dist/adapters/opencode/journal.d.ts +2 -0
  32. package/claude-plugin/dist/adapters/opencode/journal.js +12 -4
  33. package/claude-plugin/dist/adapters/opencode/plugin.d.ts +3 -5
  34. package/claude-plugin/dist/adapters/opencode/plugin.js +3 -292
  35. package/claude-plugin/dist/adapters/opencode/setup.d.ts +9 -0
  36. package/claude-plugin/dist/adapters/opencode/setup.js +350 -0
  37. package/claude-plugin/dist/adapters/supervisor.js +64 -20
  38. package/claude-plugin/dist/adapters/types.d.ts +7 -0
  39. package/claude-plugin/dist/contract/schema.d.ts +8 -17
  40. package/claude-plugin/dist/contract/schema.js +3 -4
  41. package/claude-plugin/dist/contract/states.d.ts +11 -0
  42. package/claude-plugin/dist/contract/states.js +9 -0
  43. package/claude-plugin/dist/contract/types.d.ts +3 -3
  44. package/claude-plugin/dist/contract/validate.js +24 -14
  45. package/claude-plugin/dist/contract/version.d.ts +1 -1
  46. package/claude-plugin/dist/contract/version.js +1 -1
  47. package/claude-plugin/dist/core/dsh-selection.d.ts +43 -0
  48. package/claude-plugin/dist/core/dsh-selection.js +78 -0
  49. package/claude-plugin/dist/core/handoff.d.ts +42 -0
  50. package/claude-plugin/dist/core/handoff.js +63 -0
  51. package/claude-plugin/dist/core/index.d.ts +2 -0
  52. package/claude-plugin/dist/core/index.js +1 -0
  53. package/claude-plugin/dist/core/operations.js +33 -1
  54. package/claude-plugin/dist/core/retained-input.d.ts +24 -0
  55. package/claude-plugin/dist/core/retained-input.js +50 -0
  56. package/claude-plugin/dist/core/session-probe.js +11 -22
  57. package/claude-plugin/dist/core/store.d.ts +8 -3
  58. package/claude-plugin/dist/core/store.js +17 -3
  59. package/claude-plugin/request-schema.json +1 -2
  60. package/dist/adapters/claude/adapter.d.ts +10 -1
  61. package/dist/adapters/claude/adapter.js +35 -10
  62. package/dist/adapters/claude/journal.d.ts +8 -0
  63. package/dist/adapters/claude/journal.js +4 -1
  64. package/dist/adapters/claude/plugin.js +254 -107
  65. package/dist/adapters/claude/worker.js +30 -8
  66. package/dist/adapters/codex/adapter.d.ts +26 -19
  67. package/dist/adapters/codex/adapter.js +283 -187
  68. package/dist/adapters/codex/app-server.js +1 -1
  69. package/dist/adapters/codex/control.d.ts +36 -1
  70. package/dist/adapters/codex/control.js +74 -4
  71. package/dist/adapters/codex/native-handoff.d.ts +60 -0
  72. package/dist/adapters/codex/native-handoff.js +138 -0
  73. package/dist/adapters/codex/runner.js +35 -32
  74. package/dist/adapters/codex/tui-daemon-watch.js +60 -49
  75. package/dist/adapters/declarations.d.ts +0 -1
  76. package/dist/adapters/declarations.js +0 -1
  77. package/dist/adapters/dsh/adapter.d.ts +39 -2
  78. package/dist/adapters/dsh/adapter.js +164 -37
  79. package/dist/adapters/dsh/plugin.d.ts +3 -1
  80. package/dist/adapters/dsh/plugin.js +33 -22
  81. package/dist/adapters/executors.d.ts +25 -2
  82. package/dist/adapters/executors.js +58 -4
  83. package/dist/adapters/external.d.ts +21 -0
  84. package/dist/adapters/external.js +128 -18
  85. package/dist/adapters/opencode/adapter.d.ts +13 -2
  86. package/dist/adapters/opencode/adapter.js +53 -10
  87. package/dist/adapters/opencode/journal.d.ts +2 -0
  88. package/dist/adapters/opencode/journal.js +12 -4
  89. package/dist/adapters/opencode/plugin.d.ts +3 -5
  90. package/dist/adapters/opencode/plugin.js +3 -292
  91. package/dist/adapters/opencode/setup.d.ts +9 -0
  92. package/dist/adapters/opencode/setup.js +350 -0
  93. package/dist/adapters/supervisor.js +64 -20
  94. package/dist/adapters/types.d.ts +7 -0
  95. package/dist/contract/schema.d.ts +8 -17
  96. package/dist/contract/schema.js +3 -4
  97. package/dist/contract/states.d.ts +11 -0
  98. package/dist/contract/states.js +9 -0
  99. package/dist/contract/types.d.ts +3 -3
  100. package/dist/contract/validate.js +24 -14
  101. package/dist/contract/version.d.ts +1 -1
  102. package/dist/contract/version.js +1 -1
  103. package/dist/core/dsh-selection.d.ts +43 -0
  104. package/dist/core/dsh-selection.js +78 -0
  105. package/dist/core/handoff.d.ts +42 -0
  106. package/dist/core/handoff.js +63 -0
  107. package/dist/core/index.d.ts +2 -0
  108. package/dist/core/index.js +1 -0
  109. package/dist/core/operations.js +33 -1
  110. package/dist/core/retained-input.d.ts +24 -0
  111. package/dist/core/retained-input.js +50 -0
  112. package/dist/core/session-probe.js +11 -22
  113. package/dist/core/store.d.ts +8 -3
  114. package/dist/core/store.js +17 -3
  115. package/docs/contract.md +31 -15
  116. package/opencode-plugin/dist/adapters/claude/adapter.d.ts +10 -1
  117. package/opencode-plugin/dist/adapters/claude/adapter.js +35 -10
  118. package/opencode-plugin/dist/adapters/claude/journal.d.ts +8 -0
  119. package/opencode-plugin/dist/adapters/claude/journal.js +4 -1
  120. package/opencode-plugin/dist/adapters/claude/plugin.js +254 -107
  121. package/opencode-plugin/dist/adapters/claude/worker.js +30 -8
  122. package/opencode-plugin/dist/adapters/codex/adapter.d.ts +26 -19
  123. package/opencode-plugin/dist/adapters/codex/adapter.js +283 -187
  124. package/opencode-plugin/dist/adapters/codex/app-server.js +1 -1
  125. package/opencode-plugin/dist/adapters/codex/control.d.ts +36 -1
  126. package/opencode-plugin/dist/adapters/codex/control.js +74 -4
  127. package/opencode-plugin/dist/adapters/codex/native-handoff.d.ts +60 -0
  128. package/opencode-plugin/dist/adapters/codex/native-handoff.js +138 -0
  129. package/opencode-plugin/dist/adapters/codex/runner.js +35 -32
  130. package/opencode-plugin/dist/adapters/codex/tui-daemon-watch.js +60 -49
  131. package/opencode-plugin/dist/adapters/declarations.d.ts +0 -1
  132. package/opencode-plugin/dist/adapters/declarations.js +0 -1
  133. package/opencode-plugin/dist/adapters/dsh/adapter.d.ts +39 -2
  134. package/opencode-plugin/dist/adapters/dsh/adapter.js +164 -37
  135. package/opencode-plugin/dist/adapters/dsh/plugin.d.ts +3 -1
  136. package/opencode-plugin/dist/adapters/dsh/plugin.js +33 -22
  137. package/opencode-plugin/dist/adapters/executors.d.ts +25 -2
  138. package/opencode-plugin/dist/adapters/executors.js +58 -4
  139. package/opencode-plugin/dist/adapters/external.d.ts +21 -0
  140. package/opencode-plugin/dist/adapters/external.js +128 -18
  141. package/opencode-plugin/dist/adapters/opencode/adapter.d.ts +13 -2
  142. package/opencode-plugin/dist/adapters/opencode/adapter.js +53 -10
  143. package/opencode-plugin/dist/adapters/opencode/journal.d.ts +2 -0
  144. package/opencode-plugin/dist/adapters/opencode/journal.js +12 -4
  145. package/opencode-plugin/dist/adapters/opencode/plugin.d.ts +3 -5
  146. package/opencode-plugin/dist/adapters/opencode/plugin.js +3 -292
  147. package/opencode-plugin/dist/adapters/opencode/setup.d.ts +9 -0
  148. package/opencode-plugin/dist/adapters/opencode/setup.js +350 -0
  149. package/opencode-plugin/dist/adapters/supervisor.js +64 -20
  150. package/opencode-plugin/dist/adapters/types.d.ts +7 -0
  151. package/opencode-plugin/dist/contract/schema.d.ts +8 -17
  152. package/opencode-plugin/dist/contract/schema.js +3 -4
  153. package/opencode-plugin/dist/contract/states.d.ts +11 -0
  154. package/opencode-plugin/dist/contract/states.js +9 -0
  155. package/opencode-plugin/dist/contract/types.d.ts +3 -3
  156. package/opencode-plugin/dist/contract/validate.js +24 -14
  157. package/opencode-plugin/dist/contract/version.d.ts +1 -1
  158. package/opencode-plugin/dist/contract/version.js +1 -1
  159. package/opencode-plugin/dist/core/dsh-selection.d.ts +43 -0
  160. package/opencode-plugin/dist/core/dsh-selection.js +78 -0
  161. package/opencode-plugin/dist/core/handoff.d.ts +42 -0
  162. package/opencode-plugin/dist/core/handoff.js +63 -0
  163. package/opencode-plugin/dist/core/index.d.ts +2 -0
  164. package/opencode-plugin/dist/core/index.js +1 -0
  165. package/opencode-plugin/dist/core/operations.js +33 -1
  166. package/opencode-plugin/dist/core/retained-input.d.ts +24 -0
  167. package/opencode-plugin/dist/core/retained-input.js +50 -0
  168. package/opencode-plugin/dist/core/session-probe.js +11 -22
  169. package/opencode-plugin/dist/core/store.d.ts +8 -3
  170. package/opencode-plugin/dist/core/store.js +17 -3
  171. package/opencode-plugin/package.json +1 -1
  172. package/package.json +1 -1
  173. package/claude-plugin/dist/adapters/codex/tui-restart-watch.d.ts +0 -2
  174. package/claude-plugin/dist/adapters/codex/tui-restart-watch.js +0 -330
  175. package/claude-plugin/dist/tmux/backend.d.ts +0 -55
  176. package/claude-plugin/dist/tmux/backend.js +0 -161
  177. package/dist/adapters/codex/tui-restart-watch.d.ts +0 -2
  178. package/dist/adapters/codex/tui-restart-watch.js +0 -330
  179. package/dist/tmux/backend.d.ts +0 -55
  180. package/dist/tmux/backend.js +0 -161
  181. package/opencode-plugin/dist/adapters/codex/tui-restart-watch.d.ts +0 -2
  182. package/opencode-plugin/dist/adapters/codex/tui-restart-watch.js +0 -330
  183. package/opencode-plugin/dist/tmux/backend.d.ts +0 -55
  184. package/opencode-plugin/dist/tmux/backend.js +0 -161
package/docs/contract.md CHANGED
@@ -46,19 +46,42 @@ A pending handoff cancelled before application returns `cancelled`. For `cancel`
46
46
  `completed` means the target confirmed stopped, `pending` means the stop was requested,
47
47
  `unknown` means no confirmation was obtained.
48
48
 
49
+ ## Handoff phases, successors and idempotency
50
+
51
+ - `handoff.phase` is a set of reportable states, not a mandatory sequence. An implementation
52
+ is not required to visit every value in order, and `scheduled` is optional: an adapter may
53
+ report `pending` -> `applied` -> `completed` directly when its native safe point is atomic.
54
+ - `successor` is a complete Identity: `harness`, `workspace`, `surface`, `session`,
55
+ `generation` and `agent`. A handoff always keeps the native `session` and advances only
56
+ `generation`; it never changes the session identity. Use `spawn` for a new session, and
57
+ never fabricate a successor identity from a CLI carrier id.
58
+ - `proof.mechanism` is `surface-replacement` (zero-summary in-place restart) or
59
+ `native-compaction` (explicit compact opt-in that used the harness summarizer).
60
+ `new-session` is legacy read-only evidence from releases before 0.0.5 and is accepted
61
+ only when re-reading those records; current adapters never produce it.
62
+ - The first `handoff` call may return `pending` because the native transition completes at a
63
+ safe point. Re-querying with the same `operationId` is idempotent and returns the
64
+ progressed (eventually `completed`) result; it must not start a second transition.
65
+ - A handoff is atomic once accepted: real user input that arrives while it is `pending`,
66
+ `scheduled` or `applied` does not cancel it. Adapters retain that input and deliver it in
67
+ the fresh context, after the handoff task and in arrival order; consecutive messages may be
68
+ merged into one replay. Only an explicit abort/cancel or a mechanism failure (marker,
69
+ phase or session identity mismatch) terminates a handoff, and an aborted handoff discards
70
+ its retained input instead of replaying it later.
71
+
49
72
  ## Request fields
50
73
 
51
74
  - `operation`: `handoff`, `spawn`, `status`, `message`, `cancel`, `stop`, `list`, `capabilities`.
52
75
  - `operationId`: caller-chosen idempotency key.
53
76
  - `target`: `"self"` or an owned executor id (`handoff`, `status`, `message`, `cancel`).
54
- - `mode`: `compact` | `restart` (`compact` in place, `restart` fresh context).
77
+ - `mode`: `compact` | `restart` (`restart` is the default and replaces the context in place with the material only; `compact` is an explicit opt-in that uses the harness summarizer and is refused where the capability declaration does not list it).
55
78
  - `surface`: `preserve` | `tui` | `headless` | `web`; default `preserve`. A silent surface change is forbidden.
56
79
  - `task`: seed material for `handoff`, `spawn`, `message`.
57
80
  - `model`, `reasoningEffort`: optional overrides. The default is to pass nothing and inherit the harness configuration.
58
81
  - `policy`: `allowSelfHandoff` (default `true`), `allowSpawnChildren` (default `false`), `allowSelfStop` (default `true`).
59
82
  - `isolation`: `inherit` | `isolated`; `inherit` is the default.
60
83
  - `count`: 1..16 for `spawn`; the adapter declares the effective concurrency limit and over-limit requests fail loudly.
61
- - `requiredFeatures`: optional mandatory feature names: `handoff`, `spawn`, `status`, `message`, `cancel`, `stop`, `list`, `surface-preserve`, `surface-cross`, `spawn-isolation`, `spawn-policy`, `model-override`, `reasoning-effort-override`, `tmux-fallback`.
84
+ - `requiredFeatures`: optional mandatory feature names: `handoff`, `spawn`, `status`, `message`, `cancel`, `stop`, `list`, `surface-preserve`, `surface-cross`, `spawn-isolation`, `spawn-policy`, `model-override`, `reasoning-effort-override`.
62
85
 
63
86
  ## Result fields
64
87
 
@@ -81,7 +104,7 @@ A pending handoff cancelled before application returns `cancelled`. For `cancel`
81
104
  - `unavailable`: names of fields the adapter could not obtain; their values are `null`. Missing values are never omitted or replaced with 0/empty placeholders.
82
105
  - `notices`: `{ code, impact: "none", action_required: false, message }`. **Skills must treat notices as informational: never stop, retry or prompt because of one.**
83
106
  - `error`: `{ code, message }` for refusals and failures.
84
- - `proof` (handoff completion): source/successor identities, mechanism and native evidence.
107
+ - `proof` (any result that claims a context replacement, including `applied`): source/successor identities, mechanism and native evidence. For a current mechanism the successor `session` must equal the source `session`; a mismatch is rejected as `invalid-result`, never accepted as a handoff.
85
108
  - `capabilities`, `executors` for the corresponding operations.
86
109
 
87
110
  ## Status resolution: the per-field source ladder
@@ -196,8 +219,7 @@ A `supported` spawn must declare `lifecycle: "detached"`; a tested failure is re
196
219
  "spawn-isolation",
197
220
  "spawn-policy",
198
221
  "model-override",
199
- "reasoning-effort-override",
200
- "tmux-fallback"
222
+ "reasoning-effort-override"
201
223
  ]
202
224
  },
203
225
  "description": "Feature names this caller requires; the request fails when the harness does not declare them."
@@ -1273,8 +1295,9 @@ A `supported` spawn must declare `lifecycle: "detached"`; a tested failure is re
1273
1295
  },
1274
1296
  "mechanism": {
1275
1297
  "enum": [
1276
- "new-session",
1277
- "surface-replacement"
1298
+ "surface-replacement",
1299
+ "native-compaction",
1300
+ "new-session"
1278
1301
  ]
1279
1302
  },
1280
1303
  "nativeEvidence": {
@@ -1374,12 +1397,6 @@ A `supported` spawn must declare `lifecycle: "detached"`; a tested failure is re
1374
1397
  "unsupported",
1375
1398
  "not-tested"
1376
1399
  ]
1377
- },
1378
- "tmuxFallback": {
1379
- "enum": [
1380
- "off",
1381
- "experimental"
1382
- ]
1383
1400
  }
1384
1401
  },
1385
1402
  "required": [
@@ -1387,8 +1404,7 @@ A `supported` spawn must declare `lifecycle: "detached"`; a tested failure is re
1387
1404
  "modes",
1388
1405
  "modelOverride",
1389
1406
  "reasoningEffortOverride",
1390
- "crossSurface",
1391
- "tmuxFallback"
1407
+ "crossSurface"
1392
1408
  ]
1393
1409
  },
1394
1410
  "spawn": {
@@ -1,6 +1,6 @@
1
1
  import type { AdapterContext, CarrierCommand, StatusDetails } from '../external.js';
2
2
  import { ExternalExecutorAdapter } from '../external.js';
3
- import type { CapabilityDeclaration } from '../../contract/types.js';
3
+ import type { CapabilityDeclaration, Request } from '../../contract/types.js';
4
4
  import type { HarnessId, Os } from '../../contract/states.js';
5
5
  import type { ExecutorRecord } from '../../core/store.js';
6
6
  import type { LogLine, ExecutorStatus } from '../executors.js';
@@ -15,6 +15,15 @@ export declare function claudePluginDir(home: string): string | undefined;
15
15
  export declare class ClaudeAdapter extends ExternalExecutorAdapter {
16
16
  readonly harness: HarnessId;
17
17
  capabilities(os: Os): CapabilityDeclaration[];
18
+ /**
19
+ * Persist the model a resumed turn must keep. The carrier passes `--model`
20
+ * only when the request has one, so the effective value can come from the
21
+ * settings `env` block (which overrides the inherited process environment)
22
+ * or the process environment.
23
+ */
24
+ protected persistedModel(request: Request, ctx: AdapterContext): Promise<string | undefined>;
25
+ /** `CLAUDE_CODE_EFFORT_LEVEL` overrides the settings `effortLevel`. */
26
+ protected persistedReasoningEffort(request: Request, ctx: AdapterContext): Promise<string | undefined>;
18
27
  protected carrier(request: Parameters<ExternalExecutorAdapter['spawn']>[0], ctx: AdapterContext, _executorId: string, resumeSessionId?: string): Promise<CarrierCommand>;
19
28
  protected statusDetails(_record: ExecutorRecord, status: ExecutorStatus, log: LogLine[], ctx: AdapterContext): Promise<StatusDetails>;
20
29
  }
@@ -4,6 +4,7 @@ import { randomUUID } from 'node:crypto';
4
4
  import { ExternalExecutorAdapter, lastJson } from '../external.js';
5
5
  import { resolveClaudeStatus } from './status.js';
6
6
  import { verifiedText, verifiedTokens, verifiedWindow } from '../../core/ladder.js';
7
+ import { envValue, probeClaudeSettings } from '../../core/config-probe.js';
7
8
  import { declaration } from '../declarations.js';
8
9
  /**
9
10
  * Claude Code adapter.
@@ -31,24 +32,48 @@ export function claudePluginDir(home) {
31
32
  export class ClaudeAdapter extends ExternalExecutorAdapter {
32
33
  harness = 'claude-code';
33
34
  capabilities(os) {
34
- const verified = os === 'linux' || os === 'darwin';
35
- const reason = os === 'linux'
36
- ? 'The mods plugin loads and both native handoff modes completed in place: restart via the built-in /clear (new session, same process) and compact via the native safe point; detached carriers spawn, report status and survive the parent. Exercised on Linux.'
37
- : os === 'darwin'
38
- ? 'The mods plugin loads and the native in-place handoff completed on macOS; detached carriers spawn and report status with model and context. Exercised on macOS.'
35
+ const linux = os === 'linux';
36
+ const mac = os === 'darwin';
37
+ // macOS proves both the handoff and the detached carrier in this release.
38
+ const reason = linux
39
+ ? 'The mods plugin loads and the zero-summary restart replaces the context in place through the native compact hook while keeping the session id; a disabled-compaction session is reported unsupported. Detached carriers spawn, report status and survive the parent. Exercised on Linux.'
40
+ : mac
41
+ ? 'The mods plugin loads and the zero-summary in-place restart completed on macOS with the session id preserved (handoff verified). The detached carrier was exercised on macOS with a real two-turn executor: spawn, status, message queued into the same session (both turn markers in the executor log), stop, and the error paths (unauthorized target, message to a completed executor) all completed.'
39
42
  : 'The mods plugin and the detached carrier are implemented; native Windows is out of scope (WSL counts as Linux) and was not exercised.';
40
- const level = verified ? 'supported' : 'not-tested';
43
+ const carrier = linux || mac ? 'supported' : 'not-tested';
41
44
  const common = {
42
- handoff: { availability: level, modes: ['compact', 'restart'], tmuxFallback: 'off' },
43
- spawn: { availability: level, maxConcurrent: 4 },
44
- status: { availability: level, model: level, reasoningEffort: 'unsupported', context: level, percentSource: 'derived' },
45
- ...(verified ? { evidence: `matrix:claude-code/${os}/2026-11-18` } : {}),
45
+ handoff: { availability: linux || mac ? 'supported' : 'not-tested', modes: ['restart'] },
46
+ spawn: { availability: carrier, maxConcurrent: 4 },
47
+ status: { availability: carrier, model: carrier, reasoningEffort: 'unsupported', context: carrier, percentSource: 'derived' },
48
+ ...(linux || mac ? { evidence: `matrix:claude-code/${os}/2026-11-21` } : {}),
46
49
  };
47
50
  return [
48
51
  declaration({ harness: 'claude-code', os, interface: 'tui', reason, ...common }),
49
52
  declaration({ harness: 'claude-code', os, interface: 'headless', reason, ...common }),
50
53
  ];
51
54
  }
55
+ /**
56
+ * Persist the model a resumed turn must keep. The carrier passes `--model`
57
+ * only when the request has one, so the effective value can come from the
58
+ * settings `env` block (which overrides the inherited process environment)
59
+ * or the process environment.
60
+ */
61
+ async persistedModel(request, ctx) {
62
+ if (request.model)
63
+ return request.model;
64
+ const settings = await probeClaudeSettings(ctx.identity.workspace, undefined, ['ANTHROPIC_MODEL']).catch(() => null);
65
+ return settings?.env[0]?.value ?? envValue('ANTHROPIC_MODEL') ?? undefined;
66
+ }
67
+ /** `CLAUDE_CODE_EFFORT_LEVEL` overrides the settings `effortLevel`. */
68
+ async persistedReasoningEffort(request, ctx) {
69
+ if (request.reasoningEffort)
70
+ return request.reasoningEffort;
71
+ const env = envValue('CLAUDE_CODE_EFFORT_LEVEL');
72
+ if (env)
73
+ return env;
74
+ const settings = await probeClaudeSettings(ctx.identity.workspace, undefined, []).catch(() => null);
75
+ return settings?.effortLevel?.value ?? undefined;
76
+ }
52
77
  async carrier(request, ctx, _executorId, resumeSessionId) {
53
78
  // A detached executor has no one to answer permission prompts: run it in the
54
79
  // harness's non-interactive bypass mode, consistent with the spawn contract.
@@ -1,4 +1,5 @@
1
1
  import type { Identity, Request, Result } from '../../contract/types.js';
2
+ import type { StoredProofMechanism } from '../../contract/states.js';
2
3
  export type ClaudePhase = 'pending' | 'scheduled' | 'applied' | 'completed' | 'cancelled' | 'failed' | 'unknown';
3
4
  export interface ClaudeRecord {
4
5
  format: 2;
@@ -11,6 +12,12 @@ export interface ClaudeRecord {
11
12
  reason: string;
12
13
  /** Native context replacement strategy recorded for this handoff. */
13
14
  mechanism?: 'restart' | 'compact';
15
+ /**
16
+ * Explicit proof mechanism. New records always set it. Records written
17
+ * before 0.0.5 lack it; their proof is derived from `mechanism` under the
18
+ * historical rules and is exempt from the same-session gate.
19
+ */
20
+ proofMechanism?: StoredProofMechanism;
14
21
  successor?: Identity;
15
22
  }
16
23
  export interface ClaudeCommand {
@@ -25,6 +32,7 @@ export interface ClaudeCommand {
25
32
  /** Native successor identity after a restart (new session id) or compact generation. */
26
33
  successor?: Identity;
27
34
  mechanism?: 'restart' | 'compact';
35
+ proofMechanism?: StoredProofMechanism;
28
36
  usage?: {
29
37
  window?: number | null;
30
38
  used?: number | null;
@@ -3,6 +3,7 @@ import path from 'node:path';
3
3
  import { atomicJson, bytes, contained, digest, ownership, withScopeLock } from '../../install/scope.js';
4
4
  import { result } from '../../contract/validate.js';
5
5
  import { handoffOutcome } from '../../contract/states.js';
6
+ import { legacyProofMechanism } from '../../core/handoff.js';
6
7
  const PHASES = ['pending', 'scheduled', 'applied', 'completed', 'cancelled', 'failed', 'unknown'];
7
8
  const sessionKey = (identity) => `${identity.workspace}\0${identity.surface}\0${identity.session}`;
8
9
  function response(record, operation = 'handoff') {
@@ -16,7 +17,9 @@ function response(record, operation = 'handoff') {
16
17
  ? {
17
18
  proof: {
18
19
  source: record.source, successor: record.successor,
19
- mechanism: (record.mechanism === 'restart' ? 'new-session' : 'surface-replacement'),
20
+ // New records carry the explicit field; old records keep the
21
+ // mechanism they historically implied and stay legacy-exempt.
22
+ mechanism: record.proofMechanism ?? legacyProofMechanism(record.mechanism),
20
23
  nativeEvidence: record.marker,
21
24
  },
22
25
  }