@primitive.ai/prim 0.1.0-alpha.97 → 0.1.0-alpha.99
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -0
- package/dist/{chunk-ZYK3TBEW.js → chunk-25DDRMWS.js} +4 -6
- package/dist/{chunk-LY6NJ7KL.js → chunk-2IRLFOEL.js} +123 -19
- package/dist/{chunk-27ADT6FQ.js → chunk-2Q3OGSTV.js} +44 -6
- package/dist/{chunk-35FMRWJH.js → chunk-5LRKJTLA.js} +1 -1
- package/dist/{chunk-RK4ZS3HG.js → chunk-6C3CCVDI.js} +2 -2
- package/dist/{chunk-UO2U6IKF.js → chunk-7VIMU2HR.js} +1 -1
- package/dist/{chunk-OW4GJBLW.js → chunk-EJPKZT5M.js} +2 -2
- package/dist/{chunk-2MBV7ZMV.js → chunk-FK7FJPWS.js} +1 -1
- package/dist/{chunk-4GHANPWQ.js → chunk-JJI7FU24.js} +2 -2
- package/dist/{chunk-AJYZB5PF.js → chunk-JJYS7IPD.js} +3 -3
- package/dist/{chunk-Y5W4TZM7.js → chunk-K4JWJ6OM.js} +80 -269
- package/dist/{chunk-XEDJ5N3M.js → chunk-KGBMU76T.js} +2 -4
- package/dist/{chunk-7KABYYWG.js → chunk-O2WV5SQZ.js} +11 -13
- package/dist/{chunk-FBPZ4YUD.js → chunk-X5BN67D2.js} +2 -2
- package/dist/{chunk-DWRSEC34.js → chunk-XG7S3LIL.js} +596 -16
- package/dist/{chunk-3I4GEWXQ.js → chunk-XPS6LG6I.js} +8 -12
- package/dist/{chunk-QNPTWTBG.js → chunk-ZNLIGT3J.js} +2 -2
- package/dist/daemon/server.js +247 -180
- package/dist/hook-runtime/daemon/server.js +247 -180
- package/dist/hook-runtime/hooks/post-commit.js +114 -59
- package/dist/hook-runtime/hooks/post-rewrite.js +109 -54
- package/dist/hook-runtime/hooks/post-tool-use.js +256 -156
- package/dist/hook-runtime/hooks/pre-commit.js +374 -31
- package/dist/hook-runtime/hooks/pre-tool-use.js +237 -137
- package/dist/hook-runtime/hooks/prim-hook.js +281 -181
- package/dist/hook-runtime/hooks/session-start.js +209 -109
- package/dist/hook-runtime/index.js +656 -521
- package/dist/hook-runtime/statusline-main.js +71 -16
- package/dist/hooks/post-commit.js +7 -8
- package/dist/hooks/post-rewrite.js +6 -7
- package/dist/hooks/post-tool-use.js +13 -14
- package/dist/hooks/pre-commit.js +4 -4
- package/dist/hooks/pre-tool-use.js +11 -14
- package/dist/hooks/prim-hook.js +14 -15
- package/dist/hooks/session-end.js +6 -7
- package/dist/hooks/session-start.js +13 -14
- package/dist/index.js +33 -35
- package/dist/statusline-main.js +71 -16
- package/package.json +1 -1
- package/dist/chunk-DHOQGHKQ.js +0 -379
|
@@ -52,15 +52,15 @@ var require_ucs2length = __commonJS({
|
|
|
52
52
|
});
|
|
53
53
|
|
|
54
54
|
// src/daemon/server.ts
|
|
55
|
-
import { chmodSync as chmodSync7, existsSync as
|
|
55
|
+
import { chmodSync as chmodSync7, existsSync as existsSync10, mkdirSync as mkdirSync8, readFileSync as readFileSync10, unlinkSync as unlinkSync3 } from "fs";
|
|
56
56
|
import { createServer } from "net";
|
|
57
|
-
import { join as
|
|
58
|
-
import { fileURLToPath } from "url";
|
|
57
|
+
import { join as join15 } from "path";
|
|
58
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
59
59
|
|
|
60
60
|
// src/client.ts
|
|
61
61
|
import { createHash as createHash2 } from "crypto";
|
|
62
|
-
import { chmodSync, existsSync as
|
|
63
|
-
import { dirname as
|
|
62
|
+
import { chmodSync as chmodSync2, existsSync as existsSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync5, rmSync as rmSync3 } from "fs";
|
|
63
|
+
import { dirname as dirname4 } from "path";
|
|
64
64
|
|
|
65
65
|
// src/lib/atomic-file.ts
|
|
66
66
|
import { randomUUID } from "crypto";
|
|
@@ -599,6 +599,149 @@ async function withFileLock(lockDir, operation, options = {}) {
|
|
|
599
599
|
}
|
|
600
600
|
}
|
|
601
601
|
|
|
602
|
+
// src/daemon/client-instance-id.ts
|
|
603
|
+
import { randomBytes as randomBytes2 } from "crypto";
|
|
604
|
+
import { chmodSync, lstatSync, readFileSync as readFileSync3 } from "fs";
|
|
605
|
+
import { join as join4 } from "path";
|
|
606
|
+
var CONFIG_DIRECTORY_MODE = 448;
|
|
607
|
+
var INSTANCE_FILE_MODE = 384;
|
|
608
|
+
var INSTANCE_ENTROPY_BYTES = 32;
|
|
609
|
+
var INSTANCE_BODY_CHARS = 43;
|
|
610
|
+
var INSTANCE_PREFIX = "pci_";
|
|
611
|
+
var CLIENT_INSTANCE_ID_RE = /^pci_[A-Za-z0-9_-]{43}$/u;
|
|
612
|
+
var MAX_STORED_BYTES = INSTANCE_PREFIX.length + INSTANCE_BODY_CHARS + 1;
|
|
613
|
+
function isClientInstanceId(value) {
|
|
614
|
+
return typeof value === "string" && CLIENT_INSTANCE_ID_RE.test(value);
|
|
615
|
+
}
|
|
616
|
+
function ensurePrivateConfigDirectory(configDir) {
|
|
617
|
+
ensureDurableDirectory(configDir, CONFIG_DIRECTORY_MODE);
|
|
618
|
+
const metadata = lstatSync(configDir);
|
|
619
|
+
if (!metadata.isDirectory() || metadata.isSymbolicLink()) {
|
|
620
|
+
throw new Error("prim config path must be a private directory");
|
|
621
|
+
}
|
|
622
|
+
chmodSync(configDir, CONFIG_DIRECTORY_MODE);
|
|
623
|
+
syncDirectory(configDir);
|
|
624
|
+
}
|
|
625
|
+
function readExisting(path) {
|
|
626
|
+
let metadata;
|
|
627
|
+
try {
|
|
628
|
+
metadata = lstatSync(path);
|
|
629
|
+
} catch (error) {
|
|
630
|
+
if (error.code === "ENOENT") {
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
633
|
+
throw error;
|
|
634
|
+
}
|
|
635
|
+
if (!metadata.isFile() || metadata.isSymbolicLink()) {
|
|
636
|
+
throw new Error("stored client instance identity is invalid");
|
|
637
|
+
}
|
|
638
|
+
chmodSync(path, INSTANCE_FILE_MODE);
|
|
639
|
+
if (metadata.size > MAX_STORED_BYTES) {
|
|
640
|
+
throw new Error("stored client instance identity is invalid");
|
|
641
|
+
}
|
|
642
|
+
const raw = readFileSync3(path, "utf8");
|
|
643
|
+
const value = raw.endsWith("\n") ? raw.slice(0, -1) : raw;
|
|
644
|
+
if (raw !== value && raw !== `${value}
|
|
645
|
+
` || !isClientInstanceId(value)) {
|
|
646
|
+
throw new Error("stored client instance identity is invalid");
|
|
647
|
+
}
|
|
648
|
+
return value;
|
|
649
|
+
}
|
|
650
|
+
function atomicWrite(path, value) {
|
|
651
|
+
atomicWriteFile(path, `${value}
|
|
652
|
+
`, { mode: INSTANCE_FILE_MODE });
|
|
653
|
+
}
|
|
654
|
+
async function getOrCreateClientInstanceId(options) {
|
|
655
|
+
const configDir = options.configDir;
|
|
656
|
+
const path = join4(configDir, "client_instance_id");
|
|
657
|
+
const lockPath = join4(configDir, "client-instance.lock");
|
|
658
|
+
ensurePrivateConfigDirectory(configDir);
|
|
659
|
+
return withFileLock(
|
|
660
|
+
lockPath,
|
|
661
|
+
() => {
|
|
662
|
+
const existing = readExisting(path);
|
|
663
|
+
if (existing !== void 0) {
|
|
664
|
+
return existing;
|
|
665
|
+
}
|
|
666
|
+
const generated = `${INSTANCE_PREFIX}${randomBytes2(INSTANCE_ENTROPY_BYTES).toString(
|
|
667
|
+
"base64url"
|
|
668
|
+
)}`;
|
|
669
|
+
if (!isClientInstanceId(generated)) {
|
|
670
|
+
throw new Error("generated client instance identity is invalid");
|
|
671
|
+
}
|
|
672
|
+
atomicWrite(path, generated);
|
|
673
|
+
return generated;
|
|
674
|
+
},
|
|
675
|
+
options.lockOptions
|
|
676
|
+
);
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
// src/lib/bin-path.ts
|
|
680
|
+
import { existsSync as existsSync2, readFileSync as readFileSync4 } from "fs";
|
|
681
|
+
import { dirname as dirname3, isAbsolute as isAbsolute2, join as join5 } from "path";
|
|
682
|
+
import { fileURLToPath } from "url";
|
|
683
|
+
var PKG_NAME = "@primitive.ai/prim";
|
|
684
|
+
var ROOT_WALK_LIMIT = 6;
|
|
685
|
+
var resolvedRoot;
|
|
686
|
+
function locateRoot() {
|
|
687
|
+
if (resolvedRoot !== void 0) {
|
|
688
|
+
return resolvedRoot;
|
|
689
|
+
}
|
|
690
|
+
let dir = dirname3(fileURLToPath(import.meta.url));
|
|
691
|
+
for (let depth = 0; depth < ROOT_WALK_LIMIT; depth++) {
|
|
692
|
+
const manifestPath = join5(dir, "package.json");
|
|
693
|
+
if (existsSync2(manifestPath)) {
|
|
694
|
+
try {
|
|
695
|
+
const manifest = JSON.parse(readFileSync4(manifestPath, "utf-8"));
|
|
696
|
+
if (manifest.name === PKG_NAME && manifest.bin) {
|
|
697
|
+
resolvedRoot = { dir, version: manifest.version, bin: manifest.bin };
|
|
698
|
+
return resolvedRoot;
|
|
699
|
+
}
|
|
700
|
+
} catch {
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
const parent = dirname3(dir);
|
|
704
|
+
if (parent === dir) {
|
|
705
|
+
break;
|
|
706
|
+
}
|
|
707
|
+
dir = parent;
|
|
708
|
+
}
|
|
709
|
+
resolvedRoot = null;
|
|
710
|
+
return resolvedRoot;
|
|
711
|
+
}
|
|
712
|
+
function packageVersion() {
|
|
713
|
+
return locateRoot()?.version ?? null;
|
|
714
|
+
}
|
|
715
|
+
var PRIM_CONFIG_SHELL_RESOLVER = [
|
|
716
|
+
'prim_absolute() { case "$1" in [/]* ) ;; *) return 1 ;; esac; case "$1" in [[:space:]]*|*[[:space:]]|*[/][/]*|*[/].[/]*|*[/]..[/]*|*[/].|*[/]..|?*[/]) return 1 ;; esac; }; ',
|
|
717
|
+
'prim_config=${PRIM_CONFIG_DIR:-}; if ! prim_absolute "$prim_config"; then prim_config=${XDG_CONFIG_HOME:-}; if prim_absolute "$prim_config"; then ',
|
|
718
|
+
'case "$prim_config" in /) prim_config=/prim ;; *) prim_config="$prim_config/prim" ;; esac; ',
|
|
719
|
+
'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; ',
|
|
720
|
+
"fi; fi; "
|
|
721
|
+
].join("");
|
|
722
|
+
|
|
723
|
+
// src/lib/ingest-uploader.ts
|
|
724
|
+
var runtimeVersion = process.env.PRIM_RUNTIME_VERSION ?? packageVersion();
|
|
725
|
+
var VERSION_RE = /^\d+\.\d+\.\d+(?:-[A-Za-z0-9.-]+)?(?:\+[A-Za-z0-9.-]+)?$/u;
|
|
726
|
+
var instanceId;
|
|
727
|
+
async function ingestUploaderHeaders() {
|
|
728
|
+
const headers = {};
|
|
729
|
+
if (runtimeVersion && runtimeVersion.length <= 64 && VERSION_RE.test(runtimeVersion)) {
|
|
730
|
+
headers["X-Prim-Uploader-Version"] = runtimeVersion;
|
|
731
|
+
}
|
|
732
|
+
instanceId ??= getOrCreateClientInstanceId({
|
|
733
|
+
configDir: primConfigDirectory(),
|
|
734
|
+
// Attribution must not consume the upload deadline waiting for another process.
|
|
735
|
+
lockOptions: { timeoutMs: 0 }
|
|
736
|
+
}).catch(() => {
|
|
737
|
+
instanceId = void 0;
|
|
738
|
+
return void 0;
|
|
739
|
+
});
|
|
740
|
+
const id = await instanceId;
|
|
741
|
+
if (id) headers["X-Prim-Client-Instance-Id"] = id;
|
|
742
|
+
return headers;
|
|
743
|
+
}
|
|
744
|
+
|
|
602
745
|
// src/lib/terminal-safe.ts
|
|
603
746
|
function replaceIsolatedSurrogates(value) {
|
|
604
747
|
let out = "";
|
|
@@ -649,7 +792,7 @@ var DEFAULT_API_URL = "https://api.getprimitive.ai";
|
|
|
649
792
|
var AUTH_EXPIRED_MESSAGE = "Authentication expired. Run `prim auth login` to re-authenticate.";
|
|
650
793
|
function readTrimmed2(path) {
|
|
651
794
|
try {
|
|
652
|
-
const value =
|
|
795
|
+
const value = readFileSync5(path, "utf8").trim();
|
|
653
796
|
return value || void 0;
|
|
654
797
|
} catch {
|
|
655
798
|
return void 0;
|
|
@@ -665,16 +808,16 @@ function expiresAtFor(token, expiresIn) {
|
|
|
665
808
|
return expiresIn === void 0 ? jwtExpiresAt(token) : Date.now() + expiresIn * 1e3;
|
|
666
809
|
}
|
|
667
810
|
function ensureConfigDirectory() {
|
|
668
|
-
const directory =
|
|
811
|
+
const directory = dirname4(TOKEN_FILE_PATH);
|
|
669
812
|
mkdirSync3(directory, { recursive: true, mode: CONFIG_DIR_MODE });
|
|
670
|
-
|
|
813
|
+
chmodSync2(directory, CONFIG_DIR_MODE);
|
|
671
814
|
}
|
|
672
|
-
function
|
|
815
|
+
function atomicWrite2(path, content) {
|
|
673
816
|
ensureConfigDirectory();
|
|
674
817
|
atomicWriteFile(path, content, { mode: CREDENTIAL_FILE_MODE });
|
|
675
818
|
}
|
|
676
819
|
function removeCredentialFile(path) {
|
|
677
|
-
if (!
|
|
820
|
+
if (!existsSync3(path)) return false;
|
|
678
821
|
rmSync3(path, { force: true });
|
|
679
822
|
return true;
|
|
680
823
|
}
|
|
@@ -708,7 +851,7 @@ function credentialFamilyMetadata(accessToken, refreshToken2, metadata) {
|
|
|
708
851
|
return metadata === void 0 ? legacyBrokerCredentialMetadata(accessToken, refreshToken2) : { ...metadata, ...hashes };
|
|
709
852
|
}
|
|
710
853
|
function writeCredentialMigrationSentinel() {
|
|
711
|
-
|
|
854
|
+
atomicWrite2(
|
|
712
855
|
CREDENTIAL_MIGRATION_PATH,
|
|
713
856
|
`${JSON.stringify({
|
|
714
857
|
version: CREDENTIAL_MIGRATION_VERSION,
|
|
@@ -726,7 +869,7 @@ function bindLegacyBrokerGeneration(accessToken, refreshToken2, metadata) {
|
|
|
726
869
|
return { state: "invalid" };
|
|
727
870
|
}
|
|
728
871
|
if (metadata.metadata === void 0) {
|
|
729
|
-
|
|
872
|
+
atomicWrite2(CREDENTIAL_FAMILY_PATH, `${JSON.stringify(familyMetadata)}
|
|
730
873
|
`);
|
|
731
874
|
}
|
|
732
875
|
const migrationState = readCredentialMigrationState();
|
|
@@ -741,14 +884,14 @@ function preserveMarkerlessLegacyGeneration() {
|
|
|
741
884
|
const refreshToken2 = readTrimmed2(REFRESH_TOKEN_PATH);
|
|
742
885
|
if (!(accessToken && refreshToken2)) return;
|
|
743
886
|
const familyMetadata = legacyBrokerCredentialMetadata(accessToken, refreshToken2);
|
|
744
|
-
|
|
887
|
+
atomicWrite2(CREDENTIAL_FAMILY_PATH, `${JSON.stringify(familyMetadata)}
|
|
745
888
|
`);
|
|
746
889
|
}
|
|
747
890
|
function terminalFingerprint() {
|
|
748
891
|
return readTrimmed2(TERMINAL_REFRESH_PATH);
|
|
749
892
|
}
|
|
750
893
|
function writeTerminalFingerprint(refreshToken2) {
|
|
751
|
-
|
|
894
|
+
atomicWrite2(TERMINAL_REFRESH_PATH, `${refreshFingerprint(refreshToken2)}
|
|
752
895
|
`);
|
|
753
896
|
}
|
|
754
897
|
function clearTerminalFingerprint() {
|
|
@@ -773,24 +916,24 @@ function commitCredentialsUnlocked(credentials) {
|
|
|
773
916
|
if (credentials.metadata !== void 0) {
|
|
774
917
|
preserveMarkerlessLegacyGeneration();
|
|
775
918
|
writeCredentialMigrationSentinel();
|
|
776
|
-
|
|
919
|
+
atomicWrite2(CREDENTIAL_FAMILY_PATH, `${JSON.stringify(familyMetadata)}
|
|
777
920
|
`);
|
|
778
|
-
|
|
921
|
+
atomicWrite2(CREDENTIAL_METADATA_PATH, `${JSON.stringify(familyMetadata)}
|
|
779
922
|
`);
|
|
780
|
-
|
|
923
|
+
atomicWrite2(REFRESH_TOKEN_PATH, `${refreshToken2}
|
|
781
924
|
`);
|
|
782
925
|
} else {
|
|
783
|
-
|
|
926
|
+
atomicWrite2(REFRESH_TOKEN_PATH, `${refreshToken2}
|
|
784
927
|
`);
|
|
785
|
-
|
|
928
|
+
atomicWrite2(CREDENTIAL_FAMILY_PATH, `${JSON.stringify(familyMetadata)}
|
|
786
929
|
`);
|
|
787
930
|
removeCredentialFile(CREDENTIAL_METADATA_PATH);
|
|
788
931
|
}
|
|
789
932
|
const expiresAt = expiresAtFor(accessToken, credentials.expiresIn);
|
|
790
933
|
if (expiresAt === void 0) removeCredentialFile(TOKEN_EXPIRES_PATH);
|
|
791
|
-
else
|
|
934
|
+
else atomicWrite2(TOKEN_EXPIRES_PATH, `${expiresAt}
|
|
792
935
|
`);
|
|
793
|
-
|
|
936
|
+
atomicWrite2(TOKEN_FILE_PATH, `${accessToken}
|
|
794
937
|
`);
|
|
795
938
|
clearTerminalFingerprint();
|
|
796
939
|
_cachedCredential = { token: accessToken, source: "token_file" };
|
|
@@ -1024,12 +1167,13 @@ function selectedCredential() {
|
|
|
1024
1167
|
}
|
|
1025
1168
|
return _cachedCredential;
|
|
1026
1169
|
}
|
|
1027
|
-
function fetchWithToken(method, path, body, options, token, siteUrl) {
|
|
1170
|
+
async function fetchWithToken(method, path, body, options, token, siteUrl) {
|
|
1028
1171
|
return fetch(`${siteUrl}${path}`, {
|
|
1029
1172
|
method,
|
|
1030
1173
|
headers: {
|
|
1031
1174
|
Authorization: `Bearer ${token}`,
|
|
1032
|
-
"Content-Type": "application/json"
|
|
1175
|
+
"Content-Type": "application/json",
|
|
1176
|
+
...method === "POST" && path === "/api/cli/moves/ingest" ? await ingestUploaderHeaders() : {}
|
|
1033
1177
|
},
|
|
1034
1178
|
body: body === void 0 ? void 0 : JSON.stringify(body),
|
|
1035
1179
|
signal: options?.signal
|
|
@@ -1113,15 +1257,15 @@ async function getPinnedClient(options = {}) {
|
|
|
1113
1257
|
|
|
1114
1258
|
// src/flusher.ts
|
|
1115
1259
|
import { createReadStream, renameSync as renameSync3, statSync as statSync2, unlinkSync } from "fs";
|
|
1116
|
-
import { dirname as
|
|
1260
|
+
import { dirname as dirname9, join as join11 } from "path";
|
|
1117
1261
|
|
|
1118
1262
|
// src/dead-letter.ts
|
|
1119
|
-
import { createHash as createHash3, randomBytes as
|
|
1263
|
+
import { createHash as createHash3, randomBytes as randomBytes3 } from "crypto";
|
|
1120
1264
|
import {
|
|
1121
1265
|
constants as constants2,
|
|
1122
|
-
chmodSync as
|
|
1266
|
+
chmodSync as chmodSync3,
|
|
1123
1267
|
closeSync as closeSync2,
|
|
1124
|
-
existsSync as
|
|
1268
|
+
existsSync as existsSync4,
|
|
1125
1269
|
fchmodSync as fchmodSync2,
|
|
1126
1270
|
fsyncSync as fsyncSync2,
|
|
1127
1271
|
mkdirSync as mkdirSync4,
|
|
@@ -1130,32 +1274,32 @@ import {
|
|
|
1130
1274
|
rmSync as rmSync4,
|
|
1131
1275
|
writeFileSync as writeFileSync3
|
|
1132
1276
|
} from "fs";
|
|
1133
|
-
import { dirname as
|
|
1277
|
+
import { dirname as dirname5, join as join7 } from "path";
|
|
1134
1278
|
var DIRECTORY_MODE2 = 448;
|
|
1135
1279
|
var FILE_MODE2 = 384;
|
|
1136
1280
|
var DEAD_LETTER_DIRNAME = "dead-letter";
|
|
1137
1281
|
function deadLetterDirectoryForRotation(flushingPath) {
|
|
1138
|
-
return
|
|
1282
|
+
return join7(dirname5(flushingPath), DEAD_LETTER_DIRNAME);
|
|
1139
1283
|
}
|
|
1140
1284
|
function deadLetterPathForRawLine(flushingPath, rawLine) {
|
|
1141
1285
|
const quarantineId = createHash3("sha256").update(rawLine).digest("hex");
|
|
1142
|
-
return
|
|
1286
|
+
return join7(deadLetterDirectoryForRotation(flushingPath), `raw-${quarantineId}.json`);
|
|
1143
1287
|
}
|
|
1144
1288
|
function ensureDeadLetterDirectory(flushingPath, persistDirectory) {
|
|
1145
1289
|
const directory = deadLetterDirectoryForRotation(flushingPath);
|
|
1146
1290
|
mkdirSync4(directory, { recursive: true, mode: DIRECTORY_MODE2 });
|
|
1147
|
-
|
|
1148
|
-
persistDirectory(
|
|
1291
|
+
chmodSync3(directory, DIRECTORY_MODE2);
|
|
1292
|
+
persistDirectory(dirname5(directory));
|
|
1149
1293
|
return directory;
|
|
1150
1294
|
}
|
|
1151
1295
|
function persistDeadLetter(directory, path, quarantineId, record, persistDirectory) {
|
|
1152
|
-
if (
|
|
1296
|
+
if (existsSync4(path)) {
|
|
1153
1297
|
persistDirectory(directory);
|
|
1154
1298
|
return;
|
|
1155
1299
|
}
|
|
1156
|
-
const temporaryPath =
|
|
1300
|
+
const temporaryPath = join7(
|
|
1157
1301
|
directory,
|
|
1158
|
-
`.${quarantineId}.${String(process.pid)}.${
|
|
1302
|
+
`.${quarantineId}.${String(process.pid)}.${randomBytes3(8).toString("hex")}.tmp`
|
|
1159
1303
|
);
|
|
1160
1304
|
const flags = constants2.O_CREAT | constants2.O_EXCL | constants2.O_WRONLY | constants2.O_NOFOLLOW;
|
|
1161
1305
|
try {
|
|
@@ -1185,7 +1329,7 @@ function quarantineMove(flushingPath, move, reason, now = Date.now, options = {}
|
|
|
1185
1329
|
reason,
|
|
1186
1330
|
move
|
|
1187
1331
|
};
|
|
1188
|
-
const path =
|
|
1332
|
+
const path = join7(directory, `${record.quarantineId}.json`);
|
|
1189
1333
|
persistDeadLetter(directory, path, record.quarantineId, record, persistDirectory);
|
|
1190
1334
|
return record;
|
|
1191
1335
|
}
|
|
@@ -1215,14 +1359,14 @@ function quarantineRawLine(flushingPath, rawLine, now = Date.now, options = {})
|
|
|
1215
1359
|
|
|
1216
1360
|
// src/drain-progress.ts
|
|
1217
1361
|
import {
|
|
1218
|
-
chmodSync as
|
|
1219
|
-
existsSync as
|
|
1220
|
-
readFileSync as
|
|
1362
|
+
chmodSync as chmodSync4,
|
|
1363
|
+
existsSync as existsSync5,
|
|
1364
|
+
readFileSync as readFileSync6,
|
|
1221
1365
|
readdirSync,
|
|
1222
1366
|
rmSync as rmSync5,
|
|
1223
1367
|
rmdirSync
|
|
1224
1368
|
} from "fs";
|
|
1225
|
-
import { basename, dirname as
|
|
1369
|
+
import { basename, dirname as dirname6, join as join8 } from "path";
|
|
1226
1370
|
var DIRECTORY_MODE3 = 448;
|
|
1227
1371
|
var FILE_MODE3 = 384;
|
|
1228
1372
|
var DRAIN_PROGRESS_DIRNAME = "drain-progress";
|
|
@@ -1231,10 +1375,10 @@ function rotationIdentity(stat) {
|
|
|
1231
1375
|
return { size: stat.size, ino: stat.ino, dev: stat.dev };
|
|
1232
1376
|
}
|
|
1233
1377
|
function drainProgressDirectory(flushingPath) {
|
|
1234
|
-
return
|
|
1378
|
+
return join8(dirname6(flushingPath), DRAIN_PROGRESS_DIRNAME);
|
|
1235
1379
|
}
|
|
1236
1380
|
function drainProgressPath(flushingPath) {
|
|
1237
|
-
return
|
|
1381
|
+
return join8(drainProgressDirectory(flushingPath), `${basename(flushingPath)}.json`);
|
|
1238
1382
|
}
|
|
1239
1383
|
function isByteCount(value) {
|
|
1240
1384
|
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
@@ -1242,7 +1386,7 @@ function isByteCount(value) {
|
|
|
1242
1386
|
function drainResumeOffset(flushingPath, rotation) {
|
|
1243
1387
|
let parsed;
|
|
1244
1388
|
try {
|
|
1245
|
-
parsed = JSON.parse(
|
|
1389
|
+
parsed = JSON.parse(readFileSync6(drainProgressPath(flushingPath), "utf8"));
|
|
1246
1390
|
} catch {
|
|
1247
1391
|
return 0;
|
|
1248
1392
|
}
|
|
@@ -1258,7 +1402,7 @@ function drainResumeOffset(flushingPath, rotation) {
|
|
|
1258
1402
|
function writeDrainCheckpoint(flushingPath, checkpoint) {
|
|
1259
1403
|
const directory = drainProgressDirectory(flushingPath);
|
|
1260
1404
|
ensureDurableDirectory(directory, DIRECTORY_MODE3);
|
|
1261
|
-
|
|
1405
|
+
chmodSync4(directory, DIRECTORY_MODE3);
|
|
1262
1406
|
atomicWriteFile(drainProgressPath(flushingPath), `${JSON.stringify(checkpoint)}
|
|
1263
1407
|
`, {
|
|
1264
1408
|
mode: FILE_MODE3
|
|
@@ -1279,7 +1423,7 @@ function removeDrainCheckpoint(flushingPath) {
|
|
|
1279
1423
|
removeEmptyDirectory(drainProgressDirectory(flushingPath));
|
|
1280
1424
|
}
|
|
1281
1425
|
function sweepOrphanedDrainCheckpoints(bucketDirectory) {
|
|
1282
|
-
const directory =
|
|
1426
|
+
const directory = join8(bucketDirectory, DRAIN_PROGRESS_DIRNAME);
|
|
1283
1427
|
let names;
|
|
1284
1428
|
try {
|
|
1285
1429
|
names = readdirSync(directory);
|
|
@@ -1288,11 +1432,11 @@ function sweepOrphanedDrainCheckpoints(bucketDirectory) {
|
|
|
1288
1432
|
}
|
|
1289
1433
|
for (const name of names) {
|
|
1290
1434
|
const rotation = CHECKPOINT_NAME.exec(name)?.[1];
|
|
1291
|
-
if (rotation === void 0 ||
|
|
1435
|
+
if (rotation === void 0 || existsSync5(join8(bucketDirectory, rotation))) {
|
|
1292
1436
|
continue;
|
|
1293
1437
|
}
|
|
1294
1438
|
try {
|
|
1295
|
-
rmSync5(
|
|
1439
|
+
rmSync5(join8(directory, name), { force: true });
|
|
1296
1440
|
} catch {
|
|
1297
1441
|
}
|
|
1298
1442
|
}
|
|
@@ -19520,15 +19664,15 @@ validate68.evaluated = { "props": true, "dynamicProps": false, "dynamicItems": f
|
|
|
19520
19664
|
|
|
19521
19665
|
// src/lib/activation.ts
|
|
19522
19666
|
import { execFileSync as execFileSync2 } from "child_process";
|
|
19523
|
-
import { existsSync as
|
|
19667
|
+
import { existsSync as existsSync6, readFileSync as readFileSync7 } from "fs";
|
|
19524
19668
|
import { homedir as homedir2 } from "os";
|
|
19525
|
-
import { join as
|
|
19669
|
+
import { join as join9 } from "path";
|
|
19526
19670
|
|
|
19527
19671
|
// src/lib/git.ts
|
|
19528
19672
|
import { execFileSync } from "child_process";
|
|
19529
19673
|
import { createHash as createHash4 } from "crypto";
|
|
19530
|
-
import { lstatSync, realpathSync } from "fs";
|
|
19531
|
-
import { basename as basename2, dirname as
|
|
19674
|
+
import { lstatSync as lstatSync2, realpathSync } from "fs";
|
|
19675
|
+
import { basename as basename2, dirname as dirname7, isAbsolute as isAbsolute3, relative, resolve as resolve2, sep } from "path";
|
|
19532
19676
|
var GIT_TIMEOUT_MS = 1e3;
|
|
19533
19677
|
var GITHUB_OWNER_PATTERN = /^(?![A-Za-z0-9-]*--)[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/u;
|
|
19534
19678
|
var GITHUB_REPOSITORY_PATTERN = /^[A-Za-z0-9._-]{1,100}$/u;
|
|
@@ -19638,10 +19782,10 @@ function hasProjectPrimInstall(cwd) {
|
|
|
19638
19782
|
const root = gitToplevel(cwd);
|
|
19639
19783
|
if (root === null || root === homedir2()) return false;
|
|
19640
19784
|
for (const rel of PROJECT_INSTALL_FILES) {
|
|
19641
|
-
const path =
|
|
19642
|
-
if (
|
|
19785
|
+
const path = join9(root, rel);
|
|
19786
|
+
if (existsSync6(path)) {
|
|
19643
19787
|
try {
|
|
19644
|
-
const content =
|
|
19788
|
+
const content = readFileSync7(path, "utf-8");
|
|
19645
19789
|
if (PRIM_HOOK_BINS.some((bin) => content.includes(bin))) return true;
|
|
19646
19790
|
} catch {
|
|
19647
19791
|
}
|
|
@@ -19991,17 +20135,17 @@ async function inspectJournalDelivery(buckets, options = {}) {
|
|
|
19991
20135
|
import {
|
|
19992
20136
|
appendFileSync,
|
|
19993
20137
|
closeSync as closeSync3,
|
|
19994
|
-
existsSync as
|
|
20138
|
+
existsSync as existsSync7,
|
|
19995
20139
|
fstatSync,
|
|
19996
20140
|
mkdirSync as mkdirSync5,
|
|
19997
20141
|
openSync as openSync3,
|
|
19998
20142
|
opendirSync,
|
|
19999
|
-
readFileSync as
|
|
20143
|
+
readFileSync as readFileSync8,
|
|
20000
20144
|
readSync,
|
|
20001
20145
|
readdirSync as readdirSync2
|
|
20002
20146
|
} from "fs";
|
|
20003
|
-
import { dirname as
|
|
20004
|
-
var JOURNAL_DIR =
|
|
20147
|
+
import { dirname as dirname8, join as join10 } from "path";
|
|
20148
|
+
var JOURNAL_DIR = join10(primConfigDirectory(), "moves");
|
|
20005
20149
|
var JOURNAL_BASENAME = "journal.ndjson";
|
|
20006
20150
|
var JOURNAL_STATS_SAMPLE_BYTES = 64 * 1024;
|
|
20007
20151
|
var PENDING_STATS_MAX_FILES = 128;
|
|
@@ -20013,7 +20157,7 @@ function envSlug(apiUrl) {
|
|
|
20013
20157
|
return slug;
|
|
20014
20158
|
}
|
|
20015
20159
|
function currentEnvDir() {
|
|
20016
|
-
return
|
|
20160
|
+
return join10(JOURNAL_DIR, envSlug(getSiteUrl()));
|
|
20017
20161
|
}
|
|
20018
20162
|
function parseMoves(content) {
|
|
20019
20163
|
const moves = [];
|
|
@@ -20031,15 +20175,15 @@ function parseMoves(content) {
|
|
|
20031
20175
|
function listBuckets() {
|
|
20032
20176
|
const out = [];
|
|
20033
20177
|
const envDir = currentEnvDir();
|
|
20034
|
-
if (!
|
|
20178
|
+
if (!existsSync7(envDir)) {
|
|
20035
20179
|
return out;
|
|
20036
20180
|
}
|
|
20037
20181
|
for (const entry of readdirSync2(envDir, { withFileTypes: true })) {
|
|
20038
20182
|
if (!entry.isDirectory()) {
|
|
20039
20183
|
continue;
|
|
20040
20184
|
}
|
|
20041
|
-
const path =
|
|
20042
|
-
if (
|
|
20185
|
+
const path = join10(envDir, entry.name, JOURNAL_BASENAME);
|
|
20186
|
+
if (existsSync7(path)) {
|
|
20043
20187
|
out.push({ bucket: entry.name, path });
|
|
20044
20188
|
}
|
|
20045
20189
|
}
|
|
@@ -20101,7 +20245,7 @@ function parseFlushingPid(name) {
|
|
|
20101
20245
|
return Number.isSafeInteger(pid) && pid > 0 ? pid : void 0;
|
|
20102
20246
|
}
|
|
20103
20247
|
function listFlushingInDir(dir, bucket, options = {}) {
|
|
20104
|
-
if (!
|
|
20248
|
+
if (!existsSync7(dir)) {
|
|
20105
20249
|
return [];
|
|
20106
20250
|
}
|
|
20107
20251
|
const out = [];
|
|
@@ -20115,7 +20259,7 @@ function listFlushingInDir(dir, bucket, options = {}) {
|
|
|
20115
20259
|
entry = entries.readSync();
|
|
20116
20260
|
continue;
|
|
20117
20261
|
}
|
|
20118
|
-
const path =
|
|
20262
|
+
const path = join10(dir, entry.name);
|
|
20119
20263
|
let sample;
|
|
20120
20264
|
try {
|
|
20121
20265
|
sample = sampleJournalFile(path, remainingBytes, { fromDrainCheckpoint: true });
|
|
@@ -20142,7 +20286,7 @@ function listFlushingInDir(dir, bucket, options = {}) {
|
|
|
20142
20286
|
}
|
|
20143
20287
|
function listFlushing(options = {}) {
|
|
20144
20288
|
const envDir = currentEnvDir();
|
|
20145
|
-
if (!
|
|
20289
|
+
if (!existsSync7(envDir)) {
|
|
20146
20290
|
return [];
|
|
20147
20291
|
}
|
|
20148
20292
|
const out = [];
|
|
@@ -20153,7 +20297,7 @@ function listFlushing(options = {}) {
|
|
|
20153
20297
|
break;
|
|
20154
20298
|
}
|
|
20155
20299
|
if (entry.isDirectory()) {
|
|
20156
|
-
const found = listFlushingInDir(
|
|
20300
|
+
const found = listFlushingInDir(join10(envDir, entry.name), entry.name, {
|
|
20157
20301
|
sampleBytes: remainingBytes,
|
|
20158
20302
|
maxFiles: maxFiles - out.length
|
|
20159
20303
|
});
|
|
@@ -20168,12 +20312,12 @@ function listFlushing(options = {}) {
|
|
|
20168
20312
|
}
|
|
20169
20313
|
function sweepOrphanedDrainProgress() {
|
|
20170
20314
|
const envDir = currentEnvDir();
|
|
20171
|
-
if (!
|
|
20315
|
+
if (!existsSync7(envDir)) {
|
|
20172
20316
|
return;
|
|
20173
20317
|
}
|
|
20174
20318
|
for (const entry of readdirSync2(envDir, { withFileTypes: true })) {
|
|
20175
20319
|
if (entry.isDirectory()) {
|
|
20176
|
-
sweepOrphanedDrainCheckpoints(
|
|
20320
|
+
sweepOrphanedDrainCheckpoints(join10(envDir, entry.name));
|
|
20177
20321
|
}
|
|
20178
20322
|
}
|
|
20179
20323
|
}
|
|
@@ -20571,7 +20715,7 @@ async function flushOnce() {
|
|
|
20571
20715
|
return inspection.retainedBuckets.length > 0 ? { flushed: total, quarantined, retained: inspection.retainedBuckets } : { flushed: total, quarantined };
|
|
20572
20716
|
}
|
|
20573
20717
|
var flushInFlight;
|
|
20574
|
-
var FLUSH_LOCK_PATH =
|
|
20718
|
+
var FLUSH_LOCK_PATH = join11(dirname9(JOURNAL_DIR), ".flush.lock");
|
|
20575
20719
|
var FLUSH_LOCK_TIMEOUT_MS = 250;
|
|
20576
20720
|
function isFlushLockContended(error) {
|
|
20577
20721
|
return error instanceof Error && error.message.startsWith("timed out waiting for file lock");
|
|
@@ -20771,86 +20915,9 @@ var StatuslineIngestionCache = class {
|
|
|
20771
20915
|
}
|
|
20772
20916
|
};
|
|
20773
20917
|
|
|
20774
|
-
// src/daemon/client-instance-id.ts
|
|
20775
|
-
import { randomBytes as randomBytes3 } from "crypto";
|
|
20776
|
-
import { chmodSync as chmodSync4, lstatSync as lstatSync2, readFileSync as readFileSync7 } from "fs";
|
|
20777
|
-
import { join as join10 } from "path";
|
|
20778
|
-
var CONFIG_DIRECTORY_MODE = 448;
|
|
20779
|
-
var INSTANCE_FILE_MODE = 384;
|
|
20780
|
-
var INSTANCE_ENTROPY_BYTES = 32;
|
|
20781
|
-
var INSTANCE_BODY_CHARS = 43;
|
|
20782
|
-
var INSTANCE_PREFIX = "pci_";
|
|
20783
|
-
var CLIENT_INSTANCE_ID_RE = /^pci_[A-Za-z0-9_-]{43}$/u;
|
|
20784
|
-
var MAX_STORED_BYTES = INSTANCE_PREFIX.length + INSTANCE_BODY_CHARS + 1;
|
|
20785
|
-
function isClientInstanceId(value) {
|
|
20786
|
-
return typeof value === "string" && CLIENT_INSTANCE_ID_RE.test(value);
|
|
20787
|
-
}
|
|
20788
|
-
function ensurePrivateConfigDirectory(configDir) {
|
|
20789
|
-
ensureDurableDirectory(configDir, CONFIG_DIRECTORY_MODE);
|
|
20790
|
-
const metadata = lstatSync2(configDir);
|
|
20791
|
-
if (!metadata.isDirectory() || metadata.isSymbolicLink()) {
|
|
20792
|
-
throw new Error("prim config path must be a private directory");
|
|
20793
|
-
}
|
|
20794
|
-
chmodSync4(configDir, CONFIG_DIRECTORY_MODE);
|
|
20795
|
-
syncDirectory(configDir);
|
|
20796
|
-
}
|
|
20797
|
-
function readExisting(path) {
|
|
20798
|
-
let metadata;
|
|
20799
|
-
try {
|
|
20800
|
-
metadata = lstatSync2(path);
|
|
20801
|
-
} catch (error) {
|
|
20802
|
-
if (error.code === "ENOENT") {
|
|
20803
|
-
return;
|
|
20804
|
-
}
|
|
20805
|
-
throw error;
|
|
20806
|
-
}
|
|
20807
|
-
if (!metadata.isFile() || metadata.isSymbolicLink()) {
|
|
20808
|
-
throw new Error("stored client instance identity is invalid");
|
|
20809
|
-
}
|
|
20810
|
-
chmodSync4(path, INSTANCE_FILE_MODE);
|
|
20811
|
-
if (metadata.size > MAX_STORED_BYTES) {
|
|
20812
|
-
throw new Error("stored client instance identity is invalid");
|
|
20813
|
-
}
|
|
20814
|
-
const raw = readFileSync7(path, "utf8");
|
|
20815
|
-
const value = raw.endsWith("\n") ? raw.slice(0, -1) : raw;
|
|
20816
|
-
if (raw !== value && raw !== `${value}
|
|
20817
|
-
` || !isClientInstanceId(value)) {
|
|
20818
|
-
throw new Error("stored client instance identity is invalid");
|
|
20819
|
-
}
|
|
20820
|
-
return value;
|
|
20821
|
-
}
|
|
20822
|
-
function atomicWrite2(path, value) {
|
|
20823
|
-
atomicWriteFile(path, `${value}
|
|
20824
|
-
`, { mode: INSTANCE_FILE_MODE });
|
|
20825
|
-
}
|
|
20826
|
-
async function getOrCreateClientInstanceId(options) {
|
|
20827
|
-
const configDir = options.configDir;
|
|
20828
|
-
const path = join10(configDir, "client_instance_id");
|
|
20829
|
-
const lockPath = join10(configDir, "client-instance.lock");
|
|
20830
|
-
ensurePrivateConfigDirectory(configDir);
|
|
20831
|
-
return withFileLock(
|
|
20832
|
-
lockPath,
|
|
20833
|
-
() => {
|
|
20834
|
-
const existing = readExisting(path);
|
|
20835
|
-
if (existing !== void 0) {
|
|
20836
|
-
return existing;
|
|
20837
|
-
}
|
|
20838
|
-
const generated = `${INSTANCE_PREFIX}${randomBytes3(INSTANCE_ENTROPY_BYTES).toString(
|
|
20839
|
-
"base64url"
|
|
20840
|
-
)}`;
|
|
20841
|
-
if (!isClientInstanceId(generated)) {
|
|
20842
|
-
throw new Error("generated client instance identity is invalid");
|
|
20843
|
-
}
|
|
20844
|
-
atomicWrite2(path, generated);
|
|
20845
|
-
return generated;
|
|
20846
|
-
},
|
|
20847
|
-
options.lockOptions
|
|
20848
|
-
);
|
|
20849
|
-
}
|
|
20850
|
-
|
|
20851
20918
|
// src/daemon/client.ts
|
|
20852
20919
|
import { createConnection } from "net";
|
|
20853
|
-
import { join as
|
|
20920
|
+
import { join as join12 } from "path";
|
|
20854
20921
|
|
|
20855
20922
|
// src/daemon/principal.ts
|
|
20856
20923
|
import { createHash as createHash5 } from "crypto";
|
|
@@ -20927,7 +20994,7 @@ function parseDaemonResponseEnvelope(value) {
|
|
|
20927
20994
|
}
|
|
20928
20995
|
|
|
20929
20996
|
// src/daemon/client.ts
|
|
20930
|
-
var SOCK_PATH =
|
|
20997
|
+
var SOCK_PATH = join12(primConfigDirectory(), "sock");
|
|
20931
20998
|
var DEFAULT_TIMEOUT_MS2 = 250;
|
|
20932
20999
|
var nextRequestId = 1;
|
|
20933
21000
|
function daemonRequest(method, params = {}, opts = {}) {
|
|
@@ -21196,8 +21263,8 @@ function assertCallerEnvMatches(callerEnv, boundEnv) {
|
|
|
21196
21263
|
}
|
|
21197
21264
|
|
|
21198
21265
|
// src/daemon/health.ts
|
|
21199
|
-
import { chmodSync as chmodSync5, existsSync as
|
|
21200
|
-
import { dirname as
|
|
21266
|
+
import { chmodSync as chmodSync5, existsSync as existsSync8, mkdirSync as mkdirSync6, renameSync as renameSync4, writeFileSync as writeFileSync4 } from "fs";
|
|
21267
|
+
import { dirname as dirname10, join as join13 } from "path";
|
|
21201
21268
|
var CONFIG_DIR_MODE2 = 448;
|
|
21202
21269
|
var HEALTH_FILE_MODE = 384;
|
|
21203
21270
|
var INGESTION_SLA_MS = 3e4;
|
|
@@ -21205,7 +21272,7 @@ var HEARTBEAT_FRESH_MS = 9e4;
|
|
|
21205
21272
|
var HEARTBEAT_RETRY_CAP_MS = 3e4;
|
|
21206
21273
|
var INGESTION_RETRY_BASE_MS = 5e3;
|
|
21207
21274
|
var INGESTION_RETRY_CAP_MS = 15e3;
|
|
21208
|
-
var DAEMON_HEALTH_PATH =
|
|
21275
|
+
var DAEMON_HEALTH_PATH = join13(primConfigDirectory(), "daemon-health.json");
|
|
21209
21276
|
function createDaemonHealthState(version, pid, startedAt2, siteUrl) {
|
|
21210
21277
|
return {
|
|
21211
21278
|
schemaVersion: 1,
|
|
@@ -21246,11 +21313,11 @@ function ingestionRetryDelayMs(consecutiveFailures, random = Math.random) {
|
|
|
21246
21313
|
return retryDelayMs(consecutiveFailures, INGESTION_RETRY_CAP_MS, random);
|
|
21247
21314
|
}
|
|
21248
21315
|
function writeDaemonHealthState(state, path = DAEMON_HEALTH_PATH) {
|
|
21249
|
-
const dir =
|
|
21250
|
-
if (!
|
|
21316
|
+
const dir = dirname10(path);
|
|
21317
|
+
if (!existsSync8(dir)) {
|
|
21251
21318
|
mkdirSync6(dir, { recursive: true, mode: CONFIG_DIR_MODE2 });
|
|
21252
21319
|
}
|
|
21253
|
-
const tmp =
|
|
21320
|
+
const tmp = join13(dir, `.${process.pid}.daemon-health.tmp`);
|
|
21254
21321
|
writeFileSync4(tmp, `${JSON.stringify(state, null, 2)}
|
|
21255
21322
|
`, { mode: HEALTH_FILE_MODE });
|
|
21256
21323
|
chmodSync5(tmp, HEALTH_FILE_MODE);
|
|
@@ -21261,22 +21328,22 @@ function writeDaemonHealthState(state, path = DAEMON_HEALTH_PATH) {
|
|
|
21261
21328
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
21262
21329
|
import {
|
|
21263
21330
|
chmodSync as chmodSync6,
|
|
21264
|
-
existsSync as
|
|
21331
|
+
existsSync as existsSync9,
|
|
21265
21332
|
mkdirSync as mkdirSync7,
|
|
21266
|
-
readFileSync as
|
|
21333
|
+
readFileSync as readFileSync9,
|
|
21267
21334
|
renameSync as renameSync5,
|
|
21268
21335
|
rmSync as rmSync6,
|
|
21269
21336
|
statSync as statSync3,
|
|
21270
21337
|
unlinkSync as unlinkSync2,
|
|
21271
21338
|
writeFileSync as writeFileSync5
|
|
21272
21339
|
} from "fs";
|
|
21273
|
-
import { join as
|
|
21340
|
+
import { join as join14 } from "path";
|
|
21274
21341
|
var DIR_MODE = 448;
|
|
21275
21342
|
var FILE_MODE4 = 384;
|
|
21276
21343
|
var DAEMON_STARTUP_GRACE_MS = 5e3;
|
|
21277
21344
|
function readLockRecord(path) {
|
|
21278
21345
|
try {
|
|
21279
|
-
const value = JSON.parse(
|
|
21346
|
+
const value = JSON.parse(readFileSync9(path, "utf-8"));
|
|
21280
21347
|
if (Number.isSafeInteger(value.pid) && value.pid > 0 && typeof value.instanceId === "string" && typeof value.startedAt === "number") {
|
|
21281
21348
|
return value;
|
|
21282
21349
|
}
|
|
@@ -21286,17 +21353,17 @@ function readLockRecord(path) {
|
|
|
21286
21353
|
}
|
|
21287
21354
|
function numericPid(path) {
|
|
21288
21355
|
try {
|
|
21289
|
-
const pid = Number(
|
|
21356
|
+
const pid = Number(readFileSync9(path, "utf-8").trim());
|
|
21290
21357
|
return Number.isSafeInteger(pid) && pid > 0 ? pid : void 0;
|
|
21291
21358
|
} catch {
|
|
21292
21359
|
return;
|
|
21293
21360
|
}
|
|
21294
21361
|
}
|
|
21295
21362
|
function readDaemonOwner(configDir) {
|
|
21296
|
-
return readLockRecord(
|
|
21363
|
+
return readLockRecord(join14(configDir, "daemon.lock", "owner.json"));
|
|
21297
21364
|
}
|
|
21298
21365
|
function readDaemonPid(configDir) {
|
|
21299
|
-
const path =
|
|
21366
|
+
const path = join14(configDir, "daemon.pid");
|
|
21300
21367
|
const pid = numericPid(path);
|
|
21301
21368
|
if (pid === void 0) {
|
|
21302
21369
|
return;
|
|
@@ -21311,11 +21378,11 @@ function acquireDaemonOwnership(configDir, opts = {}) {
|
|
|
21311
21378
|
const pid = opts.pid ?? process.pid;
|
|
21312
21379
|
const now = opts.now ?? Date.now();
|
|
21313
21380
|
const isAlive = opts.isAlive ?? processIsAlive;
|
|
21314
|
-
const lockDir =
|
|
21315
|
-
const ownerPath2 =
|
|
21316
|
-
const pidPath =
|
|
21317
|
-
const
|
|
21318
|
-
if (!
|
|
21381
|
+
const lockDir = join14(configDir, "daemon.lock");
|
|
21382
|
+
const ownerPath2 = join14(lockDir, "owner.json");
|
|
21383
|
+
const pidPath = join14(configDir, "daemon.pid");
|
|
21384
|
+
const instanceId2 = randomUUID2();
|
|
21385
|
+
if (!existsSync9(configDir)) {
|
|
21319
21386
|
mkdirSync7(configDir, { recursive: true, mode: DIR_MODE });
|
|
21320
21387
|
}
|
|
21321
21388
|
for (; ; ) {
|
|
@@ -21344,7 +21411,7 @@ function acquireDaemonOwnership(configDir, opts = {}) {
|
|
|
21344
21411
|
throw new Error("daemon startup already in progress");
|
|
21345
21412
|
}
|
|
21346
21413
|
}
|
|
21347
|
-
const stale = `${lockDir}.stale.${String(pid)}.${
|
|
21414
|
+
const stale = `${lockDir}.stale.${String(pid)}.${instanceId2}`;
|
|
21348
21415
|
try {
|
|
21349
21416
|
renameSync5(lockDir, stale);
|
|
21350
21417
|
rmSync6(stale, { recursive: true, force: true });
|
|
@@ -21361,9 +21428,9 @@ function acquireDaemonOwnership(configDir, opts = {}) {
|
|
|
21361
21428
|
ownerPath: ownerPath2,
|
|
21362
21429
|
pidPath,
|
|
21363
21430
|
pid,
|
|
21364
|
-
instanceId
|
|
21431
|
+
instanceId: instanceId2
|
|
21365
21432
|
};
|
|
21366
|
-
const record = { pid, instanceId, startedAt: now };
|
|
21433
|
+
const record = { pid, instanceId: instanceId2, startedAt: now };
|
|
21367
21434
|
writeFileSync5(ownerPath2, `${JSON.stringify(record)}
|
|
21368
21435
|
`, { mode: FILE_MODE4 });
|
|
21369
21436
|
chmodSync6(ownerPath2, FILE_MODE4);
|
|
@@ -21458,7 +21525,7 @@ function normalizePresenceHeartbeatResponse(value) {
|
|
|
21458
21525
|
}
|
|
21459
21526
|
|
|
21460
21527
|
// src/daemon/statusline-protocol.ts
|
|
21461
|
-
import { isAbsolute as
|
|
21528
|
+
import { isAbsolute as isAbsolute4 } from "path";
|
|
21462
21529
|
var STATUSLINE_PROTOCOL_PREFIX = Buffer.from("prim-statusline-v1\0", "utf8");
|
|
21463
21530
|
var STATUSLINE_REQUEST_MAX_BYTES = 64 * 1024;
|
|
21464
21531
|
var utf8Decoder = new TextDecoder("utf-8", { fatal: true });
|
|
@@ -21487,7 +21554,7 @@ function parseStatuslineRequest(buffer) {
|
|
|
21487
21554
|
try {
|
|
21488
21555
|
const cwd = utf8Decoder.decode(buffer.subarray(STATUSLINE_PROTOCOL_PREFIX.length, cwdEnd));
|
|
21489
21556
|
const primApiUrl = utf8Decoder.decode(buffer.subarray(cwdEnd + 1, apiUrlEnd));
|
|
21490
|
-
if (!cwd || !
|
|
21557
|
+
if (!cwd || !isAbsolute4(cwd)) {
|
|
21491
21558
|
return { state: "invalid" };
|
|
21492
21559
|
}
|
|
21493
21560
|
return { state: "complete", request: { cwd, primApiUrl } };
|
|
@@ -21498,7 +21565,7 @@ function parseStatuslineRequest(buffer) {
|
|
|
21498
21565
|
|
|
21499
21566
|
// src/daemon/server.ts
|
|
21500
21567
|
var CONFIG_DIR = primConfigDirectory();
|
|
21501
|
-
var SOCK_PATH2 =
|
|
21568
|
+
var SOCK_PATH2 = join15(CONFIG_DIR, "sock");
|
|
21502
21569
|
var CONFIG_DIR_MODE3 = 448;
|
|
21503
21570
|
var SOCKET_MODE = 384;
|
|
21504
21571
|
var MAX_SOCKET_CONNECTIONS = 64;
|
|
@@ -21514,8 +21581,8 @@ var EXIT_OK = 0;
|
|
|
21514
21581
|
var EXIT_CRASH = 1;
|
|
21515
21582
|
var startedAt = Date.now();
|
|
21516
21583
|
var client = getClient();
|
|
21517
|
-
var
|
|
21518
|
-
var daemonHealth = createDaemonHealthState(
|
|
21584
|
+
var runtimeVersion2 = resolveRuntimeVersion();
|
|
21585
|
+
var daemonHealth = createDaemonHealthState(runtimeVersion2, process.pid, startedAt, getSiteUrl());
|
|
21519
21586
|
var statuslineIngestionCache = new StatuslineIngestionCache(decisionIngestionStatus, {
|
|
21520
21587
|
resolveRepositoryBindingState: repositoryBindingState
|
|
21521
21588
|
});
|
|
@@ -21566,8 +21633,8 @@ function resolveRuntimeVersion() {
|
|
|
21566
21633
|
return process.env.PRIM_RUNTIME_VERSION;
|
|
21567
21634
|
}
|
|
21568
21635
|
try {
|
|
21569
|
-
const here =
|
|
21570
|
-
const pkg = JSON.parse(
|
|
21636
|
+
const here = fileURLToPath2(new URL(".", import.meta.url));
|
|
21637
|
+
const pkg = JSON.parse(readFileSync10(join15(here, "..", "..", "package.json"), "utf-8"));
|
|
21571
21638
|
return pkg.version ?? "unknown";
|
|
21572
21639
|
} catch {
|
|
21573
21640
|
return "unknown";
|
|
@@ -21693,7 +21760,7 @@ async function takeOwnership() {
|
|
|
21693
21760
|
(pid) => pid !== void 0 && processIsAlive(pid)
|
|
21694
21761
|
)
|
|
21695
21762
|
);
|
|
21696
|
-
if (
|
|
21763
|
+
if (existsSync10(SOCK_PATH2) || candidatePids.size > 0) {
|
|
21697
21764
|
const snapshot = await daemonRequest(
|
|
21698
21765
|
"status_snapshot",
|
|
21699
21766
|
{},
|
|
@@ -21968,7 +22035,7 @@ function handleStatusSnapshot(params, caller, enforcePrincipal = false) {
|
|
|
21968
22035
|
uptimeMs: Date.now() - startedAt,
|
|
21969
22036
|
sessionId: activeSessionId,
|
|
21970
22037
|
lastHeartbeatAt,
|
|
21971
|
-
version:
|
|
22038
|
+
version: runtimeVersion2,
|
|
21972
22039
|
launchRevision: process.env.PRIM_LAUNCH_REVISION,
|
|
21973
22040
|
healthy: daemonHealth.healthy,
|
|
21974
22041
|
needsReauth: daemonHealth.needsReauth === true,
|
|
@@ -22167,7 +22234,7 @@ function handleConnection(conn) {
|
|
|
22167
22234
|
!isCrossEnv(callerEnv, getSiteUrl())
|
|
22168
22235
|
);
|
|
22169
22236
|
const line = formatStatusline(
|
|
22170
|
-
|
|
22237
|
+
runtimeVersion2,
|
|
22171
22238
|
snapshot,
|
|
22172
22239
|
() => statuslineIngestionCache.get(parsed.request.cwd),
|
|
22173
22240
|
{
|
|
@@ -22240,7 +22307,7 @@ function startSocketServer() {
|
|
|
22240
22307
|
`);
|
|
22241
22308
|
startTimers();
|
|
22242
22309
|
process.stderr.write(
|
|
22243
|
-
`[prim-daemon] started (pid=${process.pid}, session=${activeSessionId}, version=${
|
|
22310
|
+
`[prim-daemon] started (pid=${process.pid}, session=${activeSessionId}, version=${runtimeVersion2})
|
|
22244
22311
|
`
|
|
22245
22312
|
);
|
|
22246
22313
|
});
|