Skip to content

Scaffold, core contracts and run pipeline - #1

Merged
mths-mcfs merged 9 commits into
mainfrom
feat/scaffold
Nov 19, 2026
Merged

mths-mcfs merged 9 commits into
mainfrom
feat/scaffold

Conversation

@mths-mcfs

Copy link
Copy Markdown
Owner

Summary

Project skeleton plus the frozen contracts and run pipeline that the sandbox, host adapter, tools and benchmark parts build against. The whole run path already works with test fakes.

tools/call run {code, transaction?, timeoutMs?}       (src/server/mcp.ts)
  parseRunArgs            unknown fields, including _ctx, stripped
  detectHost              --host > CLAUDE_CODE_SESSION_ID > _meta x-codex-turn-metadata > generic
  ContextProvider         env, _meta, roots, companion-hook record only
  runScript               (src/core/run.ts)  timeout 120 s default, 600 s max, 55 s on Codex
    Sandbox.run → onCall → Dispatcher.dispatch     (src/core/dispatcher.ts)
      parseToolCall → prepare (deep-frozen) → checkStatic → authorize (hooks)
        updatedArgs → re-parse → re-prepare → checkStatic again
      → commit (mutations serialized in call order, reads concurrent)
    on error/timeout/cancel/deny in a transaction → stop, settle, rollback
  formatRunResult         30,000 / 9,500 char caps, overflow file 0600 in state dir 0700
src/
├── core/      types.ts (contracts), schemas.ts, dispatcher.ts, run.ts, output.ts, state-dir.ts, command-hook.ts, paths.ts
├── server/    mcp.ts, context.ts (providers + host detection), runtime.ts (factory, fakes today)
├── testing/   FakeSandbox, StaticHostAdapter, MemoryToolRuntime
└── cli.ts     serve [--host], hook and install stubs, --version

Evidence

  • Before: the repo held only a README.
    After: npm run verify passes: typecheck, 86 tests in 8 files, build. CI is green on all 5 jobs (ubuntu and macos × Node 22/24, windows typecheck + test).
  • e2e (src/server/mcp.test.ts): SDK client → linked transport → server → FakeSandbox → Dispatcher → StaticHostAdapter → MemoryToolRuntime. Calls come back as c1 allowed, c2 denied (rule: rm is not allowed), c3 allowed, and the transaction variant rolls back out.txt.
  • The built CLI was checked by hand: piping initialize and tools/call into node dist/cli.js serve returned the run result with the denied rm call.
  • Dispatcher rule tests: 20 reads + 5 writes in Promise.all keep write order (c5,c10,c15,c20,c25) with reads running concurrently. Also tested: a deny in a transaction rolls back earlier writes; updatedArgs pointing outside the workspace are refused; nothing commits after a stop; a commit still running at stop is reported; a throwing hook becomes deny hook-error.

Merge Danger

Door: two-way

Nothing exists yet that depends on this. Changing a contract later means reopening the parts built on it.

Blast Radius: contracts

Parts P1 to P5 build against src/core/types.ts. A contract that turns out wrong costs one cross-part PR.

Decisions

  • Authorization order: if a permission rule already denies or asks, hooks do not run, so hook side effects such as logging do not happen for those calls. The alternative was to run hooks first, the way Claude does natively, and then let rules win.
  • Writes to protected host files (hook and settings files, the state dir) fail as a normal tool error that the script can catch. The alternative was a permission denial that aborts a transaction.
  • A rewritten call that is invalid: if a hook's rewritten call is invalid or points somewhere refused, it counts as a denial and aborts a transaction. The alternative was a catchable tool error.
  • Protected-path matching ignores letter case on macOS and Windows.
  • Codex run timeout is capped at 55 s, under Codex's documented 60 s tool timeout.
  • Transaction scope: only a denied call aborts a transactional run. Other failed calls (file not found, stale file) are reported to the script and do not trigger a rollback.
  • Tool argument checking: unknown keys in tool arguments (e.g. file_path instead of path) are rejected with a clear error. Unknown keys on the run input itself are silently dropped.
  • Contract changes from the brief: commit receives the transaction explicitly, so concurrent runs do not share a journal. A binding call resolves to an ok/error reply and never throws. Results carry a warnings list, used for things like "bash effects are not rolled back" and commits that were running at stop.
  • Edit match strategies are fixed to exact, line-trimmed, whitespace-normalized and indentation-flexible. The tools part can extend the list.
  • The shipped server runs the test fakes (in-memory files, a placeholder rule that denies rm) until the integration part swaps in the real pieces.
  • Commit author is the GitHub noreply address, because no git identity was configured and a personal email would be public.
  • Toolchain: TypeScript 7 and vitest 5, the current releases.

🤖 Generated with Claude Code

