@primitive.ai/prim 0.1.0-alpha.125 → 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-2BEUR3DU.js → chunk-A5VTE43F.js} +2 -2
- package/dist/{chunk-6OPSSJHO.js → chunk-C4QNBSWB.js} +24 -9
- 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-HPA7RGSZ.js → chunk-MGKSZSTV.js} +7 -8
- 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-R35M4RCY.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 +616 -165
- 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
|
@@ -60,10 +60,10 @@ import {
|
|
|
60
60
|
fstatSync as fstatSync2,
|
|
61
61
|
lstatSync as lstatSync7,
|
|
62
62
|
openSync as openSync4,
|
|
63
|
-
readFileSync as
|
|
63
|
+
readFileSync as readFileSync17,
|
|
64
64
|
unlinkSync as unlinkSync2
|
|
65
65
|
} from "fs";
|
|
66
|
-
import { basename as basename4, dirname as dirname11, isAbsolute as isAbsolute5, join as
|
|
66
|
+
import { basename as basename4, dirname as dirname11, isAbsolute as isAbsolute5, join as join18 } from "path";
|
|
67
67
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
68
68
|
|
|
69
69
|
// src/binding.ts
|
|
@@ -77,8 +77,17 @@ import { join as join7 } from "path";
|
|
|
77
77
|
|
|
78
78
|
// src/lib/machine-credentials.ts
|
|
79
79
|
import { execFileSync } from "child_process";
|
|
80
|
-
import { createHash as createHash3, randomUUID as randomUUID2 } from "crypto";
|
|
81
|
-
import {
|
|
80
|
+
import { createHash as createHash3, randomBytes as randomBytes3, randomUUID as randomUUID2 } from "crypto";
|
|
81
|
+
import {
|
|
82
|
+
chmodSync,
|
|
83
|
+
existsSync as existsSync3,
|
|
84
|
+
linkSync,
|
|
85
|
+
lstatSync as lstatSync3,
|
|
86
|
+
mkdirSync as mkdirSync3,
|
|
87
|
+
readFileSync as readFileSync5,
|
|
88
|
+
rmSync as rmSync5,
|
|
89
|
+
writeFileSync as writeFileSync3
|
|
90
|
+
} from "fs";
|
|
82
91
|
import { createRequire } from "module";
|
|
83
92
|
import { dirname as dirname4, join as join6 } from "path";
|
|
84
93
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
@@ -156,6 +165,15 @@ var PRIM_CONFIG_SHELL_RESOLVER = [
|
|
|
156
165
|
"fi; fi; "
|
|
157
166
|
].join("");
|
|
158
167
|
|
|
168
|
+
// src/lib/loopback-fetch.ts
|
|
169
|
+
import { request } from "http";
|
|
170
|
+
import { Readable } from "stream";
|
|
171
|
+
|
|
172
|
+
// src/lib/cloud-env.ts
|
|
173
|
+
function isClaudeCloudSession(env = process.env) {
|
|
174
|
+
return env.CLAUDE_CODE_REMOTE === "true";
|
|
175
|
+
}
|
|
176
|
+
|
|
159
177
|
// src/lib/workos-connect.ts
|
|
160
178
|
var DISCOVERY_MAX_BYTES = 16 * 1024;
|
|
161
179
|
var WORKOS_CONNECT_RESPONSE_MAX_BYTES = 64 * 1024;
|
|
@@ -331,12 +349,16 @@ function primConfigDirectory(options = {}) {
|
|
|
331
349
|
|
|
332
350
|
// src/lib/machine-broker.ts
|
|
333
351
|
var MAX_RESPONSE_BYTES = 96 * 1024;
|
|
352
|
+
var MAX_FORWARD_REQUEST_BYTES = 12 * 1024 * 1024;
|
|
353
|
+
var MAX_API_RESPONSE_BYTES = 8 * 1024 * 1024;
|
|
354
|
+
var MAX_FORWARD_RESPONSE_BYTES = 36 * 1024 * 1024;
|
|
334
355
|
var IDLE_MS = 5 * 6e4;
|
|
335
356
|
|
|
336
357
|
// src/lib/machine-retry.ts
|
|
337
358
|
import { createHash as createHash2 } from "crypto";
|
|
338
|
-
import { lstatSync as lstatSync2, readFileSync as readFileSync4, rmSync as rmSync4 } from "fs";
|
|
359
|
+
import { lstatSync as lstatSync2, readFileSync as readFileSync4, readdirSync, rmSync as rmSync4 } from "fs";
|
|
339
360
|
import { join as join5 } from "path";
|
|
361
|
+
var MAX_SERVER_WAIT_MS = 15 * 6e4;
|
|
340
362
|
|
|
341
363
|
// src/lib/machine-credentials.ts
|
|
342
364
|
var require2 = createRequire(import.meta.url);
|
|
@@ -379,6 +401,33 @@ function readEnvironmentContext(environment, deps) {
|
|
|
379
401
|
return void 0;
|
|
380
402
|
}
|
|
381
403
|
}
|
|
404
|
+
function protectPath(path, directory) {
|
|
405
|
+
if (process.platform !== "win32") {
|
|
406
|
+
chmodSync(path, directory ? 448 : 384);
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
const encodedPath = Buffer.from(path).toString("base64");
|
|
410
|
+
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)`;
|
|
411
|
+
execFileSync(
|
|
412
|
+
"powershell.exe",
|
|
413
|
+
[
|
|
414
|
+
"-NoProfile",
|
|
415
|
+
"-NonInteractive",
|
|
416
|
+
"-EncodedCommand",
|
|
417
|
+
Buffer.from(script, "utf16le").toString("base64")
|
|
418
|
+
],
|
|
419
|
+
{ stdio: "pipe", encoding: "utf8", windowsHide: true }
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
function ensureDirectory(directory) {
|
|
423
|
+
mkdirSync3(directory, { recursive: true, mode: 448 });
|
|
424
|
+
if (lstatSync3(directory).isSymbolicLink())
|
|
425
|
+
throw new MachineAuthError(
|
|
426
|
+
"unsafe_storage",
|
|
427
|
+
"Credential directory must not be a symbolic link."
|
|
428
|
+
);
|
|
429
|
+
protectPath(directory, true);
|
|
430
|
+
}
|
|
382
431
|
function readPrivate(path) {
|
|
383
432
|
let raw;
|
|
384
433
|
try {
|
|
@@ -437,10 +486,98 @@ function readMachineProfile(deps = {}) {
|
|
|
437
486
|
const value = readPrivate(join6(configurationDirectory(deps), PROFILE_FILE));
|
|
438
487
|
return value === void 0 ? void 0 : parseProfile(value);
|
|
439
488
|
}
|
|
489
|
+
var NETWORK_SECRET_AUTH = "network-secret";
|
|
490
|
+
var NETWORK_TOKEN_AUTH = "network-token";
|
|
491
|
+
var INJECTED_IDENTITY_TTL_MS = 60 * 6e4;
|
|
492
|
+
var brokerKeys = /* @__PURE__ */ new Map();
|
|
493
|
+
function networkSecretBrokerKey(deps, clientId) {
|
|
494
|
+
const directory = configurationDirectory(deps);
|
|
495
|
+
const path = join6(directory, `machine_network_${hash(`${apiUrlFor(deps)}\0${clientId}`)}.key`);
|
|
496
|
+
const known = brokerKeys.get(path);
|
|
497
|
+
if (known) return known;
|
|
498
|
+
ensureDirectory(directory);
|
|
499
|
+
const read = () => {
|
|
500
|
+
try {
|
|
501
|
+
const stat = lstatSync3(path);
|
|
502
|
+
if (!stat.isFile() || process.platform !== "win32" && ((stat.mode & 63) !== 0 || typeof process.getuid === "function" && stat.uid !== process.getuid()))
|
|
503
|
+
throw new MachineAuthError(
|
|
504
|
+
"unsafe_storage",
|
|
505
|
+
`The machine broker key at ${path} is not an owner-only file. Delete it and retry.`,
|
|
506
|
+
true
|
|
507
|
+
);
|
|
508
|
+
const value = readFileSync5(path, "utf8").trim();
|
|
509
|
+
return { key: /^[a-f0-9]{64}$/u.test(value) ? value : void 0 };
|
|
510
|
+
} catch (error) {
|
|
511
|
+
if (error.code === "ENOENT") return void 0;
|
|
512
|
+
throw error;
|
|
513
|
+
}
|
|
514
|
+
};
|
|
515
|
+
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
516
|
+
const existing = read();
|
|
517
|
+
if (existing?.key) {
|
|
518
|
+
brokerKeys.set(path, existing.key);
|
|
519
|
+
return existing.key;
|
|
520
|
+
}
|
|
521
|
+
if (existing)
|
|
522
|
+
throw new MachineAuthError(
|
|
523
|
+
"unsafe_storage",
|
|
524
|
+
`The machine broker key at ${path} is damaged. Delete it and retry.`,
|
|
525
|
+
true
|
|
526
|
+
);
|
|
527
|
+
const staged = `${path}.${process.pid}.${randomBytes3(6).toString("hex")}`;
|
|
528
|
+
try {
|
|
529
|
+
writeFileSync3(staged, `${randomBytes3(32).toString("hex")}
|
|
530
|
+
`, { mode: 384, flag: "wx" });
|
|
531
|
+
protectPath(staged, false);
|
|
532
|
+
linkSync(staged, path);
|
|
533
|
+
} catch (error) {
|
|
534
|
+
if (error.code !== "EEXIST") throw error;
|
|
535
|
+
} finally {
|
|
536
|
+
rmSync5(staged, { force: true });
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
const key = read()?.key;
|
|
540
|
+
if (!key)
|
|
541
|
+
throw new MachineAuthError("unsafe_storage", "The machine broker key is unreadable.", true);
|
|
542
|
+
brokerKeys.set(path, key);
|
|
543
|
+
return key;
|
|
544
|
+
}
|
|
440
545
|
function environmentCredentials(deps) {
|
|
441
546
|
const env = deps.env ?? process.env;
|
|
442
|
-
const {
|
|
443
|
-
|
|
547
|
+
const {
|
|
548
|
+
PRIM_M2M_CLIENT_ID: clientId,
|
|
549
|
+
PRIM_M2M_CLIENT_SECRET: clientSecret,
|
|
550
|
+
PRIM_M2M_CLIENT_AUTH: auth
|
|
551
|
+
} = env;
|
|
552
|
+
if (clientId === void 0 && clientSecret === void 0 && auth === void 0) return void 0;
|
|
553
|
+
if (auth !== void 0 && auth !== NETWORK_SECRET_AUTH && auth !== NETWORK_TOKEN_AUTH)
|
|
554
|
+
throw new MachineAuthError(
|
|
555
|
+
"incomplete_machine_credentials",
|
|
556
|
+
`PRIM_M2M_CLIENT_AUTH accepts ${NETWORK_SECRET_AUTH} or ${NETWORK_TOKEN_AUTH}.`
|
|
557
|
+
);
|
|
558
|
+
if (auth !== void 0) {
|
|
559
|
+
if (!clientId || !/^client_[\w-]+$/u.test(clientId))
|
|
560
|
+
throw new MachineAuthError(
|
|
561
|
+
"incomplete_machine_credentials",
|
|
562
|
+
`Set PRIM_M2M_CLIENT_ID with PRIM_M2M_CLIENT_AUTH=${auth}.`
|
|
563
|
+
);
|
|
564
|
+
if (clientSecret !== void 0)
|
|
565
|
+
throw new MachineAuthError(
|
|
566
|
+
"conflicting_credentials",
|
|
567
|
+
`Unset PRIM_M2M_CLIENT_SECRET: with PRIM_M2M_CLIENT_AUTH=${auth} the environment's network secret supplies it.`
|
|
568
|
+
);
|
|
569
|
+
const generation = hash(`${apiUrlFor(deps)}\0${clientId}\0${auth}\0broker-proxy`);
|
|
570
|
+
const credentials = {
|
|
571
|
+
clientId,
|
|
572
|
+
generation,
|
|
573
|
+
...auth === NETWORK_TOKEN_AUTH ? { tokenInjection: "network" } : { secretInjection: "network" }
|
|
574
|
+
};
|
|
575
|
+
Object.defineProperty(credentials, "clientSecret", {
|
|
576
|
+
enumerable: true,
|
|
577
|
+
get: () => networkSecretBrokerKey(deps, clientId)
|
|
578
|
+
});
|
|
579
|
+
return credentials;
|
|
580
|
+
}
|
|
444
581
|
if (!clientId || !clientSecret || !/^client_[\w-]+$/u.test(clientId) || !machineString(clientSecret)) {
|
|
445
582
|
throw new MachineAuthError(
|
|
446
583
|
"incomplete_machine_credentials",
|
|
@@ -455,7 +592,7 @@ function environmentCredentials(deps) {
|
|
|
455
592
|
}
|
|
456
593
|
function hasMachineConfiguration(deps = {}) {
|
|
457
594
|
const env = deps.env ?? process.env;
|
|
458
|
-
const configured = env.PRIM_M2M_CLIENT_ID !== void 0 || env.PRIM_M2M_CLIENT_SECRET !== void 0 || existsSync3(join6(configurationDirectory(deps), PROFILE_FILE));
|
|
595
|
+
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));
|
|
459
596
|
if (configured && env.PRIM_TOKEN?.trim()) {
|
|
460
597
|
throw new MachineAuthError(
|
|
461
598
|
"conflicting_credentials",
|
|
@@ -504,6 +641,12 @@ function machineCaptureActor(deps = {}) {
|
|
|
504
641
|
function machineJournalBucket(identity) {
|
|
505
642
|
return `_machine_${hash(`${identity.apiUrl}\0${identity.clientId}${identity.authorizedUserId ? `\0${identity.authorizedUserId}` : ""}`)}`;
|
|
506
643
|
}
|
|
644
|
+
function identityPending(actor) {
|
|
645
|
+
return actor.machineId === void 0 && actor.organizationId === void 0 && actor.authorizedUserId === void 0;
|
|
646
|
+
}
|
|
647
|
+
function machinePendingBucket(identity) {
|
|
648
|
+
return `_machine_pending_${hash(`${identity.apiUrl}\0${identity.clientId}`)}`;
|
|
649
|
+
}
|
|
507
650
|
|
|
508
651
|
// src/lib/credentials.ts
|
|
509
652
|
var CONFIG_DIRECTORY = primConfigDirectory();
|
|
@@ -529,7 +672,7 @@ function readTrimmed(path) {
|
|
|
529
672
|
function resolveAuthCredential(options = {}) {
|
|
530
673
|
if (!options.tokenFilePath && hasMachineConfiguration({ env: options.env })) {
|
|
531
674
|
const machine = cachedMachineCredential({ env: options.env });
|
|
532
|
-
return machine ? { token: machine.accessToken, source: "machine" } : void 0;
|
|
675
|
+
return machine?.accessToken ? { token: machine.accessToken, source: "machine" } : void 0;
|
|
533
676
|
}
|
|
534
677
|
const envToken = (options.env ?? process.env).PRIM_TOKEN?.trim();
|
|
535
678
|
if (envToken) return { token: envToken, source: "environment" };
|
|
@@ -719,7 +862,7 @@ import {
|
|
|
719
862
|
opendirSync,
|
|
720
863
|
readFileSync as readFileSync11,
|
|
721
864
|
readSync,
|
|
722
|
-
readdirSync as
|
|
865
|
+
readdirSync as readdirSync3
|
|
723
866
|
} from "fs";
|
|
724
867
|
import { dirname as dirname8, join as join12 } from "path";
|
|
725
868
|
|
|
@@ -729,7 +872,7 @@ import { chmodSync as chmodSync3, existsSync as existsSync5, mkdirSync as mkdirS
|
|
|
729
872
|
import { dirname as dirname6 } from "path";
|
|
730
873
|
|
|
731
874
|
// src/daemon/client-instance-id.ts
|
|
732
|
-
import { randomBytes as
|
|
875
|
+
import { randomBytes as randomBytes4 } from "crypto";
|
|
733
876
|
import { chmodSync as chmodSync2, lstatSync as lstatSync4, readFileSync as readFileSync8 } from "fs";
|
|
734
877
|
import { join as join9 } from "path";
|
|
735
878
|
var INSTANCE_BODY_CHARS = 43;
|
|
@@ -754,7 +897,7 @@ import {
|
|
|
754
897
|
chmodSync as chmodSync4,
|
|
755
898
|
existsSync as existsSync6,
|
|
756
899
|
readFileSync as readFileSync10,
|
|
757
|
-
readdirSync,
|
|
900
|
+
readdirSync as readdirSync2,
|
|
758
901
|
rmSync as rmSync7,
|
|
759
902
|
rmdirSync
|
|
760
903
|
} from "fs";
|
|
@@ -797,16 +940,33 @@ function journalPath(orgId) {
|
|
|
797
940
|
function appendMove(move, orgId) {
|
|
798
941
|
const actor = machineCaptureActor();
|
|
799
942
|
const captured = actor ? { ...move, captureActor: actor } : move;
|
|
800
|
-
|
|
943
|
+
const bucket = actor ? identityPending(actor) ? machinePendingBucket(actor) : machineJournalBucket(actor) : orgId;
|
|
944
|
+
appendMoveToPath(journalPath(bucket), captured);
|
|
801
945
|
return captured;
|
|
802
946
|
}
|
|
803
947
|
var FLUSHING_PREFIX = `${JOURNAL_BASENAME}.flushing.`;
|
|
804
948
|
|
|
805
949
|
// src/lib/activation.ts
|
|
806
950
|
import { execFileSync as execFileSync4 } from "child_process";
|
|
807
|
-
import { existsSync as
|
|
951
|
+
import { existsSync as existsSync9, readFileSync as readFileSync14 } from "fs";
|
|
808
952
|
import { homedir as homedir2 } from "os";
|
|
953
|
+
import { join as join15 } from "path";
|
|
954
|
+
|
|
955
|
+
// src/lib/cloud-prepared.ts
|
|
956
|
+
import { existsSync as existsSync8, mkdirSync as mkdirSync6, readFileSync as readFileSync12, rmSync as rmSync8, writeFileSync as writeFileSync4 } from "fs";
|
|
809
957
|
import { join as join13 } from "path";
|
|
958
|
+
var CLOUD_PREPARED_MARKER = "cloud-prepared";
|
|
959
|
+
function cloudPreparedPath(env = process.env) {
|
|
960
|
+
return join13(primConfigDirectory({ env }), CLOUD_PREPARED_MARKER);
|
|
961
|
+
}
|
|
962
|
+
function isPreparedCloudSession(env = process.env) {
|
|
963
|
+
if (!isClaudeCloudSession(env)) return false;
|
|
964
|
+
try {
|
|
965
|
+
return existsSync8(cloudPreparedPath(env));
|
|
966
|
+
} catch {
|
|
967
|
+
return false;
|
|
968
|
+
}
|
|
969
|
+
}
|
|
810
970
|
|
|
811
971
|
// src/lib/demo-pause.ts
|
|
812
972
|
import { execFileSync as execFileSync2 } from "child_process";
|
|
@@ -872,11 +1032,12 @@ function healDemoPause(cwd, pause, options = {}) {
|
|
|
872
1032
|
// src/lib/git.ts
|
|
873
1033
|
import { execFileSync as execFileSync3 } from "child_process";
|
|
874
1034
|
import { createHash as createHash6 } from "crypto";
|
|
875
|
-
import { lstatSync as lstatSync5, realpathSync } from "fs";
|
|
876
|
-
import { basename as basename3, dirname as dirname9, isAbsolute as isAbsolute3, relative, resolve as resolve2, sep } from "path";
|
|
1035
|
+
import { lstatSync as lstatSync5, readFileSync as readFileSync13, realpathSync } from "fs";
|
|
1036
|
+
import { basename as basename3, dirname as dirname9, isAbsolute as isAbsolute3, join as join14, relative, resolve as resolve2, sep } from "path";
|
|
877
1037
|
var GIT_TIMEOUT_MS2 = 1e3;
|
|
1038
|
+
var MAX_SETTINGS_BYTES = 1024 * 1024;
|
|
878
1039
|
var GITHUB_OWNER_PATTERN = /^(?![A-Za-z0-9-]*--)[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/u;
|
|
879
|
-
var GITHUB_REPOSITORY_PATTERN = /^[A-Za-z0-9._-]{1,100}$/u;
|
|
1040
|
+
var GITHUB_REPOSITORY_PATTERN = /^(?!\.{1,2}$)[A-Za-z0-9._-]{1,100}$/u;
|
|
880
1041
|
function gitToplevel(cwd) {
|
|
881
1042
|
try {
|
|
882
1043
|
return execFileSync3("git", ["rev-parse", "--show-toplevel"], {
|
|
@@ -902,19 +1063,57 @@ function gitValue(cwd, args) {
|
|
|
902
1063
|
return void 0;
|
|
903
1064
|
}
|
|
904
1065
|
}
|
|
905
|
-
function
|
|
906
|
-
const
|
|
907
|
-
if (
|
|
1066
|
+
function parseGithubRepositoryName(path) {
|
|
1067
|
+
const parts = path.replace(/^\/+|\/+$/g, "").replace(/\.git$/i, "").split("/");
|
|
1068
|
+
if (parts.length !== 2 || !GITHUB_OWNER_PATTERN.test(parts[0] ?? "") || !GITHUB_REPOSITORY_PATTERN.test(parts[1] ?? "")) {
|
|
1069
|
+
return null;
|
|
1070
|
+
}
|
|
1071
|
+
return `${parts[0]}/${parts[1]}`;
|
|
1072
|
+
}
|
|
1073
|
+
function githubRepositoryFromRemote(remote) {
|
|
1074
|
+
if ([...remote].some((char) => char < " " || char === "\x7F")) return null;
|
|
908
1075
|
const match = /^(?:git@github\.com:([^?#]+)|(?:https|ssh):\/\/(?:[^/@]+@)?github\.com(?::\d+)?\/([^?#]+))$/i.exec(
|
|
909
1076
|
remote
|
|
910
1077
|
);
|
|
911
1078
|
const path = match?.[1] ?? match?.[2];
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
1079
|
+
return path ? parseGithubRepositoryName(path) : null;
|
|
1080
|
+
}
|
|
1081
|
+
function checkoutSettingsText(repoRoot) {
|
|
1082
|
+
const path = join14(repoRoot, ".claude", "settings.json");
|
|
1083
|
+
try {
|
|
1084
|
+
if (!lstatSync5(join14(repoRoot, ".claude")).isDirectory()) return null;
|
|
1085
|
+
const stat = lstatSync5(path);
|
|
1086
|
+
if (!stat.isFile() || stat.size > MAX_SETTINGS_BYTES) return null;
|
|
1087
|
+
return readFileSync13(path, "utf8");
|
|
1088
|
+
} catch {
|
|
915
1089
|
return null;
|
|
916
1090
|
}
|
|
917
|
-
|
|
1091
|
+
}
|
|
1092
|
+
function checkoutDeclaration(repoRoot, name) {
|
|
1093
|
+
const text = checkoutSettingsText(repoRoot);
|
|
1094
|
+
if (text === null) return null;
|
|
1095
|
+
let parsed;
|
|
1096
|
+
try {
|
|
1097
|
+
parsed = JSON.parse(text);
|
|
1098
|
+
} catch {
|
|
1099
|
+
return null;
|
|
1100
|
+
}
|
|
1101
|
+
const env = typeof parsed === "object" && parsed !== null ? parsed.env : void 0;
|
|
1102
|
+
const value = typeof env === "object" && env !== null ? env[name] : void 0;
|
|
1103
|
+
return typeof value === "string" ? value : null;
|
|
1104
|
+
}
|
|
1105
|
+
function declaredGithubRepository(repoRoot) {
|
|
1106
|
+
const value = checkoutDeclaration(repoRoot, "PRIM_REPOSITORY");
|
|
1107
|
+
return value === null ? null : parseGithubRepositoryName(value.trim());
|
|
1108
|
+
}
|
|
1109
|
+
function githubRepositoryFullName(cwd) {
|
|
1110
|
+
const remote = gitValue(cwd, ["config", "--get", "remote.origin.url"]);
|
|
1111
|
+
if (remote) {
|
|
1112
|
+
const fromOrigin = githubRepositoryFromRemote(remote);
|
|
1113
|
+
if (fromOrigin || normalizeOriginRemote(remote)) return fromOrigin;
|
|
1114
|
+
}
|
|
1115
|
+
const root = gitToplevel(cwd);
|
|
1116
|
+
return root ? declaredGithubRepository(root) : null;
|
|
918
1117
|
}
|
|
919
1118
|
function normalizeOriginRemote(remote) {
|
|
920
1119
|
const value = remote.trim();
|
|
@@ -960,6 +1159,14 @@ function resolveRepositoryContext(cwd = process.cwd()) {
|
|
|
960
1159
|
repoFullName
|
|
961
1160
|
};
|
|
962
1161
|
}
|
|
1162
|
+
if (repoFullName) {
|
|
1163
|
+
return {
|
|
1164
|
+
repoRoot,
|
|
1165
|
+
repoKey: opaqueRepoKey("origin", `github.com/${repoFullName}`),
|
|
1166
|
+
identitySource: "declared",
|
|
1167
|
+
repoFullName
|
|
1168
|
+
};
|
|
1169
|
+
}
|
|
963
1170
|
const roots = gitValue(repoRoot, ["rev-list", "--max-parents=0", "HEAD"])?.split(/\s+/).filter(Boolean).sort();
|
|
964
1171
|
if (roots && roots.length > 0) {
|
|
965
1172
|
return {
|
|
@@ -974,6 +1181,7 @@ function resolveRepositoryContext(cwd = process.cwd()) {
|
|
|
974
1181
|
|
|
975
1182
|
// src/lib/activation.ts
|
|
976
1183
|
var PRIM_ACTIVE_KEY = "prim.active";
|
|
1184
|
+
var PRIM_ACTIVE_DECLARATION = "PRIM_ACTIVE";
|
|
977
1185
|
var PRIM_REPO_SYNC_ID_KEY = "prim.repoSyncId";
|
|
978
1186
|
var PRIM_REPO_SYNC_REPOSITORY_KEY = "prim.repoSyncRepository";
|
|
979
1187
|
var GIT_TIMEOUT_MS3 = 1e3;
|
|
@@ -1020,14 +1228,13 @@ function repoSyncId(cwd) {
|
|
|
1020
1228
|
const repositoryFullName = localGitConfigValue(cwd, PRIM_REPO_SYNC_REPOSITORY_KEY);
|
|
1021
1229
|
return repositoryFullName === githubRepositoryFullName(cwd) ? value : void 0;
|
|
1022
1230
|
}
|
|
1023
|
-
function
|
|
1024
|
-
const root = gitToplevel(cwd);
|
|
1231
|
+
function projectPrimInstallAt(root) {
|
|
1025
1232
|
if (root === null || root === homedir2()) return false;
|
|
1026
1233
|
for (const rel of PROJECT_INSTALL_FILES) {
|
|
1027
|
-
const path =
|
|
1028
|
-
if (
|
|
1234
|
+
const path = join15(root, rel);
|
|
1235
|
+
if (existsSync9(path)) {
|
|
1029
1236
|
try {
|
|
1030
|
-
const content =
|
|
1237
|
+
const content = readFileSync14(path, "utf-8");
|
|
1031
1238
|
if (PRIM_HOOK_BINS.some((bin) => content.includes(bin))) return true;
|
|
1032
1239
|
} catch {
|
|
1033
1240
|
}
|
|
@@ -1035,12 +1242,27 @@ function hasProjectPrimInstall(cwd) {
|
|
|
1035
1242
|
}
|
|
1036
1243
|
return false;
|
|
1037
1244
|
}
|
|
1245
|
+
var UNPARSED_OPT_OUT = /"PRIM_ACTIVE"\s*:\s*"\s*false\s*"/u;
|
|
1246
|
+
function declaresInactiveAt(root) {
|
|
1247
|
+
if (root === null || root === homedir2()) return false;
|
|
1248
|
+
if (checkoutDeclaration(root, PRIM_ACTIVE_DECLARATION)?.trim() === "false") return true;
|
|
1249
|
+
const text = checkoutSettingsText(root);
|
|
1250
|
+
if (text === null || !UNPARSED_OPT_OUT.test(text)) return false;
|
|
1251
|
+
try {
|
|
1252
|
+
JSON.parse(text);
|
|
1253
|
+
return false;
|
|
1254
|
+
} catch {
|
|
1255
|
+
return true;
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1038
1258
|
function isRepoActiveForCapture(cwd, options = {}) {
|
|
1039
1259
|
let { active: flag, pause } = readCaptureConfig(cwd);
|
|
1040
1260
|
if (pause && healDemoPause(cwd, pause, options)) flag = repoActiveFlag(cwd);
|
|
1041
1261
|
if (flag === "true") return true;
|
|
1042
1262
|
if (flag === "false") return false;
|
|
1043
|
-
|
|
1263
|
+
const root = gitToplevel(cwd);
|
|
1264
|
+
if (declaresInactiveAt(root)) return false;
|
|
1265
|
+
return projectPrimInstallAt(root) || isPreparedCloudSession() && root !== null;
|
|
1044
1266
|
}
|
|
1045
1267
|
|
|
1046
1268
|
// src/generated/cli-http-v1.validators.js
|
|
@@ -28026,17 +28248,17 @@ import {
|
|
|
28026
28248
|
closeSync as closeSync3,
|
|
28027
28249
|
fchmodSync as fchmodSync2,
|
|
28028
28250
|
fsyncSync as fsyncSync2,
|
|
28029
|
-
linkSync,
|
|
28251
|
+
linkSync as linkSync2,
|
|
28030
28252
|
lstatSync as lstatSync6,
|
|
28031
|
-
mkdirSync as
|
|
28253
|
+
mkdirSync as mkdirSync7,
|
|
28032
28254
|
openSync as openSync3,
|
|
28033
|
-
readFileSync as
|
|
28255
|
+
readFileSync as readFileSync15,
|
|
28034
28256
|
statSync as statSync2,
|
|
28035
28257
|
unlinkSync,
|
|
28036
|
-
writeFileSync as
|
|
28258
|
+
writeFileSync as writeFileSync5
|
|
28037
28259
|
} from "fs";
|
|
28038
|
-
import { dirname as dirname10, isAbsolute as isAbsolute4, join as
|
|
28039
|
-
var WORKSPACE_ID_RELATIVE_PATH =
|
|
28260
|
+
import { dirname as dirname10, isAbsolute as isAbsolute4, join as join16, resolve as resolve3 } from "path";
|
|
28261
|
+
var WORKSPACE_ID_RELATIVE_PATH = join16("prim", "workspace-id");
|
|
28040
28262
|
var MAX_ANCESTORS = 64;
|
|
28041
28263
|
var MAX_GIT_FILE_BYTES = 4096;
|
|
28042
28264
|
var MAX_ID_FILE_BYTES = 128;
|
|
@@ -28095,19 +28317,19 @@ function resolveWorkspaceIdPath(cwd) {
|
|
|
28095
28317
|
function resolveFromFilesystem(cwd) {
|
|
28096
28318
|
let current = resolve3(cwd);
|
|
28097
28319
|
for (let depth = 0; depth < MAX_ANCESTORS; depth += 1) {
|
|
28098
|
-
const dotGit =
|
|
28320
|
+
const dotGit = join16(current, ".git");
|
|
28099
28321
|
try {
|
|
28100
28322
|
const stat = lstatSync6(dotGit);
|
|
28101
28323
|
if (stat.isDirectory() && isGitDirectory(dotGit)) {
|
|
28102
|
-
return
|
|
28324
|
+
return join16(dotGit, WORKSPACE_ID_RELATIVE_PATH);
|
|
28103
28325
|
}
|
|
28104
28326
|
if (stat.isFile() && stat.size <= MAX_GIT_FILE_BYTES) {
|
|
28105
|
-
const contents =
|
|
28327
|
+
const contents = readFileSync15(dotGit, "utf8");
|
|
28106
28328
|
const match = /^gitdir: (.+?)(?:\r?\n)?$/.exec(contents);
|
|
28107
28329
|
if (match?.[1]) {
|
|
28108
28330
|
const gitDirectory = isAbsolute4(match[1]) ? resolve3(match[1]) : resolve3(current, match[1]);
|
|
28109
28331
|
if (isGitDirectory(gitDirectory)) {
|
|
28110
|
-
return
|
|
28332
|
+
return join16(gitDirectory, WORKSPACE_ID_RELATIVE_PATH);
|
|
28111
28333
|
}
|
|
28112
28334
|
}
|
|
28113
28335
|
}
|
|
@@ -28126,7 +28348,7 @@ function resolveFromFilesystem(cwd) {
|
|
|
28126
28348
|
}
|
|
28127
28349
|
function isGitDirectory(path) {
|
|
28128
28350
|
try {
|
|
28129
|
-
return statSync2(
|
|
28351
|
+
return statSync2(join16(path, "HEAD")).isFile();
|
|
28130
28352
|
} catch {
|
|
28131
28353
|
return false;
|
|
28132
28354
|
}
|
|
@@ -28145,7 +28367,7 @@ function inspectPath(path) {
|
|
|
28145
28367
|
return { status: "corrupt", path, reason: "invalid_content" };
|
|
28146
28368
|
}
|
|
28147
28369
|
try {
|
|
28148
|
-
const contents =
|
|
28370
|
+
const contents = readFileSync15(path, "utf8");
|
|
28149
28371
|
const workspaceId = contents.endsWith("\n") ? contents.slice(0, -1) : contents;
|
|
28150
28372
|
if ((contents === workspaceId || contents === `${workspaceId}
|
|
28151
28373
|
`) && isCanonicalWorkspaceId(workspaceId)) {
|
|
@@ -28164,11 +28386,11 @@ function inspectPath(path) {
|
|
|
28164
28386
|
function createWorkspaceId(path) {
|
|
28165
28387
|
const parent = dirname10(path);
|
|
28166
28388
|
const workspaceId = randomUUID3();
|
|
28167
|
-
const temporaryPath =
|
|
28389
|
+
const temporaryPath = join16(parent, `.workspace-id-${process.pid}-${randomUUID3()}.tmp`);
|
|
28168
28390
|
let temporaryCreated = false;
|
|
28169
28391
|
let publishing = false;
|
|
28170
28392
|
try {
|
|
28171
|
-
|
|
28393
|
+
mkdirSync7(parent, { recursive: true, mode: 448 });
|
|
28172
28394
|
chmodSync5(parent, 448);
|
|
28173
28395
|
const fd = openSync3(
|
|
28174
28396
|
temporaryPath,
|
|
@@ -28177,7 +28399,7 @@ function createWorkspaceId(path) {
|
|
|
28177
28399
|
);
|
|
28178
28400
|
temporaryCreated = true;
|
|
28179
28401
|
try {
|
|
28180
|
-
|
|
28402
|
+
writeFileSync5(fd, `${workspaceId}
|
|
28181
28403
|
`, "utf8");
|
|
28182
28404
|
fchmodSync2(fd, 384);
|
|
28183
28405
|
fsyncSync2(fd);
|
|
@@ -28185,7 +28407,7 @@ function createWorkspaceId(path) {
|
|
|
28185
28407
|
closeSync3(fd);
|
|
28186
28408
|
}
|
|
28187
28409
|
publishing = true;
|
|
28188
|
-
|
|
28410
|
+
linkSync2(temporaryPath, path);
|
|
28189
28411
|
return { status: "ready", workspaceId, path, created: true };
|
|
28190
28412
|
} catch (error) {
|
|
28191
28413
|
if (publishing && errorCode(error) === "EEXIST") return inspectAfterRace(path);
|
|
@@ -28232,8 +28454,8 @@ var LEGACY_ENVELOPE_VERSION = 1;
|
|
|
28232
28454
|
var ENVELOPE_VERSION = LEGACY_ENVELOPE_VERSION;
|
|
28233
28455
|
|
|
28234
28456
|
// src/hooks/redact.ts
|
|
28235
|
-
import { existsSync as
|
|
28236
|
-
import { join as
|
|
28457
|
+
import { existsSync as existsSync10, readFileSync as readFileSync16, statSync as statSync3 } from "fs";
|
|
28458
|
+
import { join as join17 } from "path";
|
|
28237
28459
|
import { Worker } from "worker_threads";
|
|
28238
28460
|
var USER_HOME_RULES = [
|
|
28239
28461
|
{
|
|
@@ -28277,6 +28499,11 @@ var DEFAULT_RULES = [
|
|
|
28277
28499
|
pattern: /\bAWS_(?:SECRET_ACCESS_KEY|SESSION_TOKEN)"?\s*[:=]\s*["']?[A-Za-z0-9/+=]{20,}["']?/gi,
|
|
28278
28500
|
reason: "aws-secret"
|
|
28279
28501
|
},
|
|
28502
|
+
{
|
|
28503
|
+
// `prim auth enroll --print-env` output an agent may write into a file.
|
|
28504
|
+
pattern: /\bPRIM_M2M_CLIENT_SECRET"?\s*[:=]\s*["']?[^\s"']+["']?/g,
|
|
28505
|
+
reason: "prim-m2m-secret"
|
|
28506
|
+
},
|
|
28280
28507
|
{ pattern: /\bAIza[0-9A-Za-z_-]{35}(?![0-9A-Za-z_-])/g, reason: "gcp-api-key" },
|
|
28281
28508
|
{
|
|
28282
28509
|
pattern: /\bya29\.[0-9A-Za-z_-]{20,}(?![0-9A-Za-z_-])/g,
|
|
@@ -28452,7 +28679,7 @@ function rewritePairsFromLauncher(env = process.env, now = Date.now()) {
|
|
|
28452
28679
|
if (!privatePairsFileStat(openStat, now) || openStat.dev !== pathStat.dev || openStat.ino !== pathStat.ino) {
|
|
28453
28680
|
return;
|
|
28454
28681
|
}
|
|
28455
|
-
const bytes =
|
|
28682
|
+
const bytes = readFileSync17(fd);
|
|
28456
28683
|
if (bytes.length !== openStat.size) return;
|
|
28457
28684
|
let text;
|
|
28458
28685
|
try {
|
|
@@ -28508,14 +28735,14 @@ function validBranch(value) {
|
|
|
28508
28735
|
}
|
|
28509
28736
|
function resolveCliVersion() {
|
|
28510
28737
|
try {
|
|
28511
|
-
const pkg = JSON.parse(
|
|
28738
|
+
const pkg = JSON.parse(readFileSync17(join18(here, "..", "..", "package.json"), "utf-8"));
|
|
28512
28739
|
return pkg.version ?? "unknown";
|
|
28513
28740
|
} catch {
|
|
28514
28741
|
return "unknown";
|
|
28515
28742
|
}
|
|
28516
28743
|
}
|
|
28517
28744
|
function spawnBackgroundFlush() {
|
|
28518
|
-
const entry =
|
|
28745
|
+
const entry = join18(here, "..", "index.js");
|
|
28519
28746
|
spawn2(process.execPath, [entry, "moves", "flush"], {
|
|
28520
28747
|
detached: true,
|
|
28521
28748
|
stdio: "ignore",
|