@astrosheep/keiyaku 4.0.0 → 4.0.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 (241) hide show
  1. package/README.md +2 -9
  2. package/build/integrations/marketplace/plugins/keiyaku/.claude-plugin/plugin.json +2 -2
  3. package/build/integrations/marketplace/plugins/keiyaku/.codex-plugin/plugin.json +4 -4
  4. package/build/integrations/marketplace/plugins/keiyaku/opencode.js +2 -2
  5. package/build/integrations/marketplace/plugins/keiyaku/package.json +2 -2
  6. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku/SKILL.md +11 -3
  7. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-akuma/SKILL.md +9 -6
  8. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-bind/SKILL.md +94 -0
  9. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-bind/agents/openai.yaml +4 -0
  10. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-task/SKILL.md +41 -6
  11. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-workflow/SKILL.md +162 -45
  12. package/build/src/akuma/akuma.d.ts +33 -25
  13. package/build/src/akuma/akuma.js +93 -61
  14. package/build/src/akuma/archetype.d.ts +8 -0
  15. package/build/src/akuma/archetype.js +28 -9
  16. package/build/src/akuma/body.js +196 -84
  17. package/build/src/akuma/coordinate.d.ts +9 -0
  18. package/build/src/akuma/coordinate.js +22 -0
  19. package/build/src/akuma/heart/facts.d.ts +67 -15
  20. package/build/src/akuma/heart/facts.js +3 -3
  21. package/build/src/akuma/heart/index.d.ts +41 -29
  22. package/build/src/akuma/heart/index.js +72 -193
  23. package/build/src/akuma/heart/rows.d.ts +30 -53
  24. package/build/src/akuma/heart/rows.js +91 -111
  25. package/build/src/akuma/heart/schema.d.ts +1 -1
  26. package/build/src/akuma/heart/schema.js +55 -8
  27. package/build/src/akuma/heart/storage.d.ts +33 -0
  28. package/build/src/akuma/heart/storage.js +164 -0
  29. package/build/src/akuma/heart/tells.d.ts +12 -0
  30. package/build/src/akuma/heart/tells.js +79 -0
  31. package/build/src/akuma/heart/timeline.d.ts +15 -0
  32. package/build/src/akuma/heart/timeline.js +86 -0
  33. package/build/src/akuma/index.d.ts +4 -2
  34. package/build/src/akuma/index.js +1 -1
  35. package/build/src/akuma/projection.d.ts +97 -0
  36. package/build/src/akuma/projection.js +145 -0
  37. package/build/src/akuma/provider.d.ts +57 -11
  38. package/build/src/akuma/provider.js +57 -37
  39. package/build/src/akuma/providers/{claude.d.ts → claude/events.d.ts} +9 -41
  40. package/build/src/akuma/providers/claude/events.js +185 -0
  41. package/build/src/akuma/providers/claude/index.d.ts +46 -0
  42. package/build/src/akuma/providers/claude/index.js +265 -0
  43. package/build/src/akuma/providers/claude/input.d.ts +13 -0
  44. package/build/src/akuma/providers/claude/input.js +109 -0
  45. package/build/src/akuma/providers/codex-app-server/events.d.ts +1 -1
  46. package/build/src/akuma/providers/codex-app-server/events.js +12 -12
  47. package/build/src/akuma/providers/codex-app-server/index.d.ts +13 -11
  48. package/build/src/akuma/providers/codex-app-server/index.js +73 -22
  49. package/build/src/akuma/providers/index.js +22 -8
  50. package/build/src/akuma/providers/opencode-sdk/events.d.ts +48 -0
  51. package/build/src/akuma/providers/opencode-sdk/events.js +116 -0
  52. package/build/src/akuma/providers/opencode-sdk/index.d.ts +32 -0
  53. package/build/src/akuma/providers/opencode-sdk/index.js +203 -0
  54. package/build/src/akuma/providers/opencode-sdk/session.d.ts +41 -0
  55. package/build/src/akuma/providers/opencode-sdk/session.js +62 -0
  56. package/build/src/akuma/providers/pi/events.d.ts +33 -0
  57. package/build/src/akuma/providers/pi/events.js +128 -0
  58. package/build/src/akuma/providers/pi/index.d.ts +11 -0
  59. package/build/src/akuma/providers/pi/index.js +162 -0
  60. package/build/src/akuma/requests.d.ts +1 -0
  61. package/build/src/akuma/requests.js +5 -2
  62. package/build/src/alias/index.d.ts +4 -3
  63. package/build/src/alias/index.js +2 -3
  64. package/build/src/body/render.js +2 -1
  65. package/build/src/body/shape.js +7 -1
  66. package/build/src/body/verification.js +19 -4
  67. package/build/src/cli/accepted.d.ts +2 -0
  68. package/build/src/cli/accepted.js +2 -1
  69. package/build/src/cli/commands/akuma-invoke.d.ts +42 -18
  70. package/build/src/cli/commands/akuma-invoke.js +94 -50
  71. package/build/src/cli/commands/akuma.d.ts +15 -7
  72. package/build/src/cli/commands/akuma.js +94 -56
  73. package/build/src/cli/commands/contract.d.ts +142 -0
  74. package/build/src/cli/commands/contract.js +14 -0
  75. package/build/src/cli/commands/install.js +2 -0
  76. package/build/src/cli/commands/task-invoke.d.ts +3 -1
  77. package/build/src/cli/commands/task-invoke.js +27 -2
  78. package/build/src/cli/commands/task.js +2 -2
  79. package/build/src/cli/invoke.d.ts +6 -1
  80. package/build/src/cli/invoke.js +241 -43
  81. package/build/src/cli/main.js +20 -1
  82. package/build/src/cli/parse.d.ts +13 -116
  83. package/build/src/cli/parse.js +51 -78
  84. package/build/src/cli/render/akuma-tool.d.ts +2 -0
  85. package/build/src/cli/render/akuma-tool.js +6 -2
  86. package/build/src/cli/render/akuma.d.ts +2 -1
  87. package/build/src/cli/render/akuma.js +157 -217
  88. package/build/src/cli/render/catalog.d.ts +2 -0
  89. package/build/src/cli/render/catalog.js +16 -0
  90. package/build/src/cli/render/contract.d.ts +1 -1
  91. package/build/src/cli/render/contract.js +38 -5
  92. package/build/src/cli/render/kanshi.js +53 -5
  93. package/build/src/cli/render/refusal.js +17 -0
  94. package/build/src/cli/render/terminal.d.ts +13 -0
  95. package/build/src/cli/render/terminal.js +75 -0
  96. package/build/src/cli/render/text.js +5 -0
  97. package/build/src/cli/result.d.ts +15 -3
  98. package/build/src/contract-worktree.d.ts +43 -0
  99. package/build/src/contract-worktree.js +213 -0
  100. package/build/src/coordination/durable-file.d.ts +3 -0
  101. package/build/src/coordination/durable-file.js +44 -1
  102. package/build/src/core/facts/codec.js +23 -4
  103. package/build/src/core/facts/eligibility.d.ts +1 -10
  104. package/build/src/core/facts/eligibility.js +0 -49
  105. package/build/src/core/facts/observation.d.ts +3 -0
  106. package/build/src/core/facts/observation.js +12 -0
  107. package/build/src/core/facts/types.d.ts +10 -3
  108. package/build/src/core/subject.js +2 -2
  109. package/build/src/core/verbs/amend.js +12 -16
  110. package/build/src/core/verbs/bind.js +2 -16
  111. package/build/src/core/verbs/deliver.js +20 -4
  112. package/build/src/core/verbs/placement.js +3 -8
  113. package/build/src/dispatch/index.d.ts +3 -1
  114. package/build/src/dispatch/index.js +14 -5
  115. package/build/src/duration.d.ts +10 -0
  116. package/build/src/duration.js +22 -0
  117. package/build/src/git/admission.d.ts +2 -2
  118. package/build/src/git/admission.js +26 -16
  119. package/build/src/git/hooks.d.ts +15 -0
  120. package/build/src/git/hooks.js +57 -5
  121. package/build/src/git/identity.d.ts +5 -1
  122. package/build/src/git/identity.js +23 -4
  123. package/build/src/git/integration.d.ts +49 -0
  124. package/build/src/git/integration.js +214 -0
  125. package/build/src/git/observe.d.ts +25 -13
  126. package/build/src/git/observe.js +175 -72
  127. package/build/src/git/read-observation.d.ts +41 -0
  128. package/build/src/git/read-observation.js +361 -0
  129. package/build/src/git/reconcile.d.ts +15 -5
  130. package/build/src/git/reconcile.js +238 -85
  131. package/build/src/git/repository.d.ts +19 -4
  132. package/build/src/git/repository.js +77 -43
  133. package/build/src/git/scratch.d.ts +13 -0
  134. package/build/src/git/scratch.js +66 -0
  135. package/build/src/git/target-placement.d.ts +56 -0
  136. package/build/src/git/target-placement.js +255 -0
  137. package/build/src/git/tender.d.ts +48 -0
  138. package/build/src/git/tender.js +82 -0
  139. package/build/src/git/terminal-seal.d.ts +24 -0
  140. package/build/src/git/terminal-seal.js +87 -0
  141. package/build/src/git/tree.d.ts +2 -2
  142. package/build/src/git/tree.js +4 -0
  143. package/build/src/git/workspace.d.ts +21 -0
  144. package/build/src/git/workspace.js +104 -0
  145. package/build/src/identity/selector.d.ts +6 -0
  146. package/build/src/identity/selector.js +19 -0
  147. package/build/src/index.d.ts +4 -2
  148. package/build/src/index.js +2 -1
  149. package/build/src/kanshi/index.d.ts +1 -1
  150. package/build/src/kanshi/read.d.ts +5 -2
  151. package/build/src/kanshi/read.js +154 -45
  152. package/build/src/kanshi/report.d.ts +31 -6
  153. package/build/src/kanshi/select.js +1 -1
  154. package/build/src/library/address.d.ts +48 -0
  155. package/build/src/library/address.js +134 -0
  156. package/build/src/library/akuma-creation.d.ts +10 -6
  157. package/build/src/library/akuma-creation.js +12 -11
  158. package/build/src/library/bind.d.ts +21 -0
  159. package/build/src/library/bind.js +56 -0
  160. package/build/src/library/catalog.d.ts +58 -0
  161. package/build/src/library/catalog.js +72 -0
  162. package/build/src/library/configuration.d.ts +6 -15
  163. package/build/src/library/configuration.js +14 -17
  164. package/build/src/library/contract.d.ts +21 -46
  165. package/build/src/library/contract.js +193 -183
  166. package/build/src/library/delivery.d.ts +23 -0
  167. package/build/src/library/delivery.js +21 -0
  168. package/build/src/library/fleet.d.ts +65 -0
  169. package/build/src/library/fleet.js +189 -0
  170. package/build/src/library/input.d.ts +3 -0
  171. package/build/src/library/input.js +19 -0
  172. package/build/src/library/keiyaku.d.ts +16 -2
  173. package/build/src/library/keiyaku.js +11 -1
  174. package/build/src/library/mutation.d.ts +38 -0
  175. package/build/src/library/mutation.js +39 -0
  176. package/build/src/library/refusal.d.ts +21 -0
  177. package/build/src/library/refusal.js +29 -0
  178. package/build/src/library/region.d.ts +2 -1
  179. package/build/src/library/region.js +3 -3
  180. package/build/src/library/repo.d.ts +4 -1
  181. package/build/src/library/repo.js +31 -16
  182. package/build/src/protocol/attempt.d.ts +16 -3
  183. package/build/src/protocol/attempt.js +39 -8
  184. package/build/src/protocol/bind.d.ts +9 -2
  185. package/build/src/protocol/bind.js +47 -39
  186. package/build/src/protocol/intent.d.ts +42 -18
  187. package/build/src/protocol/intent.js +36 -75
  188. package/build/src/protocol/operations.d.ts +93 -35
  189. package/build/src/protocol/operations.js +235 -123
  190. package/build/src/protocol/outcome.d.ts +7 -2
  191. package/build/src/protocol/outcome.js +9 -3
  192. package/build/src/protocol/placement.d.ts +30 -0
  193. package/build/src/protocol/placement.js +114 -0
  194. package/build/src/protocol/read/audit.d.ts +9 -3
  195. package/build/src/protocol/read/audit.js +25 -9
  196. package/build/src/protocol/read/documents.d.ts +2 -2
  197. package/build/src/protocol/read/documents.js +4 -4
  198. package/build/src/protocol/read/status.d.ts +11 -5
  199. package/build/src/protocol/read/status.js +28 -15
  200. package/build/src/protocol/run.d.ts +49 -7
  201. package/build/src/protocol/run.js +53 -25
  202. package/build/src/runtime/proc/line-rpc.d.ts +1 -0
  203. package/build/src/runtime/proc/line-rpc.js +21 -0
  204. package/build/src/runtime/proc/run.d.ts +18 -2
  205. package/build/src/runtime/proc/run.js +34 -8
  206. package/build/src/settings.d.ts +6 -0
  207. package/build/src/settings.js +29 -14
  208. package/build/src/settlement/fence.d.ts +9 -0
  209. package/build/src/settlement/fence.js +23 -0
  210. package/build/src/settlement/holder.d.ts +25 -4
  211. package/build/src/settlement/holder.js +102 -28
  212. package/build/src/settlement/settle.d.ts +8 -0
  213. package/build/src/settlement/settle.js +102 -28
  214. package/build/src/task/board.d.ts +20 -2
  215. package/build/src/task/board.js +11 -1
  216. package/build/src/task/compose.d.ts +2 -2
  217. package/build/src/task/compose.js +2 -2
  218. package/build/src/task/context.js +2 -7
  219. package/build/src/task/index.d.ts +9 -9
  220. package/build/src/task/index.js +15 -12
  221. package/build/src/task/operations.d.ts +31 -12
  222. package/build/src/task/operations.js +8 -4
  223. package/build/src/task/store.d.ts +4 -6
  224. package/build/src/task/store.js +3 -3
  225. package/build/src/verification/declaration.d.ts +1 -0
  226. package/build/src/verification/execution.d.ts +49 -0
  227. package/build/src/verification/execution.js +104 -0
  228. package/build/src/world.d.ts +13 -0
  229. package/build/src/world.js +103 -0
  230. package/package.json +7 -4
  231. package/build/src/akuma/activity.d.ts +0 -66
  232. package/build/src/akuma/activity.js +0 -139
  233. package/build/src/akuma/providers/claude.js +0 -305
  234. package/build/src/context-root.d.ts +0 -4
  235. package/build/src/context-root.js +0 -15
  236. package/build/src/git/delivery.d.ts +0 -20
  237. package/build/src/git/delivery.js +0 -109
  238. package/build/src/git/verification.d.ts +0 -14
  239. package/build/src/git/verification.js +0 -56
  240. package/build/src/verification/producer.d.ts +0 -23
  241. package/build/src/verification/producer.js +0 -54
