@indigoai-us/hq-cli 5.345.215-beta.0 → 5.345.215
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 +65 -1
- package/assets/scaffold/core/scripts/hq-delegate-verify.sh +5 -2
- package/dist/command-catalog.generated.d.ts +46 -6
- package/dist/command-catalog.generated.js +53 -6
- package/dist/commands/bot.js +64 -6
- package/dist/commands/capacity.d.ts +4 -1
- package/dist/commands/capacity.js +46 -10
- package/dist/commands/cloud.js +1 -1
- package/dist/commands/core-delegate-w1b.js +15 -1
- package/dist/commands/core-policy.js +67 -8
- package/dist/commands/daemon.js +5 -0
- package/dist/commands/files-browse.d.ts +11 -4
- package/dist/commands/files-browse.js +21 -4
- package/dist/commands/files.d.ts +1 -1
- package/dist/commands/files.js +25 -11
- package/dist/commands/integrations-auth-rules.d.ts +27 -0
- package/dist/commands/integrations-auth-rules.js +79 -0
- package/dist/commands/integrations-import.js +124 -12
- package/dist/commands/lanes.js +2 -2
- package/dist/commands/mesh.d.ts +2 -0
- package/dist/commands/mesh.js +60 -35
- package/dist/commands/sync-held.js +5 -2
- package/dist/lazy-commands.js +3 -5
- package/dist/lib/bot/fleet-cron.d.ts +8 -0
- package/dist/lib/bot/fleet-cron.js +35 -3
- package/dist/lib/bot/fleet-daemon.d.ts +46 -0
- package/dist/lib/bot/fleet-daemon.js +99 -1
- package/dist/lib/bot/probe.js +7 -1
- package/dist/lib/bot/run.js +20 -1
- package/dist/lib/bot/runtime/codex.js +1 -1
- package/dist/lib/bot/runtime/grok-acp.d.ts +5 -1
- package/dist/lib/bot/runtime/grok-acp.js +6 -3
- package/dist/lib/bot/runtime/index.js +19 -9
- package/dist/lib/bot/runtime/messages-stream.js +2 -2
- package/dist/lib/bot/runtime/types.d.ts +15 -0
- package/dist/lib/bot/runtime/types.js +9 -0
- package/dist/lib/bot/runtime-failure.d.ts +23 -0
- package/dist/lib/bot/runtime-failure.js +43 -1
- package/dist/lib/capacity/accounts.d.ts +8 -0
- package/dist/lib/capacity/accounts.js +19 -0
- package/dist/lib/capacity/available.d.ts +154 -0
- package/dist/lib/capacity/available.js +905 -0
- package/dist/lib/capacity/codex-availability.d.ts +14 -1
- package/dist/lib/capacity/codex-availability.js +26 -1
- package/dist/lib/capacity/collectors/claude-oauth.d.ts +29 -2
- package/dist/lib/capacity/collectors/claude-oauth.js +104 -7
- package/dist/lib/capacity/collectors/codex.js +10 -7
- package/dist/lib/capacity/ledger.d.ts +37 -1
- package/dist/lib/capacity/ledger.js +207 -30
- package/dist/lib/capacity/project.d.ts +26 -0
- package/dist/lib/capacity/project.js +137 -8
- package/dist/lib/capacity/refusal-rows.d.ts +31 -0
- package/dist/lib/capacity/refusal-rows.js +61 -0
- package/dist/lib/capacity/refusal.d.ts +53 -2
- package/dist/lib/capacity/refusal.js +284 -65
- package/dist/lib/capacity/route.js +46 -11
- package/dist/lib/capacity/widget.d.ts +12 -1
- package/dist/lib/capacity/widget.js +91 -3
- package/dist/lib/daemon/resolver.d.ts +2 -0
- package/dist/lib/daemon/resolver.js +3 -0
- package/dist/lib/daemon/run.d.ts +9 -0
- package/dist/lib/daemon/run.js +54 -1
- package/dist/lib/daemon/server.d.ts +2 -0
- package/dist/lib/daemon/server.js +10 -1
- package/dist/lib/daemon/tcc-eperm.d.ts +153 -0
- package/dist/lib/daemon/tcc-eperm.js +310 -0
- package/dist/lib/delivery/admission.d.ts +86 -0
- package/dist/lib/delivery/admission.js +148 -0
- package/dist/lib/delivery/artifacts.d.ts +7 -1
- package/dist/lib/delivery/artifacts.js +29 -10
- package/dist/lib/delivery/attempt-id.d.ts +13 -0
- package/dist/lib/delivery/attempt-id.js +16 -0
- package/dist/lib/delivery/disposable-target.d.ts +42 -0
- package/dist/lib/delivery/disposable-target.js +111 -0
- package/dist/lib/delivery/effects.d.ts +136 -0
- package/dist/lib/delivery/effects.js +541 -0
- package/dist/lib/delivery/enrollment.d.ts +21 -17
- package/dist/lib/delivery/enrollment.js +83 -5
- package/dist/lib/delivery/escalations.d.ts +51 -0
- package/dist/lib/delivery/escalations.js +60 -0
- package/dist/lib/delivery/lease.d.ts +80 -0
- package/dist/lib/delivery/lease.js +134 -0
- package/dist/lib/delivery/migrations.d.ts +120 -4
- package/dist/lib/delivery/migrations.js +215 -15
- package/dist/lib/delivery/mqtt.d.ts +2 -0
- package/dist/lib/delivery/mqtt.js +7 -0
- package/dist/lib/delivery/reconciler.d.ts +65 -1
- package/dist/lib/delivery/reconciler.js +224 -13
- package/dist/lib/delivery/rpc/client.d.ts +22 -0
- package/dist/lib/delivery/rpc/client.js +159 -0
- package/dist/lib/delivery/rpc/port.d.ts +40 -0
- package/dist/lib/delivery/rpc/port.js +16 -0
- package/dist/lib/delivery/rpc/server.d.ts +30 -0
- package/dist/lib/delivery/rpc/server.js +205 -0
- package/dist/lib/delivery/rpc/wire.d.ts +85 -0
- package/dist/lib/delivery/rpc/wire.js +143 -0
- package/dist/lib/delivery/store.d.ts +2 -0
- package/dist/lib/delivery/store.js +4 -0
- package/dist/lib/delivery/windows-service-install.d.ts +262 -0
- package/dist/lib/delivery/windows-service-install.js +892 -0
- package/dist/lib/delivery/workers/macos.d.ts +16 -1
- package/dist/lib/delivery/workers/macos.js +54 -12
- package/dist/lib/delivery/workers/windows-service-live.d.ts +121 -0
- package/dist/lib/delivery/workers/windows-service-live.js +711 -0
- package/dist/lib/delivery/workers/windows-service-runner.d.ts +33 -0
- package/dist/lib/delivery/workers/windows-service-runner.js +82 -0
- package/dist/lib/delivery/workers/windows-service.d.ts +140 -0
- package/dist/lib/delivery/workers/windows-service.js +584 -0
- package/dist/lib/delivery/workers/windows.d.ts +32 -22
- package/dist/lib/delivery/workers/windows.js +50 -64
- package/dist/lib/hot-channels/adapters/meetings.d.ts +15 -0
- package/dist/lib/hot-channels/adapters/meetings.js +36 -3
- package/dist/lib/hot-channels/signals-pass.d.ts +10 -0
- package/dist/lib/hot-channels/signals-pass.js +71 -2
- package/dist/lib/hot-channels/signals-redo.js +10 -2
- package/dist/lib/lanes/watcher.js +35 -0
- package/dist/lib/signals/steps/extract.js +40 -4
- package/dist/schemas/hq-available-ai.v1.schema.json +76 -0
- package/dist/utils/catalog-runtime-paths.d.ts +34 -0
- package/dist/utils/catalog-runtime-paths.js +53 -0
- package/dist/utils/files-browse-acl.js +1 -1
- package/package.json +7 -7
- package/dist/lib/delivery/workers/windows-boundary.d.ts +0 -453
- package/dist/lib/delivery/workers/windows-boundary.js +0 -693
|
@@ -16,6 +16,7 @@ import { installIntegration, startOAuth } from "./integrations-api.js";
|
|
|
16
16
|
import { loadRevealedSecrets } from "./secrets.js";
|
|
17
17
|
import { registerServer } from "./mcp-registration.js";
|
|
18
18
|
import { personalConnectorSettingsEnabled } from "./personal-connector-settings-flag.js";
|
|
19
|
+
import { apiKeyIsSendable, authHeaderProblem, MAX_AUTH_HEADER_LENGTH } from "./integrations-auth-rules.js";
|
|
19
20
|
const OAUTH_REQUIRED_CODE = "INTEGRATION_FACTORY_OAUTH_REQUIRED";
|
|
20
21
|
/** Claude Desktop's documented connector-config location for the current OS. */
|
|
21
22
|
export function claudeDesktopConfigPath(platform = process.platform, home = os.homedir(), env = process.env) {
|
|
@@ -128,6 +129,63 @@ function isLocal(entry) {
|
|
|
128
129
|
function isRemote(entry) {
|
|
129
130
|
return typeof entry.url === "string";
|
|
130
131
|
}
|
|
132
|
+
const MAX_BASIC_USERNAME_LENGTH = 256;
|
|
133
|
+
const CONNECT_INSTEAD = "connect it with `hq integrations connect`";
|
|
134
|
+
const KEY_UNSENDABLE_REASON = `its key has a space or a character HQ can't send in a header; copy the key again and ${CONNECT_INSTEAD}`;
|
|
135
|
+
/**
|
|
136
|
+
* feedback_950d8abe: `Authorization: Basic <base64 user:password>` maps to
|
|
137
|
+
* hq-pro's Basic scheme ({ placement: authorization, format: basic }), which
|
|
138
|
+
* stores the password as the key and the username beside it, and rebuilds the
|
|
139
|
+
* same header when it calls the app. Before, the whole `Basic <base64>` value
|
|
140
|
+
* was sent as a raw key with an inner space, which hq-pro refuses.
|
|
141
|
+
*/
|
|
142
|
+
function basicCredential(encoded, header) {
|
|
143
|
+
const invalid = { unimportable: "its Authorization: Basic value is not base64-encoded user:password" };
|
|
144
|
+
const unpadded = encoded.replace(/=+$/, "");
|
|
145
|
+
if (!/^[A-Za-z0-9+/]+$/.test(unpadded))
|
|
146
|
+
return invalid;
|
|
147
|
+
const bytes = Buffer.from(unpadded, "base64");
|
|
148
|
+
if (bytes.toString("base64").replace(/=+$/, "") !== unpadded)
|
|
149
|
+
return invalid;
|
|
150
|
+
let pair;
|
|
151
|
+
try {
|
|
152
|
+
pair = new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
return invalid;
|
|
156
|
+
}
|
|
157
|
+
const colon = pair.indexOf(":");
|
|
158
|
+
if (colon < 0)
|
|
159
|
+
return invalid;
|
|
160
|
+
const username = pair.slice(0, colon);
|
|
161
|
+
const password = pair.slice(colon + 1);
|
|
162
|
+
const secrets = [header, encoded, unpadded, pair, password];
|
|
163
|
+
// hq-pro refuses control characters (a pasted line break, tab or NUL) in a
|
|
164
|
+
// Basic username or password.
|
|
165
|
+
if (/\p{Cc}/u.test(pair))
|
|
166
|
+
return { unimportable: KEY_UNSENDABLE_REASON };
|
|
167
|
+
if (username === "") {
|
|
168
|
+
// hq-pro's Basic scheme with no username sends `<key>:`, so an empty
|
|
169
|
+
// username with a password has no equivalent there.
|
|
170
|
+
return { unimportable: `its Basic credentials have no username, which HQ can't store; ${CONNECT_INSTEAD}` };
|
|
171
|
+
}
|
|
172
|
+
// hq-pro stores a Basic username of at most this many characters.
|
|
173
|
+
if (username.length > MAX_BASIC_USERNAME_LENGTH) {
|
|
174
|
+
return {
|
|
175
|
+
unimportable: `its Basic username is longer than ${MAX_BASIC_USERNAME_LENGTH} characters, which HQ can't store; ${CONNECT_INSTEAD}`,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
if (password === "") {
|
|
179
|
+
return { value: username, authScheme: { placement: "authorization", format: "basic" }, secrets };
|
|
180
|
+
}
|
|
181
|
+
return { value: password, authScheme: { placement: "authorization", format: "basic", username }, secrets };
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Read the connector's static key and how hq-pro should send it. Applies
|
|
185
|
+
* hq-pro's header-name and key rules first (feedback_950d8abe), so a key hq-pro
|
|
186
|
+
* would refuse skips this one connector instead of sending a request that
|
|
187
|
+
* comes back as a 400.
|
|
188
|
+
*/
|
|
131
189
|
function staticCredential(entry) {
|
|
132
190
|
if (!entry.headers || typeof entry.headers !== "object" || Array.isArray(entry.headers))
|
|
133
191
|
return undefined;
|
|
@@ -136,13 +194,57 @@ function staticCredential(entry) {
|
|
|
136
194
|
continue;
|
|
137
195
|
if (!/(authorization|api[-_]?key|token|secret)/i.test(key))
|
|
138
196
|
continue;
|
|
139
|
-
|
|
140
|
-
|
|
197
|
+
const value = raw.trim();
|
|
198
|
+
if (/^authorization$/i.test(key)) {
|
|
199
|
+
if (/^Bearer\s+/i.test(value)) {
|
|
200
|
+
const bearer = value.replace(/^Bearer\s+/i, "");
|
|
201
|
+
return apiKeyIsSendable(bearer) ? { value: bearer, secrets: [value, bearer] } : { unimportable: KEY_UNSENDABLE_REASON };
|
|
202
|
+
}
|
|
203
|
+
const basic = /^Basic\s+(\S+)$/i.exec(value);
|
|
204
|
+
if (basic)
|
|
205
|
+
return basicCredential(basic[1], value);
|
|
206
|
+
if (/^Basic\s/i.test(value))
|
|
207
|
+
return basicCredential("", value);
|
|
208
|
+
if (/^\S+\s+\S/.test(value)) {
|
|
209
|
+
return {
|
|
210
|
+
unimportable: `its Authorization header uses a scheme HQ can't import (only Bearer and Basic are imported); ${CONNECT_INSTEAD}`,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
141
213
|
}
|
|
142
|
-
|
|
214
|
+
switch (authHeaderProblem(key)) {
|
|
215
|
+
case "invalid":
|
|
216
|
+
return { unimportable: "its credential header name is not a valid HTTP header name" };
|
|
217
|
+
case "denied":
|
|
218
|
+
return {
|
|
219
|
+
unimportable: `HQ can't send a key in the ${key} header; ${CONNECT_INSTEAD} and the header name from the app's docs, such as X-API-Key`,
|
|
220
|
+
};
|
|
221
|
+
case "too-long":
|
|
222
|
+
return {
|
|
223
|
+
unimportable: `its credential header name is longer than ${MAX_AUTH_HEADER_LENGTH} characters, which HQ can't store`,
|
|
224
|
+
};
|
|
225
|
+
case null:
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
if (!apiKeyIsSendable(value))
|
|
229
|
+
return { unimportable: KEY_UNSENDABLE_REASON };
|
|
230
|
+
return { value, authScheme: { placement: "header", header: key }, secrets: [value] };
|
|
143
231
|
}
|
|
144
232
|
return undefined;
|
|
145
233
|
}
|
|
234
|
+
/** hq-pro's message for a refused install, with the connector's key scrubbed out. */
|
|
235
|
+
function refusalReason(error, credential) {
|
|
236
|
+
// hq-pro never quotes a key; scrub every string derived from the header (raw
|
|
237
|
+
// value, base64 with and without padding, decoded pair, password, key) anyway
|
|
238
|
+
// so a future message can't leak it. Any length: a short key is still a key.
|
|
239
|
+
const secrets = [...new Set([credential?.value, ...(credential?.secrets ?? [])])]
|
|
240
|
+
.filter((secret) => typeof secret === "string" && secret !== "")
|
|
241
|
+
.sort((a, b) => b.length - a.length);
|
|
242
|
+
// One pass, longest alternative first: scrubbing one secret at a time lets a
|
|
243
|
+
// short secret match inside an earlier "[redacted]" marker and split it.
|
|
244
|
+
const pattern = secrets.map((secret) => secret.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|");
|
|
245
|
+
const message = pattern ? error.message.replace(new RegExp(pattern, "g"), "[redacted]") : error.message;
|
|
246
|
+
return `HQ refused this connector${error.code ? ` (${error.code})` : ""}: ${message}`;
|
|
247
|
+
}
|
|
146
248
|
function oauthRequired(error) {
|
|
147
249
|
return error instanceof IntegrationsCliError &&
|
|
148
250
|
(error.code === OAUTH_REQUIRED_CODE || error.oauthProtected === true);
|
|
@@ -190,9 +292,12 @@ function writeLocalConnector(hqRoot, name, company, personal, entry) {
|
|
|
190
292
|
}
|
|
191
293
|
async function importRemote(token, companyUid, name, entry, dryRun) {
|
|
192
294
|
const provider = providerSlug(name);
|
|
295
|
+
const credential = staticCredential(entry);
|
|
296
|
+
if (credential && "unimportable" in credential) {
|
|
297
|
+
return { name, status: "skipped", provider, reason: credential.unimportable };
|
|
298
|
+
}
|
|
193
299
|
if (dryRun)
|
|
194
300
|
return { name, status: "imported", reason: "would connect remote MCP endpoint", provider };
|
|
195
|
-
const credential = staticCredential(entry);
|
|
196
301
|
try {
|
|
197
302
|
return await installRemote(token, companyUid, name, provider, entry, credential);
|
|
198
303
|
}
|
|
@@ -200,14 +305,21 @@ async function importRemote(token, companyUid, name, entry, dryRun) {
|
|
|
200
305
|
// Members may import connectors, but not over an app someone else already
|
|
201
306
|
// connected for the company. Skip that one connector and keep importing
|
|
202
307
|
// the rest rather than aborting the whole run.
|
|
203
|
-
if (
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}
|
|
308
|
+
if (reconnectForbidden(error)) {
|
|
309
|
+
return {
|
|
310
|
+
name,
|
|
311
|
+
status: "skipped",
|
|
312
|
+
provider,
|
|
313
|
+
reason: "already connected by someone else; ask a company owner or admin to reconnect it",
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
// feedback_950d8abe: hq-pro refuses one connector's settings (a header or
|
|
317
|
+
// key the checks above did not catch, a bad URL) with a 400. Skip that
|
|
318
|
+
// connector and keep importing the rest.
|
|
319
|
+
if (error instanceof IntegrationsCliError && error.status === 400) {
|
|
320
|
+
return { name, status: "skipped", provider, reason: refusalReason(error, credential) };
|
|
321
|
+
}
|
|
322
|
+
throw error;
|
|
211
323
|
}
|
|
212
324
|
}
|
|
213
325
|
async function installRemote(token, companyUid, name, provider, entry, credential) {
|
package/dist/commands/lanes.js
CHANGED
|
@@ -94,7 +94,7 @@ import { writeQuestionBody } from "../lib/lanes/questions.js";
|
|
|
94
94
|
import { compactionAfterUsage, } from "../lib/lanes/compaction.js";
|
|
95
95
|
import { parseCliEffort, resolveLaneEffort, } from "../lib/lanes/effort.js";
|
|
96
96
|
import { LanesError } from "../lib/lanes/errors.js";
|
|
97
|
-
import { LedgerCorrupt, LedgerMissing, capacityOptionsFromEnv, readCollectorMark,
|
|
97
|
+
import { LedgerCorrupt, LedgerMissing, capacityOptionsFromEnv, readCollectorMark, readCurrentNow, rebuildNow, } from "../lib/capacity/ledger.js";
|
|
98
98
|
import { pickAccount, refusalHasNoReadings, refusalHasStaleReading, staleReadingTargets, UNKNOWN_USAGE_SCORE, } from "../lib/capacity/route.js";
|
|
99
99
|
import { capacityViewAge } from "../lib/capacity/freshness.js";
|
|
100
100
|
import { applyTerminalToLane, classifyLaneExit, readLatestEnvelopeRecord } from "../lib/lanes/watcher.js";
|
|
@@ -3626,7 +3626,7 @@ async function runCreate(ctx, opts) {
|
|
|
3626
3626
|
};
|
|
3627
3627
|
let view = null;
|
|
3628
3628
|
try {
|
|
3629
|
-
view =
|
|
3629
|
+
view = readCurrentNow(ledgerOptions);
|
|
3630
3630
|
}
|
|
3631
3631
|
catch (err) {
|
|
3632
3632
|
if (err instanceof LedgerCorrupt) {
|
package/dist/commands/mesh.d.ts
CHANGED
|
@@ -13,6 +13,8 @@ export declare function localPrdWithStory(company: {
|
|
|
13
13
|
prdPath: string;
|
|
14
14
|
source: ProjectPlanSource;
|
|
15
15
|
} | null;
|
|
16
|
+
/** 404 PROJECT_VIEW_NOT_FOUND: the project has no Board at all yet. */
|
|
17
|
+
export declare function isMissingBoardProject(error: unknown): boolean;
|
|
16
18
|
type ProjectPlanSource = {
|
|
17
19
|
name?: string;
|
|
18
20
|
description?: string;
|
package/dist/commands/mesh.js
CHANGED
|
@@ -211,6 +211,52 @@ function unknownStoryHint(error, company, projectId, storyId, prdPath) {
|
|
|
211
211
|
code: error?.code,
|
|
212
212
|
});
|
|
213
213
|
}
|
|
214
|
+
/** 404 PROJECT_VIEW_NOT_FOUND: the project has no Board at all yet. */
|
|
215
|
+
export function isMissingBoardProject(error) {
|
|
216
|
+
if (!error || typeof error !== "object" || httpStatus(error) !== 404)
|
|
217
|
+
return false;
|
|
218
|
+
const candidate = error;
|
|
219
|
+
return (candidate.code === "PROJECT_VIEW_NOT_FOUND" ||
|
|
220
|
+
(typeof candidate.message === "string" && candidate.message.includes("PROJECT_VIEW_NOT_FOUND")));
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* PATCH a story. When the story (or its whole project) is not on the Board but
|
|
224
|
+
* the local prd.json lists it, register the PRD (the same merge `hq mesh
|
|
225
|
+
* project ensure` does) and retry once. `ensure: false` only prints the command.
|
|
226
|
+
*/
|
|
227
|
+
async function patchStoryRegisteringLocalPrd(token, company, projectId, storyId, patch, opts) {
|
|
228
|
+
try {
|
|
229
|
+
return { patched: await patchStory(token, company.companyUid, projectId, storyId, patch) };
|
|
230
|
+
}
|
|
231
|
+
catch (err) {
|
|
232
|
+
if (!isUnknownBoardStory(err) && !isMissingBoardProject(err))
|
|
233
|
+
throw err;
|
|
234
|
+
const recovery = localPrdWithStory(company, projectId, storyId);
|
|
235
|
+
if (!recovery)
|
|
236
|
+
throw unknownStoryHint(err, company, projectId, storyId);
|
|
237
|
+
if (opts.ensure === false) {
|
|
238
|
+
throw unknownStoryHint(err, company, projectId, storyId, recovery.prdPath);
|
|
239
|
+
}
|
|
240
|
+
await ensureProjectFromSource({
|
|
241
|
+
token,
|
|
242
|
+
company,
|
|
243
|
+
projectId,
|
|
244
|
+
source: recovery.source,
|
|
245
|
+
current: await getProjectView(token, company.companyUid, projectId).catch((viewErr) => {
|
|
246
|
+
if (httpStatus(viewErr) === 404)
|
|
247
|
+
return undefined;
|
|
248
|
+
throw viewErr;
|
|
249
|
+
}),
|
|
250
|
+
});
|
|
251
|
+
if (!opts.json) {
|
|
252
|
+
console.error(`Work mesh: ${storyId} was not on the ${projectId} Board; registered the project from ${recovery.prdPath}.`);
|
|
253
|
+
}
|
|
254
|
+
return {
|
|
255
|
+
patched: await patchStory(token, company.companyUid, projectId, storyId, patch),
|
|
256
|
+
registeredFrom: recovery.prdPath,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
}
|
|
214
260
|
async function runStory(opts) {
|
|
215
261
|
const storyId = opts.story?.trim();
|
|
216
262
|
const status = opts.status?.trim();
|
|
@@ -249,37 +295,7 @@ async function runStory(opts) {
|
|
|
249
295
|
let patched;
|
|
250
296
|
let registeredFrom;
|
|
251
297
|
try {
|
|
252
|
-
|
|
253
|
-
patched = await patchStory(token, company.companyUid, projectId, storyId, patch);
|
|
254
|
-
}
|
|
255
|
-
catch (err) {
|
|
256
|
-
if (!isUnknownBoardStory(err))
|
|
257
|
-
throw err;
|
|
258
|
-
// The story is in the local PRD but not on the Board yet: register the
|
|
259
|
-
// PRD (the same merge `hq mesh project ensure` does), then retry once.
|
|
260
|
-
const recovery = localPrdWithStory(company, projectId, storyId);
|
|
261
|
-
if (!recovery)
|
|
262
|
-
throw unknownStoryHint(err, company, projectId, storyId);
|
|
263
|
-
if (opts.ensure === false) {
|
|
264
|
-
throw unknownStoryHint(err, company, projectId, storyId, recovery.prdPath);
|
|
265
|
-
}
|
|
266
|
-
await ensureProjectFromSource({
|
|
267
|
-
token,
|
|
268
|
-
company,
|
|
269
|
-
projectId,
|
|
270
|
-
source: recovery.source,
|
|
271
|
-
current: await getProjectView(token, company.companyUid, projectId).catch((viewErr) => {
|
|
272
|
-
if (httpStatus(viewErr) === 404)
|
|
273
|
-
return undefined;
|
|
274
|
-
throw viewErr;
|
|
275
|
-
}),
|
|
276
|
-
});
|
|
277
|
-
registeredFrom = recovery.prdPath;
|
|
278
|
-
if (!opts.json) {
|
|
279
|
-
console.error(`Work mesh: ${storyId} was not on the ${projectId} Board; registered the project from ${recovery.prdPath}.`);
|
|
280
|
-
}
|
|
281
|
-
patched = await patchStory(token, company.companyUid, projectId, storyId, patch);
|
|
282
|
-
}
|
|
298
|
+
({ patched, registeredFrom } = await patchStoryRegisteringLocalPrd(token, company, projectId, storyId, patch, opts));
|
|
283
299
|
}
|
|
284
300
|
catch (err) {
|
|
285
301
|
const conflict = storyConflictFromError(err);
|
|
@@ -315,12 +331,13 @@ async function runClaim(opts) {
|
|
|
315
331
|
const { token, company } = await withCompany(opts);
|
|
316
332
|
const me = await requireAssignableSelf(token, "hq mesh claim");
|
|
317
333
|
let patched;
|
|
334
|
+
let registeredFrom;
|
|
318
335
|
try {
|
|
319
|
-
patched = await
|
|
336
|
+
({ patched, registeredFrom } = await patchStoryRegisteringLocalPrd(token, company, projectId, storyId, {
|
|
320
337
|
status: "in_progress",
|
|
321
338
|
assigneeUid: me,
|
|
322
339
|
...(opts.force ? { force: true } : {}),
|
|
323
|
-
});
|
|
340
|
+
}, opts));
|
|
324
341
|
}
|
|
325
342
|
catch (err) {
|
|
326
343
|
const conflict = storyConflictFromError(err);
|
|
@@ -329,7 +346,14 @@ async function runClaim(opts) {
|
|
|
329
346
|
throw err;
|
|
330
347
|
}
|
|
331
348
|
if (opts.json) {
|
|
332
|
-
console.log(JSON.stringify({
|
|
349
|
+
console.log(JSON.stringify({
|
|
350
|
+
ok: true,
|
|
351
|
+
action: "claim",
|
|
352
|
+
company,
|
|
353
|
+
...patched,
|
|
354
|
+
storyId,
|
|
355
|
+
...(registeredFrom ? { registeredFrom } : {}),
|
|
356
|
+
}, null, 2));
|
|
333
357
|
return;
|
|
334
358
|
}
|
|
335
359
|
console.log(`Work mesh: claimed ${storyId} (in_progress, assignee ${patched.assigneeUid ?? me}) (v${patched.version ?? "?"})`);
|
|
@@ -2750,7 +2774,8 @@ export function registerMeshCommand(program, deps = {}) {
|
|
|
2750
2774
|
.command("claim")
|
|
2751
2775
|
.description("Assign a story to yourself and move it to in_progress")
|
|
2752
2776
|
.requiredOption("--story <id>", "Story id, e.g. US-001")
|
|
2753
|
-
.option("--force", "Take the story even when someone else holds it")
|
|
2777
|
+
.option("--force", "Take the story even when someone else holds it")
|
|
2778
|
+
.option("--no-ensure", "Do not register the project from its local prd.json when the story is not on the Board")).action((opts) => wrap(() => runClaim(opts))());
|
|
2754
2779
|
mesh
|
|
2755
2780
|
.command("overlap")
|
|
2756
2781
|
.description("List other sessions working on the same story, branch, or files")
|
|
@@ -60,7 +60,10 @@ export async function runSyncHeld(deps, json = false) {
|
|
|
60
60
|
deps.log("No uploads are held on this computer.");
|
|
61
61
|
return 0;
|
|
62
62
|
}
|
|
63
|
-
|
|
63
|
+
// First install also writes this hold (feedback_baa82c96). Do not say
|
|
64
|
+
// another account was signed in; that is often false and reads as a
|
|
65
|
+
// security scare. The hold is still a confirmation before upload.
|
|
66
|
+
deps.log("These uploads are held until you confirm they belong to the signed-in account on this computer:");
|
|
64
67
|
for (const scope of scopes)
|
|
65
68
|
for (const line of describe(scope))
|
|
66
69
|
deps.log(line);
|
|
@@ -172,7 +175,7 @@ export function createDefaultSyncHeldDeps() {
|
|
|
172
175
|
export function registerSyncHeldCommands(syncCmd) {
|
|
173
176
|
syncCmd
|
|
174
177
|
.command("held")
|
|
175
|
-
.description("Show uploads held
|
|
178
|
+
.description("Show uploads held until you confirm they belong to the signed-in account")
|
|
176
179
|
.option("--json", "Print the held scopes as JSON")
|
|
177
180
|
.action(async (options) => {
|
|
178
181
|
process.exitCode = await runSyncHeld(createDefaultSyncHeldDeps(), options.json === true);
|
package/dist/lazy-commands.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Argument, Command, Option } from "commander";
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
|
-
import { dirname, join, resolve } from "node:path";
|
|
4
|
+
import { dirname, join, resolve, sep } from "node:path";
|
|
5
5
|
import { COMMAND_CATALOG } from "./command-catalog.generated.js";
|
|
6
6
|
import { installUnknownCommandSuggestions } from "./unknown-command.js";
|
|
7
|
+
import { restoreRuntimeText } from "./utils/catalog-runtime-paths.js";
|
|
7
8
|
import { MissingRegistrationPlanError } from "./utils/registration-plan-error.js";
|
|
8
9
|
const commandCatalog = COMMAND_CATALOG;
|
|
9
10
|
/**
|
|
@@ -71,10 +72,7 @@ function commandDefinition(command) {
|
|
|
71
72
|
}
|
|
72
73
|
function restoreRuntimePath(value) {
|
|
73
74
|
if (typeof value === "string") {
|
|
74
|
-
|
|
75
|
-
if (restored.includes("<runtime-path>"))
|
|
76
|
-
restored = restored.replaceAll("<runtime-path>", runtimeHqRoot());
|
|
77
|
-
return restored;
|
|
75
|
+
return restoreRuntimeText(value, { home: homedir(), hqRoot: runtimeHqRoot }, sep);
|
|
78
76
|
}
|
|
79
77
|
if (Array.isArray(value))
|
|
80
78
|
return value.map(restoreRuntimePath);
|
|
@@ -73,6 +73,12 @@ export declare const FLEET_HOT_SIGNAL_SYNC_NAME = "hot-signal-sync";
|
|
|
73
73
|
export declare const FLEET_HOT_SIGNAL_SYNC_SCHEDULE = "30 6 * * *";
|
|
74
74
|
export declare function fleetHotSignalSyncScript(company: string): string;
|
|
75
75
|
export declare function companyOfHotSignalSyncJob(job: FleetCronJob): string | null;
|
|
76
|
+
/**
|
|
77
|
+
* pnpm global installs land the CLI under `.../pnpm/global/vN/<hash>/...`.
|
|
78
|
+
* That hash folder is removed on the next CLI update. The stable launcher is
|
|
79
|
+
* `.../pnpm/bin/hq`. Empty when `hqBinary` is not a pnpm package entry.
|
|
80
|
+
*/
|
|
81
|
+
export declare function fleetPnpmHqLauncher(hqBinary: string): string;
|
|
76
82
|
export declare function renderFleetHotSignalSyncScript(input: {
|
|
77
83
|
nodeBinary: string;
|
|
78
84
|
hqBinary: string;
|
|
@@ -85,6 +91,8 @@ export declare function renderFleetHotSignalSyncScript(input: {
|
|
|
85
91
|
* the job these bots ran before the engine.
|
|
86
92
|
*/
|
|
87
93
|
signalsEngine?: boolean;
|
|
94
|
+
/** Override the baked pnpm `bin/hq` fallback. Tests pass this. */
|
|
95
|
+
hqLauncher?: string;
|
|
88
96
|
}): string;
|
|
89
97
|
export interface EnsureFleetHotSignalSyncInput {
|
|
90
98
|
dir: string;
|
|
@@ -361,6 +361,31 @@ def classify(out, err, code):
|
|
|
361
361
|
const HOT_SIGNAL_SYNC_RUN_END = String.raw `def run_end(code):
|
|
362
362
|
return 'signal %d' % -code if code < 0 else 'exit %d' % code
|
|
363
363
|
`;
|
|
364
|
+
/**
|
|
365
|
+
* pnpm global installs land the CLI under `.../pnpm/global/vN/<hash>/...`.
|
|
366
|
+
* That hash folder is removed on the next CLI update. The stable launcher is
|
|
367
|
+
* `.../pnpm/bin/hq`. Empty when `hqBinary` is not a pnpm package entry.
|
|
368
|
+
*/
|
|
369
|
+
export function fleetPnpmHqLauncher(hqBinary) {
|
|
370
|
+
const normalized = hqBinary.replace(/\\/g, "/");
|
|
371
|
+
const match = /^(.*)\/pnpm\/global\/v\d+\/[^/]+\/node_modules\/@indigoai-us\/hq-cli\/dist\/index\.js$/i.exec(normalized);
|
|
372
|
+
return match ? `${match[1]}/pnpm/bin/hq` : "";
|
|
373
|
+
}
|
|
374
|
+
const HOT_SIGNAL_SYNC_HQ_ARGV = String.raw `def hq_argv():
|
|
375
|
+
if os.path.isfile(HQ):
|
|
376
|
+
return [NODE, HQ]
|
|
377
|
+
if LAUNCHER and os.path.isfile(LAUNCHER):
|
|
378
|
+
return [LAUNCHER]
|
|
379
|
+
found = shutil.which('hq')
|
|
380
|
+
if found:
|
|
381
|
+
return [found]
|
|
382
|
+
home = os.path.expanduser('~')
|
|
383
|
+
for rel in ('Library/pnpm/bin/hq', '.local/share/pnpm/hq'):
|
|
384
|
+
p = os.path.join(home, rel)
|
|
385
|
+
if os.path.isfile(p):
|
|
386
|
+
return [p]
|
|
387
|
+
raise FileNotFoundError(HQ)
|
|
388
|
+
`;
|
|
364
389
|
export function renderFleetHotSignalSyncScript(input) {
|
|
365
390
|
const plainSync = input.signalsEngine === false;
|
|
366
391
|
const args = plainSync
|
|
@@ -390,9 +415,14 @@ export function renderFleetHotSignalSyncScript(input) {
|
|
|
390
415
|
// plain script exits non-zero after a failed run (128 + N after signal N, as
|
|
391
416
|
// a shell does), so the job's status is not `ok`: Fleet records a no-agent
|
|
392
417
|
// job from its exit code.
|
|
418
|
+
const launcher = input.hqLauncher ?? fleetPnpmHqLauncher(input.hqBinary);
|
|
419
|
+
// HQ is often the pnpm hash folder's dist/index.js. That path dies on the
|
|
420
|
+
// next CLI update (feedback_614121bf). Prefer it while it exists so tests
|
|
421
|
+
// and `node <entry>` callers stay unchanged; otherwise run the stable
|
|
422
|
+
// launcher without node (it is a shell/cmd shim, not JS).
|
|
393
423
|
const run = plainSync
|
|
394
424
|
? [
|
|
395
|
-
" result = subprocess.run(
|
|
425
|
+
" result = subprocess.run(hq_argv() + ARGS, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8', errors='replace')",
|
|
396
426
|
" with open(LOG, 'a', encoding='utf-8') as log:",
|
|
397
427
|
header,
|
|
398
428
|
" log.write(result.stderr)",
|
|
@@ -409,18 +439,20 @@ export function renderFleetHotSignalSyncScript(input) {
|
|
|
409
439
|
" with open(LOG, 'a', encoding='utf-8') as log:",
|
|
410
440
|
header,
|
|
411
441
|
" log.flush()",
|
|
412
|
-
" result = subprocess.run(
|
|
442
|
+
" result = subprocess.run(hq_argv() + ARGS, stdout=subprocess.PIPE, stderr=log, encoding='utf-8', errors='replace')",
|
|
413
443
|
footer,
|
|
414
444
|
" sys.stdout.write(result.stdout)",
|
|
415
445
|
];
|
|
416
446
|
return [
|
|
417
|
-
plainSync ? "import json, os, re, signal, subprocess, sys, time, urllib.parse" : "import subprocess, sys, time",
|
|
447
|
+
plainSync ? "import json, os, re, shutil, signal, subprocess, sys, time, urllib.parse" : "import os, shutil, subprocess, sys, time",
|
|
418
448
|
`NODE = ${JSON.stringify(input.nodeBinary)}`,
|
|
419
449
|
`HQ = ${JSON.stringify(input.hqBinary)}`,
|
|
450
|
+
`LAUNCHER = ${JSON.stringify(launcher)}`,
|
|
420
451
|
`ARGS = ${JSON.stringify(args)}`,
|
|
421
452
|
`LOG = ${JSON.stringify(input.logFile)}`,
|
|
422
453
|
"STARTED = time.localtime()",
|
|
423
454
|
HOT_SIGNAL_SYNC_RUN_END,
|
|
455
|
+
HOT_SIGNAL_SYNC_HQ_ARGV,
|
|
424
456
|
...(plainSync ? [`FIXES = ${JSON.stringify(fixes)}`, HOT_SIGNAL_SYNC_ALERT_HELPERS] : []),
|
|
425
457
|
"try:",
|
|
426
458
|
...run,
|
|
@@ -29,6 +29,52 @@ export interface FleetDaemonHost {
|
|
|
29
29
|
* own LaunchAgents instead.
|
|
30
30
|
*/
|
|
31
31
|
export declare function fleetBotsManagedByDaemon(host?: FleetDaemonHost): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Whether a bot handed to hq daemon now would be picked up:
|
|
34
|
+
* - `not-used`: the daemon does not run this Mac's bots; the runtime's own service does.
|
|
35
|
+
* - `running`: a live daemon holds the lock (a hosted daemon included).
|
|
36
|
+
* - `stopped`: the daemon's login item is installed, so bots are handed to it,
|
|
37
|
+
* but no daemon is running to read the request.
|
|
38
|
+
*/
|
|
39
|
+
export type FleetBotDaemonState = "not-used" | "running" | "stopped";
|
|
40
|
+
export declare function fleetBotDaemonState(host?: FleetDaemonHost & {
|
|
41
|
+
alive?: (pid: number) => boolean;
|
|
42
|
+
}): FleetBotDaemonState;
|
|
43
|
+
/** The one sentence a person sees when hq daemon is off and could not be started. */
|
|
44
|
+
export declare function fleetDaemonStoppedMessage(name: string): string;
|
|
45
|
+
/** hq daemon is installed here but not running, and starting it did not bring it up. */
|
|
46
|
+
export declare class FleetDaemonStoppedError extends Error {
|
|
47
|
+
readonly expected: true;
|
|
48
|
+
readonly reason: "daemon-stopped";
|
|
49
|
+
constructor(name: string);
|
|
50
|
+
}
|
|
51
|
+
/** `hq daemon start` waits up to 15 s for the daemon itself; this bounds the whole command. */
|
|
52
|
+
export declare const FLEET_DAEMON_START_TIMEOUT_MS = 45000;
|
|
53
|
+
/** How long to look for a live daemon after `hq daemon start` returned. */
|
|
54
|
+
export declare const FLEET_DAEMON_LIVE_WAIT_MS = 20000;
|
|
55
|
+
/** Side effects of {@link ensureFleetBotDaemon}; tests replace them. */
|
|
56
|
+
export declare const fleetDaemonSeams: {
|
|
57
|
+
startDaemon: (timeoutMs: number) => {
|
|
58
|
+
ok: boolean;
|
|
59
|
+
detail: string;
|
|
60
|
+
};
|
|
61
|
+
sleep: (ms: number) => void;
|
|
62
|
+
startTimeoutMs: number;
|
|
63
|
+
liveWaitMs: number;
|
|
64
|
+
pollMs: number;
|
|
65
|
+
};
|
|
66
|
+
export interface EnsureFleetDaemonDeps extends FleetDaemonHost {
|
|
67
|
+
alive?: (pid: number) => boolean;
|
|
68
|
+
log?: (message: string) => void;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Before a bot is handed to hq daemon: make sure a daemon is running to pick
|
|
72
|
+
* it up. When the daemon's login item is installed but no daemon is live
|
|
73
|
+
* (unloaded after a failed update, for one), run `hq daemon start` and wait,
|
|
74
|
+
* bounded, for a live daemon. Throws {@link FleetDaemonStoppedError} when it
|
|
75
|
+
* still is not up, so the caller never reports a hand-off nobody will read.
|
|
76
|
+
*/
|
|
77
|
+
export declare function ensureFleetBotDaemon(name: string, deps?: EnsureFleetDaemonDeps): "untouched" | "started";
|
|
32
78
|
export type LaunchctlRun = (args: string[]) => {
|
|
33
79
|
status: number | null;
|
|
34
80
|
};
|
|
@@ -22,7 +22,9 @@ import { botsRoot } from "./paths.js";
|
|
|
22
22
|
import { isPidAlive } from "./status.js";
|
|
23
23
|
import { askDaemonToStart, askDaemonToStop, daemonUnitInstalled, hostedDaemonRunning } from "../daemon/handoff.js";
|
|
24
24
|
import { daemonPaths } from "../daemon/paths.js";
|
|
25
|
-
import { isDaemonProcess } from "../daemon/lock.js";
|
|
25
|
+
import { isDaemonProcess, runningDaemonPid } from "../daemon/lock.js";
|
|
26
|
+
import { resolveHqBinary } from "../mesh/live/daemon/install.js";
|
|
27
|
+
import { blockingSleep } from "../service-manager/launchd.js";
|
|
26
28
|
export const FLEET_BOT_UNIT_PREFIX = "fleet-bots:";
|
|
27
29
|
export function fleetBotUnitId(name) {
|
|
28
30
|
return `${FLEET_BOT_UNIT_PREFIX}${name}`;
|
|
@@ -42,6 +44,97 @@ export function fleetBotsManagedByDaemon(host = {}) {
|
|
|
42
44
|
const paths = host.paths ?? daemonPaths(home);
|
|
43
45
|
return daemonUnitInstalled({ platform, home, windowsTaskName: "", windowsTaskExists: () => false }) || hostedDaemonRunning(paths);
|
|
44
46
|
}
|
|
47
|
+
export function fleetBotDaemonState(host = {}) {
|
|
48
|
+
const platform = host.platform ?? process.platform;
|
|
49
|
+
if (platform !== "darwin")
|
|
50
|
+
return "not-used";
|
|
51
|
+
if ((host.env ?? process.env).HQ_FLEET_BOTS_SERVICE?.trim() === "runtime")
|
|
52
|
+
return "not-used";
|
|
53
|
+
const home = host.home ?? os.homedir();
|
|
54
|
+
const paths = host.paths ?? daemonPaths(home);
|
|
55
|
+
if (runningDaemonPid(paths.lockPath, host.alive ?? ((pid) => isDaemonProcess(pid))) !== null)
|
|
56
|
+
return "running";
|
|
57
|
+
return daemonUnitInstalled({ platform, home, windowsTaskName: "", windowsTaskExists: () => false }) ? "stopped" : "not-used";
|
|
58
|
+
}
|
|
59
|
+
/** The one sentence a person sees when hq daemon is off and could not be started. */
|
|
60
|
+
export function fleetDaemonStoppedMessage(name) {
|
|
61
|
+
const who = name.trim() || "the bot";
|
|
62
|
+
return (`HQ's background service (hq daemon) is off on this Mac and could not be turned on, so ${who} can't start. ` +
|
|
63
|
+
"Try again, or run `hq daemon start` and check `hq daemon logs`; restart your Mac if it keeps happening.");
|
|
64
|
+
}
|
|
65
|
+
/** hq daemon is installed here but not running, and starting it did not bring it up. */
|
|
66
|
+
export class FleetDaemonStoppedError extends Error {
|
|
67
|
+
expected = true;
|
|
68
|
+
reason = "daemon-stopped";
|
|
69
|
+
constructor(name) {
|
|
70
|
+
super(fleetDaemonStoppedMessage(name));
|
|
71
|
+
this.name = "FleetDaemonStoppedError";
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/** `hq daemon start` waits up to 15 s for the daemon itself; this bounds the whole command. */
|
|
75
|
+
export const FLEET_DAEMON_START_TIMEOUT_MS = 45_000;
|
|
76
|
+
/** How long to look for a live daemon after `hq daemon start` returned. */
|
|
77
|
+
export const FLEET_DAEMON_LIVE_WAIT_MS = 20_000;
|
|
78
|
+
const FLEET_DAEMON_LIVE_POLL_MS = 500;
|
|
79
|
+
/** Run `hq daemon start` with this CLI, bounded. Never throws. */
|
|
80
|
+
function defaultStartDaemon(timeoutMs) {
|
|
81
|
+
let entry;
|
|
82
|
+
try {
|
|
83
|
+
entry = resolveHqBinary();
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
return { ok: false, detail: err.message };
|
|
87
|
+
}
|
|
88
|
+
const r = spawnSync(process.execPath, [entry, "daemon", "start"], {
|
|
89
|
+
encoding: "utf8",
|
|
90
|
+
windowsHide: true,
|
|
91
|
+
timeout: timeoutMs,
|
|
92
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
93
|
+
env: { ...process.env, HQ_NO_UPDATE_CHECK: "1", HQ_NO_ENSURE_HQ_DESKTOP: "1" },
|
|
94
|
+
});
|
|
95
|
+
if (r.error)
|
|
96
|
+
return { ok: false, detail: r.error.message };
|
|
97
|
+
const detail = (r.stderr || r.stdout || "").trim().replace(/\s+/g, " ").slice(0, 400);
|
|
98
|
+
return { ok: r.status === 0, detail: r.status === 0 ? detail : `exit ${r.status ?? r.signal}: ${detail}` };
|
|
99
|
+
}
|
|
100
|
+
/** Side effects of {@link ensureFleetBotDaemon}; tests replace them. */
|
|
101
|
+
export const fleetDaemonSeams = {
|
|
102
|
+
startDaemon: defaultStartDaemon,
|
|
103
|
+
sleep: blockingSleep,
|
|
104
|
+
startTimeoutMs: FLEET_DAEMON_START_TIMEOUT_MS,
|
|
105
|
+
liveWaitMs: FLEET_DAEMON_LIVE_WAIT_MS,
|
|
106
|
+
pollMs: FLEET_DAEMON_LIVE_POLL_MS,
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Before a bot is handed to hq daemon: make sure a daemon is running to pick
|
|
110
|
+
* it up. When the daemon's login item is installed but no daemon is live
|
|
111
|
+
* (unloaded after a failed update, for one), run `hq daemon start` and wait,
|
|
112
|
+
* bounded, for a live daemon. Throws {@link FleetDaemonStoppedError} when it
|
|
113
|
+
* still is not up, so the caller never reports a hand-off nobody will read.
|
|
114
|
+
*/
|
|
115
|
+
export function ensureFleetBotDaemon(name, deps = {}) {
|
|
116
|
+
const home = deps.home ?? os.homedir();
|
|
117
|
+
const paths = deps.paths ?? daemonPaths(home);
|
|
118
|
+
const alive = deps.alive ?? ((pid) => isDaemonProcess(pid));
|
|
119
|
+
const host = { platform: deps.platform, home, paths, env: deps.env, alive };
|
|
120
|
+
if (fleetBotDaemonState(host) !== "stopped")
|
|
121
|
+
return "untouched";
|
|
122
|
+
deps.log?.("hq daemon runs this Mac's bots but is not running; starting it (hq daemon start)");
|
|
123
|
+
const started = fleetDaemonSeams.startDaemon(fleetDaemonSeams.startTimeoutMs);
|
|
124
|
+
if (!started.ok)
|
|
125
|
+
deps.log?.(`hq daemon start failed: ${started.detail}`);
|
|
126
|
+
for (let waited = 0;; waited += fleetDaemonSeams.pollMs) {
|
|
127
|
+
if (runningDaemonPid(paths.lockPath, alive) !== null) {
|
|
128
|
+
deps.log?.("hq daemon is running again");
|
|
129
|
+
return "started";
|
|
130
|
+
}
|
|
131
|
+
if (waited >= fleetDaemonSeams.liveWaitMs)
|
|
132
|
+
break;
|
|
133
|
+
fleetDaemonSeams.sleep(fleetDaemonSeams.pollMs);
|
|
134
|
+
}
|
|
135
|
+
deps.log?.(`hq daemon did not come up within ${Math.round(fleetDaemonSeams.liveWaitMs / 1000)}s; not handing ${name || "the bot"} to it`);
|
|
136
|
+
throw new FleetDaemonStoppedError(name);
|
|
137
|
+
}
|
|
45
138
|
function defaultLaunchctl(args) {
|
|
46
139
|
return spawnSync("launchctl", args, { encoding: "utf8", windowsHide: true, timeout: 15_000 });
|
|
47
140
|
}
|
|
@@ -196,6 +289,11 @@ export function controlFleetBot(agentUid, action, deps = {}) {
|
|
|
196
289
|
return controlFleetLocalBot(agentUid, action, deps);
|
|
197
290
|
const unit = fleetBotUnitId(bot.name);
|
|
198
291
|
const agent = { home, uid: deps.uid, launchctl: deps.launchctl };
|
|
292
|
+
// A start request a stopped daemon never reads leaves the bot offline while
|
|
293
|
+
// this reports success. Bring the daemon up first, or fail before changing anything.
|
|
294
|
+
if (action === "install" || action === "start" || action === "restart") {
|
|
295
|
+
ensureFleetBotDaemon(bot.name, { platform, home, paths, env: deps.env, ...(deps.alive ? { alive: deps.alive } : {}) });
|
|
296
|
+
}
|
|
199
297
|
switch (action) {
|
|
200
298
|
case "install":
|
|
201
299
|
case "start": {
|