@indigoai-us/hq-cli 5.345.233 → 5.345.235
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 +67 -0
- package/dist/command-catalog.generated.d.ts +240 -7
- package/dist/command-catalog.generated.js +296 -7
- package/dist/command-registration-plan.d.ts +24 -0
- package/dist/command-registration-plan.js +4 -0
- package/dist/commands/bot-companies.d.ts +4 -1
- package/dist/commands/bot-companies.js +5 -1
- package/dist/commands/bot.d.ts +10 -0
- package/dist/commands/bot.js +165 -36
- package/dist/commands/capacity.js +1 -1
- package/dist/commands/core-handoff.js +2 -2
- package/dist/commands/core-ontology-native.js +5 -4
- package/dist/commands/core-pipeline-workflow-runner-native.js +4 -9
- package/dist/commands/deploy-app-db.d.ts +3 -0
- package/dist/commands/deploy-app-db.js +79 -0
- package/dist/commands/deploy-app-upload.d.ts +3 -0
- package/dist/commands/deploy-app-upload.js +120 -0
- package/dist/commands/deploy-comments.js +46 -1
- package/dist/commands/deploy-mutations.js +71 -5
- package/dist/commands/deploy-ssr.d.ts +3 -0
- package/dist/commands/deploy-ssr.js +74 -0
- package/dist/commands/dm.d.ts +7 -1
- package/dist/commands/dm.js +39 -9
- package/dist/commands/doctor.d.ts +1 -0
- package/dist/commands/doctor.js +26 -10
- package/dist/commands/fingerprint.js +4 -9
- package/dist/commands/install-global.js +10 -0
- package/dist/commands/lanes-accounts.js +5 -5
- package/dist/commands/lanes-hold.js +1 -1
- package/dist/commands/lanes-message.js +3 -3
- package/dist/commands/lanes-move.js +1 -1
- package/dist/commands/lanes-resume.js +6 -6
- package/dist/commands/lanes-watch.js +2 -2
- package/dist/commands/lanes.js +21 -21
- package/dist/commands/work-env.d.ts +90 -0
- package/dist/commands/work-env.js +304 -0
- package/dist/lazy-commands.js +2 -10
- package/dist/lib/bot/api.d.ts +27 -0
- package/dist/lib/bot/api.js +28 -2
- package/dist/lib/bot/cloud-create.d.ts +46 -0
- package/dist/lib/bot/cloud-create.js +128 -0
- package/dist/lib/bot/fleet-daemon.js +4 -1
- package/dist/lib/bot/fleet-local.d.ts +7 -0
- package/dist/lib/bot/fleet-local.js +39 -3
- package/dist/lib/bot/fleet-owner-companies.js +2 -2
- package/dist/lib/bot/promote.d.ts +81 -2
- package/dist/lib/bot/promote.js +425 -51
- package/dist/lib/bot/promotion-hold.d.ts +9 -0
- package/dist/lib/bot/promotion-hold.js +29 -0
- package/dist/lib/bot/promotion-receipt.d.ts +10 -0
- package/dist/lib/bot/promotion-receipt.js +41 -1
- package/dist/lib/bot/promotion-upload.d.ts +6 -1
- package/dist/lib/bot/promotion-upload.js +3 -1
- package/dist/lib/bot/readiness.d.ts +9 -0
- package/dist/lib/bot/readiness.js +16 -0
- package/dist/lib/capacity/route.js +4 -4
- package/dist/lib/capacity/sign-in.js +1 -1
- package/dist/lib/checkpoint-ontology/entity-file.js +15 -17
- package/dist/lib/daemon/catalog.d.ts +2 -0
- package/dist/lib/daemon/catalog.js +2 -0
- package/dist/lib/daemon/hook-requests.js +23 -3
- package/dist/lib/daemon/run.d.ts +14 -0
- package/dist/lib/daemon/run.js +24 -14
- package/dist/lib/deploy-api.d.ts +2 -0
- package/dist/lib/deploy-api.js +9 -0
- package/dist/lib/environment/work-requirements.js +1 -1
- package/dist/lib/hook-engine/coverage.js +50 -0
- package/dist/lib/hot-channels/signals-pass.d.ts +0 -76
- package/dist/lib/hot-channels/signals-pass.js +81 -4
- package/dist/lib/lanes/account-company.js +1 -1
- package/dist/lib/lanes/account-ownership.js +1 -1
- package/dist/lib/lanes/accounts.js +1 -1
- package/dist/lib/lanes/delivery.js +7 -7
- package/dist/lib/lanes/dropbox.js +1 -1
- package/dist/lib/lanes/grants.js +3 -3
- package/dist/lib/lanes/hq-root.js +1 -1
- package/dist/lib/lanes/keep-alive-audit.js +2 -2
- package/dist/lib/lanes/links.js +4 -4
- package/dist/lib/lanes/monitor.js +3 -3
- package/dist/lib/lanes/quota-notice.js +1 -1
- package/dist/lib/lanes/reconcile.js +22 -12
- package/dist/lib/lanes/signal-brief-template.js +1 -1
- package/dist/lib/lanes/worker-continuity.js +1 -1
- package/dist/lib/mesh/live/direct-drain.d.ts +1 -0
- package/dist/lib/mesh/live/direct-drain.js +12 -1
- package/dist/lib/mesh/live/emit.d.ts +1 -1
- package/dist/lib/mesh/live/emit.js +10 -5
- package/dist/lib/mesh/live/flush.js +19 -4
- package/dist/lib/mesh/live/reporting-privacy.d.ts +9 -3
- package/dist/lib/mesh/live/reporting-privacy.js +27 -7
- package/dist/lib/mesh/live/spool.d.ts +2 -0
- package/dist/lib/mesh/live/spool.js +41 -0
- package/dist/lib/signals/sanitize.js +5 -4
- package/dist/lib/signals/steps/garden.js +5 -4
- package/dist/lib/windows/jq.d.ts +17 -0
- package/dist/lib/windows/jq.js +72 -0
- package/dist/utils/frontmatter.d.ts +8 -0
- package/dist/utils/frontmatter.js +11 -2
- package/dist/utils/hq-roots-core.d.ts +5 -0
- package/dist/utils/hq-roots-core.js +18 -9
- package/dist/utils/owner-session.d.ts +13 -0
- package/dist/utils/owner-session.js +28 -0
- package/package.json +7 -7
- package/scripts/install-hook-engine.mjs +8 -15
|
@@ -115,7 +115,7 @@ export function heldByOwner(account) {
|
|
|
115
115
|
return !accountHeldByOther(account);
|
|
116
116
|
}
|
|
117
117
|
export function setOwnerCommand(provider, id) {
|
|
118
|
-
return `hq
|
|
118
|
+
return `hq runners accounts set-owner ${provider} ${id} --owning-company <slug|personal|unknown> --holder <owner|name>`;
|
|
119
119
|
}
|
|
120
120
|
/** Warning for an enabled account missing either field; undefined when nothing is missing. */
|
|
121
121
|
export function ownershipWarning(provider, id, account) {
|
|
@@ -89,7 +89,7 @@ export function claudeIdentityDiffers(a, b) {
|
|
|
89
89
|
}
|
|
90
90
|
/** The operator command that lifts a recorded quota hold. */
|
|
91
91
|
export function clearQuotaCommand(provider, accountId) {
|
|
92
|
-
return `hq
|
|
92
|
+
return `hq runners accounts clear-quota ${provider} ${accountId}`;
|
|
93
93
|
}
|
|
94
94
|
export const AUTH_JSON_NAME = "auth.json";
|
|
95
95
|
export const CLAUDE_CREDENTIALS_NAME = ".credentials.json";
|
|
@@ -129,7 +129,7 @@ export function deliveryRefusalReason(lane) {
|
|
|
129
129
|
case "running":
|
|
130
130
|
return "";
|
|
131
131
|
case "awaiting_input":
|
|
132
|
-
return "Lane is awaiting_input. The worker has exited after writing an ask envelope. Use hq
|
|
132
|
+
return "Lane is awaiting_input. The worker has exited after writing an ask envelope. Use hq runners questions answer <question-id>.";
|
|
133
133
|
case "done":
|
|
134
134
|
case "blocked": {
|
|
135
135
|
if (!providerSupportsSessionResume(lane.provider)) {
|
|
@@ -144,9 +144,9 @@ export function deliveryRefusalReason(lane) {
|
|
|
144
144
|
case "cancelled":
|
|
145
145
|
return `Lane is ${state}. The operator stopped it on purpose; a message does not restart it. Resuming from ${state} needs an explicit opt-in, which does not exist yet.`;
|
|
146
146
|
case "interrupted":
|
|
147
|
-
return `Lane is ${state}. The run did not close cleanly and the operator has not decided what to do with it. Resuming from ${state} needs an explicit opt-in: hq
|
|
147
|
+
return `Lane is ${state}. The run did not close cleanly and the operator has not decided what to do with it. Resuming from ${state} needs an explicit opt-in: hq runners resume <lane-id> [--text <message>].`;
|
|
148
148
|
case "failed":
|
|
149
|
-
return `Lane is ${state}. A plain message does not restart it. Its senior can resume the recorded session with: hq
|
|
149
|
+
return `Lane is ${state}. A plain message does not restart it. Its senior can resume the recorded session with: hq runners resume <lane-id> --from-failed --reason <text>.`;
|
|
150
150
|
default: {
|
|
151
151
|
const _exhaustive = state;
|
|
152
152
|
return _exhaustive;
|
|
@@ -362,12 +362,12 @@ export function resumeCommandRefusal(lane, options = {}) {
|
|
|
362
362
|
!(options.allowFailed === true && lane.state === "failed")) {
|
|
363
363
|
return {
|
|
364
364
|
error: "lane_not_resumable",
|
|
365
|
-
message: `Lane is ${lane.state}. hq
|
|
366
|
-
? "use hq
|
|
365
|
+
message: `Lane is ${lane.state}. hq runners resume continues a lane in ${RESUME_COMMAND_STATES.join(", ")}; ${lane.state === "awaiting_input"
|
|
366
|
+
? "use hq runners questions answer <question-id>."
|
|
367
367
|
: lane.state === "queued"
|
|
368
|
-
? "use hq
|
|
368
|
+
? "use hq runners admit <lane-id>."
|
|
369
369
|
: lane.state === "running"
|
|
370
|
-
? "use hq
|
|
370
|
+
? "use hq runners message for a live lane."
|
|
371
371
|
: "a lane in this state is not resumed."}`,
|
|
372
372
|
};
|
|
373
373
|
}
|
|
@@ -717,7 +717,7 @@ export function operatorMessageRefusalReason(state) {
|
|
|
717
717
|
case "running":
|
|
718
718
|
return "";
|
|
719
719
|
case "awaiting_input":
|
|
720
|
-
return "Lane is awaiting_input. The worker has exited after writing an ask envelope. Use hq
|
|
720
|
+
return "Lane is awaiting_input. The worker has exited after writing an ask envelope. Use hq runners questions answer <question-id>.";
|
|
721
721
|
case "blocked":
|
|
722
722
|
return "Lane is blocked. The worker has exited and there is no delivery path.";
|
|
723
723
|
case "interrupted":
|
package/dist/lib/lanes/grants.js
CHANGED
|
@@ -30,7 +30,7 @@ export function terminalChildResumeHireGrantError(current, snapshot, finishedChi
|
|
|
30
30
|
return hireGrantCapacityError(parent, children);
|
|
31
31
|
const requestedGrant = current.released_hire_grant ?? current.hire_grant ?? 0;
|
|
32
32
|
if (requestedGrant > availableChildGrant) {
|
|
33
|
-
return new LanesError("hire_grant_carve_exceeded", `Senior lane ${parent.lane_id} has ${availableChildGrant} unassigned hire grant remaining, but ${terminal ? "terminal" : "finished"} child ${current.lane_id} needs ${requestedGrant} to resume. Ask its senior for more: write an ask envelope with the desired total grant and why; the senior runs hq
|
|
33
|
+
return new LanesError("hire_grant_carve_exceeded", `Senior lane ${parent.lane_id} has ${availableChildGrant} unassigned hire grant remaining, but ${terminal ? "terminal" : "finished"} child ${current.lane_id} needs ${requestedGrant} to resume. Ask its senior for more: write an ask envelope with the desired total grant and why; the senior runs hq runners grant ${parent.lane_id} --hire <n>.`, {
|
|
34
34
|
senior_lane_id: parent.lane_id,
|
|
35
35
|
parent_grant: parentGrant,
|
|
36
36
|
alive_children: children.map((child) => child.lane_id),
|
|
@@ -39,7 +39,7 @@ export function terminalChildResumeHireGrantError(current, snapshot, finishedChi
|
|
|
39
39
|
available_hire_grant: availableChildGrant,
|
|
40
40
|
ask_guidance: {
|
|
41
41
|
envelope: "decision=ask; include the desired total grant and the reason",
|
|
42
|
-
senior_command: `hq
|
|
42
|
+
senior_command: `hq runners grant ${parent.lane_id} --hire <n>`,
|
|
43
43
|
},
|
|
44
44
|
});
|
|
45
45
|
}
|
|
@@ -59,7 +59,7 @@ export function hireGrantCapacityError(parent, children) {
|
|
|
59
59
|
const capacity = children.length === grant
|
|
60
60
|
? `is at its hire grant (${children.length} of ${grant} alive children)`
|
|
61
61
|
: `has exhausted its hire grant (${children.length} alive children; grant ${grant})`;
|
|
62
|
-
const grantCommand = `hq
|
|
62
|
+
const grantCommand = `hq runners grant ${parent.lane_id} --hire <n>`;
|
|
63
63
|
const authorityGuidance = grantor
|
|
64
64
|
? `Its senior ${grantor.kind} ${grantor.id} can raise it with: ${grantCommand}`
|
|
65
65
|
: parent.senior.kind === "user"
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* is never a match. Missing both an explicit root and a real HQ tree is an
|
|
12
12
|
* error — never an empty successful list against the wrong directory.
|
|
13
13
|
*/
|
|
14
|
-
import { resolveLiveRoot } from "../../utils/hq-roots.js";
|
|
14
|
+
import { resolveLiveRoot } from "../../utils/hq-roots-core.js";
|
|
15
15
|
import { LanesError } from "./errors.js";
|
|
16
16
|
export function resolveLanesHqRoot(opts = {}) {
|
|
17
17
|
try {
|
|
@@ -613,7 +613,7 @@ export function buildKeepAliveAudit(input) {
|
|
|
613
613
|
restart: null,
|
|
614
614
|
verdict: "stranded",
|
|
615
615
|
...(lane.terminal_reason === undefined ? {} : { terminal_reason: lane.terminal_reason }),
|
|
616
|
-
remediation: `Ask the senior to run: hq
|
|
616
|
+
remediation: `Ask the senior to run: hq runners resume ${lane.lane_id} --from-failed --reason "recover stranded keep-alive lane"`,
|
|
617
617
|
});
|
|
618
618
|
}
|
|
619
619
|
for (const lane of lanes) {
|
|
@@ -726,7 +726,7 @@ export function formatKeepAliveAuditText(result) {
|
|
|
726
726
|
`finished_story=${result.summary.finished_story}, idle_no_queued_work=${result.summary.idle_no_queued_work} (neither counts against the keep-alive KPI)`,
|
|
727
727
|
`Stopped and not restarted on their own: ${result.summary.stopped_and_not_restarted_on_their_own}`,
|
|
728
728
|
...result.rows.filter((row) => row.remediation).map((row) => `Stranded ${row.lane}: ${row.remediation}`),
|
|
729
|
-
...result.companyless_lead_lanes.map((lane) => `Company-less lead ${lane.lane} (${lane.project}): ${lane.reason}; repair with hq
|
|
729
|
+
...result.companyless_lead_lanes.map((lane) => `Company-less lead ${lane.lane} (${lane.project}): ${lane.reason}; repair with hq runners repair-company ${lane.lane} --company <slug>`),
|
|
730
730
|
...result.errors.map((error) => `Error ${error.lane} (${error.error}) at ${error.path}: ${error.message}`),
|
|
731
731
|
].join("\n");
|
|
732
732
|
}
|
package/dist/lib/lanes/links.js
CHANGED
|
@@ -834,10 +834,10 @@ export async function runLaneLink(subcommand, options) {
|
|
|
834
834
|
if (!messages)
|
|
835
835
|
return {};
|
|
836
836
|
const receipt = claim ? { _hqLinkDelivery: { version: 1, sessionId: sid, link: pointer.link, child: pointer.name ?? null, claims: claim.claims } } : {};
|
|
837
|
-
const acceptance = claim ? `\n\n[conduct receipt] Stable instruction receipt IDs: ${claim.claims.join(",")}. Treat replayed IDs as the same instruction, not new execution authority. After accepting these instructions, acknowledge receipt once with: hq
|
|
837
|
+
const acceptance = claim ? `\n\n[conduct receipt] Stable instruction receipt IDs: ${claim.claims.join(",")}. Treat replayed IDs as the same instruction, not new execution authority. After accepting these instructions, acknowledge receipt once with: hq runners link ack --session-id ${sid} --link ${pointer.link}${pointer.name ? ` --child ${pointer.name}` : ""} --claims ${claim.claims.join(",")}. Receipt acceptance does not approve actions, answer owner pickers, or mean work is completed.` : "";
|
|
838
838
|
const body = (target.role === "conductor"
|
|
839
|
-
? `[conduct] Sessions you are conducting reported while you were working.\nEach report names the session it came from. Relay what the operator needs to know, and answer a session with: hq
|
|
840
|
-
: `[conduct] The session conducting you sent this while you were working.\nTreat it as a new instruction from the operator, taking precedence over your current task where the two conflict. When you have something to tell the conductor - a result, a blocker, a question - send it with: hq
|
|
839
|
+
? `[conduct] Sessions you are conducting reported while you were working.\nEach report names the session it came from. Relay what the operator needs to know, and answer a session with: hq runners link send --child <name> --text '...'\n\n${messages}`
|
|
840
|
+
: `[conduct] The session conducting you sent this while you were working.\nTreat it as a new instruction from the operator, taking precedence over your current task where the two conflict. When you have something to tell the conductor - a result, a blocker, a question - send it with: hq runners link report --state <working|blocked|idle|done> --text '...'\n\n${messages}`) + acceptance;
|
|
841
841
|
return options.event === "PostToolUse"
|
|
842
842
|
? { output: { ...receipt, hookSpecificOutput: { hookEventName: "PostToolUse", additionalContext: body } } }
|
|
843
843
|
: { output: { ...receipt, decision: "block", reason: body } };
|
|
@@ -1027,7 +1027,7 @@ export async function runLaneLink(subcommand, options) {
|
|
|
1027
1027
|
});
|
|
1028
1028
|
// The token is printed once. The successor should pass it on stdin or in a
|
|
1029
1029
|
// file, not on argv, where other processes can read it.
|
|
1030
|
-
return { output: { link: pointer.link, token, expires, adopt: `hq
|
|
1030
|
+
return { output: { link: pointer.link, token, expires, adopt: `hq runners link adopt --link ${pointer.link} --token -` } };
|
|
1031
1031
|
}
|
|
1032
1032
|
if (subcommand === "adopt") {
|
|
1033
1033
|
const sessionId = requireSid();
|
|
@@ -525,9 +525,9 @@ export function readLiveMonitorEvidence(sessionId, options = {}) {
|
|
|
525
525
|
export function monitorReminderText() {
|
|
526
526
|
return [
|
|
527
527
|
"For active Claude senior lanes, arm one live Claude Code Monitor task per uncovered lane:",
|
|
528
|
-
'Monitor(command="hq
|
|
529
|
-
"When the session's cwd is outside the HQ tree, prefix the command with HQ_ROOT=<hq root> (for example HQ_ROOT=/path/to/hq hq
|
|
530
|
-
"Claude Code stops every Monitor after 30 minutes, so a lane stays covered only while a Monitor armed in the last 30 minutes watches it. Re-arm the same call when `hq
|
|
528
|
+
'Monitor(command="hq runners watch <lane-id>...", timeout_ms=1800000)',
|
|
529
|
+
"When the session's cwd is outside the HQ tree, prefix the command with HQ_ROOT=<hq root> (for example HQ_ROOT=/path/to/hq hq runners watch <lane-id>...); the gate counts that form too.",
|
|
530
|
+
"Claude Code stops every Monitor after 30 minutes, so a lane stays covered only while a Monitor armed in the last 30 minutes watches it. Re-arm the same call when `hq runners monitor-check --session <id>` reports the lane as expired.",
|
|
531
531
|
"The caller must pass `--engine codex` or `--engine grok` (or set HQ_LANE_ENGINE; deprecated alias HQ_CONDUCT_ENGINE) for sessions whose engine has no Claude Monitor tool; those engines are never required to provide one.",
|
|
532
532
|
].join("\n");
|
|
533
533
|
}
|
|
@@ -23,7 +23,7 @@ export function quotaLaneNotice(lane, quota) {
|
|
|
23
23
|
];
|
|
24
24
|
if (quota?.provider_text)
|
|
25
25
|
lines.push(`Provider said: "${quota.provider_text}".`);
|
|
26
|
-
lines.push("No account hold was set; other lanes keep using this account.", `To continue this lane: hq
|
|
26
|
+
lines.push("No account hold was set; other lanes keep using this account.", `To continue this lane: hq runners resume ${lane.lane_id} (pass --account <id> to use another account).`);
|
|
27
27
|
return { message_id: `quota-limit:${lane.lane_id}:${lane.version}`, text: lines.join(" ") };
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
@@ -206,10 +206,14 @@ export function currentHopStartedAtMs(question) {
|
|
|
206
206
|
return Number.isFinite(ms) ? ms : Number.NEGATIVE_INFINITY;
|
|
207
207
|
}
|
|
208
208
|
const BLOCKED_ESCALATION_WINDOW_MS = 6 * 60 * 60 * 1000;
|
|
209
|
-
const BLOCKED_ESCALATION_OPERATOR_SESSION = "fad349d4-38a6-4ae0-b8cc-e5dfd1bc3e9a";
|
|
210
209
|
function seniorKey(senior) {
|
|
211
210
|
return senior.id ? `${senior.kind}:${senior.id}` : senior.kind;
|
|
212
211
|
}
|
|
212
|
+
function deferBlockedEscalation(summary, laneId, reason) {
|
|
213
|
+
const skip = { kind: "lane", id: laneId, why: `blocked escalation deferred: ${reason}` };
|
|
214
|
+
summary.skipped.push(skip);
|
|
215
|
+
logSkip(skip);
|
|
216
|
+
}
|
|
213
217
|
function recipientIsOnCurrentHost(recipientHost, currentHost) {
|
|
214
218
|
if (!recipientHost)
|
|
215
219
|
return false;
|
|
@@ -259,7 +263,7 @@ async function reconcileBlockedEscalations(hqRoot, lanes, summary, deps, now) {
|
|
|
259
263
|
if (last && nowMs - Date.parse(last.at) < BLOCKED_ESCALATION_WINDOW_MS)
|
|
260
264
|
continue;
|
|
261
265
|
const directSenior = lane.senior;
|
|
262
|
-
let recipient =
|
|
266
|
+
let recipient = directSenior;
|
|
263
267
|
let recipientHost;
|
|
264
268
|
if (directSenior.kind === "lane" && directSenior.id) {
|
|
265
269
|
let seniorLane;
|
|
@@ -294,9 +298,6 @@ async function reconcileBlockedEscalations(hqRoot, lanes, summary, deps, now) {
|
|
|
294
298
|
continue;
|
|
295
299
|
}
|
|
296
300
|
}
|
|
297
|
-
else if (recipient.kind !== "session") {
|
|
298
|
-
recipient = { kind: "session", id: BLOCKED_ESCALATION_OPERATOR_SESSION };
|
|
299
|
-
}
|
|
300
301
|
}
|
|
301
302
|
if (recipient.kind === "session")
|
|
302
303
|
recipientHost = { kind: "local", id: "primary" };
|
|
@@ -328,6 +329,10 @@ async function reconcileBlockedEscalations(hqRoot, lanes, summary, deps, now) {
|
|
|
328
329
|
(current.escalations?.at(-1) !== undefined &&
|
|
329
330
|
nowMs - Date.parse(current.escalations.at(-1).at) < BLOCKED_ESCALATION_WINDOW_MS))
|
|
330
331
|
continue;
|
|
332
|
+
if (recipient.kind === "user") {
|
|
333
|
+
deferBlockedEscalation(summary, lane.lane_id, "no senior session is recorded");
|
|
334
|
+
continue;
|
|
335
|
+
}
|
|
331
336
|
if (deps.deliverBlockedEscalation && !recipientIsOnCurrentHost(recipientHost, deps.host)) {
|
|
332
337
|
await deps.deliverBlockedEscalation(delivery);
|
|
333
338
|
}
|
|
@@ -335,8 +340,13 @@ async function reconcileBlockedEscalations(hqRoot, lanes, summary, deps, now) {
|
|
|
335
340
|
appendDropboxMessageOnce(hqRoot, recipient.id, { at: delivery.at, message_id: messageId, kind: "blocked_escalation", text });
|
|
336
341
|
}
|
|
337
342
|
else if (recipient.kind === "session" && recipient.id) {
|
|
338
|
-
const
|
|
339
|
-
|
|
343
|
+
const sessionId = recipient.id;
|
|
344
|
+
const dirs = LANE_PROVIDERS.map((provider) => monitorSessionDir(hqRoot, provider, sessionId))
|
|
345
|
+
.filter((dir) => fs.statSync(dir, { throwIfNoEntry: false }) !== undefined);
|
|
346
|
+
if (dirs.length === 0) {
|
|
347
|
+
deferBlockedEscalation(summary, lane.lane_id, `no durable inbox for ${seniorKey(recipient)}`);
|
|
348
|
+
continue;
|
|
349
|
+
}
|
|
340
350
|
if (dirs.length !== 1)
|
|
341
351
|
throw new LanesError("blocked_escalation_recipient_unavailable", `Expected one durable inbox for ${recipient.id}; found ${dirs.length}`);
|
|
342
352
|
appendDropboxMessageOnceAtPath(path.join(dirs[0], "dropbox"), { at: delivery.at, message_id: messageId, kind: "blocked_escalation", text });
|
|
@@ -2415,7 +2425,7 @@ async function admitQueued(hqRoot, lanes, summary, deps, now, onlyLaneIds, exclu
|
|
|
2415
2425
|
reason: "worker_profile_changed",
|
|
2416
2426
|
expected_hash: expectedHash,
|
|
2417
2427
|
actual_hash: actualHash,
|
|
2418
|
-
recovery_command: `hq
|
|
2428
|
+
recovery_command: `hq runners resume ${lane.lane_id} --worker ${workerProfile}`,
|
|
2419
2429
|
},
|
|
2420
2430
|
admission_reserved_at: undefined,
|
|
2421
2431
|
}), false);
|
|
@@ -2522,13 +2532,13 @@ function keepAliveAccountSelectionEvidence(selection) {
|
|
|
2522
2532
|
function keepAliveSkipGuidance(laneId, reason) {
|
|
2523
2533
|
switch (reason) {
|
|
2524
2534
|
case "missing_opt_in_time":
|
|
2525
|
-
return `if appropriate, run hq
|
|
2535
|
+
return `if appropriate, run hq runners keep-alive ${laneId} --on`;
|
|
2526
2536
|
case "not_opted_in":
|
|
2527
2537
|
return "explicit opt-in is required before keep-alive can resume this lane";
|
|
2528
2538
|
case "envelope_before_opt_in":
|
|
2529
|
-
return `the latest envelope predates opt-in; review the lane with hq
|
|
2539
|
+
return `the latest envelope predates opt-in; review the lane with hq runners show ${laneId}`;
|
|
2530
2540
|
case "interruption_before_opt_in":
|
|
2531
|
-
return `the interruption predates opt-in; review the lane with hq
|
|
2541
|
+
return `the interruption predates opt-in; review the lane with hq runners show ${laneId}`;
|
|
2532
2542
|
case "missing_interruption_time":
|
|
2533
2543
|
return "the interruption time is unavailable; inspect the watcher classification before resuming";
|
|
2534
2544
|
case "retired":
|
|
@@ -2538,7 +2548,7 @@ function keepAliveSkipGuidance(laneId, reason) {
|
|
|
2538
2548
|
case "retired_list_invalid":
|
|
2539
2549
|
return "the retired lane list is invalid; repair workspace/lane-briefs/juniors.json before retrying";
|
|
2540
2550
|
case "terminal_state":
|
|
2541
|
-
return `the lane is in a terminal state; review it with hq
|
|
2551
|
+
return `the lane is in a terminal state; review it with hq runners show ${laneId} before starting replacement work`;
|
|
2542
2552
|
}
|
|
2543
2553
|
}
|
|
2544
2554
|
function recordKeepAliveSkip(hqRoot, lane, reason, summary, deps, detail) {
|
|
@@ -26,7 +26,7 @@ End with an envelope containing this exact outcome object shape (choose one stat
|
|
|
26
26
|
{"outcome":{"state":"done","outcome":"What was delivered and verified","gathered":[{"label":"Evidence","text":"What was found","ref":"optional reference"}],"next_steps":[]}}
|
|
27
27
|
\`\`\`
|
|
28
28
|
The three states are done, needs_decision and partial. outcome must be non-empty. gathered is an array of {label, text, ref?}; next_steps is an array of strings; decision_id is an optional string on outcome.
|
|
29
|
-
For needs_decision use hq
|
|
29
|
+
For needs_decision use hq runners ask, put the returned question id in outcome.decision_id, and end with decision: ask. For partial include at least one remaining next_steps entry. A done outcome cannot accompany decision: blocked. These states do not replace the envelope decision field.\n`;
|
|
30
30
|
// Overrides can omit fields that are still persisted in the lane record.
|
|
31
31
|
const safetyText = `${JSON.stringify(signal)}\n${brief}`;
|
|
32
32
|
assertNoSecretText("signal brief", safetyText);
|
|
@@ -16,7 +16,7 @@ function compareNewest(left, right) {
|
|
|
16
16
|
}
|
|
17
17
|
function workerBusyError(lookup, lane, lead, extra = {}) {
|
|
18
18
|
const remote = lookup.runsHere !== undefined && lookup.runsHere(lane) === false;
|
|
19
|
-
const fix = `hq
|
|
19
|
+
const fix = `hq runners stop ${lane.lane_id}`;
|
|
20
20
|
const message = remote
|
|
21
21
|
? `${lead} on ${lane.host.kind}:${lane.host.id} (state ${lane.state}). That lane is on another machine. Free the worker on that machine with \`${fix}\`.`
|
|
22
22
|
: `${lead} (state ${lane.state}). Free the worker with \`${fix}\`.`;
|
|
@@ -24,7 +24,7 @@ import { ensureOwnerDir } from "../../work-context/atomic.js";
|
|
|
24
24
|
import { flushSessionEvents } from "./flush.js";
|
|
25
25
|
import { updateLivenessCarry } from "./liveness-carry.js";
|
|
26
26
|
import { workMeshClaimPath, workMeshSpoolPath } from "./paths.js";
|
|
27
|
-
import { appendDroppedReceipt, appendJsonlLine, forEachJsonlLine, hasPendingFlushWork, hasPendingSpoolWork, removeClaimFile, trimDeadLetter, } from "./spool.js";
|
|
27
|
+
import { appendDroppedReceipt, appendJsonlLine, forEachJsonlLine, hasPendingFlushWork, hasPendingSpoolWork, removeClaimFile, trimDeadLetter, trimHeld, } from "./spool.js";
|
|
28
28
|
export const DIRECT_DRAIN_MARKER_BASENAME = "direct-drain.json";
|
|
29
29
|
export const PRE_DRAIN_BACKLOG_DIRNAME = "pre-drain-backlog";
|
|
30
30
|
/** Lines kept in spool.jsonl while nothing can be delivered. */
|
|
@@ -246,6 +246,15 @@ export async function runDirectDrainCycle(deps) {
|
|
|
246
246
|
now,
|
|
247
247
|
log: deps.log,
|
|
248
248
|
});
|
|
249
|
+
const capHeld = () => {
|
|
250
|
+
const cap = deps.heldMaxLines ?? DIRECT_SPOOL_MAX_LINES;
|
|
251
|
+
const dropped = trimHeld(root, cap, now);
|
|
252
|
+
if (dropped > 0) {
|
|
253
|
+
appendDroppedReceipt({ v: 1, dropped, reason: "held_cap", cap, at: now().toISOString() }, root);
|
|
254
|
+
deps.log?.(`held cap: discarded ${dropped} oldest undelivered line(s) (cap=${cap})`);
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
capHeld();
|
|
249
258
|
const pending = deps.heldRetryDue === false
|
|
250
259
|
? hasPendingSpoolWork(root)
|
|
251
260
|
: hasPendingFlushWork(root);
|
|
@@ -254,6 +263,8 @@ export async function runDirectDrainCycle(deps) {
|
|
|
254
263
|
}
|
|
255
264
|
const flushDeps = directFlushDeps(await deps.flushDeps(), now);
|
|
256
265
|
const summary = await (deps.flush ?? flushSessionEvents)(flushDeps);
|
|
266
|
+
if (summary.held > 0)
|
|
267
|
+
capHeld();
|
|
257
268
|
let deadLetterDiscarded = 0;
|
|
258
269
|
if (summary.deadLettered > 0) {
|
|
259
270
|
deadLetterDiscarded = trimDeadLetter(root, {
|
|
@@ -38,7 +38,7 @@ export interface EmitEventsSummary {
|
|
|
38
38
|
retryDepth: number;
|
|
39
39
|
batches: number;
|
|
40
40
|
statuses: Record<EmitEventStatus, number>;
|
|
41
|
-
/**
|
|
41
|
+
/** Code for each terminally rejected event. */
|
|
42
42
|
rejections: Array<{
|
|
43
43
|
eventId: string;
|
|
44
44
|
code: string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { hasWorkMeshEventCompanyBinding, mayEmitConversation, workMeshSwitchDisabled } from "./reporting-privacy.js";
|
|
2
|
+
import { hqAnywhereRuntimeLocallyDisabled } from "../../anywhere-runtime-flag-key.js";
|
|
2
3
|
/**
|
|
3
4
|
* Direct-emit orchestration (owner decision 2026-09-08). One invocation:
|
|
4
5
|
* 1. drains the local retry file (prior failures),
|
|
@@ -92,19 +93,23 @@ export async function emitEvents(deps) {
|
|
|
92
93
|
rejections: [],
|
|
93
94
|
};
|
|
94
95
|
const env = deps.env ?? process.env;
|
|
95
|
-
if (
|
|
96
|
+
if (hqAnywhereRuntimeLocallyDisabled(env) || (deps.reportingAllowed && !(await deps.reportingAllowed()))) {
|
|
96
97
|
const written = writeEmitRetry(deps.workMeshRoot, combined, retryMax);
|
|
97
98
|
return { ...summary, attempted: 0, retained: written.written,
|
|
98
99
|
retryDepth: written.written, droppedOverflow: written.dropped };
|
|
99
100
|
}
|
|
101
|
+
const meshDisabled = workMeshSwitchDisabled(env);
|
|
100
102
|
const allowed = combined.filter(event => {
|
|
101
|
-
|
|
103
|
+
const code = meshDisabled && !hasWorkMeshEventCompanyBinding(event, env)
|
|
104
|
+
? "WORK_MESH_DISABLED"
|
|
105
|
+
: !mayEmitConversation(event, env) ? "PERSONAL_OR_UNATTRIBUTED" : undefined;
|
|
106
|
+
if (code === undefined)
|
|
102
107
|
return true;
|
|
103
108
|
summary.rejected += 1;
|
|
104
109
|
summary.statuses.rejected += 1;
|
|
105
110
|
const eventId = eventIdOf(event);
|
|
106
111
|
if (eventId)
|
|
107
|
-
summary.rejections.push({ eventId, code
|
|
112
|
+
summary.rejections.push({ eventId, code });
|
|
108
113
|
return false;
|
|
109
114
|
});
|
|
110
115
|
summary.attempted = allowed.length;
|
|
@@ -188,7 +193,7 @@ export async function emitEvents(deps) {
|
|
|
188
193
|
summary.lastPostAt = nowIso;
|
|
189
194
|
delete nextState.lastError;
|
|
190
195
|
}
|
|
191
|
-
else if (
|
|
196
|
+
else if (allowed.length > 0) {
|
|
192
197
|
nextState.lastError = "emit failed (network/server); retained for retry";
|
|
193
198
|
}
|
|
194
199
|
writeEmitState(deps.workMeshRoot, nextState);
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
* 2xx responses are accounted per eventId (accepted / duplicates / rejected).
|
|
10
10
|
*/
|
|
11
11
|
import * as fs from "node:fs";
|
|
12
|
-
import {
|
|
12
|
+
import { eventMatchesWorkMeshCompany, hasWorkMeshCompanyBinding, workMeshSwitchDisabled } from "./reporting-privacy.js";
|
|
13
|
+
import { hqAnywhereRuntimeLocallyDisabled } from "../../anywhere-runtime-flag-key.js";
|
|
13
14
|
import * as path from "node:path";
|
|
14
15
|
import { readMetaCompanySlug, resolveCompany } from "../../work-context/company.js";
|
|
15
16
|
import { companyBindingChanged, isNonCloudCompanySlug, reboundSessionProjection, } from "../../work-context/company-rebind.js";
|
|
@@ -176,7 +177,7 @@ export async function flushSessionEvents(inputDeps) {
|
|
|
176
177
|
const env = inputDeps.env ?? process.env;
|
|
177
178
|
const nothingDone = () => ({ claimed: 0, posted: 0, held: 0, dropped: 0, deadLettered: 0,
|
|
178
179
|
restored: 0, batches: 0, heldClaimed: false, heldOverflow: 0 });
|
|
179
|
-
if (
|
|
180
|
+
if (hqAnywhereRuntimeLocallyDisabled(env))
|
|
180
181
|
return nothingDone();
|
|
181
182
|
// Idle machine: with nothing spooled, held or orphaned there is nothing to
|
|
182
183
|
// report, so do not ask whether reporting is allowed. The gate still runs
|
|
@@ -287,11 +288,25 @@ export async function flushSessionEvents(inputDeps) {
|
|
|
287
288
|
};
|
|
288
289
|
const loggedProject404 = new Set();
|
|
289
290
|
const heldUidCache = new Map();
|
|
290
|
-
|
|
291
|
+
const meshDisabled = workMeshSwitchDisabled(env);
|
|
292
|
+
sessionLoop: for (const [sessionId, sessionItems] of bySession) {
|
|
291
293
|
if (deps.signal?.aborted)
|
|
292
294
|
break sessionLoop;
|
|
293
295
|
let state = readSessionState(sessionId, deps.workContextRoot);
|
|
294
|
-
state = applySessionMetaCompanyRebind(sessionId,
|
|
296
|
+
state = applySessionMetaCompanyRebind(sessionId, sessionItems, state, deps, now);
|
|
297
|
+
let items = sessionItems;
|
|
298
|
+
if (meshDisabled) {
|
|
299
|
+
const binding = state;
|
|
300
|
+
items = sessionItems.filter(item => {
|
|
301
|
+
if (hasWorkMeshCompanyBinding(binding) && eventMatchesWorkMeshCompany(item.event, binding.companySlug))
|
|
302
|
+
return true;
|
|
303
|
+
summary.dropped += 1;
|
|
304
|
+
markDisposed(item.event);
|
|
305
|
+
return false;
|
|
306
|
+
});
|
|
307
|
+
if (items.length === 0)
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
295
310
|
// Personal is the documented non-cloud scope, even if an old projection
|
|
296
311
|
// still contains a company UID or a pending presence leave.
|
|
297
312
|
if (isNonCloudCompanySlug(state?.companySlug) || items.some(item => isNonCloudCompanySlug(eventText(item.event, "companySlug")))) {
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
+
import { type SessionStateFile } from "../../work-context/state.js";
|
|
1
2
|
/** Match the off controls used by the hook and handoff command. */
|
|
2
|
-
export declare function
|
|
3
|
+
export declare function workMeshSwitchDisabled(env?: NodeJS.ProcessEnv): boolean;
|
|
4
|
+
export declare function hasWorkMeshCompanyBinding(state: SessionStateFile | null): state is SessionStateFile & {
|
|
5
|
+
companyUid: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function eventMatchesWorkMeshCompany(event: Record<string, unknown>, companySlug: string | undefined): boolean;
|
|
8
|
+
export declare function hasWorkMeshEventCompanyBinding(event: Record<string, unknown>, env: NodeJS.ProcessEnv): boolean;
|
|
3
9
|
/** Legacy emit must not let the server infer a company for conversation text. */
|
|
4
10
|
export declare function mayEmitConversation(event: Record<string, unknown>, env?: NodeJS.ProcessEnv): boolean;
|
|
5
11
|
/** Fleet identities have no person preference; operator and local controls still apply. */
|
|
@@ -32,8 +38,8 @@ export interface ReportingGateOptions {
|
|
|
32
38
|
* The reporting gate for a long-running process (the Work Mesh Live daemon).
|
|
33
39
|
* Same answer as reportingRuntimeAllowed, but the person setting is read from
|
|
34
40
|
* the server once and kept: it is re-read when local state signals a change
|
|
35
|
-
* and on a slow safety refresh, never per call.
|
|
36
|
-
*
|
|
41
|
+
* and on a slow safety refresh, never per call. The local Anywhere flag
|
|
42
|
+
* is still checked on every call. Unknown stays closed.
|
|
37
43
|
*/
|
|
38
44
|
export declare function createReportingGate(machine: boolean, env?: NodeJS.ProcessEnv, options?: ReportingGateOptions): () => Promise<boolean>;
|
|
39
45
|
//# sourceMappingURL=reporting-privacy.d.ts.map
|
|
@@ -11,11 +11,31 @@ import { deriveRemoteOwnerSlug, deriveRepoIdentityKey } from "../../work-context
|
|
|
11
11
|
import { workContextRoot } from "../../work-context/paths.js";
|
|
12
12
|
import { readSessionState } from "../../work-context/state.js";
|
|
13
13
|
/** Match the off controls used by the hook and handoff command. */
|
|
14
|
-
export function
|
|
14
|
+
export function workMeshSwitchDisabled(env = process.env) {
|
|
15
15
|
const hooks = (env.HQ_DISABLED_HOOKS ?? "").split(",").map(value => value.trim());
|
|
16
16
|
return ["1", "true", "TRUE", "yes", "YES", "on", "ON"].includes(env.HQ_WORK_MESH_DISABLED ?? "") ||
|
|
17
|
-
hooks.some(value => ["*", "work-mesh", "work-mesh-live"].includes(value))
|
|
18
|
-
|
|
17
|
+
hooks.some(value => ["*", "work-mesh", "work-mesh-live"].includes(value));
|
|
18
|
+
}
|
|
19
|
+
export function hasWorkMeshCompanyBinding(state) {
|
|
20
|
+
return state?.contractVersion === 1 && typeof state.companyUid === "string" && !!state.companyUid.trim() &&
|
|
21
|
+
(state.contextStatus === "bound" || state.contextStatus === "needs_project" || state.contextStatus === "needs_task") &&
|
|
22
|
+
state.companyConfidence !== "device_default" &&
|
|
23
|
+
state.ownerMismatch?.companyUid !== state.companyUid &&
|
|
24
|
+
(state.companySlug === undefined || typeof state.companySlug === "string") &&
|
|
25
|
+
!isNonCloudCompanySlug(state.companySlug);
|
|
26
|
+
}
|
|
27
|
+
export function eventMatchesWorkMeshCompany(event, companySlug) {
|
|
28
|
+
const evidence = event.evidence;
|
|
29
|
+
return [event.companySlug, evidence?.companySlug].every(slug => typeof slug !== "string" || !slug.trim() ||
|
|
30
|
+
(!isNonCloudCompanySlug(slug) && slug === companySlug));
|
|
31
|
+
}
|
|
32
|
+
export function hasWorkMeshEventCompanyBinding(event, env) {
|
|
33
|
+
if (typeof event.sessionId !== "string")
|
|
34
|
+
return false;
|
|
35
|
+
// The scope files SessionStart can mint from a guess do not grant the
|
|
36
|
+
// switch exception. Use the established binding for this exact session.
|
|
37
|
+
const state = readSessionState(event.sessionId, workContextRoot(undefined, env));
|
|
38
|
+
return hasWorkMeshCompanyBinding(state) && eventMatchesWorkMeshCompany(event, state.companySlug);
|
|
19
39
|
}
|
|
20
40
|
/** Legacy emit must not let the server infer a company for conversation text. */
|
|
21
41
|
export function mayEmitConversation(event, env = process.env) {
|
|
@@ -44,7 +64,7 @@ export function mayEmitConversation(event, env = process.env) {
|
|
|
44
64
|
}
|
|
45
65
|
/** Fleet identities have no person preference; operator and local controls still apply. */
|
|
46
66
|
export async function reportingRuntimeAllowed(machine, env = process.env) {
|
|
47
|
-
if (
|
|
67
|
+
if (hqAnywhereRuntimeLocallyDisabled(env))
|
|
48
68
|
return false;
|
|
49
69
|
return machine ? anywhereRuntimeEnabledFromSnapshot(env) : anywhereRuntimeAllowed(env);
|
|
50
70
|
}
|
|
@@ -81,8 +101,8 @@ export function reportingSettingChangeSignal(env = process.env, home) {
|
|
|
81
101
|
* The reporting gate for a long-running process (the Work Mesh Live daemon).
|
|
82
102
|
* Same answer as reportingRuntimeAllowed, but the person setting is read from
|
|
83
103
|
* the server once and kept: it is re-read when local state signals a change
|
|
84
|
-
* and on a slow safety refresh, never per call.
|
|
85
|
-
*
|
|
104
|
+
* and on a slow safety refresh, never per call. The local Anywhere flag
|
|
105
|
+
* is still checked on every call. Unknown stays closed.
|
|
86
106
|
*/
|
|
87
107
|
export function createReportingGate(machine, env = process.env, options = {}) {
|
|
88
108
|
const readSetting = cachedPersonSettingReader(options.readSetting ?? (() => readHqAnywherePersonSetting({ env, home: options.home })), {
|
|
@@ -92,7 +112,7 @@ export function createReportingGate(machine, env = process.env, options = {}) {
|
|
|
92
112
|
changeSignal: options.changeSignal ?? (() => reportingSettingChangeSignal(env, options.home)),
|
|
93
113
|
});
|
|
94
114
|
return async () => {
|
|
95
|
-
if (
|
|
115
|
+
if (hqAnywhereRuntimeLocallyDisabled(env))
|
|
96
116
|
return false;
|
|
97
117
|
if (machine)
|
|
98
118
|
return anywhereRuntimeEnabledFromSnapshot(env);
|
|
@@ -22,6 +22,8 @@ export declare function appendHeldLine(line: string, root?: string): string;
|
|
|
22
22
|
/** Append a deduplicated held batch under one file lock and one write. */
|
|
23
23
|
export declare function appendHeldLinesIfAbsent(lines: string[], root?: string): number;
|
|
24
24
|
export declare function appendDeadLetterLine(line: string, root?: string): string;
|
|
25
|
+
/** Trim oldest held events under the same lock used by enqueue and claim. */
|
|
26
|
+
export declare function trimHeld(root: string, maxLines: number, now: () => Date): number;
|
|
25
27
|
/**
|
|
26
28
|
* Keep dead-letter.jsonl bounded for the direct-mode drain. Only lines
|
|
27
29
|
* dead-lettered at or after `protectBefore` count against `maxLines`; older
|
|
@@ -7,6 +7,7 @@ import * as fs from "node:fs";
|
|
|
7
7
|
import * as path from "node:path";
|
|
8
8
|
import { randomBytes } from "node:crypto";
|
|
9
9
|
import { ensureOwnerDir } from "../../work-context/atomic.js";
|
|
10
|
+
import { updateLivenessCarry } from "./liveness-carry.js";
|
|
10
11
|
import { workMeshClaimPath, workMeshDeadLetterPath, workMeshDroppedReceiptPath, workMeshHeldPath, workMeshRoot, workMeshSpoolPath, } from "./paths.js";
|
|
11
12
|
/** Linux PIPE_BUF is typically 4096; keep a conservative ceiling for one line. */
|
|
12
13
|
export const SPOOL_LINE_MAX_BYTES = 4096;
|
|
@@ -222,6 +223,46 @@ export function appendDeadLetterLine(line, root) {
|
|
|
222
223
|
});
|
|
223
224
|
return dl;
|
|
224
225
|
}
|
|
226
|
+
/** Trim oldest held events under the same lock used by enqueue and claim. */
|
|
227
|
+
export function trimHeld(root, maxLines, now) {
|
|
228
|
+
const held = workMeshHeldPath(root);
|
|
229
|
+
// A held envelope is longer than this per line. Avoid scanning small queues.
|
|
230
|
+
if (maxLines <= 0 || (fs.statSync(held, { throwIfNoEntry: false })?.size ?? 0) < maxLines * 64)
|
|
231
|
+
return 0;
|
|
232
|
+
return withJsonlLock(held, () => {
|
|
233
|
+
const total = countJsonlLines(held);
|
|
234
|
+
if (total <= maxLines)
|
|
235
|
+
return 0;
|
|
236
|
+
const remove = total - Math.max(1, Math.floor(maxLines * 0.75));
|
|
237
|
+
const tmp = `${held}.${process.pid}.${randomBytes(6).toString("hex")}.tmp`;
|
|
238
|
+
const fd = fs.openSync(tmp, "wx", 0o600);
|
|
239
|
+
let seen = 0;
|
|
240
|
+
try {
|
|
241
|
+
try {
|
|
242
|
+
updateLivenessCarry(root, (ingest) => {
|
|
243
|
+
if (!forEachJsonlLine(held, (line) => {
|
|
244
|
+
if (!line.trim())
|
|
245
|
+
return;
|
|
246
|
+
if (seen++ < remove)
|
|
247
|
+
ingest(line);
|
|
248
|
+
else
|
|
249
|
+
fs.writeFileSync(fd, `${line}\n`);
|
|
250
|
+
}))
|
|
251
|
+
throw new SpoolWriteError("Could not read the held queue while trimming it");
|
|
252
|
+
}, now);
|
|
253
|
+
fs.fsyncSync(fd);
|
|
254
|
+
}
|
|
255
|
+
finally {
|
|
256
|
+
fs.closeSync(fd);
|
|
257
|
+
}
|
|
258
|
+
fs.renameSync(tmp, held);
|
|
259
|
+
}
|
|
260
|
+
finally {
|
|
261
|
+
fs.rmSync(tmp, { force: true });
|
|
262
|
+
}
|
|
263
|
+
return remove;
|
|
264
|
+
});
|
|
265
|
+
}
|
|
225
266
|
/**
|
|
226
267
|
* Keep dead-letter.jsonl bounded for the direct-mode drain. Only lines
|
|
227
268
|
* dead-lettered at or after `protectBefore` count against `maxLines`; older
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
* hq-cloud change. The signals and ontology _candidates folders are in the
|
|
27
27
|
* shipped .hqignore.
|
|
28
28
|
*/
|
|
29
|
+
import { splitFrontmatterBody } from "../../utils/frontmatter.js";
|
|
29
30
|
import { createHash } from "node:crypto";
|
|
30
31
|
import * as fs from "node:fs";
|
|
31
32
|
import * as path from "node:path";
|
|
@@ -280,17 +281,17 @@ function citationRanges(raw, sourceRef) {
|
|
|
280
281
|
}
|
|
281
282
|
// ── local files ──────────────────────────────────────────────────────────────
|
|
282
283
|
export function splitFrontmatter(text) {
|
|
283
|
-
const
|
|
284
|
-
if (!
|
|
284
|
+
const block = splitFrontmatterBody(text);
|
|
285
|
+
if (!block)
|
|
285
286
|
return { frontmatter: {}, body: text };
|
|
286
287
|
let parsed;
|
|
287
288
|
try {
|
|
288
|
-
parsed = yaml.load(
|
|
289
|
+
parsed = yaml.load(block.yaml);
|
|
289
290
|
}
|
|
290
291
|
catch {
|
|
291
292
|
parsed = null;
|
|
292
293
|
}
|
|
293
|
-
return { frontmatter: isRecord(parsed) ? parsed : {}, body:
|
|
294
|
+
return { frontmatter: isRecord(parsed) ? parsed : {}, body: block.body };
|
|
294
295
|
}
|
|
295
296
|
/** Highest-version audience receipt for a meeting, read from the local company tree. */
|
|
296
297
|
export function readAudienceReceipt(companyRoot, meetingId) {
|