@indigoai-us/hq-cli 5.345.245 → 5.345.246
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/CHANGELOG.md +82 -0
- package/dist/command-catalog.generated.d.ts +93 -6
- package/dist/command-catalog.generated.js +114 -6
- package/dist/commands/bot.js +1 -1
- package/dist/commands/core-checkpoint-native.d.ts +5 -1
- package/dist/commands/core-checkpoint-native.js +13 -5
- package/dist/commands/deploy-comments.js +139 -0
- package/dist/commands/deploy-list.d.ts +5 -0
- package/dist/commands/deploy-list.js +8 -0
- package/dist/commands/dm.d.ts +4 -1
- package/dist/commands/dm.js +11 -2
- package/dist/commands/files.d.ts +11 -2
- package/dist/commands/files.js +48 -3
- package/dist/commands/lanes-loop.js +4 -1
- package/dist/commands/lanes.js +16 -5
- package/dist/commands/mesh.d.ts +2 -0
- package/dist/commands/mesh.js +26 -6
- package/dist/commands/reindex.js +2 -1
- package/dist/commands/rescue.d.ts +22 -1
- package/dist/commands/rescue.js +56 -9
- package/dist/commands/sources.d.ts +1 -1
- package/dist/commands/sources.js +1 -1
- package/dist/commands/storage.d.ts +15 -2
- package/dist/commands/storage.js +74 -7
- package/dist/hq-cloud-sync-runner/bin/sync-runner.js +232 -225
- package/dist/hq-cloud-sync-runner/package.json +1 -1
- package/dist/lib/agent-kit/mcp/tools.js +22 -0
- package/dist/lib/bot/jobs/hot-signal-sync.js +4 -1
- package/dist/lib/daemon/fleet-members-cache.d.ts +55 -0
- package/dist/lib/daemon/fleet-members-cache.js +266 -0
- package/dist/lib/daemon/handoff.d.ts +4 -0
- package/dist/lib/daemon/handoff.js +2 -1
- package/dist/lib/daemon/hook-requests.d.ts +2 -1
- package/dist/lib/daemon/hook-requests.js +19 -2
- package/dist/lib/daemon/install.d.ts +9 -1
- package/dist/lib/daemon/install.js +11 -2
- package/dist/lib/daemon/ops/policy.d.ts +23 -3
- package/dist/lib/daemon/ops/policy.js +62 -15
- package/dist/lib/daemon/run.js +12 -0
- package/dist/lib/daemon/server.d.ts +5 -0
- package/dist/lib/daemon/server.js +1 -1
- package/dist/lib/daemon/supervisor.d.ts +6 -0
- package/dist/lib/daemon/supervisor.js +31 -2
- package/dist/lib/doctor/checks/sync-runtime.js +8 -1
- package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
- package/dist/lib/flag-registry-worker-source.generated.js +1 -1
- package/dist/lib/hook-engine/coverage.d.ts +68 -0
- package/dist/lib/hook-engine/coverage.js +163 -0
- package/dist/lib/hook-engine/native-precompact-compatibility.json +1 -0
- package/dist/lib/hot-channels/signals-pass.d.ts +52 -2
- package/dist/lib/hot-channels/signals-pass.js +65 -3
- package/dist/lib/install/claude-targets.d.ts +6 -0
- package/dist/lib/install/claude-targets.js +9 -1
- package/dist/lib/lanes/reconcile-result.d.ts +1 -1
- package/dist/lib/lanes/reconcile.js +19 -4
- package/dist/lib/lanes/remote-control-lane.d.ts +6 -0
- package/dist/lib/lanes/remote-control-lane.js +10 -1
- package/dist/lib/lanes/spawn.d.ts +2 -0
- package/dist/lib/lanes/spawn.js +19 -3
- package/dist/lib/lanes/worker-env-scrub.d.ts +48 -0
- package/dist/lib/lanes/worker-env-scrub.js +146 -0
- package/dist/lib/lanes/worker-process.js +4 -1
- package/dist/lib/mesh/client.js +5 -1
- package/dist/lib/mesh/live/daemon/doctor.d.ts +9 -0
- package/dist/lib/mesh/live/daemon/doctor.js +51 -6
- package/dist/lib/mesh/live/daemon/install.d.ts +39 -0
- package/dist/lib/mesh/live/daemon/install.js +70 -0
- package/dist/lib/mesh/live/daemon/outbox-company.d.ts +47 -0
- package/dist/lib/mesh/live/daemon/outbox-company.js +77 -0
- package/dist/lib/mesh/live/daemon/run.d.ts +2 -0
- package/dist/lib/mesh/live/daemon/run.js +48 -3
- package/dist/lib/mesh/live/daemon/state.d.ts +5 -0
- package/dist/lib/mesh/live/daemon/system-unit.d.ts +21 -0
- package/dist/lib/mesh/live/daemon/system-unit.js +80 -0
- package/dist/lib/mesh/live/daemon/transcript-watch.d.ts +4 -1
- package/dist/lib/mesh/live/daemon/transcript-watch.js +42 -38
- package/dist/lib/mesh/live/direct-drain.js +3 -1
- package/dist/lib/mesh/live/emit.js +4 -2
- package/dist/lib/mesh/live/flush.d.ts +61 -0
- package/dist/lib/mesh/live/flush.js +434 -114
- package/dist/lib/mesh/live/paths.d.ts +10 -0
- package/dist/lib/mesh/live/paths.js +14 -0
- package/dist/lib/mesh/live/reporting-privacy.d.ts +41 -1
- package/dist/lib/mesh/live/reporting-privacy.js +81 -7
- package/dist/lib/mesh/live/spool.d.ts +171 -17
- package/dist/lib/mesh/live/spool.js +777 -62
- package/dist/lib/signals/engine.d.ts +82 -2
- package/dist/lib/signals/engine.js +389 -53
- package/dist/lib/signals/steps/extract.js +5 -0
- package/dist/lib/work-context/organize.d.ts +22 -4
- package/dist/lib/work-context/organize.js +50 -21
- package/dist/lib/work-context/paths.d.ts +6 -0
- package/dist/lib/work-context/paths.js +9 -0
- package/dist/lib/work-context/reconcile.d.ts +1 -1
- package/dist/lib/work-context/reconcile.js +1 -1
- package/dist/startup-registration.d.ts +14 -0
- package/dist/startup-registration.js +26 -0
- package/dist/utils/cli-telemetry.d.ts +6 -0
- package/dist/utils/cli-telemetry.js +154 -9
- package/dist/utils/github-tag-fallback.d.ts +7 -2
- package/dist/utils/github-tag-fallback.js +17 -8
- package/dist/utils/hq-core-source.d.ts +31 -0
- package/dist/utils/hq-core-source.js +144 -0
- package/dist/utils/interactive-caller.d.ts +6 -0
- package/dist/utils/interactive-caller.js +8 -0
- package/dist/utils/shipped-codex-hooks.d.ts +6 -4
- package/dist/utils/shipped-codex-hooks.js +22 -10
- package/dist/utils/vault-api.js +1 -0
- package/dist/utils/version-report.d.ts +3 -1
- package/dist/utils/version-report.js +13 -5
- package/docs/anywhere-runtime.md +2 -2
- package/package.json +8 -8
- package/scripts/check-function-manifest.mjs +99 -18
|
@@ -10,6 +10,16 @@ export declare const OWNER_INBOX_PUSH_STATE_BASENAME = "owner-inbox-push.json";
|
|
|
10
10
|
export declare function workMeshRoot(home?: string, env?: NodeJS.ProcessEnv): string;
|
|
11
11
|
export declare function workMeshSpoolPath(root?: string): string;
|
|
12
12
|
export declare function workMeshHeldPath(root?: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Lines a flush with HQ Anywhere off may not act on (a session without a
|
|
15
|
+
* verified company binding, events from before HQ Anywhere was seen off, lines
|
|
16
|
+
* that are not events). They wait here instead of on the spool, so they are
|
|
17
|
+
* not claimed and re-read on every flush. Offered again when HQ Anywhere is on
|
|
18
|
+
* or a parked session's company binding changes.
|
|
19
|
+
*/
|
|
20
|
+
export declare function workMeshParkedPath(root?: string): string;
|
|
21
|
+
/** Per-session binding recorded when lines were parked (see workMeshParkedPath). */
|
|
22
|
+
export declare function workMeshParkedIndexPath(root?: string): string;
|
|
13
23
|
/** Rotating cursor for bounded daemon-start held-event recovery. */
|
|
14
24
|
export declare function workMeshHeldBackfillCursorPath(root?: string): string;
|
|
15
25
|
export declare function workMeshDeadLetterPath(root?: string): string;
|
|
@@ -22,6 +22,20 @@ export function workMeshSpoolPath(root) {
|
|
|
22
22
|
export function workMeshHeldPath(root) {
|
|
23
23
|
return path.join(root ?? workMeshRoot(), "held.jsonl");
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Lines a flush with HQ Anywhere off may not act on (a session without a
|
|
27
|
+
* verified company binding, events from before HQ Anywhere was seen off, lines
|
|
28
|
+
* that are not events). They wait here instead of on the spool, so they are
|
|
29
|
+
* not claimed and re-read on every flush. Offered again when HQ Anywhere is on
|
|
30
|
+
* or a parked session's company binding changes.
|
|
31
|
+
*/
|
|
32
|
+
export function workMeshParkedPath(root) {
|
|
33
|
+
return path.join(root ?? workMeshRoot(), "spool.parked.jsonl");
|
|
34
|
+
}
|
|
35
|
+
/** Per-session binding recorded when lines were parked (see workMeshParkedPath). */
|
|
36
|
+
export function workMeshParkedIndexPath(root) {
|
|
37
|
+
return path.join(root ?? workMeshRoot(), "spool.parked.index.json");
|
|
38
|
+
}
|
|
25
39
|
/** Rotating cursor for bounded daemon-start held-event recovery. */
|
|
26
40
|
export function workMeshHeldBackfillCursorPath(root) {
|
|
27
41
|
return path.join(root ?? workMeshRoot(), "held-backfill-cursor.json");
|
|
@@ -1,9 +1,49 @@
|
|
|
1
1
|
import { type SessionStateFile } from "../../work-context/state.js";
|
|
2
2
|
/** Match the off controls used by the hook and handoff command. */
|
|
3
3
|
export declare function workMeshSwitchDisabled(env?: NodeJS.ProcessEnv): boolean;
|
|
4
|
-
|
|
4
|
+
/** Privacy gate: missing, stale or unreadable snapshots never override a member's off switch.
|
|
5
|
+
* The notice hold explicitly requires confirmed on, unlike default-on kill switches.
|
|
6
|
+
*/
|
|
7
|
+
export declare const WORK_MESH_COMPANY_REPORTING_REQUIRED = "work-mesh-company-reporting-required";
|
|
8
|
+
export declare function workMeshCompanyReportingRequired(companyUid?: string, env?: NodeJS.ProcessEnv): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* `root` is the Work Context root the state was read from; it holds the
|
|
11
|
+
* session's fleet runtime record. Defaults to the root `env` names.
|
|
12
|
+
*
|
|
13
|
+
* A fleet session is exempt from the notice hold in two ways: its own hook
|
|
14
|
+
* recorded the fleet runtime (`recordedFleetSession`), or the judging process
|
|
15
|
+
* is that fleet session itself (`ownFleetSession`). The second keeps fleet
|
|
16
|
+
* agents reporting as before when no record was written, for example an
|
|
17
|
+
* agents-v2 session with Work Mesh on, where the hook never writes one.
|
|
18
|
+
*/
|
|
19
|
+
export declare function hasWorkMeshCompanyBinding(state: SessionStateFile | null, env?: NodeJS.ProcessEnv, root?: string): state is SessionStateFile & {
|
|
5
20
|
companyUid: string;
|
|
6
21
|
};
|
|
22
|
+
/**
|
|
23
|
+
* This process runs under a fleet agent adapter and `sessionId` is the
|
|
24
|
+
* session its environment names. A fleet agent judging its own session is
|
|
25
|
+
* never held (policy indigo-fleet-agent-telemetry-always-on), as before the
|
|
26
|
+
* per-session record. Other sessions, such as a member's sessions in a home a
|
|
27
|
+
* fleet-local bot shares, are judged by their own record only.
|
|
28
|
+
*/
|
|
29
|
+
export declare function ownFleetSession(sessionId: string, env?: NodeJS.ProcessEnv): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* The session's own hook recorded that a fleet agent adapter ran it. Fleet
|
|
32
|
+
* agents are not held (policy indigo-fleet-agent-telemetry-always-on). This
|
|
33
|
+
* is read per session: the member's daemon and a fleet process both judge
|
|
34
|
+
* other sessions' events (the emit retry file, the spool, the daemon-disable
|
|
35
|
+
* scan), so the judging process's environment exempts only its own session
|
|
36
|
+
* (`ownFleetSession`).
|
|
37
|
+
*/
|
|
38
|
+
export declare function recordedFleetSession(sessionId: string, root: string): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* This process runs under a fleet agent adapter. Mirrors
|
|
41
|
+
* `fleet_agent_runtime` in crates/hq-hook/src/mesh_session_policy.rs. It
|
|
42
|
+
* describes this process only: it exempts this process's own session
|
|
43
|
+
* (`ownFleetSession`), and whether another session is a fleet agent's is read
|
|
44
|
+
* from that session's record (`recordedFleetSession`).
|
|
45
|
+
*/
|
|
46
|
+
export declare function fleetAgentRuntime(env?: NodeJS.ProcessEnv): boolean;
|
|
7
47
|
/**
|
|
8
48
|
* The operator's HQ Anywhere switch, read from the server's flag snapshot
|
|
9
49
|
* only. A flag override in the member's own environment (`HQ_FLAG_*`) is the
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
|
+
import { readFlagSnapshotFile, readPersonFlagSnapshotFile } from "../../flag-snapshot-file.js";
|
|
2
3
|
import * as os from "node:os";
|
|
3
4
|
import { anywhereRuntimeAllowed, personTokenCachePath, readHqAnywherePersonSetting } from "../../anywhere-person-setting.js";
|
|
4
5
|
import { anywhereRuntimeRevocationMarkerPath } from "../../anywhere-runtime-revocation-marker.js";
|
|
@@ -9,8 +10,9 @@ import { isNonCloudCompanySlug } from "../../work-context/company-rebind.js";
|
|
|
9
10
|
import { readMetaCompanySlug, resolveCompany } from "../../work-context/company.js";
|
|
10
11
|
import { deriveRemoteOwnerSlug, deriveRepoIdentityKey } from "../../work-context/repo-remote.js";
|
|
11
12
|
import * as path from "node:path";
|
|
12
|
-
import { workContextRoot, workContextSessionsDir } from "../../work-context/paths.js";
|
|
13
|
+
import { isSafeWorkContextSegment, isWorkContextSessionStateFileName, workContextFleetRuntimePath, workContextRoot, workContextSessionsDir, } from "../../work-context/paths.js";
|
|
13
14
|
import { SESSION_COMPANY_CHANGE_COMMAND } from "../../work-context/errors.js";
|
|
15
|
+
import { sessionIdFromEnv } from "../../core-utils/session-id.js";
|
|
14
16
|
import { readSessionState } from "../../work-context/state.js";
|
|
15
17
|
/** Match the off controls used by the hook and handoff command. */
|
|
16
18
|
export function workMeshSwitchDisabled(env = process.env) {
|
|
@@ -18,13 +20,84 @@ export function workMeshSwitchDisabled(env = process.env) {
|
|
|
18
20
|
return ["1", "true", "TRUE", "yes", "YES", "on", "ON"].includes(env.HQ_WORK_MESH_DISABLED ?? "") ||
|
|
19
21
|
hooks.some(value => ["*", "work-mesh", "work-mesh-live"].includes(value));
|
|
20
22
|
}
|
|
21
|
-
|
|
23
|
+
/** Privacy gate: missing, stale or unreadable snapshots never override a member's off switch.
|
|
24
|
+
* The notice hold explicitly requires confirmed on, unlike default-on kill switches.
|
|
25
|
+
*/
|
|
26
|
+
export const WORK_MESH_COMPANY_REPORTING_REQUIRED = "work-mesh-company-reporting-required";
|
|
27
|
+
export function workMeshCompanyReportingRequired(companyUid, env = process.env) {
|
|
28
|
+
const snapshot = companyUid
|
|
29
|
+
? readFlagSnapshotFile(companyUid, { env })
|
|
30
|
+
: readPersonFlagSnapshotFile({ env });
|
|
31
|
+
return snapshot?.flags[WORK_MESH_COMPANY_REPORTING_REQUIRED] === true;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* `root` is the Work Context root the state was read from; it holds the
|
|
35
|
+
* session's fleet runtime record. Defaults to the root `env` names.
|
|
36
|
+
*
|
|
37
|
+
* A fleet session is exempt from the notice hold in two ways: its own hook
|
|
38
|
+
* recorded the fleet runtime (`recordedFleetSession`), or the judging process
|
|
39
|
+
* is that fleet session itself (`ownFleetSession`). The second keeps fleet
|
|
40
|
+
* agents reporting as before when no record was written, for example an
|
|
41
|
+
* agents-v2 session with Work Mesh on, where the hook never writes one.
|
|
42
|
+
*/
|
|
43
|
+
export function hasWorkMeshCompanyBinding(state, env = process.env, root) {
|
|
22
44
|
return state?.contractVersion === 1 && typeof state.companyUid === "string" && !!state.companyUid.trim() &&
|
|
23
45
|
(state.contextStatus === "bound" || state.contextStatus === "needs_project" || state.contextStatus === "needs_task") &&
|
|
24
46
|
state.companyConfidence !== "device_default" &&
|
|
25
47
|
state.ownerMismatch?.companyUid !== state.companyUid &&
|
|
26
48
|
(state.companySlug === undefined || typeof state.companySlug === "string") &&
|
|
27
|
-
!isNonCloudCompanySlug(state.companySlug)
|
|
49
|
+
!isNonCloudCompanySlug(state.companySlug) &&
|
|
50
|
+
(ownFleetSession(state.sessionId, env) ||
|
|
51
|
+
recordedFleetSession(state.sessionId, root ?? workContextRoot(undefined, env)) ||
|
|
52
|
+
workMeshCompanyReportingRequired(state.companyUid, env));
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* This process runs under a fleet agent adapter and `sessionId` is the
|
|
56
|
+
* session its environment names. A fleet agent judging its own session is
|
|
57
|
+
* never held (policy indigo-fleet-agent-telemetry-always-on), as before the
|
|
58
|
+
* per-session record. Other sessions, such as a member's sessions in a home a
|
|
59
|
+
* fleet-local bot shares, are judged by their own record only.
|
|
60
|
+
*/
|
|
61
|
+
export function ownFleetSession(sessionId, env = process.env) {
|
|
62
|
+
if (!fleetAgentRuntime(env))
|
|
63
|
+
return false;
|
|
64
|
+
const own = sessionIdFromEnv(env);
|
|
65
|
+
return own !== "" && own === sessionId;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The session's own hook recorded that a fleet agent adapter ran it. Fleet
|
|
69
|
+
* agents are not held (policy indigo-fleet-agent-telemetry-always-on). This
|
|
70
|
+
* is read per session: the member's daemon and a fleet process both judge
|
|
71
|
+
* other sessions' events (the emit retry file, the spool, the daemon-disable
|
|
72
|
+
* scan), so the judging process's environment exempts only its own session
|
|
73
|
+
* (`ownFleetSession`).
|
|
74
|
+
*/
|
|
75
|
+
export function recordedFleetSession(sessionId, root) {
|
|
76
|
+
if (!isSafeWorkContextSegment(sessionId))
|
|
77
|
+
return false;
|
|
78
|
+
try {
|
|
79
|
+
const raw = fs.readFileSync(workContextFleetRuntimePath(sessionId, root), "utf8");
|
|
80
|
+
if (raw.length > 4096)
|
|
81
|
+
return false;
|
|
82
|
+
const record = JSON.parse(raw);
|
|
83
|
+
return typeof record === "object" && record !== null &&
|
|
84
|
+
FLEET_AGENT_RUNTIMES.has(String(record.runtime ?? "").trim());
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/** The runtimes the fleet agent adapters set in HQ_CHECKPOINT_RUNTIME (hq-hook `stop::fleet::runtime`). */
|
|
91
|
+
const FLEET_AGENT_RUNTIMES = new Set(["hq-fleet-local", "agents-v2"]);
|
|
92
|
+
/**
|
|
93
|
+
* This process runs under a fleet agent adapter. Mirrors
|
|
94
|
+
* `fleet_agent_runtime` in crates/hq-hook/src/mesh_session_policy.rs. It
|
|
95
|
+
* describes this process only: it exempts this process's own session
|
|
96
|
+
* (`ownFleetSession`), and whether another session is a fleet agent's is read
|
|
97
|
+
* from that session's record (`recordedFleetSession`).
|
|
98
|
+
*/
|
|
99
|
+
export function fleetAgentRuntime(env = process.env) {
|
|
100
|
+
return FLEET_AGENT_RUNTIMES.has((env.HQ_CHECKPOINT_RUNTIME ?? "").trim());
|
|
28
101
|
}
|
|
29
102
|
/**
|
|
30
103
|
* The operator's HQ Anywhere switch, read from the server's flag snapshot
|
|
@@ -50,8 +123,9 @@ export function hasWorkMeshEventCompanyBinding(event, env) {
|
|
|
50
123
|
return false;
|
|
51
124
|
// The scope files SessionStart can mint from a guess do not grant the
|
|
52
125
|
// switch exception. Use the established binding for this exact session.
|
|
53
|
-
const
|
|
54
|
-
|
|
126
|
+
const root = workContextRoot(undefined, env);
|
|
127
|
+
const state = readSessionState(event.sessionId, root);
|
|
128
|
+
return hasWorkMeshCompanyBinding(state, env, root) && eventMatchesWorkMeshCompany(event, state.companySlug);
|
|
55
129
|
}
|
|
56
130
|
/** The file, in the Work Mesh root, that holds when HQ Anywhere was first seen off on this machine. */
|
|
57
131
|
export const ANYWHERE_OFF_SINCE_BASENAME = "anywhere-off-since";
|
|
@@ -157,14 +231,14 @@ export function anyRecentSessionHasWorkMeshCompanyBinding(home, env = process.en
|
|
|
157
231
|
continue;
|
|
158
232
|
}
|
|
159
233
|
for (const name of names) {
|
|
160
|
-
if (!name
|
|
234
|
+
if (!isWorkContextSessionStateFileName(name))
|
|
161
235
|
continue;
|
|
162
236
|
if ((read += 1) > SESSION_BINDING_SCAN_MAX)
|
|
163
237
|
return false;
|
|
164
238
|
const sessionId = path.basename(name, ".json");
|
|
165
239
|
try {
|
|
166
240
|
const state = readSessionState(sessionId, root);
|
|
167
|
-
if (state?.sessionId !== sessionId || !hasWorkMeshCompanyBinding(state))
|
|
241
|
+
if (state?.sessionId !== sessionId || !hasWorkMeshCompanyBinding(state, env, root))
|
|
168
242
|
continue;
|
|
169
243
|
let at = Date.parse(state.updatedAt);
|
|
170
244
|
if (!Number.isFinite(at))
|
|
@@ -17,16 +17,29 @@ export declare function ensureSpoolFile(filePath: string): void;
|
|
|
17
17
|
* Append one JSON line (without newline in `line`) as a single write under O_APPEND.
|
|
18
18
|
*/
|
|
19
19
|
export declare function appendJsonlLine(filePath: string, line: string): void;
|
|
20
|
-
/**
|
|
21
|
-
* Put lines back on the spool exactly as they were read: the same bytes, one
|
|
22
|
-
* write per line under O_APPEND, in the order given. Nothing is parsed or
|
|
23
|
-
* checked; a line a flush is not allowed to act on is not its to change.
|
|
24
|
-
*/
|
|
25
|
-
export declare function appendRawSpoolLines(lines: readonly string[], root?: string): void;
|
|
26
20
|
export declare function appendSpoolLine(line: string, root?: string): string;
|
|
27
21
|
export declare function appendHeldLine(line: string, root?: string): string;
|
|
28
22
|
/** Append a deduplicated held batch under one file lock and one write. */
|
|
29
23
|
export declare function appendHeldLinesIfAbsent(lines: string[], root?: string): number;
|
|
24
|
+
/**
|
|
25
|
+
* Appends whole lines to a JSONL file with bounded memory: lines are buffered
|
|
26
|
+
* up to about 64 KB, then written with one open, one O_APPEND write and one
|
|
27
|
+
* close. A short write throws SpoolWriteError. `writeChunk` replaces the plain
|
|
28
|
+
* append (the parked file writes its index under a lock first).
|
|
29
|
+
*/
|
|
30
|
+
export declare class JsonlAppender {
|
|
31
|
+
private readonly filePath;
|
|
32
|
+
private readonly writeChunk;
|
|
33
|
+
private buffered;
|
|
34
|
+
private bytes;
|
|
35
|
+
/** Lines written to disk so far. */
|
|
36
|
+
written: number;
|
|
37
|
+
constructor(filePath: string, writeChunk?: (filePath: string, lines: string[]) => void);
|
|
38
|
+
push(line: string): void;
|
|
39
|
+
/** Lines pushed and not yet written. */
|
|
40
|
+
get pending(): number;
|
|
41
|
+
flush(): void;
|
|
42
|
+
}
|
|
30
43
|
export declare function appendDeadLetterLine(line: string, root?: string): string;
|
|
31
44
|
/** Trim oldest held events under the same lock used by enqueue and claim. */
|
|
32
45
|
export declare function trimHeld(root: string, maxLines: number, now: () => Date): number;
|
|
@@ -44,6 +57,15 @@ export declare function trimDeadLetter(root: string, opts: {
|
|
|
44
57
|
protectBefore: string;
|
|
45
58
|
}): number;
|
|
46
59
|
export declare function appendDroppedReceipt(receipt: Record<string, unknown>, root?: string): string;
|
|
60
|
+
/**
|
|
61
|
+
* Append a dropped receipt unless one with the same `receiptId` is already in
|
|
62
|
+
* the file: a flush that dies after writing it and before removing its claim
|
|
63
|
+
* reads the same claim again and drops the same lines, and must not count
|
|
64
|
+
* them twice. Returns true when the receipt was written.
|
|
65
|
+
*/
|
|
66
|
+
export declare function appendDroppedReceiptOnce(receipt: Record<string, unknown> & {
|
|
67
|
+
receiptId: string;
|
|
68
|
+
}, root?: string): boolean;
|
|
47
69
|
export interface ClaimResult {
|
|
48
70
|
claimPath: string | null;
|
|
49
71
|
lines: string[];
|
|
@@ -53,6 +75,102 @@ export interface ClaimResult {
|
|
|
53
75
|
* Concurrent appends after the rename land on a fresh file.
|
|
54
76
|
*/
|
|
55
77
|
export declare function claimJsonlByRename(sourcePath: string, claimPath: string): ClaimResult;
|
|
78
|
+
/**
|
|
79
|
+
* Rename a jsonl file aside and return the claim path without reading it, or
|
|
80
|
+
* null when there was nothing to claim. The flush streams the claim itself.
|
|
81
|
+
*/
|
|
82
|
+
export declare function claimJsonlPathByRename(sourcePath: string, claimPath: string): string | null;
|
|
83
|
+
/** {@link claimSpool} without reading the claim. */
|
|
84
|
+
export declare function claimSpoolPath(root: string, ts?: string): string | null;
|
|
85
|
+
/** {@link claimHeld} without reading the claim. */
|
|
86
|
+
export declare function claimHeldPath(root: string, ts?: string): string | null;
|
|
87
|
+
/**
|
|
88
|
+
* The parked file's index: for each parked session, its company binding when
|
|
89
|
+
* its lines were parked ("bound:<slug>" or "unbound"). Read on every flush
|
|
90
|
+
* while HQ Anywhere is off, so a binding change can be seen without reading
|
|
91
|
+
* the parked lines.
|
|
92
|
+
*/
|
|
93
|
+
export interface ParkedIndex {
|
|
94
|
+
v: 1;
|
|
95
|
+
sessions: Record<string, string>;
|
|
96
|
+
/**
|
|
97
|
+
* When the parked file's lines were parked, in file order: `lines`
|
|
98
|
+
* consecutive non-empty lines parked at `parkedAt` (null: not known, for a
|
|
99
|
+
* file written before this was recorded). Absent in such a file's index.
|
|
100
|
+
*/
|
|
101
|
+
segments?: ParkedSegment[];
|
|
102
|
+
/** Size of the parked file the segments describe; segments of a file of another size are not used. */
|
|
103
|
+
bytes?: number;
|
|
104
|
+
}
|
|
105
|
+
export interface ParkedSegment {
|
|
106
|
+
lines: number;
|
|
107
|
+
parkedAt: string | null;
|
|
108
|
+
}
|
|
109
|
+
/** The oldest and newest known parked-at times of the parked file, or null when none is known. */
|
|
110
|
+
export declare function parkedTimesRange(root: string): {
|
|
111
|
+
oldestMs: number;
|
|
112
|
+
newestMs: number;
|
|
113
|
+
} | null;
|
|
114
|
+
/**
|
|
115
|
+
* The segments of a parked claim, only when they describe it: the claim is
|
|
116
|
+
* the size recorded with them and holds as many non-empty lines as they
|
|
117
|
+
* count. Otherwise null, and every line is of unknown age.
|
|
118
|
+
*/
|
|
119
|
+
export declare function verifiedParkedClaimTimes(claimPath: string): ParkedSegment[] | null;
|
|
120
|
+
export declare function segmentsRange(segments: ParkedSegment[]): {
|
|
121
|
+
oldestMs: number;
|
|
122
|
+
newestMs: number;
|
|
123
|
+
} | null;
|
|
124
|
+
/** Sidecar of a parked claim: the parked-at segments its lines had in the parked file. */
|
|
125
|
+
export declare function parkedClaimTimesPath(claimPath: string): string;
|
|
126
|
+
/** The parked-at segments recorded for a parked claim (unverified), or null when none were. */
|
|
127
|
+
export declare function readParkedClaimTimes(claimPath: string): ParkedSegment[] | null;
|
|
128
|
+
/** Remove staging files left by a flush that died more than an hour ago. */
|
|
129
|
+
export declare function removeStaleStagingFiles(root: string, nowMs?: number): void;
|
|
130
|
+
export interface StagedAppender {
|
|
131
|
+
push(line: string): void;
|
|
132
|
+
/** Lines pushed so far. */
|
|
133
|
+
readonly count: number;
|
|
134
|
+
/** Append the staged lines to the target file, then remove the staging file. */
|
|
135
|
+
commit(): void;
|
|
136
|
+
/** Remove the staging file without touching the target. */
|
|
137
|
+
discard(): void;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Lines a flush writes back while it is still reading its claims go to a
|
|
141
|
+
* private staging file first, and reach the spool only on commit, once every
|
|
142
|
+
* claim was read to the end. A flush that fails partway through the read
|
|
143
|
+
* discards the staging file and keeps its claims, so a failure that repeats
|
|
144
|
+
* on every flush never writes the same lines to the spool again and again.
|
|
145
|
+
*/
|
|
146
|
+
export declare function createStagedAppender(root: string, target: string): StagedAppender;
|
|
147
|
+
/**
|
|
148
|
+
* Appender for the parked file. Lines are staged (see createStagedAppender)
|
|
149
|
+
* and reach the parked file on commit, under the parked lock together with the
|
|
150
|
+
* index entries of their sessions, so a concurrent re-offer (which renames the
|
|
151
|
+
* file and removes the index under the same lock) never separates lines from
|
|
152
|
+
* their index entries. The index is written on every commit, also when no
|
|
153
|
+
* parked line has a session id, so such lines are not re-offered on every
|
|
154
|
+
* flush. `bindingOf` gives the binding to record for a session.
|
|
155
|
+
*/
|
|
156
|
+
export declare function createParkedAppender(root: string, bindingOf: (sessionId: string) => string): {
|
|
157
|
+
/** `parkedAt`: when the line was first parked (now, for a line not parked before). */
|
|
158
|
+
push(line: string, sessionId: string | null, parkedAt: string): void;
|
|
159
|
+
commit(): void;
|
|
160
|
+
/** Append the staged lines to `target` instead (no index), then remove the staging file. */
|
|
161
|
+
commitTo(target: string): void;
|
|
162
|
+
discard(): void;
|
|
163
|
+
readonly count: number;
|
|
164
|
+
};
|
|
165
|
+
/**
|
|
166
|
+
* Offer the parked lines to a flush again: under the parked lock, rename the
|
|
167
|
+
* parked file to a spool claim (`spool.<ts>.parked.claimed`, which orphan
|
|
168
|
+
* recovery reads like any spool claim) and remove its index. `changed` decides
|
|
169
|
+
* from the index; it is not asked when the index is missing or unreadable, and
|
|
170
|
+
* the lines are offered then, so the index is rebuilt. Returns the claim path,
|
|
171
|
+
* or null when nothing was offered.
|
|
172
|
+
*/
|
|
173
|
+
export declare function reofferParkedLines(root: string, ts: string, changed: ((index: ParkedIndex) => boolean) | null): string | null;
|
|
56
174
|
export declare function claimSpool(root: string, ts?: string): ClaimResult;
|
|
57
175
|
export declare function claimHeld(root: string, ts?: string): ClaimResult;
|
|
58
176
|
/**
|
|
@@ -83,17 +201,10 @@ export declare function recoverOrphanClaims(root: string): {
|
|
|
83
201
|
claimPaths: string[];
|
|
84
202
|
unreadable: UnreadableClaim[];
|
|
85
203
|
};
|
|
204
|
+
/** Every orphaned claim file, spool and held, oldest name first. */
|
|
205
|
+
export declare function listOrphanClaims(root: string): string[];
|
|
86
206
|
/** Orphaned claim files of the spool only (never held claims). */
|
|
87
207
|
export declare function listOrphanSpoolClaims(root: string): string[];
|
|
88
|
-
/**
|
|
89
|
-
* {@link recoverOrphanClaims} for spool claims only. Used when the member has
|
|
90
|
-
* HQ Anywhere switched off: held lines and held claims are left where they are.
|
|
91
|
-
*/
|
|
92
|
-
export declare function recoverOrphanSpoolClaims(root: string): {
|
|
93
|
-
lines: string[];
|
|
94
|
-
claimPaths: string[];
|
|
95
|
-
unreadable: UnreadableClaim[];
|
|
96
|
-
};
|
|
97
208
|
export declare function removeClaimFile(claimPath: string | null): void;
|
|
98
209
|
export declare function deadLetterNonEmpty(root?: string): boolean;
|
|
99
210
|
/**
|
|
@@ -101,9 +212,52 @@ export declare function deadLetterNonEmpty(root?: string): boolean;
|
|
|
101
212
|
* string. Queue files (dead-letter especially) can grow past V8's ~512 MB
|
|
102
213
|
* string ceiling, where readFileSync(..., "utf8") throws. Splits on the raw
|
|
103
214
|
* newline byte so multi-byte UTF-8 sequences are never cut. Returns false when
|
|
104
|
-
* the file cannot be opened.
|
|
215
|
+
* the file cannot be opened. A visitor that returns `false` stops the read.
|
|
216
|
+
*/
|
|
217
|
+
export declare function forEachJsonlLine(filePath: string, visit: (line: string) => void | boolean): boolean;
|
|
218
|
+
/** Let timers, sockets and MQTT keepalives run between read chunks. */
|
|
219
|
+
export declare const yieldToEventLoop: () => Promise<void>;
|
|
220
|
+
/**
|
|
221
|
+
* {@link forEachJsonlLine}, yielding to the event loop after every full read
|
|
222
|
+
* chunk (1 MB), so a read of a very large file does not hold up timers,
|
|
223
|
+
* sockets or MQTT keepalives for its whole length. A file under one chunk is
|
|
224
|
+
* read without yielding. Lines are visited in the same order
|
|
225
|
+
* with the same content. Returns false when the file cannot be opened.
|
|
226
|
+
*/
|
|
227
|
+
export declare function forEachJsonlLineAsync(filePath: string, visit: (line: string) => void | boolean, yieldNow?: () => Promise<void>): Promise<boolean>;
|
|
228
|
+
/**
|
|
229
|
+
* Read a JSONL file: synchronously when it fits in one read chunk (no pause,
|
|
230
|
+
* no extra promise, as before), otherwise with {@link forEachJsonlLineAsync}.
|
|
231
|
+
* Callers await only a promise result.
|
|
232
|
+
*/
|
|
233
|
+
export declare function forEachJsonlLineYielding(filePath: string, visit: (line: string) => void | boolean): boolean | Promise<boolean>;
|
|
234
|
+
/** How the dead-letter id index was kept up to date (tests read this). */
|
|
235
|
+
export declare const deadLetterIdIndexStats: {
|
|
236
|
+
fullScans: number;
|
|
237
|
+
tailReads: number;
|
|
238
|
+
};
|
|
239
|
+
/** Forget remembered dead-letter ids (tests). */
|
|
240
|
+
export declare function resetDeadLetterIdIndexes(): void;
|
|
241
|
+
/** A dead-letter file at least this large is compacted when the daemon starts. */
|
|
242
|
+
export declare const DEAD_LETTER_COMPACT_MIN_BYTES: number;
|
|
243
|
+
export interface DeadLetterCompaction {
|
|
244
|
+
compacted: boolean;
|
|
245
|
+
linesBefore: number;
|
|
246
|
+
linesAfter: number;
|
|
247
|
+
bytesBefore: number;
|
|
248
|
+
bytesAfter: number;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Rewrite dead-letter.jsonl keeping the first line per eventId (lines with no
|
|
252
|
+
* eventId are all kept). Nothing is expired by age. The file is read with the
|
|
253
|
+
* event loop yielding between chunks and written to a temp file; then, under
|
|
254
|
+
* the dead-letter lock, lines appended meanwhile are added and the temp file
|
|
255
|
+
* is renamed over the original. Below `minBytes` nothing is done.
|
|
105
256
|
*/
|
|
106
|
-
export declare function
|
|
257
|
+
export declare function compactDeadLetter(root: string, opts?: {
|
|
258
|
+
minBytes?: number;
|
|
259
|
+
yieldNow?: () => Promise<void>;
|
|
260
|
+
}): Promise<DeadLetterCompaction>;
|
|
107
261
|
export declare function countJsonlLines(filePath: string): number;
|
|
108
262
|
/** Count held eventIds once; legacy rows without an eventId remain line-counted. */
|
|
109
263
|
export declare function countDistinctHeldEvents(filePath: string): number;
|