@webpieces/hook-runtime 0.0.1
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/package.json +37 -0
- package/src/adapters/agent-adapters.d.ts +13 -0
- package/src/adapters/agent-adapters.js +23 -0
- package/src/adapters/agent-adapters.js.map +1 -0
- package/src/adapters/agent-payload.d.ts +48 -0
- package/src/adapters/agent-payload.js +30 -0
- package/src/adapters/agent-payload.js.map +1 -0
- package/src/adapters/claude-code-adapter.d.ts +26 -0
- package/src/adapters/claude-code-adapter.js +69 -0
- package/src/adapters/claude-code-adapter.js.map +1 -0
- package/src/adapters/codex-adapter.d.ts +19 -0
- package/src/adapters/codex-adapter.js +48 -0
- package/src/adapters/codex-adapter.js.map +1 -0
- package/src/adapters/detect-ai.d.ts +70 -0
- package/src/adapters/detect-ai.js +82 -0
- package/src/adapters/detect-ai.js.map +1 -0
- package/src/core/apply-patch-parse.d.ts +36 -0
- package/src/core/apply-patch-parse.js +155 -0
- package/src/core/apply-patch-parse.js.map +1 -0
- package/src/core/build-context.d.ts +11 -0
- package/src/core/build-context.js +69 -0
- package/src/core/build-context.js.map +1 -0
- package/src/core/command-scan.d.ts +122 -0
- package/src/core/command-scan.js +282 -0
- package/src/core/command-scan.js.map +1 -0
- package/src/core/custom-rule-adapter.d.ts +23 -0
- package/src/core/custom-rule-adapter.js +50 -0
- package/src/core/custom-rule-adapter.js.map +1 -0
- package/src/core/delete-scoped-rules.d.ts +9 -0
- package/src/core/delete-scoped-rules.js +31 -0
- package/src/core/delete-scoped-rules.js.map +1 -0
- package/src/core/disable-directives.d.ts +8 -0
- package/src/core/disable-directives.js +86 -0
- package/src/core/disable-directives.js.map +1 -0
- package/src/core/effective-tree.d.ts +197 -0
- package/src/core/effective-tree.js +269 -0
- package/src/core/effective-tree.js.map +1 -0
- package/src/core/excluded-paths.d.ts +23 -0
- package/src/core/excluded-paths.js +54 -0
- package/src/core/excluded-paths.js.map +1 -0
- package/src/core/file-evaluation.d.ts +11 -0
- package/src/core/file-evaluation.js +45 -0
- package/src/core/file-evaluation.js.map +1 -0
- package/src/core/fix-hint.d.ts +40 -0
- package/src/core/fix-hint.js +53 -0
- package/src/core/fix-hint.js.map +1 -0
- package/src/core/glob.d.ts +1 -0
- package/src/core/glob.js +42 -0
- package/src/core/glob.js.map +1 -0
- package/src/core/report.d.ts +21 -0
- package/src/core/report.js +74 -0
- package/src/core/report.js.map +1 -0
- package/src/core/root-manifest.d.ts +1 -0
- package/src/core/root-manifest.js +21 -0
- package/src/core/root-manifest.js.map +1 -0
- package/src/core/rule-base.d.ts +40 -0
- package/src/core/rule-base.js +37 -0
- package/src/core/rule-base.js.map +1 -0
- package/src/core/rule-evaluation.d.ts +18 -0
- package/src/core/rule-evaluation.js +179 -0
- package/src/core/rule-evaluation.js.map +1 -0
- package/src/core/rules/shell-segment-scan.d.ts +64 -0
- package/src/core/rules/shell-segment-scan.js +88 -0
- package/src/core/rules/shell-segment-scan.js.map +1 -0
- package/src/core/shell-read-parity.d.ts +34 -0
- package/src/core/shell-read-parity.js +157 -0
- package/src/core/shell-read-parity.js.map +1 -0
- package/src/core/strip-ts-noise.d.ts +1 -0
- package/src/core/strip-ts-noise.js +191 -0
- package/src/core/strip-ts-noise.js.map +1 -0
- package/src/core/target-tree.d.ts +84 -0
- package/src/core/target-tree.js +148 -0
- package/src/core/target-tree.js.map +1 -0
- package/src/core/types.d.ts +149 -0
- package/src/core/types.js +190 -0
- package/src/core/types.js.map +1 -0
- package/src/harness-vocabulary.d.ts +2 -0
- package/src/harness-vocabulary.js +10 -0
- package/src/harness-vocabulary.js.map +1 -0
- package/src/hook-app.d.ts +15 -0
- package/src/hook-app.js +58 -0
- package/src/hook-app.js.map +1 -0
- package/src/hook-evaluator.d.ts +5 -0
- package/src/hook-evaluator.js +13 -0
- package/src/hook-evaluator.js.map +1 -0
- package/src/hook-ports.d.ts +9 -0
- package/src/hook-ports.js +40 -0
- package/src/hook-ports.js.map +1 -0
- package/src/index.d.ts +31 -0
- package/src/index.js +59 -0
- package/src/index.js.map +1 -0
- package/src/outcome.d.ts +14 -0
- package/src/outcome.js +20 -0
- package/src/outcome.js.map +1 -0
- package/src/protocol.d.ts +40 -0
- package/src/protocol.js +55 -0
- package/src/protocol.js.map +1 -0
- package/src/response.d.ts +2 -0
- package/src/response.js +21 -0
- package/src/response.js.map +1 -0
- package/src/to-error.d.ts +1 -0
- package/src/to-error.js +9 -0
- package/src/to-error.js.map +1 -0
package/src/protocol.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AgentHookEvent = exports.FileOperation = exports.NormalizedBashInput = exports.NormalizedToolInput = exports.NormalizedEdit = exports.AI_TYPE_UNKNOWN = exports.AI_TYPES = void 0;
|
|
4
|
+
exports.AI_TYPES = ['claude-code', 'codex'];
|
|
5
|
+
exports.AI_TYPE_UNKNOWN = 'unknown';
|
|
6
|
+
class NormalizedEdit {
|
|
7
|
+
oldString;
|
|
8
|
+
newString;
|
|
9
|
+
constructor(oldString, newString) { this.oldString = oldString; this.newString = newString; }
|
|
10
|
+
}
|
|
11
|
+
exports.NormalizedEdit = NormalizedEdit;
|
|
12
|
+
class NormalizedToolInput {
|
|
13
|
+
filePath;
|
|
14
|
+
edits;
|
|
15
|
+
constructor(filePath, edits) { this.filePath = filePath; this.edits = edits; }
|
|
16
|
+
}
|
|
17
|
+
exports.NormalizedToolInput = NormalizedToolInput;
|
|
18
|
+
class NormalizedBashInput {
|
|
19
|
+
command;
|
|
20
|
+
constructor(command) { this.command = command; }
|
|
21
|
+
}
|
|
22
|
+
exports.NormalizedBashInput = NormalizedBashInput;
|
|
23
|
+
class FileOperation {
|
|
24
|
+
toolKind;
|
|
25
|
+
input;
|
|
26
|
+
constructor(toolKind, input) { this.toolKind = toolKind; this.input = input; }
|
|
27
|
+
}
|
|
28
|
+
exports.FileOperation = FileOperation;
|
|
29
|
+
/** One normalized hook event, independent of the source harness and rule product. */
|
|
30
|
+
class AgentHookEvent {
|
|
31
|
+
aiType;
|
|
32
|
+
kind;
|
|
33
|
+
rawToolName;
|
|
34
|
+
cwd;
|
|
35
|
+
sessionId;
|
|
36
|
+
agentId;
|
|
37
|
+
agentType;
|
|
38
|
+
files;
|
|
39
|
+
bash;
|
|
40
|
+
reads;
|
|
41
|
+
constructor(aiType, kind, rawToolName, cwd, sessionId, agentId, agentType, files, bash, reads) {
|
|
42
|
+
this.aiType = aiType;
|
|
43
|
+
this.kind = kind;
|
|
44
|
+
this.rawToolName = rawToolName;
|
|
45
|
+
this.cwd = cwd;
|
|
46
|
+
this.sessionId = sessionId;
|
|
47
|
+
this.agentId = agentId;
|
|
48
|
+
this.agentType = agentType;
|
|
49
|
+
this.files = files;
|
|
50
|
+
this.bash = bash;
|
|
51
|
+
this.reads = reads;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.AgentHookEvent = AgentHookEvent;
|
|
55
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../../../../packages/tooling/hook-runtime/src/protocol.ts"],"names":[],"mappings":";;;AAEa,QAAA,QAAQ,GAAsB,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;AACvD,QAAA,eAAe,GAAG,SAAS,CAAC;AAKzC,MAAa,cAAc;IACd,SAAS,CAAS;IAClB,SAAS,CAAS;IAC3B,YAAY,SAAiB,EAAE,SAAiB,IAAI,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC,CAAC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC,CAAC,CAAC;CAChH;AAJD,wCAIC;AAED,MAAa,mBAAmB;IACnB,QAAQ,CAAS;IACjB,KAAK,CAA4B;IAC1C,YAAY,QAAgB,EAAE,KAAgC,IAAI,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,CAAC,IAAI,CAAC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export type AiType = 'claude-code' | 'codex';\nexport const AI_TYPES: readonly AiType[] = ['claude-code', 'codex'];\nexport const AI_TYPE_UNKNOWN = 'unknown';\nexport type HookMode = 'rules' | 'guards' | 'all';\nexport type ToolKind = 'Write' | 'Edit' | 'MultiEdit' | 'Read' | 'Delete';\nexport type AgentEventKind = 'File' | 'Bash' | 'Read' | 'Ignored';\n\nexport class NormalizedEdit {\n readonly oldString: string;\n readonly newString: string;\n constructor(oldString: string, newString: string) { this.oldString = oldString; this.newString = newString; }\n}\n\nexport class NormalizedToolInput {\n readonly filePath: string;\n readonly edits: readonly NormalizedEdit[];\n constructor(filePath: string, edits: readonly NormalizedEdit[]) { this.filePath = filePath; this.edits = edits; }\n}\n\nexport class NormalizedBashInput {\n readonly command: string;\n constructor(command: string) { this.command = command; }\n}\n\nexport class FileOperation {\n readonly toolKind: ToolKind;\n readonly input: NormalizedToolInput;\n constructor(toolKind: ToolKind, input: NormalizedToolInput) { this.toolKind = toolKind; this.input = input; }\n}\n\n/** One normalized hook event, independent of the source harness and rule product. */\nexport class AgentHookEvent {\n readonly aiType: AiType;\n readonly kind: AgentEventKind;\n readonly rawToolName: string;\n readonly cwd: string;\n readonly sessionId: string;\n readonly agentId: string;\n readonly agentType: string;\n readonly files: readonly FileOperation[];\n readonly bash: NormalizedBashInput | null;\n readonly reads: readonly string[];\n\n constructor(\n aiType: AiType, kind: AgentEventKind, rawToolName: string, cwd: string, sessionId: string,\n agentId: string, agentType: string, files: readonly FileOperation[],\n bash: NormalizedBashInput | null, reads: readonly string[],\n ) {\n this.aiType = aiType;\n this.kind = kind;\n this.rawToolName = rawToolName;\n this.cwd = cwd;\n this.sessionId = sessionId;\n this.agentId = agentId;\n this.agentType = agentType;\n this.files = files;\n this.bash = bash;\n this.reads = reads;\n }\n}\n"]}
|
package/src/response.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.denyJson = denyJson;
|
|
4
|
+
const ESC = String.fromCharCode(0x1b);
|
|
5
|
+
// webpieces-disable no-function-outside-class -- private wire-format helper at the protocol boundary.
|
|
6
|
+
function redSystemMessage(reason) {
|
|
7
|
+
const nl = reason.indexOf('\n');
|
|
8
|
+
if (nl < 0)
|
|
9
|
+
return `${ESC}[31;1m🛑 ${reason}${ESC}[0m`;
|
|
10
|
+
return `${ESC}[31;1m🛑 ${reason.slice(0, nl)}${ESC}[0m${reason.slice(nl)}`;
|
|
11
|
+
}
|
|
12
|
+
// webpieces-disable no-function-outside-class -- the shared PreToolUse wire format.
|
|
13
|
+
function denyJson(event, reason) {
|
|
14
|
+
const safe = reason.trim() === '' ? '[ai-hooks] blocked, but the guard produced no reason — failing closed.' : reason;
|
|
15
|
+
const hookSpecificOutput = { hookEventName: 'PreToolUse', permissionDecision: 'deny', permissionDecisionReason: safe };
|
|
16
|
+
if (event !== null && event.kind === 'Bash') {
|
|
17
|
+
return JSON.stringify({ systemMessage: redSystemMessage(safe), hookSpecificOutput });
|
|
18
|
+
}
|
|
19
|
+
return JSON.stringify({ hookSpecificOutput });
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=response.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response.js","sourceRoot":"","sources":["../../../../../packages/tooling/hook-runtime/src/response.ts"],"names":[],"mappings":";;AAYA,4BAOC;AAjBD,MAAM,GAAG,GAAG,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;AAEtC,sGAAsG;AACtG,SAAS,gBAAgB,CAAC,MAAc;IACpC,MAAM,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAChC,IAAI,EAAE,GAAG,CAAC;QAAE,OAAO,GAAG,GAAG,YAAY,MAAM,GAAG,GAAG,KAAK,CAAC;IACvD,OAAO,GAAG,GAAG,YAAY,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;AAC/E,CAAC;AAED,oFAAoF;AACpF,SAAgB,QAAQ,CAAC,KAA4B,EAAE,MAAc;IACjE,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,wEAAwE,CAAC,CAAC,CAAC,MAAM,CAAC;IACtH,MAAM,kBAAkB,GAAG,EAAE,aAAa,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,EAAE,wBAAwB,EAAE,IAAI,EAAE,CAAC;IACvH,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QAC1C,OAAO,IAAI,CAAC,SAAS,CAAC,EAAE,aAAa,EAAE,gBAAgB,CAAC,IAAI,CAAC,EAAE,kBAAkB,EAAE,CAAC,CAAC;IACzF,CAAC;IACD,OAAO,IAAI,CAAC,SAAS,CAAC,EAAE,kBAAkB,EAAE,CAAC,CAAC;AAClD,CAAC","sourcesContent":["import { AgentHookEvent } from './protocol';\n\nconst ESC = String.fromCharCode(0x1b);\n\n// webpieces-disable no-function-outside-class -- private wire-format helper at the protocol boundary.\nfunction redSystemMessage(reason: string): string {\n const nl = reason.indexOf('\\n');\n if (nl < 0) return `${ESC}[31;1m🛑 ${reason}${ESC}[0m`;\n return `${ESC}[31;1m🛑 ${reason.slice(0, nl)}${ESC}[0m${reason.slice(nl)}`;\n}\n\n// webpieces-disable no-function-outside-class -- the shared PreToolUse wire format.\nexport function denyJson(event: AgentHookEvent | null, reason: string): string {\n const safe = reason.trim() === '' ? '[ai-hooks] blocked, but the guard produced no reason — failing closed.' : reason;\n const hookSpecificOutput = { hookEventName: 'PreToolUse', permissionDecision: 'deny', permissionDecisionReason: safe };\n if (event !== null && event.kind === 'Bash') {\n return JSON.stringify({ systemMessage: redSystemMessage(safe), hookSpecificOutput });\n }\n return JSON.stringify({ hookSpecificOutput });\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function toError(err: unknown): Error;
|
package/src/to-error.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toError = toError;
|
|
4
|
+
// webpieces-disable no-any-unknown -- thrown values are unknown by construction; this boundary narrows them to Error.
|
|
5
|
+
// webpieces-disable no-function-outside-class -- dependency-free exception normalizer used before/without DI at the process boundary.
|
|
6
|
+
function toError(err) {
|
|
7
|
+
return err instanceof Error ? err : new Error(String(err));
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=to-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to-error.js","sourceRoot":"","sources":["../../../../../packages/tooling/hook-runtime/src/to-error.ts"],"names":[],"mappings":";;AAEA,0BAEC;AAJD,sHAAsH;AACtH,sIAAsI;AACtI,SAAgB,OAAO,CAAC,GAAY;IAChC,OAAO,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;AAC/D,CAAC","sourcesContent":["// webpieces-disable no-any-unknown -- thrown values are unknown by construction; this boundary narrows them to Error.\n// webpieces-disable no-function-outside-class -- dependency-free exception normalizer used before/without DI at the process boundary.\nexport function toError(err: unknown): Error {\n return err instanceof Error ? err : new Error(String(err));\n}\n"]}
|