Skip to content

Fix invalid triple-quote delimiter in generated Swift plugin scaffold#1701

Open
jax-0n-git wants to merge 1 commit into
osaurus-ai:mainfrom
jax-0n-git:fix/tools-create-swift-manifest-triple-quote
Open

Fix invalid triple-quote delimiter in generated Swift plugin scaffold#1701
jax-0n-git wants to merge 1 commit into
osaurus-ai:mainfrom
jax-0n-git:fix/tools-create-swift-manifest-triple-quote

Conversation

@jax-0n-git

Copy link
Copy Markdown
Contributor

Summary

osaurus tools create <name> with the default language (swift) scaffolds a Sources/<module>/Plugin.swift that does not compile.

The scaffold template (ToolsCreate.createSwiftPlugin's pluginSwift) is itself a Swift """...""" literal. The get_manifest body opens its manifest with the delimiter written as \\"\\"\\" (ToolsCreate.swift:415, and the matching close at :446). Inside the outer multiline literal, \\ collapses to one backslash and \" to one quote, so the generated file receives the literal text \"\"\":

let manifest = \"\"\"

That is a stray backslash outside any string literal — a Swift syntax error. Every Swift plugin scaffolded by the CLI fails to build out of the box.

The fix drops one backslash per quote (\\"\\"\\" -> \"\"\") at both the opening and closing manifest delimiter, so the generated file gets a valid bare """. The Rust path is unaffected — it uses an r#"..."# raw string.

Changes

  • Bug fix
  • Tests

Test Plan

swift test in Packages/OsaurusCLI (89 tests green, +1 new) + swift-format lint --strict clean. The new test (testSwiftManifestUsesValidTripleQuoteDelimiter) reads the generated Plugin.swift and asserts it opens the manifest with a bare """ and not an escaped-quote triple; it fails on the pre-fix template and passes after. No MLX/GUI dependency.

`osaurus tools create <name>` (default language `swift`) emits a
`Sources/<module>/Plugin.swift` whose `get_manifest` body opens a multiline
string with `\"\"\"` instead of a bare `"""`.

The scaffold template (`pluginSwift`) is itself a Swift `"""..."""` literal.
The manifest delimiters were written as `\\"\\"\\"`; inside the outer literal
`\\` collapses to one backslash and `\"` to one quote, so the generated file
gets the literal text `\"\"\"` (`let manifest = \"\"\"`) — a stray backslash
outside any string literal, which is a Swift syntax error. The scaffolded
plugin does not compile out of the box.

Drop one backslash per quote (`\\"\\"\\"` -> `\"\"\"`) at both the opening
and closing manifest delimiter so the generated file gets a valid bare `"""`.
The Rust path is unaffected (it uses an `r#"..."#` raw string).

Adds a regression test asserting the generated Plugin.swift opens the manifest
with a bare triple-quote and not an escaped-quote triple.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant