@indigoai-us/hq-cli 5.345.237 → 5.345.241
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 +33 -0
- package/assets/scaffold/core/scripts/hq-delegate-repo.sh +7 -1
- package/assets/scaffold/core/scripts/hq-delegate-secrets.sh +95 -20
- package/assets/scaffold/core/scripts/hq-delegate-transfer.sh +57 -9
- package/dist/command-catalog.generated.d.ts +185 -3
- package/dist/command-catalog.generated.js +228 -3
- package/dist/command-registration-plan.d.ts +6 -0
- package/dist/command-registration-plan.js +1 -0
- package/dist/commands/bot.d.ts +2 -0
- package/dist/commands/bot.js +23 -0
- package/dist/commands/cloud-off-gate.d.ts +2 -1
- package/dist/commands/cloud-off-gate.js +17 -4
- package/dist/commands/cloud.d.ts +17 -2
- package/dist/commands/cloud.js +126 -24
- package/dist/commands/core-delegate-w1b.js +35 -10
- package/dist/commands/core-delegate.d.ts +2 -1
- package/dist/commands/core-delegate.js +207 -48
- package/dist/commands/deploy-comments.js +8 -2
- package/dist/commands/deploy-events.d.ts +40 -0
- package/dist/commands/deploy-events.js +300 -0
- package/dist/commands/doctor.d.ts +4 -4
- package/dist/commands/doctor.js +2 -2
- package/dist/commands/feedback.js +2 -3
- package/dist/commands/keyed-sync-pull.d.ts +12 -0
- package/dist/commands/keyed-sync-pull.js +151 -0
- package/dist/commands/library-add.d.ts +5 -2
- package/dist/commands/library-add.js +22 -9
- package/dist/commands/mcp-registration.d.ts +4 -18
- package/dist/commands/mcp-registration.js +9 -29
- package/dist/commands/mesh.d.ts +4 -0
- package/dist/commands/mesh.js +25 -5
- package/dist/commands/pack-install.d.ts +2 -3
- package/dist/commands/pack-install.js +6 -8
- package/dist/commands/secrets.d.ts +3 -4
- package/dist/commands/secrets.js +3 -20
- package/dist/hq-cloud-sync-runner/bin/sync-runner.js +307 -232
- package/dist/hq-cloud-sync-runner/package.json +1 -1
- package/dist/lib/agent-kit/inbox-state.d.ts +2 -1
- package/dist/lib/agent-kit/inbox-state.js +27 -3
- package/dist/lib/bot/api.d.ts +2 -1
- package/dist/lib/bot/api.js +2 -15
- package/dist/lib/bot/promote.d.ts +23 -0
- package/dist/lib/bot/promote.js +73 -0
- package/dist/lib/bot/promotion-hold-reconcile.d.ts +56 -0
- package/dist/lib/bot/promotion-hold-reconcile.js +155 -0
- package/dist/lib/capacity/collectors/claude-oauth.d.ts +0 -2
- package/dist/lib/capacity/collectors/claude-oauth.js +0 -5
- package/dist/lib/core-utils/delegate-helper-paths.d.ts +26 -0
- package/dist/lib/core-utils/delegate-helper-paths.js +33 -0
- package/dist/lib/daemon/jq-provision.d.ts +63 -0
- package/dist/lib/daemon/jq-provision.js +155 -0
- package/dist/lib/daemon/lanes-reconcile-guard.d.ts +4 -3
- package/dist/lib/daemon/lanes-reconcile-guard.js +4 -4
- package/dist/lib/daemon/mesh-owner.d.ts +4 -0
- package/dist/lib/daemon/mesh-owner.js +20 -0
- package/dist/lib/daemon/ops/policy.d.ts +3 -0
- package/dist/lib/daemon/ops/policy.js +32 -4
- package/dist/lib/daemon/run.d.ts +17 -1
- package/dist/lib/daemon/run.js +24 -3
- package/dist/lib/daemon/server.d.ts +6 -0
- package/dist/lib/daemon/server.js +5 -0
- package/dist/lib/daemon/verified-jq.d.ts +96 -0
- package/dist/lib/daemon/verified-jq.js +337 -0
- package/dist/lib/doctor/checks/jq.js +16 -0
- package/dist/lib/doctor/deep/executor.d.ts +7 -0
- package/dist/lib/doctor/deep/executor.js +1 -1
- package/dist/lib/doctor/deep/parity.js +1 -27
- package/dist/lib/doctor/deep/sandbox.d.ts +2 -2
- package/dist/lib/doctor/deep/sandbox.js +3 -19
- package/dist/lib/doctor/fix/refresh-sync-handoff.js +52 -21
- package/dist/lib/doctor/fixtures/discover.d.ts +2 -0
- package/dist/lib/doctor/fixtures/discover.js +1 -1
- package/dist/lib/doctor/json-output.d.ts +1 -1
- package/dist/lib/doctor/registry.d.ts +6 -7
- package/dist/lib/doctor/registry.js +6 -7
- package/dist/lib/doctor/report.d.ts +9 -10
- package/dist/lib/doctor/report.js +4 -4
- 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/jq/install.d.ts +27 -0
- package/dist/lib/jq/install.js +156 -0
- package/dist/lib/lanes/outpost-dispatch.d.ts +1 -1
- package/dist/lib/lanes/outpost-dispatch.js +13 -13
- package/dist/lib/lanes/outpost-pruner-install.js +1 -1
- package/dist/lib/mesh/live/daemon/doctor.js +7 -1
- package/dist/lib/mesh/live/daemon/install.d.ts +4 -0
- package/dist/lib/mesh/live/daemon/install.js +10 -0
- package/dist/lib/mesh/live/daemon/run.js +17 -0
- package/dist/lib/mesh/live/emit-retry.d.ts +20 -2
- package/dist/lib/mesh/live/emit-retry.js +57 -4
- package/dist/lib/mesh/live/emit.js +25 -4
- package/dist/lib/mesh/live/flush.d.ts +2 -0
- package/dist/lib/mesh/live/flush.js +21 -8
- package/dist/lib/mesh/live/spool.d.ts +9 -1
- package/dist/lib/mesh/live/spool.js +41 -29
- package/dist/lib/sync-core/rollout-state.d.ts +9 -1
- package/dist/lib/sync-core/rollout-state.js +34 -4
- package/dist/lib/windows/jq.d.ts +4 -0
- package/dist/lib/windows/jq.js +10 -39
- package/dist/lib/workers-registry/index.js +7 -11
- package/dist/utils/callback-port-busy.d.ts +2 -2
- package/dist/utils/callback-port-busy.js +2 -2
- package/dist/utils/cli-network-lifecycle.js +1 -0
- package/dist/utils/client-health-contract.d.ts +2 -0
- package/dist/utils/client-health-contract.js +1 -1
- package/dist/utils/client-health.js +1 -9
- package/dist/utils/cognito-config.js +5 -0
- package/dist/utils/cognito-session.d.ts +4 -6
- package/dist/utils/cognito-session.js +4 -24
- package/dist/utils/incomplete-install-error.js +1 -11
- package/dist/utils/install-tree-torn.d.ts +11 -0
- package/dist/utils/install-tree-torn.js +1 -1
- package/dist/utils/resident-package-preload.js +2 -1
- package/docs/anywhere-runtime.md +8 -0
- package/package.json +9 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"hq-cli-daemon-sync-runner","type":"module","version":"6.18.
|
|
1
|
+
{"name":"hq-cli-daemon-sync-runner","type":"module","version":"6.18.117","bundleSha256":"425e7b51afda9223d469b19d2a657cd4ea6af5c2c0bbd1354b837dc682faecfc","formatVersion":1}
|
|
@@ -43,7 +43,8 @@ export declare function readDoneIds(paths: Pick<AgentKitPaths, "inboxDir">): Set
|
|
|
43
43
|
export declare function markInboxDone(paths: Pick<AgentKitPaths, "inboxDir">, ids: string[]): string[];
|
|
44
44
|
/**
|
|
45
45
|
* Ids marked handled by the bot whose server ack is not confirmed yet, oldest
|
|
46
|
-
* first.
|
|
46
|
+
* first. Listing reads treat a missing or unreadable file as an empty list;
|
|
47
|
+
* addAckPending and confirmInboxAck use the strict reader below.
|
|
47
48
|
*/
|
|
48
49
|
export declare function readAckPending(paths: Pick<AgentKitPaths, "inboxDir">): string[];
|
|
49
50
|
/** Record ids as awaiting a server ack. Call before the ack is sent. */
|
|
@@ -92,7 +92,8 @@ function markInboxDoneUnlocked(paths, ids) {
|
|
|
92
92
|
}
|
|
93
93
|
/**
|
|
94
94
|
* Ids marked handled by the bot whose server ack is not confirmed yet, oldest
|
|
95
|
-
* first.
|
|
95
|
+
* first. Listing reads treat a missing or unreadable file as an empty list;
|
|
96
|
+
* addAckPending and confirmInboxAck use the strict reader below.
|
|
96
97
|
*/
|
|
97
98
|
export function readAckPending(paths) {
|
|
98
99
|
try {
|
|
@@ -103,13 +104,36 @@ export function readAckPending(paths) {
|
|
|
103
104
|
return [];
|
|
104
105
|
}
|
|
105
106
|
}
|
|
107
|
+
/** A failed read must not turn an existing pending list into an empty write. */
|
|
108
|
+
function readAckPendingStrict(paths) {
|
|
109
|
+
let text;
|
|
110
|
+
try {
|
|
111
|
+
text = fs.readFileSync(path.join(paths.inboxDir, ACK_PENDING_NAME), "utf8");
|
|
112
|
+
}
|
|
113
|
+
catch (err) {
|
|
114
|
+
if (err.code === "ENOENT")
|
|
115
|
+
return [];
|
|
116
|
+
throw new Error("Pending inbox acknowledgements could not be read; existing state was not changed.", { cause: err });
|
|
117
|
+
}
|
|
118
|
+
let raw;
|
|
119
|
+
try {
|
|
120
|
+
raw = JSON.parse(text);
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
throw new Error("Pending inbox acknowledgements are not valid JSON; existing state was not changed.");
|
|
124
|
+
}
|
|
125
|
+
if (!Array.isArray(raw) || raw.some((id) => typeof id !== "string")) {
|
|
126
|
+
throw new Error("Pending inbox acknowledgements must be an array of IDs; existing state was not changed.");
|
|
127
|
+
}
|
|
128
|
+
return [...new Set(raw)];
|
|
129
|
+
}
|
|
106
130
|
function writeAckPending(paths, ids) {
|
|
107
131
|
writePrivateFile(path.join(paths.inboxDir, ACK_PENDING_NAME), JSON.stringify(ids.slice(-MAX_ACK_PENDING_IDS)), 0o600);
|
|
108
132
|
}
|
|
109
133
|
/** Record ids as awaiting a server ack. Call before the ack is sent. */
|
|
110
134
|
export function addAckPending(paths, ids) {
|
|
111
135
|
withStateLock(paths, () => {
|
|
112
|
-
const current =
|
|
136
|
+
const current = readAckPendingStrict(paths);
|
|
113
137
|
const have = new Set(current);
|
|
114
138
|
const next = [...current];
|
|
115
139
|
for (const id of ids) {
|
|
@@ -129,8 +153,8 @@ export function addAckPending(paths, ids) {
|
|
|
129
153
|
*/
|
|
130
154
|
export function confirmInboxAck(paths, id) {
|
|
131
155
|
return withStateLock(paths, () => {
|
|
156
|
+
const current = readAckPendingStrict(paths);
|
|
132
157
|
const added = markInboxDoneUnlocked(paths, [id]).length > 0;
|
|
133
|
-
const current = readAckPending(paths);
|
|
134
158
|
if (current.includes(id))
|
|
135
159
|
writeAckPending(paths, current.filter((x) => x !== id));
|
|
136
160
|
return added;
|
package/dist/lib/bot/api.d.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { vaultApiFetch } from "../../utils/vault-api.js";
|
|
9
9
|
import { type BotLocalConfig } from "./local-config.js";
|
|
10
|
+
import { parseRetryAfterMs as retryAfterHeaderMs } from "../mesh/live/daemon/credentials.js";
|
|
10
11
|
export type TokenSupplier = () => Promise<string>;
|
|
11
12
|
/**
|
|
12
13
|
* One agent-inbox item. DMs carry the base fields; room (channel / group chat)
|
|
@@ -170,7 +171,7 @@ export declare class InvalidDmRecipientError extends Error {
|
|
|
170
171
|
constructor(recipient: string);
|
|
171
172
|
}
|
|
172
173
|
/** Parse a Retry-After header (delta-seconds or HTTP-date) to milliseconds. */
|
|
173
|
-
export
|
|
174
|
+
export { retryAfterHeaderMs };
|
|
174
175
|
export interface BotApiOptions {
|
|
175
176
|
token: TokenSupplier;
|
|
176
177
|
baseUrl?: string;
|
package/dist/lib/bot/api.js
CHANGED
|
@@ -9,6 +9,7 @@ import { vaultApiFetch } from "../../utils/vault-api.js";
|
|
|
9
9
|
import { tokenAgentUid } from "../heartbeat-identity.js";
|
|
10
10
|
import { assertNoSecretKeys } from "./local-config.js";
|
|
11
11
|
import { isRecipientUid } from "../notify-recipient.js";
|
|
12
|
+
import { parseRetryAfterMs as retryAfterHeaderMs } from "../mesh/live/daemon/credentials.js";
|
|
12
13
|
export class BotApiError extends Error {
|
|
13
14
|
status;
|
|
14
15
|
path;
|
|
@@ -36,21 +37,7 @@ export class InvalidDmRecipientError extends Error {
|
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
/** Parse a Retry-After header (delta-seconds or HTTP-date) to milliseconds. */
|
|
39
|
-
export
|
|
40
|
-
if (!value)
|
|
41
|
-
return undefined;
|
|
42
|
-
const trimmed = value.trim();
|
|
43
|
-
if (!trimmed)
|
|
44
|
-
return undefined;
|
|
45
|
-
const seconds = Number(trimmed);
|
|
46
|
-
if (Number.isFinite(seconds) && seconds >= 0) {
|
|
47
|
-
return Math.round(seconds * 1000);
|
|
48
|
-
}
|
|
49
|
-
const dateMs = Date.parse(trimmed);
|
|
50
|
-
if (!Number.isNaN(dateMs))
|
|
51
|
-
return Math.max(0, dateMs - nowMs);
|
|
52
|
-
return undefined;
|
|
53
|
-
}
|
|
40
|
+
export { retryAfterHeaderMs };
|
|
54
41
|
async function readError(res) {
|
|
55
42
|
try {
|
|
56
43
|
const body = (await res.json());
|
|
@@ -71,6 +71,29 @@ export declare function promoteLocalBot(input: {
|
|
|
71
71
|
pending: boolean;
|
|
72
72
|
fleetState?: FleetStateManifest | null;
|
|
73
73
|
}>;
|
|
74
|
+
export type PromotionHoldReconcile = {
|
|
75
|
+
outcome: "none";
|
|
76
|
+
} | {
|
|
77
|
+
outcome: "kept";
|
|
78
|
+
reason: string;
|
|
79
|
+
} | {
|
|
80
|
+
outcome: "released";
|
|
81
|
+
reason: "cancelled" | "not-found";
|
|
82
|
+
companyUid: string;
|
|
83
|
+
wasRunning: boolean | null;
|
|
84
|
+
};
|
|
85
|
+
/** A held bot whose move HQ has since dropped frees itself, by the proof rules
|
|
86
|
+
* of cancelLocalBotPromotion: HQ shows this hold's own operation cancelled, or
|
|
87
|
+
* HQ has no move for the bot and its owner is the one signed in. A bot with an
|
|
88
|
+
* active-promotion receipt, a damaged hold, an in-flight or different move, or
|
|
89
|
+
* any failed read stays held. Never cancels anything on the server.
|
|
90
|
+
*/
|
|
91
|
+
export declare function reconcilePromotionHold(input: {
|
|
92
|
+
dir: string;
|
|
93
|
+
config: BotConfig;
|
|
94
|
+
api: BotApi;
|
|
95
|
+
signedInPerson?: SignedInPerson;
|
|
96
|
+
}): Promise<PromotionHoldReconcile>;
|
|
74
97
|
export type PromotionCancelOutcome = "canceled" | "pending" | "active" | "not-found";
|
|
75
98
|
export interface PromotionCancelResult {
|
|
76
99
|
outcome: PromotionCancelOutcome;
|
package/dist/lib/bot/promote.js
CHANGED
|
@@ -463,6 +463,79 @@ async function serverMayKnow(api, config, companyUid, operationId) {
|
|
|
463
463
|
return true;
|
|
464
464
|
}
|
|
465
465
|
}
|
|
466
|
+
function hasReceiptFile(dir) {
|
|
467
|
+
try {
|
|
468
|
+
fs.lstatSync(path.join(dir, "promotion-active.json"));
|
|
469
|
+
return true;
|
|
470
|
+
}
|
|
471
|
+
catch {
|
|
472
|
+
return false;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
/** A held bot whose move HQ has since dropped frees itself, by the proof rules
|
|
476
|
+
* of cancelLocalBotPromotion: HQ shows this hold's own operation cancelled, or
|
|
477
|
+
* HQ has no move for the bot and its owner is the one signed in. A bot with an
|
|
478
|
+
* active-promotion receipt, a damaged hold, an in-flight or different move, or
|
|
479
|
+
* any failed read stays held. Never cancels anything on the server.
|
|
480
|
+
*/
|
|
481
|
+
export async function reconcilePromotionHold(input) {
|
|
482
|
+
const { dir, config, api } = input;
|
|
483
|
+
if (!hasPromotionHold(dir))
|
|
484
|
+
return { outcome: "none" };
|
|
485
|
+
if (hasReceiptFile(dir))
|
|
486
|
+
return { outcome: "kept", reason: "the bot moved to the cloud" };
|
|
487
|
+
const read = readLocalHold(dir, config);
|
|
488
|
+
if (!read.hold)
|
|
489
|
+
return { outcome: "kept", reason: `the hold cannot be used: ${read.unreadable ?? "it is missing"}` };
|
|
490
|
+
const companyUid = read.hold.companyUid;
|
|
491
|
+
const operationId = read.hold.operationId;
|
|
492
|
+
let state;
|
|
493
|
+
try {
|
|
494
|
+
state = await readPromotionStatusRaw(api, config, companyUid);
|
|
495
|
+
}
|
|
496
|
+
catch (error) {
|
|
497
|
+
if (error instanceof BotApiError)
|
|
498
|
+
logRaw(dir, error);
|
|
499
|
+
else
|
|
500
|
+
appendBotLog(dir, botLogLine("warn", `promotion: status check failed: ${sentence(error)}`));
|
|
501
|
+
if (!(error instanceof BotApiError && error.status === 404 && error.code === "PROMOTION_NOT_FOUND"))
|
|
502
|
+
return { outcome: "kept", reason: "HQ did not show the move" };
|
|
503
|
+
state = null;
|
|
504
|
+
}
|
|
505
|
+
let why;
|
|
506
|
+
if (state === null) {
|
|
507
|
+
if (!await signedInAsOwner(input))
|
|
508
|
+
return { outcome: "kept", reason: "only the bot's owner can confirm HQ has no move" };
|
|
509
|
+
why = "not-found";
|
|
510
|
+
}
|
|
511
|
+
else if (state.operationId !== operationId) {
|
|
512
|
+
return { outcome: "kept", reason: "HQ shows a different move" };
|
|
513
|
+
}
|
|
514
|
+
else if (state.phase === "active") {
|
|
515
|
+
// The bot is live in the cloud; record it so nothing asks HQ about this hold again.
|
|
516
|
+
try {
|
|
517
|
+
recordActivePromotion(dir, { agentUid: config.agentUid, ownerUid: config.ownerUid, companyUid, operationId }, state);
|
|
518
|
+
}
|
|
519
|
+
catch (error) {
|
|
520
|
+
appendBotLog(dir, botLogLine("warn", `promotion: could not record the cloud move: ${sentence(error)}`));
|
|
521
|
+
}
|
|
522
|
+
return { outcome: "kept", reason: "the bot moved to the cloud" };
|
|
523
|
+
}
|
|
524
|
+
else if (state.phase !== "cancelled") {
|
|
525
|
+
return { outcome: "kept", reason: `the move is ${state.phase}` };
|
|
526
|
+
}
|
|
527
|
+
else
|
|
528
|
+
why = "cancelled";
|
|
529
|
+
const again = readLocalHold(dir, config);
|
|
530
|
+
if (again.hold?.operationId !== operationId || again.hold.companyUid !== companyUid || hasReceiptFile(dir))
|
|
531
|
+
return { outcome: "kept", reason: "the hold changed" };
|
|
532
|
+
const wasRunning = readPromotionHoldOrigin(dir, operationId);
|
|
533
|
+
releaseLocalPromotion(dir);
|
|
534
|
+
appendBotLog(dir, botLogLine("info", why === "cancelled"
|
|
535
|
+
? `promotion: HQ shows the move ${operationId} to company ${companyUid} cancelled; released the hold on this computer`
|
|
536
|
+
: `promotion: HQ has no move to company ${companyUid} for this bot; released the hold on this computer`));
|
|
537
|
+
return { outcome: "released", reason: why, companyUid, wasRunning };
|
|
538
|
+
}
|
|
466
539
|
export const PROMOTION_CANCEL_POLL_MS = 5_000;
|
|
467
540
|
/** Below the bot lock's stale age, so no other command can take the lock mid-cancel. */
|
|
468
541
|
export const PROMOTION_CANCEL_TIMEOUT_MS = 8 * 60_000;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { BotApi } from "./api.js";
|
|
2
|
+
import { type BotConfig } from "./config.js";
|
|
3
|
+
import { type PromotionHoldReconcile, type SignedInPerson } from "./promote.js";
|
|
4
|
+
export interface PromotionAccess {
|
|
5
|
+
api: BotApi;
|
|
6
|
+
signedInPerson: SignedInPerson;
|
|
7
|
+
}
|
|
8
|
+
/** The signed-in owner's HQ access, without ever opening a browser sign-in. */
|
|
9
|
+
export declare function ownerPromotionAccess(command: string): PromotionAccess;
|
|
10
|
+
/** How often the daemon and `hq bot run` ask HQ about one held bot. */
|
|
11
|
+
export declare const HELD_BOT_RECONCILE_INTERVAL_MS: number;
|
|
12
|
+
/** Per-bot record of the last HQ check, shared by every process on this
|
|
13
|
+
* computer (a restarting daemon, each `hq bot run`). Written before the check
|
|
14
|
+
* starts, so a check in flight counts as a recent one.
|
|
15
|
+
*/
|
|
16
|
+
/** Where the per-bot check records live, under the daemon's own folder. */
|
|
17
|
+
export declare const heldBotThrottleDir: (daemonRoot: string) => string;
|
|
18
|
+
export interface ReconcileThrottle {
|
|
19
|
+
dir: string;
|
|
20
|
+
intervalMs?: number;
|
|
21
|
+
now?: () => number;
|
|
22
|
+
}
|
|
23
|
+
/** Claims this bot's next HQ check: false while a check is in flight or ran within the interval. */
|
|
24
|
+
export declare function claimHeldBotCheck(throttle: ReconcileThrottle, name: string): boolean;
|
|
25
|
+
/** reconcilePromotionHold under the bot's lock. A busy lock, a signed-out owner
|
|
26
|
+
* or any other failure keeps the hold. With a throttle, a bot checked recently
|
|
27
|
+
* (or being checked now) is skipped without asking HQ.
|
|
28
|
+
*/
|
|
29
|
+
export declare function reconcileHeldBot(name: string, dir: string, config: BotConfig, opts: {
|
|
30
|
+
command: string;
|
|
31
|
+
access?: PromotionAccess;
|
|
32
|
+
lockWaitMs?: number;
|
|
33
|
+
root?: string;
|
|
34
|
+
throttle?: ReconcileThrottle;
|
|
35
|
+
onWait?: () => void;
|
|
36
|
+
}): Promise<PromotionHoldReconcile>;
|
|
37
|
+
export interface HeldBot {
|
|
38
|
+
name: string;
|
|
39
|
+
dir: string;
|
|
40
|
+
config: BotConfig;
|
|
41
|
+
}
|
|
42
|
+
/** The daemon's self-heal for held bots: one pass at a time, and at most one
|
|
43
|
+
* HQ check per bot per interval across daemon restarts. A released bot's
|
|
44
|
+
* daemon unit is asked to start.
|
|
45
|
+
*/
|
|
46
|
+
export declare function createHeldBotReconciler(deps: {
|
|
47
|
+
root?: string;
|
|
48
|
+
platform?: NodeJS.Platform;
|
|
49
|
+
throttle: ReconcileThrottle;
|
|
50
|
+
reconcile?: (bot: HeldBot) => Promise<PromotionHoldReconcile>;
|
|
51
|
+
requestStart: (unitId: string) => void;
|
|
52
|
+
log: (level: "info" | "warn", message: string) => void;
|
|
53
|
+
}): {
|
|
54
|
+
kick(): Promise<void>;
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=promotion-hold-reconcile.d.ts.map
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
4
|
+
import { ensureOwnerToken } from "../../utils/owner-session.js";
|
|
5
|
+
import { resolveCallerPersonUid } from "../../utils/vault-api.js";
|
|
6
|
+
import { BotApi } from "./api.js";
|
|
7
|
+
import { HQ_FLEET_RUNTIME_ENGINE_ID, readBotConfig } from "./config.js";
|
|
8
|
+
import { withBotLock } from "./lock.js";
|
|
9
|
+
import { botsRoot } from "./paths.js";
|
|
10
|
+
import { reconcilePromotionHold } from "./promote.js";
|
|
11
|
+
import { hasPromotionHold } from "./promotion-hold.js";
|
|
12
|
+
/** The signed-in owner's HQ access, without ever opening a browser sign-in. */
|
|
13
|
+
export function ownerPromotionAccess(command) {
|
|
14
|
+
const token = () => ensureOwnerToken({ interactive: false });
|
|
15
|
+
return { api: new BotApi({ token }), signedInPerson: async () => resolveCallerPersonUid(await token(), undefined, { command }) };
|
|
16
|
+
}
|
|
17
|
+
/** How often the daemon and `hq bot run` ask HQ about one held bot. */
|
|
18
|
+
export const HELD_BOT_RECONCILE_INTERVAL_MS = 15 * 60_000;
|
|
19
|
+
/** Per-bot record of the last HQ check, shared by every process on this
|
|
20
|
+
* computer (a restarting daemon, each `hq bot run`). Written before the check
|
|
21
|
+
* starts, so a check in flight counts as a recent one.
|
|
22
|
+
*/
|
|
23
|
+
/** Where the per-bot check records live, under the daemon's own folder. */
|
|
24
|
+
export const heldBotThrottleDir = (daemonRoot) => path.join(daemonRoot, "promotion-reconcile");
|
|
25
|
+
const throttleFile = (throttle, name) => path.join(throttle.dir, `${name}.json`);
|
|
26
|
+
/** Claims this bot's next HQ check: false while a check is in flight or ran within the interval. */
|
|
27
|
+
export function claimHeldBotCheck(throttle, name) {
|
|
28
|
+
const now = (throttle.now ?? Date.now)();
|
|
29
|
+
const file = throttleFile(throttle, name);
|
|
30
|
+
try {
|
|
31
|
+
const last = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
32
|
+
if (typeof last.startedAt === "number" && last.startedAt <= now && now - last.startedAt < (throttle.intervalMs ?? HELD_BOT_RECONCILE_INTERVAL_MS))
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
catch { /* none yet, or unreadable: check now */ }
|
|
36
|
+
writeThrottle(file, { startedAt: now, inFlight: true, pid: process.pid });
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
function finishHeldBotCheck(throttle, name, result) {
|
|
40
|
+
const file = throttleFile(throttle, name);
|
|
41
|
+
if (result.outcome === "released" || result.outcome === "none") {
|
|
42
|
+
fs.rmSync(file, { force: true });
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
const last = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
47
|
+
writeThrottle(file, { ...last, inFlight: false, finishedAt: (throttle.now ?? Date.now)() });
|
|
48
|
+
}
|
|
49
|
+
catch { /* the claim stays as written */ }
|
|
50
|
+
}
|
|
51
|
+
function writeThrottle(file, value) {
|
|
52
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
53
|
+
const temp = `${file}.${randomUUID()}.tmp`;
|
|
54
|
+
fs.writeFileSync(temp, JSON.stringify(value), { mode: 0o600 });
|
|
55
|
+
fs.renameSync(temp, file);
|
|
56
|
+
}
|
|
57
|
+
/** reconcilePromotionHold under the bot's lock. A busy lock, a signed-out owner
|
|
58
|
+
* or any other failure keeps the hold. With a throttle, a bot checked recently
|
|
59
|
+
* (or being checked now) is skipped without asking HQ.
|
|
60
|
+
*/
|
|
61
|
+
export async function reconcileHeldBot(name, dir, config, opts) {
|
|
62
|
+
let claimed = false;
|
|
63
|
+
let result;
|
|
64
|
+
try {
|
|
65
|
+
if (!hasPromotionHold(dir))
|
|
66
|
+
return { outcome: "none" };
|
|
67
|
+
if (opts.throttle) {
|
|
68
|
+
if (!claimHeldBotCheck(opts.throttle, name))
|
|
69
|
+
return { outcome: "kept", reason: "HQ was asked recently" };
|
|
70
|
+
claimed = true;
|
|
71
|
+
}
|
|
72
|
+
const access = opts.access ?? ownerPromotionAccess(opts.command);
|
|
73
|
+
result = await withBotLock(name, () => reconcilePromotionHold({ dir, config, ...access }), {
|
|
74
|
+
command: opts.command,
|
|
75
|
+
...(opts.lockWaitMs !== undefined ? { waitMs: opts.lockWaitMs } : {}),
|
|
76
|
+
...(opts.root ? { root: opts.root } : {}),
|
|
77
|
+
...(opts.onWait ? { onWait: opts.onWait } : {}),
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
result = { outcome: "kept", reason: error instanceof Error ? error.message : String(error) };
|
|
82
|
+
}
|
|
83
|
+
if (claimed) {
|
|
84
|
+
try {
|
|
85
|
+
finishHeldBotCheck(opts.throttle, name, result);
|
|
86
|
+
}
|
|
87
|
+
catch { /* the claim stays as written */ }
|
|
88
|
+
}
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
/** The daemon's self-heal for held bots: one pass at a time, and at most one
|
|
92
|
+
* HQ check per bot per interval across daemon restarts. A released bot's
|
|
93
|
+
* daemon unit is asked to start.
|
|
94
|
+
*/
|
|
95
|
+
export function createHeldBotReconciler(deps) {
|
|
96
|
+
const root = deps.root ?? botsRoot();
|
|
97
|
+
const platform = deps.platform ?? process.platform;
|
|
98
|
+
const reconcile = deps.reconcile ?? ((bot) => reconcileHeldBot(bot.name, bot.dir, bot.config, { command: "hq daemon", lockWaitMs: 0, root }));
|
|
99
|
+
let running = null;
|
|
100
|
+
const held = () => {
|
|
101
|
+
let names;
|
|
102
|
+
try {
|
|
103
|
+
names = fs.readdirSync(root, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name).sort();
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
const bots = [];
|
|
109
|
+
for (const name of names) {
|
|
110
|
+
const dir = path.join(root, name);
|
|
111
|
+
try {
|
|
112
|
+
if (!hasPromotionHold(dir) || fs.existsSync(path.join(dir, "promotion-active.json")))
|
|
113
|
+
continue;
|
|
114
|
+
const config = readBotConfig(dir);
|
|
115
|
+
if (config)
|
|
116
|
+
bots.push({ name, dir, config });
|
|
117
|
+
}
|
|
118
|
+
catch { /* unreadable: stays held */ }
|
|
119
|
+
}
|
|
120
|
+
return bots;
|
|
121
|
+
};
|
|
122
|
+
const pass = async () => {
|
|
123
|
+
for (const bot of held()) {
|
|
124
|
+
if (!claimHeldBotCheck(deps.throttle, bot.name))
|
|
125
|
+
continue;
|
|
126
|
+
const result = await reconcile(bot).catch((error) => ({ outcome: "kept", reason: error instanceof Error ? error.message : String(error) }));
|
|
127
|
+
try {
|
|
128
|
+
finishHeldBotCheck(deps.throttle, bot.name, result);
|
|
129
|
+
}
|
|
130
|
+
catch { /* the claim stays as written */ }
|
|
131
|
+
if (result.outcome !== "released")
|
|
132
|
+
continue;
|
|
133
|
+
const fleet = bot.config.engine?.id === HQ_FLEET_RUNTIME_ENGINE_ID;
|
|
134
|
+
const unit = fleet ? (platform === "darwin" ? `fleet-bots:${bot.name}` : null) : `bots:${bot.name}`;
|
|
135
|
+
const start = unit !== null && (fleet || result.wasRunning !== false);
|
|
136
|
+
const why = result.reason === "cancelled" ? "HQ shows its move to the cloud was cancelled" : "HQ has no move to the cloud for it";
|
|
137
|
+
deps.log("info", `${bot.name}: ${why}; released its hold${start ? " and starting it" : `; start it with: hq bot start ${bot.name}`}`);
|
|
138
|
+
if (start) {
|
|
139
|
+
try {
|
|
140
|
+
deps.requestStart(unit);
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
deps.log("warn", `${bot.name}: could not ask the daemon to start it: ${error instanceof Error ? error.message : String(error)}`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
return {
|
|
149
|
+
kick() {
|
|
150
|
+
running ??= pass().catch(() => undefined).finally(() => { running = null; });
|
|
151
|
+
return running;
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=promotion-hold-reconcile.js.map
|
|
@@ -338,8 +338,6 @@ export declare function claudeOAuthRefreshLastPath(root: string): string;
|
|
|
338
338
|
export declare function tokenFingerprint(token: string): string;
|
|
339
339
|
/** Reads the last refresh outcome for a home. Exposed for the doctor command. */
|
|
340
340
|
export declare function readClaudeRefreshLast(root: string, home: string): ClaudeRefreshLastEntry | null;
|
|
341
|
-
/** @deprecated prefer {@link revokedMarkerForCurrentCredential}; this is the pre-fingerprint shim. */
|
|
342
|
-
export declare function isAccountRevokedPersisted(root: string, accountId: string): boolean;
|
|
343
341
|
/**
|
|
344
342
|
* True when the capacity collector has recorded this refresh token as
|
|
345
343
|
* revoked (by token fingerprint, under any account). Lanes use it to tell a
|
|
@@ -1657,11 +1657,6 @@ function clearAccountRevoked(root, accountId) {
|
|
|
1657
1657
|
delete file.revokedAccounts[accountId];
|
|
1658
1658
|
writeRefreshLast(root, file);
|
|
1659
1659
|
}
|
|
1660
|
-
/** @deprecated prefer {@link revokedMarkerForCurrentCredential}; this is the pre-fingerprint shim. */
|
|
1661
|
-
export function isAccountRevokedPersisted(root, accountId) {
|
|
1662
|
-
const file = readRefreshLast(root);
|
|
1663
|
-
return Object.prototype.hasOwnProperty.call(file.revokedAccounts, accountId);
|
|
1664
|
-
}
|
|
1665
1660
|
/**
|
|
1666
1661
|
* True when the capacity collector has recorded this refresh token as
|
|
1667
1662
|
* revoked (by token fingerprint, under any account). Lanes use it to tell a
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Paths the native delegate steps print, spelled exactly as the hq-core
|
|
3
|
+
* helpers spell them: the HQ root as given, then literal forward slashes
|
|
4
|
+
* ("$HQ_ROOT/companies/..."). These strings appear in plans and error text
|
|
5
|
+
* that the parity tests compare byte for byte, so they must not depend on the
|
|
6
|
+
* platform path module. Node opens mixed-separator paths on every platform,
|
|
7
|
+
* so the same strings are used to read the files.
|
|
8
|
+
*
|
|
9
|
+
* This module imports nothing: core-delegate-paths.test.ts runs it under
|
|
10
|
+
* path.win32 semantics, and a path.join rewrite would fail there on any OS.
|
|
11
|
+
*/
|
|
12
|
+
/** Schema sources as hq-delegate-secrets.sh builds them. */
|
|
13
|
+
export declare function secretsSourcePaths(root: string, company: string, project: string, repoRel: string): {
|
|
14
|
+
projectSchema: string;
|
|
15
|
+
prdFile: string;
|
|
16
|
+
repoSchema: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* The repository directory as hq-delegate-repo.sh resolves it: an absolute
|
|
20
|
+
* repo.path (POSIX or a Windows drive path) is used as-is, otherwise
|
|
21
|
+
* "$HQ_ROOT/$REPO_REL".
|
|
22
|
+
*/
|
|
23
|
+
export declare function delegateRepoDirectory(root: string, repoRel: string): string;
|
|
24
|
+
/** The company board as hq-delegate-transfer.sh spells it. */
|
|
25
|
+
export declare function delegateBoardPath(root: string, company: string): string;
|
|
26
|
+
//# sourceMappingURL=delegate-helper-paths.d.ts.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Paths the native delegate steps print, spelled exactly as the hq-core
|
|
3
|
+
* helpers spell them: the HQ root as given, then literal forward slashes
|
|
4
|
+
* ("$HQ_ROOT/companies/..."). These strings appear in plans and error text
|
|
5
|
+
* that the parity tests compare byte for byte, so they must not depend on the
|
|
6
|
+
* platform path module. Node opens mixed-separator paths on every platform,
|
|
7
|
+
* so the same strings are used to read the files.
|
|
8
|
+
*
|
|
9
|
+
* This module imports nothing: core-delegate-paths.test.ts runs it under
|
|
10
|
+
* path.win32 semantics, and a path.join rewrite would fail there on any OS.
|
|
11
|
+
*/
|
|
12
|
+
/** Schema sources as hq-delegate-secrets.sh builds them. */
|
|
13
|
+
export function secretsSourcePaths(root, company, project, repoRel) {
|
|
14
|
+
const projectDir = `${root}/companies/${company}/projects/${project}`;
|
|
15
|
+
return {
|
|
16
|
+
projectSchema: `${projectDir}/.env.schema`,
|
|
17
|
+
prdFile: `${projectDir}/prd.json`,
|
|
18
|
+
repoSchema: repoRel ? `${root}/${repoRel}/.env.schema` : "",
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The repository directory as hq-delegate-repo.sh resolves it: an absolute
|
|
23
|
+
* repo.path (POSIX or a Windows drive path) is used as-is, otherwise
|
|
24
|
+
* "$HQ_ROOT/$REPO_REL".
|
|
25
|
+
*/
|
|
26
|
+
export function delegateRepoDirectory(root, repoRel) {
|
|
27
|
+
return /^\//.test(repoRel) || /^[A-Za-z]:[\\/]/.test(repoRel) ? repoRel : `${root}/${repoRel}`;
|
|
28
|
+
}
|
|
29
|
+
/** The company board as hq-delegate-transfer.sh spells it. */
|
|
30
|
+
export function delegateBoardPath(root, company) {
|
|
31
|
+
return `${root}/companies/${company}/board.json`;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=delegate-helper-paths.js.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Installs a pinned, checksum-verified jq for the daemon's own use when the
|
|
3
|
+
* machine has no working jq (see verified-jq.ts).
|
|
4
|
+
*
|
|
5
|
+
* Unix copies go to ~/.hq/daemon/tools/<version>/jq, outside the shell PATH.
|
|
6
|
+
* Windows shares ~/.local/bin/jq.exe with the global hook installer and doctor.
|
|
7
|
+
* Both paths use the same pinned download and safe staging implementation.
|
|
8
|
+
*
|
|
9
|
+
* Binaries and checksums are jqlang/jq's official release (sha256sum.txt of
|
|
10
|
+
* jq-1.8.2); the macOS values match the desktop app's pinned ones.
|
|
11
|
+
*/
|
|
12
|
+
import { type JqRunner, type ResolveJqDeps, type VerifiedJq } from "./verified-jq.js";
|
|
13
|
+
export declare const MANAGED_JQ_VERSION = "jq-1.8.2";
|
|
14
|
+
/** Where the daemon keeps its own jq, or null on a platform it does not provision. */
|
|
15
|
+
export declare function managedJqPath(home: string | undefined, platform?: NodeJS.Platform): string | null;
|
|
16
|
+
export declare function managedJqAsset(platform: NodeJS.Platform, arch: string): {
|
|
17
|
+
url: string;
|
|
18
|
+
sha256: string;
|
|
19
|
+
} | null;
|
|
20
|
+
export interface ProvisionJqDeps {
|
|
21
|
+
home: string | undefined;
|
|
22
|
+
platform?: NodeJS.Platform;
|
|
23
|
+
arch?: string;
|
|
24
|
+
fetch?: (url: string, init: {
|
|
25
|
+
signal: AbortSignal;
|
|
26
|
+
redirect: "follow";
|
|
27
|
+
}) => Promise<Response>;
|
|
28
|
+
run?: JqRunner;
|
|
29
|
+
log?: (line: string) => void;
|
|
30
|
+
/** Test seam: the download and its checksum. Defaults to managedJqAsset. */
|
|
31
|
+
asset?: {
|
|
32
|
+
url: string;
|
|
33
|
+
sha256: string;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export type ProvisionJqResult = {
|
|
37
|
+
ok: true;
|
|
38
|
+
path: string;
|
|
39
|
+
} | {
|
|
40
|
+
ok: false;
|
|
41
|
+
reason: string;
|
|
42
|
+
};
|
|
43
|
+
/** For tests. */
|
|
44
|
+
export declare function resetJqProvision(): void;
|
|
45
|
+
/**
|
|
46
|
+
* Install the managed jq. Concurrent callers share one install, and after a
|
|
47
|
+
* failure (offline, say) callers get that failure for ten minutes instead of
|
|
48
|
+
* starting a download per policy check.
|
|
49
|
+
*/
|
|
50
|
+
export declare function provisionManagedJq(deps: ProvisionJqDeps, now?: () => number): Promise<ProvisionJqResult>;
|
|
51
|
+
export interface ResolveOrProvisionDeps extends ResolveJqDeps {
|
|
52
|
+
/** How long a caller waits for a fresh install before failing closed. */
|
|
53
|
+
waitMs?: number;
|
|
54
|
+
provision?: Partial<ProvisionJqDeps>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The jq policy checks run with: the daemon's own managed copy or another jq
|
|
58
|
+
* that passes the probe; when there is none, install the managed copy (waiting
|
|
59
|
+
* up to `waitMs`) and look again. Throws JqUnavailableError when that fails or
|
|
60
|
+
* is still running, so the caller fails closed.
|
|
61
|
+
*/
|
|
62
|
+
export declare function resolveOrProvisionJq(deps: ResolveOrProvisionDeps): Promise<VerifiedJq>;
|
|
63
|
+
//# sourceMappingURL=jq-provision.d.ts.map
|