Skip to content

feat(sbx): sbx up --cortex loads the project's CLAUDE.md - #629

Merged
huang195 merged 9 commits into
rossoctl:mainfrom
huang195:feat/sbx-cortex
Oct 27, 2026
Merged

huang195 merged 9 commits into
rossoctl:mainfrom
huang195:feat/sbx-cortex

Conversation

@huang195

Copy link
Copy Markdown
Member

Problem

What this does

mocactl sbx up --cortex lets Cortex keep the agent off local tools instead of a deny list:

  • Before anything is created, up checks agentop --version is v0.9.3 or later (dev and main-<sha> builds accepted), then runs agentop script install moca-sandbox. Either failing stops up with nothing created, bound or pushed.
  • The agent config is written as today, minus the 17 permissions.deny entries. The server, allow rule, enabledMcpjsonServers, opencode.json and the rules block are unchanged.
  • The mode is recorded as cortex: true in .sbx/agent-config.json, so a later plain up keeps it. Denies an earlier up added are taken back, and the developer's own denies stay.
  • sbx doctor skips the deny check in Cortex mode and adds a cortex check: the script is installed and loaded, with a fix named for each failure.
  • sbx rm is unchanged. Cortex's install stays, since other repos may use it.

Without --cortex, nothing changes and agentop is never run. moca does not depend on Cortex.

