@astrosheep/keiyaku 4.0.3 → 4.0.5

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 (238) hide show
  1. package/build/integrations/marketplace/plugins/keiyaku/.claude-plugin/plugin.json +1 -1
  2. package/build/integrations/marketplace/plugins/keiyaku/.codex-plugin/plugin.json +1 -1
  3. package/build/integrations/marketplace/plugins/keiyaku/package.json +1 -1
  4. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku/SKILL.md +4 -4
  5. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-akuma/SKILL.md +1 -1
  6. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-bind/SKILL.md +15 -1
  7. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-task/SKILL.md +3 -1
  8. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-workflow/SKILL.md +34 -13
  9. package/build/src/akuma/akuma.d.ts +34 -12
  10. package/build/src/akuma/akuma.js +118 -63
  11. package/build/src/akuma/allowed.d.ts +7 -0
  12. package/build/src/akuma/allowed.js +33 -0
  13. package/build/src/akuma/archetype.d.ts +7 -4
  14. package/build/src/akuma/archetype.js +15 -16
  15. package/build/src/akuma/body.d.ts +6 -1
  16. package/build/src/akuma/body.js +36 -27
  17. package/build/src/akuma/heart/facts.d.ts +82 -14
  18. package/build/src/akuma/heart/index.d.ts +5 -18
  19. package/build/src/akuma/heart/index.js +14 -84
  20. package/build/src/akuma/heart/request-authority.d.ts +12 -0
  21. package/build/src/akuma/heart/request-authority.js +119 -0
  22. package/build/src/akuma/heart/request-rows.d.ts +16 -0
  23. package/build/src/akuma/heart/request-rows.js +88 -0
  24. package/build/src/akuma/heart/rows.d.ts +1 -26
  25. package/build/src/akuma/heart/rows.js +0 -50
  26. package/build/src/akuma/heart/schema.d.ts +1 -1
  27. package/build/src/akuma/heart/schema.js +22 -10
  28. package/build/src/akuma/heart/soul.js +2 -36
  29. package/build/src/akuma/heart/storage.d.ts +1 -0
  30. package/build/src/akuma/heart/storage.js +15 -0
  31. package/build/src/akuma/heart/timeline.d.ts +1 -5
  32. package/build/src/akuma/heart/timeline.js +8 -17
  33. package/build/src/akuma/index.d.ts +5 -2
  34. package/build/src/akuma/index.js +1 -0
  35. package/build/src/akuma/projection.d.ts +17 -3
  36. package/build/src/akuma/projection.js +40 -3
  37. package/build/src/akuma/provider-recipe.js +1 -11
  38. package/build/src/akuma/provider.d.ts +2 -7
  39. package/build/src/akuma/provider.js +2 -1
  40. package/build/src/akuma/providers/acp/core.d.ts +3 -1
  41. package/build/src/akuma/providers/acp/core.js +10 -6
  42. package/build/src/akuma/providers/acp/events.d.ts +11 -3
  43. package/build/src/akuma/providers/acp/events.js +78 -4
  44. package/build/src/akuma/providers/acp/index.js +0 -1
  45. package/build/src/akuma/providers/claude/events.js +62 -3
  46. package/build/src/akuma/providers/claude/index.d.ts +0 -4
  47. package/build/src/akuma/providers/claude/index.js +7 -3
  48. package/build/src/akuma/providers/codex-app-server/events.js +1 -13
  49. package/build/src/akuma/providers/codex-app-server/index.d.ts +2 -27
  50. package/build/src/akuma/providers/codex-app-server/index.js +0 -2
  51. package/build/src/akuma/providers/grok-build/index.d.ts +2 -1
  52. package/build/src/akuma/providers/grok-build/index.js +72 -3
  53. package/build/src/akuma/providers/opencode-sdk/events.js +71 -6
  54. package/build/src/akuma/providers/opencode-sdk/index.d.ts +2 -28
  55. package/build/src/akuma/providers/opencode-sdk/index.js +8 -4
  56. package/build/src/akuma/providers/opencode-sdk/session.d.ts +1 -1
  57. package/build/src/akuma/providers/opencode-sdk/session.js +1 -1
  58. package/build/src/akuma/providers/pi/events.js +17 -3
  59. package/build/src/akuma/providers/pi/index.js +11 -4
  60. package/build/src/akuma/providers/unified-patch.d.ts +4 -0
  61. package/build/src/akuma/providers/unified-patch.js +14 -0
  62. package/build/src/akuma/publication.d.ts +1 -1
  63. package/build/src/akuma/publication.js +1 -1
  64. package/build/src/akuma/request-serve.d.ts +87 -0
  65. package/build/src/akuma/request-serve.js +484 -0
  66. package/build/src/akuma/request-wire.d.ts +124 -0
  67. package/build/src/akuma/request-wire.js +380 -0
  68. package/build/src/akuma/requests.d.ts +41 -41
  69. package/build/src/akuma/requests.js +75 -374
  70. package/build/src/akuma-body.d.ts +8 -0
  71. package/build/src/akuma-body.js +84 -0
  72. package/build/src/body/arc.js +4 -29
  73. package/build/src/body/decode.js +5 -39
  74. package/build/src/body/envelope.d.ts +7 -0
  75. package/build/src/body/envelope.js +37 -0
  76. package/build/src/cli/accepted.d.ts +4 -1
  77. package/build/src/cli/accepted.js +39 -9
  78. package/build/src/cli/commands/akuma-invoke.d.ts +8 -7
  79. package/build/src/cli/commands/akuma-invoke.js +18 -10
  80. package/build/src/cli/commands/akuma.d.ts +11 -2
  81. package/build/src/cli/commands/akuma.js +67 -28
  82. package/build/src/cli/commands/amend.d.ts +1 -1
  83. package/build/src/cli/commands/amend.js +1 -1
  84. package/build/src/cli/commands/contract.d.ts +8 -8
  85. package/build/src/cli/commands/contract.js +3 -3
  86. package/build/src/cli/commands/install.js +2 -2
  87. package/build/src/cli/commands/task-invoke.js +98 -9
  88. package/build/src/cli/commands/task-query.d.ts +1 -1
  89. package/build/src/cli/commands/task-query.js +11 -5
  90. package/build/src/cli/coordinates.d.ts +2 -0
  91. package/build/src/cli/coordinates.js +12 -5
  92. package/build/src/cli/invoke.d.ts +1 -0
  93. package/build/src/cli/invoke.js +116 -75
  94. package/build/src/cli/main.d.ts +2 -0
  95. package/build/src/cli/main.js +29 -4
  96. package/build/src/cli/parse.d.ts +3 -2
  97. package/build/src/cli/parse.js +25 -8
  98. package/build/src/cli/render/akuma.d.ts +2 -2
  99. package/build/src/cli/render/akuma.js +138 -24
  100. package/build/src/cli/render/audit.js +18 -8
  101. package/build/src/cli/render/contract.d.ts +2 -0
  102. package/build/src/cli/render/contract.js +243 -36
  103. package/build/src/cli/render/kanshi.js +64 -29
  104. package/build/src/cli/render/receipt.d.ts +2 -1
  105. package/build/src/cli/render/receipt.js +37 -2
  106. package/build/src/cli/render/terminal.d.ts +0 -2
  107. package/build/src/cli/render/terminal.js +0 -29
  108. package/build/src/cli/render/text.js +3 -1
  109. package/build/src/cli/result.d.ts +52 -9
  110. package/build/src/cli/selectors.d.ts +1 -0
  111. package/build/src/cli/selectors.js +9 -6
  112. package/build/src/contract-worktree.d.ts +1 -2
  113. package/build/src/contract-worktree.js +7 -9
  114. package/build/src/core/facts/codec.js +9 -0
  115. package/build/src/core/facts/fold.js +13 -1
  116. package/build/src/core/facts/types.d.ts +8 -1
  117. package/build/src/core/subject.js +4 -3
  118. package/build/src/core/verbs/placement.d.ts +9 -1
  119. package/build/src/core/verbs/placement.js +24 -6
  120. package/build/src/core/verbs/reintegrate.d.ts +13 -0
  121. package/build/src/core/verbs/reintegrate.js +24 -0
  122. package/build/src/dispatch/index.d.ts +1 -1
  123. package/build/src/dispatch/index.js +50 -39
  124. package/build/src/git/admission.d.ts +2 -1
  125. package/build/src/git/hooks.d.ts +0 -4
  126. package/build/src/git/hooks.js +0 -36
  127. package/build/src/git/integration.d.ts +7 -8
  128. package/build/src/git/integration.js +62 -9
  129. package/build/src/git/observe.d.ts +2 -1
  130. package/build/src/git/observe.js +6 -5
  131. package/build/src/git/process.d.ts +26 -0
  132. package/build/src/git/process.js +94 -0
  133. package/build/src/git/read-observation.d.ts +2 -1
  134. package/build/src/git/read-observation.js +3 -2
  135. package/build/src/git/reconcile.d.ts +8 -2
  136. package/build/src/git/reconcile.js +63 -14
  137. package/build/src/git/repository.d.ts +2 -29
  138. package/build/src/git/repository.js +4 -118
  139. package/build/src/git/scratch.d.ts +1 -1
  140. package/build/src/git/scratch.js +1 -1
  141. package/build/src/git/target-placement.d.ts +1 -1
  142. package/build/src/git/target-placement.js +9 -7
  143. package/build/src/git/tender.d.ts +20 -5
  144. package/build/src/git/tender.js +45 -13
  145. package/build/src/git/terminal-seal.d.ts +16 -2
  146. package/build/src/git/terminal-seal.js +15 -5
  147. package/build/src/git/workspace.d.ts +2 -1
  148. package/build/src/git/workspace.js +13 -5
  149. package/build/src/index.d.ts +1 -2
  150. package/build/src/index.js +1 -1
  151. package/build/src/kanshi/index.d.ts +1 -1
  152. package/build/src/kanshi/index.js +1 -1
  153. package/build/src/kanshi/read.d.ts +9 -1
  154. package/build/src/kanshi/read.js +91 -37
  155. package/build/src/kanshi/report.d.ts +1 -0
  156. package/build/src/library/address.d.ts +5 -14
  157. package/build/src/library/address.js +27 -23
  158. package/build/src/library/akuma-creation.d.ts +4 -2
  159. package/build/src/library/akuma-creation.js +43 -26
  160. package/build/src/library/audit.d.ts +2 -1
  161. package/build/src/library/audit.js +1 -1
  162. package/build/src/library/bind.d.ts +2 -1
  163. package/build/src/library/bind.js +4 -4
  164. package/build/src/library/catalog.d.ts +1 -2
  165. package/build/src/library/catalog.js +11 -6
  166. package/build/src/library/configuration.d.ts +5 -1
  167. package/build/src/library/configuration.js +71 -18
  168. package/build/src/library/contract.d.ts +70 -3
  169. package/build/src/library/contract.js +213 -27
  170. package/build/src/library/delivery.d.ts +1 -1
  171. package/build/src/library/fleet.d.ts +70 -12
  172. package/build/src/library/fleet.js +236 -56
  173. package/build/src/library/input.d.ts +0 -1
  174. package/build/src/library/input.js +1 -5
  175. package/build/src/library/keiyaku.d.ts +4 -4
  176. package/build/src/library/keiyaku.js +1 -2
  177. package/build/src/library/mutation.d.ts +2 -1
  178. package/build/src/library/reconcile.d.ts +2 -1
  179. package/build/src/library/reconcile.js +3 -1
  180. package/build/src/library/region.d.ts +1 -1
  181. package/build/src/library/repo.d.ts +3 -1
  182. package/build/src/library/repo.js +8 -4
  183. package/build/src/protocol/abandon.d.ts +9 -0
  184. package/build/src/protocol/abandon.js +15 -0
  185. package/build/src/protocol/amend.d.ts +16 -0
  186. package/build/src/protocol/amend.js +77 -0
  187. package/build/src/protocol/arc.d.ts +6 -0
  188. package/build/src/protocol/arc.js +12 -0
  189. package/build/src/protocol/attempt.d.ts +2 -1
  190. package/build/src/protocol/audit.d.ts +53 -0
  191. package/build/src/protocol/audit.js +140 -0
  192. package/build/src/protocol/bind.d.ts +2 -3
  193. package/build/src/protocol/bind.js +2 -16
  194. package/build/src/protocol/completion.d.ts +32 -0
  195. package/build/src/protocol/completion.js +130 -0
  196. package/build/src/protocol/deliver.d.ts +37 -0
  197. package/build/src/protocol/deliver.js +160 -0
  198. package/build/src/protocol/intent.d.ts +1 -1
  199. package/build/src/protocol/intent.js +1 -1
  200. package/build/src/protocol/operations.d.ts +65 -198
  201. package/build/src/protocol/operations.js +21 -634
  202. package/build/src/protocol/placement.d.ts +4 -13
  203. package/build/src/protocol/placement.js +3 -15
  204. package/build/src/protocol/read/status.d.ts +4 -2
  205. package/build/src/protocol/read/status.js +27 -15
  206. package/build/src/protocol/reconcile.d.ts +35 -0
  207. package/build/src/protocol/reconcile.js +41 -0
  208. package/build/src/protocol/reintegrate.d.ts +31 -0
  209. package/build/src/protocol/reintegrate.js +74 -0
  210. package/build/src/protocol/review.d.ts +33 -0
  211. package/build/src/protocol/review.js +148 -0
  212. package/build/src/protocol/run.d.ts +1 -1
  213. package/build/src/runtime/proc/run.d.ts +1 -0
  214. package/build/src/runtime/proc/run.js +9 -2
  215. package/build/src/settlement/fence.d.ts +1 -1
  216. package/build/src/settlement/holder.d.ts +1 -1
  217. package/build/src/settlement/settle.d.ts +2 -1
  218. package/build/src/settlement/settle.js +4 -1
  219. package/build/src/task/board.d.ts +18 -4
  220. package/build/src/task/board.js +73 -29
  221. package/build/src/task/compose.d.ts +1 -1
  222. package/build/src/task/compose.js +11 -4
  223. package/build/src/task/index.d.ts +4 -4
  224. package/build/src/task/index.js +8 -131
  225. package/build/src/task/input.d.ts +18 -0
  226. package/build/src/task/input.js +189 -0
  227. package/build/src/task/mutation.d.ts +39 -0
  228. package/build/src/task/mutation.js +85 -0
  229. package/build/src/task/operations.d.ts +4 -19
  230. package/build/src/task/operations.js +64 -18
  231. package/build/src/task/query.d.ts +9 -2
  232. package/build/src/task/query.js +32 -64
  233. package/build/src/task/store.js +0 -2
  234. package/build/src/verification/execution.d.ts +1 -1
  235. package/build/src/verification/execution.js +2 -1
  236. package/build/src/workspace-place.d.ts +1 -4
  237. package/build/src/workspace-place.js +0 -15
  238. package/package.json +5 -3
