@zgeoff/skill-gate 0.2.9 → 0.2.12

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.
Files changed (52) hide show
  1. package/README.md +25 -89
  2. package/dist/index.d.ts +3 -2
  3. package/dist/index.js +4 -13133
  4. package/package.json +7 -13
  5. package/dist/bash-snapshot-schema.d.ts +0 -9
  6. package/dist/build-bash-change-output.d.ts +0 -6
  7. package/dist/build-bash-check-failure-output.d.ts +0 -2
  8. package/dist/build-bash-skill-gate-output.d.ts +0 -6
  9. package/dist/build-edit-output.d.ts +0 -3
  10. package/dist/build-patch-gate-output.d.ts +0 -2
  11. package/dist/build-skill-gate-output.d.ts +0 -2
  12. package/dist/build-tool-gate-output.d.ts +0 -2
  13. package/dist/classify-command-reads.d.ts +0 -5
  14. package/dist/collect-bash-candidates.d.ts +0 -2
  15. package/dist/collect-changed-paths.d.ts +0 -2
  16. package/dist/collect-command-reads.d.ts +0 -1
  17. package/dist/collect-gate-skills.d.ts +0 -2
  18. package/dist/collect-prompt-skills.d.ts +0 -1
  19. package/dist/collect-rule-warnings.d.ts +0 -2
  20. package/dist/collect-session-loads.d.ts +0 -2
  21. package/dist/collect-written-paths.d.ts +0 -2
  22. package/dist/format-skill-list.d.ts +0 -1
  23. package/dist/format-unknown-key-warning.d.ts +0 -1
  24. package/dist/harness.d.ts +0 -1
  25. package/dist/load-ledger.d.ts +0 -6
  26. package/dist/parse-hook-input.d.ts +0 -3
  27. package/dist/parse-patch-paths.d.ts +0 -1
  28. package/dist/parse-shell-commands.d.ts +0 -4
  29. package/dist/parse-skill-gate-rules.d.ts +0 -2
  30. package/dist/pick-commit-range.d.ts +0 -2
  31. package/dist/pick-comparison-step.d.ts +0 -2
  32. package/dist/pick-harness-wording.d.ts +0 -3
  33. package/dist/pick-record-step.d.ts +0 -2
  34. package/dist/plan-bash-skill-gate.d.ts +0 -2
  35. package/dist/plan-skill-gate.d.ts +0 -2
  36. package/dist/plan-tool-gate.d.ts +0 -2
  37. package/dist/read-available-references.d.ts +0 -2
  38. package/dist/read-available-skills.d.ts +0 -1
  39. package/dist/read-commit-hashes.d.ts +0 -3
  40. package/dist/read-committed-paths.d.ts +0 -2
  41. package/dist/read-file-content.d.ts +0 -1
  42. package/dist/read-file-hashes.d.ts +0 -2
  43. package/dist/read-project-dir.d.ts +0 -1
  44. package/dist/read-session-loads.d.ts +0 -2
  45. package/dist/read-session-transcript.d.ts +0 -2
  46. package/dist/read-work-tree.d.ts +0 -3
  47. package/dist/record-codex-loads.d.ts +0 -3
  48. package/dist/resolve-state-dir.d.ts +0 -3
  49. package/dist/run-skill-gate.d.ts +0 -2
  50. package/dist/to-content-hash.d.ts +0 -1
  51. package/dist/types.d.ts +0 -209
  52. package/dist/with-ledger-lock.d.ts +0 -1
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zgeoff/skill-gate",
3
- "version": "0.2.9",
4
- "description": "A Claude Code and Codex CLI 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",
3
+ "version": "0.2.12",
4
+ "description": "Moved to @zgeoff/agent-hooks: this release runs the skill gate from that package",
5
5
  "keywords": [
6
6
  "claude-code",
7
7
  "codex",
@@ -28,22 +28,16 @@
28
28
  "access": "public"
29
29
  },
