@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
@@ -42,6 +42,60 @@ export declare function isOntologyModelName(value: unknown): value is string;
42
42
  * is no file, it does not parse, or it names none.
43
43
  */
44
44
  export declare function readModelSetting(companyRoot: string): string | null;
45
+ /**
46
+ * Which of the graph's own model tasks a company runs. Every task is on unless the company's
47
+ * `settings/ontology.yaml` turns it off:
48
+ *
49
+ * model_tasks:
50
+ * extraction: off # reading sources no signal covers (`extract-source`, and `digest` in the pass)
51
+ * typing: off # typing a relationship between two entities (`type-relationship`, and `retype`)
52
+ * summaries: on # page summaries (`summaries`), switched on its own
53
+ *
54
+ * With `extraction` and `typing` off, what the graph holds about documents comes from records and
55
+ * signals by rule. Name matching and the `profile` and `supersede` tasks are not covered by this setting.
56
+ */
57
+ export interface ModelTasksSetting {
58
+ extraction: boolean;
59
+ typing: boolean;
60
+ summaries: boolean;
61
+ }
62
+ export type ModelTaskName = keyof ModelTasksSetting;
63
+ export declare const MODEL_TASK_NAMES: readonly ModelTaskName[];
64
+ export declare const MODEL_TASKS_DEFAULT: ModelTasksSetting;
65
+ /** The setting as read, with what was wrong with the file. */
66
+ export interface ModelTasksState {
67
+ tasks: ModelTasksSetting;
68
+ /**
69
+ * `default`: no file, or a file without the key. `setting`: the file says so. `invalid`: the file or the
70
+ * key could not be read as written, and every task the unreadable part could have governed is off.
71
+ */
72
+ source: "default" | "setting" | "invalid";
73
+ /** What could not be read. Each one switched a task off. */
74
+ problems: string[];
75
+ /** What was read and ignored: a key under `model_tasks` that names no task. */
76
+ warnings: string[];
77
+ }
78
+ /**
79
+ * The `model_tasks` of the company's `settings/ontology.yaml` (also read under `ontology:`), and what was wrong
80
+ * with it. The setting fails closed: a person who wrote the key meant to switch model work off, so a file or a
81
+ * value that cannot be read switches off every task it could have governed and says why. A company with no file,
82
+ * or a file without the key, runs every task as before.
83
+ *
84
+ * - The file does not parse, or is not a mapping: all three off.
85
+ * - `model_tasks: off` or `false`: all three off. `on` or `true`: all three on.
86
+ * - `model_tasks` is anything else that is not a mapping (a list, a number, empty): all three off.
87
+ * - A task whose value is not `on`, `off`, `true` or `false`: that task off.
88
+ * - A key that names no task: a warning, and the tasks are as the other keys say.
89
+ */
90
+ export declare function readModelTasks(companyRoot: string): ModelTasksState;
91
+ /** The tasks alone. See `readModelTasks` for what an unreadable file does. */
92
+ export declare function readModelTasksSetting(companyRoot: string): ModelTasksSetting;
93
+ /** The names of the tasks a setting switches off, for a run's notes. */
94
+ export declare function modelTasksOff(setting: ModelTasksSetting): string[];
95
+ /** `extraction on, typing off, summaries on`. */
96
+ export declare function modelTasksLine(setting: ModelTasksSetting): string;
97
+ /** The lines a run or `hq ontology status` prints about a setting that could not be read as written. */
98
+ export declare function modelTasksNotes(state: ModelTasksState): string[];
45
99
  /**
46
100
  * The model the step calls. Order: the explicit option, then
47
101
  * `HQ_ONTOLOGY_MODEL`, then `model` in the company's `settings/ontology.yaml`,
@@ -50,6 +50,118 @@ export function readModelSetting(companyRoot) {
50
50
  }
51
51
  return null;
52
52
  }
53
+ export const MODEL_TASK_NAMES = ["extraction", "typing", "summaries"];
54
+ export const MODEL_TASKS_DEFAULT = { extraction: true, typing: true, summaries: true };
55
+ const MODEL_TASKS_ALL_OFF = { extraction: false, typing: false, summaries: false };
56
+ /** `on`, `off`, `true` and `false` (any letter case, or the YAML booleans). Anything else is not a value. */
57
+ function taskValue(value) {
58
+ if (value === true || value === false)
59
+ return value;
60
+ if (typeof value !== "string")
61
+ return null;
62
+ const word = value.trim().toLowerCase();
63
+ if (word === "on" || word === "true")
64
+ return true;
65
+ if (word === "off" || word === "false")
66
+ return false;
67
+ return null;
68
+ }
69
+ function shown(value) {
70
+ const text = typeof value === "string" ? value : JSON.stringify(value);
71
+ return (text ?? String(value)).slice(0, 40);
72
+ }
73
+ /**
74
+ * The `model_tasks` of the company's `settings/ontology.yaml` (also read under `ontology:`), and what was wrong
75
+ * with it. The setting fails closed: a person who wrote the key meant to switch model work off, so a file or a
76
+ * value that cannot be read switches off every task it could have governed and says why. A company with no file,
77
+ * or a file without the key, runs every task as before.
78
+ *
79
+ * - The file does not parse, or is not a mapping: all three off.
80
+ * - `model_tasks: off` or `false`: all three off. `on` or `true`: all three on.
81
+ * - `model_tasks` is anything else that is not a mapping (a list, a number, empty): all three off.
82
+ * - A task whose value is not `on`, `off`, `true` or `false`: that task off.
83
+ * - A key that names no task: a warning, and the tasks are as the other keys say.
84
+ */
85
+ export function readModelTasks(companyRoot) {
86
+ const allOff = (problem) => ({ tasks: { ...MODEL_TASKS_ALL_OFF }, source: "invalid", problems: [problem], warnings: [] });
87
+ const unchanged = () => ({ tasks: { ...MODEL_TASKS_DEFAULT }, source: "default", problems: [], warnings: [] });
88
+ let text;
89
+ try {
90
+ text = fs.readFileSync(path.join(companyRoot, ...ONTOLOGY_SETTINGS_FILE.split("/")), "utf8");
91
+ }
92
+ catch (error) {
93
+ const code = error.code;
94
+ return code === "ENOENT" || code === "ENOTDIR" ? unchanged() : allOff(`the file could not be read (${code ?? "error"})`);
95
+ }
96
+ let parsed;
97
+ try {
98
+ parsed = yaml.load(text);
99
+ }
100
+ catch (error) {
101
+ const reason = String(error.reason ?? "YAML error");
102
+ const line = error.mark?.line;
103
+ return allOff(`the file is not valid YAML (${reason}${typeof line === "number" ? `, line ${String(line + 1)}` : ""})`);
104
+ }
105
+ if (parsed === undefined || parsed === null)
106
+ return unchanged();
107
+ if (typeof parsed !== "object" || Array.isArray(parsed))
108
+ return allOff("the file is not a mapping of settings");
109
+ const record = parsed;
110
+ const nested = record.ontology && typeof record.ontology === "object" && !Array.isArray(record.ontology) ? record.ontology : {};
111
+ const has = (holder) => Object.prototype.hasOwnProperty.call(holder, "model_tasks");
112
+ if (!has(record) && !has(nested))
113
+ return unchanged();
114
+ const raw = has(record) ? record.model_tasks : nested.model_tasks;
115
+ const all = taskValue(raw);
116
+ if (all !== null)
117
+ return { tasks: all ? { ...MODEL_TASKS_DEFAULT } : { ...MODEL_TASKS_ALL_OFF }, source: "setting", problems: [], warnings: [] };
118
+ if (raw === null || raw === undefined || typeof raw !== "object" || Array.isArray(raw)) {
119
+ const what = raw === null || raw === undefined ? "empty" : Array.isArray(raw) ? "a list" : `"${shown(raw)}"`;
120
+ return allOff(`model_tasks is ${what}, not a mapping of tasks and not on or off`);
121
+ }
122
+ const set = raw;
123
+ const tasks = { ...MODEL_TASKS_DEFAULT };
124
+ const problems = [];
125
+ const warnings = [];
126
+ for (const key of Object.keys(set).sort()) {
127
+ if (!MODEL_TASK_NAMES.includes(key)) {
128
+ warnings.push(`unknown key under model_tasks: ${shown(key)} (the tasks are ${MODEL_TASK_NAMES.join(", ")})`);
129
+ continue;
130
+ }
131
+ const value = taskValue(set[key]);
132
+ if (value === null) {
133
+ tasks[key] = false;
134
+ problems.push(`model_tasks.${key} is "${shown(set[key])}", not on, off, true or false`);
135
+ }
136
+ else {
137
+ tasks[key] = value;
138
+ }
139
+ }
140
+ return { tasks, source: problems.length > 0 ? "invalid" : "setting", problems, warnings };
141
+ }
142
+ /** The tasks alone. See `readModelTasks` for what an unreadable file does. */
143
+ export function readModelTasksSetting(companyRoot) {
144
+ return readModelTasks(companyRoot).tasks;
145
+ }
146
+ /** The names of the tasks a setting switches off, for a run's notes. */
147
+ export function modelTasksOff(setting) {
148
+ return MODEL_TASK_NAMES.filter((task) => !setting[task]);
149
+ }
150
+ /** `extraction on, typing off, summaries on`. */
151
+ export function modelTasksLine(setting) {
152
+ return MODEL_TASK_NAMES.map((task) => `${task} ${setting[task] ? "on" : "off"}`).join(", ");
153
+ }
154
+ /** The lines a run or `hq ontology status` prints about a setting that could not be read as written. */
155
+ export function modelTasksNotes(state) {
156
+ const out = [];
157
+ if (state.problems.length > 0) {
158
+ const off = modelTasksOff(state.tasks);
159
+ out.push(`${ONTOLOGY_SETTINGS_FILE}: ${state.problems.join("; ")}. The setting fails closed: ${off.join(", ")} ${off.length === 1 ? "is" : "are"} off until the file is fixed.`);
160
+ }
161
+ for (const warning of state.warnings)
162
+ out.push(`${ONTOLOGY_SETTINGS_FILE}: ${warning}. The key is ignored.`);
163
+ return out;
164
+ }
53
165
  /**
54
166
  * The model the step calls. Order: the explicit option, then
55
167
  * `HQ_ONTOLOGY_MODEL`, then `model` in the company's `settings/ontology.yaml`,
@@ -161,4 +161,79 @@ export interface SupersessionAnswer {
161
161
  }
162
162
  export declare const SUPERSESSION_PROMPT_VERSION = "decision-supersession.v1";
163
163
  export declare function supersessionSpec(day: IsoDate): BatchSpec<SupersessionItem, SupersessionAnswer>;
164
+ /**
165
+ * What a decision can do to an earlier one that a link can say, as the signals pass names it (`changes[].kind`).
166
+ * A withdrawal has no later decision to link from and is not asked for: an answer that gives one is dropped.
167
+ */
168
+ export declare const LINEAGE_KINDS: readonly ["replaces", "reverses"];
169
+ export type LineageKind = (typeof LINEAGE_KINDS)[number];
170
+ /** Earlier decisions shown with one decision, at most. */
171
+ export declare const LINEAGE_MAX_CANDIDATES = 6;
172
+ /** Entries kept per decision, at most. */
173
+ export declare const LINEAGE_MAX_CHANGES = 4;
174
+ /** A quote needs this many words and characters, from either decision. */
175
+ export declare const LINEAGE_QUOTE_MIN_WORDS = 4;
176
+ export declare const LINEAGE_QUOTE_MIN_CHARS = 20;
177
+ /** Decisions per model turn. */
178
+ export declare const LINEAGE_BATCH_ITEMS = 8;
179
+ export interface LineageCandidate {
180
+ /** Graph id. Not sent to the model. */
181
+ ref: string;
182
+ date: IsoDate;
183
+ text: string;
184
+ }
185
+ export interface LineageItem {
186
+ /** Graph id of the newer decision. Not sent to the model. */
187
+ ref: string;
188
+ /** Audience folder the decision and every candidate were read from. Not sent to the model. */
189
+ audience: string;
190
+ date: IsoDate;
191
+ text: string;
192
+ /** Earlier decisions that were open on `date`, best match first. */
193
+ earlier: LineageCandidate[];
194
+ }
195
+ export interface LineageChange {
196
+ /** Index into the item's `earlier`. */
197
+ older: number;
198
+ kind: LineageKind;
199
+ /** A span of the newer decision's statement that shows the change. */
200
+ quote: string;
201
+ /** A span of the earlier decision's statement that names what is replaced. */
202
+ oldQuote: string;
203
+ }
204
+ export type LineageDropReason = "not_an_object" | "too_many" | "unknown_kind" | "target_not_shown" | "target_is_itself" | "target_not_older" | "quote_missing" | "quote_too_short" | "quote_not_in_decision" | "quote_in_both" | "old_quote_missing" | "old_quote_too_short" | "old_quote_not_in_earlier" | "old_quote_in_both" | "duplicate_target";
205
+ export interface LineageAnswer {
206
+ changes: LineageChange[];
207
+ /** Entries the host refused, by reason. */
208
+ dropped: Partial<Record<LineageDropReason, number>>;
209
+ }
210
+ export declare const LINEAGE_PROMPT_VERSION = "decision-lineage.v2";
211
+ /** What the model is sent for one item: text and dates only, so the cache key is the same in any graph built from the same sources. */
212
+ export declare function renderLineageItem(item: LineageItem): {
213
+ decision: string;
214
+ earlier: string[];
215
+ };
216
+ /**
217
+ * Checks one item's `changes` on the host. An entry is kept only when its target is one of the
218
+ * earlier decisions shown, is another decision and is dated before the item, its kind is known,
219
+ * and it quotes both texts: `q` from the newer decision's statement and `oq` from the earlier one's,
220
+ * each at least four words and twenty characters, each found in its own statement and not in the
221
+ * other. Anything else is dropped and counted by reason. A dropped entry never fails the item.
222
+ */
223
+ export declare function validateLineageAnswer(item: LineageItem, raw: Record<string, unknown>): {
224
+ ok: true;
225
+ value: LineageAnswer;
226
+ } | {
227
+ ok: false;
228
+ reason: string;
229
+ };
230
+ export declare function lineageSpec(day: IsoDate): BatchSpec<LineageItem, LineageAnswer>;
231
+ /**
232
+ * The turns a list of items would take and the input tokens they would cost, by the step's own
233
+ * rules: items and bytes per turn, bytes / 4, and the fixed overhead of a turn. Calls nothing.
234
+ */
235
+ export declare function estimateLineageTurns(items: readonly LineageItem[], overheadTokens: number): {
236
+ turns: number;
237
+ inputTokens: number;
238
+ };
164
239
  //# sourceMappingURL=pass-tasks.d.ts.map
