@indigoai-us/hq-cli 5.345.236 → 5.345.237
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 +38 -0
- package/dist/command-catalog.generated.d.ts +1 -1
- package/dist/command-catalog.generated.js +1 -1
- package/dist/commands/bot.js +9 -0
- package/dist/commands/daemon.d.ts +1 -0
- package/dist/commands/daemon.js +70 -6
- package/dist/commands/deploy-app-db.js +4 -19
- package/dist/commands/deploy-app-upload.js +66 -40
- package/dist/commands/deploy-mutations.js +24 -16
- package/dist/commands/deploy-runtime-bindings.js +7 -26
- package/dist/commands/deploy-ssr.js +5 -24
- package/dist/commands/mesh.js +6 -2
- package/dist/commands/signals-run.d.ts +43 -2
- package/dist/commands/signals-run.js +85 -7
- package/dist/commands/sync-core.d.ts +7 -0
- package/dist/commands/sync-core.js +52 -3
- package/dist/lib/bot/continuity.d.ts +21 -2
- package/dist/lib/bot/continuity.js +48 -19
- package/dist/lib/bot/fleet-cron.js +6 -0
- package/dist/lib/bot/fleet-local.d.ts +11 -1
- package/dist/lib/bot/fleet-local.js +21 -1
- package/dist/lib/bot/fleet-state.d.ts +129 -0
- package/dist/lib/bot/fleet-state.js +669 -0
- package/dist/lib/bot/promote.d.ts +9 -3
- package/dist/lib/bot/promote.js +115 -16
- package/dist/lib/daemon/catalog.d.ts +13 -0
- package/dist/lib/daemon/catalog.js +32 -6
- package/dist/lib/daemon/lanes-reconcile-status.d.ts +0 -4
- package/dist/lib/daemon/lanes-reconcile-status.js +2 -12
- package/dist/lib/daemon/lanes-reconcile-watcher.d.ts +1 -1
- package/dist/lib/daemon/lanes-reconcile-watcher.js +2 -1
- package/dist/lib/daemon/legacy-handover.d.ts +38 -0
- package/dist/lib/daemon/legacy-handover.js +117 -0
- package/dist/lib/daemon/mesh-owner.js +2 -1
- package/dist/lib/daemon/run.d.ts +18 -1
- package/dist/lib/daemon/run.js +85 -12
- package/dist/lib/daemon/selfcheck.d.ts +28 -0
- package/dist/lib/daemon/selfcheck.js +86 -15
- package/dist/lib/deploy-api.d.ts +1 -1
- package/dist/lib/deploy-api.js +2 -1
- package/dist/lib/deploy-identity.d.ts +18 -0
- package/dist/lib/deploy-identity.js +179 -0
- package/dist/lib/hot-channels/alert.js +13 -6
- package/dist/lib/hot-channels/fleet-complete.d.ts +89 -0
- package/dist/lib/hot-channels/fleet-complete.js +157 -0
- package/dist/lib/hot-channels/run.js +2 -1
- package/dist/lib/hot-channels/signals-claude-login.d.ts +3 -2
- package/dist/lib/hot-channels/signals-claude-login.js +6 -1
- package/dist/lib/hot-channels/signals-pass-failure.d.ts +29 -0
- package/dist/lib/hot-channels/signals-pass-failure.js +36 -0
- package/dist/lib/hot-channels/signals-pass.d.ts +49 -2
- package/dist/lib/hot-channels/signals-pass.js +188 -12
- package/dist/lib/hot-channels/signals-runtime.d.ts +6 -3
- package/dist/lib/hot-channels/signals-runtime.js +11 -2
- package/dist/lib/lanes/reconcile-result.d.ts +5 -0
- package/dist/lib/lanes/reconcile-result.js +20 -2
- package/dist/lib/lanes/reconcile.js +12 -3
- package/dist/lib/mesh/live/emit.js +25 -6
- package/dist/lib/mesh/live/flush.js +119 -15
- package/dist/lib/mesh/live/reporting-privacy.d.ts +41 -0
- package/dist/lib/mesh/live/reporting-privacy.js +147 -1
- package/dist/lib/mesh/live/spool.d.ts +16 -0
- package/dist/lib/mesh/live/spool.js +45 -0
- package/dist/lib/signals/engine.d.ts +17 -3
- package/dist/lib/signals/engine.js +28 -9
- package/dist/lib/signals/failure-alert.d.ts +33 -1
- package/dist/lib/signals/failure-alert.js +72 -5
- package/dist/lib/signals/owner-notice.d.ts +94 -0
- package/dist/lib/signals/owner-notice.js +233 -0
- package/dist/lib/signals/reply.d.ts +7 -0
- package/dist/lib/signals/reply.js +23 -3
- package/dist/lib/signals/steps/adapters.d.ts +51 -2
- package/dist/lib/signals/steps/adapters.js +213 -7
- package/dist/lib/signals/steps/extract.js +18 -4
- package/dist/lib/signals/steps/types.d.ts +63 -1
- package/dist/lib/signals/steps/types.js +32 -0
- package/dist/lib/sync-core/engine-auth.d.ts +35 -0
- package/dist/lib/sync-core/engine-auth.js +96 -0
- package/dist/lib/sync-core/engine-home.d.ts +6 -0
- package/dist/lib/sync-core/engine-home.js +12 -0
- package/dist/lib/sync-core/rollout-state.d.ts +1 -0
- package/dist/lib/sync-core/rollout-state.js +3 -0
- package/dist/lib/vault-sync-switches.d.ts +7 -0
- package/dist/lib/vault-sync-switches.js +56 -0
- package/dist/lib/work-context/errors.d.ts +12 -0
- package/dist/lib/work-context/errors.js +15 -0
- package/dist/lib/work-context/organize.js +6 -1
- package/dist/lib/work-context/reconcile.js +20 -1
- package/dist/utils/resident-package-preload.js +34 -4
- package/docs/anywhere-runtime.md +6 -0
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,44 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [5.345.237] — 2026-11-19
|
|
6
|
+
- Declare the tests for the Unicode credential and released secrets guard replay differences.
|
|
7
|
+
- Declare the existing tests for five dispatcher replay differences.
|
|
8
|
+
- Declare the existing tests for the two env-file replay differences.
|
|
9
|
+
- Preserve configured Grok prompt bookkeeping after the native host adapter.
|
|
10
|
+
- Verify the Codex UserPromptSubmit adapter claim alongside released behavior parity.
|
|
11
|
+
- Test: require Rust hook difference ledgers to declare each referenced test function explicitly.
|
|
12
|
+
- `hq bot promote` now moves an HQ Fleet Runtime bot's learned skills and its scheduled jobs that report to its owner in the HQ DM. They travel in the promotion snapshot under `memory/fleet-state/`, with a record of the bot's runtime, provider, model, effort and timezone. Of those settings only the timezone is used, to pin the carried jobs' schedules; the cloud bot's model follows HQ's brain rules for the move. Memory notes are not carried: the computer's shared memory store cannot yet be separated per bot, so every note stays on the computer, and the snapshot records only whether any stayed, not how many.
|
|
13
|
+
- A learned skill stays behind when HQ's secret scanner (the same rules as `hq scan secrets`) finds a key or token in one of its files, when a file has a key or credentials name (`.pem`, `.key`, `.p12`, `.pfx`, `id_rsa`, `credentials*`, `secrets.*`, `.env*`), when it holds a path the cloud importer refuses, such as `node_modules` or `auth.json`, or when one of its files is over 4 MiB, the cloud computer's per-file limit. Placeholders and references such as `API_KEY=your-api-key-here`, `TOKEN_URL=https://…`, `op://…` and `hq://secrets/…` no longer hold a skill back, and a very long line is checked in bounded time. A skill also stays when a file's path looks like a key, or when a file has a line over 64 KiB, which is not scanned. `gitleaks:allow` and `hq-secret-scan:allow` markers do not exempt carried files. Learned skills that together pass one transfer's 2000-file or 32 MiB limit fail the move before any file is read or scanned, naming the skills largest first, and each file is scanned once per promotion. At most 500 learned skills move, as the cloud computer installs no more; the rest are listed as past the limit. A skill whose folder name looks like a key is listed as `(name withheld)` and never carried, and a provider or model name that looks like a key is left out of the recorded settings. No skills move when the runtime's bundled-skill list is missing.
|
|
14
|
+
- A scheduled job stays behind, with the reason printed, when its instructions or any other field it would carry (name, schedule, skills, state) look like they hold a secret, it is limited to certain tools, its id is not 1 to 64 letters, digits, `_` or `-`, its cron line has a line break, its interval is not a whole number of minutes from 1 to 525600, its repeat count is not a whole number, its one-time `run_at` is not an ISO 8601 time the cloud computer reads (a time without an offset is read in the job's or the bot's zone), its time zone is not one the cloud computer accepts, it has already run as many times as it was set to, or it is past the first 200 carried jobs. A job left behind is listed by id and name only when they hold no secret. A carried job keeps its state only when it is paused; any other state is carried as scheduled. Job text is scanned once per promotion. A top-level timezone the cloud computer would not accept is replaced by this computer's zone.
|
|
15
|
+
- The command prints what moves and what stays, `--json` adds a `fleetState` field for these bots, and a snapshot the cloud importer would refuse fails on the computer before the bot is held, stopped or uploaded, naming the learned skills to remove when they are the cause. If the snapshot fails after this run held the bot, the hold is removed and the bot started again if it was running; if a hold from an earlier run remains, the message says to rerun `hq bot promote <name> --company <uid>` or cancel. When HQ reports the earlier move as canceled and the snapshot then fails, the bot is started again if it was running before that move, and the message says so. The recorded runtime, model and effort, and so the printed summary, come from the brain sent to HQ (the Fleet profile first), not from `bot.json`. Bots that do not run on the HQ Fleet Runtime are unchanged.
|
|
16
|
+
- `hq bot promote` treats a 5xx answer to the prepare request like a lost answer: it asks HQ whether it recorded the move before releasing the bot. For an HQ Fleet bot the model in its Fleet profile is sent instead of `bot.json`'s when the profile's provider is known, and a profile model starting with `claude`, `anthropic/`, `grok`, `x-ai/` or `xai/` marks the bot as Claude or Grok.
|
|
17
|
+
- `hq bot promote --cancel` keeps the hold when HQ will not show the move and then answers that it has no move to cancel, and prints how to free the bot by hand, naming every file to delete: the hold, `promotion-hold-origin.json`, `promotion-active.json` and the frozen snapshots. The 8-minute cap on waiting for the cloud copy to shut down is measured on the clock, so slow requests count toward it.
|
|
18
|
+
- Harden native scope checks for uncertain function calls and zsh runtime state, and cover the mandatory scope guard on all five hosts.
|
|
19
|
+
- Close four native scope-guard bypasses: a zsh multi-name `for` loop glued to a case pattern, a `}` used as a case word, zsh `argv` outside a function body, and zsh extendedglob patterns (`#`, `^`, `~`) in a company path.
|
|
20
|
+
- Close two more native scope-guard bypasses: a `}` or other reserved word after an assignment or redirection (bash reads it as a command name, so the function body stays open), and zsh glob groups such as `companies/oth(e|x)rco` or `(companies)/...` in a path. zsh numeric globs (`<1-9>`) and glob qualifiers that run code are refused too.
|
|
21
|
+
- Close a native scope-guard bypass under bash 3.2 (macOS `/bin/bash` and `/bin/sh`), which has no `coproc` keyword: a reserved word, a group or nothing after `coproc` is refused. Bound functions that use `case $1 in ...` or the `[ ... ]` test command are allowed again.
|
|
22
|
+
- signals: the hot-channel signals pass runs on an HQ Fleet Executive bot's own login. When the Executive bot is a Claude or Codex HQ Fleet bot with its `hq-fleet-local` helper installed, each document goes through `hq-fleet-local complete` (one locked-down turn with the login the bot answers chat with), so signals no longer need a separate `claude auth login` and keep running while the `claude` CLI is signed out. An API-key login is refused. The pass falls back to the `claude` CLI only when the helper is missing or has no `complete` command; a Grok Fleet bot keeps the `claude` CLI path for now. A bot that cannot sign in fails with a distinct bot-login outcome; alerts and job notices point at its Brain profile. API-key logins get subscription-switch advice. A pass using another login retires the old Claude Code sign-out record, and bot status ignores it for Fleet completion targets.
|
|
23
|
+
|
|
24
|
+
- A scheduled signals run that could not do its work now tells the owner the same morning. When the signals pass found its login signed out, failed, or left landed documents unread at its document cap, or the run failed, `hq signals run --report-found` (the HQ Fleet job, whose output reaches the owner as an HQ DM) prints a plain notice with its fix. If the run used the Fleet bot's own login, a sign-out points to the bot's Brain profile in HQ to reconnect. If the run used the Claude Code fallback, the notice names that login and asks the owner to decide how signals should run; reconnecting the bot does not fix that fallback. Other causes link to Try now on the Daily Brief page. It prints no error code and no command. One notice per company per day per cause; after a told problem, the next clean run says signals are running again. State is in `workspace/signals/notices/{company}.json`. The bot's run reply for a blocked pass leads with the same words and keeps the run's own guidance, such as a reconnect step, after them.
|
|
25
|
+
|
|
26
|
+
- Notices distinguish Fleet bot login failures from the Claude CLI fallback and the bot Codex CLI; unsupported own-login setups call for an owner decision. The run detail records the selected login route.
|
|
27
|
+
- `hq signals run` now creates signals for the hot-channel sources its adapters step lands (meetings, Slack, Linear, Attio), using the same local signals pass, sign-in and document cap as `hq sources sync`. Before, a company whose bot job ran the signals engine landed a meeting, moved the cursor past it and wrote no signal. The run record counts the pass's signals in `counts.signalsOut`, sets `engine` and `account` from the pass when extract ran no model turn, and records the pass under the adapters step (`signalsOut`, `modelTurns`, `detail.signalsPass`). A pass that does not finish (Claude Code signed out, out of usage, a timeout), or whose document cap leaves a landed document unread, makes the run `partial` and leaves the landed documents queued in `sources/_signals-pending/` for the next run. The existing signals-failure alert fires when the pass failed after a landing, when its tool is signed out, or when the cap left everything an adapter landed unread. A channel folder with a `source.yaml` stays with the extract step. `hq signals run --report-found` also prints the owner's reply for signals the pass wrote and for those pass failures.
|
|
28
|
+
- The hot-channel signals pass now gives every `claude` call (the `claude auth status` check and each `claude -p` turn) only an allowlisted environment (`CLAUDE_SIGNALS_ENV_ALLOWLIST`), so `ANTHROPIC_API_KEY`, `ANTHROPIC_AUTH_TOKEN`, `ANTHROPIC_BASE_URL`, `CLAUDE_CODE_USE_BEDROCK`, `CLAUDE_CODE_USE_VERTEX` and any other parent variable never reach it, and the check refuses a Claude Code login that is an API key or a Bedrock/Vertex provider. The pass runs only on the subscription login, never an API key.
|
|
29
|
+
- Extraction turns (including incremental extraction) and fallback login checks now use the same Claude environment allowlist.
|
|
30
|
+
- `hq sync-core status` (text and `--json`) and the daemon's sync-engine self-check now report when the sync service keeps refusing the engine's token (HTTP 401) for a vault. Before, the engine unit kept running and looked healthy while nothing synced.
|
|
31
|
+
- The move from the old sync to the new sync engine now finishes on its own: the daemon asks an old sync runner that was started before a vault's switch changed to stop, so the desktop app relaunches it with the current switches. This covers a vault moving to the engine and a vault moved back to the old sync. It is never done for a vault the engine cannot run yet, and never on Windows. A handover still waiting after 10 minutes shows as stuck in `hq daemon status` or `hq sync-core status`, and the sync self-check reports it.
|
|
32
|
+
- Work Mesh now runs whenever a vault is on the new sync engine in full mode, even when the daemon config disables it, and `hq daemon disable mesh` says so. The sync self-check restarts Work Mesh or takes it over from an older unit before it sends a DM, at most once every 3 hours, and leaves a crash-looping Work Mesh alone.
|
|
33
|
+
- `hq sync-core status` shows, for each vault, whether its engine is running or waiting (and why) and whether its push channel is connected.
|
|
34
|
+
- `hq deploy upload-app` now retries the same app archive within a bounded window while its database is being created.
|
|
35
|
+
- Deploy metadata reads, app archive uploads, SSR registration, database enablement, and runtime binding commands keep the selected HQ identity and scope when recovering from a rejected session.
|
|
36
|
+
- Daemon status and logs now identify missing story ledgers during background lane reconciliation without exposing lane details.
|
|
37
|
+
- Work Mesh reporting of company work has fewer member off switches. For a session with a verified company binding, the HQ Anywhere person opt-out and `HQ_FLAG_HQ_ANYWHERE_RUNTIME=false|0` no longer stop Work Mesh events; the operator's `hq-anywhere-runtime` switch still stops everything. This also applies to fleet agent hosts that set the variable.
|
|
38
|
+
- Events from before are not sent: the first time HQ Anywhere is seen off on a machine the time is stored in `~/.hq/work-mesh/anywhere-off-since`, and while HQ Anywhere stays off a bound session's events dated before it (or undated) stay in the spool or retry file, unsent and undeleted.
|
|
39
|
+
- With HQ Anywhere off, a session without a verified company binding is unchanged: its events are not sent, held or dropped and its state is not written. A spool that holds no sendable event of a bound session is not claimed; otherwise the lines that are not sent are appended back byte for byte. The acknowledged-register repair no longer writes a binding into a session that has none while a Work Mesh switch is set or HQ Anywhere is off.
|
|
40
|
+
- `hq mesh context untracked` and `hq mesh context organize --untracked` are refused for a session with a verified company binding (`COMPANY_BOUND`; the untracked command exits 4). The message names the way to correct a wrong binding.
|
|
41
|
+
- `hq daemon disable mesh` is refused on a desktop or self-hosted machine while a session on it with a verified company binding was updated in the last 24 hours. The message names the way out.
|
|
42
|
+
|
|
5
43
|
## [5.345.236] — 2026-11-19
|
|
6
44
|
- Test the Claude PostToolUse native claim alongside released dispatcher parity.
|
|
7
45
|
- Verify the Codex SessionStart adapter claim alongside released behavior parity.
|
|
@@ -5663,7 +5663,7 @@ export declare const COMMAND_CATALOG: readonly [{
|
|
|
5663
5663
|
readonly hidden: false;
|
|
5664
5664
|
}, {
|
|
5665
5665
|
readonly flags: "--report-found";
|
|
5666
|
-
readonly description: "Print the owner's run reply only when the run found new signals; print nothing otherwise";
|
|
5666
|
+
readonly description: "Print the owner's run reply only when the run found new signals or its hot-channel signals pass did not finish; print nothing otherwise";
|
|
5667
5667
|
readonly hidden: false;
|
|
5668
5668
|
}, {
|
|
5669
5669
|
readonly flags: "--redo <file>";
|
|
@@ -6880,7 +6880,7 @@ export const COMMAND_CATALOG = [
|
|
|
6880
6880
|
},
|
|
6881
6881
|
{
|
|
6882
6882
|
"flags": "--report-found",
|
|
6883
|
-
"description": "Print the owner's run reply only when the run found new signals; print nothing otherwise",
|
|
6883
|
+
"description": "Print the owner's run reply only when the run found new signals or its hot-channel signals pass did not finish; print nothing otherwise",
|
|
6884
6884
|
"hidden": false
|
|
6885
6885
|
},
|
|
6886
6886
|
{
|
package/dist/commands/bot.js
CHANGED
|
@@ -11,6 +11,7 @@ import { currentHotSignalSyncCompany, hasScheduledBriefJob, hotSignalSyncJobComp
|
|
|
11
11
|
import { CLAUDE_SIGN_IN_STEPS, CODEX_SIGN_IN_STEPS, codexBotSignalsOptInCommand, createClaudeSignalsPass } from "../lib/hot-channels/signals-pass.js";
|
|
12
12
|
import { executiveSignalsRuntimeOptions, signalsPassCodexLogin } from "../lib/hot-channels/signals-runtime.js";
|
|
13
13
|
import { checkClaudeLoginNow, readSignalsClaudeLogin, recordSignalsPassClaudeLogin } from "../lib/hot-channels/signals-claude-login.js";
|
|
14
|
+
import { fleetCompleteTargetFor } from "../lib/hot-channels/fleet-complete.js";
|
|
14
15
|
import { machineTimeZone } from "../lib/bot/job-run.js";
|
|
15
16
|
import { runCompanyHotChannelSync } from "./sources.js";
|
|
16
17
|
import { OwnerContextCache, lookupOwnerContext } from "../lib/bot/owner-context.js";
|
|
@@ -41,6 +42,7 @@ import { hasPromotionHold, promotionHoldSummary } from "../lib/bot/promotion-hol
|
|
|
41
42
|
* list (online flag), and rm. Secrets are never printed.
|
|
42
43
|
*/
|
|
43
44
|
import { assertPromotedBotRemovable, cancelLocalBotPromotion, promoteLocalBot, promotionDetailsError, promotionFailureText, PROMOTION_CANCEL_TIMEOUT_MS } from "../lib/bot/promote.js";
|
|
45
|
+
import { describeFleetState } from "../lib/bot/fleet-state.js";
|
|
44
46
|
import { DecisionsClient } from "../lib/decisions/client.js";
|
|
45
47
|
import { releaseCurrentPackageUseLease, releasePackageUseLeaseAfterResidentPreload } from "../utils/package-use-lease.js";
|
|
46
48
|
import { preloadResidentPackageModules, reportResidentPackagePreloadFailure, runResidentCommandWithPackageLease, } from "../utils/resident-package-preload.js";
|
|
@@ -534,6 +536,8 @@ export function signalsClaudeSignInFor(dir, fleet, record = readSignalsClaudeLog
|
|
|
534
536
|
const executiveBot = resolveExecutiveBot();
|
|
535
537
|
const source = executiveBot?.config ?? null;
|
|
536
538
|
const executiveDir = executiveBot?.dir ?? null;
|
|
539
|
+
if (fleetCompleteTargetFor(source) && record?.loginRoute !== "claude-cli")
|
|
540
|
+
return null;
|
|
537
541
|
if (signalsPassRuntime(source) === "codex")
|
|
538
542
|
return null;
|
|
539
543
|
const signedOutSince = record && !record.signedIn ? (record.signedOutSince ?? record.checkedAt) : null;
|
|
@@ -4325,6 +4329,11 @@ export function registerBotCommand(program) {
|
|
|
4325
4329
|
isRunning: () => readBotListedProcess(dir, config).running,
|
|
4326
4330
|
restart: () => botPromoteSeams.start(name, dir, config),
|
|
4327
4331
|
...(isFleetRuntimeBot(config) ? { runtime: fleetLocalPromotionRuntime(config.agentUid) } : {}),
|
|
4332
|
+
onSnapshot: (fleetState) => {
|
|
4333
|
+
if (fleetState && !opts.json)
|
|
4334
|
+
for (const line of describeFleetState(fleetState))
|
|
4335
|
+
console.log(line);
|
|
4336
|
+
},
|
|
4328
4337
|
}), { command: "hq bot promote" });
|
|
4329
4338
|
let details = null;
|
|
4330
4339
|
let detailsError = null;
|
|
@@ -90,6 +90,7 @@ export declare function runLogs(d: DaemonCommandDeps, unit: string | undefined,
|
|
|
90
90
|
follow?: boolean;
|
|
91
91
|
lines?: string;
|
|
92
92
|
}): Promise<void>;
|
|
93
|
+
export declare function repairWorkMesh(d: DaemonCommandDeps, action: "take-over" | "restart" | null): string | null;
|
|
93
94
|
export declare function registerDaemonCommand(program: Command, over?: Partial<DaemonCommandDeps>): Command;
|
|
94
95
|
export {};
|
|
95
96
|
//# sourceMappingURL=daemon.d.ts.map
|
package/dist/commands/daemon.js
CHANGED
|
@@ -20,12 +20,14 @@ import * as fs from "node:fs";
|
|
|
20
20
|
import * as os from "node:os";
|
|
21
21
|
import * as path from "node:path";
|
|
22
22
|
import { SYNC_WAKE_STATE_BASENAME, workMeshRoot } from "../lib/mesh/live/paths.js";
|
|
23
|
+
import { anyRecentSessionHasWorkMeshCompanyBinding, MESH_SERVICE_REQUIRED_NOTICE } from "../lib/mesh/live/reporting-privacy.js";
|
|
23
24
|
import { homeIsLoginSafe, meshJobLoadedForHome } from "../lib/mesh/live/daemon/unit-home.js";
|
|
24
25
|
import { randomBytes } from "node:crypto";
|
|
25
26
|
import { spawn, spawnSync } from "node:child_process";
|
|
26
27
|
import { once } from "node:events";
|
|
27
28
|
import { compare as semverCompare, major as semverMajor, valid as validSemver } from "semver";
|
|
28
29
|
import { DEFAULT_SERVICES, SERVICE_DESCRIPTIONS, enabledServices, hqCloudUnits } from "../lib/daemon/catalog.js";
|
|
30
|
+
import { engineVaultCount } from "../lib/sync-core/rollout-state.js";
|
|
29
31
|
import { applyServiceToggle, effectiveSyncOwner, readDaemonConfig, writeDaemonConfig } from "../lib/daemon/config.js";
|
|
30
32
|
import { daemonUnitInstalled } from "../lib/daemon/handoff.js";
|
|
31
33
|
import { adoptLegacyUnits, readAdoptedUnits, restoreLegacyUnits } from "../lib/daemon/migrate.js";
|
|
@@ -192,8 +194,12 @@ function detect(d, flag, config) {
|
|
|
192
194
|
readFileSync: d.readFile,
|
|
193
195
|
});
|
|
194
196
|
}
|
|
195
|
-
function describeServices(machineType, config) {
|
|
196
|
-
|
|
197
|
+
function describeServices(machineType, config, engineVaults = 0) {
|
|
198
|
+
const lines = enabledServices(machineType, config, { engineVaults }).map((s) => ` ${s.padEnd(16)} ${SERVICE_DESCRIPTIONS[s]}`);
|
|
199
|
+
if (enabledServices(machineType, config, { engineVaults }).includes("mesh") && !enabledServices(machineType, config).includes("mesh")) {
|
|
200
|
+
lines.push(" mesh is kept on although disabled: the new sync engine needs it for change notifications while a vault is on it");
|
|
201
|
+
}
|
|
202
|
+
return lines;
|
|
197
203
|
}
|
|
198
204
|
function hostFor(d, paths, pathEnv) {
|
|
199
205
|
const env = {};
|
|
@@ -311,7 +317,7 @@ async function runInstall(d, opts) {
|
|
|
311
317
|
// The older Work Mesh unit is taken over by the install itself once the
|
|
312
318
|
// daemon is running (feedback_c85ad51b): left alone, it kept running beside
|
|
313
319
|
// the daemon until someone ran `hq daemon migrate --apply` by hand.
|
|
314
|
-
const meshTakeover = scope === "user" && enabledServices(detected.type, config).includes("mesh")
|
|
320
|
+
const meshTakeover = scope === "user" && enabledServices(detected.type, config, { engineVaults: engineVaultCount(d.home) }).includes("mesh")
|
|
315
321
|
? migratable.filter((u) => u.service === "mesh" && u.kind !== "systemd-system")
|
|
316
322
|
: [];
|
|
317
323
|
const noteLegacy = (u) => d.out(`Note: ${describeLegacyUnit(u)} still runs ${u.unitId}. The daemon leaves it alone until \`hq daemon migrate\` takes it over.`);
|
|
@@ -972,11 +978,19 @@ async function runToggle(d, action, services) {
|
|
|
972
978
|
const { paths } = host;
|
|
973
979
|
const config = readDaemonConfig(paths.configPath);
|
|
974
980
|
const machineType = host.detected.type;
|
|
981
|
+
// Work Mesh reporting of company work has no member off switch. On a
|
|
982
|
+
// member's own machine the mesh service cannot be switched off while a
|
|
983
|
+
// session here with a verified company binding was updated in the last 24
|
|
984
|
+
// hours. Agent machines have no member and are unchanged.
|
|
985
|
+
if (action === "disable" && services.includes("mesh") && (machineType === "desktop" || machineType === "self-hosted") &&
|
|
986
|
+
anyRecentSessionHasWorkMeshCompanyBinding(d.home, d.env)) {
|
|
987
|
+
throw new DaemonCommandError(MESH_SERVICE_REQUIRED_NOTICE);
|
|
988
|
+
}
|
|
975
989
|
const next = applyServiceToggle(config, action, services, DEFAULT_SERVICES[machineType]);
|
|
976
990
|
writeDaemonConfig(paths.configPath, next);
|
|
977
991
|
handOver(d, host);
|
|
978
992
|
d.out(`Services for this ${machineType} machine:`);
|
|
979
|
-
for (const line of describeServices(machineType, next))
|
|
993
|
+
for (const line of describeServices(machineType, next, engineVaultCount(d.home)))
|
|
980
994
|
d.out(line);
|
|
981
995
|
d.out("A running daemon picks this up within 15 seconds.");
|
|
982
996
|
}
|
|
@@ -1558,6 +1572,24 @@ async function runServiceCodexRemoteControl(d, opts) {
|
|
|
1558
1572
|
watch: codex,
|
|
1559
1573
|
});
|
|
1560
1574
|
}
|
|
1575
|
+
export function repairWorkMesh(d, action) {
|
|
1576
|
+
if (action === "restart") {
|
|
1577
|
+
queueRequest(d, { action: "restart", unit: "mesh" }, "restart mesh");
|
|
1578
|
+
return "asked the daemon to restart Work Mesh";
|
|
1579
|
+
}
|
|
1580
|
+
if (action !== "take-over")
|
|
1581
|
+
return null;
|
|
1582
|
+
const host = currentHost(d);
|
|
1583
|
+
const units = legacyUnitsFor(d, host).filter((u) => u.service === "mesh" && u.migratable && u.kind !== "systemd-system");
|
|
1584
|
+
if (units.length === 0)
|
|
1585
|
+
return null;
|
|
1586
|
+
const result = adoptLegacyUnits(units, { ...migrateDeps(d, host.paths, host.runAsUser), sleep: d.sleep });
|
|
1587
|
+
for (const f of result.failed)
|
|
1588
|
+
d.err(`could not take over mesh from ${describeLegacyUnit(f.unit)}: ${f.error}`);
|
|
1589
|
+
return result.adopted.length > 0
|
|
1590
|
+
? `took over Work Mesh from ${result.adopted.map((u) => describeLegacyUnit(u)).join(", ")}`
|
|
1591
|
+
: null;
|
|
1592
|
+
}
|
|
1561
1593
|
/**
|
|
1562
1594
|
* DM the person signed in on this machine (the machine owner) through the
|
|
1563
1595
|
* same route as `hq dm`. A machine identity (agent box) has no person to tell.
|
|
@@ -1567,6 +1599,26 @@ async function runServiceCodexRemoteControl(d, opts) {
|
|
|
1567
1599
|
* in ~/.hq/sync-core/skip.json or not on the rollout recorded in rollout.json
|
|
1568
1600
|
* is kept on the old sync on purpose, so a hold left over for it is not an outage.
|
|
1569
1601
|
*/
|
|
1602
|
+
/** Engine units on this machine whose cycles the sync service keeps refusing (401). */
|
|
1603
|
+
async function engineAuthRefusals(home, unitLogPath) {
|
|
1604
|
+
const [{ readSyncCoreRolloutState }, { syncCoreUnitId }, { describeAuthRefusal, readEngineAuthRefusal }] = await Promise.all([
|
|
1605
|
+
import("../lib/sync-core/rollout-state.js"),
|
|
1606
|
+
import("../lib/sync-core/engine-home.js"),
|
|
1607
|
+
import("../lib/sync-core/engine-auth.js"),
|
|
1608
|
+
]);
|
|
1609
|
+
let vaults = [];
|
|
1610
|
+
try {
|
|
1611
|
+
vaults = readSyncCoreRolloutState(home)?.vaults ?? [];
|
|
1612
|
+
}
|
|
1613
|
+
catch {
|
|
1614
|
+
return [];
|
|
1615
|
+
}
|
|
1616
|
+
return vaults.flatMap((vault) => {
|
|
1617
|
+
const unitId = syncCoreUnitId(vault.uid);
|
|
1618
|
+
const refused = readEngineAuthRefusal(unitLogPath(unitId), vault.engineHome, vault.uid);
|
|
1619
|
+
return refused ? [{ unitId, since: Date.parse(refused.lastAt), what: describeAuthRefusal(refused) }] : [];
|
|
1620
|
+
});
|
|
1621
|
+
}
|
|
1570
1622
|
async function selfCheckVaults(home) {
|
|
1571
1623
|
const [{ readSyncCoreSkips }, { readSyncCoreRolloutState }] = await Promise.all([
|
|
1572
1624
|
import("../lib/sync-core/skip.js"),
|
|
@@ -1945,10 +1997,11 @@ export function registerDaemonCommand(program, over = {}) {
|
|
|
1945
1997
|
.command("sync-core-selfcheck")
|
|
1946
1998
|
.description("DM the person signed in here when a sync engine unit has been held or failing for over 30 minutes (at most daily per unit set)")
|
|
1947
1999
|
.action(wrap(async (d) => {
|
|
1948
|
-
const [{ runSelfCheck, SELF_CHECK_RESULT_FILE }, { readUnitHolds }, { daemonStateFileEnabled }] = await Promise.all([
|
|
2000
|
+
const [{ runSelfCheck, meshRepairAction, SELF_CHECK_RESULT_FILE }, { readUnitHolds }, { daemonStateFileEnabled }, { readLegacyHandoverStuck, LEGACY_HANDOVER_STUCK_FILE }] = await Promise.all([
|
|
1949
2001
|
import("../lib/daemon/selfcheck.js"),
|
|
1950
2002
|
import("../lib/daemon/unit-holds.js"),
|
|
1951
2003
|
import("../lib/daemon/state-file-switch.js"),
|
|
2004
|
+
import("../lib/daemon/legacy-handover.js"),
|
|
1952
2005
|
]);
|
|
1953
2006
|
const { paths } = currentHost(d);
|
|
1954
2007
|
await runSelfCheck({
|
|
@@ -1982,10 +2035,21 @@ export function registerDaemonCommand(program, over = {}) {
|
|
|
1982
2035
|
meshWanted: () => {
|
|
1983
2036
|
const config = readDaemonConfig(paths.configPath);
|
|
1984
2037
|
const { detected } = currentHost(d);
|
|
1985
|
-
return enabledServices(detected.type, config).includes("mesh");
|
|
2038
|
+
return enabledServices(detected.type, config, { engineVaults: engineVaultCount(d.home) }).includes("mesh");
|
|
1986
2039
|
},
|
|
2040
|
+
repairPath: path.join(paths.root, "selfcheck-mesh-repair.json"),
|
|
2041
|
+
repairMesh: async () => repairWorkMesh(d, meshRepairAction((() => {
|
|
2042
|
+
try {
|
|
2043
|
+
return readState(paths);
|
|
2044
|
+
}
|
|
2045
|
+
catch {
|
|
2046
|
+
return null;
|
|
2047
|
+
}
|
|
2048
|
+
})())),
|
|
1987
2049
|
},
|
|
1988
2050
|
...(await selfCheckVaults(d.home)),
|
|
2051
|
+
readRestoreStuck: () => readLegacyHandoverStuck(path.join(paths.root, LEGACY_HANDOVER_STUCK_FILE)),
|
|
2052
|
+
readAuthRefusals: () => engineAuthRefusals(d.home, paths.unitLogPath),
|
|
1989
2053
|
log: (line) => d.out(line),
|
|
1990
2054
|
});
|
|
1991
2055
|
}));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { deployApiRequest } from "../lib/deploy-api.js";
|
|
2
|
-
import {
|
|
2
|
+
import { DeployIdentityError, openDeployIdentity } from "../lib/deploy-identity.js";
|
|
3
3
|
class EnableDatabaseError extends Error {
|
|
4
4
|
}
|
|
5
5
|
const VERIFY_SETTING = "Check the app's database setting before trying again.";
|
|
@@ -7,8 +7,6 @@ function responseError(status) {
|
|
|
7
7
|
switch (status) {
|
|
8
8
|
case 400:
|
|
9
9
|
return new EnableDatabaseError("The deploy service refused the request. Check the app ID and billing acknowledgement.");
|
|
10
|
-
case 401:
|
|
11
|
-
return new EnableDatabaseError("Your deploy sign-in expired. Run hq login and try again.");
|
|
12
10
|
case 403:
|
|
13
11
|
case 404:
|
|
14
12
|
return new EnableDatabaseError("Could not access this app. To continue, check your scope and app ID or ask the app owner.");
|
|
@@ -32,21 +30,8 @@ async function enableDatabase(appId, options) {
|
|
|
32
30
|
if (acknowledgeDatabaseBilling !== true) {
|
|
33
31
|
throw new EnableDatabaseError("Obtain explicit database billing approval before passing --acknowledge-database-billing.");
|
|
34
32
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
const token = await ensureCognitoToken({ tokenSource: "person", interactive: false }).catch(() => {
|
|
39
|
-
throw new EnableDatabaseError("Could not get an HQ person sign-in. Run hq login and try again.");
|
|
40
|
-
});
|
|
41
|
-
const headers = company === undefined
|
|
42
|
-
? { "X-HQ-Deploy-Scope": "personal" }
|
|
43
|
-
: { "X-Org-Slug": company };
|
|
44
|
-
const response = await deployApiRequest(token, `/api/apps/${encodeURIComponent(appId)}`, "PATCH", {
|
|
45
|
-
database: true,
|
|
46
|
-
databaseBillingAcknowledged: true,
|
|
47
|
-
}, headers).catch(() => {
|
|
48
|
-
throw new EnableDatabaseError(`Could not confirm database enablement. ${VERIFY_SETTING}`);
|
|
49
|
-
});
|
|
33
|
+
const request = await openDeployIdentity({ company, personal }, { personOnly: true });
|
|
34
|
+
const response = await request((token, headers) => deployApiRequest(token, "/api/apps/" + encodeURIComponent(appId), "PATCH", { database: true, databaseBillingAcknowledged: true }, headers, { redirect: "error" }));
|
|
50
35
|
if (response.status !== 200)
|
|
51
36
|
throw responseError(response.status);
|
|
52
37
|
const receipt = await response.json().catch(() => null);
|
|
@@ -69,7 +54,7 @@ export function registerDeployAppDatabaseCommand(deploy) {
|
|
|
69
54
|
await enableDatabase(appId, options);
|
|
70
55
|
}
|
|
71
56
|
catch (error) {
|
|
72
|
-
console.error(error instanceof EnableDatabaseError
|
|
57
|
+
console.error(error instanceof EnableDatabaseError || error instanceof DeployIdentityError
|
|
73
58
|
? error.message
|
|
74
59
|
: `Could not confirm database enablement. ${VERIFY_SETTING}`);
|
|
75
60
|
process.exitCode = 1;
|
|
@@ -1,24 +1,18 @@
|
|
|
1
1
|
import { openAsBlob } from "node:fs";
|
|
2
2
|
import { stat } from "node:fs/promises";
|
|
3
3
|
import { deployApiFormRequest } from "../lib/deploy-api.js";
|
|
4
|
-
import {
|
|
4
|
+
import { DeployIdentityError, openDeployIdentity } from "../lib/deploy-identity.js";
|
|
5
5
|
const MAX_ARCHIVE_BYTES = 100 * 1024 * 1024;
|
|
6
|
+
const DATABASE_PROVISIONING_WAIT_MS = 600_000;
|
|
6
7
|
class AppUploadError extends Error {
|
|
7
8
|
}
|
|
8
|
-
function
|
|
9
|
-
if (
|
|
9
|
+
function validateScope(options) {
|
|
10
|
+
if ((options.company !== undefined) === (options.personal === true)) {
|
|
10
11
|
throw new AppUploadError("Choose exactly one of --company <slug> or --personal.");
|
|
11
12
|
}
|
|
12
|
-
if (options.company) {
|
|
13
|
-
|
|
14
|
-
throw new AppUploadError("Use a valid company slug.");
|
|
15
|
-
}
|
|
16
|
-
return { "X-Org-Slug": options.company };
|
|
17
|
-
}
|
|
18
|
-
if (resolveCognitoTokenSource() === "machine") {
|
|
19
|
-
throw new AppUploadError("A machine identity needs an explicit company scope. Choose an authorized company.");
|
|
13
|
+
if (options.company !== undefined && !/^[a-z0-9][a-z0-9-]{0,62}$/.test(options.company)) {
|
|
14
|
+
throw new AppUploadError("Use a valid company slug.");
|
|
20
15
|
}
|
|
21
|
-
return { "X-HQ-Deploy-Scope": "personal" };
|
|
22
16
|
}
|
|
23
17
|
async function loadArchive(path) {
|
|
24
18
|
try {
|
|
@@ -42,37 +36,72 @@ async function loadArchive(path) {
|
|
|
42
36
|
throw new AppUploadError("Could not read the archive. Check the file path and permissions.");
|
|
43
37
|
}
|
|
44
38
|
}
|
|
45
|
-
|
|
46
|
-
if (
|
|
47
|
-
return "Your deploy sign-in expired. Run hq login and try again.";
|
|
48
|
-
if (response.status === 403 || response.status === 404) {
|
|
39
|
+
function failureMessage(status, code) {
|
|
40
|
+
if (status === 403 || status === 404) {
|
|
49
41
|
return "Could not access this app. To continue, check your scope and app ID or ask the app owner.";
|
|
50
42
|
}
|
|
51
|
-
if (
|
|
43
|
+
if (status === 413 || status === 415 || status === 422) {
|
|
52
44
|
return "The deploy service refused the archive. Rebuild it as gzip within 100 MiB and try again.";
|
|
53
45
|
}
|
|
54
|
-
if (
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
46
|
+
if (status === 409 && code === "DATABASE_BILLING_ACK_REQUIRED") {
|
|
47
|
+
return "This deployment needs database billing approval. Obtain approval before acknowledging billing.";
|
|
48
|
+
}
|
|
49
|
+
if (status === 409 && code === "PUBLIC_SECRET_BACKED_DEPLOY_BLOCKED") {
|
|
50
|
+
return "This public app has bound secrets. Add an access gate or obtain explicit approval before acknowledging the risk.";
|
|
51
|
+
}
|
|
52
|
+
return "Could not confirm the app upload. Check deployment history before trying again.";
|
|
53
|
+
}
|
|
54
|
+
async function submitArchive(send) {
|
|
55
|
+
let retry;
|
|
56
|
+
try {
|
|
57
|
+
while (true) {
|
|
58
|
+
const signal = retry?.controller.signal;
|
|
59
|
+
const response = await send(signal);
|
|
60
|
+
if (response.status === 200) {
|
|
61
|
+
const receipt = await response.json().catch(() => null);
|
|
62
|
+
signal?.throwIfAborted();
|
|
63
|
+
return receipt;
|
|
64
|
+
}
|
|
65
|
+
const body = (response.status === 409 || response.status === 503
|
|
66
|
+
? await response.json().catch(() => null)
|
|
67
|
+
: null);
|
|
68
|
+
signal?.throwIfAborted();
|
|
69
|
+
const code = body?.code ?? body?.error?.code;
|
|
70
|
+
if (response.status !== 503 || code !== "DATABASE_PROVISIONING") {
|
|
71
|
+
throw new AppUploadError(failureMessage(response.status, code));
|
|
72
|
+
}
|
|
73
|
+
// The deploy service stops this attempt before activation and reuses the app's pending cluster.
|
|
74
|
+
if (!retry) {
|
|
75
|
+
const controller = new AbortController();
|
|
76
|
+
retry = {
|
|
77
|
+
controller,
|
|
78
|
+
deadline: performance.now() + DATABASE_PROVISIONING_WAIT_MS,
|
|
79
|
+
timer: setTimeout(() => controller.abort(), DATABASE_PROVISIONING_WAIT_MS),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
64
82
|
const hint = body?.retryAfterSeconds;
|
|
65
|
-
const
|
|
66
|
-
|
|
83
|
+
const delaySeconds = typeof hint === "number" && Number.isFinite(hint) ? Math.max(2, Math.min(30, Math.floor(hint))) : 5;
|
|
84
|
+
const delayMs = delaySeconds * 1000;
|
|
85
|
+
if (performance.now() + delayMs >= retry.deadline) {
|
|
86
|
+
throw new AppUploadError("The app database is still being created. Check deployment history before trying again.");
|
|
87
|
+
}
|
|
88
|
+
console.error(`The app database is being created. Retrying the same upload in ${delaySeconds} seconds.`);
|
|
89
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
90
|
+
if (performance.now() >= retry.deadline)
|
|
91
|
+
retry.controller.abort();
|
|
92
|
+
retry.controller.signal.throwIfAborted();
|
|
67
93
|
}
|
|
68
94
|
}
|
|
69
|
-
|
|
95
|
+
finally {
|
|
96
|
+
if (retry)
|
|
97
|
+
clearTimeout(retry.timer);
|
|
98
|
+
}
|
|
70
99
|
}
|
|
71
100
|
async function uploadApp(appId, archive, options) {
|
|
72
101
|
if (!/^(?:[a-f0-9]{8}-(?:[a-f0-9]{4}-){3}[a-f0-9]{12}|app_[A-Za-z0-9_-]+)$/i.test(appId)) {
|
|
73
102
|
throw new AppUploadError("Use the app ID shown by hq deploy list.");
|
|
74
103
|
}
|
|
75
|
-
|
|
104
|
+
validateScope(options);
|
|
76
105
|
const form = new FormData();
|
|
77
106
|
form.set("type", "app");
|
|
78
107
|
form.set("file", await loadArchive(archive), "upload.tar.gz");
|
|
@@ -80,14 +109,11 @@ async function uploadApp(appId, archive, options) {
|
|
|
80
109
|
form.set("database_billing_acknowledged", "true");
|
|
81
110
|
if (options.acknowledgePublicSecretRisk)
|
|
82
111
|
form.set("acknowledge_public_secret_risk", "true");
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (response.status !== 200)
|
|
89
|
-
throw new AppUploadError(await failureMessage(response));
|
|
90
|
-
const receipt = await response.json().catch(() => null);
|
|
112
|
+
const request = await openDeployIdentity(options);
|
|
113
|
+
const appRoute = "/api/apps/" + encodeURIComponent(appId);
|
|
114
|
+
const receipt = await submitArchive((signal) => request((token, headers) => deployApiFormRequest(token, appRoute + "/deploy", form, headers, signal),
|
|
115
|
+
// Provisioning retries already have a deadline and must reuse the accepted identity.
|
|
116
|
+
{ recoverUnauthorized: signal === undefined }));
|
|
91
117
|
const { appId: returnedApp, deployId, version, status, statusUrl } = receipt ?? {};
|
|
92
118
|
if (returnedApp !== appId || typeof deployId !== "string" || !/^[A-Za-z0-9_-]+$/.test(deployId)
|
|
93
119
|
|| typeof version !== "number" || !Number.isSafeInteger(version) || version < 1
|
|
@@ -112,7 +138,7 @@ export function registerDeployAppUploadCommand(deploy) {
|
|
|
112
138
|
await uploadApp(appId, archive, options);
|
|
113
139
|
}
|
|
114
140
|
catch (error) {
|
|
115
|
-
console.error(error instanceof AppUploadError ? error.message : "Could not confirm the app upload. Check deployment history before trying again.");
|
|
141
|
+
console.error(error instanceof AppUploadError || error instanceof DeployIdentityError ? error.message : "Could not confirm the app upload. Check deployment history before trying again.");
|
|
116
142
|
process.exitCode = 1;
|
|
117
143
|
}
|
|
118
144
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { readFile } from "node:fs/promises";
|
|
3
3
|
import { deployApiRequest } from "../lib/deploy-api.js";
|
|
4
|
+
import { DeployIdentityError, openDeployIdentity } from "../lib/deploy-identity.js";
|
|
4
5
|
import { findDeployApp } from "../lib/deploy-apps.js";
|
|
5
6
|
import { ensureCognitoToken } from "../utils/cognito-session.js";
|
|
6
7
|
import { displayText } from "./deploy-comments.js";
|
|
@@ -18,11 +19,11 @@ function id(value) {
|
|
|
18
19
|
throw new DeployMutationError("Invalid app or deployment identifier.");
|
|
19
20
|
return encodeURIComponent(value);
|
|
20
21
|
}
|
|
21
|
-
async function resolveAppId(
|
|
22
|
+
async function resolveAppId(app, lookup) {
|
|
22
23
|
// The service issues UUIDs. The deploy CLI also accepts legacy app_ IDs.
|
|
23
24
|
if (/^(?:[a-f0-9]{8}-(?:[a-f0-9]{4}-){3}[a-f0-9]{12}|app_[A-Za-z0-9_-]+)$/i.test(app))
|
|
24
25
|
return app;
|
|
25
|
-
const match = await findDeployApp(app,
|
|
26
|
+
const match = await findDeployApp(app, lookup);
|
|
26
27
|
if (match.kind === "none")
|
|
27
28
|
throw new DeployMutationError(`No deploy app '${displayText(app)}' in the selected scope.`);
|
|
28
29
|
if (match.kind === "many")
|
|
@@ -45,12 +46,17 @@ async function readLocal(path, what) {
|
|
|
45
46
|
throw new DeployMutationError(`Could not read the ${what} at ${path}. Nothing was sent.`);
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
|
-
|
|
49
|
+
function request(token, route, method, body, scope) {
|
|
50
|
+
return readResponse(deployApiRequest(token, route, method, body, scope));
|
|
51
|
+
}
|
|
52
|
+
async function readResponse(pending) {
|
|
49
53
|
let response;
|
|
50
54
|
try {
|
|
51
|
-
response = await
|
|
55
|
+
response = await pending;
|
|
52
56
|
}
|
|
53
|
-
catch {
|
|
57
|
+
catch (error) {
|
|
58
|
+
if (error instanceof DeployIdentityError)
|
|
59
|
+
throw error;
|
|
54
60
|
throw new DeployMutationError("Could not reach hq-deploy. Retry the operation.");
|
|
55
61
|
}
|
|
56
62
|
if (!response.ok) {
|
|
@@ -67,6 +73,10 @@ async function request(token, route, method, body, scope) {
|
|
|
67
73
|
throw new DeployMutationError("hq-deploy returned an invalid response.");
|
|
68
74
|
}
|
|
69
75
|
}
|
|
76
|
+
async function openMetadataRead(options) {
|
|
77
|
+
const scopedRequest = await openDeployIdentity(options);
|
|
78
|
+
return (route) => readResponse(scopedRequest((token, headers) => deployApiRequest(token, route, "GET", undefined, headers, { redirect: "error" })));
|
|
79
|
+
}
|
|
70
80
|
function requiredText(record, key) {
|
|
71
81
|
if (typeof record[key] !== "string" || !record[key])
|
|
72
82
|
throw new DeployMutationError(`hq-deploy response is missing ${key}.`);
|
|
@@ -94,7 +104,7 @@ function action(fn) {
|
|
|
94
104
|
await fn(...args);
|
|
95
105
|
}
|
|
96
106
|
catch (error) {
|
|
97
|
-
console.error(error instanceof DeployMutationError ? error.message : "Deploy operation failed.");
|
|
107
|
+
console.error(error instanceof DeployMutationError || error instanceof DeployIdentityError ? error.message : "Deploy operation failed.");
|
|
98
108
|
process.exitCode = 1;
|
|
99
109
|
}
|
|
100
110
|
};
|
|
@@ -104,16 +114,15 @@ export function registerDeployMutationsCommand(deploy) {
|
|
|
104
114
|
.action(action(async (app, options) => {
|
|
105
115
|
const context = headers(options);
|
|
106
116
|
const token = await signIn();
|
|
107
|
-
const appId = await resolveAppId(token,
|
|
117
|
+
const appId = await resolveAppId(app, (route) => request(token, route, "GET", undefined, context));
|
|
108
118
|
const record = await request(token, `/api/apps/${id(appId)}`, "GET", undefined, context);
|
|
109
119
|
output({ id: appId, accessMode: record.accessMode ?? null, passwordProtected: record.passwordProtected === true, privateMode: record.privateMode === true }, options);
|
|
110
120
|
}));
|
|
111
121
|
scope(deploy.command("app-info <app>").description("Read deploy app identity and access metadata"))
|
|
112
122
|
.action(action(async (app, options) => {
|
|
113
|
-
const
|
|
114
|
-
const
|
|
115
|
-
const
|
|
116
|
-
const record = await request(token, `/api/apps/${id(appId)}`, "GET", undefined, context);
|
|
123
|
+
const read = await openMetadataRead(options);
|
|
124
|
+
const appId = await resolveAppId(app, read);
|
|
125
|
+
const record = await read("/api/apps/" + id(appId));
|
|
117
126
|
if (record.id !== appId)
|
|
118
127
|
throw new DeployMutationError("hq-deploy returned a different app id.");
|
|
119
128
|
const subdomain = requiredText(record, "subdomain");
|
|
@@ -132,10 +141,9 @@ export function registerDeployMutationsCommand(deploy) {
|
|
|
132
141
|
}));
|
|
133
142
|
scope(deploy.command("history <app>").description("Read deployment history for one app"))
|
|
134
143
|
.action(action(async (app, options) => {
|
|
135
|
-
const
|
|
136
|
-
const
|
|
137
|
-
const
|
|
138
|
-
const record = await request(token, `/api/apps/${id(appId)}/deploys`, "GET", undefined, context);
|
|
144
|
+
const read = await openMetadataRead(options);
|
|
145
|
+
const appId = await resolveAppId(app, read);
|
|
146
|
+
const record = await read("/api/apps/" + id(appId) + "/deploys");
|
|
139
147
|
if (record.appId !== appId)
|
|
140
148
|
throw new DeployMutationError("hq-deploy returned a different app id.");
|
|
141
149
|
if (Array.isArray(record.deploys)) {
|
|
@@ -162,7 +170,7 @@ export function registerDeployMutationsCommand(deploy) {
|
|
|
162
170
|
.action(action(async (app, options) => {
|
|
163
171
|
const context = headers(options);
|
|
164
172
|
const token = await signIn();
|
|
165
|
-
const appId = await resolveAppId(token,
|
|
173
|
+
const appId = await resolveAppId(app, (route) => request(token, route, "GET", undefined, context));
|
|
166
174
|
await request(token, `/api/apps/${id(appId)}`, "PATCH", { active: false }, context);
|
|
167
175
|
output({ app, active: false }, options);
|
|
168
176
|
}));
|