{
  "schema_version": 1,
  "diagram_type": "architecture",
  "meta": {
    "title": "Ailoha iOS current main：运行与所有权边界",
    "subtitle": "main@6922f359 · 代码事实，不代表 Release 或生产行为",
    "output": "current-main-architecture.html",
    "animation": "trace",
    "visual_preset": "editorial",
    "quality_profile": "showcase",
    "repository": {
      "url": "https://github.com/Ailoha-ai/ailoha-agent-iOS",
      "revision": "6922f359ad08da70242e4ec0c5c4a1486bc2908d"
    },
    "views": [
      {
        "id": "user-loop",
        "label": "用户主路径",
        "focus": ["user", "app-lifecycle", "root-shell", "onboarding-home", "task-chat", "relations", "app-owners", "transport", "backend"],
        "note": "从启动和交互一路追到页面投影、App owner 与服务端。"
      },
      {
        "id": "state-ownership",
        "label": "状态所有权",
        "focus": ["onboarding-home", "task-chat", "relations", "app-owners", "local-packages"],
        "note": "Package 已拥有部分策略、缓存和副作用；身份、canonical entity 与组合恢复仍在 App。"
      },
      {
        "id": "cross-process",
        "label": "跨进程恢复",
        "focus": ["ios-system", "shared-extensions", "app-lifecycle", "app-owners", "backend"],
        "note": "Widget、Live Activity、通知与主 App 通过 AilohaShared / App Group 交接。"
      },
      {
        "id": "verification-frontier",
        "label": "验证前沿",
        "focus": ["root-shell", "app-owners", "local-packages", "shared-extensions"],
        "note": "Package 与脚本门很多，但 main 没有真实 App test target，跨层合同仍缺裁判。"
      }
    ]
  },
  "components": [
    {
      "id": "user",
      "type": "external",
      "label": "用户",
      "sublabel": "启动 · 浏览 · 输入 · 确认",
      "pos": [40, 274],
      "size": [150, 68],
      "sources": [
        {"path": "Ailoha/Pages/Root/MainTabPage.swift", "line": 21, "label": "登录后主壳"},
        {"path": "Ailoha/Pages/Home/HomePage.swift", "line": 12, "label": "Home 入口"}
      ]
    },
    {
      "id": "app-lifecycle",
      "type": "frontend",
      "label": "进程与生命周期",
      "sublabel": "AilohaApp · AppDelegate",
      "tag": "composition root",
      "pos": [260, 270],
      "size": [180, 76],
      "sources": [
        {"path": "Ailoha/AilohaApp.swift", "line": 34, "label": "SwiftUI 入口"},
        {"path": "Ailoha/AilohaApp.swift", "line": 283, "label": "scene phase"},
        {"path": "Ailoha/AilohaApp.swift", "line": 548, "end_line": 629, "label": "登录 / 登出组合"}
      ]
    },
    {
      "id": "root-shell",
      "type": "frontend",
      "label": "Root / MainTab / Router",
      "sublabel": "登录分流 · 顶层路由 · 页面栈",
      "pos": [510, 270],
      "size": [190, 76],
      "sources": [
        {"path": "Ailoha/Pages/Root/RootPage.swift", "line": 56, "end_line": 83, "label": "Root ownership"},
        {"path": "Ailoha/Pages/Root/MainTabPage.swift", "line": 21, "end_line": 103, "label": "主壳与事件入口"},
        {"path": "Ailoha/GlobalService/Router/Router.swift", "line": 79, "label": "typed routes"}
      ]
    },
    {
      "id": "onboarding-home",
      "type": "frontend",
      "label": "Onboarding · Home",
      "sublabel": "首次体验 · 任务列表 · 输入",
      "pos": [770, 70],
      "size": [190, 76],
      "sources": [
        {"path": "Ailoha/Pages/Root/RootPage.swift", "line": 126, "end_line": 199, "label": "登录态分流"},
        {"path": "Ailoha/Pages/Home/HomePage.swift", "line": 12, "label": "Home surface"},
        {"path": "Ailoha/Pages/Home/HomeViewModel.swift", "line": 14, "label": "Home projection"}
      ]
    },
    {
      "id": "task-chat",
      "type": "frontend",
      "label": "Task · Chat V2",
      "sublabel": "会话投影 · 乐观状态 · Widget",
      "tag": "V2 only on main",
      "pos": [770, 270],
      "size": [190, 76],
      "sources": [
        {"path": "Ailoha/GlobalService/Router/Router.swift", "line": 181, "label": "唯一 Chat route"},
        {"path": "Ailoha/Pages/Task/TaskChatPageV2.swift", "line": 16, "label": "Chat V2 surface"},
        {"path": "Ailoha/Pages/Task/TaskChatViewModel.swift", "line": 18, "label": "页面投影"}
      ]
    },
    {
      "id": "relations",
      "type": "frontend",
      "label": "Contact · Calendar",
      "sublabel": "关系 · 事件 · 搜索 · 编辑",
      "pos": [770, 470],
      "size": [190, 76],
      "sources": [
        {"path": "Ailoha/GlobalService/Router/Router.swift", "line": 209, "end_line": 246, "label": "关系与日历 route"},
        {"path": "Ailoha/GlobalService/Contact/ContactManager.swift", "line": 17, "label": "Contact owner"},
        {"path": "Ailoha/Pages/Calendar/CalendarViewModel.swift", "line": 19, "label": "Calendar projection"}
      ]
    },
    {
      "id": "app-owners",
      "type": "backend",
      "label": "App 状态与副作用 Owners",
      "sublabel": "Auth · Task · Contact · Calendar · Import",
      "tag": "singletons + locator + view models",
      "pos": [1030, 270],
      "size": [210, 76],
      "sources": [
        {"path": "Ailoha/GlobalService/ServiceLocator.swift", "line": 13, "end_line": 85, "label": "service lifecycle"},
        {"path": "Ailoha/GlobalService/Task/TaskLifecycleCoordinator.swift", "line": 17, "label": "Task coordinator"},
        {"path": "Ailoha/GlobalService/Contact/ContactManager.swift", "line": 17, "label": "Contact state"}
      ]
    },
    {
      "id": "transport",
      "type": "backend",
      "label": "REST Facade · ARPC",
      "sublabel": "generated client · handlers · WebSocket",
      "pos": [1300, 270],
      "size": [190, 76],
      "sources": [
        {"path": "Ailoha/GlobalService/APIService/APIService.swift", "line": 18, "label": "API client owner"},
        {"path": "Ailoha/ARPC/ARPCService.swift", "line": 8, "end_line": 44, "label": "App ARPC composition"},
        {"path": "Packages/AilohaARPCKit/Sources/ARPCTransport/ARPCSession.swift", "line": 7, "label": "transport state"}
      ]
    },
    {
      "id": "backend",
      "type": "external",
      "label": "Ailoha Backend / Agent",
      "sublabel": "HTTP · ARPC events · push",
      "pos": [1560, 270],
      "size": [180, 76],
      "sources": [
        {"path": "Ailoha/GlobalService/APIService/APIService.swift", "line": 21, "end_line": 34, "label": "HTTP base path"},
        {"path": "Ailoha/ARPC/ARPCService.swift", "line": 83, "end_line": 105, "label": "ARPC session"}
      ]
    },
    {
      "id": "ios-system",
      "type": "external",
      "label": "iOS 系统入口",
      "sublabel": "push · URL · Share · App Intent",
      "pos": [260, 680],
      "size": [180, 76],
      "sources": [
        {"path": "Ailoha/AppDelegate.swift", "line": 41, "end_line": 67, "label": "push lifecycle"},
        {"path": "Ailoha/AilohaApp.swift", "line": 466, "end_line": 510, "label": "URL handling"},
        {"path": "AilohaWidget/AilohaWidgetBundle.swift", "line": 11, "label": "Widget entry"}
      ]
    },
    {
      "id": "shared-extensions",
      "type": "database",
      "label": "AilohaShared / App Group",
      "sublabel": "Widget · Live Activity · 通知扩展",
      "tag": "cross-process recovery",
      "pos": [770, 680],
      "size": [210, 76],
      "sources": [
        {"path": "AilohaShared/SharedConstants.swift", "line": 15, "label": "shared contract"},
        {"path": "AilohaWidget/ScreenshotTaskLiveActivity.swift", "line": 881, "label": "Activity configuration"},
        {"path": "AilohaNotificationContent/NotificationViewController.swift", "line": 13, "label": "notification extension"}
      ]
    },
    {
      "id": "local-packages",
      "type": "backend",
      "label": "12 个本地 Swift Package",
      "sublabel": "policy · UI · cache · transport · effects",
      "tag": "seams, not full feature owners",
      "pos": [1030, 680],
      "size": [210, 76],
      "sources": [
        {"path": "Ailoha/GlobalService/GlobalImports.swift", "line": 9, "end_line": 18, "label": "global re-export"},
        {"path": "Ailoha.xcodeproj/project.pbxproj", "line": 397, "end_line": 429, "label": "App package products"},
        {"path": "Packages/OnboardingKit/Package.swift", "line": 12, "end_line": 44, "label": "multi-target package"}
      ]
    }
  ],
  "boundaries": [
    {
      "kind": "region",
      "label": "Ailoha main App target",
      "wraps": ["app-lifecycle", "root-shell", "onboarding-home", "task-chat", "relations", "app-owners", "transport"],
      "pad": 24
    },
    {
      "kind": "region",
      "label": "跨进程客户端边界",
      "wraps": ["shared-extensions"],
      "pad": 20
    }
  ],
  "connections": [
    {"id": "user-to-app", "from": "user", "to": "app-lifecycle", "variant": "emphasis", "fromSide": "right", "toSide": "left", "route": "straight"},
    {"id": "app-to-root", "from": "app-lifecycle", "to": "root-shell"},
    {"id": "root-to-home", "from": "root-shell", "to": "onboarding-home", "fromSide": "right", "toSide": "left"},
    {"id": "root-to-chat", "from": "root-shell", "to": "task-chat"},
    {"id": "root-to-relations", "from": "root-shell", "to": "relations", "fromSide": "right", "toSide": "left"},
    {"id": "home-to-owners", "from": "onboarding-home", "to": "app-owners", "fromSide": "right", "toSide": "top"},
    {"id": "chat-to-owners", "from": "task-chat", "to": "app-owners"},
    {"id": "relations-to-owners", "from": "relations", "to": "app-owners", "fromSide": "right", "toSide": "bottom"},
    {"id": "owners-to-transport", "from": "app-owners", "to": "transport", "label": "REST / ARPC"},
    {"id": "transport-to-backend", "from": "transport", "to": "backend", "variant": "emphasis"},
    {"id": "system-to-app", "from": "ios-system", "to": "app-lifecycle", "label": "lifecycle callback", "fromSide": "top", "toSide": "bottom"},
    {"id": "system-to-shared", "from": "ios-system", "to": "shared-extensions", "label": "extension process"},
    {"id": "shared-to-owners", "from": "shared-extensions", "to": "app-owners", "label": "App Group handoff", "variant": "dashed", "fromSide": "top", "toSide": "bottom", "via": [[875, 620], [1135, 620], [1135, 390]]},
    {"id": "owners-to-packages", "from": "app-owners", "to": "local-packages", "variant": "dashed", "fromSide": "bottom", "toSide": "top"},
    {"id": "extension-to-backend", "from": "shared-extensions", "to": "backend", "label": "intent REST / token", "variant": "dashed", "fromSide": "bottom", "toSide": "bottom", "via": [[875, 800], [1650, 800], [1650, 390]]}
  ],
  "cards": [
    {
      "dot": "cyan",
      "title": "当前事实",
      "items": [
        "固定在 main@6922f359；不代表 Release 或线上",
        "4 个 Xcode 产品，12 个本地 Package，771 个 Swift 文件",
        "Chat V2 是 main 唯一路由"
      ]
    },
    {
      "dot": "amber",
      "title": "所有权尚未收口",
      "items": [
        "App target 仍拥有身份、canonical state、恢复与多数网络组合",
        "Package seam 不等于垂直 feature ownership",
        "GlobalImports 让 feature 依赖在 caller 处不可见"
      ]
    },
    {
      "dot": "rose",
      "title": "验证边界",
      "items": [
        "19 个 Package test 文件 + 28 个 Agent E2E case",
        "main 没有 App unit / UI test target，scheme 仍引用不存在产物",
        "默认 PR 只跑 lightweight；完整 Simulator build 需要显式触发"
      ]
    },
    {
      "dot": "slate",
      "title": "证据边界",
      "items": [
        "静态调用链能证明结构，不能证明真机性能、可访问性或生产正确性",
        "目标重构需单独标注，不画成 current fact"
      ]
    }
  ]
}