@@ -345,4 +345,170 @@ export function supersessionSpec(day) {
345
345
  },
346
346
  };
347
347
  }
348
+ // ---------------------------------------------------------------------------
349
+ // (e) Lineage backfill: does one decision replace or reverse an earlier one
350
+ // ---------------------------------------------------------------------------
351
+ /**
352
+ * What a decision can do to an earlier one that a link can say, as the signals pass names it (`changes[].kind`).
353
+ * A withdrawal has no later decision to link from and is not asked for: an answer that gives one is dropped.
354
+ */
355
+ export const LINEAGE_KINDS = ["replaces", "reverses"];
356
+ /** Earlier decisions shown with one decision, at most. */
357
+ export const LINEAGE_MAX_CANDIDATES = 6;
358
+ /** Entries kept per decision, at most. */
359
+ export const LINEAGE_MAX_CHANGES = 4;
360
+ /** A quote needs this many words and characters, from either decision. */
361
+ export const LINEAGE_QUOTE_MIN_WORDS = 4;
362
+ export const LINEAGE_QUOTE_MIN_CHARS = 20;
363
+ /** Decisions per model turn. */
364
+ export const LINEAGE_BATCH_ITEMS = 8;
365
+ const LINEAGE_BATCH_BYTES = 40_000;
366
+ export const LINEAGE_PROMPT_VERSION = "decision-lineage.v2";
367
+ const LINEAGE_PROMPT = [
368
+ "You tidy the decision record of a company knowledge graph.",
369
+ "Each item has one `decision` (its date and text) and `earlier`: numbered decisions made before it that were still open on that date, each with its date and text.",
370
+ 'Report an entry only when the decision replaces an earlier one (it changes its terms or settles the same question differently) or reverses it (it decides the opposite): {old: number, k: "replaces"|"reverses", q, oq}.',
371
+ "`q` is 4 to 30 words copied exactly from the text of `decision` that state what is new. `oq` is 4 to 30 words copied exactly from the text of that earlier decision that state what is being replaced or reversed.",
372
+ "Each is at least 20 characters and is found only in its own text: a span that both texts hold word for word shows no change and is refused. Give no entry when you cannot quote both.",
373
+ "A decision that merely concerns the same topic, repeats an earlier one, or adds to it is not an entry. Most items have none: answer with an empty list.",
374
+ DATA_RULE,
375
+ 'Reply shape: {"results":[{"id":"i1","changes":[{"old":2,"k":"replaces","q":"...","oq":"..."}]},{"id":"i2","changes":[]}]}',
376
+ ].join("\n");
377
+ /** What the model is sent for one item: text and dates only, so the cache key is the same in any graph built from the same sources. */
378
+ export function renderLineageItem(item) {
379
+ return {
380
+ decision: `${item.date} ${clipText(item.text, 400)}`,
381
+ earlier: item.earlier.map((candidate, i) => `${i + 1}. ${candidate.date} ${clipText(candidate.text, 320)}`),
382
+ };
383
+ }
384
+ /**
385
+ * Checks one item's `changes` on the host. An entry is kept only when its target is one of the
386
+ * earlier decisions shown, is another decision and is dated before the item, its kind is known,
387
+ * and it quotes both texts: `q` from the newer decision's statement and `oq` from the earlier one's,
388
+ * each at least four words and twenty characters, each found in its own statement and not in the
389
+ * other. Anything else is dropped and counted by reason. A dropped entry never fails the item.
390
+ */
391
+ export function validateLineageAnswer(item, raw) {
392
+ if (!Array.isArray(raw.changes))
393
+ return { ok: false, reason: "changes must be a list" };
394
+ const out = { changes: [], dropped: {} };
395
+ const drop = (reason) => void (out.dropped[reason] = (out.dropped[reason] ?? 0) + 1);
396
+ const text = squash(item.text);
397
+ const seen = new Set();
398
+ for (const entry of raw.changes) {
399
+ if (entry === null || typeof entry !== "object" || Array.isArray(entry)) {
400
+ drop("not_an_object");
401
+ continue;
402
+ }
403
+ const change = entry;
404
+ const kind = LINEAGE_KINDS.includes(change.k) ? change.k : null;
405
+ if (!kind) {
406
+ drop("unknown_kind");
407
+ continue;
408
+ }
409
+ const older = typeof change.old === "number" && Number.isInteger(change.old) ? change.old - 1 : -1;
410
+ const target = item.earlier[older];
411
+ if (!target) {
412
+ drop("target_not_shown");
413
+ continue;
414
+ }
415
+ if (target.ref === item.ref) {
416
+ drop("target_is_itself");
417
+ continue;
418
+ }
419
+ if (!(target.date < item.date)) {
420
+ drop("target_not_older");
421
+ continue;
422
+ }
423
+ if (typeof change.q !== "string" || change.q.trim() === "") {
424
+ drop("quote_missing");
425
+ continue;
426
+ }
427
+ const needle = squash(change.q);
428
+ if (needle.length < LINEAGE_QUOTE_MIN_CHARS || needle.split(" ").length < LINEAGE_QUOTE_MIN_WORDS) {
429
+ drop("quote_too_short");
430
+ continue;
431
+ }
432
+ if (!text.includes(needle)) {
433
+ drop("quote_not_in_decision");
434
+ continue;
435
+ }
436
+ const earlier = squash(target.text);
437
+ // Words both statements hold say what they share, not what changed.
438
+ if (earlier.includes(needle)) {
439
+ drop("quote_in_both");
440
+ continue;
441
+ }
442
+ if (typeof change.oq !== "string" || change.oq.trim() === "") {
443
+ drop("old_quote_missing");
444
+ continue;
445
+ }
446
+ const oldNeedle = squash(change.oq);
447
+ if (oldNeedle.length < LINEAGE_QUOTE_MIN_CHARS || oldNeedle.split(" ").length < LINEAGE_QUOTE_MIN_WORDS) {
448
+ drop("old_quote_too_short");
449
+ continue;
450
+ }
451
+ if (!earlier.includes(oldNeedle)) {
452
+ drop("old_quote_not_in_earlier");
453
+ continue;
454
+ }
455
+ if (text.includes(oldNeedle)) {
456
+ drop("old_quote_in_both");
457
+ continue;
458
+ }
459
+ if (seen.has(older)) {
460
+ drop("duplicate_target");
461
+ continue;
462
+ }
463
+ if (out.changes.length >= LINEAGE_MAX_CHANGES) {
464
+ drop("too_many");
465
+ continue;
466
+ }
467
+ seen.add(older);
468
+ out.changes.push({ older, kind, quote: clipText(change.q, 240), oldQuote: clipText(change.oq, 240) });
469
+ }
470
+ return { ok: true, value: out };
471
+ }
472
+ export function lineageSpec(day) {
473
+ return {
474
+ kind: "decision-lineage",
475
+ promptVersion: LINEAGE_PROMPT_VERSION,
476
+ prompt: LINEAGE_PROMPT,
477
+ day,
478
+ maxItems: LINEAGE_BATCH_ITEMS,
479
+ maxInputBytes: LINEAGE_BATCH_BYTES,
480
+ itemKey: (item) => `lineage:${item.ref}:${sha256Hex(stableStringify(item.earlier.map((candidate) => candidate.ref))).slice(0, 10)}`,
481
+ renderItem: renderLineageItem,
482
+ validate: validateLineageAnswer,
483
+ };
484
+ }
485
+ /**
486
+ * The turns a list of items would take and the input tokens they would cost, by the step's own
487
+ * rules: items and bytes per turn, bytes / 4, and the fixed overhead of a turn. Calls nothing.
488
+ */
489
+ export function estimateLineageTurns(items, overheadTokens) {
490
+ let turns = 0;
491
+ let inputTokens = 0;
492
+ let current = [];
493
+ let bytes = 0;
494
+ const close = () => {
495
+ if (current.length === 0)
496
+ return;
497
+ const input = `{"items":[${current.map((entry, i) => `{"id":"i${String(i + 1)}","data":${entry}}`).join(",")}]}`;
498
+ turns += 1;
499
+ inputTokens += Math.ceil(Buffer.byteLength(`${LINEAGE_PROMPT}\n${input}`, "utf8") / 4) + overheadTokens;
500
+ current = [];
501
+ bytes = 0;
502
+ };
503
+ for (const item of items) {
504
+ const entry = stableStringify(renderLineageItem(item));
505
+ const size = Buffer.byteLength(entry, "utf8");
506
+ if (current.length > 0 && (current.length >= LINEAGE_BATCH_ITEMS || bytes + size > LINEAGE_BATCH_BYTES))
507
+ close();
508
+ current.push(entry);
509
+ bytes += size;
510
+ }
511
+ close();
512
+ return { turns, inputTokens };
513
+ }
348
514
  //# sourceMappingURL=pass-tasks.js.map