mths-mcfs and others added 3 commits November 15, 2026 02:30
Add the project skeleton (package, TypeScript strict ESM, vitest, CI on
Linux, macOS and Windows, Apache-2.0 LICENSE and NOTICE, CLAUDE.md and
AGENTS.md) and the frozen contracts the sandbox, host adapter, tool and
benchmark parts build against.

The run path is executable end to end with test fakes: MCP tools/call ->
FakeSandbox -> Dispatcher (prepare, static rules, hooks, re-prepare on
updated args, commit) -> StaticHostAdapter -> MemoryToolRuntime, with
mutation ordering, cancellation, transactions with rollback, output caps
with overflow files, and a command hook runner that kills the process
group on timeout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Commit a dispatcher-owned deep-frozen copy of each prepared call; deep
  freeze now descends into objects that are already frozen.
- Bound every await on adapter and runtime code by the run's abort signal
  or a grace: prepare, PostToolUse (which now receives the signal),
  loadPolicy (the run deadline starts before it), in-flight calls on stop,
  rollback and dispose.
- Kill the command hook's whole process group on every completion path,
  so a backgrounded descendant cannot outlive the hook.
- Send protocol and validation errors through the capped result
  formatter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mths-mcfs
mths-mcfs marked this pull request as ready for review November 19, 2026 05:21
mths-mcfs and others added 2 commits November 19, 2026 03:17
- Validate adapter decisions with a schema, reject non-string tool names and
  refresh the call summary after a hook rewrite.
- Keep overflow output out of non-private state directories and off Windows.
- Match path patterns across newlines and treat "..name" as inside a root.
- Run a single deadline from the start of the run, counting policy loading,
  and give the sandbox the time left rounded up.
- Roll back only after queued writes and edits end, report a pending
  rollback, and dispose the journal after the rollback has really finished.
- Make the fake sandbox check its deadline before steps and calls, yield
  between steps, and tie its deadline and sleeps to one signal.
- Describe the placeholder runtime the default server serves, with a
  runnable example.
- Resolve in-memory paths against the session cwd and roots (Windows paths
  included), track file revisions for rollback, and run grep and glob in a
  stoppable worker thread.
- Accept only a single --host option in serve.
- Skip spawning a hook whose run was already cancelled and stop recording
  calls in the default runtime.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Fake runtime: cap concurrent search workers per runtime; extra searches wait in a cancelable queue and a slot is reused only after its worker exits.
- Fake runtime: build the search job after a slot is held, send grep content only for files that pass the name filter, and reject a search that would copy more than the text limit.
- Fake runtime: count edit occurrences and build the diff without per-match or per-line arrays.
- Normalize Windows drive paths in the fake runtime and path patterns, and restore original revisions on rollback.
- Run: check the deadline before opening a transaction and word the pending-rollback warning accurately.

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

Copy link
Copy Markdown
Owner Author

NEEDS_HUMAN for 3cba6aea72a1db732e3acca9e8e9b92c0c6225a2. Local typecheck and all five CI jobs passed, including the Windows job that failed in round 2. CI run

The third round requires design decisions on two recurring findings.

  • Windows network shares. The runtime and the protection rules still use different forms of share paths. Choose a common representation for both, or explicitly exclude network shares from the workspaces supported by this milestone.
  • Edit preparation. Large edits can still consume disproportionate memory while preparing the edited text and diff, before the permissions check. Decide how to bound that intermediate work while keeping ordinary edit results intact.

The review had one full round and two confirmation rounds. The two correction commits are 535304b and 3cba6ae. The ledger records 6 resolved blockers, 12 major findings and 10 minor findings, including follow-up corrections. From the initial diff to the reviewed head, added lines went from 3,408 to 3,760 in code, from 1,077 to 1,425 in tests and stayed at 56 in docs. The first correction added 671 lines after the cut pass and the follow-up deadline and rollback checks, above the 300-line threshold.

🔐 Protected paths ignore letter case on Mac and Windows

  • What changes. A protection rule also covers paths with different letter case on those platforms.
  • Who it affects. Users with case-sensitive workspaces on those platforms.
  • At deployment. The rule applies on the next protected-path check.
  • Where it came from. The implementation chose the comparison rule. The request requires applying host protection rules.
  • How to change it. Use each workspace's filesystem case behavior when matching its rules.

🔐 The project uses the Apache 2.0 license

  • What changes. The project offers the code under Apache 2.0 terms.
  • Who it affects. People and organizations that use, modify or redistribute the code.
  • At deployment. The default branch would include the license and attribution notice.
  • Where it came from. The implementation added the license. The request did not specify one.
  • How to change it. Choose the terms for future versions with the rights holders.

The decision labels become actionable once the technical findings are resolved and the review reaches READY.

