geneseed 5.4.0 → 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.
Files changed (162) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/README.md +30 -0
  3. package/SHIPPED.md +1 -1
  4. package/adapters/bob/README.md +12 -1
  5. package/adapters/opencode/README.md +2 -1
  6. package/adapters/opencode/plugins/geneseed-context.js +71 -10
  7. package/adapters/opencode/plugins/geneseed-guard.js +101 -19
  8. package/adapters/opencode/plugins/geneseed-learn.js +641 -6
  9. package/bin/geneseed-cli.mjs +3 -0
  10. package/bin/geneseed-hook.mjs +2 -1
  11. package/docs/concepts/agents.md +13 -1
  12. package/docs/concepts/enforcement-table.md +1 -1
  13. package/docs/concepts/foreman-mode.md +22 -3
  14. package/docs/concepts/hook-gates.md +1 -1
  15. package/docs/concepts/hooks.md +22 -5
  16. package/docs/concepts/host-matrix.md +2 -2
  17. package/docs/concepts/hosts.md +1 -1
  18. package/docs/concepts/shared-tier.md +1 -1
  19. package/docs/concepts/skills.md +21 -1
  20. package/docs/concepts/themes.md +1 -1
  21. package/docs/extending.md +10 -1
  22. package/docs/guides/install-clone.md +18 -0
  23. package/docs/guides/install-scripted.md +8 -2
  24. package/docs/guides/install.md +19 -1
  25. package/docs/guides/upgrade.md +1 -1
  26. package/docs/reference/env-context.md +1 -1
  27. package/docs/reference/environment.md +1 -1
  28. package/docs/reference/plugin-learn.md +4 -0
  29. package/docs/reference/profiles.md +142 -0
  30. package/docs/token-footprint.md +9 -4
  31. package/docs/understand/design-choices-engineering.md +1 -1
  32. package/docs/web-ui.md +3 -1
  33. package/harness.config.json +1 -1
  34. package/js/README.md +9 -2
  35. package/js/build/args.mjs +4 -3
  36. package/js/build/catalog.mjs +11 -1
  37. package/js/build/driver.mjs +42 -11
  38. package/js/build/emit-claude.mjs +24 -1
  39. package/js/build/emit-opencode.mjs +3 -0
  40. package/js/build/export.mjs +1 -1
  41. package/js/build/generate.mjs +2 -1
  42. package/js/build/notes-migrate.mjs +99 -0
  43. package/js/build/profile.mjs +14 -6
  44. package/js/build/render.mjs +34 -10
  45. package/js/build/source.mjs +85 -2
  46. package/js/cli-table.json +164 -4
  47. package/js/hosts/agent-runs.mjs +205 -0
  48. package/js/hosts/done-checks.mjs +3 -1
  49. package/js/hosts/hooks-done.mjs +91 -16
  50. package/js/hosts/hooks-learn.mjs +85 -0
  51. package/js/hosts/hooks-prims.mjs +39 -1
  52. package/js/hosts/hooks.mjs +6 -3
  53. package/js/hosts/hosts.mjs +10 -0
  54. package/js/hosts/installs.mjs +25 -1
  55. package/js/hosts/link.mjs +45 -10
  56. package/js/hosts/native.mjs +42 -5
  57. package/js/hosts/opencode.mjs +1 -1
  58. package/js/hosts/settings.mjs +72 -0
  59. package/js/hosts/spec-feedback.mjs +538 -0
  60. package/js/hosts/usage.mjs +67 -8
  61. package/js/inspect/agent-scores.mjs +118 -0
  62. package/js/inspect/checks-authoring.mjs +2 -1
  63. package/js/inspect/checks-build.mjs +20 -4
  64. package/js/inspect/checks-repo.mjs +27 -2
  65. package/js/inspect/cost.mjs +6 -5
  66. package/js/inspect/diff.mjs +25 -5
  67. package/js/inspect/doctor.mjs +4 -0
  68. package/js/inspect/status.mjs +3 -1
  69. package/js/inspect/validate.mjs +1 -0
  70. package/js/lib/machine-dir.mjs +8 -0
  71. package/js/lib/paths.mjs +4 -1
  72. package/js/maintain/profile-scope.mjs +145 -0
  73. package/js/maintain/profiles.mjs +486 -0
  74. package/js/maintain/setup.mjs +409 -15
  75. package/js/maintain/uninstall.mjs +4 -1
  76. package/js/maintain/update.mjs +1 -1
  77. package/js/web/actions.mjs +28 -38
  78. package/js/web/api.mjs +7 -2
  79. package/js/web/handler.mjs +8 -0
  80. package/js/web/jobs.mjs +5 -4
  81. package/js/web/profiles-api.mjs +201 -0
  82. package/js/web/routes.mjs +5 -0
  83. package/package.json +2 -1
  84. package/profiles/guillaume-claude-global.json +16 -0
  85. package/profiles/starter.json +14 -0
  86. package/src/AGENT.md.tmpl +1 -1
  87. package/src/agents/_self-improvement.md +15 -7
  88. package/src/agents/_template.md +4 -2
  89. package/src/agents/advocate.md +1 -1
  90. package/src/agents/architect.md +1 -1
  91. package/src/agents/developer.md +10 -3
  92. package/src/agents/devops-engineer.md +1 -1
  93. package/src/agents/docker-expert.md +1 -1
  94. package/src/agents/docs.md +1 -1
  95. package/src/agents/empiricist.md +1 -1
  96. package/src/agents/explorer.md +4 -2
  97. package/src/agents/framer.md +1 -1
  98. package/src/agents/historian.md +1 -1
  99. package/src/agents/kubernetes-specialist.md +1 -1
  100. package/src/agents/memory-curator.md +1 -1
  101. package/src/agents/operator.md +1 -1
  102. package/src/agents/performance.md +1 -1
  103. package/src/agents/pragmatist.md +1 -1
  104. package/src/agents/react-engineer.md +1 -1
  105. package/src/agents/react-reviewer.md +1 -1
  106. package/src/agents/researcher.md +1 -1
  107. package/src/agents/reviewer.md +10 -3
  108. package/src/agents/security.md +1 -1
  109. package/src/agents/skeptic.md +1 -1
  110. package/src/agents/spring-boot-engineer.md +1 -1
  111. package/src/agents/spring-reviewer.md +1 -1
  112. package/src/agents/spring-security.md +1 -1
  113. package/src/agents/steward.md +1 -1
  114. package/src/agents/tester.md +4 -2
  115. package/src/agents/user-advocate.md +1 -1
  116. package/src/agents/visionary.md +1 -1
  117. package/src/memory/README.md +12 -2
  118. package/src/modes/foreman.md +23 -10
  119. package/src/skill-descriptions.json +63 -0
  120. package/src/skills/_self-improvement.md +42 -26
  121. package/src/skills/_template.md +3 -1
  122. package/src/skills/brainstorm.md +35 -22
  123. package/src/skills/daydream/VENDOR.md +6 -0
  124. package/src/skills/diagram-design/VENDOR.md +4 -0
  125. package/src/skills/explain-changes/VENDOR.md +5 -1
  126. package/src/skills/parallel-agents.md +11 -0
  127. package/src/skills/pipeline.md +3 -3
  128. package/src/skills/plan.md +5 -4
  129. package/src/skills/react-view-transitions/VENDOR.md +7 -1
  130. package/src/skills/release.md +7 -2
  131. package/src/skills/rule/approve.md +2 -1
  132. package/src/skills/skill-forge.md +5 -3
  133. package/src/skills/token-report/VENDOR.md +5 -1
  134. package/src/upstreams.json +2 -2
  135. package/themes/README.md +3 -1
  136. package/web/dist/assets/{ActiveLoops-BJJN3P-V.js → ActiveLoops-DOJCPPPc.js} +1 -1
  137. package/web/dist/assets/{Activity-D2kOc3yi.js → Activity-LKsDzsnK.js} +1 -1
  138. package/web/dist/assets/{ActivityDetail-By3xOr21.js → ActivityDetail-DhwTfPm6.js} +1 -1
  139. package/web/dist/assets/{Bonsai-CBWDTBA4.js → Bonsai-CePMLrpr.js} +1 -1
  140. package/web/dist/assets/{CopyButton-BVbpriMB.js → CopyButton-CuoaJ6k7.js} +1 -1
  141. package/web/dist/assets/{Dashboard-CIJLPHM9.js → Dashboard-D1VKuvLe.js} +2 -2
  142. package/web/dist/assets/{Docs-CiRRIELs.js → Docs-CUrHJKaU.js} +1 -1
  143. package/web/dist/assets/{Factories-DhyK0O8d.js → Factories-Ci1XfmSy.js} +1 -1
  144. package/web/dist/assets/{GreenhouseView-DW3PgTPy.js → GreenhouseView-CNfH2lPK.js} +1 -1
  145. package/web/dist/assets/Installs-ZHQZM1iS.js +3 -0
  146. package/web/dist/assets/{JournalView-O65qEWfp.js → JournalView-CMsWahkS.js} +1 -1
  147. package/web/dist/assets/{Kits-C5U-yT6Z.js → Kits-CkliyK0n.js} +1 -1
  148. package/web/dist/assets/{Laws-CuTw_XNf.js → Laws-hh4O3HZ4.js} +1 -1
  149. package/web/dist/assets/{LibRows-D6-CVa3K.js → LibRows-Brv0Hmkr.js} +1 -1
  150. package/web/dist/assets/{Library-CzPlerd6.js → Library-BYmiLjJr.js} +1 -1
  151. package/web/dist/assets/{Loops-CqNF_-nS.js → Loops-ytm-xJ68.js} +1 -1
  152. package/web/dist/assets/{OperatorHudView-BNr8K5qj.js → OperatorHudView-KaqCx_HP.js} +1 -1
  153. package/web/dist/assets/{Personal-DeDb9e8O.js → Personal-CmcnRKYE.js} +1 -1
  154. package/web/dist/assets/{Settings-B8MPN_AD.js → Settings-tUrpdOfq.js} +1 -1
  155. package/web/dist/assets/{Tabs-DJzAez4h.js → Tabs-CD7etcGD.js} +1 -1
  156. package/web/dist/assets/api-CZ-x0iWG.js +1 -0
  157. package/web/dist/assets/{controls-D4wmg_pl.js → controls-CK7qHA8H.js} +1 -1
  158. package/web/dist/assets/{index-CRWqKxfY.css → index-Ba_Kg3Af.css} +1 -1
  159. package/web/dist/assets/{index-BL3P-9Rg.js → index-COKbhFNo.js} +3 -3
  160. package/web/dist/index.html +3 -3
  161. package/web/dist/assets/Installs-B6nlo-Ly.js +0 -3
  162. package/web/dist/assets/api-DLDVY3K-.js +0 -1
