@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.
Files changed (96) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/dist/command-catalog.generated.d.ts +1 -1
  3. package/dist/command-catalog.generated.js +1 -1
  4. package/dist/commands/bot.d.ts +2 -0
  5. package/dist/commands/bot.js +32 -0
  6. package/dist/commands/daemon.d.ts +1 -0
  7. package/dist/commands/daemon.js +70 -6
  8. package/dist/commands/deploy-app-db.js +4 -19
  9. package/dist/commands/deploy-app-upload.js +66 -40
  10. package/dist/commands/deploy-mutations.js +24 -16
  11. package/dist/commands/deploy-runtime-bindings.js +7 -26
  12. package/dist/commands/deploy-ssr.js +5 -24
  13. package/dist/commands/mesh.js +6 -2
  14. package/dist/commands/signals-run.d.ts +43 -2
  15. package/dist/commands/signals-run.js +85 -7
  16. package/dist/commands/sync-core.d.ts +7 -0
  17. package/dist/commands/sync-core.js +52 -3
  18. package/dist/lib/agent-kit/inbox-state.d.ts +2 -1
  19. package/dist/lib/agent-kit/inbox-state.js +27 -3
  20. package/dist/lib/bot/continuity.d.ts +21 -2
  21. package/dist/lib/bot/continuity.js +48 -19
  22. package/dist/lib/bot/fleet-cron.js +6 -0
  23. package/dist/lib/bot/fleet-local.d.ts +11 -1
  24. package/dist/lib/bot/fleet-local.js +21 -1
  25. package/dist/lib/bot/fleet-state.d.ts +129 -0
  26. package/dist/lib/bot/fleet-state.js +669 -0
  27. package/dist/lib/bot/promote.d.ts +32 -3
  28. package/dist/lib/bot/promote.js +188 -16
  29. package/dist/lib/bot/promotion-hold-reconcile.d.ts +56 -0
  30. package/dist/lib/bot/promotion-hold-reconcile.js +155 -0
  31. package/dist/lib/daemon/catalog.d.ts +13 -0
  32. package/dist/lib/daemon/catalog.js +32 -6
  33. package/dist/lib/daemon/lanes-reconcile-status.d.ts +0 -4
  34. package/dist/lib/daemon/lanes-reconcile-status.js +2 -12
  35. package/dist/lib/daemon/lanes-reconcile-watcher.d.ts +1 -1
  36. package/dist/lib/daemon/lanes-reconcile-watcher.js +2 -1
  37. package/dist/lib/daemon/legacy-handover.d.ts +38 -0
  38. package/dist/lib/daemon/legacy-handover.js +117 -0
  39. package/dist/lib/daemon/mesh-owner.js +2 -1
  40. package/dist/lib/daemon/run.d.ts +35 -2
  41. package/dist/lib/daemon/run.js +108 -15
  42. package/dist/lib/daemon/selfcheck.d.ts +28 -0
  43. package/dist/lib/daemon/selfcheck.js +86 -15
  44. package/dist/lib/deploy-api.d.ts +1 -1
  45. package/dist/lib/deploy-api.js +2 -1
  46. package/dist/lib/deploy-identity.d.ts +18 -0
  47. package/dist/lib/deploy-identity.js +179 -0
  48. package/dist/lib/hot-channels/alert.js +13 -6
  49. package/dist/lib/hot-channels/fleet-complete.d.ts +89 -0
  50. package/dist/lib/hot-channels/fleet-complete.js +157 -0
  51. package/dist/lib/hot-channels/run.js +2 -1
  52. package/dist/lib/hot-channels/signals-claude-login.d.ts +3 -2
  53. package/dist/lib/hot-channels/signals-claude-login.js +6 -1
  54. package/dist/lib/hot-channels/signals-pass-failure.d.ts +29 -0
  55. package/dist/lib/hot-channels/signals-pass-failure.js +36 -0
  56. package/dist/lib/hot-channels/signals-pass.d.ts +49 -2
  57. package/dist/lib/hot-channels/signals-pass.js +188 -12
  58. package/dist/lib/hot-channels/signals-runtime.d.ts +6 -3
  59. package/dist/lib/hot-channels/signals-runtime.js +11 -2
  60. package/dist/lib/lanes/reconcile-result.d.ts +5 -0
  61. package/dist/lib/lanes/reconcile-result.js +20 -2
  62. package/dist/lib/lanes/reconcile.js +12 -3
  63. package/dist/lib/mesh/live/emit.js +25 -6
  64. package/dist/lib/mesh/live/flush.js +119 -15
  65. package/dist/lib/mesh/live/reporting-privacy.d.ts +41 -0
  66. package/dist/lib/mesh/live/reporting-privacy.js +147 -1
  67. package/dist/lib/mesh/live/spool.d.ts +16 -0
  68. package/dist/lib/mesh/live/spool.js +45 -0
  69. package/dist/lib/signals/engine.d.ts +17 -3
  70. package/dist/lib/signals/engine.js +28 -9
  71. package/dist/lib/signals/failure-alert.d.ts +33 -1
  72. package/dist/lib/signals/failure-alert.js +72 -5
  73. package/dist/lib/signals/owner-notice.d.ts +94 -0
  74. package/dist/lib/signals/owner-notice.js +233 -0
  75. package/dist/lib/signals/reply.d.ts +7 -0
  76. package/dist/lib/signals/reply.js +23 -3
  77. package/dist/lib/signals/steps/adapters.d.ts +51 -2
  78. package/dist/lib/signals/steps/adapters.js +213 -7
  79. package/dist/lib/signals/steps/extract.js +18 -4
  80. package/dist/lib/signals/steps/types.d.ts +63 -1
  81. package/dist/lib/signals/steps/types.js +32 -0
  82. package/dist/lib/sync-core/engine-auth.d.ts +35 -0
  83. package/dist/lib/sync-core/engine-auth.js +96 -0
  84. package/dist/lib/sync-core/engine-home.d.ts +6 -0
  85. package/dist/lib/sync-core/engine-home.js +12 -0
  86. package/dist/lib/sync-core/rollout-state.d.ts +1 -0
  87. package/dist/lib/sync-core/rollout-state.js +3 -0
  88. package/dist/lib/vault-sync-switches.d.ts +7 -0
  89. package/dist/lib/vault-sync-switches.js +56 -0
  90. package/dist/lib/work-context/errors.d.ts +12 -0
  91. package/dist/lib/work-context/errors.js +15 -0
  92. package/dist/lib/work-context/organize.js +6 -1
  93. package/dist/lib/work-context/reconcile.js +20 -1
  94. package/dist/utils/resident-package-preload.js +34 -4
  95. package/docs/anywhere-runtime.md +6 -0
  96. package/package.json +7 -7
