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
package/js/hosts/settings.mjs
CHANGED
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
*/
|
|
36
36
|
import { existsSync, mkdirSync, renameSync, rmSync, unlinkSync } from 'node:fs';
|
|
37
37
|
import path from 'node:path';
|
|
38
|
+
import { blockDelimiters, blockSpan } from '../lib/managed-block.mjs';
|
|
38
39
|
import { readText, writeText, isOsError } from '../lib/fs.mjs';
|
|
39
40
|
import {
|
|
40
41
|
jsonDumps, jsonDumpsCompact, jsonDumpsIndent, parseJson, deepEquals, formatRepr,
|
|
@@ -272,6 +273,10 @@ function defaultPermission(doctrines = null, excluded = [], deletionGate = true)
|
|
|
272
273
|
const OWNED_BASH = ['git commit*', 'git push*',
|
|
273
274
|
...PUSH_CHAIN.flatMap(([keys]) => keys)];
|
|
274
275
|
|
|
276
|
+
/** The verdict Geneseed itself writes for each owned key — what "still reads as ours" means. */
|
|
277
|
+
const OWNED_VERDICT = new Map([['git commit*', 'ask'], ['git push*', 'ask']]);
|
|
278
|
+
for (const [keys, verdict] of PUSH_CHAIN) for (const k of /** @type {string[]} */ (keys)) OWNED_VERDICT.set(k, /** @type {string} */ (verdict));
|
|
279
|
+
|
|
275
280
|
/**
|
|
276
281
|
* Bring an ALREADY-WRITTEN `permission` block back into line with the pack selection, and
|
|
277
282
|
* touch nothing else. Returns `[changed, stranded]` — whether anything moved, and the owned
|
|
@@ -293,16 +298,27 @@ const OWNED_BASH = ['git commit*', 'git push*',
|
|
|
293
298
|
* thing to want, and the value Geneseed writes precisely because it is the obvious one — had
|
|
294
299
|
* it DELETED by a pack-off build.
|
|
295
300
|
*
|
|
296
|
-
*
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
*
|
|
301
|
+
* THE RECORD IS THE MANIFEST'S `bash_gates` (5.2.0), the `bash` twin of `skill_denies` and
|
|
302
|
+
* `edit_asks`: the keys an emit itself ADDED, because they were absent when it ran. `record` is
|
|
303
|
+
* the previous manifest's list, as a Set, updated in place. A key that was already there, at
|
|
304
|
+
* any value, is the user's and is never claimed — the value is what a user would write too, and
|
|
305
|
+
* the carrier's `Active packs:` marker cannot stand in for a record either: this same emit
|
|
306
|
+
* rewrites it BEFORE `mergeOpencodeJson` runs, so it answers with the NEW selection and would
|
|
307
|
+
* licence every removal. (This docblock once ruled the record out as "a new marker file"; the
|
|
308
|
+
* manifest has since carried two such records, so it is one more key, not one more file.)
|
|
309
|
+
*
|
|
310
|
+
* So an unwanted owned key goes only when BOTH hold: it is recorded, and it still reads
|
|
311
|
+
* Geneseed's own verdict (`OWNED_VERDICT`) — the record licenses taking back our entry, not
|
|
312
|
+
* whatever a user has since put under that key. Anything else stays and is reported as
|
|
313
|
+
* `stranded`, so the user is told rather than left to discover it.
|
|
314
|
+
*
|
|
315
|
+
* `pruneAll` (`--prune-gates`) IS THE USER SAYING "THEY ARE YOURS" for an install that predates
|
|
316
|
+
* the record: every `opencode.json` written before 5.2.0 has the gates and no `bash_gates`, so
|
|
317
|
+
* without it they would be stranded for good. For that one build it stands in for the record;
|
|
318
|
+
* the value check stays, so an entry the user re-scoped is still kept. One-shot: no marker
|
|
319
|
+
* records it and no rebuild replays it.
|
|
304
320
|
*
|
|
305
|
-
*
|
|
321
|
+
* A stranded gate is wired for a rule this build does not make binding, which is the
|
|
306
322
|
* FAIL-CLOSED direction — the boundary asks for a confirmation the constitution no longer
|
|
307
323
|
* compels, exactly as the commit skill's own consent step does with the pack off. The unsafe
|
|
308
324
|
* direction, a rule with no gate behind it, cannot occur here. A FRESH file is unaffected:
|
|
@@ -319,10 +335,11 @@ const OWNED_BASH = ['git commit*', 'git push*',
|
|
|
319
335
|
* Returns a third element, `opaque`: the shape reason wiring was impossible, or `null`. The
|
|
320
336
|
* caller warns on it. This is the one branch where the boundary can end up with NO Geneseed
|
|
321
337
|
* gate at all while the constitution states the rule — the unsafe direction — so it must not
|
|
322
|
-
* also be the silent one.
|
|
338
|
+
* also be the silent one. `removed` collects the keys taken back, for the commented-`.jsonc`
|
|
339
|
+
* branch, which cannot write and has to name them instead.
|
|
323
340
|
* @returns {[boolean, string[], string | null]}
|
|
324
341
|
*/
|
|
325
|
-
function reconcileOpencodePermission(perm, want) {
|
|
342
|
+
function reconcileOpencodePermission(perm, want, record = new Set(), pruneAll = false, removed = []) {
|
|
326
343
|
// A `permission` that is not an object, or whose `bash` is not one — OpenCode also accepts a
|
|
327
344
|
// bare `"bash": "allow"` — is a shape this function has no owned keys inside of. Leaving it
|
|
328
345
|
// exactly as found is the whole point; rewriting it into a map would DELETE a blanket policy
|
|
@@ -335,12 +352,23 @@ function reconcileOpencodePermission(perm, want) {
|
|
|
335
352
|
const bash = fresh ? {} : get(perm, 'bash');
|
|
336
353
|
let changed = false;
|
|
337
354
|
const stranded = [];
|
|
355
|
+
let addedAny = false;
|
|
338
356
|
for (const k of OWNED_BASH) {
|
|
339
357
|
if (has(want.bash, k)) {
|
|
340
|
-
if (!has(bash, k)) { bash[k] = want.bash[k]; changed = true; }
|
|
341
|
-
} else if (has(bash, k))
|
|
358
|
+
if (!has(bash, k)) { bash[k] = want.bash[k]; changed = addedAny = true; record.add(k); }
|
|
359
|
+
} else if (has(bash, k)) {
|
|
360
|
+
if ((record.has(k) || pruneAll) && bash[k] === OWNED_VERDICT.get(k)) {
|
|
361
|
+
delete bash[k];
|
|
362
|
+
removed.push(k);
|
|
363
|
+
changed = true;
|
|
364
|
+
} else stranded.push(k);
|
|
365
|
+
// Taken back, or re-scoped by the user since: either way no longer ours to remember.
|
|
366
|
+
record.delete(k);
|
|
367
|
+
} else record.delete(k);
|
|
342
368
|
}
|
|
343
|
-
if (
|
|
369
|
+
if (addedAny && fresh) perm.bash = bash;
|
|
370
|
+
// The last gate out takes the map with it, as uninstall drops an emptied `permission.skill`.
|
|
371
|
+
if (removed.length && !fresh && !Object.keys(bash).length) delete perm.bash;
|
|
344
372
|
return [changed, stranded, null];
|
|
345
373
|
}
|
|
346
374
|
|
|
@@ -619,9 +647,12 @@ export function atomicWriteJson(p, config) {
|
|
|
619
647
|
* `result.skillsAdded` is set to the `permission.skill` denies this call added ONLY when the
|
|
620
648
|
* file on disk now matches what it computed (written, or nothing to change). Left unset on
|
|
621
649
|
* every path that wrote nothing — unreadable, not an object, commented `.jsonc`, write
|
|
622
|
-
* failure — so the caller keeps its previous record rather than claiming denies never written.
|
|
650
|
+
* failure — so the caller keeps its previous record rather than claiming denies never written.
|
|
651
|
+
* `result.bashGates` (the next `bash_gates`, from `oldGates`) follows the same rule.
|
|
652
|
+
* `pruneGates` is `--prune-gates`: see `reconcileOpencodePermission`. */
|
|
623
653
|
export function mergeOpencodeJson(p, agentPath, doctrines = null, excluded = [], skillNames = [],
|
|
624
|
-
staleSkillNames = [], result = {}, deletionGate = true, editAsks = [], oldEdit = null
|
|
654
|
+
staleSkillNames = [], result = {}, deletionGate = true, editAsks = [], oldEdit = null,
|
|
655
|
+
oldGates = [], pruneGates = false) {
|
|
625
656
|
const target = opencodeTarget(p);
|
|
626
657
|
let config = { $schema: OPENCODE_SCHEMA, instructions: [] };
|
|
627
658
|
const { state, data, hadComments, error } = loadJsonObject(target);
|
|
@@ -655,11 +686,16 @@ export function mergeOpencodeJson(p, agentPath, doctrines = null, excluded = [],
|
|
|
655
686
|
let skillOpaque = null;
|
|
656
687
|
let permIsObject = true;
|
|
657
688
|
const added = [];
|
|
689
|
+
const gates = new Set(oldGates);
|
|
690
|
+
const gatesRemoved = [];
|
|
691
|
+
let permOther = false; // a `permission.skill` or `.edit` change, as opposed to a bash gate's
|
|
658
692
|
// The edit record is a copy, filled in place, and handed back only on the paths that wrote.
|
|
659
693
|
const edit = { asks: [...((oldEdit && oldEdit.asks) || [])], shorthand: (oldEdit && oldEdit.shorthand) || null };
|
|
660
694
|
let editNote = null;
|
|
661
695
|
if (addPerm) {
|
|
662
696
|
config.permission = defaultPermission(doctrines, excluded, deletionGate);
|
|
697
|
+
gates.clear();
|
|
698
|
+
for (const k of Object.keys(config.permission.bash)) gates.add(k);
|
|
663
699
|
if (skillNames.length) {
|
|
664
700
|
config.permission.skill = defaultSkillPermission(skillNames);
|
|
665
701
|
added.push(...skillNames);
|
|
@@ -669,7 +705,7 @@ export function mergeOpencodeJson(p, agentPath, doctrines = null, excluded = [],
|
|
|
669
705
|
const perm = get(config, 'permission');
|
|
670
706
|
permIsObject = isDict(perm);
|
|
671
707
|
[permChanged, stranded, opaque] = reconcileOpencodePermission(perm,
|
|
672
|
-
defaultPermission(doctrines, excluded, deletionGate));
|
|
708
|
+
defaultPermission(doctrines, excluded, deletionGate), gates, pruneGates, gatesRemoved);
|
|
673
709
|
// Independent of the `bash` shape: a `permission.bash` the build cannot wire into must
|
|
674
710
|
// not also block the UNRELATED `permission.skill` key from being reconciled.
|
|
675
711
|
if (permIsObject) {
|
|
@@ -680,6 +716,7 @@ export function mergeOpencodeJson(p, agentPath, doctrines = null, excluded = [],
|
|
|
680
716
|
let editChanged;
|
|
681
717
|
[editChanged, editNote] = reconcileOpencodeEditPermission(perm, editAsks, edit);
|
|
682
718
|
permChanged = permChanged || editChanged;
|
|
719
|
+
permOther = skillChanged || editChanged;
|
|
683
720
|
}
|
|
684
721
|
}
|
|
685
722
|
// The shape said no. This is the direction the residue warning above is NOT — a rule stated
|
|
@@ -713,8 +750,9 @@ export function mergeOpencodeJson(p, agentPath, doctrines = null, excluded = [],
|
|
|
713
750
|
process.stderr.write(`[geneseed] WARN: ${path.basename(target)} keeps `
|
|
714
751
|
+ `${stranded.map((k) => jsonDumps(k)).join(', ')} under "permission".bash — the `
|
|
715
752
|
+ 'rule behind those gates (a doctrine, or the deletion gate) is off in this build, but '
|
|
716
|
-
+ 'Geneseed
|
|
717
|
-
+ '
|
|
753
|
+
+ 'Geneseed has no record that it wrote them, so it leaves them. Run this build once '
|
|
754
|
+
+ 'with --prune-gates to remove those still set as Geneseed writes them, or delete them '
|
|
755
|
+
+ 'by hand.\n');
|
|
718
756
|
}
|
|
719
757
|
if (editNote) {
|
|
720
758
|
process.stderr.write(`[geneseed] WARN: "permission"."edit" in ${path.basename(target)} `
|
|
@@ -730,9 +768,20 @@ export function mergeOpencodeJson(p, agentPath, doctrines = null, excluded = [],
|
|
|
730
768
|
if (!addInstr && !permChanged && !addLsp && !addDepth) {
|
|
731
769
|
result.skillsAdded = added;
|
|
732
770
|
result.editRecord = edit;
|
|
771
|
+
result.bashGates = [...gates];
|
|
733
772
|
return target;
|
|
734
773
|
}
|
|
735
774
|
if (path.extname(target) === '.jsonc' && hadComments) {
|
|
775
|
+
// Named, since this branch cannot take them out; `bash_gates` keeps its old value (the
|
|
776
|
+
// caller's rule for a merge that wrote nothing), so they are still ours on the next emit.
|
|
777
|
+
if (gatesRemoved.length) {
|
|
778
|
+
process.stderr.write(`[geneseed] WARN: ${path.basename(target)} has comments, so it is `
|
|
779
|
+
+ 'not rewritten: remove these from its "permission".bash by hand — the rule behind '
|
|
780
|
+
+ `them is off in this build: ${gatesRemoved.map((k) => jsonDumps(k)).join(', ')}.\n`);
|
|
781
|
+
// Nothing but removals: the paste-in advice below is for what a file is MISSING.
|
|
782
|
+
const gateAdds = [...gates].some((k) => !oldGates.includes(k));
|
|
783
|
+
if (!addInstr && !addPerm && !gateAdds && !permOther && !addLsp && !addDepth) return target;
|
|
784
|
+
}
|
|
736
785
|
// ⚠ THE TWO CASES GIVE OPPOSITE ADVICE, and telling a file that HAS a `permission` key to
|
|
737
786
|
// add one is how the first cut of this got it wrong. `add` = there is no block, here is the
|
|
738
787
|
// whole one; `reconcile` = there is a block and it is missing gates this build wires, and
|
|
@@ -752,6 +801,7 @@ export function mergeOpencodeJson(p, agentPath, doctrines = null, excluded = [],
|
|
|
752
801
|
atomicWriteJson(target, config);
|
|
753
802
|
result.skillsAdded = added;
|
|
754
803
|
result.editRecord = edit;
|
|
804
|
+
result.bashGates = [...gates];
|
|
755
805
|
} catch (e) {
|
|
756
806
|
if (!isOsError(e)) throw e;
|
|
757
807
|
process.stderr.write(`[geneseed] WARN: could not write ${target} (${e.message}) — `
|
|
@@ -1350,7 +1400,8 @@ export function settingsIntegrityCheck(p, managed, expect = 'present') {
|
|
|
1350
1400
|
return flush();
|
|
1351
1401
|
}
|
|
1352
1402
|
|
|
1353
|
-
|
|
1403
|
+
// Where the block is: `blockSpan` (js/lib/managed-block.mjs), shared with the hook-side readers.
|
|
1404
|
+
const delimiters = blockDelimiters;
|
|
1354
1405
|
|
|
1355
1406
|
/**
|
|
1356
1407
|
* `_build_settings._managed_block_write` — 'created' | 'updated' | 'merged'.
|
|
@@ -1365,10 +1416,9 @@ export function managedBlockWrite(p, content, blockId = 'GENESEED') {
|
|
|
1365
1416
|
return 'created';
|
|
1366
1417
|
}
|
|
1367
1418
|
const existing = readText(p);
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
writeText(p, pre + block + lstripNewlines(post));
|
|
1419
|
+
const span = blockSpan(existing, blockId);
|
|
1420
|
+
if (span) {
|
|
1421
|
+
writeText(p, existing.slice(0, span[0]) + block + lstripNewlines(existing.slice(span[1])));
|
|
1372
1422
|
return 'updated';
|
|
1373
1423
|
}
|
|
1374
1424
|
const sep = existing.endsWith('\n') ? '' : '\n';
|
|
@@ -1383,12 +1433,11 @@ export function managedBlockRemove(p, blockId = 'GENESEED', whole = false) {
|
|
|
1383
1433
|
unlinkSync(p);
|
|
1384
1434
|
return;
|
|
1385
1435
|
}
|
|
1386
|
-
const [begin, end] = delimiters(blockId);
|
|
1387
1436
|
const existing = readText(p);
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
const
|
|
1391
|
-
|
|
1437
|
+
const span = blockSpan(existing, blockId);
|
|
1438
|
+
if (!span) return;
|
|
1439
|
+
const rest = stripWhitespace(`${stripTrailingNewlines(existing.slice(0, span[0]))}\n`
|
|
1440
|
+
+ `${lstripNewlines(existing.slice(span[1]))}`);
|
|
1392
1441
|
if (rest) writeText(p, `${rest}\n`);
|
|
1393
1442
|
else unlinkSync(p);
|
|
1394
1443
|
}
|
|
@@ -1414,11 +1463,12 @@ export function opencodeSentinelWrite(cfgDir) {
|
|
|
1414
1463
|
/** `_build_settings._managed_block_read` — the block's inner content, or null. */
|
|
1415
1464
|
export function managedBlockRead(p, blockId = 'GENESEED') {
|
|
1416
1465
|
if (!existsSync(p)) return null;
|
|
1417
|
-
const [begin, end] = delimiters(blockId);
|
|
1418
1466
|
const text = readText(p);
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1467
|
+
const span = blockSpan(text, blockId);
|
|
1468
|
+
if (!span) return null;
|
|
1469
|
+
// Between the two marker lines; an empty block has one newline, which is both ends.
|
|
1470
|
+
const block = text.slice(span[0], span[1]);
|
|
1471
|
+
return stripNewlines(block.slice(block.indexOf('\n') + 1, Math.max(block.lastIndexOf('\n'), 0)));
|
|
1422
1472
|
}
|
|
1423
1473
|
|
|
1424
1474
|
/** `str.lstrip("\n")`; the one copy — `native.mjs` and `opencode.mjs` import it from here. */
|
package/js/inspect/diff.mjs
CHANGED
|
@@ -46,6 +46,7 @@ import {
|
|
|
46
46
|
readJsonMaybe, readMaybe, renderedTier, themeOfDir,
|
|
47
47
|
} from '../hosts/installs.mjs';
|
|
48
48
|
import { hashesOf, ownedState, safeLeaf } from '../hosts/owned.mjs';
|
|
49
|
+
import { hostGlobalInstalls as globalInstalls } from './excludes.mjs';
|
|
49
50
|
import { unifiedDiff, splitLines } from '../lib/udiff.mjs';
|
|
50
51
|
import { printOut, printErr, readText, writeText, isFile } from '../lib/fs.mjs';
|
|
51
52
|
import { NOTES_DIRS, sharedPaths } from '../lib/machine-dir.mjs';
|
|
@@ -527,7 +528,21 @@ export function flushExportNotes() {
|
|
|
527
528
|
}
|
|
528
529
|
|
|
529
530
|
export function cmdDiff(args) {
|
|
530
|
-
|
|
531
|
+
// No `--target`: the global install there is, whatever its host — the OpenCode dir used to be
|
|
532
|
+
// the answer on a Claude-only machine too. Several: the first, named on stderr. None: the
|
|
533
|
+
// OpenCode dir, whose refusal below says what to do. Here and not in `diffCollect`, whose
|
|
534
|
+
// other caller (`upgrade`'s export) keeps its own default.
|
|
535
|
+
let chosen = args.target;
|
|
536
|
+
if (!chosen) {
|
|
537
|
+
const globals = globalInstalls((_h, d) => existsSync(path.join(d, GLOBAL_MANIFEST))
|
|
538
|
+
&& manifestScope(d) !== 'project');
|
|
539
|
+
if (globals.length) chosen = globals[0][1];
|
|
540
|
+
if (globals.length > 1) {
|
|
541
|
+
printErr(`[diff] ${globals.length} global installs found; diffing ${globals[0][1]} `
|
|
542
|
+
+ `(${globals[0][0]}:global). Pass --target for another.\n`);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
const { target, theme, files } = diffCollect({ target: chosen, theme: args.theme });
|
|
531
546
|
if (files === null) {
|
|
532
547
|
if (existsSync(path.join(target, GLOBAL_MANIFEST)) && manifestScope(target) === 'project') {
|
|
533
548
|
printErr(`[diff] ${target} is a PROJECT install — diff only compares GLOBAL `
|
package/js/inspect/doctor.mjs
CHANGED
|
@@ -38,7 +38,7 @@ import {
|
|
|
38
38
|
hookShellProblems, installedDefaults, openclaudeDualHarnessRoots, themeFiles,
|
|
39
39
|
} from '../hosts/installs.mjs';
|
|
40
40
|
import { validateIsVendored } from '../hosts/native.mjs';
|
|
41
|
-
import { printOut } from '../lib/fs.mjs';
|
|
41
|
+
import { printErr, printOut } from '../lib/fs.mjs';
|
|
42
42
|
import { authoringProblems, factoryProblems, loopProblems } from './checks-authoring.mjs';
|
|
43
43
|
import { gateProbe, guardProbe } from './checks-probe.mjs';
|
|
44
44
|
import {
|
|
@@ -189,7 +189,7 @@ export function claudeBobEmitProblems(themeName) {
|
|
|
189
189
|
*/
|
|
190
190
|
export function doctorCollect({
|
|
191
191
|
theme = null, allThemes = false, bundle = null, noBundle = false, groups = null,
|
|
192
|
-
probe = false, probed = null, extraProbeProblems = [],
|
|
192
|
+
probe = false, probed = null, extraProbeProblems = [], onTheme = null,
|
|
193
193
|
} = {}) {
|
|
194
194
|
const available = themeFiles().map(stemOf);
|
|
195
195
|
if (!available.length) return [[], ['[doctor] no themes found']];
|
|
@@ -217,7 +217,9 @@ export function doctorCollect({
|
|
|
217
217
|
if (probeRun && probed) probed.push(...probeRun.probed);
|
|
218
218
|
let problems = [];
|
|
219
219
|
withTempDir((tmp) => {
|
|
220
|
-
for (const themeName of themes) {
|
|
220
|
+
for (const [i, themeName] of themes.entries()) {
|
|
221
|
+
// A sweep of several themes runs for minutes; the caller may say where it is.
|
|
222
|
+
if (onTheme && themes.length > 1) onTheme(i + 1, themes.length, themeName);
|
|
221
223
|
const out = path.join(tmp, themeName);
|
|
222
224
|
// capture_output=True: BOTH streams, unlike the emits below, which redirect stdout
|
|
223
225
|
// only. A failing build's stderr is not doctor's output either — the return code is.
|
|
@@ -302,6 +304,8 @@ function doctorReport(args, guard) {
|
|
|
302
304
|
theme: args.theme, allThemes: Boolean(args.all), bundle: args.bundle,
|
|
303
305
|
noBundle: Boolean(args.noBundle), probe: Boolean(args.probe), probed,
|
|
304
306
|
extraProbeProblems: guard ? guard.problems : [],
|
|
307
|
+
// stderr, so the verdict on stdout is the bytes it was; `--all` took ~2 min 40 s in silence.
|
|
308
|
+
onTheme: (n, total, name) => printErr(`[doctor] theme ${n}/${total}: ${name}\n`),
|
|
305
309
|
});
|
|
306
310
|
if (!themes.length) {
|
|
307
311
|
printOut(`${collected.length ? collected[0] : '[doctor] no themes found'}\n`);
|
package/js/inspect/excludes.mjs
CHANGED
|
@@ -55,21 +55,33 @@ function worktreeNote(host, cfg, repo) {
|
|
|
55
55
|
+ `to the repo's ${marker}/settings.json: "claudeMdExcludes": ["${claudeMdEntry(cfg)}"]`;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
/**
|
|
59
|
-
|
|
58
|
+
/**
|
|
59
|
+
* `[host, configDir]` for each host whose GLOBAL config dir `has` accepts, in `HOSTS` order —
|
|
60
|
+
* THE one walk over the hosts' global dirs. `exclude` tests for the manifest; `uninstall`,
|
|
61
|
+
* `version` and `diff` pass their own test to pick a no-`--target` default.
|
|
62
|
+
*
|
|
63
|
+
* HERE, not in `maintain/uninstall.mjs`: every global emit runs the fold, the fold reaches this
|
|
64
|
+
* module, and `tests/unit/hook_cli.test.mjs` keeps js/maintain out of the fold's import graph.
|
|
65
|
+
*/
|
|
66
|
+
export function hostGlobalInstalls(has) {
|
|
60
67
|
const out = [];
|
|
61
68
|
for (const { host, configDir } of HOSTS) {
|
|
62
|
-
let cfg;
|
|
63
69
|
try {
|
|
64
|
-
|
|
70
|
+
const dir = configDir();
|
|
71
|
+
if (has(host, dir)) out.push([host, dir]);
|
|
65
72
|
} catch {
|
|
66
|
-
continue; // a broken resolver must not kill the CLI
|
|
73
|
+
continue; // a broken resolver, or an unreadable dir, must not kill the CLI
|
|
67
74
|
}
|
|
68
|
-
if (isFile(path.join(cfg, GLOBAL_MANIFEST))) out.push({ host, cfg });
|
|
69
75
|
}
|
|
70
76
|
return out;
|
|
71
77
|
}
|
|
72
78
|
|
|
79
|
+
/** `_global_installs` — every host whose GLOBAL config dir carries a Geneseed manifest. */
|
|
80
|
+
function globalInstalls() {
|
|
81
|
+
return hostGlobalInstalls((_host, cfg) => isFile(path.join(cfg, GLOBAL_MANIFEST)))
|
|
82
|
+
.map(([host, cfg]) => ({ host, cfg }));
|
|
83
|
+
}
|
|
84
|
+
|
|
73
85
|
/** `_read_excludes` — the file, or the seeded stub's shape when it is absent or unusable. */
|
|
74
86
|
function readExcludes(cfg) {
|
|
75
87
|
try {
|
package/js/inspect/status.mjs
CHANGED
|
@@ -57,7 +57,8 @@ import { pendingDrafts } from '../hosts/hooks-context.mjs';
|
|
|
57
57
|
import { factCount } from '../hosts/memory-files.mjs';
|
|
58
58
|
import { lastStoreReport } from '../hosts/store-watch.mjs';
|
|
59
59
|
import { hookShimPath, shimDead } from '../hosts/shim.mjs';
|
|
60
|
-
import { printOut } from '../lib/fs.mjs';
|
|
60
|
+
import { printErr, printOut } from '../lib/fs.mjs';
|
|
61
|
+
import { hostGlobalInstalls as globalInstalls } from './excludes.mjs';
|
|
61
62
|
import { readDefaultInstall, sharedPaths } from '../lib/machine-dir.mjs';
|
|
62
63
|
import { normcase } from '../lib/paths.mjs';
|
|
63
64
|
import { renamedFilesIn } from '../build/stubs.mjs';
|
|
@@ -79,7 +80,14 @@ export function cmdVersion(args) {
|
|
|
79
80
|
const current = sourceFingerprint(cfg);
|
|
80
81
|
// `Path(args.target).expanduser().resolve()` — `resolvePath` already expands, so the tilde
|
|
81
82
|
// is handled once rather than twice.
|
|
82
|
-
let target = args.target ? resolvePath(args.target) :
|
|
83
|
+
let target = args.target ? resolvePath(args.target) : null;
|
|
84
|
+
// No `--target`: the global install the user picked as the default leads, as it leads
|
|
85
|
+
// `status`'s version row (`statusData`), so the two verbs name the same install.
|
|
86
|
+
if (!target) {
|
|
87
|
+
const picked = pickedInstall();
|
|
88
|
+
if (picked && picked[1] === 'global' && readVersion(picked[2]) !== null) target = picked[2];
|
|
89
|
+
}
|
|
90
|
+
target ??= opencodeConfigDir();
|
|
83
91
|
let installed = readVersion(target);
|
|
84
92
|
if (installed === null) {
|
|
85
93
|
// A claude/bob/openclaude-only machine must not report "no install detected". The bundle
|
|
@@ -90,6 +98,15 @@ export function cmdVersion(args) {
|
|
|
90
98
|
if (v) { installed = v; target = base; break; }
|
|
91
99
|
}
|
|
92
100
|
}
|
|
101
|
+
// The walk above already finds a Claude-only machine's install; with several, it shows the
|
|
102
|
+
// first, and says so rather than letting the reader take it for the only one.
|
|
103
|
+
if (!args.target) {
|
|
104
|
+
const globals = globalInstalls((_h, d) => readVersion(d) !== null);
|
|
105
|
+
if (globals.length > 1) {
|
|
106
|
+
printErr(`[version] ${globals.length} global installs found; showing ${target}. `
|
|
107
|
+
+ 'Pass --target for another.\n');
|
|
108
|
+
}
|
|
109
|
+
}
|
|
93
110
|
printOut(`[version] source: ${current} (${ROOT})\n`);
|
|
94
111
|
printOut(`[version] installed: ${installed || '(none found)'}`
|
|
95
112
|
+ (installed ? ` (${target})` : '') + '\n');
|
|
@@ -306,8 +323,10 @@ export function statusData() {
|
|
|
306
323
|
try { otherCfg.push(fn()); } catch { /* a missing host dir must not sink status */ }
|
|
307
324
|
}
|
|
308
325
|
const hostDirs = [...(cfgDir ? [cfgDir] : []), ...otherCfg, path.join(process.cwd(), 'Harness')];
|
|
309
|
-
// Same walk as `cmdVersion`'s fallback, and cwd-relative for the same reason
|
|
310
|
-
|
|
326
|
+
// Same walk as `cmdVersion`'s fallback, and cwd-relative for the same reason — led by the
|
|
327
|
+
// global install the `install` row names, so the `version` row describes that install.
|
|
328
|
+
const lead = picked && picked[1] === 'global' ? [picked[2]] : [];
|
|
329
|
+
for (const base of [...lead, ...hostDirs, process.cwd()]) {
|
|
311
330
|
const v = readVersion(base);
|
|
312
331
|
if (v) { installedFp = v; verTarget = base; break; }
|
|
313
332
|
}
|
|
@@ -391,8 +410,12 @@ function colorEnabled() {
|
|
|
391
410
|
* `_TUI_ASCII` is read from the environment at CALL time, not import time. Same value for a
|
|
392
411
|
* process that runs one verb and exits; spelled this way because a module-level constant in
|
|
393
412
|
* a file the tests import would freeze at whatever the test runner's environment was.
|
|
413
|
+
*
|
|
414
|
+
* `boxed` false is the face off a terminal: the title, the rows and the verdict, with no frame
|
|
415
|
+
* and no padding to the widest row. A long `installs` row made every boxed line ~210 columns,
|
|
416
|
+
* which a pipe, a log or an agent reads as 4–5 kB of spaces.
|
|
394
417
|
*/
|
|
395
|
-
export function statusLines(d, color = false) {
|
|
418
|
+
export function statusLines(d, color = false, boxed = true) {
|
|
396
419
|
const asc = Boolean(process.env.GENESEED_TUI_ASCII);
|
|
397
420
|
const [H, V] = asc ? ['-', '|'] : ['─', '│'];
|
|
398
421
|
const [TL, TR, BL, BR, LT, RT] = asc
|
|
@@ -429,7 +452,10 @@ export function statusLines(d, color = false) {
|
|
|
429
452
|
+ `doctrine rules in ${d.packs}/${d.packs_total} packs`]);
|
|
430
453
|
}
|
|
431
454
|
if (d.agent_md) {
|
|
432
|
-
|
|
455
|
+
// The row is the OpenCode global's health, shown whichever install the `install` row names;
|
|
456
|
+
// under another host's install it says whose AGENT.md it is, so the two rows cannot be read
|
|
457
|
+
// as one install.
|
|
458
|
+
rows.push([d.emit === 'opencode-global' ? 'AGENT.md' : 'opencode AGENT.md',
|
|
433
459
|
`${d.agent_md} (${d.agent_md_present ? 'present' : 'MISSING'})`]);
|
|
434
460
|
}
|
|
435
461
|
// Conditional for the same recording reason as `constitution` above: the 30 recorded
|
|
@@ -496,6 +522,7 @@ export function statusLines(d, color = false) {
|
|
|
496
522
|
const body = rows.map(([k, v]) => ` ${padEndToWidth(k, labelW)} ${v}`);
|
|
497
523
|
const verdict = ` ${mark} ${d.version_verdict}`;
|
|
498
524
|
const title = ` ${badge} Geneseed ${emdash} status `;
|
|
525
|
+
if (!boxed) return [title.trim(), ...body, verdict];
|
|
499
526
|
const width = Math.max(...body.map(codePointLength), codePointLength(verdict), codePointLength(title) + 2);
|
|
500
527
|
|
|
501
528
|
const ac = ANSI_CODES[d.accent] ?? '36';
|
|
@@ -524,6 +551,7 @@ export function cmdStatus(args) {
|
|
|
524
551
|
printOut(`${JSON.stringify(d, null, 2)}\n`);
|
|
525
552
|
return 0;
|
|
526
553
|
}
|
|
527
|
-
|
|
554
|
+
// The box only on a terminal; NO_COLOR on a terminal still gets it, so this is not `color`.
|
|
555
|
+
for (const line of statusLines(d, colorEnabled(), Boolean(process.stdout.isTTY))) printOut(`${line}\n`);
|
|
528
556
|
return 0;
|
|
529
557
|
}
|
package/js/inspect/validate.mjs
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* reached — see its row in `tests/ported.json`.
|
|
8
8
|
*/
|
|
9
9
|
import path from 'node:path';
|
|
10
|
+
import { FLAGS, VALUED } from '../build/args.mjs';
|
|
10
11
|
import { buildInto, emitGlobalInto, emitProjectInto } from '../build/driver.mjs';
|
|
11
12
|
import { GATE_SWITCHES } from '../build/source.mjs';
|
|
12
13
|
import { resolvePath } from '../hosts/hosts.mjs';
|
|
@@ -17,6 +18,7 @@ import { validateIsVendored } from '../hosts/native.mjs';
|
|
|
17
18
|
import { printOut, printErr } from '../lib/fs.mjs';
|
|
18
19
|
import { comparePaths } from '../lib/paths.mjs';
|
|
19
20
|
import { stripWhitespace } from '../lib/text.mjs';
|
|
21
|
+
import { cliCommand, formatHelp, helpWidth } from '../ui/cli.mjs';
|
|
20
22
|
import { checkBuild } from './checks-build.mjs';
|
|
21
23
|
import { cmdDoctor } from './doctor.mjs';
|
|
22
24
|
import { isDir, isFile, rglob, withTempDir, within } from './scan.mjs';
|
|
@@ -25,23 +27,45 @@ import { isDir, isFile, rglob, withTempDir, within } from './scan.mjs';
|
|
|
25
27
|
// validate — the generator's `--validate-only`, on this binary because it runs the doctor
|
|
26
28
|
// --------------------------------------------------------------------------------------
|
|
27
29
|
|
|
30
|
+
/** The generator flags `validate` refuses (`cmdValidate`) or has no use for. */
|
|
31
|
+
const NOT_VALIDATE = ['--sync-themes', '--config-dir', '--validate-only'];
|
|
32
|
+
|
|
28
33
|
/**
|
|
29
|
-
* `validate --help`.
|
|
30
|
-
*
|
|
31
|
-
*
|
|
34
|
+
* `validate --help`. Not the borrowed parser's own `-h`, which prints `usage: geneseed-build …`
|
|
35
|
+
* under a program name the user did not type.
|
|
36
|
+
*
|
|
37
|
+
* DERIVED FROM THE GENERATOR'S FLAG TABLES (`VALUED`, `FLAGS`), never typed out: the hand-kept
|
|
38
|
+
* copy it replaces had already lost `--no-ownership-gate`, `--prune-gates` and `--force`. Each
|
|
39
|
+
* flag's help and choices are `geneseed build`'s (`cliCommand`), so the two verbs say one thing.
|
|
32
40
|
*/
|
|
33
|
-
export
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
export function validateUsage(width = helpWidth()) {
|
|
42
|
+
const build = new Map(cliCommand('build').options.map((o) => [o.names[0], o]));
|
|
43
|
+
const byDest = new Map();
|
|
44
|
+
for (const [table, isFlag] of [[VALUED, false], [FLAGS, true]]) {
|
|
45
|
+
for (const [flag, dest] of Object.entries(table)) {
|
|
46
|
+
if (NOT_VALIDATE.includes(flag)) continue;
|
|
47
|
+
if (byDest.has(dest)) { byDest.get(dest).names.push(flag); continue; }
|
|
48
|
+
const row = build.get(flag);
|
|
49
|
+
const choices = row?.choices ?? null;
|
|
50
|
+
// argparse's metavar is the dest upper-cased; the driver's dests are camelCase, so the
|
|
51
|
+
// flag spells it (`EXCLUDE_RULES`, as `build --help` shows), unless choices stand in.
|
|
52
|
+
const metavar = row?.metavar ?? (isFlag || choices ? null
|
|
53
|
+
: flag.slice(2).toUpperCase().replace(/-/g, '_'));
|
|
54
|
+
byDest.set(dest, {
|
|
55
|
+
names: [flag], dest, metavar, help: row?.help ?? '',
|
|
56
|
+
choices, required: false, nargs: isFlag ? '0' : null, is_flag: isFlag,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// `-v`/`--verbose` is the one flag `build` does not forward, so the table has no help for it.
|
|
61
|
+
const verbose = byDest.get('verbose');
|
|
62
|
+
if (verbose && !verbose.help) verbose.help = 'list every file the dry run would write';
|
|
63
|
+
return formatHelp({
|
|
64
|
+
options: [...byDest.values()],
|
|
65
|
+
description: "Render and emit into a throwaway sandbox, run the doctor's checks, and write "
|
|
66
|
+
+ `nothing real. Takes the generator's render flags except ${NOT_VALIDATE.slice(0, 2).join(' and ')}.`,
|
|
67
|
+
}, 'geneseed validate', width);
|
|
68
|
+
}
|
|
45
69
|
|
|
46
70
|
/**
|
|
47
71
|
* Capture the streams of an IN-PROCESS call.
|
|
@@ -149,13 +173,12 @@ export function cmdValidate(args) {
|
|
|
149
173
|
} catch (e) {
|
|
150
174
|
// A DELIBERATE refusal from the render (an unknown theme, an incomplete source).
|
|
151
175
|
//
|
|
152
|
-
//
|
|
153
|
-
//
|
|
154
|
-
//
|
|
155
|
-
//
|
|
176
|
+
// The refusal already explained itself on stderr (`loadTheme`'s sentence) on the way out;
|
|
177
|
+
// what crosses the seam is only its exit code. So this line names what failed and adds
|
|
178
|
+
// nothing after it: it used to end in that bare code (`: 1`), which read as a message
|
|
179
|
+
// cut short. The code is the process's exit status, where it belongs.
|
|
156
180
|
if (e && e.exitCode !== undefined) {
|
|
157
|
-
printOut(`[validate-only] render/emit FAILED for theme '${args.theme}' `
|
|
158
|
-
+ `emit '${emit}': ${e.exitCode}\n`);
|
|
181
|
+
printOut(`[validate-only] render/emit FAILED for theme '${args.theme}' emit '${emit}'\n`);
|
|
159
182
|
return null;
|
|
160
183
|
}
|
|
161
184
|
throw e;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The managed block: the `<!-- BEGIN GENESEED -->` … `<!-- END GENESEED -->` span Geneseed keeps
|
|
3
|
+
* inside a file the user co-owns (`CLAUDE.md`, `AGENTS.md`).
|
|
4
|
+
*
|
|
5
|
+
* ONE DEFINITION OF WHERE IT IS, for the writer (`js/hosts/settings.mjs`) and for every reader
|
|
6
|
+
* on the hook path (`js/hosts/hosts.mjs`, `js/hosts/ownership-gate.mjs`). They used to be five
|
|
7
|
+
* copies of one regex, because the hook path may not import `settings.mjs`, and when the writer
|
|
8
|
+
* learnt to read a marker only as a whole line the readers went on matching it anywhere. No
|
|
9
|
+
* imports at all, so the hook path pays nothing for it.
|
|
10
|
+
*
|
|
11
|
+
* The two OpenCode plugins cannot import this (a plugin is one self-contained file), so each
|
|
12
|
+
* carries `BLOCK_RE` below by value; `tests/unit/managed_block.test.mjs` holds the copies equal.
|
|
13
|
+
*
|
|
14
|
+
* A MARKER IS A WHOLE LINE. The block is written with each marker alone on its line, so that is
|
|
15
|
+
* the only shape read back. Matching the marker text anywhere took a user's sentence ABOUT the
|
|
16
|
+
* block ("everything below the `<!-- BEGIN GENESEED -->` line is generated") for the block's
|
|
17
|
+
* start: the next emit replaced everything from that sentence down to the real END, the user's
|
|
18
|
+
* own rules with it, and said nothing.
|
|
19
|
+
*
|
|
20
|
+
* THE PAIR IS the first END line with a BEGIN line above it, and the LAST such BEGIN. A lone
|
|
21
|
+
* BEGIN left higher up (a hand-deleted block's first line) therefore stays the user's text, with
|
|
22
|
+
* whatever they wrote under it. A file with no such pair has no block.
|
|
23
|
+
*/
|
|
24
|
+
export const blockDelimiters = (blockId = 'GENESEED') => [`<!-- BEGIN ${blockId} -->`, `<!-- END ${blockId} -->`];
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* `[start, stop]`: from the first character of the BEGIN line to the last of the END line (no
|
|
28
|
+
* line ending), or null. Trailing blanks and a `\r` after a marker are allowed: a hook reads
|
|
29
|
+
* the file raw, and on Windows the line ends `\r\n`.
|
|
30
|
+
*/
|
|
31
|
+
export function blockSpan(text, blockId = 'GENESEED') {
|
|
32
|
+
const [begin, end] = blockDelimiters(blockId);
|
|
33
|
+
let at = 0;
|
|
34
|
+
let start = -1;
|
|
35
|
+
for (const line of text.split('\n')) {
|
|
36
|
+
const bare = line.replace(/[ \t\r]+$/, '');
|
|
37
|
+
if (bare === begin) start = at;
|
|
38
|
+
else if (bare === end && start >= 0) return [start, at + bare.length];
|
|
39
|
+
at += line.length + 1;
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The block, markers included, or `''` when the text has none. */
|
|
45
|
+
export function blockOf(text, blockId = 'GENESEED') {
|
|
46
|
+
const span = blockSpan(text, blockId);
|
|
47
|
+
return span ? text.slice(span[0], span[1]) : '';
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** The text with every block removed: what is left is the user's own. */
|
|
51
|
+
export function withoutBlocks(text, blockId = 'GENESEED') {
|
|
52
|
+
let out = text;
|
|
53
|
+
for (let span = blockSpan(out, blockId); span; span = blockSpan(out, blockId)) {
|
|
54
|
+
out = out.slice(0, span[0]) + out.slice(span[1]);
|
|
55
|
+
}
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* How many whole-line markers the text holds, BEGIN and END together. The carrier gate asks when
|
|
61
|
+
* an edit changes this as well as when it changes the block: a marker line added outside the
|
|
62
|
+
* block changes nothing a reader reads today, and is still an edit to the fence itself.
|
|
63
|
+
*/
|
|
64
|
+
export function markerLines(text, blockId = 'GENESEED') {
|
|
65
|
+
const pair = blockDelimiters(blockId);
|
|
66
|
+
return text.split('\n').filter((line) => pair.includes(line.replace(/[ \t\r]+$/, ''))).length;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The same rule as one regex, for the OpenCode plugins, which cannot import this file: a BEGIN
|
|
71
|
+
* line, lazily to the first END line. It differs from `blockSpan` on one input only, a lone
|
|
72
|
+
* BEGIN line above a real block, where it starts at the lone one; a plugin only reads.
|
|
73
|
+
*/
|
|
74
|
+
export const BLOCK_RE_SOURCE = '^<!-- BEGIN GENESEED -->[ \\t]*\\r?\\n[\\s\\S]*?^<!-- END GENESEED -->[ \\t]*\\r?$';
|