@raishin/vanguard-frontier-agentic 3.14.0 → 3.16.0
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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.cursor-plugin/plugin.json +1 -1
- package/.github/plugin/marketplace.json +1 -1
- package/agents/cross-functional/revenue-critical-journey-integrity-agent/harnesses/codex.toml +1 -1
- package/agents/dotnet/dotnet-aspire-cloud-native-review-agent/harnesses/codex.toml +1 -1
- package/agents/dotnet/dotnet-aspnetcore-api-review-agent/harnesses/codex.toml +1 -1
- package/agents/dotnet/dotnet-aspnetcore-identity-authz-review-agent/harnesses/codex.toml +1 -1
- package/agents/dotnet/dotnet-csharp-runtime-review-agent/harnesses/codex.toml +1 -1
- package/agents/dotnet/dotnet-efcore-data-access-review-agent/harnesses/codex.toml +1 -1
- package/agents/dotnet/dotnet-maestro-agent/harnesses/codex.toml +1 -1
- package/agents/dotnet/dotnet-observability-otel-review-agent/harnesses/codex.toml +1 -1
- package/agents/dotnet/dotnet-performance-aot-review-agent/harnesses/codex.toml +1 -1
- package/agents/dotnet/dotnet-supply-chain-review-agent/harnesses/codex.toml +1 -1
- package/agents/dotnet/dotnet-testing-quality-review-agent/harnesses/codex.toml +1 -1
- package/agents/frontend/nextjs-specialist-agent/harnesses/codex.toml +1 -1
- package/agents/frontend/svelte-sveltekit-specialist-agent/harnesses/codex.toml +1 -1
- package/agents/hr/hr-analytics-people-data-agent/harnesses/codex.toml +1 -1
- package/agents/hr/hr-benefits-payroll-agent/harnesses/codex.toml +1 -1
- package/agents/hr/hr-compensation-equity-agent/harnesses/codex.toml +1 -1
- package/agents/hr/hr-culture-dei-agent/harnesses/codex.toml +1 -1
- package/agents/hr/hr-employee-relations-agent/harnesses/codex.toml +1 -1
- package/agents/hr/hr-hris-process-controls-agent/harnesses/codex.toml +1 -1
- package/agents/hr/hr-learning-policy-agent/harnesses/codex.toml +1 -1
- package/agents/hr/hr-leave-accommodation-agent/harnesses/codex.toml +1 -1
- package/agents/hr/hr-maestro-agent/harnesses/codex.toml +1 -1
- package/agents/hr/hr-performance-management-agent/harnesses/codex.toml +1 -1
- package/agents/hr/hr-recruiting-selection-agent/harnesses/codex.toml +1 -1
- package/agents/hr/hr-risk-triage-review-agent/harnesses/codex.toml +1 -1
- package/agents/hr/hr-termination-readiness-agent/harnesses/codex.toml +1 -1
- package/agents/hr/hr-workforce-planning-rif-agent/harnesses/codex.toml +1 -1
- package/agents/hr/hr-workplace-investigations-agent/harnesses/codex.toml +1 -1
- package/agents/java/java-application-server-exit-agent/harnesses/codex.toml +1 -1
- package/agents/java/java-concurrency-and-virtual-thread-agent/harnesses/codex.toml +1 -1
- package/agents/java/java-container-and-kubernetes-readiness-agent/harnesses/codex.toml +1 -1
- package/agents/java/java-database-migration-safety-agent/harnesses/codex.toml +1 -1
- package/agents/java/java-deserialization-and-parser-security-agent/harnesses/codex.toml +1 -1
- package/agents/java/java-framework-production-readiness-agent/harnesses/codex.toml +1 -1
- package/agents/java/java-jdk-lifecycle-and-upgrade-agent/harnesses/codex.toml +1 -1
- package/agents/java/java-jpa-hibernate-performance-agent/harnesses/codex.toml +1 -1
- package/agents/java/java-jvm-performance-and-gc-agent/harnesses/codex.toml +1 -1
- package/agents/java/java-kafka-reliability-agent/harnesses/codex.toml +1 -1
- package/agents/java/java-maestro-agent/harnesses/codex.toml +1 -1
- package/agents/java/java-resilience-pattern-agent/harnesses/codex.toml +1 -1
- package/agents/java/java-spring-security-agent/harnesses/codex.toml +1 -1
- package/agents/java/java-test-architecture-agent/harnesses/codex.toml +1 -1
- package/agents/java/java-transaction-and-consistency-agent/harnesses/codex.toml +1 -1
- package/agents/legal/legal-contract-review-agent/harnesses/codex.toml +1 -1
- package/agents/legal/legal-counsel-review-agent/harnesses/codex.toml +1 -1
- package/agents/legal/legal-employment-law-risk-agent/harnesses/codex.toml +1 -1
- package/agents/legal/legal-ethics-investigations-agent/harnesses/codex.toml +1 -1
- package/agents/legal/legal-ip-open-source-agent/harnesses/codex.toml +1 -1
- package/agents/legal/legal-knowledge-management-agent/harnesses/codex.toml +1 -1
- package/agents/legal/legal-litigation-discovery-hold-agent/harnesses/codex.toml +1 -1
- package/agents/legal/legal-maestro-agent/harnesses/codex.toml +1 -1
- package/agents/legal/legal-policy-governance-agent/harnesses/codex.toml +1 -1
- package/agents/legal/legal-privacy-data-protection-agent/harnesses/codex.toml +1 -1
- package/agents/legal/legal-public-disclosure-agent/harnesses/codex.toml +1 -1
- package/agents/legal/legal-regulatory-compliance-agent/harnesses/codex.toml +1 -1
- package/agents/legal/legal-vendor-procurement-risk-agent/harnesses/codex.toml +1 -1
- package/agents/netsuite/netsuite-administrator-agent/harnesses/codex.toml +1 -1
- package/agents/netsuite/netsuite-ai-connector-mcp-agent/harnesses/codex.toml +1 -1
- package/agents/netsuite/netsuite-ai-foundations-agent/harnesses/codex.toml +1 -1
- package/agents/netsuite/netsuite-application-developer-agent/harnesses/codex.toml +1 -1
- package/agents/netsuite/netsuite-audit-controls-sox-agent/harnesses/codex.toml +1 -1
- package/agents/netsuite/netsuite-bi-reporting-agent/harnesses/codex.toml +1 -1
- package/agents/netsuite/netsuite-data-governance-privacy-agent/harnesses/codex.toml +1 -1
- package/agents/netsuite/netsuite-enterprise-architecture-agent/harnesses/codex.toml +1 -1
- package/agents/netsuite/netsuite-erp-consultant-agent/harnesses/codex.toml +1 -1
- package/agents/netsuite/netsuite-evidence-release-drift-agent/harnesses/codex.toml +1 -1
- package/agents/netsuite/netsuite-financial-foundations-agent/harnesses/codex.toml +1 -1
- package/agents/netsuite/netsuite-identity-access-role-permission-agent/harnesses/codex.toml +1 -1
- package/agents/netsuite/netsuite-integration-migration-agent/harnesses/codex.toml +1 -1
- package/agents/netsuite/netsuite-live-org-mutation-guard-agent/harnesses/codex.toml +1 -1
- package/agents/netsuite/netsuite-maestro-agent/harnesses/codex.toml +1 -1
- package/agents/netsuite/netsuite-oneworld-multisubsidiary-agent/harnesses/codex.toml +1 -1
- package/agents/netsuite/netsuite-sandbox-nonproduction-governance-agent/harnesses/codex.toml +1 -1
- package/agents/netsuite/netsuite-saved-searches-workbook-agent/harnesses/codex.toml +1 -1
- package/agents/netsuite/netsuite-sdf-devops-release-agent/harnesses/codex.toml +1 -1
- package/agents/netsuite/netsuite-sso-oauth-tba-agent/harnesses/codex.toml +1 -1
- package/agents/netsuite/netsuite-suitecloud-developer-agent/harnesses/codex.toml +1 -1
- package/agents/netsuite/netsuite-suiteflow-automation-agent/harnesses/codex.toml +1 -1
- package/agents/netsuite/netsuite-suitefoundation-agent/harnesses/codex.toml +1 -1
- package/agents/netsuite/netsuite-suitescript-secure-code-review-agent/harnesses/codex.toml +1 -1
- package/agents/netsuite/netsuite-web-services-integration-agent/harnesses/codex.toml +1 -1
- package/agents/qa/ci-test-pipeline-review-agent/harnesses/codex.toml +1 -1
- package/agents/qa/helm-chart-quality-review-agent/harnesses/codex.toml +1 -1
- package/agents/qa/kubernetes-manifest-quality-review-agent/harnesses/codex.toml +1 -1
- package/agents/qa/llm-ai-pipeline-test-review-agent/harnesses/codex.toml +1 -1
- package/agents/qa/playwright-e2e-suite-review-agent/harnesses/codex.toml +1 -1
- package/agents/qa/plc-control-logic-safety-review-agent/harnesses/codex.toml +1 -1
- package/agents/qa/rpa-workflow-resilience-review-agent/harnesses/codex.toml +1 -1
- package/agents/qa/test-coverage-quality-review-agent/harnesses/codex.toml +1 -1
- package/agents/qa/test-flakiness-triage-agent/harnesses/codex.toml +1 -1
- package/agents/salesforce/salesforce-adaptive-access-agent/harnesses/codex.toml +1 -1
- package/agents/salesforce/salesforce-agentforce-ai-agent/harnesses/codex.toml +1 -1
- package/agents/salesforce/salesforce-analytics-tableau-agent/harnesses/codex.toml +1 -1
- package/agents/salesforce/salesforce-app-builder-automation-agent/harnesses/codex.toml +1 -1
- package/agents/salesforce/salesforce-business-analyst-agent/harnesses/codex.toml +1 -1
- package/agents/salesforce/salesforce-certificate-lifecycle-agent/harnesses/codex.toml +1 -1
- package/agents/salesforce/salesforce-change-impact-analyst-agent/harnesses/codex.toml +1 -1
- package/agents/salesforce/salesforce-code-analyzer-orchestrator-agent/harnesses/codex.toml +1 -1
- package/agents/salesforce/salesforce-compliance-privacy-agent/harnesses/codex.toml +1 -1
- package/agents/salesforce/salesforce-continuous-verification-agent/harnesses/codex.toml +1 -1
- package/agents/salesforce/salesforce-data-architecture-agent/harnesses/codex.toml +1 -1
- package/agents/salesforce/salesforce-development-agent/harnesses/codex.toml +1 -1
- package/agents/salesforce/salesforce-devops-release-agent/harnesses/codex.toml +1 -1
- package/agents/salesforce/salesforce-enterprise-architect-agent/harnesses/codex.toml +1 -1
- package/agents/salesforce/salesforce-experience-cloud-agent/harnesses/codex.toml +1 -1
- package/agents/salesforce/salesforce-hyperforce-security-agent/harnesses/codex.toml +1 -1
- package/agents/salesforce/salesforce-industry-cloud-agent/harnesses/codex.toml +1 -1
- package/agents/salesforce/salesforce-integration-mulesoft-agent/harnesses/codex.toml +1 -1
- package/agents/salesforce/salesforce-live-guard-agent/harnesses/codex.toml +1 -1
- package/agents/salesforce/salesforce-maestro-agent/harnesses/codex.toml +1 -1
- package/agents/salesforce/salesforce-marketing-cloud-agent/harnesses/codex.toml +1 -1
- package/agents/salesforce/salesforce-network-policy-architect-agent/harnesses/codex.toml +1 -1
- package/agents/salesforce/salesforce-platform-admin-review-agent/harnesses/codex.toml +1 -1
- package/agents/salesforce/salesforce-sales-cloud-revenue-agent/harnesses/codex.toml +1 -1
- package/agents/salesforce/salesforce-sandbox-governance-agent/harnesses/codex.toml +1 -1
- package/agents/salesforce/salesforce-sandbox-isolation-agent/harnesses/codex.toml +1 -1
- package/agents/salesforce/salesforce-security-identity-access-agent/harnesses/codex.toml +1 -1
- package/agents/salesforce/salesforce-service-field-service-agent/harnesses/codex.toml +1 -1
- package/agents/salesforce/salesforce-session-governance-agent/harnesses/codex.toml +1 -1
- package/agents/salesforce/salesforce-slack-collaboration-agent/harnesses/codex.toml +1 -1
- package/catalog/AGENTS.md +2 -1
- package/catalog/asset-integrity.json +723 -276
- package/catalog/index.json +3 -2
- package/catalog/model-assignments.json +121 -121
- package/catalog/model-policy.json +9 -9
- package/catalog/model-registry.json +28 -13
- package/catalog/mods.json +131 -0
- package/mods/README.md +220 -0
- package/mods/audit-trail/README.md +70 -0
- package/mods/audit-trail/bin/hook.mjs +65 -0
- package/mods/audit-trail/claude-code/UNSUPPORTED.md +11 -0
- package/mods/audit-trail/claude-code/settings.hooks.json +14 -0
- package/mods/audit-trail/codex/hooks.json +14 -0
- package/mods/audit-trail/kiro/UNSUPPORTED.md +7 -0
- package/mods/audit-trail/kiro/audit-trail-post-tool-use-hook.json +14 -0
- package/mods/audit-trail/lib/common.mjs +213 -0
- package/mods/audit-trail/lib/core.mjs +50 -0
- package/mods/audit-trail/lib/runtime.mjs +140 -0
- package/mods/audit-trail/mod.toml +37 -0
- package/mods/blast-radius-guard/.claude-plugin/plugin.json +5 -0
- package/mods/blast-radius-guard/README.md +53 -0
- package/mods/blast-radius-guard/bin/hook.mjs +18 -0
- package/mods/blast-radius-guard/claude-code/settings.hooks.json +14 -0
- package/mods/blast-radius-guard/codex/UNSUPPORTED.md +7 -0
- package/mods/blast-radius-guard/codex/hooks.json +14 -0
- package/mods/blast-radius-guard/hooks/hooks.json +5 -0
- package/mods/blast-radius-guard/hooks/register.test.ts +97 -0
- package/mods/blast-radius-guard/hooks/register.ts +13 -0
- package/mods/blast-radius-guard/kiro/UNSUPPORTED.md +7 -0
- package/mods/blast-radius-guard/kiro/blast-radius-guard-pre-tool-use-hook.json +14 -0
- package/mods/blast-radius-guard/lib/common.mjs +213 -0
- package/mods/blast-radius-guard/lib/core.mjs +66 -0
- package/mods/blast-radius-guard/lib/patterns.mjs +102 -0
- package/mods/blast-radius-guard/lib/runtime.mjs +140 -0
- package/mods/blast-radius-guard/mod.toml +34 -0
- package/mods/blast-radius-guard/patterns.json +101 -0
- package/mods/context-burn/.claude-plugin/plugin.json +5 -0
- package/mods/context-burn/README.md +66 -0
- package/mods/context-burn/bin/hook.mjs +38 -0
- package/mods/context-burn/claude-code/UNSUPPORTED.md +7 -0
- package/mods/context-burn/claude-code/settings.hooks.json +24 -0
- package/mods/context-burn/codex/UNSUPPORTED.md +7 -0
- package/mods/context-burn/codex/hooks.json +24 -0
- package/mods/context-burn/hooks/hooks.json +5 -0
- package/mods/context-burn/hooks/register.test.ts +151 -0
- package/mods/context-burn/hooks/register.ts +35 -0
- package/mods/context-burn/kiro/UNSUPPORTED.md +7 -0
- package/mods/context-burn/kiro/context-burn-post-tool-use-hook.json +14 -0
- package/mods/context-burn/kiro/context-burn-session-start-hook.json +14 -0
- package/mods/context-burn/lib/common.mjs +213 -0
- package/mods/context-burn/lib/core.mjs +79 -0
- package/mods/context-burn/lib/runtime.mjs +140 -0
- package/mods/context-burn/mod.toml +37 -0
- package/mods/live-guard-gate/.claude-plugin/plugin.json +5 -0
- package/mods/live-guard-gate/README.md +43 -0
- package/mods/live-guard-gate/bin/hook.mjs +12 -0
- package/mods/live-guard-gate/claude-code/settings.hooks.json +14 -0
- package/mods/live-guard-gate/codex/UNSUPPORTED.md +7 -0
- package/mods/live-guard-gate/codex/hooks.json +14 -0
- package/mods/live-guard-gate/hooks/hooks.json +5 -0
- package/mods/live-guard-gate/hooks/register.test.ts +59 -0
- package/mods/live-guard-gate/hooks/register.ts +11 -0
- package/mods/live-guard-gate/kiro/UNSUPPORTED.md +7 -0
- package/mods/live-guard-gate/kiro/live-guard-gate-pre-tool-use-hook.json +14 -0
- package/mods/live-guard-gate/lib/common.mjs +213 -0
- package/mods/live-guard-gate/lib/core.mjs +24 -0
- package/mods/live-guard-gate/lib/live-agents.mjs +65 -0
- package/mods/live-guard-gate/lib/patterns.mjs +523 -0
- package/mods/live-guard-gate/lib/runtime.mjs +140 -0
- package/mods/live-guard-gate/mod.toml +34 -0
- package/mods/live-guard-gate/patterns.json +522 -0
- package/mods/secret-redactor/.claude-plugin/plugin.json +5 -0
- package/mods/secret-redactor/README.md +86 -0
- package/mods/secret-redactor/bin/hook.mjs +35 -0
- package/mods/secret-redactor/claude-code/UNSUPPORTED.md +7 -0
- package/mods/secret-redactor/claude-code/settings.hooks.json +24 -0
- package/mods/secret-redactor/codex/UNSUPPORTED.md +11 -0
- package/mods/secret-redactor/codex/hooks.json +14 -0
- package/mods/secret-redactor/hooks/hooks.json +5 -0
- package/mods/secret-redactor/hooks/register.test.ts +150 -0
- package/mods/secret-redactor/hooks/register.ts +19 -0
- package/mods/secret-redactor/kiro/UNSUPPORTED.md +11 -0
- package/mods/secret-redactor/kiro/secret-redactor-pre-tool-use-hook.json +14 -0
- package/mods/secret-redactor/lib/common.mjs +213 -0
- package/mods/secret-redactor/lib/core.mjs +61 -0
- package/mods/secret-redactor/lib/patterns.mjs +75 -0
- package/mods/secret-redactor/lib/runtime.mjs +140 -0
- package/mods/secret-redactor/mod.toml +43 -0
- package/mods/secret-redactor/patterns.json +74 -0
- package/package.json +9 -5
- package/plugins/vanguard-frontier-agentic/.codex-plugin/plugin.json +1 -1
- package/scripts/generate-mods.mjs +784 -0
- package/scripts/mods/common.mjs +213 -0
- package/scripts/mods/runtime.mjs +140 -0
- package/tests/fixtures/README.md +1 -1
- package/tests/fuzz-properties.test.mjs +254 -0
- package/tests/mods.test.mjs +768 -0
- package/tests/validate-asset-integrity.py +1 -0
- package/tests/validate-mods.py +821 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Node hook for audit-trail: appends one JSON line per tool call to a per-session log.
|
|
2
|
+
// An honest append log, not tamper-evident: anything with write access can edit it.
|
|
3
|
+
import { appendFileSync, closeSync, existsSync, mkdirSync, openSync, readFileSync, readdirSync, unlinkSync } from 'node:fs'
|
|
4
|
+
import { dirname, join } from 'node:path'
|
|
5
|
+
import { runHook, projectPath } from '../lib/runtime.mjs'
|
|
6
|
+
import { buildRecord, lastSequence, rawSessionId, safeSessionId } from '../lib/core.mjs'
|
|
7
|
+
|
|
8
|
+
const sleep = (ms) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms)
|
|
9
|
+
|
|
10
|
+
// Reuses the earliest date dir that already holds this session, so the sequence never
|
|
11
|
+
// resets at midnight.
|
|
12
|
+
// ponytail: scans every date dir, O(days); index it if slow.
|
|
13
|
+
function logFile(base, sid, today) {
|
|
14
|
+
const days = existsSync(base) ? readdirSync(base).filter((d) => /^\d{4}-\d{2}-\d{2}$/.test(d)).sort() : []
|
|
15
|
+
const hit = days.find((d) => existsSync(join(base, d, `${sid}.jsonl`)))
|
|
16
|
+
return join(base, hit ?? today, `${sid}.jsonl`)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Never steal a lock: its age does not prove the owner is dead. Explicit recovery is safer
|
|
20
|
+
// than racing two writers after an automatic stale-lock takeover.
|
|
21
|
+
function acquire(lock, file) {
|
|
22
|
+
const deadline = Date.now() + 2000
|
|
23
|
+
for (;;) {
|
|
24
|
+
try {
|
|
25
|
+
return openSync(lock, 'wx')
|
|
26
|
+
} catch (err) {
|
|
27
|
+
if (err.code !== 'EEXIST') throw err
|
|
28
|
+
}
|
|
29
|
+
if (Date.now() > deadline) throw new Error(`audit-trail: could not lock ${file} within 2s`)
|
|
30
|
+
sleep(20)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Read directly instead of exists-then-read, so there is no check/use gap.
|
|
35
|
+
function readIfExists(file) {
|
|
36
|
+
try {
|
|
37
|
+
return readFileSync(file, 'utf8')
|
|
38
|
+
} catch (err) {
|
|
39
|
+
if (err.code === 'ENOENT') return ''
|
|
40
|
+
throw err
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function PostToolUse(payload, ctx) {
|
|
45
|
+
const base = projectPath(process.env.VANGUARD_AUDIT_TRAIL_LOG_DIR || '.audit', ctx.harness, import.meta.dirname)
|
|
46
|
+
const sid = await safeSessionId(rawSessionId(process.env.VANGUARD_AUDIT_TRAIL_SESSION_ID, payload))
|
|
47
|
+
const timestamp = new Date().toISOString()
|
|
48
|
+
mkdirSync(base, { recursive: true })
|
|
49
|
+
// Serialize session-file selection as well as appends, including across midnight.
|
|
50
|
+
const lock = join(base, `${sid}.lock`)
|
|
51
|
+
const fd = acquire(lock, lock)
|
|
52
|
+
try {
|
|
53
|
+
const file = logFile(base, sid, timestamp.slice(0, 10))
|
|
54
|
+
mkdirSync(dirname(file), { recursive: true })
|
|
55
|
+
const sequence = lastSequence(readIfExists(file), file) + 1
|
|
56
|
+
const agentId = process.env.VANGUARD_AUDIT_TRAIL_AGENT_ID
|
|
57
|
+
const record = await buildRecord({ timestamp, sessionId: sid, agentId, payload, harness: ctx.harness, sequence })
|
|
58
|
+
appendFileSync(file, JSON.stringify(record) + '\n')
|
|
59
|
+
} finally {
|
|
60
|
+
closeSync(fd)
|
|
61
|
+
unlinkSync(lock)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
process.exitCode = await runHook({ name: 'audit-trail', handlers: { PostToolUse } })
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Audit Trail on Claude Code
|
|
2
|
+
|
|
3
|
+
<!-- Generated by scripts/generate-mods.mjs from mod.toml. Do not edit. -->
|
|
4
|
+
|
|
5
|
+
## Unsupported
|
|
6
|
+
|
|
7
|
+
- `native`: The native mod API has no file append; rewriting the whole log would break append-only writes. Install the classic hook instead.
|
|
8
|
+
|
|
9
|
+
## Degraded
|
|
10
|
+
|
|
11
|
+
- `classic`: Classic PostToolUse fires only after a tool succeeds, so failed tool calls are not logged.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Audit Trail on Kiro
|
|
2
|
+
|
|
3
|
+
<!-- Generated by scripts/generate-mods.mjs from mod.toml. Do not edit. -->
|
|
4
|
+
|
|
5
|
+
## Degraded
|
|
6
|
+
|
|
7
|
+
- `PostToolUse`: Kiro does not document stdin field names; args_hash covers the whole payload, result_hash hashes null, and without VANGUARD_AUDIT_TRAIL_SESSION_ID every session shares the unsessioned log.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "v1",
|
|
3
|
+
"hooks": [
|
|
4
|
+
{
|
|
5
|
+
"name": "audit-trail:PostToolUse",
|
|
6
|
+
"description": "Appends one JSON line per tool call to a per-session log with sha256 hashes of the arguments and result.",
|
|
7
|
+
"trigger": "PostToolUse",
|
|
8
|
+
"action": {
|
|
9
|
+
"type": "command",
|
|
10
|
+
"command": "node .kiro/vanguard-mods/audit-trail/bin/hook.mjs --harness kiro --event PostToolUse"
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
// Shared helpers for the mods under mods/. scripts/generate-mods.mjs copies this file
|
|
2
|
+
// byte-for-byte to mods/<id>/lib/common.mjs, so edit it here and run `npm run mods:write`.
|
|
3
|
+
//
|
|
4
|
+
// Pure on purpose: no imports, no environment, no I/O. Claude Code's native mod runtime
|
|
5
|
+
// imports it and has no Node, and every harness must reach the same verdict on the same
|
|
6
|
+
// input. Regexes compile without the `u` flag so Node and Python `re.ASCII`
|
|
7
|
+
// (tests/validate-mods.py) read them the same way.
|
|
8
|
+
|
|
9
|
+
export const LIMITS = Object.freeze({
|
|
10
|
+
// A redaction that still changes after this many passes is withheld as a whole.
|
|
11
|
+
maxPasses: 8,
|
|
12
|
+
// A guard candidate longer than this is not evaluated and counts as a hit.
|
|
13
|
+
maxCandidateChars: 65536,
|
|
14
|
+
// Guard candidates are not evaluated past this combined length; the call counts as a hit.
|
|
15
|
+
maxTotalChars: 262144,
|
|
16
|
+
// Only the tail of a leaf's context (key or previous sibling) is prefixed to it.
|
|
17
|
+
maxContextChars: 256,
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
const MARKER_PREFIX = '[REDACTED:'
|
|
21
|
+
export const OVERFLOW_MARKER = '[REDACTED:overflow]'
|
|
22
|
+
const OVERFLOW_HIT = Object.freeze({ id: 'overflow', name: 'redaction did not converge' })
|
|
23
|
+
export const TOO_LARGE_HIT = Object.freeze({ id: 'too-large', name: 'input too large to evaluate' })
|
|
24
|
+
|
|
25
|
+
const ID_RE = /^[a-z0-9]+(-[a-z0-9]+)*$/
|
|
26
|
+
const PATTERN_KEYS = new Set(['id', 'name', 'description', 'regex', 'flags', 'context', 'severity', 'agents'])
|
|
27
|
+
const isStringArray = (v) => Array.isArray(v) && v.every((s) => typeof s === 'string' && s !== '')
|
|
28
|
+
|
|
29
|
+
// Parser diagnostics can quote credential-bearing data; never expose it in hook logs.
|
|
30
|
+
export function parseJson(text, source) {
|
|
31
|
+
try {
|
|
32
|
+
return JSON.parse(text)
|
|
33
|
+
} catch {
|
|
34
|
+
throw new Error(`${source}: invalid JSON`)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Validates a patterns.json-shaped list and compiles it. Throws on anything malformed so a
|
|
39
|
+
// bad extension file fails closed in the caller instead of silently matching nothing.
|
|
40
|
+
export function compilePatterns(list, source = 'patterns') {
|
|
41
|
+
if (!Array.isArray(list)) throw new Error(`${source}: expected an array of patterns`)
|
|
42
|
+
const seen = new Set()
|
|
43
|
+
return list.map((p, i) => {
|
|
44
|
+
const where = `${source}[${i}]`
|
|
45
|
+
if (p === null || typeof p !== 'object' || Array.isArray(p)) throw new Error(`${where}: expected an object`)
|
|
46
|
+
for (const k of Object.keys(p)) if (!PATTERN_KEYS.has(k)) throw new Error(`${where}: unknown key ${k}`)
|
|
47
|
+
if (typeof p.id !== 'string' || !ID_RE.test(p.id)) throw new Error(`${where}: id must be kebab-case`)
|
|
48
|
+
if (seen.has(p.id)) throw new Error(`${where}: duplicate id ${p.id}`)
|
|
49
|
+
seen.add(p.id)
|
|
50
|
+
if (typeof p.name !== 'string' || p.name === '') throw new Error(`${where}: name must be a non-empty string`)
|
|
51
|
+
if (typeof p.regex !== 'string' || p.regex === '') throw new Error(`${where}: regex must be a non-empty string`)
|
|
52
|
+
if (p.flags !== '' && p.flags !== 'i') throw new Error(`${where}: flags must be "" or "i"`)
|
|
53
|
+
if (!isStringArray(p.context) || p.context.length === 0) throw new Error(`${where}: context must be a non-empty string array`)
|
|
54
|
+
for (const k of ['description', 'severity']) {
|
|
55
|
+
if (p[k] !== undefined && typeof p[k] !== 'string') throw new Error(`${where}: ${k} must be a string`)
|
|
56
|
+
}
|
|
57
|
+
if (p.agents !== undefined && !isStringArray(p.agents)) throw new Error(`${where}: agents must be a string array`)
|
|
58
|
+
let rx, rxg
|
|
59
|
+
try {
|
|
60
|
+
rx = new RegExp(p.regex, p.flags)
|
|
61
|
+
rxg = new RegExp(p.regex, 'g' + p.flags)
|
|
62
|
+
} catch {
|
|
63
|
+
throw new Error(`${where}: regex does not compile`)
|
|
64
|
+
}
|
|
65
|
+
return Object.freeze({
|
|
66
|
+
id: p.id,
|
|
67
|
+
name: p.name,
|
|
68
|
+
severity: p.severity,
|
|
69
|
+
context: Object.freeze([...p.context]),
|
|
70
|
+
agents: p.agents ? Object.freeze([...p.agents]) : undefined,
|
|
71
|
+
rx,
|
|
72
|
+
rxg,
|
|
73
|
+
marker: `${MARKER_PREFIX}${p.id}]`,
|
|
74
|
+
})
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Every string value (not key) in depth-first order. The order follows the input, so the
|
|
79
|
+
// same payload always yields the same list.
|
|
80
|
+
export function stringLeaves(value, out = []) {
|
|
81
|
+
if (typeof value === 'string') out.push(value)
|
|
82
|
+
else if (Array.isArray(value)) for (const v of value) stringLeaves(v, out)
|
|
83
|
+
else if (value !== null && typeof value === 'object') for (const v of Object.values(value)) stringLeaves(v, out)
|
|
84
|
+
return out
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Guard candidates: every string leaf, plus every all-string array joined with spaces so
|
|
88
|
+
// an argv-style command (["rm", "-rf", "/"]) reads like the shell line it runs.
|
|
89
|
+
export function candidates(value) {
|
|
90
|
+
const out = stringLeaves(value)
|
|
91
|
+
const joinArrays = (v) => {
|
|
92
|
+
if (Array.isArray(v)) {
|
|
93
|
+
if (v.length > 1 && v.every((s) => typeof s === 'string')) out.push(v.join(' '))
|
|
94
|
+
v.forEach(joinArrays)
|
|
95
|
+
} else if (v !== null && typeof v === 'object') {
|
|
96
|
+
Object.values(v).forEach(joinArrays)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
joinArrays(value)
|
|
100
|
+
return out
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// The patterns tagged with `context` that match any text, in catalog order. Oversized input
|
|
104
|
+
// is not evaluated (regex cost is unbounded there) and reports TOO_LARGE_HIT instead.
|
|
105
|
+
export function matchPatterns(patterns, texts, context) {
|
|
106
|
+
let total = 0
|
|
107
|
+
for (const t of texts) {
|
|
108
|
+
total += t.length
|
|
109
|
+
if (t.length > LIMITS.maxCandidateChars || total > LIMITS.maxTotalChars) return [TOO_LARGE_HIT]
|
|
110
|
+
}
|
|
111
|
+
return patterns.filter((p) => p.context.includes(context) && texts.some((t) => p.rx.test(t)))
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// One pattern pass after another until the text stops changing. Each pass can expose a new
|
|
115
|
+
// match (password-in-url can swallow an earlier marker), so a single pass is not enough.
|
|
116
|
+
function fixedPoint(text, patterns, hits) {
|
|
117
|
+
let x = text
|
|
118
|
+
for (let pass = 0; pass <= LIMITS.maxPasses; pass++) {
|
|
119
|
+
let y = x
|
|
120
|
+
for (const p of patterns) {
|
|
121
|
+
y = y.replace(p.rxg, (m) => {
|
|
122
|
+
if (m === '') return m
|
|
123
|
+
hits.add(p)
|
|
124
|
+
return p.marker
|
|
125
|
+
})
|
|
126
|
+
}
|
|
127
|
+
if (y === x) return x
|
|
128
|
+
x = y
|
|
129
|
+
}
|
|
130
|
+
hits.add(OVERFLOW_HIT)
|
|
131
|
+
return OVERFLOW_MARKER
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Redacts `s` with `ctx` in front so a secret split across a key and its value, or across
|
|
135
|
+
// argv elements ("Bearer", "<token>"), still matches; then strips the context back off.
|
|
136
|
+
function redactLeaf(s, ctx, patterns, hits) {
|
|
137
|
+
if (ctx === '') return fixedPoint(s, patterns, hits)
|
|
138
|
+
const pre = ctx.slice(-LIMITS.maxContextChars) + ' '
|
|
139
|
+
const y = fixedPoint(pre + s, patterns, hits)
|
|
140
|
+
if (y === OVERFLOW_MARKER) return y
|
|
141
|
+
const r = fixedPoint(pre, patterns, new Set())
|
|
142
|
+
if (y.startsWith(r)) return fixedPoint(y.slice(r.length), patterns, hits)
|
|
143
|
+
// A match spans the boundary: keep from the marker that covers it. Slicing changes
|
|
144
|
+
// anchors and boundaries, so also check the standalone leaf after contextual matching.
|
|
145
|
+
let d = 0
|
|
146
|
+
while (d < r.length && y[d] === r[d]) d++
|
|
147
|
+
const i = y.lastIndexOf(MARKER_PREFIX, d)
|
|
148
|
+
return fixedPoint(i >= 0 ? y.slice(i) : y, patterns, hits)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function walk(v, ctx, patterns, hits) {
|
|
152
|
+
if (typeof v === 'string') {
|
|
153
|
+
const local = new Set()
|
|
154
|
+
const out = redactLeaf(v, ctx, patterns, local)
|
|
155
|
+
if (out !== v) for (const h of local) hits.add(h)
|
|
156
|
+
return out
|
|
157
|
+
}
|
|
158
|
+
if (Array.isArray(v)) {
|
|
159
|
+
let prev = null
|
|
160
|
+
return v.map((el) => {
|
|
161
|
+
const out = walk(el, typeof prev === 'string' ? prev : ctx, patterns, hits)
|
|
162
|
+
prev = el
|
|
163
|
+
return out
|
|
164
|
+
})
|
|
165
|
+
}
|
|
166
|
+
if (v !== null && typeof v === 'object') {
|
|
167
|
+
const named = typeof v.name === 'string' ? v.name : typeof v.key === 'string' ? v.key : null
|
|
168
|
+
// fromEntries, not assignment: `out[k] = v` would drop an own "__proto__" key.
|
|
169
|
+
return Object.fromEntries(
|
|
170
|
+
Object.entries(v).map(([k, x]) => [
|
|
171
|
+
walk(k, '', patterns, hits),
|
|
172
|
+
walk(x, k === 'value' && named !== null ? named : k, patterns, hits),
|
|
173
|
+
]),
|
|
174
|
+
)
|
|
175
|
+
}
|
|
176
|
+
return v
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Returns a copy of `value` with every match replaced by `[REDACTED:<id>]`, plus the
|
|
180
|
+
// patterns that fired (catalog order, unique). Keys are redacted too; two keys that redact
|
|
181
|
+
// to the same marker collapse into one, which loses data but never leaks it.
|
|
182
|
+
export function redactValue(value, patterns) {
|
|
183
|
+
const hits = new Set()
|
|
184
|
+
const out = walk(value, '', patterns, hits)
|
|
185
|
+
const order = [...patterns, OVERFLOW_HIT]
|
|
186
|
+
return { value: out, hits: order.filter((p) => hits.has(p)) }
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Same shape as `value`, every string replaced by `text`. The fallback when redaction
|
|
190
|
+
// itself failed: withhold everything rather than pass anything through.
|
|
191
|
+
export function maskValue(value, text) {
|
|
192
|
+
if (typeof value === 'string') return text
|
|
193
|
+
if (Array.isArray(value)) return value.map((v) => maskValue(v, text))
|
|
194
|
+
if (value !== null && typeof value === 'object') {
|
|
195
|
+
return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, maskValue(v, text)]))
|
|
196
|
+
}
|
|
197
|
+
return value
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// JSON with object keys sorted at every level, so equal values hash equally.
|
|
201
|
+
export function canonicalJson(value) {
|
|
202
|
+
if (Array.isArray(value)) return '[' + value.map((v) => (v === undefined ? 'null' : canonicalJson(v))).join(',') + ']'
|
|
203
|
+
if (value !== null && typeof value === 'object') {
|
|
204
|
+
const keys = Object.keys(value).filter((k) => value[k] !== undefined).sort()
|
|
205
|
+
return '{' + keys.map((k) => JSON.stringify(k) + ':' + canonicalJson(value[k])).join(',') + '}'
|
|
206
|
+
}
|
|
207
|
+
return JSON.stringify(value) ?? 'null'
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export async function sha256Hex(text) {
|
|
211
|
+
const digest = await globalThis.crypto.subtle.digest('SHA-256', new TextEncoder().encode(text))
|
|
212
|
+
return Array.from(new Uint8Array(digest), (b) => b.toString(16).padStart(2, '0')).join('')
|
|
213
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Pure record logic for audit-trail. The hook adds the file I/O around it.
|
|
2
|
+
import { canonicalJson, sha256Hex } from './common.mjs'
|
|
3
|
+
|
|
4
|
+
export const SESSION_RE = /^[A-Za-z0-9._-]{1,128}$/
|
|
5
|
+
|
|
6
|
+
const isObject = (v) => v !== null && typeof v === 'object' && !Array.isArray(v)
|
|
7
|
+
|
|
8
|
+
// Picks the session id: env override, then the payload, then a shared fallback log.
|
|
9
|
+
export function rawSessionId(envValue, payload) {
|
|
10
|
+
if (typeof envValue === 'string' && envValue) return envValue
|
|
11
|
+
const id = isObject(payload) ? payload.session_id : undefined
|
|
12
|
+
return typeof id === 'string' && id ? id : 'unsessioned'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Ids become file names, so anything outside SESSION_RE is replaced by a hash prefix.
|
|
16
|
+
export async function safeSessionId(raw) {
|
|
17
|
+
return SESSION_RE.test(raw) ? raw : (await sha256Hex(raw)).slice(0, 32)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Last sequence number in an existing log. A corrupt tail throws: restarting at 1 would fake
|
|
21
|
+
// a clean sequence.
|
|
22
|
+
export function lastSequence(text, name = '') {
|
|
23
|
+
if (text !== '' && !text.endsWith('\n')) throw new Error(`audit log ${name} has an unterminated last line`)
|
|
24
|
+
const lines = text.split('\n').filter((l) => l.trim() !== '')
|
|
25
|
+
if (lines.length === 0) return 0
|
|
26
|
+
let n
|
|
27
|
+
try {
|
|
28
|
+
n = JSON.parse(lines[lines.length - 1]).sequence_number
|
|
29
|
+
} catch {
|
|
30
|
+
n = undefined
|
|
31
|
+
}
|
|
32
|
+
if (!Number.isInteger(n) || n < 1) throw new Error(`audit log ${name} has a corrupt last line`)
|
|
33
|
+
return n
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// One log line. Hashes cover the canonical JSON of the arguments and the result; Kiro's
|
|
37
|
+
// stdin field names are undocumented, so there the whole payload is hashed.
|
|
38
|
+
export async function buildRecord({ timestamp, sessionId, agentId, payload, harness, sequence }) {
|
|
39
|
+
const p = isObject(payload) ? payload : {}
|
|
40
|
+
const kiro = harness === 'kiro'
|
|
41
|
+
return {
|
|
42
|
+
timestamp,
|
|
43
|
+
session_id: sessionId,
|
|
44
|
+
agent_id: agentId || null,
|
|
45
|
+
tool_name: typeof p.tool_name === 'string' ? p.tool_name : null,
|
|
46
|
+
args_hash: await sha256Hex(canonicalJson(kiro ? (payload ?? null) : (p.tool_input ?? null))),
|
|
47
|
+
result_hash: await sha256Hex(canonicalJson(kiro ? null : (p.tool_response ?? null))),
|
|
48
|
+
sequence_number: sequence,
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// Command-hook runtime for the mods under mods/. scripts/generate-mods.mjs copies this file
|
|
2
|
+
// byte-for-byte to mods/<id>/lib/runtime.mjs, so edit it here and run `npm run mods:write`.
|
|
3
|
+
//
|
|
4
|
+
// A mod's bin/hook.mjs hands its handlers to runHook, which reads the harness payload from
|
|
5
|
+
// stdin and renders the handler's decision in that harness's protocol. It writes no files
|
|
6
|
+
// and reads no environment; Claude Code's native runtime never imports it.
|
|
7
|
+
import { readFileSync } from 'node:fs'
|
|
8
|
+
import { isAbsolute, resolve, sep } from 'node:path'
|
|
9
|
+
|
|
10
|
+
const HARNESSES = new Set(['claude-code', 'kiro', 'codex'])
|
|
11
|
+
const EVENTS = new Set(['PreToolUse', 'PostToolUse', 'SessionStart'])
|
|
12
|
+
const DECISIONS = new Set(['allow', 'deny', 'ask', 'replace', 'context'])
|
|
13
|
+
|
|
14
|
+
const nodeIo = () => ({
|
|
15
|
+
argv: process.argv.slice(2),
|
|
16
|
+
readStdin: () => readFileSync(0, 'utf8'),
|
|
17
|
+
out: (s) => process.stdout.write(s),
|
|
18
|
+
err: (s) => process.stderr.write(s),
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
const message = (err) => (err instanceof Error ? err.message : String(err))
|
|
22
|
+
|
|
23
|
+
// JSON.parse errors quote the text they failed on, and stdin can carry a tool's input or
|
|
24
|
+
// output: report the failure without echoing any of it.
|
|
25
|
+
function parseStdin(text) {
|
|
26
|
+
try {
|
|
27
|
+
return JSON.parse(text)
|
|
28
|
+
} catch {
|
|
29
|
+
throw new Error('stdin is not valid JSON')
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function parseArgs(argv) {
|
|
34
|
+
const usage = 'usage: hook.mjs --harness <claude-code|kiro|codex> --event <PreToolUse|PostToolUse|SessionStart>'
|
|
35
|
+
if (argv.length !== 4) throw new Error(usage)
|
|
36
|
+
const args = {}
|
|
37
|
+
for (let i = 0; i < 4; i += 2) {
|
|
38
|
+
const key = { '--harness': 'harness', '--event': 'event' }[argv[i]]
|
|
39
|
+
if (!key || key in args) throw new Error(usage)
|
|
40
|
+
args[key] = argv[i + 1]
|
|
41
|
+
}
|
|
42
|
+
if (!HARNESSES.has(args.harness)) throw new Error(`unknown harness ${args.harness}; ${usage}`)
|
|
43
|
+
if (!EVENTS.has(args.event)) throw new Error(`unknown event ${args.event}; ${usage}`)
|
|
44
|
+
return args
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Where an observer writes `path`. A relative path resolves against the project root when
|
|
48
|
+
// the hook runs from its install location <root>/.<harness dir>/vanguard-mods/<id>/bin/,
|
|
49
|
+
// otherwise against the working directory. Never CLAUDE_PROJECT_DIR: mods read only their
|
|
50
|
+
// own VANGUARD_<ID>_* variables.
|
|
51
|
+
export function projectPath(path, harness, binDir) {
|
|
52
|
+
if (isAbsolute(path)) return path
|
|
53
|
+
const parts = resolve(binDir).split(sep)
|
|
54
|
+
const n = parts.length
|
|
55
|
+
const dir = { 'claude-code': '.claude', kiro: '.kiro', codex: '.codex' }[harness]
|
|
56
|
+
const installed = n >= 5 && parts[n - 1] === 'bin' && parts[n - 3] === 'vanguard-mods' && parts[n - 4] === dir
|
|
57
|
+
return resolve(installed ? parts.slice(0, n - 4).join(sep) || sep : process.cwd(), path)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Rejects decisions the harness cannot express, so a handler bug surfaces as an error
|
|
61
|
+
// instead of a silently dropped verdict.
|
|
62
|
+
function normalize(d, { harness, event }) {
|
|
63
|
+
if (d === undefined) return { decision: 'allow', log: [] }
|
|
64
|
+
if (d === null || typeof d !== 'object' || !DECISIONS.has(d.decision)) {
|
|
65
|
+
throw new Error(`handler returned an invalid decision: ${JSON.stringify(d)}`)
|
|
66
|
+
}
|
|
67
|
+
const log = d.log ?? []
|
|
68
|
+
if (!Array.isArray(log) || !log.every((l) => typeof l === 'string')) throw new Error('decision log must be a string array')
|
|
69
|
+
const needs = { deny: 'reason', ask: 'reason', context: 'text' }[d.decision]
|
|
70
|
+
if (needs && (typeof d[needs] !== 'string' || d[needs] === '')) throw new Error(`${d.decision} needs a ${needs}`)
|
|
71
|
+
if ((d.decision === 'deny' || d.decision === 'ask') && event !== 'PreToolUse') {
|
|
72
|
+
throw new Error(`${d.decision} is only valid for PreToolUse, not ${event}`)
|
|
73
|
+
}
|
|
74
|
+
if (d.decision === 'replace' && (harness !== 'claude-code' || event !== 'PostToolUse')) {
|
|
75
|
+
throw new Error(`replace is only valid for claude-code PostToolUse, not ${harness} ${event}`)
|
|
76
|
+
}
|
|
77
|
+
return { ...d, log }
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function render(d, { harness, event }, io) {
|
|
81
|
+
const json = (hookSpecificOutput) => io.out(JSON.stringify({ hookSpecificOutput: { hookEventName: event, ...hookSpecificOutput } }) + '\n')
|
|
82
|
+
for (const line of d.log) io.err(line + '\n')
|
|
83
|
+
switch (d.decision) {
|
|
84
|
+
case 'allow':
|
|
85
|
+
return 0
|
|
86
|
+
case 'deny':
|
|
87
|
+
case 'ask':
|
|
88
|
+
if (harness === 'claude-code') {
|
|
89
|
+
json({ permissionDecision: d.decision, permissionDecisionReason: d.reason })
|
|
90
|
+
return 0
|
|
91
|
+
}
|
|
92
|
+
// Kiro and Codex have no confirmation step; exit 2 blocks the call in both.
|
|
93
|
+
io.err(d.decision === 'ask' ? `${d.reason} (confirmation unsupported on ${harness}; denied)\n` : `${d.reason}\n`)
|
|
94
|
+
return 2
|
|
95
|
+
case 'replace':
|
|
96
|
+
json({ updatedToolOutput: d.output })
|
|
97
|
+
return 0
|
|
98
|
+
case 'context':
|
|
99
|
+
if (harness === 'kiro') io.err(d.text + '\n')
|
|
100
|
+
else json({ additionalContext: d.text })
|
|
101
|
+
return 0
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Runs one hook invocation and returns the exit code; bin/hook.mjs sets process.exitCode
|
|
106
|
+
// with it rather than calling process.exit, so buffered stdout is never cut short.
|
|
107
|
+
//
|
|
108
|
+
// - Bad arguments, or an event this mod has no handler for: exit 2, which blocks a
|
|
109
|
+
// PreToolUse call in every harness (a broken install must not allow silently).
|
|
110
|
+
// - Invalid stdin or a throwing handler: `onError(err, payload, ctx)` supplies the decision
|
|
111
|
+
// (guards deny, the redactor withholds). Without onError: stderr and exit 1, which is
|
|
112
|
+
// loud but does not block.
|
|
113
|
+
// - An onError that throws or returns an invalid decision: exit 2.
|
|
114
|
+
export async function runHook({ name, handlers, onError }, io = nodeIo()) {
|
|
115
|
+
let ctx
|
|
116
|
+
try {
|
|
117
|
+
ctx = parseArgs(io.argv)
|
|
118
|
+
if (!Object.hasOwn(handlers, ctx.event)) throw new Error(`no handler for ${ctx.event}`)
|
|
119
|
+
} catch (err) {
|
|
120
|
+
io.err(`${name}: ${message(err)}\n`)
|
|
121
|
+
return 2
|
|
122
|
+
}
|
|
123
|
+
let payload
|
|
124
|
+
let decision
|
|
125
|
+
try {
|
|
126
|
+
payload = parseStdin(io.readStdin())
|
|
127
|
+
if (payload === null || typeof payload !== 'object' || Array.isArray(payload)) throw new Error('stdin is not a JSON object')
|
|
128
|
+
decision = normalize(await handlers[ctx.event](payload, ctx), ctx)
|
|
129
|
+
} catch (err) {
|
|
130
|
+
io.err(`${name}: ${message(err)}\n`)
|
|
131
|
+
if (typeof onError !== 'function') return 1
|
|
132
|
+
try {
|
|
133
|
+
decision = normalize(await onError(err, payload, ctx), ctx)
|
|
134
|
+
} catch (err2) {
|
|
135
|
+
io.err(`${name}: error handler failed: ${message(err2)}\n`)
|
|
136
|
+
return 2
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return render(decision, ctx, io)
|
|
140
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
[mod]
|
|
2
|
+
id = "audit-trail"
|
|
3
|
+
name = "Audit Trail"
|
|
4
|
+
description = "Appends one JSON line per tool call to a per-session log with sha256 hashes of the arguments and result."
|
|
5
|
+
version = "1.0.0"
|
|
6
|
+
reach_level = 1
|
|
7
|
+
events = ["PostToolUse"]
|
|
8
|
+
|
|
9
|
+
[footprint]
|
|
10
|
+
env_reads = ["VANGUARD_AUDIT_TRAIL_LOG_DIR", "VANGUARD_AUDIT_TRAIL_SESSION_ID", "VANGUARD_AUDIT_TRAIL_AGENT_ID"]
|
|
11
|
+
file_writes = [".audit/**"]
|
|
12
|
+
spawns = []
|
|
13
|
+
egress_hosts = []
|
|
14
|
+
|
|
15
|
+
[harnesses.claude-code]
|
|
16
|
+
supported = true
|
|
17
|
+
surfaces = ["classic"]
|
|
18
|
+
events = ["PostToolUse"]
|
|
19
|
+
|
|
20
|
+
[harnesses.claude-code.degraded]
|
|
21
|
+
classic = "Classic PostToolUse fires only after a tool succeeds, so failed tool calls are not logged."
|
|
22
|
+
|
|
23
|
+
[harnesses.claude-code.unsupported]
|
|
24
|
+
native = "The native mod API has no file append; rewriting the whole log would break append-only writes. Install the classic hook instead."
|
|
25
|
+
|
|
26
|
+
[harnesses.kiro]
|
|
27
|
+
supported = true
|
|
28
|
+
requires = ["node"]
|
|
29
|
+
events = ["PostToolUse"]
|
|
30
|
+
|
|
31
|
+
[harnesses.kiro.degraded]
|
|
32
|
+
PostToolUse = "Kiro does not document stdin field names; args_hash covers the whole payload, result_hash hashes null, and without VANGUARD_AUDIT_TRAIL_SESSION_ID every session shares the unsessioned log."
|
|
33
|
+
|
|
34
|
+
[harnesses.codex]
|
|
35
|
+
supported = true
|
|
36
|
+
requires = ["node"]
|
|
37
|
+
events = ["PostToolUse"]
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Blast Radius Guard
|
|
2
|
+
|
|
3
|
+
## Reach and declared footprint
|
|
4
|
+
|
|
5
|
+
**L0 (no declared file writes, subprocess spawns or network egress).** The manifest
|
|
6
|
+
only declares environment reads of `VANGUARD_BLAST_RADIUS_GUARD_MODE` and
|
|
7
|
+
`VANGUARD_BLAST_RADIUS_GUARD_PATTERNS`. The `file_writes`, `spawns` and `egress_hosts`
|
|
8
|
+
arrays are empty. This is capability disclosure, not enforced isolation.
|
|
9
|
+
|
|
10
|
+
## What it does
|
|
11
|
+
|
|
12
|
+
Checks every tool call before it runs. It asks for confirmation, or blocks, when the call
|
|
13
|
+
looks destructive: a shell command from the built-in pattern list (recursive deletes of
|
|
14
|
+
system or home paths, SQL drops, force pushes to protected branches, piping a download
|
|
15
|
+
into a shell, and similar) or a write to a system path. Paths are normalized lexically
|
|
16
|
+
first, so `/tmp/../etc/passwd` is caught.
|
|
17
|
+
|
|
18
|
+
## Configuration
|
|
19
|
+
|
|
20
|
+
- `VANGUARD_BLAST_RADIUS_GUARD_MODE`: `confirm` (the default when unset) asks. Any other
|
|
21
|
+
value, including a typo, blocks.
|
|
22
|
+
- `VANGUARD_BLAST_RADIUS_GUARD_PATTERNS`: optional path to a JSON file of extra patterns.
|
|
23
|
+
They are appended to the built-in list and never replace it. If the file is set but
|
|
24
|
+
cannot be read, is not valid JSON, is malformed, or reuses a built-in id, every call is
|
|
25
|
+
denied.
|
|
26
|
+
|
|
27
|
+
The extension file is an array of entries with the same keys as `patterns.json`: `id`
|
|
28
|
+
(kebab-case, unique), `name`, `description`, `regex`, `flags` (`""` or `"i"`), `context`
|
|
29
|
+
(`["bash"]` for shell text or `["file-write"]` for normalized paths) and `severity`.
|
|
30
|
+
|
|
31
|
+
## Per-harness behavior
|
|
32
|
+
|
|
33
|
+
| Harness | Surface | Behavior |
|
|
34
|
+
| --- | --- | --- |
|
|
35
|
+
| Claude Code | native | `tool.check` guard. Never loosens the engine verdict; a hit asks (or denies in block mode). |
|
|
36
|
+
| Claude Code | classic | `PreToolUse` command hook; a hit asks (or denies in block mode). |
|
|
37
|
+
| Kiro | hook | Degraded. The whole payload is scanned, the system-path rule applies to the path keys whatever the tool, and confirm mode denies. |
|
|
38
|
+
| Codex | hook | Degraded. Codex rejects ask, so confirm mode denies with a reason. |
|
|
39
|
+
|
|
40
|
+
## Limitations
|
|
41
|
+
|
|
42
|
+
- It scans every string in the tool input, so a file write whose content mentions a
|
|
43
|
+
destructive command also asks. This false positive is by design (fail closed).
|
|
44
|
+
- Relative paths are not resolved against a working directory.
|
|
45
|
+
- Kiro documents no stdin field names, so its whole payload is scanned.
|
|
46
|
+
- An `ask` is settled by the permission mode, so a bypass mode may auto-approve.
|
|
47
|
+
- Input over the size limit is not evaluated and counts as a hit.
|
|
48
|
+
- The native API is early access, verified against Claude Code 2.1.296.
|
|
49
|
+
- Classic, Kiro and Codex hooks need Node 22+.
|
|
50
|
+
|
|
51
|
+
## Install
|
|
52
|
+
|
|
53
|
+
See `mods/README.md`.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Command-hook entry for classic Claude Code, Kiro and Codex.
|
|
2
|
+
import { readFileSync } from 'node:fs'
|
|
3
|
+
import { checkToolUse, compileGuardPatterns, modeOf, toolUseFromPayload } from '../lib/core.mjs'
|
|
4
|
+
import { runHook } from '../lib/runtime.mjs'
|
|
5
|
+
|
|
6
|
+
const PreToolUse = (payload) => {
|
|
7
|
+
const mode = modeOf(process.env.VANGUARD_BLAST_RADIUS_GUARD_MODE)
|
|
8
|
+
const file = process.env.VANGUARD_BLAST_RADIUS_GUARD_PATTERNS
|
|
9
|
+
const patterns = compileGuardPatterns(file ? readFileSync(file, 'utf8') : undefined)
|
|
10
|
+
return checkToolUse(toolUseFromPayload(payload), patterns, mode)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const onError = (err) => ({
|
|
14
|
+
decision: 'deny',
|
|
15
|
+
reason: `blast-radius-guard: check failed; denied (${err instanceof Error ? err.message : String(err)})`,
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
process.exitCode = await runHook({ name: 'blast-radius-guard', handlers: { PreToolUse }, onError })
|