@@ -1,3 +1,4 @@
1
+ import { decodeResumeCoordinate, encodeResumeCoordinate } from "./coordinate.js";
1
2
  export const AKUMA_REQUESTS_ENV = "AKUMA_REQUESTS";
2
3
  export const AGENT_EVENT_TEXT_LIMIT = 16_384;
3
4
  export const AGENT_THOUGHT_TEXT_LIMIT = 4_000;
@@ -14,6 +15,7 @@ function object(value) {
14
15
  ? value
15
16
  : null;
16
17
  }
18
+ export { decodeResumeCoordinate, encodeResumeCoordinate };
17
19
  function optionText(options, field, blank) {
18
20
  const selected = options[field];
19
21
  if (selected === undefined)
@@ -106,27 +108,34 @@ function decodeToolResult(value) {
106
108
  };
107
109
  }
108
110
  function decodeToolEvent(event) {
111
+ if (event.truncated !== undefined && event.truncated !== true)
112
+ return null;
109
113
  if (typeof event.id !== "string" || typeof event.name !== "string")
110
114
  return null;
111
115
  const call = decodeToolCall(event.call);
112
116
  if (call !== null && event.phase === "started" && event.result === undefined) {
113
- return { type: "tool", phase: "started", id: event.id, name: event.name, call };
117
+ return { type: "tool", phase: "started", id: event.id, name: event.name, call,
118
+ ...(event.truncated === true ? { truncated: true } : {}) };
114
119
  }
115
120
  const result = decodeToolResult(event.result);
116
121
  if (call !== null && event.phase === "completed" && result !== null) {
117
- return { type: "tool", phase: "completed", id: event.id, name: event.name, call, result };
122
+ return { type: "tool", phase: "completed", id: event.id, name: event.name, call, result,
123
+ ...(event.truncated === true ? { truncated: true } : {}) };
118
124
  }
119
125
  return null;
120
126
  }
