geneseed 5.1.1 → 5.3.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 +52 -0
- package/README.md +2 -2
- package/SHIPPED.md +1 -1
- package/adapters/opencode/README.md +4 -3
- package/adapters/opencode/plugins/geneseed-context.js +82 -29
- package/adapters/opencode/plugins/geneseed-guard.js +118 -8
- package/bin/geneseed-cli.mjs +64 -16
- package/bin/geneseed-hook.mjs +37 -3
- package/docs/concepts/exclusions.md +1 -1
- package/docs/concepts/factories.md +40 -6
- package/docs/concepts/footprint.md +1 -1
- package/docs/concepts/foreman-mode.md +2 -2
- package/docs/concepts/host-matrix.md +1 -1
- package/docs/concepts/loop-gates.md +1 -1
- package/docs/concepts/loops.md +2 -2
- package/docs/concepts/shared-tier.md +1 -1
- package/docs/design-history.md +140 -0
- package/docs/extending.md +54 -162
- package/docs/guides/run-a-factory.md +15 -2
- package/docs/guides/setup-doctrines.md +1 -1
- package/docs/guides/upgrade.md +2 -2
- package/docs/reference/factory-actions.md +6 -5
- package/docs/reference/troubleshoot-update.md +1 -1
- package/docs/understand/enforced-vs-asked.md +1 -1
- package/docs/web-ui.md +16 -3
- package/harness.config.json +1 -1
- package/js/README.md +10 -7
- package/js/build/args.mjs +10 -4
- package/js/build/bundle.mjs +122 -23
- package/js/build/driver.mjs +32 -12
- package/js/build/emit-claude.mjs +2 -1
- package/js/build/emit-common.mjs +2 -2
- package/js/build/emit-opencode.mjs +22 -10
- package/js/build/export.mjs +431 -0
- package/js/build/generate.mjs +3 -0
- package/js/build/render.mjs +44 -24
- package/js/build/source.mjs +6 -1
- package/js/cli-table.json +232 -57
- package/js/factory/cli.mjs +24 -5
- package/js/factory/graph.mjs +13 -9
- package/js/factory/metrics.mjs +93 -0
- package/js/factory/registry.mjs +37 -12
- package/js/factory/state.mjs +25 -6
- package/js/hosts/hooks-context.mjs +26 -1
- package/js/hosts/hooks-done.mjs +8 -2
- package/js/hosts/hooks-prims.mjs +52 -3
- package/js/hosts/hooks.mjs +155 -33
- package/js/hosts/hosts.mjs +2 -4
- package/js/hosts/installs.mjs +28 -0
- package/js/hosts/loss.mjs +25 -3
- package/js/hosts/native.mjs +30 -2
- package/js/hosts/owned.mjs +55 -1
- package/js/hosts/ownership-gate.mjs +5 -5
- package/js/hosts/settings.mjs +83 -33
- package/js/inspect/diff.mjs +16 -1
- package/js/inspect/doctor.mjs +7 -3
- package/js/inspect/excludes.mjs +18 -6
- package/js/inspect/status.mjs +35 -7
- package/js/inspect/validate.mjs +44 -21
- package/js/lib/managed-block.mjs +74 -0
- package/js/maintain/uninstall.mjs +85 -15
- package/js/maintain/update.mjs +31 -7
- package/js/ui/cli.mjs +34 -4
- package/js/ui/menu.mjs +1 -1
- package/js/ui/tui.mjs +11 -14
- package/js/web/actions.mjs +5 -0
- package/js/web/api.mjs +32 -11
- package/js/web/daemon.mjs +0 -1
- package/js/web/server.mjs +1 -0
- package/js/web/state.mjs +37 -16
- package/package.json +1 -1
- package/src/AGENT.md.tmpl +23 -17
- package/src/agents/_template.md +1 -1
- package/src/agents/advocate.md +1 -1
- package/src/agents/developer.md +12 -3
- package/src/agents/empiricist.md +1 -1
- package/src/agents/framer.md +1 -1
- package/src/agents/historian.md +1 -1
- package/src/agents/operator.md +1 -1
- package/src/agents/pragmatist.md +1 -1
- package/src/agents/researcher.md +1 -1
- package/src/agents/skeptic.md +1 -1
- package/src/agents/steward.md +1 -1
- package/src/agents/user-advocate.md +1 -1
- package/src/agents/visionary.md +1 -1
- package/src/bricks/intake.md +10 -3
- package/src/bricks/retro.md +13 -3
- package/src/doctrines/comms.md +1 -1
- package/src/doctrines/ops.md +1 -1
- package/src/doctrines/process.md +7 -5
- package/src/factories/analysis-to-build.json +1 -0
- package/src/factories/bug-report-to-fix.json +1 -0
- package/src/factories/issue-to-pr.json +1 -0
- package/src/laws/universal.md +2 -2
- package/src/modes/foreman.md +8 -14
- package/src/skills/commit.md +7 -2
- package/src/skills/debug.md +1 -1
- package/src/skills/diagram-design/SKILL.md +1 -1
- package/src/skills/diagram-design/VENDOR.md +3 -1
- package/src/skills/factory-forge.md +5 -3
- package/src/skills/factory.md +22 -1
- package/src/skills/geneseed.md +1 -1
- package/src/skills/handoff.md +1 -1
- package/src/skills/parallel-agents.md +1 -1
- package/src/skills/pipeline.md +6 -6
- package/src/skills/plan.md +7 -3
- package/src/skills/spring-testing.md +1 -1
- package/themes/biker.json +78 -78
- package/themes/commentator.json +81 -81
- package/themes/cyberpunk.json +79 -79
- package/themes/gamer.json +77 -77
- package/themes/imperial.json +82 -82
- package/themes/joker.json +79 -79
- package/themes/marvin.json +82 -82
- package/themes/mean.json +82 -82
- package/themes/military.json +78 -78
- package/themes/neutral.json +78 -78
- package/themes/pirate.json +79 -79
- package/themes/sports.json +79 -79
- package/themes/verstappen.json +78 -78
- package/themes/wizard.json +79 -79
- package/web/dist/assets/ActiveLoops-BJJN3P-V.js +1 -0
- package/web/dist/assets/Activity-CqJiquEq.js +1 -0
- package/web/dist/assets/ActivityDetail-BSzevynX.js +1 -0
- package/web/dist/assets/{Bonsai-hiG_gGNU.js → Bonsai-Bfpb6W-1.js} +1 -1
- package/web/dist/assets/{CopyButton-DUIUfNp6.js → CopyButton-ByIntFtB.js} +1 -1
- package/web/dist/assets/Dashboard-DBOEi9lQ.js +2 -0
- package/web/dist/assets/Docs-DvlMJhpu.js +5 -0
- package/web/dist/assets/Factories-Bpvv7L2H.js +1 -0
- package/web/dist/assets/{GreenhouseView-BKxy5apE.js → GreenhouseView-GpBsYn50.js} +1 -1
- package/web/dist/assets/Installs-BlGmVrFK.js +3 -0
- package/web/dist/assets/{JournalView-ChFitHjo.js → JournalView-iLuLrOxE.js} +1 -1
- package/web/dist/assets/Kits-DRwpxC-J.js +1 -0
- package/web/dist/assets/Laws-CZkiNOWQ.js +4 -0
- package/web/dist/assets/LibRows-DEHjIoD-.js +1 -0
- package/web/dist/assets/Library-B4K-1iNF.js +3 -0
- package/web/dist/assets/Loops-BWSzaW8E.js +2 -0
- package/web/dist/assets/{OperatorHudView-BO0aIKPL.js → OperatorHudView-BAXwCEvY.js} +1 -1
- package/web/dist/assets/Personal-Bp9nV4GR.js +2 -0
- package/web/dist/assets/Settings-CWWuaIp-.js +1 -0
- package/web/dist/assets/Tabs-CWeQTADL.js +1 -0
- package/web/dist/assets/index-CsAZq0BQ.css +1 -0
- package/web/dist/assets/index-How7SzDZ.js +6 -0
- package/web/dist/assets/usePoll-D5c_qIFZ.js +1 -0
- package/web/dist/index.html +2 -2
- package/web/dist/assets/ActiveLoops-BTHIaRhn.js +0 -1
- package/web/dist/assets/Activity-CpkBwpu7.js +0 -1
- package/web/dist/assets/ActivityDetail-DTPziZWM.js +0 -1
- package/web/dist/assets/Dashboard-Dnw6EyX7.js +0 -2
- package/web/dist/assets/Docs-BEET_l16.js +0 -5
- package/web/dist/assets/Factories-D6KXkfWw.js +0 -1
- package/web/dist/assets/Installs-CnFVlVD0.js +0 -3
- package/web/dist/assets/Kits-CcR-OlwQ.js +0 -1
- package/web/dist/assets/Laws-B1s5idOg.js +0 -4
- package/web/dist/assets/LibRows-BZgdbI1l.js +0 -1
- package/web/dist/assets/Library-x6TkkEVF.js +0 -3
- package/web/dist/assets/Loops-BH93KKxn.js +0 -2
- package/web/dist/assets/Personal-CE_0Vhh0.js +0 -2
- package/web/dist/assets/Settings-CbpZvVN_.js +0 -1
- package/web/dist/assets/Tabs-C2oW7oEj.js +0 -1
- package/web/dist/assets/index-BQwOmbor.js +0 -6
- package/web/dist/assets/index-CuIop_pO.css +0 -1
- package/web/dist/assets/usePoll-o8ul-Sog.js +0 -1
|
@@ -59,7 +59,9 @@ import {
|
|
|
59
59
|
resolvePath, settingsFile,
|
|
60
60
|
} from '../hosts/hosts.mjs';
|
|
61
61
|
import { mcpCommented, mcpLoad } from '../hosts/mcp.mjs';
|
|
62
|
-
import {
|
|
62
|
+
import {
|
|
63
|
+
SRC_DIRS_MARKER, bundleFiles, hashesOf, ownedState, ownedWithin, recordedDenies, recordedEdit,
|
|
64
|
+
} from '../hosts/owned.mjs';
|
|
63
65
|
import {
|
|
64
66
|
atomicWriteJson, managedBlockRead, managedBlockRemove, managedBlockWrite,
|
|
65
67
|
loadJsonObject, mergeClaudeSettings, opencodeTarget, OPENCODE_SENTINEL, opencodeSentinelWrite,
|
|
@@ -70,6 +72,7 @@ import { printOut, printErr, readText, writeText, isFile, isDir, isOsError } fro
|
|
|
70
72
|
import { indexOfDeepEqual, isDict, jsonDumps, deepEquals } from '../lib/json.mjs';
|
|
71
73
|
import { sharedPaths } from '../lib/machine-dir.mjs';
|
|
72
74
|
import { archiveStore } from '../hosts/memory-files.mjs';
|
|
75
|
+
import { hostGlobalInstalls } from '../inspect/excludes.mjs';
|
|
73
76
|
import { comparePaths, isAbsolutePath } from '../lib/paths.mjs';
|
|
74
77
|
|
|
75
78
|
const hostSpec = (host) => HOSTS.find((h) => h.host === host);
|
|
@@ -405,11 +408,26 @@ export function installAgentEntryOf(instr) {
|
|
|
405
408
|
/**
|
|
406
409
|
* Reverse a per-repo OpenCode emit.
|
|
407
410
|
*
|
|
408
|
-
*
|
|
409
|
-
*
|
|
410
|
-
*
|
|
411
|
-
*
|
|
412
|
-
*
|
|
411
|
+
* ONLY WHAT THE EMIT RECORDED IS REMOVED, in both halves. `.opencode/` is unlinked file by file
|
|
412
|
+
* off its manifest, so a hand-added agent or plugin under it survives. The portable bundle
|
|
413
|
+
* beside it is unlinked file by file off the bundle's own list (`bundleFiles`,
|
|
414
|
+
* `js/build/bundle.mjs`), so the user's own `agents/`, `skills/`, `laws/` or `AGENT.md` at the
|
|
415
|
+
* repository root survive too. Both halves used to delete by directory, and a repository that
|
|
416
|
+
* had such folders before the install lost them.
|
|
417
|
+
*
|
|
418
|
+
* `userOnly` names the watched directories this reversal emptied of everything recorded and
|
|
419
|
+
* that still exist: what is left in them is the user's. `installUninstall` does not count them
|
|
420
|
+
* as survivors. Counting them reported INCOMPLETE and advised a retry, with the manifest already
|
|
421
|
+
* unlinked, and the retry then read `.opencode/` as a pre-manifest install and removed it whole.
|
|
422
|
+
*
|
|
423
|
+
* WITHOUT A RECORD the old shape still runs, for an install an older build made: no manifest
|
|
424
|
+
* means `.opencode/` goes whole, and no bundle list means `laws`/`agents`/`skills` and
|
|
425
|
+
* `AGENT.md` go whole. Two conditions fence it. The root must carry a bundle's own marker
|
|
426
|
+
* (`.geneseed-theme` or the version file), the test `build` uses: `installState` calls a bare
|
|
427
|
+
* `.opencode/` directory an install, and without the marker this reversal took a repository
|
|
428
|
+
* Geneseed had already left, or never entered, for a pre-manifest install. And a root that has
|
|
429
|
+
* the bundle list was made by a build that also writes the manifest, so a missing manifest
|
|
430
|
+
* there is not a pre-manifest install and `.opencode/` is left alone.
|
|
413
431
|
*
|
|
414
432
|
* The entry is read BEFORE AGENT.md is deleted. Reading it after would find the wire
|
|
415
433
|
* describing a file that no longer exists, which the fallback would then paper over with the
|
|
@@ -421,8 +439,11 @@ function opencodeProjectUninstall(root, force = false) {
|
|
|
421
439
|
let failed = [];
|
|
422
440
|
let kept = [];
|
|
423
441
|
let man = null;
|
|
442
|
+
const userOnly = [];
|
|
424
443
|
const oc = path.join(root, '.opencode');
|
|
425
444
|
const manifestPath = path.join(oc, GLOBAL_MANIFEST);
|
|
445
|
+
const listed = bundleFiles(root);
|
|
446
|
+
const legacy = isFile(path.join(root, '.geneseed-theme')) || isFile(path.join(root, VERSION_MARKER));
|
|
426
447
|
if (isFile(manifestPath)) {
|
|
427
448
|
man = claudeReadManifest(oc);
|
|
428
449
|
[removed, failed, kept] = unlinkOwned(oc, ownedOf(man), '.opencode/', hashesOf(man), force);
|
|
@@ -434,22 +455,41 @@ function opencodeProjectUninstall(root, force = false) {
|
|
|
434
455
|
if (!failed.length) {
|
|
435
456
|
unlinkQuiet(manifestPath);
|
|
436
457
|
if (isDir(oc) && isEmptyDir(oc)) rmdirQuiet(oc);
|
|
458
|
+
else if (isDir(oc)) userOnly.push(oc);
|
|
437
459
|
} else {
|
|
438
460
|
warnMarkersKept();
|
|
439
461
|
}
|
|
440
462
|
} else if (isDir(oc)) {
|
|
441
|
-
|
|
442
|
-
removed += 1;
|
|
463
|
+
if (listed || !legacy) userOnly.push(oc);
|
|
464
|
+
else { rmtreeQuiet(oc); removed += 1; }
|
|
443
465
|
}
|
|
444
|
-
|
|
445
|
-
const
|
|
446
|
-
|
|
466
|
+
if (listed) {
|
|
467
|
+
const [n, bundleFailed] = unlinkOwned(root, listed, '', {}, true);
|
|
468
|
+
removed += n;
|
|
469
|
+
if (bundleFailed.length) {
|
|
470
|
+
warnSurvivors(bundleFailed);
|
|
471
|
+
failed = failed.concat(bundleFailed);
|
|
472
|
+
} else {
|
|
473
|
+
unlinkQuiet(path.join(root, SRC_DIRS_MARKER));
|
|
474
|
+
for (const d of ['laws', 'agents', 'skills']) {
|
|
475
|
+
if (isDir(path.join(root, d))) userOnly.push(path.join(root, d));
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
} else if (legacy) {
|
|
479
|
+
for (const d of ['laws', 'agents', 'skills']) {
|
|
480
|
+
const p = path.join(root, d);
|
|
481
|
+
if (isDir(p)) { rmtreeQuiet(p); removed += 1; }
|
|
482
|
+
}
|
|
483
|
+
const am = path.join(root, 'AGENT.md');
|
|
484
|
+
if (isFile(am)) { unlinkQuiet(am); removed += 1; }
|
|
485
|
+
} else {
|
|
486
|
+
for (const d of ['laws', 'agents', 'skills']) {
|
|
487
|
+
if (isDir(path.join(root, d))) userOnly.push(path.join(root, d));
|
|
488
|
+
}
|
|
447
489
|
}
|
|
448
|
-
const am = path.join(root, 'AGENT.md');
|
|
449
|
-
if (isFile(am)) { unlinkQuiet(am); removed += 1; }
|
|
450
490
|
const unmerged = unmergeOpencodeJson(path.join(root, 'opencode.json'), entry,
|
|
451
491
|
man ? recordedDenies(man) : [], man ? recordedEdit(man) : null);
|
|
452
|
-
const result = { removed, unmerged, archived: null };
|
|
492
|
+
const result = { removed, unmerged, archived: null, userOnly };
|
|
453
493
|
if (failed.length) result.failed = failed;
|
|
454
494
|
if (kept.length) result.kept = kept;
|
|
455
495
|
return result;
|
|
@@ -536,7 +576,11 @@ export function installUninstall(root, host = 'opencode', scope = 'global', memo
|
|
|
536
576
|
// `kept` rels are spelled relative to the reversal's own base: the cfg dir for the Claude
|
|
537
577
|
// family, the root for OpenCode (whose project reversal already prefixes `.opencode/`).
|
|
538
578
|
const keptAbs = new Set(kept.map((r) => path.join(CLAUDE_STYLE.includes(host) ? data : root, r)));
|
|
579
|
+
// `userOnly`: a reversal that removed by record names the watched dirs it left holding only
|
|
580
|
+
// the user's files (`opencodeProjectUninstall`).
|
|
581
|
+
const userOnly = new Set(summary.userOnly || []);
|
|
539
582
|
const survivors = ownedDirsFor(root, host, scope, data).filter((d) => existsSync(d)
|
|
583
|
+
&& !userOnly.has(d)
|
|
540
584
|
&& !(keptAbs.size && readdirSync(d, { recursive: true, withFileTypes: true })
|
|
541
585
|
.every((e) => e.isDirectory() || keptAbs.has(path.join(e.parentPath, e.name)))));
|
|
542
586
|
const withKept = (o) => (kept.length ? { ...o, kept } : o);
|
|
@@ -677,7 +721,8 @@ export function projectQualifies(root, host) {
|
|
|
677
721
|
* 2. `--target` IS a project marker dir itself (…/.claude) — root is its parent.
|
|
678
722
|
* 3. `--target` (as a root) carries a Geneseed project install.
|
|
679
723
|
* 4. `--target` given and unrecognised — null, and the caller reports it.
|
|
680
|
-
* 5. No `--target`: the cwd, then the
|
|
724
|
+
* 5. No `--target`: the cwd, then the one global install on the machine, else the OpenCode
|
|
725
|
+
* global config dir (`cmdUninstall` refuses when there are several).
|
|
681
726
|
*/
|
|
682
727
|
export function uninstallResolve(targetArg) {
|
|
683
728
|
const globalHit = (p) => {
|
|
@@ -711,9 +756,23 @@ export function uninstallResolve(targetArg) {
|
|
|
711
756
|
// would otherwise return a root that LOOKS different from the identical directory.
|
|
712
757
|
const hit = projectHit(resolvePath(process.cwd()));
|
|
713
758
|
if (hit) return hit;
|
|
759
|
+
// The one global install on this machine, whatever its host: a Claude-only machine used to
|
|
760
|
+
// resolve to the empty OpenCode dir. With none, or several, the OpenCode dir stays the
|
|
761
|
+
// answer; `cmdUninstall` refuses the several case before it acts on it.
|
|
762
|
+
const globals = globalInstalls();
|
|
763
|
+
if (globals.length === 1) return [globals[0][0], 'global', globals[0][1]];
|
|
714
764
|
return ['opencode', 'global', opencodeConfigDir()];
|
|
715
765
|
}
|
|
716
766
|
|
|
767
|
+
/**
|
|
768
|
+
* `[host, configDir]` for each host's global dir that holds an install (`installState` not
|
|
769
|
+
* absent) — the candidates a bare `uninstall` chooses from. The walk is `hostGlobalInstalls`
|
|
770
|
+
* (`inspect/excludes.mjs`), its one owner; `version` and `diff` call it with their own marker.
|
|
771
|
+
*/
|
|
772
|
+
export function globalInstalls() {
|
|
773
|
+
return hostGlobalInstalls((host, dir) => installState(dir, host, 'global') !== 'absent');
|
|
774
|
+
}
|
|
775
|
+
|
|
717
776
|
/**
|
|
718
777
|
* The PROJECT installs still on record.
|
|
719
778
|
*
|
|
@@ -788,6 +847,17 @@ export function cmdUninstall(args) {
|
|
|
788
847
|
return 1;
|
|
789
848
|
}
|
|
790
849
|
const [host, scope, root] = hit;
|
|
850
|
+
// No `--target` and more than one global install: which one is meant is a guess, and this
|
|
851
|
+
// verb deletes. Refused before anything is printed as a target, `--yes` or not.
|
|
852
|
+
if (!args.target && scope === 'global') {
|
|
853
|
+
const globals = globalInstalls();
|
|
854
|
+
if (globals.length > 1) {
|
|
855
|
+
printErr(`[uninstall] ${globals.length} global installs found, and no --target names one. `
|
|
856
|
+
+ 'Run one of:\n'
|
|
857
|
+
+ globals.map(([h, d]) => ` geneseed uninstall --target "${d}" (${h}:global)\n`).join(''));
|
|
858
|
+
return 2;
|
|
859
|
+
}
|
|
860
|
+
}
|
|
791
861
|
if (installState(root, host, scope) === 'absent') {
|
|
792
862
|
const where = scope === 'project' && host !== 'opencode'
|
|
793
863
|
? ` under ${hostSpec(host).projectMarker}/` : '';
|
package/js/maintain/update.mjs
CHANGED
|
@@ -936,7 +936,17 @@ export async function upgrade(themeArg = null) {
|
|
|
936
936
|
* captured against the PRE-refresh source. Anything it throws is a warning on stderr and the
|
|
937
937
|
* upgrade continues — a failed export is a lost note, a blocked upgrade is a broken install.
|
|
938
938
|
*/
|
|
939
|
-
export async function cmdUpgrade(args) {
|
|
939
|
+
export async function cmdUpgrade(args, { handoff = reexec } = {}) {
|
|
940
|
+
// `--theme NAME` is the positional `[theme]` spelled as every other verb spells it; both kept.
|
|
941
|
+
// Two different answers on one line is a typo, not a choice, so it is refused before anything runs.
|
|
942
|
+
if (args.theme && args.themeOpt && args.theme !== args.themeOpt) {
|
|
943
|
+
printErr(`geneseed: error: argument --theme: '${args.themeOpt}' contradicts the theme `
|
|
944
|
+
+ `argument '${args.theme}' — give one.\n`);
|
|
945
|
+
return 2;
|
|
946
|
+
}
|
|
947
|
+
const theme = args.themeOpt || args.theme || null;
|
|
948
|
+
// `--setup`: the update with its step banner, then a FRESH `setup` — what `bootstrap` was.
|
|
949
|
+
if (args.setup) return updateThenSetup(theme, { handoff });
|
|
940
950
|
try {
|
|
941
951
|
const [ipath] = exportImprovements();
|
|
942
952
|
if (ipath) {
|
|
@@ -947,7 +957,7 @@ export async function cmdUpgrade(args) {
|
|
|
947
957
|
printErr(`[upgrade] ⚠️ could not export local edits (${e && e.message ? e.message : e}) — `
|
|
948
958
|
+ 'run `geneseed diff --out FILE` before upgrading to keep them.\n');
|
|
949
959
|
}
|
|
950
|
-
return upgrade(
|
|
960
|
+
return upgrade(theme);
|
|
951
961
|
}
|
|
952
962
|
|
|
953
963
|
// ---------------------------------------------------------------------------------------
|
|
@@ -1037,7 +1047,7 @@ export function diagnoseFailedStep(n, total, title, cmd, rc, output) {
|
|
|
1037
1047
|
*
|
|
1038
1048
|
* Returns true when a step FAILED, so scripted callers get a real exit code.
|
|
1039
1049
|
*/
|
|
1040
|
-
async function bootstrapPlain() {
|
|
1050
|
+
async function bootstrapPlain(theme = null) {
|
|
1041
1051
|
// One `git pull` refreshes launchers + factory together, then rebuilds — a single step.
|
|
1042
1052
|
//
|
|
1043
1053
|
// `cmdUpgrade`, NOT `upgrade`. The step the reference runs is the SUBCOMMAND — its argv is
|
|
@@ -1048,7 +1058,7 @@ async function bootstrapPlain() {
|
|
|
1048
1058
|
// which was written for `_flush_export_notes` and found this instead.
|
|
1049
1059
|
/** @type {Array<[string, string[], () => Promise<number>]>} */
|
|
1050
1060
|
const steps = [['Update & rebuild', updateStepCmd('upgrade'),
|
|
1051
|
-
() => cmdUpgrade({ theme
|
|
1061
|
+
() => cmdUpgrade({ theme })]];
|
|
1052
1062
|
let failed = false;
|
|
1053
1063
|
for (let i = 0; i < steps.length; i += 1) {
|
|
1054
1064
|
const [title, cmd, step] = steps[i];
|
|
@@ -1095,16 +1105,19 @@ function reexec(argv) {
|
|
|
1095
1105
|
*
|
|
1096
1106
|
* AN UNCHECKED SOURCE IS THE EXCEPTION: `setup` renders, and no doctor has judged this tree.
|
|
1097
1107
|
* An npm install has no record to hold, so it is not asked.
|
|
1108
|
+
*
|
|
1109
|
+
* `upgrade --setup` since `bootstrap` was folded into it; `setup: false` is what
|
|
1110
|
+
* `bootstrap --no-setup` still reaches for the one release it stays.
|
|
1098
1111
|
*/
|
|
1099
|
-
|
|
1100
|
-
const failed = await bootstrapPlain();
|
|
1112
|
+
async function updateThenSetup(theme, { handoff = reexec, setup = true } = {}) {
|
|
1113
|
+
const failed = await bootstrapPlain(theme);
|
|
1101
1114
|
flushExportNotes();
|
|
1102
1115
|
if (isGitCheckout() && pendingGate()) {
|
|
1103
1116
|
printOut('[geneseed] setup not started: the source has no doctor verdict yet. '
|
|
1104
1117
|
+ 'Run `geneseed update`, then `geneseed setup`.\n');
|
|
1105
1118
|
return 1;
|
|
1106
1119
|
}
|
|
1107
|
-
if (
|
|
1120
|
+
if (setup) {
|
|
1108
1121
|
const rc = handoff([process.execPath,
|
|
1109
1122
|
path.join(String(ROOT), 'bin', 'geneseed-cli.mjs'), 'setup']);
|
|
1110
1123
|
return failed ? 1 : rc;
|
|
@@ -1112,3 +1125,14 @@ export async function cmdBootstrap(args, { handoff = reexec } = {}) {
|
|
|
1112
1125
|
// Scripted `bootstrap --no-setup` must not exit 0 over a failed update.
|
|
1113
1126
|
return failed ? 1 : 0;
|
|
1114
1127
|
}
|
|
1128
|
+
|
|
1129
|
+
/**
|
|
1130
|
+
* `bootstrap`, DEPRECATED: folded into `upgrade --setup`. Kept one release as an alias that
|
|
1131
|
+
* says so on stderr and then does exactly what it did; its `--no-setup` is a plain `upgrade`
|
|
1132
|
+
* with the step banner.
|
|
1133
|
+
*/
|
|
1134
|
+
export async function cmdBootstrap(args, { handoff = reexec } = {}) {
|
|
1135
|
+
printErr('[geneseed] bootstrap is deprecated: run `geneseed upgrade --setup` '
|
|
1136
|
+
+ '(or `geneseed upgrade` for --no-setup).\n');
|
|
1137
|
+
return updateThenSetup(null, { handoff, setup: !args.noSetup });
|
|
1138
|
+
}
|
package/js/ui/cli.mjs
CHANGED
|
@@ -35,15 +35,19 @@
|
|
|
35
35
|
import { readFileSync } from 'node:fs';
|
|
36
36
|
import path from 'node:path';
|
|
37
37
|
|
|
38
|
+
import { choicesFor } from '../build/args.mjs';
|
|
38
39
|
import { ROOT } from '../build/source.mjs';
|
|
39
40
|
import { printOut } from '../lib/fs.mjs';
|
|
40
41
|
import { parseIntStrict, stripWhitespace } from '../lib/text.mjs';
|
|
41
42
|
|
|
42
43
|
const CLI_JSON = path.join(ROOT, 'js', 'cli-table.json');
|
|
43
44
|
|
|
44
|
-
/**
|
|
45
|
+
/**
|
|
46
|
+
* The keys the docs page carries, per argument — `type` and `hidden` are ours. `description` is
|
|
47
|
+
* an argument's own paragraph, when the table gives one; `null` when it does not.
|
|
48
|
+
*/
|
|
45
49
|
const PAGE_ARG_KEYS = ['names', 'dest', 'metavar', 'help', 'choices', 'default',
|
|
46
|
-
'required', 'nargs', 'is_flag'];
|
|
50
|
+
'required', 'nargs', 'is_flag', 'description'];
|
|
47
51
|
|
|
48
52
|
/**
|
|
49
53
|
* `js/cli-table.json`, parsed. An unreadable file is the empty reference; the entry points
|
|
@@ -61,6 +65,26 @@ function load() {
|
|
|
61
65
|
}
|
|
62
66
|
}
|
|
63
67
|
|
|
68
|
+
/**
|
|
69
|
+
* `build` forwards the generator's flags, and the generator owns their choice lists — two of
|
|
70
|
+
* them (`--posture`, `--mode`) are discovered from the checkout. So the table carries no copy:
|
|
71
|
+
* the readers that SHOW the rows (help, the docs page) lay `choicesFor` over them here. Not in
|
|
72
|
+
* `load`: `cliSpec` never reads an option's choices, and every verb's parse would pay the scan.
|
|
73
|
+
*/
|
|
74
|
+
function withDriverChoices(cmd) {
|
|
75
|
+
if (cmd?.name !== 'build') return cmd;
|
|
76
|
+
const choices = choicesFor();
|
|
77
|
+
for (const o of cmd.options ?? []) {
|
|
78
|
+
const list = choices[o.names?.[0]];
|
|
79
|
+
if (!list) continue;
|
|
80
|
+
o.choices = list;
|
|
81
|
+
// A row with its own metavar (`--emit`: nine names do not fit a usage line) names the
|
|
82
|
+
// list in its help instead of in `{…}`.
|
|
83
|
+
if (o.metavar) o.help = `${o.help} (one of: ${list.join(', ')})`;
|
|
84
|
+
}
|
|
85
|
+
return cmd;
|
|
86
|
+
}
|
|
87
|
+
|
|
64
88
|
const pageArgs = (args) => (args ?? [])
|
|
65
89
|
.filter((a) => !a.hidden)
|
|
66
90
|
.map((a) => Object.fromEntries(PAGE_ARG_KEYS.map((k) => [k, a[k] ?? null])));
|
|
@@ -77,7 +101,7 @@ export function cliReference() {
|
|
|
77
101
|
const data = load();
|
|
78
102
|
return {
|
|
79
103
|
prog: data.prog ?? 'geneseed',
|
|
80
|
-
commands: (data.commands ?? []).map((c) => ({
|
|
104
|
+
commands: (data.commands ?? []).map(withDriverChoices).map((c) => ({
|
|
81
105
|
name: c.name ?? '',
|
|
82
106
|
help: c.help ?? '',
|
|
83
107
|
description: c.description ?? '',
|
|
@@ -364,6 +388,12 @@ export function formatHelp(cmd, prog, width) {
|
|
|
364
388
|
maxHelpPosition);
|
|
365
389
|
|
|
366
390
|
const blocks = [`${formatUsage(prog, optParts, posParts, width)}\n`];
|
|
391
|
+
// argparse's `description`, wrapped to the full width after the usage line. It is where a
|
|
392
|
+
// verb's paragraph lives, so the top-level listing can keep each verb to one short line.
|
|
393
|
+
if (cmd.description && cmd.description.trim()) {
|
|
394
|
+
const collapsed = cmd.description.replace(/[ \t\n\v\f\r]+/g, ' ').trim();
|
|
395
|
+
blocks.push(`${wrapText(collapsed, Math.max(width, 11)).join('\n')}\n`);
|
|
396
|
+
}
|
|
367
397
|
if (positionals.length) {
|
|
368
398
|
blocks.push(`positional arguments:\n${positionals
|
|
369
399
|
.map((a) => formatAction(a, true, helpPosition, width)).join('')}`);
|
|
@@ -401,7 +431,7 @@ export function helpWidth() {
|
|
|
401
431
|
|
|
402
432
|
/** One command's raw row — everything the table knows, unlike the page's filtered view. */
|
|
403
433
|
export function cliCommand(verb) {
|
|
404
|
-
return (load().commands ?? []).find((c) => c.name === verb) ?? null;
|
|
434
|
+
return withDriverChoices((load().commands ?? []).find((c) => c.name === verb) ?? null);
|
|
405
435
|
}
|
|
406
436
|
|
|
407
437
|
/**
|
package/js/ui/menu.mjs
CHANGED
|
@@ -25,7 +25,7 @@ import { startDaemon } from '../web/daemon.mjs';
|
|
|
25
25
|
/** The off-TTY arm, and the fallback both TTY arms end in. */
|
|
26
26
|
function menuHelp() {
|
|
27
27
|
printOut('Geneseed — no interactive menu here. Get started with: geneseed setup\n');
|
|
28
|
-
printOut('Other commands:
|
|
28
|
+
printOut('Other commands: update · build · doctor · diff · web\n');
|
|
29
29
|
printOut('`geneseed --help` lists every command.\n');
|
|
30
30
|
return 0;
|
|
31
31
|
}
|
package/js/ui/tui.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `tui` — and the TUI's pure half: the layout helpers that have no screen in them.
|
|
3
3
|
*
|
|
4
|
-
* `cmdTui` is an
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* `isTTY` true in a child and asserts
|
|
8
|
-
* the
|
|
4
|
+
* `cmdTui` is RETIRED: an alias kept one release that prints one line pointing at `geneseed
|
|
5
|
+
* menu` and returns 0, on a TTY or off one — `menu`'s own off-terminal exit. There is no
|
|
6
|
+
* full-screen panel behind it, the same decision `js/ui/menu.mjs` makes.
|
|
7
|
+
* `tests/unit/no_panel.test.mjs` fakes `isTTY` true in a child and asserts the exit code, that
|
|
8
|
+
* the line names only declared verbs, and that nothing is drawn.
|
|
9
9
|
*
|
|
10
10
|
* What lives here is the alignment contract — the functions below that decide what a row
|
|
11
11
|
* looks like: display width, fitting, glyph tiers, the catalogue's entries and detail lines.
|
|
@@ -310,15 +310,12 @@ export function detailLines(kind, label, data) {
|
|
|
310
310
|
// ---- the verb ------------------------------------------------------------------------
|
|
311
311
|
|
|
312
312
|
/**
|
|
313
|
-
* The `tui` verb
|
|
314
|
-
*
|
|
313
|
+
* The `tui` verb, RETIRED: it refused on every terminal, since there is no panel (see this
|
|
314
|
+
* module's header). Kept one release as an alias that says where to go and exits as `menu`
|
|
315
|
+
* does off a terminal (0), so a script that called it learns the new name without breaking.
|
|
316
|
+
* The same one line on a TTY and off one. The layout helpers above stay: `catalog` uses them.
|
|
315
317
|
*/
|
|
316
318
|
export function cmdTui() {
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
return 1;
|
|
320
|
-
}
|
|
321
|
-
printOut('[tui] full-screen panel unavailable (this entry carries the TUI\'s layout '
|
|
322
|
-
+ 'half, not its screens). Use `geneseed setup`, `geneseed doctor`, or `geneseed build`.\n');
|
|
323
|
-
return 1;
|
|
319
|
+
printOut('[tui] tui is retired; use `geneseed menu`.\n');
|
|
320
|
+
return 0;
|
|
324
321
|
}
|
package/js/web/actions.mjs
CHANGED
|
@@ -234,6 +234,8 @@ export function targetView(base, [host, scope, root]) {
|
|
|
234
234
|
v = webState(null, target);
|
|
235
235
|
v.selectView(target, root, emitOf(host, scope));
|
|
236
236
|
v.pinned = true;
|
|
237
|
+
// A serving daemon runs no doctor on the event loop, for a named install either (`warmDoctor`).
|
|
238
|
+
Object.defineProperty(v, 'warm', { get: () => base.warm });
|
|
237
239
|
// The daemon's one memo: a render is keyed on what it read, not on who asked for it.
|
|
238
240
|
v.renderMemo = (base.renderMemo ??= renderMemo());
|
|
239
241
|
v.refresh = base.refresh;
|
|
@@ -786,6 +788,9 @@ export function apiInstallCmd(state, body) {
|
|
|
786
788
|
const argv = setupBuildArgs(theme || 'neutral', emit, out, out, fp, pos, mode, doctrines,
|
|
787
789
|
PACK_ORDER, excludeRules, trust, excludedSkillsOfDir(root, host), gates,
|
|
788
790
|
kits ?? kitsOfDir(root, host), sharedTier);
|
|
791
|
+
// `--force` only on a literal `true`: the panel's "Replace with Geneseed's copies", which
|
|
792
|
+
// names the files first. It is this one build's instruction and is never recorded.
|
|
793
|
+
if (bget(body, 'force') === true) argv.push('--force');
|
|
789
794
|
return { cmd: [process.execPath, path.join(ROOT, 'bin', 'build-driver.mjs'), ...argv] };
|
|
790
795
|
}
|
|
791
796
|
|
package/js/web/api.mjs
CHANGED
|
@@ -23,14 +23,14 @@ import { CLAUDE_STYLE, VERSION_MARKER } from '../hosts/hosts.mjs';
|
|
|
23
23
|
import { factCount } from '../hosts/memory-files.mjs';
|
|
24
24
|
import { autostartState } from '../hosts/shim.mjs';
|
|
25
25
|
import {
|
|
26
|
-
footprintOfDir, gatesOfDir, installState, installTargets, modeOfDir,
|
|
26
|
+
footprintOfDir, gatesOfDir, installState, installTargets, leftoversOf, modeOfDir,
|
|
27
27
|
trustOfDir, sharedTierOfDir,
|
|
28
28
|
postureOfDir, readJsonMaybe, readMaybe, themeOfDir,
|
|
29
29
|
} from '../hosts/installs.mjs';
|
|
30
30
|
import { PRESETS } from '../loop/score.mjs';
|
|
31
31
|
import { loadCatalog, catalogProblems } from '../loop/catalog.mjs';
|
|
32
32
|
import { activeLoops, runningLoops, sameRoot } from '../loop/registry.mjs';
|
|
33
|
-
import {
|
|
33
|
+
import { listFactories } from '../factory/registry.mjs';
|
|
34
34
|
import { factoryCatalogProblems, loopOf } from '../factory/graph.mjs';
|
|
35
35
|
import { EMIT_OPTIONS, themeOptions } from '../maintain/setup.mjs';
|
|
36
36
|
import { accentFor, keptKitFiles, statusData } from '../inspect/status.mjs';
|
|
@@ -40,7 +40,7 @@ import { comparePaths } from '../lib/paths.mjs';
|
|
|
40
40
|
import {
|
|
41
41
|
configItems, deployed, dget, fleetCounts, memoryDir, memoryItems, notebookItems, orSkip, tierOf, wikiItems,
|
|
42
42
|
} from './catalog.mjs';
|
|
43
|
-
import { defaultView, samePath, stampMinute, viewCfg } from './state.mjs';
|
|
43
|
+
import { defaultView, samePath, stampMinute, viewCfg, warmDoctor } from './state.mjs';
|
|
44
44
|
import { MANUAL_UPDATE, gitBehind, installKind, updateStatus } from './update-check.mjs';
|
|
45
45
|
|
|
46
46
|
/**
|
|
@@ -93,22 +93,34 @@ const DOCTOR_COOLDOWN_MS = 3_000;
|
|
|
93
93
|
*
|
|
94
94
|
* A fresh ask within `DOCTOR_COOLDOWN_MS` of the last one THIS PATH ran reuses that run, so a
|
|
95
95
|
* page looping on `?fresh=1` cannot pin the event loop. `_doctorFreshAt` is written here only: a
|
|
96
|
-
* verdict planted any other way still re-runs.
|
|
97
|
-
*
|
|
96
|
+
* verdict planted any other way still re-runs. On a serving daemon (`state.warm`) the fresh run
|
|
97
|
+
* goes to the warm-up thread (`warmDoctor`, which stops the run it replaces); elsewhere it is
|
|
98
|
+
* the synchronous `runDoctor`.
|
|
98
99
|
*
|
|
99
|
-
* This page needs the groups, so
|
|
100
|
-
* rather than a pending one: the request waits, the event loop does not.
|
|
100
|
+
* This page needs the groups, so while a run is out it answers with a promise of the verdict
|
|
101
|
+
* rather than a pending one: the request waits, the event loop does not. A run that a refresh or
|
|
102
|
+
* a newer fresh ask replaced settles with no verdict, so the promise follows the newer run. Only a
|
|
103
|
+
* thread that could not give one (it failed to start or died) leaves the run to this request.
|
|
101
104
|
*/
|
|
102
105
|
export function apiDoctor(state, fresh = false) {
|
|
103
106
|
if (fresh && Date.now() - (state._doctorFreshAt ?? 0) >= DOCTOR_COOLDOWN_MS) {
|
|
104
|
-
|
|
107
|
+
// A daemon re-runs on the warm-up thread: the page waits on the promise, the loop does not.
|
|
108
|
+
if (state.warm) {
|
|
109
|
+
state._doctor = null;
|
|
110
|
+
state._doctorJob = null;
|
|
111
|
+
} else state.runDoctor();
|
|
105
112
|
state._doctorFreshAt = Date.now();
|
|
106
113
|
}
|
|
114
|
+
// `_doctor`, not the `doctor` getter: on a daemon the getter would start a thread and say null.
|
|
107
115
|
const answer = () => {
|
|
108
|
-
|
|
116
|
+
if (state._doctor === null && state._doctorJob !== null) return state._doctorJob.then(answer);
|
|
117
|
+
if (state._doctor === null) state.runDoctor();
|
|
118
|
+
const { ok, problems, checked_at } = state._doctor;
|
|
109
119
|
return { ...state._doctorRun, ok, problems, checked_at };
|
|
110
120
|
};
|
|
111
|
-
|
|
121
|
+
// A cold cache on a daemon (a view switch dropped it) is filled on the thread, as the overview's is.
|
|
122
|
+
if (state.warm && state._doctor === null) warmDoctor(state);
|
|
123
|
+
return answer();
|
|
112
124
|
}
|
|
113
125
|
|
|
114
126
|
/**
|
|
@@ -228,6 +240,9 @@ export function apiInstalls(state) {
|
|
|
228
240
|
trust: trustOfDir(root, host),
|
|
229
241
|
// A project install's switch for reading the machine tier (a global install owns it).
|
|
230
242
|
sharedTier: scope === 'global' ? false : sharedTierOfDir(root, host),
|
|
243
|
+
// Files here that are the user's where Geneseed ships one, and retired leftovers: what a
|
|
244
|
+
// forced rebuild would replace or remove (`leftoversOf`). Read off the emit's own record.
|
|
245
|
+
leftovers: leftoversOf(root, host, scope),
|
|
231
246
|
// The install a request naming none reads (`defaultView`): the console's pickers start on it.
|
|
232
247
|
default: !!def && samePath(viewCfg(host, scope, root), def[0]),
|
|
233
248
|
});
|
|
@@ -643,11 +658,17 @@ export function apiFactoriesCatalog(state) {
|
|
|
643
658
|
* `apiLoopsActive`), each with the loop running in its worktree as `loop` (the root is the join
|
|
644
659
|
* key, `js/factory/registry.mjs`), or null. `runningLoops`, not `activeLoops`: it is read-only,
|
|
645
660
|
* so this poll never prunes or stamps `loops.json` behind the Loops page's back.
|
|
661
|
+
*
|
|
662
|
+
* It is the board's read too (D7). A live row carries what `FACTORY.md` holds — `status`, `stage`,
|
|
663
|
+
* `awaiting`, `tasks`, `counters` beside the graph's cycles and their `max`, `history` — and
|
|
664
|
+
* `metrics`, `runMetrics` of that state. A `FACTORY.md` that does not parse is a row with status
|
|
665
|
+
* `unreadable`, and a missing one `finished`: identity only, never a throw. `listFactories` is
|
|
666
|
+
* read-only: this poll never writes a run or `factories.json` (D7).
|
|
646
667
|
*/
|
|
647
668
|
export function apiFactoriesActive() {
|
|
648
669
|
const loops = runningLoops();
|
|
649
670
|
return {
|
|
650
|
-
factories:
|
|
671
|
+
factories: listFactories().map((run) => {
|
|
651
672
|
const l = loops.find((x) => sameRoot(x.root, run.root));
|
|
652
673
|
return { ...run, loop: l ? { title: l.title, status: l.status, node: l.node, iteration: l.iteration, graph: l.graph } : null };
|
|
653
674
|
}),
|
package/js/web/daemon.mjs
CHANGED
|
@@ -524,7 +524,6 @@ export async function findConsoles(target, ports) {
|
|
|
524
524
|
const all = [...new Set([isTruthy(rec) ? Number(rec.port) : null, ...ports].filter(Number.isInteger))];
|
|
525
525
|
const found = [];
|
|
526
526
|
for (const p of all) {
|
|
527
|
-
// eslint-disable-next-line no-await-in-loop
|
|
528
527
|
const c = await identify(p);
|
|
529
528
|
if (c) found.push({ port: p, url: `http://127.0.0.1:${p}`, pid: c.pid, root: c.root,
|
|
530
529
|
recorded: isTruthy(rec) && rec.pid === c.pid && Number(rec.port) === p });
|
package/js/web/server.mjs
CHANGED
|
@@ -188,6 +188,7 @@ export async function serve({ theme = null, port = 4747, openBrowser = true,
|
|
|
188
188
|
printOut(daemon ? '[web] daemon ready.\n' : '[web] Ctrl-C to stop.\n');
|
|
189
189
|
if (openBrowser) openUrl(url);
|
|
190
190
|
// After the record and the ready line, so `web start`'s wait loop already has its URL.
|
|
191
|
+
state.warm = true;
|
|
191
192
|
warmDoctor(state);
|
|
192
193
|
// Node kills on SIGINT by default, which would skip this message and the record
|
|
193
194
|
// cleanup in `srv.on('close', ...)` below — a foreground `--daemon-internal` server
|
package/js/web/state.mjs
CHANGED
|
@@ -95,7 +95,7 @@ export function stampMinute(ms) {
|
|
|
95
95
|
* THE CACHING IS BEHAVIOUR, NOT AN OPTIMISATION: `doctorCollect` renders a theme per call
|
|
96
96
|
* and the console GETs `/api/overview` on mount and again after every mutation, so an
|
|
97
97
|
* uncached `doctor` would put a full build on each of those requests. `refresh()` is what a mutation calls to
|
|
98
|
-
* drop both — except where the mutation cannot change anything the doctor reads (the checkout,
|
|
98
|
+
* drop both (a serving daemon then re-runs the doctor on its thread at once, `warmDoctor`) — except where the mutation cannot change anything the doctor reads (the checkout,
|
|
99
99
|
* the hook shim, the hook shell, the OpenCode config dirs, the deployed install): a memory
|
|
100
100
|
* delete passes `{ doctor: false }` and keeps the ~3.6 s verdict. Rule and profile writes do not
|
|
101
101
|
* call `refresh()` at all. Every other caller keeps the default, so a new one is slow, never stale.
|
|
@@ -124,6 +124,8 @@ export function webState(theme = null, target = null) {
|
|
|
124
124
|
_doctorRun: null,
|
|
125
125
|
// The warm-up run still in flight, a promise settled when its thread ends (`warmDoctor`).
|
|
126
126
|
_doctorJob: null,
|
|
127
|
+
// The thread of the latest warm-up, so the next one can stop it once a refresh dropped its job.
|
|
128
|
+
_doctorWorker: null,
|
|
127
129
|
// `diffCollect`'s memo of `expected` renders, made on first use by `api.mjs` (`memoOf`);
|
|
128
130
|
// it re-renders on its own key change, so `refresh()` leaves it alone.
|
|
129
131
|
renderMemo: null,
|
|
@@ -139,6 +141,10 @@ export function webState(theme = null, target = null) {
|
|
|
139
141
|
// The per-install views made off this daemon's state, keyed `[host, root]` — see
|
|
140
142
|
// `installView`. Kept here, not at module level, so each handler (each test's) has its own.
|
|
141
143
|
_views: new Map(),
|
|
144
|
+
// Set by `serve()` once it listens: from then on no request runs the doctor on the event loop.
|
|
145
|
+
// A cold cache starts `warmDoctor` and reads as pending; tests and one-shot reads keep the
|
|
146
|
+
// inline run, which answers at once.
|
|
147
|
+
warm: false,
|
|
142
148
|
};
|
|
143
149
|
// The INSTALL ROOT (== build --out). For globals it IS the data dir; a claude/bob/openclaude
|
|
144
150
|
// PROJECT install keeps its data under <repo>/.claude|.bob|.openclaude while the markers
|
|
@@ -172,7 +178,8 @@ export function webState(theme = null, target = null) {
|
|
|
172
178
|
// NULL WHILE THE WARM-UP RUNS, and only then: a pending verdict, which the console draws as
|
|
173
179
|
// "checking" and asks again for. Blocking here would put the run back on the event loop.
|
|
174
180
|
get() {
|
|
175
|
-
|
|
181
|
+
// A worker that cannot start (`warmDoctor` returns null) falls back to the inline run.
|
|
182
|
+
if (st._doctor === null && st._doctorJob === null && !(st.warm && warmDoctor(st))) st.runDoctor();
|
|
176
183
|
return st._doctor;
|
|
177
184
|
},
|
|
178
185
|
});
|
|
@@ -260,6 +267,9 @@ export function webState(theme = null, target = null) {
|
|
|
260
267
|
st.refresh = (opts = {}) => {
|
|
261
268
|
st.refreshOwn(opts);
|
|
262
269
|
for (const v of st._views.values()) v.refreshOwn(opts);
|
|
270
|
+
// Every job ends here, and the console asks the overview right after: start the new verdict
|
|
271
|
+
// now, on its thread, rather than inside that request (~12 s of a frozen console).
|
|
272
|
+
if (st.warm && opts.doctor !== false) warmDoctor(st);
|
|
263
273
|
};
|
|
264
274
|
return st;
|
|
265
275
|
}
|
|
@@ -268,43 +278,54 @@ export function webState(theme = null, target = null) {
|
|
|
268
278
|
const WARM_DOCTOR_LIMIT_MS = 180_000;
|
|
269
279
|
|
|
270
280
|
/**
|
|
271
|
-
* Run the doctor
|
|
272
|
-
*
|
|
273
|
-
*
|
|
281
|
+
* Run the doctor ON ITS OWN THREAD: right after the server binds, and on a serving daemon
|
|
282
|
+
* (`st.warm`) after every refresh, on a cold cache and for `/api/doctor?fresh=1`. On the event loop
|
|
283
|
+
* this run held every request of a cold daemon for 13-24 s, past `BootSplash`'s stall at 8 s, and
|
|
284
|
+
* froze the console ~12 s after every job. Until it lands `st.doctor` is null and `/api/doctor`
|
|
285
|
+
* waits on the promise this returns. A new run stops the thread of the one it replaces: its
|
|
286
|
+
* verdict would be dropped anyway, and a burst of writes must not stack CPU-bound threads.
|
|
274
287
|
*
|
|
275
288
|
* A verdict is stamped only while its job is still the current one: `refresh`, `selectView` and a
|
|
276
289
|
* newer run all clear `_doctorJob`, and the daemon must not serve what a mutation made stale. A
|
|
277
|
-
*
|
|
278
|
-
*
|
|
279
|
-
*
|
|
290
|
+
* thread that dies (an `error`, or an exit with no verdict) is stamped as a FAILED verdict too:
|
|
291
|
+
* left cold, a serving daemon's getter would start a new thread on every overview poll and read
|
|
292
|
+
* "checking" for good. The `error` listener is not optional, an unheard worker error is uncaught
|
|
293
|
+
* and kills the daemon. `unref`: a stopping daemon does not wait for it. `script` is the worker's
|
|
294
|
+
* module, for a test that needs a thread that dies.
|
|
280
295
|
*
|
|
281
296
|
* A HUNG run would leave `/api/doctor` unanswered and the console polling for good, so past
|
|
282
297
|
* `limitMs` it is stopped and stamped as a FAILED verdict: unknown is never a green. Re-run clears it.
|
|
283
298
|
*/
|
|
284
|
-
export function warmDoctor(st, limitMs = WARM_DOCTOR_LIMIT_MS
|
|
299
|
+
export function warmDoctor(st, limitMs = WARM_DOCTOR_LIMIT_MS,
|
|
300
|
+
script = new URL('./doctor-worker.mjs', import.meta.url)) {
|
|
285
301
|
if (st._doctor !== null || st._doctorJob !== null) return st._doctorJob;
|
|
302
|
+
st._doctorWorker?.terminate();
|
|
303
|
+
st._doctorWorker = null;
|
|
286
304
|
let worker;
|
|
287
305
|
try {
|
|
288
|
-
worker = new Worker(
|
|
289
|
-
{ workerData: { theme: st.theme } });
|
|
306
|
+
worker = new Worker(script, { workerData: { theme: st.theme } });
|
|
290
307
|
} catch { return null; }
|
|
291
308
|
worker.unref();
|
|
309
|
+
st._doctorWorker = worker;
|
|
292
310
|
const job = new Promise((done) => {
|
|
293
|
-
const
|
|
311
|
+
const failed = (said) => {
|
|
294
312
|
if (st._doctorJob === job) {
|
|
295
|
-
const said = `[doctor] the warm-up run did not finish in ${limitMs / 1000} s, so nothing was checked`;
|
|
296
313
|
st.stampDoctor([said], [], [{ check: 'warm_up', label: 'Warm-up run', problems: [said] }]);
|
|
297
314
|
}
|
|
315
|
+
};
|
|
316
|
+
const limit = setTimeout(() => {
|
|
317
|
+
failed(`[doctor] the warm-up run did not finish in ${limitMs / 1000} s, so nothing was checked`);
|
|
298
318
|
worker.terminate();
|
|
299
319
|
}, limitMs);
|
|
300
320
|
limit.unref();
|
|
301
321
|
worker.once('message', (r) => {
|
|
302
322
|
if (st._doctorJob === job) st.stampDoctor(r.problems, r.themes, r.groups);
|
|
303
323
|
});
|
|
304
|
-
worker.once('error', () =>
|
|
305
|
-
worker.once('exit', () => {
|
|
324
|
+
worker.once('error', (e) => failed(`[doctor] the warm-up run failed: ${e?.message ?? e}`));
|
|
325
|
+
worker.once('exit', (code) => {
|
|
306
326
|
clearTimeout(limit);
|
|
307
|
-
|
|
327
|
+
failed(`[doctor] the warm-up run ended (code ${code}) without a verdict, so nothing was checked`);
|
|
328
|
+
if (st._doctorWorker === worker) st._doctorWorker = null;
|
|
308
329
|
done();
|
|
309
330
|
});
|
|
310
331
|
});
|