@primitive.ai/prim 0.1.0-alpha.111 → 0.1.0-alpha.112

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.
Files changed (40) hide show
  1. package/README.md +11 -1
  2. package/SKILL.md +12 -2
  3. package/dist/{chunk-KQ4WBK5R.js → chunk-3KKEV7VI.js} +2 -2
  4. package/dist/{chunk-2IRLFOEL.js → chunk-6JHKKLA2.js} +79 -1
  5. package/dist/{chunk-IQZA65NV.js → chunk-7DVEH7FO.js} +1 -1
  6. package/dist/{chunk-W4ZEPZLK.js → chunk-BXLH4LDU.js} +1 -1
  7. package/dist/{chunk-GA2RXPJL.js → chunk-DWAXFXDG.js} +2 -2
  8. package/dist/{chunk-7VIMU2HR.js → chunk-FTW4ZCBA.js} +2 -2
  9. package/dist/{chunk-JJI7FU24.js → chunk-HMD5K6W7.js} +1 -1
  10. package/dist/{chunk-HTRFPXMD.js → chunk-IW5HCCOW.js} +3 -3
  11. package/dist/{chunk-UDBBJWQH.js → chunk-IZXLH3R5.js} +930 -582
  12. package/dist/{chunk-5LRKJTLA.js → chunk-J5HBSRAV.js} +7 -5
  13. package/dist/{chunk-5BLGBSDM.js → chunk-JDIAPBY7.js} +1 -1
  14. package/dist/{chunk-2Q3OGSTV.js → chunk-NEQI2VLM.js} +2 -2
  15. package/dist/{chunk-AOJ254C2.js → chunk-PJW6JZMH.js} +4 -4
  16. package/dist/{chunk-43ZKL27W.js → chunk-RTULPLS7.js} +1 -1
  17. package/dist/{chunk-CTRAJCPN.js → chunk-XV6C5ZV2.js} +1 -1
  18. package/dist/daemon/server.js +1184 -754
  19. package/dist/hook-runtime/daemon/server.js +1184 -754
  20. package/dist/hook-runtime/hooks/post-commit.js +929 -581
  21. package/dist/hook-runtime/hooks/post-rewrite.js +929 -581
  22. package/dist/hook-runtime/hooks/post-tool-use.js +1015 -588
  23. package/dist/hook-runtime/hooks/pre-commit.js +85 -6
  24. package/dist/hook-runtime/hooks/pre-tool-use.js +1017 -591
  25. package/dist/hook-runtime/hooks/prim-hook.js +1016 -589
  26. package/dist/hook-runtime/hooks/session-end.js +14 -12
  27. package/dist/hook-runtime/hooks/session-start.js +1016 -589
  28. package/dist/hook-runtime/index.js +1211 -791
  29. package/dist/hook-runtime/statusline-main.js +7 -5
  30. package/dist/hooks/post-commit.js +5 -5
  31. package/dist/hooks/post-rewrite.js +5 -5
  32. package/dist/hooks/post-tool-use.js +12 -12
  33. package/dist/hooks/pre-commit.js +3 -3
  34. package/dist/hooks/pre-tool-use.js +10 -11
  35. package/dist/hooks/prim-hook.js +12 -12
  36. package/dist/hooks/session-end.js +1 -1
  37. package/dist/hooks/session-start.js +7 -7
  38. package/dist/index.js +177 -183
  39. package/dist/statusline-main.js +7 -5
  40. package/package.json +2 -1
@@ -3,6 +3,83 @@
3
3
  // src/hooks/pre-commit.ts
4
4
  import { execSync } from "child_process";
5
5
 