@@ -114,21 +114,35 @@ export type ActivitySnapshotEntry<Row extends SnapshotRow = SnapshotRow> = Reado
114
114
  kind: "gap";
115
115
  count: number;
116
116
  }>;
117
+ export type ReportedFileChange = Readonly<{
118
+ sequence: number;
119
+ at: string;
120
+ op: "add" | "update" | "delete" | "unspecified";
121
+ path: string;
122
+ diffstat?: Readonly<{
123
+ added: number;
124
+ removed: number;
125
+ }>;
126
+ }>;
127
+ type ReportedChangeSummary = Readonly<{
128
+ reportedChanges: readonly ReportedFileChange[];
129
+ reportedChangesOmitted: number;
130
+ }>;
117
131
  export type Snapshot = Readonly<{
118
132
  kind: "unborn";
119
133
  entries: readonly [];
120
134
  omitted: 0;
121
- }> | Readonly<{
135
+ } & ReportedChangeSummary> | Readonly<{
122
136
  kind: "open";
123
137
  turn: TurnStartRow;
124
138
  entries: readonly ActivitySnapshotEntry<OpenSnapshotRow>[];
125
139
  omitted: number;
126
- }> | Readonly<{
140
+ } & ReportedChangeSummary> | Readonly<{
127
141
  kind: "idle";
128
142
  outcome?: OutcomeRow;
129
143
  entries: readonly ActivitySnapshotEntry<IdleSnapshotRow>[];
130
144
  omitted: number;
131
- }>;
145
+ } & ReportedChangeSummary>;
132
146
  export type ActivitySnapshot = Snapshot;