@@ -45,20 +45,25 @@ import { existsSync, readdirSync } from 'node:fs';
45
45
  import os from 'node:os';
46
46
  import path from 'node:path';
47
47
 
48
- import { main as driverMain, resolveOut } from '../build/driver.mjs';
48
+ import { main as driverMain, parseDriverArgs, resolveOut } from '../build/driver.mjs';
49
+ import { preserveRefusal } from '../build/profile.mjs';
50
+ import { cmdLink } from '../hosts/link.mjs';
51
+ import { autostartInstall, autostartState, transientRoot } from '../hosts/shim.mjs';
52
+ import { loadProfile, profileBuildArgs, profileHosts } from './profiles.mjs';
53
+ import { checkProjectFolder, globalLayering, layeringText } from './profile-scope.mjs';
49
54
  import { playLine } from '../ui/anim.mjs';
50
- import { discoverNames, GATE_SWITCHES, PACK_ORDER, loadKits } from '../build/source.mjs';
55
+ import { DEFAULT_CONTEXT_WINDOW, discoverNames, GATE_SWITCHES, PACK_ORDER, ROOT, loadKits } from '../build/source.mjs';
51
56
  import { exportImprovements } from '../inspect/diff.mjs';
52
57
  import { cmdDoctor } from '../inspect/doctor.mjs';
