@primitive.ai/prim 0.1.0-alpha.97 → 0.1.0-alpha.99
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 +20 -0
- package/dist/{chunk-ZYK3TBEW.js → chunk-25DDRMWS.js} +4 -6
- package/dist/{chunk-LY6NJ7KL.js → chunk-2IRLFOEL.js} +123 -19
- package/dist/{chunk-27ADT6FQ.js → chunk-2Q3OGSTV.js} +44 -6
- package/dist/{chunk-35FMRWJH.js → chunk-5LRKJTLA.js} +1 -1
- package/dist/{chunk-RK4ZS3HG.js → chunk-6C3CCVDI.js} +2 -2
- package/dist/{chunk-UO2U6IKF.js → chunk-7VIMU2HR.js} +1 -1
- package/dist/{chunk-OW4GJBLW.js → chunk-EJPKZT5M.js} +2 -2
- package/dist/{chunk-2MBV7ZMV.js → chunk-FK7FJPWS.js} +1 -1
- package/dist/{chunk-4GHANPWQ.js → chunk-JJI7FU24.js} +2 -2
- package/dist/{chunk-AJYZB5PF.js → chunk-JJYS7IPD.js} +3 -3
- package/dist/{chunk-Y5W4TZM7.js → chunk-K4JWJ6OM.js} +80 -269
- package/dist/{chunk-XEDJ5N3M.js → chunk-KGBMU76T.js} +2 -4
- package/dist/{chunk-7KABYYWG.js → chunk-O2WV5SQZ.js} +11 -13
- package/dist/{chunk-FBPZ4YUD.js → chunk-X5BN67D2.js} +2 -2
- package/dist/{chunk-DWRSEC34.js → chunk-XG7S3LIL.js} +596 -16
- package/dist/{chunk-3I4GEWXQ.js → chunk-XPS6LG6I.js} +8 -12
- package/dist/{chunk-QNPTWTBG.js → chunk-ZNLIGT3J.js} +2 -2
- package/dist/daemon/server.js +247 -180
- package/dist/hook-runtime/daemon/server.js +247 -180
- package/dist/hook-runtime/hooks/post-commit.js +114 -59
- package/dist/hook-runtime/hooks/post-rewrite.js +109 -54
- package/dist/hook-runtime/hooks/post-tool-use.js +256 -156
- package/dist/hook-runtime/hooks/pre-commit.js +374 -31
- package/dist/hook-runtime/hooks/pre-tool-use.js +237 -137
- package/dist/hook-runtime/hooks/prim-hook.js +281 -181
- package/dist/hook-runtime/hooks/session-start.js +209 -109
- package/dist/hook-runtime/index.js +656 -521
- package/dist/hook-runtime/statusline-main.js +71 -16
- package/dist/hooks/post-commit.js +7 -8
- package/dist/hooks/post-rewrite.js +6 -7
- package/dist/hooks/post-tool-use.js +13 -14
- package/dist/hooks/pre-commit.js +4 -4
- package/dist/hooks/pre-tool-use.js +11 -14
- package/dist/hooks/prim-hook.js +14 -15
- package/dist/hooks/session-end.js +6 -7
- package/dist/hooks/session-start.js +13 -14
- package/dist/index.js +33 -35
- package/dist/statusline-main.js +71 -16
- package/package.json +1 -1
- package/dist/chunk-DHOQGHKQ.js +0 -379
|
@@ -4963,7 +4963,7 @@ var require_rc = __commonJS({
|
|
|
4963
4963
|
"node_modules/.pnpm/rc@1.2.8/node_modules/rc/index.js"(exports, module) {
|
|
4964
4964
|
"use strict";
|
|
4965
4965
|
var cc = require_utils();
|
|
4966
|
-
var
|
|
4966
|
+
var join33 = __require("path").join;
|
|
4967
4967
|
var deepExtend = require_deep_extend();
|
|
4968
4968
|
var etc = "/etc";
|
|
4969
4969
|
var win = process.platform === "win32";
|
|
@@ -4988,15 +4988,15 @@ var require_rc = __commonJS({
|
|
|
4988
4988
|
}
|
|
4989
4989
|
if (!win)
|
|
4990
4990
|
[
|
|
4991
|
-
|
|
4992
|
-
|
|
4991
|
+
join33(etc, name, "config"),
|
|
4992
|
+
join33(etc, name + "rc")
|
|
4993
4993
|
].forEach(addConfigFile);
|
|
4994
4994
|
if (home)
|
|
4995
4995
|
[
|
|
4996
|
-
|
|
4997
|
-
|
|
4998
|
-
|
|
4999
|
-
|
|
4996
|
+
join33(home, ".config", name, "config"),
|
|
4997
|
+
join33(home, ".config", name),
|
|
4998
|
+
join33(home, "." + name, "config"),
|
|
4999
|
+
join33(home, "." + name + "rc")
|
|
5000
5000
|
].forEach(addConfigFile);
|
|
5001
5001
|
addConfigFile(cc.find("." + name + "rc"));
|
|
5002
5002
|
if (env4.config) addConfigFile(env4.config);
|
|
@@ -8896,7 +8896,7 @@ var require_ucs2length = __commonJS({
|
|
|
8896
8896
|
});
|
|
8897
8897
|
|
|
8898
8898
|
// src/index.ts
|
|
8899
|
-
import { readFileSync as
|
|
8899
|
+
import { readFileSync as readFileSync26 } from "fs";
|
|
8900
8900
|
import { dirname as dirname20, resolve as resolve11 } from "path";
|
|
8901
8901
|
import { fileURLToPath as fileURLToPath7 } from "url";
|
|
8902
8902
|
|
|
@@ -12955,6 +12955,9 @@ function gitValue(cwd, args) {
|
|
|
12955
12955
|
return void 0;
|
|
12956
12956
|
}
|
|
12957
12957
|
}
|
|
12958
|
+
function currentBranch(cwd) {
|
|
12959
|
+
return gitValue(cwd, ["symbolic-ref", "--quiet", "--short", "HEAD"]);
|
|
12960
|
+
}
|
|
12958
12961
|
function githubRepositoryFullName(cwd) {
|
|
12959
12962
|
const remote = gitValue(cwd, ["config", "--get", "remote.origin.url"]);
|
|
12960
12963
|
if (!remote || [...remote].some((char) => char < " " || char === "\x7F")) return null;
|
|
@@ -13173,8 +13176,8 @@ function decisionIngestionStatus(cwd) {
|
|
|
13173
13176
|
|
|
13174
13177
|
// src/client.ts
|
|
13175
13178
|
import { createHash as createHash4 } from "crypto";
|
|
13176
|
-
import { chmodSync, existsSync as
|
|
13177
|
-
import { dirname as
|
|
13179
|
+
import { chmodSync as chmodSync2, existsSync as existsSync4, mkdirSync as mkdirSync3, readFileSync as readFileSync6, rmSync as rmSync3 } from "fs";
|
|
13180
|
+
import { dirname as dirname5 } from "path";
|
|
13178
13181
|
|
|
13179
13182
|
// src/lib/atomic-file.ts
|
|
13180
13183
|
import { randomUUID } from "crypto";
|
|
@@ -13432,6 +13435,293 @@ async function withFileLock(lockDir, operation, options = {}) {
|
|
|
13432
13435
|
}
|
|
13433
13436
|
}
|
|
13434
13437
|
|
|
13438
|
+
// src/daemon/client-instance-id.ts
|
|
13439
|
+
import { randomBytes as randomBytes2 } from "crypto";
|
|
13440
|
+
import { chmodSync, lstatSync as lstatSync2, readFileSync as readFileSync4 } from "fs";
|
|
13441
|
+
import { join as join6 } from "path";
|
|
13442
|
+
var CONFIG_DIRECTORY_MODE = 448;
|
|
13443
|
+
var INSTANCE_FILE_MODE = 384;
|
|
13444
|
+
var INSTANCE_ENTROPY_BYTES = 32;
|
|
13445
|
+
var INSTANCE_BODY_CHARS = 43;
|
|
13446
|
+
var INSTANCE_PREFIX = "pci_";
|
|
13447
|
+
var CLIENT_INSTANCE_ID_RE = /^pci_[A-Za-z0-9_-]{43}$/u;
|
|
13448
|
+
var MAX_STORED_BYTES = INSTANCE_PREFIX.length + INSTANCE_BODY_CHARS + 1;
|
|
13449
|
+
function isClientInstanceId(value) {
|
|
13450
|
+
return typeof value === "string" && CLIENT_INSTANCE_ID_RE.test(value);
|
|
13451
|
+
}
|
|
13452
|
+
function ensurePrivateConfigDirectory(configDir) {
|
|
13453
|
+
ensureDurableDirectory(configDir, CONFIG_DIRECTORY_MODE);
|
|
13454
|
+
const metadata = lstatSync2(configDir);
|
|
13455
|
+
if (!metadata.isDirectory() || metadata.isSymbolicLink()) {
|
|
13456
|
+
throw new Error("prim config path must be a private directory");
|
|
13457
|
+
}
|
|
13458
|
+
chmodSync(configDir, CONFIG_DIRECTORY_MODE);
|
|
13459
|
+
syncDirectory(configDir);
|
|
13460
|
+
}
|
|
13461
|
+
function readExisting(path9) {
|
|
13462
|
+
let metadata;
|
|
13463
|
+
try {
|
|
13464
|
+
metadata = lstatSync2(path9);
|
|
13465
|
+
} catch (error) {
|
|
13466
|
+
if (error.code === "ENOENT") {
|
|
13467
|
+
return;
|
|
13468
|
+
}
|
|
13469
|
+
throw error;
|
|
13470
|
+
}
|
|
13471
|
+
if (!metadata.isFile() || metadata.isSymbolicLink()) {
|
|
13472
|
+
throw new Error("stored client instance identity is invalid");
|
|
13473
|
+
}
|
|
13474
|
+
chmodSync(path9, INSTANCE_FILE_MODE);
|
|
13475
|
+
if (metadata.size > MAX_STORED_BYTES) {
|
|
13476
|
+
throw new Error("stored client instance identity is invalid");
|
|
13477
|
+
}
|
|
13478
|
+
const raw = readFileSync4(path9, "utf8");
|
|
13479
|
+
const value = raw.endsWith("\n") ? raw.slice(0, -1) : raw;
|
|
13480
|
+
if (raw !== value && raw !== `${value}
|
|
13481
|
+
` || !isClientInstanceId(value)) {
|
|
13482
|
+
throw new Error("stored client instance identity is invalid");
|
|
13483
|
+
}
|
|
13484
|
+
return value;
|
|
13485
|
+
}
|
|
13486
|
+
function atomicWrite(path9, value) {
|
|
13487
|
+
atomicWriteFile(path9, `${value}
|
|
13488
|
+
`, { mode: INSTANCE_FILE_MODE });
|
|
13489
|
+
}
|
|
13490
|
+
async function getOrCreateClientInstanceId(options) {
|
|
13491
|
+
const configDir = options.configDir;
|
|
13492
|
+
const path9 = join6(configDir, "client_instance_id");
|
|
13493
|
+
const lockPath = join6(configDir, "client-instance.lock");
|
|
13494
|
+
ensurePrivateConfigDirectory(configDir);
|
|
13495
|
+
return withFileLock(
|
|
13496
|
+
lockPath,
|
|
13497
|
+
() => {
|
|
13498
|
+
const existing = readExisting(path9);
|
|
13499
|
+
if (existing !== void 0) {
|
|
13500
|
+
return existing;
|
|
13501
|
+
}
|
|
13502
|
+
const generated = `${INSTANCE_PREFIX}${randomBytes2(INSTANCE_ENTROPY_BYTES).toString(
|
|
13503
|
+
"base64url"
|
|
13504
|
+
)}`;
|
|
13505
|
+
if (!isClientInstanceId(generated)) {
|
|
13506
|
+
throw new Error("generated client instance identity is invalid");
|
|
13507
|
+
}
|
|
13508
|
+
atomicWrite(path9, generated);
|
|
13509
|
+
return generated;
|
|
13510
|
+
},
|
|
13511
|
+
options.lockOptions
|
|
13512
|
+
);
|
|
13513
|
+
}
|
|
13514
|
+
|
|
13515
|
+
// src/lib/bin-path.ts
|
|
13516
|
+
import { existsSync as existsSync3, readFileSync as readFileSync5 } from "fs";
|
|
13517
|
+
import { dirname as dirname4, isAbsolute as isAbsolute3, join as join7 } from "path";
|
|
13518
|
+
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
13519
|
+
|
|
13520
|
+
// src/lib/semver.ts
|
|
13521
|
+
function parseSemver(value) {
|
|
13522
|
+
if (typeof value !== "string" || value.length > 256) return;
|
|
13523
|
+
const match = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/u.exec(
|
|
13524
|
+
value
|
|
13525
|
+
);
|
|
13526
|
+
if (!match) return;
|
|
13527
|
+
const prerelease = match[4]?.split(".") ?? [];
|
|
13528
|
+
if (prerelease.some((part) => /^\d+$/u.test(part) && part.length > 1 && part.startsWith("0"))) {
|
|
13529
|
+
return;
|
|
13530
|
+
}
|
|
13531
|
+
return { core: [BigInt(match[1]), BigInt(match[2]), BigInt(match[3])], prerelease };
|
|
13532
|
+
}
|
|
13533
|
+
function compareSemver(left, right) {
|
|
13534
|
+
const a = parseSemver(left);
|
|
13535
|
+
const b = parseSemver(right);
|
|
13536
|
+
if (!a || !b) return;
|
|
13537
|
+
for (let i = 0; i < a.core.length; i += 1) {
|
|
13538
|
+
if (a.core[i] !== b.core[i]) return a.core[i] < b.core[i] ? -1 : 1;
|
|
13539
|
+
}
|
|
13540
|
+
if (a.prerelease.length === 0 || b.prerelease.length === 0) {
|
|
13541
|
+
return a.prerelease.length === b.prerelease.length ? 0 : a.prerelease.length === 0 ? 1 : -1;
|
|
13542
|
+
}
|
|
13543
|
+
for (let i = 0; i < Math.max(a.prerelease.length, b.prerelease.length); i += 1) {
|
|
13544
|
+
const x = a.prerelease[i];
|
|
13545
|
+
const y = b.prerelease[i];
|
|
13546
|
+
if (x === void 0 || y === void 0) return x === void 0 ? -1 : 1;
|
|
13547
|
+
if (x === y) continue;
|
|
13548
|
+
const xNumeric = /^\d+$/u.test(x);
|
|
13549
|
+
const yNumeric = /^\d+$/u.test(y);
|
|
13550
|
+
if (xNumeric && yNumeric) return BigInt(x) < BigInt(y) ? -1 : 1;
|
|
13551
|
+
if (xNumeric !== yNumeric) return xNumeric ? -1 : 1;
|
|
13552
|
+
return x < y ? -1 : 1;
|
|
13553
|
+
}
|
|
13554
|
+
return 0;
|
|
13555
|
+
}
|
|
13556
|
+
|
|
13557
|
+
// src/lib/bin-path.ts
|
|
13558
|
+
var PKG_NAME = "@primitive.ai/prim";
|
|
13559
|
+
var ROOT_WALK_LIMIT = 6;
|
|
13560
|
+
var STABLE_HOOK_LAUNCHER_NAME = "prim-hook-launcher-v1";
|
|
13561
|
+
var resolvedRoot;
|
|
13562
|
+
function locateRoot() {
|
|
13563
|
+
if (resolvedRoot !== void 0) {
|
|
13564
|
+
return resolvedRoot;
|
|
13565
|
+
}
|
|
13566
|
+
let dir = dirname4(fileURLToPath3(import.meta.url));
|
|
13567
|
+
for (let depth = 0; depth < ROOT_WALK_LIMIT; depth++) {
|
|
13568
|
+
const manifestPath = join7(dir, "package.json");
|
|
13569
|
+
if (existsSync3(manifestPath)) {
|
|
13570
|
+
try {
|
|
13571
|
+
const manifest = JSON.parse(readFileSync5(manifestPath, "utf-8"));
|
|
13572
|
+
if (manifest.name === PKG_NAME && manifest.bin) {
|
|
13573
|
+
resolvedRoot = { dir, version: manifest.version, bin: manifest.bin };
|
|
13574
|
+
return resolvedRoot;
|
|
13575
|
+
}
|
|
13576
|
+
} catch {
|
|
13577
|
+
}
|
|
13578
|
+
}
|
|
13579
|
+
const parent = dirname4(dir);
|
|
13580
|
+
if (parent === dir) {
|
|
13581
|
+
break;
|
|
13582
|
+
}
|
|
13583
|
+
dir = parent;
|
|
13584
|
+
}
|
|
13585
|
+
resolvedRoot = null;
|
|
13586
|
+
return resolvedRoot;
|
|
13587
|
+
}
|
|
13588
|
+
function binFile(bin) {
|
|
13589
|
+
const root = locateRoot();
|
|
13590
|
+
const rel = root?.bin[bin];
|
|
13591
|
+
if (!root || !rel) {
|
|
13592
|
+
return null;
|
|
13593
|
+
}
|
|
13594
|
+
return isAbsolute3(rel) ? rel : join7(root.dir, rel);
|
|
13595
|
+
}
|
|
13596
|
+
function packageVersion() {
|
|
13597
|
+
return locateRoot()?.version ?? null;
|
|
13598
|
+
}
|
|
13599
|
+
function packageRoot() {
|
|
13600
|
+
return locateRoot()?.dir ?? null;
|
|
13601
|
+
}
|
|
13602
|
+
function shellQuote(value) {
|
|
13603
|
+
return `'${value.replaceAll("'", `'"'"'`)}'`;
|
|
13604
|
+
}
|
|
13605
|
+
function shellWord(value) {
|
|
13606
|
+
return /^[A-Za-z0-9_@%+=:,./-]+$/u.test(value) ? value : shellQuote(value);
|
|
13607
|
+
}
|
|
13608
|
+
function pinnedNpxArgs(bin, args = [], options = {}) {
|
|
13609
|
+
const version = packageVersion();
|
|
13610
|
+
if (!version) throw new Error("cannot determine Primitive package version");
|
|
13611
|
+
return [
|
|
13612
|
+
"--yes",
|
|
13613
|
+
"--ignore-scripts",
|
|
13614
|
+
...options.preferOnline ? ["--prefer-online"] : [],
|
|
13615
|
+
"-p",
|
|
13616
|
+
`${PKG_NAME}@${version}`,
|
|
13617
|
+
bin,
|
|
13618
|
+
...args
|
|
13619
|
+
];
|
|
13620
|
+
}
|
|
13621
|
+
function pinnedNpxCommand(bin, args = [], options = {}) {
|
|
13622
|
+
return ["npx", ...pinnedNpxArgs(bin, args, options)].map(shellWord).join(" ");
|
|
13623
|
+
}
|
|
13624
|
+
function pinnedHookCommand(bin, args = "") {
|
|
13625
|
+
const suffix = args ? ` ${args}` : "";
|
|
13626
|
+
const fallback = `${pinnedNpxCommand(bin)}${suffix}`;
|
|
13627
|
+
const file = binFile(bin);
|
|
13628
|
+
if (!file) return fallback;
|
|
13629
|
+
return `if [ -x ${shellQuote(process.execPath)} ] && [ -f ${shellQuote(file)} ]; then ${shellQuote(process.execPath)} ${shellQuote(file)}${suffix}; else ${fallback}; fi`;
|
|
13630
|
+
}
|
|
13631
|
+
var STABLE_HOOK_ARGUMENTS_RE = /^[-A-Za-z0-9_ ]*$/u;
|
|
13632
|
+
var STABLE_HOOK_BIN_RE = /^[A-Za-z0-9][A-Za-z0-9-]*$/u;
|
|
13633
|
+
var PRIM_CONFIG_SHELL_RESOLVER = [
|
|
13634
|
+
'prim_absolute() { case "$1" in [/]* ) ;; *) return 1 ;; esac; case "$1" in [[:space:]]*|*[[:space:]]|*[/][/]*|*[/].[/]*|*[/]..[/]*|*[/].|*[/]..|?*[/]) return 1 ;; esac; }; ',
|
|
13635
|
+
'prim_config=${PRIM_CONFIG_DIR:-}; if ! prim_absolute "$prim_config"; then prim_config=${XDG_CONFIG_HOME:-}; if prim_absolute "$prim_config"; then ',
|
|
13636
|
+
'case "$prim_config" in /) prim_config=/prim ;; *) prim_config="$prim_config/prim" ;; esac; ',
|
|
13637
|
+
'else prim_home=${HOME:-}; prim_absolute "$prim_home" || exit 78; case "$prim_home" in /) prim_config=/.config/prim ;; *) prim_config="$prim_home/.config/prim" ;; esac; ',
|
|
13638
|
+
"fi; fi; "
|
|
13639
|
+
].join("");
|
|
13640
|
+
function stableHookCommand(bin, args = "") {
|
|
13641
|
+
if (!STABLE_HOOK_BIN_RE.test(bin) || !STABLE_HOOK_ARGUMENTS_RE.test(args)) {
|
|
13642
|
+
throw new Error("invalid stable hook command");
|
|
13643
|
+
}
|
|
13644
|
+
const resolver = [
|
|
13645
|
+
// #242 and earlier identify managed commands by this package marker. Keep
|
|
13646
|
+
// it as inert data during the rolling window so an older uninstall or
|
|
13647
|
+
// reinstall can remove the stable entry without invoking npm or PATH.
|
|
13648
|
+
`prim_legacy_reader='-p ${PKG_NAME}@stable prim-shim.sh ${bin} '; `,
|
|
13649
|
+
PRIM_CONFIG_SHELL_RESOLVER,
|
|
13650
|
+
`case "$prim_config" in /) prim_launcher=/${STABLE_HOOK_LAUNCHER_NAME} ;; *) prim_launcher="$prim_config/${STABLE_HOOK_LAUNCHER_NAME}" ;; esac; `,
|
|
13651
|
+
'exec "$prim_launcher" "$@"'
|
|
13652
|
+
].join("");
|
|
13653
|
+
const suffix = args ? ` ${args}` : "";
|
|
13654
|
+
return `/bin/sh -c ${shellQuote(resolver)} ${STABLE_HOOK_LAUNCHER_NAME} ${bin}${suffix}`;
|
|
13655
|
+
}
|
|
13656
|
+
function detachedHookShimCommand(bin, args = "") {
|
|
13657
|
+
return `payload=$(cat); { trap '' HUP; printf '%s' "$payload" | { ${stableHookCommand(bin, args)}; }; } </dev/null >/dev/null 2>&1 &`;
|
|
13658
|
+
}
|
|
13659
|
+
function commandMatchesBin(command, bin) {
|
|
13660
|
+
if (!command) {
|
|
13661
|
+
return false;
|
|
13662
|
+
}
|
|
13663
|
+
const c = command.trim();
|
|
13664
|
+
if (c === bin || c.startsWith(`${bin} `)) {
|
|
13665
|
+
return true;
|
|
13666
|
+
}
|
|
13667
|
+
const exactBin = new RegExp(`(?:^|\\s)${bin.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(?:\\s|;|$)`);
|
|
13668
|
+
return c.includes(`command -v ${bin} `) || c.includes(`-p ${PKG_NAME}@`) && exactBin.test(c) || c.includes(STABLE_HOOK_LAUNCHER_NAME) && exactBin.test(c);
|
|
13669
|
+
}
|
|
13670
|
+
function exactPinnedNpxVersion(command, bin) {
|
|
13671
|
+
const escapedBin = bin.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
13672
|
+
const shellQuoted = `'(?:[^']|'"'"')*'`;
|
|
13673
|
+
const safeArgs = "(?: [A-Za-z0-9_@%+=:,./-]+)*";
|
|
13674
|
+
const direct = new RegExp(
|
|
13675
|
+
`^npx --yes --ignore-scripts -p @primitive\\.ai/prim@(?<version>[0-9A-Za-z.+-]+) ${escapedBin}${safeArgs}$`,
|
|
13676
|
+
"u"
|
|
13677
|
+
).exec(command);
|
|
13678
|
+
const wrapped = new RegExp(
|
|
13679
|
+
`^if \\[ -x (?<node>${shellQuoted}) \\] && \\[ -f (?<entry>${shellQuoted}) \\]; then \\k<node> \\k<entry>(?<args>${safeArgs}); else npx --yes --ignore-scripts -p @primitive\\.ai/prim@(?<version>[0-9A-Za-z.+-]+) ${escapedBin}\\k<args>; fi$`,
|
|
13680
|
+
"u"
|
|
13681
|
+
).exec(command);
|
|
13682
|
+
const version = direct?.groups?.version ?? wrapped?.groups?.version;
|
|
13683
|
+
return version && compareSemver(version, version) !== void 0 ? version : void 0;
|
|
13684
|
+
}
|
|
13685
|
+
function hookCommandResolution(command, bin) {
|
|
13686
|
+
const trimmed = command?.trim();
|
|
13687
|
+
if (!trimmed || !commandMatchesBin(trimmed, bin)) return void 0;
|
|
13688
|
+
if (trimmed.includes(STABLE_HOOK_LAUNCHER_NAME)) return { kind: "stable_launcher" };
|
|
13689
|
+
const version = exactPinnedNpxVersion(trimmed, bin);
|
|
13690
|
+
return version ? { kind: "exact_npx_fallback", version } : { kind: "legacy_path" };
|
|
13691
|
+
}
|
|
13692
|
+
function hookCommandResolutions(commands, bins) {
|
|
13693
|
+
const resolutions = [];
|
|
13694
|
+
for (const command of commands) {
|
|
13695
|
+
for (const bin of bins) {
|
|
13696
|
+
const resolution = hookCommandResolution(command, bin);
|
|
13697
|
+
if (resolution) resolutions.push(resolution);
|
|
13698
|
+
}
|
|
13699
|
+
}
|
|
13700
|
+
return resolutions;
|
|
13701
|
+
}
|
|
13702
|
+
|
|
13703
|
+
// src/lib/ingest-uploader.ts
|
|
13704
|
+
var runtimeVersion = process.env.PRIM_RUNTIME_VERSION ?? packageVersion();
|
|
13705
|
+
var VERSION_RE = /^\d+\.\d+\.\d+(?:-[A-Za-z0-9.-]+)?(?:\+[A-Za-z0-9.-]+)?$/u;
|
|
13706
|
+
var instanceId;
|
|
13707
|
+
async function ingestUploaderHeaders() {
|
|
13708
|
+
const headers = {};
|
|
13709
|
+
if (runtimeVersion && runtimeVersion.length <= 64 && VERSION_RE.test(runtimeVersion)) {
|
|
13710
|
+
headers["X-Prim-Uploader-Version"] = runtimeVersion;
|
|
13711
|
+
}
|
|
13712
|
+
instanceId ??= getOrCreateClientInstanceId({
|
|
13713
|
+
configDir: primConfigDirectory(),
|
|
13714
|
+
// Attribution must not consume the upload deadline waiting for another process.
|
|
13715
|
+
lockOptions: { timeoutMs: 0 }
|
|
13716
|
+
}).catch(() => {
|
|
13717
|
+
instanceId = void 0;
|
|
13718
|
+
return void 0;
|
|
13719
|
+
});
|
|
13720
|
+
const id = await instanceId;
|
|
13721
|
+
if (id) headers["X-Prim-Client-Instance-Id"] = id;
|
|
13722
|
+
return headers;
|
|
13723
|
+
}
|
|
13724
|
+
|
|
13435
13725
|
// src/lib/terminal-safe.ts
|
|
13436
13726
|
function replaceIsolatedSurrogates(value) {
|
|
13437
13727
|
let out = "";
|
|
@@ -13482,7 +13772,7 @@ var DEFAULT_API_URL = "https://api.getprimitive.ai";
|
|
|
13482
13772
|
var AUTH_EXPIRED_MESSAGE = "Authentication expired. Run `prim auth login` to re-authenticate.";
|
|
13483
13773
|
function readTrimmed2(path9) {
|
|
13484
13774
|
try {
|
|
13485
|
-
const value =
|
|
13775
|
+
const value = readFileSync6(path9, "utf8").trim();
|
|
13486
13776
|
return value || void 0;
|
|
13487
13777
|
} catch {
|
|
13488
13778
|
return void 0;
|
|
@@ -13498,16 +13788,16 @@ function expiresAtFor(token, expiresIn) {
|
|
|
13498
13788
|
return expiresIn === void 0 ? jwtExpiresAt(token) : Date.now() + expiresIn * 1e3;
|
|
13499
13789
|
}
|
|
13500
13790
|
function ensureConfigDirectory() {
|
|
13501
|
-
const directory =
|
|
13791
|
+
const directory = dirname5(TOKEN_FILE_PATH);
|
|
13502
13792
|
mkdirSync3(directory, { recursive: true, mode: CONFIG_DIR_MODE });
|
|
13503
|
-
|
|
13793
|
+
chmodSync2(directory, CONFIG_DIR_MODE);
|
|
13504
13794
|
}
|
|
13505
|
-
function
|
|
13795
|
+
function atomicWrite2(path9, content) {
|
|
13506
13796
|
ensureConfigDirectory();
|
|
13507
13797
|
atomicWriteFile(path9, content, { mode: CREDENTIAL_FILE_MODE });
|
|
13508
13798
|
}
|
|
13509
13799
|
function removeCredentialFile(path9) {
|
|
13510
|
-
if (!
|
|
13800
|
+
if (!existsSync4(path9)) return false;
|
|
13511
13801
|
rmSync3(path9, { force: true });
|
|
13512
13802
|
return true;
|
|
13513
13803
|
}
|
|
@@ -13541,7 +13831,7 @@ function credentialFamilyMetadata(accessToken, refreshToken2, metadata) {
|
|
|
13541
13831
|
return metadata === void 0 ? legacyBrokerCredentialMetadata(accessToken, refreshToken2) : { ...metadata, ...hashes };
|
|
13542
13832
|
}
|
|
13543
13833
|
function writeCredentialMigrationSentinel() {
|
|
13544
|
-
|
|
13834
|
+
atomicWrite2(
|
|
13545
13835
|
CREDENTIAL_MIGRATION_PATH,
|
|
13546
13836
|
`${JSON.stringify({
|
|
13547
13837
|
version: CREDENTIAL_MIGRATION_VERSION,
|
|
@@ -13559,7 +13849,7 @@ function bindLegacyBrokerGeneration(accessToken, refreshToken2, metadata) {
|
|
|
13559
13849
|
return { state: "invalid" };
|
|
13560
13850
|
}
|
|
13561
13851
|
if (metadata.metadata === void 0) {
|
|
13562
|
-
|
|
13852
|
+
atomicWrite2(CREDENTIAL_FAMILY_PATH, `${JSON.stringify(familyMetadata)}
|
|
13563
13853
|
`);
|
|
13564
13854
|
}
|
|
13565
13855
|
const migrationState = readCredentialMigrationState();
|
|
@@ -13574,14 +13864,14 @@ function preserveMarkerlessLegacyGeneration() {
|
|
|
13574
13864
|
const refreshToken2 = readTrimmed2(REFRESH_TOKEN_PATH);
|
|
13575
13865
|
if (!(accessToken && refreshToken2)) return;
|
|
13576
13866
|
const familyMetadata = legacyBrokerCredentialMetadata(accessToken, refreshToken2);
|
|
13577
|
-
|
|
13867
|
+
atomicWrite2(CREDENTIAL_FAMILY_PATH, `${JSON.stringify(familyMetadata)}
|
|
13578
13868
|
`);
|
|
13579
13869
|
}
|
|
13580
13870
|
function terminalFingerprint() {
|
|
13581
13871
|
return readTrimmed2(TERMINAL_REFRESH_PATH);
|
|
13582
13872
|
}
|
|
13583
13873
|
function writeTerminalFingerprint(refreshToken2) {
|
|
13584
|
-
|
|
13874
|
+
atomicWrite2(TERMINAL_REFRESH_PATH, `${refreshFingerprint(refreshToken2)}
|
|
13585
13875
|
`);
|
|
13586
13876
|
}
|
|
13587
13877
|
function clearTerminalFingerprint() {
|
|
@@ -13606,24 +13896,24 @@ function commitCredentialsUnlocked(credentials) {
|
|
|
13606
13896
|
if (credentials.metadata !== void 0) {
|
|
13607
13897
|
preserveMarkerlessLegacyGeneration();
|
|
13608
13898
|
writeCredentialMigrationSentinel();
|
|
13609
|
-
|
|
13899
|
+
atomicWrite2(CREDENTIAL_FAMILY_PATH, `${JSON.stringify(familyMetadata)}
|
|
13610
13900
|
`);
|
|
13611
|
-
|
|
13901
|
+
atomicWrite2(CREDENTIAL_METADATA_PATH, `${JSON.stringify(familyMetadata)}
|
|
13612
13902
|
`);
|
|
13613
|
-
|
|
13903
|
+
atomicWrite2(REFRESH_TOKEN_PATH, `${refreshToken2}
|
|
13614
13904
|
`);
|
|
13615
13905
|
} else {
|
|
13616
|
-
|
|
13906
|
+
atomicWrite2(REFRESH_TOKEN_PATH, `${refreshToken2}
|
|
13617
13907
|
`);
|
|
13618
|
-
|
|
13908
|
+
atomicWrite2(CREDENTIAL_FAMILY_PATH, `${JSON.stringify(familyMetadata)}
|
|
13619
13909
|
`);
|
|
13620
13910
|
removeCredentialFile(CREDENTIAL_METADATA_PATH);
|
|
13621
13911
|
}
|
|
13622
13912
|
const expiresAt = expiresAtFor(accessToken, credentials.expiresIn);
|
|
13623
13913
|
if (expiresAt === void 0) removeCredentialFile(TOKEN_EXPIRES_PATH);
|
|
13624
|
-
else
|
|
13914
|
+
else atomicWrite2(TOKEN_EXPIRES_PATH, `${expiresAt}
|
|
13625
13915
|
`);
|
|
13626
|
-
|
|
13916
|
+
atomicWrite2(TOKEN_FILE_PATH, `${accessToken}
|
|
13627
13917
|
`);
|
|
13628
13918
|
clearTerminalFingerprint();
|
|
13629
13919
|
_cachedCredential = { token: accessToken, source: "token_file" };
|
|
@@ -13641,7 +13931,7 @@ async function setStoredToken(token, options = {}) {
|
|
|
13641
13931
|
removeCredentialFile(CREDENTIAL_METADATA_PATH);
|
|
13642
13932
|
clearTerminalFingerprint();
|
|
13643
13933
|
removeCredentialFile(CREDENTIAL_MIGRATION_PATH);
|
|
13644
|
-
|
|
13934
|
+
atomicWrite2(TOKEN_FILE_PATH, `${value}
|
|
13645
13935
|
`);
|
|
13646
13936
|
_cachedCredential = { token: value, source: "token_file" };
|
|
13647
13937
|
}, options);
|
|
@@ -13934,12 +14224,13 @@ function selectedCredential() {
|
|
|
13934
14224
|
}
|
|
13935
14225
|
return _cachedCredential;
|
|
13936
14226
|
}
|
|
13937
|
-
function fetchWithToken(method, path9, body, options, token, siteUrl) {
|
|
14227
|
+
async function fetchWithToken(method, path9, body, options, token, siteUrl) {
|
|
13938
14228
|
return fetch(`${siteUrl}${path9}`, {
|
|
13939
14229
|
method,
|
|
13940
14230
|
headers: {
|
|
13941
14231
|
Authorization: `Bearer ${token}`,
|
|
13942
|
-
"Content-Type": "application/json"
|
|
14232
|
+
"Content-Type": "application/json",
|
|
14233
|
+
...method === "POST" && path9 === "/api/cli/moves/ingest" ? await ingestUploaderHeaders() : {}
|
|
13943
14234
|
},
|
|
13944
14235
|
body: body === void 0 ? void 0 : JSON.stringify(body),
|
|
13945
14236
|
signal: options?.signal
|
|
@@ -32467,8 +32758,8 @@ function scheduleCollectScopeRefresh(cwd, collectScopeVersion, dependencies = de
|
|
|
32467
32758
|
|
|
32468
32759
|
// src/lib/commit-heartbeat.ts
|
|
32469
32760
|
import { execFileSync as execFileSync3 } from "child_process";
|
|
32470
|
-
import { mkdirSync as mkdirSync4, readFileSync as
|
|
32471
|
-
import { dirname as
|
|
32761
|
+
import { mkdirSync as mkdirSync4, readFileSync as readFileSync7, readdirSync, unlinkSync } from "fs";
|
|
32762
|
+
import { dirname as dirname6, join as join9, resolve as resolve3 } from "path";
|
|
32472
32763
|
var FIRED_DIR = "prim/post-commit-fired";
|
|
32473
32764
|
var WIRED_PATH = "prim/git-hooks-wired";
|
|
32474
32765
|
var GIT_TIMEOUT_MS3 = 1e3;
|
|
@@ -32487,7 +32778,7 @@ function commonPath(cwd, relative4) {
|
|
|
32487
32778
|
timeout: GIT_TIMEOUT_MS3
|
|
32488
32779
|
}).replace(/\r?\n$/u, "");
|
|
32489
32780
|
if (value === "" || /[\0\r\n]/u.test(value)) throw new Error("Git returned an unsafe path");
|
|
32490
|
-
return
|
|
32781
|
+
return join9(resolve3(cwd, value), relative4);
|
|
32491
32782
|
}
|
|
32492
32783
|
function gitPath(cwd, relative4) {
|
|
32493
32784
|
const value = execFileSync3("git", ["rev-parse", "--git-path", relative4], {
|
|
@@ -32500,8 +32791,8 @@ function gitPath(cwd, relative4) {
|
|
|
32500
32791
|
return resolve3(cwd, value);
|
|
32501
32792
|
}
|
|
32502
32793
|
function ensurePrivateParent(path9) {
|
|
32503
|
-
mkdirSync4(
|
|
32504
|
-
mkdirSync4(
|
|
32794
|
+
mkdirSync4(dirname6(dirname6(path9)), { recursive: true, mode: 448 });
|
|
32795
|
+
mkdirSync4(dirname6(path9), { recursive: true, mode: 448 });
|
|
32505
32796
|
}
|
|
32506
32797
|
function writeStamp(path9, at) {
|
|
32507
32798
|
ensurePrivateParent(path9);
|
|
@@ -32510,7 +32801,7 @@ function writeStamp(path9, at) {
|
|
|
32510
32801
|
}
|
|
32511
32802
|
function readStampAt(path9) {
|
|
32512
32803
|
try {
|
|
32513
|
-
const raw =
|
|
32804
|
+
const raw = readFileSync7(path9, "utf8");
|
|
32514
32805
|
if (raw.length > MAX_STAMP_BYTES) return void 0;
|
|
32515
32806
|
const parsed = JSON.parse(raw);
|
|
32516
32807
|
return typeof parsed.at === "number" && Number.isSafeInteger(parsed.at) && parsed.at > 0 ? parsed.at : void 0;
|
|
@@ -32530,7 +32821,7 @@ function readFiredStamps(cwd) {
|
|
|
32530
32821
|
const dir = gitPath(cwd, FIRED_DIR);
|
|
32531
32822
|
return readdirSync(dir).flatMap((sha) => {
|
|
32532
32823
|
if (!FULL_SHA_RE.test(sha)) return [];
|
|
32533
|
-
const at = readStampAt(
|
|
32824
|
+
const at = readStampAt(join9(dir, sha));
|
|
32534
32825
|
return at === void 0 ? [] : [{ sha, at }];
|
|
32535
32826
|
});
|
|
32536
32827
|
} catch {
|
|
@@ -32632,204 +32923,16 @@ import {
|
|
|
32632
32923
|
existsSync as existsSync6,
|
|
32633
32924
|
fchmodSync as fchmodSync2,
|
|
32634
32925
|
fsyncSync as fsyncSync2,
|
|
32635
|
-
lstatSync as
|
|
32926
|
+
lstatSync as lstatSync4,
|
|
32636
32927
|
mkdirSync as mkdirSync7,
|
|
32637
32928
|
openSync as openSync2,
|
|
32638
|
-
readFileSync as
|
|
32929
|
+
readFileSync as readFileSync9,
|
|
32639
32930
|
realpathSync as realpathSync3,
|
|
32640
32931
|
renameSync as renameSync3,
|
|
32641
32932
|
unlinkSync as unlinkSync2,
|
|
32642
32933
|
writeFileSync as writeFileSync5
|
|
32643
32934
|
} from "fs";
|
|
32644
|
-
import { basename as basename2, dirname as dirname8, isAbsolute as isAbsolute6, join as
|
|
32645
|
-
|
|
32646
|
-
// src/lib/bin-path.ts
|
|
32647
|
-
import { existsSync as existsSync4, readFileSync as readFileSync6 } from "fs";
|
|
32648
|
-
import { dirname as dirname6, isAbsolute as isAbsolute3, join as join8 } from "path";
|
|
32649
|
-
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
32650
|
-
|
|
32651
|
-
// src/lib/semver.ts
|
|
32652
|
-
function parseSemver(value) {
|
|
32653
|
-
if (typeof value !== "string" || value.length > 256) return;
|
|
32654
|
-
const match = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/u.exec(
|
|
32655
|
-
value
|
|
32656
|
-
);
|
|
32657
|
-
if (!match) return;
|
|
32658
|
-
const prerelease = match[4]?.split(".") ?? [];
|
|
32659
|
-
if (prerelease.some((part) => /^\d+$/u.test(part) && part.length > 1 && part.startsWith("0"))) {
|
|
32660
|
-
return;
|
|
32661
|
-
}
|
|
32662
|
-
return { core: [BigInt(match[1]), BigInt(match[2]), BigInt(match[3])], prerelease };
|
|
32663
|
-
}
|
|
32664
|
-
function compareSemver(left, right) {
|
|
32665
|
-
const a = parseSemver(left);
|
|
32666
|
-
const b = parseSemver(right);
|
|
32667
|
-
if (!a || !b) return;
|
|
32668
|
-
for (let i = 0; i < a.core.length; i += 1) {
|
|
32669
|
-
if (a.core[i] !== b.core[i]) return a.core[i] < b.core[i] ? -1 : 1;
|
|
32670
|
-
}
|
|
32671
|
-
if (a.prerelease.length === 0 || b.prerelease.length === 0) {
|
|
32672
|
-
return a.prerelease.length === b.prerelease.length ? 0 : a.prerelease.length === 0 ? 1 : -1;
|
|
32673
|
-
}
|
|
32674
|
-
for (let i = 0; i < Math.max(a.prerelease.length, b.prerelease.length); i += 1) {
|
|
32675
|
-
const x = a.prerelease[i];
|
|
32676
|
-
const y = b.prerelease[i];
|
|
32677
|
-
if (x === void 0 || y === void 0) return x === void 0 ? -1 : 1;
|
|
32678
|
-
if (x === y) continue;
|
|
32679
|
-
const xNumeric = /^\d+$/u.test(x);
|
|
32680
|
-
const yNumeric = /^\d+$/u.test(y);
|
|
32681
|
-
if (xNumeric && yNumeric) return BigInt(x) < BigInt(y) ? -1 : 1;
|
|
32682
|
-
if (xNumeric !== yNumeric) return xNumeric ? -1 : 1;
|
|
32683
|
-
return x < y ? -1 : 1;
|
|
32684
|
-
}
|
|
32685
|
-
return 0;
|
|
32686
|
-
}
|
|
32687
|
-
|
|
32688
|
-
// src/lib/bin-path.ts
|
|
32689
|
-
var PKG_NAME = "@primitive.ai/prim";
|
|
32690
|
-
var ROOT_WALK_LIMIT = 6;
|
|
32691
|
-
var STABLE_HOOK_LAUNCHER_NAME = "prim-hook-launcher-v1";
|
|
32692
|
-
var resolvedRoot;
|
|
32693
|
-
function locateRoot() {
|
|
32694
|
-
if (resolvedRoot !== void 0) {
|
|
32695
|
-
return resolvedRoot;
|
|
32696
|
-
}
|
|
32697
|
-
let dir = dirname6(fileURLToPath3(import.meta.url));
|
|
32698
|
-
for (let depth = 0; depth < ROOT_WALK_LIMIT; depth++) {
|
|
32699
|
-
const manifestPath = join8(dir, "package.json");
|
|
32700
|
-
if (existsSync4(manifestPath)) {
|
|
32701
|
-
try {
|
|
32702
|
-
const manifest = JSON.parse(readFileSync6(manifestPath, "utf-8"));
|
|
32703
|
-
if (manifest.name === PKG_NAME && manifest.bin) {
|
|
32704
|
-
resolvedRoot = { dir, version: manifest.version, bin: manifest.bin };
|
|
32705
|
-
return resolvedRoot;
|
|
32706
|
-
}
|
|
32707
|
-
} catch {
|
|
32708
|
-
}
|
|
32709
|
-
}
|
|
32710
|
-
const parent = dirname6(dir);
|
|
32711
|
-
if (parent === dir) {
|
|
32712
|
-
break;
|
|
32713
|
-
}
|
|
32714
|
-
dir = parent;
|
|
32715
|
-
}
|
|
32716
|
-
resolvedRoot = null;
|
|
32717
|
-
return resolvedRoot;
|
|
32718
|
-
}
|
|
32719
|
-
function binFile(bin) {
|
|
32720
|
-
const root = locateRoot();
|
|
32721
|
-
const rel = root?.bin[bin];
|
|
32722
|
-
if (!root || !rel) {
|
|
32723
|
-
return null;
|
|
32724
|
-
}
|
|
32725
|
-
return isAbsolute3(rel) ? rel : join8(root.dir, rel);
|
|
32726
|
-
}
|
|
32727
|
-
function packageVersion() {
|
|
32728
|
-
return locateRoot()?.version ?? null;
|
|
32729
|
-
}
|
|
32730
|
-
function packageRoot() {
|
|
32731
|
-
return locateRoot()?.dir ?? null;
|
|
32732
|
-
}
|
|
32733
|
-
function shellQuote(value) {
|
|
32734
|
-
return `'${value.replaceAll("'", `'"'"'`)}'`;
|
|
32735
|
-
}
|
|
32736
|
-
function shellWord(value) {
|
|
32737
|
-
return /^[A-Za-z0-9_@%+=:,./-]+$/u.test(value) ? value : shellQuote(value);
|
|
32738
|
-
}
|
|
32739
|
-
function pinnedNpxArgs(bin, args = [], options = {}) {
|
|
32740
|
-
const version = packageVersion();
|
|
32741
|
-
if (!version) throw new Error("cannot determine Primitive package version");
|
|
32742
|
-
return [
|
|
32743
|
-
"--yes",
|
|
32744
|
-
"--ignore-scripts",
|
|
32745
|
-
...options.preferOnline ? ["--prefer-online"] : [],
|
|
32746
|
-
"-p",
|
|
32747
|
-
`${PKG_NAME}@${version}`,
|
|
32748
|
-
bin,
|
|
32749
|
-
...args
|
|
32750
|
-
];
|
|
32751
|
-
}
|
|
32752
|
-
function pinnedNpxCommand(bin, args = [], options = {}) {
|
|
32753
|
-
return ["npx", ...pinnedNpxArgs(bin, args, options)].map(shellWord).join(" ");
|
|
32754
|
-
}
|
|
32755
|
-
function pinnedHookCommand(bin, args = "") {
|
|
32756
|
-
const suffix = args ? ` ${args}` : "";
|
|
32757
|
-
const fallback = `${pinnedNpxCommand(bin)}${suffix}`;
|
|
32758
|
-
const file = binFile(bin);
|
|
32759
|
-
if (!file) return fallback;
|
|
32760
|
-
return `if [ -x ${shellQuote(process.execPath)} ] && [ -f ${shellQuote(file)} ]; then ${shellQuote(process.execPath)} ${shellQuote(file)}${suffix}; else ${fallback}; fi`;
|
|
32761
|
-
}
|
|
32762
|
-
var STABLE_HOOK_ARGUMENTS_RE = /^[-A-Za-z0-9_ ]*$/u;
|
|
32763
|
-
var STABLE_HOOK_BIN_RE = /^[A-Za-z0-9][A-Za-z0-9-]*$/u;
|
|
32764
|
-
var PRIM_CONFIG_SHELL_RESOLVER = [
|
|
32765
|
-
'prim_absolute() { case "$1" in [/]* ) ;; *) return 1 ;; esac; case "$1" in [[:space:]]*|*[[:space:]]|*[/][/]*|*[/].[/]*|*[/]..[/]*|*[/].|*[/]..|?*[/]) return 1 ;; esac; }; ',
|
|
32766
|
-
'prim_config=${PRIM_CONFIG_DIR:-}; if ! prim_absolute "$prim_config"; then prim_config=${XDG_CONFIG_HOME:-}; if prim_absolute "$prim_config"; then ',
|
|
32767
|
-
'case "$prim_config" in /) prim_config=/prim ;; *) prim_config="$prim_config/prim" ;; esac; ',
|
|
32768
|
-
'else prim_home=${HOME:-}; prim_absolute "$prim_home" || exit 78; case "$prim_home" in /) prim_config=/.config/prim ;; *) prim_config="$prim_home/.config/prim" ;; esac; ',
|
|
32769
|
-
"fi; fi; "
|
|
32770
|
-
].join("");
|
|
32771
|
-
function stableHookCommand(bin, args = "") {
|
|
32772
|
-
if (!STABLE_HOOK_BIN_RE.test(bin) || !STABLE_HOOK_ARGUMENTS_RE.test(args)) {
|
|
32773
|
-
throw new Error("invalid stable hook command");
|
|
32774
|
-
}
|
|
32775
|
-
const resolver = [
|
|
32776
|
-
// #242 and earlier identify managed commands by this package marker. Keep
|
|
32777
|
-
// it as inert data during the rolling window so an older uninstall or
|
|
32778
|
-
// reinstall can remove the stable entry without invoking npm or PATH.
|
|
32779
|
-
`prim_legacy_reader='-p ${PKG_NAME}@stable prim-shim.sh ${bin} '; `,
|
|
32780
|
-
PRIM_CONFIG_SHELL_RESOLVER,
|
|
32781
|
-
`case "$prim_config" in /) prim_launcher=/${STABLE_HOOK_LAUNCHER_NAME} ;; *) prim_launcher="$prim_config/${STABLE_HOOK_LAUNCHER_NAME}" ;; esac; `,
|
|
32782
|
-
'exec "$prim_launcher" "$@"'
|
|
32783
|
-
].join("");
|
|
32784
|
-
const suffix = args ? ` ${args}` : "";
|
|
32785
|
-
return `/bin/sh -c ${shellQuote(resolver)} ${STABLE_HOOK_LAUNCHER_NAME} ${bin}${suffix}`;
|
|
32786
|
-
}
|
|
32787
|
-
function detachedHookShimCommand(bin, args = "") {
|
|
32788
|
-
return `payload=$(cat); { trap '' HUP; printf '%s' "$payload" | { ${stableHookCommand(bin, args)}; }; } </dev/null >/dev/null 2>&1 &`;
|
|
32789
|
-
}
|
|
32790
|
-
function commandMatchesBin(command, bin) {
|
|
32791
|
-
if (!command) {
|
|
32792
|
-
return false;
|
|
32793
|
-
}
|
|
32794
|
-
const c = command.trim();
|
|
32795
|
-
if (c === bin || c.startsWith(`${bin} `)) {
|
|
32796
|
-
return true;
|
|
32797
|
-
}
|
|
32798
|
-
const exactBin = new RegExp(`(?:^|\\s)${bin.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(?:\\s|;|$)`);
|
|
32799
|
-
return c.includes(`command -v ${bin} `) || c.includes(`-p ${PKG_NAME}@`) && exactBin.test(c) || c.includes(STABLE_HOOK_LAUNCHER_NAME) && exactBin.test(c);
|
|
32800
|
-
}
|
|
32801
|
-
function exactPinnedNpxVersion(command, bin) {
|
|
32802
|
-
const escapedBin = bin.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
32803
|
-
const shellQuoted = `'(?:[^']|'"'"')*'`;
|
|
32804
|
-
const safeArgs = "(?: [A-Za-z0-9_@%+=:,./-]+)*";
|
|
32805
|
-
const direct = new RegExp(
|
|
32806
|
-
`^npx --yes --ignore-scripts -p @primitive\\.ai/prim@(?<version>[0-9A-Za-z.+-]+) ${escapedBin}${safeArgs}$`,
|
|
32807
|
-
"u"
|
|
32808
|
-
).exec(command);
|
|
32809
|
-
const wrapped = new RegExp(
|
|
32810
|
-
`^if \\[ -x (?<node>${shellQuoted}) \\] && \\[ -f (?<entry>${shellQuoted}) \\]; then \\k<node> \\k<entry>(?<args>${safeArgs}); else npx --yes --ignore-scripts -p @primitive\\.ai/prim@(?<version>[0-9A-Za-z.+-]+) ${escapedBin}\\k<args>; fi$`,
|
|
32811
|
-
"u"
|
|
32812
|
-
).exec(command);
|
|
32813
|
-
const version = direct?.groups?.version ?? wrapped?.groups?.version;
|
|
32814
|
-
return version && compareSemver(version, version) !== void 0 ? version : void 0;
|
|
32815
|
-
}
|
|
32816
|
-
function hookCommandResolution(command, bin) {
|
|
32817
|
-
const trimmed = command?.trim();
|
|
32818
|
-
if (!trimmed || !commandMatchesBin(trimmed, bin)) return void 0;
|
|
32819
|
-
if (trimmed.includes(STABLE_HOOK_LAUNCHER_NAME)) return { kind: "stable_launcher" };
|
|
32820
|
-
const version = exactPinnedNpxVersion(trimmed, bin);
|
|
32821
|
-
return version ? { kind: "exact_npx_fallback", version } : { kind: "legacy_path" };
|
|
32822
|
-
}
|
|
32823
|
-
function hookCommandResolutions(commands, bins) {
|
|
32824
|
-
const resolutions = [];
|
|
32825
|
-
for (const command of commands) {
|
|
32826
|
-
for (const bin of bins) {
|
|
32827
|
-
const resolution = hookCommandResolution(command, bin);
|
|
32828
|
-
if (resolution) resolutions.push(resolution);
|
|
32829
|
-
}
|
|
32830
|
-
}
|
|
32831
|
-
return resolutions;
|
|
32832
|
-
}
|
|
32935
|
+
import { basename as basename2, dirname as dirname8, isAbsolute as isAbsolute6, join as join12, relative as relative2, resolve as resolve5, sep as sep2 } from "path";
|
|
32833
32936
|
|
|
32834
32937
|
// src/lib/git-hook-contract.ts
|
|
32835
32938
|
var MANAGED_GIT_HOOK_NAMES = ["pre-commit", "post-commit", "post-rewrite"];
|
|
@@ -32973,9 +33076,9 @@ exit 0
|
|
|
32973
33076
|
import { isAbsolute as isAbsolute4 } from "path";
|
|
32974
33077
|
|
|
32975
33078
|
// src/lib/bin-cache.ts
|
|
32976
|
-
import { chmodSync as
|
|
33079
|
+
import { chmodSync as chmodSync3, mkdirSync as mkdirSync5 } from "fs";
|
|
32977
33080
|
import { homedir as homedir3 } from "os";
|
|
32978
|
-
import { join as
|
|
33081
|
+
import { join as join10 } from "path";
|
|
32979
33082
|
var GIT_HOOK_CACHE_SHELL_DIR = "${XDG_CACHE_HOME:-$HOME/.cache}/prim/bin";
|
|
32980
33083
|
var GIT_HOOK_CACHE_TTL_MINUTES = 1440;
|
|
32981
33084
|
|
|
@@ -33211,17 +33314,17 @@ ${end}`;
|
|
|
33211
33314
|
}
|
|
33212
33315
|
|
|
33213
33316
|
// src/lib/hook-runtime.ts
|
|
33214
|
-
import { createHash as createHash5, randomBytes as
|
|
33317
|
+
import { createHash as createHash5, randomBytes as randomBytes3 } from "crypto";
|
|
33215
33318
|
import {
|
|
33216
33319
|
constants as constants2,
|
|
33217
33320
|
accessSync,
|
|
33218
|
-
chmodSync as
|
|
33321
|
+
chmodSync as chmodSync4,
|
|
33219
33322
|
copyFileSync,
|
|
33220
33323
|
existsSync as existsSync5,
|
|
33221
|
-
lstatSync as
|
|
33324
|
+
lstatSync as lstatSync3,
|
|
33222
33325
|
mkdirSync as mkdirSync6,
|
|
33223
33326
|
mkdtempSync,
|
|
33224
|
-
readFileSync as
|
|
33327
|
+
readFileSync as readFileSync8,
|
|
33225
33328
|
readdirSync as readdirSync2,
|
|
33226
33329
|
realpathSync as realpathSync2,
|
|
33227
33330
|
renameSync as renameSync2,
|
|
@@ -33230,7 +33333,7 @@ import {
|
|
|
33230
33333
|
utimesSync,
|
|
33231
33334
|
writeFileSync as writeFileSync4
|
|
33232
33335
|
} from "fs";
|
|
33233
|
-
import { delimiter, dirname as dirname7, isAbsolute as isAbsolute5, join as
|
|
33336
|
+
import { delimiter, dirname as dirname7, isAbsolute as isAbsolute5, join as join11, resolve as resolve4 } from "path";
|
|
33234
33337
|
var HOOK_RUNTIME_SCHEMA_VERSION = 1;
|
|
33235
33338
|
var DIRECTORY_MODE2 = 448;
|
|
33236
33339
|
var DATA_FILE_MODE = 384;
|
|
@@ -33270,19 +33373,19 @@ function hookRuntimePaths(options = {}) {
|
|
|
33270
33373
|
env: env4,
|
|
33271
33374
|
homeDir: options.homeDir ?? env4.HOME ?? ""
|
|
33272
33375
|
});
|
|
33273
|
-
const runtimeDir =
|
|
33376
|
+
const runtimeDir = join11(configDir, "hook-runtime");
|
|
33274
33377
|
return {
|
|
33275
33378
|
configDir,
|
|
33276
|
-
launcher:
|
|
33277
|
-
gitHookEntrypoint:
|
|
33379
|
+
launcher: join11(configDir, STABLE_HOOK_LAUNCHER_NAME),
|
|
33380
|
+
gitHookEntrypoint: join11(configDir, GIT_HOOK_ENTRYPOINT_NAME),
|
|
33278
33381
|
runtimeDir,
|
|
33279
|
-
releasesDir:
|
|
33280
|
-
current:
|
|
33281
|
-
selectionLock:
|
|
33382
|
+
releasesDir: join11(runtimeDir, "releases"),
|
|
33383
|
+
current: join11(runtimeDir, "current"),
|
|
33384
|
+
selectionLock: join11(runtimeDir, "selection.lock")
|
|
33282
33385
|
};
|
|
33283
33386
|
}
|
|
33284
33387
|
function sha2562(path9) {
|
|
33285
|
-
return createHash5("sha256").update(
|
|
33388
|
+
return createHash5("sha256").update(readFileSync8(path9)).digest("hex");
|
|
33286
33389
|
}
|
|
33287
33390
|
function exactManifest(manifest) {
|
|
33288
33391
|
return `${JSON.stringify(manifest, null, 2)}
|
|
@@ -33312,18 +33415,18 @@ function runtimePackageJson(manifest) {
|
|
|
33312
33415
|
function validateRelease(releaseDir, manifest) {
|
|
33313
33416
|
try {
|
|
33314
33417
|
if (!directReleaseLayout(releaseDir)) return false;
|
|
33315
|
-
if (
|
|
33418
|
+
if (readFileSync8(join11(releaseDir, "manifest.json"), "utf8") !== exactManifest(manifest)) {
|
|
33316
33419
|
return false;
|
|
33317
33420
|
}
|
|
33318
|
-
if (
|
|
33421
|
+
if (readFileSync8(join11(releaseDir, "package.json"), "utf8") !== runtimePackageJson(manifest)) {
|
|
33319
33422
|
return false;
|
|
33320
33423
|
}
|
|
33321
|
-
if (
|
|
33424
|
+
if (readFileSync8(join11(releaseDir, "node"), "utf8") !== `${manifest.nodePath}
|
|
33322
33425
|
`) {
|
|
33323
33426
|
return false;
|
|
33324
33427
|
}
|
|
33325
33428
|
for (const [bin, relativePath] of Object.entries(HOOK_RUNTIME_ENTRIES)) {
|
|
33326
|
-
const target =
|
|
33429
|
+
const target = join11(releaseDir, relativePath);
|
|
33327
33430
|
if (sha2562(target) !== manifest.files[bin]) return false;
|
|
33328
33431
|
}
|
|
33329
33432
|
return true;
|
|
@@ -33336,22 +33439,22 @@ function directReleaseLayout(releaseDir) {
|
|
|
33336
33439
|
const directories = /* @__PURE__ */ new Set([releaseDir]);
|
|
33337
33440
|
for (const relativePath of Object.values(HOOK_RUNTIME_ENTRIES)) {
|
|
33338
33441
|
for (let directory = dirname7(relativePath); directory !== "."; directory = dirname7(directory)) {
|
|
33339
|
-
directories.add(
|
|
33442
|
+
directories.add(join11(releaseDir, directory));
|
|
33340
33443
|
}
|
|
33341
33444
|
}
|
|
33342
|
-
if (![...directories].every((directory) =>
|
|
33445
|
+
if (![...directories].every((directory) => lstatSync3(directory).isDirectory())) return false;
|
|
33343
33446
|
const files = ["manifest.json", "package.json", "node", ...Object.values(HOOK_RUNTIME_ENTRIES)];
|
|
33344
|
-
return files.every((relativePath) =>
|
|
33447
|
+
return files.every((relativePath) => lstatSync3(join11(releaseDir, relativePath)).isFile());
|
|
33345
33448
|
} catch {
|
|
33346
33449
|
return false;
|
|
33347
33450
|
}
|
|
33348
33451
|
}
|
|
33349
33452
|
function readReleaseManifest(releaseDir, releaseName) {
|
|
33350
33453
|
try {
|
|
33351
|
-
const manifestPath =
|
|
33454
|
+
const manifestPath = join11(releaseDir, "manifest.json");
|
|
33352
33455
|
const manifestStat = statSync2(manifestPath);
|
|
33353
33456
|
if (!manifestStat.isFile() || manifestStat.size > MAX_MANIFEST_BYTES) return null;
|
|
33354
|
-
const raw =
|
|
33457
|
+
const raw = readFileSync8(manifestPath, "utf8");
|
|
33355
33458
|
const parsed = JSON.parse(raw);
|
|
33356
33459
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
|
|
33357
33460
|
if (!exactKeys(parsed, ["schemaVersion", "version", "nodePath", "files"])) return null;
|
|
@@ -33373,7 +33476,7 @@ function readReleaseManifest(releaseDir, releaseName) {
|
|
|
33373
33476
|
function readSelectedRelease(paths) {
|
|
33374
33477
|
let raw;
|
|
33375
33478
|
try {
|
|
33376
|
-
raw =
|
|
33479
|
+
raw = readFileSync8(paths.current, "utf8");
|
|
33377
33480
|
} catch (error) {
|
|
33378
33481
|
if (error.code === "ENOENT") return null;
|
|
33379
33482
|
throw error;
|
|
@@ -33383,7 +33486,7 @@ function readSelectedRelease(paths) {
|
|
|
33383
33486
|
` !== raw || !RELEASE_NAME_RE.test(name)) {
|
|
33384
33487
|
throw new Error("cannot stage hook runtime: selected release is malformed");
|
|
33385
33488
|
}
|
|
33386
|
-
const dir =
|
|
33489
|
+
const dir = join11(paths.releasesDir, name);
|
|
33387
33490
|
const manifest = readReleaseManifest(dir, name);
|
|
33388
33491
|
if (!manifest) {
|
|
33389
33492
|
throw new Error("cannot stage hook runtime: immutable release is corrupt");
|
|
@@ -33393,7 +33496,7 @@ function readSelectedRelease(paths) {
|
|
|
33393
33496
|
function releaseEntries(paths) {
|
|
33394
33497
|
return readdirSync2(paths.releasesDir, { withFileTypes: true }).flatMap((entry) => {
|
|
33395
33498
|
if (!entry.isDirectory() || !RELEASE_NAME_RE.test(entry.name)) return [];
|
|
33396
|
-
const dir =
|
|
33499
|
+
const dir = join11(paths.releasesDir, entry.name);
|
|
33397
33500
|
try {
|
|
33398
33501
|
return [{ name: entry.name, dir, mtimeMs: statSync2(dir).mtimeMs }];
|
|
33399
33502
|
} catch {
|
|
@@ -33432,7 +33535,7 @@ function pruneReleases(paths, protectedNames, reserveSlots, now) {
|
|
|
33432
33535
|
function sourceManifest(sourceDir, version, nodePath) {
|
|
33433
33536
|
const files = {};
|
|
33434
33537
|
for (const [bin, relativePath] of Object.entries(SOURCE_ENTRIES)) {
|
|
33435
|
-
const source =
|
|
33538
|
+
const source = join11(sourceDir, relativePath);
|
|
33436
33539
|
if (!existsSync5(source) || !statSync2(source).isFile()) {
|
|
33437
33540
|
throw new Error(`cannot stage hook runtime: missing self-contained ${bin} bundle`);
|
|
33438
33541
|
}
|
|
@@ -33477,14 +33580,14 @@ function hasSafeRuntimeLayout(paths, selected) {
|
|
|
33477
33580
|
const releaseDirectories = /* @__PURE__ */ new Set([selected.dir]);
|
|
33478
33581
|
for (const relativePath of Object.values(HOOK_RUNTIME_ENTRIES)) {
|
|
33479
33582
|
for (let directory = dirname7(relativePath); directory !== "."; directory = dirname7(directory)) {
|
|
33480
|
-
releaseDirectories.add(
|
|
33583
|
+
releaseDirectories.add(join11(selected.dir, directory));
|
|
33481
33584
|
}
|
|
33482
33585
|
}
|
|
33483
|
-
if (!privateDirectory(paths.configDir) || !privateDirectory(paths.runtimeDir) || !privateDirectory(paths.releasesDir) || ![...releaseDirectories].every(privateDirectory) || !privateFile(paths.launcher, LAUNCHER_MODE) || !privateFile(paths.current, DATA_FILE_MODE) || !privateFile(
|
|
33586
|
+
if (!privateDirectory(paths.configDir) || !privateDirectory(paths.runtimeDir) || !privateDirectory(paths.releasesDir) || ![...releaseDirectories].every(privateDirectory) || !privateFile(paths.launcher, LAUNCHER_MODE) || !privateFile(paths.current, DATA_FILE_MODE) || !privateFile(join11(selected.dir, "manifest.json"), DATA_FILE_MODE) || !privateFile(join11(selected.dir, "package.json"), DATA_FILE_MODE) || !privateFile(join11(selected.dir, "node"), DATA_FILE_MODE)) {
|
|
33484
33587
|
return false;
|
|
33485
33588
|
}
|
|
33486
33589
|
return Object.values(HOOK_RUNTIME_ENTRIES).every(
|
|
33487
|
-
(relativePath) => privateFile(
|
|
33590
|
+
(relativePath) => privateFile(join11(selected.dir, relativePath), DATA_FILE_MODE)
|
|
33488
33591
|
);
|
|
33489
33592
|
}
|
|
33490
33593
|
function recordedNodeMatchesCurrentProcess(nodePath) {
|
|
@@ -33508,7 +33611,7 @@ function inspectHookRuntime(options = {}) {
|
|
|
33508
33611
|
if (!(launcher || selector)) return { state: "missing" };
|
|
33509
33612
|
if (!(launcher && selector)) return { state: "invalid" };
|
|
33510
33613
|
try {
|
|
33511
|
-
if (
|
|
33614
|
+
if (readFileSync8(paths.launcher, "utf8") !== STABLE_HOOK_LAUNCHER_CONTENT) {
|
|
33512
33615
|
return { state: "invalid" };
|
|
33513
33616
|
}
|
|
33514
33617
|
const selected = readSelectedRelease(paths);
|
|
@@ -33521,8 +33624,8 @@ function inspectHookRuntime(options = {}) {
|
|
|
33521
33624
|
}
|
|
33522
33625
|
}
|
|
33523
33626
|
function writeRelease(sourceDir, releaseDir, manifest, releasesDir) {
|
|
33524
|
-
const stagingDir = mkdtempSync(
|
|
33525
|
-
|
|
33627
|
+
const stagingDir = mkdtempSync(join11(releasesDir, ".stage-"));
|
|
33628
|
+
chmodSync4(stagingDir, DIRECTORY_MODE2);
|
|
33526
33629
|
try {
|
|
33527
33630
|
const directories = /* @__PURE__ */ new Set([stagingDir]);
|
|
33528
33631
|
const syncStagedFile = (path9) => {
|
|
@@ -33533,18 +33636,18 @@ function writeRelease(sourceDir, releaseDir, manifest, releasesDir) {
|
|
|
33533
33636
|
}
|
|
33534
33637
|
};
|
|
33535
33638
|
for (const [bin, targetRelative] of Object.entries(HOOK_RUNTIME_ENTRIES)) {
|
|
33536
|
-
const source =
|
|
33537
|
-
const target =
|
|
33639
|
+
const source = join11(sourceDir, SOURCE_ENTRIES[bin]);
|
|
33640
|
+
const target = join11(stagingDir, targetRelative);
|
|
33538
33641
|
mkdirSync6(dirname7(target), { recursive: true, mode: DIRECTORY_MODE2 });
|
|
33539
|
-
|
|
33642
|
+
chmodSync4(dirname7(target), DIRECTORY_MODE2);
|
|
33540
33643
|
copyFileSync(source, target);
|
|
33541
|
-
|
|
33644
|
+
chmodSync4(target, DATA_FILE_MODE);
|
|
33542
33645
|
if (sha2562(target) !== manifest.files[bin]) {
|
|
33543
33646
|
throw new Error(`cannot stage hook runtime: ${bin} changed while it was copied`);
|
|
33544
33647
|
}
|
|
33545
33648
|
syncStagedFile(target);
|
|
33546
33649
|
}
|
|
33547
|
-
const nodePath =
|
|
33650
|
+
const nodePath = join11(stagingDir, "node");
|
|
33548
33651
|
writeFileSync4(nodePath, `${manifest.nodePath}
|
|
33549
33652
|
`, {
|
|
33550
33653
|
encoding: "utf8",
|
|
@@ -33552,14 +33655,14 @@ function writeRelease(sourceDir, releaseDir, manifest, releasesDir) {
|
|
|
33552
33655
|
mode: DATA_FILE_MODE
|
|
33553
33656
|
});
|
|
33554
33657
|
syncStagedFile(nodePath);
|
|
33555
|
-
const packageJsonPath =
|
|
33658
|
+
const packageJsonPath = join11(stagingDir, "package.json");
|
|
33556
33659
|
writeFileSync4(packageJsonPath, runtimePackageJson(manifest), {
|
|
33557
33660
|
encoding: "utf8",
|
|
33558
33661
|
flag: "wx",
|
|
33559
33662
|
mode: DATA_FILE_MODE
|
|
33560
33663
|
});
|
|
33561
33664
|
syncStagedFile(packageJsonPath);
|
|
33562
|
-
const manifestPath =
|
|
33665
|
+
const manifestPath = join11(stagingDir, "manifest.json");
|
|
33563
33666
|
writeFileSync4(manifestPath, exactManifest(manifest), {
|
|
33564
33667
|
encoding: "utf8",
|
|
33565
33668
|
flag: "wx",
|
|
@@ -33590,7 +33693,7 @@ function stableNodePath(execPath = process.execPath, searchPath = process.env.PA
|
|
|
33590
33693
|
}
|
|
33591
33694
|
for (const directory of searchPath.split(delimiter)) {
|
|
33592
33695
|
if (!isAbsolute5(directory)) continue;
|
|
33593
|
-
const candidate =
|
|
33696
|
+
const candidate = join11(directory, "node");
|
|
33594
33697
|
try {
|
|
33595
33698
|
if (realpathSync2(candidate) === target) return candidate;
|
|
33596
33699
|
} catch {
|
|
@@ -33600,7 +33703,7 @@ function stableNodePath(execPath = process.execPath, searchPath = process.env.PA
|
|
|
33600
33703
|
}
|
|
33601
33704
|
function stageHookRuntime(options = {}) {
|
|
33602
33705
|
const root = packageRoot();
|
|
33603
|
-
const sourceDir = options.sourceDir ?? (root ?
|
|
33706
|
+
const sourceDir = options.sourceDir ?? (root ? join11(root, "dist", "hook-runtime") : null);
|
|
33604
33707
|
const version = options.version ?? packageVersion();
|
|
33605
33708
|
const nodePath = resolve4(options.nodePath ?? stableNodePath());
|
|
33606
33709
|
if (!sourceDir || !version || compareSemver(version, version) !== 0 || !isAbsolute5(nodePath) || /[\r\n]/u.test(nodePath)) {
|
|
@@ -33609,11 +33712,11 @@ function stageHookRuntime(options = {}) {
|
|
|
33609
33712
|
const manifest = sourceManifest(sourceDir, version, nodePath);
|
|
33610
33713
|
const paths = hookRuntimePaths(options);
|
|
33611
33714
|
const releaseName = `${RELEASE_PREFIX}${releaseId(manifest)}`;
|
|
33612
|
-
const releaseDir =
|
|
33715
|
+
const releaseDir = join11(paths.releasesDir, releaseName);
|
|
33613
33716
|
mkdirSync6(paths.releasesDir, { recursive: true, mode: DIRECTORY_MODE2 });
|
|
33614
|
-
|
|
33615
|
-
|
|
33616
|
-
|
|
33717
|
+
chmodSync4(paths.configDir, DIRECTORY_MODE2);
|
|
33718
|
+
chmodSync4(paths.runtimeDir, DIRECTORY_MODE2);
|
|
33719
|
+
chmodSync4(paths.releasesDir, DIRECTORY_MODE2);
|
|
33617
33720
|
return withFileLockSync(paths.selectionLock, () => {
|
|
33618
33721
|
const now = Date.now();
|
|
33619
33722
|
const selected = readSelectedRelease(paths);
|
|
@@ -33636,7 +33739,7 @@ function stageHookRuntime(options = {}) {
|
|
|
33636
33739
|
const finalRelease = selectRequested ? { name: releaseName, dir: releaseDir, manifest } : selected;
|
|
33637
33740
|
const launcherCurrent = (() => {
|
|
33638
33741
|
try {
|
|
33639
|
-
return
|
|
33742
|
+
return readFileSync8(paths.launcher, "utf8") === STABLE_HOOK_LAUNCHER_CONTENT;
|
|
33640
33743
|
} catch {
|
|
33641
33744
|
return false;
|
|
33642
33745
|
}
|
|
@@ -33680,7 +33783,7 @@ function stageHookRuntime(options = {}) {
|
|
|
33680
33783
|
}
|
|
33681
33784
|
function gitHookEntrypointCurrent(paths) {
|
|
33682
33785
|
try {
|
|
33683
|
-
return
|
|
33786
|
+
return readFileSync8(paths.gitHookEntrypoint, "utf8") === GIT_HOOK_ENTRYPOINT_CONTENT;
|
|
33684
33787
|
} catch {
|
|
33685
33788
|
return false;
|
|
33686
33789
|
}
|
|
@@ -33695,7 +33798,7 @@ function inspectGitHookEntrypoint(options = {}) {
|
|
|
33695
33798
|
try {
|
|
33696
33799
|
const entrypoint = lstatIfPresent(paths.gitHookEntrypoint);
|
|
33697
33800
|
if (!entrypoint) return "missing";
|
|
33698
|
-
if (!entrypoint.isFile() || (Number(entrypoint.mode) & 64) === 0 || !gitHookEntrypointCurrent(paths) ||
|
|
33801
|
+
if (!entrypoint.isFile() || (Number(entrypoint.mode) & 64) === 0 || !gitHookEntrypointCurrent(paths) || readFileSync8(paths.launcher, "utf8") !== STABLE_HOOK_LAUNCHER_CONTENT || !lstatIfPresent(paths.current)?.isFile()) {
|
|
33699
33802
|
return "invalid";
|
|
33700
33803
|
}
|
|
33701
33804
|
return "ready";
|
|
@@ -33705,7 +33808,7 @@ function inspectGitHookEntrypoint(options = {}) {
|
|
|
33705
33808
|
}
|
|
33706
33809
|
function lstatIfPresent(path9) {
|
|
33707
33810
|
try {
|
|
33708
|
-
return
|
|
33811
|
+
return lstatSync3(path9);
|
|
33709
33812
|
} catch (error) {
|
|
33710
33813
|
const code = error.code;
|
|
33711
33814
|
if (code === "ENOENT" || code === "ENOTDIR") return void 0;
|
|
@@ -33721,7 +33824,7 @@ function assertOwnedHookRuntime(paths) {
|
|
|
33721
33824
|
}
|
|
33722
33825
|
const launcher = lstatIfPresent(paths.launcher);
|
|
33723
33826
|
if (launcher) {
|
|
33724
|
-
if (!launcher.isFile() ||
|
|
33827
|
+
if (!launcher.isFile() || readFileSync8(paths.launcher, "utf8") !== STABLE_HOOK_LAUNCHER_CONTENT) {
|
|
33725
33828
|
throw new Error(`refusing to remove unrecognized hook launcher at ${paths.launcher}`);
|
|
33726
33829
|
}
|
|
33727
33830
|
}
|
|
@@ -33749,7 +33852,7 @@ function assertOwnedHookRuntime(paths) {
|
|
|
33749
33852
|
throw new Error(`refusing to remove non-directory hook releases at ${paths.releasesDir}`);
|
|
33750
33853
|
}
|
|
33751
33854
|
for (const entry of readdirSync2(paths.releasesDir, { withFileTypes: true })) {
|
|
33752
|
-
const releaseDir =
|
|
33855
|
+
const releaseDir = join11(paths.releasesDir, entry.name);
|
|
33753
33856
|
if (!entry.isDirectory() || !RELEASE_NAME_RE.test(entry.name) || !readReleaseManifest(releaseDir, entry.name)) {
|
|
33754
33857
|
throw new Error(`refusing to remove unrecognized hook release ${releaseDir}`);
|
|
33755
33858
|
}
|
|
@@ -33771,7 +33874,7 @@ function removeHookRuntime(options = {}) {
|
|
|
33771
33874
|
assertOwnedHookRuntime(paths);
|
|
33772
33875
|
if (lstatIfPresent(paths.gitHookEntrypoint)) rmSync4(paths.gitHookEntrypoint, { force: true });
|
|
33773
33876
|
if (lstatIfPresent(paths.launcher)) rmSync4(paths.launcher, { force: true });
|
|
33774
|
-
const quarantined = `${paths.runtimeDir}.uninstall-${String(process.pid)}-${
|
|
33877
|
+
const quarantined = `${paths.runtimeDir}.uninstall-${String(process.pid)}-${randomBytes3(8).toString("hex")}`;
|
|
33775
33878
|
renameSync2(paths.runtimeDir, quarantined);
|
|
33776
33879
|
rmSync4(quarantined, { recursive: true, force: true });
|
|
33777
33880
|
});
|
|
@@ -33913,7 +34016,7 @@ function realpathLoose(path9) {
|
|
|
33913
34016
|
let current = resolve5(path9);
|
|
33914
34017
|
for (; ; ) {
|
|
33915
34018
|
try {
|
|
33916
|
-
return
|
|
34019
|
+
return join12(realpathSync3.native(current), ...missing);
|
|
33917
34020
|
} catch {
|
|
33918
34021
|
const parent = dirname8(current);
|
|
33919
34022
|
if (parent === current) return resolve5(path9);
|
|
@@ -33928,7 +34031,7 @@ function isWithin(path9, directory) {
|
|
|
33928
34031
|
}
|
|
33929
34032
|
function primGitHooksDirectory() {
|
|
33930
34033
|
try {
|
|
33931
|
-
return
|
|
34034
|
+
return join12(primConfigDirectory(), "git-hooks");
|
|
33932
34035
|
} catch {
|
|
33933
34036
|
return void 0;
|
|
33934
34037
|
}
|
|
@@ -34034,7 +34137,7 @@ function resolveEffectiveGitHook(hookName, cwd = process.cwd()) {
|
|
|
34034
34137
|
}
|
|
34035
34138
|
function assertSafeFile(path9, spec) {
|
|
34036
34139
|
if (!existsSync6(path9)) return void 0;
|
|
34037
|
-
const stat =
|
|
34140
|
+
const stat = lstatSync4(path9);
|
|
34038
34141
|
if (!stat.isFile() || stat.isSymbolicLink() || stat.size > MAX_HOOK_BYTES) {
|
|
34039
34142
|
throw new Error(`unsafe ${spec.hookName} hook target: ${path9}`);
|
|
34040
34143
|
}
|
|
@@ -34064,7 +34167,7 @@ function assertUsableHuskyDispatcher(target, spec) {
|
|
|
34064
34167
|
}
|
|
34065
34168
|
}
|
|
34066
34169
|
function readHookFile(path9) {
|
|
34067
|
-
const value =
|
|
34170
|
+
const value = readFileSync9(path9);
|
|
34068
34171
|
return Buffer.isBuffer(value) ? value : Buffer.from(value);
|
|
34069
34172
|
}
|
|
34070
34173
|
function decodeHookText(content, spec) {
|
|
@@ -34137,11 +34240,11 @@ function blockInsertionPoint(content, allowShebangless, spec, huskyV8) {
|
|
|
34137
34240
|
var HUSKY_SPEC_MAJOR_RE = /^\s*[~^]?=?\s*v?([0-9]+)(?:\.(?:[0-9]+|[xX*])){0,2}(?:-[0-9A-Za-z.-]+)?\s*$/u;
|
|
34138
34241
|
function declaredHuskyMajor(dir) {
|
|
34139
34242
|
for (let current = resolve5(dir); ; ) {
|
|
34140
|
-
const manifest =
|
|
34243
|
+
const manifest = join12(current, "package.json");
|
|
34141
34244
|
if (existsSync6(manifest)) {
|
|
34142
34245
|
try {
|
|
34143
|
-
if (
|
|
34144
|
-
const parsed = JSON.parse(
|
|
34246
|
+
if (lstatSync4(manifest).size > MAX_HOOK_BYTES) return void 0;
|
|
34247
|
+
const parsed = JSON.parse(readFileSync9(manifest, "utf8"));
|
|
34145
34248
|
const range = parsed.devDependencies?.husky ?? parsed.dependencies?.husky;
|
|
34146
34249
|
const major = typeof range === "string" ? HUSKY_SPEC_MAJOR_RE.exec(range)?.[1] : void 0;
|
|
34147
34250
|
return major === void 0 ? void 0 : Number(major);
|
|
@@ -34150,15 +34253,15 @@ function declaredHuskyMajor(dir) {
|
|
|
34150
34253
|
}
|
|
34151
34254
|
}
|
|
34152
34255
|
const parent = dirname8(current);
|
|
34153
|
-
if (parent === current || existsSync6(
|
|
34256
|
+
if (parent === current || existsSync6(join12(current, ".git"))) return void 0;
|
|
34154
34257
|
current = parent;
|
|
34155
34258
|
}
|
|
34156
34259
|
}
|
|
34157
34260
|
function isHuskyV8Hook(hookPath) {
|
|
34158
|
-
const runtime =
|
|
34261
|
+
const runtime = join12(dirname8(hookPath), "_", "husky.sh");
|
|
34159
34262
|
try {
|
|
34160
|
-
const stat =
|
|
34161
|
-
return stat.isFile() && stat.size <= MAX_HOOK_BYTES &&
|
|
34263
|
+
const stat = lstatSync4(runtime);
|
|
34264
|
+
return stat.isFile() && stat.size <= MAX_HOOK_BYTES && readFileSync9(runtime, "utf8").includes("husky_skip_init");
|
|
34162
34265
|
} catch (error) {
|
|
34163
34266
|
if (errorCode(error) !== "ENOENT") return false;
|
|
34164
34267
|
}
|
|
@@ -34303,7 +34406,7 @@ function errorCode(error) {
|
|
|
34303
34406
|
function assertTargetUnchanged(path9, expected, spec, stat) {
|
|
34304
34407
|
let current;
|
|
34305
34408
|
try {
|
|
34306
|
-
current =
|
|
34409
|
+
current = lstatSync4(path9);
|
|
34307
34410
|
} catch (error) {
|
|
34308
34411
|
if (expected === void 0 && errorCode(error) === "ENOENT") return;
|
|
34309
34412
|
throw new Error(`${spec.hookName} hook changed concurrently: ${path9}`);
|
|
@@ -34824,13 +34927,13 @@ async function pollGitHubInstallIntent(client, start, options = {}) {
|
|
|
34824
34927
|
|
|
34825
34928
|
// src/commands/auth.ts
|
|
34826
34929
|
import { execFile } from "child_process";
|
|
34827
|
-
import { createHash as createHash7, randomBytes as
|
|
34828
|
-
import { existsSync as existsSync7, readFileSync as
|
|
34930
|
+
import { createHash as createHash7, randomBytes as randomBytes5 } from "crypto";
|
|
34931
|
+
import { existsSync as existsSync7, readFileSync as readFileSync10 } from "fs";
|
|
34829
34932
|
import { createServer } from "http";
|
|
34830
34933
|
import { platform } from "os";
|
|
34831
34934
|
|
|
34832
34935
|
// src/auth/api-keys.ts
|
|
34833
|
-
import { randomBytes as
|
|
34936
|
+
import { randomBytes as randomBytes4 } from "crypto";
|
|
34834
34937
|
var USER_API_KEY_TIMEOUT_MS = 1e4;
|
|
34835
34938
|
var USER_API_KEY_EXIT = {
|
|
34836
34939
|
ok: 0,
|
|
@@ -34841,7 +34944,7 @@ var USER_API_KEY_EXIT = {
|
|
|
34841
34944
|
};
|
|
34842
34945
|
var defaultDependencies2 = {
|
|
34843
34946
|
getClient: () => getPinnedManagementClient({ signal: AbortSignal.timeout(USER_API_KEY_TIMEOUT_MS) }),
|
|
34844
|
-
requestId: () =>
|
|
34947
|
+
requestId: () => randomBytes4(32).toString("hex"),
|
|
34845
34948
|
signal: () => AbortSignal.timeout(USER_API_KEY_TIMEOUT_MS),
|
|
34846
34949
|
writeStdout: (value) => console.log(value),
|
|
34847
34950
|
writeStderr: (value) => console.error(value)
|
|
@@ -35274,7 +35377,7 @@ function base64url(buffer) {
|
|
|
35274
35377
|
return buffer.toString("base64").replace(BASE64_PLUS_RE, "-").replace(BASE64_SLASH_RE, "_").replace(BASE64_PAD_RE, "");
|
|
35275
35378
|
}
|
|
35276
35379
|
function generatePkce() {
|
|
35277
|
-
const verifier = base64url(
|
|
35380
|
+
const verifier = base64url(randomBytes5(32));
|
|
35278
35381
|
const challenge = base64url(createHash7("sha256").update(verifier).digest());
|
|
35279
35382
|
return { verifier, challenge };
|
|
35280
35383
|
}
|
|
@@ -35388,7 +35491,7 @@ function reportSuccess() {
|
|
|
35388
35491
|
function hasStoredRefreshToken() {
|
|
35389
35492
|
if (!existsSync7(REFRESH_TOKEN_PATH)) return false;
|
|
35390
35493
|
try {
|
|
35391
|
-
return
|
|
35494
|
+
return readFileSync10(REFRESH_TOKEN_PATH, "utf-8").trim().length > 0;
|
|
35392
35495
|
} catch {
|
|
35393
35496
|
return false;
|
|
35394
35497
|
}
|
|
@@ -35574,7 +35677,7 @@ ${verificationUrl}`);
|
|
|
35574
35677
|
return;
|
|
35575
35678
|
}
|
|
35576
35679
|
const { verifier, challenge } = generatePkce();
|
|
35577
|
-
const state = base64url(
|
|
35680
|
+
const state = base64url(randomBytes5(16));
|
|
35578
35681
|
const redirectUri = `http://${LOCALHOST}:${CALLBACK_PORT}/callback`;
|
|
35579
35682
|
let settle;
|
|
35580
35683
|
const outcome = new Promise((resolve12) => {
|
|
@@ -35881,15 +35984,15 @@ function registerGithubCommands(program3, dependencies = defaultDependencies3) {
|
|
|
35881
35984
|
import { execFileSync as execFileSync5 } from "child_process";
|
|
35882
35985
|
import {
|
|
35883
35986
|
existsSync as existsSync8,
|
|
35884
|
-
lstatSync as
|
|
35987
|
+
lstatSync as lstatSync5,
|
|
35885
35988
|
mkdirSync as mkdirSync8,
|
|
35886
|
-
readFileSync as
|
|
35989
|
+
readFileSync as readFileSync11,
|
|
35887
35990
|
readdirSync as readdirSync3,
|
|
35888
35991
|
unlinkSync as unlinkSync3,
|
|
35889
35992
|
writeFileSync as writeFileSync6
|
|
35890
35993
|
} from "fs";
|
|
35891
35994
|
import { homedir as homedir4 } from "os";
|
|
35892
|
-
import { join as
|
|
35995
|
+
import { join as join13, resolve as resolve6 } from "path";
|
|
35893
35996
|
var PRE_COMMIT2 = { hookName: "pre-commit", binName: "prim-pre-commit" };
|
|
35894
35997
|
var POST_COMMIT2 = { hookName: "post-commit", binName: "prim-post-commit" };
|
|
35895
35998
|
var POST_REWRITE2 = { hookName: "post-rewrite", binName: "prim-post-rewrite" };
|
|
@@ -35930,7 +36033,7 @@ function detectHusky(gitRoot) {
|
|
|
35930
36033
|
const pkgPath = resolve6(gitRoot, "package.json");
|
|
35931
36034
|
if (existsSync8(pkgPath)) {
|
|
35932
36035
|
try {
|
|
35933
|
-
const pkg2 = JSON.parse(
|
|
36036
|
+
const pkg2 = JSON.parse(readFileSync11(pkgPath, "utf-8"));
|
|
35934
36037
|
const scripts = pkg2.scripts ?? {};
|
|
35935
36038
|
if (/husky/i.test(scripts.prepare ?? "") || /husky/i.test(scripts.postinstall ?? "")) {
|
|
35936
36039
|
return true;
|
|
@@ -35940,9 +36043,9 @@ function detectHusky(gitRoot) {
|
|
|
35940
36043
|
}
|
|
35941
36044
|
return false;
|
|
35942
36045
|
}
|
|
35943
|
-
var PRIM_GIT_HOOKS_DIR =
|
|
36046
|
+
var PRIM_GIT_HOOKS_DIR = join13(primConfigDirectory(), "git-hooks");
|
|
35944
36047
|
function expandTilde(p) {
|
|
35945
|
-
return p.startsWith("~/") ?
|
|
36048
|
+
return p.startsWith("~/") ? join13(homedir4(), p.slice(2)) : p;
|
|
35946
36049
|
}
|
|
35947
36050
|
function isOurHooksDir(value) {
|
|
35948
36051
|
return value !== "" && expandTilde(value) === PRIM_GIT_HOOKS_DIR;
|
|
@@ -36022,7 +36125,7 @@ function isExpectedOwnedGlobalHook(content, hookName) {
|
|
|
36022
36125
|
}
|
|
36023
36126
|
function lstatIfPresent2(path9) {
|
|
36024
36127
|
try {
|
|
36025
|
-
return
|
|
36128
|
+
return lstatSync5(path9);
|
|
36026
36129
|
} catch (error) {
|
|
36027
36130
|
const code = error.code;
|
|
36028
36131
|
if (code === "ENOENT" || code === "ENOTDIR") return void 0;
|
|
@@ -36045,8 +36148,8 @@ function assertOwnedHooksDirectorySafeToRemove() {
|
|
|
36045
36148
|
);
|
|
36046
36149
|
}
|
|
36047
36150
|
const path9 = resolve6(PRIM_GIT_HOOKS_DIR, name);
|
|
36048
|
-
const stat =
|
|
36049
|
-
if (!stat.isFile() || stat.isSymbolicLink() || !isExpectedOwnedGlobalHook(
|
|
36151
|
+
const stat = lstatSync5(path9);
|
|
36152
|
+
if (!stat.isFile() || stat.isSymbolicLink() || !isExpectedOwnedGlobalHook(readFileSync11(path9, "utf-8"), name)) {
|
|
36050
36153
|
throw new Error(`refusing to remove global hooks: ${path9} is not an exact Prim-owned hook`);
|
|
36051
36154
|
}
|
|
36052
36155
|
}
|
|
@@ -36084,7 +36187,7 @@ function stripPrimBlock(hookPath, spec) {
|
|
|
36084
36187
|
}
|
|
36085
36188
|
function planPreCommitRemoval(hookPath, options) {
|
|
36086
36189
|
if (!existsSync8(hookPath)) return { path: hookPath, action: "missing" };
|
|
36087
|
-
const existing =
|
|
36190
|
+
const existing = readFileSync11(hookPath, "utf-8");
|
|
36088
36191
|
if (options.allowOwnedStandalone && isOwnedStandalonePreCommit(existing)) {
|
|
36089
36192
|
return { path: hookPath, action: "remove-owned-file" };
|
|
36090
36193
|
}
|
|
@@ -36614,9 +36717,9 @@ function registerActivationCommands(program3) {
|
|
|
36614
36717
|
}
|
|
36615
36718
|
|
|
36616
36719
|
// src/commands/claude-install.ts
|
|
36617
|
-
import { existsSync as existsSync9, readFileSync as
|
|
36720
|
+
import { existsSync as existsSync9, readFileSync as readFileSync12 } from "fs";
|
|
36618
36721
|
import { homedir as homedir5 } from "os";
|
|
36619
|
-
import { join as
|
|
36722
|
+
import { join as join14 } from "path";
|
|
36620
36723
|
var CAPTURE_BIN = "prim-hook";
|
|
36621
36724
|
var GATE_BIN = "prim-pre-tool-use";
|
|
36622
36725
|
var POST_TOOL_USE_BIN = "prim-post-tool-use";
|
|
@@ -36634,11 +36737,11 @@ var PRIM_BINS = [
|
|
|
36634
36737
|
SESSION_END_BIN
|
|
36635
36738
|
];
|
|
36636
36739
|
var JSON_INDENT = 2;
|
|
36637
|
-
var USER_SCOPE_PATH =
|
|
36740
|
+
var USER_SCOPE_PATH = join14(homedir5(), ".claude", "settings.json");
|
|
36638
36741
|
function projectRoot() {
|
|
36639
36742
|
return gitToplevel() ?? process.cwd();
|
|
36640
36743
|
}
|
|
36641
|
-
var projectScopePath = () =>
|
|
36744
|
+
var projectScopePath = () => join14(projectRoot(), ".claude", "settings.json");
|
|
36642
36745
|
var CAPTURE_EVENTS = [
|
|
36643
36746
|
"SessionStart",
|
|
36644
36747
|
"UserPromptSubmit",
|
|
@@ -36692,7 +36795,7 @@ function readSettings(path9) {
|
|
|
36692
36795
|
if (!existsSync9(path9)) {
|
|
36693
36796
|
return {};
|
|
36694
36797
|
}
|
|
36695
|
-
const raw =
|
|
36798
|
+
const raw = readFileSync12(path9, "utf-8");
|
|
36696
36799
|
try {
|
|
36697
36800
|
return JSON.parse(raw);
|
|
36698
36801
|
} catch (err) {
|
|
@@ -36896,7 +36999,7 @@ function statuslineState(settings) {
|
|
|
36896
36999
|
function isGateInstalled(settings) {
|
|
36897
37000
|
return (settings.hooks?.PreToolUse ?? []).some((e) => entryHasCommand(e, GATE_BIN));
|
|
36898
37001
|
}
|
|
36899
|
-
function
|
|
37002
|
+
function atomicWrite3(path9, content) {
|
|
36900
37003
|
atomicWriteFile(path9, `${JSON.stringify(content, null, JSON_INDENT)}
|
|
36901
37004
|
`, {
|
|
36902
37005
|
ensureParent: true
|
|
@@ -36920,7 +37023,7 @@ function performInstall(scope, force) {
|
|
|
36920
37023
|
});
|
|
36921
37024
|
const changed = JSON.stringify(before) !== JSON.stringify(after);
|
|
36922
37025
|
if (changed) {
|
|
36923
|
-
|
|
37026
|
+
atomicWrite3(path9, after);
|
|
36924
37027
|
}
|
|
36925
37028
|
return {
|
|
36926
37029
|
scope,
|
|
@@ -36939,7 +37042,7 @@ function performUninstall(scope) {
|
|
|
36939
37042
|
const after = applyUninstall(before);
|
|
36940
37043
|
const changed = JSON.stringify(before) !== JSON.stringify(after);
|
|
36941
37044
|
if (changed) {
|
|
36942
|
-
|
|
37045
|
+
atomicWrite3(path9, after);
|
|
36943
37046
|
}
|
|
36944
37047
|
return {
|
|
36945
37048
|
scope,
|
|
@@ -36958,7 +37061,7 @@ function performPermissionInstall(scope) {
|
|
|
36958
37061
|
const after = applyAutoModeTrust(applyPermissions(before));
|
|
36959
37062
|
const changed = JSON.stringify(before) !== JSON.stringify(after);
|
|
36960
37063
|
if (changed) {
|
|
36961
|
-
|
|
37064
|
+
atomicWrite3(path9, after);
|
|
36962
37065
|
}
|
|
36963
37066
|
return {
|
|
36964
37067
|
scope,
|
|
@@ -37061,7 +37164,7 @@ ${line("project", result.project)}`);
|
|
|
37061
37164
|
|
|
37062
37165
|
// src/commands/codex-install.ts
|
|
37063
37166
|
import { homedir as homedir6 } from "os";
|
|
37064
|
-
import { join as
|
|
37167
|
+
import { join as join15 } from "path";
|
|
37065
37168
|
var CAPTURE_BIN2 = "prim-hook";
|
|
37066
37169
|
var GATE_BIN2 = "prim-pre-tool-use";
|
|
37067
37170
|
var POST_TOOL_USE_BIN2 = "prim-post-tool-use";
|
|
@@ -37085,8 +37188,8 @@ var CODEX_REGISTRATIONS = [
|
|
|
37085
37188
|
makeRegistration("PostToolUse", CODEX_POST_TOOL_MATCHER, POST_TOOL_USE_BIN2, CODEX_ARGS),
|
|
37086
37189
|
makeRegistration("SessionStart", "*", SESSION_START_BIN2, CODEX_ARGS)
|
|
37087
37190
|
];
|
|
37088
|
-
var USER_SCOPE_PATH2 =
|
|
37089
|
-
var projectScopePath2 = () =>
|
|
37191
|
+
var USER_SCOPE_PATH2 = join15(homedir6(), ".codex", "hooks.json");
|
|
37192
|
+
var projectScopePath2 = () => join15(projectRoot(), ".codex", "hooks.json");
|
|
37090
37193
|
function settingsPathFor2(scope) {
|
|
37091
37194
|
return scope === "user" ? USER_SCOPE_PATH2 : projectScopePath2();
|
|
37092
37195
|
}
|
|
@@ -37166,7 +37269,7 @@ function performInstall2(scope, force) {
|
|
|
37166
37269
|
const after = applyInstall2(before, { force });
|
|
37167
37270
|
const changed = JSON.stringify(before) !== JSON.stringify(after);
|
|
37168
37271
|
if (changed) {
|
|
37169
|
-
|
|
37272
|
+
atomicWrite3(path9, after);
|
|
37170
37273
|
}
|
|
37171
37274
|
return resultFor(scope, path9, after, changed);
|
|
37172
37275
|
}
|
|
@@ -37176,7 +37279,7 @@ function performUninstall2(scope) {
|
|
|
37176
37279
|
const after = applyUninstall2(before);
|
|
37177
37280
|
const changed = JSON.stringify(before) !== JSON.stringify(after);
|
|
37178
37281
|
if (changed) {
|
|
37179
|
-
|
|
37282
|
+
atomicWrite3(path9, after);
|
|
37180
37283
|
}
|
|
37181
37284
|
return resultFor(scope, path9, after, changed);
|
|
37182
37285
|
}
|
|
@@ -37197,7 +37300,7 @@ function uncoveredWorktreeHooks(status) {
|
|
|
37197
37300
|
if (status.user.present || status.project.present) return null;
|
|
37198
37301
|
const main = mainWorktreeRoot();
|
|
37199
37302
|
if (main === null) return null;
|
|
37200
|
-
const path9 =
|
|
37303
|
+
const path9 = join15(main, ".codex", "hooks.json");
|
|
37201
37304
|
return hasAnyHookRegistration2(readSettings(path9)) ? path9 : null;
|
|
37202
37305
|
}
|
|
37203
37306
|
function uncoveredWorktreeAdvice(path9) {
|
|
@@ -37257,9 +37360,9 @@ ${line("project", result.project)}`);
|
|
|
37257
37360
|
}
|
|
37258
37361
|
|
|
37259
37362
|
// src/commands/cursor-install.ts
|
|
37260
|
-
import { existsSync as existsSync10, readFileSync as
|
|
37363
|
+
import { existsSync as existsSync10, readFileSync as readFileSync13 } from "fs";
|
|
37261
37364
|
import { homedir as homedir7 } from "os";
|
|
37262
|
-
import { isAbsolute as isAbsolute7, join as
|
|
37365
|
+
import { isAbsolute as isAbsolute7, join as join16 } from "path";
|
|
37263
37366
|
var CAPTURE_BIN3 = "prim-hook";
|
|
37264
37367
|
var GATE_BIN3 = "prim-pre-tool-use";
|
|
37265
37368
|
var POST_TOOL_BIN = "prim-post-tool-use";
|
|
@@ -37290,14 +37393,14 @@ function cursorConfigDirectory(env4 = process.env, home = homedir7(), platform2
|
|
|
37290
37393
|
const explicit = env4.CURSOR_CONFIG_DIR?.trim();
|
|
37291
37394
|
if (explicit && isAbsolute7(explicit)) return explicit;
|
|
37292
37395
|
const xdg = env4.XDG_CONFIG_HOME?.trim();
|
|
37293
|
-
if (platform2 !== "darwin" && xdg && isAbsolute7(xdg)) return
|
|
37294
|
-
return
|
|
37396
|
+
if (platform2 !== "darwin" && xdg && isAbsolute7(xdg)) return join16(xdg, "cursor");
|
|
37397
|
+
return join16(home, ".cursor");
|
|
37295
37398
|
}
|
|
37296
37399
|
function cursorHooksPath(scope, root = projectRoot()) {
|
|
37297
|
-
return scope === "user" ?
|
|
37400
|
+
return scope === "user" ? join16(cursorConfigDirectory(), "hooks.json") : join16(root, ".cursor", "hooks.json");
|
|
37298
37401
|
}
|
|
37299
37402
|
function cursorCliConfigPath() {
|
|
37300
|
-
return
|
|
37403
|
+
return join16(cursorConfigDirectory(), "cli-config.json");
|
|
37301
37404
|
}
|
|
37302
37405
|
function plainObject(value) {
|
|
37303
37406
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -37306,7 +37409,7 @@ function readCursorHooks(path9) {
|
|
|
37306
37409
|
if (!existsSync10(path9)) return {};
|
|
37307
37410
|
let parsed;
|
|
37308
37411
|
try {
|
|
37309
|
-
parsed = JSON.parse(
|
|
37412
|
+
parsed = JSON.parse(readFileSync13(path9, "utf8"));
|
|
37310
37413
|
} catch {
|
|
37311
37414
|
throw new Error(`invalid Cursor hooks JSON at ${path9}`);
|
|
37312
37415
|
}
|
|
@@ -37328,7 +37431,7 @@ function readObject(path9) {
|
|
|
37328
37431
|
if (!existsSync10(path9)) return {};
|
|
37329
37432
|
let parsed;
|
|
37330
37433
|
try {
|
|
37331
|
-
parsed = JSON.parse(
|
|
37434
|
+
parsed = JSON.parse(readFileSync13(path9, "utf8"));
|
|
37332
37435
|
} catch {
|
|
37333
37436
|
throw new Error(`invalid Cursor CLI config JSON at ${path9}`);
|
|
37334
37437
|
}
|
|
@@ -37546,12 +37649,12 @@ function registerCursorCommands(program3) {
|
|
|
37546
37649
|
|
|
37547
37650
|
// src/commands/daemon.ts
|
|
37548
37651
|
import { spawn as spawn3 } from "child_process";
|
|
37549
|
-
import { closeSync as closeSync4, existsSync as existsSync12, mkdirSync as mkdirSync10, openSync as openSync4, readFileSync as
|
|
37550
|
-
import { join as
|
|
37652
|
+
import { closeSync as closeSync4, existsSync as existsSync12, mkdirSync as mkdirSync10, openSync as openSync4, readFileSync as readFileSync15, unlinkSync as unlinkSync4 } from "fs";
|
|
37653
|
+
import { join as join19 } from "path";
|
|
37551
37654
|
|
|
37552
37655
|
// src/daemon/latest-bootstrap.ts
|
|
37553
37656
|
import { spawn as spawn2 } from "child_process";
|
|
37554
|
-
import { join as
|
|
37657
|
+
import { join as join17 } from "path";
|
|
37555
37658
|
var LATEST_BOOTSTRAP_TIMEOUT_MS = 45e3;
|
|
37556
37659
|
var LATEST_BOOTSTRAP_LOCK_NAME = "daemon-latest.lock";
|
|
37557
37660
|
async function runPinnedEnsure(options) {
|
|
@@ -37592,7 +37695,7 @@ async function runPinnedEnsure(options) {
|
|
|
37592
37695
|
});
|
|
37593
37696
|
}
|
|
37594
37697
|
async function runLatestDaemonBootstrap(ensureCurrent, options = {}) {
|
|
37595
|
-
const lockPath = options.lockPath ??
|
|
37698
|
+
const lockPath = options.lockPath ?? join17(
|
|
37596
37699
|
primConfigDirectory({ env: options.env, homeDir: options.homeDir }),
|
|
37597
37700
|
LATEST_BOOTSTRAP_LOCK_NAME
|
|
37598
37701
|
);
|
|
@@ -37616,17 +37719,17 @@ async function runLatestDaemonBootstrap(ensureCurrent, options = {}) {
|
|
|
37616
37719
|
|
|
37617
37720
|
// src/daemon/launchd.ts
|
|
37618
37721
|
import { spawnSync } from "child_process";
|
|
37619
|
-
import { createHash as createHash8, randomBytes as
|
|
37722
|
+
import { createHash as createHash8, randomBytes as randomBytes6 } from "crypto";
|
|
37620
37723
|
import {
|
|
37621
37724
|
constants as constants5,
|
|
37622
37725
|
accessSync as accessSync2,
|
|
37623
|
-
chmodSync as
|
|
37726
|
+
chmodSync as chmodSync5,
|
|
37624
37727
|
copyFileSync as copyFileSync2,
|
|
37625
37728
|
existsSync as existsSync11,
|
|
37626
|
-
lstatSync as
|
|
37729
|
+
lstatSync as lstatSync7,
|
|
37627
37730
|
mkdirSync as mkdirSync9,
|
|
37628
37731
|
mkdtempSync as mkdtempSync2,
|
|
37629
|
-
readFileSync as
|
|
37732
|
+
readFileSync as readFileSync14,
|
|
37630
37733
|
readdirSync as readdirSync4,
|
|
37631
37734
|
readlinkSync,
|
|
37632
37735
|
realpathSync as realpathSync4,
|
|
@@ -37637,14 +37740,14 @@ import {
|
|
|
37637
37740
|
writeFileSync as writeFileSync7
|
|
37638
37741
|
} from "fs";
|
|
37639
37742
|
import { homedir as homedir8 } from "os";
|
|
37640
|
-
import { basename as basename3, dirname as dirname10, isAbsolute as isAbsolute8, join as
|
|
37743
|
+
import { basename as basename3, dirname as dirname10, isAbsolute as isAbsolute8, join as join18, resolve as resolve7 } from "path";
|
|
37641
37744
|
|
|
37642
37745
|
// src/lib/bounded-file.ts
|
|
37643
|
-
import { constants as constants4, closeSync as closeSync3, fstatSync, lstatSync as
|
|
37746
|
+
import { constants as constants4, closeSync as closeSync3, fstatSync, lstatSync as lstatSync6, openSync as openSync3, readSync } from "fs";
|
|
37644
37747
|
function readBoundedRegularFile(path9, maxBytes) {
|
|
37645
37748
|
let fd;
|
|
37646
37749
|
try {
|
|
37647
|
-
const linked =
|
|
37750
|
+
const linked = lstatSync6(path9);
|
|
37648
37751
|
if (!linked.isFile() || linked.size > maxBytes) return void 0;
|
|
37649
37752
|
fd = openSync3(path9, constants4.O_RDONLY | constants4.O_NOFOLLOW | constants4.O_NONBLOCK);
|
|
37650
37753
|
const opened = fstatSync(fd);
|
|
@@ -37719,31 +37822,31 @@ var LaunchctlError = class extends Error {
|
|
|
37719
37822
|
function xdgDataHome(options) {
|
|
37720
37823
|
const home = options.homeDir ?? homedir8();
|
|
37721
37824
|
const configured = (options.env ?? process.env).XDG_DATA_HOME;
|
|
37722
|
-
return configured && isAbsolute8(configured) ? configured :
|
|
37825
|
+
return configured && isAbsolute8(configured) ? configured : join18(home, ".local", "share");
|
|
37723
37826
|
}
|
|
37724
37827
|
function runtimePaths(options = {}) {
|
|
37725
|
-
const dataDir =
|
|
37726
|
-
const runtimeDir =
|
|
37727
|
-
const currentLink =
|
|
37828
|
+
const dataDir = join18(xdgDataHome(options), "prim");
|
|
37829
|
+
const runtimeDir = join18(dataDir, "runtime");
|
|
37830
|
+
const currentLink = join18(runtimeDir, "current");
|
|
37728
37831
|
return {
|
|
37729
37832
|
dataDir,
|
|
37730
37833
|
runtimeDir,
|
|
37731
|
-
releasesDir:
|
|
37834
|
+
releasesDir: join18(runtimeDir, "releases"),
|
|
37732
37835
|
currentLink,
|
|
37733
|
-
statuslineLauncher:
|
|
37734
|
-
disabledMarker:
|
|
37735
|
-
lifecycleLockDir:
|
|
37836
|
+
statuslineLauncher: join18(runtimeDir, "prim-statusline"),
|
|
37837
|
+
disabledMarker: join18(dataDir, "daemon.disabled"),
|
|
37838
|
+
lifecycleLockDir: join18(dataDir, "daemon.lifecycle.lock")
|
|
37736
37839
|
};
|
|
37737
37840
|
}
|
|
37738
37841
|
function daemonControlPaths(options = {}) {
|
|
37739
37842
|
const configDir = primConfigDirectory(options);
|
|
37740
37843
|
const legacy = runtimePaths(options);
|
|
37741
37844
|
return {
|
|
37742
|
-
launcher:
|
|
37743
|
-
disabledMarker:
|
|
37744
|
-
driftHealMarker:
|
|
37745
|
-
driftHealClaim:
|
|
37746
|
-
lifecycleLockDir:
|
|
37845
|
+
launcher: join18(configDir, `prim-daemon-launcher-v${LAUNCHER_SCHEMA_VERSION}`),
|
|
37846
|
+
disabledMarker: join18(configDir, "daemon.disabled"),
|
|
37847
|
+
driftHealMarker: join18(configDir, DRIFT_HEAL_MARKER),
|
|
37848
|
+
driftHealClaim: join18(configDir, "daemon-drift-heal.lock"),
|
|
37849
|
+
lifecycleLockDir: join18(configDir, "daemon.lifecycle.lock"),
|
|
37747
37850
|
legacyDisabledMarker: legacy.disabledMarker,
|
|
37748
37851
|
legacyLifecycleLockDir: legacy.lifecycleLockDir
|
|
37749
37852
|
};
|
|
@@ -37751,10 +37854,10 @@ function daemonControlPaths(options = {}) {
|
|
|
37751
37854
|
function findPackageVersion(entryFile) {
|
|
37752
37855
|
let dir = dirname10(resolve7(entryFile));
|
|
37753
37856
|
for (let depth = 0; depth < 6; depth++) {
|
|
37754
|
-
const packagePath =
|
|
37857
|
+
const packagePath = join18(dir, "package.json");
|
|
37755
37858
|
if (existsSync11(packagePath)) {
|
|
37756
37859
|
try {
|
|
37757
|
-
const manifest = JSON.parse(
|
|
37860
|
+
const manifest = JSON.parse(readFileSync14(packagePath, "utf8"));
|
|
37758
37861
|
if (manifest.name === "@primitive.ai/prim" && manifest.version) {
|
|
37759
37862
|
return manifest.version;
|
|
37760
37863
|
}
|
|
@@ -37769,7 +37872,7 @@ function findPackageVersion(entryFile) {
|
|
|
37769
37872
|
}
|
|
37770
37873
|
function readRuntimeManifest(path9) {
|
|
37771
37874
|
try {
|
|
37772
|
-
const parsed = JSON.parse(
|
|
37875
|
+
const parsed = JSON.parse(readFileSync14(path9, "utf8"));
|
|
37773
37876
|
if (parsed.schemaVersion !== RUNTIME_SCHEMA_VERSION || typeof parsed.version !== "string" || typeof parsed.nodePath !== "string" || parsed.daemonFile !== "prim-daemon-server" || typeof parsed.daemonSha256 !== "string" || !/^[a-f0-9]{64}$/u.test(parsed.daemonSha256)) {
|
|
37774
37877
|
return null;
|
|
37775
37878
|
}
|
|
@@ -37785,10 +37888,10 @@ function exactKeys2(value, expected) {
|
|
|
37785
37888
|
return actual.length === wanted.length && actual.every((key, index) => key === wanted[index]);
|
|
37786
37889
|
}
|
|
37787
37890
|
function readOwnedRuntimeManifest(releaseDir) {
|
|
37788
|
-
const manifestPath =
|
|
37789
|
-
const daemonPath =
|
|
37891
|
+
const manifestPath = join18(releaseDir, "manifest.json");
|
|
37892
|
+
const daemonPath = join18(releaseDir, "prim-daemon-server");
|
|
37790
37893
|
try {
|
|
37791
|
-
const raw =
|
|
37894
|
+
const raw = readFileSync14(manifestPath, "utf8");
|
|
37792
37895
|
const parsed = JSON.parse(raw);
|
|
37793
37896
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
|
|
37794
37897
|
if (!exactKeys2(parsed, [
|
|
@@ -37803,7 +37906,7 @@ function readOwnedRuntimeManifest(releaseDir) {
|
|
|
37803
37906
|
}
|
|
37804
37907
|
const manifest = parsed;
|
|
37805
37908
|
if (manifest.schemaVersion !== RUNTIME_SCHEMA_VERSION || compareSemver(manifest.version, manifest.version) !== 0 || !isAbsolute8(manifest.nodePath) || /[\r\n]/u.test(manifest.nodePath) || manifest.daemonFile !== "prim-daemon-server" || !/^[0-9a-f]{64}$/u.test(manifest.daemonSha256) || new Date(manifest.stagedAt).toISOString() !== manifest.stagedAt || raw !== `${JSON.stringify(manifest, null, 2)}
|
|
37806
|
-
` || !
|
|
37909
|
+
` || !lstatSync7(daemonPath).isFile() || sha256File(daemonPath) !== manifest.daemonSha256) {
|
|
37807
37910
|
return null;
|
|
37808
37911
|
}
|
|
37809
37912
|
const entries = readdirSync4(releaseDir).sort();
|
|
@@ -37832,7 +37935,7 @@ function sameRuntime(current, desired, daemonPath) {
|
|
|
37832
37935
|
}
|
|
37833
37936
|
}
|
|
37834
37937
|
function sha256File(path9) {
|
|
37835
|
-
return createHash8("sha256").update(
|
|
37938
|
+
return createHash8("sha256").update(readFileSync14(path9)).digest("hex");
|
|
37836
37939
|
}
|
|
37837
37940
|
function atomicSymlink(target, linkPath) {
|
|
37838
37941
|
const tempLink = `${linkPath}.tmp-${process.pid}-${createHash8("sha256").update(`${target}\0${Date.now()}\0${Math.random()}`).digest("hex").slice(0, 12)}`;
|
|
@@ -37865,11 +37968,11 @@ function stageRuntime(options = {}) {
|
|
|
37865
37968
|
currentRelease = realpathSync4(paths.currentLink);
|
|
37866
37969
|
} catch {
|
|
37867
37970
|
}
|
|
37868
|
-
const current = currentRelease ? readRuntimeManifest(
|
|
37869
|
-
const currentDaemon = currentRelease ?
|
|
37971
|
+
const current = currentRelease ? readRuntimeManifest(join18(currentRelease, "manifest.json")) : null;
|
|
37972
|
+
const currentDaemon = currentRelease ? join18(currentRelease, desired.daemonFile) : "";
|
|
37870
37973
|
if (currentRelease && sameRuntime(current, desired, currentDaemon)) {
|
|
37871
37974
|
const manifest = current;
|
|
37872
|
-
|
|
37975
|
+
atomicWrite4(
|
|
37873
37976
|
paths.statuslineLauncher,
|
|
37874
37977
|
statuslineLauncherContent(manifest.version, options),
|
|
37875
37978
|
RUNTIME_LAUNCHER_MODE
|
|
@@ -37882,19 +37985,19 @@ function stageRuntime(options = {}) {
|
|
|
37882
37985
|
};
|
|
37883
37986
|
}
|
|
37884
37987
|
mkdirSync9(paths.releasesDir, { recursive: true, mode: RUNTIME_DIR_MODE });
|
|
37885
|
-
|
|
37886
|
-
|
|
37887
|
-
const stagingDir = mkdtempSync2(
|
|
37888
|
-
|
|
37988
|
+
chmodSync5(paths.runtimeDir, RUNTIME_DIR_MODE);
|
|
37989
|
+
chmodSync5(paths.releasesDir, RUNTIME_DIR_MODE);
|
|
37990
|
+
const stagingDir = mkdtempSync2(join18(paths.releasesDir, ".stage-"));
|
|
37991
|
+
chmodSync5(stagingDir, RUNTIME_DIR_MODE);
|
|
37889
37992
|
let releaseDir;
|
|
37890
37993
|
try {
|
|
37891
|
-
const daemonTarget =
|
|
37994
|
+
const daemonTarget = join18(stagingDir, desired.daemonFile);
|
|
37892
37995
|
copyFileSync2(daemonSource, daemonTarget);
|
|
37893
|
-
|
|
37996
|
+
chmodSync5(daemonTarget, RUNTIME_FILE_MODE);
|
|
37894
37997
|
if (sha256File(daemonTarget) !== desired.daemonSha256) {
|
|
37895
37998
|
throw new Error("cannot stage runtime: daemon bundle changed while it was copied");
|
|
37896
37999
|
}
|
|
37897
|
-
const manifestTarget =
|
|
38000
|
+
const manifestTarget = join18(stagingDir, "manifest.json");
|
|
37898
38001
|
writeFileSync7(manifestTarget, `${JSON.stringify(desired, null, 2)}
|
|
37899
38002
|
`, {
|
|
37900
38003
|
encoding: "utf8",
|
|
@@ -37902,11 +38005,11 @@ function stageRuntime(options = {}) {
|
|
|
37902
38005
|
flag: "wx"
|
|
37903
38006
|
});
|
|
37904
38007
|
const releaseName = `release-${createHash8("sha256").update(`${version}\0${nodePath}\0${desired.stagedAt}\0${process.pid}\0${Math.random()}`).digest("hex").slice(0, 16)}`;
|
|
37905
|
-
releaseDir =
|
|
38008
|
+
releaseDir = join18(paths.releasesDir, releaseName);
|
|
37906
38009
|
renameSync4(stagingDir, releaseDir);
|
|
37907
38010
|
releaseDir = realpathSync4(releaseDir);
|
|
37908
|
-
atomicSymlink(
|
|
37909
|
-
|
|
38011
|
+
atomicSymlink(join18("releases", releaseName), paths.currentLink);
|
|
38012
|
+
atomicWrite4(
|
|
37910
38013
|
paths.statuslineLauncher,
|
|
37911
38014
|
statuslineLauncherContent(desired.version, options),
|
|
37912
38015
|
RUNTIME_LAUNCHER_MODE
|
|
@@ -37919,14 +38022,14 @@ function stageRuntime(options = {}) {
|
|
|
37919
38022
|
changed: true,
|
|
37920
38023
|
manifest: desired,
|
|
37921
38024
|
paths,
|
|
37922
|
-
daemonPath:
|
|
38025
|
+
daemonPath: join18(releaseDir, desired.daemonFile)
|
|
37923
38026
|
};
|
|
37924
38027
|
}
|
|
37925
38028
|
function shellQuote2(value) {
|
|
37926
38029
|
return `'${value.replaceAll("'", `'"'"'`)}'`;
|
|
37927
38030
|
}
|
|
37928
38031
|
function statuslineLauncherContent(version, options = {}) {
|
|
37929
|
-
const socketPath =
|
|
38032
|
+
const socketPath = join18(primConfigDirectory(options), "sock");
|
|
37930
38033
|
const fallback = `primitive ${version} (daemon: down)`;
|
|
37931
38034
|
return `#!/bin/sh
|
|
37932
38035
|
response=$(
|
|
@@ -37949,7 +38052,7 @@ function assertRegularFile(path9, label) {
|
|
|
37949
38052
|
}
|
|
37950
38053
|
function lstatIfPresent3(path9) {
|
|
37951
38054
|
try {
|
|
37952
|
-
return
|
|
38055
|
+
return lstatSync7(path9);
|
|
37953
38056
|
} catch (error) {
|
|
37954
38057
|
const code = error.code;
|
|
37955
38058
|
if (code === "ENOENT" || code === "ENOTDIR") return void 0;
|
|
@@ -37958,7 +38061,7 @@ function lstatIfPresent3(path9) {
|
|
|
37958
38061
|
}
|
|
37959
38062
|
function driftHealMarkerTemporaries(configDir) {
|
|
37960
38063
|
try {
|
|
37961
|
-
return readdirSync4(configDir).filter((entry) => DRIFT_HEAL_MARKER_TEMPORARY_RE.test(entry)).map((entry) =>
|
|
38064
|
+
return readdirSync4(configDir).filter((entry) => DRIFT_HEAL_MARKER_TEMPORARY_RE.test(entry)).map((entry) => join18(configDir, entry));
|
|
37962
38065
|
} catch (error) {
|
|
37963
38066
|
const code = error.code;
|
|
37964
38067
|
if (code === "ENOENT" || code === "ENOTDIR") return [];
|
|
@@ -37971,12 +38074,12 @@ function assertDriftHealClaim(path9) {
|
|
|
37971
38074
|
if (!claim.isDirectory() || readdirSync4(path9).some((entry) => entry !== DRIFT_HEAL_CLAIM_OWNER)) {
|
|
37972
38075
|
throw new Error(`refusing to remove unrecognized daemon drift-heal claim at ${path9}`);
|
|
37973
38076
|
}
|
|
37974
|
-
assertRegularFile(
|
|
38077
|
+
assertRegularFile(join18(path9, DRIFT_HEAL_CLAIM_OWNER), "daemon drift-heal claim owner");
|
|
37975
38078
|
}
|
|
37976
38079
|
function assertExactFile(path9, expected, label) {
|
|
37977
38080
|
if (!lstatIfPresent3(path9)) return;
|
|
37978
38081
|
assertRegularFile(path9, label);
|
|
37979
|
-
if (
|
|
38082
|
+
if (readFileSync14(path9, "utf8") !== expected) {
|
|
37980
38083
|
throw new Error(`refusing to remove unrecognized ${label} at ${path9}`);
|
|
37981
38084
|
}
|
|
37982
38085
|
}
|
|
@@ -37985,12 +38088,12 @@ function assertOwnedDaemonRuntime(options) {
|
|
|
37985
38088
|
const control = daemonControlPaths(options);
|
|
37986
38089
|
const configDir = primConfigDirectory(options);
|
|
37987
38090
|
const service = process.platform === "darwin" ? launchdPaths(options) : void 0;
|
|
37988
|
-
const logPath = service?.logPath ??
|
|
38091
|
+
const logPath = service?.logPath ?? join18(configDir, "daemon.log");
|
|
37989
38092
|
for (const activeArtifact of [
|
|
37990
|
-
|
|
37991
|
-
|
|
37992
|
-
|
|
37993
|
-
|
|
38093
|
+
join18(configDir, "daemon.pid"),
|
|
38094
|
+
join18(configDir, "sock"),
|
|
38095
|
+
join18(configDir, "daemon.lock"),
|
|
38096
|
+
join18(configDir, "client-instance.lock")
|
|
37994
38097
|
]) {
|
|
37995
38098
|
if (lstatIfPresent3(activeArtifact)) {
|
|
37996
38099
|
throw new Error(`refusing runtime removal while daemon state remains at ${activeArtifact}`);
|
|
@@ -38016,11 +38119,11 @@ function assertOwnedDaemonRuntime(options) {
|
|
|
38016
38119
|
assertRegularFile(temporary, "daemon drift-heal marker temporary");
|
|
38017
38120
|
}
|
|
38018
38121
|
assertDriftHealClaim(control.driftHealClaim);
|
|
38019
|
-
assertRegularFile(
|
|
38020
|
-
assertRegularFile(
|
|
38122
|
+
assertRegularFile(join18(configDir, "daemon-health.json"), "daemon health snapshot");
|
|
38123
|
+
assertRegularFile(join18(configDir, "client_instance_id"), "daemon client instance id");
|
|
38021
38124
|
if (service && lstatIfPresent3(service.plistPath)) {
|
|
38022
38125
|
assertRegularFile(service.plistPath, "launchd property list");
|
|
38023
|
-
if (
|
|
38126
|
+
if (readFileSync14(service.plistPath, "utf8") !== ownedLaunchAgentPlist(options, logPath)) {
|
|
38024
38127
|
throw new Error(
|
|
38025
38128
|
`refusing to remove unrecognized launchd property list at ${service.plistPath}`
|
|
38026
38129
|
);
|
|
@@ -38045,7 +38148,7 @@ function assertOwnedDaemonRuntime(options) {
|
|
|
38045
38148
|
throw new Error(`refusing to remove non-directory daemon releases at ${runtime.releasesDir}`);
|
|
38046
38149
|
}
|
|
38047
38150
|
for (const entry of readdirSync4(runtime.releasesDir, { withFileTypes: true })) {
|
|
38048
|
-
const releaseDir =
|
|
38151
|
+
const releaseDir = join18(runtime.releasesDir, entry.name);
|
|
38049
38152
|
const manifest = entry.isDirectory() && RUNTIME_RELEASE_RE.test(entry.name) ? readOwnedRuntimeManifest(releaseDir) : null;
|
|
38050
38153
|
if (!manifest) {
|
|
38051
38154
|
throw new Error(`refusing to remove unrecognized daemon release ${releaseDir}`);
|
|
@@ -38063,7 +38166,7 @@ function assertOwnedDaemonRuntime(options) {
|
|
|
38063
38166
|
}
|
|
38064
38167
|
const target = readlinkSync(runtime.currentLink);
|
|
38065
38168
|
const releaseName = basename3(target);
|
|
38066
|
-
if (target !==
|
|
38169
|
+
if (target !== join18("releases", releaseName) || !RUNTIME_RELEASE_RE.test(releaseName)) {
|
|
38067
38170
|
throw new Error(
|
|
38068
38171
|
`refusing to remove malformed daemon runtime selector ${runtime.currentLink}`
|
|
38069
38172
|
);
|
|
@@ -38091,7 +38194,7 @@ async function removeDaemonRuntime(options = {}) {
|
|
|
38091
38194
|
const control = daemonControlPaths(options);
|
|
38092
38195
|
const configDir = primConfigDirectory(options);
|
|
38093
38196
|
const service = process.platform === "darwin" ? launchdPaths(options) : void 0;
|
|
38094
|
-
const logPath = service?.logPath ??
|
|
38197
|
+
const logPath = service?.logPath ?? join18(configDir, "daemon.log");
|
|
38095
38198
|
const ownedArtifacts = [
|
|
38096
38199
|
runtime.runtimeDir,
|
|
38097
38200
|
control.launcher,
|
|
@@ -38102,8 +38205,8 @@ async function removeDaemonRuntime(options = {}) {
|
|
|
38102
38205
|
control.driftHealClaim,
|
|
38103
38206
|
...service ? [service.plistPath] : [],
|
|
38104
38207
|
logPath,
|
|
38105
|
-
|
|
38106
|
-
|
|
38208
|
+
join18(configDir, "daemon-health.json"),
|
|
38209
|
+
join18(configDir, "client_instance_id")
|
|
38107
38210
|
];
|
|
38108
38211
|
if (!ownedArtifacts.some((path9) => lstatIfPresent3(path9))) {
|
|
38109
38212
|
return { changed: false, runtimePaths: runtime };
|
|
@@ -38114,7 +38217,7 @@ async function removeDaemonRuntime(options = {}) {
|
|
|
38114
38217
|
rmSync5(path9, { force: true, recursive: path9 === control.driftHealClaim });
|
|
38115
38218
|
}
|
|
38116
38219
|
if (lstatIfPresent3(runtime.runtimeDir)) {
|
|
38117
|
-
const quarantined = `${runtime.runtimeDir}.uninstall-${String(process.pid)}-${
|
|
38220
|
+
const quarantined = `${runtime.runtimeDir}.uninstall-${String(process.pid)}-${randomBytes6(8).toString("hex")}`;
|
|
38118
38221
|
renameSync4(runtime.runtimeDir, quarantined);
|
|
38119
38222
|
rmSync5(quarantined, { recursive: true, force: true });
|
|
38120
38223
|
}
|
|
@@ -38183,7 +38286,7 @@ function readDaemonLauncherFile(path9) {
|
|
|
38183
38286
|
function readUsableDaemonConfig(path9) {
|
|
38184
38287
|
const config = readDaemonLauncher(path9);
|
|
38185
38288
|
if (!config) return null;
|
|
38186
|
-
const manifest = readRuntimeManifest(
|
|
38289
|
+
const manifest = readRuntimeManifest(join18(dirname10(config.daemonPath), "manifest.json"));
|
|
38187
38290
|
try {
|
|
38188
38291
|
accessSync2(config.nodePath, constants5.X_OK);
|
|
38189
38292
|
return manifest?.version === config.runtimeVersion && manifest.nodePath === config.nodePath && manifest.daemonSha256 === sha256File(config.daemonPath) ? config : null;
|
|
@@ -38236,8 +38339,8 @@ function launchdPaths(options = {}) {
|
|
|
38236
38339
|
return {
|
|
38237
38340
|
domainTarget: `gui/${uid}`,
|
|
38238
38341
|
serviceTarget: `gui/${uid}/${label}`,
|
|
38239
|
-
plistPath:
|
|
38240
|
-
logPath:
|
|
38342
|
+
plistPath: join18(home, "Library", "LaunchAgents", `${label}.plist`),
|
|
38343
|
+
logPath: join18(configDir, "daemon.log")
|
|
38241
38344
|
};
|
|
38242
38345
|
}
|
|
38243
38346
|
var runLaunchctl = (args, timeoutMs2 = COMMAND_TIMEOUT_MS) => {
|
|
@@ -38268,10 +38371,10 @@ function getLaunchdService(options = {}) {
|
|
|
38268
38371
|
)
|
|
38269
38372
|
);
|
|
38270
38373
|
}
|
|
38271
|
-
function
|
|
38374
|
+
function atomicWrite4(path9, content, mode, validate3) {
|
|
38272
38375
|
try {
|
|
38273
|
-
if (
|
|
38274
|
-
|
|
38376
|
+
if (readFileSync14(path9, "utf8") === content) {
|
|
38377
|
+
chmodSync5(path9, mode);
|
|
38275
38378
|
validate3?.(path9, COMMAND_TIMEOUT_MS);
|
|
38276
38379
|
return false;
|
|
38277
38380
|
}
|
|
@@ -38319,7 +38422,7 @@ function canonicalProspectivePath(path9) {
|
|
|
38319
38422
|
ancestor = parent;
|
|
38320
38423
|
}
|
|
38321
38424
|
try {
|
|
38322
|
-
return
|
|
38425
|
+
return join18(realpathSync4(ancestor), ...suffix);
|
|
38323
38426
|
} catch {
|
|
38324
38427
|
return resolve7(path9);
|
|
38325
38428
|
}
|
|
@@ -38334,10 +38437,10 @@ async function withDaemonLifecycleLock(operation, options = {}) {
|
|
|
38334
38437
|
);
|
|
38335
38438
|
}
|
|
38336
38439
|
async function stopVerifiedLegacyDaemon(options, deadlineMs, nowMs, sleep2) {
|
|
38337
|
-
const pidPath =
|
|
38440
|
+
const pidPath = join18(primConfigDirectory(options), "daemon.pid");
|
|
38338
38441
|
let pid;
|
|
38339
38442
|
try {
|
|
38340
|
-
pid = Number(
|
|
38443
|
+
pid = Number(readFileSync14(pidPath, "utf8").trim());
|
|
38341
38444
|
} catch {
|
|
38342
38445
|
throw new Error("an unsupervised daemon answered, but it has no verifiable pidfile");
|
|
38343
38446
|
}
|
|
@@ -38525,9 +38628,9 @@ function setDaemonExplicitlyDisabled(disabled, options = {}) {
|
|
|
38525
38628
|
}
|
|
38526
38629
|
const content = DAEMON_DISABLED_CONTENT;
|
|
38527
38630
|
if (paths.legacyDisabledMarker !== paths.disabledMarker) {
|
|
38528
|
-
|
|
38631
|
+
atomicWrite4(paths.legacyDisabledMarker, content, RUNTIME_FILE_MODE);
|
|
38529
38632
|
}
|
|
38530
|
-
|
|
38633
|
+
atomicWrite4(paths.disabledMarker, content, RUNTIME_FILE_MODE);
|
|
38531
38634
|
}
|
|
38532
38635
|
function launcherRunnable(config) {
|
|
38533
38636
|
try {
|
|
@@ -38600,7 +38703,7 @@ async function ensureMacDaemonLocked(options) {
|
|
|
38600
38703
|
if (!options.explicitlyStarted && daemonExplicitlyDisabled(options)) {
|
|
38601
38704
|
const control2 = daemonControlPaths(options);
|
|
38602
38705
|
if (!existsSync11(control2.disabledMarker)) {
|
|
38603
|
-
|
|
38706
|
+
atomicWrite4(control2.disabledMarker, "disabled by `prim daemon stop`\n", RUNTIME_FILE_MODE);
|
|
38604
38707
|
}
|
|
38605
38708
|
return {
|
|
38606
38709
|
state: "disabled",
|
|
@@ -38626,7 +38729,7 @@ async function ensureMacDaemonLocked(options) {
|
|
|
38626
38729
|
const configuredApiUrl = (options.env ?? process.env).PRIM_API_URL;
|
|
38627
38730
|
const apiUrl = configuredApiUrl ? normalizeApiUrl(configuredApiUrl) || void 0 : void 0;
|
|
38628
38731
|
const configDir = primConfigDirectory(options);
|
|
38629
|
-
const legacyDefaultConfigDir =
|
|
38732
|
+
const legacyDefaultConfigDir = join18(options.homeDir ?? homedir8(), ".config", "prim");
|
|
38630
38733
|
const launcherConfigDir = configDir === legacyDefaultConfigDir ? void 0 : configDir;
|
|
38631
38734
|
if (retainSelected && selected) {
|
|
38632
38735
|
const usable = readUsableDaemonConfig(control.launcher);
|
|
@@ -38655,16 +38758,16 @@ async function ensureMacDaemonLocked(options) {
|
|
|
38655
38758
|
const servicePaths = launchdPaths(options);
|
|
38656
38759
|
mkdirSync9(dirname10(servicePaths.logPath), { recursive: true, mode: RUNTIME_DIR_MODE });
|
|
38657
38760
|
writeFileSync7(servicePaths.logPath, "", { mode: RUNTIME_FILE_MODE, flag: "a" });
|
|
38658
|
-
|
|
38761
|
+
chmodSync5(servicePaths.logPath, RUNTIME_FILE_MODE);
|
|
38659
38762
|
const launcher = generateDaemonLauncher(daemonConfig);
|
|
38660
|
-
|
|
38763
|
+
atomicWrite4(control.launcher, launcher.content, RUNTIME_LAUNCHER_MODE);
|
|
38661
38764
|
const plist = generateLaunchAgentPlist({
|
|
38662
38765
|
launcherPath: control.launcher,
|
|
38663
38766
|
logPath: servicePaths.logPath,
|
|
38664
38767
|
workingDirectory: options.homeDir ?? homedir8(),
|
|
38665
38768
|
label: options.label
|
|
38666
38769
|
});
|
|
38667
|
-
const plistChanged =
|
|
38770
|
+
const plistChanged = atomicWrite4(
|
|
38668
38771
|
servicePaths.plistPath,
|
|
38669
38772
|
plist,
|
|
38670
38773
|
PLIST_FILE_MODE,
|
|
@@ -38933,9 +39036,9 @@ function formatStatusline(version, snapshot, resolveIngestionStatus, options = {
|
|
|
38933
39036
|
// src/commands/daemon.ts
|
|
38934
39037
|
var DAEMON_BIN = "prim-daemon-server";
|
|
38935
39038
|
var CONFIG_DIR = primConfigDirectory();
|
|
38936
|
-
var PID_PATH =
|
|
38937
|
-
var SOCK_PATH2 =
|
|
38938
|
-
var LOG_PATH =
|
|
39039
|
+
var PID_PATH = join19(CONFIG_DIR, "daemon.pid");
|
|
39040
|
+
var SOCK_PATH2 = join19(CONFIG_DIR, "sock");
|
|
39041
|
+
var LOG_PATH = join19(CONFIG_DIR, "daemon.log");
|
|
38939
39042
|
var CONFIG_DIR_MODE2 = 448;
|
|
38940
39043
|
var LOG_FILE_MODE = 384;
|
|
38941
39044
|
var STOP_TIMEOUT_MS = 5e3;
|
|
@@ -38980,7 +39083,7 @@ function readPidfile() {
|
|
|
38980
39083
|
if (!existsSync12(PID_PATH)) {
|
|
38981
39084
|
return null;
|
|
38982
39085
|
}
|
|
38983
|
-
const raw =
|
|
39086
|
+
const raw = readFileSync15(PID_PATH, "utf-8").trim();
|
|
38984
39087
|
const pid = Number(raw);
|
|
38985
39088
|
if (!Number.isInteger(pid) || pid <= 0) {
|
|
38986
39089
|
return null;
|
|
@@ -39008,7 +39111,7 @@ function openDaemonLog(configDir = CONFIG_DIR) {
|
|
|
39008
39111
|
if (!existsSync12(configDir)) {
|
|
39009
39112
|
mkdirSync10(configDir, { recursive: true, mode: CONFIG_DIR_MODE2 });
|
|
39010
39113
|
}
|
|
39011
|
-
return openSync4(
|
|
39114
|
+
return openSync4(join19(configDir, "daemon.log"), "a", LOG_FILE_MODE);
|
|
39012
39115
|
}
|
|
39013
39116
|
async function waitForReady() {
|
|
39014
39117
|
const deadline = Date.now() + READY_TIMEOUT_MS;
|
|
@@ -41517,18 +41620,28 @@ function chunk(items, size) {
|
|
|
41517
41620
|
}
|
|
41518
41621
|
return out;
|
|
41519
41622
|
}
|
|
41520
|
-
async function fetchAffecting(client, batch) {
|
|
41623
|
+
async function fetchAffecting(client, batch, repository) {
|
|
41521
41624
|
const params = new URLSearchParams();
|
|
41625
|
+
params.set("repoSyncId", repository.repoSyncId);
|
|
41626
|
+
if (repository.branch) params.set("branch", repository.branch);
|
|
41522
41627
|
for (const file of batch) {
|
|
41523
41628
|
params.append("files", file);
|
|
41524
41629
|
}
|
|
41525
41630
|
try {
|
|
41526
|
-
|
|
41631
|
+
const response = await daemonOrDirectGet(
|
|
41527
41632
|
"decisions_affecting",
|
|
41528
41633
|
`/api/cli/decisions/affecting?${params.toString()}`,
|
|
41529
41634
|
client,
|
|
41530
41635
|
DECISIONS_CHECK_TIMEOUT_MS
|
|
41531
41636
|
);
|
|
41637
|
+
if (response.repoSyncId !== repository.repoSyncId) {
|
|
41638
|
+
return {
|
|
41639
|
+
decisions: [],
|
|
41640
|
+
truncated: response.truncated === true,
|
|
41641
|
+
unavailable: response.unavailable ?? "service did not verify repository-scoped discovery"
|
|
41642
|
+
};
|
|
41643
|
+
}
|
|
41644
|
+
return response;
|
|
41532
41645
|
} catch (err) {
|
|
41533
41646
|
const detail = err instanceof Error ? err.message : String(err);
|
|
41534
41647
|
return { decisions: [], truncated: false, unavailable: `decision check failed: ${detail}` };
|
|
@@ -41538,9 +41651,31 @@ async function checkAffectedDecisions(filePaths, deps = defaultDeps8) {
|
|
|
41538
41651
|
if (filePaths.length === 0) {
|
|
41539
41652
|
return { decisions: [], truncated: false };
|
|
41540
41653
|
}
|
|
41654
|
+
const cwd = process.cwd();
|
|
41655
|
+
const root = canonicalGitRoot(cwd);
|
|
41656
|
+
const binding = repoSyncId(cwd);
|
|
41657
|
+
if (!root || !binding) {
|
|
41658
|
+
return {
|
|
41659
|
+
decisions: [],
|
|
41660
|
+
truncated: false,
|
|
41661
|
+
unavailable: "this checkout has no current Primitive repository binding; run prim enable"
|
|
41662
|
+
};
|
|
41663
|
+
}
|
|
41664
|
+
const canonical = filePaths.map(
|
|
41665
|
+
(file) => canonicalRepositoryPath(file, { repoRoot: root }, root)
|
|
41666
|
+
);
|
|
41667
|
+
if (canonical.some((path9) => !path9.ok)) {
|
|
41668
|
+
return {
|
|
41669
|
+
decisions: [],
|
|
41670
|
+
truncated: false,
|
|
41671
|
+
unavailable: "files must resolve inside this repository; use repository-relative paths"
|
|
41672
|
+
};
|
|
41673
|
+
}
|
|
41674
|
+
const paths = [...new Set(canonical.flatMap((path9) => path9.ok ? [path9.file] : []))];
|
|
41675
|
+
const repository = { repoSyncId: binding, branch: currentBranch(cwd) };
|
|
41541
41676
|
const client = deps.getClient();
|
|
41542
41677
|
const responses = await Promise.all(
|
|
41543
|
-
chunk(
|
|
41678
|
+
chunk(paths, MAX_FILES_PER_REQUEST).map((batch) => fetchAffecting(client, batch, repository))
|
|
41544
41679
|
);
|
|
41545
41680
|
const byId = /* @__PURE__ */ new Map();
|
|
41546
41681
|
let truncated = false;
|
|
@@ -41588,7 +41723,7 @@ function formatDecisionsWarning(result) {
|
|
|
41588
41723
|
}
|
|
41589
41724
|
if (result.truncated) {
|
|
41590
41725
|
lines.push(
|
|
41591
|
-
"[prim] result truncated \u2014
|
|
41726
|
+
"[prim] result truncated \u2014 a discovery scan or result limit was reached; not all decisions shown"
|
|
41592
41727
|
);
|
|
41593
41728
|
}
|
|
41594
41729
|
return lines.join("\n");
|
|
@@ -41706,9 +41841,9 @@ function locationScopeFromOptions(options) {
|
|
|
41706
41841
|
}
|
|
41707
41842
|
function registerDecisionsCommands(program3) {
|
|
41708
41843
|
const decisions = program3.command("decisions").description("Inspect the project Decision Graph");
|
|
41709
|
-
decisions.command("check").description("Look up active decisions
|
|
41844
|
+
decisions.command("check").description("Look up active decisions scoped to file paths in the connected repository").requiredOption(
|
|
41710
41845
|
"--files <files>",
|
|
41711
|
-
"Comma-separated
|
|
41846
|
+
"Comma-separated repository-relative paths to check against the Decision Graph (repeatable)",
|
|
41712
41847
|
collectPaths
|
|
41713
41848
|
).action(async (opts) => {
|
|
41714
41849
|
const result = await checkAffectedDecisions(opts.files);
|
|
@@ -42274,22 +42409,22 @@ import {
|
|
|
42274
42409
|
mkdirSync as mkdirSync11,
|
|
42275
42410
|
openSync as openSync5,
|
|
42276
42411
|
opendirSync,
|
|
42277
|
-
readFileSync as
|
|
42412
|
+
readFileSync as readFileSync17,
|
|
42278
42413
|
readSync as readSync2,
|
|
42279
42414
|
readdirSync as readdirSync6
|
|
42280
42415
|
} from "fs";
|
|
42281
|
-
import { dirname as dirname12, join as
|
|
42416
|
+
import { dirname as dirname12, join as join21 } from "path";
|
|
42282
42417
|
|
|
42283
42418
|
// src/drain-progress.ts
|
|
42284
42419
|
import {
|
|
42285
|
-
chmodSync as
|
|
42420
|
+
chmodSync as chmodSync6,
|
|
42286
42421
|
existsSync as existsSync13,
|
|
42287
|
-
readFileSync as
|
|
42422
|
+
readFileSync as readFileSync16,
|
|
42288
42423
|
readdirSync as readdirSync5,
|
|
42289
42424
|
rmSync as rmSync6,
|
|
42290
42425
|
rmdirSync
|
|
42291
42426
|
} from "fs";
|
|
42292
|
-
import { basename as basename4, dirname as dirname11, join as
|
|
42427
|
+
import { basename as basename4, dirname as dirname11, join as join20 } from "path";
|
|
42293
42428
|
var DIRECTORY_MODE3 = 448;
|
|
42294
42429
|
var FILE_MODE2 = 384;
|
|
42295
42430
|
var DRAIN_PROGRESS_DIRNAME = "drain-progress";
|
|
@@ -42298,10 +42433,10 @@ function rotationIdentity(stat) {
|
|
|
42298
42433
|
return { size: stat.size, ino: stat.ino, dev: stat.dev };
|
|
42299
42434
|
}
|
|
42300
42435
|
function drainProgressDirectory(flushingPath) {
|
|
42301
|
-
return
|
|
42436
|
+
return join20(dirname11(flushingPath), DRAIN_PROGRESS_DIRNAME);
|
|
42302
42437
|
}
|
|
42303
42438
|
function drainProgressPath(flushingPath) {
|
|
42304
|
-
return
|
|
42439
|
+
return join20(drainProgressDirectory(flushingPath), `${basename4(flushingPath)}.json`);
|
|
42305
42440
|
}
|
|
42306
42441
|
function isByteCount(value) {
|
|
42307
42442
|
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
@@ -42309,7 +42444,7 @@ function isByteCount(value) {
|
|
|
42309
42444
|
function drainResumeOffset(flushingPath, rotation) {
|
|
42310
42445
|
let parsed;
|
|
42311
42446
|
try {
|
|
42312
|
-
parsed = JSON.parse(
|
|
42447
|
+
parsed = JSON.parse(readFileSync16(drainProgressPath(flushingPath), "utf8"));
|
|
42313
42448
|
} catch {
|
|
42314
42449
|
return 0;
|
|
42315
42450
|
}
|
|
@@ -42325,7 +42460,7 @@ function drainResumeOffset(flushingPath, rotation) {
|
|
|
42325
42460
|
function writeDrainCheckpoint(flushingPath, checkpoint) {
|
|
42326
42461
|
const directory = drainProgressDirectory(flushingPath);
|
|
42327
42462
|
ensureDurableDirectory(directory, DIRECTORY_MODE3);
|
|
42328
|
-
|
|
42463
|
+
chmodSync6(directory, DIRECTORY_MODE3);
|
|
42329
42464
|
atomicWriteFile(drainProgressPath(flushingPath), `${JSON.stringify(checkpoint)}
|
|
42330
42465
|
`, {
|
|
42331
42466
|
mode: FILE_MODE2
|
|
@@ -42346,7 +42481,7 @@ function removeDrainCheckpoint(flushingPath) {
|
|
|
42346
42481
|
removeEmptyDirectory(drainProgressDirectory(flushingPath));
|
|
42347
42482
|
}
|
|
42348
42483
|
function sweepOrphanedDrainCheckpoints(bucketDirectory) {
|
|
42349
|
-
const directory =
|
|
42484
|
+
const directory = join20(bucketDirectory, DRAIN_PROGRESS_DIRNAME);
|
|
42350
42485
|
let names;
|
|
42351
42486
|
try {
|
|
42352
42487
|
names = readdirSync5(directory);
|
|
@@ -42355,11 +42490,11 @@ function sweepOrphanedDrainCheckpoints(bucketDirectory) {
|
|
|
42355
42490
|
}
|
|
42356
42491
|
for (const name of names) {
|
|
42357
42492
|
const rotation = CHECKPOINT_NAME.exec(name)?.[1];
|
|
42358
|
-
if (rotation === void 0 || existsSync13(
|
|
42493
|
+
if (rotation === void 0 || existsSync13(join20(bucketDirectory, rotation))) {
|
|
42359
42494
|
continue;
|
|
42360
42495
|
}
|
|
42361
42496
|
try {
|
|
42362
|
-
rmSync6(
|
|
42497
|
+
rmSync6(join20(directory, name), { force: true });
|
|
42363
42498
|
} catch {
|
|
42364
42499
|
}
|
|
42365
42500
|
}
|
|
@@ -42370,7 +42505,7 @@ function sweepOrphanedDrainCheckpoints(bucketDirectory) {
|
|
|
42370
42505
|
}
|
|
42371
42506
|
|
|
42372
42507
|
// src/journal.ts
|
|
42373
|
-
var JOURNAL_DIR =
|
|
42508
|
+
var JOURNAL_DIR = join21(primConfigDirectory(), "moves");
|
|
42374
42509
|
var JOURNAL_BASENAME = "journal.ndjson";
|
|
42375
42510
|
var JOURNAL_STATS_SAMPLE_BYTES = 64 * 1024;
|
|
42376
42511
|
var PENDING_STATS_MAX_FILES = 128;
|
|
@@ -42382,7 +42517,7 @@ function envSlug(apiUrl) {
|
|
|
42382
42517
|
return slug;
|
|
42383
42518
|
}
|
|
42384
42519
|
function currentEnvDir() {
|
|
42385
|
-
return
|
|
42520
|
+
return join21(JOURNAL_DIR, envSlug(getSiteUrl()));
|
|
42386
42521
|
}
|
|
42387
42522
|
function parseMoves(content) {
|
|
42388
42523
|
const moves = [];
|
|
@@ -42401,7 +42536,7 @@ function readMovesFromPath(path9) {
|
|
|
42401
42536
|
if (!existsSync14(path9)) {
|
|
42402
42537
|
return [];
|
|
42403
42538
|
}
|
|
42404
|
-
return parseMoves(
|
|
42539
|
+
return parseMoves(readFileSync17(path9, "utf-8"));
|
|
42405
42540
|
}
|
|
42406
42541
|
function listBuckets() {
|
|
42407
42542
|
const out = [];
|
|
@@ -42413,7 +42548,7 @@ function listBuckets() {
|
|
|
42413
42548
|
if (!entry.isDirectory()) {
|
|
42414
42549
|
continue;
|
|
42415
42550
|
}
|
|
42416
|
-
const path9 =
|
|
42551
|
+
const path9 = join21(envDir, entry.name, JOURNAL_BASENAME);
|
|
42417
42552
|
if (existsSync14(path9)) {
|
|
42418
42553
|
out.push({ bucket: entry.name, path: path9 });
|
|
42419
42554
|
}
|
|
@@ -42490,7 +42625,7 @@ function listFlushingInDir(dir, bucket, options = {}) {
|
|
|
42490
42625
|
entry = entries.readSync();
|
|
42491
42626
|
continue;
|
|
42492
42627
|
}
|
|
42493
|
-
const path9 =
|
|
42628
|
+
const path9 = join21(dir, entry.name);
|
|
42494
42629
|
let sample;
|
|
42495
42630
|
try {
|
|
42496
42631
|
sample = sampleJournalFile(path9, remainingBytes, { fromDrainCheckpoint: true });
|
|
@@ -42528,7 +42663,7 @@ function listFlushing(options = {}) {
|
|
|
42528
42663
|
break;
|
|
42529
42664
|
}
|
|
42530
42665
|
if (entry.isDirectory()) {
|
|
42531
|
-
const found = listFlushingInDir(
|
|
42666
|
+
const found = listFlushingInDir(join21(envDir, entry.name), entry.name, {
|
|
42532
42667
|
sampleBytes: remainingBytes,
|
|
42533
42668
|
maxFiles: maxFiles - out.length
|
|
42534
42669
|
});
|
|
@@ -42548,7 +42683,7 @@ function sweepOrphanedDrainProgress() {
|
|
|
42548
42683
|
}
|
|
42549
42684
|
for (const entry of readdirSync6(envDir, { withFileTypes: true })) {
|
|
42550
42685
|
if (entry.isDirectory()) {
|
|
42551
|
-
sweepOrphanedDrainCheckpoints(
|
|
42686
|
+
sweepOrphanedDrainCheckpoints(join21(envDir, entry.name));
|
|
42552
42687
|
}
|
|
42553
42688
|
}
|
|
42554
42689
|
}
|
|
@@ -42597,9 +42732,9 @@ function pendingJournalStats() {
|
|
|
42597
42732
|
}
|
|
42598
42733
|
|
|
42599
42734
|
// src/commands/hermes-install.ts
|
|
42600
|
-
import { existsSync as existsSync15, readFileSync as
|
|
42735
|
+
import { existsSync as existsSync15, readFileSync as readFileSync18, rmSync as rmSync7, statSync as statSync4 } from "fs";
|
|
42601
42736
|
import { homedir as homedir9 } from "os";
|
|
42602
|
-
import { join as
|
|
42737
|
+
import { join as join22 } from "path";
|
|
42603
42738
|
|
|
42604
42739
|
// node_modules/.pnpm/yaml@2.9.0/node_modules/yaml/browser/dist/nodes/identity.js
|
|
42605
42740
|
var ALIAS = /* @__PURE__ */ Symbol.for("yaml.alias");
|
|
@@ -48878,13 +49013,13 @@ var JSON_INDENT3 = 2;
|
|
|
48878
49013
|
var CONFIG_MODE = 384;
|
|
48879
49014
|
var PRIM_BINS4 = [CAPTURE_BIN4, GATE_BIN4, POST_TOOL_USE_BIN3, SESSION_START_BIN4, SESSION_END_BIN3];
|
|
48880
49015
|
function hermesHome() {
|
|
48881
|
-
return process.env.HERMES_HOME ??
|
|
49016
|
+
return process.env.HERMES_HOME ?? join22(homedir9(), ".hermes");
|
|
48882
49017
|
}
|
|
48883
49018
|
function configPath() {
|
|
48884
|
-
return
|
|
49019
|
+
return join22(hermesHome(), "config.yaml");
|
|
48885
49020
|
}
|
|
48886
49021
|
function legacyShimPath() {
|
|
48887
|
-
return
|
|
49022
|
+
return join22(hermesHome(), "agent-hooks", "prim-shim.sh");
|
|
48888
49023
|
}
|
|
48889
49024
|
function commandFor2(bin) {
|
|
48890
49025
|
return stableHookCommand(bin, HERMES_ARGS);
|
|
@@ -48999,7 +49134,7 @@ function hookRuntimeResolutions3(hooks) {
|
|
|
48999
49134
|
function inspectHookRuntimeResolutions4() {
|
|
49000
49135
|
const path9 = configPath();
|
|
49001
49136
|
if (!existsSync15(path9)) return [];
|
|
49002
|
-
return hookRuntimeResolutions3(readHooks(parseHermesDocument(
|
|
49137
|
+
return hookRuntimeResolutions3(readHooks(parseHermesDocument(readFileSync18(path9, "utf8"))));
|
|
49003
49138
|
}
|
|
49004
49139
|
function entryMatchesRegistration3(owned, registration) {
|
|
49005
49140
|
const expected = entryFor(registration);
|
|
@@ -49272,7 +49407,7 @@ function readConfigSnapshot(path9) {
|
|
|
49272
49407
|
return {
|
|
49273
49408
|
exists: true,
|
|
49274
49409
|
mode: statSync4(path9).mode & 511,
|
|
49275
|
-
raw:
|
|
49410
|
+
raw: readFileSync18(path9, "utf8")
|
|
49276
49411
|
};
|
|
49277
49412
|
}
|
|
49278
49413
|
var CONCURRENT_CONFIG_MESSAGE = "Hermes config changed during update; concurrent changes were preserved, retry the command";
|
|
@@ -49281,7 +49416,7 @@ function writeHermesConfigSnapshot(path9, before, after, expectedHooks) {
|
|
|
49281
49416
|
ensureParent: true,
|
|
49282
49417
|
mode: before.mode,
|
|
49283
49418
|
validate(temporaryPath) {
|
|
49284
|
-
const flushed =
|
|
49419
|
+
const flushed = readFileSync18(temporaryPath, "utf8");
|
|
49285
49420
|
if (!mergePreservesHermesSemantics(before.raw, flushed, expectedHooks)) {
|
|
49286
49421
|
throw new Error(INVALID_MERGE_MESSAGE);
|
|
49287
49422
|
}
|
|
@@ -49359,7 +49494,7 @@ function performUninstall4() {
|
|
|
49359
49494
|
}
|
|
49360
49495
|
function performStatus4() {
|
|
49361
49496
|
const path9 = configPath();
|
|
49362
|
-
const raw = existsSync15(path9) ?
|
|
49497
|
+
const raw = existsSync15(path9) ? readFileSync18(path9, "utf8") : "";
|
|
49363
49498
|
const hooks = raw ? readHooks(parseHermesDocument(raw)) : {};
|
|
49364
49499
|
return {
|
|
49365
49500
|
path: path9,
|
|
@@ -50243,17 +50378,17 @@ function registerDoctorCommands(program3, dependencies = {}) {
|
|
|
50243
50378
|
|
|
50244
50379
|
// src/commands/moves.ts
|
|
50245
50380
|
import { existsSync as existsSync18, mkdirSync as mkdirSync13, unlinkSync as unlinkSync6, writeFileSync as writeFileSync9 } from "fs";
|
|
50246
|
-
import { join as
|
|
50381
|
+
import { join as join25 } from "path";
|
|
50247
50382
|
|
|
50248
50383
|
// src/flusher.ts
|
|
50249
50384
|
import { createReadStream, renameSync as renameSync6, statSync as statSync5, unlinkSync as unlinkSync5 } from "fs";
|
|
50250
|
-
import { dirname as dirname14, join as
|
|
50385
|
+
import { dirname as dirname14, join as join24 } from "path";
|
|
50251
50386
|
|
|
50252
50387
|
// src/dead-letter.ts
|
|
50253
|
-
import { createHash as createHash9, randomBytes as
|
|
50388
|
+
import { createHash as createHash9, randomBytes as randomBytes7 } from "crypto";
|
|
50254
50389
|
import {
|
|
50255
50390
|
constants as constants6,
|
|
50256
|
-
chmodSync as
|
|
50391
|
+
chmodSync as chmodSync7,
|
|
50257
50392
|
closeSync as closeSync6,
|
|
50258
50393
|
existsSync as existsSync17,
|
|
50259
50394
|
fchmodSync as fchmodSync3,
|
|
@@ -50264,21 +50399,21 @@ import {
|
|
|
50264
50399
|
rmSync as rmSync8,
|
|
50265
50400
|
writeFileSync as writeFileSync8
|
|
50266
50401
|
} from "fs";
|
|
50267
|
-
import { dirname as dirname13, join as
|
|
50402
|
+
import { dirname as dirname13, join as join23 } from "path";
|
|
50268
50403
|
var DIRECTORY_MODE4 = 448;
|
|
50269
50404
|
var FILE_MODE3 = 384;
|
|
50270
50405
|
var DEAD_LETTER_DIRNAME = "dead-letter";
|
|
50271
50406
|
function deadLetterDirectoryForRotation(flushingPath) {
|
|
50272
|
-
return
|
|
50407
|
+
return join23(dirname13(flushingPath), DEAD_LETTER_DIRNAME);
|
|
50273
50408
|
}
|
|
50274
50409
|
function deadLetterPathForRawLine(flushingPath, rawLine) {
|
|
50275
50410
|
const quarantineId = createHash9("sha256").update(rawLine).digest("hex");
|
|
50276
|
-
return
|
|
50411
|
+
return join23(deadLetterDirectoryForRotation(flushingPath), `raw-${quarantineId}.json`);
|
|
50277
50412
|
}
|
|
50278
50413
|
function ensureDeadLetterDirectory(flushingPath, persistDirectory) {
|
|
50279
50414
|
const directory = deadLetterDirectoryForRotation(flushingPath);
|
|
50280
50415
|
mkdirSync12(directory, { recursive: true, mode: DIRECTORY_MODE4 });
|
|
50281
|
-
|
|
50416
|
+
chmodSync7(directory, DIRECTORY_MODE4);
|
|
50282
50417
|
persistDirectory(dirname13(directory));
|
|
50283
50418
|
return directory;
|
|
50284
50419
|
}
|
|
@@ -50287,9 +50422,9 @@ function persistDeadLetter(directory, path9, quarantineId, record3, persistDirec
|
|
|
50287
50422
|
persistDirectory(directory);
|
|
50288
50423
|
return;
|
|
50289
50424
|
}
|
|
50290
|
-
const temporaryPath =
|
|
50425
|
+
const temporaryPath = join23(
|
|
50291
50426
|
directory,
|
|
50292
|
-
`.${quarantineId}.${String(process.pid)}.${
|
|
50427
|
+
`.${quarantineId}.${String(process.pid)}.${randomBytes7(8).toString("hex")}.tmp`
|
|
50293
50428
|
);
|
|
50294
50429
|
const flags = constants6.O_CREAT | constants6.O_EXCL | constants6.O_WRONLY | constants6.O_NOFOLLOW;
|
|
50295
50430
|
try {
|
|
@@ -50319,7 +50454,7 @@ function quarantineMove(flushingPath, move, reason, now = Date.now, options = {}
|
|
|
50319
50454
|
reason,
|
|
50320
50455
|
move
|
|
50321
50456
|
};
|
|
50322
|
-
const path9 =
|
|
50457
|
+
const path9 = join23(directory, `${record3.quarantineId}.json`);
|
|
50323
50458
|
persistDeadLetter(directory, path9, record3.quarantineId, record3, persistDirectory);
|
|
50324
50459
|
return record3;
|
|
50325
50460
|
}
|
|
@@ -50727,7 +50862,7 @@ async function flushOnce() {
|
|
|
50727
50862
|
return inspection.retainedBuckets.length > 0 ? { flushed: total, quarantined, retained: inspection.retainedBuckets } : { flushed: total, quarantined };
|
|
50728
50863
|
}
|
|
50729
50864
|
var flushInFlight;
|
|
50730
|
-
var FLUSH_LOCK_PATH =
|
|
50865
|
+
var FLUSH_LOCK_PATH = join24(dirname14(JOURNAL_DIR), ".flush.lock");
|
|
50731
50866
|
var FLUSH_LOCK_TIMEOUT_MS = 250;
|
|
50732
50867
|
function isFlushLockContended(error) {
|
|
50733
50868
|
return error instanceof Error && error.message.startsWith("timed out waiting for file lock");
|
|
@@ -50859,18 +50994,18 @@ function registerMovesCommands(program3) {
|
|
|
50859
50994
|
}
|
|
50860
50995
|
});
|
|
50861
50996
|
moves.command("bind").description("Pin the current directory to an org via .prim/workspace.json").requiredOption("--orgId <orgId>", "Convex organization id").action((opts) => {
|
|
50862
|
-
const dir =
|
|
50997
|
+
const dir = join25(process.cwd(), ".prim");
|
|
50863
50998
|
if (!existsSync18(dir)) {
|
|
50864
50999
|
mkdirSync13(dir, { recursive: true, mode: DIR_MODE });
|
|
50865
51000
|
}
|
|
50866
|
-
const file =
|
|
51001
|
+
const file = join25(process.cwd(), WORKSPACE_FILE);
|
|
50867
51002
|
writeFileSync9(file, JSON.stringify({ orgId: opts.orgId, boundAt: Date.now() }, null, 2), {
|
|
50868
51003
|
mode: FILE_MODE4
|
|
50869
51004
|
});
|
|
50870
51005
|
console.log(`[prim] bound ${process.cwd()} to org ${opts.orgId}`);
|
|
50871
51006
|
});
|
|
50872
51007
|
moves.command("drop").description("Remove the .prim/workspace.json binding from the cwd").action(() => {
|
|
50873
|
-
const file =
|
|
51008
|
+
const file = join25(process.cwd(), WORKSPACE_FILE);
|
|
50874
51009
|
if (!existsSync18(file)) {
|
|
50875
51010
|
console.log("[prim] no workspace binding in cwd");
|
|
50876
51011
|
return;
|
|
@@ -50964,18 +51099,18 @@ function registerReconcileCommands(program3) {
|
|
|
50964
51099
|
import {
|
|
50965
51100
|
existsSync as existsSync20,
|
|
50966
51101
|
mkdirSync as mkdirSync14,
|
|
50967
|
-
readFileSync as
|
|
51102
|
+
readFileSync as readFileSync20,
|
|
50968
51103
|
readdirSync as readdirSync7,
|
|
50969
51104
|
unlinkSync as unlinkSync7,
|
|
50970
51105
|
writeFileSync as writeFileSync10
|
|
50971
51106
|
} from "fs";
|
|
50972
|
-
import { join as
|
|
51107
|
+
import { join as join27 } from "path";
|
|
50973
51108
|
|
|
50974
51109
|
// src/binding.ts
|
|
50975
|
-
import { existsSync as existsSync19, readFileSync as
|
|
50976
|
-
import { dirname as dirname15, join as
|
|
51110
|
+
import { existsSync as existsSync19, readFileSync as readFileSync19 } from "fs";
|
|
51111
|
+
import { dirname as dirname15, join as join26 } from "path";
|
|
50977
51112
|
var PRIM_CONFIG_DIR = primConfigDirectory();
|
|
50978
|
-
var SESSIONS_DIR =
|
|
51113
|
+
var SESSIONS_DIR = join26(PRIM_CONFIG_DIR, "sessions");
|
|
50979
51114
|
|
|
50980
51115
|
// src/commands/session.ts
|
|
50981
51116
|
var DIR_MODE2 = 448;
|
|
@@ -50986,7 +51121,7 @@ function ensureDir() {
|
|
|
50986
51121
|
}
|
|
50987
51122
|
}
|
|
50988
51123
|
function markerPath(sessionId) {
|
|
50989
|
-
return
|
|
51124
|
+
return join27(SESSIONS_DIR, `${sessionId}.json`);
|
|
50990
51125
|
}
|
|
50991
51126
|
function registerSessionCommands(program3) {
|
|
50992
51127
|
const session = program3.command("session").description("Decision Event Pipeline \u2014 session binding markers");
|
|
@@ -51014,7 +51149,7 @@ function registerSessionCommands(program3) {
|
|
|
51014
51149
|
for (const f of files) {
|
|
51015
51150
|
const sessionId = f.replace(/\.json$/, "");
|
|
51016
51151
|
try {
|
|
51017
|
-
const m = JSON.parse(
|
|
51152
|
+
const m = JSON.parse(readFileSync20(join27(SESSIONS_DIR, f), "utf-8"));
|
|
51018
51153
|
console.log(`${sessionId} org=${m.orgId}`);
|
|
51019
51154
|
} catch {
|
|
51020
51155
|
}
|
|
@@ -51033,8 +51168,8 @@ function registerSessionCommands(program3) {
|
|
|
51033
51168
|
|
|
51034
51169
|
// src/commands/setup.ts
|
|
51035
51170
|
import { spawnSync as spawnSync2 } from "child_process";
|
|
51036
|
-
import { existsSync as existsSync21, readFileSync as
|
|
51037
|
-
import { join as
|
|
51171
|
+
import { existsSync as existsSync21, readFileSync as readFileSync21 } from "fs";
|
|
51172
|
+
import { join as join28 } from "path";
|
|
51038
51173
|
var EXIT_INCOMPLETE = 1;
|
|
51039
51174
|
var EXIT_USAGE3 = 2;
|
|
51040
51175
|
var SETUP_ORCHESTRATOR_ENV = "PRIM_SETUP_ORCHESTRATOR";
|
|
@@ -51172,8 +51307,8 @@ function detectProjectConflicts(agent, run, globalHooksActive) {
|
|
|
51172
51307
|
let preCommit;
|
|
51173
51308
|
try {
|
|
51174
51309
|
const root = gitToplevel();
|
|
51175
|
-
const path9 = root &&
|
|
51176
|
-
if (path9 && existsSync21(path9)) preCommit =
|
|
51310
|
+
const path9 = root && join28(root, ".git", "hooks", "pre-commit");
|
|
51311
|
+
if (path9 && existsSync21(path9)) preCommit = readFileSync21(path9, "utf-8");
|
|
51177
51312
|
} catch {
|
|
51178
51313
|
}
|
|
51179
51314
|
if (projectHooksConflict(globalHooksActive, preCommit)) conflicts.push(CONFLICT_HOOKS);
|
|
@@ -51359,16 +51494,16 @@ import {
|
|
|
51359
51494
|
closeSync as closeSync8,
|
|
51360
51495
|
existsSync as existsSync23,
|
|
51361
51496
|
fstatSync as fstatSync4,
|
|
51362
|
-
lstatSync as
|
|
51497
|
+
lstatSync as lstatSync9,
|
|
51363
51498
|
openSync as openSync8,
|
|
51364
|
-
readFileSync as
|
|
51499
|
+
readFileSync as readFileSync23,
|
|
51365
51500
|
readSync as readSync4,
|
|
51366
51501
|
readdirSync as readdirSync9,
|
|
51367
51502
|
rmdirSync as rmdirSync3,
|
|
51368
51503
|
unlinkSync as unlinkSync8
|
|
51369
51504
|
} from "fs";
|
|
51370
51505
|
import { homedir as homedir11 } from "os";
|
|
51371
|
-
import { dirname as dirname17, join as
|
|
51506
|
+
import { dirname as dirname17, join as join31, resolve as resolve9 } from "path";
|
|
51372
51507
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
51373
51508
|
|
|
51374
51509
|
// node_modules/.pnpm/diff@5.2.2/node_modules/diff/lib/index.mjs
|
|
@@ -51538,7 +51673,7 @@ Diff.prototype = {
|
|
|
51538
51673
|
tokenize: function tokenize(value) {
|
|
51539
51674
|
return value.split("");
|
|
51540
51675
|
},
|
|
51541
|
-
join: function
|
|
51676
|
+
join: function join29(chars) {
|
|
51542
51677
|
return chars.join("");
|
|
51543
51678
|
}
|
|
51544
51679
|
};
|
|
@@ -51880,10 +52015,10 @@ import {
|
|
|
51880
52015
|
closeSync as closeSync7,
|
|
51881
52016
|
existsSync as existsSync22,
|
|
51882
52017
|
fstatSync as fstatSync3,
|
|
51883
|
-
lstatSync as
|
|
52018
|
+
lstatSync as lstatSync8,
|
|
51884
52019
|
mkdirSync as mkdirSync15,
|
|
51885
52020
|
openSync as openSync7,
|
|
51886
|
-
readFileSync as
|
|
52021
|
+
readFileSync as readFileSync22,
|
|
51887
52022
|
readSync as readSync3,
|
|
51888
52023
|
readdirSync as readdirSync8,
|
|
51889
52024
|
realpathSync as realpathSync5,
|
|
@@ -51891,15 +52026,15 @@ import {
|
|
|
51891
52026
|
rmdirSync as rmdirSync2
|
|
51892
52027
|
} from "fs";
|
|
51893
52028
|
import { homedir as homedir10 } from "os";
|
|
51894
|
-
import { dirname as dirname16, isAbsolute as isAbsolute9, join as
|
|
52029
|
+
import { dirname as dirname16, isAbsolute as isAbsolute9, join as join30, relative as relative3, resolve as resolve8, sep as sep3 } from "path";
|
|
51895
52030
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
51896
52031
|
var __dirname4 = dirname16(fileURLToPath4(import.meta.url));
|
|
51897
52032
|
var PLUGIN_DESCRIPTION = "Primitive decision-graph guidance for the prim CLI \u2014 a model-invoked skill installed by prim skill install.";
|
|
51898
52033
|
var MAX_MANIFEST_BYTES2 = 64 * 1024;
|
|
51899
52034
|
var MAX_SKILL_BYTES = 1024 * 1024;
|
|
51900
52035
|
function pluginDirFor(cwd, scope) {
|
|
51901
|
-
const base = scope === "user" ?
|
|
51902
|
-
return
|
|
52036
|
+
const base = scope === "user" ? join30(homedir10(), ".claude") : join30(gitToplevel(cwd) ?? cwd, ".claude");
|
|
52037
|
+
return join30(base, "skills", "prim");
|
|
51903
52038
|
}
|
|
51904
52039
|
function resolvePluginDir(cwd, scope) {
|
|
51905
52040
|
if (scope && scope !== "user" && scope !== "project") {
|
|
@@ -51912,7 +52047,7 @@ function packageVersion2() {
|
|
|
51912
52047
|
let dir = __dirname4;
|
|
51913
52048
|
while (dir !== dirname16(dir)) {
|
|
51914
52049
|
const p = resolve8(dir, "package.json");
|
|
51915
|
-
if (existsSync22(p)) return JSON.parse(
|
|
52050
|
+
if (existsSync22(p)) return JSON.parse(readFileSync22(p, "utf-8")).version;
|
|
51916
52051
|
dir = dirname16(dir);
|
|
51917
52052
|
}
|
|
51918
52053
|
return "0.0.0";
|
|
@@ -51931,8 +52066,8 @@ function removeDirIfEmpty(dir) {
|
|
|
51931
52066
|
}
|
|
51932
52067
|
function pluginPaths(dir) {
|
|
51933
52068
|
return {
|
|
51934
|
-
manifestPath:
|
|
51935
|
-
skillPath:
|
|
52069
|
+
manifestPath: join30(dir, ".claude-plugin", "plugin.json"),
|
|
52070
|
+
skillPath: join30(dir, "SKILL.md")
|
|
51936
52071
|
};
|
|
51937
52072
|
}
|
|
51938
52073
|
function installClaudePlugin(cwd, opts) {
|
|
@@ -51940,8 +52075,8 @@ function installClaudePlugin(cwd, opts) {
|
|
|
51940
52075
|
if (dir === null) return 1;
|
|
51941
52076
|
const { manifestPath, skillPath } = pluginPaths(dir);
|
|
51942
52077
|
const { manifest, skill } = renderClaudePlugin();
|
|
51943
|
-
const manifestCurrent = existsSync22(manifestPath) ?
|
|
51944
|
-
const skillCurrent = existsSync22(skillPath) ?
|
|
52078
|
+
const manifestCurrent = existsSync22(manifestPath) ? readFileSync22(manifestPath, "utf-8") : null;
|
|
52079
|
+
const skillCurrent = existsSync22(skillPath) ? readFileSync22(skillPath, "utf-8") : null;
|
|
51945
52080
|
if (manifestCurrent === manifest && skillCurrent === skill) {
|
|
51946
52081
|
console.log("No changes \u2014 prim skill plugin already up to date.");
|
|
51947
52082
|
return 0;
|
|
@@ -51950,9 +52085,9 @@ function installClaudePlugin(cwd, opts) {
|
|
|
51950
52085
|
console.log(`Would write plugin to ${dir} (.claude-plugin/plugin.json + SKILL.md)`);
|
|
51951
52086
|
return 0;
|
|
51952
52087
|
}
|
|
51953
|
-
mkdirSync15(
|
|
51954
|
-
|
|
51955
|
-
|
|
52088
|
+
mkdirSync15(join30(dir, ".claude-plugin"), { recursive: true });
|
|
52089
|
+
atomicWrite5(manifestPath, manifest);
|
|
52090
|
+
atomicWrite5(skillPath, skill);
|
|
51956
52091
|
console.log(`Installed prim skill plugin at ${dir}`);
|
|
51957
52092
|
console.log("Restart Claude Code or run /reload-plugins to load it.");
|
|
51958
52093
|
if (opts.scope !== "user") {
|
|
@@ -51970,7 +52105,7 @@ function uninstallClaudePlugin(cwd, opts) {
|
|
|
51970
52105
|
}
|
|
51971
52106
|
rmSync9(manifestPath, { force: true });
|
|
51972
52107
|
rmSync9(skillPath, { force: true });
|
|
51973
|
-
removeDirIfEmpty(
|
|
52108
|
+
removeDirIfEmpty(join30(dir, ".claude-plugin"));
|
|
51974
52109
|
removeDirIfEmpty(dir);
|
|
51975
52110
|
console.log(`Removed prim skill plugin from ${dir}`);
|
|
51976
52111
|
return 0;
|
|
@@ -52021,19 +52156,19 @@ function sha2563(content) {
|
|
|
52021
52156
|
}
|
|
52022
52157
|
function cursorSkillDirectory(cwd, scope) {
|
|
52023
52158
|
const base = scope === "user" ? cursorConfigDirectory() : gitToplevel(cwd) ?? cwd;
|
|
52024
|
-
return
|
|
52159
|
+
return join31(base, scope === "user" ? "skills" : ".cursor/skills", "prim");
|
|
52025
52160
|
}
|
|
52026
52161
|
function cursorSkillPaths(cwd, scope) {
|
|
52027
52162
|
const directory = cursorSkillDirectory(cwd, scope);
|
|
52028
52163
|
return {
|
|
52029
52164
|
directory,
|
|
52030
|
-
skill:
|
|
52031
|
-
manifest:
|
|
52165
|
+
skill: join31(directory, "SKILL.md"),
|
|
52166
|
+
manifest: join31(directory, CURSOR_SKILL_MANIFEST)
|
|
52032
52167
|
};
|
|
52033
52168
|
}
|
|
52034
52169
|
function readCursorSkillManifest(path9) {
|
|
52035
52170
|
try {
|
|
52036
|
-
const value = JSON.parse(
|
|
52171
|
+
const value = JSON.parse(readFileSync23(path9, "utf8"));
|
|
52037
52172
|
if (!value || typeof value !== "object" || Array.isArray(value)) return;
|
|
52038
52173
|
const record3 = value;
|
|
52039
52174
|
if (record3.version !== 1 || record3.owner !== CURSOR_SKILL_OWNER || typeof record3.contentSha256 !== "string" || !/^[0-9a-f]{64}$/u.test(record3.contentSha256)) {
|
|
@@ -52047,7 +52182,7 @@ function readCursorSkillManifest(path9) {
|
|
|
52047
52182
|
function cursorSkillStatus(cwd, scope) {
|
|
52048
52183
|
const paths = cursorSkillPaths(cwd, scope);
|
|
52049
52184
|
const manifest = readCursorSkillManifest(paths.manifest);
|
|
52050
|
-
const content = existsSync23(paths.skill) ?
|
|
52185
|
+
const content = existsSync23(paths.skill) ? readFileSync23(paths.skill, "utf8") : void 0;
|
|
52051
52186
|
const owned = manifest !== void 0;
|
|
52052
52187
|
const installed = owned && content !== void 0 && sha2563(content) === manifest.contentSha256;
|
|
52053
52188
|
return {
|
|
@@ -52077,12 +52212,12 @@ function installCursorSkill(cwd, opts) {
|
|
|
52077
52212
|
owner: CURSOR_SKILL_OWNER,
|
|
52078
52213
|
contentSha256: sha2563(content)
|
|
52079
52214
|
};
|
|
52080
|
-
if (status.installed &&
|
|
52215
|
+
if (status.installed && readFileSync23(paths.skill, "utf8") === content) {
|
|
52081
52216
|
console.log(`No changes \u2014 Cursor skill already up to date at ${paths.skill}`);
|
|
52082
52217
|
return 0;
|
|
52083
52218
|
}
|
|
52084
52219
|
if (opts.dryRun) {
|
|
52085
|
-
const existing = skillExists ?
|
|
52220
|
+
const existing = skillExists ? readFileSync23(paths.skill, "utf8") : "";
|
|
52086
52221
|
process.stdout.write(createPatch(paths.skill, existing, content, "current", "proposed"));
|
|
52087
52222
|
return 0;
|
|
52088
52223
|
}
|
|
@@ -52113,10 +52248,10 @@ function uninstallCursorSkill(cwd, scope) {
|
|
|
52113
52248
|
return 0;
|
|
52114
52249
|
}
|
|
52115
52250
|
function userTargetFor(agent) {
|
|
52116
|
-
if (agent === "claude") return
|
|
52117
|
-
if (agent === "codex") return
|
|
52251
|
+
if (agent === "claude") return join31(homedir11(), ".claude", "CLAUDE.md");
|
|
52252
|
+
if (agent === "codex") return join31(homedir11(), ".codex", "AGENTS.md");
|
|
52118
52253
|
if (agent === "hermes") {
|
|
52119
|
-
return
|
|
52254
|
+
return join31(process.env.HERMES_HOME ?? join31(homedir11(), ".hermes"), ".hermes.md");
|
|
52120
52255
|
}
|
|
52121
52256
|
return null;
|
|
52122
52257
|
}
|
|
@@ -52124,7 +52259,7 @@ function loadSkill() {
|
|
|
52124
52259
|
let dir = __dirname5;
|
|
52125
52260
|
while (dir !== dirname17(dir)) {
|
|
52126
52261
|
const p = resolve9(dir, "SKILL.md");
|
|
52127
|
-
if (existsSync23(p)) return
|
|
52262
|
+
if (existsSync23(p)) return readFileSync23(p, "utf-8");
|
|
52128
52263
|
dir = dirname17(dir);
|
|
52129
52264
|
}
|
|
52130
52265
|
throw new Error("SKILL.md not found in package");
|
|
@@ -52156,7 +52291,7 @@ function removeBlock(existing) {
|
|
|
52156
52291
|
const out = existing.slice(0, b) + existing.slice(e + SKILL_END.length);
|
|
52157
52292
|
return out.replace(/(\r?\n){2,}$/, "$1");
|
|
52158
52293
|
}
|
|
52159
|
-
function
|
|
52294
|
+
function atomicWrite5(target, content) {
|
|
52160
52295
|
atomicWriteFile(target, content);
|
|
52161
52296
|
}
|
|
52162
52297
|
function resolveTarget(cwd, opts) {
|
|
@@ -52196,7 +52331,7 @@ function runInstall(cwd, opts) {
|
|
|
52196
52331
|
}
|
|
52197
52332
|
const target = resolveTarget(cwd, opts);
|
|
52198
52333
|
if (target === null) return 1;
|
|
52199
|
-
const existing = existsSync23(target) ?
|
|
52334
|
+
const existing = existsSync23(target) ? readFileSync23(target, "utf-8") : "";
|
|
52200
52335
|
const eol = existing ? detectNewline(existing) : "\n";
|
|
52201
52336
|
const block = composeBlock(loadSkill(), eol);
|
|
52202
52337
|
const next = applyBlock(existing, block, eol);
|
|
@@ -52208,7 +52343,7 @@ function runInstall(cwd, opts) {
|
|
|
52208
52343
|
process.stdout.write(createPatch(target, existing, next, "current", "proposed"));
|
|
52209
52344
|
return 0;
|
|
52210
52345
|
}
|
|
52211
|
-
|
|
52346
|
+
atomicWrite5(target, next);
|
|
52212
52347
|
console.log(`Wrote ${Buffer.byteLength(next)} bytes to ${target}`);
|
|
52213
52348
|
return 0;
|
|
52214
52349
|
}
|
|
@@ -52224,13 +52359,13 @@ function runUninstall(cwd, opts) {
|
|
|
52224
52359
|
console.log(`Skill block not present at ${target}`);
|
|
52225
52360
|
return 0;
|
|
52226
52361
|
}
|
|
52227
|
-
const existing =
|
|
52362
|
+
const existing = readFileSync23(target, "utf-8");
|
|
52228
52363
|
const next = removeBlock(existing);
|
|
52229
52364
|
if (next === null) {
|
|
52230
52365
|
console.log(`Skill block not present at ${target}`);
|
|
52231
52366
|
return 0;
|
|
52232
52367
|
}
|
|
52233
|
-
|
|
52368
|
+
atomicWrite5(target, next);
|
|
52234
52369
|
console.log(`Removed skill block from ${target}`);
|
|
52235
52370
|
return 0;
|
|
52236
52371
|
}
|
|
@@ -52251,7 +52386,7 @@ function runStatus(cwd, opts) {
|
|
|
52251
52386
|
const fileExists = existsSync23(target);
|
|
52252
52387
|
let installed = false;
|
|
52253
52388
|
if (fileExists) {
|
|
52254
|
-
const content =
|
|
52389
|
+
const content = readFileSync23(target, "utf-8");
|
|
52255
52390
|
installed = content.includes(SKILL_BEGIN) && content.includes(SKILL_END);
|
|
52256
52391
|
}
|
|
52257
52392
|
if (opts.json) {
|
|
@@ -52288,7 +52423,7 @@ function registerSkillCommands(program3) {
|
|
|
52288
52423
|
}
|
|
52289
52424
|
|
|
52290
52425
|
// src/commands/statusline.ts
|
|
52291
|
-
import { readFileSync as
|
|
52426
|
+
import { readFileSync as readFileSync24 } from "fs";
|
|
52292
52427
|
import { dirname as dirname18, resolve as resolve10 } from "path";
|
|
52293
52428
|
import { fileURLToPath as fileURLToPath6 } from "url";
|
|
52294
52429
|
var STATUSLINE_TIMEOUT_MS = 200;
|
|
@@ -52304,7 +52439,7 @@ function readPackageVersion() {
|
|
|
52304
52439
|
];
|
|
52305
52440
|
for (const path9 of candidates) {
|
|
52306
52441
|
try {
|
|
52307
|
-
const pkg2 = JSON.parse(
|
|
52442
|
+
const pkg2 = JSON.parse(readFileSync24(path9, "utf-8"));
|
|
52308
52443
|
if (pkg2.version) {
|
|
52309
52444
|
return pkg2.version;
|
|
52310
52445
|
}
|
|
@@ -52848,13 +52983,13 @@ function healDaemonDrift(options = {}) {
|
|
|
52848
52983
|
|
|
52849
52984
|
// src/lib/background-flush.ts
|
|
52850
52985
|
import { spawn as spawn5 } from "child_process";
|
|
52851
|
-
import { readFileSync as
|
|
52986
|
+
import { readFileSync as readFileSync25 } from "fs";
|
|
52852
52987
|
|
|
52853
52988
|
// src/daemon/health.ts
|
|
52854
|
-
import { chmodSync as
|
|
52855
|
-
import { dirname as dirname19, join as
|
|
52989
|
+
import { chmodSync as chmodSync8, existsSync as existsSync24, mkdirSync as mkdirSync16, renameSync as renameSync7, writeFileSync as writeFileSync11 } from "fs";
|
|
52990
|
+
import { dirname as dirname19, join as join32 } from "path";
|
|
52856
52991
|
var HEARTBEAT_FRESH_MS = 9e4;
|
|
52857
|
-
var DAEMON_HEALTH_PATH =
|
|
52992
|
+
var DAEMON_HEALTH_PATH = join32(primConfigDirectory(), "daemon-health.json");
|
|
52858
52993
|
|
|
52859
52994
|
// src/lib/background-flush.ts
|
|
52860
52995
|
function record2(value) {
|
|
@@ -52865,7 +53000,7 @@ function daemonOwnsDrain(options = {}) {
|
|
|
52865
53000
|
const expectedVersion = options.expectedVersion === void 0 ? packageVersion() : options.expectedVersion;
|
|
52866
53001
|
if (!expectedVersion) return false;
|
|
52867
53002
|
const health = record2(
|
|
52868
|
-
JSON.parse(
|
|
53003
|
+
JSON.parse(readFileSync25(options.healthPath ?? DAEMON_HEALTH_PATH, "utf8"))
|
|
52869
53004
|
);
|
|
52870
53005
|
const heartbeat = record2(health?.heartbeat);
|
|
52871
53006
|
const ingestion = record2(health?.ingestion);
|
|
@@ -52982,7 +53117,7 @@ function runStartupBackgroundWork(argv, env4, work) {
|
|
|
52982
53117
|
|
|
52983
53118
|
// src/index.ts
|
|
52984
53119
|
var __dirname6 = dirname20(fileURLToPath7(import.meta.url));
|
|
52985
|
-
var pkg = JSON.parse(
|
|
53120
|
+
var pkg = JSON.parse(readFileSync26(resolve11(__dirname6, "../package.json"), "utf-8"));
|
|
52986
53121
|
runStartupBackgroundWork(process.argv.slice(2), process.env, {
|
|
52987
53122
|
notify: () => updateNotifier({ pkg }).notify(),
|
|
52988
53123
|
flush: () => startBackgroundFlush(),
|