@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
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
import { createRequire as __primCreateRequire } from "node:module"; const require = __primCreateRequire(import.meta.url);
|
|
3
3
|
|
|
4
4
|
// src/commands/statusline.ts
|
|
5
|
-
import { readFileSync as
|
|
6
|
-
import { dirname as
|
|
7
|
-
import { fileURLToPath as
|
|
5
|
+
import { readFileSync as readFileSync13 } from "fs";
|
|
6
|
+
import { dirname as dirname9, resolve as resolve4 } from "path";
|
|
7
|
+
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
8
8
|
|
|
9
9
|
// src/lib/cloud-env.ts
|
|
10
10
|
function isClaudeCloudSession(env = process.env) {
|
|
@@ -14,9 +14,9 @@ var CLOUD_REJECTED_CREDENTIALS_REMEDY = 'correct the credentials in the cloud en
|
|
|
14
14
|
var CLOUD_REJECTED_CREDENTIALS_NOTICE = `Primitive is not connected in this Claude Code cloud session: its credentials were rejected. To fix it, ${CLOUD_REJECTED_CREDENTIALS_REMEDY}.`;
|
|
15
15
|
|
|
16
16
|
// src/client.ts
|
|
17
|
-
import { createHash as
|
|
18
|
-
import { chmodSync as
|
|
19
|
-
import { dirname as
|
|
17
|
+
import { createHash as createHash8 } from "crypto";
|
|
18
|
+
import { chmodSync as chmodSync4, existsSync as existsSync6, mkdirSync as mkdirSync5, readFileSync as readFileSync10, rmSync as rmSync8 } from "fs";
|
|
19
|
+
import { dirname as dirname8 } from "path";
|
|
20
20
|
|
|
21
21
|
// src/lib/atomic-file.ts
|
|
22
22
|
import { randomUUID } from "crypto";
|
|
@@ -34,26 +34,26 @@ import {
|
|
|
34
34
|
import { dirname } from "path";
|
|
35
35
|
|
|
36
36
|
// src/lib/credentials.ts
|
|
37
|
-
import { createHash as
|
|
38
|
-
import { readFileSync as
|
|
39
|
-
import { join as
|
|
37
|
+
import { createHash as createHash7 } from "crypto";
|
|
38
|
+
import { readFileSync as readFileSync8 } from "fs";
|
|
39
|
+
import { join as join11 } from "path";
|
|
40
40
|
|
|
41
41
|
// src/lib/machine-credentials.ts
|
|
42
42
|
import { execFileSync as execFileSync2 } from "child_process";
|
|
43
|
-
import { createHash as
|
|
43
|
+
import { createHash as createHash6, randomBytes as randomBytes4, randomUUID as randomUUID2 } from "crypto";
|
|
44
44
|
import {
|
|
45
|
-
chmodSync,
|
|
46
|
-
existsSync as
|
|
45
|
+
chmodSync as chmodSync2,
|
|
46
|
+
existsSync as existsSync5,
|
|
47
47
|
linkSync,
|
|
48
|
-
lstatSync as
|
|
49
|
-
mkdirSync as
|
|
50
|
-
readFileSync as
|
|
51
|
-
rmSync as
|
|
52
|
-
writeFileSync as
|
|
48
|
+
lstatSync as lstatSync5,
|
|
49
|
+
mkdirSync as mkdirSync4,
|
|
50
|
+
readFileSync as readFileSync7,
|
|
51
|
+
rmSync as rmSync7,
|
|
52
|
+
writeFileSync as writeFileSync4
|
|
53
53
|
} from "fs";
|
|
54
|
-
import { createRequire } from "module";
|
|
55
|
-
import { dirname as
|
|
56
|
-
import { fileURLToPath as
|
|
54
|
+
import { createRequire as createRequire2 } from "module";
|
|
55
|
+
import { dirname as dirname7, join as join10 } from "path";
|
|
56
|
+
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
57
57
|
|
|
58
58
|
// src/lib/file-lock.ts
|
|
59
59
|
import { randomBytes } from "crypto";
|
|
@@ -61,13 +61,27 @@ import { existsSync, mkdirSync as mkdirSync2, readFileSync, rmSync as rmSync2, s
|
|
|
61
61
|
import { dirname as dirname2, join } from "path";
|
|
62
62
|
var syncSleeper = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT));
|
|
63
63
|
|
|
64
|
-
// src/lib/
|
|
65
|
-
import {
|
|
66
|
-
import {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
64
|
+
// src/lib/hook-runtime.ts
|
|
65
|
+
import { createHash, randomBytes as randomBytes2 } from "crypto";
|
|
66
|
+
import {
|
|
67
|
+
constants as constants2,
|
|
68
|
+
accessSync,
|
|
69
|
+
chmodSync,
|
|
70
|
+
copyFileSync,
|
|
71
|
+
existsSync as existsSync4,
|
|
72
|
+
lstatSync,
|
|
73
|
+
mkdirSync as mkdirSync3,
|
|
74
|
+
mkdtempSync,
|
|
75
|
+
readFileSync as readFileSync3,
|
|
76
|
+
readdirSync,
|
|
77
|
+
realpathSync,
|
|
78
|
+
renameSync as renameSync2,
|
|
79
|
+
rmSync as rmSync3,
|
|
80
|
+
statSync as statSync2,
|
|
81
|
+
utimesSync,
|
|
82
|
+
writeFileSync as writeFileSync3
|
|
83
|
+
} from "fs";
|
|
84
|
+
import { delimiter, dirname as dirname5, isAbsolute as isAbsolute3, join as join5, resolve } from "path";
|
|
71
85
|
|
|
72
86
|
// src/lib/bin-path.ts
|
|
73
87
|
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
|
|
@@ -75,6 +89,7 @@ import { dirname as dirname3, isAbsolute, join as join2 } from "path";
|
|
|
75
89
|
import { fileURLToPath } from "url";
|
|
76
90
|
var PKG_NAME = "@primitive.ai/prim";
|
|
77
91
|
var ROOT_WALK_LIMIT = 6;
|
|
92
|
+
var STABLE_HOOK_LAUNCHER_NAME = "prim-hook-launcher-v1";
|
|
78
93
|
var resolvedRoot;
|
|
79
94
|
function locateRoot() {
|
|
80
95
|
if (resolvedRoot !== void 0) {
|
|
@@ -113,6 +128,140 @@ var PRIM_CONFIG_SHELL_RESOLVER = [
|
|
|
113
128
|
"fi; fi; "
|
|
114
129
|
].join("");
|
|
115
130
|
|
|
131
|
+
// src/lib/git-hook-contract.ts
|
|
132
|
+
var GIT_HOOK_ENTRYPOINT_CONTENT = `#!/bin/sh
|
|
133
|
+
# prim git hook entrypoint v1 \u2014 managed by prim; do not edit.
|
|
134
|
+
# Run by the "# >>> prim <hook> hook >>>" block in a Git hook file. Acts only
|
|
135
|
+
# where prim is active (git config prim.active true) and never fails the hook.
|
|
136
|
+
case "$0" in */*) prim_dir=\${0%/*} ;; *) exit 0 ;; esac
|
|
137
|
+
prim_launcher="$prim_dir/${STABLE_HOOK_LAUNCHER_NAME}"
|
|
138
|
+
[ -x "$prim_launcher" ] || exit 0
|
|
139
|
+
[ "$(git config --get prim.active 2>/dev/null)" = "true" ] || exit 0
|
|
140
|
+
prim_hook=\${1-}
|
|
141
|
+
if [ "$#" -gt 0 ]; then shift; fi
|
|
142
|
+
case "$prim_hook" in
|
|
143
|
+
pre-commit)
|
|
144
|
+
"$prim_launcher" prim-pre-commit "$@" || :
|
|
145
|
+
;;
|
|
146
|
+
post-commit)
|
|
147
|
+
prim_sha=$(git rev-parse --verify HEAD 2>/dev/null) || exit 0
|
|
148
|
+
case "$prim_sha" in *[!0-9a-f]* | "") exit 0 ;; esac
|
|
149
|
+
case "\${#prim_sha}" in 40 | 64) ;; *) exit 0 ;; esac
|
|
150
|
+
prim_branch=$(git symbolic-ref --quiet --short HEAD 2>/dev/null) || prim_branch=
|
|
151
|
+
prim_observed=$(mktemp "\${TMPDIR:-/tmp}/prim-post-commit-observed.XXXXXXXX" 2>/dev/null) || prim_observed=
|
|
152
|
+
(
|
|
153
|
+
trap '' HUP
|
|
154
|
+
trap 'if [ -n "$prim_observed" ]; then rm -f "$prim_observed"; fi' 0
|
|
155
|
+
PRIM_COMMIT_SHA=$prim_sha PRIM_COMMIT_BRANCH=$prim_branch PRIM_COMMIT_OBSERVED_FILE=$prim_observed "$prim_launcher" prim-post-commit
|
|
156
|
+
) </dev/null >/dev/null 2>&1 &
|
|
157
|
+
;;
|
|
158
|
+
post-rewrite)
|
|
159
|
+
case "\${1-}" in amend | rebase) prim_source=$1 ;; *) exit 0 ;; esac
|
|
160
|
+
prim_pairs=$(mktemp "\${TMPDIR:-/tmp}/prim-post-rewrite-pairs.XXXXXXXX" 2>/dev/null) || exit 0
|
|
161
|
+
if ! chmod 600 "$prim_pairs" 2>/dev/null || ! cat >"$prim_pairs"; then
|
|
162
|
+
rm -f "$prim_pairs"
|
|
163
|
+
exit 0
|
|
164
|
+
fi
|
|
165
|
+
prim_branch=$(git symbolic-ref --quiet --short HEAD 2>/dev/null) || prim_branch=
|
|
166
|
+
(
|
|
167
|
+
trap '' HUP
|
|
168
|
+
trap 'rm -f "$prim_pairs"' 0
|
|
169
|
+
PRIM_REWRITE_SOURCE=$prim_source PRIM_REWRITE_BRANCH=$prim_branch PRIM_REWRITE_PAIRS_FILE=$prim_pairs "$prim_launcher" prim-post-rewrite
|
|
170
|
+
) </dev/null >/dev/null 2>&1 &
|
|
171
|
+
;;
|
|
172
|
+
esac
|
|
173
|
+
exit 0
|
|
174
|
+
`;
|
|
175
|
+
|
|
176
|
+
// src/lib/native-keyring.ts
|
|
177
|
+
import { existsSync as existsSync3 } from "fs";
|
|
178
|
+
import { createRequire } from "module";
|
|
179
|
+
import { dirname as dirname4, join as join3 } from "path";
|
|
180
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
181
|
+
var require2 = createRequire(import.meta.url);
|
|
182
|
+
|
|
183
|
+
// src/lib/paths.ts
|
|
184
|
+
import { homedir } from "os";
|
|
185
|
+
import { isAbsolute as isAbsolute2, join as join4, normalize } from "path";
|
|
186
|
+
var UNSAFE_CONFIG_PATH_CHARACTERS = /[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/u;
|
|
187
|
+
function absolutePath(value, variable) {
|
|
188
|
+
if (value !== void 0 && UNSAFE_CONFIG_PATH_CHARACTERS.test(value)) {
|
|
189
|
+
throw new Error(`${variable} contains unsafe characters`);
|
|
190
|
+
}
|
|
191
|
+
if (!value || value.trim() !== value || !isAbsolute2(value)) return;
|
|
192
|
+
const normalized = normalize(value);
|
|
193
|
+
return normalized === value ? value : void 0;
|
|
194
|
+
}
|
|
195
|
+
function resolvePrimConfigDirectory(options = {}) {
|
|
196
|
+
const env = options.env ?? process.env;
|
|
197
|
+
const explicit = absolutePath(env.PRIM_CONFIG_DIR, "PRIM_CONFIG_DIR");
|
|
198
|
+
if (explicit) return { path: explicit, source: "explicit" };
|
|
199
|
+
const xdgConfigHome = absolutePath(env.XDG_CONFIG_HOME, "XDG_CONFIG_HOME");
|
|
200
|
+
if (xdgConfigHome) return { path: join4(xdgConfigHome, "prim"), source: "xdg" };
|
|
201
|
+
const home = absolutePath(options.homeDir ?? homedir(), "HOME");
|
|
202
|
+
if (!home) {
|
|
203
|
+
throw new Error("cannot resolve Primitive config directory: HOME is not an absolute path");
|
|
204
|
+
}
|
|
205
|
+
return { path: join4(home, ".config", "prim"), source: "default" };
|
|
206
|
+
}
|
|
207
|
+
function primConfigDirectory(options = {}) {
|
|
208
|
+
return resolvePrimConfigDirectory(options).path;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// src/lib/hook-runtime.ts
|
|
212
|
+
var RELEASE_PREFIX = "release-";
|
|
213
|
+
var MAX_MANIFEST_BYTES = 64 * 1024;
|
|
214
|
+
var RELEASE_GRACE_MS = 10 * 60 * 1e3;
|
|
215
|
+
var HOOK_RUNTIME_ENTRIES = {
|
|
216
|
+
// SessionStart self-healing resolves this exact CLI entry to run
|
|
217
|
+
// `daemon ensure`; it must travel with the immutable hook release.
|
|
218
|
+
prim: "dist/index.js",
|
|
219
|
+
"prim-hook": "dist/hooks/prim-hook.js",
|
|
220
|
+
"prim-pre-commit": "dist/hooks/pre-commit.js",
|
|
221
|
+
"prim-post-commit": "dist/hooks/post-commit.js",
|
|
222
|
+
"prim-post-rewrite": "dist/hooks/post-rewrite.js",
|
|
223
|
+
"prim-pre-tool-use-worker": "dist/hooks/pre-tool-use-worker.js",
|
|
224
|
+
"prim-pre-tool-use": "dist/hooks/pre-tool-use.js",
|
|
225
|
+
"prim-post-tool-use": "dist/hooks/post-tool-use.js",
|
|
226
|
+
"prim-session-start": "dist/hooks/session-start.js",
|
|
227
|
+
"prim-session-end": "dist/hooks/session-end.js",
|
|
228
|
+
"prim-daemon-server": "dist/daemon/server.js",
|
|
229
|
+
"prim-statusline": "dist/statusline-main.js"
|
|
230
|
+
};
|
|
231
|
+
var SOURCE_ENTRIES = Object.fromEntries(
|
|
232
|
+
Object.entries(HOOK_RUNTIME_ENTRIES).map(([bin, target]) => [
|
|
233
|
+
bin,
|
|
234
|
+
target.replace(/^dist\//u, "")
|
|
235
|
+
])
|
|
236
|
+
);
|
|
237
|
+
var STABLE_HOOK_LAUNCHER_CONTENT = `#!/bin/sh
|
|
238
|
+
set -eu
|
|
239
|
+
case "$0" in */*) prim_launcher_dir=\${0%/*} ;; *) exit 78 ;; esac
|
|
240
|
+
IFS= read -r prim_release_name < "$prim_launcher_dir/hook-runtime/current" || exit 69
|
|
241
|
+
case "$prim_release_name" in ${RELEASE_PREFIX}*) ;; *) exit 69 ;; esac
|
|
242
|
+
prim_release_id=\${prim_release_name#${RELEASE_PREFIX}}
|
|
243
|
+
case "$prim_release_id" in *[!0-9a-f]*|"") exit 69 ;; esac
|
|
244
|
+
[ "\${#prim_release_id}" -eq 64 ] || exit 69
|
|
245
|
+
prim_release="$prim_launcher_dir/hook-runtime/releases/$prim_release_name"
|
|
246
|
+
case "\${1-}" in
|
|
247
|
+
${Object.entries(HOOK_RUNTIME_ENTRIES).map(([bin, entry]) => ` ${bin}) prim_entry="$prim_release/${entry}" ;;`).join("\n")}
|
|
248
|
+
*) exit 64 ;;
|
|
249
|
+
esac
|
|
250
|
+
shift
|
|
251
|
+
IFS= read -r prim_node < "$prim_release/node" || exit 69
|
|
252
|
+
case "$prim_node" in /*) ;; *) exit 69 ;; esac
|
|
253
|
+
[ -x "$prim_node" ] && [ -f "$prim_entry" ] || exit 69
|
|
254
|
+
exec "$prim_node" "$prim_entry" "$@"
|
|
255
|
+
`;
|
|
256
|
+
|
|
257
|
+
// src/lib/machine-broker.ts
|
|
258
|
+
import { spawn } from "child_process";
|
|
259
|
+
import { createHash as createHash2, createHmac, randomBytes as randomBytes3, timingSafeEqual } from "crypto";
|
|
260
|
+
import { lstatSync as lstatSync2, readFileSync as readFileSync4, rmSync as rmSync4 } from "fs";
|
|
261
|
+
import { createServer } from "http";
|
|
262
|
+
import { basename, join as join6 } from "path";
|
|
263
|
+
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
264
|
+
|
|
116
265
|
// src/lib/loopback-fetch.ts
|
|
117
266
|
import { request } from "http";
|
|
118
267
|
import { Readable } from "stream";
|
|
@@ -262,34 +411,6 @@ function parseMachineIdentity(value, clientId) {
|
|
|
262
411
|
};
|
|
263
412
|
}
|
|
264
413
|
|
|
265
|
-
// src/lib/paths.ts
|
|
266
|
-
import { homedir } from "os";
|
|
267
|
-
import { isAbsolute as isAbsolute2, join as join3, normalize } from "path";
|
|
268
|
-
var UNSAFE_CONFIG_PATH_CHARACTERS = /[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/u;
|
|
269
|
-
function absolutePath(value, variable) {
|
|
270
|
-
if (value !== void 0 && UNSAFE_CONFIG_PATH_CHARACTERS.test(value)) {
|
|
271
|
-
throw new Error(`${variable} contains unsafe characters`);
|
|
272
|
-
}
|
|
273
|
-
if (!value || value.trim() !== value || !isAbsolute2(value)) return;
|
|
274
|
-
const normalized = normalize(value);
|
|
275
|
-
return normalized === value ? value : void 0;
|
|
276
|
-
}
|
|
277
|
-
function resolvePrimConfigDirectory(options = {}) {
|
|
278
|
-
const env = options.env ?? process.env;
|
|
279
|
-
const explicit = absolutePath(env.PRIM_CONFIG_DIR, "PRIM_CONFIG_DIR");
|
|
280
|
-
if (explicit) return { path: explicit, source: "explicit" };
|
|
281
|
-
const xdgConfigHome = absolutePath(env.XDG_CONFIG_HOME, "XDG_CONFIG_HOME");
|
|
282
|
-
if (xdgConfigHome) return { path: join3(xdgConfigHome, "prim"), source: "xdg" };
|
|
283
|
-
const home = absolutePath(options.homeDir ?? homedir(), "HOME");
|
|
284
|
-
if (!home) {
|
|
285
|
-
throw new Error("cannot resolve Primitive config directory: HOME is not an absolute path");
|
|
286
|
-
}
|
|
287
|
-
return { path: join3(home, ".config", "prim"), source: "default" };
|
|
288
|
-
}
|
|
289
|
-
function primConfigDirectory(options = {}) {
|
|
290
|
-
return resolvePrimConfigDirectory(options).path;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
414
|
// src/lib/machine-broker.ts
|
|
294
415
|
var MAX_RESPONSE_BYTES = 96 * 1024;
|
|
295
416
|
var MAX_FORWARD_REQUEST_BYTES = 12 * 1024 * 1024;
|
|
@@ -298,23 +419,23 @@ var MAX_FORWARD_RESPONSE_BYTES = 36 * 1024 * 1024;
|
|
|
298
419
|
var IDLE_MS = 5 * 6e4;
|
|
299
420
|
|
|
300
421
|
// src/lib/machine-retry.ts
|
|
301
|
-
import { createHash as
|
|
302
|
-
import { lstatSync as
|
|
303
|
-
import { join as
|
|
422
|
+
import { createHash as createHash3 } from "crypto";
|
|
423
|
+
import { lstatSync as lstatSync3, readFileSync as readFileSync5, readdirSync as readdirSync2, rmSync as rmSync5 } from "fs";
|
|
424
|
+
import { join as join7 } from "path";
|
|
304
425
|
var MAX_SERVER_WAIT_MS = 15 * 6e4;
|
|
305
426
|
|
|
306
427
|
// src/lib/session-identity.ts
|
|
307
428
|
import { execFile } from "child_process";
|
|
308
|
-
import { createHash as
|
|
309
|
-
import { rmSync as
|
|
310
|
-
import { join as
|
|
429
|
+
import { createHash as createHash5 } from "crypto";
|
|
430
|
+
import { rmSync as rmSync6 } from "fs";
|
|
431
|
+
import { join as join9 } from "path";
|
|
311
432
|
import { promisify } from "util";
|
|
312
433
|
|
|
313
434
|
// src/lib/git.ts
|
|
314
435
|
import { execFileSync } from "child_process";
|
|
315
|
-
import { createHash as
|
|
316
|
-
import { lstatSync as
|
|
317
|
-
import { basename as basename2, dirname as
|
|
436
|
+
import { createHash as createHash4 } from "crypto";
|
|
437
|
+
import { lstatSync as lstatSync4, readFileSync as readFileSync6, realpathSync as realpathSync2 } from "fs";
|
|
438
|
+
import { basename as basename2, dirname as dirname6, isAbsolute as isAbsolute4, join as join8, relative, resolve as resolve2, sep } from "path";
|
|
318
439
|
var GIT_TIMEOUT_MS = 1e3;
|
|
319
440
|
var MAX_SETTINGS_BYTES = 1024 * 1024;
|
|
320
441
|
var GITHUB_OWNER_PATTERN = /^(?![A-Za-z0-9-]*--)[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/u;
|
|
@@ -368,12 +489,12 @@ function githubRepositoryFromRemote(remote) {
|
|
|
368
489
|
return path ? parseGithubRepositoryName(path) : null;
|
|
369
490
|
}
|
|
370
491
|
function checkoutSettingsText(repoRoot) {
|
|
371
|
-
const path =
|
|
492
|
+
const path = join8(repoRoot, ".claude", "settings.json");
|
|
372
493
|
try {
|
|
373
|
-
if (!
|
|
374
|
-
const stat =
|
|
494
|
+
if (!lstatSync4(join8(repoRoot, ".claude")).isDirectory()) return null;
|
|
495
|
+
const stat = lstatSync4(path);
|
|
375
496
|
if (!stat.isFile() || stat.size > MAX_SETTINGS_BYTES) return null;
|
|
376
|
-
return
|
|
497
|
+
return readFileSync6(path, "utf8");
|
|
377
498
|
} catch {
|
|
378
499
|
return null;
|
|
379
500
|
}
|
|
@@ -502,7 +623,7 @@ var CHALLENGE_GONE = failure(
|
|
|
502
623
|
NEW_SESSION_REMEDY
|
|
503
624
|
);
|
|
504
625
|
function hash(value) {
|
|
505
|
-
return
|
|
626
|
+
return createHash5("sha256").update(value).digest("hex");
|
|
506
627
|
}
|
|
507
628
|
function sessionContext(deps) {
|
|
508
629
|
const env = deps.env ?? process.env;
|
|
@@ -529,9 +650,9 @@ function sessionContext(deps) {
|
|
|
529
650
|
clientId: environment.clientId,
|
|
530
651
|
generation: environment.generation,
|
|
531
652
|
sessionId,
|
|
532
|
-
tokenPath:
|
|
533
|
-
statePath:
|
|
534
|
-
lockPath:
|
|
653
|
+
tokenPath: join9(directory, `session_identity_${key}.json`),
|
|
654
|
+
statePath: join9(directory, `session_identity_${key}.state.json`),
|
|
655
|
+
lockPath: join9(directory, "session-identity.lock")
|
|
535
656
|
};
|
|
536
657
|
}
|
|
537
658
|
function readRecord(path) {
|
|
@@ -597,7 +718,7 @@ var SERVER_CONTRACT_FAILURE = failure(
|
|
|
597
718
|
function sessionScoped(deps) {
|
|
598
719
|
return !deps.localEnvironment && !deps.environmentOnly && sessionIdentityMode(deps);
|
|
599
720
|
}
|
|
600
|
-
var
|
|
721
|
+
var require3 = createRequire2(import.meta.url);
|
|
601
722
|
var DEFAULT_API_URL2 = "https://api.getprimitive.ai";
|
|
602
723
|
var PROFILE_FILE = "machine_profile.json";
|
|
603
724
|
var cached;
|
|
@@ -608,10 +729,10 @@ function apiUrlFor(deps) {
|
|
|
608
729
|
return machineApiUrl((deps.env ?? process.env).PRIM_API_URL?.trim() || DEFAULT_API_URL2);
|
|
609
730
|
}
|
|
610
731
|
function hash2(value) {
|
|
611
|
-
return
|
|
732
|
+
return createHash6("sha256").update(value).digest("hex");
|
|
612
733
|
}
|
|
613
734
|
function environmentContextPath(deps, clientId) {
|
|
614
|
-
return
|
|
735
|
+
return join10(
|
|
615
736
|
configurationDirectory(deps),
|
|
616
737
|
`machine_context_${hash2(`${apiUrlFor(deps)}\0${clientId}`)}.json`
|
|
617
738
|
);
|
|
@@ -639,7 +760,7 @@ function readEnvironmentContext(environment, deps) {
|
|
|
639
760
|
}
|
|
640
761
|
function protectPath(path, directory) {
|
|
641
762
|
if (process.platform !== "win32") {
|
|
642
|
-
|
|
763
|
+
chmodSync2(path, directory ? 448 : 384);
|
|
643
764
|
return;
|
|
644
765
|
}
|
|
645
766
|
const encodedPath = Buffer.from(path).toString("base64");
|
|
@@ -656,8 +777,8 @@ function protectPath(path, directory) {
|
|
|
656
777
|
);
|
|
657
778
|
}
|
|
658
779
|
function ensureDirectory(directory) {
|
|
659
|
-
|
|
660
|
-
if (
|
|
780
|
+
mkdirSync4(directory, { recursive: true, mode: 448 });
|
|
781
|
+
if (lstatSync5(directory).isSymbolicLink())
|
|
661
782
|
throw new MachineAuthError(
|
|
662
783
|
"unsafe_storage",
|
|
663
784
|
"Credential directory must not be a symbolic link."
|
|
@@ -670,14 +791,14 @@ function readMachineMetadata(path) {
|
|
|
670
791
|
function readPrivate(path) {
|
|
671
792
|
let raw;
|
|
672
793
|
try {
|
|
673
|
-
const stat =
|
|
794
|
+
const stat = lstatSync5(path);
|
|
674
795
|
if (!stat.isFile() || stat.size > 96 * 1024 || process.platform !== "win32" && ((stat.mode & 63) !== 0 || stat.uid !== process.getuid?.())) {
|
|
675
796
|
throw new MachineAuthError(
|
|
676
797
|
"unsafe_storage",
|
|
677
798
|
"Machine credential files must be owner-only regular files."
|
|
678
799
|
);
|
|
679
800
|
}
|
|
680
|
-
raw =
|
|
801
|
+
raw = readFileSync7(path, "utf8");
|
|
681
802
|
} catch (error) {
|
|
682
803
|
if (error.code === "ENOENT") return void 0;
|
|
683
804
|
throw error;
|
|
@@ -722,7 +843,7 @@ function parseProfile(value) {
|
|
|
722
843
|
};
|
|
723
844
|
}
|
|
724
845
|
function readMachineProfile(deps = {}) {
|
|
725
|
-
const value = readPrivate(
|
|
846
|
+
const value = readPrivate(join10(configurationDirectory(deps), PROFILE_FILE));
|
|
726
847
|
return value === void 0 ? void 0 : parseProfile(value);
|
|
727
848
|
}
|
|
728
849
|
var NETWORK_SECRET_AUTH = "network-secret";
|
|
@@ -731,20 +852,20 @@ var INJECTED_IDENTITY_TTL_MS = 60 * 6e4;
|
|
|
731
852
|
var brokerKeys = /* @__PURE__ */ new Map();
|
|
732
853
|
function networkSecretBrokerKey(deps, clientId) {
|
|
733
854
|
const directory = configurationDirectory(deps);
|
|
734
|
-
const path =
|
|
855
|
+
const path = join10(directory, `machine_network_${hash2(`${apiUrlFor(deps)}\0${clientId}`)}.key`);
|
|
735
856
|
const known = brokerKeys.get(path);
|
|
736
857
|
if (known) return known;
|
|
737
858
|
ensureDirectory(directory);
|
|
738
859
|
const read = () => {
|
|
739
860
|
try {
|
|
740
|
-
const stat =
|
|
861
|
+
const stat = lstatSync5(path);
|
|
741
862
|
if (!stat.isFile() || process.platform !== "win32" && ((stat.mode & 63) !== 0 || typeof process.getuid === "function" && stat.uid !== process.getuid()))
|
|
742
863
|
throw new MachineAuthError(
|
|
743
864
|
"unsafe_storage",
|
|
744
865
|
`The machine broker key at ${path} is not an owner-only file. Delete it and retry.`,
|
|
745
866
|
true
|
|
746
867
|
);
|
|
747
|
-
const value =
|
|
868
|
+
const value = readFileSync7(path, "utf8").trim();
|
|
748
869
|
return { key: /^[a-f0-9]{64}$/u.test(value) ? value : void 0 };
|
|
749
870
|
} catch (error) {
|
|
750
871
|
if (error.code === "ENOENT") return void 0;
|
|
@@ -763,16 +884,16 @@ function networkSecretBrokerKey(deps, clientId) {
|
|
|
763
884
|
`The machine broker key at ${path} is damaged. Delete it and retry.`,
|
|
764
885
|
true
|
|
765
886
|
);
|
|
766
|
-
const staged = `${path}.${process.pid}.${
|
|
887
|
+
const staged = `${path}.${process.pid}.${randomBytes4(6).toString("hex")}`;
|
|
767
888
|
try {
|
|
768
|
-
|
|
889
|
+
writeFileSync4(staged, `${randomBytes4(32).toString("hex")}
|
|
769
890
|
`, { mode: 384, flag: "wx" });
|
|
770
891
|
protectPath(staged, false);
|
|
771
892
|
linkSync(staged, path);
|
|
772
893
|
} catch (error) {
|
|
773
894
|
if (error.code !== "EEXIST") throw error;
|
|
774
895
|
} finally {
|
|
775
|
-
|
|
896
|
+
rmSync7(staged, { force: true });
|
|
776
897
|
}
|
|
777
898
|
}
|
|
778
899
|
const key = read()?.key;
|
|
@@ -831,7 +952,7 @@ function environmentCredentials(deps) {
|
|
|
831
952
|
}
|
|
832
953
|
function hasMachineConfiguration(deps = {}) {
|
|
833
954
|
const env = deps.env ?? process.env;
|
|
834
|
-
const configured = env.PRIM_M2M_CLIENT_ID !== void 0 || env.PRIM_M2M_CLIENT_SECRET !== void 0 || env.PRIM_M2M_CLIENT_AUTH !== void 0 ||
|
|
955
|
+
const configured = env.PRIM_M2M_CLIENT_ID !== void 0 || env.PRIM_M2M_CLIENT_SECRET !== void 0 || env.PRIM_M2M_CLIENT_AUTH !== void 0 || existsSync5(join10(configurationDirectory(deps), PROFILE_FILE));
|
|
835
956
|
if (configured && env.PRIM_TOKEN?.trim()) {
|
|
836
957
|
throw new MachineAuthError(
|
|
837
958
|
"conflicting_credentials",
|
|
@@ -866,20 +987,20 @@ var environmentTerminal;
|
|
|
866
987
|
|
|
867
988
|
// src/lib/credentials.ts
|
|
868
989
|
var CONFIG_DIRECTORY = primConfigDirectory();
|
|
869
|
-
var TOKEN_FILE_PATH =
|
|
870
|
-
var REFRESH_TOKEN_PATH =
|
|
871
|
-
var TOKEN_EXPIRES_PATH =
|
|
872
|
-
var TERMINAL_REFRESH_PATH =
|
|
873
|
-
var CREDENTIAL_METADATA_PATH =
|
|
874
|
-
var CREDENTIAL_FAMILY_PATH =
|
|
875
|
-
var CREDENTIAL_MIGRATION_PATH =
|
|
876
|
-
var CREDENTIAL_LOCK_PATH =
|
|
990
|
+
var TOKEN_FILE_PATH = join11(CONFIG_DIRECTORY, "token");
|
|
991
|
+
var REFRESH_TOKEN_PATH = join11(CONFIG_DIRECTORY, "refresh_token");
|
|
992
|
+
var TOKEN_EXPIRES_PATH = join11(CONFIG_DIRECTORY, "token_expires_at");
|
|
993
|
+
var TERMINAL_REFRESH_PATH = join11(CONFIG_DIRECTORY, "refresh_terminal");
|
|
994
|
+
var CREDENTIAL_METADATA_PATH = join11(CONFIG_DIRECTORY, "credential_metadata.json");
|
|
995
|
+
var CREDENTIAL_FAMILY_PATH = join11(CONFIG_DIRECTORY, "credential_family.json");
|
|
996
|
+
var CREDENTIAL_MIGRATION_PATH = join11(CONFIG_DIRECTORY, "credential_migration.json");
|
|
997
|
+
var CREDENTIAL_LOCK_PATH = join11(CONFIG_DIRECTORY, "credentials.lock");
|
|
877
998
|
var MAX_CREDENTIAL_METADATA_BYTES = 4096;
|
|
878
999
|
var CREDENTIAL_MIGRATION_VERSION = 1;
|
|
879
1000
|
var CREDENTIAL_MIGRATION_STATE = "family_bound";
|
|
880
1001
|
function readTrimmed(path) {
|
|
881
1002
|
try {
|
|
882
|
-
const value =
|
|
1003
|
+
const value = readFileSync8(path, "utf8").trim();
|
|
883
1004
|
return value || void 0;
|
|
884
1005
|
} catch {
|
|
885
1006
|
return void 0;
|
|
@@ -916,7 +1037,7 @@ function resolveAuthCredential(options = {}) {
|
|
|
916
1037
|
return { token: stored, source: "token_file" };
|
|
917
1038
|
}
|
|
918
1039
|
function credentialFingerprint(value) {
|
|
919
|
-
return
|
|
1040
|
+
return createHash7("sha256").update(value).digest("hex");
|
|
920
1041
|
}
|
|
921
1042
|
function parseLegacyBrokerCredentialMetadata(value) {
|
|
922
1043
|
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
@@ -936,7 +1057,7 @@ function parseLegacyBrokerCredentialMetadata(value) {
|
|
|
936
1057
|
function readBoundedCredentialJson(path) {
|
|
937
1058
|
let raw;
|
|
938
1059
|
try {
|
|
939
|
-
raw =
|
|
1060
|
+
raw = readFileSync8(path, "utf8");
|
|
940
1061
|
} catch (error) {
|
|
941
1062
|
return error.code === "ENOENT" ? void 0 : null;
|
|
942
1063
|
}
|
|
@@ -1004,9 +1125,9 @@ function decodeJwtPayload(token) {
|
|
|
1004
1125
|
}
|
|
1005
1126
|
|
|
1006
1127
|
// src/daemon/client-instance-id.ts
|
|
1007
|
-
import { randomBytes as
|
|
1008
|
-
import { chmodSync as
|
|
1009
|
-
import { join as
|
|
1128
|
+
import { randomBytes as randomBytes5 } from "crypto";
|
|
1129
|
+
import { chmodSync as chmodSync3, lstatSync as lstatSync6, readFileSync as readFileSync9 } from "fs";
|
|
1130
|
+
import { join as join12 } from "path";
|
|
1010
1131
|
var INSTANCE_BODY_CHARS = 43;
|
|
1011
1132
|
var INSTANCE_PREFIX = "pci_";
|
|
1012
1133
|
var MAX_STORED_BYTES = INSTANCE_PREFIX.length + INSTANCE_BODY_CHARS + 1;
|
|
@@ -1025,13 +1146,13 @@ function getSiteUrlForEnvironment(primApiUrl) {
|
|
|
1025
1146
|
var CLI_MANAGEMENT_RESPONSE_MAX_BYTES = 2 * 1024 * 1024;
|
|
1026
1147
|
|
|
1027
1148
|
// src/daemon/principal.ts
|
|
1028
|
-
import { createHash as
|
|
1149
|
+
import { createHash as createHash9 } from "crypto";
|
|
1029
1150
|
var PRINCIPAL_COMPONENT_MAX_LENGTH = 512;
|
|
1030
1151
|
function boundedClaim(value) {
|
|
1031
1152
|
return typeof value === "string" && value.length > 0 && value.length <= PRINCIPAL_COMPONENT_MAX_LENGTH ? value : void 0;
|
|
1032
1153
|
}
|
|
1033
1154
|
function sha256(value) {
|
|
1034
|
-
return
|
|
1155
|
+
return createHash9("sha256").update(value).digest("hex");
|
|
1035
1156
|
}
|
|
1036
1157
|
function resolveDaemonPrincipal(token = resolveAuthCredential()?.token) {
|
|
1037
1158
|
if (hasMachineConfiguration()) {
|
|
@@ -1082,8 +1203,8 @@ function parseDaemonResponseEnvelope(value) {
|
|
|
1082
1203
|
|
|
1083
1204
|
// src/daemon/client.ts
|
|
1084
1205
|
import { createConnection } from "net";
|
|
1085
|
-
import { join as
|
|
1086
|
-
var SOCK_PATH =
|
|
1206
|
+
import { join as join14 } from "path";
|
|
1207
|
+
var SOCK_PATH = join14(primConfigDirectory(), "sock");
|
|
1087
1208
|
var DEFAULT_TIMEOUT_MS = 250;
|
|
1088
1209
|
var nextRequestId = 1;
|
|
1089
1210
|
function daemonRequest(method, params = {}, opts = {}) {
|
|
@@ -1096,7 +1217,7 @@ function daemonRequest(method, params = {}, opts = {}) {
|
|
|
1096
1217
|
...caller ? { caller } : {}
|
|
1097
1218
|
};
|
|
1098
1219
|
const timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
1099
|
-
return new Promise((
|
|
1220
|
+
return new Promise((resolve5) => {
|
|
1100
1221
|
let settled = false;
|
|
1101
1222
|
let socket;
|
|
1102
1223
|
let buffer = Buffer.alloc(0);
|
|
@@ -1111,7 +1232,7 @@ function daemonRequest(method, params = {}, opts = {}) {
|
|
|
1111
1232
|
} catch {
|
|
1112
1233
|
}
|
|
1113
1234
|
}
|
|
1114
|
-
|
|
1235
|
+
resolve5(value);
|
|
1115
1236
|
};
|
|
1116
1237
|
const timer = setTimeout(() => settle(null), timeoutMs);
|
|
1117
1238
|
timer.unref();
|
|
@@ -1174,21 +1295,21 @@ function daemonRequest(method, params = {}, opts = {}) {
|
|
|
1174
1295
|
|
|
1175
1296
|
// src/lib/activation.ts
|
|
1176
1297
|
import { execFileSync as execFileSync4 } from "child_process";
|
|
1177
|
-
import { existsSync as
|
|
1298
|
+
import { existsSync as existsSync8, readFileSync as readFileSync12 } from "fs";
|
|
1178
1299
|
import { homedir as homedir2 } from "os";
|
|
1179
|
-
import { join as
|
|
1300
|
+
import { join as join16 } from "path";
|
|
1180
1301
|
|
|
1181
1302
|
// src/lib/cloud-prepared.ts
|
|
1182
|
-
import { existsSync as
|
|
1183
|
-
import { join as
|
|
1303
|
+
import { existsSync as existsSync7, mkdirSync as mkdirSync6, readFileSync as readFileSync11, rmSync as rmSync9, writeFileSync as writeFileSync5 } from "fs";
|
|
1304
|
+
import { join as join15 } from "path";
|
|
1184
1305
|
var CLOUD_PREPARED_MARKER = "cloud-prepared";
|
|
1185
1306
|
function cloudPreparedPath(env = process.env) {
|
|
1186
|
-
return
|
|
1307
|
+
return join15(primConfigDirectory({ env }), CLOUD_PREPARED_MARKER);
|
|
1187
1308
|
}
|
|
1188
1309
|
function isPreparedCloudSession(env = process.env) {
|
|
1189
1310
|
if (!isClaudeCloudSession(env)) return false;
|
|
1190
1311
|
try {
|
|
1191
|
-
return
|
|
1312
|
+
return existsSync7(cloudPreparedPath(env));
|
|
1192
1313
|
} catch {
|
|
1193
1314
|
return false;
|
|
1194
1315
|
}
|
|
@@ -1317,10 +1438,10 @@ function repositoryBindingState(cwd) {
|
|
|
1317
1438
|
function projectPrimInstallAt(root) {
|
|
1318
1439
|
if (root === null || root === homedir2()) return false;
|
|
1319
1440
|
for (const rel of PROJECT_INSTALL_FILES) {
|
|
1320
|
-
const path =
|
|
1321
|
-
if (
|
|
1441
|
+
const path = join16(root, rel);
|
|
1442
|
+
if (existsSync8(path)) {
|
|
1322
1443
|
try {
|
|
1323
|
-
const content =
|
|
1444
|
+
const content = readFileSync12(path, "utf-8");
|
|
1324
1445
|
if (PRIM_HOOK_BINS.some((bin) => content.includes(bin))) return true;
|
|
1325
1446
|
} catch {
|
|
1326
1447
|
}
|
|
@@ -1483,17 +1604,17 @@ function formatStatusline(version, snapshot, resolveIngestionStatus, options = {
|
|
|
1483
1604
|
var STATUSLINE_TIMEOUT_MS = 200;
|
|
1484
1605
|
function readPackageVersion() {
|
|
1485
1606
|
try {
|
|
1486
|
-
const here =
|
|
1607
|
+
const here = dirname9(fileURLToPath5(import.meta.url));
|
|
1487
1608
|
const candidates = [
|
|
1488
1609
|
// Schema-v2 runtimes staged a manifest beside this standalone bundle.
|
|
1489
1610
|
// Keep resolving it while those legacy launchers transition to schema v3.
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1611
|
+
resolve4(here, "manifest.json"),
|
|
1612
|
+
resolve4(here, "../../package.json"),
|
|
1613
|
+
resolve4(here, "../package.json")
|
|
1493
1614
|
];
|
|
1494
1615
|
for (const path of candidates) {
|
|
1495
1616
|
try {
|
|
1496
|
-
const pkg = JSON.parse(
|
|
1617
|
+
const pkg = JSON.parse(readFileSync13(path, "utf-8"));
|
|
1497
1618
|
if (pkg.version) {
|
|
1498
1619
|
return pkg.version;
|
|
1499
1620
|
}
|
|
@@ -1535,7 +1656,7 @@ async function renderStatusline(cwd = process.cwd()) {
|
|
|
1535
1656
|
// src/hooks/hook-stdin.ts
|
|
1536
1657
|
var DEFAULT_MAX_BYTES = 1024 * 1024;
|
|
1537
1658
|
function readHookStdin(timeoutMs = 1e3, maxBytes = DEFAULT_MAX_BYTES) {
|
|
1538
|
-
return new Promise((
|
|
1659
|
+
return new Promise((resolve5, reject) => {
|
|
1539
1660
|
const chunks = [];
|
|
1540
1661
|
let bytes = 0;
|
|
1541
1662
|
let settled = false;
|
|
@@ -1547,7 +1668,7 @@ function readHookStdin(timeoutMs = 1e3, maxBytes = DEFAULT_MAX_BYTES) {
|
|
|
1547
1668
|
process.stdin.removeAllListeners("end");
|
|
1548
1669
|
process.stdin.removeAllListeners("error");
|
|
1549
1670
|
if (error) reject(error);
|
|
1550
|
-
else
|
|
1671
|
+
else resolve5(Buffer.concat(chunks, bytes).toString("utf-8"));
|
|
1551
1672
|
};
|
|
1552
1673
|
const timer = setTimeout(() => finish(new Error("stdin read timeout")), timeoutMs);
|
|
1553
1674
|
process.stdin.on("data", (chunk) => {
|