@indigoai-us/hq-cli 5.345.215 → 5.345.218
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 +168 -0
- package/README.md +46 -1
- package/assets/bot-workers/setup/skills/add-a-pack.md +3 -3
- package/assets/scaffold/core/scripts/hq-session.sh +4 -0
- package/assets/scaffold/core/scripts/lib/epochrealtime.sh +30 -0
- package/assets/scaffold/core/scripts/lib/work-mesh-enqueue.sh +12 -5
- package/dist/command-catalog.generated.d.ts +59 -4
- package/dist/command-catalog.generated.js +74 -4
- package/dist/command-help.js +3 -1
- package/dist/command-registration-plan.d.ts +6 -0
- package/dist/command-registration-plan.js +1 -0
- package/dist/commands/auth.d.ts +1 -1
- package/dist/commands/auth.js +11 -52
- package/dist/commands/bot.js +11 -4
- package/dist/commands/cloud-demote.d.ts +19 -4
- package/dist/commands/cloud-demote.js +85 -12
- package/dist/commands/cloud-provision.d.ts +5 -1
- package/dist/commands/cloud-provision.js +6 -2
- package/dist/commands/cloud.d.ts +37 -1
- package/dist/commands/cloud.js +110 -27
- package/dist/commands/core-hq-session-native.js +3 -0
- package/dist/commands/core.js +1 -0
- package/dist/commands/daemon.js +4 -1
- package/dist/commands/dm.js +7 -0
- package/dist/commands/doctor-usage.d.ts +8 -0
- package/dist/commands/doctor-usage.js +20 -0
- package/dist/commands/doctor.js +7 -1
- package/dist/commands/env.d.ts +18 -0
- package/dist/commands/env.js +82 -0
- package/dist/commands/install-global.js +3 -3
- package/dist/commands/lanes.js +100 -24
- package/dist/commands/logout.d.ts +7 -0
- package/dist/commands/logout.js +41 -34
- package/dist/commands/members.js +1 -1
- package/dist/commands/pack-start-bot.d.ts +1 -1
- package/dist/commands/pack-start-bot.js +2 -2
- package/dist/commands/pkg-update.js +1 -1
- package/dist/commands/sources.d.ts +8 -2
- package/dist/commands/sources.js +65 -9
- package/dist/commands/sync-narrow.js +1 -1
- package/dist/commands/team-sync.js +1 -1
- package/dist/commands/whoami.js +26 -1
- package/dist/data/command-states.json +22 -0
- package/dist/index.js +52 -4
- package/dist/lazy-commands.js +2 -1
- package/dist/lib/anywhere-person-setting.d.ts +2 -0
- package/dist/lib/anywhere-person-setting.js +6 -3
- package/dist/lib/billing/usage-card.d.ts +25 -4
- package/dist/lib/billing/usage-card.js +76 -9
- package/dist/lib/billing/usage-cost.d.ts +3 -3
- package/dist/lib/billing/usage-cost.js +40 -15
- package/dist/lib/billing/usage-only.js +4 -2
- package/dist/lib/billing/usage-rate-card.d.ts +2 -2
- package/dist/lib/billing/usage-rate-card.js +3 -0
- package/dist/lib/bot/fleet-cron.js +93 -6
- package/dist/lib/bot/inflight.d.ts +9 -0
- package/dist/lib/bot/inflight.js +10 -0
- package/dist/lib/bot/jobs/hot-signal-sync.js +12 -1
- package/dist/lib/bot/pack-link.d.ts +2 -2
- package/dist/lib/bot/pack-link.js +2 -2
- package/dist/lib/bot/runtime/grok-acp.d.ts +1 -0
- package/dist/lib/bot/runtime/grok-acp.js +26 -11
- package/dist/lib/bot/runtime/grok.js +1 -1
- package/dist/lib/daemon/flag-monitor.d.ts +8 -0
- package/dist/lib/daemon/flag-monitor.js +17 -6
- package/dist/lib/daemon/flag.d.ts +65 -1
- package/dist/lib/daemon/flag.js +190 -40
- package/dist/lib/daemon/hook-env.d.ts +32 -0
- package/dist/lib/daemon/hook-env.js +51 -0
- package/dist/lib/daemon/ops/policy.js +67 -8
- package/dist/lib/daemon/paths.d.ts +72 -2
- package/dist/lib/daemon/paths.js +154 -3
- package/dist/lib/daemon/run.js +32 -21
- package/dist/lib/daemon/selfcheck.d.ts +22 -0
- package/dist/lib/daemon/selfcheck.js +40 -1
- package/dist/lib/daemon/server.d.ts +3 -1
- package/dist/lib/daemon/server.js +7 -22
- package/dist/lib/daemon/state-file-switch.d.ts +57 -0
- package/dist/lib/daemon/state-file-switch.js +88 -0
- package/dist/lib/daemon/state-file.d.ts +198 -0
- package/dist/lib/daemon/state-file.js +419 -0
- package/dist/lib/daemon/timed-flag-monitors.d.ts +47 -0
- package/dist/lib/daemon/timed-flag-monitors.js +75 -0
- package/dist/lib/doctor/checks/host-core.d.ts +52 -0
- package/dist/lib/doctor/checks/host-core.js +337 -0
- package/dist/lib/doctor/checks/replay-recorder.d.ts +39 -0
- package/dist/lib/doctor/checks/replay-recorder.js +261 -0
- package/dist/lib/doctor/checks/sync-runtime.js +3 -3
- package/dist/lib/doctor/registry.js +4 -0
- package/dist/lib/environment/credential-shapes.d.ts +61 -0
- package/dist/lib/environment/credential-shapes.js +333 -0
- package/dist/lib/environment/profile.d.ts +239 -0
- package/dist/lib/environment/profile.js +239 -0
- package/dist/lib/hook-engine/coverage.d.ts +13 -0
- package/dist/lib/hook-engine/coverage.js +124 -0
- package/dist/lib/hook-engine/reconcile.js +300 -94
- package/dist/lib/hook-engine/registration.d.ts +17 -1
- package/dist/lib/hook-engine/registration.js +62 -7
- package/dist/lib/hot-channels/adapters/slack.d.ts +21 -5
- package/dist/lib/hot-channels/adapters/slack.js +64 -21
- package/dist/lib/hot-channels/alert.d.ts +2 -0
- package/dist/lib/hot-channels/alert.js +8 -1
- package/dist/lib/hot-channels/contract.d.ts +12 -0
- package/dist/lib/hot-channels/contract.js +7 -0
- package/dist/lib/hot-channels/loop.js +1 -0
- package/dist/lib/hot-channels/run.d.ts +6 -0
- package/dist/lib/hot-channels/run.js +4 -0
- package/dist/lib/hot-channels/signals-pass.d.ts +64 -1
- package/dist/lib/hot-channels/signals-pass.js +21 -49
- package/dist/lib/install/claude-targets.d.ts +12 -1
- package/dist/lib/install/claude-targets.js +70 -5
- package/dist/lib/install/codex-pack-contributions.js +1 -1
- package/dist/lib/install/codex-targets.d.ts +2 -2
- package/dist/lib/install/codex-targets.js +48 -5
- package/dist/lib/install/hook-target.d.ts +4 -1
- package/dist/lib/install/hook-target.js +14 -1
- package/dist/lib/lanes/canonical-host.d.ts +35 -0
- package/dist/lib/lanes/canonical-host.js +65 -0
- package/dist/lib/lanes/host-capacity.d.ts +30 -0
- package/dist/lib/lanes/host-capacity.js +29 -3
- package/dist/lib/mesh/live/daemon/run.d.ts +2 -0
- package/dist/lib/mesh/live/daemon/run.js +5 -2
- package/dist/lib/mesh/live/flush.d.ts +5 -1
- package/dist/lib/mesh/live/flush.js +12 -6
- package/dist/lib/mesh/live/reporting-privacy.d.ts +32 -0
- package/dist/lib/mesh/live/reporting-privacy.js +56 -1
- package/dist/lib/mesh/live/spool.d.ts +7 -0
- package/dist/lib/mesh/live/spool.js +25 -0
- package/dist/lib/packages/setup-block.d.ts +2 -2
- package/dist/lib/packages/setup-block.js +2 -2
- package/dist/lib/packages/start-bot.d.ts +1 -1
- package/dist/lib/packages/start-bot.js +1 -1
- package/dist/lib/person-setting-cache.d.ts +38 -0
- package/dist/lib/person-setting-cache.js +98 -0
- package/dist/lib/safe-store.d.ts +245 -0
- package/dist/lib/safe-store.js +777 -0
- package/dist/lib/signals/engine.d.ts +29 -2
- package/dist/lib/signals/engine.js +103 -4
- package/dist/lib/signals/reply.js +73 -18
- package/dist/lib/signals/steps/adapters.js +7 -2
- package/dist/lib/signals/steps/extract.d.ts +13 -0
- package/dist/lib/signals/steps/extract.js +84 -4
- package/dist/main.js +47 -4
- package/dist/schemas/hq-environment-profile.v1.schema.json +438 -0
- package/dist/types.d.ts +1 -1
- package/dist/utils/auth-expiry.d.ts +8 -0
- package/dist/utils/auth-expiry.js +53 -0
- package/dist/utils/callback-port-busy.d.ts +1 -1
- package/dist/utils/callback-port-busy.js +4 -4
- package/dist/utils/cli-telemetry.d.ts +21 -0
- package/dist/utils/cli-telemetry.js +34 -0
- package/dist/utils/command-usage.d.ts +275 -0
- package/dist/utils/command-usage.js +797 -0
- package/dist/utils/hook-trust.d.ts +7 -0
- package/dist/utils/hook-trust.js +34 -4
- package/dist/utils/host-registration.d.ts +179 -0
- package/dist/utils/host-registration.js +505 -0
- package/dist/utils/resident-package-preload.js +2 -0
- package/package.json +10 -8
- package/scripts/bench-core.mjs +1096 -0
- package/scripts/check-function-manifest.mjs +702 -0
|
@@ -5,6 +5,7 @@ import { effectiveBotCompanies, effectiveBotKind } from "./config.js";
|
|
|
5
5
|
import { fleetLocalRuntimePython, stderrTail } from "./fleet-local.js";
|
|
6
6
|
import { readLocalJobs, withJobsLock, writeLocalJobs } from "./local-jobs.js";
|
|
7
7
|
import { signInCommand } from "./runtime-sign-in.js";
|
|
8
|
+
import { SIGNALS_FAILURE_PREFIX } from "../hot-channels/alert.js";
|
|
8
9
|
import { currentHotSignalSyncCompany, forgetHotSignalSyncRegistrationsExcept, hotSignalSyncJobCompany, fleetHotSignalSyncRegistered, markFleetHotSignalSyncRegistered, otherBotWithHotSignalSync, } from "./jobs/hot-signal-sync.js";
|
|
9
10
|
const RESULT_MARKER = "@@HQ_FLEET_CRON@@";
|
|
10
11
|
export const FLEET_CRON_BRIDGE = [
|
|
@@ -340,6 +341,9 @@ def classify(out, err, code):
|
|
|
340
341
|
text = ANSI.sub('', (err or '') + '\n' + (out or ''))
|
|
341
342
|
if re.search(r"HQ session has expired|not signed in to HQ|Sign in to HQ first|run .hq login", text, re.I):
|
|
342
343
|
return 'you are signed out of HQ', FIXES['hq_signed_out']
|
|
344
|
+
# Before the plain claude checks: a Codex main bot is told why Claude Code is needed.
|
|
345
|
+
if re.search(r'claude-logged-out-codex-bot', text, re.I):
|
|
346
|
+
return "your main bot runs on Codex, but signals from hot-channel sync need Claude Code, which is not installed or not signed in on this computer", FIXES['codex_bot_needs_claude']
|
|
343
347
|
if re.search(r'claude could not start:.*\bENOENT\b|spawn claude ENOENT', text, re.I):
|
|
344
348
|
return 'Claude Code is not installed on this computer', FIXES['claude_missing']
|
|
345
349
|
if re.search(r'claude-logged-out|claude (reported it )?is not logged in|claude could not start', text, re.I):
|
|
@@ -350,12 +354,48 @@ def classify(out, err, code):
|
|
|
350
354
|
if re.match(r'^sources/[A-Za-z0-9._/-]+\.md$', key) and '..' not in key:
|
|
351
355
|
return 'Claude ran out of time on one document', FIXES['claude_timeout_key'].replace('KEY', key)
|
|
352
356
|
return 'Claude ran out of time on one document', FIXES['claude_timeout']
|
|
357
|
+
# The other signals-pass codes; the run ledger stores the bare code as the error.
|
|
358
|
+
if re.search(r'claude-usage-limit|claude is out of usage', text, re.I):
|
|
359
|
+
return 'Claude is out of usage on this account', FIXES['claude_usage_limit']
|
|
360
|
+
if re.search(r'claude-bad-output', text, re.I):
|
|
361
|
+
return 'Claude gave replies the signals step could not read', FIXES['claude_bad_output']
|
|
362
|
+
if re.search(r'claude-provider-error', text, re.I):
|
|
363
|
+
return 'Claude reported an error', FIXES['claude_provider_error']
|
|
353
364
|
if re.search(r'fetch failed|ENOTFOUND|ECONNREFUSED|ECONNRESET|EAI_AGAIN|ETIMEDOUT|ENETUNREACH|EHOSTUNREACH|socket hang up', text, re.I):
|
|
354
365
|
return 'HQ could not reach the network', FIXES['network']
|
|
355
366
|
line = last_error_line(out, err)
|
|
356
367
|
if line:
|
|
357
368
|
return line, FIXES['other']
|
|
358
|
-
|
|
369
|
+
if output_lines(out) or output_lines(err):
|
|
370
|
+
return 'hq stopped with exit code %d and printed no error (its output is in the log)' % code, FIXES['unknown']
|
|
371
|
+
return 'hq stopped with exit code %d and printed nothing' % code, FIXES['unknown']
|
|
372
|
+
`;
|
|
373
|
+
/**
|
|
374
|
+
* Python helper for the flag-off script: the signals-failure alerts that
|
|
375
|
+
* `hq sources sync` printed to stderr on a run that still exited 0 (the text
|
|
376
|
+
* of formatSignalsFailureAlert in lib/hot-channels/alert.ts, found by
|
|
377
|
+
* SIGNALS_FAILURE_PREFIX anywhere in a line, so a prefix the writer adds does
|
|
378
|
+
* not hide it). Only alerts with an "Error:" line count: the signals pass or
|
|
379
|
+
* the channel failed. A clean run that found no signals has no error and stays
|
|
380
|
+
* in the log. Returns one "<adapter> landed N sources and generated M signals"
|
|
381
|
+
* per failed alert and their errors. The connection id and the person are left out.
|
|
382
|
+
*/
|
|
383
|
+
const HOT_SIGNAL_SYNC_SIGNALS_FAILURES = String.raw `SIGNALS_FAILURE = re.compile(re.escape(SIGNALS_FAILURE_PREFIX) + r'.*?: (\S+)(?: \([^)]*\))? landed (\d+ sources?) and generated (\d+ signals?)\.$')
|
|
384
|
+
ALERT_ERROR = re.compile(r'^\W*Error: (.+)$')
|
|
385
|
+
|
|
386
|
+
def signals_failures(err):
|
|
387
|
+
found, errors = [], []
|
|
388
|
+
lines = output_lines(err)
|
|
389
|
+
for i, line in enumerate(lines):
|
|
390
|
+
m = SIGNALS_FAILURE.search(line)
|
|
391
|
+
if not m:
|
|
392
|
+
continue
|
|
393
|
+
error = next((e.group(1) for e in (ALERT_ERROR.match(f) for f in lines[i + 1:i + 3]) if e), '')
|
|
394
|
+
if not error:
|
|
395
|
+
continue
|
|
396
|
+
found.append('%s landed %s and generated %s' % (m.group(1), m.group(2), m.group(3)))
|
|
397
|
+
errors.append(error)
|
|
398
|
+
return found, errors
|
|
359
399
|
`;
|
|
360
400
|
/** How a run ended, for the log line after it: `exit 1` or `signal 9`. */
|
|
361
401
|
const HOT_SIGNAL_SYNC_RUN_END = String.raw `def run_end(code):
|
|
@@ -388,13 +428,19 @@ const HOT_SIGNAL_SYNC_HQ_ARGV = String.raw `def hq_argv():
|
|
|
388
428
|
`;
|
|
389
429
|
export function renderFleetHotSignalSyncScript(input) {
|
|
390
430
|
const plainSync = input.signalsEngine === false;
|
|
431
|
+
// The plain sync's ledger lines record `scheduled` for this job. The CLI
|
|
432
|
+
// that writes this script runs it (HQ is its own entry), but a fallback
|
|
433
|
+
// launcher can be an older hq without --trigger; the script then runs
|
|
434
|
+
// LEGACY_ARGS, the same command without it.
|
|
435
|
+
const legacyArgs = ["sources", "sync", "--company", input.company, "--hq-root", input.hqRoot];
|
|
391
436
|
const args = plainSync
|
|
392
|
-
? ["sources", "sync", "--company", input.company, "--hq-root", input.hqRoot]
|
|
437
|
+
? ["sources", "sync", "--trigger", "scheduled", "--company", input.company, "--hq-root", input.hqRoot]
|
|
393
438
|
: ["signals", "run", "--trigger", "job", "--company", input.company, "--hq-root", input.hqRoot, "--report-found"];
|
|
394
439
|
const syncCommand = `hq sources sync --company ${input.company}`;
|
|
395
440
|
const fixes = {
|
|
396
441
|
hq_signed_out: "run `hq login`.",
|
|
397
442
|
claude_signed_out: `run \`${signInCommand("claude")}\`.`,
|
|
443
|
+
codex_bot_needs_claude: `sign in to Claude Code here (\`${signInCommand("claude")}\`).`,
|
|
398
444
|
claude_missing: `install Claude Code (\`npm install -g @anthropic-ai/claude-code\`), then run \`${signInCommand("claude")}\`.`,
|
|
399
445
|
claude_timeout_key: `run \`hq sources signals --company ${input.company} --key KEY\` to retry that document.`,
|
|
400
446
|
claude_timeout: "the next run retries the document.",
|
|
@@ -402,6 +448,10 @@ export function renderFleetHotSignalSyncScript(input) {
|
|
|
402
448
|
signal: `run \`${syncCommand}\` to see whether it happens again.`,
|
|
403
449
|
other: `run \`${syncCommand}\` to see the full error.`,
|
|
404
450
|
unknown: `run \`${syncCommand}\` to see what goes wrong.`,
|
|
451
|
+
// DATE becomes the run's date when the script starts.
|
|
452
|
+
claude_usage_limit: `wait for your Claude usage to reset, then run \`hq sources signals --company ${input.company} --since DATE\` to build the missing signals.`,
|
|
453
|
+
claude_bad_output: `run \`hq sources signals --company ${input.company} --since DATE\` to try those documents again.`,
|
|
454
|
+
claude_provider_error: `run \`hq sources signals --company ${input.company} --since DATE\` to try again and see the full error.`,
|
|
405
455
|
};
|
|
406
456
|
// One header per run, so an alert's start time finds its entry in the log,
|
|
407
457
|
// and one line after it with how the run ended.
|
|
@@ -414,7 +464,12 @@ export function renderFleetHotSignalSyncScript(input) {
|
|
|
414
464
|
// failed, with the job's time, the reason, one fix step and the log. The
|
|
415
465
|
// plain script exits non-zero after a failed run (128 + N after signal N, as
|
|
416
466
|
// a shell does), so the job's status is not `ok`: Fleet records a no-agent
|
|
417
|
-
// job from its exit code.
|
|
467
|
+
// job from its exit code. A run that exits 0 after its signals pass failed
|
|
468
|
+
// prints the signals-failure alert to stderr only, since the CLI has no DM
|
|
469
|
+
// sender; the script finds that alert and sends the owner the same three
|
|
470
|
+
// lines (US-018 AC1). A clean run that landed sources and found no signals
|
|
471
|
+
// also raises the alert, but with no error; it stays in the log. The exit
|
|
472
|
+
// code stays 0: the sync itself finished.
|
|
418
473
|
const launcher = input.hqLauncher ?? fleetPnpmHqLauncher(input.hqBinary);
|
|
419
474
|
// HQ is often the pnpm hash folder's dist/index.js. That path dies on the
|
|
420
475
|
// next CLI update (feedback_614121bf). Prefer it while it exists so tests
|
|
@@ -422,11 +477,22 @@ export function renderFleetHotSignalSyncScript(input) {
|
|
|
422
477
|
// launcher without node (it is a shell/cmd shim, not JS).
|
|
423
478
|
const run = plainSync
|
|
424
479
|
? [
|
|
425
|
-
"
|
|
480
|
+
" command = hq_argv() + ARGS",
|
|
481
|
+
" result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8', errors='replace')",
|
|
482
|
+
" note = ''",
|
|
483
|
+
// Commander rejects the option before the sync starts, so the retry is
|
|
484
|
+
// the only run that does any work.
|
|
485
|
+
" if result.returncode != 0 and \"unknown option '--trigger'\" in result.stderr:",
|
|
486
|
+
" note = 'This hq has no --trigger option; ran the sync without it.\\n'",
|
|
487
|
+
" command = hq_argv() + LEGACY_ARGS",
|
|
488
|
+
" result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8', errors='replace')",
|
|
426
489
|
" with open(LOG, 'a', encoding='utf-8') as log:",
|
|
427
490
|
header,
|
|
491
|
+
" log.write(note)",
|
|
428
492
|
" log.write(result.stderr)",
|
|
429
493
|
" log.write(result.stdout)",
|
|
494
|
+
" if result.returncode != 0 and not output_lines(result.stderr) and not output_lines(result.stdout):",
|
|
495
|
+
" log.write('hq printed nothing. Command: ' + shlex.join(command) + '\\n')",
|
|
430
496
|
footer,
|
|
431
497
|
" if result.returncode != 0:",
|
|
432
498
|
" reason, fix = classify(result.stdout, result.stderr, result.returncode)",
|
|
@@ -434,6 +500,18 @@ export function renderFleetHotSignalSyncScript(input) {
|
|
|
434
500
|
" sys.stdout.write('Fix: ' + fix + '\\n')",
|
|
435
501
|
" sys.stdout.write('Log: ' + LOG + ' (run started ' + time.strftime('%Y-%m-%d %H:%M', STARTED) + ')\\n')",
|
|
436
502
|
" sys.exit(128 - result.returncode if result.returncode < 0 else result.returncode)",
|
|
503
|
+
" found, errors = signals_failures(result.stderr)",
|
|
504
|
+
" if found:",
|
|
505
|
+
" reasons, fixes = [], []",
|
|
506
|
+
" for error in errors:",
|
|
507
|
+
" reason, fix = classify('', error, 1)",
|
|
508
|
+
" if reason not in reasons:",
|
|
509
|
+
" reasons.append(reason)",
|
|
510
|
+
" if fix not in fixes:",
|
|
511
|
+
" fixes.append(fix)",
|
|
512
|
+
` sys.stdout.write('The ' + scheduled_time() + ${JSON.stringify(` hot-channel sync for ${input.company} landed sources but the signals step failed: `)} + '; '.join(found) + '. Cause: ' + '; '.join(reasons) + '.\\n')`,
|
|
513
|
+
" sys.stdout.write('Fix: ' + ' Also, '.join(fixes) + '\\n')",
|
|
514
|
+
" sys.stdout.write('Log: ' + LOG + ' (run started ' + time.strftime('%Y-%m-%d %H:%M', STARTED) + ')\\n')",
|
|
437
515
|
]
|
|
438
516
|
: [
|
|
439
517
|
" with open(LOG, 'a', encoding='utf-8') as log:",
|
|
@@ -444,7 +522,7 @@ export function renderFleetHotSignalSyncScript(input) {
|
|
|
444
522
|
" sys.stdout.write(result.stdout)",
|
|
445
523
|
];
|
|
446
524
|
return [
|
|
447
|
-
plainSync ? "import json, os, re, shutil, signal, subprocess, sys, time, urllib.parse" : "import os, shutil, subprocess, sys, time",
|
|
525
|
+
plainSync ? "import json, os, re, shlex, shutil, signal, subprocess, sys, time, urllib.parse" : "import os, shutil, subprocess, sys, time",
|
|
448
526
|
`NODE = ${JSON.stringify(input.nodeBinary)}`,
|
|
449
527
|
`HQ = ${JSON.stringify(input.hqBinary)}`,
|
|
450
528
|
`LAUNCHER = ${JSON.stringify(launcher)}`,
|
|
@@ -453,7 +531,16 @@ export function renderFleetHotSignalSyncScript(input) {
|
|
|
453
531
|
"STARTED = time.localtime()",
|
|
454
532
|
HOT_SIGNAL_SYNC_RUN_END,
|
|
455
533
|
HOT_SIGNAL_SYNC_HQ_ARGV,
|
|
456
|
-
...(plainSync
|
|
534
|
+
...(plainSync
|
|
535
|
+
? [
|
|
536
|
+
`LEGACY_ARGS = ${JSON.stringify(legacyArgs)}`,
|
|
537
|
+
`FIXES = ${JSON.stringify(fixes)}`,
|
|
538
|
+
"FIXES = dict((k, v.replace('DATE', time.strftime('%Y-%m-%d', STARTED))) for k, v in FIXES.items())",
|
|
539
|
+
HOT_SIGNAL_SYNC_ALERT_HELPERS,
|
|
540
|
+
`SIGNALS_FAILURE_PREFIX = ${JSON.stringify(SIGNALS_FAILURE_PREFIX)}`,
|
|
541
|
+
HOT_SIGNAL_SYNC_SIGNALS_FAILURES,
|
|
542
|
+
]
|
|
543
|
+
: []),
|
|
457
544
|
"try:",
|
|
458
545
|
...run,
|
|
459
546
|
"except OSError as exc:",
|
|
@@ -112,6 +112,15 @@ export interface InflightTurn {
|
|
|
112
112
|
silenceable?: boolean;
|
|
113
113
|
}
|
|
114
114
|
export declare function botInflightPath(dir: string): string;
|
|
115
|
+
/**
|
|
116
|
+
* Whether a bot is answering right now. A legacy runner records each turn in
|
|
117
|
+
* its in-flight marker; an HQ Fleet gateway only reports how many turns it is
|
|
118
|
+
* running (`active_agents`), so its start time is unknown.
|
|
119
|
+
*/
|
|
120
|
+
export declare function botBusyState(processAlive: boolean, turns: readonly InflightTurn[], fleetActiveTurns?: number): {
|
|
121
|
+
busy: boolean;
|
|
122
|
+
busySince: string | null;
|
|
123
|
+
};
|
|
115
124
|
/** Every turn that was in progress, oldest first. */
|
|
116
125
|
export declare function readInflightTurns(dir: string, options?: {
|
|
117
126
|
strictIo?: boolean;
|
package/dist/lib/bot/inflight.js
CHANGED
|
@@ -23,6 +23,16 @@ function isTurn(raw) {
|
|
|
23
23
|
const t = raw;
|
|
24
24
|
return t?.v === 1 && typeof t.messageId === "string" && Boolean(t.target);
|
|
25
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Whether a bot is answering right now. A legacy runner records each turn in
|
|
28
|
+
* its in-flight marker; an HQ Fleet gateway only reports how many turns it is
|
|
29
|
+
* running (`active_agents`), so its start time is unknown.
|
|
30
|
+
*/
|
|
31
|
+
export function botBusyState(processAlive, turns, fleetActiveTurns = 0) {
|
|
32
|
+
if (!processAlive)
|
|
33
|
+
return { busy: false, busySince: null };
|
|
34
|
+
return { busy: turns.length > 0 || fleetActiveTurns > 0, busySince: turns[0]?.startedAt ?? null };
|
|
35
|
+
}
|
|
26
36
|
/** Every turn that was in progress, oldest first. */
|
|
27
37
|
export function readInflightTurns(dir, options = {}) {
|
|
28
38
|
try {
|
|
@@ -38,7 +38,7 @@ import * as fs from "node:fs";
|
|
|
38
38
|
import * as path from "node:path";
|
|
39
39
|
import { signalsAlertKey } from "../../hot-channels/alert.js";
|
|
40
40
|
import { JOB_RUN_OPTIONS_CONTEXT_KEY } from "../job-run.js";
|
|
41
|
-
import { localDate, runRecordRel } from "../../signals/engine.js";
|
|
41
|
+
import { localDate, raiseStoppedRunAlert, runRecordRel } from "../../signals/engine.js";
|
|
42
42
|
import { formatJobErrorReply, formatLockedReply, formatRunReply, timeInWords } from "../../signals/reply.js";
|
|
43
43
|
import { effectiveBotCompanies, effectiveBotKind, readBotConfig } from "../config.js";
|
|
44
44
|
import { ensureLocalJob, readLocalJobs, removeLocalJobsWhere, withJobsLock } from "../local-jobs.js";
|
|
@@ -377,6 +377,17 @@ async function runSignalsEngineJob(input) {
|
|
|
377
377
|
return { ok: false, text: reply.text, report: null, reply };
|
|
378
378
|
}
|
|
379
379
|
const timeZone = input.timeZone ?? "UTC";
|
|
380
|
+
// US-018 AC1: a run that hung or died left today's record `running` (or
|
|
381
|
+
// `failed` with no alert sent), and the end-of-run alert never fired for it.
|
|
382
|
+
// Check it before this run replaces the record; one alert per stopped run.
|
|
383
|
+
// Yesterday's record is checked too: a hung morning run usually has no
|
|
384
|
+
// later fire that day, so the next morning's fire is the first to see it.
|
|
385
|
+
if (input.sendAlert) {
|
|
386
|
+
const senders = { sendOwnerDm: input.sendAlert, ...(input.log ? { log: input.log } : {}) };
|
|
387
|
+
for (const daysAgo of [1, 0]) {
|
|
388
|
+
await raiseStoppedRunAlert({ hqRoot: input.hqRoot, company: input.company, now: input.now, senders, daysAgo });
|
|
389
|
+
}
|
|
390
|
+
}
|
|
380
391
|
if (input.retry) {
|
|
381
392
|
const today = readTodaysRecord(input.hqRoot, input.company, input.now());
|
|
382
393
|
if (today && (today.status === "complete" || today.status === "partial")) {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* "add the {Display Name}" a display name from the catalog
|
|
11
11
|
* ./packs/hq-pack-{slug}, ~/Downloads/hq-pack-{slug} a local pack folder
|
|
12
12
|
*
|
|
13
|
-
* The catalog is the curated list `hq
|
|
13
|
+
* The catalog is the curated list `hq packs list` prints (core.yaml
|
|
14
14
|
* `recommended_packages`, see readRecommendedPackages). A slug or display name
|
|
15
15
|
* that matches none of its entries is `unknown`, with the three closest
|
|
16
16
|
* catalog names to offer. Nothing here knows any particular pack.
|
|
@@ -34,7 +34,7 @@ export type PackReference = {
|
|
|
34
34
|
kind: PackReferenceKind;
|
|
35
35
|
slug: string;
|
|
36
36
|
displayName: string;
|
|
37
|
-
/** What to hand `hq
|
|
37
|
+
/** What to hand `hq install`: the slug, or the local path when the message carried one. */
|
|
38
38
|
installSource: string;
|
|
39
39
|
entry?: PackCatalogEntry;
|
|
40
40
|
} | {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* "add the {Display Name}" a display name from the catalog
|
|
11
11
|
* ./packs/hq-pack-{slug}, ~/Downloads/hq-pack-{slug} a local pack folder
|
|
12
12
|
*
|
|
13
|
-
* The catalog is the curated list `hq
|
|
13
|
+
* The catalog is the curated list `hq packs list` prints (core.yaml
|
|
14
14
|
* `recommended_packages`, see readRecommendedPackages). A slug or display name
|
|
15
15
|
* that matches none of its entries is `unknown`, with the three closest
|
|
16
16
|
* catalog names to offer. Nothing here knows any particular pack.
|
|
@@ -148,6 +148,6 @@ export function packConfirmSuggestions(displayName) {
|
|
|
148
148
|
/** The exact command the setup bot runs after "Add the ...". */
|
|
149
149
|
export function packInstallCommand(installSource) {
|
|
150
150
|
const arg = /[\s"']/.test(installSource) ? JSON.stringify(installSource) : installSource;
|
|
151
|
-
return `hq
|
|
151
|
+
return `hq install ${arg} --start-bot`;
|
|
152
152
|
}
|
|
153
153
|
//# sourceMappingURL=pack-link.js.map
|
|
@@ -9,6 +9,7 @@ export class GrokAcpClient {
|
|
|
9
9
|
terminals = new Map();
|
|
10
10
|
sessionId;
|
|
11
11
|
text = "";
|
|
12
|
+
prompting = false;
|
|
12
13
|
finished = false;
|
|
13
14
|
constructor(options) {
|
|
14
15
|
this.options = options;
|
|
@@ -16,7 +17,8 @@ export class GrokAcpClient {
|
|
|
16
17
|
start() {
|
|
17
18
|
this.request("initialize", {
|
|
18
19
|
protocolVersion: 1,
|
|
19
|
-
|
|
20
|
+
// Grok 1.0.77 fails to deserialize terminal/* replies when this is true.
|
|
21
|
+
clientCapabilities: {},
|
|
20
22
|
}, (result) => this.authenticate(result));
|
|
21
23
|
}
|
|
22
24
|
receive(line) {
|
|
@@ -86,11 +88,19 @@ export class GrokAcpClient {
|
|
|
86
88
|
this.request("session/new", { cwd: this.options.cwd, mcpServers: [], _meta: { yoloMode: true } }, (result) => this.prompt(result));
|
|
87
89
|
}
|
|
88
90
|
prompt(result) {
|
|
89
|
-
|
|
91
|
+
const sessionId = typeof result.sessionId === "string" && result.sessionId
|
|
92
|
+
? result.sessionId
|
|
93
|
+
: this.options.sessionId;
|
|
94
|
+
if (!sessionId) {
|
|
90
95
|
this.fail("Grok ACP did not return a session ID");
|
|
91
96
|
return;
|
|
92
97
|
}
|
|
93
|
-
this.sessionId =
|
|
98
|
+
this.sessionId = sessionId;
|
|
99
|
+
// session/load replays the earlier conversation as agent_message_chunk
|
|
100
|
+
// updates before it answers. Start the reply buffer empty so only this
|
|
101
|
+
// turn's text is posted.
|
|
102
|
+
this.text = "";
|
|
103
|
+
this.prompting = true;
|
|
94
104
|
this.request("session/prompt", { sessionId: this.sessionId, prompt: [{ type: "text", text: this.options.prompt }] }, (response) => this.complete(response));
|
|
95
105
|
}
|
|
96
106
|
receiveUpdate(message) {
|
|
@@ -99,13 +109,10 @@ export class GrokAcpClient {
|
|
|
99
109
|
const content = update.content && typeof update.content === "object" ? update.content : {};
|
|
100
110
|
if (update.sessionUpdate !== "agent_message_chunk" || typeof content.text !== "string")
|
|
101
111
|
return;
|
|
112
|
+
// Ignore history replayed during session/load, before the prompt is sent.
|
|
113
|
+
if (!this.prompting)
|
|
114
|
+
return;
|
|
102
115
|
this.text += content.text;
|
|
103
|
-
this.options.onText(JSON.stringify({
|
|
104
|
-
type: "assistant",
|
|
105
|
-
message: { role: "assistant", content: [{ type: "text", text: content.text }] },
|
|
106
|
-
parent_tool_use_id: null,
|
|
107
|
-
session_id: this.sessionId,
|
|
108
|
-
}));
|
|
109
116
|
}
|
|
110
117
|
complete(response) {
|
|
111
118
|
if (!this.sessionId) {
|
|
@@ -117,6 +124,14 @@ export class GrokAcpClient {
|
|
|
117
124
|
return;
|
|
118
125
|
}
|
|
119
126
|
this.finished = true;
|
|
127
|
+
if (this.text) {
|
|
128
|
+
this.options.onText(JSON.stringify({
|
|
129
|
+
type: "assistant",
|
|
130
|
+
message: { role: "assistant", content: [{ type: "text", text: this.text }] },
|
|
131
|
+
parent_tool_use_id: null,
|
|
132
|
+
session_id: this.sessionId,
|
|
133
|
+
}));
|
|
134
|
+
}
|
|
120
135
|
this.notify("exit");
|
|
121
136
|
this.options.onComplete(this.sessionId, this.text);
|
|
122
137
|
}
|
|
@@ -153,8 +168,8 @@ export class GrokAcpClient {
|
|
|
153
168
|
return typeof candidate.optionId === "string" && /allow|approve/i.test(String(candidate.kind ?? candidate.name ?? ""));
|
|
154
169
|
});
|
|
155
170
|
if (!allow || typeof allow.optionId !== "string")
|
|
156
|
-
return { outcome: "cancelled" };
|
|
157
|
-
return { outcome: "selected", optionId: allow.optionId };
|
|
171
|
+
return { outcome: { outcome: "cancelled" } };
|
|
172
|
+
return { outcome: { outcome: "selected", optionId: allow.optionId } };
|
|
158
173
|
}
|
|
159
174
|
if (shortMethod === "terminal/create")
|
|
160
175
|
return this.createTerminal(params);
|
|
@@ -112,7 +112,7 @@ export function createGrokRuntime(opts = {}) {
|
|
|
112
112
|
resolveBinary: (env, cwd, platform) => resolveRuntimeBinary("grok", env, platform ?? process.platform, undefined, cwd),
|
|
113
113
|
buildArgs(input) {
|
|
114
114
|
if (input.platform === "win32") {
|
|
115
|
-
const args = ["--no-auto-update", "agent", "--always-approve"
|
|
115
|
+
const args = ["--no-auto-update", "agent", "--always-approve"];
|
|
116
116
|
if (input.model)
|
|
117
117
|
args.push("--model", input.model);
|
|
118
118
|
args.push("--effort", input.effort?.trim() || "medium");
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/** How often every daemon flag monitor asks the registry again. */
|
|
2
|
+
export declare const DAEMON_FLAG_REFRESH_INTERVAL_MS = 30000;
|
|
1
3
|
export interface BoundedDaemonFlagMonitorOptions {
|
|
2
4
|
read: () => Promise<boolean>;
|
|
3
5
|
/** Registry default, also used for absent rows and stale reads. */
|
|
@@ -5,6 +7,12 @@ export interface BoundedDaemonFlagMonitorOptions {
|
|
|
5
7
|
now?: () => number;
|
|
6
8
|
onChange?: (enabled: boolean) => void;
|
|
7
9
|
onReadError?: (error: unknown) => void;
|
|
10
|
+
/**
|
|
11
|
+
* Run the 30-second refresh on a shared timer instead of this monitor's own,
|
|
12
|
+
* so monitors reading from one DaemonFlagSnapshotSource refresh on the same
|
|
13
|
+
* tick and share its registry request. Returns the cancel function.
|
|
14
|
+
*/
|
|
15
|
+
scheduleRefresh?: (tick: () => void) => () => void;
|
|
8
16
|
}
|
|
9
17
|
export interface BoundedDaemonFlagMonitor {
|
|
10
18
|
enabled(): Promise<boolean>;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { performance } from "node:perf_hooks";
|
|
2
|
-
|
|
2
|
+
/** How often every daemon flag monitor asks the registry again. */
|
|
3
|
+
export const DAEMON_FLAG_REFRESH_INTERVAL_MS = 30_000;
|
|
4
|
+
const HQ_ANYWHERE_FLAG_REFRESH_INTERVAL_MS = DAEMON_FLAG_REFRESH_INTERVAL_MS;
|
|
3
5
|
const HQ_ANYWHERE_FLAG_MAX_STALENESS_MS = 60_000;
|
|
4
6
|
/**
|
|
5
7
|
* Refreshes a long-running daemon's flag independently of incoming requests.
|
|
@@ -64,11 +66,21 @@ export function createBoundedDaemonFlagMonitor(options) {
|
|
|
64
66
|
});
|
|
65
67
|
return refreshInFlight;
|
|
66
68
|
};
|
|
67
|
-
const
|
|
69
|
+
const tick = () => {
|
|
70
|
+
if (closed)
|
|
71
|
+
return;
|
|
68
72
|
expireIfStale();
|
|
69
73
|
void refresh();
|
|
70
|
-
}
|
|
71
|
-
|
|
74
|
+
};
|
|
75
|
+
let cancelRefresh;
|
|
76
|
+
if (options.scheduleRefresh) {
|
|
77
|
+
cancelRefresh = options.scheduleRefresh(tick);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
const refreshTimer = setInterval(tick, HQ_ANYWHERE_FLAG_REFRESH_INTERVAL_MS);
|
|
81
|
+
refreshTimer.unref?.();
|
|
82
|
+
cancelRefresh = () => clearInterval(refreshTimer);
|
|
83
|
+
}
|
|
72
84
|
void refresh();
|
|
73
85
|
return {
|
|
74
86
|
async enabled() {
|
|
@@ -95,8 +107,7 @@ export function createBoundedDaemonFlagMonitor(options) {
|
|
|
95
107
|
},
|
|
96
108
|
close() {
|
|
97
109
|
closed = true;
|
|
98
|
-
|
|
99
|
-
clearInterval(refreshTimer);
|
|
110
|
+
cancelRefresh();
|
|
100
111
|
if (expiryTimer)
|
|
101
112
|
clearTimeout(expiryTimer);
|
|
102
113
|
},
|
|
@@ -2,17 +2,39 @@
|
|
|
2
2
|
* Feature flags read by the daemon. The daemon runs for weeks, so each read
|
|
3
3
|
* asks the registry again instead of holding a per-process answer, and it
|
|
4
4
|
* reads as each flag's fallback unless the registry or a local override decides it.
|
|
5
|
+
*
|
|
6
|
+
* The daemon's timed monitors pass one shared DaemonFlagSnapshotSource, so the
|
|
7
|
+
* flags they watch are decided from one registry request per refresh interval
|
|
8
|
+
* instead of one request per flag.
|
|
5
9
|
*/
|
|
6
|
-
import { type FlagClientOptions, type FlagResolution } from "@indigoai-us/hq-flags-client";
|
|
10
|
+
import { type FlagClientOptions, type FlagResolution, type FlagSnapshot } from "@indigoai-us/hq-flags-client";
|
|
7
11
|
/** Outposts hand running services to the next daemon on a CLI update instead of restarting them all. */
|
|
8
12
|
export declare const SUPERVISOR_HANDOFF_FLAG = "daemon.supervisor-handoff";
|
|
9
13
|
/** Self-updates build the new CLI beside the running one and swap it in, so `hq` never disappears mid-update. */
|
|
10
14
|
export declare const STAGED_SELF_UPDATE_FLAG = "cli.staged-self-update";
|
|
15
|
+
/**
|
|
16
|
+
* How long a loaded registry snapshot may answer further daemon flag reads
|
|
17
|
+
* that arrive between refresh ticks: the monitors' first reads at daemon
|
|
18
|
+
* start, a restarted hqd server's first read, and a request-driven refresh.
|
|
19
|
+
* It is the most a shared read can add to the time a flag change takes to
|
|
20
|
+
* reach one of those reads. A refresh tick never uses it: each tick discards
|
|
21
|
+
* the held snapshot and any request already in flight, so the tick's reads are
|
|
22
|
+
* decided from a request sent on that tick, as they were before sharing.
|
|
23
|
+
*
|
|
24
|
+
* One case differs from a monitor on its own timer: a monitor whose first
|
|
25
|
+
* read is still pending when the shared tick arrives skips that tick (its
|
|
26
|
+
* refresh joins its own pending read), so its next refresh is up to one
|
|
27
|
+
* pending read later than 30 seconds after its first. That applies to the hqd
|
|
28
|
+
* runtime gate just after the server starts, not to the kill switches.
|
|
29
|
+
*/
|
|
30
|
+
export declare const DAEMON_FLAG_SNAPSHOT_TTL_MS = 5000;
|
|
11
31
|
export interface DaemonFlagClient {
|
|
12
32
|
ready(): Promise<void>;
|
|
13
33
|
explain(flagKey: string, options?: {
|
|
14
34
|
fallback?: boolean;
|
|
15
35
|
}): FlagResolution;
|
|
36
|
+
/** Every flag the registry returned, for the daemon's state file. The registry client has it; a test client may not. */
|
|
37
|
+
snapshot?(): FlagSnapshot | null;
|
|
16
38
|
close(): void;
|
|
17
39
|
}
|
|
18
40
|
export interface ReadDaemonFlagOptions {
|
|
@@ -26,6 +48,48 @@ export interface ReadDaemonFlagOptions {
|
|
|
26
48
|
onError?: (error: unknown) => void;
|
|
27
49
|
/** Reject a failed registry read so the daemon monitor can distinguish it from an explicit OFF. */
|
|
28
50
|
throwOnError?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Share one registry request with the daemon's other timed flag reads. The
|
|
53
|
+
* request is made with the options of whichever read starts it, so every
|
|
54
|
+
* read on one source must use the same env, createClient and getToken.
|
|
55
|
+
*/
|
|
56
|
+
snapshots?: DaemonFlagSnapshotSource;
|
|
57
|
+
}
|
|
58
|
+
/** One registry request's outcome, before any single flag is decided from it. */
|
|
59
|
+
export interface DaemonFlagRegistryRead {
|
|
60
|
+
/** No usable token: the flag reads as its fallback without reaching the registry. */
|
|
61
|
+
signedOut: boolean;
|
|
62
|
+
/** Every failure the request reported, first one first. Empty means the snapshot loaded. */
|
|
63
|
+
errors: unknown[];
|
|
64
|
+
client?: DaemonFlagClient;
|
|
65
|
+
}
|
|
66
|
+
export interface DaemonFlagSnapshotSource {
|
|
67
|
+
/** One refresh timer for every monitor on this source, so their reads land on the same tick. */
|
|
68
|
+
schedule(tick: () => void): () => void;
|
|
69
|
+
/** Used by readDaemonFlag: the shared registry request for this env. */
|
|
70
|
+
load(env: NodeJS.ProcessEnv, options: ReadDaemonFlagOptions): Promise<DaemonFlagRegistryRead>;
|
|
71
|
+
close(): void;
|
|
72
|
+
}
|
|
73
|
+
export interface DaemonFlagSnapshotSourceOptions {
|
|
74
|
+
ttlMs?: number;
|
|
75
|
+
intervalMs?: number;
|
|
76
|
+
now?: () => number;
|
|
77
|
+
/**
|
|
78
|
+
* Told about every shared registry request when it finishes, before the
|
|
79
|
+
* reads waiting on it decide. The daemon's state file is written from here,
|
|
80
|
+
* so it costs no request of its own. It cannot change or delay a read: it
|
|
81
|
+
* runs synchronously and whatever it throws is dropped.
|
|
82
|
+
*/
|
|
83
|
+
onRead?: (read: DaemonFlagRegistryRead, env: NodeJS.ProcessEnv) => void;
|
|
29
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Share registry requests between the daemon's timed flag reads.
|
|
87
|
+
*
|
|
88
|
+
* Reads that arrive while a request is in flight join it, and a loaded
|
|
89
|
+
* snapshot answers further reads for `ttlMs`. A failed or signed-out request
|
|
90
|
+
* is handed to the reads that joined it and is never kept, so the next read
|
|
91
|
+
* asks again and each flag keeps its own failure behavior.
|
|
92
|
+
*/
|
|
93
|
+
export declare function createDaemonFlagSnapshotSource(options?: DaemonFlagSnapshotSourceOptions): DaemonFlagSnapshotSource;
|
|
30
94
|
export declare function readDaemonFlag(flagKey: string, options?: ReadDaemonFlagOptions): Promise<boolean>;
|
|
31
95
|
//# sourceMappingURL=flag.d.ts.map
|