@primitive.ai/prim 0.1.0-alpha.10 → 0.1.0-alpha.100

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 (47) hide show
  1. package/README.md +413 -37
  2. package/SKILL.md +272 -0
  3. package/dist/chunk-2IRLFOEL.js +766 -0
  4. package/dist/chunk-2Q3OGSTV.js +164 -0
  5. package/dist/chunk-4GLVJLEQ.js +55 -0
  6. package/dist/chunk-5HFTJEA6.js +168 -0
  7. package/dist/chunk-5LRKJTLA.js +155 -0
  8. package/dist/chunk-6C3CCVDI.js +264 -0
  9. package/dist/chunk-7VIMU2HR.js +209 -0
  10. package/dist/chunk-C4D2LMTS.js +511 -0
  11. package/dist/chunk-EZXEWFDG.js +210 -0
  12. package/dist/chunk-GSBHBU7N.js +18982 -0
  13. package/dist/chunk-H6JAQVW4.js +258 -0
  14. package/dist/chunk-IDMLJ4TM.js +36 -0
  15. package/dist/chunk-JJI7FU24.js +439 -0
  16. package/dist/chunk-K4JWJ6OM.js +1496 -0
  17. package/dist/chunk-KGBMU76T.js +175 -0
  18. package/dist/chunk-MXVCP33E.js +847 -0
  19. package/dist/chunk-MZEVEPL3.js +262 -0
  20. package/dist/chunk-O2WV5SQZ.js +1876 -0
  21. package/dist/chunk-OYHYCK4K.js +13 -0
  22. package/dist/chunk-QIHXTYRD.js +135 -0
  23. package/dist/chunk-XG7S3LIL.js +1372 -0
  24. package/dist/daemon/server.js +22644 -0
  25. package/dist/hook-runtime/daemon/server.js +22644 -0
  26. package/dist/hook-runtime/hooks/post-commit.js +20133 -0
  27. package/dist/hook-runtime/hooks/post-rewrite.js +20032 -0
  28. package/dist/hook-runtime/hooks/post-tool-use.js +27307 -0
  29. package/dist/hook-runtime/hooks/pre-commit.js +1657 -0
  30. package/dist/hook-runtime/hooks/pre-tool-use.js +26714 -0
  31. package/dist/hook-runtime/hooks/prim-hook.js +27367 -0
  32. package/dist/hook-runtime/hooks/session-end.js +1176 -0
  33. package/dist/hook-runtime/hooks/session-start.js +30167 -0
  34. package/dist/hook-runtime/index.js +53486 -0
  35. package/dist/hook-runtime/statusline-main.js +886 -0
  36. package/dist/hooks/post-commit.js +196 -0
  37. package/dist/hooks/post-rewrite.js +205 -0
  38. package/dist/hooks/post-tool-use.js +285 -0
  39. package/dist/hooks/pre-commit.js +15 -99
  40. package/dist/hooks/pre-tool-use.js +387 -0
  41. package/dist/hooks/prim-hook.js +235 -0
  42. package/dist/hooks/session-end.js +64 -0
  43. package/dist/hooks/session-start.js +309 -0
  44. package/dist/index.js +9721 -428
  45. package/dist/statusline-main.js +886 -0
  46. package/package.json +35 -13
  47. package/dist/chunk-3APLWTLB.js +0 -165