@@ -8,6 +8,12 @@ export declare const PASS_TASKS: readonly PassTask[];
8
8
  * output was graded against the sources (indigo, 2026-11-22), and the model that passed.
9
9
  * A caller that wants the measured choice builds a second step with this model and passes it in `taskSteps`.
10
10
  */
11
+ /** The pass tasks a company's `model_tasks` setting leaves on: `digest` is extraction, `retype` is typing. */
12
+ export declare function passTasksFor(setting: {
13
+ extraction: boolean;
14
+ typing: boolean;
15
+ summaries: boolean;
16
+ }): PassTask[];
11
17
  export declare const PASS_TASK_MODELS: Partial<Record<PassTask, string>>;
12
18
  /** One line per model-written row: what it rests on. Written beside the graph's other state files. */
13
19
  export declare const MODEL_ROWS_FILE = ".state/model-rows.jsonl";
@@ -16,7 +16,7 @@
16
16
  */
17
17
  import * as fs from "node:fs";
18
18
  import * as path from "node:path";
19
- import { effectiveFacts, isOpen, isSingleValued, originTier, parseEntityRef, rowId, slugify, validateRow } from "../schema/index.js";
19
+ import { effectiveFacts, endsDecision, isOpen, isSingleValued, originTier, parseEntityRef, rowId, slugify, validateRow } from "../schema/index.js";
20
20
  import { appendJsonLine, applyIngest, openGraphStore } from "../store/index.js";
