@citeark/agent 0.3.20
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/LICENSE +202 -0
- package/README.md +128 -0
- package/data/dataset-source-registry.v1.json +300 -0
- package/dist/arkgraph/boot.js +6 -0
- package/dist/arkgraph/index.html +1 -0
- package/dist/arkgraph/viewer.css +1 -0
- package/dist/arkgraph/viewer.en.css +1 -0
- package/dist/arkgraph/viewer.en.js +49 -0
- package/dist/arkgraph/viewer.en.js.LEGAL.txt +56 -0
- package/dist/arkgraph/viewer.js +49 -0
- package/dist/arkgraph/viewer.js.LEGAL.txt +56 -0
- package/docker/claude-code/Dockerfile +97 -0
- package/docker/claude-code/codex-pro-relay.mjs +466 -0
- package/docker/claude-code/runtime-contract-check.mjs +79 -0
- package/docs/arkgraph-reading.md +79 -0
- package/docs/configuration.md +100 -0
- package/docs/integration.md +92 -0
- package/docs/maturity-plan.md +27 -0
- package/docs/npm-release.md +44 -0
- package/docs/paper-reading.md +40 -0
- package/docs/research-plan-granularity.md +27 -0
- package/docs/terminal.md +49 -0
- package/examples/toy-evaluation/compile-task.json +27 -0
- package/examples/toy-evaluation/paper.md +5 -0
- package/examples/toy-evaluation/repository/README.md +9 -0
- package/examples/toy-evaluation/repository/checkpoint.json +4 -0
- package/examples/toy-evaluation/repository/evaluate.py +17 -0
- package/examples/toy-evaluation/task.json +81 -0
- package/package.json +59 -0
- package/prompts/compile-research.md +58 -0
- package/prompts/execute-contract.md +72 -0
- package/prompts/execute-workspace-simple.md +51 -0
- package/prompts/execute-workspace.md +34 -0
- package/prompts/prepare-reproduction.md +82 -0
- package/prompts/repair-research.md +45 -0
- package/protocol/CAP.md +129 -0
- package/protocol/LICENSE +12 -0
- package/protocol/MAPPINGS.md +72 -0
- package/protocol/README.md +38 -0
- package/protocol/conformance-v2.0-alpha.1.json +36 -0
- package/protocol/examples/arkgraph/checkpoint-evaluation.json +309 -0
- package/protocol/examples/arkgraph/fixtures.mjs +49 -0
- package/protocol/examples/arkgraph/paper-free.json +291 -0
- package/protocol/examples/arkgraph/partial-failure.json +344 -0
- package/protocol/examples/arkgraph/training-evaluation.json +443 -0
- package/protocol/profiles/agent-trace.md +16 -0
- package/protocol/profiles/computational-run.md +16 -0
- package/protocol/profiles/core.md +15 -0
- package/protocol/profiles/public-bundle.md +18 -0
- package/protocol/profiles/reproduction.md +29 -0
- package/protocol/profiles/research-compilation.md +44 -0
- package/protocol/profiles/research-plan.md +39 -0
- package/protocol/profiles/restricted-evidence.md +15 -0
- package/runtime/bootstrap-autodl-runtime.sh +314 -0
- package/runtime/create-runtime-venv.sh +41 -0
- package/runtime/install-local-cpu-runtime.sh +23 -0
- package/runtime/install-scientific-runtime.sh +153 -0
- package/runtime/mineru/parse.py +62 -0
- package/runtime/mineru/requirements.txt +4 -0
- package/runtime/requirements-baseline.txt +38 -0
- package/schemas/cap/v2/activity.schema.json +47 -0
- package/schemas/cap/v2/agent.schema.json +32 -0
- package/schemas/cap/v2/assertion.schema.json +110 -0
- package/schemas/cap/v2/descriptor.schema.json +243 -0
- package/schemas/cap/v2/entity.schema.json +64 -0
- package/schemas/cap/v2/manifest.schema.json +67 -0
- package/schemas/cap/v2/relation.schema.json +82 -0
- package/schemas/compute-catalog.schema.json +63 -0
- package/schemas/compute-decision.schema.json +27 -0
- package/schemas/execution-contract.schema.json +1024 -0
- package/schemas/research-card.schema.json +30 -0
- package/schemas/research-inventory-draft.schema.json +366 -0
- package/schemas/research.schema.json +1044 -0
- package/schemas/result.schema.json +173 -0
- package/schemas/verification-policy.schema.json +47 -0
- package/schemas/verified-conclusion.schema.json +58 -0
- package/schemas/workspace-summary.schema.json +24 -0
- package/scripts/build-arkgraph-view.mjs +12 -0
- package/scripts/check-execution-feasibility.mjs +24 -0
- package/scripts/check-syntax.mjs +15 -0
- package/scripts/deterministic-asset-preparation.py +438 -0
- package/scripts/package-cap.mjs +23 -0
- package/scripts/package-local-agent.mjs +23 -0
- package/scripts/preview-arkgraph.mjs +25 -0
- package/scripts/replay-research-compiler-candidate.mjs +134 -0
- package/scripts/review-compiler-sources.mjs +44 -0
- package/scripts/run-asset-preparation.sh +17 -0
- package/scripts/run-research-plan.mjs +98 -0
- package/scripts/validate-asset-preparation.py +290 -0
- package/scripts/verify-local-runtime.mjs +57 -0
- package/scripts/verify-npm-package.mjs +57 -0
- package/src/adapters/paper2agent.mjs +107 -0
- package/src/assets/cache.mjs +159 -0
- package/src/assets/compute.mjs +98 -0
- package/src/assets/executor.mjs +145 -0
- package/src/assets/lifecycle.mjs +213 -0
- package/src/assets/manifest.mjs +242 -0
- package/src/assets/opportunistic-preparation.mjs +81 -0
- package/src/assets/plan.mjs +411 -0
- package/src/assets/prompts.mjs +29 -0
- package/src/assets/public-asset-probe.mjs +525 -0
- package/src/assets/qualification.mjs +119 -0
- package/src/assets/readiness.mjs +130 -0
- package/src/assets/reproduction-admission.mjs +355 -0
- package/src/assets/requirements.mjs +152 -0
- package/src/assets/source-grounding.mjs +341 -0
- package/src/assets/source-policy.mjs +118 -0
- package/src/autodl/client.mjs +260 -0
- package/src/autodl/ssh.mjs +380 -0
- package/src/autodl/tools.mjs +129 -0
- package/src/cap/redaction.mjs +38 -0
- package/src/cap/v2/archive.mjs +152 -0
- package/src/cap/v2/attestation.mjs +204 -0
- package/src/cap/v2/canonical-json.mjs +114 -0
- package/src/cap/v2/compilation-artifact.mjs +240 -0
- package/src/cap/v2/core.mjs +282 -0
- package/src/cap/v2/measurement-assessment-records.mjs +23 -0
- package/src/cap/v2/pipeline-artifact.mjs +922 -0
- package/src/cap/v2/read.mjs +41 -0
- package/src/cap/v2/reassessment-artifact.mjs +383 -0
- package/src/cap/v2/research-artifact.mjs +231 -0
- package/src/cap/v2/research-map-records.mjs +46 -0
- package/src/cap/v2/research-object-records.mjs +163 -0
- package/src/cap/v2/research-records.mjs +187 -0
- package/src/cap/v2/verify.mjs +642 -0
- package/src/cli.mjs +1146 -0
- package/src/compute/autodl-pro-compiler.mjs +347 -0
- package/src/compute/autodl-pro-executor.mjs +459 -0
- package/src/compute/autodl-pro-job.mjs +843 -0
- package/src/compute/autodl-pro-network.mjs +295 -0
- package/src/compute/autodl-pro-remote.mjs +810 -0
- package/src/compute/autodl-pro-staging.mjs +117 -0
- package/src/compute/campaign.mjs +110 -0
- package/src/compute/catalog.mjs +123 -0
- package/src/compute/checkpoint-protocol.mjs +154 -0
- package/src/compute/codex-account-lock.mjs +111 -0
- package/src/compute/codex-account-session.mjs +107 -0
- package/src/compute/compiler-profile.mjs +38 -0
- package/src/compute/compiler-router.mjs +23 -0
- package/src/compute/coordinator-recovery.mjs +210 -0
- package/src/compute/executor-router.mjs +29 -0
- package/src/compute/gcp-batch-compiler.mjs +685 -0
- package/src/compute/gcp-batch-executor.mjs +1215 -0
- package/src/compute/gcp-batch-failure.mjs +92 -0
- package/src/compute/gcp-batch-job.mjs +527 -0
- package/src/compute/gcp-batch-lifecycle.mjs +81 -0
- package/src/compute/gcp-checkpoint-worker.mjs +1633 -0
- package/src/compute/local-codex-compiler.mjs +52 -0
- package/src/compute/measurement-hardware.mjs +128 -0
- package/src/compute/remote-attempt.mjs +226 -0
- package/src/compute/requirements.mjs +124 -0
- package/src/compute/research-phases.mjs +48 -0
- package/src/compute/scheduler.mjs +452 -0
- package/src/compute/shared-workloads.mjs +26 -0
- package/src/compute/stage-archive.mjs +79 -0
- package/src/contracts/campaign-contract.mjs +52 -0
- package/src/contracts/execution-contract.mjs +819 -0
- package/src/contracts/execution-mode.mjs +19 -0
- package/src/contracts/execution-timeouts.mjs +45 -0
- package/src/contracts/execution-workload.mjs +68 -0
- package/src/contracts/preflight-schema.mjs +25 -0
- package/src/contracts/public-contract.mjs +63 -0
- package/src/contracts/subject-tags.mjs +31 -0
- package/src/dashboard/data.mjs +898 -0
- package/src/dashboard/server.mjs +79 -0
- package/src/dashboard/static/dashboard.css +366 -0
- package/src/dashboard/static/dashboard.js +560 -0
- package/src/dashboard/static/index.html +85 -0
- package/src/deployment/community-policy.mjs +9 -0
- package/src/deployment/environment.mjs +112 -0
- package/src/deployment/guided.mjs +98 -0
- package/src/deployment/handoff.mjs +102 -0
- package/src/deployment/local-contract.mjs +31 -0
- package/src/deployment/local.mjs +100 -0
- package/src/deployment/prepare.mjs +46 -0
- package/src/deployment/recipe.mjs +108 -0
- package/src/deployment/supplement.mjs +51 -0
- package/src/deployment/terminal.mjs +43 -0
- package/src/diagnosis/renderer.mjs +75 -0
- package/src/diagnosis/target-failure.mjs +46 -0
- package/src/evidence/parser-registry.mjs +54 -0
- package/src/evidence/parsers/fasttext-classification.mjs +82 -0
- package/src/evidence/parsers/json-scalar.mjs +96 -0
- package/src/evidence/parsers/simcse-senteval.mjs +104 -0
- package/src/evidence/parsers/starspace-classification.mjs +78 -0
- package/src/evidence/registry.mjs +147 -0
- package/src/execution/runner-audit.mjs +473 -0
- package/src/gcp/auth.mjs +106 -0
- package/src/gcp/batch-client.mjs +120 -0
- package/src/gcp/resource-discovery.mjs +177 -0
- package/src/gcp/rest.mjs +82 -0
- package/src/gcp/secret-manager.mjs +34 -0
- package/src/gcp/signed-url.mjs +133 -0
- package/src/gcp/storage.mjs +220 -0
- package/src/graph/command.mjs +41 -0
- package/src/graph/execution.mjs +97 -0
- package/src/graph/model.mjs +37 -0
- package/src/graph/presentation.mjs +110 -0
- package/src/graph/query.mjs +159 -0
- package/src/graph/research-relations.mjs +69 -0
- package/src/graph/source-page.mjs +12 -0
- package/src/graph/source-preview.mjs +34 -0
- package/src/graph/validate.mjs +76 -0
- package/src/job.mjs +496 -0
- package/src/network/autodl-routing-proxy.mjs +462 -0
- package/src/network/egress-proxy.mjs +158 -0
- package/src/observability/event-contract.mjs +230 -0
- package/src/observability/pipeline-monitor.mjs +166 -0
- package/src/pipeline/orchestrator.mjs +1281 -0
- package/src/pipeline/recovery-error.mjs +11 -0
- package/src/pipeline/replay.mjs +304 -0
- package/src/pipeline/shared-execution.mjs +115 -0
- package/src/pipeline/stage-checkpoint.mjs +86 -0
- package/src/pipeline/stage-recovery.mjs +101 -0
- package/src/pipeline/targets.mjs +110 -0
- package/src/process.mjs +143 -0
- package/src/protocol.mjs +312 -0
- package/src/provider/codex-account.mjs +44 -0
- package/src/provider/codex-completion.mjs +49 -0
- package/src/provider/completion.mjs +292 -0
- package/src/provider/model-client.mjs +44 -0
- package/src/provider/model-route.mjs +29 -0
- package/src/provider/openrouter-readiness.mjs +189 -0
- package/src/provider/reader-bridge.mjs +35 -0
- package/src/provider/relay.mjs +263 -0
- package/src/provider/runtime-auth.mjs +40 -0
- package/src/public/cap.d.mts +90 -0
- package/src/public/cap.mjs +12 -0
- package/src/public/contracts.d.mts +2 -0
- package/src/public/host.mjs +171 -0
- package/src/public/operations.d.mts +11 -0
- package/src/public/presentation.d.mts +4 -0
- package/src/records/views.mjs +26 -0
- package/src/remote/command.mjs +178 -0
- package/src/remote/ssh.mjs +59 -0
- package/src/repository-origin.mjs +81 -0
- package/src/reproduction/evidence-feedback.mjs +96 -0
- package/src/reproduction/incomplete-initialization.mjs +25 -0
- package/src/reproduction/lifecycle.mjs +253 -0
- package/src/reproduction/plan.mjs +132 -0
- package/src/reproduction/prompts.mjs +70 -0
- package/src/reproduction/runner.mjs +188 -0
- package/src/reproduction/summary.mjs +130 -0
- package/src/reproduction/workspace-mode.mjs +7 -0
- package/src/research/automatic-admission.mjs +156 -0
- package/src/research/compiler-coverage.mjs +85 -0
- package/src/research/compiler-failure.mjs +24 -0
- package/src/research/compiler-normalization-guards.mjs +112 -0
- package/src/research/compiler-repair.mjs +3 -0
- package/src/research/compiler.mjs +853 -0
- package/src/research/continuation-selection.mjs +26 -0
- package/src/research/execution-graph-context.mjs +43 -0
- package/src/research/experiment-importance.mjs +15 -0
- package/src/research/inventory-handoff.mjs +104 -0
- package/src/research/inventory-revisions.mjs +32 -0
- package/src/research/mineru-local.mjs +73 -0
- package/src/research/paper-command.mjs +19 -0
- package/src/research/paper-markdown.mjs +180 -0
- package/src/research/paper-source-map.mjs +69 -0
- package/src/research/planning-policy.mjs +88 -0
- package/src/research/reference-materials.mjs +11 -0
- package/src/research/reproduction-scope.mjs +30 -0
- package/src/research/research-map.mjs +94 -0
- package/src/research/research-objects.mjs +88 -0
- package/src/research/source-discovery.mjs +646 -0
- package/src/research/source-observations.mjs +75 -0
- package/src/research/source-review-cli-mcp.mjs +26 -0
- package/src/research/source-review-input.mjs +209 -0
- package/src/research/source-review-local-codex.mjs +36 -0
- package/src/research/source-review-model.mjs +70 -0
- package/src/research/source-review.mjs +173 -0
- package/src/research/structure.mjs +3163 -0
- package/src/research-card/renderer.mjs +277 -0
- package/src/research-card/verified-conclusion.mjs +143 -0
- package/src/results/output-registry.mjs +183 -0
- package/src/runtime/claude-code.mjs +52 -0
- package/src/runtime/codex-capacity-retry.mjs +87 -0
- package/src/runtime/codex.mjs +64 -0
- package/src/runtime/config.mjs +157 -0
- package/src/runtime/final-output.mjs +40 -0
- package/src/runtime/index.mjs +21 -0
- package/src/runtime/local-codex.mjs +74 -0
- package/src/runtime/opencode.mjs +95 -0
- package/src/runtime/prompt.mjs +13 -0
- package/src/sandbox/docker.mjs +363 -0
- package/src/settings/command.mjs +297 -0
- package/src/settings/store.mjs +119 -0
- package/src/telemetry/pricing.mjs +68 -0
- package/src/telemetry/usage.mjs +265 -0
- package/src/terminal/events.mjs +97 -0
- package/src/terminal/input.mjs +40 -0
- package/src/terminal/plain.mjs +40 -0
- package/src/terminal/remote-stream.mjs +22 -0
- package/src/terminal/screen.mjs +214 -0
- package/src/terminal/transcript.mjs +69 -0
- package/src/util.mjs +107 -0
- package/src/verification/ai-assessor.mjs +534 -0
- package/src/verification/claim-evaluator.mjs +242 -0
- package/src/verification/evidence-context.mjs +165 -0
- package/src/verification/evidence-reader.mjs +95 -0
- package/src/verification/integrity.mjs +570 -0
- package/src/verification/tolerance.mjs +32 -0
- package/src/workloads/cpu-research-preparation.mjs +56 -0
- package/src/workloads/definition.mjs +74 -0
- package/src/workloads/phase-aware-reproduction.mjs +46 -0
- package/src/workloads/reproduction.mjs +85 -0
- package/src/workspace/command.mjs +242 -0
- package/src/workspace/control.mjs +49 -0
- package/src/workspace/entry.mjs +28 -0
- package/src/workspace/input.mjs +93 -0
- package/src/workspace/interactive.mjs +94 -0
- package/src/workspace/jobs.mjs +418 -0
- package/src/workspace/session.mjs +97 -0
- package/src/workspace/worker.mjs +137 -0
- package/ui/arkgraph/ambient-motion.mjs +10 -0
- package/ui/arkgraph/app.jsx +153 -0
- package/ui/arkgraph/boot.js +6 -0
- package/ui/arkgraph/camera-motion.mjs +20 -0
- package/ui/arkgraph/context-reveal.mjs +39 -0
- package/ui/arkgraph/details.css +3 -0
- package/ui/arkgraph/entry.jsx +28 -0
- package/ui/arkgraph/experiment-curves.mjs +17 -0
- package/ui/arkgraph/experiment-selection.mjs +15 -0
- package/ui/arkgraph/experiment-style.css +26 -0
- package/ui/arkgraph/experiment-ui.jsx +32 -0
- package/ui/arkgraph/frame.html +1 -0
- package/ui/arkgraph/graph-gestures.mjs +62 -0
- package/ui/arkgraph/label-layout.mjs +57 -0
- package/ui/arkgraph/locales/en.json +229 -0
- package/ui/arkgraph/locales/source-types.json +15 -0
- package/ui/arkgraph/localization-build.mjs +27 -0
- package/ui/arkgraph/material-build.mjs +23 -0
- package/ui/arkgraph/material-colors.mjs +39 -0
- package/ui/arkgraph/material-style.css +15 -0
- package/ui/arkgraph/open-graph.jsx +326 -0
- package/ui/arkgraph/outline.jsx +49 -0
- package/ui/arkgraph/package-lock.json +888 -0
- package/ui/arkgraph/package.json +17 -0
- package/ui/arkgraph/reading-layout.mjs +130 -0
- package/ui/arkgraph/reading-presentation.mjs +73 -0
- package/ui/arkgraph/record-detail.css +51 -0
- package/ui/arkgraph/record-details.jsx +29 -0
- package/ui/arkgraph/research-types.mjs +31 -0
- package/ui/arkgraph/selection-mark.jsx +6 -0
- package/ui/arkgraph/soft-spine.mjs +26 -0
- package/ui/arkgraph/steering-style.css +187 -0
- package/ui/arkgraph/style.css +272 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { lstat, mkdtemp, readFile, rm } from "node:fs/promises";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
import { assembleResearchCompilationCap } from "../cap/v2/compilation-artifact.mjs";
|
|
6
|
+
import { captureProcess } from "../process.mjs";
|
|
7
|
+
import { CiteArkError, pathExists } from "../util.mjs";
|
|
8
|
+
|
|
9
|
+
/** Import one current Paper2Agent delivery without interpreting it as scientific truth. */
|
|
10
|
+
export async function assemblePaper2AgentCompilationCap({
|
|
11
|
+
directory,
|
|
12
|
+
inventory,
|
|
13
|
+
deliveryPath,
|
|
14
|
+
paper2AgentVersion,
|
|
15
|
+
runId,
|
|
16
|
+
createdAt,
|
|
17
|
+
signingKeyPath,
|
|
18
|
+
}) {
|
|
19
|
+
const delivery = await readPaper2AgentDelivery(deliveryPath);
|
|
20
|
+
const built = await assembleResearchCompilationCap({
|
|
21
|
+
directory,
|
|
22
|
+
inventory,
|
|
23
|
+
compiler: {
|
|
24
|
+
id: "paper2agent",
|
|
25
|
+
name: "Paper2Agent",
|
|
26
|
+
version: paper2AgentVersion ?? "current-skill-output",
|
|
27
|
+
capabilities: delivery.capabilities,
|
|
28
|
+
identity: { deliveryKind: delivery.kind },
|
|
29
|
+
},
|
|
30
|
+
runId,
|
|
31
|
+
createdAt,
|
|
32
|
+
signingKeyPath,
|
|
33
|
+
nativeOutputBytes: delivery.bytes,
|
|
34
|
+
nativeOutputMediaType: delivery.mediaType,
|
|
35
|
+
});
|
|
36
|
+
return { ...built, delivery };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export async function readPaper2AgentDelivery(deliveryPath) {
|
|
40
|
+
const source = path.resolve(deliveryPath);
|
|
41
|
+
let sourceStat;
|
|
42
|
+
try {
|
|
43
|
+
sourceStat = await lstat(source);
|
|
44
|
+
} catch {
|
|
45
|
+
throw new CiteArkError(`Paper2Agent 交付物不存在:${source}`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (sourceStat.isFile()) {
|
|
49
|
+
if (path.extname(source).toLowerCase() !== ".zip") {
|
|
50
|
+
throw new CiteArkError("Paper2Agent 文件交付物必须是 Paper2MCP ZIP");
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
source,
|
|
54
|
+
kind: "paper2mcp-zip",
|
|
55
|
+
capabilities: ["mcp-tools"],
|
|
56
|
+
mediaType: "application/zip",
|
|
57
|
+
bytes: await readFile(source),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (!sourceStat.isDirectory()) {
|
|
62
|
+
throw new CiteArkError("Paper2Agent 交付物必须是目录或 ZIP 文件");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const kind = await classifyDirectory(source);
|
|
66
|
+
const capabilities = kind === "combined-agent"
|
|
67
|
+
? ["mcp-tools", "paper-skill"]
|
|
68
|
+
: kind === "paper-skill"
|
|
69
|
+
? ["paper-skill"]
|
|
70
|
+
: ["mcp-tools"];
|
|
71
|
+
const temporary = await mkdtemp(path.join(os.tmpdir(), "citeark-paper2agent-"));
|
|
72
|
+
try {
|
|
73
|
+
const archivePath = path.join(temporary, "paper2agent-output.tar.gz");
|
|
74
|
+
const packed = await captureProcess(
|
|
75
|
+
"tar",
|
|
76
|
+
["-czf", archivePath, "--exclude=.DS_Store", "--exclude=._*", path.basename(source)],
|
|
77
|
+
{ cwd: path.dirname(source), env: { ...process.env, COPYFILE_DISABLE: "1" } },
|
|
78
|
+
);
|
|
79
|
+
if (packed.code !== 0) {
|
|
80
|
+
throw new CiteArkError(`无法封装 Paper2Agent 交付目录:${packed.stderr.trim()}`);
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
source,
|
|
84
|
+
kind,
|
|
85
|
+
capabilities,
|
|
86
|
+
mediaType: "application/gzip",
|
|
87
|
+
bytes: await readFile(archivePath),
|
|
88
|
+
};
|
|
89
|
+
} finally {
|
|
90
|
+
await rm(temporary, { recursive: true, force: true });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async function classifyDirectory(source) {
|
|
95
|
+
if (
|
|
96
|
+
await pathExists(path.join(source, "skill"))
|
|
97
|
+
&& await pathExists(path.join(source, "mcp"))
|
|
98
|
+
) return "combined-agent";
|
|
99
|
+
if (
|
|
100
|
+
await pathExists(path.join(source, "SKILL.md"))
|
|
101
|
+
&& await pathExists(path.join(source, "references", "paper.md"))
|
|
102
|
+
) return "paper-skill";
|
|
103
|
+
if (await pathExists(path.join(source, "USAGE.md"))) return "paper2mcp-directory";
|
|
104
|
+
throw new CiteArkError(
|
|
105
|
+
"无法识别 Paper2Agent 交付目录;应为组合 agent、paper skill 或解压后的 Paper2MCP 目录",
|
|
106
|
+
);
|
|
107
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { validateAssetPreparationManifest } from "./manifest.mjs";
|
|
2
|
+
import { sha256Value } from "../util.mjs";
|
|
3
|
+
|
|
4
|
+
export class GcsAssetCache {
|
|
5
|
+
constructor({ storage, bucket, sourceBucket = bucket, runtimeImage }) {
|
|
6
|
+
this.storage = storage;
|
|
7
|
+
this.bucket = bucket;
|
|
8
|
+
this.sourceBucket = sourceBucket;
|
|
9
|
+
this.runtimeImage = runtimeImage;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async lookup(plan) {
|
|
13
|
+
const key = cacheCompatibilityKey(plan, this.runtimeImage);
|
|
14
|
+
const object = planIndexObject(key);
|
|
15
|
+
const index = await this.storage.readJsonObject({
|
|
16
|
+
bucket: this.bucket,
|
|
17
|
+
object,
|
|
18
|
+
missing: null,
|
|
19
|
+
});
|
|
20
|
+
if (!validIndex(index, plan, this.runtimeImage)) {
|
|
21
|
+
return { hit: false, key, indexObject: object, reason: "missing_or_incompatible" };
|
|
22
|
+
}
|
|
23
|
+
const manifestIssues = validateAssetPreparationManifest(plan, index.manifest);
|
|
24
|
+
if (manifestIssues.length) {
|
|
25
|
+
return { hit: false, key, indexObject: object, reason: "manifest_invalid", issues: manifestIssues };
|
|
26
|
+
}
|
|
27
|
+
const objects = await this.storage.listObjects({
|
|
28
|
+
bucket: this.bucket,
|
|
29
|
+
prefix: `${index.checkpoint.checkpointPrefix}-full-`,
|
|
30
|
+
});
|
|
31
|
+
if (!objects.some((name) => name === index.checkpoint.object)) {
|
|
32
|
+
return { hit: false, key, indexObject: object, reason: "checkpoint_missing" };
|
|
33
|
+
}
|
|
34
|
+
const checkpointStatus = await this.storage.readJsonObject({
|
|
35
|
+
bucket: this.bucket,
|
|
36
|
+
object: index.checkpoint.checkpointStatus,
|
|
37
|
+
missing: null,
|
|
38
|
+
});
|
|
39
|
+
if (!validCheckpointStatus(checkpointStatus, index.checkpoint)) {
|
|
40
|
+
return { hit: false, key, indexObject: object, reason: "checkpoint_status_invalid" };
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
hit: true,
|
|
44
|
+
key,
|
|
45
|
+
indexObject: object,
|
|
46
|
+
manifest: index.manifest,
|
|
47
|
+
checkpoint: index.checkpoint,
|
|
48
|
+
createdAt: index.createdAt,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async publish(plan, manifest, checkpoint) {
|
|
53
|
+
const issues = validateAssetPreparationManifest(plan, manifest);
|
|
54
|
+
if (issues.length) throw new TypeError(`拒绝缓存无效资产清单:${issues.join(";")}`);
|
|
55
|
+
if (
|
|
56
|
+
!checkpoint?.object
|
|
57
|
+
|| checkpoint?.kind !== "full"
|
|
58
|
+
|| !/^sha256:[0-9a-f]{64}$/.test(String(checkpoint?.sha256))
|
|
59
|
+
) {
|
|
60
|
+
throw new TypeError("拒绝缓存没有完整检查点的资产准备结果");
|
|
61
|
+
}
|
|
62
|
+
const manifestHex = manifest.manifestDigest.slice("sha256:".length);
|
|
63
|
+
const canonicalPrefix = `citeark-asset-cache-manifest-${manifestHex}`;
|
|
64
|
+
const canonicalObject = `${canonicalPrefix}-full-${checkpoint.sequence}.tar.gz`;
|
|
65
|
+
if (checkpoint.object !== canonicalObject) {
|
|
66
|
+
await this.storage.copyObject({
|
|
67
|
+
sourceBucket: this.sourceBucket,
|
|
68
|
+
sourceObject: checkpoint.object,
|
|
69
|
+
destinationBucket: this.bucket,
|
|
70
|
+
destinationObject: canonicalObject,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
const canonicalCheckpoint = {
|
|
74
|
+
...checkpoint,
|
|
75
|
+
bucket: this.bucket,
|
|
76
|
+
checkpointPrefix: canonicalPrefix,
|
|
77
|
+
checkpointStatus: `${canonicalPrefix}-status.json`,
|
|
78
|
+
object: canonicalObject,
|
|
79
|
+
reason: "asset-preparation",
|
|
80
|
+
};
|
|
81
|
+
await this.storage.writeJsonObject({
|
|
82
|
+
bucket: this.bucket,
|
|
83
|
+
object: canonicalCheckpoint.checkpointStatus,
|
|
84
|
+
value: {
|
|
85
|
+
schemaVersion: "0.1",
|
|
86
|
+
sequence: canonicalCheckpoint.sequence,
|
|
87
|
+
kind: "full",
|
|
88
|
+
reason: "asset-preparation",
|
|
89
|
+
object: canonicalObject,
|
|
90
|
+
createdAt: canonicalCheckpoint.createdAt,
|
|
91
|
+
bytes: canonicalCheckpoint.bytes,
|
|
92
|
+
sha256: canonicalCheckpoint.sha256,
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
const key = cacheCompatibilityKey(plan, this.runtimeImage);
|
|
96
|
+
const index = {
|
|
97
|
+
schemaVersion: "0.1",
|
|
98
|
+
kind: "citeark.asset-cache-index",
|
|
99
|
+
key,
|
|
100
|
+
planDigest: plan.planDigest,
|
|
101
|
+
manifestDigest: manifest.manifestDigest,
|
|
102
|
+
runtimeImage: this.runtimeImage,
|
|
103
|
+
checkpoint: canonicalCheckpoint,
|
|
104
|
+
manifest,
|
|
105
|
+
createdAt: new Date().toISOString(),
|
|
106
|
+
};
|
|
107
|
+
await Promise.all([
|
|
108
|
+
this.storage.writeJsonObject({
|
|
109
|
+
bucket: this.bucket,
|
|
110
|
+
object: manifestIndexObject(manifestHex),
|
|
111
|
+
value: index,
|
|
112
|
+
}),
|
|
113
|
+
this.storage.writeJsonObject({
|
|
114
|
+
bucket: this.bucket,
|
|
115
|
+
object: planIndexObject(key),
|
|
116
|
+
value: index,
|
|
117
|
+
}),
|
|
118
|
+
]);
|
|
119
|
+
return index;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function cacheCompatibilityKey(plan, runtimeImage) {
|
|
124
|
+
return sha256Value({
|
|
125
|
+
schemaVersion: "0.1",
|
|
126
|
+
planDigest: plan?.planDigest ?? null,
|
|
127
|
+
runtimeImage: runtimeImage ?? null,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function validIndex(value, plan, runtimeImage) {
|
|
132
|
+
return value?.schemaVersion === "0.1"
|
|
133
|
+
&& value?.kind === "citeark.asset-cache-index"
|
|
134
|
+
&& value?.planDigest === plan?.planDigest
|
|
135
|
+
&& value?.runtimeImage === runtimeImage
|
|
136
|
+
&& value?.checkpoint?.kind === "full"
|
|
137
|
+
&& value?.checkpoint?.reason === "asset-preparation"
|
|
138
|
+
&& typeof value?.checkpoint?.checkpointPrefix === "string"
|
|
139
|
+
&& typeof value?.checkpoint?.object === "string"
|
|
140
|
+
&& /^sha256:[0-9a-f]{64}$/.test(String(value?.checkpoint?.sha256));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function validCheckpointStatus(value, checkpoint) {
|
|
144
|
+
return value?.schemaVersion === "0.1"
|
|
145
|
+
&& value?.sequence === checkpoint.sequence
|
|
146
|
+
&& value?.kind === "full"
|
|
147
|
+
&& value?.reason === "asset-preparation"
|
|
148
|
+
&& value?.object === checkpoint.object
|
|
149
|
+
&& value?.bytes === checkpoint.bytes
|
|
150
|
+
&& value?.sha256 === checkpoint.sha256;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function planIndexObject(key) {
|
|
154
|
+
return `citeark-asset-cache-plan-${key}.json`;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function manifestIndexObject(manifestHex) {
|
|
158
|
+
return `citeark-asset-cache-manifest-${manifestHex}.json`;
|
|
159
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { CiteArkError, sha256Value } from "../util.mjs";
|
|
2
|
+
|
|
3
|
+
export function selectAssetPreparationProfile(catalog, reproductionDecision, { profileOverride } = {}) {
|
|
4
|
+
const reproductionConfig = reproductionDecision?.selectedProfile?.executorConfig ?? {};
|
|
5
|
+
const runtimeImage = reproductionDecision?.environment?.image;
|
|
6
|
+
const requiredProvisioningModel = reproductionDecision?.policy?.requiredProvisioningModel;
|
|
7
|
+
const candidates = (Array.isArray(catalog?.profiles) ? catalog.profiles : [])
|
|
8
|
+
.filter((profile) => profile?.available !== false)
|
|
9
|
+
.filter((profile) => profile?.executor === "gcp-batch" && profile?.accelerator === "cpu")
|
|
10
|
+
.filter((profile) => !profileOverride || profile.id === profileOverride)
|
|
11
|
+
.filter((profile) => sameControlPlane(profile, reproductionConfig))
|
|
12
|
+
.filter((profile) => !runtimeImage || profile?.image === runtimeImage)
|
|
13
|
+
.filter((profile) => !requiredProvisioningModel
|
|
14
|
+
|| profile.executorConfig?.provisioningModel === requiredProvisioningModel)
|
|
15
|
+
.sort((left, right) => {
|
|
16
|
+
return (left.hourlyUsd ?? Number.POSITIVE_INFINITY)
|
|
17
|
+
- (right.hourlyUsd ?? Number.POSITIVE_INFINITY);
|
|
18
|
+
});
|
|
19
|
+
if (!candidates.length) {
|
|
20
|
+
throw new CiteArkError(`${profileOverride ? `指定的资产 profile ${profileOverride}` : "资产准备"} 需要可用的 GCP Batch CPU profile${runtimeImage ? ",并与复现任务使用同一镜像和 GCS 控制面" : ""},但计算目录中没有兼容项`, {
|
|
21
|
+
retryable: false,
|
|
22
|
+
failureCode: "asset_preparation.cpu_profile_missing",
|
|
23
|
+
failureCategory: "configuration",
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return candidates[0];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function createAssetPreparationComputeDecision({
|
|
30
|
+
profile,
|
|
31
|
+
contract,
|
|
32
|
+
experiment,
|
|
33
|
+
plan,
|
|
34
|
+
catalog,
|
|
35
|
+
researchRuntimeMinutes,
|
|
36
|
+
decidedAt = new Date().toISOString(),
|
|
37
|
+
}) {
|
|
38
|
+
const researchPreparation = researchRuntimeMinutes !== undefined;
|
|
39
|
+
if (researchPreparation && (!Number.isFinite(researchRuntimeMinutes) || researchRuntimeMinutes <= 0)) {
|
|
40
|
+
throw new CiteArkError("CPU 研究准备需要有限的累计科研时限");
|
|
41
|
+
}
|
|
42
|
+
// Full workspace preparation includes rereading, planning and dependencies.
|
|
43
|
+
// The legacy quick preflight limit must not truncate this research phase.
|
|
44
|
+
const timeoutMinutes = researchPreparation
|
|
45
|
+
? Math.min(researchRuntimeMinutes, profile.timeoutMinutes ?? researchRuntimeMinutes, 360)
|
|
46
|
+
: Math.max(15, Math.min(plan?.maxMinutes ?? 120, profile.timeoutMinutes ?? plan?.maxMinutes ?? 120));
|
|
47
|
+
const expectedHours = timeoutMinutes / 60;
|
|
48
|
+
const body = {
|
|
49
|
+
schemaVersion: "0.1",
|
|
50
|
+
kind: "citeark.operational-compute-decision",
|
|
51
|
+
workload: researchPreparation ? "research-preparation" : "asset-preparation",
|
|
52
|
+
experimentId: experiment?.id ?? null,
|
|
53
|
+
experimentVersionId: experiment?.versionId ?? null,
|
|
54
|
+
contractDigest: contract?.contractDigest ?? null,
|
|
55
|
+
planDigest: plan?.planDigest ?? null,
|
|
56
|
+
requirement: {
|
|
57
|
+
classification: "cpu-only",
|
|
58
|
+
accelerator: "none",
|
|
59
|
+
cpuCores: Math.min(profile.cpuCores ?? 4, 8),
|
|
60
|
+
memoryGb: Math.min(profile.memoryGb ?? 16, 32),
|
|
61
|
+
preemptionSafe: true,
|
|
62
|
+
},
|
|
63
|
+
selectedProfile: structuredClone(profile),
|
|
64
|
+
environment: {
|
|
65
|
+
image: profile.image,
|
|
66
|
+
timeoutMinutes,
|
|
67
|
+
cpus: Math.min(profile.cpuCores ?? 4, 8),
|
|
68
|
+
memoryGb: Math.min(profile.memoryGb ?? 16, 32),
|
|
69
|
+
shmGb: Math.max(1, Math.min(profile.shmGb ?? 2, 4)),
|
|
70
|
+
gpu: "none",
|
|
71
|
+
networkAccess: true,
|
|
72
|
+
},
|
|
73
|
+
estimate: {
|
|
74
|
+
durationMinutes: timeoutMinutes,
|
|
75
|
+
costUsd: typeof profile.hourlyUsd === "number"
|
|
76
|
+
? Number((expectedHours * profile.hourlyUsd).toFixed(6))
|
|
77
|
+
: null,
|
|
78
|
+
pricingKnown: typeof profile.hourlyUsd === "number",
|
|
79
|
+
},
|
|
80
|
+
catalogDigest: `sha256:${sha256Value(catalog)}`,
|
|
81
|
+
rationale: researchPreparation ? "在 CPU 延续研究工作区,时限取累计科研上限与 CPU 阶段上限,不受旧短预检限制。" : "在 GPU 分配前,用同一 GCS 控制面的低成本 CPU 工作负载准备并验证资产与任务隔离依赖环境。",
|
|
82
|
+
decidedAt,
|
|
83
|
+
scheduler: {
|
|
84
|
+
name: "citeark-asset-preparation-scheduler",
|
|
85
|
+
version: "0.1.0",
|
|
86
|
+
strategy: "same-control-plane-cheapest-cpu",
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
return { ...body, decisionDigest: `sha256:${sha256Value(body)}` };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function sameControlPlane(profile, config) {
|
|
93
|
+
const candidate = profile?.executorConfig ?? {};
|
|
94
|
+
if (!config.stagingBucket) return true;
|
|
95
|
+
return candidate.stagingBucket === config.stagingBucket
|
|
96
|
+
&& candidate.projectId === config.projectId
|
|
97
|
+
&& candidate.region === config.region;
|
|
98
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { GoogleAccessTokenProvider } from "../gcp/auth.mjs";
|
|
2
|
+
import { GcsStagingClient } from "../gcp/storage.mjs";
|
|
3
|
+
import { executeGcpBatchReproduction } from "../compute/gcp-batch-executor.mjs";
|
|
4
|
+
import { CiteArkError } from "../util.mjs";
|
|
5
|
+
import { GcsAssetCache } from "./cache.mjs";
|
|
6
|
+
import { createAssetPreparationWorkload, recordAssetCacheHit } from "./lifecycle.mjs";
|
|
7
|
+
|
|
8
|
+
export async function executeGcpAssetPreparation({
|
|
9
|
+
taskPath,
|
|
10
|
+
runsDirectory,
|
|
11
|
+
repositoryOverride,
|
|
12
|
+
paperOverride,
|
|
13
|
+
computeDecision,
|
|
14
|
+
assetPlan,
|
|
15
|
+
runId,
|
|
16
|
+
agentRuntime,
|
|
17
|
+
executorOptions = {},
|
|
18
|
+
dryRun = false,
|
|
19
|
+
progress = () => {},
|
|
20
|
+
}) {
|
|
21
|
+
const gcpOptions = executorOptions.gcpBatch ?? {};
|
|
22
|
+
const {
|
|
23
|
+
restoreCheckpointPrefix: _reproductionCheckpoint,
|
|
24
|
+
restoreCheckpointBucket: _reproductionCheckpointBucket,
|
|
25
|
+
assetPreparationRestoreCheckpointPrefix,
|
|
26
|
+
assetPreparationRestoreCheckpointBucket,
|
|
27
|
+
...assetGcpOptions
|
|
28
|
+
} = gcpOptions;
|
|
29
|
+
if (assetPreparationRestoreCheckpointPrefix) {
|
|
30
|
+
assetGcpOptions.restoreCheckpointPrefix = assetPreparationRestoreCheckpointPrefix;
|
|
31
|
+
if (assetPreparationRestoreCheckpointBucket) {
|
|
32
|
+
assetGcpOptions.restoreCheckpointBucket = assetPreparationRestoreCheckpointBucket;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const profile = computeDecision?.selectedProfile?.executorConfig ?? {};
|
|
36
|
+
const stagingBucket = gcpOptions.stagingBucket
|
|
37
|
+
?? profile.stagingBucket
|
|
38
|
+
?? process.env.CITEARK_GCP_STAGING_BUCKET;
|
|
39
|
+
const cacheBucket = gcpOptions.assetCacheBucket
|
|
40
|
+
?? process.env.CITEARK_GCP_ASSET_CACHE_BUCKET
|
|
41
|
+
?? stagingBucket;
|
|
42
|
+
if (!stagingBucket || !cacheBucket) throw new CiteArkError("资产准备缺少 GCS 暂存或缓存 bucket");
|
|
43
|
+
const clients = resolveAssetPreparationClients(
|
|
44
|
+
gcpOptions,
|
|
45
|
+
gcpOptions.assetPreparationClients ?? gcpOptions.clients,
|
|
46
|
+
);
|
|
47
|
+
const runtimeImage = computeDecision?.environment?.image;
|
|
48
|
+
const cache = new GcsAssetCache({
|
|
49
|
+
storage: clients.storage,
|
|
50
|
+
bucket: cacheBucket,
|
|
51
|
+
sourceBucket: stagingBucket,
|
|
52
|
+
runtimeImage,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
if (!dryRun && gcpOptions.disableAssetCache !== true) {
|
|
56
|
+
const cached = await cache.lookup(assetPlan);
|
|
57
|
+
if (cached.hit) {
|
|
58
|
+
progress(`资产准备命中已验证缓存 ${cached.manifest.manifestDigest}`);
|
|
59
|
+
const directories = await recordAssetCacheHit({
|
|
60
|
+
runsDirectory,
|
|
61
|
+
runId,
|
|
62
|
+
plan: assetPlan,
|
|
63
|
+
manifest: cached.manifest,
|
|
64
|
+
cache: cached,
|
|
65
|
+
});
|
|
66
|
+
return {
|
|
67
|
+
dryRun: false,
|
|
68
|
+
cacheHit: true,
|
|
69
|
+
directories,
|
|
70
|
+
manifest: cached.manifest,
|
|
71
|
+
checkpoint: cached.checkpoint,
|
|
72
|
+
usage: null,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
progress(`资产准备缓存未命中(${cached.reason}),启动低成本 CPU 工作负载`);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const execution = await executeGcpBatchReproduction({
|
|
79
|
+
taskPath,
|
|
80
|
+
runsDirectory,
|
|
81
|
+
repositoryOverride,
|
|
82
|
+
paperOverride,
|
|
83
|
+
computeDecision,
|
|
84
|
+
runId,
|
|
85
|
+
agentRuntime,
|
|
86
|
+
executorOptions: {
|
|
87
|
+
...executorOptions,
|
|
88
|
+
gcpBatch: {
|
|
89
|
+
...assetGcpOptions,
|
|
90
|
+
clients,
|
|
91
|
+
keepStaging: true,
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
workloadAdapter: createAssetPreparationWorkload(assetPlan),
|
|
95
|
+
dryRun,
|
|
96
|
+
progress,
|
|
97
|
+
});
|
|
98
|
+
if (dryRun) return execution;
|
|
99
|
+
|
|
100
|
+
const index = await cache.publish(assetPlan, execution.manifest, execution.checkpoint);
|
|
101
|
+
progress(`资产准备已按内容清单缓存 ${execution.manifest.manifestDigest}`);
|
|
102
|
+
await cleanupEphemeralPreparationObjects({
|
|
103
|
+
storage: clients.storage,
|
|
104
|
+
bucket: stagingBucket,
|
|
105
|
+
checkpoint: execution.checkpoint,
|
|
106
|
+
});
|
|
107
|
+
return {
|
|
108
|
+
...execution,
|
|
109
|
+
cacheHit: false,
|
|
110
|
+
checkpoint: index.checkpoint,
|
|
111
|
+
cache: {
|
|
112
|
+
key: index.key,
|
|
113
|
+
planDigest: index.planDigest,
|
|
114
|
+
manifestDigest: index.manifestDigest,
|
|
115
|
+
checkpoint: index.checkpoint,
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function resolveAssetPreparationClients(options = {}, injected = {}) {
|
|
121
|
+
const configured = {
|
|
122
|
+
authOptions: options.authOptions,
|
|
123
|
+
batchOptions: options.batchOptions,
|
|
124
|
+
storageOptions: options.storageOptions,
|
|
125
|
+
...(injected ?? {}),
|
|
126
|
+
};
|
|
127
|
+
if (configured.storage) return configured;
|
|
128
|
+
const auth = configured.auth ?? new GoogleAccessTokenProvider(configured.authOptions);
|
|
129
|
+
return {
|
|
130
|
+
...configured,
|
|
131
|
+
auth,
|
|
132
|
+
storage: new GcsStagingClient({
|
|
133
|
+
auth,
|
|
134
|
+
...(configured.storageOptions ?? {}),
|
|
135
|
+
}),
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async function cleanupEphemeralPreparationObjects({ storage, bucket, checkpoint }) {
|
|
140
|
+
const prefix = checkpoint?.checkpointPrefix;
|
|
141
|
+
if (!prefix || prefix.startsWith("citeark-asset-cache-manifest-")) return;
|
|
142
|
+
const runPrefix = prefix.replace(/-checkpoint-a\d+$/, "");
|
|
143
|
+
const objects = await storage.listObjects({ bucket, prefix: runPrefix }).catch(() => []);
|
|
144
|
+
await Promise.allSettled(objects.map((object) => storage.deleteObject({ bucket, object })));
|
|
145
|
+
}
|