stitchkit 0.122.2 → 0.123.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 (194) hide show
  1. package/CHANGELOG.md +80 -0
  2. package/dist/browser/client.d.ts.map +1 -1
  3. package/dist/browser/contract-identity.d.ts +21 -0
  4. package/dist/browser/contract-identity.d.ts.map +1 -0
  5. package/dist/browser/unknown-operation.d.ts +3 -0
  6. package/dist/browser/unknown-operation.d.ts.map +1 -0
  7. package/dist/contract/define.d.ts +6 -2
  8. package/dist/contract/define.d.ts.map +1 -1
  9. package/dist/contract/endpoint-capabilities.d.ts.map +1 -1
  10. package/dist/contract/errors.d.ts +4 -0
  11. package/dist/contract/errors.d.ts.map +1 -1
  12. package/dist/contract/fingerprint.d.ts +51 -0
  13. package/dist/contract/fingerprint.d.ts.map +1 -0
  14. package/dist/contract/identity.d.ts +21 -0
  15. package/dist/contract/identity.d.ts.map +1 -0
  16. package/dist/contract/stream.d.ts +32 -0
  17. package/dist/contract/stream.d.ts.map +1 -1
  18. package/dist/entrypoints/agent-runtime/browser.js +2 -2
  19. package/dist/entrypoints/agent-runtime/coding-tools.js +11 -11
  20. package/dist/entrypoints/agent-runtime/harness.js +12 -12
  21. package/dist/entrypoints/agent-runtime/openrouter.js +1 -1
  22. package/dist/entrypoints/agent-runtime/realtime.js +2 -2
  23. package/dist/entrypoints/agent-runtime/sandbox.js +11 -11
  24. package/dist/entrypoints/agent-runtime/sqlite/bun.js +15 -15
  25. package/dist/entrypoints/agent-runtime/sqlite/node.js +15 -15
  26. package/dist/entrypoints/agent-runtime/testing.js +15 -15
  27. package/dist/entrypoints/agent-runtime.js +22 -22
  28. package/dist/entrypoints/application/diagnostic-journal.js +5 -5
  29. package/dist/entrypoints/application/directory-inbox.js +5 -5
  30. package/dist/entrypoints/application/grammy.js +1 -1
  31. package/dist/entrypoints/application.js +7 -7
  32. package/dist/entrypoints/cli/publish.js +5 -5
  33. package/dist/entrypoints/cli.d.ts +1 -1
  34. package/dist/entrypoints/cli.d.ts.map +1 -1
  35. package/dist/entrypoints/cli.js +20 -17
  36. package/dist/entrypoints/contract.d.ts +2 -0
  37. package/dist/entrypoints/contract.d.ts.map +1 -1
  38. package/dist/entrypoints/contract.js +11 -5
  39. package/dist/entrypoints/files/packaging.d.ts +1 -0
  40. package/dist/entrypoints/files/packaging.d.ts.map +1 -1
  41. package/dist/entrypoints/files/packaging.js +230 -61
  42. package/dist/entrypoints/files.js +5 -5
  43. package/dist/entrypoints/geo.js +3 -3
  44. package/dist/entrypoints/http.js +3 -3
  45. package/dist/entrypoints/index.d.ts +1 -0
  46. package/dist/entrypoints/index.d.ts.map +1 -1
  47. package/dist/entrypoints/index.js +45 -24
  48. package/dist/entrypoints/live.js +2 -2
  49. package/dist/entrypoints/node.js +11 -11
  50. package/dist/entrypoints/observability.js +4 -4
  51. package/dist/entrypoints/primitives.js +1 -1
  52. package/dist/entrypoints/process/owner-loss.js +2 -2
  53. package/dist/entrypoints/process.d.ts +6 -1
  54. package/dist/entrypoints/process.d.ts.map +1 -1
  55. package/dist/entrypoints/process.js +370 -9
  56. package/dist/entrypoints/react.js +2 -2
  57. package/dist/entrypoints/realtime.js +3 -3
  58. package/dist/entrypoints/remote.js +20 -10
  59. package/dist/entrypoints/server.d.ts +1 -0
  60. package/dist/entrypoints/server.d.ts.map +1 -1
  61. package/dist/entrypoints/server.js +56 -20
  62. package/dist/entrypoints/telegram/screens.js +4 -4
  63. package/dist/entrypoints/telegram.js +6 -6
  64. package/dist/entrypoints/testing.js +10 -10
  65. package/dist/entrypoints/tools/agent.js +9 -9
  66. package/dist/entrypoints/tools/connections.js +7 -7
  67. package/dist/entrypoints/tools/contract.js +1 -1
  68. package/dist/entrypoints/tools/invoker.js +7 -7
  69. package/dist/entrypoints/tools/mcp.js +9 -9
  70. package/dist/entrypoints/tools/toolkit.js +15 -14
  71. package/dist/entrypoints/tools.js +17 -17
  72. package/dist/entrypoints/tracking/contract.js +2 -2
  73. package/dist/entrypoints/tracking.js +1 -1
  74. package/dist/files/client-artifact.d.ts +75 -0
  75. package/dist/files/client-artifact.d.ts.map +1 -0
  76. package/dist/{index-am1h8c9v.js → index-0d3sm0m9.js} +5 -5
  77. package/dist/{index-72xtvcvr.js → index-0ndz5r8z.js} +1 -1
  78. package/dist/index-0v9xb8pz.js +66 -0
  79. package/dist/{index-qcn84byh.js → index-0w0hxp7n.js} +4 -0
  80. package/dist/{index-3za04re9.js → index-1c945ten.js} +1 -1
  81. package/dist/{index-r6v4mc67.js → index-1d7s7da0.js} +1 -1
  82. package/dist/{index-zsvzhjtk.js → index-20hn8pbh.js} +1 -1
  83. package/dist/{index-f6pw75e1.js → index-2x2ch0bt.js} +2 -2
  84. package/dist/{index-61hve0ez.js → index-303qne11.js} +1 -1
  85. package/dist/{index-g149e9pk.js → index-3bzk2645.js} +1 -1
  86. package/dist/index-45dyex0j.js +119 -0
  87. package/dist/{index-nwm3ww60.js → index-64b2dxqz.js} +1 -1
  88. package/dist/{index-aqwg2dm5.js → index-6k47xdtt.js} +2 -2
  89. package/dist/index-7q05ag0z.js +10 -0
  90. package/dist/{index-kz9734jc.js → index-96yjwwgf.js} +6 -5
  91. package/dist/{index-ff39f9dr.js → index-993vtv1w.js} +3 -3
  92. package/dist/{index-4jpykzvw.js → index-99nnsz39.js} +2 -2
  93. package/dist/{index-pfvde2fz.js → index-9ypczvpj.js} +1 -1
  94. package/dist/{index-qch1vcaa.js → index-a7ebd769.js} +2 -2
  95. package/dist/{index-98hv3sba.js → index-aw6kx2e6.js} +1 -1
  96. package/dist/{index-yj6saztf.js → index-bz9cmnqq.js} +96 -14
  97. package/dist/{index-mtwh9hyp.js → index-cjzaj7ev.js} +1 -1
  98. package/dist/{index-gtx3eknx.js → index-dv7pa9w6.js} +2 -2
  99. package/dist/{index-sa99p98w.js → index-eabx6qjh.js} +3 -3
  100. package/dist/{index-8yxgcyt6.js → index-egg0yp2j.js} +1 -1
  101. package/dist/{index-h1j71dr1.js → index-enkc9pem.js} +1 -1
  102. package/dist/{index-aqmadanx.js → index-fa53vygr.js} +2 -2
  103. package/dist/{index-e6c2spsd.js → index-fpwbskp2.js} +1 -1
  104. package/dist/{index-m8a44e64.js → index-ftk3838x.js} +1 -1
  105. package/dist/{index-j95jp7ee.js → index-gdqawggb.js} +1 -1
  106. package/dist/{index-9dyd8xzf.js → index-hkw233vx.js} +2 -2
  107. package/dist/{index-9jfdm5tg.js → index-hkxgennw.js} +7 -1
  108. package/dist/{index-qaqxdbxf.js → index-j8rda9n6.js} +7 -7
  109. package/dist/{index-4tyt1qya.js → index-jc5xgkpk.js} +2 -2
  110. package/dist/{index-s9a0fjh3.js → index-kffm4r8w.js} +1 -1
  111. package/dist/{index-5w6t91ze.js → index-m8ddk770.js} +1 -1
  112. package/dist/{index-2fc1k9k2.js → index-mdyhr36s.js} +32 -122
  113. package/dist/{index-r7a7r7ha.js → index-mfntvj58.js} +6 -3
  114. package/dist/{index-gq3fnq3f.js → index-n90tkkcv.js} +2 -2
  115. package/dist/{index-k42ckyzx.js → index-ndjzbt2v.js} +2 -2
  116. package/dist/{index-ycqhyars.js → index-qc7tq0za.js} +3 -3
  117. package/dist/{index-9frf01t9.js → index-r0xr7y4m.js} +1 -1
  118. package/dist/{index-s3yxw6kt.js → index-s512scra.js} +9 -7
  119. package/dist/{index-1h2zv8rx.js → index-sqc6ezrb.js} +41 -1
  120. package/dist/{index-2bqf0a74.js → index-sqkttz7z.js} +1 -1
  121. package/dist/{index-rbzq0q16.js → index-t8jz0e20.js} +1 -1
  122. package/dist/{index-8ryydawp.js → index-tt3ej8r3.js} +1 -1
  123. package/dist/{index-x4p3kw1p.js → index-tynna0n4.js} +6 -6
  124. package/dist/{index-72r9k0av.js → index-v62cpkx3.js} +1 -1
  125. package/dist/{index-10rg78vf.js → index-v8xm2s9v.js} +2 -2
  126. package/dist/{index-y6ye582c.js → index-w0wy05gr.js} +10 -10
  127. package/dist/{index-kw1ws0cs.js → index-w3nv6kr8.js} +1 -1
  128. package/dist/{index-eeahxwvg.js → index-ww3gss55.js} +1 -1
  129. package/dist/{index-6j15ktag.js → index-wzqd6pen.js} +1 -1
  130. package/dist/{index-aswegq1r.js → index-xjb131sc.js} +367 -131
  131. package/dist/{index-1fyea34p.js → index-yebkpytc.js} +5 -5
  132. package/dist/{index-bgcwxhxh.js → index-yfpt7sxr.js} +24 -46
  133. package/dist/{index-69t14s4a.js → index-yt1gg11x.js} +3 -2
  134. package/dist/{index-jk29rwkr.js → index-zfncctjp.js} +1 -1
  135. package/dist/internal/stable-digest.d.ts +5 -0
  136. package/dist/internal/stable-digest.d.ts.map +1 -1
  137. package/dist/internal/typed.d.ts +2 -0
  138. package/dist/internal/typed.d.ts.map +1 -1
  139. package/dist/process/operation-child.d.ts +38 -0
  140. package/dist/process/operation-child.d.ts.map +1 -0
  141. package/dist/process/operation-wire.d.ts +68 -0
  142. package/dist/process/operation-wire.d.ts.map +1 -0
  143. package/dist/process/operation.d.ts +74 -0
  144. package/dist/process/operation.d.ts.map +1 -0
  145. package/dist/server/contract-identity.d.ts +10 -0
  146. package/dist/server/contract-identity.d.ts.map +1 -0
  147. package/dist/server/contract-stream.d.ts.map +1 -1
  148. package/dist/server/endpoint-response.d.ts.map +1 -1
  149. package/dist/server/error-hook.d.ts +1 -0
  150. package/dist/server/error-hook.d.ts.map +1 -1
  151. package/dist/tools/cli/args-route.d.ts.map +1 -1
  152. package/dist/tools/cli/args-tokens.d.ts.map +1 -1
  153. package/dist/tools/cli/command.d.ts +39 -18
  154. package/dist/tools/cli/command.d.ts.map +1 -1
  155. package/dist/tools/cli/format.d.ts.map +1 -1
  156. package/dist/tools/cli/help.d.ts.map +1 -1
  157. package/dist/tools/cli/invoke.d.ts +3 -1
  158. package/dist/tools/cli/invoke.d.ts.map +1 -1
  159. package/dist/tools/cli/io.d.ts +6 -0
  160. package/dist/tools/cli/io.d.ts.map +1 -1
  161. package/dist/tools/cli/managed-surface.d.ts +2 -0
  162. package/dist/tools/cli/managed-surface.d.ts.map +1 -1
  163. package/dist/tools/cli/policy.d.ts +14 -0
  164. package/dist/tools/cli/policy.d.ts.map +1 -1
  165. package/dist/tools/cli/run-managed.d.ts.map +1 -1
  166. package/dist/tools/cli/run-native.d.ts.map +1 -1
  167. package/dist/tools/cli/run-stream.d.ts +23 -0
  168. package/dist/tools/cli/run-stream.d.ts.map +1 -0
  169. package/dist/tools/cli/session.d.ts +8 -0
  170. package/dist/tools/cli/session.d.ts.map +1 -1
  171. package/dist/tools/cli/stream-surface.d.ts +17 -0
  172. package/dist/tools/cli/stream-surface.d.ts.map +1 -0
  173. package/dist/tools/execute.d.ts +7 -1
  174. package/dist/tools/execute.d.ts.map +1 -1
  175. package/dist/tools/invoker.d.ts.map +1 -1
  176. package/dist/tools/remote.d.ts.map +1 -1
  177. package/llms/cli.2.txt +56 -1
  178. package/llms/cli.txt +68 -1
  179. package/llms/contract.txt +4 -1
  180. package/llms/files-packaging.txt +10 -0
  181. package/llms/process.2.txt +75 -1
  182. package/llms/process.txt +59 -25
  183. package/llms/server.4.txt +8 -4
  184. package/llms/server.5.txt +1 -0
  185. package/llms/stitchkit.2.txt +74 -0
  186. package/llms/stitchkit.txt +5 -5
  187. package/llms/tools.txt +1 -1
  188. package/llms/{upgrading-0.106.0-0.122.0.txt → upgrading-0.106.0-0.123.0.txt} +50 -3
  189. package/llms/upgrading.txt +1 -1
  190. package/llms-full.txt +379 -13
  191. package/llms.txt +7 -7
  192. package/package.json +1 -1
  193. package/dist/index-h2fhjqy7.js +0 -19
  194. package/dist/index-m5m9rmvt.js +0 -44
