@intentius/chant-lexicon-fountain 0.124.97 → 0.124.99

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 (249) hide show
  1. package/dist/acp/command-line.d.ts +0 -1
  2. package/dist/acp/host.d.ts +0 -1
  3. package/dist/acp/index.d.ts +0 -1
  4. package/dist/acp/jsonrpc.d.ts +0 -1
  5. package/dist/acp/output.d.ts +0 -1
  6. package/dist/acp/protocol.d.ts +0 -1
  7. package/dist/acp/serve.d.ts +0 -1
  8. package/dist/acp/server.d.ts +0 -1
  9. package/dist/acp/turn.d.ts +0 -1
  10. package/dist/allowlist-refs.d.ts +0 -1
  11. package/dist/audit-entities.d.ts +0 -1
  12. package/dist/codegen/docs-cli.d.ts +0 -1
  13. package/dist/codegen/docs.d.ts +0 -1
  14. package/dist/codegen/generate-cli.d.ts +0 -1
  15. package/dist/codegen/generate-lexicon.d.ts +0 -1
  16. package/dist/codegen/generate-typescript.d.ts +0 -1
  17. package/dist/codegen/generate.d.ts +0 -1
  18. package/dist/codegen/naming.d.ts +0 -1
  19. package/dist/codegen/package.d.ts +0 -1
  20. package/dist/composites/box.d.ts +0 -1
  21. package/dist/composites/concierge-stack.d.ts +0 -1
  22. package/dist/composites/steward.d.ts +0 -1
  23. package/dist/config.d.ts +0 -1
  24. package/dist/coverage.d.ts +0 -1
  25. package/dist/deep-observe-hooks.d.ts +0 -1
  26. package/dist/deep-observe.d.ts +0 -1
  27. package/dist/describe-resources.d.ts +0 -1
  28. package/dist/detect.d.ts +0 -1
  29. package/dist/entity-props.d.ts +0 -1
  30. package/dist/export-resources.d.ts +0 -1
  31. package/dist/generated/index.d.ts +0 -1
  32. package/dist/generated/runtime.d.ts +0 -1
  33. package/dist/import/generator.d.ts +0 -1
  34. package/dist/import/local-agents.d.ts +0 -1
  35. package/dist/import/parser.d.ts +0 -1
  36. package/dist/index.d.ts +0 -1
  37. package/dist/init-templates.d.ts +0 -1
  38. package/dist/integrity.json +2 -2
  39. package/dist/lint/audit-catalog.d.ts +0 -1
  40. package/dist/lint/audit-lineage.d.ts +0 -1
  41. package/dist/lint/post-synth/ftn010-networking-explicit.d.ts +0 -1
  42. package/dist/lint/post-synth/ftn011-no-unrestricted-networking.d.ts +0 -1
  43. package/dist/lint/post-synth/ftn012-no-cloud-credential-env.d.ts +0 -1
  44. package/dist/lint/post-synth/ftn013-substitution-resolvable.d.ts +0 -1
  45. package/dist/lint/post-synth/ftn014-vault-shadowing.d.ts +0 -1
  46. package/dist/lint/post-synth/ftn015-mcp-secret-env-substitution.d.ts +0 -1
  47. package/dist/lint/post-synth/ftn016-runtime-model-valid.d.ts +0 -1
  48. package/dist/lint/post-synth/ftn017-unique-resource-names.d.ts +0 -1
  49. package/dist/lint/post-synth/ftn023-acp-runtime-command.d.ts +0 -1
  50. package/dist/lint/post-synth/ftn024-setup-timeout-range.d.ts +0 -1
  51. package/dist/lint/post-synth/ftn025-removed-upstream.d.ts +0 -1
  52. package/dist/lint/post-synth/index.d.ts +0 -1
  53. package/dist/lint/rules/ftn001-no-secret-literals.d.ts +0 -1
  54. package/dist/lint/rules/index.d.ts +0 -1
  55. package/dist/live-identity.d.ts +0 -1
  56. package/dist/lsp/completions.d.ts +0 -1
  57. package/dist/lsp/hover.d.ts +0 -1
  58. package/dist/lsp/lexicon-index.d.ts +0 -1
  59. package/dist/manifest.json +1 -1
  60. package/dist/op/activities/fountain-apply.d.ts +0 -1
  61. package/dist/op/activities/fountain-prompt.d.ts +0 -1
  62. package/dist/op/activities/fountain-run.d.ts +0 -1
  63. package/dist/op/activities/index.d.ts +0 -1
  64. package/dist/op/run-prompt.d.ts +0 -1
  65. package/dist/op/runtime.d.ts +0 -1
  66. package/dist/package-cli.d.ts +0 -1
  67. package/dist/plugin.d.ts +0 -1
  68. package/dist/reference-catalog.d.ts +0 -1
  69. package/dist/retired.d.ts +0 -1
  70. package/dist/serializer.d.ts +0 -1
  71. package/dist/spec/fetch.d.ts +0 -1
  72. package/dist/spec/parse.d.ts +0 -1
  73. package/dist/validate-cli.d.ts +0 -1
  74. package/dist/validate.d.ts +0 -1
  75. package/package.json +3 -4
  76. package/dist/acp/command-line.d.ts.map +0 -1
  77. package/dist/acp/host.d.ts.map +0 -1
  78. package/dist/acp/index.d.ts.map +0 -1
  79. package/dist/acp/jsonrpc.d.ts.map +0 -1
  80. package/dist/acp/output.d.ts.map +0 -1
  81. package/dist/acp/protocol.d.ts.map +0 -1
  82. package/dist/acp/serve.d.ts.map +0 -1
  83. package/dist/acp/server.d.ts.map +0 -1
  84. package/dist/acp/turn.d.ts.map +0 -1
  85. package/dist/allowlist-refs.d.ts.map +0 -1
  86. package/dist/audit-entities.d.ts.map +0 -1
  87. package/dist/codegen/docs-cli.d.ts.map +0 -1
  88. package/dist/codegen/docs.d.ts.map +0 -1
  89. package/dist/codegen/generate-cli.d.ts.map +0 -1
  90. package/dist/codegen/generate-lexicon.d.ts.map +0 -1
  91. package/dist/codegen/generate-typescript.d.ts.map +0 -1
  92. package/dist/codegen/generate.d.ts.map +0 -1
  93. package/dist/codegen/naming.d.ts.map +0 -1
  94. package/dist/codegen/package.d.ts.map +0 -1
  95. package/dist/composites/box.d.ts.map +0 -1
  96. package/dist/composites/concierge-stack.d.ts.map +0 -1
  97. package/dist/composites/steward.d.ts.map +0 -1
  98. package/dist/config.d.ts.map +0 -1
  99. package/dist/coverage.d.ts.map +0 -1
  100. package/dist/deep-observe-hooks.d.ts.map +0 -1
  101. package/dist/deep-observe.d.ts.map +0 -1
  102. package/dist/describe-resources.d.ts.map +0 -1
  103. package/dist/detect.d.ts.map +0 -1
  104. package/dist/entity-props.d.ts.map +0 -1
  105. package/dist/export-resources.d.ts.map +0 -1
  106. package/dist/generated/index.d.ts.map +0 -1
  107. package/dist/generated/runtime.d.ts.map +0 -1
  108. package/dist/import/generator.d.ts.map +0 -1
  109. package/dist/import/local-agents.d.ts.map +0 -1
  110. package/dist/import/parser.d.ts.map +0 -1
  111. package/dist/index.d.ts.map +0 -1
  112. package/dist/init-templates.d.ts.map +0 -1
  113. package/dist/lint/audit-catalog.d.ts.map +0 -1
  114. package/dist/lint/audit-lineage.d.ts.map +0 -1
  115. package/dist/lint/post-synth/ftn010-networking-explicit.d.ts.map +0 -1
  116. package/dist/lint/post-synth/ftn011-no-unrestricted-networking.d.ts.map +0 -1
  117. package/dist/lint/post-synth/ftn012-no-cloud-credential-env.d.ts.map +0 -1
  118. package/dist/lint/post-synth/ftn013-substitution-resolvable.d.ts.map +0 -1
  119. package/dist/lint/post-synth/ftn014-vault-shadowing.d.ts.map +0 -1
  120. package/dist/lint/post-synth/ftn015-mcp-secret-env-substitution.d.ts.map +0 -1
  121. package/dist/lint/post-synth/ftn016-runtime-model-valid.d.ts.map +0 -1
  122. package/dist/lint/post-synth/ftn017-unique-resource-names.d.ts.map +0 -1
  123. package/dist/lint/post-synth/ftn023-acp-runtime-command.d.ts.map +0 -1
  124. package/dist/lint/post-synth/ftn024-setup-timeout-range.d.ts.map +0 -1
  125. package/dist/lint/post-synth/ftn025-removed-upstream.d.ts.map +0 -1
  126. package/dist/lint/post-synth/index.d.ts.map +0 -1
  127. package/dist/lint/rules/ftn001-no-secret-literals.d.ts.map +0 -1
  128. package/dist/lint/rules/index.d.ts.map +0 -1
  129. package/dist/live-identity.d.ts.map +0 -1
  130. package/dist/lsp/completions.d.ts.map +0 -1
  131. package/dist/lsp/hover.d.ts.map +0 -1
  132. package/dist/lsp/lexicon-index.d.ts.map +0 -1
  133. package/dist/op/activities/fountain-apply.d.ts.map +0 -1
  134. package/dist/op/activities/fountain-prompt.d.ts.map +0 -1
  135. package/dist/op/activities/fountain-run.d.ts.map +0 -1
  136. package/dist/op/activities/index.d.ts.map +0 -1
  137. package/dist/op/run-prompt.d.ts.map +0 -1
  138. package/dist/op/runtime.d.ts.map +0 -1
  139. package/dist/package-cli.d.ts.map +0 -1
  140. package/dist/plugin.d.ts.map +0 -1
  141. package/dist/reference-catalog.d.ts.map +0 -1
  142. package/dist/retired.d.ts.map +0 -1
  143. package/dist/serializer.d.ts.map +0 -1
  144. package/dist/spec/fetch.d.ts.map +0 -1
  145. package/dist/spec/parse.d.ts.map +0 -1
  146. package/dist/validate-cli.d.ts.map +0 -1
  147. package/dist/validate.d.ts.map +0 -1
  148. package/src/acp/acp.test.ts +0 -850
  149. package/src/acp/command-line.ts +0 -192
  150. package/src/acp/gate-resolution.test.ts +0 -81
  151. package/src/acp/host.ts +0 -121
  152. package/src/acp/index.ts +0 -64
  153. package/src/acp/jsonrpc.ts +0 -239
  154. package/src/acp/output.ts +0 -59
  155. package/src/acp/protocol.ts +0 -164
  156. package/src/acp/serve.ts +0 -67
  157. package/src/acp/server.ts +0 -376
  158. package/src/acp/turn.ts +0 -349
  159. package/src/allowlist-refs.ts +0 -138
  160. package/src/audit-entities.test.ts +0 -157
  161. package/src/audit-entities.ts +0 -43
  162. package/src/codegen/docs-cli.ts +0 -7
  163. package/src/codegen/docs.ts +0 -139
  164. package/src/codegen/generate-cli.ts +0 -8
  165. package/src/codegen/generate-lexicon.ts +0 -70
  166. package/src/codegen/generate-typescript.ts +0 -69
  167. package/src/codegen/generate.ts +0 -109
  168. package/src/codegen/naming.ts +0 -45
  169. package/src/codegen/package.ts +0 -36
  170. package/src/composites/box.ts +0 -321
  171. package/src/composites/composites.test.ts +0 -530
  172. package/src/composites/concierge-stack.ts +0 -71
  173. package/src/composites/steward.ts +0 -285
  174. package/src/config.test.ts +0 -160
  175. package/src/config.ts +0 -148
  176. package/src/coverage.test.ts +0 -127
  177. package/src/coverage.ts +0 -278
  178. package/src/deep-observe-hooks.ts +0 -238
  179. package/src/deep-observe.test.ts +0 -684
  180. package/src/deep-observe.ts +0 -346
  181. package/src/describe-resources.test.ts +0 -215
  182. package/src/describe-resources.ts +0 -181
  183. package/src/detect.ts +0 -43
  184. package/src/entity-props.ts +0 -22
  185. package/src/export-resources.ts +0 -159
  186. package/src/generated/index.d.ts +0 -87
  187. package/src/generated/index.ts +0 -10
  188. package/src/generated/runtime.ts +0 -4
  189. package/src/import/generator.ts +0 -128
  190. package/src/import/local-agents.test.ts +0 -216
  191. package/src/import/local-agents.ts +0 -364
  192. package/src/import/parser.ts +0 -90
  193. package/src/import/roundtrip.test.ts +0 -256
  194. package/src/index.ts +0 -68
  195. package/src/init-templates.e2e.test.ts +0 -171
  196. package/src/init-templates.ts +0 -223
  197. package/src/lint/audit-catalog.ts +0 -145
  198. package/src/lint/audit-lineage.ts +0 -15
  199. package/src/lint/post-synth/ftn010-networking-explicit.ts +0 -37
  200. package/src/lint/post-synth/ftn011-no-unrestricted-networking.ts +0 -36
  201. package/src/lint/post-synth/ftn012-no-cloud-credential-env.ts +0 -58
  202. package/src/lint/post-synth/ftn013-substitution-resolvable.ts +0 -93
  203. package/src/lint/post-synth/ftn014-vault-shadowing.ts +0 -61
  204. package/src/lint/post-synth/ftn015-mcp-secret-env-substitution.ts +0 -49
  205. package/src/lint/post-synth/ftn016-runtime-model-valid.ts +0 -89
  206. package/src/lint/post-synth/ftn017-unique-resource-names.ts +0 -43
  207. package/src/lint/post-synth/ftn023-acp-runtime-command.ts +0 -58
  208. package/src/lint/post-synth/ftn024-setup-timeout-range.ts +0 -48
  209. package/src/lint/post-synth/ftn025-removed-upstream.ts +0 -65
  210. package/src/lint/post-synth/index.ts +0 -27
  211. package/src/lint/post-synth/post-synth.test.ts +0 -261
  212. package/src/lint/rules/ftn001-no-secret-literals.ts +0 -126
  213. package/src/lint/rules/index.ts +0 -7
  214. package/src/lint/rules/rules.test.ts +0 -161
  215. package/src/live-identity.ts +0 -153
  216. package/src/lsp/completions.test.ts +0 -67
  217. package/src/lsp/completions.ts +0 -11
  218. package/src/lsp/hover.test.ts +0 -65
  219. package/src/lsp/hover.ts +0 -68
  220. package/src/lsp/lexicon-index.ts +0 -46
  221. package/src/op/activities/fountain-apply.test.ts +0 -666
  222. package/src/op/activities/fountain-apply.ts +0 -458
  223. package/src/op/activities/fountain-prompt.test.ts +0 -117
  224. package/src/op/activities/fountain-prompt.ts +0 -197
  225. package/src/op/activities/fountain-run.test.ts +0 -295
  226. package/src/op/activities/fountain-run.ts +0 -292
  227. package/src/op/activities/index.ts +0 -38
  228. package/src/op/activities/op-runtime.test.ts +0 -194
  229. package/src/op/run-prompt.ts +0 -118
  230. package/src/op/runtime.test.ts +0 -1471
  231. package/src/op/runtime.ts +0 -1464
  232. package/src/package-cli.ts +0 -26
  233. package/src/plugin.test.ts +0 -88
  234. package/src/plugin.ts +0 -234
  235. package/src/reference-catalog.ts +0 -27
  236. package/src/retired.ts +0 -55
  237. package/src/serializer.test.ts +0 -262
  238. package/src/serializer.ts +0 -191
  239. package/src/skills/chant-fountain-locked-sandboxes.md +0 -34
  240. package/src/skills/chant-fountain-ops.md +0 -166
  241. package/src/skills/chant-fountain-secrets.md +0 -29
  242. package/src/skills/chant-fountain.md +0 -69
  243. package/src/spec/fetch.ts +0 -113
  244. package/src/spec/parse.ts +0 -484
  245. package/src/spec/spec.e2e.test.ts +0 -171
  246. package/src/validate-cli.ts +0 -13
  247. package/src/validate.ts +0 -39
  248. /package/{src → dist}/generated/lexicon-fountain.json +0 -0
  249. /package/{src → dist}/spec/fountain-openapi.snapshot.json +0 -0
