@venizia/vulcan 0.4.9-0 → 0.4.9-2

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 (141) hide show
  1. package/base/extensions/vulcan-guards.ts +48 -41
  2. package/base/hooks/antigravity-guards.ts +2 -2
  3. package/base/hooks/codex-guards.ts +15 -5
  4. package/base/hooks/guard-git.ts +8 -8
  5. package/base/hooks/guard-manifest.ts +4 -5
  6. package/base/hooks/guard-outside.ts +8 -8
  7. package/base/hooks/guard-package.ts +5 -6
  8. package/base/hooks/guard-remote-hosts.ts +6 -7
  9. package/base/hooks/guard-scripting.ts +5 -6
  10. package/base/hooks/guard-writes.ts +8 -9
  11. package/base/hooks/post-tool.ts +2 -2
  12. package/base/hooks/prompt-submit.ts +2 -2
  13. package/base/hooks/session-start.ts +3 -3
  14. package/base/hooks/stop.ts +2 -2
  15. package/base/hooks/subagent-start.ts +2 -2
  16. package/base/skills/docs-update/SKILL.md +4 -2
  17. package/base/skills/visualize-work/SKILL.md +9 -0
  18. package/package.json +3 -3
  19. package/src/agents/atlas-block.ts +43 -43
  20. package/src/agents/codex-hooks.ts +45 -43
  21. package/src/agents/detect.ts +19 -16
  22. package/src/agents/exclude.ts +96 -97
  23. package/src/agents/hooks-json.ts +38 -36
  24. package/src/agents/local.ts +46 -43
  25. package/src/agents/prompt.ts +45 -42
  26. package/src/agents/render.ts +201 -195
  27. package/src/agents/resolve.ts +133 -134
  28. package/src/agents/table.ts +12 -8
  29. package/src/commands/add.command.ts +2 -2
  30. package/src/commands/agents.command.ts +11 -17
  31. package/src/commands/clean.command.ts +6 -6
  32. package/src/commands/doctor.command.ts +4 -4
  33. package/src/commands/init.command.ts +12 -8
  34. package/src/commands/preset.command.ts +2 -2
  35. package/src/commands/profile.command.ts +42 -49
  36. package/src/commands/sync.command.ts +109 -111
  37. package/src/commands/upgrade.command.ts +80 -75
  38. package/src/commands/visualize.command.ts +7 -13
  39. package/src/commands/x.command.ts +55 -50
  40. package/src/common/format.ts +23 -21
  41. package/src/common/json.ts +8 -5
  42. package/src/common/layout-folder.ts +94 -91
  43. package/src/common/paths.ts +14 -12
  44. package/src/config/loader.ts +52 -49
  45. package/src/config/packages.ts +14 -11
  46. package/src/config/schema.ts +3 -3
  47. package/src/create/add-app.ts +519 -509
  48. package/src/create/add-lib.ts +237 -240
  49. package/src/create/bunfig.ts +26 -23
  50. package/src/create/checks.ts +36 -34
  51. package/src/create/diff.ts +21 -23
  52. package/src/create/dockerignore.ts +26 -24
  53. package/src/create/files.ts +7 -5
  54. package/src/create/init-monorepo.ts +75 -80
  55. package/src/create/lib-preset.ts +59 -63
  56. package/src/create/manifest-json.ts +10 -4
  57. package/src/create/names.ts +217 -210
  58. package/src/create/next.ts +26 -23
  59. package/src/create/plan.ts +15 -12
  60. package/src/create/preset-diff.ts +301 -303
  61. package/src/create/preset-menu.ts +38 -32
  62. package/src/create/preset.ts +202 -197
  63. package/src/create/process.ts +79 -72
  64. package/src/create/scratch.ts +48 -49
  65. package/src/create/workspace.ts +404 -396
  66. package/src/doctor/checks.ts +1027 -1014
  67. package/src/doctor/makefile.ts +17 -13
  68. package/src/doctor/runner.ts +88 -118
  69. package/src/doctor/skills.ts +97 -95
  70. package/src/doctor/tags.ts +42 -37
  71. package/src/hooks/codex-patch.ts +25 -22
  72. package/src/hooks/command-view.ts +44 -39
  73. package/src/hooks/decision.ts +37 -37
  74. package/src/hooks/guard-git.ts +51 -49
  75. package/src/hooks/guard-manifest.ts +58 -55
  76. package/src/hooks/guard-outside.ts +93 -91
  77. package/src/hooks/guard-package.ts +82 -79
  78. package/src/hooks/guard-scripting.ts +19 -14
  79. package/src/hooks/guard-writes.ts +154 -149
  80. package/src/hooks/owner-reply.ts +127 -127
  81. package/src/hooks/post-tool.ts +94 -93
  82. package/src/hooks/project-guards.ts +65 -62
  83. package/src/hooks/project-tmp.ts +27 -24
  84. package/src/hooks/remote-hosts.ts +153 -130
  85. package/src/hooks/session-digest.ts +98 -101
  86. package/src/hooks/shell.ts +509 -499
  87. package/src/hooks/subagent-card.ts +11 -7
  88. package/src/hooks/trusted-scripts.ts +106 -104
  89. package/src/init/scaffold.ts +135 -132
  90. package/src/local/clean.ts +38 -36
  91. package/src/local/format.ts +21 -17
  92. package/src/local/scan.ts +144 -138
  93. package/src/manifest/render.ts +110 -104
  94. package/src/owner/card.ts +51 -46
  95. package/src/owner/profile.ts +99 -93
  96. package/src/owner/reply-switch.ts +9 -6
  97. package/src/owner/shape.ts +71 -69
  98. package/src/owner/survey.ts +173 -171
  99. package/src/owner/view.ts +62 -59
  100. package/src/owner/violations.ts +119 -123
  101. package/src/rules/base.ts +15 -11
  102. package/src/rules/parser.ts +39 -32
  103. package/src/rules/slots.ts +8 -6
  104. package/src/signals/claims.ts +30 -28
  105. package/src/signals/classify.ts +38 -33
  106. package/src/signals/loop.ts +39 -37
  107. package/src/signals/state.ts +79 -81
  108. package/src/skills/frontmatter.ts +28 -28
  109. package/src/sync/agent-files.ts +217 -199
  110. package/src/sync/agent-removal.ts +56 -59
  111. package/src/sync/atlas-block.ts +45 -43
  112. package/src/sync/base-rules.ts +32 -30
  113. package/src/sync/claude-launch.ts +36 -34
  114. package/src/sync/exclude.ts +77 -69
  115. package/src/sync/local-choice.ts +50 -47
  116. package/src/sync/planner.ts +59 -61
  117. package/src/sync/prune.ts +52 -48
  118. package/src/sync/settings.ts +166 -167
  119. package/src/ui/capability.ts +12 -7
  120. package/src/ui/keyboard.ts +38 -38
  121. package/src/ui/prompt.ts +79 -77
  122. package/src/visualize/assets.ts +33 -24
  123. package/src/visualize/charts.ts +179 -176
  124. package/src/visualize/compare-css.ts +3 -2
  125. package/src/visualize/compare-render.ts +9 -7
  126. package/src/visualize/diagrams.ts +189 -174
  127. package/src/visualize/grid-span.ts +34 -0
  128. package/src/visualize/icons.ts +7 -5
  129. package/src/visualize/kinds-render.ts +50 -45
  130. package/src/visualize/kinds-validate.ts +12 -10
  131. package/src/visualize/labels.ts +21 -17
  132. package/src/visualize/layout.ts +112 -97
  133. package/src/visualize/page.ts +92 -104
  134. package/src/visualize/render.ts +143 -140
  135. package/src/visualize/sections.ts +395 -384
  136. package/src/visualize/sources.ts +2 -2
  137. package/src/visualize/theme.ts +12 -10
  138. package/src/visualize/validate.ts +13 -9
  139. package/src/wiki/anchors.ts +38 -36
  140. package/src/wiki/command.ts +4 -4
  141. package/src/wiki/source-links.ts +46 -44