53
58
  import { setupBuildArgs } from '../build/generate.mjs';
54
59
  import { SHARED_TIER_BENEFIT, sharedTierCost, sharedTierFigure } from '../inspect/cost.mjs';
55
60
  import { GLOBAL_MANIFEST, HOSTS, opencodeConfigDir } from '../hosts/hosts.mjs';
56
61
  import {
57
- claudeCfg, defaultMode, defaultPosture, defaultTheme, EMIT_HOST_SCOPE, gatesOfDir, installedDefaults,
58
- readJsonMaybe, sharedTierOfDir, themeFiles,
62
+ claudeCfg, defaultMode, defaultPosture, defaultTheme, EMIT_HOST_SCOPE, gatesOfDir, installedDefaults, installState,
63
+ contextWindowOfDir, readJsonMaybe, sharedTierOfDir, themeFiles,
59
64
  } from '../hosts/installs.mjs';
60
65
  import { printOut, printErr } from '../lib/fs.mjs';
61
- import { which } from '../lib/paths.mjs';
66
+ import { inNpxCache, which } from '../lib/paths.mjs';
62
67
  import { ask, askChoice, confirm } from '../lib/prompt.mjs';
63
68
  import { parseIntStrict } from '../lib/text.mjs';
64
69
  import { NO_WINDOW } from '../lib/proc.mjs';
@@ -288,6 +293,25 @@ function targetGates(emit, out) {
288
293
  }
289
294
  }
290
295
 