@@ -0,0 +1,13 @@
1
+ // src/lib/unattended.ts
2
+ var UNATTENDED_ENV = "PRIM_UNATTENDED";
3
+ function unattendedEnv(env = process.env) {
4
+ return { ...env, [UNATTENDED_ENV]: "1" };
5
+ }
6
+ function isUnattended(env = process.env) {
7
+ return env[UNATTENDED_ENV] === "1";
8
+ }
9
+
10
+ export {
11
+ unattendedEnv,
12
+ isUnattended
13
+ };
@@ -0,0 +1,135 @@
1
+ import {
2
+ getOrCreateWorkspaceId
3
+ } from "./chunk-EZXEWFDG.js";
4
+ import {
5
+ analyzeShellTargets,
6
+ extractFileTargets
7
+ } from "./chunk-MXVCP33E.js";
8
+ import {
9
+ scrubEnvironmentPaths
10
+ } from "./chunk-MZEVEPL3.js";
11
+ import {
12
+ cachedCollectScopeAdmits
13
+ } from "./chunk-GSBHBU7N.js";
14
+ import {
15
+ canonicalRepositoryPath,
16
+ currentBranch,
17
+ isRepoActiveForCapture,
18
+ relatedWorktreeTarget,
19
+ repoSyncId
20
+ } from "./chunk-XG7S3LIL.js";
21
+
22
+ // src/hooks/file-refs.ts
23
+ var MAX_PREFLIGHT_FILE_TARGETS = 25;
24
+ function primitiveMetadataForResolution(resolution) {
25
+ const shouldAttach = resolution.fileRefs.length > 0 || (resolution.targetCheckouts?.length ?? 0) > 0 || resolution.rejected.length > 0 || resolution.targetsIncomplete || resolution.targetsTruncated || resolution.shellMutation !== void 0;
26
+ if (!shouldAttach) return;
27
+ return {
28
+ fileRefs: [...resolution.fileRefs],
29
+ ...resolution.targetCheckouts ? { targetCheckouts: resolution.targetCheckouts } : {},
30
+ ...resolution.rejected.length > 0 || resolution.targetsIncomplete ? { fileRefsIncomplete: true } : {},
31
+ ...resolution.targetsTruncated ? { fileRefsTruncated: true } : {},
32
+ ...resolution.shellMutation !== void 0 ? { shellMutation: resolution.shellMutation } : {}
33
+ };
34
+ }
35
+ function preserveHookFileMetadata(payload, resolution) {
36
+ const primitive = primitiveMetadataForResolution(resolution);
37
+ if (!primitive || !payload || typeof payload !== "object" || Array.isArray(payload)) {
38
+ return payload;
39
+ }
40
+ return { ...payload, primitive };
41
+ }
42
+ function resolveHookFileRefs(args) {
43
+ const isShellTool = (args.agent === "claude_code" || args.agent === "codex") && args.toolName === "Bash" || args.agent === "cursor" && args.toolName === "Shell";
44
+ const command = isShellTool ? typeof args.toolInput === "string" ? args.toolInput : args.toolInput && typeof args.toolInput === "object" && typeof args.toolInput.command === "string" ? args.toolInput.command : void 0 : void 0;
45
+ const shell = command === void 0 ? void 0 : analyzeShellTargets(command);
46
+ const shellMutation = shell?.mutation === "none" ? "none" : shell?.coverage === "complete" ? "resolved" : shell ? "unresolved" : void 0;
47
+ 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;
48
+ const nativeTargets = shell ? null : readPath ? { paths: readPath, complete: true } : extractFileTargets(args.toolName, args.toolInput, args.agent);
49
+ const rawPaths = shell ? shellMutation === "unresolved" ? [] : shell.paths : nativeTargets?.paths ?? [];
50
+ const uniqueRawPaths = Array.from(new Set(rawPaths));
51
+ const targetsTruncated = uniqueRawPaths.length > MAX_PREFLIGHT_FILE_TARGETS;
52
+ const fileRefs = /* @__PURE__ */ new Set();
53
+ const rejected = [];
54
+ const targets = /* @__PURE__ */ new Map();
55
+ for (const path of uniqueRawPaths.slice(0, MAX_PREFLIGHT_FILE_TARGETS)) {
56
+ const canonical = canonicalRepositoryPath(path, args.repository, args.cwd);
57
+ if (canonical.ok) fileRefs.add(canonical.file);
58
+ else {
59
+ const target = args.captureTargets && canonical.reason === "outside_repository" ? relatedWorktreeTarget(path, args.cwd, args.repository) : null;
60
+ const resolved = target ? canonicalRepositoryPath(path, target, args.cwd) : null;
61
+ if (target && resolved?.ok && isRepoActiveForCapture(target.repoRoot) && repoSyncId(target.repoRoot) === args.repository.repoSyncId && args.repository.repoSyncId && cachedCollectScopeAdmits(target.repoRoot, {
62
+ repository: target.repoFullName,
63
+ branch: currentBranch(target.repoRoot),
64
+ agent: args.agent,
65
+ paths: [resolved.file],
66
+ pathsComplete: true
67
+ })) {
68
+ const group = targets.get(target.repoRoot) ?? { repository: target, fileRefs: [] };
69
+ group.fileRefs.push(resolved.file);
70
+ targets.set(target.repoRoot, group);
71
+ } else rejected.push({ path, reason: canonical.reason });
72
+ }
73
+ }
74
+ const targetCheckouts = [];
75
+ if (targets.size > 0) {
76
+ if (fileRefs.size > 0)
77
+ targets.set(args.repository.repoRoot, {
78
+ repository: args.repository,
79
+ fileRefs: [...fileRefs]
80
+ });
81
+ for (const { repository, fileRefs: paths } of targets.values()) {
82
+ const identity = getOrCreateWorkspaceId(repository.repoRoot);
83
+ const binding = repoSyncId(repository.repoRoot);
84
+ if (identity.status !== "ready" || !binding) {
85
+ rejected.push({ path: repository.repoRoot, reason: "invalid_path" });
86
+ continue;
87
+ }
88
+ const root = scrubEnvironmentPaths({
89
+ cwd: repository.repoRoot,
90
+ gitRoot: repository.repoRoot
91
+ }).gitRoot;
92
+ targetCheckouts.push({
93
+ gitRoot: root,
94
+ workspaceId: identity.workspaceId,
95
+ repoSyncId: binding,
96
+ fileRefs: paths
97
+ });
98
+ }
99
+ }
100
+ return {
101
+ fileRefs: [...fileRefs],
102
+ ...targetCheckouts.length > 0 ? { targetCheckouts } : {},
103
+ rejected,
104
+ targetsIncomplete: nativeTargets?.complete === false,
105
+ targetsTruncated,
106
+ ...shellMutation ? { shellMutation: targetsTruncated ? "unresolved" : shellMutation } : {}
107
+ };
108
+ }
109
+ function enrichHookPayloadWithFileRefs(args) {
110
+ const toolName = typeof args.parsed.tool_name === "string" ? args.parsed.tool_name : "";
111
+ const resolution = resolveHookFileRefs({
112
+ toolName,
113
+ toolInput: args.parsed.tool_input,
114
+ agent: args.agent,
115
+ cwd: args.cwd,
116
+ repository: args.repository,
117
+ captureTargets: true
118
+ });
119
+ const primitive = primitiveMetadataForResolution(resolution);
120
+ if (!primitive) return { parsed: args.parsed, resolution };
121
+ return {
122
+ parsed: {
123
+ ...args.parsed,
124
+ // An explicit empty list is authoritative when every exposed target was
125
+ // rejected. It prevents backend fallback to unsafe raw tool input.
126
+ primitive
127
+ },
128
+ resolution
129
+ };
130
+ }
131
+
132
+ export {
133
+ preserveHookFileMetadata,
134
+ enrichHookPayloadWithFileRefs
135
+ };