@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.
- package/README.md +550 -38
- package/SKILL.md +320 -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-2DNC2MUN.js +503 -0
- package/dist/chunk-2PFJJO2M.js +262 -0
- package/dist/chunk-4GLVJLEQ.js +55 -0
- package/dist/chunk-4GYJHN26.js +1440 -0
- package/dist/chunk-6DEROXLM.js +22695 -0
- package/dist/chunk-7LXRFXZG.js +1992 -0
- package/dist/chunk-AKGRY7OU.js +1572 -0
- package/dist/chunk-BHT6X3T5.js +1450 -0
- package/dist/chunk-DQ4I3FLF.js +164 -0
- package/dist/chunk-DVHD6LBQ.js +258 -0
- package/dist/chunk-EZXEWFDG.js +210 -0
- package/dist/chunk-HG7FJK7R.js +253 -0
- package/dist/chunk-JSBRDJBE.js +30 -0
- package/dist/chunk-JXRJLHE4.js +168 -0
- package/dist/chunk-JZC2LHS6.js +209 -0
- package/dist/chunk-KZB4ABIB.js +13 -0
- package/dist/chunk-LQLP26RL.js +459 -0
- package/dist/chunk-M4NZJCPQ.js +135 -0
- package/dist/chunk-MRDY7VQP.js +96 -0
- package/dist/chunk-NMZSCSMY.js +157 -0
- package/dist/chunk-NQZLXYTW.js +36 -0
- package/dist/chunk-OXW6PSPT.js +439 -0
- package/dist/chunk-OYHYCK4K.js +13 -0
- package/dist/chunk-S3ZIMGXV.js +844 -0
- package/dist/chunk-WN7OURQ3.js +175 -0
- package/dist/daemon/server.js +26506 -0
- package/dist/hook-runtime/daemon/server.js +26507 -0
- package/dist/hook-runtime/hooks/post-commit.js +23898 -0
- package/dist/hook-runtime/hooks/post-rewrite.js +23797 -0
- package/dist/hook-runtime/hooks/post-tool-use.js +36213 -0
- package/dist/hook-runtime/hooks/pre-commit.js +1741 -0
- package/dist/hook-runtime/hooks/pre-tool-use-worker.js +35071 -0
- package/dist/hook-runtime/hooks/pre-tool-use.js +96 -0
- package/dist/hook-runtime/hooks/prim-hook.js +36273 -0
- package/dist/hook-runtime/hooks/session-end.js +1250 -0
- package/dist/hook-runtime/hooks/session-start.js +34021 -0
- package/dist/hook-runtime/index.js +71700 -0
- package/dist/hook-runtime/statusline-main.js +954 -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 +11249 -572
- package/dist/statusline-main.js +953 -0
- package/package.json +51 -17
- package/skills/prim-welcome/SKILL.md +197 -0
- package/dist/chunk-3APLWTLB.js +0 -165
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire as __primCreateRequire } from "node:module"; const require = __primCreateRequire(import.meta.url);
|
|
3
|
+
|
|
4
|
+
// src/hooks/pre-tool-use.ts
|
|
5
|
+
import { spawn } from "child_process";
|
|
6
|
+
import { fileURLToPath } from "url";
|
|
7
|
+
|
|
8
|
+
// src/hooks/agent.ts
|
|
9
|
+
function parseAgent(argv) {
|
|
10
|
+
const i = argv.indexOf("--agent");
|
|
11
|
+
const value = i !== -1 ? argv[i + 1] : void 0;
|
|
12
|
+
if (value === "codex" || value === "cursor" || value === "hermes") {
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
return "claude_code";
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// src/hooks/pre-tool-use.ts
|
|
19
|
+
var BUDGET_MS = 2e3;
|
|
20
|
+
var OUTPUT_RESERVE_MS = 150;
|
|
21
|
+
var MAX_OUTPUT_BYTES = 262144;
|
|
22
|
+
var agent = parseAgent(process.argv);
|
|
23
|
+
var silent = agent === "cursor" ? { permission: "allow" } : agent === "claude_code" ? {
|
|
24
|
+
hookSpecificOutput: { hookEventName: "PreToolUse", permissionDecision: "allow" }
|
|
25
|
+
} : {};
|
|
26
|
+
var remaining = Math.max(0, BUDGET_MS - process.uptime() * 1e3 - OUTPUT_RESERVE_MS);
|
|
27
|
+
var child;
|
|
28
|
+
var finished = false;
|
|
29
|
+
var stdout = "";
|
|
30
|
+
var stderr = "";
|
|
31
|
+
function stopWorker() {
|
|
32
|
+
if (!child?.pid) return;
|
|
33
|
+
try {
|
|
34
|
+
if (process.platform !== "win32") process.kill(-child.pid, "SIGKILL");
|
|
35
|
+
else child.kill("SIGKILL");
|
|
36
|
+
} catch {
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function finish(output = silent, diagnostics = "") {
|
|
40
|
+
if (finished) return;
|
|
41
|
+
finished = true;
|
|
42
|
+
clearTimeout(timer);
|
|
43
|
+
process.stdin.unpipe();
|
|
44
|
+
process.stdin.pause();
|
|
45
|
+
stopWorker();
|
|
46
|
+
if (diagnostics) process.stderr.write(diagnostics);
|
|
47
|
+
process.stdout.write(`${JSON.stringify(output)}
|
|
48
|
+
`, () => process.exit(0));
|
|
49
|
+
}
|
|
50
|
+
var timer = setTimeout(() => finish(), remaining);
|
|
51
|
+
process.once("SIGTERM", () => finish());
|
|
52
|
+
process.once("SIGINT", () => finish());
|
|
53
|
+
process.once("exit", stopWorker);
|
|
54
|
+
if (remaining <= 0) finish();
|
|
55
|
+
else {
|
|
56
|
+
try {
|
|
57
|
+
child = spawn(
|
|
58
|
+
process.execPath,
|
|
59
|
+
[
|
|
60
|
+
fileURLToPath(new URL("./pre-tool-use-worker.js", import.meta.url)),
|
|
61
|
+
"--agent",
|
|
62
|
+
agent,
|
|
63
|
+
String(Date.now() + remaining - 50)
|
|
64
|
+
],
|
|
65
|
+
{
|
|
66
|
+
detached: process.platform !== "win32",
|
|
67
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
child.on("error", () => finish());
|
|
71
|
+
child.stdin?.on("error", () => finish());
|
|
72
|
+
child.stderr?.setEncoding("utf8").on("data", (chunk) => {
|
|
73
|
+
stderr = (stderr + chunk).slice(0, MAX_OUTPUT_BYTES);
|
|
74
|
+
});
|
|
75
|
+
child.stdout?.setEncoding("utf8").on("data", (chunk) => {
|
|
76
|
+
stdout += chunk;
|
|
77
|
+
if (stdout.length > MAX_OUTPUT_BYTES) return finish();
|
|
78
|
+
if (!stdout.includes("\n")) return;
|
|
79
|
+
try {
|
|
80
|
+
const message = JSON.parse(stdout);
|
|
81
|
+
if (!message || typeof message !== "object" || !("output" in message) || !("confirmed" in message))
|
|
82
|
+
return finish();
|
|
83
|
+
if (!message.output || typeof message.output !== "object" || Array.isArray(message.output))
|
|
84
|
+
return finish();
|
|
85
|
+
if (message.confirmed === true) finish(message.output, stderr);
|
|
86
|
+
else finish();
|
|
87
|
+
} catch {
|
|
88
|
+
finish();
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
child.on("exit", () => finish());
|
|
92
|
+
if (child.stdin) process.stdin.pipe(child.stdin);
|
|
93
|
+
} catch {
|
|
94
|
+
finish();
|
|
95
|
+
}
|
|
96
|
+
}
|