@primitive.ai/prim 0.1.0-alpha.98 → 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 +11 -0
- package/dist/{chunk-7IPGD6CD.js → chunk-25DDRMWS.js} +2 -2
- package/dist/{chunk-B6EPQ4YH.js → chunk-2IRLFOEL.js} +123 -19
- package/dist/{chunk-WKLYYT63.js → chunk-2Q3OGSTV.js} +3 -3
- package/dist/{chunk-2DPLT2CQ.js → chunk-5LRKJTLA.js} +1 -1
- package/dist/{chunk-AN6XTFIN.js → chunk-6C3CCVDI.js} +2 -2
- package/dist/{chunk-NIQAVFP6.js → chunk-7VIMU2HR.js} +1 -1
- package/dist/{chunk-2DA2B4EC.js → chunk-EJPKZT5M.js} +2 -2
- package/dist/{chunk-HUZXBJJ5.js → chunk-FK7FJPWS.js} +1 -1
- package/dist/{chunk-QPMLAD2C.js → chunk-JJI7FU24.js} +2 -2
- package/dist/{chunk-PPZBEOWK.js → chunk-JJYS7IPD.js} +3 -3
- package/dist/{chunk-RT7DXMTN.js → chunk-K4JWJ6OM.js} +79 -266
- package/dist/{chunk-3X77XQGW.js → chunk-KGBMU76T.js} +1 -1
- package/dist/{chunk-JOR67B5T.js → chunk-O2WV5SQZ.js} +8 -8
- package/dist/{chunk-IL443QTF.js → chunk-X5BN67D2.js} +2 -2
- package/dist/{chunk-6QK75B7G.js → chunk-XG7S3LIL.js} +214 -11
- package/dist/{chunk-MN4X6RR6.js → chunk-XPS6LG6I.js} +5 -7
- package/dist/{chunk-BIAWZMCK.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 +177 -33
- 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 +615 -515
- package/dist/hook-runtime/statusline-main.js +71 -16
- package/dist/hooks/post-commit.js +7 -7
- package/dist/hooks/post-rewrite.js +6 -6
- package/dist/hooks/post-tool-use.js +13 -13
- package/dist/hooks/pre-commit.js +4 -4
- package/dist/hooks/pre-tool-use.js +10 -11
- package/dist/hooks/prim-hook.js +14 -14
- package/dist/hooks/session-end.js +4 -4
- package/dist/hooks/session-start.js +11 -11
- package/dist/index.js +20 -20
- package/dist/statusline-main.js +71 -16
- package/package.json +1 -1
|
@@ -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
|
|
|
@@ -13176,8 +13176,8 @@ function decisionIngestionStatus(cwd) {
|
|
|
13176
13176
|
|
|
13177
13177
|
// src/client.ts
|
|
13178
13178
|
import { createHash as createHash4 } from "crypto";
|
|
13179
|
-
import { chmodSync, existsSync as
|
|
13180
|
-
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";
|
|
13181
13181
|
|
|
13182
13182
|
// src/lib/atomic-file.ts
|
|
13183
13183
|
import { randomUUID } from "crypto";
|
|
@@ -13435,6 +13435,293 @@ async function withFileLock(lockDir, operation, options = {}) {
|
|
|
13435
13435
|
}
|
|
13436
13436
|
}
|
|
13437
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
|
+
|
|
13438
13725
|
// src/lib/terminal-safe.ts
|
|
13439
13726
|
function replaceIsolatedSurrogates(value) {
|
|
13440
13727
|
let out = "";
|
|
@@ -13485,7 +13772,7 @@ var DEFAULT_API_URL = "https://api.getprimitive.ai";
|
|
|
13485
13772
|
var AUTH_EXPIRED_MESSAGE = "Authentication expired. Run `prim auth login` to re-authenticate.";
|
|
13486
13773
|
function readTrimmed2(path9) {
|
|
13487
13774
|
try {
|
|
13488
|
-
const value =
|
|
13775
|
+
const value = readFileSync6(path9, "utf8").trim();
|
|
13489
13776
|
return value || void 0;
|
|
13490
13777
|
} catch {
|
|
13491
13778
|
return void 0;
|
|
@@ -13501,16 +13788,16 @@ function expiresAtFor(token, expiresIn) {
|
|
|
13501
13788
|
return expiresIn === void 0 ? jwtExpiresAt(token) : Date.now() + expiresIn * 1e3;
|
|
13502
13789
|
}
|
|
13503
13790
|
function ensureConfigDirectory() {
|
|
13504
|
-
const directory =
|
|
13791
|
+
const directory = dirname5(TOKEN_FILE_PATH);
|
|
13505
13792
|
mkdirSync3(directory, { recursive: true, mode: CONFIG_DIR_MODE });
|
|
13506
|
-
|
|
13793
|
+
chmodSync2(directory, CONFIG_DIR_MODE);
|
|
13507
13794
|
}
|
|
13508
|
-
function
|
|
13795
|
+
function atomicWrite2(path9, content) {
|
|
13509
13796
|
ensureConfigDirectory();
|
|
13510
13797
|
atomicWriteFile(path9, content, { mode: CREDENTIAL_FILE_MODE });
|
|
13511
13798
|
}
|
|
13512
13799
|
function removeCredentialFile(path9) {
|
|
13513
|
-
if (!
|
|
13800
|
+
if (!existsSync4(path9)) return false;
|
|
13514
13801
|
rmSync3(path9, { force: true });
|
|
13515
13802
|
return true;
|
|
13516
13803
|
}
|
|
@@ -13544,7 +13831,7 @@ function credentialFamilyMetadata(accessToken, refreshToken2, metadata) {
|
|
|
13544
13831
|
return metadata === void 0 ? legacyBrokerCredentialMetadata(accessToken, refreshToken2) : { ...metadata, ...hashes };
|
|
13545
13832
|
}
|
|
13546
13833
|
function writeCredentialMigrationSentinel() {
|
|
13547
|
-
|
|
13834
|
+
atomicWrite2(
|
|
13548
13835
|
CREDENTIAL_MIGRATION_PATH,
|
|
13549
13836
|
`${JSON.stringify({
|
|
13550
13837
|
version: CREDENTIAL_MIGRATION_VERSION,
|
|
@@ -13562,7 +13849,7 @@ function bindLegacyBrokerGeneration(accessToken, refreshToken2, metadata) {
|
|
|
13562
13849
|
return { state: "invalid" };
|
|
13563
13850
|
}
|
|
13564
13851
|
if (metadata.metadata === void 0) {
|
|
13565
|
-
|
|
13852
|
+
atomicWrite2(CREDENTIAL_FAMILY_PATH, `${JSON.stringify(familyMetadata)}
|
|
13566
13853
|
`);
|
|
13567
13854
|
}
|
|
13568
13855
|
const migrationState = readCredentialMigrationState();
|
|
@@ -13577,14 +13864,14 @@ function preserveMarkerlessLegacyGeneration() {
|
|
|
13577
13864
|
const refreshToken2 = readTrimmed2(REFRESH_TOKEN_PATH);
|
|
13578
13865
|
if (!(accessToken && refreshToken2)) return;
|
|
13579
13866
|
const familyMetadata = legacyBrokerCredentialMetadata(accessToken, refreshToken2);
|
|
13580
|
-
|
|
13867
|
+
atomicWrite2(CREDENTIAL_FAMILY_PATH, `${JSON.stringify(familyMetadata)}
|
|
13581
13868
|
`);
|
|
13582
13869
|
}
|
|
13583
13870
|
function terminalFingerprint() {
|
|
13584
13871
|
return readTrimmed2(TERMINAL_REFRESH_PATH);
|
|
13585
13872
|
}
|
|
13586
13873
|
function writeTerminalFingerprint(refreshToken2) {
|
|
13587
|
-
|
|
13874
|
+
atomicWrite2(TERMINAL_REFRESH_PATH, `${refreshFingerprint(refreshToken2)}
|
|
13588
13875
|
`);
|
|
13589
13876
|
}
|
|
13590
13877
|
function clearTerminalFingerprint() {
|
|
@@ -13609,24 +13896,24 @@ function commitCredentialsUnlocked(credentials) {
|
|
|
13609
13896
|
if (credentials.metadata !== void 0) {
|
|
13610
13897
|
preserveMarkerlessLegacyGeneration();
|
|
13611
13898
|
writeCredentialMigrationSentinel();
|
|
13612
|
-
|
|
13899
|
+
atomicWrite2(CREDENTIAL_FAMILY_PATH, `${JSON.stringify(familyMetadata)}
|
|
13613
13900
|
`);
|
|
13614
|
-
|
|
13901
|
+
atomicWrite2(CREDENTIAL_METADATA_PATH, `${JSON.stringify(familyMetadata)}
|
|
13615
13902
|
`);
|
|
13616
|
-
|
|
13903
|
+
atomicWrite2(REFRESH_TOKEN_PATH, `${refreshToken2}
|
|
13617
13904
|
`);
|
|
13618
13905
|
} else {
|
|
13619
|
-
|
|
13906
|
+
atomicWrite2(REFRESH_TOKEN_PATH, `${refreshToken2}
|
|
13620
13907
|
`);
|
|
13621
|
-
|
|
13908
|
+
atomicWrite2(CREDENTIAL_FAMILY_PATH, `${JSON.stringify(familyMetadata)}
|
|
13622
13909
|
`);
|
|
13623
13910
|
removeCredentialFile(CREDENTIAL_METADATA_PATH);
|
|
13624
13911
|
}
|
|
13625
13912
|
const expiresAt = expiresAtFor(accessToken, credentials.expiresIn);
|
|
13626
13913
|
if (expiresAt === void 0) removeCredentialFile(TOKEN_EXPIRES_PATH);
|
|
13627
|
-
else
|
|
13914
|
+
else atomicWrite2(TOKEN_EXPIRES_PATH, `${expiresAt}
|
|
13628
13915
|
`);
|
|
13629
|
-
|
|
13916
|
+
atomicWrite2(TOKEN_FILE_PATH, `${accessToken}
|
|
13630
13917
|
`);
|
|
13631
13918
|
clearTerminalFingerprint();
|
|
13632
13919
|
_cachedCredential = { token: accessToken, source: "token_file" };
|
|
@@ -13644,7 +13931,7 @@ async function setStoredToken(token, options = {}) {
|
|
|
13644
13931
|
removeCredentialFile(CREDENTIAL_METADATA_PATH);
|
|
13645
13932
|
clearTerminalFingerprint();
|
|
13646
13933
|
removeCredentialFile(CREDENTIAL_MIGRATION_PATH);
|
|
13647
|
-
|
|
13934
|
+
atomicWrite2(TOKEN_FILE_PATH, `${value}
|
|
13648
13935
|
`);
|
|
13649
13936
|
_cachedCredential = { token: value, source: "token_file" };
|
|
13650
13937
|
}, options);
|
|
@@ -13937,12 +14224,13 @@ function selectedCredential() {
|
|
|
13937
14224
|
}
|
|
13938
14225
|
return _cachedCredential;
|
|
13939
14226
|
}
|
|
13940
|
-
function fetchWithToken(method, path9, body, options, token, siteUrl) {
|
|
14227
|
+
async function fetchWithToken(method, path9, body, options, token, siteUrl) {
|
|
13941
14228
|
return fetch(`${siteUrl}${path9}`, {
|
|
13942
14229
|
method,
|
|
13943
14230
|
headers: {
|
|
13944
14231
|
Authorization: `Bearer ${token}`,
|
|
13945
|
-
"Content-Type": "application/json"
|
|
14232
|
+
"Content-Type": "application/json",
|
|
14233
|
+
...method === "POST" && path9 === "/api/cli/moves/ingest" ? await ingestUploaderHeaders() : {}
|
|
13946
14234
|
},
|
|
13947
14235
|
body: body === void 0 ? void 0 : JSON.stringify(body),
|
|
13948
14236
|
signal: options?.signal
|
|
@@ -32470,8 +32758,8 @@ function scheduleCollectScopeRefresh(cwd, collectScopeVersion, dependencies = de
|
|
|
32470
32758
|
|
|
32471
32759
|
// src/lib/commit-heartbeat.ts
|
|
32472
32760
|
import { execFileSync as execFileSync3 } from "child_process";
|
|
32473
|
-
import { mkdirSync as mkdirSync4, readFileSync as
|
|
32474
|
-
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";
|
|
32475
32763
|
var FIRED_DIR = "prim/post-commit-fired";
|
|
32476
32764
|
var WIRED_PATH = "prim/git-hooks-wired";
|
|
32477
32765
|
var GIT_TIMEOUT_MS3 = 1e3;
|
|
@@ -32490,7 +32778,7 @@ function commonPath(cwd, relative4) {
|
|
|
32490
32778
|
timeout: GIT_TIMEOUT_MS3
|
|
32491
32779
|
}).replace(/\r?\n$/u, "");
|
|
32492
32780
|
if (value === "" || /[\0\r\n]/u.test(value)) throw new Error("Git returned an unsafe path");
|
|
32493
|
-
return
|
|
32781
|
+
return join9(resolve3(cwd, value), relative4);
|
|
32494
32782
|
}
|
|
32495
32783
|
function gitPath(cwd, relative4) {
|
|
32496
32784
|
const value = execFileSync3("git", ["rev-parse", "--git-path", relative4], {
|
|
@@ -32503,8 +32791,8 @@ function gitPath(cwd, relative4) {
|
|
|
32503
32791
|
return resolve3(cwd, value);
|
|
32504
32792
|
}
|
|
32505
32793
|
function ensurePrivateParent(path9) {
|
|
32506
|
-
mkdirSync4(
|
|
32507
|
-
mkdirSync4(
|
|
32794
|
+
mkdirSync4(dirname6(dirname6(path9)), { recursive: true, mode: 448 });
|
|
32795
|
+
mkdirSync4(dirname6(path9), { recursive: true, mode: 448 });
|
|
32508
32796
|
}
|
|
32509
32797
|
function writeStamp(path9, at) {
|
|
32510
32798
|
ensurePrivateParent(path9);
|
|
@@ -32513,7 +32801,7 @@ function writeStamp(path9, at) {
|
|
|
32513
32801
|
}
|
|
32514
32802
|
function readStampAt(path9) {
|
|
32515
32803
|
try {
|
|
32516
|
-
const raw =
|
|
32804
|
+
const raw = readFileSync7(path9, "utf8");
|
|
32517
32805
|
if (raw.length > MAX_STAMP_BYTES) return void 0;
|
|
32518
32806
|
const parsed = JSON.parse(raw);
|
|
32519
32807
|
return typeof parsed.at === "number" && Number.isSafeInteger(parsed.at) && parsed.at > 0 ? parsed.at : void 0;
|
|
@@ -32533,7 +32821,7 @@ function readFiredStamps(cwd) {
|
|
|
32533
32821
|
const dir = gitPath(cwd, FIRED_DIR);
|
|
32534
32822
|
return readdirSync(dir).flatMap((sha) => {
|
|
32535
32823
|
if (!FULL_SHA_RE.test(sha)) return [];
|
|
32536
|
-
const at = readStampAt(
|
|
32824
|
+
const at = readStampAt(join9(dir, sha));
|
|
32537
32825
|
return at === void 0 ? [] : [{ sha, at }];
|
|
32538
32826
|
});
|
|
32539
32827
|
} catch {
|
|
@@ -32635,204 +32923,16 @@ import {
|
|
|
32635
32923
|
existsSync as existsSync6,
|
|
32636
32924
|
fchmodSync as fchmodSync2,
|
|
32637
32925
|
fsyncSync as fsyncSync2,
|
|
32638
|
-
lstatSync as
|
|
32926
|
+
lstatSync as lstatSync4,
|
|
32639
32927
|
mkdirSync as mkdirSync7,
|
|
32640
32928
|
openSync as openSync2,
|
|
32641
|
-
readFileSync as
|
|
32929
|
+
readFileSync as readFileSync9,
|
|
32642
32930
|
realpathSync as realpathSync3,
|
|
32643
32931
|
renameSync as renameSync3,
|
|
32644
32932
|
unlinkSync as unlinkSync2,
|
|
32645
32933
|
writeFileSync as writeFileSync5
|
|
32646
32934
|
} from "fs";
|
|
32647
|
-
import { basename as basename2, dirname as dirname8, isAbsolute as isAbsolute6, join as
|
|
32648
|
-
|
|
32649
|
-
// src/lib/bin-path.ts
|
|
32650
|
-
import { existsSync as existsSync4, readFileSync as readFileSync6 } from "fs";
|
|
32651
|
-
import { dirname as dirname6, isAbsolute as isAbsolute3, join as join8 } from "path";
|
|
32652
|
-
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
32653
|
-
|
|
32654
|
-
// src/lib/semver.ts
|
|
32655
|
-
function parseSemver(value) {
|
|
32656
|
-
if (typeof value !== "string" || value.length > 256) return;
|
|
32657
|
-
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(
|
|
32658
|
-
value
|
|
32659
|
-
);
|
|
32660
|
-
if (!match) return;
|
|
32661
|
-
const prerelease = match[4]?.split(".") ?? [];
|
|
32662
|
-
if (prerelease.some((part) => /^\d+$/u.test(part) && part.length > 1 && part.startsWith("0"))) {
|
|
32663
|
-
return;
|
|
32664
|
-
}
|
|
32665
|
-
return { core: [BigInt(match[1]), BigInt(match[2]), BigInt(match[3])], prerelease };
|
|
32666
|
-
}
|
|
32667
|
-
function compareSemver(left, right) {
|
|
32668
|
-
const a = parseSemver(left);
|
|
32669
|
-
const b = parseSemver(right);
|
|
32670
|
-
if (!a || !b) return;
|
|
32671
|
-
for (let i = 0; i < a.core.length; i += 1) {
|
|
32672
|
-
if (a.core[i] !== b.core[i]) return a.core[i] < b.core[i] ? -1 : 1;
|
|
32673
|
-
}
|
|
32674
|
-
if (a.prerelease.length === 0 || b.prerelease.length === 0) {
|
|
32675
|
-
return a.prerelease.length === b.prerelease.length ? 0 : a.prerelease.length === 0 ? 1 : -1;
|
|
32676
|
-
}
|
|
32677
|
-
for (let i = 0; i < Math.max(a.prerelease.length, b.prerelease.length); i += 1) {
|
|
32678
|
-
const x = a.prerelease[i];
|
|
32679
|
-
const y = b.prerelease[i];
|
|
32680
|
-
if (x === void 0 || y === void 0) return x === void 0 ? -1 : 1;
|
|
32681
|
-
if (x === y) continue;
|
|
32682
|
-
const xNumeric = /^\d+$/u.test(x);
|
|
32683
|
-
const yNumeric = /^\d+$/u.test(y);
|
|
32684
|
-
if (xNumeric && yNumeric) return BigInt(x) < BigInt(y) ? -1 : 1;
|
|
32685
|
-
if (xNumeric !== yNumeric) return xNumeric ? -1 : 1;
|
|
32686
|
-
return x < y ? -1 : 1;
|
|
32687
|
-
}
|
|
32688
|
-
return 0;
|
|
32689
|
-
}
|
|
32690
|
-
|
|
32691
|
-
// src/lib/bin-path.ts
|
|
32692
|
-
var PKG_NAME = "@primitive.ai/prim";
|
|
32693
|
-
var ROOT_WALK_LIMIT = 6;
|
|
32694
|
-
var STABLE_HOOK_LAUNCHER_NAME = "prim-hook-launcher-v1";
|
|
32695
|
-
var resolvedRoot;
|
|
32696
|
-
function locateRoot() {
|
|
32697
|
-
if (resolvedRoot !== void 0) {
|
|
32698
|
-
return resolvedRoot;
|
|
32699
|
-
}
|
|
32700
|
-
let dir = dirname6(fileURLToPath3(import.meta.url));
|
|
32701
|
-
for (let depth = 0; depth < ROOT_WALK_LIMIT; depth++) {
|
|
32702
|
-
const manifestPath = join8(dir, "package.json");
|
|
32703
|
-
if (existsSync4(manifestPath)) {
|
|
32704
|
-
try {
|
|
32705
|
-
const manifest = JSON.parse(readFileSync6(manifestPath, "utf-8"));
|
|
32706
|
-
if (manifest.name === PKG_NAME && manifest.bin) {
|
|
32707
|
-
resolvedRoot = { dir, version: manifest.version, bin: manifest.bin };
|
|
32708
|
-
return resolvedRoot;
|
|
32709
|
-
}
|
|
32710
|
-
} catch {
|
|
32711
|
-
}
|
|
32712
|
-
}
|
|
32713
|
-
const parent = dirname6(dir);
|
|
32714
|
-
if (parent === dir) {
|
|
32715
|
-
break;
|
|
32716
|
-
}
|
|
32717
|
-
dir = parent;
|
|
32718
|
-
}
|
|
32719
|
-
resolvedRoot = null;
|
|
32720
|
-
return resolvedRoot;
|
|
32721
|
-
}
|
|
32722
|
-
function binFile(bin) {
|
|
32723
|
-
const root = locateRoot();
|
|
32724
|
-
const rel = root?.bin[bin];
|
|
32725
|
-
if (!root || !rel) {
|
|
32726
|
-
return null;
|
|
32727
|
-
}
|
|
32728
|
-
return isAbsolute3(rel) ? rel : join8(root.dir, rel);
|
|
32729
|
-
}
|
|
32730
|
-
function packageVersion() {
|
|
32731
|
-
return locateRoot()?.version ?? null;
|
|
32732
|
-
}
|
|
32733
|
-
function packageRoot() {
|
|
32734
|
-
return locateRoot()?.dir ?? null;
|
|
32735
|
-
}
|
|
32736
|
-
function shellQuote(value) {
|
|
32737
|
-
return `'${value.replaceAll("'", `'"'"'`)}'`;
|
|
32738
|
-
}
|
|
32739
|
-
function shellWord(value) {
|
|
32740
|
-
return /^[A-Za-z0-9_@%+=:,./-]+$/u.test(value) ? value : shellQuote(value);
|
|
32741
|
-
}
|
|
32742
|
-
function pinnedNpxArgs(bin, args = [], options = {}) {
|
|
32743
|
-
const version = packageVersion();
|
|
32744
|
-
if (!version) throw new Error("cannot determine Primitive package version");
|
|
32745
|
-
return [
|
|
32746
|
-
"--yes",
|
|
32747
|
-
"--ignore-scripts",
|
|
32748
|
-
...options.preferOnline ? ["--prefer-online"] : [],
|
|
32749
|
-
"-p",
|
|
32750
|
-
`${PKG_NAME}@${version}`,
|
|
32751
|
-
bin,
|
|
32752
|
-
...args
|
|
32753
|
-
];
|
|
32754
|
-
}
|
|
32755
|
-
function pinnedNpxCommand(bin, args = [], options = {}) {
|
|
32756
|
-
return ["npx", ...pinnedNpxArgs(bin, args, options)].map(shellWord).join(" ");
|
|
32757
|
-
}
|
|
32758
|
-
function pinnedHookCommand(bin, args = "") {
|
|
32759
|
-
const suffix = args ? ` ${args}` : "";
|
|
32760
|
-
const fallback = `${pinnedNpxCommand(bin)}${suffix}`;
|
|
32761
|
-
const file = binFile(bin);
|
|
32762
|
-
if (!file) return fallback;
|
|
32763
|
-
return `if [ -x ${shellQuote(process.execPath)} ] && [ -f ${shellQuote(file)} ]; then ${shellQuote(process.execPath)} ${shellQuote(file)}${suffix}; else ${fallback}; fi`;
|
|
32764
|
-
}
|
|
32765
|
-
var STABLE_HOOK_ARGUMENTS_RE = /^[-A-Za-z0-9_ ]*$/u;
|
|
32766
|
-
var STABLE_HOOK_BIN_RE = /^[A-Za-z0-9][A-Za-z0-9-]*$/u;
|
|
32767
|
-
var PRIM_CONFIG_SHELL_RESOLVER = [
|
|
32768
|
-
'prim_absolute() { case "$1" in [/]* ) ;; *) return 1 ;; esac; case "$1" in [[:space:]]*|*[[:space:]]|*[/][/]*|*[/].[/]*|*[/]..[/]*|*[/].|*[/]..|?*[/]) return 1 ;; esac; }; ',
|
|
32769
|
-
'prim_config=${PRIM_CONFIG_DIR:-}; if ! prim_absolute "$prim_config"; then prim_config=${XDG_CONFIG_HOME:-}; if prim_absolute "$prim_config"; then ',
|
|
32770
|
-
'case "$prim_config" in /) prim_config=/prim ;; *) prim_config="$prim_config/prim" ;; esac; ',
|
|
32771
|
-
'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; ',
|
|
32772
|
-
"fi; fi; "
|
|
32773
|
-
].join("");
|
|
32774
|
-
function stableHookCommand(bin, args = "") {
|
|
32775
|
-
if (!STABLE_HOOK_BIN_RE.test(bin) || !STABLE_HOOK_ARGUMENTS_RE.test(args)) {
|
|
32776
|
-
throw new Error("invalid stable hook command");
|
|
32777
|
-
}
|
|
32778
|
-
const resolver = [
|
|
32779
|
-
// #242 and earlier identify managed commands by this package marker. Keep
|
|
32780
|
-
// it as inert data during the rolling window so an older uninstall or
|
|
32781
|
-
// reinstall can remove the stable entry without invoking npm or PATH.
|
|
32782
|
-
`prim_legacy_reader='-p ${PKG_NAME}@stable prim-shim.sh ${bin} '; `,
|
|
32783
|
-
PRIM_CONFIG_SHELL_RESOLVER,
|
|
32784
|
-
`case "$prim_config" in /) prim_launcher=/${STABLE_HOOK_LAUNCHER_NAME} ;; *) prim_launcher="$prim_config/${STABLE_HOOK_LAUNCHER_NAME}" ;; esac; `,
|
|
32785
|
-
'exec "$prim_launcher" "$@"'
|
|
32786
|
-
].join("");
|
|
32787
|
-
const suffix = args ? ` ${args}` : "";
|
|
32788
|
-
return `/bin/sh -c ${shellQuote(resolver)} ${STABLE_HOOK_LAUNCHER_NAME} ${bin}${suffix}`;
|
|
32789
|
-
}
|
|
32790
|
-
function detachedHookShimCommand(bin, args = "") {
|
|
32791
|
-
return `payload=$(cat); { trap '' HUP; printf '%s' "$payload" | { ${stableHookCommand(bin, args)}; }; } </dev/null >/dev/null 2>&1 &`;
|
|
32792
|
-
}
|
|
32793
|
-
function commandMatchesBin(command, bin) {
|
|
32794
|
-
if (!command) {
|
|
32795
|
-
return false;
|
|
32796
|
-
}
|
|
32797
|
-
const c = command.trim();
|
|
32798
|
-
if (c === bin || c.startsWith(`${bin} `)) {
|
|
32799
|
-
return true;
|
|
32800
|
-
}
|
|
32801
|
-
const exactBin = new RegExp(`(?:^|\\s)${bin.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(?:\\s|;|$)`);
|
|
32802
|
-
return c.includes(`command -v ${bin} `) || c.includes(`-p ${PKG_NAME}@`) && exactBin.test(c) || c.includes(STABLE_HOOK_LAUNCHER_NAME) && exactBin.test(c);
|
|
32803
|
-
}
|
|
32804
|
-
function exactPinnedNpxVersion(command, bin) {
|
|
32805
|
-
const escapedBin = bin.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
32806
|
-
const shellQuoted = `'(?:[^']|'"'"')*'`;
|
|
32807
|
-
const safeArgs = "(?: [A-Za-z0-9_@%+=:,./-]+)*";
|
|
32808
|
-
const direct = new RegExp(
|
|
32809
|
-
`^npx --yes --ignore-scripts -p @primitive\\.ai/prim@(?<version>[0-9A-Za-z.+-]+) ${escapedBin}${safeArgs}$`,
|
|
32810
|
-
"u"
|
|
32811
|
-
).exec(command);
|
|
32812
|
-
const wrapped = new RegExp(
|
|
32813
|
-
`^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$`,
|
|
32814
|
-
"u"
|
|
32815
|
-
).exec(command);
|
|
32816
|
-
const version = direct?.groups?.version ?? wrapped?.groups?.version;
|
|
32817
|
-
return version && compareSemver(version, version) !== void 0 ? version : void 0;
|
|
32818
|
-
}
|
|
32819
|
-
function hookCommandResolution(command, bin) {
|
|
32820
|
-
const trimmed = command?.trim();
|
|
32821
|
-
if (!trimmed || !commandMatchesBin(trimmed, bin)) return void 0;
|
|
32822
|
-
if (trimmed.includes(STABLE_HOOK_LAUNCHER_NAME)) return { kind: "stable_launcher" };
|
|
32823
|
-
const version = exactPinnedNpxVersion(trimmed, bin);
|
|
32824
|
-
return version ? { kind: "exact_npx_fallback", version } : { kind: "legacy_path" };
|
|
32825
|
-
}
|
|
32826
|
-
function hookCommandResolutions(commands, bins) {
|
|
32827
|
-
const resolutions = [];
|
|
32828
|
-
for (const command of commands) {
|
|
32829
|
-
for (const bin of bins) {
|
|
32830
|
-
const resolution = hookCommandResolution(command, bin);
|
|
32831
|
-
if (resolution) resolutions.push(resolution);
|
|
32832
|
-
}
|
|
32833
|
-
}
|
|
32834
|
-
return resolutions;
|
|
32835
|
-
}
|
|
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";
|
|
32836
32936
|
|
|
32837
32937
|
// src/lib/git-hook-contract.ts
|
|
32838
32938
|
var MANAGED_GIT_HOOK_NAMES = ["pre-commit", "post-commit", "post-rewrite"];
|
|
@@ -32976,9 +33076,9 @@ exit 0
|
|
|
32976
33076
|
import { isAbsolute as isAbsolute4 } from "path";
|
|
32977
33077
|
|
|
32978
33078
|
// src/lib/bin-cache.ts
|
|
32979
|
-
import { chmodSync as
|
|
33079
|
+
import { chmodSync as chmodSync3, mkdirSync as mkdirSync5 } from "fs";
|
|
32980
33080
|
import { homedir as homedir3 } from "os";
|
|
32981
|
-
import { join as
|
|
33081
|
+
import { join as join10 } from "path";
|
|
32982
33082
|
var GIT_HOOK_CACHE_SHELL_DIR = "${XDG_CACHE_HOME:-$HOME/.cache}/prim/bin";
|
|
32983
33083
|
var GIT_HOOK_CACHE_TTL_MINUTES = 1440;
|
|
32984
33084
|
|
|
@@ -33214,17 +33314,17 @@ ${end}`;
|
|
|
33214
33314
|
}
|
|
33215
33315
|
|
|
33216
33316
|
// src/lib/hook-runtime.ts
|
|
33217
|
-
import { createHash as createHash5, randomBytes as
|
|
33317
|
+
import { createHash as createHash5, randomBytes as randomBytes3 } from "crypto";
|
|
33218
33318
|
import {
|
|
33219
33319
|
constants as constants2,
|
|
33220
33320
|
accessSync,
|
|
33221
|
-
chmodSync as
|
|
33321
|
+
chmodSync as chmodSync4,
|
|
33222
33322
|
copyFileSync,
|
|
33223
33323
|
existsSync as existsSync5,
|
|
33224
|
-
lstatSync as
|
|
33324
|
+
lstatSync as lstatSync3,
|
|
33225
33325
|
mkdirSync as mkdirSync6,
|
|
33226
33326
|
mkdtempSync,
|
|
33227
|
-
readFileSync as
|
|
33327
|
+
readFileSync as readFileSync8,
|
|
33228
33328
|
readdirSync as readdirSync2,
|
|
33229
33329
|
realpathSync as realpathSync2,
|
|
33230
33330
|
renameSync as renameSync2,
|
|
@@ -33233,7 +33333,7 @@ import {
|
|
|
33233
33333
|
utimesSync,
|
|
33234
33334
|
writeFileSync as writeFileSync4
|
|
33235
33335
|
} from "fs";
|
|
33236
|
-
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";
|
|
33237
33337
|
var HOOK_RUNTIME_SCHEMA_VERSION = 1;
|
|
33238
33338
|
var DIRECTORY_MODE2 = 448;
|
|
33239
33339
|
var DATA_FILE_MODE = 384;
|
|
@@ -33273,19 +33373,19 @@ function hookRuntimePaths(options = {}) {
|
|
|
33273
33373
|
env: env4,
|
|
33274
33374
|
homeDir: options.homeDir ?? env4.HOME ?? ""
|
|
33275
33375
|
});
|
|
33276
|
-
const runtimeDir =
|
|
33376
|
+
const runtimeDir = join11(configDir, "hook-runtime");
|
|
33277
33377
|
return {
|
|
33278
33378
|
configDir,
|
|
33279
|
-
launcher:
|
|
33280
|
-
gitHookEntrypoint:
|
|
33379
|
+
launcher: join11(configDir, STABLE_HOOK_LAUNCHER_NAME),
|
|
33380
|
+
gitHookEntrypoint: join11(configDir, GIT_HOOK_ENTRYPOINT_NAME),
|
|
33281
33381
|
runtimeDir,
|
|
33282
|
-
releasesDir:
|
|
33283
|
-
current:
|
|
33284
|
-
selectionLock:
|
|
33382
|
+
releasesDir: join11(runtimeDir, "releases"),
|
|
33383
|
+
current: join11(runtimeDir, "current"),
|
|
33384
|
+
selectionLock: join11(runtimeDir, "selection.lock")
|
|
33285
33385
|
};
|
|
33286
33386
|
}
|
|
33287
33387
|
function sha2562(path9) {
|
|
33288
|
-
return createHash5("sha256").update(
|
|
33388
|
+
return createHash5("sha256").update(readFileSync8(path9)).digest("hex");
|
|
33289
33389
|
}
|
|
33290
33390
|
function exactManifest(manifest) {
|
|
33291
33391
|
return `${JSON.stringify(manifest, null, 2)}
|
|
@@ -33315,18 +33415,18 @@ function runtimePackageJson(manifest) {
|
|
|
33315
33415
|
function validateRelease(releaseDir, manifest) {
|
|
33316
33416
|
try {
|
|
33317
33417
|
if (!directReleaseLayout(releaseDir)) return false;
|
|
33318
|
-
if (
|
|
33418
|
+
if (readFileSync8(join11(releaseDir, "manifest.json"), "utf8") !== exactManifest(manifest)) {
|
|
33319
33419
|
return false;
|
|
33320
33420
|
}
|
|
33321
|
-
if (
|
|
33421
|
+
if (readFileSync8(join11(releaseDir, "package.json"), "utf8") !== runtimePackageJson(manifest)) {
|
|
33322
33422
|
return false;
|
|
33323
33423
|
}
|
|
33324
|
-
if (
|
|
33424
|
+
if (readFileSync8(join11(releaseDir, "node"), "utf8") !== `${manifest.nodePath}
|
|
33325
33425
|
`) {
|
|
33326
33426
|
return false;
|
|
33327
33427
|
}
|
|
33328
33428
|
for (const [bin, relativePath] of Object.entries(HOOK_RUNTIME_ENTRIES)) {
|
|
33329
|
-
const target =
|
|
33429
|
+
const target = join11(releaseDir, relativePath);
|
|
33330
33430
|
if (sha2562(target) !== manifest.files[bin]) return false;
|
|
33331
33431
|
}
|
|
33332
33432
|
return true;
|
|
@@ -33339,22 +33439,22 @@ function directReleaseLayout(releaseDir) {
|
|
|
33339
33439
|
const directories = /* @__PURE__ */ new Set([releaseDir]);
|
|
33340
33440
|
for (const relativePath of Object.values(HOOK_RUNTIME_ENTRIES)) {
|
|
33341
33441
|
for (let directory = dirname7(relativePath); directory !== "."; directory = dirname7(directory)) {
|
|
33342
|
-
directories.add(
|
|
33442
|
+
directories.add(join11(releaseDir, directory));
|
|
33343
33443
|
}
|
|
33344
33444
|
}
|
|
33345
|
-
if (![...directories].every((directory) =>
|
|
33445
|
+
if (![...directories].every((directory) => lstatSync3(directory).isDirectory())) return false;
|
|
33346
33446
|
const files = ["manifest.json", "package.json", "node", ...Object.values(HOOK_RUNTIME_ENTRIES)];
|
|
33347
|
-
return files.every((relativePath) =>
|
|
33447
|
+
return files.every((relativePath) => lstatSync3(join11(releaseDir, relativePath)).isFile());
|
|
33348
33448
|
} catch {
|
|
33349
33449
|
return false;
|
|
33350
33450
|
}
|
|
33351
33451
|
}
|
|
33352
33452
|
function readReleaseManifest(releaseDir, releaseName) {
|
|
33353
33453
|
try {
|
|
33354
|
-
const manifestPath =
|
|
33454
|
+
const manifestPath = join11(releaseDir, "manifest.json");
|
|
33355
33455
|
const manifestStat = statSync2(manifestPath);
|
|
33356
33456
|
if (!manifestStat.isFile() || manifestStat.size > MAX_MANIFEST_BYTES) return null;
|
|
33357
|
-
const raw =
|
|
33457
|
+
const raw = readFileSync8(manifestPath, "utf8");
|
|
33358
33458
|
const parsed = JSON.parse(raw);
|
|
33359
33459
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
|
|
33360
33460
|
if (!exactKeys(parsed, ["schemaVersion", "version", "nodePath", "files"])) return null;
|
|
@@ -33376,7 +33476,7 @@ function readReleaseManifest(releaseDir, releaseName) {
|
|
|
33376
33476
|
function readSelectedRelease(paths) {
|
|
33377
33477
|
let raw;
|
|
33378
33478
|
try {
|
|
33379
|
-
raw =
|
|
33479
|
+
raw = readFileSync8(paths.current, "utf8");
|
|
33380
33480
|
} catch (error) {
|
|
33381
33481
|
if (error.code === "ENOENT") return null;
|
|
33382
33482
|
throw error;
|
|
@@ -33386,7 +33486,7 @@ function readSelectedRelease(paths) {
|
|
|
33386
33486
|
` !== raw || !RELEASE_NAME_RE.test(name)) {
|
|
33387
33487
|
throw new Error("cannot stage hook runtime: selected release is malformed");
|
|
33388
33488
|
}
|
|
33389
|
-
const dir =
|
|
33489
|
+
const dir = join11(paths.releasesDir, name);
|
|
33390
33490
|
const manifest = readReleaseManifest(dir, name);
|
|
33391
33491
|
if (!manifest) {
|
|
33392
33492
|
throw new Error("cannot stage hook runtime: immutable release is corrupt");
|
|
@@ -33396,7 +33496,7 @@ function readSelectedRelease(paths) {
|
|
|
33396
33496
|
function releaseEntries(paths) {
|
|
33397
33497
|
return readdirSync2(paths.releasesDir, { withFileTypes: true }).flatMap((entry) => {
|
|
33398
33498
|
if (!entry.isDirectory() || !RELEASE_NAME_RE.test(entry.name)) return [];
|
|
33399
|
-
const dir =
|
|
33499
|
+
const dir = join11(paths.releasesDir, entry.name);
|
|
33400
33500
|
try {
|
|
33401
33501
|
return [{ name: entry.name, dir, mtimeMs: statSync2(dir).mtimeMs }];
|
|
33402
33502
|
} catch {
|
|
@@ -33435,7 +33535,7 @@ function pruneReleases(paths, protectedNames, reserveSlots, now) {
|
|
|
33435
33535
|
function sourceManifest(sourceDir, version, nodePath) {
|
|
33436
33536
|
const files = {};
|
|
33437
33537
|
for (const [bin, relativePath] of Object.entries(SOURCE_ENTRIES)) {
|
|
33438
|
-
const source =
|
|
33538
|
+
const source = join11(sourceDir, relativePath);
|
|
33439
33539
|
if (!existsSync5(source) || !statSync2(source).isFile()) {
|
|
33440
33540
|
throw new Error(`cannot stage hook runtime: missing self-contained ${bin} bundle`);
|
|
33441
33541
|
}
|
|
@@ -33480,14 +33580,14 @@ function hasSafeRuntimeLayout(paths, selected) {
|
|
|
33480
33580
|
const releaseDirectories = /* @__PURE__ */ new Set([selected.dir]);
|
|
33481
33581
|
for (const relativePath of Object.values(HOOK_RUNTIME_ENTRIES)) {
|
|
33482
33582
|
for (let directory = dirname7(relativePath); directory !== "."; directory = dirname7(directory)) {
|
|
33483
|
-
releaseDirectories.add(
|
|
33583
|
+
releaseDirectories.add(join11(selected.dir, directory));
|
|
33484
33584
|
}
|
|
33485
33585
|
}
|
|
33486
|
-
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)) {
|
|
33487
33587
|
return false;
|
|
33488
33588
|
}
|
|
33489
33589
|
return Object.values(HOOK_RUNTIME_ENTRIES).every(
|
|
33490
|
-
(relativePath) => privateFile(
|
|
33590
|
+
(relativePath) => privateFile(join11(selected.dir, relativePath), DATA_FILE_MODE)
|
|
33491
33591
|
);
|
|
33492
33592
|
}
|
|
33493
33593
|
function recordedNodeMatchesCurrentProcess(nodePath) {
|
|
@@ -33511,7 +33611,7 @@ function inspectHookRuntime(options = {}) {
|
|
|
33511
33611
|
if (!(launcher || selector)) return { state: "missing" };
|
|
33512
33612
|
if (!(launcher && selector)) return { state: "invalid" };
|
|
33513
33613
|
try {
|
|
33514
|
-
if (
|
|
33614
|
+
if (readFileSync8(paths.launcher, "utf8") !== STABLE_HOOK_LAUNCHER_CONTENT) {
|
|
33515
33615
|
return { state: "invalid" };
|
|
33516
33616
|
}
|
|
33517
33617
|
const selected = readSelectedRelease(paths);
|
|
@@ -33524,8 +33624,8 @@ function inspectHookRuntime(options = {}) {
|
|
|
33524
33624
|
}
|
|
33525
33625
|
}
|
|
33526
33626
|
function writeRelease(sourceDir, releaseDir, manifest, releasesDir) {
|
|
33527
|
-
const stagingDir = mkdtempSync(
|
|
33528
|
-
|
|
33627
|
+
const stagingDir = mkdtempSync(join11(releasesDir, ".stage-"));
|
|
33628
|
+
chmodSync4(stagingDir, DIRECTORY_MODE2);
|
|
33529
33629
|
try {
|
|
33530
33630
|
const directories = /* @__PURE__ */ new Set([stagingDir]);
|
|
33531
33631
|
const syncStagedFile = (path9) => {
|
|
@@ -33536,18 +33636,18 @@ function writeRelease(sourceDir, releaseDir, manifest, releasesDir) {
|
|
|
33536
33636
|
}
|
|
33537
33637
|
};
|
|
33538
33638
|
for (const [bin, targetRelative] of Object.entries(HOOK_RUNTIME_ENTRIES)) {
|
|
33539
|
-
const source =
|
|
33540
|
-
const target =
|
|
33639
|
+
const source = join11(sourceDir, SOURCE_ENTRIES[bin]);
|
|
33640
|
+
const target = join11(stagingDir, targetRelative);
|
|
33541
33641
|
mkdirSync6(dirname7(target), { recursive: true, mode: DIRECTORY_MODE2 });
|
|
33542
|
-
|
|
33642
|
+
chmodSync4(dirname7(target), DIRECTORY_MODE2);
|
|
33543
33643
|
copyFileSync(source, target);
|
|
33544
|
-
|
|
33644
|
+
chmodSync4(target, DATA_FILE_MODE);
|
|
33545
33645
|
if (sha2562(target) !== manifest.files[bin]) {
|
|
33546
33646
|
throw new Error(`cannot stage hook runtime: ${bin} changed while it was copied`);
|
|
33547
33647
|
}
|
|
33548
33648
|
syncStagedFile(target);
|
|
33549
33649
|
}
|
|
33550
|
-
const nodePath =
|
|
33650
|
+
const nodePath = join11(stagingDir, "node");
|
|
33551
33651
|
writeFileSync4(nodePath, `${manifest.nodePath}
|
|
33552
33652
|
`, {
|
|
33553
33653
|
encoding: "utf8",
|
|
@@ -33555,14 +33655,14 @@ function writeRelease(sourceDir, releaseDir, manifest, releasesDir) {
|
|
|
33555
33655
|
mode: DATA_FILE_MODE
|
|
33556
33656
|
});
|
|
33557
33657
|
syncStagedFile(nodePath);
|
|
33558
|
-
const packageJsonPath =
|
|
33658
|
+
const packageJsonPath = join11(stagingDir, "package.json");
|
|
33559
33659
|
writeFileSync4(packageJsonPath, runtimePackageJson(manifest), {
|
|
33560
33660
|
encoding: "utf8",
|
|
33561
33661
|
flag: "wx",
|
|
33562
33662
|
mode: DATA_FILE_MODE
|
|
33563
33663
|
});
|
|
33564
33664
|
syncStagedFile(packageJsonPath);
|
|
33565
|
-
const manifestPath =
|
|
33665
|
+
const manifestPath = join11(stagingDir, "manifest.json");
|
|
33566
33666
|
writeFileSync4(manifestPath, exactManifest(manifest), {
|
|
33567
33667
|
encoding: "utf8",
|
|
33568
33668
|
flag: "wx",
|
|
@@ -33593,7 +33693,7 @@ function stableNodePath(execPath = process.execPath, searchPath = process.env.PA
|
|
|
33593
33693
|
}
|
|
33594
33694
|
for (const directory of searchPath.split(delimiter)) {
|
|
33595
33695
|
if (!isAbsolute5(directory)) continue;
|
|
33596
|
-
const candidate =
|
|
33696
|
+
const candidate = join11(directory, "node");
|
|
33597
33697
|
try {
|
|
33598
33698
|
if (realpathSync2(candidate) === target) return candidate;
|
|
33599
33699
|
} catch {
|
|
@@ -33603,7 +33703,7 @@ function stableNodePath(execPath = process.execPath, searchPath = process.env.PA
|
|
|
33603
33703
|
}
|
|
33604
33704
|
function stageHookRuntime(options = {}) {
|
|
33605
33705
|
const root = packageRoot();
|
|
33606
|
-
const sourceDir = options.sourceDir ?? (root ?
|
|
33706
|
+
const sourceDir = options.sourceDir ?? (root ? join11(root, "dist", "hook-runtime") : null);
|
|
33607
33707
|
const version = options.version ?? packageVersion();
|
|
33608
33708
|
const nodePath = resolve4(options.nodePath ?? stableNodePath());
|
|
33609
33709
|
if (!sourceDir || !version || compareSemver(version, version) !== 0 || !isAbsolute5(nodePath) || /[\r\n]/u.test(nodePath)) {
|
|
@@ -33612,11 +33712,11 @@ function stageHookRuntime(options = {}) {
|
|
|
33612
33712
|
const manifest = sourceManifest(sourceDir, version, nodePath);
|
|
33613
33713
|
const paths = hookRuntimePaths(options);
|
|
33614
33714
|
const releaseName = `${RELEASE_PREFIX}${releaseId(manifest)}`;
|
|
33615
|
-
const releaseDir =
|
|
33715
|
+
const releaseDir = join11(paths.releasesDir, releaseName);
|
|
33616
33716
|
mkdirSync6(paths.releasesDir, { recursive: true, mode: DIRECTORY_MODE2 });
|
|
33617
|
-
|
|
33618
|
-
|
|
33619
|
-
|
|
33717
|
+
chmodSync4(paths.configDir, DIRECTORY_MODE2);
|
|
33718
|
+
chmodSync4(paths.runtimeDir, DIRECTORY_MODE2);
|
|
33719
|
+
chmodSync4(paths.releasesDir, DIRECTORY_MODE2);
|
|
33620
33720
|
return withFileLockSync(paths.selectionLock, () => {
|
|
33621
33721
|
const now = Date.now();
|
|
33622
33722
|
const selected = readSelectedRelease(paths);
|
|
@@ -33639,7 +33739,7 @@ function stageHookRuntime(options = {}) {
|
|
|
33639
33739
|
const finalRelease = selectRequested ? { name: releaseName, dir: releaseDir, manifest } : selected;
|
|
33640
33740
|
const launcherCurrent = (() => {
|
|
33641
33741
|
try {
|
|
33642
|
-
return
|
|
33742
|
+
return readFileSync8(paths.launcher, "utf8") === STABLE_HOOK_LAUNCHER_CONTENT;
|
|
33643
33743
|
} catch {
|
|
33644
33744
|
return false;
|
|
33645
33745
|
}
|
|
@@ -33683,7 +33783,7 @@ function stageHookRuntime(options = {}) {
|
|
|
33683
33783
|
}
|
|
33684
33784
|
function gitHookEntrypointCurrent(paths) {
|
|
33685
33785
|
try {
|
|
33686
|
-
return
|
|
33786
|
+
return readFileSync8(paths.gitHookEntrypoint, "utf8") === GIT_HOOK_ENTRYPOINT_CONTENT;
|
|
33687
33787
|
} catch {
|
|
33688
33788
|
return false;
|
|
33689
33789
|
}
|
|
@@ -33698,7 +33798,7 @@ function inspectGitHookEntrypoint(options = {}) {
|
|
|
33698
33798
|
try {
|
|
33699
33799
|
const entrypoint = lstatIfPresent(paths.gitHookEntrypoint);
|
|
33700
33800
|
if (!entrypoint) return "missing";
|
|
33701
|
-
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()) {
|
|
33702
33802
|
return "invalid";
|
|
33703
33803
|
}
|
|
33704
33804
|
return "ready";
|
|
@@ -33708,7 +33808,7 @@ function inspectGitHookEntrypoint(options = {}) {
|
|
|
33708
33808
|
}
|
|
33709
33809
|
function lstatIfPresent(path9) {
|
|
33710
33810
|
try {
|
|
33711
|
-
return
|
|
33811
|
+
return lstatSync3(path9);
|
|
33712
33812
|
} catch (error) {
|
|
33713
33813
|
const code = error.code;
|
|
33714
33814
|
if (code === "ENOENT" || code === "ENOTDIR") return void 0;
|
|
@@ -33724,7 +33824,7 @@ function assertOwnedHookRuntime(paths) {
|
|
|
33724
33824
|
}
|
|
33725
33825
|
const launcher = lstatIfPresent(paths.launcher);
|
|
33726
33826
|
if (launcher) {
|
|
33727
|
-
if (!launcher.isFile() ||
|
|
33827
|
+
if (!launcher.isFile() || readFileSync8(paths.launcher, "utf8") !== STABLE_HOOK_LAUNCHER_CONTENT) {
|
|
33728
33828
|
throw new Error(`refusing to remove unrecognized hook launcher at ${paths.launcher}`);
|
|
33729
33829
|
}
|
|
33730
33830
|
}
|
|
@@ -33752,7 +33852,7 @@ function assertOwnedHookRuntime(paths) {
|
|
|
33752
33852
|
throw new Error(`refusing to remove non-directory hook releases at ${paths.releasesDir}`);
|
|
33753
33853
|
}
|
|
33754
33854
|
for (const entry of readdirSync2(paths.releasesDir, { withFileTypes: true })) {
|
|
33755
|
-
const releaseDir =
|
|
33855
|
+
const releaseDir = join11(paths.releasesDir, entry.name);
|
|
33756
33856
|
if (!entry.isDirectory() || !RELEASE_NAME_RE.test(entry.name) || !readReleaseManifest(releaseDir, entry.name)) {
|
|
33757
33857
|
throw new Error(`refusing to remove unrecognized hook release ${releaseDir}`);
|
|
33758
33858
|
}
|
|
@@ -33774,7 +33874,7 @@ function removeHookRuntime(options = {}) {
|
|
|
33774
33874
|
assertOwnedHookRuntime(paths);
|
|
33775
33875
|
if (lstatIfPresent(paths.gitHookEntrypoint)) rmSync4(paths.gitHookEntrypoint, { force: true });
|
|
33776
33876
|
if (lstatIfPresent(paths.launcher)) rmSync4(paths.launcher, { force: true });
|
|
33777
|
-
const quarantined = `${paths.runtimeDir}.uninstall-${String(process.pid)}-${
|
|
33877
|
+
const quarantined = `${paths.runtimeDir}.uninstall-${String(process.pid)}-${randomBytes3(8).toString("hex")}`;
|
|
33778
33878
|
renameSync2(paths.runtimeDir, quarantined);
|
|
33779
33879
|
rmSync4(quarantined, { recursive: true, force: true });
|
|
33780
33880
|
});
|
|
@@ -33916,7 +34016,7 @@ function realpathLoose(path9) {
|
|
|
33916
34016
|
let current = resolve5(path9);
|
|
33917
34017
|
for (; ; ) {
|
|
33918
34018
|
try {
|
|
33919
|
-
return
|
|
34019
|
+
return join12(realpathSync3.native(current), ...missing);
|
|
33920
34020
|
} catch {
|
|
33921
34021
|
const parent = dirname8(current);
|
|
33922
34022
|
if (parent === current) return resolve5(path9);
|
|
@@ -33931,7 +34031,7 @@ function isWithin(path9, directory) {
|
|
|
33931
34031
|
}
|
|
33932
34032
|
function primGitHooksDirectory() {
|
|
33933
34033
|
try {
|
|
33934
|
-
return
|
|
34034
|
+
return join12(primConfigDirectory(), "git-hooks");
|
|
33935
34035
|
} catch {
|
|
33936
34036
|
return void 0;
|
|
33937
34037
|
}
|
|
@@ -34037,7 +34137,7 @@ function resolveEffectiveGitHook(hookName, cwd = process.cwd()) {
|
|
|
34037
34137
|
}
|
|
34038
34138
|
function assertSafeFile(path9, spec) {
|
|
34039
34139
|
if (!existsSync6(path9)) return void 0;
|
|
34040
|
-
const stat =
|
|
34140
|
+
const stat = lstatSync4(path9);
|
|
34041
34141
|
if (!stat.isFile() || stat.isSymbolicLink() || stat.size > MAX_HOOK_BYTES) {
|
|
34042
34142
|
throw new Error(`unsafe ${spec.hookName} hook target: ${path9}`);
|
|
34043
34143
|
}
|
|
@@ -34067,7 +34167,7 @@ function assertUsableHuskyDispatcher(target, spec) {
|
|
|
34067
34167
|
}
|
|
34068
34168
|
}
|
|
34069
34169
|
function readHookFile(path9) {
|
|
34070
|
-
const value =
|
|
34170
|
+
const value = readFileSync9(path9);
|
|
34071
34171
|
return Buffer.isBuffer(value) ? value : Buffer.from(value);
|
|
34072
34172
|
}
|
|
34073
34173
|
function decodeHookText(content, spec) {
|
|
@@ -34140,11 +34240,11 @@ function blockInsertionPoint(content, allowShebangless, spec, huskyV8) {
|
|
|
34140
34240
|
var HUSKY_SPEC_MAJOR_RE = /^\s*[~^]?=?\s*v?([0-9]+)(?:\.(?:[0-9]+|[xX*])){0,2}(?:-[0-9A-Za-z.-]+)?\s*$/u;
|
|
34141
34241
|
function declaredHuskyMajor(dir) {
|
|
34142
34242
|
for (let current = resolve5(dir); ; ) {
|
|
34143
|
-
const manifest =
|
|
34243
|
+
const manifest = join12(current, "package.json");
|
|
34144
34244
|
if (existsSync6(manifest)) {
|
|
34145
34245
|
try {
|
|
34146
|
-
if (
|
|
34147
|
-
const parsed = JSON.parse(
|
|
34246
|
+
if (lstatSync4(manifest).size > MAX_HOOK_BYTES) return void 0;
|
|
34247
|
+
const parsed = JSON.parse(readFileSync9(manifest, "utf8"));
|
|
34148
34248
|
const range = parsed.devDependencies?.husky ?? parsed.dependencies?.husky;
|
|
34149
34249
|
const major = typeof range === "string" ? HUSKY_SPEC_MAJOR_RE.exec(range)?.[1] : void 0;
|
|
34150
34250
|
return major === void 0 ? void 0 : Number(major);
|
|
@@ -34153,15 +34253,15 @@ function declaredHuskyMajor(dir) {
|
|
|
34153
34253
|
}
|
|
34154
34254
|
}
|
|
34155
34255
|
const parent = dirname8(current);
|
|
34156
|
-
if (parent === current || existsSync6(
|
|
34256
|
+
if (parent === current || existsSync6(join12(current, ".git"))) return void 0;
|
|
34157
34257
|
current = parent;
|
|
34158
34258
|
}
|
|
34159
34259
|
}
|
|
34160
34260
|
function isHuskyV8Hook(hookPath) {
|
|
34161
|
-
const runtime =
|
|
34261
|
+
const runtime = join12(dirname8(hookPath), "_", "husky.sh");
|
|
34162
34262
|
try {
|
|
34163
|
-
const stat =
|
|
34164
|
-
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");
|
|
34165
34265
|
} catch (error) {
|
|
34166
34266
|
if (errorCode(error) !== "ENOENT") return false;
|
|
34167
34267
|
}
|
|
@@ -34306,7 +34406,7 @@ function errorCode(error) {
|
|
|
34306
34406
|
function assertTargetUnchanged(path9, expected, spec, stat) {
|
|
34307
34407
|
let current;
|
|
34308
34408
|
try {
|
|
34309
|
-
current =
|
|
34409
|
+
current = lstatSync4(path9);
|
|
34310
34410
|
} catch (error) {
|
|
34311
34411
|
if (expected === void 0 && errorCode(error) === "ENOENT") return;
|
|
34312
34412
|
throw new Error(`${spec.hookName} hook changed concurrently: ${path9}`);
|
|
@@ -34827,13 +34927,13 @@ async function pollGitHubInstallIntent(client, start, options = {}) {
|
|
|
34827
34927
|
|
|
34828
34928
|
// src/commands/auth.ts
|
|
34829
34929
|
import { execFile } from "child_process";
|
|
34830
|
-
import { createHash as createHash7, randomBytes as
|
|
34831
|
-
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";
|
|
34832
34932
|
import { createServer } from "http";
|
|
34833
34933
|
import { platform } from "os";
|
|
34834
34934
|
|
|
34835
34935
|
// src/auth/api-keys.ts
|
|
34836
|
-
import { randomBytes as
|
|
34936
|
+
import { randomBytes as randomBytes4 } from "crypto";
|
|
34837
34937
|
var USER_API_KEY_TIMEOUT_MS = 1e4;
|
|
34838
34938
|
var USER_API_KEY_EXIT = {
|
|
34839
34939
|
ok: 0,
|
|
@@ -34844,7 +34944,7 @@ var USER_API_KEY_EXIT = {
|
|
|
34844
34944
|
};
|
|
34845
34945
|
var defaultDependencies2 = {
|
|
34846
34946
|
getClient: () => getPinnedManagementClient({ signal: AbortSignal.timeout(USER_API_KEY_TIMEOUT_MS) }),
|
|
34847
|
-
requestId: () =>
|
|
34947
|
+
requestId: () => randomBytes4(32).toString("hex"),
|
|
34848
34948
|
signal: () => AbortSignal.timeout(USER_API_KEY_TIMEOUT_MS),
|
|
34849
34949
|
writeStdout: (value) => console.log(value),
|
|
34850
34950
|
writeStderr: (value) => console.error(value)
|
|
@@ -35277,7 +35377,7 @@ function base64url(buffer) {
|
|
|
35277
35377
|
return buffer.toString("base64").replace(BASE64_PLUS_RE, "-").replace(BASE64_SLASH_RE, "_").replace(BASE64_PAD_RE, "");
|
|
35278
35378
|
}
|
|
35279
35379
|
function generatePkce() {
|
|
35280
|
-
const verifier = base64url(
|
|
35380
|
+
const verifier = base64url(randomBytes5(32));
|
|
35281
35381
|
const challenge = base64url(createHash7("sha256").update(verifier).digest());
|
|
35282
35382
|
return { verifier, challenge };
|
|
35283
35383
|
}
|
|
@@ -35391,7 +35491,7 @@ function reportSuccess() {
|
|
|
35391
35491
|
function hasStoredRefreshToken() {
|
|
35392
35492
|
if (!existsSync7(REFRESH_TOKEN_PATH)) return false;
|
|
35393
35493
|
try {
|
|
35394
|
-
return
|
|
35494
|
+
return readFileSync10(REFRESH_TOKEN_PATH, "utf-8").trim().length > 0;
|
|
35395
35495
|
} catch {
|
|
35396
35496
|
return false;
|
|
35397
35497
|
}
|
|
@@ -35577,7 +35677,7 @@ ${verificationUrl}`);
|
|
|
35577
35677
|
return;
|
|
35578
35678
|
}
|
|
35579
35679
|
const { verifier, challenge } = generatePkce();
|
|
35580
|
-
const state = base64url(
|
|
35680
|
+
const state = base64url(randomBytes5(16));
|
|
35581
35681
|
const redirectUri = `http://${LOCALHOST}:${CALLBACK_PORT}/callback`;
|
|
35582
35682
|
let settle;
|
|
35583
35683
|
const outcome = new Promise((resolve12) => {
|
|
@@ -35884,15 +35984,15 @@ function registerGithubCommands(program3, dependencies = defaultDependencies3) {
|
|
|
35884
35984
|
import { execFileSync as execFileSync5 } from "child_process";
|
|
35885
35985
|
import {
|
|
35886
35986
|
existsSync as existsSync8,
|
|
35887
|
-
lstatSync as
|
|
35987
|
+
lstatSync as lstatSync5,
|
|
35888
35988
|
mkdirSync as mkdirSync8,
|
|
35889
|
-
readFileSync as
|
|
35989
|
+
readFileSync as readFileSync11,
|
|
35890
35990
|
readdirSync as readdirSync3,
|
|
35891
35991
|
unlinkSync as unlinkSync3,
|
|
35892
35992
|
writeFileSync as writeFileSync6
|
|
35893
35993
|
} from "fs";
|
|
35894
35994
|
import { homedir as homedir4 } from "os";
|
|
35895
|
-
import { join as
|
|
35995
|
+
import { join as join13, resolve as resolve6 } from "path";
|
|
35896
35996
|
var PRE_COMMIT2 = { hookName: "pre-commit", binName: "prim-pre-commit" };
|
|
35897
35997
|
var POST_COMMIT2 = { hookName: "post-commit", binName: "prim-post-commit" };
|
|
35898
35998
|
var POST_REWRITE2 = { hookName: "post-rewrite", binName: "prim-post-rewrite" };
|
|
@@ -35933,7 +36033,7 @@ function detectHusky(gitRoot) {
|
|
|
35933
36033
|
const pkgPath = resolve6(gitRoot, "package.json");
|
|
35934
36034
|
if (existsSync8(pkgPath)) {
|
|
35935
36035
|
try {
|
|
35936
|
-
const pkg2 = JSON.parse(
|
|
36036
|
+
const pkg2 = JSON.parse(readFileSync11(pkgPath, "utf-8"));
|
|
35937
36037
|
const scripts = pkg2.scripts ?? {};
|
|
35938
36038
|
if (/husky/i.test(scripts.prepare ?? "") || /husky/i.test(scripts.postinstall ?? "")) {
|
|
35939
36039
|
return true;
|
|
@@ -35943,9 +36043,9 @@ function detectHusky(gitRoot) {
|
|
|
35943
36043
|
}
|
|
35944
36044
|
return false;
|
|
35945
36045
|
}
|
|
35946
|
-
var PRIM_GIT_HOOKS_DIR =
|
|
36046
|
+
var PRIM_GIT_HOOKS_DIR = join13(primConfigDirectory(), "git-hooks");
|
|
35947
36047
|
function expandTilde(p) {
|
|
35948
|
-
return p.startsWith("~/") ?
|
|
36048
|
+
return p.startsWith("~/") ? join13(homedir4(), p.slice(2)) : p;
|
|
35949
36049
|
}
|
|
35950
36050
|
function isOurHooksDir(value) {
|
|
35951
36051
|
return value !== "" && expandTilde(value) === PRIM_GIT_HOOKS_DIR;
|
|
@@ -36025,7 +36125,7 @@ function isExpectedOwnedGlobalHook(content, hookName) {
|
|
|
36025
36125
|
}
|
|
36026
36126
|
function lstatIfPresent2(path9) {
|
|
36027
36127
|
try {
|
|
36028
|
-
return
|
|
36128
|
+
return lstatSync5(path9);
|
|
36029
36129
|
} catch (error) {
|
|
36030
36130
|
const code = error.code;
|
|
36031
36131
|
if (code === "ENOENT" || code === "ENOTDIR") return void 0;
|
|
@@ -36048,8 +36148,8 @@ function assertOwnedHooksDirectorySafeToRemove() {
|
|
|
36048
36148
|
);
|
|
36049
36149
|
}
|
|
36050
36150
|
const path9 = resolve6(PRIM_GIT_HOOKS_DIR, name);
|
|
36051
|
-
const stat =
|
|
36052
|
-
if (!stat.isFile() || stat.isSymbolicLink() || !isExpectedOwnedGlobalHook(
|
|
36151
|
+
const stat = lstatSync5(path9);
|
|
36152
|
+
if (!stat.isFile() || stat.isSymbolicLink() || !isExpectedOwnedGlobalHook(readFileSync11(path9, "utf-8"), name)) {
|
|
36053
36153
|
throw new Error(`refusing to remove global hooks: ${path9} is not an exact Prim-owned hook`);
|
|
36054
36154
|
}
|
|
36055
36155
|
}
|
|
@@ -36087,7 +36187,7 @@ function stripPrimBlock(hookPath, spec) {
|
|
|
36087
36187
|
}
|
|
36088
36188
|
function planPreCommitRemoval(hookPath, options) {
|
|
36089
36189
|
if (!existsSync8(hookPath)) return { path: hookPath, action: "missing" };
|
|
36090
|
-
const existing =
|
|
36190
|
+
const existing = readFileSync11(hookPath, "utf-8");
|
|
36091
36191
|
if (options.allowOwnedStandalone && isOwnedStandalonePreCommit(existing)) {
|
|
36092
36192
|
return { path: hookPath, action: "remove-owned-file" };
|
|
36093
36193
|
}
|
|
@@ -36617,9 +36717,9 @@ function registerActivationCommands(program3) {
|
|
|
36617
36717
|
}
|
|
36618
36718
|
|
|
36619
36719
|
// src/commands/claude-install.ts
|
|
36620
|
-
import { existsSync as existsSync9, readFileSync as
|
|
36720
|
+
import { existsSync as existsSync9, readFileSync as readFileSync12 } from "fs";
|
|
36621
36721
|
import { homedir as homedir5 } from "os";
|
|
36622
|
-
import { join as
|
|
36722
|
+
import { join as join14 } from "path";
|
|
36623
36723
|
var CAPTURE_BIN = "prim-hook";
|
|
36624
36724
|
var GATE_BIN = "prim-pre-tool-use";
|
|
36625
36725
|
var POST_TOOL_USE_BIN = "prim-post-tool-use";
|
|
@@ -36637,11 +36737,11 @@ var PRIM_BINS = [
|
|
|
36637
36737
|
SESSION_END_BIN
|
|
36638
36738
|
];
|
|
36639
36739
|
var JSON_INDENT = 2;
|
|
36640
|
-
var USER_SCOPE_PATH =
|
|
36740
|
+
var USER_SCOPE_PATH = join14(homedir5(), ".claude", "settings.json");
|
|
36641
36741
|
function projectRoot() {
|
|
36642
36742
|
return gitToplevel() ?? process.cwd();
|
|
36643
36743
|
}
|
|
36644
|
-
var projectScopePath = () =>
|
|
36744
|
+
var projectScopePath = () => join14(projectRoot(), ".claude", "settings.json");
|
|
36645
36745
|
var CAPTURE_EVENTS = [
|
|
36646
36746
|
"SessionStart",
|
|
36647
36747
|
"UserPromptSubmit",
|
|
@@ -36695,7 +36795,7 @@ function readSettings(path9) {
|
|
|
36695
36795
|
if (!existsSync9(path9)) {
|
|
36696
36796
|
return {};
|
|
36697
36797
|
}
|
|
36698
|
-
const raw =
|
|
36798
|
+
const raw = readFileSync12(path9, "utf-8");
|
|
36699
36799
|
try {
|
|
36700
36800
|
return JSON.parse(raw);
|
|
36701
36801
|
} catch (err) {
|
|
@@ -36899,7 +36999,7 @@ function statuslineState(settings) {
|
|
|
36899
36999
|
function isGateInstalled(settings) {
|
|
36900
37000
|
return (settings.hooks?.PreToolUse ?? []).some((e) => entryHasCommand(e, GATE_BIN));
|
|
36901
37001
|
}
|
|
36902
|
-
function
|
|
37002
|
+
function atomicWrite3(path9, content) {
|
|
36903
37003
|
atomicWriteFile(path9, `${JSON.stringify(content, null, JSON_INDENT)}
|
|
36904
37004
|
`, {
|
|
36905
37005
|
ensureParent: true
|
|
@@ -36923,7 +37023,7 @@ function performInstall(scope, force) {
|
|
|
36923
37023
|
});
|
|
36924
37024
|
const changed = JSON.stringify(before) !== JSON.stringify(after);
|
|
36925
37025
|
if (changed) {
|
|
36926
|
-
|
|
37026
|
+
atomicWrite3(path9, after);
|
|
36927
37027
|
}
|
|
36928
37028
|
return {
|
|
36929
37029
|
scope,
|
|
@@ -36942,7 +37042,7 @@ function performUninstall(scope) {
|
|
|
36942
37042
|
const after = applyUninstall(before);
|
|
36943
37043
|
const changed = JSON.stringify(before) !== JSON.stringify(after);
|
|
36944
37044
|
if (changed) {
|
|
36945
|
-
|
|
37045
|
+
atomicWrite3(path9, after);
|
|
36946
37046
|
}
|
|
36947
37047
|
return {
|
|
36948
37048
|
scope,
|
|
@@ -36961,7 +37061,7 @@ function performPermissionInstall(scope) {
|
|
|
36961
37061
|
const after = applyAutoModeTrust(applyPermissions(before));
|
|
36962
37062
|
const changed = JSON.stringify(before) !== JSON.stringify(after);
|
|
36963
37063
|
if (changed) {
|
|
36964
|
-
|
|
37064
|
+
atomicWrite3(path9, after);
|
|
36965
37065
|
}
|
|
36966
37066
|
return {
|
|
36967
37067
|
scope,
|
|
@@ -37064,7 +37164,7 @@ ${line("project", result.project)}`);
|
|
|
37064
37164
|
|
|
37065
37165
|
// src/commands/codex-install.ts
|
|
37066
37166
|
import { homedir as homedir6 } from "os";
|
|
37067
|
-
import { join as
|
|
37167
|
+
import { join as join15 } from "path";
|
|
37068
37168
|
var CAPTURE_BIN2 = "prim-hook";
|
|
37069
37169
|
var GATE_BIN2 = "prim-pre-tool-use";
|
|
37070
37170
|
var POST_TOOL_USE_BIN2 = "prim-post-tool-use";
|
|
@@ -37088,8 +37188,8 @@ var CODEX_REGISTRATIONS = [
|
|
|
37088
37188
|
makeRegistration("PostToolUse", CODEX_POST_TOOL_MATCHER, POST_TOOL_USE_BIN2, CODEX_ARGS),
|
|
37089
37189
|
makeRegistration("SessionStart", "*", SESSION_START_BIN2, CODEX_ARGS)
|
|
37090
37190
|
];
|
|
37091
|
-
var USER_SCOPE_PATH2 =
|
|
37092
|
-
var projectScopePath2 = () =>
|
|
37191
|
+
var USER_SCOPE_PATH2 = join15(homedir6(), ".codex", "hooks.json");
|
|
37192
|
+
var projectScopePath2 = () => join15(projectRoot(), ".codex", "hooks.json");
|
|
37093
37193
|
function settingsPathFor2(scope) {
|
|
37094
37194
|
return scope === "user" ? USER_SCOPE_PATH2 : projectScopePath2();
|
|
37095
37195
|
}
|
|
@@ -37169,7 +37269,7 @@ function performInstall2(scope, force) {
|
|
|
37169
37269
|
const after = applyInstall2(before, { force });
|
|
37170
37270
|
const changed = JSON.stringify(before) !== JSON.stringify(after);
|
|
37171
37271
|
if (changed) {
|
|
37172
|
-
|
|
37272
|
+
atomicWrite3(path9, after);
|
|
37173
37273
|
}
|
|
37174
37274
|
return resultFor(scope, path9, after, changed);
|
|
37175
37275
|
}
|
|
@@ -37179,7 +37279,7 @@ function performUninstall2(scope) {
|
|
|
37179
37279
|
const after = applyUninstall2(before);
|
|
37180
37280
|
const changed = JSON.stringify(before) !== JSON.stringify(after);
|
|
37181
37281
|
if (changed) {
|
|
37182
|
-
|
|
37282
|
+
atomicWrite3(path9, after);
|
|
37183
37283
|
}
|
|
37184
37284
|
return resultFor(scope, path9, after, changed);
|
|
37185
37285
|
}
|
|
@@ -37200,7 +37300,7 @@ function uncoveredWorktreeHooks(status) {
|
|
|
37200
37300
|
if (status.user.present || status.project.present) return null;
|
|
37201
37301
|
const main = mainWorktreeRoot();
|
|
37202
37302
|
if (main === null) return null;
|
|
37203
|
-
const path9 =
|
|
37303
|
+
const path9 = join15(main, ".codex", "hooks.json");
|
|
37204
37304
|
return hasAnyHookRegistration2(readSettings(path9)) ? path9 : null;
|
|
37205
37305
|
}
|
|
37206
37306
|
function uncoveredWorktreeAdvice(path9) {
|
|
@@ -37260,9 +37360,9 @@ ${line("project", result.project)}`);
|
|
|
37260
37360
|
}
|
|
37261
37361
|
|
|
37262
37362
|
// src/commands/cursor-install.ts
|
|
37263
|
-
import { existsSync as existsSync10, readFileSync as
|
|
37363
|
+
import { existsSync as existsSync10, readFileSync as readFileSync13 } from "fs";
|
|
37264
37364
|
import { homedir as homedir7 } from "os";
|
|
37265
|
-
import { isAbsolute as isAbsolute7, join as
|
|
37365
|
+
import { isAbsolute as isAbsolute7, join as join16 } from "path";
|
|
37266
37366
|
var CAPTURE_BIN3 = "prim-hook";
|
|
37267
37367
|
var GATE_BIN3 = "prim-pre-tool-use";
|
|
37268
37368
|
var POST_TOOL_BIN = "prim-post-tool-use";
|
|
@@ -37293,14 +37393,14 @@ function cursorConfigDirectory(env4 = process.env, home = homedir7(), platform2
|
|
|
37293
37393
|
const explicit = env4.CURSOR_CONFIG_DIR?.trim();
|
|
37294
37394
|
if (explicit && isAbsolute7(explicit)) return explicit;
|
|
37295
37395
|
const xdg = env4.XDG_CONFIG_HOME?.trim();
|
|
37296
|
-
if (platform2 !== "darwin" && xdg && isAbsolute7(xdg)) return
|
|
37297
|
-
return
|
|
37396
|
+
if (platform2 !== "darwin" && xdg && isAbsolute7(xdg)) return join16(xdg, "cursor");
|
|
37397
|
+
return join16(home, ".cursor");
|
|
37298
37398
|
}
|
|
37299
37399
|
function cursorHooksPath(scope, root = projectRoot()) {
|
|
37300
|
-
return scope === "user" ?
|
|
37400
|
+
return scope === "user" ? join16(cursorConfigDirectory(), "hooks.json") : join16(root, ".cursor", "hooks.json");
|
|
37301
37401
|
}
|
|
37302
37402
|
function cursorCliConfigPath() {
|
|
37303
|
-
return
|
|
37403
|
+
return join16(cursorConfigDirectory(), "cli-config.json");
|
|
37304
37404
|
}
|
|
37305
37405
|
function plainObject(value) {
|
|
37306
37406
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -37309,7 +37409,7 @@ function readCursorHooks(path9) {
|
|
|
37309
37409
|
if (!existsSync10(path9)) return {};
|
|
37310
37410
|
let parsed;
|
|
37311
37411
|
try {
|
|
37312
|
-
parsed = JSON.parse(
|
|
37412
|
+
parsed = JSON.parse(readFileSync13(path9, "utf8"));
|
|
37313
37413
|
} catch {
|
|
37314
37414
|
throw new Error(`invalid Cursor hooks JSON at ${path9}`);
|
|
37315
37415
|
}
|
|
@@ -37331,7 +37431,7 @@ function readObject(path9) {
|
|
|
37331
37431
|
if (!existsSync10(path9)) return {};
|
|
37332
37432
|
let parsed;
|
|
37333
37433
|
try {
|
|
37334
|
-
parsed = JSON.parse(
|
|
37434
|
+
parsed = JSON.parse(readFileSync13(path9, "utf8"));
|
|
37335
37435
|
} catch {
|
|
37336
37436
|
throw new Error(`invalid Cursor CLI config JSON at ${path9}`);
|
|
37337
37437
|
}
|
|
@@ -37549,12 +37649,12 @@ function registerCursorCommands(program3) {
|
|
|
37549
37649
|
|
|
37550
37650
|
// src/commands/daemon.ts
|
|
37551
37651
|
import { spawn as spawn3 } from "child_process";
|
|
37552
|
-
import { closeSync as closeSync4, existsSync as existsSync12, mkdirSync as mkdirSync10, openSync as openSync4, readFileSync as
|
|
37553
|
-
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";
|
|
37554
37654
|
|
|
37555
37655
|
// src/daemon/latest-bootstrap.ts
|
|
37556
37656
|
import { spawn as spawn2 } from "child_process";
|
|
37557
|
-
import { join as
|
|
37657
|
+
import { join as join17 } from "path";
|
|
37558
37658
|
var LATEST_BOOTSTRAP_TIMEOUT_MS = 45e3;
|
|
37559
37659
|
var LATEST_BOOTSTRAP_LOCK_NAME = "daemon-latest.lock";
|
|
37560
37660
|
async function runPinnedEnsure(options) {
|
|
@@ -37595,7 +37695,7 @@ async function runPinnedEnsure(options) {
|
|
|
37595
37695
|
});
|
|
37596
37696
|
}
|
|
37597
37697
|
async function runLatestDaemonBootstrap(ensureCurrent, options = {}) {
|
|
37598
|
-
const lockPath = options.lockPath ??
|
|
37698
|
+
const lockPath = options.lockPath ?? join17(
|
|
37599
37699
|
primConfigDirectory({ env: options.env, homeDir: options.homeDir }),
|
|
37600
37700
|
LATEST_BOOTSTRAP_LOCK_NAME
|
|
37601
37701
|
);
|
|
@@ -37619,17 +37719,17 @@ async function runLatestDaemonBootstrap(ensureCurrent, options = {}) {
|
|
|
37619
37719
|
|
|
37620
37720
|
// src/daemon/launchd.ts
|
|
37621
37721
|
import { spawnSync } from "child_process";
|
|
37622
|
-
import { createHash as createHash8, randomBytes as
|
|
37722
|
+
import { createHash as createHash8, randomBytes as randomBytes6 } from "crypto";
|
|
37623
37723
|
import {
|
|
37624
37724
|
constants as constants5,
|
|
37625
37725
|
accessSync as accessSync2,
|
|
37626
|
-
chmodSync as
|
|
37726
|
+
chmodSync as chmodSync5,
|
|
37627
37727
|
copyFileSync as copyFileSync2,
|
|
37628
37728
|
existsSync as existsSync11,
|
|
37629
|
-
lstatSync as
|
|
37729
|
+
lstatSync as lstatSync7,
|
|
37630
37730
|
mkdirSync as mkdirSync9,
|
|
37631
37731
|
mkdtempSync as mkdtempSync2,
|
|
37632
|
-
readFileSync as
|
|
37732
|
+
readFileSync as readFileSync14,
|
|
37633
37733
|
readdirSync as readdirSync4,
|
|
37634
37734
|
readlinkSync,
|
|
37635
37735
|
realpathSync as realpathSync4,
|
|
@@ -37640,14 +37740,14 @@ import {
|
|
|
37640
37740
|
writeFileSync as writeFileSync7
|
|
37641
37741
|
} from "fs";
|
|
37642
37742
|
import { homedir as homedir8 } from "os";
|
|
37643
|
-
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";
|
|
37644
37744
|
|
|
37645
37745
|
// src/lib/bounded-file.ts
|
|
37646
|
-
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";
|
|
37647
37747
|
function readBoundedRegularFile(path9, maxBytes) {
|
|
37648
37748
|
let fd;
|
|
37649
37749
|
try {
|
|
37650
|
-
const linked =
|
|
37750
|
+
const linked = lstatSync6(path9);
|
|
37651
37751
|
if (!linked.isFile() || linked.size > maxBytes) return void 0;
|
|
37652
37752
|
fd = openSync3(path9, constants4.O_RDONLY | constants4.O_NOFOLLOW | constants4.O_NONBLOCK);
|
|
37653
37753
|
const opened = fstatSync(fd);
|
|
@@ -37722,31 +37822,31 @@ var LaunchctlError = class extends Error {
|
|
|
37722
37822
|
function xdgDataHome(options) {
|
|
37723
37823
|
const home = options.homeDir ?? homedir8();
|
|
37724
37824
|
const configured = (options.env ?? process.env).XDG_DATA_HOME;
|
|
37725
|
-
return configured && isAbsolute8(configured) ? configured :
|
|
37825
|
+
return configured && isAbsolute8(configured) ? configured : join18(home, ".local", "share");
|
|
37726
37826
|
}
|
|
37727
37827
|
function runtimePaths(options = {}) {
|
|
37728
|
-
const dataDir =
|
|
37729
|
-
const runtimeDir =
|
|
37730
|
-
const currentLink =
|
|
37828
|
+
const dataDir = join18(xdgDataHome(options), "prim");
|
|
37829
|
+
const runtimeDir = join18(dataDir, "runtime");
|
|
37830
|
+
const currentLink = join18(runtimeDir, "current");
|
|
37731
37831
|
return {
|
|
37732
37832
|
dataDir,
|
|
37733
37833
|
runtimeDir,
|
|
37734
|
-
releasesDir:
|
|
37834
|
+
releasesDir: join18(runtimeDir, "releases"),
|
|
37735
37835
|
currentLink,
|
|
37736
|
-
statuslineLauncher:
|
|
37737
|
-
disabledMarker:
|
|
37738
|
-
lifecycleLockDir:
|
|
37836
|
+
statuslineLauncher: join18(runtimeDir, "prim-statusline"),
|
|
37837
|
+
disabledMarker: join18(dataDir, "daemon.disabled"),
|
|
37838
|
+
lifecycleLockDir: join18(dataDir, "daemon.lifecycle.lock")
|
|
37739
37839
|
};
|
|
37740
37840
|
}
|
|
37741
37841
|
function daemonControlPaths(options = {}) {
|
|
37742
37842
|
const configDir = primConfigDirectory(options);
|
|
37743
37843
|
const legacy = runtimePaths(options);
|
|
37744
37844
|
return {
|
|
37745
|
-
launcher:
|
|
37746
|
-
disabledMarker:
|
|
37747
|
-
driftHealMarker:
|
|
37748
|
-
driftHealClaim:
|
|
37749
|
-
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"),
|
|
37750
37850
|
legacyDisabledMarker: legacy.disabledMarker,
|
|
37751
37851
|
legacyLifecycleLockDir: legacy.lifecycleLockDir
|
|
37752
37852
|
};
|
|
@@ -37754,10 +37854,10 @@ function daemonControlPaths(options = {}) {
|
|
|
37754
37854
|
function findPackageVersion(entryFile) {
|
|
37755
37855
|
let dir = dirname10(resolve7(entryFile));
|
|
37756
37856
|
for (let depth = 0; depth < 6; depth++) {
|
|
37757
|
-
const packagePath =
|
|
37857
|
+
const packagePath = join18(dir, "package.json");
|
|
37758
37858
|
if (existsSync11(packagePath)) {
|
|
37759
37859
|
try {
|
|
37760
|
-
const manifest = JSON.parse(
|
|
37860
|
+
const manifest = JSON.parse(readFileSync14(packagePath, "utf8"));
|
|
37761
37861
|
if (manifest.name === "@primitive.ai/prim" && manifest.version) {
|
|
37762
37862
|
return manifest.version;
|
|
37763
37863
|
}
|
|
@@ -37772,7 +37872,7 @@ function findPackageVersion(entryFile) {
|
|
|
37772
37872
|
}
|
|
37773
37873
|
function readRuntimeManifest(path9) {
|
|
37774
37874
|
try {
|
|
37775
|
-
const parsed = JSON.parse(
|
|
37875
|
+
const parsed = JSON.parse(readFileSync14(path9, "utf8"));
|
|
37776
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)) {
|
|
37777
37877
|
return null;
|
|
37778
37878
|
}
|
|
@@ -37788,10 +37888,10 @@ function exactKeys2(value, expected) {
|
|
|
37788
37888
|
return actual.length === wanted.length && actual.every((key, index) => key === wanted[index]);
|
|
37789
37889
|
}
|
|
37790
37890
|
function readOwnedRuntimeManifest(releaseDir) {
|
|
37791
|
-
const manifestPath =
|
|
37792
|
-
const daemonPath =
|
|
37891
|
+
const manifestPath = join18(releaseDir, "manifest.json");
|
|
37892
|
+
const daemonPath = join18(releaseDir, "prim-daemon-server");
|
|
37793
37893
|
try {
|
|
37794
|
-
const raw =
|
|
37894
|
+
const raw = readFileSync14(manifestPath, "utf8");
|
|
37795
37895
|
const parsed = JSON.parse(raw);
|
|
37796
37896
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
|
|
37797
37897
|
if (!exactKeys2(parsed, [
|
|
@@ -37806,7 +37906,7 @@ function readOwnedRuntimeManifest(releaseDir) {
|
|
|
37806
37906
|
}
|
|
37807
37907
|
const manifest = parsed;
|
|
37808
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)}
|
|
37809
|
-
` || !
|
|
37909
|
+
` || !lstatSync7(daemonPath).isFile() || sha256File(daemonPath) !== manifest.daemonSha256) {
|
|
37810
37910
|
return null;
|
|
37811
37911
|
}
|
|
37812
37912
|
const entries = readdirSync4(releaseDir).sort();
|
|
@@ -37835,7 +37935,7 @@ function sameRuntime(current, desired, daemonPath) {
|
|
|
37835
37935
|
}
|
|
37836
37936
|
}
|
|
37837
37937
|
function sha256File(path9) {
|
|
37838
|
-
return createHash8("sha256").update(
|
|
37938
|
+
return createHash8("sha256").update(readFileSync14(path9)).digest("hex");
|
|
37839
37939
|
}
|
|
37840
37940
|
function atomicSymlink(target, linkPath) {
|
|
37841
37941
|
const tempLink = `${linkPath}.tmp-${process.pid}-${createHash8("sha256").update(`${target}\0${Date.now()}\0${Math.random()}`).digest("hex").slice(0, 12)}`;
|
|
@@ -37868,11 +37968,11 @@ function stageRuntime(options = {}) {
|
|
|
37868
37968
|
currentRelease = realpathSync4(paths.currentLink);
|
|
37869
37969
|
} catch {
|
|
37870
37970
|
}
|
|
37871
|
-
const current = currentRelease ? readRuntimeManifest(
|
|
37872
|
-
const currentDaemon = currentRelease ?
|
|
37971
|
+
const current = currentRelease ? readRuntimeManifest(join18(currentRelease, "manifest.json")) : null;
|
|
37972
|
+
const currentDaemon = currentRelease ? join18(currentRelease, desired.daemonFile) : "";
|
|
37873
37973
|
if (currentRelease && sameRuntime(current, desired, currentDaemon)) {
|
|
37874
37974
|
const manifest = current;
|
|
37875
|
-
|
|
37975
|
+
atomicWrite4(
|
|
37876
37976
|
paths.statuslineLauncher,
|
|
37877
37977
|
statuslineLauncherContent(manifest.version, options),
|
|
37878
37978
|
RUNTIME_LAUNCHER_MODE
|
|
@@ -37885,19 +37985,19 @@ function stageRuntime(options = {}) {
|
|
|
37885
37985
|
};
|
|
37886
37986
|
}
|
|
37887
37987
|
mkdirSync9(paths.releasesDir, { recursive: true, mode: RUNTIME_DIR_MODE });
|
|
37888
|
-
|
|
37889
|
-
|
|
37890
|
-
const stagingDir = mkdtempSync2(
|
|
37891
|
-
|
|
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);
|
|
37892
37992
|
let releaseDir;
|
|
37893
37993
|
try {
|
|
37894
|
-
const daemonTarget =
|
|
37994
|
+
const daemonTarget = join18(stagingDir, desired.daemonFile);
|
|
37895
37995
|
copyFileSync2(daemonSource, daemonTarget);
|
|
37896
|
-
|
|
37996
|
+
chmodSync5(daemonTarget, RUNTIME_FILE_MODE);
|
|
37897
37997
|
if (sha256File(daemonTarget) !== desired.daemonSha256) {
|
|
37898
37998
|
throw new Error("cannot stage runtime: daemon bundle changed while it was copied");
|
|
37899
37999
|
}
|
|
37900
|
-
const manifestTarget =
|
|
38000
|
+
const manifestTarget = join18(stagingDir, "manifest.json");
|
|
37901
38001
|
writeFileSync7(manifestTarget, `${JSON.stringify(desired, null, 2)}
|
|
37902
38002
|
`, {
|
|
37903
38003
|
encoding: "utf8",
|
|
@@ -37905,11 +38005,11 @@ function stageRuntime(options = {}) {
|
|
|
37905
38005
|
flag: "wx"
|
|
37906
38006
|
});
|
|
37907
38007
|
const releaseName = `release-${createHash8("sha256").update(`${version}\0${nodePath}\0${desired.stagedAt}\0${process.pid}\0${Math.random()}`).digest("hex").slice(0, 16)}`;
|
|
37908
|
-
releaseDir =
|
|
38008
|
+
releaseDir = join18(paths.releasesDir, releaseName);
|
|
37909
38009
|
renameSync4(stagingDir, releaseDir);
|
|
37910
38010
|
releaseDir = realpathSync4(releaseDir);
|
|
37911
|
-
atomicSymlink(
|
|
37912
|
-
|
|
38011
|
+
atomicSymlink(join18("releases", releaseName), paths.currentLink);
|
|
38012
|
+
atomicWrite4(
|
|
37913
38013
|
paths.statuslineLauncher,
|
|
37914
38014
|
statuslineLauncherContent(desired.version, options),
|
|
37915
38015
|
RUNTIME_LAUNCHER_MODE
|
|
@@ -37922,14 +38022,14 @@ function stageRuntime(options = {}) {
|
|
|
37922
38022
|
changed: true,
|
|
37923
38023
|
manifest: desired,
|
|
37924
38024
|
paths,
|
|
37925
|
-
daemonPath:
|
|
38025
|
+
daemonPath: join18(releaseDir, desired.daemonFile)
|
|
37926
38026
|
};
|
|
37927
38027
|
}
|
|
37928
38028
|
function shellQuote2(value) {
|
|
37929
38029
|
return `'${value.replaceAll("'", `'"'"'`)}'`;
|
|
37930
38030
|
}
|
|
37931
38031
|
function statuslineLauncherContent(version, options = {}) {
|
|
37932
|
-
const socketPath =
|
|
38032
|
+
const socketPath = join18(primConfigDirectory(options), "sock");
|
|
37933
38033
|
const fallback = `primitive ${version} (daemon: down)`;
|
|
37934
38034
|
return `#!/bin/sh
|
|
37935
38035
|
response=$(
|
|
@@ -37952,7 +38052,7 @@ function assertRegularFile(path9, label) {
|
|
|
37952
38052
|
}
|
|
37953
38053
|
function lstatIfPresent3(path9) {
|
|
37954
38054
|
try {
|
|
37955
|
-
return
|
|
38055
|
+
return lstatSync7(path9);
|
|
37956
38056
|
} catch (error) {
|
|
37957
38057
|
const code = error.code;
|
|
37958
38058
|
if (code === "ENOENT" || code === "ENOTDIR") return void 0;
|
|
@@ -37961,7 +38061,7 @@ function lstatIfPresent3(path9) {
|
|
|
37961
38061
|
}
|
|
37962
38062
|
function driftHealMarkerTemporaries(configDir) {
|
|
37963
38063
|
try {
|
|
37964
|
-
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));
|
|
37965
38065
|
} catch (error) {
|
|
37966
38066
|
const code = error.code;
|
|
37967
38067
|
if (code === "ENOENT" || code === "ENOTDIR") return [];
|
|
@@ -37974,12 +38074,12 @@ function assertDriftHealClaim(path9) {
|
|
|
37974
38074
|
if (!claim.isDirectory() || readdirSync4(path9).some((entry) => entry !== DRIFT_HEAL_CLAIM_OWNER)) {
|
|
37975
38075
|
throw new Error(`refusing to remove unrecognized daemon drift-heal claim at ${path9}`);
|
|
37976
38076
|
}
|
|
37977
|
-
assertRegularFile(
|
|
38077
|
+
assertRegularFile(join18(path9, DRIFT_HEAL_CLAIM_OWNER), "daemon drift-heal claim owner");
|
|
37978
38078
|
}
|
|
37979
38079
|
function assertExactFile(path9, expected, label) {
|
|
37980
38080
|
if (!lstatIfPresent3(path9)) return;
|
|
37981
38081
|
assertRegularFile(path9, label);
|
|
37982
|
-
if (
|
|
38082
|
+
if (readFileSync14(path9, "utf8") !== expected) {
|
|
37983
38083
|
throw new Error(`refusing to remove unrecognized ${label} at ${path9}`);
|
|
37984
38084
|
}
|
|
37985
38085
|
}
|
|
@@ -37988,12 +38088,12 @@ function assertOwnedDaemonRuntime(options) {
|
|
|
37988
38088
|
const control = daemonControlPaths(options);
|
|
37989
38089
|
const configDir = primConfigDirectory(options);
|
|
37990
38090
|
const service = process.platform === "darwin" ? launchdPaths(options) : void 0;
|
|
37991
|
-
const logPath = service?.logPath ??
|
|
38091
|
+
const logPath = service?.logPath ?? join18(configDir, "daemon.log");
|
|
37992
38092
|
for (const activeArtifact of [
|
|
37993
|
-
|
|
37994
|
-
|
|
37995
|
-
|
|
37996
|
-
|
|
38093
|
+
join18(configDir, "daemon.pid"),
|
|
38094
|
+
join18(configDir, "sock"),
|
|
38095
|
+
join18(configDir, "daemon.lock"),
|
|
38096
|
+
join18(configDir, "client-instance.lock")
|
|
37997
38097
|
]) {
|
|
37998
38098
|
if (lstatIfPresent3(activeArtifact)) {
|
|
37999
38099
|
throw new Error(`refusing runtime removal while daemon state remains at ${activeArtifact}`);
|
|
@@ -38019,11 +38119,11 @@ function assertOwnedDaemonRuntime(options) {
|
|
|
38019
38119
|
assertRegularFile(temporary, "daemon drift-heal marker temporary");
|
|
38020
38120
|
}
|
|
38021
38121
|
assertDriftHealClaim(control.driftHealClaim);
|
|
38022
|
-
assertRegularFile(
|
|
38023
|
-
assertRegularFile(
|
|
38122
|
+
assertRegularFile(join18(configDir, "daemon-health.json"), "daemon health snapshot");
|
|
38123
|
+
assertRegularFile(join18(configDir, "client_instance_id"), "daemon client instance id");
|
|
38024
38124
|
if (service && lstatIfPresent3(service.plistPath)) {
|
|
38025
38125
|
assertRegularFile(service.plistPath, "launchd property list");
|
|
38026
|
-
if (
|
|
38126
|
+
if (readFileSync14(service.plistPath, "utf8") !== ownedLaunchAgentPlist(options, logPath)) {
|
|
38027
38127
|
throw new Error(
|
|
38028
38128
|
`refusing to remove unrecognized launchd property list at ${service.plistPath}`
|
|
38029
38129
|
);
|
|
@@ -38048,7 +38148,7 @@ function assertOwnedDaemonRuntime(options) {
|
|
|
38048
38148
|
throw new Error(`refusing to remove non-directory daemon releases at ${runtime.releasesDir}`);
|
|
38049
38149
|
}
|
|
38050
38150
|
for (const entry of readdirSync4(runtime.releasesDir, { withFileTypes: true })) {
|
|
38051
|
-
const releaseDir =
|
|
38151
|
+
const releaseDir = join18(runtime.releasesDir, entry.name);
|
|
38052
38152
|
const manifest = entry.isDirectory() && RUNTIME_RELEASE_RE.test(entry.name) ? readOwnedRuntimeManifest(releaseDir) : null;
|
|
38053
38153
|
if (!manifest) {
|
|
38054
38154
|
throw new Error(`refusing to remove unrecognized daemon release ${releaseDir}`);
|
|
@@ -38066,7 +38166,7 @@ function assertOwnedDaemonRuntime(options) {
|
|
|
38066
38166
|
}
|
|
38067
38167
|
const target = readlinkSync(runtime.currentLink);
|
|
38068
38168
|
const releaseName = basename3(target);
|
|
38069
|
-
if (target !==
|
|
38169
|
+
if (target !== join18("releases", releaseName) || !RUNTIME_RELEASE_RE.test(releaseName)) {
|
|
38070
38170
|
throw new Error(
|
|
38071
38171
|
`refusing to remove malformed daemon runtime selector ${runtime.currentLink}`
|
|
38072
38172
|
);
|
|
@@ -38094,7 +38194,7 @@ async function removeDaemonRuntime(options = {}) {
|
|
|
38094
38194
|
const control = daemonControlPaths(options);
|
|
38095
38195
|
const configDir = primConfigDirectory(options);
|
|
38096
38196
|
const service = process.platform === "darwin" ? launchdPaths(options) : void 0;
|
|
38097
|
-
const logPath = service?.logPath ??
|
|
38197
|
+
const logPath = service?.logPath ?? join18(configDir, "daemon.log");
|
|
38098
38198
|
const ownedArtifacts = [
|
|
38099
38199
|
runtime.runtimeDir,
|
|
38100
38200
|
control.launcher,
|
|
@@ -38105,8 +38205,8 @@ async function removeDaemonRuntime(options = {}) {
|
|
|
38105
38205
|
control.driftHealClaim,
|
|
38106
38206
|
...service ? [service.plistPath] : [],
|
|
38107
38207
|
logPath,
|
|
38108
|
-
|
|
38109
|
-
|
|
38208
|
+
join18(configDir, "daemon-health.json"),
|
|
38209
|
+
join18(configDir, "client_instance_id")
|
|
38110
38210
|
];
|
|
38111
38211
|
if (!ownedArtifacts.some((path9) => lstatIfPresent3(path9))) {
|
|
38112
38212
|
return { changed: false, runtimePaths: runtime };
|
|
@@ -38117,7 +38217,7 @@ async function removeDaemonRuntime(options = {}) {
|
|
|
38117
38217
|
rmSync5(path9, { force: true, recursive: path9 === control.driftHealClaim });
|
|
38118
38218
|
}
|
|
38119
38219
|
if (lstatIfPresent3(runtime.runtimeDir)) {
|
|
38120
|
-
const quarantined = `${runtime.runtimeDir}.uninstall-${String(process.pid)}-${
|
|
38220
|
+
const quarantined = `${runtime.runtimeDir}.uninstall-${String(process.pid)}-${randomBytes6(8).toString("hex")}`;
|
|
38121
38221
|
renameSync4(runtime.runtimeDir, quarantined);
|
|
38122
38222
|
rmSync5(quarantined, { recursive: true, force: true });
|
|
38123
38223
|
}
|
|
@@ -38186,7 +38286,7 @@ function readDaemonLauncherFile(path9) {
|
|
|
38186
38286
|
function readUsableDaemonConfig(path9) {
|
|
38187
38287
|
const config = readDaemonLauncher(path9);
|
|
38188
38288
|
if (!config) return null;
|
|
38189
|
-
const manifest = readRuntimeManifest(
|
|
38289
|
+
const manifest = readRuntimeManifest(join18(dirname10(config.daemonPath), "manifest.json"));
|
|
38190
38290
|
try {
|
|
38191
38291
|
accessSync2(config.nodePath, constants5.X_OK);
|
|
38192
38292
|
return manifest?.version === config.runtimeVersion && manifest.nodePath === config.nodePath && manifest.daemonSha256 === sha256File(config.daemonPath) ? config : null;
|
|
@@ -38239,8 +38339,8 @@ function launchdPaths(options = {}) {
|
|
|
38239
38339
|
return {
|
|
38240
38340
|
domainTarget: `gui/${uid}`,
|
|
38241
38341
|
serviceTarget: `gui/${uid}/${label}`,
|
|
38242
|
-
plistPath:
|
|
38243
|
-
logPath:
|
|
38342
|
+
plistPath: join18(home, "Library", "LaunchAgents", `${label}.plist`),
|
|
38343
|
+
logPath: join18(configDir, "daemon.log")
|
|
38244
38344
|
};
|
|
38245
38345
|
}
|
|
38246
38346
|
var runLaunchctl = (args, timeoutMs2 = COMMAND_TIMEOUT_MS) => {
|
|
@@ -38271,10 +38371,10 @@ function getLaunchdService(options = {}) {
|
|
|
38271
38371
|
)
|
|
38272
38372
|
);
|
|
38273
38373
|
}
|
|
38274
|
-
function
|
|
38374
|
+
function atomicWrite4(path9, content, mode, validate3) {
|
|
38275
38375
|
try {
|
|
38276
|
-
if (
|
|
38277
|
-
|
|
38376
|
+
if (readFileSync14(path9, "utf8") === content) {
|
|
38377
|
+
chmodSync5(path9, mode);
|
|
38278
38378
|
validate3?.(path9, COMMAND_TIMEOUT_MS);
|
|
38279
38379
|
return false;
|
|
38280
38380
|
}
|
|
@@ -38322,7 +38422,7 @@ function canonicalProspectivePath(path9) {
|
|
|
38322
38422
|
ancestor = parent;
|
|
38323
38423
|
}
|
|
38324
38424
|
try {
|
|
38325
|
-
return
|
|
38425
|
+
return join18(realpathSync4(ancestor), ...suffix);
|
|
38326
38426
|
} catch {
|
|
38327
38427
|
return resolve7(path9);
|
|
38328
38428
|
}
|
|
@@ -38337,10 +38437,10 @@ async function withDaemonLifecycleLock(operation, options = {}) {
|
|
|
38337
38437
|
);
|
|
38338
38438
|
}
|
|
38339
38439
|
async function stopVerifiedLegacyDaemon(options, deadlineMs, nowMs, sleep2) {
|
|
38340
|
-
const pidPath =
|
|
38440
|
+
const pidPath = join18(primConfigDirectory(options), "daemon.pid");
|
|
38341
38441
|
let pid;
|
|
38342
38442
|
try {
|
|
38343
|
-
pid = Number(
|
|
38443
|
+
pid = Number(readFileSync14(pidPath, "utf8").trim());
|
|
38344
38444
|
} catch {
|
|
38345
38445
|
throw new Error("an unsupervised daemon answered, but it has no verifiable pidfile");
|
|
38346
38446
|
}
|
|
@@ -38528,9 +38628,9 @@ function setDaemonExplicitlyDisabled(disabled, options = {}) {
|
|
|
38528
38628
|
}
|
|
38529
38629
|
const content = DAEMON_DISABLED_CONTENT;
|
|
38530
38630
|
if (paths.legacyDisabledMarker !== paths.disabledMarker) {
|
|
38531
|
-
|
|
38631
|
+
atomicWrite4(paths.legacyDisabledMarker, content, RUNTIME_FILE_MODE);
|
|
38532
38632
|
}
|
|
38533
|
-
|
|
38633
|
+
atomicWrite4(paths.disabledMarker, content, RUNTIME_FILE_MODE);
|
|
38534
38634
|
}
|
|
38535
38635
|
function launcherRunnable(config) {
|
|
38536
38636
|
try {
|
|
@@ -38603,7 +38703,7 @@ async function ensureMacDaemonLocked(options) {
|
|
|
38603
38703
|
if (!options.explicitlyStarted && daemonExplicitlyDisabled(options)) {
|
|
38604
38704
|
const control2 = daemonControlPaths(options);
|
|
38605
38705
|
if (!existsSync11(control2.disabledMarker)) {
|
|
38606
|
-
|
|
38706
|
+
atomicWrite4(control2.disabledMarker, "disabled by `prim daemon stop`\n", RUNTIME_FILE_MODE);
|
|
38607
38707
|
}
|
|
38608
38708
|
return {
|
|
38609
38709
|
state: "disabled",
|
|
@@ -38629,7 +38729,7 @@ async function ensureMacDaemonLocked(options) {
|
|
|
38629
38729
|
const configuredApiUrl = (options.env ?? process.env).PRIM_API_URL;
|
|
38630
38730
|
const apiUrl = configuredApiUrl ? normalizeApiUrl(configuredApiUrl) || void 0 : void 0;
|
|
38631
38731
|
const configDir = primConfigDirectory(options);
|
|
38632
|
-
const legacyDefaultConfigDir =
|
|
38732
|
+
const legacyDefaultConfigDir = join18(options.homeDir ?? homedir8(), ".config", "prim");
|
|
38633
38733
|
const launcherConfigDir = configDir === legacyDefaultConfigDir ? void 0 : configDir;
|
|
38634
38734
|
if (retainSelected && selected) {
|
|
38635
38735
|
const usable = readUsableDaemonConfig(control.launcher);
|
|
@@ -38658,16 +38758,16 @@ async function ensureMacDaemonLocked(options) {
|
|
|
38658
38758
|
const servicePaths = launchdPaths(options);
|
|
38659
38759
|
mkdirSync9(dirname10(servicePaths.logPath), { recursive: true, mode: RUNTIME_DIR_MODE });
|
|
38660
38760
|
writeFileSync7(servicePaths.logPath, "", { mode: RUNTIME_FILE_MODE, flag: "a" });
|
|
38661
|
-
|
|
38761
|
+
chmodSync5(servicePaths.logPath, RUNTIME_FILE_MODE);
|
|
38662
38762
|
const launcher = generateDaemonLauncher(daemonConfig);
|
|
38663
|
-
|
|
38763
|
+
atomicWrite4(control.launcher, launcher.content, RUNTIME_LAUNCHER_MODE);
|
|
38664
38764
|
const plist = generateLaunchAgentPlist({
|
|
38665
38765
|
launcherPath: control.launcher,
|
|
38666
38766
|
logPath: servicePaths.logPath,
|
|
38667
38767
|
workingDirectory: options.homeDir ?? homedir8(),
|
|
38668
38768
|
label: options.label
|
|
38669
38769
|
});
|
|
38670
|
-
const plistChanged =
|
|
38770
|
+
const plistChanged = atomicWrite4(
|
|
38671
38771
|
servicePaths.plistPath,
|
|
38672
38772
|
plist,
|
|
38673
38773
|
PLIST_FILE_MODE,
|
|
@@ -38936,9 +39036,9 @@ function formatStatusline(version, snapshot, resolveIngestionStatus, options = {
|
|
|
38936
39036
|
// src/commands/daemon.ts
|
|
38937
39037
|
var DAEMON_BIN = "prim-daemon-server";
|
|
38938
39038
|
var CONFIG_DIR = primConfigDirectory();
|
|
38939
|
-
var PID_PATH =
|
|
38940
|
-
var SOCK_PATH2 =
|
|
38941
|
-
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");
|
|
38942
39042
|
var CONFIG_DIR_MODE2 = 448;
|
|
38943
39043
|
var LOG_FILE_MODE = 384;
|
|
38944
39044
|
var STOP_TIMEOUT_MS = 5e3;
|
|
@@ -38983,7 +39083,7 @@ function readPidfile() {
|
|
|
38983
39083
|
if (!existsSync12(PID_PATH)) {
|
|
38984
39084
|
return null;
|
|
38985
39085
|
}
|
|
38986
|
-
const raw =
|
|
39086
|
+
const raw = readFileSync15(PID_PATH, "utf-8").trim();
|
|
38987
39087
|
const pid = Number(raw);
|
|
38988
39088
|
if (!Number.isInteger(pid) || pid <= 0) {
|
|
38989
39089
|
return null;
|
|
@@ -39011,7 +39111,7 @@ function openDaemonLog(configDir = CONFIG_DIR) {
|
|
|
39011
39111
|
if (!existsSync12(configDir)) {
|
|
39012
39112
|
mkdirSync10(configDir, { recursive: true, mode: CONFIG_DIR_MODE2 });
|
|
39013
39113
|
}
|
|
39014
|
-
return openSync4(
|
|
39114
|
+
return openSync4(join19(configDir, "daemon.log"), "a", LOG_FILE_MODE);
|
|
39015
39115
|
}
|
|
39016
39116
|
async function waitForReady() {
|
|
39017
39117
|
const deadline = Date.now() + READY_TIMEOUT_MS;
|
|
@@ -42309,22 +42409,22 @@ import {
|
|
|
42309
42409
|
mkdirSync as mkdirSync11,
|
|
42310
42410
|
openSync as openSync5,
|
|
42311
42411
|
opendirSync,
|
|
42312
|
-
readFileSync as
|
|
42412
|
+
readFileSync as readFileSync17,
|
|
42313
42413
|
readSync as readSync2,
|
|
42314
42414
|
readdirSync as readdirSync6
|
|
42315
42415
|
} from "fs";
|
|
42316
|
-
import { dirname as dirname12, join as
|
|
42416
|
+
import { dirname as dirname12, join as join21 } from "path";
|
|
42317
42417
|
|
|
42318
42418
|
// src/drain-progress.ts
|
|
42319
42419
|
import {
|
|
42320
|
-
chmodSync as
|
|
42420
|
+
chmodSync as chmodSync6,
|
|
42321
42421
|
existsSync as existsSync13,
|
|
42322
|
-
readFileSync as
|
|
42422
|
+
readFileSync as readFileSync16,
|
|
42323
42423
|
readdirSync as readdirSync5,
|
|
42324
42424
|
rmSync as rmSync6,
|
|
42325
42425
|
rmdirSync
|
|
42326
42426
|
} from "fs";
|
|
42327
|
-
import { basename as basename4, dirname as dirname11, join as
|
|
42427
|
+
import { basename as basename4, dirname as dirname11, join as join20 } from "path";
|
|
42328
42428
|
var DIRECTORY_MODE3 = 448;
|
|
42329
42429
|
var FILE_MODE2 = 384;
|
|
42330
42430
|
var DRAIN_PROGRESS_DIRNAME = "drain-progress";
|
|
@@ -42333,10 +42433,10 @@ function rotationIdentity(stat) {
|
|
|
42333
42433
|
return { size: stat.size, ino: stat.ino, dev: stat.dev };
|
|
42334
42434
|
}
|
|
42335
42435
|
function drainProgressDirectory(flushingPath) {
|
|
42336
|
-
return
|
|
42436
|
+
return join20(dirname11(flushingPath), DRAIN_PROGRESS_DIRNAME);
|
|
42337
42437
|
}
|
|
42338
42438
|
function drainProgressPath(flushingPath) {
|
|
42339
|
-
return
|
|
42439
|
+
return join20(drainProgressDirectory(flushingPath), `${basename4(flushingPath)}.json`);
|
|
42340
42440
|
}
|
|
42341
42441
|
function isByteCount(value) {
|
|
42342
42442
|
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
@@ -42344,7 +42444,7 @@ function isByteCount(value) {
|
|
|
42344
42444
|
function drainResumeOffset(flushingPath, rotation) {
|
|
42345
42445
|
let parsed;
|
|
42346
42446
|
try {
|
|
42347
|
-
parsed = JSON.parse(
|
|
42447
|
+
parsed = JSON.parse(readFileSync16(drainProgressPath(flushingPath), "utf8"));
|
|
42348
42448
|
} catch {
|
|
42349
42449
|
return 0;
|
|
42350
42450
|
}
|
|
@@ -42360,7 +42460,7 @@ function drainResumeOffset(flushingPath, rotation) {
|
|
|
42360
42460
|
function writeDrainCheckpoint(flushingPath, checkpoint) {
|
|
42361
42461
|
const directory = drainProgressDirectory(flushingPath);
|
|
42362
42462
|
ensureDurableDirectory(directory, DIRECTORY_MODE3);
|
|
42363
|
-
|
|
42463
|
+
chmodSync6(directory, DIRECTORY_MODE3);
|
|
42364
42464
|
atomicWriteFile(drainProgressPath(flushingPath), `${JSON.stringify(checkpoint)}
|
|
42365
42465
|
`, {
|
|
42366
42466
|
mode: FILE_MODE2
|
|
@@ -42381,7 +42481,7 @@ function removeDrainCheckpoint(flushingPath) {
|
|
|
42381
42481
|
removeEmptyDirectory(drainProgressDirectory(flushingPath));
|
|
42382
42482
|
}
|
|
42383
42483
|
function sweepOrphanedDrainCheckpoints(bucketDirectory) {
|
|
42384
|
-
const directory =
|
|
42484
|
+
const directory = join20(bucketDirectory, DRAIN_PROGRESS_DIRNAME);
|
|
42385
42485
|
let names;
|
|
42386
42486
|
try {
|
|
42387
42487
|
names = readdirSync5(directory);
|
|
@@ -42390,11 +42490,11 @@ function sweepOrphanedDrainCheckpoints(bucketDirectory) {
|
|
|
42390
42490
|
}
|
|
42391
42491
|
for (const name of names) {
|
|
42392
42492
|
const rotation = CHECKPOINT_NAME.exec(name)?.[1];
|
|
42393
|
-
if (rotation === void 0 || existsSync13(
|
|
42493
|
+
if (rotation === void 0 || existsSync13(join20(bucketDirectory, rotation))) {
|
|
42394
42494
|
continue;
|
|
42395
42495
|
}
|
|
42396
42496
|
try {
|
|
42397
|
-
rmSync6(
|
|
42497
|
+
rmSync6(join20(directory, name), { force: true });
|
|
42398
42498
|
} catch {
|
|
42399
42499
|
}
|
|
42400
42500
|
}
|
|
@@ -42405,7 +42505,7 @@ function sweepOrphanedDrainCheckpoints(bucketDirectory) {
|
|
|
42405
42505
|
}
|
|
42406
42506
|
|
|
42407
42507
|
// src/journal.ts
|
|
42408
|
-
var JOURNAL_DIR =
|
|
42508
|
+
var JOURNAL_DIR = join21(primConfigDirectory(), "moves");
|
|
42409
42509
|
var JOURNAL_BASENAME = "journal.ndjson";
|
|
42410
42510
|
var JOURNAL_STATS_SAMPLE_BYTES = 64 * 1024;
|
|
42411
42511
|
var PENDING_STATS_MAX_FILES = 128;
|
|
@@ -42417,7 +42517,7 @@ function envSlug(apiUrl) {
|
|
|
42417
42517
|
return slug;
|
|
42418
42518
|
}
|
|
42419
42519
|
function currentEnvDir() {
|
|
42420
|
-
return
|
|
42520
|
+
return join21(JOURNAL_DIR, envSlug(getSiteUrl()));
|
|
42421
42521
|
}
|
|
42422
42522
|
function parseMoves(content) {
|
|
42423
42523
|
const moves = [];
|
|
@@ -42436,7 +42536,7 @@ function readMovesFromPath(path9) {
|
|
|
42436
42536
|
if (!existsSync14(path9)) {
|
|
42437
42537
|
return [];
|
|
42438
42538
|
}
|
|
42439
|
-
return parseMoves(
|
|
42539
|
+
return parseMoves(readFileSync17(path9, "utf-8"));
|
|
42440
42540
|
}
|
|
42441
42541
|
function listBuckets() {
|
|
42442
42542
|
const out = [];
|
|
@@ -42448,7 +42548,7 @@ function listBuckets() {
|
|
|
42448
42548
|
if (!entry.isDirectory()) {
|
|
42449
42549
|
continue;
|
|
42450
42550
|
}
|
|
42451
|
-
const path9 =
|
|
42551
|
+
const path9 = join21(envDir, entry.name, JOURNAL_BASENAME);
|
|
42452
42552
|
if (existsSync14(path9)) {
|
|
42453
42553
|
out.push({ bucket: entry.name, path: path9 });
|
|
42454
42554
|
}
|
|
@@ -42525,7 +42625,7 @@ function listFlushingInDir(dir, bucket, options = {}) {
|
|
|
42525
42625
|
entry = entries.readSync();
|
|
42526
42626
|
continue;
|
|
42527
42627
|
}
|
|
42528
|
-
const path9 =
|
|
42628
|
+
const path9 = join21(dir, entry.name);
|
|
42529
42629
|
let sample;
|
|
42530
42630
|
try {
|
|
42531
42631
|
sample = sampleJournalFile(path9, remainingBytes, { fromDrainCheckpoint: true });
|
|
@@ -42563,7 +42663,7 @@ function listFlushing(options = {}) {
|
|
|
42563
42663
|
break;
|
|
42564
42664
|
}
|
|
42565
42665
|
if (entry.isDirectory()) {
|
|
42566
|
-
const found = listFlushingInDir(
|
|
42666
|
+
const found = listFlushingInDir(join21(envDir, entry.name), entry.name, {
|
|
42567
42667
|
sampleBytes: remainingBytes,
|
|
42568
42668
|
maxFiles: maxFiles - out.length
|
|
42569
42669
|
});
|
|
@@ -42583,7 +42683,7 @@ function sweepOrphanedDrainProgress() {
|
|
|
42583
42683
|
}
|
|
42584
42684
|
for (const entry of readdirSync6(envDir, { withFileTypes: true })) {
|
|
42585
42685
|
if (entry.isDirectory()) {
|
|
42586
|
-
sweepOrphanedDrainCheckpoints(
|
|
42686
|
+
sweepOrphanedDrainCheckpoints(join21(envDir, entry.name));
|
|
42587
42687
|
}
|
|
42588
42688
|
}
|
|
42589
42689
|
}
|
|
@@ -42632,9 +42732,9 @@ function pendingJournalStats() {
|
|
|
42632
42732
|
}
|
|
42633
42733
|
|
|
42634
42734
|
// src/commands/hermes-install.ts
|
|
42635
|
-
import { existsSync as existsSync15, readFileSync as
|
|
42735
|
+
import { existsSync as existsSync15, readFileSync as readFileSync18, rmSync as rmSync7, statSync as statSync4 } from "fs";
|
|
42636
42736
|
import { homedir as homedir9 } from "os";
|
|
42637
|
-
import { join as
|
|
42737
|
+
import { join as join22 } from "path";
|
|
42638
42738
|
|
|
42639
42739
|
// node_modules/.pnpm/yaml@2.9.0/node_modules/yaml/browser/dist/nodes/identity.js
|
|
42640
42740
|
var ALIAS = /* @__PURE__ */ Symbol.for("yaml.alias");
|
|
@@ -48913,13 +49013,13 @@ var JSON_INDENT3 = 2;
|
|
|
48913
49013
|
var CONFIG_MODE = 384;
|
|
48914
49014
|
var PRIM_BINS4 = [CAPTURE_BIN4, GATE_BIN4, POST_TOOL_USE_BIN3, SESSION_START_BIN4, SESSION_END_BIN3];
|
|
48915
49015
|
function hermesHome() {
|
|
48916
|
-
return process.env.HERMES_HOME ??
|
|
49016
|
+
return process.env.HERMES_HOME ?? join22(homedir9(), ".hermes");
|
|
48917
49017
|
}
|
|
48918
49018
|
function configPath() {
|
|
48919
|
-
return
|
|
49019
|
+
return join22(hermesHome(), "config.yaml");
|
|
48920
49020
|
}
|
|
48921
49021
|
function legacyShimPath() {
|
|
48922
|
-
return
|
|
49022
|
+
return join22(hermesHome(), "agent-hooks", "prim-shim.sh");
|
|
48923
49023
|
}
|
|
48924
49024
|
function commandFor2(bin) {
|
|
48925
49025
|
return stableHookCommand(bin, HERMES_ARGS);
|
|
@@ -49034,7 +49134,7 @@ function hookRuntimeResolutions3(hooks) {
|
|
|
49034
49134
|
function inspectHookRuntimeResolutions4() {
|
|
49035
49135
|
const path9 = configPath();
|
|
49036
49136
|
if (!existsSync15(path9)) return [];
|
|
49037
|
-
return hookRuntimeResolutions3(readHooks(parseHermesDocument(
|
|
49137
|
+
return hookRuntimeResolutions3(readHooks(parseHermesDocument(readFileSync18(path9, "utf8"))));
|
|
49038
49138
|
}
|
|
49039
49139
|
function entryMatchesRegistration3(owned, registration) {
|
|
49040
49140
|
const expected = entryFor(registration);
|
|
@@ -49307,7 +49407,7 @@ function readConfigSnapshot(path9) {
|
|
|
49307
49407
|
return {
|
|
49308
49408
|
exists: true,
|
|
49309
49409
|
mode: statSync4(path9).mode & 511,
|
|
49310
|
-
raw:
|
|
49410
|
+
raw: readFileSync18(path9, "utf8")
|
|
49311
49411
|
};
|
|
49312
49412
|
}
|
|
49313
49413
|
var CONCURRENT_CONFIG_MESSAGE = "Hermes config changed during update; concurrent changes were preserved, retry the command";
|
|
@@ -49316,7 +49416,7 @@ function writeHermesConfigSnapshot(path9, before, after, expectedHooks) {
|
|
|
49316
49416
|
ensureParent: true,
|
|
49317
49417
|
mode: before.mode,
|
|
49318
49418
|
validate(temporaryPath) {
|
|
49319
|
-
const flushed =
|
|
49419
|
+
const flushed = readFileSync18(temporaryPath, "utf8");
|
|
49320
49420
|
if (!mergePreservesHermesSemantics(before.raw, flushed, expectedHooks)) {
|
|
49321
49421
|
throw new Error(INVALID_MERGE_MESSAGE);
|
|
49322
49422
|
}
|
|
@@ -49394,7 +49494,7 @@ function performUninstall4() {
|
|
|
49394
49494
|
}
|
|
49395
49495
|
function performStatus4() {
|
|
49396
49496
|
const path9 = configPath();
|
|
49397
|
-
const raw = existsSync15(path9) ?
|
|
49497
|
+
const raw = existsSync15(path9) ? readFileSync18(path9, "utf8") : "";
|
|
49398
49498
|
const hooks = raw ? readHooks(parseHermesDocument(raw)) : {};
|
|
49399
49499
|
return {
|
|
49400
49500
|
path: path9,
|
|
@@ -50278,17 +50378,17 @@ function registerDoctorCommands(program3, dependencies = {}) {
|
|
|
50278
50378
|
|
|
50279
50379
|
// src/commands/moves.ts
|
|
50280
50380
|
import { existsSync as existsSync18, mkdirSync as mkdirSync13, unlinkSync as unlinkSync6, writeFileSync as writeFileSync9 } from "fs";
|
|
50281
|
-
import { join as
|
|
50381
|
+
import { join as join25 } from "path";
|
|
50282
50382
|
|
|
50283
50383
|
// src/flusher.ts
|
|
50284
50384
|
import { createReadStream, renameSync as renameSync6, statSync as statSync5, unlinkSync as unlinkSync5 } from "fs";
|
|
50285
|
-
import { dirname as dirname14, join as
|
|
50385
|
+
import { dirname as dirname14, join as join24 } from "path";
|
|
50286
50386
|
|
|
50287
50387
|
// src/dead-letter.ts
|
|
50288
|
-
import { createHash as createHash9, randomBytes as
|
|
50388
|
+
import { createHash as createHash9, randomBytes as randomBytes7 } from "crypto";
|
|
50289
50389
|
import {
|
|
50290
50390
|
constants as constants6,
|
|
50291
|
-
chmodSync as
|
|
50391
|
+
chmodSync as chmodSync7,
|
|
50292
50392
|
closeSync as closeSync6,
|
|
50293
50393
|
existsSync as existsSync17,
|
|
50294
50394
|
fchmodSync as fchmodSync3,
|
|
@@ -50299,21 +50399,21 @@ import {
|
|
|
50299
50399
|
rmSync as rmSync8,
|
|
50300
50400
|
writeFileSync as writeFileSync8
|
|
50301
50401
|
} from "fs";
|
|
50302
|
-
import { dirname as dirname13, join as
|
|
50402
|
+
import { dirname as dirname13, join as join23 } from "path";
|
|
50303
50403
|
var DIRECTORY_MODE4 = 448;
|
|
50304
50404
|
var FILE_MODE3 = 384;
|
|
50305
50405
|
var DEAD_LETTER_DIRNAME = "dead-letter";
|
|
50306
50406
|
function deadLetterDirectoryForRotation(flushingPath) {
|
|
50307
|
-
return
|
|
50407
|
+
return join23(dirname13(flushingPath), DEAD_LETTER_DIRNAME);
|
|
50308
50408
|
}
|
|
50309
50409
|
function deadLetterPathForRawLine(flushingPath, rawLine) {
|
|
50310
50410
|
const quarantineId = createHash9("sha256").update(rawLine).digest("hex");
|
|
50311
|
-
return
|
|
50411
|
+
return join23(deadLetterDirectoryForRotation(flushingPath), `raw-${quarantineId}.json`);
|
|
50312
50412
|
}
|
|
50313
50413
|
function ensureDeadLetterDirectory(flushingPath, persistDirectory) {
|
|
50314
50414
|
const directory = deadLetterDirectoryForRotation(flushingPath);
|
|
50315
50415
|
mkdirSync12(directory, { recursive: true, mode: DIRECTORY_MODE4 });
|
|
50316
|
-
|
|
50416
|
+
chmodSync7(directory, DIRECTORY_MODE4);
|
|
50317
50417
|
persistDirectory(dirname13(directory));
|
|
50318
50418
|
return directory;
|
|
50319
50419
|
}
|
|
@@ -50322,9 +50422,9 @@ function persistDeadLetter(directory, path9, quarantineId, record3, persistDirec
|
|
|
50322
50422
|
persistDirectory(directory);
|
|
50323
50423
|
return;
|
|
50324
50424
|
}
|
|
50325
|
-
const temporaryPath =
|
|
50425
|
+
const temporaryPath = join23(
|
|
50326
50426
|
directory,
|
|
50327
|
-
`.${quarantineId}.${String(process.pid)}.${
|
|
50427
|
+
`.${quarantineId}.${String(process.pid)}.${randomBytes7(8).toString("hex")}.tmp`
|
|
50328
50428
|
);
|
|
50329
50429
|
const flags = constants6.O_CREAT | constants6.O_EXCL | constants6.O_WRONLY | constants6.O_NOFOLLOW;
|
|
50330
50430
|
try {
|
|
@@ -50354,7 +50454,7 @@ function quarantineMove(flushingPath, move, reason, now = Date.now, options = {}
|
|
|
50354
50454
|
reason,
|
|
50355
50455
|
move
|
|
50356
50456
|
};
|
|
50357
|
-
const path9 =
|
|
50457
|
+
const path9 = join23(directory, `${record3.quarantineId}.json`);
|
|
50358
50458
|
persistDeadLetter(directory, path9, record3.quarantineId, record3, persistDirectory);
|
|
50359
50459
|
return record3;
|
|
50360
50460
|
}
|
|
@@ -50762,7 +50862,7 @@ async function flushOnce() {
|
|
|
50762
50862
|
return inspection.retainedBuckets.length > 0 ? { flushed: total, quarantined, retained: inspection.retainedBuckets } : { flushed: total, quarantined };
|
|
50763
50863
|
}
|
|
50764
50864
|
var flushInFlight;
|
|
50765
|
-
var FLUSH_LOCK_PATH =
|
|
50865
|
+
var FLUSH_LOCK_PATH = join24(dirname14(JOURNAL_DIR), ".flush.lock");
|
|
50766
50866
|
var FLUSH_LOCK_TIMEOUT_MS = 250;
|
|
50767
50867
|
function isFlushLockContended(error) {
|
|
50768
50868
|
return error instanceof Error && error.message.startsWith("timed out waiting for file lock");
|
|
@@ -50894,18 +50994,18 @@ function registerMovesCommands(program3) {
|
|
|
50894
50994
|
}
|
|
50895
50995
|
});
|
|
50896
50996
|
moves.command("bind").description("Pin the current directory to an org via .prim/workspace.json").requiredOption("--orgId <orgId>", "Convex organization id").action((opts) => {
|
|
50897
|
-
const dir =
|
|
50997
|
+
const dir = join25(process.cwd(), ".prim");
|
|
50898
50998
|
if (!existsSync18(dir)) {
|
|
50899
50999
|
mkdirSync13(dir, { recursive: true, mode: DIR_MODE });
|
|
50900
51000
|
}
|
|
50901
|
-
const file =
|
|
51001
|
+
const file = join25(process.cwd(), WORKSPACE_FILE);
|
|
50902
51002
|
writeFileSync9(file, JSON.stringify({ orgId: opts.orgId, boundAt: Date.now() }, null, 2), {
|
|
50903
51003
|
mode: FILE_MODE4
|
|
50904
51004
|
});
|
|
50905
51005
|
console.log(`[prim] bound ${process.cwd()} to org ${opts.orgId}`);
|
|
50906
51006
|
});
|
|
50907
51007
|
moves.command("drop").description("Remove the .prim/workspace.json binding from the cwd").action(() => {
|
|
50908
|
-
const file =
|
|
51008
|
+
const file = join25(process.cwd(), WORKSPACE_FILE);
|
|
50909
51009
|
if (!existsSync18(file)) {
|
|
50910
51010
|
console.log("[prim] no workspace binding in cwd");
|
|
50911
51011
|
return;
|
|
@@ -50999,18 +51099,18 @@ function registerReconcileCommands(program3) {
|
|
|
50999
51099
|
import {
|
|
51000
51100
|
existsSync as existsSync20,
|
|
51001
51101
|
mkdirSync as mkdirSync14,
|
|
51002
|
-
readFileSync as
|
|
51102
|
+
readFileSync as readFileSync20,
|
|
51003
51103
|
readdirSync as readdirSync7,
|
|
51004
51104
|
unlinkSync as unlinkSync7,
|
|
51005
51105
|
writeFileSync as writeFileSync10
|
|
51006
51106
|
} from "fs";
|
|
51007
|
-
import { join as
|
|
51107
|
+
import { join as join27 } from "path";
|
|
51008
51108
|
|
|
51009
51109
|
// src/binding.ts
|
|
51010
|
-
import { existsSync as existsSync19, readFileSync as
|
|
51011
|
-
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";
|
|
51012
51112
|
var PRIM_CONFIG_DIR = primConfigDirectory();
|
|
51013
|
-
var SESSIONS_DIR =
|
|
51113
|
+
var SESSIONS_DIR = join26(PRIM_CONFIG_DIR, "sessions");
|
|
51014
51114
|
|
|
51015
51115
|
// src/commands/session.ts
|
|
51016
51116
|
var DIR_MODE2 = 448;
|
|
@@ -51021,7 +51121,7 @@ function ensureDir() {
|
|
|
51021
51121
|
}
|
|
51022
51122
|
}
|
|
51023
51123
|
function markerPath(sessionId) {
|
|
51024
|
-
return
|
|
51124
|
+
return join27(SESSIONS_DIR, `${sessionId}.json`);
|
|
51025
51125
|
}
|
|
51026
51126
|
function registerSessionCommands(program3) {
|
|
51027
51127
|
const session = program3.command("session").description("Decision Event Pipeline \u2014 session binding markers");
|
|
@@ -51049,7 +51149,7 @@ function registerSessionCommands(program3) {
|
|
|
51049
51149
|
for (const f of files) {
|
|
51050
51150
|
const sessionId = f.replace(/\.json$/, "");
|
|
51051
51151
|
try {
|
|
51052
|
-
const m = JSON.parse(
|
|
51152
|
+
const m = JSON.parse(readFileSync20(join27(SESSIONS_DIR, f), "utf-8"));
|
|
51053
51153
|
console.log(`${sessionId} org=${m.orgId}`);
|
|
51054
51154
|
} catch {
|
|
51055
51155
|
}
|
|
@@ -51068,8 +51168,8 @@ function registerSessionCommands(program3) {
|
|
|
51068
51168
|
|
|
51069
51169
|
// src/commands/setup.ts
|
|
51070
51170
|
import { spawnSync as spawnSync2 } from "child_process";
|
|
51071
|
-
import { existsSync as existsSync21, readFileSync as
|
|
51072
|
-
import { join as
|
|
51171
|
+
import { existsSync as existsSync21, readFileSync as readFileSync21 } from "fs";
|
|
51172
|
+
import { join as join28 } from "path";
|
|
51073
51173
|
var EXIT_INCOMPLETE = 1;
|
|
51074
51174
|
var EXIT_USAGE3 = 2;
|
|
51075
51175
|
var SETUP_ORCHESTRATOR_ENV = "PRIM_SETUP_ORCHESTRATOR";
|
|
@@ -51207,8 +51307,8 @@ function detectProjectConflicts(agent, run, globalHooksActive) {
|
|
|
51207
51307
|
let preCommit;
|
|
51208
51308
|
try {
|
|
51209
51309
|
const root = gitToplevel();
|
|
51210
|
-
const path9 = root &&
|
|
51211
|
-
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");
|
|
51212
51312
|
} catch {
|
|
51213
51313
|
}
|
|
51214
51314
|
if (projectHooksConflict(globalHooksActive, preCommit)) conflicts.push(CONFLICT_HOOKS);
|
|
@@ -51394,16 +51494,16 @@ import {
|
|
|
51394
51494
|
closeSync as closeSync8,
|
|
51395
51495
|
existsSync as existsSync23,
|
|
51396
51496
|
fstatSync as fstatSync4,
|
|
51397
|
-
lstatSync as
|
|
51497
|
+
lstatSync as lstatSync9,
|
|
51398
51498
|
openSync as openSync8,
|
|
51399
|
-
readFileSync as
|
|
51499
|
+
readFileSync as readFileSync23,
|
|
51400
51500
|
readSync as readSync4,
|
|
51401
51501
|
readdirSync as readdirSync9,
|
|
51402
51502
|
rmdirSync as rmdirSync3,
|
|
51403
51503
|
unlinkSync as unlinkSync8
|
|
51404
51504
|
} from "fs";
|
|
51405
51505
|
import { homedir as homedir11 } from "os";
|
|
51406
|
-
import { dirname as dirname17, join as
|
|
51506
|
+
import { dirname as dirname17, join as join31, resolve as resolve9 } from "path";
|
|
51407
51507
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
51408
51508
|
|
|
51409
51509
|
// node_modules/.pnpm/diff@5.2.2/node_modules/diff/lib/index.mjs
|
|
@@ -51573,7 +51673,7 @@ Diff.prototype = {
|
|
|
51573
51673
|
tokenize: function tokenize(value) {
|
|
51574
51674
|
return value.split("");
|
|
51575
51675
|
},
|
|
51576
|
-
join: function
|
|
51676
|
+
join: function join29(chars) {
|
|
51577
51677
|
return chars.join("");
|
|
51578
51678
|
}
|
|
51579
51679
|
};
|
|
@@ -51915,10 +52015,10 @@ import {
|
|
|
51915
52015
|
closeSync as closeSync7,
|
|
51916
52016
|
existsSync as existsSync22,
|
|
51917
52017
|
fstatSync as fstatSync3,
|
|
51918
|
-
lstatSync as
|
|
52018
|
+
lstatSync as lstatSync8,
|
|
51919
52019
|
mkdirSync as mkdirSync15,
|
|
51920
52020
|
openSync as openSync7,
|
|
51921
|
-
readFileSync as
|
|
52021
|
+
readFileSync as readFileSync22,
|
|
51922
52022
|
readSync as readSync3,
|
|
51923
52023
|
readdirSync as readdirSync8,
|
|
51924
52024
|
realpathSync as realpathSync5,
|
|
@@ -51926,15 +52026,15 @@ import {
|
|
|
51926
52026
|
rmdirSync as rmdirSync2
|
|
51927
52027
|
} from "fs";
|
|
51928
52028
|
import { homedir as homedir10 } from "os";
|
|
51929
|
-
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";
|
|
51930
52030
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
51931
52031
|
var __dirname4 = dirname16(fileURLToPath4(import.meta.url));
|
|
51932
52032
|
var PLUGIN_DESCRIPTION = "Primitive decision-graph guidance for the prim CLI \u2014 a model-invoked skill installed by prim skill install.";
|
|
51933
52033
|
var MAX_MANIFEST_BYTES2 = 64 * 1024;
|
|
51934
52034
|
var MAX_SKILL_BYTES = 1024 * 1024;
|
|
51935
52035
|
function pluginDirFor(cwd, scope) {
|
|
51936
|
-
const base = scope === "user" ?
|
|
51937
|
-
return
|
|
52036
|
+
const base = scope === "user" ? join30(homedir10(), ".claude") : join30(gitToplevel(cwd) ?? cwd, ".claude");
|
|
52037
|
+
return join30(base, "skills", "prim");
|
|
51938
52038
|
}
|
|
51939
52039
|
function resolvePluginDir(cwd, scope) {
|
|
51940
52040
|
if (scope && scope !== "user" && scope !== "project") {
|
|
@@ -51947,7 +52047,7 @@ function packageVersion2() {
|
|
|
51947
52047
|
let dir = __dirname4;
|
|
51948
52048
|
while (dir !== dirname16(dir)) {
|
|
51949
52049
|
const p = resolve8(dir, "package.json");
|
|
51950
|
-
if (existsSync22(p)) return JSON.parse(
|
|
52050
|
+
if (existsSync22(p)) return JSON.parse(readFileSync22(p, "utf-8")).version;
|
|
51951
52051
|
dir = dirname16(dir);
|
|
51952
52052
|
}
|
|
51953
52053
|
return "0.0.0";
|
|
@@ -51966,8 +52066,8 @@ function removeDirIfEmpty(dir) {
|
|
|
51966
52066
|
}
|
|
51967
52067
|
function pluginPaths(dir) {
|
|
51968
52068
|
return {
|
|
51969
|
-
manifestPath:
|
|
51970
|
-
skillPath:
|
|
52069
|
+
manifestPath: join30(dir, ".claude-plugin", "plugin.json"),
|
|
52070
|
+
skillPath: join30(dir, "SKILL.md")
|
|
51971
52071
|
};
|
|
51972
52072
|
}
|
|
51973
52073
|
function installClaudePlugin(cwd, opts) {
|
|
@@ -51975,8 +52075,8 @@ function installClaudePlugin(cwd, opts) {
|
|
|
51975
52075
|
if (dir === null) return 1;
|
|
51976
52076
|
const { manifestPath, skillPath } = pluginPaths(dir);
|
|
51977
52077
|
const { manifest, skill } = renderClaudePlugin();
|
|
51978
|
-
const manifestCurrent = existsSync22(manifestPath) ?
|
|
51979
|
-
const skillCurrent = existsSync22(skillPath) ?
|
|
52078
|
+
const manifestCurrent = existsSync22(manifestPath) ? readFileSync22(manifestPath, "utf-8") : null;
|
|
52079
|
+
const skillCurrent = existsSync22(skillPath) ? readFileSync22(skillPath, "utf-8") : null;
|
|
51980
52080
|
if (manifestCurrent === manifest && skillCurrent === skill) {
|
|
51981
52081
|
console.log("No changes \u2014 prim skill plugin already up to date.");
|
|
51982
52082
|
return 0;
|
|
@@ -51985,9 +52085,9 @@ function installClaudePlugin(cwd, opts) {
|
|
|
51985
52085
|
console.log(`Would write plugin to ${dir} (.claude-plugin/plugin.json + SKILL.md)`);
|
|
51986
52086
|
return 0;
|
|
51987
52087
|
}
|
|
51988
|
-
mkdirSync15(
|
|
51989
|
-
|
|
51990
|
-
|
|
52088
|
+
mkdirSync15(join30(dir, ".claude-plugin"), { recursive: true });
|
|
52089
|
+
atomicWrite5(manifestPath, manifest);
|
|
52090
|
+
atomicWrite5(skillPath, skill);
|
|
51991
52091
|
console.log(`Installed prim skill plugin at ${dir}`);
|
|
51992
52092
|
console.log("Restart Claude Code or run /reload-plugins to load it.");
|
|
51993
52093
|
if (opts.scope !== "user") {
|
|
@@ -52005,7 +52105,7 @@ function uninstallClaudePlugin(cwd, opts) {
|
|
|
52005
52105
|
}
|
|
52006
52106
|
rmSync9(manifestPath, { force: true });
|
|
52007
52107
|
rmSync9(skillPath, { force: true });
|
|
52008
|
-
removeDirIfEmpty(
|
|
52108
|
+
removeDirIfEmpty(join30(dir, ".claude-plugin"));
|
|
52009
52109
|
removeDirIfEmpty(dir);
|
|
52010
52110
|
console.log(`Removed prim skill plugin from ${dir}`);
|
|
52011
52111
|
return 0;
|
|
@@ -52056,19 +52156,19 @@ function sha2563(content) {
|
|
|
52056
52156
|
}
|
|
52057
52157
|
function cursorSkillDirectory(cwd, scope) {
|
|
52058
52158
|
const base = scope === "user" ? cursorConfigDirectory() : gitToplevel(cwd) ?? cwd;
|
|
52059
|
-
return
|
|
52159
|
+
return join31(base, scope === "user" ? "skills" : ".cursor/skills", "prim");
|
|
52060
52160
|
}
|
|
52061
52161
|
function cursorSkillPaths(cwd, scope) {
|
|
52062
52162
|
const directory = cursorSkillDirectory(cwd, scope);
|
|
52063
52163
|
return {
|
|
52064
52164
|
directory,
|
|
52065
|
-
skill:
|
|
52066
|
-
manifest:
|
|
52165
|
+
skill: join31(directory, "SKILL.md"),
|
|
52166
|
+
manifest: join31(directory, CURSOR_SKILL_MANIFEST)
|
|
52067
52167
|
};
|
|
52068
52168
|
}
|
|
52069
52169
|
function readCursorSkillManifest(path9) {
|
|
52070
52170
|
try {
|
|
52071
|
-
const value = JSON.parse(
|
|
52171
|
+
const value = JSON.parse(readFileSync23(path9, "utf8"));
|
|
52072
52172
|
if (!value || typeof value !== "object" || Array.isArray(value)) return;
|
|
52073
52173
|
const record3 = value;
|
|
52074
52174
|
if (record3.version !== 1 || record3.owner !== CURSOR_SKILL_OWNER || typeof record3.contentSha256 !== "string" || !/^[0-9a-f]{64}$/u.test(record3.contentSha256)) {
|
|
@@ -52082,7 +52182,7 @@ function readCursorSkillManifest(path9) {
|
|
|
52082
52182
|
function cursorSkillStatus(cwd, scope) {
|
|
52083
52183
|
const paths = cursorSkillPaths(cwd, scope);
|
|
52084
52184
|
const manifest = readCursorSkillManifest(paths.manifest);
|
|
52085
|
-
const content = existsSync23(paths.skill) ?
|
|
52185
|
+
const content = existsSync23(paths.skill) ? readFileSync23(paths.skill, "utf8") : void 0;
|
|
52086
52186
|
const owned = manifest !== void 0;
|
|
52087
52187
|
const installed = owned && content !== void 0 && sha2563(content) === manifest.contentSha256;
|
|
52088
52188
|
return {
|
|
@@ -52112,12 +52212,12 @@ function installCursorSkill(cwd, opts) {
|
|
|
52112
52212
|
owner: CURSOR_SKILL_OWNER,
|
|
52113
52213
|
contentSha256: sha2563(content)
|
|
52114
52214
|
};
|
|
52115
|
-
if (status.installed &&
|
|
52215
|
+
if (status.installed && readFileSync23(paths.skill, "utf8") === content) {
|
|
52116
52216
|
console.log(`No changes \u2014 Cursor skill already up to date at ${paths.skill}`);
|
|
52117
52217
|
return 0;
|
|
52118
52218
|
}
|
|
52119
52219
|
if (opts.dryRun) {
|
|
52120
|
-
const existing = skillExists ?
|
|
52220
|
+
const existing = skillExists ? readFileSync23(paths.skill, "utf8") : "";
|
|
52121
52221
|
process.stdout.write(createPatch(paths.skill, existing, content, "current", "proposed"));
|
|
52122
52222
|
return 0;
|
|
52123
52223
|
}
|
|
@@ -52148,10 +52248,10 @@ function uninstallCursorSkill(cwd, scope) {
|
|
|
52148
52248
|
return 0;
|
|
52149
52249
|
}
|
|
52150
52250
|
function userTargetFor(agent) {
|
|
52151
|
-
if (agent === "claude") return
|
|
52152
|
-
if (agent === "codex") return
|
|
52251
|
+
if (agent === "claude") return join31(homedir11(), ".claude", "CLAUDE.md");
|
|
52252
|
+
if (agent === "codex") return join31(homedir11(), ".codex", "AGENTS.md");
|
|
52153
52253
|
if (agent === "hermes") {
|
|
52154
|
-
return
|
|
52254
|
+
return join31(process.env.HERMES_HOME ?? join31(homedir11(), ".hermes"), ".hermes.md");
|
|
52155
52255
|
}
|
|
52156
52256
|
return null;
|
|
52157
52257
|
}
|
|
@@ -52159,7 +52259,7 @@ function loadSkill() {
|
|
|
52159
52259
|
let dir = __dirname5;
|
|
52160
52260
|
while (dir !== dirname17(dir)) {
|
|
52161
52261
|
const p = resolve9(dir, "SKILL.md");
|
|
52162
|
-
if (existsSync23(p)) return
|
|
52262
|
+
if (existsSync23(p)) return readFileSync23(p, "utf-8");
|
|
52163
52263
|
dir = dirname17(dir);
|
|
52164
52264
|
}
|
|
52165
52265
|
throw new Error("SKILL.md not found in package");
|
|
@@ -52191,7 +52291,7 @@ function removeBlock(existing) {
|
|
|
52191
52291
|
const out = existing.slice(0, b) + existing.slice(e + SKILL_END.length);
|
|
52192
52292
|
return out.replace(/(\r?\n){2,}$/, "$1");
|
|
52193
52293
|
}
|
|
52194
|
-
function
|
|
52294
|
+
function atomicWrite5(target, content) {
|
|
52195
52295
|
atomicWriteFile(target, content);
|
|
52196
52296
|
}
|
|
52197
52297
|
function resolveTarget(cwd, opts) {
|
|
@@ -52231,7 +52331,7 @@ function runInstall(cwd, opts) {
|
|
|
52231
52331
|
}
|
|
52232
52332
|
const target = resolveTarget(cwd, opts);
|
|
52233
52333
|
if (target === null) return 1;
|
|
52234
|
-
const existing = existsSync23(target) ?
|
|
52334
|
+
const existing = existsSync23(target) ? readFileSync23(target, "utf-8") : "";
|
|
52235
52335
|
const eol = existing ? detectNewline(existing) : "\n";
|
|
52236
52336
|
const block = composeBlock(loadSkill(), eol);
|
|
52237
52337
|
const next = applyBlock(existing, block, eol);
|
|
@@ -52243,7 +52343,7 @@ function runInstall(cwd, opts) {
|
|
|
52243
52343
|
process.stdout.write(createPatch(target, existing, next, "current", "proposed"));
|
|
52244
52344
|
return 0;
|
|
52245
52345
|
}
|
|
52246
|
-
|
|
52346
|
+
atomicWrite5(target, next);
|
|
52247
52347
|
console.log(`Wrote ${Buffer.byteLength(next)} bytes to ${target}`);
|
|
52248
52348
|
return 0;
|
|
52249
52349
|
}
|
|
@@ -52259,13 +52359,13 @@ function runUninstall(cwd, opts) {
|
|
|
52259
52359
|
console.log(`Skill block not present at ${target}`);
|
|
52260
52360
|
return 0;
|
|
52261
52361
|
}
|
|
52262
|
-
const existing =
|
|
52362
|
+
const existing = readFileSync23(target, "utf-8");
|
|
52263
52363
|
const next = removeBlock(existing);
|
|
52264
52364
|
if (next === null) {
|
|
52265
52365
|
console.log(`Skill block not present at ${target}`);
|
|
52266
52366
|
return 0;
|
|
52267
52367
|
}
|
|
52268
|
-
|
|
52368
|
+
atomicWrite5(target, next);
|
|
52269
52369
|
console.log(`Removed skill block from ${target}`);
|
|
52270
52370
|
return 0;
|
|
52271
52371
|
}
|
|
@@ -52286,7 +52386,7 @@ function runStatus(cwd, opts) {
|
|
|
52286
52386
|
const fileExists = existsSync23(target);
|
|
52287
52387
|
let installed = false;
|
|
52288
52388
|
if (fileExists) {
|
|
52289
|
-
const content =
|
|
52389
|
+
const content = readFileSync23(target, "utf-8");
|
|
52290
52390
|
installed = content.includes(SKILL_BEGIN) && content.includes(SKILL_END);
|
|
52291
52391
|
}
|
|
52292
52392
|
if (opts.json) {
|
|
@@ -52323,7 +52423,7 @@ function registerSkillCommands(program3) {
|
|
|
52323
52423
|
}
|
|
52324
52424
|
|
|
52325
52425
|
// src/commands/statusline.ts
|
|
52326
|
-
import { readFileSync as
|
|
52426
|
+
import { readFileSync as readFileSync24 } from "fs";
|
|
52327
52427
|
import { dirname as dirname18, resolve as resolve10 } from "path";
|
|
52328
52428
|
import { fileURLToPath as fileURLToPath6 } from "url";
|
|
52329
52429
|
var STATUSLINE_TIMEOUT_MS = 200;
|
|
@@ -52339,7 +52439,7 @@ function readPackageVersion() {
|
|
|
52339
52439
|
];
|
|
52340
52440
|
for (const path9 of candidates) {
|
|
52341
52441
|
try {
|
|
52342
|
-
const pkg2 = JSON.parse(
|
|
52442
|
+
const pkg2 = JSON.parse(readFileSync24(path9, "utf-8"));
|
|
52343
52443
|
if (pkg2.version) {
|
|
52344
52444
|
return pkg2.version;
|
|
52345
52445
|
}
|
|
@@ -52883,13 +52983,13 @@ function healDaemonDrift(options = {}) {
|
|
|
52883
52983
|
|
|
52884
52984
|
// src/lib/background-flush.ts
|
|
52885
52985
|
import { spawn as spawn5 } from "child_process";
|
|
52886
|
-
import { readFileSync as
|
|
52986
|
+
import { readFileSync as readFileSync25 } from "fs";
|
|
52887
52987
|
|
|
52888
52988
|
// src/daemon/health.ts
|
|
52889
|
-
import { chmodSync as
|
|
52890
|
-
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";
|
|
52891
52991
|
var HEARTBEAT_FRESH_MS = 9e4;
|
|
52892
|
-
var DAEMON_HEALTH_PATH =
|
|
52992
|
+
var DAEMON_HEALTH_PATH = join32(primConfigDirectory(), "daemon-health.json");
|
|
52893
52993
|
|
|
52894
52994
|
// src/lib/background-flush.ts
|
|
52895
52995
|
function record2(value) {
|
|
@@ -52900,7 +53000,7 @@ function daemonOwnsDrain(options = {}) {
|
|
|
52900
53000
|
const expectedVersion = options.expectedVersion === void 0 ? packageVersion() : options.expectedVersion;
|
|
52901
53001
|
if (!expectedVersion) return false;
|
|
52902
53002
|
const health = record2(
|
|
52903
|
-
JSON.parse(
|
|
53003
|
+
JSON.parse(readFileSync25(options.healthPath ?? DAEMON_HEALTH_PATH, "utf8"))
|
|
52904
53004
|
);
|
|
52905
53005
|
const heartbeat = record2(health?.heartbeat);
|
|
52906
53006
|
const ingestion = record2(health?.ingestion);
|
|
@@ -53017,7 +53117,7 @@ function runStartupBackgroundWork(argv, env4, work) {
|
|
|
53017
53117
|
|
|
53018
53118
|
// src/index.ts
|
|
53019
53119
|
var __dirname6 = dirname20(fileURLToPath7(import.meta.url));
|
|
53020
|
-
var pkg = JSON.parse(
|
|
53120
|
+
var pkg = JSON.parse(readFileSync26(resolve11(__dirname6, "../package.json"), "utf-8"));
|
|
53021
53121
|
runStartupBackgroundWork(process.argv.slice(2), process.env, {
|
|
53022
53122
|
notify: () => updateNotifier({ pkg }).notify(),
|
|
53023
53123
|
flush: () => startBackgroundFlush(),
|