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
@@ -12,7 +12,7 @@ import { handoffMode, handoffOutcome } from '../../contract/states.js';
12
12
  import { fingerprint } from '../../core/fingerprint.js';
13
13
  import { activeRecord } from '../../core/journal.js';
14
14
  import { Ai4aiStore } from '../../core/store.js';
15
- import { execute } from '../../core/operations.js';
15
+ import { currentOs, execute } from '../../core/operations.js';
16
16
  import { ClaudeJournal, response } from './journal.js';
17
17
  import { ClaudeAdapter } from './adapter.js';
18
18
  import { resolveClaudeStatus } from './status.js';
@@ -99,12 +99,19 @@ if (command.action === 'transition') {
99
99
  const to = command.phase ?? 'unknown';
100
100
  if (!allowed[to]?.includes(latest.phase))
101
101
  throw new Error(`Unexpected transition ${latest.phase} -> ${to}; no replay`);
102
+ const successor = command.successor ?? { ...latest.source, generation: latest.marker };
103
+ // A handoff never changes the native session identity; the plugin asserts
104
+ // this too, and the journal refuses a mismatched record rather than storing
105
+ // a false success.
106
+ if (successor.session !== latest.source.session)
107
+ throw new Error('Handoff successor changed the native session id; no transition recorded');
102
108
  const next = {
103
109
  ...latest, phase: to, reason: command.reason ?? to,
104
110
  ...(to === 'applied'
105
111
  ? {
106
- successor: command.successor ?? { ...latest.source, generation: latest.marker },
107
- mechanism: command.mechanism ?? latest.mechanism ?? 'compact',
112
+ successor,
113
+ mechanism: command.mechanism ?? latest.mechanism ?? 'restart',
114
+ proofMechanism: command.proofMechanism ?? latest.proofMechanism ?? 'surface-replacement',
108
115
  }
109
116
  : {}),
110
117
  };
@@ -131,9 +138,12 @@ if (request.operation === 'status' && (request.target === undefined || request.t
131
138
  });
132
139
  const pointer = await sessionPointer('claude-code', caller.workspace, caller.session).catch(() => null);
133
140
  const activity = await sessionActivity(pointer?.path ?? null);
141
+ const compactionDisabled = !!process.env.DISABLE_COMPACT && process.env.DISABLE_COMPACT !== '0';
134
142
  console.log(JSON.stringify({
135
143
  result: result(request, 'completed', 'Native session status', {
136
144
  durable: true,
145
+ // A session-level limit, reported honestly without blocking status.
146
+ ...(compactionDisabled ? { notices: [{ code: 'claude-compaction-disabled', impact: 'none', action_required: false, message: 'Compaction is switched off in this session (DISABLE_COMPACT); the in-place restart handoff is unsupported here.' }] } : {}),
137
147
  // The session is alive while it serves this call; handoff progress is
138
148
  // reported separately, and quiescence is inferred from lastActivityAt.
139
149
  state: 'running',
@@ -155,7 +165,7 @@ if (request.operation === 'status' && (request.target === undefined || request.t
155
165
  process.exit(0);
156
166
  }
157
167
  if (request.operation === 'capabilities') {
158
- console.log(JSON.stringify({ result: result(request, 'completed', 'Claude adapter capabilities are declared by the installed plugin', { durable: false }) }));
168
+ console.log(JSON.stringify({ result: result(request, 'completed', 'Claude adapter capabilities are declared by the installed plugin', { durable: false, capabilities: new ClaudeAdapter().capabilities(currentOs()) }) }));
159
169
  process.exit(0);
160
170
  }
161
171
  if (request.operation === 'cancel' || request.operation === 'stop') {
@@ -183,8 +193,21 @@ if (request.operation === 'handoff' && request.target === 'self') {
183
193
  console.log(JSON.stringify({ result: result(request, 'failed', 'Another handoff is unresolved; reconcile it before requesting a transition') }));
184
194
  process.exit(0);
185
195
  }
196
+ // Compaction can be switched off per session; the restart path needs it, so
197
+ // report the limitation up front instead of failing midway.
198
+ if (process.env.DISABLE_COMPACT && process.env.DISABLE_COMPACT !== '0') {
199
+ console.log(JSON.stringify({ result: result(request, 'unsupported', 'Compaction is switched off in this session (DISABLE_COMPACT); the in-place restart handoff needs it', { unavailable: ['handoff.restart'], error: { code: 'claude-compaction-disabled', message: 'DISABLE_COMPACT is set for this session' } }) }));
200
+ process.exit(0);
201
+ }
202
+ // This version declares restart only. `compact` means a native summary,
203
+ // which Claude does not implement here; refuse it instead of silently
204
+ // running the zero-summary replacement under a compact label.
205
+ if (request.mode === 'compact') {
206
+ console.log(JSON.stringify({ result: result(request, 'unsupported', 'Claude Code handoff implements restart only in this version; native compaction plus task delivery is not available', { unavailable: ['handoff.compact'] }) }));
207
+ process.exit(0);
208
+ }
186
209
  const mechanism = handoffMode(request.mode);
187
- if (mechanism === 'restart' && !request.task) {
210
+ if (!request.task) {
188
211
  console.log(JSON.stringify({ result: result(request, 'unsupported', 'A restart handoff needs task material: the new context contains only that material', { unavailable: ['handoff.task'] }) }));
189
212
  process.exit(0);
190
213
  }
@@ -192,9 +215,8 @@ if (request.operation === 'handoff' && request.target === 'self') {
192
215
  const record = {
193
216
  format: 2, operationId: request.operationId, fingerprint: fingerprint(request), request, source: caller, marker, phase: 'pending',
194
217
  mechanism,
195
- reason: mechanism === 'restart'
196
- ? 'Finish this turn; the native /clear reset replaces this context with the caller task material'
197
- : 'Finish this turn; the native safe point will replace the context with the caller task material',
218
+ proofMechanism: 'surface-replacement',
219
+ reason: 'Finish this turn; the native compact hook replaces this context in place with the caller task material (no summary model is called)',
198
220
  };
199
221
  await journal.transaction(caller, async (_rows, commit) => commit(record));
200
222
  console.log(JSON.stringify({ result: response(record), record }));
@@ -1,41 +1,48 @@
1
1
  import type { AdapterContext, CarrierCommand, StatusDetails, NativeOutcome } from '../external.js';
2
2
  import { ExternalExecutorAdapter } from '../external.js';
3
- import type { CapabilityDeclaration } from '../../contract/types.js';
4
- import type { Request } from '../../contract/types.js';
3
+ import type { CapabilityDeclaration, Request } from '../../contract/types.js';
5
4
  import type { HarnessId, Os } from '../../contract/states.js';
6
5
  import type { ExecutorRecord } from '../../core/store.js';
7
6
  import { type LogLine, type ExecutorStatus } from '../executors.js';
8
7
  export declare class CodexAdapter extends ExternalExecutorAdapter {
9
8
  readonly harness: HarnessId;
10
9
  capabilities(os: Os): CapabilityDeclaration[];
10
+ /**
11
+ * A detached Codex executor inherits the profile model and reasoning effort:
12
+ * the runner starts a thread without per-request overrides. Refuse them
13
+ * loudly instead of accepting values that would never reach the harness.
14
+ */
15
+ spawn(request: Request, ctx: AdapterContext): Promise<NativeOutcome>;
11
16
  protected carrier(request: Parameters<ExternalExecutorAdapter['spawn']>[0], ctx: AdapterContext, _executorId: string, resumeSessionId?: string): Promise<CarrierCommand>;
12
17
  /**
13
18
  * Same-window handoff through the local app-server daemon.
14
19
  *
15
- * The daemon owns the TUI's live thread. Compacting it and starting the
16
- * successor turn through the daemon changes what the user sees in the same
17
- * window: a compaction marker followed by the handoff task as the next turn.
18
- * When no daemon or live thread is reachable, the experimental tmux fallback
19
- * is attempted once.
20
+ * The daemon owns the TUI's live thread. Reverting it and starting the
21
+ * material turn through the daemon changes what the user sees in the same
22
+ * window: a reset history followed by the handoff task as the next turn.
23
+ * When no daemon or live thread is reachable, the call fails as the
24
+ * structured `codex-no-daemon` host boundary; no new thread is created.
20
25
  */
21
26
  handoff(request: Request, ctx: AdapterContext): Promise<NativeOutcome>;
22
27
  /**
23
- * Native TUI restart. The visible terminal is the only surface the user
24
- * sees, so ai4ai drives that terminal's own `/new` command (a documented
25
- * harness action) and then delivers the material as the next turn. The
26
- * source turn is still running when this call is made, so a detached watcher
27
- * applies the reset at the turn boundary. The process, pane and host channel
28
- * are never replaced.
28
+ * Re-query a pending handoff written by the headless runner or the detached
29
+ * TUI watcher. Without this, the same operationId would return the original
30
+ * pending result forever even after the native side completed.
31
+ */
32
+ reconcileHandoff(request: Request, ctx: AdapterContext): Promise<NativeOutcome | undefined>;
33
+ /**
34
+ * Native TUI restart. The TUI's shared app-server daemon owns the live
35
+ * thread; a detached watcher waits for the safe point, archives best-effort,
36
+ * reverts the thread to its start and starts the material turn in the same
37
+ * thread. No tmux, no `/new`, no new thread.
29
38
  */
30
39
  private tuiRestart;
31
40
  /**
32
- * tmux-independent TUI restart. A bare terminal TUI still speaks to its
33
- * local app-server daemon. ai4ai asks the model to call the core
34
- * `new_context` tool (an in-thread reset without a summary) and a detached
35
- * watcher starts the material turn once the reset is observed. Same thread,
36
- * same process, no tmux and no process replacement.
41
+ * Explicit compact opt-in for the TUI: the harness's native compaction runs
42
+ * (and may spend summary tokens), then the material is the next turn in the
43
+ * same thread. Proof uses the native thread id for both source and successor.
37
44
  */
38
- private daemonRestart;
45
+ private tuiCompact;
39
46
  protected statusDetails(record: ExecutorRecord, status: ExecutorStatus, _log: LogLine[], ctx: AdapterContext): Promise<StatusDetails>;
40
47
  }
41
48
  export declare const codexAdapter: CodexAdapter;