@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.
- package/base/extensions/vulcan-guards.ts +48 -41
- package/base/hooks/antigravity-guards.ts +2 -2
- package/base/hooks/codex-guards.ts +15 -5
- package/base/hooks/guard-git.ts +8 -8
- package/base/hooks/guard-manifest.ts +4 -5
- package/base/hooks/guard-outside.ts +8 -8
- package/base/hooks/guard-package.ts +5 -6
- package/base/hooks/guard-remote-hosts.ts +6 -7
- package/base/hooks/guard-scripting.ts +5 -6
- package/base/hooks/guard-writes.ts +8 -9
- package/base/hooks/post-tool.ts +2 -2
- package/base/hooks/prompt-submit.ts +2 -2
- package/base/hooks/session-start.ts +3 -3
- package/base/hooks/stop.ts +2 -2
- package/base/hooks/subagent-start.ts +2 -2
- package/base/skills/docs-update/SKILL.md +4 -2
- package/base/skills/visualize-work/SKILL.md +9 -0
- package/package.json +3 -3
- package/src/agents/atlas-block.ts +43 -43
- package/src/agents/codex-hooks.ts +45 -43
- package/src/agents/detect.ts +19 -16
- package/src/agents/exclude.ts +96 -97
- package/src/agents/hooks-json.ts +38 -36
- package/src/agents/local.ts +46 -43
- package/src/agents/prompt.ts +45 -42
- package/src/agents/render.ts +201 -195
- package/src/agents/resolve.ts +133 -134
- package/src/agents/table.ts +12 -8
- package/src/commands/add.command.ts +2 -2
- package/src/commands/agents.command.ts +11 -17
- package/src/commands/clean.command.ts +6 -6
- package/src/commands/doctor.command.ts +4 -4
- package/src/commands/init.command.ts +12 -8
- package/src/commands/preset.command.ts +2 -2
- package/src/commands/profile.command.ts +42 -49
- package/src/commands/sync.command.ts +109 -111
- package/src/commands/upgrade.command.ts +80 -75
- package/src/commands/visualize.command.ts +7 -13
- package/src/commands/x.command.ts +55 -50
- package/src/common/format.ts +23 -21
- package/src/common/json.ts +8 -5
- package/src/common/layout-folder.ts +94 -91
- package/src/common/paths.ts +14 -12
- package/src/config/loader.ts +52 -49
- package/src/config/packages.ts +14 -11
- package/src/config/schema.ts +3 -3
- package/src/create/add-app.ts +519 -509
- package/src/create/add-lib.ts +237 -240
- package/src/create/bunfig.ts +26 -23
- package/src/create/checks.ts +36 -34
- package/src/create/diff.ts +21 -23
- package/src/create/dockerignore.ts +26 -24
- package/src/create/files.ts +7 -5
- package/src/create/init-monorepo.ts +75 -80
- package/src/create/lib-preset.ts +59 -63
- package/src/create/manifest-json.ts +10 -4
- package/src/create/names.ts +217 -210
- package/src/create/next.ts +26 -23
- package/src/create/plan.ts +15 -12
- package/src/create/preset-diff.ts +301 -303
- package/src/create/preset-menu.ts +38 -32
- package/src/create/preset.ts +202 -197
- package/src/create/process.ts +79 -72
- package/src/create/scratch.ts +48 -49
- package/src/create/workspace.ts +404 -396
- package/src/doctor/checks.ts +1027 -1014
- package/src/doctor/makefile.ts +17 -13
- package/src/doctor/runner.ts +88 -118
- package/src/doctor/skills.ts +97 -95
- package/src/doctor/tags.ts +42 -37
- package/src/hooks/codex-patch.ts +25 -22
- package/src/hooks/command-view.ts +44 -39
- package/src/hooks/decision.ts +37 -37
- package/src/hooks/guard-git.ts +51 -49
- package/src/hooks/guard-manifest.ts +58 -55
- package/src/hooks/guard-outside.ts +93 -91
- package/src/hooks/guard-package.ts +82 -79
- package/src/hooks/guard-scripting.ts +19 -14
- package/src/hooks/guard-writes.ts +154 -149
- package/src/hooks/owner-reply.ts +127 -127
- package/src/hooks/post-tool.ts +94 -93
- package/src/hooks/project-guards.ts +65 -62
- package/src/hooks/project-tmp.ts +27 -24
- package/src/hooks/remote-hosts.ts +153 -130
- package/src/hooks/session-digest.ts +98 -101
- package/src/hooks/shell.ts +509 -499
- package/src/hooks/subagent-card.ts +11 -7
- package/src/hooks/trusted-scripts.ts +106 -104
- package/src/init/scaffold.ts +135 -132
- package/src/local/clean.ts +38 -36
- package/src/local/format.ts +21 -17
- package/src/local/scan.ts +144 -138
- package/src/manifest/render.ts +110 -104
- package/src/owner/card.ts +51 -46
- package/src/owner/profile.ts +99 -93
- package/src/owner/reply-switch.ts +9 -6
- package/src/owner/shape.ts +71 -69
- package/src/owner/survey.ts +173 -171
- package/src/owner/view.ts +62 -59
- package/src/owner/violations.ts +119 -123
- package/src/rules/base.ts +15 -11
- package/src/rules/parser.ts +39 -32
- package/src/rules/slots.ts +8 -6
- package/src/signals/claims.ts +30 -28
- package/src/signals/classify.ts +38 -33
- package/src/signals/loop.ts +39 -37
- package/src/signals/state.ts +79 -81
- package/src/skills/frontmatter.ts +28 -28
- package/src/sync/agent-files.ts +217 -199
- package/src/sync/agent-removal.ts +56 -59
- package/src/sync/atlas-block.ts +45 -43
- package/src/sync/base-rules.ts +32 -30
- package/src/sync/claude-launch.ts +36 -34
- package/src/sync/exclude.ts +77 -69
- package/src/sync/local-choice.ts +50 -47
- package/src/sync/planner.ts +59 -61
- package/src/sync/prune.ts +52 -48
- package/src/sync/settings.ts +166 -167
- package/src/ui/capability.ts +12 -7
- package/src/ui/keyboard.ts +38 -38
- package/src/ui/prompt.ts +79 -77
- package/src/visualize/assets.ts +33 -24
- package/src/visualize/charts.ts +179 -176
- package/src/visualize/compare-css.ts +3 -2
- package/src/visualize/compare-render.ts +9 -7
- package/src/visualize/diagrams.ts +189 -174
- package/src/visualize/grid-span.ts +34 -0
- package/src/visualize/icons.ts +7 -5
- package/src/visualize/kinds-render.ts +50 -45
- package/src/visualize/kinds-validate.ts +12 -10
- package/src/visualize/labels.ts +21 -17
- package/src/visualize/layout.ts +112 -97
- package/src/visualize/page.ts +92 -104
- package/src/visualize/render.ts +143 -140
- package/src/visualize/sections.ts +395 -384
- package/src/visualize/sources.ts +2 -2
- package/src/visualize/theme.ts +12 -10
- package/src/visualize/validate.ts +13 -9
- package/src/wiki/anchors.ts +38 -36
- package/src/wiki/command.ts +4 -4
- package/src/wiki/source-links.ts +46 -44
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
83
|
+
if (CommandView.isDataOnly({ command, withMessages: opts.withMessages })) {
|
|
84
|
+
return name;
|
|
85
|
+
}
|
|
87
86
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
87
|
+
const body =
|
|
88
|
+
command.heredoc !== undefined && HEREDOC_READERS.has(name) ? `\n${command.heredoc}` : '';
|
|
91
89
|
|
|
92
|
-
|
|
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
|
-
|
|
101
|
-
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
return `${command.words.join(' ')}${body}`;
|
|
108
|
-
});
|
|
107
|
+
if (name === 'gh' && isGhRequest({ command: opts.command })) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
109
110
|
|
|
110
|
-
|
|
111
|
-
|
|
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
|
-
|
|
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
|
+
}
|
package/src/hooks/decision.ts
CHANGED
|
@@ -9,45 +9,45 @@ interface IDecisionOutput {
|
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
output: IDecisionOutput;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
return {
|
|
31
|
+
hookSpecificOutput: {
|
|
32
|
+
...specific,
|
|
33
|
+
permissionDecision: decision,
|
|
34
|
+
permissionDecisionReason: reason,
|
|
35
|
+
},
|
|
35
36
|
permissionDecision: decision,
|
|
36
37
|
permissionDecisionReason: reason,
|
|
37
|
-
}
|
|
38
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
package/src/hooks/guard-git.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { spawnSync } from 'node:child_process';
|
|
2
|
-
import {
|
|
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 {
|
|
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
9
|
const runQuery: IGitRunner = (opts) => {
|
|
@@ -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
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
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
|
-
|
|
462
|
-
|
|
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
|
-
|
|
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
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
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
|
-
|
|
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 {
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
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
|
-
|
|
61
|
-
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
89
|
+
if (filePath === undefined) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
83
92
|
|
|
84
|
-
|
|
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
|
-
|
|
89
|
-
return false;
|
|
95
|
+
return normalize(absolute).endsWith(MANIFEST_SUFFIX);
|
|
90
96
|
}
|
|
91
97
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
+
}
|