@turri-dev/cli 0.2.4-next.8422d0f → 0.2.4-next.d779410
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 +7 -8
- package/dist/bedrock-region.js +3 -3
- package/dist/chat-idle.d.ts +2 -2
- package/dist/chat-idle.js +2 -2
- package/dist/chat-models.d.ts +1 -1
- package/dist/chat-models.js +1 -1
- package/dist/chat-scope.d.ts +1 -3
- package/dist/chat-skills.d.ts +1 -1
- package/dist/chat-skills.js +1 -1
- package/dist/chats.d.ts +44 -20
- package/dist/chats.js +125 -64
- package/dist/cli.js +12 -31
- package/dist/config-edit.d.ts +20 -8
- package/dist/config-edit.js +32 -26
- package/dist/config.d.ts +106 -78
- package/dist/config.js +267 -133
- package/dist/conform-cli.js +14 -3
- package/dist/conformance-switch.d.ts +13 -22
- package/dist/conformance-switch.js +37 -59
- package/dist/drift-cli.js +1 -1
- package/dist/extension.d.ts +17 -10
- package/dist/extension.js +435 -532
- package/dist/genome.js +10 -49
- package/dist/graph.js +3 -5
- package/dist/host-session.d.ts +11 -21
- package/dist/host-session.js +6 -8
- package/dist/host.d.ts +4 -4
- package/dist/host.js +4 -7
- package/dist/identity.js +2 -3
- package/dist/init-config.d.ts +1 -2
- package/dist/init-config.js +10 -17
- package/dist/installed-providers.d.ts +1 -1
- package/dist/installed-providers.js +1 -1
- package/dist/launch-agent.d.ts +51 -0
- package/dist/launch-agent.js +267 -0
- package/dist/{release-cli.js → launch-cli.js} +41 -24
- package/dist/launch-session.d.ts +68 -0
- package/dist/launch-session.js +217 -0
- package/dist/launch-tools.d.ts +28 -0
- package/dist/launch-tools.js +69 -0
- package/dist/launch-track.d.ts +125 -0
- package/dist/launch-track.js +320 -0
- package/dist/loop-cli.d.ts +4 -3
- package/dist/loop-cli.js +17 -15
- package/dist/loop-tools.d.ts +45 -21
- package/dist/loop-tools.js +155 -90
- package/dist/new-project.js +2 -2
- package/dist/notice.d.ts +7 -6
- package/dist/parse-cli.js +2 -2
- package/dist/pi-launch.js +4 -1
- package/dist/pi-settings.d.ts +4 -0
- package/dist/pi-settings.js +39 -0
- package/dist/pi.js +12 -9
- package/dist/plain/check.d.ts +2 -9
- package/dist/plain/check.js +6 -39
- package/dist/plain-files.d.ts +2 -2
- package/dist/plain-files.js +7 -7
- package/dist/regenerate/activity.d.ts +0 -7
- package/dist/regenerate/activity.js +2 -20
- package/dist/regenerate/agent-env.d.ts +1 -1
- package/dist/regenerate/agent-env.js +3 -3
- package/dist/regenerate/agent-shell.js +5 -3
- package/dist/regenerate/audit.js +9 -0
- package/dist/regenerate/base-folder.d.ts +2 -2
- package/dist/regenerate/base-folder.js +1 -1
- 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/command-check.d.ts +7 -1
- package/dist/regenerate/command-check.js +43 -1
- package/dist/regenerate/delivery.d.ts +1 -1
- package/dist/regenerate/delivery.js +3 -3
- 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 +4 -2
- package/dist/regenerate/jobs.js +14 -10
- package/dist/regenerate/launch.d.ts +154 -0
- package/dist/regenerate/{release.js → launch.js} +195 -51
- package/dist/regenerate/ledger-view.d.ts +11 -24
- package/dist/regenerate/ledger-view.js +14 -60
- package/dist/regenerate/ledger.d.ts +34 -16
- package/dist/regenerate/ledger.js +1 -1
- package/dist/regenerate/lineage.d.ts +2 -0
- package/dist/regenerate/lineage.js +8 -0
- package/dist/regenerate/loop.d.ts +54 -67
- package/dist/regenerate/loop.js +312 -148
- package/dist/regenerate/model-names.d.ts +33 -0
- package/dist/regenerate/{engine.js → model-names.js} +2 -28
- package/dist/regenerate/paths.d.ts +3 -3
- package/dist/regenerate/paths.js +4 -4
- 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/scripts-being-written.d.ts +4 -4
- package/dist/regenerate/scripts-being-written.js +3 -3
- 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/test-scripts.d.ts +2 -1
- package/dist/regenerate/test-scripts.js +33 -23
- package/dist/regenerate/testing-steps.d.ts +16 -5
- package/dist/regenerate/testing-steps.js +28 -9
- package/dist/regenerate-cli.js +18 -9
- package/dist/self-invocation.d.ts +11 -0
- package/dist/self-invocation.js +36 -10
- package/dist/sentinel-check.d.ts +3 -3
- package/dist/sentinel-check.js +3 -3
- package/dist/sentinel.d.ts +18 -12
- package/dist/sentinel.js +75 -46
- package/dist/{config-command.d.ts → settings.d.ts} +13 -8
- package/dist/{config-command.js → settings.js} +155 -24
- package/dist/setup.d.ts +2 -2
- package/dist/setup.js +7 -7
- package/dist/skill.d.ts +0 -11
- package/dist/skill.js +0 -9
- package/dist/tools.js +2 -3
- package/dist/turri-versions.js +2 -1
- package/docs/README.md +4 -6
- package/docs/authoring-plain.md +3 -3
- package/docs/chats.md +6 -9
- package/docs/claude-subscription.md +2 -2
- package/docs/config.md +61 -51
- package/docs/development.md +4 -5
- package/docs/headless.md +7 -6
- package/docs/hosting.md +25 -24
- package/docs/launch.md +67 -0
- package/docs/parser.md +3 -3
- package/docs/regenerating.md +30 -22
- package/docs/sandbox.md +3 -3
- package/docs/sentinel.md +28 -16
- package/docs/skills-and-gates.md +6 -11
- package/docs/using.md +25 -42
- package/genome/rules/project-model.md +2 -1
- package/genome/rules/test-plain-files.md +15 -7
- package/genome/rules/turri-regeneration.md +7 -10
- package/genome/skills/convert-old-syntax/SKILL.md +5 -5
- package/genome/skills/implement-conformance-testing-script/SKILL.md +2 -2
- package/genome/skills/implement-unit-testing-script/SKILL.md +3 -3
- 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.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/engine.d.ts +0 -52
- package/dist/regenerate/release.d.ts +0 -121
- package/dist/regenerate/test-advisor.d.ts +0 -101
- package/dist/regenerate/test-advisor.js +0 -379
- package/dist/release-agent.d.ts +0 -43
- package/dist/release-agent.js +0 -130
- package/dist/release-cli.d.ts +0 -1
- package/dist/release-tools.d.ts +0 -44
- package/dist/release-tools.js +0 -170
- package/dist/spec-tools.d.ts +0 -36
- package/dist/spec-tools.js +0 -128
- package/dist/stacks.d.ts +0 -13
- package/dist/stacks.js +0 -96
- package/docs/deploy.md +0 -48
- package/docs/test-advisor.md +0 -110
- /package/dist/{change-plain-cli.d.ts → launch-cli.d.ts} +0 -0
|
@@ -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,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Which model the agents of a job run on.
|
|
3
|
-
*
|
|
4
|
-
* By default, whatever the conversation is using. The person can say otherwise - "render spec
|
|
5
|
-
* changes with Gemini Flash" - for one kind of work or for all of it, and that holds for the
|
|
6
|
-
* rest of the session, for jobs started from a tool call and for jobs a skill queues alike. A
|
|
7
|
-
* single tool call can also name a model for itself alone.
|
|
8
|
-
*
|
|
9
|
-
* A name is resolved strictly. pi's own pattern matching picks its best guess and says nothing
|
|
10
|
-
* - "gpt-5" becomes a Bedrock model with no credentials, "flash" a GLM one - and a job on a
|
|
11
|
-
* guessed model is worse than a question. So an exact id is taken as it is, a looser name is
|
|
12
|
-
* taken only when it fits exactly one model that has credentials, and anything else comes back
|
|
13
|
-
* as a short list to ask the person about.
|
|
14
|
-
*/
|
|
15
|
-
/** The part of pi's model registry this needs. */
|
|
16
|
-
export interface ModelCatalog {
|
|
17
|
-
getAll(): ReadonlyArray<CatalogModel>;
|
|
18
|
-
hasConfiguredAuth(model: CatalogModel): boolean;
|
|
19
|
-
}
|
|
20
|
-
export interface CatalogModel {
|
|
21
|
-
provider: string;
|
|
22
|
-
id: string;
|
|
23
|
-
name?: string;
|
|
24
|
-
}
|
|
25
|
-
export type ModelResolution = {
|
|
26
|
-
ok: true;
|
|
27
|
-
model: string;
|
|
28
|
-
name: string;
|
|
29
|
-
} | {
|
|
30
|
-
ok: false;
|
|
31
|
-
message: string;
|
|
32
|
-
candidates: string[];
|
|
33
|
-
};
|
|
34
|
-
/** Resolve what the person called a model to one this machine can run, or say why not. */
|
|
35
|
-
export declare function resolveModel(query: string, catalog: ModelCatalog): ModelResolution;
|
|
36
|
-
/** The resolution as text for the agent: the model, or why not and what to ask. */
|
|
37
|
-
export declare function describeResolution(resolution: ModelResolution): string;
|
|
38
|
-
/** Kinds of work a model can be chosen for. */
|
|
39
|
-
export type RenderWork = "spec_changes" | "functionalities";
|
|
40
|
-
export declare const WORK_LABEL: Record<RenderWork | "all", string>;
|
|
41
|
-
/** The models chosen in this session, by kind of work. Unset: the project's, or the conversation's model. */
|
|
42
|
-
export type ModelChoices = Partial<Record<RenderWork | "all", string>>;
|
|
43
|
-
/** The model a job of this kind runs on: chosen for it, chosen for everything, or the chat's. */
|
|
44
|
-
export declare function modelFor(choices: ModelChoices, work: RenderWork, chat: string | undefined): string | undefined;
|
|
45
|
-
/**
|
|
46
|
-
* Where each kind of work runs now, in a line each: chosen in this session, or the default coding
|
|
47
|
-
* model - from `--coding-model` or config.turri.yaml, said which - or the conversation's.
|
|
48
|
-
*/
|
|
49
|
-
export declare function describeChoices(choices: ModelChoices, chat: string | undefined, project?: {
|
|
50
|
-
model: string;
|
|
51
|
-
from: string;
|
|
52
|
-
}): string;
|