@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.
- package/base/extensions/vulcan-guards.ts +48 -41
- package/base/hooks/antigravity-guards.ts +4 -3
- package/base/hooks/codex-guards.ts +17 -6
- package/base/hooks/guard-git.ts +8 -8
- package/base/hooks/guard-manifest.ts +5 -5
- package/base/hooks/guard-outside.ts +8 -8
- package/base/hooks/guard-package.ts +6 -6
- package/base/hooks/guard-remote-hosts.ts +14 -9
- package/base/hooks/guard-scripting.ts +6 -6
- package/base/hooks/guard-writes.ts +20 -11
- package/base/hooks/post-tool.ts +4 -3
- package/base/hooks/prompt-submit.ts +4 -3
- package/base/hooks/session-start.ts +5 -3
- package/base/hooks/stop.ts +4 -3
- package/base/hooks/subagent-start.ts +2 -2
- package/base/make/vulcan.mk +1 -4
- package/base/skills/build-a-feature/SKILL.md +1 -1
- package/base/skills/docs-update/SKILL.md +11 -5
- package/base/skills/docs-update/evals/evals.json +1 -1
- package/base/skills/docs-writing/SKILL.md +1 -1
- package/base/skills/plan-a-change/references/spec-card.md +1 -1
- package/base/skills/ship/SKILL.md +1 -1
- package/base/skills/visualize-work/SKILL.md +29 -6
- package/base/skills/visualize-work/references/spec.md +16 -5
- package/package.json +5 -6
- package/src/agents/atlas-block.ts +43 -43
- package/src/agents/codex-hooks.ts +55 -52
- package/src/agents/common/types.ts +1 -1
- package/src/agents/detect.ts +19 -16
- package/src/agents/exclude.ts +97 -98
- package/src/agents/hooks-json.ts +41 -43
- package/src/agents/local.ts +46 -43
- package/src/agents/prompt.ts +45 -42
- package/src/agents/render.ts +203 -201
- package/src/agents/resolve.ts +133 -134
- package/src/agents/table.ts +12 -8
- package/src/cli.ts +3 -1
- 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 +6 -4
- package/src/commands/help.command.ts +11 -9
- package/src/commands/init.command.ts +14 -8
- package/src/commands/preset.command.ts +2 -2
- package/src/commands/profile.command.ts +43 -50
- package/src/commands/sync.command.ts +109 -111
- package/src/commands/upgrade.command.ts +85 -78
- package/src/commands/visualize.command.ts +20 -5
- package/src/commands/x.command.ts +55 -50
- package/src/common/format.ts +23 -21
- package/src/common/index.ts +2 -0
- package/src/common/json.ts +8 -5
- package/src/common/layout-folder.ts +96 -111
- package/src/common/paths.ts +14 -12
- package/src/common/record.ts +7 -0
- package/src/common/text.ts +7 -0
- package/src/config/common/constants.ts +13 -1
- package/src/config/common/types.ts +8 -1
- package/src/config/loader.ts +53 -48
- package/src/config/packages.ts +17 -11
- package/src/config/schema.ts +54 -7
- package/src/create/add-app.ts +604 -493
- package/src/create/add-lib.ts +249 -242
- package/src/create/bunfig.ts +26 -23
- package/src/create/checks.ts +36 -34
- package/src/create/common/constants.ts +1 -0
- package/src/create/common/failure.ts +10 -0
- package/src/create/common/index.ts +2 -0
- package/src/create/common/preset-path.ts +11 -0
- package/src/create/common/types.ts +7 -2
- 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 +78 -80
- package/src/create/lib-preset.ts +62 -61
- package/src/create/manifest-json.ts +10 -4
- package/src/create/names.ts +217 -210
- package/src/create/next.ts +27 -24
- package/src/create/plan.ts +15 -12
- package/src/create/preset-diff.ts +415 -240
- package/src/create/preset-menu.ts +40 -34
- package/src/create/preset.ts +207 -194
- package/src/create/process.ts +80 -71
- package/src/create/scratch.ts +49 -48
- package/src/create/workspace.ts +423 -398
- package/src/doctor/checks.ts +1069 -998
- package/src/doctor/makefile.ts +17 -13
- package/src/doctor/runner.ts +88 -116
- package/src/doctor/skills.ts +97 -95
- package/src/doctor/tags.ts +44 -41
- package/src/hooks/codex-patch.ts +27 -24
- package/src/hooks/command-view.ts +44 -39
- package/src/hooks/common/constants.ts +0 -3
- package/src/hooks/common/types.ts +15 -1
- package/src/hooks/decision.ts +38 -42
- package/src/hooks/guard-git.ts +52 -50
- package/src/hooks/guard-manifest.ts +58 -55
- package/src/hooks/guard-outside.ts +109 -88
- package/src/hooks/guard-package.ts +86 -77
- package/src/hooks/guard-scripting.ts +20 -15
- package/src/hooks/guard-writes.ts +169 -111
- package/src/hooks/owner-reply.ts +128 -128
- package/src/hooks/post-tool.ts +94 -93
- package/src/hooks/project-guards.ts +93 -55
- package/src/hooks/project-tmp.ts +27 -24
- package/src/hooks/remote-hosts.ts +157 -149
- package/src/hooks/session-digest.ts +99 -95
- package/src/hooks/shell.ts +519 -500
- package/src/hooks/subagent-card.ts +11 -7
- package/src/hooks/trusted-scripts.ts +158 -80
- package/src/init/common/types.ts +1 -1
- package/src/init/scaffold.ts +137 -134
- package/src/local/clean.ts +39 -37
- package/src/local/format.ts +21 -17
- package/src/local/scan.ts +146 -140
- package/src/manifest/render.ts +127 -112
- package/src/owner/card.ts +51 -46
- package/src/owner/profile.ts +100 -96
- package/src/owner/reply-switch.ts +9 -6
- package/src/owner/shape.ts +72 -70
- package/src/owner/survey.ts +175 -164
- package/src/owner/view.ts +62 -59
- package/src/owner/violations.ts +119 -123
- package/src/router.ts +4 -1
- package/src/rules/base.ts +15 -11
- package/src/rules/common/types.ts +1 -1
- 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 +36 -33
- package/src/signals/loop.ts +39 -37
- package/src/signals/state.ts +80 -85
- package/src/skills/frontmatter.ts +28 -28
- package/src/sync/agent-files.ts +217 -199
- package/src/sync/agent-removal.ts +62 -68
- package/src/sync/atlas-block.ts +45 -43
- package/src/sync/base-rules.ts +32 -30
- package/src/sync/claude-launch.ts +74 -37
- package/src/sync/common/constants.ts +4 -0
- package/src/sync/common/index.ts +1 -0
- package/src/sync/common/symlink.ts +9 -0
- package/src/sync/common/types.ts +2 -2
- package/src/sync/exclude.ts +77 -69
- package/src/sync/local-choice.ts +50 -47
- package/src/sync/planner.ts +64 -68
- package/src/sync/prune.ts +52 -48
- package/src/sync/settings.ts +167 -168
- package/src/ui/capability.ts +12 -7
- package/src/ui/keyboard.ts +35 -33
- package/src/ui/prompt.ts +81 -77
- package/src/visualize/assets.ts +379 -195
- package/src/visualize/charts.ts +188 -176
- package/src/visualize/compare-css.ts +31 -0
- package/src/visualize/compare-render.ts +196 -0
- package/src/visualize/compare-schema.ts +81 -0
- package/src/visualize/compare-validate.ts +126 -0
- package/src/visualize/constants.ts +29 -3
- package/src/visualize/diagrams.ts +189 -174
- package/src/visualize/gate.ts +136 -0
- package/src/visualize/grid-span.ts +34 -0
- package/src/visualize/icons.ts +9 -4
- package/src/visualize/index.ts +2 -0
- package/src/visualize/kinds-css.ts +54 -0
- package/src/visualize/kinds-render.ts +698 -0
- package/src/visualize/kinds-schema.ts +148 -0
- package/src/visualize/kinds-validate.ts +186 -0
- package/src/visualize/labels-vi.ts +109 -0
- package/src/visualize/labels.ts +53 -0
- package/src/visualize/layout.ts +112 -92
- package/src/visualize/page.ts +140 -114
- package/src/visualize/render.ts +158 -114
- package/src/visualize/schema.ts +21 -1
- package/src/visualize/sections.ts +401 -309
- package/src/visualize/sources.ts +270 -0
- package/src/visualize/theme.ts +474 -0
- package/src/visualize/validate.ts +15 -5
- package/src/wiki/anchors.ts +39 -37
- package/src/wiki/command.ts +4 -4
- package/src/wiki/source-links.ts +49 -49
|
@@ -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
|
+
}
|
|
@@ -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
|
-
|
|
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;
|
package/src/hooks/decision.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
}
|
|
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
|
+
}
|
package/src/hooks/guard-git.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
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) => {
|
|
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
|
-
|
|
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
|
+
}
|