6
+ // src/decisions/identity.ts
7
+ var PUBLIC_ID = /^dec_[0-9a-f]{8}$/u;
8
+ var BARE_ID = /^[0-9a-f]{8}$/u;
9
+ var OPAQUE_FIELDS = /* @__PURE__ */ new Set([
10
+ "cursor",
11
+ "continueCursor",
12
+ "nextCursor",
13
+ "reviewToken",
14
+ "bypassToken"
15
+ ]);
16
+ function decisionIdentifier(id, shortId) {
17
+ if (typeof id === "string" && PUBLIC_ID.test(id)) return id;
18
+ if (typeof shortId === "string" && BARE_ID.test(shortId)) return `dec_${shortId}`;
19
+ if (typeof id === "string" && BARE_ID.test(id)) return `dec_${id}`;
20
+ return void 0;
21
+ }
22
+ function publicDecisionResponse(value) {
23
+ const replacements = /* @__PURE__ */ new Map();
24
+ const referenceKeys = /* @__PURE__ */ new Set([
25
+ "decisionId",
26
+ "childId",
27
+ "parentId",
28
+ "supersededBy",
29
+ "activationDecisionId"
30
+ ]);
31
+ function visit(input, field = "") {
32
+ if (OPAQUE_FIELDS.has(field) || input === null || input === void 0) return input;
33
+ if (Array.isArray(input)) return input.map((item) => visit(item, field));
34
+ if (typeof input === "string" && (referenceKeys.has(field) || /DecisionIds$/u.test(field))) {
35
+ const id = decisionIdentifier(input);
36
+ if (!id) throw new Error("Decision identity unavailable; update Primitive and retry");
37
+ return id;
38
+ }
39
+ if (typeof input !== "object") return input;
40
+ const row = { ...input };
41
+ for (const [idKey, shortKey] of [
42
+ ["id", "shortId"],
43
+ ["_id", "shortId"],
44
+ ["decisionId", "shortId"],
45
+ ["childId", "childShortId"],
46
+ ["parentId", "parentShortId"]
47
+ ]) {
48
+ if (!(idKey in row) || (idKey === "id" || idKey === "_id") && !("intent" in row || "shortId" in row))
49
+ continue;
50
+ const id = decisionIdentifier(
51
+ row[idKey],
52
+ row[shortKey] ?? (idKey === "decisionId" ? row.decisionShortId : void 0)
53
+ );
54
+ if (!id) throw new Error("Decision identity unavailable; update Primitive and retry");
55
+ const previous = row[idKey];
56
+ if (typeof previous === "string" && !PUBLIC_ID.test(previous) && !BARE_ID.test(previous)) {
57
+ replacements.set(previous, id);
58
+ }
59
+ if (shortKey in row) row[shortKey] = id.slice(4);
60
+ if (idKey === "decisionId" && "decisionShortId" in row) row.decisionShortId = id.slice(4);
61
+ row[idKey] = id;
62
+ }
63
+ return Object.fromEntries(Object.entries(row).map(([key, item]) => [key, visit(item, key)]));
64
+ }
65
+ const projected = visit(value);
66
+ function replace(input, field = "") {
67
+ if (OPAQUE_FIELDS.has(field)) return input;
68
+ if (typeof input === "string") {
69
+ let output = input;
70
+ for (const [raw, id] of replacements) if (raw !== id) output = output.replaceAll(raw, id);
71
+ return output;
72
+ }
73
+ if (Array.isArray(input)) return input.map((item) => replace(item, field));
74
+ if (input && typeof input === "object")
75
+ return Object.fromEntries(
76
+ Object.entries(input).map(([key, item]) => [key, replace(item, key)])
77
+ );
78
+ return input;
79
+ }
80
+ return replace(projected);
81
+ }
82
+
6
83
  // src/client.ts
7
84
  import { createHash as createHash2 } from "crypto";
8
85
  import { chmodSync as chmodSync2, existsSync as existsSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync5, rmSync as rmSync3 } from "fs";
@@ -1134,7 +1211,7 @@ async function responseValue(response) {
1134
1211
  const message = typeof errorRecord?.error === "string" ? errorRecord.error : `HTTP ${response.status}`;
1135
1212
  throw new HttpError(response.status, message, errorBody);
1136
1213
  }
1137
- return response.json();
1214
+ return publicDecisionResponse(await response.json());
1138
1215
  }
1139
1216
  async function request(method, path, body, options) {
1140
1217
  const siteUrl = getSiteUrl();
@@ -1180,10 +1257,6 @@ function getClient() {
1180
1257
  };
1181
1258
  }
1182
1259
 
1183
- // src/daemon/client.ts
1184
- import { createConnection } from "net";
1185
- import { join as join7 } from "path";
1186
-
1187
1260
  // src/daemon/principal.ts
1188
1261
  import { createHash as createHash3 } from "crypto";
1189
1262
  var PRINCIPAL_COMPONENT_MAX_LENGTH = 512;
@@ -1210,6 +1283,7 @@ function resolveDaemonPrincipal(token = resolveAuthCredential()?.token) {
1210
1283
  // src/daemon/protocol.ts
1211
1284
  var DAEMON_JSON_REQUEST_MAX_BYTES = 64 * 1024;
1212
1285
  var DAEMON_JSON_RESPONSE_MAX_BYTES = 8 * 1024 * 1024;
1286
+ var DECISION_IDENTITY_VERSION = 7;
1213
1287
  function isRecord(value) {
1214
1288
  return typeof value === "object" && value !== null && !Array.isArray(value);
1215
1289
  }
@@ -1222,6 +1296,7 @@ function parseDaemonResponseEnvelope(value) {
1222
1296
  if (value.error !== void 0 && typeof value.error !== "string") return void 0;
1223
1297
  return {
1224
1298
  id: value.id,
1299
+ ...typeof value.decisionIdentityVersion === "number" ? { decisionIdentityVersion: value.decisionIdentityVersion } : {},
1225
1300
  ok: value.ok,
1226
1301
  ...value.result === void 0 ? {} : { result: value.result },
1227
1302
  ...value.error === void 0 ? {} : { error: value.error }
@@ -1229,6 +1304,8 @@ function parseDaemonResponseEnvelope(value) {
1229
1304
  }
1230
1305
 
1231
1306
  // src/daemon/client.ts
1307
+ import { createConnection } from "net";
1308
+ import { join as join7 } from "path";
1232
1309
  var SOCK_PATH = join7(primConfigDirectory(), "sock");
1233
1310
  var DEFAULT_TIMEOUT_MS2 = 250;
1234
1311
  var nextRequestId = 1;
@@ -1301,7 +1378,9 @@ function daemonRequest(method, params = {}, opts = {}) {
1301
1378
  return;
1302
1379
  }
1303
1380
  clearTimeout(timer);
1304
- settle(res.ok && res.result !== void 0 ? res.result : null);
1381
+ settle(
1382
+ (!(method.startsWith("decisions_") || method.startsWith("decision_")) || res.decisionIdentityVersion === DECISION_IDENTITY_VERSION) && res.ok && res.result !== void 0 ? res.result : null
1383
+ );
1305
1384
  } catch {
1306
1385
  clearTimeout(timer);
1307
1386
  settle(null);