[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7ECD9BWDJN2Y1ZYYGPCXCKW":3,"skill-same:01M7ECD9BWDJN2Y1ZYYGPCXCKW":46},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":27,"repositoryHtmlUrl":28,"repositoryHomepageUrl":6,"ownerHtmlUrl":29,"ownerBlogUrl":6,"ownerDescription":30,"updatedAt":31,"install":32,"resources":45},"01M7ECD9BWDJN2Y1ZYYGPCXCKW","foundation-models-on-device",null,"Apple FoundationModels framework for on-device LLM — text generation, guided generation with @Generable, tool calling, and snapshot streaming in iOS 26+.","lza6\u002FArmor-piercing-system-prompts","lza6","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F128880206?v=4","01M7EB3K7WPX5T28EJ2NVHE6EG","Chinese-tingfeng","01M7EB3K97E1KQ16QWKJMFNGX8",11,"MIT","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F03-逆向工程\u002Ffoundation-models-on-device-everything-claude-code-main\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: foundation-models-on-device\ndescription: Apple FoundationModels framework for on-device LLM — text generation, guided generation with @Generable, tool calling, and snapshot streaming in iOS 26+.\n---\n\n# FoundationModels: On-Device LLM (iOS 26)\n\nPatterns for integrating Apple's on-device language model into apps using the FoundationModels framework. Covers text generation, structured output with `@Generable`, custom tool calling, and snapshot streaming — all running on-device for privacy and offline support.\n\n## When to Activate\n\n- Building AI-powered features using Apple Intelligence on-device\n- Generating or summarizing text without cloud dependency\n- Extracting structured data from natural language input\n- Implementing custom tool calling for domain-specific AI actions\n- Streaming structured responses for real-time UI updates\n- Need privacy-preserving AI (no data leaves the device)\n\n## Core Pattern — Availability Check\n\nAlways check model availability before creating a session:\n\n```swift\nstruct GenerativeView: View {\n    private var model = SystemLanguageModel.default\n\n    var body: some View {\n        switch model.availability {\n        case .available:\n            ContentView()\n        case .unavailable(.deviceNotEligible):\n            Text(\"Device not eligible for Apple Intelligence\")\n        case .unavailable(.appleIntelligenceNotEnabled):\n            Text(\"Please enable Apple Intelligence in Settings\")\n        case .unavailable(.modelNotReady):\n            Text(\"Model is downloading or not ready\")\n        case .unavailable(let other):\n            Text(\"Model unavailable: \\(other)\")\n        }\n    }\n}\n```\n\n## Core Pattern — Basic Session\n\n```swift\n\u002F\u002F Single-turn: create a new session each time\nlet session = LanguageModelSession()\nlet response = try await session.respond(to: \"What's a good month to visit Paris?\")\nprint(response.content)\n\n\u002F\u002F Multi-turn: reuse session for conversation context\nlet session = LanguageModelSession(instructions: \"\"\"\n    You are a cooking assistant.\n    Provide recipe suggestions based on ingredients.\n    Keep suggestions brief and practical.\n    \"\"\")\n\nlet first = try await session.respond(to: \"I have chicken and rice\")\nlet followUp = try await session.respond(to: \"What about a vegetarian option?\")\n```\n\nKey points for instructions:\n- Define the model's role (\"You are a mentor\")\n- Specify what to do (\"Help extract calendar events\")\n- Set style preferences (\"Respond as briefly as possible\")\n- Add safety measures (\"Respond with 'I can't help with that' for dangerous requests\")\n\n## Core Pattern — Guided Generation with @Generable\n\nGenerate structured Swift types instead of raw strings:\n\n### 1. Define a Generable Type\n\n```swift\n@Generable(description: \"Basic profile information about a cat\")\nstruct CatProfile {\n    var name: String\n\n    @Guide(description: \"The age of the cat\", .range(0...20))\n    var age: Int\n\n    @Guide(description: \"A one sentence profile about the cat's personality\")\n    var profile: String\n}\n```\n\n### 2. Request Structured Output\n\n```swift\nlet response = try await session.respond(\n    to: \"Generate a cute rescue cat\",\n    generating: CatProfile.self\n)\n\n\u002F\u002F Access structured fields directly\nprint(\"Name: \\(response.content.name)\")\nprint(\"Age: \\(response.content.age)\")\nprint(\"Profile: \\(response.content.profile)\")\n```\n\n### Supported @Guide Constraints\n\n- `.range(0...20)` — numeric range\n- `.count(3)` — array element count\n- `description:` — semantic guidance for generation\n\n## Core Pattern — Tool Calling\n\nLet the model invoke custom code for domain-specific tasks:\n\n### 1. Define a Tool\n\n```swift\nstruct RecipeSearchTool: Tool {\n    let name = \"recipe_search\"\n    let description = \"Search for recipes matching a given term and return a list of results.\"\n\n    @Generable\n    struct Arguments {\n        var searchTerm: String\n        var numberOfResults: Int\n    }\n\n    func call(arguments: Arguments) async throws -> ToolOutput {\n        let recipes = await searchRecipes(\n            term: arguments.searchTerm,\n            limit: arguments.numberOfResults\n        )\n        return .string(recipes.map { \"- \\($0.name): \\($0.description)\" }.joined(separator: \"\\n\"))\n    }\n}\n```\n\n### 2. Create Session with Tools\n\n```swift\nlet session = LanguageModelSession(tools: [RecipeSearchTool()])\nlet response = try await session.respond(to: \"Find me some pasta recipes\")\n```\n\n### 3. Handle Tool Errors\n\n```swift\ndo {\n    let answer = try await session.respond(to: \"Find a recipe for tomato soup.\")\n} catch let error as LanguageModelSession.ToolCallError {\n    print(error.tool.name)\n    if case .databaseIsEmpty = error.underlyingError as? RecipeSearchToolError {\n        \u002F\u002F Handle specific tool error\n    }\n}\n```\n\n## Core Pattern — Snapshot Streaming\n\nStream structured responses for real-time UI with `PartiallyGenerated` types:\n\n```swift\n@Generable\nstruct TripIdeas {\n    @Guide(description: \"Ideas for upcoming trips\")\n    var ideas: [String]\n}\n\nlet stream = session.streamResponse(\n    to: \"What are some exciting trip ideas?\",\n    generating: TripIdeas.self\n)\n\nfor try await partial in stream {\n    \u002F\u002F partial: TripIdeas.PartiallyGenerated (all properties Optional)\n    print(partial)\n}\n```\n\n### SwiftUI Integration\n\n```swift\n@State private var partialResult: TripIdeas.PartiallyGenerated?\n@State private var errorMessage: String?\n\nvar body: some View {\n    List {\n        ForEach(partialResult?.ideas ?? [], id: \\.self) { idea in\n            Text(idea)\n        }\n    }\n    .overlay {\n        if let errorMessage { Text(errorMessage).foregroundStyle(.red) }\n    }\n    .task {\n        do {\n            let stream = session.streamResponse(to: prompt, generating: TripIdeas.self)\n            for try await partial in stream {\n                partialResult = partial\n            }\n        } catch {\n            errorMessage = error.localizedDescription\n        }\n    }\n}\n```\n\n## Key Design Decisions\n\n| Decision | Rationale |\n|----------|-----------|\n| On-device execution | Privacy — no data leaves the device; works offline |\n| 4,096 token limit | On-device model constraint; chunk large data across sessions |\n| Snapshot streaming (not deltas) | Structured output friendly; each snapshot is a complete partial state |\n| `@Generable` macro | Compile-time safety for structured generation; auto-generates `PartiallyGenerated` type |\n| Single request per session | `isResponding` prevents concurrent requests; create multiple sessions if needed |\n| `response.content` (not `.output`) | Correct API — always access results via `.content` property |\n\n## Best Practices\n\n- **Always check `model.availability`** before creating a session — handle all unavailability cases\n- **Use `instructions`** to guide model behavior — they take priority over prompts\n- **Check `isResponding`** before sending a new request — sessions handle one request at a time\n- **Access `response.content`** for results — not `.output`\n- **Break large inputs into chunks** — 4,096 token limit applies to instructions + prompt + output combined\n- **Use `@Generable`** for structured output — stronger guarantees than parsing raw strings\n- **Use `GenerationOptions(temperature:)`** to tune creativity (higher = more creative)\n- **Monitor with Instruments** — use Xcode Instruments to profile request performance\n\n## Anti-Patterns to Avoid\n\n- Creating sessions without checking `model.availability` first\n- Sending inputs exceeding the 4,096 token context window\n- Attempting concurrent requests on a single session\n- Using `.output` instead of `.content` to access response data\n- Parsing raw string responses when `@Generable` structured output would work\n- Building complex multi-step logic in a single prompt — break into multiple focused prompts\n- Assuming the model is always available — device eligibility and settings vary\n\n## When to Use\n\n- On-device text generation for privacy-sensitive apps\n- Structured data extraction from user input (forms, natural language commands)\n- AI-assisted features that must work offline\n- Streaming UI that progressively shows generated content\n- Domain-specific AI actions via tool calling (search, compute, lookup)\n","# FoundationModels: On-Device LLM (iOS 26)\n\nPatterns for integrating Apple's on-device language model into apps using the FoundationModels framework. Covers text generation, structured output with `@Generable`, custom tool calling, and snapshot streaming — all running on-device for privacy and offline support.\n\n## When to Activate\n\n- Building AI-powered features using Apple Intelligence on-device\n- Generating or summarizing text without cloud dependency\n- Extracting structured data from natural language input\n- Implementing custom tool calling for domain-specific AI actions\n- Streaming structured responses for real-time UI updates\n- Need privacy-preserving AI (no data leaves the device)\n\n## Core Pattern — Availability Check\n\nAlways check model availability before creating a session:\n\n```swift\nstruct GenerativeView: View {\n    private var model = SystemLanguageModel.default\n\n    var body: some View {\n        switch model.availability {\n        case .available:\n            ContentView()\n        case .unavailable(.deviceNotEligible):\n            Text(\"Device not eligible for Apple Intelligence\")\n        case .unavailable(.appleIntelligenceNotEnabled):\n            Text(\"Please enable Apple Intelligence in Settings\")\n        case .unavailable(.modelNotReady):\n            Text(\"Model is downloading or not ready\")\n        case .unavailable(let other):\n            Text(\"Model unavailable: \\(other)\")\n        }\n    }\n}\n```\n\n## Core Pattern — Basic Session\n\n```swift\n\u002F\u002F Single-turn: create a new session each time\nlet session = LanguageModelSession()\nlet response = try await session.respond(to: \"What's a good month to visit Paris?\")\nprint(response.content)\n\n\u002F\u002F Multi-turn: reuse session for conversation context\nlet session = LanguageModelSession(instructions: \"\"\"\n    You are a cooking assistant.\n    Provide recipe suggestions based on ingredients.\n    Keep suggestions brief and practical.\n    \"\"\")\n\nlet first = try await session.respond(to: \"I have chicken and rice\")\nlet followUp = try await session.respond(to: \"What about a vegetarian option?\")\n```\n\nKey points for instructions:\n- Define the model's role (\"You are a mentor\")\n- Specify what to do (\"Help extract calendar events\")\n- Set style preferences (\"Respond as briefly as possible\")\n- Add safety measures (\"Respond with 'I can't help with that' for dangerous requests\")\n\n## Core Pattern — Guided Generation with @Generable\n\nGenerate structured Swift types instead of raw strings:\n\n### 1. Define a Generable Type\n\n```swift\n@Generable(description: \"Basic profile information about a cat\")\nstruct CatProfile {\n    var name: String\n\n    @Guide(description: \"The age of the cat\", .range(0...20))\n    var age: Int\n\n    @Guide(description: \"A one sentence profile about the cat's personality\")\n    var profile: String\n}\n```\n\n### 2. Request Structured Output\n\n```swift\nlet response = try await session.respond(\n    to: \"Generate a cute rescue cat\",\n    generating: CatProfile.self\n)\n\n\u002F\u002F Access structured fields directly\nprint(\"Name: \\(response.content.name)\")\nprint(\"Age: \\(response.content.age)\")\nprint(\"Profile: \\(response.content.profile)\")\n```\n\n### Supported @Guide Constraints\n\n- `.range(0...20)` — numeric range\n- `.count(3)` — array element count\n- `description:` — semantic guidance for generation\n\n## Core Pattern — Tool Calling\n\nLet the model invoke custom code for domain-specific tasks:\n\n### 1. Define a Tool\n\n```swift\nstruct RecipeSearchTool: Tool {\n    let name = \"recipe_search\"\n    let description = \"Search for recipes matching a given term and return a list of results.\"\n\n    @Generable\n    struct Arguments {\n        var searchTerm: String\n        var numberOfResults: Int\n    }\n\n    func call(arguments: Arguments) async throws -> ToolOutput {\n        let recipes = await searchRecipes(\n            term: arguments.searchTerm,\n            limit: arguments.numberOfResults\n        )\n        return .string(recipes.map { \"- \\($0.name): \\($0.description)\" }.joined(separator: \"\\n\"))\n    }\n}\n```\n\n### 2. Create Session with Tools\n\n```swift\nlet session = LanguageModelSession(tools: [RecipeSearchTool()])\nlet response = try await session.respond(to: \"Find me some pasta recipes\")\n```\n\n### 3. Handle Tool Errors\n\n```swift\ndo {\n    let answer = try await session.respond(to: \"Find a recipe for tomato soup.\")\n} catch let error as LanguageModelSession.ToolCallError {\n    print(error.tool.name)\n    if case .databaseIsEmpty = error.underlyingError as? RecipeSearchToolError {\n        \u002F\u002F Handle specific tool error\n    }\n}\n```\n\n## Core Pattern — Snapshot Streaming\n\nStream structured responses for real-time UI with `PartiallyGenerated` types:\n\n```swift\n@Generable\nstruct TripIdeas {\n    @Guide(description: \"Ideas for upcoming trips\")\n    var ideas: [String]\n}\n\nlet stream = session.streamResponse(\n    to: \"What are some exciting trip ideas?\",\n    generating: TripIdeas.self\n)\n\nfor try await partial in stream {\n    \u002F\u002F partial: TripIdeas.PartiallyGenerated (all properties Optional)\n    print(partial)\n}\n```\n\n### SwiftUI Integration\n\n```swift\n@State private var partialResult: TripIdeas.PartiallyGenerated?\n@State private var errorMessage: String?\n\nvar body: some View {\n    List {\n        ForEach(partialResult?.ideas ?? [], id: \\.self) { idea in\n            Text(idea)\n        }\n    }\n    .overlay {\n        if let errorMessage { Text(errorMessage).foregroundStyle(.red) }\n    }\n    .task {\n        do {\n            let stream = session.streamResponse(to: prompt, generating: TripIdeas.self)\n            for try await partial in stream {\n                partialResult = partial\n            }\n        } catch {\n            errorMessage = error.localizedDescription\n        }\n    }\n}\n```\n\n## Key Design Decisions\n\n| Decision | Rationale |\n|----------|-----------|\n| On-device execution | Privacy — no data leaves the device; works offline |\n| 4,096 token limit | On-device model constraint; chunk large data across sessions |\n| Snapshot streaming (not deltas) | Structured output friendly; each snapshot is a complete partial state |\n| `@Generable` macro | Compile-time safety for structured generation; auto-generates `PartiallyGenerated` type |\n| Single request per session | `isResponding` prevents concurrent requests; create multiple sessions if needed |\n| `response.content` (not `.output`) | Correct API — always access results via `.content` property |\n\n## Best Practices\n\n- **Always check `model.availability`** before creating a session — handle all unavailability cases\n- **Use `instructions`** to guide model behavior — they take priority over prompts\n- **Check `isResponding`** before sending a new request — sessions handle one request at a time\n- **Access `response.content`** for results — not `.output`\n- **Break large inputs into chunks** — 4,096 token limit applies to instructions + prompt + output combined\n- **Use `@Generable`** for structured output — stronger guarantees than parsing raw strings\n- **Use `GenerationOptions(temperature:)`** to tune creativity (higher = more creative)\n- **Monitor with Instruments** — use Xcode Instruments to profile request performance\n\n## Anti-Patterns to Avoid\n\n- Creating sessions without checking `model.availability` first\n- Sending inputs exceeding the 4,096 token context window\n- Attempting concurrent requests on a single session\n- Using `.output` instead of `.content` to access response data\n- Parsing raw string responses when `@Generable` structured output would work\n- Building complex multi-step logic in a single prompt — break into multiple focused prompts\n- Assuming the model is always available — device eligibility and settings vary\n\n## When to Use\n\n- On-device text generation for privacy-sensitive apps\n- Structured data extraction from user input (forms, natural language commands)\n- AI-assisted features that must work offline\n- Streaming UI that progressively shows generated content\n- Domain-specific AI actions via tool calling (search, compute, lookup)\n",{"name":5,"description":7},"main","d69096e239f2a89aabc2cd078c47664a9d3b1e11","03-逆向工程\u002Ffoundation-models-on-device-everything-claude-code-main",3,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts","https:\u002F\u002Fgithub.com\u002Flza6","个人vx：Tf00798\r\n个人✈：@TFGY999","2026-10-08 14:29:22",{"source":8,"skillName":5,"commands":33,"prompt":43,"zipAvailable":44},[34,37,40],{"tool":35,"command":36},"npx","npx skills add lza6\u002FArmor-piercing-system-prompts --skill foundation-models-on-device",{"tool":38,"command":39},"bunx","bunx skills add lza6\u002FArmor-piercing-system-prompts --skill foundation-models-on-device",{"tool":41,"command":42},"pnpm","pnpm dlx skills add lza6\u002FArmor-piercing-system-prompts --skill foundation-models-on-device","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F03-逆向工程\u002Ffoundation-models-on-device-everything-claude-code-main\u002FSKILL.md",true,[],[47,55,60,67,74,81],{"skillNo":48,"name":49,"nameZh":6,"description":50,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":51,"categories":52,"keywords":53,"publishedAt":54},"01M7FFG485KY83TD6HSC4YPCMC","obsidian-clipper-template-creator","Guide for creating templates for the Obsidian Web Clipper. Use when you want to create a new clipping template, understand available variables, or format clipped content.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobsidian-clipper-template-creator\u002FSKILL.md",[],[],"2026-11-16 10:05:34",{"skillNo":56,"name":49,"nameZh":6,"description":50,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":57,"categories":58,"keywords":59,"publishedAt":54},"01M7FFG0T6AZ0STEJPSB3CX84K","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobsidian-clipper-template-creator-antigravity-awesome-skills-main\u002FSKILL.md",[],[],{"skillNo":61,"name":62,"nameZh":6,"description":63,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":64,"categories":65,"keywords":66,"publishedAt":54},"01M7FFFY0QEM14SKWPDYGMXM2P","python-api","Programmatic Object-Detection-Metrics API guidance for BoundingBox, BoundingBoxes, Evaluator, enums, coordinate conversion, AP\u002FmAP semantics, and source-style import diagnostics.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobject-detection-metrics\u002Fsub-skills\u002Fpython-api\u002FSKILL.md",[],[],{"skillNo":68,"name":69,"nameZh":6,"description":70,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":71,"categories":72,"keywords":73,"publishedAt":54},"01M7FFFVZQZ2GJ0C0TGP7JHD20","file-evaluation","Folder-based PASCAL VOC AP\u002FmAP evaluation from ground-truth and detection text files.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobject-detection-metrics\u002Fsub-skills\u002Ffile-evaluation\u002FSKILL.md",[],[],{"skillNo":75,"name":76,"nameZh":6,"description":77,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":78,"categories":79,"keywords":80,"publishedAt":54},"01M7FFFSFNYSE77SJ6PE1CK2DA","object-detection-metrics","Guides legacy Object-Detection-Metrics PASCAL VOC AP\u002FmAP evaluation from detection text folders and direct Python API classes.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobject-detection-metrics\u002FSKILL.md",[],[],{"skillNo":82,"name":83,"nameZh":6,"description":84,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":85,"categories":86,"keywords":87,"publishedAt":54},"01M7FFFP0GCK1RVXBCPQ8APBMT","nx-workspace-patterns","Configure and optimize Nx monorepo workspaces. Use when setting up Nx, configuring project boundaries, optimizing build caching, or implementing affected commands.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fnx-workspace-patterns\u002FSKILL.md",[],[]]