geneseed 3.14.0 → 3.16.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 (94) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/SHIPPED.md +1 -1
  3. package/adapters/opencode/plugins/geneseed-context.js +45 -11
  4. package/adapters/opencode/plugins/geneseed-guard.js +16 -4
  5. package/adapters/opencode/plugins/geneseed-learn.js +37 -11
  6. package/adapters/opencode/plugins/geneseed-notify.js +37 -19
  7. package/adapters/opencode/plugins/geneseed-workflow.js +3 -1
  8. package/adapters/opencode/workflows/_runtime.js +16 -3
  9. package/bin/geneseed-cli.mjs +22 -20
  10. package/bin/geneseed-hook.mjs +6 -3
  11. package/docs/concepts/exclusions.md +21 -9
  12. package/docs/guides/install-scripted.md +1 -1
  13. package/docs/guides/project-context.md +1 -1
  14. package/docs/token-footprint.md +10 -7
  15. package/harness.config.json +1 -1
  16. package/js/README.md +9 -5
  17. package/js/build/args.mjs +38 -6
  18. package/js/build/bundle.mjs +10 -10
  19. package/js/build/driver.mjs +16 -14
  20. package/js/build/emit-claude.mjs +3 -2
  21. package/js/build/emit-common.mjs +2 -14
  22. package/js/build/emit-opencode.mjs +12 -8
  23. package/js/build/generate.mjs +26 -16
  24. package/js/build/render.mjs +34 -4
  25. package/js/build/source.mjs +43 -7
  26. package/js/build/stubs.mjs +6 -5
  27. package/js/build/version.mjs +21 -2
  28. package/js/cli-table.json +15 -0
  29. package/js/hosts/hooks-context.mjs +85 -34
  30. package/js/hosts/hooks-prims.mjs +2 -2
  31. package/js/hosts/hosts.mjs +24 -26
  32. package/js/hosts/installs.mjs +58 -16
  33. package/js/hosts/link.mjs +75 -26
  34. package/js/hosts/memory-files.mjs +13 -4
  35. package/js/hosts/native.mjs +106 -48
  36. package/js/hosts/opencode.mjs +46 -36
  37. package/js/hosts/shim.mjs +4 -2
  38. package/js/inspect/diff.mjs +9 -7
  39. package/js/inspect/excludes.mjs +10 -5
  40. package/js/inspect/status.mjs +20 -22
  41. package/js/inspect/validate.mjs +5 -3
  42. package/js/lib/fs.mjs +12 -11
  43. package/js/lib/json.mjs +4 -4
  44. package/js/lib/paths.mjs +27 -33
  45. package/js/lib/proc.mjs +3 -3
  46. package/js/lib/prompt.mjs +132 -0
  47. package/js/lib/text.mjs +18 -4
  48. package/js/lib/udiff.mjs +3 -2
  49. package/js/maintain/memory.mjs +5 -6
  50. package/js/maintain/migrate.mjs +4 -3
  51. package/js/maintain/setup.mjs +20 -135
  52. package/js/maintain/uninstall.mjs +10 -9
  53. package/js/maintain/update.mjs +115 -34
  54. package/js/ui/anim.mjs +8 -12
  55. package/js/ui/cli.mjs +29 -35
  56. package/js/ui/menu.mjs +7 -13
  57. package/js/ui/tui.mjs +14 -123
  58. package/js/web/actions.mjs +87 -389
  59. package/js/web/activity.mjs +1 -1
  60. package/js/web/api.mjs +33 -717
  61. package/js/web/catalog.mjs +527 -0
  62. package/js/web/daemon.mjs +21 -3
  63. package/js/web/handler.mjs +51 -27
  64. package/js/web/jobs.mjs +24 -2
  65. package/js/web/routes.mjs +61 -6
  66. package/js/web/server.mjs +4 -4
  67. package/js/web/state.mjs +138 -0
  68. package/js/web/user-files.mjs +339 -0
  69. package/package.json +1 -1
  70. package/src/AGENT.md.tmpl +1 -1
  71. package/web/dist/assets/{Activity-CjRqZnr-.js → Activity-kpWxd70F.js} +1 -1
  72. package/web/dist/assets/{ActivityDetail-OQTxKBj2.js → ActivityDetail-Ccr942VL.js} +1 -1
  73. package/web/dist/assets/Dashboard-D1lE7jcg.js +2 -0
  74. package/web/dist/assets/{Docs-CvOZ8akL.js → Docs-BHyaggFy.js} +3 -3
  75. package/web/dist/assets/{GreenhouseView-6KDjX8da.js → GreenhouseView-Sc_UDMOE.js} +1 -1
  76. package/web/dist/assets/Installs-Gw-pJ3Zi.js +2 -0
  77. package/web/dist/assets/JournalView-_gxpsxXi.js +1 -0
  78. package/web/dist/assets/{Laws-Du0-Zyp2.js → Laws-S9fq1r9T.js} +1 -1
  79. package/web/dist/assets/{Library-DOkO0TtB.js → Library-MBxadRzn.js} +1 -1
  80. package/web/dist/assets/{Loops-Dv_aLByJ.js → Loops-Da_JhlzM.js} +2 -2
  81. package/web/dist/assets/{OperatorHudView-BPP1dtLz.js → OperatorHudView--TkvDybH.js} +1 -1
  82. package/web/dist/assets/{Personal-26VPYkK0.js → Personal-CTXKHVbV.js} +1 -1
  83. package/web/dist/assets/Tabs-B0cdf8k6.js +1 -0
  84. package/web/dist/assets/api-CxgfYu18.js +1 -0
  85. package/web/dist/assets/drawable-BbWQxe82.js +1 -0
  86. package/web/dist/assets/index-ujKG1ZNf.js +2 -0
  87. package/web/dist/index.html +2 -2
  88. package/web/dist/assets/Dashboard-J-xCe_Gk.js +0 -2
  89. package/web/dist/assets/Installs-MWuhNjSm.js +0 -2
  90. package/web/dist/assets/JournalView-C8MrOz2c.js +0 -1
  91. package/web/dist/assets/Tabs-BzKuFskD.js +0 -1
  92. package/web/dist/assets/api-D_ixdyEY.js +0 -1
  93. package/web/dist/assets/drawable-zVVDbsyw.js +0 -1
  94. package/web/dist/assets/index-KHt3wE_K.js +0 -2
