@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
|
@@ -54,8 +54,8 @@ var require_ucs2length = __commonJS({
|
|
|
54
54
|
|
|
55
55
|
// src/hooks/post-commit.ts
|
|
56
56
|
import { execFileSync as execFileSync7, spawn as spawn2 } from "child_process";
|
|
57
|
-
import { lstatSync as lstatSync7, readFileSync as
|
|
58
|
-
import { basename as basename4, dirname as dirname12, isAbsolute as isAbsolute5, join as
|
|
57
|
+
import { lstatSync as lstatSync7, readFileSync as readFileSync18 } from "fs";
|
|
58
|
+
import { basename as basename4, dirname as dirname12, isAbsolute as isAbsolute5, join as join19 } from "path";
|
|
59
59
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
60
60
|
|
|
61
61
|
// src/binding.ts
|
|
@@ -69,8 +69,17 @@ import { join as join7 } from "path";
|
|
|
69
69
|
|
|
70
70
|
// src/lib/machine-credentials.ts
|
|
71
71
|
import { execFileSync } from "child_process";
|
|
72
|
-
import { createHash as createHash3, randomUUID as randomUUID2 } from "crypto";
|
|
73
|
-
import {
|
|
72
|
+
import { createHash as createHash3, randomBytes as randomBytes3, randomUUID as randomUUID2 } from "crypto";
|
|
73
|
+
import {
|
|
74
|
+
chmodSync,
|
|
75
|
+
existsSync as existsSync3,
|
|
76
|
+
linkSync,
|
|
77
|
+
lstatSync as lstatSync3,
|
|
78
|
+
mkdirSync as mkdirSync3,
|
|
79
|
+
readFileSync as readFileSync5,
|
|
80
|
+
rmSync as rmSync5,
|
|
81
|
+
writeFileSync as writeFileSync3
|
|
82
|
+
} from "fs";
|
|
74
83
|
import { createRequire } from "module";
|
|
75
84
|
import { dirname as dirname4, join as join6 } from "path";
|
|
76
85
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
@@ -212,6 +221,15 @@ var PRIM_CONFIG_SHELL_RESOLVER = [
|
|
|
212
221
|
"fi; fi; "
|
|
213
222
|
].join("");
|
|
214
223
|
|
|
224
|
+
// src/lib/loopback-fetch.ts
|
|
225
|
+
import { request } from "http";
|
|
226
|
+
import { Readable } from "stream";
|
|
227
|
+
|
|
228
|
+
// src/lib/cloud-env.ts
|
|
229
|
+
function isClaudeCloudSession(env = process.env) {
|
|
230
|
+
return env.CLAUDE_CODE_REMOTE === "true";
|
|
231
|
+
}
|
|
232
|
+
|
|
215
233
|
// src/lib/workos-connect.ts
|
|
216
234
|
var DISCOVERY_MAX_BYTES = 16 * 1024;
|
|
217
235
|
var WORKOS_CONNECT_RESPONSE_MAX_BYTES = 64 * 1024;
|
|
@@ -387,12 +405,16 @@ function primConfigDirectory(options = {}) {
|
|
|
387
405
|
|
|
388
406
|
// src/lib/machine-broker.ts
|
|
389
407
|
var MAX_RESPONSE_BYTES = 96 * 1024;
|
|
408
|
+
var MAX_FORWARD_REQUEST_BYTES = 12 * 1024 * 1024;
|
|
409
|
+
var MAX_API_RESPONSE_BYTES = 8 * 1024 * 1024;
|
|
410
|
+
var MAX_FORWARD_RESPONSE_BYTES = 36 * 1024 * 1024;
|
|
390
411
|
var IDLE_MS = 5 * 6e4;
|
|
391
412
|
|
|
392
413
|
// src/lib/machine-retry.ts
|
|
393
414
|
import { createHash as createHash2 } from "crypto";
|
|
394
|
-
import { lstatSync as lstatSync2, readFileSync as readFileSync4, rmSync as rmSync4 } from "fs";
|
|
415
|
+
import { lstatSync as lstatSync2, readFileSync as readFileSync4, readdirSync, rmSync as rmSync4 } from "fs";
|
|
395
416
|
import { join as join5 } from "path";
|
|
417
|
+
var MAX_SERVER_WAIT_MS = 15 * 6e4;
|
|
396
418
|
|
|
397
419
|
// src/lib/machine-credentials.ts
|
|
398
420
|
var require2 = createRequire(import.meta.url);
|
|
@@ -435,6 +457,33 @@ function readEnvironmentContext(environment, deps) {
|
|
|
435
457
|
return void 0;
|
|
436
458
|
}
|
|
437
459
|
}
|
|
460
|
+
function protectPath(path, directory) {
|
|
461
|
+
if (process.platform !== "win32") {
|
|
462
|
+
chmodSync(path, directory ? 448 : 384);
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
const encodedPath = Buffer.from(path).toString("base64");
|
|
466
|
+
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)`;
|
|
467
|
+
execFileSync(
|
|
468
|
+
"powershell.exe",
|
|
469
|
+
[
|
|
470
|
+
"-NoProfile",
|
|
471
|
+
"-NonInteractive",
|
|
472
|
+
"-EncodedCommand",
|
|
473
|
+
Buffer.from(script, "utf16le").toString("base64")
|
|
474
|
+
],
|
|
475
|
+
{ stdio: "pipe", encoding: "utf8", windowsHide: true }
|
|
476
|
+
);
|
|
477
|
+
}
|
|
478
|
+
function ensureDirectory(directory) {
|
|
479
|
+
mkdirSync3(directory, { recursive: true, mode: 448 });
|
|
480
|
+
if (lstatSync3(directory).isSymbolicLink())
|
|
481
|
+
throw new MachineAuthError(
|
|
482
|
+
"unsafe_storage",
|
|
483
|
+
"Credential directory must not be a symbolic link."
|
|
484
|
+
);
|
|
485
|
+
protectPath(directory, true);
|
|
486
|
+
}
|
|
438
487
|
function readPrivate(path) {
|
|
439
488
|
let raw;
|
|
440
489
|
try {
|
|
@@ -493,10 +542,98 @@ function readMachineProfile(deps = {}) {
|
|
|
493
542
|
const value = readPrivate(join6(configurationDirectory(deps), PROFILE_FILE));
|
|
494
543
|
return value === void 0 ? void 0 : parseProfile(value);
|
|
495
544
|
}
|
|
545
|
+
var NETWORK_SECRET_AUTH = "network-secret";
|
|
546
|
+
var NETWORK_TOKEN_AUTH = "network-token";
|
|
547
|
+
var INJECTED_IDENTITY_TTL_MS = 60 * 6e4;
|
|
548
|
+
var brokerKeys = /* @__PURE__ */ new Map();
|
|
549
|
+
function networkSecretBrokerKey(deps, clientId) {
|
|
550
|
+
const directory = configurationDirectory(deps);
|
|
551
|
+
const path = join6(directory, `machine_network_${hash(`${apiUrlFor(deps)}\0${clientId}`)}.key`);
|
|
552
|
+
const known = brokerKeys.get(path);
|
|
553
|
+
if (known) return known;
|
|
554
|
+
ensureDirectory(directory);
|
|
555
|
+
const read = () => {
|
|
556
|
+
try {
|
|
557
|
+
const stat = lstatSync3(path);
|
|
558
|
+
if (!stat.isFile() || process.platform !== "win32" && ((stat.mode & 63) !== 0 || typeof process.getuid === "function" && stat.uid !== process.getuid()))
|
|
559
|
+
throw new MachineAuthError(
|
|
560
|
+
"unsafe_storage",
|
|
561
|
+
`The machine broker key at ${path} is not an owner-only file. Delete it and retry.`,
|
|
562
|
+
true
|
|
563
|
+
);
|
|
564
|
+
const value = readFileSync5(path, "utf8").trim();
|
|
565
|
+
return { key: /^[a-f0-9]{64}$/u.test(value) ? value : void 0 };
|
|
566
|
+
} catch (error) {
|
|
567
|
+
if (error.code === "ENOENT") return void 0;
|
|
568
|
+
throw error;
|
|
569
|
+
}
|
|
570
|
+
};
|
|
571
|
+
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
572
|
+
const existing = read();
|
|
573
|
+
if (existing?.key) {
|
|
574
|
+
brokerKeys.set(path, existing.key);
|
|
575
|
+
return existing.key;
|
|
576
|
+
}
|
|
577
|
+
if (existing)
|
|
578
|
+
throw new MachineAuthError(
|
|
579
|
+
"unsafe_storage",
|
|
580
|
+
`The machine broker key at ${path} is damaged. Delete it and retry.`,
|
|
581
|
+
true
|
|
582
|
+
);
|
|
583
|
+
const staged = `${path}.${process.pid}.${randomBytes3(6).toString("hex")}`;
|
|
584
|
+
try {
|
|
585
|
+
writeFileSync3(staged, `${randomBytes3(32).toString("hex")}
|
|
586
|
+
`, { mode: 384, flag: "wx" });
|
|
587
|
+
protectPath(staged, false);
|
|
588
|
+
linkSync(staged, path);
|
|
589
|
+
} catch (error) {
|
|
590
|
+
if (error.code !== "EEXIST") throw error;
|
|
591
|
+
} finally {
|
|
592
|
+
rmSync5(staged, { force: true });
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
const key = read()?.key;
|
|
596
|
+
if (!key)
|
|
597
|
+
throw new MachineAuthError("unsafe_storage", "The machine broker key is unreadable.", true);
|
|
598
|
+
brokerKeys.set(path, key);
|
|
599
|
+
return key;
|
|
600
|
+
}
|
|
496
601
|
function environmentCredentials(deps) {
|
|
497
602
|
const env = deps.env ?? process.env;
|
|
498
|
-
const {
|
|
499
|
-
|
|
603
|
+
const {
|
|
604
|
+
PRIM_M2M_CLIENT_ID: clientId,
|
|
605
|
+
PRIM_M2M_CLIENT_SECRET: clientSecret,
|
|
606
|
+
PRIM_M2M_CLIENT_AUTH: auth
|
|
607
|
+
} = env;
|
|
608
|
+
if (clientId === void 0 && clientSecret === void 0 && auth === void 0) return void 0;
|
|
609
|
+
if (auth !== void 0 && auth !== NETWORK_SECRET_AUTH && auth !== NETWORK_TOKEN_AUTH)
|
|
610
|
+
throw new MachineAuthError(
|
|
611
|
+
"incomplete_machine_credentials",
|
|
612
|
+
`PRIM_M2M_CLIENT_AUTH accepts ${NETWORK_SECRET_AUTH} or ${NETWORK_TOKEN_AUTH}.`
|
|
613
|
+
);
|
|
614
|
+
if (auth !== void 0) {
|
|
615
|
+
if (!clientId || !/^client_[\w-]+$/u.test(clientId))
|
|
616
|
+
throw new MachineAuthError(
|
|
617
|
+
"incomplete_machine_credentials",
|
|
618
|
+
`Set PRIM_M2M_CLIENT_ID with PRIM_M2M_CLIENT_AUTH=${auth}.`
|
|
619
|
+
);
|
|
620
|
+
if (clientSecret !== void 0)
|
|
621
|
+
throw new MachineAuthError(
|
|
622
|
+
"conflicting_credentials",
|
|
623
|
+
`Unset PRIM_M2M_CLIENT_SECRET: with PRIM_M2M_CLIENT_AUTH=${auth} the environment's network secret supplies it.`
|
|
624
|
+
);
|
|
625
|
+
const generation = hash(`${apiUrlFor(deps)}\0${clientId}\0${auth}\0broker-proxy`);
|
|
626
|
+
const credentials = {
|
|
627
|
+
clientId,
|
|
628
|
+
generation,
|
|
629
|
+
...auth === NETWORK_TOKEN_AUTH ? { tokenInjection: "network" } : { secretInjection: "network" }
|
|
630
|
+
};
|
|
631
|
+
Object.defineProperty(credentials, "clientSecret", {
|
|
632
|
+
enumerable: true,
|
|
633
|
+
get: () => networkSecretBrokerKey(deps, clientId)
|
|
634
|
+
});
|
|
635
|
+
return credentials;
|
|
636
|
+
}
|
|
500
637
|
if (!clientId || !clientSecret || !/^client_[\w-]+$/u.test(clientId) || !machineString(clientSecret)) {
|
|
501
638
|
throw new MachineAuthError(
|
|
502
639
|
"incomplete_machine_credentials",
|
|
@@ -511,7 +648,7 @@ function environmentCredentials(deps) {
|
|
|
511
648
|
}
|
|
512
649
|
function hasMachineConfiguration(deps = {}) {
|
|
513
650
|
const env = deps.env ?? process.env;
|
|
514
|
-
const configured = env.PRIM_M2M_CLIENT_ID !== void 0 || env.PRIM_M2M_CLIENT_SECRET !== void 0 || existsSync3(join6(configurationDirectory(deps), PROFILE_FILE));
|
|
651
|
+
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));
|
|
515
652
|
if (configured && env.PRIM_TOKEN?.trim()) {
|
|
516
653
|
throw new MachineAuthError(
|
|
517
654
|
"conflicting_credentials",
|
|
@@ -560,6 +697,12 @@ function machineCaptureActor(deps = {}) {
|
|
|
560
697
|
function machineJournalBucket(identity) {
|
|
561
698
|
return `_machine_${hash(`${identity.apiUrl}\0${identity.clientId}${identity.authorizedUserId ? `\0${identity.authorizedUserId}` : ""}`)}`;
|
|
562
699
|
}
|
|
700
|
+
function identityPending(actor) {
|
|
701
|
+
return actor.machineId === void 0 && actor.organizationId === void 0 && actor.authorizedUserId === void 0;
|
|
702
|
+
}
|
|
703
|
+
function machinePendingBucket(identity) {
|
|
704
|
+
return `_machine_pending_${hash(`${identity.apiUrl}\0${identity.clientId}`)}`;
|
|
705
|
+
}
|
|
563
706
|
|
|
564
707
|
// src/lib/credentials.ts
|
|
565
708
|
var CONFIG_DIRECTORY = primConfigDirectory();
|
|
@@ -585,7 +728,7 @@ function readTrimmed(path) {
|
|
|
585
728
|
function resolveAuthCredential(options = {}) {
|
|
586
729
|
if (!options.tokenFilePath && hasMachineConfiguration({ env: options.env })) {
|
|
587
730
|
const machine = cachedMachineCredential({ env: options.env });
|
|
588
|
-
return machine ? { token: machine.accessToken, source: "machine" } : void 0;
|
|
731
|
+
return machine?.accessToken ? { token: machine.accessToken, source: "machine" } : void 0;
|
|
589
732
|
}
|
|
590
733
|
const envToken = (options.env ?? process.env).PRIM_TOKEN?.trim();
|
|
591
734
|
if (envToken) return { token: envToken, source: "environment" };
|
|
@@ -775,7 +918,7 @@ import {
|
|
|
775
918
|
opendirSync,
|
|
776
919
|
readFileSync as readFileSync11,
|
|
777
920
|
readSync,
|
|
778
|
-
readdirSync as
|
|
921
|
+
readdirSync as readdirSync3
|
|
779
922
|
} from "fs";
|
|
780
923
|
import { dirname as dirname8, join as join12 } from "path";
|
|
781
924
|
|
|
@@ -785,7 +928,7 @@ import { chmodSync as chmodSync3, existsSync as existsSync5, mkdirSync as mkdirS
|
|
|
785
928
|
import { dirname as dirname6 } from "path";
|
|
786
929
|
|
|
787
930
|
// src/daemon/client-instance-id.ts
|
|
788
|
-
import { randomBytes as
|
|
931
|
+
import { randomBytes as randomBytes4 } from "crypto";
|
|
789
932
|
import { chmodSync as chmodSync2, lstatSync as lstatSync4, readFileSync as readFileSync8 } from "fs";
|
|
790
933
|
import { join as join9 } from "path";
|
|
791
934
|
var INSTANCE_BODY_CHARS = 43;
|
|
@@ -810,7 +953,7 @@ import {
|
|
|
810
953
|
chmodSync as chmodSync4,
|
|
811
954
|
existsSync as existsSync6,
|
|
812
955
|
readFileSync as readFileSync10,
|
|
813
|
-
readdirSync,
|
|
956
|
+
readdirSync as readdirSync2,
|
|
814
957
|
rmSync as rmSync7,
|
|
815
958
|
rmdirSync
|
|
816
959
|
} from "fs";
|
|
@@ -853,16 +996,33 @@ function journalPath(orgId) {
|
|
|
853
996
|
function appendMove(move, orgId) {
|
|
854
997
|
const actor = machineCaptureActor();
|
|
855
998
|
const captured = actor ? { ...move, captureActor: actor } : move;
|
|
856
|
-
|
|
999
|
+
const bucket = actor ? identityPending(actor) ? machinePendingBucket(actor) : machineJournalBucket(actor) : orgId;
|
|
1000
|
+
appendMoveToPath(journalPath(bucket), captured);
|
|
857
1001
|
return captured;
|
|
858
1002
|
}
|
|
859
1003
|
var FLUSHING_PREFIX = `${JOURNAL_BASENAME}.flushing.`;
|
|
860
1004
|
|
|
861
1005
|
// src/lib/activation.ts
|
|
862
1006
|
import { execFileSync as execFileSync4 } from "child_process";
|
|
863
|
-
import { existsSync as
|
|
1007
|
+
import { existsSync as existsSync9, readFileSync as readFileSync14 } from "fs";
|
|
864
1008
|
import { homedir as homedir2 } from "os";
|
|
1009
|
+
import { join as join15 } from "path";
|
|
1010
|
+
|
|
1011
|
+
// src/lib/cloud-prepared.ts
|
|
1012
|
+
import { existsSync as existsSync8, mkdirSync as mkdirSync6, readFileSync as readFileSync12, rmSync as rmSync8, writeFileSync as writeFileSync4 } from "fs";
|
|
865
1013
|
import { join as join13 } from "path";
|
|
1014
|
+
var CLOUD_PREPARED_MARKER = "cloud-prepared";
|
|
1015
|
+
function cloudPreparedPath(env = process.env) {
|
|
1016
|
+
return join13(primConfigDirectory({ env }), CLOUD_PREPARED_MARKER);
|
|
1017
|
+
}
|
|
1018
|
+
function isPreparedCloudSession(env = process.env) {
|
|
1019
|
+
if (!isClaudeCloudSession(env)) return false;
|
|
1020
|
+
try {
|
|
1021
|
+
return existsSync8(cloudPreparedPath(env));
|
|
1022
|
+
} catch {
|
|
1023
|
+
return false;
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
866
1026
|
|
|
867
1027
|
// src/lib/demo-pause.ts
|
|
868
1028
|
import { execFileSync as execFileSync2 } from "child_process";
|
|
@@ -928,11 +1088,12 @@ function healDemoPause(cwd, pause, options = {}) {
|
|
|
928
1088
|
// src/lib/git.ts
|
|
929
1089
|
import { execFileSync as execFileSync3 } from "child_process";
|
|
930
1090
|
import { createHash as createHash6 } from "crypto";
|
|
931
|
-
import { lstatSync as lstatSync5, realpathSync } from "fs";
|
|
932
|
-
import { basename as basename3, dirname as dirname9, isAbsolute as isAbsolute3, relative, resolve as resolve2, sep } from "path";
|
|
1091
|
+
import { lstatSync as lstatSync5, readFileSync as readFileSync13, realpathSync } from "fs";
|
|
1092
|
+
import { basename as basename3, dirname as dirname9, isAbsolute as isAbsolute3, join as join14, relative, resolve as resolve2, sep } from "path";
|
|
933
1093
|
var GIT_TIMEOUT_MS2 = 1e3;
|
|
1094
|
+
var MAX_SETTINGS_BYTES = 1024 * 1024;
|
|
934
1095
|
var GITHUB_OWNER_PATTERN = /^(?![A-Za-z0-9-]*--)[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/u;
|
|
935
|
-
var GITHUB_REPOSITORY_PATTERN = /^[A-Za-z0-9._-]{1,100}$/u;
|
|
1096
|
+
var GITHUB_REPOSITORY_PATTERN = /^(?!\.{1,2}$)[A-Za-z0-9._-]{1,100}$/u;
|
|
936
1097
|
function gitToplevel(cwd) {
|
|
937
1098
|
try {
|
|
938
1099
|
return execFileSync3("git", ["rev-parse", "--show-toplevel"], {
|
|
@@ -958,19 +1119,57 @@ function gitValue(cwd, args) {
|
|
|
958
1119
|
return void 0;
|
|
959
1120
|
}
|
|
960
1121
|
}
|
|
961
|
-
function
|
|
962
|
-
const
|
|
963
|
-
if (
|
|
1122
|
+
function parseGithubRepositoryName(path) {
|
|
1123
|
+
const parts = path.replace(/^\/+|\/+$/g, "").replace(/\.git$/i, "").split("/");
|
|
1124
|
+
if (parts.length !== 2 || !GITHUB_OWNER_PATTERN.test(parts[0] ?? "") || !GITHUB_REPOSITORY_PATTERN.test(parts[1] ?? "")) {
|
|
1125
|
+
return null;
|
|
1126
|
+
}
|
|
1127
|
+
return `${parts[0]}/${parts[1]}`;
|
|
1128
|
+
}
|
|
1129
|
+
function githubRepositoryFromRemote(remote) {
|
|
1130
|
+
if ([...remote].some((char) => char < " " || char === "\x7F")) return null;
|
|
964
1131
|
const match = /^(?:git@github\.com:([^?#]+)|(?:https|ssh):\/\/(?:[^/@]+@)?github\.com(?::\d+)?\/([^?#]+))$/i.exec(
|
|
965
1132
|
remote
|
|
966
1133
|
);
|
|
967
1134
|
const path = match?.[1] ?? match?.[2];
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
1135
|
+
return path ? parseGithubRepositoryName(path) : null;
|
|
1136
|
+
}
|
|
1137
|
+
function checkoutSettingsText(repoRoot) {
|
|
1138
|
+
const path = join14(repoRoot, ".claude", "settings.json");
|
|
1139
|
+
try {
|
|
1140
|
+
if (!lstatSync5(join14(repoRoot, ".claude")).isDirectory()) return null;
|
|
1141
|
+
const stat = lstatSync5(path);
|
|
1142
|
+
if (!stat.isFile() || stat.size > MAX_SETTINGS_BYTES) return null;
|
|
1143
|
+
return readFileSync13(path, "utf8");
|
|
1144
|
+
} catch {
|
|
971
1145
|
return null;
|
|
972
1146
|
}
|
|
973
|
-
|
|
1147
|
+
}
|
|
1148
|
+
function checkoutDeclaration(repoRoot, name) {
|
|
1149
|
+
const text = checkoutSettingsText(repoRoot);
|
|
1150
|
+
if (text === null) return null;
|
|
1151
|
+
let parsed;
|
|
1152
|
+
try {
|
|
1153
|
+
parsed = JSON.parse(text);
|
|
1154
|
+
} catch {
|
|
1155
|
+
return null;
|
|
1156
|
+
}
|
|
1157
|
+
const env = typeof parsed === "object" && parsed !== null ? parsed.env : void 0;
|
|
1158
|
+
const value = typeof env === "object" && env !== null ? env[name] : void 0;
|
|
1159
|
+
return typeof value === "string" ? value : null;
|
|
1160
|
+
}
|
|
1161
|
+
function declaredGithubRepository(repoRoot) {
|
|
1162
|
+
const value = checkoutDeclaration(repoRoot, "PRIM_REPOSITORY");
|
|
1163
|
+
return value === null ? null : parseGithubRepositoryName(value.trim());
|
|
1164
|
+
}
|
|
1165
|
+
function githubRepositoryFullName(cwd) {
|
|
1166
|
+
const remote = gitValue(cwd, ["config", "--get", "remote.origin.url"]);
|
|
1167
|
+
if (remote) {
|
|
1168
|
+
const fromOrigin = githubRepositoryFromRemote(remote);
|
|
1169
|
+
if (fromOrigin || normalizeOriginRemote(remote)) return fromOrigin;
|
|
1170
|
+
}
|
|
1171
|
+
const root = gitToplevel(cwd);
|
|
1172
|
+
return root ? declaredGithubRepository(root) : null;
|
|
974
1173
|
}
|
|
975
1174
|
function normalizeOriginRemote(remote) {
|
|
976
1175
|
const value = remote.trim();
|
|
@@ -1016,6 +1215,14 @@ function resolveRepositoryContext(cwd = process.cwd()) {
|
|
|
1016
1215
|
repoFullName
|
|
1017
1216
|
};
|
|
1018
1217
|
}
|
|
1218
|
+
if (repoFullName) {
|
|
1219
|
+
return {
|
|
1220
|
+
repoRoot,
|
|
1221
|
+
repoKey: opaqueRepoKey("origin", `github.com/${repoFullName}`),
|
|
1222
|
+
identitySource: "declared",
|
|
1223
|
+
repoFullName
|
|
1224
|
+
};
|
|
1225
|
+
}
|
|
1019
1226
|
const roots = gitValue(repoRoot, ["rev-list", "--max-parents=0", "HEAD"])?.split(/\s+/).filter(Boolean).sort();
|
|
1020
1227
|
if (roots && roots.length > 0) {
|
|
1021
1228
|
return {
|
|
@@ -1030,6 +1237,7 @@ function resolveRepositoryContext(cwd = process.cwd()) {
|
|
|
1030
1237
|
|
|
1031
1238
|
// src/lib/activation.ts
|
|
1032
1239
|
var PRIM_ACTIVE_KEY = "prim.active";
|
|
1240
|
+
var PRIM_ACTIVE_DECLARATION = "PRIM_ACTIVE";
|
|
1033
1241
|
var PRIM_REPO_SYNC_ID_KEY = "prim.repoSyncId";
|
|
1034
1242
|
var PRIM_REPO_SYNC_REPOSITORY_KEY = "prim.repoSyncRepository";
|
|
1035
1243
|
var GIT_TIMEOUT_MS3 = 1e3;
|
|
@@ -1076,14 +1284,13 @@ function repoSyncId(cwd) {
|
|
|
1076
1284
|
const repositoryFullName = localGitConfigValue(cwd, PRIM_REPO_SYNC_REPOSITORY_KEY);
|
|
1077
1285
|
return repositoryFullName === githubRepositoryFullName(cwd) ? value : void 0;
|
|
1078
1286
|
}
|
|
1079
|
-
function
|
|
1080
|
-
const root = gitToplevel(cwd);
|
|
1287
|
+
function projectPrimInstallAt(root) {
|
|
1081
1288
|
if (root === null || root === homedir2()) return false;
|
|
1082
1289
|
for (const rel of PROJECT_INSTALL_FILES) {
|
|
1083
|
-
const path =
|
|
1084
|
-
if (
|
|
1290
|
+
const path = join15(root, rel);
|
|
1291
|
+
if (existsSync9(path)) {
|
|
1085
1292
|
try {
|
|
1086
|
-
const content =
|
|
1293
|
+
const content = readFileSync14(path, "utf-8");
|
|
1087
1294
|
if (PRIM_HOOK_BINS.some((bin) => content.includes(bin))) return true;
|
|
1088
1295
|
} catch {
|
|
1089
1296
|
}
|
|
@@ -1091,12 +1298,27 @@ function hasProjectPrimInstall(cwd) {
|
|
|
1091
1298
|
}
|
|
1092
1299
|
return false;
|
|
1093
1300
|
}
|
|
1301
|
+
var UNPARSED_OPT_OUT = /"PRIM_ACTIVE"\s*:\s*"\s*false\s*"/u;
|
|
1302
|
+
function declaresInactiveAt(root) {
|
|
1303
|
+
if (root === null || root === homedir2()) return false;
|
|
1304
|
+
if (checkoutDeclaration(root, PRIM_ACTIVE_DECLARATION)?.trim() === "false") return true;
|
|
1305
|
+
const text = checkoutSettingsText(root);
|
|
1306
|
+
if (text === null || !UNPARSED_OPT_OUT.test(text)) return false;
|
|
1307
|
+
try {
|
|
1308
|
+
JSON.parse(text);
|
|
1309
|
+
return false;
|
|
1310
|
+
} catch {
|
|
1311
|
+
return true;
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1094
1314
|
function isRepoActiveForCapture(cwd, options = {}) {
|
|
1095
1315
|
let { active: flag, pause } = readCaptureConfig(cwd);
|
|
1096
1316
|
if (pause && healDemoPause(cwd, pause, options)) flag = repoActiveFlag(cwd);
|
|
1097
1317
|
if (flag === "true") return true;
|
|
1098
1318
|
if (flag === "false") return false;
|
|
1099
|
-
|
|
1319
|
+
const root = gitToplevel(cwd);
|
|
1320
|
+
if (declaresInactiveAt(root)) return false;
|
|
1321
|
+
return projectPrimInstallAt(root) || isPreparedCloudSession() && root !== null;
|
|
1100
1322
|
}
|
|
1101
1323
|
|
|
1102
1324
|
// src/generated/cli-http-v1.validators.js
|
|
@@ -28069,8 +28291,8 @@ function cachedCollectScopeAdmits(cwd, facts) {
|
|
|
28069
28291
|
|
|
28070
28292
|
// src/lib/commit-heartbeat.ts
|
|
28071
28293
|
import { execFileSync as execFileSync5 } from "child_process";
|
|
28072
|
-
import { mkdirSync as
|
|
28073
|
-
import { dirname as dirname10, join as
|
|
28294
|
+
import { mkdirSync as mkdirSync7, readFileSync as readFileSync15, readdirSync as readdirSync4, unlinkSync } from "fs";
|
|
28295
|
+
import { dirname as dirname10, join as join16, resolve as resolve3 } from "path";
|
|
28074
28296
|
var FIRED_DIR = "prim/post-commit-fired";
|
|
28075
28297
|
var GIT_TIMEOUT_MS4 = 1e3;
|
|
28076
28298
|
var MAX_STAMP_BYTES = 1024;
|
|
@@ -28088,8 +28310,8 @@ function gitPath(cwd, relative2) {
|
|
|
28088
28310
|
return resolve3(cwd, value);
|
|
28089
28311
|
}
|
|
28090
28312
|
function ensurePrivateParent(path) {
|
|
28091
|
-
|
|
28092
|
-
|
|
28313
|
+
mkdirSync7(dirname10(dirname10(path)), { recursive: true, mode: 448 });
|
|
28314
|
+
mkdirSync7(dirname10(path), { recursive: true, mode: 448 });
|
|
28093
28315
|
}
|
|
28094
28316
|
function writeStamp(path, at) {
|
|
28095
28317
|
ensurePrivateParent(path);
|
|
@@ -28098,7 +28320,7 @@ function writeStamp(path, at) {
|
|
|
28098
28320
|
}
|
|
28099
28321
|
function readStampAt(path) {
|
|
28100
28322
|
try {
|
|
28101
|
-
const raw =
|
|
28323
|
+
const raw = readFileSync15(path, "utf8");
|
|
28102
28324
|
if (raw.length > MAX_STAMP_BYTES) return void 0;
|
|
28103
28325
|
const parsed = JSON.parse(raw);
|
|
28104
28326
|
return typeof parsed.at === "number" && Number.isSafeInteger(parsed.at) && parsed.at > 0 ? parsed.at : void 0;
|
|
@@ -28110,11 +28332,11 @@ function recordPostCommitFired(cwd, sha, now = Date.now()) {
|
|
|
28110
28332
|
if (!sha || !FULL_SHA_RE.test(sha)) return;
|
|
28111
28333
|
try {
|
|
28112
28334
|
const dir = gitPath(cwd, FIRED_DIR);
|
|
28113
|
-
writeStamp(
|
|
28114
|
-
const names =
|
|
28335
|
+
writeStamp(join16(dir, sha), now);
|
|
28336
|
+
const names = readdirSync4(dir).filter((name) => FULL_SHA_RE.test(name));
|
|
28115
28337
|
if (names.length <= MAX_FIRED_STAMPS + PRUNE_SLACK) return;
|
|
28116
|
-
const stale = names.map((name) => ({ name, at: readStampAt(
|
|
28117
|
-
for (const { name } of stale) unlinkSync(
|
|
28338
|
+
const stale = names.map((name) => ({ name, at: readStampAt(join16(dir, name)) ?? 0 })).sort((left, right) => right.at - left.at || left.name.localeCompare(right.name)).slice(MAX_FIRED_STAMPS);
|
|
28339
|
+
for (const { name } of stale) unlinkSync(join16(dir, name));
|
|
28118
28340
|
} catch {
|
|
28119
28341
|
}
|
|
28120
28342
|
}
|
|
@@ -28134,17 +28356,17 @@ import {
|
|
|
28134
28356
|
closeSync as closeSync3,
|
|
28135
28357
|
fchmodSync as fchmodSync2,
|
|
28136
28358
|
fsyncSync as fsyncSync2,
|
|
28137
|
-
linkSync,
|
|
28359
|
+
linkSync as linkSync2,
|
|
28138
28360
|
lstatSync as lstatSync6,
|
|
28139
|
-
mkdirSync as
|
|
28361
|
+
mkdirSync as mkdirSync8,
|
|
28140
28362
|
openSync as openSync3,
|
|
28141
|
-
readFileSync as
|
|
28363
|
+
readFileSync as readFileSync16,
|
|
28142
28364
|
statSync as statSync2,
|
|
28143
28365
|
unlinkSync as unlinkSync2,
|
|
28144
|
-
writeFileSync as
|
|
28366
|
+
writeFileSync as writeFileSync5
|
|
28145
28367
|
} from "fs";
|
|
28146
|
-
import { dirname as dirname11, isAbsolute as isAbsolute4, join as
|
|
28147
|
-
var WORKSPACE_ID_RELATIVE_PATH =
|
|
28368
|
+
import { dirname as dirname11, isAbsolute as isAbsolute4, join as join17, resolve as resolve4 } from "path";
|
|
28369
|
+
var WORKSPACE_ID_RELATIVE_PATH = join17("prim", "workspace-id");
|
|
28148
28370
|
var MAX_ANCESTORS = 64;
|
|
28149
28371
|
var MAX_GIT_FILE_BYTES = 4096;
|
|
28150
28372
|
var MAX_ID_FILE_BYTES = 128;
|
|
@@ -28203,19 +28425,19 @@ function resolveWorkspaceIdPath(cwd) {
|
|
|
28203
28425
|
function resolveFromFilesystem(cwd) {
|
|
28204
28426
|
let current = resolve4(cwd);
|
|
28205
28427
|
for (let depth = 0; depth < MAX_ANCESTORS; depth += 1) {
|
|
28206
|
-
const dotGit =
|
|
28428
|
+
const dotGit = join17(current, ".git");
|
|
28207
28429
|
try {
|
|
28208
28430
|
const stat = lstatSync6(dotGit);
|
|
28209
28431
|
if (stat.isDirectory() && isGitDirectory(dotGit)) {
|
|
28210
|
-
return
|
|
28432
|
+
return join17(dotGit, WORKSPACE_ID_RELATIVE_PATH);
|
|
28211
28433
|
}
|
|
28212
28434
|
if (stat.isFile() && stat.size <= MAX_GIT_FILE_BYTES) {
|
|
28213
|
-
const contents =
|
|
28435
|
+
const contents = readFileSync16(dotGit, "utf8");
|
|
28214
28436
|
const match = /^gitdir: (.+?)(?:\r?\n)?$/.exec(contents);
|
|
28215
28437
|
if (match?.[1]) {
|
|
28216
28438
|
const gitDirectory = isAbsolute4(match[1]) ? resolve4(match[1]) : resolve4(current, match[1]);
|
|
28217
28439
|
if (isGitDirectory(gitDirectory)) {
|
|
28218
|
-
return
|
|
28440
|
+
return join17(gitDirectory, WORKSPACE_ID_RELATIVE_PATH);
|
|
28219
28441
|
}
|
|
28220
28442
|
}
|
|
28221
28443
|
}
|
|
@@ -28234,7 +28456,7 @@ function resolveFromFilesystem(cwd) {
|
|
|
28234
28456
|
}
|
|
28235
28457
|
function isGitDirectory(path) {
|
|
28236
28458
|
try {
|
|
28237
|
-
return statSync2(
|
|
28459
|
+
return statSync2(join17(path, "HEAD")).isFile();
|
|
28238
28460
|
} catch {
|
|
28239
28461
|
return false;
|
|
28240
28462
|
}
|
|
@@ -28253,7 +28475,7 @@ function inspectPath(path) {
|
|
|
28253
28475
|
return { status: "corrupt", path, reason: "invalid_content" };
|
|
28254
28476
|
}
|
|
28255
28477
|
try {
|
|
28256
|
-
const contents =
|
|
28478
|
+
const contents = readFileSync16(path, "utf8");
|
|
28257
28479
|
const workspaceId = contents.endsWith("\n") ? contents.slice(0, -1) : contents;
|
|
28258
28480
|
if ((contents === workspaceId || contents === `${workspaceId}
|
|
28259
28481
|
`) && isCanonicalWorkspaceId(workspaceId)) {
|
|
@@ -28272,11 +28494,11 @@ function inspectPath(path) {
|
|
|
28272
28494
|
function createWorkspaceId(path) {
|
|
28273
28495
|
const parent = dirname11(path);
|
|
28274
28496
|
const workspaceId = randomUUID3();
|
|
28275
|
-
const temporaryPath =
|
|
28497
|
+
const temporaryPath = join17(parent, `.workspace-id-${process.pid}-${randomUUID3()}.tmp`);
|
|
28276
28498
|
let temporaryCreated = false;
|
|
28277
28499
|
let publishing = false;
|
|
28278
28500
|
try {
|
|
28279
|
-
|
|
28501
|
+
mkdirSync8(parent, { recursive: true, mode: 448 });
|
|
28280
28502
|
chmodSync5(parent, 448);
|
|
28281
28503
|
const fd = openSync3(
|
|
28282
28504
|
temporaryPath,
|
|
@@ -28285,7 +28507,7 @@ function createWorkspaceId(path) {
|
|
|
28285
28507
|
);
|
|
28286
28508
|
temporaryCreated = true;
|
|
28287
28509
|
try {
|
|
28288
|
-
|
|
28510
|
+
writeFileSync5(fd, `${workspaceId}
|
|
28289
28511
|
`, "utf8");
|
|
28290
28512
|
fchmodSync2(fd, 384);
|
|
28291
28513
|
fsyncSync2(fd);
|
|
@@ -28293,7 +28515,7 @@ function createWorkspaceId(path) {
|
|
|
28293
28515
|
closeSync3(fd);
|
|
28294
28516
|
}
|
|
28295
28517
|
publishing = true;
|
|
28296
|
-
|
|
28518
|
+
linkSync2(temporaryPath, path);
|
|
28297
28519
|
return { status: "ready", workspaceId, path, created: true };
|
|
28298
28520
|
} catch (error) {
|
|
28299
28521
|
if (publishing && errorCode(error) === "EEXIST") return inspectAfterRace(path);
|
|
@@ -28341,8 +28563,8 @@ var AGENT_ENVELOPE_VERSION = 3;
|
|
|
28341
28563
|
var ENVELOPE_VERSION = LEGACY_ENVELOPE_VERSION;
|
|
28342
28564
|
|
|
28343
28565
|
// src/hooks/redact.ts
|
|
28344
|
-
import { existsSync as
|
|
28345
|
-
import { join as
|
|
28566
|
+
import { existsSync as existsSync10, readFileSync as readFileSync17, statSync as statSync3 } from "fs";
|
|
28567
|
+
import { join as join18 } from "path";
|
|
28346
28568
|
import { Worker } from "worker_threads";
|
|
28347
28569
|
var USER_HOME_RULES = [
|
|
28348
28570
|
{
|
|
@@ -28386,6 +28608,11 @@ var DEFAULT_RULES = [
|
|
|
28386
28608
|
pattern: /\bAWS_(?:SECRET_ACCESS_KEY|SESSION_TOKEN)"?\s*[:=]\s*["']?[A-Za-z0-9/+=]{20,}["']?/gi,
|
|
28387
28609
|
reason: "aws-secret"
|
|
28388
28610
|
},
|
|
28611
|
+
{
|
|
28612
|
+
// `prim auth enroll --print-env` output an agent may write into a file.
|
|
28613
|
+
pattern: /\bPRIM_M2M_CLIENT_SECRET"?\s*[:=]\s*["']?[^\s"']+["']?/g,
|
|
28614
|
+
reason: "prim-m2m-secret"
|
|
28615
|
+
},
|
|
28389
28616
|
{ pattern: /\bAIza[0-9A-Za-z_-]{35}(?![0-9A-Za-z_-])/g, reason: "gcp-api-key" },
|
|
28390
28617
|
{
|
|
28391
28618
|
pattern: /\bya29\.[0-9A-Za-z_-]{20,}(?![0-9A-Za-z_-])/g,
|
|
@@ -28612,14 +28839,14 @@ function readCommit() {
|
|
|
28612
28839
|
}
|
|
28613
28840
|
function resolveCliVersion() {
|
|
28614
28841
|
try {
|
|
28615
|
-
const pkg = JSON.parse(
|
|
28842
|
+
const pkg = JSON.parse(readFileSync18(join19(here, "..", "..", "package.json"), "utf-8"));
|
|
28616
28843
|
return pkg.version ?? "unknown";
|
|
28617
28844
|
} catch {
|
|
28618
28845
|
return "unknown";
|
|
28619
28846
|
}
|
|
28620
28847
|
}
|
|
28621
28848
|
function spawnBackgroundFlush() {
|
|
28622
|
-
const entry =
|
|
28849
|
+
const entry = join19(here, "..", "index.js");
|
|
28623
28850
|
spawn2(process.execPath, [entry, "moves", "flush"], {
|
|
28624
28851
|
detached: true,
|
|
28625
28852
|
stdio: "ignore",
|