@primitive.ai/prim 0.1.0-alpha.12 → 0.1.0-alpha.121

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 (57) hide show
  1. package/README.md +550 -38
  2. package/SKILL.md +320 -75
  3. package/assets/primitive-gameplan/SKILL.md +134 -0
  4. package/assets/primitive-gameplan/claude-hooks.json +28 -0
  5. package/assets/primitive-gameplan/scripts/activate.mjs +37 -0
  6. package/dist/chunk-2DNC2MUN.js +503 -0
  7. package/dist/chunk-2PFJJO2M.js +262 -0
  8. package/dist/chunk-4GLVJLEQ.js +55 -0
  9. package/dist/chunk-4GYJHN26.js +1440 -0
  10. package/dist/chunk-6DEROXLM.js +22695 -0
  11. package/dist/chunk-7LXRFXZG.js +1992 -0
  12. package/dist/chunk-AKGRY7OU.js +1572 -0
  13. package/dist/chunk-BHT6X3T5.js +1450 -0
  14. package/dist/chunk-DQ4I3FLF.js +164 -0
  15. package/dist/chunk-DVHD6LBQ.js +258 -0
  16. package/dist/chunk-EZXEWFDG.js +210 -0
  17. package/dist/chunk-HG7FJK7R.js +253 -0
  18. package/dist/chunk-JSBRDJBE.js +30 -0
  19. package/dist/chunk-JXRJLHE4.js +168 -0
  20. package/dist/chunk-JZC2LHS6.js +209 -0
  21. package/dist/chunk-KZB4ABIB.js +13 -0
  22. package/dist/chunk-LQLP26RL.js +459 -0
  23. package/dist/chunk-M4NZJCPQ.js +135 -0
  24. package/dist/chunk-MRDY7VQP.js +96 -0
  25. package/dist/chunk-NMZSCSMY.js +157 -0
  26. package/dist/chunk-NQZLXYTW.js +36 -0
  27. package/dist/chunk-OXW6PSPT.js +439 -0
  28. package/dist/chunk-OYHYCK4K.js +13 -0
  29. package/dist/chunk-S3ZIMGXV.js +844 -0
  30. package/dist/chunk-WN7OURQ3.js +175 -0
  31. package/dist/daemon/server.js +26506 -0
  32. package/dist/hook-runtime/daemon/server.js +26507 -0
  33. package/dist/hook-runtime/hooks/post-commit.js +23898 -0
  34. package/dist/hook-runtime/hooks/post-rewrite.js +23797 -0
  35. package/dist/hook-runtime/hooks/post-tool-use.js +36213 -0
  36. package/dist/hook-runtime/hooks/pre-commit.js +1741 -0
  37. package/dist/hook-runtime/hooks/pre-tool-use-worker.js +35071 -0
  38. package/dist/hook-runtime/hooks/pre-tool-use.js +96 -0
  39. package/dist/hook-runtime/hooks/prim-hook.js +36273 -0
  40. package/dist/hook-runtime/hooks/session-end.js +1250 -0
  41. package/dist/hook-runtime/hooks/session-start.js +34021 -0
  42. package/dist/hook-runtime/index.js +71700 -0
  43. package/dist/hook-runtime/statusline-main.js +954 -0
  44. package/dist/hooks/post-commit.js +197 -0
  45. package/dist/hooks/post-rewrite.js +206 -0
  46. package/dist/hooks/post-tool-use.js +295 -0
  47. package/dist/hooks/pre-commit.js +16 -108
  48. package/dist/hooks/pre-tool-use-worker.js +238 -0
  49. package/dist/hooks/pre-tool-use.js +87 -0
  50. package/dist/hooks/prim-hook.js +245 -0
  51. package/dist/hooks/session-end.js +67 -0
  52. package/dist/hooks/session-start.js +312 -0
  53. package/dist/index.js +11249 -572
  54. package/dist/statusline-main.js +953 -0
  55. package/package.json +51 -17
  56. package/skills/prim-welcome/SKILL.md +197 -0
  57. package/dist/chunk-3APLWTLB.js +0 -165
