@dzhechkov/harness-core 0.8.11 → 0.8.21
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/.dz-manifest.json +399 -139
- package/LICENSE +13 -0
- package/README.md +420 -6
- package/dist/agents-policy.d.ts +15 -1
- package/dist/agents-policy.d.ts.map +1 -1
- package/dist/agents-policy.js +27 -1
- package/dist/agents-policy.js.map +1 -1
- package/dist/amendment-trace.d.ts +72 -0
- package/dist/amendment-trace.d.ts.map +1 -1
- package/dist/amendment-trace.js +385 -17
- package/dist/amendment-trace.js.map +1 -1
- package/dist/backlog-public.d.ts +153 -0
- package/dist/backlog-public.d.ts.map +1 -0
- package/dist/backlog-public.js +415 -0
- package/dist/backlog-public.js.map +1 -0
- package/dist/backlog-transitions.d.ts +48 -0
- package/dist/backlog-transitions.d.ts.map +1 -0
- package/dist/backlog-transitions.js +64 -0
- package/dist/backlog-transitions.js.map +1 -0
- package/dist/backlog.d.ts.map +1 -1
- package/dist/backlog.js +13 -0
- package/dist/backlog.js.map +1 -1
- package/dist/claim-check.d.ts.map +1 -1
- package/dist/claim-check.js +24 -2
- package/dist/claim-check.js.map +1 -1
- package/dist/claude-hooks-assets.d.ts +93 -0
- package/dist/claude-hooks-assets.d.ts.map +1 -0
- package/dist/claude-hooks-assets.js +208 -0
- package/dist/claude-hooks-assets.js.map +1 -0
- package/dist/clean-room-smoke.d.ts +83 -0
- package/dist/clean-room-smoke.d.ts.map +1 -0
- package/dist/clean-room-smoke.js +138 -0
- package/dist/clean-room-smoke.js.map +1 -0
- package/dist/cmd-usage.d.ts.map +1 -1
- package/dist/cmd-usage.js +36 -6
- package/dist/cmd-usage.js.map +1 -1
- package/dist/codex-hooks-assets.d.ts +25 -7
- package/dist/codex-hooks-assets.d.ts.map +1 -1
- package/dist/codex-hooks-assets.js +138 -30
- package/dist/codex-hooks-assets.js.map +1 -1
- package/dist/codex-hooks.d.ts +21 -1
- package/dist/codex-hooks.d.ts.map +1 -1
- package/dist/codex-hooks.js +21 -1
- package/dist/codex-hooks.js.map +1 -1
- package/dist/course-staleness.d.ts +19 -0
- package/dist/course-staleness.d.ts.map +1 -0
- package/dist/course-staleness.js +95 -0
- package/dist/course-staleness.js.map +1 -0
- package/dist/destructive-guard-hook.d.ts +40 -0
- package/dist/destructive-guard-hook.d.ts.map +1 -0
- package/dist/destructive-guard-hook.js +109 -0
- package/dist/destructive-guard-hook.js.map +1 -0
- package/dist/destructive-guard.d.ts +27 -0
- package/dist/destructive-guard.d.ts.map +1 -0
- package/dist/destructive-guard.js +2808 -0
- package/dist/destructive-guard.js.map +1 -0
- package/dist/discrimination-gate.d.ts +28 -3
- package/dist/discrimination-gate.d.ts.map +1 -1
- package/dist/discrimination-gate.js +76 -16
- package/dist/discrimination-gate.js.map +1 -1
- package/dist/feature-adr-routing.d.ts +95 -1
- package/dist/feature-adr-routing.d.ts.map +1 -1
- package/dist/feature-adr-routing.js +193 -27
- package/dist/feature-adr-routing.js.map +1 -1
- package/dist/guard.d.ts +90 -0
- package/dist/guard.d.ts.map +1 -1
- package/dist/guard.js +271 -0
- package/dist/guard.js.map +1 -1
- package/dist/harness-core-location.d.ts +18 -0
- package/dist/harness-core-location.d.ts.map +1 -0
- package/dist/harness-core-location.js +42 -0
- package/dist/harness-core-location.js.map +1 -0
- package/dist/index.d.ts +24 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24 -3
- package/dist/index.js.map +1 -1
- package/dist/lead-shift-gate.d.ts +95 -0
- package/dist/lead-shift-gate.d.ts.map +1 -0
- package/dist/lead-shift-gate.js +100 -0
- package/dist/lead-shift-gate.js.map +1 -0
- package/dist/ledger-backfill.d.ts +11 -1
- package/dist/ledger-backfill.d.ts.map +1 -1
- package/dist/ledger-backfill.js +19 -0
- package/dist/ledger-backfill.js.map +1 -1
- package/dist/loop-blobs.generated.d.ts +1 -1
- package/dist/loop-blobs.generated.d.ts.map +1 -1
- package/dist/loop-blobs.generated.js +12 -3
- package/dist/loop-blobs.generated.js.map +1 -1
- package/dist/loop-lint.d.ts.map +1 -1
- package/dist/loop-lint.js +56 -7
- package/dist/loop-lint.js.map +1 -1
- package/dist/loop-plan-graph.d.ts +1 -3
- package/dist/loop-plan-graph.d.ts.map +1 -1
- package/dist/loop-plan-graph.js +70 -1
- package/dist/loop-plan-graph.js.map +1 -1
- package/dist/loop-trace.d.ts.map +1 -1
- package/dist/loop-trace.js +16 -2
- package/dist/loop-trace.js.map +1 -1
- package/dist/managed-hooks.d.ts +5 -6
- package/dist/managed-hooks.d.ts.map +1 -1
- package/dist/managed-hooks.js +2 -2
- package/dist/managed-hooks.js.map +1 -1
- package/dist/model-recommender.d.ts.map +1 -1
- package/dist/model-recommender.js +14 -3
- package/dist/model-recommender.js.map +1 -1
- package/dist/operations.d.ts.map +1 -1
- package/dist/operations.js +82 -0
- package/dist/operations.js.map +1 -1
- package/dist/patterns.d.ts +23 -0
- package/dist/patterns.d.ts.map +1 -1
- package/dist/patterns.js +10 -0
- package/dist/patterns.js.map +1 -1
- package/dist/publish.d.ts +11 -0
- package/dist/publish.d.ts.map +1 -1
- package/dist/publish.js +16 -2
- package/dist/publish.js.map +1 -1
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +3 -2
- package/dist/registry.js.map +1 -1
- package/dist/score.d.ts.map +1 -1
- package/dist/score.js +15 -4
- package/dist/score.js.map +1 -1
- package/dist/session-retro.d.ts +121 -2
- package/dist/session-retro.d.ts.map +1 -1
- package/dist/session-retro.js +454 -11
- package/dist/session-retro.js.map +1 -1
- package/dist/setup.d.ts +28 -0
- package/dist/setup.d.ts.map +1 -1
- package/dist/setup.js +223 -6
- package/dist/setup.js.map +1 -1
- package/dist/sign.d.ts.map +1 -1
- package/dist/sign.js +18 -1
- package/dist/sign.js.map +1 -1
- package/dist/skills-verify.d.ts +34 -1
- package/dist/skills-verify.d.ts.map +1 -1
- package/dist/skills-verify.js +82 -0
- package/dist/skills-verify.js.map +1 -1
- package/dist/stage-line.d.ts +68 -0
- package/dist/stage-line.d.ts.map +1 -0
- package/dist/stage-line.js +129 -0
- package/dist/stage-line.js.map +1 -0
- package/dist/statusline.d.ts +99 -0
- package/dist/statusline.d.ts.map +1 -1
- package/dist/statusline.js +310 -44
- package/dist/statusline.js.map +1 -1
- package/dist/store-counts.d.ts +26 -0
- package/dist/store-counts.d.ts.map +1 -0
- package/dist/store-counts.js +125 -0
- package/dist/store-counts.js.map +1 -0
- package/dist/store-guard.d.ts +106 -0
- package/dist/store-guard.d.ts.map +1 -0
- package/dist/store-guard.js +294 -0
- package/dist/store-guard.js.map +1 -0
- package/dist/swarm-brief.d.ts +95 -0
- package/dist/swarm-brief.d.ts.map +1 -0
- package/dist/swarm-brief.js +660 -0
- package/dist/swarm-brief.js.map +1 -0
- package/dist/trace-bundle.d.ts +8 -0
- package/dist/trace-bundle.d.ts.map +1 -1
- package/dist/trace-bundle.js +11 -0
- package/dist/trace-bundle.js.map +1 -1
- package/package.json +12 -11
- package/sbom.json +804 -154
- package/src/agents-policy.ts +46 -2
- package/src/amendment-trace.ts +441 -19
- package/src/backlog-public.ts +503 -0
- package/src/backlog-transitions.ts +77 -0
- package/src/backlog.ts +12 -0
- package/src/claim-check.ts +25 -2
- package/src/claude-hooks-assets.ts +227 -0
- package/src/clean-room-smoke.ts +195 -0
- package/src/cmd-usage.ts +29 -5
- package/src/codex-hooks-assets.ts +140 -30
- package/src/codex-hooks.ts +21 -1
- package/src/course-staleness.ts +125 -0
- package/src/destructive-guard-hook.ts +151 -0
- package/src/destructive-guard.ts +3027 -0
- package/src/discrimination-gate.ts +98 -19
- package/src/feature-adr-routing.ts +220 -22
- package/src/guard.ts +318 -0
- package/src/harness-core-location.ts +44 -0
- package/src/index.ts +111 -3
- package/src/lead-shift-gate.ts +145 -0
- package/src/ledger-backfill.ts +20 -1
- package/src/loop-blobs.generated.ts +12 -3
- package/src/loop-lint.ts +52 -7
- package/src/loop-plan-graph.ts +66 -1
- package/src/loop-trace.ts +13 -1
- package/src/managed-hooks.ts +5 -6
- package/src/model-recommender.ts +14 -3
- package/src/operations.ts +75 -0
- package/src/patterns.ts +33 -0
- package/src/publish.ts +27 -2
- package/src/registry.ts +3 -2
- package/src/score.ts +16 -4
- package/src/session-retro.ts +466 -11
- package/src/setup.ts +246 -9
- package/src/sign.ts +18 -1
- package/src/skills-verify.ts +99 -1
- package/src/stage-line.ts +151 -0
- package/src/statusline.ts +396 -47
- package/src/store-counts.ts +154 -0
- package/src/store-guard.ts +388 -0
- package/src/swarm-brief.ts +661 -0
- package/src/trace-bundle.ts +10 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"course-staleness.d.ts","sourceRoot":"","sources":["../src/course-staleness.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,oBAAoB,GAC5B,YAAY,GACZ,mBAAmB,GACnB,mBAAmB,GACnB,cAAc,GACd,oBAAoB,GACpB,qBAAqB,GACrB,qBAAqB,CAAC;AAE1B,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzC,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1C;AAED,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,KAAK,EAAE,oBAAoB,CAAC;IACrC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AASD;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,oBAAoB,GAAG,qBAAqB,CAwF1F"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { compareVersions } from './publish.js';
|
|
2
|
+
const SEMVER = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
|
|
3
|
+
const PACKAGE_NAME = /^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/;
|
|
4
|
+
function isRecord(value) {
|
|
5
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Classify only the version evidence supplied by the caller. Obtaining a registry version is a
|
|
9
|
+
* caller responsibility; this function performs no filesystem, network, clock, or environment I/O.
|
|
10
|
+
*/
|
|
11
|
+
export function classifyCourseStaleness(input) {
|
|
12
|
+
const candidate = isRecord(input) ? input : undefined;
|
|
13
|
+
const source = candidate?.source;
|
|
14
|
+
// Presence and shape come first. Unknown values must never reach an equality comparison where
|
|
15
|
+
// two absences could be mistaken for parity.
|
|
16
|
+
if (!isRecord(source)
|
|
17
|
+
|| typeof source.package !== 'string'
|
|
18
|
+
|| source.package.trim() === ''
|
|
19
|
+
|| typeof source.version !== 'string'
|
|
20
|
+
|| source.version.trim() === '') {
|
|
21
|
+
return {
|
|
22
|
+
state: 'E2_UNSTAMPED',
|
|
23
|
+
reason: 'course.source.package and course.source.version must both be non-empty strings',
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const packageName = source.package.trim();
|
|
27
|
+
const courseVersion = source.version.trim();
|
|
28
|
+
if (!SEMVER.test(courseVersion)) {
|
|
29
|
+
return {
|
|
30
|
+
state: 'E3_INVALID_VERSION',
|
|
31
|
+
reason: `course.source.version is not valid semver: ${courseVersion}`,
|
|
32
|
+
courseVersion,
|
|
33
|
+
package: packageName,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const expectedPackage = typeof candidate?.expectedPackage === 'string'
|
|
37
|
+
? candidate.expectedPackage.trim()
|
|
38
|
+
: candidate?.expectedPackage;
|
|
39
|
+
if (!PACKAGE_NAME.test(packageName)
|
|
40
|
+
|| (expectedPackage !== null && expectedPackage !== undefined
|
|
41
|
+
&& (!PACKAGE_NAME.test(expectedPackage) || packageName !== expectedPackage))) {
|
|
42
|
+
return {
|
|
43
|
+
state: 'E4_PACKAGE_MISMATCH',
|
|
44
|
+
reason: expectedPackage
|
|
45
|
+
? `course.source.package ${packageName} does not match expectedPackage ${expectedPackage}`
|
|
46
|
+
: `course.source.package is not a valid npm package name: ${packageName}`,
|
|
47
|
+
courseVersion,
|
|
48
|
+
package: packageName,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const registryVersion = candidate?.registryVersion;
|
|
52
|
+
if (registryVersion === null || registryVersion === undefined) {
|
|
53
|
+
return {
|
|
54
|
+
state: 'E5_REGISTRY_UNKNOWN',
|
|
55
|
+
reason: 'registryVersion is absent, so package parity is unknown',
|
|
56
|
+
courseVersion,
|
|
57
|
+
package: packageName,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
if (typeof registryVersion !== 'string' || !SEMVER.test(registryVersion.trim())) {
|
|
61
|
+
return {
|
|
62
|
+
state: 'E3_INVALID_VERSION',
|
|
63
|
+
reason: `registryVersion is not valid semver: ${String(registryVersion)}`,
|
|
64
|
+
courseVersion,
|
|
65
|
+
package: packageName,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
const normalizedRegistryVersion = registryVersion.trim();
|
|
69
|
+
const ordering = compareVersions(courseVersion, normalizedRegistryVersion);
|
|
70
|
+
const common = {
|
|
71
|
+
courseVersion,
|
|
72
|
+
registryVersion: normalizedRegistryVersion,
|
|
73
|
+
package: packageName,
|
|
74
|
+
};
|
|
75
|
+
if (ordering === 0) {
|
|
76
|
+
return {
|
|
77
|
+
state: 'S0_SHIPPED',
|
|
78
|
+
reason: 'course.source.version equals registryVersion',
|
|
79
|
+
...common,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
if (ordering < 0) {
|
|
83
|
+
return {
|
|
84
|
+
state: 'S3_TUTORIAL_STALE',
|
|
85
|
+
reason: 'course.source.version is below registryVersion',
|
|
86
|
+
...common,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
state: 'S4_PACKAGE_BEHIND',
|
|
91
|
+
reason: 'course.source.version is above registryVersion',
|
|
92
|
+
...common,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=course-staleness.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"course-staleness.js","sourceRoot":"","sources":["../src/course-staleness.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAyB/C,MAAM,MAAM,GAAG,2HAA2H,CAAC;AAC3I,MAAM,YAAY,GAAG,oDAAoD,CAAC;AAE1E,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,uBAAuB,CAAC,KAA2B;IACjE,MAAM,SAAS,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IACtD,MAAM,MAAM,GAAG,SAAS,EAAE,MAAM,CAAC;IAEjC,8FAA8F;IAC9F,6CAA6C;IAC7C,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;WAChB,OAAO,MAAM,CAAC,OAAO,KAAK,QAAQ;WAClC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE;WAC5B,OAAO,MAAM,CAAC,OAAO,KAAK,QAAQ;WAClC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QAClC,OAAO;YACL,KAAK,EAAE,cAAc;YACrB,MAAM,E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,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC;QAChF,OAAO;YACL,KAAK,EAAE,oBAAoB;YAC3B,MAAM,EAAE,wCAAwC,MAAM,CAAC,eAAe,CAAC,EAAE;YACzE,aAAa;YACb,OAAO,EAAE,WAAW;SACrB,CAAC;IACJ,CAAC;IAED,MAAM,yBAAyB,GAAG,eAAe,CAAC,IAAI,EAAE,CAAC;IACzD,MAAM,QAAQ,GAAG,eAAe,CAAC,aAAa,EAAE,yBAAyB,CAAC,CAAC;IAC3E,MAAM,MAAM,GAAG;QACb,aAAa;QACb,eAAe,EAAE,yBAAyB;QAC1C,OAAO,EAAE,WAAW;KACrB,CAAC;IACF,IAAI,QAAQ,KAAK,CAAC,EAAE,CAAC;QACnB,OAAO;YACL,KAAK,EAAE,YAAY;YACnB,MAAM,EAAE,8CAA8C;YACtD,GAAG,MAAM;SACV,CAAC;IACJ,CAAC;IACD,IAAI,QAAQ,GAAG,CAAC,EAAE,CAAC;QACjB,OAAO;YACL,KAAK,EAAE,mBAAmB;YAC1B,MAAM,EAAE,gDAAgD;YACxD,GAAG,MAAM;SACV,CAAC;IACJ,CAAC;IACD,OAAO;QACL,KAAK,EAAE,mBAAmB;QAC1B,MAAM,EAAE,gDAAgD;QACxD,GAAG,MAAM;KACV,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** Prefix of a BLOCKING message. Must appear verbatim for a block to be attributed to this guard. */
|
|
2
|
+
export declare const DESTRUCTIVE_REFUSE_MARKER = "DZ-DESTRUCTIVE:";
|
|
3
|
+
/** Prefix of a non-blocking message: an `undecidable` verdict, or our own failure to read. */
|
|
4
|
+
export declare const DESTRUCTIVE_WARN_MARKER = "DZ-DESTRUCTIVE-WARN:";
|
|
5
|
+
/**
|
|
6
|
+
* Which host contract the payload follows. The two differ in ONE measured respect, so the
|
|
7
|
+
* difference is a parameter rather than a guess:
|
|
8
|
+
*
|
|
9
|
+
* - `claude` — Claude Code sends `tool_name` for every tool and the registered matcher is `^Bash$`.
|
|
10
|
+
* A payload whose `tool_name` is not a shell tool is skipped WITHOUT looking at any command field,
|
|
11
|
+
* which is what the host contract promises and what the test pins.
|
|
12
|
+
* - `codex` — AM-8 of `crossrt-2-codex-hooks`: key on the PRESENCE of `tool_input.command`, never on
|
|
13
|
+
* `tool_name` equality. Codex's shell tool has been observed under more than one name
|
|
14
|
+
* (`Bash|shell|local_shell` is the matcher the emitted registry entry already carries), so a
|
|
15
|
+
* tool_name test there would silently disarm the guard the day the runtime renames its tool.
|
|
16
|
+
*/
|
|
17
|
+
export type DestructiveHookHost = 'claude' | 'codex';
|
|
18
|
+
export interface DestructiveHookDecision {
|
|
19
|
+
/** 2 = block the call (the host contract on BOTH runtimes). 0 = let it through. */
|
|
20
|
+
readonly exitCode: 0 | 2;
|
|
21
|
+
/** Exactly what the hook body writes to stderr. Empty string ⇒ write nothing at all. */
|
|
22
|
+
readonly stderr: string;
|
|
23
|
+
/**
|
|
24
|
+
* What happened, for tests and for the helper's own notes log:
|
|
25
|
+
* `refuse` / `allow` / `undecidable` are the classifier's three outcomes;
|
|
26
|
+
* `skipped` = not a shell command, the classifier was never consulted;
|
|
27
|
+
* `unreadable` = the payload or the classifier failed us, and we passed rather than guessed.
|
|
28
|
+
*/
|
|
29
|
+
readonly outcome: 'refuse' | 'allow' | 'undecidable' | 'skipped' | 'unreadable';
|
|
30
|
+
/** The rule id from a refusal, so a note can record WHICH rule fired without the command line. */
|
|
31
|
+
readonly rule: string | null;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Turn one hook payload into an exit code and a piece of text. The whole policy, both hosts.
|
|
35
|
+
*
|
|
36
|
+
* @param payload the parsed stdin object, or `null`/anything else when it did not parse.
|
|
37
|
+
* @param host which host contract the payload follows — see {@link DestructiveHookHost}.
|
|
38
|
+
*/
|
|
39
|
+
export declare function decideDestructiveHook(payload: unknown, host: DestructiveHookHost): DestructiveHookDecision;
|
|
40
|
+
//# sourceMappingURL=destructive-guard-hook.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"destructive-guard-hook.d.ts","sourceRoot":"","sources":["../src/destructive-guard-hook.ts"],"names":[],"mappings":"AAsBA,qGAAqG;AACrG,eAAO,MAAM,yBAAyB,oBAAoB,CAAC;AAE3D,8FAA8F;AAC9F,eAAO,MAAM,uBAAuB,yBAAyB,CAAC;AAE9D;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,mBAAmB,GAAG,QAAQ,GAAG,OAAO,CAAC;AAKrD,MAAM,WAAW,uBAAuB;IACtC,mFAAmF;IACnF,QAAQ,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC;IACzB,wFAAwF;IACxF,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB;;;;;OAKG;IACH,QAAQ,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,GAAG,aAAa,GAAG,SAAS,GAAG,YAAY,CAAC;IAChF,kGAAkG;IAClG,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AAoDD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,mBAAmB,GAAG,uBAAuB,CAiC1G"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// destructive-guard-hook — the CONSUMER half of the destructive-command guard
|
|
2
|
+
// (feature `destructive-command-guard`, ADR-001, plan task T8).
|
|
3
|
+
//
|
|
4
|
+
// WHY THIS FILE EXISTS AT ALL. The classifier (`destructive-guard.ts`) already returned a verdict,
|
|
5
|
+
// and nothing on either host read it: the export existed, the consumer did not, so
|
|
6
|
+
// `rm -rf .agentic-qe` still executed on both runtimes. A verdict nobody consumes is a document,
|
|
7
|
+
// not a guard. This module is that consumer — and it is ONE module rather than two hook bodies,
|
|
8
|
+
// because the two hosts must give the SAME answer in the SAME words. A refusal text duplicated in
|
|
9
|
+
// two shell-spawned strings drifts silently the first time either is edited.
|
|
10
|
+
//
|
|
11
|
+
// PURE BY CONTRACT, exactly like the classifier it wraps: a payload in, an exit code and a piece of
|
|
12
|
+
// text out. No filesystem access, no subprocess, no environment. The hook bodies that call it read
|
|
13
|
+
// stdin, hand the parsed object over, print what comes back and exit with the code — nothing else.
|
|
14
|
+
//
|
|
15
|
+
// FAIL-OPEN ON OUR OWN FAILURE. Every branch that is not a decided `refuse` exits 0. An unparseable
|
|
16
|
+
// payload, a classifier that throws, a tool that is not a shell — none of them is evidence of a
|
|
17
|
+
// violation, and a guard that blocks on its own confusion is a guard the user switches off. This is
|
|
18
|
+
// the same polarity the sibling guards ship with (`claim-check-hook.cjs`, `dz-codex-veto.cjs`).
|
|
19
|
+
import { classifyDestructive } from './destructive-guard.js';
|
|
20
|
+
/** Prefix of a BLOCKING message. Must appear verbatim for a block to be attributed to this guard. */
|
|
21
|
+
export const DESTRUCTIVE_REFUSE_MARKER = 'DZ-DESTRUCTIVE:';
|
|
22
|
+
/** Prefix of a non-blocking message: an `undecidable` verdict, or our own failure to read. */
|
|
23
|
+
export const DESTRUCTIVE_WARN_MARKER = 'DZ-DESTRUCTIVE-WARN:';
|
|
24
|
+
/** Tool names that ARE a shell on the Claude host. */
|
|
25
|
+
const SHELL_TOOL_NAMES = new Set(['Bash', 'bash', 'shell', 'local_shell']);
|
|
26
|
+
/**
|
|
27
|
+
* Render the limits block from THE VERDICT's own list — never from a copy kept here.
|
|
28
|
+
*
|
|
29
|
+
* ADR-001 obliges the guard to NAME what it does not decide, in its own text, on every verdict it
|
|
30
|
+
* speaks about: a guard silent about its limits reads as a guarantee that recursive deletion is
|
|
31
|
+
* covered, and it is not. Re-listing them in this file would be a second copy free to drift from
|
|
32
|
+
* the classifier's; `verdict.limits` is the single source.
|
|
33
|
+
*/
|
|
34
|
+
function renderLimits(limits) {
|
|
35
|
+
const head = 'Чего этот страж НЕ решает (печатается при каждом вердикте, чтобы он не читался как гарантия):';
|
|
36
|
+
return [head, ...limits.map((l) => ` - ${l}`)].join('\n');
|
|
37
|
+
}
|
|
38
|
+
function renderRefusal(verdict) {
|
|
39
|
+
return [
|
|
40
|
+
`${DESTRUCTIVE_REFUSE_MARKER} ОТКАЗ — удаление по буквальному пути в защищаемое хранилище.`,
|
|
41
|
+
'',
|
|
42
|
+
`Путь: ${verdict.path ?? '(не назван)'}`,
|
|
43
|
+
`Правило: ${verdict.rule ?? '(не названо)'}`,
|
|
44
|
+
`Причина: ${verdict.reason}`,
|
|
45
|
+
'',
|
|
46
|
+
renderLimits(verdict.limits),
|
|
47
|
+
'',
|
|
48
|
+
'Санкционированное удаление защищаемого хранилища выполняет владелец вручную, вне сеанса агента.',
|
|
49
|
+
'',
|
|
50
|
+
].join('\n');
|
|
51
|
+
}
|
|
52
|
+
function renderUndecidable(verdict) {
|
|
53
|
+
return [
|
|
54
|
+
`${DESTRUCTIVE_WARN_MARKER} команду не удалось разобрать (${verdict.reason}) — ПРОПУЩЕНА без отказа: «проверить не удалось» никогда не выдаётся за «запрещено» (AC-10).`,
|
|
55
|
+
renderLimits(verdict.limits),
|
|
56
|
+
'',
|
|
57
|
+
].join('\n');
|
|
58
|
+
}
|
|
59
|
+
function unreadable(message) {
|
|
60
|
+
return {
|
|
61
|
+
exitCode: 0,
|
|
62
|
+
// One line, and no limits block: there is no verdict here to quote limits FROM, and inventing
|
|
63
|
+
// one would be the same lie in the other direction.
|
|
64
|
+
stderr: `${DESTRUCTIVE_WARN_MARKER} ${message} — пропуск без отказа; отсутствие вердикта нарушением не является.\n`,
|
|
65
|
+
outcome: 'unreadable',
|
|
66
|
+
rule: null,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
const SKIP = { exitCode: 0, stderr: '', outcome: 'skipped', rule: null };
|
|
70
|
+
const ALLOW = { exitCode: 0, stderr: '', outcome: 'allow', rule: null };
|
|
71
|
+
/**
|
|
72
|
+
* Turn one hook payload into an exit code and a piece of text. The whole policy, both hosts.
|
|
73
|
+
*
|
|
74
|
+
* @param payload the parsed stdin object, or `null`/anything else when it did not parse.
|
|
75
|
+
* @param host which host contract the payload follows — see {@link DestructiveHookHost}.
|
|
76
|
+
*/
|
|
77
|
+
export function decideDestructiveHook(payload, host) {
|
|
78
|
+
if (payload === null || typeof payload !== 'object') {
|
|
79
|
+
return unreadable('полезная нагрузка хука не прочиталась');
|
|
80
|
+
}
|
|
81
|
+
const p = payload;
|
|
82
|
+
if (host === 'claude') {
|
|
83
|
+
// The Claude contract: decide from the tool NAME first, and on a non-shell tool return before
|
|
84
|
+
// any command field is even looked at.
|
|
85
|
+
const toolName = typeof p.tool_name === 'string' ? p.tool_name : '';
|
|
86
|
+
if (!SHELL_TOOL_NAMES.has(toolName))
|
|
87
|
+
return SKIP;
|
|
88
|
+
}
|
|
89
|
+
const input = p.tool_input;
|
|
90
|
+
const command = input !== null && typeof input === 'object' ? input.command : undefined;
|
|
91
|
+
if (typeof command !== 'string' || command === '')
|
|
92
|
+
return SKIP;
|
|
93
|
+
let verdict;
|
|
94
|
+
try {
|
|
95
|
+
verdict = classifyDestructive(command);
|
|
96
|
+
}
|
|
97
|
+
catch (err) {
|
|
98
|
+
// Our own failure. Never a refusal — see the FAIL-OPEN note at the top of the file.
|
|
99
|
+
return unreadable(`классификатор не смог вынести вердикт (${String(err?.message ?? err)})`);
|
|
100
|
+
}
|
|
101
|
+
if (verdict.outcome === 'refuse') {
|
|
102
|
+
return { exitCode: 2, stderr: renderRefusal(verdict), outcome: 'refuse', rule: verdict.rule };
|
|
103
|
+
}
|
|
104
|
+
if (verdict.outcome === 'undecidable') {
|
|
105
|
+
return { exitCode: 0, stderr: renderUndecidable(verdict), outcome: 'undecidable', rule: null };
|
|
106
|
+
}
|
|
107
|
+
return ALLOW;
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=destructive-guard-hook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"destructive-guard-hook.js","sourceR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AC;IAED,MAAM,KAAK,GAAG,CAAC,CAAC,UAAU,CAAC;IAC3B,MAAM,OAAO,GAAG,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAE,KAA+B,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;IACnH,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,EAAE;QAAE,OAAO,IAAI,CAAC;IAE/D,IAAI,OAA2B,CAAC;IAChC,IAAI,CAAC;QACH,OAAO,GAAG,mBAAmB,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,oFAAoF;QACpF,OAAO,UAAU,CAAC,0CAA0C,MAAM,CAAE,GAAa,EAAE,OAAO,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IACzG,CAAC;IAED,IAAI,OAAO,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;QACjC,OAAO,EAAE,QAAQ,EAAE,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC;IAChG,CAAC;IACD,IAAI,OAAO,CAAC,OAAO,KAAK,aAAa,EAAE,CAAC;QACtC,OAAO,EAAE,QAAQ,EAAE,CAAC,EAAE,MAAM,EAAE,iBAAiB,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IACjG,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** A verdict on one shell command. `limits` is always populated — see LIMITS below. */
|
|
2
|
+
export interface DestructiveVerdict {
|
|
3
|
+
/** `refuse` = block it. `allow` = out of scope. `undecidable` = could not parse; consumer PASSES. */
|
|
4
|
+
outcome: 'refuse' | 'allow' | 'undecidable';
|
|
5
|
+
/** The literal path that triggered the refusal, as the SHELL would pass it to the program. */
|
|
6
|
+
path: string | null;
|
|
7
|
+
/** The id of the rule that fired — one of DESTRUCTIVE_RULES. */
|
|
8
|
+
rule: string | null;
|
|
9
|
+
/** One line naming what was decided and why. A refusal always names the path and the rule. */
|
|
10
|
+
reason: string;
|
|
11
|
+
/** What this guard does NOT decide. Printed on EVERY verdict, refusals included. */
|
|
12
|
+
limits: readonly string[];
|
|
13
|
+
}
|
|
14
|
+
/** The complete rule table. A refusal always carries one of these ids. */
|
|
15
|
+
export declare const DESTRUCTIVE_RULES: readonly {
|
|
16
|
+
id: string;
|
|
17
|
+
what: string;
|
|
18
|
+
}[];
|
|
19
|
+
/**
|
|
20
|
+
* Decide whether a shell command must be refused BEFORE it runs.
|
|
21
|
+
*
|
|
22
|
+
* Refuses only when it can name a concrete literal path and the rule that path broke. Everything
|
|
23
|
+
* else is allowed, and every verdict prints the guard's limits (LIMITS) so it is never read as a
|
|
24
|
+
* total guarantee.
|
|
25
|
+
*/
|
|
26
|
+
export declare function classifyDestructive(command: string): DestructiveVerdict;
|
|
27
|
+
//# sourceMappingURL=destructive-guard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"destructive-guard.d.ts","sourceRoot":"","sources":["../src/destructive-guard.ts"],"names":[],"mappings":"AAkBA,uFAAuF;AACvF,MAAM,WAAW,kBAAkB;IACjC,qGAAqG;IACrG,OAAO,EAAE,QAAQ,GAAG,OAAO,GAAG,aAAa,CAAC;IAC5C,8FAA8F;IAC9F,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,gEAAgE;IAChE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,8FAA8F;IAC9F,MAAM,EAAE,MAAM,CAAC;IACf,oFAAoF;IACpF,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;CAC3B;AAiBD,0EAA0E;AAC1E,eAAO,MAAM,iBAAiB,EAAE,SAAS;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EAInE,CAAC;AA4rFH;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,kBAAkB,CAoBvE"}
|