@astrosheep/keiyaku 4.0.6 → 4.1.1

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 (251) hide show
  1. package/README.md +1 -1
  2. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku/SKILL.md +3 -0
  3. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-akuma/SKILL.md +3 -0
  4. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-workflow/SKILL.md +3 -6
  5. package/build/src/akuma/akuma.d.ts +17 -14
  6. package/build/src/akuma/akuma.js +122 -114
  7. package/build/src/akuma/allowed.d.ts +1 -0
  8. package/build/src/akuma/allowed.js +6 -0
  9. package/build/src/akuma/archetype.js +12 -2
  10. package/build/src/akuma/body-turn.js +27 -15
  11. package/build/src/akuma/body.d.ts +44 -3
  12. package/build/src/akuma/body.js +142 -33
  13. package/build/src/akuma/coordinate.js +17 -7
  14. package/build/src/akuma/heart/facts.js +1 -1
  15. package/build/src/akuma/heart/index.d.ts +1 -1
  16. package/build/src/akuma/heart/index.js +2 -4
  17. package/build/src/akuma/heart/request-authority.js +4 -4
  18. package/build/src/akuma/heart/request-rows.js +27 -16
  19. package/build/src/akuma/heart/rows.js +79 -41
  20. package/build/src/akuma/heart/soul.js +1 -1
  21. package/build/src/akuma/heart/storage.d.ts +1 -0
  22. package/build/src/akuma/heart/storage.js +76 -11
  23. package/build/src/akuma/heart/tells.js +35 -18
  24. package/build/src/akuma/heart/timeline.js +19 -11
  25. package/build/src/akuma/identity.d.ts +1 -0
  26. package/build/src/akuma/identity.js +1 -0
  27. package/build/src/akuma/index.d.ts +3 -3
  28. package/build/src/akuma/index.js +1 -1
  29. package/build/src/akuma/nuke.js +106 -14
  30. package/build/src/akuma/projection.d.ts +11 -9
  31. package/build/src/akuma/projection.js +110 -53
  32. package/build/src/akuma/provider-recipe.d.ts +2 -0
  33. package/build/src/akuma/provider-recipe.js +21 -5
  34. package/build/src/akuma/provider.js +105 -62
  35. package/build/src/akuma/providers/acp/config.d.ts +2 -0
  36. package/build/src/akuma/providers/acp/config.js +13 -6
  37. package/build/src/akuma/providers/acp/core.d.ts +5 -2
  38. package/build/src/akuma/providers/acp/core.js +45 -25
  39. package/build/src/akuma/providers/acp/events.js +38 -29
  40. package/build/src/akuma/providers/acp/index.js +18 -8
  41. package/build/src/akuma/providers/claude/events.js +8 -12
  42. package/build/src/akuma/providers/claude/index.d.ts +2 -1
  43. package/build/src/akuma/providers/claude/index.js +59 -26
  44. package/build/src/akuma/providers/claude/input.js +6 -2
  45. package/build/src/akuma/providers/codex-app-server/events.js +61 -36
  46. package/build/src/akuma/providers/codex-app-server/index.js +29 -14
  47. package/build/src/akuma/providers/grok-build/index.js +28 -17
  48. package/build/src/akuma/providers/index.js +3 -19
  49. package/build/src/akuma/providers/opencode-sdk/events.js +32 -18
  50. package/build/src/akuma/providers/opencode-sdk/index.js +29 -17
  51. package/build/src/akuma/providers/opencode-sdk/session.js +21 -5
  52. package/build/src/akuma/providers/pi/events.js +26 -19
  53. package/build/src/akuma/providers/pi/index.js +58 -38
  54. package/build/src/akuma/publication.js +9 -9
  55. package/build/src/akuma/request-serve.js +37 -40
  56. package/build/src/akuma/request-wire.d.ts +2 -2
  57. package/build/src/akuma/request-wire.js +75 -102
  58. package/build/src/akuma/requests.js +2 -2
  59. package/build/src/akuma-body.js +6 -5
  60. package/build/src/body/amend.d.ts +4 -1
  61. package/build/src/body/amend.js +14 -15
  62. package/build/src/body/decode.js +2 -4
  63. package/build/src/body/envelope.js +2 -4
  64. package/build/src/body/region.d.ts +1 -2
  65. package/build/src/body/region.js +4 -72
  66. package/build/src/body/render.js +17 -12
  67. package/build/src/body/shape.js +1 -7
  68. package/build/src/cli/accepted.d.ts +1 -1
  69. package/build/src/cli/accepted.js +10 -1
  70. package/build/src/cli/commands/akuma-invoke.js +18 -6
  71. package/build/src/cli/commands/akuma.js +10 -13
  72. package/build/src/cli/commands/amend.d.ts +2 -2
  73. package/build/src/cli/commands/amend.js +2 -4
  74. package/build/src/cli/commands/bind.d.ts +4 -4
  75. package/build/src/cli/commands/bind.js +16 -6
  76. package/build/src/cli/commands/contract.d.ts +99 -10
  77. package/build/src/cli/commands/contract.js +128 -24
  78. package/build/src/cli/commands/install.d.ts +1 -1
  79. package/build/src/cli/commands/install.js +23 -15
  80. package/build/src/cli/commands/task-invoke.d.ts +4 -1
  81. package/build/src/cli/commands/task-invoke.js +191 -68
  82. package/build/src/cli/commands/task-query.js +48 -24
  83. package/build/src/cli/commands/task.js +150 -30
  84. package/build/src/cli/coordinates.js +2 -4
  85. package/build/src/cli/invoke.js +88 -44
  86. package/build/src/cli/main.js +4 -2
  87. package/build/src/cli/parse.d.ts +2 -89
  88. package/build/src/cli/parse.js +87 -79
  89. package/build/src/cli/render/akuma-tool-command.js +6 -7
  90. package/build/src/cli/render/akuma-tool.js +10 -8
  91. package/build/src/cli/render/akuma.js +149 -53
  92. package/build/src/cli/render/audit.js +5 -15
  93. package/build/src/cli/render/board.d.ts +1 -0
  94. package/build/src/cli/render/board.js +17 -0
  95. package/build/src/cli/render/catalog.js +84 -7
  96. package/build/src/cli/render/contract-observation.d.ts +10 -0
  97. package/build/src/cli/render/contract-observation.js +58 -0
  98. package/build/src/cli/render/contract.js +57 -54
  99. package/build/src/cli/render/kanshi.js +281 -209
  100. package/build/src/cli/render/receipt.d.ts +1 -0
  101. package/build/src/cli/render/receipt.js +20 -23
  102. package/build/src/cli/render/refusal.js +16 -15
  103. package/build/src/cli/render/region.js +22 -6
  104. package/build/src/cli/render/settings.js +4 -4
  105. package/build/src/cli/render/task.js +93 -21
  106. package/build/src/cli/render/terminal.js +16 -5
  107. package/build/src/cli/result.d.ts +11 -4
  108. package/build/src/cli/runtime.d.ts +6 -1
  109. package/build/src/cli/runtime.js +84 -63
  110. package/build/src/cli/selectors.js +2 -4
  111. package/build/src/cli/usage.js +6 -5
  112. package/build/src/contract-worktree.d.ts +1 -25
  113. package/build/src/contract-worktree.js +87 -174
  114. package/build/src/coordination/durable-file.js +7 -3
  115. package/build/src/coordination/sqlite-transaction-lock.js +29 -12
  116. package/build/src/core/facts/codec.js +7 -3
  117. package/build/src/core/facts/types.d.ts +1 -1
  118. package/build/src/core/subject.js +16 -9
  119. package/build/src/core/verbs/abandon.d.ts +1 -1
  120. package/build/src/core/verbs/abandon.js +1 -1
  121. package/build/src/core/verbs/amend.d.ts +1 -1
  122. package/build/src/core/verbs/amend.js +7 -7
  123. package/build/src/core/verbs/attestation.js +4 -1
  124. package/build/src/core/verbs/bind.d.ts +1 -1
  125. package/build/src/core/verbs/bind.js +1 -1
  126. package/build/src/core/verbs/placement.d.ts +1 -1
  127. package/build/src/core/verbs/placement.js +10 -8
  128. package/build/src/dispatch/index.js +8 -6
  129. package/build/src/duration.js +5 -1
  130. package/build/src/git/admission.js +5 -3
  131. package/build/src/git/hooks.d.ts +8 -0
  132. package/build/src/git/hooks.js +63 -14
  133. package/build/src/git/identity.js +1 -4
  134. package/build/src/git/integration.d.ts +2 -3
  135. package/build/src/git/integration.js +32 -39
  136. package/build/src/git/nuke.d.ts +1 -1
  137. package/build/src/git/nuke.js +110 -62
  138. package/build/src/git/observe.d.ts +13 -1
  139. package/build/src/git/observe.js +51 -44
  140. package/build/src/git/process.js +4 -2
  141. package/build/src/git/read-observation.js +10 -8
  142. package/build/src/git/reconcile.d.ts +14 -3
  143. package/build/src/git/reconcile.js +123 -102
  144. package/build/src/git/repository.d.ts +2 -0
  145. package/build/src/git/repository.js +13 -22
  146. package/build/src/git/target-placement.d.ts +9 -10
  147. package/build/src/git/target-placement.js +59 -62
  148. package/build/src/git/tender.d.ts +13 -2
  149. package/build/src/git/tender.js +28 -22
  150. package/build/src/git/terminal-seal.js +15 -12
  151. package/build/src/git/tree.js +5 -2
  152. package/build/src/git/workspace.d.ts +24 -2
  153. package/build/src/git/workspace.js +120 -16
  154. package/build/src/identity/coordinates.js +3 -1
  155. package/build/src/identity/selector.js +6 -3
  156. package/build/src/kanshi/fleet.d.ts +6 -0
  157. package/build/src/kanshi/fleet.js +27 -0
  158. package/build/src/kanshi/index.d.ts +1 -1
  159. package/build/src/kanshi/read.js +77 -45
  160. package/build/src/kanshi/report.d.ts +13 -24
  161. package/build/src/kanshi/select.js +25 -24
  162. package/build/src/library/address.d.ts +2 -1
  163. package/build/src/library/address.js +7 -8
  164. package/build/src/library/akuma-creation.js +20 -12
  165. package/build/src/library/audit.d.ts +0 -1
  166. package/build/src/library/audit.js +1 -2
  167. package/build/src/library/bind.d.ts +53 -5
  168. package/build/src/library/bind.js +98 -22
  169. package/build/src/library/catalog.d.ts +1 -0
  170. package/build/src/library/catalog.js +6 -3
  171. package/build/src/library/configuration.js +3 -1
  172. package/build/src/library/continuation.d.ts +37 -0
  173. package/build/src/library/continuation.js +86 -0
  174. package/build/src/library/contract.d.ts +39 -45
  175. package/build/src/library/contract.js +141 -118
  176. package/build/src/library/delivery.d.ts +18 -13
  177. package/build/src/library/fleet.d.ts +1 -1
  178. package/build/src/library/fleet.js +19 -11
  179. package/build/src/library/input.d.ts +2 -0
  180. package/build/src/library/input.js +14 -0
  181. package/build/src/library/keiyaku.d.ts +8 -7
  182. package/build/src/library/keiyaku.js +3 -3
  183. package/build/src/library/mutation.js +11 -4
  184. package/build/src/library/nuke.js +14 -5
  185. package/build/src/library/reconcile.d.ts +9 -4
  186. package/build/src/library/reconcile.js +30 -24
  187. package/build/src/library/refusal.d.ts +13 -5
  188. package/build/src/library/refusal.js +7 -0
  189. package/build/src/library/region.d.ts +8 -7
  190. package/build/src/library/region.js +31 -11
  191. package/build/src/library/repo.js +2 -2
  192. package/build/src/markdown/lex.js +9 -2
  193. package/build/src/markdown/parse.js +11 -7
  194. package/build/src/markdown/query.js +4 -2
  195. package/build/src/protocol/amend.js +3 -1
  196. package/build/src/protocol/attempt.d.ts +7 -3
  197. package/build/src/protocol/attempt.js +9 -5
  198. package/build/src/protocol/audit.d.ts +1 -1
  199. package/build/src/protocol/audit.js +4 -14
  200. package/build/src/protocol/bind.d.ts +19 -6
  201. package/build/src/protocol/bind.js +28 -13
  202. package/build/src/protocol/completion.d.ts +0 -1
  203. package/build/src/protocol/completion.js +1 -3
  204. package/build/src/protocol/deliver.d.ts +12 -4
  205. package/build/src/protocol/deliver.js +60 -51
  206. package/build/src/protocol/intent.d.ts +1 -0
  207. package/build/src/protocol/intent.js +9 -7
  208. package/build/src/protocol/operations.d.ts +10 -9
  209. package/build/src/protocol/operations.js +5 -3
  210. package/build/src/protocol/placement.d.ts +0 -1
  211. package/build/src/protocol/placement.js +6 -6
  212. package/build/src/protocol/read/observation.d.ts +11 -0
  213. package/build/src/protocol/read/observation.js +37 -0
  214. package/build/src/protocol/read/status.d.ts +23 -12
  215. package/build/src/protocol/read/status.js +90 -72
  216. package/build/src/protocol/reconcile.d.ts +1 -0
  217. package/build/src/protocol/reconcile.js +2 -3
  218. package/build/src/protocol/reintegrate.js +1 -1
  219. package/build/src/protocol/review.d.ts +0 -1
  220. package/build/src/protocol/review.js +15 -22
  221. package/build/src/protocol/run.d.ts +1 -0
  222. package/build/src/protocol/run.js +4 -5
  223. package/build/src/runtime/proc/launch.d.ts +33 -0
  224. package/build/src/runtime/proc/launch.js +98 -0
  225. package/build/src/runtime/proc/line-rpc.js +9 -3
  226. package/build/src/runtime/proc/run.d.ts +12 -6
  227. package/build/src/runtime/proc/run.js +78 -21
  228. package/build/src/runtime/proc/stdio.js +7 -10
  229. package/build/src/settings.js +6 -2
  230. package/build/src/settlement/fence.d.ts +0 -2
  231. package/build/src/settlement/fence.js +0 -24
  232. package/build/src/settlement/holder.js +13 -10
  233. package/build/src/settlement/settle.js +39 -6
  234. package/build/src/task/board.d.ts +21 -2
  235. package/build/src/task/board.js +35 -16
  236. package/build/src/task/compose.js +85 -22
  237. package/build/src/task/context.js +21 -8
  238. package/build/src/task/document.js +46 -10
  239. package/build/src/task/identity.js +19 -6
  240. package/build/src/task/index.js +118 -27
  241. package/build/src/task/input.js +29 -7
  242. package/build/src/task/mutation.js +61 -19
  243. package/build/src/task/operations.d.ts +8 -2
  244. package/build/src/task/operations.js +97 -32
  245. package/build/src/task/query.js +57 -28
  246. package/build/src/task/store.d.ts +5 -1
  247. package/build/src/task/store.js +88 -95
  248. package/build/src/verification/execution.js +14 -11
  249. package/build/src/workspace-place.js +19 -7
  250. package/build/src/world.js +16 -6
  251. package/package.json +8 -3