121
127
  function decodeTypedEvent(type, event) {
128
+ if (type !== "session" && event.truncated !== undefined && event.truncated !== true)
129
+ return null;
130
+ const truncated = event.truncated === true ? { truncated: true } : {};
122
131
  switch (type) {
123
132
  case "assistant":
124
- case "thought": return typeof event.text === "string" ? { type, text: event.text } : null;
125
- case "note": return typeof event.text === "string" ? { type, text: event.text } : null;
126
- case "unknown": return typeof event.kind === "string" ? { type, kind: event.kind } : null;
133
+ case "thought": return typeof event.text === "string" ? { type, text: event.text, ...truncated } : null;
134
+ case "note": return typeof event.text === "string" ? { type, text: event.text, ...truncated } : null;
135
+ case "unknown": return typeof event.kind === "string" ? { type, kind: event.kind, ...truncated } : null;
127
136
  case "session": {
128
- const coordinate = object(event.coordinate);
129
- return typeof coordinate?.sessionId === "string" ? { type, coordinate: { sessionId: coordinate.sessionId } } : null;
137
+ const coordinate = decodeResumeCoordinate(event.coordinate);
138
+ return coordinate === null ? null : { type, coordinate };
130
139
  }
131
140
  case "tool": return decodeToolEvent(event);
132
141
  default: return type;
@@ -143,50 +152,61 @@ export function decodeAgentEvent(value) {
143
152
  }
144
153
  function boundedToolCall(call) {
145
154
  switch (call.kind) {
146
- case "run": return { kind: call.kind, command: boundedEventText(call.command) };
147
- case "read": return { kind: call.kind, path: boundedEventText(call.path) };
148
- case "search": return { kind: call.kind, query: boundedEventText(call.query) };
155
+ case "run": return { value: { kind: call.kind, command: boundedEventText(call.command) }, truncated: call.command.length > AGENT_EVENT_TEXT_LIMIT };
156
+ case "read": return { value: { kind: call.kind, path: boundedEventText(call.path) }, truncated: call.path.length > AGENT_EVENT_TEXT_LIMIT };
157
+ case "search": return { value: { kind: call.kind, query: boundedEventText(call.query) }, truncated: call.query.length > AGENT_EVENT_TEXT_LIMIT };
149
158
  case "fileChange": return {
150
- kind: call.kind,
151
- changes: call.changes.map((change) => ({
152
- ...change,
153
- path: boundedEventText(change.path),
154
- })),
159
+ value: {
160
+ kind: call.kind,
161
+ changes: call.changes.map((change) => ({ ...change, path: boundedEventText(change.path) })),
162
+ },
163
+ truncated: call.changes.some((change) => change.path.length > AGENT_EVENT_TEXT_LIMIT),
155
164
  };
156
- case "other": return { kind: call.kind, display: boundedEventText(call.display) };
165
+ case "other": return { value: { kind: call.kind, display: boundedEventText(call.display) }, truncated: call.display.length > AGENT_EVENT_TEXT_LIMIT };
157
166
  default: return call;
158
167
  }
159
168
  }
160
169
  function boundedToolResult(result) {
161
170
  return {
162
- status: result.status,
163
- ...(result.message === undefined ? {} : { message: boundedEventText(result.message) }),
164
- ...(result.exitCode === undefined ? {} : { exitCode: result.exitCode }),
171
+ value: {
172
+ status: result.status,
173
+ ...(result.message === undefined ? {} : { message: boundedEventText(result.message) }),
174
+ ...(result.exitCode === undefined ? {} : { exitCode: result.exitCode }),
175
+ },
176
+ truncated: result.message !== undefined && result.message.length > AGENT_EVENT_TEXT_LIMIT,
165
177
  };
166
178
  }
167
179
  export function encodeAgentEvent(event) {
180
+ const marked = (value, changed) => ({
181
+ ...value,
182
+ ...(changed || ("truncated" in event && event.truncated === true) ? { truncated: true } : {}),
183
+ });
168
184
  switch (event.type) {
169
- case "session": return { type: event.type, coordinate: { sessionId: event.coordinate.sessionId } };
170
- case "assistant": return { type: event.type, text: boundedEventText(event.text) };
171
- case "thought": return { type: event.type, text: boundedThoughtText(event.text) };
172
- case "note": return { type: event.type, text: boundedEventText(event.text) };
173
- case "unknown": return { type: event.type, kind: boundedEventText(event.kind) };
174
- case "tool": return event.phase === "started"
175
- ? {
185
+ case "session": return { type: event.type, coordinate: encodeResumeCoordinate(event.coordinate) };
186
+ case "assistant": return marked({ type: event.type, text: boundedEventText(event.text) }, event.text.length > AGENT_EVENT_TEXT_LIMIT);
187
+ case "thought": return marked({ type: event.type, text: boundedThoughtText(event.text) }, event.text.length > AGENT_THOUGHT_TEXT_LIMIT);
188
+ case "note": return marked({ type: event.type, text: boundedEventText(event.text) }, event.text.length > AGENT_EVENT_TEXT_LIMIT);
189
+ case "unknown": return marked({ type: event.type, kind: boundedEventText(event.kind) }, event.kind.length > AGENT_EVENT_TEXT_LIMIT);
190
+ case "tool": {
191
+ const call = boundedToolCall(event.call);
192
+ const name = boundedEventText(event.name);
193
+ const result = event.phase === "completed" ? boundedToolResult(event.result) : undefined;
194
+ return marked(event.phase === "started" ? {
176
195
  type: event.type,
177
196
  id: event.id,
178
197
  phase: event.phase,
179
- name: boundedEventText(event.name),
180
- call: boundedToolCall(event.call),
198
+ name,
199
+ call: call.value,
181
200
  }
182
- : {
183
- type: event.type,
184
- id: event.id,
185
- phase: event.phase,
186
- name: boundedEventText(event.name),
187
- call: boundedToolCall(event.call),
188
- result: boundedToolResult(event.result),
189
- };
201
+ : {
202
+ type: event.type,
203
+ id: event.id,
204
+ phase: event.phase,
205
+ name,
206
+ call: call.value,
207
+ result: result.value,
208
+ }, name !== event.name || call.truncated || result?.truncated === true);
209
+ }
190
210
  default: return event;
191
211
  }
192
212
  }
@@ -197,7 +217,7 @@ export function boundedThoughtText(value) {
197
217
  return value.slice(0, AGENT_THOUGHT_TEXT_LIMIT);
198
218
  }
199
219
  export function noteEvent(note) {
200
- return { type: "note", text: boundedEventText(note.replace(/\s+/g, " ").trim()) };
220
+ return { type: "note", text: note.replace(/\s+/g, " ").trim() };
201
221
  }
202
222
  export function unknownEvent(kind) {
203
223
  return { type: "unknown", kind };
@@ -1,5 +1,11 @@
1
- import type { Options, Query } from "@anthropic-ai/claude-agent-sdk";
2
- import { type Drive, type ProviderAdapter, type ProviderOptions } from "../provider.js";
1
+ import type { SDKMessage } from "@anthropic-ai/claude-agent-sdk";
2
+ import { AgentEventChannel, type ToolCall } from "../../provider.js";
3
+ export type ClaudeObservationState = {
4
+ tools: Map<string, Readonly<{
5
+ name: string;
6
+ call: ToolCall;
7
+ }>>;
8
+ };
3
9
  export declare const CLAUDE_MESSAGE_DISPOSITIONS: {
4
10
  readonly assistant: "assistant";
5
11
  readonly auth_status: "auth";
@@ -43,42 +49,4 @@ export declare const CLAUDE_SYSTEM_DISPOSITIONS: {
43
49
  readonly thinking_tokens: "drop";
44
50
  readonly worker_shutting_down: "note";
45
51
  };
46
- export type ClaudeSdk = Readonly<{
47
- query(input: Readonly<{
48
- prompt: string;
49
- options?: Options;
50
- }>): Query;
51
- forkSession?(sessionId: string, options: Readonly<{
52
- dir: string;
53
- upToMessageId: string;
54
- }>): Promise<Readonly<{
55
- sessionId: string;
56
- }>>;
57
- }>;
58
- export declare function createClaudeProvider(load: () => Promise<ClaudeSdk>, execution?: Readonly<{
59
- executable?: string;
60
- env?: Readonly<Record<string, string>>;
61
- }>): ProviderAdapter;
62
- export declare const claudeProvider: Readonly<{
63
- confinement(input: Readonly<{
64
- cwd: string;
65
- options: ProviderOptions;
66
- }>): import("../index.js").Confinement;
67
- admitOptions(options: ProviderOptions): import("../provider.js").ProviderOptionAdmission;
68
- fork?(input: Readonly<{
69
- session: import("../provider.js").ResumeCoordinate;
70
- at: string;
71
- cwd: string;
72
- }>): Promise<Readonly<{
73
- session: import("../provider.js").ResumeCoordinate;
74
- }>>;
75
- start(input: Readonly<{
76
- prompt: string;
77
- cwd: string;
78
- options: ProviderOptions;
79
- session?: import("../provider.js").ResumeCoordinate;
80
- requests?: Readonly<{
81
- dir: string;
82
- }>;
83
- }>): Promise<Drive>;
84
- }>;
52
+ export declare function emitClaudeMessage(message: SDKMessage, events: AgentEventChannel, state: ClaudeObservationState): void;
@@ -0,0 +1,185 @@
1
+ import { noteEvent, unknownEvent, } from "../../provider.js";
2
+ export const CLAUDE_MESSAGE_DISPOSITIONS = {
3
+ assistant: "assistant",
4
+ auth_status: "auth",
5
+ conversation_reset: "note",
6
+ prompt_suggestion: "drop",
7
+ rate_limit_event: "drop",
8
+ result: "terminal",
9
+ stream_event: "drop",
10
+ system: "system",
11
+ tool_progress: "drop",
12
+ tool_use_summary: "drop",
13
+ user: "tool-results",
14
+ };
15
+ export const CLAUDE_SYSTEM_DISPOSITIONS = {
16
+ api_retry: "note",
17
+ background_tasks_changed: "note",
18
+ commands_changed: "drop",
19
+ compact_boundary: "drop",
20
+ control_request_progress: "control-progress",
21
+ elicitation_complete: "drop",
22
+ files_persisted: "note",
23
+ hook_progress: "drop",
24
+ hook_response: "drop",
25
+ hook_started: "note",
26
+ informational: "note",
27
+ init: "drop",
28
+ local_command_output: "drop",
29
+ memory_recall: "drop",
30
+ mirror_error: "note",
31
+ model_refusal_fallback: "note",
32
+ model_refusal_no_fallback: "note",
33
+ notification: "note",
34
+ permission_denied: "note",
35
+ plugin_install: "note",
36
+ session_state_changed: "drop",
37
+ status: "note",
38
+ task_notification: "note",
39
+ task_progress: "note",
40
+ task_started: "note",
41
+ task_updated: "note",
42
+ thinking_tokens: "drop",
43
+ worker_shutting_down: "note",
44
+ };
45
+ function object(value) {
46
+ return value !== null && typeof value === "object" && !Array.isArray(value)
47
+ ? value
48
+ : undefined;
49
+ }
50
+ function nonblank(value) {
51
+ return typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
52
+ }
53
+ function number(value) {
54
+ return typeof value === "number" && Number.isFinite(value) ? value : undefined;
55
+ }
56
+ const CLAUDE_SYSTEM_NOTES = {
57
+ api_retry: (message) => {
58
+ const attempt = number(message.attempt);
59
+ const maximum = number(message.max_retries);
60
+ return attempt === undefined || maximum === undefined
61
+ ? "Retrying request"
62
+ : `Retrying request ${attempt}/${maximum}`;
63
+ },
64
+ background_tasks_changed: (message) => `Background tasks: ${Array.isArray(message.tasks) ? message.tasks.length : 0}`,
65
+ files_persisted: (message) => {
66
+ const files = Array.isArray(message.files) ? message.files.length : 0;
67
+ const failed = Array.isArray(message.failed) ? message.failed.length : 0;
68
+ return failed === 0 ? `Persisted ${files} files` : `Persisted ${files} files; ${failed} failed`;
69
+ },
70
+ hook_started: (message) => `Hook ${nonblank(message.hook_name) ?? "unknown"} started`,
71
+ informational: (message) => nonblank(message.content) ?? "Informational notice",
72
+ mirror_error: (message) => `Transcript mirror warning: ${nonblank(message.error) ?? nonblank(message.message) ?? "unknown error"}`,
73
+ model_refusal_fallback: () => "Model refusal; using fallback",
74
+ model_refusal_no_fallback: () => "Model refusal; no fallback available",
75
+ notification: (message) => nonblank(message.message) ?? nonblank(message.content) ?? "Notification",
76
+ permission_denied: (message) => `Permission refused${nonblank(message.message) === undefined ? "" : `: ${nonblank(message.message)}`}`,
77
+ plugin_install: (message) => `Plugin install ${nonblank(message.status) ?? "updated"}${nonblank(message.name) === undefined ? "" : `: ${nonblank(message.name)}`}`,
78
+ status: (message) => `Status: ${nonblank(message.status) ?? "idle"}${nonblank(message.error) === undefined ? "" : ` (${nonblank(message.error)})`}`,
79
+ task_notification: (message) => `Task ${nonblank(message.task_id) ?? "unknown"} ${nonblank(message.status) ?? "updated"}`,
80
+ task_progress: (message) => nonblank(message.description) ?? `Task ${nonblank(message.task_id) ?? "unknown"} progressed`,
81
+ task_started: (message) => nonblank(message.description) ?? `Task ${nonblank(message.task_id) ?? "unknown"} started`,
82
+ task_updated: (message) => `Task ${nonblank(message.task_id) ?? "unknown"} updated`,
83
+ worker_shutting_down: (message) => `Worker stopping: ${nonblank(message.reason) ?? "unknown reason"}`,
84
+ };
85
+ function toolCall(name, input) {
86
+ const value = object(input) ?? {};
87
+ const command = nonblank(value.command);
88
+ if (command !== undefined)
89
+ return { kind: "run", command };
90
+ const path = nonblank(value.file_path) ?? nonblank(value.path);
91
+ if (/^(?:read|view)/iu.test(name) && path !== undefined)
92
+ return { kind: "read", path };
93
+ const query = nonblank(value.query) ?? nonblank(value.pattern);
94
+ if (/search|grep|glob/iu.test(name) && query !== undefined)
95
+ return { kind: "search", query };
96
+ if (/write/iu.test(name) && path !== undefined)
97
+ return { kind: "fileChange", changes: [{ op: "add", path }] };
98
+ if (/edit|notebook/iu.test(name) && path !== undefined)
99
+ return { kind: "fileChange", changes: [{ op: "update", path }] };
100
+ return { kind: "other", display: name };
101
+ }
102
+ function assistantEvents(message, events, state) {
103
+ if (message.aborted === true)
104
+ return;
105
+ if (message.error !== undefined) {
106
+ events.emit(noteEvent(`Assistant error: ${message.error}`));
107
+ return;
108
+ }
109
+ const text = message.message.content
110
+ .filter((block) => block.type === "text")
111
+ .map((block) => block.text).join("");
112
+ if (text.length > 0)
113
+ events.emit({ type: "assistant", text });
114
+ for (const block of message.message.content) {
115
+ const value = object(block);
116
+ if (value?.type === "thinking" && typeof value.thinking === "string" && value.thinking.trim().length > 0) {
117
+ events.emit({ type: "thought", text: value.thinking });
118
+ continue;
119
+ }
120
+ if (block.type !== "tool_use")
121
+ continue;
122
+ const call = toolCall(block.name, block.input);
123
+ state.tools.set(block.id, { name: block.name, call });
124
+ events.emit({ type: "tool", phase: "started", id: block.id, name: block.name, call });
125
+ }
126
+ }
127
+ function toolResultEvents(message, events, state) {
128
+ const content = object(message.message)?.content;
129
+ if (!Array.isArray(content))
130
+ return;
131
+ for (const block of content) {
132
+ const value = object(block);
133
+ if (value?.type !== "tool_result")
134
+ continue;
135
+ const id = nonblank(value.tool_use_id);
136
+ if (id === undefined)
137
+ continue;
138
+ const observed = state.tools.get(id);
139
+ if (observed === undefined)
140
+ continue;
141
+ state.tools.delete(id);
142
+ events.emit({
143
+ type: "tool", phase: "completed", id, name: observed.name, call: observed.call,
144
+ result: { status: value.is_error === true ? "error" : "ok" },
145
+ });
146
+ }
147
+ }
148
+ function emitSystemMessage(value, events) {
149
+ const subtype = nonblank(value?.subtype) ?? "unknown";
150
+ if (!Object.hasOwn(CLAUDE_SYSTEM_DISPOSITIONS, subtype)) {
151
+ events.emit(unknownEvent(subtype));
152
+ return;
153
+ }
154
+ const systemDisposition = CLAUDE_SYSTEM_DISPOSITIONS[subtype];
155
+ if (systemDisposition === "drop")
156
+ return;
157
+ if (systemDisposition === "control-progress" && value?.status !== "api_retry")
158
+ return;
159
+ const note = CLAUDE_SYSTEM_NOTES[subtype];
160
+ events.emit(noteEvent(note?.(value ?? {}) ?? subtype));
161
+ }
162
+ export function emitClaudeMessage(message, events, state) {
163
+ const value = object(message) ?? {};
164
+ const kind = nonblank(value.type) ?? "unknown";
165
+ if (!Object.hasOwn(CLAUDE_MESSAGE_DISPOSITIONS, kind))
166
+ return events.emit(unknownEvent(kind));
167
+ const disposition = CLAUDE_MESSAGE_DISPOSITIONS[kind];
168
+ if (disposition === "assistant") {
169
+ assistantEvents(message, events, state);
170
+ }
171
+ else if (disposition === "tool-results") {
172
+ toolResultEvents(message, events, state);
173
+ }
174
+ else if (disposition === "auth") {
175
+ const error = nonblank(value.error);
176
+ if (error !== undefined)
177
+ events.emit(noteEvent(`Authentication warning: ${error}`));
178
+ }
179
+ else if (disposition === "note") {
180
+ events.emit(noteEvent("Conversation reset"));
181
+ }
182
+ else if (disposition === "system") {
183
+ emitSystemMessage(value, events);
184
+ }
185
+ }
@@ -0,0 +1,46 @@
1
+ import type { Options, Query, SDKUserMessage } from "@anthropic-ai/claude-agent-sdk";
2
+ import { type ProviderAdapter, type ProviderOptions, type Session } from "../../provider.js";
3
+ import type { ResumeCoordinate } from "../../provider.js";
4
+ export { CLAUDE_MESSAGE_DISPOSITIONS, CLAUDE_SYSTEM_DISPOSITIONS } from "./events.js";
5
+ type ClaudeExecution = Readonly<{
6
+ executable?: string;
7
+ env?: Readonly<Record<string, string>>;
8
+ }>;
9
+ export type ClaudeSdk = Readonly<{
10
+ query(input: Readonly<{
11
+ prompt: string | AsyncIterable<SDKUserMessage>;
12
+ options?: Options;
13
+ }>): Query;
14
+ forkSession?(sessionId: string, options: Readonly<{
15
+ dir: string;
16
+ upToMessageId: string;
17
+ }>): Promise<Readonly<{
18
+ sessionId: string;
19
+ }>>;
20
+ }>;
21
+ export declare function createClaudeProvider(load: () => Promise<ClaudeSdk>, execution?: ClaudeExecution): ProviderAdapter;
22
+ export declare const claudeProvider: Readonly<{
23
+ confinement(input: Readonly<{
24
+ cwd: string;
25
+ options: ProviderOptions;
26
+ }>): import("../../index.js").Confinement;
27
+ admitOptions(options: ProviderOptions): import("../../provider.js").ProviderOptionAdmission;
28
+ fork?(input: Readonly<{
29
+ session: ResumeCoordinate;
30
+ at: string;
31
+ cwd: string;
32
+ }>): Promise<Readonly<{
33
+ session: ResumeCoordinate;
34
+ }>>;
35
+ start(input: import("../../provider.js").DriveInput & Readonly<{
36
+ session: Readonly<{
37
+ kind: "fresh";
38
+ }>;
39
+ }>): Promise<Session>;
40
+ resume?(input: import("../../provider.js").DriveInput & Readonly<{
41
+ session: Readonly<{
42
+ kind: "resume";
43
+ coordinate: ResumeCoordinate;
44
+ }>;
45
+ }>): Promise<Session>;
46
+ }>;