@indigoai-us/hq-cli 5.345.250 → 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.
- package/CHANGELOG.md +214 -0
- package/assets/scaffold/core/scripts/hq-session.sh +9 -0
- package/contracts/host-canary-release.json +9 -3
- package/dist/command-catalog.generated.d.ts +316 -2
- package/dist/command-catalog.generated.js +389 -2
- package/dist/commands/bot.js +12 -3
- package/dist/commands/core-bucket-c-work-mesh-offer-native.js +1 -1
- package/dist/commands/core-hq-session-binding.d.ts +140 -0
- package/dist/commands/core-hq-session-binding.js +363 -0
- package/dist/commands/core-hq-session-native.d.ts +23 -0
- package/dist/commands/core-hq-session-native.js +59 -9
- package/dist/commands/core-stop-autosave.js +1 -1
- package/dist/commands/core.js +10 -0
- package/dist/commands/doctor.d.ts +5 -1
- package/dist/commands/doctor.js +42 -5
- package/dist/commands/files.js +1 -1
- package/dist/commands/install-global.js +4 -2
- package/dist/commands/lanes.d.ts +2 -0
- package/dist/commands/lanes.js +9 -4
- package/dist/commands/logout.js +4 -0
- package/dist/commands/ontology-graph.d.ts +11 -2
- package/dist/commands/ontology-graph.js +130 -4
- package/dist/commands/report.js +35 -2
- package/dist/commands/sources.js +26 -8
- package/dist/commands/storage-gate.js +1 -1
- package/dist/commands/vault-retention-flag.js +2 -1
- package/dist/commands/whoami.js +1 -1
- package/dist/hq-cloud-sync-runner/bin/sync-runner.js +238 -221
- package/dist/hq-cloud-sync-runner/package.json +1 -1
- package/dist/index.js +3 -1
- package/dist/lib/agent-kit/inbox-poll-backoff-flag.js +1 -1
- package/dist/lib/agent-kit/mcp/tools.js +48 -0
- package/dist/lib/bot/fleet-bots-update-pass.js +1 -1
- package/dist/lib/bot/fleet-cron.d.ts +37 -0
- package/dist/lib/bot/fleet-cron.js +59 -12
- package/dist/lib/bot/fleet-local.d.ts +18 -0
- package/dist/lib/bot/fleet-local.js +51 -5
- package/dist/lib/bot/inbox-poll-backoff-flag.js +1 -1
- package/dist/lib/bot/signals-engine-flag.d.ts +1 -1
- package/dist/lib/bot/signals-engine-flag.js +1 -1
- package/dist/lib/cli-invite-nudge.js +1 -1
- package/dist/lib/client-version.d.ts +2 -0
- package/dist/lib/client-version.js +24 -0
- package/dist/lib/company-flag-gate.d.ts +30 -0
- package/dist/lib/company-flag-gate.js +104 -0
- package/dist/lib/core-utils/hook-timeout-debug-context-flag.js +1 -1
- package/dist/lib/daemon/flag.js +2 -1
- package/dist/lib/daemon/legacy-journal-gate.js +3 -1
- package/dist/lib/daemon/shared-flag-reads.js +1 -1
- package/dist/lib/doctor/checks/host-core.js +22 -4
- package/dist/lib/doctor/checks/jq.d.ts +27 -6
- package/dist/lib/doctor/checks/jq.js +46 -8
- package/dist/lib/doctor/client-health-reason-codes-flag.js +1 -1
- package/dist/lib/doctor/fix/refresh-sync-handoff.d.ts +1 -1
- package/dist/lib/doctor/fix/refresh-sync-handoff.js +1 -1
- package/dist/lib/flag-client-gate-headers.d.ts +38 -0
- package/dist/lib/flag-client-gate-headers.js +62 -0
- package/dist/lib/flag-client-headers.d.ts +15 -0
- package/dist/lib/flag-client-headers.js +25 -0
- package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
- package/dist/lib/flag-registry-worker-source.generated.js +1 -1
- package/dist/lib/flag-registry-worker.js +35 -0
- package/dist/lib/flag-registry.d.ts +1 -20
- package/dist/lib/flag-registry.js +5 -81
- package/dist/lib/hook-engine/adapter-core-pin.d.ts +29 -0
- package/dist/lib/hook-engine/adapter-core-pin.js +29 -0
- package/dist/lib/hook-engine/coverage.d.ts +68 -8
- package/dist/lib/hook-engine/coverage.js +167 -25
- package/dist/lib/hook-engine/native-stop-compatibility.json +9 -4
- package/dist/lib/hook-engine/reconcile.js +3 -2
- package/dist/lib/hot-channels/graph-context.d.ts +26 -1
- package/dist/lib/hot-channels/graph-context.js +76 -9
- package/dist/lib/hot-channels/prompts/signals-pass.md +20 -0
- package/dist/lib/hot-channels/run.d.ts +1 -0
- package/dist/lib/hot-channels/signal-changes.d.ts +228 -0
- package/dist/lib/hot-channels/signal-changes.js +683 -0
- package/dist/lib/hot-channels/signals-pass.d.ts +24 -0
- package/dist/lib/hot-channels/signals-pass.js +240 -15
- package/dist/lib/lanes/outpost-worktree-pruner-flag.d.ts +1 -1
- package/dist/lib/lanes/outpost-worktree-pruner-flag.js +1 -1
- package/dist/lib/lanes/registry-flag.js +2 -1
- package/dist/lib/lanes/spawn.js +11 -1
- package/dist/lib/mesh/live/binding-intent.d.ts +61 -0
- package/dist/lib/mesh/live/binding-intent.js +201 -0
- package/dist/lib/mesh/live/binding-receipt.d.ts +157 -0
- package/dist/lib/mesh/live/binding-receipt.js +365 -0
- package/dist/lib/mesh/live/company-flag-refresh.js +1 -1
- package/dist/lib/mesh/live/daemon/doctor-telemetry.d.ts +39 -0
- package/dist/lib/mesh/live/daemon/doctor-telemetry.js +58 -0
- package/dist/lib/mesh/live/daemon/install.js +2 -1
- package/dist/lib/mesh/live/daemon/presence.js +9 -0
- package/dist/lib/mesh/live/daemon/run.d.ts +3 -0
- package/dist/lib/mesh/live/daemon/run.js +33 -1
- package/dist/lib/ontology-graph/lineage/index.d.ts +401 -0
- package/dist/lib/ontology-graph/lineage/index.js +1027 -0
- package/dist/lib/ontology-graph/model/files.d.ts +4 -0
- package/dist/lib/ontology-graph/model/files.js +23 -0
- package/dist/lib/ontology-graph/model/index.d.ts +65 -1
- package/dist/lib/ontology-graph/model/index.js +154 -18
- package/dist/lib/ontology-graph/model/pass-tasks.d.ts +84 -1
- package/dist/lib/ontology-graph/model/pass-tasks.js +173 -4
- package/dist/lib/ontology-graph/model/pass.d.ts +11 -0
- package/dist/lib/ontology-graph/model/pass.js +17 -10
- package/dist/lib/ontology-graph/model/pending-items.d.ts +39 -0
- package/dist/lib/ontology-graph/model/pending-items.js +136 -0
- package/dist/lib/ontology-graph/model/step.d.ts +47 -2
- package/dist/lib/ontology-graph/model/step.js +202 -36
- package/dist/lib/ontology-graph/model/tasks.d.ts +28 -4
- package/dist/lib/ontology-graph/model/tasks.js +48 -15
- package/dist/lib/ontology-graph/pages/render.d.ts +1 -1
- package/dist/lib/ontology-graph/pages/render.js +4 -3
- package/dist/lib/ontology-graph/read/brief.d.ts +13 -3
- package/dist/lib/ontology-graph/read/brief.js +349 -67
- package/dist/lib/ontology-graph/read/index.d.ts +5 -1
- package/dist/lib/ontology-graph/read/index.js +174 -30
- package/dist/lib/ontology-graph/read/lineage.d.ts +101 -0
- package/dist/lib/ontology-graph/read/lineage.js +262 -0
- package/dist/lib/ontology-graph/read/reader-setting.d.ts +2 -0
- package/dist/lib/ontology-graph/read/reader-setting.js +4 -1
- package/dist/lib/ontology-graph/remodel/index.d.ts +174 -0
- package/dist/lib/ontology-graph/remodel/index.js +450 -0
- package/dist/lib/ontology-graph/replay/buffered-store.js +17 -0
- package/dist/lib/ontology-graph/replay/engine.d.ts +32 -1
- package/dist/lib/ontology-graph/replay/engine.js +213 -8
- package/dist/lib/ontology-graph/replay/extractors.d.ts +26 -0
- package/dist/lib/ontology-graph/replay/extractors.js +25 -1
- package/dist/lib/ontology-graph/replay/index.d.ts +2 -0
- package/dist/lib/ontology-graph/replay/index.js +120 -8
- package/dist/lib/ontology-graph/replay/signal-changes.d.ts +118 -0
- package/dist/lib/ontology-graph/replay/signal-changes.js +687 -0
- package/dist/lib/ontology-graph/schema/authority.d.ts +14 -5
- package/dist/lib/ontology-graph/schema/authority.js +13 -3
- package/dist/lib/ontology-graph/schema/decision-status.d.ts +18 -0
- package/dist/lib/ontology-graph/schema/decision-status.js +20 -0
- package/dist/lib/ontology-graph/schema/index.d.ts +2 -1
- package/dist/lib/ontology-graph/schema/index.js +2 -1
- package/dist/lib/ontology-graph/setup/index.d.ts +88 -0
- package/dist/lib/ontology-graph/setup/index.js +499 -0
- package/dist/lib/ontology-graph/types.d.ts +21 -0
- package/dist/lib/ontology-graph/types.js +5 -0
- package/dist/lib/search-index/index.d.ts +33 -1
- package/dist/lib/search-index/index.js +180 -25
- package/dist/lib/search-index/qmd-exit-diagnostics.d.ts +7 -0
- package/dist/lib/search-index/qmd-exit-diagnostics.js +25 -1
- package/dist/lib/signals/adapters-catalog.js +1 -1
- package/dist/lib/signals/failure-alert.js +4 -5
- package/dist/lib/signals/steps/adapters.js +3 -0
- package/dist/lib/sync-core/engine-holds.d.ts +1 -0
- package/dist/lib/sync-core/engine-holds.js +26 -0
- package/dist/lib/sync-core/engine-home.d.ts +3 -0
- package/dist/lib/sync-core/engine-home.js +41 -1
- package/dist/lib/sync-core/flag.js +2 -1
- package/dist/lib/sync-core/legacy-journal-export-child.js +5 -3
- package/dist/lib/sync-core/legacy-journal-export.d.ts +23 -4
- package/dist/lib/sync-core/legacy-journal-export.js +120 -55
- package/dist/lib/sync-core/reconcile.d.ts +2 -1
- package/dist/lib/sync-core/reconcile.js +30 -5
- package/dist/lib/sync-invalid-entity-warning.js +2 -1
- package/dist/lib/windows/install-followup.d.ts +41 -0
- package/dist/lib/windows/install-followup.js +87 -0
- package/dist/lib/windows/jq.d.ts +59 -0
- package/dist/lib/windows/jq.js +154 -3
- package/dist/lib/windows/user-path.d.ts +5 -0
- package/dist/lib/windows/user-path.js +1 -1
- package/dist/lib/work-context/auto-bind.d.ts +12 -0
- package/dist/lib/work-context/auto-bind.js +49 -3
- package/dist/lib/work-context/organize.d.ts +4 -2
- package/dist/lib/work-context/organize.js +18 -8
- package/dist/lib/work-context/reconcile.js +16 -1
- package/dist/main.js +12 -1
- package/dist/utils/client-health-contract.d.ts +30 -0
- package/dist/utils/client-health-contract.js +111 -0
- package/dist/utils/client-health.d.ts +5 -2
- package/dist/utils/client-health.js +74 -5
- package/dist/utils/exclusive-lock.d.ts +5 -1
- package/dist/utils/exclusive-lock.js +9 -2
- package/dist/utils/host-registration.d.ts +7 -0
- package/dist/utils/host-registration.js +10 -1
- package/dist/utils/pid.d.ts +31 -0
- package/dist/utils/pid.js +65 -0
- package/dist/utils/resident-package-preload.js +12 -4
- package/dist/utils/sentry-fingerprint.js +3 -0
- package/dist/utils/sync-person.d.ts +15 -0
- package/dist/utils/sync-person.js +74 -0
- package/package.json +8 -8
- package/scripts/install-hook-engine.mjs +5 -3
|
@@ -26,10 +26,13 @@ import * as os from "node:os";
|
|
|
26
26
|
import * as path from "node:path";
|
|
27
27
|
import { importLegacy as defaultImportLegacy } from "../legacy/index.js";
|
|
28
28
|
import { MODEL_STATE_PATHS, createModelStep as defaultCreateModelStep, extractFromSources, extractionRows, judgeFuzzyPairs, relationshipRow, isReplayMarker, replayPending, resolveModelStateDir, resumePending, typeRelationships, } from "../model/index.js";
|
|
29
|
+
import { MODEL_TASK_NAMES, heldMarkerCounts, isHeldMarker, modelTasksLine, modelTasksNotes, modelTasksOff, peekPendingMarkers, readModelTasks } from "../model/index.js";
|
|
29
30
|
import { OntologyGraphNotImplementedError } from "../not-implemented.js";
|
|
30
31
|
import { compilePages as defaultCompilePages } from "../pages/index.js";
|
|
31
32
|
import { createResolver as defaultCreateResolver, saveResolverIndex } from "../resolve/index.js";
|
|
32
33
|
import { parseEntityRef, slugify, validateRow } from "../schema/index.js";
|
|
34
|
+
import { SIGNAL_CHANGES_STATE_RELATIVE, applySignalChanges, compareSignalChanges, decisionOfSignal, loadSignalChangesState, mergeSignalChanges, signalChangeKey, signalChangesOf, signalTimeOf, writeSignalChangesState, } from "./signal-changes.js";
|
|
35
|
+
import { audienceForInput } from "./rules.js";
|
|
33
36
|
import { GRAPH_PATHS, appendJsonLine, applyIngest, assertGraphWritableFor, graphPath, ledgerTotals, openGraphStore, readJsonLines, readUnresolved, stampGraphCompany } from "../store/index.js";
|
|
34
37
|
import { MemberIdentityRequiredError, VERBS, } from "../types.js";
|
|
35
38
|
import { briefCommand as defaultBriefCommand } from "../read/index.js";
|
|
@@ -80,6 +83,52 @@ export function resolveDayBudget(options = {}) {
|
|
|
80
83
|
const outputTokens = check("maxOutputTokens", options.maxOutputTokens, DEFAULT_DAY_BUDGET.outputTokens);
|
|
81
84
|
return { inputTokens, outputTokens, overridden: options.maxInputTokens !== undefined || options.maxOutputTokens !== undefined };
|
|
82
85
|
}
|
|
86
|
+
const SKIPPED_PREFIX = "signal_changes_skipped.";
|
|
87
|
+
/** The revision summary of a set of ledger entries, or null when none of them saw a `changes` entry. */
|
|
88
|
+
export function revisedFrom(entries) {
|
|
89
|
+
const out = { stated: 0, replaced: 0, reversed: 0, withdrawn: 0, statusClosed: 0, links: 0, modelLinksClosed: 0, rowsRemoved: 0, leftAlone: {} };
|
|
90
|
+
for (const entry of entries) {
|
|
91
|
+
for (const [name, value] of Object.entries(entry.counters ?? {})) {
|
|
92
|
+
if (name === "signal_changes")
|
|
93
|
+
out.stated += value;
|
|
94
|
+
else if (name === "signal_changes_links")
|
|
95
|
+
out.links += value;
|
|
96
|
+
else if (name === "signal_changes_status_closed")
|
|
97
|
+
out.statusClosed += value;
|
|
98
|
+
else if (name === "signal_changes_model_links_closed")
|
|
99
|
+
out.modelLinksClosed += value;
|
|
100
|
+
else if (name === "signal_changes_rows_removed")
|
|
101
|
+
out.rowsRemoved += value;
|
|
102
|
+
else if (name === "signal_changes_status.superseded")
|
|
103
|
+
out.replaced += value;
|
|
104
|
+
else if (name === "signal_changes_status.reversed")
|
|
105
|
+
out.reversed += value;
|
|
106
|
+
else if (name === "signal_changes_status.withdrawn")
|
|
107
|
+
out.withdrawn += value;
|
|
108
|
+
else if (name.startsWith(SKIPPED_PREFIX))
|
|
109
|
+
out.leftAlone[name.slice(SKIPPED_PREFIX.length)] = (out.leftAlone[name.slice(SKIPPED_PREFIX.length)] ?? 0) + value;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const wrote = out.replaced + out.reversed + out.withdrawn + out.statusClosed + out.links + out.modelLinksClosed + out.rowsRemoved;
|
|
113
|
+
return out.stated === 0 && wrote === 0 && Object.keys(out.leftAlone).length === 0 ? null : out;
|
|
114
|
+
}
|
|
115
|
+
/** The lines a run summary prints for what it revised: one for what was written, one for what was left alone. */
|
|
116
|
+
export function revisedLines(revised) {
|
|
117
|
+
const s = (n, one, many = `${one}s`) => `${String(n)} ${n === 1 ? one : many}`;
|
|
118
|
+
const lines = [];
|
|
119
|
+
// A day replayed again restates entries that are already in the graph: a run that wrote nothing prints no line for them.
|
|
120
|
+
if (revised.replaced + revised.reversed + revised.withdrawn + revised.statusClosed + revised.links + revised.modelLinksClosed + revised.rowsRemoved > 0) {
|
|
121
|
+
const more = [
|
|
122
|
+
...(revised.modelLinksClosed > 0 ? [`${s(revised.modelLinksClosed, "model link")} that pointed the other way closed`] : []),
|
|
123
|
+
...(revised.rowsRemoved > 0 ? [`${s(revised.rowsRemoved, "row")} taken out (no longer stated)`] : []),
|
|
124
|
+
];
|
|
125
|
+
lines.push(`revised: ${s(revised.replaced, "decision")} marked replaced, ${String(revised.reversed)} reversed, ${String(revised.withdrawn)} withdrawn; ${s(revised.statusClosed, "status row")} closed; ${s(revised.links, "lineage link")} written${more.map((part) => `; ${part}`).join("")}`);
|
|
126
|
+
}
|
|
127
|
+
const left = Object.entries(revised.leftAlone).filter(([, n]) => n > 0).sort((a, b) => (a[0] < b[0] ? -1 : 1));
|
|
128
|
+
if (left.length > 0)
|
|
129
|
+
lines.push(`stated changes left alone: ${left.map(([reason, n]) => `${reason} ${String(n)}`).join(", ")}`);
|
|
130
|
+
return lines;
|
|
131
|
+
}
|
|
83
132
|
const MAX_IDENTITY_PASSES = 3;
|
|
84
133
|
function fuzzyHooks(resolver) {
|
|
85
134
|
return typeof resolver.setAdjudication === "function" ? resolver : null;
|
|
@@ -230,17 +279,27 @@ function typingItemFor(input, batch) {
|
|
|
230
279
|
}
|
|
231
280
|
/** Markers WP-D's step left for a later run (`.state/model-pending.json`). 0 when there is no file. */
|
|
232
281
|
/** Markers the replay itself left pending, read from wherever the model keeps its state for this graph. */
|
|
233
|
-
function pendingModelWork(context, env) {
|
|
282
|
+
function pendingModelWork(context, env, tasks) {
|
|
234
283
|
try {
|
|
235
284
|
const file = path.join(resolveModelStateDir(context, undefined, env), ...MODEL_STATE_PATHS.pending.replace(/^\.state\//, "").split("/"));
|
|
236
285
|
const parsed = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
237
286
|
const markers = Array.isArray(parsed.markers) ? parsed.markers : parsed.markers && typeof parsed.markers === "object" ? Object.values(parsed.markers) : [];
|
|
238
|
-
|
|
287
|
+
// A marker of a task the company switched off is held, not sent: it is not work for this run.
|
|
288
|
+
return markers.filter((marker) => {
|
|
289
|
+
if (marker === null || typeof marker !== "object")
|
|
290
|
+
return false;
|
|
291
|
+
const typed = marker;
|
|
292
|
+
return isReplayMarker(typed) && !isHeldMarker(typed, tasks);
|
|
293
|
+
}).length;
|
|
239
294
|
}
|
|
240
295
|
catch {
|
|
241
296
|
return 0;
|
|
242
297
|
}
|
|
243
298
|
}
|
|
299
|
+
/** The pending file of the model step, read without opening a step. */
|
|
300
|
+
function pendingMarkersOnDisk(context, env) {
|
|
301
|
+
return peekPendingMarkers(path.join(resolveModelStateDir(context, undefined, env), ...MODEL_STATE_PATHS.pending.replace(/^\.state\//, "").split("/")));
|
|
302
|
+
}
|
|
244
303
|
function emptyTotals() {
|
|
245
304
|
return { entries: 0, rowsAdded: 0, rowsClosed: 0, entitiesCreated: 0, modelCalls: 0, cacheHits: 0, inputTokens: 0, outputTokens: 0, pending: 0, seconds: 0, counters: {} };
|
|
246
305
|
}
|
|
@@ -441,13 +500,32 @@ async function runReplay(command, context, options, deps) {
|
|
|
441
500
|
// An update lists first. With nothing new it ends here, before the resolver reads every
|
|
442
501
|
// entity: a daily run on a quiet day costs the listing and nothing else. Model work an
|
|
443
502
|
// earlier run left pending keeps the full path, so it is sent when the model is on.
|
|
503
|
+
// `model_tasks` in the company's settings/ontology.yaml. A file or a value that cannot be read switches the
|
|
504
|
+
// tasks it could have governed off (the setting fails closed) and the run says why.
|
|
505
|
+
const tasksState = deps.modelTasks
|
|
506
|
+
? { tasks: deps.modelTasks, source: "setting", problems: [], warnings: [] }
|
|
507
|
+
: readModelTasks(context.companyRoot);
|
|
508
|
+
const modelTasks = tasksState.tasks;
|
|
509
|
+
notes.push(...modelTasksNotes(tasksState));
|
|
510
|
+
if (modelTasksOff(modelTasks).length > 0) {
|
|
511
|
+
notes.push(`Model tasks switched off in settings/ontology.yaml: ${modelTasksOff(modelTasks).join(", ")}. Effective setting: ${modelTasksLine(modelTasks)}. Nothing new is collected or sent for a task that is off.`);
|
|
512
|
+
// Work an earlier run left pending for a task that is off is kept, counted and not sent.
|
|
513
|
+
const heldOnDisk = heldMarkerCounts(pendingMarkersOnDisk(effective, env), modelTasks);
|
|
514
|
+
for (const task of MODEL_TASK_NAMES) {
|
|
515
|
+
const held = heldOnDisk[task] ?? 0;
|
|
516
|
+
if (held === 0)
|
|
517
|
+
continue;
|
|
518
|
+
notes.push(`${String(held)} ${held === 1 ? "item" : "items"} pending for ${task} ${held === 1 ? "is" : "are"} held because the task is off.`);
|
|
519
|
+
bump(`model_tasks_held_${task}`, held);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
444
522
|
let listed = null;
|
|
445
523
|
let planned = null;
|
|
446
524
|
if (command === "update") {
|
|
447
525
|
listed = listCorpus();
|
|
448
526
|
planned = planDays(listed);
|
|
449
527
|
const modelIsOff = env[NO_MODEL_ENV] === "1" || options.budgetTokens === 0 || options.noModel === true || deps.modelStep === null;
|
|
450
|
-
if (planned.days.length === 0 && (modelIsOff || options.dryRun || pendingModelWork(effective, env) === 0)) {
|
|
528
|
+
if (planned.days.length === 0 && (modelIsOff || options.dryRun || pendingModelWork(effective, env, modelTasks) === 0)) {
|
|
451
529
|
if (!planned.explicitInput)
|
|
452
530
|
notes.push("Nothing new since the last run: no day was replayed.");
|
|
453
531
|
return {
|
|
@@ -706,11 +784,13 @@ async function runReplay(command, context, options, deps) {
|
|
|
706
784
|
signalled.add(cited);
|
|
707
785
|
}
|
|
708
786
|
// Model work an earlier run left pending (budget spent, usage refused) is sent first, in batches.
|
|
709
|
-
|
|
787
|
+
// The markers of a task the company switched off are not sent: they stay in the pending file.
|
|
788
|
+
const resumeTasks = { typing: modelTasks.typing, extraction: modelTasks.extraction };
|
|
789
|
+
if (batchStep && !options.dryRun && !explicitInput && replayPending(batchStep, resumeTasks).length > 0) {
|
|
710
790
|
const resumeStarted = Date.now();
|
|
711
791
|
batchStep.resetDay(today);
|
|
712
792
|
try {
|
|
713
|
-
const resumed = await resumePending(batchStep, schema, { day: today });
|
|
793
|
+
const resumed = await resumePending(batchStep, schema, { day: today, tasks: resumeTasks });
|
|
714
794
|
const verdicts = applyVerdicts(resumed.fuzzy.results);
|
|
715
795
|
const typed = applyTyped(resumed.relationships.results, null, batchStep.model);
|
|
716
796
|
const extracted = applyExtractions(resumed.extractions.results, batchStep.model);
|
|
@@ -731,6 +811,61 @@ async function runReplay(command, context, options, deps) {
|
|
|
731
811
|
notes.push(`Pending model work was not resumed (${error.name}); rules carried on.`);
|
|
732
812
|
}
|
|
733
813
|
}
|
|
814
|
+
// Every `changes` entry the replay has collected, kept in the graph folder across runs (signal-changes.ts).
|
|
815
|
+
const keptChanges = loadSignalChangesState(effective.graphRoot);
|
|
816
|
+
let signalChangeSet = keptChanges.changes;
|
|
817
|
+
// Set when the set in memory is not what the file holds, so the next day writes it and applies it.
|
|
818
|
+
let signalChangesRebuilt = false;
|
|
819
|
+
const wholeRebuild = command === "rebuild" && !options.resume && !options.from && !options.to && !options.input;
|
|
820
|
+
if (keptChanges.state !== "ok" && !wholeRebuild && cursorDay(cursor) !== null) {
|
|
821
|
+
// The file is gone or cannot be used, and this run replays only part of the signals. A set built from that
|
|
822
|
+
// part alone would give other rows than the signals state (an older change on the same decision would be
|
|
823
|
+
// missing), so the whole set is built again from every signal file this run does not replay itself; the
|
|
824
|
+
// ones it replays state their entries as their day comes.
|
|
825
|
+
const replayedHere = new Set();
|
|
826
|
+
for (const bucket of plan.values())
|
|
827
|
+
for (const input of bucket)
|
|
828
|
+
replayedHere.add(`${input.audience ?? ""}|${input.ref}|${input.relPath}`);
|
|
829
|
+
const decisionRefs = store.listEntities("decision");
|
|
830
|
+
const derived = new Map();
|
|
831
|
+
let read = 0;
|
|
832
|
+
for (const input of corpus.inputs) {
|
|
833
|
+
if (input.kind !== "signal" || !input.audience || input.date > today || replayedHere.has(`${input.audience}|${input.ref}|${input.relPath}`))
|
|
834
|
+
continue;
|
|
835
|
+
const audience = audienceForInput(input.cls ?? "", input.audience, tools.localKey);
|
|
836
|
+
if (!audience)
|
|
837
|
+
continue;
|
|
838
|
+
let frontmatter;
|
|
839
|
+
try {
|
|
840
|
+
frontmatter = corpus.read(input).frontmatter;
|
|
841
|
+
}
|
|
842
|
+
catch {
|
|
843
|
+
continue;
|
|
844
|
+
}
|
|
845
|
+
read += 1;
|
|
846
|
+
const stated = signalChangesOf(frontmatter);
|
|
847
|
+
if (stated.length === 0)
|
|
848
|
+
continue;
|
|
849
|
+
const time = signalTimeOf(frontmatter);
|
|
850
|
+
const decision = (asString(frontmatter.type) || "signal") === "decision" ? decisionOfSignal(store, audience, input.ref, decisionRefs) : null;
|
|
851
|
+
for (const change of stated) {
|
|
852
|
+
const entry = { src: input.ref, day: input.date, ...(time ? { time } : {}), audience, decision, ...change };
|
|
853
|
+
derived.set(signalChangeKey(entry), entry);
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
signalChangeSet = [...derived.values()].sort(compareSignalChanges);
|
|
857
|
+
signalChangesRebuilt = true;
|
|
858
|
+
bump("signal_changes_state_rebuilt");
|
|
859
|
+
bump("signal_changes_state_signals_read", read);
|
|
860
|
+
if (keptChanges.state === "invalid") {
|
|
861
|
+
notes.push(`The kept set of signal changes (${SIGNAL_CHANGES_STATE_RELATIVE}) could not be used: ${keptChanges.problem ?? "unknown"}. It was built again from ${String(read)} signal ${read === 1 ? "file" : "files"} (${String(signalChangeSet.length)} ${signalChangeSet.length === 1 ? "entry" : "entries"}).`);
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
else if (keptChanges.state === "invalid") {
|
|
865
|
+
notes.push(`The kept set of signal changes (${SIGNAL_CHANGES_STATE_RELATIVE}) could not be used: ${keptChanges.problem ?? "unknown"}. This rebuild collects it again from the signal files.`);
|
|
866
|
+
signalChangesRebuilt = true;
|
|
867
|
+
}
|
|
868
|
+
const signalsSeen = new Set();
|
|
734
869
|
const pendingFile = graphPath(effective.graphRoot, PENDING_RELATIVE);
|
|
735
870
|
const pendingKnown = new Set(readJsonLines(pendingFile).map((marker) => marker.cacheKey));
|
|
736
871
|
const entries = [];
|
|
@@ -879,6 +1014,9 @@ async function runReplay(command, context, options, deps) {
|
|
|
879
1014
|
const typing = [];
|
|
880
1015
|
const contradictions = [];
|
|
881
1016
|
let killed = false;
|
|
1017
|
+
// Only what this pass over the day's inputs notes is merged into the set below.
|
|
1018
|
+
tools.signalChanges = [];
|
|
1019
|
+
tools.signalsReplayed = new Set();
|
|
882
1020
|
for (const { input, document } of documents) {
|
|
883
1021
|
if (stopRequested || deps.shouldStop?.()) {
|
|
884
1022
|
killed = true;
|
|
@@ -890,7 +1028,7 @@ async function runReplay(command, context, options, deps) {
|
|
|
890
1028
|
count(`class.${input.cls}`);
|
|
891
1029
|
if (!batch)
|
|
892
1030
|
continue;
|
|
893
|
-
if (batchStep && input.kind === "source" && input.audience && !signalled.has(input.relPath) && document.body.trim() !== "") {
|
|
1031
|
+
if (batchStep && modelTasks.extraction && input.kind === "source" && input.audience && !signalled.has(input.relPath) && document.body.trim() !== "") {
|
|
894
1032
|
// No signal cites this source: the entities the rules found in it and its text go to the model.
|
|
895
1033
|
const refs = new Set();
|
|
896
1034
|
for (const { entity, row } of batch.rows) {
|
|
@@ -951,10 +1089,58 @@ async function runReplay(command, context, options, deps) {
|
|
|
951
1089
|
if (row.kind === "E")
|
|
952
1090
|
resolver.noteAudience(row.target, audience);
|
|
953
1091
|
}
|
|
954
|
-
|
|
1092
|
+
// With typing off in the company's setting no pair is collected, so none is sent and none is left pending.
|
|
1093
|
+
const item = modelTasks.typing ? typingItemFor(input, batch) : null;
|
|
955
1094
|
if (item)
|
|
956
1095
|
typing.push(item);
|
|
957
1096
|
}
|
|
1097
|
+
// Lineage the day's signals state (`changes`). The day's entries join the set kept in the graph folder and
|
|
1098
|
+
// the rule brings its rows in line with the whole set, so neither the order of two signals within a day nor
|
|
1099
|
+
// the split of the days over runs changes the rows. The last day of a run applies the set again even with no
|
|
1100
|
+
// new entry: a person's or a record's status written since then is seen. A stopped day is replayed whole.
|
|
1101
|
+
const stated = tools.signalChanges;
|
|
1102
|
+
const replayedSignals = tools.signalsReplayed;
|
|
1103
|
+
tools.signalChanges = [];
|
|
1104
|
+
tools.signalsReplayed = new Set();
|
|
1105
|
+
for (const signal of replayedSignals)
|
|
1106
|
+
signalsSeen.add(signal);
|
|
1107
|
+
if (!killed) {
|
|
1108
|
+
const merged = mergeSignalChanges(signalChangeSet, replayedSignals, stated);
|
|
1109
|
+
const setChanged = signalChangesRebuilt || JSON.stringify(merged) !== JSON.stringify(signalChangeSet);
|
|
1110
|
+
signalChangesRebuilt = false;
|
|
1111
|
+
signalChangeSet = merged;
|
|
1112
|
+
// A dry run on a store the caller passed in has no shadow folder to write to.
|
|
1113
|
+
if (setChanged && !(options.dryRun && deps.store))
|
|
1114
|
+
writeSignalChangesState(effective.graphRoot, signalChangeSet);
|
|
1115
|
+
if (signalChangeSet.length > 0 && (setChanged || stated.length > 0 || day === days[days.length - 1])) {
|
|
1116
|
+
const revised = applySignalChanges(store, signalChangeSet);
|
|
1117
|
+
entry.rowsAdded += revised.rowsAdded;
|
|
1118
|
+
entry.rowsClosed += revised.rowsClosed;
|
|
1119
|
+
if (stated.length > 0)
|
|
1120
|
+
count("signal_changes", stated.length);
|
|
1121
|
+
if (revised.links > 0)
|
|
1122
|
+
count("signal_changes_links", revised.links);
|
|
1123
|
+
if (revised.statusClosed > 0)
|
|
1124
|
+
count("signal_changes_status_closed", revised.statusClosed);
|
|
1125
|
+
for (const [status, n] of Object.entries(revised.statusBy))
|
|
1126
|
+
count(`signal_changes_status.${status}`, n);
|
|
1127
|
+
if (revised.modelLinksClosed > 0)
|
|
1128
|
+
count("signal_changes_model_links_closed", revised.modelLinksClosed);
|
|
1129
|
+
if (revised.modelLinksOtherAudience > 0)
|
|
1130
|
+
count("signal_changes_model_links_other_audience", revised.modelLinksOtherAudience);
|
|
1131
|
+
if (revised.rowsRemoved > 0)
|
|
1132
|
+
count("signal_changes_rows_removed", revised.rowsRemoved);
|
|
1133
|
+
// The reasons are counted on the day the entry was stated, once.
|
|
1134
|
+
for (const change of stated) {
|
|
1135
|
+
const key = signalChangeKey(change);
|
|
1136
|
+
const reason = revised.reasons.get(key) ?? (revised.statusHeld.has(key) ? "status_held_by_a_record_or_a_person" : null);
|
|
1137
|
+
if (reason)
|
|
1138
|
+
count(`signal_changes_skipped.${reason}`);
|
|
1139
|
+
}
|
|
1140
|
+
for (const ref of revised.touched)
|
|
1141
|
+
touchedByRun.add(ref);
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
958
1144
|
if (killed) {
|
|
959
1145
|
partial = true;
|
|
960
1146
|
stoppedBecause = stopRequested ?? "stop requested";
|
|
@@ -1097,6 +1283,21 @@ async function runReplay(command, context, options, deps) {
|
|
|
1097
1283
|
commit(day);
|
|
1098
1284
|
log(`replay: ${day} inputs ${documents.length} rows +${entry.rowsAdded} closed ${entry.rowsClosed} ${Date.now() - dayStarted} ms`);
|
|
1099
1285
|
}
|
|
1286
|
+
// A whole rebuild that read every signal drops the entries of signals that are gone, so the set is what a
|
|
1287
|
+
// rebuild into an empty folder would collect. The rows those entries wrote stay, as every other row does.
|
|
1288
|
+
if (command === "rebuild" && !partial && !options.resume && !options.from && !options.to && !options.input && days.length > 0) {
|
|
1289
|
+
const kept = signalChangeSet.filter((change) => signalsSeen.has(`${change.audience}|${change.src}`));
|
|
1290
|
+
if (kept.length !== signalChangeSet.length) {
|
|
1291
|
+
bump("signal_changes_dropped_signal_gone", signalChangeSet.length - kept.length);
|
|
1292
|
+
signalChangeSet = kept;
|
|
1293
|
+
if (!(options.dryRun && deps.store))
|
|
1294
|
+
writeSignalChangesState(effective.graphRoot, signalChangeSet);
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
// The file is there after every run that replayed a day, also when the set is empty: a missing file then means
|
|
1298
|
+
// the set was lost, not that no signal has stated a change.
|
|
1299
|
+
if (days.length > 0 && !partial && !(options.dryRun && deps.store))
|
|
1300
|
+
writeSignalChangesState(effective.graphRoot, signalChangeSet);
|
|
1100
1301
|
// Human answers again, to close or move rows the replay wrote a second time.
|
|
1101
1302
|
if (!partial && days.length > 0 && !options.input)
|
|
1102
1303
|
replayStanding("after");
|
|
@@ -1110,7 +1311,7 @@ async function runReplay(command, context, options, deps) {
|
|
|
1110
1311
|
if (compiler && !partial && changedSomething) {
|
|
1111
1312
|
const compileStarted = Date.now();
|
|
1112
1313
|
try {
|
|
1113
|
-
const compileOptions = { store: real, audiences: scope.audiences(), day: today, ...(modelOff || !model ? {} : { model }) };
|
|
1314
|
+
const compileOptions = { store: real, audiences: scope.audiences(), day: today, ...(modelOff || !model || !modelTasks.summaries ? {} : { model }) };
|
|
1114
1315
|
const compiled = await compiler(effective, compileOptions);
|
|
1115
1316
|
bump("pages_compiled", compiled.compiled);
|
|
1116
1317
|
bump("pages_compile_ms", Date.now() - compileStarted);
|
|
@@ -1164,6 +1365,7 @@ async function runReplay(command, context, options, deps) {
|
|
|
1164
1365
|
pendingOther: Math.max(0, stepTotals.pending - atDayCap - atRunBudget),
|
|
1165
1366
|
};
|
|
1166
1367
|
}
|
|
1368
|
+
const revised = revisedFrom(entries);
|
|
1167
1369
|
return {
|
|
1168
1370
|
run, command, days: entries.length,
|
|
1169
1371
|
...(entries.length > 0 ? { firstDay: entries[0].day, lastDay: entries[entries.length - 1].day } : {}),
|
|
@@ -1174,6 +1376,7 @@ async function runReplay(command, context, options, deps) {
|
|
|
1174
1376
|
inputsByClass: corpus.stats.listed, excluded: corpus.stats.excluded, scanMs: corpus.stats.scanMs,
|
|
1175
1377
|
wallMs: Date.now() - started, counters, notes,
|
|
1176
1378
|
...(modelCap ? { modelCap } : {}),
|
|
1379
|
+
...(revised ? { revised } : {}),
|
|
1177
1380
|
...(command === "update" ? { touched: [...touchedByRun].sort() } : {}),
|
|
1178
1381
|
};
|
|
1179
1382
|
}
|
|
@@ -1231,6 +1434,8 @@ export function formatReport(report) {
|
|
|
1231
1434
|
lines.push(`left out: ${excluded.map(([reason, value]) => `${reason} ${value}`).join(", ")}`);
|
|
1232
1435
|
if (report.modelCap)
|
|
1233
1436
|
lines.push(...modelCapLines(report.modelCap));
|
|
1437
|
+
if (report.revised)
|
|
1438
|
+
lines.push(...revisedLines(report.revised));
|
|
1234
1439
|
if (report.partial)
|
|
1235
1440
|
lines.push(`stopped early: ${report.stoppedBecause ?? "unknown"}. Run again with --resume.`);
|
|
1236
1441
|
for (const note of report.notes)
|
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WP-B rule extractors: one document in, one ingest batch out, no model.
|
|
3
|
+
*
|
|
4
|
+
* Every row cites the input it came from (`src`), carries the event day
|
|
5
|
+
* (`valid`, timeline date), the replay day (`learned`), an origin (`record`
|
|
6
|
+
* for a field copied from a system of record, `rule:<id>` otherwise), a
|
|
7
|
+
* confidence and the audience of its source. Names are never decided here:
|
|
8
|
+
* every name goes to WP-C's resolver, and a name it does not resolve becomes
|
|
9
|
+
* an unresolved mention, not an entity. New entities are made only from
|
|
10
|
+
* structured records (roster, PRD, board, meeting, decision, repo).
|
|
11
|
+
*
|
|
12
|
+
* Round 2 (corrections C7 and C8):
|
|
13
|
+
* - a source with no audience key is filed under the member's local audience,
|
|
14
|
+
* never `company`, unless its class is one the company publishes as a record;
|
|
15
|
+
* - a single-valued fact or edge is written once: not when the same value is
|
|
16
|
+
* already open, not when an open row outranks it;
|
|
17
|
+
* - a timeline line that repeats one already on the entity that day (the same
|
|
18
|
+
* statement, or a cut copy of it) is not written;
|
|
19
|
+
* - Slack ids the graph knows are written as names;
|
|
20
|
+
* - sessions attach to work by path, never by a word in a prompt.
|
|
21
|
+
*/
|
|
22
|
+
import { type PendingSignalChange } from "./signal-changes.js";
|
|
1
23
|
import type { AudienceKey, EntityRef, GraphStore, IsoDate, ReplayDocument, RuleExtractor } from "../types.js";
|
|
2
24
|
import { type EdgeMemo } from "./mentions.js";
|
|
3
25
|
interface OpenSingle {
|
|
@@ -40,6 +62,10 @@ export interface ExtractTools {
|
|
|
40
62
|
slackDirectoryNames: Map<string, string> | null;
|
|
41
63
|
/** Meetings a signal cites: their content is already in the graph. */
|
|
42
64
|
meetingsWithSignals: Set<EntityRef>;
|
|
65
|
+
/** `changes` entries of the signals replayed so far today; the engine applies them after the day's inputs. */
|
|
66
|
+
signalChanges: PendingSignalChange[];
|
|
67
|
+
/** Every signal replayed so far today, as `<audience>|<src>`, with or without `changes`. */
|
|
68
|
+
signalsReplayed: Set<string>;
|
|
43
69
|
/** Parsed files the rules read once per run, by path. */
|
|
44
70
|
files: Map<string, unknown>;
|
|
45
71
|
roster: RosterPerson[] | null;
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
* - Slack ids the graph knows are written as names;
|
|
20
20
|
* - sessions attach to work by path, never by a word in a prompt.
|
|
21
21
|
*/
|
|
22
|
+
import { signalChangesOf, signalTimeOf } from "./signal-changes.js";
|
|
22
23
|
import * as fs from "node:fs";
|
|
23
24
|
import * as path from "node:path";
|
|
24
25
|
import { originTier, parseEntityRef, rowId, slugify, validateRow } from "../schema/index.js";
|
|
@@ -54,6 +55,8 @@ export function createExtractTools(store, options = {}) {
|
|
|
54
55
|
slackNames: new Map(),
|
|
55
56
|
slackDirectoryNames: null,
|
|
56
57
|
meetingsWithSignals: new Set(),
|
|
58
|
+
signalChanges: [],
|
|
59
|
+
signalsReplayed: new Set(),
|
|
57
60
|
files: new Map(),
|
|
58
61
|
roster: null,
|
|
59
62
|
};
|
|
@@ -365,6 +368,23 @@ class Batch {
|
|
|
365
368
|
readAudiences() {
|
|
366
369
|
return this.audience === "company" ? ["company"] : ["company", this.audience];
|
|
367
370
|
}
|
|
371
|
+
/**
|
|
372
|
+
* Notes the `changes` a signal states, for the engine to apply once the day's inputs are in the graph
|
|
373
|
+
* (replay/signal-changes.ts). `decision` is the decision this signal produced, or null.
|
|
374
|
+
*/
|
|
375
|
+
noteSignalChanges(frontmatter, decision) {
|
|
376
|
+
if (this.tools.identityPass)
|
|
377
|
+
return;
|
|
378
|
+
const audience = this.place(this.audience);
|
|
379
|
+
if (!audience)
|
|
380
|
+
return;
|
|
381
|
+
const src = this.input.ref;
|
|
382
|
+
this.tools.signalsReplayed.add(`${audience}|${src}`);
|
|
383
|
+
const time = signalTimeOf(frontmatter);
|
|
384
|
+
for (const change of signalChangesOf(frontmatter)) {
|
|
385
|
+
this.tools.signalChanges.push({ src, day: this.day, ...(time ? { time } : {}), audience, decision, ...change });
|
|
386
|
+
}
|
|
387
|
+
}
|
|
368
388
|
fact(entity, field, value, options = {}) {
|
|
369
389
|
let text = oneLine(typeof value === "number" ? String(value) : value, 400);
|
|
370
390
|
if (!entity || text === "")
|
|
@@ -819,13 +839,17 @@ const signals = extractor("signal-entity-refs", ["signals.legacy.meeting", "sign
|
|
|
819
839
|
batch.timeline(meeting, type, content, { date: day ?? batch.day });
|
|
820
840
|
}
|
|
821
841
|
}
|
|
822
|
-
if (type !== "decision")
|
|
842
|
+
if (type !== "decision") {
|
|
843
|
+
// An action item, a commitment or a risk can withdraw an earlier decision; it links nothing.
|
|
844
|
+
batch.noteSignalChanges(fm, null);
|
|
823
845
|
return;
|
|
846
|
+
}
|
|
824
847
|
const heading = /^##\s*Decision:?\s*(.+)$/im.exec(body)?.[1] ?? content.split(/\s+/).slice(0, 10).join(" ");
|
|
825
848
|
const id = batch.input.ref.slice("signal:".length, "signal:".length + 6);
|
|
826
849
|
const decision = batch.upsert("decision", `${slugify(heading).slice(0, 60).replace(/-+$/g, "")}-${id}`, oneLine(heading, 120));
|
|
827
850
|
if (!decision)
|
|
828
851
|
return;
|
|
852
|
+
batch.noteSignalChanges(fm, decision);
|
|
829
853
|
batch.fact(decision, "statement", content);
|
|
830
854
|
batch.fact(decision, "decided_on", batch.day);
|
|
831
855
|
batch.fact(decision, "status", "decided");
|
|
@@ -15,6 +15,8 @@ export { resolveMemberScope } from "./scope.js";
|
|
|
15
15
|
export type { MemberScope } from "./scope.js";
|
|
16
16
|
export { DEFAULT_DAY_BUDGET, DayBudgetError, FULL_LISTING_ENV, LISTING_MANIFEST_RELATIVE, NO_MODEL_ENV, PENDING_RELATIVE, TYPING_PROMPT_VERSION, formatReport, modelCapLines, parseTypingReply, resolveDayBudget } from "./engine.js";
|
|
17
17
|
export type { ModelCapReport } from "./engine.js";
|
|
18
|
+
export { revisedFrom, revisedLines } from "./engine.js";
|
|
19
|
+
export type { RevisedReport } from "./engine.js";
|
|
18
20
|
export { LISTING_MANIFEST_VERSION, gitHeadCommit, openListingManifest } from "./listing-manifest.js";
|
|
19
21
|
export type { ListingManifest, ListingManifestStats } from "./listing-manifest.js";
|
|
20
22
|
export type { ReplayDeps, ReplayReport } from "./engine.js";
|