Skip to content

refactor(agents): resolve code-mode vs tool-search once for every harness - #115189

Merged
steipete merged 3 commits into
mainfrom
steipete/busy-bartik-7cb866
Jul 28, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/busy-bartik-7cb866

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

The decision of whether a run gets Code Mode, a Tool Search catalog, or the raw
tool surface was implemented twice — once in the embedded agent runner and once
in the native harness bridge that Copilot runs on. The two copies had already
drifted: the harness copy was missing the skillWorkshopProposalOnly condition,
and its params object had no field to express it, so the divergence could not be
seen from the harness side at all.

The three-way catalog application (Code Mode / schema-directory / Tool Search)
was likewise duplicated nearly verbatim across the same two surfaces, including
the invariant that a policy-required message tool must stay directly visible.

Why This Change Was Made

Both surfaces now consume one resolver, resolveAgentToolSurfacePlan, plus one
catalog applier, applyAgentToolSurfaceCatalog. Both gate booleans derive from a
single shared toolsAvailable intermediate, so Code Mode and Tool Search cannot
drift apart again, and the "message tool must stay directly visible" invariant is
stated once. The old inline copies are deleted rather than kept alongside.

createCodeModeTools intentionally stays at each call site: its arguments
genuinely differ (forceRestartSafeTools, codeModeSkills), so sharing it would
add an adapter that only renames fields.

Deliberate behavior decision: skillWorkshopProposalOnly now applies to the
harness path too. A proposal-only skill-workshop run is a deliberately narrow
single-tool run (toolsAllow: ["skill_workshop"], disableMessageTool: true,
lightweight bootstrap), so Code Mode indirection and a Tool Search catalog are
pure overhead — a reason that does not depend on which harness runs the turn.
Both proposal-only callers currently pin agentHarnessRuntimeOverride: "openclaw"
(src/skills/workshop/history-scan-review.ts,
src/skills/workshop/experience-review.ts), so this closes a latent fail-open
rather than fixing a live bug.

Non-goal: the Codex app-server, which has its own codexDynamicToolsLoading
path and is untouched. Also out of scope: the separate client-tools catalog
branch in attempt-client-tools.ts, which has no harness sibling.

User Impact

No user-visible change on any shipped path. Operators keep the same Code Mode
and Tool Search behavior they have today; the one behavior difference is that a
skill-workshop proposal-only run routed through a native harness would now keep
the raw tool surface instead of engaging Code Mode, matching what the embedded
runner has always done.

Plugin authors implementing a native harness gain one optional pass-through
field, skillWorkshopProposalOnly, documented in docs/plugins/sdk-agent-harness.md.

Evidence

Proven on Blacksmith Testbox lease tbx_01kymabq83q54fp4x3vmg9404x
(exitCode: 0, runStatus: "succeeded"):

  • pnpm tsgo:core, pnpm tsgo:extensions, pnpm tsgo:test
  • pnpm test src/agents/embedded-agent-runner/run — 71 files, 928 tests passed
  • extensions/copilot/src/tool-bridge.test.ts — 77 tests passed
  • src/agents/tool-surface-plan.test.ts + src/agents/harness/tool-surface-bridge.test.ts
    — 25 tests passed

New coverage: the embedded runner's gate conditions previously had no focused
test. src/agents/tool-surface-plan.test.ts table-drives each suppressing input
(model tools disabled, disableTools, raw model run, ring-zero run, empty
explicit allowlist, skillWorkshopProposalOnly), asserts Code Mode and Tool
Search stay mutually exclusive, and pins which applier each mode selects.
tool-surface-bridge.test.ts adds a harness-level test proving a proposal-only
run keeps the raw tool surface with no exec/wait.

Per src/agents/embedded-agent-runner/run/AGENTS.md, this deliberately adds no
new full runEmbeddedAttempt test; the helper is production-called and tested
directly.

steipete added 2 commits July 28, 2026 05:14
…arness

The code-mode vs tool-search gate decision and the three-way catalog
application were duplicated across the embedded runner and the native
harness bridge, and had already drifted: the harness copy was missing the
skillWorkshopProposalOnly condition and its params object had no field to
express it.

Both surfaces now consume resolveAgentToolSurfacePlan and
applyAgentToolSurfaceCatalog, so the gates and the catalog branch exist
once. Both gate booleans derive from a single shared toolsAvailable
intermediate.

Behavior change: the harness path now honors skillWorkshopProposalOnly.
Proposal-only skill-workshop runs are deliberately narrow single-tool runs,
so code-mode indirection and tool-search catalogs are pure overhead — a
harness-independent reason. Both callers currently pin
agentHarnessRuntimeOverride "openclaw", so this closes a latent fail-open
rather than fixing a live bug.
resolveAgentToolSearchRuntimeConfig returns OpenClawConfig | undefined, so
requiring a non-null toolSearchRuntimeConfig broke tsgo:core at both call
sites. Keep the key required so it cannot be silently omitted, but let the
value be undefined as the pre-refactor code already allowed.
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling extensions: copilot size: M maintainer Maintainer-authored PR labels Jul 28, 2026
@steipete
steipete marked this pull request as ready for review July 28, 2026 12:32
Importing isCodeModeEngagedForModel and applyToolSchemaDirectoryCatalog from
their defining modules left the code-mode.ts and tool-search.ts re-exports with
no production consumer, which knip rejects. Go back through the barrels, which
is also what both call sites did before this refactor.

The two params types were exported only for the test, so knip's production scan
saw them as dead. Keep them module-local and derive the type in the test.
@steipete
steipete merged commit fe9893d into main Jul 28, 2026
188 of 190 checks passed
@steipete
steipete deleted the steipete/busy-bartik-7cb866 branch July 28, 2026 13:16
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 29, 2026
…ness (openclaw#115189)

* refactor(agents): share one tool-surface resolver across runner and harness

The code-mode vs tool-search gate decision and the three-way catalog
application were duplicated across the embedded runner and the native
harness bridge, and had already drifted: the harness copy was missing the
skillWorkshopProposalOnly condition and its params object had no field to
express it.

Both surfaces now consume resolveAgentToolSurfacePlan and
applyAgentToolSurfaceCatalog, so the gates and the catalog branch exist
once. Both gate booleans derive from a single shared toolsAvailable
intermediate.

Behavior change: the harness path now honors skillWorkshopProposalOnly.
Proposal-only skill-workshop runs are deliberately narrow single-tool runs,
so code-mode indirection and tool-search catalogs are pure overhead — a
harness-independent reason. Both callers currently pin
agentHarnessRuntimeOverride "openclaw", so this closes a latent fail-open
rather than fixing a live bug.

* fix(agents): let the shared catalog params carry a config-less run

resolveAgentToolSearchRuntimeConfig returns OpenClawConfig | undefined, so
requiring a non-null toolSearchRuntimeConfig broke tsgo:core at both call
sites. Keep the key required so it cannot be silently omitted, but let the
value be undefined as the pre-refactor code already allowed.

* fix(agents): keep the tool-surface module free of dead exports

Importing isCodeModeEngagedForModel and applyToolSchemaDirectoryCatalog from
their defining modules left the code-mode.ts and tool-search.ts re-exports with
no production consumer, which knip rejects. Go back through the barrels, which
is also what both call sites did before this refactor.

The two params types were exported only for the test, so knip's production scan
saw them as dead. Keep them module-local and derive the type in the test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation extensions: copilot maintainer Maintainer-authored PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant