@indigoai-us/hq-cli 5.345.251 → 5.345.252

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (160) hide show
  1. package/CHANGELOG.md +112 -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 +121 -1
  5. package/dist/command-catalog.generated.js +148 -1
  6. package/dist/commands/bot.js +7 -2
  7. package/dist/commands/core-bucket-c-work-mesh-offer-native.js +1 -1
  8. package/dist/commands/core-hq-session-binding.d.ts +140 -0
  9. package/dist/commands/core-hq-session-binding.js +363 -0
  10. package/dist/commands/core-hq-session-native.d.ts +23 -0
  11. package/dist/commands/core-hq-session-native.js +59 -9
  12. package/dist/commands/core-stop-autosave.js +1 -1
  13. package/dist/commands/core.js +10 -0
  14. package/dist/commands/doctor.d.ts +5 -1
  15. package/dist/commands/doctor.js +42 -5
  16. package/dist/commands/files.js +1 -1
  17. package/dist/commands/install-global.js +4 -2
  18. package/dist/commands/logout.js +4 -0
  19. package/dist/commands/ontology-graph.d.ts +2 -0
  20. package/dist/commands/ontology-graph.js +33 -0
  21. package/dist/commands/report.js +35 -2
  22. package/dist/commands/storage-gate.js +1 -1
  23. package/dist/commands/vault-retention-flag.js +2 -1
  24. package/dist/commands/whoami.js +1 -1
  25. package/dist/hq-cloud-sync-runner/bin/sync-runner.js +238 -221
  26. package/dist/hq-cloud-sync-runner/package.json +1 -1
  27. package/dist/index.js +3 -1
  28. package/dist/lib/agent-kit/inbox-poll-backoff-flag.js +1 -1
  29. package/dist/lib/agent-kit/mcp/tools.js +48 -0
  30. package/dist/lib/bot/fleet-bots-update-pass.js +1 -1
  31. package/dist/lib/bot/fleet-cron.d.ts +35 -0
  32. package/dist/lib/bot/fleet-cron.js +54 -12
  33. package/dist/lib/bot/fleet-local.d.ts +18 -0
  34. package/dist/lib/bot/fleet-local.js +51 -5
  35. package/dist/lib/bot/inbox-poll-backoff-flag.js +1 -1
  36. package/dist/lib/bot/signals-engine-flag.d.ts +1 -1
  37. package/dist/lib/bot/signals-engine-flag.js +1 -1
  38. package/dist/lib/cli-invite-nudge.js +1 -1
  39. package/dist/lib/client-version.d.ts +2 -0
  40. package/dist/lib/client-version.js +24 -0
  41. package/dist/lib/company-flag-gate.d.ts +30 -0
  42. package/dist/lib/company-flag-gate.js +104 -0
  43. package/dist/lib/core-utils/hook-timeout-debug-context-flag.js +1 -1
  44. package/dist/lib/daemon/flag.js +2 -1
  45. package/dist/lib/daemon/legacy-journal-gate.js +3 -1
  46. package/dist/lib/daemon/shared-flag-reads.js +1 -1
  47. package/dist/lib/doctor/checks/host-core.js +22 -4
  48. package/dist/lib/doctor/checks/jq.d.ts +27 -6
  49. package/dist/lib/doctor/checks/jq.js +46 -8
  50. package/dist/lib/doctor/client-health-reason-codes-flag.js +1 -1
  51. package/dist/lib/doctor/fix/refresh-sync-handoff.d.ts +1 -1
  52. package/dist/lib/doctor/fix/refresh-sync-handoff.js +1 -1
  53. package/dist/lib/flag-client-gate-headers.d.ts +38 -0
  54. package/dist/lib/flag-client-gate-headers.js +62 -0
  55. package/dist/lib/flag-client-headers.d.ts +15 -0
  56. package/dist/lib/flag-client-headers.js +25 -0
  57. package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
  58. package/dist/lib/flag-registry-worker-source.generated.js +1 -1
  59. package/dist/lib/flag-registry-worker.js +35 -0
  60. package/dist/lib/flag-registry.d.ts +1 -20
  61. package/dist/lib/flag-registry.js +5 -81
  62. package/dist/lib/hook-engine/adapter-core-pin.d.ts +29 -0
  63. package/dist/lib/hook-engine/adapter-core-pin.js +29 -0
  64. package/dist/lib/hook-engine/coverage.d.ts +50 -1
  65. package/dist/lib/hook-engine/coverage.js +111 -7
  66. package/dist/lib/hook-engine/reconcile.js +3 -2
  67. package/dist/lib/hot-channels/prompts/signals-pass.md +20 -0
  68. package/dist/lib/hot-channels/signal-changes.d.ts +228 -0
  69. package/dist/lib/hot-channels/signal-changes.js +683 -0
  70. package/dist/lib/hot-channels/signals-pass.d.ts +24 -0
  71. package/dist/lib/hot-channels/signals-pass.js +232 -12
  72. package/dist/lib/lanes/outpost-worktree-pruner-flag.d.ts +1 -1
  73. package/dist/lib/lanes/outpost-worktree-pruner-flag.js +1 -1
  74. package/dist/lib/lanes/registry-flag.js +2 -1
  75. package/dist/lib/lanes/spawn.js +11 -1
  76. package/dist/lib/mesh/live/binding-intent.d.ts +61 -0
  77. package/dist/lib/mesh/live/binding-intent.js +201 -0
  78. package/dist/lib/mesh/live/binding-receipt.d.ts +157 -0
  79. package/dist/lib/mesh/live/binding-receipt.js +365 -0
  80. package/dist/lib/mesh/live/company-flag-refresh.js +1 -1
  81. package/dist/lib/mesh/live/daemon/doctor-telemetry.d.ts +39 -0
  82. package/dist/lib/mesh/live/daemon/doctor-telemetry.js +58 -0
  83. package/dist/lib/mesh/live/daemon/install.js +2 -1
  84. package/dist/lib/mesh/live/daemon/presence.js +9 -0
  85. package/dist/lib/mesh/live/daemon/run.d.ts +3 -0
  86. package/dist/lib/mesh/live/daemon/run.js +33 -1
  87. package/dist/lib/ontology-graph/lineage/index.d.ts +401 -0
  88. package/dist/lib/ontology-graph/lineage/index.js +1027 -0
  89. package/dist/lib/ontology-graph/model/index.d.ts +54 -0
  90. package/dist/lib/ontology-graph/model/index.js +112 -0
  91. package/dist/lib/ontology-graph/model/pass-tasks.d.ts +75 -0
  92. package/dist/lib/ontology-graph/model/pass-tasks.js +166 -0
  93. package/dist/lib/ontology-graph/model/pass.d.ts +6 -0
  94. package/dist/lib/ontology-graph/model/pass.js +9 -2
  95. package/dist/lib/ontology-graph/model/pending-items.d.ts +8 -0
  96. package/dist/lib/ontology-graph/model/pending-items.js +24 -1
  97. package/dist/lib/ontology-graph/model/step.d.ts +1 -1
  98. package/dist/lib/ontology-graph/model/tasks.d.ts +11 -3
  99. package/dist/lib/ontology-graph/model/tasks.js +20 -7
  100. package/dist/lib/ontology-graph/read/brief.js +41 -6
  101. package/dist/lib/ontology-graph/read/index.d.ts +4 -0
  102. package/dist/lib/ontology-graph/read/index.js +173 -29
  103. package/dist/lib/ontology-graph/read/lineage.d.ts +101 -0
  104. package/dist/lib/ontology-graph/read/lineage.js +262 -0
  105. package/dist/lib/ontology-graph/replay/buffered-store.js +17 -0
  106. package/dist/lib/ontology-graph/replay/engine.d.ts +32 -1
  107. package/dist/lib/ontology-graph/replay/engine.js +213 -8
  108. package/dist/lib/ontology-graph/replay/extractors.d.ts +26 -0
  109. package/dist/lib/ontology-graph/replay/extractors.js +25 -1
  110. package/dist/lib/ontology-graph/replay/index.d.ts +2 -0
  111. package/dist/lib/ontology-graph/replay/index.js +9 -3
  112. package/dist/lib/ontology-graph/replay/signal-changes.d.ts +118 -0
  113. package/dist/lib/ontology-graph/replay/signal-changes.js +687 -0
  114. package/dist/lib/ontology-graph/schema/decision-status.d.ts +18 -0
  115. package/dist/lib/ontology-graph/schema/decision-status.js +20 -0
  116. package/dist/lib/ontology-graph/schema/index.d.ts +1 -0
  117. package/dist/lib/ontology-graph/schema/index.js +1 -0
  118. package/dist/lib/ontology-graph/setup/index.js +13 -3
  119. package/dist/lib/search-index/index.d.ts +33 -1
  120. package/dist/lib/search-index/index.js +180 -25
  121. package/dist/lib/search-index/qmd-exit-diagnostics.d.ts +7 -0
  122. package/dist/lib/search-index/qmd-exit-diagnostics.js +25 -1
  123. package/dist/lib/signals/adapters-catalog.js +1 -1
  124. package/dist/lib/sync-core/engine-holds.d.ts +1 -0
  125. package/dist/lib/sync-core/engine-holds.js +26 -0
  126. package/dist/lib/sync-core/engine-home.d.ts +3 -0
  127. package/dist/lib/sync-core/engine-home.js +41 -1
  128. package/dist/lib/sync-core/flag.js +2 -1
  129. package/dist/lib/sync-core/legacy-journal-export-child.js +5 -3
  130. package/dist/lib/sync-core/legacy-journal-export.d.ts +23 -4
  131. package/dist/lib/sync-core/legacy-journal-export.js +120 -55
  132. package/dist/lib/sync-core/reconcile.d.ts +2 -1
  133. package/dist/lib/sync-core/reconcile.js +30 -5
  134. package/dist/lib/sync-invalid-entity-warning.js +2 -1
  135. package/dist/lib/windows/install-followup.d.ts +41 -0
  136. package/dist/lib/windows/install-followup.js +87 -0
  137. package/dist/lib/windows/jq.d.ts +59 -0
  138. package/dist/lib/windows/jq.js +154 -3
  139. package/dist/lib/windows/user-path.d.ts +5 -0
  140. package/dist/lib/windows/user-path.js +1 -1
  141. package/dist/lib/work-context/auto-bind.d.ts +12 -0
  142. package/dist/lib/work-context/auto-bind.js +49 -3
  143. package/dist/lib/work-context/organize.d.ts +4 -2
  144. package/dist/lib/work-context/organize.js +18 -8
  145. package/dist/lib/work-context/reconcile.js +16 -1
  146. package/dist/main.js +12 -1
  147. package/dist/utils/client-health-contract.d.ts +30 -0
  148. package/dist/utils/client-health-contract.js +111 -0
  149. package/dist/utils/client-health.d.ts +5 -2
  150. package/dist/utils/client-health.js +74 -5
  151. package/dist/utils/exclusive-lock.d.ts +5 -1
  152. package/dist/utils/exclusive-lock.js +9 -2
  153. package/dist/utils/host-registration.d.ts +7 -0
  154. package/dist/utils/host-registration.js +10 -1
  155. package/dist/utils/pid.d.ts +31 -0
  156. package/dist/utils/pid.js +65 -0
  157. package/dist/utils/resident-package-preload.js +12 -4
  158. package/dist/utils/sentry-fingerprint.js +3 -0
  159. package/package.json +8 -8
  160. package/scripts/install-hook-engine.mjs +5 -3
