@zgeoff/skill-gate 0.2.5 → 0.2.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/README.md +7 -6
- package/dist/index.js +28 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -129,12 +129,13 @@ reference that the repo lacks, and warns on each gated call until the rule is fi
|
|
|
129
129
|
The gate counts the loads of the session that makes the edit or the tool call. A skill loads through
|
|
130
130
|
a Skill tool call or a slash command. A reference counts once a Read tool call of its file succeeds;
|
|
131
131
|
a Bash `cat` of the file does not count. A subagent's tool call carries `agent_id` beside the main
|
|
132
|
-
session's `transcript_path`, and the gate reads that subagent's own transcript
|
|
133
|
-
`<session>/subagents/agent-<agent_id>.jsonl
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
132
|
+
session's `transcript_path`, and the gate reads that subagent's own transcript beside the main one:
|
|
133
|
+
`<session>/subagents/agent-<agent_id>.jsonl`, or
|
|
134
|
+
`<session>/subagents/workflows/<workflow_id>/agent-<agent_id>.jsonl` for a subagent that a workflow
|
|
135
|
+
started. A subagent therefore loads the skills itself, and the main session's loads never count for
|
|
136
|
+
it. A compaction writes a `compact_boundary` entry, and the loads and reads before it no longer
|
|
137
|
+
count: after a compaction, the gate denies a gated edit or tool call until the session loads the
|
|
138
|
+
skills and reads the references again, and its denial says so.
|
|
138
139
|
|
|
139
140
|
## Bash commands
|
|
140
141
|
|
package/dist/index.js
CHANGED
|
@@ -12350,7 +12350,7 @@ async function runSkillGate() {
|
|
|
12350
12350
|
process.exit(0);
|
|
12351
12351
|
}
|
|
12352
12352
|
const availableSkills = await readAvailableSkills(path7.join(projectDir, ".claude", "skills"));
|
|
12353
|
-
const transcript = await
|
|
12353
|
+
const transcript = await readSessionTranscript(input);
|
|
12354
12354
|
const loaded = collectSessionLoads(transcript);
|
|
12355
12355
|
const plan = planSkillGate({
|
|
12356
12356
|
rules: parsed.rules,
|
|
@@ -12407,7 +12407,7 @@ async function checkToolCall(check) {
|
|
|
12407
12407
|
return;
|
|
12408
12408
|
}
|
|
12409
12409
|
const skillsDir = path7.join(check.projectDir, ".claude", "skills");
|
|
12410
|
-
const transcript = await
|
|
12410
|
+
const transcript = await readSessionTranscript(check.hookInput);
|
|
12411
12411
|
const loads = collectSessionLoads(transcript);
|
|
12412
12412
|
const plan = planToolGate({
|
|
12413
12413
|
tools: parsedRules.tools,
|
|
@@ -12428,23 +12428,36 @@ function printOutput(output) {
|
|
|
12428
12428
|
console.log(JSON.stringify(output));
|
|
12429
12429
|
}
|
|
12430
12430
|
}
|
|
12431
|
-
async function
|
|
12432
|
-
if (
|
|
12431
|
+
async function readSessionTranscript(hookInput) {
|
|
12432
|
+
if (hookInput.agentID === undefined) {
|
|
12433
|
+
return readTranscript(hookInput.transcriptPath);
|
|
12434
|
+
}
|
|
12435
|
+
if (typeof hookInput.agentID !== "string" || !/^[\w-]+$/u.test(hookInput.agentID)) {
|
|
12433
12436
|
return "";
|
|
12434
12437
|
}
|
|
12438
|
+
const subagentsDir = path7.join(hookInput.transcriptPath.replace(/\.jsonl$/u, ""), "subagents");
|
|
12439
|
+
const transcriptName = `agent-${hookInput.agentID}.jsonl`;
|
|
12440
|
+
const agentTranscript = await readTranscript(path7.join(subagentsDir, transcriptName));
|
|
12441
|
+
if (agentTranscript !== "") {
|
|
12442
|
+
return agentTranscript;
|
|
12443
|
+
}
|
|
12444
|
+
return readWorkflowAgentTranscript(subagentsDir, transcriptName);
|
|
12445
|
+
}
|
|
12446
|
+
async function readTranscript(transcriptPath) {
|
|
12435
12447
|
const transcriptFile = Bun.file(transcriptPath);
|
|
12436
12448
|
const exists = await transcriptFile.exists();
|
|
12437
12449
|
return exists ? transcriptFile.text() : "";
|
|
12438
12450
|
}
|
|
12439
|
-
function
|
|
12440
|
-
|
|
12441
|
-
|
|
12442
|
-
|
|
12443
|
-
|
|
12444
|
-
|
|
12445
|
-
|
|
12446
|
-
|
|
12447
|
-
|
|
12451
|
+
async function readWorkflowAgentTranscript(subagentsDir, transcriptName) {
|
|
12452
|
+
const scan = new Bun.Glob(`workflows/*/${transcriptName}`).scan({ cwd: subagentsDir });
|
|
12453
|
+
let transcriptPath = null;
|
|
12454
|
+
try {
|
|
12455
|
+
for await (const scannedPath of scan) {
|
|
12456
|
+
transcriptPath = scannedPath;
|
|
12457
|
+
break;
|
|
12458
|
+
}
|
|
12459
|
+
} catch {}
|
|
12460
|
+
return transcriptPath === null ? "" : readTranscript(path7.join(subagentsDir, transcriptPath));
|
|
12448
12461
|
}
|
|
12449
12462
|
async function readAvailableSkills(skillsDir) {
|
|
12450
12463
|
const skills = [];
|
|
@@ -12528,7 +12541,7 @@ async function checkBashCommand(check, rules) {
|
|
|
12528
12541
|
return;
|
|
12529
12542
|
}
|
|
12530
12543
|
const skills = await readAvailableSkills(path7.join(check.projectDir, ".claude", "skills"));
|
|
12531
|
-
const sessionTranscript = await
|
|
12544
|
+
const sessionTranscript = await readSessionTranscript(check.hookInput);
|
|
12532
12545
|
const sessionLoads = collectSessionLoads(sessionTranscript);
|
|
12533
12546
|
const bashPlan = planBashSkillGate({
|
|
12534
12547
|
rules,
|
|
@@ -12583,7 +12596,7 @@ async function runBashResultStep(check, rules, result, step) {
|
|
|
12583
12596
|
}
|
|
12584
12597
|
async function checkChangedPaths(check, rules, result, changedPaths) {
|
|
12585
12598
|
const skills = await readAvailableSkills(path7.join(check.projectDir, ".claude", "skills"));
|
|
12586
|
-
const sessionTranscript = await
|
|
12599
|
+
const sessionTranscript = await readSessionTranscript(check.hookInput);
|
|
12587
12600
|
const sessionLoads = collectSessionLoads(sessionTranscript);
|
|
12588
12601
|
const changePlan = planBashSkillGate({
|
|
12589
12602
|
rules,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zgeoff/skill-gate",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"description": "A Claude Code hook that denies an edit or a gated tool call until the session loads the skills and reads the reference files it needs, and blocks after a Bash command that changed a gated file without them",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"claude-code",
|