bareloop 0.47.1 → 0.49.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +56 -0
- package/README.md +16 -9
- package/bareloop.context.md +70 -46
- package/bin/bareloop.mjs +2 -0
- package/package.json +3 -3
- package/src/bundle.js +36 -9
- package/src/bundleref.js +103 -0
- package/src/bundlerun.js +134 -17
- package/src/cli.js +138 -144
- package/src/config.js +1 -1
- package/src/draftspend.js +88 -34
- package/src/facts.js +1 -1
- package/src/interviewrun.js +11 -11
- package/src/invoke.js +3 -2
- package/src/launcher.js +122 -12
- package/src/learn.js +34 -20
- package/src/learnstore.js +30 -14
- package/src/pagedropwords.js +1 -0
- package/src/pagedry.js +77 -6
- package/src/pagemap.js +17 -3
- package/src/pagerules.js +2 -1
- package/src/panel/authorsession.js +7 -13
- package/src/panel/index.html +30 -7
- package/src/panel/runroutes.js +28 -14
- package/src/panel/server.js +69 -118
- package/src/prompts.js +50 -0
- package/src/reuse.js +1 -1
- package/src/runexport.js +162 -0
- package/src/runfiles.js +65 -0
- package/src/runlist.js +72 -0
- package/src/userrun.js +17 -13
- package/types/bundle.d.ts +16 -0
- package/types/bundleref.d.ts +63 -0
- package/types/bundlerun.d.ts +10 -3
- package/types/cli.d.ts +2 -1
- package/types/draftspend.d.ts +7 -23
- package/types/launcher.d.ts +67 -2
- package/types/learn.d.ts +29 -15
- package/types/learnstore.d.ts +31 -10
- package/types/pagedry.d.ts +26 -0
- package/types/pagemap.d.ts +1 -0
- package/types/panel/server.d.ts +7 -3
- package/types/prompts.d.ts +21 -0
- package/types/reuse.d.ts +3 -0
- package/types/runexport.d.ts +58 -0
- package/types/runfiles.d.ts +40 -0
- package/types/runlist.d.ts +55 -0
package/src/runfiles.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// The files that sit beside a run's spine, found the one way (panel and CLI both ask here): the source
|
|
2
|
+
// door's manifest, and the signed spec the run's latest leg ran under. Moved out of src/panel/server.js so
|
|
3
|
+
// `bareloop export` and the panel share ONE spelling (PRD v1.114). Pure reads, $0.
|
|
4
|
+
|
|
5
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
6
|
+
import { basename, dirname, join } from 'node:path';
|
|
7
|
+
import { legsOf } from './legs.js';
|
|
8
|
+
import { jobSpecHash } from './job.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* `<out>/source-<seed>/<job>-bareloop/u-<runid>.jsonl` -> the two files an
|
|
12
|
+
* authoring session leaves BESIDE that layout — `<out>/resolved-spec.json`
|
|
13
|
+
* (the signed spec `--spec`/a JOBS-table row ran) and
|
|
14
|
+
* `<out>/source-<seed>/source.json` (the source front door's manifest) —
|
|
15
|
+
* verified against `src/userrun.js`'s own construction (`specWorkdir = join(into,
|
|
16
|
+
* 'tree')`, `spineDir = join(wd, '..', target.spine)`, both `--spec` and the
|
|
17
|
+
* `pulselog-person-strict` JOBS-table row read `into` the same way) and a real
|
|
18
|
+
* archived run (pulselog-person-live-2, run mu2p83go): `dirname(spine)` is
|
|
19
|
+
* `<into>/<job>-bareloop`, `dirname(dirname(spine))` is `<into>` itself
|
|
20
|
+
* (`source-<seed>`, carrying `source.json`), and `dirname(dirname(dirname(spine)))`
|
|
21
|
+
* is `<out>` (carrying `resolved-spec.json`).
|
|
22
|
+
*
|
|
23
|
+
* Only resolves when `<into>`'s own name starts with `source-` — the one
|
|
24
|
+
* shape marker this convention always carries — and each file is checked to
|
|
25
|
+
* actually exist before being handed back; any other spine layout (the bundle
|
|
26
|
+
* `spine.jsonl`, a JOBS-table row whose workdir has no source-seed copy, e.g.
|
|
27
|
+
* `litectx-u`) returns both fields `null`, never a guessed path (build spec
|
|
28
|
+
* item 2, 2026-09-25: "don't search the disk broadly — fall through").
|
|
29
|
+
* @param {string} spinePath
|
|
30
|
+
* @returns {{ specPath: string|null, sourceJsonPath: string|null }}
|
|
31
|
+
*/
|
|
32
|
+
export function sourceNearSpine(spinePath) {
|
|
33
|
+
const into = dirname(dirname(spinePath)); // <into>/<job>-bareloop/u-x.jsonl -> <into>
|
|
34
|
+
if (!basename(into).startsWith('source-')) return { specPath: null, sourceJsonPath: null };
|
|
35
|
+
const sourceJsonPath = join(into, 'source.json');
|
|
36
|
+
const specPath = join(dirname(into), 'resolved-spec.json'); // <into> -> <out>
|
|
37
|
+
return {
|
|
38
|
+
specPath: existsSync(specPath) ? specPath : null,
|
|
39
|
+
sourceJsonPath: existsSync(sourceJsonPath) ? sourceJsonPath : null,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The signed spec a run's LATEST leg ran under — the `resolved-spec*.json` beside the run whose hash is the one its
|
|
44
|
+
* latest `job-start` carries (the same lookup `resumePlanFor` does). `null` = no such file.
|
|
45
|
+
* @param {{ spine: string }} row
|
|
46
|
+
* @param {any[]} records
|
|
47
|
+
* @returns {{spec: any, specPath: string, specHash: string}|null}
|
|
48
|
+
*/
|
|
49
|
+
export function signedSpecForRun(row, records) {
|
|
50
|
+
const jobStart = (legsOf(records).findLast((l) => l.jobStart !== null) ?? null)?.jobStart ?? null;
|
|
51
|
+
if (!jobStart || typeof jobStart.specHash !== 'string') return null;
|
|
52
|
+
const near = sourceNearSpine(row.spine);
|
|
53
|
+
if (!near.specPath) return null;
|
|
54
|
+
const dir = dirname(near.specPath);
|
|
55
|
+
/** @type {string[]} */
|
|
56
|
+
let names = [];
|
|
57
|
+
try { names = readdirSync(dir).filter((n) => n === 'resolved-spec.json' || /^resolved-spec-r\d+\.json$/.test(n)); } catch { names = []; }
|
|
58
|
+
for (const n of names) {
|
|
59
|
+
let spec;
|
|
60
|
+
try { spec = JSON.parse(readFileSync(join(dir, n), 'utf8')); } catch { continue; }
|
|
61
|
+
if (!spec || typeof spec !== 'object') continue;
|
|
62
|
+
if (jobSpecHash(spec) === jobStart.specHash) return { spec, specPath: join(dir, n), specHash: jobStart.specHash };
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
}
|
package/src/runlist.js
CHANGED
|
@@ -164,6 +164,37 @@ export function readNeedsRemovals(opts = {}) {
|
|
|
164
164
|
return out;
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
+
/**
|
|
168
|
+
* @typedef {{ type: 'exported', runid: string, job: string, bundle: string, bundleHash: string, at: string }} ExportedRow
|
|
169
|
+
* RULED 2026-10-25 (PRD v1.114): `bareloop export` appends ONE of these per bundle it makes, so `bareloop run` can find the bundle by the
|
|
170
|
+
* run's name. Not a run, a claim or an event: {@link readRunList} ignores it (it has a `type`), so the monthly limit, the run counter and the
|
|
171
|
+
* scheduler never see it. Nothing is rewritten.
|
|
172
|
+
*/
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Append one {@link ExportedRow}. THROWS on IO failure.
|
|
176
|
+
* @param {Omit<ExportedRow, 'type'>} row
|
|
177
|
+
* @param {{ home?: string }} [opts]
|
|
178
|
+
* @returns {void}
|
|
179
|
+
*/
|
|
180
|
+
export function appendExported(row, opts = {}) {
|
|
181
|
+
const path = runlistPath(opts.home);
|
|
182
|
+
mkdirSync(runlistHome(opts.home), { recursive: true, mode: 0o700 });
|
|
183
|
+
appendFileSync(path, `${JSON.stringify({ ...row, type: 'exported' })}\n`);
|
|
184
|
+
try { chmodSync(path, 0o600); } catch { /* best-effort perms */ }
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Every `exported` row, in file order (a re-export of the same run is a later row). An absent file is an empty list.
|
|
189
|
+
* @param {{ home?: string }} [opts]
|
|
190
|
+
* @returns {ExportedRow[]}
|
|
191
|
+
*/
|
|
192
|
+
export function readExported(opts = {}) {
|
|
193
|
+
const path = runlistPath(opts.home);
|
|
194
|
+
if (!existsSync(path)) return [];
|
|
195
|
+
return parseJsonl(path).records.filter((r) => r && r.type === 'exported' && typeof r.bundle === 'string' && typeof r.runid === 'string');
|
|
196
|
+
}
|
|
197
|
+
|
|
167
198
|
/**
|
|
168
199
|
* @typedef {{ type: 'leg-start', runid: string, leg: number, pid?: number, capUsd?: number, at: string }} LegStart
|
|
169
200
|
* A resumed run's NEW claim (P5-R, hamr 2026-10-02: one run, one id, one row): appended beside the run's row
|
|
@@ -483,3 +514,44 @@ export function formatRunRow(row) {
|
|
|
483
514
|
const missing = existsSync(row.spine) ? '' : ' — file missing';
|
|
484
515
|
return `${row.job} (${row.runid}) · ${date} · ${row.spine}${missing}`;
|
|
485
516
|
}
|
|
517
|
+
|
|
518
|
+
/**
|
|
519
|
+
* @param {any} r
|
|
520
|
+
* @returns {number}
|
|
521
|
+
*/
|
|
522
|
+
export function atMs(r) {
|
|
523
|
+
const t = typeof r?.at === 'string' ? Date.parse(r.at) : NaN;
|
|
524
|
+
return Number.isFinite(t) ? t : 0;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* A run's name for a person: `job (run-N)`, N from {@link runNumbers}. The ONE spelling (the panel, `bareloop export` and `bareloop run` all print it).
|
|
529
|
+
* @param {string} job @param {number|undefined} n
|
|
530
|
+
* @returns {string}
|
|
531
|
+
*/
|
|
532
|
+
export function runNameOf(job, n) { return `${job} (run-${n})`; }
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* The ONE owner of run names (P6 item 7): runs of the same job (`row.job`) are numbered oldest `at` first, 1-based
|
|
536
|
+
* (ties keep file order). A resume is one row, so it counts once; died and stopped runs are rows too. Every view
|
|
537
|
+
* reads this number — the page never counts on its own.
|
|
538
|
+
* @param {any[]} rows
|
|
539
|
+
* @returns {Map<string, number>} runid → N
|
|
540
|
+
*/
|
|
541
|
+
export function runNumbers(rows) {
|
|
542
|
+
/** @type {Map<string, any[]>} */
|
|
543
|
+
const byJob = new Map();
|
|
544
|
+
rows.forEach((row, index) => {
|
|
545
|
+
if (!row || typeof row.runid !== 'string') return;
|
|
546
|
+
const g = byJob.get(row.job) || [];
|
|
547
|
+
g.push({ row, index });
|
|
548
|
+
byJob.set(row.job, g);
|
|
549
|
+
});
|
|
550
|
+
/** @type {Map<string, number>} */
|
|
551
|
+
const out = new Map();
|
|
552
|
+
for (const g of byJob.values()) {
|
|
553
|
+
g.sort((a, b) => (atMs(a.row) - atMs(b.row)) || (a.index - b.index));
|
|
554
|
+
g.forEach(({ row }, i) => out.set(row.runid, i + 1));
|
|
555
|
+
}
|
|
556
|
+
return out;
|
|
557
|
+
}
|
package/src/userrun.js
CHANGED
|
@@ -32,7 +32,7 @@ import { commitWork, removeWorktree } from './worktree.js';
|
|
|
32
32
|
import { moveFile } from './movefile.js';
|
|
33
33
|
import { runJob } from './run.js';
|
|
34
34
|
import { moneyWithDraft } from './replay.js';
|
|
35
|
-
import { jobSpecHash, resolveWorkerModel, validateJob } from './job.js';
|
|
35
|
+
import { jobSpecHash, resolveWorkerModel, validateJob, workflowKey } from './job.js';
|
|
36
36
|
import { readShimArm } from './readshim.js';
|
|
37
37
|
import { closeStagesOf } from './plan.js';
|
|
38
38
|
import { resolveCloseTimeoutMs } from './closetimeout.js';
|
|
@@ -82,7 +82,7 @@ import { keysForDoor } from './keysfile.js';
|
|
|
82
82
|
import { parseJsonl } from './replayio.js';
|
|
83
83
|
import { claimRun, monthlyRefusalText, legSpend, chainSpend } from './monthly.js';
|
|
84
84
|
import { ConfigError } from './config.js';
|
|
85
|
-
import { learnAtRunEnd,
|
|
85
|
+
import { learnAtRunEnd, handedHints, releaseRun } from './learnstore.js';
|
|
86
86
|
import { commandFor } from './invoke.js';
|
|
87
87
|
import { judgeRatesFor, keyNameFor, keyValueOf, priceReadout, ratesFor, ratesOfLine, resolveWorker, judgeRowFor, rowsForHome, REFUSE_NAME_MODEL } from './providerrows.js';
|
|
88
88
|
// the banner's wall arithmetic, extracted so it is reachable by a test (F83): the
|
|
@@ -1906,7 +1906,10 @@ async function execute(ctx) {
|
|
|
1906
1906
|
/** @type {{text: string, ids: string[]}|null} */
|
|
1907
1907
|
let learnHints = null;
|
|
1908
1908
|
if (cfgOn) {
|
|
1909
|
-
|
|
1909
|
+
// an unreadable ledger hands nothing but is never silent: the reason rides a `learnings` spine record (hintsError) the Audit prints
|
|
1910
|
+
const handed = handedHints({ home: cfgHome, spec, workflowKey: workflowKey(spec) });
|
|
1911
|
+
learnHints = handed.hints;
|
|
1912
|
+
if (handed.error !== null) emit('learnings', { phase: 'draft', hintsError: handed.error });
|
|
1910
1913
|
}
|
|
1911
1914
|
let outcome;
|
|
1912
1915
|
try {
|
|
@@ -2033,7 +2036,7 @@ async function execute(ctx) {
|
|
|
2033
2036
|
try {
|
|
2034
2037
|
const filedAudit = ctx.bundle ? join(spineDir, 'gate-audit.jsonl') : join(spineDir, `u-${runid}-gate-audit.jsonl`);
|
|
2035
2038
|
learnAtRunEnd({
|
|
2036
|
-
home: cfgHome, runid, events: allEvents, auditFiles: [filedAudit, join(wd, 'gate-audit.jsonl')], spec, specHash, workdir: wd,
|
|
2039
|
+
home: cfgHome, runid, events: allEvents, auditFiles: [filedAudit, join(wd, 'gate-audit.jsonl')], spec, specHash, workflowKey: workflowKey(spec), workdir: wd,
|
|
2037
2040
|
trust: quarantinesCredit(spec.verdictType) ? 'rubric' : 'deterministic',
|
|
2038
2041
|
});
|
|
2039
2042
|
} catch (/** @type {any} */ e) { err(`WARNING: could not record this run's lessons in the learnings ledger (${redactSecrets(String(e?.message ?? e)).split('\n')[0]}) — the run itself is unaffected.`); }
|
|
@@ -2140,8 +2143,9 @@ async function execute(ctx) {
|
|
|
2140
2143
|
out(` trend ${mh.trend} — ${mh.reading}`);
|
|
2141
2144
|
if (ctx.bundle) {
|
|
2142
2145
|
// a bundle's spec is manifest-hashed: there is no budgetUsd to edit and no new hash to sign. The room that
|
|
2143
|
-
// is left is the signed ceiling, and the
|
|
2144
|
-
//
|
|
2146
|
+
// is left is the signed ceiling, and the way to use it is the person typing a larger --budget. Going PAST the
|
|
2147
|
+
// signed ceiling is allowed only with the person's own yes (hamr 2026-10-25), shown back and recorded in the run.
|
|
2148
|
+
// The exhausted --budget is never echoed (pasted as printed it halts again at once: the chain folds prior spend),
|
|
2145
2149
|
// and nothing is filled in for them.
|
|
2146
2150
|
const signed = ctx.bundle.signedBudgetUsd;
|
|
2147
2151
|
const spentUsd = typeof mh.budgetUsd === 'number' && typeof mh.remainingUsd === 'number' ? mh.budgetUsd - mh.remainingUsd : null;
|
|
@@ -2152,12 +2156,12 @@ async function execute(ctx) {
|
|
|
2152
2156
|
out(` lever ${lever}`);
|
|
2153
2157
|
if (spentUsd !== null && spentUsd >= signed) {
|
|
2154
2158
|
// the whole signed ceiling is spent: "more than spent, at most signed" is unsatisfiable, so no resume line is printed
|
|
2155
|
-
out(` · no room left under the signed ceiling: this run spent all of the signed $${signed}, and a bundle's ceiling
|
|
2159
|
+
out(` · no room left under the signed ceiling: this run spent all of the signed $${signed}, and raising a bundle's ceiling needs your typed yes (--yes)`);
|
|
2156
2160
|
out(' · abandon the task');
|
|
2157
2161
|
} else {
|
|
2158
|
-
out(` · choose a larger --budget on the resume line below (the room left is the signed $${signed}; it
|
|
2162
|
+
out(` · choose a larger --budget on the resume line below (the room left is the signed $${signed}; going past it asks you to type yes)`);
|
|
2159
2163
|
out(' · abandon the task');
|
|
2160
|
-
out(` resume ${ctx.bundle.invoke}${WALL_FLAG} --resume ${runid}${SHIM_TAIL}${SCOUT_TAIL}${DRAFT_TAIL}${REGISTRY_TAIL} --budget <more than ${spentTxt},
|
|
2164
|
+
out(` resume ${ctx.bundle.invoke}${WALL_FLAG} --resume ${runid}${SHIM_TAIL}${SCOUT_TAIL}${DRAFT_TAIL}${REGISTRY_TAIL} --budget <more than ${spentTxt}, above $${signed} asks you to type yes> --approve ${PRINT_APPROVE}`);
|
|
2161
2165
|
out(' (type the --budget number yourself — nothing here fills it in, so this line does not run as printed; nothing in the run may widen its own budget)');
|
|
2162
2166
|
}
|
|
2163
2167
|
} else {
|
|
@@ -2580,7 +2584,7 @@ export async function main(argv, deps = {}) {
|
|
|
2580
2584
|
if (!existsSync(specPath)) {
|
|
2581
2585
|
die(`--job ${jobArg}: there is no spec at ${specPath}.\n`
|
|
2582
2586
|
+ ' The table row is the runner\'s half of a job (patient, seed, spine); the SPEC is yours — authored through\n'
|
|
2583
|
-
+
|
|
2587
|
+
+ ' the panel\'s drafting (or node scripts/run-interview.mjs and node scripts/run-author.mjs), then signed. Nothing here can stand in for it: a job\n'
|
|
2584
2588
|
+ ' with no spec has no goal, no close, no budget and no hash to approve.');
|
|
2585
2589
|
}
|
|
2586
2590
|
try { spec = JSON.parse(readFileSync(specPath, 'utf8')); } catch (e) {
|
|
@@ -2592,7 +2596,7 @@ export async function main(argv, deps = {}) {
|
|
|
2592
2596
|
specPath = resolve(/** @type {string} */ (specArg));
|
|
2593
2597
|
if (!existsSync(specPath)) {
|
|
2594
2598
|
die(`--spec ${specPath} does not exist — a run needs the resolved-spec.json an authoring session actually wrote `
|
|
2595
|
-
+
|
|
2599
|
+
+ '(the panel\'s drafting session, or node scripts/run-author.mjs\'s own `out/resolved-spec.json`), never a path nobody authored');
|
|
2596
2600
|
}
|
|
2597
2601
|
let raw;
|
|
2598
2602
|
try { raw = readFileSync(specPath, 'utf8'); } catch (e) {
|
|
@@ -2632,8 +2636,8 @@ export async function main(argv, deps = {}) {
|
|
|
2632
2636
|
if (candidates.length === 0) {
|
|
2633
2637
|
die(`--spec ${specPath}: no prepared copy beside it — looked for a source-*/ directory carrying source.json in `
|
|
2634
2638
|
+ `${dirname(specPath)} and found none. A --spec run reads its workdir and seed off the copy the authoring `
|
|
2635
|
-
+ `session prepared; it is never typed or guessed. Prepare one first:
|
|
2636
|
-
+
|
|
2639
|
+
+ `session prepared; it is never typed or guessed. Prepare one first: draft the job in the panel (or node scripts/run-interview.mjs, `
|
|
2640
|
+
+ 'then node scripts/run-author.mjs against a --source) before running this spec.');
|
|
2637
2641
|
}
|
|
2638
2642
|
if (candidates.length > 1) {
|
|
2639
2643
|
die(`--spec ${specPath}: ${candidates.length} prepared copies sit beside it (${candidates.join(', ')}) — `
|
package/types/bundle.d.ts
CHANGED
|
@@ -120,6 +120,22 @@ export function checkEnvelope(spec: any, envelope?: {
|
|
|
120
120
|
ok: boolean;
|
|
121
121
|
reds: Red[];
|
|
122
122
|
};
|
|
123
|
+
/**
|
|
124
|
+
* The caps a typed envelope would RAISE above the bundle's signed ones (hamr 2026-10-25: a raise is allowed, but only signed by the
|
|
125
|
+
* person typing `yes` or passing `--yes`). Same fields and test as {@link checkEnvelope}'s widen red; a field the spec has no ceiling
|
|
126
|
+
* for cannot be raised. Pure.
|
|
127
|
+
* @param {any} spec the (already `$BARELOOP_BUNDLE`-resolved) bundle spec
|
|
128
|
+
* @param {{ budgetUsd?: number, maxWallMs?: number }} envelope
|
|
129
|
+
* @returns {{ field: 'budgetUsd'|'maxWallMs', old: number, new: number }[]}
|
|
130
|
+
*/
|
|
131
|
+
export function capRaises(spec: any, envelope?: {
|
|
132
|
+
budgetUsd?: number;
|
|
133
|
+
maxWallMs?: number;
|
|
134
|
+
}): {
|
|
135
|
+
field: "budgetUsd" | "maxWallMs";
|
|
136
|
+
old: number;
|
|
137
|
+
new: number;
|
|
138
|
+
}[];
|
|
123
139
|
/**
|
|
124
140
|
* Write `blessing.json`: the FIRST GREEN RUN on the importer's own machine
|
|
125
141
|
* signs the bundle as trustworthy (hamr Q2), so later runs need no
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every bundle on this machine the CLI knows, NEWEST FIRST, one per folder: the exported ones (the `exported` rows) and any bundle that
|
|
3
|
+
* has `bareloop run` rows (spine `<bundle>/runs/<runid>/spine.jsonl`). `label` = the run name (or the job) and the folder.
|
|
4
|
+
* @param {{ home?: string }} [opts]
|
|
5
|
+
* @returns {{ name: string, dir: string, label: string, atMs: number }[]}
|
|
6
|
+
*/
|
|
7
|
+
export function knownBundles(opts?: {
|
|
8
|
+
home?: string;
|
|
9
|
+
}): {
|
|
10
|
+
name: string;
|
|
11
|
+
dir: string;
|
|
12
|
+
label: string;
|
|
13
|
+
atMs: number;
|
|
14
|
+
}[];
|
|
15
|
+
/**
|
|
16
|
+
* The shared bundle question of `run` and `history`: show the last {@link RECENT_BUNDLES} bundles, newest first, numbered; then ask. A number
|
|
17
|
+
* picks one shown; a run name or a folder reaches an older one. None known: one plain line and the command ends.
|
|
18
|
+
* @param {{ ask: (q: string) => Promise<string>, out: (s: string) => void, home?: string, none: string, cancelled: string }} o
|
|
19
|
+
* @returns {Promise<{ ref: string } | { end: true }>} `end` = the command ends cleanly (exit 0)
|
|
20
|
+
*/
|
|
21
|
+
export function askBundle({ ask, out, home, none, cancelled }: {
|
|
22
|
+
ask: (q: string) => Promise<string>;
|
|
23
|
+
out: (s: string) => void;
|
|
24
|
+
home?: string;
|
|
25
|
+
none: string;
|
|
26
|
+
cancelled: string;
|
|
27
|
+
}): Promise<{
|
|
28
|
+
ref: string;
|
|
29
|
+
} | {
|
|
30
|
+
end: true;
|
|
31
|
+
}>;
|
|
32
|
+
/**
|
|
33
|
+
* A bundle reference typed by a person: an existing folder (relative to `cwd`), else an exported run name.
|
|
34
|
+
* @param {string} ref @param {{ home?: string, cwd: string }} o
|
|
35
|
+
* @returns {{ ok: true, dir: string } | { ok: false, why: string }}
|
|
36
|
+
*/
|
|
37
|
+
export function resolveBundleRef(ref: string, { home, cwd }: {
|
|
38
|
+
home?: string;
|
|
39
|
+
cwd: string;
|
|
40
|
+
}): {
|
|
41
|
+
ok: true;
|
|
42
|
+
dir: string;
|
|
43
|
+
} | {
|
|
44
|
+
ok: false;
|
|
45
|
+
why: string;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* The stopped / capped runs of `bareloop run` the engine would accept a resume for, newest first: not alive, no answer yet, an
|
|
49
|
+
* attempt to continue, checkpoint not expired, and the bundle folder still on disk.
|
|
50
|
+
* @param {{ home?: string }} [opts]
|
|
51
|
+
* @returns {{ runid: string, job: string, bundleDir: string, outcome: string, label: string }[]}
|
|
52
|
+
*/
|
|
53
|
+
export function listResumableBundleRuns(opts?: {
|
|
54
|
+
home?: string;
|
|
55
|
+
}): {
|
|
56
|
+
runid: string;
|
|
57
|
+
job: string;
|
|
58
|
+
bundleDir: string;
|
|
59
|
+
outcome: string;
|
|
60
|
+
label: string;
|
|
61
|
+
}[];
|
|
62
|
+
/** how many bundles a pick list shows; older ones stay reachable by typing their run name or folder */
|
|
63
|
+
export const RECENT_BUNDLES: 10;
|
package/types/bundlerun.d.ts
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `bareloop run <
|
|
3
|
-
* `bareloop run <
|
|
2
|
+
* `bareloop run <bundle> --repo <path> [--model <id>] [--budget N] [--wall MIN] [--yes] [--approve <bundleHash>]`
|
|
3
|
+
* `bareloop run <bundle> --resume <runid> [--repo <path>] [--budget N] [--wall MIN] [--yes] [--approve <bundleHash>]`
|
|
4
|
+
* `<bundle>` is a bundle folder or the run name it was exported under (`job (run-N)`). A missing bundle, repo or model is asked for
|
|
5
|
+
* (when there is something to ask: `canAsk`); a required answer left empty twice ends the command cleanly (exit 0, nothing run).
|
|
6
|
+
* A cap typed ABOVE the signed one is shown back and needs `yes` (or `--yes`); the approval is recorded in the run's own folder.
|
|
4
7
|
* @param {string[]} args
|
|
5
8
|
* @param {{
|
|
6
9
|
* out: (s: string) => void, err: (s: string) => void, cwd: string,
|
|
7
10
|
* env: Record<string,string|undefined>, now: () => number, deps: any, keysHome?: string,
|
|
11
|
+
* ask?: (q: string) => Promise<string>, canAsk?: boolean, guided?: boolean,
|
|
8
12
|
* parseFlags: (a: string[]) => { positional: string[], flags: Record<string, string|true> },
|
|
9
13
|
* printReds: (reds: import('./bundle.js').Red[], err: (s: string) => void) => void,
|
|
10
14
|
* }} ctx
|
|
11
15
|
* @returns {Promise<number>}
|
|
12
16
|
*/
|
|
13
|
-
export function bundleMain(args: string[], { out, err, cwd, env, now, deps, keysHome, parseFlags, printReds, }: {
|
|
17
|
+
export function bundleMain(args: string[], { out, err, cwd, env, now, deps, keysHome, ask, canAsk, guided: guidedIn, parseFlags, printReds, }: {
|
|
14
18
|
out: (s: string) => void;
|
|
15
19
|
err: (s: string) => void;
|
|
16
20
|
cwd: string;
|
|
@@ -18,6 +22,9 @@ export function bundleMain(args: string[], { out, err, cwd, env, now, deps, keys
|
|
|
18
22
|
now: () => number;
|
|
19
23
|
deps: any;
|
|
20
24
|
keysHome?: string;
|
|
25
|
+
ask?: (q: string) => Promise<string>;
|
|
26
|
+
canAsk?: boolean;
|
|
27
|
+
guided?: boolean;
|
|
21
28
|
parseFlags: (a: string[]) => {
|
|
22
29
|
positional: string[];
|
|
23
30
|
flags: Record<string, string | true>;
|
package/types/cli.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* code, so `bin/bareloop.mjs` can set `process.exitCode` and let node flush
|
|
4
4
|
* queued stdout on its own (F-something: `process.exit()` can discard it).
|
|
5
5
|
* @param {string[]} argv
|
|
6
|
-
* @param {{ env?: Record<string,string|undefined>, stdout?: any, stderr?: any, cwd?: string, provider?: any, providerFor?: any, judgeProvider?: any, judgeModel?: string|null, now?: () => number, stdin?: any, runlistHome?: string, keysHome?: string, processEnv?: Record<string,string|undefined> }} deps
|
|
6
|
+
* @param {{ env?: Record<string,string|undefined>, stdout?: any, stderr?: any, cwd?: string, provider?: any, providerFor?: any, judgeProvider?: any, judgeModel?: string|null, now?: () => number, stdin?: any, interactive?: boolean, runlistHome?: string, keysHome?: string, processEnv?: Record<string,string|undefined> }} deps
|
|
7
7
|
* @returns {Promise<number>}
|
|
8
8
|
*/
|
|
9
9
|
export function main(argv: string[], deps?: {
|
|
@@ -17,6 +17,7 @@ export function main(argv: string[], deps?: {
|
|
|
17
17
|
judgeModel?: string | null;
|
|
18
18
|
now?: () => number;
|
|
19
19
|
stdin?: any;
|
|
20
|
+
interactive?: boolean;
|
|
20
21
|
runlistHome?: string;
|
|
21
22
|
keysHome?: string;
|
|
22
23
|
processEnv?: Record<string, string | undefined>;
|
package/types/draftspend.d.ts
CHANGED
|
@@ -5,39 +5,22 @@
|
|
|
5
5
|
* - `step-label` {no, label, at} (the step reads `label` from now on, status and times untouched: the thinking row's "the model thought anyway" / "can't change it" / "not confirmed")
|
|
6
6
|
* - `human` {no, source: 'confirm'|'try-3'|'look', question, answer, line?, at}: one question the person was asked and what they answered (the answer is secret-masked
|
|
7
7
|
* before it is written; the row is written only when BOTH exist, so a question nobody answered leaves no row)
|
|
8
|
-
* - `call` {no, step, label, model, thinking, thinkingSupport, thinkingStatus?, costUsd (null stays null), unpricedRounds, at}: one METERED model call
|
|
8
|
+
* - `call` {no, step, label, model, provider, baseUrl, thinking, thinkingSupport, thinkingStatus?, costUsd (null stays null), unpricedRounds, at}: one METERED model call
|
|
9
9
|
* (`thinking` = the tick's mode: off | on; `thinkingSupport` = bare-agent's lookup for the model: true | false | 'unverified';
|
|
10
10
|
* `thinkingStatus` = bare-agent's own verdict for the call's run: applied | unsupported | ignored | unknown, present only when thinkingMode was sent)
|
|
11
11
|
* (no token counts: the call path does not carry them without reworking the library, so none are recorded)
|
|
12
12
|
* @typedef {{kind: string, no: number, at: string, [k: string]: any}} DraftEvent
|
|
13
13
|
*/
|
|
14
14
|
/**
|
|
15
|
-
* Append one event to `<dir>/draft-log.jsonl`. Best-effort
|
|
15
|
+
* Append one event to `<dir>/draft-log.jsonl`. Best-effort: a disk fault never stops the draft.
|
|
16
16
|
* @param {string} dir the session's folder
|
|
17
17
|
* @param {DraftEvent} ev
|
|
18
18
|
* @returns {void}
|
|
19
19
|
*/
|
|
20
20
|
export function appendDraftLog(dir: string, ev: DraftEvent): void;
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* @property {number} spentUsd the known floor of the session's drafting spend
|
|
25
|
-
* @property {boolean} spendComplete false = `spentUsd` is a floor ("at least")
|
|
26
|
-
* @property {string|null} provider the worker's provider shape (`anthropic-api` | `openai-api` | ...)
|
|
27
|
-
* @property {string|null} baseUrl
|
|
28
|
-
* @property {string|null} model
|
|
29
|
-
* @property {string} startedAt ISO, the first metered call
|
|
30
|
-
* @property {string} updatedAt ISO, the latest metered call
|
|
31
|
-
*/
|
|
32
|
-
/**
|
|
33
|
-
* (Re)write `<dir>/draft-spend.json` atomically (tmp + rename).
|
|
34
|
-
* @param {string} dir the session's folder
|
|
35
|
-
* @param {DraftSpend} rec
|
|
36
|
-
* @returns {void}
|
|
37
|
-
*/
|
|
38
|
-
export function writeDraftSpend(dir: string, rec: DraftSpend): void;
|
|
39
|
-
/**
|
|
40
|
-
* Every session folder's drafting spend that never became a run.
|
|
22
|
+
* Every session folder's drafting spend that never became a run: folded from the log's `call` lines, else read from a legacy
|
|
23
|
+
* `draft-spend.json`; a folder with neither is skipped.
|
|
41
24
|
* @param {{ home?: string, sessionsRoot?: string }} [opts] `home` = the bareloop config dir (as everywhere in src/monthly.js); the sessions live in `<home>/panel-sessions` unless `sessionsRoot` names them
|
|
42
25
|
* @returns {DraftSpend[]}
|
|
43
26
|
*/
|
|
@@ -125,8 +108,9 @@ export function draftingPartFor(row: {
|
|
|
125
108
|
home?: string;
|
|
126
109
|
sessionsRoot?: string;
|
|
127
110
|
}): any | null;
|
|
111
|
+
/** the OLD per-session total, no longer written; read only for a session folder that predates the log's call lines carrying it */
|
|
128
112
|
export const DRAFT_SPEND_FILE: "draft-spend.json";
|
|
129
|
-
/** the session's drafting LOG: an append-only JSONL
|
|
113
|
+
/** the session's drafting LOG: an append-only JSONL (one owner: the session, src/panel/authorsession.js). Three event kinds, see {@link DraftEvent}. */
|
|
130
114
|
export const DRAFT_LOG_FILE: "draft-log.jsonl";
|
|
131
115
|
/**
|
|
132
116
|
* One line of the drafting log. `no` = the step's position in the session's progress list (a step id can repeat).
|
|
@@ -135,7 +119,7 @@ export const DRAFT_LOG_FILE: "draft-log.jsonl";
|
|
|
135
119
|
* - `step-label` {no, label, at} (the step reads `label` from now on, status and times untouched: the thinking row's "the model thought anyway" / "can't change it" / "not confirmed")
|
|
136
120
|
* - `human` {no, source: 'confirm'|'try-3'|'look', question, answer, line?, at}: one question the person was asked and what they answered (the answer is secret-masked
|
|
137
121
|
* before it is written; the row is written only when BOTH exist, so a question nobody answered leaves no row)
|
|
138
|
-
* - `call` {no, step, label, model, thinking, thinkingSupport, thinkingStatus?, costUsd (null stays null), unpricedRounds, at}: one METERED model call
|
|
122
|
+
* - `call` {no, step, label, model, provider, baseUrl, thinking, thinkingSupport, thinkingStatus?, costUsd (null stays null), unpricedRounds, at}: one METERED model call
|
|
139
123
|
* (`thinking` = the tick's mode: off | on; `thinkingSupport` = bare-agent's lookup for the model: true | false | 'unverified';
|
|
140
124
|
* `thinkingStatus` = bare-agent's own verdict for the call's run: applied | unsupported | ignored | unknown, present only when thinkingMode was sent)
|
|
141
125
|
* (no token counts: the call path does not carry them without reworking the library, so none are recorded)
|
package/types/launcher.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* @typedef {object} Panel one answered probe
|
|
3
3
|
* @property {number} port @property {number} pid @property {string} version @property {number} drafts @property {number} schedules
|
|
4
4
|
* @property {string} url
|
|
5
|
+
* @property {string|null} [startedAt] ISO time the panel process started (`whoami`); absent on an older panel
|
|
5
6
|
*/
|
|
6
7
|
/**
|
|
7
8
|
* @typedef {object} LauncherDeps every OS touch, injectable (a test passes all of them)
|
|
@@ -13,6 +14,10 @@
|
|
|
13
14
|
* @property {number} [silentWaitMs] how long start keeps asking a taken, silent port (default 10 s)
|
|
14
15
|
* @property {string} [nodeVersion] default process.versions.node
|
|
15
16
|
* @property {typeof fetch} [fetchImpl]
|
|
17
|
+
* @property {(cmd: string, args: string[], o: object) => any} [npmSpawn] runs `npm install -g bareloop@latest` for `update` (default node:child_process spawn, no shell)
|
|
18
|
+
* @property {number} [npmDeadlineMs] how long `update`'s npm install may run before its child is killed (default 300 s)
|
|
19
|
+
* @property {boolean} [terminal] false = no person at a terminal (piped / redirected stdin): `update` then never installs, it prints the command (absent = ask)
|
|
20
|
+
* @property {typeof fetch} [npmFetch] the registry check of `update` only (default the global fetch); nothing else ever goes online
|
|
16
21
|
* @property {(cmd: string, args: string[], o: object) => any} [spawnFn] default node:child_process spawn
|
|
17
22
|
* @property {(pid: number, sig: string|number) => void} [kill] default process.kill
|
|
18
23
|
* @property {((target: string) => Promise<boolean>)} [open] default the shared OS opener
|
|
@@ -125,6 +130,21 @@ export function statusCmd(io: {
|
|
|
125
130
|
lines: string[];
|
|
126
131
|
panels: Panel[];
|
|
127
132
|
}): Promise<number>;
|
|
133
|
+
/**
|
|
134
|
+
* `bareloop update` — the only launcher command that goes online, and only when pressed: reads the newest published version from the npm
|
|
135
|
+
* registry (5 s deadline) and says whether there is a newer one. It installs nothing; it tells the person the command.
|
|
136
|
+
* @param {{out: (s: string) => void, err: (s: string) => void}} io @param {LauncherDeps & {version?: string}} d @param {{lines: string[], panels: Panel[]}} [shown]
|
|
137
|
+
* @returns {Promise<number>}
|
|
138
|
+
*/
|
|
139
|
+
export function updateCmd(io: {
|
|
140
|
+
out: (s: string) => void;
|
|
141
|
+
err: (s: string) => void;
|
|
142
|
+
}, d: LauncherDeps & {
|
|
143
|
+
version?: string;
|
|
144
|
+
}, shown?: {
|
|
145
|
+
lines: string[];
|
|
146
|
+
panels: Panel[];
|
|
147
|
+
}): Promise<number>;
|
|
128
148
|
/**
|
|
129
149
|
* `bareloop start` — find a running panel first; else start one detached on the first free port 4700..4709, wait until it answers,
|
|
130
150
|
* open the page.
|
|
@@ -157,8 +177,27 @@ export function stopCmd(args: string[], io: {
|
|
|
157
177
|
panels: Panel[];
|
|
158
178
|
}): Promise<number>;
|
|
159
179
|
/**
|
|
160
|
-
*
|
|
161
|
-
*
|
|
180
|
+
* `bareloop restart [--yes]` — the existing stop (same open-drafts warning and ask; `--yes` skips it), then the existing start, on the
|
|
181
|
+
* port the panel had when it is free again (else the normal first-free-port rule). No panel running: says so and just starts.
|
|
182
|
+
* No new process model, no pid file.
|
|
183
|
+
* @param {string[]} args
|
|
184
|
+
* @param {{out: (s: string) => void, err: (s: string) => void}} io @param {LauncherDeps & {version?: string}} d @param {{lines: string[], panels: Panel[]}} [shown]
|
|
185
|
+
* @returns {Promise<number>}
|
|
186
|
+
*/
|
|
187
|
+
export function restartCmd(args: string[], io: {
|
|
188
|
+
out: (s: string) => void;
|
|
189
|
+
err: (s: string) => void;
|
|
190
|
+
}, d: LauncherDeps & {
|
|
191
|
+
version?: string;
|
|
192
|
+
}, shown?: {
|
|
193
|
+
lines: string[];
|
|
194
|
+
panels: Panel[];
|
|
195
|
+
}): Promise<number>;
|
|
196
|
+
/**
|
|
197
|
+
* The bare `bareloop` menu (PRD v1.114, one menu): the panel's six choices, the four job commands, one question. Runs the chosen command
|
|
198
|
+
* and returns its exit code. The job commands (7 export, 8 run, 9 resume, 10 history) are `d.jobs`, supplied by the CLI: each prompts for
|
|
199
|
+
* what it needs on the same asker this menu uses.
|
|
200
|
+
* @param {{out: (s: string) => void, err: (s: string) => void}} io @param {LauncherDeps & {version?: string, jobs?: {export: () => Promise<number>, run: () => Promise<number>, resume: () => Promise<number>, history: () => Promise<number>}}} d
|
|
162
201
|
* @returns {Promise<number>}
|
|
163
202
|
*/
|
|
164
203
|
export function menuCmd(io: {
|
|
@@ -166,6 +205,12 @@ export function menuCmd(io: {
|
|
|
166
205
|
err: (s: string) => void;
|
|
167
206
|
}, d: LauncherDeps & {
|
|
168
207
|
version?: string;
|
|
208
|
+
jobs?: {
|
|
209
|
+
export: () => Promise<number>;
|
|
210
|
+
run: () => Promise<number>;
|
|
211
|
+
resume: () => Promise<number>;
|
|
212
|
+
history: () => Promise<number>;
|
|
213
|
+
};
|
|
169
214
|
}): Promise<number>;
|
|
170
215
|
/** the first port tried, and how many in a row (4700..4709) */
|
|
171
216
|
export const PORT_START: 4700;
|
|
@@ -180,6 +225,10 @@ export type Panel = {
|
|
|
180
225
|
drafts: number;
|
|
181
226
|
schedules: number;
|
|
182
227
|
url: string;
|
|
228
|
+
/**
|
|
229
|
+
* ISO time the panel process started (`whoami`); absent on an older panel
|
|
230
|
+
*/
|
|
231
|
+
startedAt?: string | null | undefined;
|
|
183
232
|
};
|
|
184
233
|
/**
|
|
185
234
|
* every OS touch, injectable (a test passes all of them)
|
|
@@ -212,6 +261,22 @@ export type LauncherDeps = {
|
|
|
212
261
|
*/
|
|
213
262
|
nodeVersion?: string | undefined;
|
|
214
263
|
fetchImpl?: typeof fetch | undefined;
|
|
264
|
+
/**
|
|
265
|
+
* runs `npm install -g bareloop@latest` for `update` (default node:child_process spawn, no shell)
|
|
266
|
+
*/
|
|
267
|
+
npmSpawn?: ((cmd: string, args: string[], o: object) => any) | undefined;
|
|
268
|
+
/**
|
|
269
|
+
* how long `update`'s npm install may run before its child is killed (default 300 s)
|
|
270
|
+
*/
|
|
271
|
+
npmDeadlineMs?: number | undefined;
|
|
272
|
+
/**
|
|
273
|
+
* false = no person at a terminal (piped / redirected stdin): `update` then never installs, it prints the command (absent = ask)
|
|
274
|
+
*/
|
|
275
|
+
terminal?: boolean | undefined;
|
|
276
|
+
/**
|
|
277
|
+
* the registry check of `update` only (default the global fetch); nothing else ever goes online
|
|
278
|
+
*/
|
|
279
|
+
npmFetch?: typeof fetch | undefined;
|
|
215
280
|
/**
|
|
216
281
|
* default node:child_process spawn
|
|
217
282
|
*/
|