@indigoai-us/hq-cli 5.345.251 → 5.345.253

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 (188) hide show
  1. package/CHANGELOG.md +153 -0
  2. package/assets/scaffold/core/scripts/hq-session.sh +9 -0
  3. package/contracts/host-canary-release.json +9 -3
  4. package/dist/command-catalog.generated.d.ts +269 -1
  5. package/dist/command-catalog.generated.js +330 -1
  6. package/dist/command-registration-plan.d.ts +6 -0
  7. package/dist/command-registration-plan.js +1 -0
  8. package/dist/commands/bot.js +7 -2
  9. package/dist/commands/ci-intake.d.ts +15 -0
  10. package/dist/commands/ci-intake.js +252 -0
  11. package/dist/commands/ci-metrics.d.ts +8 -0
  12. package/dist/commands/ci-metrics.js +55 -0
  13. package/dist/commands/ci.d.ts +13 -0
  14. package/dist/commands/ci.js +10 -0
  15. package/dist/commands/core-bucket-c-work-mesh-offer-native.js +1 -1
  16. package/dist/commands/core-hq-session-binding.d.ts +140 -0
  17. package/dist/commands/core-hq-session-binding.js +363 -0
  18. package/dist/commands/core-hq-session-native.d.ts +23 -0
  19. package/dist/commands/core-hq-session-native.js +59 -9
  20. package/dist/commands/core-stop-autosave.js +1 -1
  21. package/dist/commands/core.js +10 -0
  22. package/dist/commands/doctor.d.ts +5 -1
  23. package/dist/commands/doctor.js +42 -5
  24. package/dist/commands/files.d.ts +62 -0
  25. package/dist/commands/files.js +250 -9
  26. package/dist/commands/install-global.js +4 -2
  27. package/dist/commands/logout.js +4 -0
  28. package/dist/commands/ontology-graph.d.ts +2 -0
  29. package/dist/commands/ontology-graph.js +33 -0
  30. package/dist/commands/report.js +35 -2
  31. package/dist/commands/storage-gate.js +1 -1
  32. package/dist/commands/vault-retention-flag.js +2 -1
  33. package/dist/commands/whoami.js +1 -1
  34. package/dist/hq-cloud-sync-runner/bin/sync-runner.js +238 -221
  35. package/dist/hq-cloud-sync-runner/package.json +1 -1
  36. package/dist/index.js +3 -1
  37. package/dist/lib/agent-kit/inbox-poll-backoff-flag.js +1 -1
  38. package/dist/lib/agent-kit/mcp/tools.js +48 -0
  39. package/dist/lib/bot/fleet-bots-update-pass.js +1 -1
  40. package/dist/lib/bot/fleet-cron.d.ts +50 -0
  41. package/dist/lib/bot/fleet-cron.js +173 -32
  42. package/dist/lib/bot/fleet-local.d.ts +18 -0
  43. package/dist/lib/bot/fleet-local.js +51 -5
  44. package/dist/lib/bot/inbox-poll-backoff-flag.js +1 -1
  45. package/dist/lib/bot/signals-engine-flag.d.ts +1 -1
  46. package/dist/lib/bot/signals-engine-flag.js +1 -1
  47. package/dist/lib/cli-invite-nudge.js +1 -1
  48. package/dist/lib/client-version.d.ts +2 -0
  49. package/dist/lib/client-version.js +24 -0
  50. package/dist/lib/company-flag-gate.d.ts +30 -0
  51. package/dist/lib/company-flag-gate.js +104 -0
  52. package/dist/lib/core-utils/hook-timeout-debug-context-flag.js +1 -1
  53. package/dist/lib/daemon/flag.js +2 -1
  54. package/dist/lib/daemon/legacy-journal-gate.js +3 -1
  55. package/dist/lib/daemon/run.js +4 -3
  56. package/dist/lib/daemon/shared-flag-reads.js +1 -1
  57. package/dist/lib/delivery/migrations.d.ts +32 -1
  58. package/dist/lib/delivery/migrations.js +69 -8
  59. package/dist/lib/doctor/checks/host-core.js +22 -4
  60. package/dist/lib/doctor/checks/jq.d.ts +27 -6
  61. package/dist/lib/doctor/checks/jq.js +46 -8
  62. package/dist/lib/doctor/client-health-reason-codes-flag.js +1 -1
  63. package/dist/lib/doctor/fix/refresh-sync-handoff.d.ts +1 -1
  64. package/dist/lib/doctor/fix/refresh-sync-handoff.js +1 -1
  65. package/dist/lib/flag-client-gate-headers.d.ts +38 -0
  66. package/dist/lib/flag-client-gate-headers.js +62 -0
  67. package/dist/lib/flag-client-headers.d.ts +15 -0
  68. package/dist/lib/flag-client-headers.js +25 -0
  69. package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
  70. package/dist/lib/flag-registry-worker-source.generated.js +1 -1
  71. package/dist/lib/flag-registry-worker.js +35 -0
  72. package/dist/lib/flag-registry.d.ts +1 -20
  73. package/dist/lib/flag-registry.js +5 -81
  74. package/dist/lib/hook-engine/adapter-core-pin.d.ts +30 -0
  75. package/dist/lib/hook-engine/adapter-core-pin.js +30 -0
  76. package/dist/lib/hook-engine/coverage.d.ts +65 -1
  77. package/dist/lib/hook-engine/coverage.js +173 -8
  78. package/dist/lib/hook-engine/reconcile.js +3 -2
  79. package/dist/lib/hot-channels/prompts/signals-pass.md +20 -0
  80. package/dist/lib/hot-channels/signal-changes.d.ts +228 -0
  81. package/dist/lib/hot-channels/signal-changes.js +683 -0
  82. package/dist/lib/hot-channels/signals-pass.d.ts +24 -0
  83. package/dist/lib/hot-channels/signals-pass.js +232 -12
  84. package/dist/lib/lanes/outpost-worktree-pruner-flag.d.ts +1 -1
  85. package/dist/lib/lanes/outpost-worktree-pruner-flag.js +1 -1
  86. package/dist/lib/lanes/registry-flag.js +2 -1
  87. package/dist/lib/lanes/spawn.js +11 -1
  88. package/dist/lib/mesh/live/binding-intent.d.ts +61 -0
  89. package/dist/lib/mesh/live/binding-intent.js +201 -0
  90. package/dist/lib/mesh/live/binding-receipt.d.ts +157 -0
  91. package/dist/lib/mesh/live/binding-receipt.js +365 -0
  92. package/dist/lib/mesh/live/company-flag-refresh.js +1 -1
  93. package/dist/lib/mesh/live/daemon/doctor-telemetry.d.ts +39 -0
  94. package/dist/lib/mesh/live/daemon/doctor-telemetry.js +58 -0
  95. package/dist/lib/mesh/live/daemon/install.js +2 -1
  96. package/dist/lib/mesh/live/daemon/presence.js +9 -0
  97. package/dist/lib/mesh/live/daemon/run.d.ts +3 -0
  98. package/dist/lib/mesh/live/daemon/run.js +33 -1
  99. package/dist/lib/ontology-graph/lineage/index.d.ts +401 -0
  100. package/dist/lib/ontology-graph/lineage/index.js +1027 -0
  101. package/dist/lib/ontology-graph/model/index.d.ts +54 -0
  102. package/dist/lib/ontology-graph/model/index.js +112 -0
  103. package/dist/lib/ontology-graph/model/pass-tasks.d.ts +75 -0
  104. package/dist/lib/ontology-graph/model/pass-tasks.js +166 -0
  105. package/dist/lib/ontology-graph/model/pass.d.ts +6 -0
  106. package/dist/lib/ontology-graph/model/pass.js +9 -2
  107. package/dist/lib/ontology-graph/model/pending-items.d.ts +8 -0
  108. package/dist/lib/ontology-graph/model/pending-items.js +24 -1
  109. package/dist/lib/ontology-graph/model/step.d.ts +1 -1
  110. package/dist/lib/ontology-graph/model/tasks.d.ts +11 -3
  111. package/dist/lib/ontology-graph/model/tasks.js +20 -7
  112. package/dist/lib/ontology-graph/read/brief.js +41 -6
  113. package/dist/lib/ontology-graph/read/index.d.ts +4 -0
  114. package/dist/lib/ontology-graph/read/index.js +173 -29
  115. package/dist/lib/ontology-graph/read/lineage.d.ts +101 -0
  116. package/dist/lib/ontology-graph/read/lineage.js +262 -0
  117. package/dist/lib/ontology-graph/replay/buffered-store.js +17 -0
  118. package/dist/lib/ontology-graph/replay/engine.d.ts +32 -1
  119. package/dist/lib/ontology-graph/replay/engine.js +213 -8
  120. package/dist/lib/ontology-graph/replay/extractors.d.ts +26 -0
  121. package/dist/lib/ontology-graph/replay/extractors.js +25 -1
  122. package/dist/lib/ontology-graph/replay/index.d.ts +2 -0
  123. package/dist/lib/ontology-graph/replay/index.js +9 -3
  124. package/dist/lib/ontology-graph/replay/signal-changes.d.ts +118 -0
  125. package/dist/lib/ontology-graph/replay/signal-changes.js +687 -0
  126. package/dist/lib/ontology-graph/schema/decision-status.d.ts +18 -0
  127. package/dist/lib/ontology-graph/schema/decision-status.js +20 -0
  128. package/dist/lib/ontology-graph/schema/index.d.ts +1 -0
  129. package/dist/lib/ontology-graph/schema/index.js +1 -0
  130. package/dist/lib/ontology-graph/setup/index.js +13 -3
  131. package/dist/lib/search-index/index.d.ts +33 -1
  132. package/dist/lib/search-index/index.js +180 -25
  133. package/dist/lib/search-index/qmd-exit-diagnostics.d.ts +7 -0
  134. package/dist/lib/search-index/qmd-exit-diagnostics.js +25 -1
  135. package/dist/lib/signals/adapters-catalog.js +1 -1
  136. package/dist/lib/smart-ci/cost.d.ts +72 -0
  137. package/dist/lib/smart-ci/cost.js +120 -0
  138. package/dist/lib/smart-ci/github.d.ts +112 -0
  139. package/dist/lib/smart-ci/github.js +267 -0
  140. package/dist/lib/smart-ci/intake.d.ts +288 -0
  141. package/dist/lib/smart-ci/intake.js +1078 -0
  142. package/dist/lib/smart-ci/ledger.d.ts +218 -0
  143. package/dist/lib/smart-ci/ledger.js +527 -0
  144. package/dist/lib/smart-ci/metrics.d.ts +137 -0
  145. package/dist/lib/smart-ci/metrics.js +249 -0
  146. package/dist/lib/smart-ci/records.d.ts +265 -0
  147. package/dist/lib/smart-ci/records.js +281 -0
  148. package/dist/lib/smart-ci/reducer.d.ts +67 -0
  149. package/dist/lib/smart-ci/reducer.js +261 -0
  150. package/dist/lib/sync-core/engine-holds.d.ts +15 -0
  151. package/dist/lib/sync-core/engine-holds.js +104 -11
  152. package/dist/lib/sync-core/engine-home.d.ts +3 -0
  153. package/dist/lib/sync-core/engine-home.js +41 -1
  154. package/dist/lib/sync-core/flag.js +2 -1
  155. package/dist/lib/sync-core/hand-back.d.ts +1 -0
  156. package/dist/lib/sync-core/hand-back.js +7 -2
  157. package/dist/lib/sync-core/legacy-journal-export-child.js +5 -3
  158. package/dist/lib/sync-core/legacy-journal-export.d.ts +23 -4
  159. package/dist/lib/sync-core/legacy-journal-export.js +120 -55
  160. package/dist/lib/sync-core/reconcile.d.ts +2 -1
  161. package/dist/lib/sync-core/reconcile.js +40 -7
  162. package/dist/lib/sync-invalid-entity-warning.js +2 -1
  163. package/dist/lib/windows/install-followup.d.ts +41 -0
  164. package/dist/lib/windows/install-followup.js +87 -0
  165. package/dist/lib/windows/jq.d.ts +59 -0
  166. package/dist/lib/windows/jq.js +154 -3
  167. package/dist/lib/windows/user-path.d.ts +5 -0
  168. package/dist/lib/windows/user-path.js +1 -1
  169. package/dist/lib/work-context/auto-bind.d.ts +12 -0
  170. package/dist/lib/work-context/auto-bind.js +49 -3
  171. package/dist/lib/work-context/organize.d.ts +4 -2
  172. package/dist/lib/work-context/organize.js +18 -8
  173. package/dist/lib/work-context/reconcile.js +16 -1
  174. package/dist/main.js +12 -1
  175. package/dist/utils/client-health-contract.d.ts +30 -0
  176. package/dist/utils/client-health-contract.js +111 -0
  177. package/dist/utils/client-health.d.ts +5 -2
  178. package/dist/utils/client-health.js +74 -5
  179. package/dist/utils/exclusive-lock.d.ts +5 -1
  180. package/dist/utils/exclusive-lock.js +9 -2
  181. package/dist/utils/host-registration.d.ts +7 -0
  182. package/dist/utils/host-registration.js +10 -1
  183. package/dist/utils/pid.d.ts +31 -0
  184. package/dist/utils/pid.js +65 -0
  185. package/dist/utils/resident-package-preload.js +12 -4
  186. package/dist/utils/sentry-fingerprint.js +3 -0
  187. package/package.json +10 -8
  188. package/scripts/install-hook-engine.mjs +5 -3
