stitchkit 0.91.2 → 0.93.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 (86) hide show
  1. package/CHANGELOG.md +137 -0
  2. package/dist/agent-runtime-coding-tools.js +3 -3
  3. package/dist/agent-runtime-harness.js +5 -5
  4. package/dist/agent-runtime-sandbox.js +3 -3
  5. package/dist/agent-runtime.js +8 -8
  6. package/dist/cli.d.ts +6 -3
  7. package/dist/cli.d.ts.map +1 -1
  8. package/dist/cli.js +377 -49
  9. package/dist/contract/define.d.ts +84 -2
  10. package/dist/contract/define.d.ts.map +1 -1
  11. package/dist/contract/index.d.ts +1 -1
  12. package/dist/contract/index.d.ts.map +1 -1
  13. package/dist/{index-a2nzz56k.js → index-2c2bjw3s.js} +3 -3
  14. package/dist/{index-seyy8dvn.js → index-3bmnp41g.js} +245 -116
  15. package/dist/{index-axvavfr4.js → index-bx75zwt7.js} +3 -3
  16. package/dist/{index-709nh7z7.js → index-cxqhvq21.js} +2 -1
  17. package/dist/{index-pena034b.js → index-e42wzzz5.js} +3 -3
  18. package/dist/{index-qjeyx5t2.js → index-fq77yfzc.js} +1 -1
  19. package/dist/{index-fenaekmk.js → index-h9etkkyk.js} +37 -27
  20. package/dist/{index-4x809vqd.js → index-mzvgxp0n.js} +2 -2
  21. package/dist/{index-jpfqfg5c.js → index-n0f51dfn.js} +2 -2
  22. package/dist/{index-bv7mytab.js → index-sr93cwf9.js} +1 -1
  23. package/dist/{index-vsbzgd7b.js → index-tmwcrptx.js} +1 -0
  24. package/dist/{index-8z9we758.js → index-vjpvjqpn.js} +1 -1
  25. package/dist/{index-7hz88dy8.js → index-vk3kq9sb.js} +1 -1
  26. package/dist/{index-s3dssqxp.js → index-yn8remb1.js} +60 -56
  27. package/dist/internal/atomic-file.d.ts +21 -0
  28. package/dist/internal/atomic-file.d.ts.map +1 -0
  29. package/dist/internal/secure-fetch.d.ts +12 -0
  30. package/dist/internal/secure-fetch.d.ts.map +1 -1
  31. package/dist/node.js +3 -3
  32. package/dist/observability/audit.d.ts +5 -1
  33. package/dist/observability/audit.d.ts.map +1 -1
  34. package/dist/observability/changes.d.ts.map +1 -1
  35. package/dist/observability/context.d.ts +27 -6
  36. package/dist/observability/context.d.ts.map +1 -1
  37. package/dist/observability/event.d.ts +34 -6
  38. package/dist/observability/event.d.ts.map +1 -1
  39. package/dist/observability/index.d.ts +2 -1
  40. package/dist/observability/index.d.ts.map +1 -1
  41. package/dist/observability/index.js +50 -6
  42. package/dist/observability/work.d.ts +55 -0
  43. package/dist/observability/work.d.ts.map +1 -0
  44. package/dist/server/context-contribution.d.ts.map +1 -1
  45. package/dist/server/index.js +4 -4
  46. package/dist/server/types.d.ts +20 -6
  47. package/dist/server/types.d.ts.map +1 -1
  48. package/dist/testing/surface-manifest.d.ts +34 -1
  49. package/dist/testing/surface-manifest.d.ts.map +1 -1
  50. package/dist/testing.d.ts +1 -1
  51. package/dist/testing.d.ts.map +1 -1
  52. package/dist/testing.js +31 -9
  53. package/dist/tool-invoker.js +5 -5
  54. package/dist/tools/cli-checkpoint.d.ts +24 -0
  55. package/dist/tools/cli-checkpoint.d.ts.map +1 -0
  56. package/dist/tools/cli-command.d.ts +18 -0
  57. package/dist/tools/cli-command.d.ts.map +1 -1
  58. package/dist/tools/cli-format.d.ts +10 -0
  59. package/dist/tools/cli-format.d.ts.map +1 -1
  60. package/dist/tools/cli-invoke.d.ts +143 -0
  61. package/dist/tools/cli-invoke.d.ts.map +1 -0
  62. package/dist/tools/cli-manifest.d.ts +6 -9
  63. package/dist/tools/cli-manifest.d.ts.map +1 -1
  64. package/dist/tools/cli-signature.d.ts +81 -0
  65. package/dist/tools/cli-signature.d.ts.map +1 -0
  66. package/dist/tools/cli-stream.d.ts +93 -0
  67. package/dist/tools/cli-stream.d.ts.map +1 -0
  68. package/dist/tools/cli-update.d.ts +62 -0
  69. package/dist/tools/cli-update.d.ts.map +1 -1
  70. package/dist/tools/cli.d.ts +4 -16
  71. package/dist/tools/cli.d.ts.map +1 -1
  72. package/dist/tools/connections/index.js +2 -2
  73. package/dist/tools/execute.d.ts +21 -0
  74. package/dist/tools/execute.d.ts.map +1 -1
  75. package/dist/tools/mcp-progress.d.ts +46 -0
  76. package/dist/tools/mcp-progress.d.ts.map +1 -0
  77. package/dist/tools/mcp-round-policy.d.ts +25 -1
  78. package/dist/tools/mcp-round-policy.d.ts.map +1 -1
  79. package/dist/tools/mcp-round.d.ts +20 -1
  80. package/dist/tools/mcp-round.d.ts.map +1 -1
  81. package/dist/tools/mcp-trace.d.ts +9 -1
  82. package/dist/tools/mcp-trace.d.ts.map +1 -1
  83. package/dist/tools/mount-wait.d.ts.map +1 -1
  84. package/dist/tools.js +159 -50
  85. package/llms-full.txt +449 -8
  86. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"cli-format.d.ts","sourceRoot":"","sources":["../../src/tools/cli-format.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAGzD,sDAAsD;AACtD,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEjD;;;GAGG;AACH,eAAO,MAAM,kBAAkB,EAAE,WAWhC,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,wBAAgB,UAAU,CACxB,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,UAAU,EACnB,IAAI,EAAE,WAAW,GAChB,MAAM,CAgBR"}
