@garygentry/system1-core 0.1.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/LICENSE +21 -0
- package/README.md +13 -0
- package/dist/config/consent.d.ts +11 -0
- package/dist/config/consent.d.ts.map +1 -0
- package/dist/config/consent.js +33 -0
- package/dist/config/consent.js.map +1 -0
- package/dist/config/load.d.ts +64 -0
- package/dist/config/load.d.ts.map +1 -0
- package/dist/config/load.js +216 -0
- package/dist/config/load.js.map +1 -0
- package/dist/config/session.d.ts +31 -0
- package/dist/config/session.d.ts.map +1 -0
- package/dist/config/session.js +36 -0
- package/dist/config/session.js.map +1 -0
- package/dist/config.d.ts +28 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +64 -0
- package/dist/config.js.map +1 -0
- package/dist/decide.d.ts +57 -0
- package/dist/decide.d.ts.map +1 -0
- package/dist/decide.js +87 -0
- package/dist/decide.js.map +1 -0
- package/dist/egress/exclude.d.ts +24 -0
- package/dist/egress/exclude.d.ts.map +1 -0
- package/dist/egress/exclude.js +60 -0
- package/dist/egress/exclude.js.map +1 -0
- package/dist/egress/scrub.d.ts +12 -0
- package/dist/egress/scrub.d.ts.map +1 -0
- package/dist/egress/scrub.js +84 -0
- package/dist/egress/scrub.js.map +1 -0
- package/dist/egress/size.d.ts +16 -0
- package/dist/egress/size.d.ts.map +1 -0
- package/dist/egress/size.js +25 -0
- package/dist/egress/size.js.map +1 -0
- package/dist/errors.d.ts +44 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +23 -0
- package/dist/errors.js.map +1 -0
- package/dist/fixtures/store.d.ts +34 -0
- package/dist/fixtures/store.d.ts.map +1 -0
- package/dist/fixtures/store.js +74 -0
- package/dist/fixtures/store.js.map +1 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/model/answers.d.ts +38 -0
- package/dist/model/answers.d.ts.map +1 -0
- package/dist/model/answers.js +48 -0
- package/dist/model/answers.js.map +1 -0
- package/dist/model/profiles.d.ts +39 -0
- package/dist/model/profiles.d.ts.map +1 -0
- package/dist/model/profiles.js +42 -0
- package/dist/model/profiles.js.map +1 -0
- package/dist/model/types.d.ts +107 -0
- package/dist/model/types.d.ts.map +1 -0
- package/dist/model/types.js +17 -0
- package/dist/model/types.js.map +1 -0
- package/dist/model/validate.d.ts +17 -0
- package/dist/model/validate.d.ts.map +1 -0
- package/dist/model/validate.js +151 -0
- package/dist/model/validate.js.map +1 -0
- package/dist/ping.d.ts +30 -0
- package/dist/ping.d.ts.map +1 -0
- package/dist/ping.js +50 -0
- package/dist/ping.js.map +1 -0
- package/dist/prepare.d.ts +39 -0
- package/dist/prepare.d.ts.map +1 -0
- package/dist/prepare.js +84 -0
- package/dist/prepare.js.map +1 -0
- package/dist/project/project.d.ts +64 -0
- package/dist/project/project.d.ts.map +1 -0
- package/dist/project/project.js +144 -0
- package/dist/project/project.js.map +1 -0
- package/dist/run/budget.d.ts +20 -0
- package/dist/run/budget.d.ts.map +1 -0
- package/dist/run/budget.js +31 -0
- package/dist/run/budget.js.map +1 -0
- package/dist/run/pool.d.ts +16 -0
- package/dist/run/pool.d.ts.map +1 -0
- package/dist/run/pool.js +35 -0
- package/dist/run/pool.js.map +1 -0
- package/dist/run/spend.d.ts +34 -0
- package/dist/run/spend.d.ts.map +1 -0
- package/dist/run/spend.js +55 -0
- package/dist/run/spend.js.map +1 -0
- package/dist/sources/read.d.ts +40 -0
- package/dist/sources/read.d.ts.map +1 -0
- package/dist/sources/read.js +294 -0
- package/dist/sources/read.js.map +1 -0
- package/dist/sources/types.d.ts +79 -0
- package/dist/sources/types.d.ts.map +1 -0
- package/dist/sources/types.js +2 -0
- package/dist/sources/types.js.map +1 -0
- package/dist/spec/expect.d.ts +39 -0
- package/dist/spec/expect.d.ts.map +1 -0
- package/dist/spec/expect.js +95 -0
- package/dist/spec/expect.js.map +1 -0
- package/dist/spec/spec.d.ts +90 -0
- package/dist/spec/spec.d.ts.map +1 -0
- package/dist/spec/spec.js +252 -0
- package/dist/spec/spec.js.map +1 -0
- package/dist/split/split.d.ts +33 -0
- package/dist/split/split.d.ts.map +1 -0
- package/dist/split/split.js +116 -0
- package/dist/split/split.js.map +1 -0
- package/dist/testdata/index.d.ts +5 -0
- package/dist/testdata/index.d.ts.map +1 -0
- package/dist/testdata/index.js +6 -0
- package/dist/testdata/index.js.map +1 -0
- package/dist/testkit/fake-model.d.ts +14 -0
- package/dist/testkit/fake-model.d.ts.map +1 -0
- package/dist/testkit/fake-model.js +57 -0
- package/dist/testkit/fake-model.js.map +1 -0
- package/dist/testkit/tmp.d.ts +6 -0
- package/dist/testkit/tmp.d.ts.map +1 -0
- package/dist/testkit/tmp.js +46 -0
- package/dist/testkit/tmp.js.map +1 -0
- package/dist/tools/ask.d.ts +32 -0
- package/dist/tools/ask.d.ts.map +1 -0
- package/dist/tools/ask.js +59 -0
- package/dist/tools/ask.js.map +1 -0
- package/dist/tools/context.d.ts +52 -0
- package/dist/tools/context.d.ts.map +1 -0
- package/dist/tools/context.js +130 -0
- package/dist/tools/context.js.map +1 -0
- package/dist/tools/doctor.d.ts +37 -0
- package/dist/tools/doctor.d.ts.map +1 -0
- package/dist/tools/doctor.js +203 -0
- package/dist/tools/doctor.js.map +1 -0
- package/dist/tools/many.d.ts +74 -0
- package/dist/tools/many.d.ts.map +1 -0
- package/dist/tools/many.js +141 -0
- package/dist/tools/many.js.map +1 -0
- package/dist/tools/schemas.d.ts +293 -0
- package/dist/tools/schemas.d.ts.map +1 -0
- package/dist/tools/schemas.js +112 -0
- package/dist/tools/schemas.js.map +1 -0
- package/dist/tools/spec-check.d.ts +48 -0
- package/dist/tools/spec-check.d.ts.map +1 -0
- package/dist/tools/spec-check.js +164 -0
- package/dist/tools/spec-check.js.map +1 -0
- package/dist/tools/usage.d.ts +11 -0
- package/dist/tools/usage.d.ts.map +1 -0
- package/dist/tools/usage.js +27 -0
- package/dist/tools/usage.js.map +1 -0
- package/dist/transport/openrouter.d.ts +38 -0
- package/dist/transport/openrouter.d.ts.map +1 -0
- package/dist/transport/openrouter.js +89 -0
- package/dist/transport/openrouter.js.map +1 -0
- package/dist/version.d.ts +4 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +5 -0
- package/dist/version.js.map +1 -0
- package/dist/wiring.d.ts +30 -0
- package/dist/wiring.d.ts.map +1 -0
- package/dist/wiring.js +31 -0
- package/dist/wiring.js.map +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
2
|
+
import { basename, extname, isAbsolute, join, relative, resolve } from "node:path";
|
|
3
|
+
import { Type } from "typebox";
|
|
4
|
+
import { Value } from "typebox/value";
|
|
5
|
+
import { parse } from "yaml";
|
|
6
|
+
import { DecisionsError } from "../errors.js";
|
|
7
|
+
import { assertQuestionSet } from "../model/validate.js";
|
|
8
|
+
import { parseFilter, parseSort } from "../project/project.js";
|
|
9
|
+
import { parseFileRef } from "../sources/read.js";
|
|
10
|
+
import { parseSplit } from "../split/split.js";
|
|
11
|
+
import { parseExpect } from "./expect.js";
|
|
12
|
+
/**
|
|
13
|
+
* The question spec: the plugin's one durable file format. It holds a question
|
|
14
|
+
* set together with the policy that reads its answers, so thresholds live in a
|
|
15
|
+
* versioned, testable file rather than in anyone's head (charter principle 3).
|
|
16
|
+
*/
|
|
17
|
+
const Threshold = Type.Object({ value: Type.Number(), why: Type.String({ minLength: 1 }) });
|
|
18
|
+
export const SPEC_FORMAT = 1;
|
|
19
|
+
export const SpecSchema = Type.Object({
|
|
20
|
+
/** Spec file format. Absent means 1; a newer one is refused, not guessed. */
|
|
21
|
+
version: Type.Optional(Type.Integer({ minimum: 1 })),
|
|
22
|
+
description: Type.String({ minLength: 1 }),
|
|
23
|
+
questions: Type.Record(Type.String(), Type.Unknown()),
|
|
24
|
+
keep: Type.Optional(Type.Array(Type.String())),
|
|
25
|
+
sort: Type.Optional(Type.String()),
|
|
26
|
+
policy: Type.Optional(Type.Object({ thresholds: Type.Optional(Type.Record(Type.String(), Threshold)) })),
|
|
27
|
+
source: Type.Optional(Type.Object({
|
|
28
|
+
glob: Type.Optional(Type.Array(Type.String())),
|
|
29
|
+
file: Type.Optional(Type.String()),
|
|
30
|
+
jsonl: Type.Optional(Type.String()),
|
|
31
|
+
diff: Type.Optional(Type.String()),
|
|
32
|
+
split: Type.Optional(Type.String()),
|
|
33
|
+
})),
|
|
34
|
+
examples: Type.Optional(Type.Array(Type.Object({
|
|
35
|
+
id: Type.String({ minLength: 1 }),
|
|
36
|
+
/** The text (or a JSON value, sent as its JSON text) to judge. Give this or `file`. */
|
|
37
|
+
state: Type.Optional(Type.Unknown()),
|
|
38
|
+
/** A repo file to judge, `path` or `path:START-END`. Give this or `state`. */
|
|
39
|
+
file: Type.Optional(Type.String()),
|
|
40
|
+
expect: Type.Optional(Type.Record(Type.String(), Type.Unknown())),
|
|
41
|
+
}))),
|
|
42
|
+
provenance: Type.Optional(Type.Record(Type.String(), Type.Unknown())),
|
|
43
|
+
/** Anything else a team wants to carry, ignored by the engine. */
|
|
44
|
+
meta: Type.Optional(Type.Record(Type.String(), Type.Unknown())),
|
|
45
|
+
},
|
|
46
|
+
// A misspelled key (`kepe:`, `exepct:`) must fail rather than silently
|
|
47
|
+
// becoming no policy at all.
|
|
48
|
+
{ additionalProperties: false });
|
|
49
|
+
const NAME = /^[a-z0-9][a-z0-9._-]*$/;
|
|
50
|
+
/** Parse and validate spec text. Collects every problem before failing. */
|
|
51
|
+
export function parseSpec(text, file, origin) {
|
|
52
|
+
let raw;
|
|
53
|
+
try {
|
|
54
|
+
raw = parse(text);
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
throw new DecisionsError("invalid-request", `${file}: not valid YAML: ${String(error)}`, {
|
|
58
|
+
file,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
const problems = [...Value.Errors(SpecSchema, raw)].map((e) => `${e.instancePath || "/"} ${e.message}`);
|
|
62
|
+
if (problems.length > 0) {
|
|
63
|
+
throw new DecisionsError("invalid-request", `${file}: invalid spec:\n ${problems.join("\n ")}`, { file, problems });
|
|
64
|
+
}
|
|
65
|
+
const spec = raw;
|
|
66
|
+
if ((spec.version ?? SPEC_FORMAT) > SPEC_FORMAT) {
|
|
67
|
+
throw new DecisionsError("invalid-request", `${file}: spec format version ${spec.version} is newer than this CLI understands (${SPEC_FORMAT}). Upgrade @garygentry/system1.`, { file, version: spec.version });
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
assertQuestionSet(spec.questions);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
throw new DecisionsError("invalid-request", `${file}: ${error.message}`, { file });
|
|
74
|
+
}
|
|
75
|
+
const questions = spec.questions;
|
|
76
|
+
for (const text of spec.keep ?? [])
|
|
77
|
+
wrap(file, () => parseFilter(text, questions));
|
|
78
|
+
if (spec.sort)
|
|
79
|
+
wrap(file, () => parseSort(spec.sort, questions));
|
|
80
|
+
if (spec.source?.split)
|
|
81
|
+
wrap(file, () => parseSplit(spec.source?.split));
|
|
82
|
+
const name = basename(file, extname(file));
|
|
83
|
+
if (!NAME.test(name)) {
|
|
84
|
+
throw new DecisionsError("invalid-request", `${file}: spec names must be lowercase letters, digits, . _ -`, { file });
|
|
85
|
+
}
|
|
86
|
+
return { ...spec, questions, name, file, origin };
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Problems with a spec's examples. Checked by `spec validate` and `spec check`
|
|
90
|
+
* only, so a bad example never stops `ask` or `many` from using the spec.
|
|
91
|
+
* With `repoRoot`, each example `file` must also exist inside the repo.
|
|
92
|
+
*/
|
|
93
|
+
export function exampleProblems(spec, repoRoot) {
|
|
94
|
+
const problems = [];
|
|
95
|
+
const ids = new Set();
|
|
96
|
+
for (const [i, example] of (spec.examples ?? []).entries()) {
|
|
97
|
+
const where = `examples[${i}] (${example.id})`;
|
|
98
|
+
if (ids.has(example.id))
|
|
99
|
+
problems.push(`${where}: duplicate id`);
|
|
100
|
+
ids.add(example.id);
|
|
101
|
+
if ((example.state === undefined) === (example.file === undefined)) {
|
|
102
|
+
problems.push(`${where}: give exactly one of state or file`);
|
|
103
|
+
}
|
|
104
|
+
if (example.expect) {
|
|
105
|
+
try {
|
|
106
|
+
parseExpect(example.expect, spec.questions, where);
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
problems.push(error.message);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (example.file !== undefined && repoRoot) {
|
|
113
|
+
const why = exampleFileProblem(example.file, repoRoot);
|
|
114
|
+
if (why)
|
|
115
|
+
problems.push(`${where}: file ${example.file} ${why}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return problems;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Why an example's `file` can't be used, or undefined. Only files inside the
|
|
122
|
+
* repo: a committed spec must not be able to read (and send) anything else.
|
|
123
|
+
*/
|
|
124
|
+
export function exampleFileProblem(ref, repoRoot) {
|
|
125
|
+
const { path } = parseFileRef(ref);
|
|
126
|
+
const full = resolve(repoRoot, path);
|
|
127
|
+
const rel = relative(repoRoot, full);
|
|
128
|
+
if (isAbsolute(path) || rel.startsWith("..") || isAbsolute(rel))
|
|
129
|
+
return "is outside the repo";
|
|
130
|
+
if (!existsSync(full))
|
|
131
|
+
return "does not exist";
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
134
|
+
/** @throws DecisionsError `invalid-request` listing every example problem. */
|
|
135
|
+
export function assertExamples(spec, repoRoot) {
|
|
136
|
+
const problems = exampleProblems(spec, repoRoot);
|
|
137
|
+
if (problems.length > 0) {
|
|
138
|
+
throw new DecisionsError("invalid-request", `${spec.file}: invalid examples:\n ${problems.join("\n ")}`, { file: spec.file, problems });
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Parse a question set given on its own (`--questions`): YAML or JSON, in the
|
|
143
|
+
* same shape as a spec's `questions:`.
|
|
144
|
+
*/
|
|
145
|
+
export function parseQuestionSet(text, from) {
|
|
146
|
+
let raw;
|
|
147
|
+
try {
|
|
148
|
+
raw = parse(text);
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
throw new DecisionsError("invalid-request", `${from}: not valid YAML or JSON: ${String(error)}`);
|
|
152
|
+
}
|
|
153
|
+
// Accept a whole spec-shaped document too, so a spec's file can be reused as-is.
|
|
154
|
+
const questions = raw &&
|
|
155
|
+
typeof raw === "object" &&
|
|
156
|
+
"questions" in raw &&
|
|
157
|
+
!isQuestion(raw.questions)
|
|
158
|
+
? raw.questions
|
|
159
|
+
: raw;
|
|
160
|
+
try {
|
|
161
|
+
assertQuestionSet(questions);
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
throw new DecisionsError("invalid-request", `${from}: ${error.message}`);
|
|
165
|
+
}
|
|
166
|
+
return questions;
|
|
167
|
+
}
|
|
168
|
+
function isQuestion(value) {
|
|
169
|
+
return !!value && typeof value === "object" && "type" in value && "instructions" in value;
|
|
170
|
+
}
|
|
171
|
+
/** The default spec directories for a repo. */
|
|
172
|
+
export function specDirs(repoRoot, userConfigDir, bundled) {
|
|
173
|
+
return {
|
|
174
|
+
repo: join(repoRoot, ".system1", "specs"),
|
|
175
|
+
user: join(userConfigDir, "specs"),
|
|
176
|
+
...(bundled ? { bundled } : {}),
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Resolve a spec by name (repo → user → bundled) or by path.
|
|
181
|
+
*
|
|
182
|
+
* @throws DecisionsError `invalid-request` when nothing matches, listing what exists.
|
|
183
|
+
*/
|
|
184
|
+
export function loadSpec(ref, dirs, cwd) {
|
|
185
|
+
if (ref.includes("/") || ref.endsWith(".yaml") || ref.endsWith(".yml") || ref.endsWith(".json")) {
|
|
186
|
+
const file = isAbsolute(ref) ? ref : resolve(cwd, ref);
|
|
187
|
+
if (!existsSync(file))
|
|
188
|
+
throw new DecisionsError("invalid-request", `No spec file at ${ref}`);
|
|
189
|
+
return parseSpec(readFileSync(file, "utf8"), file, "path");
|
|
190
|
+
}
|
|
191
|
+
for (const [origin, dir] of layers(dirs)) {
|
|
192
|
+
for (const ext of [".yaml", ".yml", ".json"]) {
|
|
193
|
+
const file = join(dir, `${ref}${ext}`);
|
|
194
|
+
if (existsSync(file))
|
|
195
|
+
return parseSpec(readFileSync(file, "utf8"), file, origin);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
const known = listSpecs(dirs).map((s) => s.name);
|
|
199
|
+
throw new DecisionsError("invalid-request", `No spec named "${ref}". ${known.length ? `Available: ${known.join(", ")}.` : "No specs found."}`, { known });
|
|
200
|
+
}
|
|
201
|
+
export function listSpecs(dirs) {
|
|
202
|
+
const seen = new Set();
|
|
203
|
+
const out = [];
|
|
204
|
+
for (const [origin, dir] of layers(dirs)) {
|
|
205
|
+
if (!existsSync(dir))
|
|
206
|
+
continue;
|
|
207
|
+
for (const entry of readdirSync(dir).sort()) {
|
|
208
|
+
if (!/\.(ya?ml|json)$/.test(entry))
|
|
209
|
+
continue;
|
|
210
|
+
const file = join(dir, entry);
|
|
211
|
+
const name = basename(entry, extname(entry));
|
|
212
|
+
const shadowed = seen.has(name);
|
|
213
|
+
seen.add(name);
|
|
214
|
+
try {
|
|
215
|
+
const spec = parseSpec(readFileSync(file, "utf8"), file, origin);
|
|
216
|
+
out.push({
|
|
217
|
+
name,
|
|
218
|
+
origin,
|
|
219
|
+
file,
|
|
220
|
+
description: spec.description,
|
|
221
|
+
...(shadowed ? { shadowed } : {}),
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
catch (error) {
|
|
225
|
+
out.push({
|
|
226
|
+
name,
|
|
227
|
+
origin,
|
|
228
|
+
file,
|
|
229
|
+
error: error.message,
|
|
230
|
+
...(shadowed ? { shadowed } : {}),
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return out;
|
|
236
|
+
}
|
|
237
|
+
function layers(dirs) {
|
|
238
|
+
return [
|
|
239
|
+
["repo", dirs.repo],
|
|
240
|
+
["user", dirs.user],
|
|
241
|
+
...(dirs.bundled ? [["bundled", dirs.bundled]] : []),
|
|
242
|
+
];
|
|
243
|
+
}
|
|
244
|
+
function wrap(file, fn) {
|
|
245
|
+
try {
|
|
246
|
+
fn();
|
|
247
|
+
}
|
|
248
|
+
catch (error) {
|
|
249
|
+
throw new DecisionsError("invalid-request", `${file}: ${error.message}`, { file });
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
//# sourceMappingURL=spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spec.js","sourceRoot":"","sources":["../../src/spec/spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAC/D,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAClF,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAA;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAA;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAE7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEzC;;;;GAIG;AACH,MAAM,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E,CAAC;KAC1F,CAAA;AACH,CAAC;AAED,SAAS,IAAI,CAAC,IAAY,EAAE,EAAiB;IAC3C,IAAI,CAAC;QACH,EAAE,EAAE,CAAA;IACN,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,cAAc,CAAC,iBAAiB,EAAE,GAAG,IAAI,KAAM,KAAe,CAAC,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAA;IAC/F,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Document, Item } from "../sources/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* How documents become items: one item = one state = one decision call.
|
|
4
|
+
*
|
|
5
|
+
* - `file`: each document whole.
|
|
6
|
+
* - `hunk`: each `@@` hunk of a diff document, with its file header for context.
|
|
7
|
+
* - `lines`: windows of `size` lines, overlapping by `overlap`.
|
|
8
|
+
* - `row`: JSONL rows as-is; for text, each non-empty line.
|
|
9
|
+
*/
|
|
10
|
+
export type SplitSpec = {
|
|
11
|
+
kind: "file";
|
|
12
|
+
} | {
|
|
13
|
+
kind: "hunk";
|
|
14
|
+
} | {
|
|
15
|
+
kind: "lines";
|
|
16
|
+
size: number;
|
|
17
|
+
overlap: number;
|
|
18
|
+
} | {
|
|
19
|
+
kind: "row";
|
|
20
|
+
}
|
|
21
|
+
/** Every source as one state, joined after excludes (see `prepare`). */
|
|
22
|
+
| {
|
|
23
|
+
kind: "join";
|
|
24
|
+
};
|
|
25
|
+
/** Parse `file`, `hunk`, `row`, `join`, `lines:40` or `lines:40/10`. */
|
|
26
|
+
export declare function parseSplit(text: string): SplitSpec;
|
|
27
|
+
export declare function split(documents: readonly Document[], spec: SplitSpec): Item[];
|
|
28
|
+
/**
|
|
29
|
+
* One item from many, each part headed by its id. Used by `join` after
|
|
30
|
+
* excludes have run, so a secret-shaped file is never folded in.
|
|
31
|
+
*/
|
|
32
|
+
export declare function joinItems(items: readonly Item[]): Item[];
|
|
33
|
+
//# sourceMappingURL=split.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"split.d.ts","sourceRoot":"","sources":["../../src/split/split.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAA;AAEzD;;;;;;;GAOG;AACH,MAAM,MAAM,SAAS,GACjB;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAChB;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAChB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAChD;IAAE,IAAI,EAAE,KAAK,CAAA;CAAE;AACjB,wEAAwE;GACtE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAA;AAEpB,wEAAwE;AACxE,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAkBlD;AAED,wBAAgB,KAAK,CAAC,SAAS,EAAE,SAAS,QAAQ,EAAE,EAAE,IAAI,EAAE,SAAS,GAAG,IAAI,EAAE,CAI7E;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,GAAG,IAAI,EAAE,CAQxD"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { DecisionsError } from "../errors.js";
|
|
2
|
+
/** Parse `file`, `hunk`, `row`, `join`, `lines:40` or `lines:40/10`. */
|
|
3
|
+
export function parseSplit(text) {
|
|
4
|
+
if (text === "file" || text === "hunk" || text === "row" || text === "join")
|
|
5
|
+
return { kind: text };
|
|
6
|
+
const match = /^lines:(\d+)(?:\/(\d+))?$/.exec(text);
|
|
7
|
+
if (match) {
|
|
8
|
+
const size = Number(match[1]);
|
|
9
|
+
const overlap = Number(match[2] ?? 0);
|
|
10
|
+
if (size < 1 || overlap >= size) {
|
|
11
|
+
throw new DecisionsError("invalid-request", `Invalid split "${text}": need size ≥ 1 and overlap < size`);
|
|
12
|
+
}
|
|
13
|
+
return { kind: "lines", size, overlap };
|
|
14
|
+
}
|
|
15
|
+
throw new DecisionsError("invalid-request", `Unknown split "${text}" (file, hunk, row, join, lines:N[/overlap])`);
|
|
16
|
+
}
|
|
17
|
+
export function split(documents, spec) {
|
|
18
|
+
// `join` splits by file first, so excludes still see each file on its own.
|
|
19
|
+
const each = spec.kind === "join" ? { kind: "file" } : spec;
|
|
20
|
+
return documents.flatMap((doc) => splitOne(doc, each));
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* One item from many, each part headed by its id. Used by `join` after
|
|
24
|
+
* excludes have run, so a secret-shaped file is never folded in.
|
|
25
|
+
*/
|
|
26
|
+
export function joinItems(items) {
|
|
27
|
+
if (items.length <= 1)
|
|
28
|
+
return [...items];
|
|
29
|
+
const text = items
|
|
30
|
+
.map((i) => `--- ${i.id} ---\n${typeof i.state === "string" ? i.state : JSON.stringify(i.state)}`)
|
|
31
|
+
.join("\n\n");
|
|
32
|
+
return [{ id: `joined(${items.length})`, state: text }];
|
|
33
|
+
}
|
|
34
|
+
function splitOne(doc, spec) {
|
|
35
|
+
if (doc.kind === "row")
|
|
36
|
+
return [rowItem(doc)];
|
|
37
|
+
const text = doc.text ?? "";
|
|
38
|
+
const start = doc.startLine ?? 1;
|
|
39
|
+
switch (spec.kind) {
|
|
40
|
+
case "file":
|
|
41
|
+
case "join":
|
|
42
|
+
case "row":
|
|
43
|
+
if (spec.kind === "file" || spec.kind === "join")
|
|
44
|
+
return [base(doc, doc.id, text, doc.kind === "file" ? span(start, text) : undefined)];
|
|
45
|
+
return text
|
|
46
|
+
.split("\n")
|
|
47
|
+
.map((line, i) => ({ line, n: start + i }))
|
|
48
|
+
.filter(({ line }) => line.trim() !== "")
|
|
49
|
+
.map(({ line, n }) => base(doc, `${idRoot(doc)}:${n}`, line, { start: n, end: n }));
|
|
50
|
+
case "lines": {
|
|
51
|
+
const lines = text.split("\n");
|
|
52
|
+
const step = spec.size - spec.overlap;
|
|
53
|
+
const items = [];
|
|
54
|
+
for (let i = 0; i < lines.length; i += step) {
|
|
55
|
+
const chunk = lines.slice(i, i + spec.size);
|
|
56
|
+
const from = start + i;
|
|
57
|
+
const to = from + chunk.length - 1;
|
|
58
|
+
items.push(base(doc, `${idRoot(doc)}:${from}-${to}`, chunk.join("\n"), { start: from, end: to }));
|
|
59
|
+
if (i + spec.size >= lines.length)
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
return items;
|
|
63
|
+
}
|
|
64
|
+
case "hunk":
|
|
65
|
+
if (doc.kind !== "diff") {
|
|
66
|
+
throw new DecisionsError("invalid-request", `split "hunk" needs a diff source, but ${doc.id} is not a diff`);
|
|
67
|
+
}
|
|
68
|
+
return hunks(doc);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function hunks(doc) {
|
|
72
|
+
const text = doc.text ?? "";
|
|
73
|
+
const headerEnd = text.search(/^@@ /m);
|
|
74
|
+
if (headerEnd < 0)
|
|
75
|
+
return [base(doc, `${doc.path}#h0`, text)]; // binary or mode-only change
|
|
76
|
+
const header = text
|
|
77
|
+
.slice(0, headerEnd)
|
|
78
|
+
.split("\n")
|
|
79
|
+
.filter((l) => l.startsWith("--- ") || l.startsWith("+++ "))
|
|
80
|
+
.join("\n");
|
|
81
|
+
return text
|
|
82
|
+
.slice(headerEnd)
|
|
83
|
+
.split(/^(?=@@ )/m)
|
|
84
|
+
.map((hunk, i) => {
|
|
85
|
+
const m = /^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@/.exec(hunk);
|
|
86
|
+
const from = Number(m?.[1] ?? 0);
|
|
87
|
+
const count = Number(m?.[2] ?? 1);
|
|
88
|
+
const lines = count > 0 ? { start: from, end: from + count - 1 } : undefined;
|
|
89
|
+
return base(doc, `${doc.path}#h${i + 1}`, `${header}\n${hunk.replace(/\n$/, "")}`, lines);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
function rowItem(doc) {
|
|
93
|
+
return {
|
|
94
|
+
id: doc.id,
|
|
95
|
+
state: doc.data,
|
|
96
|
+
...(doc.path ? { path: doc.path } : {}),
|
|
97
|
+
...(doc.startLine ? { lines: { start: doc.startLine, end: doc.startLine } } : {}),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function base(doc, id, text, lines) {
|
|
101
|
+
return {
|
|
102
|
+
id,
|
|
103
|
+
state: text,
|
|
104
|
+
...(doc.path ? { path: doc.path } : {}),
|
|
105
|
+
...(doc.realPath ? { realPath: doc.realPath } : {}),
|
|
106
|
+
...(lines ? { lines } : {}),
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function span(start, text) {
|
|
110
|
+
return { start, end: start + text.split("\n").length - 1 };
|
|
111
|
+
}
|
|
112
|
+
/** A document id without any line suffix, so window ids read `path:10-49`. */
|
|
113
|
+
function idRoot(doc) {
|
|
114
|
+
return doc.path ?? doc.id;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=split.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"split.js","sourceRoot":"","sources":["../../src/split/split.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAmB7C,wEAAwE;AACxE,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,IAAI,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,MAAM;QAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAA;IAClG,MAAM,KAAK,GAAG,2BAA2B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACpD,IAAI,KAAK,EAAE,CAAC;QACV,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;QAC7B,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CA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from "../model/types.js";
|
|
2
|
+
/** A real recorded Jev response and the question set it answered. */
|
|
3
|
+
export declare const guardrailQuestions: () => QuestionSet;
|
|
4
|
+
export declare const guardrailResponse: () => Record<string, unknown>;
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testdata/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAIpD,qEAAqE;AACrE,eAAO,MAAM,kBAAkB,QAAO,WAAiD,CAAA;AACvF,eAAO,MAAM,iBAAiB,QAAO,MAAM,CAAC,MAAM,EAAE,OAAO,CAAyC,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
const read = (name) => JSON.parse(readFileSync(new URL(name, import.meta.url), "utf8"));
|
|
3
|
+
/** A real recorded Jev response and the question set it answered. */
|
|
4
|
+
export const guardrailQuestions = () => read("./guardrail.questions.json");
|
|
5
|
+
export const guardrailResponse = () => read("./guardrail-ls.response.json");
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testdata/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAGtC,MAAM,IAAI,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,GAAG,CAAC,IAAI,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC,CAAA;AAE/F,qEAAqE;AACrE,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAgB,EAAE,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAA;AACvF,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAA4B,EAAE,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A stand-in decisions endpoint for tool tests: deterministic answers derived
|
|
3
|
+
* from the state's text, so tests can steer outcomes.
|
|
4
|
+
*
|
|
5
|
+
* - a state mentioning "auth" gets noul 0.95 (and the first choice option);
|
|
6
|
+
* - "maybe" gets noul 0.5 and a flat choice (undecided);
|
|
7
|
+
* - "explode" makes the endpoint answer HTTP 400;
|
|
8
|
+
* - anything else gets noul 0.05 (and the last choice option).
|
|
9
|
+
*/
|
|
10
|
+
export declare function fakeDecisionsFetch(): {
|
|
11
|
+
fetch: typeof fetch;
|
|
12
|
+
calls: number;
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=fake-model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fake-model.d.ts","sourceRoot":"","sources":["../../src/testkit/fake-model.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,IAAI;IAAE,KAAK,EAAE,OAAO,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CA8C3E"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A stand-in decisions endpoint for tool tests: deterministic answers derived
|
|
3
|
+
* from the state's text, so tests can steer outcomes.
|
|
4
|
+
*
|
|
5
|
+
* - a state mentioning "auth" gets noul 0.95 (and the first choice option);
|
|
6
|
+
* - "maybe" gets noul 0.5 and a flat choice (undecided);
|
|
7
|
+
* - "explode" makes the endpoint answer HTTP 400;
|
|
8
|
+
* - anything else gets noul 0.05 (and the last choice option).
|
|
9
|
+
*/
|
|
10
|
+
export function fakeDecisionsFetch() {
|
|
11
|
+
const counter = { calls: 0 };
|
|
12
|
+
const fetchImpl = (async (_url, init) => {
|
|
13
|
+
counter.calls += 1;
|
|
14
|
+
const body = JSON.parse(String(init.body));
|
|
15
|
+
const text = typeof body.state === "string" ? body.state : JSON.stringify(body.state);
|
|
16
|
+
if (text.includes("explode"))
|
|
17
|
+
return new Response("bad request", { status: 400 });
|
|
18
|
+
const answers = {};
|
|
19
|
+
for (const [name, q] of Object.entries(body.questions)) {
|
|
20
|
+
const hot = text.includes("auth");
|
|
21
|
+
const flat = text.includes("maybe");
|
|
22
|
+
if (q.type === "noul")
|
|
23
|
+
answers[name] = { type: "noul", noul: flat ? 0.5 : hot ? 0.95 : 0.05 };
|
|
24
|
+
if (q.type === "choice") {
|
|
25
|
+
const keys = Object.keys(q.criteria);
|
|
26
|
+
const pick = (hot ? keys[0] : keys[keys.length - 1]);
|
|
27
|
+
answers[name] = {
|
|
28
|
+
type: "choice",
|
|
29
|
+
choice: pick,
|
|
30
|
+
probabilities: Object.fromEntries(keys.map((k) => [k, flat ? 1 / keys.length : k === pick ? 1 : 0])),
|
|
31
|
+
confidence: flat ? 0 : 1,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
if (q.type === "score") {
|
|
35
|
+
const top = q.criteria.length - 1;
|
|
36
|
+
answers[name] = {
|
|
37
|
+
type: "score",
|
|
38
|
+
score: hot ? top : 0,
|
|
39
|
+
probabilities: { "0": 1 },
|
|
40
|
+
confidence: flat ? 0.05 : 0.9,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return Response.json({
|
|
45
|
+
model: "typesafe/jev-1.13-20260917",
|
|
46
|
+
answers,
|
|
47
|
+
usage: { input_tokens: 100, output_tokens: 10, cost: 0.000004 },
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
return {
|
|
51
|
+
fetch: fetchImpl,
|
|
52
|
+
get calls() {
|
|
53
|
+
return counter.calls;
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=fake-model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fake-model.js","sourceRoot":"","sources":["../../src/testkit/f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,aAAa,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;SAChE,CAAC,CAAA;IACJ,CAAC,CAA4B,CAAA;IAC7B,OAAO;QACL,KAAK,EAAE,SAAS;QAChB,IAAI,KAAK;YACP,OAAO,OAAO,CAAC,KAAK,CAAA;QACtB,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Temp directories removed after each test. Call at module level. */
|
|
2
|
+
export declare function useTempDirs(): (files?: Record<string, string>) => string;
|
|
3
|
+
export declare function writeTree(root: string, files: Record<string, string>): void;
|
|
4
|
+
/** A throwaway git repo with one commit of `files`. */
|
|
5
|
+
export declare function gitRepo(dir: string, files: Record<string, string>): string;
|
|
6
|
+
//# sourceMappingURL=tmp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tmp.d.ts","sourceRoot":"","sources":["../../src/testkit/tmp.ts"],"names":[],"mappings":"AAQA,sEAAsE;AACtE,wBAAgB,WAAW,IAAI,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,MAAM,CAUxE;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAM3E;AAED,uDAAuD;AACvD,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAkB1E"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import { afterEach } from "vitest";
|
|
6
|
+
const dirs = [];
|
|
7
|
+
/** Temp directories removed after each test. Call at module level. */
|
|
8
|
+
export function useTempDirs() {
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
for (const dir of dirs.splice(0))
|
|
11
|
+
rmSync(dir, { recursive: true, force: true });
|
|
12
|
+
});
|
|
13
|
+
return (files = {}) => {
|
|
14
|
+
const dir = mkdtempSync(join(tmpdir(), "decisions-test-"));
|
|
15
|
+
dirs.push(dir);
|
|
16
|
+
writeTree(dir, files);
|
|
17
|
+
return dir;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export function writeTree(root, files) {
|
|
21
|
+
for (const [path, content] of Object.entries(files)) {
|
|
22
|
+
const file = join(root, path);
|
|
23
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
24
|
+
writeFileSync(file, content);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** A throwaway git repo with one commit of `files`. */
|
|
28
|
+
export function gitRepo(dir, files) {
|
|
29
|
+
writeTree(dir, files);
|
|
30
|
+
const git = (...args) => execFileSync("git", ["-C", dir, ...args], {
|
|
31
|
+
stdio: "ignore",
|
|
32
|
+
env: {
|
|
33
|
+
...process.env,
|
|
34
|
+
GIT_AUTHOR_NAME: "t",
|
|
35
|
+
GIT_AUTHOR_EMAIL: "t@t",
|
|
36
|
+
GIT_COMMITTER_NAME: "t",
|
|
37
|
+
GIT_COMMITTER_EMAIL: "t@t",
|
|
38
|
+
GIT_CONFIG_GLOBAL: "/dev/null",
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
git("init", "-q", "-b", "main");
|
|
42
|
+
git("add", "-A");
|
|
43
|
+
git("commit", "-q", "-m", "init");
|
|
44
|
+
return dir;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=tmp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tmp.js","sourceRoot":"","sources":["../../src/testkit/tmp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,S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,EAAE,KAA6B;IAChE,SAAS,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;IACrB,MAAM,GAAG,GAAG,CAAC,GAAG,IAAc,EAAE,EAAE,CAChC,YAAY,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,EAAE;QACxC,KAAK,EAAE,QAAQ;QACf,GAAG,EAAE;YACH,GAAG,OAAO,CAAC,GAAG;YACd,eAAe,EAAE,GAAG;YACpB,gBAAgB,EAAE,KAAK;YACvB,kBAAkB,EAAE,GAAG;YACvB,mBAAmB,EAAE,KAAK;YAC1B,iBAAiB,EAAE,WAAW;SAC/B;KACF,CAAC,CAAA;IACJ,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;IAC/B,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;IAChB,GAAG,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;IACjC,OAAO,GAAG,CAAA;AACZ,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Answers, Usage } from "../model/types.js";
|
|
2
|
+
import type { AnswerSource } from "../run/spend.js";
|
|
3
|
+
import type { LineRange } from "../sources/types.js";
|
|
4
|
+
import { type ToolContext } from "./context.js";
|
|
5
|
+
import { type SkippedSummary } from "./many.js";
|
|
6
|
+
export interface AskResult {
|
|
7
|
+
spec?: string;
|
|
8
|
+
id: string;
|
|
9
|
+
path?: string;
|
|
10
|
+
lines?: LineRange;
|
|
11
|
+
source: AnswerSource;
|
|
12
|
+
model: string;
|
|
13
|
+
servedBy: string;
|
|
14
|
+
answers: Answers;
|
|
15
|
+
/** Answers too flat to act on. */
|
|
16
|
+
undecided: string[];
|
|
17
|
+
/**
|
|
18
|
+
* With `keep`: whether this one state passes. Undecided on any question the
|
|
19
|
+
* filters reference means `undecided`, never a pass or fail.
|
|
20
|
+
*/
|
|
21
|
+
verdict?: "kept" | "dropped" | "undecided";
|
|
22
|
+
usage: Usage;
|
|
23
|
+
latencyMs: number;
|
|
24
|
+
skipped: SkippedSummary;
|
|
25
|
+
redactions: {
|
|
26
|
+
total: number;
|
|
27
|
+
items: number;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** One state, one question set, one call. The shape hooks and scripts want. */
|
|
31
|
+
export declare function runAsk(ctx: ToolContext, rawInput: unknown): Promise<AskResult>;
|
|
32
|
+
//# sourceMappingURL=ask.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ask.d.ts","sourceRoot":"","sources":["../../src/tools/ask.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAGvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EAA0C,KAAK,WAAW,EAAE,MAAM,cAAc,CAAA;AACvF,OAAO,EAAE,KAAK,cAAc,EAAoB,MAAM,WAAW,CAAA;AAGjE,MAAM,WAAW,SAAS;IACxB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB,MAAM,EAAE,YAAY,CAAA;IACpB,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;IAChB,kCAAkC;IAClC,SAAS,EAAE,MAAM,EAAE,CAAA;IACnB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,WAAW,CAAA;IAC1C,KAAK,EAAE,KAAK,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,cAAc,CAAA;IACvB,UAAU,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;CAC7C;AAED,+EAA+E;AAC/E,wBAAsB,MAAM,CAAC,GAAG,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CA0DpF"}
|