@staix/agent-research 0.2.1 → 0.3.1

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.
Files changed (73) hide show
  1. package/CHANGELOG.md +129 -0
  2. package/README.md +261 -24
  3. package/package.json +2 -2
  4. package/src/cli.ts +117 -10
  5. package/src/commands-table.ts +39 -8
  6. package/src/commands.ts +201 -34
  7. package/src/exp/artifacts.ts +20 -2
  8. package/src/exp/attempts.ts +505 -65
  9. package/src/exp/executor.ts +264 -17
  10. package/src/exp/final.ts +1 -1
  11. package/src/exp/logs.ts +25 -12
  12. package/src/exp/metrics.ts +8 -9
  13. package/src/exp/pipeline.ts +92 -0
  14. package/src/exp/protocol.ts +87 -20
  15. package/src/exp/retention-script.ts +649 -0
  16. package/src/exp/retention.ts +70 -0
  17. package/src/exp/reuse-admission.ts +65 -0
  18. package/src/exp/reuse-contract.ts +48 -0
  19. package/src/exp/reuse-runtime.ts +91 -0
  20. package/src/exp/reuse.ts +87 -0
  21. package/src/exp/selection.ts +1 -1
  22. package/src/exp/snapshot.ts +30 -10
  23. package/src/exp/stages.ts +117 -0
  24. package/src/harness/experience-source.ts +34 -0
  25. package/src/harness/experience.ts +206 -0
  26. package/src/harness/hub-guidance.ts +140 -0
  27. package/src/harness/hub-reference.ts +18 -0
  28. package/src/harness/lesson-candidates.ts +162 -0
  29. package/src/harness/limits.ts +2 -0
  30. package/src/harness/privacy.ts +4 -0
  31. package/src/harness/receipts.ts +84 -0
  32. package/src/harness/rounds.ts +198 -0
  33. package/src/harness/transitions.ts +152 -0
  34. package/src/lit/candidates.ts +13 -5
  35. package/src/lit/cards.ts +55 -4
  36. package/src/lit/flow.ts +82 -0
  37. package/src/lit/queries.ts +62 -0
  38. package/src/manifest.ts +13 -6
  39. package/src/mcp-tools.ts +123 -25
  40. package/src/mcp.ts +4 -0
  41. package/src/memory/amem-show.ts +135 -0
  42. package/src/memory/amem.ts +3 -0
  43. package/src/memory/archive.ts +17 -8
  44. package/src/memory/evidence-local.ts +77 -0
  45. package/src/memory/evidence.ts +39 -0
  46. package/src/memory/lessons.ts +4 -2
  47. package/src/memory/skill-check.ts +56 -0
  48. package/src/memory/skill-format.ts +77 -0
  49. package/src/memory/skills.ts +72 -26
  50. package/src/memory/source-budget.ts +11 -0
  51. package/src/memory/vault-cards.ts +226 -0
  52. package/src/paper/build.ts +16 -7
  53. package/src/paper/check.ts +37 -10
  54. package/src/paper/headings.ts +39 -0
  55. package/src/paper/hygiene.ts +153 -0
  56. package/src/paper/placeholders.ts +16 -1
  57. package/src/paper/plan.ts +170 -0
  58. package/src/paper/point-evidence.ts +63 -0
  59. package/src/paper/points.ts +83 -0
  60. package/src/paper/review.ts +102 -9
  61. package/src/paper/scopes.ts +51 -0
  62. package/src/plan/definition.ts +5 -1
  63. package/src/plan/hub.ts +6 -0
  64. package/src/plan/state.ts +5 -0
  65. package/src/playbook.ts +35 -20
  66. package/src/privacy.ts +9 -0
  67. package/src/provenance.ts +679 -0
  68. package/src/scope.ts +24 -3
  69. package/src/study-export.ts +55 -27
  70. package/src/study.ts +54 -14
  71. package/src/ui/panel.css +4 -0
  72. package/src/ui/panel.js +263 -6
  73. package/src/ui/plugin.ts +68 -10
@@ -0,0 +1,82 @@
1
+ import { existsSync } from "node:fs";
2
+ import { candidatesPath, includedHash, isVerified, loadCandidates, type Candidate } from "./candidates.ts";
3
+ import { cardPath } from "./cards.ts";
4
+ import { readScope } from "../scope.ts";
5
+ import { gateState, openStudy, readLedger, type LedgerEvent } from "../study.ts";
6
+
7
+ /** Fields available as {{n:lit.flow.<field>}}; excluded.<code> is added per declared code plus "uncoded". */
8
+ export const FLOW_FIELDS = ["records", "duplicates", "unique", "screened", "excluded", "unscreened", "included", "verified", "cards"] as const;
9
+ export type FlowField = typeof FLOW_FIELDS[number];
10
+ const count = (value: unknown) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : 0;
11
+
12
+ /** Derived only from the ledger, the candidate file, scope.json and card existence; no new state. */
13
+ export function flowFrom(dir: string, events: LedgerEvent[], candidates: Candidate[]) {
14
+ const searches = events.filter(e => e.type === "lit.search"), scope = readScope(dir);
15
+ const bySource: Record<string, { searches: number; ok: number; records: number }> = {};
16
+ let records = 0, duplicates = 0, dropped = 0;
17
+ const yearFrom = new Set<number>();
18
+ for (const e of searches) {
19
+ for (const s of Array.isArray(e.data.sources) ? e.data.sources as { source?: unknown; ok?: unknown; returned?: unknown }[] : []) {
20
+ const name = typeof s.source === "string" ? s.source : "unknown", row = bySource[name] ??= { searches: 0, ok: 0, records: 0 };
21
+ row.searches++; if (s.ok === true) row.ok++; row.records += count(s.returned); records += count(s.returned);
22
+ }
23
+ // A bridging record that folds an earlier candidate away removes one more duplicate than its single merge.
24
+ duplicates += count(e.data.merged) + count(e.data.absorbed); dropped += count(e.data.dropped);
25
+ if (typeof e.data.yearFrom === "number") yearFrom.add(e.data.yearFrom);
26
+ }
27
+ const included = candidates.filter(c => c.status === "included"), excluded = candidates.filter(c => c.status === "excluded");
28
+ const codes = scope?.exclusionCodes ?? [];
29
+ // Without declared codes every exclusion is one "uncoded" group; a code no longer declared still counts under its name.
30
+ const excludedByCode: Record<string, number> = Object.fromEntries([...codes.map(c => [c.code, 0] as [string, number]), ["uncoded", 0]]);
31
+ for (const c of excluded) { const key = c.exclusionCode ?? "uncoded"; excludedByCode[key] = (excludedByCode[key] ?? 0) + 1; }
32
+ return {
33
+ window: { firstSearch: searches[0]?.at ?? null, lastSearch: searches.at(-1)?.at ?? null, searches: searches.length, yearFrom: [...yearFrom].sort((a, b) => a - b), scopeYearFrom: scope?.yearFrom ?? null, scopeYearTo: scope?.yearTo ?? null },
34
+ sources: bySource,
35
+ records, duplicates, dropped, unique: candidates.length,
36
+ screened: included.length + excluded.length, excluded: excluded.length, excludedByCode,
37
+ exclusionCodes: codes, unscreened: candidates.length - included.length - excluded.length,
38
+ included: included.length, verified: included.filter(isVerified).length,
39
+ cards: included.filter(c => existsSync(cardPath(dir, c.id))).length,
40
+ };
41
+ }
42
+ export type Flow = ReturnType<typeof flowFrom>;
43
+
44
+ /** The screen gate binds the included set; flow numbers are citable only while it is approved for the current set. */
45
+ export function screenApproved(events: LedgerEvent[], candidates: Candidate[]): boolean {
46
+ return gateState("screen", events, gate => gate === "screen" ? includedHash(candidates) : undefined).state === "approved";
47
+ }
48
+
49
+ export function litFlow(dirArg: string) {
50
+ const { dir } = openStudy(dirArg), events = readLedger(dir), candidates = loadCandidates(dir);
51
+ return { ...flowFrom(dir, events, candidates), screenApproved: screenApproved(events, candidates) };
52
+ }
53
+
54
+ /** Value for a lit.flow.* ref, or undefined for an unknown field. */
55
+ export function flowValue(flow: Flow, field: string): number | undefined {
56
+ if ((FLOW_FIELDS as readonly string[]).includes(field)) return flow[field as FlowField];
57
+ const match = /^excluded\.([a-z][a-z0-9-]{0,31})$/.exec(field);
58
+ return match && Object.hasOwn(flow.excludedByCode, match[1]!) ? flow.excludedByCode[match[1]!] : undefined;
59
+ }
60
+
61
+ /** A pasteable Markdown table whose every number is a {{n:lit.flow.*}} placeholder; labels hold no digits. */
62
+ export function flowMarkdown(dirArg: string): string {
63
+ const { dir } = openStudy(dirArg), flow = flowFrom(dir, readLedger(dir), loadCandidates(dir));
64
+ const n = (field: string) => `{{n:lit.flow.${field}}}`;
65
+ const label = (text: string) => /\p{Nd}/u.test(text) ? `{{lit:${text}}}` : text;
66
+ const rows: [string, string][] = [
67
+ ["Records retrieved from all sources", n("records")],
68
+ ["Duplicates merged", n("duplicates")],
69
+ ["Unique records", n("unique")],
70
+ ["Records screened", n("screened")],
71
+ ["Records excluded", n("excluded")],
72
+ ...flow.exclusionCodes.map(c => [`Excluded: ${label(c.label)}`, n(`excluded.${c.code}`)] as [string, string]),
73
+ ...(flow.exclusionCodes.length && flow.excludedByCode.uncoded ? [["Excluded without a code", n("excluded.uncoded")] as [string, string]] : []),
74
+ ["Records not yet screened", n("unscreened")],
75
+ ["Studies included", n("included")],
76
+ ["Included with verified identifiers", n("verified")],
77
+ ["Included with extraction cards", n("cards")],
78
+ ];
79
+ return ["| Stage | Count |", "| --- | --- |", ...rows.map(([stage, value]) => `| ${stage} | ${value} |`)].join("\n") + "\n";
80
+ }
81
+
82
+ export function flowSourceFile(dir: string): string { return candidatesPath(dir); }
@@ -0,0 +1,62 @@
1
+ import { loadCandidates } from "./candidates.ts";
2
+ import { openStudy, readLedger, type LedgerEvent } from "../study.ts";
3
+
4
+ /** Query intents (#103). ares records them; it never generates or ranks queries. */
5
+ export const QUERY_INTENTS = ["lexical", "semantic", "background"] as const;
6
+ export type QueryIntent = typeof QUERY_INTENTS[number];
7
+ export type IntentLabel = QueryIntent | "unspecified";
8
+
9
+ export function validateIntent(raw: unknown, field = "--intent"): QueryIntent {
10
+ if (typeof raw !== "string" || !(QUERY_INTENTS as readonly string[]).includes(raw)) throw new Error(`${field}: unknown query intent; use ${QUERY_INTENTS.join(", ")} or omit it`);
11
+ return raw as QueryIntent;
12
+ }
13
+ /** Ledger events carry no id; a search is named by its 1-based ordinal among lit.search events in the append-only ledger. */
14
+ export function searchId(ordinal: number): string { return `search-${ordinal}`; }
15
+ export function nextSearchId(events: LedgerEvent[]): string { return searchId(events.filter(e => e.type === "lit.search").length + 1); }
16
+ /** Old or hand-edited events read as unspecified rather than failing the report. */
17
+ export function intentOf(event: LedgerEvent): IntentLabel {
18
+ const value = event.data.intent;
19
+ return typeof value === "string" && (QUERY_INTENTS as readonly string[]).includes(value) ? value as QueryIntent : "unspecified";
20
+ }
21
+
22
+ interface Yield { included: number; excluded: number; new: number }
23
+ const LABELS: IntentLabel[] = [...QUERY_INTENTS, "unspecified"];
24
+ const count = (value: unknown) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : 0;
25
+
26
+ /** Per-intent counts only, for the content-free export bundle. */
27
+ export function intentSummary(events: LedgerEvent[], candidates: { firstQuery?: string; status: string }[]) {
28
+ return queryReport(events, candidates).byIntent;
29
+ }
30
+
31
+ function queryReport(events: LedgerEvent[], candidates: { firstQuery?: string; status: string }[]) {
32
+ const yields = new Map<string, Yield>();
33
+ let unattributed = 0;
34
+ for (const c of candidates) {
35
+ if (!c.firstQuery) { unattributed++; continue; }
36
+ const row = yields.get(c.firstQuery) ?? { included: 0, excluded: 0, new: 0 };
37
+ if (c.status === "included") row.included++; else if (c.status === "excluded") row.excluded++; else row.new++;
38
+ yields.set(c.firstQuery, row);
39
+ }
40
+ const rows = events.filter(e => e.type === "lit.search").map((e, index) => {
41
+ const id = searchId(index + 1), y = yields.get(id) ?? { included: 0, excluded: 0, new: 0 };
42
+ const sources = Array.isArray(e.data.sources) ? (e.data.sources as { source?: unknown; ok?: unknown }[]).map(s => ({ source: typeof s.source === "string" ? s.source : "unknown", ok: s.ok === true })) : [];
43
+ return { id, at: e.at, query: typeof e.data.query === "string" ? e.data.query : "", intent: intentOf(e), sources, added: count(e.data.added), merged: count(e.data.merged), ...y };
44
+ });
45
+ const byIntent = Object.fromEntries(LABELS.map(label => [label, { queries: 0, added: 0, merged: 0, included: 0, excluded: 0, new: 0 }])) as Record<IntentLabel, { queries: number; added: number; merged: number } & Yield>;
46
+ for (const row of rows) {
47
+ const s = byIntent[row.intent];
48
+ s.queries++; s.added += row.added; s.merged += row.merged; s.included += row.included; s.excluded += row.excluded; s.new += row.new;
49
+ }
50
+ return { rows, byIntent, unattributed };
51
+ }
52
+
53
+ /** Read-only per-query yield: what each search first added and how that screened out. */
54
+ export function litQueries(dirArg: string) {
55
+ const { dir } = openStudy(dirArg), report = queryReport(readLedger(dir), loadCandidates(dir));
56
+ return {
57
+ queries: report.rows, byIntent: report.byIntent,
58
+ zeroIncluded: report.rows.filter(row => row.included === 0).map(row => ({ id: row.id, intent: row.intent, added: row.added })),
59
+ // Candidates created before #103 (or by older ares) have no firstQuery and cannot be attributed to one search.
60
+ unattributed: report.unattributed,
61
+ };
62
+ }
package/src/manifest.ts CHANGED
@@ -5,26 +5,33 @@ import { ARES_TOOLS } from "./mcp-tools.ts";
5
5
  /** Implemented family-readable records only; private inputs and future integrations are not contracts. */
