@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,347 @@
|
|
|
1
|
+
import { recordResearchCleanup } from '../workspace/control.mjs';
|
|
2
|
+
import { restoreRunRecovery } from './coordinator-recovery.mjs';
|
|
3
|
+
import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
|
|
7
|
+
import { ensureFinalWorkspaceCapture, updateRunState } from "../job.mjs";
|
|
8
|
+
import {
|
|
9
|
+
acceptCompilerDraft,
|
|
10
|
+
compilerPrompt,
|
|
11
|
+
normalizeCompilationTask,
|
|
12
|
+
prepareCompilationBundle,
|
|
13
|
+
} from "../research/compiler.mjs";
|
|
14
|
+
import { agentInvocationPromptArgument, buildAgentInvocation } from "../runtime/index.mjs";
|
|
15
|
+
import { publicAgentRuntime, resolveAgentRuntime } from "../runtime/config.mjs";
|
|
16
|
+
import {
|
|
17
|
+
CODEX_FINAL_MESSAGE_PATH,
|
|
18
|
+
recoverJsonFromFinalMessage,
|
|
19
|
+
} from "../runtime/final-output.mjs";
|
|
20
|
+
import { readAgentUsage } from "../telemetry/usage.mjs";
|
|
21
|
+
import {
|
|
22
|
+
CiteArkError,
|
|
23
|
+
createRunId,
|
|
24
|
+
pathExists,
|
|
25
|
+
readJson,
|
|
26
|
+
writeJson,
|
|
27
|
+
} from "../util.mjs";
|
|
28
|
+
import { remoteProviderSession } from "./gcp-batch-job.mjs";
|
|
29
|
+
import {
|
|
30
|
+
classifyProviderActionRequired,
|
|
31
|
+
describeRemoteAgentFailure,
|
|
32
|
+
} from "./remote-attempt.mjs";
|
|
33
|
+
import {
|
|
34
|
+
acquireAutoDlProLease,
|
|
35
|
+
autoDlInstanceRequest,
|
|
36
|
+
resolveAutoDlProConfig,
|
|
37
|
+
} from "./autodl-pro-job.mjs";
|
|
38
|
+
import {
|
|
39
|
+
createAutoDlStageArchive,
|
|
40
|
+
executeAutoDlRemoteAttempt,
|
|
41
|
+
} from "./autodl-pro-remote.mjs";
|
|
42
|
+
|
|
43
|
+
export async function executeAutoDlProCompilation({
|
|
44
|
+
taskPath,
|
|
45
|
+
runsDirectory,
|
|
46
|
+
runId = createRunId(),
|
|
47
|
+
agentRuntime,
|
|
48
|
+
computeProfile,
|
|
49
|
+
executorOptions = {},
|
|
50
|
+
dryRun = false,
|
|
51
|
+
progress = () => {},
|
|
52
|
+
sourceReviewer,
|
|
53
|
+
prepareMarkdown,
|
|
54
|
+
validateResearch = async () => [],
|
|
55
|
+
}) {
|
|
56
|
+
assertCompilerProfile(computeProfile);
|
|
57
|
+
const absoluteTaskPath = path.resolve(taskPath);
|
|
58
|
+
const taskDirectory = path.dirname(absoluteTaskPath);
|
|
59
|
+
const task = normalizeCompilationTask(await readJson(absoluteTaskPath));
|
|
60
|
+
const runtimeAgent = resolveAgentRuntime({
|
|
61
|
+
taskAgent: task.agent,
|
|
62
|
+
...agentRuntime,
|
|
63
|
+
requireApi: false,
|
|
64
|
+
});
|
|
65
|
+
task.environment = {
|
|
66
|
+
...task.environment,
|
|
67
|
+
image: computeProfile.image,
|
|
68
|
+
cpus: computeProfile.cpuCores,
|
|
69
|
+
memoryGb: computeProfile.memoryGb,
|
|
70
|
+
gpu: computeProfile.accelerator === "gpu" ? "all" : "none",
|
|
71
|
+
};
|
|
72
|
+
const bundle = await restoreRunRecovery({ runsDirectory, runId }) ?? await prepareCompilationBundle({
|
|
73
|
+
task,
|
|
74
|
+
taskDirectory,
|
|
75
|
+
runsDirectory,
|
|
76
|
+
runId,
|
|
77
|
+
prepareMarkdown,
|
|
78
|
+
});
|
|
79
|
+
bundle.runtimeAgent = runtimeAgent;
|
|
80
|
+
bundle.computeDecision = {
|
|
81
|
+
schemaVersion: "0.1",
|
|
82
|
+
selectedProfile: structuredClone(computeProfile),
|
|
83
|
+
};
|
|
84
|
+
bundle.executionEnvironment = structuredClone(task.environment);
|
|
85
|
+
bundle.sandboxProvider = "autodl-pro";
|
|
86
|
+
await updateRunState(bundle, {
|
|
87
|
+
runtime: runtimeAgent.runtime,
|
|
88
|
+
agent: publicAgentRuntime(runtimeAgent),
|
|
89
|
+
sandbox: "autodl-pro",
|
|
90
|
+
image: task.environment.image,
|
|
91
|
+
executionEnvironment: bundle.executionEnvironment,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const instructions = await readFile(
|
|
95
|
+
path.join(bundle.directories.input, "agent-instructions.md"),
|
|
96
|
+
"utf8",
|
|
97
|
+
);
|
|
98
|
+
const autoDlOptions = executorOptions.autoDl ?? {};
|
|
99
|
+
const config = resolveAutoDlProConfig({
|
|
100
|
+
bundle,
|
|
101
|
+
options: autoDlOptions,
|
|
102
|
+
requireToken: !dryRun,
|
|
103
|
+
});
|
|
104
|
+
bundle.sourceReviewProviderSecret = config.providerSecret;
|
|
105
|
+
bundle.paperBudget = autoDlOptions.paperBudget;
|
|
106
|
+
const instanceRequest = autoDlInstanceRequest(config, bundle.runId);
|
|
107
|
+
await writeJson(
|
|
108
|
+
path.join(bundle.directories.execution, "autodl-instance-request.json"),
|
|
109
|
+
{ schemaVersion: "0.1", executor: "autodl-pro", instanceRequest },
|
|
110
|
+
);
|
|
111
|
+
if (dryRun) {
|
|
112
|
+
await updateRunState(bundle, { status: "prepared" });
|
|
113
|
+
return {
|
|
114
|
+
dryRun: true,
|
|
115
|
+
bundle,
|
|
116
|
+
instanceRequest,
|
|
117
|
+
cloud: publicAutoDlExecution(config, null, []),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const temporaryDirectory = await mkdtemp(
|
|
122
|
+
path.join(os.tmpdir(), "citeark-autodl-compiler-"),
|
|
123
|
+
);
|
|
124
|
+
const records = [];
|
|
125
|
+
let validationIssues = ["research.json 尚未生成"];
|
|
126
|
+
let normalizationWarnings = [];
|
|
127
|
+
let normalizedResearch = null;
|
|
128
|
+
let blockingFailure = null;
|
|
129
|
+
let lease = null;
|
|
130
|
+
let successful = false;
|
|
131
|
+
await mkdir(path.join(bundle.directories.execution, "prompts"), { recursive: true });
|
|
132
|
+
try {
|
|
133
|
+
await updateRunState(bundle, {
|
|
134
|
+
status: "running",
|
|
135
|
+
startedAt: new Date().toISOString(),
|
|
136
|
+
});
|
|
137
|
+
await autoDlOptions.assertActive?.();
|
|
138
|
+
lease = await acquireAutoDlProLease({
|
|
139
|
+
config,
|
|
140
|
+
runId: bundle.runId,
|
|
141
|
+
clients: autoDlOptions.clients,
|
|
142
|
+
progress,
|
|
143
|
+
});
|
|
144
|
+
await autoDlOptions.assertActive?.();
|
|
145
|
+
const maxAttempts = 1 + runtimeAgent.validationRetries;
|
|
146
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
|
|
147
|
+
const invocation = await buildAgentInvocation({
|
|
148
|
+
bundle,
|
|
149
|
+
attempt,
|
|
150
|
+
prompt: compilerPrompt(attempt, validationIssues, {
|
|
151
|
+
continuation: bundle.runtimeTask?.continuation,
|
|
152
|
+
repairBaseline: bundle.repairBaselineResearch,
|
|
153
|
+
}),
|
|
154
|
+
instructions,
|
|
155
|
+
providerSession: remoteProviderSession(runtimeAgent),
|
|
156
|
+
});
|
|
157
|
+
const resumeInvocation = await buildAgentInvocation({
|
|
158
|
+
bundle,
|
|
159
|
+
attempt: 2,
|
|
160
|
+
prompt: [
|
|
161
|
+
"Continue from the restored compilation workspace. Inspect preserved artifacts and apply the current task below; a prior research.json may still contain the rejected draft.",
|
|
162
|
+
compilerPrompt(attempt, validationIssues, {
|
|
163
|
+
continuation: bundle.runtimeTask?.continuation,
|
|
164
|
+
repairBaseline: bundle.repairBaselineResearch,
|
|
165
|
+
}),
|
|
166
|
+
].join("\n\n"),
|
|
167
|
+
instructions,
|
|
168
|
+
providerSession: remoteProviderSession(runtimeAgent),
|
|
169
|
+
});
|
|
170
|
+
await writeFile(
|
|
171
|
+
path.join(bundle.directories.execution, "prompts", `attempt-${attempt}.txt`),
|
|
172
|
+
`${agentInvocationPromptArgument(invocation)}\n`,
|
|
173
|
+
);
|
|
174
|
+
await writeFile(
|
|
175
|
+
path.join(bundle.directories.execution, "prompts", `attempt-${attempt}-resume.txt`),
|
|
176
|
+
`${agentInvocationPromptArgument(resumeInvocation)}\n`,
|
|
177
|
+
);
|
|
178
|
+
const stageArchive = path.join(temporaryDirectory, `compile-stage-a${attempt}.tar.gz`);
|
|
179
|
+
const resultArchive = path.join(temporaryDirectory, `compile-result-a${attempt}.tar.gz`);
|
|
180
|
+
await createAutoDlStageArchive(bundle, stageArchive);
|
|
181
|
+
const remote = await executeAutoDlRemoteAttempt({
|
|
182
|
+
bundle,
|
|
183
|
+
lease,
|
|
184
|
+
config,
|
|
185
|
+
invocation,
|
|
186
|
+
resumeInvocation,
|
|
187
|
+
attempt,
|
|
188
|
+
stageArchive,
|
|
189
|
+
resultArchive,
|
|
190
|
+
checkpointPolicy: config.checkpointing,
|
|
191
|
+
restoreCheckpointOnStart: attempt > 1,
|
|
192
|
+
reuseCompletedResultOnRestore: false,
|
|
193
|
+
completionRelativePath: "output/research.json",
|
|
194
|
+
completionHasEvidence: false,
|
|
195
|
+
secretManager: autoDlOptions.secretManager,
|
|
196
|
+
stageTransfer: autoDlOptions.stageTransfer,
|
|
197
|
+
stageClients: autoDlOptions.clients,
|
|
198
|
+
assertActive: autoDlOptions.assertActive,
|
|
199
|
+
progress,
|
|
200
|
+
});
|
|
201
|
+
records.push(remote.record);
|
|
202
|
+
const researchPath = path.join(bundle.directories.output, "research.json");
|
|
203
|
+
await recoverJsonFromFinalMessage({
|
|
204
|
+
finalMessagePath: hostRuntimePath(bundle, CODEX_FINAL_MESSAGE_PATH),
|
|
205
|
+
outputPath: researchPath,
|
|
206
|
+
});
|
|
207
|
+
const remoteFailure = await describeRemoteAgentFailure(bundle, attempt);
|
|
208
|
+
const providerFailure = classifyProviderActionRequired(remoteFailure?.message);
|
|
209
|
+
if (providerFailure) {
|
|
210
|
+
blockingFailure = providerFailure;
|
|
211
|
+
validationIssues = [providerFailure.message];
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
// A syntactically valid compiler file can still be an unfinished draft.
|
|
215
|
+
// Transport publication errors retain their independent recovery path.
|
|
216
|
+
if (remoteFailure && remoteFailure.failureCategory !== "publication") {
|
|
217
|
+
blockingFailure = { code: remoteFailure.failureCode ?? "compiler.agent_incomplete",
|
|
218
|
+
failureCategory: remoteFailure.failureCategory, retryable: remoteFailure.retryable };
|
|
219
|
+
validationIssues = [remoteFailure.message];
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
try {
|
|
223
|
+
if (!(await pathExists(researchPath))) {
|
|
224
|
+
throw new CiteArkError("缺少 /job/output/research.json");
|
|
225
|
+
}
|
|
226
|
+
const accepted = await acceptCompilerDraft({ bundle, draft: await readJson(researchPath), validateResearch, sourceReviewer });
|
|
227
|
+
normalizedResearch = accepted.research;
|
|
228
|
+
normalizationWarnings = accepted.normalizationWarnings;
|
|
229
|
+
validationIssues = [];
|
|
230
|
+
break;
|
|
231
|
+
} catch (error) {
|
|
232
|
+
validationIssues = [
|
|
233
|
+
...(remoteFailure ? [remoteFailure.message] : []),
|
|
234
|
+
error instanceof Error ? error.message : String(error),
|
|
235
|
+
];
|
|
236
|
+
if (error.failureCode === "compiler.source_review_unavailable") { blockingFailure = { code: error.failureCode, retryable: false }; break; }
|
|
237
|
+
if (attempt < maxAttempts) {
|
|
238
|
+
progress(`Research Compiler 结果校验失败,将在同一 AutoDL 实例继续:${validationIssues.join(";")}`);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
await ensureFinalWorkspaceCapture(bundle);
|
|
244
|
+
const usage = await readAgentUsage(
|
|
245
|
+
path.join(bundle.directories.execution, "trace.jsonl"),
|
|
246
|
+
{ runtimeHome: bundle.directories.runtimeHome, model: runtimeAgent.model },
|
|
247
|
+
);
|
|
248
|
+
const status = validationIssues.length ? "invalid_result" : "completed";
|
|
249
|
+
await updateRunState(bundle, {
|
|
250
|
+
status,
|
|
251
|
+
finishedAt: new Date().toISOString(),
|
|
252
|
+
validationIssues,
|
|
253
|
+
normalizationWarnings,
|
|
254
|
+
output: normalizedResearch ? "output/research.normalized.json" : null,
|
|
255
|
+
sandboxImageIdentity: {
|
|
256
|
+
id: config.imageUuid,
|
|
257
|
+
repositoryDigests: [],
|
|
258
|
+
},
|
|
259
|
+
cloudExecution: publicAutoDlExecution(config, lease, records),
|
|
260
|
+
usage,
|
|
261
|
+
});
|
|
262
|
+
if (validationIssues.length || !normalizedResearch) {
|
|
263
|
+
throw new CiteArkError(
|
|
264
|
+
`研究编译失败:\n- ${validationIssues.join("\n- ")}`,
|
|
265
|
+
{
|
|
266
|
+
exitCode: 2,
|
|
267
|
+
retryable: blockingFailure?.retryable,
|
|
268
|
+
failureCode: blockingFailure?.code,
|
|
269
|
+
failureCategory: blockingFailure?.failureCategory,
|
|
270
|
+
recoveryAction: blockingFailure?.recoveryAction,
|
|
271
|
+
},
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
successful = true;
|
|
275
|
+
return {
|
|
276
|
+
dryRun: false,
|
|
277
|
+
bundle,
|
|
278
|
+
research: normalizedResearch,
|
|
279
|
+
normalizationWarnings,
|
|
280
|
+
runs: records,
|
|
281
|
+
};
|
|
282
|
+
} catch (error) {
|
|
283
|
+
if (bundle.state.status === "running") {
|
|
284
|
+
await updateRunState(bundle, {
|
|
285
|
+
status: "failed",
|
|
286
|
+
finishedAt: new Date().toISOString(),
|
|
287
|
+
error: error instanceof Error ? error.message : String(error),
|
|
288
|
+
cloudExecution: publicAutoDlExecution(config, lease, records),
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
throw error;
|
|
292
|
+
} finally {
|
|
293
|
+
if (lease) {
|
|
294
|
+
const cleanup = await lease.close({ successful }).catch(error => ({ released: false, error: error.message }));
|
|
295
|
+
await recordResearchCleanup({ provider: 'autodl', resource: lease.instanceUuid, status: cleanup?.released ? 'released' : 'failed', ...(cleanup?.error ? { error: cleanup.error } : {}) });
|
|
296
|
+
}
|
|
297
|
+
await rm(temporaryDirectory, { recursive: true, force: true });
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function publicAutoDlExecution(config, lease, records) {
|
|
302
|
+
const runSeconds = records.reduce(
|
|
303
|
+
(total, record) => total + (Number(record.durationSeconds) || 0),
|
|
304
|
+
0,
|
|
305
|
+
);
|
|
306
|
+
const hourlyCny = lease?.observedHourlyCny ?? config.hourlyCny;
|
|
307
|
+
return {
|
|
308
|
+
provider: "autodl",
|
|
309
|
+
service: "container-instance-pro",
|
|
310
|
+
instance: lease?.publicRecord() ?? null,
|
|
311
|
+
gpuSpecUuid: lease?.config.gpuSpecUuid ?? config.gpuSpecUuid,
|
|
312
|
+
imageUuid: config.imageUuid,
|
|
313
|
+
inputStaging: {
|
|
314
|
+
preferred: config.stagingBucket && config.stageSigningServiceAccount
|
|
315
|
+
? "gcs-signed-url"
|
|
316
|
+
: "sftp",
|
|
317
|
+
fallback: "sftp",
|
|
318
|
+
signedUrlExpiresSeconds: config.stageSignedUrlExpiresSeconds,
|
|
319
|
+
},
|
|
320
|
+
credentialInjection: {
|
|
321
|
+
mode: "secret-manager-to-ephemeral-ssh-environment",
|
|
322
|
+
valueRecorded: false,
|
|
323
|
+
},
|
|
324
|
+
computeUsage: {
|
|
325
|
+
runSeconds,
|
|
326
|
+
observedHourlyCny: hourlyCny ?? null,
|
|
327
|
+
estimatedCostCny: typeof hourlyCny === "number"
|
|
328
|
+
? Number(((runSeconds / 3600) * hourlyCny).toFixed(6))
|
|
329
|
+
: null,
|
|
330
|
+
invoiceReconciled: false,
|
|
331
|
+
},
|
|
332
|
+
runs: structuredClone(records),
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function hostRuntimePath(bundle, containerPath) {
|
|
337
|
+
return path.join(bundle.directories.run, containerPath.replace(/^\/job\//, ""));
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function assertCompilerProfile(profile) {
|
|
341
|
+
if (!profile || profile.executor !== "autodl-pro") {
|
|
342
|
+
throw new CiteArkError("AutoDL Research Compiler 必须使用 autodl-pro 资源规格");
|
|
343
|
+
}
|
|
344
|
+
if (typeof profile.image !== "string" || !profile.image) {
|
|
345
|
+
throw new CiteArkError("AutoDL Research Compiler 资源规格必须声明私有镜像标识");
|
|
346
|
+
}
|
|
347
|
+
}
|