FROM public.ecr.aws/x8v8d7g8/mars-base:latest
WORKDIR /app

ENV NODE_ENV=development
ENV NPM_CONFIG_PRODUCTION=false

# Git time-travel: clone, then make the repo's default branch point AT the base
# commit with no future history — a real branch checkout (not a detached HEAD),
# future commits/tags gc'd away so the reference solution can't leak from history.
ARG BASE_SHA=8a96e2dcd7f821d1250b58cf71c327679f94de25
RUN git clone https://github.com/bombshell-dev/clack . \
 && DEFAULT="$(git remote show origin | sed -n 's/.*HEAD branch: //p')" \
 && git checkout -B "$DEFAULT" "$BASE_SHA" \
 && git remote remove origin \
 && for b in $(git for-each-ref --format='%(refname:short)' refs/heads | grep -vx "$DEFAULT"); do git branch -D "$b" || true; done \
 && for t in $(git tag); do git merge-base --is-ancestor "$t" HEAD 2>/dev/null || git tag -d "$t"; done \
 && git reflog expire --expire=now --all \
 && git gc --prune=now \
 && (git submodule update --init --recursive || true)

RUN rm -rf node_modules packages/*/node_modules && pnpm install --no-frozen-lockfile

# v1.1 node-id scoring: vitest's JUnit reporter is built into vitest itself
# (`--reporter=junit --outputFile=...`); no extra reporter dependency needed.
# CTRF grading: vitest has no official CTRF reporter (ctrf-io ships none), so the
# verifier converts the JUnit XML with the OFFICIAL ctrf-io converter, pinned.
# npm -g installs under /usr (global prefix) and never touches /app's pnpm
# manifests; the smoke check fails the build loudly if node is too old (>=20).
RUN npm install -g junit-to-ctrf@0.0.14 && junit-to-ctrf --version

# `pnpm install --no-frozen-lockfile` may rewrite pnpm-lock.yaml; restore it so
# the image worktree is porcelain-clean (model.patch must not be polluted).
RUN git checkout -- pnpm-lock.yaml 2>/dev/null || true
RUN test -z "$(git status --porcelain)"

# Disable git commit hooks (husky etc.): dev-workflow tooling, not task content.
# Broken hook environments otherwise block the agent's (and oracle's) commits.
RUN cd /app && git config core.hooksPath /dev/null

CMD ["/bin/bash"]
