@indigoai-us/hq-cli 5.345.246 → 5.345.248
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 +63 -0
- package/assets/lanes-hooks/hq-lanes-drain.sh +1 -1
- package/contracts/host-canary-release.json +14 -0
- package/dist/command-catalog.generated.d.ts +1116 -3
- package/dist/command-catalog.generated.js +1373 -3
- package/dist/command-registration-plan.d.ts +6 -0
- package/dist/command-registration-plan.js +1 -0
- package/dist/commands/install-global.d.ts +15 -0
- package/dist/commands/install-global.js +98 -4
- package/dist/commands/lanes-hold.js +7 -7
- package/dist/commands/lanes-resume.js +2 -2
- package/dist/commands/lanes-review.js +1 -1
- package/dist/commands/lanes-session-start.d.ts +1 -1
- package/dist/commands/lanes-session-start.js +3 -3
- package/dist/commands/lanes-shared.d.ts +1 -1
- package/dist/commands/lanes.d.ts +2 -2
- package/dist/commands/lanes.js +50 -50
- package/dist/commands/mcp-registration.d.ts +17 -0
- package/dist/commands/mcp-registration.js +119 -0
- package/dist/commands/mesh.d.ts +25 -0
- package/dist/commands/mesh.js +48 -8
- package/dist/commands/ontology-graph.d.ts +62 -0
- package/dist/commands/ontology-graph.js +439 -0
- package/dist/commands/pkg-install.js +1 -1
- package/dist/commands/reindex.js +1 -1
- package/dist/index.js +1 -1
- package/dist/lanes-monitor-check-argv.d.ts +1 -1
- package/dist/lanes-monitor-check-argv.js +1 -1
- package/dist/lanes-monitor-check-fast.d.ts +1 -1
- package/dist/lanes-monitor-check-fast.js +1 -1
- package/dist/lanes-session-start-argv.d.ts +1 -1
- package/dist/lanes-session-start-argv.js +1 -1
- package/dist/lib/capacity/sign-in.d.ts +1 -1
- package/dist/lib/capacity/sign-in.js +1 -1
- package/dist/lib/daemon/hook-requests-conduct-link.js +2 -2
- package/dist/lib/daemon/lanes-monitor-state.d.ts +2 -2
- package/dist/lib/daemon/lanes-monitor-state.js +2 -2
- package/dist/lib/daemon/merge-sections.d.ts +3 -3
- package/dist/lib/daemon/merge-sections.js +7 -7
- package/dist/lib/daemon/remote-control-pools.js +1 -1
- package/dist/lib/daemon/run.js +1 -1
- package/dist/lib/daemon/state-file.d.ts +1 -1
- package/dist/lib/daemon/state-file.js +1 -1
- package/dist/lib/doctor/checks/antigravity-wiring.d.ts +21 -0
- package/dist/lib/doctor/checks/antigravity-wiring.js +75 -0
- package/dist/lib/doctor/checks/anywhere.js +30 -0
- package/dist/lib/doctor/checks/runtime-probe.js +13 -0
- package/dist/lib/doctor/platform.d.ts +1 -1
- package/dist/lib/doctor/platform.js +5 -0
- package/dist/lib/doctor/registry.js +3 -0
- package/dist/lib/flag-snapshot-file.d.ts +2 -0
- package/dist/lib/flag-snapshot-file.js +118 -48
- package/dist/lib/hook-engine/canary-gate.d.ts +57 -3
- package/dist/lib/hook-engine/canary-gate.js +138 -6
- package/dist/lib/hook-engine/coverage.d.ts +91 -0
- package/dist/lib/hook-engine/coverage.js +184 -0
- package/dist/lib/hot-channels/graph-context.d.ts +105 -0
- package/dist/lib/hot-channels/graph-context.js +377 -0
- package/dist/lib/hot-channels/signals-pass.js +27 -1
- package/dist/lib/install/antigravity-targets.d.ts +39 -0
- package/dist/lib/install/antigravity-targets.js +122 -0
- package/dist/lib/lanes/claude-credential.d.ts +1 -1
- package/dist/lib/lanes/claude-credential.js +1 -1
- package/dist/lib/lanes/delivery-core.d.ts +1 -1
- package/dist/lib/lanes/delivery-core.js +1 -1
- package/dist/lib/lanes/delivery.d.ts +10 -10
- package/dist/lib/lanes/delivery.js +8 -8
- package/dist/lib/lanes/dropbox.d.ts +1 -1
- package/dist/lib/lanes/dropbox.js +1 -1
- package/dist/lib/lanes/hooks-install.js +2 -2
- package/dist/lib/lanes/index.d.ts +1 -1
- package/dist/lib/lanes/index.js +1 -1
- package/dist/lib/lanes/monitor.js +1 -1
- package/dist/lib/lanes/quota-notice.js +1 -1
- package/dist/lib/lanes/quota.d.ts +1 -1
- package/dist/lib/lanes/quota.js +1 -1
- package/dist/lib/lanes/repo-merge-hold.d.ts +2 -2
- package/dist/lib/lanes/repo-merge-hold.js +2 -2
- package/dist/lib/lanes/spawn.d.ts +4 -4
- package/dist/lib/lanes/spawn.js +5 -5
- package/dist/lib/mesh/live/company-flag-refresh.d.ts +61 -0
- package/dist/lib/mesh/live/company-flag-refresh.js +159 -0
- package/dist/lib/mesh/live/company-reporting-gaps.d.ts +61 -0
- package/dist/lib/mesh/live/company-reporting-gaps.js +238 -0
- package/dist/lib/mesh/live/daemon/duplicate-unit.d.ts +156 -0
- package/dist/lib/mesh/live/daemon/duplicate-unit.js +616 -0
- package/dist/lib/mesh/live/daemon/run.d.ts +13 -0
- package/dist/lib/mesh/live/daemon/run.js +35 -2
- package/dist/lib/mesh/live/direct-drain.js +1 -1
- package/dist/lib/mesh/live/emit.d.ts +3 -0
- package/dist/lib/mesh/live/emit.js +32 -9
- package/dist/lib/mesh/live/flush.d.ts +3 -0
- package/dist/lib/mesh/live/flush.js +115 -32
- package/dist/lib/mesh/live/liveness-carry.d.ts +1 -1
- package/dist/lib/mesh/live/liveness-carry.js +1 -1
- package/dist/lib/mesh/live/reporting-privacy.d.ts +119 -3
- package/dist/lib/mesh/live/reporting-privacy.js +235 -11
- package/dist/lib/mesh/live/spool.d.ts +17 -2
- package/dist/lib/mesh/live/spool.js +22 -6
- package/dist/lib/ontology-graph/legacy/coverage.d.ts +67 -0
- package/dist/lib/ontology-graph/legacy/coverage.js +192 -0
- package/dist/lib/ontology-graph/legacy/index.d.ts +199 -0
- package/dist/lib/ontology-graph/legacy/index.js +1150 -0
- package/dist/lib/ontology-graph/legacy/parse.d.ts +49 -0
- package/dist/lib/ontology-graph/legacy/parse.js +126 -0
- package/dist/lib/ontology-graph/legacy/report.d.ts +14 -0
- package/dist/lib/ontology-graph/legacy/report.js +254 -0
- package/dist/lib/ontology-graph/legacy/verb-map.d.ts +35 -0
- package/dist/lib/ontology-graph/legacy/verb-map.js +84 -0
- package/dist/lib/ontology-graph/lint/checks.d.ts +140 -0
- package/dist/lib/ontology-graph/lint/checks.js +717 -0
- package/dist/lib/ontology-graph/lint/coverage.d.ts +106 -0
- package/dist/lib/ontology-graph/lint/coverage.js +241 -0
- package/dist/lib/ontology-graph/lint/daily-job.d.ts +259 -0
- package/dist/lib/ontology-graph/lint/daily-job.js +595 -0
- package/dist/lib/ontology-graph/lint/index.d.ts +65 -0
- package/dist/lib/ontology-graph/lint/index.js +176 -0
- package/dist/lib/ontology-graph/model/files.d.ts +20 -0
- package/dist/lib/ontology-graph/model/files.js +89 -0
- package/dist/lib/ontology-graph/model/index.d.ts +65 -0
- package/dist/lib/ontology-graph/model/index.js +100 -0
- package/dist/lib/ontology-graph/model/pass-tasks.d.ts +156 -0
- package/dist/lib/ontology-graph/model/pass-tasks.js +345 -0
- package/dist/lib/ontology-graph/model/pass.d.ts +109 -0
- package/dist/lib/ontology-graph/model/pass.js +958 -0
- package/dist/lib/ontology-graph/model/runner.d.ts +50 -0
- package/dist/lib/ontology-graph/model/runner.js +160 -0
- package/dist/lib/ontology-graph/model/step.d.ts +195 -0
- package/dist/lib/ontology-graph/model/step.js +523 -0
- package/dist/lib/ontology-graph/model/tasks.d.ts +183 -0
- package/dist/lib/ontology-graph/model/tasks.js +349 -0
- package/dist/lib/ontology-graph/not-implemented.d.ts +5 -0
- package/dist/lib/ontology-graph/not-implemented.js +8 -0
- package/dist/lib/ontology-graph/org/compare.d.ts +28 -0
- package/dist/lib/ontology-graph/org/compare.js +239 -0
- package/dist/lib/ontology-graph/org/derive.d.ts +65 -0
- package/dist/lib/ontology-graph/org/derive.js +352 -0
- package/dist/lib/ontology-graph/org/index.d.ts +73 -0
- package/dist/lib/ontology-graph/org/index.js +513 -0
- package/dist/lib/ontology-graph/org/load.d.ts +31 -0
- package/dist/lib/ontology-graph/org/load.js +476 -0
- package/dist/lib/ontology-graph/org/role.d.ts +38 -0
- package/dist/lib/ontology-graph/org/role.js +268 -0
- package/dist/lib/ontology-graph/org/structure.d.ts +63 -0
- package/dist/lib/ontology-graph/org/structure.js +437 -0
- package/dist/lib/ontology-graph/org/text.d.ts +95 -0
- package/dist/lib/ontology-graph/org/text.js +315 -0
- package/dist/lib/ontology-graph/org/types.d.ts +452 -0
- package/dist/lib/ontology-graph/org/types.js +80 -0
- package/dist/lib/ontology-graph/pages/index.d.ts +64 -0
- package/dist/lib/ontology-graph/pages/index.js +193 -0
- package/dist/lib/ontology-graph/pages/render.d.ts +142 -0
- package/dist/lib/ontology-graph/pages/render.js +682 -0
- package/dist/lib/ontology-graph/proposals/apply.d.ts +109 -0
- package/dist/lib/ontology-graph/proposals/apply.js +468 -0
- package/dist/lib/ontology-graph/proposals/group.d.ts +63 -0
- package/dist/lib/ontology-graph/proposals/group.js +232 -0
- package/dist/lib/ontology-graph/proposals/index.d.ts +173 -0
- package/dist/lib/ontology-graph/proposals/index.js +474 -0
- package/dist/lib/ontology-graph/proposals/model.d.ts +162 -0
- package/dist/lib/ontology-graph/proposals/model.js +196 -0
- package/dist/lib/ontology-graph/proposals/org-chart.d.ts +82 -0
- package/dist/lib/ontology-graph/proposals/org-chart.js +340 -0
- package/dist/lib/ontology-graph/read/brief.d.ts +26 -0
- package/dist/lib/ontology-graph/read/brief.js +251 -0
- package/dist/lib/ontology-graph/read/graph-index.d.ts +76 -0
- package/dist/lib/ontology-graph/read/graph-index.js +198 -0
- package/dist/lib/ontology-graph/read/index.d.ts +59 -0
- package/dist/lib/ontology-graph/read/index.js +792 -0
- package/dist/lib/ontology-graph/read/member.d.ts +7 -0
- package/dist/lib/ontology-graph/read/member.js +34 -0
- package/dist/lib/ontology-graph/read/names.d.ts +44 -0
- package/dist/lib/ontology-graph/read/names.js +292 -0
- package/dist/lib/ontology-graph/read/reader-setting.d.ts +19 -0
- package/dist/lib/ontology-graph/read/reader-setting.js +62 -0
- package/dist/lib/ontology-graph/read/test-graph.d.ts +37 -0
- package/dist/lib/ontology-graph/read/test-graph.js +150 -0
- package/dist/lib/ontology-graph/replay/buffered-store.d.ts +33 -0
- package/dist/lib/ontology-graph/replay/buffered-store.js +50 -0
- package/dist/lib/ontology-graph/replay/config.d.ts +41 -0
- package/dist/lib/ontology-graph/replay/config.js +105 -0
- package/dist/lib/ontology-graph/replay/engine.d.ts +100 -0
- package/dist/lib/ontology-graph/replay/engine.js +1174 -0
- package/dist/lib/ontology-graph/replay/extractors.d.ts +59 -0
- package/dist/lib/ontology-graph/replay/extractors.js +1555 -0
- package/dist/lib/ontology-graph/replay/index.d.ts +90 -0
- package/dist/lib/ontology-graph/replay/index.js +220 -0
- package/dist/lib/ontology-graph/replay/listing-manifest.d.ts +66 -0
- package/dist/lib/ontology-graph/replay/listing-manifest.js +242 -0
- package/dist/lib/ontology-graph/replay/member.d.ts +19 -0
- package/dist/lib/ontology-graph/replay/member.js +65 -0
- package/dist/lib/ontology-graph/replay/mentions.d.ts +58 -0
- package/dist/lib/ontology-graph/replay/mentions.js +239 -0
- package/dist/lib/ontology-graph/replay/readers.d.ts +98 -0
- package/dist/lib/ontology-graph/replay/readers.js +1251 -0
- package/dist/lib/ontology-graph/replay/rules.d.ts +127 -0
- package/dist/lib/ontology-graph/replay/rules.js +374 -0
- package/dist/lib/ontology-graph/replay/scope.d.ts +35 -0
- package/dist/lib/ontology-graph/replay/scope.js +115 -0
- package/dist/lib/ontology-graph/replay/transcripts.d.ts +39 -0
- package/dist/lib/ontology-graph/replay/transcripts.js +224 -0
- package/dist/lib/ontology-graph/replay/util.d.ts +55 -0
- package/dist/lib/ontology-graph/replay/util.js +256 -0
- package/dist/lib/ontology-graph/resolve/entity-index.d.ts +159 -0
- package/dist/lib/ontology-graph/resolve/entity-index.js +652 -0
- package/dist/lib/ontology-graph/resolve/index.d.ts +113 -0
- package/dist/lib/ontology-graph/resolve/index.js +214 -0
- package/dist/lib/ontology-graph/resolve/machine.d.ts +34 -0
- package/dist/lib/ontology-graph/resolve/machine.js +95 -0
- package/dist/lib/ontology-graph/resolve/normalize.d.ts +35 -0
- package/dist/lib/ontology-graph/resolve/normalize.js +124 -0
- package/dist/lib/ontology-graph/resolve/org-chart.d.ts +107 -0
- package/dist/lib/ontology-graph/resolve/org-chart.js +578 -0
- package/dist/lib/ontology-graph/resolve/org-layer.d.ts +78 -0
- package/dist/lib/ontology-graph/resolve/org-layer.js +159 -0
- package/dist/lib/ontology-graph/resolve/org-seed.d.ts +141 -0
- package/dist/lib/ontology-graph/resolve/org-seed.js +631 -0
- package/dist/lib/ontology-graph/resolve/org-sources.d.ts +165 -0
- package/dist/lib/ontology-graph/resolve/org-sources.js +634 -0
- package/dist/lib/ontology-graph/resolve/roster.d.ts +76 -0
- package/dist/lib/ontology-graph/resolve/roster.js +226 -0
- package/dist/lib/ontology-graph/resolve/seed.d.ts +267 -0
- package/dist/lib/ontology-graph/resolve/seed.js +1198 -0
- package/dist/lib/ontology-graph/resolve/upsert.d.ts +58 -0
- package/dist/lib/ontology-graph/resolve/upsert.js +139 -0
- package/dist/lib/ontology-graph/resolve/writer.d.ts +128 -0
- package/dist/lib/ontology-graph/resolve/writer.js +351 -0
- package/dist/lib/ontology-graph/schema/authority.d.ts +73 -0
- package/dist/lib/ontology-graph/schema/authority.js +157 -0
- package/dist/lib/ontology-graph/schema/default-schema.d.ts +10 -0
- package/dist/lib/ontology-graph/schema/default-schema.js +242 -0
- package/dist/lib/ontology-graph/schema/grammar.d.ts +57 -0
- package/dist/lib/ontology-graph/schema/grammar.js +409 -0
- package/dist/lib/ontology-graph/schema/index.d.ts +12 -0
- package/dist/lib/ontology-graph/schema/index.js +10 -0
- package/dist/lib/ontology-graph/schema/validate.d.ts +13 -0
- package/dist/lib/ontology-graph/schema/validate.js +132 -0
- package/dist/lib/ontology-graph/store/files.d.ts +34 -0
- package/dist/lib/ontology-graph/store/files.js +207 -0
- package/dist/lib/ontology-graph/store/fs.d.ts +30 -0
- package/dist/lib/ontology-graph/store/fs.js +101 -0
- package/dist/lib/ontology-graph/store/graph-store.d.ts +14 -0
- package/dist/lib/ontology-graph/store/graph-store.js +520 -0
- package/dist/lib/ontology-graph/store/index.d.ts +18 -0
- package/dist/lib/ontology-graph/store/index.js +15 -0
- package/dist/lib/ontology-graph/store/ingest.d.ts +37 -0
- package/dist/lib/ontology-graph/store/ingest.js +323 -0
- package/dist/lib/ontology-graph/store/paths.d.ts +114 -0
- package/dist/lib/ontology-graph/store/paths.js +232 -0
- package/dist/lib/ontology-graph/types.d.ts +1183 -0
- package/dist/lib/ontology-graph/types.js +131 -0
- package/dist/lib/secret-scan/gitleaks-rules.generated.js +1 -1
- package/dist/utils/frontmatter.d.ts +14 -0
- package/dist/utils/frontmatter.js +18 -0
- package/dist/utils/interactive-caller.js +1 -1
- package/package.json +8 -8
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
import { GRAPH_PATHS, appendJsonLine, atomicWriteFile, graphPath, openGraphStore, readJsonLines, claimGraphRootFor } from "../store/index.js";
|
|
2
|
+
import { ProposalApplyError, RecordingStore, applyAction, buildUndoRecord, readUndoRecord, undoAccept, writeUndoRecord, } from "./apply.js";
|
|
3
|
+
import { groupNameVariants } from "./group.js";
|
|
4
|
+
import { humanOrigin, namesGoneEntity, normalizeSetName, proposalSet } from "./model.js";
|
|
5
|
+
export { ProposalApplyError, RecordingStore, applyAction, undoAccept } from "./apply.js";
|
|
6
|
+
export { NAME_VARIANT_SET, closeFactProposal, contradictionProposal, humanOrigin, mergeGroupProposal, mergeProposal, normalizeSetName, proposalSet, proposalId, proposalRef, proposalsFromContradictions, retypeProposal, splitProposal, } from "./model.js";
|
|
7
|
+
/** Environment variable the decider falls back to (the same one that names the member for a build). */
|
|
8
|
+
const MEMBER_ENV = "HQ_ONTOLOGY_MEMBER";
|
|
9
|
+
export class ProposalUsageError extends Error {
|
|
10
|
+
constructor(message) {
|
|
11
|
+
super(`ontology proposals: ${message}`);
|
|
12
|
+
this.name = "ProposalUsageError";
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
const openFile = (context) => graphPath(context.graphRoot, GRAPH_PATHS.proposalsOpen);
|
|
16
|
+
const decidedFile = (context) => graphPath(context.graphRoot, GRAPH_PATHS.proposalsDecided);
|
|
17
|
+
/** Every open proposal, as this package files them (with `set` and `replaces`). */
|
|
18
|
+
export function readOpenGraphProposals(context) {
|
|
19
|
+
return readOpen(context);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Files one merge proposal per person for name variants at one outside company,
|
|
23
|
+
* in place of the pair proposals between those names (see group.ts). Lint runs
|
|
24
|
+
* it after it files; the import or the replay may call it too. Idempotent.
|
|
25
|
+
*/
|
|
26
|
+
export function groupNameVariantProposals(context, options = {}) {
|
|
27
|
+
return groupNameVariants(context, { ...options, io: { readOpen, writeOpen } });
|
|
28
|
+
}
|
|
29
|
+
function readOpen(context) {
|
|
30
|
+
return readJsonLines(openFile(context)).filter((proposal) => typeof proposal?.id === "string");
|
|
31
|
+
}
|
|
32
|
+
/** Every decision line, oldest first. */
|
|
33
|
+
export function readDecisions(context) {
|
|
34
|
+
return readJsonLines(decidedFile(context)).filter((record) => typeof record?.id === "string");
|
|
35
|
+
}
|
|
36
|
+
/** The decision that currently stands for each proposal id: the last line for that id. */
|
|
37
|
+
export function standingDecisions(context) {
|
|
38
|
+
const standing = new Map();
|
|
39
|
+
for (const record of readDecisions(context)) {
|
|
40
|
+
// Re-insert so the map keeps the order in which decisions came to stand.
|
|
41
|
+
standing.delete(record.id);
|
|
42
|
+
standing.set(record.id, record);
|
|
43
|
+
}
|
|
44
|
+
return standing;
|
|
45
|
+
}
|
|
46
|
+
/** Ids whose standing decision is "nope". Lint leaves these findings out. */
|
|
47
|
+
export function declinedProposalIds(context) {
|
|
48
|
+
const ids = new Set();
|
|
49
|
+
for (const [id, record] of standingDecisions(context))
|
|
50
|
+
if (record.decision === "nope")
|
|
51
|
+
ids.add(id);
|
|
52
|
+
return ids;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Ids that have a standing answer: decided proposals, the pair proposals an
|
|
56
|
+
* accepted group stood in for, and the proposals an accept made pointless.
|
|
57
|
+
* None of them is filed again while the answer stands.
|
|
58
|
+
*/
|
|
59
|
+
export function answeredProposalIds(context) {
|
|
60
|
+
const ids = new Set();
|
|
61
|
+
for (const [id, record] of standingDecisions(context)) {
|
|
62
|
+
if (record.decision === "undo")
|
|
63
|
+
continue;
|
|
64
|
+
ids.add(id);
|
|
65
|
+
if (record.decision !== "accept")
|
|
66
|
+
continue;
|
|
67
|
+
for (const held of [...(record.replaces ?? []), ...(record.superseded ?? [])])
|
|
68
|
+
if (typeof held?.id === "string")
|
|
69
|
+
ids.add(held.id);
|
|
70
|
+
}
|
|
71
|
+
return ids;
|
|
72
|
+
}
|
|
73
|
+
/** Appends to proposals/open.jsonl, skipping ids already open or decided. Returns how many were new. */
|
|
74
|
+
export function fileProposals(context, proposals) {
|
|
75
|
+
if (proposals.length === 0)
|
|
76
|
+
return 0;
|
|
77
|
+
claimGraphRootFor(context.graphRoot, context.company, context.companyRoot);
|
|
78
|
+
const known = new Set();
|
|
79
|
+
for (const open of readOpen(context)) {
|
|
80
|
+
known.add(open.id);
|
|
81
|
+
// A pair an open group stands in for is already in front of the member, inside the group.
|
|
82
|
+
for (const held of open.replaces ?? [])
|
|
83
|
+
if (typeof held?.id === "string")
|
|
84
|
+
known.add(held.id);
|
|
85
|
+
}
|
|
86
|
+
for (const id of answeredProposalIds(context))
|
|
87
|
+
known.add(id);
|
|
88
|
+
let filed = 0;
|
|
89
|
+
for (const proposal of proposals) {
|
|
90
|
+
if (typeof proposal?.id !== "string" || !/^[0-9a-f]{12}$/.test(proposal.id) || known.has(proposal.id))
|
|
91
|
+
continue;
|
|
92
|
+
known.add(proposal.id);
|
|
93
|
+
appendJsonLine(openFile(context), proposal);
|
|
94
|
+
filed += 1;
|
|
95
|
+
}
|
|
96
|
+
return filed;
|
|
97
|
+
}
|
|
98
|
+
export function readOpenProposals(context) {
|
|
99
|
+
// Extended kinds and actions are valid JSON for a reader that only lists them.
|
|
100
|
+
return readOpen(context);
|
|
101
|
+
}
|
|
102
|
+
function writeOpen(context, proposals) {
|
|
103
|
+
atomicWriteFile(openFile(context), proposals.map((proposal) => `${JSON.stringify(proposal)}\n`).join(""));
|
|
104
|
+
}
|
|
105
|
+
/** Exact id, or a prefix of at least 6 characters that matches one proposal. */
|
|
106
|
+
function pick(items, id, what) {
|
|
107
|
+
const wanted = id.trim().toLowerCase();
|
|
108
|
+
const exact = items.find((item) => item.id === wanted);
|
|
109
|
+
if (exact)
|
|
110
|
+
return exact;
|
|
111
|
+
const prefixed = wanted.length >= 6 ? items.filter((item) => item.id.startsWith(wanted)) : [];
|
|
112
|
+
if (prefixed.length === 1)
|
|
113
|
+
return prefixed[0];
|
|
114
|
+
if (prefixed.length > 1)
|
|
115
|
+
throw new ProposalUsageError(`"${id}" matches ${prefixed.length} ${what}; give more of the id`);
|
|
116
|
+
throw new ProposalUsageError(`no ${what.replace(/s$/, "")} with id "${id}"`);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Who is deciding: `--as`, else the run's member (`--member`), else
|
|
120
|
+
* HQ_ONTOLOGY_MEMBER, else the person signed in to the CLI (correction C5),
|
|
121
|
+
* so a member does not have to type their own id.
|
|
122
|
+
*/
|
|
123
|
+
async function decider(context, as, resolveMember) {
|
|
124
|
+
let given = as ?? context.member?.personUid ?? process.env[MEMBER_ENV] ?? "";
|
|
125
|
+
if (given.trim() === "") {
|
|
126
|
+
const resolve = resolveMember ?? (await import("../replay/member.js")).resolveSignedInMember;
|
|
127
|
+
given = resolve(context)?.personUid ?? "";
|
|
128
|
+
}
|
|
129
|
+
const origin = humanOrigin(given);
|
|
130
|
+
if (!origin) {
|
|
131
|
+
throw new ProposalUsageError("who is deciding? Sign in (hq login), or pass --as <prs id>");
|
|
132
|
+
}
|
|
133
|
+
return origin;
|
|
134
|
+
}
|
|
135
|
+
function logDecision(store, date, record, change) {
|
|
136
|
+
store.appendLog({
|
|
137
|
+
date,
|
|
138
|
+
op: "decision",
|
|
139
|
+
subject: `${record.decision} ${record.id}`,
|
|
140
|
+
touched: change.touched,
|
|
141
|
+
rowsAdded: change.rowsAdded,
|
|
142
|
+
rowsClosed: change.rowsClosed,
|
|
143
|
+
note: `by ${record.decidedBy}: ${record.summary}`,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
/** Moves the proposal to decided.jsonl; on accept, applies its action as a `by human:<prs id>` row and logs it. */
|
|
147
|
+
export async function decideProposal(context, options) {
|
|
148
|
+
if (options.decision !== "accept" && options.decision !== "nope") {
|
|
149
|
+
throw new ProposalUsageError(`the decision is accept or nope, not "${String(options.decision)}"`);
|
|
150
|
+
}
|
|
151
|
+
const open = readOpen(context);
|
|
152
|
+
if (options.id === undefined)
|
|
153
|
+
throw new ProposalUsageError("which proposal? Pass its id, or --set <name> for a whole set");
|
|
154
|
+
const proposal = pick(open, options.id, "open proposals");
|
|
155
|
+
const decidedBy = await decider(context, options.as, options.resolveMember);
|
|
156
|
+
const decidedAt = (options.now ?? new Date()).toISOString();
|
|
157
|
+
const date = decidedAt.slice(0, 10);
|
|
158
|
+
const store = openGraphStore(context.graphRoot, { company: context.company });
|
|
159
|
+
claimGraphRootFor(context.graphRoot, context.company, context.companyRoot);
|
|
160
|
+
store.init();
|
|
161
|
+
let applied;
|
|
162
|
+
if (options.decision === "accept") {
|
|
163
|
+
const recording = new RecordingStore(store);
|
|
164
|
+
const identities = applyAction(recording, proposal.action, { id: proposal.id, by: decidedBy, date, summary: proposal.summary });
|
|
165
|
+
writeUndoRecord(context.graphRoot, buildUndoRecord(proposal.id, recording));
|
|
166
|
+
applied = {
|
|
167
|
+
touched: [...recording.touched].sort(),
|
|
168
|
+
rowsAdded: recording.rowsAdded,
|
|
169
|
+
rowsClosed: recording.rowsClosed,
|
|
170
|
+
...identities,
|
|
171
|
+
};
|
|
172
|
+
if (applied.touched.length > 0)
|
|
173
|
+
store.markDirty(applied.touched);
|
|
174
|
+
}
|
|
175
|
+
let remaining = open.filter((candidate) => candidate.id !== proposal.id);
|
|
176
|
+
// An accept that merged or removed entities leaves nothing behind that still names them: a pair proposal
|
|
177
|
+
// between two names of a merged group, or a finding on an entity that is gone, cannot be applied any more.
|
|
178
|
+
const gone = new Set((applied?.removed ?? []).map((entity) => entity.id));
|
|
179
|
+
const superseded = remaining.filter((candidate) => namesGoneEntity(candidate, gone));
|
|
180
|
+
if (superseded.length > 0)
|
|
181
|
+
remaining = remaining.filter((candidate) => !superseded.includes(candidate));
|
|
182
|
+
const record = {
|
|
183
|
+
...proposal,
|
|
184
|
+
decision: options.decision,
|
|
185
|
+
decidedBy,
|
|
186
|
+
decidedAt,
|
|
187
|
+
...(applied ? { applied } : {}),
|
|
188
|
+
...(superseded.length > 0 ? { superseded } : {}),
|
|
189
|
+
};
|
|
190
|
+
appendJsonLine(decidedFile(context), record);
|
|
191
|
+
// Declining a proposal that stands in for others (a group of name variants) brings those back, one by one.
|
|
192
|
+
if (options.decision === "nope" && Array.isArray(proposal.replaces)) {
|
|
193
|
+
const known = new Set(remaining.map((candidate) => candidate.id));
|
|
194
|
+
for (const [id, standing] of standingDecisions(context))
|
|
195
|
+
if (standing.decision !== "undo")
|
|
196
|
+
known.add(id);
|
|
197
|
+
for (const replaced of proposal.replaces) {
|
|
198
|
+
if (typeof replaced?.id !== "string" || known.has(replaced.id))
|
|
199
|
+
continue;
|
|
200
|
+
known.add(replaced.id);
|
|
201
|
+
remaining.push(replaced);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
writeOpen(context, remaining);
|
|
205
|
+
logDecision(store, date, record, applied ?? { touched: [], rowsAdded: 0, rowsClosed: 0 });
|
|
206
|
+
return record;
|
|
207
|
+
}
|
|
208
|
+
/** Open proposals in one set, in file order. */
|
|
209
|
+
export function openProposalsInSet(context, set) {
|
|
210
|
+
const wanted = normalizeSetName(set);
|
|
211
|
+
return readOpen(context).filter((proposal) => proposalSet(proposal) === wanted);
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Answers every open proposal of a set the same way, one after the other, each
|
|
215
|
+
* with its own decision line and undo record. A proposal that cannot be
|
|
216
|
+
* applied stays open, is reported in `failed`, and does not stop the rest.
|
|
217
|
+
*/
|
|
218
|
+
export async function decideProposalSet(context, options) {
|
|
219
|
+
const set = normalizeSetName(options.set);
|
|
220
|
+
if (set === "")
|
|
221
|
+
throw new ProposalUsageError("--set needs a name; `hq ontology proposals list` prints the sets");
|
|
222
|
+
const matching = openProposalsInSet(context, set);
|
|
223
|
+
if (matching.length === 0)
|
|
224
|
+
throw new ProposalUsageError(`no open proposal in the set "${set}"`);
|
|
225
|
+
const result = { set, decision: options.decision, matched: matching.length, decided: [], failed: [], rowsAdded: 0, rowsClosed: 0, touched: [] };
|
|
226
|
+
const touched = new Set();
|
|
227
|
+
for (const proposal of matching) {
|
|
228
|
+
try {
|
|
229
|
+
const record = (await decideProposal(context, {
|
|
230
|
+
id: proposal.id,
|
|
231
|
+
decision: options.decision,
|
|
232
|
+
...(options.as !== undefined ? { as: options.as } : {}),
|
|
233
|
+
...(options.now ? { now: options.now } : {}),
|
|
234
|
+
...(options.resolveMember ? { resolveMember: options.resolveMember } : {}),
|
|
235
|
+
}));
|
|
236
|
+
result.decided.push(record);
|
|
237
|
+
result.rowsAdded += record.applied?.rowsAdded ?? 0;
|
|
238
|
+
result.rowsClosed += record.applied?.rowsClosed ?? 0;
|
|
239
|
+
for (const ref of record.applied?.touched ?? [])
|
|
240
|
+
touched.add(ref);
|
|
241
|
+
}
|
|
242
|
+
catch (error) {
|
|
243
|
+
// Nobody to decide is the same answer for every proposal: say it once.
|
|
244
|
+
if (error instanceof ProposalUsageError)
|
|
245
|
+
throw error;
|
|
246
|
+
result.failed.push({ id: proposal.id, summary: proposal.summary, error: error instanceof Error ? error.message : String(error) });
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
result.touched = [...touched].sort();
|
|
250
|
+
return result;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Takes back a decision. An accept is reversed row by row (see `undoAccept`);
|
|
254
|
+
* either way the proposal returns to the open list and the rebuild stops
|
|
255
|
+
* replaying it.
|
|
256
|
+
*/
|
|
257
|
+
export async function undoDecision(context, options) {
|
|
258
|
+
const standing = [...standingDecisions(context).values()].filter((record) => record.decision !== "undo");
|
|
259
|
+
const record = pick(standing, options.id, "decided proposals");
|
|
260
|
+
const decidedBy = await decider(context, options.as, options.resolveMember);
|
|
261
|
+
const decidedAt = (options.now ?? new Date()).toISOString();
|
|
262
|
+
const store = openGraphStore(context.graphRoot, { company: context.company });
|
|
263
|
+
claimGraphRootFor(context.graphRoot, context.company, context.companyRoot);
|
|
264
|
+
let result = { touched: [], rowsRemoved: 0, rowsReopened: 0, entitiesRestored: [], entitiesKept: [] };
|
|
265
|
+
if (record.decision === "accept") {
|
|
266
|
+
const undo = readUndoRecord(context.graphRoot, record.id);
|
|
267
|
+
if (!undo)
|
|
268
|
+
throw new ProposalApplyError(`cannot undo ${record.id}: its undo record is missing`);
|
|
269
|
+
// Rows are removed and reopened through the store, never by rewriting a facts file here.
|
|
270
|
+
result = undoAccept(store, undo);
|
|
271
|
+
}
|
|
272
|
+
if (result.touched.length > 0)
|
|
273
|
+
store.markDirty(result.touched);
|
|
274
|
+
const { decision: undid, applied: _applied, decidedBy: _by, decidedAt: _at, superseded, ...proposal } = record;
|
|
275
|
+
appendJsonLine(decidedFile(context), { ...proposal, decision: "undo", decidedBy, decidedAt });
|
|
276
|
+
const open = readOpen(context);
|
|
277
|
+
const reopened = !open.some((candidate) => candidate.id === record.id);
|
|
278
|
+
if (reopened)
|
|
279
|
+
appendJsonLine(openFile(context), proposal);
|
|
280
|
+
// The proposals the accept took off the list with it are open questions again.
|
|
281
|
+
const known = new Set([...open.map((candidate) => candidate.id), record.id, ...answeredProposalIds(context)]);
|
|
282
|
+
for (const held of superseded ?? []) {
|
|
283
|
+
if (typeof held?.id !== "string" || known.has(held.id))
|
|
284
|
+
continue;
|
|
285
|
+
known.add(held.id);
|
|
286
|
+
appendJsonLine(openFile(context), held);
|
|
287
|
+
}
|
|
288
|
+
logDecision(store, decidedAt.slice(0, 10), { id: record.id, decision: "undo", decidedBy, summary: `took back ${undid}: ${record.summary}` }, { touched: result.touched, rowsAdded: 0, rowsClosed: 0 });
|
|
289
|
+
return { ...result, id: record.id, undid: undid, reopened };
|
|
290
|
+
}
|
|
291
|
+
/** Takes back every standing answer to the proposals of one set, newest first. */
|
|
292
|
+
export async function undoDecisionSet(context, options) {
|
|
293
|
+
const set = normalizeSetName(options.set);
|
|
294
|
+
const standing = [...standingDecisions(context).values()].filter((record) => record.decision !== "undo" && proposalSet(record) === set).reverse();
|
|
295
|
+
if (standing.length === 0)
|
|
296
|
+
throw new ProposalUsageError(`no answered proposal in the set "${set}"`);
|
|
297
|
+
const result = { set, matched: standing.length, undone: [], failed: [] };
|
|
298
|
+
for (const record of standing) {
|
|
299
|
+
try {
|
|
300
|
+
const { set: _set, ...rest } = options;
|
|
301
|
+
result.undone.push(await undoDecision(context, { ...rest, id: record.id }));
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
if (error instanceof ProposalUsageError)
|
|
305
|
+
throw error;
|
|
306
|
+
result.failed.push({ id: record.id, error: error instanceof Error ? error.message : String(error) });
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return result;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Applies every standing accept again, oldest first, with the decider and day
|
|
313
|
+
* it was first made on. The rebuild calls this before the legacy import (so
|
|
314
|
+
* human rows are in place and outrank what the replay writes) and again after
|
|
315
|
+
* the last day (so rows the replay wrote again are closed or moved again).
|
|
316
|
+
* Idempotent. A decision that can no longer be applied is reported in
|
|
317
|
+
* `failed` and does not stop the others.
|
|
318
|
+
*/
|
|
319
|
+
export function replayDecisions(context, options = {}) {
|
|
320
|
+
const store = options.store ?? openGraphStore(context.graphRoot, { company: context.company });
|
|
321
|
+
if (!options.store)
|
|
322
|
+
claimGraphRootFor(context.graphRoot, context.company, context.companyRoot);
|
|
323
|
+
store.init();
|
|
324
|
+
const result = { accepted: 0, applied: 0, rowsAdded: 0, rowsClosed: 0, touched: [], failed: [] };
|
|
325
|
+
const touched = new Set();
|
|
326
|
+
for (const record of standingDecisions(context).values()) {
|
|
327
|
+
if (record.decision !== "accept")
|
|
328
|
+
continue;
|
|
329
|
+
result.accepted += 1;
|
|
330
|
+
const recording = new RecordingStore(store);
|
|
331
|
+
try {
|
|
332
|
+
applyAction(recording, record.action, {
|
|
333
|
+
id: record.id,
|
|
334
|
+
by: record.decidedBy,
|
|
335
|
+
date: record.decidedAt.slice(0, 10),
|
|
336
|
+
summary: record.summary,
|
|
337
|
+
...(record.applied ? { recorded: record.applied } : {}),
|
|
338
|
+
});
|
|
339
|
+
result.applied += 1;
|
|
340
|
+
}
|
|
341
|
+
catch (error) {
|
|
342
|
+
result.failed.push({ id: record.id, error: error instanceof Error ? error.message : String(error) });
|
|
343
|
+
}
|
|
344
|
+
result.rowsAdded += recording.rowsAdded;
|
|
345
|
+
result.rowsClosed += recording.rowsClosed;
|
|
346
|
+
for (const ref of recording.touched)
|
|
347
|
+
touched.add(ref);
|
|
348
|
+
}
|
|
349
|
+
result.touched = [...touched].sort();
|
|
350
|
+
if (result.touched.length > 0)
|
|
351
|
+
store.markDirty(result.touched);
|
|
352
|
+
return result;
|
|
353
|
+
}
|
|
354
|
+
/** Reads one row for `proposalsFromContradictions`. */
|
|
355
|
+
export function rowLookup(store) {
|
|
356
|
+
return (entity, audience, id) => {
|
|
357
|
+
const stored = store.readRows(entity, { audiences: [audience] }).find((candidate) => candidate.id === id);
|
|
358
|
+
return stored && stored.row.kind !== "T" ? stored.row : null;
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
const compareText = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
|
|
362
|
+
/** `hq ontology proposals list`. */
|
|
363
|
+
export async function proposalsListCommand(context, options) {
|
|
364
|
+
const all = readOpen(context);
|
|
365
|
+
const byKind = {};
|
|
366
|
+
const bySet = {};
|
|
367
|
+
for (const proposal of all) {
|
|
368
|
+
byKind[proposal.kind] = (byKind[proposal.kind] ?? 0) + 1;
|
|
369
|
+
const set = proposalSet(proposal);
|
|
370
|
+
if (set)
|
|
371
|
+
bySet[set] = (bySet[set] ?? 0) + 1;
|
|
372
|
+
}
|
|
373
|
+
const wantedSet = options.set !== undefined ? normalizeSetName(options.set) : undefined;
|
|
374
|
+
const matching = all.filter((proposal) => (!options.kind || proposal.kind === options.kind) && (wantedSet === undefined || proposalSet(proposal) === wantedSet));
|
|
375
|
+
const limit = options.limit ?? 50;
|
|
376
|
+
const shown = matching.slice(0, limit);
|
|
377
|
+
const kinds = Object.keys(byKind).sort(compareText);
|
|
378
|
+
const sets = Object.keys(bySet).sort(compareText);
|
|
379
|
+
const lines = [];
|
|
380
|
+
if (all.length === 0)
|
|
381
|
+
lines.push("No open proposals.");
|
|
382
|
+
else {
|
|
383
|
+
lines.push(`${all.length} open proposal${all.length === 1 ? "" : "s"}: ${kinds.map((kind) => `${kind} ${byKind[kind]}`).join(", ")}`);
|
|
384
|
+
if (sets.length > 0)
|
|
385
|
+
lines.push(`Sets: ${sets.map((set) => `"${set}" ${bySet[set]}`).join(", ")}`);
|
|
386
|
+
if (options.kind && matching.length === 0 && wantedSet === undefined)
|
|
387
|
+
lines.push(`None of kind "${options.kind}".`);
|
|
388
|
+
if (wantedSet !== undefined && matching.length === 0)
|
|
389
|
+
lines.push(`None in the set "${wantedSet}"${options.kind ? ` of kind "${options.kind}"` : ""}.`);
|
|
390
|
+
for (const proposal of shown) {
|
|
391
|
+
lines.push(`${proposal.id} ${proposal.kind.padEnd(18)} ${proposal.summary}`);
|
|
392
|
+
}
|
|
393
|
+
if (matching.length > shown.length)
|
|
394
|
+
lines.push(`... ${matching.length - shown.length} more (raise --limit)`);
|
|
395
|
+
lines.push("", "Answer one: hq ontology proposals accept <id> | nope <id>. Take an answer back: hq ontology proposals undo <id>.");
|
|
396
|
+
if (sets.length > 0) {
|
|
397
|
+
lines.push('Answer a whole set after reading it: hq ontology proposals list --set "<name>", then accept --set "<name>" or nope --set "<name>".');
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
return {
|
|
401
|
+
text: lines.join("\n"),
|
|
402
|
+
json: {
|
|
403
|
+
open: all.length,
|
|
404
|
+
byKind: Object.fromEntries(kinds.map((kind) => [kind, byKind[kind]])),
|
|
405
|
+
bySet: Object.fromEntries(sets.map((set) => [set, bySet[set]])),
|
|
406
|
+
matching: matching.length,
|
|
407
|
+
proposals: shown,
|
|
408
|
+
},
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
/** `--set` given: answer the set. Otherwise an id is required. */
|
|
412
|
+
function oneOf(id, set, verb) {
|
|
413
|
+
const hasId = typeof id === "string" && id.trim() !== "";
|
|
414
|
+
const hasSet = typeof set === "string" && set.trim() !== "";
|
|
415
|
+
if (hasId && hasSet)
|
|
416
|
+
throw new ProposalUsageError(`give a proposal id or --set <name>, not both`);
|
|
417
|
+
if (!hasId && !hasSet)
|
|
418
|
+
throw new ProposalUsageError(`${verb} needs a proposal id, or --set <name> for a whole set`);
|
|
419
|
+
return hasSet ? "set" : "id";
|
|
420
|
+
}
|
|
421
|
+
/** `hq ontology proposals accept|nope <id>`, or `--set <name>` for a whole set. */
|
|
422
|
+
export async function proposalsDecideCommand(context, options) {
|
|
423
|
+
if (oneOf(options.id, options.set, options.decision) === "set") {
|
|
424
|
+
const { id: _id, set, ...rest } = options;
|
|
425
|
+
const result = await decideProposalSet(context, { ...rest, set: set });
|
|
426
|
+
const by = result.decided[0]?.decidedBy;
|
|
427
|
+
const lines = result.decision === "accept"
|
|
428
|
+
? [
|
|
429
|
+
`Accepted ${result.decided.length} of ${result.matched} in the set "${result.set}"${by ? ` as ${by}` : ""}.`,
|
|
430
|
+
`Rows added ${result.rowsAdded}, closed ${result.rowsClosed}, entities touched ${result.touched.length}.`,
|
|
431
|
+
]
|
|
432
|
+
: [`Declined ${result.decided.length} of ${result.matched} in the set "${result.set}"${by ? ` as ${by}` : ""}. They will not be proposed again.`];
|
|
433
|
+
for (const failure of result.failed)
|
|
434
|
+
lines.push(`Not applied, still open: ${failure.id} ${failure.error}`);
|
|
435
|
+
if (result.decided.length > 0)
|
|
436
|
+
lines.push(`Take it back: hq ontology proposals undo --set "${result.set}"`);
|
|
437
|
+
return { text: lines.join("\n"), json: result, ...(result.failed.length > 0 ? { exitCode: 1 } : {}) };
|
|
438
|
+
}
|
|
439
|
+
const decided = (await decideProposal(context, { ...options, id: options.id }));
|
|
440
|
+
const applied = decided.applied;
|
|
441
|
+
const lines = decided.decision === "accept"
|
|
442
|
+
? [
|
|
443
|
+
`Accepted ${decided.id} as ${decided.decidedBy}: ${decided.summary}`,
|
|
444
|
+
`Rows added ${applied?.rowsAdded ?? 0}, closed ${applied?.rowsClosed ?? 0}, entities touched ${applied?.touched.length ?? 0}.`,
|
|
445
|
+
`Take it back: hq ontology proposals undo ${decided.id}`,
|
|
446
|
+
]
|
|
447
|
+
: [`Declined ${decided.id} as ${decided.decidedBy}. It will not be proposed again.`];
|
|
448
|
+
return { text: lines.join("\n"), json: decided };
|
|
449
|
+
}
|
|
450
|
+
/** `hq ontology proposals undo <id>`, or `--set <name>` for every answer given to a set. */
|
|
451
|
+
export async function proposalsUndoCommand(context, options) {
|
|
452
|
+
if (oneOf(options.id, options.set, "undo") === "set") {
|
|
453
|
+
const { id: _id, set, ...rest } = options;
|
|
454
|
+
const all = await undoDecisionSet(context, { ...rest, set: set });
|
|
455
|
+
const lines = [
|
|
456
|
+
`Took back ${all.undone.length} of ${all.matched} answers in the set "${all.set}". They are open again.`,
|
|
457
|
+
`Rows removed ${all.undone.reduce((sum, entry) => sum + entry.rowsRemoved, 0)}, reopened ${all.undone.reduce((sum, entry) => sum + entry.rowsReopened, 0)}.`,
|
|
458
|
+
...all.failed.map((failure) => `Not taken back: ${failure.id} ${failure.error}`),
|
|
459
|
+
];
|
|
460
|
+
return { text: lines.join("\n"), json: all, ...(all.failed.length > 0 ? { exitCode: 1 } : {}) };
|
|
461
|
+
}
|
|
462
|
+
const result = await undoDecision(context, { ...options, id: options.id });
|
|
463
|
+
const lines = [
|
|
464
|
+
`Took back the ${result.undid} of ${result.id}. It is open again.`,
|
|
465
|
+
...(result.undid === "accept"
|
|
466
|
+
? [`Rows removed ${result.rowsRemoved}, reopened ${result.rowsReopened}, entity files restored ${result.entitiesRestored.length}.`]
|
|
467
|
+
: []),
|
|
468
|
+
...(result.entitiesKept.length > 0
|
|
469
|
+
? [`Left as they are, because they changed after the accept: ${result.entitiesKept.join(", ")}`]
|
|
470
|
+
: []),
|
|
471
|
+
];
|
|
472
|
+
return { text: lines.join("\n"), json: result };
|
|
473
|
+
}
|
|
474
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import type { AudienceKey, Contradiction, DecidedProposal, EdgeRow, EntityKeys, EntityRef, FactRow, GraphEntity, GraphRow, IsoTimestamp, Origin, Proposal, ProposalAction, ProposalKind, RowId, SourceRef, Verb } from "../types.js";
|
|
2
|
+
/** Proposal kinds this package files in addition to the contract's. */
|
|
3
|
+
export type GraphProposalKind = ProposalKind | "split" | "close_fact" | "near_duplicate" | "closed_entity_edge" | "audience_leak";
|
|
4
|
+
export interface RowAddress {
|
|
5
|
+
audience: AudienceKey;
|
|
6
|
+
row: RowId;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Keep one row of a single-valued field or verb and close the rows that
|
|
10
|
+
* disagree with it. `keep` is the full row so the decision can be written
|
|
11
|
+
* again when the row it came from does not exist yet.
|
|
12
|
+
*/
|
|
13
|
+
export interface KeepFactAction {
|
|
14
|
+
type: "keep_fact";
|
|
15
|
+
entity: EntityRef;
|
|
16
|
+
audience: AudienceKey;
|
|
17
|
+
keep: FactRow | EdgeRow;
|
|
18
|
+
close: RowAddress[];
|
|
19
|
+
}
|
|
20
|
+
/** Replace an edge's verb (usually `related_to`) with a typed verb. `edge` is the row as filed. */
|
|
21
|
+
export interface RetypeEdgeAction {
|
|
22
|
+
type: "retype_edge";
|
|
23
|
+
entity: EntityRef;
|
|
24
|
+
audience: AudienceKey;
|
|
25
|
+
row: RowId;
|
|
26
|
+
edge: EdgeRow;
|
|
27
|
+
verb: Verb;
|
|
28
|
+
}
|
|
29
|
+
/** Move some rows of one entity onto a new entity of the same type. */
|
|
30
|
+
export interface SplitAction {
|
|
31
|
+
type: "split";
|
|
32
|
+
entity: EntityRef;
|
|
33
|
+
into: {
|
|
34
|
+
slug: string;
|
|
35
|
+
canonical_name: string;
|
|
36
|
+
aliases?: string[];
|
|
37
|
+
keys?: Partial<EntityKeys>;
|
|
38
|
+
};
|
|
39
|
+
rows: RowAddress[];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Write one row. On accept an F or E row is written as the member's own
|
|
43
|
+
* statement: origin human, confidence 1. When an edge points at an entity
|
|
44
|
+
* that has no file yet (a `member_of` to a team nobody has made), the accept
|
|
45
|
+
* creates it first, named `targetName` when given.
|
|
46
|
+
*/
|
|
47
|
+
export interface WriteRowAction {
|
|
48
|
+
type: "write_row";
|
|
49
|
+
entity: EntityRef;
|
|
50
|
+
audience: AudienceKey;
|
|
51
|
+
row: GraphRow;
|
|
52
|
+
targetName?: string;
|
|
53
|
+
}
|
|
54
|
+
/** Several names of one person (or thing): every entity in `from` is merged into `into`. */
|
|
55
|
+
export interface MergeGroupAction {
|
|
56
|
+
type: "merge_group";
|
|
57
|
+
into: EntityRef;
|
|
58
|
+
from: EntityRef[];
|
|
59
|
+
}
|
|
60
|
+
export type GraphProposalAction = ProposalAction | KeepFactAction | RetypeEdgeAction | SplitAction | WriteRowAction | MergeGroupAction;
|
|
61
|
+
/** A proposal as this package files and reads it. Assignable from the contract's `Proposal`. */
|
|
62
|
+
export interface GraphProposal extends Omit<Proposal, "kind" | "action"> {
|
|
63
|
+
kind: GraphProposalKind;
|
|
64
|
+
action: GraphProposalAction;
|
|
65
|
+
/**
|
|
66
|
+
* The reviewed set the proposal belongs to (`org chart draft`, `name variants`). A set is listed and answered
|
|
67
|
+
* as one: `proposals list --set <name>`, `proposals accept --set <name>`.
|
|
68
|
+
*/
|
|
69
|
+
set?: string;
|
|
70
|
+
/** Proposals this one stands in for. They return to the open list when it is declined. */
|
|
71
|
+
replaces?: GraphProposal[];
|
|
72
|
+
}
|
|
73
|
+
/** The set name as typed or stored: case and spacing do not matter. */
|
|
74
|
+
export declare function normalizeSetName(name: string): string;
|
|
75
|
+
/**
|
|
76
|
+
* The set a proposal belongs to: its `set` field, else the name in square
|
|
77
|
+
* brackets its summary starts with (`[org chart draft] ...`). Null for a
|
|
78
|
+
* proposal in no set.
|
|
79
|
+
*/
|
|
80
|
+
export declare function proposalSet(proposal: Pick<GraphProposal, "summary" | "set">): string | null;
|
|
81
|
+
/** The set every grouped name-variant proposal is filed in. */
|
|
82
|
+
export declare const NAME_VARIANT_SET = "name variants";
|
|
83
|
+
/** What an accept changed, kept with the decision so undo and replay need nothing else. */
|
|
84
|
+
export interface AppliedSummary {
|
|
85
|
+
touched: EntityRef[];
|
|
86
|
+
rowsAdded: number;
|
|
87
|
+
rowsClosed: number;
|
|
88
|
+
/** Identity of an entity the accept removed (merge, remove_entity). */
|
|
89
|
+
removed?: GraphEntity[];
|
|
90
|
+
/** Identity of the entity a merge kept, as it was before the merge. */
|
|
91
|
+
kept?: GraphEntity;
|
|
92
|
+
}
|
|
93
|
+
/** One line of proposals/decided.jsonl. `undo` reverses the accept before it. */
|
|
94
|
+
export interface DecisionRecord extends Omit<DecidedProposal, "kind" | "action" | "decision"> {
|
|
95
|
+
kind: GraphProposalKind;
|
|
96
|
+
action: GraphProposalAction;
|
|
97
|
+
decision: "accept" | "nope" | "undo";
|
|
98
|
+
applied?: AppliedSummary;
|
|
99
|
+
/**
|
|
100
|
+
* Open proposals this accept made pointless, because they name an entity it
|
|
101
|
+
* merged away or removed. They leave the open list with it, are not filed
|
|
102
|
+
* again while it stands, and come back when it is undone.
|
|
103
|
+
*/
|
|
104
|
+
superseded?: GraphProposal[];
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* True when `proposal` can no longer be applied as filed once the entities in
|
|
108
|
+
* `gone` have been merged away or removed: it would merge from or into one of
|
|
109
|
+
* them, or it addresses rows on one of them.
|
|
110
|
+
*/
|
|
111
|
+
export declare function namesGoneEntity(proposal: GraphProposal, gone: ReadonlySet<EntityRef>): boolean;
|
|
112
|
+
/** The source ref rows and closures written by a decision cite. */
|
|
113
|
+
export declare function proposalRef(id: string): SourceRef;
|
|
114
|
+
/** 12 hex from kind, entity and rows (plus `extra` for merges, splits and retypes), so re-filing never duplicates. */
|
|
115
|
+
export declare function proposalId(kind: string, entity: string | undefined, rows: readonly RowId[], extra?: string): string;
|
|
116
|
+
interface Filing {
|
|
117
|
+
evidence?: readonly SourceRef[];
|
|
118
|
+
summary?: string;
|
|
119
|
+
/** Default: the clock. */
|
|
120
|
+
filedAt?: IsoTimestamp;
|
|
121
|
+
}
|
|
122
|
+
/** Merge `from` into `into`: aliases, keys and rows move, `from` is removed. */
|
|
123
|
+
export declare function mergeProposal(from: EntityRef, into: EntityRef, reason: string, filing?: Filing): GraphProposal;
|
|
124
|
+
/**
|
|
125
|
+
* One proposal for several names of one person: accept merges every entity in
|
|
126
|
+
* `from` into `into`. `where` says what ties them together (the company they
|
|
127
|
+
* are all placed at). The id depends on the members, so the same group is
|
|
128
|
+
* never filed twice and a different group is a different proposal.
|
|
129
|
+
*/
|
|
130
|
+
export declare function mergeGroupProposal(into: EntityRef, from: readonly EntityRef[], where: string, filing?: Filing & {
|
|
131
|
+
replaces?: readonly GraphProposal[];
|
|
132
|
+
}): GraphProposal;
|
|
133
|
+
/** Split `entity`: the listed rows move to a new entity of the same type. */
|
|
134
|
+
export declare function splitProposal(entity: EntityRef, into: SplitAction["into"], rows: readonly RowAddress[], reason: string, filing?: Filing): GraphProposal;
|
|
135
|
+
/** Close one open fact or edge. */
|
|
136
|
+
export declare function closeFactProposal(entity: EntityRef, audience: AudienceKey, row: RowId, reason: string, filing?: Filing & {
|
|
137
|
+
kind?: GraphProposalKind;
|
|
138
|
+
}): GraphProposal;
|
|
139
|
+
/** Retype an edge: the old row is closed and a human-origin row with `verb` is written. */
|
|
140
|
+
export declare function retypeProposal(entity: EntityRef, audience: AudienceKey, row: RowId, edge: EdgeRow, verb: Verb, filing?: Filing): GraphProposal;
|
|
141
|
+
/** Two or more open rows disagree on a single-valued field or verb: keep `keep`, close the rest. */
|
|
142
|
+
export declare function contradictionProposal(entity: EntityRef, key: string, keep: {
|
|
143
|
+
audience: AudienceKey;
|
|
144
|
+
id: RowId;
|
|
145
|
+
row: FactRow | EdgeRow;
|
|
146
|
+
}, rivals: readonly {
|
|
147
|
+
audience: AudienceKey;
|
|
148
|
+
id: RowId;
|
|
149
|
+
row: FactRow | EdgeRow;
|
|
150
|
+
}[], filing?: Filing): GraphProposal;
|
|
151
|
+
/**
|
|
152
|
+
* Turns the contradictions `applyIngest` returns into proposals (CONTRACT
|
|
153
|
+
* section 4: the caller passes them to `fileProposals`). `lookup` reads a row
|
|
154
|
+
* by id; a contradiction whose rows cannot be read is skipped. So is a
|
|
155
|
+
* challenger dated on or before the human row it loses to: a person's answer
|
|
156
|
+
* is asked about again only when something later disagrees with it.
|
|
157
|
+
*/
|
|
158
|
+
export declare function proposalsFromContradictions(contradictions: readonly Contradiction[], lookup: (entity: EntityRef, audience: AudienceKey, id: RowId) => FactRow | EdgeRow | null, filing?: Filing): GraphProposal[];
|
|
159
|
+
/** `human:<prs id>` for a decider, or null when the id cannot be an origin. */
|
|
160
|
+
export declare function humanOrigin(personUid: string): Origin | null;
|
|
161
|
+
export {};
|
|
162
|
+
//# sourceMappingURL=model.d.ts.map
|