geneseed 5.1.0 → 5.2.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 (67) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/SHIPPED.md +2 -2
  3. package/adapters/opencode/README.md +4 -3
  4. package/adapters/opencode/plugins/geneseed-context.js +26 -19
  5. package/adapters/opencode/plugins/geneseed-guard.js +112 -7
  6. package/bin/geneseed-cli.mjs +3 -0
  7. package/docs/concepts/exclusions.md +1 -1
  8. package/docs/concepts/host-matrix.md +1 -1
  9. package/docs/guides/setup-doctrines.md +1 -1
  10. package/docs/understand/enforced-vs-asked.md +1 -1
  11. package/harness.config.json +1 -1
  12. package/js/README.md +7 -5
  13. package/js/build/args.mjs +7 -1
  14. package/js/build/bundle.mjs +122 -23
  15. package/js/build/driver.mjs +32 -12
  16. package/js/build/emit-claude.mjs +2 -1
  17. package/js/build/emit-common.mjs +2 -2
  18. package/js/build/emit-opencode.mjs +22 -10
  19. package/js/build/export.mjs +431 -0
  20. package/js/build/generate.mjs +3 -0
  21. package/js/build/source.mjs +6 -1
  22. package/js/cli-table.json +102 -2
  23. package/js/hosts/hooks-done.mjs +8 -2
  24. package/js/hosts/hooks.mjs +105 -4
  25. package/js/hosts/hosts.mjs +2 -4
  26. package/js/hosts/installs.mjs +28 -0
  27. package/js/hosts/loss.mjs +19 -2
  28. package/js/hosts/memory-files.mjs +3 -0
  29. package/js/hosts/native.mjs +30 -2
  30. package/js/hosts/owned.mjs +55 -1
  31. package/js/hosts/ownership-gate.mjs +5 -5
  32. package/js/hosts/settings.mjs +83 -33
  33. package/js/lib/managed-block.mjs +74 -0
  34. package/js/maintain/memory.mjs +27 -2
  35. package/js/maintain/uninstall.mjs +57 -14
  36. package/js/web/actions.mjs +3 -0
  37. package/js/web/api.mjs +4 -1
  38. package/package.json +1 -1
  39. package/src/agents/memory-curator.md +4 -4
  40. package/src/memory/README.md +1 -1
  41. package/src/skills/geneseed.md +1 -1
  42. package/src/skills/rule/consolidate.md +1 -1
  43. package/src/skills/rule.md +1 -1
  44. package/web/dist/assets/{Activity-CpkBwpu7.js → Activity-DlQ30znB.js} +1 -1
  45. package/web/dist/assets/{ActivityDetail-DTPziZWM.js → ActivityDetail-CG0mn5fW.js} +1 -1
  46. package/web/dist/assets/{Bonsai-hiG_gGNU.js → Bonsai-DSwUbavu.js} +1 -1
  47. package/web/dist/assets/{CopyButton-DUIUfNp6.js → CopyButton-BzRQz7k2.js} +1 -1
  48. package/web/dist/assets/{Dashboard-Dnw6EyX7.js → Dashboard-Ce3UOsxJ.js} +2 -2
  49. package/web/dist/assets/{Docs-BEET_l16.js → Docs-CisVnYqv.js} +1 -1
  50. package/web/dist/assets/{Factories-D6KXkfWw.js → Factories-Dq5oW4CU.js} +1 -1
  51. package/web/dist/assets/{GreenhouseView-BKxy5apE.js → GreenhouseView-y9WAfcc_.js} +1 -1
  52. package/web/dist/assets/Installs-m4GElwFW.js +3 -0
  53. package/web/dist/assets/{JournalView-ChFitHjo.js → JournalView-DeBLRNGc.js} +1 -1
  54. package/web/dist/assets/{Kits-CcR-OlwQ.js → Kits-DJYVAnyE.js} +1 -1
  55. package/web/dist/assets/{Laws-B1s5idOg.js → Laws-CNpc_8ZV.js} +1 -1
  56. package/web/dist/assets/{LibRows-BZgdbI1l.js → LibRows-RO5bvXth.js} +1 -1
  57. package/web/dist/assets/{Library-x6TkkEVF.js → Library-Dg0ScciC.js} +1 -1
  58. package/web/dist/assets/{Loops-BH93KKxn.js → Loops-CjEdo-NG.js} +1 -1
  59. package/web/dist/assets/{OperatorHudView-BO0aIKPL.js → OperatorHudView-2ujVMjq1.js} +1 -1
  60. package/web/dist/assets/{Personal-CE_0Vhh0.js → Personal-D0yS7ahT.js} +1 -1
  61. package/web/dist/assets/{Settings-CbpZvVN_.js → Settings-DEN0U8QI.js} +1 -1
  62. package/web/dist/assets/{Tabs-C2oW7oEj.js → Tabs-But5R6_r.js} +1 -1
  63. package/web/dist/assets/{index-BQwOmbor.js → index-Ck42AbRX.js} +2 -2
  64. package/web/dist/assets/{index-CuIop_pO.css → index-PG_ukkh6.css} +1 -1
  65. package/web/dist/index.html +2 -2
  66. package/adapters/claude-code/skills/geneseed/SKILL.md +0 -76
  67. package/web/dist/assets/Installs-CnFVlVD0.js +0 -3