21
21
  import { createResolver } from "../resolve/index.js";
22
22
  import { sha256Hex } from "./files.js";
@@ -28,6 +28,10 @@ export const PASS_TASKS = ["digest", "profile", "retype", "supersede", "summarie
28
28
  * output was graded against the sources (indigo, 2026-11-22), and the model that passed.
29
29
  * A caller that wants the measured choice builds a second step with this model and passes it in `taskSteps`.
30
30
  */
31
+ /** The pass tasks a company's `model_tasks` setting leaves on: `digest` is extraction, `retype` is typing. */
32
+ export function passTasksFor(setting) {
33
+ return PASS_TASKS.filter((task) => (task === "digest" ? setting.extraction : task === "retype" ? setting.typing : task === "summaries" ? setting.summaries : true));
34
+ }
31
35
  export const PASS_TASK_MODELS = { retype: "sonnet", supersede: "sonnet" };
32
36
  /** One line per model-written row: what it rests on. Written beside the graph's other state files. */
33
37
  export const MODEL_ROWS_FILE = ".state/model-rows.jsonl";
@@ -745,8 +749,11 @@ function supersessionCandidates(snapshot, report) {
745
749
  bump(report.skipped, "statement under 5 words");
746
750
  continue;
747
751
  }
748
- if (rows.some((stored) => stored.row.kind === "F" && stored.row.field === "status" && isOpen(stored.row) && stored.row.value === "superseded"))
752
+ // A decision that is already replaced, reversed or withdrawn is not asked about again.
753
+ if (rows.some((stored) => stored.row.kind === "F" && stored.row.field === "status" && isOpen(stored.row) && endsDecision(stored.row.value))) {
754
+ bump(report.skipped, "already replaced, reversed or withdrawn");
749
755
  continue;
756
+ }
750
757
  const decidedOn = rows.find((stored) => stored.row.kind === "F" && stored.row.field === "decided_on" && isOpen(stored.row));
751
758
  const date = decidedOn && decidedOn.row.kind === "F" && /^\d{4}-\d{2}-\d{2}$/.test(decidedOn.row.value) ? decidedOn.row.value : statement.row.valid.from;
752
759
  for (const stored of rows) {
@@ -21,6 +21,13 @@ export declare function isFollowUpMarker(marker: Pick<PendingMarker, "kind" | "p
21
21
  export declare function followUpEntities(marker: Pick<PendingMarker, "kind" | "promptVersion" | "payload" | "itemKey">): EntityRef[];
22
22
  /** The pass task a follow-up marker belongs to, or null. */
23
23
  export declare function followUpTask(marker: Pick<PendingMarker, "kind" | "promptVersion">): PassTask | null;
24
+ type GovernedTask = "extraction" | "typing" | "summaries";
25
+ /** The `model_tasks` setting a pending marker falls under, or null for work the setting does not govern. */
26
+ export declare function markerModelTask(marker: Pick<PendingMarker, "kind" | "promptVersion">): GovernedTask | null;
27
+ /** True for a marker whose task the setting switches off: it is kept and counted, and nothing is sent for it. */
28
+ export declare function isHeldMarker(marker: Pick<PendingMarker, "kind" | "promptVersion">, setting: Record<GovernedTask, boolean>): boolean;
29
+ /** How many pending markers each switched-off task holds. A task that is on, or holds none, is absent. */
30
+ export declare function heldMarkerCounts(markers: readonly Pick<PendingMarker, "kind" | "promptVersion">[], setting: Record<GovernedTask, boolean>): Partial<Record<GovernedTask, number>>;
24
31
  /** Every entity the follow-up markers in a list are about. */
25
32
  export declare function followUpScope(markers: readonly Pick<PendingMarker, "kind" | "promptVersion" | "payload" | "itemKey">[]): Set<EntityRef>;
26
33
  /**
@@ -28,4 +35,5 @@ export declare function followUpScope(markers: readonly Pick<PendingMarker, "kin
28
35
  * read, for a run that has to decide whether there is anything to do. An unreadable file is empty.
29
36
  */
30
37
  export declare function peekPendingMarkers(file: string): PendingMarker[];
38
+ export {};
31
39
  //# sourceMappingURL=pending-items.d.ts.map
@@ -13,7 +13,7 @@
13
13
  */
14
14
  import { isEntityRef } from "../schema/index.js";
15
15
  import { readTextIfPresent } from "./files.js";
16
- import { digestSpec, profileSpec, retypeSpec, supersessionSpec } from "./pass-tasks.js";
16
+ import { digestSpec, lineageSpec, profileSpec, retypeSpec, supersessionSpec } from "./pass-tasks.js";
17
17
  import { promptFamily } from "./step.js";
18
18
  import { extractSourceSpec, fuzzySpec, isReplayMarker, relationshipSpec, summarizeSpec } from "./tasks.js";
19
19
  /** The day a spec charges its calls to plays no part in how it renders an item. */
@@ -30,6 +30,7 @@ export function pendingItemRenderer(schema) {
30
30
  profileSpec(ANY_DAY),
31
31
  retypeSpec(ANY_DAY),
32
32
  supersessionSpec(ANY_DAY),
33
+ lineageSpec(ANY_DAY),
33
34
  ]) {
34
35
  specs.set(promptFamily(spec.promptVersion), spec);
35
36
  }
@@ -86,6 +87,28 @@ export function followUpTask(marker) {
86
87
  return null;
87
88
  return FOLLOW_UP_TASK[promptFamily(String(marker.promptVersion ?? ""))] ?? null;
88
89
  }
90
+ /** The `model_tasks` setting a pending marker falls under, or null for work the setting does not govern. */
91
+ export function markerModelTask(marker) {
92
+ if (isReplayMarker(marker))
93
+ return marker.kind === "type-relationship" ? "typing" : marker.kind === "extract-source" ? "extraction" : null;
94
+ const task = followUpTask(marker);
95
+ return task === "digest" ? "extraction" : task === "retype" ? "typing" : task === "summaries" ? "summaries" : null;
96
+ }
97
+ /** True for a marker whose task the setting switches off: it is kept and counted, and nothing is sent for it. */
98
+ export function isHeldMarker(marker, setting) {
99
+ const task = markerModelTask(marker);
100
+ return task !== null && !setting[task];
101
+ }
102
+ /** How many pending markers each switched-off task holds. A task that is on, or holds none, is absent. */
103
+ export function heldMarkerCounts(markers, setting) {
104
+ const counts = {};
105
+ for (const marker of markers) {
106
+ const task = markerModelTask(marker);
107
+ if (task !== null && !setting[task])
108
+ counts[task] = (counts[task] ?? 0) + 1;
109
+ }
110
+ return counts;
111
+ }
89
112
  /** Every entity the follow-up markers in a list are about. */
90
113
  export function followUpScope(markers) {
91
114
  const scope = new Set();
@@ -27,7 +27,7 @@
27
27
  */
28
28
  import type { IsoDate, ModelBudget, ModelRunner, ModelStep, ModelStepKind, ModelUsage } from "../types.js";
29
29
  /** The contract's kinds plus the graph pass's own (pass-tasks.ts). The kind is part of the cache key and names the task in the call ledger. */
30
- export type ModelTaskKind = ModelStepKind | "extract-source" | "digest-source" | "profile-entity" | "retype-edge" | "decision-supersession";
30
+ export type ModelTaskKind = ModelStepKind | "extract-source" | "digest-source" | "profile-entity" | "retype-edge" | "decision-supersession" | "decision-lineage";
31
31
  export type PendingReason = "budget-day" | "budget-run" | "dry-run" | "usage-limit" | "logged-out" | "timeout" | "provider-error";
32
32
  /** Left for the next run when an item could not be sent. */
33
33
  export interface PendingMarker {
@@ -186,14 +186,22 @@ export interface ResumedPending {
186
186
  * handed to a replay task has the wrong shape.
187
187
  */
188
188
  export declare function isReplayMarker(marker: Pick<PendingMarker, "kind" | "promptVersion">): boolean;
189
- /** The pending markers `resumePending` will send. */
190
- export declare function replayPending(step: BatchModelStep): PendingMarker[];
189
+ /** Which of the replay's own tasks a company's `model_tasks` setting leaves on. Absent: both. */
190
+ export interface ResumeTasks {
191
+ typing: boolean;
192
+ extraction: boolean;
193
+ }
194
+ /** The pending markers `resumePending` will send: the replay's own, less those of a task that is switched off. */
195
+ export declare function replayPending(step: BatchModelStep, tasks?: ResumeTasks): PendingMarker[];
191
196
  /**
192
197
  * Sends the items earlier runs left pending, under today's budget. The caller
193
198
  * applies the results as it would for fresh items. Markers that still do not
194
- * fit stay pending.
199
+ * fit stay pending. With `tasks`, the markers of a task that is switched off
200
+ * are not sent and not touched: they stay in the pending file until the task
201
+ * is on again.
195
202
  */
196
203
  export declare function resumePending(step: BatchModelStep, schema: GraphSchema, options: {
197
204
  day: IsoDate;
205
+ tasks?: ResumeTasks;
198
206
  }): Promise<ResumedPending>;
199
207
  //# sourceMappingURL=tasks.d.ts.map
@@ -349,20 +349,33 @@ export function isReplayMarker(marker) {
349
349
  return version.startsWith("extract-source.");
350
350
  return false;
351
351
  }
352
- /** The pending markers `resumePending` will send. */
353
- export function replayPending(step) {
354
- return step.pending().filter(isReplayMarker);
352
+ /** The pending markers `resumePending` will send: the replay's own, less those of a task that is switched off. */
353
+ export function replayPending(step, tasks) {
354
+ return step.pending().filter((marker) => {
355
+ if (!isReplayMarker(marker))
356
+ return false;
357
+ if (marker.kind === "type-relationship")
358
+ return tasks?.typing !== false;
359
+ if (marker.kind === "extract-source")
360
+ return tasks?.extraction !== false;
361
+ return true;
362
+ });
355
363
  }
356
364
  /**
357
365
  * Sends the items earlier runs left pending, under today's budget. The caller
358
366
  * applies the results as it would for fresh items. Markers that still do not
359
- * fit stay pending.
367
+ * fit stay pending. With `tasks`, the markers of a task that is switched off
368
+ * are not sent and not touched: they stay in the pending file until the task
369
+ * is on again.
360
370
  */
361
371
  export async function resumePending(step, schema, options) {
362
372
  const own = (kind) => step.pending(kind).filter(isReplayMarker);
363
- const relationships = await typeRelationships(step, schema, payloads(own("type-relationship")), options);
364
- const fuzzy = await judgeFuzzyPairs(step, payloads(own("resolve-fuzzy")), options);
365
- const extractions = await extractFromSources(step, schema, payloads(own("extract-source")).filter((item) => Array.isArray(item.entities) && typeof item.text === "string"), options);
373
+ const day = { day: options.day };
374
+ const relationships = await typeRelationships(step, schema, options.tasks?.typing === false ? [] : payloads(own("type-relationship")), day);
375
+ const fuzzy = await judgeFuzzyPairs(step, payloads(own("resolve-fuzzy")), day);
376
+ const extractions = await extractFromSources(step, schema, options.tasks?.extraction === false
377
+ ? []
378
+ : payloads(own("extract-source")).filter((item) => Array.isArray(item.entities) && typeof item.text === "string"), day);
366
379
  const summaryEntities = [...new Set(step.pending("summarize-page").map((marker) => marker.itemKey).filter(isEntityRef))].sort();
367
380
  return { relationships, fuzzy, extractions, summaryEntities };
368
381
  }