@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
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WP-E: decision lineage for the read commands and the brief.
|
|
3
|
+
*
|
|
4
|
+
* A decision that a later decision replaced carries an open `superseded_by`
|
|
5
|
+
* edge; the later one carries the inverse `supersedes` edge. The readers use
|
|
6
|
+
* this module to say so on every line that shows a decision, so a replaced
|
|
7
|
+
* decision is never printed as the current one.
|
|
8
|
+
*
|
|
9
|
+
* Rules only. Nothing here calls a model or writes to the graph: it reads the
|
|
10
|
+
* open edges the caller is allowed to see and reports them.
|
|
11
|
+
*
|
|
12
|
+
* - Several edges to the same decision count once. The row with the strongest
|
|
13
|
+
* origin is kept, then the earliest date, then the lowest row id.
|
|
14
|
+
* - A chain is followed from each replacing decision along the same verb, one
|
|
15
|
+
* decision per step (the earliest replacement), for at most
|
|
16
|
+
* `LINEAGE_MAX_STEPS` steps. A step that returns to a decision already on
|
|
17
|
+
* the chain ends it and is reported as a loop.
|
|
18
|
+
*
|
|
19
|
+
* With the status rows of the decisions (`LineageFacts`) it also says
|
|
20
|
+
*
|
|
21
|
+
* - the kind of a link the rule `signal-changes` wrote: `replaced`, or
|
|
22
|
+
* `reversed` when the status row the same signal wrote says so;
|
|
23
|
+
* - that a decision was withdrawn (an open `withdrawn` status the rule wrote),
|
|
24
|
+
* which has a source and may have no replacing decision;
|
|
25
|
+
* - that a link no longer stands: a person or a record wrote, on or after the
|
|
26
|
+
* day of a link a rule or a model wrote, a status that says the decision
|
|
27
|
+
* stands (`decided`, `active`, ...). Such a link is not reported as a
|
|
28
|
+
* replacement. It is listed under `earlier`, with the status that set the
|
|
29
|
+
* decision back and who wrote it. A status that says the decision ended
|
|
30
|
+
* (`endsDecision` in schema/decision-status.ts: superseded, reversed,
|
|
31
|
+
* withdrawn, replaced) agrees with the link, which is reported as before.
|
|
32
|
+
*/
|
|
33
|
+
import { endsDecision, originTier } from "../schema/index.js";
|
|
34
|
+
import { COMPANY_AUDIENCE } from "../types.js";
|
|
35
|
+
/** The origin of rows the rule `signal-changes` writes (replay/signal-changes.ts). */
|
|
36
|
+
export const SIGNAL_CHANGES_ORIGIN = "rule:signal-changes";
|
|
37
|
+
/**
|
|
38
|
+
* Appended to the citation of a row that rule wrote. The rule applies an entry a model wrote after reading a
|
|
39
|
+
* document, checked only by a quote; the note tells a reader the row is that reading, not a record.
|
|
40
|
+
*/
|
|
41
|
+
export const SIGNAL_QUOTE_NOTE = "from a signal quote";
|
|
42
|
+
/** `, from a signal quote` for a row the rule `signal-changes` wrote, else nothing. */
|
|
43
|
+
export function originNote(by) {
|
|
44
|
+
return by === SIGNAL_CHANGES_ORIGIN ? `, ${SIGNAL_QUOTE_NOTE}` : "";
|
|
45
|
+
}
|
|
46
|
+
/** Most decisions on one lineage line: the direct one plus the chain after it. */
|
|
47
|
+
export const LINEAGE_MAX_STEPS = 5;
|
|
48
|
+
export const NO_LINEAGE = { replacedBy: [], replaces: [] };
|
|
49
|
+
export function isDecisionRef(ref) {
|
|
50
|
+
return ref.startsWith("decision/");
|
|
51
|
+
}
|
|
52
|
+
function byCode(a, b) {
|
|
53
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
54
|
+
}
|
|
55
|
+
/** One step per distinct target of `verb`, earliest first. */
|
|
56
|
+
function distinctSteps(edges, from, verb) {
|
|
57
|
+
const best = new Map();
|
|
58
|
+
for (const stored of edges) {
|
|
59
|
+
const row = stored.row;
|
|
60
|
+
if (row.verb !== verb || row.valid.to || row.target === from || !isDecisionRef(row.target))
|
|
61
|
+
continue;
|
|
62
|
+
const held = best.get(row.target);
|
|
63
|
+
if (!held ||
|
|
64
|
+
(originTier(row.by) - originTier(held.row.by) || byCode(row.valid.from, held.row.valid.from) || byCode(stored.id, held.id)) < 0) {
|
|
65
|
+
best.set(row.target, stored);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return [...best.values()]
|
|
69
|
+
.map((stored) => ({
|
|
70
|
+
id: stored.row.target,
|
|
71
|
+
date: stored.row.valid.from,
|
|
72
|
+
source: stored.row.src,
|
|
73
|
+
by: stored.row.by,
|
|
74
|
+
conf: stored.row.conf,
|
|
75
|
+
audience: stored.audience,
|
|
76
|
+
}))
|
|
77
|
+
.sort((a, b) => byCode(a.date, b.date) || byCode(a.id, b.id));
|
|
78
|
+
}
|
|
79
|
+
function links(edgesOf, ref, own, verb) {
|
|
80
|
+
return distinctSteps(own, ref, verb).map((first) => {
|
|
81
|
+
const link = { ...first, chain: [] };
|
|
82
|
+
const seen = new Set([ref, first.id]);
|
|
83
|
+
let at = first.id;
|
|
84
|
+
for (;;) {
|
|
85
|
+
const next = distinctSteps(edgesOf(at), at, verb)[0];
|
|
86
|
+
if (!next)
|
|
87
|
+
break;
|
|
88
|
+
if (link.chain.length + 1 >= LINEAGE_MAX_STEPS) {
|
|
89
|
+
link.chainEnd = "limit";
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
link.chain.push(next);
|
|
93
|
+
if (seen.has(next.id)) {
|
|
94
|
+
link.chainEnd = "loop";
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
seen.add(next.id);
|
|
98
|
+
at = next.id;
|
|
99
|
+
}
|
|
100
|
+
return link;
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
const RULE_TIER = originTier(SIGNAL_CHANGES_ORIGIN);
|
|
104
|
+
function asStatus(stored) {
|
|
105
|
+
return { status: stored.row.value, date: stored.row.valid.from, source: stored.row.src, by: stored.row.by, conf: stored.row.conf, audience: stored.audience };
|
|
106
|
+
}
|
|
107
|
+
/** The current status a person or a record wrote on a decision, the latest one, or null. */
|
|
108
|
+
function heldStatus(facts, ref) {
|
|
109
|
+
let held = null;
|
|
110
|
+
for (const stored of facts.statusRows(ref)) {
|
|
111
|
+
if (originTier(stored.row.by) >= RULE_TIER || !facts.live(stored.row))
|
|
112
|
+
continue;
|
|
113
|
+
if (!held || byCode(stored.row.valid.from, held.row.valid.from) > 0 || (stored.row.valid.from === held.row.valid.from && stored.id < held.id))
|
|
114
|
+
held = stored;
|
|
115
|
+
}
|
|
116
|
+
return held;
|
|
117
|
+
}
|
|
118
|
+
/** `reversed` when the signal that wrote the link also wrote that status on the earlier decision, else `replaced`. */
|
|
119
|
+
function kindOf(facts, replaced, step) {
|
|
120
|
+
if (step.by !== SIGNAL_CHANGES_ORIGIN)
|
|
121
|
+
return "replaced";
|
|
122
|
+
const said = facts.statusRows(replaced).some((stored) => stored.row.by === SIGNAL_CHANGES_ORIGIN && stored.row.src === step.source && stored.row.value === "reversed");
|
|
123
|
+
return said ? "reversed" : "replaced";
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* True when a person or a record wrote, on or after the day of a rule's or a model's link, a status on the earlier
|
|
127
|
+
* decision that disagrees with the link: one that says the decision stands. A status that says it ended confirms
|
|
128
|
+
* the link, and the link is kept.
|
|
129
|
+
*/
|
|
130
|
+
function setAside(held, step) {
|
|
131
|
+
return held !== null && originTier(step.by) >= RULE_TIER && held.row.valid.from >= step.date && !endsDecision(held.row.value);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* The lineage of one entity. Anything that is not a decision has none, and
|
|
135
|
+
* its edges are not read. Without `facts` every link is reported as it is
|
|
136
|
+
* stored and its kind is not set.
|
|
137
|
+
*/
|
|
138
|
+
export function decisionLineage(edgesOf, ref, facts) {
|
|
139
|
+
if (!isDecisionRef(ref))
|
|
140
|
+
return NO_LINEAGE;
|
|
141
|
+
const own = edgesOf(ref);
|
|
142
|
+
let replacedBy = links(edgesOf, ref, own, "superseded_by");
|
|
143
|
+
let replaces = links(edgesOf, ref, own, "supersedes");
|
|
144
|
+
if (!facts)
|
|
145
|
+
return replacedBy.length === 0 && replaces.length === 0 ? NO_LINEAGE : { replacedBy, replaces };
|
|
146
|
+
const held = heldStatus(facts, ref);
|
|
147
|
+
const earlier = [];
|
|
148
|
+
const stands = [];
|
|
149
|
+
for (const link of replacedBy) {
|
|
150
|
+
const kind = kindOf(facts, ref, link);
|
|
151
|
+
if (setAside(held, link)) {
|
|
152
|
+
const { chain: _chain, chainEnd: _chainEnd, ...step } = link;
|
|
153
|
+
earlier.push({ ...step, kind, setBack: asStatus(held) });
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
stands.push({ ...link, kind, chain: link.chain.map((step, index) => ({ ...step, kind: kindOf(facts, index === 0 ? link.id : link.chain[index - 1].id, step) })) });
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
replacedBy = stands;
|
|
160
|
+
// A link the rule closed because the person's or record's status came after it is still part of the story.
|
|
161
|
+
if (held && !endsDecision(held.row.value) && facts.allEdges) {
|
|
162
|
+
for (const stored of facts.allEdges(ref)) {
|
|
163
|
+
const row = stored.row;
|
|
164
|
+
if (row.verb !== "superseded_by" || row.by !== SIGNAL_CHANGES_ORIGIN || !row.closed || row.closed.by !== held.row.src || !isDecisionRef(row.target))
|
|
165
|
+
continue;
|
|
166
|
+
if (earlier.some((link) => link.id === row.target))
|
|
167
|
+
continue;
|
|
168
|
+
const step = { id: row.target, date: row.valid.from, source: row.src, by: row.by, conf: row.conf, audience: stored.audience };
|
|
169
|
+
earlier.push({ ...step, kind: kindOf(facts, ref, step), setBack: asStatus(held) });
|
|
170
|
+
}
|
|
171
|
+
earlier.sort((a, b) => byCode(a.date, b.date) || byCode(a.id, b.id));
|
|
172
|
+
}
|
|
173
|
+
// The newer decision does not claim a decision whose status a person or a record has set since.
|
|
174
|
+
replaces = replaces
|
|
175
|
+
.filter((link) => !setAside(heldStatus(facts, link.id), link))
|
|
176
|
+
.map((link) => ({ ...link, kind: kindOf(facts, link.id, link), chain: link.chain.map((step) => ({ ...step, kind: kindOf(facts, step.id, step) })) }));
|
|
177
|
+
const lineage = { replacedBy, replaces };
|
|
178
|
+
if (held) {
|
|
179
|
+
// A person or a record says the decision was withdrawn: that is the withdrawal, cited to them.
|
|
180
|
+
if (held.row.value.trim().toLowerCase() === "withdrawn")
|
|
181
|
+
lineage.withdrawn = asStatus(held);
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
const withdrawn = facts
|
|
185
|
+
.statusRows(ref)
|
|
186
|
+
.filter((stored) => stored.row.by === SIGNAL_CHANGES_ORIGIN && stored.row.value === "withdrawn" && facts.live(stored.row))
|
|
187
|
+
.sort((a, b) => byCode(b.row.valid.from, a.row.valid.from) || byCode(a.id, b.id))[0];
|
|
188
|
+
if (withdrawn)
|
|
189
|
+
lineage.withdrawn = asStatus(withdrawn);
|
|
190
|
+
}
|
|
191
|
+
if (earlier.length > 0)
|
|
192
|
+
lineage.earlier = earlier;
|
|
193
|
+
return replacedBy.length === 0 && replaces.length === 0 && !lineage.withdrawn && !lineage.earlier ? NO_LINEAGE : lineage;
|
|
194
|
+
}
|
|
195
|
+
/** `[<by> <conf>]`, with ` @<key>` when the row is not company-wide and the note for a row the signal rule wrote. */
|
|
196
|
+
function shortCite(step) {
|
|
197
|
+
const scope = step.audience === COMPANY_AUDIENCE ? "" : ` @${step.audience}`;
|
|
198
|
+
return `[${step.by} ${step.conf.toFixed(2)}${scope}${originNote(step.by)}]`;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* The short marker a list line carries for a decision that no longer stands:
|
|
202
|
+
* ` | replaced <date> by <id> [<by> <conf>]` (or ` | reversed ...`), with
|
|
203
|
+
* ` (+N more)` when several decisions replaced it, and
|
|
204
|
+
* ` | withdrawn <date> [<by> <conf>, from a signal quote]` for a withdrawal.
|
|
205
|
+
* The bracket holds the origin and confidence of the row that says so, with
|
|
206
|
+
* ` @<key>` when it is not company-wide, so a reader can tell a model's
|
|
207
|
+
* reading (`agent:sonnet 0.60`) from a rule's. A link a person's or a
|
|
208
|
+
* record's later status set aside carries no marker. Empty for a decision
|
|
209
|
+
* that stands.
|
|
210
|
+
*/
|
|
211
|
+
export function replacedMarker(lineage) {
|
|
212
|
+
const first = lineage.replacedBy[0];
|
|
213
|
+
const more = lineage.replacedBy.length - 1;
|
|
214
|
+
const replaced = first ? ` | ${first.kind ?? "replaced"} ${first.date} by ${first.id} ${shortCite(first)}${more > 0 ? ` (+${String(more)} more)` : ""}` : "";
|
|
215
|
+
const withdrawn = lineage.withdrawn ? ` | withdrawn ${lineage.withdrawn.date} ${shortCite(lineage.withdrawn)}` : "";
|
|
216
|
+
return `${replaced}${withdrawn}`;
|
|
217
|
+
}
|
|
218
|
+
/** The fields `--json` carries for each replacing or replaced decision. */
|
|
219
|
+
export function lineageJson(list, nameOf, fileOf = () => null) {
|
|
220
|
+
return list.map((link) => {
|
|
221
|
+
const file = fileOf(link.source);
|
|
222
|
+
return {
|
|
223
|
+
id: link.id,
|
|
224
|
+
name: nameOf(link.id),
|
|
225
|
+
kind: link.kind ?? "replaced",
|
|
226
|
+
date: link.date,
|
|
227
|
+
source: link.source,
|
|
228
|
+
...(file ? { file } : {}),
|
|
229
|
+
by: link.by,
|
|
230
|
+
conf: link.conf,
|
|
231
|
+
audience: link.audience,
|
|
232
|
+
chain: link.chain.map((step) => ({ id: step.id, name: nameOf(step.id), date: step.date, source: step.source })),
|
|
233
|
+
...(link.chainEnd ? { chainEnd: link.chainEnd } : {}),
|
|
234
|
+
};
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
/** `[{id, kind, date, source, by, conf}]` for a list line: the short form of `lineageJson`. */
|
|
238
|
+
export function replacedByShortJson(lineage) {
|
|
239
|
+
return lineage.replacedBy.map((link) => ({ id: link.id, kind: link.kind ?? "replaced", date: link.date, source: link.source, by: link.by, conf: link.conf }));
|
|
240
|
+
}
|
|
241
|
+
/** `withdrawn` and `earlierLinks` for `--json`, present only when the decision has them. */
|
|
242
|
+
export function lineageStatusJson(lineage, nameOf) {
|
|
243
|
+
return {
|
|
244
|
+
...(lineage.withdrawn ? { withdrawn: { ...lineage.withdrawn } } : {}),
|
|
245
|
+
...(lineage.earlier
|
|
246
|
+
? {
|
|
247
|
+
earlierLinks: lineage.earlier.map((link) => ({
|
|
248
|
+
id: link.id,
|
|
249
|
+
name: nameOf(link.id),
|
|
250
|
+
kind: link.kind ?? "replaced",
|
|
251
|
+
date: link.date,
|
|
252
|
+
source: link.source,
|
|
253
|
+
by: link.by,
|
|
254
|
+
conf: link.conf,
|
|
255
|
+
audience: link.audience,
|
|
256
|
+
setBack: { ...link.setBack },
|
|
257
|
+
})),
|
|
258
|
+
}
|
|
259
|
+
: {}),
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
//# sourceMappingURL=lineage.js.map
|
|
@@ -6,6 +6,8 @@ export interface ReaderSetting {
|
|
|
6
6
|
company: string;
|
|
7
7
|
/** `person/<slug>` of the member, or "" when absent. */
|
|
8
8
|
member: string;
|
|
9
|
+
/** `map` or `full` when the file names one, else "" (the brief's default applies). */
|
|
10
|
+
briefStyle: "map" | "full" | "";
|
|
9
11
|
/** False when the file is missing or unreadable (the default applies). */
|
|
10
12
|
present: boolean;
|
|
11
13
|
}
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* reader: entities # entities (old files) | graph (new graph)
|
|
11
11
|
* company: indigo # company whose graph the session brief comes from
|
|
12
12
|
* member: person/<slug> # optional: the member's own entity, for the brief
|
|
13
|
+
* brief_style: map # optional: map (default) | full, the shape `hq ontology brief` writes
|
|
13
14
|
*
|
|
14
15
|
* The file is parsed line by line on purpose: the hook reads it with shell
|
|
15
16
|
* builtins and both readers must agree on what counts as a value.
|
|
@@ -17,7 +18,7 @@
|
|
|
17
18
|
import * as fs from "node:fs";
|
|
18
19
|
import * as path from "node:path";
|
|
19
20
|
export const READER_SETTING_RELATIVE = "personal/settings/ontology-reader.yaml";
|
|
20
|
-
const DEFAULT_SETTING = { reader: "entities", company: "", member: "", present: false };
|
|
21
|
+
const DEFAULT_SETTING = { reader: "entities", company: "", member: "", briefStyle: "", present: false };
|
|
21
22
|
const MAX_SETTING_BYTES = 4096;
|
|
22
23
|
export function readerSettingFile(hqRoot) {
|
|
23
24
|
return path.join(hqRoot, ...READER_SETTING_RELATIVE.split("/"));
|
|
@@ -38,6 +39,8 @@ export function parseReaderSetting(text) {
|
|
|
38
39
|
else if (key === "member") {
|
|
39
40
|
out.member = /^person\/[a-z0-9][a-z0-9._-]*$/.test(value) && !value.includes("..") ? value : "";
|
|
40
41
|
}
|
|
42
|
+
else if (key === "brief_style")
|
|
43
|
+
out.briefStyle = value === "map" || value === "full" ? value : "";
|
|
41
44
|
}
|
|
42
45
|
return out;
|
|
43
46
|
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `hq ontology remodel`: replace the rows one model wrote with what the model
|
|
3
|
+
* in use now says.
|
|
4
|
+
*
|
|
5
|
+
* Rows by two models are of the same authority, so running the pass again on a
|
|
6
|
+
* better model adds its rows beside the weaker model's and leaves those open.
|
|
7
|
+
* This command asks again, on the configured model, the questions behind the
|
|
8
|
+
* open rows written `by agent:<from>`, and closes those rows through the
|
|
9
|
+
* store's own closure (`closeRow`: the row keeps its id and its line, with
|
|
10
|
+
* `closed <day> by <ref>`; nothing is deleted).
|
|
11
|
+
*
|
|
12
|
+
* What it can ask again is what the graph pass wrote and recorded in
|
|
13
|
+
* `.state/model-rows.jsonl`: digests of meetings and threads, and profiles
|
|
14
|
+
* (role, employer, stage, contacts). For each of those rows it knows the item
|
|
15
|
+
* that produced it. A row is closed only when that item was answered in this
|
|
16
|
+
* run; an item the budget did not reach keeps its rows open for the next run.
|
|
17
|
+
* Rows the replay wrote (typed relationships, extractions), retyped edges and
|
|
18
|
+
* decision supersessions are counted and left as they are.
|
|
19
|
+
*
|
|
20
|
+
* Order: ask (model turns, nothing written), close the old rows of the
|
|
21
|
+
* answered items, write the new rows from the cached answers. The old rows are
|
|
22
|
+
* out of the way before the new ones arrive, so the new model's value is never
|
|
23
|
+
* written closed behind a weaker model's newer row.
|
|
24
|
+
*
|
|
25
|
+
* Closing and writing are two steps, so the run writes down what it is about to
|
|
26
|
+
* do first (`.state/remodel-intent.json`: the rows to close, the items behind
|
|
27
|
+
* them, the model). A run that is killed between the two leaves that file. The
|
|
28
|
+
* next run finishes the job before it does anything else: it closes what was
|
|
29
|
+
* not yet closed, writes the new rows from the cached answers, and reopens any
|
|
30
|
+
* row whose item has no usable answer after all. Only then is the file marked
|
|
31
|
+
* finished. A row is therefore never left closed with nothing asked in its place.
|
|
32
|
+
*/
|
|
33
|
+
import { type BatchModelStep, type PassTask } from "../model/index.js";
|
|
34
|
+
import { compilePages as defaultCompilePages } from "../pages/index.js";
|
|
35
|
+
import { briefCommand as defaultBriefCommand } from "../read/index.js";
|
|
36
|
+
import { type AudienceKey, type CommandOutput, type EntityRef, type GraphContext, type IsoDate, type MemberIdentity, type ModelRunner, type Origin, type RowId, type SourceRef } from "../types.js";
|
|
37
|
+
export interface RemodelOptions {
|
|
38
|
+
/** The model whose rows to replace: `haiku`, or `agent:haiku`. */
|
|
39
|
+
from: string;
|
|
40
|
+
/**
|
|
41
|
+
* Fact fields and verbs that pick what is asked again (`role_title`, `affiliation`, `works_at`). Default: every
|
|
42
|
+
* kind. An item is asked as a whole, so every row the old model wrote from the same source or the same profile
|
|
43
|
+
* is replaced with the rows that were picked.
|
|
44
|
+
*/
|
|
45
|
+
kinds?: readonly string[];
|
|
46
|
+
/** Cap on model input tokens for this run. */
|
|
47
|
+
budgetTokens?: number;
|
|
48
|
+
/** The daily cap for this run, as on `update` (`--max-input-tokens`, `--max-output-tokens`). */
|
|
49
|
+
maxInputTokens?: number;
|
|
50
|
+
maxOutputTokens?: number;
|
|
51
|
+
/** Count and estimate; call no model and write nothing. */
|
|
52
|
+
dryRun: boolean;
|
|
53
|
+
}
|
|
54
|
+
/** Seams for tests. Production passes nothing. */
|
|
55
|
+
export interface RemodelDeps {
|
|
56
|
+
runner?: ModelRunner;
|
|
57
|
+
/** The step to ask through. Default: a step on the configured model with the run's caps. */
|
|
58
|
+
step?: BatchModelStep;
|
|
59
|
+
now?: () => Date;
|
|
60
|
+
env?: NodeJS.ProcessEnv;
|
|
61
|
+
resolveMember?: (context: GraphContext) => MemberIdentity | null;
|
|
62
|
+
compilePages?: typeof defaultCompilePages | null;
|
|
63
|
+
brief?: typeof defaultBriefCommand | null;
|
|
64
|
+
/** Called after the old rows are closed and before the new ones are written. A test throws here, as a kill would. */
|
|
65
|
+
afterClose?: () => void;
|
|
66
|
+
}
|
|
67
|
+
/** Where a run writes what it is about to close and write, relative to the graph folder. */
|
|
68
|
+
export declare const REMODEL_INTENT_RELATIVE = ".state/remodel-intent.json";
|
|
69
|
+
interface IntentClosure {
|
|
70
|
+
entity: EntityRef;
|
|
71
|
+
audience: AudienceKey;
|
|
72
|
+
id: RowId;
|
|
73
|
+
on: IsoDate;
|
|
74
|
+
by: SourceRef;
|
|
75
|
+
/** The items of the pass that cover the row (`itemKeys`). */
|
|
76
|
+
items: string[];
|
|
77
|
+
/** The other end of a relationship, closed and reopened with it. */
|
|
78
|
+
inverse?: {
|
|
79
|
+
entity: EntityRef;
|
|
80
|
+
id: RowId;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/** What one run is about to close and write. On file from before the first row is closed until the last row is written. */
|
|
84
|
+
export interface RemodelIntent {
|
|
85
|
+
version: 1;
|
|
86
|
+
run: string;
|
|
87
|
+
from: Origin;
|
|
88
|
+
model: string;
|
|
89
|
+
day: IsoDate;
|
|
90
|
+
tasks: PassTask[];
|
|
91
|
+
only: EntityRef[];
|
|
92
|
+
closures: IntentClosure[];
|
|
93
|
+
/** Set when the run is complete. A file with it is history, not work to finish. */
|
|
94
|
+
finished?: string;
|
|
95
|
+
}
|
|
96
|
+
/** The intent of a run that did not finish, or null. An unreadable file is no intent: nothing in it can be trusted to close a row. */
|
|
97
|
+
export declare function readUnfinishedRemodel(graphRoot: string): RemodelIntent | null;
|
|
98
|
+
/** Thrown for a request the command cannot carry out as given. */
|
|
99
|
+
export declare class RemodelUsageError extends Error {
|
|
100
|
+
constructor(message: string);
|
|
101
|
+
}
|
|
102
|
+
export interface RemodelReport {
|
|
103
|
+
from: Origin;
|
|
104
|
+
/** The model asked now. */
|
|
105
|
+
model: string;
|
|
106
|
+
day: IsoDate;
|
|
107
|
+
dryRun: boolean;
|
|
108
|
+
kinds: string[];
|
|
109
|
+
rows: {
|
|
110
|
+
/** Open fact and relationship rows by the old model (and of the kinds asked for), both ends of a relationship counted. */
|
|
111
|
+
open: number;
|
|
112
|
+
byKind: Record<string, number>;
|
|
113
|
+
/** Of those, rows the pass wrote as a digest or a profile: the ones this command can ask about again. */
|
|
114
|
+
askable: number;
|
|
115
|
+
/** Rows with no record of the task that wrote them: the replay's typed relationships and extractions. */
|
|
116
|
+
noRecord: number;
|
|
117
|
+
/** Rows of a task that cannot be asked again from the graph (retyped edges, decision supersessions). */
|
|
118
|
+
otherTask: number;
|
|
119
|
+
/** With `kinds`: rows of other kinds that the same items wrote, replaced with them. */
|
|
120
|
+
sameItem: number;
|
|
121
|
+
};
|
|
122
|
+
/** Items (one source to digest, one entity to profile) behind the askable rows. */
|
|
123
|
+
items: {
|
|
124
|
+
total: number;
|
|
125
|
+
byTask: Partial<Record<PassTask, number>>;
|
|
126
|
+
answered: number;
|
|
127
|
+
cached: number;
|
|
128
|
+
pending: number;
|
|
129
|
+
};
|
|
130
|
+
/** Dry run: what asking would send. Input tokens are an estimate from the size of the turns. */
|
|
131
|
+
estimate?: {
|
|
132
|
+
itemsToSend: number;
|
|
133
|
+
inputTokens: number;
|
|
134
|
+
};
|
|
135
|
+
/** Rows of answered items, closed. Both ends of a relationship counted. */
|
|
136
|
+
closed: number;
|
|
137
|
+
/** Closed rows the new model stated again (same field, or same relationship). */
|
|
138
|
+
replaced: number;
|
|
139
|
+
/** Closed rows the new model did not state again when it read the same source. */
|
|
140
|
+
notRestated: number;
|
|
141
|
+
/** Askable rows whose item was not answered in this run (budget, usage limit): still open. */
|
|
142
|
+
leftOpen: number;
|
|
143
|
+
rowsAdded: number;
|
|
144
|
+
usage: {
|
|
145
|
+
inputTokens: number;
|
|
146
|
+
outputTokens: number;
|
|
147
|
+
calls: number;
|
|
148
|
+
};
|
|
149
|
+
/** Rows closed for an item that turned out to have no usable answer when the new rows were written: open again. */
|
|
150
|
+
reopened: number;
|
|
151
|
+
/** An earlier run that was interrupted between closing and writing, finished by this one before anything else. */
|
|
152
|
+
resumed?: {
|
|
153
|
+
run: string;
|
|
154
|
+
from: Origin;
|
|
155
|
+
model: string;
|
|
156
|
+
closed: number;
|
|
157
|
+
rowsAdded: number;
|
|
158
|
+
reopened: number;
|
|
159
|
+
};
|
|
160
|
+
cap: {
|
|
161
|
+
dayInputTokens: number;
|
|
162
|
+
dayOutputTokens: number;
|
|
163
|
+
overridden: boolean;
|
|
164
|
+
runInputTokens?: number;
|
|
165
|
+
};
|
|
166
|
+
halted: string | null;
|
|
167
|
+
notes: string[];
|
|
168
|
+
}
|
|
169
|
+
export declare function runRemodel(context: GraphContext, options: RemodelOptions, deps?: RemodelDeps): Promise<RemodelReport>;
|
|
170
|
+
export declare function formatRemodelReport(report: RemodelReport): string;
|
|
171
|
+
/** `hq ontology remodel`. */
|
|
172
|
+
export declare function remodelCommand(context: GraphContext, options: RemodelOptions, deps?: RemodelDeps): Promise<CommandOutput>;
|
|
173
|
+
export {};
|
|
174
|
+
//# sourceMappingURL=index.d.ts.map
|