@venizia/vulcan 0.4.8 → 0.4.9-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. package/base/extensions/vulcan-guards.ts +48 -41
  2. package/base/hooks/antigravity-guards.ts +4 -3
  3. package/base/hooks/codex-guards.ts +17 -6
  4. package/base/hooks/guard-git.ts +8 -8
  5. package/base/hooks/guard-manifest.ts +5 -5
  6. package/base/hooks/guard-outside.ts +8 -8
  7. package/base/hooks/guard-package.ts +6 -6
  8. package/base/hooks/guard-remote-hosts.ts +14 -9
  9. package/base/hooks/guard-scripting.ts +6 -6
  10. package/base/hooks/guard-writes.ts +20 -11
  11. package/base/hooks/post-tool.ts +4 -3
  12. package/base/hooks/prompt-submit.ts +4 -3
  13. package/base/hooks/session-start.ts +5 -3
  14. package/base/hooks/stop.ts +4 -3
  15. package/base/hooks/subagent-start.ts +2 -2
  16. package/base/make/vulcan.mk +1 -4
  17. package/base/skills/build-a-feature/SKILL.md +1 -1
  18. package/base/skills/docs-update/SKILL.md +11 -5
  19. package/base/skills/docs-update/evals/evals.json +1 -1
  20. package/base/skills/docs-writing/SKILL.md +1 -1
  21. package/base/skills/plan-a-change/references/spec-card.md +1 -1
  22. package/base/skills/ship/SKILL.md +1 -1
  23. package/base/skills/visualize-work/SKILL.md +29 -6
  24. package/base/skills/visualize-work/references/spec.md +16 -5
  25. package/package.json +5 -6
  26. package/src/agents/atlas-block.ts +43 -43
  27. package/src/agents/codex-hooks.ts +55 -52
  28. package/src/agents/common/types.ts +1 -1
  29. package/src/agents/detect.ts +19 -16
  30. package/src/agents/exclude.ts +97 -98
  31. package/src/agents/hooks-json.ts +41 -43
  32. package/src/agents/local.ts +46 -43
  33. package/src/agents/prompt.ts +45 -42
  34. package/src/agents/render.ts +203 -201
  35. package/src/agents/resolve.ts +133 -134
  36. package/src/agents/table.ts +12 -8
  37. package/src/cli.ts +3 -1
  38. package/src/commands/add.command.ts +2 -2
  39. package/src/commands/agents.command.ts +11 -17
  40. package/src/commands/clean.command.ts +6 -6
  41. package/src/commands/doctor.command.ts +6 -4
  42. package/src/commands/help.command.ts +11 -9
  43. package/src/commands/init.command.ts +14 -8
  44. package/src/commands/preset.command.ts +2 -2
  45. package/src/commands/profile.command.ts +43 -50
  46. package/src/commands/sync.command.ts +109 -111
  47. package/src/commands/upgrade.command.ts +85 -78
  48. package/src/commands/visualize.command.ts +20 -5
  49. package/src/commands/x.command.ts +55 -50
  50. package/src/common/format.ts +23 -21
  51. package/src/common/index.ts +2 -0
  52. package/src/common/json.ts +8 -5
  53. package/src/common/layout-folder.ts +96 -111
  54. package/src/common/paths.ts +14 -12
  55. package/src/common/record.ts +7 -0
  56. package/src/common/text.ts +7 -0
  57. package/src/config/common/constants.ts +13 -1
  58. package/src/config/common/types.ts +8 -1
  59. package/src/config/loader.ts +53 -48
  60. package/src/config/packages.ts +17 -11
  61. package/src/config/schema.ts +54 -7
  62. package/src/create/add-app.ts +604 -493
  63. package/src/create/add-lib.ts +249 -242
  64. package/src/create/bunfig.ts +26 -23
  65. package/src/create/checks.ts +36 -34
  66. package/src/create/common/constants.ts +1 -0
  67. package/src/create/common/failure.ts +10 -0
  68. package/src/create/common/index.ts +2 -0
  69. package/src/create/common/preset-path.ts +11 -0
  70. package/src/create/common/types.ts +7 -2
  71. package/src/create/diff.ts +21 -23
  72. package/src/create/dockerignore.ts +26 -24
  73. package/src/create/files.ts +7 -5
  74. package/src/create/init-monorepo.ts +78 -80
  75. package/src/create/lib-preset.ts +62 -61
  76. package/src/create/manifest-json.ts +10 -4
  77. package/src/create/names.ts +217 -210
  78. package/src/create/next.ts +27 -24
  79. package/src/create/plan.ts +15 -12
  80. package/src/create/preset-diff.ts +415 -240
  81. package/src/create/preset-menu.ts +40 -34
  82. package/src/create/preset.ts +207 -194
  83. package/src/create/process.ts +80 -71
  84. package/src/create/scratch.ts +49 -48
  85. package/src/create/workspace.ts +423 -398
  86. package/src/doctor/checks.ts +1069 -998
  87. package/src/doctor/makefile.ts +17 -13
  88. package/src/doctor/runner.ts +88 -116
  89. package/src/doctor/skills.ts +97 -95
  90. package/src/doctor/tags.ts +44 -41
  91. package/src/hooks/codex-patch.ts +27 -24
  92. package/src/hooks/command-view.ts +44 -39
  93. package/src/hooks/common/constants.ts +0 -3
  94. package/src/hooks/common/types.ts +15 -1
  95. package/src/hooks/decision.ts +38 -42
  96. package/src/hooks/guard-git.ts +52 -50
  97. package/src/hooks/guard-manifest.ts +58 -55
  98. package/src/hooks/guard-outside.ts +109 -88
  99. package/src/hooks/guard-package.ts +86 -77
  100. package/src/hooks/guard-scripting.ts +20 -15
  101. package/src/hooks/guard-writes.ts +169 -111
  102. package/src/hooks/owner-reply.ts +128 -128
  103. package/src/hooks/post-tool.ts +94 -93
  104. package/src/hooks/project-guards.ts +93 -55
  105. package/src/hooks/project-tmp.ts +27 -24
  106. package/src/hooks/remote-hosts.ts +157 -149
  107. package/src/hooks/session-digest.ts +99 -95
  108. package/src/hooks/shell.ts +519 -500
  109. package/src/hooks/subagent-card.ts +11 -7
  110. package/src/hooks/trusted-scripts.ts +158 -80
  111. package/src/init/common/types.ts +1 -1
  112. package/src/init/scaffold.ts +137 -134
  113. package/src/local/clean.ts +39 -37
  114. package/src/local/format.ts +21 -17
  115. package/src/local/scan.ts +146 -140
  116. package/src/manifest/render.ts +127 -112
  117. package/src/owner/card.ts +51 -46
  118. package/src/owner/profile.ts +100 -96
  119. package/src/owner/reply-switch.ts +9 -6
  120. package/src/owner/shape.ts +72 -70
  121. package/src/owner/survey.ts +175 -164
  122. package/src/owner/view.ts +62 -59
  123. package/src/owner/violations.ts +119 -123
  124. package/src/router.ts +4 -1
  125. package/src/rules/base.ts +15 -11
  126. package/src/rules/common/types.ts +1 -1
  127. package/src/rules/parser.ts +39 -32
  128. package/src/rules/slots.ts +8 -6
  129. package/src/signals/claims.ts +30 -28
  130. package/src/signals/classify.ts +36 -33
  131. package/src/signals/loop.ts +39 -37
  132. package/src/signals/state.ts +80 -85
  133. package/src/skills/frontmatter.ts +28 -28
  134. package/src/sync/agent-files.ts +217 -199
  135. package/src/sync/agent-removal.ts +62 -68
  136. package/src/sync/atlas-block.ts +45 -43
  137. package/src/sync/base-rules.ts +32 -30
  138. package/src/sync/claude-launch.ts +74 -37
  139. package/src/sync/common/constants.ts +4 -0
  140. package/src/sync/common/index.ts +1 -0
  141. package/src/sync/common/symlink.ts +9 -0
  142. package/src/sync/common/types.ts +2 -2
  143. package/src/sync/exclude.ts +77 -69
  144. package/src/sync/local-choice.ts +50 -47
  145. package/src/sync/planner.ts +64 -68
  146. package/src/sync/prune.ts +52 -48
  147. package/src/sync/settings.ts +167 -168
  148. package/src/ui/capability.ts +12 -7
  149. package/src/ui/keyboard.ts +35 -33
  150. package/src/ui/prompt.ts +81 -77
  151. package/src/visualize/assets.ts +379 -195
  152. package/src/visualize/charts.ts +188 -176
  153. package/src/visualize/compare-css.ts +31 -0
  154. package/src/visualize/compare-render.ts +196 -0
  155. package/src/visualize/compare-schema.ts +81 -0
  156. package/src/visualize/compare-validate.ts +126 -0
  157. package/src/visualize/constants.ts +29 -3
  158. package/src/visualize/diagrams.ts +189 -174
  159. package/src/visualize/gate.ts +136 -0
  160. package/src/visualize/grid-span.ts +34 -0
  161. package/src/visualize/icons.ts +9 -4
  162. package/src/visualize/index.ts +2 -0
  163. package/src/visualize/kinds-css.ts +54 -0
  164. package/src/visualize/kinds-render.ts +698 -0
  165. package/src/visualize/kinds-schema.ts +148 -0
  166. package/src/visualize/kinds-validate.ts +186 -0
  167. package/src/visualize/labels-vi.ts +109 -0
  168. package/src/visualize/labels.ts +53 -0
  169. package/src/visualize/layout.ts +112 -92
  170. package/src/visualize/page.ts +140 -114
  171. package/src/visualize/render.ts +158 -114
  172. package/src/visualize/schema.ts +21 -1
  173. package/src/visualize/sections.ts +401 -309
  174. package/src/visualize/sources.ts +270 -0
  175. package/src/visualize/theme.ts +474 -0
  176. package/src/visualize/validate.ts +15 -5
  177. package/src/wiki/anchors.ts +39 -37
  178. package/src/wiki/command.ts +4 -4
  179. package/src/wiki/source-links.ts +49 -49