133
147
  export type ActivityHistory = Readonly<{
134
148
  rows: readonly ActivityRow[];
@@ -1,6 +1,8 @@
1
1
  import { decodeAgentEvent } from "./provider.js";
2
2
  const DEFAULT_TAIL = 3;
3
3
  const DEFAULT_VOICE = 3;
4
+ const REPORTED_CHANGE_LIMIT = 5;
5
+ const EMPTY_REPORTED = { reportedChanges: [], reportedChangesOmitted: 0 };
4
6
  function duration(startedAt, completedAt) {
5
7
  const start = Date.parse(startedAt);
6
8
  const end = Date.parse(completedAt);
@@ -204,11 +206,45 @@ export function ordinarySelectedCount(snapshot) {
204
206
  return count + 1;
205
207
  }, 0);
206
208
  }
209
+ function isSuccessfulFileChange(row) {
210
+ return row.kind === "tool"
211
+ && typeof row.state === "object"
212
+ && row.state.status === "ok"
213
+ && row.call.kind === "fileChange";
214
+ }
215
+ function flattenReportedChanges(rows) {
216
+ return rows.flatMap((row) => {
217
+ if (!isSuccessfulFileChange(row))
218
+ return [];
219
+ return row.call.changes.map((change) => ({
220
+ sequence: row.sequence,
221
+ at: row.at,
222
+ op: change.op,
223
+ path: change.path,
224
+ ...(change.diffstat === undefined ? {} : { diffstat: change.diffstat }),
225
+ }));
226
+ });
227
+ }
228
+ function summarizeReportedChanges(rows) {
229
+ const eligible = flattenReportedChanges(rows);
230
+ return {
231
+ reportedChanges: eligible.slice(-REPORTED_CHANGE_LIMIT),
232
+ reportedChangesOmitted: Math.max(0, eligible.length - REPORTED_CHANGE_LIMIT),
233
+ };
234
+ }
235
+ function frontierReportedChanges(ledger) {
236
+ if (ledger.openTurn !== undefined)
237
+ return summarizeReportedChanges(ledger.openTurn.rows);
238
+ const closed = ledger.turns.findLast((turn) => turn.kind === "closed");
239
+ return closed === undefined ? EMPTY_REPORTED : summarizeReportedChanges(closed.rows);
240
+ }
207
241
  /** Select one current Turn, one latest outcome, or no focus; pending tells stay actionable. */
