@primitive.ai/prim 0.1.0-alpha.98 → 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 +11 -0
- package/dist/{chunk-7IPGD6CD.js → chunk-25DDRMWS.js} +2 -2
- package/dist/{chunk-B6EPQ4YH.js → chunk-2IRLFOEL.js} +123 -19
- package/dist/{chunk-WKLYYT63.js → chunk-2Q3OGSTV.js} +3 -3
- package/dist/{chunk-2DPLT2CQ.js → chunk-5LRKJTLA.js} +1 -1
- package/dist/{chunk-AN6XTFIN.js → chunk-6C3CCVDI.js} +2 -2
- package/dist/{chunk-NIQAVFP6.js → chunk-7VIMU2HR.js} +1 -1
- package/dist/{chunk-2DA2B4EC.js → chunk-EJPKZT5M.js} +2 -2
- package/dist/{chunk-HUZXBJJ5.js → chunk-FK7FJPWS.js} +1 -1
- package/dist/{chunk-QPMLAD2C.js → chunk-JJI7FU24.js} +2 -2
- package/dist/{chunk-PPZBEOWK.js → chunk-JJYS7IPD.js} +3 -3
- package/dist/{chunk-RT7DXMTN.js → chunk-K4JWJ6OM.js} +79 -266
- package/dist/{chunk-3X77XQGW.js → chunk-KGBMU76T.js} +1 -1
- package/dist/{chunk-JOR67B5T.js → chunk-O2WV5SQZ.js} +8 -8
- package/dist/{chunk-IL443QTF.js → chunk-X5BN67D2.js} +2 -2
- package/dist/{chunk-6QK75B7G.js → chunk-XG7S3LIL.js} +214 -11
- package/dist/{chunk-MN4X6RR6.js → chunk-XPS6LG6I.js} +5 -7
- package/dist/{chunk-BIAWZMCK.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 +177 -33
- 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 +615 -515
- package/dist/hook-runtime/statusline-main.js +71 -16
- package/dist/hooks/post-commit.js +7 -7
- package/dist/hooks/post-rewrite.js +6 -6
- package/dist/hooks/post-tool-use.js +13 -13
- package/dist/hooks/pre-commit.js +4 -4
- package/dist/hooks/pre-tool-use.js +10 -11
- package/dist/hooks/prim-hook.js +14 -14
- package/dist/hooks/session-end.js +4 -4
- package/dist/hooks/session-start.js +11 -11
- package/dist/index.js +20 -20
- package/dist/statusline-main.js +71 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -424,6 +424,17 @@ long) hands them to a detached background `prim moves flush` and never waits for
|
|
|
424
424
|
it. It starts none while a live daemon on the same version and deployment, with
|
|
425
425
|
a healthy heartbeat and no recorded ingestion failure, already owns the drain.
|
|
426
426
|
|
|
427
|
+
Move uploads include `X-Prim-Uploader-Version` (the uploader process's version)
|
|
428
|
+
and `X-Prim-Client-Instance-Id` (the opaque installation ID also used by presence
|
|
429
|
+
heartbeats). These let server traces distinguish the uploader from the version
|
|
430
|
+
that originally captured a replayed move. The ID is stored in
|
|
431
|
+
`client_instance_id` under the Prim config directory (`~/.config/prim` by default,
|
|
432
|
+
or `PRIM_CONFIG_DIR` / `XDG_CONFIG_HOME/prim`). Compare that file with the trace's
|
|
433
|
+
`uploaderClientInstanceId` to correlate an installation; it contains no hostname.
|
|
434
|
+
If the identity cannot be read or created immediately, uploads omit that header
|
|
435
|
+
and continue. Invalid stored identities are never silently replaced. Older
|
|
436
|
+
clients remain unattributed until updated and their uploader process restarted.
|
|
437
|
+
|
|
427
438
|
### Skill
|
|
428
439
|
|
|
429
440
|
```bash
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getClient,
|
|
3
3
|
terminalSafeLine
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-2IRLFOEL.js";
|
|
5
5
|
import {
|
|
6
6
|
__commonJS,
|
|
7
7
|
__toESM,
|
|
8
8
|
localGitConfigValue,
|
|
9
9
|
setLocalGitConfigValue
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-XG7S3LIL.js";
|
|
11
11
|
|
|
12
12
|
// node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/runtime/ucs2length.js
|
|
13
13
|
var require_ucs2length = __commonJS({
|
|
@@ -11,21 +11,124 @@ import {
|
|
|
11
11
|
TOKEN_FILE_PATH,
|
|
12
12
|
WORKOS_CONNECT_RESPONSE_MAX_BYTES,
|
|
13
13
|
atomicWriteFile,
|
|
14
|
+
ensureDurableDirectory,
|
|
14
15
|
jwtExpiresAt,
|
|
16
|
+
packageVersion,
|
|
15
17
|
parseWorkosConnectTokens,
|
|
18
|
+
primConfigDirectory,
|
|
16
19
|
readBoundedJson,
|
|
17
20
|
readCredentialMigrationState,
|
|
18
21
|
readStoredCredentialMetadata,
|
|
19
22
|
resolveAuthCredential,
|
|
23
|
+
syncDirectory,
|
|
20
24
|
withFileLock,
|
|
21
25
|
workosConnectTokenEndpoint
|
|
22
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-XG7S3LIL.js";
|
|
23
27
|
|
|
24
28
|
// src/client.ts
|
|
25
29
|
import { createHash } from "crypto";
|
|
26
|
-
import { chmodSync, existsSync, mkdirSync, readFileSync, rmSync } from "fs";
|
|
30
|
+
import { chmodSync as chmodSync2, existsSync, mkdirSync, readFileSync as readFileSync2, rmSync } from "fs";
|
|
27
31
|
import { dirname } from "path";
|
|
28
32
|
|
|
33
|
+
// src/daemon/client-instance-id.ts
|
|
34
|
+
import { randomBytes } from "crypto";
|
|
35
|
+
import { chmodSync, lstatSync, readFileSync } from "fs";
|
|
36
|
+
import { join } from "path";
|
|
37
|
+
var CONFIG_DIRECTORY_MODE = 448;
|
|
38
|
+
var INSTANCE_FILE_MODE = 384;
|
|
39
|
+
var INSTANCE_ENTROPY_BYTES = 32;
|
|
40
|
+
var INSTANCE_BODY_CHARS = 43;
|
|
41
|
+
var INSTANCE_PREFIX = "pci_";
|
|
42
|
+
var CLIENT_INSTANCE_ID_RE = /^pci_[A-Za-z0-9_-]{43}$/u;
|
|
43
|
+
var MAX_STORED_BYTES = INSTANCE_PREFIX.length + INSTANCE_BODY_CHARS + 1;
|
|
44
|
+
function isClientInstanceId(value) {
|
|
45
|
+
return typeof value === "string" && CLIENT_INSTANCE_ID_RE.test(value);
|
|
46
|
+
}
|
|
47
|
+
function ensurePrivateConfigDirectory(configDir) {
|
|
48
|
+
ensureDurableDirectory(configDir, CONFIG_DIRECTORY_MODE);
|
|
49
|
+
const metadata = lstatSync(configDir);
|
|
50
|
+
if (!metadata.isDirectory() || metadata.isSymbolicLink()) {
|
|
51
|
+
throw new Error("prim config path must be a private directory");
|
|
52
|
+
}
|
|
53
|
+
chmodSync(configDir, CONFIG_DIRECTORY_MODE);
|
|
54
|
+
syncDirectory(configDir);
|
|
55
|
+
}
|
|
56
|
+
function readExisting(path) {
|
|
57
|
+
let metadata;
|
|
58
|
+
try {
|
|
59
|
+
metadata = lstatSync(path);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
if (error.code === "ENOENT") {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
if (!metadata.isFile() || metadata.isSymbolicLink()) {
|
|
67
|
+
throw new Error("stored client instance identity is invalid");
|
|
68
|
+
}
|
|
69
|
+
chmodSync(path, INSTANCE_FILE_MODE);
|
|
70
|
+
if (metadata.size > MAX_STORED_BYTES) {
|
|
71
|
+
throw new Error("stored client instance identity is invalid");
|
|
72
|
+
}
|
|
73
|
+
const raw = readFileSync(path, "utf8");
|
|
74
|
+
const value = raw.endsWith("\n") ? raw.slice(0, -1) : raw;
|
|
75
|
+
if (raw !== value && raw !== `${value}
|
|
76
|
+
` || !isClientInstanceId(value)) {
|
|
77
|
+
throw new Error("stored client instance identity is invalid");
|
|
78
|
+
}
|
|
79
|
+
return value;
|
|
80
|
+
}
|
|
81
|
+
function atomicWrite(path, value) {
|
|
82
|
+
atomicWriteFile(path, `${value}
|
|
83
|
+
`, { mode: INSTANCE_FILE_MODE });
|
|
84
|
+
}
|
|
85
|
+
async function getOrCreateClientInstanceId(options) {
|
|
86
|
+
const configDir = options.configDir;
|
|
87
|
+
const path = join(configDir, "client_instance_id");
|
|
88
|
+
const lockPath = join(configDir, "client-instance.lock");
|
|
89
|
+
ensurePrivateConfigDirectory(configDir);
|
|
90
|
+
return withFileLock(
|
|
91
|
+
lockPath,
|
|
92
|
+
() => {
|
|
93
|
+
const existing = readExisting(path);
|
|
94
|
+
if (existing !== void 0) {
|
|
95
|
+
return existing;
|
|
96
|
+
}
|
|
97
|
+
const generated = `${INSTANCE_PREFIX}${randomBytes(INSTANCE_ENTROPY_BYTES).toString(
|
|
98
|
+
"base64url"
|
|
99
|
+
)}`;
|
|
100
|
+
if (!isClientInstanceId(generated)) {
|
|
101
|
+
throw new Error("generated client instance identity is invalid");
|
|
102
|
+
}
|
|
103
|
+
atomicWrite(path, generated);
|
|
104
|
+
return generated;
|
|
105
|
+
},
|
|
106
|
+
options.lockOptions
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// src/lib/ingest-uploader.ts
|
|
111
|
+
var runtimeVersion = process.env.PRIM_RUNTIME_VERSION ?? packageVersion();
|
|
112
|
+
var VERSION_RE = /^\d+\.\d+\.\d+(?:-[A-Za-z0-9.-]+)?(?:\+[A-Za-z0-9.-]+)?$/u;
|
|
113
|
+
var instanceId;
|
|
114
|
+
async function ingestUploaderHeaders() {
|
|
115
|
+
const headers = {};
|
|
116
|
+
if (runtimeVersion && runtimeVersion.length <= 64 && VERSION_RE.test(runtimeVersion)) {
|
|
117
|
+
headers["X-Prim-Uploader-Version"] = runtimeVersion;
|
|
118
|
+
}
|
|
119
|
+
instanceId ??= getOrCreateClientInstanceId({
|
|
120
|
+
configDir: primConfigDirectory(),
|
|
121
|
+
// Attribution must not consume the upload deadline waiting for another process.
|
|
122
|
+
lockOptions: { timeoutMs: 0 }
|
|
123
|
+
}).catch(() => {
|
|
124
|
+
instanceId = void 0;
|
|
125
|
+
return void 0;
|
|
126
|
+
});
|
|
127
|
+
const id = await instanceId;
|
|
128
|
+
if (id) headers["X-Prim-Client-Instance-Id"] = id;
|
|
129
|
+
return headers;
|
|
130
|
+
}
|
|
131
|
+
|
|
29
132
|
// src/lib/terminal-safe.ts
|
|
30
133
|
function replaceIsolatedSurrogates(value) {
|
|
31
134
|
let out = "";
|
|
@@ -79,7 +182,7 @@ var DEFAULT_API_URL = "https://api.getprimitive.ai";
|
|
|
79
182
|
var AUTH_EXPIRED_MESSAGE = "Authentication expired. Run `prim auth login` to re-authenticate.";
|
|
80
183
|
function readTrimmed(path) {
|
|
81
184
|
try {
|
|
82
|
-
const value =
|
|
185
|
+
const value = readFileSync2(path, "utf8").trim();
|
|
83
186
|
return value || void 0;
|
|
84
187
|
} catch {
|
|
85
188
|
return void 0;
|
|
@@ -97,9 +200,9 @@ function expiresAtFor(token, expiresIn) {
|
|
|
97
200
|
function ensureConfigDirectory() {
|
|
98
201
|
const directory = dirname(TOKEN_FILE_PATH);
|
|
99
202
|
mkdirSync(directory, { recursive: true, mode: CONFIG_DIR_MODE });
|
|
100
|
-
|
|
203
|
+
chmodSync2(directory, CONFIG_DIR_MODE);
|
|
101
204
|
}
|
|
102
|
-
function
|
|
205
|
+
function atomicWrite2(path, content) {
|
|
103
206
|
ensureConfigDirectory();
|
|
104
207
|
atomicWriteFile(path, content, { mode: CREDENTIAL_FILE_MODE });
|
|
105
208
|
}
|
|
@@ -138,7 +241,7 @@ function credentialFamilyMetadata(accessToken, refreshToken2, metadata) {
|
|
|
138
241
|
return metadata === void 0 ? legacyBrokerCredentialMetadata(accessToken, refreshToken2) : { ...metadata, ...hashes };
|
|
139
242
|
}
|
|
140
243
|
function writeCredentialMigrationSentinel() {
|
|
141
|
-
|
|
244
|
+
atomicWrite2(
|
|
142
245
|
CREDENTIAL_MIGRATION_PATH,
|
|
143
246
|
`${JSON.stringify({
|
|
144
247
|
version: CREDENTIAL_MIGRATION_VERSION,
|
|
@@ -156,7 +259,7 @@ function bindLegacyBrokerGeneration(accessToken, refreshToken2, metadata) {
|
|
|
156
259
|
return { state: "invalid" };
|
|
157
260
|
}
|
|
158
261
|
if (metadata.metadata === void 0) {
|
|
159
|
-
|
|
262
|
+
atomicWrite2(CREDENTIAL_FAMILY_PATH, `${JSON.stringify(familyMetadata)}
|
|
160
263
|
`);
|
|
161
264
|
}
|
|
162
265
|
const migrationState = readCredentialMigrationState();
|
|
@@ -171,14 +274,14 @@ function preserveMarkerlessLegacyGeneration() {
|
|
|
171
274
|
const refreshToken2 = readTrimmed(REFRESH_TOKEN_PATH);
|
|
172
275
|
if (!(accessToken && refreshToken2)) return;
|
|
173
276
|
const familyMetadata = legacyBrokerCredentialMetadata(accessToken, refreshToken2);
|
|
174
|
-
|
|
277
|
+
atomicWrite2(CREDENTIAL_FAMILY_PATH, `${JSON.stringify(familyMetadata)}
|
|
175
278
|
`);
|
|
176
279
|
}
|
|
177
280
|
function terminalFingerprint() {
|
|
178
281
|
return readTrimmed(TERMINAL_REFRESH_PATH);
|
|
179
282
|
}
|
|
180
283
|
function writeTerminalFingerprint(refreshToken2) {
|
|
181
|
-
|
|
284
|
+
atomicWrite2(TERMINAL_REFRESH_PATH, `${refreshFingerprint(refreshToken2)}
|
|
182
285
|
`);
|
|
183
286
|
}
|
|
184
287
|
function clearTerminalFingerprint() {
|
|
@@ -203,24 +306,24 @@ function commitCredentialsUnlocked(credentials) {
|
|
|
203
306
|
if (credentials.metadata !== void 0) {
|
|
204
307
|
preserveMarkerlessLegacyGeneration();
|
|
205
308
|
writeCredentialMigrationSentinel();
|
|
206
|
-
|
|
309
|
+
atomicWrite2(CREDENTIAL_FAMILY_PATH, `${JSON.stringify(familyMetadata)}
|
|
207
310
|
`);
|
|
208
|
-
|
|
311
|
+
atomicWrite2(CREDENTIAL_METADATA_PATH, `${JSON.stringify(familyMetadata)}
|
|
209
312
|
`);
|
|
210
|
-
|
|
313
|
+
atomicWrite2(REFRESH_TOKEN_PATH, `${refreshToken2}
|
|
211
314
|
`);
|
|
212
315
|
} else {
|
|
213
|
-
|
|
316
|
+
atomicWrite2(REFRESH_TOKEN_PATH, `${refreshToken2}
|
|
214
317
|
`);
|
|
215
|
-
|
|
318
|
+
atomicWrite2(CREDENTIAL_FAMILY_PATH, `${JSON.stringify(familyMetadata)}
|
|
216
319
|
`);
|
|
217
320
|
removeCredentialFile(CREDENTIAL_METADATA_PATH);
|
|
218
321
|
}
|
|
219
322
|
const expiresAt = expiresAtFor(accessToken, credentials.expiresIn);
|
|
220
323
|
if (expiresAt === void 0) removeCredentialFile(TOKEN_EXPIRES_PATH);
|
|
221
|
-
else
|
|
324
|
+
else atomicWrite2(TOKEN_EXPIRES_PATH, `${expiresAt}
|
|
222
325
|
`);
|
|
223
|
-
|
|
326
|
+
atomicWrite2(TOKEN_FILE_PATH, `${accessToken}
|
|
224
327
|
`);
|
|
225
328
|
clearTerminalFingerprint();
|
|
226
329
|
_cachedCredential = { token: accessToken, source: "token_file" };
|
|
@@ -238,7 +341,7 @@ async function setStoredToken(token, options = {}) {
|
|
|
238
341
|
removeCredentialFile(CREDENTIAL_METADATA_PATH);
|
|
239
342
|
clearTerminalFingerprint();
|
|
240
343
|
removeCredentialFile(CREDENTIAL_MIGRATION_PATH);
|
|
241
|
-
|
|
344
|
+
atomicWrite2(TOKEN_FILE_PATH, `${value}
|
|
242
345
|
`);
|
|
243
346
|
_cachedCredential = { token: value, source: "token_file" };
|
|
244
347
|
}, options);
|
|
@@ -531,12 +634,13 @@ function selectedCredential() {
|
|
|
531
634
|
}
|
|
532
635
|
return _cachedCredential;
|
|
533
636
|
}
|
|
534
|
-
function fetchWithToken(method, path, body, options, token, siteUrl) {
|
|
637
|
+
async function fetchWithToken(method, path, body, options, token, siteUrl) {
|
|
535
638
|
return fetch(`${siteUrl}${path}`, {
|
|
536
639
|
method,
|
|
537
640
|
headers: {
|
|
538
641
|
Authorization: `Bearer ${token}`,
|
|
539
|
-
"Content-Type": "application/json"
|
|
642
|
+
"Content-Type": "application/json",
|
|
643
|
+
...method === "POST" && path === "/api/cli/moves/ingest" ? await ingestUploaderHeaders() : {}
|
|
540
644
|
},
|
|
541
645
|
body: body === void 0 ? void 0 : JSON.stringify(body),
|
|
542
646
|
signal: options?.signal
|
|
@@ -2,16 +2,16 @@ import {
|
|
|
2
2
|
getClient,
|
|
3
3
|
getSiteUrl,
|
|
4
4
|
terminalSafeLine
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-2IRLFOEL.js";
|
|
6
6
|
import {
|
|
7
7
|
daemonRequest
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-5LRKJTLA.js";
|
|
9
9
|
import {
|
|
10
10
|
canonicalGitRoot,
|
|
11
11
|
canonicalRepositoryPath,
|
|
12
12
|
currentBranch,
|
|
13
13
|
repoSyncId
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-XG7S3LIL.js";
|
|
15
15
|
|
|
16
16
|
// src/daemon/proxy.ts
|
|
17
17
|
var DAEMON_HTTP_TIMEOUT_MS = 1e4;
|
|
@@ -2,10 +2,10 @@ import {
|
|
|
2
2
|
cursorHooksPath,
|
|
3
3
|
hasExactCursorHandler,
|
|
4
4
|
readCursorHooks
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-K4JWJ6OM.js";
|
|
6
6
|
import {
|
|
7
7
|
resolveRepositoryContext
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-XG7S3LIL.js";
|
|
9
9
|
|
|
10
10
|
// src/hooks/agent.ts
|
|
11
11
|
function parseAgent(argv) {
|
|
@@ -3,10 +3,10 @@ import {
|
|
|
3
3
|
} from "./chunk-EZXEWFDG.js";
|
|
4
4
|
import {
|
|
5
5
|
scrubEnvironmentPaths
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-ZNLIGT3J.js";
|
|
7
7
|
import {
|
|
8
8
|
isValidRepoSyncId
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-XG7S3LIL.js";
|
|
10
10
|
|
|
11
11
|
// src/hooks/prim-hook-core.ts
|
|
12
12
|
import { createHash, randomUUID } from "crypto";
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getSiteUrl
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-2IRLFOEL.js";
|
|
4
4
|
import {
|
|
5
5
|
atomicWriteFile,
|
|
6
6
|
ensureDurableDirectory,
|
|
7
7
|
jwtOrganizationId,
|
|
8
8
|
primConfigDirectory,
|
|
9
9
|
resolveAuthCredential
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-XG7S3LIL.js";
|
|
11
11
|
|
|
12
12
|
// src/journal.ts
|
|
13
13
|
import {
|
|
@@ -7,17 +7,17 @@ import {
|
|
|
7
7
|
} from "./chunk-MXVCP33E.js";
|
|
8
8
|
import {
|
|
9
9
|
scrubEnvironmentPaths
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-ZNLIGT3J.js";
|
|
11
11
|
import {
|
|
12
12
|
cachedCollectScopeAdmits
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-25DDRMWS.js";
|
|
14
14
|
import {
|
|
15
15
|
canonicalRepositoryPath,
|
|
16
16
|
currentBranch,
|
|
17
17
|
isRepoActiveForCapture,
|
|
18
18
|
relatedWorktreeTarget,
|
|
19
19
|
repoSyncId
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-XG7S3LIL.js";
|
|
21
21
|
|
|
22
22
|
// src/hooks/file-refs.ts
|
|
23
23
|
var MAX_PREFLIGHT_FILE_TARGETS = 25;
|