@primitive.ai/prim 0.1.0-alpha.91 → 0.1.0-alpha.93

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 +34 -2
  2. package/dist/{chunk-67VNLLBN.js → chunk-2GP5UFV7.js} +1 -0
  3. package/dist/{chunk-VW3FDYRT.js → chunk-36TWVNBE.js} +6 -6
  4. package/dist/{chunk-HU4PW6I6.js → chunk-C3VAA5CG.js} +1 -1
  5. package/dist/{chunk-FOLKHXLJ.js → chunk-DCJN6LZH.js} +37 -5
  6. package/dist/{chunk-M6RIJVRE.js → chunk-DSWT6BCC.js} +78 -4
  7. package/dist/{chunk-FBAYCS3X.js → chunk-DXJQR4QI.js} +150 -38
  8. package/dist/{chunk-PCVGBE5B.js → chunk-G2VMA2QO.js} +2 -1
  9. package/dist/{chunk-NAHHFSLH.js → chunk-ICM2XCXS.js} +2 -2
  10. package/dist/{chunk-OAAP2MY6.js → chunk-K7D2EYBS.js} +2 -2
  11. package/dist/{chunk-5AFRMOPX.js → chunk-OH3EZXYX.js} +1 -1
  12. package/dist/{chunk-KFXF2V5G.js → chunk-OTHKG76J.js} +1 -1
  13. package/dist/chunk-OYHYCK4K.js +13 -0
  14. package/dist/{chunk-FKXFUUWJ.js → chunk-TYAHC25F.js} +1 -1
  15. package/dist/{chunk-5GYQ4J3D.js → chunk-UKUAAAXE.js} +2 -2
  16. package/dist/{chunk-EWZMDD44.js → chunk-X64HTHUF.js} +22 -3
  17. package/dist/{chunk-WX52U7Z2.js → chunk-ZU563PQI.js} +58 -2
  18. package/dist/daemon/server.js +382 -124
  19. package/dist/hook-runtime/daemon/server.js +382 -124
  20. package/dist/hook-runtime/hooks/post-commit.js +57 -39
  21. package/dist/hook-runtime/hooks/post-rewrite.js +58 -40
  22. package/dist/hook-runtime/hooks/post-tool-use.js +111 -78
  23. package/dist/hook-runtime/hooks/pre-tool-use.js +48 -26
  24. package/dist/hook-runtime/hooks/prim-hook.js +157 -117
  25. package/dist/hook-runtime/hooks/session-end.js +1 -1
  26. package/dist/hook-runtime/hooks/session-start.js +38 -4
  27. package/dist/hook-runtime/index.js +1293 -526
  28. package/dist/hook-runtime/statusline-main.js +23 -1
  29. package/dist/hooks/post-commit.js +11 -8
  30. package/dist/hooks/post-rewrite.js +11 -8
  31. package/dist/hooks/post-tool-use.js +13 -15
  32. package/dist/hooks/pre-commit.js +4 -4
  33. package/dist/hooks/pre-tool-use.js +10 -12
  34. package/dist/hooks/prim-hook.js +17 -14
  35. package/dist/hooks/session-end.js +4 -4
  36. package/dist/hooks/session-start.js +12 -36
  37. package/dist/index.js +867 -291
  38. package/dist/statusline-main.js +23 -1
  39. package/package.json +1 -1
  40. package/dist/chunk-BTNNEH2W.js +0 -79
@@ -470,7 +470,7 @@ import {
470
470
  utimesSync,
471
471
  writeFileSync as writeFileSync3
472
472
  } from "fs";
473
- import { dirname as dirname4, isAbsolute as isAbsolute3, join as join6, resolve } from "path";
473
+ import { delimiter, dirname as dirname4, isAbsolute as isAbsolute3, join as join6, resolve } from "path";
474
474
 
475
475
  // src/lib/file-lock.ts
476
476
  import { randomBytes } from "crypto";
@@ -331,7 +331,7 @@ import {
331
331
  utimesSync,
332
332
  writeFileSync as writeFileSync3
333
333
  } from "fs";
334
- import { dirname as dirname4, isAbsolute as isAbsolute3, join as join5, resolve } from "path";
334
+ import { delimiter, dirname as dirname4, isAbsolute as isAbsolute3, join as join5, resolve } from "path";
335
335
 
336
336
  // src/lib/file-lock.ts
337
337
  import { randomBytes } from "crypto";
