@turri-dev/cli 0.2.4-next.240620d → 0.2.4-next.359b847
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 +6 -7
- package/dist/bedrock-region.js +3 -3
- 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 -10
- package/dist/chats.js +125 -41
- package/dist/cli.js +10 -26
- package/dist/config-edit.d.ts +20 -8
- package/dist/config-edit.js +32 -24
- package/dist/config.d.ts +101 -58
- package/dist/config.js +265 -118
- package/dist/conform-cli.js +14 -3
- package/dist/conformance-switch.d.ts +7 -6
- package/dist/conformance-switch.js +19 -16
- package/dist/extension.d.ts +29 -3
- package/dist/extension.js +375 -351
- package/dist/genome.js +5 -1
- package/dist/host-session.d.ts +8 -7
- package/dist/host-session.js +4 -4
- package/dist/host.d.ts +3 -1
- package/dist/host.js +3 -3
- package/dist/identity.js +2 -2
- package/dist/init-config.d.ts +1 -1
- package/dist/init-config.js +8 -8
- 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.js +4 -4
- package/dist/loop-tools.d.ts +45 -21
- package/dist/loop-tools.js +152 -82
- package/dist/notice.d.ts +7 -6
- package/dist/parse-cli.js +2 -2
- package/dist/pi-launch.js +3 -0
- package/dist/pi-settings.d.ts +4 -0
- package/dist/pi-settings.js +39 -0
- package/dist/pi.js +6 -3
- package/dist/plain/check.d.ts +1 -1
- package/dist/plain/check.js +3 -1
- package/dist/plain-files.d.ts +2 -2
- package/dist/plain-files.js +7 -7
- 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/job-panel.js +3 -1
- package/dist/regenerate/jobs.d.ts +2 -2
- package/dist/regenerate/jobs.js +10 -10
- package/dist/regenerate/launch.d.ts +154 -0
- package/dist/regenerate/{release.js → launch.js} +195 -51
- package/dist/regenerate/ledger.d.ts +33 -2
- package/dist/regenerate/lineage.d.ts +2 -0
- package/dist/regenerate/lineage.js +8 -0
- package/dist/regenerate/loop.d.ts +30 -10
- package/dist/regenerate/loop.js +166 -59
- 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.js +4 -1
- 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/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 +6 -6
- package/dist/regenerate/testing-steps.js +8 -8
- package/dist/regenerate-cli.js +1 -1
- package/dist/self-invocation.d.ts +11 -0
- package/dist/self-invocation.js +36 -7
- 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 +72 -43
- 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/turri-versions.js +2 -1
- package/docs/README.md +4 -4
- package/docs/chats.md +5 -6
- package/docs/claude-subscription.md +2 -2
- package/docs/config.md +58 -46
- package/docs/development.md +2 -2
- package/docs/headless.md +4 -4
- package/docs/hosting.md +20 -19
- package/docs/launch.md +67 -0
- package/docs/parser.md +2 -2
- package/docs/regenerating.md +21 -15
- package/docs/sandbox.md +3 -3
- package/docs/sentinel.md +26 -14
- package/docs/skills-and-gates.md +4 -4
- package/docs/using.md +19 -28
- package/genome/rules/project-model.md +2 -1
- package/genome/rules/turri-regeneration.md +5 -3
- 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/regenerate/engine.d.ts +0 -52
- package/dist/regenerate/release.d.ts +0 -121
- package/dist/release-agent.d.ts +0 -43
- package/dist/release-agent.js +0 -130
- package/dist/release-tools.d.ts +0 -44
- package/dist/release-tools.js +0 -170
- package/dist/stacks.d.ts +0 -13
- package/dist/stacks.js +0 -96
- package/docs/deploy.md +0 -48
- /package/dist/{release-cli.d.ts → launch-cli.d.ts} +0 -0
package/dist/config.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
-
import { copyFileSync, existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { copyFileSync, existsSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { basename, join, resolve } from "node:path";
|
|
4
4
|
import { load as loadYaml } from "js-yaml";
|
|
5
|
-
import {
|
|
6
|
-
import { projectDirOf } from "./regenerate/paths.js";
|
|
5
|
+
import { projectDirOf, resolveTemplateDirs } from "./regenerate/paths.js";
|
|
7
6
|
/**
|
|
8
7
|
* The project's `config.turri.yaml`, at its root - the folder that holds `plain_modules` - or, before it had one, its `config.yaml`.
|
|
9
8
|
*
|
|
@@ -25,8 +24,8 @@ import { projectDirOf } from "./regenerate/paths.js";
|
|
|
25
24
|
* review: false # review the code and its tests once they pass (default: true)
|
|
26
25
|
* mutation-testing: false # give the coding agent and the reviewer can_it_fail (default: true)
|
|
27
26
|
* allow-to-stop-jobs: false # stop a running job the spec moved on from (default: true)
|
|
28
|
-
*
|
|
29
|
-
* sentinel: true # a chat of its own every finished pulse goes to, which tests
|
|
27
|
+
* launch-after-pulse: true # launch what each pulse lands, in the background, the newest commit winning (default: false)
|
|
28
|
+
* sentinel: true # a chat of its own every finished pulse goes to, which tests what is launched and tells you what is wrong: true, false, or ask - the person asked before it first opens in a session (default: ask)
|
|
30
29
|
* rules-off: [integrations] # ***plain rules to leave out of the prompts, by name (default: none)
|
|
31
30
|
* unittests-script: test_scripts/run_unittests.sh # the testing scripts - see test-scripts.ts
|
|
32
31
|
* conformance-tests-script: test_scripts/run_conformance_tests.sh
|
|
@@ -49,49 +48,51 @@ import { projectDirOf } from "./regenerate/paths.js";
|
|
|
49
48
|
* either of which may be left out; a bare string is the model alone. What a model leaves out it takes
|
|
50
49
|
* from the one it inherits: judge-model from coding-model, coding-model from harness-model. They are
|
|
51
50
|
* defaults: `--harness-model` / `--coding-model` / `--judge-model` on the command line win over them,
|
|
52
|
-
* and so does a model chosen during the conversation (pi's /model
|
|
51
|
+
* and so does a model chosen during the conversation (pi's /model) or named on a call. `model:` is read
|
|
53
52
|
* as `coding-model`, which it was before there were two.
|
|
54
53
|
*
|
|
55
54
|
* Keys are written with dashes; underscores are read the same (`conformance_tests`). Keys it
|
|
56
55
|
* does not know - another tool's `config.yaml`, read while it is the old file, may carry several - are ignored, and so is a value of
|
|
57
56
|
* the wrong type. Everything is optional, and what is given on the command line wins.
|
|
58
57
|
*
|
|
59
|
-
* A
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* from the
|
|
65
|
-
*
|
|
66
|
-
* stack's file.
|
|
58
|
+
* A module can have settings of its own in `config.turri.<module>.yaml` beside `config.turri.yaml`:
|
|
59
|
+
* `config.turri.backend.yaml` for `backend.plain` - its testing scripts, its toolchains, its models - laid over
|
|
60
|
+
* `config.turri.yaml` key by key, a model it names taking what it leaves out from the project's. A module with no file
|
|
61
|
+
* of its own takes the one of a module it requires - `config.turri.backend.yaml` builds `backend_auth.plain`, which
|
|
62
|
+
* requires `backend.plain` - and two among the modules it requires is an error (`configModuleFor`). Nobody chooses it:
|
|
63
|
+
* it is worked out from the module, and a pulse keeps the one it started with. `module:`, `harness-model:` and the
|
|
64
|
+
* other settings of the whole project are read from `config.turri.yaml` alone.
|
|
67
65
|
*/
|
|
68
66
|
/** turri's settings for a project, in a file of its own: a `config.yaml` beside it may be another tool's. */
|
|
69
67
|
export const CONFIG_FILE = "config.turri.yaml";
|
|
70
68
|
/**
|
|
71
69
|
* Where turri's settings were before they had a file of their own. A project with no `config.turri*.yaml` yet is read
|
|
72
|
-
* from it - and a `config.<name>.yaml` beside it as the
|
|
70
|
+
* from it - and a `config.<name>.yaml` beside it as the module `<name>`'s - and turri never writes it: the first setting
|
|
73
71
|
* turri writes copies them to the new names (`adoptLegacyConfig`), and from then on the old files are not read.
|
|
74
72
|
*/
|
|
75
73
|
export const LEGACY_CONFIG_FILE = "config.yaml";
|
|
76
|
-
/** A
|
|
77
|
-
export function
|
|
78
|
-
return `config.turri.${
|
|
74
|
+
/** A module's config file's name: `config.turri.backend.yaml` for `backend.plain`. */
|
|
75
|
+
export function moduleConfigFile(module) {
|
|
76
|
+
return `config.turri.${module}.yaml`;
|
|
79
77
|
}
|
|
80
|
-
function
|
|
81
|
-
return `config.${
|
|
78
|
+
function legacyModuleConfigFile(module) {
|
|
79
|
+
return `config.${module}.yaml`;
|
|
82
80
|
}
|
|
83
81
|
/**
|
|
84
82
|
* The names in a folder - read again only once the folder itself has changed: a name added, removed or renamed in it
|
|
85
|
-
* moves its modification time. Asked many times a look, for every module of every chain.
|
|
83
|
+
* moves its modification time. Asked many times a look, for every module of every chain. A folder changed less than a
|
|
84
|
+
* second before it was read is read again each time: a name added within the same tick of the file system's clock
|
|
85
|
+
* would not move it (readConfigFile).
|
|
86
86
|
*/
|
|
87
87
|
function namesIn(root) {
|
|
88
88
|
try {
|
|
89
89
|
const at = statSync(root).mtimeMs;
|
|
90
90
|
const kept = keptNames.get(root);
|
|
91
|
-
if (kept !== undefined && kept.at === at)
|
|
91
|
+
if (kept !== undefined && kept.at === at && at < kept.readAt - RACY_MS)
|
|
92
92
|
return [...kept.names];
|
|
93
|
+
const readAt = Date.now();
|
|
93
94
|
const names = readdirSync(root);
|
|
94
|
-
keptNames.set(root, { at, names });
|
|
95
|
+
keptNames.set(root, { at, names, readAt });
|
|
95
96
|
if (keptNames.size > 64)
|
|
96
97
|
keptNames.delete(keptNames.keys().next().value);
|
|
97
98
|
return [...names];
|
|
@@ -101,36 +102,36 @@ function namesIn(root) {
|
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
104
|
const keptNames = new Map();
|
|
104
|
-
/** The
|
|
105
|
-
function
|
|
105
|
+
/** The modules with a file of their own in the old naming, `config.<module>.yaml`. */
|
|
106
|
+
function legacyModuleConfigs(root) {
|
|
106
107
|
return namesIn(root)
|
|
107
108
|
.map((name) => /^config\.(?!turri(?:\.|$))(.+)\.yaml$/.exec(name)?.[1])
|
|
108
109
|
.filter((name) => name !== undefined)
|
|
109
110
|
.sort();
|
|
110
111
|
}
|
|
111
|
-
/** Whether a folder's settings are still in the old files: a config.yaml or a config.<
|
|
112
|
+
/** Whether a folder's settings are still in the old files: a config.yaml or a config.<module>.yaml, and no config.turri*.yaml. */
|
|
112
113
|
export function usesLegacyConfig(root) {
|
|
113
114
|
const names = namesIn(root);
|
|
114
115
|
if (names.some((name) => /^config\.turri(?:\..+)?\.yaml$/.test(name)))
|
|
115
116
|
return false;
|
|
116
|
-
return names.includes(LEGACY_CONFIG_FILE) ||
|
|
117
|
+
return names.includes(LEGACY_CONFIG_FILE) || legacyModuleConfigs(root).length > 0;
|
|
117
118
|
}
|
|
118
119
|
/** The file the project's settings are read from, by name: config.turri.yaml, or config.yaml while the folder has only the old files. */
|
|
119
120
|
export function projectConfigFile(root) {
|
|
120
121
|
return usesLegacyConfig(root) ? LEGACY_CONFIG_FILE : CONFIG_FILE;
|
|
121
122
|
}
|
|
122
|
-
/** The file a
|
|
123
|
-
export function
|
|
124
|
-
return usesLegacyConfig(root) ?
|
|
123
|
+
/** The file a module's own settings are read from, by name - the old name while the folder has only the old files. */
|
|
124
|
+
export function moduleConfigFileIn(root, module) {
|
|
125
|
+
return usesLegacyConfig(root) ? legacyModuleConfigFile(module) : moduleConfigFile(module);
|
|
125
126
|
}
|
|
126
|
-
/** Whether a folder holds a project's settings: a config.turri.yaml, a
|
|
127
|
+
/** Whether a folder holds a project's settings: a config.turri.yaml, a module's file, or the old files. */
|
|
127
128
|
export function hasProjectConfig(root) {
|
|
128
|
-
return existsSync(join(root, CONFIG_FILE)) ||
|
|
129
|
+
return existsSync(join(root, CONFIG_FILE)) || moduleConfigsOf(root).length > 0 || usesLegacyConfig(root);
|
|
129
130
|
}
|
|
130
|
-
/** The
|
|
131
|
-
export function
|
|
131
|
+
/** The modules a project folder has config files for, by name. */
|
|
132
|
+
export function moduleConfigsOf(root) {
|
|
132
133
|
if (usesLegacyConfig(root))
|
|
133
|
-
return
|
|
134
|
+
return legacyModuleConfigs(root);
|
|
134
135
|
return namesIn(root)
|
|
135
136
|
.map((name) => /^config\.turri\.(.+)\.yaml$/.exec(name)?.[1])
|
|
136
137
|
.filter((name) => name !== undefined)
|
|
@@ -138,91 +139,163 @@ export function stacksOf(root) {
|
|
|
138
139
|
}
|
|
139
140
|
/**
|
|
140
141
|
* Before turri first writes a setting in a folder whose settings are still in the old files: config.yaml copied to
|
|
141
|
-
* config.turri.yaml, and each config.<
|
|
142
|
+
* config.turri.yaml, and each config.<module>.yaml to config.turri.<module>.yaml, so nothing is lost when the old files
|
|
142
143
|
* stop being read. The old files are left as they are. Gives back the files written, by name.
|
|
143
144
|
*/
|
|
145
|
+
/**
|
|
146
|
+
* Keys turri has renamed, old to new - no alias: a project's config.turri.yaml or config.turri.<module>.yaml that still has
|
|
147
|
+
* the old one has it renamed as turri first reads or writes the project's config (`renameOldKeys`), its value and its
|
|
148
|
+
* comment kept. One that sets the new one too is left as it is, the old one said in the banner as doing nothing.
|
|
149
|
+
*/
|
|
150
|
+
export const RENAMED_KEYS = { "release-after-pulse": "launch-after-pulse" };
|
|
151
|
+
/** The projects whose config files were looked at for old keys this process, and what was renamed in each - for the banner. */
|
|
152
|
+
const renamedKeys = new Map();
|
|
153
|
+
/**
|
|
154
|
+
* Rename the old keys of `RENAMED_KEYS` in the project's config.turri*.yaml files - once a process, or again with `again`
|
|
155
|
+
* (a file just copied from its old name). A top-level key alone, its line kept but for the key's name; a file that also
|
|
156
|
+
* sets the new key, one that does not parse, or one that cannot be written is left as it is. Returns every key renamed
|
|
157
|
+
* in the project this process.
|
|
158
|
+
*/
|
|
159
|
+
export function renameOldKeys(root, options = {}) {
|
|
160
|
+
const dir = resolve(root);
|
|
161
|
+
const done = renamedKeys.get(dir);
|
|
162
|
+
if (done !== undefined && options.again !== true)
|
|
163
|
+
return done;
|
|
164
|
+
const renamed = done ?? [];
|
|
165
|
+
renamedKeys.set(dir, renamed);
|
|
166
|
+
for (const file of namesIn(dir).filter((name) => /^config\.turri(\.[^.]+)?\.yaml$/.test(name))) {
|
|
167
|
+
const path = join(dir, file);
|
|
168
|
+
let text;
|
|
169
|
+
let parsed;
|
|
170
|
+
try {
|
|
171
|
+
text = readFileSync(path, "utf8");
|
|
172
|
+
parsed = loadYaml(text);
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed))
|
|
178
|
+
continue;
|
|
179
|
+
let changed = text;
|
|
180
|
+
const now = [];
|
|
181
|
+
for (const [from, to] of Object.entries(RENAMED_KEYS)) {
|
|
182
|
+
if (!(from in parsed) || to in parsed)
|
|
183
|
+
continue;
|
|
184
|
+
const line = new RegExp(`^${from.replace(/[-]/g, "\\-")}(?=[ \\t]*:)`, "m");
|
|
185
|
+
if (!line.test(changed))
|
|
186
|
+
continue;
|
|
187
|
+
changed = changed.replace(line, to);
|
|
188
|
+
now.push({ file, from, to });
|
|
189
|
+
}
|
|
190
|
+
if (now.length === 0)
|
|
191
|
+
continue;
|
|
192
|
+
try {
|
|
193
|
+
writeFileSync(path, changed);
|
|
194
|
+
renamed.push(...now);
|
|
195
|
+
}
|
|
196
|
+
catch {
|
|
197
|
+
/* a file turri cannot write keeps its old key: the banner says it does nothing */
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return renamed;
|
|
201
|
+
}
|
|
144
202
|
export function adoptLegacyConfig(root, options = {}) {
|
|
203
|
+
renameOldKeys(root);
|
|
145
204
|
if (!usesLegacyConfig(root))
|
|
146
205
|
return [];
|
|
147
206
|
const copies = [
|
|
148
|
-
// `projectFile: false`: the
|
|
207
|
+
// `projectFile: false`: the modules' files alone - turri init-config writes config.turri.yaml itself.
|
|
149
208
|
...(options.projectFile !== false && existsSync(join(root, LEGACY_CONFIG_FILE)) ? [[LEGACY_CONFIG_FILE, CONFIG_FILE]] : []),
|
|
150
|
-
...
|
|
209
|
+
...legacyModuleConfigs(root).map((module) => [legacyModuleConfigFile(module), moduleConfigFile(module)]),
|
|
151
210
|
];
|
|
152
211
|
for (const [from, to] of copies)
|
|
153
212
|
copyFileSync(join(root, from), join(root, to));
|
|
213
|
+
// What was copied may have keys turri has renamed since.
|
|
214
|
+
if (copies.length > 0)
|
|
215
|
+
renameOldKeys(root, { again: true });
|
|
154
216
|
return copies.map(([, to]) => to);
|
|
155
217
|
}
|
|
156
|
-
/** The
|
|
157
|
-
const
|
|
158
|
-
/**
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
*/
|
|
162
|
-
export function chosenStack() {
|
|
163
|
-
const pinned = pinnedStack.getStore();
|
|
164
|
-
if (pinned !== undefined)
|
|
165
|
-
return pinned.stack;
|
|
166
|
-
const chat = currentChat();
|
|
167
|
-
if (chat !== undefined)
|
|
168
|
-
return chat.stack;
|
|
169
|
-
return text(process.env.TURRI_STACK);
|
|
218
|
+
/** The module whose config file a pulse runs with: worked out as it was queued, whatever the files say since. */
|
|
219
|
+
const pinnedConfig = new AsyncLocalStorage();
|
|
220
|
+
/** Inside a pulse - or work pinned like one - the module whose config file it runs with; none outside. */
|
|
221
|
+
export function pinnedConfigModule() {
|
|
222
|
+
return pinnedConfig.getStore()?.module;
|
|
170
223
|
}
|
|
171
|
-
/**
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
if (chat !== undefined)
|
|
179
|
-
chat.stack = chosen;
|
|
180
|
-
else if (chosen === undefined)
|
|
181
|
-
delete process.env.TURRI_STACK;
|
|
182
|
-
else
|
|
183
|
-
process.env.TURRI_STACK = chosen;
|
|
184
|
-
}
|
|
185
|
-
/** Run `work` with `stack` as the one chosen, whatever is chosen meanwhile: a pulse keeps the stack it started with. */
|
|
186
|
-
export function withStack(stack, work) {
|
|
187
|
-
return pinnedStack.run({ stack }, work);
|
|
188
|
-
}
|
|
189
|
-
/** Whether a stack is pinned here - named by the call that asked for the work, or kept by the pulse it runs in. */
|
|
190
|
-
export function stackPinned() {
|
|
191
|
-
return pinnedStack.getStore() !== undefined;
|
|
224
|
+
/** Run `work` with `module`'s config file over the project's, whatever the files say meanwhile: a pulse keeps the one it started with. */
|
|
225
|
+
export function withConfigModule(module, work) {
|
|
226
|
+
return pinnedConfig.run({ module }, work);
|
|
227
|
+
}
|
|
228
|
+
/** Whether a module's config file is pinned here - by the pulse it runs in, or the work that plans it. */
|
|
229
|
+
export function configModulePinned() {
|
|
230
|
+
return pinnedConfig.getStore() !== undefined;
|
|
192
231
|
}
|
|
193
232
|
/**
|
|
194
|
-
* The
|
|
195
|
-
*
|
|
196
|
-
*
|
|
233
|
+
* The module whose config file builds a module - its `config.turri.<module>.yaml` laid over `config.turri.yaml` - or
|
|
234
|
+
* none, `config.turri.yaml` alone. The one pinned, inside a pulse; else the module's own file; else the one file among
|
|
235
|
+
* the modules it requires, all the way down - a module is built on their code, in one codebase, with their testing
|
|
236
|
+
* scripts. Two among them is an error: which one builds it cannot be told. Only `requires` counts, not imports.
|
|
197
237
|
*/
|
|
198
|
-
export function
|
|
238
|
+
export function configModuleFor(plainFile) {
|
|
199
239
|
const root = projectDirOf(resolve(plainFile));
|
|
200
|
-
if (
|
|
201
|
-
return
|
|
240
|
+
if (configModulePinned())
|
|
241
|
+
return configModuleOf(root);
|
|
202
242
|
const own = basename(plainFile).replace(/\.plain$/, "");
|
|
203
|
-
|
|
243
|
+
const files = moduleConfigsOf(root);
|
|
244
|
+
if (files.length === 0)
|
|
245
|
+
return undefined;
|
|
246
|
+
if (files.includes(own))
|
|
247
|
+
return own;
|
|
248
|
+
const below = requiredModulesOf(resolve(plainFile)).filter((name) => files.includes(name));
|
|
249
|
+
if (below.length > 1)
|
|
250
|
+
throw new Error(moduleConfigClash(own, below, root));
|
|
251
|
+
return below[0];
|
|
252
|
+
}
|
|
253
|
+
/** Why a module's config cannot be told: two or more of the modules it requires have a config file of their own. */
|
|
254
|
+
export function moduleConfigClash(module, below, root) {
|
|
255
|
+
const named = below.map((name) => moduleConfigFileIn(root, name)).join(", ");
|
|
256
|
+
return (`${module}.plain requires modules that each have a config file of their own - ${named} - and a module built on others ` +
|
|
257
|
+
`takes theirs, so which builds ${module}.plain cannot be told. Give ${module}.plain its own ${moduleConfigFileIn(root, module)}, ` +
|
|
258
|
+
`or keep only one of them.`);
|
|
204
259
|
}
|
|
205
|
-
/** The words that choose no stack: the project's config alone. */
|
|
206
|
-
export const NO_STACK = ["none", "off", "base", "-"];
|
|
207
260
|
/**
|
|
208
|
-
*
|
|
209
|
-
*
|
|
261
|
+
* Every module a module requires, all the way down, by name - read from each file's frontmatter alone, found as the
|
|
262
|
+
* parser finds them (the module's folder, its template/ folder, PLAIN_TEMPLATE_DIRS). One that is not there, or does
|
|
263
|
+
* not read, ends its branch: the parse says what is wrong with it.
|
|
210
264
|
*/
|
|
211
|
-
export function
|
|
212
|
-
const
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
265
|
+
export function requiredModulesOf(plainFile) {
|
|
266
|
+
const dirs = resolveTemplateDirs(plainFile);
|
|
267
|
+
const found = [];
|
|
268
|
+
const visit = (file) => {
|
|
269
|
+
for (const name of requiresIn(file)) {
|
|
270
|
+
const bare = basename(name.replace(/^\.\//, ""), ".plain");
|
|
271
|
+
if (found.includes(bare))
|
|
272
|
+
continue;
|
|
273
|
+
found.push(bare);
|
|
274
|
+
const next = dirs.map((dir) => join(dir, `${name}.plain`)).find((candidate) => existsSync(candidate));
|
|
275
|
+
if (next !== undefined)
|
|
276
|
+
visit(next);
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
visit(plainFile);
|
|
280
|
+
return found;
|
|
281
|
+
}
|
|
282
|
+
/** The modules a .plain file's frontmatter says it requires. */
|
|
283
|
+
function requiresIn(file) {
|
|
284
|
+
try {
|
|
285
|
+
const match = /^-{3,}[ \t]*\n(?:([\s\S]*?)\n)?-{3,}[ \t]*(?:\n|$)/.exec(readFileSync(file, "utf8"));
|
|
286
|
+
const front = match?.[1] !== undefined ? loadYaml(match[1]) : undefined;
|
|
287
|
+
const requires = front?.requires;
|
|
288
|
+
const names = typeof requires === "string" ? [requires] : Array.isArray(requires) ? requires : [];
|
|
289
|
+
return names.filter((name) => typeof name === "string" && name.trim() !== "").map((name) => name.trim());
|
|
290
|
+
}
|
|
291
|
+
catch {
|
|
292
|
+
return [];
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
/** The module whose config file is pinned here, when the project folder has that file. */
|
|
296
|
+
export function configModuleOf(root) {
|
|
297
|
+
const module = pinnedConfigModule();
|
|
298
|
+
return module !== undefined && moduleConfigsOf(root).includes(module) ? module : undefined;
|
|
226
299
|
}
|
|
227
300
|
export const THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
228
301
|
/**
|
|
@@ -230,10 +303,10 @@ export const THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhig
|
|
|
230
303
|
* The code fixer of a conformance run and the repair agent are coding agents; the unit-test and conformance arbiters
|
|
231
304
|
* are both `arbiter`.
|
|
232
305
|
*/
|
|
233
|
-
export const AGENT_ROLES = ["chat", "sentinel", "planner", "diagnosis", "
|
|
306
|
+
export const AGENT_ROLES = ["chat", "sentinel", "planner", "diagnosis", "launch", "coding", "conformance", "explorer", "reviewer", "test-reviewer", "judge", "arbiter", "debugger"];
|
|
234
307
|
/**
|
|
235
308
|
* How hard each role thinks when nothing names a level - not the config's `models:`, nor a `:level` on the model it is
|
|
236
|
-
* given. The agents that do the work - write the code and the tests, explore,
|
|
309
|
+
* given. The agents that do the work - write the code and the tests, explore, launch - think little: they work from a
|
|
237
310
|
* spec that leaves little to guess, and every turn of theirs is many. The ones that judge - review, weigh, plan, find a
|
|
238
311
|
* cause - think more: a wrong call there costs pulses. The conversation keeps its own level, pi's.
|
|
239
312
|
*/
|
|
@@ -241,7 +314,7 @@ export const ROLE_THINKING = {
|
|
|
241
314
|
coding: "low",
|
|
242
315
|
conformance: "low",
|
|
243
316
|
explorer: "low",
|
|
244
|
-
|
|
317
|
+
launch: "low",
|
|
245
318
|
reviewer: "medium",
|
|
246
319
|
"test-reviewer": "medium",
|
|
247
320
|
judge: "medium",
|
|
@@ -251,7 +324,7 @@ export const ROLE_THINKING = {
|
|
|
251
324
|
diagnosis: "medium",
|
|
252
325
|
};
|
|
253
326
|
/** The roles on the conversation's side: without their own entry they take the chat's model, not `default`. */
|
|
254
|
-
// The
|
|
327
|
+
// The launch is not: it follows steps - a script, a start command - and runs on the coding model, thinking low. Nor
|
|
255
328
|
// is the diagnosis: a post-mortem of a job that failed, read by the person - it runs on the coding model, thinking medium.
|
|
256
329
|
const CHAT_SIDE = ["chat", "sentinel", "planner"];
|
|
257
330
|
function isThinkingLevel(value) {
|
|
@@ -314,7 +387,7 @@ export function projectModels(config) {
|
|
|
314
387
|
* when the project names none.
|
|
315
388
|
*/
|
|
316
389
|
export function skillModel(root, role = "harness") {
|
|
317
|
-
return modelSpec(projectModels(readProjectConfig(root,
|
|
390
|
+
return modelSpec(projectModels(readProjectConfig(root, configModuleOf(root)))[role]);
|
|
318
391
|
}
|
|
319
392
|
/** A role entry's model and thinking alone. */
|
|
320
393
|
function choiceOf(entry) {
|
|
@@ -401,7 +474,7 @@ export const CONFIG_KEYS = {
|
|
|
401
474
|
review: "review",
|
|
402
475
|
mutationTesting: "mutation-testing",
|
|
403
476
|
allowToStopJobs: "allow-to-stop-jobs",
|
|
404
|
-
|
|
477
|
+
launchAfterPulse: "launch-after-pulse",
|
|
405
478
|
sentinel: "sentinel",
|
|
406
479
|
testDir: "test-dir",
|
|
407
480
|
conformanceTests: "conformance-tests",
|
|
@@ -430,17 +503,19 @@ function text(value) {
|
|
|
430
503
|
return typeof value === "string" && value.trim() !== "" ? value.trim() : undefined;
|
|
431
504
|
}
|
|
432
505
|
/**
|
|
433
|
-
* The project's config - with a
|
|
506
|
+
* The project's config - with a module's own file over it, when one is named - or nothing of it when there is no file or it does
|
|
434
507
|
* not parse.
|
|
435
508
|
*/
|
|
436
|
-
export function readProjectConfig(root,
|
|
437
|
-
return withRunOverrides(
|
|
509
|
+
export function readProjectConfig(root, module) {
|
|
510
|
+
return withRunOverrides(readLayeredConfig(root, module));
|
|
438
511
|
}
|
|
439
|
-
function
|
|
512
|
+
function readLayeredConfig(root, module) {
|
|
513
|
+
// A key turri has renamed, renamed in the files as they are first read.
|
|
514
|
+
renameOldKeys(root);
|
|
440
515
|
const project = readConfigFile(join(root, projectConfigFile(root)));
|
|
441
|
-
if (
|
|
516
|
+
if (module === undefined)
|
|
442
517
|
return project;
|
|
443
|
-
const own = readConfigFile(join(root,
|
|
518
|
+
const own = readConfigFile(join(root, moduleConfigFileIn(root, module)));
|
|
444
519
|
// The project's alone: one conversation, one module built when none is named.
|
|
445
520
|
const merged = { ...project };
|
|
446
521
|
for (const key of Object.keys(CONFIG_KEYS)) {
|
|
@@ -522,39 +597,55 @@ function withoutUndefined(config) {
|
|
|
522
597
|
}
|
|
523
598
|
/** Where the test plain files are when `test-dir:` does not say. */
|
|
524
599
|
export const DEFAULT_TEST_DIR = "tests";
|
|
525
|
-
/** The folder of a module's project's test plain files: `test-dir:` - its
|
|
600
|
+
/** The folder of a module's project's test plain files: `test-dir:` - its own file's over the project's - from the project's folder. */
|
|
526
601
|
export function testDirOf(plainFile) {
|
|
527
602
|
return resolve(projectDirOf(resolve(plainFile)), configForSpec(plainFile).testDir ?? DEFAULT_TEST_DIR);
|
|
528
603
|
}
|
|
529
|
-
/** The config a spec is built with: its project's, with its module's
|
|
604
|
+
/** The config a spec is built with: its project's, with its module's own file over it - or a required module's (`configModuleFor`). */
|
|
530
605
|
export function configForSpec(plainFile) {
|
|
531
606
|
const root = projectDirOf(resolve(plainFile));
|
|
532
|
-
|
|
607
|
+
// Two module files among the modules it requires: the project's alone, read as anything reads it - the parse, and
|
|
608
|
+
// every call that would build the module, refuse it with why (`configModuleFor`).
|
|
609
|
+
let module;
|
|
610
|
+
try {
|
|
611
|
+
module = configModuleFor(plainFile);
|
|
612
|
+
}
|
|
613
|
+
catch {
|
|
614
|
+
module = undefined;
|
|
615
|
+
}
|
|
616
|
+
return readProjectConfig(root, module);
|
|
533
617
|
}
|
|
534
618
|
/**
|
|
535
619
|
* One config file, read, or nothing of it when it is not there or does not parse. Parsed again only once the file has
|
|
536
|
-
* changed - its size or its modification time - and each caller given its own copy.
|
|
620
|
+
* changed - its size or its modification time - and each caller given its own copy. A file modified less than a second
|
|
621
|
+
* before it was read is read again each time, as git treats a racily clean file: written again within the same tick of
|
|
622
|
+
* the file system's clock - milliseconds on Linux - and to the same size, its stamp would not change.
|
|
537
623
|
*/
|
|
538
624
|
export function readConfigFile(path) {
|
|
539
625
|
let stamp;
|
|
626
|
+
let modified;
|
|
540
627
|
try {
|
|
541
628
|
const stat = statSync(path);
|
|
542
629
|
if (!stat.isFile())
|
|
543
630
|
return {};
|
|
544
631
|
stamp = `${stat.size}:${stat.mtimeMs}:${stat.ino}`;
|
|
632
|
+
modified = stat.mtimeMs;
|
|
545
633
|
}
|
|
546
634
|
catch {
|
|
547
635
|
return {};
|
|
548
636
|
}
|
|
549
637
|
const kept = keptConfigs.get(path);
|
|
550
|
-
if (kept !== undefined && kept.stamp === stamp)
|
|
638
|
+
if (kept !== undefined && kept.stamp === stamp && modified < kept.readAt - RACY_MS)
|
|
551
639
|
return structuredClone(kept.config);
|
|
640
|
+
const readAt = Date.now();
|
|
552
641
|
const config = readConfigFileNow(path);
|
|
553
|
-
keptConfigs.set(path, { stamp, config });
|
|
642
|
+
keptConfigs.set(path, { stamp, config, readAt });
|
|
554
643
|
if (keptConfigs.size > 64)
|
|
555
644
|
keptConfigs.delete(keptConfigs.keys().next().value);
|
|
556
645
|
return structuredClone(config);
|
|
557
646
|
}
|
|
647
|
+
/** How long before it was read a config file must have last changed for its stamp to be trusted. */
|
|
648
|
+
const RACY_MS = 1_000;
|
|
558
649
|
const keptConfigs = new Map();
|
|
559
650
|
function readConfigFileNow(path) {
|
|
560
651
|
let parsed;
|
|
@@ -575,7 +666,7 @@ function readConfigFileNow(path) {
|
|
|
575
666
|
review: typeof raw[CONFIG_KEYS.review] === "boolean" ? raw[CONFIG_KEYS.review] : undefined,
|
|
576
667
|
mutationTesting: typeof raw[CONFIG_KEYS.mutationTesting] === "boolean" ? raw[CONFIG_KEYS.mutationTesting] : undefined,
|
|
577
668
|
allowToStopJobs: typeof raw[CONFIG_KEYS.allowToStopJobs] === "boolean" ? raw[CONFIG_KEYS.allowToStopJobs] : undefined,
|
|
578
|
-
|
|
669
|
+
launchAfterPulse: typeof raw[CONFIG_KEYS.launchAfterPulse] === "boolean" ? raw[CONFIG_KEYS.launchAfterPulse] : undefined,
|
|
579
670
|
sentinel: typeof raw[CONFIG_KEYS.sentinel] === "boolean" || raw[CONFIG_KEYS.sentinel] === "ask" ? raw[CONFIG_KEYS.sentinel] : undefined,
|
|
580
671
|
testDir: text(raw[CONFIG_KEYS.testDir]),
|
|
581
672
|
conformanceTests: typeof raw[CONFIG_KEYS.conformanceTests] === "boolean" ? raw[CONFIG_KEYS.conformanceTests] : undefined,
|
|
@@ -608,3 +699,59 @@ function readConfigFileNow(path) {
|
|
|
608
699
|
turnLimit: turnLimitSetting(raw[CONFIG_KEYS.turnLimit]),
|
|
609
700
|
};
|
|
610
701
|
}
|
|
702
|
+
/** Keys a config file is read for besides CONFIG_KEYS: the older spellings turri still takes. */
|
|
703
|
+
const OLDER_KEYS = ["model", "turn_limit"];
|
|
704
|
+
/**
|
|
705
|
+
* The keys of the project's own config files - config.turri.yaml and each module's - that turri reads nothing of: a setting
|
|
706
|
+
* turri no longer has (`test-advisor`), or one misspelt. Said as turri starts, so a setting the person thinks is on is
|
|
707
|
+
* not silently ignored. config.yaml is left out: it may be another tool's, with keys of its own.
|
|
708
|
+
*/
|
|
709
|
+
export function unknownConfigKeys(root) {
|
|
710
|
+
// An old name of a renamed key is said on a line of its own (configLines), not as a key turri does not read.
|
|
711
|
+
const known = new Set([...Object.values(CONFIG_KEYS), ...OLDER_KEYS, ...Object.keys(RENAMED_KEYS)]);
|
|
712
|
+
const found = [];
|
|
713
|
+
for (const file of namesIn(root).filter((name) => /^config\.turri(\.[^.]+)?\.yaml$/.test(name)).sort()) {
|
|
714
|
+
let parsed;
|
|
715
|
+
try {
|
|
716
|
+
parsed = loadYaml(readFileSync(join(root, file), "utf8"));
|
|
717
|
+
}
|
|
718
|
+
catch {
|
|
719
|
+
continue;
|
|
720
|
+
}
|
|
721
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed))
|
|
722
|
+
continue;
|
|
723
|
+
const keys = Object.keys(parsed).filter((key) => !known.has(key));
|
|
724
|
+
if (keys.length > 0)
|
|
725
|
+
found.push({ file, keys });
|
|
726
|
+
}
|
|
727
|
+
return found;
|
|
728
|
+
}
|
|
729
|
+
/**
|
|
730
|
+
* The banner's lines for the project's config files: each key turri renamed in them this process, each old name left
|
|
731
|
+
* beside its new one - doing nothing - and each file with keys turri does not read.
|
|
732
|
+
*/
|
|
733
|
+
export function configLines(root) {
|
|
734
|
+
const renamed = renameOldKeys(root).map(({ file, from, to }) => ({ kind: "renamed", file, text: `${file}: ${from} is called ${to} now - turri renamed it there, its value kept.` }));
|
|
735
|
+
const left = [];
|
|
736
|
+
for (const file of namesIn(root).filter((name) => /^config\.turri(\.[^.]+)?\.yaml$/.test(name)).sort()) {
|
|
737
|
+
let parsed;
|
|
738
|
+
try {
|
|
739
|
+
parsed = loadYaml(readFileSync(join(root, file), "utf8"));
|
|
740
|
+
}
|
|
741
|
+
catch {
|
|
742
|
+
continue;
|
|
743
|
+
}
|
|
744
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed))
|
|
745
|
+
continue;
|
|
746
|
+
for (const [from, to] of Object.entries(RENAMED_KEYS)) {
|
|
747
|
+
if (from in parsed && to in parsed)
|
|
748
|
+
left.push({ kind: "old-beside-new", file, text: `${file} has ${from}, the old name of ${to}, which it sets too: ${from} does nothing - take it out.` });
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
const unknown = unknownConfigKeys(root).map(({ file, keys }) => ({
|
|
752
|
+
kind: "unknown",
|
|
753
|
+
file,
|
|
754
|
+
text: `${file} has ${keys.length === 1 ? "a key" : "keys"} turri does not read - ${keys.join(", ")}: no setting turri has, so ${keys.length === 1 ? "it does" : "they do"} nothing. Take ${keys.length === 1 ? "it" : "them"} out, or see docs/config.md for the spelling.`,
|
|
755
|
+
}));
|
|
756
|
+
return [...renamed, ...left, ...unknown];
|
|
757
|
+
}
|
package/dist/conform-cli.js
CHANGED
|
@@ -7,23 +7,33 @@ as module:func-id, or every one with scenarios - on the code as it is built, as
|
|
|
7
7
|
exactly their conformance and acceptance scenarios, following the spec's test reqs, with the whole suite
|
|
8
8
|
the module inherits, a failure fixed in the test or the code, whichever is wrong. A functional spec with
|
|
9
9
|
no scenarios is refused: write them first. So is a module with no test reqs, or no conformance testing
|
|
10
|
-
script
|
|
11
|
-
as far as the size guardrail lets.
|
|
10
|
+
script: the refusal names the next step. Every functional spec tested goes in one pulse,
|
|
11
|
+
as far as the size guardrail lets. A functional spec named whose tests are written has them written
|
|
12
|
+
again: deleted and written anew from its scenarios, its code untouched.
|
|
12
13
|
|
|
13
14
|
--one-by-one a pulse a functional spec instead
|
|
15
|
+
--from-scratch take out the tests folder where the module's code lives - the tip of its chain - (its
|
|
16
|
+
lineage keeps it) and write the tests again, starting from a copy of the tests of the
|
|
17
|
+
module the tip requires; the code untouched
|
|
18
|
+
--from-scratch-chain the same, starting from nothing: every functional spec of the chain's tests written again
|
|
14
19
|
--harness-model <p/id> config.turri.yaml's harness-model for this run: the planner, a diagnosis
|
|
15
20
|
--coding-model <p/id> its coding-model, --model too: the agents that build
|
|
16
21
|
--judge-model <p/id> its judge-model: the judge and the test review
|
|
17
22
|
--review <true|false> its review: whether the code and its tests are reviewed once they pass
|
|
18
23
|
--build-dir <dir> as the run ends, export the code there (see turri regenerate --help)
|
|
19
24
|
--report <file.json> write a report of the run there (see turri regenerate --help)`;
|
|
20
|
-
const { positional, options } = parseArgs(process.argv.slice(2), ["--one-by-one"], USAGE, ["--build-dir", "--report", "--harness-model", "--judge-model", "--review"]);
|
|
25
|
+
const { positional, options } = parseArgs(process.argv.slice(2), ["--one-by-one", "--from-scratch", "--from-scratch-chain"], USAGE, ["--build-dir", "--report", "--harness-model", "--judge-model", "--review"]);
|
|
21
26
|
const { report, buildDir } = headlessOptions(options);
|
|
22
27
|
const [plainFile, ...funcIds] = positional;
|
|
23
28
|
if (plainFile === undefined) {
|
|
24
29
|
console.error(USAGE);
|
|
25
30
|
process.exit(1);
|
|
26
31
|
}
|
|
32
|
+
const scratch = options["from-scratch-chain"] !== undefined ? "chain" : options["from-scratch"] !== undefined ? "module" : undefined;
|
|
33
|
+
if (scratch !== undefined && funcIds.length > 0) {
|
|
34
|
+
console.error(`Name functional specs or --from-scratch${scratch === "chain" ? "-chain" : ""}, not both: from scratch writes every one of them again.`);
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
27
37
|
runLoop({
|
|
28
38
|
plainFile,
|
|
29
39
|
...(buildDir !== undefined ? { buildDir } : {}),
|
|
@@ -32,6 +42,7 @@ runLoop({
|
|
|
32
42
|
ask: (loop) => loop.conformance(plainFile, {
|
|
33
43
|
...(funcIds.length > 0 ? { funcIds } : {}),
|
|
34
44
|
...(options["one-by-one"] !== undefined ? { separately: true } : {}),
|
|
45
|
+
...(scratch !== undefined ? { fromScratch: scratch } : {}),
|
|
35
46
|
}),
|
|
36
47
|
}).catch((error) => {
|
|
37
48
|
console.error(error instanceof Error ? error.message : error);
|