@turri-dev/cli 0.2.4-next.8422d0f → 0.2.4-next.bc1fc47
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/README.md +3 -3
- package/dist/chat-idle.d.ts +2 -2
- package/dist/chat-idle.js +2 -2
- package/dist/chats.d.ts +0 -10
- package/dist/chats.js +0 -23
- package/dist/cli.js +5 -7
- package/dist/config-edit.js +1 -3
- package/dist/config.d.ts +20 -22
- package/dist/config.js +49 -22
- package/dist/conform-cli.js +13 -2
- package/dist/conformance-switch.d.ts +7 -17
- package/dist/conformance-switch.js +24 -46
- package/dist/drift-cli.js +1 -1
- package/dist/extension.d.ts +8 -10
- package/dist/extension.js +188 -242
- package/dist/genome.js +9 -48
- package/dist/graph.js +3 -5
- package/dist/host-session.d.ts +4 -15
- package/dist/host-session.js +2 -4
- package/dist/host.d.ts +1 -3
- package/dist/host.js +1 -4
- package/dist/identity.js +0 -1
- package/dist/init-config.d.ts +0 -1
- package/dist/init-config.js +2 -9
- package/dist/installed-providers.d.ts +1 -1
- package/dist/installed-providers.js +1 -1
- package/dist/loop-cli.d.ts +4 -3
- package/dist/loop-cli.js +13 -11
- package/dist/loop-tools.d.ts +28 -5
- package/dist/loop-tools.js +87 -22
- package/dist/new-project.js +2 -2
- package/dist/pi-launch.js +1 -1
- package/dist/pi.js +9 -6
- package/dist/plain/check.d.ts +1 -8
- package/dist/plain/check.js +3 -38
- package/dist/regenerate/activity.d.ts +0 -7
- package/dist/regenerate/activity.js +2 -20
- package/dist/regenerate/agent-shell.js +3 -1
- package/dist/regenerate/audit.js +9 -0
- package/dist/regenerate/cases.js +7 -0
- package/dist/regenerate/chunk-plan.d.ts +5 -0
- package/dist/regenerate/chunk-plan.js +16 -1
- package/dist/regenerate/drift.d.ts +4 -0
- package/dist/regenerate/drift.js +26 -6
- package/dist/regenerate/failure-reports.d.ts +28 -0
- package/dist/regenerate/failure-reports.js +79 -0
- package/dist/regenerate/job-panel.js +3 -1
- package/dist/regenerate/jobs-tree.js +1 -1
- package/dist/regenerate/jobs.d.ts +2 -0
- package/dist/regenerate/jobs.js +4 -0
- package/dist/regenerate/ledger-view.d.ts +11 -24
- package/dist/regenerate/ledger-view.js +14 -60
- package/dist/regenerate/ledger.d.ts +1 -14
- package/dist/regenerate/ledger.js +1 -1
- package/dist/regenerate/loop.d.ts +46 -60
- package/dist/regenerate/loop.js +277 -116
- package/dist/regenerate/records.d.ts +11 -0
- package/dist/regenerate/records.js +15 -0
- package/dist/regenerate/regenerate.d.ts +0 -2
- package/dist/regenerate/regenerate.js +4 -15
- package/dist/regenerate/renames.js +4 -4
- package/dist/regenerate/requires.d.ts +7 -0
- package/dist/regenerate/requires.js +24 -18
- package/dist/regenerate/spec-map.js +3 -3
- package/dist/regenerate/standing.js +1 -1
- package/dist/regenerate/submit-work.d.ts +2 -0
- package/dist/regenerate/submit-work.js +8 -3
- package/dist/regenerate/testing-steps.d.ts +11 -0
- package/dist/regenerate/testing-steps.js +22 -3
- package/dist/regenerate-cli.js +18 -9
- package/dist/self-invocation.d.ts +11 -0
- package/dist/self-invocation.js +33 -7
- package/dist/sentinel.js +8 -5
- package/dist/skill.d.ts +0 -11
- package/dist/skill.js +0 -9
- package/dist/stacks.js +1 -1
- package/dist/tools.js +2 -3
- package/dist/turri-versions.js +2 -1
- package/docs/README.md +0 -2
- package/docs/authoring-plain.md +3 -3
- package/docs/chats.md +1 -3
- package/docs/config.md +11 -13
- package/docs/deploy.md +1 -1
- package/docs/development.md +2 -3
- package/docs/headless.md +6 -4
- package/docs/hosting.md +6 -6
- package/docs/parser.md +2 -2
- package/docs/regenerating.md +21 -13
- package/docs/sentinel.md +4 -4
- package/docs/skills-and-gates.md +4 -8
- package/docs/using.md +13 -21
- package/genome/rules/test-plain-files.md +15 -7
- package/genome/rules/turri-regeneration.md +4 -8
- package/genome/skills/convert-old-syntax/SKILL.md +5 -5
- package/package.json +1 -1
- package/dist/advisor-chat.d.ts +0 -63
- package/dist/advisor-chat.js +0 -290
- package/dist/change-plain-cli.d.ts +0 -1
- package/dist/change-plain-cli.js +0 -55
- package/dist/ledger-cli.d.ts +0 -1
- package/dist/ledger-cli.js +0 -50
- package/dist/ledger-tools.d.ts +0 -10
- package/dist/ledger-tools.js +0 -64
- package/dist/regenerate/advisor-records.d.ts +0 -93
- package/dist/regenerate/advisor-records.js +0 -110
- package/dist/regenerate/advisor-runs.d.ts +0 -87
- package/dist/regenerate/advisor-runs.js +0 -327
- package/dist/regenerate/test-advisor.d.ts +0 -101
- package/dist/regenerate/test-advisor.js +0 -379
- package/dist/spec-tools.d.ts +0 -36
- package/dist/spec-tools.js +0 -128
- package/docs/test-advisor.md +0 -110
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
import { existsSync, readdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
3
|
-
import { join, resolve } from "node:path";
|
|
4
|
-
import { ensureInScratch } from "./paths.js";
|
|
5
|
-
/**
|
|
6
|
-
* The test advisor's file: `.turri/advisor/<module>.json` in the project - what it made of each functional spec of the
|
|
7
|
-
* module it looked at, by func-id, keyed by a hash of its text (docs/test-advisor.md). Local to this machine: `.turri`
|
|
8
|
-
* ignores itself, so it is never committed - another machine starts with none, and classifies only what changes there.
|
|
9
|
-
*
|
|
10
|
-
* An entry is current while its hash is the functional spec's text's: a text that changes makes it stale, and the
|
|
11
|
-
* functional spec is looked at again. `pending` is written the moment the advisor sees a functional spec, so quitting
|
|
12
|
-
* loses nothing: the next start in the chat or a host picks it up.
|
|
13
|
-
*/
|
|
14
|
-
export const ADVISOR_DIR = "advisor";
|
|
15
|
-
/** The four questions, each a yes or a no: could it fail silently, be read two ways, be built on later, cost much when wrong. */
|
|
16
|
-
export const ADVISOR_QUESTIONS = ["silent-failure", "divergence", "revisited", "cost"];
|
|
17
|
-
/** The hash a functional spec's text is known by: its text, trimmed. */
|
|
18
|
-
export function textHash(text) {
|
|
19
|
-
return createHash("sha256").update(text.trim()).digest("hex").slice(0, 16);
|
|
20
|
-
}
|
|
21
|
-
/** The folder of a project's advisor files. */
|
|
22
|
-
export function advisorDir(project) {
|
|
23
|
-
return join(resolve(project), ".turri", ADVISOR_DIR);
|
|
24
|
-
}
|
|
25
|
-
/** A module's advisor file. */
|
|
26
|
-
export function advisorPath(project, module) {
|
|
27
|
-
return join(advisorDir(project), `${module}.json`);
|
|
28
|
-
}
|
|
29
|
-
/** A module's advisor file, or nothing when there is none or it does not read. */
|
|
30
|
-
export function readAdvisor(project, module) {
|
|
31
|
-
try {
|
|
32
|
-
const parsed = JSON.parse(readFileSync(advisorPath(project, module), "utf8"));
|
|
33
|
-
return parsed !== null && typeof parsed === "object" && typeof parsed.entries === "object" && parsed.entries !== null ? parsed : undefined;
|
|
34
|
-
}
|
|
35
|
-
catch {
|
|
36
|
-
return undefined;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
/** A functional spec's entry, or nothing. */
|
|
40
|
-
export function advisorEntry(project, module, funcId) {
|
|
41
|
-
return readAdvisor(project, module)?.entries[funcId];
|
|
42
|
-
}
|
|
43
|
-
/** Whether an entry is about the text as it is now: one that is not, or none, is stale, and the functional spec is looked at again. */
|
|
44
|
-
export function isCurrent(entry, hash) {
|
|
45
|
-
return entry !== undefined && entry.hash === hash;
|
|
46
|
-
}
|
|
47
|
-
/** Write a functional spec's entry, in place of the one it had. `plainFile` is the module's, from the project. */
|
|
48
|
-
export function putAdvisorEntry(project, module, plainFile, entry) {
|
|
49
|
-
const file = readAdvisor(project, module) ?? { module, plainFile, entries: {} };
|
|
50
|
-
const written = { ...entry, at: entry.at ?? new Date().toISOString() };
|
|
51
|
-
file.plainFile = plainFile;
|
|
52
|
-
file.entries[entry.funcId] = written;
|
|
53
|
-
writeAdvisor(project, file);
|
|
54
|
-
return written;
|
|
55
|
-
}
|
|
56
|
-
/** Take a functional spec's entry out - its functional spec is gone. */
|
|
57
|
-
export function removeAdvisorEntry(project, module, funcId) {
|
|
58
|
-
const file = readAdvisor(project, module);
|
|
59
|
-
if (file === undefined || file.entries[funcId] === undefined)
|
|
60
|
-
return;
|
|
61
|
-
delete file.entries[funcId];
|
|
62
|
-
writeAdvisor(project, file);
|
|
63
|
-
}
|
|
64
|
-
function writeAdvisor(project, file) {
|
|
65
|
-
const scratch = join(resolve(project), ".turri");
|
|
66
|
-
ensureInScratch(scratch, advisorDir(project));
|
|
67
|
-
const path = advisorPath(project, file.module);
|
|
68
|
-
// Written whole, then moved in place: a turri killed part-way never leaves half a file.
|
|
69
|
-
const temporary = `${path}.${process.pid}.tmp`;
|
|
70
|
-
writeFileSync(temporary, `${JSON.stringify(file, null, 2)}\n`);
|
|
71
|
-
renameSync(temporary, path);
|
|
72
|
-
}
|
|
73
|
-
/** Every pending entry of a project's advisor files, with the module and its .plain file - what a start picks up. */
|
|
74
|
-
export function pendingEntries(project) {
|
|
75
|
-
return entriesWhere(project, (entry) => entry.state === "pending");
|
|
76
|
-
}
|
|
77
|
-
/** Every yes of a project's advisor files not yet handed to a chat - what a start delivers. */
|
|
78
|
-
export function undeliveredEntries(project) {
|
|
79
|
-
return entriesWhere(project, (entry) => entry.state === "yes" && entry.undelivered === true);
|
|
80
|
-
}
|
|
81
|
-
/** A yes handed to a chat: the entry for that text no longer kept for the next start. */
|
|
82
|
-
export function markDelivered(project, module, funcId, hash) {
|
|
83
|
-
const file = readAdvisor(project, module);
|
|
84
|
-
const entry = file?.entries[funcId];
|
|
85
|
-
if (file === undefined || entry === undefined || entry.hash !== hash || entry.undelivered !== true)
|
|
86
|
-
return;
|
|
87
|
-
const { undelivered: _delivered, ...rest } = entry;
|
|
88
|
-
file.entries[funcId] = rest;
|
|
89
|
-
writeAdvisor(project, file);
|
|
90
|
-
}
|
|
91
|
-
function entriesWhere(project, wanted) {
|
|
92
|
-
const dir = advisorDir(project);
|
|
93
|
-
if (!existsSync(dir))
|
|
94
|
-
return [];
|
|
95
|
-
let names;
|
|
96
|
-
try {
|
|
97
|
-
names = readdirSync(dir).filter((name) => name.endsWith(".json"));
|
|
98
|
-
}
|
|
99
|
-
catch {
|
|
100
|
-
return [];
|
|
101
|
-
}
|
|
102
|
-
return names.flatMap((name) => {
|
|
103
|
-
const file = readAdvisor(project, name.slice(0, -".json".length));
|
|
104
|
-
if (file === undefined)
|
|
105
|
-
return [];
|
|
106
|
-
return Object.values(file.entries)
|
|
107
|
-
.filter(wanted)
|
|
108
|
-
.map((entry) => ({ module: file.module, plainFile: file.plainFile, entry }));
|
|
109
|
-
});
|
|
110
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { type AdvisorReport } from "./advisor-records.ts";
|
|
2
|
-
import type { SeenSpec } from "./loop.ts";
|
|
3
|
-
import { type AdvisorCallOptions, type AdvisorSubject } from "./test-advisor.ts";
|
|
4
|
-
/**
|
|
5
|
-
* When the test advisor runs, and on what (docs/test-advisor.md). It watches what the work loop looks at - every
|
|
6
|
-
* ***plain change the loop sees, as it sees it - and takes each functional spec that is new or whose text changed since
|
|
7
|
-
* its code was built (its code record), has no scenarios, and has no entry in the advisor's file for that text. A
|
|
8
|
-
* project already built, with no advisor file, is looked at not at all: only what changes from now on is.
|
|
9
|
-
*
|
|
10
|
-
* Each is marked `pending` in the advisor's file then and there, and judged in the background - two at a time at most,
|
|
11
|
-
* outside `parallel-jobs` and the lanes: no pulse waits for it, and it never steers or stops one. Its work is clear of
|
|
12
|
-
* any pulse: no panel, no log, no stop of a pulse's reaches it. A functional spec whose text changes while it is judged
|
|
13
|
-
* has that work thrown away - whoever changed it - and the new text starts again. What `pending` is left as turri quits,
|
|
14
|
-
* the next start in the chat or a host picks up.
|
|
15
|
-
*
|
|
16
|
-
* The advisor decides and writes nothing in the ***plain: what it made of a functional spec is kept in its file and
|
|
17
|
-
* handed on (`onVerdict`) to the chat the person looks at, which writes the scenarios on a yes. A yes not yet handed to a
|
|
18
|
-
* chat stays marked undelivered, and is handed on again at the next start.
|
|
19
|
-
*
|
|
20
|
-
* It is made only where the session starts in the chat or a host (extension.ts) - never for a headless command, nor
|
|
21
|
-
* pi's print, json and rpc modes - and does nothing in a project whose `test-advisor:` is false.
|
|
22
|
-
*/
|
|
23
|
-
/** How many functional specs the advisor works on at once. */
|
|
24
|
-
export declare const ADVISOR_PARALLEL = 2;
|
|
25
|
-
/** A finished verdict, handed on to the chat: the functional spec, what was made of it, and where its scenarios go. */
|
|
26
|
-
export interface AdvisorVerdict {
|
|
27
|
-
project: string;
|
|
28
|
-
module: string;
|
|
29
|
-
funcId: string;
|
|
30
|
-
/** The module's .plain file. */
|
|
31
|
-
plainFile: string;
|
|
32
|
-
/** The tip's .plain file: where the chain's scenarios are tested, and its test reqs and conformance testing script are. */
|
|
33
|
-
tip: string;
|
|
34
|
-
/** The test plain file its scenarios go in, from the project: `<test-dir>/<module>/<func-id>.plain`. */
|
|
35
|
-
testFile: string;
|
|
36
|
-
/** The hash of the text it judged. */
|
|
37
|
-
hash: string;
|
|
38
|
-
report: AdvisorReport;
|
|
39
|
-
/** Whether it is still about the functional spec as it is now: its text the same, and still with no scenarios. */
|
|
40
|
-
current(): boolean;
|
|
41
|
-
/** Handed to a chat: no longer kept for the next start. */
|
|
42
|
-
delivered(): void;
|
|
43
|
-
}
|
|
44
|
-
export interface TestAdvisorOptions {
|
|
45
|
-
/** Whether a project wants the advisor now. Default: its `test-advisor:` is not false. */
|
|
46
|
-
enabled?: (project: string) => boolean;
|
|
47
|
-
/** The judgement of a functional spec. Default: the model calls of test-advisor.ts. */
|
|
48
|
-
advise?: (subject: AdvisorSubject, options: AdvisorCallOptions) => Promise<AdvisorReport>;
|
|
49
|
-
/** The conversation's own words on what matters for a module - its steering. */
|
|
50
|
-
context?: (plainFile: string) => string[];
|
|
51
|
-
/** A verdict finished - or a yes left undelivered, at the next start: for the chat the person looks at. Not given: only kept. */
|
|
52
|
-
onVerdict?: (verdict: AdvisorVerdict) => void;
|
|
53
|
-
/** How many functional specs at once. Default: ADVISOR_PARALLEL. */
|
|
54
|
-
parallel?: number;
|
|
55
|
-
}
|
|
56
|
-
export interface TestAdvisor {
|
|
57
|
-
/** What the loop looked at: the functional specs to take, and the work whose text changed under it to drop. */
|
|
58
|
-
seen(look: SeenSpec): void;
|
|
59
|
-
/** Pick up what a project's advisor file has pending - the work turri quit in the middle of - and hand on its undelivered yeses. */
|
|
60
|
-
resume(project: string): void;
|
|
61
|
-
/** Resolves once nothing is queued or running. */
|
|
62
|
-
idle(): Promise<void>;
|
|
63
|
-
/** Stop everything, leaving what was running pending. */
|
|
64
|
-
stop(): void;
|
|
65
|
-
/** The functional specs it is judging for now, or about to - `module:func-id`, a project's alone when named. */
|
|
66
|
-
taking(project?: string): string[];
|
|
67
|
-
/**
|
|
68
|
-
* The chat's own way in (evaluate_tests): a functional spec evaluated now - even a text already judged, and whatever
|
|
69
|
-
* `test-advisor` says - its verdict handed on as any is. `already`: it is being evaluated now; `scenarios`: it has some,
|
|
70
|
-
* and is not evaluated; `missing`: its module has no such functional spec.
|
|
71
|
-
*/
|
|
72
|
-
evaluate(asked: EvaluateRequest): "started" | "already" | "scenarios" | "missing";
|
|
73
|
-
}
|
|
74
|
-
/** A functional spec the chat asks the advisor to evaluate. */
|
|
75
|
-
export interface EvaluateRequest {
|
|
76
|
-
module: string;
|
|
77
|
-
funcId: string;
|
|
78
|
-
/** The module's .plain file. */
|
|
79
|
-
plainFile: string;
|
|
80
|
-
/** The tip its scenarios are tested in. Default: the one the advisor last knew, else the module at the top of a chain it is in, else itself. */
|
|
81
|
-
tip?: string;
|
|
82
|
-
/** Why the chat asks - "the coding agent failed three times to implement it" - for the classifier, as context. */
|
|
83
|
-
reason?: string;
|
|
84
|
-
}
|
|
85
|
-
/** Whether a functional spec has scenarios of any kind: then it is tested as the person wants, and today's review covers it. */
|
|
86
|
-
export declare function hasScenarios(item: unknown): boolean;
|
|
87
|
-
export declare function createTestAdvisor(options?: TestAdvisorOptions): TestAdvisor;
|
|
@@ -1,327 +0,0 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
-
import { basename, join, relative, resolve } from "node:path";
|
|
3
|
-
import { advisorModel, configForSpec, readProjectConfig, stackOf, testDirOf } from "../config.js";
|
|
4
|
-
import { plainFileParser } from "../plain/parser.js";
|
|
5
|
-
import { ACCEPTANCE_TESTS, CONFORMANCE_TESTS, FUNCTIONAL_REQUIREMENTS, REQUIRED_FUNCTIONAL_SPECS } from "../plain/spec.js";
|
|
6
|
-
import { tipsAbove } from "../plain/check.js";
|
|
7
|
-
import { conformanceTestsOnIn } from "../conformance-switch.js";
|
|
8
|
-
import { isStdlibModule } from "../plain/stdlib.js";
|
|
9
|
-
import { outsideJobs, withStopSignal } from "./activity.js";
|
|
10
|
-
import { advisorEntry, isCurrent, markDelivered, pendingEntries, putAdvisorEntry, removeAdvisorEntry, textHash, undeliveredEntries, } from "./advisor-records.js";
|
|
11
|
-
import { firstLine, record } from "./ledger.js";
|
|
12
|
-
import { projectDirOf, resolveTemplateDirs } from "./paths.js";
|
|
13
|
-
import { advise as adviseByModel } from "./test-advisor.js";
|
|
14
|
-
/**
|
|
15
|
-
* When the test advisor runs, and on what (docs/test-advisor.md). It watches what the work loop looks at - every
|
|
16
|
-
* ***plain change the loop sees, as it sees it - and takes each functional spec that is new or whose text changed since
|
|
17
|
-
* its code was built (its code record), has no scenarios, and has no entry in the advisor's file for that text. A
|
|
18
|
-
* project already built, with no advisor file, is looked at not at all: only what changes from now on is.
|
|
19
|
-
*
|
|
20
|
-
* Each is marked `pending` in the advisor's file then and there, and judged in the background - two at a time at most,
|
|
21
|
-
* outside `parallel-jobs` and the lanes: no pulse waits for it, and it never steers or stops one. Its work is clear of
|
|
22
|
-
* any pulse: no panel, no log, no stop of a pulse's reaches it. A functional spec whose text changes while it is judged
|
|
23
|
-
* has that work thrown away - whoever changed it - and the new text starts again. What `pending` is left as turri quits,
|
|
24
|
-
* the next start in the chat or a host picks up.
|
|
25
|
-
*
|
|
26
|
-
* The advisor decides and writes nothing in the ***plain: what it made of a functional spec is kept in its file and
|
|
27
|
-
* handed on (`onVerdict`) to the chat the person looks at, which writes the scenarios on a yes. A yes not yet handed to a
|
|
28
|
-
* chat stays marked undelivered, and is handed on again at the next start.
|
|
29
|
-
*
|
|
30
|
-
* It is made only where the session starts in the chat or a host (extension.ts) - never for a headless command, nor
|
|
31
|
-
* pi's print, json and rpc modes - and does nothing in a project whose `test-advisor:` is false.
|
|
32
|
-
*/
|
|
33
|
-
/** How many functional specs the advisor works on at once. */
|
|
34
|
-
export const ADVISOR_PARALLEL = 2;
|
|
35
|
-
/** The functional spec's own place in a module, as its own .plain file has it now - or nothing. */
|
|
36
|
-
function currentItem(plainFile, funcId) {
|
|
37
|
-
try {
|
|
38
|
-
const [, tree] = plainFileParser(basename(plainFile), resolveTemplateDirs(plainFile), { allowNoFunctionalities: true, testDir: testDirOf(plainFile) });
|
|
39
|
-
return (tree[FUNCTIONAL_REQUIREMENTS] ?? []).find((item) => item.id === funcId);
|
|
40
|
-
}
|
|
41
|
-
catch {
|
|
42
|
-
return undefined;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
/** Whether a functional spec has scenarios of any kind: then it is tested as the person wants, and today's review covers it. */
|
|
46
|
-
export function hasScenarios(item) {
|
|
47
|
-
const of = (key) => (item?.[key] ?? []).length;
|
|
48
|
-
return of(CONFORMANCE_TESTS) + of(ACCEPTANCE_TESTS) > 0;
|
|
49
|
-
}
|
|
50
|
-
/** The project's AGENTS.md, whole: its own words on what matters. */
|
|
51
|
-
function agentsText(project) {
|
|
52
|
-
const file = join(project, "AGENTS.md");
|
|
53
|
-
try {
|
|
54
|
-
return existsSync(file) ? [readFileSync(file, "utf8")] : [];
|
|
55
|
-
}
|
|
56
|
-
catch {
|
|
57
|
-
return [];
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
/** Whether a project wants the advisor: it conformance tests (`conformance-tests: true`), and its `test-advisor:` is not false. */
|
|
61
|
-
function wanted(project) {
|
|
62
|
-
try {
|
|
63
|
-
return conformanceTestsOnIn(project) && readProjectConfig(project, stackOf(project)).testAdvisor !== false;
|
|
64
|
-
}
|
|
65
|
-
catch {
|
|
66
|
-
return true;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
export function createTestAdvisor(options = {}) {
|
|
70
|
-
const enabled = options.enabled ?? wanted;
|
|
71
|
-
const advise = options.advise ?? adviseByModel;
|
|
72
|
-
const parallel = options.parallel ?? ADVISOR_PARALLEL;
|
|
73
|
-
const queue = [];
|
|
74
|
-
const running = new Map();
|
|
75
|
-
let idleWaiters = [];
|
|
76
|
-
let stopped = false;
|
|
77
|
-
const keyOf = (project, module, funcId) => `${project}\0${module}:${funcId}`;
|
|
78
|
-
const settleIdle = () => {
|
|
79
|
-
if (queue.length > 0 || running.size > 0)
|
|
80
|
-
return;
|
|
81
|
-
const waiters = idleWaiters;
|
|
82
|
-
idleWaiters = [];
|
|
83
|
-
for (const resolveIdle of waiters)
|
|
84
|
-
resolveIdle();
|
|
85
|
-
};
|
|
86
|
-
/** The work on a functional spec thrown away: its text is not what it was judging any more. */
|
|
87
|
-
const drop = (key, hash) => {
|
|
88
|
-
const at = queue.findIndex((work) => work.key === key && work.hash !== hash);
|
|
89
|
-
if (at !== -1)
|
|
90
|
-
queue.splice(at, 1);
|
|
91
|
-
const work = running.get(key);
|
|
92
|
-
if (work !== undefined && work.hash !== hash && work.dropped !== true) {
|
|
93
|
-
work.dropped = true;
|
|
94
|
-
work.controller.abort();
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
/** Take a functional spec, marked pending at once - unless the same text is taken already. Whether it was taken. */
|
|
98
|
-
const take = (given) => {
|
|
99
|
-
const key = keyOf(given.project, given.module, given.funcId);
|
|
100
|
-
drop(key, given.hash);
|
|
101
|
-
if (queue.some((work) => work.key === key) || running.get(key)?.hash === given.hash)
|
|
102
|
-
return false;
|
|
103
|
-
putAdvisorEntry(given.project, given.module, relative(given.project, given.plainFile), {
|
|
104
|
-
funcId: given.funcId,
|
|
105
|
-
hash: given.hash,
|
|
106
|
-
state: "pending",
|
|
107
|
-
tip: relative(given.project, given.tip),
|
|
108
|
-
...(given.asked !== undefined ? { asked: given.asked } : {}),
|
|
109
|
-
});
|
|
110
|
-
queue.push({ ...given, key, controller: new AbortController() });
|
|
111
|
-
pump();
|
|
112
|
-
return true;
|
|
113
|
-
};
|
|
114
|
-
const pump = () => {
|
|
115
|
-
if (stopped)
|
|
116
|
-
return;
|
|
117
|
-
while (running.size < parallel) {
|
|
118
|
-
// A new text waits for the work on its old one to unwind; the rest go on past it.
|
|
119
|
-
const at = queue.findIndex((work) => !running.has(work.key));
|
|
120
|
-
if (at === -1)
|
|
121
|
-
break;
|
|
122
|
-
const work = queue.splice(at, 1)[0];
|
|
123
|
-
running.set(work.key, work);
|
|
124
|
-
// Clear of any pulse the loop was looking for, and stopped by its own signal alone.
|
|
125
|
-
void outsideJobs(() => withStopSignal(work.controller.signal, () => run(work))).finally(() => {
|
|
126
|
-
if (running.get(work.key) === work)
|
|
127
|
-
running.delete(work.key);
|
|
128
|
-
pump();
|
|
129
|
-
settleIdle();
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
settleIdle();
|
|
133
|
-
};
|
|
134
|
-
const spec = (work) => `${work.module}:${work.funcId}`;
|
|
135
|
-
const place = (work) => ({ project: work.project, module: work.module });
|
|
136
|
-
/** A verdict handed on to the chat: a yes kept undelivered in the advisor's file until a chat has it. */
|
|
137
|
-
const handOn = (given) => {
|
|
138
|
-
if (options.onVerdict === undefined)
|
|
139
|
-
return;
|
|
140
|
-
const { project, module, funcId, plainFile, hash } = given;
|
|
141
|
-
try {
|
|
142
|
-
options.onVerdict({
|
|
143
|
-
...given,
|
|
144
|
-
testFile: relative(project, join(testDirOf(plainFile), module, `${funcId}.plain`)),
|
|
145
|
-
current: () => {
|
|
146
|
-
const item = currentItem(plainFile, funcId);
|
|
147
|
-
return item !== undefined && textHash(item.markdown) === hash && !hasScenarios(item) && advisorEntry(project, module, funcId)?.hash === hash;
|
|
148
|
-
},
|
|
149
|
-
delivered: () => markDelivered(project, module, funcId, hash),
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
catch {
|
|
153
|
-
/* a chat that throws as it is told: the yes stays undelivered, for the next start */
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
const run = async (work) => {
|
|
157
|
-
const config = (() => {
|
|
158
|
-
try {
|
|
159
|
-
return configForSpec(work.plainFile);
|
|
160
|
-
}
|
|
161
|
-
catch {
|
|
162
|
-
return {};
|
|
163
|
-
}
|
|
164
|
-
})();
|
|
165
|
-
const model = advisorModel(config);
|
|
166
|
-
const entryOf = (state, more = {}) => {
|
|
167
|
-
putAdvisorEntry(work.project, work.module, relative(work.project, work.plainFile), {
|
|
168
|
-
funcId: work.funcId,
|
|
169
|
-
hash: work.hash,
|
|
170
|
-
state,
|
|
171
|
-
tip: relative(work.project, work.tip),
|
|
172
|
-
...(model !== undefined ? { model } : {}),
|
|
173
|
-
...more,
|
|
174
|
-
});
|
|
175
|
-
};
|
|
176
|
-
try {
|
|
177
|
-
// The setting turns off only what a change starts: the chat's asking stands.
|
|
178
|
-
if (work.asked === undefined && !enabled(work.project))
|
|
179
|
-
return;
|
|
180
|
-
const subject = {
|
|
181
|
-
module: work.module,
|
|
182
|
-
funcId: work.funcId,
|
|
183
|
-
text: work.text,
|
|
184
|
-
moduleText: readFileSync(work.plainFile, "utf8"),
|
|
185
|
-
...(resolve(work.tip) !== resolve(work.plainFile) && existsSync(work.tip) ? { testedIn: { module: basename(work.tip).replace(/\.plain$/, ""), text: readFileSync(work.tip, "utf8") } } : {}),
|
|
186
|
-
context: [...agentsText(work.project), ...(options.context?.(work.plainFile) ?? [])],
|
|
187
|
-
...(work.asked?.reason !== undefined ? { reason: work.asked.reason } : {}),
|
|
188
|
-
};
|
|
189
|
-
const report = await advise(subject, { cwd: work.project, ...(model !== undefined ? { model } : {}) });
|
|
190
|
-
if (work.controller.signal.aborted)
|
|
191
|
-
throw new Error("stopped");
|
|
192
|
-
record({ kind: "advisor.classified", spec: spec(work), verdict: report.verdict, questions: report.questions.map((answered) => answered.question), asked: work.asked !== undefined }, place(work));
|
|
193
|
-
// A yes is kept undelivered until a chat has it; a no is only a line, and nothing is lost when it is not drawn.
|
|
194
|
-
entryOf(report.verdict, { report, ...(report.verdict === "yes" && options.onVerdict !== undefined ? { undelivered: true } : {}) });
|
|
195
|
-
handOn({ project: work.project, module: work.module, funcId: work.funcId, plainFile: work.plainFile, tip: work.tip, hash: work.hash, report });
|
|
196
|
-
}
|
|
197
|
-
catch (error) {
|
|
198
|
-
if (work.dropped === true) {
|
|
199
|
-
record({ kind: "advisor.dropped", spec: spec(work) }, place(work));
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
// Stopped with the session: left pending, for the next start.
|
|
203
|
-
if (stopped || work.controller.signal.aborted)
|
|
204
|
-
return;
|
|
205
|
-
const reason = firstLine(error instanceof Error ? error.message : String(error), 300);
|
|
206
|
-
entryOf("failed", { reason });
|
|
207
|
-
record({ kind: "advisor.failed", spec: spec(work), reason }, place(work));
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
const advisor = {
|
|
211
|
-
seen(look) {
|
|
212
|
-
if (stopped)
|
|
213
|
-
return;
|
|
214
|
-
const tip = look.chain.at(-1);
|
|
215
|
-
if (tip === undefined)
|
|
216
|
-
return;
|
|
217
|
-
const project = projectDirOf(tip.plainFile);
|
|
218
|
-
if (!enabled(project))
|
|
219
|
-
return;
|
|
220
|
-
const built = new Map();
|
|
221
|
-
const builtItems = (section) => (look.built[section] ?? []);
|
|
222
|
-
for (const item of builtItems(FUNCTIONAL_REQUIREMENTS))
|
|
223
|
-
built.set(`${tip.moduleName}:${item.id}`, (item.markdown ?? "").trim());
|
|
224
|
-
for (const item of builtItems(REQUIRED_FUNCTIONAL_SPECS))
|
|
225
|
-
built.set(`${item.module}:${item.id}`, (item.markdown ?? "").trim());
|
|
226
|
-
const items = (section, own) => (look.tree[section] ?? []).map((item) => ({ item, module: own ? tip.moduleName : (item.module ?? "") }));
|
|
227
|
-
for (const { item, module } of [...items(REQUIRED_FUNCTIONAL_SPECS, false), ...items(FUNCTIONAL_REQUIREMENTS, true)]) {
|
|
228
|
-
if (module === "" || isStdlibModule(module))
|
|
229
|
-
continue;
|
|
230
|
-
const entry = look.chain.find((link) => link.moduleName === module);
|
|
231
|
-
if (entry === undefined)
|
|
232
|
-
continue;
|
|
233
|
-
const text = item.markdown.trim();
|
|
234
|
-
const hash = textHash(text);
|
|
235
|
-
const key = keyOf(project, module, item.id);
|
|
236
|
-
// Work on a text that is no more is thrown away, wherever the change came from.
|
|
237
|
-
drop(key, hash);
|
|
238
|
-
// Built as it is now: neither new nor changed.
|
|
239
|
-
if (built.get(`${module}:${item.id}`) === text)
|
|
240
|
-
continue;
|
|
241
|
-
// Scenarios of any kind: tested as the person wants, and today's review covers it.
|
|
242
|
-
if (hasScenarios(item))
|
|
243
|
-
continue;
|
|
244
|
-
// Judged already, for this text - or being judged now.
|
|
245
|
-
const known = advisorEntry(project, module, item.id);
|
|
246
|
-
if (isCurrent(known, hash) && (known.state !== "pending" || running.has(key) || queue.some((work) => work.key === key)))
|
|
247
|
-
continue;
|
|
248
|
-
take({ project, module, funcId: item.id, plainFile: resolve(entry.plainFile), tip: resolve(tip.plainFile), text, hash });
|
|
249
|
-
}
|
|
250
|
-
},
|
|
251
|
-
resume(project) {
|
|
252
|
-
if (stopped)
|
|
253
|
-
return;
|
|
254
|
-
// Conformance tests off: the advisor is off with them - nothing pending is picked up, not even what the chat asked for.
|
|
255
|
-
if (options.enabled === undefined && !conformanceTestsOnIn(project))
|
|
256
|
-
return;
|
|
257
|
-
// With the setting off, only what the chat asked for is picked up.
|
|
258
|
-
const wants = enabled(project);
|
|
259
|
-
for (const pending of pendingEntries(project)) {
|
|
260
|
-
if (!wants && pending.entry.asked === undefined)
|
|
261
|
-
continue;
|
|
262
|
-
const plainFile = resolve(project, pending.plainFile);
|
|
263
|
-
const item = currentItem(plainFile, pending.entry.funcId);
|
|
264
|
-
// Gone, or given scenarios meanwhile: nothing is left to pick up.
|
|
265
|
-
if (item === undefined || hasScenarios(item)) {
|
|
266
|
-
removeAdvisorEntry(project, pending.module, pending.entry.funcId);
|
|
267
|
-
continue;
|
|
268
|
-
}
|
|
269
|
-
const text = item.markdown.trim();
|
|
270
|
-
take({
|
|
271
|
-
project,
|
|
272
|
-
module: pending.module,
|
|
273
|
-
funcId: item.id,
|
|
274
|
-
plainFile,
|
|
275
|
-
tip: resolve(project, pending.entry.tip ?? pending.plainFile),
|
|
276
|
-
text,
|
|
277
|
-
hash: textHash(text),
|
|
278
|
-
...(pending.entry.asked !== undefined ? { asked: pending.entry.asked } : {}),
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
// A yes no chat had when turri quit: handed on now, while it is still about the functional spec as it is.
|
|
282
|
-
for (const kept of undeliveredEntries(project)) {
|
|
283
|
-
const { entry } = kept;
|
|
284
|
-
const plainFile = resolve(project, kept.plainFile);
|
|
285
|
-
const item = currentItem(plainFile, entry.funcId);
|
|
286
|
-
if (entry.report === undefined || item === undefined || textHash(item.markdown) !== entry.hash || hasScenarios(item)) {
|
|
287
|
-
markDelivered(project, kept.module, entry.funcId, entry.hash);
|
|
288
|
-
continue;
|
|
289
|
-
}
|
|
290
|
-
handOn({ project, module: kept.module, funcId: entry.funcId, plainFile, tip: resolve(project, entry.tip ?? kept.plainFile), hash: entry.hash, report: entry.report });
|
|
291
|
-
}
|
|
292
|
-
},
|
|
293
|
-
idle() {
|
|
294
|
-
if (queue.length === 0 && running.size === 0)
|
|
295
|
-
return Promise.resolve();
|
|
296
|
-
return new Promise((resolveIdle) => idleWaiters.push(resolveIdle));
|
|
297
|
-
},
|
|
298
|
-
taking(project) {
|
|
299
|
-
const mine = (work) => project === undefined || resolve(work.project) === resolve(project);
|
|
300
|
-
return [...new Set([...running.values(), ...queue].filter(mine).map((work) => `${work.module}:${work.funcId}`))];
|
|
301
|
-
},
|
|
302
|
-
evaluate(asked) {
|
|
303
|
-
const plainFile = resolve(asked.plainFile);
|
|
304
|
-
const project = projectDirOf(plainFile);
|
|
305
|
-
const item = currentItem(plainFile, asked.funcId);
|
|
306
|
-
if (item === undefined)
|
|
307
|
-
return "missing";
|
|
308
|
-
if (hasScenarios(item))
|
|
309
|
-
return "scenarios";
|
|
310
|
-
const text = item.markdown.trim();
|
|
311
|
-
const hash = textHash(text);
|
|
312
|
-
const known = advisorEntry(project, asked.module, asked.funcId);
|
|
313
|
-
// The tip its scenarios are tested in: given, else known, else the module at the top of a chain it is in - itself when none is.
|
|
314
|
-
const tip = asked.tip ?? (known?.tip !== undefined ? resolve(project, known.tip) : (tipsAbove(asked.module, project)[0]?.file ?? plainFile));
|
|
315
|
-
const reason = asked.reason?.trim();
|
|
316
|
-
const taken = take({ project, module: asked.module, funcId: asked.funcId, plainFile, tip: resolve(tip), text, hash, asked: reason !== undefined && reason !== "" ? { reason } : {} });
|
|
317
|
-
return taken ? "started" : "already";
|
|
318
|
-
},
|
|
319
|
-
stop() {
|
|
320
|
-
stopped = true;
|
|
321
|
-
queue.length = 0;
|
|
322
|
-
for (const work of running.values())
|
|
323
|
-
work.controller.abort();
|
|
324
|
-
},
|
|
325
|
-
};
|
|
326
|
-
return advisor;
|
|
327
|
-
}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import type { AdvisorAnswer, AdvisorInput, AdvisorReport } from "./advisor-records.ts";
|
|
2
|
-
/**
|
|
3
|
-
* The test advisor's judgement of one functional spec: does it need explicit testing scenarios, and if so, which inputs
|
|
4
|
-
* should they cover (docs/test-advisor.md). Every step is a plain model call on `models.advisor`, answered through one
|
|
5
|
-
* tool and checked in code, as the planner's grouping agent is - none is a skill, and none can touch the project.
|
|
6
|
-
*
|
|
7
|
-
* - **Classify:** four questions, each yes carrying its evidence - a wrong output that looks right (silent failure), an
|
|
8
|
-
* input two reasonable readings answer differently (divergence), what would change (revisited), the consequence of a
|
|
9
|
-
* bug (cost). A yes whose evidence is empty or malformed counts as no. Silent failure, divergence or cost make the
|
|
10
|
-
* verdict yes; revisited alone does not - the unit tests are the regression protection.
|
|
11
|
-
* - **On a yes, pick the inputs:** one call writes 1-10 boundary probes (and the divergence's input), readers that
|
|
12
|
-
* differ only by their system prompt each predict every probe's output, code compares them, and any disagreement is a
|
|
13
|
-
* candidate - the union, never a majority. The third reader is spared when the first two already disagree. One last
|
|
14
|
-
* call keeps, of each candidate, the readings a reasonable person could hold.
|
|
15
|
-
*/
|
|
16
|
-
/** The functional spec the advisor looks at, and what it reads it with. */
|
|
17
|
-
export interface AdvisorSubject {
|
|
18
|
-
module: string;
|
|
19
|
-
funcId: string;
|
|
20
|
-
/** The functional spec's text. */
|
|
21
|
-
text: string;
|
|
22
|
-
/** The module's .plain file, whole: its definitions, its reqs, the functional specs around it. */
|
|
23
|
-
moduleText: string;
|
|
24
|
-
/** The project's own words on what matters: its AGENTS.md, the steering given in the conversation. */
|
|
25
|
-
context: string[];
|
|
26
|
-
/** A module below's: the tip its scenarios are tested in - built on it, its own functional specs beside it. */
|
|
27
|
-
testedIn?: {
|
|
28
|
-
module: string;
|
|
29
|
-
text: string;
|
|
30
|
-
};
|
|
31
|
-
/** Why the chat asked for the evaluation (evaluate_tests) - "the coding agent failed three times to implement it" - for the classifier, as context. */
|
|
32
|
-
reason?: string;
|
|
33
|
-
}
|
|
34
|
-
export interface AdvisorCallOptions {
|
|
35
|
-
/** Where the calls run: the project. */
|
|
36
|
-
cwd: string;
|
|
37
|
-
/** The advisor's model (advisorModel) - the `advisor` role's config is laid over it as for any agent. */
|
|
38
|
-
model?: string;
|
|
39
|
-
}
|
|
40
|
-
/** The classification: the verdict, the questions that were a yes with their evidence, and the divergence's input. */
|
|
41
|
-
export interface Classification {
|
|
42
|
-
verdict: "yes" | "no";
|
|
43
|
-
questions: AdvisorAnswer[];
|
|
44
|
-
divergence?: {
|
|
45
|
-
input: string;
|
|
46
|
-
readings: [string, string];
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
/** The fewest and most probes a functional spec is given. */
|
|
50
|
-
export declare const MIN_PROBES = 1;
|
|
51
|
-
export declare const MAX_PROBES = 10;
|
|
52
|
-
/** What a reader answers for an input the functional spec does not settle: a scenario on it would pin a guess. */
|
|
53
|
-
export declare const UNSPECIFIED = "unspecified";
|
|
54
|
-
/** The readers: the same task, decorrelated by their system prompts alone. */
|
|
55
|
-
export declare const READERS: ReadonlyArray<{
|
|
56
|
-
name: string;
|
|
57
|
-
system: string;
|
|
58
|
-
}>;
|
|
59
|
-
/** Text compared as the readers' outputs are: whitespace collapsed, case left aside. */
|
|
60
|
-
export declare function normalised(text: string): string;
|
|
61
|
-
type ClassificationAnswer = {
|
|
62
|
-
silent_failure: {
|
|
63
|
-
answer: boolean;
|
|
64
|
-
wrong_output?: string;
|
|
65
|
-
};
|
|
66
|
-
divergence: {
|
|
67
|
-
answer: boolean;
|
|
68
|
-
input?: string;
|
|
69
|
-
reading_a?: string;
|
|
70
|
-
reading_b?: string;
|
|
71
|
-
};
|
|
72
|
-
revisited: {
|
|
73
|
-
answer: boolean;
|
|
74
|
-
would_change?: string;
|
|
75
|
-
};
|
|
76
|
-
cost: {
|
|
77
|
-
answer: boolean;
|
|
78
|
-
consequence?: string;
|
|
79
|
-
};
|
|
80
|
-
};
|
|
81
|
-
/**
|
|
82
|
-
* The classification, from the call's answer: each yes kept only with its evidence - a yes without it, or with it
|
|
83
|
-
* malformed (two readings that are the same), is a no. The verdict is yes on silent failure, divergence or cost.
|
|
84
|
-
*/
|
|
85
|
-
export declare function classificationOf(answer: ClassificationAnswer): Classification;
|
|
86
|
-
/** Classify a functional spec: one call, four evidence-backed questions. Throws when the call gives no answer. */
|
|
87
|
-
export declare function classify(subject: AdvisorSubject, options: AdvisorCallOptions): Promise<Classification>;
|
|
88
|
-
/**
|
|
89
|
-
* The inputs the readers split on - every probe where any two predictions differ once normalised: the union, never a
|
|
90
|
-
* majority - each with its distinct readings, in the order the readers gave them.
|
|
91
|
-
*/
|
|
92
|
-
export declare function splitInputs(readings: string[][]): Map<number, string[]>;
|
|
93
|
-
/**
|
|
94
|
-
* Pick the inputs a functional spec's scenarios should cover: the probes, the readers' predictions of them, the
|
|
95
|
-
* disagreements in code, and the verifier's word on each. An input the readers agree on comes with their output; one
|
|
96
|
-
* they split on, with every reading the verifier kept - a single reading left is an agreed one, and none left drops it.
|
|
97
|
-
*/
|
|
98
|
-
export declare function pickInputs(subject: AdvisorSubject, classification: Classification, options: AdvisorCallOptions): Promise<AdvisorInput[]>;
|
|
99
|
-
/** The whole judgement: classify, and on a yes pick the inputs. Throws when a call that cannot be done without fails. */
|
|
100
|
-
export declare function advise(subject: AdvisorSubject, options: AdvisorCallOptions): Promise<AdvisorReport>;
|
|
101
|
-
export {};
|