@@ -66,8 +66,12 @@ export function sovereignBypass(root) {
66
66
  // `withDiscardableStderr` because `expanduser` writes its refusal at the RAISE SITE
67
67
  // and this caller catches: the reference prints nothing here, so replaying the
68
68
  // message would be a stderr divergence on every hook call for one bad entry.
69
+ //
70
+ // `resolvePath`, the same resolution as `cwd` above: symlinks and junctions are followed on
71
+ // BOTH sides, so an entry spelled through a link matches the real directory the session
72
+ // stands in (and the OpenCode plugins' `norm` applies the identical rule).
69
73
  base = withDiscardableStderr(
70
- () => normcase(toPlatformPath(expanduser(raw.trim()))).replace(/[\\/]+$/, ''));
74
+ () => normcase(resolvePath(raw.trim())).replace(/[\\/]+$/, ''));
71
75
  } catch {
72
76
  // PER ENTRY, and the loop continues. One unusable line in a file the USER hand-edits
73
77
  // must not decide the whole function — `expanduser` refuses a `~user` form, and the
@@ -208,14 +212,13 @@ export function openclaudeConfigDir() {
208
212
  }
209
213
 
210
214
  /**
211
- * `_build_global.HOSTS`, reduced to the two columns a non-emitting caller needs, and IN ITS
212
- * ORDER — opencode, claude, bob, openclaude.
215
+ * `_build_global.HOSTS` — one row per host, IN ITS ORDER: opencode, claude, bob, openclaude.
216
+ * A new host is one row here; `EMIT_HOST_SCOPE` (`js/hosts/installs.mjs`) and `CLAUDE_STYLE`
217
+ * below are derived from it.
213
218
  *
214
219
  * An array rather than an object because the order is observable output, not an
215
220
  * implementation detail: `harness exclude add` walks it and prints one message per host, so
216
- * a reordering is a diff in stderr. (`emit_global` and `native_catalog` stay out;
217
- * `bin/build-driver.mjs` receives those decisions from its own dispatch rather than reading a
218
- * table.)
221
+ * a reordering is a diff in stderr.
219
222
  *
220
223
  * `projectMarker` joined in P5f. `_install_targets` asks "does this cwd carry a project
221
224
  * install of host H", and `_claude_cfg` asks "which subdir holds a project install's
@@ -232,13 +235,16 @@ export function openclaudeConfigDir() {
232
235
  * `family` joined in 2026-10: `'claude'` for every host emitted through the Claude-shaped
233
236
  * engine — one manifest shape, one `settings.json` hook wiring, one strict-JSON `mcpServers`
234
237
  * config, one reversal. The list had been spelled out by hand in ten places, one of which
235
- * ignored the named constant right above it; a fifth host is now one row here.
238
+ * ignored the named constant right above it.
239
+ *
240
+ * `catalog` — does the host list every skill and agent to the model by itself? See
241
+ * `hostCatalogsNatively` below for what it decides and why it is split per kind.
236
242
  */
237
243
  export const HOSTS = [
238
- { host: 'opencode', family: 'opencode', configDir: opencodeConfigDir, projectMarker: '.opencode', agentFile: 'AGENT.md' },
239
- { host: 'claude', family: 'claude', configDir: claudeConfigDir, projectMarker: '.claude', agentFile: 'CLAUDE.md' },
240
- { host: 'bob', family: 'claude', configDir: bobConfigDir, projectMarker: '.bob', agentFile: 'AGENTS.md' },
241
- { host: 'openclaude', family: 'claude', configDir: openclaudeConfigDir, projectMarker: '.openclaude', agentFile: 'CLAUDE.md' },
244
+ { host: 'opencode', family: 'opencode', configDir: opencodeConfigDir, projectMarker: '.opencode', agentFile: 'AGENT.md', catalog: { skills: true, agents: true } },
245
+ { host: 'claude', family: 'claude', configDir: claudeConfigDir, projectMarker: '.claude', agentFile: 'CLAUDE.md', catalog: { skills: true, agents: true } },
246
+ { host: 'bob', family: 'claude', configDir: bobConfigDir, projectMarker: '.bob', agentFile: 'AGENTS.md', catalog: { skills: true, agents: false } },
247
+ { host: 'openclaude', family: 'claude', configDir: openclaudeConfigDir, projectMarker: '.openclaude', agentFile: 'CLAUDE.md', catalog: { skills: true, agents: true } },
242
248
  ];
243
249
 
244
250
  /** The Claude-STYLE hosts (`family: 'claude'`), in `HOSTS` order. Test with `.includes(host)`. */
@@ -248,12 +254,11 @@ export const CLAUDE_STYLE = HOSTS.filter((h) => h.family === 'claude').map((h) =
248
254
  * `_build_global.host_catalogs_natively` — does `host` list every skill and agent to the
249
255
  * model by itself?
250
256
  *
251
- * The third column of `HOSTS`, and the reason the docblock above no longer says
252
- * `native_catalog` stays out: `doctor`'s `_rendered_problems` has to know, because a host
257
+ * `HOSTS`' `catalog` column. `doctor`'s `_rendered_problems` has to know, because a host
253
258
  * that catalogues natively gets AGENT.md's tables collapsed to a pointer and comparing the
254
259
  * portable shape against its bundle reports AGENT.md stale on every run forever. It is a
255
- * column and not a set literal so that the capability is still declared in exactly one place
256
- * — the Python's own reason for the helper.
260
+ * column and not a set literal so that the capability is declared in exactly one place
261
+ * — the Python's own reason for the helper. The driver reads it through this function too.
257
262
  *
258
263
  * Unknown host -> false, which is the shape that KEEPS the tables. The value arrives from a
259
264
  * user-editable `.geneseed-emit` marker, so an unrecognised one must degrade to the portable
@@ -264,19 +269,12 @@ export const CLAUDE_STYLE = HOSTS.filter((h) => h.family === 'claude').map((h) =
264
269
  * single boolean was wrong both ways: `false` shipped the §4 Skills table on top of a
265
270
  * catalogue Bob already had (~1.7k tokens twice), `true` would have stripped the §3 Agents
266
271
  * table that is Bob's ONLY agent catalogue. Each CATALOG block in AGENT.md names its kind and
267
- * resolves against its own flag. Mirrored in
268
- * `bin/build-driver.mjs` (which cannot import this module's spawning neighbours).
272
+ * resolves against its own flag.
273
+ *
274
+ * Returns `{ skills, agents }` for a known host, `false` for an unknown one.
269
275
  */
270
- const NATIVE_CATALOG = {
271
- opencode: { skills: true, agents: true },
272
- claude: { skills: true, agents: true },
273
- bob: { skills: true, agents: false },
274
- openclaude: { skills: true, agents: true },
275
- };
276
-
277
- /** `{ skills, agents }` for a known host, `false` for an unknown one. */
278
276
  export function hostCatalogsNatively(host) {
279
- return NATIVE_CATALOG[host] || false;
277
+ return HOSTS.find((h) => h.host === host)?.catalog || false;
280
278
  }
281
279
 
282
280
  /** `_harness_learn.MEMORY_DIR_NAMES` — the neutral name and the imperial theme's. */
@@ -35,7 +35,7 @@
35
35
  import { existsSync, readdirSync } from 'node:fs';
36
36
  import path from 'node:path';
37
37
 
38
- import { CONFIG, PACK_ORDER, THEMES, discoverNames } from '../build/source.mjs';
38
+ import { CONFIG, PACK_ORDER, THEMES, discoverNames, knownSkillIds } from '../build/source.mjs';
39
39
  import { CLAUDE_STYLE, GLOBAL_MANIFEST, HOSTS, resolvePath } from './hosts.mjs';
40
40
  import { registryRoots } from '../inspect/registry.mjs';
41
41
  import { printErr, readText, isFile, isDir } from '../lib/fs.mjs';
@@ -107,8 +107,8 @@ export const defaultMode = () => configuredDefault('mode', 'direct');
107
107
  * `_build_render.theme_files` — shipped themes, `_`-prefixed scaffolds excluded.
108
108
  *
109
109
  * `dir` defaults to the checkout's own `themes/`, which is every caller but one: P2's
110
- * `syncThemes` is driven over a FIXTURE directory by the cross-implementation corpus in
111
- * `tests/test_maintainer_tools_parity.py`, because the tool it belongs to rewrites committed
110
+ * `syncThemes` is driven over a FIXTURE directory by the corpus in
111
+ * `tests/unit/maintainer_tools.test.mjs`, because the tool it belongs to rewrites committed
112
112
  * files and cannot be gated against the real ones. A parameter, not a second enumeration —
113
113
  * a scaffold mistaken for a theme is exactly what this function exists to prevent, once.
114
114
  *
@@ -162,12 +162,26 @@ function firstCarrier(d, probe, fallback = null) {
162
162
  return fallback;
163
163
  }
164
164
 
165
- /** `_harness_setup._theme_of_dir` — the marker, else the sigil in one of five carriers. */
165
+ /**
166
+ * A marker value that can only name a file directly in the themes dir: no separator, no `..`,
167
+ * and not a `_`-prefixed scaffold.
168
+ */
169
+ const THEME_NAME_RE = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
170
+
171
+ /**
172
+ * `_harness_setup._theme_of_dir` — the marker, else the sigil in one of five carriers.
173
+ *
174
+ * The marker's value becomes `<themes>/<name>.json` in `loadTheme`, so a path in it
175
+ * (`../harness.config`) loaded any `.json` as a theme. A value that is not a plain name falls
176
+ * through to the sigil scan, as a missing marker does. A plain name that is not shipped is
177
+ * still RETURNED: `loadTheme` then refuses it loudly, which `status`/`rebuild-all`/`migrate`
178
+ * cells pin ("unknown theme 'nosuchtheme'"), rather than a typo going unnoticed.
179
+ */
166
180
  export function themeOfDir(d) {
167
181
  const marker = path.join(d, '.geneseed-theme');
168
182
  if (isFile(marker)) {
169
183
  const name = (readMaybe(marker) ?? '').trim();
170
- if (name) return name;
184
+ if (THEME_NAME_RE.test(name)) return name;
171
185
  }
172
186
  return firstCarrier(d, (carrierPath) => themeFromAgent(carrierPath) || undefined);
173
187
  }
@@ -210,7 +224,7 @@ export function footprintOfDir(d) {
210
224
  * the string, so a posture file named `Foreman` renders `**Foreman**` and one named `FOREMAN`
211
225
  * would be scanned for as `**Foreman**` by both implementations only if this reproduces the
212
226
  * lowercasing. Every shipped name is already lowercase, which is exactly why the difference
213
- * would go unnoticed — the corpus in `tests/test_pure_function_parity.py` is what covers it.
227
+ * would go unnoticed — the former Python corpus covered it, and no test drives it now.
214
228
  */
215
229
  export function capitalize(s) {
216
230
  return s.length ? s[0].toUpperCase() + s.slice(1).toLowerCase() : s;
@@ -239,10 +253,15 @@ export const modeOfDir = (d) => leadOfDir(d, discoverNames('modes', 'direct'));
239
253
  * `Default trust preset: **<Label>**` line, and this scans the places an emit lands it: the
240
254
  * native layer (`skills/loop/SKILL.md`, in the root itself for a global install and under the
241
255
  * host's `projectMarker` for a project one) and the plain bundle (`skills/loop.md`).
256
+ *
257
+ * `host` narrows the project dirs to that host's own: in a repo carrying `.opencode/` AND
258
+ * `.claude/`, the Claude row otherwise read OpenCode's preset, since OpenCode comes first in
259
+ * `HOSTS`. Without it every host's dir is tried, in `HOSTS` order — the caller that has no host.
242
260
  */
243
261
  const TRUST_RE = /^Default trust preset: \*\*(Prudent|Balanced|Aggressive)\*\*/m;
244
- export function trustOfDir(d) {
245
- for (const base of ['', ...HOSTS.map((h) => h.projectMarker)]) {
262
+ export function trustOfDir(d, host = null) {
263
+ const rows = host === null ? HOSTS : HOSTS.filter((h) => h.host === host);
264
+ for (const base of ['', ...rows.map((h) => h.projectMarker)]) {
246
265
  for (const rel of [['skills', 'loop', 'SKILL.md'], ['skills', 'loop.md']]) {
247
266
  const m = TRUST_RE.exec(readMaybe(path.join(d, base, ...rel)) ?? '');
248
267
  if (m) return m[1].toLowerCase();
@@ -389,6 +408,28 @@ export function excludedRulesOfDir(d) {
389
408
  }, []);
390
409
  }
391
410
 
411
+ /** `Excluded skills: bruno-test-writer, daydream` — written only when something is excluded. */
412
+ const EXCLUDED_SKILLS_RE = /^Excluded skills:[ \t]*(.+?)[ \t]*$/m;
413
+
414
+ /**
415
+ * The skills a DEPLOYED install left out, read back so `upgrade`, `rebuild-all` and `diff`
416
+ * re-render the same set. Same semantics as `excludedRulesOfDir`: a missing line is `[]`
417
+ * (nothing excluded), and a name this checkout does not ship condemns the whole line to `[]`
418
+ * — re-admitting a skill is the safe direction, and the flag would refuse the name anyway.
419
+ */
420
+ export function excludedSkillsOfDir(d) {
421
+ return firstCarrier(d, (carrierPath) => {
422
+ const text = readMaybe(carrierPath);
423
+ if (text === null) return undefined;
424
+ const m = EXCLUDED_SKILLS_RE.exec(text);
425
+ if (!m) return undefined;
426
+ const names = m[1].split(',').map((s) => s.trim()).filter(Boolean);
427
+ const known = knownSkillIds();
428
+ if (!names.every((n) => known.includes(n))) return [];
429
+ return [...new Set(names)].sort();
430
+ }, []);
431
+ }
432
+
392
433
  // ---- what host a deployed dir belongs to (`_harness_mcp`) ---------------------------------
393
434
 
394
435
  /** `_harness_mcp._claude_read_manifest`. */
@@ -406,13 +447,13 @@ export function manifestIsClaude(cfgDir) {
406
447
  return isDict(claudeReadManifest(cfgDir).managed);
407
448
  }
408
449
 
409
- /** `_harness_mcp._EMIT_HOST_SCOPE` — a marker's emit name fixes (host, scope). */
410
- export const EMIT_HOST_SCOPE = new Map([
411
- ['opencode', ['opencode', 'project']], ['opencode-global', ['opencode', 'global']],
412
- ['claude', ['claude', 'project']], ['claude-global', ['claude', 'global']],
413
- ['bob', ['bob', 'project']], ['bob-global', ['bob', 'global']],
414
- ['openclaude', ['openclaude', 'project']], ['openclaude-global', ['openclaude', 'global']],
415
- ]);
450
+ /**
451
+ * `_harness_mcp._EMIT_HOST_SCOPE` — a marker's emit name fixes (host, scope). Derived from
452
+ * `HOSTS`, whose emit names are `<host>` and `<host>-global`, so a new host is one row there.
453
+ */
454
+ export const EMIT_HOST_SCOPE = new Map(HOSTS.flatMap(({ host }) => [
455
+ [host, [host, 'project']], [`${host}-global`, [host, 'global']],
456
+ ]));
416
457
 
417
458
  /** `_harness_mcp._emit_host_scope_of` — `root`'s own marker, resolved, or null. */
418
459
  export function emitHostScopeOf(root) {
@@ -535,7 +576,7 @@ export function installTargets() {
535
576
  export function installedDefaults() {
536
577
  const found = {
537
578
  theme: null, posture: null, mode: null, emit: null, footprint: null, doctrines: null,
538
- excludeRules: null,
579
+ excludeRules: null, excludeSkills: null,
539
580
  };
540
581
  const candidates = [];
541
582
  for (const { host, configDir } of HOSTS) {
@@ -577,6 +618,7 @@ export function installedDefaults() {
577
618
  // pre-selects. The cost of that choice is that "excludes nothing" and "no carrier" are
578
619
  // indistinguishable here, which is exactly what the marker itself already says.
579
620
  if (!found.excludeRules?.length) found.excludeRules = excludedRulesOfDir(base);
621
+ if (!found.excludeSkills?.length) found.excludeSkills = excludedSkillsOfDir(base);
580
622
  }
581
623
  return found;
582
624
  }
package/js/hosts/link.mjs CHANGED
@@ -57,8 +57,8 @@
57
57
  * never needs to:
58
58
  *
59
59
  * * `winUserPathScript` is PURE — the escaping, the split and the idempotence live there
60
- * and `tests/test_win_user_path.py` runs it over a corpus (apostrophes, trailing
61
- * separators, UNC roots) against the Python twin, byte for byte.
60
+ * and `tests/unit/win_user_path.test.mjs` runs it over a corpus of hazards (apostrophes,
61
+ * typographic quotes, trailing separators, UNC roots) and asserts each property absolutely.
62
62
  * * `cmdLink` SHORT-CIRCUITS when the bin dir is already on `PATH`, so a cell that seeds
63
63
  * `PATH` with its own sandboxed bin dir exercises the whole verb and never spawns.
64
64
  * * `cmdUnlink` has no such short-circuit, so its cells seed a `PATH` with no `powershell`
@@ -81,9 +81,11 @@ import os from 'node:os';
81
81
  import { ROOT } from '../build/source.mjs';
82
82
  import { readMaybe } from './installs.mjs';
83
83
  import { printOut, printErr, writeText } from '../lib/fs.mjs';
84
- import { toPlatformPath } from '../lib/paths.mjs';
84
+ import { toPlatformPath, which } from '../lib/paths.mjs';
85
85
 
86
86
  const IS_WIN = process.platform === 'win32';
87
+ /** What `cmdUnlink` recognises a written Unix launcher by — see `isOurLauncher`. */
88
+ const SHIM_MARKER = 'GENESEED_LINK_SHIM';
87
89
 
88
90
  /** `_harness_lifecycle._win_bin_dir`. */
89
91
  function winBinDir() {
@@ -97,12 +99,18 @@ function winBinDir() {
97
99
  * `_harness_lifecycle._win_user_path_script` — the PowerShell one-liner, built but not run.
98
100
  *
99
101
  * Every quoting hazard in this verb is in this string, which is why it is a separate
100
- * function on both sides: `''` is PowerShell's single-quote escape, the `;` split drops
102
+ * function: `''` is PowerShell's single-quote escape, the `;` split drops
101
103
  * empty segments so a trailing separator cannot append an empty entry, and `-notcontains`
102
104
  * is what makes `link` idempotent.
105
+ *
106
+ * THE ESCAPE COVERS FIVE CHARACTERS, NOT ONE. PowerShell also reads the typographic quotes
107
+ * U+2018–U+201B as single quotes, so one of them left bare in a directory name closes the
108
+ * string exactly as `'` does and turns the rest of the path into code. Each is doubled with
109
+ * ITSELF — `‘‘` is the escape for `‘` — which is what PowerShell's own `CodeGeneration.
110
+ * EscapeSingleQuotedStringContent` does.
103
111
  */
104
112
  export function winUserPathScript(action, directory) {
105
- const d = directory.replaceAll("'", "''"); // PS single-quote escape (O'Brien)
113
+ const d = directory.replace(/['‘-‛]/g, '$&$&'); // PS single-quote escape (O'Brien)
106
114
  if (action === 'add') {
107
115
  return `$d='${d}';`
108
116
  + "$p=[Environment]::GetEnvironmentVariable('Path','User');"
@@ -134,13 +142,56 @@ export function winUserPathScript(action, directory) {
134
142
  * false rather than crashing the verb.
135
143
  */
136
144
  function winUserPath(action, directory) {
137
- const r = spawnSync('powershell',
145
+ // `which`, never a bare name: Windows resolves a bare name against the cwd first, and
146
+ // `which` never searches the cwd implicitly (see its docblock).
147
+ const ps = which('powershell');
148
+ if (!ps) return false;
149
+ const r = spawnSync(ps,
138
150
  ['-NoProfile', '-Command', winUserPathScript(action, directory)],
139
151
  { stdio: 'inherit', windowsHide: true });
140
152
  if (r.error) return false;
141
153
  return r.status === 0;
142
154
  }
143
155
 
156
+ /**
157
+ * Is `dir` one of the ENTRIES of a Windows PATH string?
158
+ *
159
+ * Entry-wise, not a substring test: `…\Geneseed\bin` is a substring of `…\Geneseed\bin2` and of
160
+ * `…\Geneseed\bin\old`, and a substring hit skipped the registry write while the shim's own dir
161
+ * stayed off PATH. Trailing separators and case are both noise on Windows.
162
+ */
163
+ export function winPathHas(pathEnv, dir) {
164
+ const norm = (s) => s.replace(/[\\/]+$/, '').toLowerCase();
165
+ const want = norm(dir);
166
+ return pathEnv.split(';').some((e) => e && norm(e) === want);
167
+ }
168
+
169
+ /**
170
+ * The Unix launcher's text. Single-quoted, never double: inside `"…"` the shell still expands
171
+ * `$`, backticks and `\`, so an install path holding any of them ran as code each time
172
+ * `geneseed` started. `'\''` is the one escape single quotes need.
173
+ */
174
+ export function unixShimText(exe, entry) {
175
+ const q = (s) => `'${s.replaceAll("'", "'\\''")}'`;
176
+ return `#!/bin/sh\n# ${SHIM_MARKER}\nexec ${q(exe)} ${q(entry)} "$@"\n`;
177
+ }
178
+
179
+ /**
180
+ * Is the file at `f` a launcher `geneseed link` made? Two shapes exist on disk. (a) A symlink,
181
+ * judged by `os.readlink(f)` raw, then `.name` — NOT a resolved path: the question is whether
182
+ * the link's own target BASENAME is `geneseed`, so a symlink pointing at some other program
183
+ * that happens to sit in a `geneseed` directory is left alone. That is every install made
184
+ * before the shim. (b) A regular file carrying the marker — never "any regular file called
185
+ * geneseed", which would be npm's own bin link or a stranger's program.
186
+ *
187
+ * ONE OWNER FOR BOTH VERBS. `unlink` always refused what is not ours; `link` used to delete
188
+ * whatever sat at its destination before writing, so the two disagreed about the same file.
189
+ */
190
+ function isOurLauncher(f) {
191
+ if (isSymlink(f)) return path.basename(readlinkSync(f)) === 'geneseed';
192
+ return existsSync(f) && (readMaybe(f) ?? '').includes(SHIM_MARKER);
193
+ }
194
+
144
195
  /** `_harness_lifecycle.cmd_link` — put `geneseed` on PATH so it runs from any directory. */
145
196
  export function cmdLink(args) {
146
197
  const here = ROOT;
@@ -159,8 +210,7 @@ export function cmdLink(args) {
159
210
  return 1;
160
211
  }
161
212
  printOut(`geneseed: wrote shim ${shim}\n`);
162
- const on_path = (process.env.PATH || '').toLowerCase().includes(bindir.toLowerCase());
163
- if (on_path || winUserPath('add', bindir)) {
213
+ if (winPathHas(process.env.PATH || '', bindir) || winUserPath('add', bindir)) {
164
214
  printOut(`geneseed: '${bindir}' is on your user PATH — open a NEW terminal, then run \`geneseed\`.\n`);
165
215
  } else {
166
216
  printOut(`geneseed: add '${bindir}' to your PATH manually, then run \`geneseed\` from anywhere.\n`);
@@ -174,8 +224,8 @@ export function cmdLink(args) {
174
224
  // PATH=` line) as well as comparing it against `PATH.split(os.pathsep)`, so an argument
175
225
  // that is not already normalised diverges in three places at once. A trailing slash is the
176
226
  // cheapest one: `str(Path('/x/bin/'))` is `/x/bin` and the raw string is not.
177
- // `harness_golden`'s `link/an-explicit-dir-argument-is-used-instead-of-the-default` passes
178
- // one, and it is the cell that found this.
227
+ // The retired cell `link/an-explicit-dir-argument-is-used-instead-of-the-default` passed
228
+ // one, and it is what found this.
179
229
  let targetDir = args.dir ? toPlatformPath(args.dir) : null;
180
230
  if (targetDir === null) {
181
231
  const local = path.join(os.homedir(), '.local', 'bin');
@@ -191,16 +241,23 @@ export function cmdLink(args) {
191
241
  try {
192
242
  mkdirSync(targetDir, { recursive: true });
193
243
  // `dest.is_symlink() or dest.exists()` — the first half is what catches a BROKEN
194
- // symlink, which `existsSync` follows and reports absent.
195
- if (isSymlink(dest) || existsSync(dest)) rmSync(dest, { force: true });
244
+ // symlink, which `existsSync` follows and reports absent. Only OUR launcher is replaced:
245
+ // anything else there — npm's own bin link, a stranger's program — is refused, the same
246
+ // judgement `cmdUnlink` makes about the same file.
247
+ if (isSymlink(dest) || existsSync(dest)) {
248
+ if (!isOurLauncher(dest)) {
249
+ printErr(`geneseed: ${dest} exists and is not a launcher geneseed wrote — leaving it `
250
+ + 'alone. Remove it yourself, or pick another dir: geneseed link <dir>\n');
251
+ return 1;
252
+ }
253
+ rmSync(dest, { force: true });
254
+ }
196
255
  // A WRITTEN SHIM, not a symlink to `ROOT/geneseed`. The bash launcher execs a Python
197
256
  // interpreter, so symlinking it puts Python on PATH from the Node verb. The Windows
198
- // arm above has always written a shim; this is the same shape. `GENESEED_LINK_SHIM`
199
- // is the marker `cmdUnlink` recognises — without it, unlink cannot tell our file from
257
+ // arm above has always written a shim; this is the same shape. `SHIM_MARKER`
258
+ // is what `cmdUnlink` recognises — without it, unlink cannot tell our file from
200
259
  // a stranger's and would have to refuse every regular file, which is a no-op.
201
- writeText(dest, '#!/bin/sh\n'
202
- + '# GENESEED_LINK_SHIM\n'
203
- + `exec "${process.execPath}" "${entry}" "$@"\n`);
260
+ writeText(dest, unixShimText(process.execPath, entry));
204
261
  chmodSync(dest, 0o755);
205
262
  } catch (e) {
206
263
  printErr(`geneseed: could not write ${dest} (${asOsError(e)}) — pick a writable dir: `
@@ -246,15 +303,7 @@ export function cmdUnlink() {
246
303
  if (seen.has(d)) continue;
247
304
  seen.add(d);
248
305
  const f = path.join(d, 'geneseed');
249
- // TWO shapes, because two shapes exist on disk. (a) `os.readlink(f)` raw, then `.name`
250
- // — NOT a resolved path: the reference asks whether the link's own target BASENAME is
251
- // `geneseed`, so a symlink pointing at some other program that happens to sit in a
252
- // `geneseed` directory is left alone. That is every install made before the shim.
253
- // (b) a regular file we wrote, identified by its marker — never "any regular file
254
- // called geneseed", which would delete a stranger's program.
255
- const ours = (isSymlink(f) && path.basename(readlinkSync(f)) === 'geneseed')
256
- || (!isSymlink(f) && existsSync(f) && (readMaybe(f) ?? '').includes('GENESEED_LINK_SHIM'));
257
- if (ours) {
306
+ if (isOurLauncher(f)) {
258
307
  try {
259
308
  rmSync(f);
260
309
  printOut(`geneseed: removed ${f}\n`);
@@ -74,18 +74,25 @@ function globMd(dir) {
74
74
  && isFile(path.join(dir, n)));
75
75
  }
76
76
 
77
+ /** Stems that name the store's own files, never a fact — `MEMORY` is the index itself. */
78
+ const RESERVED_STEMS = new Set(['memory', 'readme']);
79
+
77
80
  /** `_existing_slugs` — slugs already stored, so learn never re-emits a known fact. */
78
81
  export function existingSlugs(memDir) {
79
- const skip = new Set(['memory', 'readme']);
80
- return new Set(globMd(memDir).map(stem).filter((s) => !skip.has(s.toLowerCase())));
82
+ return new Set(globMd(memDir).map(stem).filter((s) => !RESERVED_STEMS.has(s.toLowerCase())));
81
83
  }
82
84
 
83
85
  /**
84
86
  * `_write_memories` — split the model output into files, write each NEW one, and append a
85
87
  * pointer line to MEMORY.md. `existing` is MUTATED, so a reply carrying the same slug
86
88
  * twice writes it once.
89
+ *
90
+ * A reserved stem is refused (`name: MEMORY` would overwrite the index), and names compare
91
+ * LOWERCASE: on Windows and macOS `User-Prefs.md` and `user-prefs.md` are one file, so a
92
+ * case variant of a stored slug would overwrite it.
87
93
  */
88
94
  export function writeMemories(modelOutput, memDir, existing) {
95
+ const taken = new Set([...existing].map((s) => s.toLowerCase()));
89
96
  const written = [];
90
97
  const indexLines = [];
91
98
  for (let chunk of modelOutput.split(FILE_SEP_RE)) {
@@ -93,9 +100,11 @@ export function writeMemories(modelOutput, memDir, existing) {
93
100
  if (!chunk || chunk.toUpperCase() === 'NOTHING') continue;
94
101
  const [fm] = frontmatter(chunk);
95
102
  const name = fmGet(fm, 'name').trim();
96
- if (!MEMORY_SLUG_RE.test(name) || existing.has(name)) continue;
103
+ const key = name.toLowerCase();
104
+ if (!MEMORY_SLUG_RE.test(name) || RESERVED_STEMS.has(key) || taken.has(key)) continue;
97
105
  writeText(path.join(memDir, `${name}.md`), `${chunk.replace(/\n+$/, '')}\n`);
98
106
  existing.add(name);
107
+ taken.add(key);
99
108
  written.push(name);
100
109
  const desc = fmGet(fm, 'description').trim();
101
110
  indexLines.push(`- [${name}](${name}.md)${desc ? ` \u2014 ${desc}` : ''}`);
@@ -147,7 +156,7 @@ export function memoryDropIndex(memDir, name) {
147
156
  * the user's to keep).
148
157
  */
149
158
  export function consolidateMemory(memDir) {
150
- const skip = new Set(['memory', 'readme']);
159
+ const skip = RESERVED_STEMS;
151
160
  const facts = new Map();
152
161
  for (const name of sortPaths(globMd(memDir))) {
153
162
  const s = stem(name);