@@ -1,4 +1,4 @@
1
- import { noteEvent, unknownEvent, } from "../../provider.js";
1
+ import { noteEvent, unknownEvent } from "../../provider.js";
2
2
  export const CLAUDE_MESSAGE_DISPOSITIONS = {
3
3
  assistant: "assistant",
4
4
  auth_status: "auth",
@@ -181,9 +181,7 @@ function editResult(result) {
181
181
  }
182
182
  function notebookResult(result) {
183
183
  const path = nonblank(object(result)?.notebook_path);
184
- return path === undefined
185
- ? undefined
186
- : { kind: "fileChange", changes: [{ op: "update", path }] };
184
+ return path === undefined ? undefined : { kind: "fileChange", changes: [{ op: "update", path }] };
187
185
  }
188
186
  function structuredFileChange(name, result) {
189
187
  if (name === "Write")
@@ -198,10 +196,9 @@ function toolCall(name, input) {
198
196
  if (run !== undefined)
199
197
  return run;
200
198
  const path = startedPath(name, value);
201
- return readCall(name, path, value)
202
- ?? searchCall(name, value)
203
- ?? fileChangeCall(name, path)
204
- ?? { kind: "other", display: name };
199
+ return (readCall(name, path, value) ??
200
+ searchCall(name, value) ??
201
+ fileChangeCall(name, path) ?? { kind: "other", display: name });
205
202
  }
206
203
  function assistantEvents(message, events, state) {
207
204
  if (message.aborted === true)
@@ -212,7 +209,8 @@ function assistantEvents(message, events, state) {
212
209
  }
213
210
  const text = message.message.content
214
211
  .filter((block) => block.type === "text")
215
- .map((block) => block.text).join("");
212
+ .map((block) => block.text)
213
+ .join("");
216
214
  if (text.length > 0)
217
215
  events.emit({ type: "assistant", text });
218
216
  for (const block of message.message.content) {
@@ -244,9 +242,7 @@ function toolResultEvents(message, events, state) {
244
242
  continue;
245
243
  state.tools.delete(id);
246
244
  const failed = value.is_error === true;
247
- const structured = failed
248
- ? undefined
249
- : structuredFileChange(observed.name, message.tool_use_result);
245
+ const structured = failed ? undefined : structuredFileChange(observed.name, message.tool_use_result);
250
246
  events.emit({
251
247
  type: "tool",
252
248
  phase: "completed",
@@ -5,6 +5,7 @@ import type { ResumeCoordinate } from "../../provider.js";
5
5
  export { CLAUDE_MESSAGE_DISPOSITIONS, CLAUDE_SYSTEM_DISPOSITIONS } from "./events.js";
6
6
  type ClaudeExecution = Readonly<{
7
7
  executable?: string;
8
+ config?: Readonly<Record<string, unknown>>;
8
9
  env?: Readonly<Record<string, string>>;
9
10
  }>;
10
11
  export type ClaudeSdk = Readonly<{
@@ -19,7 +20,7 @@ export type ClaudeSdk = Readonly<{
19
20
  sessionId: string;
20
21
  }>>;
21
22
  }>;
22
- export declare function createClaudeProvider(load: () => Promise<ClaudeSdk>, execution?: ClaudeExecution): ProviderAdapter;
23
+ export declare function createClaudeProvider(loadOrExecution?: (() => Promise<ClaudeSdk>) | ClaudeExecution, execution?: ClaudeExecution): ProviderAdapter;
23
24
  export declare const claudeProvider: Readonly<{
24
25
  admitOptions(options: ProviderOptions): import("../../provider.js").ProviderOptionAdmission;
25
26
  fork?(input: Readonly<{
@@ -1,7 +1,7 @@
1
1
  import { randomUUID } from "node:crypto";
2
2
  import { abortable } from "../../abort.js";
3
3
  import { AKUMA_REQUESTS_ENV, AgentEventChannel, } from "../../provider.js";
4
- import { emitClaudeMessage, } from "./events.js";
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";
7
7
  class ReceiptChannel {
@@ -59,23 +59,32 @@ function claudeSessionId(coordinate) {
59
59
  function claudeQueryOptions(input, execution, abortController) {
60
60
  const mode = permissionMode(input.options.readonly);
61
61
  return {
62
+ ...(execution.config ?? {}),
62
63
  cwd: input.cwd,
63
64
  abortController,
64
65
  ...(input.requests === undefined ? {} : { additionalDirectories: [input.requests.dir] }),
65
66
  ...(execution.executable === undefined ? {} : { pathToClaudeCodeExecutable: execution.executable }),
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
- } }),
67
+ ...(execution.env === undefined && input.requests === undefined
68
+ ? {}
69
+ : {
70
+ env: {
71
+ ...process.env,
72
+ ...execution.env,
73
+ ...(input.requests === undefined ? {} : { [AKUMA_REQUESTS_ENV]: input.requests.dir }),
74
+ },
75
+ }),
71
76
  permissionMode: mode,
72
77
  ...(mode === "bypassPermissions" ? { allowDangerouslySkipPermissions: true } : {}),
73
78
  settingSources: ["user", "project", "local"],
74
79
  ...(input.options.model === undefined ? {} : { model: input.options.model }),
75
80
  ...(input.options.effort === undefined ? {} : { effort: input.options.effort }),
76
- ...(input.options.systemPrompt === undefined || input.options.systemPrompt.length === 0 ? {} : {
77
- systemPrompt: { type: "preset", preset: "claude_code", append: input.options.systemPrompt },
78
- }),
81
+ ...(input.options.systemPrompt === undefined || input.options.systemPrompt.length === 0
82
+ ? {}
83
+ : {
84
+ systemPrompt: input.options.systemPromptMode === "replace"
85
+ ? input.options.systemPrompt
86
+ : { type: "preset", preset: "claude_code", append: input.options.systemPrompt },
87
+ }),
79
88
  ...(input.session.kind === "fresh" ? {} : { resume: claudeSessionId(input.session.coordinate) }),
80
89
  };
81
90
  }
@@ -94,8 +103,7 @@ async function forkClaude(load, execution, input) {
94
103
  return { session: { sessionId: forked.sessionId } };
95
104
  }
96
105
  function launchText(input) {
97
- return [input.body, ...input.launchTells.map((tell) => tell.text)]
98
- .filter((part) => part.length > 0).join("\n\n");
106
+ return [input.body, ...input.launchTells.map((tell) => tell.text)].filter((part) => part.length > 0).join("\n\n");
99
107
  }
100
108
  function successfulResult(message, historyId) {
101
109
  return {
@@ -115,9 +123,14 @@ function observeClaudeQuery(context) {
115
123
  const observation = { tools: new Map() };
116
124
  let admit;
117
125
  let rejectAdmission;
118
- const admission = new Promise((resolve, reject) => { admit = resolve; rejectAdmission = reject; });
126
+ const admission = new Promise((resolve, reject) => {
127
+ admit = resolve;
128
+ rejectAdmission = reject;
129
+ });
119
130
  let settle;
120
- const completion = new Promise((resolve) => { settle = resolve; });
131
+ const completion = new Promise((resolve) => {
132
+ settle = resolve;
133
+ });
121
134
  let checkpoint = 0, ended = false;
122
135
  const settleReceipts = () => {
123
136
  if (ended && state.openSubmissions === 0 && accepted.every((tell) => tell.visible))
@@ -152,8 +165,10 @@ function observeClaudeQuery(context) {
152
165
  admit();
153
166
  }
154
167
  emitClaudeMessage(message, events, observation);
155
- if (message.type === "assistant" && message.parent_tool_use_id === null
156
- && typeof message.uuid === "string" && message.uuid.length > 0)
168
+ if (message.type === "assistant" &&
169
+ message.parent_tool_use_id === null &&
170
+ typeof message.uuid === "string" &&
171
+ message.uuid.length > 0)
157
172
  historyId = message.uuid;
158
173
  if (message.type !== "result")
159
174
  continue;
@@ -191,8 +206,12 @@ function observeClaudeQuery(context) {
191
206
  return {
192
207
  admission,
193
208
  completion,
194
- get ended() { return ended; },
195
- get checkpoint() { return checkpoint; },
209
+ get ended() {
210
+ return ended;
211
+ },
212
+ get checkpoint() {
213
+ return checkpoint;
214
+ },
196
215
  flushReceipts,
197
216
  settleReceipts,
198
217
  };
@@ -225,8 +244,16 @@ async function driveClaude(load, execution, drive) {
225
244
  const abortSetup = () => shutDown(signal.reason);
226
245
  signal.addEventListener("abort", abortSetup, { once: true });
227
246
  const observed = observeClaudeQuery({
228
- query, input, events, receipts, accepted,
229
- state: { get openSubmissions() { return openSubmissions; } },
247
+ query,
248
+ input,
249
+ events,
250
+ receipts,
251
+ accepted,
252
+ state: {
253
+ get openSubmissions() {
254
+ return openSubmissions;
255
+ },
256
+ },
230
257
  });
231
258
  try {
232
259
  await Promise.all([launchAcknowledged, observed.admission]);
@@ -246,10 +273,12 @@ async function driveClaude(load, execution, drive) {
246
273
  const ordinal = ++submission;
247
274
  return new Promise((resolve, reject) => {
248
275
  const pending = { id: tell.id, afterCheckpoint: 0, visible: false };
249
- void input.push(claudeUserMessage(tell.text), () => {
276
+ void input
277
+ .push(claudeUserMessage(tell.text), () => {
250
278
  pending.afterCheckpoint = observed.checkpoint;
251
279
  accepted.push(pending);
252
- }).then(() => {
280
+ })
281
+ .then(() => {
253
282
  openSubmissions -= 1;
254
283
  resolve({ kind: "accepted", fence: `claude:${run}:${ordinal}` });
255
284
  queueMicrotask(() => {
@@ -277,12 +306,16 @@ async function driveClaude(load, execution, drive) {
277
306
  },
278
307
  };
279
308
  }
280
- export function createClaudeProvider(load, execution = {}) {
309
+ export function createClaudeProvider(loadOrExecution = async () => (await import("@anthropic-ai/claude-agent-sdk")), execution = {}) {
310
+ const load = typeof loadOrExecution === "function"
311
+ ? loadOrExecution
312
+ : async () => (await import("@anthropic-ai/claude-agent-sdk"));
313
+ const selectedExecution = typeof loadOrExecution === "function" ? execution : loadOrExecution;
281
314
  return {
282
315
  admitOptions: admitClaudeOptions,
283
- fork: (input) => forkClaude(load, execution, input),
284
- start: (input) => driveClaude(load, execution, input),
285
- resume: (input) => driveClaude(load, execution, input),
316
+ fork: (input) => forkClaude(load, selectedExecution, input),
317
+ start: (input) => driveClaude(load, selectedExecution, input),
318
+ resume: (input) => driveClaude(load, selectedExecution, input),
286
319
  };
287
320
  }
288
- export const claudeProvider = createClaudeProvider(async () => await import("@anthropic-ai/claude-agent-sdk"));
321
+ export const claudeProvider = createClaudeProvider(async () => (await import("@anthropic-ai/claude-agent-sdk")));
@@ -49,8 +49,12 @@ export function createClaudeInput() {
49
49
  entry.pulled.reject(error);
50
50
  };
51
51
  return {
52
- get closed() { return closed; },
53
- get pending() { return queue.length + (previous === undefined ? 0 : 1); },
52
+ get closed() {
53
+ return closed;
54
+ },
55
+ get pending() {
56
+ return queue.length + (previous === undefined ? 0 : 1);
57
+ },
54
58
  push(message, onPulled) {
55
59
  if (closed)
56
60
  return Promise.reject(failure ?? ended());
@@ -112,11 +112,16 @@ function turnError(value) {
112
112
  }
113
113
  function itemNote(item, kind) {
114
114
  switch (kind) {
115
- case "enteredReviewMode": return "Entered review mode";
116
- case "exitedReviewMode": return "Exited review mode";
117
- case "sleep": return "Waiting";
118
- case "subAgentActivity": return `Agent activity: ${codexText(item.kind) ?? "updated"}`;
119
- default: return kind;
115
+ case "enteredReviewMode":
116
+ return "Entered review mode";
117
+ case "exitedReviewMode":
118
+ return "Exited review mode";
119
+ case "sleep":
120
+ return "Waiting";
121
+ case "subAgentActivity":
122
+ return `Agent activity: ${codexText(item.kind) ?? "updated"}`;
123
+ default:
124
+ return kind;
120
125
  }
121
126
  }
122
127
  function itemToolName(item, kind) {
@@ -132,9 +137,7 @@ function fileChangeOp(value) {
132
137
  if (value === "add" || value === "update" || value === "delete")
133
138
  return value;
134
139
  const record = codexObject(value);
135
- return record?.type === "add" || record?.type === "update" || record?.type === "delete"
136
- ? record.type
137
- : undefined;
140
+ return record?.type === "add" || record?.type === "update" || record?.type === "delete" ? record.type : undefined;
138
141
  }
139
142
  function itemChanges(item) {
140
143
  if (!Array.isArray(item.changes))
@@ -146,11 +149,13 @@ function itemChanges(item) {
146
149
  if (path === undefined || op === undefined)
147
150
  return [];
148
151
  const diffstat = typeof change?.diff === "string" ? diffstatFromUnifiedPatch(change.diff) : undefined;
149
- return [{
152
+ return [
153
+ {
150
154
  op,
151
155
  path,
152
156
  ...(diffstat === undefined ? {} : { diffstat }),
153
- }];
157
+ },
158
+ ];
154
159
  });
155
160
  }
156
161
  function reasoningSummary(item) {
@@ -158,12 +163,14 @@ function reasoningSummary(item) {
158
163
  return codexText(item.summary);
159
164
  if (!Array.isArray(item.summary))
160
165
  return undefined;
161
- return codexText(item.summary.map((part) => {
166
+ return codexText(item.summary
167
+ .map((part) => {
162
168
  if (typeof part === "string")
163
169
  return part;
164
170
  const value = codexObject(part);
165
- return value?.type === "summary_text" || value?.type === "text" ? codexText(value.text) ?? "" : "";
166
- }).join("\n"));
171
+ return value?.type === "summary_text" || value?.type === "text" ? (codexText(value.text) ?? "") : "";
172
+ })
173
+ .join("\n"));
167
174
  }
168
175
  function itemToolCall(item, kind) {
169
176
  if (kind === "commandExecution") {
@@ -175,9 +182,7 @@ function itemToolCall(item, kind) {
175
182
  }
176
183
  if (kind === "webSearch") {
177
184
  const query = codexText(item.query);
178
- return query === undefined
179
- ? { kind: "other", display: "web search" }
180
- : { kind: "search", query, scope: "web" };
185
+ return query === undefined ? { kind: "other", display: "web search" } : { kind: "search", query, scope: "web" };
181
186
  }
182
187
  if (kind === "fileChange") {
183
188
  const changes = itemChanges(item);
@@ -256,24 +261,42 @@ function emitItem(item, completed, events, state) {
256
261
  function notificationAction(method, params) {
257
262
  const message = codexText(params.message) ?? codexText(params.reason) ?? codexText(params.error);
258
263
  switch (method) {
259
- case "configWarning": return `Configuration warning: ${message ?? "unknown warning"}`;
260
- case "deprecationNotice": return `Deprecation warning: ${message ?? "deprecated behavior"}`;
261
- case "externalAgentConfig/import/completed": return "External agent configuration import completed";
262
- case "externalAgentConfig/import/progress": return "External agent configuration import updated";
263
- case "fs/changed": return "Filesystem changed";
264
- case "guardianWarning": return `Guardian warning: ${message ?? "action warned"}`;
265
- case "hook/started": return `Hook ${codexText(params.name) ?? codexText(params.hookName) ?? "unknown"} started`;
266
- case "item/autoApprovalReview/completed": return "Action approval review completed";
267
- case "item/autoApprovalReview/started": return "Action approval review started";
268
- case "model/rerouted": return `Model rerouted${message === undefined ? "" : `: ${message}`}`;
269
- case "thread/goal/cleared": return "Goal cleared";
270
- case "thread/goal/updated": return "Goal updated";
271
- case "thread/realtime/error": return `Realtime warning: ${message ?? "unknown error"}`;
272
- case "turn/moderationMetadata": return "Moderation updated";
273
- case "warning": return `Warning: ${message ?? "unknown warning"}`;
274
- case "windows/worldWritableWarning": return `Filesystem warning: ${message ?? "world-writable path"}`;
275
- case "windowsSandbox/setupCompleted": return "Windows sandbox setup completed";
276
- default: return method;
264
+ case "configWarning":
265
+ return `Configuration warning: ${message ?? "unknown warning"}`;
266
+ case "deprecationNotice":
267
+ return `Deprecation warning: ${message ?? "deprecated behavior"}`;
268
+ case "externalAgentConfig/import/completed":
269
+ return "External agent configuration import completed";
270
+ case "externalAgentConfig/import/progress":
271
+ return "External agent configuration import updated";
272
+ case "fs/changed":
273
+ return "Filesystem changed";
274
+ case "guardianWarning":
275
+ return `Guardian warning: ${message ?? "action warned"}`;
276
+ case "hook/started":
277
+ return `Hook ${codexText(params.name) ?? codexText(params.hookName) ?? "unknown"} started`;
278
+ case "item/autoApprovalReview/completed":
279
+ return "Action approval review completed";
280
+ case "item/autoApprovalReview/started":
281
+ return "Action approval review started";
282
+ case "model/rerouted":
283
+ return `Model rerouted${message === undefined ? "" : `: ${message}`}`;
284
+ case "thread/goal/cleared":
285
+ return "Goal cleared";
286
+ case "thread/goal/updated":
287
+ return "Goal updated";
288
+ case "thread/realtime/error":
289
+ return `Realtime warning: ${message ?? "unknown error"}`;
290
+ case "turn/moderationMetadata":
291
+ return "Moderation updated";
292
+ case "warning":
293
+ return `Warning: ${message ?? "unknown warning"}`;
294
+ case "windows/worldWritableWarning":
295
+ return `Filesystem warning: ${message ?? "world-writable path"}`;
296
+ case "windowsSandbox/setupCompleted":
297
+ return "Windows sandbox setup completed";
298
+ default:
299
+ return method;
277
300
  }
278
301
  }
279
302
  function observeError(params, state, events) {
@@ -303,7 +326,8 @@ export function codexNotificationResult(notification, state, events) {
303
326
  const disposition = CODEX_NOTIFICATION_DISPOSITIONS[method];
304
327
  const params = codexObject(notification.params) ?? {};
305
328
  switch (disposition) {
306
- case "drop": return undefined;
329
+ case "drop":
330
+ return undefined;
307
331
  case "note":
308
332
  events.emit(noteEvent(notificationAction(method, params)));
309
333
  return undefined;
@@ -323,6 +347,7 @@ export function codexNotificationResult(notification, state, events) {
323
347
  case "error":
324
348
  observeError(params, state, events);
325
349
  return undefined;
326
- case "terminal": return terminalResult(params, state);
350
+ case "terminal":
351
+ return terminalResult(params, state);
327
352
  }
328
353
  }
@@ -1,6 +1,6 @@
1
1
  import { LineRpcProcess } from "../../../runtime/proc/line-rpc.js";
2
2
  import { AgentEventChannel, AKUMA_REQUESTS_ENV, } from "../../provider.js";
3
- import { codexNotificationResult, codexObject, codexText, } from "./events.js";
3
+ import { codexNotificationResult, codexObject, codexText } from "./events.js";
4
4
  export { CODEX_ITEM_DISPOSITIONS, CODEX_NOTIFICATION_DISPOSITIONS } from "./events.js";
5
5
  function diagnostic(error) {
6
6
  return error instanceof Error ? error.message : String(error);
@@ -66,7 +66,10 @@ async function admitTurn(server, input, state, events, config) {
66
66
  ...(config === undefined ? {} : { config }),
67
67
  ...(input.options.model === undefined ? {} : { model: input.options.model }),
68
68
  ...(input.options.systemPrompt === undefined || input.options.systemPrompt.length === 0
69
- ? {} : { developerInstructions: input.options.systemPrompt }),
69
+ ? {}
70
+ : input.options.systemPromptMode === "replace"
71
+ ? { baseInstructions: input.options.systemPrompt }
72
+ : { developerInstructions: input.options.systemPrompt }),
70
73
  };
71
74
  if (input.session.kind === "fresh") {
72
75
  state.threadId = threadId(await server.request("thread/start", threadParams));
@@ -80,8 +83,14 @@ async function admitTurn(server, input, state, events, config) {
80
83
  events.emit({ type: "session", coordinate: { sessionId: state.threadId } });
81
84
  state.turnId = turnId(await server.request("turn/start", {
82
85
  threadId: state.threadId,
83
- input: [{ type: "text", text: [input.body, ...input.launchTells.map((tell) => tell.text)]
84
- .filter((part) => part.length > 0).join("\n\n") }],
86
+ input: [
87
+ {
88
+ type: "text",
89
+ text: [input.body, ...input.launchTells.map((tell) => tell.text)]
90
+ .filter((part) => part.length > 0)
91
+ .join("\n\n"),
92
+ },
93
+ ],
85
94
  ...(input.options.model === undefined ? {} : { model: input.options.model }),
86
95
  ...(input.options.effort === undefined ? {} : { effort: input.options.effort }),
87
96
  approvalPolicy: "never",
@@ -123,15 +132,21 @@ async function startCodex(execution, input) {
123
132
  const server = new LineRpcProcess({
124
133
  argv: [execution.executable ?? "codex", "app-server", "--listen", "stdio://"],
125
134
  cwd: input.cwd,
126
- ...((execution.env === undefined && input.requests === undefined) ? {} : { env: {
127
- ...process.env,
128
- ...execution.env,
129
- ...(input.requests === undefined ? {} : { [AKUMA_REQUESTS_ENV]: input.requests.dir }),
130
- } }),
135
+ ...(execution.env === undefined && input.requests === undefined
136
+ ? {}
137
+ : {
138
+ env: {
139
+ ...process.env,
140
+ ...execution.env,
141
+ ...(input.requests === undefined ? {} : { [AKUMA_REQUESTS_ENV]: input.requests.dir }),
142
+ },
143
+ }),
131
144
  });
132
145
  const state = { settled: false, tools: new Map() };
133
146
  let settle;
134
- const completion = new Promise((resolve) => { settle = resolve; });
147
+ const completion = new Promise((resolve) => {
148
+ settle = resolve;
149
+ });
135
150
  let terminal;
136
151
  const finish = (result) => {
137
152
  if (terminal !== undefined)
@@ -159,7 +174,9 @@ async function startCodex(execution, input) {
159
174
  kind: "failed",
160
175
  diagnostic: `codex app-server made forbidden interactive request ${request.method}`,
161
176
  }));
162
- const abortSetup = () => { void server.close(true); };
177
+ const abortSetup = () => {
178
+ void server.close(true);
179
+ };
163
180
  signal.addEventListener("abort", abortSetup, { once: true });
164
181
  try {
165
182
  signal.throwIfAborted();
@@ -191,9 +208,7 @@ async function startCodex(execution, input) {
191
208
  };
192
209
  }
193
210
  export function createCodexAppServerProvider(input = "codex") {
194
- const execution = typeof input === "string"
195
- ? { name: "codex-app-server", kind: "codex-app-server", executable: input }
196
- : input;
211
+ const execution = typeof input === "string" ? { name: "codex-app-server", kind: "codex-app-server", executable: input } : input;
197
212
  return {
198
213
  admitOptions(options) {
199
214
  return {
@@ -52,39 +52,51 @@ function fileChangeCall(name, input) {
52
52
  if (name !== "search_replace")
53
53
  return undefined;
54
54
  const path = nonblank(input.file_path);
55
- return path === undefined
56
- ? undefined
57
- : { kind: "fileChange", changes: [{ op: "unspecified", path }] };
55
+ return path === undefined ? undefined : { kind: "fileChange", changes: [{ op: "unspecified", path }] };
58
56
  }
59
57
  export const interpretGrokTool = (update) => {
60
58
  const name = nativeName(update);
61
59
  const input = object(update.rawInput);
62
60
  if (name === undefined || input === undefined)
63
61
  return undefined;
64
- return readCall(name, input)
65
- ?? contentSearchCall(name, input)
66
- ?? runCall(name, input)
67
- ?? webSearchCall(name, input)
68
- ?? fileChangeCall(name, input);
62
+ return (readCall(name, input) ??
63
+ contentSearchCall(name, input) ??
64
+ runCall(name, input) ??
65
+ webSearchCall(name, input) ??
66
+ fileChangeCall(name, input));
69
67
  };
70
68
  function optionAdmission(options) {
71
69
  if (options.network !== undefined) {
72
70
  return { kind: "refused", diagnostic: "Grok Build does not support the network option" };
73
71
  }
74
- if (options.systemPrompt !== undefined && options.systemPrompt.length > 0) {
72
+ if (options.systemPrompt !== undefined && options.systemPrompt.length > 0 && options.systemPromptMode === undefined) {
75
73
  return { kind: "refused", diagnostic: "Grok Build does not support the systemPrompt option" };
76
74
  }
77
75
  return {
78
76
  kind: "admitted",
79
77
  options,
80
- ...(options.readonly === undefined ? {} : {
81
- readonly: {
82
- enforcement: "none",
83
- diagnostic: "Grok Build cannot remove task-surface mutation capabilities",
84
- },
85
- }),
78
+ ...(options.readonly === undefined
79
+ ? {}
80
+ : {
81
+ readonly: {
82
+ enforcement: "none",
83
+ diagnostic: "Grok Build cannot remove task-surface mutation capabilities",
84
+ },
85
+ }),
86
86
  };
87
87
  }
88
+ function grokSessionMeta(config, options) {
89
+ const configured = config === undefined ? {} : { freshSessionMeta: config, loadSessionMeta: config };
90
+ if (options.systemPrompt === undefined || options.systemPrompt.length === 0)
91
+ return configured;
92
+ if (options.systemPromptMode === "append")
93
+ return { ...configured, freshSessionMeta: { ...config, rules: options.systemPrompt } };
94
+ if (options.systemPromptMode === "replace") {
95
+ const meta = { systemPromptOverride: options.systemPrompt };
96
+ return { ...configured, freshSessionMeta: { ...config, ...meta }, loadSessionMeta: { ...config, ...meta } };
97
+ }
98
+ return configured;
99
+ }
88
100
  function argv(execution, options) {
89
101
  if (execution.executable === undefined)
90
102
  throw new Error("Grok Build provider execution requires executable");
@@ -119,8 +131,6 @@ function withInterject(live) {
119
131
  export function createGrokBuildProvider(execution, dependencies = {}) {
120
132
  if (execution.executable === undefined)
121
133
  throw new TypeError("Grok Build provider execution requires executable");
122
- if (execution.config !== undefined)
123
- throw new TypeError("Grok Build provider does not support execution config");
124
134
  const drive = async (input) => {
125
135
  const launch = {
126
136
  argv: argv(execution, input.options),
@@ -129,6 +139,7 @@ export function createGrokBuildProvider(execution, dependencies = {}) {
129
139
  return withInterject(await startAcpSession(launch, input, {
130
140
  ...dependencies,
131
141
  interpretTool: interpretGrokTool,
142
+ ...grokSessionMeta(execution.config, input.options),
132
143
  }));
133
144
  };
134
145
  return {
@@ -1,27 +1,11 @@
1
1
  import { decodeProviderRecipe } from "../provider-recipe.js";
2
- import { decodeAcpConfig } from "./acp/config.js";
3
2
  export function decodeProviderExecution(input) {
4
3
  const decoded = decodeProviderRecipe(input);
5
- if ((decoded.kind === "claude-agent-sdk" || decoded.kind === "opencode-sdk") && decoded.config !== undefined) {
6
- throw new TypeError(`provider execution config is unsupported by ${decoded.kind}`);
7
- }
8
- if (decoded.kind === "pi") {
9
- if (decoded.executable !== undefined || decoded.config !== undefined) {
10
- throw new TypeError("Pi provider does not support executable or config");
11
- }
12
- if (decoded.env !== undefined && Object.keys(decoded.env).length > 0) {
13
- throw new TypeError("env injection not supported for provider pi");
14
- }
15
- }
16
- if (decoded.kind === "grok-build" && decoded.config !== undefined) {
17
- throw new TypeError("Grok Build does not support execution config");
18
- }
19
- const config = decoded.kind === "acp" ? decodeAcpConfig(decoded.config) : decoded.config;
20
4
  return Object.freeze({
21
5
  name: decoded.name,
22
6
  kind: decoded.kind,
23
7
  ...(decoded.executable === undefined ? {} : { executable: decoded.executable }),
24
- ...(config === undefined ? {} : { config }),
8
+ ...(decoded.config === undefined ? {} : { config: decoded.config }),
25
9
  ...(decoded.env === undefined ? {} : { env: decoded.env }),
26
10
  });
27
11
  }
@@ -30,9 +14,9 @@ async function adapterFor(execution) {
30
14
  return (await import("./acp/index.js")).createAcpProvider(execution);
31
15
  if (execution.kind === "claude-agent-sdk") {
32
16
  const { claudeProvider, createClaudeProvider } = await import("./claude/index.js");
33
- return execution.executable === undefined && execution.env === undefined
17
+ return execution.executable === undefined && execution.config === undefined && execution.env === undefined
34
18
  ? claudeProvider
35
- : createClaudeProvider(async () => await import("@anthropic-ai/claude-agent-sdk"), execution);
19
+ : createClaudeProvider(execution);
36
20
  }
37
21
  if (execution.kind === "codex-app-server")
38
22
  return (await import("./codex-app-server/index.js")).createCodexAppServerProvider(execution);