@@ -12,8 +12,9 @@
12
12
  */
13
13
  import path from 'node:path';
14
14
  import { VERSION_MARKER } from '../hosts/hosts.mjs';
15
+ import { BUNDLE_FILES_KEY, bundleFiles, ownedWithin } from '../hosts/owned.mjs';
15
16
  import { migrateMemoryIndex } from '../hosts/memory-files.mjs';
16
- import { copyFile, isDir, isFile, readText, writeText } from '../lib/fs.mjs';
17
+ import { copyFile, isFile, readText, writeText } from '../lib/fs.mjs';
17
18
  import { jsonDumpsIndent, parseJson, formatReprAscii, isTruthy } from '../lib/json.mjs';
18
19
  import { OWNED_SRC_DIRS, SRC_DIRS_MARKER, TMPL_SPEC_RE } from './emit-common.mjs';
19
20
  import { SRC_DIR_TOKENS, renderAll } from './render.mjs';
@@ -21,8 +22,12 @@ import {
21
22
  ensureBundleGitignore, ensureContextStub, ensureMemoryIndex, ensureNotebookIndex,
22
23
  ensureProfileStub, ensureRulesStub, ensureWikiStub,
23
24
  } from './stubs.mjs';
25
+ import { retiredSkillNames, skillLabels } from './retired-skills.mjs';
26
+ import { skillAliases } from './source.mjs';
24
27
  import { writeVersion } from './version.mjs';
25
- import { existsSync, mkdirSync, renameSync, rmSync } from 'node:fs';
28
+ import {
29
+ existsSync, mkdirSync, readdirSync, renameSync, rmdirSync, unlinkSync,
30
+ } from 'node:fs';
26
31
 
