@primitive.ai/prim 0.1.0-alpha.12 → 0.1.0-alpha.120
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 +540 -38
- package/SKILL.md +315 -75
- package/assets/primitive-gameplan/SKILL.md +134 -0
- package/assets/primitive-gameplan/claude-hooks.json +28 -0
- package/assets/primitive-gameplan/scripts/activate.mjs +37 -0
- package/dist/chunk-2AKDX4RU.js +209 -0
- package/dist/chunk-4GLVJLEQ.js +55 -0
- package/dist/chunk-5BQ2NEMP.js +22695 -0
- package/dist/chunk-A6M2M5A2.js +36 -0
- package/dist/chunk-CCGFRNAA.js +1871 -0
- package/dist/chunk-D235RJNO.js +164 -0
- package/dist/chunk-EYBE724K.js +135 -0
- package/dist/chunk-EZXEWFDG.js +210 -0
- package/dist/chunk-GYQOZGGF.js +168 -0
- package/dist/chunk-HXICZG5J.js +503 -0
- package/dist/chunk-JSBRDJBE.js +30 -0
- package/dist/chunk-KZB4ABIB.js +13 -0
- package/dist/chunk-L52OD62C.js +1444 -0
- package/dist/chunk-LBCPRHNG.js +175 -0
- package/dist/chunk-LTTF4MBE.js +439 -0
- package/dist/chunk-MWNRXAEB.js +1572 -0
- package/dist/chunk-NQFRQ56V.js +262 -0
- package/dist/chunk-OYHYCK4K.js +13 -0
- package/dist/chunk-P2O7NLVN.js +1341 -0
- package/dist/chunk-R2NUH4B7.js +96 -0
- package/dist/chunk-SLDZJD6Q.js +157 -0
- package/dist/chunk-TC4FTRYO.js +253 -0
- package/dist/chunk-U67RBNIZ.js +844 -0
- package/dist/chunk-VOC4KOOP.js +258 -0
- package/dist/chunk-YTF6OCF3.js +459 -0
- package/dist/daemon/server.js +26444 -0
- package/dist/hook-runtime/daemon/server.js +26445 -0
- package/dist/hook-runtime/hooks/post-commit.js +23836 -0
- package/dist/hook-runtime/hooks/post-rewrite.js +23735 -0
- package/dist/hook-runtime/hooks/post-tool-use.js +36151 -0
- package/dist/hook-runtime/hooks/pre-commit.js +1737 -0
- package/dist/hook-runtime/hooks/pre-tool-use-worker.js +35067 -0
- package/dist/hook-runtime/hooks/pre-tool-use.js +96 -0
- package/dist/hook-runtime/hooks/prim-hook.js +36211 -0
- package/dist/hook-runtime/hooks/session-end.js +1188 -0
- package/dist/hook-runtime/hooks/session-start.js +33950 -0
- package/dist/hook-runtime/index.js +71245 -0
- package/dist/hook-runtime/statusline-main.js +892 -0
- package/dist/hooks/post-commit.js +197 -0
- package/dist/hooks/post-rewrite.js +206 -0
- package/dist/hooks/post-tool-use.js +295 -0
- package/dist/hooks/pre-commit.js +16 -108
- package/dist/hooks/pre-tool-use-worker.js +238 -0
- package/dist/hooks/pre-tool-use.js +87 -0
- package/dist/hooks/prim-hook.js +245 -0
- package/dist/hooks/session-end.js +67 -0
- package/dist/hooks/session-start.js +312 -0
- package/dist/index.js +10998 -572
- package/dist/statusline-main.js +891 -0
- package/package.json +49 -16
- package/dist/chunk-3APLWTLB.js +0 -165
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import {
|
|
2
|
+
boundedHealthError
|
|
3
|
+
} from "./chunk-5BQ2NEMP.js";
|
|
4
|
+
import {
|
|
5
|
+
terminalSafeLine
|
|
6
|
+
} from "./chunk-U67RBNIZ.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,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
|
+
};
|