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