[PR #868] [MERGED] fix(native): pass Swift symbols to swift-demangle as operands #2304

Closed
opened 2026-10-16 21:17:01 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/868
Author: @kaoru0822-kitauji
Created: 10/7/2026
Status: ✅ Merged
Merged: 10/7/2026
Merged by: @kaoru0822-kitauji

Base: main ← Head: fix/swift-demangle-arguments


📝 Commits (2)

  • 6c88094 fix(native): pass Swift symbols to swift-demangle as operands
  • 01779a6 Merge remote-tracking branch 'origin/main' into fix/swift-demangle-arguments

📊 Changes

11 files changed (+175 additions, -16 deletions)

View changed files

📝 docs/product-catalog.json (+2 -2)
📝 docs/verification/managed-conformance-manifest.json (+2 -2)
📝 skills/reverse-engineer-anything/SKILL.md (+1 -1)
📝 src/cli/utilityCommands.ts (+2 -4)
📝 src/contracts/nativeToolContracts.ts (+12 -2)
📝 src/generatedMcpToolCatalog.ts (+1 -1)
📝 src/native/NativeMacOSProvider.ts (+2 -1)
📝 src/native/parsers/demangle.test.ts (+10 -1)
📝 src/native/parsers/demangle.ts (+6 -2)
➕ tests/boundary/cli/nativeDemangleCli.test.ts (+61 -0)
➕ tests/boundary/mcp/nativeDemangleMcp.test.ts (+76 -0)

📄 Description

Summary

demangle_swift (MCP) and rea demangle-swift (CLI) mishandled three kinds of symbol text:

  • Option-like symbols. Symbols were appended after --compact with no separator, so swift-demangle read -help as its own option, printed usage, and REA reported unreadable_output / "Native output parsing failed". Options that change formatting (e.g. --simplified, --expand) could also silently change how later symbols were demangled. Symbols now follow --.
  • Carriage returns. The parser split on \r?\n, but swift-demangle ends each record with LF. A symbol such as name\r came back with the CR stripped and was reported as demangled to a different value. Records are now split on LF only.
  • Line feeds. A symbol containing LF produces more output records than inputs, which also failed as unreadable_output. The shared input schema now rejects a multi-line symbol (pattern: ^[^\n]*$, advertised in JSON Schema). The CLI reuses the contract schema instead of keeping a separate, weaker copy.

Contract change

The demangle_swift input schema adds pattern: "^[^\\n]*$" to each symbol, and the description now says "single-line". The generated catalog, skill, and conformance manifest were regenerated. I checked the advertised MCP input schema with Ajv 2020: ["$s4main3FooV", "a\rb"] is accepted and ["a\nb"] is rejected.

{"symbols":{"minItems":1,"type":"array","items":{"type":"string","minLength":1,"pattern":"^[^\\n]*$"}}}

Verification

  • tests/boundary/mcp/nativeDemangleMcp.test.ts (darwin only) runs the real MCP server against real xcrun swift-demangle. It covers -help, --simplified, $s4main3FooV → main.Foo, carriage\r, and rejection of a multi-line symbol. It fails on main with unreadable_output.
  • tests/boundary/cli/nativeDemangleCli.test.ts (darwin only) runs the real CLI. It covers CR preservation and multi-line rejection.
  • src/native/parsers/demangle.test.ts covers CR-bearing symbols.
  • npm run check:changed, npm run docs:check, and npm run test:focused on the new tests plus tests/boundary/providers/native/nativeProvider.test.ts and src/contracts/toolContracts.test.ts all pass.

The CLI still cannot receive option-like symbols, because incur parses them as flags before REA sees them, and it does not accept --. This PR only fixes that case on the MCP path.

No Hopper/Ghidra/IDA verification is needed (native macOS utilities only).

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/868 **Author:** [@kaoru0822-kitauji](https://github.com/kaoru0822-kitauji) **Created:** 10/7/2026 **Status:** ✅ Merged **Merged:** 10/7/2026 **Merged by:** [@kaoru0822-kitauji](https://github.com/kaoru0822-kitauji) **Base:** `main` ← **Head:** `fix/swift-demangle-arguments` --- ### 📝 Commits (2) - [`6c88094`](https://github.com/morluto/rea/commit/6c88094da45258b346fe594764e561f999622a58) fix(native): pass Swift symbols to swift-demangle as operands - [`01779a6`](https://github.com/morluto/rea/commit/01779a6f61dd0537d1e5951b36d46b9796135d9a) Merge remote-tracking branch 'origin/main' into fix/swift-demangle-arguments ### 📊 Changes **11 files changed** (+175 additions, -16 deletions) <details> <summary>View changed files</summary> 📝 `docs/product-catalog.json` (+2 -2) 📝 `docs/verification/managed-conformance-manifest.json` (+2 -2) 📝 `skills/reverse-engineer-anything/SKILL.md` (+1 -1) 📝 `src/cli/utilityCommands.ts` (+2 -4) 📝 `src/contracts/nativeToolContracts.ts` (+12 -2) 📝 `src/generatedMcpToolCatalog.ts` (+1 -1) 📝 `src/native/NativeMacOSProvider.ts` (+2 -1) 📝 `src/native/parsers/demangle.test.ts` (+10 -1) 📝 `src/native/parsers/demangle.ts` (+6 -2) ➕ `tests/boundary/cli/nativeDemangleCli.test.ts` (+61 -0) ➕ `tests/boundary/mcp/nativeDemangleMcp.test.ts` (+76 -0) </details> ### 📄 Description ## Summary `demangle_swift` (MCP) and `rea demangle-swift` (CLI) mishandled three kinds of symbol text: - **Option-like symbols.** Symbols were appended after `--compact` with no separator, so `swift-demangle` read `-help` as its own option, printed usage, and REA reported `unreadable_output` / "Native output parsing failed". Options that change formatting (e.g. `--simplified`, `--expand`) could also silently change how later symbols were demangled. Symbols now follow `--`. - **Carriage returns.** The parser split on `\r?\n`, but `swift-demangle` ends each record with LF. A symbol such as `name\r` came back with the CR stripped and was reported as `demangled` to a different value. Records are now split on LF only. - **Line feeds.** A symbol containing LF produces more output records than inputs, which also failed as `unreadable_output`. The shared input schema now rejects a multi-line symbol (`pattern: ^[^\n]*$`, advertised in JSON Schema). The CLI reuses the contract schema instead of keeping a separate, weaker copy. ## Contract change The `demangle_swift` input schema adds `pattern: "^[^\\n]*$"` to each symbol, and the description now says "single-line". The generated catalog, skill, and conformance manifest were regenerated. I checked the advertised MCP input schema with Ajv 2020: `["$s4main3FooV", "a\rb"]` is accepted and `["a\nb"]` is rejected. ```json {"symbols":{"minItems":1,"type":"array","items":{"type":"string","minLength":1,"pattern":"^[^\\n]*$"}}} ``` ## Verification - `tests/boundary/mcp/nativeDemangleMcp.test.ts` (darwin only) runs the real MCP server against real `xcrun swift-demangle`. It covers `-help`, `--simplified`, `$s4main3FooV` → `main.Foo`, `carriage\r`, and rejection of a multi-line symbol. It fails on `main` with `unreadable_output`. - `tests/boundary/cli/nativeDemangleCli.test.ts` (darwin only) runs the real CLI. It covers CR preservation and multi-line rejection. - `src/native/parsers/demangle.test.ts` covers CR-bearing symbols. - `npm run check:changed`, `npm run docs:check`, and `npm run test:focused` on the new tests plus `tests/boundary/providers/native/nativeProvider.test.ts` and `src/contracts/toolContracts.test.ts` all pass. The CLI still cannot receive option-like symbols, because incur parses them as flags before REA sees them, and it does not accept `--`. This PR only fixes that case on the MCP path. No Hopper/Ghidra/IDA verification is needed (native macOS utilities only). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-16 21:17:01 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#2304
No description provided.