@sentropic/h2a 0.98.6 → 0.98.7-rc.10
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/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +2 -1
- package/dist/bin-routing.d.ts.map +1 -1
- package/dist/bin-routing.js +23 -3
- package/dist/bin-routing.js.map +1 -1
- package/dist/bin.js +51 -4
- package/dist/bin.js.map +1 -1
- package/dist/cli-command-map.d.ts.map +1 -1
- package/dist/cli-command-map.js +1 -0
- package/dist/cli-command-map.js.map +1 -1
- package/dist/cli-contract.js +2 -2
- package/dist/cli-contract.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +270 -45
- package/dist/cli.js.map +1 -1
- package/dist/focus-build.d.ts +10 -0
- package/dist/focus-build.d.ts.map +1 -0
- package/dist/focus-build.js +202 -0
- package/dist/focus-build.js.map +1 -0
- package/dist/focus-feedback.d.ts +30 -0
- package/dist/focus-feedback.d.ts.map +1 -0
- package/dist/focus-feedback.js +133 -0
- package/dist/focus-feedback.js.map +1 -0
- package/dist/hosts/agy.js +1 -1
- package/dist/hosts/agy.js.map +1 -1
- package/dist/hosts/installation-doctor.d.ts +1 -0
- package/dist/hosts/installation-doctor.d.ts.map +1 -1
- package/dist/hosts/installation-doctor.js +1 -1
- package/dist/hosts/installation-doctor.js.map +1 -1
- package/dist/hosts/muse.d.ts.map +1 -1
- package/dist/hosts/muse.js +2 -4
- package/dist/hosts/muse.js.map +1 -1
- package/dist/hosts/native-artifacts.d.ts +33 -0
- package/dist/hosts/native-artifacts.d.ts.map +1 -0
- package/dist/hosts/native-artifacts.js +104 -0
- package/dist/hosts/native-artifacts.js.map +1 -0
- package/dist/hosts/native-catalog.d.ts +19 -0
- package/dist/hosts/native-catalog.d.ts.map +1 -0
- package/dist/hosts/native-catalog.js +14 -0
- package/dist/hosts/native-catalog.js.map +1 -0
- package/dist/hosts/native-convergence.d.ts +169 -0
- package/dist/hosts/native-convergence.d.ts.map +1 -0
- package/dist/hosts/native-convergence.js +152 -0
- package/dist/hosts/native-convergence.js.map +1 -0
- package/dist/hosts/native-files.d.ts +46 -0
- package/dist/hosts/native-files.d.ts.map +1 -0
- package/dist/hosts/native-files.js +136 -0
- package/dist/hosts/native-files.js.map +1 -0
- package/dist/hosts/native-inspection.d.ts +31 -0
- package/dist/hosts/native-inspection.d.ts.map +1 -0
- package/dist/hosts/native-inspection.js +79 -0
- package/dist/hosts/native-inspection.js.map +1 -0
- package/dist/hosts/native-paths.d.ts +11 -0
- package/dist/hosts/native-paths.d.ts.map +1 -0
- package/dist/hosts/native-paths.js +21 -0
- package/dist/hosts/native-paths.js.map +1 -0
- package/dist/hosts/native-proof.d.ts +32 -0
- package/dist/hosts/native-proof.d.ts.map +1 -0
- package/dist/hosts/native-proof.js +31 -0
- package/dist/hosts/native-proof.js.map +1 -0
- package/dist/hosts/native-questions.d.ts +2 -0
- package/dist/hosts/native-questions.d.ts.map +1 -0
- package/dist/hosts/native-questions.js +22 -0
- package/dist/hosts/native-questions.js.map +1 -0
- package/dist/hosts/native-runtime-record.d.ts +3 -0
- package/dist/hosts/native-runtime-record.d.ts.map +1 -0
- package/dist/hosts/native-runtime-record.js +60 -0
- package/dist/hosts/native-runtime-record.js.map +1 -0
- package/dist/hosts/native-skills.d.ts +24 -0
- package/dist/hosts/native-skills.d.ts.map +1 -0
- package/dist/hosts/native-skills.js +56 -0
- package/dist/hosts/native-skills.js.map +1 -0
- package/dist/hosts/native-toml.d.ts +18 -0
- package/dist/hosts/native-toml.d.ts.map +1 -0
- package/dist/hosts/native-toml.js +93 -0
- package/dist/hosts/native-toml.js.map +1 -0
- package/dist/hosts/operator-notices.d.ts +3 -0
- package/dist/hosts/operator-notices.d.ts.map +1 -0
- package/dist/hosts/operator-notices.js +31 -0
- package/dist/hosts/operator-notices.js.map +1 -0
- package/dist/hosts/plugin.d.ts +30 -0
- package/dist/hosts/plugin.d.ts.map +1 -1
- package/dist/hosts/plugin.js +56 -4
- package/dist/hosts/plugin.js.map +1 -1
- package/dist/hosts/upgrade-equipment.d.ts +42 -0
- package/dist/hosts/upgrade-equipment.d.ts.map +1 -0
- package/dist/hosts/upgrade-equipment.js +26 -0
- package/dist/hosts/upgrade-equipment.js.map +1 -0
- package/dist/hosts/vibe-discovery.d.ts +12 -0
- package/dist/hosts/vibe-discovery.d.ts.map +1 -0
- package/dist/hosts/vibe-discovery.js +33 -0
- package/dist/hosts/vibe-discovery.js.map +1 -0
- package/dist/hosts/vibe-equipment.d.ts +73 -0
- package/dist/hosts/vibe-equipment.d.ts.map +1 -0
- package/dist/hosts/vibe-equipment.js +179 -0
- package/dist/hosts/vibe-equipment.js.map +1 -0
- package/dist/hosts/vibe-mcp.d.ts +32 -0
- package/dist/hosts/vibe-mcp.d.ts.map +1 -0
- package/dist/hosts/vibe-mcp.js +210 -0
- package/dist/hosts/vibe-mcp.js.map +1 -0
- package/dist/hosts/vibe.d.ts +12 -3
- package/dist/hosts/vibe.d.ts.map +1 -1
- package/dist/hosts/vibe.js +15 -7
- package/dist/hosts/vibe.js.map +1 -1
- package/dist/identity-operator-break.d.ts +31 -0
- package/dist/identity-operator-break.d.ts.map +1 -0
- package/dist/identity-operator-break.js +77 -0
- package/dist/identity-operator-break.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/runtime/agy-claude.d.ts +42 -0
- package/dist/runtime/agy-claude.d.ts.map +1 -0
- package/dist/runtime/agy-claude.js +140 -0
- package/dist/runtime/agy-claude.js.map +1 -0
- package/dist/runtime/focus/edit-receipts.d.ts +22 -0
- package/dist/runtime/focus/edit-receipts.d.ts.map +1 -0
- package/dist/runtime/focus/edit-receipts.js +46 -0
- package/dist/runtime/focus/edit-receipts.js.map +1 -0
- package/dist/runtime/live/contracts.d.ts +55 -0
- package/dist/runtime/live/contracts.d.ts.map +1 -0
- package/dist/runtime/live/contracts.js +59 -0
- package/dist/runtime/live/contracts.js.map +1 -0
- package/dist/runtime/local-files/identity-fence.d.ts.map +1 -1
- package/dist/runtime/local-files/identity-fence.js +2 -0
- package/dist/runtime/local-files/identity-fence.js.map +1 -1
- package/dist/runtime/local-files/orphan-gc.d.ts +3 -0
- package/dist/runtime/local-files/orphan-gc.d.ts.map +1 -0
- package/dist/runtime/local-files/orphan-gc.js +69 -0
- package/dist/runtime/local-files/orphan-gc.js.map +1 -0
- package/dist/runtime/local-files/presence.d.ts +5 -2
- package/dist/runtime/local-files/presence.d.ts.map +1 -1
- package/dist/runtime/local-files/presence.js +32 -29
- package/dist/runtime/local-files/presence.js.map +1 -1
- package/dist/runtime/local-files/recipient-hints.d.ts +10 -0
- package/dist/runtime/local-files/recipient-hints.d.ts.map +1 -0
- package/dist/runtime/local-files/recipient-hints.js +156 -0
- package/dist/runtime/local-files/recipient-hints.js.map +1 -0
- package/dist/runtime/local-files/store.d.ts.map +1 -1
- package/dist/runtime/local-files/store.js +22 -2
- package/dist/runtime/local-files/store.js.map +1 -1
- package/dist/runtime/loop/engine/adapters.d.ts.map +1 -1
- package/dist/runtime/loop/engine/adapters.js +7 -1
- package/dist/runtime/loop/engine/adapters.js.map +1 -1
- package/dist/runtime/mcp/agent-launch.d.ts +3 -0
- package/dist/runtime/mcp/agent-launch.d.ts.map +1 -1
- package/dist/runtime/mcp/agent-launch.js +93 -8
- package/dist/runtime/mcp/agent-launch.js.map +1 -1
- package/dist/runtime/mcp/handlers.d.ts +1 -0
- package/dist/runtime/mcp/handlers.d.ts.map +1 -1
- package/dist/runtime/mcp/handlers.js +7 -4
- package/dist/runtime/mcp/handlers.js.map +1 -1
- package/dist/runtime/mcp/notifications.d.ts +2 -1
- package/dist/runtime/mcp/notifications.d.ts.map +1 -1
- package/dist/runtime/mcp/notifications.js +16 -2
- package/dist/runtime/mcp/notifications.js.map +1 -1
- package/dist/runtime/mcp/server.d.ts +3 -0
- package/dist/runtime/mcp/server.d.ts.map +1 -1
- package/dist/runtime/mcp/server.js +19 -6
- package/dist/runtime/mcp/server.js.map +1 -1
- package/dist/runtime/mcp/sessions.d.ts +6 -6
- package/dist/runtime/mcp/sessions.d.ts.map +1 -1
- package/dist/runtime/mcp/sessions.js +18 -6
- package/dist/runtime/mcp/sessions.js.map +1 -1
- package/dist/runtime/mcp/stdio.d.ts.map +1 -1
- package/dist/runtime/mcp/stdio.js +11 -0
- package/dist/runtime/mcp/stdio.js.map +1 -1
- package/dist/runtime/mcp/tools.d.ts.map +1 -1
- package/dist/runtime/mcp/tools.js +11 -7
- package/dist/runtime/mcp/tools.js.map +1 -1
- package/dist/runtime/send.d.ts +10 -0
- package/dist/runtime/send.d.ts.map +1 -1
- package/dist/runtime/send.js +80 -5
- package/dist/runtime/send.js.map +1 -1
- package/dist/runtime/upgrade/index.d.ts +1 -0
- package/dist/runtime/upgrade/index.d.ts.map +1 -1
- package/dist/runtime/upgrade/index.js +1 -0
- package/dist/runtime/upgrade/index.js.map +1 -1
- package/dist/vendor/engram-live/contracts.d.ts +825 -0
- package/dist/vendor/engram-live/contracts.js +1734 -0
- package/fixtures/native-host-catalog.json +1 -0
- package/fixtures/native-host-history.json +1261 -0
- package/fixtures/native-host-renderers.json +1 -0
- package/focus-app/client/_app/immutable/chunks/{unQroC_0.js → BXS4ok-I.js} +2 -2
- package/focus-app/client/_app/immutable/chunks/BXS4ok-I.js.br +0 -0
- package/focus-app/client/_app/immutable/chunks/BXS4ok-I.js.gz +0 -0
- package/focus-app/client/_app/immutable/entry/{app.75Uzo4oj.js → app.BJwKYx8S.js} +2 -2
- package/focus-app/client/_app/immutable/entry/app.BJwKYx8S.js.br +0 -0
- package/focus-app/client/_app/immutable/entry/app.BJwKYx8S.js.gz +0 -0
- package/focus-app/client/_app/immutable/entry/start.to_m_bSO.js +1 -0
- package/focus-app/client/_app/immutable/entry/start.to_m_bSO.js.br +2 -0
- package/focus-app/client/_app/immutable/entry/start.to_m_bSO.js.gz +0 -0
- package/focus-app/client/_app/immutable/nodes/{1.hqfmE-jM.js → 1.CvN150m3.js} +1 -1
- package/focus-app/client/_app/immutable/nodes/1.CvN150m3.js.br +3 -0
- package/focus-app/client/_app/immutable/nodes/1.CvN150m3.js.gz +0 -0
- package/focus-app/client/_app/version.json +1 -1
- package/focus-app/client/_app/version.json.br +0 -0
- package/focus-app/client/_app/version.json.gz +0 -0
- package/focus-app/h2a-focus.json +29 -29
- package/focus-app/handler.js +4 -4
- package/focus-app/index.js +4 -4
- package/focus-app/server/chunks/chunks/{internal.js-vq85iWAx.js → internal.js-BORbEOh-.js} +2 -2
- package/focus-app/server/chunks/chunks/{internal.js-vq85iWAx.js.map → internal.js-BORbEOh-.js.map} +1 -1
- package/focus-app/server/chunks/{handler-f-0S9j72.js → handler-Ccwb0eyC.js} +3 -3
- package/focus-app/server/chunks/{handler-f-0S9j72.js.map → handler-Ccwb0eyC.js.map} +1 -1
- package/focus-app/server/chunks/{index.js-DlbaFcic.js → index.js-CzPOZLjV.js} +2 -2
- package/focus-app/server/chunks/{index.js-DlbaFcic.js.map → index.js-CzPOZLjV.js.map} +1 -1
- package/focus-app/server/chunks/{manifest.js-CxrShg-z.js → manifest.js-E-BEcOes.js} +3 -3
- package/focus-app/server/chunks/{manifest.js-CxrShg-z.js.map → manifest.js-E-BEcOes.js.map} +1 -1
- package/focus-app/server/chunks/nodes/{1.js-O2SZgyXK.js → 1.js-BJ_PpMI-.js} +2 -2
- package/focus-app/server/chunks/nodes/{1.js-O2SZgyXK.js.map → 1.js-BJ_PpMI-.js.map} +1 -1
- package/focus-kit/dossier.evidence.template.json +206 -0
- package/focus-kit/dossier.schema.json +193 -0
- package/focus-kit/dossier.template.json +39 -0
- package/focus-kit/dossier.v2.schema.json +925 -0
- package/focus-kit/ecosystem.json +853 -0
- package/focus-kit/renderer-manifest.json +48 -0
- package/focus-kit/renderer.html +278 -0
- package/focus-kit/validator.mjs +1128 -0
- package/hooks/deny-manual-h2a-cli.mjs +38 -0
- package/hooks/hooks.json +17 -0
- package/hooks/vibe-post-agent.mjs +29 -0
- package/hooks/vibe-pre-tool.mjs +40 -0
- package/hooks/workspace-scope-grant.mjs +22 -0
- package/hooks/workspace-scope-guard.mjs +277 -0
- package/hooks/workspace-scope-shell.mjs +564 -0
- package/hooks/workspace-scope-state.mjs +71 -0
- package/hooks/workspace-scope.opt-in.json +17 -0
- package/package.json +24 -8
- package/scripts/qualification-budget.mjs +56 -0
- package/scripts/qualification-cleanup.mjs +15 -0
- package/scripts/qualification-oracles.mjs +44 -0
- package/scripts/qualification-patch.mjs +21 -0
- package/scripts/qualification-poll-hosts.mjs +19 -0
- package/scripts/qualification-probe.mjs +63 -0
- package/scripts/qualification-rpc.mjs +59 -0
- package/scripts/qualification-vibe.mjs +159 -0
- package/scripts/qualify-host.mjs +143 -0
- package/skills/h2a/SKILL.md +25 -2
- package/skills/h2a-run/SKILL.md +20 -1
- package/skills/harness/SKILL.md +19 -0
- package/skills/harness/track-report/SKILL.md +78 -5
- package/skills/harness/using-harness/SKILL.md +19 -0
- package/focus-app/client/_app/immutable/chunks/unQroC_0.js.br +0 -0
- package/focus-app/client/_app/immutable/chunks/unQroC_0.js.gz +0 -0
- package/focus-app/client/_app/immutable/entry/app.75Uzo4oj.js.br +0 -0
- package/focus-app/client/_app/immutable/entry/app.75Uzo4oj.js.gz +0 -0
- package/focus-app/client/_app/immutable/entry/start.BmwiFFoe.js +0 -1
- package/focus-app/client/_app/immutable/entry/start.BmwiFFoe.js.br +0 -2
- package/focus-app/client/_app/immutable/entry/start.BmwiFFoe.js.gz +0 -0
- package/focus-app/client/_app/immutable/nodes/1.hqfmE-jM.js.br +0 -3
- package/focus-app/client/_app/immutable/nodes/1.hqfmE-jM.js.gz +0 -0
|
@@ -0,0 +1,1128 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
MIT License
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2025 Fabien Antoine
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
|
23
|
+
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
// packages/focus/src/model.ts
|
|
27
|
+
var isEvidenceDossier = (doc) => "schemaVersion" in doc && doc.schemaVersion === 2;
|
|
28
|
+
|
|
29
|
+
// packages/focus/src/validation/readability.ts
|
|
30
|
+
var READABILITY_BUDGETS = { low: 2, medium: 8, high: 30 };
|
|
31
|
+
var READABILITY_LIMITS = {
|
|
32
|
+
minOwnerRequestQuoteLength: 8,
|
|
33
|
+
minStakesLength: 20,
|
|
34
|
+
minQuestionContextLength: 20,
|
|
35
|
+
minOptionsPerQuestion: 2,
|
|
36
|
+
maxOptionsPerQuestion: 4,
|
|
37
|
+
maxQuestionReadingMinutes: 2,
|
|
38
|
+
maxDossierBudgetMinutes: 30,
|
|
39
|
+
wordsPerMinute: 180,
|
|
40
|
+
maxHeadingLength: 100,
|
|
41
|
+
maxDecisionLineLength: 300,
|
|
42
|
+
maxOptionLabelLength: 100,
|
|
43
|
+
maxConsequenceLength: 160,
|
|
44
|
+
maxOptionBodyLength: 300
|
|
45
|
+
};
|
|
46
|
+
var CODE_PATTERN = /\b(?:[A-Z][A-Z0-9]*(?:-[A-Z0-9]+)+|[A-Z][A-Z0-9]*\d[A-Z0-9]*[a-z]?|[A-Z]{2,})\b/g;
|
|
47
|
+
var PLAIN_TOKENS = /* @__PURE__ */ new Set(["GO", "NO-GO", "NO", "PENDING", "DEFERRED", "LR", "RL", "TB", "BT", "TD", "UTF-8"]);
|
|
48
|
+
var CHOICE_PATTERN = /\beither\b[\s\S]{0,160}?\bor\b|\bsoit\b[\s\S]{0,160}?\bsoit\b|\b(?:instead of|rather than|plut[oô]t que|versus|vs\.?|choos(?:e|ing) between|choisir entre)\b/i;
|
|
49
|
+
var SUBOPTION_PATTERN = /(?:^|[\n\r\u2028\u2029])\s*(?:[-*+•‣>]|\d+[.)]|[a-z][.)])\s+\S|\([a-z]\)[\s\S]*\([a-z]\)|\b(?:sub[- ]?options?|sous[- ]?options?)\b/i;
|
|
50
|
+
var LINE_BREAK = /[\n\r\u2028\u2029]/;
|
|
51
|
+
var blank = (text2) => !text2?.trim();
|
|
52
|
+
var asRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
53
|
+
var minutesFor = (texts) => (texts.join(" ").match(/\S+/gu)?.length ?? 0) / READABILITY_LIMITS.wordsPerMinute;
|
|
54
|
+
var validateDecisionDossierReadability = (doc) => {
|
|
55
|
+
const issues = [];
|
|
56
|
+
const refuse = (path, code, message) => {
|
|
57
|
+
issues.push({ path, code, message });
|
|
58
|
+
};
|
|
59
|
+
const r = doc.readability;
|
|
60
|
+
const quote = r?.ownerRequestQuote?.trim() ?? "";
|
|
61
|
+
if (r?.noOwnerRequest === true) {
|
|
62
|
+
refuse(
|
|
63
|
+
"$.readability.noOwnerRequest",
|
|
64
|
+
quote ? "conflicting_owner_request" : "presentation_blocked",
|
|
65
|
+
quote ? "A quoted owner request conflicts with noOwnerRequest: keep the literal request and remove the flag." : "No owner request: presentation is blocked until the owner's literal request is quoted."
|
|
66
|
+
);
|
|
67
|
+
} else if (!quote) {
|
|
68
|
+
refuse("$.readability.ownerRequestQuote", "missing_owner_request", "Quote the literal owner request this dossier serves, or set noOwnerRequest to block presentation explicitly.");
|
|
69
|
+
} else if (quote.length < READABILITY_LIMITS.minOwnerRequestQuoteLength) {
|
|
70
|
+
refuse("$.readability.ownerRequestQuote", "owner_request_too_short", "Quote the full literal owner request so the owner recognizes their own intention.");
|
|
71
|
+
}
|
|
72
|
+
if (blank(r?.stakes)) {
|
|
73
|
+
refuse("$.readability.stakes", "missing_stakes", "State why the decision matters to the owner, using plain words about cost, time or consequences.");
|
|
74
|
+
} else if (r.stakes.trim().length < READABILITY_LIMITS.minStakesLength) {
|
|
75
|
+
refuse("$.readability.stakes", "stakes_too_short", "Explain the actual consequence for the owner in at least 20 characters; an internal label is insufficient.");
|
|
76
|
+
}
|
|
77
|
+
const level = r?.stakesLevel;
|
|
78
|
+
if (!level || !Object.hasOwn(READABILITY_BUDGETS, level)) {
|
|
79
|
+
refuse("$.readability.stakesLevel", "missing_stakes_level", "Declare stakesLevel: low for a small reversible inconvenience, medium for cost/disruption, high for lasting or major impact.");
|
|
80
|
+
}
|
|
81
|
+
const budget = r?.readingBudgetMinutes;
|
|
82
|
+
const budgetValid = budget !== void 0 && Number.isFinite(budget) && budget >= 1 && budget <= READABILITY_LIMITS.maxDossierBudgetMinutes;
|
|
83
|
+
if (budget === void 0) {
|
|
84
|
+
refuse("$.readability.readingBudgetMinutes", "missing_reading_budget", "Declare a total reading budget in minutes proportionate to the stakes: low up to 2, medium up to 8, high up to 30.");
|
|
85
|
+
} else if (!budgetValid) {
|
|
86
|
+
refuse("$.readability.readingBudgetMinutes", "reading_budget_out_of_range", "The total reading budget must be a finite number between 1 and 30 minutes.");
|
|
87
|
+
} else if (level && Object.hasOwn(READABILITY_BUDGETS, level) && budget > READABILITY_BUDGETS[level]) {
|
|
88
|
+
refuse("$.readability.readingBudgetMinutes", "reading_budget_disproportionate", `The ${level} stakes budget is at most ${READABILITY_BUDGETS[level]} minutes; shorten this dossier or justify a different stakes level.`);
|
|
89
|
+
}
|
|
90
|
+
const glossary = /* @__PURE__ */ new Map();
|
|
91
|
+
r?.glossary?.forEach((entry, i) => {
|
|
92
|
+
if (blank(entry.term) || blank(entry.definition)) {
|
|
93
|
+
refuse(`$.readability.glossary[${i}]`, "empty_glossary_entry", "Give every glossary term a definition in plain words visible to the reader.");
|
|
94
|
+
} else {
|
|
95
|
+
const term = entry.term.trim();
|
|
96
|
+
if (glossary.has(term) || entry.definition.trim() === term) {
|
|
97
|
+
refuse(`$.readability.glossary[${i}]`, "invalid_glossary_entry", "Use one definition per term and expand its meaning; repeating the code does not explain it.");
|
|
98
|
+
}
|
|
99
|
+
if ((entry.definition.match(CODE_PATTERN) ?? []).some((code) => !PLAIN_TOKENS.has(code))) {
|
|
100
|
+
refuse(
|
|
101
|
+
`$.readability.glossary[${i}].definition`,
|
|
102
|
+
"invalid_glossary_entry",
|
|
103
|
+
"Explain each term independently in plain words, without itself or another code, even one defined elsewhere."
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
glossary.set(term, entry.definition);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
const checkCodes = (text2, path) => {
|
|
110
|
+
for (const code of new Set(text2?.match(CODE_PATTERN) ?? [])) {
|
|
111
|
+
if (!PLAIN_TOKENS.has(code) && !glossary.has(code)) {
|
|
112
|
+
refuse(path, "undefined_code", `Unexpanded code or acronym "${code}": define it in the visible glossary in plain words, or rewrite it.`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
const shared = [];
|
|
117
|
+
const visible = (text2, path) => {
|
|
118
|
+
checkCodes(text2, path);
|
|
119
|
+
if (text2) shared.push(text2);
|
|
120
|
+
};
|
|
121
|
+
if (isEvidenceDossier(doc)) {
|
|
122
|
+
doc.sources.forEach((s, i) => {
|
|
123
|
+
checkCodes(s.title, `$.sources[${i}].title`);
|
|
124
|
+
checkCodes(s.alt, `$.sources[${i}].alt`);
|
|
125
|
+
});
|
|
126
|
+
doc.citations.forEach((c, i) => {
|
|
127
|
+
checkCodes(c.label, `$.citations[${i}].label`);
|
|
128
|
+
if (c.locator.kind === "image") checkCodes(c.locator.caption, `$.citations[${i}].locator.caption`);
|
|
129
|
+
});
|
|
130
|
+
doc.evidenceGroups.forEach((g, i) => visible(g.summary, `$.evidenceGroups[${i}].summary`));
|
|
131
|
+
doc.annexes.forEach((a, i) => {
|
|
132
|
+
visible(a.title, `$.annexes[${i}].title`);
|
|
133
|
+
visible(a.summary, `$.annexes[${i}].summary`);
|
|
134
|
+
a.blocks.forEach((b, j) => {
|
|
135
|
+
const path = `$.annexes[${i}].blocks[${j}]`;
|
|
136
|
+
if (b.kind === "text") checkCodes(b.text, `${path}.text`);
|
|
137
|
+
if (b.kind === "table") [...b.columns, ...b.rows.flat()].forEach((t) => checkCodes(t, path));
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
for (const field of ["title", "subject"]) {
|
|
142
|
+
visible(doc[field], `$.${field}`);
|
|
143
|
+
if (blank(doc[field])) refuse(
|
|
144
|
+
`$.${field}`,
|
|
145
|
+
"empty_heading",
|
|
146
|
+
"Name the subject and decision in a short, non-empty line the owner understands."
|
|
147
|
+
);
|
|
148
|
+
checkLine(doc[field], `$.${field}`, READABILITY_LIMITS.maxHeadingLength);
|
|
149
|
+
}
|
|
150
|
+
visible(quote, "$.readability.ownerRequestQuote");
|
|
151
|
+
visible(r?.stakes, "$.readability.stakes");
|
|
152
|
+
r?.glossary?.forEach((entry, i) => {
|
|
153
|
+
shared.push(entry.term);
|
|
154
|
+
visible(entry.definition, `$.readability.glossary[${i}].definition`);
|
|
155
|
+
});
|
|
156
|
+
const checkSteps = (steps, path) => {
|
|
157
|
+
steps.forEach((step, i) => {
|
|
158
|
+
visible(step.author, `${path}[${i}].author`);
|
|
159
|
+
visible(step.summary, `${path}[${i}].summary`);
|
|
160
|
+
});
|
|
161
|
+
};
|
|
162
|
+
checkSteps(doc.amendmentTrace, "$.amendmentTrace");
|
|
163
|
+
doc.interactions.forEach((action, i) => visible(action.label, `$.interactions[${i}].label`));
|
|
164
|
+
const questions = doc.sections.filter((s) => s.kind === "question");
|
|
165
|
+
const questionIds = new Set(questions.map((q) => q.id));
|
|
166
|
+
if (!questions.length) refuse("$.sections", "missing_question", "A decision dossier needs an explicit question with context, options and a recommendation.");
|
|
167
|
+
const checkQuestionRef = (questionId, path, required) => {
|
|
168
|
+
if (blank(questionId)) {
|
|
169
|
+
if (required) refuse(path, "hidden_decision", "This content implies a choice without an explicit question: set questionId to the question the owner must answer.");
|
|
170
|
+
} else if (!questionIds.has(questionId)) {
|
|
171
|
+
refuse(path, "unknown_question_ref", `Question "${questionId}" does not exist in this dossier; link to an explicit question.`);
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
const optionSets = doc.sections.filter((s) => s.kind === "optionSet");
|
|
175
|
+
let totalQuestionMinutes = 0;
|
|
176
|
+
doc.sections.forEach((section, i) => {
|
|
177
|
+
const path = `$.sections[${i}]`;
|
|
178
|
+
switch (section.kind) {
|
|
179
|
+
case "prose":
|
|
180
|
+
visible(section.markdown, `${path}.markdown`);
|
|
181
|
+
checkQuestionRef(section.questionId, `${path}.questionId`, CHOICE_PATTERN.test(section.markdown));
|
|
182
|
+
break;
|
|
183
|
+
case "outcome":
|
|
184
|
+
visible(section.statement, `${path}.statement`);
|
|
185
|
+
checkQuestionRef(section.questionId, `${path}.questionId`, section.modality !== "comment" || CHOICE_PATTERN.test(section.statement));
|
|
186
|
+
break;
|
|
187
|
+
case "diagram":
|
|
188
|
+
visible(section.alt, `${path}.alt`);
|
|
189
|
+
if (section.scene === void 0) visible(section.source, `${path}.source`);
|
|
190
|
+
else checkCodes(section.source, `${path}.source`);
|
|
191
|
+
for (const [family, field] of [["entities", "name"], ["relations", "label"]]) {
|
|
192
|
+
for (const [id, member] of Object.entries(asRecord(section.scene?.[family]))) {
|
|
193
|
+
const attribute = asRecord(asRecord(asRecord(member).attributes)[field]);
|
|
194
|
+
if (attribute.kind === "text" && typeof attribute.value === "string") {
|
|
195
|
+
visible(attribute.value, `${path}.scene.${family}.${id}.attributes.${field}.value`);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
break;
|
|
200
|
+
case "amendmentTrace":
|
|
201
|
+
checkSteps(section.steps, `${path}.steps`);
|
|
202
|
+
break;
|
|
203
|
+
case "optionSet":
|
|
204
|
+
checkQuestionRef(section.questionId, `${path}.questionId`, true);
|
|
205
|
+
checkCodes(section.title, `${path}.title`);
|
|
206
|
+
checkLine(section.title, `${path}.title`, READABILITY_LIMITS.maxHeadingLength);
|
|
207
|
+
section.options.forEach((option, j) => checkOption(option, `${path}.options[${j}]`));
|
|
208
|
+
break;
|
|
209
|
+
case "question": {
|
|
210
|
+
if (blank(section.question)) refuse(`${path}.question`, "empty_question", "State the explicit decision the owner needs to make in this question.");
|
|
211
|
+
if (blank(section.context)) {
|
|
212
|
+
refuse(`${path}.context`, "missing_question_context", "Add representative context in plain words so the question can be understood on its own.");
|
|
213
|
+
} else if (section.context.trim().length < READABILITY_LIMITS.minQuestionContextLength) {
|
|
214
|
+
refuse(`${path}.context`, "question_context_too_short", "Give representative context of at least 20 characters, including what changes for the owner.");
|
|
215
|
+
}
|
|
216
|
+
if (blank(section.recommendedAnswer)) refuse(`${path}.recommendedAnswer`, "missing_recommendation", "Recommend an option with a short reason that relates to the owner's request and stakes.");
|
|
217
|
+
checkLine(section.question, `${path}.question`, READABILITY_LIMITS.maxDecisionLineLength);
|
|
218
|
+
checkLine(section.recommendedAnswer, `${path}.recommendedAnswer`, READABILITY_LIMITS.maxDecisionLineLength);
|
|
219
|
+
const linked = optionSets.filter((set) => set.questionId === section.id);
|
|
220
|
+
const options = linked.flatMap((set) => set.options);
|
|
221
|
+
if (options.length < 2 || options.length > 4) refuse(path, "option_count", `Each question needs 2\u20134 short options; this question has ${options.length}.`);
|
|
222
|
+
if (!options.some((option) => option.id === section.recommendedOptionId)) {
|
|
223
|
+
refuse(`${path}.recommendedOptionId`, "unknown_recommended_option", "Identify the recommended option by its id among this question's options, with the reason in recommendedAnswer.");
|
|
224
|
+
}
|
|
225
|
+
const texts = [
|
|
226
|
+
section.question,
|
|
227
|
+
section.context,
|
|
228
|
+
section.recommendedAnswer,
|
|
229
|
+
section.answer,
|
|
230
|
+
options.find((option) => option.id === section.recommendedOptionId)?.label,
|
|
231
|
+
...linked.map((set) => set.title),
|
|
232
|
+
...options.flatMap((o) => [o.label, o.consequence, o.body, o.annotationComment])
|
|
233
|
+
];
|
|
234
|
+
checkCodes(section.question, `${path}.question`);
|
|
235
|
+
checkCodes(section.context, `${path}.context`);
|
|
236
|
+
checkCodes(section.recommendedAnswer, `${path}.recommendedAnswer`);
|
|
237
|
+
checkCodes(section.answer, `${path}.answer`);
|
|
238
|
+
const minutes = section.readingTimeMinutes;
|
|
239
|
+
const minimum = minutesFor(texts);
|
|
240
|
+
if (minutes === void 0) {
|
|
241
|
+
refuse(`${path}.readingTimeMinutes`, "missing_reading_time", "Estimate the time to read this question, context and options in readingTimeMinutes (up to 2 minutes).");
|
|
242
|
+
} else if (!Number.isFinite(minutes) || minutes <= 0 || minutes > 2) {
|
|
243
|
+
refuse(`${path}.readingTimeMinutes`, "reading_time_exceeded", "Each question must take a positive finite time of at most 2 minutes; shorten or split it.");
|
|
244
|
+
} else {
|
|
245
|
+
if (minutes < minimum) refuse(`${path}.readingTimeMinutes`, "reading_time_underestimated", `This question needs at least ${minimum.toFixed(2)} minutes at 180 words/minute; shorten it or correct its estimate (maximum 2 minutes).`);
|
|
246
|
+
totalQuestionMinutes += Math.max(minutes, minimum);
|
|
247
|
+
}
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
if (budgetValid && totalQuestionMinutes + minutesFor(shared) > budget) {
|
|
253
|
+
refuse("$.readability.readingBudgetMinutes", "reading_budget_exceeded", "The questions plus shared context and glossary exceed the declared reading budget; shorten the dossier to match its stakes.");
|
|
254
|
+
}
|
|
255
|
+
return issues;
|
|
256
|
+
function checkLine(text2, path, max) {
|
|
257
|
+
if (!text2) return;
|
|
258
|
+
if (text2.trim().length > max || LINE_BREAK.test(text2)) refuse(
|
|
259
|
+
path,
|
|
260
|
+
"decision_line_too_long",
|
|
261
|
+
`Use one short line of at most ${max} characters; put explanation in the question context.`
|
|
262
|
+
);
|
|
263
|
+
if (SUBOPTION_PATTERN.test(text2)) refuse(
|
|
264
|
+
path,
|
|
265
|
+
"nested_suboptions",
|
|
266
|
+
"Expose sub-choices as separate options or questions, without nested lists or inline branches."
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
function checkOption(option, path) {
|
|
270
|
+
const fields = [
|
|
271
|
+
{ field: "label", text: option.label, max: READABILITY_LIMITS.maxOptionLabelLength, code: "option_too_long" },
|
|
272
|
+
{ field: "consequence", text: option.consequence, max: READABILITY_LIMITS.maxConsequenceLength, code: "consequence_too_long" },
|
|
273
|
+
{ field: "body", text: option.body, max: READABILITY_LIMITS.maxOptionBodyLength, code: "option_too_long" },
|
|
274
|
+
{ field: "annotationComment", text: option.annotationComment, max: READABILITY_LIMITS.maxOptionBodyLength, code: "option_too_long" }
|
|
275
|
+
];
|
|
276
|
+
if (blank(option.label)) refuse(`${path}.label`, "empty_option_label", "Name this option in a few plain words so the owner can compare it at a glance.");
|
|
277
|
+
if (blank(option.consequence)) refuse(`${path}.consequence`, "missing_consequence", "Add a one-line consequence: what choosing this option changes for the owner.");
|
|
278
|
+
for (const { field, text: text2, max, code } of fields) {
|
|
279
|
+
if (!text2) continue;
|
|
280
|
+
checkCodes(text2, `${path}.${field}`);
|
|
281
|
+
if (text2.trim().length > max || LINE_BREAK.test(text2)) refuse(`${path}.${field}`, code, `Keep this option ${field} to one short line of at most ${max} characters; move necessary context to the question.`);
|
|
282
|
+
if (SUBOPTION_PATTERN.test(text2) || CHOICE_PATTERN.test(text2)) refuse(`${path}.${field}`, "nested_suboptions", "This option hides sub-options: expose the choices as separate options or as a separate question.");
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
// packages/focus/src/validation/evidence-shape.ts
|
|
288
|
+
var EvidenceError = class extends Error {
|
|
289
|
+
constructor(issue2) {
|
|
290
|
+
super(issue2.message);
|
|
291
|
+
this.issue = issue2;
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
var fail = (path, code, message) => {
|
|
295
|
+
throw new EvidenceError({ path, code, message });
|
|
296
|
+
};
|
|
297
|
+
function record(value, path, required, optional = []) {
|
|
298
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) fail(path, "invalid_evidence", "Expected a closed object");
|
|
299
|
+
const obj = value;
|
|
300
|
+
for (const key of Object.keys(obj)) if (![...required, ...optional].includes(key)) fail(`${path}.${key}`, "invalid_evidence", "Unknown evidence field");
|
|
301
|
+
for (const key of required) if (!Object.hasOwn(obj, key)) fail(`${path}.${key}`, "invalid_evidence", "Missing evidence field");
|
|
302
|
+
return obj;
|
|
303
|
+
}
|
|
304
|
+
function text(value, path, allowEmpty = false) {
|
|
305
|
+
if (typeof value !== "string" || !allowEmpty && !value.trim()) fail(path, "invalid_evidence", "Expected a non-empty string");
|
|
306
|
+
return value;
|
|
307
|
+
}
|
|
308
|
+
function array(value, path) {
|
|
309
|
+
if (!Array.isArray(value)) fail(path, "invalid_evidence", "Expected an array");
|
|
310
|
+
return value;
|
|
311
|
+
}
|
|
312
|
+
var strings = (value, path) => array(value, path).map((v, i) => text(v, `${path}[${i}]`));
|
|
313
|
+
function imageDimensions(bytes, media) {
|
|
314
|
+
const u32 = (n) => new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength).getUint32(n);
|
|
315
|
+
if (media === "image/png") {
|
|
316
|
+
if (bytes.length >= 33 && [137, 80, 78, 71, 13, 10, 26, 10].every((v, i) => bytes[i] === v) && u32(8) === 13 && u32(12) === 1229472850) return [u32(16), u32(20)];
|
|
317
|
+
} else if (bytes[0] === 255 && bytes[1] === 216) {
|
|
318
|
+
let i = 2;
|
|
319
|
+
while (i + 4 < bytes.length && bytes[i] === 255) {
|
|
320
|
+
const marker = bytes[i + 1], size = bytes[i + 2] << 8 | bytes[i + 3];
|
|
321
|
+
if (size < 2 || i + 2 + size > bytes.length) break;
|
|
322
|
+
if ([192, 193, 194, 195, 197, 198, 199, 201, 202, 203, 205, 206, 207].includes(marker) && size >= 8)
|
|
323
|
+
return [bytes[i + 7] << 8 | bytes[i + 8], bytes[i + 5] << 8 | bytes[i + 6]];
|
|
324
|
+
i += size + 2;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return void 0;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// packages/focus/src/validation/evidence-bytes.ts
|
|
331
|
+
var K = [
|
|
332
|
+
1116352408,
|
|
333
|
+
1899447441,
|
|
334
|
+
3049323471,
|
|
335
|
+
3921009573,
|
|
336
|
+
961987163,
|
|
337
|
+
1508970993,
|
|
338
|
+
2453635748,
|
|
339
|
+
2870763221,
|
|
340
|
+
3624381080,
|
|
341
|
+
310598401,
|
|
342
|
+
607225278,
|
|
343
|
+
1426881987,
|
|
344
|
+
1925078388,
|
|
345
|
+
2162078206,
|
|
346
|
+
2614888103,
|
|
347
|
+
3248222580,
|
|
348
|
+
3835390401,
|
|
349
|
+
4022224774,
|
|
350
|
+
264347078,
|
|
351
|
+
604807628,
|
|
352
|
+
770255983,
|
|
353
|
+
1249150122,
|
|
354
|
+
1555081692,
|
|
355
|
+
1996064986,
|
|
356
|
+
2554220882,
|
|
357
|
+
2821834349,
|
|
358
|
+
2952996808,
|
|
359
|
+
3210313671,
|
|
360
|
+
3336571891,
|
|
361
|
+
3584528711,
|
|
362
|
+
113926993,
|
|
363
|
+
338241895,
|
|
364
|
+
666307205,
|
|
365
|
+
773529912,
|
|
366
|
+
1294757372,
|
|
367
|
+
1396182291,
|
|
368
|
+
1695183700,
|
|
369
|
+
1986661051,
|
|
370
|
+
2177026350,
|
|
371
|
+
2456956037,
|
|
372
|
+
2730485921,
|
|
373
|
+
2820302411,
|
|
374
|
+
3259730800,
|
|
375
|
+
3345764771,
|
|
376
|
+
3516065817,
|
|
377
|
+
3600352804,
|
|
378
|
+
4094571909,
|
|
379
|
+
275423344,
|
|
380
|
+
430227734,
|
|
381
|
+
506948616,
|
|
382
|
+
659060556,
|
|
383
|
+
883997877,
|
|
384
|
+
958139571,
|
|
385
|
+
1322822218,
|
|
386
|
+
1537002063,
|
|
387
|
+
1747873779,
|
|
388
|
+
1955562222,
|
|
389
|
+
2024104815,
|
|
390
|
+
2227730452,
|
|
391
|
+
2361852424,
|
|
392
|
+
2428436474,
|
|
393
|
+
2756734187,
|
|
394
|
+
3204031479,
|
|
395
|
+
3329325298
|
|
396
|
+
];
|
|
397
|
+
var rr = (v, n) => v >>> n | v << 32 - n;
|
|
398
|
+
function sha256(bytes) {
|
|
399
|
+
const padded = new Uint8Array(Math.ceil((bytes.length + 9) / 64) * 64);
|
|
400
|
+
padded.set(bytes);
|
|
401
|
+
padded[bytes.length] = 128;
|
|
402
|
+
const view = new DataView(padded.buffer), bits = bytes.length * 8;
|
|
403
|
+
view.setUint32(padded.length - 8, Math.floor(bits / 4294967296));
|
|
404
|
+
view.setUint32(padded.length - 4, bits >>> 0);
|
|
405
|
+
const h = [1779033703, 3144134277, 1013904242, 2773480762, 1359893119, 2600822924, 528734635, 1541459225];
|
|
406
|
+
const w = new Int32Array(64);
|
|
407
|
+
for (let offset = 0; offset < padded.length; offset += 64) {
|
|
408
|
+
for (let i = 0; i < 16; i++) w[i] = view.getInt32(offset + i * 4);
|
|
409
|
+
for (let i = 16; i < 64; i++) {
|
|
410
|
+
const x = w[i - 15], y = w[i - 2];
|
|
411
|
+
w[i] = w[i - 16] + (rr(x, 7) ^ rr(x, 18) ^ x >>> 3) + w[i - 7] + (rr(y, 17) ^ rr(y, 19) ^ y >>> 10);
|
|
412
|
+
}
|
|
413
|
+
let [a, b, c, d, e, f, g, j] = h;
|
|
414
|
+
for (let i = 0; i < 64; i++) {
|
|
415
|
+
const t = j + (rr(e, 6) ^ rr(e, 11) ^ rr(e, 25)) + (e & f ^ ~e & g) + K[i] + w[i] | 0;
|
|
416
|
+
const u = (rr(a, 2) ^ rr(a, 13) ^ rr(a, 22)) + (a & b ^ a & c ^ b & c) | 0;
|
|
417
|
+
j = g;
|
|
418
|
+
g = f;
|
|
419
|
+
f = e;
|
|
420
|
+
e = d + t | 0;
|
|
421
|
+
d = c;
|
|
422
|
+
c = b;
|
|
423
|
+
b = a;
|
|
424
|
+
a = t + u | 0;
|
|
425
|
+
}
|
|
426
|
+
[a, b, c, d, e, f, g, j].forEach((v, i) => {
|
|
427
|
+
h[i] = h[i] + v | 0;
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
return h.map((v) => (v >>> 0).toString(16).padStart(8, "0")).join("");
|
|
431
|
+
}
|
|
432
|
+
function decodeEvidence(data) {
|
|
433
|
+
if (data.length % 4 || /[^A-Za-z0-9+/]/.test(data.replace(/={1,2}$/, ""))) throw new Error("Invalid base64");
|
|
434
|
+
const binary = atob(data);
|
|
435
|
+
if (btoa(binary) !== data) throw new Error("Non-canonical base64");
|
|
436
|
+
const bytes = new Uint8Array(binary.length);
|
|
437
|
+
for (let i = 0; i < bytes.length; i++) bytes[i] = binary.charCodeAt(i);
|
|
438
|
+
return bytes;
|
|
439
|
+
}
|
|
440
|
+
var evidenceText = (bytes) => new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(bytes);
|
|
441
|
+
var evidenceLines = (text2) => text2.split(/\r\n|\n|\r/);
|
|
442
|
+
|
|
443
|
+
// packages/focus/src/validation/evidence-sources.ts
|
|
444
|
+
var isTextSource = (media) => /^text\/[a-z0-9.+-]+$/.test(media) || ["application/json", "application/yaml", "application/x-yaml", "application/x-ndjson"].includes(media);
|
|
445
|
+
function checkSources(value, register) {
|
|
446
|
+
const lineCounts = /* @__PURE__ */ new Map();
|
|
447
|
+
const sources = array(value, "$.sources").map((raw, i) => {
|
|
448
|
+
const path = `$.sources[${i}]`;
|
|
449
|
+
const s = record(raw, path, ["id", "title", "origin", "mediaType", "encoding", "data", "sha256", "size"], ["width", "height", "alt"]);
|
|
450
|
+
for (const key of ["id", "title", "mediaType", "sha256"]) text(s[key], `${path}.${key}`);
|
|
451
|
+
register(s.id, `${path}.id`);
|
|
452
|
+
const origin = s.origin;
|
|
453
|
+
const fields = origin && Object.hasOwn(origin, "uri") ? ["uri"] : ["repo", "revision", "path"];
|
|
454
|
+
record(origin, `${path}.origin`, fields);
|
|
455
|
+
for (const key of fields) text(origin[key], `${path}.origin.${key}`);
|
|
456
|
+
if (s.encoding !== "base64") fail(`${path}.encoding`, "source_encoding", "Only original base64 bytes are accepted");
|
|
457
|
+
const media = s.mediaType;
|
|
458
|
+
if (!isTextSource(media) && !["image/png", "image/jpeg"].includes(media)) fail(`${path}.mediaType`, "unsupported_media", `Unsupported media for source ${s.id}`);
|
|
459
|
+
let bytes;
|
|
460
|
+
try {
|
|
461
|
+
bytes = decodeEvidence(text(s.data, `${path}.data`, true));
|
|
462
|
+
} catch {
|
|
463
|
+
return fail(`${path}.data`, "source_encoding", `Invalid base64 for source ${s.id}`);
|
|
464
|
+
}
|
|
465
|
+
if (!Number.isSafeInteger(s.size) || s.size !== bytes.length) fail(`${path}.size`, "source_size", `Byte size mismatch for source ${s.id}`);
|
|
466
|
+
if (!/^[a-f0-9]{64}$/.test(s.sha256) || sha256(bytes) !== s.sha256) fail(`${path}.sha256`, "source_digest", `SHA-256 mismatch for source ${s.id}`);
|
|
467
|
+
if (isTextSource(media)) {
|
|
468
|
+
try {
|
|
469
|
+
lineCounts.set(s.id, evidenceLines(evidenceText(bytes)).length);
|
|
470
|
+
} catch {
|
|
471
|
+
fail(`${path}.data`, "source_encoding", `Invalid UTF-8 for source ${s.id}`);
|
|
472
|
+
}
|
|
473
|
+
for (const key of ["width", "height", "alt"]) if (s[key] !== void 0) fail(`${path}.${key}`, "invalid_evidence", "Image metadata on text");
|
|
474
|
+
} else {
|
|
475
|
+
text(s.alt, `${path}.alt`);
|
|
476
|
+
const dimensions = imageDimensions(bytes, media);
|
|
477
|
+
if (!dimensions || !Number.isSafeInteger(s.width) || !Number.isSafeInteger(s.height) || dimensions[0] <= 0 || dimensions[1] <= 0 || dimensions[0] !== s.width || dimensions[1] !== s.height)
|
|
478
|
+
fail(path, "image_metadata", `Image dimensions/signature mismatch for source ${s.id}`);
|
|
479
|
+
}
|
|
480
|
+
return s;
|
|
481
|
+
});
|
|
482
|
+
return { sources, lineCounts };
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
// packages/focus/src/validation/evidence.ts
|
|
486
|
+
function checkEvidence(value, legacy) {
|
|
487
|
+
try {
|
|
488
|
+
const { schemaVersion: _version, sources: rawSources, citations: rawCitations, evidenceGroups: rawGroups, annexes: rawAnnexes, ...base } = value;
|
|
489
|
+
const citationLinks = /* @__PURE__ */ new Map();
|
|
490
|
+
const strip = (raw, path) => {
|
|
491
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return raw;
|
|
492
|
+
const { citationRefs, ...node } = raw;
|
|
493
|
+
if (citationRefs !== void 0) citationLinks.set(path, strings(citationRefs, `${path}.citationRefs`));
|
|
494
|
+
return node;
|
|
495
|
+
};
|
|
496
|
+
if (Array.isArray(base.sections)) base.sections = base.sections.map((raw, i) => {
|
|
497
|
+
const section = strip(raw, `$.sections[${i}]`);
|
|
498
|
+
if (section?.kind === "optionSet" && Array.isArray(section.options)) return {
|
|
499
|
+
...section,
|
|
500
|
+
options: section.options.map((o, j) => strip(o, `$.sections[${i}].options[${j}]`))
|
|
501
|
+
};
|
|
502
|
+
return section;
|
|
503
|
+
});
|
|
504
|
+
const checked = legacy(base);
|
|
505
|
+
if (!checked.ok) return checked;
|
|
506
|
+
const doc = checked.value, seen = /* @__PURE__ */ new Set(), targets = /* @__PURE__ */ new Set([doc.ref]);
|
|
507
|
+
const register = (id, path) => {
|
|
508
|
+
if (seen.has(id)) fail(path, "duplicate_id", `Duplicate id ${id}`);
|
|
509
|
+
seen.add(id);
|
|
510
|
+
};
|
|
511
|
+
doc.sections.forEach((s) => {
|
|
512
|
+
register(s.id, "$.sections");
|
|
513
|
+
targets.add(s.id);
|
|
514
|
+
targets.add(s.targetRef);
|
|
515
|
+
if (s.kind === "optionSet") s.options.forEach((o) => {
|
|
516
|
+
register(o.id, "$.sections.options");
|
|
517
|
+
targets.add(o.id);
|
|
518
|
+
targets.add(o.targetRef);
|
|
519
|
+
});
|
|
520
|
+
});
|
|
521
|
+
const { sources, lineCounts } = checkSources(rawSources, register);
|
|
522
|
+
const sourceMap = new Map(sources.map((s) => [s.id, s]));
|
|
523
|
+
const citations = array(rawCitations, "$.citations").map((raw, i) => {
|
|
524
|
+
const p = `$.citations[${i}]`, c = record(raw, p, ["id", "sourceId", "label", "locator"]);
|
|
525
|
+
for (const key of ["id", "sourceId", "label"]) text(c[key], `${p}.${key}`);
|
|
526
|
+
register(c.id, `${p}.id`);
|
|
527
|
+
const source = sourceMap.get(c.sourceId) ?? fail(`${p}.sourceId`, "unresolved_source", `Unknown source ${c.sourceId}`);
|
|
528
|
+
const loc = c.locator;
|
|
529
|
+
if (loc?.kind === "lines") {
|
|
530
|
+
record(loc, `${p}.locator`, ["kind", "start", "end"]);
|
|
531
|
+
if (!lineCounts.has(source.id)) fail(`${p}.locator`, "citation_media", `Source ${source.id} is not text`);
|
|
532
|
+
if (!Number.isSafeInteger(loc.start) || !Number.isSafeInteger(loc.end) || loc.start < 1 || loc.end < loc.start || loc.end > lineCounts.get(source.id))
|
|
533
|
+
fail(`${p}.locator`, "citation_range", `Invalid inclusive line range for ${source.id}`);
|
|
534
|
+
} else if (loc?.kind === "image") {
|
|
535
|
+
record(loc, `${p}.locator`, ["kind", "caption"]);
|
|
536
|
+
text(loc.caption, `${p}.locator.caption`);
|
|
537
|
+
if (!source.mediaType.startsWith("image/")) fail(`${p}.locator`, "citation_media", `Source ${source.id} is not an image`);
|
|
538
|
+
} else fail(`${p}.locator`, "invalid_evidence", "Unknown citation locator");
|
|
539
|
+
return c;
|
|
540
|
+
});
|
|
541
|
+
const citationIds = new Set(citations.map((c) => c.id));
|
|
542
|
+
const references = (raw, p, ids, code) => {
|
|
543
|
+
const refs = strings(raw, p);
|
|
544
|
+
for (const id of refs) if (!ids.has(id)) fail(p, code, `Unresolved reference ${id}`);
|
|
545
|
+
return refs;
|
|
546
|
+
};
|
|
547
|
+
for (const [path, refs] of citationLinks) references(refs, `${path}.citationRefs`, citationIds, "unresolved_citation");
|
|
548
|
+
const evidenceGroups = array(rawGroups, "$.evidenceGroups").map((raw, i) => {
|
|
549
|
+
const p = `$.evidenceGroups[${i}]`, g = record(raw, p, ["id", "summary", "citationRefs", "sourceRefs"]);
|
|
550
|
+
register(text(g.id, `${p}.id`), `${p}.id`);
|
|
551
|
+
text(g.summary, `${p}.summary`);
|
|
552
|
+
references(g.citationRefs, `${p}.citationRefs`, citationIds, "unresolved_citation");
|
|
553
|
+
references(g.sourceRefs, `${p}.sourceRefs`, new Set(sourceMap.keys()), "unresolved_source");
|
|
554
|
+
return g;
|
|
555
|
+
});
|
|
556
|
+
const annexes = array(rawAnnexes, "$.annexes").map((raw, i) => {
|
|
557
|
+
const p = `$.annexes[${i}]`, a = record(raw, p, ["id", "title", "summary", "blocks", "backRefs"]);
|
|
558
|
+
register(text(a.id, `${p}.id`), `${p}.id`);
|
|
559
|
+
text(a.title, `${p}.title`);
|
|
560
|
+
text(a.summary, `${p}.summary`);
|
|
561
|
+
references(a.backRefs, `${p}.backRefs`, targets, "unresolved_target");
|
|
562
|
+
array(a.blocks, `${p}.blocks`).forEach((rawBlock, j) => {
|
|
563
|
+
const bpath = `${p}.blocks[${j}]`, kind = rawBlock?.kind;
|
|
564
|
+
if (kind === "text" || kind === "code") {
|
|
565
|
+
const b = record(rawBlock, bpath, ["kind", "text"], kind === "code" ? ["language"] : []);
|
|
566
|
+
text(b.text, `${bpath}.text`, true);
|
|
567
|
+
if (b.language !== void 0) text(b.language, `${bpath}.language`);
|
|
568
|
+
} else if (kind === "table") {
|
|
569
|
+
const b = record(rawBlock, bpath, ["kind", "columns", "rows"]);
|
|
570
|
+
const columns = strings(b.columns, `${bpath}.columns`);
|
|
571
|
+
if (!columns.length) fail(bpath, "invalid_evidence", "A table needs columns");
|
|
572
|
+
array(b.rows, `${bpath}.rows`).forEach((row, k) => {
|
|
573
|
+
const cells = array(row, `${bpath}.rows[${k}]`);
|
|
574
|
+
cells.forEach((cell, l) => text(cell, `${bpath}.rows[${k}][${l}]`, true));
|
|
575
|
+
if (cells.length !== columns.length) fail(bpath, "invalid_evidence", "Table row width mismatch");
|
|
576
|
+
});
|
|
577
|
+
} else if (kind === "references") {
|
|
578
|
+
const b = record(rawBlock, bpath, ["kind", "citationRefs"]);
|
|
579
|
+
references(b.citationRefs, `${bpath}.citationRefs`, citationIds, "unresolved_citation");
|
|
580
|
+
} else fail(`${bpath}.kind`, "invalid_evidence", "Unsupported annex block (no decisions or active content)");
|
|
581
|
+
});
|
|
582
|
+
return a;
|
|
583
|
+
});
|
|
584
|
+
const attach = (node, path) => citationLinks.has(path) ? { ...node, citationRefs: citationLinks.get(path) } : node;
|
|
585
|
+
const sections = doc.sections.map((s, i) => attach(s.kind === "optionSet" ? {
|
|
586
|
+
...s,
|
|
587
|
+
options: s.options.map((o, j) => attach(o, `$.sections[${i}].options[${j}]`))
|
|
588
|
+
} : s, `$.sections[${i}]`));
|
|
589
|
+
return { ok: true, value: { ...doc, schemaVersion: 2, sections, sources, citations, evidenceGroups, annexes } };
|
|
590
|
+
} catch (error) {
|
|
591
|
+
if (error instanceof EvidenceError) return { ok: false, issues: [error.issue] };
|
|
592
|
+
throw error;
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
// packages/focus/src/validation/index.ts
|
|
597
|
+
var DOSSIER_SCHEMA_ID = "urn:sentropic:focus:DecisionDossierDocument:1.0.0";
|
|
598
|
+
var DOSSIER_SCHEMA_VERSION = "1.0.0";
|
|
599
|
+
var DecisionDossierValidationError = class extends Error {
|
|
600
|
+
issues;
|
|
601
|
+
constructor(issues) {
|
|
602
|
+
super(
|
|
603
|
+
`invalid DecisionDossierDocument: ${issues.map((issue2) => `${issue2.path} ${issue2.code}: ${issue2.message}`).join("; ")}`
|
|
604
|
+
);
|
|
605
|
+
this.name = "DecisionDossierValidationError";
|
|
606
|
+
this.issues = issues;
|
|
607
|
+
}
|
|
608
|
+
};
|
|
609
|
+
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
610
|
+
var issue = (path, code, message) => ({
|
|
611
|
+
path,
|
|
612
|
+
code,
|
|
613
|
+
message
|
|
614
|
+
});
|
|
615
|
+
var checkClosedObject = (value, path, allowed, required, stringKeys, issues) => {
|
|
616
|
+
if (!isRecord(value)) {
|
|
617
|
+
issues.push(issue(path, "invalid_type", "expected an object"));
|
|
618
|
+
return void 0;
|
|
619
|
+
}
|
|
620
|
+
const allowedSet = new Set(allowed);
|
|
621
|
+
for (const key of Object.keys(value)) {
|
|
622
|
+
if (!allowedSet.has(key)) {
|
|
623
|
+
issues.push(issue(`${path}.${key}`, "unknown_field", "field not in the closed schema"));
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
for (const key of required) {
|
|
627
|
+
if (value[key] === void 0) {
|
|
628
|
+
issues.push(issue(`${path}.${key}`, "missing_field", "required field is missing"));
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
for (const key of stringKeys) {
|
|
632
|
+
if (value[key] !== void 0 && typeof value[key] !== "string") {
|
|
633
|
+
issues.push(issue(`${path}.${key}`, "invalid_type", "expected a string"));
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
return value;
|
|
637
|
+
};
|
|
638
|
+
var checkEnum = (value, path, allowed, issues) => {
|
|
639
|
+
if (typeof value !== "string" || !allowed.includes(value)) {
|
|
640
|
+
issues.push(
|
|
641
|
+
issue(path, "invalid_enum", `expected one of: ${allowed.join(" | ")}`)
|
|
642
|
+
);
|
|
643
|
+
}
|
|
644
|
+
};
|
|
645
|
+
var TOP_REQUIRED = [
|
|
646
|
+
"ref",
|
|
647
|
+
"subject",
|
|
648
|
+
"title",
|
|
649
|
+
"hash",
|
|
650
|
+
"cursor",
|
|
651
|
+
"sections",
|
|
652
|
+
"interactions",
|
|
653
|
+
"provenance",
|
|
654
|
+
"amendmentTrace"
|
|
655
|
+
];
|
|
656
|
+
var TOP_STRINGS = ["ref", "subject", "title", "hash", "cursor"];
|
|
657
|
+
var TOP_ALLOWED = [...TOP_REQUIRED, "readability"];
|
|
658
|
+
var checkOptionNode = (value, path, issues) => {
|
|
659
|
+
const start = issues.length;
|
|
660
|
+
const node = checkClosedObject(
|
|
661
|
+
value,
|
|
662
|
+
path,
|
|
663
|
+
["kind", "id", "targetRef", "label", "body", "annotation", "annotationComment", "consequence"],
|
|
664
|
+
["kind", "id", "targetRef", "label", "annotation"],
|
|
665
|
+
["id", "targetRef", "label", "body", "annotationComment", "consequence"],
|
|
666
|
+
issues
|
|
667
|
+
);
|
|
668
|
+
if (node === void 0) return void 0;
|
|
669
|
+
if (node["kind"] !== "option") {
|
|
670
|
+
issues.push(issue(`${path}.kind`, "invalid_discriminator", 'expected "option"'));
|
|
671
|
+
}
|
|
672
|
+
checkEnum(node["annotation"], `${path}.annotation`, ["none", "accept", "reject", "comment"], issues);
|
|
673
|
+
if (issues.length !== start) return void 0;
|
|
674
|
+
return {
|
|
675
|
+
kind: "option",
|
|
676
|
+
id: node["id"],
|
|
677
|
+
targetRef: node["targetRef"],
|
|
678
|
+
label: node["label"],
|
|
679
|
+
...typeof node["body"] === "string" ? { body: node["body"] } : {},
|
|
680
|
+
annotation: node["annotation"],
|
|
681
|
+
...typeof node["annotationComment"] === "string" ? { annotationComment: node["annotationComment"] } : {},
|
|
682
|
+
...typeof node["consequence"] === "string" ? { consequence: node["consequence"] } : {}
|
|
683
|
+
};
|
|
684
|
+
};
|
|
685
|
+
var checkAmendmentStep = (value, path, issues) => {
|
|
686
|
+
const start = issues.length;
|
|
687
|
+
const step = checkClosedObject(
|
|
688
|
+
value,
|
|
689
|
+
path,
|
|
690
|
+
["at", "author", "summary"],
|
|
691
|
+
["at", "author", "summary"],
|
|
692
|
+
["at", "author", "summary"],
|
|
693
|
+
issues
|
|
694
|
+
);
|
|
695
|
+
if (step === void 0 || issues.length !== start) return void 0;
|
|
696
|
+
return { at: step["at"], author: step["author"], summary: step["summary"] };
|
|
697
|
+
};
|
|
698
|
+
var checkSectionNode = (value, path, issues) => {
|
|
699
|
+
if (!isRecord(value)) {
|
|
700
|
+
issues.push(issue(path, "invalid_type", "expected an object"));
|
|
701
|
+
return void 0;
|
|
702
|
+
}
|
|
703
|
+
const kind = value["kind"];
|
|
704
|
+
if (kind !== "prose" && kind !== "question" && kind !== "optionSet" && kind !== "outcome" && kind !== "amendmentTrace" && kind !== "diagram") {
|
|
705
|
+
issues.push(
|
|
706
|
+
issue(
|
|
707
|
+
`${path}.kind`,
|
|
708
|
+
typeof kind === "undefined" ? "missing_field" : "unknown_node_kind",
|
|
709
|
+
`unknown section kind ${typeof kind === "string" ? `"${kind}"` : " discriminant"}`
|
|
710
|
+
)
|
|
711
|
+
);
|
|
712
|
+
return void 0;
|
|
713
|
+
}
|
|
714
|
+
const start = issues.length;
|
|
715
|
+
switch (kind) {
|
|
716
|
+
case "prose": {
|
|
717
|
+
const node = checkClosedObject(
|
|
718
|
+
value,
|
|
719
|
+
path,
|
|
720
|
+
["kind", "id", "targetRef", "markdown", "questionId"],
|
|
721
|
+
["kind", "id", "targetRef", "markdown"],
|
|
722
|
+
["id", "targetRef", "markdown", "questionId"],
|
|
723
|
+
issues
|
|
724
|
+
);
|
|
725
|
+
if (node === void 0 || issues.length !== start) return void 0;
|
|
726
|
+
return { kind: "prose", id: node["id"], targetRef: node["targetRef"], markdown: node["markdown"], ...typeof node["questionId"] === "string" ? { questionId: node["questionId"] } : {} };
|
|
727
|
+
}
|
|
728
|
+
case "question": {
|
|
729
|
+
const node = checkClosedObject(
|
|
730
|
+
value,
|
|
731
|
+
path,
|
|
732
|
+
["kind", "id", "targetRef", "question", "recommendedAnswer", "answer", "state", "context", "readingTimeMinutes", "recommendedOptionId"],
|
|
733
|
+
["kind", "id", "targetRef", "question", "state"],
|
|
734
|
+
["id", "targetRef", "question", "recommendedAnswer", "answer", "context", "recommendedOptionId"],
|
|
735
|
+
issues
|
|
736
|
+
);
|
|
737
|
+
if (node === void 0) return void 0;
|
|
738
|
+
checkEnum(node["state"], `${path}.state`, ["open", "answered", "validated"], issues);
|
|
739
|
+
if (node["readingTimeMinutes"] !== void 0 && (typeof node["readingTimeMinutes"] !== "number" || !Number.isFinite(node["readingTimeMinutes"]))) {
|
|
740
|
+
issues.push(issue(`${path}.readingTimeMinutes`, "invalid_type", "expected a finite number"));
|
|
741
|
+
}
|
|
742
|
+
if (issues.length !== start) return void 0;
|
|
743
|
+
return {
|
|
744
|
+
kind: "question",
|
|
745
|
+
id: node["id"],
|
|
746
|
+
targetRef: node["targetRef"],
|
|
747
|
+
question: node["question"],
|
|
748
|
+
...typeof node["recommendedAnswer"] === "string" ? { recommendedAnswer: node["recommendedAnswer"] } : {},
|
|
749
|
+
...typeof node["answer"] === "string" ? { answer: node["answer"] } : {},
|
|
750
|
+
state: node["state"],
|
|
751
|
+
...typeof node["context"] === "string" ? { context: node["context"] } : {},
|
|
752
|
+
...typeof node["recommendedOptionId"] === "string" ? { recommendedOptionId: node["recommendedOptionId"] } : {},
|
|
753
|
+
...typeof node["readingTimeMinutes"] === "number" ? { readingTimeMinutes: node["readingTimeMinutes"] } : {}
|
|
754
|
+
};
|
|
755
|
+
}
|
|
756
|
+
case "optionSet": {
|
|
757
|
+
const node = checkClosedObject(
|
|
758
|
+
value,
|
|
759
|
+
path,
|
|
760
|
+
["kind", "id", "targetRef", "title", "options", "questionId"],
|
|
761
|
+
["kind", "id", "targetRef", "options"],
|
|
762
|
+
["id", "targetRef", "title", "questionId"],
|
|
763
|
+
issues
|
|
764
|
+
);
|
|
765
|
+
if (node === void 0) return void 0;
|
|
766
|
+
const options = [];
|
|
767
|
+
if (!Array.isArray(node["options"])) {
|
|
768
|
+
issues.push(issue(`${path}.options`, "invalid_type", "expected an array"));
|
|
769
|
+
} else {
|
|
770
|
+
node["options"].forEach((option, index) => {
|
|
771
|
+
const checked = checkOptionNode(option, `${path}.options[${index}]`, issues);
|
|
772
|
+
if (checked !== void 0) options.push(checked);
|
|
773
|
+
});
|
|
774
|
+
}
|
|
775
|
+
if (issues.length !== start) return void 0;
|
|
776
|
+
return {
|
|
777
|
+
kind: "optionSet",
|
|
778
|
+
id: node["id"],
|
|
779
|
+
targetRef: node["targetRef"],
|
|
780
|
+
...typeof node["title"] === "string" ? { title: node["title"] } : {},
|
|
781
|
+
options,
|
|
782
|
+
...typeof node["questionId"] === "string" ? { questionId: node["questionId"] } : {}
|
|
783
|
+
};
|
|
784
|
+
}
|
|
785
|
+
case "outcome": {
|
|
786
|
+
const node = checkClosedObject(
|
|
787
|
+
value,
|
|
788
|
+
path,
|
|
789
|
+
["kind", "id", "targetRef", "modality", "statement", "questionId"],
|
|
790
|
+
["kind", "id", "targetRef", "modality", "statement"],
|
|
791
|
+
["id", "targetRef", "statement", "questionId"],
|
|
792
|
+
issues
|
|
793
|
+
);
|
|
794
|
+
if (node === void 0) return void 0;
|
|
795
|
+
checkEnum(node["modality"], `${path}.modality`, ["decision", "orientation", "amendment", "comment"], issues);
|
|
796
|
+
if (issues.length !== start) return void 0;
|
|
797
|
+
return {
|
|
798
|
+
kind: "outcome",
|
|
799
|
+
id: node["id"],
|
|
800
|
+
targetRef: node["targetRef"],
|
|
801
|
+
modality: node["modality"],
|
|
802
|
+
statement: node["statement"],
|
|
803
|
+
...typeof node["questionId"] === "string" ? { questionId: node["questionId"] } : {}
|
|
804
|
+
};
|
|
805
|
+
}
|
|
806
|
+
case "amendmentTrace": {
|
|
807
|
+
const node = checkClosedObject(
|
|
808
|
+
value,
|
|
809
|
+
path,
|
|
810
|
+
["kind", "id", "targetRef", "steps"],
|
|
811
|
+
["kind", "id", "targetRef", "steps"],
|
|
812
|
+
["id", "targetRef"],
|
|
813
|
+
issues
|
|
814
|
+
);
|
|
815
|
+
if (node === void 0) return void 0;
|
|
816
|
+
const steps = [];
|
|
817
|
+
if (!Array.isArray(node["steps"])) {
|
|
818
|
+
issues.push(issue(`${path}.steps`, "invalid_type", "expected an array"));
|
|
819
|
+
} else {
|
|
820
|
+
node["steps"].forEach((step, index) => {
|
|
821
|
+
const checked = checkAmendmentStep(step, `${path}.steps[${index}]`, issues);
|
|
822
|
+
if (checked !== void 0) steps.push(checked);
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
if (issues.length !== start) return void 0;
|
|
826
|
+
return {
|
|
827
|
+
kind: "amendmentTrace",
|
|
828
|
+
id: node["id"],
|
|
829
|
+
targetRef: node["targetRef"],
|
|
830
|
+
steps
|
|
831
|
+
};
|
|
832
|
+
}
|
|
833
|
+
case "diagram": {
|
|
834
|
+
const node = checkClosedObject(
|
|
835
|
+
value,
|
|
836
|
+
path,
|
|
837
|
+
["kind", "id", "targetRef", "syntax", "source", "alt", "scene"],
|
|
838
|
+
["kind", "id", "targetRef", "syntax", "source", "alt"],
|
|
839
|
+
["id", "targetRef", "source", "alt"],
|
|
840
|
+
issues
|
|
841
|
+
);
|
|
842
|
+
if (node === void 0) return void 0;
|
|
843
|
+
checkEnum(node["syntax"], `${path}.syntax`, ["mermaid", "plantuml"], issues);
|
|
844
|
+
if (node["scene"] !== void 0 && !isRecord(node["scene"])) {
|
|
845
|
+
issues.push(issue(`${path}.scene`, "invalid_type", "expected a diagram-core SemanticDocument object"));
|
|
846
|
+
}
|
|
847
|
+
if (issues.length !== start) return void 0;
|
|
848
|
+
return {
|
|
849
|
+
kind: "diagram",
|
|
850
|
+
id: node["id"],
|
|
851
|
+
targetRef: node["targetRef"],
|
|
852
|
+
syntax: node["syntax"],
|
|
853
|
+
source: node["source"],
|
|
854
|
+
alt: node["alt"],
|
|
855
|
+
...node["scene"] === void 0 ? {} : { scene: node["scene"] }
|
|
856
|
+
};
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
};
|
|
860
|
+
var checkInteraction = (value, path, issues) => {
|
|
861
|
+
const start = issues.length;
|
|
862
|
+
const affordance = checkClosedObject(
|
|
863
|
+
value,
|
|
864
|
+
path,
|
|
865
|
+
["name", "targetRef", "label", "enabled"],
|
|
866
|
+
["name", "targetRef", "label", "enabled"],
|
|
867
|
+
["name", "targetRef", "label"],
|
|
868
|
+
issues
|
|
869
|
+
);
|
|
870
|
+
if (affordance === void 0) return void 0;
|
|
871
|
+
if (affordance["enabled"] !== false) {
|
|
872
|
+
issues.push(
|
|
873
|
+
issue(`${path}.enabled`, "enabled_action", "snapshot interactions must stay disabled (enabled:false)")
|
|
874
|
+
);
|
|
875
|
+
}
|
|
876
|
+
if (issues.length !== start) return void 0;
|
|
877
|
+
return {
|
|
878
|
+
name: affordance["name"],
|
|
879
|
+
targetRef: affordance["targetRef"],
|
|
880
|
+
label: affordance["label"],
|
|
881
|
+
enabled: false
|
|
882
|
+
};
|
|
883
|
+
};
|
|
884
|
+
var checkGlossaryEntry = (value, path, issues) => {
|
|
885
|
+
const start = issues.length;
|
|
886
|
+
const entry = checkClosedObject(
|
|
887
|
+
value,
|
|
888
|
+
path,
|
|
889
|
+
["term", "definition"],
|
|
890
|
+
["term", "definition"],
|
|
891
|
+
["term", "definition"],
|
|
892
|
+
issues
|
|
893
|
+
);
|
|
894
|
+
if (entry === void 0 || issues.length !== start) return void 0;
|
|
895
|
+
return { term: entry["term"], definition: entry["definition"] };
|
|
896
|
+
};
|
|
897
|
+
var checkReadability = (value, path, issues) => {
|
|
898
|
+
const start = issues.length;
|
|
899
|
+
const block = checkClosedObject(
|
|
900
|
+
value,
|
|
901
|
+
path,
|
|
902
|
+
["ownerRequestQuote", "noOwnerRequest", "stakes", "stakesLevel", "readingBudgetMinutes", "glossary"],
|
|
903
|
+
[],
|
|
904
|
+
["ownerRequestQuote", "stakes"],
|
|
905
|
+
issues
|
|
906
|
+
);
|
|
907
|
+
if (block === void 0) return void 0;
|
|
908
|
+
if (block["stakesLevel"] !== void 0) {
|
|
909
|
+
checkEnum(block["stakesLevel"], `${path}.stakesLevel`, ["low", "medium", "high"], issues);
|
|
910
|
+
}
|
|
911
|
+
if (block["noOwnerRequest"] !== void 0 && typeof block["noOwnerRequest"] !== "boolean") {
|
|
912
|
+
issues.push(issue(`${path}.noOwnerRequest`, "invalid_type", "expected a boolean"));
|
|
913
|
+
}
|
|
914
|
+
if (block["readingBudgetMinutes"] !== void 0 && (typeof block["readingBudgetMinutes"] !== "number" || !Number.isFinite(block["readingBudgetMinutes"]))) {
|
|
915
|
+
issues.push(issue(`${path}.readingBudgetMinutes`, "invalid_type", "expected a finite number"));
|
|
916
|
+
}
|
|
917
|
+
let glossary;
|
|
918
|
+
if (block["glossary"] !== void 0) {
|
|
919
|
+
glossary = [];
|
|
920
|
+
if (!Array.isArray(block["glossary"])) {
|
|
921
|
+
issues.push(issue(`${path}.glossary`, "invalid_type", "expected an array"));
|
|
922
|
+
} else {
|
|
923
|
+
block["glossary"].forEach((entry, index) => {
|
|
924
|
+
const checked = checkGlossaryEntry(entry, `${path}.glossary[${index}]`, issues);
|
|
925
|
+
if (checked !== void 0) glossary.push(checked);
|
|
926
|
+
});
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
if (issues.length !== start) return void 0;
|
|
930
|
+
return {
|
|
931
|
+
...typeof block["ownerRequestQuote"] === "string" ? { ownerRequestQuote: block["ownerRequestQuote"] } : {},
|
|
932
|
+
...typeof block["noOwnerRequest"] === "boolean" ? { noOwnerRequest: block["noOwnerRequest"] } : {},
|
|
933
|
+
...typeof block["stakes"] === "string" ? { stakes: block["stakes"] } : {},
|
|
934
|
+
...block["stakesLevel"] !== void 0 ? { stakesLevel: block["stakesLevel"] } : {},
|
|
935
|
+
...typeof block["readingBudgetMinutes"] === "number" ? { readingBudgetMinutes: block["readingBudgetMinutes"] } : {},
|
|
936
|
+
...glossary !== void 0 ? { glossary } : {}
|
|
937
|
+
};
|
|
938
|
+
};
|
|
939
|
+
var validateLegacyStructure = (value) => {
|
|
940
|
+
const issues = [];
|
|
941
|
+
const doc = checkClosedObject(value, "$", [...TOP_ALLOWED], [...TOP_REQUIRED], [...TOP_STRINGS], issues);
|
|
942
|
+
if (doc === void 0) return { ok: false, issues };
|
|
943
|
+
const sections = [];
|
|
944
|
+
if (!Array.isArray(doc["sections"])) {
|
|
945
|
+
issues.push(issue("$.sections", "invalid_type", "expected an array"));
|
|
946
|
+
} else {
|
|
947
|
+
doc["sections"].forEach((section, index) => {
|
|
948
|
+
const checked = checkSectionNode(section, `$.sections[${index}]`, issues);
|
|
949
|
+
if (checked !== void 0) sections.push(checked);
|
|
950
|
+
});
|
|
951
|
+
}
|
|
952
|
+
const interactions = [];
|
|
953
|
+
if (!Array.isArray(doc["interactions"])) {
|
|
954
|
+
issues.push(issue("$.interactions", "invalid_type", "expected an array"));
|
|
955
|
+
} else {
|
|
956
|
+
doc["interactions"].forEach((interaction, index) => {
|
|
957
|
+
const checked = checkInteraction(interaction, `$.interactions[${index}]`, issues);
|
|
958
|
+
if (checked !== void 0) interactions.push(checked);
|
|
959
|
+
});
|
|
960
|
+
}
|
|
961
|
+
let provenance;
|
|
962
|
+
const rawProvenance = checkClosedObject(
|
|
963
|
+
doc["provenance"],
|
|
964
|
+
"$.provenance",
|
|
965
|
+
["source", "readAt", "comprehensionEvidence"],
|
|
966
|
+
["source", "readAt"],
|
|
967
|
+
["source", "readAt"],
|
|
968
|
+
issues
|
|
969
|
+
);
|
|
970
|
+
if (rawProvenance !== void 0) {
|
|
971
|
+
let evidence;
|
|
972
|
+
if (rawProvenance["comprehensionEvidence"] !== void 0) {
|
|
973
|
+
const evidenceStart = issues.length;
|
|
974
|
+
const rawEvidence = checkClosedObject(
|
|
975
|
+
rawProvenance["comprehensionEvidence"],
|
|
976
|
+
"$.provenance.comprehensionEvidence",
|
|
977
|
+
["subject", "dossierHash", "signature"],
|
|
978
|
+
["subject", "dossierHash"],
|
|
979
|
+
["subject", "dossierHash", "signature"],
|
|
980
|
+
issues
|
|
981
|
+
);
|
|
982
|
+
if (rawEvidence !== void 0 && issues.length === evidenceStart) {
|
|
983
|
+
evidence = {
|
|
984
|
+
subject: rawEvidence["subject"],
|
|
985
|
+
dossierHash: rawEvidence["dossierHash"],
|
|
986
|
+
...typeof rawEvidence["signature"] === "string" ? { signature: rawEvidence["signature"] } : {}
|
|
987
|
+
};
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
provenance = {
|
|
991
|
+
source: rawProvenance["source"],
|
|
992
|
+
readAt: rawProvenance["readAt"],
|
|
993
|
+
...evidence !== void 0 ? { comprehensionEvidence: evidence } : {}
|
|
994
|
+
};
|
|
995
|
+
}
|
|
996
|
+
const amendmentTrace = [];
|
|
997
|
+
if (!Array.isArray(doc["amendmentTrace"])) {
|
|
998
|
+
issues.push(issue("$.amendmentTrace", "invalid_type", "expected an array"));
|
|
999
|
+
} else {
|
|
1000
|
+
doc["amendmentTrace"].forEach((step, index) => {
|
|
1001
|
+
const checked = checkAmendmentStep(step, `$.amendmentTrace[${index}]`, issues);
|
|
1002
|
+
if (checked !== void 0) amendmentTrace.push(checked);
|
|
1003
|
+
});
|
|
1004
|
+
}
|
|
1005
|
+
let readability;
|
|
1006
|
+
if (doc["readability"] !== void 0) {
|
|
1007
|
+
readability = checkReadability(doc["readability"], "$.readability", issues);
|
|
1008
|
+
}
|
|
1009
|
+
if (issues.length > 0 || provenance === void 0 || doc["readability"] !== void 0 && readability === void 0) {
|
|
1010
|
+
return { ok: false, issues };
|
|
1011
|
+
}
|
|
1012
|
+
if (typeof doc["ref"] !== "string" || typeof doc["subject"] !== "string" || typeof doc["title"] !== "string" || typeof doc["hash"] !== "string" || typeof doc["cursor"] !== "string") {
|
|
1013
|
+
return { ok: false, issues };
|
|
1014
|
+
}
|
|
1015
|
+
return {
|
|
1016
|
+
ok: true,
|
|
1017
|
+
value: {
|
|
1018
|
+
ref: doc["ref"],
|
|
1019
|
+
subject: doc["subject"],
|
|
1020
|
+
title: doc["title"],
|
|
1021
|
+
hash: doc["hash"],
|
|
1022
|
+
cursor: doc["cursor"],
|
|
1023
|
+
sections,
|
|
1024
|
+
interactions,
|
|
1025
|
+
provenance,
|
|
1026
|
+
amendmentTrace,
|
|
1027
|
+
...readability !== void 0 ? { readability } : {}
|
|
1028
|
+
}
|
|
1029
|
+
};
|
|
1030
|
+
};
|
|
1031
|
+
var validateDecisionDossierStructure = (value) => {
|
|
1032
|
+
if (isRecord(value) && Object.hasOwn(value, "schemaVersion")) {
|
|
1033
|
+
if (value.schemaVersion !== 2) return { ok: false, issues: [issue("$.schemaVersion", "unsupported_version", "Supported explicit version: 2; omit schemaVersion for legacy v1")] };
|
|
1034
|
+
return checkEvidence(value, validateLegacyStructure);
|
|
1035
|
+
}
|
|
1036
|
+
return validateLegacyStructure(value);
|
|
1037
|
+
};
|
|
1038
|
+
var validateDecisionDossierSemantics = (doc) => {
|
|
1039
|
+
const issues = [];
|
|
1040
|
+
const seen = /* @__PURE__ */ new Map();
|
|
1041
|
+
const registerId = (id, path) => {
|
|
1042
|
+
const first = seen.get(id);
|
|
1043
|
+
if (first !== void 0) {
|
|
1044
|
+
issues.push(issue(path, "duplicate_id", `node id "${id}" already used at ${first}`));
|
|
1045
|
+
} else {
|
|
1046
|
+
seen.set(id, path);
|
|
1047
|
+
}
|
|
1048
|
+
};
|
|
1049
|
+
doc.sections.forEach((section, index) => {
|
|
1050
|
+
const path = `$.sections[${index}]`;
|
|
1051
|
+
registerId(section.id, `${path}.id`);
|
|
1052
|
+
if (section.kind === "optionSet") {
|
|
1053
|
+
section.options.forEach((option, optionIndex) => {
|
|
1054
|
+
registerId(option.id, `${path}.options[${optionIndex}].id`);
|
|
1055
|
+
});
|
|
1056
|
+
}
|
|
1057
|
+
});
|
|
1058
|
+
const resolvable = /* @__PURE__ */ new Set([doc.ref]);
|
|
1059
|
+
for (const section of doc.sections) {
|
|
1060
|
+
resolvable.add(section.id);
|
|
1061
|
+
resolvable.add(section.targetRef);
|
|
1062
|
+
if (section.kind === "optionSet") {
|
|
1063
|
+
for (const option of section.options) {
|
|
1064
|
+
resolvable.add(option.id);
|
|
1065
|
+
resolvable.add(option.targetRef);
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
doc.interactions.forEach((interaction, index) => {
|
|
1070
|
+
if (!resolvable.has(interaction.targetRef)) {
|
|
1071
|
+
issues.push(
|
|
1072
|
+
issue(
|
|
1073
|
+
`$.interactions[${index}].targetRef`,
|
|
1074
|
+
"unresolved_target",
|
|
1075
|
+
`interaction target "${interaction.targetRef}" resolves to no node`
|
|
1076
|
+
)
|
|
1077
|
+
);
|
|
1078
|
+
}
|
|
1079
|
+
});
|
|
1080
|
+
const evidence = doc.provenance.comprehensionEvidence;
|
|
1081
|
+
if (evidence !== void 0 && evidence.dossierHash !== doc.hash) {
|
|
1082
|
+
issues.push(
|
|
1083
|
+
issue(
|
|
1084
|
+
"$.provenance.comprehensionEvidence.dossierHash",
|
|
1085
|
+
"evidence_mismatch",
|
|
1086
|
+
"comprehension evidence does not match the snapshot hash"
|
|
1087
|
+
)
|
|
1088
|
+
);
|
|
1089
|
+
}
|
|
1090
|
+
return issues;
|
|
1091
|
+
};
|
|
1092
|
+
var validateDecisionDossierDocument = (value) => {
|
|
1093
|
+
const structural = validateDecisionDossierStructure(value);
|
|
1094
|
+
if (!structural.ok) return structural;
|
|
1095
|
+
const semantic = validateDecisionDossierSemantics(structural.value);
|
|
1096
|
+
if (semantic.length > 0) return { ok: false, issues: semantic };
|
|
1097
|
+
return structural;
|
|
1098
|
+
};
|
|
1099
|
+
var assertDecisionDossierDocument = (value) => {
|
|
1100
|
+
const result = validateDecisionDossierDocument(value);
|
|
1101
|
+
if (!result.ok) throw new DecisionDossierValidationError(result.issues);
|
|
1102
|
+
return result.value;
|
|
1103
|
+
};
|
|
1104
|
+
var validateDecisionDossierForPresentation = (value) => {
|
|
1105
|
+
const result = validateDecisionDossierDocument(value);
|
|
1106
|
+
if (!result.ok) return result;
|
|
1107
|
+
const issues = validateDecisionDossierReadability(result.value);
|
|
1108
|
+
return issues.length > 0 ? { ok: false, issues } : result;
|
|
1109
|
+
};
|
|
1110
|
+
var assertDecisionDossierForPresentation = (value) => {
|
|
1111
|
+
const result = validateDecisionDossierForPresentation(value);
|
|
1112
|
+
if (!result.ok) throw new DecisionDossierValidationError(result.issues);
|
|
1113
|
+
return result.value;
|
|
1114
|
+
};
|
|
1115
|
+
export {
|
|
1116
|
+
DOSSIER_SCHEMA_ID,
|
|
1117
|
+
DOSSIER_SCHEMA_VERSION,
|
|
1118
|
+
DecisionDossierValidationError,
|
|
1119
|
+
READABILITY_BUDGETS,
|
|
1120
|
+
READABILITY_LIMITS,
|
|
1121
|
+
assertDecisionDossierDocument,
|
|
1122
|
+
assertDecisionDossierForPresentation,
|
|
1123
|
+
validateDecisionDossierDocument,
|
|
1124
|
+
validateDecisionDossierForPresentation,
|
|
1125
|
+
validateDecisionDossierReadability,
|
|
1126
|
+
validateDecisionDossierSemantics,
|
|
1127
|
+
validateDecisionDossierStructure
|
|
1128
|
+
};
|