GitNexus/.devcontainer/devcontainer.json
Gergő Magyar 5b968a098c
fix(devcontainer): move workspace and snapshots to Linux volumes (#3835)
* fix(devcontainer): move workspace and snapshots to Linux volumes

* fix(devcontainer): exclude evaluation virtualenv from source import

* fix(devcontainer): preserve WSL links during volume imports

* fix(devcontainer): skip parser caches and report import progress

Exclude regenerable GitNexus parser caches from every nested worktree
while preserving graph databases, Git state, and local work.

Report archive bytes and elapsed time every five seconds, and stream
output with activity updates during longer Docker initialization stages.

* fix(devcontainer): resolve workspace volume ID before startup

* fix(devcontainer): relink nested worktrees and harden host imports

- Relink nested worktrees whose Git pointers still name the host path
  (C:/..., /Users/...): match the longest existing suffix in the copy
  and rewrite both pointers, as `git worktree repair` would.
- Fail the import when a file changes while tar reads it. bsdtar on
  macOS and Windows pads or truncates such files and exits 0.
- Disable AppleDouble `._*` entries from macOS tar (COPYFILE_DISABLE).
- Follow selected snapshot roots that are symlinks (dotfile-managed
  ~/.config/gh, ~/.claude.json) like the bind mounts they replace.
- Keep node at UID 1000 for root host users; the Dev Containers CLI
  skips UID realignment for UID 0.
- Make fixture modes independent of the process umask and check the
  no-partial-write case with lstat.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(devcontainer): stage on the host and commit once at container creation

initializeCommand also runs when an existing container is reopened. A
developer who pulled the volume change and reopened the old bind-mount
container got an import marked ready, and the eventual rebuild silently
showed that stale copy.

- The host now only stages the checkout into gitnexus-seed-<id>
  (tree/ plus a stage-complete marker written last); the helper mounts
  the source volume read-only.
- onCreateCommand, which runs once per container creation, commits a
  complete stage into the empty source volume, empties the stage and
  repairs ownership. initializeCommand copies the host's
  seed-workspace.cjs into the seed volume on every start, so the
  commit matches devcontainer.json and works with any image.
- Staging and snapshot retakes are best-effort: a failure clears its
  target, warns and is retried next start, so a busy host never locks
  out reopening an existing container. Creation without a complete
  stage stops at onCreateCommand with a clear message.
- Snapshots are retaken while the source volume is uncommitted, and a
  partial snapshot is replaced instead of failing closed; snapshots are
  read-only host copies, so replacing them is safe.
- Node writes the tar stream (ustar + PAX for long and UTF-8 names).
  Windows tar.exe read the file list in the ANSI code page, so any
  non-ASCII path failed; macOS tar added AppleDouble files; both padded
  or truncated a file that changed while being read. A changed file now
  discards that copy. The host no longer needs tar. Sockets and FIFOs
  are skipped, as tar did.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(devcontainer): simplify importer helpers and read small files whole

- tarStream reads files up to 1 MiB in one call instead of opening a
  stream per file: 50k files stream in 1.0 s instead of 12 s, with a
  byte-identical archive and unchanged change detection.
- Drop copyArchive's dead `excludes` parameter; the snapshot marker is
  excluded through the existing predicate.
- Share the source/target overlap check and the common-dir check.
- Remove exports with no consumer and two comments left from the
  host-tar implementation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(devcontainer): skip POSIX-only tar assertions on Windows (#3835)

- Address PR review feedback: the tar round-trip test ran mkfifo and
  asserted a 0755 mode unconditionally. Split it: UTF-8, long-name and
  empty-file round-trips run everywhere; POSIX mode preservation and
  FIFO exclusion move to a test skipped on win32, where tarStream
  writes 0644 by design.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(devcontainer): skip POSIX-tooling importer tests on Windows (#3835)

- Address PR review feedback: the Docker-adapter fixture assumed a POSIX
  PATH separator. A Windows-safe separator would not help: the fake
  `docker` is a shebang script Windows cannot spawn, and it runs Linux
  helper commands. One shared `posixOnly` skip option now covers the
  seven Docker-adapter tests, the bash credential test and the POSIX
  modes/FIFO test; all still run on Linux.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(devcontainer): keep failed snapshots retryable and nested worktrees local (#3835)

Address PR review feedback:
- Select snapshot roots with lstat, so a dangling or unfollowable
  `.claude.json` link reaches the archiver and is preserved as a link.
  A path under a non-directory still counts as absent.
- post-create.sh publishes the one-shot identity and shareable seed
  markers only when /host carries its completion marker; a snapshot
  skipped during initialization is seeded by a later rebuild.
- Remove an absolute core.worktree from each relinked nested worktree's
  config.worktree before Git first reads that checkout, as already done
  for the root configuration.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(devcontainer): run fake-Docker importer tests only on Linux (#3835)

- Address PR review feedback: on macOS the importer passes container
  UID 1000, and the fake Docker adapter ran finishSnapshot's chown as the
  unprivileged host user. The adapter emulates the Linux helper
  container on the host, so its seven tests now share a `linuxHelper`
  gate; the bash, mode and FIFO tests keep the narrower `posixOnly`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* ci(devcontainer): run host importer tests on macOS and Windows (#3835)

Address PR review feedback: the suite's platform assumptions surfaced one
review finding per push. The host-side importer now runs on all three CI
hosts and the tests state what each one needs.

- New `host-importer` job runs initialize-volumes.test.cjs on
  macos-latest and windows-latest (Linux already runs every test).
- The importer reads its Docker CLI from GITNEXUS_IMPORT_DOCKER (JSON
  argv, default docker). Windows spawn resolves only .exe/.com, so the
  test adapter is now a Node script on every OS instead of a shebang
  file on PATH. The adapter emulates the helper's find/mkdir/touch and,
  on Windows, snapshot finalization.
- Gates: posixOnly (bash, modes, mkfifo), a symlink capability probe,
  and containerSide (Linux only) for code that runs only in the dev
  container or helper. Host staging assertions read the staged tree;
  the commit and 0600 snapshot modes stay in one Linux test.
- seed-workspace.test.cjs is container-side, so it skips on other hosts.
- The long-name round trip stays above 100 bytes (PAX) but under
  Windows MAX_PATH once extracted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(devcontainer): verify the tar stream with Python's PAX reader (#3835)

Windows tar.exe converts names to the ANSI code page while extracting, so
it cannot write `jegyzet-ő.md` or an emoji directory ("empty or
unreadable filename") - the limitation the Node writer exists to avoid.
Production never extracts with it; Docker's Go extractor does.

Read the round-trip archive with Python's tarfile instead, an
independent PAX reader that handles UTF-8 on every host, so the UTF-8
check also runs on Windows CI. A capability gate skips the test when no
Python 3 is installed. Removing the PAX path record fails the test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Gergo Magyar <gergomagyar0@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 20:36:27 +00:00

157 lines
7.2 KiB
JSON

// Devcontainer for GitNexus. It pre-installs Claude Code, the OpenAI Codex
// CLI, and the Cursor CLI, plus the Node.js native build chain. It works on
// macOS, Linux, Windows via WSL2, and Windows native. Host prerequisites:
// Docker and Node.js on PATH. All workspace and configuration mounts use
// Linux-native Docker volumes. See .devcontainer/README.md.
//
// For first-time setup, auth flows, and troubleshooting, see
// .devcontainer/README.md.
{
"name": "GitNexus AI CLI Devcontainer",
"build": {
"dockerfile": "Dockerfile",
"context": ".",
"args": {
// Bun: pinned by version. Installed by the official bun.sh/install
// script, which accepts the release tag as its first positional arg
// (`bash -s bun-vX.Y.Z`). UNLIKE Cursor, the install path runs an
// unverified remote script — chosen at request time for simplicity.
// To bump: pick a tag from github.com/oven-sh/bun/releases and update
// this value.
"BUN_VERSION": "1.3.14",
"TZ": "${localEnv:TZ:UTC}"
}
},
// Runs on the HOST before every start. Stages the checkout and snapshots
// through the Docker copy API; no host directory is mounted in any container.
"initializeCommand": [
"node",
".devcontainer/initialize-volumes.cjs",
"${devcontainerId}",
"source"
],
"features": {
"ghcr.io/devcontainers/features/github-cli:1": {}
},
"remoteUser": "node",
"updateRemoteUserUID": true,
// Reap orphaned subprocesses from CLI workers and test runs.
"init": true,
// Disable the automatic workspace mount. Declare it in mounts below so the
// Dev Containers CLI substitutes devcontainerId before passing it to Docker.
"workspaceMount": "",
"workspaceFolder": "/workspace",
// Existing writable config, session, dependency and cache volumes retain
// their names. /host and identity directories are read-only Linux snapshots.
// Snapshot credentials seed missing files only; container logins persist.
// Session volumes overlay config volumes so resetting config preserves history.
"mounts": [
"source=gitnexus-source-${devcontainerId},target=/workspace,type=volume,volume-nocopy",
"source=gitnexus-seed-${devcontainerId},target=/seed,type=volume",
"source=claude-config-${devcontainerId},target=/home/node/.claude,type=volume",
"source=codex-config-${devcontainerId},target=/home/node/.codex,type=volume",
"source=cursor-config-${devcontainerId},target=/home/node/.cursor,type=volume",
"source=gh-config-${devcontainerId},target=/home/node/.config/gh,type=volume",
"source=claude-mem-${devcontainerId},target=/home/node/.claude-mem,type=volume",
"source=${localWorkspaceFolderBasename}-claude-sessions-${devcontainerId},target=/home/node/.claude/projects,type=volume",
"source=${localWorkspaceFolderBasename}-codex-sessions-${devcontainerId},target=/home/node/.codex/sessions,type=volume",
"source=${localWorkspaceFolderBasename}-cursor-sessions-${devcontainerId},target=/home/node/.cursor/chats,type=volume",
"source=${localWorkspaceFolderBasename}-cursor-projects-${devcontainerId},target=/home/node/.cursor/projects,type=volume",
"source=commandhistory-${devcontainerId},target=/commandhistory,type=volume",
"source=npm-cache-${devcontainerId},target=/home/node/.npm,type=volume",
"source=gitnexus-store-${devcontainerId},target=/home/node/.gitnexus,type=volume",
"source=${localWorkspaceFolderBasename}-root-node-modules-${devcontainerId},target=/workspace/node_modules,type=volume",
"source=${localWorkspaceFolderBasename}-gitnexus-node-modules-${devcontainerId},target=/workspace/gitnexus/node_modules,type=volume",
"source=${localWorkspaceFolderBasename}-gitnexus-web-node-modules-${devcontainerId},target=/workspace/gitnexus-web/node_modules,type=volume",
"source=${localWorkspaceFolderBasename}-gitnexus-shared-node-modules-${devcontainerId},target=/workspace/gitnexus-shared/node_modules,type=volume",
"source=gitnexus-host-snapshot-${devcontainerId},target=/host,type=volume,readonly,volume-nocopy",
"source=gitnexus-ssh-snapshot-${devcontainerId},target=/home/node/.ssh,type=volume,readonly,volume-nocopy",
"source=gitnexus-docker-snapshot-${devcontainerId},target=/home/node/.docker,type=volume,readonly,volume-nocopy",
"source=gitnexus-aws-snapshot-${devcontainerId},target=/home/node/.aws,type=volume,readonly,volume-nocopy",
"source=gitnexus-azure-snapshot-${devcontainerId},target=/home/node/.azure,type=volume,readonly,volume-nocopy",
"source=gitnexus-git-snapshot-${devcontainerId},target=/home/node/.config/git,type=volume,readonly,volume-nocopy"
],
// API keys are not injected as empty environment variables. Log in inside
// the container or export a key in its shell. Claude uses its default home.
"containerEnv": {
"CODEX_HOME": "/home/node/.codex",
"HISTFILE": "/commandhistory/.zsh_history",
"GITNEXUS_HOME": "/home/node/.gitnexus"
},
"customizations": {
"vscode": {
"extensions": [
"anthropic.claude-code",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"eamodio.gitlens"
],
"settings": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
"files.eol": "\n",
// Generated indexes and sibling worktrees can dwarf the source tree.
// These exclusions affect VS Code only; Vite and test watchers keep
// their own configuration.
"files.watcherExclude": {
"**/node_modules/**": true,
"**/.gitnexus/**": true,
"**/.worktrees/**": true,
"**/.claude/worktrees/**": true,
"**/dist/**": true,
"**/coverage/**": true
},
"search.exclude": {
"**/node_modules": true,
"**/.gitnexus": true,
"**/.worktrees": true,
"**/.claude/worktrees": true,
"**/dist": true,
"**/coverage": true
},
"git.autoRepositoryDetection": "openEditors",
"terminal.integrated.defaultProfile.linux": "zsh",
"terminal.integrated.profiles.linux": {
"bash": { "path": "bash", "icon": "terminal-bash" },
"zsh": { "path": "zsh" }
}
}
}
},
// Do not remap port 4747 (gitnexus serve). gitnexus-web hardcodes
// http://localhost:4747 as its default backend URL.
"forwardPorts": [5173, 4747, 4173],
"portsAttributes": {
"5173": {
"label": "Vite dev (gitnexus-web)",
"onAutoForward": "notify"
},
"4747": {
"label": "gitnexus serve HTTP API",
"onAutoForward": "notify",
"requireLocalPort": true
},
"4173": {
"label": "Static web (Vite preview)",
"onAutoForward": "silent"
}
},
// Runs once per container creation: commits the complete staged checkout into
// the empty source volume, then repairs ownership before dependency
// installation. initializeCommand copies this script into /seed each start.
"onCreateCommand": "sudo -n node /seed/seed-workspace.cjs --prepare /workspace /seed",
"updateContentCommand": "bash .devcontainer/install-deps.sh",
"postCreateCommand": "bash .devcontainer/post-create.sh"
}