@primitive.ai/prim 0.1.0-alpha.101 → 0.1.0-alpha.103
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 +16 -0
- package/SKILL.md +49 -0
- package/dist/chunk-6WCBVSND.js +107 -0
- package/dist/{chunk-MXVCP33E.js → chunk-LNFWFYSN.js} +60 -0
- package/dist/{chunk-QIHXTYRD.js → chunk-RCFDZ4DY.js} +1 -1
- package/dist/hook-runtime/hooks/post-tool-use.js +497 -358
- package/dist/hook-runtime/hooks/pre-tool-use.js +214 -74
- package/dist/hook-runtime/hooks/prim-hook.js +260 -123
- package/dist/hook-runtime/index.js +2000 -1412
- package/dist/hooks/post-tool-use.js +9 -2
- package/dist/hooks/pre-tool-use.js +10 -1
- package/dist/hooks/prim-hook.js +9 -2
- package/dist/index.js +611 -80
- package/package.json +1 -1
|
@@ -544,14 +544,14 @@ function throwIfAborted(signal) {
|
|
|
544
544
|
}
|
|
545
545
|
async function defaultSleep(ms, signal) {
|
|
546
546
|
if (!signal) {
|
|
547
|
-
await new Promise((
|
|
547
|
+
await new Promise((resolve6) => setTimeout(resolve6, ms));
|
|
548
548
|
return;
|
|
549
549
|
}
|
|
550
550
|
throwIfAborted(signal);
|
|
551
|
-
await new Promise((
|
|
551
|
+
await new Promise((resolve6, reject) => {
|
|
552
552
|
const timer = setTimeout(() => {
|
|
553
553
|
signal.removeEventListener("abort", onAbort);
|
|
554
|
-
|
|
554
|
+
resolve6();
|
|
555
555
|
}, ms);
|
|
556
556
|
const onAbort = () => {
|
|
557
557
|
clearTimeout(timer);
|
|
@@ -561,6 +561,33 @@ async function defaultSleep(ms, signal) {
|
|
|
561
561
|
});
|
|
562
562
|
}
|
|
563
563
|
var syncSleeper = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT));
|
|
564
|
+
function defaultSleepSync(ms) {
|
|
565
|
+
Atomics.wait(syncSleeper, 0, 0, ms);
|
|
566
|
+
}
|
|
567
|
+
function withFileLockSync(lockDir, operation, options = {}) {
|
|
568
|
+
mkdirSync2(dirname2(lockDir), { recursive: true, mode: DIRECTORY_MODE });
|
|
569
|
+
const nowMs = options.nowMs ?? Date.now;
|
|
570
|
+
const alive = options.processAlive ?? processIsAlive;
|
|
571
|
+
const deadline = nowMs() + (options.timeoutMs ?? DEFAULT_TIMEOUT_MS);
|
|
572
|
+
let owner = null;
|
|
573
|
+
while (!owner) {
|
|
574
|
+
const now = nowMs();
|
|
575
|
+
owner = tryTakeLock(lockDir, now);
|
|
576
|
+
if (owner) break;
|
|
577
|
+
recoverStaleLock(lockDir, now, alive, options.initGraceMs ?? DEFAULT_INIT_GRACE_MS);
|
|
578
|
+
if (now >= deadline) {
|
|
579
|
+
throw new Error(`timed out waiting for file lock ${lockDir}`);
|
|
580
|
+
}
|
|
581
|
+
(options.sleep ?? defaultSleepSync)(options.pollMs ?? DEFAULT_POLL_MS);
|
|
582
|
+
}
|
|
583
|
+
try {
|
|
584
|
+
return operation();
|
|
585
|
+
} finally {
|
|
586
|
+
if (sameOwner(readOwner(lockDir), owner)) {
|
|
587
|
+
rmSync2(lockDir, { recursive: true, force: true });
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
}
|
|
564
591
|
async function withFileLock(lockDir, operation, options = {}) {
|
|
565
592
|
mkdirSync2(dirname2(lockDir), { recursive: true, mode: DIRECTORY_MODE });
|
|
566
593
|
const nowMs = options.nowMs ?? Date.now;
|
|
@@ -1254,17 +1281,123 @@ function getClient() {
|
|
|
1254
1281
|
};
|
|
1255
1282
|
}
|
|
1256
1283
|
|
|
1284
|
+
// src/demo/isolation.ts
|
|
1285
|
+
import { existsSync as existsSync5 } from "fs";
|
|
1286
|
+
|
|
1287
|
+
// src/demo/state.ts
|
|
1288
|
+
import { createHash as createHash3, randomUUID as randomUUID2 } from "crypto";
|
|
1289
|
+
import { existsSync as existsSync4, lstatSync as lstatSync2, readFileSync as readFileSync6, readdirSync } from "fs";
|
|
1290
|
+
import { join as join7, resolve as resolve2 } from "path";
|
|
1291
|
+
var RUN_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/u;
|
|
1292
|
+
var demoDirectory = () => join7(primConfigDirectory(), "demo");
|
|
1293
|
+
var runPath = (id) => {
|
|
1294
|
+
if (!RUN_ID.test(id)) throw new Error("invalid demo run ID");
|
|
1295
|
+
return join7(demoDirectory(), "runs", `${id}.json`);
|
|
1296
|
+
};
|
|
1297
|
+
function readDemoJson(path) {
|
|
1298
|
+
const stat = lstatSync2(path);
|
|
1299
|
+
if (!stat.isFile() || stat.size > 16384) throw new Error(`invalid demo state: ${path}`);
|
|
1300
|
+
return JSON.parse(readFileSync6(path, "utf8"));
|
|
1301
|
+
}
|
|
1302
|
+
function saveDemoJson(path, value) {
|
|
1303
|
+
atomicWriteFile(path, `${JSON.stringify(value)}
|
|
1304
|
+
`, { mode: 384, ensureParent: true });
|
|
1305
|
+
}
|
|
1306
|
+
function readRun(id) {
|
|
1307
|
+
const run = readDemoJson(runPath(id));
|
|
1308
|
+
if (run.version !== 1 || run.id !== id || !["prepared", "proposal", "conflict", "completed", "skipped"].includes(run.stage) || typeof run.terminal !== "boolean" || !Array.isArray(run.launcher) || run.launcher.length !== 2 || run.launcher.some((value) => typeof value !== "string" || !value.startsWith("/")) || run.agent !== void 0 && !["claude_code", "codex", "cursor", "hermes"].includes(run.agent)) {
|
|
1309
|
+
throw new Error("invalid demo run state");
|
|
1310
|
+
}
|
|
1311
|
+
return run;
|
|
1312
|
+
}
|
|
1313
|
+
var saveRun = (run) => saveDemoJson(runPath(run.id), run);
|
|
1314
|
+
var lockRun = (id, action) => withFileLockSync(`${runPath(id)}.lock`, () => action(readRun(id)), { timeoutMs: 500 });
|
|
1315
|
+
var quote = (value) => `'${value.replaceAll("'", "'\\''")}'`;
|
|
1316
|
+
function demoCommand(run, action, choice) {
|
|
1317
|
+
return [
|
|
1318
|
+
...run.launcher,
|
|
1319
|
+
"demo",
|
|
1320
|
+
action,
|
|
1321
|
+
run.id,
|
|
1322
|
+
...choice === void 0 ? [] : ["--choice", choice]
|
|
1323
|
+
].map(quote).join(" ");
|
|
1324
|
+
}
|
|
1325
|
+
function sessionKey(agent2, session) {
|
|
1326
|
+
return createHash3("sha256").update(`${agent2}\0${session}`).digest("hex");
|
|
1327
|
+
}
|
|
1328
|
+
function exclusionPath(key) {
|
|
1329
|
+
if (!/^[0-9a-f]{64}$/u.test(key)) throw new Error("invalid demo session identity");
|
|
1330
|
+
return join7(demoDirectory(), "excluded-sessions", `${key}.json`);
|
|
1331
|
+
}
|
|
1332
|
+
function sessionExcluded(agent2, session) {
|
|
1333
|
+
if (typeof session !== "string" || !session) return false;
|
|
1334
|
+
const path = exclusionPath(sessionKey(agent2, session));
|
|
1335
|
+
if (!existsSync4(path)) return false;
|
|
1336
|
+
const record = readDemoJson(path);
|
|
1337
|
+
if (typeof record.runId !== "string" || !RUN_ID.test(record.runId)) {
|
|
1338
|
+
throw new Error("invalid demo capture exclusion");
|
|
1339
|
+
}
|
|
1340
|
+
return true;
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
// src/demo/isolation.ts
|
|
1344
|
+
function observeDemoInvocation(envelope, agent2, checkExclusion = true) {
|
|
1345
|
+
const session = typeof envelope.session_id === "string" && envelope.session_id ? envelope.session_id : agent2 === "hermes" ? envelope.extra?.session_key : void 0;
|
|
1346
|
+
let invocation = false;
|
|
1347
|
+
if (envelope.hook_event_name === "PreToolUse" && typeof session === "string" && session) {
|
|
1348
|
+
const tool = agent2 === "cursor" ? "Shell" : agent2 === "hermes" ? "terminal" : "Bash";
|
|
1349
|
+
const input = envelope.tool_input;
|
|
1350
|
+
const command = input?.command;
|
|
1351
|
+
if (envelope.tool_name === tool && typeof command === "string" && command.length < 8192) {
|
|
1352
|
+
const ids = command.match(
|
|
1353
|
+
/[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/gu
|
|
1354
|
+
);
|
|
1355
|
+
if (ids?.length === 1 && existsSync5(runPath(ids[0]))) {
|
|
1356
|
+
invocation = lockRun(ids[0], (run) => {
|
|
1357
|
+
const actions = [
|
|
1358
|
+
["start"],
|
|
1359
|
+
["confirm"],
|
|
1360
|
+
["resolve", "repository"],
|
|
1361
|
+
["resolve", "local-storage"],
|
|
1362
|
+
["skip"]
|
|
1363
|
+
];
|
|
1364
|
+
const match = actions.find(
|
|
1365
|
+
([action, choice]) => demoCommand(run, action, choice) === command
|
|
1366
|
+
);
|
|
1367
|
+
if (run.terminal || !match) {
|
|
1368
|
+
return false;
|
|
1369
|
+
}
|
|
1370
|
+
if (match[0] === "skip") return true;
|
|
1371
|
+
const key = sessionKey(agent2, session);
|
|
1372
|
+
if (run.agent && run.agent !== agent2 || run.binding && run.binding !== key) {
|
|
1373
|
+
run.acknowledgment = void 0;
|
|
1374
|
+
saveRun(run);
|
|
1375
|
+
return false;
|
|
1376
|
+
}
|
|
1377
|
+
saveDemoJson(exclusionPath(key), { runId: run.id });
|
|
1378
|
+
run.binding = key;
|
|
1379
|
+
run.agent = agent2;
|
|
1380
|
+
run.acknowledgment = { command, at: Date.now() };
|
|
1381
|
+
saveRun(run);
|
|
1382
|
+
return true;
|
|
1383
|
+
});
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
return { invocation, excluded: checkExclusion && sessionExcluded(agent2, session) };
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1257
1390
|
// src/lib/activation.ts
|
|
1258
1391
|
import { execFileSync as execFileSync2 } from "child_process";
|
|
1259
|
-
import { existsSync as
|
|
1392
|
+
import { existsSync as existsSync6, readFileSync as readFileSync7 } from "fs";
|
|
1260
1393
|
import { homedir as homedir2 } from "os";
|
|
1261
|
-
import { join as
|
|
1394
|
+
import { join as join8 } from "path";
|
|
1262
1395
|
|
|
1263
1396
|
// src/lib/git.ts
|
|
1264
1397
|
import { execFileSync } from "child_process";
|
|
1265
|
-
import { createHash as
|
|
1266
|
-
import { lstatSync as
|
|
1267
|
-
import { basename, dirname as dirname5, isAbsolute as isAbsolute3, relative, resolve as
|
|
1398
|
+
import { createHash as createHash4 } from "crypto";
|
|
1399
|
+
import { lstatSync as lstatSync3, realpathSync } from "fs";
|
|
1400
|
+
import { basename, dirname as dirname5, isAbsolute as isAbsolute3, relative, resolve as resolve3, sep } from "path";
|
|
1268
1401
|
var GIT_TIMEOUT_MS = 1e3;
|
|
1269
1402
|
var GITHUB_OWNER_PATTERN = /^(?![A-Za-z0-9-]*--)[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/u;
|
|
1270
1403
|
var GITHUB_REPOSITORY_PATTERN = /^[A-Za-z0-9._-]{1,100}$/u;
|
|
@@ -1340,7 +1473,7 @@ function normalizeOriginRemote(remote) {
|
|
|
1340
1473
|
}
|
|
1341
1474
|
}
|
|
1342
1475
|
function opaqueRepoKey(source, value) {
|
|
1343
|
-
return `repo_v1_${
|
|
1476
|
+
return `repo_v1_${createHash4("sha256").update(`${source}\0${value}`).digest("hex")}`;
|
|
1344
1477
|
}
|
|
1345
1478
|
function resolveRepositoryContext(cwd = process.cwd()) {
|
|
1346
1479
|
const top = gitToplevel(cwd);
|
|
@@ -1349,7 +1482,7 @@ function resolveRepositoryContext(cwd = process.cwd()) {
|
|
|
1349
1482
|
try {
|
|
1350
1483
|
repoRoot = realpathSync.native(top);
|
|
1351
1484
|
} catch {
|
|
1352
|
-
repoRoot =
|
|
1485
|
+
repoRoot = resolve3(top);
|
|
1353
1486
|
}
|
|
1354
1487
|
const origin = gitValue(repoRoot, ["config", "--get", "remote.origin.url"]);
|
|
1355
1488
|
const repoFullName = githubRepositoryFullName(repoRoot) ?? void 0;
|
|
@@ -1378,7 +1511,7 @@ function nearestExistingAncestor(path) {
|
|
|
1378
1511
|
let cursor = path;
|
|
1379
1512
|
while (true) {
|
|
1380
1513
|
try {
|
|
1381
|
-
|
|
1514
|
+
lstatSync3(cursor);
|
|
1382
1515
|
break;
|
|
1383
1516
|
} catch (error) {
|
|
1384
1517
|
const code = typeof error === "object" && error !== null && "code" in error ? error.code : void 0;
|
|
@@ -1399,10 +1532,10 @@ function canonicalRepositoryPathScoped(filePath, context, baseDir) {
|
|
|
1399
1532
|
if (!filePath || filePath !== filePath.trim() || filePath.includes("\0")) {
|
|
1400
1533
|
return { ok: false, reason: "invalid_path" };
|
|
1401
1534
|
}
|
|
1402
|
-
const absolute =
|
|
1535
|
+
const absolute = resolve3(baseDir, filePath);
|
|
1403
1536
|
const resolved = nearestExistingAncestor(absolute);
|
|
1404
1537
|
if (!resolved) return { ok: false, reason: "invalid_path" };
|
|
1405
|
-
const target =
|
|
1538
|
+
const target = resolve3(resolved.real, ...resolved.suffix);
|
|
1406
1539
|
const rel = relative(context.repoRoot, target);
|
|
1407
1540
|
if (!rel || rel === ".") return { ok: false, reason: "invalid_path" };
|
|
1408
1541
|
if (isAbsolute3(rel) || rel === ".." || rel.startsWith(`..${sep}`)) {
|
|
@@ -1413,10 +1546,10 @@ function canonicalRepositoryPathScoped(filePath, context, baseDir) {
|
|
|
1413
1546
|
function canonicalRepositoryPathLegacy(filePath, cwd, repositoryRoot = canonicalGitRoot(cwd)) {
|
|
1414
1547
|
if (!repositoryRoot || !filePath || [...filePath].some((char) => char < " " || char === "\x7F" || "~*?[]{}$`\\".includes(char)))
|
|
1415
1548
|
return null;
|
|
1416
|
-
const absolute =
|
|
1549
|
+
const absolute = resolve3(cwd, filePath);
|
|
1417
1550
|
let target;
|
|
1418
1551
|
try {
|
|
1419
|
-
const stat =
|
|
1552
|
+
const stat = lstatSync3(absolute);
|
|
1420
1553
|
if (!stat.isFile() || stat.isSymbolicLink()) return null;
|
|
1421
1554
|
target = realpathSync.native(absolute);
|
|
1422
1555
|
} catch (error) {
|
|
@@ -1425,8 +1558,8 @@ function canonicalRepositoryPathLegacy(filePath, cwd, repositoryRoot = canonical
|
|
|
1425
1558
|
}
|
|
1426
1559
|
try {
|
|
1427
1560
|
const parent = realpathSync.native(dirname5(absolute));
|
|
1428
|
-
if (!
|
|
1429
|
-
target =
|
|
1561
|
+
if (!lstatSync3(parent).isDirectory()) return null;
|
|
1562
|
+
target = resolve3(parent, basename(absolute));
|
|
1430
1563
|
} catch {
|
|
1431
1564
|
return null;
|
|
1432
1565
|
}
|
|
@@ -1510,10 +1643,10 @@ function hasProjectPrimInstall(cwd) {
|
|
|
1510
1643
|
const root = gitToplevel(cwd);
|
|
1511
1644
|
if (root === null || root === homedir2()) return false;
|
|
1512
1645
|
for (const rel of PROJECT_INSTALL_FILES) {
|
|
1513
|
-
const path =
|
|
1514
|
-
if (
|
|
1646
|
+
const path = join8(root, rel);
|
|
1647
|
+
if (existsSync6(path)) {
|
|
1515
1648
|
try {
|
|
1516
|
-
const content =
|
|
1649
|
+
const content = readFileSync7(path, "utf-8");
|
|
1517
1650
|
if (PRIM_HOOK_BINS.some((bin) => content.includes(bin))) return true;
|
|
1518
1651
|
} catch {
|
|
1519
1652
|
}
|
|
@@ -20299,33 +20432,33 @@ function parseAgent(argv) {
|
|
|
20299
20432
|
}
|
|
20300
20433
|
|
|
20301
20434
|
// src/hooks/codex-context.ts
|
|
20302
|
-
import { createHash as
|
|
20435
|
+
import { createHash as createHash6, randomBytes as randomBytes4 } from "crypto";
|
|
20303
20436
|
import {
|
|
20304
20437
|
chmodSync as chmodSync3,
|
|
20305
|
-
existsSync as
|
|
20438
|
+
existsSync as existsSync7,
|
|
20306
20439
|
mkdirSync as mkdirSync4,
|
|
20307
|
-
readFileSync as
|
|
20308
|
-
readdirSync,
|
|
20440
|
+
readFileSync as readFileSync8,
|
|
20441
|
+
readdirSync as readdirSync2,
|
|
20309
20442
|
renameSync as renameSync2,
|
|
20310
20443
|
rmSync as rmSync4,
|
|
20311
20444
|
statSync as statSync2,
|
|
20312
20445
|
unlinkSync,
|
|
20313
20446
|
writeFileSync as writeFileSync3
|
|
20314
20447
|
} from "fs";
|
|
20315
|
-
import { join as
|
|
20448
|
+
import { join as join10 } from "path";
|
|
20316
20449
|
|
|
20317
20450
|
// src/daemon/client.ts
|
|
20318
20451
|
import { createConnection } from "net";
|
|
20319
|
-
import { join as
|
|
20452
|
+
import { join as join9 } from "path";
|
|
20320
20453
|
|
|
20321
20454
|
// src/daemon/principal.ts
|
|
20322
|
-
import { createHash as
|
|
20455
|
+
import { createHash as createHash5 } from "crypto";
|
|
20323
20456
|
var PRINCIPAL_COMPONENT_MAX_LENGTH = 512;
|
|
20324
20457
|
function boundedClaim(value) {
|
|
20325
20458
|
return typeof value === "string" && value.length > 0 && value.length <= PRINCIPAL_COMPONENT_MAX_LENGTH ? value : void 0;
|
|
20326
20459
|
}
|
|
20327
20460
|
function sha256(value) {
|
|
20328
|
-
return
|
|
20461
|
+
return createHash5("sha256").update(value).digest("hex");
|
|
20329
20462
|
}
|
|
20330
20463
|
function resolveDaemonPrincipal(token = resolveAuthCredential()?.token) {
|
|
20331
20464
|
if (!token) return void 0;
|
|
@@ -20366,7 +20499,7 @@ function parseDaemonResponseEnvelope(value) {
|
|
|
20366
20499
|
}
|
|
20367
20500
|
|
|
20368
20501
|
// src/daemon/client.ts
|
|
20369
|
-
var SOCK_PATH =
|
|
20502
|
+
var SOCK_PATH = join9(primConfigDirectory(), "sock");
|
|
20370
20503
|
var DEFAULT_TIMEOUT_MS2 = 250;
|
|
20371
20504
|
var nextRequestId = 1;
|
|
20372
20505
|
function daemonRequest(method, params = {}, opts = {}) {
|
|
@@ -20379,7 +20512,7 @@ function daemonRequest(method, params = {}, opts = {}) {
|
|
|
20379
20512
|
...caller ? { caller } : {}
|
|
20380
20513
|
};
|
|
20381
20514
|
const timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS2;
|
|
20382
|
-
return new Promise((
|
|
20515
|
+
return new Promise((resolve6) => {
|
|
20383
20516
|
let settled = false;
|
|
20384
20517
|
let socket;
|
|
20385
20518
|
let buffer = Buffer.alloc(0);
|
|
@@ -20394,7 +20527,7 @@ function daemonRequest(method, params = {}, opts = {}) {
|
|
|
20394
20527
|
} catch {
|
|
20395
20528
|
}
|
|
20396
20529
|
}
|
|
20397
|
-
|
|
20530
|
+
resolve6(value);
|
|
20398
20531
|
};
|
|
20399
20532
|
const timer = setTimeout(() => settle(null), timeoutMs);
|
|
20400
20533
|
timer.unref();
|
|
@@ -20643,10 +20776,10 @@ function appendCodexContext(output, context) {
|
|
|
20643
20776
|
return next;
|
|
20644
20777
|
}
|
|
20645
20778
|
function stateRoot(namespace) {
|
|
20646
|
-
return
|
|
20779
|
+
return join10(primConfigDirectory(), namespace, "decision-digests");
|
|
20647
20780
|
}
|
|
20648
20781
|
function draftStateRoot(namespace) {
|
|
20649
|
-
return
|
|
20782
|
+
return join10(primConfigDirectory(), namespace, "decision-draft-deliveries");
|
|
20650
20783
|
}
|
|
20651
20784
|
function workspaceFor(cwd) {
|
|
20652
20785
|
try {
|
|
@@ -20657,13 +20790,13 @@ function workspaceFor(cwd) {
|
|
|
20657
20790
|
}
|
|
20658
20791
|
function statePath(args) {
|
|
20659
20792
|
const identity = `${args.siteUrl}\0${workspaceFor(args.cwd)}\0${args.sessionId}`;
|
|
20660
|
-
const key =
|
|
20661
|
-
return
|
|
20793
|
+
const key = createHash6("sha256").update(identity).digest("hex");
|
|
20794
|
+
return join10(stateRoot(args.namespace), `${key}.json`);
|
|
20662
20795
|
}
|
|
20663
20796
|
function draftStatePath(args) {
|
|
20664
20797
|
const identity = `${args.siteUrl}\0${workspaceFor(args.cwd)}\0${args.sessionId}\0${args.principalId}\0${args.organizationId}\0${args.credentialFingerprint}`;
|
|
20665
|
-
const key =
|
|
20666
|
-
return
|
|
20798
|
+
const key = createHash6("sha256").update(identity).digest("hex");
|
|
20799
|
+
return join10(draftStateRoot(args.namespace), `${key}.json`);
|
|
20667
20800
|
}
|
|
20668
20801
|
function parseState(value) {
|
|
20669
20802
|
if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
|
|
@@ -20702,17 +20835,17 @@ function parseDraftState(value) {
|
|
|
20702
20835
|
};
|
|
20703
20836
|
}
|
|
20704
20837
|
function readState(path) {
|
|
20705
|
-
if (!
|
|
20838
|
+
if (!existsSync7(path)) return void 0;
|
|
20706
20839
|
try {
|
|
20707
|
-
return parseState(JSON.parse(
|
|
20840
|
+
return parseState(JSON.parse(readFileSync8(path, "utf8")));
|
|
20708
20841
|
} catch {
|
|
20709
20842
|
return void 0;
|
|
20710
20843
|
}
|
|
20711
20844
|
}
|
|
20712
20845
|
function readDraftState(path) {
|
|
20713
|
-
if (!
|
|
20846
|
+
if (!existsSync7(path)) return void 0;
|
|
20714
20847
|
try {
|
|
20715
|
-
return parseDraftState(JSON.parse(
|
|
20848
|
+
return parseDraftState(JSON.parse(readFileSync8(path, "utf8")));
|
|
20716
20849
|
} catch {
|
|
20717
20850
|
return void 0;
|
|
20718
20851
|
}
|
|
@@ -20720,7 +20853,7 @@ function readDraftState(path) {
|
|
|
20720
20853
|
function writeStateFile(path, directory, state) {
|
|
20721
20854
|
mkdirSync4(directory, { recursive: true, mode: 448 });
|
|
20722
20855
|
chmodSync3(directory, 448);
|
|
20723
|
-
const temporary =
|
|
20856
|
+
const temporary = join10(
|
|
20724
20857
|
directory,
|
|
20725
20858
|
`.${path.slice(directory.length + 1)}.tmp-${process.pid}-${randomBytes4(8).toString("hex")}`
|
|
20726
20859
|
);
|
|
@@ -20741,17 +20874,17 @@ function writeStateFile(path, directory, state) {
|
|
|
20741
20874
|
}
|
|
20742
20875
|
}
|
|
20743
20876
|
function cleanupStateFiles(directory, now) {
|
|
20744
|
-
if (!
|
|
20877
|
+
if (!existsSync7(directory)) return;
|
|
20745
20878
|
let names;
|
|
20746
20879
|
try {
|
|
20747
|
-
names =
|
|
20880
|
+
names = readdirSync2(directory);
|
|
20748
20881
|
} catch {
|
|
20749
20882
|
return;
|
|
20750
20883
|
}
|
|
20751
20884
|
const files = [];
|
|
20752
20885
|
const residue = [];
|
|
20753
20886
|
for (const name of names) {
|
|
20754
|
-
const path =
|
|
20887
|
+
const path = join10(directory, name);
|
|
20755
20888
|
try {
|
|
20756
20889
|
const mtimeMs = statSync2(path).mtimeMs;
|
|
20757
20890
|
if (name.endsWith(".json")) {
|
|
@@ -21056,23 +21189,23 @@ async function prepareCodexContext(options) {
|
|
|
21056
21189
|
}
|
|
21057
21190
|
|
|
21058
21191
|
// src/commands/cursor-install.ts
|
|
21059
|
-
import { existsSync as
|
|
21192
|
+
import { existsSync as existsSync10, readFileSync as readFileSync11 } from "fs";
|
|
21060
21193
|
import { homedir as homedir4 } from "os";
|
|
21061
|
-
import { isAbsolute as isAbsolute5, join as
|
|
21194
|
+
import { isAbsolute as isAbsolute5, join as join13 } from "path";
|
|
21062
21195
|
|
|
21063
21196
|
// src/lib/hook-runtime.ts
|
|
21064
|
-
import { createHash as
|
|
21197
|
+
import { createHash as createHash7, randomBytes as randomBytes5 } from "crypto";
|
|
21065
21198
|
import {
|
|
21066
21199
|
constants as constants2,
|
|
21067
21200
|
accessSync,
|
|
21068
21201
|
chmodSync as chmodSync4,
|
|
21069
21202
|
copyFileSync,
|
|
21070
|
-
existsSync as
|
|
21071
|
-
lstatSync as
|
|
21203
|
+
existsSync as existsSync8,
|
|
21204
|
+
lstatSync as lstatSync4,
|
|
21072
21205
|
mkdirSync as mkdirSync5,
|
|
21073
21206
|
mkdtempSync,
|
|
21074
|
-
readFileSync as
|
|
21075
|
-
readdirSync as
|
|
21207
|
+
readFileSync as readFileSync9,
|
|
21208
|
+
readdirSync as readdirSync3,
|
|
21076
21209
|
realpathSync as realpathSync2,
|
|
21077
21210
|
renameSync as renameSync3,
|
|
21078
21211
|
rmSync as rmSync5,
|
|
@@ -21080,7 +21213,7 @@ import {
|
|
|
21080
21213
|
utimesSync,
|
|
21081
21214
|
writeFileSync as writeFileSync4
|
|
21082
21215
|
} from "fs";
|
|
21083
|
-
import { delimiter, dirname as dirname6, isAbsolute as isAbsolute4, join as
|
|
21216
|
+
import { delimiter, dirname as dirname6, isAbsolute as isAbsolute4, join as join11, resolve as resolve4 } from "path";
|
|
21084
21217
|
|
|
21085
21218
|
// src/lib/git-hook-contract.ts
|
|
21086
21219
|
var GIT_HOOK_ENTRYPOINT_CONTENT = `#!/bin/sh
|
|
@@ -21173,9 +21306,9 @@ exec "$prim_node" "$prim_entry" "$@"
|
|
|
21173
21306
|
`;
|
|
21174
21307
|
|
|
21175
21308
|
// src/commands/claude-install.ts
|
|
21176
|
-
import { existsSync as
|
|
21309
|
+
import { existsSync as existsSync9, readFileSync as readFileSync10 } from "fs";
|
|
21177
21310
|
import { homedir as homedir3 } from "os";
|
|
21178
|
-
import { join as
|
|
21311
|
+
import { join as join12 } from "path";
|
|
21179
21312
|
var CAPTURE_BIN = "prim-hook";
|
|
21180
21313
|
var GATE_BIN = "prim-pre-tool-use";
|
|
21181
21314
|
var POST_TOOL_USE_BIN = "prim-post-tool-use";
|
|
@@ -21184,7 +21317,7 @@ var SESSION_END_BIN = "prim-session-end";
|
|
|
21184
21317
|
var STATUSLINE_BIN = "prim-statusline";
|
|
21185
21318
|
var STATUSLINE_ARGS = "";
|
|
21186
21319
|
var STATUSLINE_COMMAND = stableHookCommand(STATUSLINE_BIN, STATUSLINE_ARGS);
|
|
21187
|
-
var USER_SCOPE_PATH =
|
|
21320
|
+
var USER_SCOPE_PATH = join12(homedir3(), ".claude", "settings.json");
|
|
21188
21321
|
function projectRoot() {
|
|
21189
21322
|
return gitToplevel() ?? process.cwd();
|
|
21190
21323
|
}
|
|
@@ -21263,20 +21396,20 @@ function cursorConfigDirectory(env = process.env, home = homedir4(), platform =
|
|
|
21263
21396
|
const explicit = env.CURSOR_CONFIG_DIR?.trim();
|
|
21264
21397
|
if (explicit && isAbsolute5(explicit)) return explicit;
|
|
21265
21398
|
const xdg = env.XDG_CONFIG_HOME?.trim();
|
|
21266
|
-
if (platform !== "darwin" && xdg && isAbsolute5(xdg)) return
|
|
21267
|
-
return
|
|
21399
|
+
if (platform !== "darwin" && xdg && isAbsolute5(xdg)) return join13(xdg, "cursor");
|
|
21400
|
+
return join13(home, ".cursor");
|
|
21268
21401
|
}
|
|
21269
21402
|
function cursorHooksPath(scope, root = projectRoot()) {
|
|
21270
|
-
return scope === "user" ?
|
|
21403
|
+
return scope === "user" ? join13(cursorConfigDirectory(), "hooks.json") : join13(root, ".cursor", "hooks.json");
|
|
21271
21404
|
}
|
|
21272
21405
|
function plainObject(value) {
|
|
21273
21406
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21274
21407
|
}
|
|
21275
21408
|
function readCursorHooks(path) {
|
|
21276
|
-
if (!
|
|
21409
|
+
if (!existsSync10(path)) return {};
|
|
21277
21410
|
let parsed;
|
|
21278
21411
|
try {
|
|
21279
|
-
parsed = JSON.parse(
|
|
21412
|
+
parsed = JSON.parse(readFileSync11(path, "utf8"));
|
|
21280
21413
|
} catch {
|
|
21281
21414
|
throw new Error(`invalid Cursor hooks JSON at ${path}`);
|
|
21282
21415
|
}
|
|
@@ -21389,7 +21522,7 @@ function shouldSuppressImportedCursorHandler(parsed, bin) {
|
|
|
21389
21522
|
// src/hooks/hook-stdin.ts
|
|
21390
21523
|
var DEFAULT_MAX_BYTES = 1024 * 1024;
|
|
21391
21524
|
function readHookStdin(timeoutMs = 1e3, maxBytes = DEFAULT_MAX_BYTES) {
|
|
21392
|
-
return new Promise((
|
|
21525
|
+
return new Promise((resolve6, reject) => {
|
|
21393
21526
|
const chunks = [];
|
|
21394
21527
|
let bytes = 0;
|
|
21395
21528
|
let settled = false;
|
|
@@ -21401,7 +21534,7 @@ function readHookStdin(timeoutMs = 1e3, maxBytes = DEFAULT_MAX_BYTES) {
|
|
|
21401
21534
|
process.stdin.removeAllListeners("end");
|
|
21402
21535
|
process.stdin.removeAllListeners("error");
|
|
21403
21536
|
if (error) reject(error);
|
|
21404
|
-
else
|
|
21537
|
+
else resolve6(Buffer.concat(chunks, bytes).toString("utf-8"));
|
|
21405
21538
|
};
|
|
21406
21539
|
const timer = setTimeout(() => finish(new Error("stdin read timeout")), timeoutMs);
|
|
21407
21540
|
process.stdin.on("data", (chunk) => {
|
|
@@ -21418,9 +21551,9 @@ function readHookStdin(timeoutMs = 1e3, maxBytes = DEFAULT_MAX_BYTES) {
|
|
|
21418
21551
|
}
|
|
21419
21552
|
|
|
21420
21553
|
// src/hooks/normalize.ts
|
|
21421
|
-
import { createHash as
|
|
21554
|
+
import { createHash as createHash8 } from "crypto";
|
|
21422
21555
|
import { realpathSync as realpathSync3 } from "fs";
|
|
21423
|
-
import { isAbsolute as isAbsolute6, resolve as
|
|
21556
|
+
import { isAbsolute as isAbsolute6, resolve as resolve5 } from "path";
|
|
21424
21557
|
var HERMES_EVENT_MAP = {
|
|
21425
21558
|
on_session_start: "SessionStart",
|
|
21426
21559
|
on_session_end: "SessionEnd",
|
|
@@ -21463,7 +21596,7 @@ function requiredId(value, field) {
|
|
|
21463
21596
|
}
|
|
21464
21597
|
function cursorToolUseId(value) {
|
|
21465
21598
|
if (SAFE_CORRELATION_ID_RE.test(value)) return value;
|
|
21466
|
-
return `cursor:tool:v1:${
|
|
21599
|
+
return `cursor:tool:v1:${createHash8("sha256").update(value).digest("hex")}`;
|
|
21467
21600
|
}
|
|
21468
21601
|
function workspaceCandidates(value) {
|
|
21469
21602
|
if (!Array.isArray(value)) return [];
|
|
@@ -21477,7 +21610,7 @@ function pathIdentity(path) {
|
|
|
21477
21610
|
try {
|
|
21478
21611
|
return realpathSync3.native(path);
|
|
21479
21612
|
} catch {
|
|
21480
|
-
return
|
|
21613
|
+
return resolve5(path);
|
|
21481
21614
|
}
|
|
21482
21615
|
}
|
|
21483
21616
|
function resolveCursorCwd(parsed) {
|
|
@@ -21502,7 +21635,7 @@ function resolveCursorCwd(parsed) {
|
|
|
21502
21635
|
if (rawToolCwd && !isAbsolute6(rawToolCwd) && !base) {
|
|
21503
21636
|
throw new TypeError("relative Cursor tool cwd has no workspace base");
|
|
21504
21637
|
}
|
|
21505
|
-
const toolCwd = rawToolCwd ? pathIdentity(isAbsolute6(rawToolCwd) ? rawToolCwd :
|
|
21638
|
+
const toolCwd = rawToolCwd ? pathIdentity(isAbsolute6(rawToolCwd) ? rawToolCwd : resolve5(base, rawToolCwd)) : void 0;
|
|
21506
21639
|
const selected = toolCwd ?? envelopeCwd ?? (roots.length === 1 ? roots[0] : expectedRepo);
|
|
21507
21640
|
if (!selected) {
|
|
21508
21641
|
throw new TypeError("Cursor hook envelope has no unambiguous workspace");
|
|
@@ -21560,7 +21693,7 @@ function normalizeEnvelope(parsed, agent2) {
|
|
|
21560
21693
|
]);
|
|
21561
21694
|
return {
|
|
21562
21695
|
...parsed,
|
|
21563
|
-
tool_use_id: `codex:fallback:v1:${
|
|
21696
|
+
tool_use_id: `codex:fallback:v1:${createHash8("sha256").update(stableToolIdentity).digest("hex")}`
|
|
21564
21697
|
};
|
|
21565
21698
|
}
|
|
21566
21699
|
return parsed;
|
|
@@ -21813,8 +21946,8 @@ function demoteForMode(verdict, mode) {
|
|
|
21813
21946
|
import { Buffer as Buffer2 } from "buffer";
|
|
21814
21947
|
|
|
21815
21948
|
// src/hooks/redact.ts
|
|
21816
|
-
import { existsSync as
|
|
21817
|
-
import { join as
|
|
21949
|
+
import { existsSync as existsSync11, readFileSync as readFileSync12, statSync as statSync4 } from "fs";
|
|
21950
|
+
import { join as join14 } from "path";
|
|
21818
21951
|
import { Worker } from "worker_threads";
|
|
21819
21952
|
var USER_HOME_RULES = [
|
|
21820
21953
|
{
|
|
@@ -26520,12 +26653,12 @@ function unverifiedResult(message) {
|
|
|
26520
26653
|
var STDIN_TIMEOUT_MS = 1e3;
|
|
26521
26654
|
var agent = parseAgent(process.argv);
|
|
26522
26655
|
async function emit(output) {
|
|
26523
|
-
return await new Promise((
|
|
26656
|
+
return await new Promise((resolve6) => {
|
|
26524
26657
|
try {
|
|
26525
26658
|
process.stdout.write(`${JSON.stringify(output)}
|
|
26526
|
-
`, (error) =>
|
|
26659
|
+
`, (error) => resolve6(!error));
|
|
26527
26660
|
} catch {
|
|
26528
|
-
|
|
26661
|
+
resolve6(false);
|
|
26529
26662
|
}
|
|
26530
26663
|
});
|
|
26531
26664
|
}
|
|
@@ -26611,6 +26744,13 @@ async function main() {
|
|
|
26611
26744
|
await emit(failOpen());
|
|
26612
26745
|
return;
|
|
26613
26746
|
}
|
|
26747
|
+
try {
|
|
26748
|
+
if (observeDemoInvocation(envelope, agent, false).invocation) {
|
|
26749
|
+
await emit(failOpen());
|
|
26750
|
+
return;
|
|
26751
|
+
}
|
|
26752
|
+
} catch {
|
|
26753
|
+
}
|
|
26614
26754
|
if (envelope.hook_event_name !== "PreToolUse") {
|
|
26615
26755
|
await emit(failOpen());
|
|
26616
26756
|
return;
|