onto-mcp 0.4.11 → 0.4.13
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/.onto/authority/core-lexicon.yaml +1 -1
- package/.onto/authority/supported-models.yaml +153 -0
- package/.onto/domains/accounting-kr/competency_qs.md +153 -153
- package/.onto/processes/reconstruct/obligation-coverage-ledger.yaml +842 -0
- package/.onto/processes/reconstruct/obligation-coverage-recorded.yaml +225 -0
- package/.onto/processes/reconstruct/ontology-seeding-and-maturation-design.md +93 -54
- package/.onto/processes/reconstruct/reconstruct-contract-registry.yaml +202 -49
- package/.onto/processes/reconstruct/reconstruct-execution-ux-contract.md +72 -1
- package/.onto/processes/reconstruct/source-profiles/spreadsheet.md +35 -0
- package/.onto/processes/review/nesting-batch-worker-contract.md +1 -1
- package/.onto/processes/review/productized-live-path.md +9 -5
- package/.onto/processes/review/prompt-execution-runner-contract.md +32 -8
- package/.onto/processes/review/review-target-profile-contract.md +47 -4
- package/.onto/processes/shared/pipeline-execution-ledger-contract.md +11 -0
- package/.onto/processes/shared/target-material-kind-contract.md +1 -1
- package/README.md +64 -1
- package/dist/cli.js +11 -1
- package/dist/core-api/reconstruct-api.js +679 -18
- package/dist/core-api/review-api.js +70 -5
- package/dist/core-api/review-progress.js +7 -0
- package/dist/core-api/runtime-observation.js +7 -0
- package/dist/core-runtime/artifact-io.js +131 -0
- package/dist/core-runtime/cli/claude-code-review-unit-executor.js +21 -9
- package/dist/core-runtime/cli/claude-nesting-batch-worker.js +4 -2
- package/dist/core-runtime/cli/materialize-review-prompt-packets.js +68 -14
- package/dist/core-runtime/cli/prepare-review-session.js +34 -1
- package/dist/core-runtime/cli/render-review-final-output.js +2 -1
- package/dist/core-runtime/cli/run-review-prompt-execution.js +758 -48
- package/dist/core-runtime/cli/run-seats.js +18 -0
- package/dist/core-runtime/cli/runtime-submit-context.js +10 -2
- package/dist/core-runtime/cli/unit-resubmit.js +269 -0
- package/dist/core-runtime/cli/worker-structured-output.js +80 -2
- package/dist/core-runtime/discovery/host-detection.js +71 -22
- package/dist/core-runtime/discovery/review-cert-assemble.js +208 -0
- package/dist/core-runtime/discovery/review-cert-record.js +442 -0
- package/dist/core-runtime/discovery/review-execution-units.js +22 -0
- package/dist/core-runtime/discovery/seat-inventory.js +167 -0
- package/dist/core-runtime/discovery/settings-chain.js +311 -52
- package/dist/core-runtime/discovery/supported-models.js +289 -25
- package/dist/core-runtime/discovery/synthesize-cert-assemble.js +197 -0
- package/dist/core-runtime/discovery/synthesize-cert-capsule.js +399 -0
- package/dist/core-runtime/discovery/synthesize-cert-judge.js +340 -0
- package/dist/core-runtime/discovery/synthesize-cert-loop.js +234 -0
- package/dist/core-runtime/discovery/synthesize-cert-mutation.js +117 -0
- package/dist/core-runtime/discovery/synthesize-cert-packet.js +182 -0
- package/dist/core-runtime/discovery/synthesize-cert-record.js +831 -0
- package/dist/core-runtime/discovery/synthesize-cert-sampler.js +336 -0
- package/dist/core-runtime/effort-calibration-ingest.js +326 -0
- package/dist/core-runtime/effort-calibration-reconstruct.js +47 -0
- package/dist/core-runtime/effort-calibration-review.js +22 -0
- package/dist/core-runtime/effort-calibration-sweep.js +110 -0
- package/dist/core-runtime/effort-frontier.js +134 -0
- package/dist/core-runtime/llm/claude-bin.js +77 -0
- package/dist/core-runtime/llm/dispatch-breaker.js +412 -0
- package/dist/core-runtime/llm/dispatch-fallback-adapter-capabilities.js +33 -0
- package/dist/core-runtime/llm/llm-caller.js +316 -35
- package/dist/core-runtime/llm/mock-llm-realization.js +35 -4
- package/dist/core-runtime/llm/model-switcher.js +1 -1
- package/dist/core-runtime/llm/openai-responses-incomplete-error.js +46 -0
- package/dist/core-runtime/llm/sealed-dispatch-capability.js +359 -0
- package/dist/core-runtime/llm/structured-dispatch-error.js +15 -0
- package/dist/core-runtime/onboard/claude-profile-scan.js +65 -0
- package/dist/core-runtime/onboard/cli-host.js +5 -2
- package/dist/core-runtime/onboard/configure-provider.js +33 -1
- package/dist/core-runtime/onboard/host-target.js +28 -3
- package/dist/core-runtime/onboard/register.js +54 -12
- package/dist/core-runtime/pipeline-execution-ledger.js +10 -0
- package/dist/core-runtime/reconstruct/artifact-types.js +37 -0
- package/dist/core-runtime/reconstruct/benchmark-evidence.js +16 -0
- package/dist/core-runtime/reconstruct/claim-projection-validation.js +19 -5
- package/dist/core-runtime/reconstruct/competency-projection-contract.js +63 -0
- package/dist/core-runtime/reconstruct/comprehension-artifact.js +321 -0
- package/dist/core-runtime/reconstruct/comprehension-reduce.js +367 -0
- package/dist/core-runtime/reconstruct/comprehension-semantic-map.js +771 -0
- package/dist/core-runtime/reconstruct/contract-registry.js +20 -0
- package/dist/core-runtime/reconstruct/directive-validation.js +4 -3
- package/dist/core-runtime/reconstruct/dispatch-fallback-artifacts.js +640 -0
- package/dist/core-runtime/reconstruct/execution-telemetry.js +84 -9
- package/dist/core-runtime/reconstruct/final-output-sections.js +89 -0
- package/dist/core-runtime/reconstruct/governing-snapshot.js +36 -1
- package/dist/core-runtime/reconstruct/leaf-reader.js +305 -0
- package/dist/core-runtime/reconstruct/llm-dispatch-failure.js +270 -0
- package/dist/core-runtime/reconstruct/llm-touch-fingerprint.js +94 -0
- package/dist/core-runtime/reconstruct/material-admission-validation.js +20 -5
- package/dist/core-runtime/reconstruct/material-profile-validation.js +24 -6
- package/dist/core-runtime/reconstruct/materialize-preparation.js +380 -23
- package/dist/core-runtime/reconstruct/maturation-validation.js +1522 -67
- package/dist/core-runtime/reconstruct/mock-llm-realization.js +120 -1
- package/dist/core-runtime/reconstruct/obligation-assertion.js +18 -0
- package/dist/core-runtime/reconstruct/ontology-seed-validation.js +39 -7
- package/dist/core-runtime/reconstruct/output-budget.js +6 -0
- package/dist/core-runtime/reconstruct/pipeline-execution-ledger.js +112 -5
- package/dist/core-runtime/reconstruct/post-seed-validation.js +122 -11
- package/dist/core-runtime/reconstruct/proof-authority-validation.js +2 -6
- package/dist/core-runtime/reconstruct/purpose-authority-validation.js +119 -7
- package/dist/core-runtime/reconstruct/record.js +49 -3
- package/dist/core-runtime/reconstruct/registry-verification-validation.js +41 -5
- package/dist/core-runtime/reconstruct/run-control-validation.js +1019 -37
- package/dist/core-runtime/reconstruct/run.js +5409 -517
- package/dist/core-runtime/reconstruct/seed-authoring-readiness-validation.js +56 -8
- package/dist/core-runtime/reconstruct/semantic-quality-gate.js +112 -7
- package/dist/core-runtime/reconstruct/source-observation-delta-validation.js +53 -5
- package/dist/core-runtime/reconstruct/source-observations.js +166 -0
- package/dist/core-runtime/reconstruct/source-safety-validation.js +77 -188
- package/dist/core-runtime/reconstruct/source-scout-pack-validation.js +50 -6
- package/dist/core-runtime/reconstruct/terminal-validation.js +145 -13
- package/dist/core-runtime/review/continuation-plan.js +12 -5
- package/dist/core-runtime/review/issue-artifact-runtime.js +4 -1
- package/dist/core-runtime/review/materializers.js +100 -11
- package/dist/core-runtime/review/nesting-batch.js +6 -2
- package/dist/core-runtime/review/obligation-shardability.js +138 -0
- package/dist/core-runtime/review/pipeline-execution-ledger.js +42 -2
- package/dist/core-runtime/review/review-artifact-utils.js +219 -7
- package/dist/core-runtime/review/review-execution-steps.js +32 -8
- package/dist/core-runtime/review/review-progress-contract.js +8 -0
- package/dist/core-runtime/review/review-prompt-budget.js +97 -0
- package/dist/core-runtime/review/semantic-quality-gate.js +33 -7
- package/dist/core-runtime/review/spreadsheet-review-disposition.js +94 -0
- package/dist/core-runtime/route-identity.js +182 -0
- package/dist/core-runtime/spreadsheet-header-escalation.js +204 -0
- package/dist/core-runtime/spreadsheet-structure-observer.js +2689 -0
- package/dist/core-runtime/target-material-kind.js +58 -0
- package/dist/mcp/server.js +27 -5
- package/dist/mcp/tool-schemas.js +8 -0
- package/dist/tui/app.js +167 -0
- package/dist/tui/data/event-follower.js +116 -0
- package/dist/tui/data/node-detail.js +42 -0
- package/dist/tui/data/projection-poll.js +26 -0
- package/dist/tui/data/session-discovery.js +65 -0
- package/dist/tui/index.js +108 -0
- package/dist/tui/screens/log.js +25 -0
- package/dist/tui/screens/node-detail.js +17 -0
- package/dist/tui/screens/session-selector.js +26 -0
- package/dist/tui/screens/workflow-tree.js +90 -0
- package/dist/tui/view-model/reconstruct-adapter.js +162 -0
- package/dist/tui/view-model/review-adapter.js +270 -0
- package/dist/tui/view-model/tree-view-model.js +19 -0
- package/package.json +20 -3
- package/settings.example.json +77 -16
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
2
|
+
// ComprehensionArtifact (§5.7) — the governance contract that guarantees every
|
|
3
|
+
// consumer receives the SAME complete set of dimensions, so a consumer can never
|
|
4
|
+
// silently drop a capped status, a lower-bound flag, a boundary witness, or a safety
|
|
5
|
+
// tier. Completeness is fail-closed: a silently-missing baseline field is a contract
|
|
6
|
+
// violation, never "empty = safe" (§5.7 2nd issue-002).
|
|
7
|
+
//
|
|
8
|
+
// Two editions share this one contract (P1-C2-A §11 R1):
|
|
9
|
+
// - DETERMINISTIC (P1-C1): the COMPANION embedded in the source observation; LLM-free,
|
|
10
|
+
// rebuilt from the inventory every run (Layer 1). producer_kind='deterministic',
|
|
11
|
+
// leaf_read_attempt='not_attempted', every LLM-touch field not_applicable.
|
|
12
|
+
// - LLM (P1-C2-A): a SEPARATE Layer-2 authored artifact carrying the provisional label
|
|
13
|
+
// read for low-confidence regions (§3.2). producer_kind='llm', leaf_read_attempt='produced',
|
|
14
|
+
// leaf-read-owned fields PRESENT, persisted+reused under llm_touch_fingerprint.
|
|
15
|
+
//
|
|
16
|
+
// A failed/empty leaf-read attempt NEVER masquerades as an 'llm' producer with all
|
|
17
|
+
// fields deferred (the gate's convergent loophole — onto issue-001/003/004 / ultracode
|
|
18
|
+
// T4/T6): content provenance (producer_kind) is split from attempt provenance
|
|
19
|
+
// (leaf_read_attempt), an 'llm' producer MUST carry produced leaf-read content, and
|
|
20
|
+
// `deferred` is allowed ONLY for engine-not-yet fields on a stage-scoped allowlist.
|
|
21
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
22
|
+
/** Edited whenever the baseline field SET or its semantics change; folded into the reconstruct
|
|
23
|
+
* reuse digest (§12 T2) so a seed authored under an older/weaker contract fails the resume
|
|
24
|
+
* provenance check rather than being silently reused. Bumped 1→2 for the P1-C2-A LLM edition
|
|
25
|
+
* (leaf_read_attempt provenance + provisional label fields). */
|
|
26
|
+
export const COMPREHENSION_ARTIFACT_CONTRACT_VERSION = 2;
|
|
27
|
+
export const LEAF_SEMANTIC_ROLES = [
|
|
28
|
+
"category",
|
|
29
|
+
"measure",
|
|
30
|
+
"identifier",
|
|
31
|
+
"free_text",
|
|
32
|
+
"reference",
|
|
33
|
+
];
|
|
34
|
+
/** Deterministic baseline fields: PRESENT (or explicit absence with lineage) in both editions. */
|
|
35
|
+
const DETERMINISTIC_BASELINE_FIELDS = [
|
|
36
|
+
"region_identity",
|
|
37
|
+
"value_signature_tile_witness",
|
|
38
|
+
"capped_or_frontier_state",
|
|
39
|
+
"is_lower_bound_by_claim",
|
|
40
|
+
"evidence_quality",
|
|
41
|
+
"examples",
|
|
42
|
+
];
|
|
43
|
+
/** Leaf-read-owned LLM-touch fields: PRESENT when producer_kind='llm' (§11 R4 required-PRESENT
|
|
44
|
+
* guard); never `deferred`. not_applicable only for a deterministic producer. */
|
|
45
|
+
const LEAF_READ_OWNED_FIELDS = [
|
|
46
|
+
"spine_claims",
|
|
47
|
+
"confidence_by_claim",
|
|
48
|
+
"limiting_witness",
|
|
49
|
+
];
|
|
50
|
+
/** Engine-not-yet LLM-touch fields: the ONLY fields allowed to be `deferred` in P1-C2-A
|
|
51
|
+
* (the stage-scoped deferred allowlist — onto issue-003 / §11 R4c). triage·reduce = next cut. */
|
|
52
|
+
const ENGINE_DEFERRABLE_FIELDS = [
|
|
53
|
+
"semantic_depth",
|
|
54
|
+
"consumer_handoff_notes",
|
|
55
|
+
"relation_obligation_lifecycle_state",
|
|
56
|
+
"downstream_blocking_semantics",
|
|
57
|
+
"trigger_provenance",
|
|
58
|
+
"triage_audit_status",
|
|
59
|
+
];
|
|
60
|
+
const LLM_TOUCH_BASELINE_FIELDS = [
|
|
61
|
+
...LEAF_READ_OWNED_FIELDS,
|
|
62
|
+
...ENGINE_DEFERRABLE_FIELDS,
|
|
63
|
+
];
|
|
64
|
+
const ENGINE_DEFERRABLE_SET = new Set(ENGINE_DEFERRABLE_FIELDS);
|
|
65
|
+
/** Stable descriptor of the contract SHAPE (version + baseline field sets). Folded into the source-
|
|
66
|
+
* observations reuse digest (§12 T2) so editing the baseline set rotates the resume key
|
|
67
|
+
* tautologically — a seed authored under an older/weaker contract then fails the provenance check. */
|
|
68
|
+
export const COMPREHENSION_ARTIFACT_CONTRACT_DESCRIPTOR = {
|
|
69
|
+
version: COMPREHENSION_ARTIFACT_CONTRACT_VERSION,
|
|
70
|
+
deterministic_fields: [...DETERMINISTIC_BASELINE_FIELDS],
|
|
71
|
+
leaf_read_owned_fields: [...LEAF_READ_OWNED_FIELDS],
|
|
72
|
+
engine_deferrable_fields: [...ENGINE_DEFERRABLE_FIELDS],
|
|
73
|
+
};
|
|
74
|
+
const VALID_ABSENCE_STATUS = new Set(["unknown", "deferred", "not_applicable"]);
|
|
75
|
+
const VALID_ATTEMPT_STATUS = new Set([
|
|
76
|
+
"not_attempted",
|
|
77
|
+
"produced",
|
|
78
|
+
"unread",
|
|
79
|
+
"failed",
|
|
80
|
+
]);
|
|
81
|
+
const VALID_SAFETY_TIERS = new Set([
|
|
82
|
+
"consumption_allowed",
|
|
83
|
+
"internal_only",
|
|
84
|
+
"no_prompt_use",
|
|
85
|
+
"no_replay_use",
|
|
86
|
+
]);
|
|
87
|
+
function isAbsence(value) {
|
|
88
|
+
return (typeof value === "object" &&
|
|
89
|
+
value !== null &&
|
|
90
|
+
!Array.isArray(value) &&
|
|
91
|
+
"status" in value &&
|
|
92
|
+
"lineage" in value);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Completeness + honesty validator (§5.7; §12 T3/T4; §11 R4). Fail-closed. Beyond the P1-C1
|
|
96
|
+
* completeness rules it enforces the gate's convergent anti-loophole contract:
|
|
97
|
+
* - leaf_read_attempt (content↔attempt provenance split) is present, valid, and COUPLED to
|
|
98
|
+
* producer_kind: an 'llm' producer requires attempt='produced'; an unread/failed attempt must
|
|
99
|
+
* degrade to 'deterministic'; a 'produced' attempt requires an 'llm' producer.
|
|
100
|
+
* - when producer_kind='llm', every leaf-read-owned field is PRESENT (never absent) — a failed
|
|
101
|
+
* read cannot pass as a successful production with deferred placeholders.
|
|
102
|
+
* - `deferred` is allowed ONLY for engine-not-yet fields on the stage allowlist.
|
|
103
|
+
* Pushes onto `violations` (mirrors validateSpreadsheetObservationHonesty); empty = valid.
|
|
104
|
+
*/
|
|
105
|
+
export function validateComprehensionArtifact(artifact, violations) {
|
|
106
|
+
if (artifact.contract_version !== COMPREHENSION_ARTIFACT_CONTRACT_VERSION) {
|
|
107
|
+
violations.push(`comprehension_artifact.contract_version must be ${COMPREHENSION_ARTIFACT_CONTRACT_VERSION}`);
|
|
108
|
+
}
|
|
109
|
+
if (!artifact.observation_id || !artifact.observation_id.trim()) {
|
|
110
|
+
violations.push("comprehension_artifact.observation_id is required");
|
|
111
|
+
}
|
|
112
|
+
if (!VALID_SAFETY_TIERS.has(artifact.safety_visibility_tier)) {
|
|
113
|
+
violations.push("comprehension_artifact.safety_visibility_tier is invalid");
|
|
114
|
+
}
|
|
115
|
+
const producerKind = artifact.provenance?.producer_kind;
|
|
116
|
+
if (producerKind !== "deterministic" &&
|
|
117
|
+
producerKind !== "llm" &&
|
|
118
|
+
producerKind !== "vision-assist") {
|
|
119
|
+
violations.push("comprehension_artifact.provenance.producer_kind is invalid");
|
|
120
|
+
}
|
|
121
|
+
// ── attempt provenance + coupling to content provenance (§11 R4) ──
|
|
122
|
+
const attempt = artifact.provenance?.leaf_read_attempt;
|
|
123
|
+
if (!attempt || !VALID_ATTEMPT_STATUS.has(attempt.status)) {
|
|
124
|
+
violations.push("comprehension_artifact.provenance.leaf_read_attempt.status is invalid");
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
if (typeof attempt.lineage !== "string" || attempt.lineage.trim() === "") {
|
|
128
|
+
violations.push("comprehension_artifact.provenance.leaf_read_attempt.lineage must not be blank");
|
|
129
|
+
}
|
|
130
|
+
if (producerKind === "llm" && attempt.status !== "produced") {
|
|
131
|
+
violations.push("comprehension_artifact: producer_kind='llm' requires leaf_read_attempt.status='produced' (an attempted-but-unread/failed read must degrade to a deterministic producer)");
|
|
132
|
+
}
|
|
133
|
+
if ((attempt.status === "unread" || attempt.status === "failed") && producerKind !== "deterministic") {
|
|
134
|
+
violations.push("comprehension_artifact: an unread/failed leaf_read_attempt must degrade to producer_kind='deterministic'");
|
|
135
|
+
}
|
|
136
|
+
if (attempt.status === "produced" && producerKind === "deterministic") {
|
|
137
|
+
violations.push("comprehension_artifact: leaf_read_attempt.status='produced' requires an llm producer_kind");
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const checkBaseline = (name, value, isLlmTouch) => {
|
|
141
|
+
if (value === undefined || value === null) {
|
|
142
|
+
violations.push(`comprehension_artifact.${name} is silently absent (must be present or explicit)`);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
if (isAbsence(value)) {
|
|
146
|
+
if (!VALID_ABSENCE_STATUS.has(value.status)) {
|
|
147
|
+
violations.push(`comprehension_artifact.${name} absence status is invalid`);
|
|
148
|
+
}
|
|
149
|
+
if (typeof value.lineage !== "string" || value.lineage.trim() === "") {
|
|
150
|
+
violations.push(`comprehension_artifact.${name} absence lineage must not be blank`);
|
|
151
|
+
}
|
|
152
|
+
// T4: an LLM-touch field may be `not_applicable` ONLY for a deterministic producer.
|
|
153
|
+
if (isLlmTouch && value.status === "not_applicable" && producerKind !== "deterministic") {
|
|
154
|
+
violations.push(`comprehension_artifact.${name} not_applicable is only allowed when producer_kind is deterministic`);
|
|
155
|
+
}
|
|
156
|
+
// §11 R4c: `deferred` is allowed ONLY for engine-not-yet fields on the stage allowlist —
|
|
157
|
+
// a leaf-read-owned field may never be quietly deferred (loophole: onto issue-003).
|
|
158
|
+
if (isLlmTouch && value.status === "deferred" && !ENGINE_DEFERRABLE_SET.has(name)) {
|
|
159
|
+
violations.push(`comprehension_artifact.${name} may not be 'deferred' (not on the P1-C2-A deferred allowlist; a leaf-read-owned field must be produced or the region must degrade to deterministic)`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
// a PRESENT value satisfies completeness; field-shape checks live in the producers/types.
|
|
163
|
+
};
|
|
164
|
+
for (const name of DETERMINISTIC_BASELINE_FIELDS) {
|
|
165
|
+
checkBaseline(name, artifact[name], false);
|
|
166
|
+
}
|
|
167
|
+
for (const name of LLM_TOUCH_BASELINE_FIELDS) {
|
|
168
|
+
checkBaseline(name, artifact[name], true);
|
|
169
|
+
}
|
|
170
|
+
// §11 R4 required-PRESENT guard: a successful llm production must actually carry leaf-read
|
|
171
|
+
// content — the loophole both families flagged (producer='llm' + all-deferred passing as success).
|
|
172
|
+
if (producerKind === "llm") {
|
|
173
|
+
for (const name of LEAF_READ_OWNED_FIELDS) {
|
|
174
|
+
const value = artifact[name];
|
|
175
|
+
if (isAbsence(value)) {
|
|
176
|
+
violations.push(`comprehension_artifact.${name} must be PRESENT when producer_kind='llm' (leaf-read-owned field cannot be '${value.status}')`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const NOT_APPLICABLE_LINEAGE = "no semantic reading for this region; deterministic value-tile sidecar only (LLM leaf-read = P1-C2-A llm edition)";
|
|
182
|
+
const ENGINE_DEFERRED_LINEAGE = "triage·reduce engine not built yet (P1-C2-B/C); this cut reads leaf labels only";
|
|
183
|
+
function notApplicable() {
|
|
184
|
+
return { status: "not_applicable", lineage: NOT_APPLICABLE_LINEAGE };
|
|
185
|
+
}
|
|
186
|
+
function engineDeferred() {
|
|
187
|
+
return { status: "deferred", lineage: ENGINE_DEFERRED_LINEAGE };
|
|
188
|
+
}
|
|
189
|
+
function deriveDeterministicBaseline(inventory) {
|
|
190
|
+
const tiles = inventory.segmented_value_tiles ?? [];
|
|
191
|
+
const boundaries = tiles.flatMap((sheet) => sheet.columns.flatMap((col) => col.intra_tile_notes.map((note) => ({
|
|
192
|
+
sheet: sheet.sheet,
|
|
193
|
+
column_index: col.column_index,
|
|
194
|
+
boundary_kind: note.boundary_kind,
|
|
195
|
+
prev_shape: note.prev_shape,
|
|
196
|
+
new_shape: note.new_shape,
|
|
197
|
+
last_prev_format_row: note.last_prev_format_row,
|
|
198
|
+
first_new_format_row: note.first_new_format_row,
|
|
199
|
+
}))));
|
|
200
|
+
const segmentsCapped = tiles.some((sheet) => sheet.columns.some((col) => col.segments_capped));
|
|
201
|
+
const distinctIsLowerBound = tiles.some((sheet) => sheet.columns.some((col) => col.segments.some((seg) => seg.distinct_is_lower_bound)));
|
|
202
|
+
const sheets = inventory.sheets.map((s) => s.name);
|
|
203
|
+
const rowExtents = inventory.sheets.map((s) => s.dimensions.rows).filter((r) => r > 0);
|
|
204
|
+
const rowSpan = rowExtents.length > 0 ? { min: 1, max: Math.max(...rowExtents) } : null;
|
|
205
|
+
// examples = canonical value-tile witnesses (a bounded rendering of "where the shape/format
|
|
206
|
+
// changes"). The downstream LLM names what each change MEANS; the code never names it.
|
|
207
|
+
const examples = boundaries
|
|
208
|
+
.slice(0, 16)
|
|
209
|
+
.map((b) => `${b.sheet}!col${b.column_index} ${b.boundary_kind} ${b.prev_shape}→${b.new_shape} @row${b.first_new_format_row}`);
|
|
210
|
+
return {
|
|
211
|
+
region_identity: { sheets, row_span: rowSpan },
|
|
212
|
+
value_signature_tile_witness: { boundaries, boundaries_are_lower_bound: segmentsCapped },
|
|
213
|
+
capped_or_frontier_state: { segments_capped: segmentsCapped, distinct_is_lower_bound: distinctIsLowerBound },
|
|
214
|
+
is_lower_bound_by_claim: segmentsCapped || distinctIsLowerBound,
|
|
215
|
+
examples,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Build the DETERMINISTIC-edition ComprehensionArtifact embedded in the source observation
|
|
220
|
+
* (§4; P1-C1). Pure + LLM-free — the COMPANION that stays Layer-1 (its reuse stays content-hash
|
|
221
|
+
* gated; §11 R1 keeps the LLM leaf-read in a SEPARATE artifact). `leafReadAttempt` defaults to
|
|
222
|
+
* 'not_attempted'; pass 'unread'/'failed' to record an attempted-but-degraded read (§11 R9).
|
|
223
|
+
*/
|
|
224
|
+
export function buildDeterministicComprehensionArtifact(args) {
|
|
225
|
+
const base = deriveDeterministicBaseline(args.inventory);
|
|
226
|
+
return {
|
|
227
|
+
contract_version: COMPREHENSION_ARTIFACT_CONTRACT_VERSION,
|
|
228
|
+
observation_id: args.observationId,
|
|
229
|
+
region_identity: base.region_identity,
|
|
230
|
+
value_signature_tile_witness: base.value_signature_tile_witness,
|
|
231
|
+
provenance: {
|
|
232
|
+
producer_kind: "deterministic",
|
|
233
|
+
epoch_fingerprint_contribution: null,
|
|
234
|
+
leaf_read_attempt: args.leafReadAttempt ?? {
|
|
235
|
+
status: "not_attempted",
|
|
236
|
+
lineage: "deterministic companion; no LLM leaf-read run for this observation",
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
safety_visibility_tier: "consumption_allowed",
|
|
240
|
+
capped_or_frontier_state: base.capped_or_frontier_state,
|
|
241
|
+
is_lower_bound_by_claim: base.is_lower_bound_by_claim,
|
|
242
|
+
evidence_quality: "structural_only",
|
|
243
|
+
examples: base.examples,
|
|
244
|
+
spine_claims: notApplicable(),
|
|
245
|
+
confidence_by_claim: notApplicable(),
|
|
246
|
+
limiting_witness: notApplicable(),
|
|
247
|
+
semantic_depth: notApplicable(),
|
|
248
|
+
consumer_handoff_notes: notApplicable(),
|
|
249
|
+
relation_obligation_lifecycle_state: notApplicable(),
|
|
250
|
+
downstream_blocking_semantics: notApplicable(),
|
|
251
|
+
trigger_provenance: notApplicable(),
|
|
252
|
+
triage_audit_status: notApplicable(),
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Build the LLM-edition ComprehensionArtifact — the SEPARATE Layer-2 authored artifact carrying the
|
|
257
|
+
* provisional label read for low-confidence regions (§11 R1/R4/R5/R7/R11). producer_kind='llm',
|
|
258
|
+
* leaf_read_attempt='produced', leaf-read-owned fields PRESENT, engine fields explicitly deferred.
|
|
259
|
+
* `fingerprint` = the llm_touch_fingerprint (ⓐ+ⓑ) gating this artifact's reuse (provenance only).
|
|
260
|
+
* Deterministic baseline fields are still inventory-derived (LLM-free); the artifact is producer_kind
|
|
261
|
+
* 'llm' because it CARRIES llm content.
|
|
262
|
+
*/
|
|
263
|
+
export function buildLlmComprehensionArtifact(args) {
|
|
264
|
+
if (args.leafRead.labels.length === 0) {
|
|
265
|
+
// Guard: an empty read is NOT a production — callers must route it to the degraded
|
|
266
|
+
// deterministic builder (status='unread'). Fail loud rather than emit an llm artifact
|
|
267
|
+
// with no content (which the validator would reject anyway).
|
|
268
|
+
throw new Error("buildLlmComprehensionArtifact requires ≥1 produced label; route an empty read to buildDeterministicComprehensionArtifact({leafReadAttempt:{status:'unread'}})");
|
|
269
|
+
}
|
|
270
|
+
const base = deriveDeterministicBaseline(args.inventory);
|
|
271
|
+
const spineClaims = args.leafRead.labels.map((label) => {
|
|
272
|
+
const claim = {
|
|
273
|
+
claim_kind: "provisional_label_read",
|
|
274
|
+
authority: "non_authoritative",
|
|
275
|
+
sheet: label.sheet,
|
|
276
|
+
column_index: label.column_index,
|
|
277
|
+
tentative_label: label.tentative_label,
|
|
278
|
+
};
|
|
279
|
+
if (label.semantic_role)
|
|
280
|
+
claim.semantic_role = label.semantic_role;
|
|
281
|
+
if (label.captured_note)
|
|
282
|
+
claim.captured_note = label.captured_note;
|
|
283
|
+
return claim;
|
|
284
|
+
});
|
|
285
|
+
const confidenceByClaim = args.leafRead.labels.map((label) => ({
|
|
286
|
+
claim_ref: `${label.sheet}!col${label.column_index}`,
|
|
287
|
+
confidence: label.confidence,
|
|
288
|
+
is_lower_bound: label.is_lower_bound,
|
|
289
|
+
}));
|
|
290
|
+
return {
|
|
291
|
+
contract_version: COMPREHENSION_ARTIFACT_CONTRACT_VERSION,
|
|
292
|
+
observation_id: args.observationId,
|
|
293
|
+
region_identity: base.region_identity,
|
|
294
|
+
value_signature_tile_witness: base.value_signature_tile_witness,
|
|
295
|
+
provenance: {
|
|
296
|
+
producer_kind: "llm",
|
|
297
|
+
epoch_fingerprint_contribution: args.fingerprint,
|
|
298
|
+
leaf_read_attempt: {
|
|
299
|
+
status: "produced",
|
|
300
|
+
lineage: `leaf-read produced ${args.leafRead.labels.length} provisional label(s) for low-confidence region(s)`,
|
|
301
|
+
},
|
|
302
|
+
},
|
|
303
|
+
safety_visibility_tier: "consumption_allowed",
|
|
304
|
+
capped_or_frontier_state: base.capped_or_frontier_state,
|
|
305
|
+
is_lower_bound_by_claim: base.is_lower_bound_by_claim, // DETERMINISTIC; leaf bound lives in confidence_by_claim.
|
|
306
|
+
evidence_quality: "structural_plus_provisional_label",
|
|
307
|
+
examples: base.examples,
|
|
308
|
+
spine_claims: spineClaims,
|
|
309
|
+
confidence_by_claim: confidenceByClaim,
|
|
310
|
+
limiting_witness: {
|
|
311
|
+
region_ref: args.leafRead.limiting_region_ref,
|
|
312
|
+
reason: args.leafRead.limiting_reason,
|
|
313
|
+
},
|
|
314
|
+
semantic_depth: engineDeferred(),
|
|
315
|
+
consumer_handoff_notes: engineDeferred(),
|
|
316
|
+
relation_obligation_lifecycle_state: engineDeferred(),
|
|
317
|
+
downstream_blocking_semantics: engineDeferred(),
|
|
318
|
+
trigger_provenance: engineDeferred(),
|
|
319
|
+
triage_audit_status: engineDeferred(),
|
|
320
|
+
};
|
|
321
|
+
}
|