rulereceipt 0.1.49 → 0.1.50
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 -1
- package/dist/cli.js +4 -1
- package/dist/guard.d.ts +28 -0
- package/dist/guard.js +38 -61
- package/dist/parsers/transcriptParser.d.ts +6 -0
- package/dist/parsers/transcriptParser.js +13 -0
- package/dist/projectConfig.d.ts +11 -2
- package/dist/projectConfig.js +46 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -403,11 +403,17 @@ rules --list`):
|
|
|
403
403
|
"a1b2c3": "off", // hidden from the report, never gates
|
|
404
404
|
"d4e5f6": "warn", // shown, but does not fail the build
|
|
405
405
|
"97h8i9": "error" // shown, FAILS the build — the default for a checkable rule
|
|
406
|
+
},
|
|
407
|
+
"checks": {
|
|
408
|
+
"emoji": "off", // silence a whole check type by name
|
|
409
|
+
"git": "warn" // emoji, attribution, approval, git, files, code, claim, tests, judgment
|
|
406
410
|
}
|
|
407
411
|
}
|
|
408
412
|
```
|
|
409
413
|
|
|
410
|
-
|
|
414
|
+
A per-rule `rules` entry wins over a per-check `checks` entry, which wins over
|
|
415
|
+
the default. No config means today's behaviour: every checkable FAIL is an
|
|
416
|
+
`error`. This is
|
|
411
417
|
the one place severity lives — a team marks the must-not-break rules `error`
|
|
412
418
|
and the nice-to-haves `warn`, so CI gates on what matters instead of going red
|
|
413
419
|
on day one. (Refusing a command *before* it runs is separate, and stays with
|
package/dist/cli.js
CHANGED
|
@@ -6,7 +6,7 @@ import { join, dirname, resolve, isAbsolute } from "node:path";
|
|
|
6
6
|
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
import { parseClaudeMd } from "./parsers/readClaudeMd.js";
|
|
9
|
-
import { readLatestTranscript, readTranscriptFromFile, findLatestSessionFile } from "./parsers/transcriptParser.js";
|
|
9
|
+
import { readLatestTranscript, readTranscriptFromFile, findLatestSessionFile, subagentNote } from "./parsers/transcriptParser.js";
|
|
10
10
|
import { loadRules } from "./rules.js";
|
|
11
11
|
import { adviseRules } from "./checkability.js";
|
|
12
12
|
import { shadowedAgentsMd } from "./shadowedAgents.js";
|
|
@@ -283,6 +283,9 @@ async function runCheck(opts) {
|
|
|
283
283
|
}
|
|
284
284
|
else {
|
|
285
285
|
console.log(reportText);
|
|
286
|
+
const subNote = subagentNote(sessionFilePath);
|
|
287
|
+
if (subNote)
|
|
288
|
+
console.log(`\n${subNote}`);
|
|
286
289
|
}
|
|
287
290
|
// Shown only to someone who has just read their own broken rules, and only
|
|
288
291
|
// if they have not already wired it up. See report/gateOffer.ts.
|
package/dist/guard.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import type { Rule } from "./types.js";
|
|
2
|
+
interface Block {
|
|
3
|
+
rule: Rule;
|
|
4
|
+
why: string;
|
|
5
|
+
}
|
|
1
6
|
/**
|
|
2
7
|
* A PreToolUse hook that refuses a command before it runs.
|
|
3
8
|
*
|
|
@@ -39,4 +44,27 @@
|
|
|
39
44
|
* 3. It says which rule and why, in the refusal itself, because a block with
|
|
40
45
|
* no reason is indistinguishable from a broken tool.
|
|
41
46
|
*/
|
|
47
|
+
export interface GuardDecision {
|
|
48
|
+
/** True when the proposed call breaks a rule and should be refused. */
|
|
49
|
+
deny: boolean;
|
|
50
|
+
/** The message for the model, or "" when allowed. */
|
|
51
|
+
reason: string;
|
|
52
|
+
/** The rules that would refuse it, empty when allowed. */
|
|
53
|
+
blocks: Block[];
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The allow/deny decision for one proposed tool call, with no I/O.
|
|
57
|
+
*
|
|
58
|
+
* Extracted from runGuard 2026-09-25 so the decision is a pure function the
|
|
59
|
+
* shell hook calls today and any future host — an in-process function hook,
|
|
60
|
+
* a different runtime — calls tomorrow without re-deriving the logic. The
|
|
61
|
+
* function-hook interface is still an unshipped Anthropic proposal (#91870),
|
|
62
|
+
* so nothing here targets it; this is only the seam that keeps the adapter
|
|
63
|
+
* thin when it lands. Same reasoning as evaluateSession: one body of code so
|
|
64
|
+
* two callers can never disagree about whether a rule was broken.
|
|
65
|
+
*/
|
|
66
|
+
export declare function guardDecision(cwd: string, toolName: string, toolInput: {
|
|
67
|
+
command?: unknown;
|
|
68
|
+
} & Record<string, unknown>): GuardDecision;
|
|
42
69
|
export declare function runGuard(): Promise<void>;
|
|
70
|
+
export {};
|
package/dist/guard.js
CHANGED
|
@@ -143,46 +143,42 @@ function reason(blocks) {
|
|
|
143
143
|
`\n\nIf the rule should not apply here, say so to the user and let them decide. Do not work around the rule by rephrasing the command.`);
|
|
144
144
|
}
|
|
145
145
|
/**
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
* done was "far worse than a force push". A report would have described a
|
|
156
|
-
* database that was already gone.
|
|
157
|
-
*
|
|
158
|
-
* What it does NOT do is the thing it was built for. Blocking on a rule's
|
|
159
|
-
* banned command literal was measured before shipping and cut: see the note
|
|
160
|
-
* above `reason`. It refused 62% of 16,336 real commands, and the residue
|
|
161
|
-
* after two rounds of narrowing was still wrong in a way no matcher fixes.
|
|
162
|
-
* PocketOS would not have been stopped by this hook, and saying otherwise
|
|
163
|
-
* would be the exact failure this tool exists to catch.
|
|
164
|
-
*
|
|
165
|
-
* What remains is real and narrower: rules that name a FILE or a BRANCH.
|
|
166
|
-
* "Never modify `.env`", "never touch `migrations/`", "never commit to
|
|
167
|
-
* `main`". The classifier identified those as a path or a ref rather than
|
|
168
|
-
* guessing which backtick was the prohibition, so a refusal can be stated
|
|
169
|
-
* with a reason that holds up.
|
|
170
|
-
*
|
|
171
|
-
* Three properties, in the order they matter:
|
|
172
|
-
*
|
|
173
|
-
* 1. FORBIDDING rules only, answered by a structured checker. Never a
|
|
174
|
-
* judgment rule, never an LLM opinion, never a requirement, and never a
|
|
175
|
-
* bare command literal. Blocking someone's terminal on a guess is not a
|
|
176
|
-
* trade worth making at any hit rate.
|
|
177
|
-
*
|
|
178
|
-
* 2. It fails OPEN. Any error allows the command and writes to stderr. The
|
|
179
|
-
* opposite choice means a bug in this file stops someone from running
|
|
180
|
-
* anything at all, and they would remove the hook within the hour — which
|
|
181
|
-
* leaves them with no guard rather than an imperfect one.
|
|
182
|
-
*
|
|
183
|
-
* 3. It says which rule and why, in the refusal itself, because a block with
|
|
184
|
-
* no reason is indistinguishable from a broken tool.
|
|
146
|
+
* The allow/deny decision for one proposed tool call, with no I/O.
|
|
147
|
+
*
|
|
148
|
+
* Extracted from runGuard 2026-09-25 so the decision is a pure function the
|
|
149
|
+
* shell hook calls today and any future host — an in-process function hook,
|
|
150
|
+
* a different runtime — calls tomorrow without re-deriving the logic. The
|
|
151
|
+
* function-hook interface is still an unshipped Anthropic proposal (#91870),
|
|
152
|
+
* so nothing here targets it; this is only the seam that keeps the adapter
|
|
153
|
+
* thin when it lands. Same reasoning as evaluateSession: one body of code so
|
|
154
|
+
* two callers can never disagree about whether a rule was broken.
|
|
185
155
|
*/
|
|
156
|
+
export function guardDecision(cwd, toolName, toolInput) {
|
|
157
|
+
const allow = { deny: false, reason: "", blocks: [] };
|
|
158
|
+
if (loadRules(cwd).length === 0)
|
|
159
|
+
return allow;
|
|
160
|
+
let blocks = [];
|
|
161
|
+
if (toolName === "Bash" && typeof toolInput.command === "string") {
|
|
162
|
+
const event = {
|
|
163
|
+
role: "assistant", kind: "tool_use", toolName: "Bash",
|
|
164
|
+
input: { command: toolInput.command }, timestamp: "",
|
|
165
|
+
};
|
|
166
|
+
blocks = [...structuredBlocks(cwd, event), ...ratifiedLiteralBlocks(cwd, toolInput.command)];
|
|
167
|
+
}
|
|
168
|
+
else if (toolName === "Write" || toolName === "Edit" || toolName === "NotebookEdit") {
|
|
169
|
+
const event = {
|
|
170
|
+
role: "assistant", kind: "tool_use", toolName,
|
|
171
|
+
input: toolInput, timestamp: "",
|
|
172
|
+
};
|
|
173
|
+
blocks = structuredBlocks(cwd, event);
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
return allow;
|
|
177
|
+
}
|
|
178
|
+
if (blocks.length === 0)
|
|
179
|
+
return allow;
|
|
180
|
+
return { deny: true, reason: reason(blocks), blocks };
|
|
181
|
+
}
|
|
186
182
|
export async function runGuard() {
|
|
187
183
|
const allow = () => {
|
|
188
184
|
process.stdout.write(JSON.stringify({}));
|
|
@@ -193,29 +189,10 @@ export async function runGuard() {
|
|
|
193
189
|
const cwd = input.cwd || process.cwd();
|
|
194
190
|
const tool = input.tool_name ?? "";
|
|
195
191
|
const toolInput = input.tool_input ?? {};
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
let blocks = [];
|
|
199
|
-
if (tool === "Bash" && typeof toolInput.command === "string") {
|
|
200
|
-
const event = {
|
|
201
|
-
role: "assistant", kind: "tool_use", toolName: "Bash",
|
|
202
|
-
input: { command: toolInput.command }, timestamp: "",
|
|
203
|
-
};
|
|
204
|
-
blocks = [...structuredBlocks(cwd, event), ...ratifiedLiteralBlocks(cwd, toolInput.command)];
|
|
205
|
-
}
|
|
206
|
-
else if (tool === "Write" || tool === "Edit" || tool === "NotebookEdit") {
|
|
207
|
-
const event = {
|
|
208
|
-
role: "assistant", kind: "tool_use", toolName: tool,
|
|
209
|
-
input: toolInput, timestamp: "",
|
|
210
|
-
};
|
|
211
|
-
blocks = structuredBlocks(cwd, event);
|
|
212
|
-
}
|
|
213
|
-
else {
|
|
214
|
-
return allow();
|
|
215
|
-
}
|
|
216
|
-
if (blocks.length === 0)
|
|
192
|
+
const decision = guardDecision(cwd, tool, toolInput);
|
|
193
|
+
if (!decision.deny)
|
|
217
194
|
return allow();
|
|
218
|
-
const why = reason
|
|
195
|
+
const why = decision.reason;
|
|
219
196
|
process.stdout.write(JSON.stringify({
|
|
220
197
|
hookSpecificOutput: {
|
|
221
198
|
hookEventName: "PreToolUse",
|
|
@@ -36,4 +36,10 @@ export declare function readTranscriptFromFile(filePath: string): TranscriptEven
|
|
|
36
36
|
* false negative — the safe direction for a tool that must not over-accuse.
|
|
37
37
|
*/
|
|
38
38
|
export declare function findSubagentFiles(sessionFile: string): string[];
|
|
39
|
+
/**
|
|
40
|
+
* A one-line note for the report so a user knows their subagents were included
|
|
41
|
+
* in the check — otherwise the coverage is invisible and they might think a
|
|
42
|
+
* violation a subagent committed went unseen. Null when there were none.
|
|
43
|
+
*/
|
|
44
|
+
export declare function subagentNote(sessionFile: string | null): string | null;
|
|
39
45
|
export declare function readLatestTranscript(cwd: string): TranscriptEvent[];
|
|
@@ -197,6 +197,19 @@ export function findSubagentFiles(sessionFile) {
|
|
|
197
197
|
const subagentDir = join(dirname(sessionFile), sessionId, "subagents");
|
|
198
198
|
return listSessionFiles(subagentDir);
|
|
199
199
|
}
|
|
200
|
+
/**
|
|
201
|
+
* A one-line note for the report so a user knows their subagents were included
|
|
202
|
+
* in the check — otherwise the coverage is invisible and they might think a
|
|
203
|
+
* violation a subagent committed went unseen. Null when there were none.
|
|
204
|
+
*/
|
|
205
|
+
export function subagentNote(sessionFile) {
|
|
206
|
+
if (!sessionFile)
|
|
207
|
+
return null;
|
|
208
|
+
const n = findSubagentFiles(sessionFile).length;
|
|
209
|
+
if (n === 0)
|
|
210
|
+
return null;
|
|
211
|
+
return `Checked ${n} subagent session${n === 1 ? "" : "s"} alongside the main one — their actions are held to the same rules.`;
|
|
212
|
+
}
|
|
200
213
|
export function readLatestTranscript(cwd) {
|
|
201
214
|
const filePath = findLatestSessionFile(cwd);
|
|
202
215
|
if (!filePath)
|
package/dist/projectConfig.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CheckResult, Rule } from "./types.js";
|
|
1
|
+
import type { CheckResult, CheckMethod, Rule } from "./types.js";
|
|
2
2
|
/**
|
|
3
3
|
* A committed, team-shared config at .rulereceipt/config.json.
|
|
4
4
|
*
|
|
@@ -31,11 +31,20 @@ export type RuleMode = "off" | "warn" | "error";
|
|
|
31
31
|
export interface ProjectConfig {
|
|
32
32
|
warn: string[];
|
|
33
33
|
rules: Record<string, RuleMode>;
|
|
34
|
+
/** A whole check type, by friendly name (see CHECK_ALIASES) or raw method. */
|
|
35
|
+
checks: Record<string, RuleMode>;
|
|
34
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Friendly names for a check type, so `checks: { "emoji": "off" }` silences
|
|
39
|
+
* every emoji verdict without listing each rule. A result carries a `method`
|
|
40
|
+
* (e.g. "emoji_output"); these are the human-facing aliases for those.
|
|
41
|
+
*/
|
|
42
|
+
export declare const CHECK_ALIASES: Record<string, CheckMethod>;
|
|
35
43
|
export declare const PROJECT_CONFIG_PATH: string;
|
|
36
44
|
export declare function loadProjectConfig(cwd: string): ProjectConfig;
|
|
37
45
|
/**
|
|
38
|
-
* The mode for one result. `rules` wins over
|
|
46
|
+
* The mode for one result. Precedence: a per-rule `rules` entry wins over a
|
|
47
|
+
* per-check `checks` entry, which wins over the legacy `warn` list; anything
|
|
39
48
|
* unlisted is `error`, so the default is unchanged and no config means today's
|
|
40
49
|
* behaviour exactly.
|
|
41
50
|
*/
|
package/dist/projectConfig.js
CHANGED
|
@@ -2,28 +2,62 @@ import { readFileSync } from "node:fs";
|
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { ruleFingerprint } from "./overrides.js";
|
|
4
4
|
const VALID_MODES = ["off", "warn", "error"];
|
|
5
|
+
/**
|
|
6
|
+
* Friendly names for a check type, so `checks: { "emoji": "off" }` silences
|
|
7
|
+
* every emoji verdict without listing each rule. A result carries a `method`
|
|
8
|
+
* (e.g. "emoji_output"); these are the human-facing aliases for those.
|
|
9
|
+
*/
|
|
10
|
+
export const CHECK_ALIASES = {
|
|
11
|
+
emoji: "emoji_output",
|
|
12
|
+
attribution: "attribution_scan",
|
|
13
|
+
approval: "approval_gate",
|
|
14
|
+
git: "git_events",
|
|
15
|
+
files: "file_events",
|
|
16
|
+
code: "code_content",
|
|
17
|
+
claim: "claim_vs_evidence",
|
|
18
|
+
tests: "edit_test_pairing",
|
|
19
|
+
text: "text_scan",
|
|
20
|
+
judgment: "model_judgment",
|
|
21
|
+
};
|
|
5
22
|
export const PROJECT_CONFIG_PATH = join(".rulereceipt", "config.json");
|
|
6
23
|
export function loadProjectConfig(cwd) {
|
|
7
24
|
try {
|
|
8
25
|
const parsed = JSON.parse(readFileSync(join(cwd, PROJECT_CONFIG_PATH), "utf-8"));
|
|
9
26
|
const warn = Array.isArray(parsed?.warn) ? parsed.warn.filter((x) => typeof x === "string") : [];
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
27
|
+
const readModes = (raw) => {
|
|
28
|
+
const out = {};
|
|
29
|
+
if (raw && typeof raw === "object" && !Array.isArray(raw)) {
|
|
30
|
+
for (const [key, mode] of Object.entries(raw)) {
|
|
31
|
+
if (typeof mode === "string" && VALID_MODES.includes(mode))
|
|
32
|
+
out[key] = mode;
|
|
33
|
+
}
|
|
15
34
|
}
|
|
16
|
-
|
|
17
|
-
|
|
35
|
+
return out;
|
|
36
|
+
};
|
|
37
|
+
return { warn, rules: readModes(parsed?.rules), checks: readModes(parsed?.checks) };
|
|
18
38
|
}
|
|
19
39
|
catch {
|
|
20
40
|
// Missing or malformed config means no severities configured, never an
|
|
21
41
|
// error — same fail-open discipline as the rest of the tool.
|
|
22
|
-
return { warn: [], rules: {} };
|
|
42
|
+
return { warn: [], rules: {}, checks: {} };
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/** The mode a `checks` entry sets for a result's method, if any. */
|
|
46
|
+
function checkMode(method, config) {
|
|
47
|
+
if (!method || !config.checks || Object.keys(config.checks).length === 0)
|
|
48
|
+
return undefined;
|
|
49
|
+
// A raw method key ("emoji_output") wins over its friendly alias ("emoji").
|
|
50
|
+
if (config.checks[method])
|
|
51
|
+
return config.checks[method];
|
|
52
|
+
for (const [alias, m] of Object.entries(CHECK_ALIASES)) {
|
|
53
|
+
if (m === method && config.checks[alias])
|
|
54
|
+
return config.checks[alias];
|
|
23
55
|
}
|
|
56
|
+
return undefined;
|
|
24
57
|
}
|
|
25
58
|
/**
|
|
26
|
-
* The mode for one result. `rules` wins over
|
|
59
|
+
* The mode for one result. Precedence: a per-rule `rules` entry wins over a
|
|
60
|
+
* per-check `checks` entry, which wins over the legacy `warn` list; anything
|
|
27
61
|
* unlisted is `error`, so the default is unchanged and no config means today's
|
|
28
62
|
* behaviour exactly.
|
|
29
63
|
*/
|
|
@@ -31,6 +65,9 @@ export function modeForResult(result, config, handleFor) {
|
|
|
31
65
|
const handle = handleFor(result);
|
|
32
66
|
if (config.rules[handle])
|
|
33
67
|
return config.rules[handle];
|
|
68
|
+
const byCheck = checkMode(result.method, config);
|
|
69
|
+
if (byCheck)
|
|
70
|
+
return byCheck;
|
|
34
71
|
if (config.warn.includes(handle))
|
|
35
72
|
return "warn";
|
|
36
73
|
return "error";
|