@primitive.ai/prim 0.1.0-alpha.126 → 0.1.0-alpha.127
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 +140 -1
- package/SKILL.md +6 -1
- package/dist/{chunk-JFWJN2ME.js → chunk-72NIZMZN.js} +114 -5
- package/dist/{chunk-R6NDP7OF.js → chunk-A5VTE43F.js} +2 -2
- package/dist/{chunk-C5VBPHOS.js → chunk-C4QNBSWB.js} +20 -6
- package/dist/{chunk-BFYJLI7V.js → chunk-F3FDVHR7.js} +1 -1
- package/dist/{chunk-YP4OXKNX.js → chunk-H6X52UVF.js} +1 -1
- package/dist/{chunk-ND6TYHNI.js → chunk-H74RDXKP.js} +2 -2
- package/dist/{chunk-NJBN3WXF.js → chunk-HZI5PBN4.js} +785 -154
- package/dist/{chunk-FYYHBOOM.js → chunk-JCKOW45X.js} +2 -2
- package/dist/{chunk-DT7E3SD5.js → chunk-KFRGVHGB.js} +4 -4
- package/dist/{chunk-TI37ME2D.js → chunk-L6IL4N6Y.js} +16 -7
- package/dist/{chunk-KKUDAQQZ.js → chunk-MGKSZSTV.js} +3 -3
- package/dist/{chunk-ZKXNJB6U.js → chunk-NVDPKW7Z.js} +69 -29
- package/dist/{chunk-NBNQI3YJ.js → chunk-O65UVJZH.js} +6 -3
- package/dist/{chunk-74DQDWLW.js → chunk-R4EYLEIK.js} +7 -2
- package/dist/{chunk-5D2C6RCH.js → chunk-RV3JFSMX.js} +4 -4
- package/dist/{chunk-PPZ56EVJ.js → chunk-TNWI3JWK.js} +1 -1
- package/dist/{chunk-6KXQQ7CQ.js → chunk-URYZDQFH.js} +3 -3
- package/dist/{chunk-L32WYFJT.js → chunk-UUQT5GMO.js} +135 -12
- package/dist/{chunk-EZXIKEMA.js → chunk-VVFVENU4.js} +6 -4
- package/dist/{chunk-O73J3KQQ.js → chunk-WGTUNUIS.js} +5 -2
- package/dist/daemon/server.js +805 -218
- package/dist/hook-runtime/daemon/server.js +805 -218
- package/dist/hook-runtime/hooks/post-commit.js +286 -59
- package/dist/hook-runtime/hooks/post-rewrite.js +278 -51
- package/dist/hook-runtime/hooks/post-tool-use.js +672 -194
- package/dist/hook-runtime/hooks/pre-commit.js +536 -88
- package/dist/hook-runtime/hooks/pre-tool-use-worker.js +608 -157
- package/dist/hook-runtime/hooks/prim-hook.js +642 -167
- package/dist/hook-runtime/hooks/session-end.js +263 -47
- package/dist/hook-runtime/hooks/session-start.js +1103 -476
- package/dist/hook-runtime/index.js +3645 -2120
- package/dist/hook-runtime/statusline-main.js +257 -29
- package/dist/hooks/post-commit.js +7 -7
- package/dist/hooks/post-rewrite.js +6 -6
- package/dist/hooks/post-tool-use.js +15 -15
- package/dist/hooks/pre-commit.js +4 -4
- package/dist/hooks/pre-tool-use-worker.js +14 -15
- package/dist/hooks/prim-hook.js +16 -16
- package/dist/hooks/session-end.js +4 -4
- package/dist/hooks/session-start.js +49 -18
- package/dist/index.js +1014 -271
- package/dist/statusline-main.js +257 -29
- package/package.json +1 -1
|
@@ -11,8 +11,17 @@ import { join as join7 } from "path";
|
|
|
11
11
|
|
|
12
12
|
// src/lib/machine-credentials.ts
|
|
13
13
|
import { execFileSync } from "child_process";
|
|
14
|
-
import { createHash as createHash3, randomUUID as randomUUID2 } from "crypto";
|
|
15
|
-
import {
|
|
14
|
+
import { createHash as createHash3, randomBytes as randomBytes3, randomUUID as randomUUID2 } from "crypto";
|
|
15
|
+
import {
|
|
16
|
+
chmodSync,
|
|
17
|
+
existsSync as existsSync3,
|
|
18
|
+
linkSync,
|
|
19
|
+
lstatSync as lstatSync3,
|
|
20
|
+
mkdirSync as mkdirSync3,
|
|
21
|
+
readFileSync as readFileSync5,
|
|
22
|
+
rmSync as rmSync5,
|
|
23
|
+
writeFileSync as writeFileSync3
|
|
24
|
+
} from "fs";
|
|
16
25
|
import { createRequire } from "module";
|
|
17
26
|
import { dirname as dirname4, join as join6 } from "path";
|
|
18
27
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
@@ -64,6 +73,7 @@ var PRIM_CONFIG_SHELL_RESOLVER = [
|
|
|
64
73
|
'else prim_home=${HOME:-}; prim_absolute "$prim_home" || exit 78; case "$prim_home" in /) prim_config=/.config/prim ;; *) prim_config="$prim_home/.config/prim" ;; esac; ',
|
|
65
74
|
"fi; fi; "
|
|
66
75
|
].join("");
|
|
76
|
+
var LAUNCHER_EXEC = 'exec "$prim_launcher" "$@"';
|
|
67
77
|
function stableHookCommand(bin, args = "") {
|
|
68
78
|
if (!STABLE_HOOK_BIN_RE.test(bin) || !STABLE_HOOK_ARGUMENTS_RE.test(args)) {
|
|
69
79
|
throw new Error("invalid stable hook command");
|
|
@@ -75,7 +85,7 @@ function stableHookCommand(bin, args = "") {
|
|
|
75
85
|
`prim_legacy_reader='-p ${PKG_NAME}@stable prim-shim.sh ${bin} '; `,
|
|
76
86
|
PRIM_CONFIG_SHELL_RESOLVER,
|
|
77
87
|
`case "$prim_config" in /) prim_launcher=/${STABLE_HOOK_LAUNCHER_NAME} ;; *) prim_launcher="$prim_config/${STABLE_HOOK_LAUNCHER_NAME}" ;; esac; `,
|
|
78
|
-
|
|
88
|
+
LAUNCHER_EXEC
|
|
79
89
|
].join("");
|
|
80
90
|
const suffix = args ? ` ${args}` : "";
|
|
81
91
|
return `/bin/sh -c ${shellQuote(resolver)} ${STABLE_HOOK_LAUNCHER_NAME} ${bin}${suffix}`;
|
|
@@ -84,6 +94,15 @@ function detachedHookShimCommand(bin, args = "") {
|
|
|
84
94
|
return `payload=$(cat); { trap '' HUP; printf '%s' "$payload" | { ${stableHookCommand(bin, args)}; }; } </dev/null >/dev/null 2>&1 &`;
|
|
85
95
|
}
|
|
86
96
|
|
|
97
|
+
// src/lib/loopback-fetch.ts
|
|
98
|
+
import { request } from "http";
|
|
99
|
+
import { Readable } from "stream";
|
|
100
|
+
|
|
101
|
+
// src/lib/cloud-env.ts
|
|
102
|
+
function isClaudeCloudSession(env = process.env) {
|
|
103
|
+
return env.CLAUDE_CODE_REMOTE === "true";
|
|
104
|
+
}
|
|
105
|
+
|
|
87
106
|
// src/lib/workos-connect.ts
|
|
88
107
|
var DISCOVERY_MAX_BYTES = 16 * 1024;
|
|
89
108
|
var WORKOS_CONNECT_RESPONSE_MAX_BYTES = 64 * 1024;
|
|
@@ -259,12 +278,16 @@ function primConfigDirectory(options = {}) {
|
|
|
259
278
|
|
|
260
279
|
// src/lib/machine-broker.ts
|
|
261
280
|
var MAX_RESPONSE_BYTES = 96 * 1024;
|
|
281
|
+
var MAX_FORWARD_REQUEST_BYTES = 12 * 1024 * 1024;
|
|
282
|
+
var MAX_API_RESPONSE_BYTES = 8 * 1024 * 1024;
|
|
283
|
+
var MAX_FORWARD_RESPONSE_BYTES = 36 * 1024 * 1024;
|
|
262
284
|
var IDLE_MS = 5 * 6e4;
|
|
263
285
|
|
|
264
286
|
// src/lib/machine-retry.ts
|
|
265
287
|
import { createHash as createHash2 } from "crypto";
|
|
266
|
-
import { lstatSync as lstatSync2, readFileSync as readFileSync4, rmSync as rmSync4 } from "fs";
|
|
288
|
+
import { lstatSync as lstatSync2, readFileSync as readFileSync4, readdirSync, rmSync as rmSync4 } from "fs";
|
|
267
289
|
import { join as join5 } from "path";
|
|
290
|
+
var MAX_SERVER_WAIT_MS = 15 * 6e4;
|
|
268
291
|
|
|
269
292
|
// src/lib/machine-credentials.ts
|
|
270
293
|
var require2 = createRequire(import.meta.url);
|
|
@@ -307,6 +330,33 @@ function readEnvironmentContext(environment, deps) {
|
|
|
307
330
|
return void 0;
|
|
308
331
|
}
|
|
309
332
|
}
|
|
333
|
+
function protectPath(path, directory) {
|
|
334
|
+
if (process.platform !== "win32") {
|
|
335
|
+
chmodSync(path, directory ? 448 : 384);
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
const encodedPath = Buffer.from(path).toString("base64");
|
|
339
|
+
const script = `$ErrorActionPreference = 'Stop'; $p = [Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('${encodedPath}')); $sid = [Security.Principal.WindowsIdentity]::GetCurrent().User; $acl = [System.Security.AccessControl.${directory ? "DirectorySecurity" : "FileSecurity"}]::new(); $acl.SetOwner($sid); $acl.SetAccessRuleProtection($true, $false); $rule = [System.Security.AccessControl.FileSystemAccessRule]::new($sid, 'FullControl', '${directory ? "ContainerInherit, ObjectInherit" : "None"}', 'None', 'Allow'); $acl.AddAccessRule($rule); [System.IO.${directory ? "Directory" : "File"}]::SetAccessControl($p, $acl)`;
|
|
340
|
+
execFileSync(
|
|
341
|
+
"powershell.exe",
|
|
342
|
+
[
|
|
343
|
+
"-NoProfile",
|
|
344
|
+
"-NonInteractive",
|
|
345
|
+
"-EncodedCommand",
|
|
346
|
+
Buffer.from(script, "utf16le").toString("base64")
|
|
347
|
+
],
|
|
348
|
+
{ stdio: "pipe", encoding: "utf8", windowsHide: true }
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
function ensureDirectory(directory) {
|
|
352
|
+
mkdirSync3(directory, { recursive: true, mode: 448 });
|
|
353
|
+
if (lstatSync3(directory).isSymbolicLink())
|
|
354
|
+
throw new MachineAuthError(
|
|
355
|
+
"unsafe_storage",
|
|
356
|
+
"Credential directory must not be a symbolic link."
|
|
357
|
+
);
|
|
358
|
+
protectPath(directory, true);
|
|
359
|
+
}
|
|
310
360
|
function readPrivate(path) {
|
|
311
361
|
let raw;
|
|
312
362
|
try {
|
|
@@ -365,10 +415,98 @@ function readMachineProfile(deps = {}) {
|
|
|
365
415
|
const value = readPrivate(join6(configurationDirectory(deps), PROFILE_FILE));
|
|
366
416
|
return value === void 0 ? void 0 : parseProfile(value);
|
|
367
417
|
}
|
|
418
|
+
var NETWORK_SECRET_AUTH = "network-secret";
|
|
419
|
+
var NETWORK_TOKEN_AUTH = "network-token";
|
|
420
|
+
var INJECTED_IDENTITY_TTL_MS = 60 * 6e4;
|
|
421
|
+
var brokerKeys = /* @__PURE__ */ new Map();
|
|
422
|
+
function networkSecretBrokerKey(deps, clientId) {
|
|
423
|
+
const directory = configurationDirectory(deps);
|
|
424
|
+
const path = join6(directory, `machine_network_${hash(`${apiUrlFor(deps)}\0${clientId}`)}.key`);
|
|
425
|
+
const known = brokerKeys.get(path);
|
|
426
|
+
if (known) return known;
|
|
427
|
+
ensureDirectory(directory);
|
|
428
|
+
const read = () => {
|
|
429
|
+
try {
|
|
430
|
+
const stat = lstatSync3(path);
|
|
431
|
+
if (!stat.isFile() || process.platform !== "win32" && ((stat.mode & 63) !== 0 || typeof process.getuid === "function" && stat.uid !== process.getuid()))
|
|
432
|
+
throw new MachineAuthError(
|
|
433
|
+
"unsafe_storage",
|
|
434
|
+
`The machine broker key at ${path} is not an owner-only file. Delete it and retry.`,
|
|
435
|
+
true
|
|
436
|
+
);
|
|
437
|
+
const value = readFileSync5(path, "utf8").trim();
|
|
438
|
+
return { key: /^[a-f0-9]{64}$/u.test(value) ? value : void 0 };
|
|
439
|
+
} catch (error) {
|
|
440
|
+
if (error.code === "ENOENT") return void 0;
|
|
441
|
+
throw error;
|
|
442
|
+
}
|
|
443
|
+
};
|
|
444
|
+
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
445
|
+
const existing = read();
|
|
446
|
+
if (existing?.key) {
|
|
447
|
+
brokerKeys.set(path, existing.key);
|
|
448
|
+
return existing.key;
|
|
449
|
+
}
|
|
450
|
+
if (existing)
|
|
451
|
+
throw new MachineAuthError(
|
|
452
|
+
"unsafe_storage",
|
|
453
|
+
`The machine broker key at ${path} is damaged. Delete it and retry.`,
|
|
454
|
+
true
|
|
455
|
+
);
|
|
456
|
+
const staged = `${path}.${process.pid}.${randomBytes3(6).toString("hex")}`;
|
|
457
|
+
try {
|
|
458
|
+
writeFileSync3(staged, `${randomBytes3(32).toString("hex")}
|
|
459
|
+
`, { mode: 384, flag: "wx" });
|
|
460
|
+
protectPath(staged, false);
|
|
461
|
+
linkSync(staged, path);
|
|
462
|
+
} catch (error) {
|
|
463
|
+
if (error.code !== "EEXIST") throw error;
|
|
464
|
+
} finally {
|
|
465
|
+
rmSync5(staged, { force: true });
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
const key = read()?.key;
|
|
469
|
+
if (!key)
|
|
470
|
+
throw new MachineAuthError("unsafe_storage", "The machine broker key is unreadable.", true);
|
|
471
|
+
brokerKeys.set(path, key);
|
|
472
|
+
return key;
|
|
473
|
+
}
|
|
368
474
|
function environmentCredentials(deps) {
|
|
369
475
|
const env = deps.env ?? process.env;
|
|
370
|
-
const {
|
|
371
|
-
|
|
476
|
+
const {
|
|
477
|
+
PRIM_M2M_CLIENT_ID: clientId,
|
|
478
|
+
PRIM_M2M_CLIENT_SECRET: clientSecret,
|
|
479
|
+
PRIM_M2M_CLIENT_AUTH: auth
|
|
480
|
+
} = env;
|
|
481
|
+
if (clientId === void 0 && clientSecret === void 0 && auth === void 0) return void 0;
|
|
482
|
+
if (auth !== void 0 && auth !== NETWORK_SECRET_AUTH && auth !== NETWORK_TOKEN_AUTH)
|
|
483
|
+
throw new MachineAuthError(
|
|
484
|
+
"incomplete_machine_credentials",
|
|
485
|
+
`PRIM_M2M_CLIENT_AUTH accepts ${NETWORK_SECRET_AUTH} or ${NETWORK_TOKEN_AUTH}.`
|
|
486
|
+
);
|
|
487
|
+
if (auth !== void 0) {
|
|
488
|
+
if (!clientId || !/^client_[\w-]+$/u.test(clientId))
|
|
489
|
+
throw new MachineAuthError(
|
|
490
|
+
"incomplete_machine_credentials",
|
|
491
|
+
`Set PRIM_M2M_CLIENT_ID with PRIM_M2M_CLIENT_AUTH=${auth}.`
|
|
492
|
+
);
|
|
493
|
+
if (clientSecret !== void 0)
|
|
494
|
+
throw new MachineAuthError(
|
|
495
|
+
"conflicting_credentials",
|
|
496
|
+
`Unset PRIM_M2M_CLIENT_SECRET: with PRIM_M2M_CLIENT_AUTH=${auth} the environment's network secret supplies it.`
|
|
497
|
+
);
|
|
498
|
+
const generation = hash(`${apiUrlFor(deps)}\0${clientId}\0${auth}\0broker-proxy`);
|
|
499
|
+
const credentials = {
|
|
500
|
+
clientId,
|
|
501
|
+
generation,
|
|
502
|
+
...auth === NETWORK_TOKEN_AUTH ? { tokenInjection: "network" } : { secretInjection: "network" }
|
|
503
|
+
};
|
|
504
|
+
Object.defineProperty(credentials, "clientSecret", {
|
|
505
|
+
enumerable: true,
|
|
506
|
+
get: () => networkSecretBrokerKey(deps, clientId)
|
|
507
|
+
});
|
|
508
|
+
return credentials;
|
|
509
|
+
}
|
|
372
510
|
if (!clientId || !clientSecret || !/^client_[\w-]+$/u.test(clientId) || !machineString(clientSecret)) {
|
|
373
511
|
throw new MachineAuthError(
|
|
374
512
|
"incomplete_machine_credentials",
|
|
@@ -383,7 +521,7 @@ function environmentCredentials(deps) {
|
|
|
383
521
|
}
|
|
384
522
|
function hasMachineConfiguration(deps = {}) {
|
|
385
523
|
const env = deps.env ?? process.env;
|
|
386
|
-
const configured = env.PRIM_M2M_CLIENT_ID !== void 0 || env.PRIM_M2M_CLIENT_SECRET !== void 0 || existsSync3(join6(configurationDirectory(deps), PROFILE_FILE));
|
|
524
|
+
const configured = env.PRIM_M2M_CLIENT_ID !== void 0 || env.PRIM_M2M_CLIENT_SECRET !== void 0 || env.PRIM_M2M_CLIENT_AUTH !== void 0 || existsSync3(join6(configurationDirectory(deps), PROFILE_FILE));
|
|
387
525
|
if (configured && env.PRIM_TOKEN?.trim()) {
|
|
388
526
|
throw new MachineAuthError(
|
|
389
527
|
"conflicting_credentials",
|
|
@@ -438,7 +576,7 @@ function readTrimmed(path) {
|
|
|
438
576
|
function resolveAuthCredential(options = {}) {
|
|
439
577
|
if (!options.tokenFilePath && hasMachineConfiguration({ env: options.env })) {
|
|
440
578
|
const machine = cachedMachineCredential({ env: options.env });
|
|
441
|
-
return machine ? { token: machine.accessToken, source: "machine" } : void 0;
|
|
579
|
+
return machine?.accessToken ? { token: machine.accessToken, source: "machine" } : void 0;
|
|
442
580
|
}
|
|
443
581
|
const envToken = (options.env ?? process.env).PRIM_TOKEN?.trim();
|
|
444
582
|
if (envToken) return { token: envToken, source: "environment" };
|
|
@@ -617,7 +755,7 @@ var nextRequestId = 1;
|
|
|
617
755
|
function daemonRequest(method, params = {}, opts = {}) {
|
|
618
756
|
const id = nextRequestId++;
|
|
619
757
|
const caller = resolveDaemonPrincipal();
|
|
620
|
-
const
|
|
758
|
+
const request2 = {
|
|
621
759
|
id,
|
|
622
760
|
method,
|
|
623
761
|
params,
|
|
@@ -656,7 +794,7 @@ function daemonRequest(method, params = {}, opts = {}) {
|
|
|
656
794
|
});
|
|
657
795
|
socket.on("connect", () => {
|
|
658
796
|
try {
|
|
659
|
-
socket?.write(`${JSON.stringify(
|
|
797
|
+
socket?.write(`${JSON.stringify(request2)}
|
|
660
798
|
`);
|
|
661
799
|
} catch {
|
|
662
800
|
clearTimeout(timer);
|
|
@@ -702,9 +840,25 @@ function daemonRequest(method, params = {}, opts = {}) {
|
|
|
702
840
|
|
|
703
841
|
// src/lib/activation.ts
|
|
704
842
|
import { execFileSync as execFileSync4 } from "child_process";
|
|
705
|
-
import { existsSync as
|
|
843
|
+
import { existsSync as existsSync5, readFileSync as readFileSync9 } from "fs";
|
|
706
844
|
import { homedir as homedir2 } from "os";
|
|
845
|
+
import { join as join11 } from "path";
|
|
846
|
+
|
|
847
|
+
// src/lib/cloud-prepared.ts
|
|
848
|
+
import { existsSync as existsSync4, mkdirSync as mkdirSync4, readFileSync as readFileSync7, rmSync as rmSync6, writeFileSync as writeFileSync4 } from "fs";
|
|
707
849
|
import { join as join9 } from "path";
|
|
850
|
+
var CLOUD_PREPARED_MARKER = "cloud-prepared";
|
|
851
|
+
function cloudPreparedPath(env = process.env) {
|
|
852
|
+
return join9(primConfigDirectory({ env }), CLOUD_PREPARED_MARKER);
|
|
853
|
+
}
|
|
854
|
+
function isPreparedCloudSession(env = process.env) {
|
|
855
|
+
if (!isClaudeCloudSession(env)) return false;
|
|
856
|
+
try {
|
|
857
|
+
return existsSync4(cloudPreparedPath(env));
|
|
858
|
+
} catch {
|
|
859
|
+
return false;
|
|
860
|
+
}
|
|
861
|
+
}
|
|
708
862
|
|
|
709
863
|
// src/lib/demo-pause.ts
|
|
710
864
|
import { execFileSync as execFileSync2 } from "child_process";
|
|
@@ -770,11 +924,12 @@ function healDemoPause(cwd, pause, options = {}) {
|
|
|
770
924
|
// src/lib/git.ts
|
|
771
925
|
import { execFileSync as execFileSync3 } from "child_process";
|
|
772
926
|
import { createHash as createHash6 } from "crypto";
|
|
773
|
-
import { lstatSync as lstatSync4, realpathSync } from "fs";
|
|
774
|
-
import { basename as basename2, dirname as dirname5, isAbsolute as isAbsolute3, relative, resolve, sep } from "path";
|
|
927
|
+
import { lstatSync as lstatSync4, readFileSync as readFileSync8, realpathSync } from "fs";
|
|
928
|
+
import { basename as basename2, dirname as dirname5, isAbsolute as isAbsolute3, join as join10, relative, resolve, sep } from "path";
|
|
775
929
|
var GIT_TIMEOUT_MS2 = 1e3;
|
|
930
|
+
var MAX_SETTINGS_BYTES = 1024 * 1024;
|
|
776
931
|
var GITHUB_OWNER_PATTERN = /^(?![A-Za-z0-9-]*--)[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/u;
|
|
777
|
-
var GITHUB_REPOSITORY_PATTERN = /^[A-Za-z0-9._-]{1,100}$/u;
|
|
932
|
+
var GITHUB_REPOSITORY_PATTERN = /^(?!\.{1,2}$)[A-Za-z0-9._-]{1,100}$/u;
|
|
778
933
|
function gitToplevel(cwd) {
|
|
779
934
|
try {
|
|
780
935
|
return execFileSync3("git", ["rev-parse", "--show-toplevel"], {
|
|
@@ -800,19 +955,57 @@ function gitValue(cwd, args) {
|
|
|
800
955
|
return void 0;
|
|
801
956
|
}
|
|
802
957
|
}
|
|
803
|
-
function
|
|
804
|
-
const
|
|
805
|
-
if (
|
|
958
|
+
function parseGithubRepositoryName(path) {
|
|
959
|
+
const parts = path.replace(/^\/+|\/+$/g, "").replace(/\.git$/i, "").split("/");
|
|
960
|
+
if (parts.length !== 2 || !GITHUB_OWNER_PATTERN.test(parts[0] ?? "") || !GITHUB_REPOSITORY_PATTERN.test(parts[1] ?? "")) {
|
|
961
|
+
return null;
|
|
962
|
+
}
|
|
963
|
+
return `${parts[0]}/${parts[1]}`;
|
|
964
|
+
}
|
|
965
|
+
function githubRepositoryFromRemote(remote) {
|
|
966
|
+
if ([...remote].some((char) => char < " " || char === "\x7F")) return null;
|
|
806
967
|
const match = /^(?:git@github\.com:([^?#]+)|(?:https|ssh):\/\/(?:[^/@]+@)?github\.com(?::\d+)?\/([^?#]+))$/i.exec(
|
|
807
968
|
remote
|
|
808
969
|
);
|
|
809
970
|
const path = match?.[1] ?? match?.[2];
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
971
|
+
return path ? parseGithubRepositoryName(path) : null;
|
|
972
|
+
}
|
|
973
|
+
function checkoutSettingsText(repoRoot) {
|
|
974
|
+
const path = join10(repoRoot, ".claude", "settings.json");
|
|
975
|
+
try {
|
|
976
|
+
if (!lstatSync4(join10(repoRoot, ".claude")).isDirectory()) return null;
|
|
977
|
+
const stat = lstatSync4(path);
|
|
978
|
+
if (!stat.isFile() || stat.size > MAX_SETTINGS_BYTES) return null;
|
|
979
|
+
return readFileSync8(path, "utf8");
|
|
980
|
+
} catch {
|
|
813
981
|
return null;
|
|
814
982
|
}
|
|
815
|
-
|
|
983
|
+
}
|
|
984
|
+
function checkoutDeclaration(repoRoot, name) {
|
|
985
|
+
const text = checkoutSettingsText(repoRoot);
|
|
986
|
+
if (text === null) return null;
|
|
987
|
+
let parsed;
|
|
988
|
+
try {
|
|
989
|
+
parsed = JSON.parse(text);
|
|
990
|
+
} catch {
|
|
991
|
+
return null;
|
|
992
|
+
}
|
|
993
|
+
const env = typeof parsed === "object" && parsed !== null ? parsed.env : void 0;
|
|
994
|
+
const value = typeof env === "object" && env !== null ? env[name] : void 0;
|
|
995
|
+
return typeof value === "string" ? value : null;
|
|
996
|
+
}
|
|
997
|
+
function declaredGithubRepository(repoRoot) {
|
|
998
|
+
const value = checkoutDeclaration(repoRoot, "PRIM_REPOSITORY");
|
|
999
|
+
return value === null ? null : parseGithubRepositoryName(value.trim());
|
|
1000
|
+
}
|
|
1001
|
+
function githubRepositoryFullName(cwd) {
|
|
1002
|
+
const remote = gitValue(cwd, ["config", "--get", "remote.origin.url"]);
|
|
1003
|
+
if (remote) {
|
|
1004
|
+
const fromOrigin = githubRepositoryFromRemote(remote);
|
|
1005
|
+
if (fromOrigin || normalizeOriginRemote(remote)) return fromOrigin;
|
|
1006
|
+
}
|
|
1007
|
+
const root = gitToplevel(cwd);
|
|
1008
|
+
return root ? declaredGithubRepository(root) : null;
|
|
816
1009
|
}
|
|
817
1010
|
function normalizeOriginRemote(remote) {
|
|
818
1011
|
const value = remote.trim();
|
|
@@ -858,6 +1051,14 @@ function resolveRepositoryContext(cwd = process.cwd()) {
|
|
|
858
1051
|
repoFullName
|
|
859
1052
|
};
|
|
860
1053
|
}
|
|
1054
|
+
if (repoFullName) {
|
|
1055
|
+
return {
|
|
1056
|
+
repoRoot,
|
|
1057
|
+
repoKey: opaqueRepoKey("origin", `github.com/${repoFullName}`),
|
|
1058
|
+
identitySource: "declared",
|
|
1059
|
+
repoFullName
|
|
1060
|
+
};
|
|
1061
|
+
}
|
|
861
1062
|
const roots = gitValue(repoRoot, ["rev-list", "--max-parents=0", "HEAD"])?.split(/\s+/).filter(Boolean).sort();
|
|
862
1063
|
if (roots && roots.length > 0) {
|
|
863
1064
|
return {
|
|
@@ -872,6 +1073,7 @@ function resolveRepositoryContext(cwd = process.cwd()) {
|
|
|
872
1073
|
|
|
873
1074
|
// src/lib/activation.ts
|
|
874
1075
|
var PRIM_ACTIVE_KEY = "prim.active";
|
|
1076
|
+
var PRIM_ACTIVE_DECLARATION = "PRIM_ACTIVE";
|
|
875
1077
|
var GIT_TIMEOUT_MS3 = 1e3;
|
|
876
1078
|
var PROJECT_INSTALL_FILES = [".claude/settings.json", ".codex/hooks.json", ".cursor/hooks.json"];
|
|
877
1079
|
var PRIM_HOOK_BINS = ["prim-hook", "prim-pre-tool-use", "prim-post-tool-use"];
|
|
@@ -893,14 +1095,13 @@ function repoActiveFlag(cwd, strict = false) {
|
|
|
893
1095
|
return void 0;
|
|
894
1096
|
}
|
|
895
1097
|
}
|
|
896
|
-
function
|
|
897
|
-
const root = gitToplevel(cwd);
|
|
1098
|
+
function projectPrimInstallAt(root) {
|
|
898
1099
|
if (root === null || root === homedir2()) return false;
|
|
899
1100
|
for (const rel of PROJECT_INSTALL_FILES) {
|
|
900
|
-
const path =
|
|
901
|
-
if (
|
|
1101
|
+
const path = join11(root, rel);
|
|
1102
|
+
if (existsSync5(path)) {
|
|
902
1103
|
try {
|
|
903
|
-
const content =
|
|
1104
|
+
const content = readFileSync9(path, "utf-8");
|
|
904
1105
|
if (PRIM_HOOK_BINS.some((bin) => content.includes(bin))) return true;
|
|
905
1106
|
} catch {
|
|
906
1107
|
}
|
|
@@ -908,12 +1109,27 @@ function hasProjectPrimInstall(cwd) {
|
|
|
908
1109
|
}
|
|
909
1110
|
return false;
|
|
910
1111
|
}
|
|
1112
|
+
var UNPARSED_OPT_OUT = /"PRIM_ACTIVE"\s*:\s*"\s*false\s*"/u;
|
|
1113
|
+
function declaresInactiveAt(root) {
|
|
1114
|
+
if (root === null || root === homedir2()) return false;
|
|
1115
|
+
if (checkoutDeclaration(root, PRIM_ACTIVE_DECLARATION)?.trim() === "false") return true;
|
|
1116
|
+
const text = checkoutSettingsText(root);
|
|
1117
|
+
if (text === null || !UNPARSED_OPT_OUT.test(text)) return false;
|
|
1118
|
+
try {
|
|
1119
|
+
JSON.parse(text);
|
|
1120
|
+
return false;
|
|
1121
|
+
} catch {
|
|
1122
|
+
return true;
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
911
1125
|
function isRepoActiveForCapture(cwd, options = {}) {
|
|
912
1126
|
let { active: flag, pause } = readCaptureConfig(cwd);
|
|
913
1127
|
if (pause && healDemoPause(cwd, pause, options)) flag = repoActiveFlag(cwd);
|
|
914
1128
|
if (flag === "true") return true;
|
|
915
1129
|
if (flag === "false") return false;
|
|
916
|
-
|
|
1130
|
+
const root = gitToplevel(cwd);
|
|
1131
|
+
if (declaresInactiveAt(root)) return false;
|
|
1132
|
+
return projectPrimInstallAt(root) || isPreparedCloudSession() && root !== null;
|
|
917
1133
|
}
|
|
918
1134
|
|
|
919
1135
|
// src/hooks/agent.ts
|
|
@@ -927,31 +1143,31 @@ function parseAgent(argv) {
|
|
|
927
1143
|
}
|
|
928
1144
|
|
|
929
1145
|
// src/commands/cursor-install.ts
|
|
930
|
-
import { existsSync as
|
|
1146
|
+
import { existsSync as existsSync9, readFileSync as readFileSync12 } from "fs";
|
|
931
1147
|
import { homedir as homedir4 } from "os";
|
|
932
|
-
import { isAbsolute as isAbsolute5, join as
|
|
1148
|
+
import { isAbsolute as isAbsolute5, join as join15 } from "path";
|
|
933
1149
|
|
|
934
1150
|
// src/lib/hook-runtime.ts
|
|
935
|
-
import { createHash as createHash7, randomBytes as
|
|
1151
|
+
import { createHash as createHash7, randomBytes as randomBytes4 } from "crypto";
|
|
936
1152
|
import {
|
|
937
1153
|
constants as constants2,
|
|
938
1154
|
accessSync,
|
|
939
1155
|
chmodSync as chmodSync2,
|
|
940
1156
|
copyFileSync,
|
|
941
|
-
existsSync as
|
|
1157
|
+
existsSync as existsSync7,
|
|
942
1158
|
lstatSync as lstatSync5,
|
|
943
|
-
mkdirSync as
|
|
1159
|
+
mkdirSync as mkdirSync5,
|
|
944
1160
|
mkdtempSync,
|
|
945
|
-
readFileSync as
|
|
946
|
-
readdirSync,
|
|
1161
|
+
readFileSync as readFileSync10,
|
|
1162
|
+
readdirSync as readdirSync2,
|
|
947
1163
|
realpathSync as realpathSync2,
|
|
948
1164
|
renameSync as renameSync2,
|
|
949
|
-
rmSync as
|
|
1165
|
+
rmSync as rmSync7,
|
|
950
1166
|
statSync as statSync2,
|
|
951
1167
|
utimesSync,
|
|
952
|
-
writeFileSync as
|
|
1168
|
+
writeFileSync as writeFileSync5
|
|
953
1169
|
} from "fs";
|
|
954
|
-
import { delimiter, dirname as dirname7, isAbsolute as isAbsolute4, join as
|
|
1170
|
+
import { delimiter, dirname as dirname7, isAbsolute as isAbsolute4, join as join13, resolve as resolve2 } from "path";
|
|
955
1171
|
|
|
956
1172
|
// src/lib/git-hook-contract.ts
|
|
957
1173
|
var GIT_HOOK_ENTRYPOINT_CONTENT = `#!/bin/sh
|
|
@@ -999,9 +1215,9 @@ exit 0
|
|
|
999
1215
|
`;
|
|
1000
1216
|
|
|
1001
1217
|
// src/lib/native-keyring.ts
|
|
1002
|
-
import { existsSync as
|
|
1218
|
+
import { existsSync as existsSync6 } from "fs";
|
|
1003
1219
|
import { createRequire as createRequire2 } from "module";
|
|
1004
|
-
import { dirname as dirname6, join as
|
|
1220
|
+
import { dirname as dirname6, join as join12 } from "path";
|
|
1005
1221
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
1006
1222
|
var require3 = createRequire2(import.meta.url);
|
|
1007
1223
|
|
|
@@ -1055,9 +1271,9 @@ exec "$prim_node" "$prim_entry" "$@"
|
|
|
1055
1271
|
import { execFileSync as execFileSync5 } from "child_process";
|
|
1056
1272
|
|
|
1057
1273
|
// src/commands/claude-install.ts
|
|
1058
|
-
import { existsSync as
|
|
1274
|
+
import { existsSync as existsSync8, lstatSync as lstatSync6, readFileSync as readFileSync11 } from "fs";
|
|
1059
1275
|
import { homedir as homedir3 } from "os";
|
|
1060
|
-
import { join as
|
|
1276
|
+
import { join as join14 } from "path";
|
|
1061
1277
|
var CAPTURE_BIN = "prim-hook";
|
|
1062
1278
|
var GATE_BIN = "prim-pre-tool-use";
|
|
1063
1279
|
var POST_TOOL_USE_BIN = "prim-post-tool-use";
|
|
@@ -1066,7 +1282,7 @@ var SESSION_END_BIN = "prim-session-end";
|
|
|
1066
1282
|
var STATUSLINE_BIN = "prim-statusline";
|
|
1067
1283
|
var STATUSLINE_ARGS = "";
|
|
1068
1284
|
var STATUSLINE_COMMAND = stableHookCommand(STATUSLINE_BIN, STATUSLINE_ARGS);
|
|
1069
|
-
var USER_SCOPE_PATH =
|
|
1285
|
+
var USER_SCOPE_PATH = join14(homedir3(), ".claude", "settings.json");
|
|
1070
1286
|
function projectRoot() {
|
|
1071
1287
|
return gitToplevel() ?? process.cwd();
|
|
1072
1288
|
}
|
|
@@ -1146,20 +1362,20 @@ function cursorConfigDirectory(env = process.env, home = homedir4(), platform =
|
|
|
1146
1362
|
const explicit = env.CURSOR_CONFIG_DIR?.trim();
|
|
1147
1363
|
if (explicit && isAbsolute5(explicit)) return explicit;
|
|
1148
1364
|
const xdg = env.XDG_CONFIG_HOME?.trim();
|
|
1149
|
-
if (platform !== "darwin" && xdg && isAbsolute5(xdg)) return
|
|
1150
|
-
return
|
|
1365
|
+
if (platform !== "darwin" && xdg && isAbsolute5(xdg)) return join15(xdg, "cursor");
|
|
1366
|
+
return join15(home, ".cursor");
|
|
1151
1367
|
}
|
|
1152
1368
|
function cursorHooksPath(scope, root = projectRoot()) {
|
|
1153
|
-
return scope === "user" ?
|
|
1369
|
+
return scope === "user" ? join15(cursorConfigDirectory(), "hooks.json") : join15(root, ".cursor", "hooks.json");
|
|
1154
1370
|
}
|
|
1155
1371
|
function plainObject(value) {
|
|
1156
1372
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1157
1373
|
}
|
|
1158
1374
|
function readCursorHooks(path) {
|
|
1159
|
-
if (!
|
|
1375
|
+
if (!existsSync9(path)) return {};
|
|
1160
1376
|
let parsed;
|
|
1161
1377
|
try {
|
|
1162
|
-
parsed = JSON.parse(
|
|
1378
|
+
parsed = JSON.parse(readFileSync12(path, "utf8"));
|
|
1163
1379
|
} catch {
|
|
1164
1380
|
throw new Error(`invalid Cursor hooks JSON at ${path}`);
|
|
1165
1381
|
}
|