@tiangong-ai/cli 0.0.61 → 0.0.63
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/AGENTS.md +17 -6
- package/CONTRIBUTING.md +5 -5
- package/README.md +417 -36
- package/dist/cli.js +2 -2
- package/dist/data/builtins.js +33 -5
- package/dist/data/builtins.js.map +1 -1
- package/dist/data/catalog.js +46 -0
- package/dist/data/catalog.js.map +1 -1
- package/dist/data/commands.js +15 -1
- package/dist/data/commands.js.map +1 -1
- package/dist/data/connectors/airnow-hourly-observations.js +60 -10
- package/dist/data/connectors/airnow-hourly-observations.js.map +1 -1
- package/dist/data/connectors/epa-eis-records.js +16 -2
- package/dist/data/connectors/epa-eis-records.js.map +1 -1
- package/dist/data/connectors/gdelt-doc-search.js +54 -18
- package/dist/data/connectors/gdelt-doc-search.js.map +1 -1
- package/dist/data/connectors/gdelt-file-feeds.js +20 -11
- package/dist/data/connectors/gdelt-file-feeds.js.map +1 -1
- package/dist/data/connectors/gdelt-web-ngrams.d.ts +2 -0
- package/dist/data/connectors/gdelt-web-ngrams.js +350 -0
- package/dist/data/connectors/gdelt-web-ngrams.js.map +1 -0
- package/dist/data/connectors/gdelt-web-ngrams.schemas.d.ts +188 -0
- package/dist/data/connectors/gdelt-web-ngrams.schemas.js +138 -0
- package/dist/data/connectors/gdelt-web-ngrams.schemas.js.map +1 -0
- package/dist/data/connectors/nasa-firms-fire.js +4 -0
- package/dist/data/connectors/nasa-firms-fire.js.map +1 -1
- package/dist/data/connectors/open-meteo-air-quality.js +27 -22
- package/dist/data/connectors/open-meteo-air-quality.js.map +1 -1
- package/dist/data/connectors/open-meteo-air-quality.schemas.d.ts +4 -1
- package/dist/data/connectors/open-meteo-air-quality.schemas.js +21 -1
- package/dist/data/connectors/open-meteo-air-quality.schemas.js.map +1 -1
- package/dist/data/connectors/open-meteo-flood.js +28 -23
- package/dist/data/connectors/open-meteo-flood.js.map +1 -1
- package/dist/data/connectors/open-meteo-flood.schemas.d.ts +4 -1
- package/dist/data/connectors/open-meteo-flood.schemas.js +21 -1
- package/dist/data/connectors/open-meteo-flood.schemas.js.map +1 -1
- package/dist/data/connectors/open-meteo-historical-weather.js +26 -21
- package/dist/data/connectors/open-meteo-historical-weather.js.map +1 -1
- package/dist/data/connectors/open-meteo-historical-weather.schemas.d.ts +4 -1
- package/dist/data/connectors/open-meteo-historical-weather.schemas.js +21 -1
- package/dist/data/connectors/open-meteo-historical-weather.schemas.js.map +1 -1
- package/dist/data/connectors/openaq-air-quality.js +50 -12
- package/dist/data/connectors/openaq-air-quality.js.map +1 -1
- package/dist/data/connectors/openaq-air-quality.schemas.d.ts +0 -4
- package/dist/data/connectors/openaq-air-quality.schemas.js +2 -2
- package/dist/data/connectors/openaq-air-quality.schemas.js.map +1 -1
- package/dist/data/connectors/youtube-public-content.js +76 -6
- package/dist/data/connectors/youtube-public-content.js.map +1 -1
- package/dist/data/connectors/youtube-public-content.schemas.d.ts +63 -3
- package/dist/data/connectors/youtube-public-content.schemas.js +56 -2
- package/dist/data/connectors/youtube-public-content.schemas.js.map +1 -1
- package/dist/data/contracts.d.ts +22 -1
- package/dist/data/runtime/bounded-http.d.ts +2 -0
- package/dist/data/runtime/bounded-http.js +221 -59
- package/dist/data/runtime/bounded-http.js.map +1 -1
- package/dist/data/runtime/execute.d.ts +2 -0
- package/dist/data/runtime/execute.js +82 -60
- package/dist/data/runtime/execute.js.map +1 -1
- package/dist/data/runtime/http-timing.d.ts +15 -0
- package/dist/data/runtime/http-timing.js +59 -0
- package/dist/data/runtime/http-timing.js.map +1 -0
- package/dist/data/runtime/http-transport.d.ts +1 -0
- package/dist/data/runtime/http-transport.js +27 -0
- package/dist/data/runtime/http-transport.js.map +1 -0
- package/dist/data/schemas/catalog.v1.json +46 -0
- package/dist/data/schemas/discovery.v1.json +12 -0
- package/dist/data/schemas/error.v1.json +1 -0
- package/dist/data/schemas/manifest.v1.json +19 -1
- package/dist/research/orchestration.js +233 -10
- package/dist/research/orchestration.js.map +1 -1
- package/dist/research/setup-command.js +37 -6
- package/dist/research/setup-command.js.map +1 -1
- package/dist/research/workspace/audit-bundle.js +28 -8
- package/dist/research/workspace/audit-bundle.js.map +1 -1
- package/dist/research/workspace/broker.js +25 -4
- package/dist/research/workspace/broker.js.map +1 -1
- package/dist/research/workspace/constants.d.ts +1 -0
- package/dist/research/workspace/constants.js +1 -0
- package/dist/research/workspace/constants.js.map +1 -1
- package/dist/research/workspace/content-evidence.d.ts +1 -0
- package/dist/research/workspace/content-evidence.js +1 -1
- package/dist/research/workspace/content-evidence.js.map +1 -1
- package/dist/research/workspace/credentials.js +2 -1
- package/dist/research/workspace/credentials.js.map +1 -1
- package/dist/research/workspace/data-evidence-adapter.d.ts +71 -0
- package/dist/research/workspace/data-evidence-adapter.js +269 -59
- package/dist/research/workspace/data-evidence-adapter.js.map +1 -1
- package/dist/research/workspace/data-evidence-view.d.ts +58 -0
- package/dist/research/workspace/data-evidence-view.js +411 -0
- package/dist/research/workspace/data-evidence-view.js.map +1 -0
- package/dist/research/workspace/evidence-ledger.js +32 -29
- package/dist/research/workspace/evidence-ledger.js.map +1 -1
- package/dist/research/workspace/evidence.d.ts +28 -0
- package/dist/research/workspace/evidence.js +48 -0
- package/dist/research/workspace/evidence.js.map +1 -1
- package/dist/research/workspace/executor.d.ts +27 -1
- package/dist/research/workspace/executor.js +180 -20
- package/dist/research/workspace/executor.js.map +1 -1
- package/dist/research/workspace/external-skills.d.ts +1 -0
- package/dist/research/workspace/external-skills.js +4 -2
- package/dist/research/workspace/external-skills.js.map +1 -1
- package/dist/research/workspace/investigation-attempt.d.ts +159 -0
- package/dist/research/workspace/investigation-attempt.js +619 -0
- package/dist/research/workspace/investigation-attempt.js.map +1 -0
- package/dist/research/workspace/investigation-audit.d.ts +20 -0
- package/dist/research/workspace/investigation-audit.js +306 -0
- package/dist/research/workspace/investigation-audit.js.map +1 -0
- package/dist/research/workspace/investigation-candidate.d.ts +84 -0
- package/dist/research/workspace/investigation-candidate.js +156 -0
- package/dist/research/workspace/investigation-candidate.js.map +1 -0
- package/dist/research/workspace/investigation-certification.d.ts +39 -0
- package/dist/research/workspace/investigation-certification.js +152 -0
- package/dist/research/workspace/investigation-certification.js.map +1 -0
- package/dist/research/workspace/investigation-close.d.ts +47 -0
- package/dist/research/workspace/investigation-close.js +153 -0
- package/dist/research/workspace/investigation-close.js.map +1 -0
- package/dist/research/workspace/investigation-lineage.d.ts +8 -0
- package/dist/research/workspace/investigation-lineage.js +10 -0
- package/dist/research/workspace/investigation-lineage.js.map +1 -0
- package/dist/research/workspace/investigation-observer.d.ts +22 -0
- package/dist/research/workspace/investigation-observer.js +122 -0
- package/dist/research/workspace/investigation-observer.js.map +1 -0
- package/dist/research/workspace/investigation-promotion.d.ts +129 -0
- package/dist/research/workspace/investigation-promotion.js +316 -0
- package/dist/research/workspace/investigation-promotion.js.map +1 -0
- package/dist/research/workspace/investigation-requirements.d.ts +5 -0
- package/dist/research/workspace/investigation-requirements.js +32 -0
- package/dist/research/workspace/investigation-requirements.js.map +1 -0
- package/dist/research/workspace/investigation-resources.d.ts +12 -0
- package/dist/research/workspace/investigation-resources.js +78 -0
- package/dist/research/workspace/investigation-resources.js.map +1 -0
- package/dist/research/workspace/investigation-source-export.d.ts +6 -0
- package/dist/research/workspace/investigation-source-export.js +68 -0
- package/dist/research/workspace/investigation-source-export.js.map +1 -0
- package/dist/research/workspace/investigation-store.d.ts +9 -0
- package/dist/research/workspace/investigation-store.js +55 -0
- package/dist/research/workspace/investigation-store.js.map +1 -0
- package/dist/research/workspace/investigation.d.ts +424 -0
- package/dist/research/workspace/investigation.js +716 -0
- package/dist/research/workspace/investigation.js.map +1 -0
- package/dist/research/workspace/native-process-supervisor.d.ts +1 -0
- package/dist/research/workspace/native-process-supervisor.js +97 -0
- package/dist/research/workspace/native-process-supervisor.js.map +1 -0
- package/dist/research/workspace/native-run.d.ts +79 -6
- package/dist/research/workspace/native-run.js +293 -51
- package/dist/research/workspace/native-run.js.map +1 -1
- package/dist/research/workspace/preflight.d.ts +3 -0
- package/dist/research/workspace/preflight.js +11 -6
- package/dist/research/workspace/preflight.js.map +1 -1
- package/dist/research/workspace/project-authority.js +2 -0
- package/dist/research/workspace/project-authority.js.map +1 -1
- package/dist/research/workspace/project-budget.d.ts +41 -0
- package/dist/research/workspace/project-budget.js +265 -0
- package/dist/research/workspace/project-budget.js.map +1 -0
- package/dist/research/workspace/project-mutations.d.ts +1 -1
- package/dist/research/workspace/project-mutations.js +27 -3
- package/dist/research/workspace/project-mutations.js.map +1 -1
- package/dist/research/workspace/projects.d.ts +66 -0
- package/dist/research/workspace/projects.js +181 -3
- package/dist/research/workspace/projects.js.map +1 -1
- package/dist/research/workspace/provider-budget.d.ts +3 -0
- package/dist/research/workspace/provider-budget.js +45 -0
- package/dist/research/workspace/provider-budget.js.map +1 -0
- package/dist/research/workspace/provider-state.d.ts +1 -0
- package/dist/research/workspace/provider-state.js +20 -0
- package/dist/research/workspace/provider-state.js.map +1 -0
- package/dist/research/workspace/publication-lineage.d.ts +34 -0
- package/dist/research/workspace/publication-lineage.js +165 -0
- package/dist/research/workspace/publication-lineage.js.map +1 -0
- package/dist/research/workspace/publication-workflow.d.ts +24 -0
- package/dist/research/workspace/publication-workflow.js +118 -14
- package/dist/research/workspace/publication-workflow.js.map +1 -1
- package/dist/research/workspace/review-executor.d.ts +6 -1
- package/dist/research/workspace/review-executor.js +17 -3
- package/dist/research/workspace/review-executor.js.map +1 -1
- package/dist/research/workspace/runtime.d.ts +12 -1
- package/dist/research/workspace/runtime.js +143 -19
- package/dist/research/workspace/runtime.js.map +1 -1
- package/dist/research/workspace/scientific-amendment.d.ts +103 -0
- package/dist/research/workspace/scientific-amendment.js +537 -0
- package/dist/research/workspace/scientific-amendment.js.map +1 -0
- package/dist/research/workspace/scientific-fulfillment-audit.d.ts +20 -2
- package/dist/research/workspace/scientific-fulfillment-audit.js +87 -7
- package/dist/research/workspace/scientific-fulfillment-audit.js.map +1 -1
- package/dist/research/workspace/scientific-fulfillment.d.ts +10 -1
- package/dist/research/workspace/scientific-fulfillment.js +20 -6
- package/dist/research/workspace/scientific-fulfillment.js.map +1 -1
- package/dist/research/workspace/scientific-review-execution.js +162 -22
- package/dist/research/workspace/scientific-review-execution.js.map +1 -1
- package/dist/research/workspace/scientific-review.d.ts +2 -1
- package/dist/research/workspace/scientific-review.js +33 -2
- package/dist/research/workspace/scientific-review.js.map +1 -1
- package/dist/research/workspace/setup-catalog.js +13 -13
- package/dist/research/workspace/setup-catalog.js.map +1 -1
- package/dist/research/workspace/setup-release.d.ts +22 -0
- package/dist/research/workspace/setup-release.js +426 -0
- package/dist/research/workspace/setup-release.js.map +1 -0
- package/dist/research/workspace/setup-runtime-integrity.d.ts +2 -0
- package/dist/research/workspace/setup-runtime-integrity.js +31 -0
- package/dist/research/workspace/setup-runtime-integrity.js.map +1 -0
- package/dist/research/workspace/setup-upgrade.d.ts +17 -0
- package/dist/research/workspace/setup-upgrade.js +784 -0
- package/dist/research/workspace/setup-upgrade.js.map +1 -0
- package/dist/research/workspace/setup.d.ts +31 -39
- package/dist/research/workspace/setup.js +228 -19
- package/dist/research/workspace/setup.js.map +1 -1
- package/dist/research/workspace/task-acceptance.d.ts +8 -1
- package/dist/research/workspace/task-acceptance.js +37 -5
- package/dist/research/workspace/task-acceptance.js.map +1 -1
- package/dist/research/workspace/task-audit.d.ts +5 -1
- package/dist/research/workspace/task-audit.js +33 -18
- package/dist/research/workspace/task-audit.js.map +1 -1
- package/dist/research/workspace/types.d.ts +44 -0
- package/dist/research/workspace/workspace.js +34 -4
- package/dist/research/workspace/workspace.js.map +1 -1
- package/package.json +5 -4
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { localInvestigationReadStore } from "./investigation-store.js";
|
|
2
|
+
import { Ajv2020 } from "ajv/dist/2020.js";
|
|
3
|
+
import { CliError } from "../../errors.js";
|
|
4
|
+
import { loadInvestigation } from "./investigation.js";
|
|
5
|
+
import { assertInvestigationCurrent, investigationAttemptHistory, } from "./investigation-attempt.js";
|
|
6
|
+
import { appendJournalEvent, readVerifiedJournal } from "./journal.js";
|
|
7
|
+
import { loadProject } from "./projects.js";
|
|
8
|
+
import { configuredResearchSecrets, sanitizeResearchValue } from "./sanitization.js";
|
|
9
|
+
import { canonicalJson, sha256Text, workspacePaths } from "./storage.js";
|
|
10
|
+
import { writeTaskObject } from "./task-contract.js";
|
|
11
|
+
import { withWorkspaceLock } from "./workspace.js";
|
|
12
|
+
const id = { type: "string", pattern: "^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$" };
|
|
13
|
+
const schema = {
|
|
14
|
+
type: "object",
|
|
15
|
+
additionalProperties: false,
|
|
16
|
+
required: ["schemaVersion", "selectionId", "investigationId", "attemptId", "reason"],
|
|
17
|
+
properties: {
|
|
18
|
+
schemaVersion: { const: 1 },
|
|
19
|
+
selectionId: id,
|
|
20
|
+
investigationId: id,
|
|
21
|
+
attemptId: id,
|
|
22
|
+
reason: { type: "string", minLength: 8, maxLength: 4000 },
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
const validate = new Ajv2020({ strict: false, allErrors: true }).compile(schema);
|
|
26
|
+
export function investigationCandidateInputSchema() {
|
|
27
|
+
return structuredClone(schema);
|
|
28
|
+
}
|
|
29
|
+
function failure(message) {
|
|
30
|
+
return new CliError(message, { code: "RESEARCH_INVESTIGATION_CANDIDATE_INVALID", exitCode: 3 });
|
|
31
|
+
}
|
|
32
|
+
function recipeFor(definition, attempt) {
|
|
33
|
+
const run = attempt.record;
|
|
34
|
+
const program = definition.plan.programs.find((p) => p.id === run?.programId);
|
|
35
|
+
const files = definition.programs.find((p) => p.id === run?.programId);
|
|
36
|
+
if (!run ||
|
|
37
|
+
!program ||
|
|
38
|
+
!files ||
|
|
39
|
+
["stale", "inputs-changed"].includes(run.outcome) ||
|
|
40
|
+
run.runtime.binarySha256 !== program.runtime.binarySha256 ||
|
|
41
|
+
run.runtime.kind !== program.runtime.kind ||
|
|
42
|
+
!(run.runtime.kind === "node" ? /^v\d+\.\d+\.\d+$/u : /^Python \d+\.\d+\.\d+$/u).test(run.runtime.version))
|
|
43
|
+
throw failure("Select one committed, stable diagnostic attempt with its observed runtime identity.");
|
|
44
|
+
return {
|
|
45
|
+
programId: program.id,
|
|
46
|
+
runtime: run.runtime,
|
|
47
|
+
script: files.script,
|
|
48
|
+
environmentLock: files.environmentLock,
|
|
49
|
+
inputs: attempt.start.inputs,
|
|
50
|
+
configuration: run.configuration,
|
|
51
|
+
arguments: program.arguments.map((arg) => arg.replace(/\{option:([^}]+)\}/gu, (_match, key) => String(run.configuration[key]))),
|
|
52
|
+
outputs: program.outputs,
|
|
53
|
+
diagnosticOutputId: program.diagnosticOutputId,
|
|
54
|
+
telemetry: program.telemetry,
|
|
55
|
+
maxOutputBytes: definition.plan.limits.maxOutputBytes,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export async function loadInvestigationCandidates(root, projectId, definition, events, attempts, store = localInvestigationReadStore(root)) {
|
|
59
|
+
const selected = events.filter((e) => e.scope === projectId &&
|
|
60
|
+
e.type === "investigation.candidate.selected" &&
|
|
61
|
+
e.payload.investigationId === definition.investigationId);
|
|
62
|
+
const records = [];
|
|
63
|
+
const ids = new Set();
|
|
64
|
+
for (const event of selected) {
|
|
65
|
+
const record = await store.readTask(projectId, "investigation-candidates", String(event.payload.recordSha256), "recordSha256");
|
|
66
|
+
const input = {
|
|
67
|
+
schemaVersion: record.schemaVersion,
|
|
68
|
+
selectionId: record.selectionId,
|
|
69
|
+
investigationId: record.investigationId,
|
|
70
|
+
attemptId: record.attemptId,
|
|
71
|
+
reason: record.reason,
|
|
72
|
+
};
|
|
73
|
+
const attempt = attempts.find((a) => a.record?.recordSha256 === record.attemptSha256 && a.start.attemptId === record.attemptId);
|
|
74
|
+
const completed = events.find((e) => e.scope === projectId &&
|
|
75
|
+
e.type === "investigation.attempt.completed" &&
|
|
76
|
+
e.payload.recordSha256 === record.attemptSha256);
|
|
77
|
+
if (!validate(input) ||
|
|
78
|
+
!attempt ||
|
|
79
|
+
!completed ||
|
|
80
|
+
completed.sequence >= event.sequence ||
|
|
81
|
+
record.kind !== "tiangong-investigation-candidate" ||
|
|
82
|
+
record.projectId !== projectId ||
|
|
83
|
+
record.investigationId !== definition.investigationId ||
|
|
84
|
+
record.definitionSha256 !== definition.recordSha256 ||
|
|
85
|
+
record.parentCandidateSha256 !== (records.at(-1)?.recordSha256 ?? null) ||
|
|
86
|
+
ids.has(record.selectionId) ||
|
|
87
|
+
record.selectionId !== event.payload.selectionId ||
|
|
88
|
+
record.attemptSha256 !== event.payload.attemptSha256 ||
|
|
89
|
+
record.recipeSha256 !== event.payload.recipeSha256 ||
|
|
90
|
+
record.purpose !== "diagnostic-candidate-only" ||
|
|
91
|
+
record.requestSha256 !== sha256Text(canonicalJson(input)))
|
|
92
|
+
throw failure("Candidate selection does not match its committed investigation history.");
|
|
93
|
+
const recipe = recipeFor(definition, attempt);
|
|
94
|
+
if (canonicalJson(recipe) !== canonicalJson(record.recipe) ||
|
|
95
|
+
sha256Text(canonicalJson(recipe)) !== record.recipeSha256)
|
|
96
|
+
throw failure("Candidate recipe differs from the exact observed attempt.");
|
|
97
|
+
ids.add(record.selectionId);
|
|
98
|
+
records.push(record);
|
|
99
|
+
}
|
|
100
|
+
return records;
|
|
101
|
+
}
|
|
102
|
+
export async function selectInvestigationCandidate(root, projectId, value) {
|
|
103
|
+
if (!validate(value) ||
|
|
104
|
+
canonicalJson(sanitizeResearchValue(value, configuredResearchSecrets(process.env))) !==
|
|
105
|
+
canonicalJson(value))
|
|
106
|
+
throw failure("Candidate selection must match the closed non-secret schema.");
|
|
107
|
+
const input = value;
|
|
108
|
+
const requestSha256 = sha256Text(canonicalJson(input));
|
|
109
|
+
return withWorkspaceLock(root, "research.investigation.select", async () => {
|
|
110
|
+
const project = await loadProject(root, projectId);
|
|
111
|
+
const events = await readVerifiedJournal(workspacePaths(root).journal);
|
|
112
|
+
const definition = await loadInvestigation(root, projectId, input.investigationId, events);
|
|
113
|
+
const attempts = await investigationAttemptHistory(root, projectId, definition, events);
|
|
114
|
+
const candidates = await loadInvestigationCandidates(root, projectId, definition, events, attempts);
|
|
115
|
+
const known = candidates.find((c) => c.selectionId === input.selectionId);
|
|
116
|
+
if (known) {
|
|
117
|
+
if (known.requestSha256 !== requestSha256)
|
|
118
|
+
throw failure("Selection ID already belongs to another exact request.");
|
|
119
|
+
return known;
|
|
120
|
+
}
|
|
121
|
+
await assertInvestigationCurrent(root, project, definition, events);
|
|
122
|
+
if (attempts.some((a) => !a.record))
|
|
123
|
+
throw failure("Resolve the unfinished attempt before choosing a candidate.");
|
|
124
|
+
const attempt = attempts.find((a) => a.start.attemptId === input.attemptId);
|
|
125
|
+
if (!attempt?.record)
|
|
126
|
+
throw failure("Candidate selection needs an exact committed attempt.");
|
|
127
|
+
const recipe = recipeFor(definition, attempt);
|
|
128
|
+
const core = {
|
|
129
|
+
...input,
|
|
130
|
+
kind: "tiangong-investigation-candidate",
|
|
131
|
+
projectId,
|
|
132
|
+
definitionSha256: definition.recordSha256,
|
|
133
|
+
attemptSha256: attempt.record.recordSha256,
|
|
134
|
+
parentCandidateSha256: candidates.at(-1)?.recordSha256 ?? null,
|
|
135
|
+
requestSha256,
|
|
136
|
+
recipe,
|
|
137
|
+
recipeSha256: sha256Text(canonicalJson(recipe)),
|
|
138
|
+
purpose: "diagnostic-candidate-only",
|
|
139
|
+
selectedAt: new Date().toISOString(),
|
|
140
|
+
};
|
|
141
|
+
const record = {
|
|
142
|
+
...core,
|
|
143
|
+
recordSha256: sha256Text(canonicalJson(core)),
|
|
144
|
+
};
|
|
145
|
+
await writeTaskObject(root, projectId, "investigation-candidates", record.recordSha256, record);
|
|
146
|
+
await appendJournalEvent(workspacePaths(root).journal, "investigation.candidate.selected", projectId, {
|
|
147
|
+
investigationId: input.investigationId,
|
|
148
|
+
selectionId: input.selectionId,
|
|
149
|
+
recordSha256: record.recordSha256,
|
|
150
|
+
attemptSha256: record.attemptSha256,
|
|
151
|
+
recipeSha256: record.recipeSha256,
|
|
152
|
+
});
|
|
153
|
+
return record;
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=investigation-candidate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"investigation-candidate.js","sourceRoot":"","sources":["../../../src/research/workspace/investigation-candidate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAA+B,MAAM,0BAA0B,CAAC;AACpG,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAgC,MAAM,oBAAoB,CAAC;AACrF,OAAO,EACL,0BAA0B,EAC1B,2BAA2B,GAC5B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AACrF,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AASnD,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,oCAAoC,EAAE,CAAC;AAC7E,MAAM,MAAM,GAAG;IACb,IAAI,EAAE,QAAQ;IACd,oBAAoB,EAAE,KAAK;IAC3B,QAAQ,EAAE,CAAC,eAAe,EAAE,aAAa,EAAE,iBAAiB,EAAE,WAAW,EAAE,QAAQ,CAAC;IACpF,UAAU,EAAE;QACV,aAAa,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE;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,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { parseInvestigationDiagnostic } from "./investigation-attempt.js";
|
|
2
|
+
import { type InvestigationPromotion } from "./investigation-promotion.js";
|
|
3
|
+
import type { NativeRunInput, NativeRunRecord, captureProcess } from "./native-run.js";
|
|
4
|
+
import type { JournalEvent, ProjectState } from "./types.js";
|
|
5
|
+
export declare function assertInvestigationCertificationRequired(root: string, projectId: string, input: NativeRunInput, events: JournalEvent[]): Promise<void>;
|
|
6
|
+
export declare function frozenPromotionView(root: string, project: ProjectState, promotion: InvestigationPromotion, events: JournalEvent[]): Promise<string>;
|
|
7
|
+
export declare function prepareInvestigationCertification(root: string, project: ProjectState, input: NativeRunInput, binarySha256: string, events: JournalEvent[]): Promise<{
|
|
8
|
+
promotion: InvestigationPromotion;
|
|
9
|
+
effectiveDesignSha256: string;
|
|
10
|
+
} | null>;
|
|
11
|
+
type ProcessObservation = Awaited<ReturnType<typeof captureProcess>>;
|
|
12
|
+
export interface InvestigationCertification {
|
|
13
|
+
promotionSha256: string;
|
|
14
|
+
candidateSha256: string;
|
|
15
|
+
recipeSha256: string;
|
|
16
|
+
effectiveDesignSha256: string;
|
|
17
|
+
status: "passed" | "failed";
|
|
18
|
+
diagnostic: ReturnType<typeof parseInvestigationDiagnostic>;
|
|
19
|
+
missingTelemetry: string[];
|
|
20
|
+
actualCostUsd: null;
|
|
21
|
+
accountedCostUpperBoundUsd: number;
|
|
22
|
+
maxOutputBytes: number;
|
|
23
|
+
observedOutputBytes: number;
|
|
24
|
+
outputLimitExceeded: boolean;
|
|
25
|
+
isolation: {
|
|
26
|
+
provider: string;
|
|
27
|
+
policySha256: string;
|
|
28
|
+
};
|
|
29
|
+
runtimeProbeIsolation: {
|
|
30
|
+
provider: string;
|
|
31
|
+
policySha256: string;
|
|
32
|
+
};
|
|
33
|
+
runtimeProbe: Omit<ProcessObservation, "stdout" | "stderr">;
|
|
34
|
+
}
|
|
35
|
+
export declare function certificationAssessment(root: string, projectId: string, context: NonNullable<Awaited<ReturnType<typeof prepareInvestigationCertification>>>, status: NativeRunRecord["status"], outputs: NativeRunRecord["outputs"], runtimeProbe: ProcessObservation, isolation: InvestigationCertification["isolation"], runtimeProbeIsolation: InvestigationCertification["isolation"], outputObservation: {
|
|
36
|
+
observedOutputBytes: number;
|
|
37
|
+
outputLimitExceeded: boolean;
|
|
38
|
+
}): Promise<InvestigationCertification>;
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { investigatedRequirementHashes } from "./investigation-requirements.js";
|
|
2
|
+
import { readTaskObject } from "./task-contract.js";
|
|
3
|
+
import { lstat, readFile } from "node:fs/promises";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { CliError } from "../../errors.js";
|
|
6
|
+
import { loadCurrentEvidenceSnapshot } from "./acquisition.js";
|
|
7
|
+
import { investigationAttemptHistory, parseInvestigationDiagnostic, } from "./investigation-attempt.js";
|
|
8
|
+
import { loadInvestigationCandidates } from "./investigation-candidate.js";
|
|
9
|
+
import { loadInvestigationPromotion, } from "./investigation-promotion.js";
|
|
10
|
+
import { loadInvestigation } from "./investigation.js";
|
|
11
|
+
import { assertResearchPolicyBinding } from "./research-policy.js";
|
|
12
|
+
import { applyScientificFulfillmentRecord, loadScientificFulfillmentView, } from "./scientific-fulfillment.js";
|
|
13
|
+
import { canonicalJson, sha256File, sha256Text, workspacePaths } from "./storage.js";
|
|
14
|
+
function failure(message, code = "RESEARCH_INVESTIGATION_CERTIFICATION_INVALID") {
|
|
15
|
+
return new CliError(message, { code, exitCode: 3 });
|
|
16
|
+
}
|
|
17
|
+
export async function assertInvestigationCertificationRequired(root, projectId, input, events) {
|
|
18
|
+
if (input.investigationPromotionSha256)
|
|
19
|
+
return;
|
|
20
|
+
const investigated = await investigatedRequirementHashes(projectId, events, (group, hash, field) => readTaskObject(root, projectId, group, hash, field));
|
|
21
|
+
if (investigated.has(input.requirementSha256))
|
|
22
|
+
throw failure("This investigated requirement needs an exact approved promotion and a fresh certification run. Diagnostic or ordinary runs cannot bypass that boundary.", "RESEARCH_INVESTIGATION_CERTIFICATION_REQUIRED");
|
|
23
|
+
}
|
|
24
|
+
export async function frozenPromotionView(root, project, promotion, events) {
|
|
25
|
+
const plan = promotion.plan;
|
|
26
|
+
if (!project.publicationPolicy ||
|
|
27
|
+
!project.scientificDesign ||
|
|
28
|
+
project.scientificDesign.designSha256 !== plan.designSha256 ||
|
|
29
|
+
project.publicationPolicy.resolvedPolicySha256 !== plan.policySha256 ||
|
|
30
|
+
sha256Text(project.question) !== plan.questionSha256)
|
|
31
|
+
throw failure("Certification scientific identity changed; review a new exact promotion.");
|
|
32
|
+
await assertResearchPolicyBinding(root, project.publicationPolicy);
|
|
33
|
+
const view = await loadScientificFulfillmentView(root, project, undefined, events);
|
|
34
|
+
const model = view.contract.identity.modelStructures.find((m) => m.id === plan.modelId);
|
|
35
|
+
const recipe = plan.recipe;
|
|
36
|
+
if (!model ||
|
|
37
|
+
model.implementationStatus !== "executable-frozen" ||
|
|
38
|
+
model.implementationArtifactSha256 !== recipe.script.sha256 ||
|
|
39
|
+
model.implementationEntrypoint !==
|
|
40
|
+
(recipe.runtime.kind === "node" ? "program.mjs" : "program.py") ||
|
|
41
|
+
model.environmentLockStatus !== "exact-frozen" ||
|
|
42
|
+
model.environmentLockSha256 !== recipe.environmentLock.sha256)
|
|
43
|
+
throw failure("Freeze the exact authorized implementation and environment through the existing fulfillment or successor route before certification.", "RESEARCH_INVESTIGATION_CERTIFICATION_NOT_FROZEN");
|
|
44
|
+
const before = structuredClone(view.amendedBase);
|
|
45
|
+
let extendsPlan = sha256Text(canonicalJson(before)) === plan.beforeEffectiveDesignSha256;
|
|
46
|
+
for (const record of view.records) {
|
|
47
|
+
applyScientificFulfillmentRecord(before, record);
|
|
48
|
+
extendsPlan ||= sha256Text(canonicalJson(before)) === plan.beforeEffectiveDesignSha256;
|
|
49
|
+
}
|
|
50
|
+
if (!extendsPlan)
|
|
51
|
+
throw failure("The scientific declaration no longer extends the approved promotion view.");
|
|
52
|
+
const acquisition = await loadCurrentEvidenceSnapshot(root, project.id);
|
|
53
|
+
if (acquisition.snapshotSha256 !== plan.acquisitionSnapshotSha256)
|
|
54
|
+
throw failure("The certification acquisition changed after promotion approval.");
|
|
55
|
+
return view.effectiveSha256;
|
|
56
|
+
}
|
|
57
|
+
export async function prepareInvestigationCertification(root, project, input, binarySha256, events) {
|
|
58
|
+
const hash = input.investigationPromotionSha256;
|
|
59
|
+
if (!hash)
|
|
60
|
+
return null;
|
|
61
|
+
const promotion = await loadInvestigationPromotion(root, project.id, hash, events);
|
|
62
|
+
if (events.some((e) => e.scope === project.id &&
|
|
63
|
+
e.type === "project.task.run.started" &&
|
|
64
|
+
e.payload.investigationPromotionSha256 === hash))
|
|
65
|
+
throw failure("This promotion already started its one authorized certification. Inspect that run; a new certification needs a new exact promotion approval.", "RESEARCH_INVESTIGATION_CERTIFICATION_EXHAUSTED");
|
|
66
|
+
const plan = promotion.plan;
|
|
67
|
+
if (plan.requirementId !== input.requirementId ||
|
|
68
|
+
plan.requirementSha256 !== input.requirementSha256)
|
|
69
|
+
throw failure("Certification must use the promoted requirement version.");
|
|
70
|
+
const definition = await loadInvestigation(root, plan.sourceProjectId, plan.investigationId, events);
|
|
71
|
+
const attempts = await investigationAttemptHistory(root, plan.sourceProjectId, definition, events);
|
|
72
|
+
const candidates = await loadInvestigationCandidates(root, plan.sourceProjectId, definition, events, attempts);
|
|
73
|
+
const candidate = candidates.find((c) => c.recordSha256 === plan.candidateSha256);
|
|
74
|
+
if (!candidate ||
|
|
75
|
+
candidate.recipeSha256 !== plan.recipeSha256 ||
|
|
76
|
+
canonicalJson(candidate.recipe) !== canonicalJson(plan.recipe))
|
|
77
|
+
throw failure("The approved recipe does not match its original observed candidate.");
|
|
78
|
+
const recipe = plan.recipe;
|
|
79
|
+
if (!Number.isSafeInteger(plan.certification.maxOutputBytes) ||
|
|
80
|
+
plan.certification.maxOutputBytes < 1 ||
|
|
81
|
+
plan.certification.maxOutputBytes !== recipe.maxOutputBytes ||
|
|
82
|
+
input.timeoutSeconds > plan.certification.maxRunSeconds ||
|
|
83
|
+
input.runtime.kind !== recipe.runtime.kind ||
|
|
84
|
+
binarySha256 !== recipe.runtime.binarySha256 ||
|
|
85
|
+
canonicalJson(input.arguments) !== canonicalJson(recipe.arguments) ||
|
|
86
|
+
canonicalJson(input.outputs) !== canonicalJson(recipe.outputs) ||
|
|
87
|
+
canonicalJson(input.inputs) !==
|
|
88
|
+
canonicalJson(recipe.inputs.map((i) => ({ id: i.id, artifactId: i.artifactId, sha256: i.sha256 }))))
|
|
89
|
+
throw failure("Certification inputs, runtime, arguments, outputs or time exceed the exact promoted recipe.");
|
|
90
|
+
const effectiveDesignSha256 = await frozenPromotionView(root, project, promotion, events);
|
|
91
|
+
for (const [path, hash] of [
|
|
92
|
+
[input.scriptPath, recipe.script.sha256],
|
|
93
|
+
[input.environmentLockPath, recipe.environmentLock.sha256],
|
|
94
|
+
]) {
|
|
95
|
+
const info = await lstat(path);
|
|
96
|
+
if (!info.isFile() || info.isSymbolicLink() || (await sha256File(path)) !== hash)
|
|
97
|
+
throw failure("Certification implementation or environment bytes differ from the promoted recipe.");
|
|
98
|
+
}
|
|
99
|
+
const allocation = project.budget?.entries.find((e) => e.id === `investigation-certification-${promotion.recordSha256}`);
|
|
100
|
+
if (!allocation ||
|
|
101
|
+
allocation.status !== "reserved" ||
|
|
102
|
+
allocation.maxCostUsd !== plan.certification.maxCostUsd)
|
|
103
|
+
throw failure("Certification has no current exact cost reservation.");
|
|
104
|
+
return { promotion, effectiveDesignSha256 };
|
|
105
|
+
}
|
|
106
|
+
export async function certificationAssessment(root, projectId, context, status, outputs, runtimeProbe, isolation, runtimeProbeIsolation, outputObservation) {
|
|
107
|
+
const plan = context.promotion.plan;
|
|
108
|
+
const output = outputs.find((o) => o.id === plan.recipe.diagnosticOutputId && o.mediaType === "application/json");
|
|
109
|
+
let diagnostic = null;
|
|
110
|
+
if (output && output.bytes <= 65536) {
|
|
111
|
+
try {
|
|
112
|
+
diagnostic = parseInvestigationDiagnostic(JSON.parse(await readFile(join(workspacePaths(root).projects, projectId, output.path), "utf8")));
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
/* Missing diagnostics cannot certify the recipe. */
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const missingTelemetry = diagnostic?.solverReached
|
|
119
|
+
? [
|
|
120
|
+
...plan.recipe.telemetry.requiredMetrics
|
|
121
|
+
.filter((id) => !Object.hasOwn(diagnostic.metrics, id))
|
|
122
|
+
.map((id) => `metrics.${id}`),
|
|
123
|
+
...plan.recipe.telemetry.requiredStatuses
|
|
124
|
+
.filter((id) => !Object.hasOwn(diagnostic.statuses, id))
|
|
125
|
+
.map((id) => `statuses.${id}`),
|
|
126
|
+
].sort()
|
|
127
|
+
: [];
|
|
128
|
+
const { stdout: _stdout, stderr: _stderr, ...probe } = runtimeProbe;
|
|
129
|
+
return {
|
|
130
|
+
promotionSha256: context.promotion.recordSha256,
|
|
131
|
+
candidateSha256: plan.candidateSha256,
|
|
132
|
+
recipeSha256: plan.recipeSha256,
|
|
133
|
+
effectiveDesignSha256: context.effectiveDesignSha256,
|
|
134
|
+
status: status === "succeeded" &&
|
|
135
|
+
!outputObservation.outputLimitExceeded &&
|
|
136
|
+
diagnostic?.solverReached &&
|
|
137
|
+
diagnostic.feasible &&
|
|
138
|
+
!missingTelemetry.length
|
|
139
|
+
? "passed"
|
|
140
|
+
: "failed",
|
|
141
|
+
diagnostic,
|
|
142
|
+
missingTelemetry,
|
|
143
|
+
actualCostUsd: null,
|
|
144
|
+
accountedCostUpperBoundUsd: plan.certification.maxCostUsd,
|
|
145
|
+
maxOutputBytes: plan.certification.maxOutputBytes,
|
|
146
|
+
...outputObservation,
|
|
147
|
+
isolation,
|
|
148
|
+
runtimeProbeIsolation,
|
|
149
|
+
runtimeProbe: probe,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=investigation-certification.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"investigation-certification.js","sourceRoot":"","sources":["../../../src/research/workspace/investigation-certification.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EACL,2BAA2B,EAC3B,4BAA4B,GAC7B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAC;AAC3E,OAAO,EACL,0BAA0B,GAE3B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEvD,OAAO,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EACL,gCAAgC,EAChC,6BAA6B,GAC9B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAGrF,SAAS,OAAO,CAAC,OAAe,EAAE,IAAI,GAAG,8CAA8C;IACrF,OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC;AACtD,CAAC;AACD,MAAM,CAAC,KAAK,UAAU,wCAAwC,CAC5D,IAAY,EACZ,SAAiB,EACjB,KAAqB,EACrB,MAAsB;IAEtB,IAAI,KAAK,CAAC,4BAA4B;QAAE,OAAO;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ACzB,UAAU,CAAC,QAAQ;YACnB,CAAC,gBAAgB,CAAC,MAAM;YACtB,CAAC,CAAC,QAAQ;YACV,CAAC,CAAC,QAAQ;QACd,UAAU;QACV,gBAAgB;QAChB,aAAa,EAAE,IAAI;QACnB,0BAA0B,EAAE,IAAI,CAAC,aAAa,CAAC,UAAU;QACzD,cAAc,EAAE,IAAI,CAAC,aAAa,CAAC,cAAc;QACjD,GAAG,iBAAiB;QACpB,SAAS;QACT,qBAAqB;QACrB,YAAY,EAAE,KAAK;KACpB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { investigationAttemptHistory } from "./investigation-attempt.js";
|
|
2
|
+
import { type InvestigationDefinition } from "./investigation.js";
|
|
3
|
+
import { type InvestigationReadStore } from "./investigation-store.js";
|
|
4
|
+
import type { JournalEvent } from "./types.js";
|
|
5
|
+
interface CloseInput {
|
|
6
|
+
schemaVersion: 1;
|
|
7
|
+
investigationId: string;
|
|
8
|
+
reason: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function investigationCloseInputSchema(): {
|
|
11
|
+
type: string;
|
|
12
|
+
additionalProperties: boolean;
|
|
13
|
+
required: string[];
|
|
14
|
+
properties: {
|
|
15
|
+
schemaVersion: {
|
|
16
|
+
const: number;
|
|
17
|
+
};
|
|
18
|
+
investigationId: {
|
|
19
|
+
type: string;
|
|
20
|
+
pattern: string;
|
|
21
|
+
};
|
|
22
|
+
reason: {
|
|
23
|
+
type: string;
|
|
24
|
+
minLength: number;
|
|
25
|
+
maxLength: number;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
export interface InvestigationClosure extends CloseInput {
|
|
30
|
+
kind: "tiangong-investigation-closure";
|
|
31
|
+
projectId: string;
|
|
32
|
+
definitionSha256: string;
|
|
33
|
+
candidateSha256: string | null;
|
|
34
|
+
requestSha256: string;
|
|
35
|
+
attemptSha256s: string[];
|
|
36
|
+
attemptCostUpperBoundUsd: number;
|
|
37
|
+
accountedCostUsd: number;
|
|
38
|
+
releasedCostUpperBoundUsd: number;
|
|
39
|
+
actualCostUsd: null;
|
|
40
|
+
settlementBasis: "allocated-upper-bound" | "owner-estimate" | "reported-usage";
|
|
41
|
+
closedAt: string;
|
|
42
|
+
recordSha256: string;
|
|
43
|
+
}
|
|
44
|
+
type History = Awaited<ReturnType<typeof investigationAttemptHistory>>;
|
|
45
|
+
export declare function loadInvestigationClosure(root: string, projectId: string, definition: InvestigationDefinition, history: History, events: JournalEvent[], store?: InvestigationReadStore): Promise<InvestigationClosure | null>;
|
|
46
|
+
export declare function closeInvestigation(root: string, projectId: string, value: unknown): Promise<InvestigationClosure>;
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { Ajv2020 } from "ajv/dist/2020.js";
|
|
2
|
+
import { CliError } from "../../errors.js";
|
|
3
|
+
import { investigationAttemptHistory } from "./investigation-attempt.js";
|
|
4
|
+
import { loadInvestigationCandidates } from "./investigation-candidate.js";
|
|
5
|
+
import { loadInvestigation } from "./investigation.js";
|
|
6
|
+
import { localInvestigationReadStore } from "./investigation-store.js";
|
|
7
|
+
import { appendJournalEvent, readVerifiedJournal } from "./journal.js";
|
|
8
|
+
import { assertProjectAuthority, projectAuthorityIndex } from "./project-authority.js";
|
|
9
|
+
import { settleProjectCost } from "./project-budget.js";
|
|
10
|
+
import { beginProjectMutation, prepareProjectMutation, projectMutationBinding, settleProjectMutation, } from "./project-mutations.js";
|
|
11
|
+
import { loadProject } from "./projects.js";
|
|
12
|
+
import { configuredResearchSecrets, sanitizeResearchValue } from "./sanitization.js";
|
|
13
|
+
import { canonicalJson, sha256Text, workspacePaths } from "./storage.js";
|
|
14
|
+
import { writeTaskObject } from "./task-contract.js";
|
|
15
|
+
import { withWorkspaceLock } from "./workspace.js";
|
|
16
|
+
const schema = {
|
|
17
|
+
type: "object",
|
|
18
|
+
additionalProperties: false,
|
|
19
|
+
required: ["schemaVersion", "investigationId", "reason"],
|
|
20
|
+
properties: {
|
|
21
|
+
schemaVersion: { const: 1 },
|
|
22
|
+
investigationId: { type: "string", pattern: "^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$" },
|
|
23
|
+
reason: { type: "string", minLength: 8, maxLength: 4000 },
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
const validate = new Ajv2020({ strict: false, allErrors: true }).compile(schema);
|
|
27
|
+
export function investigationCloseInputSchema() {
|
|
28
|
+
return structuredClone(schema);
|
|
29
|
+
}
|
|
30
|
+
function invalid(message, code = "RESEARCH_INVESTIGATION_CLOSE_INVALID") {
|
|
31
|
+
return new CliError(message, { code, exitCode: 3 });
|
|
32
|
+
}
|
|
33
|
+
export async function loadInvestigationClosure(root, projectId, definition, history, events, store = localInvestigationReadStore(root)) {
|
|
34
|
+
const closed = events.filter((e) => e.scope === projectId &&
|
|
35
|
+
e.type === "investigation.closed" &&
|
|
36
|
+
e.payload.investigationId === definition.investigationId);
|
|
37
|
+
if (!closed.length)
|
|
38
|
+
return null;
|
|
39
|
+
if (closed.length !== 1)
|
|
40
|
+
throw invalid("Investigation has duplicate closure authority.");
|
|
41
|
+
const event = closed[0];
|
|
42
|
+
const record = await store.readTask(projectId, "investigation-closures", String(event.payload.recordSha256), "recordSha256");
|
|
43
|
+
const input = {
|
|
44
|
+
schemaVersion: record.schemaVersion,
|
|
45
|
+
investigationId: record.investigationId,
|
|
46
|
+
reason: record.reason,
|
|
47
|
+
};
|
|
48
|
+
const candidates = await loadInvestigationCandidates(root, projectId, definition, events, history, store);
|
|
49
|
+
const spent = history.reduce((sum, a) => sum + a.start.maxCostUsd, 0);
|
|
50
|
+
if (!validate(input) ||
|
|
51
|
+
record.kind !== "tiangong-investigation-closure" ||
|
|
52
|
+
record.projectId !== projectId ||
|
|
53
|
+
record.investigationId !== definition.investigationId ||
|
|
54
|
+
record.definitionSha256 !== definition.recordSha256 ||
|
|
55
|
+
record.requestSha256 !== sha256Text(canonicalJson(input)) ||
|
|
56
|
+
record.candidateSha256 !== (candidates.at(-1)?.recordSha256 ?? null) ||
|
|
57
|
+
history.some((a) => !a.record) ||
|
|
58
|
+
canonicalJson(record.attemptSha256s) !==
|
|
59
|
+
canonicalJson(history.map((a) => a.record.recordSha256)) ||
|
|
60
|
+
!Number.isFinite(record.attemptCostUpperBoundUsd) ||
|
|
61
|
+
record.attemptCostUpperBoundUsd < 0 ||
|
|
62
|
+
Math.abs(record.attemptCostUpperBoundUsd - spent) > 1e-9 ||
|
|
63
|
+
!["allocated-upper-bound", "owner-estimate", "reported-usage"].includes(record.settlementBasis) ||
|
|
64
|
+
(record.settlementBasis === "allocated-upper-bound" &&
|
|
65
|
+
Math.abs(record.accountedCostUsd - spent) > 1e-9) ||
|
|
66
|
+
!Number.isFinite(record.releasedCostUpperBoundUsd) ||
|
|
67
|
+
record.releasedCostUpperBoundUsd < 0 ||
|
|
68
|
+
!Number.isFinite(record.accountedCostUsd) ||
|
|
69
|
+
record.accountedCostUsd < 0 ||
|
|
70
|
+
record.actualCostUsd !== null ||
|
|
71
|
+
Math.abs(record.releasedCostUpperBoundUsd -
|
|
72
|
+
Math.max(0, definition.plan.limits.maxCostUsd - record.accountedCostUsd)) > 1e-9 ||
|
|
73
|
+
events.some((e) => e.scope === projectId &&
|
|
74
|
+
e.payload.investigationId === definition.investigationId &&
|
|
75
|
+
[
|
|
76
|
+
"investigation.attempt.started",
|
|
77
|
+
"investigation.attempt.completed",
|
|
78
|
+
"investigation.candidate.selected",
|
|
79
|
+
].includes(e.type) &&
|
|
80
|
+
e.sequence >= event.sequence))
|
|
81
|
+
throw invalid("Investigation closure does not match its complete immutable history.");
|
|
82
|
+
return record;
|
|
83
|
+
}
|
|
84
|
+
export async function closeInvestigation(root, projectId, value) {
|
|
85
|
+
if (!validate(value) ||
|
|
86
|
+
canonicalJson(sanitizeResearchValue(value, configuredResearchSecrets(process.env))) !==
|
|
87
|
+
canonicalJson(value))
|
|
88
|
+
throw invalid("Close with a bounded non-secret reason and exact investigation ID.");
|
|
89
|
+
const input = value, requestSha256 = sha256Text(canonicalJson(input));
|
|
90
|
+
return withWorkspaceLock(root, "research.investigation.close", async () => {
|
|
91
|
+
const project = await loadProject(root, projectId), events = await readVerifiedJournal(workspacePaths(root).journal);
|
|
92
|
+
assertProjectAuthority(project, projectAuthorityIndex(events));
|
|
93
|
+
const definition = await loadInvestigation(root, projectId, input.investigationId, events);
|
|
94
|
+
const history = await investigationAttemptHistory(root, projectId, definition, events);
|
|
95
|
+
const known = await loadInvestigationClosure(root, projectId, definition, history, events);
|
|
96
|
+
if (known) {
|
|
97
|
+
if (known.requestSha256 !== requestSha256)
|
|
98
|
+
throw invalid("The closed investigation already binds a different final reason.");
|
|
99
|
+
return known;
|
|
100
|
+
}
|
|
101
|
+
if (history.some((a) => !a.record))
|
|
102
|
+
throw invalid("An unresolved attempt keeps its reservation. Inspect it before closing; no resource estimate was erased.", "RESEARCH_INVESTIGATION_INCOMPLETE");
|
|
103
|
+
const candidates = await loadInvestigationCandidates(root, projectId, definition, events, history);
|
|
104
|
+
const allocation = project.budget?.entries.find((e) => e.id === `investigation-${definition.recordSha256}`);
|
|
105
|
+
if (!allocation)
|
|
106
|
+
throw invalid("Investigation has no project allocation to settle.");
|
|
107
|
+
const spent = history.reduce((sum, a) => sum + a.start.maxCostUsd, 0);
|
|
108
|
+
const accounted = allocation.status === "reserved" ? spent : allocation.accountedCostUsd;
|
|
109
|
+
if (!Number.isFinite(accounted) ||
|
|
110
|
+
accounted < 0 ||
|
|
111
|
+
spent > definition.plan.limits.maxCostUsd + 1e-9)
|
|
112
|
+
throw invalid("Investigation resource accounting is inconsistent.");
|
|
113
|
+
const core = {
|
|
114
|
+
...input,
|
|
115
|
+
kind: "tiangong-investigation-closure",
|
|
116
|
+
projectId,
|
|
117
|
+
definitionSha256: definition.recordSha256,
|
|
118
|
+
candidateSha256: candidates.at(-1)?.recordSha256 ?? null,
|
|
119
|
+
requestSha256,
|
|
120
|
+
attemptSha256s: history.map((a) => a.record.recordSha256),
|
|
121
|
+
attemptCostUpperBoundUsd: spent,
|
|
122
|
+
accountedCostUsd: accounted,
|
|
123
|
+
releasedCostUpperBoundUsd: Math.max(0, definition.plan.limits.maxCostUsd - accounted),
|
|
124
|
+
actualCostUsd: null,
|
|
125
|
+
settlementBasis: allocation.status === "reserved"
|
|
126
|
+
? "allocated-upper-bound"
|
|
127
|
+
: allocation.settlementBasis,
|
|
128
|
+
closedAt: new Date().toISOString(),
|
|
129
|
+
};
|
|
130
|
+
const record = { ...core, recordSha256: sha256Text(canonicalJson(core)) };
|
|
131
|
+
await writeTaskObject(root, projectId, "investigation-closures", record.recordSha256, record);
|
|
132
|
+
let mutation = await beginProjectMutation(root, "investigation-closure", project, record.recordSha256);
|
|
133
|
+
try {
|
|
134
|
+
if (allocation.status === "reserved")
|
|
135
|
+
settleProjectCost(project, allocation.id, spent, "allocated-upper-bound");
|
|
136
|
+
project.updatedAt = new Date().toISOString();
|
|
137
|
+
mutation = await prepareProjectMutation(root, mutation, project);
|
|
138
|
+
await appendJournalEvent(workspacePaths(root).journal, "investigation.closed", projectId, {
|
|
139
|
+
projectId,
|
|
140
|
+
investigationId: input.investigationId,
|
|
141
|
+
recordSha256: record.recordSha256,
|
|
142
|
+
mutation: projectMutationBinding(mutation),
|
|
143
|
+
});
|
|
144
|
+
await settleProjectMutation(root, mutation);
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
await settleProjectMutation(root, mutation);
|
|
148
|
+
throw error;
|
|
149
|
+
}
|
|
150
|
+
return record;
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=investigation-close.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"investigation-close.js","sourceRoot":"","sources":["../../../src/research/workspace/investigation-close.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,C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types.js";
|
|
2
|
+
export interface InvestigationSourceReference {
|
|
3
|
+
projectId: string;
|
|
4
|
+
investigationId: string;
|
|
5
|
+
}
|
|
6
|
+
/** Incoming dependencies only. Equal strings in unrelated payloads do not
|
|
7
|
+
* grant that project's records authority over this export. */
|
|
8
|
+
export declare function relevantInvestigationEvents<T extends Pick<JournalEvent, "scope" | "type" | "payload">>(projectId: string, events: T[], sources: InvestigationSourceReference[]): T[];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Incoming dependencies only. Equal strings in unrelated payloads do not
|
|
2
|
+
* grant that project's records authority over this export. */
|
|
3
|
+
export function relevantInvestigationEvents(projectId, events, sources) {
|
|
4
|
+
const allowed = new Set(sources.map((source) => `${source.projectId}\0${source.investigationId}`));
|
|
5
|
+
return events.filter((event) => event.scope === projectId ||
|
|
6
|
+
(event.type.startsWith("investigation.") &&
|
|
7
|
+
!event.type.startsWith("investigation.promotion.") &&
|
|
8
|
+
allowed.has(`${event.scope}\0${String(event.payload.investigationId)}`)));
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=investigation-lineage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"investigation-lineage.js","sourceRoot":"","sources":["../../../src/research/workspace/investigation-lineage.ts"],"names":[],"mappings":"AAMA;8DAC8D;AAC9D,MAAM,UAAU,2BAA2B,CAEzC,SAAiB,EAAE,MAAW,EAAE,OAAuC;IACvE,MAAM,OAAO,GAAG,IAAI,GAAG,CACrB,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,MAAM,CAAC,SAAS,KAAK,MAAM,CAAC,eAAe,EAAE,CAAC,CAC1E,CAAC;IACF,OAAO,MAAM,CAAC,MAAM,CAClB,CAAC,KAAK,EAAE,EAAE,CACR,KAAK,CAAC,KAAK,KAAK,SAAS;QACzB,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,gBAAgB,CAAC;YACtC,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,0BAA0B,CAAC;YAClD,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,KAAK,KAAK,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,CAC7E,CAAC;AACJ,CAAC"}
|