@primitive.ai/prim 0.1.0-alpha.128 → 0.1.0-alpha.129
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/dist/{chunk-6QAXVFRJ.js → chunk-BVGASV3B.js} +942 -123
- package/dist/{chunk-M6KIDB5R.js → chunk-DYXCJ6WZ.js} +10 -10
- package/dist/{chunk-B3ICJZXV.js → chunk-FHDTJP2C.js} +2 -2
- package/dist/{chunk-XINFTNA2.js → chunk-HDL3UXYJ.js} +5 -5
- package/dist/{chunk-C357P37M.js → chunk-IJ3W2YBM.js} +4 -4
- package/dist/{chunk-N6PZE7HX.js → chunk-IZAEAALI.js} +2 -2
- package/dist/{chunk-PTZ6BWSU.js → chunk-KZNOT2YH.js} +2 -2
- package/dist/{chunk-P4O7L7JZ.js → chunk-L7U3G4XR.js} +2 -2
- package/dist/{chunk-EQWUCFXK.js → chunk-LBZJD2I4.js} +3 -5
- package/dist/{chunk-PRJ7P6J5.js → chunk-MMMY57UA.js} +22 -837
- package/dist/{chunk-WEGZGF3K.js → chunk-NWWTFQP2.js} +1 -1
- package/dist/{chunk-NYDM4HSS.js → chunk-QSDWWEHF.js} +2 -2
- package/dist/{chunk-3KPTVK4N.js → chunk-RAEOSDQ6.js} +1 -1
- package/dist/{chunk-E57UVUJL.js → chunk-RS5ADTDF.js} +4 -4
- package/dist/{chunk-ANMNGGTN.js → chunk-RWJ7WHTJ.js} +2 -2
- package/dist/{chunk-RDT2IV2Z.js → chunk-SJE7OWVS.js} +3 -3
- package/dist/{chunk-VLT2KGPE.js → chunk-USJ4JGDC.js} +3 -3
- package/dist/{chunk-ZCT23NBS.js → chunk-YPHDV5AS.js} +2 -2
- package/dist/{chunk-QQ3G5SXX.js → chunk-YSV43WLK.js} +1 -1
- package/dist/{chunk-4DYEBYKM.js → chunk-ZKIBD5MO.js} +2 -2
- package/dist/daemon/server.js +624 -289
- package/dist/hook-runtime/daemon/server.js +624 -289
- package/dist/hook-runtime/hooks/post-commit.js +307 -186
- package/dist/hook-runtime/hooks/post-rewrite.js +302 -181
- package/dist/hook-runtime/hooks/post-tool-use.js +490 -276
- package/dist/hook-runtime/hooks/pre-commit.js +516 -181
- package/dist/hook-runtime/hooks/pre-tool-use-worker.js +221 -7
- package/dist/hook-runtime/hooks/prim-hook.js +511 -297
- package/dist/hook-runtime/hooks/session-end.js +229 -229
- package/dist/hook-runtime/hooks/session-start.js +170 -14
- package/dist/hook-runtime/index.js +1623 -1607
- package/dist/hook-runtime/statusline-main.js +245 -124
- package/dist/hooks/post-commit.js +7 -7
- package/dist/hooks/post-rewrite.js +6 -6
- package/dist/hooks/post-tool-use.js +15 -15
- package/dist/hooks/pre-commit.js +4 -4
- package/dist/hooks/pre-tool-use-worker.js +9 -9
- package/dist/hooks/prim-hook.js +16 -16
- package/dist/hooks/session-end.js +4 -4
- package/dist/hooks/session-start.js +12 -13
- package/dist/index.js +24 -24
- package/dist/statusline-main.js +245 -124
- package/package.json +1 -1
|
@@ -591,6 +591,7 @@ import { createRequire } from "module";
|
|
|
591
591
|
import { dirname as dirname4, join as join3 } from "path";
|
|
592
592
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
593
593
|
var require2 = createRequire(import.meta.url);
|
|
594
|
+
var KEYRING_NATIVE_FILES = ["native/keyring.cjs", "native/keyring.node"];
|
|
594
595
|
|
|
595
596
|
// src/lib/paths.ts
|
|
596
597
|
import { homedir } from "os";
|
|
@@ -621,7 +622,9 @@ function primConfigDirectory(options = {}) {
|
|
|
621
622
|
}
|
|
622
623
|
|
|
623
624
|
// src/lib/hook-runtime.ts
|
|
625
|
+
var HOOK_RUNTIME_SCHEMA_VERSION = 1;
|
|
624
626
|
var RELEASE_PREFIX = "release-";
|
|
627
|
+
var RELEASE_NAME_RE = /^release-[0-9a-f]{64}$/u;
|
|
625
628
|
var MAX_MANIFEST_BYTES = 64 * 1024;
|
|
626
629
|
var RELEASE_GRACE_MS = 10 * 60 * 1e3;
|
|
627
630
|
var HOOK_RUNTIME_ENTRIES = {
|
|
@@ -664,6 +667,153 @@ function hookRuntimePaths(options = {}) {
|
|
|
664
667
|
selectionLock: join5(runtimeDir, "selection.lock")
|
|
665
668
|
};
|
|
666
669
|
}
|
|
670
|
+
function sha256(path) {
|
|
671
|
+
return createHash("sha256").update(readFileSync3(path)).digest("hex");
|
|
672
|
+
}
|
|
673
|
+
function exactManifest(manifest) {
|
|
674
|
+
return `${JSON.stringify(manifest, null, 2)}
|
|
675
|
+
`;
|
|
676
|
+
}
|
|
677
|
+
function exactKeys(value, expected) {
|
|
678
|
+
const actual = Object.keys(value).sort();
|
|
679
|
+
const wanted = [...expected].sort();
|
|
680
|
+
return actual.length === wanted.length && actual.every((key, index) => key === wanted[index]);
|
|
681
|
+
}
|
|
682
|
+
function releaseId(manifest) {
|
|
683
|
+
return createHash("sha256").update(exactManifest(manifest)).digest("hex");
|
|
684
|
+
}
|
|
685
|
+
function runtimePackageJson(manifest) {
|
|
686
|
+
return `${JSON.stringify(
|
|
687
|
+
{
|
|
688
|
+
name: "@primitive.ai/prim",
|
|
689
|
+
version: manifest.version,
|
|
690
|
+
type: "module",
|
|
691
|
+
bin: HOOK_RUNTIME_ENTRIES
|
|
692
|
+
},
|
|
693
|
+
null,
|
|
694
|
+
2
|
|
695
|
+
)}
|
|
696
|
+
`;
|
|
697
|
+
}
|
|
698
|
+
function validateRelease(releaseDir, manifest) {
|
|
699
|
+
try {
|
|
700
|
+
if (!directReleaseLayout(releaseDir, manifest)) return false;
|
|
701
|
+
if (readFileSync3(join5(releaseDir, "manifest.json"), "utf8") !== exactManifest(manifest)) {
|
|
702
|
+
return false;
|
|
703
|
+
}
|
|
704
|
+
if (readFileSync3(join5(releaseDir, "package.json"), "utf8") !== runtimePackageJson(manifest)) {
|
|
705
|
+
return false;
|
|
706
|
+
}
|
|
707
|
+
if (readFileSync3(join5(releaseDir, "node"), "utf8") !== `${manifest.nodePath}
|
|
708
|
+
`) {
|
|
709
|
+
return false;
|
|
710
|
+
}
|
|
711
|
+
for (const [bin, relativePath] of Object.entries(HOOK_RUNTIME_ENTRIES)) {
|
|
712
|
+
const target = join5(releaseDir, relativePath);
|
|
713
|
+
if (sha256(target) !== manifest.files[bin]) return false;
|
|
714
|
+
}
|
|
715
|
+
for (const [path, digest] of Object.entries(manifest.native ?? {})) {
|
|
716
|
+
if (sha256(join5(releaseDir, path)) !== digest) return false;
|
|
717
|
+
}
|
|
718
|
+
return true;
|
|
719
|
+
} catch {
|
|
720
|
+
return false;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
function directReleaseLayout(releaseDir, manifest) {
|
|
724
|
+
try {
|
|
725
|
+
const directories = /* @__PURE__ */ new Set([releaseDir]);
|
|
726
|
+
for (const relativePath of [
|
|
727
|
+
...Object.values(HOOK_RUNTIME_ENTRIES),
|
|
728
|
+
...Object.keys(manifest.native ?? {})
|
|
729
|
+
]) {
|
|
730
|
+
for (let directory = dirname5(relativePath); directory !== "."; directory = dirname5(directory)) {
|
|
731
|
+
directories.add(join5(releaseDir, directory));
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
if (![...directories].every((directory) => lstatSync(directory).isDirectory())) return false;
|
|
735
|
+
const files = [
|
|
736
|
+
"manifest.json",
|
|
737
|
+
"package.json",
|
|
738
|
+
"node",
|
|
739
|
+
...Object.values(HOOK_RUNTIME_ENTRIES),
|
|
740
|
+
...Object.keys(manifest.native ?? {})
|
|
741
|
+
];
|
|
742
|
+
const owned = /* @__PURE__ */ new Set([...directories, ...files.map((path) => join5(releaseDir, path))]);
|
|
743
|
+
if (![...directories].every(
|
|
744
|
+
(directory) => readdirSync(directory).every((name) => owned.has(join5(directory, name)))
|
|
745
|
+
))
|
|
746
|
+
return false;
|
|
747
|
+
return files.every((relativePath) => lstatSync(join5(releaseDir, relativePath)).isFile());
|
|
748
|
+
} catch {
|
|
749
|
+
return false;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
function readReleaseManifest(releaseDir, releaseName) {
|
|
753
|
+
try {
|
|
754
|
+
const manifestPath = join5(releaseDir, "manifest.json");
|
|
755
|
+
const manifestStat = statSync2(manifestPath);
|
|
756
|
+
if (!manifestStat.isFile() || manifestStat.size > MAX_MANIFEST_BYTES) return null;
|
|
757
|
+
const raw = readFileSync3(manifestPath, "utf8");
|
|
758
|
+
const parsed = JSON.parse(raw);
|
|
759
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
|
|
760
|
+
if (!exactKeys(parsed, [
|
|
761
|
+
"schemaVersion",
|
|
762
|
+
"version",
|
|
763
|
+
"nodePath",
|
|
764
|
+
"files",
|
|
765
|
+
..."native" in parsed ? ["native"] : []
|
|
766
|
+
]))
|
|
767
|
+
return null;
|
|
768
|
+
const candidate = parsed;
|
|
769
|
+
if (candidate.schemaVersion !== HOOK_RUNTIME_SCHEMA_VERSION || typeof candidate.version !== "string" || compareSemver(candidate.version, candidate.version) !== 0 || typeof candidate.nodePath !== "string" || !isAbsolute3(candidate.nodePath) || /[\r\n]/u.test(candidate.nodePath) || !candidate.files || typeof candidate.files !== "object" || Array.isArray(candidate.files) || !exactKeys(candidate.files, Object.keys(HOOK_RUNTIME_ENTRIES)) || Object.values(candidate.files).some(
|
|
770
|
+
(digest) => typeof digest !== "string" || !/^[0-9a-f]{64}$/u.test(digest)
|
|
771
|
+
)) {
|
|
772
|
+
return null;
|
|
773
|
+
}
|
|
774
|
+
if (candidate.native !== void 0 && (!candidate.native || typeof candidate.native !== "object" || Array.isArray(candidate.native) || !exactKeys(candidate.native, KEYRING_NATIVE_FILES) || Object.values(candidate.native).some(
|
|
775
|
+
(digest) => typeof digest !== "string" || !/^[a-f0-9]{64}$/u.test(digest)
|
|
776
|
+
)))
|
|
777
|
+
return null;
|
|
778
|
+
const manifest = candidate;
|
|
779
|
+
if (raw !== exactManifest(manifest) || releaseName !== `${RELEASE_PREFIX}${releaseId(manifest)}` || !validateRelease(releaseDir, manifest)) {
|
|
780
|
+
return null;
|
|
781
|
+
}
|
|
782
|
+
return manifest;
|
|
783
|
+
} catch {
|
|
784
|
+
return null;
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
function readSelectedRelease(paths) {
|
|
788
|
+
let raw;
|
|
789
|
+
try {
|
|
790
|
+
raw = readFileSync3(paths.current, "utf8");
|
|
791
|
+
} catch (error) {
|
|
792
|
+
if (error.code === "ENOENT") return null;
|
|
793
|
+
throw error;
|
|
794
|
+
}
|
|
795
|
+
const name = raw.endsWith("\n") ? raw.slice(0, -1) : "";
|
|
796
|
+
if (`${name}
|
|
797
|
+
` !== raw || !RELEASE_NAME_RE.test(name)) {
|
|
798
|
+
throw new Error("cannot stage hook runtime: selected release is malformed");
|
|
799
|
+
}
|
|
800
|
+
const dir = join5(paths.releasesDir, name);
|
|
801
|
+
const manifest = readReleaseManifest(dir, name);
|
|
802
|
+
if (!manifest) {
|
|
803
|
+
throw new Error("cannot stage hook runtime: immutable release is corrupt");
|
|
804
|
+
}
|
|
805
|
+
return { name, dir, manifest };
|
|
806
|
+
}
|
|
807
|
+
function selectedHookRuntimeKeyringLoader(options = {}) {
|
|
808
|
+
try {
|
|
809
|
+
const selected = readSelectedRelease(hookRuntimePaths(options));
|
|
810
|
+
if (!selected?.manifest.native) return void 0;
|
|
811
|
+
const loader = join5(selected.dir, "native", "keyring.cjs");
|
|
812
|
+
return existsSync4(loader) ? loader : void 0;
|
|
813
|
+
} catch {
|
|
814
|
+
return void 0;
|
|
815
|
+
}
|
|
816
|
+
}
|
|
667
817
|
var STABLE_HOOK_LAUNCHER_CONTENT = `#!/bin/sh
|
|
668
818
|
set -eu
|
|
669
819
|
case "$0" in */*) prim_launcher_dir=\${0%/*} ;; *) exit 78 ;; esac
|
|
@@ -3363,17 +3513,23 @@ function readEnvironmentContext(environment, deps) {
|
|
|
3363
3513
|
return void 0;
|
|
3364
3514
|
}
|
|
3365
3515
|
}
|
|
3366
|
-
function
|
|
3367
|
-
let directory =
|
|
3516
|
+
function keyringLoaderPath(start, options = {}) {
|
|
3517
|
+
let directory = start;
|
|
3368
3518
|
for (let depth = 0; depth < 5; depth++) {
|
|
3369
3519
|
const loader = join14(directory, "native", "keyring.cjs");
|
|
3370
|
-
if (existsSync9(loader))
|
|
3371
|
-
const module2 = require3(loader);
|
|
3372
|
-
return new module2.AsyncEntry(SERVICE, key, { linux: { store: "secret-service" } });
|
|
3373
|
-
}
|
|
3520
|
+
if (existsSync9(loader)) return loader;
|
|
3374
3521
|
directory = dirname8(directory);
|
|
3375
3522
|
}
|
|
3376
|
-
|
|
3523
|
+
try {
|
|
3524
|
+
createRequire2(join14(start, "noop.js")).resolve("@napi-rs/keyring");
|
|
3525
|
+
return void 0;
|
|
3526
|
+
} catch {
|
|
3527
|
+
return selectedHookRuntimeKeyringLoader(options);
|
|
3528
|
+
}
|
|
3529
|
+
}
|
|
3530
|
+
function keyringEntry(key) {
|
|
3531
|
+
const loader = keyringLoaderPath(dirname8(fileURLToPath4(import.meta.url)));
|
|
3532
|
+
const module = require3(loader ?? "@napi-rs/keyring");
|
|
3377
3533
|
return new module.AsyncEntry(SERVICE, key, { linux: { store: "secret-service" } });
|
|
3378
3534
|
}
|
|
3379
3535
|
function protectPath(path, directory) {
|
|
@@ -11443,7 +11599,7 @@ function hasUsableCodexGuidance(projectRoot2) {
|
|
|
11443
11599
|
}
|
|
11444
11600
|
var CURSOR_SKILL_OWNER = "@primitive.ai/prim";
|
|
11445
11601
|
var CURSOR_SKILL_MANIFEST = ".prim-owned.json";
|
|
11446
|
-
function
|
|
11602
|
+
function sha2562(content) {
|
|
11447
11603
|
return createHash10("sha256").update(content).digest("hex");
|
|
11448
11604
|
}
|
|
11449
11605
|
function cursorSkillDirectory(cwd, scope) {
|
|
@@ -11476,7 +11632,7 @@ function cursorSkillStatus(cwd, scope) {
|
|
|
11476
11632
|
const manifest = readCursorSkillManifest(paths.manifest);
|
|
11477
11633
|
const content = existsSync12(paths.skill) ? readFileSync16(paths.skill, "utf8") : void 0;
|
|
11478
11634
|
const owned = manifest !== void 0;
|
|
11479
|
-
const installed = owned && content !== void 0 &&
|
|
11635
|
+
const installed = owned && content !== void 0 && sha2562(content) === manifest.contentSha256;
|
|
11480
11636
|
return {
|
|
11481
11637
|
installed,
|
|
11482
11638
|
owned,
|
|
@@ -11675,18 +11831,18 @@ var PRINCIPAL_COMPONENT_MAX_LENGTH = 512;
|
|
|
11675
11831
|
function boundedClaim(value) {
|
|
11676
11832
|
return typeof value === "string" && value.length > 0 && value.length <= PRINCIPAL_COMPONENT_MAX_LENGTH ? value : void 0;
|
|
11677
11833
|
}
|
|
11678
|
-
function
|
|
11834
|
+
function sha2563(value) {
|
|
11679
11835
|
return createHash12("sha256").update(value).digest("hex");
|
|
11680
11836
|
}
|
|
11681
11837
|
function resolveDaemonPrincipal(token = resolveAuthCredential()?.token) {
|
|
11682
11838
|
if (hasMachineConfiguration()) {
|
|
11683
11839
|
const machine = machineContext();
|
|
11684
11840
|
return machine ? {
|
|
11685
|
-
principalId:
|
|
11841
|
+
principalId: sha2563(
|
|
11686
11842
|
`${machine.issuer}\0${machine.clientId}${machine.authorizedUserId ? `\0${machine.authorizedUserId}` : ""}`
|
|
11687
11843
|
),
|
|
11688
11844
|
organizationId: machine.workosOrganizationId,
|
|
11689
|
-
credentialFingerprint:
|
|
11845
|
+
credentialFingerprint: sha2563(machine.generation)
|
|
11690
11846
|
} : void 0;
|
|
11691
11847
|
}
|
|
11692
11848
|
if (!token) return void 0;
|
|
@@ -11696,9 +11852,9 @@ function resolveDaemonPrincipal(token = resolveAuthCredential()?.token) {
|
|
|
11696
11852
|
if (!(subject && organizationId)) return void 0;
|
|
11697
11853
|
const issuer = boundedClaim(payload?.iss) ?? "unknown-issuer";
|
|
11698
11854
|
return {
|
|
11699
|
-
principalId:
|
|
11855
|
+
principalId: sha2563(`${issuer}\0${subject}`),
|
|
11700
11856
|
organizationId,
|
|
11701
|
-
credentialFingerprint:
|
|
11857
|
+
credentialFingerprint: sha2563(token)
|
|
11702
11858
|
};
|
|
11703
11859
|
}
|
|
11704
11860
|
function daemonPrincipalsMatch(caller, daemon) {
|