@@ -1,33 +1,13 @@
1
1
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
2
2
  import { dirname, join } from 'node:path';
3
- import { LOCAL_AGENTS_FILE, renderLocalChoice } from '../agents/index.ts';
3
+ import { LOCAL_AGENTS_FILE, LocalChoice } from '../agents/index.ts';
4
4
  import { ProjectLayout } from '../common/index.ts';
5
- import { planClaudeLaunch } from './claude-launch.ts';
5
+ import { LaunchSettings } from './claude-launch.ts';
6
6
  import { SyncStatuses } from './common/index.ts';
7
7
  import type { ISyncAction } from './common/index.ts';
8
8
 
9
9
  const NO_CHANGE = (): void => {};
10
10
 
11
- /** The developer's stored agents: written when the machine just chose, reported unchanged when it was read. */
12
- export const planLocalChoice = (opts: { root: string; agents: string[] }): ISyncAction => {
13
- const path = join(opts.root, LOCAL_AGENTS_FILE);
14
- const text = renderLocalChoice({ agents: opts.agents });
15
- const before = existsSync(path) ? readFileSync(path, 'utf8') : undefined;
16
-
17
- if (before === text) {
18
- return { path, status: SyncStatuses.UNCHANGED, apply: NO_CHANGE };
19
- }
20
-
21
- return {
22
- path,
23
- status: before === undefined ? SyncStatuses.CREATED : SyncStatuses.REPLACED,
24
- apply: () => {
25
- mkdirSync(dirname(path), { recursive: true });
26
- writeFileSync(path, text);
27
- },
28
- };
29
- };
30
-
31
11
  /** One line sync adds to a committed `.gitignore`; a project without one is left alone. */
