|
| 1 | +# Capsule Readiness Audit — Executive Summary |
| 2 | + |
| 3 | +> **Companion to**: [`CAPSULE_READINESS_REPORT.md`](./CAPSULE_READINESS_REPORT.md) (full audit data, methodology, 638-line per-module classification). |
| 4 | +> **For**: Sasha, Anders (Runtime team), Ahmed (ENM), board narrative. |
| 5 | +> **Reading time**: 3 minutes. |
| 6 | +> **Status**: Audit-in-progress; 51 of 272 pc2-node modules classified (18.8%); strategy stable. |
| 7 | +> **Updated**: 2026-05-16. |
| 8 | +
|
| 9 | +--- |
| 10 | + |
| 11 | +## TL;DR |
| 12 | + |
| 13 | +pc2-node is **more capsule-ready than expected**. After auditing 51 modules across 6 subtrees: |
| 14 | + |
| 15 | +- **75% of audited modules are A or A- class** (capsule-ready or close to it) |
| 16 | +- **Only 2 modules are deeply coupled** (C-class): `ConnectivityService` and `api/index.ts` — both mega-orchestrators that the Runtime architecture eliminates by design |
| 17 | +- **The ElastOS Runtime capability vocabulary already exists** inside pc2-node and is **already being enforced** at the HTTP boundary |
| 18 | +- **Migration is role-scoped, not subtree-scoped** — lift A-class leaves in parallel across all subtrees; refactor B-class orchestrators in bounded chunks; redesign the 2 C-class mega-orchestrators last |
| 19 | + |
| 20 | +Runtime convergence is **extension of existing structure, not greenfield invention**. The dual-track strategy from `AGENTIC-PC2-MONETISATION-2026-05` is supported by empirical evidence. |
| 21 | + |
| 22 | +--- |
| 23 | + |
| 24 | +## The five findings that matter |
| 25 | + |
| 26 | +### Finding 1: The capability vocabulary already exists |
| 27 | + |
| 28 | +`pc2-node/src/types/capabilities.ts` defines a 14-scope capability vocabulary (`storage:read`, `storage:write`, `ipfs:fetch`, `wallet:read`, `wallet:sign`, `drm:decrypt`, `drm:encrypt`, `compute:wasm`, `compute:ai`, `network:rpc`, `ipc:launch`, `ipc:message`, `identity:auth`, `ipfs:pin`). The file header states: |
| 29 | + |
| 30 | +> *Single source of truth for capability scope names used across: AppManifest.capabilities, API key scopes, Wallet bridge method classification, Runtime v2 capability token `action` fields. These map 1:1 to ElastOS Runtime provider contract operations.* |
| 31 | +
|
| 32 | +**Implication**: pc2-node was designed from the start with Runtime convergence in mind. The vocabulary is in place. Whoever wrote this file was already thinking in capability-token terms. |
| 33 | + |
| 34 | +### Finding 2: The capability ENFORCEMENT already exists |
| 35 | + |
| 36 | +`pc2-node/src/api/middleware.ts` exports `requireCapability(scope: string)` middleware that gates HTTP routes using the Finding-1 vocabulary. Combined with `populatePrincipal()` and the `CapabilityPrincipal` interface, **pc2-node has a working capability-token enforcement layer at HTTP request time**. |
| 37 | + |
| 38 | +**Implication**: We don't need to *invent* capability enforcement; we need to (a) extend it to non-HTTP entry points (websocket, IPC), and (b) port the enforcement layer into the Runtime substrate. The mental model already lives in pc2-node code. |
| 39 | + |
| 40 | +### Finding 3: Capsule readiness is role-based, not subtree-based |
| 41 | + |
| 42 | +The pilot audit's framing ("AI is mostly A, connectivity is mostly C") turned out to be sampling artefact. After auditing 51 modules across 6 subtrees, the pattern is clear: |
| 43 | + |
| 44 | +- **Pure utility / protocol / type leaves** → A-class everywhere |
| 45 | +- **File-backed services with light direct-fs** → A- everywhere |
| 46 | +- **Medium orchestrators wiring sibling services** → B everywhere |
| 47 | +- **Mega-orchestrators with 40+ concrete imports** → C (only 2 modules; both will be retired by capsule architecture) |
| 48 | + |
| 49 | +**Implication**: Runtime migration order is decoupled from subtree boundaries. The Runtime team can lift `boson-crypto` + `ai-providers` + `storage-migrations` **in parallel as their own crates**, not sequentially per-subtree. This unblocks parallel work. |
| 50 | + |
| 51 | +### Finding 4: One refactor pattern dominates |
| 52 | + |
| 53 | +The single biggest cross-cutting blocker is **"concrete class import where an interface should suffice"** — confirmed in 9+ modules across 5 subtrees. Examples: |
| 54 | +- `filesystem.ts` imports concrete `IPFSStorage` + `DatabaseManager` |
| 55 | +- `api/wallet.ts` imports concrete `AgentKitExecutor` |
| 56 | +- `BosonService` imports 7 concrete sibling services |
| 57 | +- `metrics.ts` imports concrete `DatabaseManager` |
| 58 | + |
| 59 | +**The fix**: extract ~5-6 interfaces (`IFilesystemManager`, `IDatabaseManager`, `IIPFSStorage`, `IAIChatService`, `IAgentKitExecutor`, `IIdentityService`). One Phase 2 ticket. Improves the score of 9+ modules. |
| 60 | + |
| 61 | +**Estimated effort**: 1 week of focused work, value-positive for PC2 v1 testability and Runtime migration alike. |
| 62 | + |
| 63 | +### Finding 5: Only 2 modules are deeply coupled |
| 64 | + |
| 65 | +After 51 audits, only **two** modules earn C-class: |
| 66 | +- `pc2-node/src/services/boson/ConnectivityService.ts` (1,597 LOC, network-side mega-orchestrator with state machine and setter-injected services) |
| 67 | +- `pc2-node/src/api/index.ts` (1,766 LOC, HTTP-side mega-orchestrator wiring 40+ siblings, ambient Express coupling) |
| 68 | + |
| 69 | +Both are the same architectural pattern on opposite sides of the codebase. Both will be **retired**, not refactored, by capsule architecture (capsules don't have single mega-entry-points by design). |
| 70 | + |
| 71 | +**Implication**: the "PC2-as-monolith" problem is concentrated in 2 files. The other 49 audited modules are either capsule-shape already (38) or one bounded refactor away (11). |
| 72 | + |
| 73 | +--- |
| 74 | + |
| 75 | +## The strategic verdict |
| 76 | + |
| 77 | +After 51 modules of empirical data: |
| 78 | + |
| 79 | +**Phase 1 (immediate, blocking nothing)**: Mac launcher ships. Stable for 48-72h. |
| 80 | + |
| 81 | +**Phase 2 (post-Mac, ~3-4 weeks of bounded work)**: |
| 82 | +- **(a) Runtime team can begin lifting A-class leaves as crates in parallel**: `boson-crypto`, `boson-protocol`, `ai-providers`, `storage-migrations`, `types-capabilities`. Low coordination cost; leaves don't change shape. |
| 83 | +- **(b) PC2 team can refactor B-class orchestrators in bounded chunks** (~15-20 days total): |
| 84 | + - `AIChatService` split (~3-5 days) |
| 85 | + - `ToolExecutor` split + capability injection (~4-5 days) |
| 86 | + - `BosonService` interface extraction (~1-2 days) |
| 87 | + - `filesystem.ts` + `indexer.ts` interface extraction (~1-2 days) |
| 88 | + - Cross-cutting "concrete-class → interface" refactor (~1 week — touches 9+ modules) |
| 89 | +- **(c) Both C-class mega-orchestrators** wait for Runtime substrate; their eventual redesign retires the mega-orchestrator pattern altogether. |
| 90 | + |
| 91 | +**Phase 3 (Q4 2026 onwards)**: ConnectivityService + api/index.ts redesign happens as the Runtime substrate matures. The 2 mega-orchestrators are the last things to migrate, by design. |
| 92 | + |
| 93 | +--- |
| 94 | + |
| 95 | +## What this changes about the AGENTIC-PC2-MONETISATION mandate |
| 96 | + |
| 97 | +The mandate's dual-track strategy is **supported with stronger empirical backing**: |
| 98 | + |
| 99 | +1. **Track 1 (PC2 v1 evolution)**: Work in the AI leaf modules is NOT throw-away. Those modules already match the capsule shape; they migrate cleanly. |
| 100 | +2. **Track 2 (Runtime convergence)**: Runtime is **not future-tense**. The vocabulary, enforcement layer, and module shape are already partly in place. Convergence is incremental extension, not greenfield rewrite. |
| 101 | +3. **The 8 new Rust crates identified in mandate v1.1 §7.5** can now be cross-referenced to specific pc2-node modules: |
| 102 | + - `dDRM provider` capsule — sources from `services/ai/tools/` + the dDRM modules (not yet audited) |
| 103 | + - `boson-crypto` capsule — sources directly from `services/boson/CryptoBox.ts` (A, 9/10) |
| 104 | + - `boson-protocol` capsule — sources directly from `services/boson/ProxyProtocol.ts` (A, 10/10) |
| 105 | + - `ai-providers` capsule — sources from `services/ai/providers/*.ts` (all A-class) |
| 106 | + - `storage-migrations` capsule — sources from `storage/migrations.ts` (A, 9/10) |
| 107 | + |
| 108 | +--- |
| 109 | + |
| 110 | +## What we DON'T yet know |
| 111 | + |
| 112 | +- 80% of pc2-node/src is still unaudited. Distribution may shift as more modules come in. |
| 113 | +- `services/dDRM/`, `services/ddrm/`, `services/gateway/`, `services/UpdateService.ts` — the DRM and update subsystems are not yet sampled. These could surface additional C-class entries or new patterns. |
| 114 | +- The 40 remaining `api/` HTTP handlers are predicted to be ~70% B / 25% A- / 5% C but unverified. |
| 115 | +- WebSocket subtree (`websocket/*`) has 4 modules; not yet sampled. |
| 116 | + |
| 117 | +**Audit completion plan**: extend in subtree batches per `CAPSULE_READINESS_REPORT §6`. Target 50% coverage in the May 25-29 window (post-Mac launcher). The remaining ~221 modules are ~12-15 hours of analyst-time at current pace. |
| 118 | + |
| 119 | +--- |
| 120 | + |
| 121 | +## What you do with this document |
| 122 | + |
| 123 | +- **Sasha**: skim Finding 3 + 4 + the strategic verdict. Decide whether to commit to the (a)(b)(c) phasing for Phase 2. |
| 124 | +- **Anders / Runtime team**: skim Findings 1 + 2 (the capability infra already exists) + the strategic verdict (a). Identify which A-class crates to lift first. |
| 125 | +- **Ahmed / ENM**: skim Finding 1 + the cross-reference table at the bottom. The ENM integration path inherits from the same capability vocabulary. |
| 126 | +- **Board narrative**: TL;DR + the strategic verdict. The story is "pc2-node was architected for Runtime convergence from the start; the migration is bounded and parallelisable". |
0 commit comments