@llm4ts/flow 2.54.1 → 3.2.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.
- package/dist/Activity.d.ts +1 -1
- package/dist/Activity.d.ts.map +1 -1
- package/dist/Activity.js +20 -0
- package/dist/Activity.js.map +1 -1
- package/dist/EstimatedUsage.d.ts.map +1 -1
- package/dist/EstimatedUsage.js +0 -1
- package/dist/EstimatedUsage.js.map +1 -1
- package/dist/Pack.d.ts +11 -0
- package/dist/Pack.d.ts.map +1 -1
- package/dist/Pack.js +2 -0
- package/dist/Pack.js.map +1 -1
- package/dist/Replay.d.ts.map +1 -1
- package/dist/Replay.js +1 -4
- package/dist/Replay.js.map +1 -1
- package/dist/RosterSeats.d.ts.map +1 -1
- package/dist/RosterSeats.js +0 -1
- package/dist/RosterSeats.js.map +1 -1
- package/dist/Timing.d.ts.map +1 -1
- package/dist/Timing.js +0 -1
- package/dist/Timing.js.map +1 -1
- package/dist/Transcript.d.ts.map +1 -1
- package/dist/Transcript.js +0 -1
- package/dist/Transcript.js.map +1 -1
- package/dist/TransientRetry.d.ts.map +1 -1
- package/dist/TransientRetry.js +0 -1
- package/dist/TransientRetry.js.map +1 -1
- package/dist/endpoint/Auth.d.ts +194 -0
- package/dist/endpoint/Auth.d.ts.map +1 -0
- package/dist/endpoint/Auth.js +302 -0
- package/dist/endpoint/Auth.js.map +1 -0
- package/dist/endpoint/Endpoints.d.ts +21 -0
- package/dist/endpoint/Endpoints.d.ts.map +1 -0
- package/dist/endpoint/Endpoints.js +34 -0
- package/dist/endpoint/Endpoints.js.map +1 -0
- package/dist/endpoint/Transport.d.ts +90 -0
- package/dist/endpoint/Transport.d.ts.map +1 -0
- package/dist/endpoint/Transport.js +306 -0
- package/dist/endpoint/Transport.js.map +1 -0
- package/dist/tools/Builtin.d.ts +5 -0
- package/dist/tools/Builtin.d.ts.map +1 -0
- package/dist/tools/Builtin.js +7 -0
- package/dist/tools/Builtin.js.map +1 -0
- package/dist/tools/Diff.d.ts +8 -0
- package/dist/tools/Diff.d.ts.map +1 -0
- package/dist/tools/Diff.js +45 -0
- package/dist/tools/Diff.js.map +1 -0
- package/dist/tools/HttpCall.d.ts +14 -0
- package/dist/tools/HttpCall.d.ts.map +1 -0
- package/dist/tools/HttpCall.js +101 -0
- package/dist/tools/HttpCall.js.map +1 -0
- package/dist/tools/JsonSchemaCheck.d.ts +36 -0
- package/dist/tools/JsonSchemaCheck.d.ts.map +1 -0
- package/dist/tools/JsonSchemaCheck.js +342 -0
- package/dist/tools/JsonSchemaCheck.js.map +1 -0
- package/dist/tools/JsonValidate.d.ts +11 -0
- package/dist/tools/JsonValidate.d.ts.map +1 -0
- package/dist/tools/JsonValidate.js +84 -0
- package/dist/tools/JsonValidate.js.map +1 -0
- package/dist/tools/Tool.d.ts +126 -0
- package/dist/tools/Tool.d.ts.map +1 -0
- package/dist/tools/Tool.js +218 -0
- package/dist/tools/Tool.js.map +1 -0
- package/dist/tools/TreeDiff.d.ts +42 -0
- package/dist/tools/TreeDiff.d.ts.map +1 -0
- package/dist/tools/TreeDiff.js +276 -0
- package/dist/tools/TreeDiff.js.map +1 -0
- package/package.json +12 -4
- package/src/Activity.ts +22 -0
- package/src/EstimatedUsage.ts +0 -1
- package/src/Pack.ts +16 -0
- package/src/Replay.ts +1 -7
- package/src/RosterSeats.ts +0 -2
- package/src/Timing.ts +0 -10
- package/src/Transcript.ts +0 -1
- package/src/TransientRetry.ts +0 -2
- package/src/endpoint/Auth.ts +446 -0
- package/src/endpoint/Endpoints.ts +54 -0
- package/src/endpoint/Transport.ts +456 -0
- package/src/tools/Builtin.ts +10 -0
- package/src/tools/Diff.ts +61 -0
- package/src/tools/HttpCall.ts +124 -0
- package/src/tools/JsonSchemaCheck.ts +457 -0
- package/src/tools/JsonValidate.ts +106 -0
- package/src/tools/Tool.ts +351 -0
- package/src/tools/TreeDiff.ts +386 -0
- package/dist/WorkspaceLayout.d.ts +0 -3
- package/dist/WorkspaceLayout.d.ts.map +0 -1
- package/dist/WorkspaceLayout.js +0 -19
- package/dist/WorkspaceLayout.js.map +0 -1
- package/dist/WorkspaceTools.d.ts +0 -4
- package/dist/WorkspaceTools.d.ts.map +0 -1
- package/dist/WorkspaceTools.js +0 -130
- package/dist/WorkspaceTools.js.map +0 -1
- package/src/WorkspaceLayout.ts +0 -22
- package/src/WorkspaceTools.ts +0 -188
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import * as Context from "effect/Context";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Schema from "effect/Schema";
|
|
4
|
+
import type { SoapTransport } from "../endpoint/Transport.ts";
|
|
5
|
+
import { PlainFileStore } from "../Persistence.ts";
|
|
6
|
+
declare const ToolError_base: Schema.Class<ToolError, Schema.TaggedStruct<"ToolError", {
|
|
7
|
+
readonly tool: Schema.String;
|
|
8
|
+
readonly message: Schema.String;
|
|
9
|
+
}>, import("effect/Cause").YieldableError>;
|
|
10
|
+
/**
|
|
11
|
+
* A tool is one repeatable action a coding agent would otherwise improvise
|
|
12
|
+
* — validate a document, compare two outputs, probe an endpoint — packaged
|
|
13
|
+
* as a module with a typed input, a typed report and an Effect `run`
|
|
14
|
+
* (ADR 0048). The `llm4ts tool` CLI lists, describes and runs them; a pack
|
|
15
|
+
* names presets over them so a story sees the same command every run.
|
|
16
|
+
*/
|
|
17
|
+
export declare class ToolError extends ToolError_base {
|
|
18
|
+
}
|
|
19
|
+
declare const ToolIssue_base: Schema.Class<ToolIssue, Schema.Struct<{
|
|
20
|
+
readonly path: Schema.String;
|
|
21
|
+
readonly detail: Schema.String;
|
|
22
|
+
}>, {}>;
|
|
23
|
+
export declare class ToolIssue extends ToolIssue_base {
|
|
24
|
+
}
|
|
25
|
+
declare const ToolReport_base: Schema.Class<ToolReport, Schema.Struct<{
|
|
26
|
+
readonly tool: Schema.String;
|
|
27
|
+
readonly ok: Schema.Boolean;
|
|
28
|
+
readonly summary: Schema.String;
|
|
29
|
+
readonly issues: Schema.$Array<typeof ToolIssue>;
|
|
30
|
+
/** Issues cut from `issues` by the output cap; `--all` lifts it. */
|
|
31
|
+
readonly truncated: Schema.Int;
|
|
32
|
+
readonly data: Schema.optionalKey<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
33
|
+
}>, {}>;
|
|
34
|
+
/** What every tool prints: a verdict, one line, and the issues behind it. */
|
|
35
|
+
export declare class ToolReport extends ToolReport_base {
|
|
36
|
+
}
|
|
37
|
+
export declare const ToolArgKind: Schema.Literals<readonly ["string", "path", "integer", "boolean", "json"]>;
|
|
38
|
+
export type ToolArgKind = typeof ToolArgKind.Type;
|
|
39
|
+
export interface ToolArg {
|
|
40
|
+
readonly description: string;
|
|
41
|
+
readonly kind: ToolArgKind;
|
|
42
|
+
readonly required?: boolean;
|
|
43
|
+
readonly default?: string;
|
|
44
|
+
}
|
|
45
|
+
export interface ToolContextShape {
|
|
46
|
+
/** The project the tool runs for: the main checkout of a worktree (`.llm4ts/` lives here). */
|
|
47
|
+
readonly projectRoot: string;
|
|
48
|
+
/** The process environment, for `env:NAME` secret references; never printed. */
|
|
49
|
+
readonly environment: Readonly<Record<string, string | undefined>>;
|
|
50
|
+
}
|
|
51
|
+
declare const ToolContext_base: Context.ServiceClass<ToolContext, "@llm4ts/flow/tools/ToolContext", ToolContextShape>;
|
|
52
|
+
/** Where a tool runs: provided by the CLI, or by `runToolMain` from its arguments. */
|
|
53
|
+
export declare class ToolContext extends ToolContext_base {
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The services a tool may use: file reads, its context, and the endpoint
|
|
57
|
+
* transport (3.2, ADR 0048) — nothing else.
|
|
58
|
+
*/
|
|
59
|
+
export type ToolServices = PlainFileStore | ToolContext | SoapTransport;
|
|
60
|
+
/** A tool with its input type erased: what a catalog holds and the CLI runs. */
|
|
61
|
+
export interface ToolShape {
|
|
62
|
+
readonly name: string;
|
|
63
|
+
readonly purpose: string;
|
|
64
|
+
readonly args: Readonly<Record<string, ToolArg>>;
|
|
65
|
+
/** Decodes parsed arguments with the tool's schema, then runs it. */
|
|
66
|
+
readonly execute: (values: Record<string, unknown>) => Effect.Effect<ToolReport, ToolError | ToolArgsError, ToolServices>;
|
|
67
|
+
}
|
|
68
|
+
export interface Tool<I> extends ToolShape {
|
|
69
|
+
readonly input: Schema.Codec<I, unknown>;
|
|
70
|
+
readonly run: (input: I) => Effect.Effect<ToolReport, ToolError, ToolServices>;
|
|
71
|
+
}
|
|
72
|
+
export interface ToolDefinition<I> {
|
|
73
|
+
readonly name: string;
|
|
74
|
+
readonly purpose: string;
|
|
75
|
+
readonly args: Readonly<Record<string, ToolArg>>;
|
|
76
|
+
readonly input: Schema.Codec<I, unknown>;
|
|
77
|
+
readonly run: (input: I) => Effect.Effect<ToolReport, ToolError, ToolServices>;
|
|
78
|
+
}
|
|
79
|
+
export declare const defineTool: <I>(definition: ToolDefinition<I>) => Tool<I>;
|
|
80
|
+
declare const ToolSpec_base: Schema.Class<ToolSpec, Schema.Struct<{
|
|
81
|
+
readonly name: Schema.String;
|
|
82
|
+
readonly purpose: Schema.String;
|
|
83
|
+
readonly args: Schema.$Record<Schema.String, Schema.Struct<{
|
|
84
|
+
readonly description: Schema.String;
|
|
85
|
+
readonly kind: Schema.Literals<readonly ["string", "path", "integer", "boolean", "json"]>;
|
|
86
|
+
readonly required: Schema.optionalKey<Schema.Boolean>;
|
|
87
|
+
readonly default: Schema.optionalKey<Schema.String>;
|
|
88
|
+
}>>;
|
|
89
|
+
}>, {}>;
|
|
90
|
+
/** The spec the CLI prints for `describe` and the brief quotes per preset. */
|
|
91
|
+
export declare class ToolSpec extends ToolSpec_base {
|
|
92
|
+
}
|
|
93
|
+
export declare const specOf: (tool: Pick<ToolShape, "name" | "purpose" | "args">) => ToolSpec;
|
|
94
|
+
export declare const isToolName: (name: string) => boolean;
|
|
95
|
+
/** `describe` text: purpose, then one line per argument. */
|
|
96
|
+
export declare const renderSpec: (spec: ToolSpec) => string;
|
|
97
|
+
/** The one-line usage the brief quotes: `name --a <kind> [--b <kind>]`. */
|
|
98
|
+
export declare const renderUsage: (spec: ToolSpec) => string;
|
|
99
|
+
declare const ToolArgsError_base: Schema.Class<ToolArgsError, Schema.TaggedStruct<"ToolArgsError", {
|
|
100
|
+
readonly tool: Schema.String;
|
|
101
|
+
readonly message: Schema.String;
|
|
102
|
+
}>, import("effect/Cause").YieldableError>;
|
|
103
|
+
export declare class ToolArgsError extends ToolArgsError_base {
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* `--name value` pairs (a boolean flag stands alone) to the record a tool's
|
|
107
|
+
* input schema decodes: kinds coerce the text, unknown names and a missing
|
|
108
|
+
* required argument are errors that quote the spec.
|
|
109
|
+
*/
|
|
110
|
+
export declare const parseToolArgs: (spec: ToolSpec, argv: ReadonlyArray<string>) => Effect.Effect<Record<string, unknown>, ToolArgsError>;
|
|
111
|
+
/** Decodes parsed arguments with the tool's own schema; a failure quotes the spec. */
|
|
112
|
+
export declare const decodeToolInput: <I>(tool: ToolDefinition<I>, values: Record<string, unknown>) => Effect.Effect<I, ToolArgsError>;
|
|
113
|
+
export declare const defaultIssueCap = 50;
|
|
114
|
+
/** The report the CLI prints: issues capped unless `all`, the rest counted. */
|
|
115
|
+
export declare const capReport: (report: ToolReport, all: boolean) => ToolReport;
|
|
116
|
+
/** A plain-text rendering for terminals; the CLI default is JSON. */
|
|
117
|
+
export declare const renderReport: (report: ToolReport) => string;
|
|
118
|
+
/** Reads a document for a tool; a missing file is a `ToolError` naming it. */
|
|
119
|
+
export declare const readToolFile: (tool: string, path: string) => Effect.Effect<string, ToolError, PlainFileStore>;
|
|
120
|
+
export declare const parseJsonDocument: (tool: string, path: string, text: string) => Effect.Effect<unknown, ToolError>;
|
|
121
|
+
export declare const report: (tool: string, issues: ReadonlyArray<{
|
|
122
|
+
readonly path: string;
|
|
123
|
+
readonly detail: string;
|
|
124
|
+
}>, okSummary: string, data?: typeof Schema.Json.Type) => ToolReport;
|
|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BAAiB,GAC5B,MAAM,MAAM,EACZ,MAAM,MAAM,EACZ,MAAM,MAAM,KACX,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,SAAS,CAQ/B,CAAA;AAEJ,eAAO,MAAM,MAAM,GACjB,MAAM,MAAM,EACZ,QAAQ,aAAa,CAAC;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,EACzE,WAAW,MAAM,EACjB,OAAO,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,KAC7B,UASC,CAAA"}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import * as Context from "effect/Context";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Schema from "effect/Schema";
|
|
4
|
+
import { PlainFileStore } from "../Persistence.js";
|
|
5
|
+
/**
|
|
6
|
+
* A tool is one repeatable action a coding agent would otherwise improvise
|
|
7
|
+
* — validate a document, compare two outputs, probe an endpoint — packaged
|
|
8
|
+
* as a module with a typed input, a typed report and an Effect `run`
|
|
9
|
+
* (ADR 0048). The `llm4ts tool` CLI lists, describes and runs them; a pack
|
|
10
|
+
* names presets over them so a story sees the same command every run.
|
|
11
|
+
*/
|
|
12
|
+
export class ToolError extends Schema.TaggedError()("ToolError", {
|
|
13
|
+
tool: Schema.String,
|
|
14
|
+
message: Schema.String
|
|
15
|
+
}) {
|
|
16
|
+
}
|
|
17
|
+
export class ToolIssue extends Schema.Class("ToolIssue")({
|
|
18
|
+
path: Schema.String,
|
|
19
|
+
detail: Schema.String
|
|
20
|
+
}) {
|
|
21
|
+
}
|
|
22
|
+
/** What every tool prints: a verdict, one line, and the issues behind it. */
|
|
23
|
+
export class ToolReport extends Schema.Class("ToolReport")({
|
|
24
|
+
tool: Schema.String,
|
|
25
|
+
ok: Schema.Boolean,
|
|
26
|
+
summary: Schema.String,
|
|
27
|
+
issues: Schema.Array(ToolIssue),
|
|
28
|
+
/** Issues cut from `issues` by the output cap; `--all` lifts it. */
|
|
29
|
+
truncated: Schema.Int,
|
|
30
|
+
data: Schema.optionalKey(Schema.Json)
|
|
31
|
+
}) {
|
|
32
|
+
}
|
|
33
|
+
export const ToolArgKind = Schema.Literals(["string", "path", "integer", "boolean", "json"]);
|
|
34
|
+
/** Where a tool runs: provided by the CLI, or by `runToolMain` from its arguments. */
|
|
35
|
+
export class ToolContext extends Context.Service()("@llm4ts/flow/tools/ToolContext") {
|
|
36
|
+
}
|
|
37
|
+
export const defineTool = (definition) => ({
|
|
38
|
+
...definition,
|
|
39
|
+
execute: (values) => withArgDefaults(definition, values).pipe(Effect.flatMap((complete) => decodeToolInput(definition, complete)), Effect.flatMap(definition.run))
|
|
40
|
+
});
|
|
41
|
+
/** The argument table's defaults, coerced by kind, under every key the caller left out. */
|
|
42
|
+
const withArgDefaults = (tool, values) => Effect.gen(function* () {
|
|
43
|
+
const complete = { ...values };
|
|
44
|
+
for (const [name, arg] of Object.entries(tool.args)) {
|
|
45
|
+
if (arg.default !== undefined && !(name in complete)) {
|
|
46
|
+
complete[name] = yield* coerce(tool.name, name, arg.kind, arg.default);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return complete;
|
|
50
|
+
});
|
|
51
|
+
/** The spec the CLI prints for `describe` and the brief quotes per preset. */
|
|
52
|
+
export class ToolSpec extends Schema.Class("ToolSpec")({
|
|
53
|
+
name: Schema.String,
|
|
54
|
+
purpose: Schema.String,
|
|
55
|
+
args: Schema.Record(Schema.String, Schema.Struct({
|
|
56
|
+
description: Schema.String,
|
|
57
|
+
kind: ToolArgKind,
|
|
58
|
+
required: Schema.optionalKey(Schema.Boolean),
|
|
59
|
+
default: Schema.optionalKey(Schema.String)
|
|
60
|
+
}))
|
|
61
|
+
}) {
|
|
62
|
+
}
|
|
63
|
+
export const specOf = (tool) => ToolSpec.make({
|
|
64
|
+
name: tool.name,
|
|
65
|
+
purpose: tool.purpose,
|
|
66
|
+
args: Object.fromEntries(Object.entries(tool.args).map(([name, arg]) => [
|
|
67
|
+
name,
|
|
68
|
+
{
|
|
69
|
+
description: arg.description,
|
|
70
|
+
kind: arg.kind,
|
|
71
|
+
...(arg.required === undefined ? {} : { required: arg.required }),
|
|
72
|
+
...(arg.default === undefined ? {} : { default: arg.default })
|
|
73
|
+
}
|
|
74
|
+
]))
|
|
75
|
+
});
|
|
76
|
+
const toolNamePattern = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/u;
|
|
77
|
+
export const isToolName = (name) => toolNamePattern.test(name);
|
|
78
|
+
/** `describe` text: purpose, then one line per argument. */
|
|
79
|
+
export const renderSpec = (spec) => [
|
|
80
|
+
`${spec.name}: ${spec.purpose}`,
|
|
81
|
+
...Object.entries(spec.args).map(([name, arg]) => ` --${name} <${arg.kind}>${arg.required === true ? " (required)" : ""}${arg.default === undefined ? "" : ` [default ${arg.default}]`}: ${arg.description}`)
|
|
82
|
+
].join("\n");
|
|
83
|
+
/** The one-line usage the brief quotes: `name --a <kind> [--b <kind>]`. */
|
|
84
|
+
export const renderUsage = (spec) => [
|
|
85
|
+
spec.name,
|
|
86
|
+
...Object.entries(spec.args).map(([name, arg]) => arg.required === true ? `--${name} <${arg.kind}>` : `[--${name} <${arg.kind}>]`)
|
|
87
|
+
].join(" ");
|
|
88
|
+
export class ToolArgsError extends Schema.TaggedError()("ToolArgsError", {
|
|
89
|
+
tool: Schema.String,
|
|
90
|
+
message: Schema.String
|
|
91
|
+
}) {
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* `--name value` pairs (a boolean flag stands alone) to the record a tool's
|
|
95
|
+
* input schema decodes: kinds coerce the text, unknown names and a missing
|
|
96
|
+
* required argument are errors that quote the spec.
|
|
97
|
+
*/
|
|
98
|
+
export const parseToolArgs = (spec, argv) => Effect.gen(function* () {
|
|
99
|
+
const fail = (message) => new ToolArgsError({ tool: spec.name, message: `${message}\n${renderSpec(spec)}` });
|
|
100
|
+
const values = {};
|
|
101
|
+
for (const [name, arg] of Object.entries(spec.args)) {
|
|
102
|
+
if (arg.default !== undefined) {
|
|
103
|
+
values[name] = yield* coerce(spec.name, name, arg.kind, arg.default);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
let index = 0;
|
|
107
|
+
while (index < argv.length) {
|
|
108
|
+
const token = argv[index] ?? "";
|
|
109
|
+
if (!token.startsWith("--")) {
|
|
110
|
+
return yield* fail(`unexpected argument '${token}'`);
|
|
111
|
+
}
|
|
112
|
+
const equals = token.indexOf("=");
|
|
113
|
+
const name = equals > 0 ? token.slice(2, equals) : token.slice(2);
|
|
114
|
+
const arg = spec.args[name];
|
|
115
|
+
if (arg === undefined) {
|
|
116
|
+
return yield* fail(`unknown argument '--${name}'`);
|
|
117
|
+
}
|
|
118
|
+
let text;
|
|
119
|
+
if (equals > 0) {
|
|
120
|
+
text = token.slice(equals + 1);
|
|
121
|
+
index += 1;
|
|
122
|
+
}
|
|
123
|
+
else if (arg.kind === "boolean" &&
|
|
124
|
+
(index + 1 >= argv.length || argv[index + 1]?.startsWith("--"))) {
|
|
125
|
+
text = "true";
|
|
126
|
+
index += 1;
|
|
127
|
+
}
|
|
128
|
+
else if (index + 1 < argv.length) {
|
|
129
|
+
text = argv[index + 1] ?? "";
|
|
130
|
+
index += 2;
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
return yield* fail(`argument '--${name}' needs a value`);
|
|
134
|
+
}
|
|
135
|
+
values[name] = yield* coerce(spec.name, name, arg.kind, text);
|
|
136
|
+
}
|
|
137
|
+
for (const [name, arg] of Object.entries(spec.args)) {
|
|
138
|
+
if (arg.required === true && !(name in values)) {
|
|
139
|
+
return yield* fail(`missing required argument '--${name}'`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return values;
|
|
143
|
+
});
|
|
144
|
+
const coerce = (tool, name, kind, text) => {
|
|
145
|
+
switch (kind) {
|
|
146
|
+
case "string":
|
|
147
|
+
case "path":
|
|
148
|
+
return Effect.succeed(text);
|
|
149
|
+
case "integer": {
|
|
150
|
+
const value = Number.parseInt(text, 10);
|
|
151
|
+
return Number.isInteger(value) && String(value) === text.trim()
|
|
152
|
+
? Effect.succeed(value)
|
|
153
|
+
: Effect.fail(new ToolArgsError({
|
|
154
|
+
tool,
|
|
155
|
+
message: `argument '--${name}' expects an integer, got '${text}'`
|
|
156
|
+
}));
|
|
157
|
+
}
|
|
158
|
+
case "boolean":
|
|
159
|
+
return text === "true" || text === "false"
|
|
160
|
+
? Effect.succeed(text === "true")
|
|
161
|
+
: Effect.fail(new ToolArgsError({
|
|
162
|
+
tool,
|
|
163
|
+
message: `argument '--${name}' expects true or false, got '${text}'`
|
|
164
|
+
}));
|
|
165
|
+
case "json":
|
|
166
|
+
return Effect.try({
|
|
167
|
+
try: () => JSON.parse(text),
|
|
168
|
+
catch: () => new ToolArgsError({ tool, message: `argument '--${name}' is not valid JSON` })
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
/** Decodes parsed arguments with the tool's own schema; a failure quotes the spec. */
|
|
173
|
+
export const decodeToolInput = (tool, values) => Schema.decodeUnknownEffect(tool.input)(values).pipe(Effect.mapError((error) => new ToolArgsError({
|
|
174
|
+
tool: tool.name,
|
|
175
|
+
message: `${String(error)}\n${renderSpec(specOf(tool))}`
|
|
176
|
+
})));
|
|
177
|
+
export const defaultIssueCap = 50;
|
|
178
|
+
/** The report the CLI prints: issues capped unless `all`, the rest counted. */
|
|
179
|
+
export const capReport = (report, all) => all || report.issues.length <= defaultIssueCap
|
|
180
|
+
? report
|
|
181
|
+
: ToolReport.make({
|
|
182
|
+
...report,
|
|
183
|
+
issues: report.issues.slice(0, defaultIssueCap),
|
|
184
|
+
truncated: report.truncated + report.issues.length - defaultIssueCap
|
|
185
|
+
});
|
|
186
|
+
/** A plain-text rendering for terminals; the CLI default is JSON. */
|
|
187
|
+
export const renderReport = (report) => [
|
|
188
|
+
`${report.ok ? "ok" : "FAIL"} ${report.tool}: ${report.summary}`,
|
|
189
|
+
...report.issues.map((issue) => ` ${issue.path}: ${issue.detail}`),
|
|
190
|
+
...(report.truncated > 0 ? [` … ${report.truncated} more (run with --all)`] : [])
|
|
191
|
+
].join("\n");
|
|
192
|
+
/** Reads a document for a tool; a missing file is a `ToolError` naming it. */
|
|
193
|
+
export const readToolFile = (tool, path) => Effect.gen(function* () {
|
|
194
|
+
const files = yield* PlainFileStore;
|
|
195
|
+
const text = yield* files
|
|
196
|
+
.read(path)
|
|
197
|
+
.pipe(Effect.mapError((error) => new ToolError({ tool, message: `cannot read ${path}: ${error.message}` })));
|
|
198
|
+
if (text === undefined) {
|
|
199
|
+
return yield* new ToolError({ tool, message: `no such file: ${path}` });
|
|
200
|
+
}
|
|
201
|
+
return text;
|
|
202
|
+
});
|
|
203
|
+
export const parseJsonDocument = (tool, path, text) => Effect.try({
|
|
204
|
+
try: () => JSON.parse(text),
|
|
205
|
+
catch: (error) => new ToolError({
|
|
206
|
+
tool,
|
|
207
|
+
message: `${path} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`
|
|
208
|
+
})
|
|
209
|
+
});
|
|
210
|
+
export const report = (tool, issues, okSummary, data) => ToolReport.make({
|
|
211
|
+
tool,
|
|
212
|
+
ok: issues.length === 0,
|
|
213
|
+
summary: issues.length === 0 ? okSummary : `${issues.length} issue${issues.length === 1 ? "" : "s"}`,
|
|
214
|
+
issues: issues.map((issue) => ToolIssue.make({ path: issue.path, detail: issue.detail })),
|
|
215
|
+
truncated: 0,
|
|
216
|
+
...(data === undefined ? {} : { data })
|
|
217
|
+
});
|
|
218
|
+
//# sourceMappingURL=Tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tool.js","sourceRoot":"","sources":["../../src/tools/Tool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAA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8B,EAClB,EAAE,CACd,UAAU,CAAC,IAAI,CAAC;IACd,IAAI;IACJ,EAAE,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;IACvB,OAAO,EACL,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE;IAC7F,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;IACzF,SAAS,EAAE,CAAC;IACZ,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC;CACxC,CAAC,CAAA"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A deep structural compare of two JSON values that reports every difference
|
|
3
|
+
* with a JSONPath-style location, for tools that check an actual payload
|
|
4
|
+
* against an expected one.
|
|
5
|
+
*
|
|
6
|
+
* Arrays compare under one of three orderings: by position (`ordered`), by an
|
|
7
|
+
* identity field of their object elements (`per-key`), or as a multiset of
|
|
8
|
+
* canonical JSON (`unordered`). Paths named in `ignore` are skipped on both
|
|
9
|
+
* sides, so neither a missing nor an unexpected nor a changed value is
|
|
10
|
+
* reported for them.
|
|
11
|
+
*/
|
|
12
|
+
export type DiffOrdering = "ordered" | "per-key" | "unordered";
|
|
13
|
+
export type DiffKind = "missing" | "unexpected" | "changed" | "type";
|
|
14
|
+
export interface DiffIssue {
|
|
15
|
+
readonly path: string;
|
|
16
|
+
readonly kind: DiffKind;
|
|
17
|
+
readonly detail: string;
|
|
18
|
+
}
|
|
19
|
+
export interface TreeDiffOptions {
|
|
20
|
+
readonly ordering: DiffOrdering;
|
|
21
|
+
/**
|
|
22
|
+
* Dot paths to skip, with `*` matching any one segment: `meta.requestId`,
|
|
23
|
+
* `items.*.updatedAt`. An array index is a segment (`items.2`); under
|
|
24
|
+
* `per-key` an element's segment is its identity (`items.42` or
|
|
25
|
+
* `items.id=42`).
|
|
26
|
+
*/
|
|
27
|
+
readonly ignore: ReadonlyArray<string>;
|
|
28
|
+
/**
|
|
29
|
+
* For `per-key`: the first of these fields present in an array element
|
|
30
|
+
* names its identity. Defaults to `["id", "key", "name", "code"]`.
|
|
31
|
+
*/
|
|
32
|
+
readonly keyFields?: ReadonlyArray<string>;
|
|
33
|
+
}
|
|
34
|
+
/** Serialises a value as compact JSON with object keys sorted. */
|
|
35
|
+
export declare const canonicalJson: (value: unknown) => string;
|
|
36
|
+
/**
|
|
37
|
+
* Compares `actual` against `expected` and returns every difference found,
|
|
38
|
+
* in document order: for objects the expected keys first, then the extra
|
|
39
|
+
* keys of `actual`; for arrays as the ordering dictates.
|
|
40
|
+
*/
|
|
41
|
+
export declare const diffJson: (expected: unknown, actual: unknown, options: TreeDiffOptions) => ReadonlyArray<DiffIssue>;
|
|
42
|
+
//# sourceMappingURL=TreeDiff.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TreeDiff.d.ts","sourceRoot":"","sources":["../../src/tools/TreeDiff.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,SAAS,GAAG,WAAW,CAAA;AAE9D,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,YAAY,GAAG,SAAS,GAAG,MAAM,CAAA;AAEpE,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CACxB;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAA;IAC/B;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;IACtC;;;OAGG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;CAC3C;AAeD,kEAAkE;AAClE,eAAO,MAAM,aAAa,GAAI,OAAO,OAAO,KAAG,MAW9C,CAAA;AAgTD;;;;GAIG;AACH,eAAO,MAAM,QAAQ,GACnB,UAAU,OAAO,EACjB,QAAQ,OAAO,EACf,SAAS,eAAe,KACvB,aAAa,CAAC,SAAS,CASzB,CAAA"}
|