208
242
  export function selectSnapshot(ledger, budget = { tail: DEFAULT_TAIL, voice: DEFAULT_VOICE }) {
209
- if (ledger.turns.length === 0 && !ledger.rows.some((row) => row.kind === "tell"))
210
- return { kind: "unborn", entries: [], omitted: 0 };
243
+ if (ledger.turns.length === 0 && !ledger.rows.some((row) => row.kind === "tell")) {
244
+ return { kind: "unborn", entries: [], omitted: 0, ...EMPTY_REPORTED };
245
+ }
211
246
  const pending = ledger.rows.filter((row) => row.kind === "tell" && row.state === "pending");
247
+ const reported = frontierReportedChanges(ledger);
212
248
  if (ledger.openTurn !== undefined) {
213
249
  const window = ledger.openTurn.rows;
214
250
  const active = window.filter((row) => row.kind === "tool" && row.state === "active");
@@ -222,13 +258,14 @@ export function selectSnapshot(ledger, budget = { tail: DEFAULT_TAIL, voice: DEF
222
258
  const voice = voiceCount === 0 ? [] : voiceCandidates.slice(-voiceCount);
223
259
  const selected = new Set([...tail, ...voice, ...active, ...pending]);
224
260
  const omitted = window.filter((row) => !selected.has(row)).length;
225
- return { kind: "open", turn: ledger.openTurn.turn, entries: openEntries(ledger, window, selected), omitted };
261
+ return { kind: "open", turn: ledger.openTurn.turn, entries: openEntries(ledger, window, selected), omitted, ...reported };
226
262
  }
227
263
  return {
228
264
  kind: "idle",
229
265
  ...(ledger.latestOutcome === undefined ? {} : { outcome: ledger.latestOutcome }),
230
266
  entries: entries(pending),
231
267
  omitted: 0,
268
+ ...reported,
232
269
  };
233
270
  }
234
271
  /** Apply the one snapshot policy used by every public observation consumer. */
@@ -24,10 +24,6 @@ export function decodeProviderOptions(value) {
24
24
  const options = record(value);
25
25
  if (options === null)
26
26
  throw new TypeError("provider options must be an object");
27
- const allowed = ["effort", "model", "network", "readonly", "systemPrompt"];
28
- const unknown = Object.keys(options).find((key) => !allowed.includes(key));
29
- if (unknown !== undefined)
30
- throw new TypeError(`provider options have unknown field ${unknown}`);
31
27
  const model = optionText(options, "model", "refuse");
32
28
  const effort = optionText(options, "effort", "refuse");
33
29
  if (options.readonly !== undefined && options.readonly !== true) {
@@ -50,12 +46,10 @@ export function decodeReadonlyRestraint(value) {
50
46
  const restraint = record(value);
51
47
  if (restraint === null)
52
48
  throw new TypeError("readonly restraint must be an object");
53
- const keys = Object.keys(restraint).sort();
54
- if (restraint.enforcement === "native" && keys.length === 1 && keys[0] === "enforcement") {
49
+ if (restraint.enforcement === "native") {
55
50
  return Object.freeze({ enforcement: "native" });
56
51
  }
57
52
  if (restraint.enforcement === "none"
58
- && keys.length === 2 && keys[0] === "diagnostic" && keys[1] === "enforcement"
59
53
  && typeof restraint.diagnostic === "string" && restraint.diagnostic.trim().length > 0) {
60
54
  return Object.freeze({ enforcement: "none", diagnostic: restraint.diagnostic });
61
55
  }
@@ -69,10 +63,6 @@ export function decodeProviderRecipe(input) {
69
63
  const value = record(input);
70
64
  if (value === null)
71
65
  throw new TypeError("provider execution must be an object");
72
- const allowed = ["config", "env", "executable", "kind", "name"];
73
- const unknown = Object.keys(value).find((key) => !allowed.includes(key));
74
- if (unknown !== undefined)
75
- throw new TypeError(`provider execution has unknown field ${unknown}`);
76
66
  if (typeof value.name !== "string" || value.name.trim().length === 0) {
77
67
  throw new TypeError("provider execution name must be a nonblank string");
78
68
  }
@@ -1,4 +1,3 @@
1
- import type { Confinement } from "./heart/index.js";
2
1
  import { decodeResumeCoordinate, encodeResumeCoordinate, type ResumeCoordinate } from "./coordinate.js";
3
2
  import type { ProviderOptions, ReadonlyRestraint } from "./provider-recipe.js";
4
3
  export type { ResumeCoordinate } from "./coordinate.js";
@@ -23,7 +22,7 @@ export type ToolCall = Readonly<{
23
22
  }> | Readonly<{
24
23
  kind: "fileChange";
25
24
  changes: readonly Readonly<{
26
- op: "add" | "update" | "delete";
25
+ op: "add" | "update" | "delete" | "unspecified";
27
26
  path: string;
28
27
  diffstat?: Readonly<{
29
28
  added: number;
@@ -138,7 +137,7 @@ export type DriveInput = Readonly<{
138
137
  cwd: string;
139
138
  options: ProviderOptions;
140
139
  signal: AbortSignal;
141
- requests?: Readonly<{
140
+ requests: Readonly<{
142
141
  dir: string;
143
142
  }>;
144
143
  }>;
@@ -151,10 +150,6 @@ export type ProviderOptionAdmission = Readonly<{
151
150
  diagnostic: string;
152
151
  }>;
153
152
  export type ProviderAdapter = Readonly<{
154
- confinement(input: Readonly<{
155
- cwd: string;
156
- options: ProviderOptions;
157
- }>): Confinement;
158
153
  admitOptions(options: ProviderOptions): ProviderOptionAdmission;
159
154
  fork?(input: Readonly<{
160
155
  session: ResumeCoordinate;
@@ -87,7 +87,8 @@ function decodeDiffstat(value) {
87
87
  }
88
88
  function decodeFileChangeMember(value) {
89
89
  const change = object(value);
90
- if (change === null || (change.op !== "add" && change.op !== "update" && change.op !== "delete")
90
+ if (change === null || (change.op !== "add" && change.op !== "update"
91
+ && change.op !== "delete" && change.op !== "unspecified")
91
92
  || typeof change.path !== "string")
92
93
  return null;
93
94
  const diffstat = decodeDiffstat(change.diffstat);
@@ -1,9 +1,12 @@
1
1
  import * as acp from "@agentclientprotocol/sdk";
2
2
  import { spawnStdioProcess } from "../../../runtime/proc/stdio.js";
3
3
  import { type ProviderAdapter, type Session } from "../../provider.js";
4
+ import { type AcpToolInterpreter, type AcpToolUpdate } from "./events.js";
5
+ export type { AcpToolInterpreter, AcpToolUpdate };
4
6
  export type AcpStartInput = Parameters<ProviderAdapter["start"]>[0] | Parameters<NonNullable<ProviderAdapter["resume"]>>[0];
5
7
  export type AcpDependencies = Readonly<{
6
8
  spawnProcess?: typeof spawnStdioProcess;
9
+ interpretTool?: AcpToolInterpreter;
7
10
  }>;
8
11
  export type AcpLiveSession = Readonly<{
9
12
  session: Session;
@@ -16,4 +19,3 @@ type AcpLaunch = Readonly<{
16
19
  env?: Readonly<Record<string, string>>;
17
20
  }>;
18
21
  export declare function startAcpSession(launch: AcpLaunch, input: AcpStartInput, dependencies?: AcpDependencies): Promise<AcpLiveSession>;
19
- export {};
@@ -2,8 +2,8 @@ import * as acp from "@agentclientprotocol/sdk";
2
2
  import { Readable, Writable } from "node:stream";
3
3
  import { spawnStdioProcess } from "../../../runtime/proc/stdio.js";
4
4
  import { abortable } from "../../abort.js";
5
- import { AgentEventChannel, } from "../../provider.js";
6
- import { EMPTY_ACP_EVENT_STATE, flushAcpEvents, mapAcpUpdate } from "./events.js";
5
+ import { AKUMA_REQUESTS_ENV, AgentEventChannel, } from "../../provider.js";
6
+ import { EMPTY_ACP_EVENT_STATE, flushAcpEvents, mapAcpUpdate, } from "./events.js";
7
7
  function diagnostic(error) {
8
8
  if (!(error instanceof Error))
9
9
  return String(error);
@@ -46,7 +46,7 @@ async function establishSession(agent, input) {
46
46
  await agent.request(acp.methods.agent.session.load, { cwd: input.cwd, mcpServers: [], sessionId });
47
47
  return sessionId;
48
48
  }
49
- function createAcpTurn(connection) {
49
+ function createAcpTurn(connection, interpret) {
50
50
  const events = new AgentEventChannel();
51
51
  let state = EMPTY_ACP_EVENT_STATE;
52
52
  let terminal = false;
@@ -55,7 +55,7 @@ function createAcpTurn(connection) {
55
55
  const update = (next) => {
56
56
  if (terminal)
57
57
  return;
58
- const mapped = mapAcpUpdate(next, state);
58
+ const mapped = mapAcpUpdate(next, state, interpret);
59
59
  state = mapped.state;
60
60
  for (const event of mapped.events)
61
61
  events.emit(event);
@@ -130,7 +130,11 @@ export async function startAcpSession(launch, input, dependencies = {}) {
130
130
  const child = (dependencies.spawnProcess ?? spawnStdioProcess)({
131
131
  argv: launch.argv,
132
132
  cwd: input.cwd,
133
- env: { ...globalThis.process.env, ...launch.env },
133
+ env: {
134
+ ...globalThis.process.env,
135
+ ...launch.env,
136
+ ...(input.requests === undefined ? {} : { [AKUMA_REQUESTS_ENV]: input.requests.dir }),
137
+ },
134
138
  });
135
139
  let sessionId;
136
140
  let turn;
@@ -138,7 +142,7 @@ export async function startAcpSession(launch, input, dependencies = {}) {
138
142
  if (notification.sessionId === sessionId)
139
143
  turn.update(notification.update);
140
144
  }).connect(acp.ndJsonStream(Writable.toWeb(child.input), Readable.toWeb(child.output)));
141
- turn = createAcpTurn(connection);
145
+ turn = createAcpTurn(connection, dependencies.interpretTool);
142
146
  try {
143
147
  sessionId = await abortable(establishSession(connection.agent, input), signal);
144
148
  turn.events.emit({ type: "session", coordinate: { sessionId } });
@@ -1,14 +1,22 @@
1
1
  import type { SessionUpdate } from "@agentclientprotocol/sdk";
2
- import { type AgentEvent } from "../../provider.js";
2
+ import { type AgentEvent, type ToolCall } from "../../provider.js";
3
3
  type OpenBlock = Readonly<{
4
4
  type: "assistant" | "thought";
5
5
  text: string;
6
6
  }> | null;
7
+ export type AcpToolObservation = Readonly<{
8
+ name: string;
9
+ call: ToolCall;
10
+ }>;
11
+ export type AcpToolUpdate = Extract<SessionUpdate, {
12
+ sessionUpdate: "tool_call" | "tool_call_update";
13
+ }>;
14
+ export type AcpToolInterpreter = (update: AcpToolUpdate) => ToolCall | undefined;
7
15
  export type AcpEventState = Readonly<{
8
16
  answer: string;
9
17
  assistantMessageId: string | null;
10
18
  open: OpenBlock;
11
- tools: ReadonlyMap<string, string>;
19
+ tools: ReadonlyMap<string, AcpToolObservation>;
12
20
  }>;
13
21
  type AcpEventMapping = Readonly<{
14
22
  events: readonly AgentEvent[];
@@ -16,5 +24,5 @@ type AcpEventMapping = Readonly<{
16
24
  }>;
17
25
  export declare const EMPTY_ACP_EVENT_STATE: AcpEventState;
18
26
  export declare function flushAcpEvents(state: AcpEventState, boundary?: readonly AgentEvent[]): AcpEventMapping;
19
- export declare function mapAcpUpdate(update: SessionUpdate, previous: AcpEventState): AcpEventMapping;
27
+ export declare function mapAcpUpdate(update: SessionUpdate, previous: AcpEventState, interpret?: AcpToolInterpreter): AcpEventMapping;
20
28
  export {};
@@ -33,7 +33,82 @@ function appendBlock(state, type, text, messageId) {
33
33
  },
34
34
  };
35
35
  }
36
- export function mapAcpUpdate(update, previous) {
36
+ function nonblank(value) {
37
+ return typeof value === "string" && value.trim().length > 0 ? value : undefined;
38
+ }
39
+ function object(value) {
40
+ return value !== null && typeof value === "object" && !Array.isArray(value)
41
+ ? value
42
+ : undefined;
43
+ }
44
+ function positiveLine(value) {
45
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= 1
46
+ ? value
47
+ : undefined;
48
+ }
49
+ function otherCall(name) {
50
+ return { kind: "other", display: name };
51
+ }
52
+ function locationFact(locations) {
53
+ if (locations === null || locations === undefined)
54
+ return {};
55
+ for (const location of locations) {
56
+ const path = nonblank(location.path);
57
+ if (path === undefined)
58
+ continue;
59
+ const offset = positiveLine(location.line);
60
+ return offset === undefined ? { path } : { path, offset };
61
+ }
62
+ return {};
63
+ }
64
+ function standardCall(update, name) {
65
+ const location = locationFact(update.locations);
66
+ if (update.kind === "read") {
67
+ return location.path === undefined
68
+ ? otherCall(name)
69
+ : {
70
+ kind: "read",
71
+ path: location.path,
72
+ ...(location.offset === undefined ? {} : { offset: location.offset }),
73
+ };
74
+ }
75
+ const input = object(update.rawInput);
76
+ if (update.kind === "execute") {
77
+ const command = nonblank(input?.command);
78
+ return command === undefined ? otherCall(name) : { kind: "run", command };
79
+ }
80
+ if (update.kind === "search") {
81
+ const query = nonblank(input?.query);
82
+ if (query === undefined)
83
+ return otherCall(name);
84
+ const path = nonblank(input?.path);
85
+ const glob = nonblank(input?.glob);
86
+ const scope = input?.scope;
87
+ const searchScope = scope === "content" || scope === "files" || scope === "web"
88
+ ? scope
89
+ : undefined;
90
+ return {
91
+ kind: "search",
92
+ query,
93
+ ...(searchScope === undefined ? {} : { scope: searchScope }),
94
+ ...(path === undefined ? {} : { path }),
95
+ ...(glob === undefined ? {} : { glob }),
96
+ };
97
+ }
98
+ return otherCall(name);
99
+ }
100
+ function strongest(previous, next) {
101
+ if (previous === undefined || previous.kind === "other")
102
+ return next;
103
+ return next.kind === "other" ? previous : next;
104
+ }
105
+ function observeTool(update, previous, interpret) {
106
+ const name = nonblank(update.name) ?? nonblank(update.title) ?? previous?.name ?? "ACP tool";
107
+ const standard = standardCall(update, name);
108
+ const dialect = standard.kind === "other" ? interpret?.(update) : undefined;
109
+ return { name, call: strongest(previous?.call, dialect ?? standard) };
110
+ }
111
+ export function mapAcpUpdate(update, previous, interpret) {
37
112
  switch (update.sessionUpdate) {
38
113
  case "agent_message_chunk":
39
114
  case "agent_thought_chunk": {
@@ -47,15 +122,14 @@ export function mapAcpUpdate(update, previous) {
47
122
  case "user_message_chunk": return flushAcpEvents(previous);
48
123
  case "tool_call":
49
124
  case "tool_call_update": {
50
- const name = update.title ?? (update.sessionUpdate === "tool_call" ? undefined : previous.tools.get(update.toolCallId)) ?? "ACP tool";
51
- const observed = { name, call: { kind: "other", display: name } };
125
+ const observed = observeTool(update, previous.tools.get(update.toolCallId), interpret);
52
126
  const tools = new Map(previous.tools);
53
127
  if (update.status === "completed" || update.status === "failed") {
54
128
  tools.delete(update.toolCallId);
55
129
  return flushAcpEvents({ ...previous, tools }, [{ type: "tool", phase: "completed", id: update.toolCallId, ...observed, result: { status: update.status === "completed" ? "ok" : "error" } }]);
56
130
  }
57
131
  const started = tools.has(update.toolCallId);
58
- tools.set(update.toolCallId, name);
132
+ tools.set(update.toolCallId, observed);
59
133
  return started
60
134
  ? flushAcpEvents({ ...previous, tools })
61
135
  : flushAcpEvents({ ...previous, tools }, [{ type: "tool", phase: "started", id: update.toolCallId, ...observed }]);
@@ -86,7 +86,6 @@ export function createAcpProvider(execution, dependencies = {}) {
86
86
  return (await startAcpSession(launch, input, dependencies)).session;
87
87
  };
88
88
  return {
89
- confinement: () => ({ kind: "unconfined" }),
90
89
  admitOptions: (options) => optionAdmission(options, config),
91
90
  start: async (input) => await drive(input),
92
91
  resume: async (input) => await drive(input),
@@ -141,12 +141,63 @@ function fileChangeCall(name, path) {
141
141
  }
142
142
  return undefined;
143
143
  }
144
+ function startedPath(name, value) {
145
+ if (name === "NotebookEdit")
146
+ return nonblank(value.notebook_path);
147
+ return nonblank(value.file_path) ?? (name === "Read" ? nonblank(value.path) : undefined);
148
+ }
149
+ function nonnegativeInt(value) {
150
+ return typeof value === "number" && Number.isInteger(value) && value >= 0 ? value : undefined;
151
+ }
152
+ function fileChange(op, path, gitDiff) {
153
+ const diff = object(gitDiff);
154
+ const added = nonnegativeInt(diff?.additions);
155
+ const removed = nonnegativeInt(diff?.deletions);
156
+ const diffstat = added === undefined || removed === undefined ? undefined : { added, removed };
157
+ return {
158
+ kind: "fileChange",
159
+ changes: [{ op, path, ...(diffstat === undefined ? {} : { diffstat }) }],
160
+ };
161
+ }
162
+ function writeResult(result) {
163
+ const value = object(result);
164
+ if (value === undefined || (value.type !== "create" && value.type !== "update"))
165
+ return undefined;
166
+ const path = nonblank(value.filePath);
167
+ if (path === undefined)
168
+ return undefined;
169
+ const op = value.type === "create" ? "add" : "update";
170
+ return fileChange(op, path, value.gitDiff);
171
+ }
172
+ function editResult(result) {
173
+ const value = object(result);
174
+ if (value === undefined || value.type === "create" || value.type === "update")
175
+ return undefined;
176
+ const path = nonblank(value.filePath);
177
+ if (path === undefined)
178
+ return undefined;
179
+ const status = object(value.gitDiff)?.status;
180
+ return fileChange(status === "added" ? "add" : "update", path, value.gitDiff);
181
+ }
182
+ function notebookResult(result) {
183
+ const path = nonblank(object(result)?.notebook_path);
184
+ return path === undefined
185
+ ? undefined
186
+ : { kind: "fileChange", changes: [{ op: "update", path }] };
187
+ }
188
+ function structuredFileChange(name, result) {
189
+ if (name === "Write")
190
+ return writeResult(result);
191
+ if (name === "Edit")
192
+ return editResult(result);
193
+ return name === "NotebookEdit" ? notebookResult(result) : undefined;
194
+ }
144
195
  function toolCall(name, input) {
145
196
  const value = object(input) ?? {};
146
197
  const run = runCall(name, value);
147
198
  if (run !== undefined)
148
199
  return run;
149
- const path = nonblank(value.file_path) ?? (name === "Read" ? nonblank(value.path) : undefined);
200
+ const path = startedPath(name, value);
150
201
  return readCall(name, path, value)
151
202
  ?? searchCall(name, value)
152
203
  ?? fileChangeCall(name, path)
@@ -192,9 +243,17 @@ function toolResultEvents(message, events, state) {
192
243
  if (observed === undefined)
193
244
  continue;
194
245
  state.tools.delete(id);
246
+ const failed = value.is_error === true;
247
+ const structured = failed
248
+ ? undefined
249
+ : structuredFileChange(observed.name, message.tool_use_result);
195
250
  events.emit({
196
- type: "tool", phase: "completed", id, name: observed.name, call: observed.call,
197
- result: { status: value.is_error === true ? "error" : "ok" },
251
+ type: "tool",
252
+ phase: "completed",
253
+ id,
254
+ name: observed.name,
255
+ call: structured ?? observed.call,
256
+ result: { status: failed ? "error" : "ok" },
198
257
  });
199
258
  }
200
259
  }
@@ -21,10 +21,6 @@ export type ClaudeSdk = Readonly<{
21
21
  }>;
22
22
  export declare function createClaudeProvider(load: () => Promise<ClaudeSdk>, execution?: ClaudeExecution): ProviderAdapter;
23
23
  export declare const claudeProvider: Readonly<{
24
- confinement(input: Readonly<{
25
- cwd: string;
26
- options: ProviderOptions;
27
- }>): import("../../index.js").Confinement;
28
24
  admitOptions(options: ProviderOptions): import("../../provider.js").ProviderOptionAdmission;
29
25
  fork?(input: Readonly<{
30
26
  session: ResumeCoordinate;
@@ -1,6 +1,6 @@
1
1
  import { randomUUID } from "node:crypto";
2
2
  import { abortable } from "../../abort.js";
3
- import { AgentEventChannel, } from "../../provider.js";
3
+ import { AKUMA_REQUESTS_ENV, AgentEventChannel, } from "../../provider.js";
4
4
  import { emitClaudeMessage, } from "./events.js";
5
5
  import { claudeUserMessage, createClaudeInput, isClaudeTurnEnded } from "./input.js";
6
6
  export { CLAUDE_MESSAGE_DISPOSITIONS, CLAUDE_SYSTEM_DISPOSITIONS } from "./events.js";
@@ -61,8 +61,13 @@ function claudeQueryOptions(input, execution, abortController) {
61
61
  return {
62
62
  cwd: input.cwd,
63
63
  abortController,
64
+ ...(input.requests === undefined ? {} : { additionalDirectories: [input.requests.dir] }),
64
65
  ...(execution.executable === undefined ? {} : { pathToClaudeCodeExecutable: execution.executable }),
65
- ...(execution.env === undefined ? {} : { env: { ...process.env, ...execution.env } }),
66
+ ...((execution.env === undefined && input.requests === undefined) ? {} : { env: {
67
+ ...process.env,
68
+ ...execution.env,
69
+ ...(input.requests === undefined ? {} : { [AKUMA_REQUESTS_ENV]: input.requests.dir }),
70
+ } }),
66
71
  permissionMode: mode,
67
72
  ...(mode === "bypassPermissions" ? { allowDangerouslySkipPermissions: true } : {}),
68
73
  settingSources: ["user", "project", "local"],
@@ -269,7 +274,6 @@ async function driveClaude(load, execution, drive) {
269
274
  }
270
275
  export function createClaudeProvider(load, execution = {}) {
271
276
  return {
272
- confinement: () => ({ kind: "unconfined" }),
273
277
  admitOptions: admitClaudeOptions,
274
278
  fork: (input) => forkClaude(load, execution, input),
275
279
  start: (input) => driveClaude(load, execution, input),
@@ -1,4 +1,5 @@
1
1
  import { noteEvent, unknownEvent, } from "../../provider.js";
2
+ import { diffstatFromUnifiedPatch } from "../unified-patch.js";
2
3
  export const CODEX_NOTIFICATION_DISPOSITIONS = {
3
4
  "account/login/completed": "drop",
4
5
  "account/rateLimits/updated": "drop",
@@ -135,19 +136,6 @@ function fileChangeOp(value) {
135
136
  ? record.type
136
137
  : undefined;
137
138
  }
138
- function diffstatFromUnifiedPatch(patch) {
139
- if (!patch.split("\n").some((line) => /^@@ -\d+(?:,\d+)? \+\d+(?:,\d+)? @@/u.test(line)))
140
- return undefined;
141
- let added = 0;
142
- let removed = 0;
143
- for (const line of patch.split("\n")) {
144
- if (line.startsWith("+") && !line.startsWith("+++"))
145
- added += 1;
146
- if (line.startsWith("-") && !line.startsWith("---"))
147
- removed += 1;
148
- }
149
- return { added, removed };
150
- }
151
139
  function itemChanges(item) {
152
140
  if (!Array.isArray(item.changes))
153
141
  return [];
@@ -1,29 +1,4 @@
1
- import { type Session, type ProviderAdapter } from "../../provider.js";
2
- import type { ProviderExecution, ProviderOptions } from "../../provider-recipe.js";
1
+ import { type ProviderAdapter } from "../../provider.js";
2
+ import type { ProviderExecution } from "../../provider-recipe.js";
3
3
  export { CODEX_ITEM_DISPOSITIONS, CODEX_NOTIFICATION_DISPOSITIONS } from "./events.js";
4
4
  export declare function createCodexAppServerProvider(input?: string | ProviderExecution): ProviderAdapter;
5
- export declare const codexAppServerProvider: Readonly<{
6
- confinement(input: Readonly<{
7
- cwd: string;
8
- options: ProviderOptions;
9
- }>): import("../../index.js").Confinement;
10
- admitOptions(options: ProviderOptions): import("../../provider.js").ProviderOptionAdmission;
11
- fork?(input: Readonly<{
12
- session: import("../../coordinate.js").ResumeCoordinate;
13
- at: string;
14
- cwd: string;
15
- }>): Promise<Readonly<{
16
- session: import("../../coordinate.js").ResumeCoordinate;
17
- }>>;
18
- start(input: import("../../provider.js").DriveInput & Readonly<{
19
- session: Readonly<{
20
- kind: "fresh";
21
- }>;
22
- }>): Promise<Session>;
23
- resume?(input: import("../../provider.js").DriveInput & Readonly<{
24
- session: Readonly<{
25
- kind: "resume";
26
- coordinate: import("../../coordinate.js").ResumeCoordinate;
27
- }>;
28
- }>): Promise<Session>;
29
- }>;
@@ -190,7 +190,6 @@ export function createCodexAppServerProvider(input = "codex") {
190
190
  ? { name: "codex-app-server", kind: "codex-app-server", executable: input }
191
191
  : input;
192
192
  return {
193
- confinement: ({ cwd }) => ({ kind: "declared", writableRoots: [cwd] }),
194
193
  admitOptions(options) {
195
194
  return {
196
195
  kind: "admitted",
@@ -203,4 +202,3 @@ export function createCodexAppServerProvider(input = "codex") {
203
202
  resume: (input) => startCodex(execution, input),
204
203
  };
205
204
  }
206
- export const codexAppServerProvider = createCodexAppServerProvider();
@@ -1,4 +1,5 @@
1
1
  import type { ProviderAdapter } from "../../provider.js";
2
2
  import type { ProviderExecution } from "../../provider-recipe.js";
3
- import { type AcpDependencies } from "../acp/core.js";
3
+ import { type AcpDependencies, type AcpToolInterpreter } from "../acp/core.js";
4
+ export declare const interpretGrokTool: AcpToolInterpreter;
4
5
  export declare function createGrokBuildProvider(execution: ProviderExecution, dependencies?: AcpDependencies): ProviderAdapter;