1
+ {"version":3,"file":"cli-format.d.ts","sourceRoot":"","sources":["../../src/tools/cli-format.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAGzD,sDAAsD;AACtD,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEjD;;;GAGG;AACH,eAAO,MAAM,kBAAkB,EAAE,WAWhC,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"}
@@ -0,0 +1,143 @@
1
+ /**
2
+ * Running one already-parsed operation, in this process.
3
+ *
4
+ * The most common way an agent drives a CLI is not one command — it is a
5
+ * stream: a JSON line per operation, an answer per line. The framework owned
6
+ * the parsing, the routing, the JSON mode, the exit codes and the error shape,
7
+ * and handed out no way to say "run this parsed call and give me its result".
8
+ * So a consumer's stream loop spawned the binary again per line: three
9
+ * conversions of the same data (arguments back into `--flag value` strings,
10
+ * nested objects through `JSON.stringify` into an argv slot, the result parsed
11
+ * back out of stdout text) plus a process start each time — measured at 0.15 s,
12
+ * which is thirty seconds for a two-hundred-line manifest before any work
13
+ * happens. The ban on nesting one stream inside another existed for the same
14
+ * reason and disappears with it.
15
+ *
16
+ * `createCliInvoker` compiles the managed surface once and executes against it.
17
+ * `createCli` is built on this same function, so the stream and the command
18
+ * line cannot answer differently: one surface, one runner, one exit table.
19
+ *
20
+ * Native commands (`config.commands`) are in it when, and only when, they
21
+ * declare `output`. The two halves of a native definition are not the same kind
22
+ * of thing: one returns a validated value the frame prints, the other prints
23
+ * itself and returns `void`. Only the second cannot be run where there is no
24
+ * stdout, and excluding both because of it cost a consumer a working `describe`
25
+ * line for no reason the type could not already tell apart.
26
+ *
27
+ * `present` is not called on this path: it is stdout formatting, and there is
28
+ * no stdout. `exitCode` is, through the same function the command line uses, so
29
+ * a script branching on the code cannot see the two paths disagree. Anything
30
+ * the handler does write is captured and returned on the result rather than
31
+ * leaking into a caller's stream of answers.
32
+ */
33
+ import type { ZodObject, z } from 'zod';
34
+ import type { ServiceDef, StitchLogger } from '../server/types.js';
35
+ import { type CliCommandDefinition } from './cli-command.js';
36
+ import { type ExitCodeMap } from './cli-format.js';
37
+ import { type CliCommandPresentation, type CliPresentationPolicyConfig } from './cli-policy.js';
38
+ import { type ErrorHintFn, type ToolCallHooks, type ToolLifecycle, type ToolResult } from './execute.js';
39
+ import { type MountableTool } from './mount.js';
40
+ import type { RuntimeToolDefinition } from './runtime-tool.js';
41
+ export type CliSurfaceSource<TAuth, TValue> = readonly TValue[] | ((auth: Awaited<TAuth> | undefined) => readonly TValue[]);
42
+ /**
43
+ * What an invocation needs to exist: the surface, the identity behind it and
44
+ * the policies every call runs under. Everything about a terminal — argv,
45
+ * writers, `--wait`, downloads — belongs to `CliConfig`, which extends this.
46
+ */
47
+ export interface CliInvokerConfig<TAuth = unknown, TContext extends Record<string, unknown> = Record<string, unknown>, TGlobals extends ZodObject = ZodObject> extends CliPresentationPolicyConfig {
48
+ /** Program name — used in diagnostics. */
49
+ name: string;
50
+ /** Contract services exposed as commands — may depend on the resolved identity. */
51
+ services?: CliSurfaceSource<TAuth, ServiceDef>;
52
+ /** Pathless managed operations. CLI exposure always requires `transports: ['CLI']`. */
53
+ runtimeTools?: CliSurfaceSource<TAuth, RuntimeToolDefinition>;
54
+ /** CLI-only executable commands, dispatched before the managed surface. */
55
+ commands?: readonly CliCommandDefinition[];
56
+ auth?: TAuth | Promise<TAuth>;
57
+ resolveAuth?: (globals: z.output<TGlobals>) => TAuth | Promise<TAuth>;
58
+ globalOptions?: TGlobals;
59
+ context?: (auth: Awaited<TAuth> | undefined, globals: z.output<TGlobals>) => TContext;
60
+ signal?: AbortSignal;
61
+ hooks?: ToolCallHooks;
62
+ lifecycle?: ToolLifecycle;
63
+ logger?: StitchLogger;
64
+ coerceJsonArgs?: boolean;
65
+ errorHint?: ErrorHintFn;
66
+ exitCodes?: ExitCodeMap;
67
+ passthrough?: Record<string, string>;
68
+ }
69
+ /** What one parsed invocation produced — never printed, never exited on. */
70
+ export interface CliInvocationResult {
71
+ ok: boolean;
72
+ /** The exit code the printed path would give this same result. */
73
+ exitCode: number;
74
+ /** The validated handler output, on success. */
75
+ data?: unknown;
76
+ /** The refusal, in the shape the CLI prints on failure. */
77
+ error?: {
78
+ code: string;
79
+ message: string;
80
+ details?: unknown;
81
+ hint?: string;
82
+ retryable?: boolean;
83
+ };
84
+ /**
85
+ * What a native handler wrote, when it wrote anything.
86
+ *
87
+ * A command that declares `output` is not supposed to write — the frame
88
+ * prints for it — but it holds the writers and may log. In process there is
89
+ * nowhere for that text to go: printing it would interleave with a caller's
90
+ * own output and corrupt a stream of JSON lines, and dropping it would lose a
91
+ * diagnostic silently. So it comes back here, and the caller decides.
92
+ */
93
+ written?: {
94
+ stdout?: string;
95
+ stderr?: string;
96
+ };
97
+ }
98
+ /** One resolved managed command. */
99
+ export interface CliInvokerCommand {
100
+ name: string;
101
+ description: string;
102
+ }
103
+ /** The compiled surface: what can be run, and how to run it. */
104
+ export interface CliInvoker {
105
+ /** Every managed command, in surface order. */
106
+ readonly commands: readonly CliInvokerCommand[];
107
+ /**
108
+ * Run one parsed call. Never writes, never exits. An unknown command is a
109
+ * `NOT_FOUND` result rather than a throw, because a stream must answer the
110
+ * line that was wrong and keep reading the ones that follow.
111
+ */
112
+ invoke(command: string, args: Record<string, unknown>): Promise<CliInvocationResult>;
113
+ }
114
+ /**
115
+ * Shape a `ToolResult` into an invocation result — the same error body the CLI
116
+ * prints, and the same exit code, produced without printing either.
117
+ */
118
+ export declare function cliInvocationResult(result: ToolResult, toolName: string, config: {
119
+ errorHint?: ErrorHintFn;
120
+ exitCodes?: ExitCodeMap;
121
+ }): CliInvocationResult;
122
+ /**
123
+ * Compile the managed surface and return a dispatcher over it.
124
+ *
125
+ * Identity resolves once, not per call: a stream of two hundred operations must
126
+ * not resolve auth two hundred times, and a CLI invocation speaks as one
127
+ * identity by construction.
128
+ */
129
+ export declare function createCliInvoker<TAuth = unknown, TContext extends Record<string, unknown> = Record<string, unknown>, TGlobals extends ZodObject = ZodObject>(config: CliInvokerConfig<TAuth, TContext, TGlobals>, globals?: Record<string, unknown>): Promise<CliInvoker>;
130
+ /**
131
+ * Walk the declared surface into executable tools and their presentation.
132
+ *
133
+ * Shared with `createCli`, which starts from its native commands rather than an
134
+ * empty map — the uniqueness and shape checks have to see both halves, or a
135
+ * managed command could silently shadow a native one.
136
+ */
137
+ 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>, assertShape?: (name: string, descriptor: CliCommandPresentation, exists: boolean, passthroughField: string | undefined, globalNames: ReadonlySet<string>) => void): {
138
+ tools: Map<string, MountableTool>;
139
+ help: Map<string, CliCommandPresentation>;
140
+ };
141
+ /** How a managed tool presents itself — the same shape a native command builds. */
142
+ export declare function managedCliDescriptor(tool: MountableTool): Omit<CliCommandPresentation, 'aliases' | 'positionals'>;
143
+ //# sourceMappingURL=cli-invoke.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli-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,iBAAiB,CAAC;AAEhE,OAAO,EACL,KAAK,oBAAoB,EAI1B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAGL,KAAK,sBAAsB,EAC3B,KAAK,2BAA2B,EACjC,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,UAAU,EAGhB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAoB,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAG5D,MAAM,MAAM,gBAAgB,CAAC,KAAK,EAAE,MAAM,IACtC,SAAS,MAAM,EAAE,GACjB,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,GAAG,SAAS,KAAK,SAAS,MAAM,EAAE,CAAC,CAAC;AAE9D;;;;GAIG;AACH,MAAM,WAAW,gBAAgB,CAC/B,KAAK,GAAG,OAAO,EACf,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClE,QAAQ,SAAS,SAAS,GAAG,SAAS,CACtC,SAAQ,2BAA2B;IACnC,0CAA0C;IAC1C,IAAI,EAAE,MAAM,CA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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,WAAW,CAAC,EAAE,CACZ,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,IAAI,GACR;IAAE,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAAC,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAA;CAAE,CA8BlF;AAED,mFAAmF;AACnF,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,aAAa,GAClB,IAAI,CAAC,sBAAsB,EAAE,SAAS,GAAG,aAAa,CAAC,CAMzD"}
@@ -56,6 +56,11 @@ export declare const CliBuildManifestSchema: z.ZodObject<{
56
56
  size: z.ZodInt;
57
57
  sha256: z.ZodString;
58
58
  }, z.core.$strip>>;
