@nodii/dev 0.6.54 → 0.6.55
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 +1 -1
- package/dist/cli.js +4 -2
- package/dist/core.js +1 -1
- package/dist/tune.js +87 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -142,7 +142,7 @@ nodii-dev rules show CLAUSE_ID
|
|
|
142
142
|
nodii-dev gather tune cases|runs
|
|
143
143
|
nodii-dev gather tune replay CASE_ID
|
|
144
144
|
nodii-dev gather tune start --cases all|ID,ID --corpus-ref REF [--pickers P,Q] [--trigger T] [--settings JSON]
|
|
145
|
-
nodii-dev gather tune exec RUN_ID [--pickers shortlist-only,gemma-e4b,gemma-12b,gemma-26b]
|
|
145
|
+
nodii-dev gather tune exec RUN_ID [--pickers shortlist-only,gemma-e4b,gemma-12b,gemma-26b] [--concurrency N] # resumable
|
|
146
146
|
nodii-dev gather tune trial RUN_ID --case ID --picker P --iteration N [--documents A,B]
|
|
147
147
|
nodii-dev gather tune finalize RUN_ID [--supersedes RUN_ID --reason TEXT]
|
|
148
148
|
nodii-dev gather tune missed [--document CODE] [--since ISO]
|
package/dist/cli.js
CHANGED
|
@@ -177,9 +177,11 @@ Usage: nodii-dev <command> [options] [--json]
|
|
|
177
177
|
gather tune replay <case-id> # blind replay + trigger shortlist, for the lane-agent picker
|
|
178
178
|
gather tune start --cases all|ID,ID --corpus-ref REF [--pickers P,Q] [--trigger manual] [--settings JSON]
|
|
179
179
|
# --pickers: the subset this run scores (default all five)
|
|
180
|
-
gather tune exec <run-id> [--pickers shortlist-only,gemma-e4b,gemma-12b,gemma-26b]
|
|
180
|
+
gather tune exec <run-id> [--pickers shortlist-only,gemma-e4b,gemma-12b,gemma-26b] [--concurrency N]
|
|
181
181
|
# runs each automatic picker the run scores 5x per case; a Gemma
|
|
182
|
-
# model this Mac lacks is reported unavailable (exit 1), never filled in
|
|
182
|
+
# model this Mac lacks is reported unavailable (exit 1), never filled in;
|
|
183
|
+
# resumable: a rerun skips the trials an earlier exec recorded;
|
|
184
|
+
# --concurrency 1-8 (default 4) for shortlist-only, Gemma runs 1 at a time
|
|
183
185
|
gather tune trial <run-id> --case ID --picker P --iteration N [--documents A,B]
|
|
184
186
|
# one trial; lane-agent passes its own --documents pick
|
|
185
187
|
gather tune finalize <run-id> [--supersedes <run-id> --reason TEXT]
|
package/dist/core.js
CHANGED
|
@@ -4,7 +4,7 @@ import { chmod, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
|
4
4
|
import { homedir, platform } from "node:os";
|
|
5
5
|
import { dirname, join } from "node:path";
|
|
6
6
|
|
|
7
|
-
export const VERSION = "0.6.
|
|
7
|
+
export const VERSION = "0.6.55";
|
|
8
8
|
export const configPath = () =>
|
|
9
9
|
process.env.NODII_DEV_CONFIG_PATH ??
|
|
10
10
|
join(homedir(), ".config/nodii-dev/config.json");
|
package/dist/tune.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { appendFile, mkdir, readFile } from "node:fs/promises";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
1
4
|
import { CliError, devRequest, encode, query } from "./core.js";
|
|
2
5
|
import { GATHER_TIMEOUT_MS, TUNING_MODELS, gatherText, pickDocuments, warmPicker } from "./gather.js";
|
|
3
6
|
|
|
@@ -10,6 +13,12 @@ export const TUNING_PICKERS = ["shortlist-only", "lane-agent", "gemma-e4b", "gem
|
|
|
10
13
|
export const TUNING_REPEATS = 5;
|
|
11
14
|
const TRIGGERS = ["setup", "trigger_change", "document_change", "missed_trigger", "manual"];
|
|
12
15
|
const SECTION_LIMIT = 3;
|
|
16
|
+
// exec runs a server-bound picker's trials this many at a time by default
|
|
17
|
+
// (AH-20: one at a time, 150 shortlist-only trials outlast a 10-minute
|
|
18
|
+
// session limit). A local Gemma picker always runs one at a time: one model
|
|
19
|
+
// in Ollama's memory, and its pick latency is part of what tuning measures.
|
|
20
|
+
const EXEC_CONCURRENCY = 4;
|
|
21
|
+
const MAX_EXEC_CONCURRENCY = 8;
|
|
13
22
|
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
14
23
|
|
|
15
24
|
const list = (value) => String(value ?? "").split(",").map((x) => x.trim()).filter(Boolean);
|
|
@@ -41,6 +50,13 @@ function pickersFlag(value) {
|
|
|
41
50
|
return pickers;
|
|
42
51
|
}
|
|
43
52
|
|
|
53
|
+
function concurrencyFlag(value) {
|
|
54
|
+
if (value === undefined) return EXEC_CONCURRENCY;
|
|
55
|
+
const n = Number(value);
|
|
56
|
+
if (!Number.isInteger(n) || n < 1 || n > MAX_EXEC_CONCURRENCY) throw new CliError("USAGE", `--concurrency must be a whole number from 1 to ${MAX_EXEC_CONCURRENCY}`, 2);
|
|
57
|
+
return n;
|
|
58
|
+
}
|
|
59
|
+
|
|
44
60
|
function iterationFlag(value) {
|
|
45
61
|
const n = Number(value);
|
|
46
62
|
if (!Number.isInteger(n) || n < 1 || n > TUNING_REPEATS) throw new CliError("USAGE", `--iteration needs a whole number from 1 to ${TUNING_REPEATS}`, 2);
|
|
@@ -226,6 +242,41 @@ export async function runTrial(replay, picker, { request = devRequest, corpus =
|
|
|
226
242
|
}
|
|
227
243
|
}
|
|
228
244
|
|
|
245
|
+
export const tuningProgressDir = (env = process.env) => env.NODII_DEV_TUNING_DIR || join(homedir(), ".cache", "nodii-dev", "tuning");
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* The trials exec has had Dev accept for one run, one JSON line each, so a
|
|
249
|
+
* rerun after a kill resumes instead of starting over. Dev's trial PUT is
|
|
250
|
+
* idempotent: a lost or unreadable line only means that trial is run again,
|
|
251
|
+
* never that a trial is skipped without Dev holding it.
|
|
252
|
+
*/
|
|
253
|
+
export function tuningProgress(runId, dir = tuningProgressDir()) {
|
|
254
|
+
const path = join(dir, `${runId}.jsonl`);
|
|
255
|
+
const key = (picker, caseId, iteration) => `${picker}\u0000${caseId}\u0000${iteration}`;
|
|
256
|
+
const done = new Set();
|
|
257
|
+
return {
|
|
258
|
+
path,
|
|
259
|
+
async load() {
|
|
260
|
+
let text = "";
|
|
261
|
+
try { text = await readFile(path, "utf8"); }
|
|
262
|
+
catch (error) { if (error.code !== "ENOENT") throw error; }
|
|
263
|
+
for (const line of text.split("\n")) {
|
|
264
|
+
if (!line.trim()) continue;
|
|
265
|
+
try {
|
|
266
|
+
const x = JSON.parse(line);
|
|
267
|
+
done.add(key(x.picker, x.caseId, x.iteration));
|
|
268
|
+
} catch { /* a torn last line: that trial runs again */ }
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
has: (picker, caseId, iteration) => done.has(key(picker, caseId, iteration)),
|
|
272
|
+
async add(picker, caseId, iteration) {
|
|
273
|
+
await mkdir(dir, { recursive: true });
|
|
274
|
+
await appendFile(path, `${JSON.stringify({ picker, caseId, iteration, at: new Date().toISOString() })}\n`);
|
|
275
|
+
done.add(key(picker, caseId, iteration));
|
|
276
|
+
},
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
|
|
229
280
|
async function runCases(request, id) {
|
|
230
281
|
const runs = (await request("GET", "/api/v1/gather/tuning/runs")).data ?? [];
|
|
231
282
|
const run = runs.find((x) => x.id === id);
|
|
@@ -250,9 +301,11 @@ function execText(payload) {
|
|
|
250
301
|
const d = payload.data;
|
|
251
302
|
const lines = [`Tuning run ${d.runId}: ${d.cases} case${d.cases === 1 ? "" : "s"} × ${TUNING_REPEATS} repeats`];
|
|
252
303
|
for (const p of d.pickers) {
|
|
253
|
-
|
|
254
|
-
|
|
304
|
+
const resumed = p.resumed ? ` (${p.resumed} from an earlier exec)` : "";
|
|
305
|
+
if (p.status === "recorded") lines.push(` ${p.picker.padEnd(15)}recorded ${p.recorded}/${p.expected}${resumed}`);
|
|
306
|
+
else lines.push(` ${p.picker.padEnd(15)}${p.status.toUpperCase()}${p.recorded ? ` after ${p.recorded}/${p.expected}${resumed}` : ""}: ${p.reason}`);
|
|
255
307
|
}
|
|
308
|
+
if (!d.complete && d.pickers.some((p) => p.recorded)) lines.push(`Rerun the same exec to resume: trials already recorded are skipped (${d.progress}).`);
|
|
256
309
|
lines.push(d.complete
|
|
257
310
|
? `All requested pickers recorded. Finalize once every picker is in: nodii-dev gather tune finalize ${d.runId}`
|
|
258
311
|
: "The matrix is not complete; Dev's finalize refuses a partial run. Nothing was faked for the pickers above.");
|
|
@@ -284,7 +337,7 @@ function missedText({ data }) {
|
|
|
284
337
|
* client for Dev's Gather tuning API (AH-11). Scoring is Dev's; the CLI only
|
|
285
338
|
* runs the pickers and assembles each trial's Clause map read-only.
|
|
286
339
|
*/
|
|
287
|
-
export async function tuneCommand(action, args, flags, { request = devRequest, pick = pickDocuments, warm = warmPicker, corpus } = {}) {
|
|
340
|
+
export async function tuneCommand(action, args, flags, { request = devRequest, pick = pickDocuments, warm = warmPicker, corpus, progressDir } = {}) {
|
|
288
341
|
// DEV-REV-18: clauses a review cited that Gather never served the lane.
|
|
289
342
|
if (action === "missed") {
|
|
290
343
|
for (const flag of ["document", "since"])
|
|
@@ -369,30 +422,51 @@ export async function tuneCommand(action, args, flags, { request = devRequest, p
|
|
|
369
422
|
if (action === "exec") {
|
|
370
423
|
const runId = uuid(args[0], "<run-id>");
|
|
371
424
|
const requested = flags.pickers === undefined ? null : pickersFlag(flags.pickers);
|
|
425
|
+
const concurrency = concurrencyFlag(flags.concurrency);
|
|
372
426
|
if (requested?.includes("lane-agent")) throw new CliError("USAGE", "the lane-agent picker is the agent itself: record each pick with `gather tune trial --picker lane-agent`", 2);
|
|
373
427
|
const { cases, pickers: runPickers } = await runCases(request, runId);
|
|
374
428
|
const outside = (requested ?? []).filter((picker) => !runPickers.includes(picker));
|
|
375
429
|
if (outside.length) throw new CliError("TUNING_TRIAL_OUTSIDE_MATRIX", `run ${runId} scores ${runPickers.join(", ")}, not ${outside.join(", ")}`, 1);
|
|
376
430
|
// By default, every automatic picker the run scores.
|
|
377
431
|
const pickers = requested ?? runPickers.filter((picker) => picker !== "lane-agent");
|
|
432
|
+
const progress = tuningProgress(runId, progressDir);
|
|
433
|
+
await progress.load();
|
|
378
434
|
const shared = corpus ?? tuningCorpus(request);
|
|
379
435
|
const replays = new Map();
|
|
380
|
-
const replayOf =
|
|
381
|
-
if (!replays.has(caseId)) replays.set(caseId,
|
|
436
|
+
const replayOf = (caseId) => {
|
|
437
|
+
if (!replays.has(caseId)) replays.set(caseId, request("GET", `/api/v1/gather/tuning/cases/${encode(caseId)}/replay`).then((x) => x.data));
|
|
382
438
|
return replays.get(caseId);
|
|
383
439
|
};
|
|
384
440
|
const results = [];
|
|
385
441
|
for (const picker of pickers) {
|
|
386
|
-
const result = { picker, status: "recorded", recorded: 0, expected: cases.length * TUNING_REPEATS };
|
|
442
|
+
const result = { picker, status: "recorded", recorded: 0, resumed: 0, expected: cases.length * TUNING_REPEATS };
|
|
387
443
|
results.push(result);
|
|
444
|
+
const pending = [];
|
|
445
|
+
for (const caseId of cases)
|
|
446
|
+
for (let iteration = 1; iteration <= TUNING_REPEATS; iteration++)
|
|
447
|
+
if (progress.has(picker, caseId, iteration)) result.resumed++;
|
|
448
|
+
else pending.push({ caseId, iteration });
|
|
449
|
+
result.recorded = result.resumed;
|
|
450
|
+
if (!pending.length) continue;
|
|
388
451
|
try {
|
|
389
452
|
if (TUNING_MODELS[picker]) await warm({ model: TUNING_MODELS[picker] });
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
453
|
+
// Workers take trials in order; the first failure stops new trials and
|
|
454
|
+
// is raised once the ones in flight settle, so each recorded trial is noted.
|
|
455
|
+
let failure;
|
|
456
|
+
const worker = async () => {
|
|
457
|
+
while (!failure && pending.length) {
|
|
458
|
+
const { caseId, iteration } = pending.shift();
|
|
459
|
+
try {
|
|
460
|
+
const trial = await runTrial(await replayOf(caseId), picker, { request, pick, corpus: shared });
|
|
461
|
+
await putTrial(request, runId, trial, iteration);
|
|
462
|
+
await progress.add(picker, caseId, iteration);
|
|
463
|
+
result.recorded++;
|
|
464
|
+
} catch (error) { failure ??= error; }
|
|
395
465
|
}
|
|
466
|
+
};
|
|
467
|
+
const width = TUNING_MODELS[picker] ? 1 : concurrency;
|
|
468
|
+
await Promise.all(Array.from({ length: Math.min(width, pending.length) }, worker));
|
|
469
|
+
if (failure) throw failure;
|
|
396
470
|
} catch (error) {
|
|
397
471
|
// A Gemma picker this Mac cannot run is reported, not filled in; any
|
|
398
472
|
// other failure is a real error and stops the run.
|
|
@@ -401,7 +475,7 @@ export async function tuneCommand(action, args, flags, { request = devRequest, p
|
|
|
401
475
|
}
|
|
402
476
|
}
|
|
403
477
|
const complete = results.every((r) => r.status === "recorded");
|
|
404
|
-
return { payload: { data: { runId, cases: cases.length, complete, pickers: results } }, human: execText, exitCode: complete ? 0 : 1 };
|
|
478
|
+
return { payload: { data: { runId, cases: cases.length, complete, progress: progress.path, pickers: results } }, human: execText, exitCode: complete ? 0 : 1 };
|
|
405
479
|
}
|
|
406
480
|
if (action === "finalize") {
|
|
407
481
|
const runId = uuid(args[0], "<run-id>");
|
|
@@ -415,5 +489,5 @@ export async function tuneCommand(action, args, flags, { request = devRequest, p
|
|
|
415
489
|
const payload = await request("POST", `/api/v1/gather/tuning/runs/${encode(runId)}/finalize`, body);
|
|
416
490
|
return { payload, human: (p) => summaryText(p.data) };
|
|
417
491
|
}
|
|
418
|
-
throw new CliError("USAGE", "gather tune missed [--document CODE] [--since ISO]|cases|replay <case-id>|start --cases all|ID,ID --corpus-ref REF [--pickers P,Q]|trial <run-id> --case ID --picker P --iteration N [--documents A,B]|exec <run-id> [--pickers P,Q]|finalize <run-id> [--supersedes <run-id> --reason TEXT]|runs", 2);
|
|
492
|
+
throw new CliError("USAGE", "gather tune missed [--document CODE] [--since ISO]|cases|replay <case-id>|start --cases all|ID,ID --corpus-ref REF [--pickers P,Q]|trial <run-id> --case ID --picker P --iteration N [--documents A,B]|exec <run-id> [--pickers P,Q] [--concurrency N]|finalize <run-id> [--supersedes <run-id> --reason TEXT]|runs", 2);
|
|
419
493
|
}
|