@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
package/dist/statusline-main.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/commands/statusline.ts
|
|
4
|
-
import { readFileSync as
|
|
4
|
+
import { readFileSync as readFileSync12 } from "fs";
|
|
5
5
|
import { dirname as dirname7, resolve as resolve3 } from "path";
|
|
6
6
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
7
7
|
|
|
8
|
+
// src/lib/cloud-env.ts
|
|
9
|
+
function isClaudeCloudSession(env = process.env) {
|
|
10
|
+
return env.CLAUDE_CODE_REMOTE === "true";
|
|
11
|
+
}
|
|
12
|
+
|
|
8
13
|
// src/client.ts
|
|
9
14
|
import { createHash as createHash5 } from "crypto";
|
|
10
15
|
import { chmodSync as chmodSync3, existsSync as existsSync4, mkdirSync as mkdirSync4, readFileSync as readFileSync8, rmSync as rmSync6 } from "fs";
|
|
@@ -32,8 +37,17 @@ import { join as join7 } from "path";
|
|
|
32
37
|
|
|
33
38
|
// src/lib/machine-credentials.ts
|
|
34
39
|
import { execFileSync } from "child_process";
|
|
35
|
-
import { createHash as createHash3, randomUUID as randomUUID2 } from "crypto";
|
|
36
|
-
import {
|
|
40
|
+
import { createHash as createHash3, randomBytes as randomBytes3, randomUUID as randomUUID2 } from "crypto";
|
|
41
|
+
import {
|
|
42
|
+
chmodSync,
|
|
43
|
+
existsSync as existsSync3,
|
|
44
|
+
linkSync,
|
|
45
|
+
lstatSync as lstatSync3,
|
|
46
|
+
mkdirSync as mkdirSync3,
|
|
47
|
+
readFileSync as readFileSync5,
|
|
48
|
+
rmSync as rmSync5,
|
|
49
|
+
writeFileSync as writeFileSync3
|
|
50
|
+
} from "fs";
|
|
37
51
|
import { createRequire } from "module";
|
|
38
52
|
import { dirname as dirname4, join as join6 } from "path";
|
|
39
53
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
@@ -96,6 +110,10 @@ var PRIM_CONFIG_SHELL_RESOLVER = [
|
|
|
96
110
|
"fi; fi; "
|
|
97
111
|
].join("");
|
|
98
112
|
|
|
113
|
+
// src/lib/loopback-fetch.ts
|
|
114
|
+
import { request } from "http";
|
|
115
|
+
import { Readable } from "stream";
|
|
116
|
+
|
|
99
117
|
// src/lib/workos-connect.ts
|
|
100
118
|
var DISCOVERY_MAX_BYTES = 16 * 1024;
|
|
101
119
|
var WORKOS_CONNECT_RESPONSE_MAX_BYTES = 64 * 1024;
|
|
@@ -271,12 +289,16 @@ function primConfigDirectory(options = {}) {
|
|
|
271
289
|
|
|
272
290
|
// src/lib/machine-broker.ts
|
|
273
291
|
var MAX_RESPONSE_BYTES = 96 * 1024;
|
|
292
|
+
var MAX_FORWARD_REQUEST_BYTES = 12 * 1024 * 1024;
|
|
293
|
+
var MAX_API_RESPONSE_BYTES = 8 * 1024 * 1024;
|
|
294
|
+
var MAX_FORWARD_RESPONSE_BYTES = 36 * 1024 * 1024;
|
|
274
295
|
var IDLE_MS = 5 * 6e4;
|
|
275
296
|
|
|
276
297
|
// src/lib/machine-retry.ts
|
|
277
298
|
import { createHash as createHash2 } from "crypto";
|
|
278
|
-
import { lstatSync as lstatSync2, readFileSync as readFileSync4, rmSync as rmSync4 } from "fs";
|
|
299
|
+
import { lstatSync as lstatSync2, readFileSync as readFileSync4, readdirSync, rmSync as rmSync4 } from "fs";
|
|
279
300
|
import { join as join5 } from "path";
|
|
301
|
+
var MAX_SERVER_WAIT_MS = 15 * 6e4;
|
|
280
302
|
|
|
281
303
|
// src/lib/machine-credentials.ts
|
|
282
304
|
var require2 = createRequire(import.meta.url);
|
|
@@ -319,6 +341,33 @@ function readEnvironmentContext(environment, deps) {
|
|
|
319
341
|
return void 0;
|
|
320
342
|
}
|
|
321
343
|
}
|
|
344
|
+
function protectPath(path, directory) {
|
|
345
|
+
if (process.platform !== "win32") {
|
|
346
|
+
chmodSync(path, directory ? 448 : 384);
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
const encodedPath = Buffer.from(path).toString("base64");
|
|
350
|
+
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)`;
|
|
351
|
+
execFileSync(
|
|
352
|
+
"powershell.exe",
|
|
353
|
+
[
|
|
354
|
+
"-NoProfile",
|
|
355
|
+
"-NonInteractive",
|
|
356
|
+
"-EncodedCommand",
|
|
357
|
+
Buffer.from(script, "utf16le").toString("base64")
|
|
358
|
+
],
|
|
359
|
+
{ stdio: "pipe", encoding: "utf8", windowsHide: true }
|
|
360
|
+
);
|
|
361
|
+
}
|
|
362
|
+
function ensureDirectory(directory) {
|
|
363
|
+
mkdirSync3(directory, { recursive: true, mode: 448 });
|
|
364
|
+
if (lstatSync3(directory).isSymbolicLink())
|
|
365
|
+
throw new MachineAuthError(
|
|
366
|
+
"unsafe_storage",
|
|
367
|
+
"Credential directory must not be a symbolic link."
|
|
368
|
+
);
|
|
369
|
+
protectPath(directory, true);
|
|
370
|
+
}
|
|
322
371
|
function readPrivate(path) {
|
|
323
372
|
let raw;
|
|
324
373
|
try {
|
|
@@ -377,10 +426,98 @@ function readMachineProfile(deps = {}) {
|
|
|
377
426
|
const value = readPrivate(join6(configurationDirectory(deps), PROFILE_FILE));
|
|
378
427
|
return value === void 0 ? void 0 : parseProfile(value);
|
|
379
428
|
}
|
|
429
|
+
var NETWORK_SECRET_AUTH = "network-secret";
|
|
430
|
+
var NETWORK_TOKEN_AUTH = "network-token";
|
|
431
|
+
var INJECTED_IDENTITY_TTL_MS = 60 * 6e4;
|
|
432
|
+
var brokerKeys = /* @__PURE__ */ new Map();
|
|
433
|
+
function networkSecretBrokerKey(deps, clientId) {
|
|
434
|
+
const directory = configurationDirectory(deps);
|
|
435
|
+
const path = join6(directory, `machine_network_${hash(`${apiUrlFor(deps)}\0${clientId}`)}.key`);
|
|
436
|
+
const known = brokerKeys.get(path);
|
|
437
|
+
if (known) return known;
|
|
438
|
+
ensureDirectory(directory);
|
|
439
|
+
const read = () => {
|
|
440
|
+
try {
|
|
441
|
+
const stat = lstatSync3(path);
|
|
442
|
+
if (!stat.isFile() || process.platform !== "win32" && ((stat.mode & 63) !== 0 || typeof process.getuid === "function" && stat.uid !== process.getuid()))
|
|
443
|
+
throw new MachineAuthError(
|
|
444
|
+
"unsafe_storage",
|
|
445
|
+
`The machine broker key at ${path} is not an owner-only file. Delete it and retry.`,
|
|
446
|
+
true
|
|
447
|
+
);
|
|
448
|
+
const value = readFileSync5(path, "utf8").trim();
|
|
449
|
+
return { key: /^[a-f0-9]{64}$/u.test(value) ? value : void 0 };
|
|
450
|
+
} catch (error) {
|
|
451
|
+
if (error.code === "ENOENT") return void 0;
|
|
452
|
+
throw error;
|
|
453
|
+
}
|
|
454
|
+
};
|
|
455
|
+
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
456
|
+
const existing = read();
|
|
457
|
+
if (existing?.key) {
|
|
458
|
+
brokerKeys.set(path, existing.key);
|
|
459
|
+
return existing.key;
|
|
460
|
+
}
|
|
461
|
+
if (existing)
|
|
462
|
+
throw new MachineAuthError(
|
|
463
|
+
"unsafe_storage",
|
|
464
|
+
`The machine broker key at ${path} is damaged. Delete it and retry.`,
|
|
465
|
+
true
|
|
466
|
+
);
|
|
467
|
+
const staged = `${path}.${process.pid}.${randomBytes3(6).toString("hex")}`;
|
|
468
|
+
try {
|
|
469
|
+
writeFileSync3(staged, `${randomBytes3(32).toString("hex")}
|
|
470
|
+
`, { mode: 384, flag: "wx" });
|
|
471
|
+
protectPath(staged, false);
|
|
472
|
+
linkSync(staged, path);
|
|
473
|
+
} catch (error) {
|
|
474
|
+
if (error.code !== "EEXIST") throw error;
|
|
475
|
+
} finally {
|
|
476
|
+
rmSync5(staged, { force: true });
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
const key = read()?.key;
|
|
480
|
+
if (!key)
|
|
481
|
+
throw new MachineAuthError("unsafe_storage", "The machine broker key is unreadable.", true);
|
|
482
|
+
brokerKeys.set(path, key);
|
|
483
|
+
return key;
|
|
484
|
+
}
|
|
380
485
|
function environmentCredentials(deps) {
|
|
381
486
|
const env = deps.env ?? process.env;
|
|
382
|
-
const {
|
|
383
|
-
|
|
487
|
+
const {
|
|
488
|
+
PRIM_M2M_CLIENT_ID: clientId,
|
|
489
|
+
PRIM_M2M_CLIENT_SECRET: clientSecret,
|
|
490
|
+
PRIM_M2M_CLIENT_AUTH: auth
|
|
491
|
+
} = env;
|
|
492
|
+
if (clientId === void 0 && clientSecret === void 0 && auth === void 0) return void 0;
|
|
493
|
+
if (auth !== void 0 && auth !== NETWORK_SECRET_AUTH && auth !== NETWORK_TOKEN_AUTH)
|
|
494
|
+
throw new MachineAuthError(
|
|
495
|
+
"incomplete_machine_credentials",
|
|
496
|
+
`PRIM_M2M_CLIENT_AUTH accepts ${NETWORK_SECRET_AUTH} or ${NETWORK_TOKEN_AUTH}.`
|
|
497
|
+
);
|
|
498
|
+
if (auth !== void 0) {
|
|
499
|
+
if (!clientId || !/^client_[\w-]+$/u.test(clientId))
|
|
500
|
+
throw new MachineAuthError(
|
|
501
|
+
"incomplete_machine_credentials",
|
|
502
|
+
`Set PRIM_M2M_CLIENT_ID with PRIM_M2M_CLIENT_AUTH=${auth}.`
|
|
503
|
+
);
|
|
504
|
+
if (clientSecret !== void 0)
|
|
505
|
+
throw new MachineAuthError(
|
|
506
|
+
"conflicting_credentials",
|
|
507
|
+
`Unset PRIM_M2M_CLIENT_SECRET: with PRIM_M2M_CLIENT_AUTH=${auth} the environment's network secret supplies it.`
|
|
508
|
+
);
|
|
509
|
+
const generation = hash(`${apiUrlFor(deps)}\0${clientId}\0${auth}\0broker-proxy`);
|
|
510
|
+
const credentials = {
|
|
511
|
+
clientId,
|
|
512
|
+
generation,
|
|
513
|
+
...auth === NETWORK_TOKEN_AUTH ? { tokenInjection: "network" } : { secretInjection: "network" }
|
|
514
|
+
};
|
|
515
|
+
Object.defineProperty(credentials, "clientSecret", {
|
|
516
|
+
enumerable: true,
|
|
517
|
+
get: () => networkSecretBrokerKey(deps, clientId)
|
|
518
|
+
});
|
|
519
|
+
return credentials;
|
|
520
|
+
}
|
|
384
521
|
if (!clientId || !clientSecret || !/^client_[\w-]+$/u.test(clientId) || !machineString(clientSecret)) {
|
|
385
522
|
throw new MachineAuthError(
|
|
386
523
|
"incomplete_machine_credentials",
|
|
@@ -395,7 +532,7 @@ function environmentCredentials(deps) {
|
|
|
395
532
|
}
|
|
396
533
|
function hasMachineConfiguration(deps = {}) {
|
|
397
534
|
const env = deps.env ?? process.env;
|
|
398
|
-
const configured = env.PRIM_M2M_CLIENT_ID !== void 0 || env.PRIM_M2M_CLIENT_SECRET !== void 0 || existsSync3(join6(configurationDirectory(deps), PROFILE_FILE));
|
|
535
|
+
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));
|
|
399
536
|
if (configured && env.PRIM_TOKEN?.trim()) {
|
|
400
537
|
throw new MachineAuthError(
|
|
401
538
|
"conflicting_credentials",
|
|
@@ -450,7 +587,7 @@ function readTrimmed(path) {
|
|
|
450
587
|
function resolveAuthCredential(options = {}) {
|
|
451
588
|
if (!options.tokenFilePath && hasMachineConfiguration({ env: options.env })) {
|
|
452
589
|
const machine = cachedMachineCredential({ env: options.env });
|
|
453
|
-
return machine ? { token: machine.accessToken, source: "machine" } : void 0;
|
|
590
|
+
return machine?.accessToken ? { token: machine.accessToken, source: "machine" } : void 0;
|
|
454
591
|
}
|
|
455
592
|
const envToken = (options.env ?? process.env).PRIM_TOKEN?.trim();
|
|
456
593
|
if (envToken) return { token: envToken, source: "environment" };
|
|
@@ -566,7 +703,7 @@ function decodeJwtPayload(token) {
|
|
|
566
703
|
}
|
|
567
704
|
|
|
568
705
|
// src/daemon/client-instance-id.ts
|
|
569
|
-
import { randomBytes as
|
|
706
|
+
import { randomBytes as randomBytes4 } from "crypto";
|
|
570
707
|
import { chmodSync as chmodSync2, lstatSync as lstatSync4, readFileSync as readFileSync7 } from "fs";
|
|
571
708
|
import { join as join8 } from "path";
|
|
572
709
|
var INSTANCE_BODY_CHARS = 43;
|
|
@@ -690,7 +827,7 @@ var nextRequestId = 1;
|
|
|
690
827
|
function daemonRequest(method, params = {}, opts = {}) {
|
|
691
828
|
const id = nextRequestId++;
|
|
692
829
|
const caller = resolveDaemonPrincipal();
|
|
693
|
-
const
|
|
830
|
+
const request2 = {
|
|
694
831
|
id,
|
|
695
832
|
method,
|
|
696
833
|
params,
|
|
@@ -729,7 +866,7 @@ function daemonRequest(method, params = {}, opts = {}) {
|
|
|
729
866
|
});
|
|
730
867
|
socket.on("connect", () => {
|
|
731
868
|
try {
|
|
732
|
-
socket?.write(`${JSON.stringify(
|
|
869
|
+
socket?.write(`${JSON.stringify(request2)}
|
|
733
870
|
`);
|
|
734
871
|
} catch {
|
|
735
872
|
clearTimeout(timer);
|
|
@@ -775,9 +912,25 @@ function daemonRequest(method, params = {}, opts = {}) {
|
|
|
775
912
|
|
|
776
913
|
// src/lib/activation.ts
|
|
777
914
|
import { execFileSync as execFileSync4 } from "child_process";
|
|
778
|
-
import { existsSync as
|
|
915
|
+
import { existsSync as existsSync6, readFileSync as readFileSync11 } from "fs";
|
|
779
916
|
import { homedir as homedir2 } from "os";
|
|
917
|
+
import { join as join13 } from "path";
|
|
918
|
+
|
|
919
|
+
// src/lib/cloud-prepared.ts
|
|
920
|
+
import { existsSync as existsSync5, mkdirSync as mkdirSync5, readFileSync as readFileSync9, rmSync as rmSync7, writeFileSync as writeFileSync4 } from "fs";
|
|
780
921
|
import { join as join11 } from "path";
|
|
922
|
+
var CLOUD_PREPARED_MARKER = "cloud-prepared";
|
|
923
|
+
function cloudPreparedPath(env = process.env) {
|
|
924
|
+
return join11(primConfigDirectory({ env }), CLOUD_PREPARED_MARKER);
|
|
925
|
+
}
|
|
926
|
+
function isPreparedCloudSession(env = process.env) {
|
|
927
|
+
if (!isClaudeCloudSession(env)) return false;
|
|
928
|
+
try {
|
|
929
|
+
return existsSync5(cloudPreparedPath(env));
|
|
930
|
+
} catch {
|
|
931
|
+
return false;
|
|
932
|
+
}
|
|
933
|
+
}
|
|
781
934
|
|
|
782
935
|
// src/lib/demo-pause.ts
|
|
783
936
|
import { execFileSync as execFileSync2 } from "child_process";
|
|
@@ -843,11 +996,12 @@ function healDemoPause(cwd, pause, options = {}) {
|
|
|
843
996
|
// src/lib/git.ts
|
|
844
997
|
import { execFileSync as execFileSync3 } from "child_process";
|
|
845
998
|
import { createHash as createHash7 } from "crypto";
|
|
846
|
-
import { lstatSync as lstatSync5, realpathSync } from "fs";
|
|
847
|
-
import { basename as basename2, dirname as dirname6, isAbsolute as isAbsolute3, relative, resolve as resolve2, sep } from "path";
|
|
999
|
+
import { lstatSync as lstatSync5, readFileSync as readFileSync10, realpathSync } from "fs";
|
|
1000
|
+
import { basename as basename2, dirname as dirname6, isAbsolute as isAbsolute3, join as join12, relative, resolve as resolve2, sep } from "path";
|
|
848
1001
|
var GIT_TIMEOUT_MS2 = 1e3;
|
|
1002
|
+
var MAX_SETTINGS_BYTES = 1024 * 1024;
|
|
849
1003
|
var GITHUB_OWNER_PATTERN = /^(?![A-Za-z0-9-]*--)[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/u;
|
|
850
|
-
var GITHUB_REPOSITORY_PATTERN = /^[A-Za-z0-9._-]{1,100}$/u;
|
|
1004
|
+
var GITHUB_REPOSITORY_PATTERN = /^(?!\.{1,2}$)[A-Za-z0-9._-]{1,100}$/u;
|
|
851
1005
|
function gitToplevel(cwd) {
|
|
852
1006
|
try {
|
|
853
1007
|
return execFileSync3("git", ["rev-parse", "--show-toplevel"], {
|
|
@@ -873,23 +1027,83 @@ function gitValue(cwd, args) {
|
|
|
873
1027
|
return void 0;
|
|
874
1028
|
}
|
|
875
1029
|
}
|
|
876
|
-
function
|
|
877
|
-
const
|
|
878
|
-
if (
|
|
1030
|
+
function parseGithubRepositoryName(path) {
|
|
1031
|
+
const parts = path.replace(/^\/+|\/+$/g, "").replace(/\.git$/i, "").split("/");
|
|
1032
|
+
if (parts.length !== 2 || !GITHUB_OWNER_PATTERN.test(parts[0] ?? "") || !GITHUB_REPOSITORY_PATTERN.test(parts[1] ?? "")) {
|
|
1033
|
+
return null;
|
|
1034
|
+
}
|
|
1035
|
+
return `${parts[0]}/${parts[1]}`;
|
|
1036
|
+
}
|
|
1037
|
+
function githubRepositoryFromRemote(remote) {
|
|
1038
|
+
if ([...remote].some((char) => char < " " || char === "\x7F")) return null;
|
|
879
1039
|
const match = /^(?:git@github\.com:([^?#]+)|(?:https|ssh):\/\/(?:[^/@]+@)?github\.com(?::\d+)?\/([^?#]+))$/i.exec(
|
|
880
1040
|
remote
|
|
881
1041
|
);
|
|
882
1042
|
const path = match?.[1] ?? match?.[2];
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
1043
|
+
return path ? parseGithubRepositoryName(path) : null;
|
|
1044
|
+
}
|
|
1045
|
+
function checkoutSettingsText(repoRoot) {
|
|
1046
|
+
const path = join12(repoRoot, ".claude", "settings.json");
|
|
1047
|
+
try {
|
|
1048
|
+
if (!lstatSync5(join12(repoRoot, ".claude")).isDirectory()) return null;
|
|
1049
|
+
const stat = lstatSync5(path);
|
|
1050
|
+
if (!stat.isFile() || stat.size > MAX_SETTINGS_BYTES) return null;
|
|
1051
|
+
return readFileSync10(path, "utf8");
|
|
1052
|
+
} catch {
|
|
886
1053
|
return null;
|
|
887
1054
|
}
|
|
888
|
-
|
|
1055
|
+
}
|
|
1056
|
+
function checkoutDeclaration(repoRoot, name) {
|
|
1057
|
+
const text = checkoutSettingsText(repoRoot);
|
|
1058
|
+
if (text === null) return null;
|
|
1059
|
+
let parsed;
|
|
1060
|
+
try {
|
|
1061
|
+
parsed = JSON.parse(text);
|
|
1062
|
+
} catch {
|
|
1063
|
+
return null;
|
|
1064
|
+
}
|
|
1065
|
+
const env = typeof parsed === "object" && parsed !== null ? parsed.env : void 0;
|
|
1066
|
+
const value = typeof env === "object" && env !== null ? env[name] : void 0;
|
|
1067
|
+
return typeof value === "string" ? value : null;
|
|
1068
|
+
}
|
|
1069
|
+
function declaredGithubRepository(repoRoot) {
|
|
1070
|
+
const value = checkoutDeclaration(repoRoot, "PRIM_REPOSITORY");
|
|
1071
|
+
return value === null ? null : parseGithubRepositoryName(value.trim());
|
|
1072
|
+
}
|
|
1073
|
+
function githubRepositoryFullName(cwd) {
|
|
1074
|
+
const remote = gitValue(cwd, ["config", "--get", "remote.origin.url"]);
|
|
1075
|
+
if (remote) {
|
|
1076
|
+
const fromOrigin = githubRepositoryFromRemote(remote);
|
|
1077
|
+
if (fromOrigin || normalizeOriginRemote(remote)) return fromOrigin;
|
|
1078
|
+
}
|
|
1079
|
+
const root = gitToplevel(cwd);
|
|
1080
|
+
return root ? declaredGithubRepository(root) : null;
|
|
1081
|
+
}
|
|
1082
|
+
function normalizeOriginRemote(remote) {
|
|
1083
|
+
const value = remote.trim();
|
|
1084
|
+
if (!value) return void 0;
|
|
1085
|
+
const scp = !value.includes("://") ? /^(?:[^@/\s]+@)?(?<host>[^:/\s]+):(?<path>.+)$/.exec(value)?.groups : void 0;
|
|
1086
|
+
if (scp?.host && scp.path) {
|
|
1087
|
+
const path = scp.path.replace(/^\/+|\/+$/g, "").replace(/\.git$/i, "");
|
|
1088
|
+
return path ? `${scp.host.toLowerCase()}/${path}` : void 0;
|
|
1089
|
+
}
|
|
1090
|
+
try {
|
|
1091
|
+
const url = new URL(value);
|
|
1092
|
+
url.username = "";
|
|
1093
|
+
url.password = "";
|
|
1094
|
+
url.search = "";
|
|
1095
|
+
url.hash = "";
|
|
1096
|
+
const path = url.pathname.replace(/^\/+|\/+$/g, "").replace(/\.git$/i, "");
|
|
1097
|
+
if (url.host && path) return `${url.host.toLowerCase()}/${path}`;
|
|
1098
|
+
return void 0;
|
|
1099
|
+
} catch {
|
|
1100
|
+
return void 0;
|
|
1101
|
+
}
|
|
889
1102
|
}
|
|
890
1103
|
|
|
891
1104
|
// src/lib/activation.ts
|
|
892
1105
|
var PRIM_ACTIVE_KEY = "prim.active";
|
|
1106
|
+
var PRIM_ACTIVE_DECLARATION = "PRIM_ACTIVE";
|
|
893
1107
|
var PRIM_REPO_SYNC_ID_KEY = "prim.repoSyncId";
|
|
894
1108
|
var PRIM_REPO_SYNC_REPOSITORY_KEY = "prim.repoSyncRepository";
|
|
895
1109
|
var PRIM_REPO_BINDING_STATE_KEY = "prim.repoBindingState";
|
|
@@ -946,14 +1160,13 @@ function repositoryBindingState(cwd) {
|
|
|
946
1160
|
if (marker !== void 0) return "invalid";
|
|
947
1161
|
return rawId === void 0 ? "unbound" : repoSyncId(cwd) ? void 0 : "unbound";
|
|
948
1162
|
}
|
|
949
|
-
function
|
|
950
|
-
const root = gitToplevel(cwd);
|
|
1163
|
+
function projectPrimInstallAt(root) {
|
|
951
1164
|
if (root === null || root === homedir2()) return false;
|
|
952
1165
|
for (const rel of PROJECT_INSTALL_FILES) {
|
|
953
|
-
const path =
|
|
954
|
-
if (
|
|
1166
|
+
const path = join13(root, rel);
|
|
1167
|
+
if (existsSync6(path)) {
|
|
955
1168
|
try {
|
|
956
|
-
const content =
|
|
1169
|
+
const content = readFileSync11(path, "utf-8");
|
|
957
1170
|
if (PRIM_HOOK_BINS.some((bin) => content.includes(bin))) return true;
|
|
958
1171
|
} catch {
|
|
959
1172
|
}
|
|
@@ -961,12 +1174,27 @@ function hasProjectPrimInstall(cwd) {
|
|
|
961
1174
|
}
|
|
962
1175
|
return false;
|
|
963
1176
|
}
|
|
1177
|
+
var UNPARSED_OPT_OUT = /"PRIM_ACTIVE"\s*:\s*"\s*false\s*"/u;
|
|
1178
|
+
function declaresInactiveAt(root) {
|
|
1179
|
+
if (root === null || root === homedir2()) return false;
|
|
1180
|
+
if (checkoutDeclaration(root, PRIM_ACTIVE_DECLARATION)?.trim() === "false") return true;
|
|
1181
|
+
const text = checkoutSettingsText(root);
|
|
1182
|
+
if (text === null || !UNPARSED_OPT_OUT.test(text)) return false;
|
|
1183
|
+
try {
|
|
1184
|
+
JSON.parse(text);
|
|
1185
|
+
return false;
|
|
1186
|
+
} catch {
|
|
1187
|
+
return true;
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
964
1190
|
function isRepoActiveForCapture(cwd, options = {}) {
|
|
965
1191
|
let { active: flag, pause } = readCaptureConfig(cwd);
|
|
966
1192
|
if (pause && healDemoPause(cwd, pause, options)) flag = repoActiveFlag(cwd);
|
|
967
1193
|
if (flag === "true") return true;
|
|
968
1194
|
if (flag === "false") return false;
|
|
969
|
-
|
|
1195
|
+
const root = gitToplevel(cwd);
|
|
1196
|
+
if (declaresInactiveAt(root)) return false;
|
|
1197
|
+
return projectPrimInstallAt(root) || isPreparedCloudSession() && root !== null;
|
|
970
1198
|
}
|
|
971
1199
|
function decisionIngestionStatus(cwd) {
|
|
972
1200
|
return isRepoActiveForCapture(cwd) ? "enabled" : "disabled";
|
|
@@ -1111,7 +1339,7 @@ function readPackageVersion() {
|
|
|
1111
1339
|
];
|
|
1112
1340
|
for (const path of candidates) {
|
|
1113
1341
|
try {
|
|
1114
|
-
const pkg = JSON.parse(
|
|
1342
|
+
const pkg = JSON.parse(readFileSync12(path, "utf-8"));
|
|
1115
1343
|
if (pkg.version) {
|
|
1116
1344
|
return pkg.version;
|
|
1117
1345
|
}
|
package/package.json
CHANGED