32
12
  const planIgnoreLine = (opts: { root: string; line: string }): ISyncAction[] => {
33
13
  const path = join(opts.root, '.gitignore');
@@ -56,32 +36,55 @@ const planIgnoreLine = (opts: { root: string; line: string }): ISyncAction[] =>
56
36
  ];
57
37
  };
58
38
 
59
- /** The one line sync adds to a committed `.gitignore`; a project without one is left alone. */
60
- export const planLocalIgnore = (opts: { root: string }): ISyncAction[] =>
61
- planIgnoreLine({ root: opts.root, line: LOCAL_AGENTS_FILE });
39
+ export class LocalPlan {
40
+ /** The developer's stored agents: written when the machine just chose, reported unchanged when it was read. */
41
+ static planChoice(opts: { root: string; agents: string[] }): ISyncAction {
42
+ const path = join(opts.root, LOCAL_AGENTS_FILE);
43
+ const text = LocalChoice.render({ agents: opts.agents });
44
+ const before = existsSync(path) ? readFileSync(path, 'utf8') : undefined;
62
45
 
63
- /**
64
- * The project's local workspace: `.agents/local/` is gitignored and holds what an agent creates while
65
- * it works (scratch, worktrees, clones, cache, prototypes), so nothing lands outside the project.
66
- */
67
- export const planLocalWorkspace = (opts: { root: string }): ISyncAction[] => {
68
- const directory = join(opts.root, ProjectLayout.LOCAL_DIRECTORY);
69
- const missing = ProjectLayout.LOCAL_LAYOUT.map((entry) => entry.name).filter(
70
- (name) => !existsSync(join(directory, name)),
71
- );
46
+ if (before === text) {
47
+ return { path, status: SyncStatuses.UNCHANGED, apply: NO_CHANGE };
48
+ }
72
49
 
73
- return [
74
- ...planIgnoreLine({ root: opts.root, line: `${ProjectLayout.LOCAL_DIRECTORY}/` }),
75
- ...planClaudeLaunch({ root: opts.root }),
76
- {
77
- path: directory,
78
- status: missing.length === 0 ? SyncStatuses.UNCHANGED : SyncStatuses.CREATED,
79
- ...(missing.length === 0 ? {} : { note: `created ${missing.join(', ')}` }),
50
+ return {
51
+ path,
52
+ status: before === undefined ? SyncStatuses.CREATED : SyncStatuses.REPLACED,
80
53
  apply: () => {
81
- for (const name of missing) {
82
- mkdirSync(join(directory, name), { recursive: true });
83
- }
54
+ mkdirSync(dirname(path), { recursive: true });
55
+ writeFileSync(path, text);
84
56
  },
85
- },
86
- ];
87
- };
57
+ };
58
+ }
59
+
60
+ /** The one line sync adds to a committed `.gitignore`; a project without one is left alone. */
61
+ static planIgnore(opts: { root: string }): ISyncAction[] {
62
+ return planIgnoreLine({ root: opts.root, line: LOCAL_AGENTS_FILE });
63
+ }
64
+
65
+ /**
66
+ * The project's local workspace: `.agents/local/` is gitignored and holds what an agent creates while
67
+ * it works (scratch, worktrees, clones, cache, prototypes), so nothing lands outside the project.
68
+ */
69
+ static planWorkspace(opts: { root: string }): ISyncAction[] {
70
+ const directory = join(opts.root, ProjectLayout.LOCAL_DIRECTORY);
71
+ const missing = ProjectLayout.LOCAL_LAYOUT.map((entry) => entry.name).filter(
72
+ (name) => !existsSync(join(directory, name)),
73
+ );
74
+
75
+ return [
76
+ ...planIgnoreLine({ root: opts.root, line: `${ProjectLayout.LOCAL_DIRECTORY}/` }),
77
+ ...LaunchSettings.planClaude({ root: opts.root }),
78
+ {
79
+ path: directory,
80
+ status: missing.length === 0 ? SyncStatuses.UNCHANGED : SyncStatuses.CREATED,
81
+ ...(missing.length === 0 ? {} : { note: `created ${missing.join(', ')}` }),
82
+ apply: () => {
83
+ for (const name of missing) {
84
+ mkdirSync(join(directory, name), { recursive: true });
85
+ }
86
+ },
87
+ },
88
+ ];
89
+ }
90
+ }
@@ -9,22 +9,16 @@ import {
9
9
  writeFileSync,
10
10
  } from 'node:fs';