@@ -8837,6 +8837,14 @@ function daemonRequest(method, params = {}, opts = {}) {
8837
8837
 
8838
8838
  // src/daemon/self-heal.ts
8839
8839
  import { spawn } from "child_process";
8840
+
8841
+ // src/lib/unattended.ts
8842
+ var UNATTENDED_ENV = "PRIM_UNATTENDED";
8843
+ function unattendedEnv(env = process.env) {
8844
+ return { ...env, [UNATTENDED_ENV]: "1" };
8845
+ }
8846
+
8847
+ // src/daemon/self-heal.ts
8840
8848
  function kickDaemonEnsure(options = {}) {
8841
8849
  const primEntry = options.primEntry === void 0 ? binFile("prim") : options.primEntry;
8842
8850
  if (!primEntry) {
@@ -8844,14 +8852,18 @@ function kickDaemonEnsure(options = {}) {
8844
8852
  }
8845
8853
  try {
8846
8854
  const args = [primEntry, "daemon", "ensure"];
8847
- if ((options.platform ?? process.platform) === "darwin") {
8855
+ if (options.latestBootstrap ?? (options.platform ?? process.platform) === "darwin") {
8848
8856
  args.push("--latest-bootstrap");
8849
8857
  }
8850
8858
  const child = (options.spawnProcess ?? spawn)(
8851
8859
  options.nodeEntry ?? process.execPath,
8852
8860
  args,
8853
- { detached: true, stdio: "ignore" }
8861
+ // Unattended: neither SessionStart's repair nor a drift heal is a person
8862
+ // running prim, so the child (and its descendants) never heal in turn.
8863
+ { detached: true, stdio: "ignore", env: unattendedEnv() }
8854
8864
  );
8865
+ child.once("error", () => {
8866
+ });
8855
8867
  child.unref();
8856
8868
  return true;
8857
8869
  } catch {
@@ -27853,6 +27865,27 @@ function isActionablePrivateDraft(row) {
27853
27865
  return typeof candidate.id === "string" && SAFE_PRIVATE_DRAFT_ID.test(candidate.id) && typeof candidate.intent === "string" && candidate.authorIsSelf === true && candidate.stage === "draft" && (candidate.intentKind === void 0 || candidate.intentKind === "change");
27854
27866
  }
27855
27867
 
27868
+ // src/lib/delivery-backlog.ts
27869
+ var MS_PER_SECOND = 1e3;
27870
+ var MS_PER_MINUTE = 60 * MS_PER_SECOND;
27871
+ var MS_PER_HOUR = 60 * MS_PER_MINUTE;
27872
+ var MS_PER_DAY = 24 * MS_PER_HOUR;
27873
+ function isNonNegativeInteger(value) {
27874
+ return typeof value === "number" && Number.isInteger(value) && value >= 0;
27875
+ }
27876
+ function isPositiveInteger(value) {
27877
+ return isNonNegativeInteger(value) && value > 0;
27878
+ }
27879
+ function deliveryBacklogState(ingestion) {
27880
+ if (ingestion?.healthy !== false) return void 0;
27881
+ const failures = ingestion.consecutiveFailures;
27882
+ const failedWithoutProgress = failures !== 0 && !(isPositiveInteger(failures) && isPositiveInteger(ingestion.lastFailedDrainAcknowledgedCount));
27883
+ if (failedWithoutProgress) return "failing";
27884
+ const retained = ingestion.lastRetainedBucketCount;
27885
+ if (!isNonNegativeInteger(retained)) return "failing";
27886
+ return retained > 0 ? "retained" : "draining";
27887
+ }
27888
+
27856
27889
  // src/lib/presence.ts
27857
27890
  var DECISION_ORIGIN = "https://app.getprimitive.ai";
27858
27891
  function validDecisionUrl(value) {
@@ -27927,7 +27960,8 @@ function formatStatusline(version, snapshot, resolveIngestionStatus, options = {
27927
27960
  if (snapshot.ingestion?.healthy === false) {
27928
27961
  const pending = snapshot.ingestion.pendingCount;
27929
27962
  const qualifier = snapshot.ingestion.pendingSampled ? "at least " : "";
27930
- return `primitive ${version} (daemon: degraded \xB7 delivery: stalled${typeof pending === "number" ? ` \xB7 ${qualifier}${String(pending)} pending` : ""}${repositorySuffix}${ingestionSuffix(ingestionStatus)})`;
27963
+ const delivery = deliveryBacklogState(snapshot.ingestion) === "draining" && snapshot.heartbeat?.healthy === true ? "draining" : "stalled";
27964
+ return `primitive ${version} (daemon: degraded \xB7 delivery: ${delivery}${typeof pending === "number" ? ` \xB7 ${qualifier}${String(pending)} pending` : ""}${repositorySuffix}${ingestionSuffix(ingestionStatus)})`;
27931
27965
  }
27932
27966
  if (snapshot.heartbeat?.healthy === false) {
27933
27967
  return `primitive ${version} (daemon: degraded \xB7 presence: unavailable${repositorySuffix}${ingestionSuffix(ingestionStatus)})`;