@primitive.ai/prim 0.1.0-alpha.15 → 0.1.0-alpha.16

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.
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ appendMove,
4
+ resolveOrg
5
+ } from "../chunk-JZGWQDM5.js";
6
+ import {
7
+ scrubFromCwd,
8
+ shouldFlushAfter,
9
+ toMove
10
+ } from "../chunk-PTLXSXIY.js";
11
+
12
+ // src/hooks/prim-hook.ts
13
+ import { spawn } from "child_process";
14
+ import { readFileSync } from "fs";
15
+ import { dirname, join } from "path";
16
+ import { fileURLToPath } from "url";
17
+ var here = dirname(fileURLToPath(import.meta.url));
18
+ function resolveCliVersion() {
19
+ try {
20
+ const pkg = JSON.parse(readFileSync(join(here, "..", "..", "package.json"), "utf-8"));
21
+ return pkg.version ?? "unknown";
22
+ } catch {
23
+ return "unknown";
24
+ }
25
+ }
26
+ function spawnBackgroundFlush() {
27
+ const entry = join(here, "..", "index.js");
28
+ spawn(process.execPath, [entry, "moves", "flush"], {
29
+ detached: true,
30
+ stdio: "ignore"
31
+ }).unref();
32
+ }
33
+ try {
34
+ const raw = readFileSync(0, "utf-8");
35
+ const parsed = JSON.parse(raw);
36
+ const cwd = parsed.cwd ?? process.cwd();
37
+ const base = toMove(parsed, resolveCliVersion());
38
+ const move = { ...base, payload: scrubFromCwd(parsed, cwd) };
39
+ const { orgId } = resolveOrg({ sessionId: move.sessionId, cwd: move.env.cwd });
40
+ appendMove(move, orgId);
41
+ if (shouldFlushAfter(move.eventType)) {
42
+ spawnBackgroundFlush();
43
+ }
44
+ } catch (err) {
45
+ if (process.env.PRIM_HOOK_DEBUG) {
46
+ const detail = err instanceof Error ? err.message : String(err);
47
+ process.stderr.write(`[prim-hook] capture failed: ${detail}
48
+ `);
49
+ }
50
+ }
51
+ process.exit(0);
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ daemonRequest
4
+ } from "../chunk-UTKQTZHL.js";
5
+
6
+ // src/hooks/session-end.ts
7
+ var STDIN_TIMEOUT_MS = 1e3;
8
+ var DAEMON_TIMEOUT_MS = 250;
9
+ function readStdin() {
10
+ return new Promise((resolve, reject) => {
11
+ const chunks = [];
12
+ const timer = setTimeout(() => {
13
+ reject(new Error("stdin read timeout"));
14
+ }, STDIN_TIMEOUT_MS);
15
+ process.stdin.on("data", (chunk) => chunks.push(chunk));
16
+ process.stdin.on("end", () => {
17
+ clearTimeout(timer);
18
+ resolve(Buffer.concat(chunks).toString("utf-8"));
19
+ });
20
+ process.stdin.on("error", (err) => {
21
+ clearTimeout(timer);
22
+ reject(err);
23
+ });
24
+ });
25
+ }
26
+ function emit() {
27
+ process.stdout.write("{}\n");
28
+ }
29
+ async function main() {
30
+ let raw;
31
+ try {
32
+ raw = await readStdin();
33
+ } catch {
34
+ emit();
35
+ return;
36
+ }
37
+ let envelope;
38
+ try {
39
+ envelope = JSON.parse(raw);
40
+ } catch {
41
+ emit();
42
+ return;
43
+ }
44
+ if (envelope.hook_event_name !== "SessionEnd") {
45
+ emit();
46
+ return;
47
+ }
48
+ if (typeof envelope.session_id !== "string" || envelope.session_id.length === 0) {
49
+ emit();
50
+ return;
51
+ }
52
+ await daemonRequest(
53
+ "session_end",
54
+ { sessionId: envelope.session_id },
55
+ { timeoutMs: DAEMON_TIMEOUT_MS }
56
+ );
57
+ emit();
58
+ }
59
+ main().catch(() => {
60
+ emit();
61
+ });
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ daemonRequest
4
+ } from "../chunk-UTKQTZHL.js";
5
+
6
+ // src/hooks/session-start.ts
7
+ var STDIN_TIMEOUT_MS = 1e3;
8
+ var DAEMON_TIMEOUT_MS = 250;
9
+ function readStdin() {
10
+ return new Promise((resolve, reject) => {
11
+ const chunks = [];
12
+ const timer = setTimeout(() => {
13
+ reject(new Error("stdin read timeout"));
14
+ }, STDIN_TIMEOUT_MS);
15
+ process.stdin.on("data", (chunk) => chunks.push(chunk));
16
+ process.stdin.on("end", () => {
17
+ clearTimeout(timer);
18
+ resolve(Buffer.concat(chunks).toString("utf-8"));
19
+ });
20
+ process.stdin.on("error", (err) => {
21
+ clearTimeout(timer);
22
+ reject(err);
23
+ });
24
+ });
25
+ }
26
+ function emit() {
27
+ process.stdout.write("{}\n");
28
+ }
29
+ async function main() {
30
+ let raw;
31
+ try {
32
+ raw = await readStdin();
33
+ } catch {
34
+ emit();
35
+ return;
36
+ }
37
+ let envelope;
38
+ try {
39
+ envelope = JSON.parse(raw);
40
+ } catch {
41
+ emit();
42
+ return;
43
+ }
44
+ if (envelope.hook_event_name !== "SessionStart") {
45
+ emit();
46
+ return;
47
+ }
48
+ if (typeof envelope.session_id !== "string" || envelope.session_id.length === 0) {
49
+ emit();
50
+ return;
51
+ }
52
+ await daemonRequest(
53
+ "session_start",
54
+ { sessionId: envelope.session_id },
55
+ { timeoutMs: DAEMON_TIMEOUT_MS }
56
+ );
57
+ emit();
58
+ }
59
+ main().catch(() => {
60
+ emit();
61
+ });