@indigoai-us/hq-cli 5.345.236 → 5.345.238
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 +46 -0
- package/dist/command-catalog.generated.d.ts +1 -1
- package/dist/command-catalog.generated.js +1 -1
- package/dist/commands/bot.d.ts +2 -0
- package/dist/commands/bot.js +32 -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/agent-kit/inbox-state.d.ts +2 -1
- package/dist/lib/agent-kit/inbox-state.js +27 -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 +32 -3
- package/dist/lib/bot/promote.js +188 -16
- package/dist/lib/bot/promotion-hold-reconcile.d.ts +56 -0
- package/dist/lib/bot/promotion-hold-reconcile.js +155 -0
- 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 +35 -2
- package/dist/lib/daemon/run.js +108 -15
- 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
|
@@ -9,19 +9,163 @@
|
|
|
9
9
|
* adapter off there is skipped with reason flag-off and the rest run in one
|
|
10
10
|
* sync), and after the sync the signed-in person's vault cursors are mirrored
|
|
11
11
|
* to workspace/signals/watermarks/{co}/{cursorKey}.json through ctx.write.
|
|
12
|
+
*
|
|
13
|
+
* The step gives the sync the hot-channel signals pass, the same one
|
|
14
|
+
* `hq sources sync` and the bot's plain hot-signal-sync job give it, so a
|
|
15
|
+
* source the sync lands gets its signals in the same run. Without it a landed
|
|
16
|
+
* meeting moved the cursor and was never read again. The step records what the
|
|
17
|
+
* pass did: `signalsOut`, `modelTurns` and `detail.signalsPass`. A pass that
|
|
18
|
+
* fails (the tool signed out, out of usage, timed out, an unusable reply)
|
|
19
|
+
* makes the step `partial`; the documents it did not finish stay queued in
|
|
20
|
+
* `sources/_signals-pending/` (or unmarked in the channel's worklist), and a
|
|
21
|
+
* later run's pass takes them first.
|
|
12
22
|
*/
|
|
13
23
|
import * as fs from "node:fs";
|
|
14
24
|
import * as path from "node:path";
|
|
15
25
|
import { TEMPORARY_ADAPTER_ERROR_CODES } from "../../hot-channels/contract.js";
|
|
26
|
+
// A module with no imports. This file must not statically import alert.ts,
|
|
27
|
+
// run.ts or signals-pass.ts: they reach the signals engine, which reads
|
|
28
|
+
// `adaptersStep` while it loads.
|
|
29
|
+
import { SIGNED_OUT_SIGNALS_CODES, signalsPassFailureOf } from "../../hot-channels/signals-pass-failure.js";
|
|
16
30
|
import { FLAG_OFF_REASON, gateAdapters, readSignalsAdaptersCatalog } from "../adapters-catalog.js";
|
|
17
31
|
import { assertNoEscapingLinks } from "../write-guard.js";
|
|
18
32
|
export const defaultHotChannelSync = async (input) => {
|
|
19
33
|
const { runCompanyHotChannelSync } = await import("../../../commands/sources.js");
|
|
20
34
|
return runCompanyHotChannelSync(input);
|
|
21
35
|
};
|
|
36
|
+
/**
|
|
37
|
+
* The pass `hq sources sync` (commands/sources.ts `runSync`) and the bot's
|
|
38
|
+
* plain hot-signal-sync job (commands/bot.ts) build: the local signals pass on
|
|
39
|
+
* the Executive bot's runtime choice, recording what it saw of the Claude
|
|
40
|
+
* login for `hq bot status`. Only `onDocumentSent` is added here.
|
|
41
|
+
*/
|
|
42
|
+
export const defaultSignalsPass = async (input) => {
|
|
43
|
+
const [{ createClaudeSignalsPass }, { executiveSignalsRuntimeOptions }, { recordSignalsPassClaudeLogin }] = await Promise.all([
|
|
44
|
+
import("../../hot-channels/signals-pass.js"),
|
|
45
|
+
import("../../hot-channels/signals-runtime.js"),
|
|
46
|
+
import("../../hot-channels/signals-claude-login.js"),
|
|
47
|
+
]);
|
|
48
|
+
return createClaudeSignalsPass({
|
|
49
|
+
hqRoot: input.hqRoot,
|
|
50
|
+
company: input.company,
|
|
51
|
+
...executiveSignalsRuntimeOptions(),
|
|
52
|
+
onClaudeLogin: recordSignalsPassClaudeLogin,
|
|
53
|
+
onDocumentSent: input.onDocumentSent,
|
|
54
|
+
onLoginRoute: input.onLoginRoute,
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
/** The longest pass failure text kept in the run record and the alert. */
|
|
58
|
+
const MAX_PASS_FAILURE_CHARS = 200;
|
|
59
|
+
/**
|
|
60
|
+
* The pass as the engine's adapters step runs it. It is the pass it wraps
|
|
61
|
+
* (`inner`), with three rules that keep the run record true and the extract
|
|
62
|
+
* step unchanged:
|
|
63
|
+
*
|
|
64
|
+
* - A channel folder with a `source.yaml` is the extract step's: that step
|
|
65
|
+
* reads it through the same ontology worklist later in the run. The pass is
|
|
66
|
+
* not called for it, so it neither takes those items nor marks them done.
|
|
67
|
+
* - Every other landed document is written to `sources/_signals-pending/`
|
|
68
|
+
* before the pass starts. The sync has already moved the cursor past it, so
|
|
69
|
+
* a pass that throws before its own queueing would otherwise lose it.
|
|
70
|
+
* - After a pass that returned without failing, landed documents still queued
|
|
71
|
+
* are counted as deferred: the run's document cap was spent before them.
|
|
72
|
+
*/
|
|
73
|
+
export async function trackSignalsPass(hqRoot, company, inner, usage) {
|
|
74
|
+
const { channelOf, queuePendingSignals, readPendingSignals } = await import("../../hot-channels/signals-pass.js");
|
|
75
|
+
const vaultRoot = path.join(hqRoot, "companies", company);
|
|
76
|
+
const extractOwns = (channel) => fs.existsSync(path.join(vaultRoot, "sources", channel, "source.yaml"));
|
|
77
|
+
return async (result, guard) => {
|
|
78
|
+
const left = (usage.leftToExtract ??= []);
|
|
79
|
+
const leave = (channel) => {
|
|
80
|
+
if (!left.includes(channel))
|
|
81
|
+
left.push(channel);
|
|
82
|
+
};
|
|
83
|
+
const byChannel = new Map();
|
|
84
|
+
for (const key of result.landedKeys ?? []) {
|
|
85
|
+
const channel = channelOf(key);
|
|
86
|
+
if (channel === null)
|
|
87
|
+
continue;
|
|
88
|
+
if (extractOwns(channel))
|
|
89
|
+
leave(channel);
|
|
90
|
+
else
|
|
91
|
+
byChannel.set(channel, [...(byChannel.get(channel) ?? []), key]);
|
|
92
|
+
}
|
|
93
|
+
let channel = result.channel;
|
|
94
|
+
if (channel !== undefined && extractOwns(channel)) {
|
|
95
|
+
leave(channel);
|
|
96
|
+
channel = undefined;
|
|
97
|
+
}
|
|
98
|
+
if (channel === undefined && byChannel.size === 0)
|
|
99
|
+
return 0;
|
|
100
|
+
for (const [ch, keys] of byChannel)
|
|
101
|
+
await queuePendingSignals(vaultRoot, ch, keys, guard?.beforeWrite);
|
|
102
|
+
const { channel: _own, landedKeys: _all, ...rest } = result;
|
|
103
|
+
const written = await inner({ ...rest, ...(channel !== undefined ? { channel } : {}), landedKeys: [...byChannel.values()].flat() }, guard);
|
|
104
|
+
let waiting = 0;
|
|
105
|
+
for (const [ch, keys] of byChannel) {
|
|
106
|
+
const pending = new Set(await readPendingSignals(vaultRoot, ch));
|
|
107
|
+
waiting += keys.filter((key) => pending.has(key)).length;
|
|
108
|
+
}
|
|
109
|
+
if (waiting > 0) {
|
|
110
|
+
const deferred = (usage.deferred ??= {});
|
|
111
|
+
deferred[result.adapterId] = (deferred[result.adapterId] ?? 0) + waiting;
|
|
112
|
+
}
|
|
113
|
+
return written;
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
/** Channel -> landed documents waiting in `companies/{co}/sources/_signals-pending/`. Unreadable files count as none. */
|
|
117
|
+
export function pendingSignalsCounts(hqRoot, company) {
|
|
118
|
+
const dir = path.join(hqRoot, "companies", company, "sources", "_signals-pending");
|
|
119
|
+
let files;
|
|
120
|
+
try {
|
|
121
|
+
files = fs.readdirSync(dir).filter((f) => f.endsWith(".json")).sort();
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
// No pending folder: nothing waits.
|
|
125
|
+
return {};
|
|
126
|
+
}
|
|
127
|
+
const out = {};
|
|
128
|
+
for (const file of files) {
|
|
129
|
+
try {
|
|
130
|
+
const parsed = JSON.parse(fs.readFileSync(path.join(dir, file), "utf8"));
|
|
131
|
+
const n = Array.isArray(parsed) ? parsed.filter((k) => typeof k === "string").length : 0;
|
|
132
|
+
if (n > 0)
|
|
133
|
+
out[file.slice(0, -".json".length)] = n;
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
// A pending file that cannot be read: the pass reads it as empty too.
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return out;
|
|
140
|
+
}
|
|
141
|
+
function waitText(n) {
|
|
142
|
+
return `${n} landed document${n === 1 ? " waits" : "s wait"} in sources/_signals-pending/ for a later run`;
|
|
143
|
+
}
|
|
144
|
+
function passFailureText(failures, pending) {
|
|
145
|
+
const which = Object.entries(failures)
|
|
146
|
+
.map(([adapter, why]) => `${adapter} (${why.slice(0, 120)})`)
|
|
147
|
+
.join(", ");
|
|
148
|
+
const waiting = Object.values(pending).reduce((n, v) => n + v, 0);
|
|
149
|
+
// The step queues every landed document before the pass starts, so a count
|
|
150
|
+
// of zero means nothing of this run's is left to do.
|
|
151
|
+
return `the signals pass did not finish for ${which}${waiting > 0 ? `; ${waitText(waiting)}` : ""}`;
|
|
152
|
+
}
|
|
153
|
+
function deferredText(deferred) {
|
|
154
|
+
const total = Object.values(deferred).reduce((n, v) => n + v, 0);
|
|
155
|
+
return `the signals pass reached its document cap before ${Object.keys(deferred).join(", ")}; ${waitText(total)}`;
|
|
156
|
+
}
|
|
22
157
|
/** Adapters whose run record carries the token level (US-010). */
|
|
23
158
|
const TOKEN_LEVEL_ADAPTERS = new Set(["attio", "gmail"]);
|
|
24
|
-
|
|
159
|
+
/**
|
|
160
|
+
* The sync report as the step's result. `pass` is what the step itself saw of
|
|
161
|
+
* the signals pass; with it the result also carries `signalsOut`, `modelTurns`
|
|
162
|
+
* and `detail.signalsPass`. An outcome that failed only because the pass
|
|
163
|
+
* failed (its sources landed) is not an adapter failure: it makes the step
|
|
164
|
+
* `partial` with the pass's reason, and is listed under
|
|
165
|
+
* `detail.signalsPass.failures`. Documents landed this run that the pass's
|
|
166
|
+
* document cap left queued (`pass.deferred`) make the step `partial` too.
|
|
167
|
+
*/
|
|
168
|
+
export function mapSyncReport(report, pass) {
|
|
25
169
|
if (report.signInRequired) {
|
|
26
170
|
return { status: "skipped", itemsIn: 0, itemsOut: 0, skippedReason: "no-login", byAdapter: {}, errorKind: "signed-out" };
|
|
27
171
|
}
|
|
@@ -37,6 +181,7 @@ export function mapSyncReport(report) {
|
|
|
37
181
|
let ok = 0;
|
|
38
182
|
let failed = 0;
|
|
39
183
|
let reconnect = false;
|
|
184
|
+
const passFailures = {};
|
|
40
185
|
for (const o of report.outcomes) {
|
|
41
186
|
byAdapter[o.adapter] = (byAdapter[o.adapter] ?? 0) + o.landed;
|
|
42
187
|
if (o.status !== "gated")
|
|
@@ -45,18 +190,28 @@ export function mapSyncReport(report) {
|
|
|
45
190
|
if (o.tokenLevel && TOKEN_LEVEL_ADAPTERS.has(o.adapter) && tokenLevels[o.adapter] !== "workspace") {
|
|
46
191
|
tokenLevels[o.adapter] = o.tokenLevel;
|
|
47
192
|
}
|
|
193
|
+
const passFailure = signalsPassFailureOf(o);
|
|
194
|
+
// The adapter ran and landed its sources; only the pass after it failed.
|
|
195
|
+
// Its own outcome is `ok`, so extract still sees the hot channel as run.
|
|
196
|
+
const status = passFailure !== null ? "ok" : o.status;
|
|
48
197
|
const seen = adapterOutcomes[o.adapter];
|
|
49
|
-
if (seen === undefined ||
|
|
50
|
-
adapterOutcomes[o.adapter] =
|
|
198
|
+
if (seen === undefined || status === "failed" || (status === "ok" && seen !== "failed"))
|
|
199
|
+
adapterOutcomes[o.adapter] = status;
|
|
51
200
|
itemsIn += o.landed + o.duplicates;
|
|
52
201
|
itemsOut += o.landed;
|
|
53
202
|
if (o.status === "ok")
|
|
54
203
|
ok += 1;
|
|
55
|
-
|
|
204
|
+
// A SignalsPassError gives its code; any other error its message, which is cut here.
|
|
205
|
+
if (passFailure !== null)
|
|
206
|
+
passFailures[o.adapter] ??= passFailure.trim().slice(0, MAX_PASS_FAILURE_CHARS) || "unknown-error";
|
|
207
|
+
else if (o.status === "failed")
|
|
56
208
|
failed += 1;
|
|
57
209
|
if (o.reconnect)
|
|
58
210
|
reconnect = true;
|
|
59
211
|
}
|
|
212
|
+
const passFailed = Object.keys(passFailures).length;
|
|
213
|
+
const deferred = Object.fromEntries(Object.entries(pass?.deferred ?? {}).filter(([, n]) => n > 0));
|
|
214
|
+
const leftToExtract = pass?.leftToExtract ?? [];
|
|
60
215
|
const result = { status: "ok", itemsIn, itemsOut, byAdapter };
|
|
61
216
|
if (Object.keys(itemsInByAdapter).length > 0)
|
|
62
217
|
result.itemsInByAdapter = itemsInByAdapter;
|
|
@@ -64,6 +219,30 @@ export function mapSyncReport(report) {
|
|
|
64
219
|
result.tokenLevels = tokenLevels;
|
|
65
220
|
if (Object.keys(adapterOutcomes).length > 0)
|
|
66
221
|
result.adapterOutcomes = adapterOutcomes;
|
|
222
|
+
const signals = report.entries.reduce((n, e) => n + e.signalsGenerated, 0);
|
|
223
|
+
if (pass) {
|
|
224
|
+
result.signalsOut = signals;
|
|
225
|
+
if (pass.documents > 0)
|
|
226
|
+
result.modelTurns = pass.documents;
|
|
227
|
+
}
|
|
228
|
+
const pending = pass?.pending ?? {};
|
|
229
|
+
if (signals > 0 ||
|
|
230
|
+
passFailed > 0 ||
|
|
231
|
+
(pass !== undefined && (pass.documents > 0 || Object.keys(pending).length > 0 || leftToExtract.length > 0))) {
|
|
232
|
+
// With no document sent, a failure code still names the tool (claude-*, codex-*).
|
|
233
|
+
const fromCode = /^(claude|codex)-/.exec(Object.values(passFailures)[0] ?? "")?.[1] ?? null;
|
|
234
|
+
const detail = {
|
|
235
|
+
signals,
|
|
236
|
+
...(pass?.route ? { route: pass.route } : {}),
|
|
237
|
+
documents: pass?.documents ?? 0,
|
|
238
|
+
runtime: pass?.runtime ?? fromCode,
|
|
239
|
+
...(passFailed > 0 ? { failures: passFailures } : {}),
|
|
240
|
+
...(Object.keys(deferred).length > 0 ? { deferred } : {}),
|
|
241
|
+
...(Object.keys(pending).length > 0 ? { pending } : {}),
|
|
242
|
+
...(leftToExtract.length > 0 ? { leftToExtract: [...leftToExtract].sort() } : {}),
|
|
243
|
+
};
|
|
244
|
+
result.detail = { signalsPass: detail };
|
|
245
|
+
}
|
|
67
246
|
if (report.outcomes.length === 0) {
|
|
68
247
|
result.status = "skipped";
|
|
69
248
|
result.skippedReason = "no-channels";
|
|
@@ -73,8 +252,8 @@ export function mapSyncReport(report) {
|
|
|
73
252
|
result.skippedReason = FLAG_OFF_REASON;
|
|
74
253
|
}
|
|
75
254
|
else if (failed > 0) {
|
|
76
|
-
result.status = ok > 0 ? "partial" : "failed";
|
|
77
|
-
const failures = report.outcomes.filter((o) => o.status === "failed");
|
|
255
|
+
result.status = ok + passFailed > 0 ? "partial" : "failed";
|
|
256
|
+
const failures = report.outcomes.filter((o) => o.status === "failed" && signalsPassFailureOf(o) === null);
|
|
78
257
|
const first = failures[0];
|
|
79
258
|
result.error = first?.message ?? "adapter failed";
|
|
80
259
|
// A rate limit clears on its own (US-009 AC9): when every failure is one,
|
|
@@ -82,6 +261,19 @@ export function mapSyncReport(report) {
|
|
|
82
261
|
const temporary = failures.every((o) => o.errorCode !== undefined && TEMPORARY_ADAPTER_ERROR_CODES.has(o.errorCode));
|
|
83
262
|
result.errorKind = reconnect ? "reconnect" : temporary ? "transient" : "other";
|
|
84
263
|
}
|
|
264
|
+
else if (passFailed > 0) {
|
|
265
|
+
result.status = "partial";
|
|
266
|
+
result.error = passFailureText(passFailures, pending);
|
|
267
|
+
// A signed-out tool is fixed on this computer, not by waiting. `signed-out`
|
|
268
|
+
// is kept for the HQ login (the reply tells the member to run hq login).
|
|
269
|
+
result.errorKind = Object.values(passFailures).every((code) => SIGNED_OUT_SIGNALS_CODES.has(code)) ? "config" : "other";
|
|
270
|
+
}
|
|
271
|
+
else if (Object.keys(deferred).length > 0) {
|
|
272
|
+
// Landed this run and not read: not a clean run, though nothing failed.
|
|
273
|
+
result.status = "partial";
|
|
274
|
+
result.error = deferredText(deferred);
|
|
275
|
+
result.errorKind = "other";
|
|
276
|
+
}
|
|
85
277
|
else if (reconnect) {
|
|
86
278
|
result.errorKind = "reconnect";
|
|
87
279
|
}
|
|
@@ -141,6 +333,18 @@ export const adaptersStep = {
|
|
|
141
333
|
if (skipped && gating.enabled.length === 0) {
|
|
142
334
|
return { status: "skipped", itemsIn: 0, itemsOut: 0, skippedReason: FLAG_OFF_REASON, byAdapter: {}, adapterSkips: gating.skips };
|
|
143
335
|
}
|
|
336
|
+
// A new pass per run: its login check and document cap are per run.
|
|
337
|
+
const usage = { documents: 0, runtime: null };
|
|
338
|
+
const pass = await (ctx.signalsPass ?? defaultSignalsPass)({
|
|
339
|
+
hqRoot: ctx.hqRoot,
|
|
340
|
+
company: ctx.company,
|
|
341
|
+
onDocumentSent: (runtime) => {
|
|
342
|
+
usage.documents += 1;
|
|
343
|
+
usage.runtime = runtime;
|
|
344
|
+
},
|
|
345
|
+
onLoginRoute: (route) => { usage.route = route; },
|
|
346
|
+
});
|
|
347
|
+
const signalsGenerated = await trackSignalsPass(ctx.hqRoot, ctx.company, pass, usage);
|
|
144
348
|
const base = {
|
|
145
349
|
hqRoot: ctx.hqRoot,
|
|
146
350
|
company: ctx.company,
|
|
@@ -148,11 +352,13 @@ export const adaptersStep = {
|
|
|
148
352
|
trigger: ctx.trigger === "job" ? "scheduled" : "on-demand",
|
|
149
353
|
catchUp: ctx.catchUp,
|
|
150
354
|
...(ctx.isFlagOn ? { isFlagOn: ctx.isFlagOn } : {}),
|
|
355
|
+
signalsGenerated,
|
|
151
356
|
};
|
|
152
357
|
// One sync for the enabled list: an enabled adapter the hq-pro catalog
|
|
153
358
|
// does not list just has nothing to run, instead of failing the step.
|
|
154
359
|
const report = await sync(skipped ? { ...base, onlyAdapters: gating.enabled } : base);
|
|
155
|
-
const
|
|
360
|
+
const ran = !report.signInRequired && !report.skipped;
|
|
361
|
+
const result = mapSyncReport(report, ran ? { ...usage, pending: pendingSignalsCounts(ctx.hqRoot, ctx.company) } : undefined);
|
|
156
362
|
const adapterSkips = { ...gating.skips };
|
|
157
363
|
for (const o of report.outcomes)
|
|
158
364
|
if (o.status === "gated")
|
|
@@ -123,7 +123,7 @@ import * as os from "node:os";
|
|
|
123
123
|
import * as path from "node:path";
|
|
124
124
|
import yaml from "js-yaml";
|
|
125
125
|
import { findPriorSignals, normalizeSignalTitle, priorSignalPath } from "../prior-signals.js";
|
|
126
|
-
import { splitFrontmatter } from "../../hot-channels/signals-pass.js";
|
|
126
|
+
import { claudeApiKeyLogin, claudeSignalsEnv, splitFrontmatter } from "../../hot-channels/signals-pass.js";
|
|
127
127
|
import { audienceKey } from "../../hot-channels/audience.js";
|
|
128
128
|
import { MEETINGS_ADAPTER_ID, MEETINGS_TRANSCRIPT_DIR } from "../../hot-channels/adapters/meetings.js";
|
|
129
129
|
import { isBotRuntimeId } from "../../bot/config.js";
|
|
@@ -1127,9 +1127,23 @@ export function chooseExtractRuntime(main, avail, platform = process.platform) {
|
|
|
1127
1127
|
function toolAvailability(ctx, bin, statusArgs, parse) {
|
|
1128
1128
|
if (!resolveOnPath(bin, process.env.PATH))
|
|
1129
1129
|
return { installed: false, signedIn: null };
|
|
1130
|
-
const res = ctx.spawn(bin, statusArgs, { env:
|
|
1130
|
+
const res = ctx.spawn(bin, statusArgs, { env: claudeSignalsEnv(process.env), timeoutMs: SIGN_IN_CHECK_TIMEOUT_MS });
|
|
1131
1131
|
if (res.error)
|
|
1132
1132
|
return { installed: true, signedIn: null };
|
|
1133
|
+
// A logged-in API key or third-party provider is not a subscription login.
|
|
1134
|
+
// Match the pass preflight before allowing an extract fallback turn.
|
|
1135
|
+
const start = res.stdout.indexOf("{");
|
|
1136
|
+
if (start >= 0) {
|
|
1137
|
+
try {
|
|
1138
|
+
const status = JSON.parse(res.stdout.slice(start));
|
|
1139
|
+
if (status && typeof status === "object" && claudeApiKeyLogin(status)) {
|
|
1140
|
+
return { installed: true, signedIn: false };
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
catch {
|
|
1144
|
+
// Keep the existing plain-text auth-status compatibility.
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1133
1147
|
return { installed: true, signedIn: parse({ code: res.status, signal: null, stdout: res.stdout, stderr: res.stderr }) };
|
|
1134
1148
|
}
|
|
1135
1149
|
export function claudeTurnArgs(prompt, scope, maxTurns, budgetUsd) {
|
|
@@ -1254,7 +1268,7 @@ function runTurn(ctx, runtime, prompt, scope, budgetUsd, opts) {
|
|
|
1254
1268
|
let cwd = scope.turnDir;
|
|
1255
1269
|
let cmd = runtime === "claude" ? opts.claudeBin : runtime === "grok" ? opts.grokBin : opts.codexBin;
|
|
1256
1270
|
let args = runtime === "claude" ? claudeTurnArgs(prompt, scope, ctx.maxTurns, budgetUsd) : [];
|
|
1257
|
-
let env = { ...process.env, HQ_ROOT: ctx.hqRoot };
|
|
1271
|
+
let env = runtime === "claude" ? claudeSignalsEnv(process.env) : { ...process.env, HQ_ROOT: ctx.hqRoot };
|
|
1258
1272
|
let grokHome;
|
|
1259
1273
|
let codexRoot;
|
|
1260
1274
|
let codexOutput;
|
|
@@ -1453,7 +1467,7 @@ export async function extractPartialDocument(ctx, doc, prior) {
|
|
|
1453
1467
|
const cwd = fs.mkdtempSync(path.join(os.tmpdir(), "hq-incremental-"));
|
|
1454
1468
|
let run;
|
|
1455
1469
|
try {
|
|
1456
|
-
run = ctx.spawn("claude", ["-p", ...CLAUDE_ISOLATION_ARGS, "--output-format", "json", "--max-turns", String(ctx.maxTurns), "--max-budget-usd", String(ctx.maxBudgetUsd)], { cwd, timeoutMs: 120_000, input: prompt });
|
|
1470
|
+
run = ctx.spawn("claude", ["-p", ...CLAUDE_ISOLATION_ARGS, "--output-format", "json", "--max-turns", String(ctx.maxTurns), "--max-budget-usd", String(ctx.maxBudgetUsd)], { cwd, env: claudeSignalsEnv(process.env), timeoutMs: 120_000, input: prompt });
|
|
1457
1471
|
}
|
|
1458
1472
|
finally {
|
|
1459
1473
|
fs.rmSync(cwd, { recursive: true, force: true });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** Pluggable step interface for the `hq signals run` engine. */
|
|
2
2
|
import type { OnDemandSyncReport } from "../../hot-channels/run.js";
|
|
3
|
-
import type { RunTrigger } from "../../hot-channels/ledger.js";
|
|
3
|
+
import type { RunTrigger, SignalsGeneratedFn } from "../../hot-channels/ledger.js";
|
|
4
4
|
import type { UploadDeps } from "./upload.js";
|
|
5
5
|
import type { AdapterFlagReader } from "../adapters-catalog.js";
|
|
6
6
|
/** Same input shape as runCompanyHotChannelSync in src/commands/sources.ts. */
|
|
@@ -16,7 +16,25 @@ export type HotChannelSyncFn = (input: {
|
|
|
16
16
|
now?: () => Date;
|
|
17
17
|
trigger?: RunTrigger;
|
|
18
18
|
catchUp?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* The signals pass the sync runs over each adapter's landed sources, as
|
|
21
|
+
* `hq sources sync` and the bot's plain hot-signal-sync job pass it. The
|
|
22
|
+
* adapters step always gives one.
|
|
23
|
+
*/
|
|
24
|
+
signalsGenerated?: SignalsGeneratedFn;
|
|
19
25
|
}) => Promise<OnDemandSyncReport>;
|
|
26
|
+
/**
|
|
27
|
+
* Builds the signals pass for one company's run. The adapters step makes one
|
|
28
|
+
* per run (the pass keeps its login check and document cap per run) and hands
|
|
29
|
+
* it to the sync. `onDocumentSent` is called once per document the pass sends
|
|
30
|
+
* to its tool, with the tool's name (`claude` or `codex`).
|
|
31
|
+
*/
|
|
32
|
+
export type SignalsPassFactory = (input: {
|
|
33
|
+
hqRoot: string;
|
|
34
|
+
company: string;
|
|
35
|
+
onDocumentSent: (runtime: string) => void;
|
|
36
|
+
onLoginRoute?: (route: "fleet" | "claude-cli" | "codex-bot") => void;
|
|
37
|
+
}) => SignalsGeneratedFn | Promise<SignalsGeneratedFn>;
|
|
20
38
|
export type StepName = "garden" | "adapters" | "extract" | "upload";
|
|
21
39
|
export type StepStatus = "ok" | "skipped" | "failed" | "partial";
|
|
22
40
|
export type ErrorKind = "reconnect" | "signed-out" | "transient" | "config" | "other";
|
|
@@ -48,6 +66,12 @@ export interface StepContext {
|
|
|
48
66
|
write: (relPath: string, data: string) => void;
|
|
49
67
|
/** Hot-channel sync used by the adapters step; defaults to runCompanyHotChannelSync. */
|
|
50
68
|
hotChannelSync?: HotChannelSyncFn;
|
|
69
|
+
/**
|
|
70
|
+
* The signals pass the adapters step gives the sync; defaults to the local
|
|
71
|
+
* pass `hq sources sync` uses (createClaudeSignalsPass with the Executive
|
|
72
|
+
* bot's runtime options).
|
|
73
|
+
*/
|
|
74
|
+
signalsPass?: SignalsPassFactory;
|
|
51
75
|
/** Overrides for the upload step's session, fetch and vault reader (tests). */
|
|
52
76
|
uploadDeps?: Partial<UploadDeps>;
|
|
53
77
|
/** Registered hot-channel adapter ids; defaults to the builtin registry. */
|
|
@@ -99,6 +123,12 @@ export interface StepResult {
|
|
|
99
123
|
* when any failed, else `ok` when any was ok.
|
|
100
124
|
*/
|
|
101
125
|
adapterOutcomes?: Record<string, string>;
|
|
126
|
+
/**
|
|
127
|
+
* adapters step: signals the hot-channel signals pass wrote this run, over
|
|
128
|
+
* every adapter (the sync's ledger `signalsGenerated`). They count in the
|
|
129
|
+
* run record's `counts.signalsOut`. `itemsOut` stays the sources landed.
|
|
130
|
+
*/
|
|
131
|
+
signalsOut?: number;
|
|
102
132
|
uploaded?: {
|
|
103
133
|
count: number;
|
|
104
134
|
bytes: number;
|
|
@@ -122,6 +152,38 @@ export interface StepResult {
|
|
|
122
152
|
/** Candidates deleted after a turn because they lacked source_ref/audience_key or had a bad type. */
|
|
123
153
|
rejectedCandidates?: number;
|
|
124
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* What the adapters step records about the hot-channel signals pass under
|
|
157
|
+
* `detail.signalsPass`. Present when the pass sent a document, wrote a signal,
|
|
158
|
+
* failed, or left documents waiting; absent on a run where it had nothing to do.
|
|
159
|
+
*/
|
|
160
|
+
export interface SignalsPassDetail {
|
|
161
|
+
route?: "fleet" | "claude-cli" | "codex-bot";
|
|
162
|
+
/** Signals the pass wrote this run (also the step's `signalsOut`). */
|
|
163
|
+
signals: number;
|
|
164
|
+
/** Documents the pass sent to its tool after the login check passed. */
|
|
165
|
+
documents: number;
|
|
166
|
+
/** The tool the pass ran on (`claude` or `codex`), or null when it could not be told. */
|
|
167
|
+
runtime: string | null;
|
|
168
|
+
/**
|
|
169
|
+
* Adapter id -> why its pass did not finish: a signals pass error code
|
|
170
|
+
* (`claude-logged-out`, `claude-usage-limit`, ...) or another error's message.
|
|
171
|
+
*/
|
|
172
|
+
failures?: Record<string, string>;
|
|
173
|
+
/**
|
|
174
|
+
* Adapter id -> documents it landed this run that the pass did not read
|
|
175
|
+
* because the run's document cap was spent first. They are queued.
|
|
176
|
+
*/
|
|
177
|
+
deferred?: Record<string, number>;
|
|
178
|
+
/** Channel -> landed documents waiting in `sources/_signals-pending/{channel}.json` after the run. */
|
|
179
|
+
pending?: Record<string, number>;
|
|
180
|
+
/** Channels with a `source.yaml` the pass left to the extract step. */
|
|
181
|
+
leftToExtract?: string[];
|
|
182
|
+
}
|
|
183
|
+
/** The adapters step's `detail.signalsPass`, or null when the step recorded none. */
|
|
184
|
+
export declare function readSignalsPassDetail(step: {
|
|
185
|
+
detail?: Record<string, unknown>;
|
|
186
|
+
} | undefined): SignalsPassDetail | null;
|
|
125
187
|
export interface StepFailure {
|
|
126
188
|
file: string;
|
|
127
189
|
error: string;
|
|
@@ -1,3 +1,35 @@
|
|
|
1
|
+
function keptEntries(x, keep) {
|
|
2
|
+
if (typeof x !== "object" || x === null || Array.isArray(x))
|
|
3
|
+
return undefined;
|
|
4
|
+
const out = {};
|
|
5
|
+
for (const [key, value] of Object.entries(x))
|
|
6
|
+
if (keep(value))
|
|
7
|
+
out[key] = value;
|
|
8
|
+
return Object.keys(out).length > 0 ? out : undefined;
|
|
9
|
+
}
|
|
10
|
+
/** The adapters step's `detail.signalsPass`, or null when the step recorded none. */
|
|
11
|
+
export function readSignalsPassDetail(step) {
|
|
12
|
+
const raw = step?.detail?.signalsPass;
|
|
13
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw))
|
|
14
|
+
return null;
|
|
15
|
+
const v = raw;
|
|
16
|
+
const count = (x) => (typeof x === "number" && Number.isFinite(x) && x > 0 ? x : 0);
|
|
17
|
+
const failures = keptEntries(v.failures, (x) => typeof x === "string" && x.length > 0);
|
|
18
|
+
const positive = (x) => typeof x === "number" && Number.isFinite(x) && x > 0;
|
|
19
|
+
const deferred = keptEntries(v.deferred, positive);
|
|
20
|
+
const pending = keptEntries(v.pending, positive);
|
|
21
|
+
const leftToExtract = Array.isArray(v.leftToExtract) ? v.leftToExtract.filter((x) => typeof x === "string" && x.length > 0) : [];
|
|
22
|
+
return {
|
|
23
|
+
signals: count(v.signals),
|
|
24
|
+
...(v.route === "fleet" || v.route === "claude-cli" || v.route === "codex-bot" ? { route: v.route } : {}),
|
|
25
|
+
documents: count(v.documents),
|
|
26
|
+
runtime: typeof v.runtime === "string" && v.runtime.trim() !== "" ? v.runtime : null,
|
|
27
|
+
...(failures ? { failures } : {}),
|
|
28
|
+
...(deferred ? { deferred } : {}),
|
|
29
|
+
...(pending ? { pending } : {}),
|
|
30
|
+
...(leftToExtract.length > 0 ? { leftToExtract } : {}),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
1
33
|
export function notImplemented() {
|
|
2
34
|
return { status: "skipped", itemsIn: 0, itemsOut: 0, skippedReason: "not-implemented" };
|
|
3
35
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detects a sync engine whose every cycle is refused by the sync service
|
|
3
|
+
* (HTTP 401). The engine keeps running and heartbeating in that state, so the
|
|
4
|
+
* daemon sees a healthy unit while the vault does not sync at all (the old
|
|
5
|
+
* sync is already off for it). hq-syncd reports it only on stderr, which the
|
|
6
|
+
* daemon writes to the unit's log:
|
|
7
|
+
*
|
|
8
|
+
* hq-syncd: GET /v1/vault/{uid}/snapshot: the server refused the token (401) and ...
|
|
9
|
+
* hq-syncd: cycle failed 6 time(s) in a row; next attempt in 1800 s
|
|
10
|
+
*
|
|
11
|
+
* A cycle that succeeds afterwards prints nothing, so the log alone cannot
|
|
12
|
+
* tell a refusal that has since cleared. The engine's status.json records the
|
|
13
|
+
* last finished cycle (`last_canary.at_ms`); a finished cycle after the log was
|
|
14
|
+
* last written means the refusal is over.
|
|
15
|
+
*/
|
|
16
|
+
/** Consecutive refused cycles after which the vault counts as not syncing. */
|
|
17
|
+
export declare const ENGINE_AUTH_REFUSED_AFTER = 3;
|
|
18
|
+
export interface SyncCoreAuthRefusal {
|
|
19
|
+
/** Cycles failed in a row when the log was last written. */
|
|
20
|
+
failuresInARow: number;
|
|
21
|
+
/** When the engine last wrote its log (the latest refused cycle). */
|
|
22
|
+
lastAt: string;
|
|
23
|
+
/** The engine's line naming the refused request, without its advice. */
|
|
24
|
+
request: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The refusal the engine for `vaultUid` is stuck in, or null. Null when the
|
|
28
|
+
* log's last cycle outcome is not a refused cycle, when fewer than
|
|
29
|
+
* ENGINE_AUTH_REFUSED_AFTER cycles failed in a row, or when a cycle finished
|
|
30
|
+
* after the log was last written.
|
|
31
|
+
*/
|
|
32
|
+
export declare function readEngineAuthRefusal(logPath: string, engineHome: string, vaultUid: string): SyncCoreAuthRefusal | null;
|
|
33
|
+
/** One line for status output and the self-check. */
|
|
34
|
+
export declare function describeAuthRefusal(refusal: SyncCoreAuthRefusal): string;
|
|
35
|
+
//# sourceMappingURL=engine-auth.d.ts.map
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detects a sync engine whose every cycle is refused by the sync service
|
|
3
|
+
* (HTTP 401). The engine keeps running and heartbeating in that state, so the
|
|
4
|
+
* daemon sees a healthy unit while the vault does not sync at all (the old
|
|
5
|
+
* sync is already off for it). hq-syncd reports it only on stderr, which the
|
|
6
|
+
* daemon writes to the unit's log:
|
|
7
|
+
*
|
|
8
|
+
* hq-syncd: GET /v1/vault/{uid}/snapshot: the server refused the token (401) and ...
|
|
9
|
+
* hq-syncd: cycle failed 6 time(s) in a row; next attempt in 1800 s
|
|
10
|
+
*
|
|
11
|
+
* A cycle that succeeds afterwards prints nothing, so the log alone cannot
|
|
12
|
+
* tell a refusal that has since cleared. The engine's status.json records the
|
|
13
|
+
* last finished cycle (`last_canary.at_ms`); a finished cycle after the log was
|
|
14
|
+
* last written means the refusal is over.
|
|
15
|
+
*/
|
|
16
|
+
import * as fs from "node:fs";
|
|
17
|
+
import * as path from "node:path";
|
|
18
|
+
/** Consecutive refused cycles after which the vault counts as not syncing. */
|
|
19
|
+
export const ENGINE_AUTH_REFUSED_AFTER = 3;
|
|
20
|
+
const LOG_TAIL_BYTES = 64 * 1024;
|
|
21
|
+
const REFUSED = /the server refused the token \(401\)/;
|
|
22
|
+
const FAILED_IN_A_ROW = /^hq-syncd: cycle failed (\d+) time\(s\) in a row/;
|
|
23
|
+
function tail(file) {
|
|
24
|
+
let fd;
|
|
25
|
+
try {
|
|
26
|
+
fd = fs.openSync(file, "r");
|
|
27
|
+
const stat = fs.fstatSync(fd);
|
|
28
|
+
if (!stat.isFile())
|
|
29
|
+
return null;
|
|
30
|
+
const length = Math.min(stat.size, LOG_TAIL_BYTES);
|
|
31
|
+
const buffer = Buffer.alloc(length);
|
|
32
|
+
fs.readSync(fd, buffer, 0, length, stat.size - length);
|
|
33
|
+
return { text: buffer.toString("utf8"), mtimeMs: stat.mtimeMs };
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
if (fd !== undefined)
|
|
40
|
+
fs.closeSync(fd);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function lastFinishedCycleMs(engineHome, vaultUid) {
|
|
44
|
+
try {
|
|
45
|
+
const status = JSON.parse(fs.readFileSync(path.join(engineHome, ".hq", "sync-core", "status.json"), "utf8"));
|
|
46
|
+
const cycle = status.last_canary;
|
|
47
|
+
if (!cycle || cycle.vault !== vaultUid)
|
|
48
|
+
return undefined;
|
|
49
|
+
return typeof cycle.at_ms === "number" && Number.isFinite(cycle.at_ms) ? cycle.at_ms : undefined;
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The refusal the engine for `vaultUid` is stuck in, or null. Null when the
|
|
57
|
+
* log's last cycle outcome is not a refused cycle, when fewer than
|
|
58
|
+
* ENGINE_AUTH_REFUSED_AFTER cycles failed in a row, or when a cycle finished
|
|
59
|
+
* after the log was last written.
|
|
60
|
+
*/
|
|
61
|
+
export function readEngineAuthRefusal(logPath, engineHome, vaultUid) {
|
|
62
|
+
const log = tail(logPath);
|
|
63
|
+
if (!log)
|
|
64
|
+
return null;
|
|
65
|
+
const lines = log.text.split(/\r?\n/).map((line) => line.trim()).filter((line) => line.startsWith("hq-syncd:"));
|
|
66
|
+
let failedAt = -1;
|
|
67
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
68
|
+
if (FAILED_IN_A_ROW.test(lines[i])) {
|
|
69
|
+
failedAt = i;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (failedAt < 1)
|
|
74
|
+
return null;
|
|
75
|
+
// Anything the engine printed after the last failure count (a resume, a restart) means it moved on.
|
|
76
|
+
if (lines.slice(failedAt + 1).length > 0)
|
|
77
|
+
return null;
|
|
78
|
+
const reason = lines[failedAt - 1];
|
|
79
|
+
if (!REFUSED.test(reason))
|
|
80
|
+
return null;
|
|
81
|
+
const failuresInARow = Number(FAILED_IN_A_ROW.exec(lines[failedAt])[1]);
|
|
82
|
+
if (!Number.isSafeInteger(failuresInARow) || failuresInARow < ENGINE_AUTH_REFUSED_AFTER)
|
|
83
|
+
return null;
|
|
84
|
+
const finished = lastFinishedCycleMs(engineHome, vaultUid);
|
|
85
|
+
if (finished !== undefined && finished > log.mtimeMs)
|
|
86
|
+
return null;
|
|
87
|
+
const request = reason.replace(/^hq-syncd:\s*/, "").split(":")[0].slice(0, 120);
|
|
88
|
+
return { failuresInARow, lastAt: new Date(log.mtimeMs).toISOString(), request };
|
|
89
|
+
}
|
|
90
|
+
/** One line for status output and the self-check. */
|
|
91
|
+
export function describeAuthRefusal(refusal) {
|
|
92
|
+
return `NOT SYNCING: the sync service refused this machine's sign-in (HTTP 401) on ${refusal.request}, ` +
|
|
93
|
+
`${refusal.failuresInARow} cycles in a row (last ${refusal.lastAt}); the old sync is off for this vault, so nothing syncs. ` +
|
|
94
|
+
"Check `hq whoami`; if it is an agent identity, the sync service may not accept that identity's token yet";
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=engine-auth.js.map
|
|
@@ -79,10 +79,16 @@ export interface SyncCoreRunningCycle {
|
|
|
79
79
|
currentPath?: string;
|
|
80
80
|
stale: boolean;
|
|
81
81
|
}
|
|
82
|
+
export interface SyncCoreWakeChannel {
|
|
83
|
+
connected: boolean;
|
|
84
|
+
since?: string;
|
|
85
|
+
}
|
|
82
86
|
export interface SyncCoreEngineStatus {
|
|
83
87
|
engineVersion?: string;
|
|
84
88
|
startedAt?: string;
|
|
85
89
|
requests24h?: number;
|
|
90
|
+
/** The push (wake) channel as the engine last saw it for this vault; absent when the engine has not reported one. */
|
|
91
|
+
wakeChannel?: SyncCoreWakeChannel;
|
|
86
92
|
cycle?: SyncCoreRunningCycle;
|
|
87
93
|
lastCycle?: SyncCoreLastCycle;
|
|
88
94
|
}
|
|
@@ -194,6 +194,16 @@ function runningCycle(value, vaultUid, now) {
|
|
|
194
194
|
stale: transferring && updatedMs !== undefined && now.getTime() - updatedMs > SYNC_CORE_CYCLE_STALE_MS,
|
|
195
195
|
};
|
|
196
196
|
}
|
|
197
|
+
function vaultWakeChannel(value, vaultUid) {
|
|
198
|
+
if (!Array.isArray(value))
|
|
199
|
+
return undefined;
|
|
200
|
+
const entry = value.map(record).find((item) => item?.vault === vaultUid);
|
|
201
|
+
const channel = record(entry?.channel);
|
|
202
|
+
if (!channel || typeof channel.connected !== "boolean")
|
|
203
|
+
return undefined;
|
|
204
|
+
const since = isoTime(channel.since_ms);
|
|
205
|
+
return { connected: channel.connected, ...(since ? { since } : {}) };
|
|
206
|
+
}
|
|
197
207
|
export function readEngineStatus(engineHome, vaultUid, now = new Date()) {
|
|
198
208
|
const status = readStatusFile(engineHome);
|
|
199
209
|
if (!status)
|
|
@@ -207,6 +217,7 @@ export function readEngineStatus(engineHome, vaultUid, now = new Date()) {
|
|
|
207
217
|
const transferWaitUntil = cycle ? isoTime(cycle.transfer_wait_until_ms) : undefined;
|
|
208
218
|
const transfersQueued = cycle ? wholeCount(cycle.transfers_queued) : 0;
|
|
209
219
|
const running = runningCycle(status.cycle, vaultUid, now);
|
|
220
|
+
const wakeChannel = vaultWakeChannel(status.wakes, vaultUid);
|
|
210
221
|
return {
|
|
211
222
|
...(typeof status.engine_version === "string" && status.engine_version ? { engineVersion: status.engine_version } : {}),
|
|
212
223
|
...(startedAt ? { startedAt } : {}),
|
|
@@ -214,6 +225,7 @@ export function readEngineStatus(engineHome, vaultUid, now = new Date()) {
|
|
|
214
225
|
? { requests24h: status.requests_24h }
|
|
215
226
|
: {}),
|
|
216
227
|
...(running ? { cycle: running } : {}),
|
|
228
|
+
...(wakeChannel ? { wakeChannel } : {}),
|
|
217
229
|
...(cycle && atMs !== undefined
|
|
218
230
|
? {
|
|
219
231
|
lastCycle: {
|