For later. Glob can stop scanning after the first extra match, and cancelled searches can skip preparation as soon as a worker slot opens. The review also recorded uncommon relative-name matching, Windows hook process cleanup and remaining coverage gaps.

Verification scope. The CI and the CLI smoke test exercised the simulated server. The production sandbox and host adapters are future work. The edit memory finding comes from static inspection of the runtime.

Other implementation choices

Static permission checks run before hooks

  • What changes. Attempts that rules refuse or send for confirmation skip the hooks.
  • Who it affects. Users who rely on hooks for audit records or alerts.
  • At deployment. Those attempts stop appearing in hook logs.
  • Where it came from. The request requires both checks and leaves their order open.
  • How to change it. Run hooks on refused attempts while keeping the rules' final verdict.

Direct and rewritten protected-path errors have different transaction behavior

  • What changes. A script can handle a direct protected-path error and continue. An invalid or protected rewrite stops and rolls back the transaction.
  • Who it affects. Scripts that group writes into transactions and users whose hooks rewrite operations.
  • At deployment. The behavior applies to the next transaction that encounters one of these cases.
  • Where it came from. The request distinguishes tool errors and refusals and leaves these cases open.
  • How to change it. Give both cases the transaction behavior the owner selects.

Codex script runs have a 55-second ceiling

  • What changes. Longer requested script durations are capped at 55 seconds.
  • Who it affects. Codex users batching operations close to one minute.
  • At deployment. The ceiling applies to subsequent Codex runs.
  • Where it came from. The request calls for a shorter Codex limit. The implementation picks the number.
  • How to change it. Adjust the ceiling while leaving time for the host to receive the response.

Rollback covers recorded file changes

  • What changes. A rollback restores recorded writes and edits. Terminal command effects can remain after rollback when real command execution is integrated.
  • Who it affects. Scripts that combine file editing and commands in a transaction.
  • At deployment. The placeholder only echoes commands. The recorded choice applies when real command execution arrives.
  • Where it came from. The request requires reverting recorded mutations and leaves command effects open.
  • How to change it. Define which commands transactions may run before integrating real execution.

Extra fields cause a binding error

  • What changes. A binding rejects arguments with an unknown field even if its required fields are present.
  • Who it affects. Script authors and clients that generate binding arguments.
  • At deployment. Operations with extra fields return an argument error.
  • Where it came from. The request requires argument validation and leaves extra fields open.
  • How to change it. Accept inputs with extra keys and use the recognized fields.

Oversized responses return a preview on Windows

  • What changes. Windows receives a capped preview and an explanation when the full response cannot be written privately.
  • Who it affects. Windows users who need the complete output of a large run.
  • At deployment. An oversized response on Windows includes the preview in the tool reply.
  • Where it came from. The request requires private overflow storage. The review chose the preview fallback for Windows.
  • How to change it. Verify private Windows storage before saving the complete response.

Searches have an input limit in the simulated runtime

  • What changes. Searches whose candidate names and eligible content exceed 20 million characters return a tool error.
  • Who it affects. Users searching large or numerous files in the simulated workspace.
  • At deployment. The search reports the limit and asks the caller to narrow the scope.
  • Where it came from. The review bounded the amount of search data sent between threads.
  • How to change it. Process the data in bounded batches and gather the results across batches.

@mths-mcfs mths-mcfs added the review-loop:needs-human O loop de revisão precisa de uma pessoa para continuar label Nov 19, 2026
@mths-mcfs
mths-mcfs marked this pull request as draft November 19, 2026 14:03
mths-mcfs and others added 2 commits November 19, 2026 11:09
…untime

Network-share (UNC) paths are not supported: POSIX resolution folds their
leading `//` while protected-path patterns keep it, so a protected share
could go unrecognized. The fixed root, seeded files, session cwd and roots,
and call paths now refuse UNC paths before any call is prepared.

Edit and write preparation now size the change from cheap counts first and
refuse, before building the edited text or the diff, an edit with more than
MAX_EDIT_REPLACEMENTS (50,000) replacements or a diff over MAX_DIFF_LINES
(200,000) lines. Changes under the budget produce the same text and diff.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The session roots are checked for network-share (UNC) paths even when a
  fixed root replaces them, so a UNC session root is refused, not ignored.
- setFile and revision refuse UNC paths like every other path entry point.
- The diff line budget counts the rows the diff actually has: a text that
  ends with a line break no longer counts one extra row. Edit preparation
  works out whether the edited text ends with one from where the replaced
  occurrences sit, still before building the text or the diff, so diffs
  of up to MAX_DIFF_LINES rows are prepared and only larger ones refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mths-mcfs
