@primitive.ai/prim 0.1.0-alpha.8 → 0.1.0-alpha.80
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 +295 -37
- package/SKILL.md +269 -0
- package/dist/chunk-2KW7DVFJ.js +1400 -0
- package/dist/chunk-3EEFL6NJ.js +529 -0
- package/dist/chunk-4A2XB2PC.js +310 -0
- package/dist/chunk-4GLVJLEQ.js +55 -0
- package/dist/chunk-BQUJ4AFJ.js +771 -0
- package/dist/chunk-CUE2LKLR.js +155 -0
- package/dist/chunk-EZXEWFDG.js +210 -0
- package/dist/chunk-FI3LIRCB.js +262 -0
- package/dist/chunk-KKP2NYZ3.js +505 -0
- package/dist/chunk-LEMX3IOG.js +79 -0
- package/dist/chunk-LMRYZL3D.js +209 -0
- package/dist/chunk-OUXH3UEP.js +247 -0
- package/dist/chunk-RO3F6JYV.js +126 -0
- package/dist/chunk-TJTVHDJ5.js +321 -0
- package/dist/chunk-WB7AUZ4C.js +52 -0
- package/dist/chunk-XGADQPCI.js +26 -0
- package/dist/chunk-YWO7O6QG.js +327 -0
- package/dist/chunk-Z7YPFWAZ.js +917 -0
- package/dist/chunk-ZOSNEO5N.js +77 -0
- package/dist/daemon/server.js +15329 -0
- package/dist/hook-runtime/daemon/server.js +15329 -0
- package/dist/hook-runtime/hooks/post-commit.js +1128 -0
- package/dist/hook-runtime/hooks/post-rewrite.js +1148 -0
- package/dist/hook-runtime/hooks/post-tool-use.js +7586 -0
- package/dist/hook-runtime/hooks/pre-commit.js +1314 -0
- package/dist/hook-runtime/hooks/pre-tool-use.js +7096 -0
- package/dist/hook-runtime/hooks/prim-hook.js +7691 -0
- package/dist/hook-runtime/hooks/session-end.js +495 -0
- package/dist/hook-runtime/hooks/session-start.js +11313 -0
- package/dist/hook-runtime/index.js +44686 -0
- package/dist/hook-runtime/statusline-main.js +765 -0
- package/dist/hooks/post-commit.js +179 -0
- package/dist/hooks/post-rewrite.js +197 -0
- package/dist/hooks/post-tool-use.js +250 -0
- package/dist/hooks/pre-commit.js +21 -74
- package/dist/hooks/pre-tool-use.js +345 -0
- package/dist/hooks/prim-hook.js +195 -0
- package/dist/hooks/session-end.js +70 -0
- package/dist/hooks/session-start.js +299 -0
- package/dist/index.js +20971 -519
- package/dist/statusline-main.js +765 -0
- package/package.json +35 -13
- package/dist/chunk-3APLWTLB.js +0 -165
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import {
|
|
2
|
+
analyzeShellTargets,
|
|
3
|
+
extractFileTargets
|
|
4
|
+
} from "./chunk-BQUJ4AFJ.js";
|
|
5
|
+
import {
|
|
6
|
+
canonicalRepositoryPath
|
|
7
|
+
} from "./chunk-TJTVHDJ5.js";
|
|
8
|
+
|
|
9
|
+
// src/hooks/file-refs.ts
|
|
10
|
+
var MAX_PREFLIGHT_FILE_TARGETS = 25;
|
|
11
|
+
function primitiveMetadataForResolution(resolution) {
|
|
12
|
+
const shouldAttach = resolution.fileRefs.length > 0 || resolution.rejected.length > 0 || resolution.targetsIncomplete || resolution.targetsTruncated || resolution.shellMutation !== void 0;
|
|
13
|
+
if (!shouldAttach) return;
|
|
14
|
+
return {
|
|
15
|
+
fileRefs: [...resolution.fileRefs],
|
|
16
|
+
...resolution.rejected.length > 0 || resolution.targetsIncomplete ? { fileRefsIncomplete: true } : {},
|
|
17
|
+
...resolution.targetsTruncated ? { fileRefsTruncated: true } : {},
|
|
18
|
+
...resolution.shellMutation !== void 0 ? { shellMutation: resolution.shellMutation } : {}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function preserveHookFileMetadata(payload, resolution) {
|
|
22
|
+
const primitive = primitiveMetadataForResolution(resolution);
|
|
23
|
+
if (!primitive || !payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
24
|
+
return payload;
|
|
25
|
+
}
|
|
26
|
+
return { ...payload, primitive };
|
|
27
|
+
}
|
|
28
|
+
function resolveHookFileRefs(args) {
|
|
29
|
+
const command = (args.agent === "claude_code" || args.agent === "codex") && args.toolName === "Bash" && args.toolInput && typeof args.toolInput === "object" && typeof args.toolInput.command === "string" ? args.toolInput.command : void 0;
|
|
30
|
+
const shell = command === void 0 ? void 0 : analyzeShellTargets(command);
|
|
31
|
+
const shellMutation = shell?.mutation === "none" ? "none" : shell?.coverage === "complete" ? "resolved" : shell ? "unresolved" : void 0;
|
|
32
|
+
const readPath = args.agent === "claude_code" && args.toolName === "Read" && args.toolInput && typeof args.toolInput === "object" && typeof args.toolInput.file_path === "string" ? [args.toolInput.file_path] : void 0;
|
|
33
|
+
const nativeTargets = shell ? null : readPath ? { paths: readPath, complete: true } : extractFileTargets(args.toolName, args.toolInput, args.agent);
|
|
34
|
+
const rawPaths = shell ? shellMutation === "unresolved" ? [] : shell.paths : nativeTargets?.paths ?? [];
|
|
35
|
+
const uniqueRawPaths = Array.from(new Set(rawPaths));
|
|
36
|
+
const targetsTruncated = uniqueRawPaths.length > MAX_PREFLIGHT_FILE_TARGETS;
|
|
37
|
+
const fileRefs = /* @__PURE__ */ new Set();
|
|
38
|
+
const rejected = [];
|
|
39
|
+
for (const path of uniqueRawPaths.slice(0, MAX_PREFLIGHT_FILE_TARGETS)) {
|
|
40
|
+
const canonical = canonicalRepositoryPath(path, args.repository, args.cwd);
|
|
41
|
+
if (canonical.ok) fileRefs.add(canonical.file);
|
|
42
|
+
else rejected.push({ path, reason: canonical.reason });
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
fileRefs: [...fileRefs],
|
|
46
|
+
rejected,
|
|
47
|
+
targetsIncomplete: nativeTargets?.complete === false,
|
|
48
|
+
targetsTruncated,
|
|
49
|
+
...shellMutation ? { shellMutation: targetsTruncated ? "unresolved" : shellMutation } : {}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function enrichHookPayloadWithFileRefs(args) {
|
|
53
|
+
const toolName = typeof args.parsed.tool_name === "string" ? args.parsed.tool_name : "";
|
|
54
|
+
const resolution = resolveHookFileRefs({
|
|
55
|
+
toolName,
|
|
56
|
+
toolInput: args.parsed.tool_input,
|
|
57
|
+
agent: args.agent,
|
|
58
|
+
cwd: args.cwd,
|
|
59
|
+
repository: args.repository
|
|
60
|
+
});
|
|
61
|
+
const primitive = primitiveMetadataForResolution(resolution);
|
|
62
|
+
if (!primitive) return { parsed: args.parsed, resolution };
|
|
63
|
+
return {
|
|
64
|
+
parsed: {
|
|
65
|
+
...args.parsed,
|
|
66
|
+
// An explicit empty list is authoritative when every exposed target was
|
|
67
|
+
// rejected. It prevents backend fallback to unsafe raw tool input.
|
|
68
|
+
primitive
|
|
69
|
+
},
|
|
70
|
+
resolution
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export {
|
|
75
|
+
preserveHookFileMetadata,
|
|
76
|
+
enrichHookPayloadWithFileRefs
|
|
77
|
+
};
|