geneseed 5.3.1 → 5.5.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 +102 -0
- package/README.md +51 -18
- package/SHIPPED.md +7 -7
- package/adapters/bob/README.md +12 -1
- package/adapters/opencode/README.md +5 -3
- package/adapters/opencode/plugins/geneseed-context.js +77 -10
- package/adapters/opencode/plugins/geneseed-guard.js +106 -22
- package/adapters/opencode/plugins/geneseed-learn.js +641 -6
- package/bin/geneseed-cli.mjs +10 -0
- package/bin/geneseed-hook.mjs +5 -4
- package/docs/PRD.md +1 -1
- package/docs/README.md +1 -0
- package/docs/concepts/agents.md +14 -2
- package/docs/concepts/collaboration.md +2 -2
- package/docs/concepts/enforcement-table.md +5 -2
- package/docs/concepts/exclusions.md +16 -2
- package/docs/concepts/footprint.md +1 -1
- package/docs/concepts/foreman-mode.md +23 -4
- package/docs/concepts/hook-gates.md +4 -4
- package/docs/concepts/hooks.md +25 -7
- package/docs/concepts/host-matrix.md +4 -4
- package/docs/concepts/hosts.md +1 -1
- package/docs/concepts/kits.md +12 -2
- package/docs/concepts/loop-bricks.md +3 -3
- package/docs/concepts/loops.md +6 -4
- package/docs/concepts/ownership.md +1 -1
- package/docs/concepts/rules.md +2 -2
- package/docs/concepts/shared-tier.md +1 -1
- package/docs/concepts/skills.md +21 -1
- package/docs/concepts/themes.md +1 -1
- package/docs/extending.md +73 -29
- package/docs/guides/auto-merge.md +100 -0
- package/docs/guides/choose-your-setup.md +1 -1
- package/docs/guides/headless.md +1 -1
- package/docs/guides/install-clone.md +19 -1
- package/docs/guides/install-scripted.md +8 -2
- package/docs/guides/install.md +20 -2
- package/docs/guides/loop-finish.md +3 -3
- package/docs/guides/loop-running.md +4 -4
- package/docs/guides/project-context.md +1 -1
- package/docs/guides/run-a-factory.md +2 -2
- package/docs/guides/setup-doctrines.md +2 -2
- package/docs/guides/setup-footprint.md +1 -1
- package/docs/guides/uninstall.md +3 -3
- package/docs/guides/upgrade.md +2 -2
- package/docs/guides/worktree.md +1 -1
- package/docs/reference/env-context.md +1 -1
- package/docs/reference/environment.md +4 -2
- package/docs/reference/plugin-activity.md +1 -1
- package/docs/reference/plugin-guard.md +1 -1
- package/docs/reference/plugin-learn.md +5 -1
- package/docs/reference/plugin-workflow.md +1 -1
- package/docs/reference/profiles.md +142 -0
- package/docs/reference/troubleshoot-doctor.md +1 -1
- package/docs/reference/troubleshoot-hooks.md +2 -2
- package/docs/reference/troubleshoot-install.md +3 -3
- package/docs/reference/troubleshoot-tools.md +1 -1
- package/docs/token-footprint.md +11 -6
- package/docs/understand/design-choices-engineering.md +1 -1
- package/docs/understand/enforced-vs-asked.md +1 -1
- package/docs/understand/machine-claude.md +2 -2
- package/docs/understand/on-your-machine.md +1 -1
- package/docs/web-ui.md +8 -6
- package/harness.config.json +1 -1
- package/js/README.md +11 -3
- package/js/build/args.mjs +16 -4
- package/js/build/catalog.mjs +11 -1
- package/js/build/driver.mjs +74 -16
- package/js/build/emit-claude.mjs +32 -5
- package/js/build/emit-opencode.mjs +16 -9
- package/js/build/export.mjs +1 -1
- package/js/build/generate.mjs +12 -157
- package/js/build/notes-migrate.mjs +99 -0
- package/js/build/profile.mjs +326 -0
- package/js/build/render.mjs +110 -8
- package/js/build/retired-skills.mjs +60 -13
- package/js/build/source.mjs +100 -3
- package/js/build/stubs.mjs +4 -1
- package/js/cli-table.json +212 -7
- package/js/hosts/agent-runs.mjs +205 -0
- package/js/hosts/done-checks.mjs +3 -1
- package/js/hosts/hooks-done.mjs +428 -63
- package/js/hosts/hooks-learn.mjs +89 -3
- package/js/hosts/hooks-prims.mjs +44 -4
- package/js/hosts/hooks.mjs +159 -9
- package/js/hosts/hosts.mjs +10 -0
- package/js/hosts/installs.mjs +44 -2
- package/js/hosts/link.mjs +45 -10
- package/js/hosts/native.mjs +61 -7
- package/js/hosts/opencode.mjs +1 -1
- package/js/hosts/settings.mjs +101 -3
- package/js/hosts/spec-feedback.mjs +538 -0
- package/js/hosts/usage.mjs +67 -8
- package/js/inspect/agent-scores.mjs +118 -0
- package/js/inspect/checks-authoring.mjs +2 -1
- package/js/inspect/checks-build.mjs +20 -4
- package/js/inspect/checks-constitution.mjs +32 -0
- package/js/inspect/checks-repo.mjs +27 -2
- package/js/inspect/cost.mjs +6 -5
- package/js/inspect/diff.mjs +46 -8
- package/js/inspect/doctor.mjs +4 -0
- package/js/inspect/inventory.mjs +1 -1
- package/js/inspect/status.mjs +3 -1
- package/js/inspect/validate.mjs +1 -0
- package/js/lib/machine-dir.mjs +8 -0
- package/js/lib/paths.mjs +4 -1
- package/js/maintain/profile-scope.mjs +145 -0
- package/js/maintain/profiles.mjs +486 -0
- package/js/maintain/setup.mjs +413 -15
- package/js/maintain/uninstall.mjs +4 -1
- package/js/maintain/update.mjs +4 -2
- package/js/web/actions.mjs +44 -41
- package/js/web/api.mjs +13 -3
- package/js/web/handler.mjs +8 -0
- package/js/web/jobs.mjs +5 -4
- package/js/web/profiles-api.mjs +201 -0
- package/js/web/routes.mjs +5 -0
- package/package.json +2 -1
- package/profiles/guillaume-claude-global.json +16 -0
- package/profiles/starter.json +14 -0
- package/registry.json +14 -0
- package/src/AGENT.md.tmpl +16 -18
- package/src/agents/_self-improvement.md +15 -7
- package/src/agents/_template.md +4 -2
- package/src/agents/advocate.md +1 -1
- package/src/agents/architect.md +1 -1
- package/src/agents/developer.md +10 -3
- package/src/agents/devops-engineer.md +1 -1
- package/src/agents/docker-expert.md +1 -1
- package/src/agents/docs.md +1 -1
- package/src/agents/empiricist.md +1 -1
- package/src/agents/explorer.md +4 -2
- package/src/agents/framer.md +1 -1
- package/src/agents/historian.md +1 -1
- package/src/agents/kubernetes-specialist.md +1 -1
- package/src/agents/memory-curator.md +1 -1
- package/src/agents/operator.md +1 -1
- package/src/agents/performance.md +1 -1
- package/src/agents/pragmatist.md +1 -1
- package/src/agents/react-engineer.md +1 -1
- package/src/agents/react-reviewer.md +1 -1
- package/src/agents/researcher.md +1 -1
- package/src/agents/reviewer.md +10 -3
- package/src/agents/security.md +1 -1
- package/src/agents/skeptic.md +1 -1
- package/src/agents/spring-boot-engineer.md +1 -1
- package/src/agents/spring-reviewer.md +1 -1
- package/src/agents/spring-security.md +1 -1
- package/src/agents/steward.md +1 -1
- package/src/agents/tester.md +4 -2
- package/src/agents/user-advocate.md +1 -1
- package/src/agents/visionary.md +1 -1
- package/src/bricks/pr-open.md +3 -2
- package/src/doctrines/ops.md +2 -2
- package/src/doctrines/process.md +40 -36
- package/src/factories/analysis-to-build.json +1 -1
- package/src/factories/bug-report-to-fix.json +1 -1
- package/src/factories/issue-to-pr.json +1 -1
- package/src/kits/terminal-tools/rules.md +10 -0
- package/src/kits/terminal-tools.json +13 -0
- package/src/licenses/herdr.txt +201 -0
- package/src/memory/README.md +12 -2
- package/src/modes/foreman.md +25 -9
- package/src/skill-descriptions.json +63 -0
- package/src/skills/_self-improvement.md +42 -24
- package/src/skills/_template.md +3 -1
- package/src/skills/brainstorm.md +35 -22
- package/src/skills/commit.md +17 -17
- package/src/skills/daydream/VENDOR.md +6 -0
- package/src/skills/debug/ci.md +1 -1
- package/src/skills/dependencies.md +3 -3
- package/src/skills/diagram-design/VENDOR.md +4 -0
- package/src/skills/document-project.md +3 -2
- package/src/skills/explain-changes/VENDOR.md +5 -1
- package/src/skills/factory.md +13 -4
- package/src/skills/geneseed.md +4 -2
- package/src/skills/git-history.md +5 -7
- package/src/skills/herdr.md +135 -0
- package/src/skills/loop.md +3 -2
- package/src/skills/opencode-cli.md +84 -0
- package/src/skills/parallel-agents.md +11 -0
- package/src/skills/pipeline.md +3 -3
- package/src/skills/plan.md +5 -4
- package/src/skills/react-view-transitions/VENDOR.md +7 -1
- package/src/skills/release.md +11 -9
- package/src/skills/review-response.md +4 -2
- package/src/skills/rule/approve.md +2 -1
- package/src/skills/rule.md +27 -1
- package/src/skills/ship.md +54 -7
- package/src/skills/skill-forge.md +5 -3
- package/src/skills/token-report/VENDOR.md +5 -1
- package/src/skills/worktree.md +2 -2
- package/src/upstreams.json +9 -2
- package/themes/README.md +3 -1
- package/themes/_TEMPLATE.json +2 -0
- package/themes/biker.json +2 -0
- package/themes/commentator.json +2 -0
- package/themes/cyberpunk.json +2 -0
- package/themes/gamer.json +2 -0
- package/themes/imperial.json +2 -0
- package/themes/joker.json +2 -0
- package/themes/marvin.json +2 -0
- package/themes/mean.json +2 -0
- package/themes/military.json +2 -0
- package/themes/neutral.json +2 -0
- package/themes/pirate.json +2 -0
- package/themes/sports.json +2 -0
- package/themes/verstappen.json +2 -0
- package/themes/wizard.json +2 -0
- package/web/dist/assets/{ActiveLoops-BJJN3P-V.js → ActiveLoops-DOJCPPPc.js} +1 -1
- package/web/dist/assets/Activity-LKsDzsnK.js +1 -0
- package/web/dist/assets/ActivityDetail-DhwTfPm6.js +1 -0
- package/web/dist/assets/{Bonsai-BBl4XXqs.js → Bonsai-CePMLrpr.js} +1 -1
- package/web/dist/assets/{CopyButton-Beven8yn.js → CopyButton-CuoaJ6k7.js} +1 -1
- package/web/dist/assets/Dashboard-D1VKuvLe.js +2 -0
- package/web/dist/assets/Docs-CUrHJKaU.js +5 -0
- package/web/dist/assets/Factories-Ci1XfmSy.js +1 -0
- package/web/dist/assets/{GreenhouseView-Bce212qd.js → GreenhouseView-CNfH2lPK.js} +1 -1
- package/web/dist/assets/Installs-ZHQZM1iS.js +3 -0
- package/web/dist/assets/{JournalView-CV4omyww.js → JournalView-CMsWahkS.js} +1 -1
- package/web/dist/assets/Kits-CkliyK0n.js +1 -0
- package/web/dist/assets/Laws-hh4O3HZ4.js +4 -0
- package/web/dist/assets/{LibRows-Dag1s0ZX.js → LibRows-Brv0Hmkr.js} +1 -1
- package/web/dist/assets/Library-BYmiLjJr.js +3 -0
- package/web/dist/assets/Loops-ytm-xJ68.js +2 -0
- package/web/dist/assets/{OperatorHudView-JmYY1pBR.js → OperatorHudView-KaqCx_HP.js} +1 -1
- package/web/dist/assets/Personal-CmcnRKYE.js +2 -0
- package/web/dist/assets/Settings-tUrpdOfq.js +1 -0
- package/web/dist/assets/{Tabs-8zsyEPSK.js → Tabs-CD7etcGD.js} +1 -1
- package/web/dist/assets/api-CZ-x0iWG.js +1 -0
- package/web/dist/assets/{controls-D4wmg_pl.js → controls-CK7qHA8H.js} +1 -1
- package/web/dist/assets/{index-CRWqKxfY.css → index-Ba_Kg3Af.css} +1 -1
- package/web/dist/assets/index-COKbhFNo.js +6 -0
- package/web/dist/index.html +3 -3
- package/web/dist/assets/Activity-WQ3ykgxU.js +0 -1
- package/web/dist/assets/ActivityDetail-7rt04SkS.js +0 -1
- package/web/dist/assets/Dashboard-BgLArtgu.js +0 -2
- package/web/dist/assets/Docs-B5aHp86J.js +0 -5
- package/web/dist/assets/Factories-BjqzXAw8.js +0 -1
- package/web/dist/assets/Installs-B1OsrHXF.js +0 -3
- package/web/dist/assets/Kits-CW1e7xNa.js +0 -1
- package/web/dist/assets/Laws-1Ckf1lbs.js +0 -4
- package/web/dist/assets/Library-B3FuFLel.js +0 -3
- package/web/dist/assets/Loops-CwqgnLNw.js +0 -2
- package/web/dist/assets/Personal-DKLgLa7Z.js +0 -2
- package/web/dist/assets/Settings-BwErnh-R.js +0 -1
- package/web/dist/assets/api-DLDVY3K-.js +0 -1
- package/web/dist/assets/index-Ce6qF2nG.js +0 -6
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The scope half of `geneseed profile apply` (spec D32, D39): the project folder a profile may be
|
|
3
|
+
* built into, and what a global install of the same host still does inside that folder.
|
|
4
|
+
*
|
|
5
|
+
* SPAWN-FREE, like the rest of `js/maintain/`: the CLI imports it under the `child_process` ban,
|
|
6
|
+
* and the web console's deploy and apply routes import it too, so the folder check has one home.
|
|
7
|
+
*/
|
|
8
|
+
import { accessSync, constants } from 'node:fs';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
|
|
11
|
+
import { GATE_SWITCHES } from '../build/source.mjs';
|
|
12
|
+
import {
|
|
13
|
+
HOSTS, bobConfigDir, claudeConfigDir, expanduser, openclaudeConfigDir, opencodeConfigDir, resolvePath,
|
|
14
|
+
} from '../hosts/hosts.mjs';
|
|
15
|
+
import { gatesOfDir, installState } from '../hosts/installs.mjs';
|
|
16
|
+
import { isDir } from '../lib/fs.mjs';
|
|
17
|
+
import { normcase } from '../lib/paths.mjs';
|
|
18
|
+
import { stripWhitespace } from '../lib/text.mjs';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A folder a PROJECT emit may be built into: `{ root }`, resolved, or `{ error }`.
|
|
22
|
+
*
|
|
23
|
+
* THIS TAKES A RAW PATH, so it is a trust boundary: an existing, writable directory that is not a
|
|
24
|
+
* host's own global config dir (a project emit there would mislabel as the global row and collide
|
|
25
|
+
* on dedup). Moved out of `apiDeployCmd` (js/web/actions.mjs, which spawns) so the CLI's
|
|
26
|
+
* `profile apply --project` and the console share one check; the texts are the console's own.
|
|
27
|
+
*
|
|
28
|
+
* `hosts` are the hosts about to be built there: for each, the folder is also refused when its
|
|
29
|
+
* project marker (`<folder>/.claude`, …) IS that host's global config dir (`markerCollision`) —
|
|
30
|
+
* `--project ~` for Claude Code would otherwise write a project install over the global one.
|
|
31
|
+
*/
|
|
32
|
+
export function checkProjectFolder(rawPath, hosts = []) {
|
|
33
|
+
const raw = stripWhitespace(typeof rawPath === 'string' ? rawPath : '');
|
|
34
|
+
if (!raw) return { error: 'no folder given' };
|
|
35
|
+
let root;
|
|
36
|
+
try {
|
|
37
|
+
root = resolvePath(expanduser(raw));
|
|
38
|
+
} catch {
|
|
39
|
+
return { error: `bad path: ${raw}` };
|
|
40
|
+
}
|
|
41
|
+
if (!isDir(root)) return { error: `not a folder: ${root}` };
|
|
42
|
+
try {
|
|
43
|
+
accessSync(root, constants.W_OK);
|
|
44
|
+
} catch {
|
|
45
|
+
return { error: `folder not writable: ${root}` };
|
|
46
|
+
}
|
|
47
|
+
const cfgdirs = new Set();
|
|
48
|
+
for (const fn of [opencodeConfigDir, claudeConfigDir, bobConfigDir, openclaudeConfigDir]) {
|
|
49
|
+
try {
|
|
50
|
+
cfgdirs.add(resolvePath(fn()));
|
|
51
|
+
} catch { /* not every host has a resolvable config dir; skip it */ }
|
|
52
|
+
}
|
|
53
|
+
if (cfgdirs.has(root)) {
|
|
54
|
+
return { error: "that's a host global config dir — use its existing row to build a global install" };
|
|
55
|
+
}
|
|
56
|
+
for (const host of hosts) {
|
|
57
|
+
const hit = markerCollision(root, host);
|
|
58
|
+
if (hit) return { error: hit };
|
|
59
|
+
}
|
|
60
|
+
return { root };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The refusal when a project install of `host` in `root` would land IN that host's global config
|
|
65
|
+
* dir — `<root>/<projectMarker>` resolves to it (`~` and `~/.claude` for Claude Code) — else
|
|
66
|
+
* null. Case-folded on Windows (`normcase`). A config dir that cannot be resolved is no collision.
|
|
67
|
+
*/
|
|
68
|
+
export function markerCollision(root, host) {
|
|
69
|
+
const row = HOSTS.find((h) => h.host === host);
|
|
70
|
+
if (!row) return null;
|
|
71
|
+
let cfg;
|
|
72
|
+
try { cfg = resolvePath(row.configDir()); } catch { return null; }
|
|
73
|
+
const at = resolvePath(path.join(root, row.projectMarker));
|
|
74
|
+
if (normcase(at) !== normcase(cfg)) return null;
|
|
75
|
+
return `${root} holds the ${host} global install (${cfg}): a ${host} project install there would `
|
|
76
|
+
+ 'overwrite it — pick a project folder';
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The global hook verbs that STAND DOWN for a live, wired project install of the same host in the
|
|
81
|
+
* session's start folder (`globalHookStandingDown`, js/hosts/hosts.mjs; docs/concepts/hook-gates.md).
|
|
82
|
+
* `tests/unit/profile_scope.test.mjs` holds this list against the verbs the hooks pass to that
|
|
83
|
+
* function, so a verb that starts (or stops) standing down fails the suite.
|
|
84
|
+
*/
|
|
85
|
+
export const STAND_DOWN_VERBS = ['context', 'git-gate', 'learn'];
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Which global hook verb carries each gate switch, per host: the `--no-*` flag of a switch rides
|
|
89
|
+
* these commands (`claudeHookGroups`, js/hosts/settings.mjs). `null`: the host has no hook verbs —
|
|
90
|
+
* OpenCode's gates live in its plugins, which do not stand down for a project install
|
|
91
|
+
* (docs/concepts/exclusions.md: "Bob's `tool-gate` and the OpenCode guard do not stand down").
|
|
92
|
+
* `ownBranchPass` is no gate of its own: it tunes the consent ask of `git-gate`/`tool-gate`.
|
|
93
|
+
* `tests/unit/profile_scope.test.mjs` derives the same table from real emitted settings files.
|
|
94
|
+
*/
|
|
95
|
+
export const GATE_VERBS = {
|
|
96
|
+
claude: {
|
|
97
|
+
secretsGate: ['rule-gate'], doneGate: ['learn'], deletionGate: ['git-gate'], ownershipGate: ['rule-gate'],
|
|
98
|
+
externalGate: ['git-gate', 'rule-gate'], testNote: ['rule-gate', 'learn'],
|
|
99
|
+
},
|
|
100
|
+
openclaude: {
|
|
101
|
+
secretsGate: ['rule-gate'], doneGate: ['learn'], deletionGate: ['git-gate'], ownershipGate: ['rule-gate'],
|
|
102
|
+
externalGate: ['git-gate', 'rule-gate'], testNote: ['rule-gate', 'learn'],
|
|
103
|
+
},
|
|
104
|
+
bob: {
|
|
105
|
+
secretsGate: ['tool-gate'], doneGate: ['learn'], deletionGate: ['tool-gate'], ownershipGate: ['tool-gate'],
|
|
106
|
+
externalGate: ['tool-gate'], testNote: ['tool-gate', 'learn'],
|
|
107
|
+
},
|
|
108
|
+
opencode: null,
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/** The gate switches D39 names: every `GATE_SWITCHES` row but the consent tuning. */
|
|
112
|
+
const LAYER_GATES = GATE_SWITCHES.filter((g) => g.key !== 'ownBranchPass');
|
|
113
|
+
|
|
114
|
+
/** Whether gate `key` of a global `host` install still runs inside a project with its own install. */
|
|
115
|
+
export function gateRunsInProject(host, key) {
|
|
116
|
+
const table = GATE_VERBS[host];
|
|
117
|
+
if (table === null) return true;
|
|
118
|
+
return (table?.[key] ?? []).some((verb) => !STAND_DOWN_VERBS.includes(verb));
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* What a global install of `host` still does inside a project folder that gets its own install
|
|
123
|
+
* (spec D39), or null when there is no active global install of that host.
|
|
124
|
+
*
|
|
125
|
+
* `{ root, gates }`: the global install's dir, and the marker names (`Secrets gate`, …) of its
|
|
126
|
+
* ARMED gates that still run in the project — a gate the global install switched off runs
|
|
127
|
+
* nowhere, so it is not named. Both root files load either way: the host reads its global
|
|
128
|
+
* instructions file and the project's. `configDir` is the test's seam.
|
|
129
|
+
*/
|
|
130
|
+
export function globalLayering(host, { configDir = (h) => HOSTS.find((x) => x.host === h).configDir() } = {}) {
|
|
131
|
+
let root;
|
|
132
|
+
try { root = configDir(host); } catch { return null; }
|
|
133
|
+
if (!root || installState(root, host, 'global') !== 'active') return null;
|
|
134
|
+
const armed = gatesOfDir(root, host);
|
|
135
|
+
const gates = LAYER_GATES.filter((g) => armed[g.key] !== false && gateRunsInProject(host, g.key)).map((g) => g.marker);
|
|
136
|
+
return { root, gates };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** The D39 summary line for one host, or null; `docs/concepts/exclusions.md` holds the detail. */
|
|
140
|
+
export function layeringText(label, layer, project) {
|
|
141
|
+
if (!layer) return null;
|
|
142
|
+
const still = layer.gates.length ? layer.gates.join(', ') : 'none';
|
|
143
|
+
return `${label}: the global install at ${layer.root} is active too, so both root files load in ${project}. `
|
|
144
|
+
+ `Global gates that still run there: ${still} (see docs/concepts/exclusions.md)`;
|
|
145
|
+
}
|
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Install profiles — a whole install selection written down once, so `geneseed setup --profile
|
|
3
|
+
* <name>` installs it with no question asked, `geneseed profile apply` builds it globally or into
|
|
4
|
+
* one project, and `geneseed profile save` writes one from an install that already exists.
|
|
5
|
+
*
|
|
6
|
+
* TWO SOURCES (spec D34): Shipped, `profiles/` in this checkout (an admin adds one by pull
|
|
7
|
+
* request), and Personal, `<machine tier>/profiles/` beside the user's memory and rules. The
|
|
8
|
+
* Personal dir is resolved AT CALL TIME (`personalProfilesDir`), never as a module constant, so a
|
|
9
|
+
* test that moves the tier is honoured, and every reader takes a `{ shippedDir, personalDir }`
|
|
10
|
+
* seam so no test reads the real tier. A Personal name may not reuse a Shipped one (D36): a save
|
|
11
|
+
* refuses it, and a clash made by hand loads the Shipped profile while the doctor names the
|
|
12
|
+
* Personal file that is never read.
|
|
13
|
+
*
|
|
14
|
+
* A PROFILE NAMES VALUES THE GENERATOR ALREADY ACCEPTS, CHECKED AGAINST THE GENERATOR'S OWN
|
|
15
|
+
* SOURCES (*One Writer Per Value*): `themes/*.json`, `discoverNames('postures'|'modes')`,
|
|
16
|
+
* `PRESETS`, `PACK_ORDER`, `GATE_SWITCHES`, the rule and skill ids the source tree declares, the
|
|
17
|
+
* kits it ships, the hosts `HOSTS` lists. No list of legal values is typed out here, so a pack or
|
|
18
|
+
* a posture added to `src/` is a legal profile value the moment it exists.
|
|
19
|
+
*
|
|
20
|
+
* AN UNKNOWN KEY IS AN ERROR, NOT IGNORED (spec D10): a typo (`"posure"`) that fell back to the
|
|
21
|
+
* default would install something its author did not write, with nothing said.
|
|
22
|
+
*
|
|
23
|
+
* Under the CLI's spawn rules like the rest of `js/maintain/`: this module reads files and
|
|
24
|
+
* writes one (`saveProfile`), and starts nothing.
|
|
25
|
+
*/
|
|
26
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
27
|
+
import path from 'node:path';
|
|
28
|
+
|
|
29
|
+
import {
|
|
30
|
+
CONTEXT_WINDOWS, DEFAULT_CONTEXT_WINDOW, discoverNames, GATE_SWITCHES, knownRuleIds, knownSkillIds, linkedSkillIds, loadKits, PACK_ORDER, ROOT,
|
|
31
|
+
} from '../build/source.mjs';
|
|
32
|
+
import { installProfile, setupBuildArgs } from '../build/profile.mjs';
|
|
33
|
+
import { PRESETS } from '../loop/score.mjs';
|
|
34
|
+
import { HOSTS } from '../hosts/hosts.mjs';
|
|
35
|
+
import { installState, themeFiles } from '../hosts/installs.mjs';
|
|
36
|
+
import { isDir, printErr, printOut } from '../lib/fs.mjs';
|
|
37
|
+
import { machineDir } from '../lib/machine-dir.mjs';
|
|
38
|
+
import { NOTE } from '../inspect/scan.mjs';
|
|
39
|
+
import { expanduser, resolvePath } from '../hosts/hosts.mjs';
|
|
40
|
+
|
|
41
|
+
/** Where the shipped profiles live: `profiles/` at the checkout (or package) root. */
|
|
42
|
+
export const PROFILES_DIR = path.join(ROOT, 'profiles');
|
|
43
|
+
|
|
44
|
+
/** Where the Personal profiles live (spec D34): `profiles/` in the machine tier, read at call time. */
|
|
45
|
+
export function personalProfilesDir() {
|
|
46
|
+
return path.join(machineDir(), 'profiles');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The two source dirs, defaults filled in. `personalDir` is computed only when the caller did
|
|
51
|
+
* not give one, so a test that injects both never reads the real tier.
|
|
52
|
+
* @param {{ shippedDir?: string, personalDir?: string }} [src]
|
|
53
|
+
*/
|
|
54
|
+
export function profileDirs(src = {}) {
|
|
55
|
+
return {
|
|
56
|
+
shippedDir: src.shippedDir ?? PROFILES_DIR,
|
|
57
|
+
personalDir: src.personalDir ?? personalProfilesDir(),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** The profile `geneseed profile save` compares a new one against. */
|
|
62
|
+
export const BASE_PROFILE = 'starter';
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Every key a profile may hold, in the order `saveProfile` writes them. `sharedTier` is one since
|
|
66
|
+
* spec D37 (which supersedes D18 on that point): a profile has no scope, so a project-only field is
|
|
67
|
+
* accepted, used by a project apply, and ignored by a global one, whose install owns the tier.
|
|
68
|
+
* `contextWindow` (`--context-window`) is optional: absent is the default, `200k`.
|
|
69
|
+
*/
|
|
70
|
+
export const PROFILE_KEYS = ['description', 'hosts', 'theme', 'footprint', 'posture', 'mode', 'trust',
|
|
71
|
+
'doctrines', 'excludeRules', 'excludeSkills', 'kits', 'sharedTier', 'contextWindow', 'gates', 'login'];
|
|
72
|
+
|
|
73
|
+
/** A profile name: a file stem, never a path. */
|
|
74
|
+
const NAME_RE = /^[a-z0-9][a-z0-9._-]*$/i;
|
|
75
|
+
|
|
76
|
+
/** The host ids a profile may list, in `HOSTS` order. */
|
|
77
|
+
export function profileHosts() {
|
|
78
|
+
return HOSTS.map((h) => h.host);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** The profile names in one dir, sorted; `[]` when the folder is missing. */
|
|
82
|
+
function namesIn(dir) {
|
|
83
|
+
let names;
|
|
84
|
+
try { names = readdirSync(dir); } catch { return []; }
|
|
85
|
+
return names.filter((n) => n.endsWith('.json')).map((n) => n.slice(0, -5)).sort();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Every profile file of both sources, Shipped first, each `{ name, source, file, shadowed }`.
|
|
90
|
+
* `shadowed` marks a Personal file whose name a Shipped profile already holds (D36): it is
|
|
91
|
+
* listed, so the doctor and the console can name it, and never loaded.
|
|
92
|
+
* @param {{ shippedDir?: string, personalDir?: string }} [src]
|
|
93
|
+
*/
|
|
94
|
+
export function listProfiles(src = {}) {
|
|
95
|
+
const { shippedDir, personalDir } = profileDirs(src);
|
|
96
|
+
const shipped = namesIn(shippedDir);
|
|
97
|
+
return [
|
|
98
|
+
...shipped.map((name) => ({ name, source: 'shipped', file: path.join(shippedDir, `${name}.json`), shadowed: false })),
|
|
99
|
+
...namesIn(personalDir).map((name) => ({ name, source: 'personal', file: path.join(personalDir, `${name}.json`),
|
|
100
|
+
shadowed: shipped.includes(name) })),
|
|
101
|
+
];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** How an error names a profile file: `profiles/<name>.json` when Shipped, the full path when Personal. */
|
|
105
|
+
const fileLabel = (e) => (e.source === 'shipped' ? `profiles/${e.name}.json` : e.file);
|
|
106
|
+
|
|
107
|
+
const list = (xs) => xs.map((x) => `'${x}'`).join(', ');
|
|
108
|
+
|
|
109
|
+
function stringList(v) {
|
|
110
|
+
return Array.isArray(v) && v.every((x) => typeof x === 'string');
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Every fault of one parsed profile, as one sentence each (empty: valid). Each sentence names the
|
|
115
|
+
* field and the values it accepts.
|
|
116
|
+
*/
|
|
117
|
+
export function profileProblems(p) {
|
|
118
|
+
if (!p || typeof p !== 'object' || Array.isArray(p)) return ['a profile is a JSON object'];
|
|
119
|
+
const errs = [];
|
|
120
|
+
for (const k of Object.keys(p)) {
|
|
121
|
+
if (!PROFILE_KEYS.includes(k)) errs.push(`unknown key '${k}' (valid keys: ${list(PROFILE_KEYS)})`);
|
|
122
|
+
}
|
|
123
|
+
for (const k of ['hosts', 'theme', 'footprint', 'posture', 'mode', 'trust', 'doctrines']) {
|
|
124
|
+
if (p[k] === undefined) errs.push(`'${k}' is missing`);
|
|
125
|
+
}
|
|
126
|
+
if (p.description !== undefined && typeof p.description !== 'string') errs.push("'description' must be a string");
|
|
127
|
+
const hosts = profileHosts();
|
|
128
|
+
if (p.hosts !== undefined) {
|
|
129
|
+
if (!stringList(p.hosts) || !p.hosts.length) errs.push(`'hosts' must be a non-empty list of: ${list(hosts)}`);
|
|
130
|
+
else for (const h of p.hosts.filter((x) => !hosts.includes(x))) errs.push(`'hosts': unknown host '${h}' (valid: ${list(hosts)})`);
|
|
131
|
+
}
|
|
132
|
+
const themes = themeFiles().map((f) => path.basename(f, '.json'));
|
|
133
|
+
if (p.theme !== undefined && !themes.includes(p.theme)) errs.push(`'theme': unknown theme '${p.theme}' (valid: ${list(themes)})`);
|
|
134
|
+
const choice = (key, valid) => {
|
|
135
|
+
if (p[key] !== undefined && !valid.includes(p[key])) errs.push(`'${key}': invalid value '${p[key]}' (valid: ${list(valid)})`);
|
|
136
|
+
};
|
|
137
|
+
choice('footprint', ['lean', 'full']);
|
|
138
|
+
choice('posture', discoverNames('postures', 'peer'));
|
|
139
|
+
choice('mode', discoverNames('modes', 'direct'));
|
|
140
|
+
choice('trust', Object.keys(PRESETS));
|
|
141
|
+
choice('contextWindow', Object.keys(CONTEXT_WINDOWS));
|
|
142
|
+
const packs = discoverNames('doctrines', PACK_ORDER[0]);
|
|
143
|
+
if (p.doctrines !== undefined && p.doctrines !== 'all') {
|
|
144
|
+
if (!stringList(p.doctrines)) errs.push(`'doctrines' must be 'all' or a list of: ${list(packs)}`);
|
|
145
|
+
else for (const d of p.doctrines.filter((x) => !packs.includes(x))) errs.push(`'doctrines': unknown pack '${d}' (valid: ${list(packs)})`);
|
|
146
|
+
}
|
|
147
|
+
if (p.excludeRules !== undefined) {
|
|
148
|
+
const rules = knownRuleIds();
|
|
149
|
+
if (!stringList(p.excludeRules)) errs.push("'excludeRules' must be a list of rule ids, e.g. 'craft.4'");
|
|
150
|
+
else for (const r of p.excludeRules.filter((x) => !rules.includes(x))) errs.push(`'excludeRules': unknown rule '${r}' (rule ids look like 'craft.4')`);
|
|
151
|
+
}
|
|
152
|
+
if (p.excludeSkills !== undefined) {
|
|
153
|
+
const linked = linkedSkillIds();
|
|
154
|
+
const skills = knownSkillIds().filter((s) => !linked.includes(s));
|
|
155
|
+
if (!stringList(p.excludeSkills)) errs.push("'excludeSkills' must be a list of skill names");
|
|
156
|
+
else for (const s of p.excludeSkills.filter((x) => !skills.includes(x))) {
|
|
157
|
+
errs.push(linked.includes(s) ? `'excludeSkills': '${s}' cannot be excluded — the harness links to it`
|
|
158
|
+
: `'excludeSkills': unknown skill '${s}'`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (p.kits !== undefined) {
|
|
162
|
+
const kits = [...loadKits().keys()];
|
|
163
|
+
if (!stringList(p.kits)) errs.push(`'kits' must be a list of: ${list(kits)}`);
|
|
164
|
+
else for (const k of p.kits.filter((x) => !kits.includes(x))) errs.push(`'kits': unknown kit '${k}' (valid: ${list(kits)})`);
|
|
165
|
+
}
|
|
166
|
+
if (p.gates !== undefined) {
|
|
167
|
+
const keys = GATE_SWITCHES.map((g) => g.key);
|
|
168
|
+
if (!p.gates || typeof p.gates !== 'object' || Array.isArray(p.gates)) errs.push(`'gates' must be an object keyed by: ${list(keys)}`);
|
|
169
|
+
else {
|
|
170
|
+
for (const [k, v] of Object.entries(p.gates)) {
|
|
171
|
+
if (!keys.includes(k)) errs.push(`'gates': unknown gate '${k}' (valid: ${list(keys)})`);
|
|
172
|
+
else if (v !== false) errs.push(`'gates.${k}' must be false (a gate is armed unless the profile turns it off)`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (p.login !== undefined && typeof p.login !== 'boolean') errs.push("'login' must be true or false");
|
|
177
|
+
if (p.sharedTier !== undefined && typeof p.sharedTier !== 'boolean') errs.push("'sharedTier' must be true or false");
|
|
178
|
+
return errs;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** Read and validate one listed entry: `{ ok, profile, source, file }` or `{ ok: false, error }`. */
|
|
182
|
+
function loadEntry(e) {
|
|
183
|
+
let profile;
|
|
184
|
+
try { profile = JSON.parse(readFileSync(e.file, 'utf8')); } catch (err) {
|
|
185
|
+
return { ok: false, error: `${fileLabel(e)} is not valid JSON (${err.message})` };
|
|
186
|
+
}
|
|
187
|
+
const errs = profileProblems(profile);
|
|
188
|
+
if (errs.length) return { ok: false, error: `${fileLabel(e)}: ${errs.join('; ')}` };
|
|
189
|
+
return { ok: true, profile, source: e.source, file: e.file };
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Read and validate profile `name` from either source. `{ ok: true, profile, source, file }`, or
|
|
194
|
+
* `{ ok: false, error }` whose text says what to fix: an unknown name lists both sources.
|
|
195
|
+
* A name both sources hold loads the Shipped one (D36; the doctor names the Personal file).
|
|
196
|
+
* @param {string} name
|
|
197
|
+
* @param {{ shippedDir?: string, personalDir?: string }} [src]
|
|
198
|
+
*/
|
|
199
|
+
export function loadProfile(name, src = {}) {
|
|
200
|
+
const entries = listProfiles(src);
|
|
201
|
+
const known = () => {
|
|
202
|
+
const of = (source) => entries.filter((e) => e.source === source && !e.shadowed).map((e) => e.name).join(', ') || 'none';
|
|
203
|
+
return `shipped: ${of('shipped')}; personal: ${of('personal')}`;
|
|
204
|
+
};
|
|
205
|
+
if (typeof name !== 'string' || !NAME_RE.test(name)) {
|
|
206
|
+
return { ok: false, error: `'${name}' is not a profile name (a file stem, no path) — ${known()}` };
|
|
207
|
+
}
|
|
208
|
+
const e = entries.find((x) => x.name === name && !x.shadowed);
|
|
209
|
+
if (!e) return { ok: false, error: `no profile '${name}' — ${known()}` };
|
|
210
|
+
return loadEntry(e);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** `doctrines` as the pack list it means: `'all'` is every pack this checkout ships, in order. */
|
|
214
|
+
export function profileDoctrines(p) {
|
|
215
|
+
const packs = discoverNames('doctrines', PACK_ORDER[0]);
|
|
216
|
+
const want = p.doctrines === 'all' ? packs : p.doctrines;
|
|
217
|
+
return PACK_ORDER.filter((d) => want.includes(d));
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* The generator argv that installs profile `p` into `host`: globally, or into the folder
|
|
222
|
+
* `project` when one is given.
|
|
223
|
+
*
|
|
224
|
+
* EXPLICIT ON EVERY AXIS (spec D18), so the result never depends on `harness.config.json`:
|
|
225
|
+
* `--exclude-rules none` and `--exclude-skills none` included. `setupBuildArgs` elides an empty
|
|
226
|
+
* skill list (absence and `none` are the same answer to the driver), so the `none` is appended
|
|
227
|
+
* here; posture and mode elide only at the value the driver would take anyway. `--reset` last,
|
|
228
|
+
* as the wizard does: a profile is a whole selection and wins over the install it lands on (D14).
|
|
229
|
+
*/
|
|
230
|
+
export function profileBuildArgs(p, host, project = null) {
|
|
231
|
+
// A stated selection, never null: `'all'` resolves to the packs, a list is the list.
|
|
232
|
+
const doctrines = PACK_ORDER.filter((d) => profileDoctrines(p).includes(d));
|
|
233
|
+
// PROJECT SCOPE (spec D32, D37): `--emit <host> --out <dir> --root <dir>`, and only here the
|
|
234
|
+
// profile's `sharedTier`; a global install owns the tier, so a global apply ignores the field.
|
|
235
|
+
const argv = setupBuildArgs(p.theme, project ? host : `${host}-global`, project, project, p.footprint,
|
|
236
|
+
p.posture, p.mode, doctrines, PACK_ORDER, p.excludeRules ?? [], p.trust, p.excludeSkills ?? [],
|
|
237
|
+
p.gates ?? {}, p.kits ?? [], project ? p.sharedTier === true : false,
|
|
238
|
+
p.contextWindow ?? DEFAULT_CONTEXT_WINDOW);
|
|
239
|
+
if (!p.excludeSkills?.length) argv.push('--exclude-skills', 'none');
|
|
240
|
+
argv.push('--reset');
|
|
241
|
+
return argv;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* A profile written from one install's read-back (`installProfile(host, 'global', root)`, spec
|
|
246
|
+
* D28): every setting as it is, gates switched off included, and `hosts: [host]`.
|
|
247
|
+
*
|
|
248
|
+
* READS NOTHING BUT `info` (spec D29): user rules, the profile, memory, the wiki and the notebook
|
|
249
|
+
* are not build settings, so they cannot reach a saved profile. `login` is not an install
|
|
250
|
+
* setting either; `true`, the value `starter` ships.
|
|
251
|
+
*/
|
|
252
|
+
export function profileFromInstall(info, description = '') {
|
|
253
|
+
const packs = discoverNames('doctrines', PACK_ORDER[0]);
|
|
254
|
+
const doctrines = PACK_ORDER.filter((d) => info.doctrines.includes(d));
|
|
255
|
+
const gates = Object.fromEntries(GATE_SWITCHES.filter((g) => info[g.key] === false).map((g) => [g.key, false]));
|
|
256
|
+
return {
|
|
257
|
+
description,
|
|
258
|
+
hosts: [info.host],
|
|
259
|
+
theme: info.theme,
|
|
260
|
+
footprint: info.footprint,
|
|
261
|
+
posture: info.posture,
|
|
262
|
+
mode: info.mode,
|
|
263
|
+
trust: info.trust,
|
|
264
|
+
doctrines: doctrines.length === packs.length && packs.every((d) => doctrines.includes(d)) ? 'all' : doctrines,
|
|
265
|
+
excludeRules: [...(info.excludeRules ?? [])].sort(),
|
|
266
|
+
excludeSkills: [...(info.excludeSkills ?? [])].sort(),
|
|
267
|
+
kits: [...(info.kits ?? [])].sort(),
|
|
268
|
+
sharedTier: info.sharedTier === true,
|
|
269
|
+
contextWindow: info.contextWindow ?? DEFAULT_CONTEXT_WINDOW,
|
|
270
|
+
gates,
|
|
271
|
+
login: true,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const showValue = (v) => (Array.isArray(v) ? (v.length ? v.join(',') : 'none') : String(v));
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* The settings where `p` differs from `base`, as `{ key, base, now }`, gates first — a gate
|
|
279
|
+
* turned off is the difference a reviewer of the pull request must not miss (spec D28). Absent
|
|
280
|
+
* list keys read as empty, an absent gate as armed.
|
|
281
|
+
*/
|
|
282
|
+
export function profileDiff(p, base) {
|
|
283
|
+
const gate = (prof, key) => (prof.gates?.[key] === false ? 'off' : 'on');
|
|
284
|
+
const out = [];
|
|
285
|
+
for (const g of GATE_SWITCHES) {
|
|
286
|
+
if (gate(p, g.key) !== gate(base, g.key)) out.push({ key: `gates.${g.key}`, base: gate(base, g.key), now: gate(p, g.key) });
|
|
287
|
+
}
|
|
288
|
+
for (const key of PROFILE_KEYS.filter((k) => k !== 'gates' && k !== 'description')) {
|
|
289
|
+
const norm = (prof) => {
|
|
290
|
+
const v = prof[key];
|
|
291
|
+
if (key === 'doctrines') return showValue(profileDoctrines(prof));
|
|
292
|
+
if (Array.isArray(v) || v === undefined) return showValue([...(v ?? [])].sort());
|
|
293
|
+
return showValue(v);
|
|
294
|
+
};
|
|
295
|
+
if (key === 'login') {
|
|
296
|
+
const l = (prof) => String(prof.login !== false);
|
|
297
|
+
if (l(p) !== l(base)) out.push({ key, base: l(base), now: l(p) });
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
300
|
+
if (key === 'sharedTier') {
|
|
301
|
+
const t = (prof) => (prof.sharedTier === true ? 'on' : 'off');
|
|
302
|
+
if (t(p) !== t(base)) out.push({ key, base: t(base), now: t(p) });
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
if (key === 'contextWindow') {
|
|
306
|
+
const w = (prof) => prof.contextWindow ?? DEFAULT_CONTEXT_WINDOW;
|
|
307
|
+
if (w(p) !== w(base)) out.push({ key, base: w(base), now: w(p) });
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
if (norm(p) !== norm(base)) out.push({ key, base: norm(base), now: norm(p) });
|
|
311
|
+
}
|
|
312
|
+
return out;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Write `<dir>/<name>.json`, creating `dir` (the Personal one may not exist yet). Refuses an
|
|
317
|
+
* existing file unless `force` (that flag reaches the profile file only), and a name that is not
|
|
318
|
+
* a plain file stem. `{ ok, file }` or `{ ok, error }`.
|
|
319
|
+
*/
|
|
320
|
+
export function saveProfile(name, profile, { dir = PROFILES_DIR, force = false } = {}) {
|
|
321
|
+
if (typeof name !== 'string' || !NAME_RE.test(name)) {
|
|
322
|
+
return { ok: false, error: `'${name}' is not a profile name: letters, digits, '.', '_' and '-' only, no path` };
|
|
323
|
+
}
|
|
324
|
+
const file = path.join(dir, `${name}.json`);
|
|
325
|
+
if (existsSync(file) && !force) {
|
|
326
|
+
return { ok: false, error: `${file} already exists — pick another name, or add --force to replace it` };
|
|
327
|
+
}
|
|
328
|
+
const ordered = Object.fromEntries(PROFILE_KEYS.filter((k) => profile[k] !== undefined).map((k) => [k, profile[k]]));
|
|
329
|
+
mkdirSync(dir, { recursive: true });
|
|
330
|
+
// LF on every OS, not `writeText`'s platform newline: a profile is a repo file, and
|
|
331
|
+
// `.gitattributes` keeps repo text LF.
|
|
332
|
+
writeFileSync(file, `${JSON.stringify(ordered, null, 2)}\n`, 'utf8');
|
|
333
|
+
return { ok: true, file };
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* The doctor's arm (spec D10, D36): every profile of both sources through the same loader
|
|
338
|
+
* `setup --profile` uses.
|
|
339
|
+
*
|
|
340
|
+
* A SHIPPED PROBLEM FAILS, A PERSONAL ONE IS A NOTE. A Shipped profile is this checkout's own
|
|
341
|
+
* file, so a broken one is a defect of the tree. A Personal file is the user's, in the machine
|
|
342
|
+
* tier: an update that retires a theme it names, or an admin who ships a name the user already
|
|
343
|
+
* has, must not fail `doctor --all` — the updater runs it on the pulled tree and rolls back on a
|
|
344
|
+
* failure (`gatePulled`), which would block every update over a file the update never touches.
|
|
345
|
+
* So a refused or shadowed Personal file is a `NOTE` line, printed and not counted.
|
|
346
|
+
* @param {{ shippedDir?: string, personalDir?: string }} [src]
|
|
347
|
+
*/
|
|
348
|
+
export function profileSetProblems(src = {}) {
|
|
349
|
+
const out = [];
|
|
350
|
+
for (const e of listProfiles(src)) {
|
|
351
|
+
const note = e.source === 'personal' ? NOTE : '';
|
|
352
|
+
if (e.shadowed) {
|
|
353
|
+
out.push(`${note}[profiles] ${e.file} has the name of a shipped profile, so it is never loaded — rename it`);
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
const r = loadEntry(e);
|
|
357
|
+
if (!r.ok) out.push(`${note}[profiles] ${r.error}`);
|
|
358
|
+
}
|
|
359
|
+
return out;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/** Whether `root` is a git clone (or a worktree: `.git` is a file there): `--shipped` needs one. */
|
|
363
|
+
export function isGitClone(root = ROOT) {
|
|
364
|
+
return existsSync(path.join(root, '.git'));
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* The (host, scope, root) a `profile save --from` names, or `{ error, rc }`. `--from <host>-global`
|
|
369
|
+
* reads that host's global install; `--from <host>` with `--project <dir>` reads the project
|
|
370
|
+
* install in that folder (the console's Save panel offers both).
|
|
371
|
+
*/
|
|
372
|
+
function saveSource(args, hosts) {
|
|
373
|
+
const emits = [...hosts.map((h) => `${h}-global`), ...hosts];
|
|
374
|
+
if (!args.from || !emits.includes(args.from)) {
|
|
375
|
+
return { error: `profile save needs --from, one of: ${emits.join(', ')} (a bare host needs --project <dir>)`, rc: 2 };
|
|
376
|
+
}
|
|
377
|
+
if (args.from.endsWith('-global')) {
|
|
378
|
+
const host = args.from.slice(0, -'-global'.length);
|
|
379
|
+
if (args.project) return { error: `--from ${args.from} reads a global install: drop --project, or use --from ${host}`, rc: 2 };
|
|
380
|
+
try {
|
|
381
|
+
return { host, scope: 'global', root: HOSTS.find((h) => h.host === host).configDir() };
|
|
382
|
+
} catch (e) {
|
|
383
|
+
return { error: `cannot find the ${host} config dir (${e && e.message})`, rc: 1 };
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
if (!args.project) return { error: `--from ${args.from} reads a project install: add --project <dir>`, rc: 2 };
|
|
387
|
+
let root;
|
|
388
|
+
try { root = resolvePath(expanduser(args.project)); } catch { return { error: `bad path: ${args.project}`, rc: 1 }; }
|
|
389
|
+
if (!isDir(root)) return { error: `not a folder: ${root}`, rc: 1 };
|
|
390
|
+
return { host: args.from, scope: 'project', root };
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* `geneseed profile <save|apply> <name> …`.
|
|
395
|
+
*
|
|
396
|
+
* `save --from <host>-global | --from <host> --project <dir> [--shipped] [--force]` (spec D28,
|
|
397
|
+
* D29, D30, D35, D36) reads the one install `--from` names through `installProfile` — the same
|
|
398
|
+
* read-back `rebuild-all` replays — and writes `<name>.json` with `hosts: [<host>]`: into the
|
|
399
|
+
* Personal dir by default, into this checkout's `profiles/` with `--shipped`, which only a git
|
|
400
|
+
* clone takes (a pull request is how a Shipped profile reaches anyone). It refuses when there is
|
|
401
|
+
* no active install there, when the read-back would not load as a profile, when the name is the
|
|
402
|
+
* other source's (D36, `--force` included: that flag replaces a file of the same source only),
|
|
403
|
+
* and when the file exists without `--force`. Then it prints how the new profile differs from
|
|
404
|
+
* `starter`, gates first.
|
|
405
|
+
*
|
|
406
|
+
* `apply` is `cmdProfileApply` (js/maintain/setup.mjs), imported lazily: it reuses the profile
|
|
407
|
+
* run's build loop, which lives there, and setup.mjs imports this module.
|
|
408
|
+
*
|
|
409
|
+
* `shippedDir`, `personalDir` and `root` are the test's seams.
|
|
410
|
+
* @param {any} args
|
|
411
|
+
* @param {{ shippedDir?: string, personalDir?: string | null, root?: string }} [seams]
|
|
412
|
+
* @returns {number | Promise<number>}
|
|
413
|
+
*/
|
|
414
|
+
export function cmdProfile(args, { shippedDir = PROFILES_DIR, personalDir = null, root = ROOT } = {}) {
|
|
415
|
+
const src = { shippedDir, personalDir: personalDir ?? personalProfilesDir() };
|
|
416
|
+
// Each action takes its own flags only: one it would ignore is refused, never dropped in silence.
|
|
417
|
+
const foreign = args.action === 'apply'
|
|
418
|
+
? [['from', '--from'], ['shipped', '--shipped'], ['force', '--force']]
|
|
419
|
+
: [['hosts', '--hosts']];
|
|
420
|
+
const given = foreign.filter(([k]) => args[k] !== undefined && args[k] !== null && args[k] !== false)
|
|
421
|
+
.map(([, flag]) => flag);
|
|
422
|
+
if (given.length && (args.action === 'apply' || args.action === 'save')) {
|
|
423
|
+
printErr(`geneseed: error: profile ${args.action} does not take ${given.join(', ')}\n`);
|
|
424
|
+
return 2;
|
|
425
|
+
}
|
|
426
|
+
if (args.action === 'apply') return import('./setup.mjs').then((m) => m.cmdProfileApply(args, { src }));
|
|
427
|
+
if (args.action !== 'save') {
|
|
428
|
+
printErr(`geneseed: error: profile: unknown action '${args.action}' (actions: save, apply)\n`);
|
|
429
|
+
return 2;
|
|
430
|
+
}
|
|
431
|
+
const from = saveSource(args, profileHosts());
|
|
432
|
+
if (from.error) {
|
|
433
|
+
printErr(from.rc === 2 ? `geneseed: error: ${from.error}\n` : `[profile] ${from.error}\n`);
|
|
434
|
+
return from.rc;
|
|
435
|
+
}
|
|
436
|
+
const { host, scope, root: installRoot } = from;
|
|
437
|
+
const where = `${host} ${scope} install`;
|
|
438
|
+
if (installState(installRoot, host, scope) !== 'active') {
|
|
439
|
+
printErr(`[profile] no active ${where} at ${installRoot} — nothing to save\n`);
|
|
440
|
+
return 1;
|
|
441
|
+
}
|
|
442
|
+
if (args.shipped && !isGitClone(root)) {
|
|
443
|
+
printErr(`[profile] --shipped writes ${shippedDir}, which only a git clone takes (a shipped profile `
|
|
444
|
+
+ 'reaches others by pull request) — drop --shipped to save it as personal\n');
|
|
445
|
+
return 1;
|
|
446
|
+
}
|
|
447
|
+
const [dest, other, otherLabel] = args.shipped
|
|
448
|
+
? [shippedDir, src.personalDir, 'personal'] : [src.personalDir, shippedDir, 'shipped'];
|
|
449
|
+
const clash = path.join(other, `${args.name}.json`);
|
|
450
|
+
if (typeof args.name === 'string' && NAME_RE.test(args.name) && existsSync(clash)) {
|
|
451
|
+
printErr(`[profile] '${args.name}' is already a ${otherLabel} profile (${clash}) — a personal profile `
|
|
452
|
+
+ 'may not reuse a shipped name, so pick another name\n');
|
|
453
|
+
return 1;
|
|
454
|
+
}
|
|
455
|
+
const p = profileFromInstall(installProfile(host, scope, installRoot), `Saved from the ${where}.`);
|
|
456
|
+
const errs = profileProblems(p);
|
|
457
|
+
if (errs.length) {
|
|
458
|
+
printErr(`[profile] the ${where} does not make a valid profile: ${errs.join('; ')}\n`);
|
|
459
|
+
return 1;
|
|
460
|
+
}
|
|
461
|
+
const r = saveProfile(args.name, p, { dir: dest, force: Boolean(args.force) });
|
|
462
|
+
if (!r.ok) {
|
|
463
|
+
printErr(`[profile] ${r.error}\n`);
|
|
464
|
+
return 1;
|
|
465
|
+
}
|
|
466
|
+
printOut(`[profile] wrote ${r.file} (${args.shipped ? 'shipped' : 'personal'}) from ${installRoot}\n`);
|
|
467
|
+
const base = loadProfile(BASE_PROFILE, src);
|
|
468
|
+
if (!base.ok) {
|
|
469
|
+
printOut(`[profile] no ${BASE_PROFILE} profile to compare with (${base.error})\n`);
|
|
470
|
+
} else {
|
|
471
|
+
const diff = profileDiff(p, base.profile);
|
|
472
|
+
if (!diff.length) {
|
|
473
|
+
printOut(`[profile] it is the same as ${BASE_PROFILE}\n`);
|
|
474
|
+
} else {
|
|
475
|
+
printOut(`[profile] how it differs from ${BASE_PROFILE}:\n`);
|
|
476
|
+
for (const d of diff) printOut(` ${d.key}: ${d.base} -> ${d.now}\n`);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
if (args.shipped) {
|
|
480
|
+
printOut('[profile] edit its description, then open a pull request; a colleague installs it with: '
|
|
481
|
+
+ `.\\install.cmd --profile ${args.name} (Windows) or ./install --profile ${args.name}\n`);
|
|
482
|
+
} else {
|
|
483
|
+
printOut(`[profile] apply it with: geneseed profile apply ${args.name} (add --project <dir> for one project)\n`);
|
|
484
|
+
}
|
|
485
|
+
return 0;
|
|
486
|
+
}
|