59
+ signature: z.ZodOptional<z.ZodObject<{
60
+ algorithm: z.ZodLiteral<"ed25519">;
61
+ keyId: z.ZodString;
62
+ signature: z.ZodString;
63
+ }, z.core.$strip>>;
59
64
  }, z.core.$strip>;
60
65
  export type CliBuildManifest = z.infer<typeof CliBuildManifestSchema>;
61
66
  /** The stamp a build carries inside itself, so the tool can say what it is. */
@@ -71,13 +76,5 @@ export declare function formatCliBuildStamp(stamp: CliBuildStamp, name?: string)
71
76
  export declare function currentCliBuildTarget(): CliBuildTarget;
72
77
  /** The asset for one target, or `undefined` when this build was not published. */
73
78
  export declare function selectCliBuildAsset(manifest: CliBuildManifest, target?: CliBuildTarget): CliBuildAsset | undefined;
74
- /**
75
- * Refuse republishing a version from a different commit.
76
- *
77
- * A version is a promise about contents. Publishing `1.4.2` twice from two trees
78
- * means everyone who already installed `1.4.2` is told they are current and
79
- * never receives the fix — and nothing about their machine looks wrong. The
80
- * check is one comparison and belongs in the publisher, before the upload.
81
- */
82
- export declare function assertCliPublishable(previous: CliBuildManifest | undefined, next: CliBuildManifest): void;
79
+ export declare function assertCliPublishable(previous: CliBuildManifest | readonly CliBuildManifest[] | undefined, next: CliBuildManifest): void;
83
80
  //# sourceMappingURL=cli-manifest.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cli-manifest.d.ts","sourceRoot":"","sources":["../../src/tools/cli-manifest.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,kFAAkF;AAClF,eAAO,MAAM,oBAAoB;;;iBAG/B,CAAC;AAEH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAElE;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;;;iBAK9B,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEhE;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;iBAMjC,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAEtE,+EAA+E;AAC/E,eAAO,MAAM,mBAAmB;;;;iBAI9B,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEhE,gFAAgF;AAChF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,aAAa,EA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AAgB,qBAAqB,IAAI,cAAc,CAEtD;AAED,kFAAkF;AAClF,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,gBAAgB,EAC1B,MAAM,GAAE,cAAwC,GAC/C,aAAa,GAAG,SAAS,CAI3B;AAgBD,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,gBAAgB,GAAG,SAAS,gBAAgB,EAAE,GAAG,SAAS,EACpE,IAAI,EAAE,gBAAgB,GACrB,IAAI,CAkBN"}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Who built the binary — which the asset digest cannot answer.
