@venizia/vulcan 0.4.4 → 0.4.6
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/LICENSE.md +1 -1
- package/README.md +13 -0
- package/base/agents.json +22 -1
- package/base/checks/wiki-anchors.ts +8 -0
- package/base/checks/wiki-source-links.ts +8 -0
- package/base/claude/remote-hosts.json +1 -1
- package/base/claude/settings.json +12 -12
- package/base/extensions/vulcan-guards.ts +301 -0
- package/base/hooks/antigravity-guards.ts +68 -0
- package/base/hooks/codex-guards.ts +66 -0
- package/base/hooks/guard-git.ts +38 -9
- package/base/hooks/guard-outside.ts +29 -9
- package/base/hooks/guard-writes.ts +29 -1
- package/base/hooks/session-start.ts +14 -4
- package/base/make/vulcan.mk +12 -1
- package/base/references/delegation-brief.md +5 -4
- package/base/rules.md +2 -2
- package/base/skills/docs-writing/SKILL.md +1 -1
- package/base/skills/docs-writing/references/agent-documents.md +1 -1
- package/base/skills/knowledge-sync/SKILL.md +1 -1
- package/base/skills/plan-a-change/SKILL.md +1 -1
- package/base/skills/report-back/SKILL.md +1 -1
- package/base/skills/retro/SKILL.md +1 -1
- package/base/skills/review-a-change/SKILL.md +1 -1
- package/base/skills/ship/SKILL.md +1 -1
- package/base/skills/visualize-work/SKILL.md +33 -11
- package/base/skills/visualize-work/references/spec.md +77 -12
- package/package.json +4 -4
- package/src/agents/codex-hooks.ts +133 -0
- package/src/agents/common/constants.ts +54 -0
- package/src/agents/common/schema.ts +10 -1
- package/src/agents/common/types.ts +3 -1
- package/src/agents/exclude.ts +4 -0
- package/src/agents/hooks-json.ts +111 -0
- package/src/agents/index.ts +2 -0
- package/src/agents/render.ts +5 -4
- package/src/agents/resolve.ts +24 -9
- package/src/config/common/constants.ts +12 -0
- package/src/config/common/types.ts +2 -1
- package/src/config/packages.ts +2 -1
- package/src/config/schema.ts +84 -5
- package/src/create/add-app.ts +2 -2
- package/src/create/add-lib.ts +21 -8
- package/src/create/common/constants.ts +12 -0
- package/src/create/common/types.ts +2 -1
- package/src/create/preset-diff.ts +4 -2
- package/src/create/workspace.ts +13 -9
- package/src/doctor/checks.ts +71 -1
- package/src/doctor/common/constants.ts +2 -0
- package/src/doctor/runner.ts +6 -0
- package/src/hooks/codex-patch.ts +47 -0
- package/src/hooks/command-view.ts +97 -0
- package/src/hooks/common/constants.ts +46 -0
- package/src/hooks/common/types.ts +9 -1
- package/src/hooks/decision.ts +50 -8
- package/src/hooks/guard-git.ts +64 -5
- package/src/hooks/guard-manifest.ts +22 -8
- package/src/hooks/guard-outside.ts +38 -6
- package/src/hooks/guard-package.ts +15 -12
- package/src/hooks/guard-writes.ts +72 -21
- package/src/hooks/index.ts +5 -0
- package/src/hooks/project-guards.ts +123 -0
- package/src/hooks/project-tmp.ts +36 -0
- package/src/hooks/remote-hosts.ts +38 -14
- package/src/hooks/session-digest.ts +5 -0
- package/src/hooks/shell.ts +665 -35
- package/src/hooks/trusted-scripts.ts +134 -0
- package/src/manifest/render.ts +38 -0
- package/src/sync/agent-files.ts +122 -4
- package/src/sync/agent-removal.ts +118 -4
- package/src/sync/claude-launch.ts +48 -0
- package/src/sync/index.ts +1 -0
- package/src/sync/local-choice.ts +2 -0
- package/src/visualize/assets.ts +195 -54
- package/src/visualize/charts.ts +235 -0
- package/src/visualize/constants.ts +122 -1
- package/src/visualize/diagrams.ts +224 -0
- package/src/visualize/icons.ts +28 -0
- package/src/visualize/layout.ts +58 -8
- package/src/visualize/page.ts +151 -145
- package/src/visualize/schema.ts +252 -2
- package/src/visualize/sections.ts +370 -0
- package/src/visualize/validate.ts +100 -7
- package/src/wiki/anchors.ts +118 -0
- package/src/wiki/command.ts +110 -0
- package/src/wiki/constants.ts +30 -0
- package/src/wiki/index.ts +4 -0
- package/src/wiki/source-links.ts +186 -0
package/LICENSE.md
CHANGED
package/README.md
CHANGED
|
@@ -74,3 +74,16 @@ not re-registered) · `adapters` (sync is current, no hand-written `CLAUDE.md`,
|
|
|
74
74
|
The session-start digest prints the base write boundaries, the slot choices, the project's own rules (bold `| **W-00** |` rows and `| V-W-02, V-W-03 |` rows that elaborate base rules), the project's `<!-- minimap-shape:start -->` ... `<!-- minimap-shape:end -->` block from `.agents/rules.md` verbatim, and the `digest.oftenDropped` rules.
|
|
75
75
|
|
|
76
76
|
MIT licensed - see [LICENSE.md](LICENSE.md).
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
<p align="center">
|
|
81
|
+
<a href="https://venizia.ai">
|
|
82
|
+
<picture>
|
|
83
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://venizia.ai/assets/logo-white.svg">
|
|
84
|
+
<img src="https://venizia.ai/assets/logo.svg" alt="VENIZIA" height="28">
|
|
85
|
+
</picture>
|
|
86
|
+
</a>
|
|
87
|
+
<br>
|
|
88
|
+
<sub>VULCAN is built and maintained by <a href="https://venizia.ai">VENIZIA</a>.</sub>
|
|
89
|
+
</p>
|
package/base/agents.json
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"skills": {
|
|
23
23
|
"dir": ".claude/skills"
|
|
24
24
|
},
|
|
25
|
+
"guards": null,
|
|
25
26
|
"instructionsSurfaced": true,
|
|
26
27
|
"notes": []
|
|
27
28
|
},
|
|
@@ -45,6 +46,10 @@
|
|
|
45
46
|
"skills": {
|
|
46
47
|
"dir": ".agents/skills"
|
|
47
48
|
},
|
|
49
|
+
"guards": {
|
|
50
|
+
"kind": "extension",
|
|
51
|
+
"path": ".omp/hooks/pre/vulcan-guards.ts"
|
|
52
|
+
},
|
|
48
53
|
"instructionsSurfaced": true,
|
|
49
54
|
"notes": []
|
|
50
55
|
},
|
|
@@ -68,9 +73,14 @@
|
|
|
68
73
|
"skills": {
|
|
69
74
|
"dir": ".agents/skills"
|
|
70
75
|
},
|
|
76
|
+
"guards": {
|
|
77
|
+
"kind": "codex-hooks",
|
|
78
|
+
"path": ".codex/hooks.json"
|
|
79
|
+
},
|
|
71
80
|
"instructionsSurfaced": true,
|
|
72
81
|
"notes": [
|
|
73
|
-
"Codex loads .codex/config.toml only for trusted projects: trust this project in Codex."
|
|
82
|
+
"Codex loads .codex/config.toml only for trusted projects: trust this project in Codex.",
|
|
83
|
+
"Codex runs the guard hook of .codex/hooks.json only after you review and trust it in /hooks."
|
|
74
84
|
]
|
|
75
85
|
},
|
|
76
86
|
{
|
|
@@ -93,6 +103,7 @@
|
|
|
93
103
|
"skills": {
|
|
94
104
|
"dir": ".agents/skills"
|
|
95
105
|
},
|
|
106
|
+
"guards": null,
|
|
96
107
|
"instructionsSurfaced": null,
|
|
97
108
|
"notes": []
|
|
98
109
|
},
|
|
@@ -116,6 +127,7 @@
|
|
|
116
127
|
"skills": {
|
|
117
128
|
"dir": ".agents/skills"
|
|
118
129
|
},
|
|
130
|
+
"guards": null,
|
|
119
131
|
"instructionsSurfaced": null,
|
|
120
132
|
"notes": []
|
|
121
133
|
},
|
|
@@ -139,6 +151,7 @@
|
|
|
139
151
|
"skills": {
|
|
140
152
|
"dir": ".agents/skills"
|
|
141
153
|
},
|
|
154
|
+
"guards": null,
|
|
142
155
|
"instructionsSurfaced": null,
|
|
143
156
|
"notes": []
|
|
144
157
|
},
|
|
@@ -162,6 +175,10 @@
|
|
|
162
175
|
"skills": {
|
|
163
176
|
"dir": ".agents/skills"
|
|
164
177
|
},
|
|
178
|
+
"guards": {
|
|
179
|
+
"kind": "hooks-json",
|
|
180
|
+
"path": ".agents/hooks.json"
|
|
181
|
+
},
|
|
165
182
|
"instructionsSurfaced": false,
|
|
166
183
|
"notes": []
|
|
167
184
|
},
|
|
@@ -185,6 +202,10 @@
|
|
|
185
202
|
"skills": {
|
|
186
203
|
"dir": ".agents/skills"
|
|
187
204
|
},
|
|
205
|
+
"guards": {
|
|
206
|
+
"kind": "extension",
|
|
207
|
+
"path": ".pi/extensions/vulcan-guards.ts"
|
|
208
|
+
},
|
|
188
209
|
"instructionsSurfaced": "partial",
|
|
189
210
|
"notes": [
|
|
190
211
|
"Pi loads .pi/mcp.json and .agents/skills only after you trust this project: start pi here and answer the trust prompt."
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gate: every in-page anchor the wiki links to exists in the built site. Needs a build (`make docs`).
|
|
3
|
+
* Run from the repository root, through `make wiki-anchors-check` or directly:
|
|
4
|
+
* bun node_modules/@venizia/vulcan/base/checks/wiki-anchors.ts
|
|
5
|
+
*/
|
|
6
|
+
import { runAnchorsCommand } from '../../src/wiki/index.ts';
|
|
7
|
+
|
|
8
|
+
process.exit(runAnchorsCommand({ args: process.argv.slice(2), root: process.cwd() }));
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gate: every source path the wiki and the knowledge bundle name is tracked by git. Run from the
|
|
3
|
+
* repository root, through `make wiki-links-check WIKI_REPO=<owner/name>` or directly:
|
|
4
|
+
* bun node_modules/@venizia/vulcan/base/checks/wiki-source-links.ts --repo <owner/name>
|
|
5
|
+
*/
|
|
6
|
+
import { runSourceLinksCommand } from '../../src/wiki/index.ts';
|
|
7
|
+
|
|
8
|
+
process.exit(runSourceLinksCommand({ args: process.argv.slice(2), root: process.cwd() }));
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"hooks": [
|
|
7
7
|
{
|
|
8
8
|
"type": "command",
|
|
9
|
-
"command": "f=\"${CLAUDE_PROJECT_DIR}/node_modules/@venizia/vulcan/base/hooks/guard-remote-hosts.ts\"; in=$(cat); ok() { printf '%s' \"$in\" | grep -Eq '\"command\" *: *\"bun (install|i)( (--frozen-lockfile|--production|-p|--no-save|--ignore-scripts|--force|--verbose|--silent))*\"'; }; if [ -f \"$f\" ] && command -v bun >/dev/null 2>&1; then printf '%s' \"$in\" | bun \"$f\"; s=$?; [ \"$s\" -eq 0 ] && exit 0; ok && exit 0; exit 2; fi; ok && exit 0; [ -f \"$f\" ] || echo \"vulcan: the guard-remote-hosts hook cannot run: node_modules/@venizia/vulcan is missing - run bun install (the one command that passes until then)\" >&2; command -v bun >/dev/null 2>&1 || echo \"vulcan: the guard-remote-hosts hook cannot run: bun is not on PATH - put bun on PATH (Claude Code may have started without your shell's PATH)\" >&2; exit 2"
|
|
9
|
+
"command": "f=\"${CLAUDE_PROJECT_DIR:-$PWD}/node_modules/@venizia/vulcan/base/hooks/guard-remote-hosts.ts\"; in=$(cat); ok() { printf '%s' \"$in\" | grep -Eq '\"command\" *: *\"bun (install|i)( (--frozen-lockfile|--production|-p|--no-save|--ignore-scripts|--force|--verbose|--silent))*\"'; }; if [ -f \"$f\" ] && command -v bun >/dev/null 2>&1; then printf '%s' \"$in\" | bun \"$f\"; s=$?; [ \"$s\" -eq 0 ] && exit 0; ok && exit 0; exit 2; fi; ok && exit 0; [ -f \"$f\" ] || echo \"vulcan: the guard-remote-hosts hook cannot run: node_modules/@venizia/vulcan is missing - run bun install (the one command that passes until then)\" >&2; command -v bun >/dev/null 2>&1 || echo \"vulcan: the guard-remote-hosts hook cannot run: bun is not on PATH - put bun on PATH (Claude Code may have started without your shell's PATH)\" >&2; exit 2"
|
|
10
10
|
}
|
|
11
11
|
]
|
|
12
12
|
}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"hooks": [
|
|
9
9
|
{
|
|
10
10
|
"type": "command",
|
|
11
|
-
"command": "f=\"${CLAUDE_PROJECT_DIR}/node_modules/@venizia/vulcan/base/hooks/session-start.ts\"; if [ -f \"$f\" ] && command -v bun >/dev/null 2>&1; then bun \"$f\"; s=$?; [ \"$s\" -eq 0 ] && exit 0; exit 2; fi; [ -f \"$f\" ] || echo \"vulcan: the session-start hook cannot run: node_modules/@venizia/vulcan is missing - run bun install\" >&2; command -v bun >/dev/null 2>&1 || echo \"vulcan: the session-start hook cannot run: bun is not on PATH - put bun on PATH (Claude Code may have started without your shell's PATH)\" >&2; exit 2"
|
|
11
|
+
"command": "f=\"${CLAUDE_PROJECT_DIR:-$PWD}/node_modules/@venizia/vulcan/base/hooks/session-start.ts\"; if [ -f \"$f\" ] && command -v bun >/dev/null 2>&1; then bun \"$f\"; s=$?; [ \"$s\" -eq 0 ] && exit 0; exit 2; fi; [ -f \"$f\" ] || echo \"vulcan: the session-start hook cannot run: node_modules/@venizia/vulcan is missing - run bun install\" >&2; command -v bun >/dev/null 2>&1 || echo \"vulcan: the session-start hook cannot run: bun is not on PATH - put bun on PATH (Claude Code may have started without your shell's PATH)\" >&2; exit 2"
|
|
12
12
|
}
|
|
13
13
|
]
|
|
14
14
|
}
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"hooks": [
|
|
20
20
|
{
|
|
21
21
|
"type": "command",
|
|
22
|
-
"command": "f=\"${CLAUDE_PROJECT_DIR}/node_modules/@venizia/vulcan/base/hooks/guard-writes.ts\"; in=$(cat); ok() { printf '%s' \"$in\" | grep -Eq '\"command\" *: *\"bun (install|i)( (--frozen-lockfile|--production|-p|--no-save|--ignore-scripts|--force|--verbose|--silent))*\"'; }; if [ -f \"$f\" ] && command -v bun >/dev/null 2>&1; then printf '%s' \"$in\" | bun \"$f\"; s=$?; [ \"$s\" -eq 0 ] && exit 0; ok && exit 0; exit 2; fi; ok && exit 0; [ -f \"$f\" ] || echo \"vulcan: the guard-writes hook cannot run: node_modules/@venizia/vulcan is missing - run bun install (the one command that passes until then)\" >&2; command -v bun >/dev/null 2>&1 || echo \"vulcan: the guard-writes hook cannot run: bun is not on PATH - put bun on PATH (Claude Code may have started without your shell's PATH)\" >&2; exit 2"
|
|
22
|
+
"command": "f=\"${CLAUDE_PROJECT_DIR:-$PWD}/node_modules/@venizia/vulcan/base/hooks/guard-writes.ts\"; in=$(cat); ok() { printf '%s' \"$in\" | grep -Eq '\"command\" *: *\"bun (install|i)( (--frozen-lockfile|--production|-p|--no-save|--ignore-scripts|--force|--verbose|--silent))*\"'; }; if [ -f \"$f\" ] && command -v bun >/dev/null 2>&1; then printf '%s' \"$in\" | bun \"$f\"; s=$?; [ \"$s\" -eq 0 ] && exit 0; ok && exit 0; exit 2; fi; ok && exit 0; [ -f \"$f\" ] || echo \"vulcan: the guard-writes hook cannot run: node_modules/@venizia/vulcan is missing - run bun install (the one command that passes until then)\" >&2; command -v bun >/dev/null 2>&1 || echo \"vulcan: the guard-writes hook cannot run: bun is not on PATH - put bun on PATH (Claude Code may have started without your shell's PATH)\" >&2; exit 2"
|
|
23
23
|
}
|
|
24
24
|
]
|
|
25
25
|
},
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"hooks": [
|
|
29
29
|
{
|
|
30
30
|
"type": "command",
|
|
31
|
-
"command": "f=\"${CLAUDE_PROJECT_DIR}/node_modules/@venizia/vulcan/base/hooks/guard-manifest.ts\"; in=$(cat); ok() { printf '%s' \"$in\" | grep -Eq '\"command\" *: *\"bun (install|i)( (--frozen-lockfile|--production|-p|--no-save|--ignore-scripts|--force|--verbose|--silent))*\"'; }; if [ -f \"$f\" ] && command -v bun >/dev/null 2>&1; then printf '%s' \"$in\" | bun \"$f\"; s=$?; [ \"$s\" -eq 0 ] && exit 0; ok && exit 0; exit 2; fi; ok && exit 0; [ -f \"$f\" ] || echo \"vulcan: the guard-manifest hook cannot run: node_modules/@venizia/vulcan is missing - run bun install (the one command that passes until then)\" >&2; command -v bun >/dev/null 2>&1 || echo \"vulcan: the guard-manifest hook cannot run: bun is not on PATH - put bun on PATH (Claude Code may have started without your shell's PATH)\" >&2; exit 2"
|
|
31
|
+
"command": "f=\"${CLAUDE_PROJECT_DIR:-$PWD}/node_modules/@venizia/vulcan/base/hooks/guard-manifest.ts\"; in=$(cat); ok() { printf '%s' \"$in\" | grep -Eq '\"command\" *: *\"bun (install|i)( (--frozen-lockfile|--production|-p|--no-save|--ignore-scripts|--force|--verbose|--silent))*\"'; }; if [ -f \"$f\" ] && command -v bun >/dev/null 2>&1; then printf '%s' \"$in\" | bun \"$f\"; s=$?; [ \"$s\" -eq 0 ] && exit 0; ok && exit 0; exit 2; fi; ok && exit 0; [ -f \"$f\" ] || echo \"vulcan: the guard-manifest hook cannot run: node_modules/@venizia/vulcan is missing - run bun install (the one command that passes until then)\" >&2; command -v bun >/dev/null 2>&1 || echo \"vulcan: the guard-manifest hook cannot run: bun is not on PATH - put bun on PATH (Claude Code may have started without your shell's PATH)\" >&2; exit 2"
|
|
32
32
|
}
|
|
33
33
|
]
|
|
34
34
|
},
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"hooks": [
|
|
38
38
|
{
|
|
39
39
|
"type": "command",
|
|
40
|
-
"command": "f=\"${CLAUDE_PROJECT_DIR}/node_modules/@venizia/vulcan/base/hooks/guard-package.ts\"; in=$(cat); ok() { printf '%s' \"$in\" | grep -Eq '\"command\" *: *\"bun (install|i)( (--frozen-lockfile|--production|-p|--no-save|--ignore-scripts|--force|--verbose|--silent))*\"'; }; if [ -f \"$f\" ] && command -v bun >/dev/null 2>&1; then printf '%s' \"$in\" | bun \"$f\"; s=$?; [ \"$s\" -eq 0 ] && exit 0; ok && exit 0; exit 2; fi; ok && exit 0; [ -f \"$f\" ] || echo \"vulcan: the guard-package hook cannot run: node_modules/@venizia/vulcan is missing - run bun install (the one command that passes until then)\" >&2; command -v bun >/dev/null 2>&1 || echo \"vulcan: the guard-package hook cannot run: bun is not on PATH - put bun on PATH (Claude Code may have started without your shell's PATH)\" >&2; exit 2"
|
|
40
|
+
"command": "f=\"${CLAUDE_PROJECT_DIR:-$PWD}/node_modules/@venizia/vulcan/base/hooks/guard-package.ts\"; in=$(cat); ok() { printf '%s' \"$in\" | grep -Eq '\"command\" *: *\"bun (install|i)( (--frozen-lockfile|--production|-p|--no-save|--ignore-scripts|--force|--verbose|--silent))*\"'; }; if [ -f \"$f\" ] && command -v bun >/dev/null 2>&1; then printf '%s' \"$in\" | bun \"$f\"; s=$?; [ \"$s\" -eq 0 ] && exit 0; ok && exit 0; exit 2; fi; ok && exit 0; [ -f \"$f\" ] || echo \"vulcan: the guard-package hook cannot run: node_modules/@venizia/vulcan is missing - run bun install (the one command that passes until then)\" >&2; command -v bun >/dev/null 2>&1 || echo \"vulcan: the guard-package hook cannot run: bun is not on PATH - put bun on PATH (Claude Code may have started without your shell's PATH)\" >&2; exit 2"
|
|
41
41
|
}
|
|
42
42
|
]
|
|
43
43
|
},
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"hooks": [
|
|
47
47
|
{
|
|
48
48
|
"type": "command",
|
|
49
|
-
"command": "f=\"${CLAUDE_PROJECT_DIR}/node_modules/@venizia/vulcan/base/hooks/guard-git.ts\"; if [ -f \"$f\" ] && command -v bun >/dev/null 2>&1; then bun \"$f\"
|
|
49
|
+
"command": "f=\"${CLAUDE_PROJECT_DIR:-$PWD}/node_modules/@venizia/vulcan/base/hooks/guard-git.ts\"; if [ -f \"$f\" ] && command -v bun >/dev/null 2>&1; then in=$(cat); t=; command -v timeout >/dev/null 2>&1 && t=\"timeout 30\"; out=$(printf '%s' \"$in\" | $t bun \"$f\"); s=$?; [ \"$s\" -eq 0 ] && { printf '%s' \"$out\"; exit 0; }; if printf '%s' \"$in\" | grep -Eq '(^|[^[:alnum:]_])(git|gh)([^[:alnum:]_]|$)'; then printf '%s\\n' '{\"hookSpecificOutput\":{\"hookEventName\":\"PreToolUse\",\"permissionDecision\":\"ask\",\"permissionDecisionReason\":\"The guard-git hook crashed or timed out, so this command was not checked. Confirm only if the owner asked for exactly this; VULCAN_GUARDS=off switches the guards off for a session.\"}}'; exit 0; fi; echo \"vulcan: the guard-git hook failed - the call passes\" >&2; exit 0; fi; echo \"vulcan: the guard-git hook cannot run: node_modules/@venizia/vulcan or bun is missing - the call passes\" >&2; exit 0"
|
|
50
50
|
}
|
|
51
51
|
]
|
|
52
52
|
},
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"hooks": [
|
|
56
56
|
{
|
|
57
57
|
"type": "command",
|
|
58
|
-
"command": "f=\"${CLAUDE_PROJECT_DIR}/node_modules/@venizia/vulcan/base/hooks/guard-scripting.ts\"; if [ -f \"$f\" ] && command -v bun >/dev/null 2>&1; then bun \"$f\" || echo \"vulcan: the guard-scripting hook failed - the call passes\" >&2; exit 0; fi; echo \"vulcan: the guard-scripting hook cannot run: node_modules/@venizia/vulcan or bun is missing - the call passes\" >&2; exit 0"
|
|
58
|
+
"command": "f=\"${CLAUDE_PROJECT_DIR:-$PWD}/node_modules/@venizia/vulcan/base/hooks/guard-scripting.ts\"; if [ -f \"$f\" ] && command -v bun >/dev/null 2>&1; then bun \"$f\" || echo \"vulcan: the guard-scripting hook failed - the call passes\" >&2; exit 0; fi; echo \"vulcan: the guard-scripting hook cannot run: node_modules/@venizia/vulcan or bun is missing - the call passes\" >&2; exit 0"
|
|
59
59
|
}
|
|
60
60
|
]
|
|
61
61
|
},
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"hooks": [
|
|
65
65
|
{
|
|
66
66
|
"type": "command",
|
|
67
|
-
"command": "f=\"${CLAUDE_PROJECT_DIR}/node_modules/@venizia/vulcan/base/hooks/guard-outside.ts\"; if [ -f \"$f\" ] && command -v bun >/dev/null 2>&1; then bun \"$f\"
|
|
67
|
+
"command": "f=\"${CLAUDE_PROJECT_DIR:-$PWD}/node_modules/@venizia/vulcan/base/hooks/guard-outside.ts\"; if [ -f \"$f\" ] && command -v bun >/dev/null 2>&1; then in=$(cat); t=; command -v timeout >/dev/null 2>&1 && t=\"timeout 30\"; out=$(printf '%s' \"$in\" | $t bun \"$f\"); s=$?; [ \"$s\" -eq 0 ] && { printf '%s' \"$out\"; exit 0; }; printf '%s\\n' '{\"hookSpecificOutput\":{\"hookEventName\":\"PreToolUse\",\"permissionDecision\":\"ask\",\"permissionDecisionReason\":\"The guard-outside hook crashed or timed out, so this call was not checked. Confirm only if the owner asked for exactly this; VULCAN_GUARDS=off switches the guards off for a session.\"}}'; exit 0; fi; echo \"vulcan: the guard-outside hook cannot run: node_modules/@venizia/vulcan or bun is missing - the call passes\" >&2; exit 0"
|
|
68
68
|
}
|
|
69
69
|
]
|
|
70
70
|
}
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"hooks": [
|
|
75
75
|
{
|
|
76
76
|
"type": "command",
|
|
77
|
-
"command": "f=\"${CLAUDE_PROJECT_DIR}/node_modules/@venizia/vulcan/base/hooks/subagent-start.ts\"; if [ -f \"$f\" ] && command -v bun >/dev/null 2>&1; then bun \"$f\"; s=$?; [ \"$s\" -eq 0 ] && exit 0; exit 2; fi; [ -f \"$f\" ] || echo \"vulcan: the subagent-start hook cannot run: node_modules/@venizia/vulcan is missing - run bun install\" >&2; command -v bun >/dev/null 2>&1 || echo \"vulcan: the subagent-start hook cannot run: bun is not on PATH - put bun on PATH (Claude Code may have started without your shell's PATH)\" >&2; exit 2"
|
|
77
|
+
"command": "f=\"${CLAUDE_PROJECT_DIR:-$PWD}/node_modules/@venizia/vulcan/base/hooks/subagent-start.ts\"; if [ -f \"$f\" ] && command -v bun >/dev/null 2>&1; then bun \"$f\"; s=$?; [ \"$s\" -eq 0 ] && exit 0; exit 2; fi; [ -f \"$f\" ] || echo \"vulcan: the subagent-start hook cannot run: node_modules/@venizia/vulcan is missing - run bun install\" >&2; command -v bun >/dev/null 2>&1 || echo \"vulcan: the subagent-start hook cannot run: bun is not on PATH - put bun on PATH (Claude Code may have started without your shell's PATH)\" >&2; exit 2"
|
|
78
78
|
}
|
|
79
79
|
]
|
|
80
80
|
}
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"hooks": [
|
|
85
85
|
{
|
|
86
86
|
"type": "command",
|
|
87
|
-
"command": "f=\"${CLAUDE_PROJECT_DIR}/node_modules/@venizia/vulcan/base/hooks/prompt-submit.ts\"; if [ -f \"$f\" ] && command -v bun >/dev/null 2>&1; then bun \"$f\" || echo \"vulcan: the prompt-submit hook failed - the prompt goes through\" >&2; exit 0; fi; echo \"vulcan: the prompt-submit hook cannot run: node_modules/@venizia/vulcan or bun is missing - the prompt goes through\" >&2; exit 0",
|
|
87
|
+
"command": "f=\"${CLAUDE_PROJECT_DIR:-$PWD}/node_modules/@venizia/vulcan/base/hooks/prompt-submit.ts\"; if [ -f \"$f\" ] && command -v bun >/dev/null 2>&1; then bun \"$f\" || echo \"vulcan: the prompt-submit hook failed - the prompt goes through\" >&2; exit 0; fi; echo \"vulcan: the prompt-submit hook cannot run: node_modules/@venizia/vulcan or bun is missing - the prompt goes through\" >&2; exit 0",
|
|
88
88
|
"timeout": 15
|
|
89
89
|
}
|
|
90
90
|
]
|
|
@@ -95,7 +95,7 @@
|
|
|
95
95
|
"hooks": [
|
|
96
96
|
{
|
|
97
97
|
"type": "command",
|
|
98
|
-
"command": "f=\"${CLAUDE_PROJECT_DIR}/node_modules/@venizia/vulcan/base/hooks/stop.ts\"; if [ -f \"$f\" ] && command -v bun >/dev/null 2>&1; then bun \"$f\" || echo \"vulcan: the stop hook failed - the reply passes\" >&2; exit 0; fi; echo \"vulcan: the stop hook cannot run: node_modules/@venizia/vulcan or bun is missing - the reply passes\" >&2; exit 0",
|
|
98
|
+
"command": "f=\"${CLAUDE_PROJECT_DIR:-$PWD}/node_modules/@venizia/vulcan/base/hooks/stop.ts\"; if [ -f \"$f\" ] && command -v bun >/dev/null 2>&1; then bun \"$f\" || echo \"vulcan: the stop hook failed - the reply passes\" >&2; exit 0; fi; echo \"vulcan: the stop hook cannot run: node_modules/@venizia/vulcan or bun is missing - the reply passes\" >&2; exit 0",
|
|
99
99
|
"timeout": 15
|
|
100
100
|
}
|
|
101
101
|
]
|
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
"hooks": [
|
|
107
107
|
{
|
|
108
108
|
"type": "command",
|
|
109
|
-
"command": "f=\"${CLAUDE_PROJECT_DIR}/node_modules/@venizia/vulcan/base/hooks/post-tool.ts\"; if [ -f \"$f\" ] && command -v bun >/dev/null 2>&1; then bun \"$f\" || echo \"vulcan: the post-tool hook failed - the call is unaffected\" >&2; exit 0; fi; echo \"vulcan: the post-tool hook cannot run: node_modules/@venizia/vulcan or bun is missing - the call is unaffected\" >&2; exit 0",
|
|
109
|
+
"command": "f=\"${CLAUDE_PROJECT_DIR:-$PWD}/node_modules/@venizia/vulcan/base/hooks/post-tool.ts\"; if [ -f \"$f\" ] && command -v bun >/dev/null 2>&1; then bun \"$f\" || echo \"vulcan: the post-tool hook failed - the call is unaffected\" >&2; exit 0; fi; echo \"vulcan: the post-tool hook cannot run: node_modules/@venizia/vulcan or bun is missing - the call is unaffected\" >&2; exit 0",
|
|
110
110
|
"timeout": 15
|
|
111
111
|
}
|
|
112
112
|
]
|
|
@@ -117,7 +117,7 @@
|
|
|
117
117
|
"hooks": [
|
|
118
118
|
{
|
|
119
119
|
"type": "command",
|
|
120
|
-
"command": "f=\"${CLAUDE_PROJECT_DIR}/node_modules/@venizia/vulcan/base/hooks/post-tool.ts\"; if [ -f \"$f\" ] && command -v bun >/dev/null 2>&1; then bun \"$f\" || echo \"vulcan: the post-tool hook failed - the call is unaffected\" >&2; exit 0; fi; echo \"vulcan: the post-tool hook cannot run: node_modules/@venizia/vulcan or bun is missing - the call is unaffected\" >&2; exit 0",
|
|
120
|
+
"command": "f=\"${CLAUDE_PROJECT_DIR:-$PWD}/node_modules/@venizia/vulcan/base/hooks/post-tool.ts\"; if [ -f \"$f\" ] && command -v bun >/dev/null 2>&1; then bun \"$f\" || echo \"vulcan: the post-tool hook failed - the call is unaffected\" >&2; exit 0; fi; echo \"vulcan: the post-tool hook cannot run: node_modules/@venizia/vulcan or bun is missing - the call is unaffected\" >&2; exit 0",
|
|
121
121
|
"timeout": 15
|
|
122
122
|
}
|
|
123
123
|
]
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
// Written by `vulcan sync` for omp and pi; sync rewrites it, so change the guards, not this file.
|
|
2
|
+
//
|
|
3
|
+
// VULCAN's guards for an agent that takes an extension instead of Claude Code's hook commands. Before each
|
|
4
|
+
// tool call it runs the same guard scripts Claude Code runs (node_modules/@venizia/vulcan/base/hooks/*.ts),
|
|
5
|
+
// with a Claude-shaped event on stdin, and turns the answer into this agent's: `deny` blocks, `ask` asks
|
|
6
|
+
// the owner (and blocks when there is no UI to ask). A guard that cannot give an answer follows the same
|
|
7
|
+
// policy as the Claude wrappers: the safety guards block, the others ask, and a missing install passes
|
|
8
|
+
// except for the safety guards, which block - bar a bare `bun install`, the way to repair it.
|
|
9
|
+
// Only node: modules are imported, so any host that loads TypeScript can load it.
|
|
10
|
+
|
|
11
|
+
import { spawnSync } from 'node:child_process';
|
|
12
|
+
import { existsSync } from 'node:fs';
|
|
13
|
+
import { dirname, join } from 'node:path';
|
|
14
|
+
|
|
15
|
+
class Tools {
|
|
16
|
+
static readonly BASH = 'bash';
|
|
17
|
+
static readonly WRITE = 'write';
|
|
18
|
+
static readonly EDIT = 'edit';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** What a guard does when it cannot answer: a crash, a timeout, or no install to run. */
|
|
22
|
+
class Failures {
|
|
23
|
+
static readonly BLOCK = 'block';
|
|
24
|
+
static readonly ASK = 'ask';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
class Answers {
|
|
28
|
+
static readonly ALLOW = 'allow';
|
|
29
|
+
static readonly ASK = 'ask';
|
|
30
|
+
static readonly DENY = 'deny';
|
|
31
|
+
static readonly FAILED = 'failed';
|
|
32
|
+
static readonly MISSING = 'missing';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
interface IToolEvent {
|
|
36
|
+
toolName: string;
|
|
37
|
+
input: Record<string, unknown>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface IToolContext {
|
|
41
|
+
cwd: string;
|
|
42
|
+
hasUI: boolean;
|
|
43
|
+
ui: { confirm: (title: string, message: string) => Promise<boolean> };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface IBlock {
|
|
47
|
+
block: boolean;
|
|
48
|
+
reason: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface IHost {
|
|
52
|
+
on: (
|
|
53
|
+
event: 'tool_call',
|
|
54
|
+
handler: (event: IToolEvent, context: IToolContext) => Promise<IBlock | undefined>,
|
|
55
|
+
) => unknown;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
interface IGuard {
|
|
59
|
+
name: string;
|
|
60
|
+
tools: string[];
|
|
61
|
+
onFailure: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
interface IAnswer {
|
|
65
|
+
kind: string;
|
|
66
|
+
reason: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const HOOKS_DIRECTORY = join('node_modules', '@venizia', 'vulcan', 'base', 'hooks');
|
|
70
|
+
const TIMEOUT_MS = 30_000;
|
|
71
|
+
/** The one command that passes while the install is missing: it is how the install is repaired. */
|
|
72
|
+
const BUN_INSTALL =
|
|
73
|
+
/^\s*bun (install|i)( (--frozen-lockfile|--production|-p|--no-save|--ignore-scripts|--force|--verbose|--silent))*\s*$/;
|
|
74
|
+
|
|
75
|
+
/** The guards of `.claude/settings.json`, with the tools each covers and what each does when it cannot answer. */
|
|
76
|
+
const GUARDS: IGuard[] = [
|
|
77
|
+
{ name: 'guard-writes', tools: [Tools.BASH], onFailure: Failures.BLOCK },
|
|
78
|
+
{
|
|
79
|
+
name: 'guard-manifest',
|
|
80
|
+
tools: [Tools.BASH, Tools.WRITE, Tools.EDIT],
|
|
81
|
+
onFailure: Failures.BLOCK,
|
|
82
|
+
},
|
|
83
|
+
{ name: 'guard-package', tools: [Tools.WRITE], onFailure: Failures.BLOCK },
|
|
84
|
+
{ name: 'guard-git', tools: [Tools.BASH], onFailure: Failures.ASK },
|
|
85
|
+
{ name: 'guard-outside', tools: [Tools.BASH, Tools.WRITE, Tools.EDIT], onFailure: Failures.ASK },
|
|
86
|
+
];
|
|
87
|
+
|
|
88
|
+
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
89
|
+
typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
90
|
+
|
|
91
|
+
/** The project root: the nearest folder at or above `cwd` that has the package installed, else `cwd`. */
|
|
92
|
+
const rootOf = (opts: { cwd: string }): string => {
|
|
93
|
+
let directory = opts.cwd;
|
|
94
|
+
|
|
95
|
+
for (;;) {
|
|
96
|
+
if (existsSync(join(directory, HOOKS_DIRECTORY))) {
|
|
97
|
+
return directory;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const parent = dirname(directory);
|
|
101
|
+
|
|
102
|
+
if (parent === directory) {
|
|
103
|
+
return opts.cwd;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
directory = parent;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/** The event Claude Code sends: snake_case keys on the wire, written through string-literal keys. */
|
|
111
|
+
const wireEventOf = (opts: {
|
|
112
|
+
tool: string;
|
|
113
|
+
input: Record<string, unknown>;
|
|
114
|
+
cwd: string;
|
|
115
|
+
}): Record<string, unknown> =>
|
|
116
|
+
Object.fromEntries([
|
|
117
|
+
['tool_name', opts.tool],
|
|
118
|
+
['tool_input', opts.input],
|
|
119
|
+
['cwd', opts.cwd],
|
|
120
|
+
]);
|
|
121
|
+
|
|
122
|
+
/** The event as Claude Code would send it, or `undefined` for a tool no guard covers. */
|
|
123
|
+
const claudeEventOf = (opts: {
|
|
124
|
+
event: IToolEvent;
|
|
125
|
+
root: string;
|
|
126
|
+
}): Record<string, unknown> | undefined => {
|
|
127
|
+
const { event, root } = opts;
|
|
128
|
+
const path = event.input.path ?? event.input.file_path;
|
|
129
|
+
|
|
130
|
+
if (event.toolName === Tools.BASH && typeof event.input.command === 'string') {
|
|
131
|
+
return wireEventOf({
|
|
132
|
+
tool: 'Bash',
|
|
133
|
+
input: Object.fromEntries([['command', event.input.command]]),
|
|
134
|
+
cwd: root,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (event.toolName === Tools.WRITE && typeof path === 'string') {
|
|
139
|
+
return wireEventOf({
|
|
140
|
+
tool: 'Write',
|
|
141
|
+
input: Object.fromEntries([
|
|
142
|
+
['file_path', path],
|
|
143
|
+
['content', event.input.content],
|
|
144
|
+
]),
|
|
145
|
+
cwd: root,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (event.toolName === Tools.EDIT && typeof path === 'string') {
|
|
150
|
+
return wireEventOf({
|
|
151
|
+
tool: 'Edit',
|
|
152
|
+
input: Object.fromEntries([['file_path', path]]),
|
|
153
|
+
cwd: root,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return undefined;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
/** The decision of a guard's stdout (`hookSpecificOutput.permissionDecision`), or allow when it printed none. */
|
|
161
|
+
const answerOf = (opts: { stdout: string }): IAnswer => {
|
|
162
|
+
if (opts.stdout.trim() === '') {
|
|
163
|
+
return { kind: Answers.ALLOW, reason: '' };
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
try {
|
|
167
|
+
const parsed: unknown = JSON.parse(opts.stdout);
|
|
168
|
+
const output = isRecord(parsed) ? parsed.hookSpecificOutput : undefined;
|
|
169
|
+
const decision = isRecord(output) ? output.permissionDecision : undefined;
|
|
170
|
+
const reason = isRecord(output) ? output.permissionDecisionReason : undefined;
|
|
171
|
+
|
|
172
|
+
if (decision === Answers.DENY || decision === Answers.ASK) {
|
|
173
|
+
return { kind: decision, reason: typeof reason === 'string' ? reason : '' };
|
|
174
|
+
}
|
|
175
|
+
} catch {
|
|
176
|
+
return { kind: Answers.FAILED, reason: 'the guard printed something that is not JSON' };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return { kind: Answers.ALLOW, reason: '' };
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
const runGuard = (opts: {
|
|
183
|
+
guard: IGuard;
|
|
184
|
+
root: string;
|
|
185
|
+
claudeEvent: Record<string, unknown>;
|
|
186
|
+
}): IAnswer => {
|
|
187
|
+
const script = join(opts.root, HOOKS_DIRECTORY, `${opts.guard.name}.ts`);
|
|
188
|
+
|
|
189
|
+
if (!existsSync(script)) {
|
|
190
|
+
return { kind: Answers.MISSING, reason: `${opts.guard.name} is missing: run bun install` };
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const result = spawnSync('bun', [script], {
|
|
194
|
+
input: JSON.stringify(opts.claudeEvent),
|
|
195
|
+
encoding: 'utf8',
|
|
196
|
+
timeout: TIMEOUT_MS,
|
|
197
|
+
env: { ...process.env, CLAUDE_PROJECT_DIR: opts.root },
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
if (result.error !== undefined && 'code' in result.error && result.error.code === 'ENOENT') {
|
|
201
|
+
return { kind: Answers.MISSING, reason: 'bun is not on PATH: put bun on PATH' };
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (result.error !== undefined || result.status !== 0) {
|
|
205
|
+
const why = result.error?.message ?? result.stderr.trim().split('\n').pop() ?? '';
|
|
206
|
+
|
|
207
|
+
return { kind: Answers.FAILED, reason: `${opts.guard.name} crashed or timed out: ${why}` };
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return answerOf({ stdout: result.stdout });
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
class Verdicts {
|
|
214
|
+
static readonly ALLOW = 'allow';
|
|
215
|
+
static readonly ASK = 'ask';
|
|
216
|
+
static readonly DENY = 'deny';
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export interface IVerdict {
|
|
220
|
+
kind: string;
|
|
221
|
+
reason: string;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* What the guards say about one tool call: `deny` (blocked), `ask` (the owner decides; one reason holds every
|
|
226
|
+
* guard that asked) or `allow`. Exported so a host that is not an extension (Antigravity's hook command) can
|
|
227
|
+
* use the same policy.
|
|
228
|
+
*/
|
|
229
|
+
export const verdictOf = (opts: {
|
|
230
|
+
toolName: string;
|
|
231
|
+
input: Record<string, unknown>;
|
|
232
|
+
cwd: string;
|
|
233
|
+
}): IVerdict => {
|
|
234
|
+
const root = rootOf({ cwd: opts.cwd });
|
|
235
|
+
const claudeEvent = claudeEventOf({ event: opts, root });
|
|
236
|
+
const asks: string[] = [];
|
|
237
|
+
|
|
238
|
+
if (claudeEvent === undefined) {
|
|
239
|
+
return { kind: Verdicts.ALLOW, reason: '' };
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
for (const guard of GUARDS.filter((item) => item.tools.includes(opts.toolName))) {
|
|
243
|
+
const answer = runGuard({ guard, root, claudeEvent });
|
|
244
|
+
|
|
245
|
+
if (answer.kind === Answers.DENY) {
|
|
246
|
+
return { kind: Verdicts.DENY, reason: answer.reason };
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (answer.kind === Answers.ASK) {
|
|
250
|
+
asks.push(answer.reason);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (answer.kind === Answers.MISSING) {
|
|
254
|
+
const isRepair = opts.toolName === Tools.BASH && BUN_INSTALL.test(String(opts.input.command));
|
|
255
|
+
|
|
256
|
+
if (guard.onFailure === Failures.BLOCK && !isRepair) {
|
|
257
|
+
return { kind: Verdicts.DENY, reason: answer.reason };
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (answer.kind === Answers.FAILED) {
|
|
262
|
+
if (guard.onFailure === Failures.BLOCK) {
|
|
263
|
+
return { kind: Verdicts.DENY, reason: answer.reason };
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
asks.push(answer.reason);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return asks.length > 0
|
|
271
|
+
? { kind: Verdicts.ASK, reason: asks.join('\n\n') }
|
|
272
|
+
: { kind: Verdicts.ALLOW, reason: '' };
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
/** Asks the owner when there is a UI to ask; without one the call is blocked, never let through. */
|
|
276
|
+
const askOwner = async (opts: {
|
|
277
|
+
context: IToolContext;
|
|
278
|
+
reason: string;
|
|
279
|
+
}): Promise<IBlock | undefined> => {
|
|
280
|
+
if (!opts.context.hasUI) {
|
|
281
|
+
return { block: true, reason: `${opts.reason}\n(no UI to confirm in: hand this to the owner)` };
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const confirmed = await opts.context.ui.confirm('VULCAN guard', opts.reason);
|
|
285
|
+
|
|
286
|
+
return confirmed ? undefined : { block: true, reason: 'declined by the owner' };
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
export default function vulcanGuards(host: IHost): void {
|
|
290
|
+
host.on('tool_call', async (event, context) => {
|
|
291
|
+
const verdict = verdictOf({ toolName: event.toolName, input: event.input, cwd: context.cwd });
|
|
292
|
+
|
|
293
|
+
if (verdict.kind === Verdicts.DENY) {
|
|
294
|
+
return { block: true, reason: verdict.reason };
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
return verdict.kind === Verdicts.ASK
|
|
298
|
+
? askOwner({ context, reason: verdict.reason })
|
|
299
|
+
: undefined;
|
|
300
|
+
});
|
|
301
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Antigravity's PreToolUse hook command (`.agents/hooks.json`, written by `vulcan sync`): reads the event
|
|
3
|
+
* Antigravity sends (camelCase, `toolCall.name` and `toolCall.args`), runs the same guard scripts Claude Code
|
|
4
|
+
* runs through the policy of `base/extensions/vulcan-guards.ts`, and prints Antigravity's answer:
|
|
5
|
+
* `{ "decision": "allow" | "ask" | "deny", "reason": "..." }`. Input it cannot read is allowed, as in the
|
|
6
|
+
* Claude hooks. The settings wrapper around it asks when this script crashes. `VULCAN_GUARDS=off` allows
|
|
7
|
+
* everything, read before anything is imported.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
// A module, so the awaits below are top-level; it has no static import, by design.
|
|
11
|
+
export {};
|
|
12
|
+
|
|
13
|
+
const answer = (opts: { decision: string; reason?: string }): void => {
|
|
14
|
+
console.log(JSON.stringify(opts));
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
if (process.env.VULCAN_GUARDS === 'off') {
|
|
18
|
+
answer({ decision: 'allow' });
|
|
19
|
+
process.exit(0);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
23
|
+
typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
24
|
+
|
|
25
|
+
const textOf = (value: unknown): string | undefined =>
|
|
26
|
+
typeof value === 'string' && value !== '' ? value : undefined;
|
|
27
|
+
|
|
28
|
+
/** The Antigravity tools a guard covers, as the tool of the Claude guards. */
|
|
29
|
+
const TOOLS = new Map([
|
|
30
|
+
['run_command', 'bash'],
|
|
31
|
+
['write_to_file', 'write'],
|
|
32
|
+
['replace_file_content', 'edit'],
|
|
33
|
+
['multi_replace_file_content', 'edit'],
|
|
34
|
+
]);
|
|
35
|
+
|
|
36
|
+
const parseJson = (opts: { text: string }): unknown => {
|
|
37
|
+
try {
|
|
38
|
+
return JSON.parse(opts.text);
|
|
39
|
+
} catch {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const parsed = parseJson({ text: await Bun.stdin.text() });
|
|
45
|
+
const toolCall = isRecord(parsed) ? parsed.toolCall : undefined;
|
|
46
|
+
const args = isRecord(toolCall) ? toolCall.args : undefined;
|
|
47
|
+
const toolName = isRecord(toolCall) ? textOf(toolCall.name) : undefined;
|
|
48
|
+
const tool = toolName === undefined ? undefined : TOOLS.get(toolName);
|
|
49
|
+
const workspaces =
|
|
50
|
+
isRecord(parsed) && Array.isArray(parsed.workspacePaths) ? parsed.workspacePaths : [];
|
|
51
|
+
|
|
52
|
+
if (tool === undefined || !isRecord(args)) {
|
|
53
|
+
answer({ decision: 'allow' });
|
|
54
|
+
} else {
|
|
55
|
+
const { verdictOf } = await import('../extensions/vulcan-guards.ts');
|
|
56
|
+
const command = textOf(args.CommandLine);
|
|
57
|
+
const path = textOf(args.TargetFile);
|
|
58
|
+
const verdict = verdictOf({
|
|
59
|
+
toolName: tool,
|
|
60
|
+
input: Object.fromEntries([
|
|
61
|
+
['command', command],
|
|
62
|
+
['path', path],
|
|
63
|
+
]),
|
|
64
|
+
cwd: textOf(args.Cwd) ?? textOf(workspaces[0]) ?? process.cwd(),
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
answer({ decision: verdict.kind, reason: verdict.reason === '' ? undefined : verdict.reason });
|
|
68
|
+
}
|