@primitive.ai/prim 0.1.0-alpha.92 → 0.1.0-alpha.94

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 (42) hide show
  1. package/README.md +84 -10
  2. package/SKILL.md +5 -2
  3. package/dist/{chunk-67VNLLBN.js → chunk-2GP5UFV7.js} +1 -0
  4. package/dist/{chunk-26P57LAR.js → chunk-AXQQMX2U.js} +203 -9
  5. package/dist/{chunk-M6RIJVRE.js → chunk-DSWT6BCC.js} +78 -4
  6. package/dist/{chunk-FBAYCS3X.js → chunk-DXJQR4QI.js} +150 -38
  7. package/dist/chunk-FXF4JWK2.js +162 -0
  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-5HRR4AOR.js → chunk-IMK4JKTA.js} +1 -1
  11. package/dist/{chunk-OAAP2MY6.js → chunk-K7D2EYBS.js} +2 -2
  12. package/dist/{chunk-ADUTW66W.js → chunk-O7YAW7G6.js} +6 -6
  13. package/dist/{chunk-5AFRMOPX.js → chunk-OH3EZXYX.js} +1 -1
  14. package/dist/{chunk-KFXF2V5G.js → chunk-OTHKG76J.js} +1 -1
  15. package/dist/chunk-OYHYCK4K.js +13 -0
  16. package/dist/{chunk-FKXFUUWJ.js → chunk-TYAHC25F.js} +1 -1
  17. package/dist/{chunk-5GYQ4J3D.js → chunk-UKUAAAXE.js} +2 -2
  18. package/dist/{chunk-LGGMJYY4.js → chunk-WUXFLE7X.js} +720 -369
  19. package/dist/{chunk-WX52U7Z2.js → chunk-ZU563PQI.js} +58 -2
  20. package/dist/daemon/server.js +372 -123
  21. package/dist/hook-runtime/daemon/server.js +372 -123
  22. package/dist/hook-runtime/hooks/post-commit.js +192 -58
  23. package/dist/hook-runtime/hooks/post-rewrite.js +58 -40
  24. package/dist/hook-runtime/hooks/post-tool-use.js +150 -67
  25. package/dist/hook-runtime/hooks/pre-tool-use.js +87 -15
  26. package/dist/hook-runtime/hooks/prim-hook.js +197 -107
  27. package/dist/hook-runtime/hooks/session-end.js +53 -5
  28. package/dist/hook-runtime/hooks/session-start.js +880 -280
  29. package/dist/hook-runtime/index.js +4008 -2438
  30. package/dist/hook-runtime/statusline-main.js +23 -1
  31. package/dist/hooks/post-commit.js +15 -8
  32. package/dist/hooks/post-rewrite.js +11 -8
  33. package/dist/hooks/post-tool-use.js +13 -15
  34. package/dist/hooks/pre-commit.js +4 -4
  35. package/dist/hooks/pre-tool-use.js +10 -12
  36. package/dist/hooks/prim-hook.js +17 -14
  37. package/dist/hooks/session-end.js +4 -4
  38. package/dist/hooks/session-start.js +35 -45
  39. package/dist/index.js +1401 -620
  40. package/dist/statusline-main.js +23 -1
  41. package/package.json +1 -1
  42. package/dist/chunk-BTNNEH2W.js +0 -79