package/src/acp/output.ts DELETED
@@ -1,59 +0,0 @@
1
- /**
2
- * Capturing what a chant command prints, so a turn can stream it (#2125).
3
- *
4
- * chant's own handlers and its activities print through `console.log` /
5
- * `console.error`, which means the process's stdout and stderr are where a
6
- * step's output actually appears — there is no per-step output channel on the
7
- * executor to subscribe to instead. So a turn borrows both writers for its
8
- * duration and forwards every chunk as an `agent_message_chunk`.
9
- *
10
- * Two consequences worth stating rather than discovering:
11
- *
12
- * - The `chant acp` process writes the protocol on stdout, so a turn MUST
13
- * hold this capture over everything it runs. A stray `console.log` reaching
14
- * the real stdout mid-turn is an unparseable line to the client.
15
- * - The capture is process-wide, so turns are serialized (see
16
- * ./server.ts). One stdio connection running one command at a time is the
17
- * honest shape anyway.
18
- *
19
- * Redaction is deliberately absent. A step's output is the environment's
20
- * output, and fountain redacts a thread's secrets on the way in — the
21
- * documented division of labour in ../skills/chant-fountain.md. This server
22
- * never reads or prints the environment it inherits.
23
- */
24
-
25
- /** Where a captured chunk came from. */
26
- export type OutputStream = "stdout" | "stderr";
27
-
28
- /** Run `fn` with both process writers forwarded to `onChunk`, and restore them after. */
29
- export async function withCapturedOutput<T>(
30
- onChunk: (text: string, stream: OutputStream) => void,
31
- fn: () => Promise<T>,
32
- ): Promise<T> {
33
- const realOut = process.stdout.write.bind(process.stdout);
34
- const realErr = process.stderr.write.bind(process.stderr);
35
-
36
- const intercept =
37
- (stream: OutputStream) =>
38
- (chunk: unknown, encoding?: unknown, cb?: unknown): boolean => {
39
- const text =
40
- typeof chunk === "string"
41
- ? chunk
42
- : Buffer.isBuffer(chunk)
43
- ? chunk.toString("utf8")
44
- : String(chunk);
45
- if (text.length > 0) onChunk(text, stream);
46
- const done = typeof encoding === "function" ? encoding : cb;
47
- if (typeof done === "function") (done as () => void)();
48
- return true;
49
- };
50
-
51
- process.stdout.write = intercept("stdout") as typeof process.stdout.write;
52
- process.stderr.write = intercept("stderr") as typeof process.stderr.write;
53
- try {
54
- return await fn();
55
- } finally {
56
- process.stdout.write = realOut;
57
- process.stderr.write = realErr;
58
- }
59
- }
@@ -1,164 +0,0 @@
1
- /**
2
- * The Agent Client Protocol wire shapes `chant acp` speaks (#2125).
3
- *
4
- * ACP (<https://agentclientprotocol.com>) is JSON-RPC 2.0 between a *client*
5
- * — an editor, or fountain — and an *agent*. chant is the agent half here: it
6
- * is spawned, it answers `initialize`, it opens sessions, and every prompt it
7
- * receives is one chant command line.
8
- *
9
- * These are hand-written rather than pulled from a package on purpose. The
10
- * subset an agent has to speak is small enough to state in one file, and a
11
- * dependency for it would be a dependency in every project that declares the
12
- * fountain lexicon. Field names match what fountain's own ACP client sends
13
- * and expects (fountain ADR 0014, `cli/internal/acp`), which is the same
14
- * vocabulary the specification defines — a client of ours that is not
15
- * fountain sees nothing fountain-specific.
16
- */
17
-
18
- /** The ACP major version this agent speaks. */
19
- export const ACP_PROTOCOL_VERSION = 1;
20
-
21
- /** JSON-RPC 2.0 error codes, plus the one ACP adds. */
22
- export const JSONRPC_PARSE_ERROR = -32700;
23
- export const JSONRPC_INVALID_REQUEST = -32600;
24
- export const JSONRPC_METHOD_NOT_FOUND = -32601;
25
- export const JSONRPC_INVALID_PARAMS = -32602;
26
- export const JSONRPC_INTERNAL_ERROR = -32603;
27
-
28
- /**
29
- * How a turn ended.
30
- *
31
- * `end_turn`, `cancelled` and `refusal` are the specification's.
32
- *
33
- * `waiting` is not: it is what `--durable-requests` returns for a run that
34
- * stopped at a gate whose `session/request_permission` will be answered after
35
- * this turn is over (BinaryBourbon/fountain#1635). Until that ships, no client
36
- * can answer such a request within the turn, and reporting `end_turn` for a
37
- * run that has not finished would be a lie a client renders as success. The
38
- * flag is off by default for exactly this reason — see ../acp/server.ts.
39
- */
40
- export type StopReason = "end_turn" | "cancelled" | "refusal" | "waiting";
41
-
42
- /** A tool call's lifecycle, as a client renders it. */
43
- export type ToolCallStatus = "pending" | "in_progress" | "completed" | "failed";
44
-
45
- /** One text block in a prompt or an update. */
46
- export interface TextContent {
47
- type: "text";
48
- text: string;
49
- }
50
-
51
- /** `initialize` params. */
52
- export interface InitializeParams {
53
- protocolVersion?: number;
54
- clientCapabilities?: unknown;
55
- }
56
-
57
- /** `initialize` result. */
58
- export interface InitializeResult {
59
- protocolVersion: number;
60
- agentInfo: { name: string; title: string; version: string };
61
- agentCapabilities: {
62
- loadSession: boolean;
63
- promptCapabilities: { image: boolean; audio: boolean; embeddedContext: boolean };
64
- /** `resume` present: the agent answers `session/resume`. */
65
- sessionCapabilities: { resume: Record<string, never> };
66
- };
67
- authMethods: unknown[];
68
- }
69
-
70
- /** `session/new` params. `mcpServers` is accepted and ignored — see the server's module doc. */
71
- export interface NewSessionParams {
72
- cwd?: string;
73
- mcpServers?: unknown[];
74
- _meta?: Record<string, unknown>;
75
- }
76
-
77
- /** `session/new` result. */
78
- export interface NewSessionResult {
79
- sessionId: string;
80
- }
81
-
82
- /** `session/resume` params: a session an earlier process opened, and the cwd to open it in. */
83
- export interface ResumeSessionParams {
84
- sessionId: string;
85
- cwd?: string;
86
- mcpServers?: unknown[];
87
- _meta?: Record<string, unknown>;
88
- }
89
-
90
- /** `session/resume` result. Nothing to report: there is no mode or model to restore. */
91
- export type ResumeSessionResult = Record<string, never>;
92
-
93
- /**
94
- * The out-of-band bag a client attaches to `session/prompt` to resume a
95
- * durable permission request (#2125). ACP's `_meta` is the extension point
96
- * fountain already uses for its own `channelId`, so a resume needs no method
97
- * of its own and a client that does not do durable requests never sends it.
98
- */
99
- export interface ChantPromptMeta {
100
- /** Answers a `session/request_permission` this agent sent in an earlier turn. */
101
- permission?: { requestId: string; optionId: string };
102
- }
103
-
104
- /** `session/prompt` params. */
105
- export interface PromptParams {
106
- sessionId: string;
107
- prompt: Array<TextContent | { type: string; [k: string]: unknown }>;
108
- _meta?: { chant?: ChantPromptMeta; [k: string]: unknown };
109
- }
110
-
111
- /** `session/prompt` result. */
112
- export interface PromptResult {
113
- stopReason: StopReason;
114
- }
115
-
116
- /** `session/cancel` params. A notification: the pending prompt is what answers. */
117
- export interface CancelParams {
118
- sessionId: string;
119
- }
120
-
121
- /** The `session/update` variants this agent emits. */
122
- export type SessionUpdate =
123
- | { sessionUpdate: "agent_message_chunk"; content: TextContent }
124
- | {
125
- sessionUpdate: "tool_call";
126
- toolCallId: string;
127
- title: string;
128
- kind: "execute";
129
- status: ToolCallStatus;
130
- rawInput?: Record<string, unknown>;
131
- }
132
- | {
133
- sessionUpdate: "tool_call_update";
134
- toolCallId: string;
135
- status: ToolCallStatus;
136
- content?: TextContent[];
137
- rawOutput?: Record<string, unknown>;
138
- };
139
-
140
- /** `session/update` notification params. */
141
- export interface SessionNotification {
142
- sessionId: string;
143
- update: SessionUpdate;
144
- }
145
-
146
- /** One choice offered on a `session/request_permission`. */
147
- export interface PermissionOption {
148
- optionId: string;
149
- name: string;
150
- kind: "allow_once" | "allow_always" | "reject_once" | "reject_always";
151
- }
152
-
153
- /** `session/request_permission` params. */
154
- export interface RequestPermissionParams {
155
- sessionId: string;
156
- toolCall: { toolCallId: string; title: string; kind: "execute" };
157
- options: PermissionOption[];
158
- _meta?: Record<string, unknown>;
159
- }
160
-
161
- /** `session/request_permission` result. */
162
- export interface RequestPermissionResult {
163
- outcome: { outcome: "selected"; optionId: string } | { outcome: "cancelled" };
164
- }
package/src/acp/serve.ts DELETED
@@ -1,67 +0,0 @@
1
- /**
2
- * `chant acp` on the process's own stdio (#2125).
3
- *
4
- * Split from ./index.ts so mounting the command group costs nothing: this
5
- * module is imported only once a client has actually spawned the agent.
6
- *
7
- * stdout is the protocol. Nothing else may write to it for the life of the
8
- * process — every turn holds the output capture (./output.ts) precisely so a
9
- * command's `console.log` cannot land between two JSON-RPC lines.
10
- */
11
-
12
- import { readFileSync } from "node:fs";
13
- import { setGateOrigin } from "@intentius/chant/lifecycle/gate-origin";
14
- import { setStewardTurn } from "@intentius/chant/op/steward-turn";
15
- import { dirname, join } from "node:path";
16
- import { fileURLToPath } from "node:url";
17
- import { AcpServer } from "./server";
18
- import { streamTransport } from "./jsonrpc";
19
-
20
- /** Serve until the client closes stdin, which is how it says the connection is over. */
21
- export async function serveAcpOverStdio(opts: { durableRequests?: boolean; steward?: string } = {}): Promise<void> {
22
- // chant#2384 — every prompt this session carries is authored by the model,
23
- // and `approve` is a verb in chant's registry like any other, so nothing in
24
- // the transport stops `chant run <op>` being followed by
25
- // `chant approve <op> <gate>` as the next prompt. Declaring the channel is
26
- // what makes the gate ledger able to tell that apart from a person at a
27
- // shell; the same-origin rule then refuses it.
28
- setGateOrigin("acp");
29
-
30
- // chant#2749 — the session is a steward's. A decision point an Op asks during
31
- // a turn names the steward, makes its model call through the steward's
32
- // brokered capability, and is left open for a person; `points answer` from
33
- // this session is refused, as the gate's resolution is above.
34
- if (opts.steward) setStewardTurn({ steward: opts.steward });
35
-
36
- // chant#3539 — fountain gives the command it spawns the conversation's id
37
- // in `FOUNTAIN_CONVERSATION_ID` (process env only, never on disk), and
38
- // `chant run <op> --on fountain` names the run by that same id. Naming the
39
- // sandbox's runs by it joins the two: the run record written here carries
40
- // the id the caller's `chant run status` reports.
41
- const conversationId = process.env.FOUNTAIN_CONVERSATION_ID?.trim();
42
-
43
- const server = new AcpServer({
44
- durableRequests: opts.durableRequests ?? false,
45
- version: lexiconVersion(),
46
- ...(conversationId ? { runId: conversationId } : {}),
47
- });
48
-
49
- const transport = streamTransport(process.stdin, process.stdout);
50
- server.connect(transport);
51
-
52
- await new Promise<void>((resolve) => {
53
- process.stdin.on("end", resolve);
54
- process.stdin.on("close", resolve);
55
- });
56
- }
57
-
58
- /** The lexicon's own version, reported as `agentInfo.version`. */
59
- function lexiconVersion(): string {
60
- try {
61
- const pkgPath = join(dirname(dirname(dirname(fileURLToPath(import.meta.url)))), "package.json");
62
- const pkg = JSON.parse(readFileSync(pkgPath, "utf8")) as { version?: string };
63
- return pkg.version ?? "dev";
64
- } catch {
65
- return "dev";
66
- }
67
- }
package/src/acp/server.ts DELETED
@@ -1,376 +0,0 @@
1
- /**
2
- * `chant acp` — chant as an Agent Client Protocol agent (#2125, epic #2115).
3
- *
4
- * An editor or fountain spawns this process, speaks JSON-RPC 2.0 over stdio,
5
- * and gets `session/update` notifications back. Every prompt is one chant
6
- * command line, so a fountain thread of turns reads as an environment's shell
7
- * history, and a run's steps arrive as tool calls a client already knows how
8
- * to render.
9
- *
10
- * It is fountain-agnostic by construction. Nothing here imports the fountain
11
- * API, a fountain type, or a fountain URL; it lives in this lexicon because
12
- * fountain is its first host (epic #2115's steward runs `runtime: "acp"`,
13
- * `runtime_command: "chant acp"`), and any ACP client can drive it unchanged.
14
- *
15
- * Three deliberate limits:
16
- *
17
- * - **Turns are serialized.** A turn borrows the process writers to stream a
18
- * command's output (./output.ts) and changes into the session's `cwd`
19
- * (./turn.ts). Both are process-wide, so two turns at once would interleave.
20
- * One stdio connection running one command at a time is the honest shape.
21
- * - **`mcpServers` from `session/new` is ignored.** chant's tools are its own
22
- * verbs; there is nothing here for an MCP server to extend.
23
- * - **The server never reads or prints the environment it inherits.** A step's
24
- * output is streamed verbatim, secrets included, because redaction belongs
25
- * to the thread that stores it — fountain redacts on the way in (see
26
- * ../skills/chant-fountain.md).
27
- */
28
-
29
- import { randomUUID } from "node:crypto";
30
- import {
31
- JsonRpcError,
32
- JsonRpcPeer,
33
- type JsonRpcHandler,
34
- type LineTransport,
35
- } from "./jsonrpc";
36
- import {
37
- ACP_PROTOCOL_VERSION,
38
- JSONRPC_INVALID_PARAMS,
39
- JSONRPC_METHOD_NOT_FOUND,
40
- type CancelParams,
41
- type InitializeParams,
42
- type InitializeResult,
43
- type NewSessionParams,
44
- type NewSessionResult,
45
- type PermissionOption,
46
- type PromptParams,
47
- type PromptResult,
48
- type RequestPermissionParams,
49
- type ResumeSessionParams,
50
- type ResumeSessionResult,
51
- type RequestPermissionResult,
52
- type SessionNotification,
53
- type SessionUpdate,
54
- type ToolCallStatus,
55
- } from "./protocol";
56
- import { parseChantCommandLine } from "./command-line";
57
- import { createChantHost, ACP_APPROVER, type ChantHost } from "./host";
58
- import { runTurn, ALLOW_OPTION, REJECT_OPTION, type PendingPermission, type TurnSink } from "./turn";
59
-
60
- /** How `chant acp` is configured, and where a test substitutes its own project. */
61
- export interface AcpServerOptions {
62
- /**
63
- * Behind BinaryBourbon/fountain#1635: carry a gate to the client as a
64
- * `session/request_permission` and end the turn `waiting`, instead of
65
- * replying with the approve line and ending it. Default off, because no
66
- * client can answer a request that outlives a turn until #1635 ships.
67
- */
68
- durableRequests?: boolean;
69
- /** Version reported as `agentInfo`. */
70
- version?: string;
71
- /** Builds the project-facing half of a session. Substituted by the conformance test. */
72
- createHost?: (cwd: string) => ChantHost;
73
- /** Mints permission request ids. Injected so a test can pin them. */
74
- newRequestId?: () => string;
75
- /**
76
- * The id every Op run in this process is named by (#3539). On fountain it
77
- * is the conversation id the sandbox's environment carries
78
- * (`FOUNTAIN_CONVERSATION_ID`), so the run record the sandbox writes and
79
- * the run `chant run status --on fountain` reports have the same id.
80
- * Omitted, the local runtime mints one per run.
81
- */
82
- runId?: string;
83
- }
84
-
85
- /** One open session: a working directory, the turn in flight, and any gate awaiting an answer. */
86
- interface Session {
87
- id: string;
88
- host: ChantHost;
89
- controller?: AbortController;
90
- permissions: Map<string, PendingPermission>;
91
- /**
92
- * A `session/request_permission` the client answered inside the turn that
93
- * sent it, keyed by request id. Kept so a resume prompt naming only the
94
- * request id still knows what the client chose.
95
- */
96
- earlyAnswers: Map<string, string>;
97
- }
98
-
99
- export class AcpServer implements JsonRpcHandler {
100
- private peer: JsonRpcPeer | undefined;
101
- private readonly sessions = new Map<string, Session>();
102
- private readonly durableRequests: boolean;
103
- private readonly version: string;
104
- private readonly createHost: (cwd: string) => ChantHost;
105
- private readonly newRequestId: () => string;
106
- private readonly runId: string | undefined;
107
- /** Serializes turns — see the module doc. */
108
- private queue: Promise<unknown> = Promise.resolve();
109
-
110
- constructor(opts: AcpServerOptions = {}) {
111
- this.durableRequests = opts.durableRequests ?? false;
112
- this.version = opts.version ?? "dev";
113
- this.createHost = opts.createHost ?? createChantHost;
114
- this.newRequestId = opts.newRequestId ?? (() => randomUUID());
115
- this.runId = opts.runId !== undefined && opts.runId !== "" ? opts.runId : undefined;
116
- }
117
-
118
- /** Serve one connection until it closes. */
119
- connect(transport: LineTransport): JsonRpcPeer {
120
- this.peer = new JsonRpcPeer(transport, this);
121
- return this.peer;
122
- }
123
-
124
- async request(method: string, params: unknown): Promise<unknown> {
125
- switch (method) {
126
- case "initialize":
127
- return this.initialize((params ?? {}) as InitializeParams);
128
- case "session/new":
129
- return this.newSession((params ?? {}) as NewSessionParams);
130
- case "session/resume":
131
- return this.resumeSession((params ?? {}) as ResumeSessionParams);
132
- case "session/prompt":
133
- return this.enqueue(() => this.prompt((params ?? {}) as PromptParams));
134
- default:
135
- throw new JsonRpcError(JSONRPC_METHOD_NOT_FOUND, `method not found: ${method}`);
136
- }
137
- }
138
-
139
- notify(method: string, params: unknown): void {
140
- if (method !== "session/cancel") return;
141
- const { sessionId } = (params ?? {}) as CancelParams;
142
- // A notification, not a request: the pending `session/prompt` is what
143
- // answers, with `cancelled`. Aborting the controller stops the in-flight
144
- // activity through the executor's own signal, which then runs the Op's
145
- // `onFailure` phases before the run settles.
146
- this.sessions.get(sessionId)?.controller?.abort();
147
- }
148
-
149
- private enqueue<T>(fn: () => Promise<T>): Promise<T> {
150
- const next = this.queue.then(fn, fn);
151
- this.queue = next.catch(() => undefined);
152
- return next;
153
- }
154
-
155
- private initialize(params: InitializeParams): InitializeResult {
156
- // Negotiate down: answer with the highest version both ends speak.
157
- const offered = params.protocolVersion ?? ACP_PROTOCOL_VERSION;
158
- const negotiated =
159
- offered <= 0 || offered > ACP_PROTOCOL_VERSION ? ACP_PROTOCOL_VERSION : offered;
160
- return {
161
- protocolVersion: negotiated,
162
- agentInfo: { name: "chant", title: "chant", version: this.version },
163
- agentCapabilities: {
164
- // `session/load` is not implemented: a chant session is a working
165
- // directory and nothing else, so there is no transcript to replay
166
- // that the run ledger does not already hold.
167
- loadSession: false,
168
- // `session/resume` is: fountain spawns `chant acp` afresh for every
169
- // turn and resumes the conversation's session from the second turn
170
- // on, and an agent that offers no way back in fails that turn
171
- // before its prompt is sent.
172
- sessionCapabilities: { resume: {} },
173
- // A chant command line is text. Claiming otherwise would invite a
174
- // client to send bytes this agent would have to drop.
175
- promptCapabilities: { image: false, audio: false, embeddedContext: false },
176
- },
177
- // No credentials: this agent runs as whoever spawned it, against the
178
- // checkout it was pointed at.
179
- authMethods: [],
180
- };
181
- }
182
-
183
- private newSession(params: NewSessionParams): NewSessionResult {
184
- const id = randomUUID();
185
- this.openSession(id, params.cwd);
186
- return { sessionId: id };
187
- }
188
-
189
- /**
190
- * Take up a session by the id a client already holds. A chant session is a
191
- * working directory and nothing else, so one this process never opened —
192
- * the usual case, since a client spawns a new process per turn — is opened
193
- * again under the same id with the cwd the client sends. A gate a previous
194
- * process asked about under `--durable-requests` is not carried over: its
195
- * answer finds no request waiting and says to prompt the line again.
196
- */
197
- private resumeSession(params: ResumeSessionParams): ResumeSessionResult {
198
- if (typeof params.sessionId !== "string" || params.sessionId.length === 0) {
199
- throw new JsonRpcError(JSONRPC_INVALID_PARAMS, "session/resume needs a sessionId");
200
- }
201
- if (!this.sessions.has(params.sessionId)) this.openSession(params.sessionId, params.cwd);
202
- return {};
203
- }
204
-
205
- private openSession(id: string, cwd: string | undefined): void {
206
- this.sessions.set(id, {
207
- id,
208
- host: this.createHost(cwd && cwd.length > 0 ? cwd : process.cwd()),
209
- permissions: new Map(),
210
- earlyAnswers: new Map(),
211
- });
212
- }
213
-
214
- private async prompt(params: PromptParams): Promise<PromptResult> {
215
- const session = this.sessions.get(params.sessionId);
216
- if (!session) {
217
- throw new JsonRpcError(JSONRPC_INVALID_PARAMS, `unknown session "${params.sessionId}"`);
218
- }
219
-
220
- const sink = this.sinkFor(session);
221
- const resume = params._meta?.chant?.permission;
222
- if (resume) return this.resume(session, sink, resume);
223
-
224
- const text = promptText(params);
225
- return this.runCommandLine(session, sink, text);
226
- }
227
-
228
- /**
229
- * Answer a `session/request_permission` this agent sent in an earlier turn.
230
- *
231
- * Allowing writes the gate resolution the way `chant approve` does — the
232
- * fact is chant's, not the protocol's — and re-runs the command line that
233
- * hit the gate, which now walks through it.
234
- */
235
- private async resume(
236
- session: Session,
237
- sink: TurnSink,
238
- resume: { requestId: string; optionId: string },
239
- ): Promise<PromptResult> {
240
- const pending = session.permissions.get(resume.requestId);
241
- if (!pending) {
242
- sink.message(
243
- `No gate is waiting on request "${resume.requestId}" in this session.\n` +
244
- `Prompt the command line again to re-evaluate its gates.\n`,
245
- );
246
- return { stopReason: "end_turn" };
247
- }
248
-
249
- const optionId = resume.optionId || session.earlyAnswers.get(resume.requestId) || REJECT_OPTION;
250
- session.permissions.delete(resume.requestId);
251
- session.earlyAnswers.delete(resume.requestId);
252
-
253
- if (optionId !== ALLOW_OPTION) {
254
- sink.message(
255
- `Gate "${pending.gate}" on Op "${pending.op}" was rejected. Nothing was run.\n`,
256
- );
257
- return { stopReason: "end_turn" };
258
- }
259
-
260
- try {
261
- await session.host.resolveGate(pending.op, pending.gate, ACP_APPROVER);
262
- } catch (err) {
263
- sink.message(
264
- `Could not record the resolution for gate "${pending.gate}": ` +
265
- `${err instanceof Error ? err.message : String(err)}\n`,
266
- );
267
- return { stopReason: "refusal" };
268
- }
269
-
270
- sink.message(`Gate "${pending.gate}" resolved by ${ACP_APPROVER}. Re-running.\n`);
271
- return this.runCommandLine(session, sink, pending.prompt);
272
- }
273
-
274
- private async runCommandLine(
275
- session: Session,
276
- sink: TurnSink,
277
- text: string,
278
- ): Promise<PromptResult> {
279
- const parsed = await parseChantCommandLine(text);
280
- if (!parsed.ok) {
281
- // Refused before anything ran — the error block is the whole turn.
282
- sink.message(`${parsed.message}\n\n${parsed.hint}\n`);
283
- return { stopReason: "refusal" };
284
- }
285
-
286
- const controller = new AbortController();
287
- session.controller = controller;
288
- try {
289
- const outcome = await runTurn({
290
- host: session.host,
291
- command: parsed.command,
292
- promptText: text,
293
- sink,
294
- signal: controller.signal,
295
- durableRequests: this.durableRequests,
296
- newRequestId: this.newRequestId,
297
- ...(this.runId ? { runId: this.runId } : {}),
298
- });
299
- if (outcome.permission) {
300
- session.permissions.set(outcome.permission.requestId, { ...outcome.permission });
301
- }
302
- return { stopReason: outcome.stopReason };
303
- } finally {
304
- session.controller = undefined;
305
- }
306
- }
307
-
308
- /** The client-facing half of a turn, bound to one session. */
309
- private sinkFor(session: Session): TurnSink {
310
- const update = (u: SessionUpdate): void => {
311
- const notification: SessionNotification = { sessionId: session.id, update: u };
312
- this.peer?.notify("session/update", notification);
313
- };
314
-
315
- return {
316
- message(text) {
317
- update({ sessionUpdate: "agent_message_chunk", content: { type: "text", text } });
318
- },
319
- toolCall(id, title, rawInput) {
320
- update({
321
- sessionUpdate: "tool_call",
322
- toolCallId: id,
323
- title,
324
- kind: "execute",
325
- status: "pending",
326
- rawInput,
327
- });
328
- },
329
- toolCallUpdate(id, status: ToolCallStatus, detail) {
330
- update({
331
- sessionUpdate: "tool_call_update",
332
- toolCallId: id,
333
- status,
334
- ...(detail?.text ? { content: [{ type: "text" as const, text: detail.text }] } : {}),
335
- ...(detail?.rawOutput ? { rawOutput: detail.rawOutput } : {}),
336
- });
337
- },
338
- requestPermission: async (
339
- requestId: string,
340
- title: string,
341
- options: PermissionOption[],
342
- meta: Record<string, unknown>,
343
- ) => {
344
- const params: RequestPermissionParams = {
345
- sessionId: session.id,
346
- toolCall: { toolCallId: requestId, title, kind: "execute" },
347
- options,
348
- _meta: meta,
349
- };
350
- const answer = this.peer?.request("session/request_permission", params);
351
- if (!answer) return;
352
- // Not awaited: the whole point of a durable request is that it can be
353
- // answered after the turn ends (BinaryBourbon/fountain#1635). A client
354
- // that answers within the turn has its choice remembered, so a resume
355
- // prompt naming only the request id can use it.
356
- void answer.then(
357
- (raw) => {
358
- const outcome = (raw as RequestPermissionResult | undefined)?.outcome;
359
- if (outcome?.outcome !== "selected") return;
360
- session.earlyAnswers.set(requestId, outcome.optionId);
361
- },
362
- () => undefined,
363
- );
364
- },
365
- };
366
- }
367
- }
368
-
369
- /** Every text block of a prompt, joined — a command line is one line of text. */
370
- function promptText(params: PromptParams): string {
371
- return (params.prompt ?? [])
372
- .filter((block): block is { type: "text"; text: string } => block?.type === "text")
373
- .map((block) => block.text)
374
- .join(" ")
375
- .trim();
376
- }