296
+ /**
297
+ * The context window of the one install a setup answer re-runs, read off it as `targetGates`
298
+ * reads the gates. PRESERVED, NOT ASKED: the wizard's questions are answered by holding Enter and
299
+ * every recorded probe compares them byte for byte, so the option is set with the flag, a profile
300
+ * or the console. A target with no install takes `machine`, the machine's answer
301
+ * (`installedDefaults`), as the CLI's new project does. Unreadable reads as the default.
302
+ */
303
+ export function targetContextWindow(emit, out, machine = DEFAULT_CONTEXT_WINDOW) {
304
+ const [host, scope] = EMIT_HOST_SCOPE.get(emit) ?? [];
305
+ try {
306
+ if (!host) return contextWindowOfDir(resolveOut(out || 'Harness'));
307
+ const dir = scope === 'global'
308
+ ? HOSTS.find((h) => h.host === host).configDir() : resolveOut(out || '.');
309
+ return installState(dir, host, scope) === 'absent' ? machine : contextWindowOfDir(dir, host);
310
+ } catch {
311
+ return DEFAULT_CONTEXT_WINDOW;
312
+ }
313
+ }
314
+
291
315
  export function collectSetupLines(kitMap = null) {
292
316
  printOut('Geneseed setup — answer a few questions; nothing is written until you confirm.\n');
293
317
  const inst = installedDefaults();
@@ -334,15 +358,17 @@ export function collectSetupLines(kitMap = null) {
334
358
  // `setupBuildArgs` elides an armed gate, so an all-armed install prints what it always did.
335
359
  const gates = targetGates(emit, out);
336
360
  const gated = Object.values(gates).some((on) => on === false);
361
+ const contextWindow = targetContextWindow(emit, out, inst.contextWindow);
337
362
  printOut(`\nAbout to run: geneseed build ${
338
363
  setupBuildArgs(theme, emit, out, root, footprint, posture, mode, doctrines, allPacks,
339
- excludeRules, undefined, excludeSkills, gates, kits, sharedTier).join(' ')} --reset\n`);
364
+ excludeRules, undefined, excludeSkills, gates, kits, sharedTier, contextWindow).join(' ')} --reset\n`);
340
365
  if (!confirm('Proceed?', true)) return null;
341
366
  // The key only when there is something to carry, so a selection that excludes no skill and
342
367
  // switches off no gate is the same object it was before either existed.
343
368
  return {
344
369
  theme, posture, mode, doctrines, excludeRules, ...(excludeSkills ? { excludeSkills } : {}),
345
370
  ...(gated ? { gates } : {}), ...(kits ? { kits } : {}), ...(sharedTier ? { sharedTier } : {}),
371
+ ...(contextWindow !== DEFAULT_CONTEXT_WINDOW ? { contextWindow } : {}),
346
372
  emit, out, root, footprint,
347
373
  };
348
374
  }
@@ -488,6 +514,22 @@ export function setupSummaryLines(theme, emit, out, root, ok) {
488
514
  // the flow
489
515
  // --------------------------------------------------------------------------------------
490
516
 
517
+ /**
518
+ * The note a setup run from the npx cache ends with; empty anywhere else.
519
+ *
520
+ * `npx geneseed setup` puts no `geneseed` command on PATH, and `link` must not: its launcher would
521
+ * name the npx cache, which npm prunes (`inNpxCache`). A global install is the lasting copy, so
522
+ * the note points there. A hint, not an act: running npm from here would breach the CLI's spawn
523
+ * ban and reach the network (decided 2026-11-13, O1 over an offered `npm i -g`).
524
+ */
525
+ export function npxPathHint(root = ROOT) {
526
+ if (!inNpxCache(root)) return [];
527
+ return [
528
+ 'This setup ran from the npx cache, so there is no `geneseed` command in your terminal.',
529
+ 'For a lasting one: npm install -g geneseed, then run geneseed setup again.',
530
+ ];
531
+ }
532
+
491
533
  /**
492
534
  * Gather, export drift, build, summarise, offer the doctor.
493
535
  *
@@ -522,7 +564,7 @@ export function setupLines() {
522
564
  const {
523
565
  theme, emit, out, root, footprint = 'lean', posture = 'peer', mode = 'direct',
524
566
  doctrines = null, excludeRules = null, excludeSkills = null, gates = {}, kits = null,
525
- sharedTier = false,
567
+ sharedTier = false, contextWindow = DEFAULT_CONTEXT_WINDOW,
526
568
  } = sel;
527
569
  if (emit === 'opencode-global') {
528
570
  // The build below overwrites the deployed global harness, which may carry hand edits (or
@@ -541,7 +583,8 @@ export function setupLines() {
541
583
  // runs must carry the pack selection the plan line just previewed, or the wizard would print
542
584
  // one command and run another.
543
585
  const argv = setupBuildArgs(theme, emit, out, root, footprint, posture, mode, doctrines,
544
- doctrineOptions().map(([n]) => n), excludeRules, undefined, excludeSkills, gates, kits, sharedTier);
586
+ doctrineOptions().map(([n]) => n), excludeRules, undefined, excludeSkills, gates, kits, sharedTier,
587
+ contextWindow);
545
588
  // `--reset`: the wizard's answers are a WHOLE selection, and `setupBuildArgs` elides an axis at
546
589
  // its default, so answering one back to it (mode direct, posture peer) over an install would
547
590
  // otherwise trip the preserve guard (js/build/profile.mjs). The plan line above says the same.
@@ -558,6 +601,7 @@ export function setupLines() {
558
601
  for (const [kind, text] of setupSummaryLines(theme, emit, out, root, true)) {
559
602
  printOut(`${{ ok: '✓', warn: '!', info: '-' }[kind] ?? '-'} ${text}\n`);
560
603
  }
604
+ for (const line of npxPathHint()) printOut(`! ${line}\n`);
561
605
  if (confirm('\nRun a health check (doctor) now?', true)) {
562
606
  // Scoped to the theme just installed — no full-sweep noise post-install.
563
607
  return cmdDoctor({ theme, all: false, bundle: null, noBundle: false });
@@ -572,12 +616,15 @@ export function setupLines() {
572
616
  * only part of this file the acceptance matrix compares. `process.stdin.isTTY` is `undefined`
573
617
  * off a terminal rather than `false`, which is why it is negated rather than compared.
574
618
  */
575
- export async function cmdSetup() {
619
+ export async function cmdSetup(args = {}) {
576
620
  const refusal = (await import('./update.mjs')).gateRefusal();
577
621
  if (refusal) {
578
622
  printErr(`[setup] not started: ${refusal}\n`);
579
623
  return 1;
580
624
  }
625
+ // Before the TTY refusal: a profile run asks nothing, so a script or a remote shell may run it
626
+ // (install profiles, D15).
627
+ if (args?.profile) return setupProfile(args.profile);
581
628
  if (!process.stdin.isTTY) {
582
629
  printErr('[setup] needs an interactive terminal. Non-interactive? e.g.:\n'
583
630
  + ' geneseed build --emit opencode-global --theme neutral\n');
@@ -587,6 +634,17 @@ export async function cmdSetup() {
587
634
  return setupLines();
588
635
  }
589
636
 
637
+ /**
638
+ * `[label, command, install url]` per host, in HOSTS order. The command is also the host id a
639
+ * profile lists (`setupProfile` pairs a `hostTools` row with its host by this index).
640
+ */
641
+ const HOST_TOOLS = [
642
+ ['OpenCode', 'opencode', 'https://opencode.ai/docs/'],
643
+ ['Claude Code', 'claude', 'https://code.claude.com/docs/en/setup'],
644
+ ['IBM Bob', 'bob', 'https://bob.ibm.com/'],
645
+ ['OpenClaude', 'openclaude', 'https://openclaude.gitlawb.com/'],
646
+ ];
647
+
590
648
  /**
591
649
  * The AI coding tools Geneseed installs into, as `[label, present, url, where]` rows in HOSTS
592
650
  * order. `where` is the path found OFF the PATH (see `userInstall`), else null.
@@ -604,12 +662,7 @@ export async function cmdSetup() {
604
662
  * test, which cannot rely on what this machine happens to have installed.
605
663
  */
606
664
  export function hostTools({ lookup = which, userLookup = userInstall } = {}) {
607
- return [
608
- ['OpenCode', 'opencode', 'https://opencode.ai/docs/'],
609
- ['Claude Code', 'claude', 'https://code.claude.com/docs/en/setup'],
610
- ['IBM Bob', 'bob', 'https://bob.ibm.com/'],
611
- ['OpenClaude', 'openclaude', 'https://openclaude.gitlawb.com/'],
612
- ].map(([label, cmd, url]) => {
665
+ return HOST_TOOLS.map(([label, cmd, url]) => {
613
666
  if (lookup(cmd)) return [label, true, url, null];
614
667
  const where = userLookup(cmd);
615
668
  return [label, Boolean(where), url, where || null];
@@ -695,3 +748,344 @@ function toolsReport(tools = hostTools()) {
695
748
  printOut('Stopped. Run setup again once a tool is installed.\n');
696
749
  return false;
697
750
  }
751
+
752
+ // --------------------------------------------------------------------------------------
753
+ // the profile run (`setup --profile <name>`)
754
+ // --------------------------------------------------------------------------------------
755
+
756
+ /**
757
+ * What a profile run would change back on `argv`'s target install, global or project (spec D14): the preserve
758
+ * guard's own comparison, run on the argv WITHOUT `--reset` (with it the guard returns null) and
759
+ * with no flag counted as given, so every setting that differs is listed. `[]` when there is no
760
+ * install there yet, or when the argv cannot be parsed (the build then refuses on its own terms).
761
+ */
762
+ export function profileChanges(argv) {
763
+ try {
764
+ const args = parseDriverArgs(argv.filter((a) => a !== '--reset'));
765
+ // A project emit's target is its `--out` folder (`guardTarget`); a global one ignores it.
766
+ return preserveRefusal(args, new Set(), args.out ?? null)?.changes ?? [];
767
+ } catch {
768
+ return [];
769
+ }
770
+ }
771
+
772
+ /**
773
+ * The login item, as one `{ ok, text }` line for the summary. Rewritten only when it is absent
774
+ * or stale (spec D7); a hand-written one is left alone with a warning that names it. `null`
775
+ * where the platform has no login item Geneseed writes. `state` and `install` are the test's
776
+ * seams; the defaults are `js/hosts/shim.mjs`'s.
777
+ */
778
+ export function loginItem({ state = autostartState, install = autostartInstall } = {}) {
779
+ const cur = state();
780
+ if (!cur) return null;
781
+ if (cur.state === 'ours') return { ok: true, text: `login item already set: ${cur.file}` };
782
+ if (cur.state === 'hand') {
783
+ return { ok: false, text: `login item not written: ${cur.file} was not written by Geneseed, so it is left alone` };
784
+ }
785
+ const r = install();
786
+ if (r.ok) return { ok: true, text: `login item written: ${cur.file}` };
787
+ return { ok: false, text: `login item not written: ${r.error} (see docs/guides/autostart.md)` };
788
+ }
789
+
790
+ /**
791
+ * Start the console without a browser, or restart it when it already runs so it serves the code
792
+ * just pulled (spec D21). `restartDaemon` with `onlyIfRunning` false is exactly that: it stops a
793
+ * live console first and starts one either way. The URL comes from the daemon record AFTER the
794
+ * start, because a busy port moves the console to another one. Lazy: `js/web/daemon.mjs` spawns,
795
+ * and only this arm of `setup` needs it.
796
+ */
797
+ async function defaultConsole() {
798
+ const [{ readDaemon, restartDaemon }, { webState }] = await Promise.all([
799
+ import('../web/daemon.mjs'), import('../web/state.mjs'),
800
+ ]);
801
+ const rc = await restartDaemon(null, null, false);
802
+ const url = readDaemon(webState(null).target)?.url ?? null;
803
+ return { ok: rc === 0 && Boolean(url), url };
804
+ }
805
+
806
+ /** `hostTools` rows as `{ label, host, url, present }`, in HOSTS order. */
807
+ function foundHosts(rows) {
808
+ return HOST_TOOLS.map(([label, host, url], i) => ({ label, host, url, present: Boolean(rows[i]?.[1]) }));
809
+ }
810
+
811
+ /**
812
+ * The per-host builds of a profile run, shared by `setup --profile` and `profile apply` (spec
813
+ * D16, D19, D33): for each target host, the settings the build will change back (D14), the local
814
+ * edits exported first (D19, a global install only: `diffCollect` reads no drift off a project
815
+ * install), then the build. A failure is recorded and the loop goes on.
816
+ *
817
+ * `project` set builds each host's project emit into that folder (D32); null builds globally.
818
+ */
819
+ export function profileBuilds(p, targets, { project = null, build, exportDrift, changes, configDir }) {
820
+ const results = [];
821
+ for (const t of targets) {
822
+ const argv = profileBuildArgs(p, t.host, project);
823
+ const moved = changes(argv);
824
+ let saved = null;
825
+ if (!project) {
826
+ try {
827
+ [saved] = exportDrift(configDir(t.host));
828
+ } catch (e) {
829
+ printOut(`! could not export local edits of ${t.label} (${e && e.message}) - continuing.\n`);
830
+ }
831
+ }
832
+ printOut(`Running: geneseed build ${argv.join(' ')}\n`);
833
+ let rc;
834
+ try {
835
+ rc = build(argv);
836
+ } catch (e) {
837
+ rc = e && e.exitCode ? e.exitCode : 1;
838
+ printErr(`[setup] ${t.label}: ${e && e.message}\n`);
839
+ }
840
+ results.push({ ...t, argv, rc, moved, saved, project });
841
+ }
842
+ return results;
843
+ }
844
+
845
+ /** The summary lines of `profileBuilds`' results: each host, what it put back, what it saved. */
846
+ export function profileBuildLines(results) {
847
+ const out = [];
848
+ for (const r of results) {
849
+ if (r.rc === 0) {
850
+ out.push(` ok ${r.label}: installed (${r.project ? `${r.host} project in ${r.project}` : `${r.host}-global`})`);
851
+ } else {
852
+ // D25: no --force on a profile run. The build's own output names the file it refused.
853
+ out.push(` FAIL ${r.label}: build failed (exit ${r.rc}) - see its output above. If it names a file`,
854
+ ' of yours at a name Geneseed ships, move that file, or replace it with:',
855
+ ` geneseed build ${r.argv.join(' ')} --force`);
856
+ }
857
+ // Only a build that ran put anything back; a failed one left the install as it was.
858
+ if (r.rc === 0 && r.moved.length) {
859
+ out.push(` changed back to the profile: ${r.moved.map((c) => `${c.name} ${c.from} -> ${c.to}`).join(', ')}`);
860
+ }
861
+ if (r.saved) out.push(` local edits saved to ${r.saved} (hand that file to your agent to back-port them)`);
862
+ }
863
+ return out;
864
+ }
865
+
866
+ /**
867
+ * `geneseed setup --profile <name>` — the whole install with no question asked.
868
+ *
869
+ * The flow is the spec's ("Flow of `geneseed setup --profile <name>`"): load the profile, find
870
+ * the hosts it lists on this machine (D27), build each one globally (a failure is recorded and
871
+ * the loop goes on, D16), then `link` (always, D23), the login item and the console (warnings,
872
+ * never failures), the doctor scoped to the profile's theme (D22), and an ASCII summary — the
873
+ * install scripts run in cmd.exe, whose codepage turns an em dash into mojibake.
874
+ *
875
+ * EVERY SIDE EFFECT IS A SEAM in `deps`, because each one reaches outside the checkout: `link`
876
+ * writes the real user PATH (PowerShell, HKCU) or a shell rc file, the login item writes the
877
+ * Startup folder or a LaunchAgent, the console spawns a daemon. A test injects all of them; the
878
+ * defaults are the real ones and only the CLI reaches them.
879
+ */
880
+ export async function setupProfile(name, deps = {}) {
881
+ const {
882
+ load = loadProfile, tools = null, build = driverMain, exportDrift = exportImprovements,
883
+ changes = profileChanges, link = (report) => cmdLink({ dir: null }, { unattended: true, report }),
884
+ autostart = loginItem, startConsole = defaultConsole, transient = transientRoot(ROOT),
885
+ doctor = (theme) => cmdDoctor({ theme, all: false, bundle: null, noBundle: false }),
886
+ configDir = (host) => HOSTS.find((h) => h.host === host).configDir(),
887
+ platform = process.platform,
888
+ } = deps;
889
+ const loaded = load(name);
890
+ if (!loaded.ok) {
891
+ printErr(`[setup] ${loaded.error}\n`);
892
+ return 1;
893
+ }
894
+ const p = loaded.profile;
895
+ const found = foundHosts(tools ?? hostTools());
896
+ const listed = found.filter((t) => p.hosts.includes(t.host));
897
+ const targets = listed.filter((t) => t.present);
898
+ printOut(`Geneseed setup - profile '${name}'${p.description ? `: ${p.description}` : ''}\n\n`);
899
+ if (!targets.length) {
900
+ // D3: nothing installed, each listed tool's install link, a non-zero exit.
901
+ printOut('None of the AI coding tools this profile installs into was found on this machine:\n');
902
+ for (const t of listed) printOut(` -- ${t.label} - install: ${t.url}\n`);
903
+ printOut('\nInstall one of them, then run this command again. Nothing was installed.\n');
904
+ return 1;
905
+ }
906
+
907
+ const results = profileBuilds(p, targets, { build, exportDrift, changes, configDir });
908
+ const built = results.filter((r) => r.rc === 0);
909
+
910
+ printOut('\n');
911
+ // A TEMPORARY COPY (an agent worktree, the npx cache) gets neither the PATH launcher nor the
912
+ // login item: both would point at a folder that is about to disappear (`transientRoot`).
913
+ const report = {};
914
+ let linkRc = 0;
915
+ if (!transient) {
916
+ try {
917
+ linkRc = link(report);
918
+ } catch (e) {
919
+ linkRc = 1;
920
+ printErr(`[setup] link: ${e && e.message}\n`);
921
+ }
922
+ }
923
+
924
+ let login = null;
925
+ let consoleUrl = null;
926
+ let consoleOk = true;
927
+ if (p.login !== false) {
928
+ if (transient) {
929
+ login = { ok: false, text: `login item not written: ${ROOT} is a temporary copy - run this from a lasting clone` };
930
+ } else if (platform === 'win32' || platform === 'darwin') {
931
+ try {
932
+ login = autostart();
933
+ } catch (e) {
934
+ login = { ok: false, text: `login item not written: ${e && e.message}` };
935
+ }
936
+ } else {
937
+ // D24: no login item here, and the console still starts now.
938
+ login = { ok: false, text: 'no login item exists for this platform - start the console with: geneseed web start' };
939
+ }
940
+ try {
941
+ const c = await startConsole();
942
+ consoleOk = c.ok;
943
+ consoleUrl = c.url;
944
+ } catch (e) {
945
+ consoleOk = false;
946
+ printErr(`[setup] web console: ${e && e.message}\n`);
947
+ }
948
+ }
949
+
950
+ // The doctor only over a harness that was written: with every build failed there is nothing
951
+ // for it to check that the failures above have not already said.
952
+ let doctorRc = null;
953
+ if (built.length) {
954
+ printOut('\n');
955
+ try {
956
+ doctorRc = doctor(p.theme);
957
+ } catch (e) {
958
+ doctorRc = 1;
959
+ printErr(`[setup] doctor: ${e && e.message}\n`);
960
+ }
961
+ }
962
+
963
+ const out = ['', `Summary - profile '${name}'`, ...profileBuildLines(results)];
964
+ for (const t of listed.filter((x) => !x.present)) out.push(` -- ${t.label}: not found - install: ${t.url}`);
965
+ for (const t of found.filter((x) => x.present && !p.hosts.includes(x.host))) {
966
+ out.push(` -- ${t.label}: found, not in this profile - left as it is`);
967
+ }
968
+ if (transient) {
969
+ out.push(` ! geneseed not put on PATH: ${ROOT} is a temporary copy - run this from a lasting clone`);
970
+ } else if (report.foreign) {
971
+ out.push(` ! geneseed on PATH: ${report.foreign} is not a launcher Geneseed wrote, so it was left alone`);
972
+ } else if (linkRc !== 0) {
973
+ out.push(' ! geneseed is not on PATH - run geneseed.cmd (Windows) or ./geneseed from this folder');
974
+ } else if (report.onPath === false) {
975
+ // `link` wrote the launcher and exits 0, but could not put its folder on PATH.
976
+ out.push(` ! geneseed is not on PATH yet: add ${report.pathDir} to your PATH by hand,`,
977
+ ' or run geneseed.cmd (Windows) or ./geneseed from this folder');
978
+ } else {
979
+ out.push(' ok geneseed on PATH (open a NEW terminal to use it)');
980
+ }
981
+ if (report.rcFile) out.push(` added the PATH block to ${report.rcFile}`);
982
+ if (login) out.push(` ${login.ok ? 'ok ' : '! '} ${login.text}`);
983
+ if (p.login !== false) {
984
+ out.push(consoleOk && consoleUrl ? ` ok web console: ${consoleUrl}`
985
+ : ' ! web console did not start - run: geneseed web start');
986
+ }
987
+ if (doctorRc !== null) out.push(doctorRc === 0 ? ' ok doctor' : ' FAIL doctor reported problems - see its output above');
988
+ out.push('', 'Next steps:',
989
+ ` 1. Open the web console: ${consoleUrl ?? 'geneseed web start'}`,
990
+ ' 2. Run: geneseed --help',
991
+ ' 3. Read the Understand docs: https://github.com/Arylmera/Geneseed/blob/main/docs/understand/',
992
+ '');
993
+ printOut(`${out.join('\n')}\n`);
994
+ return results.some((r) => r.rc !== 0) || (doctorRc !== null && doctorRc !== 0) ? 1 : 0;
995
+ }
996
+
997
+ // --------------------------------------------------------------------------------------
998
+ // `geneseed profile apply <name> [--project <dir>] [--hosts a,b]`
999
+ // --------------------------------------------------------------------------------------
1000
+
1001
+ /**
1002
+ * `geneseed profile apply` — build one profile, globally or into one project folder (spec D32,
1003
+ * D33, D37, D41).
1004
+ *
1005
+ * THE SCOPE IS CHOSEN HERE, NOT IN THE PROFILE. Global builds `<host>-global` for each host;
1006
+ * `--project <dir>` builds `--emit <host> --out <dir> --root <dir>`, and only there does the
1007
+ * profile's `sharedTier` count (D37). The hosts are the profile's, narrowed by `--hosts` (which
1008
+ * may name only the profile's own, D41), and of those the ones this machine has: a missing one is
1009
+ * a summary line, as in `setup --profile`. Every other install is left as it is.
1010
+ *
1011
+ * NOT THE ONBOARDING (D33): no `link`, no login item, no console, no doctor — `setup --profile`
1012
+ * does those. The build loop and its summary lines are `setupProfile`'s own (`profileBuilds`,
1013
+ * `profileBuildLines`), so a failure on one host never stops the others (D16) and the settings a
1014
+ * build changes back are listed (D14).
1015
+ *
1016
+ * In project scope, a host whose GLOBAL install is active gets one more line (D39): both root
1017
+ * files load in the folder, and the global gates that still run there (`globalLayering`).
1018
+ *
1019
+ * `src` is the profile sources' seam; `deps` the side effects', as in `setupProfile`.
1020
+ * @param {any} args
1021
+ * @param {{ src?: { shippedDir?: string, personalDir?: string } }} [opts]
1022
+ * @param {any} [deps]
1023
+ */
1024
+ export function cmdProfileApply(args, { src = {} } = {}, deps = {}) {
1025
+ const {
1026
+ load = (n) => loadProfile(n, src), tools = null, build = driverMain, exportDrift = exportImprovements,
1027
+ changes = profileChanges, configDir = (host) => HOSTS.find((h) => h.host === host).configDir(),
1028
+ layering = (host) => globalLayering(host, { configDir }),
1029
+ } = deps;
1030
+ const loaded = load(args.name);
1031
+ if (!loaded.ok) {
1032
+ printErr(`[profile] ${loaded.error}\n`);
1033
+ return 1;
1034
+ }
1035
+ const p = loaded.profile;
1036
+ let picked = p.hosts;
1037
+ if (args.hosts) {
1038
+ picked = [...new Set(String(args.hosts).split(',').map((h) => h.trim()).filter(Boolean))];
1039
+ // Two different mistakes, named apart: a word that is no host at all, and a real host this
1040
+ // profile does not list (D41: apply builds only the profile's own hosts).
1041
+ const known = profileHosts();
1042
+ const quote = (xs) => xs.map((h) => `'${h}'`).join(', ');
1043
+ const unknown = picked.filter((h) => !known.includes(h));
1044
+ const outside = picked.filter((h) => known.includes(h) && !p.hosts.includes(h));
1045
+ if (!picked.length || unknown.length || outside.length) {
1046
+ const why = !picked.length ? ['none given'] : [
1047
+ ...(unknown.length ? [`not a host: ${quote(unknown)} (hosts: ${known.join(', ')})`] : []),
1048
+ ...(outside.length ? [`not in this profile: ${quote(outside)}`] : []),
1049
+ ];
1050
+ printErr(`geneseed: error: --hosts: ${why.join('; ')} (profile '${args.name}' lists: ${p.hosts.join(', ')})\n`);
1051
+ return 2;
1052
+ }
1053
+ }
1054
+ const found = foundHosts(tools ?? hostTools());
1055
+ const listed = found.filter((t) => picked.includes(t.host));
1056
+ const targets = listed.filter((t) => t.present);
1057
+ let project = null;
1058
+ if (args.project) {
1059
+ // The hosts about to be built: a folder whose `.claude` (…) IS that host's global install is
1060
+ // refused for that host (`markerCollision`), so a project build never lands on the global.
1061
+ const r = checkProjectFolder(args.project, targets.map((t) => t.host));
1062
+ if (r.error) {
1063
+ printErr(`[profile] --project: ${r.error}\n`);
1064
+ return 1;
1065
+ }
1066
+ project = r.root;
1067
+ }
1068
+ const scope = project ? `project ${project}` : 'global';
1069
+ printOut(`Geneseed profile apply - '${args.name}' (${loaded.source ?? 'shipped'}) - ${scope}\n\n`);
1070
+ if (!targets.length) {
1071
+ printOut('None of the AI coding tools this apply builds was found on this machine:\n');
1072
+ for (const t of listed) printOut(` -- ${t.label} - install: ${t.url}\n`);
1073
+ printOut('\nInstall one of them, then run this command again. Nothing was built.\n');
1074
+ return 1;
1075
+ }
1076
+ const results = profileBuilds(p, targets, { project, build, exportDrift, changes, configDir });
1077
+ const out = ['', `Summary - profile '${args.name}', ${scope}`, ...profileBuildLines(results)];
1078
+ for (const t of listed.filter((x) => !x.present)) out.push(` -- ${t.label}: not found - install: ${t.url}`);
1079
+ for (const t of found.filter((x) => x.present && !picked.includes(x.host))) {
1080
+ out.push(` -- ${t.label}: ${p.hosts.includes(t.host) ? 'not picked' : 'not in this profile'} - left as it is`);
1081
+ }
1082
+ if (project) {
1083
+ for (const r of results.filter((x) => x.rc === 0)) {
1084
+ const text = layeringText(r.label, layering(r.host), project);
1085
+ if (text) out.push(` note ${text}`);
1086
+ }
1087
+ }
1088
+ out.push('');
1089
+ printOut(`${out.join('\n')}\n`);
1090
+ return results.some((r) => r.rc !== 0) ? 1 : 0;
1091
+ }
@@ -68,7 +68,7 @@ import {
68
68
  loadJsonObject, mergeClaudeSettings, opencodeTarget, OPENCODE_SENTINEL, opencodeSentinelWrite,
69
69
  OWNED_VERDICT,
70
70
  settingsIntegrityCheck, wireClaudeExcludes, unwireClaudeExcludes,
71
- unwireClaudeSettings, wireClaudeEnv, unwireClaudeEnv,
71
+ unwireClaudeSettings, wireClaudeEnv, unwireClaudeEnv, wireClaudeListing, unwireClaudeListing,
72
72
  } from '../hosts/settings.mjs';
73
73
  import { printOut, printErr, readText, writeText, isFile, isDir, isOsError } from '../lib/fs.mjs';
74
74
  import { indexOfDeepEqual, isDict, jsonDumps, deepEquals } from '../lib/json.mjs';
@@ -349,6 +349,7 @@ export function claudeUninstall(cfg, archiveMemory, force = false) {
349
349
  const unwired = unwireClaudeSettings(sf, hooks, cfg);
350
350
  unwireClaudeExcludes(sf, managed.settings_excludes || []);
351
351
  unwireClaudeEnv(sf, managed.settings_env);
352
+ unwireClaudeListing(sf, managed.settings_listing);
352
353
  // The unwire is VERIFIED, not assumed: a commented settings file is never rewritten, so a
353
354
  // supposedly-uninstalled repo could keep firing Geneseed's hooks. Loud, never fatal.
354
355
  settingsIntegrityCheck(sf, managed, 'absent');
@@ -1304,6 +1305,7 @@ function claudeDeactivate(root, scope = 'global', host = 'claude') {
1304
1305
  unwireClaudeSettings(settingsFile(cfg, managed), managed.settings_hooks || [], cfg);
1305
1306
  unwireClaudeExcludes(settingsFile(cfg, managed), managed.settings_excludes || []);
1306
1307
  unwireClaudeEnv(settingsFile(cfg, managed), managed.settings_env);
1308
+ unwireClaudeListing(settingsFile(cfg, managed), managed.settings_listing);
1307
1309
  // The same integrity check the uninstall path runs: a deactivate that silently failed to
1308
1310
  // unwire would leave hooks firing in a repo the user believes is off.
1309
1311
  settingsIntegrityCheck(settingsFile(cfg, managed), managed, 'absent');
@@ -1362,6 +1364,7 @@ function claudeReactivate(root, scope = 'global', host = 'claude') {
1362
1364
  wireClaudeExcludes(settingsFile(cfg, managed), managed.settings_excludes || []);
1363
1365
  // Only what the manifest records: a reactivate restores this install's own keys, never new ones.
1364
1366
  if (isDict(managed.settings_env)) wireClaudeEnv(settingsFile(cfg, managed), managed.settings_env);
1367
+ if (isDict(managed.settings_listing)) wireClaudeListing(settingsFile(cfg, managed), managed.settings_listing);
1365
1368
  cleanHostStash(cfg, host);
1366
1369
  return { ok: true, kind: host, moved };
1367
1370
  }
@@ -772,7 +772,7 @@ export async function installAxes(dir, { installProfile, setupBuildArgs }, notif
772
772
  if (!existsSync(path.join(String(dir), '.geneseed-emit'))) return [];
773
773
  const p = installProfile('opencode', 'global', String(dir), notify);
774
774
  return setupBuildArgs('', 'files', null, null, p.footprint, p.posture, p.mode, p.doctrines,
775
- undefined, p.excludeRules, p.trust, p.excludeSkills, p, p.kits, p.sharedTier).slice(4);
775
+ undefined, p.excludeRules, p.trust, p.excludeSkills, p, p.kits, p.sharedTier, p.contextWindow).slice(4);
776
776
  }
777
777
 
778
778
  /**