6
6
  export const FORMAT_VERSIONS = {
7
7
  manifest: 1,
8
+ harnessRound: 1,
9
+ lessonProposal: 1,
10
+ harnessTransition: 1,
11
+ harnessStream: 1,
12
+ harnessExperience: 1,
13
+ harnessFixtureProjection: 1,
8
14
  study: 2,
9
- paperEvidence: 1,
10
- skillProposal: 1,
15
+ paperEvidence: 2,
16
+ paperPlan: 2,
17
+ skillProposal: 2,
11
18
  studyRegistry: 1,
12
19
  watchConfig: 1,
13
20
  studyPlan: 1,
14
21
  ledgerEvent: 1,
15
- experimentProtocol: 1,
22
+ experimentProtocol: 2,
16
23
  experimentSelection: 1,
17
24
  experimentFinalSeeds: 1,
18
25
  ablateResult: 1,
19
26
  finalResult: 1,
20
27
  investigateResult: 1,
21
28
  executor: 1,
22
- experimentAttempt: 1,
29
+ experimentAttempt: 3,
23
30
  studyBundle: 1,
24
31
  } as const;
25
- export const MEMORY_LEDGER_EVENTS = ["archive.exported", "skill.proposed", "skill.decided"] as const;
32
+ export const MEMORY_LEDGER_EVENTS = ["archive.exported", "skill.proposed", "skill.decided", "lesson.proposed", "lesson.decided"] as const;
26
33
  export const WATCH_LEDGER_EVENTS = ["watch.set", "watch.ran"] as const;