27
32
  /**
28
33
  * Seed the memory index, then move a flat one to topics — the pair every emit runs on its
@@ -94,13 +99,53 @@ function readPriorSrcDirs(out) {
94
99
  return data && typeof data === 'object' && !Array.isArray(data) ? data : {};
95
100
  }
96
101
 
97
- /** `_build_render._write_src_dirs_marker` — temp + replace. */
98
- function writeSrcDirsMarker(out, resolved) {
102
+ /**
103
+ * `_build_render._write_src_dirs_marker` — temp + replace. `files` rides in the same marker:
104
+ * every rel this build wrote, the stores apart (see `build`).
105
+ */
106
+ function writeSrcDirsMarker(out, resolved, files, extra = {}) {
99
107
  const tmp = path.join(out, `${SRC_DIRS_MARKER}.tmp`);
100
- writeText(tmp, `${jsonDumpsIndent(resolved)}\n`);
108
+ writeText(tmp, `${jsonDumpsIndent({ ...resolved, [BUNDLE_FILES_KEY]: files, ...extra })}\n`);
101
109
  renameSync(tmp, path.join(out, SRC_DIRS_MARKER));
102
110
  }
103
111
 
112
+ /**
113
+ * The retired skills still lying in a bundle's skills dir that no record owns: `<name>.md`
114
+ * where the name is one Geneseed shipped and no longer does, and the file carries the render's
115
+ * `# <Skill label>: <id>` heading outside a code fence, the flat twin of `isRendered`
116
+ * (`./retired-skills.mjs`). A retired name is a plain word, so a file under one may be the
117
+ * user's own; the heading is what tells them apart.
118
+ *
119
+ * This is the leftover of a bundle an older build rendered, which kept no file list: the build
120
+ * that starts the list cannot know what its predecessor wrote, so it leaves such a file, names
121
+ * it, and records it as `stale`. `--force` removes it.
122
+ */
123
+ function staleRetired(out, skillsDirname, shipped, mine, aliases) {
124
+ const labels = skillLabels();
125
+ const found = [];
126
+ for (const name of retiredSkillNames({ aliases })) {
127
+ const rel = `${skillsDirname}/${name}.md`;
128
+ if (shipped.has(rel) || mine?.has(rel)) continue;
129
+ let text;
130
+ try { text = readText(path.join(out, rel)); } catch { continue; }
131
+ const ids = new Set([name, aliases.get(name)].filter(Boolean));
132
+ let fenced = false;
133
+ for (const line of text.split('\n')) {
134
+ if (/^\s*(```|~~~)/.test(line)) { fenced = !fenced; continue; }
135
+ const h = fenced ? null : /^# (.+?): (\S+)\s*$/.exec(line);
136
+ if (h && labels.has(h[1]) && ids.has(h[2])) { found.push(rel); break; }
137
+ }
138
+ }
139
+ return found;
140
+ }
141
+
142
+ /** Remove now-empty directories from `dir` up to, never including, `out`. */
143
+ function pruneEmptyDirs(dir, out) {
144
+ for (let d = dir; d !== out && d.startsWith(out + path.sep); d = path.dirname(d)) {
145
+ try { if (readdirSync(d).length) return; rmdirSync(d); } catch { return; }
146
+ }
147
+ }
148
+
104
149
  /**
105
150
  * The guard on the prune of a RENAMED owned dir — `build`'s one destructive path driven
106
151
  * by file content rather than by code.
@@ -171,16 +216,19 @@ export function build(cfg, themeName, out, { footprint = 'full', nativeCatalog =
171
216
  assertSourceComplete(cfg, `theme '${themeName}'`);
172
217
  mkdirSync(out, { recursive: true });
173
218
 
174
- // Wipe the owned dirs ONLY inside an established bundle: a first render into an
175
- // arbitrary repo (`--out .`) must never delete an agents/ or skills/ the USER owns.
219
+ // Ownership is per file — `bundleFiles` says why. `mine` is what the previous build wrote
220
+ // here, or null when there is no record (a first render, or an older build's bundle).
176
221
  const isBundle = isFile(path.join(out, '.geneseed-theme')) || isFile(path.join(out, VERSION_MARKER));
177
222
  const priorSrcDirs = isBundle ? readPriorSrcDirs(out) : {};
223
+ const prior = isBundle ? bundleFiles(out) : null;
224
+ const mine = prior && new Set(prior);
178
225
  const resolvedSrcDirs = {};
226
+ const ownedNames = new Set();
179
227
  for (const srcDir of OWNED_SRC_DIRS) {
180
228
  // `??` falls back on an explicit JSON null too. No theme has one.
181
229
  const dirname = theme[SRC_DIR_TOKENS[srcDir]] ?? srcDir;
182
230
  resolvedSrcDirs[srcDir] = dirname;
183
- const managed = path.join(out, dirname);
231
+ ownedNames.add(dirname);
184
232
 
185
233
  // `isTruthy`, not `priorName &&`: the marker is user-editable JSON, and an
186
234
  // empty `[]`, `{}` or `0` must count as absent although JS's `&&` treats the first two
@@ -188,44 +236,95 @@ export function build(cfg, themeName, out, { footprint = 'full', nativeCatalog =
188
236
  // only from a hand-edited file, which is the one place nobody would look for it.
189
237
  const priorName = priorSrcDirs[srcDir];
190
238
  if (isBundle && isTruthy(priorName) && priorName !== dirname) {
191
- if (safePriorDirName(out, priorName)) {
192
- const stale = path.join(out, priorName);
193
- if (isDir(stale)) rmSync(stale, { recursive: true, force: true });
194
- } else {
239
+ // A theme renamed the dir: the old name's recorded files go in the prune below.
240
+ if (safePriorDirName(out, priorName)) ownedNames.add(priorName);
241
+ else {
195
242
  process.stderr.write('[geneseed] WARN: ignoring suspicious prior dir name '
196
243
  + `${formatReprAscii(priorName)} recorded in ${SRC_DIRS_MARKER} - not pruned.\n`);
197
244
  }
198
245
  }
246
+ }
199
247
 
200
- if (!isDir(managed)) continue;
201
- if (isBundle) {
202
- rmSync(managed, { recursive: true, force: true });
203
- } else {
204
- // STDOUT, and ASCII-only: this print crashed with UnicodeEncodeError on a cp1252
205
- // Windows console when it carried a warning-sign emoji.
206
- process.stdout.write(`[geneseed] WARN: ${managed} already exists and ${out} is not a `
207
- + 'Geneseed bundle — keeping it; rendered files merge into it.\n');
248
+ // The prune: a recorded file under an owned dir that this render no longer ships. Before the
249
+ // writes, as the whole-dir wipe it replaces was, so a rel that changed only in case is not
250
+ // deleted after being written on a case-insensitive disk. `ownedWithin` contains the rels:
251
+ // the marker is a file a user can edit.
252
+ const shipped = new Set(items.map(({ rel }) => rel));
253
+ for (const rel of ownedWithin(out, (prior ?? []).filter((r) => !shipped.has(r)))) {
254
+ if (!ownedNames.has(rel.split('/')[0])) continue;
255
+ const victim = path.join(out, rel);
256
+ try {
257
+ if (isFile(victim)) { unlinkSync(victim); pruneEmptyDirs(path.dirname(victim), out); }
258
+ } catch (e) {
259
+ process.stderr.write(`[geneseed] WARN: could not remove stale ${rel} (${e.message})\n`);
208
260
  }
209
261
  }
210
262
 
211
263
  const nbDirname = theme[SRC_DIR_TOKENS.notebook] ?? 'notebook';
264
+ const memDirname = theme[SRC_DIR_TOKENS.memory] ?? 'memory';
265
+ const written = [];
266
+ const yours = [];
267
+ const replaced = [];
268
+ const force = cfg.force === true;
212
269
  for (const { rel, text, src } of items) {
213
270
  const dest = path.join(out, rel);
214
- mkdirSync(path.dirname(dest), { recursive: true });
215
271
  // The notebook is the agent's sovereign space: seeded files are written once and
216
272
  // never re-emitted, so the agent may rewrite its own rules. Only `.gitignore` is
217
273
  // re-asserted — the one law it cannot lift.
218
274
  const parts = rel.split('/');
219
- if (parts[0] === nbDirname && path.basename(rel) !== '.gitignore' && existsSync(dest)) {
275
+ const there = existsSync(dest);
276
+ if (parts[0] === nbDirname && path.basename(rel) !== '.gitignore' && there) {
220
277
  continue;
221
278
  }
279
+ // The two stores stand outside the claim and the record: their seeds are rewritten as
280
+ // before, and nothing in them is ever removed, by a build or by an uninstall.
281
+ const store = parts[0] === nbDirname || parts[0] === memDirname;
282
+ // Claim-on-create. With a record, only a recorded file is overwritten. Without one, an
283
+ // older build's bundle is overwritten as that build did, and in a folder that is no
284
+ // bundle at all an existing file is the user's.
285
+ // `--force` takes Geneseed's copy instead, and says which files it replaced.
286
+ if (there && !store && !(mine ? mine.has(rel) : isBundle)) {
287
+ if (!force) { yours.push(rel); continue; }
288
+ replaced.push(rel);
289
+ }
290
+ mkdirSync(path.dirname(dest), { recursive: true });
222
291
  if (text !== null) writeText(dest, text);
223
292
  else copyFile(src, dest);
293
+ if (!store) written.push(rel);
294
+ }
295
+ const shown = (rels) => rels.slice(0, 5).join(', ') + (rels.length > 5 ? `, and ${rels.length - 5} more` : '');
296
+ if (replaced.length) {
297
+ process.stdout.write(`[geneseed] --force: replaced ${replaced.length} existing file(s) in ${out}: `
298
+ + `${shown(replaced)}.\n`);
299
+ }
300
+ let stale = staleRetired(out, resolvedSrcDirs.skills, shipped, mine, skillAliases(cfg.src));
301
+ if (stale.length && force) {
302
+ for (const rel of ownedWithin(out, stale)) {
303
+ try { unlinkSync(path.join(out, rel)); } catch { /* still there: named again next build */ }
304
+ }
305
+ process.stdout.write(`[geneseed] --force: removed ${stale.length} retired file(s) an older build `
306
+ + `left in ${out}: ${shown(stale)}.\n`);
307
+ stale = stale.filter((rel) => existsSync(path.join(out, rel)));
308
+ } else if (stale.length) {
309
+ process.stdout.write(`[geneseed] WARN: ${stale.length} file(s) in ${out} are skills an older build `
310
+ + `shipped and this one retired: ${shown(stale)}. They were left in place; rebuild with `
311
+ + '--force to remove them.\n');
312
+ }
313
+ if (yours.length) {
314
+ // STDOUT, and ASCII-only: this print crashed with UnicodeEncodeError on a cp1252
315
+ // Windows console when it carried a warning-sign emoji.
316
+ process.stdout.write(`[geneseed] WARN: kept ${yours.length} existing file(s) Geneseed did not `
317
+ + `write in ${out}, and skipped its own copy of each: ${shown(yours)}. Move one aside and `
318
+ + 'rebuild to get Geneseed\'s copy, or rebuild with --force to replace them all.\n');
224
319
  }
225
320
 
226
321
  writeText(path.join(out, '.geneseed-theme'), `${themeName}\n`);
227
322
  writeVersion(cfg, out);
228
- writeSrcDirsMarker(out, resolvedSrcDirs);
323
+ // `kept` and `stale` only when there is one: a clean bundle's marker carries neither.
324
+ writeSrcDirsMarker(out, resolvedSrcDirs, written.sort(), {
325
+ ...(yours.length ? { kept: yours.sort() } : {}),
326
+ ...(stale.length ? { stale: stale.sort() } : {}),
327
+ });
229
328
  ensureContextStub(out);
230
329
  ensureWikiStub(out);
231
330
  ensureRulesStub(out);
@@ -51,7 +51,7 @@ import {
51
51
  openclaudeConfigDir, hostCatalogsNatively,
52
52
  } from '../hosts/hosts.mjs';
53
53
  import {
54
- hashesOf, ownedHashes, ownedState, ownedWithin, recordedDenies, recordedEdit, editRecordKeys,
54
+ hashesOf, ownedHashes, ownedState, ownedWithin, recordedDenies, recordedEdit, recordedGates, editRecordKeys,
55
55
  } from '../hosts/owned.mjs';
56
56
  import { seedProtectedChecks } from '../hosts/geneseed-dir.mjs';
57
57
 
@@ -214,8 +214,11 @@ function writeManifestAtomic(file, data) {
214
214
  * your edited... delete it to get Geneseed's copy back": two warnings about one rel that is in
215
215
  * fact still shipped. Excluded from `stale` before anything is checked or printed — silently,
216
216
  * because `claimer` already said everything there is to say about it.
217
+ *
218
+ * `force` (`--force`): an edited stale rel is removed too, and named. It was Geneseed's file and
219
+ * Geneseed no longer ships it, which is the leftover the flag exists to clear.
217
220
  */
218
- function pruneOwned(oc, oldOwned, owned, oldHashes = {}, editRefused = []) {
221
+ function pruneOwned(oc, oldOwned, owned, oldHashes = {}, editRefused = [], force = false) {
219
222
  const now = new Set(owned);
220
223
  const alreadyWarned = new Set(editRefused);
221
224
  const stale = [...new Set(oldOwned)]
@@ -223,8 +226,11 @@ function pruneOwned(oc, oldOwned, owned, oldHashes = {}, editRefused = []) {
223
226
  const failed = [];
224
227
  for (const rel of ownedWithin(oc, stale)) {
225
228
  if (ownedState(oc, rel, oldHashes) === 'modified') {
226
- process.stderr.write(`[geneseed] kept your edited ${rel} (no longer shipped)\n`);
227
- continue;
229
+ if (!force) {
230
+ process.stderr.write(`[geneseed] kept your edited ${rel} (no longer shipped)\n`);
231
+ continue;
232
+ }
233
+ process.stderr.write(`[geneseed] --force: removed your edited ${rel} (no longer shipped)\n`);
228
234
  }
229
235
  const victim = path.join(oc, rel);
230
236
  try {
@@ -246,6 +252,13 @@ function pruneOwned(oc, oldOwned, owned, oldHashes = {}, editRefused = []) {
246
252
  }
247
253
  }
248
254
 
255
+ /**
256
+ * The manifest's `kept` key: the rels this emit left to the user where it ships a file of its
257
+ * own (`claim.kept`). Written only when there is one, so a clean install's manifest is unchanged.
258
+ * `keptFilesOf` (js/hosts/installs.mjs) is the reader, for the console.
259
+ */
260
+ const keptKey = (kept) => (kept && kept.length ? { kept: [...kept].sort() } : {});
261
+
249
262
  /**
250
263
  * Whether this PROJECT emit seeds `<git root>/.geneseed/protected-checks.txt`. A real emit does;
251
264
  * a sandbox emit must not, because the seed walks UP to the git root and a sandbox under a temp
@@ -319,6 +332,7 @@ function emitOpencode(cfg, args, out) {
319
332
  const oldOwned = (doc && doc.owned) || [];
320
333
  const oldDenies = recordedDenies(doc);
321
334
  const oldEdit = recordedEdit(doc);
335
+ const oldGates = recordedGates(doc);
322
336
  const oldHashes = hashesOf(doc);
323
337
 
324
338
  const agentPathRel = relUnder(out, root);
@@ -331,14 +345,14 @@ function emitOpencode(cfg, args, out) {
331
345
  {
332
346
  theme: args.theme, out, root, footprint: args.footprint,
333
347
  nativeCatalog: hostCatalogsNatively('opencode'), oldOwned, manifestExisted, agentPath,
334
- oldDenies, oldEdit, oldHashes,
348
+ oldDenies, oldEdit, oldHashes, oldGates,
335
349
  });
336
- const { owned, stats, cfgName, skillDenies, editRecord, editRefused } = rendered;
350
+ const { owned, stats, cfgName, skillDenies, editRecord, editRefused, bashGates, kept } = rendered;
337
351
  // Seed once: absent -> created, then the user's (never recorded, rewritten or removed).
338
352
  if (seeds(args)) seedProtectedChecks(root);
339
353
 
340
354
  phaseLog('PRUNE');
341
- pruneOwned(oc, oldOwned, owned, oldHashes, editRefused);
355
+ pruneOwned(oc, oldOwned, owned, oldHashes, editRefused, cfg.force);
342
356
 
343
357
  phaseLog('MANIFEST');
344
358
  writeManifestAtomic(manifestPath, {
@@ -347,9 +361,11 @@ function emitOpencode(cfg, args, out) {
347
361
  + 'list is yours and is never touched.',
348
362
  owned: [...owned].sort(),
349
363
  hashes: ownedHashes(oc, owned),
364
+ ...keptKey(kept),
350
365
  scope: 'project',
351
366
  ...(skillDenies.length ? { skill_denies: skillDenies } : {}),
352
367
  ...editRecordKeys(editRecord),
368
+ ...(bashGates.length ? { bash_gates: bashGates } : {}),
353
369
  });
354
370
 
355
371
  const extra = extrasTail(stats);
@@ -384,6 +400,7 @@ function emitOpencodeGlobal(cfg, args, out) {
384
400
  const oldOwned = (doc && doc.owned) || [];
385
401
  const oldDenies = recordedDenies(doc);
386
402
  const oldEdit = recordedEdit(doc);
403
+ const oldGates = recordedGates(doc);
387
404
  const oldHashes = hashesOf(doc);
388
405
 
389
406
  const agentPath = path.join(cfgDir, 'AGENT.md').split(path.sep).join('/');
@@ -393,12 +410,12 @@ function emitOpencodeGlobal(cfg, args, out) {
393
410
  {
394
411
  theme: args.theme, cfgDir, out, sharedRoot: args.sharedRoot,
395
412
  footprint: args.footprint, nativeCatalog: hostCatalogsNatively('opencode'),
396
- oldOwned, agentPath, oldDenies, oldEdit, oldHashes,
413
+ oldOwned, agentPath, oldDenies, oldEdit, oldHashes, oldGates,
397
414
  });
398
- const { owned, stats, memStatus, nbStatus, cfgName, skillDenies, editRecord, editRefused } = rendered;
415
+ const { owned, stats, memStatus, nbStatus, cfgName, skillDenies, editRecord, editRefused, bashGates, kept } = rendered;
399
416
 
400
417
  phaseLog('PRUNE');
401
- pruneOwned(cfgDir, oldOwned, owned, oldHashes, editRefused);
418
+ pruneOwned(cfgDir, oldOwned, owned, oldHashes, editRefused, cfg.force);
402
419
 
403
420
  phaseLog('MANIFEST');
404
421
  writeManifestAtomic(manifestPath, {
@@ -407,8 +424,10 @@ function emitOpencodeGlobal(cfg, args, out) {
407
424
  + 'stores are NOT listed — they are never deleted.',
408
425
  owned: [...owned].sort(),
409
426
  hashes: ownedHashes(cfgDir, owned),
427
+ ...keptKey(kept),
410
428
  ...(skillDenies.length ? { skill_denies: skillDenies } : {}),
411
429
  ...editRecordKeys(editRecord),
430
+ ...(bashGates.length ? { bash_gates: bashGates } : {}),
412
431
  });
413
432
 
414
433
  const extra = extrasTail(stats);
@@ -450,12 +469,12 @@ function emitClaudeCore(cfg, args, { cfgDir, claudeMd, scope, host, out, hookOpt
450
469
  oldOwned, oldManaged, preambleExclude: preambleExclude(claudeMd, host),
451
470
  hookOpts, oldHashes,
452
471
  });
453
- const { owned, stats, memStatus, nbStatus, managed, editRefused } = rendered;
472
+ const { owned, stats, memStatus, nbStatus, managed, editRefused, kept } = rendered;
454
473
  // `root` is null on a global emit: it has no project to seed.
455
474
  if (root && seeds(args)) seedProtectedChecks(root);
456
475
 
457
476
  phaseLog('PRUNE');
458
- pruneOwned(cfgDir, oldOwned, owned, oldHashes, editRefused);
477
+ pruneOwned(cfgDir, oldOwned, owned, oldHashes, editRefused, cfg.force);
459
478
 
460
479
  phaseLog('MANIFEST');
461
480
  writeManifestAtomic(manifestPath, {
@@ -466,6 +485,7 @@ function emitClaudeCore(cfg, args, { cfgDir, claudeMd, scope, host, out, hookOpt
466
485
  + 'hooks so uninstall removes exactly those.',
467
486
  owned: [...owned].sort(),
468
487
  hashes: ownedHashes(cfgDir, owned),
488
+ ...keptKey(kept),
469
489
  managed,
470
490
  scope,
471
491
  });
@@ -127,7 +127,7 @@ export function emitClaudeRender(cfg, job) {
127
127
  // prints once across the whole emit rather than once per writer.
128
128
  // Before the claim: a retired folder freed here lets this emit write the alias that replaces it.
129
129
  if (sharedRoot !== null) pruneRetiredSkills(host, cfgDir, oldOwned);
130
- const claim = claimer(oldOwned, cfgDir, true, oldHashes);
130
+ const claim = claimer(oldOwned, cfgDir, true, oldHashes, cfg.force);
131
131
  const { nAgents, nSkills, written } = writeNativeLayer(
132
132
  items, path.join(cfgDir, 'agents'), path.join(cfgDir, 'skills'),
133
133
  loadAgentOverrides(cfgDir),
@@ -206,6 +206,7 @@ export function emitClaudeRender(cfg, job) {
206
206
  nbStatus,
207
207
  managed,
208
208
  editRefused: [...claim.editRefused],
209
+ kept: [...claim.kept],
209
210
  };
210
211
  }
211
212
 
@@ -16,8 +16,8 @@ import { relPosix } from '../lib/text.mjs';
16
16
  import { SRC_DIR_TOKENS, destRel } from './render.mjs';
17
17
  import { mkdirSync, readdirSync, cpSync } from 'node:fs';
18
18
 
19
- /** `_build_render.SRC_DIRS_MARKER`. */
20
- export const SRC_DIRS_MARKER = '.geneseed-srcdirs.json';
19
+ /** `_build_render.SRC_DIRS_MARKER` — defined beside its file-list reader, `bundleFiles`. */
20
+ export { SRC_DIRS_MARKER } from '../hosts/owned.mjs';
21
21
  /**
22
22
  * `_build_render.OWNED_SRC_DIRS` — wiped and regenerated each run.
23
23
  *
@@ -7,6 +7,7 @@
7
7
  * plainly as two files with the same shape than as two sections of one.
8
8
  */
9
9
  import path from 'node:path';
10
+ import { bundleFiles } from '../hosts/owned.mjs';
10
11
  import { VERSION_MARKER } from '../hosts/hosts.mjs';
11
12
  import { claimer, loadAgentOverrides, writeNativeLayer } from '../hosts/native.mjs';
12
13
  import {
@@ -55,12 +56,12 @@ import { mkdirSync } from 'node:fs';
55
56
  function opencodeLayer(cfg, items, themeName, theme, dir, owned, opts) {
56
57
  const {
57
58
  oldOwned, manifestExisted, agentPath, wireBase, overridesDir, oldDenies = [], oldEdit = { asks: [], shorthand: null },
58
- oldHashes = {},
59
+ oldHashes = {}, oldGates = [],
59
60
  } = opts;
60
61
  ensureAgentOverridesStub(cfg, overridesDir);
61
62
  const overrides = loadAgentOverrides(overridesDir);
62
63
  // One claim for every writer below whose path lands in `owned` — see `claimer`.
63
- const claim = claimer(oldOwned, dir, manifestExisted, oldHashes);
64
+ const claim = claimer(oldOwned, dir, manifestExisted, oldHashes, cfg.force);
64
65
 
65
66
  const { nAgents, nSkills, written, userOnlySkills } = writeNativeLayer(
66
67
  items, path.join(dir, 'agents'), path.join(dir, 'skills'), overrides,
@@ -100,7 +101,7 @@ function opencodeLayer(cfg, items, themeName, theme, dir, owned, opts) {
100
101
  const cfgName = path.basename(mergeOpencodeJson(path.join(wireBase, 'opencode.json'),
101
102
  agentPath, cfg.doctrines, cfg.excludeRules, userOnlySkills, staleSkillNames, wired,
102
103
  cfg.deletionGate, opencodeEditAsks(dir, wireBase === dir, wireBase === dir ? null : agentPath,
103
- cfg.doctrines, cfg.excludeRules), oldEdit));
104
+ cfg.doctrines, cfg.excludeRules), oldEdit, oldGates, cfg.pruneGates));
104
105
  // The next record: Geneseed's earlier denies still wanted, plus the ones it added now. A merge
105
106
  // that wrote nothing (`skillsAdded` unset) keeps the old record whole.
106
107
  const skillDenies = wired.skillsAdded
@@ -110,6 +111,9 @@ function opencodeLayer(cfg, items, themeName, theme, dir, owned, opts) {
110
111
  return {
111
112
  nAgents, nSkills, nPlugins, nWorkflows, primary, nCommands: commands.length, cfgName,
112
113
  skillDenies, editRecord: wired.editRecord ?? oldEdit, editRefused: [...claim.editRefused],
114
+ // As `skillDenies`: a merge that wrote nothing keeps the old record whole.
115
+ bashGates: wired.bashGates ? [...wired.bashGates].sort() : oldGates,
116
+ kept: [...claim.kept],
113
117
  };
114
118
  }
115
119
 
@@ -133,7 +137,7 @@ export function emitOpencodeRender(cfg, job) {
133
137
  phaseLog('RENDER');
134
138
  const {
135
139
  theme: _theme, out, root, footprint, nativeCatalog, oldOwned, manifestExisted, agentPath,
136
- oldDenies, oldEdit, oldHashes = {},
140
+ oldDenies, oldEdit, oldHashes = {}, oldGates = [],
137
141
  } = job;
138
142
  const oc = path.join(root, '.opencode');
139
143
 
@@ -141,16 +145,20 @@ export function emitOpencodeRender(cfg, job) {
141
145
 
142
146
  // OpenCode loads agents/skills natively, so strip AGENT.md's per-row spec links to
143
147
  // plain names (the portable build keeps them). A deliberate de-link, not a fix.
148
+ // Only the AGENT.md this build wrote: one it found there and kept is the user's, and this
149
+ // rewrite changed its links, and its line endings on Windows.
144
150
  const agentMd = path.join(out, 'AGENT.md');
145
- if (isFile(agentMd)) writeText(agentMd, stripCapabilityLinks(readText(agentMd)));
151
+ if (isFile(agentMd) && bundleFiles(out)?.includes('AGENT.md')) {
152
+ writeText(agentMd, stripCapabilityLinks(readText(agentMd)));
153
+ }
146
154
 
147
155
  const owned = [];
148
156
  const { theme, items } = renderAll(cfg, _theme, { footprint, nativeCatalog });
149
157
 
150
158
  const {
151
- nAgents, nSkills, nPlugins, nWorkflows, primary, nCommands, cfgName, skillDenies, editRecord, editRefused,
159
+ nAgents, nSkills, nPlugins, nWorkflows, primary, nCommands, cfgName, skillDenies, editRecord, editRefused, bashGates, kept,
152
160
  } = opencodeLayer(cfg, items, _theme, theme, oc, owned, {
153
- oldOwned, manifestExisted, agentPath, wireBase: root, overridesDir: out, oldDenies, oldEdit, oldHashes,
161
+ oldOwned, manifestExisted, agentPath, wireBase: root, overridesDir: out, oldDenies, oldEdit, oldHashes, oldGates,
154
162
  });
155
163
 
156
164
  return {
@@ -162,6 +170,8 @@ export function emitOpencodeRender(cfg, job) {
162
170
  skillDenies,
163
171
  editRecord,
164
172
  editRefused,
173
+ bashGates,
174
+ kept,
165
175
  };
166
176
  }
167
177
 
@@ -196,7 +206,7 @@ export function emitOpencodeGlobalRender(cfg, job) {
196
206
  phaseLog('RENDER');
197
207
  const {
198
208
  theme: themeName, cfgDir, out, footprint, nativeCatalog, oldOwned, agentPath, oldDenies, oldEdit,
199
- oldHashes = {},
209
+ oldHashes = {}, oldGates = [],
200
210
  } = job;
201
211
 
202
212
  // No `lawsPrefix`: the standalone laws dir sits beside AGENT.md in <cfg>, so the lean
@@ -227,9 +237,9 @@ export function emitOpencodeGlobalRender(cfg, job) {
227
237
  // `manifestExisted` is deliberately not passed, so
228
238
  // the pre-manifest header line is unreachable from this emit.
229
239
  const {
230
- nAgents, nSkills, nPlugins, nWorkflows, primary, nCommands, cfgName, skillDenies, editRecord, editRefused,
240
+ nAgents, nSkills, nPlugins, nWorkflows, primary, nCommands, cfgName, skillDenies, editRecord, editRefused, bashGates, kept,
231
241
  } = opencodeLayer(cfg, items, themeName, theme, cfgDir, owned, {
232
- oldOwned, agentPath, wireBase: cfgDir, overridesDir: cfgDir, oldDenies, oldEdit, oldHashes,
242
+ oldOwned, agentPath, wireBase: cfgDir, overridesDir: cfgDir, oldDenies, oldEdit, oldHashes, oldGates,
233
243
  });
234
244
 
235
245
  const memStatus = globalMemory(cfgDir, items, out, cfg.src);
@@ -258,5 +268,7 @@ export function emitOpencodeGlobalRender(cfg, job) {
258
268
  skillDenies,
259
269
  editRecord,
260
270
  editRefused,
271
+ bashGates,
272
+ kept,
261
273
  };
262
274
  }