11
11
  import { basename, dirname, join, resolve } from 'node:path';
12
- import { readAgentTable } from '../agents/index.ts';
13
- import { BASE_DIRECTORY, stableBaseDirectoryOf } from '../common/index.ts';
12
+ import { AgentTable } from '../agents/index.ts';
13
+ import { BASE_DIRECTORY, BaseDirectory } from '../common/index.ts';
14
14
  import { CodingAgents } from '../config/index.ts';
15
15
  import type { TResolvedConfig } from '../config/index.ts';
16
- import { ManifestConstants, renderManifest } from '../manifest/index.ts';
17
- import { readSlots } from '../rules/index.ts';
18
- import { planAgentFiles } from './agent-files.ts';
16
+ import { ManifestConstants, ProjectManifest } from '../manifest/index.ts';
17
+ import { RuleSlots } from '../rules/index.ts';
18
+ import { AgentFiles } from './agent-files.ts';
19
19
  import { SyncConstants, SyncLinks, SyncStatuses } from './common/index.ts';
20
20
  import type { ISyncAction, TSettings } from './common/index.ts';
21
- import {
22
- buildProjectHookSettings,
23
- isSettingsObject,
24
- keepKeyOrder,
25
- mergeSettings,
26
- removeManagedSettings,
27
- } from './settings.ts';
21
+ import { isSettingsObject, ProjectSettings } from './settings.ts';
28
22
 
29
23
  const NO_CHANGE = (): void => {};
30
24
 
@@ -91,17 +85,17 @@ const buildManagedOverlay = (opts: { config: TResolvedConfig }): TSettings => {
91
85
  readFileSync(join(BASE_DIRECTORY, 'claude', SyncConstants.SETTINGS_FILE), 'utf8'),
92
86
  );
93
87
 