@@ -0,0 +1,262 @@
1
+ import {
2
+ boundedHealthError
3
+ } from "./chunk-6DEROXLM.js";
4
+ import {
5
+ terminalSafeLine
6
+ } from "./chunk-S3ZIMGXV.js";
7
+
8
+ // src/hooks/redact.ts
9
+ import { existsSync, readFileSync, statSync } from "fs";
10
+ import { join } from "path";
11
+ import { Worker } from "worker_threads";
12
+ var USER_HOME_RULES = [
13
+ {
14
+ pattern: /\/Users\/[^/\\\s"'`]+/g,
15
+ reason: "user-home-path",
16
+ replacement: "/Users/__redacted_user__"
17
+ },
18
+ {
19
+ pattern: /\/home\/[^/\\\s"'`]+/g,
20
+ reason: "user-home-path",
21
+ replacement: "/home/__redacted_user__"
22
+ },
23
+ {
24
+ pattern: /([A-Za-z]:\\Users\\)[^/\\\s"'`]+/gi,
25
+ reason: "user-home-path",
26
+ replacement: "$1__redacted_user__"
27
+ },
28
+ {
29
+ pattern: /\/root(?=\/|$)/g,
30
+ reason: "user-home-path",
31
+ replacement: "/__redacted_user__"
32
+ }
33
+ ];
34
+ var DEFAULT_RULES = [
35
+ { pattern: /Bearer\s+[A-Za-z0-9._~+/=-]+/gi, reason: "bearer-token" },
36
+ {
37
+ pattern: /\bsk-(?:(?:ant|proj)-)?[A-Za-z0-9_-]{16,}(?![A-Za-z0-9_-])/g,
38
+ reason: "sk-api-key"
39
+ },
40
+ {
41
+ pattern: /-----BEGIN [A-Z ]+PRIVATE KEY-----[\s\S]+?-----END [A-Z ]+PRIVATE KEY-----/g,
42
+ reason: "private-key"
43
+ },
44
+ { pattern: /xox[abprs]-[A-Za-z0-9-]{10,}/g, reason: "slack-token" },
45
+ {
46
+ pattern: /\b(?:gh[pousr]_[A-Za-z0-9]{36,}|github_pat_[A-Za-z0-9_]{50,})\b/g,
47
+ reason: "github-pat"
48
+ },
49
+ { pattern: /\b(?:AKIA|ASIA)[A-Z0-9]{16}\b/g, reason: "aws-access-key" },
50
+ {
51
+ pattern: /\bAWS_(?:SECRET_ACCESS_KEY|SESSION_TOKEN)"?\s*[:=]\s*["']?[A-Za-z0-9/+=]{20,}["']?/gi,
52
+ reason: "aws-secret"
53
+ },
54
+ { pattern: /\bAIza[0-9A-Za-z_-]{35}(?![0-9A-Za-z_-])/g, reason: "gcp-api-key" },
55
+ {
56
+ pattern: /\bya29\.[0-9A-Za-z_-]{20,}(?![0-9A-Za-z_-])/g,
57
+ reason: "gcp-oauth-token"
58
+ },
59
+ {
60
+ pattern: /\beyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*(?![A-Za-z0-9_-])/g,
61
+ reason: "jwt"
62
+ },
63
+ { pattern: /\bBasic\s+[A-Za-z0-9+/]+={0,2}/gi, reason: "basic-auth" },
64
+ { pattern: /\bhttps?:\/\/[^/\s:@]+:[^/\s@]+@/gi, reason: "basic-auth" },
65
+ ...USER_HOME_RULES
66
+ ];
67
+ var MAX_SCRUB_LEN = 256e3;
68
+ var MAX_WORKSPACE_CONFIG_BYTES = 64 * 1024;
69
+ var MAX_WORKSPACE_RULES = 32;
70
+ var MAX_WORKSPACE_PATTERN_LENGTH = 512;
71
+ var MAX_WORKSPACE_REASON_LENGTH = 64;
72
+ var WORKSPACE_RULE_TIMEOUT_MS = 250;
73
+ var WORKSPACE_FILE = ".prim/redaction.json";
74
+ var SAFE_REASON_RE = /^[A-Za-z0-9][A-Za-z0-9_-]*$/u;
75
+ var SAFE_WORKSPACE_FLAGS_RE = /^[gimsu]*$/u;
76
+ function debugRedaction(message) {
77
+ writeHookDebug(`redaction: ${message}`);
78
+ }
79
+ function normalizedWorkspaceFlags(value) {
80
+ if (value !== void 0 && typeof value !== "string") return null;
81
+ const requested = value ?? "";
82
+ if (!SAFE_WORKSPACE_FLAGS_RE.test(requested)) return null;
83
+ return [...new Set(`g${requested}`)].sort().join("");
84
+ }
85
+ function loadWorkspaceRules(cwd) {
86
+ const path = join(cwd, WORKSPACE_FILE);
87
+ if (!existsSync(path)) return [];
88
+ let cfg;
89
+ try {
90
+ if (statSync(path).size > MAX_WORKSPACE_CONFIG_BYTES) {
91
+ debugRedaction(`ignoring oversized ${WORKSPACE_FILE}`);
92
+ return [];
93
+ }
94
+ cfg = JSON.parse(readFileSync(path, "utf-8"));
95
+ } catch {
96
+ debugRedaction(`ignoring unparseable ${WORKSPACE_FILE}`);
97
+ return [];
98
+ }
99
+ if (!Array.isArray(cfg.rules)) return [];
100
+ const compiled = [];
101
+ for (const candidate of cfg.rules.slice(0, MAX_WORKSPACE_RULES)) {
102
+ if (!candidate || typeof candidate !== "object") continue;
103
+ const { pattern, reason } = candidate;
104
+ const flags = normalizedWorkspaceFlags(candidate.flags);
105
+ if (typeof pattern !== "string" || pattern.length === 0 || pattern.length > MAX_WORKSPACE_PATTERN_LENGTH || typeof reason !== "string" || reason.length === 0 || reason.length > MAX_WORKSPACE_REASON_LENGTH || !SAFE_REASON_RE.test(reason) || flags === null) {
106
+ debugRedaction("skipping invalid workspace rule metadata");
107
+ continue;
108
+ }
109
+ try {
110
+ compiled.push({ pattern: new RegExp(pattern, flags), reason });
111
+ } catch {
112
+ debugRedaction(`skipping invalid workspace rule ${reason}`);
113
+ }
114
+ }
115
+ return compiled;
116
+ }
117
+ function applyRules(input, rules) {
118
+ if (input.length > MAX_SCRUB_LEN) return "<REDACTED:oversized>";
119
+ let out = input;
120
+ for (const rule of rules) {
121
+ out = out.replace(rule.pattern, rule.replacement ?? `<REDACTED:${rule.reason}>`);
122
+ }
123
+ return out;
124
+ }
125
+ var REDACTED_OBJECT_KEY = "<REDACTED:object-key>";
126
+ function redactedObjectKey(input, transform) {
127
+ return transform(input) === input ? input : REDACTED_OBJECT_KEY;
128
+ }
129
+ function uniqueObjectKey(output, key) {
130
+ let candidate = key;
131
+ let suffix = 2;
132
+ while (Object.hasOwn(output, candidate)) candidate = `${key}_${suffix++}`;
133
+ return candidate;
134
+ }
135
+ function mapStrings(value, transform) {
136
+ if (typeof value === "string") return transform(value);
137
+ if (Array.isArray(value)) return value.map((item) => mapStrings(item, transform));
138
+ if (value && typeof value === "object") {
139
+ const out = /* @__PURE__ */ Object.create(null);
140
+ for (const [key, item] of Object.entries(value)) {
141
+ out[uniqueObjectKey(out, redactedObjectKey(key, transform))] = mapStrings(item, transform);
142
+ }
143
+ return out;
144
+ }
145
+ return value;
146
+ }
147
+ function scrub(value, rules = DEFAULT_RULES) {
148
+ return mapStrings(value, (input) => applyRules(input, rules));
149
+ }
150
+ function debugDetail(value) {
151
+ try {
152
+ return String(value instanceof Error ? value.message : value);
153
+ } catch {
154
+ return "unprintable detail";
155
+ }
156
+ }
157
+ function writeHookDebug(context, ...details) {
158
+ if (!process.env.PRIM_HOOK_DEBUG) return;
159
+ const raw = details.length > 0 ? `${context}: ${details.map(debugDetail).join(": ")}` : context;
160
+ const normalized = terminalSafeLine(raw);
161
+ const message = boundedHealthError(scrub(normalized, DEFAULT_RULES)) ?? context;
162
+ process.stderr.write(`[prim-hook] ${message === `${context}:` ? context : message}
163
+ `);
164
+ }
165
+ function redactEveryString(value, reason) {
166
+ return mapStrings(value, () => `<REDACTED:${reason}>`);
167
+ }
168
+ var WORKSPACE_REDACTION_WORKER = String.raw`
169
+ const { parentPort, workerData } = require("node:worker_threads");
170
+ const REDACTED_OBJECT_KEY = "<REDACTED:object-key>";
171
+ const rules = workerData.rules.map((rule) => ({
172
+ pattern: new RegExp(rule.source, rule.flags),
173
+ reason: rule.reason,
174
+ }));
175
+ function redact(input) {
176
+ let output = input;
177
+ for (const rule of rules) {
178
+ output = output.replace(rule.pattern, "<REDACTED:" + rule.reason + ">");
179
+ }
180
+ return output;
181
+ }
182
+ function objectKey(input) {
183
+ return redact(input) === input ? input : REDACTED_OBJECT_KEY;
184
+ }
185
+ function uniqueKey(output, key) {
186
+ let candidate = key;
187
+ let suffix = 2;
188
+ while (Object.hasOwn(output, candidate)) candidate = key + "_" + suffix++;
189
+ return candidate;
190
+ }
191
+ function walk(value) {
192
+ if (typeof value === "string") {
193
+ return redact(value);
194
+ }
195
+ if (Array.isArray(value)) return value.map(walk);
196
+ if (value && typeof value === "object") {
197
+ const output = Object.create(null);
198
+ for (const [key, item] of Object.entries(value)) {
199
+ output[uniqueKey(output, objectKey(key))] = walk(item);
200
+ }
201
+ return output;
202
+ }
203
+ return value;
204
+ }
205
+ parentPort.postMessage(walk(workerData.value));
206
+ `;
207
+ function applyWorkspaceRules(value, rules) {
208
+ const serialized = rules.map(({ pattern, reason }) => ({
209
+ source: pattern.source,
210
+ flags: pattern.flags,
211
+ reason
212
+ }));
213
+ return new Promise((resolve) => {
214
+ let worker;
215
+ try {
216
+ worker = new Worker(WORKSPACE_REDACTION_WORKER, {
217
+ eval: true,
218
+ workerData: { value, rules: serialized }
219
+ });
220
+ } catch {
221
+ resolve(redactEveryString(value, "workspace-rule-failed"));
222
+ return;
223
+ }
224
+ let settled = false;
225
+ const finish = (result) => {
226
+ if (settled) return;
227
+ settled = true;
228
+ clearTimeout(timer);
229
+ void worker.terminate();
230
+ resolve(result);
231
+ };
232
+ const failClosed = () => finish(redactEveryString(value, "workspace-rule-failed"));
233
+ const timer = setTimeout(failClosed, WORKSPACE_RULE_TIMEOUT_MS);
234
+ worker.once("message", finish);
235
+ worker.once("error", failClosed);
236
+ worker.once("exit", (code) => {
237
+ if (code !== 0) failClosed();
238
+ });
239
+ });
240
+ }
241
+ async function scrubFromCwd(value, cwd) {
242
+ const defaultScrubbed = scrub(value, DEFAULT_RULES);
243
+ const workspaceRules = loadWorkspaceRules(cwd);
244
+ return workspaceRules.length === 0 ? defaultScrubbed : await applyWorkspaceRules(defaultScrubbed, workspaceRules);
245
+ }
246
+ function scrubEnvironmentPaths(environment) {
247
+ const scrubPath = (value) => value === void 0 ? void 0 : applyRules(value, USER_HOME_RULES);
248
+ return {
249
+ ...environment,
250
+ cwd: scrubPath(environment.cwd) ?? environment.cwd,
251
+ ...environment.repoRoot === void 0 ? {} : { repoRoot: scrubPath(environment.repoRoot) },
252
+ ...environment.gitRoot === void 0 ? {} : { gitRoot: scrubPath(environment.gitRoot) }
253
+ };
254
+ }
255
+
256
+ export {
257
+ DEFAULT_RULES,
258
+ scrub,
259
+ writeHookDebug,
260
+ scrubFromCwd,
261
+ scrubEnvironmentPaths
262
+ };
@@ -0,0 +1,55 @@
1
+ // src/hooks/decision-feedback-core.ts
2
+ function buildHookOutput(options) {
3
+ const output = {};
4
+ if (options.systemMessage) output.systemMessage = options.systemMessage;
5
+ const fields = {};
6
+ if (options.additionalContext) fields.additionalContext = options.additionalContext;
7
+ if (options.reloadSkills) fields.reloadSkills = true;
8
+ if (Object.keys(fields).length > 0) {
9
+ output.hookSpecificOutput = { hookEventName: "SessionStart", ...fields };
10
+ }
11
+ return output;
12
+ }
13
+ function writeHookOutput(output, stream = process.stdout) {
14
+ return new Promise((resolve) => {
15
+ let settled = false;
16
+ const finish = (ok, retainErrorListener = false) => {
17
+ if (settled) return;
18
+ settled = true;
19
+ if (!retainErrorListener) stream.off("error", onError);
20
+ resolve(ok);
21
+ };
22
+ const onError = () => {
23
+ if (settled) {
24
+ stream.off("error", onError);
25
+ return;
26
+ }
27
+ finish(false);
28
+ };
29
+ stream.once("error", onError);
30
+ try {
31
+ stream.write(
32
+ `${JSON.stringify(output)}
33
+ `,
34
+ (error) => error ? finish(false, true) : finish(true)
35
+ );
36
+ } catch {
37
+ finish(false);
38
+ }
39
+ });
40
+ }
41
+ async function handoffHookOutput(output, acknowledge, stream = process.stdout) {
42
+ const handedOff = await writeHookOutput(output, stream);
43
+ if (handedOff && acknowledge) {
44
+ try {
45
+ await acknowledge();
46
+ } catch {
47
+ }
48
+ }
49
+ return handedOff;
50
+ }
51
+
52
+ export {
53
+ buildHookOutput,
54
+ handoffHookOutput
55
+ };