mths-mcfs marked this pull request as ready for review November 19, 2026 14:23
@mths-mcfs mths-mcfs removed the review-loop:needs-human O loop de revisão precisa de uma pessoa para continuar label Nov 19, 2026
mths-mcfs and others added 2 commits November 19, 2026 11:44
Keep POSIX paths with redundant leading slashes local.
Return actionable guidance when an edit exceeds the replacement limit.
Stop glob after its first extra match and skip setup for cancelled searches.
Match local protection patterns and resolved paths with the same leading-slash normalization.
Use one resolved key for in-memory reads, writes and file revisions.

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

Copy link
Copy Markdown
Owner Author

READY, awaiting three decisions for fc6026bfd397384d5120be046a9e5d0cc9e7a8e0. The local typecheck, 64 focused tests and all five GitHub Actions jobs passed. CI run

The incremental review took three confirmation rounds. The author's updates resolved the two findings that stopped the previous review. The review loop then fixed one major and five minor findings in 7396009 and fc6026b. The added regression checks caught the earlier failures. Two isolated mutations also confirmed the glob truncation and cancellation assertions.

From the start of this episode to the final head, added lines went from 3,849 to 3,853 in code and from 1,529 to 1,559 in tests. The documentation count was 56 lines at both heads.

🔐 File protection ignores case on macOS and Windows

  • What changes. A protection rule covers paths that differ only in letter case on those platforms.
  • Who it affects. People using case-sensitive workspaces on macOS or Windows.
  • At deployment. The next protection check applies this matching rule.
  • Source. The request calls for applying host protection rules. The implementation chose how to compare letter case.
  • How to change it. Use the workspace filesystem's case behavior when matching protection rules.

🔐 The project uses the Apache 2.0 license

  • What changes. The project offers the code under Apache 2.0 terms.
  • Who it affects. People and organizations that use, modify or redistribute the project.
  • At deployment. The default branch gains the license and attribution notice.
  • Source. The implementation selected a license. The request left that choice open.
  • How to change it. Choose the terms for future versions with the rights holders.

🔐 The simulated server refuses Windows network shares

  • What changes. The server refuses paths on Windows network shares and special Windows device paths. A network share in the session's working directory or allowed folders also causes the operation to be refused.
  • Who it affects. People using network shares to configure this version of the server or as a file destination.
  • At deployment. The rule applies on the first file operation in a session that lists a network share, even when the fixed workspace is local.
  • Source. The request requires host protections. The implementation chose which workspace paths to support in this release.
  • How to change it. Support shares once the server and its protection rules can agree on the same network path.

To proceed with the merge, add review-loop:aprovado. To request a change, describe it here and add review-loop:refazer.

For later. Exercise the network working directory and allowed folders independently in tests. Stop the replacement scan as soon as it reaches its limit.

Verification scope. The checks cover the simulated server. The production sandbox and host adapters are follow-up work.

Other implementation choice

Large writes and edits have preparation limits

  • What changes. One edit can make up to 50,000 replacements. The old and new versions combined can cover up to 200,000 lines when preparing a change.
  • Who it affects. People working with long files or bulk edits in the simulated server.
  • At deployment. The first operation exceeding a limit returns an error and leaves the file as it was.
  • Source. The implementation chose these limits to bound the work before authorization.
  • How to change it. Adjust the limits while keeping a bound on preparation work. Users can retry operations after narrowing the edit.

@mths-mcfs mths-mcfs added review-loop:decisao Apto tecnicamente; aguardando decisão de produto do usuário review-loop:ready Revisão e verificações concluídas no head avaliado review-loop:aprovado Você aprovou as decisões do cartão and removed review-loop:aprovado Você aprovou as decisões do cartão review-loop:decisao Apto tecnicamente; aguardando decisão de produto do usuário labels Nov 19, 2026
@mths-mcfs
mths-mcfs merged commit 3c57d67 into main Nov 19, 2026
6 checks passed
@mths-mcfs

Copy link
Copy Markdown
Owner Author

MERGED into main as 3c57d6724997bb68d7058c8f0874e8e2061d2cab (squash). The merged tree matches reviewed head fc6026bfd397384d5120be046a9e5d0cc9e7a8e0. All three decision cards were approved on that head.

The incremental episode took three confirmation rounds. Commits 7396009 and fc6026b fixed one major and five minor findings. The local typecheck, 64 focused tests, and all five CI jobs passed. CI run

Added lines went from 3,849 to 3,853 in code and from 1,529 to 1,559 in tests. Documentation stayed at 56 added lines. The lockfile was outside the review diff.

For later, the review noted POSIX filenames containing a colon, more direct tests for cancellation and network-share rejection, and one extra match lookup at the replacement limit. The production sandbox and host adapters were outside this scaffold review. No follow-up issues were required.

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

Labels

review-loop:ready Revisão e verificações concluídas no head avaliado

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant