@indigoai-us/hq-cli 5.345.250 → 5.345.252
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 +214 -0
- package/assets/scaffold/core/scripts/hq-session.sh +9 -0
- package/contracts/host-canary-release.json +9 -3
- package/dist/command-catalog.generated.d.ts +316 -2
- package/dist/command-catalog.generated.js +389 -2
- package/dist/commands/bot.js +12 -3
- package/dist/commands/core-bucket-c-work-mesh-offer-native.js +1 -1
- package/dist/commands/core-hq-session-binding.d.ts +140 -0
- package/dist/commands/core-hq-session-binding.js +363 -0
- package/dist/commands/core-hq-session-native.d.ts +23 -0
- package/dist/commands/core-hq-session-native.js +59 -9
- package/dist/commands/core-stop-autosave.js +1 -1
- package/dist/commands/core.js +10 -0
- package/dist/commands/doctor.d.ts +5 -1
- package/dist/commands/doctor.js +42 -5
- package/dist/commands/files.js +1 -1
- package/dist/commands/install-global.js +4 -2
- package/dist/commands/lanes.d.ts +2 -0
- package/dist/commands/lanes.js +9 -4
- package/dist/commands/logout.js +4 -0
- package/dist/commands/ontology-graph.d.ts +11 -2
- package/dist/commands/ontology-graph.js +130 -4
- package/dist/commands/report.js +35 -2
- package/dist/commands/sources.js +26 -8
- package/dist/commands/storage-gate.js +1 -1
- package/dist/commands/vault-retention-flag.js +2 -1
- package/dist/commands/whoami.js +1 -1
- package/dist/hq-cloud-sync-runner/bin/sync-runner.js +238 -221
- package/dist/hq-cloud-sync-runner/package.json +1 -1
- package/dist/index.js +3 -1
- package/dist/lib/agent-kit/inbox-poll-backoff-flag.js +1 -1
- package/dist/lib/agent-kit/mcp/tools.js +48 -0
- package/dist/lib/bot/fleet-bots-update-pass.js +1 -1
- package/dist/lib/bot/fleet-cron.d.ts +37 -0
- package/dist/lib/bot/fleet-cron.js +59 -12
- package/dist/lib/bot/fleet-local.d.ts +18 -0
- package/dist/lib/bot/fleet-local.js +51 -5
- package/dist/lib/bot/inbox-poll-backoff-flag.js +1 -1
- package/dist/lib/bot/signals-engine-flag.d.ts +1 -1
- package/dist/lib/bot/signals-engine-flag.js +1 -1
- package/dist/lib/cli-invite-nudge.js +1 -1
- package/dist/lib/client-version.d.ts +2 -0
- package/dist/lib/client-version.js +24 -0
- package/dist/lib/company-flag-gate.d.ts +30 -0
- package/dist/lib/company-flag-gate.js +104 -0
- package/dist/lib/core-utils/hook-timeout-debug-context-flag.js +1 -1
- package/dist/lib/daemon/flag.js +2 -1
- package/dist/lib/daemon/legacy-journal-gate.js +3 -1
- package/dist/lib/daemon/shared-flag-reads.js +1 -1
- package/dist/lib/doctor/checks/host-core.js +22 -4
- package/dist/lib/doctor/checks/jq.d.ts +27 -6
- package/dist/lib/doctor/checks/jq.js +46 -8
- package/dist/lib/doctor/client-health-reason-codes-flag.js +1 -1
- package/dist/lib/doctor/fix/refresh-sync-handoff.d.ts +1 -1
- package/dist/lib/doctor/fix/refresh-sync-handoff.js +1 -1
- package/dist/lib/flag-client-gate-headers.d.ts +38 -0
- package/dist/lib/flag-client-gate-headers.js +62 -0
- package/dist/lib/flag-client-headers.d.ts +15 -0
- package/dist/lib/flag-client-headers.js +25 -0
- package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
- package/dist/lib/flag-registry-worker-source.generated.js +1 -1
- package/dist/lib/flag-registry-worker.js +35 -0
- package/dist/lib/flag-registry.d.ts +1 -20
- package/dist/lib/flag-registry.js +5 -81
- package/dist/lib/hook-engine/adapter-core-pin.d.ts +29 -0
- package/dist/lib/hook-engine/adapter-core-pin.js +29 -0
- package/dist/lib/hook-engine/coverage.d.ts +68 -8
- package/dist/lib/hook-engine/coverage.js +167 -25
- package/dist/lib/hook-engine/native-stop-compatibility.json +9 -4
- package/dist/lib/hook-engine/reconcile.js +3 -2
- package/dist/lib/hot-channels/graph-context.d.ts +26 -1
- package/dist/lib/hot-channels/graph-context.js +76 -9
- package/dist/lib/hot-channels/prompts/signals-pass.md +20 -0
- package/dist/lib/hot-channels/run.d.ts +1 -0
- package/dist/lib/hot-channels/signal-changes.d.ts +228 -0
- package/dist/lib/hot-channels/signal-changes.js +683 -0
- package/dist/lib/hot-channels/signals-pass.d.ts +24 -0
- package/dist/lib/hot-channels/signals-pass.js +240 -15
- package/dist/lib/lanes/outpost-worktree-pruner-flag.d.ts +1 -1
- package/dist/lib/lanes/outpost-worktree-pruner-flag.js +1 -1
- package/dist/lib/lanes/registry-flag.js +2 -1
- package/dist/lib/lanes/spawn.js +11 -1
- package/dist/lib/mesh/live/binding-intent.d.ts +61 -0
- package/dist/lib/mesh/live/binding-intent.js +201 -0
- package/dist/lib/mesh/live/binding-receipt.d.ts +157 -0
- package/dist/lib/mesh/live/binding-receipt.js +365 -0
- package/dist/lib/mesh/live/company-flag-refresh.js +1 -1
- package/dist/lib/mesh/live/daemon/doctor-telemetry.d.ts +39 -0
- package/dist/lib/mesh/live/daemon/doctor-telemetry.js +58 -0
- package/dist/lib/mesh/live/daemon/install.js +2 -1
- package/dist/lib/mesh/live/daemon/presence.js +9 -0
- package/dist/lib/mesh/live/daemon/run.d.ts +3 -0
- package/dist/lib/mesh/live/daemon/run.js +33 -1
- package/dist/lib/ontology-graph/lineage/index.d.ts +401 -0
- package/dist/lib/ontology-graph/lineage/index.js +1027 -0
- package/dist/lib/ontology-graph/model/files.d.ts +4 -0
- package/dist/lib/ontology-graph/model/files.js +23 -0
- package/dist/lib/ontology-graph/model/index.d.ts +65 -1
- package/dist/lib/ontology-graph/model/index.js +154 -18
- package/dist/lib/ontology-graph/model/pass-tasks.d.ts +84 -1
- package/dist/lib/ontology-graph/model/pass-tasks.js +173 -4
- package/dist/lib/ontology-graph/model/pass.d.ts +11 -0
- package/dist/lib/ontology-graph/model/pass.js +17 -10
- package/dist/lib/ontology-graph/model/pending-items.d.ts +39 -0
- package/dist/lib/ontology-graph/model/pending-items.js +136 -0
- package/dist/lib/ontology-graph/model/step.d.ts +47 -2
- package/dist/lib/ontology-graph/model/step.js +202 -36
- package/dist/lib/ontology-graph/model/tasks.d.ts +28 -4
- package/dist/lib/ontology-graph/model/tasks.js +48 -15
- package/dist/lib/ontology-graph/pages/render.d.ts +1 -1
- package/dist/lib/ontology-graph/pages/render.js +4 -3
- package/dist/lib/ontology-graph/read/brief.d.ts +13 -3
- package/dist/lib/ontology-graph/read/brief.js +349 -67
- package/dist/lib/ontology-graph/read/index.d.ts +5 -1
- package/dist/lib/ontology-graph/read/index.js +174 -30
- package/dist/lib/ontology-graph/read/lineage.d.ts +101 -0
- package/dist/lib/ontology-graph/read/lineage.js +262 -0
- package/dist/lib/ontology-graph/read/reader-setting.d.ts +2 -0
- package/dist/lib/ontology-graph/read/reader-setting.js +4 -1
- package/dist/lib/ontology-graph/remodel/index.d.ts +174 -0
- package/dist/lib/ontology-graph/remodel/index.js +450 -0
- package/dist/lib/ontology-graph/replay/buffered-store.js +17 -0
- package/dist/lib/ontology-graph/replay/engine.d.ts +32 -1
- package/dist/lib/ontology-graph/replay/engine.js +213 -8
- package/dist/lib/ontology-graph/replay/extractors.d.ts +26 -0
- package/dist/lib/ontology-graph/replay/extractors.js +25 -1
- package/dist/lib/ontology-graph/replay/index.d.ts +2 -0
- package/dist/lib/ontology-graph/replay/index.js +120 -8
- package/dist/lib/ontology-graph/replay/signal-changes.d.ts +118 -0
- package/dist/lib/ontology-graph/replay/signal-changes.js +687 -0
- package/dist/lib/ontology-graph/schema/authority.d.ts +14 -5
- package/dist/lib/ontology-graph/schema/authority.js +13 -3
- package/dist/lib/ontology-graph/schema/decision-status.d.ts +18 -0
- package/dist/lib/ontology-graph/schema/decision-status.js +20 -0
- package/dist/lib/ontology-graph/schema/index.d.ts +2 -1
- package/dist/lib/ontology-graph/schema/index.js +2 -1
- package/dist/lib/ontology-graph/setup/index.d.ts +88 -0
- package/dist/lib/ontology-graph/setup/index.js +499 -0
- package/dist/lib/ontology-graph/types.d.ts +21 -0
- package/dist/lib/ontology-graph/types.js +5 -0
- package/dist/lib/search-index/index.d.ts +33 -1
- package/dist/lib/search-index/index.js +180 -25
- package/dist/lib/search-index/qmd-exit-diagnostics.d.ts +7 -0
- package/dist/lib/search-index/qmd-exit-diagnostics.js +25 -1
- package/dist/lib/signals/adapters-catalog.js +1 -1
- package/dist/lib/signals/failure-alert.js +4 -5
- package/dist/lib/signals/steps/adapters.js +3 -0
- package/dist/lib/sync-core/engine-holds.d.ts +1 -0
- package/dist/lib/sync-core/engine-holds.js +26 -0
- package/dist/lib/sync-core/engine-home.d.ts +3 -0
- package/dist/lib/sync-core/engine-home.js +41 -1
- package/dist/lib/sync-core/flag.js +2 -1
- package/dist/lib/sync-core/legacy-journal-export-child.js +5 -3
- package/dist/lib/sync-core/legacy-journal-export.d.ts +23 -4
- package/dist/lib/sync-core/legacy-journal-export.js +120 -55
- package/dist/lib/sync-core/reconcile.d.ts +2 -1
- package/dist/lib/sync-core/reconcile.js +30 -5
- package/dist/lib/sync-invalid-entity-warning.js +2 -1
- package/dist/lib/windows/install-followup.d.ts +41 -0
- package/dist/lib/windows/install-followup.js +87 -0
- package/dist/lib/windows/jq.d.ts +59 -0
- package/dist/lib/windows/jq.js +154 -3
- package/dist/lib/windows/user-path.d.ts +5 -0
- package/dist/lib/windows/user-path.js +1 -1
- package/dist/lib/work-context/auto-bind.d.ts +12 -0
- package/dist/lib/work-context/auto-bind.js +49 -3
- package/dist/lib/work-context/organize.d.ts +4 -2
- package/dist/lib/work-context/organize.js +18 -8
- package/dist/lib/work-context/reconcile.js +16 -1
- package/dist/main.js +12 -1
- package/dist/utils/client-health-contract.d.ts +30 -0
- package/dist/utils/client-health-contract.js +111 -0
- package/dist/utils/client-health.d.ts +5 -2
- package/dist/utils/client-health.js +74 -5
- package/dist/utils/exclusive-lock.d.ts +5 -1
- package/dist/utils/exclusive-lock.js +9 -2
- package/dist/utils/host-registration.d.ts +7 -0
- package/dist/utils/host-registration.js +10 -1
- package/dist/utils/pid.d.ts +31 -0
- package/dist/utils/pid.js +65 -0
- package/dist/utils/resident-package-preload.js +12 -4
- package/dist/utils/sentry-fingerprint.js +3 -0
- package/dist/utils/sync-person.d.ts +15 -0
- package/dist/utils/sync-person.js +74 -0
- package/package.json +8 -8
- package/scripts/install-hook-engine.mjs +5 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"hq-cli-daemon-sync-runner","type":"module","version":"6.18.
|
|
1
|
+
{"name":"hq-cli-daemon-sync-runner","type":"module","version":"6.18.124","bundleSha256":"98bb542b595ecef200dd72eb1d25a8b741d7df41a0d7afd06241e553d6eefe12","formatVersion":1}
|
package/dist/index.js
CHANGED
|
@@ -341,13 +341,15 @@ export function stableHealWouldRun(argv, env, platform, home = homedir()) {
|
|
|
341
341
|
function dispatchInstallFollowupThenCommand(versionRequest, helpRequest, parsedFastCore, monitorRequest, secretsRequest, mcpRequest) {
|
|
342
342
|
if (!versionRequest && !monitorRequest && !parsedFastCore && !secretsRequest && !mcpRequest
|
|
343
343
|
&& installFollowupWouldDoWork(process.argv, process.env, process.platform)) {
|
|
344
|
-
void import("./lib/windows/install-followup.js").then(({ runWindowsInstallFollowup }) => {
|
|
344
|
+
void import("./lib/windows/install-followup.js").then(async ({ runWindowsInstallFollowup, runWindowsJqFollowup }) => {
|
|
345
345
|
try {
|
|
346
346
|
runWindowsInstallFollowup({ argv: process.argv });
|
|
347
347
|
}
|
|
348
348
|
catch {
|
|
349
349
|
// Install repair must not turn into a failed command.
|
|
350
350
|
}
|
|
351
|
+
// Windows only, and it never rejects: the jq HQ hooks need (hq-cli #3716).
|
|
352
|
+
await runWindowsJqFollowup({ argv: process.argv });
|
|
351
353
|
}).catch(() => undefined).then(() => {
|
|
352
354
|
dispatchCliCommand(versionRequest, helpRequest, parsedFastCore, monitorRequest, secretsRequest, mcpRequest);
|
|
353
355
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createFlagClient
|
|
1
|
+
import { createHqFlagClient as createFlagClient } from "../flag-client-headers.js";
|
|
2
2
|
import { resolveFlagGate } from "../flag-registry.js";
|
|
3
3
|
import { resolveFlagRegistryEndpoint } from "../flag-registry-endpoint.js";
|
|
4
4
|
export const AGENT_KIT_INBOX_BACKOFF_FLAG = "agents.inbox-poll-backoff-agent-kit";
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
* never a secret value. `hq_secrets_list` names secrets; values are never a
|
|
16
16
|
* tool result.
|
|
17
17
|
*/
|
|
18
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
18
19
|
import { CLI_VERSION } from "../../../cli-version.js";
|
|
19
20
|
import { peekIdToken } from "../../../utils/id-token.js";
|
|
20
21
|
import { PERSON_AGENT_AUDIENCE_MESSAGE, callerMayUseAudience, defaultAudienceFor, isAgentUid, isRecipientUid } from "../../../lib/notify-recipient.js";
|
|
@@ -84,6 +85,11 @@ function fromRun(r, label) {
|
|
|
84
85
|
export function buildAgentMcpTools(clients) {
|
|
85
86
|
const { creds } = clients;
|
|
86
87
|
const company = creds.companySlug;
|
|
88
|
+
// Idempotency keys of agent DMs the loop check held, by recipient and
|
|
89
|
+
// message, so the continueExchange resend reuses the held message's key
|
|
90
|
+
// (one dispatch identity) instead of minting a new one. Bounded; oldest first out.
|
|
91
|
+
const heldDmKeys = new Map();
|
|
92
|
+
const heldDmKey = (to, message) => createHash("sha256").update(JSON.stringify([to, message])).digest("hex");
|
|
87
93
|
/** Bounded, once-retried ack of one inbox id, under one batch deadline (feedback 3e376c49). */
|
|
88
94
|
const inboxAckDeps = () => ({
|
|
89
95
|
timeoutMs: resolveAgentInboxTimeoutMs(process.env),
|
|
@@ -239,6 +245,14 @@ export function buildAgentMcpTools(clients) {
|
|
|
239
245
|
to: { type: "string", description: "Email, prs_… or agt_… uid, or a chn_… channel id" },
|
|
240
246
|
message: { type: "string" },
|
|
241
247
|
audience: { type: "string", enum: ["human", "agent", "both"], description: "Who this message is for (default: human for a person, agent for an agent, channel or group)" },
|
|
248
|
+
continueExchange: {
|
|
249
|
+
type: "boolean",
|
|
250
|
+
description: "Agent recipients (agt_…) only. Use it only after a send to this agent came back paused by the agent-to-agent loop check, " +
|
|
251
|
+
"and only if your last messages asked for or delivered specific work that is not finished yet. " +
|
|
252
|
+
"If the recent messages are thanks, acknowledgments, greetings or status echoes, stop: do not resend and do not reply. " +
|
|
253
|
+
"If you are unsure, ask your owner instead. To continue, resend the same message once with continueExchange: true; " +
|
|
254
|
+
"set it on that one resend only, never on a first send.",
|
|
255
|
+
},
|
|
242
256
|
},
|
|
243
257
|
required: ["to", "message"],
|
|
244
258
|
additionalProperties: false,
|
|
@@ -250,6 +264,13 @@ export function buildAgentMcpTools(clients) {
|
|
|
250
264
|
if (audience !== undefined && !["human", "agent", "both"].includes(audience)) {
|
|
251
265
|
throw new McpToolInputError('"audience" must be human, agent, or both');
|
|
252
266
|
}
|
|
267
|
+
const continueExchange = args.continueExchange;
|
|
268
|
+
if (continueExchange !== undefined && typeof continueExchange !== "boolean") {
|
|
269
|
+
throw new McpToolInputError('"continueExchange" must be true or false');
|
|
270
|
+
}
|
|
271
|
+
if (continueExchange === true && !isAgentUid(to)) {
|
|
272
|
+
throw new McpToolInputError('"continueExchange" applies only to an agent recipient (agt_…)');
|
|
273
|
+
}
|
|
253
274
|
// The token decides who is sending. Normally the agent's machine
|
|
254
275
|
// identity; if it ever resolves to a person login, people only send
|
|
255
276
|
// human messages, so refuse agent/both before any send.
|
|
@@ -278,6 +299,13 @@ export function buildAgentMcpTools(clients) {
|
|
|
278
299
|
throw new McpToolInputError('"to" must be an email, prs_… or agt_… uid, or a chn_… channel id');
|
|
279
300
|
})();
|
|
280
301
|
body.audience = audience ?? defaultAudienceFor(isAgentUid(to) ? "agent" : "person", machineCaller);
|
|
302
|
+
// One idempotency key per agent DM; a continue reuses the held send's key.
|
|
303
|
+
const heldKey = isAgentUid(to) ? heldDmKey(to, message) : undefined;
|
|
304
|
+
if (heldKey)
|
|
305
|
+
body.idempotencyKey = (continueExchange === true && heldDmKeys.get(heldKey)) || randomUUID();
|
|
306
|
+
// The sender's answer to the server's loop check (hq-pro-core 1.182.0+).
|
|
307
|
+
if (continueExchange === true)
|
|
308
|
+
body.continueExchange = true;
|
|
281
309
|
const res = await clients.apiJson(token, "/v1/notify/dm", { method: "POST", body });
|
|
282
310
|
if (res.status < 200 || res.status >= 300) {
|
|
283
311
|
return errorResult(`DM send failed (${res.status}): ${describeError(res.body)}`);
|
|
@@ -286,8 +314,28 @@ export function buildAgentMcpTools(clients) {
|
|
|
286
314
|
// is stored (200) but never reaches the recipient. Say so plainly
|
|
287
315
|
// instead of "sent", so the agent does not assume it was delivered.
|
|
288
316
|
const held = heldDeliveryNotice(res.body);
|
|
317
|
+
if (heldKey) {
|
|
318
|
+
heldDmKeys.delete(heldKey);
|
|
319
|
+
if (held) {
|
|
320
|
+
heldDmKeys.set(heldKey, String(body.idempotencyKey));
|
|
321
|
+
while (heldDmKeys.size > 100)
|
|
322
|
+
heldDmKeys.delete(heldDmKeys.keys().next().value);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
if (held && continueExchange === true) {
|
|
326
|
+
// The agent already answered the check with continueExchange. Do not
|
|
327
|
+
// pass on the server's "To continue, resend…" hint: that would invite
|
|
328
|
+
// another resend. Only the reason code goes with the stop.
|
|
329
|
+
const b = res.body;
|
|
330
|
+
const reason = typeof b.heldReason === "string" && b.heldReason ? ` (${b.heldReason})` : "";
|
|
331
|
+
return textResult(`STOP: held, NOT delivered to ${to}; you already set continueExchange, so stop. ` +
|
|
332
|
+
`Do not resend it and do not reply to ${to}; tell your owner if the work is still needed.${reason}`);
|
|
333
|
+
}
|
|
289
334
|
if (held)
|
|
290
335
|
return textResult(`WARNING: saved but NOT delivered to ${to}. ${held}`);
|
|
336
|
+
if (res.body && typeof res.body === "object" && res.body.exchangeContinued === true) {
|
|
337
|
+
return textResult(`sent to ${to} (continued the exchange: a new batch of agent-to-agent DMs started)`);
|
|
338
|
+
}
|
|
291
339
|
return textResult(`sent to ${to}`);
|
|
292
340
|
},
|
|
293
341
|
},
|
|
@@ -32,7 +32,7 @@ export async function runInstalledFleetBotsUpdate(log) {
|
|
|
32
32
|
},
|
|
33
33
|
heldForPromotion: (b) => hasPromotionHold(b.dir),
|
|
34
34
|
needsAdoption: (b, release) => local.fleetLocalProfileNeedsAdoption(b.config.agentUid, { release }),
|
|
35
|
-
busy: (b) => local.fleetLocalBusyReason(b.config.agentUid),
|
|
35
|
+
busy: (b) => local.fleetLocalBusyReason(b.config.agentUid, { warn: (message) => log(`${b.name}: ${message}`) }),
|
|
36
36
|
update: (b) => bot.updateFleetRuntimeBot(b.name, { busy: () => local.fleetLocalBusyReason(b.config.agentUid) }),
|
|
37
37
|
log,
|
|
38
38
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type BotConfig } from "./config.js";
|
|
2
2
|
import { type FleetLocalControlDeps } from "./fleet-local.js";
|
|
3
|
+
import { type LocalJob } from "./local-jobs.js";
|
|
3
4
|
export interface FleetCronSchedule {
|
|
4
5
|
kind?: string;
|
|
5
6
|
expr?: string;
|
|
@@ -61,10 +62,44 @@ export declare function runFleetCronRequest(agentUid: string, request: Record<st
|
|
|
61
62
|
export declare function fleetCronOps(agentUid: string, deps?: FleetCronDeps): FleetCronOps;
|
|
62
63
|
export declare function fleetOwnerOrigin(ownerUid: string, jobs?: readonly FleetCronJob[]): FleetCronOrigin;
|
|
63
64
|
export declare function fleetScheduleFromLegacy(expr: string): string;
|
|
65
|
+
/** A legacy job's schedule in a form the HQ Fleet Runtime runs, or why there is none. */
|
|
66
|
+
export type LegacyJobSchedule = {
|
|
67
|
+
ok: true;
|
|
68
|
+
schedule: string;
|
|
69
|
+
note?: string;
|
|
70
|
+
} | {
|
|
71
|
+
ok: false;
|
|
72
|
+
reason: string;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Convert a job from a bot's old `jobs.json` to a schedule the HQ Fleet
|
|
76
|
+
* Runtime runs. The job's `timezone` is not carried over (the migration never
|
|
77
|
+
* carried it); the schedule's fields are evaluated in the runtime's zone.
|
|
78
|
+
*
|
|
79
|
+
* The old scheduler (`local-jobs.ts`) read a six-field `cron(...)` through
|
|
80
|
+
* `toStandardCron`, which drops the year field: a job saved as
|
|
81
|
+
* `cron(0 9 ? * MON-FRI 2026)` ran every weekday, every year.
|
|
82
|
+
* `fleetScheduleFromLegacy` refuses a year, because `hq bot jobs --add` must
|
|
83
|
+
* not accept a year the runtime cannot honor. For a job the old scheduler
|
|
84
|
+
* already ran, the faithful move is the same five fields it ran on.
|
|
85
|
+
*
|
|
86
|
+
* Only a job without a timed schedule (an event job) has no Fleet form.
|
|
87
|
+
*/
|
|
88
|
+
export declare function fleetScheduleFromLocalJob(job: Pick<LocalJob, "cron" | "trigger">): LegacyJobSchedule;
|
|
64
89
|
export interface FleetJobsMigrationResult {
|
|
65
90
|
imported: number;
|
|
66
91
|
alreadyPresent: number;
|
|
67
92
|
skipped: string[];
|
|
93
|
+
/** Why each skipped job could not move, in the order of `skipped`. */
|
|
94
|
+
skippedReasons: Array<{
|
|
95
|
+
jobId: string;
|
|
96
|
+
reason: string;
|
|
97
|
+
}>;
|
|
98
|
+
/** Jobs that moved with a schedule written differently from the old one. */
|
|
99
|
+
notes: Array<{
|
|
100
|
+
jobId: string;
|
|
101
|
+
note: string;
|
|
102
|
+
}>;
|
|
68
103
|
/** Where the old list went. Null when some jobs could not move: jobs.json then stays. */
|
|
69
104
|
renamedTo: string | null;
|
|
70
105
|
}
|
|
@@ -125,12 +160,14 @@ export interface EnsureFleetHotSignalSyncInput {
|
|
|
125
160
|
/** Companies with an actual replacement job on the Executive bot. */
|
|
126
161
|
executiveCompanies?: readonly string[];
|
|
127
162
|
now?: Date;
|
|
163
|
+
noPersonIdentity?: boolean;
|
|
128
164
|
}
|
|
129
165
|
export interface FleetHotSignalSyncCompanyResult {
|
|
130
166
|
company: string;
|
|
131
167
|
created: boolean;
|
|
132
168
|
job: FleetCronJob | null;
|
|
133
169
|
heldBy?: string;
|
|
170
|
+
noPersonIdentity?: true;
|
|
134
171
|
}
|
|
135
172
|
export interface EnsureFleetHotSignalSyncResult {
|
|
136
173
|
companies: FleetHotSignalSyncCompanyResult[];
|
|
@@ -3,7 +3,7 @@ import * as fs from "node:fs";
|
|
|
3
3
|
import * as path from "node:path";
|
|
4
4
|
import { effectiveBotCompanies, effectiveBotKind } from "./config.js";
|
|
5
5
|
import { fleetLocalRuntimePython, stderrTail } from "./fleet-local.js";
|
|
6
|
-
import { readLocalJobs, withJobsLock, writeLocalJobs } from "./local-jobs.js";
|
|
6
|
+
import { parseCron, readLocalJobs, toStandardCron, withJobsLock, writeLocalJobs } from "./local-jobs.js";
|
|
7
7
|
import { signInCommand } from "./runtime-sign-in.js";
|
|
8
8
|
import { BOT_SIGNALS_ENGINE_JOB_FLAG, signalsEngineJobCompanies } from "./signals-engine-flag.js";
|
|
9
9
|
import { SIGNALS_FAILURE_PREFIX } from "../hot-channels/alert.js";
|
|
@@ -151,6 +151,49 @@ export function fleetScheduleFromLegacy(expr) {
|
|
|
151
151
|
const dow = dayOfWeek === "?" ? "*" : dayOfWeek.split(",").map((term) => unshiftDayOfWeekTerm(term.trim())).join(",");
|
|
152
152
|
return `${minute} ${hour} ${dom} ${month} ${dow}`;
|
|
153
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* Convert a job from a bot's old `jobs.json` to a schedule the HQ Fleet
|
|
156
|
+
* Runtime runs. The job's `timezone` is not carried over (the migration never
|
|
157
|
+
* carried it); the schedule's fields are evaluated in the runtime's zone.
|
|
158
|
+
*
|
|
159
|
+
* The old scheduler (`local-jobs.ts`) read a six-field `cron(...)` through
|
|
160
|
+
* `toStandardCron`, which drops the year field: a job saved as
|
|
161
|
+
* `cron(0 9 ? * MON-FRI 2026)` ran every weekday, every year.
|
|
162
|
+
* `fleetScheduleFromLegacy` refuses a year, because `hq bot jobs --add` must
|
|
163
|
+
* not accept a year the runtime cannot honor. For a job the old scheduler
|
|
164
|
+
* already ran, the faithful move is the same five fields it ran on.
|
|
165
|
+
*
|
|
166
|
+
* Only a job without a timed schedule (an event job) has no Fleet form.
|
|
167
|
+
*/
|
|
168
|
+
export function fleetScheduleFromLocalJob(job) {
|
|
169
|
+
if (job.trigger) {
|
|
170
|
+
return { ok: false, reason: `it runs on the "${job.trigger.event}" event, and the HQ Fleet Runtime runs only timed schedules` };
|
|
171
|
+
}
|
|
172
|
+
if (job.cron !== undefined && typeof job.cron !== "string") {
|
|
173
|
+
return { ok: false, reason: `its schedule is not text (${JSON.stringify(job.cron)})` };
|
|
174
|
+
}
|
|
175
|
+
const expr = job.cron?.trim() ?? "";
|
|
176
|
+
if (!expr)
|
|
177
|
+
return { ok: false, reason: "it has no schedule" };
|
|
178
|
+
if (!/^(cron|rate)\(/i.test(expr))
|
|
179
|
+
return { ok: true, schedule: expr };
|
|
180
|
+
try {
|
|
181
|
+
return { ok: true, schedule: fleetScheduleFromLegacy(expr) };
|
|
182
|
+
}
|
|
183
|
+
catch (error) {
|
|
184
|
+
const refused = error instanceof Error ? error.message : String(error);
|
|
185
|
+
const year = /^cron\(\s*(?:\S+\s+){5}(\S+)\s*\)$/i.exec(expr)?.[1];
|
|
186
|
+
const standard = year !== undefined ? toStandardCron(expr) : null;
|
|
187
|
+
if (standard && parseCron(expr)) {
|
|
188
|
+
return {
|
|
189
|
+
ok: true,
|
|
190
|
+
schedule: standard,
|
|
191
|
+
note: `its year field (${year}) was never applied by the old scheduler, so it moves as "${standard}", the schedule the old scheduler ran`,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
return { ok: false, reason: refused.replace(/\.$/, "") };
|
|
195
|
+
}
|
|
196
|
+
}
|
|
154
197
|
function migratedJobsPath(dir, now) {
|
|
155
198
|
const first = path.join(dir, "jobs.migrated.json");
|
|
156
199
|
if (!fs.existsSync(first))
|
|
@@ -170,20 +213,19 @@ export function migrateLegacyJobsToFleet(dir, config, ops, now = new Date()) {
|
|
|
170
213
|
let imported = 0;
|
|
171
214
|
let alreadyPresent = 0;
|
|
172
215
|
const skipped = [];
|
|
216
|
+
const skippedReasons = [];
|
|
217
|
+
const notes = [];
|
|
173
218
|
const moved = new Set();
|
|
174
219
|
for (const job of legacy) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
continue;
|
|
178
|
-
}
|
|
179
|
-
let schedule;
|
|
180
|
-
try {
|
|
181
|
-
schedule = /^(cron|rate)\(/i.test(job.cron.trim()) ? fleetScheduleFromLegacy(job.cron) : job.cron.trim();
|
|
182
|
-
}
|
|
183
|
-
catch {
|
|
220
|
+
const converted = fleetScheduleFromLocalJob(job);
|
|
221
|
+
if (!converted.ok) {
|
|
184
222
|
skipped.push(job.jobId);
|
|
223
|
+
skippedReasons.push({ jobId: job.jobId, reason: converted.reason });
|
|
185
224
|
continue;
|
|
186
225
|
}
|
|
226
|
+
const schedule = converted.schedule;
|
|
227
|
+
if (converted.note)
|
|
228
|
+
notes.push({ jobId: job.jobId, note: converted.note });
|
|
187
229
|
const present = existing.some((candidate) => candidate.prompt === job.prompt && candidate.schedule?.expr === schedule);
|
|
188
230
|
if (present) {
|
|
189
231
|
alreadyPresent += 1;
|
|
@@ -201,11 +243,11 @@ export function migrateLegacyJobsToFleet(dir, config, ops, now = new Date()) {
|
|
|
201
243
|
const all = readLocalJobs(dir);
|
|
202
244
|
writeLocalJobs(dir, all.filter((job) => !moved.has(job.jobId)));
|
|
203
245
|
}
|
|
204
|
-
return { imported, alreadyPresent, skipped, renamedTo: null };
|
|
246
|
+
return { imported, alreadyPresent, skipped, skippedReasons, notes, renamedTo: null };
|
|
205
247
|
}
|
|
206
248
|
const renamedTo = migratedJobsPath(dir, now);
|
|
207
249
|
fs.renameSync(file, renamedTo);
|
|
208
|
-
return { imported, alreadyPresent, skipped, renamedTo };
|
|
250
|
+
return { imported, alreadyPresent, skipped, skippedReasons, notes, renamedTo };
|
|
209
251
|
});
|
|
210
252
|
}
|
|
211
253
|
export const FLEET_HOT_SIGNAL_SYNC_NAME = "hot-signal-sync";
|
|
@@ -340,6 +382,8 @@ def classify(out, err, code):
|
|
|
340
382
|
name = signal_name(-code)
|
|
341
383
|
return 'hq was stopped by signal %d%s' % (-code, ' (' + name + ')' if name else ''), FIXES['signal']
|
|
342
384
|
text = ANSI.sub('', (err or '') + '\n' + (out or ''))
|
|
385
|
+
if re.search(r'No person identity on this machine', text, re.I):
|
|
386
|
+
return 'this computer has no person identity in HQ (its sign-in is a machine identity that acts for no person)', FIXES['hq_no_person']
|
|
343
387
|
if re.search(r"HQ session has expired|not signed in to HQ|Sign in to HQ first|run .hq login", text, re.I):
|
|
344
388
|
return 'you are signed out of HQ', FIXES['hq_signed_out']
|
|
345
389
|
if re.search(r'bot-api-key-login', text, re.I):
|
|
@@ -465,6 +509,7 @@ export function renderFleetHotSignalSyncScript(input) {
|
|
|
465
509
|
bot_signed_out: "open the Executive bot's profile in HQ, go to Brain, and reconnect its subscription login.",
|
|
466
510
|
bot_api_key: "open the Executive bot's profile in HQ, go to Brain, and connect its Claude or ChatGPT subscription instead of an API key.",
|
|
467
511
|
hq_signed_out: "run `hq login`.",
|
|
512
|
+
hq_no_person: `run \`${syncCommand}\` where the bot's owner is signed in to HQ, or run the bot on its owner's computer or personal Outpost.`,
|
|
468
513
|
// The desktop app first (Settings → AI tools lists Claude Code with a
|
|
469
514
|
// "Connect Claude" or "Install Claude" button), the terminal as the fallback.
|
|
470
515
|
claude_signed_out: claudeSignInFix,
|
|
@@ -676,6 +721,8 @@ function ensureFleetHotSignalSyncFor(input, company, jobs) {
|
|
|
676
721
|
markFleetHotSignalSyncRegistered(input.dir, company, input.now);
|
|
677
722
|
return { company, created: false, job: current };
|
|
678
723
|
}
|
|
724
|
+
if (input.noPersonIdentity)
|
|
725
|
+
return { company, created: false, job: null, noPersonIdentity: true };
|
|
679
726
|
const heldBy = otherBotWithHotSignalSync(input.dir, company, input.otherBotDirs);
|
|
680
727
|
if (heldBy)
|
|
681
728
|
return { company, created: false, job: null, heldBy };
|
|
@@ -445,8 +445,26 @@ export declare function fleetLocalChannels(state: FleetLocalGatewayState | null,
|
|
|
445
445
|
slack: string;
|
|
446
446
|
telegram: string;
|
|
447
447
|
};
|
|
448
|
+
/**
|
|
449
|
+
* How long a Fleet cron job's `fire_claim` stays live. This is the HQ Fleet
|
|
450
|
+
* Runtime's own rule (`claim_ttl_seconds` in hq-fleet-runtime
|
|
451
|
+
* `cron/jobs.py`): a running job refreshes its claim every 60 seconds, and
|
|
452
|
+
* the runtime treats a claim older than 300 seconds as abandoned and fires
|
|
453
|
+
* over it. A claim left by a runner that died is never cleared by its holder,
|
|
454
|
+
* so it must age out here too or the bot looks busy forever.
|
|
455
|
+
*/
|
|
456
|
+
export declare const FLEET_CRON_FIRE_CLAIM_TTL_MS = 300000;
|
|
457
|
+
/**
|
|
458
|
+
* Whether a Fleet cron job's `fire_claim` is held by a live run, by the
|
|
459
|
+
* runtime's rule: it has a readable `at` that is not in the future and is
|
|
460
|
+
* younger than {@link FLEET_CRON_FIRE_CLAIM_TTL_MS}.
|
|
461
|
+
*/
|
|
462
|
+
export declare function fleetCronFireClaimLive(claim: unknown, nowMs: number): boolean;
|
|
448
463
|
export declare function fleetLocalBusyReason(agentUid: string, deps?: Pick<FleetLocalControlDeps, "fleetHome"> & {
|
|
449
464
|
isAlive?: (pid: number) => boolean;
|
|
465
|
+
now?: () => number;
|
|
466
|
+
/** Told about a claim or schedule file that does not count as busy, so a stale one is visible. */
|
|
467
|
+
warn?: (message: string) => void;
|
|
450
468
|
}): string | null;
|
|
451
469
|
/** Checks the instructions with the runtime's scanner, then makes them the bot's persona. */
|
|
452
470
|
export declare function refreshFleetLocalInstructions(agentUid: string, systemPrompt: string, deps?: FleetLocalControlDeps): string;
|
|
@@ -1963,6 +1963,40 @@ export function fleetLocalChannels(state, gatewayAlive) {
|
|
|
1963
1963
|
const lane = (name) => (gatewayAlive && state?.platforms[name]) || "not_connected";
|
|
1964
1964
|
return { slack: lane("slack"), telegram: lane("telegram") };
|
|
1965
1965
|
}
|
|
1966
|
+
/**
|
|
1967
|
+
* How long a Fleet cron job's `fire_claim` stays live. This is the HQ Fleet
|
|
1968
|
+
* Runtime's own rule (`claim_ttl_seconds` in hq-fleet-runtime
|
|
1969
|
+
* `cron/jobs.py`): a running job refreshes its claim every 60 seconds, and
|
|
1970
|
+
* the runtime treats a claim older than 300 seconds as abandoned and fires
|
|
1971
|
+
* over it. A claim left by a runner that died is never cleared by its holder,
|
|
1972
|
+
* so it must age out here too or the bot looks busy forever.
|
|
1973
|
+
*/
|
|
1974
|
+
export const FLEET_CRON_FIRE_CLAIM_TTL_MS = 300_000;
|
|
1975
|
+
/** The claim's time in epoch ms, or null when it has no readable `at`. */
|
|
1976
|
+
function fireClaimTime(claim) {
|
|
1977
|
+
if (!claim || typeof claim !== "object" || Array.isArray(claim))
|
|
1978
|
+
return null;
|
|
1979
|
+
const at = claim.at;
|
|
1980
|
+
if (typeof at !== "string" || !at)
|
|
1981
|
+
return null;
|
|
1982
|
+
// The runtime writes Python isoformat, which can carry microseconds. Keep
|
|
1983
|
+
// milliseconds so every JS engine parses it. A value with no offset is the
|
|
1984
|
+
// runtime machine's local time, which Date.parse also assumes.
|
|
1985
|
+
const time = Date.parse(at.replace(/(\.\d{3})\d+/, "$1"));
|
|
1986
|
+
return Number.isFinite(time) ? time : null;
|
|
1987
|
+
}
|
|
1988
|
+
/**
|
|
1989
|
+
* Whether a Fleet cron job's `fire_claim` is held by a live run, by the
|
|
1990
|
+
* runtime's rule: it has a readable `at` that is not in the future and is
|
|
1991
|
+
* younger than {@link FLEET_CRON_FIRE_CLAIM_TTL_MS}.
|
|
1992
|
+
*/
|
|
1993
|
+
export function fleetCronFireClaimLive(claim, nowMs) {
|
|
1994
|
+
const time = fireClaimTime(claim);
|
|
1995
|
+
if (time === null)
|
|
1996
|
+
return false;
|
|
1997
|
+
const age = nowMs - time;
|
|
1998
|
+
return age >= 0 && age < FLEET_CRON_FIRE_CLAIM_TTL_MS;
|
|
1999
|
+
}
|
|
1966
2000
|
export function fleetLocalBusyReason(agentUid, deps = {}) {
|
|
1967
2001
|
const state = readFleetLocalGatewayState(agentUid, deps);
|
|
1968
2002
|
const alive = deps.isAlive ?? ((pid) => {
|
|
@@ -1980,15 +2014,27 @@ export function fleetLocalBusyReason(agentUid, deps = {}) {
|
|
|
1980
2014
|
return `${state.activeAgents} turn${state.activeAgents === 1 ? "" : "s"} in progress`;
|
|
1981
2015
|
if (state.gatewayState === "draining" || state.gatewayState === "starting")
|
|
1982
2016
|
return `gateway is ${state.gatewayState}`;
|
|
2017
|
+
const file = path.join(fleetLocalProfileDir(agentUid, deps), "cron", "jobs.json");
|
|
2018
|
+
let store;
|
|
1983
2019
|
try {
|
|
1984
|
-
|
|
1985
|
-
const running = (store.jobs ?? []).find((job) => job && job.fire_claim !== null && job.fire_claim !== undefined);
|
|
1986
|
-
if (running)
|
|
1987
|
-
return typeof running.name === "string" && running.name ? `scheduled job "${running.name}" is running` : "a scheduled job is running";
|
|
2020
|
+
store = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
1988
2021
|
}
|
|
1989
|
-
catch {
|
|
2022
|
+
catch (error) {
|
|
2023
|
+
if (error.code !== "ENOENT") {
|
|
2024
|
+
deps.warn?.(`could not read the scheduled jobs in ${file} (${error instanceof Error ? error.message : String(error)}); not counting any job as running`);
|
|
2025
|
+
}
|
|
1990
2026
|
return null;
|
|
1991
2027
|
}
|
|
2028
|
+
const now = (deps.now ?? Date.now)();
|
|
2029
|
+
const label = (job) => typeof job.name === "string" && job.name ? `scheduled job "${job.name}"` : typeof job.id === "string" && job.id ? `scheduled job ${job.id}` : "a scheduled job";
|
|
2030
|
+
for (const job of Array.isArray(store?.jobs) ? store.jobs : []) {
|
|
2031
|
+
if (!job || job.fire_claim === null || job.fire_claim === undefined)
|
|
2032
|
+
continue;
|
|
2033
|
+
if (fleetCronFireClaimLive(job.fire_claim, now))
|
|
2034
|
+
return `${label(job)} is running`;
|
|
2035
|
+
const at = job.fire_claim?.at;
|
|
2036
|
+
deps.warn?.(`${label(job)} still holds a run claim${typeof at === "string" && at ? ` from ${at}` : ""} that is past the HQ Fleet Runtime's ${FLEET_CRON_FIRE_CLAIM_TTL_MS / 1000}-second limit; its run has stopped, so it does not block this update`);
|
|
2037
|
+
}
|
|
1992
2038
|
return null;
|
|
1993
2039
|
}
|
|
1994
2040
|
/** Checks the instructions with the runtime's scanner, then makes them the bot's persona. */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { loadCachedTokens } from "@indigoai-us/hq-cloud";
|
|
2
|
-
import { createFlagClient
|
|
2
|
+
import { createHqFlagClient as createFlagClient } from "../flag-client-headers.js";
|
|
3
3
|
import { resolveFlagGate, resolveProcessFlagCompanyContext } from "../flag-registry.js";
|
|
4
4
|
import { resolveFlagRegistryEndpoint } from "../flag-registry-endpoint.js";
|
|
5
5
|
import { effectiveBotCompanies, effectiveBotKind } from "./config.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CompanyFlagGateDependencies } from "../flag-
|
|
1
|
+
import type { CompanyFlagGateDependencies } from "../company-flag-gate.js";
|
|
2
2
|
export declare const BOT_SIGNALS_ENGINE_JOB_FLAG = "cli.bot-signals-engine-job";
|
|
3
3
|
export interface SignalsEngineFlagSession {
|
|
4
4
|
token: string;
|
|
@@ -84,7 +84,7 @@ async function readForCompany(company, session, deps) {
|
|
|
84
84
|
const signedIn = await session(company);
|
|
85
85
|
if (!signedIn)
|
|
86
86
|
return "signed-out";
|
|
87
|
-
const { readCompanyFlag } = await import("../flag-
|
|
87
|
+
const { readCompanyFlag } = await import("../company-flag-gate.js");
|
|
88
88
|
return readCompanyFlag(signedIn.companyUid, signedIn.token, BOT_SIGNALS_ENGINE_JOB_FLAG, { fallback: false }, deps.createClient ? { createClient: deps.createClient } : {});
|
|
89
89
|
})();
|
|
90
90
|
// A read that loses the race below must not surface later as an unhandled rejection.
|
|
@@ -5,7 +5,7 @@ import * as path from "node:path";
|
|
|
5
5
|
import { createInterface } from "node:readline/promises";
|
|
6
6
|
import { isExpiring, isMachineIdentity, loadCachedTokens, } from "../utils/cognito-session.js";
|
|
7
7
|
import { queueCliInviteNudgeEvent } from "../utils/cli-telemetry.js";
|
|
8
|
-
import { resolveCompanyFlagGate } from "./flag-
|
|
8
|
+
import { resolveCompanyFlagGate } from "./company-flag-gate.js";
|
|
9
9
|
import { isHumanInteractiveCliSession } from "./first-sync-next-step.js";
|
|
10
10
|
import { vaultApiFetch } from "../utils/vault-api.js";
|
|
11
11
|
export const CLI_INVITE_NUDGE_FLAG = "cli.first-sync-invite-teammate-v1";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The CLI version sent as `x-hq-client-version` on flag resolve requests.
|
|
3
|
+
*
|
|
4
|
+
* Unlike `cli-version.ts`, this never throws. It reads package.json relative to
|
|
5
|
+
* this file, and code that bundles it elsewhere (a test bundle in
|
|
6
|
+
* node_modules/.cache, an eval'd worker with no module URL) cannot find it.
|
|
7
|
+
* The read then returns undefined and the request goes out without the
|
|
8
|
+
* version header; hq-pro stores null and only gated rows deny on that.
|
|
9
|
+
*/
|
|
10
|
+
import { readFileSync } from "node:fs";
|
|
11
|
+
let cached;
|
|
12
|
+
export function readClientVersion() {
|
|
13
|
+
if (cached === undefined) {
|
|
14
|
+
try {
|
|
15
|
+
const pkg = JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf8"));
|
|
16
|
+
cached = typeof pkg.version === "string" && pkg.version.length > 0 ? pkg.version : null;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
cached = null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return cached ?? undefined;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=client-version.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One-shot company-scoped flag resolution helpers.
|
|
3
|
+
*
|
|
4
|
+
* Kept separate from `flag-registry.ts` so non-network fast routes (such as
|
|
5
|
+
* `timeout-guard`, `handoff`, and `delegate`) that import the worker-backed
|
|
6
|
+
* process snapshot reader do not pull `createHqFlagClient` / `globalThis.fetch`
|
|
7
|
+
* into their static import closure.
|
|
8
|
+
*/
|
|
9
|
+
import { type FlagLookupOptions, type FlagResolution } from "@indigoai-us/hq-flags-client";
|
|
10
|
+
import { createHqFlagClient } from "./flag-client-headers.js";
|
|
11
|
+
export interface CompanyFlagGateDependencies {
|
|
12
|
+
endpoint?: string;
|
|
13
|
+
requestTimeoutMs?: number;
|
|
14
|
+
createClient?: typeof createHqFlagClient;
|
|
15
|
+
}
|
|
16
|
+
/** Resolve one explicit company's flag without relying on process-wide binding. */
|
|
17
|
+
export declare function resolveCompanyFlagGate(companyUid: string, idToken: string, flagKey: string, lookup: FlagLookupOptions, legacyFallback: () => boolean, dependencies?: CompanyFlagGateDependencies): Promise<boolean>;
|
|
18
|
+
/**
|
|
19
|
+
* Read one explicit company's flag and say whether the registry answered.
|
|
20
|
+
*
|
|
21
|
+
* Returns the evaluator's resolution when the registry snapshot loaded (an
|
|
22
|
+
* absent row resolves to `lookup.fallback`, source "fallback"), a
|
|
23
|
+
* "local-override" resolution when the process sets one, and null when the
|
|
24
|
+
* registry could not be read: no company uid or token, a client error, a
|
|
25
|
+
* timeout, or a failed load. Callers that keep a last-known value (ingest
|
|
26
|
+
* kill switches) use the null to tell an unreadable registry from an answer.
|
|
27
|
+
* Bounded by the client's request timeout, like `resolveCompanyFlagGate`.
|
|
28
|
+
*/
|
|
29
|
+
export declare function readCompanyFlag(companyUid: string, idToken: string, flagKey: string, lookup: FlagLookupOptions, dependencies?: CompanyFlagGateDependencies): Promise<FlagResolution | null>;
|
|
30
|
+
//# sourceMappingURL=company-flag-gate.d.ts.map
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One-shot company-scoped flag resolution helpers.
|
|
3
|
+
*
|
|
4
|
+
* Kept separate from `flag-registry.ts` so non-network fast routes (such as
|
|
5
|
+
* `timeout-guard`, `handoff`, and `delegate`) that import the worker-backed
|
|
6
|
+
* process snapshot reader do not pull `createHqFlagClient` / `globalThis.fetch`
|
|
7
|
+
* into their static import closure.
|
|
8
|
+
*/
|
|
9
|
+
import { readLocalOverride, } from "@indigoai-us/hq-flags-client";
|
|
10
|
+
import { createHqFlagClient } from "./flag-client-headers.js";
|
|
11
|
+
import { resolveFlagRegistryEndpoint } from "./flag-registry-endpoint.js";
|
|
12
|
+
import { resolveFlagGate } from "./flag-registry.js";
|
|
13
|
+
const COMPANY_UID_RE = /^cmp_[A-Za-z0-9]{3,128}$/;
|
|
14
|
+
function normalizedCompanyUid(value) {
|
|
15
|
+
const candidate = value?.trim() ?? "";
|
|
16
|
+
return COMPANY_UID_RE.test(candidate) ? candidate : undefined;
|
|
17
|
+
}
|
|
18
|
+
function processLocalOverride(flagKey, env = process.env) {
|
|
19
|
+
return readLocalOverride(flagKey, env);
|
|
20
|
+
}
|
|
21
|
+
function localOverrideOrFallback(flagKey, legacyFallback, env = process.env) {
|
|
22
|
+
return processLocalOverride(flagKey, env) ?? legacyFallback();
|
|
23
|
+
}
|
|
24
|
+
/** Resolve one explicit company's flag without relying on process-wide binding. */
|
|
25
|
+
export async function resolveCompanyFlagGate(companyUid, idToken, flagKey, lookup, legacyFallback, dependencies = {}) {
|
|
26
|
+
const localOverride = processLocalOverride(flagKey);
|
|
27
|
+
if (localOverride !== null)
|
|
28
|
+
return localOverride;
|
|
29
|
+
const targetCompanyUid = normalizedCompanyUid(companyUid);
|
|
30
|
+
if (!targetCompanyUid || idToken.trim() === "") {
|
|
31
|
+
return localOverrideOrFallback(flagKey, legacyFallback);
|
|
32
|
+
}
|
|
33
|
+
let client;
|
|
34
|
+
try {
|
|
35
|
+
client = (dependencies.createClient ?? createHqFlagClient)({
|
|
36
|
+
endpoint: resolveFlagRegistryEndpoint(dependencies.endpoint, process.env),
|
|
37
|
+
getToken: () => idToken,
|
|
38
|
+
companyUid: targetCompanyUid,
|
|
39
|
+
refreshIntervalMs: 0,
|
|
40
|
+
requestTimeoutMs: dependencies.requestTimeoutMs ?? 1_200,
|
|
41
|
+
onError: (error) => {
|
|
42
|
+
const errorClass = error instanceof Error ? error.name : "unknown";
|
|
43
|
+
console.error(`hq: Could not resolve a company flag (${errorClass}); using its fallback.`);
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
await client.ready();
|
|
47
|
+
return resolveFlagGate(client, flagKey, lookup, legacyFallback);
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
const errorClass = error instanceof Error ? error.name : "unknown";
|
|
51
|
+
console.error(`hq: Could not resolve a company flag (${errorClass}); using its fallback.`);
|
|
52
|
+
return localOverrideOrFallback(flagKey, legacyFallback);
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
client?.close();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Read one explicit company's flag and say whether the registry answered.
|
|
60
|
+
*
|
|
61
|
+
* Returns the evaluator's resolution when the registry snapshot loaded (an
|
|
62
|
+
* absent row resolves to `lookup.fallback`, source "fallback"), a
|
|
63
|
+
* "local-override" resolution when the process sets one, and null when the
|
|
64
|
+
* registry could not be read: no company uid or token, a client error, a
|
|
65
|
+
* timeout, or a failed load. Callers that keep a last-known value (ingest
|
|
66
|
+
* kill switches) use the null to tell an unreadable registry from an answer.
|
|
67
|
+
* Bounded by the client's request timeout, like `resolveCompanyFlagGate`.
|
|
68
|
+
*/
|
|
69
|
+
export async function readCompanyFlag(companyUid, idToken, flagKey, lookup, dependencies = {}) {
|
|
70
|
+
const localOverride = processLocalOverride(flagKey);
|
|
71
|
+
if (localOverride !== null)
|
|
72
|
+
return { value: localOverride, source: "local-override" };
|
|
73
|
+
const targetCompanyUid = normalizedCompanyUid(companyUid);
|
|
74
|
+
if (!targetCompanyUid || idToken.trim() === "")
|
|
75
|
+
return null;
|
|
76
|
+
let client;
|
|
77
|
+
try {
|
|
78
|
+
client = (dependencies.createClient ?? createHqFlagClient)({
|
|
79
|
+
endpoint: resolveFlagRegistryEndpoint(dependencies.endpoint, process.env),
|
|
80
|
+
getToken: () => idToken,
|
|
81
|
+
companyUid: targetCompanyUid,
|
|
82
|
+
refreshIntervalMs: 0,
|
|
83
|
+
requestTimeoutMs: dependencies.requestTimeoutMs ?? 1_200,
|
|
84
|
+
onError: (error) => {
|
|
85
|
+
const errorClass = error instanceof Error ? error.name : "unknown";
|
|
86
|
+
console.error(`hq: Could not read a company flag (${errorClass}).`);
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
await client.ready();
|
|
90
|
+
// ready() resolves after a failed load too; no snapshot means no answer.
|
|
91
|
+
if (client.snapshot() === null)
|
|
92
|
+
return null;
|
|
93
|
+
return client.explain(flagKey, lookup);
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
const errorClass = error instanceof Error ? error.name : "unknown";
|
|
97
|
+
console.error(`hq: Could not read a company flag (${errorClass}).`);
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
finally {
|
|
101
|
+
client?.close();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=company-flag-gate.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { loadCachedTokens } from "@indigoai-us/hq-cloud";
|
|
2
|
-
import { createFlagClient
|
|
2
|
+
import { createHqFlagClient as createFlagClient } from "../flag-client-headers.js";
|
|
3
3
|
import { resolveProcessFlagCompanyContext } from "../flag-registry.js";
|
|
4
4
|
import { resolveFlagRegistryEndpoint } from "../flag-registry-endpoint.js";
|
|
5
5
|
export const HOOK_TIMEOUT_DEBUG_CONTEXT_FLAG = "hook-timeout-debug-context";
|
package/dist/lib/daemon/flag.js
CHANGED
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
* instead of one request per flag.
|
|
9
9
|
*/
|
|
10
10
|
import { performance } from "node:perf_hooks";
|
|
11
|
-
import {
|
|
11
|
+
import { readLocalOverride, } from "@indigoai-us/hq-flags-client";
|
|
12
|
+
import { createHqFlagClient as createFlagClient } from "../flag-client-headers.js";
|
|
12
13
|
import { ensureCognitoIdToken } from "../../utils/cognito-session.js";
|
|
13
14
|
import { resolveFlagRegistryEndpoint } from "../flag-registry-endpoint.js";
|
|
14
15
|
import { resolveProcessFlagCompanyContext } from "../flag-registry.js";
|