بنقرة واحدة
translate-examples-to-swift
Translates inline JavaScript example code to Swift
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Translates inline JavaScript example code to Swift
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
| name | translate-examples-to-swift |
| description | Translates inline JavaScript example code to Swift |
Invoke this skill with /translate-examples-to-swift followed by a description of what to translate.
/translate-examples-to-swift translate the JavaScript examples in src/pages/docs/ai-transport/streaming.mdx
/translate-examples-to-swift translate all JavaScript code blocks in the src/pages/docs/messages/ directory
/translate-examples-to-swift translate the code block at line 45 of src/pages/docs/channels/index.mdx
This skill uses a three-phase architecture with independent translation, verification, and assembly:
Translation phase: Spawn one sub-agent per MDX file. Each translates examples, self-checks compilation (for iteration), inserts into MDX, and writes translation metadata JSON.
Verification phase: Spawn one sub-agent per MDX file. Each reads Swift code from the MDX (source of truth), compiles in a fresh harness, assesses faithfulness, and writes verification results JSON.
Assembly phase: Run consolidate.sh to merge JSONs and generate review HTML.
Key principle: Verification reads from MDX, not from translation output. This ensures verification tests what actually ships.
Verify-only mode: When translations already exist in MDX but no translation JSONs are available, you can skip the translation phase and run only verification + assembly. See the "Verify-only workflow" section below.
Always delegate: Spawn a sub-agent for each file, even for single-file tasks. This keeps behavior consistent and context isolated.
The orchestrator (you, when running this skill) coordinates subagents but does NOT directly modify:
swift-translations/translations/*.json)swift-translations/verifications/*.json)All modifications to these files must go through the appropriate subagent. The orchestrator may:
This separation ensures that all code changes are tested before being written, and all verification results reflect actual verification.
All intermediate files go in swift-translations/ at the repo root:
swift-translations/
harness-{filename}/ # Test harness per translation subagent
verify-{filename}/ # Test harness per verification subagent
translations/
{filename}.json # One per MDX file
verifications/
{filename}.json # One per MDX file
consolidated.json # Merged data for review app (generated by script)
review.html # Human review interface (generated by script)
The {filename} is derived from the MDX filename without path or extension:
src/pages/docs/ai-transport/messaging/citations.mdx → citationssrc/pages/docs/ai-transport/token-streaming/message-per-token.mdx → message-per-tokenFor each MDX file to translate, spawn a translation subagent.
Get the prompt from the file .claude/skills/translate-examples-to-swift/prompts/translation-subagent.md:
{FILEPATH} with the full path to the MDX file being translated{FILENAME} with the MDX filename without path or extensionDo not paraphrase or rewrite the prompt. Use the file contents with only the placeholders replaced. Launch a general-purpose subagent with the resulting prompt.
After each translation subagent completes, validate its JSON output:
npx ajv-cli validate \
-s .claude/skills/translate-examples-to-swift/schemas/translation.schema.json \
-d swift-translations/translations/{filename}.json
If validation fails, report the error.
After translation subagents complete, spawn verification subagents for each file that was translated.
Important: Spawn a verification subagent for EVERY file that had a translation subagent, even if that file had no examples. This ensures 1:1 matching between translation and verification outputs, avoiding special-case handling in the consolidation phase.
Get the prompt from the file .claude/skills/translate-examples-to-swift/prompts/verification-subagent.md:
{FILEPATH} with the full path to the MDX file being verified{FILENAME} with the MDX filename without path or extensionDo not paraphrase or rewrite the prompt. Use the file contents with only the placeholders replaced. Launch a general-purpose subagent with the resulting prompt.
After the verification subagent completes, validate its JSON output:
npx ajv-cli validate \
-s .claude/skills/translate-examples-to-swift/schemas/verification.schema.json \
-d swift-translations/verifications/{filename}.json
If validation fails, report the error.
When the verification subagent returns:
Important: The orchestrator must NEVER directly edit MDX files or verification JSON files. All changes to translations must go through a translation subagent. All verification results must come from a verification subagent.
Run the consolidation script to merge JSONs and generate the review HTML:
.claude/skills/translate-examples-to-swift/scripts/consolidate.sh
This reads from swift-translations/translations/ and swift-translations/verifications/, then produces:
swift-translations/consolidated.json - merged dataswift-translations/review.html - human review interfaceThe review HTML provides:
Report back to the user, explaining:
Example:
Translation complete.
## Summary
- Files processed: 2
- Examples translated: 5
- Compilation: 4 passed, 1 failed
## Review file
Open the review file to examine translations:
swift-translations/review.html
## Issues requiring attention
- src/pages/docs/messages/updates-deletes.mdx:78 - Compilation failed: `updateSerial` property not found
When the user reviews the generated review file and provides feedback:
Important: The orchestrator must NEVER directly edit MDX files, translation JSON, or verification JSON. All file modifications must go through the appropriate subagent. This ensures:
This is not optional. Any change to a translation—whether from user feedback, verification comments, or your own corrections—must go through the full verify-and-review cycle before being considered complete.
Use this workflow when Swift translations already exist in the MDX files but no translation JSON files are available. This happens when:
Same as the normal workflow Step 2 — spawn a verification subagent for each MDX file. Use the prompt from .claude/skills/translate-examples-to-swift/prompts/verification-subagent.md with placeholders replaced.
After verification subagents complete, generate stub translation JSONs from the verification data:
.claude/skills/translate-examples-to-swift/scripts/generate-translation-stubs.sh
This reads each verification JSON and creates a matching translation JSON with a "verify-only" info note. It skips files that already have a translation JSON, so it's safe to run even if some real translations exist.
Run consolidate.sh as normal:
.claude/skills/translate-examples-to-swift/scripts/consolidate.sh
Report as normal, but note that translation notes are unavailable since the translation phase was skipped. The review HTML will show a "verify-only" info note in place of translation decision notes.
Never output code that hasn't been verified. This is the core principle of the skill:
swift build in a test harnessIf you find yourself about to report completion without having verified recent changes, stop and run verification first.
Scripts are in .claude/skills/translate-examples-to-swift/scripts/:
consolidate.sh - Merges translation and verification JSONs, validates, generates review HTMLgenerate-translation-stubs.sh - Generates stub translation JSONs from verification data (for verify-only mode)Review app scripts are in .claude/skills/translate-examples-to-swift/review-app/:
generate-review.sh - Generates review HTML from consolidated JSON (called by consolidate.sh)Schemas are in .claude/skills/translate-examples-to-swift/schemas/:
translation.schema.json - Translation sub-agent output (notes and metadata)verification.schema.json - Verification sub-agent output (code, harness, results)consolidated.schema.json - Final merged data for review appValidate with:
npx ajv-cli validate -s {schema} -d {data}