pi-mono/packages/codemode/src
Petr Houška 6d3e342b25
fix(coding-agent): follow local schema refs in tool search and codemode summaries (#11850)
Fixes #11803.

**Problem**

`tool_search` builds a tool's search text from its parameter schema but
never followed `$ref`. MCP servers (Pydantic, FastMCP) often put nested
models in `$defs`:

```json
{ "properties": { "options": { "$ref": "#/$defs/options" } },
  "$defs": { "options": { "properties": { "mode": { "description": "reconciliation" } } } } }
```

Search text was `Inspect records options`, so
`tool_search("reconciliation")` found nothing. Durable's copy of
`tool_search` had the same gap. The codemode `resolves to` summary had
the same blind spot for output schemas: a field behind a `$ref` showed
as `structuredContent?` with no field names.

**Fix**

- pi-codemode exports its existing local JSON Pointer resolver as
`resolveSchemaRef(ref, root)`. A malformed percent escape now resolves
to nothing instead of throwing `URIError` (this also affected
`schemaToType()`).
- coding-agent and Durable `schemaText()` follow local `$ref`s. Each
referenced subschema is read once, so recursive and shared definitions
neither loop nor inflate BM25 term counts. Unreferenced `$defs` and
remote refs stay out.
- coding-agent `describeFields()`/`describeUnionFields()` resolve `$ref`
chains against the output schema root.

**Tests**

- `packages/codemode/test/declarations.test.ts`: escaped, remote,
missing, malformed refs.
- `packages/coding-agent/test/tool-search.test.ts`: refs, escaped
segments, recursion and shared definitions, unused definitions.
- `packages/coding-agent/test/suite/agent-session-codemode.test.ts`:
summary through root, field, const, and union refs.
- `packages/durable/test/tool-search.test.ts`: end-to-end load via a
ref'd description; unused definition does not match.

`npm run check` passes.
2026-11-06 00:19:58 +01:00
..
runtime fix(coding-agent): keep codemode cancellation prompt and bounded 2026-10-13 18:17:31 +02:00
cloudflare-modules.d.ts feat(codemode): run sandboxes on Cloudflare Workers via a remote Durable Object 2026-10-10 14:41:36 +02:00
cloudflare.ts feat(codemode): run sandboxes on Cloudflare Workers via a remote Durable Object 2026-10-10 14:41:36 +02:00
declarations.ts fix(coding-agent): follow local schema refs in tool search and codemode summaries (#11850) 2026-11-06 00:19:58 +01:00
identifier.ts feat(coding-agent): codemode and MCP 2026-09-29 09:12:50 +02:00
index.ts fix(coding-agent): follow local schema refs in tool search and codemode summaries (#11850) 2026-11-06 00:19:58 +01:00
portable.ts feat(codemode): deterministic runs that the host answers (sandbox.start) 2026-10-11 19:50:26 +00:00
source.ts fix(codemode): reject // @options: lines that are not the first line 2026-10-12 17:55:33 +02:00
types.ts fix(coding-agent): keep codemode cancellation prompt and bounded 2026-10-13 18:17:31 +02:00
wasm.ts feat(coding-agent): codemode and MCP 2026-09-29 09:12:50 +02:00