@@ -12,6 +12,14 @@
12
12
  * `src/lib/hot-channels/alert.ts`), so the alert text, the owner DM and the
13
13
  * hourly dedupe in `sources/_runs/@{personKey}/_alerts.json` are the same ones
14
14
  * the hot-channel sync uses. No new posting path is added here.
15
+ *
16
+ * The adapters step also runs the hot-channel signals pass over what it lands
17
+ * (steps/adapters.ts). A pass that did not finish is a failure by the ledger's
18
+ * own rule (`findSignalsFailures`): the adapter landed sources this run, or
19
+ * the pass found its tool signed out with documents waiting. So is a run whose
20
+ * document cap was spent before the pass read anything an adapter landed. A
21
+ * day with no new source and nothing waiting makes no pass call and no alert,
22
+ * and a pass that finished and found no signals is not a failure.
15
23
  */
16
24
  import { type RaiseSignalsFailureAlertsResult } from "../hot-channels/alert.js";
17
25
  import type { RunLedgerEntry } from "../hot-channels/ledger.js";
@@ -55,6 +63,21 @@ export interface SignalsRunAlertSenders {
55
63
  export declare function resolveSignedInAlertPerson(): SignalsAlertPerson | null;
56
64
  /** Source items the extract step read: its worklist items minus the ones the worklist skipped. */
57
65
  export declare function extractSourcesRead(extract: StepRecord): number;
66
+ /** The alert's `error` when the pass's document cap left everything an adapter landed unread. */
67
+ export declare const SIGNALS_PASS_DOCUMENT_CAP = "document-cap";
68
+ /**
69
+ * The hot-channel signals pass failure this run should alert on, or null:
70
+ * - the pass did not finish for an adapter that landed sources this run, or it
71
+ * found its tool signed out (it only checks the login when documents are
72
+ * waiting). A signed-out code is preferred, so the alert carries the sign-in
73
+ * steps.
74
+ * - else `document-cap`: the pass returned without failing, but the run's
75
+ * document cap was spent before it read anything an adapter landed this run.
76
+ * That adapter landed sources and got no signal, which is the ledger's rule
77
+ * for the plain sync too. A landing the cap only partly deferred makes the
78
+ * run `partial` and does not alert.
79
+ */
80
+ export declare function signalsPassRunFailure(record: RunRecord): string | null;
58
81
  /**
59
82
  * True when a run's sources produced no signals. The run must be real (not a
60
83
  * dry run, not a repeat of an earlier job run) and have both an adapters and an
@@ -66,13 +89,22 @@ export declare function extractSourcesRead(extract: StepRecord): number;
66
89
  * new sources.
67
90
  * Hot-channel landings extract never reads do not count on their own, so a
68
91
  * day with Slack activity and no declared-source items is not a stall.
92
+ *
93
+ * A real run is also a failure, with or without an extract step, when the
94
+ * adapters step's signals pass did not finish (`signalsPassRunFailure`).
69
95
  */
70
96
  export declare function isSignalsRunFailure(record: RunRecord): boolean;
71
97
  /**
72
98
  * The run record as one ledger line, so the existing alert path formats,
73
99
  * sends and dedupes it. `sourcesLanded` is the source items extract read (or,
74
100
  * when extract read none, what the adapters step landed) and
75
- * `signalsGenerated` is what extract produced.
101
+ * `signalsGenerated` is what extract produced plus what the adapters step's
102
+ * signals pass wrote.
103
+ *
104
+ * When the adapters step's signals pass did not finish, the line is that
105
+ * failure instead: what the adapters landed, what the pass wrote, status
106
+ * `failed`, and the pass's code as `error`, which is how the alert path
107
+ * recognises a signed-out tool and adds the sign-in steps.
76
108
  */
77
109
  export declare function signalsRunLedgerLine(record: RunRecord, person: SignalsAlertPerson): RunLedgerEntry;
78
110
  /**
@@ -12,12 +12,21 @@
12
12
  * `src/lib/hot-channels/alert.ts`), so the alert text, the owner DM and the
13
13
  * hourly dedupe in `sources/_runs/@{personKey}/_alerts.json` are the same ones
14
14
  * the hot-channel sync uses. No new posting path is added here.
15
+ *
16
+ * The adapters step also runs the hot-channel signals pass over what it lands
17
+ * (steps/adapters.ts). A pass that did not finish is a failure by the ledger's
18
+ * own rule (`findSignalsFailures`): the adapter landed sources this run, or
19
+ * the pass found its tool signed out with documents waiting. So is a run whose
20
+ * document cap was spent before the pass read anything an adapter landed. A
21
+ * day with no new source and nothing waiting makes no pass call and no alert,
22
+ * and a pass that finished and found no signals is not a failure.
15
23
  */
16
24
  import * as path from "node:path";
17
25
  import { audienceKey } from "../hot-channels/audience.js";
18
- import { findSignalsFailures, formatSignalsFailureAlert, raiseSignalsFailureAlerts, signalsAlertKey, signalsAlertStatePath, } from "../hot-channels/alert.js";
26
+ import { SIGNED_OUT_SIGNALS_CODES, findSignalsFailures, formatSignalsFailureAlert, raiseSignalsFailureAlerts, signalsAlertKey, signalsAlertStatePath, } from "../hot-channels/alert.js";
19
27
  import { assertAllowedPath } from "./write-guard.js";
20
28
  import { resolveUploadAuthor } from "../../utils/upload-author.js";
29
+ import { readSignalsPassDetail } from "./steps/types.js";
21
30
  /**
22
31
  * Extract skips that are not a stall: no source channel to read, or the
23
32
  * ontology worker is not installed. Both are reported in the run record
@@ -42,6 +51,32 @@ function firstStep(record, name) {
42
51
  export function extractSourcesRead(extract) {
43
52
  return Math.max(0, extract.itemsIn - (extract.skippedItems?.length ?? 0));
44
53
  }
54
+ /** The alert's `error` when the pass's document cap left everything an adapter landed unread. */
55
+ export const SIGNALS_PASS_DOCUMENT_CAP = "document-cap";
56
+ /**
57
+ * The hot-channel signals pass failure this run should alert on, or null:
58
+ * - the pass did not finish for an adapter that landed sources this run, or it
59
+ * found its tool signed out (it only checks the login when documents are
60
+ * waiting). A signed-out code is preferred, so the alert carries the sign-in
61
+ * steps.
62
+ * - else `document-cap`: the pass returned without failing, but the run's
63
+ * document cap was spent before it read anything an adapter landed this run.
64
+ * That adapter landed sources and got no signal, which is the ledger's rule
65
+ * for the plain sync too. A landing the cap only partly deferred makes the
66
+ * run `partial` and does not alert.
67
+ */
68
+ export function signalsPassRunFailure(record) {
69
+ const adapters = firstStep(record, "adapters");
70
+ const detail = readSignalsPassDetail(adapters);
71
+ if (!adapters || !detail)
72
+ return null;
73
+ const landed = (adapter) => adapters.byAdapter?.[adapter] ?? 0;
74
+ const counted = Object.entries(detail.failures ?? {}).filter(([adapter, code]) => landed(adapter) > 0 || SIGNED_OUT_SIGNALS_CODES.has(code));
75
+ if (counted.length > 0)
76
+ return (counted.find(([, code]) => SIGNED_OUT_SIGNALS_CODES.has(code)) ?? counted[0])[1];
77
+ const capped = Object.entries(detail.deferred ?? {}).some(([adapter, n]) => landed(adapter) > 0 && n >= landed(adapter));
78
+ return capped ? SIGNALS_PASS_DOCUMENT_CAP : null;
79
+ }
45
80
  /**
46
81
  * True when a run's sources produced no signals. The run must be real (not a
47
82
  * dry run, not a repeat of an earlier job run) and have both an adapters and an
@@ -53,10 +88,15 @@ export function extractSourcesRead(extract) {
53
88
  * new sources.
54
89
  * Hot-channel landings extract never reads do not count on their own, so a
55
90
  * day with Slack activity and no declared-source items is not a stall.
91
+ *
92
+ * A real run is also a failure, with or without an extract step, when the
93
+ * adapters step's signals pass did not finish (`signalsPassRunFailure`).
56
94
  */
57
95
  export function isSignalsRunFailure(record) {
58
96
  if (record.dryRun || record.alreadyRanToday)
59
97
  return false;
98
+ if (signalsPassRunFailure(record) !== null)
99
+ return true;
60
100
  const adapters = firstStep(record, "adapters");
61
101
  const extract = firstStep(record, "extract");
62
102
  if (!adapters || !extract)
@@ -76,23 +116,50 @@ export function isSignalsRunFailure(record) {
76
116
  * The run record as one ledger line, so the existing alert path formats,
77
117
  * sends and dedupes it. `sourcesLanded` is the source items extract read (or,
78
118
  * when extract read none, what the adapters step landed) and
79
- * `signalsGenerated` is what extract produced.
119
+ * `signalsGenerated` is what extract produced plus what the adapters step's
120
+ * signals pass wrote.
121
+ *
122
+ * When the adapters step's signals pass did not finish, the line is that
123
+ * failure instead: what the adapters landed, what the pass wrote, status
124
+ * `failed`, and the pass's code as `error`, which is how the alert path
125
+ * recognises a signed-out tool and adds the sign-in steps.
80
126
  */
81
127
  export function signalsRunLedgerLine(record, person) {
82
128
  const adapters = firstStep(record, "adapters");
83
129
  const extract = firstStep(record, "extract");
84
130
  const extractNote = extract?.error ?? (extract?.skippedReason ? `extract skipped: ${extract.skippedReason}` : null);
131
+ const passFailure = signalsPassRunFailure(record);
132
+ if (passFailure !== null) {
133
+ return {
134
+ runId: `signals-run ${record.company} ${record.startedAt}`,
135
+ trigger: record.trigger === "job" ? "scheduled" : "on-demand",
136
+ adapter: SIGNALS_RUN_ALERT_ADAPTER,
137
+ connectionId: null,
138
+ sourcesLanded: adapters?.itemsOut ?? 0,
139
+ signalsGenerated: adapters?.signalsOut ?? 0,
140
+ startedAt: record.startedAt,
141
+ finishedAt: record.finishedAt ?? record.startedAt,
142
+ status: "failed",
143
+ error: passFailure,
144
+ personUid: person.personUid ?? person.personKey,
145
+ ...(record.catchUp ? { catchUp: true } : {}),
146
+ };
147
+ }
148
+ // Signals the adapters step's pass wrote are part of what the run generated.
149
+ // With any, the line is `failed` so the alert path still selects it (its
150
+ // rule is no signals, or a failed line), and it says what extract did.
151
+ const passSignals = adapters?.signalsOut ?? 0;
85
152
  return {
86
153
  runId: `signals-run ${record.company} ${record.startedAt}`,
87
154
  trigger: record.trigger === "job" ? "scheduled" : "on-demand",
88
155
  adapter: SIGNALS_RUN_ALERT_ADAPTER,
89
156
  connectionId: null,
90
157
  sourcesLanded: extract && extractSourcesRead(extract) > 0 ? extractSourcesRead(extract) : (adapters?.itemsOut ?? 0),
91
- signalsGenerated: extract?.itemsOut ?? 0,
158
+ signalsGenerated: (extract?.itemsOut ?? 0) + passSignals,
92
159
  startedAt: record.startedAt,
93
160
  finishedAt: record.finishedAt ?? record.startedAt,
94
- status: record.status === "failed" || record.status === "partial" ? "failed" : "ok",
95
- error: extractNote,
161
+ status: record.status === "failed" || record.status === "partial" || passSignals > 0 ? "failed" : "ok",
162
+ error: extractNote ?? (passSignals > 0 ? "extract read sources and produced no signals" : null),
96
163
  personUid: person.personUid ?? person.personKey,
97
164
  ...(record.catchUp ? { catchUp: true } : {}),
98
165
  };
@@ -0,0 +1,94 @@
1
+ import type { RunRecord } from "./engine.js";
2
+ /** The Daily Brief page in HQ Desktop; its signals card carries the sign-in button and Try now. */
3
+ export declare const SIGNALS_NOTICE_LINK = "hq-desktop://brief";
4
+ export declare const SIGNALS_NOTICE_CAUSES: readonly ["signed-out-bot", "bot-api-key", "signed-out-claude", "signed-out-codex", "pass-failed", "documents-waiting", "run-failed"];
5
+ export type SignalsNoticeCause = (typeof SIGNALS_NOTICE_CAUSES)[number];
6
+ export interface SignalsNoticeProblem {
7
+ cause: SignalsNoticeCause;
8
+ /** Landed documents still waiting for signals after the run (0 when the record does not say). */
9
+ waiting: number;
10
+ }
11
+ /** Per company: what was told today, and the cause still open since the last clean run. */
12
+ export interface SignalsNoticeState {
13
+ v: 1;
14
+ company: string;
15
+ /** Local day of `sent`. A new day starts with nothing sent. */
16
+ day: string;
17
+ /** Cause -> ISO time its notice was handed to `send` on `day`. */
18
+ sent: Partial<Record<SignalsNoticeCause, string>>;
19
+ /** The last cause told and not yet followed by a clean run. */
20
+ open: {
21
+ cause: SignalsNoticeCause;
22
+ since: string;
23
+ } | null;
24
+ }
25
+ /** HQ-root relative path of a company's notice state. */
26
+ export declare function signalsNoticeStateRel(company: string): string;
27
+ /**
28
+ * What kept this run from doing its work, or null when nothing did. Not
29
+ * judged: dry runs, a second job fire on a day that already ran, skipped and
30
+ * still-running records.
31
+ */
32
+ export declare function signalsNoticeProblem(record: RunRecord): SignalsNoticeProblem | null;
33
+ /**
34
+ * The bot whose run the notice is about: an HQ Fleet or local Executive bot.
35
+ * Its signals pass runs on the bot's own login (owner rule
36
+ * hq-local-bots-bill-to-user-subscription-signals-use-bot-login), so a
37
+ * signed-out cause is fixed by signing the bot in again, never by a separate
38
+ * Claude Code sign-in. `name` and `runtime` are null when they could not be
39
+ * read; the notice then says "your bot".
40
+ */
41
+ export interface SignalsNoticeBot {
42
+ name: string | null;
43
+ runtime: string | null;
44
+ }
45
+ /** A bot whose name and runtime could not be read: the notice says "your bot". */
46
+ export declare const UNKNOWN_SIGNALS_NOTICE_BOT: SignalsNoticeBot;
47
+ /**
48
+ * The owner's notice for a problem: plain words, one fix, no command. Every
49
+ * reader is a bot's owner (the Fleet job's `--report-found` output and the
50
+ * bot's run reply), so a signed-out cause names the bot's own sign-in, never
51
+ * a Claude Code sign-in.
52
+ */
53
+ export declare function formatSignalsNotice(company: string, problem: SignalsNoticeProblem, bot?: SignalsNoticeBot): string;
54
+ /** The "running again" notice after a told problem. */
55
+ export declare function formatSignalsFixedNotice(company: string, record: RunRecord): string;
56
+ /** A company's notice state; an empty one when the file is missing, unreadable or another company's. */
57
+ export declare function readSignalsNoticeState(hqRoot: string, company: string, day: string): SignalsNoticeState;
58
+ export interface SignalsNoticePlan {
59
+ /** The text to hand to `send`, or null when nothing is due. */
60
+ text: string | null;
61
+ kind: "problem" | "fixed" | null;
62
+ /** The state to save once `send` returned (unchanged when nothing is due). */
63
+ next: SignalsNoticeState;
64
+ }
65
+ /**
66
+ * What to tell the owner about this run, from the run record and the
67
+ * company's notice state. Pure: reads and writes nothing.
68
+ * - A problem whose cause was not told today: tell it, mark it sent today
69
+ * and open.
70
+ * - A problem already told today: nothing.
71
+ * - A clean run with a cause still open: the "running again" notice, once.
72
+ * - Anything else: nothing.
73
+ */
74
+ export declare function planSignalsNotice(record: RunRecord, state: SignalsNoticeState, now: Date, bot?: SignalsNoticeBot): SignalsNoticePlan;
75
+ export interface DeliverSignalsNoticeResult {
76
+ kind: "problem" | "fixed" | null;
77
+ /** True when `send` returned and the state was saved. */
78
+ delivered: boolean;
79
+ }
80
+ /**
81
+ * Plan, send and record the notice for one company's run record. Never
82
+ * throws: a `send` that throws leaves the state unchanged so the next run
83
+ * tells it again; a state that cannot be saved is logged.
84
+ */
85
+ export declare function deliverSignalsNotice(input: {
86
+ hqRoot: string;
87
+ record: RunRecord;
88
+ now: Date;
89
+ send: (text: string) => void | Promise<void>;
90
+ log?: (message: string) => void;
91
+ /** The bot whose run this is; a signed-out notice then names the bot's own sign-in (formatSignalsNotice). */
92
+ bot?: SignalsNoticeBot;
93
+ }): Promise<DeliverSignalsNoticeResult>;
94
+ //# sourceMappingURL=owner-notice.d.ts.map
@@ -0,0 +1,233 @@
1
+ /**
2
+ * The owner's notice for a scheduled signals run that could not do its work.
3
+ *
4
+ * Owner, 2026-11-18: "Signals are a silent background job. If I didn't ask I
5
+ * would have no way of knowing they failed." A run whose hot-channel signals
6
+ * pass was blocked (the tool it runs on is signed out or missing), failed, or
7
+ * left landed documents unread because the run's document cap was spent, and a
8
+ * run that failed outright, tells the owner the same morning in plain words,
9
+ * with the action that fixes it. A sign-out names the bot's own sign-in (its
10
+ * profile's Brain tab in HQ), because the pass runs on the bot's own login,
11
+ * never a separate Claude Code sign-in; anything else links to the Daily
12
+ * Brief page, where Try now sits. No command to run.
13
+ *
14
+ * At most one notice per company per day per cause. When a cause was told and
15
+ * a later run finishes clean, one "running again" notice closes it. The state
16
+ * is `workspace/signals/notices/{company}.json`, one file per company, written
17
+ * through the engine's write guard. Nothing here sends anything: the caller
18
+ * gives `send` (the Fleet job's stdout, which HQ Fleet delivers as the owner's
19
+ * HQ DM) and the state is saved only after `send` returns.
20
+ */
21
+ import * as fs from "node:fs";
22
+ import * as path from "node:path";
23
+ import { CLAUDE_SIGNED_OUT_CODE, CODEX_BOT_NEEDS_CLAUDE_CODE, CODEX_SIGNED_OUT_CODE } from "../hot-channels/signals-pass-failure.js";
24
+ import { localDate } from "./local-date.js";
25
+ import { readSignalsPassDetail } from "./steps/types.js";
26
+ import { guardedWrite } from "./write-guard.js";
27
+ /** The Daily Brief page in HQ Desktop; its signals card carries the sign-in button and Try now. */
28
+ export const SIGNALS_NOTICE_LINK = "hq-desktop://brief";
29
+ export const SIGNALS_NOTICE_CAUSES = ["signed-out-bot", "bot-api-key", "signed-out-claude", "signed-out-codex", "pass-failed", "documents-waiting", "run-failed"];
30
+ const SLUG_RE = /^[a-z0-9][a-z0-9._-]*$/i;
31
+ /** HQ-root relative path of a company's notice state. */
32
+ export function signalsNoticeStateRel(company) {
33
+ return `workspace/signals/notices/${company}.json`;
34
+ }
35
+ const sumValues = (rec) => Object.values(rec ?? {}).reduce((a, n) => a + n, 0);
36
+ /**
37
+ * What kept this run from doing its work, or null when nothing did. Not
38
+ * judged: dry runs, a second job fire on a day that already ran, skipped and
39
+ * still-running records.
40
+ */
41
+ export function signalsNoticeProblem(record) {
42
+ if (record.dryRun || record.alreadyRanToday)
43
+ return null;
44
+ if (record.status !== "complete" && record.status !== "partial" && record.status !== "failed")
45
+ return null;
46
+ const adapters = record.steps.find((s) => s.name === "adapters");
47
+ const detail = readSignalsPassDetail(adapters);
48
+ const waiting = detail ? sumValues(detail.pending) || sumValues(detail.deferred) : 0;
49
+ const codes = Object.values(detail?.failures ?? {});
50
+ if (codes.includes("bot-logged-out"))
51
+ return { cause: "signed-out-bot", waiting };
52
+ if (codes.includes("bot-api-key-login"))
53
+ return { cause: "bot-api-key", waiting };
54
+ if (codes.some((c) => c === CLAUDE_SIGNED_OUT_CODE || c === CODEX_BOT_NEEDS_CLAUDE_CODE))
55
+ return { cause: "signed-out-claude", waiting };
56
+ if (codes.some((c) => c === CODEX_SIGNED_OUT_CODE))
57
+ return { cause: "signed-out-codex", waiting };
58
+ if (codes.length > 0)
59
+ return { cause: "pass-failed", waiting };
60
+ if (record.status === "failed")
61
+ return { cause: "run-failed", waiting };
62
+ if (sumValues(detail?.deferred) > 0)
63
+ return { cause: "documents-waiting", waiting };
64
+ return null;
65
+ }
66
+ /** A clean run closes an open cause: it finished complete with nothing the notice counts. */
67
+ function isCleanRun(record) {
68
+ return !record.dryRun && !record.alreadyRanToday && record.status === "complete" && signalsNoticeProblem(record) === null;
69
+ }
70
+ const items = (n) => `${n} ${n === 1 ? "item is" : "items are"}`;
71
+ /**
72
+ * The subscription a Claude or Codex bot's brain signs in to, in the words
73
+ * the HQ app's Brain tab uses. Null for any other runtime: the notice then
74
+ * names no provider.
75
+ */
76
+ function botProvider(runtime) {
77
+ if (runtime === "claude")
78
+ return "Claude";
79
+ if (runtime === "codex")
80
+ return "ChatGPT";
81
+ return null;
82
+ }
83
+ /** A bot whose name and runtime could not be read: the notice says "your bot". */
84
+ export const UNKNOWN_SIGNALS_NOTICE_BOT = { name: null, runtime: null };
85
+ /**
86
+ * The signed-out notice for a bot: the bot's own sign-in, in the HQ app on the
87
+ * bot's profile (Brain tab), where its login is connected. No Claude Code
88
+ * sign-in, no Daily Brief link (that page's button signs Claude Code in).
89
+ */
90
+ function botSignedOutNotice(company, bot, waitingLine) {
91
+ const who = bot.name ?? "your bot";
92
+ const whose = bot.name ? `${bot.name}'s` : "your bot's";
93
+ const provider = botProvider(bot.runtime);
94
+ const connect = provider ? `connect ${provider} again` : "connect its sign-in again";
95
+ return [
96
+ `Signals for ${company} didn't run this morning: ${whose} own sign-in needs renewing.${waitingLine ? ` ${waitingLine}` : ""}`,
97
+ `Sign ${who} in again in HQ: open ${whose} profile, go to Brain, and ${connect}. Signals use the same login ${who} answers chat with, and the waiting items are read on the next run.`,
98
+ ].join("\n\n");
99
+ }
100
+ /**
101
+ * The owner's notice for a problem: plain words, one fix, no command. Every
102
+ * reader is a bot's owner (the Fleet job's `--report-found` output and the
103
+ * bot's run reply), so a signed-out cause names the bot's own sign-in, never
104
+ * a Claude Code sign-in.
105
+ */
106
+ export function formatSignalsNotice(company, problem, bot = UNKNOWN_SIGNALS_NOTICE_BOT) {
107
+ const waitingLine = problem.waiting > 0 ? `${items(problem.waiting)} waiting to be read for signals.` : null;
108
+ switch (problem.cause) {
109
+ case "signed-out-bot":
110
+ return botSignedOutNotice(company, bot, waitingLine);
111
+ case "bot-api-key":
112
+ return `Signals for ${company} could not run: ${bot.name ?? "your bot"} is using an API key. Open its profile in HQ, go to Brain, and connect a Claude or ChatGPT subscription instead. ${waitingLine ?? "Waiting documents stay queued."}`;
113
+ case "signed-out-claude":
114
+ return `Signals for ${company} could not run: the Claude Code login used by this run is unavailable. ${bot.name ?? "This bot"}'s signals cannot use its own login on this installed setup yet. The owner needs to decide whether to update the bot runtime or use a separate Claude Code subscription login. Reconnecting the bot will not fix this run. ${waitingLine ?? "Waiting documents stay queued."}`;
115
+ case "signed-out-codex":
116
+ return `Signals for ${company} could not run: the bot's Codex CLI login used by this run is unavailable. Open ${bot.name ?? "your bot"}'s profile in HQ and reconnect its Codex subscription login. ${waitingLine ?? "Waiting documents stay queued."}`;
117
+ case "pass-failed":
118
+ return [
119
+ `Signals for ${company} finished with problems this morning: some items could not be read for signals.${waitingLine ? ` ${waitingLine}` : ""} They stay queued.`,
120
+ `[Open the Daily Brief](${SIGNALS_NOTICE_LINK}) and press Try now to read them again.`,
121
+ ].join("\n\n");
122
+ case "documents-waiting":
123
+ return [
124
+ `Signals for ${company} read what it could this morning, but ${waitingLine ? items(problem.waiting) : "some items are"} still waiting for the next run.`,
125
+ `[Open the Daily Brief](${SIGNALS_NOTICE_LINK}) and press Try now to read them now.`,
126
+ ].join("\n\n");
127
+ case "run-failed":
128
+ return [
129
+ `Signals for ${company} didn't run this morning.${waitingLine ? ` ${waitingLine}` : ""}`,
130
+ `[Open the Daily Brief](${SIGNALS_NOTICE_LINK}) and press Try now to run them again.`,
131
+ ].join("\n\n");
132
+ }
133
+ }
134
+ /** The "running again" notice after a told problem. */
135
+ export function formatSignalsFixedNotice(company, record) {
136
+ const n = record.counts?.signalsOut ?? 0;
137
+ const found = n > 0 ? ` and found ${n} new signal${n === 1 ? "" : "s"}` : "";
138
+ return `Signals for ${company} are running again: this morning's run finished${found}.`;
139
+ }
140
+ function emptyState(company, day) {
141
+ return { v: 1, company, day, sent: {}, open: null };
142
+ }
143
+ function parseState(text, company) {
144
+ try {
145
+ const raw = JSON.parse(text);
146
+ if (!raw || raw.v !== 1 || raw.company !== company || typeof raw.day !== "string")
147
+ return null;
148
+ const sent = {};
149
+ for (const cause of SIGNALS_NOTICE_CAUSES) {
150
+ const at = raw.sent?.[cause];
151
+ if (typeof at === "string")
152
+ sent[cause] = at;
153
+ }
154
+ const open = raw.open && SIGNALS_NOTICE_CAUSES.includes(raw.open.cause) && typeof raw.open.since === "string"
155
+ ? { cause: raw.open.cause, since: raw.open.since }
156
+ : null;
157
+ return { v: 1, company, day: raw.day, sent, open };
158
+ }
159
+ catch {
160
+ return null;
161
+ }
162
+ }
163
+ /** A company's notice state; an empty one when the file is missing, unreadable or another company's. */
164
+ export function readSignalsNoticeState(hqRoot, company, day) {
165
+ let text;
166
+ try {
167
+ text = fs.readFileSync(path.join(hqRoot, signalsNoticeStateRel(company)), "utf8");
168
+ }
169
+ catch {
170
+ return emptyState(company, day);
171
+ }
172
+ return parseState(text, company) ?? emptyState(company, day);
173
+ }
174
+ /**
175
+ * What to tell the owner about this run, from the run record and the
176
+ * company's notice state. Pure: reads and writes nothing.
177
+ * - A problem whose cause was not told today: tell it, mark it sent today
178
+ * and open.
179
+ * - A problem already told today: nothing.
180
+ * - A clean run with a cause still open: the "running again" notice, once.
181
+ * - Anything else: nothing.
182
+ */
183
+ export function planSignalsNotice(record, state, now, bot) {
184
+ const day = localDate(now);
185
+ const today = state.day === day ? state : { ...state, day, sent: {} };
186
+ const problem = signalsNoticeProblem(record);
187
+ if (problem) {
188
+ if (today.sent[problem.cause])
189
+ return { text: null, kind: null, next: state };
190
+ const at = now.toISOString();
191
+ return {
192
+ text: formatSignalsNotice(record.company, problem, bot),
193
+ kind: "problem",
194
+ next: { ...today, sent: { ...today.sent, [problem.cause]: at }, open: { cause: problem.cause, since: at } },
195
+ };
196
+ }
197
+ if (state.open && isCleanRun(record)) {
198
+ return { text: formatSignalsFixedNotice(record.company, record), kind: "fixed", next: { ...today, open: null } };
199
+ }
200
+ return { text: null, kind: null, next: state };
201
+ }
202
+ /**
203
+ * Plan, send and record the notice for one company's run record. Never
204
+ * throws: a `send` that throws leaves the state unchanged so the next run
205
+ * tells it again; a state that cannot be saved is logged.
206
+ */
207
+ export async function deliverSignalsNotice(input) {
208
+ const log = input.log ?? (() => { });
209
+ const company = input.record.company;
210
+ if (!SLUG_RE.test(company)) {
211
+ log(`signals notice skipped: ${JSON.stringify(company)} is not a company slug`);
212
+ return { kind: null, delivered: false };
213
+ }
214
+ const state = readSignalsNoticeState(input.hqRoot, company, localDate(input.now));
215
+ const plan = planSignalsNotice(input.record, state, input.now, input.bot);
216
+ if (!plan.text)
217
+ return { kind: null, delivered: false };
218
+ try {
219
+ await input.send(plan.text);
220
+ }
221
+ catch (err) {
222
+ log(`signals notice for ${company} was not delivered: ${err instanceof Error ? err.message : String(err)}`);
223
+ return { kind: plan.kind, delivered: false };
224
+ }
225
+ try {
226
+ guardedWrite(input.hqRoot, signalsNoticeStateRel(company), `${JSON.stringify(plan.next, null, 2)}\n`);
227
+ }
228
+ catch (err) {
229
+ log(`signals notice state for ${company} was not saved: ${err instanceof Error ? err.message : String(err)}`);
230
+ }
231
+ return { kind: plan.kind, delivered: true };
232
+ }
233
+ //# sourceMappingURL=owner-notice.js.map
@@ -8,6 +8,7 @@
8
8
  * not carry drops its row. Pure functions: no clock, no I/O.
9
9
  */
10
10
  import type { LockedCompany, RunRecord, RunSummary } from "./engine.js";
11
+ import { type SignalsNoticeBot } from "./owner-notice.js";
11
12
  export declare const REPLY_BLOCK_KINDS: readonly ["keyValue", "callout", "badge", "progress", "decision"];
12
13
  export declare const REPLY_TONES: readonly ["neutral", "info", "success", "warning", "danger"];
13
14
  export declare const REPLY_ICONS: readonly ["check", "clock", "folder", "calendar"];
@@ -84,6 +85,12 @@ export interface RunReplyOptions {
84
85
  * open the page to create it.
85
86
  */
86
87
  briefJobScheduled?: boolean;
88
+ /**
89
+ * The bot this reply is from. Its signals pass runs on the bot's own login,
90
+ * so a signed-out pass names the bot's own sign-in (formatSignalsNotice),
91
+ * never a Claude Code sign-in. Unset: "your bot".
92
+ */
93
+ bot?: SignalsNoticeBot;
87
94
  }
88
95
  /** The in-app deep link the desktop app opens as the Daily Brief page (US-023). */
89
96
  export declare const BRIEF_DEEP_LINK = "hq-desktop://brief";
@@ -7,6 +7,7 @@
7
7
  * closed enums. Values come only from the run record; a value the record does
8
8
  * not carry drops its row. Pure functions: no clock, no I/O.
9
9
  */
10
+ import { formatSignalsNotice, signalsNoticeProblem } from "./owner-notice.js";
10
11
  export const REPLY_BLOCK_KINDS = ["keyValue", "callout", "badge", "progress", "decision"];
11
12
  export const REPLY_TONES = ["neutral", "info", "success", "warning", "danger"];
12
13
  export const REPLY_ICONS = ["check", "clock", "folder", "calendar"];
@@ -146,8 +147,12 @@ export function runCountItems(record, summary, opts) {
146
147
  const breakdown = [...parts].map(([k, v]) => `${k} ${v}`).join(", ");
147
148
  items.push({ key: "Sources read", value: `${plural(read, "item")}${breakdown ? ` (${breakdown})` : ""}` });
148
149
  }
150
+ // Signals from the hot-channel signals pass the adapters step ran count too.
151
+ const passSignals = adapters?.signalsOut ?? 0;
152
+ if (extract || passSignals > 0) {
153
+ items.push({ key: "Signals found", value: String((extract?.itemsOut ?? 0) + passSignals) });
154
+ }
149
155
  if (extract) {
150
- items.push({ key: "Signals found", value: String(extract.itemsOut) });
151
156
  const counts = extract.detail;
152
157
  if (counts && ["new", "updated", "skipped"].every((k) => typeof counts[k] === "number")) {
153
158
  items.push({ key: "Signal changes", value: `new: ${counts.new}, updated: ${counts.updated}, skipped: ${counts.skipped}` });
@@ -437,12 +442,27 @@ export function formatRunReply(record, summary, opts) {
437
442
  ? partialReasonInWords(partialReason)
438
443
  : null;
439
444
  const guidance = failureGuidance(record, failedStep, company);
440
- const body = [guidance.main, ...(guidance.note ? [guidance.note] : []), `${PARTIAL_RUN_BRIEF_LINE} ${SAY_TRY_NOW_LINE}`].join(" ");
445
+ // A signals pass that was blocked or failed: the owner's plain notice and
446
+ // its one fix lead, never the pass's error code. The run's own guidance
447
+ // (a reconnect step, the spend cap) stays after it. A run reply is always
448
+ // a bot's, so a signed-out pass names the bot's own sign-in, never a
449
+ // Claude Code sign-in.
450
+ const notice = signalsNoticeProblem(record);
451
+ const [noticeLead, noticeAction] = notice
452
+ ? formatSignalsNotice(company, notice, opts.bot).split("\n\n")
453
+ : [];
454
+ const callTitle = noticeLead ?? title;
455
+ const body = [
456
+ ...(noticeAction ? [noticeAction] : []),
457
+ guidance.main,
458
+ ...(guidance.note ? [guidance.note] : []),
459
+ `${PARTIAL_RUN_BRIEF_LINE} ${SAY_TRY_NOW_LINE}`,
460
+ ].join(" ");
441
461
  const brief = briefPointer(`${job} finished with problems at ${finished}.`, summary.date, opts, false);
442
462
  return build(brief.prose, [
443
463
  { kind: "badge", label: "Finished with problems", tone: "warning" },
444
464
  ...(record.catchUp ? [catchUpBadge] : []),
445
- title ? { kind: "callout", tone: "warning", title, body } : { kind: "callout", tone: "warning", body },
465
+ callTitle ? { kind: "callout", tone: "warning", title: callTitle, body } : { kind: "callout", tone: "warning", body },
446
466
  ...tail,
447
467
  ...brief.blocks,
448
468
  ], "partial");
@@ -1,7 +1,56 @@
1
+ import type { SignalsGeneratedFn } from "../../hot-channels/ledger.js";
1
2
  import type { OnDemandSyncReport } from "../../hot-channels/run.js";
2
- import type { HotChannelSyncFn, SignalsStep, StepContext, StepResult } from "./types.js";
3
+ import type { HotChannelSyncFn, SignalsPassFactory, SignalsStep, StepContext, StepResult } from "./types.js";
3
4
  export declare const defaultHotChannelSync: HotChannelSyncFn;
4
- export declare function mapSyncReport(report: OnDemandSyncReport): StepResult;
5
+ /**
6
+ * The pass `hq sources sync` (commands/sources.ts `runSync`) and the bot's
7
+ * plain hot-signal-sync job (commands/bot.ts) build: the local signals pass on
8
+ * the Executive bot's runtime choice, recording what it saw of the Claude
9
+ * login for `hq bot status`. Only `onDocumentSent` is added here.
10
+ */
11
+ export declare const defaultSignalsPass: SignalsPassFactory;
12
+ /** What the step saw of the pass beyond the sync report: documents sent and what still waits. */
13
+ export interface SignalsPassUsage {
14
+ route?: "fleet" | "claude-cli" | "codex-bot";
15
+ documents: number;
16
+ runtime: string | null;
17
+ /** Channel -> documents in `sources/_signals-pending/{channel}.json` after the sync. */
18
+ pending?: Record<string, number>;
19
+ /**
20
+ * Adapter id -> documents it landed this run that were still queued when its
21
+ * pass returned without failing: the run's document cap was spent first.
22
+ */
23
+ deferred?: Record<string, number>;
24
+ /** Channels with a `source.yaml` the pass left to the extract step. */
25
+ leftToExtract?: string[];
26
+ }
27
+ /**
28
+ * The pass as the engine's adapters step runs it. It is the pass it wraps
29
+ * (`inner`), with three rules that keep the run record true and the extract
30
+ * step unchanged:
31
+ *
32
+ * - A channel folder with a `source.yaml` is the extract step's: that step
33
+ * reads it through the same ontology worklist later in the run. The pass is
34
+ * not called for it, so it neither takes those items nor marks them done.
35
+ * - Every other landed document is written to `sources/_signals-pending/`
36
+ * before the pass starts. The sync has already moved the cursor past it, so
37
+ * a pass that throws before its own queueing would otherwise lose it.
38
+ * - After a pass that returned without failing, landed documents still queued
39
+ * are counted as deferred: the run's document cap was spent before them.
40
+ */
41
+ export declare function trackSignalsPass(hqRoot: string, company: string, inner: SignalsGeneratedFn, usage: SignalsPassUsage): Promise<SignalsGeneratedFn>;
42
+ /** Channel -> landed documents waiting in `companies/{co}/sources/_signals-pending/`. Unreadable files count as none. */
43
+ export declare function pendingSignalsCounts(hqRoot: string, company: string): Record<string, number>;
44
+ /**
45
+ * The sync report as the step's result. `pass` is what the step itself saw of
46
+ * the signals pass; with it the result also carries `signalsOut`, `modelTurns`
47
+ * and `detail.signalsPass`. An outcome that failed only because the pass
48
+ * failed (its sources landed) is not an adapter failure: it makes the step
49
+ * `partial` with the pass's reason, and is listed under
50
+ * `detail.signalsPass.failures`. Documents landed this run that the pass's
51
+ * document cap left queued (`pass.deferred`) make the step `partial` too.
52
+ */
53
+ export declare function mapSyncReport(report: OnDemandSyncReport, pass?: SignalsPassUsage): StepResult;
5
54
  /**
6
55
  * Mirror the signed-in person's vault cursors
7
56
  * (`companies/{co}/sources/_cursors/@{personKey}/{key}.json`, written by the