Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .codex/config.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
[mcp_servers.github-mcp-server]
url = "https://api.githubcopilot.com/mcp/"
bearer_token_env_var = "GITHUB_PERSONAL_ACCESS_TOKEN"
http_headers = { "X-MCP-Readonly" = "true" }

[mcp_servers.zai-vision]
command = "zai-mcp-vision"
args = []
env_vars = ["ZAI_API_KEY"]

[mcp_servers.zai-web-search]
command = "zai-mcp-remote"
args = ["web-search"]
env_vars = ["ZAI_API_KEY"]

[shell_environment_policy]
filters = { GITHUB_PERSONAL_ACCESS_TOKEN = "exclude", ZAI_API_KEY = "exclude", Z_AI_API_KEY = "exclude" }

[mcp_servers.zai-web-reader]
command = "zai-mcp-remote"
args = ["web-reader"]
env_vars = ["ZAI_API_KEY"]

[mcp_servers.zai-zread]
command = "zai-mcp-remote"
args = ["zread"]
env_vars = ["ZAI_API_KEY"]
10 changes: 5 additions & 5 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@
"isRoot": true,
"tools": {
"csharpier": {
"version": "1.3.0",
"version": "1.4.1",
"commands": [
"csharpier"
],
"rollForward": false
},
"coverlet.console": {
"version": "6.0.4",
"version": "10.1.1",
"commands": [
"coverlet"
],
"rollForward": false
},
"dotnet-reportgenerator-globaltool": {
"version": "5.5.11",
"version": "5.6.1",
"commands": [
"reportgenerator"
],
"rollForward": false
},
"ilspycmd": {
"version": "9.1.0.7988",
"ilspycmd.any": {
"version": "11.2.0.10050",
Comment thread
wallstop marked this conversation as resolved.
Resolved
"commands": [
"ilspycmd"
],
Expand Down
37 changes: 1 addition & 36 deletions .cursorrules
Original file line number Diff line number Diff line change
@@ -1,36 +1 @@
# Cursor Rules for NovaSharp

**Complete documentation: [`.llm/context.md`](.llm/context.md)**

## Quick Reference

| Priority | Concern | Never Sacrifice For Lower Priority |
| -------- | ------- | ---------------------------------- |
| 1. CORRECTNESS | Lua Spec Compliance | Performance, memory, clarity |
| 2. SPEED | Runtime Performance | Memory, clarity |
| 3. MEMORY | Minimal Allocations | Clarity |
| 4. UNITY | Platform Compatibility | Clarity |
| 5. CLARITY | Maintainability | - |

## Critical Rules

1. **NEVER `git add` or `git commit`** - Leave version control to humans
2. **NEVER use absolute paths** - Relative paths from repo root only
3. **NEVER discard output** - No `>/dev/null` or `2>/dev/null`
4. **Lua Spec = Source of Truth** - Fix NovaSharp, never tests
5. **Multi-Version Testing** - All tests run on Lua 5.1-5.5
6. **Mandatory post-work improvement gate** - After every large change or investigation, and before declaring it complete, follow [`.llm/skills/post-work-reflection/SKILL.md`](.llm/skills/post-work-reflection/SKILL.md). Fix discovered defects, capture reusable techniques or durable knowledge in the appropriate `.llm` artifact, and obtain an independent review when agents are available.

## Build & Test

```bash
./scripts/build/quick.sh # Build interpreter
./scripts/test/quick.sh # Run all tests
./scripts/test/quick.sh Floor # Filter by pattern
```

Do NOT use raw `dotnet build` or `dotnet test`.

## Skills

See [`.llm/skills/`](.llm/skills/) for task-specific guides.
Read and apply the shared NovaSharp engineering policy in [AGENTS.md](AGENTS.md).
3 changes: 3 additions & 0 deletions .devcontainer/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Host-generated runtime credentials must never enter the image build context.
.mcp.env
.mcp.env.*
12 changes: 11 additions & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ARG TARGETARCH=amd64
# Pinned checksum for Microsoft package repository bootstrap package.
ARG MS_PACKAGES_DEB_SHA256=8434dcb8c346dc95fbd63dbece056c343704590b58b6a5c323d39acf52bf0b48
# Keep this in sync with global.json. scripts/lint/check-tooling-consistency.py enforces it.
ARG DOTNET_SDK_MAJOR_MINOR=9.0
ARG DOTNET_SDK_MAJOR_MINOR=10.0
# Pinned Lua source version and checksum.
ARG LUA55_VERSION=5.5.0
ARG LUA55_SHA256=57ccc32bbbd005cab75bcc52444052535af691789dba2b9016d5c50640d68b3d
Expand Down Expand Up @@ -177,6 +177,11 @@ RUN git config --system init.defaultBranch main \
&& git config --system core.autocrlf input \
&& git config --system core.eol lf

# Seed the NuGet cache mount point so Docker initializes new named volumes with
# vscode ownership instead of root:root. Existing volumes are repaired by
# ensure-nuget-cache.sh before any lifecycle command invokes dotnet.
RUN install -d -m 0755 -o vscode -g vscode /home/vscode/.nuget

# Initialize zoxide for bash (add to bashrc for interactive shells).
RUN echo 'eval "$(zoxide init bash)"' >> /etc/bash.bashrc

Expand Down Expand Up @@ -219,4 +224,9 @@ RUN echo "=== Environment Verification ===" \
&& actionlint -version && yamllint --version \
&& echo "=== Verification Complete ==="

COPY --chmod=0755 zai-mcp-vision.sh /usr/local/bin/zai-mcp-vision
COPY --chmod=0755 zai-mcp-remote.sh /usr/local/bin/zai-mcp-remote
# Installed Claude launchers always use container-owned files, including on NTFS mounts.
COPY mcp_credentials.py /usr/local/bin/read-claude-mcp-key.py

USER vscode
174 changes: 140 additions & 34 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
# NovaSharp devcontainer maintenance

Host initialization requires Bash. From PowerShell in the checkout, start the
container and open an interactive login shell with:

```powershell
npx --yes --package=@devcontainers/cli -- devcontainer up --workspace-folder "$PWD"
npx --yes --package=@devcontainers/cli -- devcontainer exec --workspace-folder "$PWD" zsh -il
```

Run the second command after the first succeeds. The host hook runs relative to
the workspace, so either WSL Bash or Git Bash can find it on a Windows drive.
Docker receives its env-file path in the host's native format.

When cloning with Git for Windows, enable symlink support and use
`git clone -c core.symlinks=true` with the repository URL. This preserves the
two skill-directory links checked by the project's pre-commit hook.

The devcontainer installs the current npm `latest` dist-tag for these coding
tools:

- `@nanocollective/nanocoder`
- `opencode-ai`
- `@openai/codex`
- `@anthropic-ai/claude-code`
- `@github/copilot`
- `mcp-remote`
- `@z_ai/mcp-server`

The image build installs the current Node.js LTS through the base image's NVM
setup, then installs the tools as the `vscode` user. Container creation and every
Expand All @@ -31,12 +50,11 @@ Tool refreshes use a dedicated cache under the user's cache directory. A
successful update clears downloaded CLI tarballs without deleting the cache used
by ordinary project-level npm commands.

Image builds and first-create refreshes fail if npm cannot provide the requested
latest releases. Restart checks are deliberately bounded: if npm is temporarily
unavailable but all four image-baked tools are intact, startup emits a warning
and continues with those versions. This keeps an existing development container
usable during a registry or network outage without silently treating the tools
as current.
Image builds require npm to supply the requested latest releases. Container
creation and subsequent starts use bounded retries. If the registry is
unreachable or a published tarball cannot be installed, startup warns and
validates all seven installed tools before continuing. A missing or broken
installation still fails startup.

Run the refresh manually with:

Expand All @@ -51,10 +69,12 @@ Anthropic backends. The setup hook also installs opt-in `codex-zai` and
`claude-zai` launchers. Switching is per process; no command rewrites the native
configuration.

Provide the Z.ai credential through a private environment or secret store:
To use the optional integrations, add the credentials you need before
rebuilding. A checkout can start without `.env.local`:

```bash
export ZAI_API_KEY="..."
[ -e .env.local ] || cp .env.local.example .env.local
# Add or update ZAI_API_KEY and GITHUB_PERSONAL_ACCESS_TOKEN.
codex-zai
claude-zai
```
Expand All @@ -70,9 +90,18 @@ Optional per-process overrides are `CODEX_ZAI_MODEL`,
`ZAI_API_TIMEOUT_MS` (default: five minutes), and
`CLAUDE_ZAI_CONFIG_DIR`. Claude's `haiku`, `sonnet`, and `opus` aliases map to
Z.ai's recommended GLM models; override them with `CLAUDE_ZAI_HAIKU_MODEL`,
`CLAUDE_ZAI_SONNET_MODEL`, and `CLAUDE_ZAI_OPUS_MODEL`. Harness shell and MCP
subprocesses do not inherit the model-server credential. Reinstall the launchers
manually after moving the checkout:
`CLAUDE_ZAI_SONNET_MODEL`, and `CLAUDE_ZAI_OPUS_MODEL`. Ordinary shell and
unrelated MCP children do not inherit the model-server credential. The trusted
Z.ai MCP servers receive only their required credential. For Claude, their
wrappers use `CLAUDE_PROJECT_DIR` to select a private, workspace-specific copy
of the Z.ai key in the container user's home directory. Codex explicitly
forwards only `ZAI_API_KEY` through its stdio MCP allowlist.
The wrappers scrub the canonical key and unrelated tokens before starting the
MCP process.
After moving a managed checkout, recreate its devcontainer from the new
workspace path. Creation stages the credential for that path and reinstalls
the launchers. For a standalone POSIX checkout, reinstall the launchers from
the new repository root:

```bash
bash .devcontainer/ai-backends.sh install
Expand All @@ -85,14 +114,15 @@ to create a user and mount namespace even with
AppArmor profiles reject. In an existing devcontainer, `claude-zai` therefore
defaults `CLAUDE_CODE_SUBPROCESS_ENV_SCRUB=0` and relies on the outer container
as the process boundary. Controlled Bash and stdio MCP probes verified that
Claude still removes the model-server credential from those children.
Claude still removes the model-server credential from ordinary shell children
while deliberately authenticating the selected Z.ai MCP servers.

Outside a container, the launcher retains the stronger scrubber by default. Set
`CLAUDE_ZAI_SUBPROCESS_ENV_SCRUB=1` to request it explicitly; the launcher runs a
real bubblewrap preflight and exits with actionable guidance before starting a
model session when the runtime cannot support it. Do not add `SYS_ADMIN`, run a
privileged container, or globally weaken host AppArmor merely to make this
optional second sandbox work.
`CLAUDE_ZAI_SUBPROCESS_ENV_SCRUB=1` to request it explicitly; the launcher
runs a real bubblewrap preflight and exits with actionable guidance before
starting a model session when the runtime cannot support it. Do not add
`SYS_ADMIN`, run a privileged container, or globally weaken host AppArmor merely
to make this optional second sandbox work.

## Agent network reliability

Expand Down Expand Up @@ -205,31 +235,107 @@ run authenticated streaming and read-only tool workloads in both clients.
Record attempt counts, latency, and failure class without recording credentials
or response bodies.

## GitHub MCP

GitHub's hosted MCP server is configured for every agent harness used by this
repository:

- `.vscode/mcp.json` configures VS Code and Copilot Chat with GitHub OAuth.
## Project MCP servers

The devcontainer exposes GitHub's hosted MCP server plus every MCP currently
listed by the Z.ai Coding Plan: Vision Understanding, Web Search Prime, Web
Reader, and Zread. The Vision package is installed in the image and refreshed
with the other npm agent tools; the three remote Z.ai servers use their official
HTTPS endpoints.

Claude Code 2.1.260 cannot consume the SSE-framed MCP initialization response
currently returned by those three endpoints. Codex 0.153.2 completes the
response but loses the transport while sending the subsequent `initialized`
notification. Direct HTTP probes and OpenCode succeed from the same container,
so `claude-zai` and Codex use the installed `mcp-remote` stdio bridge only for
those three servers. Vision remains direct stdio and GitHub remains native HTTP.
Re-test native HTTP after either client upgrades before removing its bridge.

In Claude Code 2.1.260, `claude-zai mcp list` ignores this per-session strict
catalog and health-checks `.mcp.json`, so it can falsely report the three native
HTTP failures. The authoritative check is the `system/init` event from an actual
`claude-zai --print --output-format stream-json --verbose` session: its
`mcp_servers` array must show all five entries as `connected`.

Keep model access separate from MCP health. In the 2026-09-04 live probe, all
five MCPs connected before Z.ai's model API returned HTTP 429, code `1310`, for
an exhausted weekly/monthly subscription allowance. Claude retries that response
and can look hung. A rebuild, key rotation, or MCP change cannot repair quota;
interrupt the retries, check the Z.ai plan's usage/reset time, and retry after
capacity is available.

The same catalog is configured for every agent frontend used by this repository:

- `.vscode/mcp.json` configures VS Code and Copilot Chat.
- `.codex/config.toml` configures the Codex CLI and Codex extension.
- `.mcp.json` configures Claude Code, Copilot CLI, and Nanocoder.
- `opencode.json` configures OpenCode.

No credential is stored in the repository or image. Before opening the
devcontainer, export a least-privilege GitHub token on the host so VS Code can
forward it to the terminal harnesses:
Nanocoder receives the catalog's absolute path, so launching it below the
repository root still discovers every server.

No credential is committed or stored in an image layer. Before container
creation, the host preflight reads only the two allowlisted values from the
ignored `.env.local` and atomically publishes an ignored Docker env file.
The preflight restricts access to both files with an owner-only Windows ACL on
Windows drives and mode `0600` on POSIX filesystems. Each credential is optional.
A failed preflight stops the launch and preserves the last published contents.
Docker captures the environment at creation. After adding, changing, or removing
a credential, recreate the container with **Dev Containers: Rebuild Container**
or `devcontainer up --workspace-folder . --remove-existing-container`.

```bash
[ -e .env.local ] || cp .env.local.example .env.local
# Add or update GITHUB_PERSONAL_ACCESS_TOKEN and ZAI_API_KEY, then:
code .
# Select “Dev Containers: Rebuild Container” if one already exists.
```

Use a least-privilege GitHub token. Every project definition sends
`X-MCP-Readonly: true` by default, so unattended/YOLO sessions cannot invoke
GitHub write tools. Remove that header only when intentional GitHub mutations
are required; the token's permissions then define the available writes. The two
keys enter the trusted container process environment and remain readable from
the mounted workspace, so do not run untrusted repository code or agents.
The isolated `claude-zai` launcher pre-approves only the five audited names;
native Claude Code still asks before trusting project MCP definitions. Codex
loads them only after the repository itself is trusted. The project entry
replaces Copilot CLI's built-in read-only GitHub definition instead of creating
a duplicate.

Sources: [Z.ai Coding Plan MCP overview](https://docs.z.ai/devpack/overview),
[Claude Code MCP configuration](https://code.claude.com/docs/en/mcp),
[Codex MCP configuration](https://developers.openai.com/codex/mcp/),
[Claude Code native SSE failure](https://github.com/anthropics/claude-code/issues/58759),
[`mcp-remote`](https://github.com/geelen/mcp-remote),
[GitHub MCP server](https://github.com/github/github-mcp-server), and
[Dev Container environment files](https://code.visualstudio.com/remote/advancedcontainers/environment-variables).

## NuGet cache volume ownership

`novasharp-nuget-cache` is mounted at `/home/vscode/.nuget`. Docker only
copies ownership from the image when it initializes an empty named volume. If
the mount point is absent from the image, Docker creates the volume as
`root:root`, and the non-root `vscode` user cannot create
`~/.nuget/NuGet/NuGet.Config`. NuGet reports that failure as
`Failed to read NuGet.Config due to unauthorized access`.

The image seeds `/home/vscode/.nuget` with `vscode` ownership so new volumes
start correct. `ensure-nuget-cache.sh` then runs before every lifecycle step
that invokes `dotnet`; it repairs an existing volume whose owner no longer
matches the current runtime UID, including after `updateRemoteUserUID` or when
the volume predates the image seed. The repair uses only the current UID/GID
and is skipped when the cache is already writable.

If passwordless `sudo` is unavailable, or the volume is mounted read-only, stop
the container and recreate the disposable cache volume, then rebuild so the
image seed applies:

```bash
export GITHUB_PERSONAL_ACCESS_TOKEN="$(gh auth token)"
docker volume rm novasharp-nuget-cache
```

If the container is already open, run the same command in its terminal before
starting Codex, Claude Code, Copilot CLI, OpenCode, or Nanocoder. In VS Code,
open `.vscode/mcp.json`, select **Start**, and then select **Auth** to complete
GitHub OAuth. Copilot CLI also includes a read-only GitHub MCP server by default;
the project entry is deliberately named `github-mcp-server` so the authenticated
project configuration replaces that built-in definition instead of duplicating
it.
`docker volume rm` fails while a container is still using the volume.

## Generated artifact retention

Expand Down
Loading
Loading