[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6HQZ1HD4WQQ492Z1CQQKH48":3,"skill-same:01M6HQZ1HD4WQQ492Z1CQQKH48":50},{"skillNo":4,"name":5,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":23,"linkOnly":24,"markdownContent":25,"markdownBody":25,"frontMatter":26,"refName":27,"commitSha":28,"skillDirectory":29,"forksCount":30,"repositoryHtmlUrl":31,"repositoryHomepageUrl":6,"ownerHtmlUrl":32,"ownerBlogUrl":33,"ownerDescription":34,"updatedAt":35,"install":36,"resources":49},"01M6HQZ1HD4WQQ492Z1CQQKH48","clean-architecture-bridge",null,"jmservera\u002Fsquad-speckit-bridge","jmservera","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F8036360?v=4","01M6HQYYYZGAS22X1CRV8WKCYR","Juan Manuel Servera","01M6HQYZ3QS3VBBK59H86DESZE",1,"MIT","https:\u002F\u002Fgithub.com\u002Fjmservera\u002Fsquad-speckit-bridge\u002Fblob\u002Fmain\u002F.squad\u002Fskills\u002Fclean-architecture-bridge\u002FSKILL.md",[],[18,19,20,21,22],"architecture","bridge","clean","clean architecture","clean architecture bridge","2026-11-10 10:12:30",false,"# Skill: Clean Architecture for the Squad-SpecKit Bridge\n\n**Applies to**: All implementation tasks on `001-squad-speckit-bridge`\n**Source**: Uncle Bob's Clean Architecture (2012), mapped to this project\n\n## The Dependency Rule\n\nSource code dependencies point **inward only**. There are four layers:\n\n```\nOutermost → Innermost:\n  Frameworks & Drivers → Interface Adapters → Use Cases → Entities\n```\n\nAn inner layer **never** imports from an outer layer. An adapter can import an entity. An entity cannot import an adapter. A use case can import an entity. A use case cannot import `fs`, `commander`, or `@octokit`.\n\n## Our Layers — Concrete Mapping\n\n### Entities (innermost) — `src\u002Ftypes.ts`\n\nPure TypeScript types and interfaces. Business objects with no behavior beyond validation and computed properties.\n\n**Belongs here:**\n- `ContextSummary`, `SkillEntry`, `DecisionEntry`, `LearningEntry`\n- `BridgeConfig`, `DesignReviewRecord`, `ReviewFinding`, `InstallManifest`\n- Validation functions (e.g., `isValidConfig(c: BridgeConfig): boolean`)\n- Pure computations (e.g., `computeRelevanceScore(decision, now)`)\n\n**Does NOT belong here:**\n- `import fs from 'fs'` — ❌ entities don't touch the file system\n- `import matter from 'gray-matter'` — ❌ entities don't know about markdown\n- Any function that reads from disk, calls an API, or produces side effects\n\n### Use Cases — `src\u002Fbridge\u002Fcontext.ts`, `src\u002Fbridge\u002Fsummarizer.ts`, `src\u002Fbridge\u002Fports.ts`, `src\u002Freview\u002Fceremony.ts`, `src\u002Finstall\u002Finstaller.ts` (logic portion)\n\nApplication-specific orchestration. Use cases call **port interfaces** — they never call framework code directly.\n\n**Belongs here:**\n- `BuildSquadContext(reader: SquadStateReader, writer: ContextWriter, config: BridgeConfig)`\n- `SummarizeContent(entries: SkillEntry[], budget: number): SkillEntry[]`\n- Port interfaces: `SquadStateReader`, `ContextWriter`, `IssueCreator`, `FileDeployer`\n- Priority ordering, budget allocation, recency bias computation\n\n**Does NOT belong here:**\n- `import fs from 'fs'` — ❌ use cases don't touch the file system\n- `import { Octokit } from '@octokit\u002Frest'` — ❌ use cases don't know about GitHub\n- `glob('**\u002F*.md')` — ❌ use cases don't discover files\n- Direct construction of markdown strings for output — ❌ that's an adapter concern\n\n### Interface Adapters — `src\u002Fbridge\u002Fparser.ts`, `src\u002Fbridge\u002Fadapters\u002F`, `src\u002Fcli\u002Findex.ts` (handler portion)\n\nConvert between entity format and external format. Implement port interfaces.\n\n**Belongs here:**\n- `SquadFileSystemReader implements SquadStateReader` — reads `.squad\u002F` files, returns entity objects\n- `SpecKitContextWriter implements ContextWriter` — converts `ContextSummary` to markdown file\n- `MarkdownFrontmatterParser` — uses `gray-matter` to parse markdown into structured data\n- `CLIAdapter` — translates `commander` args into use case invocations\n- `GitHubIssueAdapter implements IssueCreator` — converts task entities to Octokit API calls\n\n**Does NOT belong here:**\n- Business logic (scoring, prioritization, budget allocation) — ❌ that's a use case concern\n\n### Frameworks & Drivers (outermost) — external dependencies + `src\u002Fcli\u002Findex.ts` (bootstrap)\n\n| Dependency | What It Does | Wrapped By |\n|-----------|-------------|------------|\n| `fs\u002Fpromises` | File read\u002Fwrite | `SquadFileReader`, `SpecKitWriter`, `ConfigLoader` |\n| `gray-matter` | YAML frontmatter parsing | `MarkdownFrontmatterParser` |\n| `commander` | CLI argument parsing | `CLIAdapter` |\n| `glob` | File pattern matching | `SquadFileReader` |\n| `@octokit\u002Frest` | GitHub API | `GitHubIssueAdapter` |\n\n## What NOT to Do — Anti-Patterns\n\n### ❌ Don't import `fs` in entity or use case code\n\n```typescript\n\u002F\u002F BAD — use case directly reads files\nasync function buildContext(config: BridgeConfig): Promise\u003CContextSummary> {\n  const files = await glob('.squad\u002Fskills\u002F*\u002FSKILL.md'); \u002F\u002F ❌ framework in use case\n  const content = await fs.readFile(files[0], 'utf-8');  \u002F\u002F ❌ fs in use case\n  return { skills: parseSkills(content) };\n}\n\n\u002F\u002F GOOD — use case takes a port interface\nasync function buildContext(\n  reader: SquadStateReader,     \u002F\u002F port interface\n  writer: ContextWriter,        \u002F\u002F port interface\n  config: BridgeConfig           \u002F\u002F entity\n): Promise\u003Cvoid> {\n  const skills = await reader.readSkills();    \u002F\u002F adapter handles file I\u002FO\n  const summary = summarize(skills, config);   \u002F\u002F pure logic\n  await writer.write(summary);                 \u002F\u002F adapter handles file output\n}\n```\n\n### ❌ Don't reference GitHub in use cases\n\n```typescript\n\u002F\u002F BAD — use case knows about GitHub\nimport { Octokit } from '@octokit\u002Frest';\nasync function createIssues(tasks: Task[], token: string) {\n  const octokit = new Octokit({ auth: token }); \u002F\u002F ❌\n}\n\n\u002F\u002F GOOD — use case calls an output port\nasync function createIssues(tasks: Task[], issueCreator: IssueCreator) {\n  for (const task of tasks) {\n    await issueCreator.create(task);  \u002F\u002F adapter handles GitHub details\n  }\n}\n```\n\n### ❌ Don't pass framework types across boundaries\n\n```typescript\n\u002F\u002F BAD — gray-matter output leaks into use case\nfunction processSkill(grayMatterResult: GrayMatterFile): SkillEntry { ... }\n\n\u002F\u002F GOOD — adapter converts to entity at the boundary\nfunction processSkill(entry: SkillEntry): void { ... }\n\u002F\u002F The adapter does: const entity = toSkillEntry(matter(rawMarkdown));\n```\n\n### ❌ Don't put business logic in adapters\n\n```typescript\n\u002F\u002F BAD — scoring logic in the file reader adapter\nclass SquadFileReader implements SquadStateReader {\n  async readDecisions(): Promise\u003CDecisionEntry[]> {\n    \u002F\u002F ... reads files ...\n    return decisions.sort((a, b) => b.relevanceScore - a.relevanceScore); \u002F\u002F ❌ business logic\n  }\n}\n\n\u002F\u002F GOOD — adapter returns raw entities, use case scores and sorts\nclass SquadFileReader implements SquadStateReader {\n  async readDecisions(): Promise\u003CDecisionEntry[]> {\n    \u002F\u002F ... reads files, converts to entities, returns unsorted\n  }\n}\n```\n\n## How to Test Each Layer\n\n### Entities — Pure unit tests, zero setup\n\n```typescript\ndescribe('BridgeConfig validation', () => {\n  it('rejects contextMaxBytes over 32KB', () => {\n    const config = { contextMaxBytes: 50000 };\n    expect(isValidConfig(config)).toBe(false);\n  });\n\n  it('computes relevance score from recency', () => {\n    const decision = { date: '2025-07-01', title: 'Test' };\n    const score = computeRelevanceScore(decision, new Date('2025-07-24'));\n    expect(score).toBeGreaterThan(0.5);\n  });\n});\n```\n\n### Use Cases — In-memory fakes, no file system\n\n```typescript\ndescribe('BuildSquadContext', () => {\n  it('produces summary within budget', async () => {\n    const fakeReader: SquadStateReader = {\n      readSkills: async () => [{ name: 'test', context: 'x'.repeat(1000) }],\n      readDecisions: async () => [],\n      readLearnings: async () => [],\n    };\n    let captured: ContextSummary | null = null;\n    const fakeWriter: ContextWriter = {\n      write: async (s) => { captured = s; },\n    };\n    const config = { contextMaxBytes: 8192 } as BridgeConfig;\n\n    await buildSquadContext(fakeReader, fakeWriter, config);\n\n    expect(captured).not.toBeNull();\n    expect(captured!.metadata.sizeBytes).toBeLessThanOrEqual(8192);\n  });\n});\n```\n\n### Adapters — Integration tests with fixture files\n\n```typescript\ndescribe('SquadFileReader', () => {\n  it('reads skill files from fixture directory', async () => {\n    const reader = new SquadFileSystemReader('tests\u002Ffixtures\u002Fsquad');\n    const skills = await reader.readSkills();\n    expect(skills).toHaveLength(2);\n    expect(skills[0].name).toBe('project-conventions');\n  });\n});\n```\n\n### End-to-End — Full pipeline with real files\n\n```typescript\ndescribe('bridge context command', () => {\n  it('produces squad-context.md from fixture squad dir', async () => {\n    \u002F\u002F Uses real files in tests\u002Ffixtures\u002F, real adapters, real use cases\n    execSync('node dist\u002Fcli\u002Findex.js context --squad-dir tests\u002Ffixtures\u002Fsquad');\n    const output = fs.readFileSync('tests\u002Ffixtures\u002Fspecify\u002Fsquad-context.md', 'utf-8');\n    expect(output).toContain('project-conventions');\n  });\n});\n```\n\n## Quick Reference — \"Which layer?\" Decision Tree\n\n```\nIs it a pure data type or validation rule?\n  → ENTITY (src\u002Ftypes.ts)\n\nDoes it orchestrate business logic without touching I\u002FO?\n  → USE CASE (src\u002Fbridge\u002Fcontext.ts, summarizer.ts, etc.)\n\nDoes it convert between external formats and entities?\n  → ADAPTER (src\u002Fbridge\u002Fparser.ts, adapters\u002F, cli\u002F)\n\nIs it a third-party library or Node.js built-in?\n  → FRAMEWORK\u002FDRIVER (imported only by adapters)\n```\n\n## Port Interfaces — The Contracts\n\nThese interfaces live in the use case layer and are implemented by adapters:\n\n| Port | Direction | Purpose |\n|------|-----------|---------|\n| `SquadStateReader` | Input | Read Squad memory artifacts as entities |\n| `ContextWriter` | Output | Write generated context summary |\n| `TasksReader` | Input | Read Spec Kit tasks for review |\n| `IssueCreator` | Output | Create issues from approved tasks |\n| `FrameworkDetector` | Input | Detect which frameworks are installed |\n| `FileDeployer` | Output | Deploy bridge components to file system |\n| `AgentHistoryReader` | Input | Read post-execution learnings from agent history files |\n| `ConstitutionWriter` | Output | Append learnings to Spec Kit constitution |\n| `SyncStateReader` | Input | Read sync state for idempotent operations |\n\n## Port Definition Pattern — v0.3.0 Sync Wiring\n\nThe sync feature (T001-T008, commits 4693a86, 3aedeb7, 1fedca5) demonstrates the full port\u002Fadapter cycle:\n\n### Step 1: Define ports in use case layer\n\n```typescript\n\u002F\u002F src\u002Fsync\u002Fsync-learnings.ts — use case layer\n\u002F\u002F ONLY imports from ..\u002Ftypes.ts, no framework dependencies\n\nexport interface AgentHistoryReader {\n  extractLearnings(agentDir: string, since?: Date): Promise\u003CExtractedLearning[]>;\n}\n\nexport interface ConstitutionWriter {\n  readConstitution(constitutionPath: string): Promise\u003Cstring | null>;\n  appendLearnings(constitutionPath: string, specId: string, learnings: { title: string; content: string }[]): Promise\u003Cstring>;\n}\n\nexport async function syncLearnings(\n  stateReader: SyncStateReader,           \u002F\u002F port interface\n  memoryWriter: SquadMemoryWriter,        \u002F\u002F port interface\n  options: SyncOptions,\n  historyReader?: AgentHistoryReader,     \u002F\u002F optional port\n  constitutionWriter?: ConstitutionWriter \u002F\u002F optional port\n): Promise\u003CSyncResult> {\n  \u002F\u002F Pure orchestration logic — no fs, no glob, no framework code\n}\n```\n\n### Step 2: Implement adapters\n\n```typescript\n\u002F\u002F src\u002Fsync\u002Fadapters\u002Fagent-history-reader.ts — adapter layer\n\u002F\u002F Imports fs\u002Fpromises, glob (framework dependencies)\n\nimport { readFile } from 'node:fs\u002Fpromises';\nimport { glob } from 'glob';\nimport type { AgentHistoryReader, ExtractedLearning } from '..\u002Fsync-learnings.js';\n\nexport class AgentHistoryReaderAdapter implements AgentHistoryReader {\n  async extractLearnings(agentDir: string, since?: Date): Promise\u003CExtractedLearning[]> {\n    \u002F\u002F Framework calls: glob, readFile\n    const pattern = join(agentDir, '**', 'history.md');\n    const files = await glob(pattern);\n    \u002F\u002F ... parse markdown, extract H3 headings with dates ...\n  }\n}\n```\n\n```typescript\n\u002F\u002F src\u002Fsync\u002Fadapters\u002Fconstitution-adapter.ts — adapter layer\n\u002F\u002F Implements ConstitutionWriter port\n\nimport { readFile, writeFile, mkdir } from 'node:fs\u002Fpromises';\nimport type { ConstitutionWriter } from '..\u002Fsync-learnings.js';\n\nexport class ConstitutionAdapter implements ConstitutionWriter {\n  async appendLearnings(constitutionPath: string, specId: string, learnings: { title: string; content: string }[]): Promise\u003Cstring> {\n    let existing = await readFile(constitutionPath, 'utf-8');\n    \n    \u002F\u002F Constitution amendment protocol (v0.3.0):\n    \u002F\u002F 1. Bump minor version: 1.0.0 → 1.1.0\n    existing = existing.replace(\n      \u002F\\*\\*Version\\*\\*:\\s*(\\d+)\\.(\\d+)\\.(\\d+)\u002F,\n      (_match, major, minor) => `**Version**: ${major}.${parseInt(minor, 10) + 1}.0`\n    );\n    \n    \u002F\u002F 2. Update Last Amended date\n    const today = new Date().toISOString().split('T')[0];\n    existing = existing.replace(\u002F\\*\\*Last Amended\\*\\*:\\s*\\S+\u002F, `**Last Amended**: ${today}`);\n    \n    \u002F\u002F 3. Append learnings section\n    await writeFile(constitutionPath, updated, 'utf-8');\n  }\n}\n```\n\n### Step 3: Wire adapters in composition root\n\n```typescript\n\u002F\u002F src\u002Fmain.ts — composition root (outermost layer)\n\u002F\u002F The ONLY file that knows about all layers\n\nimport { syncLearnings } from '.\u002Fsync\u002Fsync-learnings.js';\nimport { AgentHistoryReaderAdapter } from '.\u002Fsync\u002Fadapters\u002Fagent-history-reader.js';\nimport { ConstitutionAdapter } from '.\u002Fsync\u002Fadapters\u002Fconstitution-adapter.js';\n\nexport function createSyncOrchestrator(options: SyncOptions = {}) {\n  return {\n    async sync(specDir: string, opts: { dryRun?: boolean; noConstitution?: boolean } = {}): Promise\u003CSyncOutput> {\n      const stateReader = new SyncStateAdapter();\n      const memoryWriter = new SquadFileWriter();\n      \n      \u002F\u002F Optional ports — conditional wiring based on CLI flags\n      const historyReader = new AgentHistoryReaderAdapter();\n      const constitutionWriter = opts.noConstitution ? undefined : new ConstitutionAdapter();\n      \n      \u002F\u002F Constructor injection — all dependencies injected, no \"new\" in use case\n      const result = await syncLearnings(\n        stateReader,\n        memoryWriter,\n        { specDir, squadDir, dryRun: opts.dryRun ?? false },\n        historyReader,      \u002F\u002F optional\n        constitutionWriter  \u002F\u002F optional\n      );\n      \n      return formatOutput(result);\n    }\n  };\n}\n```\n\n### Key Patterns from Sync Implementation\n\n1. **Optional ports via undefined** — `historyReader?: AgentHistoryReader` allows graceful degradation when feature is disabled\n2. **Conditional adapter wiring** — `opts.noConstitution ? undefined : new ConstitutionAdapter()` — composition root controls feature flags\n3. **Port interfaces define the contract** — use case doesn't know about `glob` or `readFile`; adapter does\n4. **No \"new\" in use cases** — all dependencies injected via constructor or function parameters\n5. **Composition root is the wiring diagram** — main.ts shows the full dependency graph at a glance\n",{},"main","ece8f94b87fc2ae9752b7e78eda5218f11ea0186",".squad\u002Fskills\u002Fclean-architecture-bridge",0,"https:\u002F\u002Fgithub.com\u002Fjmservera\u002Fsquad-speckit-bridge","https:\u002F\u002Fgithub.com\u002Fjmservera","http:\u002F\u002Fjmblog.servezas.org","Cloud Solution Architect @microsoft","2026-06-13 06:38:33",{"source":7,"skillName":5,"commands":37,"prompt":47,"zipAvailable":48},[38,41,44],{"tool":39,"command":40},"npx","npx skills add jmservera\u002Fsquad-speckit-bridge --skill clean-architecture-bridge",{"tool":42,"command":43},"bunx","bunx skills add jmservera\u002Fsquad-speckit-bridge --skill clean-architecture-bridge",{"tool":45,"command":46},"pnpm","pnpm dlx skills add jmservera\u002Fsquad-speckit-bridge --skill clean-architecture-bridge","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fjmservera\u002Fsquad-speckit-bridge\u002Fblob\u002Fmain\u002F.squad\u002Fskills\u002Fclean-architecture-bridge\u002FSKILL.md",true,[],[51,60,69,77,85,94],{"skillNo":52,"name":53,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":54,"categories":55,"keywords":56,"publishedAt":23},"01M6HR0K6XQ7PYACETCC2P3ENT","testing-patterns","https:\u002F\u002Fgithub.com\u002Fjmservera\u002Fsquad-speckit-bridge\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Fsquad\u002Fskills\u002Ftesting-patterns\u002FSKILL.md",[],[57,58,59],"patterns","testing patterns","testing",{"skillNo":61,"name":62,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":63,"categories":64,"keywords":65,"publishedAt":23},"01M6HR0HKGWJPNV421ZA9GNNJN","project-conventions","https:\u002F\u002Fgithub.com\u002Fjmservera\u002Fsquad-speckit-bridge\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Fsquad\u002Fskills\u002Fproject-conventions\u002FSKILL.md",[],[66,67,68],"project","conventions","project conventions",{"skillNo":70,"name":71,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":72,"categories":73,"keywords":74,"publishedAt":23},"01M6HR0ERZB2NK3MFBWR0YYMBM","malformed-skill","https:\u002F\u002Fgithub.com\u002Fjmservera\u002Fsquad-speckit-bridge\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Fsquad\u002Fskills\u002Fmalformed-skill\u002FSKILL.md",[],[75,76],"malformed skill","malformed",{"skillNo":78,"name":79,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":80,"categories":81,"keywords":82,"publishedAt":23},"01M6HR0CSMQT5N1WNFT4WQCK5E","empty-skill","https:\u002F\u002Fgithub.com\u002Fjmservera\u002Fsquad-speckit-bridge\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Fsquad\u002Fskills\u002Fempty-skill\u002FSKILL.md",[],[83,84],"empty skill","empty",{"skillNo":86,"name":87,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":88,"categories":89,"keywords":90,"publishedAt":23},"01M6HR0AVMK7QG3PM9TKTHXD5X","api-design","https:\u002F\u002Fgithub.com\u002Fjmservera\u002Fsquad-speckit-bridge\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Fsquad\u002Fskills\u002Fapi-design\u002FSKILL.md",[],[91,92,93],"api","api design","design",{"skillNo":95,"name":5,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":96,"categories":97,"keywords":98,"publishedAt":23},"01M6HR07QKF3WD1F3ADNJWP6R0","https:\u002F\u002Fgithub.com\u002Fjmservera\u002Fsquad-speckit-bridge\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Freverse-sync\u002Fsquad\u002Fskills\u002Fclean-architecture-bridge\u002FSKILL.md",[],[18,22,21,20,19]]