@@ -1,6 +1,57 @@
1
+ import {
2
+ boundedHealthError
3
+ } from "./chunk-DSWT6BCC.js";
1
4
  import {
2
5
  stripControlChars
3
- } from "./chunk-PCVGBE5B.js";
6
+ } from "./chunk-G2VMA2QO.js";
7
+
8
+ // src/lib/delivery-backlog.ts
9
+ var MS_PER_SECOND = 1e3;
10
+ var MS_PER_MINUTE = 60 * MS_PER_SECOND;
11
+ var MS_PER_HOUR = 60 * MS_PER_MINUTE;
12
+ var MS_PER_DAY = 24 * MS_PER_HOUR;
13
+ function isNonNegativeInteger(value) {
14
+ return typeof value === "number" && Number.isInteger(value) && value >= 0;
15
+ }
16
+ function isPositiveInteger(value) {
17
+ return isNonNegativeInteger(value) && value > 0;
18
+ }
19
+ function deliveryBacklogState(ingestion) {
20
+ if (ingestion?.healthy !== false) return void 0;
21
+ const failures = ingestion.consecutiveFailures;
22
+ const failedWithoutProgress = failures !== 0 && !(isPositiveInteger(failures) && isPositiveInteger(ingestion.lastFailedDrainAcknowledgedCount));
23
+ if (failedWithoutProgress) return "failing";
24
+ const retained = ingestion.lastRetainedBucketCount;
25
+ if (!isNonNegativeInteger(retained)) return "failing";
26
+ return retained > 0 ? "retained" : "draining";
27
+ }
28
+ function formatBacklogAge(ageMs) {
29
+ if (ageMs >= MS_PER_DAY) return `${String(Math.floor(ageMs / MS_PER_DAY))}d`;
30
+ if (ageMs >= MS_PER_HOUR) return `${String(Math.floor(ageMs / MS_PER_HOUR))}h`;
31
+ if (ageMs >= MS_PER_MINUTE) return `${String(Math.floor(ageMs / MS_PER_MINUTE))}m`;
32
+ return `${String(Math.max(0, Math.floor(ageMs / MS_PER_SECOND)))}s`;
33
+ }
34
+ function formatPendingBacklog(backlog, now = Date.now()) {
35
+ const count = backlog.pendingCount;
36
+ const moves = typeof count === "number" && count > 0 ? `${backlog.pendingSampled ? "at least " : ""}${String(count)} pending move${count === 1 ? "" : "s"}` : "an unknown number of pending moves";
37
+ const age = backlog.oldestPendingAt === void 0 ? "" : ` (oldest ${backlog.pendingSampled ? "\u2265 " : ""}${formatBacklogAge(now - backlog.oldestPendingAt)})`;
38
+ return `${moves}${age}`;
39
+ }
40
+ function deliveryBacklogSummary(ingestion, now = Date.now(), backlog = ingestion) {
41
+ const state = deliveryBacklogState(ingestion);
42
+ if (!(state && ingestion && backlog)) return void 0;
43
+ const pending = formatPendingBacklog(backlog, now);
44
+ if (state === "draining") return `draining ${pending} in the background`;
45
+ if (state === "retained") {
46
+ const buckets = ingestion.lastRetainedBucketCount ?? 0;
47
+ const reasons = boundedHealthError(ingestion.lastRetainedReasons);
48
+ return `delivery held back: ${String(buckets)} journal bucket${buckets === 1 ? "" : "s"} retained${reasons ? ` (${reasons})` : ""} \xB7 holding ${pending} \u2014 run \`prim doctor\``;
49
+ }
50
+ const failures = ingestion.consecutiveFailures;
51
+ const count = isPositiveInteger(failures) ? ` (${String(failures)} consecutive failure${failures === 1 ? "" : "s"})` : "";
52
+ const error = boundedHealthError(ingestion.lastError);
53
+ return `delivery failing${count}${error ? `: ${error}` : ""} \xB7 retrying ${pending} in the background`;
54
+ }
4
55
 
5
56
  // src/lib/presence.ts
6
57
  var DECISION_ORIGIN = "https://app.getprimitive.ai";
@@ -76,7 +127,8 @@ function formatStatusline(version, snapshot, resolveIngestionStatus, options = {
76
127
  if (snapshot.ingestion?.healthy === false) {
77
128
  const pending = snapshot.ingestion.pendingCount;
78
129
  const qualifier = snapshot.ingestion.pendingSampled ? "at least " : "";
79
- return `primitive ${version} (daemon: degraded \xB7 delivery: stalled${typeof pending === "number" ? ` \xB7 ${qualifier}${String(pending)} pending` : ""}${repositorySuffix}${ingestionSuffix(ingestionStatus)})`;
130
+ const delivery = deliveryBacklogState(snapshot.ingestion) === "draining" && snapshot.heartbeat?.healthy === true ? "draining" : "stalled";
131
+ return `primitive ${version} (daemon: degraded \xB7 delivery: ${delivery}${typeof pending === "number" ? ` \xB7 ${qualifier}${String(pending)} pending` : ""}${repositorySuffix}${ingestionSuffix(ingestionStatus)})`;
80
132
  }
81
133
  if (snapshot.heartbeat?.healthy === false) {
82
134
  return `primitive ${version} (daemon: degraded \xB7 presence: unavailable${repositorySuffix}${ingestionSuffix(ingestionStatus)})`;
@@ -106,6 +158,10 @@ function formatStatusline(version, snapshot, resolveIngestionStatus, options = {
106
158
  }
107
159
 
108
160
  export {
161
+ MS_PER_SECOND,
162
+ deliveryBacklogState,
163
+ formatPendingBacklog,
164
+ deliveryBacklogSummary,
109
165
  formatTeammates,
110
166
  repositoryBindingDiagnosticLabel,
111
167
  formatStatusline