@@ -0,0 +1,401 @@
1
+ import { type BatchModelStep, type LineageKind } from "../model/index.js";
2
+ import { compilePages as defaultCompilePages } from "../pages/index.js";
3
+ import type { AudienceKey, CommandOutput, EntityRef, GraphContext, GraphStore, IsoDate, ModelRunner, Origin, RowId, SourceRef } from "../types.js";
4
+ /** Where the walk stopped, relative to the graph folder. */
5
+ export declare const LINEAGE_CURSOR_RELATIVE = ".state/lineage-backfill-cursor.json";
6
+ /** One line per link this command wrote, with the ids of its rows. `hq ontology lineage undo` removes exactly those rows. */
7
+ export declare const LINEAGE_APPLIED_RELATIVE = ".state/lineage-backfill.jsonl";
8
+ /** The confidence of a model's reading of two decisions, as the supersession task writes it. */
9
+ export declare const LINEAGE_CONFIDENCE = 0.6;
10
+ /** How candidates are picked. Part of the state's key: a change here makes the next run walk again. */
11
+ export declare const LINEAGE_RETRIEVAL_VERSION = "rarity.v1";
12
+ /** The numbers of the retrieval rule. `DEFAULT_LINEAGE_RETRIEVAL` is what the command uses; a measurement can pass others. */
13
+ export interface LineageRetrievalRule {
14
+ /** A word in more than this share of the audience's decision statements, and in more than `commonMinDocs` of them, counts for nothing. */
15
+ commonShare: number;
16
+ commonMinDocs: number;
17
+ /** A topic on more than this share of the audience's decisions, and on more than `hubMinDocs` of them, gives no bonus. */
18
+ hubShare: number;
19
+ hubMinDocs: number;
20
+ /** Added once when the two decisions share a topic that is not a hub. */
21
+ topicBonus: number;
22
+ /** Added on top, times the rarity (0 to 1) of the rarest shared topic that is not a hub: a topic on few decisions says more. */
23
+ topicRarity: number;
24
+ /** A candidate is listed only at or above this score. */
25
+ minScore: number;
26
+ /** Candidates sent with one decision, at most. */
27
+ maxCandidates: number;
28
+ /** Rarity is computed as if the audience held at least this many decisions, so a small folder does not make every word look common. */
29
+ corpusFloor: number;
30
+ }
31
+ export declare const DEFAULT_LINEAGE_RETRIEVAL: LineageRetrievalRule;
32
+ /** Output tokens a decision's answer is counted as in an estimate. */
33
+ export declare const LINEAGE_OUTPUT_TOKENS_PER_DECISION = 40;
34
+ export interface LineageBackfillOptions {
35
+ /** First and last decision day to ask about. Earlier decisions are still offered as candidates. */
36
+ from?: IsoDate;
37
+ to?: IsoDate;
38
+ /** Estimate only: call no model and write nothing. */
39
+ dryRun: boolean;
40
+ /** Forget what earlier runs settled, their attempt counts and their unanswered decisions, and walk from the first day. Answers already given come from the cache. */
41
+ restart?: boolean;
42
+ /** Send the decisions earlier runs recorded as unanswered again. */
43
+ retryUnanswered?: boolean;
44
+ /** Record a decision with no usable reply as unanswered at once instead of holding its day for the next run, and do not fail the run for it. */
45
+ allowUnanswered?: boolean;
46
+ /** The daily cap for this run, as on `rebuild` and `update`. */
47
+ maxInputTokens?: number;
48
+ maxOutputTokens?: number;
49
+ }
50
+ /** Seams for tests. Production passes nothing. */
51
+ export interface LineageBackfillDeps {
52
+ runner?: ModelRunner;
53
+ /** The step to ask through. Default: a step on the configured model with the run's caps. */
54
+ step?: BatchModelStep;
55
+ store?: GraphStore;
56
+ now?: () => Date;
57
+ env?: NodeJS.ProcessEnv;
58
+ /** Default: the page compiler, on the pages the run made dirty, with no model. Null switches it off. */
59
+ compilePages?: typeof defaultCompilePages | null;
60
+ }
61
+ /** One accepted answer: `newer` replaces or reverses `older`, both read from `audience`. */
62
+ export interface LineagePair {
63
+ newer: EntityRef;
64
+ older: EntityRef;
65
+ audience: AudienceKey;
66
+ kind: LineageKind;
67
+ /** The day of the newer decision. */
68
+ day: IsoDate;
69
+ /** The source of the newer decision's statement. */
70
+ src: SourceRef;
71
+ /** The span of the newer decision's statement the model gave. */
72
+ quote: string;
73
+ /** The span of the earlier decision's statement the model gave. */
74
+ oldQuote: string;
75
+ }
76
+ /** A line of `LINEAGE_APPLIED_RELATIVE`. */
77
+ export interface LineageAppliedRecord extends LineagePair {
78
+ run: string;
79
+ by: Origin;
80
+ learned: IsoDate;
81
+ /** The rows added: the `supersedes` edge on `newer` and the `superseded_by` edge on `older`. */
82
+ rows: {
83
+ entity: EntityRef;
84
+ id: RowId;
85
+ }[];
86
+ }
87
+ export interface LineageApplyResult {
88
+ /** Pairs that wrote a link. */
89
+ applied: number;
90
+ /** Pairs whose link was already there. */
91
+ alreadyApplied: number;
92
+ /** Pairs another model's open link already holds: no second link is written. */
93
+ alreadyLinked: number;
94
+ /** `supersedes` edges written (one per pair; the inverse is not counted). */
95
+ links: number;
96
+ /** Links written, by the kind the model gave. Readers print every one as `replaced`. */
97
+ kinds: Record<string, number>;
98
+ rowsAdded: number;
99
+ /** Pairs left alone, by reason. */
100
+ skipped: Record<string, number>;
101
+ touched: EntityRef[];
102
+ /** Earlier decisions that have a link after this call, whether it wrote the link or found it. */
103
+ closedTargets: {
104
+ ref: EntityRef;
105
+ audience: AudienceKey;
106
+ day: IsoDate;
107
+ }[];
108
+ records: Omit<LineageAppliedRecord, "run">[];
109
+ }
110
+ /**
111
+ * Writes accepted pairs, in the order given: one `supersedes` edge each, of model authority. No
112
+ * status row is written or closed. A pair is left alone when the earlier decision already ended,
113
+ * when a person or a record said on or after the newer decision's day that it stands, or when the
114
+ * link would close a loop. Applying the same pairs again writes nothing.
115
+ */
116
+ export declare function applyLineagePairs(store: GraphStore, pairs: readonly LineagePair[], options: {
117
+ by: Origin;
118
+ learned: IsoDate;
119
+ conf?: number;
120
+ }): LineageApplyResult;
121
+ /** A decision as the walk reads it: one per audience folder that holds an open statement for it. */
122
+ export interface LineageDecision {
123
+ ref: EntityRef;
124
+ audience: AudienceKey;
125
+ day: IsoDate;
126
+ text: string;
127
+ src: SourceRef;
128
+ topics: Set<EntityRef>;
129
+ words: Set<string>;
130
+ /** The signal behind the decision states a change the rule wrote: the signals pass already asked. */
131
+ hasChanges: boolean;
132
+ /** The earliest day an open row says the decision ended: a `superseded_by` edge, or a status `endsDecision` accepts, of any origin. */
133
+ closedOn?: IsoDate;
134
+ }
135
+ /** Distinct words of four letters or more, lower case, without the common ones. The signals pass compares on the same words. */
136
+ export declare function lineageWords(text: string): Set<string>;
137
+ /** Every decision with an open statement, once per audience folder that holds one, oldest first. */
138
+ export declare function loadLineageDecisions(store: GraphStore): LineageDecision[];
139
+ /** The words of every person's name and aliases in the graph. Two decisions that name the same person are not, by that, about the same thing. */
140
+ export declare function lineagePersonWords(store: GraphStore): Set<string>;
141
+ /** What one audience's decisions say about how rare a word or a topic is. */
142
+ export interface LineageCorpus {
143
+ /** Decisions counted. */
144
+ size: number;
145
+ /** 0 for a person's name and for a word that is too common, else above 0 and at most 1: the fewer statements hold the word, the more. */
146
+ weight(word: string): number;
147
+ /** True for a topic on too large a share of the decisions to say two of them are about the same thing. */
148
+ hub(topic: EntityRef): boolean;
149
+ /** 0 for a hub, else above 0 and at most 1: the fewer decisions are about the topic, the more. */
150
+ topicWeight(topic: EntityRef): number;
151
+ }
152
+ /**
153
+ * Rarity over one audience's decision statements: inverse document frequency, `ln(n / df) / ln(n)`, with `n` the
154
+ * number of statements (at least `corpusFloor`) and `df` the statements that hold the word. A word above the
155
+ * document-frequency cutoff and a word of a person's name weigh nothing.
156
+ */
157
+ export declare function lineageCorpus(pool: readonly LineageDecision[], personWords: ReadonlySet<string>, rule?: LineageRetrievalRule): LineageCorpus;
158
+ /** How much two decisions share: the summed rarity of their shared words, plus the bonus for a shared topic that is not a hub. */
159
+ export declare function lineageScore(decision: LineageDecision, candidate: LineageDecision, corpus: LineageCorpus, rule?: LineageRetrievalRule): number;
160
+ /**
161
+ * The earlier decisions of the same audience that were open on the decision's day and may be what it
162
+ * changes: those that score at or above `minScore`, best first, at most `maxCandidates`.
163
+ * `pool` holds one audience's decisions, oldest first; `corpus` is that audience's.
164
+ */
165
+ export declare function pickLineageCandidates(decision: LineageDecision, pool: readonly LineageDecision[], corpus: LineageCorpus, rule?: LineageRetrievalRule): LineageDecision[];
166
+ /** Runs that may get an unusable reply for a decision before it is recorded as unanswered and its day is written without it. */
167
+ export declare const LINEAGE_MAX_ATTEMPTS = 3;
168
+ /** The share of turns an estimate's high figure counts a second time, for the retry turn an unusable reply costs. */
169
+ export declare const LINEAGE_RETRY_ALLOWANCE = 0.25;
170
+ /**
171
+ * `.state/lineage-backfill-cursor.json`: what earlier runs settled. It is read only when the model, the prompt
172
+ * version and the retrieval-rule version are the ones this run uses, so a change to any of them walks again.
173
+ */
174
+ export interface LineageCursor {
175
+ version: 2;
176
+ model: string;
177
+ promptVersion: string;
178
+ retrievalVersion: string;
179
+ /** Every decision day up to and including this one is settled. Null when the first day is not. For people: the walk reads `answered`. */
180
+ doneThrough: IsoDate | null;
181
+ /** Decisions settled, by `<audience> <ref>`: the signature of the candidates each was asked with ("-" for none). */
182
+ answered: Record<string, string>;
183
+ /** Runs that got an unusable reply, per decision. */
184
+ attempts: Record<string, number>;
185
+ /** Decisions given up on after `LINEAGE_MAX_ATTEMPTS` (or at once under `--allow-unanswered`). `--retry-unanswered` sends them again. */
186
+ unanswered: string[];
187
+ }
188
+ /** The state of an earlier run on this model, prompt and retrieval rule, or null. An unreadable file, or one of another version, is no state. */
189
+ export declare function readLineageCursor(graphRoot: string, model: string): LineageCursor | null;
190
+ /**
191
+ * What a million input tokens cost on this model, from the list-price cost the CLI reported for the
192
+ * calls in the model step's ledger. The figure is blended: it holds the output of those calls too.
193
+ * Null when the ledger has no priced call of the model.
194
+ */
195
+ export declare function ledgerRate(stateDir: string, model: string): {
196
+ usdPerMillionInputTokens: number;
197
+ calls: number;
198
+ } | null;
199
+ /** Where an estimate's output figure comes from. */
200
+ export interface LineageOutputBasis {
201
+ /** `fixed` when the ledger has no usable call. */
202
+ from: "decision-lineage" | "decision-supersession" | "fixed";
203
+ /** The model whose calls were measured. */
204
+ model: string | null;
205
+ calls: number;
206
+ /** Mean output tokens per decision over those calls. */
207
+ tokensPerDecision: number;
208
+ /** The 90th percentile of the calls' output per decision (twice the mean with fewer than five calls or no call). */
209
+ highTokensPerDecision: number;
210
+ }
211
+ /**
212
+ * Output tokens per decision, measured from the call ledger: this task's own calls on this model, else the
213
+ * supersession task's on this model, else the supersession task's on any model, else the fixed figure. Counted
214
+ * per decision and not per call, because the two tasks put a different number of decisions in a turn.
215
+ */
216
+ export declare function ledgerOutput(stateDir: string, model: string): LineageOutputBasis;
217
+ export interface LineageBackfillReport {
218
+ run: string;
219
+ model: string;
220
+ /** The day the calls are charged to. */
221
+ day: IsoDate;
222
+ dryRun: boolean;
223
+ graphRoot: string;
224
+ range: {
225
+ from?: IsoDate;
226
+ to?: IsoDate;
227
+ firstDay?: IsoDate;
228
+ lastDay?: IsoDate;
229
+ };
230
+ decisions: {
231
+ /** Decisions with a statement, counted once per audience folder. */
232
+ total: number;
233
+ audiences: number;
234
+ /** Left out: their signal already states a change. */
235
+ withChanges: number;
236
+ /** Left to settle in the days this run walked. */
237
+ inRange: number;
238
+ /** Sent, or answered from the cache: they have earlier open decisions to compare with. */
239
+ asked: number;
240
+ /** Not sent: no earlier open decision shares enough with them. */
241
+ noCandidates: number;
242
+ /** Settled by an earlier run with the same candidates: not looked at again. */
243
+ settled: number;
244
+ };
245
+ /** Days with a decision left to settle, and the days this run finished. */
246
+ days: {
247
+ toWalk: number;
248
+ done: number;
249
+ };
250
+ /** Model turns made. */
251
+ batches: number;
252
+ /** `parked`: decisions whose reply was unusable in this run. */
253
+ items: {
254
+ cached: number;
255
+ answered: number;
256
+ pending: number;
257
+ parked: number;
258
+ };
259
+ /**
260
+ * Decisions with no usable reply. `total`: recorded as unanswered after this run. `thisRun`: recorded by this run.
261
+ * `held`: unusable in this run and sent again by the next one; their day is not written. `recovered`: recorded
262
+ * earlier and answered in this run (`--retry-unanswered`).
263
+ */
264
+ unanswered: {
265
+ total: number;
266
+ thisRun: number;
267
+ held: number;
268
+ recovered: number;
269
+ maxAttempts: number;
270
+ };
271
+ /**
272
+ * The decisions behind those counts, each as `<audience> <decision>`, sorted. `recorded`: recorded as unanswered
273
+ * after this run (the `unanswered` list of the state file). `held`: unusable in this run and sent again by the next.
274
+ */
275
+ unansweredDecisions: {
276
+ recorded: string[];
277
+ held: string[];
278
+ };
279
+ usage: {
280
+ inputTokens: number;
281
+ outputTokens: number;
282
+ };
283
+ /** Entries of the model's answers the host refused, by reason. */
284
+ dropped: Record<string, number>;
285
+ /** `alreadyLinked`: pairs another model's open link already holds; no second link is written. */
286
+ pairs: {
287
+ accepted: number;
288
+ applied: number;
289
+ alreadyApplied: number;
290
+ alreadyLinked: number;
291
+ skipped: Record<string, number>;
292
+ };
293
+ /** What the run wrote: links, the kinds the model gave for them, and rows (a link is two rows, one on each decision). No status row is written or closed. */
294
+ written: {
295
+ links: number;
296
+ replaces: number;
297
+ reverses: number;
298
+ rowsAdded: number;
299
+ };
300
+ cap: {
301
+ dayInputTokens: number;
302
+ dayOutputTokens: number;
303
+ overridden: boolean;
304
+ };
305
+ cursor: {
306
+ before: IsoDate | null;
307
+ after: IsoDate | null;
308
+ moved: boolean;
309
+ };
310
+ /** Why the walk stopped before the last day, and the day it stopped on. `unanswered`: a decision of that day got no usable reply. */
311
+ stopped?: {
312
+ reason: string;
313
+ day: IsoDate;
314
+ };
315
+ /** Dry run: what asking would send. The plain figures are the low end of the range, the `High` ones the high end. */
316
+ estimate?: {
317
+ decisions: number;
318
+ batches: number;
319
+ inputTokens: number;
320
+ inputTokensHigh: number;
321
+ outputTokens: number;
322
+ outputTokensHigh: number;
323
+ /** List price, or null when the call ledger has no priced call of the model. */
324
+ costUsd: number | null;
325
+ costUsdHigh: number | null;
326
+ usdPerMillionInputTokens: number | null;
327
+ pricedCalls: number;
328
+ outputBasis: LineageOutputBasis;
329
+ /** The share of turns the high figures count twice. */
330
+ retryAllowance: number;
331
+ /** The flags that let the high estimate through the daily cap, or null when it is under the cap. */
332
+ capFlags: string | null;
333
+ };
334
+ notes: string[];
335
+ }
336
+ export declare function runLineageBackfill(context: GraphContext, options: LineageBackfillOptions, deps?: LineageBackfillDeps): Promise<LineageBackfillReport>;
337
+ export declare function formatLineageBackfillReport(report: LineageBackfillReport): string;
338
+ /**
339
+ * `hq ontology lineage backfill`. Exit code 2 when the walk stopped before its last day (a cap, a usage limit, a
340
+ * sign-out, or a decision with no usable reply). Exit code 3 when the walk finished and a decision got no usable
341
+ * reply in this run, unless `--allow-unanswered` was passed.
342
+ */
343
+ export declare function lineageBackfillCommand(context: GraphContext, options: LineageBackfillOptions, deps?: LineageBackfillDeps): Promise<CommandOutput>;
344
+ export interface LineageUndoOptions {
345
+ /** Count what would be removed and write nothing. */
346
+ dryRun: boolean;
347
+ }
348
+ export interface LineageUndoDeps {
349
+ store?: GraphStore;
350
+ now?: () => Date;
351
+ /** As for the backfill: null switches the page compiler off. */
352
+ compilePages?: typeof defaultCompilePages | null;
353
+ }
354
+ export interface LineageUndoReport {
355
+ run: string;
356
+ dryRun: boolean;
357
+ graphRoot: string;
358
+ /** Lines of `.state/lineage-backfill.jsonl`. */
359
+ records: number;
360
+ /** `removed`: links with a row taken out and none left in the graph. `kept`: links with a row left in the graph; their lines stay in the file. */
361
+ links: {
362
+ removed: number;
363
+ kept: number;
364
+ };
365
+ /**
366
+ * `removed`: rows taken out. `missing`: recorded rows this graph does not hold. `changed`: rows left where they
367
+ * are, by reason in `changedBy` (`skipped_not_model_link`: the recorded origin is not a model's, or the row is not
368
+ * a `supersedes` or `superseded_by` edge).
369
+ */
370
+ rows: {
371
+ removed: number;
372
+ missing: number;
373
+ changed: number;
374
+ };
375
+ changedBy: Record<string, number>;
376
+ /**
377
+ * True when the file lists rows and this graph holds none of them: the record does not match this graph. Nothing
378
+ * is removed, the record file and the walk's state stay, and the command exits with code 1.
379
+ */
380
+ mismatch: boolean;
381
+ /** The walk's state file was there and is removed, so a later backfill starts from the first day. */
382
+ stateCleared: boolean;
383
+ touched: EntityRef[];
384
+ notes: string[];
385
+ }
386
+ /**
387
+ * `hq ontology lineage undo`: removes the rows `.state/lineage-backfill.jsonl` lists, the edge and its inverse of
388
+ * each link, and nothing else. The record file is not trusted: a row is removed only when the recorded origin is a
389
+ * model's (`agent:`) and the graph still holds the row under the recorded id, as an open `supersedes` or
390
+ * `superseded_by` edge of that origin. A line that names another origin (a rule, a person, a record) or a row of
391
+ * another kind removes nothing (`skipped_not_model_link`). A row that was closed since (by the rule
392
+ * `signal-changes`, for a signal that states the opposite) or differs in any other way is left and counted. When
393
+ * the graph holds none of the recorded rows, the record is of another graph: nothing is removed and the record file
394
+ * and the walk's state stay (`mismatch`). Otherwise the walk's state file is removed, so a later backfill starts
395
+ * clean. The reply cache is not touched.
396
+ */
397
+ export declare function runLineageUndo(context: GraphContext, options: LineageUndoOptions, deps?: LineageUndoDeps): Promise<LineageUndoReport>;
398
+ export declare function formatLineageUndoReport(report: LineageUndoReport): string;
399
+ /** `hq ontology lineage undo`. Exit code 1 when the record file does not match this graph (none of its rows is here). */
400
+ export declare function lineageUndoCommand(context: GraphContext, options: LineageUndoOptions, deps?: LineageUndoDeps): Promise<CommandOutput>;
401
+ //# sourceMappingURL=index.d.ts.map