@arnilo/prism-hosts 0.0.0-stage → 0.13.0

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 (322) hide show
  1. package/CHANGELOG.md +394 -0
  2. package/LICENSE +21 -0
  3. package/README.md +34 -2
  4. package/acp/README.md +87 -0
  5. package/acp/src/capabilities.ts +184 -0
  6. package/acp/src/errors.ts +24 -0
  7. package/acp/src/host.ts +36 -0
  8. package/acp/src/index.ts +25 -0
  9. package/acp/src/limits.ts +49 -0
  10. package/acp/src/mapper.ts +419 -0
  11. package/acp/src/permission.ts +37 -0
  12. package/acp/src/projection.ts +39 -0
  13. package/acp/src/prompt.ts +170 -0
  14. package/acp/src/serve.ts +345 -0
  15. package/acp/src/session-map.ts +49 -0
  16. package/ag-ui/README.md +56 -0
  17. package/ag-ui/src/a2ui.ts +570 -0
  18. package/ag-ui/src/ag-ui-mapper.ts +507 -0
  19. package/ag-ui/src/encrypted-value.ts +40 -0
  20. package/ag-ui/src/errors.ts +29 -0
  21. package/ag-ui/src/handler.ts +642 -0
  22. package/ag-ui/src/index.ts +177 -0
  23. package/ag-ui/src/input.ts +190 -0
  24. package/ag-ui/src/limits.ts +279 -0
  25. package/ag-ui/src/mcp-apps.ts +256 -0
  26. package/ag-ui/src/mcp.ts +94 -0
  27. package/ag-ui/src/projection.ts +201 -0
  28. package/ag-ui/src/projectors.ts +272 -0
  29. package/ag-ui/src/renderer/bind.ts +152 -0
  30. package/ag-ui/src/renderer/core.ts +270 -0
  31. package/ag-ui/src/renderer/index.ts +165 -0
  32. package/ag-ui/src/replay.ts +189 -0
  33. package/ag-ui/src/types.ts +66 -0
  34. package/channels/README.md +139 -0
  35. package/channels/src/admission.ts +8 -0
  36. package/channels/src/approvals.ts +262 -0
  37. package/channels/src/checkpoint-contract.ts +97 -0
  38. package/channels/src/delivery.ts +116 -0
  39. package/channels/src/host-ui.ts +356 -0
  40. package/channels/src/identity.ts +46 -0
  41. package/channels/src/index.ts +82 -0
  42. package/channels/src/limits.ts +49 -0
  43. package/channels/src/memory-stores.ts +112 -0
  44. package/channels/src/pairing.ts +178 -0
  45. package/channels/src/runtime-admit.ts +389 -0
  46. package/channels/src/runtime-core.ts +621 -0
  47. package/channels/src/runtime-reconcile.ts +299 -0
  48. package/channels/src/runtime-turn.ts +664 -0
  49. package/channels/src/runtime-types.ts +95 -0
  50. package/channels/src/runtime.ts +86 -0
  51. package/channels/src/secret-ref.ts +42 -0
  52. package/channels/src/signal.ts +790 -0
  53. package/channels/src/state.ts +355 -0
  54. package/channels/src/telegram.ts +1317 -0
  55. package/channels/src/types.ts +442 -0
  56. package/devtools/README.md +92 -0
  57. package/devtools/bin/prism-devtools.ts +63 -0
  58. package/devtools/src/args.ts +71 -0
  59. package/devtools/src/bun.d.ts +27 -0
  60. package/devtools/src/compare.ts +190 -0
  61. package/devtools/src/errors.ts +15 -0
  62. package/devtools/src/index.ts +25 -0
  63. package/devtools/src/replay.ts +36 -0
  64. package/devtools/src/security.ts +80 -0
  65. package/devtools/src/serve.ts +259 -0
  66. package/devtools/src/ui/assets.ts +108 -0
  67. package/devtools/src/ui/inspector.ts +182 -0
  68. package/driver-process/README.md +197 -0
  69. package/driver-process/src/abort.ts +74 -0
  70. package/driver-process/src/adapter.ts +211 -0
  71. package/driver-process/src/driver.ts +303 -0
  72. package/driver-process/src/errors.ts +17 -0
  73. package/driver-process/src/extend.ts +72 -0
  74. package/driver-process/src/index.ts +5 -0
  75. package/driver-process/src/inspect.ts +33 -0
  76. package/driver-process/src/session.ts +72 -0
  77. package/driver-process/src/testing.ts +394 -0
  78. package/driver-process/src/transports/json-rpc.ts +147 -0
  79. package/driver-process/src/transports/jsonl-stream.ts +12 -0
  80. package/driver-process/src/transports/types.ts +11 -0
  81. package/driver-process/src/turn.ts +106 -0
  82. package/evals/README.md +843 -0
  83. package/evals/src/calibration.ts +179 -0
  84. package/evals/src/citation-integrity.ts +98 -0
  85. package/evals/src/citations.ts +45 -0
  86. package/evals/src/compare-experiments.ts +153 -0
  87. package/evals/src/comparison.ts +230 -0
  88. package/evals/src/curate.ts +257 -0
  89. package/evals/src/dataset.ts +81 -0
  90. package/evals/src/erp-invariants.ts +163 -0
  91. package/evals/src/errors.ts +23 -0
  92. package/evals/src/experiment.ts +537 -0
  93. package/evals/src/failure-injection.ts +77 -0
  94. package/evals/src/feedback.ts +53 -0
  95. package/evals/src/index.ts +198 -0
  96. package/evals/src/injection.ts +247 -0
  97. package/evals/src/judge-panel.ts +109 -0
  98. package/evals/src/judge.ts +89 -0
  99. package/evals/src/limits.ts +50 -0
  100. package/evals/src/report-record.ts +47 -0
  101. package/evals/src/rubric-judge.ts +334 -0
  102. package/evals/src/scenario-runner.ts +317 -0
  103. package/evals/src/scenarios.ts +81 -0
  104. package/evals/src/score.ts +328 -0
  105. package/evals/src/scorer.ts +21 -0
  106. package/evals/src/state-match.ts +130 -0
  107. package/evals/src/stats.ts +635 -0
  108. package/evals/src/threshold.ts +117 -0
  109. package/evals/src/timeline.ts +38 -0
  110. package/evals/src/toolless-session.ts +33 -0
  111. package/evals/src/trace.ts +80 -0
  112. package/evals/src/trajectory.ts +623 -0
  113. package/evals/src/types.ts +672 -0
  114. package/evals/src/user-simulator.ts +101 -0
  115. package/evals/src/util.ts +207 -0
  116. package/headless/README.md +172 -0
  117. package/headless/src/answers.ts +91 -0
  118. package/headless/src/authority.ts +32 -0
  119. package/headless/src/errors.ts +36 -0
  120. package/headless/src/index.ts +17 -0
  121. package/headless/src/limits.ts +11 -0
  122. package/headless/src/pending.ts +16 -0
  123. package/headless/src/policy.ts +36 -0
  124. package/headless/src/resume.ts +103 -0
  125. package/headless/src/route.ts +153 -0
  126. package/headless/src/scheduler/clock.ts +22 -0
  127. package/headless/src/scheduler/cron.ts +19 -0
  128. package/headless/src/scheduler/firing.ts +58 -0
  129. package/headless/src/scheduler/index.ts +399 -0
  130. package/headless/src/scheduler/lease.ts +38 -0
  131. package/headless/src/scheduler/missed.ts +12 -0
  132. package/headless/src/scheduler/state.ts +132 -0
  133. package/host-builder/README.md +251 -0
  134. package/host-builder/bin/prism-host-builder.ts +169 -0
  135. package/host-builder/data/api.json +6167 -0
  136. package/host-builder/data/errors.json +546 -0
  137. package/host-builder/data/examples/acp.ts +63 -0
  138. package/host-builder/data/examples/adapters/conformance.ts +34 -0
  139. package/host-builder/data/examples/adapters/fixtures/rpc-server.json +26 -0
  140. package/host-builder/data/examples/adapters/fixtures/stream-cli.json +27 -0
  141. package/host-builder/data/examples/adapters/fixtures/workspace-config.json +28 -0
  142. package/host-builder/data/examples/adapters/rpc-server.dialect.ts +218 -0
  143. package/host-builder/data/examples/adapters/rpc-server.ts +309 -0
  144. package/host-builder/data/examples/adapters/stream-cli.dialect.ts +165 -0
  145. package/host-builder/data/examples/adapters/stream-cli.ts +256 -0
  146. package/host-builder/data/examples/adapters/workspace-config.dialect.ts +172 -0
  147. package/host-builder/data/examples/adapters/workspace-config.ts +251 -0
  148. package/host-builder/data/examples/advisor.ts +94 -0
  149. package/host-builder/data/examples/ag-ui-a2ui.ts +80 -0
  150. package/host-builder/data/examples/ag-ui-mcp-apps.ts +44 -0
  151. package/host-builder/data/examples/ag-ui-server.ts +118 -0
  152. package/host-builder/data/examples/agent-durable-approval.ts +43 -0
  153. package/host-builder/data/examples/api-key-auth.ts +23 -0
  154. package/host-builder/data/examples/approval.ts +92 -0
  155. package/host-builder/data/examples/attention-compiler.ts +81 -0
  156. package/host-builder/data/examples/autonomous-coding-loop.ts +343 -0
  157. package/host-builder/data/examples/behavior-evaluation.ts +303 -0
  158. package/host-builder/data/examples/build-workflow.ts +334 -0
  159. package/host-builder/data/examples/cache-aware-prompt-assembly.ts +139 -0
  160. package/host-builder/data/examples/caveman-ponytail.ts +197 -0
  161. package/host-builder/data/examples/cli.ts +31 -0
  162. package/host-builder/data/examples/coding-approval.ts +115 -0
  163. package/host-builder/data/examples/coding-browser-evaluation.ts +208 -0
  164. package/host-builder/data/examples/coding-compaction.ts +30 -0
  165. package/host-builder/data/examples/coding-goal-verify.ts +121 -0
  166. package/host-builder/data/examples/coding-tools-capability-gaps.ts +75 -0
  167. package/host-builder/data/examples/compaction.ts +36 -0
  168. package/host-builder/data/examples/connected-slack-mcp.ts +67 -0
  169. package/host-builder/data/examples/context.ts +29 -0
  170. package/host-builder/data/examples/custom-adapter.ts +256 -0
  171. package/host-builder/data/examples/custom-builders.ts +66 -0
  172. package/host-builder/data/examples/custom-loop.ts +89 -0
  173. package/host-builder/data/examples/custom-provider.ts +70 -0
  174. package/host-builder/data/examples/custom-session-store.ts +72 -0
  175. package/host-builder/data/examples/custom-tools-skills-context.ts +97 -0
  176. package/host-builder/data/examples/decision-models.ts +98 -0
  177. package/host-builder/data/examples/define-package.ts +188 -0
  178. package/host-builder/data/examples/delegate.ts +200 -0
  179. package/host-builder/data/examples/discover-skills.ts +65 -0
  180. package/host-builder/data/examples/drive-rag-sync.ts +44 -0
  181. package/host-builder/data/examples/durable-approval.ts +139 -0
  182. package/host-builder/data/examples/durable-investigation.ts +93 -0
  183. package/host-builder/data/examples/durable-loops-and-approvals.ts +94 -0
  184. package/host-builder/data/examples/enterprise-identity.ts +21 -0
  185. package/host-builder/data/examples/enterprise-policy-audit.ts +50 -0
  186. package/host-builder/data/examples/enterprise-work-connectors.ts +103 -0
  187. package/host-builder/data/examples/eval-injection.ts +73 -0
  188. package/host-builder/data/examples/eval-judges.ts +145 -0
  189. package/host-builder/data/examples/evals.ts +86 -0
  190. package/host-builder/data/examples/evaluation-gate.ts +40 -0
  191. package/host-builder/data/examples/execution-timeline.ts +173 -0
  192. package/host-builder/data/examples/external-agent.ts +541 -0
  193. package/host-builder/data/examples/external-app-db-backed.ts +344 -0
  194. package/host-builder/data/examples/governance-deny.ts +122 -0
  195. package/host-builder/data/examples/guardrail-packs.ts +240 -0
  196. package/host-builder/data/examples/headless-host.ts +245 -0
  197. package/host-builder/data/examples/hooks-audit-command.mjs +31 -0
  198. package/host-builder/data/examples/hooks-json.ts +87 -0
  199. package/host-builder/data/examples/host-builder-agent.ts +150 -0
  200. package/host-builder/data/examples/host-hooks.ts +71 -0
  201. package/host-builder/data/examples/host-step-loop-timeline.ts +212 -0
  202. package/host-builder/data/examples/hosted-sandbox.ts +48 -0
  203. package/host-builder/data/examples/instruction-injection.ts +127 -0
  204. package/host-builder/data/examples/jsonl-stores-branching.ts +49 -0
  205. package/host-builder/data/examples/long-term-memory.ts +158 -0
  206. package/host-builder/data/examples/manifest.ts +112 -0
  207. package/host-builder/data/examples/mcp-server.ts +48 -0
  208. package/host-builder/data/examples/mcp-trust.ts +173 -0
  209. package/host-builder/data/examples/memory-and-wiki.ts +315 -0
  210. package/host-builder/data/examples/memory-lifecycle.ts +302 -0
  211. package/host-builder/data/examples/memory-system.ts +252 -0
  212. package/host-builder/data/examples/messaging-agent.ts +70 -0
  213. package/host-builder/data/examples/minimal-host-app.ts +41 -0
  214. package/host-builder/data/examples/model-router-aggregate-budgets.ts +364 -0
  215. package/host-builder/data/examples/model-router.ts +106 -0
  216. package/host-builder/data/examples/obscura.ts +48 -0
  217. package/host-builder/data/examples/observability.ts +116 -0
  218. package/host-builder/data/examples/open-connector-sidecar.ts +105 -0
  219. package/host-builder/data/examples/openai-compatible.ts +70 -0
  220. package/host-builder/data/examples/package-skills.ts +85 -0
  221. package/host-builder/data/examples/phase9-coding-intelligence.ts +221 -0
  222. package/host-builder/data/examples/provider-registration.ts +29 -0
  223. package/host-builder/data/examples/provider-resolver.ts +39 -0
  224. package/host-builder/data/examples/rag.ts +40 -0
  225. package/host-builder/data/examples/remote-agent-server.ts +45 -0
  226. package/host-builder/data/examples/remote-agent.ts +124 -0
  227. package/host-builder/data/examples/research-ledger.ts +79 -0
  228. package/host-builder/data/examples/revocation-propagation.ts +287 -0
  229. package/host-builder/data/examples/run-feedback.ts +93 -0
  230. package/host-builder/data/examples/scanned-document-rag.ts +48 -0
  231. package/host-builder/data/examples/sdk-basics.ts +21 -0
  232. package/host-builder/data/examples/secure-agent.ts +55 -0
  233. package/host-builder/data/examples/semantic-memory.ts +52 -0
  234. package/host-builder/data/examples/serve-tools.ts +495 -0
  235. package/host-builder/data/examples/session-memory.ts +317 -0
  236. package/host-builder/data/examples/session-search.ts +131 -0
  237. package/host-builder/data/examples/session.ts +52 -0
  238. package/host-builder/data/examples/side-call.ts +64 -0
  239. package/host-builder/data/examples/signal-agent.ts +9 -0
  240. package/host-builder/data/examples/skills-progressive-disclosure.ts +88 -0
  241. package/host-builder/data/examples/skills.ts +19 -0
  242. package/host-builder/data/examples/sqlite-resume.ts +147 -0
  243. package/host-builder/data/examples/system-project-prompts.ts +74 -0
  244. package/host-builder/data/examples/system-prompts.ts +19 -0
  245. package/host-builder/data/examples/telegram-agent.ts +30 -0
  246. package/host-builder/data/examples/tool-narrowing-planes.ts +99 -0
  247. package/host-builder/data/examples/tools.ts +29 -0
  248. package/host-builder/data/examples/validator.ts +67 -0
  249. package/host-builder/data/examples/web-no-key.ts +85 -0
  250. package/host-builder/data/examples/web-research.ts +35 -0
  251. package/host-builder/data/examples/workflow-event-sink.ts +114 -0
  252. package/host-builder/data/examples/workflow-loop.ts +93 -0
  253. package/host-builder/data/examples/workflow-multimodal-document.ts +94 -0
  254. package/host-builder/data/examples/workflow-parallel-research.ts +111 -0
  255. package/host-builder/data/examples/workflow-postgres-resume.ts +75 -0
  256. package/host-builder/data/examples/workflow-research-and-review.ts +98 -0
  257. package/host-builder/data/examples/workflow-sqlite-resume.ts +163 -0
  258. package/host-builder/data/examples.json +130 -0
  259. package/host-builder/skills/prism-host-builder/SKILL.md +85 -0
  260. package/host-builder/skills/prism-host-builder/references/choosing.md +101 -0
  261. package/host-builder/skills/prism-host-builder/references/layout.md +52 -0
  262. package/host-builder/skills/prism-host-builder/references/pitfalls.md +50 -0
  263. package/host-builder/skills/prism-host-builder/references/recipes.md +129 -0
  264. package/host-builder/skills/prism-host-builder/references/security.md +52 -0
  265. package/host-builder/skills/prism-host-builder/references/upgrading.md +67 -0
  266. package/host-builder/skills/prism-host-builder/references/verification.md +108 -0
  267. package/host-builder/src/check/child.ts +108 -0
  268. package/host-builder/src/check/conformance.ts +13 -0
  269. package/host-builder/src/check/inspect.ts +20 -0
  270. package/host-builder/src/check/manifest.ts +23 -0
  271. package/host-builder/src/check/runner.ts +181 -0
  272. package/host-builder/src/check/targets.ts +65 -0
  273. package/host-builder/src/errors.ts +35 -0
  274. package/host-builder/src/index.ts +25 -0
  275. package/host-builder/src/indexes.ts +145 -0
  276. package/host-builder/src/install/install.ts +400 -0
  277. package/host-builder/src/install/targets.ts +50 -0
  278. package/host-builder/src/lookup/api.ts +127 -0
  279. package/host-builder/src/lookup/bound.ts +38 -0
  280. package/host-builder/src/lookup/docs.ts +238 -0
  281. package/host-builder/src/lookup/errors.ts +92 -0
  282. package/host-builder/src/lookup/examples.ts +117 -0
  283. package/host-builder/src/lookup/text.ts +60 -0
  284. package/host-builder/src/server.ts +300 -0
  285. package/host-builder/src/version.ts +38 -0
  286. package/mcp-server/README.md +219 -0
  287. package/mcp-server/src/bounds.ts +23 -0
  288. package/mcp-server/src/host.ts +31 -0
  289. package/mcp-server/src/index.ts +27 -0
  290. package/mcp-server/src/serve-tools.ts +408 -0
  291. package/mcp-server/src/serve.ts +329 -0
  292. package/mcp-server/src/server.ts +331 -0
  293. package/mcp-server/src/session-map.ts +47 -0
  294. package/mcp-server/src/skill-resources.ts +85 -0
  295. package/mcp-server/src/types.ts +215 -0
  296. package/package.json +130 -4
  297. package/remote/README.md +244 -0
  298. package/remote/src/attribution.ts +22 -0
  299. package/remote/src/auth.ts +30 -0
  300. package/remote/src/bun-module.d.ts +34 -0
  301. package/remote/src/channel.ts +86 -0
  302. package/remote/src/connect.ts +212 -0
  303. package/remote/src/dispatcher.ts +282 -0
  304. package/remote/src/errors.ts +59 -0
  305. package/remote/src/host-ui.ts +152 -0
  306. package/remote/src/http-gate.ts +43 -0
  307. package/remote/src/index.ts +53 -0
  308. package/remote/src/jsonl.ts +69 -0
  309. package/remote/src/limits.ts +43 -0
  310. package/remote/src/mirror.ts +90 -0
  311. package/remote/src/pending.ts +22 -0
  312. package/remote/src/protocol.ts +107 -0
  313. package/remote/src/serve.ts +560 -0
  314. package/remote/src/session-proxy.ts +219 -0
  315. package/remote/src/sse.ts +38 -0
  316. package/remote/src/stdio-client.ts +41 -0
  317. package/remote/src/testing-fixtures/serve-stdio.ts +32 -0
  318. package/remote/src/testing.ts +230 -0
  319. package/remote/src/transport.ts +139 -0
  320. package/remote/src/transports/client.ts +126 -0
  321. package/remote/src/transports/network.ts +268 -0
  322. package/remote/src/wire.ts +244 -0
@@ -0,0 +1,256 @@
1
+ /** Offline flag-configured reference adapter. See docs/agent-adapters.md, worked mapping A. */
2
+ import { cp, readFile } from "node:fs/promises";
3
+ import { join } from "node:path";
4
+ import type { ExternalActivity, JsonValue, Message, Usage } from "@arnilo/prism";
5
+ import type { AgentAdapter, Decoded } from "@arnilo/prism-hosts/driver-process";
6
+
7
+ function text(input: string | Message | readonly Message[]): string {
8
+ if (typeof input === "string") return input;
9
+ const messages: readonly Message[] = Array.isArray(input) ? input : [input as Message];
10
+ return messages.flatMap((message) => message.content.filter((part) => part.type === "text").map((part) => part.text)).join("\n");
11
+ }
12
+
13
+ export const streamCli: AgentAdapter = {
14
+ name: "@example/prism-adapter-stream-cli",
15
+ revision: "1",
16
+ transport: "jsonl-stream",
17
+ descriptor: {
18
+ vendor: "stream-cli",
19
+ usesModel: false,
20
+ models: "passthrough",
21
+ controls: {
22
+ systemPrompt: ["replace", "append"],
23
+ builtinTools: "per-tool",
24
+ clientTools: "mcp",
25
+ skills: true,
26
+ subagents: true,
27
+ permissionCallback: true,
28
+ rewrite: true,
29
+ continueOnStop: true,
30
+ steer: "mid-turn",
31
+ resume: "store",
32
+ isolation: "flags",
33
+ },
34
+ capture: {
35
+ textDeltas: true,
36
+ thinking: "deltas",
37
+ skillActivation: "native",
38
+ toolCalls: true,
39
+ fileDiffs: true,
40
+ subagents: "full",
41
+ usage: "tokens+cost",
42
+ },
43
+ auth: {
44
+ modes: [
45
+ {
46
+ name: "account",
47
+ kind: "account",
48
+ deployments: ["local"],
49
+ homeEnv: "STREAM_HOME",
50
+ protected: { paths: ["credentials.json"], env: ["STREAM_ACCOUNT_TOKEN"] },
51
+ login: ["stream-cli", "login"],
52
+ status: ["stream-cli", "status", "--json"],
53
+ },
54
+ {
55
+ name: "key",
56
+ kind: "api-key",
57
+ deployments: ["local", "hosted"],
58
+ homeEnv: "STREAM_HOME",
59
+ protected: { paths: ["api-key.json"], env: ["STREAM_API_KEY"] },
60
+ },
61
+ ],
62
+ },
63
+ },
64
+ binary: { command: ["stream-cli"], versionArgs: ["--version"], version: (stdout) => /\b\d+\.\d+\.\d+\b/.exec(stdout)?.[0] },
65
+ profile: {
66
+ parseStatus: ({ exitCode, stdout }) => {
67
+ try {
68
+ return { signedIn: exitCode === 0 && JSON.parse(stdout).signedIn === true };
69
+ } catch {
70
+ return { signedIn: false };
71
+ }
72
+ },
73
+ },
74
+ async configure(spec, ctx) {
75
+ const args = [
76
+ "--stream",
77
+ "--settings",
78
+ join(ctx.runDir.path, "settings.json"),
79
+ "--mcp-config",
80
+ join(ctx.runDir.path, "mcp.json"),
81
+ "--strict-mcp",
82
+ "--transcript",
83
+ join(ctx.runDir.path, "transcript.jsonl"),
84
+ ];
85
+ const settings: Record<string, JsonValue> = { hooks: { preTool: [...ctx.hook.argv], stop: [...ctx.hook.argv] } };
86
+ if (spec.isolation !== "inherit") args.push("--no-user-config");
87
+ if (spec.systemPrompt) {
88
+ const mode = "replace" in spec.systemPrompt ? "replace" : "append";
89
+ const content = "replace" in spec.systemPrompt ? spec.systemPrompt.replace : spec.systemPrompt.append;
90
+ settings.systemPrompt = { mode, file: await ctx.runDir.writeFile("prompt.md", content) };
91
+ }
92
+ for (const [flag, value] of [
93
+ ["--model", spec.model],
94
+ ["--effort", spec.effort],
95
+ ["--allow-tools", spec.builtinTools?.allow?.join(",")],
96
+ ["--deny-tools", spec.builtinTools?.deny?.join(",")],
97
+ ] as const) {
98
+ if (value !== undefined) args.push(flag, value);
99
+ }
100
+ if (ctx.skills) {
101
+ await ctx.runDir.writeFile(
102
+ "plugin/manifest.json",
103
+ JSON.stringify({
104
+ name: "prism-skills",
105
+ skills: "skills",
106
+ skillFiles: [...ctx.skills.pathToSkill.keys()].map((name) => `skills/${name}/SKILL.md`),
107
+ }),
108
+ );
109
+ await cp(ctx.skills.root, join(ctx.runDir.path, "plugin/skills"), { recursive: true });
110
+ args.push("--plugin", join(ctx.runDir.path, "plugin"));
111
+ }
112
+ if (spec.subagents) args.push("--agents", await ctx.runDir.writeFile("agents.json", JSON.stringify(spec.subagents)));
113
+ await ctx.runDir.writeFile("settings.json", JSON.stringify(settings));
114
+ await ctx.runDir.writeFile("mcp.json", JSON.stringify({ strict: true, endpoint: ctx.endpoint ?? null }));
115
+ return { args };
116
+ },
117
+ encode: {
118
+ prompt: (input) => ({ type: "user", text: text(input) }),
119
+ steer: (message) => ({ type: "steer", text: text([message]) }),
120
+ continue: (reason) => ({ type: "user", text: reason }),
121
+ },
122
+ decode: decodeStreamFrame,
123
+ hooks: {
124
+ codec: {
125
+ decode: (stdin) => {
126
+ const value = JSON.parse(stdin);
127
+ if (value.type === "stop") return { kind: "stop", reason: typeof value.reason === "string" ? value.reason : undefined };
128
+ if (value.type !== "pre_tool" || typeof value.id !== "string" || typeof value.name !== "string") throw Error("invalid stream hook");
129
+ return { kind: "pre-tool", request: { toolCallId: value.id, name: value.name, args: value.input ?? {}, effects: ["write"] } };
130
+ },
131
+ encode: (answer) => {
132
+ if ("end" in answer) return { exitCode: 0, stdout: JSON.stringify({ decision: answer.end.continue ? "continue" : "stop" }) };
133
+ if ("allow" in answer)
134
+ return {
135
+ exitCode: answer.allow ? 0 : 2,
136
+ stdout: JSON.stringify(
137
+ answer.allow
138
+ ? { decision: "allow", ...(answer.args !== undefined ? { updatedInput: answer.args } : {}) }
139
+ : { decision: "deny", reason: answer.message },
140
+ ),
141
+ };
142
+ return { exitCode: 2, stdout: "" };
143
+ },
144
+ },
145
+ failClosed: { exitCode: 2, stdout: "" },
146
+ },
147
+ session: {
148
+ strategy: "store",
149
+ archive: async (ctx) => [await readFile(join(ctx.runDir.path, "transcript.jsonl"), "utf8")],
150
+ restore: async (entries, ctx) => {
151
+ const transcript = entries.at(-1);
152
+ if (typeof transcript !== "string") throw Error("invalid stream transcript");
153
+ const path = await ctx.runDir.writeFile("transcript.jsonl", transcript);
154
+ return { args: ["--resume-file", path] };
155
+ },
156
+ },
157
+ abort: [{ signal: "SIGINT" }, { signal: "SIGTERM" }],
158
+ notices: (activity) =>
159
+ activity.kind === "notice" && ["rate_limit", "quota", "billing", "auth"].includes(activity.code)
160
+ ? { code: activity.code as "rate_limit" | "quota" | "billing" | "auth" }
161
+ : undefined,
162
+ };
163
+
164
+ /** The wire table is intentionally explicit: unknown frames remain available to capture:all. */
165
+ export function decodeStreamFrame(frame: JsonValue): Decoded {
166
+ if (!frame || typeof frame !== "object" || Array.isArray(frame)) return { activity: [], unmapped: true };
167
+ const f = frame as Record<string, JsonValue>;
168
+ const activity: ExternalActivity[] = [];
169
+ switch (f.type) {
170
+ case "init":
171
+ if (typeof f.sessionId === "string") return { activity, sessionId: f.sessionId };
172
+ break;
173
+ case "assistant":
174
+ if (!Array.isArray(f.blocks)) break;
175
+ for (const block of f.blocks) {
176
+ if (
177
+ block &&
178
+ typeof block === "object" &&
179
+ !Array.isArray(block) &&
180
+ (block.type === "text" || block.type === "thinking") &&
181
+ typeof block.text === "string"
182
+ ) {
183
+ activity.push({ kind: "message.delta", content: { type: block.type, text: block.text } });
184
+ } else return { activity, unmapped: true };
185
+ }
186
+ return { activity };
187
+ case "delta":
188
+ if ((f.block === "text" || f.block === "thinking") && typeof f.text === "string")
189
+ return { activity: [{ kind: "message.delta", content: { type: f.block, text: f.text } }] };
190
+ break;
191
+ case "tool_use":
192
+ if (typeof f.id === "string" && typeof f.name === "string")
193
+ return { activity: [{ kind: "tool.started", call: { id: f.id, name: f.name, args: f.input ?? {} } }] };
194
+ break;
195
+ case "tool_result":
196
+ if (typeof f.id === "string")
197
+ return {
198
+ activity: [
199
+ {
200
+ kind: "tool.completed",
201
+ toolCallId: f.id,
202
+ status: f.status === "blocked" ? "blocked" : f.status === "error" ? "error" : "finished",
203
+ ...(f.result !== undefined ? { result: f.result } : {}),
204
+ ...(typeof f.error === "string" ? { error: f.error } : {}),
205
+ },
206
+ ],
207
+ };
208
+ break;
209
+ case "retry":
210
+ case "permission_denied":
211
+ return {
212
+ activity: [
213
+ {
214
+ kind: "notice",
215
+ level: "warn",
216
+ code: f.type === "permission_denied" ? "permission_denied" : typeof f.category === "string" ? f.category : "retry",
217
+ message: typeof f.message === "string" ? f.message : String(f.type),
218
+ },
219
+ ],
220
+ };
221
+ case "subagent":
222
+ if (typeof f.parentToolId === "string" && (f.phase === "started" || f.phase === "completed"))
223
+ return {
224
+ activity: [
225
+ {
226
+ kind: "subagent",
227
+ phase: f.phase,
228
+ id: f.parentToolId,
229
+ parentToolCallId: f.parentToolId,
230
+ ...(typeof f.name === "string" ? { name: f.name } : {}),
231
+ ...(typeof f.result === "string" ? { result: f.result } : {}),
232
+ },
233
+ ],
234
+ };
235
+ break;
236
+ case "result":
237
+ return {
238
+ activity: f.usage && typeof f.usage === "object" ? [{ kind: "usage", usage: f.usage as Usage }] : [],
239
+ turnEnd: true,
240
+ ...(typeof f.sessionId === "string" ? { sessionId: f.sessionId } : {}),
241
+ };
242
+ // Additional notifications carry the same fields as their normalized activity.
243
+ case "message":
244
+ case "tool.progress":
245
+ case "skill":
246
+ case "file":
247
+ case "plan":
248
+ case "compaction":
249
+ case "usage":
250
+ case "raw":
251
+ if (f.payload && typeof f.payload === "object" && !Array.isArray(f.payload))
252
+ return { activity: [{ ...f.payload, kind: f.type } as unknown as ExternalActivity] };
253
+ break;
254
+ }
255
+ return { activity, unmapped: true };
256
+ }
@@ -0,0 +1,172 @@
1
+ /** Offline wire companion for worked mapping C in docs/agent-adapters.md. */
2
+
3
+ import { fileURLToPath } from "node:url";
4
+ import type { ExternalActivity, Usage } from "@arnilo/prism";
5
+ import { defineScriptedDialect, type ScriptedInput } from "@arnilo/prism/testing";
6
+ import type { AdapterConformanceFixtures } from "@arnilo/prism-hosts/driver-process/testing";
7
+
8
+ export const workspaceConfigDialect = defineScriptedDialect({
9
+ name: "workspace-config",
10
+ locate: ({ argv, env, readFile }) => {
11
+ const loaded: string[] = [];
12
+ const read = (path: string) => {
13
+ const content = readFile(path);
14
+ return content === undefined ? undefined : JSON.parse(content);
15
+ };
16
+ const manifest = read(".agents/manifest.json");
17
+ for (const rel of manifest?.files ?? []) if (readFile(rel) !== undefined) loaded.push(rel);
18
+ const hooks = read(".agents/hooks.json");
19
+ const mcp = read(".agents/mcp.json");
20
+ if (!argv.includes("--no-user-config")) {
21
+ const home = env.WS_HOME ?? env.HOME;
22
+ for (const rel of [".workspace-config/hooks.json", ".workspace-config/skills/planted/SKILL.md", ".workspace-config/mcp.json"]) {
23
+ const path = `${home}/${rel}`;
24
+ if (readFile(path) !== undefined) loaded.push(path);
25
+ }
26
+ }
27
+ return { hookCommand: hooks?.PreToolUse?.[0]?.command, endpoint: mcp?.endpoint ?? undefined, loaded };
28
+ },
29
+ encodeInput: (input) => {
30
+ if (input.kind === "answer") return JSON.stringify({ type: "answer", id: input.id, allow: input.allow });
31
+ if (input.kind === "interrupt") return JSON.stringify({ type: "interrupt" });
32
+ return JSON.stringify({ type: input.kind === "steer" ? "steer" : "prompt", text: input.text });
33
+ },
34
+ decodeInput: (line) => {
35
+ let value: { type?: unknown; text?: unknown; id?: unknown; allow?: unknown };
36
+ try {
37
+ value = JSON.parse(line);
38
+ } catch {
39
+ return undefined;
40
+ }
41
+ if (!value || typeof value !== "object") return undefined;
42
+ if (value.type === "prompt" && typeof value.text === "string") return { kind: "user", text: value.text } as ScriptedInput;
43
+ if (value.type === "steer" && typeof value.text === "string") return { kind: "steer", text: value.text } as ScriptedInput;
44
+ if (value.type === "answer" && typeof value.id === "string") return { kind: "answer", id: value.id, allow: value.allow === true };
45
+ if (value.type === "interrupt") return { kind: "interrupt" };
46
+ return undefined;
47
+ },
48
+ frames: (frame) => {
49
+ if (!("kind" in frame))
50
+ return JSON.stringify({
51
+ type: "result",
52
+ conversationId: "ws-conversation",
53
+ status: "done",
54
+ usage: { inputTokens: 1, outputTokens: 1, thinkingTokens: 3 },
55
+ });
56
+ switch (frame.kind) {
57
+ case "message.delta":
58
+ return frame.content.type === "thinking"
59
+ ? JSON.stringify({ type: "delta", block: "thinking", text: frame.content.text })
60
+ : JSON.stringify({ type: "text_delta", text: frame.content.text });
61
+ case "message":
62
+ return JSON.stringify({ type: "message", role: frame.message.role, blocks: frame.message.content });
63
+ case "tool.started":
64
+ return JSON.stringify({ type: "tool_start", id: frame.call.id, name: frame.call.name, parameters: frame.call.args });
65
+ case "tool.progress":
66
+ return JSON.stringify({ type: "tool_progress", id: frame.toolCallId, progress: frame.progress });
67
+ case "tool.completed":
68
+ return JSON.stringify({ type: "tool_end", id: frame.toolCallId, status: frame.status, output: frame.result, error: frame.error });
69
+ case "skill":
70
+ return JSON.stringify({ type: "skill_read", name: frame.name, source: frame.source, resolved: frame.resolved });
71
+ case "file":
72
+ return JSON.stringify({ type: "file_change", path: frame.path, change: frame.change, source: frame.source, diff: frame.diff });
73
+ case "plan":
74
+ return JSON.stringify({ type: "plan_update", entries: frame.entries });
75
+ case "subagent":
76
+ return JSON.stringify({ type: "subagent_info", phase: frame.phase, id: frame.id, name: frame.name, result: frame.result });
77
+ case "compaction":
78
+ return JSON.stringify({ type: "checkpoint", phase: frame.phase, summary: frame.summary });
79
+ case "notice":
80
+ return JSON.stringify({ type: "notice", level: frame.level, code: frame.code, message: frame.message });
81
+ case "usage":
82
+ return JSON.stringify({ type: "usage", usage: frame.usage });
83
+ default: {
84
+ const { kind, ...data } = frame;
85
+ return JSON.stringify({ type: kind, payload: data });
86
+ }
87
+ }
88
+ },
89
+ parseFrame: (line) => {
90
+ let frame: ReturnType<typeof JSON.parse>;
91
+ try {
92
+ frame = JSON.parse(line);
93
+ } catch {
94
+ return undefined;
95
+ }
96
+ if (!frame || typeof frame !== "object") return undefined;
97
+ if (frame.type === "result") return { kind: "frame", frame: { type: "turn.done" } };
98
+ let activity: ExternalActivity;
99
+ switch (frame.type) {
100
+ case "text_delta":
101
+ activity = { kind: "message.delta", content: { type: "text", text: frame.text } };
102
+ break;
103
+ case "message":
104
+ activity = { kind: "message", message: { role: frame.role, content: frame.blocks } };
105
+ break;
106
+ case "tool_start":
107
+ activity = { kind: "tool.started", call: { id: frame.id, name: frame.name, args: frame.parameters } };
108
+ break;
109
+ case "tool_progress":
110
+ activity = { kind: "tool.progress", toolCallId: frame.id, progress: frame.progress };
111
+ break;
112
+ case "tool_end":
113
+ activity = { kind: "tool.completed", toolCallId: frame.id, status: frame.status, result: frame.output, error: frame.error };
114
+ break;
115
+ case "skill_read":
116
+ activity = { kind: "skill", name: frame.name, source: frame.source, resolved: frame.resolved };
117
+ break;
118
+ case "file_change":
119
+ activity = { kind: "file", path: frame.path, change: frame.change, source: frame.source, diff: frame.diff };
120
+ break;
121
+ case "plan_update":
122
+ activity = { kind: "plan", entries: frame.entries };
123
+ break;
124
+ case "subagent_info":
125
+ activity = {
126
+ kind: "subagent",
127
+ phase: frame.phase,
128
+ id: frame.id,
129
+ parentToolCallId: frame.id,
130
+ name: frame.name,
131
+ result: frame.result,
132
+ };
133
+ break;
134
+ case "checkpoint":
135
+ activity = { kind: "compaction", phase: frame.phase, summary: frame.summary };
136
+ break;
137
+ case "notice":
138
+ activity = { kind: "notice", level: frame.level, code: frame.code, message: frame.message };
139
+ break;
140
+ case "usage":
141
+ activity = { kind: "usage", usage: frame.usage as Usage };
142
+ break;
143
+ default:
144
+ if (!frame.payload || typeof frame.payload !== "object") return undefined;
145
+ activity = { ...frame.payload, kind: frame.type };
146
+ break;
147
+ }
148
+ return { kind: "frame", frame: activity };
149
+ },
150
+ hook: {
151
+ via: "command",
152
+ payload: (call) => JSON.stringify({ type: "pre_tool", id: call.id, name: call.tool, input: call.args }),
153
+ allowed: (answer) => {
154
+ try {
155
+ return JSON.parse(answer.stdout).decision === "allow";
156
+ } catch {
157
+ return false;
158
+ }
159
+ },
160
+ },
161
+ });
162
+
163
+ export const workspaceConfigFixtures: AdapterConformanceFixtures = {
164
+ mode: "key",
165
+ home: {
166
+ hook: { path: ".workspace-config/hooks.json", content: '{"PreToolUse":[{"command":["planted-hook"]}]}' },
167
+ skill: { path: ".workspace-config/skills/planted/SKILL.md", content: "planted skill" },
168
+ mcp: { path: ".workspace-config/mcp.json", content: '{"endpoint":{"command":"planted-server"}}' },
169
+ },
170
+ config: (cli) => ({ binary: cli.command[0]!, args: cli.command.slice(1) }),
171
+ recorded: fileURLToPath(new URL("./fixtures/workspace-config.json", import.meta.url)),
172
+ };
@@ -0,0 +1,251 @@
1
+ /** Offline workspace-file-configured reference adapter. See docs/agent-adapters.md, worked mapping C. */
2
+ import { readFile } from "node:fs/promises";
3
+ import type { ExternalActivity, JsonValue, Message, Usage } from "@arnilo/prism";
4
+ import type { ExternalAgentSpec, MaterializedFile } from "@arnilo/prism/driver-kit";
5
+ import type { AgentAdapter, Decoded } from "@arnilo/prism-hosts/driver-process";
6
+
7
+ function text(input: string | Message | readonly Message[]): string {
8
+ if (typeof input === "string") return input;
9
+ const messages: readonly Message[] = Array.isArray(input) ? input : [input as Message];
10
+ return messages.flatMap((message) => message.content.filter((part) => part.type === "text").map((part) => part.text)).join("\n");
11
+ }
12
+
13
+ /** Frontmatter carries the built-in tool list; the body is the replaced prompt. */
14
+ function agentFile(spec: Pick<ExternalAgentSpec, "builtinTools" | "systemPrompt">, subagent = false): string {
15
+ const tools = spec.builtinTools?.allow ?? [];
16
+ const frontmatter = [`tools: [${tools.join(", ")}]`, ...(subagent ? ["subagent: true"] : [])].join("\n");
17
+ const body = spec.systemPrompt && "replace" in spec.systemPrompt ? spec.systemPrompt.replace : "";
18
+ return `---\n${frontmatter}\n---\n\n${body}\n`;
19
+ }
20
+
21
+ const FAIL_CLOSED = { exitCode: 0, stdout: '{"decision":"deny","reason":"prism relay unavailable"}' };
22
+
23
+ export const workspaceConfig: AgentAdapter = {
24
+ name: "@example/prism-adapter-workspace-config",
25
+ revision: "1",
26
+ transport: "jsonl-stream",
27
+ descriptor: {
28
+ vendor: "workspace-config",
29
+ usesModel: false,
30
+ models: "passthrough",
31
+ controls: {
32
+ systemPrompt: ["replace", "append"],
33
+ builtinTools: "per-tool",
34
+ clientTools: "mcp",
35
+ skills: true,
36
+ subagents: true,
37
+ permissionCallback: true,
38
+ rewrite: false,
39
+ continueOnStop: true,
40
+ steer: "next-turn",
41
+ resume: "vendor",
42
+ isolation: "workspace-files",
43
+ },
44
+ capture: {
45
+ textDeltas: true,
46
+ thinking: "tokens-only",
47
+ skillActivation: "tool",
48
+ toolCalls: true,
49
+ fileDiffs: true,
50
+ subagents: "summary",
51
+ usage: "tokens",
52
+ },
53
+ auth: {
54
+ modes: [
55
+ {
56
+ name: "account",
57
+ kind: "account",
58
+ deployments: ["local"],
59
+ protected: { paths: ["auth.json"], env: ["WORKSPACE_CONFIG_TOKEN"] },
60
+ login: ["workspace-config", "login"],
61
+ status: ["workspace-config", "status", "--json"],
62
+ },
63
+ {
64
+ name: "key",
65
+ kind: "api-key",
66
+ deployments: ["local", "hosted"],
67
+ protected: { paths: ["api-key.json"], env: ["WORKSPACE_CONFIG_API_KEY"] },
68
+ },
69
+ ],
70
+ },
71
+ },
72
+ binary: { command: ["workspace-config"], versionArgs: ["--version"], version: (stdout) => /\b\d+\.\d+\.\d+\b/.exec(stdout)?.[0] },
73
+ profile: {
74
+ parseStatus: ({ exitCode, stdout }) => {
75
+ try {
76
+ return { signedIn: exitCode === 0 && JSON.parse(stdout).signedIn === true };
77
+ } catch {
78
+ return { signedIn: false };
79
+ }
80
+ },
81
+ },
82
+ async configure(spec, ctx) {
83
+ const args = ["--agent", spec.name, "--input-format", "stream-json", "--output-format", "stream-json"];
84
+ if (spec.model !== undefined) args.push("--model", spec.model);
85
+ if (spec.effort !== undefined) args.push("--effort", spec.effort);
86
+ if (spec.isolation !== "inherit") args.push("--no-user-config");
87
+ if (ctx.resume.sessionId !== undefined) args.push("--conversation", ctx.resume.sessionId);
88
+ const overlays: MaterializedFile[] = [];
89
+ const write = (path: string, content: string) => overlays.push({ path, content });
90
+ write(`.agents/agents/${spec.name}.md`, agentFile(spec));
91
+ if (spec.systemPrompt && "append" in spec.systemPrompt) write(".agents/rules/prism-append.md", spec.systemPrompt.append);
92
+ if (spec.builtinTools?.deny?.length) write(".agents/rules/prism-deny.md", `Denied tools: ${spec.builtinTools.deny.join(", ")}`);
93
+ for (const [name, sub] of Object.entries(spec.subagents ?? {})) write(`.agents/agents/${name}.md`, agentFile(sub, true));
94
+ write(".agents/hooks.json", JSON.stringify({ PreToolUse: [{ type: "command", command: [...ctx.hook.argv] }] }));
95
+ write(".agents/mcp.json", JSON.stringify({ strict: true, endpoint: ctx.endpoint ?? null }));
96
+ if (ctx.skills) {
97
+ const skillFiles: string[] = [];
98
+ for (const [name, path] of ctx.skills.pathToSkill) {
99
+ const file = `.agents/skills/${name}/SKILL.md`;
100
+ write(file, await readFile(path, "utf8"));
101
+ skillFiles.push(file);
102
+ }
103
+ write(".agents/skills/manifest.json", JSON.stringify({ skillFiles }));
104
+ }
105
+ write(".agents/manifest.json", JSON.stringify({ files: overlays.map((file) => file.path) }));
106
+ return { args, overlays };
107
+ },
108
+ encode: {
109
+ prompt: (input) => ({ type: "prompt", text: text(input) }),
110
+ continue: (reason) => ({ type: "prompt", text: reason }),
111
+ },
112
+ decode: decodeWorkspaceFrame,
113
+ hooks: {
114
+ codec: {
115
+ decode: (stdin) => {
116
+ const value = JSON.parse(stdin);
117
+ if (value.type === "stop") return { kind: "stop", reason: typeof value.reason === "string" ? value.reason : undefined };
118
+ if (value.type !== "pre_tool" || typeof value.id !== "string" || typeof value.name !== "string")
119
+ throw Error("invalid workspace hook");
120
+ return {
121
+ kind: "pre-tool",
122
+ request: { toolCallId: value.id, name: value.name, args: value.input ?? {}, effects: ["write"] },
123
+ };
124
+ },
125
+ encode: (answer) => {
126
+ if ("end" in answer) return { exitCode: 0, stdout: JSON.stringify({ decision: answer.end.continue ? "continue" : "stop" }) };
127
+ if ("allow" in answer)
128
+ return {
129
+ exitCode: 0,
130
+ stdout: JSON.stringify(answer.allow ? { decision: "allow" } : { decision: "deny", reason: answer.message }),
131
+ };
132
+ return FAIL_CLOSED;
133
+ },
134
+ },
135
+ failClosed: FAIL_CLOSED,
136
+ },
137
+ session: { strategy: "vendor" },
138
+ abort: [{ closeStdin: true }, { signal: "SIGTERM" }],
139
+ notices: (activity) =>
140
+ activity.kind === "notice" && ["rate_limit", "quota", "billing", "auth"].includes(activity.code)
141
+ ? { code: activity.code as "rate_limit" | "quota" | "billing" | "auth" }
142
+ : undefined,
143
+ };
144
+
145
+ /** The wire table is intentionally explicit: unknown frames remain available to capture:all. */
146
+ export function decodeWorkspaceFrame(frame: JsonValue): Decoded {
147
+ if (!frame || typeof frame !== "object" || Array.isArray(frame)) return { activity: [], unmapped: true };
148
+ const f = frame as Record<string, JsonValue>;
149
+ const activity: ExternalActivity[] = [];
150
+ switch (f.type) {
151
+ case "init":
152
+ if (typeof f.conversationId === "string") return { activity, sessionId: f.conversationId };
153
+ break;
154
+ case "text_delta":
155
+ if (typeof f.text === "string") return { activity: [{ kind: "message.delta", content: { type: "text", text: f.text } }] };
156
+ break;
157
+ // The vendor streams no thinking text; only its token count in `usage` is captured.
158
+ case "delta":
159
+ break;
160
+ case "message":
161
+ if (Array.isArray(f.blocks))
162
+ return { activity: [{ kind: "message", message: { role: "assistant", content: f.blocks as unknown as Message["content"] } }] };
163
+ break;
164
+ case "tool_start":
165
+ if (typeof f.id === "string" && typeof f.name === "string")
166
+ return { activity: [{ kind: "tool.started", call: { id: f.id, name: f.name, args: f.parameters ?? {} } }] };
167
+ break;
168
+ case "tool_progress":
169
+ if (typeof f.id === "string") return { activity: [{ kind: "tool.progress", toolCallId: f.id, progress: f.progress }] };
170
+ break;
171
+ case "tool_end":
172
+ if (typeof f.id === "string")
173
+ return {
174
+ activity: [
175
+ {
176
+ kind: "tool.completed",
177
+ toolCallId: f.id,
178
+ status: f.status === "blocked" ? "blocked" : f.status === "error" ? "error" : "finished",
179
+ ...(f.output !== undefined ? { result: f.output } : {}),
180
+ ...(typeof f.error === "string" ? { error: f.error } : {}),
181
+ },
182
+ ],
183
+ };
184
+ break;
185
+ case "skill_read":
186
+ return { activity: [{ kind: "skill", name: f.name as string, source: f.source as "tool", resolved: f.resolved as boolean }] };
187
+ case "file_change":
188
+ return {
189
+ activity: [
190
+ {
191
+ kind: "file",
192
+ path: f.path as string,
193
+ change: f.change as "created" | "modified" | "deleted" | "moved",
194
+ source: f.source as "agent" | "diff",
195
+ ...(f.diff !== undefined ? { diff: f.diff as string } : {}),
196
+ },
197
+ ],
198
+ };
199
+ case "plan_update":
200
+ return { activity: [{ kind: "plan", entries: f.entries as never }] };
201
+ case "subagent_info":
202
+ if (typeof f.id === "string" && (f.phase === "started" || f.phase === "completed"))
203
+ return {
204
+ activity: [
205
+ {
206
+ kind: "subagent",
207
+ phase: f.phase,
208
+ id: f.id,
209
+ parentToolCallId: f.id,
210
+ ...(typeof f.name === "string" ? { name: f.name } : {}),
211
+ ...(typeof f.result === "string" ? { result: f.result } : {}),
212
+ },
213
+ ],
214
+ };
215
+ break;
216
+ case "checkpoint":
217
+ return {
218
+ activity: [
219
+ {
220
+ kind: "compaction",
221
+ phase: f.phase as "started" | "completed",
222
+ ...(f.summary !== undefined ? { summary: f.summary as string } : {}),
223
+ },
224
+ ],
225
+ };
226
+ case "notice":
227
+ return {
228
+ activity: [
229
+ {
230
+ kind: "notice",
231
+ level: f.level as "info" | "warn" | "error",
232
+ code: f.code as string,
233
+ message: f.message as string,
234
+ },
235
+ ],
236
+ };
237
+ case "usage":
238
+ return { activity: [{ kind: "usage", usage: f.usage as Usage }] };
239
+ case "raw":
240
+ if (f.payload && typeof f.payload === "object" && !Array.isArray(f.payload))
241
+ return { activity: [{ ...f.payload, kind: "raw" } as unknown as ExternalActivity] };
242
+ break;
243
+ case "result":
244
+ return {
245
+ activity: f.usage && typeof f.usage === "object" ? [{ kind: "usage", usage: f.usage as Usage }] : [],
246
+ turnEnd: true,
247
+ ...(typeof f.conversationId === "string" ? { sessionId: f.conversationId } : {}),
248
+ };
249
+ }
250
+ return { activity, unmapped: true };
251
+ }