geneseed 5.4.0 → 5.5.1
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 +51 -0
- package/README.md +31 -1
- package/SHIPPED.md +1 -1
- package/adapters/bob/README.md +12 -1
- package/adapters/opencode/README.md +2 -1
- package/adapters/opencode/plugins/geneseed-context.js +71 -10
- package/adapters/opencode/plugins/geneseed-guard.js +101 -19
- package/adapters/opencode/plugins/geneseed-learn.js +641 -6
- package/bin/geneseed-cli.mjs +3 -0
- package/bin/geneseed-hook.mjs +2 -1
- package/docs/concepts/agents.md +13 -1
- package/docs/concepts/enforcement-table.md +1 -1
- package/docs/concepts/foreman-mode.md +22 -3
- package/docs/concepts/hook-gates.md +1 -1
- package/docs/concepts/hooks.md +22 -5
- package/docs/concepts/host-matrix.md +2 -2
- package/docs/concepts/hosts.md +1 -1
- 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 +11 -2
- package/docs/guides/install-clone.md +18 -0
- package/docs/guides/install-scripted.md +8 -2
- package/docs/guides/install.md +19 -1
- package/docs/guides/upgrade.md +1 -1
- package/docs/reference/env-context.md +1 -1
- package/docs/reference/environment.md +1 -1
- package/docs/reference/plugin-learn.md +4 -0
- package/docs/reference/profiles.md +226 -0
- package/docs/token-footprint.md +9 -4
- package/docs/understand/design-choices-engineering.md +1 -1
- package/docs/web-ui.md +3 -1
- package/harness.config.json +1 -1
- package/js/README.md +9 -2
- package/js/build/args.mjs +4 -3
- package/js/build/catalog.mjs +11 -1
- package/js/build/driver.mjs +42 -11
- package/js/build/emit-claude.mjs +24 -1
- package/js/build/emit-opencode.mjs +3 -0
- package/js/build/export.mjs +12 -17
- package/js/build/generate.mjs +2 -1
- package/js/build/notes-migrate.mjs +99 -0
- package/js/build/profile.mjs +14 -6
- package/js/build/render.mjs +34 -10
- package/js/build/source.mjs +85 -2
- package/js/cli-table.json +164 -4
- package/js/hosts/agent-runs.mjs +205 -0
- package/js/hosts/done-checks.mjs +3 -1
- package/js/hosts/hooks-done.mjs +91 -16
- package/js/hosts/hooks-learn.mjs +85 -0
- package/js/hosts/hooks-prims.mjs +39 -1
- package/js/hosts/hooks.mjs +10 -4
- package/js/hosts/hosts.mjs +10 -0
- package/js/hosts/installs.mjs +25 -1
- package/js/hosts/link.mjs +45 -10
- package/js/hosts/native.mjs +42 -5
- package/js/hosts/opencode.mjs +1 -1
- package/js/hosts/settings.mjs +72 -0
- 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-repo.mjs +27 -2
- package/js/inspect/cost.mjs +6 -5
- package/js/inspect/diff.mjs +25 -5
- package/js/inspect/doctor.mjs +4 -0
- 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 +409 -15
- package/js/maintain/uninstall.mjs +4 -1
- package/js/maintain/update.mjs +1 -1
- package/js/web/actions.mjs +28 -38
- package/js/web/api.mjs +7 -2
- 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/autonomous.json +14 -0
- package/profiles/corporate.json +14 -0
- package/profiles/guillaume-claude-global.json +16 -0
- package/profiles/mentor.json +13 -0
- package/profiles/minimal.json +15 -0
- package/profiles/starter.json +14 -0
- package/src/AGENT.md.tmpl +1 -1
- 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 +7 -6
- 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 +4 -2
- 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 +4 -4
- package/src/agents/spring-reviewer.md +5 -3
- 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/memory/README.md +12 -2
- package/src/modes/foreman.md +23 -10
- package/src/skill-descriptions.json +63 -0
- package/src/skills/_self-improvement.md +42 -26
- package/src/skills/_template.md +3 -1
- package/src/skills/brainstorm.md +35 -22
- package/src/skills/codebase-design.md +2 -2
- package/src/skills/daydream/VENDOR.md +6 -0
- package/src/skills/diagram-design/SKILL.md +12 -7
- package/src/skills/diagram-design/VENDOR.md +23 -14
- package/src/skills/diagram-design/references/layout-budget.md +7 -1
- package/src/skills/diagram-design/references/onboarding.md +1 -1
- package/src/skills/diagram-design/references/primitives-core.md +1 -1
- package/src/skills/diagram-design/references/semantic-patterns.md +1 -1
- package/src/skills/diagram-design/references/style-guide.md +1 -1
- package/src/skills/diagram-design/references/type-dependency.md +69 -0
- package/src/skills/diagram-design/references/type-event-modeling.md +36 -0
- package/src/skills/diagram-design/references/type-requirement-traceability.md +45 -0
- package/src/skills/diagram-design/references/type-sbgn.md +80 -0
- package/src/skills/diagram-design/references/type-scatter.md +1 -1
- package/src/skills/diagram-design/references/type-steps.md +180 -0
- package/src/skills/diagram-design/references/type-unit-grid.md +63 -0
- package/src/skills/explain-changes/VENDOR.md +5 -1
- package/src/skills/geneseed-code-review.md +2 -1
- package/src/skills/parallel-agents.md +12 -1
- package/src/skills/pipeline.md +3 -3
- package/src/skills/plan.md +5 -4
- package/src/skills/react-view-transitions/AGENTS.md +26 -26
- package/src/skills/react-view-transitions/SKILL.md +1 -1
- package/src/skills/react-view-transitions/VENDOR.md +19 -4
- package/src/skills/release.md +7 -2
- package/src/skills/rule/approve.md +2 -1
- package/src/skills/skill-forge.md +5 -3
- package/src/skills/spring-boot/cloud.md +19 -1
- package/src/skills/spring-boot/logging.md +5 -3
- package/src/skills/spring-boot/web.md +27 -2
- package/src/skills/spring-boot.md +4 -2
- package/src/skills/spring-data-jpa.md +18 -4
- package/src/skills/spring-testing.md +4 -0
- package/src/skills/token-report/VENDOR.md +5 -1
- package/src/upstreams.json +6 -6
- package/themes/README.md +3 -1
- package/web/dist/assets/{ActiveLoops-BJJN3P-V.js → ActiveLoops-DOJCPPPc.js} +1 -1
- package/web/dist/assets/{Activity-D2kOc3yi.js → Activity-bUSPM3Dl.js} +1 -1
- package/web/dist/assets/{ActivityDetail-By3xOr21.js → ActivityDetail-AHRoXeFN.js} +1 -1
- package/web/dist/assets/{Bonsai-CBWDTBA4.js → Bonsai-B5XY9pid.js} +1 -1
- package/web/dist/assets/{CopyButton-BVbpriMB.js → CopyButton-C0wwRR9H.js} +1 -1
- package/web/dist/assets/{Dashboard-CIJLPHM9.js → Dashboard-DPAA96EI.js} +2 -2
- package/web/dist/assets/{Docs-CiRRIELs.js → Docs-CpGDq165.js} +1 -1
- package/web/dist/assets/{Factories-DhyK0O8d.js → Factories-cNhETa5Q.js} +1 -1
- package/web/dist/assets/{GreenhouseView-DW3PgTPy.js → GreenhouseView-DO3ADmT9.js} +1 -1
- package/web/dist/assets/Installs-D3dDyq10.js +3 -0
- package/web/dist/assets/{JournalView-O65qEWfp.js → JournalView--W-Lw_V9.js} +1 -1
- package/web/dist/assets/{Kits-C5U-yT6Z.js → Kits-ChfehxY6.js} +1 -1
- package/web/dist/assets/Laws-CNxYmV36.js +4 -0
- package/web/dist/assets/{LibRows-D6-CVa3K.js → LibRows-CiPvsRYB.js} +1 -1
- package/web/dist/assets/{Library-CzPlerd6.js → Library-BxQvbwVU.js} +1 -1
- package/web/dist/assets/{Loops-CqNF_-nS.js → Loops-DAblKkyq.js} +1 -1
- package/web/dist/assets/{OperatorHudView-BNr8K5qj.js → OperatorHudView-QtSaSyYm.js} +1 -1
- package/web/dist/assets/{Personal-DeDb9e8O.js → Personal-DxSGv638.js} +1 -1
- package/web/dist/assets/{Settings-B8MPN_AD.js → Settings-CgTbhvRv.js} +1 -1
- package/web/dist/assets/{Tabs-DJzAez4h.js → Tabs-Cf4X1hdz.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-BL3P-9Rg.js → index-B_pTwZra.js} +4 -4
- package/web/dist/assets/index-CzfImiYb.css +1 -0
- package/web/dist/index.html +3 -3
- package/web/dist/assets/Installs-B6nlo-Ly.js +0 -3
- package/web/dist/assets/Laws-CuTw_XNf.js +0 -4
- package/web/dist/assets/api-DLDVY3K-.js +0 -1
- package/web/dist/assets/index-CRWqKxfY.css +0 -1
|
@@ -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
|
+
}
|