30
30
  "scripts": {
31
- "build": "rm -rf dist && bun run build:outdir dist",
32
- "build:outdir": "sh -c 'bun build src/index.ts --target bun --outdir \"$0\" && tsc -p tsconfig.build.json --outDir \"$0\"'",
33
- "prepare": "bun run build",
31
+ "build": "rm -rf dist && bun build src/index.ts --target bun --outdir dist --packages external && tsc -p tsconfig.build.json",
34
32
  "typecheck": "tsrs"
35
33
  },
34
+ "dependencies": {
35
+ "@zgeoff/agent-hooks": "0.1.2"
36
+ },
36
37
  "devDependencies": {
37
38
  "@types/bun": "1.4.3",
38
- "@types/picomatch": "4.0.3",
39
- "@zgeoff/std": "0.3.0",
40
- "picomatch": "4.0.7",
41
- "simple-git": "4.0.2",
42
- "tiny-invariant": "1.3.3",
43
- "ts-pattern": "5.9.2",
44
39
  "tsrs": "0.18.0-ts7.1.0-dev.20260929",
45
- "typescript": "7.0.2",
46
- "zod": "4.6.7"
40
+ "typescript": "7.0.2"
47
41
  },
48
42
  "engines": {
49
43
  "bun": ">=1.3"
@@ -1,9 +0,0 @@
1
- import { z } from 'zod';
2
- export declare const bashSnapshotSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
3
- kind: z.ZodLiteral<"recorded">;
4
- head: z.ZodNullable<z.ZodString>;
5
- hashes: z.ZodRecord<z.ZodString, z.ZodNullable<z.ZodString>>;
6
- }, z.core.$strip>, z.ZodObject<{
7
- kind: z.ZodLiteral<"failed">;
8
- error: z.ZodString;
9
- }, z.core.$strip>], "kind">;
@@ -1,6 +0,0 @@
1
- import type { Harness } from './harness.ts';
2
- import type { BashChangeHookOutput, PostToolEvent } from './types.ts';
3
- export declare function buildBashChangeOutput(event: PostToolEvent, changedPaths: readonly string[], missing: readonly string[], context?: {
4
- readonly compacted?: boolean;
5
- readonly harness?: Harness;
6
- }): BashChangeHookOutput | null;
@@ -1,2 +0,0 @@
1
- import type { BashCheckFailureHookOutput, PostToolEvent } from './types.ts';
2
- export declare function buildBashCheckFailureOutput(event: PostToolEvent, error: string): BashCheckFailureHookOutput;
@@ -1,6 +0,0 @@
1
- import type { Harness } from './harness.ts';
2
- import type { SkillGateHookOutput } from './types.ts';
3
- export declare function buildBashSkillGateOutput(gatedPaths: readonly string[], missing: readonly string[], context?: {
4
- readonly compacted?: boolean;
5
- readonly harness?: Harness;
6
- }): SkillGateHookOutput | null;
@@ -1,3 +0,0 @@
1
- import type { Harness } from './harness.ts';
2
- import type { EditEntry, SkillGateHookOutput, SkillGateOutputContext } from './types.ts';
3
- export declare function buildEditOutput(harness: Harness, entries: readonly EditEntry[], context: SkillGateOutputContext): SkillGateHookOutput | null;
@@ -1,2 +0,0 @@
1
- import type { EditEntry, SkillGateHookOutput, SkillGateOutputContext } from './types.ts';
2
- export declare function buildPatchGateOutput(entries: readonly EditEntry[], context?: SkillGateOutputContext): SkillGateHookOutput | null;
@@ -1,2 +0,0 @@
1
- import type { SkillGateHookOutput, SkillGateOutputContext, SkillGatePlan } from './types.ts';
2
- export declare function buildSkillGateOutput(filePath: string, plan: SkillGatePlan, context?: SkillGateOutputContext): SkillGateHookOutput | null;
@@ -1,2 +0,0 @@
1
- import type { SkillGateHookOutput, SkillGateOutputContext, ToolGatePlan } from './types.ts';
2
- export declare function buildToolGateOutput(toolName: string, plan: ToolGatePlan, context?: SkillGateOutputContext): SkillGateHookOutput | null;
@@ -1,5 +0,0 @@
1
- export interface ClassifiedReads {
2
- readonly skills: readonly string[];
3
- readonly readPaths: readonly string[];
4
- }
5
- export declare function classifyCommandReads(readFiles: readonly string[], projectDir: string, references: readonly string[]): ClassifiedReads;
@@ -1,2 +0,0 @@
1
- import type { BashCandidates, FileHashes } from './types.ts';
2
- export declare function collectBashCandidates(recorded: FileHashes, gatedPaths: readonly string[]): BashCandidates;
@@ -1,2 +0,0 @@
1
- import type { FileHashes } from './types.ts';
2
- export declare function collectChangedPaths(recorded: FileHashes, atHead: FileHashes, after: FileHashes): readonly string[];
@@ -1 +0,0 @@
1
- export declare function collectCommandReads(command: string, cwd: string): readonly string[];
@@ -1,2 +0,0 @@
1
- import type { SkillGateRules } from './types.ts';
2
- export declare function collectGateSkills(rules: SkillGateRules, relativePath: string): readonly string[];
@@ -1 +0,0 @@
1
- export declare function collectPromptSkills(prompt: string): readonly string[];
@@ -1,2 +0,0 @@
1
- import type { SkillGateOutputContext, UnknownSkill } from './types.ts';
2
- export declare function collectRuleWarnings(unknown: readonly UnknownSkill[], context: SkillGateOutputContext): readonly string[];
@@ -1,2 +0,0 @@
1
- import type { SessionLoads } from './types.ts';
2
- export declare function collectSessionLoads(transcript: string): SessionLoads;
@@ -1,2 +0,0 @@
1
- import type { WrittenPath } from './types.ts';
2
- export declare function collectWrittenPaths(command: string): readonly WrittenPath[];
@@ -1 +0,0 @@
1
- export declare function formatSkillList(skills: readonly string[]): string;
@@ -1 +0,0 @@
1
- export declare function formatUnknownKeyWarning(key: string): string;
package/dist/harness.d.ts DELETED
@@ -1 +0,0 @@
1
- export type Harness = 'claude-code' | 'codex';
@@ -1,6 +0,0 @@
1
- import type { SessionLoads } from './types.ts';
2
- export declare const EMPTY_LEDGER: SessionLoads;
3
- export declare function readLoadLedger(ledgerPath: string | null): Promise<SessionLoads>;
4
- export declare function writeLoadLedger(ledgerPath: string | null, ledger: SessionLoads): Promise<void>;
5
- export declare function addLoads(ledger: SessionLoads, loads: Pick<SessionLoads, 'skills' | 'readPaths'>): SessionLoads;
6
- export declare function voidLoads(): SessionLoads;
@@ -1,3 +0,0 @@
1
- import type { Harness } from './harness.ts';
2
- import type { HookInput, LifecycleInput } from './types.ts';
3
- export declare function parseHookInput(harness: Harness, value: unknown): HookInput | LifecycleInput | null;
@@ -1 +0,0 @@
1
- export declare function parsePatchPaths(patch: string): readonly string[];
@@ -1,4 +0,0 @@
1
- import type { ShellCommand } from './types.ts';
2
- export declare function parseShellCommands(text: string, options?: {
3
- readonly withGuards?: boolean;
4
- }): readonly ShellCommand[] | null;
@@ -1,2 +0,0 @@
1
- import type { SkillGateRulesResult } from './types.ts';
2
- export declare function parseSkillGateRules(text: string): SkillGateRulesResult;
@@ -1,2 +0,0 @@
1
- import type { CommitRange } from './types.ts';
2
- export declare function pickCommitRange(before: string | null, after: string | null): CommitRange | null;
@@ -1,2 +0,0 @@
1
- import type { BashComparison, BashResultStep } from './types.ts';
2
- export declare function pickComparisonStep(comparison: BashComparison): BashResultStep;
@@ -1,3 +0,0 @@
1
- import type { Harness } from './harness.ts';
2
- import type { HarnessWording } from './types.ts';
3
- export declare function pickHarnessWording(harness: Harness | undefined): HarnessWording;
@@ -1,2 +0,0 @@
1
- import type { BashSnapshot, RecordStep } from './types.ts';
2
- export declare function pickRecordStep(record: BashSnapshot | null): RecordStep;
@@ -1,2 +0,0 @@
1
- import type { BashSkillGateInput, BashSkillGatePlan } from './types.ts';
2
- export declare function planBashSkillGate(input: BashSkillGateInput): BashSkillGatePlan;
@@ -1,2 +0,0 @@
1
- import type { SkillGateInput, SkillGatePlan } from './types.ts';
2
- export declare function planSkillGate(input: SkillGateInput): SkillGatePlan;
@@ -1,2 +0,0 @@
1
- import type { ToolGateInput, ToolGatePlan } from './types.ts';
2
- export declare function planToolGate(input: ToolGateInput): ToolGatePlan;
@@ -1,2 +0,0 @@
1
- import type { ReadFileContent, ToolGate } from './types.ts';
2
- export declare function readAvailableReferences(readContent: ReadFileContent, skillsDir: string, tools: readonly ToolGate[]): Promise<readonly string[]>;
@@ -1 +0,0 @@
1
- export declare function readAvailableSkills(skillsDir: string): Promise<readonly string[]>;
@@ -1,3 +0,0 @@
1
- import type { SimpleGit } from 'simple-git';
2
- import type { FileHashes } from './types.ts';
3
- export declare function readCommitHashes(git: SimpleGit, commit: string | null, relativePaths: readonly string[]): Promise<FileHashes>;
@@ -1,2 +0,0 @@
1
- import type { SimpleGit } from 'simple-git';
2
- export declare function readCommittedPaths(git: SimpleGit, directory: string, from: string | null, to: string): Promise<readonly string[]>;
@@ -1 +0,0 @@
1
- export declare function readFileContent(filePath: string): Promise<Uint8Array | null>;
@@ -1,2 +0,0 @@
1
- import type { FileHashes, ReadFileContent } from './types.ts';
2
- export declare function readFileHashes(readContent: ReadFileContent, projectDir: string, relativePaths: readonly string[]): Promise<FileHashes>;
@@ -1 +0,0 @@
1
- export declare function readProjectDir(cwd: string): Promise<string>;
@@ -1,2 +0,0 @@
1
- import type { HookInput, SessionLoads } from './types.ts';
2
- export declare function readSessionLoads(hookInput: HookInput): Promise<SessionLoads>;
@@ -1,2 +0,0 @@
1
- import type { HookInput } from './types.ts';
2
- export declare function readSessionTranscript(hookInput: HookInput): Promise<string>;
@@ -1,3 +0,0 @@
1
- import type { SimpleGit } from 'simple-git';
2
- import type { WorkTree } from './types.ts';
3
- export declare function readWorkTree(git: SimpleGit, directory: string): Promise<WorkTree | null>;
@@ -1,3 +0,0 @@
1
- import type { HookInput, LifecycleInput } from './types.ts';
2
- export declare function recordLifecycle(input: LifecycleInput, projectDir: string): Promise<void>;
3
- export declare function recordCommandReads(input: HookInput, command: string, projectDir: string, rulesText: string): Promise<void>;
@@ -1,3 +0,0 @@
1
- import type { SessionState } from './types.ts';
2
- export declare function resolveStateDir(hookInput: SessionState): string | null;
3
- export declare function resolveLedgerPath(hookInput: SessionState): string | null;
@@ -1,2 +0,0 @@
1
- import type { Harness } from './harness.ts';
2
- export declare function runSkillGate(harness?: Harness): Promise<never>;
@@ -1 +0,0 @@
1
- export declare function toContentHash(bytes: Uint8Array): string;
package/dist/types.d.ts DELETED
@@ -1,209 +0,0 @@
1
- import type { z } from 'zod';
2
- import type { bashSnapshotSchema } from './bash-snapshot-schema.ts';
3
- import type { Harness } from './harness.ts';
4
- export interface SkillGate {
5
- readonly match: string;
6
- readonly skills: readonly string[];
7
- }
8
- export interface SkillGateRules {
9
- readonly ignore: readonly string[];
10
- readonly gates: readonly SkillGate[];
11
- }
12
- export interface ToolGate {
13
- readonly tool: string;
14
- readonly skills: readonly string[];
15
- readonly references: readonly string[];
16
- }
17
- export type SkillGateRulesResult = {
18
- readonly ok: true;
19
- readonly rules: SkillGateRules;
20
- readonly tools: readonly ToolGate[];
21
- readonly unknownKeys: readonly string[];
22
- } | {
23
- readonly ok: false;
24
- readonly error: string;
25
- };
26
- export interface UnknownSkill {
27
- readonly match: string;
28
- readonly skill: string;
29
- }
30
- export interface SessionLoads {
31
- readonly skills: readonly string[];
32
- readonly readPaths: readonly string[];
33
- readonly compacted: boolean;
34
- }
35
- export interface SkillGateInput {
36
- readonly rules: SkillGateRules;
37
- readonly relativePath: string;
38
- readonly loadedSkills: readonly string[];
39
- readonly availableSkills: readonly string[];
40
- }
41
- export interface ProjectPath {
42
- readonly path: string;
43
- readonly relativePath: string;
44
- }
45
- export interface BashSkillGateInput {
46
- readonly rules: SkillGateRules;
47
- readonly paths: readonly ProjectPath[];
48
- readonly loadedSkills: readonly string[];
49
- readonly availableSkills: readonly string[];
50
- }
51
- export interface BashSkillGatePlan {
52
- readonly gatedPaths: readonly string[];
53
- readonly missing: readonly string[];
54
- }
55
- export interface SkillGatePlan {
56
- readonly missing: readonly string[];
57
- readonly unknown: readonly UnknownSkill[];
58
- }
59
- export interface ShellWord {
60
- readonly text: string;
61
- readonly literal: boolean;
62
- }
63
- export interface ShellRedirect {
64
- readonly operator: string;
65
- readonly target: ShellWord;
66
- }
67
- export interface ShellCommand {
68
- readonly words: readonly ShellWord[];
69
- readonly redirects: readonly ShellRedirect[];
70
- readonly stdin: string | null;
71
- readonly enters: number;
72
- readonly leaves: number;
73
- readonly guard?: ShellGuard | null;
74
- }
75
- export interface ShellGuard {
76
- readonly viaOr: boolean;
77
- readonly before: readonly (readonly ShellWord[])[];
78
- }
79
- export interface WrittenPath {
80
- readonly path: string;
81
- readonly fileName?: string;
82
- }
83
- export interface SkillGateOutputContext {
84
- readonly harness?: Harness;
85
- readonly compacted?: boolean;
86
- readonly rulesError?: string;
87
- readonly unknownKeys?: readonly string[];
88
- }
89
- export interface ToolGateInput {
90
- readonly tools: readonly ToolGate[];
91
- readonly toolName: string;
92
- readonly skillsDir: string;
93
- readonly loads: SessionLoads;
94
- readonly availableSkills: readonly string[];
95
- readonly availableReferences: readonly string[];
96
- }
97
- export interface UnknownToolRequirement {
98
- readonly tool: string;
99
- readonly kind: 'skill' | 'reference';
100
- readonly name: string;
101
- }
102
- export interface ToolGatePlan {
103
- readonly missingSkills: readonly string[];
104
- readonly missingReferences: readonly string[];
105
- readonly unknown: readonly UnknownToolRequirement[];
106
- }
107
- export interface SkillGateHookOutput {
108
- readonly systemMessage?: string;
109
- readonly hookSpecificOutput: {
110
- readonly hookEventName: 'PreToolUse';
111
- readonly permissionDecision?: 'deny';
112
- readonly permissionDecisionReason?: string;
113
- readonly additionalContext?: string;
114
- };
115
- }
116
- export type FileHashes = Readonly<Record<string, string | null>>;
117
- export type PostToolEvent = 'PostToolUse' | 'PostToolUseFailure';
118
- export type HookEvent = 'PreToolUse' | PostToolEvent;
119
- export type BashChangeHookOutput = {
120
- readonly decision: 'block';
121
- readonly reason: string;
122
- } | {
123
- readonly hookSpecificOutput: {
124
- readonly hookEventName: 'PostToolUseFailure';
125
- readonly additionalContext: string;
126
- };
127
- };
128
- export interface WorkTree {
129
- readonly head: string | null;
130
- readonly dirtyPaths: readonly string[];
131
- }
132
- export type BashSnapshot = Readonly<z.infer<typeof bashSnapshotSchema>>;
133
- export interface BashCheckFailureHookOutput {
134
- readonly systemMessage: string;
135
- readonly hookSpecificOutput: {
136
- readonly hookEventName: PostToolEvent;
137
- readonly additionalContext: string;
138
- };
139
- }
140
- export interface CommitRange {
141
- readonly from: string | null;
142
- readonly to: string;
143
- }
144
- export interface BashCandidates {
145
- readonly hashedPaths: readonly string[];
146
- readonly cleanBefore: readonly string[];
147
- }
148
- export type ReadFileContent = (filePath: string) => Promise<Uint8Array | null>;
149
- export type RecordedSnapshot = Extract<BashSnapshot, {
150
- kind: 'recorded';
151
- }>;
152
- export type BashComparison = {
153
- readonly kind: 'no-work-tree';
154
- } | {
155
- readonly kind: 'git-failed';
156
- readonly error: string;
157
- } | {
158
- readonly kind: 'compared';
159
- readonly changedPaths: readonly string[];
160
- };
161
- export type BashResultStep = {
162
- readonly kind: 'skip';
163
- } | {
164
- readonly kind: 'report';
165
- readonly error: string;
166
- } | {
167
- readonly kind: 'gate';
168
- readonly changedPaths: readonly string[];
169
- };
170
- export type RecordStep = Exclude<BashResultStep, {
171
- kind: 'gate';
172
- }> | {
173
- readonly kind: 'compare';
174
- readonly recorded: RecordedSnapshot;
175
- };
176
- export interface HarnessWording {
177
- readonly loadSkill: string;
178
- readonly readFile: string;
179
- readonly editTools: string;
180
- }
181
- export interface HookInput {
182
- readonly kind: 'tool';
183
- readonly harness: Harness;
184
- readonly event: HookEvent;
185
- readonly toolName: string | null;
186
- readonly cwd: string;
187
- readonly editPaths: readonly string[];
188
- readonly command: string | null;
189
- readonly transcriptPath: string | null;
190
- readonly sessionID: string | null;
191
- readonly toolUseID: unknown;
192
- readonly agentID: unknown;
193
- }
194
- export interface LifecycleInput {
195
- readonly kind: 'lifecycle';
196
- readonly event: 'UserPromptSubmit' | 'PostCompact';
197
- readonly cwd: string;
198
- readonly transcriptPath: string | null;
199
- readonly sessionID: string | null;
200
- readonly prompt: string | null;
201
- }
202
- export interface SessionState {
203
- readonly transcriptPath: string | null;
204
- readonly sessionID: string | null;
205
- }
206
- export interface EditEntry {
207
- readonly filePath: string;
208
- readonly plan: SkillGatePlan;
209
- }
@@ -1 +0,0 @@
1
- export declare function withLedgerLock<Result>(ledgerPath: string | null, job: () => Promise<Result>): Promise<Result>;