@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.
- package/README.md +34 -2
- package/dist/{chunk-67VNLLBN.js → chunk-2GP5UFV7.js} +1 -0
- package/dist/{chunk-ADUTW66W.js → chunk-36TWVNBE.js} +6 -6
- package/dist/{chunk-5HRR4AOR.js → chunk-C3VAA5CG.js} +1 -1
- package/dist/{chunk-LGGMJYY4.js → chunk-DCJN6LZH.js} +37 -5
- package/dist/{chunk-M6RIJVRE.js → chunk-DSWT6BCC.js} +78 -4
- package/dist/{chunk-FBAYCS3X.js → chunk-DXJQR4QI.js} +150 -38
- package/dist/{chunk-PCVGBE5B.js → chunk-G2VMA2QO.js} +2 -1
- package/dist/{chunk-NAHHFSLH.js → chunk-ICM2XCXS.js} +2 -2
- package/dist/{chunk-OAAP2MY6.js → chunk-K7D2EYBS.js} +2 -2
- package/dist/{chunk-5AFRMOPX.js → chunk-OH3EZXYX.js} +1 -1
- package/dist/{chunk-KFXF2V5G.js → chunk-OTHKG76J.js} +1 -1
- package/dist/chunk-OYHYCK4K.js +13 -0
- package/dist/{chunk-FKXFUUWJ.js → chunk-TYAHC25F.js} +1 -1
- package/dist/{chunk-5GYQ4J3D.js → chunk-UKUAAAXE.js} +2 -2
- package/dist/{chunk-26P57LAR.js → chunk-X64HTHUF.js} +3 -1
- package/dist/{chunk-WX52U7Z2.js → chunk-ZU563PQI.js} +58 -2
- package/dist/daemon/server.js +372 -123
- package/dist/hook-runtime/daemon/server.js +372 -123
- package/dist/hook-runtime/hooks/post-commit.js +57 -39
- package/dist/hook-runtime/hooks/post-rewrite.js +58 -40
- package/dist/hook-runtime/hooks/post-tool-use.js +95 -62
- package/dist/hook-runtime/hooks/pre-tool-use.js +32 -10
- package/dist/hook-runtime/hooks/prim-hook.js +142 -102
- package/dist/hook-runtime/hooks/session-start.js +37 -3
- package/dist/hook-runtime/index.js +1264 -523
- package/dist/hook-runtime/statusline-main.js +23 -1
- package/dist/hooks/post-commit.js +11 -8
- package/dist/hooks/post-rewrite.js +11 -8
- package/dist/hooks/post-tool-use.js +13 -15
- package/dist/hooks/pre-commit.js +4 -4
- package/dist/hooks/pre-tool-use.js +10 -12
- package/dist/hooks/prim-hook.js +17 -14
- package/dist/hooks/session-end.js +4 -4
- package/dist/hooks/session-start.js +12 -36
- package/dist/index.js +857 -290
- package/dist/statusline-main.js +23 -1
- package/package.json +1 -1
- package/dist/chunk-BTNNEH2W.js +0 -79
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/lib/unattended.ts
|
|
2
|
+
var UNATTENDED_ENV = "PRIM_UNATTENDED";
|
|
3
|
+
function unattendedEnv(env = process.env) {
|
|
4
|
+
return { ...env, [UNATTENDED_ENV]: "1" };
|
|
5
|
+
}
|
|
6
|
+
function isUnattended(env = process.env) {
|
|
7
|
+
return env[UNATTENDED_ENV] === "1";
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export {
|
|
11
|
+
unattendedEnv,
|
|
12
|
+
isUnattended
|
|
13
|
+
};
|
|
@@ -2,10 +2,10 @@ import {
|
|
|
2
2
|
getClient,
|
|
3
3
|
getSiteUrl,
|
|
4
4
|
terminalSafeLine
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-G2VMA2QO.js";
|
|
6
6
|
import {
|
|
7
7
|
daemonRequest
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-OTHKG76J.js";
|
|
9
9
|
|
|
10
10
|
// src/daemon/proxy.ts
|
|
11
11
|
var DAEMON_HTTP_TIMEOUT_MS = 1e4;
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
syncDirectory,
|
|
8
8
|
syncFile,
|
|
9
9
|
withFileLockSync
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-2GP5UFV7.js";
|
|
11
11
|
|
|
12
12
|
// src/lib/bin-path.ts
|
|
13
13
|
import { existsSync, readFileSync } from "fs";
|
|
@@ -1460,6 +1460,7 @@ export {
|
|
|
1460
1460
|
compareSemver,
|
|
1461
1461
|
binFile,
|
|
1462
1462
|
packageVersion,
|
|
1463
|
+
packageRoot,
|
|
1463
1464
|
pinnedNpxArgs,
|
|
1464
1465
|
pinnedNpxCommand,
|
|
1465
1466
|
pinnedHookCommand,
|
|
@@ -1468,6 +1469,7 @@ export {
|
|
|
1468
1469
|
hookCommandResolutions,
|
|
1469
1470
|
hookRuntimePaths,
|
|
1470
1471
|
inspectHookRuntime,
|
|
1472
|
+
stableNodePath,
|
|
1471
1473
|
stageHookRuntime,
|
|
1472
1474
|
assertOwnedHookRuntime,
|
|
1473
1475
|
removeHookRuntime,
|
|
@@ -1,6 +1,57 @@
|
|
|
1
|
+
import {
|
|
2
|
+
boundedHealthError
|
|
3
|
+
} from "./chunk-DSWT6BCC.js";
|
|
1
4
|
import {
|
|
2
5
|
stripControlChars
|
|
3
|
-
} from "./chunk-
|
|
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
|
-
|
|
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
|