@@ -1,4 +1,4 @@
1
- import { basenameOf, parseShell, programOf, splitHeredocs } from './shell.ts';
1
+ import { ShellParser } from './shell.ts';
2
2
  import type { ISimpleCommand } from './shell.ts';
3
3
 
4
4
  /** Programs that only read or print what they are given: their arguments are text to find or show, never a command to run. */
@@ -65,7 +65,7 @@ const PIPED_INTO_RUNNER =
65
65
 
66
66
  /** Whether a `gh` command is a request: its subcommand (the first word that is not an option or an option's value) is one of `GH_REQUESTS`. */
67
67
  const isGhRequest = (opts: { command: ISimpleCommand }): boolean => {
68
- const { args } = programOf({ command: opts.command });
68
+ const { args } = ShellParser.programOf({ command: opts.command });
69
69
  const subcommand = args.find(
70
70
  (word, index) =>
71
71
  !word.startsWith('-') && !(index > 0 && GH_REPOSITORY_FLAGS.has(args[index - 1] ?? '')),
@@ -74,48 +74,53 @@ const isGhRequest = (opts: { command: ISimpleCommand }): boolean => {
74
74
  return subcommand !== undefined && GH_REQUESTS.has(subcommand);
75
75
  };
76
76
 
77
- /**
78
- * Whether the arguments of a command are data. `withMessages` adds `git` and `gh` (their arguments are
79
- * messages to the write guards, but a `git` remote is a host to the remote-host guard).
80
- */
81
- export const isDataOnly = (opts: { command: ISimpleCommand; withMessages: boolean }): boolean => {
82
- const name = basenameOf({ word: programOf({ command: opts.command }).name });
77
+ export class CommandView {
78
+ /** The texts of the simple commands: the words, a bare name for data, a reader's heredoc body appended. */
79
+ private static textsOf(opts: { command: string; withMessages: boolean }): string[] {
80
+ return ShellParser.parse({ command: opts.command }).map((command) => {
81
+ const name = ShellParser.basenameOf({ word: ShellParser.programOf({ command }).name });
83
82
 
84
- if (name === 'find') {
85
- return !opts.command.words.some((word) => FIND_RUNS.has(word));
86
- }
83
+ if (CommandView.isDataOnly({ command, withMessages: opts.withMessages })) {
84
+ return name;
85
+ }
87
86
 
88
- if (name === 'gh' && isGhRequest({ command: opts.command })) {
89
- return false;
90
- }
87
+ const body =
88
+ command.heredoc !== undefined && HEREDOC_READERS.has(name) ? `\n${command.heredoc}` : '';
91
89
 
92
- return READ_ONLY_PROGRAMS.has(name) || (opts.withMessages && MESSAGE_PROGRAMS.has(name));
93
- };
94
-
95
- /** The texts of the simple commands: the words, a bare name for data, a reader's heredoc body appended. */
96
- const textsOf = (opts: { command: string; withMessages: boolean }): string[] =>
97
- parseShell({ command: opts.command }).map((command) => {
98
- const name = basenameOf({ word: programOf({ command }).name });
90
+ return `${command.words.join(' ')}${body}`;
91
+ });
92
+ }
99
93
 
100
- if (isDataOnly({ command, withMessages: opts.withMessages })) {
101
- return name;
94
+ /**
95
+ * Whether the arguments of a command are data. `withMessages` adds `git` and `gh` (their arguments are
96
+ * messages to the write guards, but a `git` remote is a host to the remote-host guard).
97
+ */
98
+ static isDataOnly(opts: { command: ISimpleCommand; withMessages: boolean }): boolean {
99
+ const name = ShellParser.basenameOf({
100
+ word: ShellParser.programOf({ command: opts.command }).name,
101
+ });
102
+
103
+ if (name === 'find') {
104
+ return !opts.command.words.some((word) => FIND_RUNS.has(word));
102
105
  }
103
106
 
104
- const body =
105
- command.heredoc !== undefined && HEREDOC_READERS.has(name) ? `\n${command.heredoc}` : '';
106
-
107
- return `${command.words.join(' ')}${body}`;
108
- });
107
+ if (name === 'gh' && isGhRequest({ command: opts.command })) {
108
+ return false;
109
+ }
109
110
 
110
- /**
111
- * What a command line runs, one text per simple command, for a guard that matches text: the words of each
112
- * command with the quotes resolved, nothing but the name for a command whose arguments are data
113
- * (`rg -n "kubectl apply" docs/`), and the body of a heredoc appended only where its reader runs it
114
- * (`psql <<EOF`). The body of `cat > f <<EOF` is data and is not here. A line that pipes into a program
115
- * that runs its input (`echo "kubectl apply -f x" | sh`) stands as one text, because what it prints is code.
116
- */
117
- export const commandTextsOf = (opts: { command: string; withMessages: boolean }): string[] => {
118
- const { text } = splitHeredocs({ command: opts.command });
111
+ return READ_ONLY_PROGRAMS.has(name) || (opts.withMessages && MESSAGE_PROGRAMS.has(name));
112
+ }
119
113
 
120
- return PIPED_INTO_RUNNER.test(text) ? [text] : textsOf(opts);
121
- };
114
+ /**
115
+ * What a command line runs, one text per simple command, for a guard that matches text: the words of each
116
+ * command with the quotes resolved, nothing but the name for a command whose arguments are data
117
+ * (`rg -n "kubectl apply" docs/`), and the body of a heredoc appended only where its reader runs it
118
+ * (`psql <<EOF`). The body of `cat > f <<EOF` is data and is not here. A line that pipes into a program
119
+ * that runs its input (`echo "kubectl apply -f x" | sh`) stands as one text, because what it prints is code.
120
+ */
121
+ static commandTextsOf(opts: { command: string; withMessages: boolean }): string[] {
122
+ const { text } = ShellParser.splitHeredocs({ command: opts.command });
123
+
124
+ return PIPED_INTO_RUNNER.test(text) ? [text] : CommandView.textsOf(opts);
125
+ }
126
+ }
@@ -78,9 +78,6 @@ export class HookConstants {
78
78
  '/tmp/claude-[0-9]*/*/*/scratchpad',
79
79
  '/tmp/claude-[0-9]*/*/*/scratchpad/**',
80
80
  ];
81
- /** Set to `off` to switch the guards off for a session; the hooks then pass every call. */
82
- static readonly KILL_SWITCH_ENV = 'VULCAN_GUARDS';
83
- static readonly KILL_SWITCH_OFF = 'off';
84
81
  /**
85
82
  * Tool-owned stores an agent may write into: package manager caches, the runtime dir for locks, the
86
83
  * agent tool's memory. Never a directory on PATH (`~/.bun/bin`) or a file git or a shell runs (`~/.gitconfig`).
@@ -3,7 +3,7 @@ import type { GuardDecisions, PackageVerdictKinds, TrustStates } from './constan
3
3
 
4
4
  export type TGuardDecision = TConstValue<typeof GuardDecisions>;
5
5
  export type TPackageVerdictKind = TConstValue<typeof PackageVerdictKinds>;
6
- export type TTrustState = TConstValue<typeof TrustStates>;
6
+ type TTrustState = TConstValue<typeof TrustStates>;
7
7
 
8
8
  /** Whether a listed trusted script may skip the script checks, and if not, why - in words an ask can show. */
9
9
  export interface IScriptTrust {
@@ -11,6 +11,20 @@ export interface IScriptTrust {
11
11
  reason: string;
12
12
  }
13
13
 
14
+ /** A script the project vouches for on some subcommands only: the first argument after the script is one of `readOnly`. */
15
+ export interface IReadOnlyScript {
16
+ script: string;
17
+ readOnly: string[];
18
+ }
19
+
20
+ /** One `bun x.ts` call as the shell sees it: the script word and the word right after it, if any. */
21
+ export interface IScriptInvocation {
22
+ script: string;
23
+ subcommand: string | undefined;
24
+ /** A `cd`, `pushd` or `popd` came before it in the line, so a relative script word is not from the hook's folder. */
25
+ moved: boolean;
26
+ }
27
+
14
28
  export interface IWriteCheck {
15
29
  rule: string;
16
30
  what: string;
@@ -1,7 +1,7 @@
1
1
  import { GuardDecisions, HookConstants } from './common/index.ts';
2
2
  import type { TGuardDecision } from './common/index.ts';
3
3
 
4
- export interface IDecisionOutput {
4
+ interface IDecisionOutput {
5
5
  hookSpecificOutput: {
6
6
  hookEventName: string;
7
7
  permissionDecision: string;
@@ -9,49 +9,45 @@ export interface IDecisionOutput {
9
9
  };
10
10
  }
11
11
 
12
- /**
13
- * The decision as every host that reads our hooks understands it. Claude Code and Cursor read
14
- * \`hookSpecificOutput\`; Copilot documents the same two fields at the top level, so they are written there
15
- * too (Claude Code ignores them: checked). Cursor does not enforce an \`ask\` on a tool call, so where it
16
- * says it is running the hook (\`CURSOR_PROJECT_DIR\`) an ask is a deny that says why.
17
- */
18
- export const forHost = (opts: {
19
- output: IDecisionOutput;
20
- env?: Record<string, string | undefined>;
21
- }) => {
22
- const specific = opts.output.hookSpecificOutput;
23
- const env = opts.env ?? process.env;
24
- const isCursorAsk =
25
- specific.permissionDecision === GuardDecisions.ASK &&
26
- env[HookConstants.CURSOR_PROJECT_DIR_ENV] !== undefined;
27
- const decision = isCursorAsk ? GuardDecisions.DENY : specific.permissionDecision;
28
- const reason = isCursorAsk
29
- ? `${specific.permissionDecisionReason}\n(Cursor cannot ask about a tool call: hand this to the owner)`
30
- : specific.permissionDecisionReason;
12
+ export class HookDecision {
13
+ /**
14
+ * The decision as every host that reads our hooks understands it. Claude Code and Cursor read
15
+ * \`hookSpecificOutput\`; Copilot documents the same two fields at the top level, so they are written there
16
+ * too (Claude Code ignores them: checked). Cursor does not enforce an \`ask\` on a tool call, so where it
17
+ * says it is running the hook (\`CURSOR_PROJECT_DIR\`) an ask is a deny that says why.
18
+ */
19
+ static forHost(opts: { output: IDecisionOutput; env?: Record<string, string | undefined> }) {
20
+ const specific = opts.output.hookSpecificOutput;
21
+ const env = opts.env ?? process.env;
22
+ const isCursorAsk =
23
+ specific.permissionDecision === GuardDecisions.ASK &&
24
+ env[HookConstants.CURSOR_PROJECT_DIR_ENV] !== undefined;
25
+ const decision = isCursorAsk ? GuardDecisions.DENY : specific.permissionDecision;
26
+ const reason = isCursorAsk
27
+ ? `${specific.permissionDecisionReason}\n(Cursor cannot ask about a tool call: hand this to the owner)`
28
+ : specific.permissionDecisionReason;
31
29
 
32
- return {
33
- hookSpecificOutput: {
34
- ...specific,
30
+ return {
31
+ hookSpecificOutput: {
32
+ ...specific,
33
+ permissionDecision: decision,
34
+ permissionDecisionReason: reason,
35
+ },
35
36
  permissionDecision: decision,
36
37
  permissionDecisionReason: reason,
37
- },
38
- permissionDecision: decision,
39
- permissionDecisionReason: reason,
40
- };
41
- };
38
+ };
39
+ }
42
40
 
43
- /** The PreToolUse answer Claude Code reads from stdout: the decision and why, shown to the human or to the model. */
44
- export const buildToolDecision = (opts: { decision: TGuardDecision; reason: string[] }) =>
45
- forHost({
46
- output: {
47
- hookSpecificOutput: {
48
- hookEventName: HookConstants.PRE_TOOL_USE,
49
- permissionDecision: opts.decision,
50
- permissionDecisionReason: opts.reason.join('\n'),
41
+ /** The PreToolUse answer Claude Code reads from stdout: the decision and why, shown to the human or to the model. */
42
+ static buildTool(opts: { decision: TGuardDecision; reason: string[] }) {
43
+ return HookDecision.forHost({
44
+ output: {
45
+ hookSpecificOutput: {
46
+ hookEventName: HookConstants.PRE_TOOL_USE,
47
+ permissionDecision: opts.decision,
48
+ permissionDecisionReason: opts.reason.join('\n'),
49
+ },
51
50
  },
52
- },
53
- });
54
-
55
- /** Whether the session switched the guards off (`VULCAN_GUARDS=off`): every call then passes. */
56
- export const guardsAreOff = (opts: { env?: Record<string, string | undefined> } = {}): boolean =>
57
- (opts.env ?? process.env)[HookConstants.KILL_SWITCH_ENV] === HookConstants.KILL_SWITCH_OFF;
51
+ });
52
+ }
53
+ }
@@ -1,12 +1,12 @@
1
1
  import { spawnSync } from 'node:child_process';
2
- import { basenameOf, parseShellChecked, programOf } from './shell.ts';
2
+ import { ShellParser } from './shell.ts';
3
3
  import type { ISimpleCommand } from './shell.ts';
4
4
  import { GuardDecisions, HookConstants } from './common/index.ts';
5
5
  import type { IGitHit, IGitRunner } from './common/index.ts';
6
- import { matchesBranch } from './project-guards.ts';
6
+ import { ProjectGuards } from './project-guards.ts';
7
7
 
8
8
  /** `git` and `gh` read-only queries the guard makes; `undefined` when the tool is missing, slow or fails. */
9
- export const runQuery: IGitRunner = (opts) => {
9
+ const runQuery: IGitRunner = (opts) => {
10
10
  const result = spawnSync(opts.program, opts.args, {
11
11
  cwd: opts.cwd,
12
12
  encoding: 'utf8',
@@ -104,7 +104,7 @@ const inspectPush = (opts: {
104
104
  for (const name of targets) {
105
105
  const branch = name.replace(/^\+/, '').replace(/^refs\/heads\//, '');
106
106
 
107
- if (matchesBranch({ name: branch, patterns: opts.askPush })) {
107
+ if (ProjectGuards.matchesBranch({ name: branch, patterns: opts.askPush })) {
108
108
  hits.push({
109
109
  decision: GuardDecisions.ASK,
110
110
  rule: 'V-W-06',
@@ -387,8 +387,8 @@ const inspectOne = (opts: {
387
387
  run: IGitRunner;
388
388
  askPush: string[];
389
389
  }): IGitHit[] => {
390
- const program = programOf({ command: opts.command });
391
- const name = basenameOf({ word: program.name });
390
+ const program = ShellParser.programOf({ command: opts.command });
391
+ const name = ShellParser.basenameOf({ word: program.name });
392
392
 
393
393
  if (name === 'gh') {
394
394
  return [
@@ -441,53 +441,55 @@ const inspectOne = (opts: {
441
441
  return [];
442
442
  };
443
443
 
444
- /** Every reason `command` is a git or gh action that loses history or a protected branch. */
445
- export const inspectGit = (opts: {
446
- command: string;
447
- cwd: string | undefined;
448
- run?: IGitRunner;
449
- /** Branches (names, `*` allowed) a plain `git push` asks about: `guard.git.askPush`. */
450
- askPush?: string[];
451
- }): IGitHit[] => {
452
- const parsed = parseShellChecked({ command: opts.command });
453
- const run = opts.run ?? runQuery;
454
- let queries = 0;
455
- let isCapped = false;
456
-
457
- // Every query is a process and can take seconds: a line may make a few, and asks past them.
458
- const limited: IGitRunner = (call) => {
459
- queries += 1;
444
+ export class GitGuard {
445
+ /** Every reason `command` is a git or gh action that loses history or a protected branch. */
446
+ static inspect(opts: {
447
+ command: string;
448
+ cwd: string | undefined;
449
+ run?: IGitRunner;
450
+ /** Branches (names, `*` allowed) a plain `git push` asks about: `guard.git.askPush`. */
451
+ askPush?: string[];
452
+ }): IGitHit[] {
453
+ const parsed = ShellParser.parseChecked({ command: opts.command });
454
+ const run = opts.run ?? runQuery;
455
+ let queries = 0;
456
+ let isCapped = false;
457
+
458
+ // Every query is a process and can take seconds: a line may make a few, and asks past them.
459
+ const limited: IGitRunner = (call) => {
460
+ queries += 1;
461
+
462
+ if (queries > HookConstants.MAX_QUERIES) {
463
+ isCapped = true;
464
+
465
+ return undefined;
466
+ }
460
467
 
461
- if (queries > HookConstants.MAX_QUERIES) {
462
- isCapped = true;
468
+ return run(call);
469
+ };
470
+ const hits = parsed.commands.flatMap((command) =>
471
+ inspectOne({ command, cwd: opts.cwd, run: limited, askPush: opts.askPush ?? [] }),
472
+ );
463
473
 
464
- return undefined;
474
+ // Part of the line was not read: never an allow.
475
+ if (parsed.isOverBudget) {
476
+ hits.push({
477
+ decision: GuardDecisions.ASK,
478
+ rule: 'V-W-06',
479
+ message:
480
+ 'this command line is larger, or nests deeper, than the guard reads, so it could not be checked',
481
+ });
465
482
  }
466
483
 
467
- return run(call);
468
- };
469
- const hits = parsed.commands.flatMap((command) =>
470
- inspectOne({ command, cwd: opts.cwd, run: limited, askPush: opts.askPush ?? [] }),
471
- );
472
-
473
- // Part of the line was not read: never an allow.
474
- if (parsed.isOverBudget) {
475
- hits.push({
476
- decision: GuardDecisions.ASK,
477
- rule: 'V-W-06',
478
- message:
479
- 'this command line is larger, or nests deeper, than the guard reads, so it could not be checked',
480
- });
481
- }
484
+ if (isCapped) {
485
+ hits.push({
486
+ decision: GuardDecisions.ASK,
487
+ rule: 'V-W-06',
488
+ message:
489
+ 'this command line needs more git or gh queries than the guard runs, so part of it could not be checked',
490
+ });
491
+ }
482
492
 
483
- if (isCapped) {
484
- hits.push({
485
- decision: GuardDecisions.ASK,
486
- rule: 'V-W-06',
487
- message:
488
- 'this command line needs more git or gh queries than the guard runs, so part of it could not be checked',
489
- });
493
+ return hits;
490
494
  }
491
-
492
- return hits;
493
- };
495
+ }
@@ -1,7 +1,7 @@
1
1
  import { isAbsolute, join, normalize } from 'node:path';
2
2
  import { GuardDecisions, HookConstants } from './common/index.ts';
3
3
  import type { IManifestHookInput } from './common/index.ts';
4
- import { forHost } from './decision.ts';
4
+ import { HookDecision } from './decision.ts';
5
5
 
6
6
  /** The shell tool under the names the hosts give it: Cursor's `Shell`, and a lower-case `bash`. */
7
7
  const SHELL_NAMES = new Set(['Shell', 'shell', 'bash']);
@@ -41,66 +41,69 @@ const toolOf = (opts: { value: unknown }): string | undefined => {
41
41
  return name !== undefined && SHELL_NAMES.has(name) ? BASH_TOOL : name;
42
42
  };
43
43
 
44
- /** The tool call from the hook's JSON; `undefined` when it is not what Claude Code sends. */
45
- export const parseManifestHookInput = (opts: { text: string }): IManifestHookInput | undefined => {
46
- let payload: unknown;
47
-
48
- try {
49
- payload = JSON.parse(opts.text);
50
- } catch (error) {
51
- console.error(
52
- `[parseManifestHookInput] unreadable hook input - letting the call through | ${error instanceof Error ? error.message : String(error)}`,
53
- );
54
-
55
- return undefined;
44
+ export class ManifestGuard {
45
+ /** The tool call from the hook's JSON; `undefined` when it is not what Claude Code sends. */
46
+ static parseHookInput(opts: { text: string }): IManifestHookInput | undefined {
47
+ let payload: unknown;
48
+
49
+ try {
50
+ payload = JSON.parse(opts.text);
51
+ } catch (error) {
52
+ console.error(
53
+ `[ManifestGuard.parseHookInput] unreadable hook input - letting the call through | ${error instanceof Error ? error.message : String(error)}`,
54
+ );
55
+
56
+ return undefined;
57
+ }
58
+
59
+ const holder = { value: payload };
60
+
61
+ if (!isRecord(holder)) {
62
+ return undefined;
63
+ }
64
+
65
+ // The wire names are snake_case; they stay behind string-literal access here, at the boundary (V-C-14).
66
+ const toolInput = { value: holder.value['tool_input'] };
67
+ const input = isRecord(toolInput) ? toolInput.value : {};
68
+ const tool = toolOf({ value: holder.value['tool_name'] });
69
+
70
+ return tool === undefined
71
+ ? undefined
72
+ : {
73
+ tool,
74
+ filePath:
75
+ toText({ value: input['file_path'] }) ?? toText({ value: input['notebook_path'] }),
76
+ command: toText({ value: input['command'] }),
77
+ cwd: toText({ value: holder.value['cwd'] }),
78
+ };
56
79
  }
57
80
 
58
- const holder = { value: payload };
81
+ /** Whether this tool call writes `.agents/vulcan.manifest.json` - which only `vulcan sync` may do. */
82
+ static inspectWrite(opts: { input: IManifestHookInput }): boolean {
83
+ const { tool, filePath, command, cwd } = opts.input;
59
84
 
60
- if (!isRecord(holder)) {
61
- return undefined;
62
- }
63
-
64
- // The wire names are snake_case; they stay behind string-literal access here, at the boundary (V-C-14).
65
- const toolInput = { value: holder.value['tool_input'] };
66
- const input = isRecord(toolInput) ? toolInput.value : {};
67
- const tool = toolOf({ value: holder.value['tool_name'] });
68
-
69
- return tool === undefined
70
- ? undefined
71
- : {
72
- tool,
73
- filePath:
74
- toText({ value: input['file_path'] }) ?? toText({ value: input['notebook_path'] }),
75
- command: toText({ value: input['command'] }),
76
- cwd: toText({ value: holder.value['cwd'] }),
77
- };
78
- };
85
+ if (tool === BASH_TOOL) {
86
+ return command !== undefined && WRITE_PATTERNS.some((pattern) => pattern.test(command));
87
+ }
79
88
 
80
- /** Whether this tool call writes `.agents/vulcan.manifest.json` - which only `vulcan sync` may do. */
81
- export const inspectManifestWrite = (opts: { input: IManifestHookInput }): boolean => {
82
- const { tool, filePath, command, cwd } = opts.input;
89
+ if (filePath === undefined) {
90
+ return false;
91
+ }
83
92
 
84
- if (tool === BASH_TOOL) {
85
- return command !== undefined && WRITE_PATTERNS.some((pattern) => pattern.test(command));
86
- }
93
+ const absolute = isAbsolute(filePath) ? filePath : join(cwd ?? process.cwd(), filePath);
87
94
 
88
- if (filePath === undefined) {
89
- return false;
95
+ return normalize(absolute).endsWith(MANIFEST_SUFFIX);
90
96
  }
91
97
 
92
- const absolute = isAbsolute(filePath) ? filePath : join(cwd ?? process.cwd(), filePath);
93
-
94
- return normalize(absolute).endsWith(MANIFEST_SUFFIX);
95
- };
96
-
97
- export const buildManifestDecision = () =>
98
- forHost({
99
- output: {
100
- hookSpecificOutput: {
101
- hookEventName: HookConstants.PRE_TOOL_USE,
102
- permissionDecision: GuardDecisions.DENY,
103
- permissionDecisionReason: MANIFEST_BLOCK_MESSAGE,
98
+ static buildDecision() {
99
+ return HookDecision.forHost({
100
+ output: {
101
+ hookSpecificOutput: {
102
+ hookEventName: HookConstants.PRE_TOOL_USE,
103
+ permissionDecision: GuardDecisions.DENY,
104
+ permissionDecisionReason: MANIFEST_BLOCK_MESSAGE,
105
+ },
104
106
  },
105
- },
106
- });
107
+ });
108
+ }
109
+ }