@primitive.ai/prim 0.1.0-alpha.92 → 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 (39) hide show
  1. package/README.md +34 -2
  2. package/dist/{chunk-67VNLLBN.js → chunk-2GP5UFV7.js} +1 -0
  3. package/dist/{chunk-ADUTW66W.js → chunk-36TWVNBE.js} +6 -6
  4. package/dist/{chunk-5HRR4AOR.js → chunk-C3VAA5CG.js} +1 -1
  5. package/dist/{chunk-LGGMJYY4.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-26P57LAR.js → chunk-X64HTHUF.js} +3 -1
  17. package/dist/{chunk-WX52U7Z2.js → chunk-ZU563PQI.js} +58 -2
  18. package/dist/daemon/server.js +372 -123
  19. package/dist/hook-runtime/daemon/server.js +372 -123
  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 +95 -62
  23. package/dist/hook-runtime/hooks/pre-tool-use.js +32 -10
  24. package/dist/hook-runtime/hooks/prim-hook.js +142 -102
  25. package/dist/hook-runtime/hooks/session-start.js +37 -3
  26. package/dist/hook-runtime/index.js +1264 -523
  27. package/dist/hook-runtime/statusline-main.js +23 -1
  28. package/dist/hooks/post-commit.js +11 -8
  29. package/dist/hooks/post-rewrite.js +11 -8
  30. package/dist/hooks/post-tool-use.js +13 -15
  31. package/dist/hooks/pre-commit.js +4 -4
  32. package/dist/hooks/pre-tool-use.js +10 -12
  33. package/dist/hooks/prim-hook.js +17 -14
  34. package/dist/hooks/session-end.js +4 -4
  35. package/dist/hooks/session-start.js +12 -36
  36. package/dist/index.js +857 -290
  37. package/dist/statusline-main.js +23 -1
  38. package/package.json +1 -1
  39. package/dist/chunk-BTNNEH2W.js +0 -79
@@ -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)})`;