# Task: Implement ML-04 Host routes and lifecycle ## Identity - Task ID: 20260827-plugin-ml04-host-lifecycle-4e7a2c91 - Mode: Feature - Branch: codex/20260827-plugin-ml04-host-lifecycle-4e7a2c91-plugin-ml04-host-lifecycle - Worktree: D:\Datas\OthersProjects\makelore-plugin-ml04-host-lifecycle-4e7a2c91 - Base commit: a92cd904d33d4fa0b7c2413188186852a39eb6d4 - Owner: codex-ml04 - Status: Ready for integration ## Scope - Implement ML-04 from exact coordinator frontier `a92cd904d33d4fa0b7c2413188186852a39eb6d4`. - Own only Main composition, Host project-plugin routes, lifecycle wiring, the explicitly listed focused tests, and this task record: `electron/api/routes/coding-plugins.ts`, `electron/api/context.ts`, `electron/api/route-handlers.ts`, `electron/api/coding-product-services.ts`, `electron/api/coding-composition.ts`, `electron/api/server.ts` only when exact registration requires it, and `electron/main/index.ts` shutdown wiring only. - Do not modify ML-01 project-service source/tests, preview session code, Renderer/ML-05, or P1 paths without an explicit coordinator transfer. ## Intent And Constraints - Follow implementation spec §7.5 and §10.2–10.3, ML-04 in the ticket graph, and detailed design §§8.1–8.4, 8.8–8.9, 12, and 13. - Compose the package registry, project plugin service, policy client, capability registry, and Data Service adapter in Main; expose only bounded project projections, never adapter internals, tokens, owner, prices, or raw policy. - Expose exact GET/PUT `/api/coding/plugins` routes using a local project handle resolved by `CodingProjectService` to real path and durable identity. Keep Data Service configuration on existing typed routes and preserve IPC/loopback order. - Wire enable/disable managed-input revision and adapter deactivation, plus logout, project transition, identity-change-before-write, shutdown, and backend-degraded behavior without deleting data. - Test-first with one final implementation commit whose sole parent is the exact base. Keep the worktree isolated and do not publish or claim a PR. ## Project Context Loaded - Concurrent Task Gate passed: `check_project_docs.py` succeeded and `task_context.py start`/`status --json` match this task ID, owner, worktree, branch, feature mode, and base commit. - Read the required entry files, active task record, project positioning/current state/decision/system/architecture/domain/evidence/reflection/commitment/stale indexes, MakeLore `AGENTS.md`, implementation spec §7.5 and §10.2–10.3, ML-04 ticket, and detailed-design host/lifecycle/authority/error sections. - Same-topic peer scopes are the client coordinator and completed ML-01–ML-03 records. ML-03's exact product frontier is `fd891ff3bb87a29381a0a7006fb4618ec4fe144f`, integrated by the coordinator as `a92cd904d33d4fa0b7c2413188186852a39eb6d4`. ML-01 owns project-service files; no unresolved semantic conflict exists. - Integrated project memory is older than this plugin implementation and remains a last-integrated snapshot; frozen spec, coordinator task record, and exact frontier control this task. Root `main` remains outside this worktree and is not modified. ## Plan 1. Inspect the exact ML-03 product seams and existing route/composition/lifecycle tests without changing files; map the required Host DTO and lifecycle callbacks. 2. Add failing focused tests for exact routes, Main-only authority, composition, projection/degraded inspect behavior, and lifecycle invalidation/deactivation. 3. Implement the smallest cohesive Host/composition/lifecycle changes within the exclusive ownership boundary, preserving typed Data Service routes and route dispatcher ordering. 4. Run owned focused and relevant regressions, typecheck, lint, build as required, and diff/doc gates; fix only failures within owned scope. 5. Record exact outcome/evidence, run `check_doc_drift.py`, complete task_context, and return a clean single commit to the coordinator. ## Gate Result - Planning Gate: Passed on 2026-08-27. No unresolved ownership or semantic conflict affects ML-04. ## Verification - Test-first red evidence: the three new focused test files initially failed because `handleCodingPluginRoutes` and `createCodingProjectPluginService` did not exist. The first lifecycle composition assertion then exposed an invalid test premise (durable project identity is immutable); it was corrected to the supported legacy-identity resolution path before the final green run. - ML-04 focused plus required Host/lifecycle regressions: `coding-plugin-routes`, `coding-plugin-composition`, `coding-plugin-lifecycle`, `coding-product-services`, `data-service-server-registration`, `coding-core-routes`, `coding-project-identity`, and `main-quit-lifecycle` — 8 files / 47 tests passed with one worker. - Policy/capability/Data Service/Pi/preview regressions — 12 files / 86 passed / 2 staged-runtime-gated skips. - `corepack pnpm run typecheck` — passed. - `corepack pnpm run lint:check` — 0 errors and the same 5 pre-existing warnings in `src/pages/Home/index.tsx` and `src/pages/Makelore/index.tsx`. - `corepack pnpm run build:vite` — Renderer, Main, Preload, and release utility builds passed; only existing dynamic-import and chunk-size warnings appeared. - `git diff --check` — passed before documentation completion. ## Outcome - Added the exact project-scoped GET/PUT Host routes and registered them in the shared IPC/loopback dispatcher between coding project and conversation routes. Requests accept only the local project handle plus the exact enable boolean; path, durable identity, owner, token, policy, and price cannot be supplied. - Added a bounded Main project-plugin projection service that resolves the local handle through `CodingProjectService`, reads durable identity in Main, refreshes and exactly joins verified policy with fixed package definitions, reports Skill assignments, sanitizes backend projection, and isolates per-adapter inspect failures. Existing typed Data Service routes remain the only configuration API. - Composition now creates the project selection service, policy client, Data Service adapter, capability registry, and Renderer projection. One `configureCapabilityRegistry(...)` late-binding seam replaces production `configureDataService(...)`; parent and child worker materialization receive the same refresh-before-resolution capability registry. - Selection changes mark managed resources stale and forget project worker bindings. Disable invalidates preview and deactivates only the affected adapter; project transition and identity change deactivate all session adapters, with identity invalidation/deactivation completing before the atomic write. Authentication cleanup deactivates the active project adapter. Shutdown deactivates adapters before subagent/runtime shutdown. Cleanup failures are isolated and never rewrite selection or delete cloud/local data. ## Follow-ups - ML-05 may consume `CodingPluginProjectProjection` through the exact Host routes; it must keep Data Service configuration on `/api/works/data-service/...`. ## Promotion Candidates - None recorded.