3
+ *
4
+ * The digest proves the bytes that arrived are the bytes the manifest named. It
5
+ * proves nothing about who named them: the manifest and the assets come from
6
+ * one origin, and whoever can replace one can replace the other. Authorship
7
+ * needs a key the build carries and the server never holds.
8
+ *
9
+ * So the signature covers the manifest's identity AND every asset's digest —
10
+ * `{name, version, commit, builtAt, assets[]}` — and the chain closes on the
11
+ * file that will execute rather than on the document describing it. Signing the
12
+ * document alone would leave an attacker free to swap an asset URL's contents
13
+ * and keep a valid signature over an unchanged document.
14
+ *
15
+ * Ed25519 over `node:crypto`; no dependency is added for this.
16
+ */
17
+ import { z } from 'zod';
18
+ import type { CliBuildManifest } from './cli-manifest.js';
19
+ /** The detached signature a published manifest carries beside its own fields. */
20
+ export declare const CliBuildSignatureSchema: z.ZodObject<{
21
+ algorithm: z.ZodLiteral<"ed25519">;
22
+ keyId: z.ZodString;
23
+ signature: z.ZodString;
24
+ }, z.core.$strip>;
25
+ export type CliBuildSignature = z.infer<typeof CliBuildSignatureSchema>;
26
+ /**
27
+ * What a verification concluded. Five answers, and `unenforced` is the one that
28
+ * earns its keep: a build with no pinned key must keep updating, and the fact
29
+ * that nothing was checked has to be VISIBLE rather than assumed. A silent
30
+ * "fine" from a check that never ran is the failure mode this whole file exists
31
+ * to remove.
32
+ */
33
+ export type CliSignatureVerdict = 'valid' | 'unenforced' | 'missing' | 'unknown-key' | 'invalid';
34
+ /** The keys a build trusts, by id. A build with none enforces nothing. */
35
+ export interface CliTrustRoot {
36
+ /**
37
+ * `keyId` → public key, as SPKI PEM or base64 of the raw 32-byte Ed25519 key.
38
+ * Compiled into the binary: a trust root fetched at runtime from the same
39
+ * origin as the manifest proves nothing.
40
+ */
41
+ keys: Readonly<Record<string, string>>;
42
+ }
43
+ /**
44
+ * The exact bytes a signature covers.
45
+ *
46
+ * Canonical JSON, so two producers that agree on the content agree on the
47
+ * bytes — key order and whitespace are not allowed to decide whether a
48
+ * signature verifies. Every asset contributes its target, its compression, its
49
+ * size and its digest; `url` does not, because where a file is served from is
50
+ * the publisher's business and moving it must not invalidate the proof of what
51
+ * it contains. Everything that decides what happens to the bytes BEFORE the
52
+ * digest can be checked is signed; only the address is free.
53
+ */
54
+ export declare function cliManifestSigningPayload(manifest: CliBuildManifest): string;
55
+ /**
56
+ * A private key as it comes out of a file or a secret store: PEM text, or DER
57
+ * bytes.
58
+ *
59
+ * Deliberately not `KeyObject`. That type belongs to `node:crypto`, and naming
60
+ * it in a published signature puts `import("node:crypto")` into the declaration
61
+ * files of a package whose browser-safe entries a consumer resolves without
62
+ * Node types at all — the whole surface stops typechecking for them over a
63
+ * function they never call.
64
+ */
65
+ export type CliSigningKey = string | Uint8Array;
66
+ /** Sign a manifest — for the publisher, which is the only side that holds a key. */
67
+ export declare function signCliManifest(manifest: CliBuildManifest, options: {
68
+ keyId: string;
69
+ privateKey: CliSigningKey;
70
+ }): CliBuildSignature;
71
+ /**
72
+ * Verify a manifest against the build's own trust root.
73
+ *
74
+ * Never throws: a verdict is the answer, including for a malformed key or a
75
+ * signature that is not base64 at all. A caller deciding whether to download
76
+ * something wants a decision, not an exception to translate into one.
77
+ */
78
+ export declare function verifyCliManifest(manifest: CliBuildManifest, signature: CliBuildSignature | undefined, trust?: CliTrustRoot): CliSignatureVerdict;
79
+ /** Whether a verdict permits installing the build it describes. */
80
+ export declare function cliSignatureAccepted(verdict: CliSignatureVerdict): boolean;
81
+ //# sourceMappingURL=cli-signature.d.ts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**
2
+ * One operation per line, and a batch that can be resumed.
3
+ *
4
+ * Every agent-facing CLI grows the same two commands, and the mechanics contain
5
+ * nothing about any product: read a line, run the operation, answer with the
6
+ * same id, do not let one bad line stop the stream — and for a batch, do not
7
+ * run again what already ran.
8
+ *
9
+ * They are factories rather than framework-owned command names. Reserving
10
+ * `jsonl` and `batch` would take two names out of a namespace that belongs to
11
+ * the consumer: an application that already has a `batch` command would either
12
+ * fail at startup or find its own command silently shadowed. So the consumer
13
+ * mounts these under whatever it calls them, exactly like its own commands.
14
+ */
15
+ import { z } from 'zod';
16
+ import type { CliInvocationResult, CliInvoker } from './cli-invoke.js';
17
+ /** One line's answer: the id it came with, plus what running it produced. */
18
+ export interface CliStreamAnswer extends CliInvocationResult {
19
+ /** Correlation id, echoed from the line. */
20
+ id: string;
21
+ /** Present when this answer was replayed from a checkpoint rather than run. */
22
+ replayed?: true;
23
+ }
24
+ export interface CliStreamCommandConfig {
25
+ /** Command name — the consumer's namespace, not the framework's. */
26
+ name?: string;
27
+ description?: string;
28
+ /** The compiled surface to run against. */
29
+ invoker: CliInvoker | (() => Promise<CliInvoker>);
30
+ /**
31
+ * Where the lines come from. Default: `process.stdin`, **as they arrive**.
32
+ *
33
+ * This is the difference between a pipe and a conversation. The framework's
34
+ * ordinary stdin routing accumulates the whole stream and hands the command a
35
+ * string, which is right for `--prompt "$(cat file)"` and fatally wrong here:
36
+ * an agent that writes one line and waits for its answer would wait for its
37
+ * own EOF, which never comes. So the stream owns its input and answers each
38
+ * line as it is read.
39
+ */
40
+ readLines?: () => AsyncIterable<string>;
41
+ }
42
+ /**
43
+ * Lines from a byte stream, delivered as they arrive.
44
+ *
45
+ * Split on `\n` with a trailing `\r` dropped, so a producer on Windows is not a
46
+ * silent parse failure on every line. A final line with no newline is delivered
47
+ * at end of stream rather than discarded.
48
+ */
49
+ export declare function readStdinLines(source?: AsyncIterable<Uint8Array | string>): AsyncIterable<string>;
50
+ /**
51
+ * Run each line as it arrives, answering before reading the next.
52
+ *
53
+ * Sequential on purpose: the answers carry ids, so a consumer could correlate
54
+ * out-of-order ones — but a stream that runs ahead of its answers removes the
55
+ * one form of backpressure an agent has, which is not answering yet.
56
+ */
57
+ export declare function runCliStream(invoker: CliInvoker, lines: AsyncIterable<string>, onAnswer: (answer: CliStreamAnswer) => void, hooks?: CliStreamHooks): Promise<void>;
58
+ /** What a caller decides per line, without owning the loop that reads them. */
59
+ export interface CliStreamHooks {
60
+ /** Answer this line without running it — a replay, or a refusal. */
61
+ before?: (id: string, line: {
62
+ command: string;
63
+ args: Record<string, unknown>;
64
+ }) => CliStreamAnswer | undefined;
65
+ /** Observe what running it produced, before the answer is written. */
66
+ after?: (id: string, line: {
67
+ command: string;
68
+ args: Record<string, unknown>;
69
+ }, outcome: CliInvocationResult) => void;
70
+ }
71
+ /**
72
+ * A stream command the consumer mounts under its own name.
73
+ *
74
+ * Answers go to stdout one JSON object per line; nothing else does, so a script
75
+ * can read stdout as data while diagnostics stay on stderr.
76
+ */
77
+ export declare function defineCliStreamCommand(config: CliStreamCommandConfig): import("./cli-command.js").CliCommandDefinitionWithoutOutput<z.ZodObject<{}, z.core.$strip>>;
78
+ export interface CliBatchCommandConfig extends CliStreamCommandConfig {
79
+ /** Where the checkpoint lives. Relative paths resolve against the process cwd. */
80
+ checkpointPath?: string;
81
+ }
82
+ /**
83
+ * A resumable batch.
84
+ *
85
+ * The checkpoint records, per line id, the digest of the line that produced the
86
+ * recorded answer. A re-run replays what already ran; a line whose CONTENT
87
+ * changed under the same id is refused rather than quietly re-run or quietly
88
+ * replayed, because both of those answer a question nobody asked.
89
+ */
90
+ export declare function defineCliBatchCommand(config: CliBatchCommandConfig): import("./cli-command.js").CliCommandDefinitionWithoutOutput<z.ZodObject<{
91
+ checkpoint: z.ZodOptional<z.ZodString>;
92
+ }, z.core.$strip>>;
93
+ //# sourceMappingURL=cli-stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli-stream.d.ts","sourceRoot":"","sources":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C,sEAAsE;IACtE,KAAK,CAAC,EAAE,CACN,EAAE,EAAE,MAAM,EACV,IAAI,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,EACxD,OAAO,EAAE,mBAAmB,KACzB,IAAI,CAAC;CACX;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,sBAAsB,6FAcpE;AAED,MAAM,WAAW,qBAAsB,SAAQ,sBAAsB;IACnE,kFAAkF;IAClF,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,qBAAqB;;mBA+DlE"}
@@ -1,4 +1,5 @@
1
1
  import { type CliBuildAsset, type CliBuildManifest, type CliBuildTarget } from './cli-manifest.js';
