@indigoai-us/hq-cli 5.345.204 → 5.345.205
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 +25 -0
- package/dist/command-catalog.generated.d.ts +51 -1
- package/dist/command-catalog.generated.js +63 -1
- package/dist/commands/bot.d.ts +67 -0
- package/dist/commands/bot.js +301 -39
- package/dist/commands/cloud-off-gate.d.ts +9 -2
- package/dist/commands/cloud-off-gate.js +49 -13
- package/dist/commands/feedback.d.ts +26 -0
- package/dist/commands/feedback.js +91 -5
- package/dist/commands/install-global.d.ts +3 -1
- package/dist/commands/install-global.js +15 -4
- package/dist/commands/lanes.d.ts +2 -0
- package/dist/commands/lanes.js +9 -3
- package/dist/commands/mcp-serve.d.ts +5 -2
- package/dist/commands/mcp-serve.js +45 -3
- package/dist/commands/mcp-status.d.ts +3 -1
- package/dist/commands/mcp-status.js +24 -14
- package/dist/commands/secrets.js +11 -1
- package/dist/commands/sources.js +10 -15
- package/dist/index.js +7 -2
- package/dist/lib/bot/executive-settings.d.ts +13 -0
- package/dist/lib/bot/executive-settings.js +20 -17
- package/dist/lib/bot/executive-sync.d.ts +12 -0
- package/dist/lib/bot/executive-sync.js +36 -0
- package/dist/lib/bot/executive.d.ts +51 -0
- package/dist/lib/bot/executive.js +144 -0
- package/dist/lib/bot/fleet-cron.d.ts +7 -0
- package/dist/lib/bot/fleet-cron.js +2 -1
- package/dist/lib/bot/jobs/executive-handover.d.ts +6 -0
- package/dist/lib/bot/jobs/executive-handover.js +33 -0
- package/dist/lib/bot/jobs/hot-signal-sync.d.ts +22 -0
- package/dist/lib/bot/jobs/hot-signal-sync.js +47 -0
- package/dist/lib/bot/listed-running.d.ts +16 -0
- package/dist/lib/bot/listed-running.js +16 -0
- package/dist/lib/bot/pending-switch.d.ts +51 -0
- package/dist/lib/bot/pending-switch.js +103 -0
- package/dist/lib/bot/run.js +27 -3
- package/dist/lib/bot/runtime-failure.js +19 -3
- package/dist/lib/bot/status.d.ts +20 -0
- package/dist/lib/company-skill-wrapper.js +29 -0
- package/dist/lib/daemon/hq-child-bootstrap.mjs +197 -2
- package/dist/lib/daemon/resolver.d.ts +14 -0
- package/dist/lib/daemon/resolver.js +96 -0
- package/dist/lib/daemon/run.d.ts +11 -0
- package/dist/lib/daemon/run.js +58 -6
- package/dist/lib/daemon/server.d.ts +2 -9
- package/dist/lib/daemon/server.js +3 -89
- package/dist/lib/doctor/checks/claude-wiring.js +41 -0
- package/dist/lib/doctor/checks/sync-health.d.ts +8 -0
- package/dist/lib/doctor/checks/sync-health.js +34 -2
- package/dist/lib/doctor/duplicate-hook-registrations.d.ts +34 -0
- package/dist/lib/doctor/duplicate-hook-registrations.js +130 -0
- package/dist/lib/doctor/fix/apply.js +79 -3
- package/dist/lib/doctor/fix/remediation.d.ts +1 -1
- package/dist/lib/doctor/fix/remediation.js +15 -0
- package/dist/lib/doctor/types.d.ts +1 -1
- package/dist/lib/doctor/types.js +1 -0
- package/dist/lib/mcp/local-native-tools.d.ts +40 -0
- package/dist/lib/mcp/local-native-tools.js +111 -0
- package/dist/lib/mcp/tools.d.ts +2 -0
- package/dist/lib/mcp/tools.js +2 -0
- package/dist/lib/signals/steps/extract.d.ts +1 -1
- package/dist/lib/signals/steps/extract.js +4 -16
- package/dist/sentry-init.js +6 -0
- package/dist/utils/cli-network-lifecycle.d.ts +11 -1
- package/dist/utils/cli-network-lifecycle.js +36 -2
- package/dist/utils/daemon-helper-lifetime.d.ts +39 -0
- package/dist/utils/daemon-helper-lifetime.js +209 -0
- package/dist/utils/daemon-helper-markers.d.ts +24 -0
- package/dist/utils/daemon-helper-markers.js +53 -0
- package/dist/utils/mcp-launcher.d.ts +28 -0
- package/dist/utils/mcp-launcher.js +117 -0
- package/dist/utils/package-use-lease.d.ts +10 -0
- package/dist/utils/package-use-lease.js +31 -0
- package/dist/utils/resident-package-preload.js +4 -1
- package/docs/anywhere-runtime.md +7 -0
- package/package.json +7 -7
|
@@ -254,6 +254,35 @@ export function ensureHotSignalSyncJob(dir, input, now = new Date()) {
|
|
|
254
254
|
});
|
|
255
255
|
return { job, created };
|
|
256
256
|
}
|
|
257
|
+
/**
|
|
258
|
+
* A bot that is not the Executive bot removes only hot-signal-sync jobs
|
|
259
|
+
* covered by the Executive and forgets those registrations (legacy and Fleet
|
|
260
|
+
* marker keys). Uncovered companies keep their fallback job. Returns the
|
|
261
|
+
* removed jobs; `forgot` says a marker was cleared even when no job was left.
|
|
262
|
+
*/
|
|
263
|
+
export function handOverHotSignalSyncJobs(dir, companies) {
|
|
264
|
+
const covered = new Set(companies);
|
|
265
|
+
const removed = removeLocalJobsWhere(dir, (job) => {
|
|
266
|
+
const company = hotSignalSyncJobCompany(job.context);
|
|
267
|
+
return company !== null && covered.has(company);
|
|
268
|
+
});
|
|
269
|
+
const forgot = withJobsLock(dir, () => {
|
|
270
|
+
const marker = readMarker(dir);
|
|
271
|
+
let changed = false;
|
|
272
|
+
for (const company of covered) {
|
|
273
|
+
for (const key of [markerKey(company), fleetMarkerKey(company)]) {
|
|
274
|
+
if (marker.registered[key]) {
|
|
275
|
+
delete marker.registered[key];
|
|
276
|
+
changed = true;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
if (changed)
|
|
281
|
+
writeMarker(dir, marker);
|
|
282
|
+
return changed;
|
|
283
|
+
});
|
|
284
|
+
return { removed, forgot };
|
|
285
|
+
}
|
|
257
286
|
/**
|
|
258
287
|
* What a bot does at start for the built-in job: remove jobs for a company it
|
|
259
288
|
* no longer syncs, register the job for its current company once, and, when
|
|
@@ -262,6 +291,24 @@ export function ensureHotSignalSyncJob(dir, input, now = new Date()) {
|
|
|
262
291
|
*/
|
|
263
292
|
export function registerHotSignalSyncOnStart(input) {
|
|
264
293
|
const log = input.log ?? (() => undefined);
|
|
294
|
+
if (input.executive === false) {
|
|
295
|
+
let handedOver = [];
|
|
296
|
+
try {
|
|
297
|
+
const { removed, forgot } = handOverHotSignalSyncJobs(input.dir, input.executiveCompanies ?? []);
|
|
298
|
+
handedOver = removed;
|
|
299
|
+
if (removed.length > 0 || forgot) {
|
|
300
|
+
const to = input.executiveName ? `${input.executiveName} is the Executive bot now and runs it` : "only the Executive bot runs it";
|
|
301
|
+
log("info", `Removed the daily hot-channel sync from this bot (${removed.length} job${removed.length === 1 ? "" : "s"}): ${to}.`);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
catch (err) {
|
|
305
|
+
log("warn", `Could not hand the hot-channel sync jobs over to the Executive bot: ${errorMessage(err)}`);
|
|
306
|
+
}
|
|
307
|
+
const current = currentHotSignalSyncCompany(input.config, input.activeCompany);
|
|
308
|
+
if (current && input.executiveCompanies?.includes(current)) {
|
|
309
|
+
return { company: null, ensured: null, firstRun: null, handedOver };
|
|
310
|
+
}
|
|
311
|
+
}
|
|
265
312
|
const company = currentHotSignalSyncCompany(input.config, input.activeCompany);
|
|
266
313
|
try {
|
|
267
314
|
for (const stale of removeStaleHotSignalSyncJobs(input.dir, company)) {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The running signal `hq bot list` uses. One place, so a stopped Executive
|
|
3
|
+
* cannot be treated as covering a company by some other reading of the same files.
|
|
4
|
+
*/
|
|
5
|
+
import { type BotConfig } from "./config.js";
|
|
6
|
+
import { type BotStatusFile } from "./status.js";
|
|
7
|
+
export interface BotListedProcess {
|
|
8
|
+
fleet: boolean;
|
|
9
|
+
status: BotStatusFile | null;
|
|
10
|
+
/** Live pid `hq bot list` would print, or null when the bot is not running. */
|
|
11
|
+
pid: number | null;
|
|
12
|
+
running: boolean;
|
|
13
|
+
}
|
|
14
|
+
/** Whether `hq bot list` shows this bot as running. */
|
|
15
|
+
export declare function readBotListedProcess(dir: string, config: Pick<BotConfig, "agentUid" | "engine">): BotListedProcess;
|
|
16
|
+
//# sourceMappingURL=listed-running.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The running signal `hq bot list` uses. One place, so a stopped Executive
|
|
3
|
+
* cannot be treated as covering a company by some other reading of the same files.
|
|
4
|
+
*/
|
|
5
|
+
import { HQ_FLEET_RUNTIME_ENGINE_ID } from "./config.js";
|
|
6
|
+
import { fleetLocalGatewayPid } from "./fleet-local.js";
|
|
7
|
+
import { isPidAlive, readBotStatus } from "./status.js";
|
|
8
|
+
/** Whether `hq bot list` shows this bot as running. */
|
|
9
|
+
export function readBotListedProcess(dir, config) {
|
|
10
|
+
const fleet = config.engine?.id === HQ_FLEET_RUNTIME_ENGINE_ID;
|
|
11
|
+
const status = readBotStatus(dir);
|
|
12
|
+
const recordedPid = fleet ? fleetLocalGatewayPid(config.agentUid) : (status?.pid ?? null);
|
|
13
|
+
const running = recordedPid !== null && isPidAlive(recordedPid) && (fleet || status?.state === "running");
|
|
14
|
+
return { fleet, status, pid: running ? recordedPid : null, running };
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=listed-running.js.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type BotConfig, type BotRuntimeId } from "./config.js";
|
|
2
|
+
import { type BotStatusFile } from "./status.js";
|
|
3
|
+
export declare const PENDING_SWITCH_FILE = "switch-pending.json";
|
|
4
|
+
export interface PendingSwitch {
|
|
5
|
+
v: 1;
|
|
6
|
+
/** The switching process. While it is alive the switch is still running. */
|
|
7
|
+
pid: number;
|
|
8
|
+
startedAt: string;
|
|
9
|
+
/** `changing`: settings may be half-written, roll back. `started`: up on the new account, finish. */
|
|
10
|
+
phase: "changing" | "started";
|
|
11
|
+
wasRunning: boolean;
|
|
12
|
+
from: {
|
|
13
|
+
runtime: BotRuntimeId;
|
|
14
|
+
runtimeAuth: BotConfig["runtimeAuth"] | null;
|
|
15
|
+
model: string | null;
|
|
16
|
+
effort: string | null;
|
|
17
|
+
};
|
|
18
|
+
to: BotRuntimeId;
|
|
19
|
+
/** Session files moved aside for a different runtime, so a rollback puts them back. */
|
|
20
|
+
aside: {
|
|
21
|
+
archiveDir: string;
|
|
22
|
+
moved: string[];
|
|
23
|
+
} | null;
|
|
24
|
+
/** The old account's state as it was before the switch cleared it. */
|
|
25
|
+
brainState: Pick<BotStatusFile, "brainUsage" | "runtimeSignIn" | "modelHold"> | null;
|
|
26
|
+
}
|
|
27
|
+
export interface PendingSwitchRecovery {
|
|
28
|
+
action: "rolled-back" | "finished";
|
|
29
|
+
/** The bot was running before the switch; a start puts it back up. */
|
|
30
|
+
wasRunning: boolean;
|
|
31
|
+
}
|
|
32
|
+
export declare function readPendingSwitch(dir: string): PendingSwitch | null;
|
|
33
|
+
export declare function writePendingSwitch(dir: string, journal: PendingSwitch): void;
|
|
34
|
+
export declare function clearPendingSwitch(dir: string): void;
|
|
35
|
+
/**
|
|
36
|
+
* `recoverPendingSwitch` for read paths (`hq bot list`, `status`): a journal
|
|
37
|
+
* that cannot be recovered (a missing archive folder, an unreadable file) is
|
|
38
|
+
* logged and skipped, so one bot's bad journal never stops the others from
|
|
39
|
+
* listing. The journal stays for the next try or for a person to look at.
|
|
40
|
+
*/
|
|
41
|
+
export declare function recoverPendingSwitchSafely(dir: string, deps?: {
|
|
42
|
+
alive?: (pid: number) => boolean;
|
|
43
|
+
}): PendingSwitchRecovery | null;
|
|
44
|
+
/**
|
|
45
|
+
* Roll back or finish a switch whose process is gone. Returns null when there
|
|
46
|
+
* is no journal, or the switch is still running in a live process.
|
|
47
|
+
*/
|
|
48
|
+
export declare function recoverPendingSwitch(dir: string, deps?: {
|
|
49
|
+
alive?: (pid: number) => boolean;
|
|
50
|
+
}): PendingSwitchRecovery | null;
|
|
51
|
+
//# sourceMappingURL=pending-switch.d.ts.map
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pending-switch journal for `hq bot switch-account`.
|
|
3
|
+
*
|
|
4
|
+
* A switch stops the bot, sets the old runtime's sessions aside, rewrites
|
|
5
|
+
* bot.json, clears the old account's sign-in and usage state, and starts the
|
|
6
|
+
* bot again. A process killed part-way (the desktop's time budget, a closed
|
|
7
|
+
* terminal, a reboot) would leave the bot stopped on half-written settings,
|
|
8
|
+
* so the switch writes this journal before it changes anything and removes
|
|
9
|
+
* it when it is done. The next `hq bot start`, `status` or `list` that finds
|
|
10
|
+
* a journal whose process is gone either rolls the switch back (the bot never
|
|
11
|
+
* came up on the new account) or finishes it (it did).
|
|
12
|
+
*/
|
|
13
|
+
import * as fs from "node:fs";
|
|
14
|
+
import * as path from "node:path";
|
|
15
|
+
import { patchBotConfig } from "./config.js";
|
|
16
|
+
import { createBotLogger } from "./log.js";
|
|
17
|
+
import { restoreBotSessions } from "./runtime-auth.js";
|
|
18
|
+
import { isPidAlive, patchBotStatus, readBotStatus } from "./status.js";
|
|
19
|
+
export const PENDING_SWITCH_FILE = "switch-pending.json";
|
|
20
|
+
function journalPath(dir) {
|
|
21
|
+
return path.join(dir, PENDING_SWITCH_FILE);
|
|
22
|
+
}
|
|
23
|
+
export function readPendingSwitch(dir) {
|
|
24
|
+
try {
|
|
25
|
+
const raw = JSON.parse(fs.readFileSync(journalPath(dir), "utf8"));
|
|
26
|
+
return raw && raw.v === 1 && typeof raw.pid === "number" && raw.from ? raw : null;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export function writePendingSwitch(dir, journal) {
|
|
33
|
+
const file = journalPath(dir);
|
|
34
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
35
|
+
fs.writeFileSync(tmp, JSON.stringify(journal, null, 2), { mode: 0o600 });
|
|
36
|
+
fs.renameSync(tmp, file);
|
|
37
|
+
}
|
|
38
|
+
export function clearPendingSwitch(dir) {
|
|
39
|
+
fs.rmSync(journalPath(dir), { force: true });
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* `recoverPendingSwitch` for read paths (`hq bot list`, `status`): a journal
|
|
43
|
+
* that cannot be recovered (a missing archive folder, an unreadable file) is
|
|
44
|
+
* logged and skipped, so one bot's bad journal never stops the others from
|
|
45
|
+
* listing. The journal stays for the next try or for a person to look at.
|
|
46
|
+
*/
|
|
47
|
+
export function recoverPendingSwitchSafely(dir, deps = {}) {
|
|
48
|
+
try {
|
|
49
|
+
return recoverPendingSwitch(dir, deps);
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
try {
|
|
53
|
+
createBotLogger(dir)("warn", `switch-account recovery skipped: ${err instanceof Error ? err.message : String(err)}`);
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
/* the log is best effort too */
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Roll back or finish a switch whose process is gone. Returns null when there
|
|
63
|
+
* is no journal, or the switch is still running in a live process.
|
|
64
|
+
*/
|
|
65
|
+
export function recoverPendingSwitch(dir, deps = {}) {
|
|
66
|
+
const journal = readPendingSwitch(dir);
|
|
67
|
+
if (!journal)
|
|
68
|
+
return null;
|
|
69
|
+
const alive = deps.alive ?? isPidAlive;
|
|
70
|
+
if (journal.pid === process.pid || alive(journal.pid))
|
|
71
|
+
return null;
|
|
72
|
+
const log = createBotLogger(dir);
|
|
73
|
+
// The switch was killed while its start was still waiting, but the bot did
|
|
74
|
+
// come up on the new account: undoing the settings under a running bot
|
|
75
|
+
// would delete its live session. Finish instead.
|
|
76
|
+
const bot = readBotStatus(dir);
|
|
77
|
+
const upOnNewAccount = journal.phase === "changing" && !!bot && bot.pid !== journal.pid && alive(bot.pid) && bot.state === "running" && bot.runtime === journal.to;
|
|
78
|
+
if (journal.phase === "started" || upOnNewAccount) {
|
|
79
|
+
clearPendingSwitch(dir);
|
|
80
|
+
log("info", `switch-account to ${journal.to} was cut off after the bot started on the new account; kept the new account`);
|
|
81
|
+
return { action: "finished", wasRunning: journal.wasRunning };
|
|
82
|
+
}
|
|
83
|
+
if (journal.aside) {
|
|
84
|
+
// Check before touching anything: putting sessions back removes the ones
|
|
85
|
+
// there now, so a missing archive must stop the recovery first.
|
|
86
|
+
const missing = journal.aside.moved.filter((name) => !fs.existsSync(path.join(journal.aside.archiveDir, name)));
|
|
87
|
+
if (missing.length)
|
|
88
|
+
throw new Error(`the set-aside sessions are missing from ${journal.aside.archiveDir}`);
|
|
89
|
+
restoreBotSessions(dir, journal.aside);
|
|
90
|
+
}
|
|
91
|
+
if (journal.brainState && readBotStatus(dir))
|
|
92
|
+
patchBotStatus(dir, journal.brainState, () => readBotStatus(dir));
|
|
93
|
+
patchBotConfig(dir, {
|
|
94
|
+
runtime: journal.from.runtime,
|
|
95
|
+
runtimeAuth: journal.from.runtimeAuth ?? undefined,
|
|
96
|
+
model: journal.from.model ?? undefined,
|
|
97
|
+
effort: journal.from.effort ?? undefined,
|
|
98
|
+
});
|
|
99
|
+
clearPendingSwitch(dir);
|
|
100
|
+
log("warn", `switch-account to ${journal.to} was cut off before the bot came up; rolled back to ${journal.from.runtime}`);
|
|
101
|
+
return { action: "rolled-back", wasRunning: journal.wasRunning };
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=pending-switch.js.map
|
package/dist/lib/bot/run.js
CHANGED
|
@@ -50,7 +50,9 @@ import { ensureSignalToLaneJobs, runSignalToLane, SIGNAL_TO_LANE_JOB_KIND } from
|
|
|
50
50
|
* Everything with a side effect is injectable so the loop is unit-testable.
|
|
51
51
|
*/
|
|
52
52
|
import { createMeetingRider, defaultMeetingRiderDeps, ensureMeetingRiderJob, MEETING_RIDER_JOB_KIND } from "./jobs/meeting-rider.js";
|
|
53
|
-
import { executiveEnabled, isExecutiveBot } from "./executive-settings.js";
|
|
53
|
+
import { executiveEnabled, isExecutiveBot, isExecutiveIdentity } from "./executive-settings.js";
|
|
54
|
+
import { resolveExecutiveBot } from "./executive.js";
|
|
55
|
+
import { handOverExecutiveJobs } from "./jobs/executive-handover.js";
|
|
54
56
|
import { createMeetingDetect, defaultMeetingDetectDeps, resolveDetectedMeeting } from "./jobs/meeting-detect.js";
|
|
55
57
|
import { botAuthEnv, describeBotAuth, formatBotAuth } from "./runtime-auth.js";
|
|
56
58
|
import { ownerContextBlock } from "./owner-context.js";
|
|
@@ -95,7 +97,7 @@ import { drainBotEvents } from "./events.js";
|
|
|
95
97
|
import { clearPendingJobCompletion, isCompletionDue, isCompletionExpired, isCompletionForOtherAgent, readPendingJobCompletions, recordPendingJobCompletion } from "./job-completions.js";
|
|
96
98
|
import { SIGN_IN_CHECK_FRESH_MS, SIGN_IN_CHECK_MS, SIGN_IN_RETRY_MS, signInNeededText, signedOutExcerpt, } from "./runtime-sign-in.js";
|
|
97
99
|
import { checkRuntimeSignIn } from "./runtime-sign-in-check.js";
|
|
98
|
-
import { classifyRuntimeError, classifyRuntimeFailure, runtimeDidNotFinishText, runtimeFailureReason, runtimeFailureText, runtimeRepairNotice, withRetrySuggestion, } from "./runtime-failure.js";
|
|
100
|
+
import { classifyRuntimeError, classifyRuntimeFailure, isRuntimeUsageLimit, usageLimitResetsAt, runtimeDidNotFinishText, runtimeFailureReason, runtimeFailureText, runtimeRepairNotice, withRetrySuggestion, } from "./runtime-failure.js";
|
|
99
101
|
import { HQ_BOT_AGENT_UID_ENV } from "../../commands/onboard-bot-membership.js";
|
|
100
102
|
import { captureHeartbeatIdentityMismatch, identityMismatchMessage, isHeartbeatIdentityMismatch, } from "../heartbeat-identity.js";
|
|
101
103
|
import { clearBotSession, ensureBotCompanyScope, readBotSession, writeBotSession } from "./session.js";
|
|
@@ -1299,7 +1301,7 @@ export async function runBot(deps) {
|
|
|
1299
1301
|
modelHealth = "ok";
|
|
1300
1302
|
markSignInWorks();
|
|
1301
1303
|
// A good turn: the last recorded failure is no longer the bot's state.
|
|
1302
|
-
setStatus({ recentFailures: failures.count(now().getTime()), lastError: undefined });
|
|
1304
|
+
setStatus({ recentFailures: failures.count(now().getTime()), lastError: undefined, ...(readStatus()?.brainUsage ? { brainUsage: null } : {}) });
|
|
1303
1305
|
resumedUnknownErrors.delete(sessionScope);
|
|
1304
1306
|
if (turn.modelFallback) {
|
|
1305
1307
|
const { from, to } = turn.modelFallback;
|
|
@@ -1378,6 +1380,14 @@ export async function runBot(deps) {
|
|
|
1378
1380
|
const count = failures.record(now().getTime());
|
|
1379
1381
|
modelHealth = count >= FAILURE_LIMIT ? "failed" : "degraded";
|
|
1380
1382
|
setStatus({ restarts: (readStatus()?.restarts ?? 0) + 1, recentFailures: count, lastError: excerpt.slice(0, 400) });
|
|
1383
|
+
if (isRuntimeUsageLimit(excerpt)) {
|
|
1384
|
+
// The account is out of plan usage: a state of its own, so HQ can offer
|
|
1385
|
+
// another account instead of "try again later".
|
|
1386
|
+
const resetsAt = usageLimitResetsAt(excerpt);
|
|
1387
|
+
const prior = readStatus()?.brainUsage;
|
|
1388
|
+
const since = prior && prior.runtime === config.runtime ? prior.since : now().toISOString();
|
|
1389
|
+
setStatus({ brainUsage: { state: "exhausted", runtime: config.runtime, since, ...(resetsAt ? { resetsAt } : {}) } });
|
|
1390
|
+
}
|
|
1381
1391
|
const cls = classifyRuntimeError(err);
|
|
1382
1392
|
log("error", `model turn failed (${count}/${FAILURE_LIMIT} in window, ${cls}): ${excerpt}`);
|
|
1383
1393
|
if (cls === "runtime-crashed" && err instanceof RuntimeError) {
|
|
@@ -2912,6 +2922,20 @@ export async function runBot(deps) {
|
|
|
2912
2922
|
log("warn", "Meeting rider registration or recovery failed");
|
|
2913
2923
|
}
|
|
2914
2924
|
}
|
|
2925
|
+
else if (!isExecutiveIdentity(config)) {
|
|
2926
|
+
// No longer the Executive bot (hq bot eb): drop the meeting rider and
|
|
2927
|
+
// signal-to-lane jobs so only the Executive bot runs them.
|
|
2928
|
+
try {
|
|
2929
|
+
const handed = handOverExecutiveJobs(dir);
|
|
2930
|
+
if (handed.removed > 0 || handed.forgot) {
|
|
2931
|
+
const executive = resolveExecutiveBot()?.name;
|
|
2932
|
+
log("info", `Removed the meeting rider and signal-to-lane jobs from this bot (${handed.removed} job${handed.removed === 1 ? "" : "s"}): ${executive ? `${executive} is the Executive bot now and runs them` : "only the Executive bot runs them"}.`);
|
|
2933
|
+
}
|
|
2934
|
+
}
|
|
2935
|
+
catch {
|
|
2936
|
+
log("warn", "Executive job hand-over failed");
|
|
2937
|
+
}
|
|
2938
|
+
}
|
|
2915
2939
|
// The kickoff runs alongside the heartbeat, before the first inbox poll, so
|
|
2916
2940
|
// an owner message sent meanwhile is answered after it in the same session.
|
|
2917
2941
|
const kickoff = kickoffAfterIntro
|
|
@@ -49,7 +49,15 @@ const MODEL_UNSUPPORTED = /there'?s an issue with the selected model|\bnot_found
|
|
|
49
49
|
* limit · resets 9pm (Asia/Dhaka)", "You've hit your session limit". Codex:
|
|
50
50
|
* "You've hit your usage limit".
|
|
51
51
|
*/
|
|
52
|
-
const USAGE_LIMIT = /\byou'?ve (?:hit|reached) your (?:[\w-]+ ){0,3}limit\b|\b(?:usage|session|weekly|daily|monthly|5-hour) limit (?:reached|exceeded)\b/i;
|
|
52
|
+
const USAGE_LIMIT = /\byou['’]?ve (?:hit|reached) your (?:[\w-]+ ){0,3}limit\b|\b(?:usage|session|weekly|daily|monthly|5-hour) limit (?:reached|exceeded)\b/i;
|
|
53
|
+
/**
|
|
54
|
+
* Limits that a "You've hit your … limit" sentence can name but that are not
|
|
55
|
+
* the plan running out: a short rate limit ("You've hit your rate limit. Try
|
|
56
|
+
* again in 30 seconds", "You've reached your API rate limit") or a
|
|
57
|
+
* conversation, context or output length. Another account does not help with
|
|
58
|
+
* these, so they never count as an out-of-usage brain.
|
|
59
|
+
*/
|
|
60
|
+
const NOT_PLAN_USAGE = /\brate[\s_-]?limit|\b(?:conversation|context|token|output|request|message)(?:[\s_-]+(?:length|window|size))?[\s_-]+limit\b/i;
|
|
53
61
|
/** "9pm (Asia/Dhaka)" from "... · resets 9pm (Asia/Dhaka)". */
|
|
54
62
|
const USAGE_LIMIT_RESET = /\bresets?(?: at| on)? ([^\n|·]{1,60}?)\s*(?:$|[\n|·])/im;
|
|
55
63
|
const TRANSIENT = /\brate[_ ]limit|\busage[_ ]limit|\btoo many requests\b|\b429\b|\boverloaded\b|\b(?:502|503|504|529)\b|\bservice unavailable\b|\bbad gateway\b|\bgateway time-?out\b|\binternal server error\b|\bECONNRESET\b|\bECONNREFUSED\b|\bETIMEDOUT\b|\bENOTFOUND\b|\bEAI_AGAIN\b|\bENETUNREACH\b|\bsocket hang up\b|\bnetwork (?:error|is unreachable)\b|\bstream (?:disconnected|error)\b|\bconnection (?:reset|refused|closed|error)\b|\btimed out\b|\bexceeded \d+ms \(HQ_BOT_TURN_TIMEOUT_MS\)/i;
|
|
@@ -71,12 +79,20 @@ export function classifyRuntimeFailure(text) {
|
|
|
71
79
|
return "unknown";
|
|
72
80
|
}
|
|
73
81
|
export function isRuntimeUsageLimit(text) {
|
|
74
|
-
|
|
82
|
+
const t = (text ?? "").trim();
|
|
83
|
+
// The veto reads only the limit sentence that matched: a plan limit that the
|
|
84
|
+
// API also tags `rate_limit_error` is still a plan limit.
|
|
85
|
+
const all = new RegExp(USAGE_LIMIT.source, "gi");
|
|
86
|
+
for (const m of t.matchAll(all)) {
|
|
87
|
+
if (!NOT_PLAN_USAGE.test(m[0]))
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
return false;
|
|
75
91
|
}
|
|
76
92
|
/** When a usage limit resets, as the tool wrote it ("9pm (Asia/Dhaka)"), or undefined. */
|
|
77
93
|
export function usageLimitResetsAt(text) {
|
|
78
94
|
const t = text ?? "";
|
|
79
|
-
if (!
|
|
95
|
+
if (!isRuntimeUsageLimit(t))
|
|
80
96
|
return undefined;
|
|
81
97
|
return USAGE_LIMIT_RESET.exec(t)?.[1]?.trim() || undefined;
|
|
82
98
|
}
|
package/dist/lib/bot/status.d.ts
CHANGED
|
@@ -50,6 +50,13 @@ export interface BotStatusFile {
|
|
|
50
50
|
* `hq bot status --json` reports as `runtimeSignedIn`.
|
|
51
51
|
*/
|
|
52
52
|
runtimeSignInCheck?: RuntimeSignInCheck | null;
|
|
53
|
+
/**
|
|
54
|
+
* Set when a model turn failed because the account the bot's coding tool is
|
|
55
|
+
* signed in with has no plan usage left ("You've hit your weekly limit").
|
|
56
|
+
* Not cleared by a restart (the plan does not reset because the process
|
|
57
|
+
* did); cleared by the next turn that works, or by `hq bot switch-account`.
|
|
58
|
+
*/
|
|
59
|
+
brainUsage?: BrainUsageRecord | null;
|
|
53
60
|
/**
|
|
54
61
|
* Set when the installed coding tool is too old for the model it was asked
|
|
55
62
|
* to use and the last turn ran on `to` instead (`from` is "" when the model
|
|
@@ -93,6 +100,14 @@ export interface BotStatusFile {
|
|
|
93
100
|
lastFailure?: BotLastFailure;
|
|
94
101
|
updatedAt: string;
|
|
95
102
|
}
|
|
103
|
+
export interface BrainUsageRecord {
|
|
104
|
+
state: "exhausted";
|
|
105
|
+
runtime: BotRuntimeId;
|
|
106
|
+
/** When the bot first saw the limit (ISO). */
|
|
107
|
+
since: string;
|
|
108
|
+
/** The reset time exactly as the tool wrote it ("9pm (Asia/Dhaka)"), when it said. */
|
|
109
|
+
resetsAt?: string;
|
|
110
|
+
}
|
|
96
111
|
export interface BotLastFailure {
|
|
97
112
|
at: string;
|
|
98
113
|
/** auth | billing | rate_limit | outage | runtime_error | generic */
|
|
@@ -107,6 +122,11 @@ export interface BotLastFailure {
|
|
|
107
122
|
reportId?: string | null;
|
|
108
123
|
uploaded?: boolean;
|
|
109
124
|
ownerNotified?: boolean;
|
|
125
|
+
/** HQ Fleet Runtime `brain_usage`: set when the brain's account ran out of plan usage. */
|
|
126
|
+
brainUsage?: {
|
|
127
|
+
state: string;
|
|
128
|
+
resetsAt?: string | null;
|
|
129
|
+
} | null;
|
|
110
130
|
}
|
|
111
131
|
export declare function defaultBotStatus(pid: number, runtime: BotRuntimeId, now?: () => Date): BotStatusFile;
|
|
112
132
|
export declare function readBotStatus(dir: string): BotStatusFile | null;
|
|
@@ -28,6 +28,12 @@ function encodeLocalSegment(segment, win32) {
|
|
|
28
28
|
}
|
|
29
29
|
return encoded;
|
|
30
30
|
}
|
|
31
|
+
function assertSkillBody(skillFile, body, which) {
|
|
32
|
+
if (body.trim().length === 0) {
|
|
33
|
+
throw new Error(`The ${which} SKILL.md at '${skillFile}' is empty, so it was not bridged as a skill. ` +
|
|
34
|
+
"Restore the skill body (run 'hq sync') and retry.");
|
|
35
|
+
}
|
|
36
|
+
}
|
|
31
37
|
function lstat(pathname) {
|
|
32
38
|
try {
|
|
33
39
|
return fs.lstatSync(pathname);
|
|
@@ -265,6 +271,10 @@ export function surfaceCompanySkill(input) {
|
|
|
265
271
|
if (!fs.existsSync(skillFile) || !fs.statSync(skillFile).isFile()) {
|
|
266
272
|
throw new Error(`The canonical SKILL.md does not exist at '${skillFile}'.`);
|
|
267
273
|
}
|
|
274
|
+
// An empty body (a zero-byte file left by an interrupted write or a sync that
|
|
275
|
+
// has not hydrated yet) would be bridged as a placeholder skill with no
|
|
276
|
+
// instructions. Fail loudly instead of surfacing it.
|
|
277
|
+
assertSkillBody(skillFile, fs.readFileSync(skillFile, "utf8"), "canonical");
|
|
268
278
|
const wrapperName = encodeLocalSegment(`${input.companySlug}:${input.skillSlug}`, input.win32 ?? process.platform === "win32");
|
|
269
279
|
const win32 = input.win32 ?? process.platform === "win32";
|
|
270
280
|
const wrapperPath = path.join(input.hqRoot, ".claude", "skills", wrapperName);
|
|
@@ -349,6 +359,25 @@ export function surfaceCompanySkill(input) {
|
|
|
349
359
|
// safer than rolling back a successful replacement.
|
|
350
360
|
}
|
|
351
361
|
}
|
|
362
|
+
// Read the body back through the committed wrapper (junction on Windows)
|
|
363
|
+
// and require it to match the canonical file, so a wrapper that exposes an
|
|
364
|
+
// empty or different SKILL.md is reported instead of silently shipped.
|
|
365
|
+
const canonicalBody = fs.readFileSync(skillFile, "utf8");
|
|
366
|
+
let bridgedBody = "";
|
|
367
|
+
try {
|
|
368
|
+
bridgedBody = fs.readFileSync(path.join(wrapperPath, "SKILL.md"), "utf8");
|
|
369
|
+
}
|
|
370
|
+
catch (readError) {
|
|
371
|
+
removeEntryNoFollow(wrapperPath, { force: true });
|
|
372
|
+
removeGeneratedMarker(wrapperPath);
|
|
373
|
+
throw new Error(`The bridged skill '${wrapperPath}' could not be read back: ` +
|
|
374
|
+
`${readError instanceof Error ? readError.message : String(readError)}.`);
|
|
375
|
+
}
|
|
376
|
+
if (bridgedBody !== canonicalBody) {
|
|
377
|
+
removeEntryNoFollow(wrapperPath, { force: true });
|
|
378
|
+
removeGeneratedMarker(wrapperPath);
|
|
379
|
+
throw new Error(`The bridged skill '${wrapperPath}' does not match the canonical SKILL.md at '${skillFile}'.`);
|
|
380
|
+
}
|
|
352
381
|
writeGeneratedMarker(wrapperPath, input.companySlug, input.skillSlug);
|
|
353
382
|
pruneStaleNamespacedWrappers(runtimeRoot, wrapperName, input.hqRoot, input.companySlug, win32);
|
|
354
383
|
if (input.legacyPrefix) {
|