Repository navigation
feat(llm): ctx.fs + ctx.tools + ctx.exec + ctx.sandbox capability seam (ar-plan PR #4) - #157
Merged
Merged
Conversation
…m (ar-plan PR #4, S1.b-e) Extend the Ctx envelope (PR #3 shipped ctx.llm) with four provider-neutral seams so consumers inject ctx.fs / ctx.tools / ctx.exec / ctx.sandbox instead of importing concrete adapters. Solves arch-ecosystem A3 (no DSH-style capability injection seam). Each seam is a thin facade wrapping an EXISTING primitive, not a rewrite: - fs.ts LocalFsCapability — node:fs/promises read/write/glob + rg grep - tools.ts BaseToolsCapability — getAllBaseTools + findToolByName + isToolDenied - exec.ts InProcessExecCapability (node:child_process spawn) + ExecutorExecCapability (drain callBashViaExecutor generator) - sandbox.ts NoneSandboxProvider no-op stub (Landlock = cross-repo defer) Default-off + byte-identical when off: fs+tools are pure facades invoked by 0 migrated prod consumers this PR (define seam + demo in tests only, gradual migration is later PRs per ar-plan). exec is env-gated (FUSION_CODE_CTX_EXEC_ENABLED, default undefined). sandbox not injected. Existing BashTool routing + runShellCommand orchestration stay UNTOUCHED — the exec seam is for future one-shot exec consumers, not a replacement. Tests: 4 new capability test files (fs/tools/exec/sandbox) + 7 new createCtx seam tests in capability.test.ts. typecheck clean, 589 tests pass, lint clean on changed files, build:dev passes. Co-Authored-By: Claude Fable 5 <[email protected]>
dahai80
added a commit
that referenced
this pull request
Aug 27, 2026
Biome formatter reformat (import reorder/organize, line-wrap). Zero logic change. PR #157 landed these files pre-formatted; this commits the on-disk formatted version. Files: src/services/llm/{ctx,capabilities/{exec,fs,tools}}.ts, src/__tests__/services/llm/{capability,capabilities/{fs,sandbox,tools}}.test.ts Co-Authored-By: Claude Fable 5 <[email protected]>
dahai80
added a commit
that referenced
this pull request
Aug 28, 2026
…173) First real prod consumer for the ctx.llm capability seam (ar-plan PR #155/#157 landed it byte-identical-off with 0 prod consumers — 555 LOC dead scaffolding). Per audit 1.1.2 decision "wire 1 real consumer". sideQuery (stateless, async, self-contained) now builds a Ctx and passes it to modelSupportsStructuredOutputs when: - output_format is in play (structured-output beta decision), AND - provider is cloud (firstParty/foundry/bedrock/vertex/openai). fusionMlx stays on the old provider-if path: its capability reads MLX model keywords (qwen3/llama3/...) and would enable the beta for models the old path blanket-denied — a deliberate capability-authoritative divergence deferred until the MLX beta-header behavior is verified. Cloud path is byte-identical (firstParty 6-clause list matches betas.ts; foundry/3P both return false). Fail-open: ctx build error -> undefined ctx -> old path (no new failure mode). Lazy: ctx only built when output_format truthy AND provider non-MLX. Globals getCwd()/getSessionId() (sync) supply cwd/sessionId without prop-drilling (sideQuery has 10 callers, all classifiers, stateless). Test: src/__tests__/utils/sideQueryCtxSeam.test.ts (7 tests, 38 expect): - firstParty 9 model ids with-ctx == no-ctx (byte-identical loop) - firstParty structured models return true - firstParty non-structured returns false - foundry capability-authoritative returns true - bedrock/vertex/openai byte-identical (both false) - fusionMlx gate: sideQuery passes ctx=undefined -> old path false (reference ctx would return true — divergence documented) - seam guard: mismatched ctx.llm.modelId falls back to old path Also fix pre-existing typecheck error in viewedTaskSelector.test.ts (fakes re-typed to narrowed InProcessTeammateTaskState/LocalAgentTaskState — .toBe() overload rejected widened TaskState). Behavior unchanged, 10/10 still pass. Per repo rule: fix failing cases even if unrelated. Gates: typecheck 0 / 721 tests / lint net-zero 4601 / build:dev 3762. Co-authored-by: Claude Fable 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PR #4 of the 9-PR ar-plan (
fusion-code-enhance-ar-plan-0827.md), milestone M2. Extends theCtxenvelope shipped in PR #3 (ctx.llm) with four provider-neutral capability seams — solves arch-ecosystem A3 (no DSH-stylectx.fs / ctx.tools / ctx.execinjection seam).ctx.fscapabilities/fs.tsnode:fs/promisesread/write/glob +rggrepctx.toolscapabilities/tools.tsgetAllBaseTools+findToolByName+isToolDeniedctx.exec?capabilities/exec.tsInProcessExecCapability(node:child_processspawn) +ExecutorExecCapability(draincallBashViaExecutor)ctx.sandbox?capabilities/sandbox.tsNoneSandboxProviderno-op stub (Landlock = cross-repo defer)Design — facade, not rewrite
Per the ar-plan constraint: "fs/tools seam 抽象易过度 → 包现有工具不重写(capability = facade). consumer 迁移渐进而非全量(本 PR 只定义 seam + 1-2 示范消费点,余渐进)". Each provider wraps ONE existing primitive — no new logic, no re-listing. If a provider would duplicate
runShellCommand's 1000 lines, it's wrong.ctx.fsusesnode:fs/promisesdirectly, NOT theFileReadToolobject (that pullsToolUseContext/permissions/UI graph — facade keeps the seam primitive-light).ctx.toolswraps the 3 registry primitives;callTool()deferred (needs fullToolUseContext, would over-couple).ctx.exectwo swappable backends. ExistingBashToolrouting +runShellCommandorchestration stay UNTOUCHED — this seam is for future one-shot exec consumers (ctx-inspect, code-search helpers) that want a result without the BashTool orchestration layer.ctx.sandboxstub only — macOS seatbelt stays in BashTool; Linux Landlock is a cross-repofusion-executordependency, deferred.Byte-identical when off
fs+toolsalways present (pure facades) but invoked by 0 migrated prod consumers this PR — demo consumers live in the test suite only. No behavior change.execenv-gated viaFUSION_CODE_CTX_EXEC_ENABLED(default undefined →ctx.execundefined).sandboxnot injected →ctx.sandboxundefined.PR #3's ctx-optional pattern holds: existing 2 consumers (
betas.ts,thinking.ts) still pass no-ctx → old path.Tests
fs.test.ts,tools.test.ts,exec.test.ts,sandbox.test.tscreateCtxseam tests incapability.test.ts(fs populated + round-trip, tools list/getTool, exec undefined-when-off / defined-when-on, sandbox undefined)Gates
bun run typecheck— clean (1 pre-existing unrelatedretrieveContext.testbaseline, not introduced)bun test src/__tests__/— 589 pass / 0 fail (was 514+; +~40 new)bun run lint— changed files clean (4601 pre-existing baseline unaffected; CI lints new files only)bun run build:dev— passScope-creep deferred (explicit)
QueryEngine, Read/Grep/Glob tools) toctx.fs/ctx.tools→ gradual, future PRsBashToolrouting viactx.exec→ NOT this PRSandboxCapabilityimpl → cross-repofusion-executorissuecallTool()onToolsCapability→ deferred (needs fullToolUseContext)Co-Authored-By: Claude Fable 5 [email protected]