94
- for (const [id, slot] of Object.entries(readSlots())) {
88
+ for (const [id, slot] of Object.entries(RuleSlots.read())) {
95
89
  const choice = opts.config.rules[id];
96
90
  const settings = choice === undefined ? undefined : slot.options[choice]?.settings;
97
91
 
98
92
  if (settings !== undefined) {
99
- overlay = mergeSettings({ base: overlay, overlay: settings });
93
+ overlay = ProjectSettings.merge({ base: overlay, overlay: settings });
100
94
  }
101
95
  }
102
96
 
103
97
  if (opts.config.remoteHosts !== undefined) {
104
- overlay = mergeSettings({
98
+ overlay = ProjectSettings.merge({
105
99
  base: overlay,
106
100
  overlay: JSON.parse(
107
101
  readFileSync(join(BASE_DIRECTORY, 'claude', SyncConstants.REMOTE_HOSTS_FILE), 'utf8'),
@@ -109,12 +103,12 @@ const buildManagedOverlay = (opts: { config: TResolvedConfig }): TSettings => {
109
103
  });
110
104
  }
111
105
 
112
- overlay = mergeSettings({
106
+ overlay = ProjectSettings.merge({
113
107
  base: overlay,
114
- overlay: buildProjectHookSettings({ hooks: opts.config.hooks }),
108
+ overlay: ProjectSettings.buildHook({ hooks: opts.config.hooks }),
115
109
  });
116
110
 
117
- return mergeSettings({ base: overlay, overlay: opts.config.claude.settings });
111
+ return ProjectSettings.merge({ base: overlay, overlay: opts.config.claude.settings });
118
112
  };
119
113
 
120
114
  /** The previous overlay is taken back before the new one merges in, so removed choices really disappear. */
@@ -135,12 +129,12 @@ const planSettings = (opts: { root: string; config: TResolvedConfig }): ISyncAct
135
129
 
136
130
  const previous = readSettingsFile({ path: managedPath }) ?? {};
137
131
  const overlay = buildManagedOverlay({ config: opts.config });
138
- const merged = mergeSettings({
139
- base: removeManagedSettings({ settings: current, managed: previous }),
132
+ const merged = ProjectSettings.merge({
133
+ base: ProjectSettings.removeManaged({ settings: current, managed: previous }),
140
134
  overlay,
141
135
  });
142
136
 
143
- const wanted = keepKeyOrder({ settings: merged, reference: current });
137
+ const wanted = ProjectSettings.keepKeyOrder({ settings: merged, reference: current });
144
138
 
145
139
  const text = `${JSON.stringify(wanted, null, 2)}\n`;
146
140
  const managedText = `${JSON.stringify(overlay, null, 2)}\n`;
@@ -201,7 +195,7 @@ const planSkillLinks = (opts: {
201
195
  ];
202
196
  }
203
197
 
204
- const stableSkills = join(stableBaseDirectoryOf(opts), SyncConstants.SKILLS_DIRECTORY);
198
+ const stableSkills = join(BaseDirectory.stableOf(opts), SyncConstants.SKILLS_DIRECTORY);
205
199
  const shipped = findSkillDirectories({
206
200
  directory: join(BASE_DIRECTORY, SyncConstants.SKILLS_DIRECTORY),
207
201
  }).map((source) => join(stableSkills, basename(source)));
@@ -281,50 +275,54 @@ const planSkillLinks = (opts: {
281
275
  return [...links, ...shadowing, ...stale];
282
276
  };
283
277
 
284
- /** The committed project manifest (Project Contract v1, C1), rendered from the config. */
285
- export const planManifest = (opts: { root: string; config: TResolvedConfig }): ISyncAction => {
286
- const path = join(opts.root, ManifestConstants.FILE);
287
- const text = renderManifest(opts);
288
- const write = (): void => {
289
- mkdirSync(dirname(path), { recursive: true });
290
- writeFileSync(path, text);
291
- };
292
-
293
- if (!existsSync(path)) {
294
- return { path, status: SyncStatuses.CREATED, apply: write };
295
- }
296
-
297
- return readFileSync(path, 'utf8') === text
298
- ? { path, status: SyncStatuses.UNCHANGED, apply: NO_CHANGE }
299
- : { path, status: SyncStatuses.REPLACED, apply: write };
300
- };
301
-
302
278
  /** The skills folders of the chosen agents, each once, in table order: agents that read one folder share its links. */
303
279
  const skillDirectoriesOf = (opts: { agents: string[] }): string[] => [
304
280
  ...new Set(
305
- readAgentTable()
281
+ AgentTable.read()
306
282
  .filter((entry) => opts.agents.includes(entry.id))
307
283
  .map((entry) => entry.skills.dir),
308
284
  ),
309
285
  ];
310
286
 
311
- /** Every adapter the project's agents need, and the manifest every project carries - planned, not written. */
312
- export const planSync = (opts: {
313
- root: string;
314
- config: TResolvedConfig;
315
- /** The agents this machine chose (`resolveAgents`); only Claude has adapters until the renderers land. */
316
- agents: string[];
317
- }): ISyncAction[] => [
318
- ...(opts.agents.includes(CodingAgents.CLAUDE)
319
- ? [planClaudeImport({ root: opts.root }), planSettings(opts)]
320
- : []),
321
- ...skillDirectoriesOf({ agents: opts.agents }).flatMap((directory) =>
322
- planSkillLinks({
323
- root: opts.root,
324
- directory,
325
- withProject: directory === SyncConstants.CLAUDE_SKILLS,
326
- }),
327
- ),
328
- ...planAgentFiles({ root: opts.root, agents: opts.agents }),
329
- planManifest(opts),
330
- ];
287
+ export class SyncPlanner {
288
+ /** The committed project manifest (Project Contract v1, C1), rendered from the config. */
289
+ static planManifest(opts: { root: string; config: TResolvedConfig }): ISyncAction {
290
+ const path = join(opts.root, ManifestConstants.FILE);
291
+ const text = ProjectManifest.render(opts);
292
+ const write = (): void => {
293
+ mkdirSync(dirname(path), { recursive: true });
294
+ writeFileSync(path, text);
295
+ };
296
+
297
+ if (!existsSync(path)) {
298
+ return { path, status: SyncStatuses.CREATED, apply: write };
299
+ }
300
+
301
+ return readFileSync(path, 'utf8') === text
302
+ ? { path, status: SyncStatuses.UNCHANGED, apply: NO_CHANGE }
303
+ : { path, status: SyncStatuses.REPLACED, apply: write };
304
+ }
305
+
306
+ /** Every adapter the project's agents need, and the manifest every project carries - planned, not written. */
307
+ static plan(opts: {
308
+ root: string;
309
+ config: TResolvedConfig;
310
+ /** The agents this machine chose (`AgentSelection.resolve`); only Claude has adapters until the renderers land. */
311
+ agents: string[];
312
+ }): ISyncAction[] {
313
+ return [
314
+ ...(opts.agents.includes(CodingAgents.CLAUDE)
315
+ ? [planClaudeImport({ root: opts.root }), planSettings(opts)]
316
+ : []),
317
+ ...skillDirectoriesOf({ agents: opts.agents }).flatMap((directory) =>
318
+ planSkillLinks({
319
+ root: opts.root,
320
+ directory,
321
+ withProject: directory === SyncConstants.CLAUDE_SKILLS,
322
+ }),
323
+ ),
324
+ ...AgentFiles.plan({ root: opts.root, agents: opts.agents }),
325
+ SyncPlanner.planManifest(opts),
326
+ ];
327
+ }
328
+ }
package/src/sync/prune.ts CHANGED
@@ -3,7 +3,7 @@ import { join } from 'node:path';
3
3
  import { BASE_DIRECTORY } from '../common/index.ts';
4
4
  import { SyncConstants, SyncStatuses } from './common/index.ts';
5
5
  import type { ISyncAction, TSettings } from './common/index.ts';
6
- import { extractHookCommands, isSettingsObject, removeHookCommands } from './settings.ts';
6
+ import { isSettingsObject, ProjectSettings } from './settings.ts';
7
7
 
8
8
  /**
9
9
  * The exact hook commands released VULCAN versions shipped (0.1.0-x, then 0.2.0-0). Only these are
@@ -70,7 +70,7 @@ const removeHookCommand = (opts: { path: string; command: string }): void => {
70
70
  continue;
71
71
  }
72
72
 
73
- const kept = removeHookCommands({ entries, commands: new Set([opts.command]) });
73
+ const kept = ProjectSettings.removeHookCommands({ entries, commands: new Set([opts.command]) });
74
74
 
75
75
  if (kept.length > 0) {
76
76
  hooks.value[event] = kept;
@@ -90,49 +90,53 @@ const isDeadLink = (opts: { path: string }): boolean => {
90
90
  }
91
91
  };
92
92
 
93
- /**
94
- * `sync --prune`: what sync can prove is stale and did not write itself - old VULCAN and plugin-era
95
- * hook commands, and skill links whose target is gone. What sync wrote last time it takes back on
96
- * every run; a developer's own hooks and any real directory are never touched.
97
- */
98
- export const planPrune = (opts: { root: string }): ISyncAction[] => {
99
- const directory = join(opts.root, SyncConstants.CLAUDE_DIRECTORY);
100
- const settingsPath = join(directory, SyncConstants.SETTINGS_FILE);
101
- const managed = new Set(
102
- extractHookCommands({
103
- settings: readJson({ path: join(directory, SyncConstants.MANAGED_FILE) }),
104
- }),
105
- );
106
- const shipped = new Set(
107
- extractHookCommands({
108
- settings: readJson({ path: join(BASE_DIRECTORY, 'claude', SyncConstants.SETTINGS_FILE) }),
109
- }),
110
- );
111
- const staleCommands = [
112
- ...new Set(extractHookCommands({ settings: readJson({ path: settingsPath }) })),
113
- ].filter(
114
- (command) => !managed.has(command) && isStaleCommand({ root: opts.root, command, shipped }),
115
- );
116
- const skills = join(directory, SyncConstants.SKILLS_DIRECTORY);
117
- // lstat, not stat: a symlinked skills directory leads out of the project and is never walked.
118
- const deadLinks = lstatSync(skills, { throwIfNoEntry: false })?.isDirectory()
119
- ? readdirSync(skills)
120
- .map((name) => join(skills, name))
121
- .filter((path) => isDeadLink({ path }))
122
- : [];
123
-
124
- return [
125
- ...staleCommands.map((command): ISyncAction => ({
126
- path: settingsPath,
127
- status: SyncStatuses.REMOVED,
128
- note: `stale hook: ${command}`,
129
- apply: () => removeHookCommand({ path: settingsPath, command }),
130
- })),
131
- ...deadLinks.map((path): ISyncAction => ({
132
- path,
133
- status: SyncStatuses.REMOVED,
134
- note: 'dead link',
135
- apply: () => rmSync(path),
136
- })),
137
- ];
138
- };
93
+ export class PrunePlan {
94
+ /**
95
+ * `sync --prune`: what sync can prove is stale and did not write itself - old VULCAN and plugin-era
96
+ * hook commands, and skill links whose target is gone. What sync wrote last time it takes back on
97
+ * every run; a developer's own hooks and any real directory are never touched.
98
+ */
99
+ static plan(opts: { root: string }): ISyncAction[] {
100
+ const directory = join(opts.root, SyncConstants.CLAUDE_DIRECTORY);
101
+ const settingsPath = join(directory, SyncConstants.SETTINGS_FILE);
102
+ const managed = new Set(
103
+ ProjectSettings.extractHookCommands({
104
+ settings: readJson({ path: join(directory, SyncConstants.MANAGED_FILE) }),
105
+ }),
106
+ );
107
+ const shipped = new Set(
108
+ ProjectSettings.extractHookCommands({
109
+ settings: readJson({ path: join(BASE_DIRECTORY, 'claude', SyncConstants.SETTINGS_FILE) }),
110
+ }),
111
+ );
112
+ const staleCommands = [
113
+ ...new Set(
114
+ ProjectSettings.extractHookCommands({ settings: readJson({ path: settingsPath }) }),
115
+ ),
116
+ ].filter(
117
+ (command) => !managed.has(command) && isStaleCommand({ root: opts.root, command, shipped }),
118
+ );
119
+ const skills = join(directory, SyncConstants.SKILLS_DIRECTORY);
120
+ // lstat, not stat: a symlinked skills directory leads out of the project and is never walked.
121
+ const deadLinks = lstatSync(skills, { throwIfNoEntry: false })?.isDirectory()
122
+ ? readdirSync(skills)
123
+ .map((name) => join(skills, name))
124
+ .filter((path) => isDeadLink({ path }))
125
+ : [];
126
+
127
+ return [
128
+ ...staleCommands.map((command): ISyncAction => ({
129
+ path: settingsPath,
130
+ status: SyncStatuses.REMOVED,
131
+ note: `stale hook: ${command}`,
132
+ apply: () => removeHookCommand({ path: settingsPath, command }),
133
+ })),
134
+ ...deadLinks.map((path): ISyncAction => ({
135
+ path,
136
+ status: SyncStatuses.REMOVED,
137
+ note: 'dead link',
138
+ apply: () => rmSync(path),
139
+ })),
140
+ ];
141
+ }
142
+ }