2
+ import { type CliSignatureVerdict, type CliTrustRoot } from './cli-signature.js';
2
3
  export interface CliUpdateCheckConfig {
3
4
  manifestUrl: string;
4
5
  currentVersion: string;
@@ -11,6 +12,11 @@ export interface CliUpdateCheckConfig {
11
12
  timeoutMs?: number;
12
13
  target?: CliBuildTarget;
13
14
  allowPrivateHosts?: boolean;
15
+ /**
16
+ * Keys this build trusts. With none, nothing is enforced and the verdict says
17
+ * so out loud (`unenforced`) rather than leaving "checked" to be assumed.
18
+ */
19
+ trust?: CliTrustRoot;
14
20
  }
15
21
  /**
16
22
  * Four answers, never three. "Could not ask" is not "up to date": collapsing
@@ -22,11 +28,14 @@ export type CliUpdateCheck = {
22
28
  } | {
23
29
  status: 'current';
24
30
  version: string;
31
+ signature?: CliSignatureVerdict;
25
32
  } | {
26
33
  status: 'outdated';
27
34
  version: string;
28
35
  manifest: CliBuildManifest;
29
36
  asset?: CliBuildAsset;
37
+ /** What the signature check concluded — always present once it ran. */
38
+ signature?: CliSignatureVerdict;
30
39
  } | {
31
40
  status: 'unknown';
32
41
  reason: string;
@@ -46,11 +55,36 @@ export interface CliUpdateApplyConfig {
46
55
  timeoutMs?: number;
47
56
  maxBytes?: number;
48
57
  allowPrivateHosts?: boolean;
58
+ /**
59
+ * The document the asset came from, so authorship can be checked here too.
60
+ *
61
+ * `CliBuildAsset` cannot carry the proof: the signature covers the manifest's
62
+ * identity and every asset's digest together, which is what closes the chain
63
+ * on the file that executes. Passing both is what lets this refuse **before**
64
+ * it downloads anything.
65
+ */
66
+ manifest?: CliBuildManifest;
67
+ /** Keys this build trusts. With `manifest`, the pair is checked before the fetch. */
68
+ trust?: CliTrustRoot;
69
+ /**
70
+ * Keep the bytes being replaced, here, so there is something to go back to.
71
+ *
72
+ * Written after the new bytes are verified and before the target is replaced:
73
+ * a backup taken earlier could preserve a binary that was about to be
74
+ * replaced by a download that then failed its digest, and a backup taken
75
+ * later has nothing left to copy. The target's own mode is carried over — the
76
+ * point of a backup is to be runnable.
77
+ */
78
+ backupPath?: string;
49
79
  }
50
80
  export interface AppliedCliUpdate {
51
81
  path: string;
52
82
  bytes: number;
53
83
  sha256: string;
84
+ /** Where the replaced bytes were kept, when a backup was asked for and there was one. */
85
+ backupPath?: string;
86
+ /** Digest of the replaced bytes — what `rollbackCliUpdate` expects to find. */
87
+ backupSha256?: string;
54
88
  }
55
89
  /**
56
90
  * Download, verify and replace the binary.
@@ -61,4 +95,32 @@ export interface AppliedCliUpdate {
61
95
  * a partial write.
62
96
  */
63
97
  export declare function applyCliUpdate(config: CliUpdateApplyConfig): Promise<AppliedCliUpdate>;
98
+ export interface CliRollbackConfig {
99
+ /** The file to restore onto; defaults to the running executable. */
100
+ targetPath?: string;
101
+ /** The copy kept by a previous `applyCliUpdate({ backupPath })`. */
102
+ backupPath: string;
103
+ /**
104
+ * The digest the backup must have — `backupSha256` from that update.
105
+ *
106
+ * Required, not optional. A rollback that installs whatever happens to be at
107
+ * the backup path is a second install of an unverified binary, and the moment
108
+ * it is used is the moment nobody is in a position to check.
109
+ */
110
+ expectedSha256: string;
111
+ }
112
+ export interface RolledBackCliUpdate {
113
+ path: string;
114
+ bytes: number;
115
+ sha256: string;
116
+ }
117
+ /**
118
+ * Put the previous build back.
119
+ *
120
+ * Rolling back is a property of updating, not of the application: the same
121
+ * attention to atomicity and file mode the replacement gets, applied in the
122
+ * other direction. The digest is checked first, so a corrupted or swapped
123
+ * backup is a refusal rather than an unbootable tool.
124
+ */
125
+ export declare function rollbackCliUpdate(config: CliRollbackConfig): RolledBackCliUpdate;
64
126
  //# sourceMappingURL=cli-update.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cli-update.d.ts","sourceRoot":"","sources":["../../src/tools/cli-update.ts"],"names":[],"mappings":"AAeA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,gBAAgB,EAErB,KAAK,cAAc,EAGpB,MAAM,gBAAgB,CAAC;AASxB,MAAM,WAAW,oBAAoB;IACnC,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,4DAA4D;IAC5D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,sEAAsE;IACtE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,uDAAuD;IACvD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;;GAGG;AACH,MAAM,MAAM,cAAc,GACtB;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GAC1C;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACtC;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,gBAAgB,CAAC;IAAC,KAAK,CAAC,EAAE,aAAa,CAAA;CAAE,GAC1F;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,MAAM,C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B;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,yFAAyF;IACzF,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,+EAA+E;IAC/E,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;GAOG;AACH,wBAAsB,cAAc,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAqE5F;AAkBD,MAAM,WAAW,iBAAiB;IAChC,oEAAoE;IACpE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oEAAoE;IACpE,UAAU,EAAE,MAAM,CAAC;IACnB;;;;;;OAMG;IACH,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,iBAAiB,GAAG,mBAAmB,CAchF"}
@@ -1,23 +1,13 @@
1
1
  import type { ZodObject, z } from 'zod';
2
- import type { ServiceDef, StitchLogger } from '../server/types.js';
3
- import { type CliCommandDefinition } from './cli-command.js';
4
2
  import { type ExitCodeMap } from './cli-format.js';
5
- import { type CliPresentationPolicyConfig } from './cli-policy.js';
3
+ import { type CliInvocationResult, type CliInvoker, type CliInvokerCommand, type CliInvokerConfig, type CliSurfaceSource, cliInvocationResult, createCliInvoker } from './cli-invoke.js';
6
4
  import { type CliWaitConfig } from './cli-wait.js';
7
5
  import { type ErrorHintFn, type ToolCallHooks, type ToolLifecycle } from './execute.js';
8
- import type { RuntimeToolDefinition } from './runtime-tool.js';
9
- export type CliSurfaceSource<TAuth, TValue> = readonly TValue[] | ((auth: Awaited<TAuth> | undefined) => readonly TValue[]);
10
- export interface CliConfig<TAuth = unknown, TContext extends Record<string, unknown> = Record<string, unknown>, TGlobals extends ZodObject = ZodObject> extends CliPresentationPolicyConfig {
11
- /** Program name — shown in help and unknown-command messages. */
12
- name: string;
6
+ export type { CliInvocationResult, CliInvoker, CliInvokerCommand, CliInvokerConfig, CliSurfaceSource, };
7
+ export { cliInvocationResult, createCliInvoker };
8
+ export interface CliConfig<TAuth = unknown, TContext extends Record<string, unknown> = Record<string, unknown>, TGlobals extends ZodObject = ZodObject> extends CliInvokerConfig<TAuth, TContext, TGlobals> {
13
9
  /** Program version — printed by `--version`. */
14
10
  version: string;
15
- /** Contract services exposed as commands — may depend on the resolved identity. */
16
- services?: CliSurfaceSource<TAuth, ServiceDef>;
17
- /** Pathless managed operations. CLI exposure always requires `transports: ['CLI']`. */
18
- runtimeTools?: CliSurfaceSource<TAuth, RuntimeToolDefinition>;
19
- /** CLI-only executable commands, dispatched before auth and managed surface factories. */
20
- commands?: readonly CliCommandDefinition[];
21
11
  /**
22
12
  * Identity for the single CLI invocation — resolved ONCE at startup (from an
23
13
  * env var / token file), like a stdio MCP server, not per call. A value or a
@@ -56,8 +46,6 @@ export interface CliConfig<TAuth = unknown, TContext extends Record<string, unkn
56
46
  * a scoped command bypasses the gate.
57
47
  */
58
48
  lifecycle?: ToolLifecycle;
59
- /** Logger for diagnostics — defaults to stderr-safe `console.error`. */
60
- logger?: StitchLogger;
61
49
  /** Coerce JSON-stringified arrays/objects in arguments. Default: true. */
62
50
  coerceJsonArgs?: boolean;
63
51
  /** Global error hint appended to every failed command's error. */
@@ -1 +1 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/tools/cli.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,SAAS,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxC,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAUhE,OAAO,EACL,KAAK,oBAAoB,EAI1B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAsB,KAAK,WAAW,EAAc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AE,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACrE;;;OAGG;IACH,yBAAyB,CAAC,EAAE,OAAO,CAAC;IACpC,6EAA6E;IAC7E,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,6EAA6E;IAC7E,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,oEAAoE;IACpE,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,oEAAoE;IACpE,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,gEAAgE;IAChE,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9B,6EAA6E;IAC7E,KAAK,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CACtC;AAiZD,8EAA8E;AAC9E,wBAAsB,SAAS,CAC7B,KAAK,GAAG,OAAO,EACf,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClE,QAAQ,SAAS,SAAS,GAAG,SAAS,EACtC,MAAM,EAAE,SAAS,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAid7D"}
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  defineRuntimeTool
3
- } from "../../index-8z9we758.js";
3
+ } from "../../index-vjpvjqpn.js";
4
4
  import {
5
5
  declaresDraft07,
6
6
  withDefsDialect
7
- } from "../../index-fenaekmk.js";
7
+ } from "../../index-h9etkkyk.js";
8
8
  import"../../index-cby4ar3v.js";
