@primitive.ai/prim 0.1.0-alpha.106 → 0.1.0-alpha.107

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.
@@ -53,7 +53,7 @@ var require_ucs2length = __commonJS({
53
53
 
54
54
  // src/hooks/post-tool-use.ts
55
55
  import { readFileSync as readFileSync17 } from "fs";
56
- import { dirname as dirname12, join as join19 } from "path";
56
+ import { dirname as dirname12, join as join20 } from "path";
57
57
  import { fileURLToPath as fileURLToPath2 } from "url";
58
58
 
59
59
  // src/binding.ts
@@ -436,12 +436,445 @@ function resolveOrg(args) {
436
436
  }
437
437
 
438
438
  // src/demo/isolation.ts
439
- import { existsSync as existsSync4 } from "fs";
439
+ import { existsSync as existsSync7 } from "fs";
440
+
441
+ // src/lib/bin-path.ts
442
+ import { existsSync as existsSync2, readFileSync as readFileSync3 } from "fs";
443
+ import { dirname as dirname2, isAbsolute as isAbsolute2, join as join4 } from "path";
444
+ import { fileURLToPath } from "url";
445
+ var PKG_NAME = "@primitive.ai/prim";
446
+ var ROOT_WALK_LIMIT = 6;
447
+ var STABLE_HOOK_LAUNCHER_NAME = "prim-hook-launcher-v1";
448
+ var resolvedRoot;
449
+ function locateRoot() {
450
+ if (resolvedRoot !== void 0) {
451
+ return resolvedRoot;
452
+ }
453
+ let dir = dirname2(fileURLToPath(import.meta.url));
454
+ for (let depth = 0; depth < ROOT_WALK_LIMIT; depth++) {
455
+ const manifestPath = join4(dir, "package.json");
456
+ if (existsSync2(manifestPath)) {
457
+ try {
458
+ const manifest = JSON.parse(readFileSync3(manifestPath, "utf-8"));
459
+ if (manifest.name === PKG_NAME && manifest.bin) {
460
+ resolvedRoot = { dir, version: manifest.version, bin: manifest.bin };
461
+ return resolvedRoot;
462
+ }
463
+ } catch {
464
+ }
465
+ }
466
+ const parent = dirname2(dir);
467
+ if (parent === dir) {
468
+ break;
469
+ }
470
+ dir = parent;
471
+ }
472
+ resolvedRoot = null;
473
+ return resolvedRoot;
474
+ }
475
+ function packageVersion() {
476
+ return locateRoot()?.version ?? null;
477
+ }
478
+ function shellQuote(value) {
479
+ return `'${value.replaceAll("'", `'"'"'`)}'`;
480
+ }
481
+ var STABLE_HOOK_ARGUMENTS_RE = /^[-A-Za-z0-9_ ]*$/u;
482
+ var STABLE_HOOK_BIN_RE = /^[A-Za-z0-9][A-Za-z0-9-]*$/u;
483
+ var PRIM_CONFIG_SHELL_RESOLVER = [
484
+ 'prim_absolute() { case "$1" in [/]* ) ;; *) return 1 ;; esac; case "$1" in [[:space:]]*|*[[:space:]]|*[/][/]*|*[/].[/]*|*[/]..[/]*|*[/].|*[/]..|?*[/]) return 1 ;; esac; }; ',
485
+ 'prim_config=${PRIM_CONFIG_DIR:-}; if ! prim_absolute "$prim_config"; then prim_config=${XDG_CONFIG_HOME:-}; if prim_absolute "$prim_config"; then ',
486
+ 'case "$prim_config" in /) prim_config=/prim ;; *) prim_config="$prim_config/prim" ;; esac; ',
487
+ '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; ',
488
+ "fi; fi; "
489
+ ].join("");
490
+ function stableHookCommand(bin, args = "") {
491
+ if (!STABLE_HOOK_BIN_RE.test(bin) || !STABLE_HOOK_ARGUMENTS_RE.test(args)) {
492
+ throw new Error("invalid stable hook command");
493
+ }
494
+ const resolver = [
495
+ // #242 and earlier identify managed commands by this package marker. Keep
496
+ // it as inert data during the rolling window so an older uninstall or
497
+ // reinstall can remove the stable entry without invoking npm or PATH.
498
+ `prim_legacy_reader='-p ${PKG_NAME}@stable prim-shim.sh ${bin} '; `,
499
+ PRIM_CONFIG_SHELL_RESOLVER,
500
+ `case "$prim_config" in /) prim_launcher=/${STABLE_HOOK_LAUNCHER_NAME} ;; *) prim_launcher="$prim_config/${STABLE_HOOK_LAUNCHER_NAME}" ;; esac; `,
501
+ 'exec "$prim_launcher" "$@"'
502
+ ].join("");
503
+ const suffix = args ? ` ${args}` : "";
504
+ return `/bin/sh -c ${shellQuote(resolver)} ${STABLE_HOOK_LAUNCHER_NAME} ${bin}${suffix}`;
505
+ }
506
+ function detachedHookShimCommand(bin, args = "") {
507
+ return `payload=$(cat); { trap '' HUP; printf '%s' "$payload" | { ${stableHookCommand(bin, args)}; }; } </dev/null >/dev/null 2>&1 &`;
508
+ }
509
+
510
+ // src/demo/diagnostics.ts
511
+ import { existsSync as existsSync6 } from "fs";
512
+ import { join as join8 } from "path";
513
+
514
+ // src/lib/hook-runtime.ts
515
+ import { createHash as createHash2, randomBytes as randomBytes2 } from "crypto";
516
+ import {
517
+ constants as constants2,
518
+ accessSync,
519
+ chmodSync,
520
+ copyFileSync,
521
+ existsSync as existsSync4,
522
+ lstatSync,
523
+ mkdirSync as mkdirSync3,
524
+ mkdtempSync,
525
+ readFileSync as readFileSync5,
526
+ readdirSync,
527
+ realpathSync,
528
+ renameSync as renameSync2,
529
+ rmSync as rmSync3,
530
+ statSync as statSync2,
531
+ utimesSync,
532
+ writeFileSync as writeFileSync3
533
+ } from "fs";
534
+ import { delimiter, dirname as dirname5, isAbsolute as isAbsolute3, join as join6, resolve } from "path";
535
+
536
+ // src/lib/atomic-file.ts
537
+ import { randomUUID } from "crypto";
538
+ import {
539
+ constants,
540
+ closeSync,
541
+ fchmodSync,
542
+ fsyncSync,
543
+ mkdirSync,
544
+ openSync,
545
+ renameSync,
546
+ rmSync,
547
+ writeFileSync
548
+ } from "fs";
549
+ import { dirname as dirname3 } from "path";
550
+ var DEFAULT_FILE_MODE = 438;
551
+ function syncDirectory(path) {
552
+ const fd = openSync(path, constants.O_RDONLY);
553
+ try {
554
+ fsyncSync(fd);
555
+ } finally {
556
+ closeSync(fd);
557
+ }
558
+ }
559
+ function syncCreatedParentChain(firstCreatedParent, parent) {
560
+ const createdDirectories = [];
561
+ let current = parent;
562
+ while (current !== firstCreatedParent) {
563
+ createdDirectories.push(current);
564
+ const next = dirname3(current);
565
+ if (next === current) {
566
+ throw new Error("recursive mkdir returned a path outside the target parent chain");
567
+ }
568
+ current = next;
569
+ }
570
+ createdDirectories.push(firstCreatedParent);
571
+ syncDirectory(dirname3(firstCreatedParent));
572
+ for (const directory of createdDirectories.reverse().slice(0, -1)) {
573
+ syncDirectory(directory);
574
+ }
575
+ }
576
+ function ensureDurableDirectory(path, mode) {
577
+ const firstCreatedParent = mkdirSync(path, { recursive: true, mode });
578
+ if (firstCreatedParent) {
579
+ syncCreatedParentChain(firstCreatedParent, path);
580
+ }
581
+ }
582
+ function atomicWriteFile(target, content, options = {}) {
583
+ const parent = dirname3(target);
584
+ if (options.ensureParent) {
585
+ ensureDurableDirectory(parent);
586
+ }
587
+ const temporaryPath = `${target}.${randomUUID()}.tmp`;
588
+ let temporaryCreated = false;
589
+ try {
590
+ const flags = constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW;
591
+ const fd = openSync(temporaryPath, flags, options.mode ?? DEFAULT_FILE_MODE);
592
+ temporaryCreated = true;
593
+ try {
594
+ if (options.mode !== void 0) fchmodSync(fd, options.mode);
595
+ writeFileSync(fd, content);
596
+ fsyncSync(fd);
597
+ } finally {
598
+ closeSync(fd);
599
+ }
600
+ options.validate?.(temporaryPath);
601
+ renameSync(temporaryPath, target);
602
+ syncDirectory(parent);
603
+ } catch (error) {
604
+ if (temporaryCreated) {
605
+ try {
606
+ rmSync(temporaryPath, { force: true });
607
+ } catch {
608
+ }
609
+ }
610
+ throw error;
611
+ }
612
+ }
613
+
614
+ // src/lib/file-lock.ts
615
+ import { randomBytes } from "crypto";
616
+ import { existsSync as existsSync3, mkdirSync as mkdirSync2, readFileSync as readFileSync4, rmSync as rmSync2, statSync, writeFileSync as writeFileSync2 } from "fs";
617
+ import { dirname as dirname4, join as join5 } from "path";
618
+
619
+ // src/lib/process-liveness.ts
620
+ function processIsAlive(pid, probe = process.kill) {
621
+ if (!Number.isSafeInteger(pid) || pid <= 0) return false;
622
+ try {
623
+ probe(pid, 0);
624
+ return true;
625
+ } catch (error) {
626
+ return error.code === "EPERM";
627
+ }
628
+ }
629
+
630
+ // src/lib/file-lock.ts
631
+ var DEFAULT_TIMEOUT_MS = 3e4;
632
+ var DEFAULT_POLL_MS = 50;
633
+ var DEFAULT_INIT_GRACE_MS = 2e3;
634
+ var DIRECTORY_MODE = 448;
635
+ var FILE_MODE = 384;
636
+ function ownerPath(lockDir) {
637
+ return join5(lockDir, "owner.json");
638
+ }
639
+ function readOwner(lockDir) {
640
+ try {
641
+ const owner = JSON.parse(readFileSync4(ownerPath(lockDir), "utf8"));
642
+ if (!Number.isInteger(owner.pid) || owner.pid <= 0 || typeof owner.nonce !== "string" || typeof owner.createdAt !== "number") {
643
+ return null;
644
+ }
645
+ return owner;
646
+ } catch {
647
+ return null;
648
+ }
649
+ }
650
+ function sameOwner(a, b) {
651
+ return a?.pid === b.pid && a.nonce === b.nonce && a.createdAt === b.createdAt;
652
+ }
653
+ function tryTakeLock(lockDir, now) {
654
+ try {
655
+ mkdirSync2(lockDir, { mode: DIRECTORY_MODE });
656
+ } catch (error) {
657
+ if (error.code === "EEXIST") return null;
658
+ throw error;
659
+ }
660
+ const owner = {
661
+ pid: process.pid,
662
+ nonce: randomBytes(16).toString("hex"),
663
+ createdAt: now
664
+ };
665
+ try {
666
+ writeFileSync2(ownerPath(lockDir), `${JSON.stringify(owner)}
667
+ `, {
668
+ encoding: "utf8",
669
+ mode: FILE_MODE,
670
+ flag: "wx"
671
+ });
672
+ return owner;
673
+ } catch (error) {
674
+ rmSync2(lockDir, { recursive: true, force: true });
675
+ throw error;
676
+ }
677
+ }
678
+ function recoverStaleLock(lockDir, now, alive, initGraceMs) {
679
+ const owner = readOwner(lockDir);
680
+ if (owner) {
681
+ if (alive(owner.pid)) return false;
682
+ if (!sameOwner(readOwner(lockDir), owner)) return false;
683
+ rmSync2(lockDir, { recursive: true, force: true });
684
+ return true;
685
+ }
686
+ try {
687
+ const before = statSync(lockDir).mtimeMs;
688
+ if (now - before < initGraceMs) return false;
689
+ if (readOwner(lockDir)) return false;
690
+ if (statSync(lockDir).mtimeMs !== before) return false;
691
+ rmSync2(lockDir, { recursive: true, force: true });
692
+ return true;
693
+ } catch {
694
+ return true;
695
+ }
696
+ }
697
+ function abortError(signal) {
698
+ if (signal.reason instanceof Error) return signal.reason;
699
+ const error = new Error("The operation was aborted");
700
+ error.name = "AbortError";
701
+ return error;
702
+ }
703
+ function throwIfAborted(signal) {
704
+ if (signal?.aborted) throw abortError(signal);
705
+ }
706
+ async function defaultSleep(ms, signal) {
707
+ if (!signal) {
708
+ await new Promise((resolve7) => setTimeout(resolve7, ms));
709
+ return;
710
+ }
711
+ throwIfAborted(signal);
712
+ await new Promise((resolve7, reject) => {
713
+ const timer = setTimeout(() => {
714
+ signal.removeEventListener("abort", onAbort);
715
+ resolve7();
716
+ }, ms);
717
+ const onAbort = () => {
718
+ clearTimeout(timer);
719
+ reject(abortError(signal));
720
+ };
721
+ signal.addEventListener("abort", onAbort, { once: true });
722
+ });
723
+ }
724
+ var syncSleeper = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT));
725
+ function defaultSleepSync(ms) {
726
+ Atomics.wait(syncSleeper, 0, 0, ms);
727
+ }
728
+ function withFileLockSync(lockDir, operation, options = {}) {
729
+ mkdirSync2(dirname4(lockDir), { recursive: true, mode: DIRECTORY_MODE });
730
+ const nowMs = options.nowMs ?? Date.now;
731
+ const alive = options.processAlive ?? processIsAlive;
732
+ const deadline = nowMs() + (options.timeoutMs ?? DEFAULT_TIMEOUT_MS);
733
+ let owner = null;
734
+ while (!owner) {
735
+ const now = nowMs();
736
+ owner = tryTakeLock(lockDir, now);
737
+ if (owner) break;
738
+ recoverStaleLock(lockDir, now, alive, options.initGraceMs ?? DEFAULT_INIT_GRACE_MS);
739
+ if (now >= deadline) {
740
+ throw new Error(`timed out waiting for file lock ${lockDir}`);
741
+ }
742
+ (options.sleep ?? defaultSleepSync)(options.pollMs ?? DEFAULT_POLL_MS);
743
+ }
744
+ try {
745
+ return operation();
746
+ } finally {
747
+ if (sameOwner(readOwner(lockDir), owner)) {
748
+ rmSync2(lockDir, { recursive: true, force: true });
749
+ }
750
+ }
751
+ }
752
+ async function withFileLock(lockDir, operation, options = {}) {
753
+ mkdirSync2(dirname4(lockDir), { recursive: true, mode: DIRECTORY_MODE });
754
+ const nowMs = options.nowMs ?? Date.now;
755
+ const alive = options.processAlive ?? processIsAlive;
756
+ const deadline = nowMs() + (options.timeoutMs ?? DEFAULT_TIMEOUT_MS);
757
+ let owner = null;
758
+ while (!owner) {
759
+ throwIfAborted(options.signal);
760
+ const now = nowMs();
761
+ owner = tryTakeLock(lockDir, now);
762
+ if (owner) break;
763
+ recoverStaleLock(lockDir, now, alive, options.initGraceMs ?? DEFAULT_INIT_GRACE_MS);
764
+ if (now >= deadline) {
765
+ throw new Error(`timed out waiting for file lock ${lockDir}`);
766
+ }
767
+ if (options.sleep) {
768
+ await options.sleep(options.pollMs ?? DEFAULT_POLL_MS);
769
+ throwIfAborted(options.signal);
770
+ } else {
771
+ await defaultSleep(options.pollMs ?? DEFAULT_POLL_MS, options.signal);
772
+ }
773
+ }
774
+ try {
775
+ throwIfAborted(options.signal);
776
+ return await operation();
777
+ } finally {
778
+ if (sameOwner(readOwner(lockDir), owner)) {
779
+ rmSync2(lockDir, { recursive: true, force: true });
780
+ }
781
+ }
782
+ }
783
+
784
+ // src/lib/git-hook-contract.ts
785
+ var GIT_HOOK_ENTRYPOINT_CONTENT = `#!/bin/sh
786
+ # prim git hook entrypoint v1 \u2014 managed by prim; do not edit.
787
+ # Run by the "# >>> prim <hook> hook >>>" block in a Git hook file. Acts only
788
+ # where prim is active (git config prim.active true) and never fails the hook.
789
+ case "$0" in */*) prim_dir=\${0%/*} ;; *) exit 0 ;; esac
790
+ prim_launcher="$prim_dir/${STABLE_HOOK_LAUNCHER_NAME}"
791
+ [ -x "$prim_launcher" ] || exit 0
792
+ [ "$(git config --get prim.active 2>/dev/null)" = "true" ] || exit 0
793
+ prim_hook=\${1-}
794
+ if [ "$#" -gt 0 ]; then shift; fi
795
+ case "$prim_hook" in
796
+ pre-commit)
797
+ "$prim_launcher" prim-pre-commit "$@" || :
798
+ ;;
799
+ post-commit)
800
+ prim_sha=$(git rev-parse --verify HEAD 2>/dev/null) || exit 0
801
+ case "$prim_sha" in *[!0-9a-f]* | "") exit 0 ;; esac
802
+ case "\${#prim_sha}" in 40 | 64) ;; *) exit 0 ;; esac
803
+ prim_branch=$(git symbolic-ref --quiet --short HEAD 2>/dev/null) || prim_branch=
804
+ prim_observed=$(mktemp "\${TMPDIR:-/tmp}/prim-post-commit-observed.XXXXXXXX" 2>/dev/null) || prim_observed=
805
+ (
806
+ trap '' HUP
807
+ trap 'if [ -n "$prim_observed" ]; then rm -f "$prim_observed"; fi' 0
808
+ PRIM_COMMIT_SHA=$prim_sha PRIM_COMMIT_BRANCH=$prim_branch PRIM_COMMIT_OBSERVED_FILE=$prim_observed "$prim_launcher" prim-post-commit
809
+ ) </dev/null >/dev/null 2>&1 &
810
+ ;;
811
+ post-rewrite)
812
+ case "\${1-}" in amend | rebase) prim_source=$1 ;; *) exit 0 ;; esac
813
+ prim_pairs=$(mktemp "\${TMPDIR:-/tmp}/prim-post-rewrite-pairs.XXXXXXXX" 2>/dev/null) || exit 0
814
+ if ! chmod 600 "$prim_pairs" 2>/dev/null || ! cat >"$prim_pairs"; then
815
+ rm -f "$prim_pairs"
816
+ exit 0
817
+ fi
818
+ prim_branch=$(git symbolic-ref --quiet --short HEAD 2>/dev/null) || prim_branch=
819
+ (
820
+ trap '' HUP
821
+ trap 'rm -f "$prim_pairs"' 0
822
+ PRIM_REWRITE_SOURCE=$prim_source PRIM_REWRITE_BRANCH=$prim_branch PRIM_REWRITE_PAIRS_FILE=$prim_pairs "$prim_launcher" prim-post-rewrite
823
+ ) </dev/null >/dev/null 2>&1 &
824
+ ;;
825
+ esac
826
+ exit 0
827
+ `;
828
+
829
+ // src/lib/hook-runtime.ts
830
+ var RELEASE_PREFIX = "release-";
831
+ var MAX_MANIFEST_BYTES = 64 * 1024;
832
+ var RELEASE_GRACE_MS = 10 * 60 * 1e3;
833
+ var HOOK_RUNTIME_ENTRIES = {
834
+ // SessionStart self-healing resolves this exact CLI entry to run
835
+ // `daemon ensure`; it must travel with the immutable hook release.
836
+ prim: "dist/index.js",
837
+ "prim-hook": "dist/hooks/prim-hook.js",
838
+ "prim-pre-commit": "dist/hooks/pre-commit.js",
839
+ "prim-post-commit": "dist/hooks/post-commit.js",
840
+ "prim-post-rewrite": "dist/hooks/post-rewrite.js",
841
+ "prim-pre-tool-use": "dist/hooks/pre-tool-use.js",
842
+ "prim-post-tool-use": "dist/hooks/post-tool-use.js",
843
+ "prim-session-start": "dist/hooks/session-start.js",
844
+ "prim-session-end": "dist/hooks/session-end.js",
845
+ "prim-daemon-server": "dist/daemon/server.js",
846
+ "prim-statusline": "dist/statusline-main.js"
847
+ };
848
+ var SOURCE_ENTRIES = Object.fromEntries(
849
+ Object.entries(HOOK_RUNTIME_ENTRIES).map(([bin, target]) => [
850
+ bin,
851
+ target.replace(/^dist\//u, "")
852
+ ])
853
+ );
854
+ var STABLE_HOOK_LAUNCHER_CONTENT = `#!/bin/sh
855
+ set -eu
856
+ case "$0" in */*) prim_launcher_dir=\${0%/*} ;; *) exit 78 ;; esac
857
+ IFS= read -r prim_release_name < "$prim_launcher_dir/hook-runtime/current" || exit 69
858
+ case "$prim_release_name" in ${RELEASE_PREFIX}*) ;; *) exit 69 ;; esac
859
+ prim_release_id=\${prim_release_name#${RELEASE_PREFIX}}
860
+ case "$prim_release_id" in *[!0-9a-f]*|"") exit 69 ;; esac
861
+ [ "\${#prim_release_id}" -eq 64 ] || exit 69
862
+ prim_release="$prim_launcher_dir/hook-runtime/releases/$prim_release_name"
863
+ case "\${1-}" in
864
+ ${Object.entries(HOOK_RUNTIME_ENTRIES).map(([bin, entry]) => ` ${bin}) prim_entry="$prim_release/${entry}" ;;`).join("\n")}
865
+ *) exit 64 ;;
866
+ esac
867
+ shift
868
+ IFS= read -r prim_node < "$prim_release/node" || exit 69
869
+ case "$prim_node" in /*) ;; *) exit 69 ;; esac
870
+ [ -x "$prim_node" ] && [ -f "$prim_entry" ] || exit 69
871
+ exec "$prim_node" "$prim_entry" "$@"
872
+ `;
440
873
 