@@ -14,7 +14,11 @@
14
14
  * and `neighbors` (CONTRACT.md lists which command reaches each).
15
15
  * - `full`. The earlier summary: who the member is and what they work on,
16
16
  * active projects with owner and stage, the most active customers with
17
- * stage, what changed in the last 7 days, the four commands.
17
+ * stage, what changed in the last 7 days, the four commands. A stage, a
18
+ * status and an owner are printed with the day the row is valid from, and
19
+ * a decision that a later decision replaced ends with
20
+ * ` | replaced <date> by <id> [<by> <conf>]`, the origin and confidence
21
+ * of the edge that says so (see lineage.ts).
18
22
  *
19
23
  * Both are kept under `BRIEF_MAX_TOKENS` by a character estimate that
20
24
  * overstates the count, and by dropping the last entry of the longest list
@@ -25,6 +29,7 @@ import { GUESS_FIELDS, dropUnverifiedGuesses, effectiveFacts, isUnverifiedGuess,
25
29
  import { GRAPH_PATHS, atomicWriteFile, graphPath, openGraphStore } from "../store/index.js";
26
30
  import { BRIEF_STYLES, COMPANY_AUDIENCE, } from "../types.js";
27
31
  import { graphExists, loadReadIndex, normalizeName, rowVisible, visible, } from "./graph-index.js";
32
+ import { decisionLineage, replacedMarker } from "./lineage.js";
28
33
  import { indexedFacts } from "./names.js";
29
34
  import { readReaderSetting } from "./reader-setting.js";
30
35
  export const BRIEF_MAX_TOKENS = 1500;
@@ -62,6 +67,14 @@ function isoDay(date) {
62
67
  function factValue(index, schema, entity, filter, field) {
63
68
  return indexedFacts(index, schema, entity, filter).find((stored) => stored.row.field === field)?.row.value ?? "";
64
69
  }
70
+ /** The day the winning row of a field is valid from, or "". */
71
+ function factDay(index, schema, entity, filter, field) {
72
+ return indexedFacts(index, schema, entity, filter).find((stored) => stored.row.field === field)?.row.valid.from ?? "";
73
+ }
74
+ /** ` [<day>]` after a value, or nothing when the row has no day. */
75
+ function dayNote(day) {
76
+ return day ? ` [${day}]` : "";
77
+ }
65
78
  /**
66
79
  * True for a role or an affiliation a model read out of a document, at any confidence. The brief prints a role
67
80
  * with no source and no origin beside it, so it prints one only when a record, a rule, a person or the old
@@ -204,6 +217,8 @@ function activeProjects(frame) {
204
217
  entity,
205
218
  status: factValue(index, schema, entity, filter, "status"),
206
219
  stage: factValue(index, schema, entity, filter, "stage"),
220
+ statusDay: factDay(index, schema, entity, filter, "status"),
221
+ stageDay: factDay(index, schema, entity, filter, "stage"),
207
222
  }))
208
223
  .filter((entry) => !ENDED.test(entry.status) && !ENDED.test(entry.stage))
209
224
  .sort((a, b) => byActivity(a.entity, b.entity));
@@ -220,6 +235,8 @@ function activeCustomers(frame) {
220
235
  customer: facts.some((stored) => stored.row.field === "relation" && /customer/i.test(stored.row.value)),
221
236
  stage: facts.find((stored) => stored.row.field === "stage")?.row.value ?? "",
222
237
  crm: facts.find((stored) => stored.row.field === "crm_status")?.row.value ?? "",
238
+ stageDay: facts.find((stored) => stored.row.field === "stage")?.row.valid.from ?? "",
239
+ crmDay: facts.find((stored) => stored.row.field === "crm_status")?.row.valid.from ?? "",
223
240
  };
224
241
  })
225
242
  .filter((entry) => entry.customer)
@@ -302,15 +319,16 @@ function buildFullBrief(frame) {
302
319
  const owner = ownerRows.rows.find((stored) => stored.row.verb === "owned_by" || stored.row.verb === "led_by");
303
320
  const parts = [
304
321
  `${clip(withNames(frame, entry.entity.name).text, 48)} (${entry.entity.id})`,
305
- ...(entry.stage ? [`stage ${clip(entry.stage, 24)}`] : entry.status ? [`status ${clip(entry.status, 24)}`] : []),
306
- ...(owner ? [`owner ${owner.row.target}`] : []),
322
+ ...(entry.stage ? [`stage ${clip(entry.stage, 24)}${dayNote(entry.stageDay)}`] : entry.status ? [`status ${clip(entry.status, 24)}${dayNote(entry.statusDay)}`] : []),
323
+ ...(owner ? [`owner ${owner.row.target}${dayNote(owner.row.valid.from)}`] : []),
307
324
  ];
308
325
  sections.projects.push(`- ${parts.join(" | ")}`);
309
326
  }
310
327
  // Customers.
311
328
  for (const entry of activeCustomers(frame).slice(0, BRIEF_MAX_CUSTOMERS)) {
312
329
  const stage = entry.stage || entry.crm;
313
- sections.customers.push(`- ${clip(withNames(frame, entry.entity.name).text, 48)} (${entry.entity.id})${stage ? ` | stage ${clip(stage, 24)}` : ""}`);
330
+ const stageDay = entry.stage ? entry.stageDay : entry.crmDay;
331
+ sections.customers.push(`- ${clip(withNames(frame, entry.entity.name).text, 48)} (${entry.entity.id})${stage ? ` | stage ${clip(stage, 24)}${dayNote(stageDay)}` : ""}`);
314
332
  }
315
333
  // What changed in the window: decisions first, then changed single-valued facts.
316
334
  const changes = [];
@@ -319,9 +337,26 @@ function buildFullBrief(frame) {
319
337
  continue;
320
338
  const day = factValue(index, schema, entity, filter, "decided_on") || entity.firstSeen;
321
339
  if (day >= cutoff && day <= today)
322
- changes.push({ day, line: `- ${day} decision: ${clip(withNames(frame, entity.name).text, 90)} (${entity.id})` });
340
+ changes.push({ day, id: entity.id, line: `- ${day} decision: ${clip(withNames(frame, entity.name).text, 90)} (${entity.id})` });
323
341
  }
324
- const decisions = changes.sort((a, b) => (a.day < b.day ? 1 : a.day > b.day ? -1 : 0)).slice(0, 8);
342
+ // A decision a later decision replaced stays on the list, marked, so it is not read as the current one.
343
+ const visibleTarget = (ref) => {
344
+ const target = index.entities[index.byId.get(ref) ?? -1];
345
+ return target !== undefined && visible(target, filter);
346
+ };
347
+ const lineageEdges = (ref) => openEdges(store, ref, filter).filter((stored) => visibleTarget(stored.row.target));
348
+ // The status rows say whether a link was a reversal, whether the decision was withdrawn, and whether a person or a
349
+ // record has set its status since (then the link carries no marker).
350
+ const lineageFacts = {
351
+ statusRows: (ref) => store
352
+ .readRows(ref, { kinds: ["F"], ...(filter === null ? {} : { audiences: [...filter] }) })
353
+ .filter((stored) => stored.row.kind === "F" && stored.row.field === "status" && rowVisible(stored.audience, filter)),
354
+ live: (row) => !row.valid.to,
355
+ };
356
+ const decisions = changes
357
+ .sort((a, b) => (a.day < b.day ? 1 : a.day > b.day ? -1 : 0))
358
+ .slice(0, 8)
359
+ .map((entry) => ({ day: entry.day, line: `${entry.line}${replacedMarker(decisionLineage(lineageEdges, entry.id, lineageFacts))}` }));
325
360
  const moved = [];
326
361
  for (const entry of index.facts) {
327
362
  const entity = index.entities[entry.e];
@@ -6,6 +6,8 @@ export { graphReaderEnabled, readReaderSetting, readerSettingFile } from "./read
6
6
  export { loadReadIndex, forgetReadIndex, READ_INDEX_RELATIVE } from "./graph-index.js";
7
7
  export { resolveName, searchIndex } from "./names.js";
8
8
  export { resolveReadMember } from "./member.js";
9
+ export { decisionLineage, replacedMarker, LINEAGE_MAX_STEPS } from "./lineage.js";
10
+ export type { Lineage, LineageLink, LineageStep } from "./lineage.js";
9
11
  export type { ResolveReadMemberOptions } from "./member.js";
10
12
  /** Optional inputs every read command accepts beside its contract options. */
11
13
  export interface ReadExtras {
@@ -32,6 +34,8 @@ export declare const LOOKUP_EDGE_LIMIT = 12;
32
34
  export declare const SIGNAL_LIMIT = 5;
33
35
  export declare const LOOKUP_RECENT_LIMIT = 3;
34
36
  export declare const WALK_NODE_LIMIT = 300;
37
+ /** Most characters of a decision's name on a `replaced:` or `replaces:` line. */
38
+ export declare const LINEAGE_NAME_MAX_CHARS = 60;
35
39
  export declare function audienceFilterFor(context: GraphContext, extras?: ReadExtras): AudienceFilter;
36
40
  /** `hq ontology lookup <name> [--as-of D]`. */
37
41
  export declare function lookupCommand(context: GraphContext, options: LookupOptions & ReadExtras & {
@@ -9,6 +9,13 @@
9
9
  * `file: <path from the HQ root>` when the source is a file on this machine,
10
10
  * so a session can open what a line rests on.
11
11
  *
12
+ * A decision that a later decision replaced (an open `superseded_by` edge) is
13
+ * never printed as current. `lookup` and `neighbors` put `replaced:` and
14
+ * `replaces:` lines directly under the header, `lookup` prints the status as
15
+ * `replaced [<citation of the edge>] (was <value> [<citation of the stored
16
+ * fact>])`, and every other line that shows such a decision ends with
17
+ * ` | replaced <date> by <id> [<by> <conf>]` (see lineage.ts).
18
+ *
12
19
  * The graph is a way in, not the record. `about`, `discussed_in`, `mentions`
13
20
  * and `related_to` say that two things appear in the same meeting, decision
14
21
  * or document; they are counted and listed on request, never shown as a
@@ -25,16 +32,18 @@
25
32
  import * as fs from "node:fs";
26
33
  import * as path from "node:path";
27
34
  import { filterPageLines } from "../pages/render.js";
28
- import { dropUnverifiedGuesses, effectiveFacts, originTier, rowCoversDay } from "../schema/index.js";
35
+ import { dropUnverifiedGuesses, effectiveFacts, endsDecision, originTier, rowCoversDay } from "../schema/index.js";
29
36
  import { openGraphStore, pageFile } from "../store/index.js";
30
37
  import { COMPANY_AUDIENCE, } from "../types.js";
31
38
  import { graphExists, loadReadIndex, visible, } from "./graph-index.js";
39
+ import { SIGNAL_CHANGES_ORIGIN, decisionLineage, isDecisionRef, lineageJson, lineageStatusJson, originNote, replacedByShortJson, replacedMarker, } from "./lineage.js";
32
40
  import { indexedFacts, resolveName, searchIndex } from "./names.js";
33
41
  export { briefCommand, buildBrief, estimateTokens, resolveBriefStyle, BRIEF_DEFAULT_STYLE, BRIEF_MAX_TOKENS } from "./brief.js";
34
42
  export { graphReaderEnabled, readReaderSetting, readerSettingFile } from "./reader-setting.js";
35
43
  export { loadReadIndex, forgetReadIndex, READ_INDEX_RELATIVE } from "./graph-index.js";
36
44
  export { resolveName, searchIndex } from "./names.js";
37
45
  export { resolveReadMember } from "./member.js";
46
+ export { decisionLineage, replacedMarker, LINEAGE_MAX_STEPS } from "./lineage.js";
38
47
  /**
39
48
  * Verbs that say two things appear together in a meeting, a decision or a
40
49
  * document. They are evidence to open, not a relationship between the two.
@@ -49,6 +58,8 @@ export const LOOKUP_EDGE_LIMIT = 12;
49
58
  export const SIGNAL_LIMIT = 5;
50
59
  export const LOOKUP_RECENT_LIMIT = 3;
51
60
  export const WALK_NODE_LIMIT = 300;
61
+ /** Most characters of a decision's name on a `replaced:` or `replaces:` line. */
62
+ export const LINEAGE_NAME_MAX_CHARS = 60;
52
63
  /** Where a session can search when the graph does not answer. */
53
64
  function vaultHint(context) {
54
65
  return `Search the vault before answering: qmd or grep under companies/${context.company}/ (knowledge, policies, projects, sources, signals).`;
@@ -149,6 +160,7 @@ function open(context, extras) {
149
160
  return {
150
161
  context,
151
162
  files: new Map(),
163
+ lineage: new Map(),
152
164
  store,
153
165
  schema: store.schema(),
154
166
  index: loadReadIndex(context.graphRoot, { store }),
@@ -170,7 +182,8 @@ function scope(audience) {
170
182
  }
171
183
  function citeFact(stored) {
172
184
  const row = stored.row;
173
- return `[${row.src} ${row.valid.from} ${row.by} ${row.conf.toFixed(2)}${scope(stored.audience)}]`;
185
+ // A row the rule `signal-changes` wrote says so: it applies what a model read in a document.
186
+ return `[${row.src} ${row.valid.from} ${row.by} ${row.conf.toFixed(2)}${scope(stored.audience)}${originNote(row.by)}]`;
174
187
  }
175
188
  function citeEdge(stored) {
176
189
  const row = stored.row;
@@ -201,10 +214,10 @@ function byImportance(schema) {
201
214
  (a.row.valid.from < b.row.valid.from ? 1 : a.row.valid.from > b.row.valid.from ? -1 : 0) ||
202
215
  (a.row.target < b.row.target ? -1 : a.row.target > b.row.target ? 1 : 0);
203
216
  }
204
- function candidateLine(session, entity) {
217
+ function candidateLine(session, entity, asOf) {
205
218
  const facts = entityFactsFromIndex(session, entity).slice(0, 2);
206
219
  const detail = facts.map((stored) => `${stored.row.field}: ${stored.row.value}`).join("; ");
207
- return ` ${entity.id} | ${entity.name}${detail ? ` | ${detail}` : ""}`;
220
+ return ` ${entity.id} | ${entity.name}${detail ? ` | ${detail}` : ""}${replacedNote(session, entity.id, asOf)}`;
208
221
  }
209
222
  function entityFactsFromIndex(session, entity) {
210
223
  return indexedFacts(session.index, session.schema, entity, session.filter);
@@ -212,8 +225,11 @@ function entityFactsFromIndex(session, entity) {
212
225
  function candidateJson(entity) {
213
226
  return { id: entity.id, type: entity.type, name: entity.name };
214
227
  }
215
- /** The reply for a name that did not resolve to one entity. Never picks one. */
216
- function unresolvedOutput(session, typed, answer) {
228
+ /**
229
+ * The reply for a name that did not resolve to one entity. Never picks one.
230
+ * With `asOf`, a candidate is marked as replaced only if it was on that day.
231
+ */
232
+ function unresolvedOutput(session, typed, answer, asOf) {
217
233
  const candidates = answer.candidates;
218
234
  const json = {
219
235
  status: answer.status,
@@ -225,7 +241,7 @@ function unresolvedOutput(session, typed, answer) {
225
241
  return {
226
242
  text: [
227
243
  `ambiguous: "${typed}" matches ${String(candidates.length)} entities (${answer.reason}). Pick one id and ask again:`,
228
- ...candidates.map((entity) => candidateLine(session, entity)),
244
+ ...candidates.map((entity) => candidateLine(session, entity, asOf)),
229
245
  ].join("\n"),
230
246
  json,
231
247
  };
@@ -236,7 +252,7 @@ function unresolvedOutput(session, typed, answer) {
236
252
  return {
237
253
  text: [
238
254
  `no match: "${typed}" (${answer.reason}).`,
239
- ...(candidates.length > 0 ? ["near matches, none selected:", ...candidates.map((entity) => candidateLine(session, entity))] : []),
255
+ ...(candidates.length > 0 ? ["near matches, none selected:", ...candidates.map((entity) => candidateLine(session, entity, asOf))] : []),
240
256
  // The graph not knowing a name is not the company not knowing it.
241
257
  `Not in the graph is not "not known". ${vaultHint(session.context)}`,
242
258
  ].join("\n"),
@@ -259,7 +275,8 @@ function chosenLine(answer) {
259
275
  `chosen: ${answer.entity.id}, who works at the company, over ${answer.chosenOver.map((entity) => `${entity.id} (${entity.type})`).join(", ")} with the same name. Ask by id for the other.`,
260
276
  ];
261
277
  }
262
- function edgeJson(session, stored) {
278
+ function edgeJson(session, stored, asOf) {
279
+ const targetReplaced = LINEAGE_VERBS.has(stored.row.verb) ? {} : replacedByField(session, stored.row.target, asOf);
263
280
  return {
264
281
  verb: stored.row.verb,
265
282
  target: stored.row.target,
@@ -273,11 +290,13 @@ function edgeJson(session, stored) {
273
290
  audience: stored.audience,
274
291
  // False: the two appear in the same meeting, decision or document. Open the source; do not report a relationship.
275
292
  relationship: !CO_MENTION_VERBS.has(stored.row.verb),
293
+ // Set when the target is a decision that a later decision replaced.
294
+ ...(targetReplaced.replacedBy ? { targetReplacedBy: targetReplaced.replacedBy } : {}),
276
295
  };
277
296
  }
278
- function edgeLine(session, stored) {
297
+ function edgeLine(session, stored, asOf) {
279
298
  const name = nameOf(session, stored.row.target);
280
- return `${stored.row.verb} -> ${stored.row.target}${name ? ` (${name})` : ""} ${citeEdge(stored)}${fileNote(session, stored.row.src)}`;
299
+ return `${stored.row.verb} -> ${stored.row.target}${name ? ` (${name})` : ""} ${citeEdge(stored)}${fileNote(session, stored.row.src)}${targetReplacedNote(session, stored, asOf)}`;
281
300
  }
282
301
  /** Counts per co-mention verb, as `discussed_in 40, about 3`. */
283
302
  function coMentionSummary(edges) {
@@ -324,6 +343,104 @@ function visibleEdges(session, rows) {
324
343
  return edgeRows(rows).filter((stored) => targetVisible(session, stored.row.target));
325
344
  }
326
345
  // ---------------------------------------------------------------------------
346
+ // decision lineage
347
+ // ---------------------------------------------------------------------------
348
+ /**
349
+ * Which decisions replaced `ref` and which it replaced, from the edges the
350
+ * caller may read: open ones, or with `asOf` the ones that cover that day.
351
+ * Empty for anything that is not a decision.
352
+ */
353
+ function lineageOf(session, ref, asOf) {
354
+ const key = `${asOf ?? ""}|${ref}`;
355
+ const known = session.lineage.get(key);
356
+ if (known)
357
+ return known;
358
+ const lineage = decisionLineage((from) => visibleEdges(session, readRows(session, from, asOf ? { asOf } : {})).filter((stored) => asOf !== undefined || !stored.row.valid.to), ref, {
359
+ // Closed rows too: the status a signal wrote says what kind of link its edge is, also after a later change closed it.
360
+ statusRows: (of) => readRows(session, of).filter((stored) => stored.row.kind === "F" && stored.row.field === "status"),
361
+ live: (row) => (asOf !== undefined ? rowCoversDay(row, asOf) : !row.valid.to),
362
+ allEdges: (of) => visibleEdges(session, readRows(session, of)).filter((stored) => stored.row.verb === "superseded_by"),
363
+ });
364
+ session.lineage.set(key, lineage);
365
+ return lineage;
366
+ }
367
+ /** ` | replaced <date> by <id> [<by> <conf>]` for a line that shows `ref`, or nothing. */
368
+ function replacedNote(session, ref, asOf) {
369
+ return isDecisionRef(ref) ? replacedMarker(lineageOf(session, ref, asOf)) : "";
370
+ }
371
+ function lineageLabel(session, ref) {
372
+ const name = nameOf(session, ref);
373
+ return `${ref}${name ? ` (${clip(name, LINEAGE_NAME_MAX_CHARS)})` : ""}`;
374
+ }
375
+ function lineageCite(step) {
376
+ return `[${step.source} ${step.date} ${step.by} ${step.conf.toFixed(2)}${scope(step.audience)}${originNote(step.by)}]`;
377
+ }
378
+ /**
379
+ * One line per decision on the other end of a decision's own lineage verbs. When a rule and a model both wrote
380
+ * the same link, the edge list shows the one with the stronger origin (then the earlier day, then the lower row
381
+ * id), which is the one the lineage line cites. Other edges are passed through in their order.
382
+ */
383
+ function onePerLineagePair(edges) {
384
+ const best = new Map();
385
+ const stronger = (a, b) => (originTier(a.row.by) - originTier(b.row.by) || (a.row.valid.from < b.row.valid.from ? -1 : a.row.valid.from > b.row.valid.from ? 1 : 0) || (a.id < b.id ? -1 : 1)) < 0;
386
+ for (const stored of edges) {
387
+ if (!LINEAGE_VERBS.has(stored.row.verb) || stored.row.valid.to)
388
+ continue;
389
+ const key = `${stored.row.verb}|${stored.row.target}`;
390
+ const held = best.get(key);
391
+ if (!held || stronger(stored, held))
392
+ best.set(key, stored);
393
+ }
394
+ return edges.filter((stored) => !LINEAGE_VERBS.has(stored.row.verb) || stored.row.valid.to || best.get(`${stored.row.verb}|${stored.row.target}`) === stored);
395
+ }
396
+ /**
397
+ * The lineage lines of one decision, one line per distinct decision on the
398
+ * other end, each naming the kind: `replaced:` or `reversed:` for what ended
399
+ * it, `withdrawn:` for a withdrawal (which has a source and may have no
400
+ * replacing decision), `replaces:` or `reverses:` for what it ended, and
401
+ * `earlier link:` for a link a person's or a record's later status set aside.
402
+ * The chain after a link is appended to the same line.
403
+ */
404
+ function lineageLines(session, lineage) {
405
+ const tail = (link, word) => {
406
+ const steps = link.chain.map(word).join("");
407
+ const end = link.chainEnd === "loop"
408
+ ? " (these edges form a loop; read the sources)"
409
+ : link.chainEnd === "limit"
410
+ ? " (the chain continues; follow it with lookup)"
411
+ : "";
412
+ return `${steps}${end}`;
413
+ };
414
+ return [
415
+ ...lineage.replacedBy.map((link) => `${link.kind ?? "replaced"}: on ${link.date} by ${lineageLabel(session, link.id)} ${lineageCite(link)}${fileNote(session, link.source)}${tail(link, (step) => `, itself ${step.kind ?? "replaced"} on ${step.date} by ${lineageLabel(session, step.id)}`)}`),
416
+ ...(lineage.withdrawn ? [`withdrawn: on ${lineage.withdrawn.date} ${lineageCite(lineage.withdrawn)}${fileNote(session, lineage.withdrawn.source)}`] : []),
417
+ ...lineage.replaces.map((link) => `${link.kind === "reversed" ? "reverses" : "replaces"}: ${lineageLabel(session, link.id)} on ${link.date} ${lineageCite(link)}${fileNote(session, link.source)}${tail(link, (step) => `, which ${step.kind ?? "replaced"} ${lineageLabel(session, step.id)} on ${step.date}`)}`),
418
+ // The link is not the answer: a person or a record wrote the status after it. Both are shown with who said what.
419
+ ...(lineage.earlier ?? []).map((link) => `earlier link: marked ${link.kind ?? "replaced"} on ${link.date} by ${lineageLabel(session, link.id)} ${lineageCite(link)}, set back to ${link.setBack.status} by ${link.setBack.by} on ${link.setBack.date} [${link.setBack.source}${scope(link.setBack.audience)}]`),
420
+ ];
421
+ }
422
+ /** `replacedBy` and `replaces` for `--json`, present only when the decision has that lineage. */
423
+ function lineageFields(session, lineage) {
424
+ const names = (ref) => nameOf(session, ref);
425
+ const files = (src) => fileOf(session, src);
426
+ return {
427
+ ...(lineage.replacedBy.length > 0 ? { replacedBy: lineageJson(lineage.replacedBy, names, files) } : {}),
428
+ ...(lineage.replaces.length > 0 ? { replaces: lineageJson(lineage.replaces, names, files) } : {}),
429
+ ...lineageStatusJson(lineage, names),
430
+ };
431
+ }
432
+ /** `replacedBy: [{id, date, source, by, conf}]` for a list entry, or nothing. */
433
+ function replacedByField(session, ref, asOf) {
434
+ const lineage = lineageOf(session, ref, asOf);
435
+ return lineage.replacedBy.length > 0 ? { replacedBy: replacedByShortJson(lineage) } : {};
436
+ }
437
+ /** A decision's own lineage verbs. A line for one of these edges already says which decision replaced which. */
438
+ const LINEAGE_VERBS = new Set(["supersedes", "superseded_by"]);
439
+ /** The marker for an edge whose target is a replaced decision, or nothing. */
440
+ function targetReplacedNote(session, stored, asOf) {
441
+ return LINEAGE_VERBS.has(stored.row.verb) ? "" : replacedNote(session, stored.row.target, asOf);
442
+ }
443
+ // ---------------------------------------------------------------------------
327
444
  // lookup
328
445
  // ---------------------------------------------------------------------------
329
446
  /** `hq ontology lookup <name> [--as-of D]`. */
@@ -333,7 +450,7 @@ export async function lookupCommand(context, options) {
333
450
  return noGraph(context);
334
451
  const answer = resolve(session, options.name);
335
452
  if (answer.status !== "resolved" || !answer.entity)
336
- return unresolvedOutput(session, options.name, answer);
453
+ return unresolvedOutput(session, options.name, answer, options.asOf);
337
454
  const entity = answer.entity;
338
455
  if (options.page)
339
456
  return pageOutput(session, entity, answer);
@@ -348,7 +465,7 @@ export async function lookupCommand(context, options) {
348
465
  const facts = effectiveFacts(session.schema, entity.type, rows, options.asOf);
349
466
  const live = options.asOf ? visibleEdges(session, rows) : visibleEdges(session, rows).filter((stored) => !stored.row.valid.to);
350
467
  // Relationships only. Appearing in the same meeting or decision is counted below, not listed as an edge.
351
- const edges = live.filter((stored) => !CO_MENTION_VERBS.has(stored.row.verb)).sort(byImportance(session.schema));
468
+ const edges = onePerLineagePair(live.filter((stored) => !CO_MENTION_VERBS.has(stored.row.verb)).sort(byImportance(session.schema)));
352
469
  const together = coMentionSummary(live.filter((stored) => CO_MENTION_VERBS.has(stored.row.verb)));
353
470
  const limit = options.limit ?? LOOKUP_EDGE_LIMIT;
354
471
  const shown = edges.slice(0, limit);
@@ -357,14 +474,33 @@ export async function lookupCommand(context, options) {
357
474
  .sort((a, b) => (a.row.date < b.row.date ? 1 : a.row.date > b.row.date ? -1 : 0));
358
475
  const recent = timeline.slice(0, LOOKUP_RECENT_LIMIT);
359
476
  const thin = facts.length + edges.length + timeline.length < THIN_ROW_COUNT || (facts.length === 0 && edges.length === 0);
477
+ const lineage = lineageOf(session, entity.id, asOf);
478
+ const replacedBy = lineage.replacedBy[0];
360
479
  const lines = [
361
480
  `${entity.id} | ${entity.name}${entity.aliases.length > 0 ? ` | aka ${entity.aliases.slice(0, 4).join(", ")}` : ""} | ${answer.reason}${options.asOf ? ` | as of ${options.asOf}` : ""}`,
362
481
  ...chosenLine(answer),
482
+ // Before the facts, so a replaced decision is not read as the current one.
483
+ ...lineageLines(session, lineage),
363
484
  ];
364
485
  if (facts.length > 0) {
365
486
  lines.push("facts:");
366
- for (const stored of facts)
367
- lines.push(` ${stored.row.field} = ${stored.row.value} ${citeFact(stored)}${fileNote(session, stored.row.src)}`);
487
+ for (const stored of facts) {
488
+ const cited = `${stored.row.value} ${citeFact(stored)}${fileNote(session, stored.row.src)}`;
489
+ // The stored status of a decision a model's edge replaced is still `decided`. It is printed as replaced (or
490
+ // reversed), cited to the edge that says so (often a model's, at 0.60), and the stored value keeps its own
491
+ // citation beside it. A status the rule `signal-changes` wrote (superseded, reversed, withdrawn) already says
492
+ // so: it is printed once, with its own citation. So does a status of a person or a record that confirms the
493
+ // link (superseded, reversed, withdrawn, replaced): it is printed with their citation and the link is kept.
494
+ // A link a later status of theirs set aside (one that says the decision stands) is not in `replacedBy`, so
495
+ // that status is printed as it is.
496
+ const saysSo = endsDecision(stored.row.value) || stored.row.by === SIGNAL_CHANGES_ORIGIN;
497
+ if (replacedBy && stored.row.field === "status" && !saysSo) {
498
+ lines.push(` status = ${replacedBy.kind ?? "replaced"} ${lineageCite(replacedBy)}${fileNote(session, replacedBy.source)} (was ${cited})`);
499
+ }
500
+ else {
501
+ lines.push(` ${stored.row.field} = ${cited}`);
502
+ }
503
+ }
368
504
  }
369
505
  else {
370
506
  lines.push("facts: none recorded");
@@ -375,7 +511,7 @@ export async function lookupCommand(context, options) {
375
511
  if (shown.length > 0) {
376
512
  lines.push(`edges (${String(shown.length)} of ${String(edges.length)}):`);
377
513
  for (const stored of shown)
378
- lines.push(` ${edgeLine(session, stored)}`);
514
+ lines.push(` ${edgeLine(session, stored, asOf)}`);
379
515
  }
380
516
  if (edges.length > shown.length)
381
517
  lines.push(`more: hq ontology neighbors ${entity.id}`);
@@ -409,8 +545,9 @@ export async function lookupCommand(context, options) {
409
545
  conf: stored.row.conf,
410
546
  audience: stored.audience,
411
547
  })),
412
- edges: shown.map((stored) => edgeJson(session, stored)),
548
+ edges: shown.map((stored) => edgeJson(session, stored, asOf)),
413
549
  edgesTotal: edges.length,
550
+ ...lineageFields(session, lineage),
414
551
  coMentions: together.counts,
415
552
  recent: recent.map((stored) => ({ date: stored.row.date, type: stored.row.signalType, text: stored.row.text, src: stored.row.src, ...fileJson(session, stored.row.src), audience: stored.audience })),
416
553
  timelineTotal: timeline.length,
@@ -465,7 +602,7 @@ export async function neighborsCommand(context, options) {
465
602
  return verbs;
466
603
  const answer = resolve(session, options.id);
467
604
  if (answer.status !== "resolved" || !answer.entity)
468
- return unresolvedOutput(session, options.id, answer);
605
+ return unresolvedOutput(session, options.id, answer, options.asOf);
469
606
  const entity = answer.entity;
470
607
  if ((options.depth ?? 1) > 1) {
471
608
  return traverseCommand(context, {
@@ -481,7 +618,7 @@ export async function neighborsCommand(context, options) {
481
618
  .filter((stored) => verbs.length === 0 || verbs.includes(stored.row.verb))
482
619
  .sort(byImportance(session.schema));
483
620
  // With no verb named, only relationships are listed. Appearing in the same meeting or decision is counted.
484
- const all = verbs.length > 0 ? matching : matching.filter((stored) => !CO_MENTION_VERBS.has(stored.row.verb));
621
+ const all = onePerLineagePair(verbs.length > 0 ? matching : matching.filter((stored) => !CO_MENTION_VERBS.has(stored.row.verb)));
485
622
  const together = coMentionSummary(verbs.length > 0 ? [] : matching.filter((stored) => CO_MENTION_VERBS.has(stored.row.verb)));
486
623
  const limit = options.limit ?? DEFAULT_EDGE_LIMIT;
487
624
  const shown = all.slice(0, limit);
@@ -491,7 +628,12 @@ export async function neighborsCommand(context, options) {
491
628
  .filter((stored) => stored.row.kind === "T")
492
629
  .sort((a, b) => (a.row.date < b.row.date ? 1 : a.row.date > b.row.date ? -1 : 0))
493
630
  .slice(0, SIGNAL_LIMIT);
494
- const lines = [`${entity.id} | ${entity.name}${options.asOf ? ` | as of ${options.asOf}` : ""} | ${String(all.length)} edges`, ...chosenLine(answer)];
631
+ const lineage = lineageOf(session, entity.id, options.asOf);
632
+ const lines = [
633
+ `${entity.id} | ${entity.name}${options.asOf ? ` | as of ${options.asOf}` : ""} | ${String(all.length)} edges`,
634
+ ...chosenLine(answer),
635
+ ...lineageLines(session, lineage),
636
+ ];
495
637
  let lastVerb = "";
496
638
  for (const stored of shown) {
497
639
  if (stored.row.verb !== lastVerb) {
@@ -499,7 +641,7 @@ export async function neighborsCommand(context, options) {
499
641
  lines.push(CO_MENTION_VERBS.has(lastVerb) ? `${lastVerb} (the two appear in the same source; not a relationship, open the file to see what was said):` : `${lastVerb}:`);
500
642
  }
501
643
  const name = nameOf(session, stored.row.target);
502
- lines.push(` ${stored.row.target}${name ? ` (${name})` : ""} ${citeEdge(stored)}${fileNote(session, stored.row.src)}`);
644
+ lines.push(` ${stored.row.target}${name ? ` (${name})` : ""} ${citeEdge(stored)}${fileNote(session, stored.row.src)}${targetReplacedNote(session, stored, options.asOf)}`);
503
645
  }
504
646
  if (all.length > shown.length) {
505
647
  const rest = new Map();
@@ -525,8 +667,9 @@ export async function neighborsCommand(context, options) {
525
667
  status: "resolved",
526
668
  entity: candidateJson(entity),
527
669
  ...(options.asOf ? { asOf: options.asOf } : {}),
528
- edges: shown.map((stored) => edgeJson(session, stored)),
670
+ edges: shown.map((stored) => edgeJson(session, stored, options.asOf)),
529
671
  edgesTotal: all.length,
672
+ ...lineageFields(session, lineage),
530
673
  coMentions: together.counts,
531
674
  signals: signals.map((stored) => ({
532
675
  date: stored.row.date,
@@ -564,7 +707,7 @@ export async function searchCommand(context, options) {
564
707
  : entityFactsFromIndex(session, hit.entity).slice(0, 1).map((stored) => ({ audience: stored.audience, row: stored.row }));
565
708
  const fact = facts[0];
566
709
  const detail = fact ? ` | ${fact.row.field} = ${clip(fact.row.value, 80)} [${fact.row.src} ${fact.row.valid.from}${scope(fact.audience)}]` : "";
567
- return `${hit.entity.id} | ${hit.entity.name} | ${hit.matched}${detail}`;
710
+ return `${hit.entity.id} | ${hit.entity.name} | ${hit.matched}${detail}${replacedNote(session, hit.entity.id)}`;
568
711
  });
569
712
  return {
570
713
  text: lines.join("\n"),
@@ -578,6 +721,7 @@ export async function searchCommand(context, options) {
578
721
  ...(hit.fact
579
722
  ? { fact: { field: hit.fact.row.field, value: hit.fact.row.value, src: hit.fact.row.src, audience: hit.fact.audience } }
580
723
  : {}),
724
+ ...replacedByField(session, hit.entity.id),
581
725
  })),
582
726
  },
583
727
  };
@@ -728,12 +872,12 @@ export async function traverseCommand(context, options) {
728
872
  const depth = Math.min(3, Math.max(1, Math.trunc(options.depth) || 1));
729
873
  const from = resolve(session, options.id);
730
874
  if (from.status !== "resolved" || !from.entity)
731
- return unresolvedOutput(session, options.id, from);
875
+ return unresolvedOutput(session, options.id, from, options.asOf);
732
876
  const start = from.entity;
733
877
  if (options.to !== undefined) {
734
878
  const to = resolve(session, options.to);
735
879
  if (to.status !== "resolved" || !to.entity)
736
- return unresolvedOutput(session, options.to, to);
880
+ return unresolvedOutput(session, options.to, to, options.asOf);
737
881
  const goal = to.entity;
738
882
  const found = findPath(session, start.id, goal.id, depth, verbs, options.asOf);
739
883
  const path = found.path ?? [];
@@ -765,14 +909,14 @@ export async function traverseCommand(context, options) {
765
909
  `${start.id} -> ${goal.id} | ${String(path.length)} hops`,
766
910
  ...chosenLine(from),
767
911
  ...chosenLine(to),
768
- ...path.map((hop) => ` ${hop.from} ${edgeLine(session, hop.edge)}`),
912
+ ...path.map((hop) => ` ${hop.from} ${edgeLine(session, hop.edge, options.asOf)}`),
769
913
  ...(shared ? ["This path runs through a shared meeting, decision or document. It shows where the two appear together, not a relationship: open the file."] : []),
770
914
  ].join("\n"),
771
915
  json: {
772
916
  status: "path",
773
917
  from: start.id,
774
918
  to: goal.id,
775
- hops: path.map((hop) => ({ from: hop.from, ...edgeJson(session, hop.edge) })),
919
+ hops: path.map((hop) => ({ from: hop.from, ...edgeJson(session, hop.edge, options.asOf) })),
776
920
  },
777
921
  };
778
922
  }
@@ -781,7 +925,7 @@ export async function traverseCommand(context, options) {
781
925
  const shown = result.hops.slice(0, limit);
782
926
  const lines = [
783
927
  `${start.id} | ${start.name} | depth ${String(depth)}${verbs.length > 0 ? ` | ${verbs.join(", ")}` : ""} | ${String(result.hops.length)} reached`,
784
- ...shown.map((hop) => ` ${String(hop.depth)} ${hop.from} ${edgeLine(session, hop.edge)}`),
928
+ ...shown.map((hop) => ` ${String(hop.depth)} ${hop.from} ${edgeLine(session, hop.edge, options.asOf)}`),
785
929
  ];
786
930
  if (result.hops.length > shown.length)
787
931
  lines.push(`not shown: ${String(result.hops.length - shown.length)} (narrow with --verb)`);
@@ -796,7 +940,7 @@ export async function traverseCommand(context, options) {
796
940
  verbs,
797
941
  reached: result.hops.length,
798
942
  truncated: result.truncated,
799
- hops: shown.map((hop) => ({ depth: hop.depth, from: hop.from, ...edgeJson(session, hop.edge) })),
943
+ hops: shown.map((hop) => ({ depth: hop.depth, from: hop.from, ...edgeJson(session, hop.edge, options.asOf) })),
800
944
  },
801
945
  };
802
946
  }
@@ -0,0 +1,101 @@
1
+ import { type AudienceKey, type EdgeRow, type EntityRef, type FactRow, type IsoDate, type Origin, type SourceRef, type StoredRow } from "../types.js";
2
+ /** The origin of rows the rule `signal-changes` writes (replay/signal-changes.ts). */
3
+ export declare const SIGNAL_CHANGES_ORIGIN: Origin;
4
+ /**
5
+ * Appended to the citation of a row that rule wrote. The rule applies an entry a model wrote after reading a
6
+ * document, checked only by a quote; the note tells a reader the row is that reading, not a record.
7
+ */
8
+ export declare const SIGNAL_QUOTE_NOTE = "from a signal quote";
9
+ /** `, from a signal quote` for a row the rule `signal-changes` wrote, else nothing. */
10
+ export declare function originNote(by: Origin): string;
11
+ /** How a later decision ended an earlier one. A model's link is always `replaced`. */
12
+ export type LineageKind = "replaced" | "reversed";
13
+ /** Most decisions on one lineage line: the direct one plus the chain after it. */
14
+ export declare const LINEAGE_MAX_STEPS = 5;
15
+ export type LineageVerb = "superseded_by" | "supersedes";
16
+ /** One decision on a lineage line, with the edge that names it. */
17
+ export interface LineageStep {
18
+ id: EntityRef;
19
+ /** The day the edge is valid from: the day the newer decision was made. */
20
+ date: IsoDate;
21
+ source: SourceRef;
22
+ by: Origin;
23
+ conf: number;
24
+ audience: AudienceKey;
25
+ /** Set when the status rows were read. Absent means `replaced`. */
26
+ kind?: LineageKind;
27
+ }
28
+ /** A status row a reader cites: who said so, when and from what. */
29
+ export interface LineageStatus {
30
+ status: string;
31
+ date: IsoDate;
32
+ source: SourceRef;
33
+ by: Origin;
34
+ conf: number;
35
+ audience: AudienceKey;
36
+ }
37
+ /** A link that no longer stands, with the status a person or a record wrote after it. */
38
+ export interface EarlierLink extends LineageStep {
39
+ setBack: LineageStatus;
40
+ }
41
+ /** What the lineage needs beyond edges, read through the caller's audience filter. */
42
+ export interface LineageFacts {
43
+ /** The status rows of a decision the caller may read, open and closed. */
44
+ statusRows: (ref: EntityRef) => readonly StoredRow<FactRow>[];
45
+ /** True for a row that is current for this read: open, or covering the as-of day. */
46
+ live: (row: FactRow | EdgeRow) => boolean;
47
+ /** Every `superseded_by` edge of a decision the caller may read, closed ones too. */
48
+ allEdges?: (ref: EntityRef) => readonly StoredRow<EdgeRow>[];
49
+ }
50
+ export interface LineageLink extends LineageStep {
51
+ /** The decisions after this one along the same verb, nearest first. */
52
+ chain: LineageStep[];
53
+ /** Why the chain stopped early: it returned to a decision already on it, or it reached the step limit. */
54
+ chainEnd?: "loop" | "limit";
55
+ }
56
+ export interface Lineage {
57
+ /** Decisions that replaced this one, earliest first. */
58
+ replacedBy: LineageLink[];
59
+ /** Decisions this one replaced, earliest first. */
60
+ replaces: LineageLink[];
61
+ /** Set when the decision's current status is a withdrawal a signal states. */
62
+ withdrawn?: LineageStatus;
63
+ /** Links a person's or a record's later status set aside, earliest first. Absent when there are none. */
64
+ earlier?: EarlierLink[];
65
+ }
66
+ export declare const NO_LINEAGE: Lineage;
67
+ /** The open edges of one entity that the caller may read, with visible targets. */
68
+ export type LineageEdges = (ref: EntityRef) => readonly StoredRow<EdgeRow>[];
69
+ export declare function isDecisionRef(ref: string): boolean;
70
+ /**
71
+ * The lineage of one entity. Anything that is not a decision has none, and
72
+ * its edges are not read. Without `facts` every link is reported as it is
73
+ * stored and its kind is not set.
74
+ */
75
+ export declare function decisionLineage(edgesOf: LineageEdges, ref: EntityRef, facts?: LineageFacts): Lineage;
76
+ /**
77
+ * The short marker a list line carries for a decision that no longer stands:
78
+ * ` | replaced <date> by <id> [<by> <conf>]` (or ` | reversed ...`), with
79
+ * ` (+N more)` when several decisions replaced it, and
80
+ * ` | withdrawn <date> [<by> <conf>, from a signal quote]` for a withdrawal.
81
+ * The bracket holds the origin and confidence of the row that says so, with
82
+ * ` @<key>` when it is not company-wide, so a reader can tell a model's
83
+ * reading (`agent:sonnet 0.60`) from a rule's. A link a person's or a
84
+ * record's later status set aside carries no marker. Empty for a decision
85
+ * that stands.
86
+ */
87
+ export declare function replacedMarker(lineage: Lineage): string;
88
+ /** The fields `--json` carries for each replacing or replaced decision. */
89
+ export declare function lineageJson(list: readonly LineageLink[], nameOf: (ref: EntityRef) => string, fileOf?: (src: SourceRef) => string | null): Record<string, unknown>[];
90
+ /** `[{id, kind, date, source, by, conf}]` for a list line: the short form of `lineageJson`. */
91
+ export declare function replacedByShortJson(lineage: Lineage): {
92
+ id: EntityRef;
93
+ kind: LineageKind;
94
+ date: IsoDate;
95
+ source: SourceRef;
96
+ by: Origin;
97
+ conf: number;
98
+ }[];
99
+ /** `withdrawn` and `earlierLinks` for `--json`, present only when the decision has them. */
100
+ export declare function lineageStatusJson(lineage: Lineage, nameOf: (ref: EntityRef) => string): Record<string, unknown>;
101
+ //# sourceMappingURL=lineage.d.ts.map