@@ -39,6 +39,7 @@ import type { RuntimeToolDefinition } from '../runtime-tool-declaration.js';
39
39
  import { type CliCommandDefinition } from './command.js';
40
40
  import { type ExitCodeMap } from './format.js';
41
41
  import { type CliCommandPresentation, type CliPresentationPolicyConfig } from './policy.js';
42
+ import { type CliStreamOperation } from './stream-surface.js';
42
43
  export type CliSurfaceSource<TAuth, TValue> = readonly TValue[] | ((auth: Awaited<TAuth> | undefined) => readonly TValue[]);
43
44
  /**
44
45
  * What an invocation needs to exist: the surface, the identity behind it and
@@ -107,7 +108,7 @@ export interface CliInvoker {
107
108
  readonly commands: readonly CliInvokerCommand[];
108
109
  /**
109
110
  * Run one parsed call. Never writes, never exits. An unknown command is a
110
- * `NOT_FOUND` result rather than a throw, because a stream must answer the
111
+ * `UNKNOWN_OPERATION` result rather than a throw, because a stream must answer the
111
112
  * line that was wrong and keep reading the ones that follow.
112
113
  */
113
114
  invoke(command: string, args: Record<string, unknown>): Promise<CliInvocationResult>;
@@ -137,6 +138,7 @@ export declare function createCliInvoker<TAuth = unknown, TContext extends Recor
137
138
  */
