dsh-research-report 0.3.32 → 0.4.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/CHANGELOG.md +9 -0
- package/LICENSE +0 -0
- package/README-es.md +0 -0
- package/README-hi.md +0 -0
- package/README-pt.md +0 -0
- package/README-zh.md +0 -0
- package/README.md +2 -0
- package/THIRD_PARTY_NOTICES.md +0 -0
- package/cordis.patch.yml +0 -0
- package/lib/cli.js +1 -1
- package/lib/index.js +196 -1
- package/lib/types/assemble.d.ts +0 -0
- package/lib/types/assemble.d.ts.map +0 -0
- package/lib/types/assemble.js +0 -0
- package/lib/types/assemble.js.map +0 -0
- package/lib/types/cli.d.ts +0 -0
- package/lib/types/cli.d.ts.map +0 -0
- package/lib/types/cli.js +0 -0
- package/lib/types/cli.js.map +0 -0
- package/lib/types/config.d.ts +0 -0
- package/lib/types/config.d.ts.map +0 -0
- package/lib/types/config.js +0 -0
- package/lib/types/config.js.map +0 -0
- package/lib/types/doi.d.ts +0 -0
- package/lib/types/doi.d.ts.map +0 -0
- package/lib/types/doi.js +0 -0
- package/lib/types/doi.js.map +0 -0
- package/lib/types/gather.d.ts +0 -0
- package/lib/types/gather.d.ts.map +0 -0
- package/lib/types/gather.js +0 -0
- package/lib/types/gather.js.map +0 -0
- package/lib/types/index.d.ts +0 -0
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/index.js +2 -0
- package/lib/types/index.js.map +1 -1
- package/lib/types/ledger.d.ts +0 -0
- package/lib/types/ledger.d.ts.map +0 -0
- package/lib/types/ledger.js +0 -0
- package/lib/types/ledger.js.map +0 -0
- package/lib/types/provider-local.d.ts +0 -0
- package/lib/types/provider-local.d.ts.map +0 -0
- package/lib/types/provider-local.js +0 -0
- package/lib/types/provider-local.js.map +0 -0
- package/lib/types/service.d.ts +0 -0
- package/lib/types/service.d.ts.map +0 -0
- package/lib/types/service.js +0 -0
- package/lib/types/service.js.map +0 -0
- package/lib/types/tools/evidence-add.d.ts +0 -0
- package/lib/types/tools/evidence-add.d.ts.map +0 -0
- package/lib/types/tools/evidence-add.js +0 -0
- package/lib/types/tools/evidence-add.js.map +0 -0
- package/lib/types/tools/ledger-query.d.ts +0 -0
- package/lib/types/tools/ledger-query.d.ts.map +0 -0
- package/lib/types/tools/ledger-query.js +0 -0
- package/lib/types/tools/ledger-query.js.map +0 -0
- package/lib/types/tools/research-report.d.ts +0 -0
- package/lib/types/tools/research-report.d.ts.map +0 -0
- package/lib/types/tools/research-report.js +0 -0
- package/lib/types/tools/research-report.js.map +0 -0
- package/lib/types/tools/research-trail.d.ts +60 -0
- package/lib/types/tools/research-trail.d.ts.map +1 -0
- package/lib/types/tools/research-trail.js +172 -0
- package/lib/types/tools/research-trail.js.map +1 -0
- package/lib/types/verify-sealed.d.ts +0 -0
- package/lib/types/verify-sealed.d.ts.map +0 -0
- package/lib/types/verify-sealed.js +0 -0
- package/lib/types/verify-sealed.js.map +0 -0
- package/lib/types/verify.d.ts +0 -0
- package/lib/types/verify.d.ts.map +0 -0
- package/lib/types/verify.js +0 -0
- package/lib/types/verify.js.map +0 -0
- package/lib/types/version.d.ts +1 -1
- package/lib/types/version.d.ts.map +1 -1
- package/lib/types/version.js +1 -1
- package/lib/types/version.js.map +1 -1
- package/lib/{verify-sealed-Dylli1KR.js → verify-sealed-BHAE-3Zw.js} +1 -1
- package/package.json +1 -1
- package/src/assemble.ts +0 -0
- package/src/cli.ts +0 -0
- package/src/config.ts +0 -0
- package/src/doi.ts +0 -0
- package/src/gather.ts +0 -0
- package/src/index.ts +2 -0
- package/src/ledger.ts +0 -0
- package/src/provider-local.ts +0 -0
- package/src/service.ts +0 -0
- package/src/tools/evidence-add.ts +0 -0
- package/src/tools/ledger-query.ts +0 -0
- package/src/tools/research-report.ts +0 -0
- package/src/tools/research-trail.ts +212 -0
- package/src/verify-sealed.ts +0 -0
- package/src/verify.ts +0 -0
- package/src/version.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.4.0] - 2026-11-10
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- `research_trail`: read-only claim → evidence → verdict trail. Joins the
|
|
8
|
+
registered claims with their evidence and stored verdicts, marks claims with
|
|
9
|
+
no resolvable evidence as unbound, lists dangling evidence ids, and returns
|
|
10
|
+
Markdown plus structured rows. No new storage, no verdict changes.
|
|
11
|
+
|
|
3
12
|
## [0.0.1] - 2026-11-05
|
|
4
13
|
|
|
5
14
|
### Changed
|
package/LICENSE
CHANGED
|
File without changes
|
package/README-es.md
CHANGED
|
File without changes
|
package/README-hi.md
CHANGED
|
File without changes
|
package/README-pt.md
CHANGED
|
File without changes
|
package/README-zh.md
CHANGED
|
File without changes
|
package/README.md
CHANGED
|
@@ -164,6 +164,7 @@ edge-case (no throw): isError=false; kind=sealed; verdicts[0]={"claimId":"c1","s
|
|
|
164
164
|
|
|
165
165
|
- `research_report`
|
|
166
166
|
- `ledger_query`
|
|
167
|
+
- `research_trail`
|
|
167
168
|
|
|
168
169
|
## Configuration
|
|
169
170
|
|
|
@@ -184,6 +185,7 @@ All tunables are Schemastery `Config` fields; invalid values fail the profile lo
|
|
|
184
185
|
|
|
185
186
|
- **`evidence_add({ origin, content?, title? })`** — register one evidence snapshot. With `content` the text is stored verbatim; without it a URL origin is fetched through `ctx.web` and a workspace-relative path is read from disk (reads never escape the workspace). Returns the evidence id and SHA-256 hash.
|
|
186
187
|
- **`research_report({ topic, title?, sections, claims, evidenceRefs, gather?, depth?, background? })`** — assemble and seal a report: validate (unregistered claim references are rejected loudly), verify every claim, render `report.md` with visible markers, write `manifest.json`, and return the seal hash. `gather: true` runs ONE search round over `ctx.web` and returns captured candidate evidence plus an explicit gap list — it never auto-assembles. `background: true` returns `{ kind: 'background', jobId }` over `ctx.jobs`.
|
|
188
|
+
- **`research_trail({ limit?, format? })`** — read-only claim → evidence → verdict trail: joins registered claims with their evidence and stored verdicts, marks claims with no resolvable evidence as **unbound**, lists dangling evidence ids, and returns Markdown for a reviewer (plus the structured rows). It adds no storage and never changes a verdict.
|
|
187
189
|
- **`ledger_query({ claimId? | evidenceId? })`** — read-only binding/verdict queries; evidence is re-hashed on read so a tampered or missing snapshot is reported explicitly. With no id, returns a ledger summary.
|
|
188
190
|
- **`ctx.researchReport.assemble(request)`** — the frozen service surface for sibling plugins (see `src/service.ts`; gated byte-for-byte by `scripts/verify-frozen-contract.mjs`).
|
|
189
191
|
|
package/THIRD_PARTY_NOTICES.md
CHANGED
|
File without changes
|
package/cordis.patch.yml
CHANGED
|
File without changes
|
package/lib/cli.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as sha256Of, a as renderSarif, o as renderVerificationJson, r as buildVerificationReport, s as verifySealedReport } from "./verify-sealed-
|
|
1
|
+
import { _ as sha256Of, a as renderSarif, o as renderVerificationJson, r as buildVerificationReport, s as verifySealedReport } from "./verify-sealed-BHAE-3Zw.js";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { readFile } from "node:fs/promises";
|
|
4
4
|
//#region src/cli.ts
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as sha256Of, a as renderSarif, c as VERSION, d as extractCitations, f as mapBridgeResults, g as LedgerError, h as EvidenceLedger, i as renderMachineCheckMarkdown, l as combineOutcomes, m as verifyClaimText, n as VERIFIER_TOOL, o as renderVerificationJson, p as normalizeNumber, r as buildVerificationReport, s as verifySealedReport, t as SARIF_SCHEMA, u as contextLabelOf } from "./verify-sealed-
|
|
1
|
+
import { _ as sha256Of, a as renderSarif, c as VERSION, d as extractCitations, f as mapBridgeResults, g as LedgerError, h as EvidenceLedger, i as renderMachineCheckMarkdown, l as combineOutcomes, m as verifyClaimText, n as VERIFIER_TOOL, o as renderVerificationJson, p as normalizeNumber, r as buildVerificationReport, s as verifySealedReport, t as SARIF_SCHEMA, u as contextLabelOf } from "./verify-sealed-BHAE-3Zw.js";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import z from "@deepseek-ai/schemastery";
|
|
4
4
|
import { appendFile, mkdir, readFile, writeFile } from "node:fs/promises";
|
|
@@ -1757,6 +1757,200 @@ function makeLedgerQueryTool(service) {
|
|
|
1757
1757
|
});
|
|
1758
1758
|
}
|
|
1759
1759
|
//#endregion
|
|
1760
|
+
//#region src/tools/research-trail.ts
|
|
1761
|
+
/**
|
|
1762
|
+
* The `research_trail` model tool (Consumer): a read-only claim → evidence →
|
|
1763
|
+
* verdict trail over the local ledger, rendered for a reviewer.
|
|
1764
|
+
*
|
|
1765
|
+
* It adds no storage and changes no ledger entry: it joins what
|
|
1766
|
+
* `evidence_add`/`research_report` already wrote, marks unbound claims and
|
|
1767
|
+
* dangling evidence explicitly, and leaves verdicts exactly as stored.
|
|
1768
|
+
*
|
|
1769
|
+
* @module dsh-research-report/tools/research-trail
|
|
1770
|
+
*/
|
|
1771
|
+
/** Build the trail from the service views (pure; exported for tests). */
|
|
1772
|
+
function buildTrail(input) {
|
|
1773
|
+
const limit = Math.max(1, Math.min(input.limit ?? 100, 500));
|
|
1774
|
+
const evidenceRows = input.evidence.map((item) => ({
|
|
1775
|
+
id: item.id,
|
|
1776
|
+
title: item.title,
|
|
1777
|
+
origin: item.origin,
|
|
1778
|
+
integrity: item.integrity,
|
|
1779
|
+
bytes: item.bytes
|
|
1780
|
+
}));
|
|
1781
|
+
const byId = new Map(evidenceRows.map((row) => [row.id, row]));
|
|
1782
|
+
const missingEvidence = [];
|
|
1783
|
+
const unboundClaims = [];
|
|
1784
|
+
const claims = input.claims.slice(0, limit).map((claim) => {
|
|
1785
|
+
const bound = [];
|
|
1786
|
+
for (const evidenceId of claim.evidenceIds) {
|
|
1787
|
+
const row = byId.get(evidenceId);
|
|
1788
|
+
if (row === void 0) {
|
|
1789
|
+
missingEvidence.push({
|
|
1790
|
+
claimId: claim.id,
|
|
1791
|
+
evidenceId
|
|
1792
|
+
});
|
|
1793
|
+
continue;
|
|
1794
|
+
}
|
|
1795
|
+
bound.push(row);
|
|
1796
|
+
}
|
|
1797
|
+
const unbound = bound.length === 0;
|
|
1798
|
+
if (unbound) unboundClaims.push(claim.id);
|
|
1799
|
+
return {
|
|
1800
|
+
id: claim.id,
|
|
1801
|
+
text: claim.text,
|
|
1802
|
+
verdict: claim.verdict?.status ?? "unverified",
|
|
1803
|
+
...claim.verdict?.note === void 0 ? {} : { note: claim.verdict.note },
|
|
1804
|
+
evidence: bound,
|
|
1805
|
+
unbound
|
|
1806
|
+
};
|
|
1807
|
+
});
|
|
1808
|
+
const lines = [
|
|
1809
|
+
"# Research trail",
|
|
1810
|
+
"",
|
|
1811
|
+
`Generated: ${input.now.toISOString()}`,
|
|
1812
|
+
"",
|
|
1813
|
+
`Evidence: ${input.summary.evidenceCount} · Claims: ${input.summary.claimCount} · Verdicts: ${input.summary.verdictCount} · Tampered: ${input.summary.tamperedCount}`,
|
|
1814
|
+
"",
|
|
1815
|
+
"## Claims",
|
|
1816
|
+
""
|
|
1817
|
+
];
|
|
1818
|
+
if (claims.length === 0) lines.push("_No claims registered yet._", "");
|
|
1819
|
+
claims.forEach((claim, index) => {
|
|
1820
|
+
lines.push(`${index + 1}. **[${claim.verdict}]** ${claim.text}`);
|
|
1821
|
+
if (claim.note !== void 0) lines.push(` note: ${claim.note}`);
|
|
1822
|
+
if (claim.evidence.length === 0) {
|
|
1823
|
+
lines.push(" evidence: **unbound** — no resolvable evidence id", "");
|
|
1824
|
+
return;
|
|
1825
|
+
}
|
|
1826
|
+
for (const item of claim.evidence) lines.push(` evidence: \`${item.id}\` (${item.integrity}, ${item.bytes} B) — ${item.title}`);
|
|
1827
|
+
lines.push("");
|
|
1828
|
+
});
|
|
1829
|
+
if (missingEvidence.length > 0) {
|
|
1830
|
+
lines.push("## Dangling evidence references", "");
|
|
1831
|
+
for (const item of missingEvidence) lines.push(`- claim \`${item.claimId}\` → \`${item.evidenceId}\` (not in the ledger)`);
|
|
1832
|
+
lines.push("");
|
|
1833
|
+
}
|
|
1834
|
+
if (unboundClaims.length > 0) lines.push("## Unbound claims", "", ...unboundClaims.map((id) => `- \`${id}\``), "");
|
|
1835
|
+
return {
|
|
1836
|
+
ok: true,
|
|
1837
|
+
generatedAt: input.now.toISOString(),
|
|
1838
|
+
summary: input.summary,
|
|
1839
|
+
claims,
|
|
1840
|
+
evidence: evidenceRows,
|
|
1841
|
+
missingEvidence,
|
|
1842
|
+
unboundClaims,
|
|
1843
|
+
markdown: lines.join("\n").trimEnd() + "\n"
|
|
1844
|
+
};
|
|
1845
|
+
}
|
|
1846
|
+
const ERROR_SCHEMA = {
|
|
1847
|
+
type: "object",
|
|
1848
|
+
additionalProperties: false,
|
|
1849
|
+
properties: {
|
|
1850
|
+
code: {
|
|
1851
|
+
type: "string",
|
|
1852
|
+
required: true
|
|
1853
|
+
},
|
|
1854
|
+
message: {
|
|
1855
|
+
type: "string",
|
|
1856
|
+
required: true
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1859
|
+
};
|
|
1860
|
+
/**
|
|
1861
|
+
* Build the `research_trail` tool.
|
|
1862
|
+
* @param service - the local research-report service.
|
|
1863
|
+
* @returns the tool definition.
|
|
1864
|
+
*/
|
|
1865
|
+
function makeResearchTrailTool(service) {
|
|
1866
|
+
return defineTool({
|
|
1867
|
+
name: "research_trail",
|
|
1868
|
+
description: [
|
|
1869
|
+
"Render the claim → evidence → verdict trail of the local research ledger (dsh-research-report).",
|
|
1870
|
+
"",
|
|
1871
|
+
"Read-only: joins registered claims with their evidence and stored verdicts, marks claims with no resolvable evidence as unbound, and lists dangling evidence ids. Returns Markdown for a reviewer plus the structured rows. It adds no storage and never changes a verdict."
|
|
1872
|
+
].join("\n"),
|
|
1873
|
+
parameters: {
|
|
1874
|
+
limit: {
|
|
1875
|
+
type: "integer",
|
|
1876
|
+
description: "Maximum claims to include (1–500, default 100)."
|
|
1877
|
+
},
|
|
1878
|
+
format: {
|
|
1879
|
+
type: "string",
|
|
1880
|
+
description: "markdown (default) or json (renderer only; the value always carries both)."
|
|
1881
|
+
}
|
|
1882
|
+
},
|
|
1883
|
+
output: {
|
|
1884
|
+
schema: {
|
|
1885
|
+
type: "object",
|
|
1886
|
+
additionalProperties: false,
|
|
1887
|
+
properties: {
|
|
1888
|
+
ok: {
|
|
1889
|
+
type: "boolean",
|
|
1890
|
+
required: true
|
|
1891
|
+
},
|
|
1892
|
+
generatedAt: { type: "string" },
|
|
1893
|
+
summary: { type: "json" },
|
|
1894
|
+
claims: { type: "json" },
|
|
1895
|
+
evidence: { type: "json" },
|
|
1896
|
+
missingEvidence: { type: "json" },
|
|
1897
|
+
unboundClaims: {
|
|
1898
|
+
type: "array",
|
|
1899
|
+
items: { type: "string" }
|
|
1900
|
+
},
|
|
1901
|
+
markdown: { type: "string" },
|
|
1902
|
+
error: ERROR_SCHEMA
|
|
1903
|
+
}
|
|
1904
|
+
},
|
|
1905
|
+
render: (args, value) => {
|
|
1906
|
+
const format = args.format ?? "markdown";
|
|
1907
|
+
const result = value;
|
|
1908
|
+
if (!result.ok) return [{
|
|
1909
|
+
type: "text",
|
|
1910
|
+
text: `research_trail failed (${result.error.code}): ${result.error.message}`
|
|
1911
|
+
}];
|
|
1912
|
+
if (format === "json") {
|
|
1913
|
+
const { markdown: _markdown, ...rest } = result;
|
|
1914
|
+
return [{
|
|
1915
|
+
type: "text",
|
|
1916
|
+
text: JSON.stringify(rest, null, 2)
|
|
1917
|
+
}];
|
|
1918
|
+
}
|
|
1919
|
+
return [{
|
|
1920
|
+
type: "text",
|
|
1921
|
+
text: result.markdown
|
|
1922
|
+
}];
|
|
1923
|
+
}
|
|
1924
|
+
},
|
|
1925
|
+
async execute(args, exec) {
|
|
1926
|
+
exec.signal.throwIfAborted();
|
|
1927
|
+
try {
|
|
1928
|
+
const [summary, evidence, claims] = await Promise.all([
|
|
1929
|
+
service.summarize(),
|
|
1930
|
+
service.listEvidence(),
|
|
1931
|
+
service.listClaims()
|
|
1932
|
+
]);
|
|
1933
|
+
const trail = buildTrail({
|
|
1934
|
+
summary,
|
|
1935
|
+
evidence,
|
|
1936
|
+
claims,
|
|
1937
|
+
now: /* @__PURE__ */ new Date(),
|
|
1938
|
+
...args.limit === void 0 ? {} : { limit: args.limit }
|
|
1939
|
+
});
|
|
1940
|
+
return JSON.parse(JSON.stringify(trail));
|
|
1941
|
+
} catch (error) {
|
|
1942
|
+
return {
|
|
1943
|
+
ok: false,
|
|
1944
|
+
error: {
|
|
1945
|
+
code: "TRAIL_FAILED",
|
|
1946
|
+
message: error instanceof Error ? error.message : String(error)
|
|
1947
|
+
}
|
|
1948
|
+
};
|
|
1949
|
+
}
|
|
1950
|
+
}
|
|
1951
|
+
});
|
|
1952
|
+
}
|
|
1953
|
+
//#endregion
|
|
1760
1954
|
//#region src/tools/research-report.ts
|
|
1761
1955
|
/**
|
|
1762
1956
|
* The `research_report` model tool (Consumer): assemble and seal one
|
|
@@ -2242,6 +2436,7 @@ function apply(ctx, config) {
|
|
|
2242
2436
|
service
|
|
2243
2437
|
})), "research-report: research_report tool");
|
|
2244
2438
|
ctx.effect(() => ctx.tools.register(makeLedgerQueryTool(service)), "research-report: ledger_query tool");
|
|
2439
|
+
ctx.effect(() => ctx.tools.register(makeResearchTrailTool(service)), "research-report: research_trail tool");
|
|
2245
2440
|
ctx.systemPrompt.section({
|
|
2246
2441
|
name: "dsh-research-report:workflow",
|
|
2247
2442
|
order: 10,
|
package/lib/types/assemble.d.ts
CHANGED
|
File without changes
|
|
File without changes
|
package/lib/types/assemble.js
CHANGED
|
File without changes
|
|
File without changes
|
package/lib/types/cli.d.ts
CHANGED
|
File without changes
|
package/lib/types/cli.d.ts.map
CHANGED
|
File without changes
|
package/lib/types/cli.js
CHANGED
|
File without changes
|
package/lib/types/cli.js.map
CHANGED
|
File without changes
|
package/lib/types/config.d.ts
CHANGED
|
File without changes
|
|
File without changes
|
package/lib/types/config.js
CHANGED
|
File without changes
|
package/lib/types/config.js.map
CHANGED
|
File without changes
|
package/lib/types/doi.d.ts
CHANGED
|
File without changes
|
package/lib/types/doi.d.ts.map
CHANGED
|
File without changes
|
package/lib/types/doi.js
CHANGED
|
File without changes
|
package/lib/types/doi.js.map
CHANGED
|
File without changes
|
package/lib/types/gather.d.ts
CHANGED
|
File without changes
|
|
File without changes
|
package/lib/types/gather.js
CHANGED
|
File without changes
|
package/lib/types/gather.js.map
CHANGED
|
File without changes
|
package/lib/types/index.d.ts
CHANGED
|
File without changes
|
package/lib/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAGlD,OAAO,EAAE,MAAM,EAAiB,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAGlD,OAAO,EAAE,MAAM,EAAiB,MAAM,aAAa,CAAA;AAOnD,eAAO,MAAM,IAAI,oBAAoB,CAAA;AAErC;;;;;GAKG;AACH,eAAO,MAAM,MAAM,UAA4B,CAAA;AAE/C,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AACnD,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAA;AACpD,YAAY,EACV,gBAAgB,EAChB,eAAe,EACf,oBAAoB,EACpB,qBAAqB,EACrB,oBAAoB,EACpB,iBAAiB,EACjB,YAAY,EACZ,SAAS,EACT,aAAa,EACb,iBAAiB,EACjB,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B,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAC9K,YAAY,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AACvI,OAAO,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAQvG;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAsBxD"}
|
package/lib/types/index.js
CHANGED
|
@@ -20,6 +20,7 @@ import { resolveConfig } from "./config.js";
|
|
|
20
20
|
import { LocalResearchReportService } from "./provider-local.js";
|
|
21
21
|
import { makeEvidenceAddTool } from "./tools/evidence-add.js";
|
|
22
22
|
import { makeLedgerQueryTool } from "./tools/ledger-query.js";
|
|
23
|
+
import { makeResearchTrailTool } from "./tools/research-trail.js";
|
|
23
24
|
import { makeResearchReportTool } from "./tools/research-report.js";
|
|
24
25
|
export const name = 'research-report';
|
|
25
26
|
/**
|
|
@@ -64,6 +65,7 @@ export function apply(ctx, config) {
|
|
|
64
65
|
ctx.effect(() => ctx.tools.register(makeEvidenceAddTool(service)), 'research-report: evidence_add tool');
|
|
65
66
|
ctx.effect(() => ctx.tools.register(makeResearchReportTool({ ctx, service })), 'research-report: research_report tool');
|
|
66
67
|
ctx.effect(() => ctx.tools.register(makeLedgerQueryTool(service)), 'research-report: ledger_query tool');
|
|
68
|
+
ctx.effect(() => ctx.tools.register(makeResearchTrailTool(service)), 'research-report: research_trail tool');
|
|
67
69
|
ctx.systemPrompt.section({
|
|
68
70
|
name: 'dsh-research-report:workflow',
|
|
69
71
|
order: 10,
|
package/lib/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAKH,OAAO,EAAU,aAAa,EA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,CAAC,KAAK,CAAC,QAAQ,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC,EAAE,oCAAoC,CAAC,CAAA;IACxG,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC,EAAE,sCAAsC,CAAC,CAAA;IAE5G,GAAG,CAAC,YAAY,CAAC,OAAO,CAAC;QACvB,IAAI,EAAE,8BAA8B;QACpC,KAAK,EAAE,EAAE;QACT,IAAI,EAAE,cAAc;KACrB,CAAC,CAAA;AACJ,CAAC"}
|
package/lib/types/ledger.d.ts
CHANGED
|
File without changes
|
|
File without changes
|
package/lib/types/ledger.js
CHANGED
|
File without changes
|
package/lib/types/ledger.js.map
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/lib/types/service.d.ts
CHANGED
|
File without changes
|
|
File without changes
|
package/lib/types/service.js
CHANGED
|
File without changes
|
package/lib/types/service.js.map
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `research_trail` model tool (Consumer): a read-only claim → evidence →
|
|
3
|
+
* verdict trail over the local ledger, rendered for a reviewer.
|
|
4
|
+
*
|
|
5
|
+
* It adds no storage and changes no ledger entry: it joins what
|
|
6
|
+
* `evidence_add`/`research_report` already wrote, marks unbound claims and
|
|
7
|
+
* dangling evidence explicitly, and leaves verdicts exactly as stored.
|
|
8
|
+
*
|
|
9
|
+
* @module dsh-research-report/tools/research-trail
|
|
10
|
+
*/
|
|
11
|
+
import type { LocalResearchReportService } from '../provider-local.js';
|
|
12
|
+
import type { ClaimView, EvidenceView, LedgerSummary } from '../service.js';
|
|
13
|
+
/** One evidence row in the trail. */
|
|
14
|
+
export interface TrailEvidence {
|
|
15
|
+
readonly id: string;
|
|
16
|
+
readonly title: string;
|
|
17
|
+
readonly origin: string;
|
|
18
|
+
readonly integrity: string;
|
|
19
|
+
readonly bytes: number;
|
|
20
|
+
}
|
|
21
|
+
/** One claim row in the trail. */
|
|
22
|
+
export interface TrailClaim {
|
|
23
|
+
readonly id: string;
|
|
24
|
+
readonly text: string;
|
|
25
|
+
readonly verdict: string;
|
|
26
|
+
readonly note?: string;
|
|
27
|
+
readonly evidence: readonly TrailEvidence[];
|
|
28
|
+
/** True when the claim has no evidence refs (or none of them resolve). */
|
|
29
|
+
readonly unbound: boolean;
|
|
30
|
+
}
|
|
31
|
+
/** The `research_trail` canonical value. */
|
|
32
|
+
export interface ResearchTrailValue {
|
|
33
|
+
readonly ok: true;
|
|
34
|
+
readonly generatedAt: string;
|
|
35
|
+
readonly summary: LedgerSummary;
|
|
36
|
+
readonly claims: readonly TrailClaim[];
|
|
37
|
+
readonly evidence: readonly TrailEvidence[];
|
|
38
|
+
/** Claim → evidence ids that are not in the ledger. */
|
|
39
|
+
readonly missingEvidence: readonly {
|
|
40
|
+
readonly claimId: string;
|
|
41
|
+
readonly evidenceId: string;
|
|
42
|
+
}[];
|
|
43
|
+
readonly unboundClaims: readonly string[];
|
|
44
|
+
readonly markdown: string;
|
|
45
|
+
}
|
|
46
|
+
/** Build the trail from the service views (pure; exported for tests). */
|
|
47
|
+
export declare function buildTrail(input: {
|
|
48
|
+
summary: LedgerSummary;
|
|
49
|
+
evidence: readonly EvidenceView[];
|
|
50
|
+
claims: readonly ClaimView[];
|
|
51
|
+
now: Date;
|
|
52
|
+
limit?: number;
|
|
53
|
+
}): ResearchTrailValue;
|
|
54
|
+
/**
|
|
55
|
+
* Build the `research_trail` tool.
|
|
56
|
+
* @param service - the local research-report service.
|
|
57
|
+
* @returns the tool definition.
|
|
58
|
+
*/
|
|
59
|
+
export declare function makeResearchTrailTool(service: LocalResearchReportService): import("@deepseek-ai/dsh-tools").ToolDefinition;
|
|
60
|
+
//# sourceMappingURL=research-trail.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"research-trail.d.ts","sourceRoot":"","sources":["../../../src/tools/research-trail.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAA;AACtE,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAE3E,qCAAqC;AACrC,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CACvB;AAED,kCAAkC;AAClC,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,QAAQ,EAAE,SAAS,aAAa,EAAE,CAAA;IAC3C,0EAA0E;IAC1E,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;CAC1B;AAED,4CAA4C;AAC5C,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAA;IACjB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAA;IAC/B,QAAQ,CAAC,MAAM,EAAE,SAAS,UAAU,EAAE,CAAA;IACtC,QAAQ,CAAC,QAAQ,EAAE,SAAS,aAAa,EAAE,CAAA;IAC3C,uDAAuD;IACvD,QAAQ,CAAC,eAAe,EAAE,SAAS;QAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;IAC9F,QAAQ,CAAC,aAAa,EAAE,SAAS,MAAM,EAAE,CAAA;IACzC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAC1B;AAED,yEAAyE;AACzE,wBAAgB,UAAU,CAAC,KAAK,EAAE;IAChC,OAAO,EAAE,aAAa,CAAA;IACtB,QAAQ,EAAE,SAAS,YAAY,EAAE,CAAA;IACjC,MAAM,EAAE,SAAS,SAAS,EAAE,CAAA;IAC5B,GAAG,EAAE,IAAI,CAAA;IACT,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,GAAG,kBAAkB,CA4ErB;AAWD;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,0BAA0B,mDAgExE"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `research_trail` model tool (Consumer): a read-only claim → evidence →
|
|
3
|
+
* verdict trail over the local ledger, rendered for a reviewer.
|
|
4
|
+
*
|
|
5
|
+
* It adds no storage and changes no ledger entry: it joins what
|
|
6
|
+
* `evidence_add`/`research_report` already wrote, marks unbound claims and
|
|
7
|
+
* dangling evidence explicitly, and leaves verdicts exactly as stored.
|
|
8
|
+
*
|
|
9
|
+
* @module dsh-research-report/tools/research-trail
|
|
10
|
+
*/
|
|
11
|
+
import { defineTool } from '@deepseek-ai/dsh-tools';
|
|
12
|
+
/** Build the trail from the service views (pure; exported for tests). */
|
|
13
|
+
export function buildTrail(input) {
|
|
14
|
+
const limit = Math.max(1, Math.min(input.limit ?? 100, 500));
|
|
15
|
+
const evidenceRows = input.evidence.map(item => ({
|
|
16
|
+
id: item.id,
|
|
17
|
+
title: item.title,
|
|
18
|
+
origin: item.origin,
|
|
19
|
+
integrity: item.integrity,
|
|
20
|
+
bytes: item.bytes,
|
|
21
|
+
}));
|
|
22
|
+
const byId = new Map(evidenceRows.map(row => [row.id, row]));
|
|
23
|
+
const missingEvidence = [];
|
|
24
|
+
const unboundClaims = [];
|
|
25
|
+
const claims = input.claims.slice(0, limit).map(claim => {
|
|
26
|
+
const bound = [];
|
|
27
|
+
for (const evidenceId of claim.evidenceIds) {
|
|
28
|
+
const row = byId.get(evidenceId);
|
|
29
|
+
if (row === undefined) {
|
|
30
|
+
missingEvidence.push({ claimId: claim.id, evidenceId });
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
bound.push(row);
|
|
34
|
+
}
|
|
35
|
+
const unbound = bound.length === 0;
|
|
36
|
+
if (unbound)
|
|
37
|
+
unboundClaims.push(claim.id);
|
|
38
|
+
return {
|
|
39
|
+
id: claim.id,
|
|
40
|
+
text: claim.text,
|
|
41
|
+
verdict: claim.verdict?.status ?? 'unverified',
|
|
42
|
+
...(claim.verdict?.note === undefined ? {} : { note: claim.verdict.note }),
|
|
43
|
+
evidence: bound,
|
|
44
|
+
unbound,
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
const lines = [
|
|
48
|
+
'# Research trail',
|
|
49
|
+
'',
|
|
50
|
+
`Generated: ${input.now.toISOString()}`,
|
|
51
|
+
'',
|
|
52
|
+
`Evidence: ${input.summary.evidenceCount} · Claims: ${input.summary.claimCount} · Verdicts: ${input.summary.verdictCount} · Tampered: ${input.summary.tamperedCount}`,
|
|
53
|
+
'',
|
|
54
|
+
'## Claims',
|
|
55
|
+
'',
|
|
56
|
+
];
|
|
57
|
+
if (claims.length === 0)
|
|
58
|
+
lines.push('_No claims registered yet._', '');
|
|
59
|
+
claims.forEach((claim, index) => {
|
|
60
|
+
lines.push(`${index + 1}. **[${claim.verdict}]** ${claim.text}`);
|
|
61
|
+
if (claim.note !== undefined)
|
|
62
|
+
lines.push(` note: ${claim.note}`);
|
|
63
|
+
if (claim.evidence.length === 0) {
|
|
64
|
+
lines.push(' evidence: **unbound** — no resolvable evidence id', '');
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
for (const item of claim.evidence) {
|
|
68
|
+
lines.push(` evidence: \`${item.id}\` (${item.integrity}, ${item.bytes} B) — ${item.title}`);
|
|
69
|
+
}
|
|
70
|
+
lines.push('');
|
|
71
|
+
});
|
|
72
|
+
if (missingEvidence.length > 0) {
|
|
73
|
+
lines.push('## Dangling evidence references', '');
|
|
74
|
+
for (const item of missingEvidence)
|
|
75
|
+
lines.push(`- claim \`${item.claimId}\` → \`${item.evidenceId}\` (not in the ledger)`);
|
|
76
|
+
lines.push('');
|
|
77
|
+
}
|
|
78
|
+
if (unboundClaims.length > 0) {
|
|
79
|
+
lines.push('## Unbound claims', '', ...unboundClaims.map(id => `- \`${id}\``), '');
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
ok: true,
|
|
83
|
+
generatedAt: input.now.toISOString(),
|
|
84
|
+
summary: input.summary,
|
|
85
|
+
claims,
|
|
86
|
+
evidence: evidenceRows,
|
|
87
|
+
missingEvidence,
|
|
88
|
+
unboundClaims,
|
|
89
|
+
markdown: lines.join('\n').trimEnd() + '\n',
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
const ERROR_SCHEMA = {
|
|
93
|
+
type: 'object',
|
|
94
|
+
additionalProperties: false,
|
|
95
|
+
properties: {
|
|
96
|
+
code: { type: 'string', required: true },
|
|
97
|
+
message: { type: 'string', required: true },
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Build the `research_trail` tool.
|
|
102
|
+
* @param service - the local research-report service.
|
|
103
|
+
* @returns the tool definition.
|
|
104
|
+
*/
|
|
105
|
+
export function makeResearchTrailTool(service) {
|
|
106
|
+
return defineTool({
|
|
107
|
+
name: 'research_trail',
|
|
108
|
+
description: [
|
|
109
|
+
'Render the claim → evidence → verdict trail of the local research ledger (dsh-research-report).',
|
|
110
|
+
'',
|
|
111
|
+
'Read-only: joins registered claims with their evidence and stored verdicts, marks claims with no resolvable evidence as unbound, and lists dangling evidence ids. Returns Markdown for a reviewer plus the structured rows. It adds no storage and never changes a verdict.',
|
|
112
|
+
].join('\n'),
|
|
113
|
+
parameters: {
|
|
114
|
+
limit: { type: 'integer', description: 'Maximum claims to include (1–500, default 100).' },
|
|
115
|
+
format: { type: 'string', description: 'markdown (default) or json (renderer only; the value always carries both).' },
|
|
116
|
+
},
|
|
117
|
+
output: {
|
|
118
|
+
schema: {
|
|
119
|
+
type: 'object',
|
|
120
|
+
additionalProperties: false,
|
|
121
|
+
properties: {
|
|
122
|
+
ok: { type: 'boolean', required: true },
|
|
123
|
+
generatedAt: { type: 'string' },
|
|
124
|
+
summary: { type: 'json' },
|
|
125
|
+
claims: { type: 'json' },
|
|
126
|
+
evidence: { type: 'json' },
|
|
127
|
+
missingEvidence: { type: 'json' },
|
|
128
|
+
unboundClaims: { type: 'array', items: { type: 'string' } },
|
|
129
|
+
markdown: { type: 'string' },
|
|
130
|
+
error: ERROR_SCHEMA,
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
render: (args, value) => {
|
|
134
|
+
const format = args.format ?? 'markdown';
|
|
135
|
+
const result = value;
|
|
136
|
+
if (!result.ok)
|
|
137
|
+
return [{ type: 'text', text: `research_trail failed (${result.error.code}): ${result.error.message}` }];
|
|
138
|
+
if (format === 'json') {
|
|
139
|
+
const { markdown: _markdown, ...rest } = result;
|
|
140
|
+
void _markdown;
|
|
141
|
+
return [{ type: 'text', text: JSON.stringify(rest, null, 2) }];
|
|
142
|
+
}
|
|
143
|
+
return [{ type: 'text', text: result.markdown }];
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
async execute(args, exec) {
|
|
147
|
+
exec.signal.throwIfAborted();
|
|
148
|
+
try {
|
|
149
|
+
const [summary, evidence, claims] = await Promise.all([
|
|
150
|
+
service.summarize(),
|
|
151
|
+
service.listEvidence(),
|
|
152
|
+
service.listClaims(),
|
|
153
|
+
]);
|
|
154
|
+
const trail = buildTrail({
|
|
155
|
+
summary,
|
|
156
|
+
evidence,
|
|
157
|
+
claims,
|
|
158
|
+
now: new Date(),
|
|
159
|
+
...(args.limit === undefined ? {} : { limit: args.limit }),
|
|
160
|
+
});
|
|
161
|
+
return JSON.parse(JSON.stringify(trail));
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
return {
|
|
165
|
+
ok: false,
|
|
166
|
+
error: { code: 'TRAIL_FAILED', message: error instanceof Error ? error.message : String(error) },
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=research-trail.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"research-trail.js","sourceRoot":"","sources":["../../../src/tools/research-trail.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAqCnD,yEAAyE;AACzE,MAAM,UAAU,UAAU,CAAC,KAM1B;IACC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,IAAI,GAAG,EAAE,GAAG,CAAC,CAAC,CAAA;IAC5D,MAAM,YAAY,GAAoB,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAChE,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,SAAS,EAAE,IAAI,CAAC,SAAS;QACzB,KAAK,EAAE,IAAI,CAAC,KAAK;KAClB,CAAC,CAAC,CAAA;IACH,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC,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/verify.d.ts
CHANGED
|
File without changes
|
|
File without changes
|
package/lib/types/verify.js
CHANGED
|
File without changes
|
package/lib/types/verify.js.map
CHANGED
|
File without changes
|
package/lib/types/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,qCAAqC;AACrC,eAAO,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,qCAAqC;AACrC,eAAO,MAAM,OAAO,UAAU,CAAA"}
|
package/lib/types/version.js
CHANGED
package/lib/types/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,qCAAqC;AACrC,MAAM,CAAC,MAAM,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,qCAAqC;AACrC,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAA"}
|
package/package.json
CHANGED
package/src/assemble.ts
CHANGED
|
File without changes
|
package/src/cli.ts
CHANGED
|
File without changes
|
package/src/config.ts
CHANGED
|
File without changes
|
package/src/doi.ts
CHANGED
|
File without changes
|
package/src/gather.ts
CHANGED
|
File without changes
|
package/src/index.ts
CHANGED
|
@@ -24,6 +24,7 @@ import { Config, resolveConfig } from './config.ts'
|
|
|
24
24
|
import { LocalResearchReportService } from './provider-local.ts'
|
|
25
25
|
import { makeEvidenceAddTool } from './tools/evidence-add.ts'
|
|
26
26
|
import { makeLedgerQueryTool } from './tools/ledger-query.ts'
|
|
27
|
+
import { makeResearchTrailTool } from './tools/research-trail.ts'
|
|
27
28
|
import { makeResearchReportTool } from './tools/research-report.ts'
|
|
28
29
|
|
|
29
30
|
export const name = 'research-report'
|
|
@@ -140,6 +141,7 @@ export function apply(ctx: Context, config: Config): void {
|
|
|
140
141
|
ctx.effect(() => ctx.tools.register(makeEvidenceAddTool(service)), 'research-report: evidence_add tool')
|
|
141
142
|
ctx.effect(() => ctx.tools.register(makeResearchReportTool({ ctx, service })), 'research-report: research_report tool')
|
|
142
143
|
ctx.effect(() => ctx.tools.register(makeLedgerQueryTool(service)), 'research-report: ledger_query tool')
|
|
144
|
+
ctx.effect(() => ctx.tools.register(makeResearchTrailTool(service)), 'research-report: research_trail tool')
|
|
143
145
|
|
|
144
146
|
ctx.systemPrompt.section({
|
|
145
147
|
name: 'dsh-research-report:workflow',
|
package/src/ledger.ts
CHANGED
|
File without changes
|
package/src/provider-local.ts
CHANGED
|
File without changes
|
package/src/service.ts
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `research_trail` model tool (Consumer): a read-only claim → evidence →
|
|
3
|
+
* verdict trail over the local ledger, rendered for a reviewer.
|
|
4
|
+
*
|
|
5
|
+
* It adds no storage and changes no ledger entry: it joins what
|
|
6
|
+
* `evidence_add`/`research_report` already wrote, marks unbound claims and
|
|
7
|
+
* dangling evidence explicitly, and leaves verdicts exactly as stored.
|
|
8
|
+
*
|
|
9
|
+
* @module dsh-research-report/tools/research-trail
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { defineTool } from '@deepseek-ai/dsh-tools'
|
|
13
|
+
import type { LocalResearchReportService } from '../provider-local.ts'
|
|
14
|
+
import type { ClaimView, EvidenceView, LedgerSummary } from '../service.ts'
|
|
15
|
+
|
|
16
|
+
/** One evidence row in the trail. */
|
|
17
|
+
export interface TrailEvidence {
|
|
18
|
+
readonly id: string
|
|
19
|
+
readonly title: string
|
|
20
|
+
readonly origin: string
|
|
21
|
+
readonly integrity: string
|
|
22
|
+
readonly bytes: number
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** One claim row in the trail. */
|
|
26
|
+
export interface TrailClaim {
|
|
27
|
+
readonly id: string
|
|
28
|
+
readonly text: string
|
|
29
|
+
readonly verdict: string
|
|
30
|
+
readonly note?: string
|
|
31
|
+
readonly evidence: readonly TrailEvidence[]
|
|
32
|
+
/** True when the claim has no evidence refs (or none of them resolve). */
|
|
33
|
+
readonly unbound: boolean
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The `research_trail` canonical value. */
|
|
37
|
+
export interface ResearchTrailValue {
|
|
38
|
+
readonly ok: true
|
|
39
|
+
readonly generatedAt: string
|
|
40
|
+
readonly summary: LedgerSummary
|
|
41
|
+
readonly claims: readonly TrailClaim[]
|
|
42
|
+
readonly evidence: readonly TrailEvidence[]
|
|
43
|
+
/** Claim → evidence ids that are not in the ledger. */
|
|
44
|
+
readonly missingEvidence: readonly { readonly claimId: string; readonly evidenceId: string }[]
|
|
45
|
+
readonly unboundClaims: readonly string[]
|
|
46
|
+
readonly markdown: string
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Build the trail from the service views (pure; exported for tests). */
|
|
50
|
+
export function buildTrail(input: {
|
|
51
|
+
summary: LedgerSummary
|
|
52
|
+
evidence: readonly EvidenceView[]
|
|
53
|
+
claims: readonly ClaimView[]
|
|
54
|
+
now: Date
|
|
55
|
+
limit?: number
|
|
56
|
+
}): ResearchTrailValue {
|
|
57
|
+
const limit = Math.max(1, Math.min(input.limit ?? 100, 500))
|
|
58
|
+
const evidenceRows: TrailEvidence[] = input.evidence.map(item => ({
|
|
59
|
+
id: item.id,
|
|
60
|
+
title: item.title,
|
|
61
|
+
origin: item.origin,
|
|
62
|
+
integrity: item.integrity,
|
|
63
|
+
bytes: item.bytes,
|
|
64
|
+
}))
|
|
65
|
+
const byId = new Map(evidenceRows.map(row => [row.id, row]))
|
|
66
|
+
const missingEvidence: Array<{ claimId: string; evidenceId: string }> = []
|
|
67
|
+
const unboundClaims: string[] = []
|
|
68
|
+
const claims: TrailClaim[] = input.claims.slice(0, limit).map(claim => {
|
|
69
|
+
const bound: TrailEvidence[] = []
|
|
70
|
+
for (const evidenceId of claim.evidenceIds) {
|
|
71
|
+
const row = byId.get(evidenceId)
|
|
72
|
+
if (row === undefined) {
|
|
73
|
+
missingEvidence.push({ claimId: claim.id, evidenceId })
|
|
74
|
+
continue
|
|
75
|
+
}
|
|
76
|
+
bound.push(row)
|
|
77
|
+
}
|
|
78
|
+
const unbound = bound.length === 0
|
|
79
|
+
if (unbound) unboundClaims.push(claim.id)
|
|
80
|
+
return {
|
|
81
|
+
id: claim.id,
|
|
82
|
+
text: claim.text,
|
|
83
|
+
verdict: claim.verdict?.status ?? 'unverified',
|
|
84
|
+
...(claim.verdict?.note === undefined ? {} : { note: claim.verdict.note }),
|
|
85
|
+
evidence: bound,
|
|
86
|
+
unbound,
|
|
87
|
+
}
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
const lines: string[] = [
|
|
91
|
+
'# Research trail',
|
|
92
|
+
'',
|
|
93
|
+
`Generated: ${input.now.toISOString()}`,
|
|
94
|
+
'',
|
|
95
|
+
`Evidence: ${input.summary.evidenceCount} · Claims: ${input.summary.claimCount} · Verdicts: ${input.summary.verdictCount} · Tampered: ${input.summary.tamperedCount}`,
|
|
96
|
+
'',
|
|
97
|
+
'## Claims',
|
|
98
|
+
'',
|
|
99
|
+
]
|
|
100
|
+
if (claims.length === 0) lines.push('_No claims registered yet._', '')
|
|
101
|
+
claims.forEach((claim, index) => {
|
|
102
|
+
lines.push(`${index + 1}. **[${claim.verdict}]** ${claim.text}`)
|
|
103
|
+
if (claim.note !== undefined) lines.push(` note: ${claim.note}`)
|
|
104
|
+
if (claim.evidence.length === 0) {
|
|
105
|
+
lines.push(' evidence: **unbound** — no resolvable evidence id', '')
|
|
106
|
+
return
|
|
107
|
+
}
|
|
108
|
+
for (const item of claim.evidence) {
|
|
109
|
+
lines.push(` evidence: \`${item.id}\` (${item.integrity}, ${item.bytes} B) — ${item.title}`)
|
|
110
|
+
}
|
|
111
|
+
lines.push('')
|
|
112
|
+
})
|
|
113
|
+
if (missingEvidence.length > 0) {
|
|
114
|
+
lines.push('## Dangling evidence references', '')
|
|
115
|
+
for (const item of missingEvidence) lines.push(`- claim \`${item.claimId}\` → \`${item.evidenceId}\` (not in the ledger)`)
|
|
116
|
+
lines.push('')
|
|
117
|
+
}
|
|
118
|
+
if (unboundClaims.length > 0) {
|
|
119
|
+
lines.push('## Unbound claims', '', ...unboundClaims.map(id => `- \`${id}\``), '')
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return {
|
|
123
|
+
ok: true,
|
|
124
|
+
generatedAt: input.now.toISOString(),
|
|
125
|
+
summary: input.summary,
|
|
126
|
+
claims,
|
|
127
|
+
evidence: evidenceRows,
|
|
128
|
+
missingEvidence,
|
|
129
|
+
unboundClaims,
|
|
130
|
+
markdown: lines.join('\n').trimEnd() + '\n',
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const ERROR_SCHEMA = {
|
|
135
|
+
type: 'object',
|
|
136
|
+
additionalProperties: false,
|
|
137
|
+
properties: {
|
|
138
|
+
code: { type: 'string', required: true },
|
|
139
|
+
message: { type: 'string', required: true },
|
|
140
|
+
},
|
|
141
|
+
} as const
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Build the `research_trail` tool.
|
|
145
|
+
* @param service - the local research-report service.
|
|
146
|
+
* @returns the tool definition.
|
|
147
|
+
*/
|
|
148
|
+
export function makeResearchTrailTool(service: LocalResearchReportService) {
|
|
149
|
+
return defineTool({
|
|
150
|
+
name: 'research_trail',
|
|
151
|
+
description: [
|
|
152
|
+
'Render the claim → evidence → verdict trail of the local research ledger (dsh-research-report).',
|
|
153
|
+
'',
|
|
154
|
+
'Read-only: joins registered claims with their evidence and stored verdicts, marks claims with no resolvable evidence as unbound, and lists dangling evidence ids. Returns Markdown for a reviewer plus the structured rows. It adds no storage and never changes a verdict.',
|
|
155
|
+
].join('\n'),
|
|
156
|
+
parameters: {
|
|
157
|
+
limit: { type: 'integer', description: 'Maximum claims to include (1–500, default 100).' },
|
|
158
|
+
format: { type: 'string', description: 'markdown (default) or json (renderer only; the value always carries both).' },
|
|
159
|
+
},
|
|
160
|
+
output: {
|
|
161
|
+
schema: {
|
|
162
|
+
type: 'object',
|
|
163
|
+
additionalProperties: false,
|
|
164
|
+
properties: {
|
|
165
|
+
ok: { type: 'boolean', required: true },
|
|
166
|
+
generatedAt: { type: 'string' },
|
|
167
|
+
summary: { type: 'json' },
|
|
168
|
+
claims: { type: 'json' },
|
|
169
|
+
evidence: { type: 'json' },
|
|
170
|
+
missingEvidence: { type: 'json' },
|
|
171
|
+
unboundClaims: { type: 'array', items: { type: 'string' } },
|
|
172
|
+
markdown: { type: 'string' },
|
|
173
|
+
error: ERROR_SCHEMA,
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
render: (args, value) => {
|
|
177
|
+
const format = (args as { format?: string }).format ?? 'markdown'
|
|
178
|
+
const result = value as ResearchTrailValue | { ok: false; error: { code: string; message: string } }
|
|
179
|
+
if (!result.ok) return [{ type: 'text', text: `research_trail failed (${result.error.code}): ${result.error.message}` }]
|
|
180
|
+
if (format === 'json') {
|
|
181
|
+
const { markdown: _markdown, ...rest } = result
|
|
182
|
+
void _markdown
|
|
183
|
+
return [{ type: 'text', text: JSON.stringify(rest, null, 2) }]
|
|
184
|
+
}
|
|
185
|
+
return [{ type: 'text', text: result.markdown }]
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
async execute(args, exec) {
|
|
189
|
+
exec.signal.throwIfAborted()
|
|
190
|
+
try {
|
|
191
|
+
const [summary, evidence, claims] = await Promise.all([
|
|
192
|
+
service.summarize(),
|
|
193
|
+
service.listEvidence(),
|
|
194
|
+
service.listClaims(),
|
|
195
|
+
])
|
|
196
|
+
const trail = buildTrail({
|
|
197
|
+
summary,
|
|
198
|
+
evidence,
|
|
199
|
+
claims,
|
|
200
|
+
now: new Date(),
|
|
201
|
+
...(args.limit === undefined ? {} : { limit: args.limit }),
|
|
202
|
+
})
|
|
203
|
+
return JSON.parse(JSON.stringify(trail)) as never
|
|
204
|
+
} catch (error) {
|
|
205
|
+
return {
|
|
206
|
+
ok: false as const,
|
|
207
|
+
error: { code: 'TRAIL_FAILED', message: error instanceof Error ? error.message : String(error) },
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
})
|
|
212
|
+
}
|
package/src/verify-sealed.ts
CHANGED
|
File without changes
|
package/src/verify.ts
CHANGED
|
File without changes
|
package/src/version.ts
CHANGED