@halonicjs/testing 0.1.1 → 0.1.2
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/adapters/http-kit/src/connector-host-class.d.ts +14 -0
- package/dist/adapters/http-kit/src/connector-host-class.js +34 -0
- package/dist/adapters/http-kit/src/index.d.ts +2 -0
- package/dist/adapters/http-kit/src/index.js +2 -0
- package/dist/adapters/http-kit/src/ollama-tags.d.ts +20 -0
- package/dist/adapters/http-kit/src/ollama-tags.js +38 -0
- package/dist/adapters/integration-kit/src/index.d.ts +2 -1
- package/dist/adapters/integration-kit/src/index.js +1 -0
- package/dist/adapters/integration-kit/src/loader.d.ts +2 -12
- package/dist/adapters/integration-kit/src/loader.js +3 -20
- package/dist/adapters/integration-kit/src/workspace-choices.d.ts +37 -0
- package/dist/adapters/integration-kit/src/workspace-choices.js +37 -0
- package/dist/core/events/src/connector-listing-failed.d.ts +18 -0
- package/dist/core/events/src/connector-listing-failed.js +1 -0
- package/dist/core/events/src/home-path.d.ts +4 -1
- package/dist/core/events/src/home-path.js +14 -3
- package/dist/core/events/src/index.d.ts +4 -2
- package/dist/core/events/src/index.js +2 -0
- package/dist/core/events/src/provider-notes.d.ts +16 -0
- package/dist/core/events/src/provider-notes.js +24 -0
- package/dist/core/events/src/run-basics.d.ts +103 -5
- package/dist/core/events/src/run-event.d.ts +72 -7
- package/dist/core/events/src/run-summary.d.ts +11 -1
- package/dist/core/events/src/sandbox-opened-read.d.ts +2 -1
- package/dist/core/events/src/sandbox-opened-read.js +27 -2
- package/dist/core/events/src/sandbox-opened.d.ts +37 -4
- package/dist/core/events/src/sandbox-opened.js +13 -3
- package/dist/core/events/src/summarize.js +3 -0
- package/dist/core/events/src/tool-failure-cause.d.ts +25 -0
- package/dist/core/events/src/tool-failure-cause.js +66 -0
- package/dist/core/format/src/index.d.ts +3 -2
- package/dist/core/format/src/index.js +3 -1
- package/dist/core/format/src/kinds/agent/harness-limits.d.ts +14 -0
- package/dist/core/format/src/kinds/agent/harness-limits.js +27 -0
- package/dist/core/format/src/kinds/agent/schema.d.ts +5 -0
- package/dist/core/format/src/kinds/agent/schema.js +3 -0
- package/dist/core/format/src/kinds/connector/kind.js +24 -3
- package/dist/core/format/src/kinds/connector/schema.d.ts +14 -0
- package/dist/core/format/src/kinds/connector/schema.js +18 -0
- package/dist/core/format/src/kinds/integration/schema.js +1 -1
- package/dist/core/format/src/kinds/integration/sign-in-checks.d.ts +2 -1
- package/dist/core/format/src/kinds/integration/sign-in-checks.js +33 -3
- package/dist/core/format/src/kinds/plugin/checks.d.ts +3 -2
- package/dist/core/format/src/kinds/plugin/checks.js +17 -5
- package/dist/core/format/src/kinds/plugin/schema.js +24 -4
- package/dist/core/format/src/kinds/provider/kind.js +40 -1
- package/dist/core/format/src/kinds/provider/types.d.ts +19 -0
- package/dist/core/format/src/kinds/provider/types.js +22 -0
- package/dist/core/format/src/kinds/routine/schema.d.ts +10 -5
- package/dist/core/format/src/kinds/routine/schema.js +21 -15
- package/dist/core/format/src/kinds/workspace/schema.js +5 -4
- package/dist/core/format/src/parse-file.js +3 -1
- package/dist/core/format/src/shared/fields.d.ts +9 -2
- package/dist/core/format/src/shared/fields.js +15 -6
- package/dist/core/format/src/shared/guard.d.ts +8 -0
- package/dist/core/format/src/shared/guard.js +50 -1
- package/dist/core/format/src/shared/missing-keys.d.ts +17 -0
- package/dist/core/format/src/shared/missing-keys.js +110 -0
- package/dist/core/ports/src/chat.d.ts +8 -0
- package/dist/core/ports/src/connector-start-failure.d.ts +31 -0
- package/dist/core/ports/src/connector-start-failure.js +32 -0
- package/dist/core/ports/src/connector-tool-error.d.ts +33 -0
- package/dist/core/ports/src/connector-tool-error.js +40 -0
- package/dist/core/ports/src/definition-store-left-out.d.ts +46 -0
- package/dist/core/ports/src/definition-store-left-out.js +47 -0
- package/dist/core/ports/src/definition-store.d.ts +13 -3
- package/dist/core/ports/src/definition-store.js +1 -1
- package/dist/core/ports/src/deploy-target.d.ts +358 -0
- package/dist/core/ports/src/deploy-target.js +2 -0
- package/dist/core/ports/src/harness-bridge-server.d.ts +55 -4
- package/dist/core/ports/src/harness.d.ts +33 -2
- package/dist/core/ports/src/host-too-old.d.ts +23 -0
- package/dist/core/ports/src/host-too-old.js +27 -0
- package/dist/core/ports/src/index.d.ts +16 -5
- package/dist/core/ports/src/index.js +15 -3
- package/dist/core/ports/src/llm-provider.d.ts +37 -6
- package/dist/core/ports/src/llm-provider.js +43 -3
- package/dist/core/ports/src/pairing-codes.d.ts +111 -0
- package/dist/core/ports/src/pairing-codes.js +336 -0
- package/dist/core/ports/src/pairing-qr-bytes.d.ts +32 -0
- package/dist/core/ports/src/pairing-qr-bytes.js +116 -0
- package/dist/core/ports/src/port-versions.d.ts +6 -2
- package/dist/core/ports/src/port-versions.js +8 -0
- package/dist/core/ports/src/remote-control.d.ts +159 -0
- package/dist/core/ports/src/remote-control.js +26 -0
- package/dist/core/ports/src/remote-gateway-protocol.d.ts +220 -0
- package/dist/core/ports/src/remote-gateway-protocol.js +62 -0
- package/dist/core/ports/src/remote-gateway-session.d.ts +194 -0
- package/dist/core/ports/src/remote-gateway-session.js +241 -0
- package/dist/core/ports/src/run-executor.d.ts +39 -3
- package/dist/core/ports/src/run-executor.js +1 -1
- package/dist/core/ports/src/sandbox.d.ts +19 -0
- package/dist/core/ports/src/sandbox.js +14 -0
- package/dist/core/ports/src/secrets.d.ts +32 -1
- package/dist/core/ports/src/secrets.js +19 -2
- package/dist/core/ports/src/tunnel-provider.d.ts +117 -0
- package/dist/core/ports/src/tunnel-provider.js +65 -0
- package/dist/core/ports/src/tunnel-resolver.d.ts +83 -0
- package/dist/core/ports/src/tunnel-resolver.js +36 -0
- package/dist/core/ports/src/vcs.d.ts +30 -0
- package/dist/core/schema-kit/src/builders.d.ts +5 -0
- package/dist/core/schema-kit/src/builders.js +5 -0
- package/dist/core/std/src/hidden-characters.d.ts +9 -0
- package/dist/core/std/src/hidden-characters.js +18 -0
- package/dist/core/std/src/index.d.ts +3 -1
- package/dist/core/std/src/index.js +3 -1
- package/dist/core/std/src/path-overlap.d.ts +22 -0
- package/dist/core/std/src/path-overlap.js +57 -0
- package/dist/core/std/src/public-suffixes.generated.d.ts +1 -1
- package/dist/core/std/src/public-suffixes.generated.js +0 -1
- package/dist/core/std/src/word-diff.d.ts +28 -0
- package/dist/core/std/src/word-diff.js +77 -0
- package/dist/core/yaml/src/edit-data.d.ts +7 -0
- package/dist/core/yaml/src/edit-data.js +62 -3
- package/dist/core/yaml/src/edit.d.ts +7 -0
- package/dist/core/yaml/src/edit.js +34 -3
- package/dist/core/yaml/src/splice-node.d.ts +6 -0
- package/dist/core/yaml/src/splice-node.js +10 -0
- package/dist/core/yaml/src/splice.js +20 -10
- package/dist/testing/integration/src/checks.d.ts +5 -3
- package/dist/testing/integration/src/checks.js +31 -3
- package/package.json +9 -2
|
@@ -1,5 +1,50 @@
|
|
|
1
1
|
import { s } from "../../../schema-kit/src/index.js";
|
|
2
2
|
const pair = () => s.tuple([s.unknown(), s.unknown()]);
|
|
3
|
+
/** The condition kinds, in the order the schema tries them. */
|
|
4
|
+
const GUARD_KINDS = [
|
|
5
|
+
"equals",
|
|
6
|
+
"notEquals",
|
|
7
|
+
"contains",
|
|
8
|
+
"exists",
|
|
9
|
+
"gt",
|
|
10
|
+
"gte",
|
|
11
|
+
"lt",
|
|
12
|
+
"lte",
|
|
13
|
+
"not",
|
|
14
|
+
"all",
|
|
15
|
+
"any",
|
|
16
|
+
];
|
|
17
|
+
/** What each kind takes, for the message about a known kind written the wrong way. */
|
|
18
|
+
const GUARD_SHAPES = {
|
|
19
|
+
equals: "a list of two values",
|
|
20
|
+
notEquals: "a list of two values",
|
|
21
|
+
contains: "a list of two values",
|
|
22
|
+
exists: "a path, such as input.email",
|
|
23
|
+
gt: "a list of two values",
|
|
24
|
+
gte: "a list of two values",
|
|
25
|
+
lt: "a list of two values",
|
|
26
|
+
lte: "a list of two values",
|
|
27
|
+
not: "one condition",
|
|
28
|
+
all: "a list of conditions",
|
|
29
|
+
any: "a list of conditions",
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Says what is wrong with a value that is no condition, instead of Zod's
|
|
33
|
+
* "Invalid input": an unknown kind and the allowed ones, or what a known
|
|
34
|
+
* kind takes.
|
|
35
|
+
*/
|
|
36
|
+
export function guardProblem(input) {
|
|
37
|
+
const allowed = `allowed: ${GUARD_KINDS.join(", ")}`;
|
|
38
|
+
const keys = typeof input === "object" && input !== null && !Array.isArray(input) ? Object.keys(input) : [];
|
|
39
|
+
if (keys.length !== 1) {
|
|
40
|
+
return `a condition is a map with exactly one kind, such as { equals: [a, b] }; ${allowed}`;
|
|
41
|
+
}
|
|
42
|
+
const [kind = ""] = keys;
|
|
43
|
+
const shape = GUARD_SHAPES[kind];
|
|
44
|
+
return shape === undefined
|
|
45
|
+
? `unknown condition kind "${kind}"; ${allowed}`
|
|
46
|
+
: `condition "${kind}" takes ${shape}`;
|
|
47
|
+
}
|
|
3
48
|
/** The schema of a `Guard`. It refers to itself for `not`, `all` and `any`. */
|
|
4
49
|
export const Guard = s.lazy(() => s.union([
|
|
5
50
|
s.object({ equals: pair() }).strict(),
|
|
@@ -13,4 +58,8 @@ export const Guard = s.lazy(() => s.union([
|
|
|
13
58
|
s.object({ not: Guard }).strict(),
|
|
14
59
|
s.object({ all: s.array(Guard) }).strict(),
|
|
15
60
|
s.object({ any: s.array(Guard) }).strict(),
|
|
16
|
-
]));
|
|
61
|
+
], { error: (issue) => guardProblem(issue.input) }));
|
|
62
|
+
/** Whether a value is a condition the engine accepts, so callers can check before they write one. */
|
|
63
|
+
export function isGuard(value) {
|
|
64
|
+
return Guard.safeParse(value).success;
|
|
65
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type Issue } from "../../../schema-kit/src/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Words the schema's issues the way a person fixes them (HAL-12126). A
|
|
4
|
+
* required key that isn't there says so by name, instead of Zod's "Invalid
|
|
5
|
+
* input: expected string, received undefined", whose path the line doesn't
|
|
6
|
+
* show. An unrecognized key next to it that is a near spelling of a missing
|
|
7
|
+
* key asks "Did you mean …?". Codes and paths stay Zod's.
|
|
8
|
+
*
|
|
9
|
+
* @param issues - the schema's issues for one file
|
|
10
|
+
* @param data - the data the schema got, to tell a missing key from a wrong value
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // { nmae: "Acme" } for a kind that needs `name`:
|
|
14
|
+
* wordIssues(issues, data).map((issue) => issue.message);
|
|
15
|
+
* // ['Missing required key "name"', 'Unrecognized key: "nmae". Did you mean "name"?']
|
|
16
|
+
*/
|
|
17
|
+
export declare function wordIssues(issues: readonly Issue[], data: unknown): Issue[];
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { formatPath } from "../../../schema-kit/src/index.js";
|
|
2
|
+
import { isMap } from "./legacy-keys.js";
|
|
3
|
+
/**
|
|
4
|
+
* How far a misspelled key may be from a missing one for "did you mean": the
|
|
5
|
+
* CLI's limit for a typed command (cli-output 1.3), so "nmae" finds "name".
|
|
6
|
+
*/
|
|
7
|
+
const nearDistance = 2;
|
|
8
|
+
/**
|
|
9
|
+
* Words the schema's issues the way a person fixes them (HAL-12126). A
|
|
10
|
+
* required key that isn't there says so by name, instead of Zod's "Invalid
|
|
11
|
+
* input: expected string, received undefined", whose path the line doesn't
|
|
12
|
+
* show. An unrecognized key next to it that is a near spelling of a missing
|
|
13
|
+
* key asks "Did you mean …?". Codes and paths stay Zod's.
|
|
14
|
+
*
|
|
15
|
+
* @param issues - the schema's issues for one file
|
|
16
|
+
* @param data - the data the schema got, to tell a missing key from a wrong value
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* // { nmae: "Acme" } for a kind that needs `name`:
|
|
20
|
+
* wordIssues(issues, data).map((issue) => issue.message);
|
|
21
|
+
* // ['Missing required key "name"', 'Unrecognized key: "nmae". Did you mean "name"?']
|
|
22
|
+
*/
|
|
23
|
+
export function wordIssues(issues, data) {
|
|
24
|
+
const missing = issues.filter((issue) => isMissingKey(issue, data));
|
|
25
|
+
return issues.map((issue) => {
|
|
26
|
+
if (missing.includes(issue)) {
|
|
27
|
+
return { ...issue, message: `Missing required key "${String(issue.path.at(-1))}"` };
|
|
28
|
+
}
|
|
29
|
+
if (issue.code === "unrecognized_keys" && issue.keys !== undefined) {
|
|
30
|
+
const near = nearMissingKeys(issue.keys, missingKeysIn(missing, issue.path));
|
|
31
|
+
return near === "" ? issue : { ...issue, message: `${issue.message}. ${near}` };
|
|
32
|
+
}
|
|
33
|
+
return issue;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/** Whether Zod found a wrong type because the key isn't in its map at all. */
|
|
37
|
+
function isMissingKey(issue, data) {
|
|
38
|
+
const key = issue.path.at(-1);
|
|
39
|
+
if (issue.code !== "invalid_type" || typeof key !== "string") {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
const parent = valueAt(data, issue.path.slice(0, -1));
|
|
43
|
+
return isMap(parent) && !Object.hasOwn(parent, key);
|
|
44
|
+
}
|
|
45
|
+
/** The value at a path, or `undefined` when a step of it isn't there. */
|
|
46
|
+
function valueAt(data, path) {
|
|
47
|
+
let value = data;
|
|
48
|
+
for (const segment of path) {
|
|
49
|
+
if (Array.isArray(value) && typeof segment === "number") {
|
|
50
|
+
value = value[segment];
|
|
51
|
+
}
|
|
52
|
+
else if (isMap(value) && typeof segment === "string" && Object.hasOwn(value, segment)) {
|
|
53
|
+
value = value[segment];
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return value;
|
|
60
|
+
}
|
|
61
|
+
/** The missing keys of the map at `path`. */
|
|
62
|
+
function missingKeysIn(missing, path) {
|
|
63
|
+
const where = formatPath(path);
|
|
64
|
+
return missing
|
|
65
|
+
.filter((issue) => formatPath(issue.path.slice(0, -1)) === where)
|
|
66
|
+
.map((issue) => String(issue.path.at(-1)));
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* "Did you mean "name"?" for one unrecognized key, or with the key named for
|
|
70
|
+
* several: 'Did you mean "name" for "nmae"?'. A key with no missing key
|
|
71
|
+
* near it, or with two equally likely, gets no guess.
|
|
72
|
+
*/
|
|
73
|
+
function nearMissingKeys(unrecognized, missing) {
|
|
74
|
+
const pairs = unrecognized.flatMap((key) => {
|
|
75
|
+
const near = missing.filter((candidate) => editDistance(key, candidate) <= nearDistance);
|
|
76
|
+
return near.length === 1 ? [{ key, near: near[0] }] : [];
|
|
77
|
+
});
|
|
78
|
+
if (pairs.length === 0) {
|
|
79
|
+
return "";
|
|
80
|
+
}
|
|
81
|
+
if (unrecognized.length === 1) {
|
|
82
|
+
return `Did you mean "${pairs[0]?.near}"?`;
|
|
83
|
+
}
|
|
84
|
+
return `Did you mean ${pairs.map(({ key, near }) => `"${near}" for "${key}"`).join(", ")}?`;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The fewest single-character insertions, deletions, substitutions and swaps
|
|
88
|
+
* of two neighbours that turn `from` into `to`, so "nmae" and "name" are one apart.
|
|
89
|
+
* The CLI has its own copy for commands; core can't use the CLI's.
|
|
90
|
+
*/
|
|
91
|
+
function editDistance(from, to) {
|
|
92
|
+
const width = to.length + 1;
|
|
93
|
+
const cells = new Array((from.length + 1) * width).fill(0);
|
|
94
|
+
const at = (i, j) => cells[i * width + j] ?? 0;
|
|
95
|
+
for (let i = 0; i <= from.length; i += 1) {
|
|
96
|
+
for (let j = 0; j <= to.length; j += 1) {
|
|
97
|
+
if (i === 0 || j === 0) {
|
|
98
|
+
cells[i * width + j] = i + j;
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
const cost = from[i - 1] === to[j - 1] ? 0 : 1;
|
|
102
|
+
let best = Math.min(at(i - 1, j) + 1, at(i, j - 1) + 1, at(i - 1, j - 1) + cost);
|
|
103
|
+
if (i > 1 && j > 1 && from[i - 1] === to[j - 2] && from[i - 2] === to[j - 1]) {
|
|
104
|
+
best = Math.min(best, at(i - 2, j - 2) + 1);
|
|
105
|
+
}
|
|
106
|
+
cells[i * width + j] = best;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return at(from.length, to.length);
|
|
110
|
+
}
|
|
@@ -85,6 +85,14 @@ export interface ChatResponse {
|
|
|
85
85
|
finishReason: "stop" | "tool_calls" | "length" | "error" | "other";
|
|
86
86
|
/** The provider's record of this turn; the engine copies it onto the assistant message unchanged. */
|
|
87
87
|
replay?: ProviderReplay;
|
|
88
|
+
/**
|
|
89
|
+
* Plain sentences from the provider on how it changed the call, for the
|
|
90
|
+
* person who reads the run log, such as "Left out temperature:
|
|
91
|
+
* claude-sonnet-5-5 doesn't take it." The provider's own words: never the
|
|
92
|
+
* vendor's text, never a key. The engine keeps them on the call's
|
|
93
|
+
* `llm.response`, out of the conversation. Absent when it changed nothing.
|
|
94
|
+
*/
|
|
95
|
+
notes?: string[];
|
|
88
96
|
}
|
|
89
97
|
/**
|
|
90
98
|
* One piece of a streamed answer. Deltas arrive in the order the model
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Why a connector couldn't start, when it's one the engine can name
|
|
3
|
+
* (requirement `ports.connector-start-failure`): its program isn't on this
|
|
4
|
+
* computer, or a secret it needs isn't set. `program` and `secret` are names
|
|
5
|
+
* as the connector's file writes them, never a secret's value.
|
|
6
|
+
*/
|
|
7
|
+
export type ConnectorStartFailure = {
|
|
8
|
+
readonly reason: "program-missing";
|
|
9
|
+
readonly program: string;
|
|
10
|
+
} | {
|
|
11
|
+
readonly reason: "secret-not-set";
|
|
12
|
+
readonly secret: string;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Why `value`, thrown while a connector started, says it couldn't start, or
|
|
16
|
+
* `undefined` for any other error. A connector adapter says it with two
|
|
17
|
+
* errors (as `@halonicjs/adapter-mcp` does):
|
|
18
|
+
*
|
|
19
|
+
* - an `Error` named `ProgramNotFoundError` with the program's name in `program`;
|
|
20
|
+
* - an `Error` named `SecretNotSetError` with the secret's name in `secretName`.
|
|
21
|
+
*
|
|
22
|
+
* It reads them by name and field, not `instanceof`, so the engine needs no
|
|
23
|
+
* adapter, and an adapter with its own copy of this package works too. It
|
|
24
|
+
* keeps only the name, never the error's message, which can hold paths or
|
|
25
|
+
* a program's output.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* connectorStartFailureOf(new SecretNotSetError("notes", "NOTES_TOKEN"));
|
|
29
|
+
* // => { reason: "secret-not-set", secret: "NOTES_TOKEN" }
|
|
30
|
+
*/
|
|
31
|
+
export declare function connectorStartFailureOf(value: unknown): ConnectorStartFailure | undefined;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Why `value`, thrown while a connector started, says it couldn't start, or
|
|
3
|
+
* `undefined` for any other error. A connector adapter says it with two
|
|
4
|
+
* errors (as `@halonicjs/adapter-mcp` does):
|
|
5
|
+
*
|
|
6
|
+
* - an `Error` named `ProgramNotFoundError` with the program's name in `program`;
|
|
7
|
+
* - an `Error` named `SecretNotSetError` with the secret's name in `secretName`.
|
|
8
|
+
*
|
|
9
|
+
* It reads them by name and field, not `instanceof`, so the engine needs no
|
|
10
|
+
* adapter, and an adapter with its own copy of this package works too. It
|
|
11
|
+
* keeps only the name, never the error's message, which can hold paths or
|
|
12
|
+
* a program's output.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* connectorStartFailureOf(new SecretNotSetError("notes", "NOTES_TOKEN"));
|
|
16
|
+
* // => { reason: "secret-not-set", secret: "NOTES_TOKEN" }
|
|
17
|
+
*/
|
|
18
|
+
export function connectorStartFailureOf(value) {
|
|
19
|
+
if (!(value instanceof Error))
|
|
20
|
+
return undefined;
|
|
21
|
+
const { program, secretName } = value;
|
|
22
|
+
if (value.name === "ProgramNotFoundError" && isName(program)) {
|
|
23
|
+
return { reason: "program-missing", program };
|
|
24
|
+
}
|
|
25
|
+
if (value.name === "SecretNotSetError" && isName(secretName)) {
|
|
26
|
+
return { reason: "secret-not-set", secret: secretName };
|
|
27
|
+
}
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
function isName(value) {
|
|
31
|
+
return typeof value === "string" && value !== "";
|
|
32
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A connector's tool that answered, but with an error of its own (MCP's
|
|
3
|
+
* `isError`), such as a file tool that found no file. The server did answer,
|
|
4
|
+
* so the call didn't break off: the engine logs it as a failed call, with the
|
|
5
|
+
* tool's own text, and the agent goes on (requirement
|
|
6
|
+
* `ports.connector-tool-error`). A call that got no answer at all, because
|
|
7
|
+
* the program died, the connection dropped or it ran out of time, throws any
|
|
8
|
+
* other error instead.
|
|
9
|
+
*
|
|
10
|
+
* The message is Halonic's; the tool's own text, which the server wrote, is
|
|
11
|
+
* kept apart in `toolText`, so a reader can fence it as untrusted.
|
|
12
|
+
*
|
|
13
|
+
* Check for it with {@link isConnectorToolError}, not `instanceof`: an
|
|
14
|
+
* adapter may be built against its own copy of this package.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* if (result.isError) throw new ConnectorToolError("handbook-files", "read_text_file", "ENOENT: …");
|
|
18
|
+
*/
|
|
19
|
+
export declare class ConnectorToolError extends Error {
|
|
20
|
+
readonly name = "ConnectorToolError";
|
|
21
|
+
/** What the tool said about its failure: the server's text. */
|
|
22
|
+
readonly toolText: string;
|
|
23
|
+
constructor(connectorId: string, toolName: string, toolText: string);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Whether `value` is a {@link ConnectorToolError}: an `Error` named
|
|
27
|
+
* "ConnectorToolError" with a `toolText` string. It works across copies of
|
|
28
|
+
* this package, where `instanceof` doesn't.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* const outcome = isConnectorToolError(error) ? "error" : "unknown";
|
|
32
|
+
*/
|
|
33
|
+
export declare function isConnectorToolError(value: unknown): value is ConnectorToolError;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A connector's tool that answered, but with an error of its own (MCP's
|
|
3
|
+
* `isError`), such as a file tool that found no file. The server did answer,
|
|
4
|
+
* so the call didn't break off: the engine logs it as a failed call, with the
|
|
5
|
+
* tool's own text, and the agent goes on (requirement
|
|
6
|
+
* `ports.connector-tool-error`). A call that got no answer at all, because
|
|
7
|
+
* the program died, the connection dropped or it ran out of time, throws any
|
|
8
|
+
* other error instead.
|
|
9
|
+
*
|
|
10
|
+
* The message is Halonic's; the tool's own text, which the server wrote, is
|
|
11
|
+
* kept apart in `toolText`, so a reader can fence it as untrusted.
|
|
12
|
+
*
|
|
13
|
+
* Check for it with {@link isConnectorToolError}, not `instanceof`: an
|
|
14
|
+
* adapter may be built against its own copy of this package.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* if (result.isError) throw new ConnectorToolError("handbook-files", "read_text_file", "ENOENT: …");
|
|
18
|
+
*/
|
|
19
|
+
export class ConnectorToolError extends Error {
|
|
20
|
+
name = "ConnectorToolError";
|
|
21
|
+
/** What the tool said about its failure: the server's text. */
|
|
22
|
+
toolText;
|
|
23
|
+
constructor(connectorId, toolName, toolText) {
|
|
24
|
+
super(`Connector "${connectorId}" says its tool "${toolName}" failed.`);
|
|
25
|
+
this.toolText = toolText;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Whether `value` is a {@link ConnectorToolError}: an `Error` named
|
|
30
|
+
* "ConnectorToolError" with a `toolText` string. It works across copies of
|
|
31
|
+
* this package, where `instanceof` doesn't.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* const outcome = isConnectorToolError(error) ? "error" : "unknown";
|
|
35
|
+
*/
|
|
36
|
+
export function isConnectorToolError(value) {
|
|
37
|
+
if (!(value instanceof Error) || value.name !== "ConnectorToolError")
|
|
38
|
+
return false;
|
|
39
|
+
return typeof value.toolText === "string";
|
|
40
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Folders a caller asks a `DefinitionSource` to leave out of `list()`
|
|
3
|
+
* and `version()` (requirement `ports.definition-store-left-out`): the
|
|
4
|
+
* working folders agents write in and `node_modules`, which can hold tens of
|
|
5
|
+
* thousands of files and no definitions. Loading the workspace asks for it;
|
|
6
|
+
* a caller that copies or compares the workspace doesn't.
|
|
7
|
+
*
|
|
8
|
+
* It is about scale, not privacy: a left-out file still reads, writes and
|
|
9
|
+
* removes as any other. Names compare as {@link segmentAsOpened} gives them,
|
|
10
|
+
* as a file system that ignores case would open them.
|
|
11
|
+
*/
|
|
12
|
+
export interface LeaveOut {
|
|
13
|
+
/** Folder paths from the store root, such as `repo` or `files/agents/coder`. Everything under one is left out. */
|
|
14
|
+
readonly folders?: readonly string[];
|
|
15
|
+
/** Folder names left out at any depth, such as `node_modules`. One segment each. */
|
|
16
|
+
readonly names?: readonly string[];
|
|
17
|
+
}
|
|
18
|
+
/** Options for `DefinitionSource.list`. */
|
|
19
|
+
export interface ListOptions {
|
|
20
|
+
/** What to leave out of the listing. Leave it out to list every file, as without options. */
|
|
21
|
+
readonly leaveOut?: LeaveOut;
|
|
22
|
+
}
|
|
23
|
+
/** Options for `DefinitionSource.version`. */
|
|
24
|
+
export interface VersionOptions {
|
|
25
|
+
/** Version only what `list()` gives with the same `leaveOut`. */
|
|
26
|
+
readonly leaveOut?: LeaveOut;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Refuses a {@link LeaveOut} with an unsafe folder path, or a name that isn't
|
|
30
|
+
* a single safe segment, so `a/../b` can't leave out more than it says. Every
|
|
31
|
+
* store calls it before it lists.
|
|
32
|
+
*
|
|
33
|
+
* @throws RangeError naming the folder or name and what is wrong with it
|
|
34
|
+
*/
|
|
35
|
+
export declare function checkLeaveOut(leaveOut: LeaveOut | undefined): void;
|
|
36
|
+
/**
|
|
37
|
+
* Whether a safe workspace path is left out: it is one of the folders, or
|
|
38
|
+
* inside one, or one of its segments is one of the names. A store that walks
|
|
39
|
+
* folders can ask it for a folder's own path and not step into it.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* isLeftOut("repo/src/a.ts", { folders: ["repo"] }); // true
|
|
43
|
+
* isLeftOut("repository.md", { folders: ["repo"] }); // false
|
|
44
|
+
* isLeftOut("tools/Node_Modules/x/index.js", { names: ["node_modules"] }); // true
|
|
45
|
+
*/
|
|
46
|
+
export declare function isLeftOut(path: string, leaveOut: LeaveOut | undefined): boolean;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { checkWorkspacePath, segmentAsOpened } from "./definition-store.js";
|
|
2
|
+
/**
|
|
3
|
+
* Refuses a {@link LeaveOut} with an unsafe folder path, or a name that isn't
|
|
4
|
+
* a single safe segment, so `a/../b` can't leave out more than it says. Every
|
|
5
|
+
* store calls it before it lists.
|
|
6
|
+
*
|
|
7
|
+
* @throws RangeError naming the folder or name and what is wrong with it
|
|
8
|
+
*/
|
|
9
|
+
export function checkLeaveOut(leaveOut) {
|
|
10
|
+
for (const folder of leaveOut?.folders ?? []) {
|
|
11
|
+
checkWorkspacePath(folder);
|
|
12
|
+
}
|
|
13
|
+
for (const name of leaveOut?.names ?? []) {
|
|
14
|
+
checkWorkspacePath(name);
|
|
15
|
+
if (name.includes("/")) {
|
|
16
|
+
throw new RangeError(`Unsafe folder name ${JSON.stringify(name)}: no "/".`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Whether a safe workspace path is left out: it is one of the folders, or
|
|
22
|
+
* inside one, or one of its segments is one of the names. A store that walks
|
|
23
|
+
* folders can ask it for a folder's own path and not step into it.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* isLeftOut("repo/src/a.ts", { folders: ["repo"] }); // true
|
|
27
|
+
* isLeftOut("repository.md", { folders: ["repo"] }); // false
|
|
28
|
+
* isLeftOut("tools/Node_Modules/x/index.js", { names: ["node_modules"] }); // true
|
|
29
|
+
*/
|
|
30
|
+
export function isLeftOut(path, leaveOut) {
|
|
31
|
+
if (leaveOut === undefined) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
const segments = path.split("/").map(segmentAsOpened);
|
|
35
|
+
const names = new Set((leaveOut.names ?? []).map(segmentAsOpened));
|
|
36
|
+
if (segments.some((segment) => names.has(segment))) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
return (leaveOut.folders ?? []).some((folder) => startsWithFolder(segments, folder));
|
|
40
|
+
}
|
|
41
|
+
function startsWithFolder(segments, folder) {
|
|
42
|
+
const folderSegments = folder.split("/").map(segmentAsOpened);
|
|
43
|
+
if (folderSegments.length > segments.length) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
return folderSegments.every((segment, index) => segments[index] === segment);
|
|
47
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { ListOptions, VersionOptions } from "./definition-store-left-out.js";
|
|
1
2
|
/** Version of the {@link DefinitionStore} and {@link DefinitionSource} ports. A breaking change bumps it and comes with an ADR. */
|
|
2
|
-
export declare const definitionStoreVersion =
|
|
3
|
+
export declare const definitionStoreVersion = 3;
|
|
3
4
|
/**
|
|
4
5
|
* Read access to the workspace files (agents, workflows, hubs …), wherever
|
|
5
6
|
* they live: a folder, git, memory or a deployed snapshot. Paths are
|
|
@@ -45,15 +46,24 @@ export interface DefinitionSource {
|
|
|
45
46
|
* gives `[]`. A folder under the root that the account may not read
|
|
46
47
|
* throws an `UnreadableWorkspaceFolderError` naming it, rather than being
|
|
47
48
|
* left out.
|
|
49
|
+
*
|
|
50
|
+
* With `options.leaveOut`, it also leaves out the folders and folder
|
|
51
|
+
* names it gives (see `LeaveOut`), and a store that walks folders doesn't
|
|
52
|
+
* step into them. It refuses an unsafe folder or name with a `RangeError`.
|
|
48
53
|
*/
|
|
49
|
-
list(dir?: string): Promise<string[]>;
|
|
54
|
+
list(dir?: string, options?: ListOptions): Promise<string[]>;
|
|
50
55
|
/** The file's text, or `null` when there is no such file. */
|
|
51
56
|
read(path: string): Promise<string | null>;
|
|
52
57
|
/**
|
|
53
58
|
* Identifier of the current version of the definitions (git commit, content
|
|
54
59
|
* hash). Runs record it so they can be explained and replayed later.
|
|
60
|
+
*
|
|
61
|
+
* With `options.leaveOut`, it covers only what `list()` gives with the
|
|
62
|
+
* same options, so a change to a left-out file alone doesn't change it. A
|
|
63
|
+
* store whose version names a whole snapshot (a commit) keeps naming it:
|
|
64
|
+
* any change makes a new snapshot.
|
|
55
65
|
*/
|
|
56
|
-
version(): Promise<string>;
|
|
66
|
+
version(options?: VersionOptions): Promise<string>;
|
|
57
67
|
}
|
|
58
68
|
/**
|
|
59
69
|
* What a caller expects a file to hold before it writes: the digest of the
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Version of the {@link DefinitionStore} and {@link DefinitionSource} ports. A breaking change bumps it and comes with an ADR. */
|
|
2
|
-
export const definitionStoreVersion =
|
|
2
|
+
export const definitionStoreVersion = 3;
|
|
3
3
|
/**
|
|
4
4
|
* What a {@link DefinitionSource}'s `list()` throws when the account may not
|
|
5
5
|
* read a folder under the store's root (requirement
|