138
139
  export declare function buildCliSurface<TAuth, TContext extends Record<string, unknown>, TGlobals extends ZodObject>(config: CliInvokerConfig<TAuth, TContext, TGlobals>, auth: Awaited<TAuth> | undefined, nativeHelp: Map<string, CliCommandPresentation>, applicationGlobalNames: ReadonlySet<string>, shapeIssue?: (name: string, descriptor: CliCommandPresentation, exists: boolean, passthroughField: string | undefined, globalNames: ReadonlySet<string>) => string | undefined): {
139
140
  tools: Map<string, MountableTool>;
141
+ streams: Map<string, CliStreamOperation>;
140
142
  help: Map<string, CliCommandPresentation>;
141
143
  };
142
144
  /** How a managed tool presents itself — the same shape a native command builds. */
@@ -1 +1 @@
1
- {"version":3,"file":"invoke.d.ts","sourceRoot":"","sources":["../../../src/tools/cli/invoke.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxC,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAClF,OAAO,EAAE,KAAK,UAAU,EAA4C,MAAM,mBAAmB,CAAC;AAC9F,OAAO,EA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,SAAS,SAAS,GAAG,SAAS,EAEtC,MAAM,EAAE,gBAAgB,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,EACnD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,OAAO,CAAC,UAAU,CAAC,CAmErB;AAmFD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EACL,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACxC,QAAQ,SAAS,SAAS,EAE1B,MAAM,EAAE,gBAAgB,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,EACnD,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,GAAG,SAAS,EAChC,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,sBAAsB,CAAC,EAC/C,sBAAsB,EAAE,WAAW,CAAC,MAAM,CAAC,EAC3C,UAAU,CAAC,EAAE,CACX,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,sBAAsB,EAClC,MAAM,EAAE,OAAO,EACf,gBAAgB,EAAE,MAAM,GAAG,SAAS,EACpC,WAAW,EAAE,WAAW,CAAC,MAAM,CAAC,KAC7B,MAAM,GAAG,SAAS,GACtB;IACD,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAClC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IACzC,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;CAC3C,CAyEA;AAED,mFAAmF;AACnF,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,aAAa,GAClB,IAAI,CAAC,sBAAsB,EAAE,SAAS,GAAG,aAAa,CAAC,CAOzD"}
@@ -2,6 +2,12 @@ import type { CliConfig } from './config.js';
2
2
  /** Where one invocation writes, reads and exits — injected sinks or the real process. */
3
3
  export interface CliIo {
4
4
  stdout: (text: string) => void;
5
+ /**
6
+ * Write to stdout and say whether its reader is still there. A feed has to
7
+ * learn that nobody reads it — `head -1` closing the pipe ends the command;
8
+ * an ordinary result is written once and has nothing to stop.
9
+ */
10
+ stdoutWhileOpen: (text: string) => boolean;
5
11
  stderr: (text: string) => void;
6
12
  exit: (code: number) => void;
7
13
  readStdin: () => Promise<string | null>;
@@ -1 +1 @@
1
- {"version":3,"file":"io.d.ts","sourceRoot":"","sources":["../../../src/tools/cli/io.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAG1C,yFAAyF;AACzF,MAAM,WAAW,KAAK;IACpB,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7B,SAAS,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CACzC;AAED,wBAAgB,WAAW,CACzB,MAAM,EAAE,IAAI,CAAC,SAAS,EAAE,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC,GAC9D,KAAK,CAqEP"}
1
+ {"version":3,"file":"io.d.ts","sourceRoot":"","sources":["../../../src/tools/cli/io.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAG1C,yFAAyF;AACzF,MAAM,WAAW,KAAK;IACpB,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B;;;;OAIG;IACH,eAAe,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;IAC3C,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7B,SAAS,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CACzC;AAOD,wBAAgB,WAAW,CACzB,MAAM,EAAE,IAAI,CAAC,SAAS,EAAE,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC,GAC9D,KAAK,CAuFP"}
@@ -3,6 +3,7 @@ import { type ToolResult } from '../execute-result.js';
3
3
  import type { MountableTool } from '../mount.js';
4
4
  import type { CliCommandPresentation } from './policy.js';
5
5
  import type { CliSession } from './session.js';
6
+ import type { CliStreamOperation } from './stream-surface.js';
6
7
  /**
7
8
  * The managed surface, or the reason there isn't one.
8
9
  *
@@ -19,6 +20,7 @@ export type ManagedSurface<TAuth> = {
19
20
  auth: Awaited<TAuth> | undefined;
20
21
  help: Map<string, CliCommandPresentation>;
21
22
  tools: Map<string, MountableTool>;
23
+ streams: Map<string, CliStreamOperation>;
22
24
  } | {
23
25
  resolved: false;
24
26
  failure: Extract<ToolResult, {
@@ -1 +1 @@
1
- {"version":3,"file":"managed-surface.d.ts","sourceRoot":"","sources":["../../../src/tools/cli/managed-surface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxC,OAAO,EAAE,KAAK,UAAU,EAA4C,MAAM,mBAAmB,CAAC;AAC9F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAG9C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE5C;;;;;;;;;;GAUG;AACH,MAAM,MAAM,cAAc,CAAC,KAAK,IAC5B;IACE,QAAQ,EAAE,IAAI,CAAC;IACf,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,GAAG,SAAS,CAAC;IACjC,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;IAC1C,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,C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AAK,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAClC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;CAC1C,GACD;IACE,QAAQ,EAAE,KAAK,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC,UAAU,EAAE;QAAE,EAAE,EAAE,KAAK,CAAA;KAAE,CAAC,CAAC;IAC5C,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;CAC3C,CAAC;AAEN,wBAAsB,mBAAmB,CACvC,KAAK,EACL,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACxC,QAAQ,SAAS,SAAS,EAE1B,OAAO,EAAE,UAAU,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAC9C,YAAY,EAAE,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,EAChC,YAAY,EAAE,OAAO,GACpB,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAuChC"}
@@ -1,4 +1,6 @@
1
+ import type { ZodType } from 'zod';
1
2
  import { describeSchemaFields } from './args-fields.js';
3
+ import type { CliResultPolicy } from './command.js';
2
4
  export interface CliPresentationPolicyConfig {
3
5
  /** Command selected when argv contains no explicit command. */
4
6
  defaultCommand?: string;
@@ -6,6 +8,12 @@ export interface CliPresentationPolicyConfig {
6
8
  optionAliases?: Readonly<Record<string, Readonly<Record<string, string>>>>;
7
9
  /** Exact ordered argv-positional fields per command; an empty array disables positionals. */
8
10
  positionals?: Readonly<Record<string, readonly string[]>>;
11
+ /**
12
+ * Terminal presentation and success exit code of a managed command's result,
13
+ * keyed by command name — `{ lookup: defineCliResult(LookupOutput, { present, exitCode }) }`.
14
+ * Declared where the CLI is mounted, because a client and a server print nothing.
15
+ */
16
+ results?: Readonly<Record<string, CliResultPolicy<unknown>>>;
9
17
  }
10
18
  export interface CliCommandPresentation {
11
19
  description: string;
@@ -13,6 +21,10 @@ export interface CliCommandPresentation {
13
21
  unavailableReason?: string;
14
22
  argumentSchema: Parameters<typeof describeSchemaFields>[0];
15
23
  presentationSchema: Record<string, unknown>;
24
+ /** The schema a successful result is validated against; absent when none is declared. */
25
+ outputSchema?: ZodType;
26
+ /** A contract stream: the command prints a line per item, and `outputSchema` is one item. */
27
+ stream?: true;
16
28
  /** Canonical field name → one short alias. */
17
29
  aliases: ReadonlyMap<string, string>;
18
30
  /**
@@ -23,6 +35,8 @@ export interface CliCommandPresentation {
23
35
  */
24
36
  positionals?: readonly string[];
25
37
  }
38
+ /** The result policy mounted for one command, if any. */
39
+ export declare function cliResultPolicy(config: Pick<CliPresentationPolicyConfig, 'results'>, command: string): CliResultPolicy<unknown> | undefined;
26
40
  export declare function applyCliPresentationPolicy(command: string, descriptor: Omit<CliCommandPresentation, 'aliases' | 'positionals'>, config: CliPresentationPolicyConfig): CliCommandPresentation;
27
41
  /** Validate name-keyed policies only when the complete managed surface has resolved. */
28
42
  export declare function assertCliPoliciesResolved(commands: ReadonlyMap<string, CliCommandPresentation>, config: CliPresentationPolicyConfig): void;
@@ -1 +1 @@
1
- {"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../../../src/tools/cli/policy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAErD,MAAM,WAAW,2BAA2B;IAC1C,+DAA+D;IAC/D,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,+EAA+E;IAC/E,aAAa,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3E,6FAA6F;IAC7F,WAAW,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC,CAAC;CAC3D;AAED,MAAM,WAAW,sBAAsB;IACrC,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EAAE,MAAM,KAAK,CAAC;AAYrC,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,UAAU,EAAkB,MAAM,WAAW,CAAC;AAQ3E,wFAAwF;AACxF,wBAAsB,oBAAoB,CACxC,KAAK,EACL,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACxC,QAAQ,SAAS,SAAS,EAC1B,OAAO,EAAE,UAAU,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAkC1F"}
1
+ {"version":3,"file":"run-managed.d.ts","sourceRoot":"","sources":["../../../src/tools/cli/run-managed.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAerC,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,UAAU,EAGhB,MAAM,WAAW,CAAC;AAQnB,wFAAwF;AACxF,wBAAsB,oBAAoB,CACxC,KAAK,EACL,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACxC,QAAQ,SAAS,SAAS,EAC1B,OAAO,EAAE,UAAU,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAkC1F"}
@@ -1 +1 @@
1
- {"version":3,"file":"run-native.d.ts","sourceRoot":"","sources":["../../../src/tools/cli/run-native.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AACrC,OAAO,EACL,KAAK,oBAAoB,EAG1B,MAAM,WAAW,CAAC;AAInB,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,UAAU,EAAkB,MAAM,WAAW,CAAC;AAE3E;;;GAGG;AACH,wBAAsB,gBAAgB,CACpC,KAAK,EACL,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACxC,QAAQ,SAAS,SAAS,EAE1B,OAAO,EAAE,UAAU,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAC9C,KAAK,EAAE,QAAQ,CAAC,QAAQ,CAAC,EACzB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,IAAI,CAAC,CA0Ef"}
1
+ {"version":3,"file":"run-native.d.ts","sourceRoot":"","sources":["../../../src/tools/cli/run-native.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AACrC,OAAO,EACL,KAAK,oBAAoB,EAI1B,MAAM,WAAW,CAAC;AAGnB,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,UAAU,EAGhB,MAAM,WAAW,CAAC;AAEnB;;;GAGG;AACH,wBAAsB,gBAAgB,CACpC,KAAK,EACL,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACxC,QAAQ,SAAS,SAAS,EAE1B,OAAO,EAAE,UAAU,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAC9C,KAAK,EAAE,QAAQ,CAAC,QAAQ,CAAC,EACzB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,IAAI,CAAC,CAgEf"}
@@ -0,0 +1,23 @@
1
+ import type { ZodObject } from 'zod';
2
+ import type { CliRunOptions } from './args.js';
3
+ import type { ManagedSurface } from './managed-surface.js';
4
+ import { type CliRoute, type CliSession } from './session.js';
5
+ import type { CliStreamOperation } from './stream-surface.js';
6
+ type ResolvedManagedSurface<TAuth> = Extract<ManagedSurface<TAuth>, {
7
+ resolved: true;
8
+ }>;
9
+ /**
10
+ * Run one contract stream as a command: a line per item until the stream
11
+ * completes, fails, is cancelled, or its reader goes away.
12
+ *
13
+ * The call opens through the shared tool runner — the same validation, the
14
+ * same `lifecycle.beforeHandle` gate, the same hooks as every other command —
15
+ * and what the handler returns is read under the contract's own stream
16
+ * descriptor, exactly as the HTTP response reads it.
17
+ */
18
+ export declare function runStreamCommand<TAuth, TContext extends Record<string, unknown>, TGlobals extends ZodObject>(session: CliSession<TAuth, TContext, TGlobals>, route: CliRoute<TGlobals>, managed: ResolvedManagedSurface<TAuth>, stream: CliStreamOperation, { toolArgs, options }: {
19
+ toolArgs: Record<string, unknown>;
20
+ options: CliRunOptions;
21
+ }): Promise<void>;
22
+ export {};
23
+ //# sourceMappingURL=run-stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-stream.d.ts","sourceRoot":"","sources":["../../../src/tools/cli/run-stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AASrC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAG5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,UAAU,EAAkB,MAAM,WAAW,CAAC;AAC3E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE3D,KAAK,sBAAsB,CAAC,KAAK,IAAI,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE;IAAE,QAAQ,EAAE,IAAI,CAAA;CAAE,CAAC,CAAC;AAKxF;;;;;;;;GAQG;AACH,wBAAsB,gBAAgB,CACpC,KAAK,EACL,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACxC,QAAQ,SAAS,SAAS,EAE1B,OAAO,EAAE,UAAU,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAC9C,KAAK,EAAE,QAAQ,CAAC,QAAQ,CAAC,EACzB,OAAO,EAAE,sBAAsB,CAAC,KAAK,CAAC,EACtC,MAAM,EAAE,kBAAkB,EAC1B,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAAC,OAAO,EAAE,aAAa,CAAA;CAAE,GACnF,OAAO,CAAC,IAAI,CAAC,CA0Df"}
@@ -28,12 +28,20 @@ export interface CliRoute<TGlobals extends ZodObject> {
28
28
  commandArgv: string[];
29
29
  beforeSeparator: string[];
30
30
  helpRequested: boolean;
31
+ /** `--schema` — answered like help: before identity, validation and the call. */
32
+ schemaRequested: boolean;
31
33
  }
32
34
  /**
33
35
  * Lift the application's globals, route the rest and answer `--version`.
34
36
  * `undefined` means the invocation was already answered and `exit` was called.
35
37
  */
36
38
  export declare function resolveCliRoute<TAuth, TContext extends Record<string, unknown>, TGlobals extends ZodObject>(session: CliSession<TAuth, TContext, TGlobals>, argv: string[]): CliRoute<TGlobals> | undefined;
39
+ /**
40
+ * `--schema`: one line of JSON carrying the JSON Schema of a command's input
41
+ * and of its successful result, converted from the very Zod schemas the call
42
+ * is validated against.
43
+ */
44
+ export declare function renderCommandSchema(command: string, descriptor: CliCommandPresentation): string;
37
45
  /** The emit options every result path shares; only `json` and the tool name vary. */
38
46
  export declare function emitOptionsFor(config: Pick<CliConfig, 'errorHint' | 'exitCodes'>, json: boolean, toolName: string): EmitOptions;
39
47
  //# sourceMappingURL=session.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../src/tools/cli/session.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxC,OAAO,EAAE,KAAK,eAAe,EAAoB,MAAM,+BAA+B,CAAC;AAIvF,OAAO,EACL,KAAK,YAAY,EAIlB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,KAAK,oBAAoB,EAAgC,MAAM,WAAW,CAAC;AAEpF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAsB,K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,EAAE,MAAM,EACf,UAAU,EAAE,sBAAsB,GACjC,MAAM,CAcR;AAED,qFAAqF;AACrF,wBAAgB,cAAc,CAC5B,MAAM,EAAE,IAAI,CAAC,SAAS,EAAE,WAAW,GAAG,WAAW,CAAC,EAClD,IAAI,EAAE,OAAO,EACb,QAAQ,EAAE,MAAM,GACf,WAAW,CAOb"}
@@ -0,0 +1,17 @@
1
+ import type { EndpointStreamDescriptor } from '../../contract/define.js';
2
+ import type { ServiceDef } from '../../server/types.js';
3
+ import type { MountableTool } from '../mount.js';
4
+ /** One contract stream exposed as a command: how it is called and what it yields. */
5
+ export interface CliStreamOperation {
6
+ tool: MountableTool;
7
+ descriptor: EndpointStreamDescriptor;
8
+ }
9
+ /**
10
+ * The contract streams a CLI carries, by command name.
11
+ *
12
+ * A stream is not a tool — a model call has one answer — so the tool surface
13
+ * never projects it. A terminal can carry a feed, a line per item, and this is
14
+ * the walk that finds the streams whose contract says so (`expose` lists `'CLI'`).
15
+ */
16
+ export declare function collectCliStreams(services: readonly ServiceDef[]): Map<string, CliStreamOperation>;
17
+ //# sourceMappingURL=stream-surface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream-surface.d.ts","sourceRoot":"","sources":["../../../src/tools/cli/stream-surface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AACtE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAK9C,qFAAqF;AACrF,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,aAAa,CAAC;IACpB,UAAU,EAAE,wBAAwB,CAAC;CACtC;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,SAAS,UAAU,EAAE,GAC9B,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAuBjC"}
@@ -1,5 +1,5 @@
1
1
  import type { ZodType, z } from 'zod';
2
- import type { TransportSource } from '../contract/define.js';
2
+ import type { EndpointStreamDescriptor, TransportSource } from '../contract/define.js';
3
3
  import type { RuntimeContext } from '../contract/runtime-context.js';
4
4
  import type { EndpointToolView } from '../contract/tool-view.js';
5
5
  import type { OperationIdentity } from '../server/types.js';
@@ -19,6 +19,12 @@ export interface ToolOperation extends OperationIdentity {
19
19
  outputSchema?: ZodType;
20
20
  /** Applied only by a runner built for the tool surface. → ADR 0196. */
21
21
  toolView?: EndpointToolView;
22
+ /**
23
+ * A contract stream: the handler's answer is the source itself, read item by
24
+ * item under this descriptor by the surface that carries it. No output schema
25
+ * applies to the source as a whole.
26
+ */
27
+ stream?: EndpointStreamDescriptor;
22
28
  handler(ctx: RuntimeContext): unknown | Promise<unknown>;
23
29
  }
24
30
  /** Executable extension parsed once inside the shared runner before resolution. */
@@ -1 +1 @@
1
- {"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../src/tools/execute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACtC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAI9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrF,OAAO,EAAE,KAAK,UAAU,EAAuB,MAAM,kBAAkB,CAAC;AAIxE,MAAM,MAAM,0BAA0B,GAAG,WAAW,GAAG,iBAAiB,CAAC;AAEzE,2FAA2F;AAC3F,qBAAa,yBAA0B,SAAQ,KAAK;IAClD,QAAQ,CAAC,MAAM,EAAE,0BAA0B,CAAC;IAE5C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E,UAAU,GAAG,SAAS,UAAU,EAAE,EAC5C,MAAM,EAAE,iBAAiB,GACxB,WAAW,CAiEb"}
@@ -1 +1 @@
1
- {"version":3,"file":"remote.d.ts","sourceRoot":"","sources":["../../src/tools/remote.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAKnE,OAAO,KAAK,EAAa,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAkE7D,MAAM,WAAW,sBAAsB;IACrC;;;;OAIG;IACH,aAAa,CAAC,EAAE,CACd,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC1B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACjE;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,EACnE,QAAQ,EAAE,WAAW,CAAC,CAAC,EAAE,MAAM,CAAC,EAChC,IAAI,EAAE,UAAU,EAChB,OAAO,CAAC,EAAE,sBAAsB,GAC/B,UAAU,CAgEZ"}
1
+ {"version":3,"file":"remote.d.ts","sourceRoot":"","sources":["../../src/tools/remote.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAKnE,OAAO,KAAK,EAAa,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAkE7D,MAAM,WAAW,sBAAsB;IACrC;;;;OAIG;IACH,aAAa,CAAC,EAAE,CACd,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC1B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACjE;AAYD;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,EACnE,QAAQ,EAAE,WAAW,CAAC,CAAC,EAAE,MAAM,CAAC,EAChC,IAAI,EAAE,UAAU,EAChB,OAAO,CAAC,EAAE,sBAAsB,GAC/B,UAAU,CAmEZ"}
package/llms/cli.2.txt CHANGED
@@ -292,6 +292,59 @@ your server. A channel is two documents at two addresses — which of them a bui
292
292
  consults is your decision, and `assertCliPublishable` is told about all of them
293
293
  rather than taught the shape of any.
294
294
 
295
+ ## A contract stream as a command
296
+
297
+ A streaming endpoint whose `expose` lists `'CLI'` is a command that prints one
298
+ line per item — `['HTTP', 'CLI']` for a stream both carry, `['CLI']` for a feed
299
+ only a terminal reads:
300
+
301
+ ```ts
302
+ watch: {
303
+ method: 'POST', path: '/watch', desc: 'Follow record events',
304
+ expose: ['HTTP', 'CLI'],
305
+ input: z.object({ record: z.string() }),
306
+ stream: { item: RecordEvent },
307
+ }
308
+ ```
309
+
310
+ ```sh
311
+ myapp watch_record --record main | head -n 5
312
+ ```
313
+
314
+ The command is named from the contract prefix and the endpoint key
315
+ (`records.watch` → `watch_record`); a stream takes no `tool` group, so it has no
316
+ `tool.name`. `optionAliases` and `positionals` apply as to any command.
317
+
318
+ The call opens through the same runner as every command — validation, the
319
+ `lifecycle.beforeHandle` gate, hooks — and the handler's async iterable is read
320
+ by the loop the HTTP response uses: each item is validated against
321
+ `stream.item` (`STREAM_ITEM_INVALID` otherwise), a declared `terminal` item
322
+ completes the command, and a stream that ends before it fails with
323
+ `STREAM_TERMINAL_MISSING`. A stream proxied by `implementRemote` is a stream
324
+ here too. Without a policy an item is one compact JSON line;
325
+ `results[command].present` formats each item instead. A presenter that throws
326
+ ends the feed with `CLI_PRESENTATION_FAILED` after the lines already printed.
327
+ `exitCode` is refused for a stream at startup — a feed has no single result to
328
+ classify.
329
+
330
+ How a feed ends:
331
+
332
+ | End | stdout / stderr | Exit |
333
+ | --- | --- | --- |
334
+ | the stream completes | every item | `0` |
335
+ | stdout is closed (`head`, a pager that quit) | the items read so far | `0` |
336
+ | `CliConfig.signal` aborts | nothing more, no error | `130` (`REQUEST_ABORTED`) |
337
+ | `stream.lifetimeMs` passes | `STREAM_LIFETIME_EXCEEDED` on stderr | `7` |
338
+ | the source or an item fails | the error on stderr | by its code |
339
+
340
+ In every case the handler's `ctx.signal` aborts and the source is asked to
341
+ close. The command does not wait for a source that ignores its signal: the
342
+ deadline and the cancellation are the command's, not the source's.
343
+
344
+ `--wait`, `--output-dir` and aggregate views do not apply to a stream and exit
345
+ `2`; a stream command is not reachable through `createCliInvoker`, whose answer
346
+ is one result per line.
347
+
295
348
  ## One operation per line — `createCliInvoker`
296
349
 
297
350
  The most common way an agent drives a CLI is not one command: it is a stream —
@@ -344,7 +397,7 @@ await createCliInvoker({ name: 'myapp', services, commands: [describe] })
344
397
  ```
345
398
 
346
399
  A command that declares `output?: never` prints itself and returns nothing, so
347
- there is no result to hand back; it answers `NOT_FOUND` and stays on the command
400
+ there is no result to hand back; it answers `UNKNOWN_OPERATION` and stays on the command
348
401
  line, where stdout exists. Your stream command is one of these, which is why a
349
402
  stream still cannot invoke itself.
350
403
 
@@ -573,6 +626,7 @@ SDK nor the `ai` peer.
573
626
  |--------|------|---------|
574
627
  | `createCli` | function | build and run a CLI from contracts; a runtime catalogue field conflicting with reserved/global argv options disables only that entry, retained in help with its reason; invocation returns `CLI_COMMAND_UNAVAILABLE` before side effects — [guide](../guide/cli.md#when-one-runtime-command-cannot-be-represented-in-argv) |
575
628
  | `defineCliCommand` | function | define one Zod-typed CLI-only executable command with optional validated-result presentation/exit policy |
629
+ | `defineCliResult` | function | type a managed command's `present` / `exitCode` policy against its output schema, for `CliConfig.results` — [guide](../guide/cli.md#the-same-policy-for-a-managed-command) |
576
630
  | `parseCliArgs` | function | argv → typed tool args against a schema; inline `--field:=JSON` assigns a whole JSON value, including null, while ordinary string flags remain lexical; named array options together with bare positionals require an explicit `positionals` policy (advanced) |
577
631
  | `routeCliArgv` | function | select the command out of argv without duplicating the global-option grammar (advanced) |
578
632
  | `extractCliGlobalOptions` | function | lift the application's own global options out of argv before routing (advanced) |
@@ -623,6 +677,7 @@ SDK nor the `ai` peer.
623
677
  | `CliCommandDefinitionBase` | _type_ | native command name, description and input schema |
624
678
  | `CliCommandDefinitionWithOutput` | _type_ | native command with validated declared output and typed optional `present` / successful `exitCode` callbacks |
625
679
  | `CliCommandDefinitionWithoutOutput` | _type_ | native void command without an output contract |
680
+ | `CliResultPolicy` | _type_ | `present` / successful `exitCode` callbacks of one command, typed against its validated result; `CliConfig.results` holds one per managed command |
626
681
  | `CliCommandContext` | _type_ | parsed input, framework run options, the application's `globals` and stdout/stderr writers |
627
682
  | `CliRunOptions` | _type_ | parsed global flags (`--json` compacts success/error records, `--wait`, …) |
628
683
  | `ParsedCliArgs` | _type_ | result of `parseCliArgs` |
package/llms/cli.txt CHANGED
@@ -219,6 +219,49 @@ result on stdout and reports `CLI_PRESENTATION_FAILED` separately, as described
219
219
  under [Aggregate views](#aggregate-views). Void native commands cannot declare
220
220
  either callback.
221
221
 
222
+ ### The same policy for a managed command
223
+
224
+ A command that comes from a contract or a runtime tool declares the same two
225
+ callbacks where the CLI is mounted — `CliConfig.results`, keyed by command name.
226
+ A client and a server print nothing, so the policy belongs to the CLI, not to
227
+ the contract. `defineCliResult` types both callbacks against the operation's
228
+ output schema:
229
+
230
+ ```ts
231
+ import { createCli, defineCliResult } from 'stitchkit/cli'
232
+
233
+ await createCli({
234
+ name: 'myapp',
235
+ version: '1.0.0',
236
+ services: [recordService],
237
+ results: {
238
+ lookup: defineCliResult(LookupOutput, {
239
+ present: ({ result, options }) =>
240
+ options.json ? `${JSON.stringify(result)}\n` : `${result.location ?? 'not found'}\n`,
241
+ exitCode: (result) => (result.found ? 0 : 1),
242
+ }),
243
+ },
244
+ })
245
+ ```
246
+
247
+ The guarantees are the native ones, because one function applies both: the
248
+ callbacks run only after the operation's output is validated, `present` is
249
+ called with and without `--json` — honouring it is the presenter's — and
250
+ returns the exact stdout bytes, a throwing `present` reports
251
+ `CLI_PRESENTATION_FAILED`, and a throwing or out-of-range `exitCode` becomes
252
+ `INTERNAL_SERVER_ERROR`.
253
+
254
+ The schema handed to `defineCliResult` is the command's own output schema — the
255
+ object the contract declares, or the item schema of a stream. A policy typed
256
+ against any other schema is a startup error, as is a key naming no managed
257
+ command or naming a native one.
258
+
259
+ The policy speaks for the command's own result only. An
260
+ [aggregate view](#aggregate-views) (`--table`, `--count-by`, …) answers a
261
+ different question, and after `--wait` the result is the polled command's, so
262
+ both print without the policy. `createCliInvoker` applies `exitCode` — the
263
+ in-process code equals the printed one — and never calls `present`.
264
+
222
265
  `--version`, a selected native command and its command help run before
223
266
  `resolveAuth`, services, context or runtime-tool factories. Top-level help is
224
267
  also credential-free when managed surfaces are static. A dynamic factory must
@@ -417,6 +460,7 @@ same Zod schema an HTTP or MCP call does.
417
460
  | `--output-dir <dir>` | Download result media into a directory |
418
461
  | `--quiet` | Suppress non-essential stderr output |
419
462
  | `--dry-run` | Print the resolved call without executing |
463
+ | `--schema` | One JSON line: the JSON Schema of a command's input and output |
420
464
  | `--help`, `-h` | Usage — top-level or per-command flag table |
421
465
  | `--help <text>` | List only the commands matching a substring |
422
466
  | `--count-by <field>` | Count records per distinct value — see [Aggregate views](#aggregate-views) |
@@ -432,9 +476,32 @@ newline-terminated JSON record on its respective stream; progress and CLI usage
432
476
  diagnostics remain ordinary stderr text. This keeps stdout pipeable and
433
477
  `2>/dev/null` clean. The process exit code carries the error class (`0` ok,
434
478
  `VALIDATION_ERROR → 1`, `UNAUTHORIZED → 2`, `FORBIDDEN → 3`, `NOT_FOUND → 4`,
479
+ `UNKNOWN_OPERATION → 4`, `TIMEOUT → 7`, `STREAM_LIFETIME_EXCEEDED → 7`,
435
480
  `CLI_PRESENTATION_FAILED → 8`,
436
481
  …) — override per app with `exitCodes`.
437
482
 
483
+ ### The schema of a command — `--schema`
484
+
485
+ `myapp <command> --schema` prints one line of JSON and exits `0` without
486
+ validating arguments or calling anything:
487
+
488
+ ```json
489
+ {"command":"lookup","input":{"type":"object","properties":{"name":{"type":"string"}},"required":["name"]},"output":{"type":"object","properties":{"found":{"type":"boolean"}},"required":["found"]}}
490
+ ```
491
+
492
+ `input` is the schema the command's arguments are read by — the one `--help`
493
+ renders — and `output` is the JSON Schema of the result, both derived from the
494
+ operation's Zod schemas and both in JSON Schema draft-07, so a script or another
495
+ program can hold a command to its schema without a copy. A command without a
496
+ declared output carries no `output`; a
497
+ [stream command](#a-contract-stream-as-a-command) carries `item` instead.
498
+ Managed and native commands answer alike. Like `--help`, the answer needs no
499
+ identity when the managed surface is static; a surface built by a
500
+ `services` or `runtimeTools` function resolves identity first to learn its
501
+ commands. `schema` is a reserved option name: a command field called `schema`
502
+ is a startup error for a contract command and makes a runtime-catalogue command
503
+ unavailable, like every other reserved name.
504
+
438
505
  ### A narrower question than "all of them"
439
506
 
440
507
  On a discovered surface `--help` is the only way to learn what exists, and that
@@ -519,7 +586,7 @@ reason in `details.message` on stderr; the default exit code is 1. `--json`
519
586
  compacts the error as usual; `exitCodes` and `errorHint` apply. The refusal precedes
520
587
  command argument parsing, stdin, context, hooks and the handler; `--dry-run` cannot
521
588
  turn it into success. A known unavailable `--wait` target returns the same refusal;
522
- an unknown target keeps `NOT_FOUND`.
589
+ an unknown target answers `UNKNOWN_OPERATION`.
523
590
 
524
591
  This isolates only reserved/global **field** conflicts in `runtimeTools`.
525
592
  Native commands and contract-defined `services` still fail at startup for those
package/llms/contract.txt CHANGED
@@ -222,7 +222,10 @@ Six intrinsic HTTP-only forms intersect an **implicit factory default** with HTT
222
222
  responses and `HEAD`. Under `['HTTP', 'CLI']` they receive `['HTTP']`; under
223
223
  `['CLI']` or `[]` they receive `[]`, not an implicitly reopened HTTP route.
224
224
  An **explicit** non-HTTP exposure on any of them is a definition error, not a
225
- silent downgrade. `safelistedBody` only changes HTTP parsing and remains
225
+ silent downgrade — with one exception: a streaming response may list `'CLI'`
226
+ (`['HTTP', 'CLI']`, or `['CLI']` for a feed only a terminal reads) and then runs
227
+ as a [command printing a line per item](./cli.md#a-contract-stream-as-a-command).
228
+ It is still never an MCP or agent tool. `safelistedBody` only changes HTTP parsing and remains
226
229
  multi-transport. A factory policy applies only to contracts authored through
227
230
  that factory, not to contracts another helper builds internally.
228
231
 
@@ -49,3 +49,13 @@ has no `outputPath`, because nothing is written beside the executable. Keep comp
49
49
  without splitting, preserve every output, and write each asset's `bytes` to its `outputPath`.
50
50
  This evolving entrypoint is a build dependency; runtime imports do not reach it.
51
51
  The detailed recipe is in [native IO](../guide/native-io.md#public-native-packaging).
52
+
53
+ It also owns the build of a client into one self-contained file:
54
+
55
+ | Export | Kind | Summary |
56
+ |--------|------|---------|
57
+ | `buildClientArtifact` | function | bundle a client entry into one self-contained file with its SHA-256, refuse forbidden modules in the graph, optionally pack and verify an npm archive — [guide](../guide/native-io.md#a-client-as-one-self-contained-file) |
58
+ | `ClientArtifactOptions` | _type_ | entry, output file, runtime, forbidden modules and the optional package to pack and verify |
59
+ | `ClientArtifact` | _type_ | the built file, its SHA-256 and size, the bundled modules and the verified archive |
60
+ | `ForbiddenModule` | _type_ | a package name, a source path fragment or a `RegExp` over module paths |
61
+ | `ForbiddenModuleError` | class | the refusal of a bundle that reaches a forbidden module: `module` and `importedBy` |
@@ -5,7 +5,74 @@
5
5
 
6
6
  Parts of this slice:
7
7
  - `llms/process.txt`: Guide: Native IO (docs/guide/native-io.md)
8
- - `llms/process.2.txt`: API reference: `stitchkit/process` (docs/api/reference.md)
8
+ - `llms/process.2.txt`: Guide: Native IO (docs/guide/native-io.md) · API reference: `stitchkit/process` (docs/api/reference.md)
9
+
10
+ ==============================================================================
11
+ # Guide: Native IO (docs/guide/native-io.md) (continued)
12
+ ==============================================================================
13
+
14
+ ## A client as one self-contained file
15
+
16
+ A package that owns a server usually ships a typed client for it, and the client's consumers
17
+ must not inherit the server's dependencies. `buildClientArtifact` (`stitchkit/files/packaging`)
18
+ bundles one entry module into a single file, publishes its SHA-256 beside it and can prove an
19
+ npm archive of it:
20
+
21
+ ```ts
22
+ import { buildClientArtifact } from 'stitchkit/files/packaging'
23
+
24
+ const artifact = await buildClientArtifact({
25
+ entry: 'src/api-client.ts',
26
+ outFile: 'dist/api-client.js', // + dist/api-client.js.sha256
27
+ forbiddenModules: ['chalk', '@acme/terminal-ui', 'src/terminal/', /providers\//],
28
+ package: {
29
+ name: '@acme/api-client', version: '1.4.0', outDir: 'dist',
30
+ exports: ['createApiClient'],
31
+ },
32
+ })
33
+ // artifact.file, artifact.sha256, artifact.bytes, artifact.modules, artifact.package.tarball
34
+ ```
35
+
36
+ - **`forbiddenModules`** refuses a bundle whose module graph reaches a listed module with a
37
+ `ForbiddenModuleError` naming the module and what imports it. A bare or scoped name
38
+ (`'chalk'`, `'@scope/pkg'`) is a package: it is matched by the specifier that imports it, so a
39
+ linked or workspace package is caught wherever it really lives, and by its installed path. A
40
+ string with a slash matches a fragment of the project's own source path; a `RegExp` is tested
41
+ against each module's absolute path. Nothing is left at `outFile` when the build is refused.
42
+ - **`package`** packs the file as an npm archive, installs it into an empty directory, imports
43
+ it by name and checks every name in `exports`. A client that still reaches for the building
44
+ package's `node_modules` fails there, before it reaches a consumer; a failed proof removes the
45
+ file and its hash again.
46
+ - **`runtime`** is the platform the file is built for — `node` by default, which Bun also runs,
47
+ or `bun` or `browser`; a module the platform does not have fails the build.
48
+
49
+ The build, the pack and the verification each run Bun as a bounded command: `timeoutMs`
50
+ (default 120 s) is the deadline of each step, `signal` cancels, and `executable` names the Bun
51
+ binary when it is not `bun` on `PATH`.
52
+
53
+ ## Qualification boundaries
54
+
55
+ Native command cleanup owns the child before launch subscriptions are installed. Setup
56
+ refusal still settles leader closure and teardown within the cleanup budget; failure to
57
+ prove closure reports `COMMAND_CLEANUP` with the original failure retained. Process-group
58
+ signaling requires evidence from the actual detached launcher, not a structural PID field.
59
+ The built-in sandbox transport carries that ownership across the package's split entrypoints.
60
+ Internal finite deadlines and Darwin retry admission use monotonic elapsed time.
61
+
62
+ Linux UID-refusal qualification is a separate privileged installed-package proof in Bun
63
+ and real Node; an unsupported platform or insufficient UID reports an explicit skip.
64
+ A generic native-owner marker does not certify the privileged case. Real Darwin CI remains
65
+ the qualification for native Darwin behavior.
66
+
67
+ Local filesystem tests do not attest delayed NFS visibility, shared-volume microVM or gVisor
68
+ ownership, actual PGID reuse, power-loss durability or macOS full-sync behavior. Those
69
+ require their actual topology or failure environment. No age-only observation proves a
70
+ process dead; the lock's owner record exists before its name does.
71
+
72
+ A sandbox admission slot is released once a direct command's pipes have closed and its owner has settled.
73
+ A `COMMAND_CLEANUP` outcome means the death of its group was not proven, so the slot stays
74
+ occupied, `stop` keeps rejecting with the cleanup error, and the sandbox session is recreated to
75
+ recover.
9
76
 
10
77
  ==============================================================================
11
78
  # API reference: `stitchkit/process` (docs/api/reference.md)
@@ -18,6 +85,13 @@ Native POSIX Bun/Node one-shot command execution. See [native IO](../guide/nativ
18
85
  | Export | Kind | Purpose |
19
86
  |---|---|---|
20
87
  | `runNativeCommand` | function | caller-lifetime streaming or explicitly bounded binary capture |
88
+ | `createOperationProcesses` | function | run contract operations in one-call child processes: `unary` / `stream` return contract handlers bounded by `maxConcurrent`, `maxResponseBytes` and `timeoutMs` — [guide](../guide/native-io.md#a-contract-operation-in-a-process-of-its-own) |
89
+ | `runOperationProcess` | function | the child side: read one call from stdin, run it against `implement(contract, handlers)` services, write the answer |
90
+ | `OperationProcessesConfig` | _type_ | the child command and the three bounds of `createOperationProcesses` |
91
+ | `OperationProcesses` | _type_ | `unary(contract, key)`, `stream(contract, key)` and the `active` count |
92
+ | `OperationCallContext` | _type_ | what a process-operation handler reads of its call: `params`, `input` and the caller's `signal` |
93
+ | `OperationProcessService` | _type_ | what `runOperationProcess` reads of a service; the result of `implement` fits |
94
+ | `OperationProcessIo` | _type_ | injectable call source, writer and stop signal of `runOperationProcess` |
21
95
  | `streamNativeCommand` | function | starts a command under the same group ownership, stop policy and bounds as `runNativeCommand` and returns `stdout` / `stderr` as `ReadableStream<Uint8Array>`, `result` and `stop()`; a slow reader slows the child, a cancelled stream drops its bytes, a failed command errors both streams |
22
96
  | `NativeCommandStream` | type | what `streamNativeCommand` returns: `stdout`, `stderr`, `result` (its buffers are empty) and `stop()` |
23
97
  | `NativeCommandStreamOptions` | type | `NativeCommandOptions` without `capture`, `onOutput` and `stdio`, which the streams own |