441
874
  // src/demo/state.ts
442
- import { createHash as createHash2, randomUUID as randomUUID2 } from "crypto";
443
- import { existsSync as existsSync3, lstatSync, readFileSync as readFileSync4, readdirSync } from "fs";
444
- import { join as join5, resolve } from "path";
875
+ import { createHash as createHash3, randomUUID as randomUUID2 } from "crypto";
876
+ import { existsSync as existsSync5, lstatSync as lstatSync2, readFileSync as readFileSync6, readdirSync as readdirSync2 } from "fs";
877
+ import { join as join7, resolve as resolve2 } from "path";
445
878
 
446
879
  // src/generated/cli-http-v1.validators.js
447
880
  var import_ucs2length = __toESM(require_ucs2length(), 1);
@@ -19816,290 +20249,42 @@ function validate75(data, { instancePath = "", parentData, parentDataProperty, r
19816
20249
  return false;
19817
20250
  break;
19818
20251
  }
19819
- }
19820
- if (_errs2 === errors) {
19821
- if (data.error !== void 0) {
19822
- let data0 = data.error;
19823
- if (typeof data0 !== "string") {
19824
- validate75.errors = [{ instancePath: instancePath + "/error", schemaPath: "https://api.getprimitive.ai/contracts/cli-http-v1.schema.json#/$defs/WorkosConnectDeviceConfigurationUnavailable/properties/error/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
19825
- return false;
19826
- }
19827
- if ("connect_device_auth_unavailable" !== data0) {
19828
- validate75.errors = [{ instancePath: instancePath + "/error", schemaPath: "https://api.getprimitive.ai/contracts/cli-http-v1.schema.json#/$defs/WorkosConnectDeviceConfigurationUnavailable/properties/error/const", keyword: "const", params: { allowedValue: "connect_device_auth_unavailable" }, message: "must be equal to constant" }];
19829
- return false;
19830
- }
19831
- }
19832
- }
19833
- }
19834
- } else {
19835
- validate75.errors = [{ instancePath, schemaPath: "https://api.getprimitive.ai/contracts/cli-http-v1.schema.json#/$defs/WorkosConnectDeviceConfigurationUnavailable/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
19836
- return false;
19837
- }
19838
- }
19839
- validate75.errors = vErrors;
19840
- return errors === 0;
19841
- }
19842
- validate75.evaluated = { "props": true, "dynamicProps": false, "dynamicItems": false };
19843
-
19844
- // src/lib/atomic-file.ts
19845
- import { randomUUID } from "crypto";
19846
- import {
19847
- constants,
19848
- closeSync,
19849
- fchmodSync,
19850
- fsyncSync,
19851
- mkdirSync,
19852
- openSync,
19853
- renameSync,
19854
- rmSync,
19855
- writeFileSync
19856
- } from "fs";
19857
- import { dirname as dirname2 } from "path";
19858
- var DEFAULT_FILE_MODE = 438;
19859
- function syncDirectory(path) {
19860
- const fd = openSync(path, constants.O_RDONLY);
19861
- try {
19862
- fsyncSync(fd);
19863
- } finally {
19864
- closeSync(fd);
19865
- }
19866
- }
19867
- function syncCreatedParentChain(firstCreatedParent, parent) {
19868
- const createdDirectories = [];
19869
- let current = parent;
19870
- while (current !== firstCreatedParent) {
19871
- createdDirectories.push(current);
19872
- const next = dirname2(current);
19873
- if (next === current) {
19874
- throw new Error("recursive mkdir returned a path outside the target parent chain");
19875
- }
19876
- current = next;
19877
- }
19878
- createdDirectories.push(firstCreatedParent);
19879
- syncDirectory(dirname2(firstCreatedParent));
19880
- for (const directory of createdDirectories.reverse().slice(0, -1)) {
19881
- syncDirectory(directory);
19882
- }
19883
- }
19884
- function ensureDurableDirectory(path, mode) {
19885
- const firstCreatedParent = mkdirSync(path, { recursive: true, mode });
19886
- if (firstCreatedParent) {
19887
- syncCreatedParentChain(firstCreatedParent, path);
19888
- }
19889
- }
19890
- function atomicWriteFile(target, content, options = {}) {
19891
- const parent = dirname2(target);
19892
- if (options.ensureParent) {
19893
- ensureDurableDirectory(parent);
19894
- }
19895
- const temporaryPath = `${target}.${randomUUID()}.tmp`;
19896
- let temporaryCreated = false;
19897
- try {
19898
- const flags = constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW;
19899
- const fd = openSync(temporaryPath, flags, options.mode ?? DEFAULT_FILE_MODE);
19900
- temporaryCreated = true;
19901
- try {
19902
- if (options.mode !== void 0) fchmodSync(fd, options.mode);
19903
- writeFileSync(fd, content);
19904
- fsyncSync(fd);
19905
- } finally {
19906
- closeSync(fd);
19907
- }
19908
- options.validate?.(temporaryPath);
19909
- renameSync(temporaryPath, target);
19910
- syncDirectory(parent);
19911
- } catch (error) {
19912
- if (temporaryCreated) {
19913
- try {
19914
- rmSync(temporaryPath, { force: true });
19915
- } catch {
19916
- }
19917
- }
19918
- throw error;
19919
- }
19920
- }
19921
-
19922
- // src/lib/file-lock.ts
19923
- import { randomBytes } from "crypto";
19924
- import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync3, rmSync as rmSync2, statSync, writeFileSync as writeFileSync2 } from "fs";
19925
- import { dirname as dirname3, join as join4 } from "path";
19926
-
19927
- // src/lib/process-liveness.ts
19928
- function processIsAlive(pid, probe = process.kill) {
19929
- if (!Number.isSafeInteger(pid) || pid <= 0) return false;
19930
- try {
19931
- probe(pid, 0);
19932
- return true;
19933
- } catch (error) {
19934
- return error.code === "EPERM";
19935
- }
19936
- }
19937
-
19938
- // src/lib/file-lock.ts
19939
- var DEFAULT_TIMEOUT_MS = 3e4;
19940
- var DEFAULT_POLL_MS = 50;
19941
- var DEFAULT_INIT_GRACE_MS = 2e3;
19942
- var DIRECTORY_MODE = 448;
19943
- var FILE_MODE = 384;
19944
- function ownerPath(lockDir) {
19945
- return join4(lockDir, "owner.json");
19946
- }
19947
- function readOwner(lockDir) {
19948
- try {
19949
- const owner = JSON.parse(readFileSync3(ownerPath(lockDir), "utf8"));
19950
- if (!Number.isInteger(owner.pid) || owner.pid <= 0 || typeof owner.nonce !== "string" || typeof owner.createdAt !== "number") {
19951
- return null;
19952
- }
19953
- return owner;
19954
- } catch {
19955
- return null;
19956
- }
19957
- }
19958
- function sameOwner(a, b) {
19959
- return a?.pid === b.pid && a.nonce === b.nonce && a.createdAt === b.createdAt;
19960
- }
19961
- function tryTakeLock(lockDir, now) {
19962
- try {
19963
- mkdirSync2(lockDir, { mode: DIRECTORY_MODE });
19964
- } catch (error) {
19965
- if (error.code === "EEXIST") return null;
19966
- throw error;
19967
- }
19968
- const owner = {
19969
- pid: process.pid,
19970
- nonce: randomBytes(16).toString("hex"),
19971
- createdAt: now
19972
- };
19973
- try {
19974
- writeFileSync2(ownerPath(lockDir), `${JSON.stringify(owner)}
19975
- `, {
19976
- encoding: "utf8",
19977
- mode: FILE_MODE,
19978
- flag: "wx"
19979
- });
19980
- return owner;
19981
- } catch (error) {
19982
- rmSync2(lockDir, { recursive: true, force: true });
19983
- throw error;
19984
- }
19985
- }
19986
- function recoverStaleLock(lockDir, now, alive, initGraceMs) {
19987
- const owner = readOwner(lockDir);
19988
- if (owner) {
19989
- if (alive(owner.pid)) return false;
19990
- if (!sameOwner(readOwner(lockDir), owner)) return false;
19991
- rmSync2(lockDir, { recursive: true, force: true });
19992
- return true;
19993
- }
19994
- try {
19995
- const before = statSync(lockDir).mtimeMs;
19996
- if (now - before < initGraceMs) return false;
19997
- if (readOwner(lockDir)) return false;
19998
- if (statSync(lockDir).mtimeMs !== before) return false;
19999
- rmSync2(lockDir, { recursive: true, force: true });
20000
- return true;
20001
- } catch {
20002
- return true;
20003
- }
20004
- }
20005
- function abortError(signal) {
20006
- if (signal.reason instanceof Error) return signal.reason;
20007
- const error = new Error("The operation was aborted");
20008
- error.name = "AbortError";
20009
- return error;
20010
- }
20011
- function throwIfAborted(signal) {
20012
- if (signal?.aborted) throw abortError(signal);
20013
- }
20014
- async function defaultSleep(ms, signal) {
20015
- if (!signal) {
20016
- await new Promise((resolve7) => setTimeout(resolve7, ms));
20017
- return;
20018
- }
20019
- throwIfAborted(signal);
20020
- await new Promise((resolve7, reject) => {
20021
- const timer = setTimeout(() => {
20022
- signal.removeEventListener("abort", onAbort);
20023
- resolve7();
20024
- }, ms);
20025
- const onAbort = () => {
20026
- clearTimeout(timer);
20027
- reject(abortError(signal));
20028
- };
20029
- signal.addEventListener("abort", onAbort, { once: true });
20030
- });
20031
- }
20032
- var syncSleeper = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT));
20033
- function defaultSleepSync(ms) {
20034
- Atomics.wait(syncSleeper, 0, 0, ms);
20035
- }
20036
- function withFileLockSync(lockDir, operation, options = {}) {
20037
- mkdirSync2(dirname3(lockDir), { recursive: true, mode: DIRECTORY_MODE });
20038
- const nowMs = options.nowMs ?? Date.now;
20039
- const alive = options.processAlive ?? processIsAlive;
20040
- const deadline = nowMs() + (options.timeoutMs ?? DEFAULT_TIMEOUT_MS);
20041
- let owner = null;
20042
- while (!owner) {
20043
- const now = nowMs();
20044
- owner = tryTakeLock(lockDir, now);
20045
- if (owner) break;
20046
- recoverStaleLock(lockDir, now, alive, options.initGraceMs ?? DEFAULT_INIT_GRACE_MS);
20047
- if (now >= deadline) {
20048
- throw new Error(`timed out waiting for file lock ${lockDir}`);
20049
- }
20050
- (options.sleep ?? defaultSleepSync)(options.pollMs ?? DEFAULT_POLL_MS);
20051
- }
20052
- try {
20053
- return operation();
20054
- } finally {
20055
- if (sameOwner(readOwner(lockDir), owner)) {
20056
- rmSync2(lockDir, { recursive: true, force: true });
20057
- }
20058
- }
20059
- }
20060
- async function withFileLock(lockDir, operation, options = {}) {
20061
- mkdirSync2(dirname3(lockDir), { recursive: true, mode: DIRECTORY_MODE });
20062
- const nowMs = options.nowMs ?? Date.now;
20063
- const alive = options.processAlive ?? processIsAlive;
20064
- const deadline = nowMs() + (options.timeoutMs ?? DEFAULT_TIMEOUT_MS);
20065
- let owner = null;
20066
- while (!owner) {
20067
- throwIfAborted(options.signal);
20068
- const now = nowMs();
20069
- owner = tryTakeLock(lockDir, now);
20070
- if (owner) break;
20071
- recoverStaleLock(lockDir, now, alive, options.initGraceMs ?? DEFAULT_INIT_GRACE_MS);
20072
- if (now >= deadline) {
20073
- throw new Error(`timed out waiting for file lock ${lockDir}`);
20074
- }
20075
- if (options.sleep) {
20076
- await options.sleep(options.pollMs ?? DEFAULT_POLL_MS);
20077
- throwIfAborted(options.signal);
20252
+ }
20253
+ if (_errs2 === errors) {
20254
+ if (data.error !== void 0) {
20255
+ let data0 = data.error;
20256
+ if (typeof data0 !== "string") {
20257
+ validate75.errors = [{ instancePath: instancePath + "/error", schemaPath: "https://api.getprimitive.ai/contracts/cli-http-v1.schema.json#/$defs/WorkosConnectDeviceConfigurationUnavailable/properties/error/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
20258
+ return false;
20259
+ }
20260
+ if ("connect_device_auth_unavailable" !== data0) {
20261
+ validate75.errors = [{ instancePath: instancePath + "/error", schemaPath: "https://api.getprimitive.ai/contracts/cli-http-v1.schema.json#/$defs/WorkosConnectDeviceConfigurationUnavailable/properties/error/const", keyword: "const", params: { allowedValue: "connect_device_auth_unavailable" }, message: "must be equal to constant" }];
20262
+ return false;
20263
+ }
20264
+ }
20265
+ }
20266
+ }
20078
20267
  } else {
20079
- await defaultSleep(options.pollMs ?? DEFAULT_POLL_MS, options.signal);
20080
- }
20081
- }
20082
- try {
20083
- throwIfAborted(options.signal);
20084
- return await operation();
20085
- } finally {
20086
- if (sameOwner(readOwner(lockDir), owner)) {
20087
- rmSync2(lockDir, { recursive: true, force: true });
20268
+ validate75.errors = [{ instancePath, schemaPath: "https://api.getprimitive.ai/contracts/cli-http-v1.schema.json#/$defs/WorkosConnectDeviceConfigurationUnavailable/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
20269
+ return false;
20088
20270
  }
20089
20271
  }
20272
+ validate75.errors = vErrors;
20273
+ return errors === 0;
20090
20274
  }
20275
+ validate75.evaluated = { "props": true, "dynamicProps": false, "dynamicItems": false };
20091
20276
 
20092
20277
  // src/demo/state.ts
20093
20278
  var RUN_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/u;
20094
- var demoDirectory = () => join5(primConfigDirectory(), "demo");
20279
+ var demoDirectory = () => join7(primConfigDirectory(), "demo");
20095
20280
  var runPath = (id) => {
20096
20281
  if (!RUN_ID.test(id)) throw new Error("invalid demo run ID");
20097
- return join5(demoDirectory(), "runs", `${id}.json`);
20282
+ return join7(demoDirectory(), "runs", `${id}.json`);
20098
20283
  };
20099
20284
  function readDemoJson(path) {
20100
- const stat = lstatSync(path);
20285
+ const stat = lstatSync2(path);
20101
20286
  if (!stat.isFile() || stat.size > 16384) throw new Error(`invalid demo state: ${path}`);
20102
- return JSON.parse(readFileSync4(path, "utf8"));
20287
+ return JSON.parse(readFileSync6(path, "utf8"));
20103
20288
  }
20104
20289
  function saveDemoJson(path, value) {
20105
20290
  atomicWriteFile(path, `${JSON.stringify(value)}
@@ -20136,16 +20321,16 @@ function demoCommand(run, action, choice, reason) {
20136
20321
  ].map(quote).join(" ");
20137
20322
  }
20138
20323
  function sessionKey(agent, session) {
20139
- return createHash2("sha256").update(`${agent}\0${session}`).digest("hex");
20324
+ return createHash3("sha256").update(`${agent}\0${session}`).digest("hex");
20140
20325
  }
20141
20326
  function exclusionPath(key) {
20142
20327
  if (!/^[0-9a-f]{64}$/u.test(key)) throw new Error("invalid demo session identity");
20143
- return join5(demoDirectory(), "excluded-sessions", `${key}.json`);
20328
+ return join7(demoDirectory(), "excluded-sessions", `${key}.json`);
20144
20329
  }
20145
20330
  function sessionExcluded(agent, session) {
20146
20331
  if (typeof session !== "string" || !session) return false;
20147
20332
  const path = exclusionPath(sessionKey(agent, session));
20148
- if (!existsSync3(path)) return false;
20333
+ if (!existsSync5(path)) return false;
20149
20334
  const record = readDemoJson(path);
20150
20335
  if (typeof record.runId !== "string" || !RUN_ID.test(record.runId)) {
20151
20336
  throw new Error("invalid demo capture exclusion");
@@ -20178,42 +20363,86 @@ function demoArgv(command) {
20178
20363
  }
20179
20364
  }
20180
20365
 
20366
+ // src/demo/diagnostics.ts
20367
+ var observationPath = (id) => join8(demoDirectory(), "observations", `${id}.json`);
20368
+ function observeRun(id, observation) {
20369
+ try {
20370
+ saveDemoJson(observationPath(id), observation);
20371
+ } catch {
20372
+ process.stderr.write(
20373
+ "[prim] demo isolation diagnostic could not be saved; check access to Primitive's configuration directory.\n"
20374
+ );
20375
+ }
20376
+ }
20377
+
20181
20378
  // src/demo/isolation.ts
20182
20379
  function observeDemoInvocation(envelope, agent, checkExclusion = true) {
20183
20380
  const session = typeof envelope.session_id === "string" && envelope.session_id ? envelope.session_id : agent === "hermes" ? envelope.extra?.session_key : void 0;
20184
20381
  let invocation = false;
20185
- if (envelope.hook_event_name === "PreToolUse" && typeof session === "string" && session) {
20382
+ if (envelope.hook_event_name === "PreToolUse") {
20186
20383
  const tool = agent === "cursor" ? "Shell" : agent === "hermes" ? "terminal" : "Bash";
20187
20384
  const input = envelope.tool_input;
20188
- const command = input?.command;
20189
- if (envelope.tool_name === tool && typeof command === "string" && command.length < 8192) {
20385
+ const command = input?.command ?? input?.cmd;
20386
+ if (typeof command === "string" && command.length < 8192) {
20190
20387
  const argv = demoArgv(command);
20191
- const id = argv?.[4];
20192
- if (id && RUN_ID.test(id) && existsSync4(runPath(id))) {
20193
- invocation = lockRun(id, (run) => {
20194
- const action = argv?.[3];
20195
- const choice = argv?.[6];
20196
- const reason = argv?.[8];
20197
- const recognized = ["start", "attempt", "resolve", "status", "skip"].includes(action);
20198
- const validChoice = action !== "resolve" || choice === "adhere" || choice === "supersede" && typeof reason === "string" && reason.trim().length > 0 && reason.length <= 500;
20199
- const match = recognized && validChoice && demoCommand(run, action, choice, reason) === command;
20200
- if (run.terminal || !match) {
20201
- return false;
20202
- }
20203
- if (action === "skip") return true;
20204
- const key = sessionKey(agent, session);
20205
- if (run.agent && run.agent !== agent || run.binding && run.binding !== key) {
20206
- run.acknowledgment = void 0;
20207
- saveRun(run);
20208
- return false;
20209
- }
20210
- saveDemoJson(exclusionPath(key), { runId: run.id });
20211
- run.binding = key;
20212
- run.agent = agent;
20213
- run.acknowledgment = { command, at: Date.now() };
20214
- saveRun(run);
20215
- return true;
20388
+ const id = argv?.[4] ?? command.match(/\x27([0-9a-f-]{36})\x27/u)?.[1];
20389
+ if (id && RUN_ID.test(id) && existsSync7(runPath(id))) {
20390
+ const identity = typeof session === "string" && session ? sessionKey(agent, session) : void 0;
20391
+ const observed = (result, errorCode2) => observeRun(id, {
20392
+ at: Date.now(),
20393
+ agent,
20394
+ runtimeVersion: packageVersion() ?? void 0,
20395
+ session: identity,
20396
+ result,
20397
+ ...errorCode2 ? { errorCode: errorCode2 } : {}
20216
20398
  });
20399
+ const action = argv?.[3];
20400
+ const choice = argv?.[6];
20401
+ const reason = argv?.[8];
20402
+ const recognized = ["start", "attempt", "resolve", "status", "skip"].includes(action);
20403
+ const validChoice = action !== "resolve" || choice === "adhere" || choice === "supersede" && typeof reason === "string" && reason.trim().length > 0 && reason.length <= 500;
20404
+ const matches = (run) => !run.terminal && recognized && validChoice && demoCommand(run, action, choice, reason) === command;
20405
+ let candidate;
20406
+ try {
20407
+ candidate = readRun(id);
20408
+ } catch {
20409
+ }
20410
+ if (envelope.tool_name !== tool || typeof input?.command !== "string") {
20411
+ observed("tool-mismatch");
20412
+ } else if (!candidate || !matches(candidate)) {
20413
+ observed("command-mismatch");
20414
+ } else
20415
+ try {
20416
+ invocation = lockRun(id, (run) => {
20417
+ if (!matches(run)) {
20418
+ observed("command-mismatch");
20419
+ return false;
20420
+ }
20421
+ if (action === "skip") return true;
20422
+ if (!identity) {
20423
+ observed("session-missing");
20424
+ return false;
20425
+ }
20426
+ const key = identity;
20427
+ if (run.agent && run.agent !== agent || run.binding && run.binding !== key) {
20428
+ observed("session-mismatch");
20429
+ run.acknowledgment = void 0;
20430
+ saveRun(run);
20431
+ return false;
20432
+ }
20433
+ saveDemoJson(exclusionPath(key), { runId: run.id });
20434
+ run.binding = key;
20435
+ run.agent = agent;
20436
+ run.acknowledgment = { command, at: Date.now() };
20437
+ saveRun(run);
20438
+ observed("acknowledged");
20439
+ return true;
20440
+ });
20441
+ } catch (error) {
20442
+ const code = error.code;
20443
+ observed("write-failed", code && /^[A-Z0-9_]{1,32}$/u.test(code) ? code : void 0);
20444
+ throw error;
20445
+ }
20217
20446
  }
20218
20447
  }
20219
20448
  }
@@ -20222,15 +20451,15 @@ function observeDemoInvocation(envelope, agent, checkExclusion = true) {
20222
20451
 
20223
20452
  // src/lib/activation.ts
20224
20453
  import { execFileSync as execFileSync2 } from "child_process";
20225
- import { existsSync as existsSync5, readFileSync as readFileSync5 } from "fs";
20454
+ import { existsSync as existsSync8, readFileSync as readFileSync7 } from "fs";
20226
20455
  import { homedir as homedir2 } from "os";
20227
- import { join as join6 } from "path";
20456
+ import { join as join9 } from "path";
20228
20457
 
20229
20458
  // src/lib/git.ts
20230
20459
  import { execFileSync } from "child_process";
20231
- import { createHash as createHash3 } from "crypto";
20232
- import { lstatSync as lstatSync2, realpathSync } from "fs";
20233
- import { basename, dirname as dirname4, isAbsolute as isAbsolute2, relative, resolve as resolve2, sep } from "path";
20460
+ import { createHash as createHash4 } from "crypto";
20461
+ import { lstatSync as lstatSync3, realpathSync as realpathSync2 } from "fs";
20462
+ import { basename, dirname as dirname6, isAbsolute as isAbsolute4, relative, resolve as resolve3, sep } from "path";
20234
20463
  var GIT_TIMEOUT_MS = 1e3;
20235
20464
  var GITHUB_OWNER_PATTERN = /^(?![A-Za-z0-9-]*--)[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/u;
20236
20465
  var GITHUB_REPOSITORY_PATTERN = /^[A-Za-z0-9._-]{1,100}$/u;
@@ -20279,19 +20508,19 @@ function githubRepositoryFullName(cwd) {
20279
20508
  function canonicalGitRoot(cwd) {
20280
20509
  try {
20281
20510
  const top = gitToplevel(cwd);
20282
- return top ? realpathSync.native(top) : null;
20511
+ return top ? realpathSync2.native(top) : null;
20283
20512
  } catch {
20284
20513
  return null;
20285
20514
  }
20286
20515
  }
20287
20516
  function relatedWorktreeTarget(path, cwd, origin) {
20288
- let parent = dirname4(resolve2(cwd, path));
20517
+ let parent = dirname6(resolve3(cwd, path));
20289
20518
  while (true) {
20290
20519
  try {
20291
- realpathSync.native(parent);
20520
+ realpathSync2.native(parent);
20292
20521
  break;
20293
20522
  } catch {
20294
- const next = dirname4(parent);
20523
+ const next = dirname6(parent);
20295
20524
  if (next === parent) return null;
20296
20525
  parent = next;
20297
20526
  }
@@ -20301,7 +20530,7 @@ function relatedWorktreeTarget(path, cwd, origin) {
20301
20530
  const common = (root) => {
20302
20531
  const value = gitValue(root, ["rev-parse", "--git-common-dir"]);
20303
20532
  try {
20304
- return value ? realpathSync.native(resolve2(root, value)) : void 0;
20533
+ return value ? realpathSync2.native(resolve3(root, value)) : void 0;
20305
20534
  } catch {
20306
20535
  return void 0;
20307
20536
  }
@@ -20331,16 +20560,16 @@ function normalizeOriginRemote(remote) {
20331
20560
  }
20332
20561
  }
20333
20562
  function opaqueRepoKey(source, value) {
20334
- return `repo_v1_${createHash3("sha256").update(`${source}\0${value}`).digest("hex")}`;
20563
+ return `repo_v1_${createHash4("sha256").update(`${source}\0${value}`).digest("hex")}`;
20335
20564
  }
20336
20565
  function resolveRepositoryContext(cwd = process.cwd()) {
20337
20566
  const top = gitToplevel(cwd);
20338
20567
  if (!top) return null;
20339
20568
  let repoRoot;
20340
20569
  try {
20341
- repoRoot = realpathSync.native(top);
20570
+ repoRoot = realpathSync2.native(top);
20342
20571
  } catch {
20343
- repoRoot = resolve2(top);
20572
+ repoRoot = resolve3(top);
20344
20573
  }
20345
20574
  const origin = gitValue(repoRoot, ["config", "--get", "remote.origin.url"]);
20346
20575
  const repoFullName = githubRepositoryFullName(repoRoot) ?? void 0;
@@ -20369,19 +20598,19 @@ function nearestExistingAncestor(path) {
20369
20598
  let cursor = path;
20370
20599
  while (true) {
20371
20600
  try {
20372
- lstatSync2(cursor);
20601
+ lstatSync3(cursor);
20373
20602
  break;
20374
20603
  } catch (error) {
20375
20604
  const code = typeof error === "object" && error !== null && "code" in error ? error.code : void 0;
20376
20605
  if (code !== "ENOENT" && code !== "ENOTDIR") return null;
20377
- const parent = dirname4(cursor);
20606
+ const parent = dirname6(cursor);
20378
20607
  if (parent === cursor) return null;
20379
20608
  suffix.unshift(cursor.slice(parent.length + (parent.endsWith(sep) ? 0 : 1)));
20380
20609
  cursor = parent;
20381
20610
  }
20382
20611
  }
20383
20612
  try {
20384
- return { real: realpathSync.native(cursor), suffix };
20613
+ return { real: realpathSync2.native(cursor), suffix };
20385
20614
  } catch {
20386
20615
  return null;
20387
20616
  }
@@ -20390,13 +20619,13 @@ function canonicalRepositoryPathScoped(filePath, context, baseDir) {
20390
20619
  if (!filePath || filePath !== filePath.trim() || filePath.includes("\0")) {
20391
20620
  return { ok: false, reason: "invalid_path" };
20392
20621
  }
20393
- const absolute = resolve2(baseDir, filePath);
20622
+ const absolute = resolve3(baseDir, filePath);
20394
20623
  const resolved = nearestExistingAncestor(absolute);
20395
20624
  if (!resolved) return { ok: false, reason: "invalid_path" };
20396
- const target = resolve2(resolved.real, ...resolved.suffix);
20625
+ const target = resolve3(resolved.real, ...resolved.suffix);
20397
20626
  const rel = relative(context.repoRoot, target);
20398
20627
  if (!rel || rel === ".") return { ok: false, reason: "invalid_path" };
20399
- if (isAbsolute2(rel) || rel === ".." || rel.startsWith(`..${sep}`)) {
20628
+ if (isAbsolute4(rel) || rel === ".." || rel.startsWith(`..${sep}`)) {
20400
20629
  return { ok: false, reason: "outside_repository" };
20401
20630
  }
20402
20631
  return { ok: true, file: sep === "/" ? rel : rel.split(sep).join("/") };
@@ -20404,26 +20633,26 @@ function canonicalRepositoryPathScoped(filePath, context, baseDir) {
20404
20633
  function canonicalRepositoryPathLegacy(filePath, cwd, repositoryRoot = canonicalGitRoot(cwd)) {
20405
20634
  if (!repositoryRoot || !filePath || [...filePath].some((char) => char < " " || char === "\x7F" || "~*?[]{}$`\\".includes(char)))
20406
20635
  return null;
20407
- const absolute = resolve2(cwd, filePath);
20636
+ const absolute = resolve3(cwd, filePath);
20408
20637
  let target;
20409
20638
  try {
20410
- const stat = lstatSync2(absolute);
20639
+ const stat = lstatSync3(absolute);
20411
20640
  if (!stat.isFile() || stat.isSymbolicLink()) return null;
20412
- target = realpathSync.native(absolute);
20641
+ target = realpathSync2.native(absolute);
20413
20642
  } catch (error) {
20414
20643
  if (!(error instanceof Error) || error.code !== "ENOENT") {
20415
20644
  return null;
20416
20645
  }
20417
20646
  try {
20418
- const parent = realpathSync.native(dirname4(absolute));
20419
- if (!lstatSync2(parent).isDirectory()) return null;
20420
- target = resolve2(parent, basename(absolute));
20647
+ const parent = realpathSync2.native(dirname6(absolute));
20648
+ if (!lstatSync3(parent).isDirectory()) return null;
20649
+ target = resolve3(parent, basename(absolute));
20421
20650
  } catch {
20422
20651
  return null;
20423
20652
  }
20424
20653
  }
20425
20654
  const rel = relative(repositoryRoot, target);
20426
- if (!rel || isAbsolute2(rel) || rel === ".." || rel.startsWith(`..${sep}`)) {
20655
+ if (!rel || isAbsolute4(rel) || rel === ".." || rel.startsWith(`..${sep}`)) {
20427
20656
  return null;
20428
20657
  }
20429
20658
  return sep === "/" ? rel : rel.split(sep).join("/");
@@ -20505,10 +20734,10 @@ function hasProjectPrimInstall(cwd) {
20505
20734
  const root = gitToplevel(cwd);
20506
20735
  if (root === null || root === homedir2()) return false;
20507
20736
  for (const rel of PROJECT_INSTALL_FILES) {
20508
- const path = join6(root, rel);
20509
- if (existsSync5(path)) {
20737
+ const path = join9(root, rel);
20738
+ if (existsSync8(path)) {
20510
20739
  try {
20511
- const content = readFileSync5(path, "utf-8");
20740
+ const content = readFileSync7(path, "utf-8");
20512
20741
  if (PRIM_HOOK_BINS.some((bin) => content.includes(bin))) return true;
20513
20742
  } catch {
20514
20743
  }
@@ -20527,14 +20756,14 @@ function decisionIngestionStatus(cwd) {
20527
20756
  }
20528
20757
 
20529
20758
  // src/client.ts
20530
- import { createHash as createHash4 } from "crypto";
20531
- import { chmodSync as chmodSync2, existsSync as existsSync7, mkdirSync as mkdirSync3, readFileSync as readFileSync8, rmSync as rmSync3 } from "fs";
20532
- import { dirname as dirname6 } from "path";
20759
+ import { createHash as createHash5 } from "crypto";
20760
+ import { chmodSync as chmodSync3, existsSync as existsSync9, mkdirSync as mkdirSync4, readFileSync as readFileSync9, rmSync as rmSync4 } from "fs";
20761
+ import { dirname as dirname7 } from "path";
20533
20762
 
20534
20763
  // src/daemon/client-instance-id.ts
20535
- import { randomBytes as randomBytes2 } from "crypto";
20536
- import { chmodSync, lstatSync as lstatSync3, readFileSync as readFileSync6 } from "fs";
20537
- import { join as join7 } from "path";
20764
+ import { randomBytes as randomBytes3 } from "crypto";
20765
+ import { chmodSync as chmodSync2, lstatSync as lstatSync4, readFileSync as readFileSync8 } from "fs";
20766
+ import { join as join10 } from "path";
20538
20767
  var CONFIG_DIRECTORY_MODE = 448;
20539
20768
  var INSTANCE_FILE_MODE = 384;
20540
20769
  var INSTANCE_ENTROPY_BYTES = 32;
@@ -20547,17 +20776,17 @@ function isClientInstanceId(value) {
20547
20776
  }
20548
20777
  function ensurePrivateConfigDirectory(configDir) {
20549
20778
  ensureDurableDirectory(configDir, CONFIG_DIRECTORY_MODE);
20550
- const metadata = lstatSync3(configDir);
20779
+ const metadata = lstatSync4(configDir);
20551
20780
  if (!metadata.isDirectory() || metadata.isSymbolicLink()) {
20552
20781
  throw new Error("prim config path must be a private directory");
20553
20782
  }
20554
- chmodSync(configDir, CONFIG_DIRECTORY_MODE);
20783
+ chmodSync2(configDir, CONFIG_DIRECTORY_MODE);
20555
20784
  syncDirectory(configDir);
20556
20785
  }
20557
20786
  function readExisting(path) {
20558
20787
  let metadata;
20559
20788
  try {
20560
- metadata = lstatSync3(path);
20789
+ metadata = lstatSync4(path);
20561
20790
  } catch (error) {
20562
20791
  if (error.code === "ENOENT") {
20563
20792
  return;
@@ -20567,11 +20796,11 @@ function readExisting(path) {
20567
20796
  if (!metadata.isFile() || metadata.isSymbolicLink()) {
20568
20797
  throw new Error("stored client instance identity is invalid");
20569
20798
  }
20570
- chmodSync(path, INSTANCE_FILE_MODE);
20799
+ chmodSync2(path, INSTANCE_FILE_MODE);
20571
20800
  if (metadata.size > MAX_STORED_BYTES) {
20572
20801
  throw new Error("stored client instance identity is invalid");
20573
20802
  }
20574
- const raw = readFileSync6(path, "utf8");
20803
+ const raw = readFileSync8(path, "utf8");
20575
20804
  const value = raw.endsWith("\n") ? raw.slice(0, -1) : raw;
20576
20805
  if (raw !== value && raw !== `${value}
20577
20806
  ` || !isClientInstanceId(value)) {
@@ -20585,8 +20814,8 @@ function atomicWrite(path, value) {
20585
20814
  }
20586
20815
  async function getOrCreateClientInstanceId(options) {
20587
20816
  const configDir = options.configDir;
20588
- const path = join7(configDir, "client_instance_id");
20589
- const lockPath = join7(configDir, "client-instance.lock");
20817
+ const path = join10(configDir, "client_instance_id");
20818
+ const lockPath = join10(configDir, "client-instance.lock");
20590
20819
  ensurePrivateConfigDirectory(configDir);
20591
20820
  return withFileLock(
20592
20821
  lockPath,
@@ -20595,7 +20824,7 @@ async function getOrCreateClientInstanceId(options) {
20595
20824
  if (existing !== void 0) {
20596
20825
  return existing;
20597
20826
  }
20598
- const generated = `${INSTANCE_PREFIX}${randomBytes2(INSTANCE_ENTROPY_BYTES).toString(
20827
+ const generated = `${INSTANCE_PREFIX}${randomBytes3(INSTANCE_ENTROPY_BYTES).toString(
20599
20828
  "base64url"
20600
20829
  )}`;
20601
20830
  if (!isClientInstanceId(generated)) {
@@ -20608,75 +20837,6 @@ async function getOrCreateClientInstanceId(options) {
20608
20837
  );
20609
20838
  }
20610
20839
 
20611
- // src/lib/bin-path.ts
20612
- import { existsSync as existsSync6, readFileSync as readFileSync7 } from "fs";
20613
- import { dirname as dirname5, isAbsolute as isAbsolute3, join as join8 } from "path";
20614
- import { fileURLToPath } from "url";
20615
- var PKG_NAME = "@primitive.ai/prim";
20616
- var ROOT_WALK_LIMIT = 6;
20617
- var STABLE_HOOK_LAUNCHER_NAME = "prim-hook-launcher-v1";
20618
- var resolvedRoot;
20619
- function locateRoot() {
20620
- if (resolvedRoot !== void 0) {
20621
- return resolvedRoot;
20622
- }
20623
- let dir = dirname5(fileURLToPath(import.meta.url));
20624
- for (let depth = 0; depth < ROOT_WALK_LIMIT; depth++) {
20625
- const manifestPath = join8(dir, "package.json");
20626
- if (existsSync6(manifestPath)) {
20627
- try {
20628
- const manifest = JSON.parse(readFileSync7(manifestPath, "utf-8"));
20629
- if (manifest.name === PKG_NAME && manifest.bin) {
20630
- resolvedRoot = { dir, version: manifest.version, bin: manifest.bin };
20631
- return resolvedRoot;
20632
- }
20633
- } catch {
20634
- }
20635
- }
20636
- const parent = dirname5(dir);
20637
- if (parent === dir) {
20638
- break;
20639
- }
20640
- dir = parent;
20641
- }
20642
- resolvedRoot = null;
20643
- return resolvedRoot;
20644
- }
20645
- function packageVersion() {
20646
- return locateRoot()?.version ?? null;
20647
- }
20648
- function shellQuote(value) {
20649
- return `'${value.replaceAll("'", `'"'"'`)}'`;
20650
- }
20651
- var STABLE_HOOK_ARGUMENTS_RE = /^[-A-Za-z0-9_ ]*$/u;
20652
- var STABLE_HOOK_BIN_RE = /^[A-Za-z0-9][A-Za-z0-9-]*$/u;
20653
- var PRIM_CONFIG_SHELL_RESOLVER = [
20654
- 'prim_absolute() { case "$1" in [/]* ) ;; *) return 1 ;; esac; case "$1" in [[:space:]]*|*[[:space:]]|*[/][/]*|*[/].[/]*|*[/]..[/]*|*[/].|*[/]..|?*[/]) return 1 ;; esac; }; ',
20655
- 'prim_config=${PRIM_CONFIG_DIR:-}; if ! prim_absolute "$prim_config"; then prim_config=${XDG_CONFIG_HOME:-}; if prim_absolute "$prim_config"; then ',
20656
- 'case "$prim_config" in /) prim_config=/prim ;; *) prim_config="$prim_config/prim" ;; esac; ',
20657
- '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; ',
20658
- "fi; fi; "
20659
- ].join("");
20660
- function stableHookCommand(bin, args = "") {
20661
- if (!STABLE_HOOK_BIN_RE.test(bin) || !STABLE_HOOK_ARGUMENTS_RE.test(args)) {
20662
- throw new Error("invalid stable hook command");
20663
- }
20664
- const resolver = [
20665
- // #242 and earlier identify managed commands by this package marker. Keep
20666
- // it as inert data during the rolling window so an older uninstall or
20667
- // reinstall can remove the stable entry without invoking npm or PATH.
20668
- `prim_legacy_reader='-p ${PKG_NAME}@stable prim-shim.sh ${bin} '; `,
20669
- PRIM_CONFIG_SHELL_RESOLVER,
20670
- `case "$prim_config" in /) prim_launcher=/${STABLE_HOOK_LAUNCHER_NAME} ;; *) prim_launcher="$prim_config/${STABLE_HOOK_LAUNCHER_NAME}" ;; esac; `,
20671
- 'exec "$prim_launcher" "$@"'
20672
- ].join("");
20673
- const suffix = args ? ` ${args}` : "";
20674
- return `/bin/sh -c ${shellQuote(resolver)} ${STABLE_HOOK_LAUNCHER_NAME} ${bin}${suffix}`;
20675
- }
20676
- function detachedHookShimCommand(bin, args = "") {
20677
- return `payload=$(cat); { trap '' HUP; printf '%s' "$payload" | { ${stableHookCommand(bin, args)}; }; } </dev/null >/dev/null 2>&1 &`;
20678
- }
20679
-
20680
20840
  // src/lib/ingest-uploader.ts
20681
20841
  var runtimeVersion = process.env.PRIM_RUNTIME_VERSION ?? packageVersion();
20682
20842
  var VERSION_RE = /^\d+\.\d+\.\d+(?:-[A-Za-z0-9.-]+)?(?:\+[A-Za-z0-9.-]+)?$/u;
@@ -20749,7 +20909,7 @@ var DEFAULT_API_URL = "https://api.getprimitive.ai";
20749
20909
  var AUTH_EXPIRED_MESSAGE = "Authentication expired. Run `prim auth login` to re-authenticate.";
20750
20910
  function readTrimmed2(path) {
20751
20911
  try {
20752
- const value = readFileSync8(path, "utf8").trim();
20912
+ const value = readFileSync9(path, "utf8").trim();
20753
20913
  return value || void 0;
20754
20914
  } catch {
20755
20915
  return void 0;
@@ -20765,17 +20925,17 @@ function expiresAtFor(token, expiresIn) {
20765
20925
  return expiresIn === void 0 ? jwtExpiresAt(token) : Date.now() + expiresIn * 1e3;
20766
20926
  }
20767
20927
  function ensureConfigDirectory() {
20768
- const directory = dirname6(TOKEN_FILE_PATH);
20769
- mkdirSync3(directory, { recursive: true, mode: CONFIG_DIR_MODE });
20770
- chmodSync2(directory, CONFIG_DIR_MODE);
20928
+ const directory = dirname7(TOKEN_FILE_PATH);
20929
+ mkdirSync4(directory, { recursive: true, mode: CONFIG_DIR_MODE });
20930
+ chmodSync3(directory, CONFIG_DIR_MODE);
20771
20931
  }
20772
20932
  function atomicWrite2(path, content) {
20773
20933
  ensureConfigDirectory();
20774
20934
  atomicWriteFile(path, content, { mode: CREDENTIAL_FILE_MODE });
20775
20935
  }
20776
20936
  function removeCredentialFile(path) {
20777
- if (!existsSync7(path)) return false;
20778
- rmSync3(path, { force: true });
20937
+ if (!existsSync9(path)) return false;
20938
+ rmSync4(path, { force: true });
20779
20939
  return true;
20780
20940
  }
20781
20941
  function getTokenExpiresAt() {
@@ -20790,7 +20950,7 @@ function isTokenExpiringSoon(credential) {
20790
20950
  return expiresAt !== void 0 && Date.now() >= expiresAt - REFRESH_THRESHOLD_MS;
20791
20951
  }
20792
20952
  function refreshFingerprint(refreshToken2) {
20793
- return createHash4("sha256").update(refreshToken2).digest("hex");
20953
+ return createHash5("sha256").update(refreshToken2).digest("hex");
20794
20954
  }
20795
20955
  function legacyBrokerCredentialMetadata(accessToken, refreshToken2) {
20796
20956
  return {
@@ -21549,22 +21709,22 @@ function scheduleCollectScopeRefresh(cwd, collectScopeVersion, dependencies = de
21549
21709
  import { execFileSync as execFileSync3 } from "child_process";
21550
21710
  import { randomUUID as randomUUID3 } from "crypto";
21551
21711
  import {
21552
- constants as constants2,
21553
- chmodSync as chmodSync3,
21712
+ constants as constants3,
21713
+ chmodSync as chmodSync4,
21554
21714
  closeSync as closeSync2,
21555
21715
  fchmodSync as fchmodSync2,
21556
21716
  fsyncSync as fsyncSync2,
21557
21717
  linkSync,
21558
- lstatSync as lstatSync4,
21559
- mkdirSync as mkdirSync4,
21718
+ lstatSync as lstatSync5,
21719
+ mkdirSync as mkdirSync5,
21560
21720
  openSync as openSync2,
21561
- readFileSync as readFileSync9,
21562
- statSync as statSync2,
21721
+ readFileSync as readFileSync10,
21722
+ statSync as statSync3,
21563
21723
  unlinkSync,
21564
- writeFileSync as writeFileSync3
21724
+ writeFileSync as writeFileSync4
21565
21725
  } from "fs";
21566
- import { dirname as dirname7, isAbsolute as isAbsolute4, join as join10, resolve as resolve4 } from "path";
21567
- var WORKSPACE_ID_RELATIVE_PATH = join10("prim", "workspace-id");
21726
+ import { dirname as dirname8, isAbsolute as isAbsolute5, join as join12, resolve as resolve5 } from "path";
21727
+ var WORKSPACE_ID_RELATIVE_PATH = join12("prim", "workspace-id");
21568
21728
  var MAX_ANCESTORS = 64;
21569
21729
  var MAX_GIT_FILE_BYTES = 4096;
21570
21730
  var MAX_ID_FILE_BYTES = 128;
@@ -21610,7 +21770,7 @@ function resolveWorkspaceIdPath(cwd) {
21610
21770
  }
21611
21771
  return {
21612
21772
  status: "resolved",
21613
- path: isAbsolute4(gitPath) ? resolve4(gitPath) : resolve4(cwd, gitPath)
21773
+ path: isAbsolute5(gitPath) ? resolve5(gitPath) : resolve5(cwd, gitPath)
21614
21774
  };
21615
21775
  } catch (error) {
21616
21776
  const code = errorCode(error);
@@ -21621,21 +21781,21 @@ function resolveWorkspaceIdPath(cwd) {
21621
21781
  }
21622
21782
  }
21623
21783
  function resolveFromFilesystem(cwd) {
21624
- let current = resolve4(cwd);
21784
+ let current = resolve5(cwd);
21625
21785
  for (let depth = 0; depth < MAX_ANCESTORS; depth += 1) {
21626
- const dotGit = join10(current, ".git");
21786
+ const dotGit = join12(current, ".git");
21627
21787
  try {
21628
- const stat = lstatSync4(dotGit);
21788
+ const stat = lstatSync5(dotGit);
21629
21789
  if (stat.isDirectory() && isGitDirectory(dotGit)) {
21630
- return join10(dotGit, WORKSPACE_ID_RELATIVE_PATH);
21790
+ return join12(dotGit, WORKSPACE_ID_RELATIVE_PATH);
21631
21791
  }
21632
21792
  if (stat.isFile() && stat.size <= MAX_GIT_FILE_BYTES) {
21633
- const contents = readFileSync9(dotGit, "utf8");
21793
+ const contents = readFileSync10(dotGit, "utf8");
21634
21794
  const match = /^gitdir: (.+?)(?:\r?\n)?$/.exec(contents);
21635
21795
  if (match?.[1]) {
21636
- const gitDirectory = isAbsolute4(match[1]) ? resolve4(match[1]) : resolve4(current, match[1]);
21796
+ const gitDirectory = isAbsolute5(match[1]) ? resolve5(match[1]) : resolve5(current, match[1]);
21637
21797
  if (isGitDirectory(gitDirectory)) {
21638
- return join10(gitDirectory, WORKSPACE_ID_RELATIVE_PATH);
21798
+ return join12(gitDirectory, WORKSPACE_ID_RELATIVE_PATH);
21639
21799
  }
21640
21800
  }
21641
21801
  }
@@ -21646,7 +21806,7 @@ function resolveFromFilesystem(cwd) {
21646
21806
  return null;
21647
21807
  }
21648
21808
  }
21649
- const parent = dirname7(current);
21809
+ const parent = dirname8(current);
21650
21810
  if (parent === current) break;
21651
21811
  current = parent;
21652
21812
  }
@@ -21654,7 +21814,7 @@ function resolveFromFilesystem(cwd) {
21654
21814
  }
21655
21815
  function isGitDirectory(path) {
21656
21816
  try {
21657
- return statSync2(join10(path, "HEAD")).isFile();
21817
+ return statSync3(join12(path, "HEAD")).isFile();
21658
21818
  } catch {
21659
21819
  return false;
21660
21820
  }
@@ -21662,7 +21822,7 @@ function isGitDirectory(path) {
21662
21822
  function inspectPath(path) {
21663
21823
  let stat;
21664
21824
  try {
21665
- stat = lstatSync4(path);
21825
+ stat = lstatSync5(path);
21666
21826
  } catch (error) {
21667
21827
  const code = errorCode(error);
21668
21828
  if (code === "ENOENT" || code === "ENOTDIR") return { status: "missing", path };
@@ -21673,7 +21833,7 @@ function inspectPath(path) {
21673
21833
  return { status: "corrupt", path, reason: "invalid_content" };
21674
21834
  }
21675
21835
  try {
21676
- const contents = readFileSync9(path, "utf8");
21836
+ const contents = readFileSync10(path, "utf8");
21677
21837
  const workspaceId = contents.endsWith("\n") ? contents.slice(0, -1) : contents;
21678
21838
  if ((contents === workspaceId || contents === `${workspaceId}
21679
21839
  `) && isCanonicalWorkspaceId(workspaceId)) {
@@ -21690,22 +21850,22 @@ function inspectPath(path) {
21690
21850
  }
21691
21851
  }
21692
21852
  function createWorkspaceId(path) {
21693
- const parent = dirname7(path);
21853
+ const parent = dirname8(path);
21694
21854
  const workspaceId = randomUUID3();
21695
- const temporaryPath = join10(parent, `.workspace-id-${process.pid}-${randomUUID3()}.tmp`);
21855
+ const temporaryPath = join12(parent, `.workspace-id-${process.pid}-${randomUUID3()}.tmp`);
21696
21856
  let temporaryCreated = false;
21697
21857
  let publishing = false;
21698
21858
  try {
21699
- mkdirSync4(parent, { recursive: true, mode: 448 });
21700
- chmodSync3(parent, 448);
21859
+ mkdirSync5(parent, { recursive: true, mode: 448 });
21860
+ chmodSync4(parent, 448);
21701
21861
  const fd = openSync2(
21702
21862
  temporaryPath,
21703
- constants2.O_CREAT | constants2.O_EXCL | constants2.O_WRONLY,
21863
+ constants3.O_CREAT | constants3.O_EXCL | constants3.O_WRONLY,
21704
21864
  384
21705
21865
  );
21706
21866
  temporaryCreated = true;
21707
21867
  try {
21708
- writeFileSync3(fd, `${workspaceId}
21868
+ writeFileSync4(fd, `${workspaceId}
21709
21869
  `, "utf8");
21710
21870
  fchmodSync2(fd, 384);
21711
21871
  fsyncSync2(fd);
@@ -21762,33 +21922,33 @@ function parseAgent(argv) {
21762
21922
  }
21763
21923
 
21764
21924
  // src/hooks/codex-context.ts
21765
- import { createHash as createHash6, randomBytes as randomBytes4 } from "crypto";
21925
+ import { createHash as createHash7, randomBytes as randomBytes5 } from "crypto";
21766
21926
  import {
21767
- chmodSync as chmodSync4,
21768
- existsSync as existsSync8,
21769
- mkdirSync as mkdirSync5,
21770
- readFileSync as readFileSync10,
21771
- readdirSync as readdirSync2,
21772
- renameSync as renameSync2,
21773
- rmSync as rmSync4,
21774
- statSync as statSync3,
21927
+ chmodSync as chmodSync5,
21928
+ existsSync as existsSync10,
21929
+ mkdirSync as mkdirSync6,
21930
+ readFileSync as readFileSync11,
21931
+ readdirSync as readdirSync3,
21932
+ renameSync as renameSync3,
21933
+ rmSync as rmSync5,
21934
+ statSync as statSync4,
21775
21935
  unlinkSync as unlinkSync2,
21776
- writeFileSync as writeFileSync4
21936
+ writeFileSync as writeFileSync5
21777
21937
  } from "fs";
21778
- import { join as join12 } from "path";
21938
+ import { join as join14 } from "path";
21779
21939
 
21780
21940
  // src/daemon/client.ts
21781
21941
  import { createConnection } from "net";
21782
- import { join as join11 } from "path";
21942
+ import { join as join13 } from "path";
21783
21943
 
21784
21944
  // src/daemon/principal.ts
21785
- import { createHash as createHash5 } from "crypto";
21945
+ import { createHash as createHash6 } from "crypto";
21786
21946
  var PRINCIPAL_COMPONENT_MAX_LENGTH = 512;
21787
21947
  function boundedClaim(value) {
21788
21948
  return typeof value === "string" && value.length > 0 && value.length <= PRINCIPAL_COMPONENT_MAX_LENGTH ? value : void 0;
21789
21949
  }
21790
21950
  function sha256(value) {
21791
- return createHash5("sha256").update(value).digest("hex");
21951
+ return createHash6("sha256").update(value).digest("hex");
21792
21952
  }
21793
21953
  function resolveDaemonPrincipal(token = resolveAuthCredential()?.token) {
21794
21954
  if (!token) return void 0;
@@ -21829,7 +21989,7 @@ function parseDaemonResponseEnvelope(value) {
21829
21989
  }
21830
21990
 
21831
21991
  // src/daemon/client.ts
21832
- var SOCK_PATH = join11(primConfigDirectory(), "sock");
21992
+ var SOCK_PATH = join13(primConfigDirectory(), "sock");
21833
21993
  var DEFAULT_TIMEOUT_MS2 = 250;
21834
21994
  var nextRequestId = 1;
21835
21995
  function daemonRequest(method, params = {}, opts = {}) {
@@ -21917,7 +22077,7 @@ function daemonRequest(method, params = {}, opts = {}) {
21917
22077
  }
21918
22078
 
21919
22079
  // src/daemon/decision-digest-cache.ts
21920
- import { randomBytes as randomBytes3 } from "crypto";
22080
+ import { randomBytes as randomBytes4 } from "crypto";
21921
22081
  var DECISION_DIGEST_CACHE_LIMIT = 100;
21922
22082
  var DECISION_DIGEST_CACHE_WINDOW = "24h";
21923
22083
  var DECISION_DIGEST_CACHE_PATH = `/api/cli/decisions/recent?limit=${String(DECISION_DIGEST_CACHE_LIMIT)}&since=${DECISION_DIGEST_CACHE_WINDOW}`;
@@ -22130,10 +22290,10 @@ function appendCodexContext(output, context) {
22130
22290
  return next;
22131
22291
  }
22132
22292
  function stateRoot(namespace) {
22133
- return join12(primConfigDirectory(), namespace, "decision-digests");
22293
+ return join14(primConfigDirectory(), namespace, "decision-digests");
22134
22294
  }
22135
22295
  function draftStateRoot(namespace) {
22136
- return join12(primConfigDirectory(), namespace, "decision-draft-deliveries");
22296
+ return join14(primConfigDirectory(), namespace, "decision-draft-deliveries");
22137
22297
  }
22138
22298
  function workspaceFor(cwd) {
22139
22299
  try {
@@ -22144,13 +22304,13 @@ function workspaceFor(cwd) {
22144
22304
  }
22145
22305
  function statePath(args) {
22146
22306
  const identity = `${args.siteUrl}\0${workspaceFor(args.cwd)}\0${args.sessionId}`;
22147
- const key = createHash6("sha256").update(identity).digest("hex");
22148
- return join12(stateRoot(args.namespace), `${key}.json`);
22307
+ const key = createHash7("sha256").update(identity).digest("hex");
22308
+ return join14(stateRoot(args.namespace), `${key}.json`);
22149
22309
  }
22150
22310
  function draftStatePath(args) {
22151
22311
  const identity = `${args.siteUrl}\0${workspaceFor(args.cwd)}\0${args.sessionId}\0${args.principalId}\0${args.organizationId}\0${args.credentialFingerprint}`;
22152
- const key = createHash6("sha256").update(identity).digest("hex");
22153
- return join12(draftStateRoot(args.namespace), `${key}.json`);
22312
+ const key = createHash7("sha256").update(identity).digest("hex");
22313
+ return join14(draftStateRoot(args.namespace), `${key}.json`);
22154
22314
  }
22155
22315
  function parseState(value) {
22156
22316
  if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
@@ -22189,37 +22349,37 @@ function parseDraftState(value) {
22189
22349
  };
22190
22350
  }
22191
22351
  function readState(path) {
22192
- if (!existsSync8(path)) return void 0;
22352
+ if (!existsSync10(path)) return void 0;
22193
22353
  try {
22194
- return parseState(JSON.parse(readFileSync10(path, "utf8")));
22354
+ return parseState(JSON.parse(readFileSync11(path, "utf8")));
22195
22355
  } catch {
22196
22356
  return void 0;
22197
22357
  }
22198
22358
  }
22199
22359
  function readDraftState(path) {
22200
- if (!existsSync8(path)) return void 0;
22360
+ if (!existsSync10(path)) return void 0;
22201
22361
  try {
22202
- return parseDraftState(JSON.parse(readFileSync10(path, "utf8")));
22362
+ return parseDraftState(JSON.parse(readFileSync11(path, "utf8")));
22203
22363
  } catch {
22204
22364
  return void 0;
22205
22365
  }
22206
22366
  }
22207
22367
  function writeStateFile(path, directory, state) {
22208
- mkdirSync5(directory, { recursive: true, mode: 448 });
22209
- chmodSync4(directory, 448);
22210
- const temporary = join12(
22368
+ mkdirSync6(directory, { recursive: true, mode: 448 });
22369
+ chmodSync5(directory, 448);
22370
+ const temporary = join14(
22211
22371
  directory,
22212
- `.${path.slice(directory.length + 1)}.tmp-${process.pid}-${randomBytes4(8).toString("hex")}`
22372
+ `.${path.slice(directory.length + 1)}.tmp-${process.pid}-${randomBytes5(8).toString("hex")}`
22213
22373
  );
22214
22374
  try {
22215
- writeFileSync4(temporary, `${JSON.stringify(state)}
22375
+ writeFileSync5(temporary, `${JSON.stringify(state)}
22216
22376
  `, {
22217
22377
  encoding: "utf8",
22218
22378
  mode: 384,
22219
22379
  flag: "wx"
22220
22380
  });
22221
- chmodSync4(temporary, 384);
22222
- renameSync2(temporary, path);
22381
+ chmodSync5(temporary, 384);
22382
+ renameSync3(temporary, path);
22223
22383
  } finally {
22224
22384
  try {
22225
22385
  unlinkSync2(temporary);
@@ -22228,19 +22388,19 @@ function writeStateFile(path, directory, state) {
22228
22388
  }
22229
22389
  }
22230
22390
  function cleanupStateFiles(directory, now) {
22231
- if (!existsSync8(directory)) return;
22391
+ if (!existsSync10(directory)) return;
22232
22392
  let names;
22233
22393
  try {
22234
- names = readdirSync2(directory);
22394
+ names = readdirSync3(directory);
22235
22395
  } catch {
22236
22396
  return;
22237
22397
  }
22238
22398
  const files = [];
22239
22399
  const residue = [];
22240
22400
  for (const name of names) {
22241
- const path = join12(directory, name);
22401
+ const path = join14(directory, name);
22242
22402
  try {
22243
- const mtimeMs = statSync3(path).mtimeMs;
22403
+ const mtimeMs = statSync4(path).mtimeMs;
22244
22404
  if (name.endsWith(".json")) {
22245
22405
  files.push({ path, mtimeMs });
22246
22406
  } else if ((name.includes(".json.tmp-") || name.endsWith(".json.lock")) && now - mtimeMs > CODEX_DIGEST_STATE_RETENTION_MS) {
@@ -22259,8 +22419,8 @@ function cleanupStateFiles(directory, now) {
22259
22419
  }
22260
22420
  for (const path of residue) {
22261
22421
  try {
22262
- if (now - statSync3(path).mtimeMs > CODEX_DIGEST_STATE_RETENTION_MS) {
22263
- rmSync4(path, { recursive: true, force: true });
22422
+ if (now - statSync4(path).mtimeMs > CODEX_DIGEST_STATE_RETENTION_MS) {
22423
+ rmSync5(path, { recursive: true, force: true });
22264
22424
  }
22265
22425
  } catch {
22266
22426
  }
@@ -22543,126 +22703,14 @@ async function prepareCodexContext(options) {
22543
22703
  }
22544
22704
 
22545
22705
  // src/commands/cursor-install.ts
22546
- import { existsSync as existsSync11, readFileSync as readFileSync13 } from "fs";
22706
+ import { existsSync as existsSync12, readFileSync as readFileSync13 } from "fs";
22547
22707
  import { homedir as homedir4 } from "os";
22548
- import { isAbsolute as isAbsolute6, join as join15 } from "path";
22549
-
22550
- // src/lib/hook-runtime.ts
22551
- import { createHash as createHash7, randomBytes as randomBytes5 } from "crypto";
22552
- import {
22553
- constants as constants3,
22554
- accessSync,
22555
- chmodSync as chmodSync5,
22556
- copyFileSync,
22557
- existsSync as existsSync9,
22558
- lstatSync as lstatSync5,
22559
- mkdirSync as mkdirSync6,
22560
- mkdtempSync,
22561
- readFileSync as readFileSync11,
22562
- readdirSync as readdirSync3,
22563
- realpathSync as realpathSync2,
22564
- renameSync as renameSync3,
22565
- rmSync as rmSync5,
22566
- statSync as statSync4,
22567
- utimesSync,
22568
- writeFileSync as writeFileSync5
22569
- } from "fs";
22570
- import { delimiter, dirname as dirname8, isAbsolute as isAbsolute5, join as join13, resolve as resolve5 } from "path";
22571
-
22572
- // src/lib/git-hook-contract.ts
22573
- var GIT_HOOK_ENTRYPOINT_CONTENT = `#!/bin/sh
22574
- # prim git hook entrypoint v1 \u2014 managed by prim; do not edit.
22575
- # Run by the "# >>> prim <hook> hook >>>" block in a Git hook file. Acts only
22576
- # where prim is active (git config prim.active true) and never fails the hook.
22577
- case "$0" in */*) prim_dir=\${0%/*} ;; *) exit 0 ;; esac
22578
- prim_launcher="$prim_dir/${STABLE_HOOK_LAUNCHER_NAME}"
22579
- [ -x "$prim_launcher" ] || exit 0
22580
- [ "$(git config --get prim.active 2>/dev/null)" = "true" ] || exit 0
22581
- prim_hook=\${1-}
22582
- if [ "$#" -gt 0 ]; then shift; fi
22583
- case "$prim_hook" in
22584
- pre-commit)
22585
- "$prim_launcher" prim-pre-commit "$@" || :
22586
- ;;
22587
- post-commit)
22588
- prim_sha=$(git rev-parse --verify HEAD 2>/dev/null) || exit 0
22589
- case "$prim_sha" in *[!0-9a-f]* | "") exit 0 ;; esac
22590
- case "\${#prim_sha}" in 40 | 64) ;; *) exit 0 ;; esac
22591
- prim_branch=$(git symbolic-ref --quiet --short HEAD 2>/dev/null) || prim_branch=
22592
- prim_observed=$(mktemp "\${TMPDIR:-/tmp}/prim-post-commit-observed.XXXXXXXX" 2>/dev/null) || prim_observed=
22593
- (
22594
- trap '' HUP
22595
- trap 'if [ -n "$prim_observed" ]; then rm -f "$prim_observed"; fi' 0
22596
- PRIM_COMMIT_SHA=$prim_sha PRIM_COMMIT_BRANCH=$prim_branch PRIM_COMMIT_OBSERVED_FILE=$prim_observed "$prim_launcher" prim-post-commit
22597
- ) </dev/null >/dev/null 2>&1 &
22598
- ;;
22599
- post-rewrite)
22600
- case "\${1-}" in amend | rebase) prim_source=$1 ;; *) exit 0 ;; esac
22601
- prim_pairs=$(mktemp "\${TMPDIR:-/tmp}/prim-post-rewrite-pairs.XXXXXXXX" 2>/dev/null) || exit 0
22602
- if ! chmod 600 "$prim_pairs" 2>/dev/null || ! cat >"$prim_pairs"; then
22603
- rm -f "$prim_pairs"
22604
- exit 0
22605
- fi
22606
- prim_branch=$(git symbolic-ref --quiet --short HEAD 2>/dev/null) || prim_branch=
22607
- (
22608
- trap '' HUP
22609
- trap 'rm -f "$prim_pairs"' 0
22610
- PRIM_REWRITE_SOURCE=$prim_source PRIM_REWRITE_BRANCH=$prim_branch PRIM_REWRITE_PAIRS_FILE=$prim_pairs "$prim_launcher" prim-post-rewrite
22611
- ) </dev/null >/dev/null 2>&1 &
22612
- ;;
22613
- esac
22614
- exit 0
22615
- `;
22616
-
22617
- // src/lib/hook-runtime.ts
22618
- var RELEASE_PREFIX = "release-";
22619
- var MAX_MANIFEST_BYTES = 64 * 1024;
22620
- var RELEASE_GRACE_MS = 10 * 60 * 1e3;
22621
- var HOOK_RUNTIME_ENTRIES = {
22622
- // SessionStart self-healing resolves this exact CLI entry to run
22623
- // `daemon ensure`; it must travel with the immutable hook release.
22624
- prim: "dist/index.js",
22625
- "prim-hook": "dist/hooks/prim-hook.js",
22626
- "prim-pre-commit": "dist/hooks/pre-commit.js",
22627
- "prim-post-commit": "dist/hooks/post-commit.js",
22628
- "prim-post-rewrite": "dist/hooks/post-rewrite.js",
22629
- "prim-pre-tool-use": "dist/hooks/pre-tool-use.js",
22630
- "prim-post-tool-use": "dist/hooks/post-tool-use.js",
22631
- "prim-session-start": "dist/hooks/session-start.js",
22632
- "prim-session-end": "dist/hooks/session-end.js",
22633
- "prim-daemon-server": "dist/daemon/server.js",
22634
- "prim-statusline": "dist/statusline-main.js"
22635
- };
22636
- var SOURCE_ENTRIES = Object.fromEntries(
22637
- Object.entries(HOOK_RUNTIME_ENTRIES).map(([bin, target]) => [
22638
- bin,
22639
- target.replace(/^dist\//u, "")
22640
- ])
22641
- );
22642
- var STABLE_HOOK_LAUNCHER_CONTENT = `#!/bin/sh
22643
- set -eu
22644
- case "$0" in */*) prim_launcher_dir=\${0%/*} ;; *) exit 78 ;; esac
22645
- IFS= read -r prim_release_name < "$prim_launcher_dir/hook-runtime/current" || exit 69
22646
- case "$prim_release_name" in ${RELEASE_PREFIX}*) ;; *) exit 69 ;; esac
22647
- prim_release_id=\${prim_release_name#${RELEASE_PREFIX}}
22648
- case "$prim_release_id" in *[!0-9a-f]*|"") exit 69 ;; esac
22649
- [ "\${#prim_release_id}" -eq 64 ] || exit 69
22650
- prim_release="$prim_launcher_dir/hook-runtime/releases/$prim_release_name"
22651
- case "\${1-}" in
22652
- ${Object.entries(HOOK_RUNTIME_ENTRIES).map(([bin, entry]) => ` ${bin}) prim_entry="$prim_release/${entry}" ;;`).join("\n")}
22653
- *) exit 64 ;;
22654
- esac
22655
- shift
22656
- IFS= read -r prim_node < "$prim_release/node" || exit 69
22657
- case "$prim_node" in /*) ;; *) exit 69 ;; esac
22658
- [ -x "$prim_node" ] && [ -f "$prim_entry" ] || exit 69
22659
- exec "$prim_node" "$prim_entry" "$@"
22660
- `;
22708
+ import { isAbsolute as isAbsolute6, join as join16 } from "path";
22661
22709
 
22662
22710
  // src/commands/claude-install.ts
22663
- import { existsSync as existsSync10, readFileSync as readFileSync12 } from "fs";
22711
+ import { existsSync as existsSync11, readFileSync as readFileSync12 } from "fs";
22664
22712
  import { homedir as homedir3 } from "os";
22665
- import { join as join14 } from "path";
22713
+ import { join as join15 } from "path";
22666
22714
  var CAPTURE_BIN = "prim-hook";
22667
22715
  var GATE_BIN = "prim-pre-tool-use";
22668
22716
  var POST_TOOL_USE_BIN = "prim-post-tool-use";
@@ -22671,7 +22719,7 @@ var SESSION_END_BIN = "prim-session-end";
22671
22719
  var STATUSLINE_BIN = "prim-statusline";
22672
22720
  var STATUSLINE_ARGS = "";
22673
22721
  var STATUSLINE_COMMAND = stableHookCommand(STATUSLINE_BIN, STATUSLINE_ARGS);
22674
- var USER_SCOPE_PATH = join14(homedir3(), ".claude", "settings.json");
22722
+ var USER_SCOPE_PATH = join15(homedir3(), ".claude", "settings.json");
22675
22723
  function projectRoot() {
22676
22724
  return gitToplevel() ?? process.cwd();
22677
22725
  }
@@ -22750,17 +22798,17 @@ function cursorConfigDirectory(env = process.env, home = homedir4(), platform2 =
22750
22798
  const explicit = env.CURSOR_CONFIG_DIR?.trim();
22751
22799
  if (explicit && isAbsolute6(explicit)) return explicit;
22752
22800
  const xdg = env.XDG_CONFIG_HOME?.trim();
22753
- if (platform2 !== "darwin" && xdg && isAbsolute6(xdg)) return join15(xdg, "cursor");
22754
- return join15(home, ".cursor");
22801
+ if (platform2 !== "darwin" && xdg && isAbsolute6(xdg)) return join16(xdg, "cursor");
22802
+ return join16(home, ".cursor");
22755
22803
  }
22756
22804
  function cursorHooksPath(scope, root = projectRoot()) {
22757
- return scope === "user" ? join15(cursorConfigDirectory(), "hooks.json") : join15(root, ".cursor", "hooks.json");
22805
+ return scope === "user" ? join16(cursorConfigDirectory(), "hooks.json") : join16(root, ".cursor", "hooks.json");
22758
22806
  }
22759
22807
  function plainObject(value) {
22760
22808
  return typeof value === "object" && value !== null && !Array.isArray(value);
22761
22809
  }
22762
22810
  function readCursorHooks(path) {
22763
- if (!existsSync11(path)) return {};
22811
+ if (!existsSync12(path)) return {};
22764
22812
  let parsed;
22765
22813
  try {
22766
22814
  parsed = JSON.parse(readFileSync13(path, "utf8"));
@@ -22983,8 +23031,8 @@ function extractFileTargets(toolName, toolInput, agent = "claude_code") {
22983
23031
  }
22984
23032
 
22985
23033
  // src/hooks/redact.ts
22986
- import { existsSync as existsSync12, readFileSync as readFileSync14, statSync as statSync5 } from "fs";
22987
- import { join as join16 } from "path";
23034
+ import { existsSync as existsSync13, readFileSync as readFileSync14, statSync as statSync5 } from "fs";
23035
+ import { join as join17 } from "path";
22988
23036
  import { Worker } from "worker_threads";
22989
23037
  var USER_HOME_RULES = [
22990
23038
  {
@@ -23060,8 +23108,8 @@ function normalizedWorkspaceFlags(value) {
23060
23108
  return [...new Set(`g${requested}`)].sort().join("");
23061
23109
  }
23062
23110
  function loadWorkspaceRules(cwd) {
23063
- const path = join16(cwd, WORKSPACE_FILE2);
23064
- if (!existsSync12(path)) return [];
23111
+ const path = join17(cwd, WORKSPACE_FILE2);
23112
+ if (!existsSync13(path)) return [];
23065
23113
  let cfg;
23066
23114
  try {
23067
23115
  if (statSync5(path).size > MAX_WORKSPACE_CONFIG_BYTES) {
@@ -27994,7 +28042,7 @@ function requireDurableIngestAcknowledgement(value, expected, cwd = process.cwd(
27994
28042
  import {
27995
28043
  appendFileSync,
27996
28044
  closeSync as closeSync3,
27997
- existsSync as existsSync14,
28045
+ existsSync as existsSync15,
27998
28046
  fstatSync,
27999
28047
  mkdirSync as mkdirSync7,
28000
28048
  openSync as openSync3,
@@ -28003,21 +28051,21 @@ import {
28003
28051
  readSync,
28004
28052
  readdirSync as readdirSync5
28005
28053
  } from "fs";
28006
- import { dirname as dirname11, join as join18 } from "path";
28054
+ import { dirname as dirname11, join as join19 } from "path";
28007
28055
 
28008
28056
  // src/drain-progress.ts
28009
28057
  import {
28010
28058
  chmodSync as chmodSync6,
28011
- existsSync as existsSync13,
28059
+ existsSync as existsSync14,
28012
28060
  readFileSync as readFileSync15,
28013
28061
  readdirSync as readdirSync4,
28014
28062
  rmSync as rmSync6,
28015
28063
  rmdirSync
28016
28064
  } from "fs";
28017
- import { basename as basename2, dirname as dirname10, join as join17 } from "path";
28065
+ import { basename as basename2, dirname as dirname10, join as join18 } from "path";
28018
28066
 
28019
28067
  // src/journal.ts
28020
- var JOURNAL_DIR = join18(primConfigDirectory(), "moves");
28068
+ var JOURNAL_DIR = join19(primConfigDirectory(), "moves");
28021
28069
  var UNBOUND_BUCKET = "_unbound";
28022
28070
  var JOURNAL_BASENAME = "journal.ndjson";
28023
28071
  var JOURNAL_STATS_SAMPLE_BYTES = 64 * 1024;
@@ -28029,7 +28077,7 @@ function envSlug(apiUrl) {
28029
28077
  return slug;
28030
28078
  }
28031
28079
  function currentEnvDir() {
28032
- return join18(JOURNAL_DIR, envSlug(getSiteUrl()));
28080
+ return join19(JOURNAL_DIR, envSlug(getSiteUrl()));
28033
28081
  }
28034
28082
  var DIR_MODE = 448;
28035
28083
  var FILE_MODE2 = 384;
@@ -28037,7 +28085,7 @@ var SAFE_BUCKET = /^[A-Za-z0-9_-]+$/;
28037
28085
  var RESERVED_BUCKETS = /* @__PURE__ */ new Set([UNBOUND_BUCKET, "_legacy"]);
28038
28086
  function appendMoveToPath(path, move) {
28039
28087
  const dir = dirname11(path);
28040
- if (!existsSync14(dir)) {
28088
+ if (!existsSync15(dir)) {
28041
28089
  mkdirSync7(dir, { recursive: true, mode: DIR_MODE });
28042
28090
  }
28043
28091
  appendFileSync(path, `${JSON.stringify(move)}
@@ -28045,10 +28093,10 @@ function appendMoveToPath(path, move) {
28045
28093
  }
28046
28094
  function bucketDir(orgId) {
28047
28095
  const safe = orgId !== void 0 && SAFE_BUCKET.test(orgId) && !RESERVED_BUCKETS.has(orgId);
28048
- return join18(currentEnvDir(), safe ? orgId : UNBOUND_BUCKET);
28096
+ return join19(currentEnvDir(), safe ? orgId : UNBOUND_BUCKET);
28049
28097
  }
28050
28098
  function journalPath(orgId) {
28051
- return join18(bucketDir(orgId), JOURNAL_BASENAME);
28099
+ return join19(bucketDir(orgId), JOURNAL_BASENAME);
28052
28100
  }
28053
28101
  function appendMove(move, orgId) {
28054
28102
  appendMoveToPath(journalPath(orgId), move);
@@ -28220,7 +28268,7 @@ function editingToolsFor(agent) {
28220
28268
  var here = dirname12(fileURLToPath2(import.meta.url));
28221
28269
  function resolveCliVersion() {
28222
28270
  try {
28223
- const pkg = JSON.parse(readFileSync17(join19(here, "..", "..", "package.json"), "utf-8"));
28271
+ const pkg = JSON.parse(readFileSync17(join20(here, "..", "..", "package.json"), "utf-8"));
28224
28272
  return pkg.version ?? "unknown";
28225
28273
  } catch {
28226
28274
  return "unknown";