stitchkit 0.122.2 → 0.123.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +96 -0
- package/dist/browser/client.d.ts.map +1 -1
- package/dist/browser/contract-identity.d.ts +21 -0
- package/dist/browser/contract-identity.d.ts.map +1 -0
- package/dist/browser/unknown-operation.d.ts +3 -0
- package/dist/browser/unknown-operation.d.ts.map +1 -0
- package/dist/contract/define.d.ts +6 -2
- package/dist/contract/define.d.ts.map +1 -1
- package/dist/contract/endpoint-capabilities.d.ts.map +1 -1
- package/dist/contract/errors.d.ts +4 -0
- package/dist/contract/errors.d.ts.map +1 -1
- package/dist/contract/fingerprint.d.ts +51 -0
- package/dist/contract/fingerprint.d.ts.map +1 -0
- package/dist/contract/identity.d.ts +21 -0
- package/dist/contract/identity.d.ts.map +1 -0
- package/dist/contract/stream.d.ts +32 -0
- package/dist/contract/stream.d.ts.map +1 -1
- package/dist/entrypoints/agent-runtime/browser.js +2 -2
- package/dist/entrypoints/agent-runtime/coding-tools.js +11 -11
- package/dist/entrypoints/agent-runtime/harness.js +12 -12
- package/dist/entrypoints/agent-runtime/openrouter.js +1 -1
- package/dist/entrypoints/agent-runtime/realtime.js +2 -2
- package/dist/entrypoints/agent-runtime/sandbox.js +11 -11
- package/dist/entrypoints/agent-runtime/sqlite/bun.js +15 -15
- package/dist/entrypoints/agent-runtime/sqlite/node.js +15 -15
- package/dist/entrypoints/agent-runtime/testing.js +15 -15
- package/dist/entrypoints/agent-runtime.js +22 -22
- package/dist/entrypoints/application/diagnostic-journal.js +5 -5
- package/dist/entrypoints/application/directory-inbox.js +5 -5
- package/dist/entrypoints/application/grammy.js +1 -1
- package/dist/entrypoints/application.js +7 -7
- package/dist/entrypoints/cli/publish.js +5 -5
- package/dist/entrypoints/cli.d.ts +1 -1
- package/dist/entrypoints/cli.d.ts.map +1 -1
- package/dist/entrypoints/cli.js +20 -17
- package/dist/entrypoints/contract.d.ts +2 -0
- package/dist/entrypoints/contract.d.ts.map +1 -1
- package/dist/entrypoints/contract.js +11 -5
- package/dist/entrypoints/files/packaging.d.ts +1 -0
- package/dist/entrypoints/files/packaging.d.ts.map +1 -1
- package/dist/entrypoints/files/packaging.js +230 -61
- package/dist/entrypoints/files.js +5 -5
- package/dist/entrypoints/geo.js +3 -3
- package/dist/entrypoints/http.js +3 -3
- package/dist/entrypoints/index.d.ts +1 -0
- package/dist/entrypoints/index.d.ts.map +1 -1
- package/dist/entrypoints/index.js +45 -24
- package/dist/entrypoints/live.js +2 -2
- package/dist/entrypoints/node.js +11 -11
- package/dist/entrypoints/observability.js +4 -4
- package/dist/entrypoints/primitives.js +1 -1
- package/dist/entrypoints/process/owner-loss.js +2 -2
- package/dist/entrypoints/process.d.ts +6 -1
- package/dist/entrypoints/process.d.ts.map +1 -1
- package/dist/entrypoints/process.js +370 -9
- package/dist/entrypoints/react.js +2 -2
- package/dist/entrypoints/realtime.js +3 -3
- package/dist/entrypoints/remote.js +20 -10
- package/dist/entrypoints/server.d.ts +1 -0
- package/dist/entrypoints/server.d.ts.map +1 -1
- package/dist/entrypoints/server.js +56 -20
- package/dist/entrypoints/telegram/screens.js +4 -4
- package/dist/entrypoints/telegram.js +6 -6
- package/dist/entrypoints/testing.js +10 -10
- package/dist/entrypoints/tools/agent.js +9 -9
- package/dist/entrypoints/tools/connections.js +7 -7
- package/dist/entrypoints/tools/contract.js +1 -1
- package/dist/entrypoints/tools/invoker.js +7 -7
- package/dist/entrypoints/tools/mcp.js +9 -9
- package/dist/entrypoints/tools/toolkit.js +15 -14
- package/dist/entrypoints/tools.js +17 -17
- package/dist/entrypoints/tracking/contract.js +2 -2
- package/dist/entrypoints/tracking.js +1 -1
- package/dist/files/client-artifact.d.ts +75 -0
- package/dist/files/client-artifact.d.ts.map +1 -0
- package/dist/{index-am1h8c9v.js → index-0d3sm0m9.js} +5 -5
- package/dist/{index-72xtvcvr.js → index-0ndz5r8z.js} +1 -1
- package/dist/index-0v9xb8pz.js +66 -0
- package/dist/{index-qcn84byh.js → index-0w0hxp7n.js} +4 -0
- package/dist/{index-3za04re9.js → index-1c945ten.js} +1 -1
- package/dist/{index-r6v4mc67.js → index-1d7s7da0.js} +1 -1
- package/dist/{index-zsvzhjtk.js → index-20hn8pbh.js} +1 -1
- package/dist/{index-f6pw75e1.js → index-2x2ch0bt.js} +2 -2
- package/dist/{index-61hve0ez.js → index-303qne11.js} +1 -1
- package/dist/{index-g149e9pk.js → index-3bzk2645.js} +1 -1
- package/dist/index-45dyex0j.js +119 -0
- package/dist/{index-aqwg2dm5.js → index-6k47xdtt.js} +2 -2
- package/dist/{index-nwm3ww60.js → index-73dappvg.js} +1 -1
- package/dist/index-7q05ag0z.js +10 -0
- package/dist/{index-kz9734jc.js → index-96yjwwgf.js} +6 -5
- package/dist/{index-ff39f9dr.js → index-993vtv1w.js} +3 -3
- package/dist/{index-4jpykzvw.js → index-99nnsz39.js} +2 -2
- package/dist/{index-pfvde2fz.js → index-9ypczvpj.js} +1 -1
- package/dist/{index-qch1vcaa.js → index-a7ebd769.js} +2 -2
- package/dist/{index-98hv3sba.js → index-aw6kx2e6.js} +1 -1
- package/dist/{index-gq3fnq3f.js → index-bqzgaj57.js} +103 -16
- package/dist/{index-yj6saztf.js → index-bz9cmnqq.js} +96 -14
- package/dist/{index-gtx3eknx.js → index-chz7c830.js} +13 -9
- package/dist/{index-mtwh9hyp.js → index-cjzaj7ev.js} +1 -1
- package/dist/{index-6j15ktag.js → index-d9cg0gen.js} +1 -1
- package/dist/{index-sa99p98w.js → index-eabx6qjh.js} +3 -3
- package/dist/{index-8yxgcyt6.js → index-egg0yp2j.js} +1 -1
- package/dist/{index-h1j71dr1.js → index-enkc9pem.js} +1 -1
- package/dist/{index-aqmadanx.js → index-fa53vygr.js} +2 -2
- package/dist/{index-e6c2spsd.js → index-fpwbskp2.js} +1 -1
- package/dist/{index-m8a44e64.js → index-ftk3838x.js} +1 -1
- package/dist/{index-j95jp7ee.js → index-gdqawggb.js} +1 -1
- package/dist/{index-9dyd8xzf.js → index-hkw233vx.js} +2 -2
- package/dist/{index-9jfdm5tg.js → index-hkxgennw.js} +7 -1
- package/dist/{index-qaqxdbxf.js → index-j8rda9n6.js} +7 -7
- package/dist/{index-4tyt1qya.js → index-jc5xgkpk.js} +2 -2
- package/dist/{index-s9a0fjh3.js → index-kffm4r8w.js} +1 -1
- package/dist/{index-5w6t91ze.js → index-m8ddk770.js} +1 -1
- package/dist/{index-2fc1k9k2.js → index-mdyhr36s.js} +32 -122
- package/dist/{index-r7a7r7ha.js → index-mfntvj58.js} +6 -3
- package/dist/{index-k42ckyzx.js → index-ndjzbt2v.js} +2 -2
- package/dist/{index-ycqhyars.js → index-qc7tq0za.js} +3 -3
- package/dist/{index-9frf01t9.js → index-r0xr7y4m.js} +1 -1
- package/dist/{index-s3yxw6kt.js → index-s512scra.js} +9 -7
- package/dist/{index-1h2zv8rx.js → index-sqc6ezrb.js} +41 -1
- package/dist/{index-2bqf0a74.js → index-sqkttz7z.js} +1 -1
- package/dist/{index-rbzq0q16.js → index-t8jz0e20.js} +1 -1
- package/dist/{index-8ryydawp.js → index-tt3ej8r3.js} +1 -1
- package/dist/{index-x4p3kw1p.js → index-tynna0n4.js} +6 -6
- package/dist/{index-72r9k0av.js → index-v62cpkx3.js} +1 -1
- package/dist/{index-10rg78vf.js → index-v8xm2s9v.js} +2 -2
- package/dist/{index-y6ye582c.js → index-w0wy05gr.js} +10 -10
- package/dist/{index-kw1ws0cs.js → index-w3nv6kr8.js} +1 -1
- package/dist/{index-eeahxwvg.js → index-ww3gss55.js} +1 -1
- package/dist/{index-aswegq1r.js → index-xjb131sc.js} +367 -131
- package/dist/{index-1fyea34p.js → index-yebkpytc.js} +5 -5
- package/dist/{index-bgcwxhxh.js → index-yfpt7sxr.js} +24 -46
- package/dist/{index-69t14s4a.js → index-yt1gg11x.js} +3 -2
- package/dist/{index-jk29rwkr.js → index-zfncctjp.js} +1 -1
- package/dist/internal/bun-command.d.ts +14 -0
- package/dist/internal/bun-command.d.ts.map +1 -0
- package/dist/internal/exclusive-lock-owner.d.ts +1 -1
- package/dist/internal/exclusive-lock-owner.d.ts.map +1 -1
- package/dist/internal/exclusive-lock.d.ts +1 -1
- package/dist/internal/exclusive-lock.d.ts.map +1 -1
- package/dist/internal/process-identity.d.ts +24 -5
- package/dist/internal/process-identity.d.ts.map +1 -1
- package/dist/internal/stable-digest.d.ts +5 -0
- package/dist/internal/stable-digest.d.ts.map +1 -1
- package/dist/internal/typed.d.ts +2 -0
- package/dist/internal/typed.d.ts.map +1 -1
- package/dist/process/operation-child.d.ts +38 -0
- package/dist/process/operation-child.d.ts.map +1 -0
- package/dist/process/operation-wire.d.ts +68 -0
- package/dist/process/operation-wire.d.ts.map +1 -0
- package/dist/process/operation.d.ts +74 -0
- package/dist/process/operation.d.ts.map +1 -0
- package/dist/server/contract-identity.d.ts +10 -0
- package/dist/server/contract-identity.d.ts.map +1 -0
- package/dist/server/contract-stream.d.ts.map +1 -1
- package/dist/server/endpoint-response.d.ts.map +1 -1
- package/dist/server/error-hook.d.ts +1 -0
- package/dist/server/error-hook.d.ts.map +1 -1
- package/dist/tools/cli/args-route.d.ts.map +1 -1
- package/dist/tools/cli/args-tokens.d.ts.map +1 -1
- package/dist/tools/cli/command.d.ts +39 -18
- package/dist/tools/cli/command.d.ts.map +1 -1
- package/dist/tools/cli/format.d.ts.map +1 -1
- package/dist/tools/cli/help.d.ts.map +1 -1
- package/dist/tools/cli/invoke.d.ts +3 -1
- package/dist/tools/cli/invoke.d.ts.map +1 -1
- package/dist/tools/cli/io.d.ts +6 -0
- package/dist/tools/cli/io.d.ts.map +1 -1
- package/dist/tools/cli/managed-surface.d.ts +2 -0
- package/dist/tools/cli/managed-surface.d.ts.map +1 -1
- package/dist/tools/cli/policy.d.ts +14 -0
- package/dist/tools/cli/policy.d.ts.map +1 -1
- package/dist/tools/cli/run-managed.d.ts.map +1 -1
- package/dist/tools/cli/run-native.d.ts.map +1 -1
- package/dist/tools/cli/run-stream.d.ts +23 -0
- package/dist/tools/cli/run-stream.d.ts.map +1 -0
- package/dist/tools/cli/session.d.ts +8 -0
- package/dist/tools/cli/session.d.ts.map +1 -1
- package/dist/tools/cli/stream-surface.d.ts +17 -0
- package/dist/tools/cli/stream-surface.d.ts.map +1 -0
- package/dist/tools/execute.d.ts +7 -1
- package/dist/tools/execute.d.ts.map +1 -1
- package/dist/tools/invoker.d.ts.map +1 -1
- package/dist/tools/remote.d.ts.map +1 -1
- package/llms/cli.2.txt +56 -1
- package/llms/cli.txt +68 -1
- package/llms/contract.txt +4 -1
- package/llms/files-packaging.txt +10 -0
- package/llms/process.2.txt +75 -1
- package/llms/process.txt +59 -25
- package/llms/server.4.txt +8 -4
- package/llms/server.5.txt +1 -0
- package/llms/stitchkit.2.txt +74 -0
- package/llms/stitchkit.txt +5 -5
- package/llms/tools.txt +1 -1
- package/llms/{upgrading-0.106.0-0.122.0.txt → upgrading-0.106.0-0.123.0.txt} +50 -3
- package/llms/upgrading.txt +1 -1
- package/llms-full.txt +379 -13
- package/llms.txt +7 -7
- package/package.json +1 -1
- package/dist/index-h2fhjqy7.js +0 -19
- package/dist/index-m5m9rmvt.js +0 -44
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ZodObject, ZodType, z } from 'zod';
|
|
2
|
-
import { type
|
|
2
|
+
import { type ToolResult } from '../execute-result.js';
|
|
3
3
|
import type { CliRunOptions } from './args.js';
|
|
4
|
-
import type
|
|
4
|
+
import { type CliWriters, type EmitOptions } from './format.js';
|
|
5
5
|
export interface CliCommandContext<TInput extends ZodObject> extends CliWriters {
|
|
6
6
|
input: z.output<TInput>;
|
|
7
7
|
options: Readonly<CliRunOptions>;
|
|
@@ -18,16 +18,33 @@ export interface CliCommandDefinitionBase<TInput extends ZodObject> {
|
|
|
18
18
|
description: string;
|
|
19
19
|
input: TInput;
|
|
20
20
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
/**
|
|
22
|
+
* How a successfully validated result leaves the process: its stdout bytes and
|
|
23
|
+
* its exit code. One shape for a native command (`defineCliCommand`) and for a
|
|
24
|
+
* managed command (`CliConfig.results`), so a result is printed and exit-coded
|
|
25
|
+
* by one rule whichever way the command was declared.
|
|
26
|
+
*/
|
|
27
|
+
export interface CliResultPolicy<TResult> {
|
|
24
28
|
/** Pure post-validation stdout presentation; returned bytes are written verbatim once. */
|
|
25
|
-
present
|
|
26
|
-
result:
|
|
29
|
+
present?(context: {
|
|
30
|
+
result: TResult;
|
|
27
31
|
options: Readonly<CliRunOptions>;
|
|
28
|
-
})
|
|
32
|
+
}): string;
|
|
29
33
|
/** Process exit code for a successfully validated result. */
|
|
30
|
-
exitCode
|
|
34
|
+
exitCode?(result: TResult): number;
|
|
35
|
+
/** The schema the policy is typed against; a managed command checks it is its own. */
|
|
36
|
+
output?: ZodType;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Type a managed command's result policy against the schema its operation
|
|
40
|
+
* returns. Pass the very schema the contract declares: the CLI refuses at
|
|
41
|
+
* startup a policy whose schema is not the one its command answers with, so a
|
|
42
|
+
* policy cannot be mounted on a command whose result it does not describe.
|
|
43
|
+
*/
|
|
44
|
+
export declare function defineCliResult<TOutput extends ZodType>(output: TOutput, policy: Pick<CliResultPolicy<z.output<TOutput>>, 'present' | 'exitCode'>): CliResultPolicy<z.output<TOutput>>;
|
|
45
|
+
export interface CliCommandDefinitionWithOutput<TInput extends ZodObject, TOutput extends ZodType> extends CliCommandDefinitionBase<TInput>, CliResultPolicy<z.output<TOutput>> {
|
|
46
|
+
output: TOutput;
|
|
47
|
+
handler: (context: CliCommandContext<TInput>) => z.output<TOutput> | Promise<z.output<TOutput>>;
|
|
31
48
|
}
|
|
32
49
|
export interface CliCommandDefinitionWithoutOutput<TInput extends ZodObject> extends CliCommandDefinitionBase<TInput> {
|
|
33
50
|
output?: never;
|
|
@@ -39,12 +56,6 @@ export type CliCommandDefinition = CliCommandDefinitionWithOutput<ZodObject, Zod
|
|
|
39
56
|
/** Typed identity helper for one transport-local executable command. */
|
|
40
57
|
export declare function defineCliCommand<TInput extends ZodObject, TOutput extends ZodType>(definition: CliCommandDefinitionWithOutput<TInput, TOutput>): CliCommandDefinitionWithOutput<TInput, TOutput>;
|
|
41
58
|
export declare function defineCliCommand<TInput extends ZodObject>(definition: CliCommandDefinitionWithoutOutput<TInput>): CliCommandDefinitionWithoutOutput<TInput>;
|
|
42
|
-
export interface PreparedCliCommandEmission {
|
|
43
|
-
result: ToolResult;
|
|
44
|
-
presentation?: string;
|
|
45
|
-
presentationFailure?: ToolFailure;
|
|
46
|
-
successExitCode: number;
|
|
47
|
-
}
|
|
48
59
|
/**
|
|
49
60
|
* Whether a native command yields a value at all.
|
|
50
61
|
*
|
|
@@ -62,9 +73,19 @@ export declare function cliCommandReturnsResult(definition: CliCommandDefinition
|
|
|
62
73
|
* same command typed at a prompt; two copies of this rule would eventually
|
|
63
74
|
* disagree and the divergence would show up as a script that branches wrong.
|
|
64
75
|
*/
|
|
65
|
-
export declare function cliCommandSuccessExitCode(
|
|
66
|
-
/**
|
|
67
|
-
export declare function
|
|
76
|
+
export declare function cliCommandSuccessExitCode(policy: CliResultPolicy<unknown> | undefined, data: unknown): number;
|
|
77
|
+
/** The result policy a native command declares; a printing command has none. */
|
|
78
|
+
export declare function cliCommandResultPolicy(definition: CliCommandDefinition): CliResultPolicy<unknown> | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* Print one result under its command's policy and return the process exit code.
|
|
81
|
+
*
|
|
82
|
+
* The single place a policy meets the terminal: a native command and a managed
|
|
83
|
+
* one answer through it, so `present`, `exitCode` and a failed presentation
|
|
84
|
+
* behave identically on both.
|
|
85
|
+
*/
|
|
86
|
+
export declare function emitCliCommandResult(policy: CliResultPolicy<unknown> | undefined, result: ToolResult, options: Readonly<CliRunOptions>, writers: CliWriters, emit: EmitOptions & {
|
|
87
|
+
repeatable: boolean;
|
|
88
|
+
}): number;
|
|
68
89
|
export declare function cliCommandPresentationSchema(definition: CliCommandDefinition): Record<string, unknown>;
|
|
69
90
|
/** Execute a CLI-only definition without inventing a tool operation identity. */
|
|
70
91
|
export declare function executeCliCommand(definition: CliCommandDefinition, rawArgs: Record<string, unknown>, options: CliRunOptions, writers: CliWriters, coerceJson: boolean, globals?: Readonly<Record<string, unknown>>): Promise<ToolResult>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../../src/tools/cli/command.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGjD,OAAO,
|
|
1
|
+
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../../src/tools/cli/command.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGjD,OAAO,EAAoB,KAAK,UAAU,EAAuB,MAAM,mBAAmB,CAAC;AAG3F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,EACL,KAAK,UAAU,EACf,KAAK,WAAW,EAGjB,MAAM,UAAU,CAAC;AAElB,MAAM,WAAW,iBAAiB,CAAC,MAAM,SAAS,SAAS,CAAE,SAAQ,UAAU;IAC7E,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACxB,OAAO,EAAE,QAAQ,CAAC,aAAa,CAAC,CAAC;IACjC;;;;;OAKG;IACH,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAC5C;AAED,MAAM,WAAW,wBAAwB,CAAC,MAAM,SAAS,SAAS;IAChE,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;GAKG;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C,CAKzB;AAED,iFAAiF;AACjF,wBAAsB,iBAAiB,CACrC,UAAU,EAAE,oBAAoB,EAChC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,OAAO,EAAE,aAAa,EACtB,OAAO,EAAE,UAAU,EACnB,UAAU,EAAE,OAAO,EACnB,OAAO,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAM,GAC9C,OAAO,CAAC,UAAU,CAAC,CAoCrB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../../src/tools/cli/format.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGjE,sDAAsD;AACtD,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEjD;;;GAGG;AACH,eAAO,MAAM,kBAAkB,EAAE,
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../../src/tools/cli/format.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGjE,sDAAsD;AACtD,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEjD;;;GAGG;AACH,eAAO,MAAM,kBAAkB,EAAE,WAsBhC,CAAC;AAEF,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAChC;AAED,MAAM,WAAW,WAAW;IAC1B,wEAAwE;IACxE,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,WAAW,CAAC;IACxB,SAAS,CAAC,EAAE,WAAW,CAAC;CACzB;AAED;;;;GAIG;AACH;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,CAAC,EAAE,WAAW,GAAG,MAAM,CAY/E;AAED,wBAAgB,UAAU,CACxB,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,UAAU,EACnB,IAAI,EAAE,WAAW,GAChB,MAAM,CAeR;AAWD;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,OAAO,CAAC,UAAU,EAAE;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,CAAC,EACzC,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE,UAAU,EACnB,IAAI,EAAE,WAAW,GAAG;IAAE,UAAU,EAAE,OAAO,CAAA;CAAE,GAC1C,MAAM,CAsBR"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"help.d.ts","sourceRoot":"","sources":["../../../src/tools/cli/help.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,eAAe,EAAoB,MAAM,+BAA+B,CAAC;AAEvF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"help.d.ts","sourceRoot":"","sources":["../../../src/tools/cli/help.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,eAAe,EAAoB,MAAM,+BAA+B,CAAC;AAEvF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAmIvD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,sBAAsB,CAAC,EAC7C,MAAM,EAAE,MAAM,GACb,GAAG,CAAC,MAAM,EAAE,sBAAsB,CAAC,CASrC;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;IAC9C,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,kBAAkB,EAAE,SAAS,eAAe,EAAE,CAAC;IAC/C,wEAAwE;IACxE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mEAAmE;IACnE,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GAAG,MAAM,CAyCT;AAED,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,sBAAsB,EAClC,kBAAkB,GAAE,SAAS,eAAe,EAAO,GAClD,MAAM,CA4ER"}
|
|
@@ -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
|
-
* `
|
|
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;
|
|
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,E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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"}
|
package/dist/tools/cli/io.d.ts
CHANGED
|
@@ -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;
|
|
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;
|
|
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;AAC5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE3D;;;;;;;;;;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,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":"
|
|
1
|
+
{"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../../../src/tools/cli/policy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAGnC,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe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E,MAAM,EACf,UAAU,EAAE,IAAI,CAAC,sBAAsB,EAAE,SAAS,GAAG,aAAa,CAAC,EACnE,MAAM,EAAE,2BAA2B,GAClC,sBAAsB,CAexB;AAED,wFAAwF;AACxF,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,sBAAsB,CAAC,EACrD,MAAM,EAAE,2BAA2B,GAClC,IAAI,CAYN"}
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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,
|
|
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,
|
|
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,EACL,KAAK,eAAe,EAGrB,MAAM,+BAA+B,CAAC;AAIvC,OAAO,EACL,KAAK,YAAY,EAIl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AY,CAAC;IACpB,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,aAAa,EAAE,OAAO,CAAC;IACvB,iFAAiF;IACjF,eAAe,EAAE,OAAO,CAAC;CAC1B;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,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,IAAI,EAAE,MAAM,EAAE,GACb,QAAQ,CAAC,QAAQ,CAAC,GAAG,SAAS,CAgEhC;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,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"}
|
package/dist/tools/execute.d.ts
CHANGED
|
@@ -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;
|
|
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,wBAAwB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAEpF,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,YAAY,MAAM,EAAE,0BAA0B,EAI7C;CACF;AAaD,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,yBAAyB,CAEpC;AAED,4FAA4F;AAC5F,MAAM,WAAW,aAAc,S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ourceRoot":"","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;
|
|
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 `
|
|
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
|
|
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
|
|
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
|
|