@inflexa-ai/harness 0.17.0 → 0.19.0
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/dist/agents/report-builder.d.ts +2 -0
- package/dist/agents/report-builder.js +2 -0
- package/dist/agents/report-session-agent.d.ts +56 -0
- package/dist/agents/report-session-agent.js +72 -0
- package/dist/app/report-session-runtime.d.ts +72 -0
- package/dist/app/report-session-runtime.js +157 -0
- package/dist/app/spawn-report-session.d.ts +85 -0
- package/dist/app/spawn-report-session.js +83 -0
- package/dist/contracts/chat-events.d.ts +9 -0
- package/dist/contracts/index.d.ts +6 -2
- package/dist/contracts/index.js +3 -1
- package/dist/contracts/organ-system.d.ts +49 -0
- package/dist/contracts/organ-system.js +67 -0
- package/dist/contracts/report-blocks.d.ts +564 -0
- package/dist/contracts/report-blocks.js +117 -0
- package/dist/contracts/report-reference.d.ts +459 -0
- package/dist/contracts/report-reference.js +256 -0
- package/dist/contracts/schemas/chat-events.d.ts +2 -0
- package/dist/contracts/schemas/chat-events.js +2 -0
- package/dist/contracts/severity.d.ts +15 -0
- package/dist/contracts/severity.js +10 -0
- package/dist/contracts/target-dossier.d.ts +8675 -12972
- package/dist/contracts/target-dossier.js +534 -591
- package/dist/data/safety-panel-schema.d.ts +18 -5
- package/dist/data/safety-panel-schema.js +4 -4
- package/dist/execution/artifact-metadata.js +1 -0
- package/dist/execution/report-runner.js +1 -3
- package/dist/execution/run-synthesis.js +2 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +19 -0
- package/dist/lib/async-utils.d.ts +16 -4
- package/dist/lib/async-utils.js +20 -15
- package/dist/lib/host-concurrency.js +1 -0
- package/dist/loop/__fixtures__/scripted-provider.js +23 -2
- package/dist/loop/run-agent.js +58 -10
- package/dist/loop/tool-detail.d.ts +40 -0
- package/dist/loop/tool-detail.js +35 -3
- package/dist/loop/types.d.ts +13 -0
- package/dist/memory/thread-history.d.ts +10 -0
- package/dist/memory/thread-history.js +12 -1
- package/dist/memory/thread-store.d.ts +4 -4
- package/dist/memory/thread-store.js +18 -9
- package/dist/prompts/report-session.d.ts +1 -0
- package/dist/prompts/report-session.js +89 -0
- package/dist/prompts/target-assessment/briefs/executive-recommendation.d.ts +1 -1
- package/dist/prompts/target-assessment/briefs/executive-recommendation.js +5 -5
- package/dist/prompts/target-assessment/briefs/liability-bullets.d.ts +1 -1
- package/dist/prompts/target-assessment/briefs/liability-bullets.js +1 -1
- package/dist/prompts/target-assessment/briefs/target-organ-liabilities.d.ts +1 -1
- package/dist/prompts/target-assessment/briefs/target-organ-liabilities.js +11 -3
- package/dist/prompts/target-assessment/investigation/adversarial-critique.d.ts +1 -0
- package/dist/prompts/target-assessment/investigation/adversarial-critique.js +67 -0
- package/dist/prompts/target-assessment/investigation/claim-reverification.d.ts +1 -0
- package/dist/prompts/target-assessment/investigation/claim-reverification.js +49 -0
- package/dist/prompts/target-assessment/investigation/index.d.ts +3 -0
- package/dist/prompts/target-assessment/investigation/index.js +3 -0
- package/dist/prompts/target-assessment/investigation/mechanism-proposal.d.ts +1 -0
- package/dist/prompts/target-assessment/investigation/mechanism-proposal.js +49 -0
- package/dist/prompts/target-assessment/tox-voice/index.d.ts +1 -1
- package/dist/prompts/target-assessment/tox-voice/vocabulary.d.ts +8 -5
- package/dist/prompts/target-assessment/tox-voice/vocabulary.js +9 -20
- package/dist/providers/__fixtures__/session.d.ts +5 -4
- package/dist/providers/__fixtures__/session.js +4 -4
- package/dist/providers/ai-sdk.d.ts +77 -0
- package/dist/providers/ai-sdk.js +149 -19
- package/dist/providers/errors.d.ts +14 -0
- package/dist/providers/errors.js +103 -18
- package/dist/providers/types.d.ts +16 -0
- package/dist/providers/types.js +10 -1
- package/dist/report-model/block-walk.d.ts +56 -0
- package/dist/report-model/block-walk.js +89 -0
- package/dist/report-model/draft-finish.d.ts +60 -0
- package/dist/report-model/draft-finish.js +56 -0
- package/dist/report-model/draft-operations.d.ts +125 -0
- package/dist/report-model/draft-operations.js +341 -0
- package/dist/report-model/draft-read.d.ts +59 -0
- package/dist/report-model/draft-read.js +109 -0
- package/dist/report-model/draft.d.ts +51 -0
- package/dist/report-model/draft.js +32 -0
- package/dist/report-model/fixture-resolver.d.ts +8 -0
- package/dist/report-model/fixture-resolver.js +252 -0
- package/dist/report-model/pin-snapshot.d.ts +30 -0
- package/dist/report-model/pin-snapshot.js +40 -0
- package/dist/report-model/reference-resolver.d.ts +113 -0
- package/dist/report-model/reference-resolver.js +60 -0
- package/dist/report-model/structural-validation.d.ts +22 -0
- package/dist/report-model/structural-validation.js +68 -0
- package/dist/report-model/validate.d.ts +72 -0
- package/dist/report-model/validate.js +95 -0
- package/dist/report-render/chart.d.ts +33 -0
- package/dist/report-render/chart.js +538 -0
- package/dist/report-render/page.d.ts +127 -0
- package/dist/report-render/page.js +307 -0
- package/dist/report-render/references.d.ts +32 -0
- package/dist/report-render/references.js +44 -0
- package/dist/report-render/render.d.ts +25 -0
- package/dist/report-render/render.js +125 -0
- package/dist/report-render/script-json.d.ts +13 -0
- package/dist/report-render/script-json.js +15 -0
- package/dist/report-render/types.d.ts +39 -0
- package/dist/report-render/types.js +10 -0
- package/dist/report-render/value-bridge.d.ts +62 -0
- package/dist/report-render/value-bridge.js +82 -0
- package/dist/report-render/views/chart-view.d.ts +11 -0
- package/dist/report-render/views/chart-view.js +23 -0
- package/dist/report-render/views/page-view.d.ts +20 -0
- package/dist/report-render/views/page-view.js +49 -0
- package/dist/report-render/views/prose.d.ts +28 -0
- package/dist/report-render/views/prose.js +75 -0
- package/dist/report-render/views/references-view.d.ts +20 -0
- package/dist/report-render/views/references-view.js +64 -0
- package/dist/report-render/views/values.d.ts +42 -0
- package/dist/report-render/views/values.js +43 -0
- package/dist/runtime/assemble.d.ts +15 -0
- package/dist/runtime/assemble.js +28 -6
- package/dist/runtime/boot.d.ts +3 -3
- package/dist/runtime/boot.js +15 -4
- package/dist/runtime/dbos.d.ts +4 -4
- package/dist/state/artifacts.d.ts +16 -0
- package/dist/state/artifacts.js +18 -0
- package/dist/state/init.js +54 -0
- package/dist/state/purge-analysis.js +2 -0
- package/dist/state/report-session-state.d.ts +112 -0
- package/dist/state/report-session-state.js +150 -0
- package/dist/state/report-versions.d.ts +129 -0
- package/dist/state/report-versions.js +167 -0
- package/dist/state/snapshot-parse.d.ts +34 -0
- package/dist/state/snapshot-parse.js +82 -0
- package/dist/tasks/data-profile.js +1 -0
- package/dist/tools/ad-hoc-router.d.ts +7 -2
- package/dist/tools/ad-hoc-router.js +2 -1
- package/dist/tools/bio/chembl.js +1 -0
- package/dist/tools/bio/comptox.js +1 -0
- package/dist/tools/bio/drug-gene-interactions.js +1 -0
- package/dist/tools/bio/gene-disease-evidence.js +1 -0
- package/dist/tools/bio/gene-preclinical-profile.js +1 -0
- package/dist/tools/bio/keys.d.ts +3 -2
- package/dist/tools/bio/keys.js +3 -2
- package/dist/tools/bio/lookup-annotation.js +1 -0
- package/dist/tools/bio/opentargets.d.ts +3 -3
- package/dist/tools/bio/opentargets.js +4 -3
- package/dist/tools/bio/pubchem.js +1 -0
- package/dist/tools/bio/search-clinical-trials.js +1 -0
- package/dist/tools/bio/search-faers.js +1 -0
- package/dist/tools/bio/search-geo-datasets.js +1 -0
- package/dist/tools/bio/search-interactions.js +1 -0
- package/dist/tools/bio/target-safety.d.ts +4 -6
- package/dist/tools/bio/target-safety.js +7 -6
- package/dist/tools/define-tool.d.ts +19 -12
- package/dist/tools/define-tool.js +4 -2
- package/dist/tools/display/show-user.js +1 -0
- package/dist/tools/iterate-report.js +2 -0
- package/dist/tools/lib/chembl-client.d.ts +2 -0
- package/dist/tools/lib/chembl-client.js +1 -0
- package/dist/tools/lib/monarch-client.d.ts +42 -0
- package/dist/tools/lib/monarch-client.js +100 -0
- package/dist/tools/report/build-report.js +1 -0
- package/dist/tools/report/mint-preview-url.js +1 -0
- package/dist/tools/report/preview-snapshot.js +1 -0
- package/dist/tools/report/submit-report.js +1 -0
- package/dist/tools/report/version-fs.js +4 -0
- package/dist/tools/report-authoring/authoring-tools.d.ts +241 -0
- package/dist/tools/report-authoring/authoring-tools.js +460 -0
- package/dist/tools/report-session/index.d.ts +8 -0
- package/dist/tools/report-session/index.js +8 -0
- package/dist/tools/report-session/preview-report.d.ts +90 -0
- package/dist/tools/report-session/preview-report.js +245 -0
- package/dist/tools/research/context7-docs.js +2 -0
- package/dist/tools/research/generate-analogy-report.js +1 -0
- package/dist/tools/research/generate-plan.js +7 -2
- package/dist/tools/research/inspect-data-profile.js +4 -0
- package/dist/tools/research/literature-reviewer.js +1 -0
- package/dist/tools/research/search-arxiv.js +1 -0
- package/dist/tools/research/search-github-repos.js +1 -0
- package/dist/tools/research/search-semantic-scholar.js +1 -0
- package/dist/tools/sandbox/list-available-packages.js +23 -0
- package/dist/tools/sandbox/list-available-refs.js +36 -0
- package/dist/tools/sandbox/report-blocker.js +1 -0
- package/dist/tools/sandbox/skills.js +2 -0
- package/dist/tools/workspace/file-stat.js +1 -0
- package/dist/tools/workspace/show-file.js +2 -0
- package/dist/tools/workspace/show-plan.js +1 -0
- package/dist/workflows/execute-analysis.d.ts +5 -1
- package/dist/workflows/execute-analysis.js +5 -5
- package/dist/workflows/execute-target-assessment.d.ts +13 -2
- package/dist/workflows/execute-target-assessment.js +78 -16
- package/dist/workflows/target-assessment/assemblers/index.d.ts +1 -1
- package/dist/workflows/target-assessment/assemblers/index.js +1 -1
- package/dist/workflows/target-assessment/assemblers/literature.d.ts +9 -27
- package/dist/workflows/target-assessment/assemblers/literature.js +32 -48
- package/dist/workflows/target-assessment/assemblers/orchestrator.d.ts +17 -9
- package/dist/workflows/target-assessment/assemblers/orchestrator.js +195 -85
- package/dist/workflows/target-assessment/assemblers/safety.d.ts +70 -48
- package/dist/workflows/target-assessment/assemblers/safety.js +125 -42
- package/dist/workflows/target-assessment/collectors/index.d.ts +5 -2
- package/dist/workflows/target-assessment/collectors/index.js +48 -5
- package/dist/workflows/target-assessment/coverage.d.ts +43 -27
- package/dist/workflows/target-assessment/coverage.js +33 -29
- package/dist/workflows/target-assessment/fanout/index.js +1 -0
- package/dist/workflows/target-assessment/investigation/index.d.ts +97 -0
- package/dist/workflows/target-assessment/investigation/index.js +419 -0
- package/dist/workflows/target-assessment/lib/approval-precedents.d.ts +26 -5
- package/dist/workflows/target-assessment/lib/approval-precedents.js +95 -29
- package/dist/workflows/target-assessment/lib/citation-validator.js +1 -1
- package/dist/workflows/target-assessment/lib/clinical-consequence-annotator.d.ts +2 -2
- package/dist/workflows/target-assessment/lib/clinical-evidence-attribution.d.ts +2 -3
- package/dist/workflows/target-assessment/lib/clinical-evidence-attribution.js +0 -4
- package/dist/workflows/target-assessment/lib/compute-derived.d.ts +6 -5
- package/dist/workflows/target-assessment/lib/compute-derived.js +14 -5
- package/dist/workflows/target-assessment/lib/family-complex-supplement.d.ts +5 -6
- package/dist/workflows/target-assessment/lib/family-complex-supplement.js +2 -3
- package/dist/workflows/target-assessment/lib/fda-label-safety.d.ts +72 -0
- package/dist/workflows/target-assessment/lib/fda-label-safety.js +166 -0
- package/dist/workflows/target-assessment/lib/heterodimer-filter.d.ts +0 -9
- package/dist/workflows/target-assessment/lib/heterodimer-filter.js +0 -10
- package/dist/workflows/target-assessment/lib/hpo-organ-map.d.ts +34 -0
- package/dist/workflows/target-assessment/lib/hpo-organ-map.js +63 -0
- package/dist/workflows/target-assessment/lib/impc-organ-map.d.ts +19 -0
- package/dist/workflows/target-assessment/lib/impc-organ-map.js +39 -0
- package/dist/workflows/target-assessment/lib/meddra-organ-map.d.ts +24 -14
- package/dist/workflows/target-assessment/lib/meddra-organ-map.js +59 -47
- package/dist/workflows/target-assessment/lib/recommendation-sanitizer.js +1 -1
- package/dist/workflows/target-assessment/lib/regulatory-actions.d.ts +2 -3
- package/dist/workflows/target-assessment/lib/regulatory-actions.js +33 -4
- package/dist/workflows/target-assessment/lib/safety-corroboration.d.ts +44 -0
- package/dist/workflows/target-assessment/lib/safety-corroboration.js +273 -0
- package/dist/workflows/target-assessment/lib/target-identity-filter.d.ts +5 -7
- package/dist/workflows/target-assessment/lib/target-identity-filter.js +5 -7
- package/dist/workflows/target-assessment/metrics.d.ts +1 -6
- package/dist/workflows/target-assessment/metrics.js +1 -13
- package/dist/workflows/target-assessment/phase4-assemble.d.ts +2147 -807
- package/dist/workflows/target-assessment/phase4-assemble.js +19 -19
- package/dist/workflows/target-assessment/phase5-persist.d.ts +20 -21
- package/dist/workflows/target-assessment/phase5-persist.js +56 -173
- package/dist/workflows/target-assessment/schemas.d.ts +46 -1
- package/dist/workflows/target-assessment/schemas.js +19 -0
- package/dist/workflows/target-assessment/steps/fanout/polypharm-for-one-modulator-step.d.ts +1 -0
- package/dist/workflows/target-assessment/steps/fanout/polypharm-for-one-modulator-step.js +2 -0
- package/dist/workflows/target-assessment/steps/phase2-aggregate.d.ts +26 -62
- package/dist/workflows/target-assessment/steps/phase2-aggregate.js +0 -4
- package/dist/workflows/target-assessment/steps/phase3-aggregate.d.ts +27 -154
- package/dist/workflows/target-assessment/steps/phase3-aggregate.js +0 -6
- package/dist/workflows/target-assessment/steps/synthesis/diagnostics.d.ts +0 -6
- package/dist/workflows/target-assessment/steps/synthesis/diagnostics.js +0 -18
- package/dist/workflows/target-assessment/sub-workflows/per-modulator-polypharm.d.ts +1 -0
- package/dist/workflows/target-assessment/synthesis/index.d.ts +52 -5
- package/dist/workflows/target-assessment/synthesis/index.js +4 -1
- package/dist/workflows/target-assessment/synthesis-probes.d.ts +3 -3
- package/package.json +4 -1
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one walk over a block tree.
|
|
3
|
+
*
|
|
4
|
+
* A block kind decides where a reference sits, which prose carries a free numeral, and whether the block
|
|
5
|
+
* holds children. Three consumers need that same knowledge: the mechanical validator, the draft finish,
|
|
6
|
+
* and the draft operations. A switch for each consumer is a switch that a ninth block kind can miss in
|
|
7
|
+
* silence, because each arm returns and none of them fails to build. Thus the walk lives here one time.
|
|
8
|
+
*
|
|
9
|
+
* The walk reads a finished `Block` tree and a relaxed `DraftBlock` tree alike. The two differ only in the
|
|
10
|
+
* section rules, and the section arm reads the children of either one.
|
|
11
|
+
*
|
|
12
|
+
* The walk resolves nothing and it opens no file. It reports what the tree holds, and a caller decides
|
|
13
|
+
* which part it needs.
|
|
14
|
+
*/
|
|
15
|
+
import type { Block } from "../contracts/report-blocks.js";
|
|
16
|
+
import type { Reference } from "../contracts/report-reference.js";
|
|
17
|
+
import type { DraftBlock } from "./draft.js";
|
|
18
|
+
/** A block of a finished report, or a block of a draft. The atoms are the same shape in both. */
|
|
19
|
+
export type AnyBlock = Block | DraftBlock;
|
|
20
|
+
/**
|
|
21
|
+
* One reference that the walk met, tied to the block that carries it.
|
|
22
|
+
*
|
|
23
|
+
* `encodingColumns` is present for a `chart` only. A chart names its axes as free strings, thus the names
|
|
24
|
+
* must be matched against the table that the binding resolves to. Nothing else can catch a chart that
|
|
25
|
+
* plots a column which does not exist. The match needs the resolved rows, thus only a value-tier consumer
|
|
26
|
+
* reads this field.
|
|
27
|
+
*/
|
|
28
|
+
export interface CollectedReference {
|
|
29
|
+
blockId: string;
|
|
30
|
+
reference: Reference;
|
|
31
|
+
encodingColumns?: string[];
|
|
32
|
+
}
|
|
33
|
+
/** An advisory warning about the content of one block. A warning never makes a report invalid. */
|
|
34
|
+
export interface ReportWarning {
|
|
35
|
+
blockId: string;
|
|
36
|
+
kind: "free-numeral";
|
|
37
|
+
detail: string;
|
|
38
|
+
}
|
|
39
|
+
/** What one walk over a block tree found. */
|
|
40
|
+
export interface BlockWalk {
|
|
41
|
+
/** Each reference, in document order, tied to the block that carries it. */
|
|
42
|
+
references: CollectedReference[];
|
|
43
|
+
/** Each id that more than one block holds, named one time, in sorted order. */
|
|
44
|
+
repeatedIds: string[];
|
|
45
|
+
/** Each free numeral that prose carries. */
|
|
46
|
+
warnings: ReportWarning[];
|
|
47
|
+
}
|
|
48
|
+
/** Warn for each free-standing numeral that the prose of one block carries. */
|
|
49
|
+
export declare function numeralWarnings(blockId: string, prose: string): ReportWarning[];
|
|
50
|
+
/**
|
|
51
|
+
* Walk a block tree, and report each reference, each repeated id, and each free numeral.
|
|
52
|
+
*
|
|
53
|
+
* An id is what makes a block addressable, thus an amend by id is well defined only while each id belongs
|
|
54
|
+
* to one block. The walk is pre-order, thus the references follow the document order.
|
|
55
|
+
*/
|
|
56
|
+
export declare function walkBlocks(blocks: readonly AnyBlock[]): BlockWalk;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one walk over a block tree.
|
|
3
|
+
*
|
|
4
|
+
* A block kind decides where a reference sits, which prose carries a free numeral, and whether the block
|
|
5
|
+
* holds children. Three consumers need that same knowledge: the mechanical validator, the draft finish,
|
|
6
|
+
* and the draft operations. A switch for each consumer is a switch that a ninth block kind can miss in
|
|
7
|
+
* silence, because each arm returns and none of them fails to build. Thus the walk lives here one time.
|
|
8
|
+
*
|
|
9
|
+
* The walk reads a finished `Block` tree and a relaxed `DraftBlock` tree alike. The two differ only in the
|
|
10
|
+
* section rules, and the section arm reads the children of either one.
|
|
11
|
+
*
|
|
12
|
+
* The walk resolves nothing and it opens no file. It reports what the tree holds, and a caller decides
|
|
13
|
+
* which part it needs.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* A free-standing token that looks like a number, with an optional decimal part and an optional percent
|
|
17
|
+
* sign.
|
|
18
|
+
*
|
|
19
|
+
* The left boundary keeps the digits of a name out of the warnings. The domain prose is dense with a
|
|
20
|
+
* symbol such as `TP53`, `CD8`, or `IL6`, and without the boundary each one warns for its digits and
|
|
21
|
+
* buries the real free figures.
|
|
22
|
+
*
|
|
23
|
+
* The check is advisory only. A natural-language numeral is brittle to police, because a numeral in prose
|
|
24
|
+
* can be a real free-standing figure or a harmless part of a name. Thus a hit warns, and it never fails
|
|
25
|
+
* the report.
|
|
26
|
+
*/
|
|
27
|
+
const NUMERAL_PATTERN = /(?<![A-Za-z0-9])-?\d+(?:\.\d+)?%?/g;
|
|
28
|
+
/** Warn for each free-standing numeral that the prose of one block carries. */
|
|
29
|
+
export function numeralWarnings(blockId, prose) {
|
|
30
|
+
const warnings = [];
|
|
31
|
+
for (const match of prose.matchAll(NUMERAL_PATTERN)) {
|
|
32
|
+
warnings.push({ blockId, kind: "free-numeral", detail: match[0] });
|
|
33
|
+
}
|
|
34
|
+
return warnings;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Walk a block tree, and report each reference, each repeated id, and each free numeral.
|
|
38
|
+
*
|
|
39
|
+
* An id is what makes a block addressable, thus an amend by id is well defined only while each id belongs
|
|
40
|
+
* to one block. The walk is pre-order, thus the references follow the document order.
|
|
41
|
+
*/
|
|
42
|
+
export function walkBlocks(blocks) {
|
|
43
|
+
const references = [];
|
|
44
|
+
const warnings = [];
|
|
45
|
+
const seenIds = new Set();
|
|
46
|
+
const repeated = new Set();
|
|
47
|
+
const visit = (block) => {
|
|
48
|
+
if (seenIds.has(block.id)) {
|
|
49
|
+
repeated.add(block.id);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
seenIds.add(block.id);
|
|
53
|
+
}
|
|
54
|
+
switch (block.kind) {
|
|
55
|
+
case "section":
|
|
56
|
+
for (const child of block.blocks) {
|
|
57
|
+
visit(child);
|
|
58
|
+
}
|
|
59
|
+
return;
|
|
60
|
+
case "text":
|
|
61
|
+
warnings.push(...numeralWarnings(block.id, block.content.prose));
|
|
62
|
+
return;
|
|
63
|
+
case "claim":
|
|
64
|
+
warnings.push(...numeralWarnings(block.id, block.content.prose));
|
|
65
|
+
for (const binding of block.bindings) {
|
|
66
|
+
references.push({ blockId: block.id, reference: binding });
|
|
67
|
+
}
|
|
68
|
+
return;
|
|
69
|
+
case "metric":
|
|
70
|
+
references.push({ blockId: block.id, reference: block.value });
|
|
71
|
+
return;
|
|
72
|
+
case "chart": {
|
|
73
|
+
const encoding = block.encoding;
|
|
74
|
+
const encodingColumns = [encoding.x, encoding.y, encoding.group, encoding.value].filter((column) => column !== undefined);
|
|
75
|
+
references.push({ blockId: block.id, reference: block.binding, encodingColumns });
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
case "table":
|
|
79
|
+
case "figure":
|
|
80
|
+
case "citation":
|
|
81
|
+
references.push({ blockId: block.id, reference: block.binding });
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
for (const block of blocks) {
|
|
86
|
+
visit(block);
|
|
87
|
+
}
|
|
88
|
+
return { references, repeatedIds: [...repeated].sort(), warnings };
|
|
89
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The finish of a draft.
|
|
3
|
+
*
|
|
4
|
+
* An edit refuses what is wrong. The finish refuses what is missing. Thus the finish gates the whole
|
|
5
|
+
* draft one time: the full document schema, the unique ids, and the structural tier over every reference.
|
|
6
|
+
*
|
|
7
|
+
* The finish opens no file, and it reads the snapshot alone. Thus it runs the structural tier only, and
|
|
8
|
+
* the value tier stays in the gate of the report pipeline. The chart encoding-column match needs the rows
|
|
9
|
+
* behind a binding, thus it stays with the value tier.
|
|
10
|
+
*
|
|
11
|
+
* The free-numeral scan needs no file, thus the finish runs it and reports each hit as a warning. A
|
|
12
|
+
* warning never makes a draft invalid, and it rides beside the outcome in either case. Without the
|
|
13
|
+
* channel a caller could not read the one signal that catches a figure typed into prose with no metric
|
|
14
|
+
* block behind it.
|
|
15
|
+
*
|
|
16
|
+
* The result is plain data. A gap is an expected outcome, not an error, thus the finish never throws. On
|
|
17
|
+
* a pass the finish gives the valid document, and it does not change the draft.
|
|
18
|
+
*/
|
|
19
|
+
import { type ReportDocument } from "../contracts/report-blocks.js";
|
|
20
|
+
import type { UnresolvedReference } from "../contracts/report-reference.js";
|
|
21
|
+
import { type ReportWarning } from "./block-walk.js";
|
|
22
|
+
import type { DraftDocument } from "./draft.js";
|
|
23
|
+
import type { ReportSnapshot } from "./reference-resolver.js";
|
|
24
|
+
/** A schema conformance gap, reduced to a path and a message. */
|
|
25
|
+
export interface SchemaGap {
|
|
26
|
+
kind: "schema";
|
|
27
|
+
path: string;
|
|
28
|
+
message: string;
|
|
29
|
+
}
|
|
30
|
+
/** A duplicate id gap. More than one block holds the id. */
|
|
31
|
+
export interface DuplicateIdGap {
|
|
32
|
+
kind: "duplicate-id";
|
|
33
|
+
id: string;
|
|
34
|
+
}
|
|
35
|
+
/** An unresolved reference gap. It ties the block that carries the reference to the reason it did not resolve. */
|
|
36
|
+
export interface UnresolvedReferenceGap {
|
|
37
|
+
kind: "unresolved-reference";
|
|
38
|
+
blockId: string;
|
|
39
|
+
failure: UnresolvedReference;
|
|
40
|
+
}
|
|
41
|
+
/** One completeness gap of a draft. The kind set is closed. */
|
|
42
|
+
export type FinishGap = SchemaGap | DuplicateIdGap | UnresolvedReferenceGap;
|
|
43
|
+
/**
|
|
44
|
+
* The finish result. On a pass it gives the valid document. On a fail it gives each gap. The warnings
|
|
45
|
+
* ride along in either case, because a warning is advisory and it never decides the outcome.
|
|
46
|
+
*/
|
|
47
|
+
export type FinishResult = {
|
|
48
|
+
valid: true;
|
|
49
|
+
document: ReportDocument;
|
|
50
|
+
warnings: ReportWarning[];
|
|
51
|
+
} | {
|
|
52
|
+
valid: false;
|
|
53
|
+
gaps: FinishGap[];
|
|
54
|
+
warnings: ReportWarning[];
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Finish a draft. The finish validates the schema, the unique ids, and the structural resolution of each
|
|
58
|
+
* reference, and it reports each gap as data. It warns about each free numeral in prose.
|
|
59
|
+
*/
|
|
60
|
+
export declare function finishDraft(draft: DraftDocument, snapshot: ReportSnapshot): FinishResult;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The finish of a draft.
|
|
3
|
+
*
|
|
4
|
+
* An edit refuses what is wrong. The finish refuses what is missing. Thus the finish gates the whole
|
|
5
|
+
* draft one time: the full document schema, the unique ids, and the structural tier over every reference.
|
|
6
|
+
*
|
|
7
|
+
* The finish opens no file, and it reads the snapshot alone. Thus it runs the structural tier only, and
|
|
8
|
+
* the value tier stays in the gate of the report pipeline. The chart encoding-column match needs the rows
|
|
9
|
+
* behind a binding, thus it stays with the value tier.
|
|
10
|
+
*
|
|
11
|
+
* The free-numeral scan needs no file, thus the finish runs it and reports each hit as a warning. A
|
|
12
|
+
* warning never makes a draft invalid, and it rides beside the outcome in either case. Without the
|
|
13
|
+
* channel a caller could not read the one signal that catches a figure typed into prose with no metric
|
|
14
|
+
* block behind it.
|
|
15
|
+
*
|
|
16
|
+
* The result is plain data. A gap is an expected outcome, not an error, thus the finish never throws. On
|
|
17
|
+
* a pass the finish gives the valid document, and it does not change the draft.
|
|
18
|
+
*/
|
|
19
|
+
import { ReportDocumentSchema } from "../contracts/report-blocks.js";
|
|
20
|
+
import { walkBlocks } from "./block-walk.js";
|
|
21
|
+
import { validateReferenceStructure } from "./structural-validation.js";
|
|
22
|
+
/**
|
|
23
|
+
* Finish a draft. The finish validates the schema, the unique ids, and the structural resolution of each
|
|
24
|
+
* reference, and it reports each gap as data. It warns about each free numeral in prose.
|
|
25
|
+
*/
|
|
26
|
+
export function finishDraft(draft, snapshot) {
|
|
27
|
+
const gaps = [];
|
|
28
|
+
const parsed = ReportDocumentSchema.safeParse(draft);
|
|
29
|
+
if (!parsed.success) {
|
|
30
|
+
for (const issue of parsed.error.issues) {
|
|
31
|
+
gaps.push({
|
|
32
|
+
kind: "schema",
|
|
33
|
+
path: issue.path.map((segment) => String(segment)).join("."),
|
|
34
|
+
message: issue.message,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// The walk reads the draft tree, not the parse result. The draft is already typed, thus the walk stays
|
|
39
|
+
// well-defined even when the schema parse fails, and a caller still gets the id and reference gaps.
|
|
40
|
+
const { references, repeatedIds, warnings } = walkBlocks(draft.sections);
|
|
41
|
+
for (const id of repeatedIds) {
|
|
42
|
+
gaps.push({ kind: "duplicate-id", id });
|
|
43
|
+
}
|
|
44
|
+
for (const entry of references) {
|
|
45
|
+
const result = validateReferenceStructure(entry.reference, snapshot);
|
|
46
|
+
if (result.isErr()) {
|
|
47
|
+
gaps.push({ kind: "unresolved-reference", blockId: entry.blockId, failure: result.error });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// A schema failure always pushes a gap. Thus an empty gap list means the parse passed. The
|
|
51
|
+
// `parsed.success` test also narrows the type for the document return.
|
|
52
|
+
if (!parsed.success || gaps.length > 0) {
|
|
53
|
+
return { valid: false, gaps, warnings };
|
|
54
|
+
}
|
|
55
|
+
return { valid: true, document: parsed.data, warnings };
|
|
56
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pure operations that compose a draft report document.
|
|
3
|
+
*
|
|
4
|
+
* An operation takes the draft, an operation value, and the pinned snapshot. It gives a new draft, or a
|
|
5
|
+
* typed refusal in the error channel. It mutates nothing. Thus a refused operation leaves the input draft
|
|
6
|
+
* as it was.
|
|
7
|
+
*
|
|
8
|
+
* An operation validates the delta only. It parses the new payload with the draft grammar. It scans the
|
|
9
|
+
* ids that the payload brings, and it resolves each new reference against the snapshot with the
|
|
10
|
+
* structural tier. The completeness rules gate one time, at the finish.
|
|
11
|
+
*
|
|
12
|
+
* The candidate shares each untouched branch with the input draft. An operation rebuilds only the path to
|
|
13
|
+
* the edit. Thus the input stays intact, and the memory cost stays small.
|
|
14
|
+
*
|
|
15
|
+
* A destination names an anchor, not an index. An index breaks when the tree changes under the agent, and
|
|
16
|
+
* an anchor id stays stable.
|
|
17
|
+
*/
|
|
18
|
+
import { type Result } from "neverthrow";
|
|
19
|
+
import type { UnresolvedReference } from "../contracts/report-reference.js";
|
|
20
|
+
import { type DraftBlock, type DraftDocument, type DraftSectionBlock } from "./draft.js";
|
|
21
|
+
import type { ReportSnapshot } from "./reference-resolver.js";
|
|
22
|
+
/**
|
|
23
|
+
* The closed set of refusal reasons. Each operation gives a subset of these.
|
|
24
|
+
*
|
|
25
|
+
* `unknown-target` means that no block holds an id that the operation named. `conflicting-destination`
|
|
26
|
+
* means that the destination named two places at one time. The two are separate because the repair
|
|
27
|
+
* differs: the first sends the agent to the outline for a correct id, and the second tells it to drop one
|
|
28
|
+
* of the fields it gave.
|
|
29
|
+
*/
|
|
30
|
+
export type DraftRefusalReason = "malformed-block" | "duplicate-id" | "unknown-target" | "conflicting-destination" | "unresolved-reference" | "cycle" | "atom-at-root" | "not-a-section" | "payload-kind-mismatch";
|
|
31
|
+
/**
|
|
32
|
+
* A typed refusal. It carries the reason and a prose detail. The `unresolved-reference` reason also
|
|
33
|
+
* carries each reference that the snapshot does not resolve.
|
|
34
|
+
*/
|
|
35
|
+
export type DraftRefusal = {
|
|
36
|
+
reason: Exclude<DraftRefusalReason, "unresolved-reference">;
|
|
37
|
+
detail: string;
|
|
38
|
+
} | {
|
|
39
|
+
reason: "unresolved-reference";
|
|
40
|
+
detail: string;
|
|
41
|
+
unresolved: UnresolvedReference[];
|
|
42
|
+
};
|
|
43
|
+
/** The place inside a parent. The default place is `end`. An anchor names a sibling id. */
|
|
44
|
+
export type DraftPlace = "start" | "end" | {
|
|
45
|
+
before: string;
|
|
46
|
+
} | {
|
|
47
|
+
after: string;
|
|
48
|
+
};
|
|
49
|
+
/** The destination of an add or a move. `parentId` names a section, or the root when it is absent. */
|
|
50
|
+
export interface DraftDestination {
|
|
51
|
+
parentId?: string;
|
|
52
|
+
place?: DraftPlace;
|
|
53
|
+
}
|
|
54
|
+
/** The add operation value. The payload can be an atom, or a section that carries children. */
|
|
55
|
+
export interface AddOperation {
|
|
56
|
+
block: unknown;
|
|
57
|
+
destination?: DraftDestination;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The change operation value. A `title` retitles a section target. A `block` replaces an atom target.
|
|
61
|
+
* The operation stamps the target id on the block, thus an id mismatch is unrepresentable.
|
|
62
|
+
*/
|
|
63
|
+
export type ChangeOperation = {
|
|
64
|
+
targetId: string;
|
|
65
|
+
} & ({
|
|
66
|
+
title: string;
|
|
67
|
+
} | {
|
|
68
|
+
block: unknown;
|
|
69
|
+
});
|
|
70
|
+
/** The remove operation value. It names one block by its id. */
|
|
71
|
+
export interface RemoveOperation {
|
|
72
|
+
targetId: string;
|
|
73
|
+
}
|
|
74
|
+
/** The move operation value. It names one block, and a destination with the shape of the add destination. */
|
|
75
|
+
export interface MoveOperation {
|
|
76
|
+
targetId: string;
|
|
77
|
+
destination?: DraftDestination;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Set the title of the document.
|
|
81
|
+
*
|
|
82
|
+
* A title carries no id and no reference, thus it needs none of the shared checks and it cannot refuse.
|
|
83
|
+
* The document schema requires a non-empty title, and the finish reports an empty one as a gap.
|
|
84
|
+
*/
|
|
85
|
+
export declare function setTitle(draft: DraftDocument, title: string): DraftDocument;
|
|
86
|
+
/**
|
|
87
|
+
* Add a block at a destination.
|
|
88
|
+
*
|
|
89
|
+
* The root admits a section only, thus an atom at the root refuses. The validation covers the payload and
|
|
90
|
+
* each of its descendants.
|
|
91
|
+
*/
|
|
92
|
+
export declare function addBlock(draft: DraftDocument, operation: AddOperation, snapshot: ReportSnapshot): Result<DraftDocument, DraftRefusal>;
|
|
93
|
+
/**
|
|
94
|
+
* Change one block by its id.
|
|
95
|
+
*
|
|
96
|
+
* A section target takes a title, and its children stay as they are. An atom target takes a full block,
|
|
97
|
+
* and a kind change is permitted. A payload that does not match the target kind refuses.
|
|
98
|
+
*/
|
|
99
|
+
export declare function changeBlock(draft: DraftDocument, operation: ChangeOperation, snapshot: ReportSnapshot): Result<DraftDocument, DraftRefusal>;
|
|
100
|
+
/**
|
|
101
|
+
* Remove one block by its id.
|
|
102
|
+
*
|
|
103
|
+
* A removed section takes its whole subtree. A removed id is free for a later add.
|
|
104
|
+
*/
|
|
105
|
+
export declare function removeBlock(draft: DraftDocument, operation: RemoveOperation, snapshot: ReportSnapshot): Result<DraftDocument, DraftRefusal>;
|
|
106
|
+
/**
|
|
107
|
+
* Move one block to a destination.
|
|
108
|
+
*
|
|
109
|
+
* The moved block keeps its subtree. A section must not move into its own subtree, thus a move into the
|
|
110
|
+
* subtree refuses with a cycle. A move with the moved block as its own anchor refuses.
|
|
111
|
+
*/
|
|
112
|
+
export declare function moveBlock(draft: DraftDocument, operation: MoveOperation, snapshot: ReportSnapshot): Result<DraftDocument, DraftRefusal>;
|
|
113
|
+
/** One block, the path of child indices from the root to the block, and the section that holds it. */
|
|
114
|
+
export interface Located {
|
|
115
|
+
block: DraftBlock;
|
|
116
|
+
path: number[];
|
|
117
|
+
/** The section that holds the block, or `undefined` when the block sits at the root. */
|
|
118
|
+
parent?: DraftSectionBlock;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Find a block by its id, with the path from the root. The search visits each block one time.
|
|
122
|
+
*
|
|
123
|
+
* The read surface needs the same search, thus this is the one find-by-id in the draft model.
|
|
124
|
+
*/
|
|
125
|
+
export declare function locate(document: DraftDocument, id: string): Located | undefined;
|