The Cortex side shipped in v0.9.3: the moca-sandbox script (rossoctl/cortex#1495) and agentop script install (rossoctl/cortex#1507). In sessions that carry mcp__sandbox__* tools, the script:

  • hides the local tools from the model;
  • renames any local tool call to blocked__<name>;
  • turns any local result into an error.

Design: docs/specs/2026-10-27-sbx-up-cortex-design.md. SBX0 §6.3 and the user guide are updated.

Testing

  • 35 new tests, and all 278 in the sbx-* files pass: sbx-agentop, sbx-agent-config-cortex, sbx-up-cortex, sbx-doctor-cortex.
  • tsc --noEmit on mocactl is clean, and the repo's prettier 3.9.10 is clean. make typecheck/make lint weren't run locally (no pnpm or built pi-fork on this laptop).
  • The full mocactl suite fails only 4 timing-sensitive TUI tests: CredentialsOverlay ×2, LeaveTurnOverlay and OnboardingOverlay. They fail the same way on untouched main, and pass rerun file by file.
  • Live, in a Lima VM with this branch's mocactl, a scratch Cortex v0.9.3, Claude Code 2.1.309 and claude-opus-5-5:
    • up --cortex installed the script (1/1 loaded) and wrote settings with no deny;
    • a real session read code through the sandbox, its reply followed CLAUDE.md's rule, it had no local Bash, and a local touch never happened;
    • doctor passed;
    • rm took back all five files and .sbx/, and deleted the sandbox.

Known gaps

  • up --cortex installs the script, which changes ~/.cortex, before the agent-config conflict check. A conflict then stops up after Cortex was already touched. The install is idempotent and inert outside sandbox sessions.
  • An agentop timeout or kill reads as an ordinary failure; the message doesn't say it timed out.
  • agentop's install message is printed without sanitizeRemote.
  • A plain up in a Cortex-mode repo names --cortex in its errors, and a migration guard failure prints rm advice.
  • SBX0 §6.1's doctor row still says the config denies every local tool. The user guide doesn't say how to leave the mode: sbx rm, then a plain up.
  • A Read deny added by hand in Cortex mode isn't flagged by doctor.
  • Whether Claude Code actually reaches the model through Cortex isn't checked: agentop has no machine-readable answer. up prints a note saying it must.

Assisted-By: Claude (Anthropic AI) [email protected]

With Cortex v0.9.3+, up installs Cortex's moca-sandbox script and writes the agent configuration without the Read deny that stops CLAUDE.md loading (rossoctl#568). Without the flag, up is unchanged.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
…list

Nothing calls it yet; sbx up --cortex and doctor will.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
…ool denies

The record keeps cortex: true, so a later up keeps the mode; denies an earlier up added are taken back, and the developer's own stay.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
…octl#568)

Before anything is created, up checks Cortex's agentop is v0.9.3 or later and installs its moca-sandbox script; the agent configuration is then written without the local-tool denies, whose Read deny stopped CLAUDE.md loading.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
In place of the local-tool denies, it checks the script is installed and loaded, and says what to do when it is not.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
…x mode

Found in the live run: in a Cortex-mode repo it said every local tool was denied.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
install.sh --ref=main installs an agentop that prints 'agentop main-<sha7>', which up --cortex refused as not a version.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
@huang195
huang195 requested a review from pdettori as a code owner October 27, 2026 13:43
…rtex

The moca-sandbox install edits the shared ~/.cortex and reloads its proxy, so a conflict in the repo's agent configuration now stops up before it runs, as up's help promises.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
@pdettori pdettori added the ready-for-ai-review Request automated AI code review from clawgenti label Oct 27, 2026

@pdettori pdettori left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of sbx up --cortex — agentop integration, Cortex-mode agent config, doctor check, docs.

Author: huang195 (MEMBER — maintainer)
Areas reviewed: TypeScript (src + tests), Docs, Security
Agent/IDE config (.claude/.vscode): none — the code writes .claude/settings.json at runtime (existing up behavior); no repo config files changed
Commits: 9 commits, all signed-off: yes
CI status: passing (14/14)

Verified:

  • agentop.ts spawns the external binary via execFile with fixed literal args — no injection surface; timeouts and maxBuffer bound hangs and output size; script list --json output is parsed defensively and fails closed.
  • Deny removal in Cortex mode drops only items moca's own manifest recorded; hand-written denies survive, and the deny container is removed only when up created it.
  • Ordering: the agent-config conflict check and the agentop version/install both run before anything is created, bound or pushed — a repository cannot end up with un-denied local tools and no Cortex blocking in place.
  • The mode is sticky via cortex: true, validated strictly; a malformed record fails safe to the strict (deny) checks.
  • 35 new tests cover the version matrix, install failure, migration, doctor rows, and flag misuse.

One note: the first bullet under "Known gaps" (install running before the agent-config conflict check) is fixed by c7d34ba — the conflict check now runs first, with a test. Consider updating the PR description.

Assisted-By: Claude Code

@huang195
huang195 merged commit 2e53d44 into rossoctl:main Oct 27, 2026
15 checks passed
@huang195
huang195 deleted the feat/sbx-cortex branch October 27, 2026 14:45

@ingpaolodettori-dev ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Clean, well-bounded change. up --cortex keeps every Cortex step (version check, script install) after the agent-config dry run and before anything is created, bound, or pushed. The deny migration only takes back items the record says up added, and goes through dropAt's guards. Cortex mode is read only from a validated record. Without the flag nothing changes. Checked against rossoctl/cortex#1507 / v0.9.3: the agentop --version format, the script list --json field contract (scripts[], state, scripts, loaded, notStarted), and the installed state semantics all match, and the slot is installed fail_closed. Accepting main-<sha> builds is safe: a pre-#1507 main build has no script install, so up stops at the install.

Only nits below, plus two for the description and docs:

  • The first "Known gap" in the PR description (the install touches ~/.cortex before the conflict check) is out of date. c7d34ba moved the dry run ahead of the install, and sbx-up-cortex.test.ts covers that ordering.
  • SBX0 §6.1's doctor row still says the config "denies every local tool". You already listed this; a short Cortex-mode qualifier would close it.

Author: huang195 (MEMBER, maintainer)
Areas reviewed: TypeScript (mocactl sbx: agent-config, agentop, cli, doctor, sync), tests, docs/specs
Agent/IDE config (.claude/.vscode): none
Commits: 9 commits, all signed-off: yes
CI status: passing

say(c, `Cortex could not install ${MOCA_SANDBOX}: ${got.message}`);
return SBX_EXIT.failed;
}
if (got.message) c.io.err(got.message);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: agentop's install output goes to the terminal raw, while everything else in cmdUp goes through say() and sanitizeRemote. You already list it as a known gap. A one-line fix closes it:

if (got.message) c.io.err(sanitizeRemote(got.message));


**Before anything is created, bound or pushed** (where `up` already checks the agent configuration):

1. **agentop.** `agentop --version` must answer `agentop vX.Y.Z` with `X.Y.Z` at least `0.9.3`, or `agentop dev…`.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: The spec has drifted from the code here. agentopProblem also accepts agentop main-<sha> (c64c75b), and the error up prints is sbx up --cortex: agentop is vX; Cortex mode needs v0.9.3 or later; install it with: … (sync.ts:342), not the quoted line. Please bring step 1 in line with the code.


## 8. Testing

vitest, in the existing files, through the harness's fake exec (`test/helpers/sbx.ts`):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This says the tests go "in the existing files", but they landed in four new files: sbx-agentop, sbx-agent-config-cortex, sbx-up-cortex, sbx-doctor-cortex. Please update the list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants