@arnilo/prism-hosts 0.0.0-stage → 0.13.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 (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 +6197 -0
  136. package/host-builder/data/errors.json +558 -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 +255 -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 +318 -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 +68 -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,309 @@
1
+ /** Offline JSON-RPC app-server reference adapter. See docs/agent-adapters.md, worked mapping B. */
2
+ import { join } from "node:path";
3
+ import type { AgentInput, JsonObject, JsonValue, Message, Usage } from "@arnilo/prism";
4
+ import type { AgentAdapter, Decoded, OutboundFrame, RequestContext } from "@arnilo/prism-hosts/driver-process";
5
+
6
+ function text(input: string | Message | readonly Message[]): string {
7
+ if (typeof input === "string") return input;
8
+ const messages: readonly Message[] = Array.isArray(input) ? input : [input as Message];
9
+ return messages.flatMap((message) => message.content.filter((part) => part.type === "text").map((part) => part.text)).join("\n");
10
+ }
11
+
12
+ function answerToDecision(answer: Awaited<ReturnType<RequestContext["ask"]>>): JsonValue {
13
+ return { decision: "allow" in answer && answer.allow ? "allow" : "deny" };
14
+ }
15
+
16
+ export const rpcServer: AgentAdapter = {
17
+ name: "@example/prism-adapter-rpc-server",
18
+ revision: "1",
19
+ transport: "json-rpc",
20
+ descriptor: {
21
+ vendor: "rpc-server",
22
+ usesModel: false,
23
+ models: "passthrough",
24
+ controls: {
25
+ systemPrompt: ["replace", "append"],
26
+ builtinTools: "partial",
27
+ clientTools: "native",
28
+ skills: false,
29
+ subagents: false,
30
+ permissionCallback: true,
31
+ rewrite: false,
32
+ continueOnStop: true,
33
+ steer: "mid-turn",
34
+ resume: "vendor",
35
+ isolation: "flags",
36
+ },
37
+ capture: {
38
+ textDeltas: true,
39
+ thinking: "deltas",
40
+ skillActivation: "none",
41
+ toolCalls: true,
42
+ fileDiffs: true,
43
+ subagents: "none",
44
+ usage: "tokens",
45
+ },
46
+ auth: {
47
+ modes: [
48
+ {
49
+ name: "account",
50
+ kind: "account",
51
+ deployments: ["local"],
52
+ homeEnv: "RPC_HOME",
53
+ protected: { paths: ["auth.json"], env: ["RPC_ACCOUNT_TOKEN"] },
54
+ login: ["rpc-server", "login"],
55
+ status: ["rpc-server", "login", "status"],
56
+ },
57
+ {
58
+ name: "token",
59
+ kind: "api-key",
60
+ deployments: ["local", "hosted"],
61
+ hostedAcknowledgements: ["rpc-server-token-terms"],
62
+ homeEnv: "RPC_HOME",
63
+ protected: { paths: ["token.json"], env: ["RPC_TOKEN"] },
64
+ },
65
+ {
66
+ name: "key",
67
+ kind: "api-key",
68
+ deployments: ["local", "hosted"],
69
+ homeEnv: "RPC_HOME",
70
+ protected: { paths: ["api-key.json"], env: ["RPC_API_KEY"] },
71
+ },
72
+ ],
73
+ },
74
+ },
75
+ binary: { command: ["rpc-server"], versionArgs: ["--version"], version: (stdout) => /\b\d+\.\d+\.\d+\b/.exec(stdout)?.[0] },
76
+ profile: {
77
+ parseStatus: ({ exitCode, stdout }) => {
78
+ try {
79
+ return { signedIn: exitCode === 0 && JSON.parse(stdout).signedIn === true };
80
+ } catch {
81
+ return { signedIn: false };
82
+ }
83
+ },
84
+ },
85
+ async configure(spec, ctx) {
86
+ const configPath = join(ctx.runDir.path, "config.json");
87
+ const args = ["app-server", "--config", configPath];
88
+ if (spec.isolation !== "inherit") args.push("--no-user-config");
89
+ const config: Record<string, JsonValue> = {};
90
+ if (spec.systemPrompt) {
91
+ const mode = "replace" in spec.systemPrompt ? "base" : "developer";
92
+ const content = "replace" in spec.systemPrompt ? spec.systemPrompt.replace : spec.systemPrompt.append;
93
+ config.instructions = { mode, file: await ctx.runDir.writeFile("instructions.md", content) };
94
+ }
95
+ if (spec.model !== undefined) config.model = spec.model;
96
+ if (spec.effort !== undefined) config.reasoningEffort = spec.effort;
97
+ if (spec.builtinTools) config.approvalPolicy = spec.builtinTools.deny?.length ? "on-request" : "on-failure";
98
+ if (ctx.endpoint) {
99
+ await ctx.runDir.writeFile("mcp.json", JSON.stringify({ servers: { prism: ctx.endpoint } }));
100
+ args.push("--mcp-config", join(ctx.runDir.path, "mcp.json"));
101
+ }
102
+ await ctx.runDir.writeFile("config.json", JSON.stringify(config));
103
+ return { args };
104
+ },
105
+ open: (ctx): readonly OutboundFrame[] => {
106
+ const thread = (method: string, threadId: string | null): OutboundFrame => ({
107
+ method,
108
+ params: { threadId, dynamicTools: ctx.tools as unknown as JsonValue },
109
+ notify: true,
110
+ });
111
+ return [
112
+ {
113
+ method: "initialize",
114
+ params: { capabilities: { experimentalApi: true }, clientInfo: { name: "prism", version: "1" } },
115
+ notify: true,
116
+ },
117
+ { method: "initialized", notify: true },
118
+ ctx.resume.sessionId ? thread("thread/resume", ctx.resume.sessionId) : thread("thread/start", null),
119
+ ];
120
+ },
121
+ encode: {
122
+ prompt: (input: AgentInput, ctx) => ({
123
+ method: "turn/start",
124
+ params: { threadId: ctx.sessionId ?? null, text: text(input) },
125
+ notify: true,
126
+ }),
127
+ steer: (message: Message, ctx) => ({
128
+ method: "turn/steer",
129
+ params: { threadId: ctx.sessionId ?? null, turnId: ctx.turnId ?? null, text: text([message]) },
130
+ notify: true,
131
+ }),
132
+ continue: (reason: string, ctx) => ({ method: "turn/start", params: { threadId: ctx.sessionId ?? null, text: reason }, notify: true }),
133
+ },
134
+ decode: decodeRpcNotification,
135
+ requests: {
136
+ "item/approval": async ({ params, ask }) => {
137
+ const call = params as { toolCallId?: unknown; name?: unknown; args?: unknown };
138
+ return answerToDecision(
139
+ await ask({
140
+ toolCallId: String(call.toolCallId ?? ""),
141
+ name: String(call.name ?? ""),
142
+ args: (call.args ?? {}) as JsonValue,
143
+ effects: ["write"],
144
+ }),
145
+ );
146
+ },
147
+ "user/input": async ({ params, host }) => {
148
+ const question = params as { question?: unknown };
149
+ const answer = await host.ui?.request({ kind: "input", title: String(question.question ?? "Input") });
150
+ return { answer: answer?.status === "answered" ? String(answer.value) : null };
151
+ },
152
+ "item/tool/call": async ({ params, bridge }) => {
153
+ const call = params as { toolCallId?: unknown; name?: unknown; args?: unknown };
154
+ const result = await bridge.invoke({
155
+ type: "tool_call",
156
+ id: String(call.toolCallId ?? ""),
157
+ name: String(call.name ?? ""),
158
+ arguments: (call.args ?? {}) as JsonObject,
159
+ });
160
+ return { result: (result.value ?? null) as JsonValue };
161
+ },
162
+ },
163
+ session: { strategy: "vendor" },
164
+ abort: [
165
+ { rpc: "turn/interrupt", params: (ctx) => ({ threadId: ctx.sessionId ?? null, turnId: ctx.turnId ?? null }) },
166
+ { closeStdin: true },
167
+ { signal: "SIGTERM" },
168
+ ],
169
+ notices: (activity) =>
170
+ activity.kind === "notice" && ["rate_limit", "quota", "billing", "auth"].includes(activity.code)
171
+ ? { code: activity.code as "rate_limit" | "quota" | "billing" | "auth" }
172
+ : undefined,
173
+ };
174
+
175
+ /** The wire table is intentionally explicit: unknown notifications remain available to capture:all. */
176
+ export function decodeRpcNotification(frame: JsonValue): Decoded {
177
+ if (!frame || typeof frame !== "object" || Array.isArray(frame)) return { activity: [], unmapped: true };
178
+ const f = frame as Record<string, JsonValue>;
179
+ if (typeof f.method !== "string") return { activity: [], unmapped: true };
180
+ const params = (f.params && typeof f.params === "object" && !Array.isArray(f.params) ? f.params : {}) as Record<string, JsonValue>;
181
+ const ids = {
182
+ ...(typeof params.threadId === "string" ? { sessionId: params.threadId } : {}),
183
+ ...(typeof params.turnId === "string" ? { turnId: params.turnId } : {}),
184
+ };
185
+ const item = (params.item && typeof params.item === "object" && !Array.isArray(params.item) ? params.item : undefined) as
186
+ | Record<string, JsonValue>
187
+ | undefined;
188
+ switch (f.method) {
189
+ case "turn/completed":
190
+ return { activity: [], turnEnd: true, ...ids };
191
+ case "item/agentMessage/delta":
192
+ if (typeof params.delta === "string")
193
+ return { activity: [{ kind: "message.delta", content: { type: "text", text: params.delta } }], ...ids };
194
+ break;
195
+ case "item/reasoning/delta":
196
+ if (typeof params.delta === "string")
197
+ return { activity: [{ kind: "message.delta", content: { type: "thinking", text: params.delta } }], ...ids };
198
+ break;
199
+ case "item/started":
200
+ if (item?.type === "toolCall" && typeof item.id === "string" && typeof item.name === "string")
201
+ return { activity: [{ kind: "tool.started", call: { id: item.id, name: item.name, args: item.args ?? {} } }], ...ids };
202
+ break;
203
+ case "item/completed":
204
+ if (item?.type === "toolResult" && typeof item.id === "string")
205
+ return {
206
+ activity: [
207
+ {
208
+ kind: "tool.completed",
209
+ toolCallId: item.id,
210
+ status: item.status === "blocked" ? "blocked" : item.status === "error" ? "error" : "finished",
211
+ ...(item.result !== undefined ? { result: item.result } : {}),
212
+ ...(typeof item.error === "string" ? { error: item.error } : {}),
213
+ },
214
+ ],
215
+ ...ids,
216
+ };
217
+ if (item?.type === "agentMessage" && typeof item.text === "string")
218
+ return { activity: [{ kind: "message", message: { role: "assistant", content: [{ type: "text", text: item.text }] } }], ...ids };
219
+ if (item?.type === "skill" && typeof item.name === "string")
220
+ return {
221
+ activity: [
222
+ {
223
+ kind: "skill",
224
+ name: item.name,
225
+ source: item.source === "native" || item.source === "tool" || item.source === "path" ? item.source : "explicit",
226
+ resolved: item.resolved === true,
227
+ },
228
+ ],
229
+ ...ids,
230
+ };
231
+ break;
232
+ case "item/toolCall/progress":
233
+ if (typeof params.toolCallId === "string")
234
+ return { activity: [{ kind: "tool.progress", toolCallId: params.toolCallId, progress: params.progress ?? null }], ...ids };
235
+ break;
236
+ case "item/fileChange":
237
+ if (typeof params.path === "string")
238
+ return {
239
+ activity: [
240
+ {
241
+ kind: "file",
242
+ path: params.path,
243
+ change: params.change === "created" || params.change === "deleted" || params.change === "moved" ? params.change : "modified",
244
+ source: params.source === "diff" ? "diff" : "agent",
245
+ ...(typeof params.diff === "string" ? { diff: params.diff } : {}),
246
+ },
247
+ ],
248
+ ...ids,
249
+ };
250
+ break;
251
+ case "turn/plan/updated":
252
+ if (Array.isArray(params.entries))
253
+ return { activity: [{ kind: "plan", entries: params.entries as unknown as { title: string; status: string }[] }], ...ids };
254
+ break;
255
+ case "item/subagent":
256
+ if ((params.phase === "started" || params.phase === "completed") && typeof params.id === "string")
257
+ return {
258
+ activity: [
259
+ {
260
+ kind: "subagent",
261
+ phase: params.phase,
262
+ id: params.id,
263
+ ...(typeof params.name === "string" ? { name: params.name } : {}),
264
+ ...(typeof params.result === "string" ? { result: params.result } : {}),
265
+ },
266
+ ],
267
+ ...ids,
268
+ };
269
+ break;
270
+ case "thread/compacted":
271
+ if (params.phase === "started" || params.phase === "completed")
272
+ return {
273
+ activity: [
274
+ { kind: "compaction", phase: params.phase, ...(typeof params.summary === "string" ? { summary: params.summary } : {}) },
275
+ ],
276
+ ...ids,
277
+ };
278
+ break;
279
+ case "notice":
280
+ return {
281
+ activity: [
282
+ {
283
+ kind: "notice",
284
+ level: params.level === "warn" || params.level === "error" ? params.level : "info",
285
+ code: typeof params.code === "string" ? params.code : "notice",
286
+ message: typeof params.message === "string" ? params.message : "notice",
287
+ },
288
+ ],
289
+ ...ids,
290
+ };
291
+ case "thread/tokenUsage/updated":
292
+ if (params.usage && typeof params.usage === "object" && !Array.isArray(params.usage))
293
+ return { activity: [{ kind: "usage", usage: params.usage as Usage }], ...ids };
294
+ break;
295
+ case "item/raw":
296
+ return {
297
+ activity: [
298
+ {
299
+ kind: "raw",
300
+ vendor: typeof params.vendor === "string" ? params.vendor : "rpc-server",
301
+ type: typeof params.type === "string" ? params.type : "raw",
302
+ data: params.data ?? null,
303
+ },
304
+ ],
305
+ ...ids,
306
+ };
307
+ }
308
+ return { activity: [], unmapped: true, ...ids };
309
+ }
@@ -0,0 +1,165 @@
1
+ /** Offline wire companion for worked mapping A in docs/agent-adapters.md. */
2
+
3
+ import { fileURLToPath } from "node:url";
4
+ import type { ExternalActivity } 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 streamCliDialect = defineScriptedDialect({
9
+ name: "stream-cli",
10
+ locate: ({ argv, env, readFile }) => {
11
+ const loaded: string[] = [];
12
+ const load = (path: string | undefined) => {
13
+ if (!path) return undefined;
14
+ const content = readFile(path);
15
+ if (content === undefined) return undefined;
16
+ loaded.push(path);
17
+ return JSON.parse(content);
18
+ };
19
+ const flag = (name: string) => {
20
+ const i = argv.indexOf(name);
21
+ return i < 0 ? undefined : argv[i + 1];
22
+ };
23
+ const settings = load(flag("--settings"));
24
+ const mcp = load(flag("--mcp-config"));
25
+ if (settings?.systemPrompt?.file && readFile(settings.systemPrompt.file) !== undefined) loaded.push(settings.systemPrompt.file);
26
+ const plugin = flag("--plugin");
27
+ if (plugin) {
28
+ const manifest = load(`${plugin}/manifest.json`);
29
+ for (const rel of manifest?.skillFiles ?? []) {
30
+ const path = `${plugin}/${rel}`;
31
+ if (readFile(path) !== undefined) loaded.push(path);
32
+ }
33
+ }
34
+ load(flag("--agents"));
35
+ const resume = flag("--resume-file");
36
+ if (resume && readFile(resume) !== undefined) loaded.push(resume);
37
+ if (!argv.includes("--no-user-config")) {
38
+ const home = env.STREAM_HOME ?? env.HOME;
39
+ for (const rel of [".stream-cli/settings.json", ".stream-cli/plugins/planted/skills/planted/SKILL.md", ".stream-cli/mcp.json"]) {
40
+ const path = `${home}/${rel}`;
41
+ if (readFile(path) !== undefined) loaded.push(path);
42
+ }
43
+ }
44
+ return { hookCommand: settings?.hooks?.preTool, endpoint: mcp?.endpoint ?? undefined, loaded };
45
+ },
46
+ encodeInput: (input) => JSON.stringify({ type: input.kind, ...("text" in input ? { text: input.text } : {}) }),
47
+ decodeInput: (line) => {
48
+ let value: ReturnType<typeof JSON.parse>;
49
+ try {
50
+ value = JSON.parse(line);
51
+ } catch {
52
+ return undefined;
53
+ }
54
+ if (!value || (value.type !== "user" && value.type !== "steer")) return undefined;
55
+ // Model a binary-owned transcript, including the restored contents on the next process start.
56
+ const i = process.argv.indexOf("--transcript");
57
+ if (i >= 0) require("node:fs").appendFileSync(process.argv[i + 1], `${line}\n`);
58
+ return { kind: value.type, text: value.text } as ScriptedInput;
59
+ },
60
+ frames: (frame) => {
61
+ if (!("kind" in frame))
62
+ return JSON.stringify({ type: "result", sessionId: "stream-session", usage: { inputTokens: 1, outputTokens: 1 } });
63
+ switch (frame.kind) {
64
+ case "message.delta":
65
+ return JSON.stringify({ type: "delta", block: frame.content.type, text: frame.content.text });
66
+ case "tool.started":
67
+ return JSON.stringify({ type: "tool_use", id: frame.call.id, name: frame.call.name, input: frame.call.args });
68
+ case "tool.completed":
69
+ return JSON.stringify({
70
+ type: "tool_result",
71
+ id: frame.toolCallId,
72
+ status: frame.status,
73
+ result: frame.result,
74
+ error: frame.error,
75
+ });
76
+ case "subagent":
77
+ return JSON.stringify({
78
+ type: "subagent",
79
+ parentToolId: frame.parentToolCallId ?? frame.id,
80
+ phase: frame.phase,
81
+ name: frame.name,
82
+ result: frame.result,
83
+ });
84
+ case "notice":
85
+ return JSON.stringify({ type: "retry", category: frame.code, message: frame.message });
86
+ default: {
87
+ const { kind, ...data } = frame;
88
+ return JSON.stringify({ type: kind, payload: data });
89
+ }
90
+ }
91
+ },
92
+ parseFrame: (line) => {
93
+ let frame: ReturnType<typeof JSON.parse>;
94
+ try {
95
+ frame = JSON.parse(line);
96
+ } catch {
97
+ return undefined;
98
+ }
99
+ if (!frame || typeof frame !== "object") return undefined;
100
+ if (frame.type === "result") return { kind: "frame", frame: { type: "turn.done" } };
101
+ let activity: ExternalActivity;
102
+ switch (frame.type) {
103
+ case "assistant":
104
+ activity = { kind: "message", message: { role: "assistant", content: frame.blocks } };
105
+ break;
106
+ case "delta":
107
+ activity = { kind: "message.delta", content: { type: frame.block, text: frame.text } };
108
+ break;
109
+ case "tool_use":
110
+ activity = { kind: "tool.started", call: { id: frame.id, name: frame.name, args: frame.input } };
111
+ break;
112
+ case "tool_result":
113
+ activity = { kind: "tool.completed", toolCallId: frame.id, status: frame.status, result: frame.result, error: frame.error };
114
+ break;
115
+ case "subagent":
116
+ activity = {
117
+ kind: "subagent",
118
+ id: frame.parentToolId,
119
+ parentToolCallId: frame.parentToolId,
120
+ phase: frame.phase,
121
+ ...(frame.name ? { name: frame.name } : {}),
122
+ };
123
+ break;
124
+ case "retry":
125
+ case "permission_denied":
126
+ activity = {
127
+ kind: "notice",
128
+ level: "warn",
129
+ code: frame.type === "retry" ? frame.category : "permission_denied",
130
+ message: frame.message,
131
+ };
132
+ break;
133
+ case "message":
134
+ case "tool.progress":
135
+ case "skill":
136
+ case "file":
137
+ case "plan":
138
+ case "compaction":
139
+ case "usage":
140
+ case "raw":
141
+ if (!frame.payload || typeof frame.payload !== "object") return undefined;
142
+ activity = { ...frame.payload, kind: frame.type };
143
+ break;
144
+ default:
145
+ return undefined;
146
+ }
147
+ return { kind: "frame", frame: activity };
148
+ },
149
+ hook: {
150
+ via: "command",
151
+ payload: (call) => JSON.stringify({ type: "pre_tool", id: call.id, name: call.tool, input: call.args }),
152
+ allowed: (answer) => answer.exitCode === 0,
153
+ },
154
+ });
155
+
156
+ export const streamCliFixtures: AdapterConformanceFixtures = {
157
+ mode: "key",
158
+ home: {
159
+ hook: { path: ".stream-cli/settings.json", content: '{"hooks":{"preTool":["planted-hook"]}}' },
160
+ skill: { path: ".stream-cli/plugins/planted/skills/planted/SKILL.md", content: "planted skill" },
161
+ mcp: { path: ".stream-cli/mcp.json", content: '{"endpoint":{"command":"planted-server"}}' },
162
+ },
163
+ config: (cli) => ({ binary: cli.command[0]!, args: cli.command.slice(1) }),
164
+ recorded: fileURLToPath(new URL("./fixtures/stream-cli.json", import.meta.url)),
165
+ };