@tiangong-ai/cli 0.0.60 → 0.0.62
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/README.md +577 -55
- 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 +341 -28
- 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/acquisition-routes.d.ts +1 -1
- package/dist/research/workspace/acquisition-routes.js +2 -11
- package/dist/research/workspace/acquisition-routes.js.map +1 -1
- package/dist/research/workspace/artifact-read-audit.d.ts +16 -0
- package/dist/research/workspace/artifact-read-audit.js +176 -0
- package/dist/research/workspace/artifact-read-audit.js.map +1 -0
- package/dist/research/workspace/artifact-trace.d.ts +12 -0
- package/dist/research/workspace/artifact-trace.js +109 -0
- package/dist/research/workspace/artifact-trace.js.map +1 -0
- package/dist/research/workspace/artifact-view-mcp.d.ts +75 -0
- package/dist/research/workspace/artifact-view-mcp.js +214 -0
- package/dist/research/workspace/artifact-view-mcp.js.map +1 -0
- package/dist/research/workspace/artifact-views.d.ts +100 -0
- package/dist/research/workspace/artifact-views.js +395 -0
- package/dist/research/workspace/artifact-views.js.map +1 -0
- package/dist/research/workspace/audit-bundle.d.ts +4 -0
- package/dist/research/workspace/audit-bundle.js +130 -11
- 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 +32 -2
- package/dist/research/workspace/executor.js +286 -42
- package/dist/research/workspace/executor.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 +150 -0
- package/dist/research/workspace/native-run.js +879 -0
- package/dist/research/workspace/native-run.js.map +1 -0
- package/dist/research/workspace/preflight.d.ts +11 -2
- package/dist/research/workspace/preflight.js +28 -20
- 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 +29 -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 +182 -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/request-provenance.d.ts +67 -0
- package/dist/research/workspace/request-provenance.js +115 -0
- package/dist/research/workspace/request-provenance.js.map +1 -0
- package/dist/research/workspace/review-executor.d.ts +6 -1
- package/dist/research/workspace/review-executor.js +39 -14
- package/dist/research/workspace/review-executor.js.map +1 -1
- package/dist/research/workspace/runtime.d.ts +64 -1
- package/dist/research/workspace/runtime.js +359 -112
- package/dist/research/workspace/runtime.js.map +1 -1
- package/dist/research/workspace/sanitization.js +1 -1
- package/dist/research/workspace/sanitization.js.map +1 -1
- package/dist/research/workspace/schema-compatibility.d.ts +5 -0
- package/dist/research/workspace/schema-compatibility.js +55 -0
- package/dist/research/workspace/schema-compatibility.js.map +1 -0
- 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-design.js +8 -17
- package/dist/research/workspace/scientific-design.js.map +1 -1
- package/dist/research/workspace/scientific-fulfillment-audit.d.ts +21 -0
- package/dist/research/workspace/scientific-fulfillment-audit.js +217 -0
- package/dist/research/workspace/scientific-fulfillment-audit.js.map +1 -0
- package/dist/research/workspace/scientific-fulfillment.d.ts +130 -0
- package/dist/research/workspace/scientific-fulfillment.js +553 -0
- package/dist/research/workspace/scientific-fulfillment.js.map +1 -0
- package/dist/research/workspace/scientific-review-execution.js +236 -75
- package/dist/research/workspace/scientific-review-execution.js.map +1 -1
- package/dist/research/workspace/scientific-review.d.ts +6 -1
- package/dist/research/workspace/scientific-review.js +228 -52
- package/dist/research/workspace/scientific-review.js.map +1 -1
- package/dist/research/workspace/setup-catalog.js +3 -3
- 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 +220 -17
- package/dist/research/workspace/setup.js.map +1 -1
- package/dist/research/workspace/task-acceptance.d.ts +17 -2
- package/dist/research/workspace/task-acceptance.js +106 -10
- 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 +70 -5
- package/dist/research/workspace/task-audit.js.map +1 -1
- package/dist/research/workspace/task-contract.d.ts +4 -1
- package/dist/research/workspace/task-contract.js +26 -5
- package/dist/research/workspace/task-contract.js.map +1 -1
- package/dist/research/workspace/types.d.ts +50 -3
- package/dist/research/workspace/workspace.js +34 -4
- package/dist/research/workspace/workspace.js.map +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { CliError } from "../../errors.js";
|
|
2
|
+
import { canonicalJson, isObject, sha256Text } from "./storage.js";
|
|
3
|
+
/** Lightweight derived index shared by intake, review context and portable audit.
|
|
4
|
+
* It never loads programs/results for requirements without investigation history. */
|
|
5
|
+
export async function investigatedRequirementHashes(projectId, events, readObject) {
|
|
6
|
+
const hashes = new Set();
|
|
7
|
+
for (const event of events) {
|
|
8
|
+
if (event.scope !== projectId ||
|
|
9
|
+
!["investigation.approved", "investigation.promotion.approved"].includes(event.type))
|
|
10
|
+
continue;
|
|
11
|
+
const promotion = event.type === "investigation.promotion.approved";
|
|
12
|
+
const value = await readObject(promotion ? "investigation-promotions" : "investigations", String(event.payload.recordSha256), "recordSha256");
|
|
13
|
+
if (!isObject(value) ||
|
|
14
|
+
value.projectId !== projectId ||
|
|
15
|
+
value.kind !== (promotion ? "tiangong-investigation-promotion" : "tiangong-investigation") ||
|
|
16
|
+
!isObject(value.plan) ||
|
|
17
|
+
value.plan.projectId !== projectId ||
|
|
18
|
+
value.plan.planSha256 !== event.payload.planSha256 ||
|
|
19
|
+
typeof value.plan.requirementSha256 !== "string" ||
|
|
20
|
+
!/^[a-f0-9]{64}$/.test(value.plan.requirementSha256))
|
|
21
|
+
throw new CliError("Investigation requirement authority is not bound to its committed plan.", { code: "RESEARCH_INVESTIGATION_BINDING_INVALID", exitCode: 3 });
|
|
22
|
+
const { planSha256, ...core } = value.plan;
|
|
23
|
+
if (sha256Text(canonicalJson(core)) !== planSha256)
|
|
24
|
+
throw new CliError("Investigation requirement plan bytes changed.", {
|
|
25
|
+
code: "RESEARCH_INVESTIGATION_BINDING_INVALID",
|
|
26
|
+
exitCode: 3,
|
|
27
|
+
});
|
|
28
|
+
hashes.add(value.plan.requirementSha256);
|
|
29
|
+
}
|
|
30
|
+
return hashes;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=investigation-requirements.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"investigation-requirements.js","sourceRoot":"","sources":["../../../src/research/workspace/investigation-requirements.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAInE;qFACqF;AACrF,MAAM,CAAC,KAAK,UAAU,6BAA6B,CACjD,SAAiB,EACjB,MAA+D,EAC/D,UAA4B;IAE5B,MAAM,MAAM,GAAG,IAAI,GAAG,EAAU,CAAC;IACjC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,IACE,KAAK,CAAC,KAAK,KAAK,SAAS;YACzB,CAAC,CAAC,wBAAwB,EAAE,kCAAkC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC;YAEpF,SAAS;QACX,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,KAAK,kCAAkC,CAAC;QACpE,MAAM,KAAK,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import type { JournalEvent } from "./types.js";
|
|
3
|
+
/** One pass over authoritative facts. A terminal event releases uncertainty,
|
|
4
|
+
* while actual completed time remains in the recovered project usage. */
|
|
5
|
+
export declare function investigationWallReservations(root: string, projectId: string, events: JournalEvent[], store?: InvestigationReadStore): Promise<{
|
|
6
|
+
wallSeconds: number;
|
|
7
|
+
reservations: {
|
|
8
|
+
kind: "investigation-attempt" | "certification";
|
|
9
|
+
id: string;
|
|
10
|
+
wallSeconds: number;
|
|
11
|
+
}[];
|
|
12
|
+
}>;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { CliError } from "../../errors.js";
|
|
2
|
+
import { localInvestigationReadStore } from "./investigation-store.js";
|
|
3
|
+
function invalid() {
|
|
4
|
+
return new CliError("Unresolved investigation time does not match its committed start.", {
|
|
5
|
+
code: "RESEARCH_INVESTIGATION_BINDING_INVALID",
|
|
6
|
+
exitCode: 3,
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
/** One pass over authoritative facts. A terminal event releases uncertainty,
|
|
10
|
+
* while actual completed time remains in the recovered project usage. */
|
|
11
|
+
export async function investigationWallReservations(root, projectId, events, store = localInvestigationReadStore(root)) {
|
|
12
|
+
const attempts = new Map(), certifications = new Map();
|
|
13
|
+
const seen = new Set();
|
|
14
|
+
for (const event of events) {
|
|
15
|
+
if (event.scope !== projectId)
|
|
16
|
+
continue;
|
|
17
|
+
const attemptKey = `${String(event.payload.investigationId)}\0${String(event.payload.attemptId)}`;
|
|
18
|
+
if (event.type === "investigation.attempt.started") {
|
|
19
|
+
const key = `attempt/${attemptKey}`;
|
|
20
|
+
if (seen.has(key))
|
|
21
|
+
throw invalid();
|
|
22
|
+
seen.add(key);
|
|
23
|
+
attempts.set(attemptKey, event);
|
|
24
|
+
}
|
|
25
|
+
else if (event.type === "investigation.attempt.completed") {
|
|
26
|
+
const start = attempts.get(attemptKey);
|
|
27
|
+
if (!start || start.payload.recordSha256 !== event.payload.startSha256)
|
|
28
|
+
throw invalid();
|
|
29
|
+
attempts.delete(attemptKey);
|
|
30
|
+
}
|
|
31
|
+
else if (event.type === "project.task.run.started" &&
|
|
32
|
+
event.payload.investigationPromotionSha256) {
|
|
33
|
+
const id = String(event.payload.runId), key = `certification/${id}`;
|
|
34
|
+
if (seen.has(key))
|
|
35
|
+
throw invalid();
|
|
36
|
+
seen.add(key);
|
|
37
|
+
certifications.set(id, event);
|
|
38
|
+
}
|
|
39
|
+
else if (event.type === "project.task.run.completed") {
|
|
40
|
+
const id = String(event.payload.runId), start = certifications.get(id);
|
|
41
|
+
if (start) {
|
|
42
|
+
if (start.payload.requestSha256 !== event.payload.requestSha256)
|
|
43
|
+
throw invalid();
|
|
44
|
+
certifications.delete(id);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const reservations = [];
|
|
49
|
+
for (const event of attempts.values()) {
|
|
50
|
+
const record = await store.readTask(projectId, "investigation-starts", String(event.payload.recordSha256), "recordSha256");
|
|
51
|
+
if (record.projectId !== projectId ||
|
|
52
|
+
record.investigationId !== event.payload.investigationId ||
|
|
53
|
+
record.attemptId !== event.payload.attemptId ||
|
|
54
|
+
!Number.isSafeInteger(record.timeoutSeconds) ||
|
|
55
|
+
record.timeoutSeconds < 1)
|
|
56
|
+
throw invalid();
|
|
57
|
+
reservations.push({
|
|
58
|
+
kind: "investigation-attempt",
|
|
59
|
+
id: `${record.investigationId}/${record.attemptId}`,
|
|
60
|
+
wallSeconds: record.timeoutSeconds,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
for (const event of certifications.values()) {
|
|
64
|
+
const seconds = event.payload.certificationReservedWallSeconds;
|
|
65
|
+
if (typeof seconds !== "number" || !Number.isSafeInteger(seconds) || seconds < 1)
|
|
66
|
+
throw invalid();
|
|
67
|
+
reservations.push({
|
|
68
|
+
kind: "certification",
|
|
69
|
+
id: String(event.payload.runId),
|
|
70
|
+
wallSeconds: seconds,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
const wallSeconds = reservations.reduce((sum, item) => sum + item.wallSeconds, 0);
|
|
74
|
+
if (!Number.isSafeInteger(wallSeconds))
|
|
75
|
+
throw invalid();
|
|
76
|
+
return { wallSeconds, reservations };
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=investigation-resources.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"investigation-resources.js","sourceRoot":"","sources":["../../../src/research/workspace/investigation-resources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,2BAA2B,EAA+B,MAAM,0BAA0B,CAAC;AAGpG,SAAS,OAAO;IACd,OAAO,IAAI,QAAQ,CAAC,mEAAmE,EAAE;QACvF,IAAI,EAAE,wCAAwC;QAC9C,QAAQ,EAAE,CAAC;KACZ,CAAC,CAAC;AACL,CAAC;AACD;yEACyE;AACzE,MAAM,CAAC,KAAK,UAAU,6BAA6B,CACjD,IAAY,EACZ,SAAiB,EACjB,MAAsB,EACtB,KAAK,GAA2B,2BAA2B,CAAC,IAAI,CAAC;IAEjE,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAwB,EAC9C,cAAc,GAAG,IAAI,GAAG,EAAwB,CAAC;IACnD,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS;YAAE,SAAS;QACxC,MAAM,UAAU,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC,KAAK,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QAClG,IAAI,KAAK,CAAC,IAAI,KAAK,+BAA+B,EAAE,CAAC;YACnD,MAAM,GAAG,GAAG,WAAW,UAAU,EAAE,CAAC;YACpC,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC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CAAC;IACL,CAAC;IACD,MAAM,WAAW,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,GAAG,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;IAClF,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,WAAW,CAAC;QAAE,MAAM,OAAO,EAAE,CAAC;IACxD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { InvestigationSourceReference } from "./investigation-lineage.js";
|
|
2
|
+
import type { JournalEvent } from "./types.js";
|
|
3
|
+
/** Export only immutable incoming investigation dependencies named by this
|
|
4
|
+
* project's committed promotion approvals. Local routing and other studies
|
|
5
|
+
* never enter the source closure. */
|
|
6
|
+
export declare function stageInvestigationSources(root: string, projectId: string, events: JournalEvent[], stageFile: (source: string, logical: string) => Promise<void>): Promise<InvestigationSourceReference[]>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { loadInvestigationClosure } from "./investigation-close.js";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { loadInvestigation } from "./investigation.js";
|
|
4
|
+
import { investigationAttemptHistory } from "./investigation-attempt.js";
|
|
5
|
+
import { loadInvestigationCandidates } from "./investigation-candidate.js";
|
|
6
|
+
import { loadInvestigationPromotion } from "./investigation-promotion.js";
|
|
7
|
+
import { localInvestigationReadStore } from "./investigation-store.js";
|
|
8
|
+
import { workspacePaths } from "./storage.js";
|
|
9
|
+
/** Export only immutable incoming investigation dependencies named by this
|
|
10
|
+
* project's committed promotion approvals. Local routing and other studies
|
|
11
|
+
* never enter the source closure. */
|
|
12
|
+
export async function stageInvestigationSources(root, projectId, events, stageFile) {
|
|
13
|
+
const store = localInvestigationReadStore(root);
|
|
14
|
+
const sources = new Map();
|
|
15
|
+
for (const event of events) {
|
|
16
|
+
if (event.scope !== projectId || event.type !== "investigation.promotion.approved")
|
|
17
|
+
continue;
|
|
18
|
+
const promotion = await loadInvestigationPromotion(root, projectId, String(event.payload.recordSha256), events, store);
|
|
19
|
+
if (promotion.plan.sourceProjectId === projectId)
|
|
20
|
+
continue;
|
|
21
|
+
const reference = {
|
|
22
|
+
projectId: promotion.plan.sourceProjectId,
|
|
23
|
+
investigationId: promotion.plan.investigationId,
|
|
24
|
+
};
|
|
25
|
+
sources.set(`${reference.projectId}\0${reference.investigationId}`, reference);
|
|
26
|
+
}
|
|
27
|
+
for (const source of sources.values()) {
|
|
28
|
+
const definition = await loadInvestigation(root, source.projectId, source.investigationId, events, store);
|
|
29
|
+
const attempts = await investigationAttemptHistory(root, source.projectId, definition, events, store);
|
|
30
|
+
const candidates = await loadInvestigationCandidates(root, source.projectId, definition, events, attempts, store);
|
|
31
|
+
const prefix = `investigation-sources/${source.projectId}`;
|
|
32
|
+
const stageRecord = (group, hash) => {
|
|
33
|
+
const path = `task/${group}/${hash}.json`;
|
|
34
|
+
return stageFile(join(workspacePaths(root).projects, source.projectId, path), `${prefix}/${path}`);
|
|
35
|
+
};
|
|
36
|
+
const blobs = new Map();
|
|
37
|
+
const collect = (object) => blobs.set(object.path, object);
|
|
38
|
+
await stageRecord("investigations", definition.recordSha256);
|
|
39
|
+
const closure = await loadInvestigationClosure(root, source.projectId, definition, attempts, events, store);
|
|
40
|
+
if (closure)
|
|
41
|
+
await stageRecord("investigation-closures", closure.recordSha256);
|
|
42
|
+
collect(definition.scopeAuthorization.source);
|
|
43
|
+
for (const program of definition.programs) {
|
|
44
|
+
collect(program.script);
|
|
45
|
+
collect(program.environmentLock);
|
|
46
|
+
}
|
|
47
|
+
for (const attempt of attempts) {
|
|
48
|
+
await stageRecord("investigation-starts", attempt.start.recordSha256);
|
|
49
|
+
for (const input of attempt.start.inputs)
|
|
50
|
+
collect(input);
|
|
51
|
+
if (attempt.record) {
|
|
52
|
+
await stageRecord("investigation-attempts", attempt.record.recordSha256);
|
|
53
|
+
for (const log of Object.values(attempt.record.logs))
|
|
54
|
+
collect(log);
|
|
55
|
+
for (const output of attempt.record.outputs)
|
|
56
|
+
collect(output);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
for (const candidate of candidates)
|
|
60
|
+
await stageRecord("investigation-candidates", candidate.recordSha256);
|
|
61
|
+
for (const object of blobs.values()) {
|
|
62
|
+
await store.verifyBlob(source.projectId, object);
|
|
63
|
+
await stageFile(join(workspacePaths(root).projects, source.projectId, object.path), `${prefix}/${object.path}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return [...sources.values()];
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=investigation-source-export.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"investigation-source-export.js","sourceRoot":"","sources":["../../../src/research/workspace/investigation-source-export.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAC;AACzE,OAAO,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAC;AAC3E,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAEvE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAG9C;;qCAEqC;AACrC,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAC7C,IAAY,EACZ,SAAiB,EACjB,MAAsB,EACtB,SAA6D;IAE7D,MAAM,KAAK,GAAG,2BAA2B,CAAC,IAAI,CAAC,CAAC;IAChD,MAAM,OAAO,GAAG,IAAI,GAAG,EAAwC,CAAC;IAChE,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,IAAI,KAAK,CA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C,MAAM,CAAC,IAAI,CAAC;oBAAE,OAAO,CAAC,GAAG,CAAC,CAAC;gBACnE,KAAK,MAAM,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,OAAO;oBAAE,OAAO,CAAC,MAAM,CAAC,CAAC;YAC/D,CAAC;QACH,CAAC;QACD,KAAK,MAAM,SAAS,IAAI,UAAU;YAChC,MAAM,WAAW,CAAC,0BAA0B,EAAE,SAAS,CAAC,YAAY,CAAC,CAAC;QACxE,KAAK,MAAM,MAAM,IAAI,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC;YACpC,MAAM,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;YACjD,MAAM,SAAS,CACb,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,EAClE,GAAG,MAAM,IAAI,MAAM,CAAC,IAAI,EAAE,CAC3B,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { OutputRecord } from "./types.js";
|
|
2
|
+
/** Operation-scoped immutable-object access, shared with indexed portable audit. */
|
|
3
|
+
export interface InvestigationReadStore {
|
|
4
|
+
readTask<T>(projectId: string, group: string, hash: string, field: string): Promise<T>;
|
|
5
|
+
verifyBlob(projectId: string, object: OutputRecord): Promise<void>;
|
|
6
|
+
readBlob(projectId: string, object: OutputRecord, maxBytes: number): Promise<Buffer>;
|
|
7
|
+
}
|
|
8
|
+
export declare function assertInvestigationBlob(object: OutputRecord): void;
|
|
9
|
+
export declare function localInvestigationReadStore(root: string): InvestigationReadStore;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { lstat, readFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { CliError } from "../../errors.js";
|
|
4
|
+
import { sha256File, workspacePaths } from "./storage.js";
|
|
5
|
+
import { readTaskObject, taskDirectory } from "./task-contract.js";
|
|
6
|
+
export function assertInvestigationBlob(object) {
|
|
7
|
+
if (!object ||
|
|
8
|
+
typeof object.sha256 !== "string" ||
|
|
9
|
+
!/^[a-f0-9]{64}$/.test(object.sha256) ||
|
|
10
|
+
object.path !== `task/run-objects/${object.sha256}` ||
|
|
11
|
+
!Number.isSafeInteger(object.bytes) ||
|
|
12
|
+
object.bytes < 0)
|
|
13
|
+
throw new CliError("Investigation blob address is invalid.", {
|
|
14
|
+
code: "RESEARCH_INVESTIGATION_BINDING_INVALID",
|
|
15
|
+
exitCode: 3,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
export function localInvestigationReadStore(root) {
|
|
19
|
+
const verified = new Set();
|
|
20
|
+
const directories = new Set();
|
|
21
|
+
const store = {
|
|
22
|
+
readTask: (projectId, group, hash, field) => readTaskObject(root, projectId, group, hash, field),
|
|
23
|
+
verifyBlob: async (projectId, object) => {
|
|
24
|
+
assertInvestigationBlob(object);
|
|
25
|
+
const key = `${projectId}/${object.sha256}/${object.bytes}`;
|
|
26
|
+
if (verified.has(key))
|
|
27
|
+
return;
|
|
28
|
+
if (!directories.has(projectId)) {
|
|
29
|
+
await taskDirectory(root, projectId, "run-objects", false);
|
|
30
|
+
directories.add(projectId);
|
|
31
|
+
}
|
|
32
|
+
const path = join(workspacePaths(root).projects, projectId, object.path), info = await lstat(path).catch(() => null);
|
|
33
|
+
if (!info?.isFile() ||
|
|
34
|
+
info.isSymbolicLink() ||
|
|
35
|
+
info.size !== object.bytes ||
|
|
36
|
+
(await sha256File(path)) !== object.sha256)
|
|
37
|
+
throw new CliError("Investigation blob bytes changed.", {
|
|
38
|
+
code: "RESEARCH_INVESTIGATION_BINDING_INVALID",
|
|
39
|
+
exitCode: 3,
|
|
40
|
+
});
|
|
41
|
+
verified.add(key);
|
|
42
|
+
},
|
|
43
|
+
readBlob: async (projectId, object, maxBytes) => {
|
|
44
|
+
await store.verifyBlob(projectId, object);
|
|
45
|
+
if (object.bytes > maxBytes)
|
|
46
|
+
throw new CliError("Investigation object exceeds this read's explicit byte limit.", {
|
|
47
|
+
code: "RESEARCH_INVESTIGATION_BINDING_INVALID",
|
|
48
|
+
exitCode: 3,
|
|
49
|
+
});
|
|
50
|
+
return readFile(join(workspacePaths(root).projects, projectId, object.path));
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
return store;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=investigation-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"investigation-store.js","sourceRoot":"","sources":["../../../src/research/workspace/investigation-store.ts"],"names":[],"mappings":"AAAA,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,UAAU,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AASnE,MAAM,UAAU,uBAAuB,CAAC,MAAoB;IAC1D,IACE,CAAC,MAAM;QACP,OAAO,MAAM,CAAC,MAAM,KAAK,QAAQ;QACjC,CAAC,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;QACrC,MAAM,CAAC,IAAI,KAAK,oBAAoB,MAAM,CAAC,MAAM,EAAE;QACnD,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC;QACnC,MAAM,CAAC,KAAK,GAAG,CAAC;QAEhB,MAAM,IAAI,QAAQ,CAAC,wCAAwC,EAAE;YAC3D,IAAI,EAAE,wCAAwC;YAC9C,QAAQ,EAAE,CAAC;SACZ,CAAC,CAAC;AACP,CAAC;AACD,MAAM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