27
- export const LEDGER_EVENTS = [...MEMORY_LEDGER_EVENTS, ...WATCH_LEDGER_EVENTS, "autonomy.set"] as const;
34
+ export const LEDGER_EVENTS = [...MEMORY_LEDGER_EVENTS, ...WATCH_LEDGER_EVENTS, "autonomy.set", "harness.round.set", "harness.probe.declared", "harness.contrast.recorded", "harness.composition.recorded", "harness.adoption.decided", "harness.round.closed", "experience.stream.set", "experience.frozen", "retention.pruned", "attempt.pipeline.code", "attempt.pipeline.inputs", "attempt.stage.terminated", "attempt.reuse.preflight", "attempt.reuse.fresh-intent", "attempt.reuse.materialized", "attempt.reuse.miss", "attempt.stage.reused", "paper.plan.set"] as const;
28
35
  export interface Manifest {
29
36
  v: 1;
30
37
  name: "ares";
package/src/mcp-tools.ts CHANGED
@@ -1,12 +1,17 @@
1
+ import { STAGE_REUSE_CONTRACT_SCHEMA } from "./exp/reuse-contract.ts";
2
+ import {HARNESS_MODEL_BYTES} from "./harness/limits.ts";
3
+ import { PROVENANCE_KINDS, type ExecutionReferenceV1 } from "./provenance.ts";
1
4
  import { PHASES, AUTONOMY_MODES } from "./autonomy.ts";
2
5
  import { SETUP_TARGETS, type SetupMode } from "./setup.ts";
3
6
  import { isAbsolute } from "node:path";
4
7
  import * as ops from "./commands.ts";
5
8
  import { createHttp, type Http } from "./http.ts";
6
9
  import type { McpHandler, McpTool } from "./mcp.ts";
10
+ import type { RetainedRef } from "./exp/retention.ts";
7
11
  import { PLAYBOOK } from "./playbook.ts";
8
12
  import { PLAN_ID_BYTES, STEP_COMMANDS } from "./plan/definition.ts";
9
13
  import { PLAN_GATE_BYTES } from "./plan/state.ts";
14
+ import { PAPER_PLAN_BYTES, PAPER_PLAN_SECTIONS, PAPER_PLAN_CITES, PAPER_PLAN_POINTS, PAPER_POINT_CLAIM_CHARACTERS, PAPER_POINT_EVIDENCE, PAPER_POINT_EVIDENCE_BYTES } from "./paper/plan.ts";
10
15
  import { detectActor, type Actor } from "./study.ts";
11
16
 
12
17
  const study = { type: "string", minLength: 1, maxLength: 4096, description: "Absolute path of the study directory (holds study.json)" };
@@ -21,15 +26,31 @@ const obj = (properties: Record<string, unknown>, required: string[]) => ({ type
21
26
  const text = (max: number) => ({ type: "string", minLength: 1, maxLength: max });
22
27
  const texts = (items: number, max: number) => ({ type: "array", items: text(max), maxItems: items });
23
28
  const year = { type: "integer", minimum: 1000, maximum: 2100 };
29
+ const PAPER_PLAN = obj({v: {type: "integer", enum: [1, 2]}, sections: {type: "array", maxItems: PAPER_PLAN_SECTIONS, items: obj({
30
+ id: {...text(64), pattern: "^[a-z0-9]+(?:-[a-z0-9]+)*$"}, heading: text(PAPER_PLAN_BYTES),
31
+ cites: {type: "array", maxItems: PAPER_PLAN_CITES, uniqueItems: true, items: text(PAPER_PLAN_BYTES)},
32
+ points: {type: "array", maxItems: PAPER_PLAN_POINTS, items: obj({
33
+ id: {...text(64), pattern: "^[a-z0-9]+(?:-[a-z0-9]+)*$"},
34
+ // MCP's generic string guard counts UTF-16 units; the shared validator enforces Unicode characters.
35
+ claim: {...text(PAPER_POINT_CLAIM_CHARACTERS * 2), description: "Single-line claim, at most 500 Unicode characters; shape only, never support or prose matching"},
36
+ requires: {type: "array", maxItems: PAPER_PLAN_CITES, uniqueItems: true, items: text(PAPER_PLAN_BYTES)},
37
+ evidence: {type: "array", maxItems: PAPER_POINT_EVIDENCE, items: {...text(PAPER_POINT_EVIDENCE_BYTES), description: "Existing current-study card:<paper-id> or attempt:<16-hex-id>, at most 4096 UTF-8 bytes; existence only"}},
38
+ }, ["id", "claim", "requires"])},
39
+ }, ["id", "heading", "cites"])}}, ["sections"]);
40
+ const EXECUTION_REFERENCE = obj({ v: { type: "integer", enum: [1] }, tool: { type: "string", enum: ["ares"] }, projectKey: text(256), kind: { type: "string", enum: [...PROVENANCE_KINDS] }, id: text(256), revision: text(128), sha256: { type: "string", minLength: 64, maxLength: 64 } }, ["v", "tool", "projectKey", "kind", "id"]);
41
+ const LINEAGE_ATTEMPTS = { type: "array", minItems: 1, maxItems: 8, items: { ...text(16), minLength: 16 } };
42
+ const LINEAGE_CANDIDATES = { type: "array", minItems: 1, maxItems: 8, items: { ...text(40), minLength: 40 } };
24
43
  const REVIEW = obj({
25
44
  v: { type: "integer", enum: [1] }, reviewer: obj({ id: text(128), modelFamily: text(128) }, ["id", "modelFamily"]), buildSha256: { type: "string", minLength: 64, maxLength: 64 },
26
- checklist: obj({ negativeResults: { type: "boolean" }, denominators: { type: "boolean" }, limitations: { type: "boolean" }, reproducibility: { type: "boolean" } }, ["negativeResults", "denominators", "limitations", "reproducibility"]),
27
- findings: { type: "array", maxItems: 200, items: obj({ id: text(128), kind: { type: "string", enum: ["contradiction", "unsupported-claim", "number", "citation", "method", "clarity", "other"] }, location: text(4000), text: text(4000), blocking: { type: "boolean" } }, ["id", "kind", "location", "text", "blocking"]) },
45
+ checklist: obj({ negativeResults: { type: "boolean" }, denominators: { type: "boolean" }, limitations: { type: "boolean" }, reproducibility: { type: "boolean" },
46
+ survey: obj({ taxonomyPrinciple: { type: "boolean" }, noEnumeration: { type: "boolean" }, specificGaps: { type: "boolean" }, citationRelations: { type: "boolean" }, selectionReported: { type: "boolean" }, scopeControl: { type: "boolean" } }, ["taxonomyPrinciple", "noEnumeration", "specificGaps", "citationRelations", "selectionReported", "scopeControl"]) }, ["negativeResults", "denominators", "limitations", "reproducibility"]),
47
+ findings: { type: "array", maxItems: 200, items: obj({ id: text(128), kind: { type: "string", enum: ["contradiction", "unsupported-claim", "number", "citation", "method", "clarity", "other"] }, location: text(4000), text: text(4000), blocking: { type: "boolean" }, repair: { type: "string", enum: ["edit", "paragraph", "section"] }, section: text(256) }, ["id", "kind", "location", "text", "blocking"]) },
28
48
  }, ["v", "reviewer", "buildSha256", "checklist", "findings"]);
29
- const SKILL = obj({ name: text(64), summary: text(16384), steps: { ...texts(16384, 16384), minItems: 1 },
30
- evidence: { ...texts(64, 16384), minItems: 1, description: "32-hex amem ids or ares:<study-id>/... refs" } }, ["name", "summary", "steps", "evidence"]);
49
+ // Source-specific current-study/exact-id rules are owned by the shared validator; the MCP transport bounds both shapes.
50
+ const SKILL_REF = {...EXECUTION_REFERENCE, type: ["string", "object"], minLength: 1, maxLength: 4096, required: ["v", "tool", "id"], properties: {...EXECUTION_REFERENCE.properties, tool: {type: "string", enum: ["ares", "amem"]}}};
51
+ const SKILL = obj({name: text(64), summary: text(4000), steps: {...texts(64, 1000), minItems: 1}, evidence: {type: "array", minItems: 1, maxItems: 64, items: SKILL_REF}, applicability: text(2000), limitations: texts(16, 1000), counterevidence: {type: "array", maxItems: 64, items: SKILL_REF}}, ["name", "summary", "steps", "evidence"]);
31
52
  const SCOPE = obj({ question: text(2000), subquestions: texts(30, 1000), include: texts(50, 500), exclude: texts(50, 500), yearFrom: year, yearTo: year, maxCandidates: { type: "integer", minimum: 1, maximum: 5000 } }, ["question"]);
32
- const CARD = obj({ summary: text(4000), claims: texts(50, 1000), methods: text(4000), findings: text(4000), limitations: text(4000), relevance: text(4000) }, ["summary"]);
53
+ const CARD = obj({ summary: text(4000), claims: texts(50, 1000), methods: text(4000), findings: text(4000), limitations: text(4000), relevance: text(4000), datasets: text(4000), results: text(4000), motivation: text(4000) }, ["summary"]);
33
54
  const integer = (minimum: number, maximum: number) => ({ type: "integer", minimum, maximum });
34
55
  const WATCH = obj({ v: {}, queries: { type: "array", minItems: 1, maxItems: 20,
35
56
  items: obj({ id: text(64), query: text(4096), source: { type: "string", enum: ["openalex", "s2", "arxiv", "all"] }, yearFrom: year, limit: integer(1, 50) }, ["id", "query"]) }, rubric: text(8000) }, ["queries"]);
@@ -39,7 +60,8 @@ const stage = { type: "string", enum: ["candidate", "evaluator"] };
39
60
  const stream = { type: "string", enum: ["stdout", "stderr"] };
40
61
  const attemptId = { type: "string", minLength: 16, maxLength: 16, description: "16-hex attempt id from attempt list" };
41
62
  const run = text(64), seed = integer(-2_147_483_648, 2_147_483_647);
42
- const PROTOCOL = obj({
63
+ const RETAINED_REFS = { type: "array", minItems: 1, maxItems: 500, items: obj({ attemptId, stage: text(32), sha256: { ...text(64), minLength: 64 } }, ["attemptId", "stage", "sha256"]) };
64
+ const PROTOCOL_V1 = obj({
43
65
  v: { type: "integer", enum: [1] }, method: text(4000),
44
66
  candidate: obj({ image, command: argv, env: { type: "object", maxProperties: 64, properties: {}, additionalProperties: { type: "string", maxLength: 4096 }, description: "Non-secret environment values; secret-like keys and reserved ARES_SEED are refused" } }, ["image", "command"]),
45
67
  evaluator: obj({ image, command: argv }, ["image", "command"]),
@@ -47,9 +69,25 @@ const PROTOCOL = obj({
47
69
  seeds: { type: "array", minItems: 1, maxItems: 1000, items: seed },
48
70
  limits: obj({ cpus: { type: "number", minimum: 0.1, maximum: 256 }, memoryMb: integer(16, 1_048_576), pidsLimit: integer(1, 65_536), wallSeconds: integer(1, 604_800), gpus: integer(0, 64) }, ["cpus", "memoryMb", "pidsLimit", "wallSeconds", "gpus"]),
49
71
  network: { type: "string", enum: ["none"] },
72
+ inputs: { type: "object", maxProperties: 8, properties: {}, additionalProperties: obj({ path: text(4096), sha256: text(64), mount: obj({ candidate: text(256), evaluator: text(256) }, []) }, ["path", "sha256", "mount"]) },
50
73
  budget: obj({ maxAttempts: integer(1, 1_000_000), maxWallHours: { type: "number", minimum: 0.000001, maximum: 1_000_000 }, maxGpuHours: { type: "number", minimum: 0, maximum: 64_000_000 } }, ["maxAttempts", "maxWallHours", "maxGpuHours"]),
51
74
  }, ["v", "method", "candidate", "evaluator", "metrics", "seeds", "limits", "network", "budget"]);
52
75
 
76
+ const STAGE_PROTOCOL = obj({ ...PROTOCOL_V1.properties,
77
+ v: { type: "integer", enum: [2] },
78
+ inputs: undefined,
79
+ candidate: obj({ stages: { type: "array", minItems: 1, maxItems: 16, items: obj({
80
+ name: text(32), reuse: STAGE_REUSE_CONTRACT_SCHEMA, image, command: argv, env: { type: "object", maxProperties: 64, properties: {}, additionalProperties: { type: "string", maxLength: 4096 } },
81
+ seed: { type: "boolean" }, code: { type: "string", enum: ["snapshot"] },
82
+ needs: { type: "array", maxItems: 16, items: text(32) },
83
+ inputs: { type: "object", maxProperties: 32, additionalProperties: { oneOf: [obj({ task: text(256) }, ["task"]), obj({ stage: text(32), output: text(32) }, ["stage", "output"])] } },
84
+ outputs: { type: "object", maxProperties: 32, additionalProperties: text(256) },
85
+ }, ["name", "image", "command", "seed", "code", "needs", "inputs", "outputs"]) } }, ["stages"]),
86
+ }, PROTOCOL_V1.required);
87
+ // Omit the v1 external-input property entirely; undefined is not a JSON schema.
88
+ delete STAGE_PROTOCOL.properties.inputs;
89
+ const PROTOCOL = { oneOf: [PROTOCOL_V1, STAGE_PROTOCOL] };
90
+
53
91
  const planId = text(PLAN_ID_BYTES);
54
92
  const PLAN = obj({
55
93
  v: { type: "integer", enum: [1] }, revision: integer(1, Number.MAX_SAFE_INTEGER),
@@ -73,6 +111,27 @@ const SELECTION = obj({
73
111
  const IDEA = obj({ id: text(64), title: text(500), hypothesis: text(4000), parent: text(64), commit: { type: "string", minLength: 40, maxLength: 40 } }, ["id", "title", "hypothesis"]);
74
112
 
75
113
  export const ARES_TOOLS: readonly McpTool[] = [
114
+ { name: "ares_retention_inspect", description: "Inspect executor-local retained identities, quota reservations and tombstones without a study write. Active sources/consumers remain explicit; no artifact bodies are returned.", inputSchema: obj({study, offset: integer(0, 16_000_000), limit: integer(1, 500)}, ["study"]), annotations: {...read, openWorldHint: true} },
115
+ { name: "ares_retention_prune", description: "Preview explicit retained references by default. Confirm the returned fingerprint to dispose bytes under current design policy; active producers/consumers refuse. Tombstones preserve provenance. Executor tombstones remain authoritative after a crash before the local audit receipt; inspect them before retrying.", inputSchema: obj({study, refs: RETAINED_REFS, fingerprint: {...text(64), minLength: 64}}, ["study", "refs"]), annotations: {...net, destructiveHint: true} },
116
+ {name: "ares_lesson_propose", description: "Propose a bounded lesson from a closed native harness round. Inspect required evidence/counterevidence explicitly; fixture-only single-task observations never establish real behavior, success or transfer.", inputSchema: obj({study, proposal: {type: "object"}}, ["study", "proposal"]), annotations: net},
117
+ {name: "ares_lesson_list", description: "Read stored lesson proposals and dispositions locally, without current source checks. Stored eligibility is not fresh proof; no body or activation.", inputSchema: obj({study}, ["study"]), annotations: read},
118
+ {name: "ares_lesson_check", description: "Explicitly recheck a lesson's current native closure and screened evidence/counterevidence without writing. Integrity never establishes support; no body is retained.", inputSchema: obj({study, name: text(64)}, ["study", "name"]), annotations: {...read, openWorldHint: true}},
119
+ {name: "ares_lesson_decide", description: "Record a hash-bound lesson disposition. Acceptance rechecks sources under the study lock and requires exact fixture-strength acknowledgement; not adoption, activation or transfer evidence.", inputSchema: obj({study, name: text(64), decision: obj({decision: {type: "string", enum: ["accept", "reject", "withdraw"]}, proposalSha256: text(64), evidenceFingerprint: text(64), reason: text(2000), acknowledgeStrength: text(1000)}, ["decision", "proposalSha256", "evidenceFingerprint", "reason"])}, ["study", "name", "decision"]), annotations: net},
120
+ { name: "ares_skill_check", description: "Explicit read-only source check of a proposal under one 25s/256KiB aggregate response budget. Evidence and counterevidence share the same owner-screened exact-id/local snapshot rules. Integrity/outcome never imply support; no body, export or installation.", inputSchema: obj({study, name: text(64)}, ["study", "name"]), annotations: {...read, openWorldHint: true} },
121
+ { name: "ares_harness_close", description: "Preview/confirm an immutable baseline-kept, inconclusive or withdrawn closure without any adoption. Record binding, current evidence fingerprint, outcome, actor and reason; source/evidence drift marks it stale and preserves it. Never scientific success or transfer.", inputSchema: obj({study, round: text(64), closure: {type: "object"}, confirm: text(64)}, ["study", "round", "closure"]), annotations: write },
122
+ { name: "ares_harness_contrast", description: "Record an actor-attributed fixture contrast against current admitted probe/output hashes and evidence fingerprint. Subjective judgments stay separate from task checks; no native metric or transfer authority.", inputSchema: obj({study, round: text(64), contrast: {type: "object"}}, ["study", "round", "contrast"]), annotations: write },
123
+ { name: "ares_harness_compose", description: "Record per-section keep/drop/revise decisions linked to current contrasts, declaring at most one successor hash. A new successor remains unexecuted until its own exact fixture execution; real evidence is unavailable.", inputSchema: obj({study, round: text(64), composition: {type: "object"}}, ["study", "round", "composition"]), annotations: write },
124
+ { name: "ares_harness_adopt", description: "Preview an experimental fixture-only adoption with a distinct independent deterministic check (unavailable for current fixtures); confirm its returned fingerprint to commit disposition and closure together under the round gate. Does not create correctness, scientific success or demonstrated transfer.", inputSchema: obj({study, round: text(64), decision: {type: "object"}, confirm: text(64)}, ["study", "round", "decision"]), annotations: write },
125
+ { name: "ares_harness_stream_set", description: "Fix an immutable ordered 1..16-task experiment stream before its first harness round. No source reads or execution.", inputSchema: obj({study, stream: {type: "object"}}, ["study", "stream"]), annotations: write },
126
+ { name: "ares_harness_stream_show", description: "Read the receipted immutable local harness stream without writes or source reads.", inputSchema: obj({study}, ["study"]), annotations: read },
127
+ { name: "ares_experience_select", description: "Rank project lessons, then screen only explicit full ids backed by earlier same-study accepted unchanged lesson/archive receipts. Fixture-only preparation, never live/controlled eligibility; stores no bodies or memory writes.", inputSchema: obj({study, selection: {type: "object"}}, ["study", "selection"]), annotations: {...read, openWorldHint: true} },
128
+ { name: "ares_experience_freeze", description: "Freeze immutable body-free source pins before a round. Empty controls or screened earlier reviewed/archived fixture lessons only; model/runtime/toolset must match. Synthetic context refuses controlled/live use. No activation or memory write.", inputSchema: obj({study, context: {type: "object"}}, ["study", "context"]), annotations: net },
129
+ { name: "ares_experience_check", description: "Pre-handoff local integrity and model/runtime check plus owning screened exact-id source recheck. Unavailable/changed sources block the frozen context. Does not launch improvement or worker sessions.", inputSchema: obj({study, round: text(64), model: text(HARNESS_MODEL_BYTES), runtime: text(128), toolsetSha256: text(64)}, ["study", "round", "model", "runtime"]), annotations: {...read, openWorldHint: true} },
130
+ { name: "ares_harness_set", description: "Set an experiment's bounded ares-owned harness round definition; no model/probe launch. Guidance and frozen refs bind a separate harness gate.", inputSchema: obj({study, round: {type: "object"}}, ["study", "round"]), annotations: write },
131
+ { name: "ares_harness_show", description: "Read local harness definitions and synthetic fixture declarations. End-to-end evaluation and real producer import stay unavailable.", inputSchema: obj({study, round: text(64)}, ["study"]), annotations: read },
132
+ { name: "ares_harness_import", description: "Record a declared ares-owned synthetic probe fixture under the round gate. Not producer wire import, host-observed evidence or a matched execution; never starts probes.", inputSchema: obj({study, round: text(64), fixture: {type: "object"}}, ["study", "round", "fixture"]), annotations: write },
133
+ { name: "ares_lineage_show", description: "Read bounded local source-proven lineage, optionally rooted at a local ExecutionReferenceV1 and continued with an opaque cursor. No executor, hub, network, repair, gate decision or result authority.", inputSchema: obj({ study, root: EXECUTION_REFERENCE, cursor: text(4096) }, ["study"]), annotations: read },
134
+ { name: "ares_lineage_compare", description: "Compare existing source-derived attempt or closed-candidate rows. Select either 1..8 attempts or 1..8 full candidate commits. Failed/unknown outcomes remain visible; retries are not independent samples. No new arithmetic aggregation, winner or verdict.", inputSchema: obj({ study, attempts: LINEAGE_ATTEMPTS, candidates: LINEAGE_CANDIDATES }, ["study"]), annotations: read },
76
135
  { name: "ares_autonomy_show", description: "Read the study autonomy policy and effective mode for each phase; no writes.", inputSchema: obj({ study }, ["study"]), annotations: read },
77
136
  { name: "ares_autonomy_set", description: `Set the default or one phase autonomy mode (${AUTONOMY_MODES.join("|")}) and record from/to/phase. Only auto approves pending gates; existing gate decisions remain unchanged. Copilot draft acceptance and step pausing are separate features.`, inputSchema: obj({ study, mode: text(16), phase: text(32) }, ["study", "mode"]), annotations: write },
78
137
  { name: "ares_watch_set", description: "Set bounded v1 literature queries and an optional display-only rubric. At most 20 queries; identical config is a no-op. Does not search, screen or start a timer. Survey and experiment studies.", inputSchema: obj({ study, watch: WATCH }, ["study", "watch"]), annotations: { ...write, idempotentHint: true } },
@@ -85,8 +144,8 @@ export const ARES_TOOLS: readonly McpTool[] = [
85
144
  { name: "ares_manifest", description: "Read this ares version, implemented commands and shared schema versions without opening a study or reaching an executor.", inputSchema: obj({}, []), annotations: read },
86
145
  { name: "ares_archive", description: "Preview pending derived lessons without writes. With the current full-list fingerprint, export up to 200 new amem notes and commit returned ids/hashes; remaining reports later batches. A partial failure records successes; repeat the same confirmation to continue. Applies to survey and experiment studies.", inputSchema: obj({ study, confirm: { type: "string", minLength: 64, maxLength: 64 } }, ["study"]), annotations: net },
87
146
  { name: "ares_lessons", description: "Read project-scoped amem lessons with half-life ranking. Query intent when supplied, otherwise the study question; intent also returns a brief. Output relevance, decayed score, ordinal rank and age in days. No study write or lock. Survey and experiment.", inputSchema: obj({ study, for: text(1000), halfLife: { type: "number", minimum: 1, maximum: 3650 }, limit: integer(1, 50) }, ["study"]), annotations: { ...read, openWorldHint: true } },
88
- { name: "ares_skill_propose", description: "Queue a reviewable skill proposal with at least one step and 1..64 evidence refs. At most 100 proposals, bounded 16 KiB Markdown plus receipt. Does not create a PR. Survey and experiment.", inputSchema: obj({ study, proposal: SKILL }, ["study", "proposal"]), annotations: write },
89
- { name: "ares_skill_decide", description: "Record a final accept/reject/withdraw with reason and actor. Accept requires an HTTP(S) PR URL without credentials; never checks or merges the PR. Withdraw only while proposed. Survey and experiment.", inputSchema: obj({ study, name: text(64), decision: { type: "string", enum: ["accept", "reject", "withdraw"] }, reason: text(16384), pr: text(16384) }, ["study", "name", "decision", "reason"]), annotations: write },
147
+ { name: "ares_skill_propose", description: "Queue a source-inspected v2 proposal; caller-supplied inspections are refused. Evidence and counterevidence share one 25s/256KiB budget. At most 100 proposals, bounded 16 KiB Markdown plus receipt. Does not create a PR. Survey and experiment.", inputSchema: obj({ study, proposal: SKILL }, ["study", "proposal"]), annotations: {...write, openWorldHint: true} },
148
+ { name: "ares_skill_decide", description: "Record a final accept/reject/withdraw with reason and actor. Accept requires an HTTP(S) PR URL without credentials; never checks or merges the PR. V2 acceptance rechecks all evidence and counterevidence under the owned lock; changed/unavailable sources require a revised proposal. Withdraw only while proposed. Survey and experiment.", inputSchema: obj({ study, name: text(64), decision: { type: "string", enum: ["accept", "reject", "withdraw"] }, reason: text(16384), pr: text(16384) }, ["study", "name", "decision", "reason"]), annotations: {...write, openWorldHint: true} },
90
149
  { name: "ares_skill_list", description: "Read all skill proposal states after verifying bounded Markdown against receipts. No lock, subprocess or write. Survey and experiment.", inputSchema: obj({ study }, ["study"]), annotations: read },
91
150
  { name: "ares_plan_set", description: "Validate a bounded revisioned DAG of existing steps, local gates and read-only hub references. Set it paused; changed consumed inputs become stale and need explicit retry. Never starts a controller.", inputSchema: obj({ study, plan: PLAN }, ["study", "plan"]), annotations: write },
92
151
  { name: "ares_plan_control", description: "Pause/resume admission or retry/cancel/skip a node. Requires a durable command id and expected definition revision: identical replay returns its original receipt; changed payloads/stale new requests refuse. Does not start a controller; run ares run separately. Cancelling an attempt may contact its executor; hub cancellation stays local.", inputSchema: obj({ study, action: { type: "string", enum: ["pause", "resume", "retry", "cancel", "skip"] }, node: text(128), commandId: text(128), expectedRevision: integer(1, Number.MAX_SAFE_INTEGER) }, ["study", "action", "commandId", "expectedRevision"]), annotations: net },
@@ -94,7 +153,7 @@ export const ARES_TOOLS: readonly McpTool[] = [
94
153
  { name: "ares_status", description: "Study summary: gates, candidate counts, verification counts, bibliography.", inputSchema: obj({ study }, ["study"]), annotations: read },
95
154
  { name: "ares_study_export", description: "Write a content-free study bundle (manifest, reduced ledger, attempt rows, closed results, review counts, evidence hashes) from committed study files into a new or empty directory. Refuses the whole export if a path, URL, env value or key-like token would be written. list=true only names the files. No executor or network.", inputSchema: obj({ study, bundle: text(4096), list: { type: "boolean" } }, ["study", "bundle"]), annotations: write },
96
155
  { name: "ares_scope_set", description: "Set scope.json (question, subquestions, include, exclude, yearFrom, yearTo, maxCandidates). A change returns the scope gate to pending.", inputSchema: obj({ study, scope: SCOPE }, ["study", "scope"]), annotations: write },
97
- { name: "ares_gate", description: "List gates, or approve/reject scope, screen, design, final, review, plan:node-id or accept:hypotheses|paper|reviews. Copilot accepts bind current draft hashes and are never automatic. Plan approvals bind all upstream output references and need complete upstream outputs; skip never bypasses them. The ledger records the actor; approval authority is workspace policy.", inputSchema: obj({ study, action: { type: "string", enum: ["list", "approve", "reject"] }, gate: text(PLAN_GATE_BYTES), reason }, ["study", "action"]), annotations: write },
156
+ { name: "ares_gate", description: "List gates, or approve/reject scope, screen, design, final, review, plan:node-id, accept:hypotheses|paper|reviews or harness:<round-id>. Copilot accepts bind current draft hashes and are never automatic. Plan approvals bind all upstream output references and need complete upstream outputs; skip never bypasses them. The ledger records the actor; approval authority is workspace policy.", inputSchema: obj({ study, action: { type: "string", enum: ["list", "approve", "reject"] }, gate: text(PLAN_GATE_BYTES), reason }, ["study", "action"]), annotations: write },
98
157
  { name: "ares_idea_add", description: "Add an experiment idea to the ledger, with optional existing parent and frozen commit. Unique run-name ids and commit ownership; at most 1000 ideas. Starts no work.", inputSchema: obj({ study, idea: IDEA }, ["study", "idea"]), annotations: write },
99
158
  { name: "ares_idea_decide", description: "Record refine/pivot with a reason of at most 2000 bytes. Ideas with commits require terminal own-commit attempts (at most 200). Untested ideas omit attempts to attach a first commit or pivot. Refine requires --commit with unique idea ownership; Pivot accepts optional cause/retryWhen (2000 bytes each); refine refuses them. Pivot rejects commit and closes further decisions. Starts no work.", inputSchema: obj({ study, id: text(64), decision: { type: "string", enum: ["refine", "pivot"] }, reason: text(2000), cause: text(2000), retryWhen: text(2000), attempts: { type: "array", maxItems: 200, items: attemptId }, commit: { type: "string", minLength: 40, maxLength: 40 } }, ["study", "id", "decision", "reason"]), annotations: write },
100
159
  { name: "ares_investigate_show", description: "Read investigation candidate/baseline paired-seed scores, winner or no-winner reason and all run attempt totals/exclusions. No executor or network calls.", inputSchema: obj({ study }, ["study"]), annotations: read },
@@ -106,26 +165,35 @@ export const ARES_TOOLS: readonly McpTool[] = [
106
165
  { name: "ares_final_close", description: "Close one-shot reserved-seed evaluation under the currently approved final gate. Re-approval keeps first attempt data fixed; later retries never replace it. Winner changes cannot buy a new final; changed protocol is not comparable. Refuses running or missing decisive attempts; writes deterministic qualified/not_qualified with unchanged inputs a no-op. The no-arg final.close plan step emits {sha256,status}; both qualification outcomes complete the step.", inputSchema: obj({ study }, ["study"]), annotations: write },
107
166
  { name: "ares_final_seeds", description: "Reserve unused unique declared protocol seeds for final evaluation (new/changed values reject prior use in every run/status), at least one and at most half the declared seeds. New/changed raw file bytes join the design seal; identical bytes are a no-op. Experiment mode only; starts no work.", inputSchema: obj({ study, final: obj({ v: { type: "integer", enum: [1] }, seeds: { type: "array", minItems: 1, maxItems: 500, items: seed } }, ["v", "seeds"]) }, ["study", "final"]), annotations: write },
108
167
  { name: "ares_selection_set", description: "Set a declared investigation selection rule before results: run (not reserved ablate/final/posthoc), primary metric, frozen baseline commit, minimum paired seeds and nonnegative improvement. Changes reopen the design gate; identical bytes leave the cutoff unchanged. Requires experiment mode and a protocol; starts no investigation or executor.", inputSchema: obj({ study, selection: SELECTION }, ["study", "selection"]), annotations: write },
109
- { name: "ares_protocol_set", description: "Set an experiment protocol after bounded validation of protocol and task/. Changes reopen design approval; attempt protocol identity excludes budget.", inputSchema: obj({ study, protocol: PROTOCOL }, ["study", "protocol"]), annotations: write },
110
- { name: "ares_executor_set", description: "Configure local or SSH Docker execution with an explicit private absolute workdir. Stores the host alias only, never credentials.", inputSchema: obj({ study, kind: { type: "string", enum: ["local", "ssh"] }, host: text(128), workdir: text(4096) }, ["study", "kind", "workdir"]), annotations: write },
168
+ { name: "ares_protocol_set", description: "Set an experiment protocol after bounded validation of protocol and task/. Sealed identity changes reopen design approval; same-identity input locator-only edits preserve approval. Comparable attempt identity excludes budget and input locators.", inputSchema: obj({ study, protocol: PROTOCOL }, ["study", "protocol"]), annotations: write },
169
+ { name: "ares_executor_set", description: "Configure local or SSH Docker execution with an explicit private absolute workdir. Stores the host alias only, never credentials. Optional gpu settings enable a one-pass device/memory/load admission check; failed admission defers without an attempt.", inputSchema: obj({ study, kind: { type: "string", enum: ["local", "ssh"] }, host: text(128), workdir: text(4096), retentionCapBytes: integer(1, 1024 ** 4), gpu: obj({ devices: { type: "array", minItems: 1, maxItems: 64, items: { type: ["string", "integer"], maxLength: 40 } }, minFreeMemoryMb: integer(0, 2147483647), maxLoadRatio: { type: "number", exclusiveMinimum: 0, maximum: 1000000 } }, ["devices", "minFreeMemoryMb", "maxLoadRatio"]) }, ["study", "kind", "workdir"]), annotations: write },
170
+ { name: "ares_executor_inputs_hash", description: "Hash a pre-staged input directory on the configured local or SSH executor host. Returns only sha256, files and bytes; never copies input paths or bodies into the study. Read-only external host access, with no gate or ledger write.", inputSchema: obj({ study, path: text(4096) }, ["study", "path"]), annotations: { ...read, openWorldHint: true } },
111
171
  { name: "ares_executor_check", description: "Check executor Docker server, non-root uid:gid and digest-pinned image availability; pulls missing images.", inputSchema: obj({ study }, ["study"]), annotations: net },
112
- { name: "ares_attempt_run", description: "Start a frozen-commit experiment attempt and return without waiting for completion. Always detached; requires approved design in gates mode. Duplicate requests return the existing attempt.", inputSchema: obj({ study, repo: text(4096), commit: { type: "string", minLength: 40, maxLength: 40 }, seed, run, label: text(128), retry: attemptId }, ["study", "repo", "commit"]), annotations: net },
172
+ { name: "ares_attempt_run", description: "Start a frozen-commit experiment attempt and return without waiting for completion. Always detached; requires approved design in gates mode. Default reuse is off; eligible mode considers reviewed deterministic candidate artifacts in investigate only. forceFresh preserves the explicit retry path and never reuses evaluator/final metrics. Duplicate requests return the existing attempt. GPU admission can return status deferred with devices/load/probe reason and exitCode 75, without creating an attempt; no automatic retry.", inputSchema: obj({ study, repo: text(4096), commit: { type: "string", minLength: 40, maxLength: 40 }, seed, run, label: text(128), retry: attemptId, reuse: { type: "string", enum: ["off", "eligible"] }, forceFresh: { type: "boolean" } }, ["study", "repo", "commit"]), annotations: net },
113
173
  { name: "ares_attempt_list", description: "List bounded attempt summaries without protocol or artifact lists. Limit defaults to 50 (maximum 200), with offset pagination. Totals cover every whole-study status regardless of filters or page.", inputSchema: obj({ study, run, status: { type: "string", enum: ["running", "succeeded", "failed", "cancelled", "unknown"] }, limit: integer(1, 200), offset: integer(0, 1_000_000) }, ["study"]), annotations: read },
114
174
  { name: "ares_attempt_show", description: "Read an attempt record, its executor, stage receipts, metrics and artifact metadata. Logs remain on the executor.", inputSchema: obj({ study, id: attemptId }, ["study", "id"]), annotations: read },
115
175
  { name: "ares_attempt_cancel", description: "Stop the running stage and record cancelled; repeated cancellation preserves the terminal attempt.", inputSchema: obj({ study, id: attemptId, reason }, ["study", "id"]), annotations: net },
116
176
  { name: "ares_attempt_reconcile", description: "Observe recorded containers, advance candidate/evaluator stages and record terminal states. Lost containers become unknown; reconcile never starts a new attempt.", inputSchema: obj({ study }, ["study"]), annotations: net },
117
- { name: "ares_attempt_logs", description: "Retrieve executor log text read-only without recording content in the study. Optionally select stage/stream; tailBytes is 0..65536 per selected stream, default 16384. Copies are checked against recorded size and sha256.", inputSchema: obj({ study, id: attemptId, stage, stream, tailBytes: integer(0, 65_536) }, ["study", "id"]), annotations: { ...read, openWorldHint: true } },
118
- { name: "ares_lit_search", description: "Search OpenAlex, Semantic Scholar and arXiv and merge candidates. Needs the scope gate. Per-source failures are reported.", inputSchema: obj({ study, query: { type: "string", minLength: 1, maxLength: 500 }, source: { type: "string", enum: ["openalex", "s2", "arxiv", "all"] }, limit: { type: "integer", minimum: 1, maximum: 50 }, yearFrom: { type: "integer", minimum: 1000, maximum: 2100 } }, ["study", "query"]), annotations: net },
177
+ { name: "ares_attempt_logs", description: "Retrieve executor log text read-only without recording content in the study. Optionally select stage/stream and candidateStage (a declared v2 name, including completed candidates). tailBytes is 0..65536 per selected stream; default 16384 is reduced for aggregate tails above 256KiB. Copies are checked against recorded size and sha256.", inputSchema: obj({ study, id: attemptId, stage, candidateStage: text(32), stream, tailBytes: integer(0, 65_536) }, ["study", "id"]), annotations: { ...read, openWorldHint: true } },
178
+ { name: "ares_lit_search", description: "Search OpenAlex, Semantic Scholar and arXiv and merge candidates. Needs the scope gate. Per-source failures are reported.", inputSchema: obj({ study, query: { type: "string", minLength: 1, maxLength: 500 }, source: { type: "string", enum: ["openalex", "s2", "arxiv", "all"] }, limit: { type: "integer", minimum: 1, maximum: 50 }, yearFrom: { type: "integer", minimum: 1000, maximum: 2100 }, intent: { type: "string", enum: ["lexical", "semantic", "background"] } }, ["study", "query"]), annotations: net },
179
+ { name: "ares_lit_queries", description: "Read per-query yield: each lit.search with its intent (lexical, semantic, background or unspecified), sources, added/merged counts and how many candidates it first added are now included, excluded or new; per-intent summary and zero-included queries. Starts no network.", inputSchema: obj({ study }, ["study"]), annotations: read },
180
+ { name: "ares_lit_flow", description: "Read the selection flow derived from the ledger and candidates: search window, records per source, duplicates merged, unique, screened, excluded by code, unscreened, included, verified, with cards, and whether the screen gate is approved. format=markdown returns a table whose numbers are {{n:lit.flow.*}} placeholders. Starts no network.", inputSchema: obj({ study, format: { type: "string", enum: ["json", "markdown"] } }, ["study"]), annotations: read },
119
181
  { name: "ares_lit_list", description: "List candidates with abstracts (first 600 characters), status and verification.", inputSchema: obj({ study, status: { type: "string", enum: ["new", "included", "excluded"] }, limit: { type: "integer", minimum: 1, maximum: 500 } }, ["study"]), annotations: read },
120
- { name: "ares_lit_screen", description: "Include or exclude candidates. Changing the included set returns the screen gate to pending.", inputSchema: obj({ study, ids: { ...ids, minItems: 1 }, decision: { type: "string", enum: ["include", "exclude"] }, reason }, ["study", "ids", "decision"]), annotations: write },
182
+ { name: "ares_lit_screen", description: "Include or exclude candidates. Changing the included set returns the screen gate to pending.", inputSchema: obj({ study, ids: { ...ids, minItems: 1 }, decision: { type: "string", enum: ["include", "exclude"] }, reason, code: text(32) }, ["study", "ids", "decision"]), annotations: write },
121
183
  { name: "ares_lit_card", description: "Record an extraction card for an included candidate: summary, claims, methods, findings, limitations, relevance.", inputSchema: obj({ study, id, card: CARD }, ["study", "id", "card"]), annotations: write },
184
+ { name: "ares_lit_card_export", description: "Preview, then with the current fingerprint write each own card (identifier verified here) to the single vault-mem reference note with the same doi/arxiv_id, under an 'ares card' section with hashed-study provenance. Exported cards are a planning aid; nothing in the study changes besides a receipt event.", inputSchema: obj({ study, ids: { ...ids, minItems: 1, maxItems: 50 }, vault: text(64), modelFamily: text(48), confirm: { type: "string", minLength: 64, maxLength: 64 } }, ["study", "ids", "vault"]), annotations: net },
185
+ { name: "ares_lit_card_import", description: "Copy cards from vault-mem reference notes for included candidates whose identifier is verified in this study. Stored with reused provenance; never changes verification, screening, gates or the bibliography, and never counts as support evidence.", inputSchema: obj({ study, ids: { ...ids, minItems: 1, maxItems: 50 }, vault: text(64) }, ["study", "ids", "vault"]), annotations: net },
186
+ { name: "ares_lit_card_list", description: "List stored cards with their fields and, for reused cards, the vault note and provenance.", inputSchema: obj({ study }, ["study"]), annotations: read },
122
187
  { name: "ares_lit_verify", description: "Check DOI or arXiv identifiers at Crossref, DataCite or arXiv and compare title and year. Never judges whether a paper supports a claim.", inputSchema: obj({ study, ids }, ["study"]), annotations: net },
123
188
  { name: "ares_lit_bib", description: "Write refs/references.bib from included and verified candidates. Needs the screen gate. Citekeys never change once assigned.", inputSchema: obj({ study }, ["study"]), annotations: write },
124
189
  { name: "ares_review_add", description: "Record a bounded current-evidence-hash review with self-reported model family and checklist. Contradictions are always blocking; 100 reports per build, 200 findings per report, 4000-byte texts and a 60 KiB combined payload ceiling. Starts no build or controller.", inputSchema: obj({ study, review: REVIEW }, ["study", "review"]), annotations: write },
125
190
  { name: "ares_review_resolve", description: "Resolve a recorded review-id/finding-id with an explicit reason and actor. No votes or automatic contradiction resolution; historical reports stay in the ledger.", inputSchema: obj({ study, target: text(257), reason: text(4000) }, ["study", "target", "reason"]), annotations: write },
126
191
  { name: "ares_review_show", description: "Read current build/check readiness, review families, checklists and unresolved blocking findings. Claims readiness is unavailable (agent-hub#931) and nonblocking. Starts no network, build or controller.", inputSchema: obj({ study }, ["study"]), annotations: read },
127
- { name: "ares_paper_build", description: "Check the bounded manuscript and refuse every finding before writing. Commit rendered Markdown, a v1 evidence map with source hashes and paper.built together; identical inputs/outputs record nothing. Unknown evidence versions are preserved. The no-arg paper.build plan step emits the committed evidence {sha256} for downstream gates. Starts no controller, executor or network calls.", inputSchema: obj({ study }, ["study"]), annotations: write },
128
- { name: "ares_paper_check", description: "Read-only manuscript readiness check: positioned bare-number, placeholder, citation and missing-negative-result findings plus every literal escape. Experiment numbers require closed evidence; survey checks citations and refuses experiment refs. Reads bounded paper/manuscript.md, starts no build/controller/network calls.", inputSchema: obj({ study }, ["study"]), annotations: read },
192
+ { name: "ares_review_checklist", description: "List the six optional survey checklist keys with their questions, the same wording reviewers answer in checklist.survey. Answers are displayed and never gate. Opens no study.", inputSchema: obj({}, []), annotations: read },
193
+ { name: "ares_paper_plan_set", description: "Validate and atomically store a declared citation routing plan, at most 64 sections/300 keys per section and 64 KiB. Only current included, identifier-verified bibliography keys. Optional writing points (40 per section) require citation presence in their own anchor windows; claims/evidence never establish support. Points select stored v2; no points keep v1. No automatic routing or relevance judgment. Starts no build/controller/network calls.", inputSchema: obj({study, plan: PAPER_PLAN}, ["study", "plan"]), annotations: write },
194
+ { name: "ares_paper_plan_show", description: "Read the optional paper citation plan and routing coverage (included references routed/total). Revalidates current references; starts no build/controller/network calls or writes.", inputSchema: obj({study}, ["study"]), annotations: read },
195
+ { name: "ares_paper_build", description: "Check the bounded manuscript and refuse blocking findings before writing. Commit rendered Markdown, v1 evidence without a plan or v2 plan-bound evidence, and paper.built together; identical inputs/outputs record nothing. Unknown evidence versions are preserved. The no-arg paper.build plan step emits the committed evidence {sha256} for downstream gates. Starts no controller, executor or network calls.", inputSchema: obj({ study }, ["study"]), annotations: write },
196
+ { name: "ares_paper_check", description: "Read-only manuscript readiness check: positioned bare-number, placeholder, citation, optional paper-plan scope and missing-negative-result findings plus every literal escape. Experiment numbers require closed evidence; survey checks citations and refuses experiment refs. Reads bounded paper/manuscript.md, starts no build/controller/network calls.", inputSchema: obj({ study }, ["study"]), annotations: read },
129
197
  { name: "ares_cite_check", description: "Check [@key] citations in a draft against verified references; lists unknown and unverified keys.", inputSchema: obj({ study, draft: { type: "string", minLength: 1, maxLength: 4096 } }, ["study", "draft"]), annotations: read },
130
198
  { name: "ares_playbook", description: "Standalone literature, experiment and plan/conductor workflows, CLI-only controller startup, gate rules and evidence boundaries.", inputSchema: obj({}, []), annotations: read },
131
199
  ];
@@ -143,6 +211,24 @@ export function createAresMcp(env: NodeJS.ProcessEnv, http: Http = createHttp(en
143
211
  const background = new Map<Promise<void>, () => void>();
144
212
  const track = (completion: Promise<void>, terminate: () => void) => { background.set(completion, terminate); void completion.then(() => { background.delete(completion); }); };
145
213
  const handlers: Record<string, McpHandler> = {
214
+ ares_retention_inspect: a => ops.retentionInspect(dir(a), ctx, { ...(a.offset === undefined ? {} : { offset: a.offset as number }), ...(a.limit === undefined ? {} : { limit: a.limit as number }) }),
215
+ ares_retention_prune: a => ops.retentionPrune(dir(a), {refs: a.refs as RetainedRef[], ...(a.fingerprint === undefined ? {} : {fingerprint: a.fingerprint as string})}, ctx),
216
+ ares_lesson_propose: a => ops.lessonPropose(dir(a), a.proposal, ctx, env),
217
+ ares_lesson_list: a => ops.lessonList(dir(a)),
218
+ ares_lesson_check: a => ops.lessonCheck(dir(a), a.name as string, ctx, env),
219
+ ares_lesson_decide: a => ops.lessonDecide(dir(a), a.name as string, a.decision, ctx, env),
220
+ ares_skill_check: a => ops.skillCheck(dir(a), a.name as string, ctx, env),
221
+ ares_harness_close: a => ops.harnessClose(dir(a), a.round as string, a.closure, a.confirm as string | undefined, ctx),
222
+ ares_harness_contrast: a => ops.harnessContrast(dir(a), a.round as string, a.contrast, ctx),
223
+ ares_harness_compose: a => ops.harnessCompose(dir(a), a.round as string, a.composition, ctx),
224
+ ares_harness_adopt: a => ops.harnessAdopt(dir(a), a.round as string, a.decision, a.confirm as string | undefined, ctx),
225
+ ares_harness_stream_set: a => ops.harnessStreamSet(dir(a), a.stream, ctx),
226
+ ares_harness_stream_show: a => ops.harnessStreamShow(dir(a)),
227
+ ares_experience_select: a => ops.experienceSelect(dir(a), a.selection, ctx, env),
228
+ ares_experience_freeze: a => ops.experienceFreeze(dir(a), a.context, ctx, env),
229
+ ares_experience_check: a => ops.experienceCheck(dir(a), a.round as string, {model: a.model as string, runtime: a.runtime as string, ...(a.toolsetSha256 !== undefined ? {toolsetSha256: a.toolsetSha256 as string} : {})}, ctx, env),
230
+ ares_lineage_show: a => ops.lineageShow(dir(a), { ...(a.root === undefined ? {} : { root: a.root as ExecutionReferenceV1 }), ...(a.cursor === undefined ? {} : { cursor: a.cursor as string }) }),
231
+ ares_lineage_compare: a => ops.lineageCompare(dir(a), { ...(a.attempts === undefined ? {} : { attempts: a.attempts as string[] }), ...(a.candidates === undefined ? {} : { candidates: a.candidates as string[] }) }),
146
232
  ares_autonomy_show: a => ops.autonomyShow(dir(a)),
147
233
  ares_autonomy_set: a => ops.autonomySet(dir(a), a.mode as string, a.phase as string | undefined, ctx),
148
234
  ares_watch_set: a => ops.watchSet(dir(a), a.watch, ctx),
@@ -153,10 +239,10 @@ export function createAresMcp(env: NodeJS.ProcessEnv, http: Http = createHttp(en
153
239
  ares_console_list: () => ops.consoleList(env),
154
240
  ares_manifest: () => ops.manifest(),
155
241
  ares_setup: a => ops.setup(a.target as string, (a.mode ?? "dry-run") as SetupMode, env, { ...(a.root === undefined ? {} : { root: absolute(a.root, "root") }), ...(a.cwd === undefined ? {} : { cwd: absolute(a.cwd, "cwd") }) }),
156
- ares_archive: a => ops.archive(dir(a), { ...(a.confirm === undefined ? {} : { confirm: a.confirm as string }) }, ctx, memoryEnv),
242
+ ares_archive: a => ops.archive(dir(a), { ...(a.confirm === undefined ? {} : { confirm: a.confirm as string }) }, ctx, memoryEnv, undefined, {...runtime, env}),
157
243
  ares_lessons: a => ops.lessons(dir(a), { ...(a.for === undefined ? {} : { for: a.for as string }), ...(a.halfLife === undefined ? {} : { halfLife: a.halfLife as number }), ...(a.limit === undefined ? {} : { limit: a.limit as number }) }, ctx, memoryEnv),
158
- ares_skill_propose: a => ops.skillPropose(dir(a), a.proposal, ctx),
159
- ares_skill_decide: a => ops.skillDecide(dir(a), a.name as string, a.decision as string, a.reason as string, a.pr as string | undefined, ctx),
244
+ ares_skill_propose: a => ops.skillPropose(dir(a), a.proposal, ctx, env),
245
+ ares_skill_decide: a => ops.skillDecide(dir(a), a.name as string, a.decision as string, a.reason as string, a.pr as string | undefined, ctx, undefined, env),
160
246
  ares_skill_list: a => ops.skillList(dir(a)),
161
247
  ares_plan_set: a => ops.planSet(dir(a), a.plan, ctx),
162
248
  ares_plan_control: a => ops.planControl(dir(a), { action: a.action as Parameters<typeof ops.planControl>[1]["action"], commandId: a.commandId as string, expectedRevision: a.expectedRevision as number, ...(a.node !== undefined ? { node: a.node as string } : {}) }, ctx),
@@ -176,29 +262,41 @@ export function createAresMcp(env: NodeJS.ProcessEnv, http: Http = createHttp(en
176
262
  ares_final_seeds: a => ops.finalSeeds(dir(a), a.final, ctx),
177
263
  ares_selection_set: a => ops.selection(dir(a), a.selection, ctx),
178
264
  ares_protocol_set: a => ops.protocol(dir(a), a.protocol, ctx),
179
- ares_executor_set: a => ops.executorSet(dir(a), { v: 1, kind: a.kind, ...(a.host !== undefined ? { host: a.host } : {}), workdir: a.workdir }, ctx),
265
+ ares_harness_set: a => ops.harnessSet(dir(a), a.round, ctx),
266
+ ares_harness_show: a => ops.harnessShow(dir(a), a.round as string | undefined),
267
+ ares_harness_import: a => ops.harnessImport(dir(a), a.round as string, a.fixture, ctx),
268
+ ares_executor_set: a => ops.executorSet(dir(a), { v: 1, kind: a.kind, ...(a.host !== undefined ? { host: a.host } : {}), workdir: a.workdir, ...(a.retentionCapBytes !== undefined ? { retentionCapBytes: a.retentionCapBytes } : {}), ...(a.gpu !== undefined ? { gpu: a.gpu } : {}) }, ctx),
269
+ ares_executor_inputs_hash: a => ops.executorInputsHash(dir(a), a.path as string, ctx),
180
270
  ares_executor_check: a => ops.executorCheck(dir(a), ctx),
181
- ares_attempt_run: a => ops.attemptRun(dir(a), { repo: absolute(a.repo, "repo"), commit: a.commit as string, ...(a.seed !== undefined ? { seed: a.seed as number } : {}), ...(a.run !== undefined ? { run: a.run as string } : {}), ...(a.label !== undefined ? { label: a.label as string } : {}), ...(a.retry !== undefined ? { retry: a.retry as string } : {}), detach: true }, ctx),
271
+ ares_attempt_run: a => ops.attemptRun(dir(a), { repo: absolute(a.repo, "repo"), commit: a.commit as string, ...(a.seed !== undefined ? { seed: a.seed as number } : {}), ...(a.run !== undefined ? { run: a.run as string } : {}), ...(a.label !== undefined ? { label: a.label as string } : {}), ...(a.retry !== undefined ? { retry: a.retry as string } : {}), ...(a.reuse !== undefined ? { reuse: a.reuse as "off" | "eligible" } : {}), ...(a.forceFresh !== undefined ? { forceFresh: a.forceFresh as boolean } : {}), detach: true }, ctx),
182
272
  ares_attempt_list: a => ops.attemptList(dir(a), { ...(a.run !== undefined ? { run: a.run as string } : {}), ...(a.status !== undefined ? { status: a.status as string } : {}), ...(a.limit !== undefined ? { limit: a.limit as number } : {}), ...(a.offset !== undefined ? { offset: a.offset as number } : {}) }),
183
273
  ares_attempt_show: a => ops.attemptShow(dir(a), a.id as string),
184
274
  ares_attempt_cancel: a => ops.attemptCancel(dir(a), a.id as string, a.reason as string | undefined, ctx),
185
275
  ares_attempt_reconcile: a => ops.attemptReconcile(dir(a), ctx),
186
- ares_attempt_logs: a => ops.attemptLogs(dir(a), a.id as string, { ...(a.stage !== undefined ? { stage: a.stage as "candidate" | "evaluator" } : {}), ...(a.stream !== undefined ? { stream: a.stream as "stdout" | "stderr" } : {}), ...(a.tailBytes !== undefined ? { tailBytes: a.tailBytes as number } : {}) }, ctx),
276
+ ares_attempt_logs: a => ops.attemptLogs(dir(a), a.id as string, { ...(a.stage !== undefined ? { stage: a.stage as "candidate" | "evaluator" } : {}), ...(a.candidateStage !== undefined ? { candidateStage: a.candidateStage as string } : {}), ...(a.stream !== undefined ? { stream: a.stream as "stdout" | "stderr" } : {}), ...(a.tailBytes !== undefined ? { tailBytes: a.tailBytes as number } : {}) }, ctx),
187
277
  ares_gate: a => {
188
278
  if (a.action === "list") return ops.gateList(dir(a));
189
279
  if (typeof a.gate !== "string") throw new Error("gate: required for approve and reject");
190
280
  return ops.gateDecide(dir(a), a.gate, a.action === "approve" ? "approve" : "reject", a.reason as string | undefined, ctx);
191
281
  },
192
- ares_lit_search: a => ops.search(dir(a), a.query as string, { ...(a.source ? { source: a.source as string } : {}), ...(a.limit ? { limit: a.limit as number } : {}), ...(a.yearFrom ? { yearFrom: a.yearFrom as number } : {}) }, ctx),
282
+ ares_lit_search: a => ops.search(dir(a), a.query as string, { ...(a.source ? { source: a.source as string } : {}), ...(a.limit ? { limit: a.limit as number } : {}), ...(a.yearFrom ? { yearFrom: a.yearFrom as number } : {}), ...(a.intent ? { intent: a.intent as string } : {}) }, ctx),
283
+ ares_lit_queries: a => ops.queries(dir(a)),
284
+ ares_lit_flow: a => ops.flow(dir(a), a.format === "markdown" ? "markdown" : "json"),
193
285
  ares_lit_list: a => ops.list(dir(a), { ...(a.status ? { status: a.status as string } : {}), ...(a.limit ? { limit: a.limit as number } : {}) }),
194
- ares_lit_screen: a => ops.screen(dir(a), a.ids as string[], a.decision as "include" | "exclude", a.reason as string | undefined, ctx),
286
+ ares_lit_screen: a => ops.screen(dir(a), a.ids as string[], a.decision as "include" | "exclude", a.reason as string | undefined, ctx, undefined, a.code as string | undefined),
195
287
  ares_lit_card: a => ops.card(dir(a), a.id as string, a.card, ctx),
288
+ ares_lit_card_export: a => ops.cardExport(dir(a), a.ids as string[], { vault: a.vault as string, ...(a.confirm !== undefined ? { confirm: a.confirm as string } : {}), ...(a.modelFamily !== undefined ? { modelFamily: a.modelFamily as string } : {}) }, ctx, env),
289
+ ares_lit_card_import: a => ops.cardImport(dir(a), a.ids as string[], { vault: a.vault as string }, ctx, env),
290
+ ares_lit_card_list: a => ops.cardList(dir(a)),
196
291
  ares_lit_verify: a => ops.verify(dir(a), (a.ids as string[] | undefined) ?? [], ctx),
197
292
  ares_lit_bib: a => ops.bib(dir(a), ctx),
198
293
  ares_review_add: a => ops.reviewAdd(dir(a), a.review, ctx),
199
294
  ares_review_resolve: a => ops.reviewResolve(dir(a), a.target as string, a.reason as string, ctx),
200
295
  ares_review_show: a => ops.reviewShow(dir(a)),
296
+ ares_review_checklist: () => ops.reviewChecklistShow(),
201
297
  ares_paper_build: a => ops.paperBuild(dir(a), ctx),
298
+ ares_paper_plan_set: a => ops.paperPlanSet(dir(a), a.plan, ctx),
299
+ ares_paper_plan_show: a => ops.paperPlanShow(dir(a)),
202
300
  ares_paper_check: a => ops.paperCheck(dir(a)),
203
301
  ares_cite_check: a => ops.cite(dir(a), absolute(a.draft, "draft")),
204
302
  ares_playbook: () => ({ playbook: PLAYBOOK }),
package/src/mcp.ts CHANGED
@@ -14,6 +14,10 @@ const plain = (v: unknown): v is Record<string, unknown> => !!v && typeof v ===
14
14
  export function validArguments(value: unknown, raw: unknown): boolean {
15
15
  // An empty JSON schema delegates a frame-bounded field (watch version) to the shared validator.
16
16
  if (plain(raw) && Object.keys(raw).length === 0) return true;
17
+ if (plain(raw) && Object.hasOwn(raw, "oneOf")) {
18
+ if (Object.keys(raw).length !== 1 || !Array.isArray(raw.oneOf) || !raw.oneOf.length || raw.oneOf.length > 16 || raw.oneOf.some(branch => !plain(branch))) return false;
19
+ return raw.oneOf.filter(branch => validArguments(value, branch)).length === 1;
20
+ }
17
21
  const s = raw as Record<string, any>, type = value === null ? "null" : Array.isArray(value) ? "array" : typeof value;
18
22
  const types: unknown[] = Array.isArray(s.type) ? s.type : [s.type];
19
23
  if (!types.includes(type) && !(type === "number" && Number.isSafeInteger(value) && types.includes("integer"))) return false;