@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,314 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
CLAUDE_CODE_VERSION="${CLAUDE_CODE_VERSION:-2.1.227}"
|
|
5
|
+
CODEX_VERSION="${CODEX_VERSION:-0.159.1}"
|
|
6
|
+
OPENCODE_VERSION="${OPENCODE_VERSION:-1.18.14}"
|
|
7
|
+
RELAY_SOURCE="${RELAY_SOURCE:-/root/codex-pro-relay.mjs}"
|
|
8
|
+
BASELINE_REQUIREMENTS="${BASELINE_REQUIREMENTS:-/root/citeark-requirements-baseline.txt}"
|
|
9
|
+
RUNTIME_VENV_SOURCE="${RUNTIME_VENV_SOURCE:-/root/citeark-create-runtime-venv.sh}"
|
|
10
|
+
PYTHON_PACKAGE_INDEX="${PYTHON_PACKAGE_INDEX:-https://pypi.tuna.tsinghua.edu.cn/simple}"
|
|
11
|
+
PYTHON_PACKAGE_FALLBACK_INDEX="${PYTHON_PACKAGE_FALLBACK_INDEX:-https://mirrors.aliyun.com/pypi/simple}"
|
|
12
|
+
HUGGINGFACE_ENDPOINT="${HUGGINGFACE_ENDPOINT:-https://hf-mirror.com}"
|
|
13
|
+
PYTHON_RUNTIME="${PYTHON_RUNTIME:-/opt/citeark/miniconda3/bin/python}"
|
|
14
|
+
RUST_TOOLCHAIN_VERSION="${RUST_TOOLCHAIN_VERSION:-1.85.1}"
|
|
15
|
+
RUSTUP_DIST_SERVER="${RUSTUP_DIST_SERVER:-https://rsproxy.cn}"
|
|
16
|
+
RUSTUP_UPDATE_ROOT="${RUSTUP_UPDATE_ROOT:-https://rsproxy.cn/rustup}"
|
|
17
|
+
LEGACY_TOKENIZERS_SDIST_URL="${LEGACY_TOKENIZERS_SDIST_URL:-https://files.pythonhosted.org/packages/23/6e/89019979dc7a3a86f36da5de707cf2eec72046bcb8656305a26df5c85ca7/tokenizers-0.9.4.tar.gz}"
|
|
18
|
+
LEGACY_TOKENIZERS_SDIST_SHA256="${LEGACY_TOKENIZERS_SDIST_SHA256:-3ea3038008f1f74c8a1e1e2e73728690eed2d7fa4db0a51bcea391e644672426}"
|
|
19
|
+
|
|
20
|
+
export DEBIAN_FRONTEND=noninteractive
|
|
21
|
+
if [ -r /etc/network_turbo ]; then
|
|
22
|
+
# AutoDL 官方学术加速仅作用于本次镜像构建进程,不写入持久配置。
|
|
23
|
+
set +u
|
|
24
|
+
# shellcheck disable=SC1091
|
|
25
|
+
source /etc/network_turbo
|
|
26
|
+
set -u
|
|
27
|
+
fi
|
|
28
|
+
apt-get update
|
|
29
|
+
apt-get install -y --no-install-recommends \
|
|
30
|
+
build-essential \
|
|
31
|
+
ca-certificates \
|
|
32
|
+
cmake \
|
|
33
|
+
curl \
|
|
34
|
+
ffmpeg \
|
|
35
|
+
git \
|
|
36
|
+
git-lfs \
|
|
37
|
+
jq \
|
|
38
|
+
libgl1 \
|
|
39
|
+
libglib2.0-0 \
|
|
40
|
+
libgomp1 \
|
|
41
|
+
libsndfile1 \
|
|
42
|
+
libssl-dev \
|
|
43
|
+
ninja-build \
|
|
44
|
+
openssh-client \
|
|
45
|
+
pkg-config \
|
|
46
|
+
poppler-utils \
|
|
47
|
+
python3 \
|
|
48
|
+
python3-pip \
|
|
49
|
+
python3-venv \
|
|
50
|
+
rsync \
|
|
51
|
+
tar \
|
|
52
|
+
unzip \
|
|
53
|
+
util-linux \
|
|
54
|
+
wget
|
|
55
|
+
|
|
56
|
+
# AutoDL 学术代理适合 GitHub/HuggingFace,但会显著拖慢 npm/PyPI;
|
|
57
|
+
# 后续包管理恢复直连,任务运行时再由 CiteArk 的统一路由代理接管失败回退。
|
|
58
|
+
unset http_proxy https_proxy HTTP_PROXY HTTPS_PROXY all_proxy ALL_PROXY
|
|
59
|
+
|
|
60
|
+
if ! command -v node >/dev/null \
|
|
61
|
+
|| [ "$(node -p 'process.versions.node.split(`.`)[0]')" != "22" ] \
|
|
62
|
+
|| ! node --help 2>&1 | grep -q -- '--use-env-proxy'; then
|
|
63
|
+
curl -fsSL https://deb.nodesource.com/setup_22.x | bash -
|
|
64
|
+
apt-get install -y --no-install-recommends nodejs
|
|
65
|
+
fi
|
|
66
|
+
if ! node --help 2>&1 | grep -q -- '--use-env-proxy'; then
|
|
67
|
+
echo "Node.js 运行时缺少 --use-env-proxy" >&2
|
|
68
|
+
exit 1
|
|
69
|
+
fi
|
|
70
|
+
|
|
71
|
+
# 旧 Python 包可能需要源码编译,但仓库内的 rust-toolchain 常固定到
|
|
72
|
+
# 已无法解析当代依赖元数据的 Cargo。镜像构建时安装固定工具链并直接
|
|
73
|
+
# 暴露实际二进制,避免运行时 rustup 按项目覆盖成旧工具链。
|
|
74
|
+
RUSTUP_TEMP_HOME=/opt/citeark/rustup-build
|
|
75
|
+
RUSTUP_TEMP_CARGO_HOME=/opt/citeark/rustup-build-cargo
|
|
76
|
+
rm -rf /opt/citeark/rust "$RUSTUP_TEMP_HOME" "$RUSTUP_TEMP_CARGO_HOME"
|
|
77
|
+
curl --fail --silent --show-error --location --retry 5 --retry-all-errors \
|
|
78
|
+
--connect-timeout 15 --max-time 120 \
|
|
79
|
+
https://rsproxy.cn/rustup-init.sh -o /tmp/citeark-rustup-init.sh
|
|
80
|
+
RUSTUP_HOME="$RUSTUP_TEMP_HOME" \
|
|
81
|
+
CARGO_HOME="$RUSTUP_TEMP_CARGO_HOME" \
|
|
82
|
+
RUSTUP_DIST_SERVER="$RUSTUP_DIST_SERVER" \
|
|
83
|
+
RUSTUP_UPDATE_ROOT="$RUSTUP_UPDATE_ROOT" \
|
|
84
|
+
sh /tmp/citeark-rustup-init.sh -y --profile minimal \
|
|
85
|
+
--default-toolchain "$RUST_TOOLCHAIN_VERSION" --no-modify-path
|
|
86
|
+
RUST_TOOLCHAIN_SOURCE="$(find "$RUSTUP_TEMP_HOME/toolchains" -mindepth 1 -maxdepth 1 -type d -name "$RUST_TOOLCHAIN_VERSION-*" -print -quit)"
|
|
87
|
+
if [ -z "$RUST_TOOLCHAIN_SOURCE" ]; then
|
|
88
|
+
echo "未找到已安装的 Rust 工具链:$RUST_TOOLCHAIN_VERSION" >&2
|
|
89
|
+
exit 1
|
|
90
|
+
fi
|
|
91
|
+
mv "$RUST_TOOLCHAIN_SOURCE" /opt/citeark/rust
|
|
92
|
+
rm -rf "$RUSTUP_TEMP_HOME" "$RUSTUP_TEMP_CARGO_HOME" /tmp/citeark-rustup-init.sh
|
|
93
|
+
ln -sfn /opt/citeark/rust/bin/rustc /usr/local/bin/rustc
|
|
94
|
+
ln -sfn /opt/citeark/rust/bin/cargo /usr/local/bin/cargo
|
|
95
|
+
ln -sfn /opt/citeark/rust/bin/rustdoc /usr/local/bin/rustdoc
|
|
96
|
+
|
|
97
|
+
if ! id node >/dev/null 2>&1; then
|
|
98
|
+
useradd --create-home --uid 10001 --shell /bin/bash node
|
|
99
|
+
fi
|
|
100
|
+
|
|
101
|
+
npm install --global \
|
|
102
|
+
"@anthropic-ai/claude-code@${CLAUDE_CODE_VERSION}" \
|
|
103
|
+
"@openai/codex@${CODEX_VERSION}" \
|
|
104
|
+
"opencode-ai@${OPENCODE_VERSION}"
|
|
105
|
+
|
|
106
|
+
install -d -m 0755 /opt/citeark
|
|
107
|
+
if [ ! -e /opt/citeark/miniconda3 ] \
|
|
108
|
+
&& [ -d /root/miniconda3 ] \
|
|
109
|
+
&& [ ! -L /root/miniconda3 ]; then
|
|
110
|
+
mv /root/miniconda3 /opt/citeark/miniconda3
|
|
111
|
+
fi
|
|
112
|
+
if [ -d /opt/citeark/miniconda3 ]; then
|
|
113
|
+
ln -sfn /opt/citeark/miniconda3 /root/miniconda3
|
|
114
|
+
chmod 0755 /opt/citeark/miniconda3
|
|
115
|
+
fi
|
|
116
|
+
|
|
117
|
+
if [ ! -r "$BASELINE_REQUIREMENTS" ]; then
|
|
118
|
+
echo "缺少 AutoDL 基线 Python 依赖清单:$BASELINE_REQUIREMENTS" >&2
|
|
119
|
+
exit 1
|
|
120
|
+
fi
|
|
121
|
+
if [ ! -r "$RUNTIME_VENV_SOURCE" ]; then
|
|
122
|
+
echo "缺少 AutoDL 运行虚拟环境脚本:$RUNTIME_VENV_SOURCE" >&2
|
|
123
|
+
exit 1
|
|
124
|
+
fi
|
|
125
|
+
if [ ! -x "$PYTHON_RUNTIME" ]; then
|
|
126
|
+
PYTHON_RUNTIME="$(command -v python3)"
|
|
127
|
+
fi
|
|
128
|
+
|
|
129
|
+
# 不把前一次镜像构建期间未完成或已经失去约束的包下载固化进镜像;
|
|
130
|
+
# 最终基线安装产生的 pip wheel 缓存仍会保留给运行任务使用。
|
|
131
|
+
rm -rf /opt/citeark/cache/pip /opt/citeark/cache/uv
|
|
132
|
+
install -d -m 1777 \
|
|
133
|
+
/opt/citeark/cache \
|
|
134
|
+
/opt/citeark/cache/cargo \
|
|
135
|
+
/opt/citeark/cache/huggingface \
|
|
136
|
+
/opt/citeark/cache/pip \
|
|
137
|
+
/opt/citeark/cache/torch \
|
|
138
|
+
/opt/citeark/cache/uv
|
|
139
|
+
chown -R root:root /opt/citeark/cache
|
|
140
|
+
cat > /opt/citeark/cache/cargo/config.toml <<'EOF'
|
|
141
|
+
[source.crates-io]
|
|
142
|
+
replace-with = "rsproxy-sparse"
|
|
143
|
+
|
|
144
|
+
[source.rsproxy-sparse]
|
|
145
|
+
registry = "sparse+https://rsproxy.cn/index/"
|
|
146
|
+
|
|
147
|
+
[net]
|
|
148
|
+
git-fetch-with-cli = true
|
|
149
|
+
EOF
|
|
150
|
+
rm -rf /opt/citeark/venv
|
|
151
|
+
"$PYTHON_RUNTIME" -m venv --system-site-packages /opt/citeark/venv
|
|
152
|
+
pip_install_with_domestic_fallback() {
|
|
153
|
+
local index
|
|
154
|
+
for index in "$PYTHON_PACKAGE_INDEX" "$PYTHON_PACKAGE_FALLBACK_INDEX"; do
|
|
155
|
+
if PIP_CACHE_DIR=/opt/citeark/cache/pip \
|
|
156
|
+
PIP_INDEX_URL="$index" \
|
|
157
|
+
PIP_DEFAULT_TIMEOUT=60 \
|
|
158
|
+
PIP_RETRIES=8 \
|
|
159
|
+
/opt/citeark/venv/bin/python -m pip install "$@"; then
|
|
160
|
+
return 0
|
|
161
|
+
fi
|
|
162
|
+
printf '%s\n' "Python 镜像源失败,切换国内备用源:$index" >&2
|
|
163
|
+
done
|
|
164
|
+
return 1
|
|
165
|
+
}
|
|
166
|
+
pip_install_with_domestic_fallback --upgrade pip setuptools uv wheel
|
|
167
|
+
pip_install_with_domestic_fallback \
|
|
168
|
+
--upgrade-strategy only-if-needed \
|
|
169
|
+
--requirement "$BASELINE_REQUIREMENTS"
|
|
170
|
+
if ! /opt/citeark/venv/bin/python -c 'import torch' >/dev/null 2>&1; then
|
|
171
|
+
pip_install_with_domestic_fallback torch torchvision
|
|
172
|
+
fi
|
|
173
|
+
TORCH_PUBLIC_VERSION="$(/opt/citeark/venv/bin/python -c 'import torch; print(torch.__version__.split("+")[0])')"
|
|
174
|
+
if ! /opt/citeark/venv/bin/python -c 'import torchaudio' >/dev/null 2>&1; then
|
|
175
|
+
pip_install_with_domestic_fallback \
|
|
176
|
+
--upgrade-strategy only-if-needed \
|
|
177
|
+
"torchaudio==$TORCH_PUBLIC_VERSION"
|
|
178
|
+
fi
|
|
179
|
+
|
|
180
|
+
# tokenizers 0.9.4 没有 CPython 3.10 wheel,且其 Rust 清单没有锁定
|
|
181
|
+
# serde。今天直接构建会拉到已经移除 serde::export 的版本。只固定
|
|
182
|
+
# 构建期 serde 到该包发布年代的兼容版本,包版本和运行时代码不变。
|
|
183
|
+
LEGACY_WHEELHOUSE=/opt/citeark/wheels
|
|
184
|
+
LEGACY_BUILD_ROOT=/tmp/citeark-tokenizers-0.9.4-build
|
|
185
|
+
rm -rf "$LEGACY_WHEELHOUSE" "$LEGACY_BUILD_ROOT"
|
|
186
|
+
install -d -m 0755 "$LEGACY_WHEELHOUSE" "$LEGACY_BUILD_ROOT"
|
|
187
|
+
curl --fail --silent --show-error --location --retry 5 --retry-all-errors \
|
|
188
|
+
--connect-timeout 15 --max-time 120 \
|
|
189
|
+
"$LEGACY_TOKENIZERS_SDIST_URL" -o "$LEGACY_BUILD_ROOT/tokenizers-0.9.4.tar.gz"
|
|
190
|
+
printf '%s %s\n' "$LEGACY_TOKENIZERS_SDIST_SHA256" "$LEGACY_BUILD_ROOT/tokenizers-0.9.4.tar.gz" \
|
|
191
|
+
| sha256sum --check --status
|
|
192
|
+
tar -xzf "$LEGACY_BUILD_ROOT/tokenizers-0.9.4.tar.gz" -C "$LEGACY_BUILD_ROOT"
|
|
193
|
+
for manifest in \
|
|
194
|
+
"$LEGACY_BUILD_ROOT/tokenizers-0.9.4/Cargo.toml" \
|
|
195
|
+
"$LEGACY_BUILD_ROOT/tokenizers-0.9.4/tokenizers-lib/Cargo.toml"; do
|
|
196
|
+
sed -i 's/serde = { version = "1.0",/serde = { version = "=1.0.118",/' "$manifest"
|
|
197
|
+
grep -q 'serde = { version = "=1.0.118",' "$manifest"
|
|
198
|
+
done
|
|
199
|
+
CARGO_HOME=/opt/citeark/cache/cargo \
|
|
200
|
+
CARGO_NET_GIT_FETCH_WITH_CLI=true \
|
|
201
|
+
RUSTFLAGS='-A invalid_reference_casting' \
|
|
202
|
+
UV_CONFIG_FILE=/dev/null \
|
|
203
|
+
UV_INDEX="$PYTHON_PACKAGE_INDEX" \
|
|
204
|
+
UV_DEFAULT_INDEX="$PYTHON_PACKAGE_FALLBACK_INDEX" \
|
|
205
|
+
UV_INDEX_STRATEGY=first-index \
|
|
206
|
+
/opt/citeark/venv/bin/uv build \
|
|
207
|
+
--python /usr/bin/python3.10 --wheel \
|
|
208
|
+
"$LEGACY_BUILD_ROOT/tokenizers-0.9.4" \
|
|
209
|
+
--out-dir "$LEGACY_WHEELHOUSE"
|
|
210
|
+
LEGACY_TOKENIZERS_WHEEL="$(find "$LEGACY_WHEELHOUSE" -maxdepth 1 -type f -name 'tokenizers-0.9.4-cp310-*.whl' -print -quit)"
|
|
211
|
+
if [ -z "$LEGACY_TOKENIZERS_WHEEL" ]; then
|
|
212
|
+
echo "未生成 tokenizers 0.9.4 的 CPython 3.10 wheel" >&2
|
|
213
|
+
exit 1
|
|
214
|
+
fi
|
|
215
|
+
LEGACY_TOKENIZERS_WHEEL_SHA256="$(sha256sum "$LEGACY_TOKENIZERS_WHEEL" | cut -d' ' -f1)"
|
|
216
|
+
jq -n \
|
|
217
|
+
--arg package "tokenizers==0.9.4" \
|
|
218
|
+
--arg sourceSha256 "$LEGACY_TOKENIZERS_SDIST_SHA256" \
|
|
219
|
+
--argjson buildConstraints '["serde==1.0.118","RUSTFLAGS=-A invalid_reference_casting"]' \
|
|
220
|
+
--arg wheel "$(basename "$LEGACY_TOKENIZERS_WHEEL")" \
|
|
221
|
+
--arg wheelSha256 "$LEGACY_TOKENIZERS_WHEEL_SHA256" \
|
|
222
|
+
'{schemaVersion:"0.1",package:$package,sourceSha256:$sourceSha256,buildConstraints:$buildConstraints,wheel:$wheel,wheelSha256:$wheelSha256}' \
|
|
223
|
+
> "$LEGACY_WHEELHOUSE/tokenizers-0.9.4-cp310-provenance.json"
|
|
224
|
+
rm -rf "$LEGACY_BUILD_ROOT"
|
|
225
|
+
|
|
226
|
+
cat > /etc/pip.conf <<EOF
|
|
227
|
+
[global]
|
|
228
|
+
index-url = $PYTHON_PACKAGE_INDEX
|
|
229
|
+
find-links = $LEGACY_WHEELHOUSE
|
|
230
|
+
timeout = 60
|
|
231
|
+
retries = 8
|
|
232
|
+
disable-pip-version-check = true
|
|
233
|
+
EOF
|
|
234
|
+
cat > /etc/profile.d/citeark-python-index.sh <<EOF
|
|
235
|
+
export UV_CONFIG_FILE="/dev/null"
|
|
236
|
+
export PIP_INDEX_URL="$PYTHON_PACKAGE_INDEX"
|
|
237
|
+
export PIP_DEFAULT_TIMEOUT="60"
|
|
238
|
+
export PIP_RETRIES="8"
|
|
239
|
+
export UV_INDEX="$PYTHON_PACKAGE_INDEX"
|
|
240
|
+
export UV_DEFAULT_INDEX="$PYTHON_PACKAGE_FALLBACK_INDEX"
|
|
241
|
+
export UV_INDEX_STRATEGY="first-index"
|
|
242
|
+
export UV_HTTP_TIMEOUT="60"
|
|
243
|
+
export UV_HTTP_RETRIES="8"
|
|
244
|
+
export PIP_FIND_LINKS="$LEGACY_WHEELHOUSE"
|
|
245
|
+
export UV_FIND_LINKS="$LEGACY_WHEELHOUSE"
|
|
246
|
+
export CARGO_HOME="/opt/citeark/cache/cargo"
|
|
247
|
+
export CARGO_NET_GIT_FETCH_WITH_CLI="true"
|
|
248
|
+
export HF_ENDPOINT="$HUGGINGFACE_ENDPOINT"
|
|
249
|
+
export HF_HUB_ETAG_TIMEOUT="30"
|
|
250
|
+
export HF_HUB_DOWNLOAD_TIMEOUT="120"
|
|
251
|
+
EOF
|
|
252
|
+
chmod 0644 /etc/pip.conf /etc/profile.d/citeark-python-index.sh
|
|
253
|
+
|
|
254
|
+
install -m 0644 "$RELAY_SOURCE" /opt/citeark/codex-pro-relay.mjs
|
|
255
|
+
install -m 0644 "$BASELINE_REQUIREMENTS" /opt/citeark/requirements-baseline.txt
|
|
256
|
+
install -m 0555 "$RUNTIME_VENV_SOURCE" /opt/citeark/create-runtime-venv.sh
|
|
257
|
+
ln -sfn /opt/citeark/venv/bin/uv /usr/local/bin/uv
|
|
258
|
+
chown -R node:node /opt/citeark/cache /opt/citeark/venv
|
|
259
|
+
install -d -o node -g node -m 0700 /root/citeark
|
|
260
|
+
|
|
261
|
+
NODE_VERSION="$(node --version)"
|
|
262
|
+
PYTHON_VERSION="$(/opt/citeark/venv/bin/python --version 2>&1)"
|
|
263
|
+
TORCH_VERSION="$(/opt/citeark/venv/bin/python -c 'import torch; print(torch.__version__)')"
|
|
264
|
+
TORCH_CUDA="$(/opt/citeark/venv/bin/python -c 'import torch; print(torch.version.cuda or "none")')"
|
|
265
|
+
RUST_VERSION="$(rustc --version)"
|
|
266
|
+
CARGO_VERSION="$(cargo --version)"
|
|
267
|
+
jq -n \
|
|
268
|
+
--arg builtAt "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
|
|
269
|
+
--arg node "$NODE_VERSION" \
|
|
270
|
+
--arg python "$PYTHON_VERSION" \
|
|
271
|
+
--arg torch "$TORCH_VERSION" \
|
|
272
|
+
--arg torchCuda "$TORCH_CUDA" \
|
|
273
|
+
--arg rust "$RUST_VERSION" \
|
|
274
|
+
--arg cargo "$CARGO_VERSION" \
|
|
275
|
+
--arg legacyTokenizersWheelSha256 "$LEGACY_TOKENIZERS_WHEEL_SHA256" \
|
|
276
|
+
--arg pythonPackageIndex "$PYTHON_PACKAGE_INDEX" \
|
|
277
|
+
--arg pythonPackageFallbackIndex "$PYTHON_PACKAGE_FALLBACK_INDEX" \
|
|
278
|
+
'{schemaVersion:"0.1",profile:"citeark-autodl-research-baseline",builtAt:$builtAt,node:$node,python:$python,torch:$torch,torchCuda:$torchCuda,rust:$rust,cargo:$cargo,legacyTokenizersWheelSha256:$legacyTokenizersWheelSha256,pythonPackageIndex:$pythonPackageIndex,pythonPackageFallbackIndex:$pythonPackageFallbackIndex}' \
|
|
279
|
+
> /opt/citeark/runtime-manifest.json
|
|
280
|
+
/opt/citeark/venv/bin/python -m pip freeze \
|
|
281
|
+
> /opt/citeark/python-packages.lock
|
|
282
|
+
|
|
283
|
+
claude --version
|
|
284
|
+
codex --version
|
|
285
|
+
opencode --version
|
|
286
|
+
node --version
|
|
287
|
+
python3 --version
|
|
288
|
+
jq --version
|
|
289
|
+
rustc --version
|
|
290
|
+
cargo --version
|
|
291
|
+
/opt/citeark/venv/bin/python -c 'import numpy, pandas, pydantic, scipy, sklearn, soundfile, torch, torchaudio, transformers, yaml; print("baseline scientific stack: ready"); print("torch cuda available:", torch.cuda.is_available())'
|
|
292
|
+
runuser -u node -- env HOME=/home/node \
|
|
293
|
+
/opt/citeark/venv/bin/python -c 'import numpy, pandas, pydantic, scipy, sklearn, soundfile, torch, torchaudio, transformers, yaml; print("node user scientific stack: ready"); print("node user torch cuda available:", torch.cuda.is_available())'
|
|
294
|
+
RUNTIME_SMOKE_ENV=/tmp/citeark-runtime-venv-smoke
|
|
295
|
+
rm -rf "$RUNTIME_SMOKE_ENV"
|
|
296
|
+
/opt/citeark/create-runtime-venv.sh "$RUNTIME_SMOKE_ENV"
|
|
297
|
+
runuser -u node -- env \
|
|
298
|
+
HOME=/home/node \
|
|
299
|
+
"$RUNTIME_SMOKE_ENV/bin/python" -c 'import numpy, scipy, soundfile, torch, torchaudio, yaml; print("isolated runtime scientific stack: ready"); print("runtime torch cuda available:", torch.cuda.is_available())'
|
|
300
|
+
rm -rf "$RUNTIME_SMOKE_ENV"
|
|
301
|
+
LEGACY_SMOKE_ENV=/tmp/citeark-tokenizers-smoke
|
|
302
|
+
rm -rf "$LEGACY_SMOKE_ENV"
|
|
303
|
+
runuser -u node -- env HOME=/home/node UV_CONFIG_FILE=/dev/null \
|
|
304
|
+
/opt/citeark/venv/bin/uv venv --python /usr/bin/python3.10 "$LEGACY_SMOKE_ENV"
|
|
305
|
+
runuser -u node -- env HOME=/home/node UV_CONFIG_FILE=/dev/null \
|
|
306
|
+
UV_FIND_LINKS="$LEGACY_WHEELHOUSE" \
|
|
307
|
+
/opt/citeark/venv/bin/uv pip install --python "$LEGACY_SMOKE_ENV/bin/python" \
|
|
308
|
+
--no-index --no-deps tokenizers==0.9.4
|
|
309
|
+
runuser -u node -- env HOME=/home/node \
|
|
310
|
+
"$LEGACY_SMOKE_ENV/bin/python" -c 'import tokenizers; assert tokenizers.__version__ == "0.9.4"; print("legacy tokenizers wheel: ready")'
|
|
311
|
+
rm -rf "$LEGACY_SMOKE_ENV"
|
|
312
|
+
cat /opt/citeark/runtime-manifest.json
|
|
313
|
+
|
|
314
|
+
echo "CiteArk AutoDL runtime bootstrap completed. Save this instance as a private image before production use."
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
TARGET_VIRTUAL_ENV="${1:-/job/runtime-venv}"
|
|
5
|
+
BASE_VIRTUAL_ENV="${CITEARK_BASE_VIRTUAL_ENV:-/opt/citeark/venv}"
|
|
6
|
+
BASE_PYTHON="$BASE_VIRTUAL_ENV/bin/python"
|
|
7
|
+
|
|
8
|
+
if [ ! -x "$BASE_PYTHON" ]; then
|
|
9
|
+
printf '%s\n' "CiteArk Python 基线不存在:$BASE_PYTHON" >&2
|
|
10
|
+
exit 70
|
|
11
|
+
fi
|
|
12
|
+
|
|
13
|
+
if [ ! -x "$TARGET_VIRTUAL_ENV/bin/python" ]; then
|
|
14
|
+
"$BASE_PYTHON" -m venv --system-site-packages "$TARGET_VIRTUAL_ENV"
|
|
15
|
+
fi
|
|
16
|
+
|
|
17
|
+
BASE_SITE_PACKAGES="$($BASE_PYTHON - <<'PY'
|
|
18
|
+
import os
|
|
19
|
+
import sys
|
|
20
|
+
|
|
21
|
+
seen = set()
|
|
22
|
+
for value in sys.path:
|
|
23
|
+
path = os.path.realpath(value or "")
|
|
24
|
+
if not path or path in seen or not os.path.isdir(path):
|
|
25
|
+
continue
|
|
26
|
+
if os.path.basename(path) not in {"site-packages", "dist-packages"}:
|
|
27
|
+
continue
|
|
28
|
+
seen.add(path)
|
|
29
|
+
print(path)
|
|
30
|
+
PY
|
|
31
|
+
)"
|
|
32
|
+
if [ -z "$BASE_SITE_PACKAGES" ]; then
|
|
33
|
+
printf '%s\n' "CiteArk Python 基线没有可继承的 site-packages" >&2
|
|
34
|
+
exit 70
|
|
35
|
+
fi
|
|
36
|
+
|
|
37
|
+
TARGET_SITE_PACKAGES="$($TARGET_VIRTUAL_ENV/bin/python -c 'import site; print(site.getsitepackages()[0])')"
|
|
38
|
+
PTH_PATH="$TARGET_SITE_PACKAGES/citeark-base-runtime.pth"
|
|
39
|
+
printf '%s\n' "$BASE_SITE_PACKAGES" > "$PTH_PATH.tmp"
|
|
40
|
+
mv "$PTH_PATH.tmp" "$PTH_PATH"
|
|
41
|
+
chown -R node:node "$TARGET_VIRTUAL_ENV"
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
python3.12 -m venv /opt/citeark/venv
|
|
5
|
+
/opt/citeark/venv/bin/python -m pip install --no-cache-dir --upgrade pip setuptools wheel
|
|
6
|
+
/opt/citeark/venv/bin/python -m pip install --no-cache-dir \
|
|
7
|
+
--index-url https://download.pytorch.org/whl/cpu \
|
|
8
|
+
torch==2.8.0 torchvision==0.23.0 torchaudio==2.8.0
|
|
9
|
+
/opt/citeark/venv/bin/python -m pip install --no-cache-dir \
|
|
10
|
+
numpy==1.26.4 scipy==1.17.1 pandas==2.2.3 matplotlib==3.10.8 \
|
|
11
|
+
scikit-learn==1.7.2 pyyaml==6.0.3 jsonschema==4.26.0 tqdm==4.67.3
|
|
12
|
+
/opt/citeark/venv/bin/python - <<'PY'
|
|
13
|
+
import json, pathlib, platform, numpy, scipy, torch, torchvision, torchaudio
|
|
14
|
+
assert torch.version.cuda is None
|
|
15
|
+
assert torchvision.ops.nms(torch.tensor([[0.,0.,2.,2.]]), torch.tensor([1.]), 0.5).tolist() == [0]
|
|
16
|
+
pathlib.Path('/opt/citeark/runtime-manifest.json').write_text(json.dumps({
|
|
17
|
+
'schemaVersion':'0.2', 'profile':'local-cpu', 'architecture':platform.machine(),
|
|
18
|
+
'python':platform.python_version(), 'torch':torch.__version__, 'torchCuda':'none',
|
|
19
|
+
'numpy':numpy.__version__, 'scipy':scipy.__version__
|
|
20
|
+
})+'\n')
|
|
21
|
+
print('CPU scientific runtime imports and native operators: ready')
|
|
22
|
+
PY
|
|
23
|
+
/opt/citeark/venv/bin/python -m pip freeze > /opt/citeark/python-packages.lock
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
BASE_VIRTUAL_ENV="${CITEARK_BASE_VIRTUAL_ENV:-/opt/citeark/venv}"
|
|
5
|
+
BASELINE_REQUIREMENTS="${CITEARK_BASELINE_REQUIREMENTS:-/opt/citeark/requirements-baseline.txt}"
|
|
6
|
+
RUNTIME_VENV_SOURCE="${CITEARK_RUNTIME_VENV_SOURCE:-/opt/citeark/create-runtime-venv.sh}"
|
|
7
|
+
PYTHON_RUNTIME="${CITEARK_PYTHON_RUNTIME:-python3.12}"
|
|
8
|
+
PYTHON_PACKAGE_INDEX="${CITEARK_PYTHON_PACKAGE_INDEX:-https://pypi.org/simple}"
|
|
9
|
+
TORCH_INDEX="${CITEARK_TORCH_INDEX:-https://download.pytorch.org/whl/cu128}"
|
|
10
|
+
TORCH_VERSION="${CITEARK_TORCH_VERSION:-2.8.0}"
|
|
11
|
+
TORCHVISION_VERSION="${CITEARK_TORCHVISION_VERSION:-0.23.0}"
|
|
12
|
+
TORCHAUDIO_VERSION="${CITEARK_TORCHAUDIO_VERSION:-2.8.0}"
|
|
13
|
+
CAUSAL_CONV1D_WHEEL_URL="${CITEARK_CAUSAL_CONV1D_WHEEL_URL:-https://github.com/Dao-AILab/causal-conv1d/releases/download/v1.7.0/causal_conv1d-1.7.0%2Bcu12torch2.8cxx11abiTRUE-cp312-cp312-linux_x86_64.whl}"
|
|
14
|
+
CAUSAL_CONV1D_WHEEL_SHA256="${CITEARK_CAUSAL_CONV1D_WHEEL_SHA256:-a1fcd5d022b67ddfc9e1c291f890004c1c081a03d66b532f6eebe31219168e0e}"
|
|
15
|
+
HUGGINGFACE_ENDPOINT="${CITEARK_HUGGINGFACE_ENDPOINT:-https://huggingface.co}"
|
|
16
|
+
RUNTIME_PROFILE="${CITEARK_RUNTIME_PROFILE:-gcp-scientific-runtime}"
|
|
17
|
+
PIP_CACHE_ROOT="${CITEARK_PIP_CACHE_ROOT:-/tmp/citeark-runtime-pip-cache}"
|
|
18
|
+
|
|
19
|
+
if [ ! -r "$BASELINE_REQUIREMENTS" ]; then
|
|
20
|
+
printf '%s\n' "缺少科学运行基线依赖:$BASELINE_REQUIREMENTS" >&2
|
|
21
|
+
exit 70
|
|
22
|
+
fi
|
|
23
|
+
if [ ! -r "$RUNTIME_VENV_SOURCE" ]; then
|
|
24
|
+
printf '%s\n' "缺少运行虚拟环境脚本:$RUNTIME_VENV_SOURCE" >&2
|
|
25
|
+
exit 70
|
|
26
|
+
fi
|
|
27
|
+
if ! command -v "$PYTHON_RUNTIME" >/dev/null 2>&1; then
|
|
28
|
+
printf '%s\n' "缺少科学运行 Python:$PYTHON_RUNTIME" >&2
|
|
29
|
+
exit 70
|
|
30
|
+
fi
|
|
31
|
+
|
|
32
|
+
rm -rf "$BASE_VIRTUAL_ENV" "$PIP_CACHE_ROOT"
|
|
33
|
+
install -d -m 0755 /opt/citeark
|
|
34
|
+
install -d -m 1777 /opt/citeark/cache
|
|
35
|
+
install -d -m 0755 "$PIP_CACHE_ROOT"
|
|
36
|
+
|
|
37
|
+
"$PYTHON_RUNTIME" -m venv --system-site-packages "$BASE_VIRTUAL_ENV"
|
|
38
|
+
|
|
39
|
+
pip_install() {
|
|
40
|
+
PIP_CACHE_DIR="$PIP_CACHE_ROOT" \
|
|
41
|
+
PIP_INDEX_URL="$PYTHON_PACKAGE_INDEX" \
|
|
42
|
+
PIP_DEFAULT_TIMEOUT=120 \
|
|
43
|
+
PIP_RETRIES=8 \
|
|
44
|
+
"$BASE_VIRTUAL_ENV/bin/python" -m pip install "$@"
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
pip_install --upgrade pip setuptools uv wheel
|
|
48
|
+
|
|
49
|
+
PIP_CACHE_DIR="$PIP_CACHE_ROOT" \
|
|
50
|
+
PIP_DEFAULT_TIMEOUT=180 \
|
|
51
|
+
PIP_RETRIES=8 \
|
|
52
|
+
"$BASE_VIRTUAL_ENV/bin/python" -m pip install \
|
|
53
|
+
--index-url "$TORCH_INDEX" \
|
|
54
|
+
"torch==$TORCH_VERSION" \
|
|
55
|
+
"torchvision==$TORCHVISION_VERSION" \
|
|
56
|
+
"torchaudio==$TORCHAUDIO_VERSION"
|
|
57
|
+
|
|
58
|
+
# Mamba-2 的官方快速路径依赖与 PyTorch/CUDA/Python ABI 精确匹配的
|
|
59
|
+
# causal-conv1d 扩展。PyPI 默认只返回源码包,在运行容器没有 nvcc 时会
|
|
60
|
+
# 让每个复现 Agent 重复搜索 wheel 或退回慢速实现。镜像仅缓存官方发布
|
|
61
|
+
# 且固定摘要的匹配 wheel;任务虚拟环境仍可按证据覆盖它。
|
|
62
|
+
pip_install --no-deps \
|
|
63
|
+
"${CAUSAL_CONV1D_WHEEL_URL}#sha256=${CAUSAL_CONV1D_WHEEL_SHA256}"
|
|
64
|
+
|
|
65
|
+
# 先固定 GPU 版 PyTorch,再安装依赖它的科学包,避免 accelerate 等包
|
|
66
|
+
# 从 PyPI 另行解析并下载另一套 PyTorch/CUDA 运行库。
|
|
67
|
+
pip_install --upgrade-strategy only-if-needed --requirement "$BASELINE_REQUIREMENTS"
|
|
68
|
+
|
|
69
|
+
install -m 0555 "$RUNTIME_VENV_SOURCE" /opt/citeark/create-runtime-venv.sh
|
|
70
|
+
if [ "$(realpath "$BASELINE_REQUIREMENTS")" != "$(realpath -m /opt/citeark/requirements-baseline.txt)" ]; then
|
|
71
|
+
install -m 0644 "$BASELINE_REQUIREMENTS" /opt/citeark/requirements-baseline.txt
|
|
72
|
+
else
|
|
73
|
+
chmod 0644 /opt/citeark/requirements-baseline.txt
|
|
74
|
+
fi
|
|
75
|
+
ln -sfn "$BASE_VIRTUAL_ENV/bin/uv" /usr/local/bin/uv
|
|
76
|
+
|
|
77
|
+
cat > /etc/pip.conf <<EOF
|
|
78
|
+
[global]
|
|
79
|
+
index-url = $PYTHON_PACKAGE_INDEX
|
|
80
|
+
timeout = 120
|
|
81
|
+
retries = 8
|
|
82
|
+
disable-pip-version-check = true
|
|
83
|
+
EOF
|
|
84
|
+
|
|
85
|
+
cat > /etc/profile.d/citeark-scientific-runtime.sh <<EOF
|
|
86
|
+
export UV_CONFIG_FILE="/dev/null"
|
|
87
|
+
export PIP_INDEX_URL="$PYTHON_PACKAGE_INDEX"
|
|
88
|
+
export PIP_DEFAULT_TIMEOUT="120"
|
|
89
|
+
export PIP_RETRIES="8"
|
|
90
|
+
export UV_INDEX="$PYTHON_PACKAGE_INDEX"
|
|
91
|
+
export UV_INDEX_STRATEGY="first-index"
|
|
92
|
+
export UV_HTTP_TIMEOUT="120"
|
|
93
|
+
export UV_HTTP_RETRIES="8"
|
|
94
|
+
export HF_ENDPOINT="$HUGGINGFACE_ENDPOINT"
|
|
95
|
+
export HF_HUB_ETAG_TIMEOUT="30"
|
|
96
|
+
export HF_HUB_DOWNLOAD_TIMEOUT="120"
|
|
97
|
+
EOF
|
|
98
|
+
chmod 0644 /etc/pip.conf /etc/profile.d/citeark-scientific-runtime.sh
|
|
99
|
+
|
|
100
|
+
PYTHON_VERSION="$($BASE_VIRTUAL_ENV/bin/python --version 2>&1)"
|
|
101
|
+
TORCH_INSTALLED_VERSION="$($BASE_VIRTUAL_ENV/bin/python -c 'import torch; print(torch.__version__)')"
|
|
102
|
+
TORCH_CUDA_VERSION="$($BASE_VIRTUAL_ENV/bin/python -c 'import torch; print(torch.version.cuda or "none")')"
|
|
103
|
+
NUMPY_VERSION="$($BASE_VIRTUAL_ENV/bin/python -c 'import numpy; print(numpy.__version__)')"
|
|
104
|
+
SCIPY_VERSION="$($BASE_VIRTUAL_ENV/bin/python -c 'import scipy; print(scipy.__version__)')"
|
|
105
|
+
CAUSAL_CONV1D_VERSION="$($BASE_VIRTUAL_ENV/bin/python -c 'from importlib.metadata import version; print(version("causal-conv1d"))')"
|
|
106
|
+
|
|
107
|
+
jq -n \
|
|
108
|
+
--arg builtAt "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
|
|
109
|
+
--arg profile "$RUNTIME_PROFILE" \
|
|
110
|
+
--arg python "$PYTHON_VERSION" \
|
|
111
|
+
--arg torch "$TORCH_INSTALLED_VERSION" \
|
|
112
|
+
--arg torchCuda "$TORCH_CUDA_VERSION" \
|
|
113
|
+
--arg numpy "$NUMPY_VERSION" \
|
|
114
|
+
--arg scipy "$SCIPY_VERSION" \
|
|
115
|
+
--arg causalConv1d "$CAUSAL_CONV1D_VERSION" \
|
|
116
|
+
--arg pythonPackageIndex "$PYTHON_PACKAGE_INDEX" \
|
|
117
|
+
--arg huggingFaceEndpoint "$HUGGINGFACE_ENDPOINT" \
|
|
118
|
+
'{schemaVersion:"0.2",$profile,$builtAt,$python,$torch,$torchCuda,$numpy,$scipy,$causalConv1d,$pythonPackageIndex,$huggingFaceEndpoint}' \
|
|
119
|
+
> /opt/citeark/runtime-manifest.json
|
|
120
|
+
|
|
121
|
+
"$BASE_VIRTUAL_ENV/bin/python" -m pip freeze > /opt/citeark/python-packages.lock
|
|
122
|
+
"$BASE_VIRTUAL_ENV/bin/python" - <<'PY'
|
|
123
|
+
import accelerate
|
|
124
|
+
import causal_conv1d
|
|
125
|
+
import datasets
|
|
126
|
+
import fastapi
|
|
127
|
+
import fastapi_cli
|
|
128
|
+
import jsonschema
|
|
129
|
+
import lm_eval
|
|
130
|
+
import numpy
|
|
131
|
+
import pandas
|
|
132
|
+
import pydantic
|
|
133
|
+
import scipy
|
|
134
|
+
import sklearn
|
|
135
|
+
import soundfile
|
|
136
|
+
import torch
|
|
137
|
+
import torchaudio
|
|
138
|
+
import torchvision
|
|
139
|
+
import transformers
|
|
140
|
+
import yaml
|
|
141
|
+
|
|
142
|
+
assert torch.version.cuda == "12.8", torch.version.cuda
|
|
143
|
+
boxes = torch.tensor([[0.0, 0.0, 10.0, 10.0], [1.0, 1.0, 9.0, 9.0]])
|
|
144
|
+
scores = torch.tensor([0.9, 0.8])
|
|
145
|
+
assert torchvision.ops.nms(boxes, scores, 0.5).tolist() == [0]
|
|
146
|
+
print("scientific runtime imports: ready")
|
|
147
|
+
print("torch:", torch.__version__)
|
|
148
|
+
print("torch cuda runtime:", torch.version.cuda)
|
|
149
|
+
print("torch cuda available during image build:", torch.cuda.is_available())
|
|
150
|
+
PY
|
|
151
|
+
|
|
152
|
+
rm -rf "$PIP_CACHE_ROOT"
|
|
153
|
+
cat /opt/citeark/runtime-manifest.json
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""Shared, offline CPU parser. Cloud hosts only transport its inputs/outputs."""
|
|
2
|
+
import argparse
|
|
3
|
+
import hashlib
|
|
4
|
+
import importlib.metadata
|
|
5
|
+
import json
|
|
6
|
+
import os
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
import time
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def main():
|
|
12
|
+
args = argparse.ArgumentParser()
|
|
13
|
+
args.add_argument('--input', required=True)
|
|
14
|
+
args.add_argument('--output', required=True)
|
|
15
|
+
args.add_argument('--source-digest', required=True)
|
|
16
|
+
args.add_argument('--threads', type=int, default=4)
|
|
17
|
+
options = args.parse_args()
|
|
18
|
+
if not 1 <= options.threads <= 64:
|
|
19
|
+
raise ValueError('CPU threads must be between 1 and 64')
|
|
20
|
+
source = Path(options.input)
|
|
21
|
+
if hashlib.sha256(source.read_bytes()).hexdigest() != options.source_digest:
|
|
22
|
+
raise ValueError('Paper source digest mismatch')
|
|
23
|
+
for package, version in [('mineru', '4.0.10'), ('mineru-llama-cpp', '0.1.2'),
|
|
24
|
+
('docvortex', '0.5.8'), ('onnxruntime', '1.30.0')]:
|
|
25
|
+
if importlib.metadata.version(package) != version:
|
|
26
|
+
raise ValueError(f'Expected {package}=={version}')
|
|
27
|
+
# Ignore user-level MinerU remote/LLM configuration. The host supplies only
|
|
28
|
+
# a model directory; no external parsing or inference endpoint is accepted.
|
|
29
|
+
model_home = os.environ.get('CITEARK_MINERU_HOME', str(Path.home() / '.citeark' / 'mineru-4.0.10'))
|
|
30
|
+
for key in list(os.environ):
|
|
31
|
+
if key.startswith('MINERU_'):
|
|
32
|
+
del os.environ[key]
|
|
33
|
+
config_path = Path(options.output).resolve().with_suffix('.config.json')
|
|
34
|
+
config_path.parent.mkdir(parents=True, exist_ok=True)
|
|
35
|
+
config_path.write_text('{}')
|
|
36
|
+
os.environ.update(MINERU_HOME=model_home, MINERU_CONFIG=str(config_path),
|
|
37
|
+
MINERU_MODEL_SOURCE='local', MINERU_MODEL_SMALL_BACKEND='onnx',
|
|
38
|
+
MINERU_MODEL_VLM_ENGINE='llama-cpp', MINERU_TABLE_DEVICE='cpu',
|
|
39
|
+
MINERU_INTRA_OP_NUM_THREADS=str(options.threads), MINERU_INTER_OP_NUM_THREADS='1',
|
|
40
|
+
OMP_NUM_THREADS=str(options.threads), OPENBLAS_NUM_THREADS=str(options.threads),
|
|
41
|
+
MKL_NUM_THREADS=str(options.threads), CUDA_VISIBLE_DEVICES='',
|
|
42
|
+
HF_HUB_OFFLINE='1', HF_HUB_DISABLE_TELEMETRY='1', DO_NOT_TRACK='1')
|
|
43
|
+
import mineru_llama_cpp
|
|
44
|
+
engine = mineru_llama_cpp.Engine
|
|
45
|
+
|
|
46
|
+
class CpuEngine(engine):
|
|
47
|
+
def __init__(self, *args, **kwargs):
|
|
48
|
+
kwargs.update(n_gpu_layers=0, n_threads=options.threads, n_parallel=1)
|
|
49
|
+
super().__init__(*args, **kwargs)
|
|
50
|
+
|
|
51
|
+
mineru_llama_cpp.Engine = CpuEngine
|
|
52
|
+
from mineru.parser import parse
|
|
53
|
+
from mineru.kit.common import save_parse_result
|
|
54
|
+
start = time.monotonic()
|
|
55
|
+
result = parse(source, tier='standard', ocr_mode='auto', image_analysis=True)
|
|
56
|
+
save_parse_result(result, Path(options.output), 'zip')
|
|
57
|
+
print(json.dumps({'event': 'paper_parse_completed', 'sourceDigest': options.source_digest,
|
|
58
|
+
'seconds': time.monotonic() - start, 'mineruVersion': '4.0.10', 'gpu': 0}), flush=True)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
if __name__ == '__main__':
|
|
62
|
+
main()
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
accelerate>=1,<2
|
|
2
|
+
beautifulsoup4>=4.12,<5
|
|
3
|
+
datasets>=2.21,<4
|
|
4
|
+
einops>=0.8,<1
|
|
5
|
+
evaluate>=0.4,<1
|
|
6
|
+
fastapi>=0.115,<1
|
|
7
|
+
fastapi-cli>=0.0.10,<1
|
|
8
|
+
huggingface-hub>=0.28,<1
|
|
9
|
+
jsonschema>=4,<5
|
|
10
|
+
lxml>=5,<7
|
|
11
|
+
lm-eval==0.4.2
|
|
12
|
+
matplotlib>=3.8,<4
|
|
13
|
+
numpy>=1.26,<2
|
|
14
|
+
opencv-python-headless>=4.10,<4.12
|
|
15
|
+
pandas>=2.2,<3
|
|
16
|
+
pillow>=10,<13
|
|
17
|
+
polars>=1,<2
|
|
18
|
+
pydantic>=2.10,<3
|
|
19
|
+
pyarrow>=18,<24
|
|
20
|
+
pymupdf>=1.25,<2
|
|
21
|
+
pytest>=8,<10
|
|
22
|
+
pyyaml>=6,<7
|
|
23
|
+
requests>=2.32,<3
|
|
24
|
+
safetensors>=0.5,<1
|
|
25
|
+
scikit-learn>=1.4,<2
|
|
26
|
+
scipy>=1.12,<1.18
|
|
27
|
+
seaborn>=0.13,<1
|
|
28
|
+
sentencepiece>=0.2,<1
|
|
29
|
+
soundfile>=0.12,<1
|
|
30
|
+
statsmodels>=0.14,<1
|
|
31
|
+
tensorboard>=2.18,<3
|
|
32
|
+
tiktoken>=0.8,<1
|
|
33
|
+
torch==2.8.0
|
|
34
|
+
torchaudio==2.8.0
|
|
35
|
+
torchvision==0.23.0
|
|
36
|
+
tqdm>=4.66,<5
|
|
37
|
+
transformers>=4.48,<5
|
|
38
|
+
xgboost>=2,<3.1
|