@indigoai-us/hq-cli 5.345.211 → 5.345.212
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 +39 -0
- package/dist/command-catalog.generated.d.ts +28 -0
- package/dist/command-catalog.generated.js +34 -0
- package/dist/command-registration-plan.d.ts +15 -0
- package/dist/command-registration-plan.js +20 -1
- package/dist/commands/agents.js +6 -1
- package/dist/commands/billing.js +17 -4
- package/dist/commands/bot-runtime.d.ts +21 -2
- package/dist/commands/bot-runtime.js +54 -9
- package/dist/commands/bot.d.ts +13 -0
- package/dist/commands/bot.js +142 -12
- package/dist/commands/daemon.js +60 -5
- package/dist/commands/files.js +2 -2
- package/dist/commands/integrations-api.d.ts +11 -0
- package/dist/commands/integrations-connect.d.ts +2 -0
- package/dist/commands/integrations-connect.js +17 -5
- package/dist/commands/integrations-core.d.ts +1 -1
- package/dist/commands/integrations-core.js +18 -10
- package/dist/commands/integrations.js +1 -1
- package/dist/commands/lanes.js +34 -16
- package/dist/commands/whoami.js +7 -6
- package/dist/lazy-commands.js +4 -1
- package/dist/lib/billing/usage-only.d.ts +4 -1
- package/dist/lib/billing/usage-only.js +7 -2
- package/dist/lib/bot/api.d.ts +1 -1
- package/dist/lib/bot/config.js +2 -1
- package/dist/lib/bot/fleet-daemon.d.ts +4 -0
- package/dist/lib/bot/fleet-daemon.js +12 -1
- package/dist/lib/bot/fleet-download.d.ts +6 -0
- package/dist/lib/bot/fleet-download.js +128 -3
- package/dist/lib/bot/fleet-local.d.ts +38 -1
- package/dist/lib/bot/fleet-local.js +239 -26
- package/dist/lib/bot/install-progress.d.ts +28 -0
- package/dist/lib/bot/install-progress.js +185 -0
- package/dist/lib/bot/legacy-provider-login.d.ts +22 -1
- package/dist/lib/bot/legacy-provider-login.js +67 -9
- package/dist/lib/bot/prompt.d.ts +1 -0
- package/dist/lib/bot/prompt.js +3 -2
- package/dist/lib/bot/readiness.d.ts +68 -0
- package/dist/lib/bot/readiness.js +145 -0
- package/dist/lib/bot/run.d.ts +2 -0
- package/dist/lib/bot/run.js +6 -3
- package/dist/lib/bot/scaffold.d.ts +6 -3
- package/dist/lib/bot/scaffold.js +18 -12
- package/dist/lib/capacity/ledger.d.ts +7 -0
- package/dist/lib/capacity/ledger.js +31 -1
- package/dist/lib/capacity/project.d.ts +1 -1
- package/dist/lib/capacity/project.js +13 -4
- package/dist/lib/capacity/route.d.ts +10 -0
- package/dist/lib/capacity/route.js +16 -0
- package/dist/lib/daemon/install.d.ts +15 -0
- package/dist/lib/daemon/install.js +31 -0
- package/dist/lib/daemon/migrate.js +29 -4
- package/dist/lib/daemon/run.d.ts +1 -0
- package/dist/lib/daemon/run.js +6 -1
- package/dist/lib/daemon/supervisor.d.ts +1 -0
- package/dist/lib/daemon/supervisor.js +5 -3
- package/dist/lib/doctor/__testing__/run-doctor.js +4 -0
- package/dist/lib/doctor/checks/jq.d.ts +27 -0
- package/dist/lib/doctor/checks/jq.js +82 -0
- package/dist/lib/doctor/registry.js +4 -0
- package/dist/lib/flag-snapshot-file.js +36 -8
- package/dist/lib/install/codex-targets.d.ts +52 -1
- package/dist/lib/install/codex-targets.js +77 -2
- package/dist/lib/lanes/monitor.d.ts +4 -1
- package/dist/lib/lanes/monitor.js +47 -10
- package/dist/lib/lanes/spawn.js +8 -1
- package/dist/lib/lanes/watch.js +31 -0
- package/dist/lib/onboarding/checkpoint.d.ts +6 -0
- package/dist/lib/onboarding/checkpoint.js +6 -0
- package/dist/lib/onboarding/orchestrator.d.ts +3 -1
- package/dist/lib/onboarding/orchestrator.js +62 -9
- package/dist/lib/onboarding/types.d.ts +8 -0
- package/dist/lib/work-context/organize.d.ts +23 -1
- package/dist/lib/work-context/organize.js +25 -3
- package/dist/lib/work-context/reconcile.js +3 -2
- package/dist/secrets-env-action.js +7 -5
- package/dist/startup-registration.js +7 -2
- package/dist/utils/billing-gate.d.ts +12 -16
- package/dist/utils/billing-gate.js +17 -18
- package/dist/utils/install-tree-torn.d.ts +22 -4
- package/dist/utils/install-tree-torn.js +24 -0
- package/dist/utils/registration-plan-error.d.ts +22 -0
- package/dist/utils/registration-plan-error.js +27 -0
- package/dist/utils/sentry-fingerprint.js +3 -0
- package/dist/utils/unauthorized-error.d.ts +36 -0
- package/dist/utils/unauthorized-error.js +105 -0
- package/dist/utils/vault-api.js +7 -5
- package/package.json +7 -7
- package/scripts/install-hook-engine.mjs +17 -0
package/dist/commands/bot.js
CHANGED
|
@@ -52,6 +52,7 @@ import { executiveStatus } from "../lib/bot/executive-settings.js";
|
|
|
52
52
|
import { describeExecutiveBotSource, resolveExecutiveBot, setExecutiveBot } from "../lib/bot/executive.js";
|
|
53
53
|
import { executiveHotSignalSyncCompanies } from "../lib/bot/executive-sync.js";
|
|
54
54
|
import { readBotListedProcess } from "../lib/bot/listed-running.js";
|
|
55
|
+
import { DEFAULT_BOT_READY_TIMEOUT_SECONDS, botReadinessReport, clearBotSetupStep, createSetupStepReporter, readBotSetupStep, waitForGatewayReady, writeBotSetupStep, } from "../lib/bot/readiness.js";
|
|
55
56
|
import { ensureFleetHotSignalSync, fleetCronOps, migrateLegacyJobsToFleet } from "../lib/bot/fleet-cron.js";
|
|
56
57
|
import { resolvePackSetupPrompt } from "../lib/bot/pack-setup.js";
|
|
57
58
|
import { detectCodingToolActivity } from "../lib/bot/coding-tool-activity.js";
|
|
@@ -80,7 +81,8 @@ import { PROBE_DEFAULT_TIMEOUT_MS, probeBotRuntime } from "../lib/bot/probe.js";
|
|
|
80
81
|
import { BOT_LOGIN_RUNTIMES, botAuthEnv, botRuntimeAuth, capacityAccountHome, describeBotAuth, formatBotAuth, isBotLoginRuntime, restoreBotSessions, setAsideBotSessions, signInBotRuntime, signOutBotRuntime, withRuntimeAuth, } from "../lib/bot/runtime-auth.js";
|
|
81
82
|
import { BotApi, BotApiError, BOT_RESTORE_DEFAULTS, buildBotLocalConfig, describeBotLocalConfig, orphanBotRunMessage, parseBotLocalConfig, removeOrphanBotDaemon, botDaemonStatus, botDir, botCredsPath, botLogPath, botsRoot, botTokenStateDir, botWorkerRelDir, buildBotDaemonPaths, createBotLogger, deleteBotCreds, installBotDaemon, repairBotDaemonIfStale, healBotDaemonNodeFromJob, introDmText, isBotMemoryMode, botLocalMemoryDir, botMemoryMode, resolveBotMemoryDir, validateBotIntro, validateBotDisplayName, validateBotKickoff, validateBotEffort, validateBotModel, effectiveBotEffort, BOT_EFFORT_LEVELS, DEFAULT_BOT_EFFORT, BOT_MEMORY_MODES, BOT_KINDS, isBotKind, effectiveBotKind, effectiveBotCompanies, normalizeBotCompanies, SETUP_BOT_WORKER_ID, isBotRuntimeId, localNameForRemoteBot, remoteBotRunnability, isPidAlive, listBotWorkerOptions, patchBotConfig, readBotConfig, readBotCredsIdentity, readBotStatus, patchBotStatus, runtimeCrashSinceStart, resolveBotWorker, runBot, runtimeFor, scaffoldBotMemory, scaffoldBotWorker, startBotDaemon, stopBotDaemon, uninstallBotDaemon, validateBotName, writeBotConfig, writeBotCreds, BOT_RUNTIMES, BOT_INTRO_MAX_CHARS, BOT_DISPLAY_NAME_MAX_CHARS, BOT_KICKOFF_MAX_CHARS, detectBotPlatform, withBotLock, localBotRole, remoteBotRole, remoteBotDisplayName, personFacingName, writeCloudDisplayName, setupSlugFor, ASSISTANT_ROLE, HQ_FLEET_RUNTIME_ENGINE_ID, HQ_FLEET_LOCAL_RELEASE, authenticateFleetLocalBot, bootstrapFleetLocalBot, buildSystemPrompt, controlFleetBot as controlFleetLocalBot, fleetBotUnitId, fleetBotsManagedByDaemon, ensureFleetPython, fleetLocalGatewayPid, fleetLocalProfileNeedsAdoption, fleetLocalServiceInstalled, fleetProviderForRuntime, importFleetLocalMachineCredential, importFleetLocalProviderLogin, fleetProviderNeedsSignIn, fleetOwnerCompanies, refreshFleetLocalInstructions, fleetLocalPromotionRuntime, installPinnedFleetLocalDistribution, installTargetFleetLocalDistribution, resolveFleetLocalPointerTarget, resolveFleetLocalTargetRelease, fleetLocalProfileDir, fleetProfileOwnerCompanies, fleetLocalChannels, readFleetLocalGatewayState, readPromptSources, removeFleetLocalBot, } from "../lib/bot/index.js";
|
|
82
83
|
import { gatedInteractiveLogin } from "../utils/interactive-caller.js";
|
|
83
|
-
import { fleetInstallProgressReporter, runBotRuntimeInstall, runBotRuntimeStatus } from "./bot-runtime.js";
|
|
84
|
+
import { fleetInstallProgressReporter, fleetRuntimeStatus, runBotAuthStatus, runBotRuntimeInstall, runBotRuntimeStatus } from "./bot-runtime.js";
|
|
85
|
+
import { ensureFleetRuntimeInstalled } from "../lib/bot/fleet-local.js";
|
|
84
86
|
function collectRepeated(value, previous) {
|
|
85
87
|
return [...previous, value];
|
|
86
88
|
}
|
|
@@ -549,6 +551,13 @@ function rowFor(name, opts = {}) {
|
|
|
549
551
|
const legacy = fleet ? null : opts.legacy ?? legacyMoveState(dir, config, legacyConvertSeams.providerLogin(dir, config));
|
|
550
552
|
const pid = listed.pid;
|
|
551
553
|
const processAlive = listed.running;
|
|
554
|
+
const readiness = botReadinessReport({
|
|
555
|
+
setupStep: readBotSetupStep(dir),
|
|
556
|
+
fleet,
|
|
557
|
+
processAlive,
|
|
558
|
+
livePid: pid,
|
|
559
|
+
gateway: fleet ? readFleetLocalGatewayState(config.agentUid) : null,
|
|
560
|
+
});
|
|
552
561
|
// Turns this bot has taken and not finished: what "thinking" means.
|
|
553
562
|
const inflightTurns = readInflightTurns(dir);
|
|
554
563
|
let daemonInstalled = false;
|
|
@@ -576,6 +585,7 @@ function rowFor(name, opts = {}) {
|
|
|
576
585
|
effort: effectiveBotEffort(config),
|
|
577
586
|
effortIsDefault: !config.effort,
|
|
578
587
|
state: processAlive ? "running" : !fleet && status?.state === "failed" ? "failed" : "stopped",
|
|
588
|
+
...readiness,
|
|
579
589
|
pid: processAlive ? pid : null,
|
|
580
590
|
processAlive,
|
|
581
591
|
hosting: hasActivePromotion(dir, config.agentUid, config.ownerUid) ? "cloud" : "local",
|
|
@@ -647,6 +657,8 @@ async function decorateOnline(rows) {
|
|
|
647
657
|
}));
|
|
648
658
|
}
|
|
649
659
|
function humanOnline(row) {
|
|
660
|
+
if (row.readiness === "creating" || row.readiness === "installing" || row.readiness === "starting")
|
|
661
|
+
return chalk.yellow(row.readiness);
|
|
650
662
|
if (row.lastHeartbeatOk === false)
|
|
651
663
|
return chalk.red("unreachable");
|
|
652
664
|
if (row.online === true)
|
|
@@ -848,6 +860,9 @@ async function convertLegacyBotToFleet(name, dir, config, from) {
|
|
|
848
860
|
};
|
|
849
861
|
if (from === "start")
|
|
850
862
|
await stopBot(name, dir, config, "silent");
|
|
863
|
+
const daemonRunsIt = fleetBotsManagedByDaemon();
|
|
864
|
+
if (daemonRunsIt)
|
|
865
|
+
writeBotConfig(dir, fleet);
|
|
851
866
|
let failure = null;
|
|
852
867
|
try {
|
|
853
868
|
refreshFleetLocalInstructions(config.agentUid, fleetBotSystemPrompt(name, fleet));
|
|
@@ -865,6 +880,8 @@ async function convertLegacyBotToFleet(name, dir, config, from) {
|
|
|
865
880
|
catch {
|
|
866
881
|
/* nothing was running */
|
|
867
882
|
}
|
|
883
|
+
if (daemonRunsIt)
|
|
884
|
+
writeBotConfig(dir, current);
|
|
868
885
|
keepLegacy("start", failure);
|
|
869
886
|
return ready();
|
|
870
887
|
}
|
|
@@ -1027,7 +1044,7 @@ async function installFleetRuntimeProfile(name, dir, config, opts = {}) {
|
|
|
1027
1044
|
installation = await installTargetFleetLocalDistribution({ target, onProgress: progress });
|
|
1028
1045
|
}
|
|
1029
1046
|
catch (err) {
|
|
1030
|
-
if (target.source !== "pointer")
|
|
1047
|
+
if (target.source !== "pointer" || target.localFile)
|
|
1031
1048
|
throw err;
|
|
1032
1049
|
if (opts.pointerOnly) {
|
|
1033
1050
|
createBotLogger(dir)("warn", `could not install HQ Fleet Local ${target.release.version} (${err instanceof Error ? err.message : String(err)}); the bot stays on its current release`);
|
|
@@ -1069,6 +1086,9 @@ async function installFleetRuntimeProfile(name, dir, config, opts = {}) {
|
|
|
1069
1086
|
export const botCreateSeams = {
|
|
1070
1087
|
/** The Claude Code login read the way the HQ Fleet Runtime reads it. */
|
|
1071
1088
|
claudeLogin: () => checkClaudeCodeLogin(),
|
|
1089
|
+
runtimeStatus: fleetRuntimeStatus,
|
|
1090
|
+
installRuntime: ensureFleetRuntimeInstalled,
|
|
1091
|
+
waitForReady: waitForGatewayReady,
|
|
1072
1092
|
};
|
|
1073
1093
|
/**
|
|
1074
1094
|
* A Claude bot on the HQ Fleet Runtime answers with the owner's Claude Code
|
|
@@ -1232,6 +1252,15 @@ export function resolveCreateKind(opts, worker) {
|
|
|
1232
1252
|
}
|
|
1233
1253
|
return { kind, companies };
|
|
1234
1254
|
}
|
|
1255
|
+
function removeEmptyDir(dir) {
|
|
1256
|
+
try {
|
|
1257
|
+
if (fs.readdirSync(dir).length === 0)
|
|
1258
|
+
fs.rmdirSync(dir);
|
|
1259
|
+
}
|
|
1260
|
+
catch {
|
|
1261
|
+
return;
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1235
1264
|
/**
|
|
1236
1265
|
* `hq bot create`. Runs under the bot's lock, so a create racing an adopt,
|
|
1237
1266
|
* restore, rm or set of the same bot waits for it instead of tripping over
|
|
@@ -1240,7 +1269,16 @@ export function resolveCreateKind(opts, worker) {
|
|
|
1240
1269
|
export async function runBotCreate(nameArg, opts) {
|
|
1241
1270
|
try {
|
|
1242
1271
|
const name = validateBotName(nameArg);
|
|
1243
|
-
|
|
1272
|
+
const dir = botDir(name);
|
|
1273
|
+
const dirExisted = fs.existsSync(dir);
|
|
1274
|
+
try {
|
|
1275
|
+
await withBotLock(name, () => runBotCreateLocked(name, opts), { command: "hq bot create" });
|
|
1276
|
+
}
|
|
1277
|
+
finally {
|
|
1278
|
+
clearBotSetupStep(dir);
|
|
1279
|
+
if (!dirExisted)
|
|
1280
|
+
removeEmptyDir(dir);
|
|
1281
|
+
}
|
|
1244
1282
|
}
|
|
1245
1283
|
catch (err) {
|
|
1246
1284
|
// Under --json the desktop app reads stdout: a failure, including one in
|
|
@@ -1362,6 +1400,31 @@ async function finishExistingSetupBot(name, dir, config, displayName, opts) {
|
|
|
1362
1400
|
else if (opts.start !== false)
|
|
1363
1401
|
console.log(chalk.yellow(`${name} did not report running within 15s`) + chalk.dim(` logs: hq bot logs ${name}`));
|
|
1364
1402
|
}
|
|
1403
|
+
export function parseReadyTimeoutSeconds(value) {
|
|
1404
|
+
if (value === undefined)
|
|
1405
|
+
return DEFAULT_BOT_READY_TIMEOUT_SECONDS;
|
|
1406
|
+
const seconds = typeof value === "number" ? value : Number(String(value).trim());
|
|
1407
|
+
if (!Number.isInteger(seconds) || seconds < 1 || seconds > 3600) {
|
|
1408
|
+
throw Object.assign(new Error("--ready-timeout must be a whole number of seconds from 1 to 3600."), { expected: true });
|
|
1409
|
+
}
|
|
1410
|
+
return seconds;
|
|
1411
|
+
}
|
|
1412
|
+
export function createReadyMessage(name, readiness, wait, timeoutMs) {
|
|
1413
|
+
if (readiness === "ready")
|
|
1414
|
+
return `${name} is ready to chat.`;
|
|
1415
|
+
if (wait?.failed)
|
|
1416
|
+
return `${name} could not start: ${wait.failed}. See its logs with hq bot logs ${name}, then run hq bot restart ${name}.`;
|
|
1417
|
+
if (wait?.timedOut) {
|
|
1418
|
+
return `${name} is still getting ready after ${Math.round(timeoutMs / 1000)} seconds. It finishes on its own; check with hq bot status ${name}.`;
|
|
1419
|
+
}
|
|
1420
|
+
return null;
|
|
1421
|
+
}
|
|
1422
|
+
function createReadyLine(name, readiness, wait, timeoutMs) {
|
|
1423
|
+
const message = createReadyMessage(name, readiness, wait, timeoutMs);
|
|
1424
|
+
if (!message)
|
|
1425
|
+
return null;
|
|
1426
|
+
return readiness === "ready" ? chalk.green(message) : chalk.yellow(message);
|
|
1427
|
+
}
|
|
1365
1428
|
async function runBotCreateLocked(name, opts) {
|
|
1366
1429
|
if (opts.legacyRuntime) {
|
|
1367
1430
|
throw Object.assign(new Error("--legacy-runtime is no longer supported: new bots run on the HQ Fleet Runtime. Drop --legacy-runtime."), { expected: true });
|
|
@@ -1521,10 +1584,20 @@ async function runBotCreateLocked(name, opts) {
|
|
|
1521
1584
|
// of sending another create that the entity store will reject.
|
|
1522
1585
|
if (isSetupBot && (await adoptOwnedSetupBot(true)))
|
|
1523
1586
|
return;
|
|
1524
|
-
const
|
|
1525
|
-
const
|
|
1587
|
+
const readyTimeoutMs = parseReadyTimeoutSeconds(opts.readyTimeout) * 1000;
|
|
1588
|
+
const progress = fleetInstallProgressReporter(opts.json ? (opts.progress ? "json" : "silent") : "text");
|
|
1589
|
+
const steps = createSetupStepReporter(opts.json ? (opts.progress ? "json" : "silent") : "text");
|
|
1590
|
+
const fleetTarget = await resolveFleetLocalTargetRelease();
|
|
1591
|
+
const runtimeStatus = await botCreateSeams.runtimeStatus({ target: fleetTarget });
|
|
1592
|
+
if (!opts.json)
|
|
1593
|
+
console.log(chalk.dim(`Setting up ${name} takes ${runtimeStatus.estimate}.`));
|
|
1594
|
+
steps.begin("install");
|
|
1595
|
+
const fleetInstallation = await installTargetFleetLocalDistribution({ target: fleetTarget, onProgress: progress });
|
|
1526
1596
|
progress({ phase: "python" });
|
|
1527
1597
|
const fleetPython = await ensureFleetPython();
|
|
1598
|
+
await botCreateSeams.installRuntime(fleetInstallation, { python: fleetPython, onProgress: progress });
|
|
1599
|
+
steps.finish("install", runtimeStatus.installed ? "skipped" : "done");
|
|
1600
|
+
steps.begin("identity");
|
|
1528
1601
|
const ownerCompanies = kind === "personal" ? await fleetOwnerCompanies() : companies;
|
|
1529
1602
|
// A company bot's companies are resolved first (a typo must not cost an
|
|
1530
1603
|
// identity) and sent with the create: the server makes the bot a member of
|
|
@@ -1595,6 +1668,7 @@ async function runBotCreateLocked(name, opts) {
|
|
|
1595
1668
|
throw err;
|
|
1596
1669
|
}
|
|
1597
1670
|
const agentUid = created.agent.uid;
|
|
1671
|
+
steps.identify(agentUid);
|
|
1598
1672
|
writeBotCreds(dir, {
|
|
1599
1673
|
username: created.identity.cognitoUsername,
|
|
1600
1674
|
secret: created.identity.secret,
|
|
@@ -1603,6 +1677,7 @@ async function runBotCreateLocked(name, opts) {
|
|
|
1603
1677
|
clientId: DEFAULT_COGNITO.clientId,
|
|
1604
1678
|
region: DEFAULT_COGNITO.region,
|
|
1605
1679
|
});
|
|
1680
|
+
const daemonRunsFleetBots = fleetBotsManagedByDaemon();
|
|
1606
1681
|
const config = {
|
|
1607
1682
|
v: 1,
|
|
1608
1683
|
name,
|
|
@@ -1639,8 +1714,10 @@ async function runBotCreateLocked(name, opts) {
|
|
|
1639
1714
|
createdAt: new Date().toISOString(),
|
|
1640
1715
|
enabled: !fleetAuthPending,
|
|
1641
1716
|
...(fleetAuthPending ? { fleetAuthPending: true } : {}),
|
|
1717
|
+
...(daemonRunsFleetBots ? { fleetServiceInstallPending: true } : {}),
|
|
1642
1718
|
};
|
|
1643
1719
|
writeBotConfig(dir, config);
|
|
1720
|
+
writeBotSetupStep(dir, "identity");
|
|
1644
1721
|
// A company bot acts as itself, so it must be a member of each of its
|
|
1645
1722
|
// companies. Only the companies it actually joined are recorded, so after a failed invite the identity
|
|
1646
1723
|
// and bot.json stay on disk and `hq bot companies <name> --add <slug>`
|
|
@@ -1662,15 +1739,19 @@ async function runBotCreateLocked(name, opts) {
|
|
|
1662
1739
|
}
|
|
1663
1740
|
// A worker-sourced bot never writes into the company tree: only its own
|
|
1664
1741
|
// memory folder is scaffolded.
|
|
1665
|
-
const scaffoldOpts = { memoryDir: config.memoryDir };
|
|
1742
|
+
const scaffoldOpts = { memoryDir: config.memoryDir, ...(config.displayName ? { displayName: config.displayName } : {}) };
|
|
1666
1743
|
const scaffold = worker
|
|
1667
1744
|
? scaffoldBotMemory(hqRoot, name, undefined, scaffoldOpts)
|
|
1668
1745
|
: scaffoldBotWorker(hqRoot, name, agentUid, HQ_FLEET_RUNTIME_ENGINE_ID, undefined, scaffoldOpts);
|
|
1669
1746
|
fs.rmSync(path.join(dir, "status.json"), { force: true });
|
|
1670
|
-
const introText = introDmText(name, runtime, intro, { kind, companies });
|
|
1747
|
+
const introText = introDmText(name, runtime, intro, { kind, companies, ...(config.displayName ? { displayName: config.displayName } : {}) });
|
|
1671
1748
|
const toolOffer = isSetupBot && kickoff ? fleetSetupToolOffer(dir, config) : null;
|
|
1672
1749
|
const startNow = opts.start !== false && !fleetAuthPending;
|
|
1673
|
-
|
|
1750
|
+
steps.finish("identity", "done");
|
|
1751
|
+
if (startNow) {
|
|
1752
|
+
steps.begin("starting");
|
|
1753
|
+
writeBotSetupStep(dir, "starting");
|
|
1754
|
+
}
|
|
1674
1755
|
const fleetBootstrap = await bootstrapFleetLocalBot({
|
|
1675
1756
|
agentUid,
|
|
1676
1757
|
ownerUid: config.ownerUid,
|
|
@@ -1692,6 +1773,22 @@ async function runBotCreateLocked(name, opts) {
|
|
|
1692
1773
|
syncFleetRuntimeJobs(name, dir, config);
|
|
1693
1774
|
const startedByDaemon = startNow && daemonRunsFleetBots && controlFleetLocalBot(agentUid, "install").ok === true;
|
|
1694
1775
|
const running = fleetBootstrap.running || startedByDaemon;
|
|
1776
|
+
let readyWait = null;
|
|
1777
|
+
if (!startNow) {
|
|
1778
|
+
steps.finish("starting", "skipped");
|
|
1779
|
+
steps.finish("ready", "skipped");
|
|
1780
|
+
}
|
|
1781
|
+
else if (!running) {
|
|
1782
|
+
steps.finish("starting", "failed");
|
|
1783
|
+
steps.finish("ready", "skipped");
|
|
1784
|
+
}
|
|
1785
|
+
else {
|
|
1786
|
+
steps.finish("starting", "done");
|
|
1787
|
+
steps.begin("ready");
|
|
1788
|
+
readyWait = await botCreateSeams.waitForReady(agentUid, { timeoutMs: readyTimeoutMs });
|
|
1789
|
+
steps.finish("ready", readyWait.ready ? "done" : readyWait.failed ? "failed" : "timeout");
|
|
1790
|
+
}
|
|
1791
|
+
const readiness = !startNow || !running || readyWait?.failed ? "offline" : readyWait?.ready ? "ready" : "starting";
|
|
1695
1792
|
const fleetProfile = fleetBootstrap.profile;
|
|
1696
1793
|
const runtimeLabel = HQ_FLEET_RUNTIME_ENGINE_ID;
|
|
1697
1794
|
createBotLogger(dir)("info", `created ${name} (${agentUid}) kind=${kind}${companies.length ? ` companies=${companies.join(",")}` : ""} runtime=${runtimeLabel}${worker ? ` worker=${worker.id} company=${worker.company ?? "-"}` : ""} memory=${memoryMode}`);
|
|
@@ -1734,6 +1831,9 @@ async function runBotCreateLocked(name, opts) {
|
|
|
1734
1831
|
if (fleetAuthPending) {
|
|
1735
1832
|
console.log(chalk.yellow(` sign it in before it can answer: hq bot auth ${name} --provider ${runtime === "grok" ? "grok" : "chatgpt"}`));
|
|
1736
1833
|
}
|
|
1834
|
+
const readyLine = createReadyLine(name, readiness, readyWait, readyTimeoutMs);
|
|
1835
|
+
if (readyLine)
|
|
1836
|
+
console.log(readyLine);
|
|
1737
1837
|
}
|
|
1738
1838
|
if (opts.json) {
|
|
1739
1839
|
const status = readBotStatus(dir);
|
|
@@ -1744,6 +1844,14 @@ async function runBotCreateLocked(name, opts) {
|
|
|
1744
1844
|
daemon: null,
|
|
1745
1845
|
running,
|
|
1746
1846
|
how: startedByDaemon ? "started by hq daemon" : fleetBootstrap.running ? "started by the HQ Fleet Runtime" : null,
|
|
1847
|
+
steps: steps.steps(),
|
|
1848
|
+
readiness,
|
|
1849
|
+
ready: readiness === "ready",
|
|
1850
|
+
readyAt: readyWait?.readyAt ?? null,
|
|
1851
|
+
readyWait: readyWait
|
|
1852
|
+
? { timedOut: readyWait.timedOut, failed: readyWait.failed, waitedMs: readyWait.waitedMs, timeoutMs: readyTimeoutMs }
|
|
1853
|
+
: null,
|
|
1854
|
+
message: createReadyMessage(name, readiness, readyWait, readyTimeoutMs),
|
|
1747
1855
|
state: status?.state ?? "unknown",
|
|
1748
1856
|
pid: status?.pid ?? null,
|
|
1749
1857
|
lastError: status?.lastError ?? null,
|
|
@@ -2112,6 +2220,7 @@ async function runBotStatus(nameArg, opts) {
|
|
|
2112
2220
|
console.log(` worker: ${row.workerId}${row.companySlug ? ` (company ${row.companySlug})` : ""} ${chalk.dim(row.workerDir)}`);
|
|
2113
2221
|
console.log(` memory: ${row.memory} ${chalk.dim(row.memoryDir)}`);
|
|
2114
2222
|
console.log(` process: ${row.processAlive ? chalk.green(`running (pid ${row.pid})`) : chalk.gray(row.state)}`);
|
|
2223
|
+
console.log(` readiness: ${row.readiness === "ready" ? chalk.green(`ready${row.readyAt ? ` since ${row.readyAt}` : ""}`) : row.readiness === "offline" ? chalk.gray("offline") : chalk.yellow(row.readiness)}`);
|
|
2115
2224
|
if (row.needsSignIn)
|
|
2116
2225
|
console.log(` sign-in: required (${row.authCommand})`);
|
|
2117
2226
|
if (row.brainUsage.state === "exhausted") {
|
|
@@ -2947,7 +3056,7 @@ export async function runBotIntro(nameArg) {
|
|
|
2947
3056
|
if (hasPromotionHold(dir))
|
|
2948
3057
|
throw new Error("This bot is held for cloud promotion. Continue its promotion before changing local settings or lifecycle.");
|
|
2949
3058
|
const api = new BotApi({ token: botTokenSupplier(dir) });
|
|
2950
|
-
await api.sendDm({ toPersonUid: config.ownerUid, body: introDmText(name, config.runtime, config.intro, { kind: effectiveBotKind(config), companies: effectiveBotCompanies(config) }) });
|
|
3059
|
+
await api.sendDm({ toPersonUid: config.ownerUid, body: introDmText(name, config.runtime, config.intro, { kind: effectiveBotKind(config), companies: effectiveBotCompanies(config), ...(config.displayName ? { displayName: config.displayName } : {}) }) });
|
|
2951
3060
|
patchBotConfig(dir, { introSentAt: new Date().toISOString() });
|
|
2952
3061
|
console.log(chalk.green(`${name} introduced itself to you.`));
|
|
2953
3062
|
}
|
|
@@ -3034,8 +3143,9 @@ export async function runBotAuth(nameArg, opts) {
|
|
|
3034
3143
|
process.on("SIGINT", keepAliveOnInterrupt);
|
|
3035
3144
|
let result;
|
|
3036
3145
|
try {
|
|
3037
|
-
result = authenticateFleetLocalBot({
|
|
3146
|
+
result = await authenticateFleetLocalBot({
|
|
3038
3147
|
agentUid: b.config.agentUid,
|
|
3148
|
+
...(opts.json ? { onAuthEvent: (event) => { console.log(JSON.stringify(event)); } } : {}),
|
|
3039
3149
|
provider: opts.provider,
|
|
3040
3150
|
...(adopted || legacy || b.config.fleetAuthPending === true ? { installService: true } : {}),
|
|
3041
3151
|
...(opts.model ? { model: opts.model } : {}),
|
|
@@ -3043,6 +3153,16 @@ export async function runBotAuth(nameArg, opts) {
|
|
|
3043
3153
|
...(opts.baseUrl ? { baseUrl: opts.baseUrl } : {}),
|
|
3044
3154
|
...(opts.transport ? { transport: opts.transport } : {}),
|
|
3045
3155
|
openBrowser: opts.browser !== false,
|
|
3156
|
+
}, {
|
|
3157
|
+
control: (agentUid, action) => {
|
|
3158
|
+
if (fleetBotsManagedByDaemon()) {
|
|
3159
|
+
if (legacy && engine)
|
|
3160
|
+
writeBotConfig(b.dir, { ...(readBotConfig(b.dir) ?? legacy), engine });
|
|
3161
|
+
else if (b.config.fleetAuthPending === true)
|
|
3162
|
+
patchBotConfig(b.dir, { fleetAuthPending: false });
|
|
3163
|
+
}
|
|
3164
|
+
return controlFleetLocalBot(agentUid, action);
|
|
3165
|
+
},
|
|
3046
3166
|
});
|
|
3047
3167
|
if (result.authenticated !== true)
|
|
3048
3168
|
throw Object.assign(new Error("The provider has not completed sign-in."), { expected: true });
|
|
@@ -3058,6 +3178,8 @@ export async function runBotAuth(nameArg, opts) {
|
|
|
3058
3178
|
catch {
|
|
3059
3179
|
/* nothing was running */
|
|
3060
3180
|
}
|
|
3181
|
+
if (fleetBotsManagedByDaemon())
|
|
3182
|
+
writeBotConfig(b.dir, legacy);
|
|
3061
3183
|
await startBot(b.name, b.dir, legacy, "silent", {}, { keepLegacy: true }).catch(() => undefined);
|
|
3062
3184
|
}
|
|
3063
3185
|
throw err;
|
|
@@ -3369,7 +3491,7 @@ async function adoptRemoteBotLocked(input) {
|
|
|
3369
3491
|
if (fleetInstallation)
|
|
3370
3492
|
config.engine = fleetInstallation.engine;
|
|
3371
3493
|
writeBotConfig(dir, config);
|
|
3372
|
-
const scaffoldOpts = { memoryDir: config.memoryDir };
|
|
3494
|
+
const scaffoldOpts = { memoryDir: config.memoryDir, ...(config.displayName ? { displayName: config.displayName } : {}) };
|
|
3373
3495
|
const scaffold = config.workerSource === "worker"
|
|
3374
3496
|
? scaffoldBotMemory(input.hqRoot, name, undefined, scaffoldOpts)
|
|
3375
3497
|
: scaffoldBotWorker(input.hqRoot, name, bot.agentUid, config.runtime, undefined, scaffoldOpts);
|
|
@@ -3388,7 +3510,7 @@ async function adoptRemoteBotLocked(input) {
|
|
|
3388
3510
|
...(input.preserveFirstStart
|
|
3389
3511
|
? {
|
|
3390
3512
|
firstStart: {
|
|
3391
|
-
intro: introDmText(name, config.runtime, config.intro, { kind: effectiveBotKind(config), companies: effectiveBotCompanies(config) }),
|
|
3513
|
+
intro: introDmText(name, config.runtime, config.intro, { kind: effectiveBotKind(config), companies: effectiveBotCompanies(config), ...(config.displayName ? { displayName: config.displayName } : {}) }),
|
|
3392
3514
|
...(config.kickoff ? { kickoff: config.kickoff } : {}),
|
|
3393
3515
|
},
|
|
3394
3516
|
}
|
|
@@ -3716,6 +3838,8 @@ export function registerBotCommand(program) {
|
|
|
3716
3838
|
.option("--memory <where>", "Where the bot keeps its memory: synced (personal/workers/<name>/memory in HQ) or local (~/.hq/bots/<name>/memory, this computer only)", "synced")
|
|
3717
3839
|
.option("--no-daemon", "Accepted for compatibility; HQ Fleet bots run under their own background service")
|
|
3718
3840
|
.option("--no-start", "Create without starting")
|
|
3841
|
+
.option("--ready-timeout <seconds>", `How long to wait for the bot to be ready to chat before returning (default ${DEFAULT_BOT_READY_TIMEOUT_SECONDS})`)
|
|
3842
|
+
.option("--progress", "With --json: print each setup step and download progress as one JSON line before the final document")
|
|
3719
3843
|
.option("--json", "Print machine-readable JSON")
|
|
3720
3844
|
.action((name, opts) => wrap(() => runBotCreate(name, opts))());
|
|
3721
3845
|
bot
|
|
@@ -3802,6 +3926,12 @@ export function registerBotCommand(program) {
|
|
|
3802
3926
|
.option("--no-browser", "Do not open a browser during device authorization")
|
|
3803
3927
|
.option("--json", "Print machine-readable JSON")
|
|
3804
3928
|
.action((name, opts) => wrap(async () => { await runBotAuth(name, opts); })());
|
|
3929
|
+
bot
|
|
3930
|
+
.command("auth-status")
|
|
3931
|
+
.description("Say whether a Fleet bot created now would need its own ChatGPT or Grok sign-in, or reuse a login already on this computer")
|
|
3932
|
+
.requiredOption("--provider <provider>", "Provider: chatgpt or grok")
|
|
3933
|
+
.option("--json", "Print machine-readable JSON: { signedIn }")
|
|
3934
|
+
.action((opts) => wrap(async () => { await runBotAuthStatus(opts); })());
|
|
3805
3935
|
bot
|
|
3806
3936
|
.command("logs <name>")
|
|
3807
3937
|
.description("Show the bot's log")
|
package/dist/commands/daemon.js
CHANGED
|
@@ -25,7 +25,7 @@ import { DEFAULT_SERVICES, SERVICE_DESCRIPTIONS, enabledServices, hqCloudUnits }
|
|
|
25
25
|
import { applyServiceToggle, effectiveSyncOwner, readDaemonConfig, writeDaemonConfig } from "../lib/daemon/config.js";
|
|
26
26
|
import { daemonUnitInstalled } from "../lib/daemon/handoff.js";
|
|
27
27
|
import { adoptLegacyUnits, readAdoptedUnits, restoreLegacyUnits } from "../lib/daemon/migrate.js";
|
|
28
|
-
import { ROOT_REFUSAL, SYSTEM_UNIT_DIR, WINDOWS_START_WAIT_MS, daemonRootRefusal, installDaemonUnit, installScopeFor, classifyWindowsTask, daemonServiceStatus, describeSupervision, legacyWindowsTask, startDaemonUnit, readWindowsSid, uninstallDaemonUnit, windowsInteractiveSession, windowsTaskName, } from "../lib/daemon/install.js";
|
|
28
|
+
import { DAEMON_ALIVE_WAIT_MS, ROOT_REFUSAL, SYSTEM_UNIT_DIR, WINDOWS_START_WAIT_MS, waitForLiveDaemon, daemonRootRefusal, installDaemonUnit, installScopeFor, classifyWindowsTask, daemonServiceStatus, describeSupervision, legacyWindowsTask, startDaemonUnit, readWindowsSid, uninstallDaemonUnit, windowsInteractiveSession, windowsTaskName, } from "../lib/daemon/install.js";
|
|
29
29
|
import { PLIST_REFRESH_MARKER } from "../lib/daemon/plist-refresh.js";
|
|
30
30
|
import { describeLegacyUnit, findLegacyUnits } from "../lib/daemon/legacy.js";
|
|
31
31
|
import { isDaemonProcess, liveDaemonLock, runningDaemonPid } from "../lib/daemon/lock.js";
|
|
@@ -194,6 +194,9 @@ function hostFor(d, paths, pathEnv) {
|
|
|
194
194
|
env.PATH = d.env.PATH;
|
|
195
195
|
if (d.env.HQ_DAEMON_DIR)
|
|
196
196
|
env.HQ_DAEMON_DIR = d.env.HQ_DAEMON_DIR;
|
|
197
|
+
const pointerFile = d.env.HQ_FLEET_RELEASE_POINTER_FILE?.trim();
|
|
198
|
+
if (pointerFile)
|
|
199
|
+
env.HQ_FLEET_RELEASE_POINTER_FILE = path.resolve(pointerFile);
|
|
197
200
|
return {
|
|
198
201
|
platform: d.platform,
|
|
199
202
|
home: d.home,
|
|
@@ -297,9 +300,16 @@ async function runInstall(d, opts) {
|
|
|
297
300
|
for (const line of describeServices(detected.type, config))
|
|
298
301
|
d.out(line);
|
|
299
302
|
const migratable = d.legacyUnits().filter((u) => u.migratable);
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
+
// The older Work Mesh unit is taken over by the install itself once the
|
|
304
|
+
// daemon is running (feedback_c85ad51b): left alone, it kept running beside
|
|
305
|
+
// the daemon until someone ran `hq daemon migrate --apply` by hand.
|
|
306
|
+
const meshTakeover = scope === "user" && enabledServices(detected.type, config).includes("mesh")
|
|
307
|
+
? migratable.filter((u) => u.service === "mesh" && u.kind !== "systemd-system")
|
|
308
|
+
: [];
|
|
309
|
+
const noteLegacy = (u) => d.out(`Note: ${describeLegacyUnit(u)} still runs ${u.unitId}. The daemon leaves it alone until \`hq daemon migrate\` takes it over.`);
|
|
310
|
+
for (const u of migratable)
|
|
311
|
+
if (!meshTakeover.includes(u))
|
|
312
|
+
noteLegacy(u);
|
|
303
313
|
// A box worked out from its runner unit, --user or sudo gets the marker file
|
|
304
314
|
// provisioning would have written: `migrate --apply` moves the runner unit
|
|
305
315
|
// aside, and later root commands (uninstall) must still find the box's type
|
|
@@ -308,10 +318,13 @@ async function runInstall(d, opts) {
|
|
|
308
318
|
d.writeFile(MACHINE_TYPE_MARKER_PATH, `type=${detected.type}\nuser=${runAsUser}\n`);
|
|
309
319
|
}
|
|
310
320
|
const runAsHome = runAsUser ? d.userHome(runAsUser) : undefined;
|
|
321
|
+
const runningDaemon = () => liveDaemonLock(paths.lockPath, d.daemonAlive);
|
|
322
|
+
// The daemon from before this install, so the takeover can tell it from a new one.
|
|
323
|
+
const daemonBefore = meshTakeover.length > 0 ? runningDaemon() : null;
|
|
311
324
|
const result = installDaemonUnit(hostFor(d, paths, scope === "user"), { scope, runAsUser, runAsHome }, {
|
|
312
325
|
run: d.run,
|
|
313
326
|
sleep: d.sleep,
|
|
314
|
-
runningDaemon
|
|
327
|
+
runningDaemon,
|
|
315
328
|
});
|
|
316
329
|
handOver(d, { paths, detected, runAsUser });
|
|
317
330
|
if (result.notice)
|
|
@@ -320,6 +333,7 @@ async function runInstall(d, opts) {
|
|
|
320
333
|
d.err(result.warning);
|
|
321
334
|
if (result.kind === "manual") {
|
|
322
335
|
d.out(`This platform has no supported service manager. Start the daemon yourself with:\n ${result.manualCommand}`);
|
|
336
|
+
meshTakeover.forEach(noteLegacy);
|
|
323
337
|
return;
|
|
324
338
|
}
|
|
325
339
|
if (result.startPending) {
|
|
@@ -335,6 +349,7 @@ async function runInstall(d, opts) {
|
|
|
335
349
|
}
|
|
336
350
|
d.out("The daemon starts at your next sign-in to Windows. It is not running yet.");
|
|
337
351
|
d.out("Check it with: hq daemon status");
|
|
352
|
+
meshTakeover.forEach(noteLegacy);
|
|
338
353
|
return;
|
|
339
354
|
}
|
|
340
355
|
const seconds = WINDOWS_START_WAIT_MS / 1000;
|
|
@@ -350,6 +365,39 @@ async function runInstall(d, opts) {
|
|
|
350
365
|
throw new DaemonCommandError(`Installed ${result.unitPath}, but it did not start: ${result.error ?? "unknown error"}`);
|
|
351
366
|
}
|
|
352
367
|
d.out(`Installed and started: ${result.unitPath}`);
|
|
368
|
+
if (meshTakeover.length === 0)
|
|
369
|
+
return;
|
|
370
|
+
// launchd and systemd report "loaded" even when the daemon exits at once and
|
|
371
|
+
// crash-loops, so wait (bounded) for a live daemon to hold the lock before
|
|
372
|
+
// stopping the working mesh agent. schtasks already waited for that above.
|
|
373
|
+
const live = result.kind === "schtasks" ? runningDaemon() : waitForLiveDaemon(runningDaemon, daemonBefore, d.sleep);
|
|
374
|
+
if (!live) {
|
|
375
|
+
const seconds = DAEMON_ALIVE_WAIT_MS / 1000;
|
|
376
|
+
for (const u of meshTakeover) {
|
|
377
|
+
d.err(`warning: the daemon's service is loaded, but no running daemon held its lock within ${seconds} seconds, ` +
|
|
378
|
+
`so ${describeLegacyUnit(u)} keeps running ${u.unitId}. Check \`hq daemon status\` and \`hq daemon logs\`, then run \`hq daemon migrate --apply\`.`);
|
|
379
|
+
}
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
takeOverLegacyMesh(d, paths, meshTakeover);
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Stop the older Work Mesh unit and move its definition aside now that the
|
|
386
|
+
* daemon runs mesh, the same takeover `hq daemon migrate --apply` does (so
|
|
387
|
+
* `hq daemon uninstall --restore-legacy` gives it back). A failed takeover
|
|
388
|
+
* leaves the old unit running as before and does not fail the install.
|
|
389
|
+
*/
|
|
390
|
+
function takeOverLegacyMesh(d, paths, units) {
|
|
391
|
+
const result = adoptLegacyUnits(units, { ...migrateDeps(d, paths), sleep: d.sleep });
|
|
392
|
+
for (const a of result.adopted)
|
|
393
|
+
d.out(`Took over ${a.unitId} from ${describeLegacyUnit(a)}; the daemon starts it within a minute.`);
|
|
394
|
+
for (const s of result.skipped)
|
|
395
|
+
d.out(`Left ${s.unit.unitId} to ${describeLegacyUnit(s.unit)}: ${s.reason}`);
|
|
396
|
+
for (const f of result.failed) {
|
|
397
|
+
d.err(`warning: could not take over ${f.unit.unitId} from ${describeLegacyUnit(f.unit)}: ${f.error}. It keeps running; retry with \`hq daemon migrate --apply\`.`);
|
|
398
|
+
}
|
|
399
|
+
if (result.adopted.length > 0)
|
|
400
|
+
d.out("`hq daemon uninstall --restore-legacy` puts the old unit back.");
|
|
353
401
|
}
|
|
354
402
|
/** Root acting for a box's login user needs that user's uid to reach their systemd manager. */
|
|
355
403
|
function loginUid(d, user) {
|
|
@@ -413,6 +461,13 @@ async function runUninstall(d, opts) {
|
|
|
413
461
|
throw new DaemonCommandError(`Some units were not restored; they are still listed in ${migrate.recordPath}.`);
|
|
414
462
|
}
|
|
415
463
|
}
|
|
464
|
+
if (!opts.restoreLegacy && adopted.length > 0) {
|
|
465
|
+
// `hq daemon install` takes over the older mesh unit by itself, so users
|
|
466
|
+
// reach this state without ever running migrate. Nothing runs those
|
|
467
|
+
// services once the daemon is gone; say how to give them back.
|
|
468
|
+
d.out(`hq daemon had taken over ${adopted.map((u) => u.unitId).join(", ")}; nothing runs ${adopted.length === 1 ? "it" : "them"} now. ` +
|
|
469
|
+
"Run `hq daemon uninstall --restore-legacy` to give the older units back.");
|
|
470
|
+
}
|
|
416
471
|
if (opts.purge) {
|
|
417
472
|
fs.rmSync(paths.root, { recursive: true, force: true });
|
|
418
473
|
d.out(`Deleted ${paths.root}`);
|
package/dist/commands/files.js
CHANGED
|
@@ -7,7 +7,7 @@ import { gateApiKeyCapabilities } from "../utils/api-key-command-gate.js";
|
|
|
7
7
|
import { vaultApiFetch, getCompanyUid } from "./secrets.js";
|
|
8
8
|
import { GROUP_ID_PATTERN, EMAIL_PATTERN, isPrivateFolderPattern, normalizeFilePrefix, OUTPOST_UID_PATTERN, toSharedFolderGlob, } from "./_patterns.js";
|
|
9
9
|
import { looksLikeCompanyUid } from "../utils/vault-api.js";
|
|
10
|
-
import {
|
|
10
|
+
import { unauthorizedError } from "../utils/unauthorized-error.js";
|
|
11
11
|
import { formatAccessDenied, offerAccessLadder, } from "../utils/access-denied-hint.js";
|
|
12
12
|
import { fetchChannels, matchChannelsByName } from "./dm.js";
|
|
13
13
|
import { suggestChannels, withChannelSuggestions } from "./channel-suggest.js";
|
|
@@ -1496,7 +1496,7 @@ async function resolveCompanyUidForAnchoredPath(token, opts) {
|
|
|
1496
1496
|
signal: AbortSignal.timeout(15_000),
|
|
1497
1497
|
});
|
|
1498
1498
|
if (response.status === 401)
|
|
1499
|
-
throw
|
|
1499
|
+
throw unauthorizedError();
|
|
1500
1500
|
if (!response.ok) {
|
|
1501
1501
|
throw new Error(`Failed to resolve company '${opts.explicit}' (HTTP ${response.status})`);
|
|
1502
1502
|
}
|
|
@@ -162,6 +162,12 @@ export interface InstallInput {
|
|
|
162
162
|
header: string;
|
|
163
163
|
};
|
|
164
164
|
scope?: ConnectScope;
|
|
165
|
+
/**
|
|
166
|
+
* Reconnect: re-key exactly this existing connection and keep its owner.
|
|
167
|
+
* Without it hq-pro places the install by `scope`, which sent a legacy
|
|
168
|
+
* shared connection's new key to a personal row (feedback_a79e0c89).
|
|
169
|
+
*/
|
|
170
|
+
connectionId?: string;
|
|
165
171
|
}
|
|
166
172
|
export type ConnectScope = "personal" | "company";
|
|
167
173
|
export declare function scopeUnavailableMessage(scope: ConnectScope): string;
|
|
@@ -231,6 +237,11 @@ export interface OAuthStartInput {
|
|
|
231
237
|
*/
|
|
232
238
|
scopes?: string[];
|
|
233
239
|
scope?: ConnectScope;
|
|
240
|
+
/**
|
|
241
|
+
* Reconnect: sign in for exactly this existing connection and keep its
|
|
242
|
+
* owner, as on install (feedback_a79e0c89).
|
|
243
|
+
*/
|
|
244
|
+
connectionId?: string;
|
|
234
245
|
}
|
|
235
246
|
export declare function startOAuth(token: string, companyUid: string, input: OAuthStartInput): Promise<OAuthStartResult>;
|
|
236
247
|
export declare function completeOAuth(token: string, companyUid: string, input: {
|
|
@@ -93,6 +93,8 @@ interface ConnectTarget {
|
|
|
93
93
|
authClass?: "none" | "key" | "oauth";
|
|
94
94
|
/** Human label for prompts and success lines. */
|
|
95
95
|
label: string;
|
|
96
|
+
/** Reconnect only: the existing connection the install must re-key. */
|
|
97
|
+
connectionId?: string;
|
|
96
98
|
}
|
|
97
99
|
/**
|
|
98
100
|
* Run the browser sign-in and finish the install.
|
|
@@ -350,6 +350,13 @@ async function resolveKey(opts, appLabel) {
|
|
|
350
350
|
}
|
|
351
351
|
throw new IntegrationsCliError(`${appLabel} needs an API key. Pass it with --token-stdin (recommended, keeps it out of shell history) or --token <key>.`, { expected: true });
|
|
352
352
|
}
|
|
353
|
+
/**
|
|
354
|
+
* Install or OAuth-start fields for a target, pinned to the reconnected
|
|
355
|
+
* connection when set, so a browser reconnect re-keys that row too.
|
|
356
|
+
*/
|
|
357
|
+
function installRefOf(target) {
|
|
358
|
+
return target.connectionId ? { ...target.ref, connectionId: target.connectionId } : target.ref;
|
|
359
|
+
}
|
|
353
360
|
/**
|
|
354
361
|
* Remote MCP endpoints the integrations.sh catalog lists as MCP without a URL.
|
|
355
362
|
*
|
|
@@ -623,7 +630,7 @@ async function connectViaOAuth(token, companyUid, target, opts) {
|
|
|
623
630
|
}
|
|
624
631
|
const requestedScopes = parseRequestedScopes(opts.scopes);
|
|
625
632
|
const startInput = {
|
|
626
|
-
...target
|
|
633
|
+
...installRefOf(target),
|
|
627
634
|
...(requestedScopes ? { scopes: requestedScopes } : {}),
|
|
628
635
|
};
|
|
629
636
|
const userClient = await resolveUserOAuthClient(opts, target.label);
|
|
@@ -1021,7 +1028,7 @@ async function linkOnlySignIn(token, companyUid, target, opts, startInput) {
|
|
|
1021
1028
|
*/
|
|
1022
1029
|
async function userClientSignIn(token, companyUid, target, opts, client, requestedScopes) {
|
|
1023
1030
|
const started = await startOAuth(token, companyUid, {
|
|
1024
|
-
...target
|
|
1031
|
+
...installRefOf(target),
|
|
1025
1032
|
clientId: client.clientId,
|
|
1026
1033
|
...(client.clientSecret ? { clientSecret: client.clientSecret } : {}),
|
|
1027
1034
|
// A caller who registered the app themselves is the one who knows which
|
|
@@ -1083,7 +1090,7 @@ async function completeCredentialIfNeeded(token, companyUid, target, opts, resul
|
|
|
1083
1090
|
console.error(chalk.dim(`${target.label} needs an API key to finish connecting.`));
|
|
1084
1091
|
const bearerToken = await resolveKey(opts, target.label);
|
|
1085
1092
|
return await installIntegration(token, companyUid, {
|
|
1086
|
-
...target
|
|
1093
|
+
...installRefOf(target),
|
|
1087
1094
|
authMode: "bearer",
|
|
1088
1095
|
bearerToken,
|
|
1089
1096
|
});
|
|
@@ -1650,7 +1657,11 @@ export function registerConnectCommands(integrations) {
|
|
|
1650
1657
|
...(connection.installation?.displayName
|
|
1651
1658
|
? { displayName: connection.installation.displayName }
|
|
1652
1659
|
: {}),
|
|
1653
|
-
|
|
1660
|
+
// A legacy row is a shared one (hq-pro reports a creator-only
|
|
1661
|
+
// legacy row as person-owned), so it reconnects as a company
|
|
1662
|
+
// connection. Sending no scope defaulted to personal and wrote the
|
|
1663
|
+
// new key to a personal row (feedback_a79e0c89).
|
|
1664
|
+
...(connection.ownerType === "company" || connection.ownerType === "legacy"
|
|
1654
1665
|
? { scope: "company" }
|
|
1655
1666
|
: connection.ownerType === "person"
|
|
1656
1667
|
? { scope: "personal" }
|
|
@@ -1658,6 +1669,7 @@ export function registerConnectCommands(integrations) {
|
|
|
1658
1669
|
},
|
|
1659
1670
|
...(opts.auth ? { authClass: opts.auth } : {}),
|
|
1660
1671
|
label: connection.installation?.displayName ?? bareProvider(connection.provider),
|
|
1672
|
+
connectionId: connection.id,
|
|
1661
1673
|
};
|
|
1662
1674
|
// Same gate `connectApp` applies. This path does not go through it —
|
|
1663
1675
|
// it resolves the endpoint off the existing connection and branches
|
|
@@ -1677,7 +1689,7 @@ export function registerConnectCommands(integrations) {
|
|
|
1677
1689
|
const bearerToken = wantsKey ? await resolveKey(opts, target.label) : undefined;
|
|
1678
1690
|
try {
|
|
1679
1691
|
const result = await installIntegration(token, companyUid, {
|
|
1680
|
-
...target
|
|
1692
|
+
...installRefOf(target),
|
|
1681
1693
|
...(bearerToken ? { authMode: "bearer", bearerToken } : {}),
|
|
1682
1694
|
});
|
|
1683
1695
|
reportInstall(await completeCredentialIfNeeded(token, companyUid, target, opts, result), opts);
|
|
@@ -230,7 +230,7 @@ export declare function upstreamUnavailableMessage(status: number): string;
|
|
|
230
230
|
* status-specific message and `expected` classification unchanged.
|
|
231
231
|
*/
|
|
232
232
|
export declare function raiseIfUpstreamUnavailable(res: Response): void;
|
|
233
|
-
export declare function raiseIfUnauthorized(res: Response): void;
|
|
233
|
+
export declare function raiseIfUnauthorized(res: Response, body?: unknown): void;
|
|
234
234
|
/**
|
|
235
235
|
* A member connected, reinstalled, or signed in to an app that someone else
|
|
236
236
|
* already connected for the company. Members may add apps and reconnect their
|