9
9
  import {
10
10
  AppError
@@ -184,6 +184,27 @@ export interface ToolArgumentExtension {
184
184
  * `AppError` becomes a tool error. Shared by `executeToolMethod` and both
185
185
  * transport mounts so every tool error has one shape.
186
186
  */
187
+ /** What one tool call's arguments parse to — or why they did not. */
188
+ export type ParsedToolCallArguments = {
189
+ ok: true;
190
+ params: unknown;
191
+ input: unknown;
192
+ } | {
193
+ ok: false;
194
+ message: string;
195
+ thrown?: unknown;
196
+ };
197
+ /**
198
+ * Split and validate a flat tool-argument object exactly as a call does.
199
+ *
200
+ * Exported so the ONE thing that needs the parsed value without running the
201
+ * call — an elicitation resolver choosing this call's questions — gets the same
202
+ * value the handler will get, rather than a second parse written beside this
203
+ * one that drifts on the next coercion change. It is pure: no lifecycle, no
204
+ * hooks, no audit row, so asking what the arguments mean costs nothing that a
205
+ * gate would charge for.
206
+ */
207
+ export declare function parseToolCallArguments(method: ToolOperation, callArgs: Record<string, unknown>, coerceJson: boolean): ParsedToolCallArguments;
187
208
  export declare function toolResultFromError(err: unknown): ToolFailure;
188
209
  /** Recover the normalized AppError behind one canonical failed tool result. */
189
210
  export declare function toolErrorFromResult(result: ToolFailure): AppError;
@@ -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,EACL,QAAQ,EAGR,KAAK,cAAc,EACnB,KAAK,cAAc,EAEnB,KAAK,eAAe,EACrB,MAAM,aAAa,CAAC;AAKrB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAIzD,MAAM,MAAM,UAAU,GAClB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAC3B;IACE,EAAE,EAAE,KAAK,CAAC;IACV,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;;;;;OASG;IACH,SAAS,CAAC,EAA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