agentic-orchestrator 0.1.25 → 0.1.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agentic/orchestrator/defaults/policy.defaults.yaml +1 -0
- package/agentic/orchestrator/policy.yaml +1 -0
- package/agentic/orchestrator/schemas/policy.schema.json +4 -0
- package/agentic/orchestrator/schemas/policy.user.schema.json +4 -0
- package/apps/control-plane/src/application/services/activity-monitor-service.ts +42 -0
- package/apps/control-plane/src/application/services/collision-queue-service.ts +48 -0
- package/apps/control-plane/src/application/services/cost-tracking-service.ts +80 -0
- package/apps/control-plane/src/application/services/feature-deletion-service.ts +57 -0
- package/apps/control-plane/src/application/services/feature-lifecycle-service.ts +65 -0
- package/apps/control-plane/src/application/services/feature-state-service.ts +87 -0
- package/apps/control-plane/src/application/services/gate-selection-service.ts +28 -0
- package/apps/control-plane/src/application/services/gate-service.ts +148 -0
- package/apps/control-plane/src/application/services/issue-tracker-service.ts +28 -0
- package/apps/control-plane/src/application/services/lock-service.ts +88 -0
- package/apps/control-plane/src/application/services/merge-service.ts +63 -0
- package/apps/control-plane/src/application/services/notifier-service.ts +70 -0
- package/apps/control-plane/src/application/services/patch-service.ts +95 -0
- package/apps/control-plane/src/application/services/performance-analytics-service.ts +90 -0
- package/apps/control-plane/src/application/services/plan-service.ts +184 -0
- package/apps/control-plane/src/application/services/pr-monitor-service.ts +58 -0
- package/apps/control-plane/src/application/services/qa-index-service.ts +68 -0
- package/apps/control-plane/src/application/services/reactions-service.ts +77 -0
- package/apps/control-plane/src/application/services/reporting-service.ts +79 -0
- package/apps/control-plane/src/application/services/run-lease-service.ts +79 -0
- package/apps/control-plane/src/application/tools/tool-router.ts +76 -0
- package/apps/control-plane/src/mcp/tool-runtime.ts +4 -0
- package/apps/control-plane/src/providers/providers.ts +96 -0
- package/apps/control-plane/src/providers/worker-provider-factory.ts +4 -0
- package/apps/control-plane/src/supervisor/build-wave-executor.ts +4 -0
- package/apps/control-plane/src/supervisor/planning-wave-executor.ts +4 -0
- package/apps/control-plane/src/supervisor/qa-wave-executor.ts +4 -0
- package/apps/control-plane/src/supervisor/run-coordinator.ts +4 -0
- package/apps/control-plane/src/supervisor/runtime.ts +4 -0
- package/apps/control-plane/src/supervisor/session-orchestrator.ts +4 -0
- package/apps/control-plane/test/dashboard-api.integration.spec.ts +310 -1
- package/apps/control-plane/test/dashboard-client.spec.ts +136 -1
- package/apps/control-plane/test/dashboard-live-feed.spec.ts +153 -0
- package/apps/control-plane/test/dashboard-ui-utils.spec.ts +132 -0
- package/apps/control-plane/test/mcp.spec.ts +96 -0
- package/apps/control-plane/test/tool-runtime.spec.ts +68 -0
- package/config/agentic/orchestrator/policy.yaml +1 -0
- package/dist/apps/control-plane/application/services/activity-monitor-service.d.ts +42 -0
- package/dist/apps/control-plane/application/services/activity-monitor-service.js +42 -0
- package/dist/apps/control-plane/application/services/activity-monitor-service.js.map +1 -1
- package/dist/apps/control-plane/application/services/collision-queue-service.d.ts +48 -0
- package/dist/apps/control-plane/application/services/collision-queue-service.js +48 -0
- package/dist/apps/control-plane/application/services/collision-queue-service.js.map +1 -1
- package/dist/apps/control-plane/application/services/cost-tracking-service.d.ts +79 -0
- package/dist/apps/control-plane/application/services/cost-tracking-service.js +76 -0
- package/dist/apps/control-plane/application/services/cost-tracking-service.js.map +1 -1
- package/dist/apps/control-plane/application/services/feature-deletion-service.d.ts +57 -0
- package/dist/apps/control-plane/application/services/feature-deletion-service.js +57 -0
- package/dist/apps/control-plane/application/services/feature-deletion-service.js.map +1 -1
- package/dist/apps/control-plane/application/services/feature-lifecycle-service.d.ts +64 -0
- package/dist/apps/control-plane/application/services/feature-lifecycle-service.js +61 -0
- package/dist/apps/control-plane/application/services/feature-lifecycle-service.js.map +1 -1
- package/dist/apps/control-plane/application/services/feature-state-service.d.ts +86 -0
- package/dist/apps/control-plane/application/services/feature-state-service.js +83 -0
- package/dist/apps/control-plane/application/services/feature-state-service.js.map +1 -1
- package/dist/apps/control-plane/application/services/gate-selection-service.d.ts +28 -0
- package/dist/apps/control-plane/application/services/gate-selection-service.js +28 -0
- package/dist/apps/control-plane/application/services/gate-selection-service.js.map +1 -1
- package/dist/apps/control-plane/application/services/gate-service.d.ts +148 -0
- package/dist/apps/control-plane/application/services/gate-service.js +120 -0
- package/dist/apps/control-plane/application/services/gate-service.js.map +1 -1
- package/dist/apps/control-plane/application/services/issue-tracker-service.d.ts +28 -0
- package/dist/apps/control-plane/application/services/issue-tracker-service.js +28 -0
- package/dist/apps/control-plane/application/services/issue-tracker-service.js.map +1 -1
- package/dist/apps/control-plane/application/services/lock-service.d.ts +88 -0
- package/dist/apps/control-plane/application/services/lock-service.js +64 -0
- package/dist/apps/control-plane/application/services/lock-service.js.map +1 -1
- package/dist/apps/control-plane/application/services/merge-service.d.ts +62 -0
- package/dist/apps/control-plane/application/services/merge-service.js +59 -0
- package/dist/apps/control-plane/application/services/merge-service.js.map +1 -1
- package/dist/apps/control-plane/application/services/notifier-service.d.ts +70 -0
- package/dist/apps/control-plane/application/services/notifier-service.js +70 -0
- package/dist/apps/control-plane/application/services/notifier-service.js.map +1 -1
- package/dist/apps/control-plane/application/services/patch-service.d.ts +94 -0
- package/dist/apps/control-plane/application/services/patch-service.js +91 -0
- package/dist/apps/control-plane/application/services/patch-service.js.map +1 -1
- package/dist/apps/control-plane/application/services/performance-analytics-service.d.ts +89 -0
- package/dist/apps/control-plane/application/services/performance-analytics-service.js +86 -0
- package/dist/apps/control-plane/application/services/performance-analytics-service.js.map +1 -1
- package/dist/apps/control-plane/application/services/plan-service.d.ts +287 -0
- package/dist/apps/control-plane/application/services/plan-service.js +207 -0
- package/dist/apps/control-plane/application/services/plan-service.js.map +1 -1
- package/dist/apps/control-plane/application/services/pr-monitor-service.d.ts +58 -0
- package/dist/apps/control-plane/application/services/pr-monitor-service.js +58 -0
- package/dist/apps/control-plane/application/services/pr-monitor-service.js.map +1 -1
- package/dist/apps/control-plane/application/services/qa-index-service.d.ts +67 -0
- package/dist/apps/control-plane/application/services/qa-index-service.js +64 -0
- package/dist/apps/control-plane/application/services/qa-index-service.js.map +1 -1
- package/dist/apps/control-plane/application/services/reactions-service.d.ts +76 -0
- package/dist/apps/control-plane/application/services/reactions-service.js +73 -0
- package/dist/apps/control-plane/application/services/reactions-service.js.map +1 -1
- package/dist/apps/control-plane/application/services/reporting-service.d.ts +78 -0
- package/dist/apps/control-plane/application/services/reporting-service.js +75 -0
- package/dist/apps/control-plane/application/services/reporting-service.js.map +1 -1
- package/dist/apps/control-plane/application/services/run-lease-service.d.ts +79 -0
- package/dist/apps/control-plane/application/services/run-lease-service.js +79 -0
- package/dist/apps/control-plane/application/services/run-lease-service.js.map +1 -1
- package/dist/apps/control-plane/application/tools/tool-router.d.ts +76 -0
- package/dist/apps/control-plane/application/tools/tool-router.js +62 -0
- package/dist/apps/control-plane/application/tools/tool-router.js.map +1 -1
- package/dist/apps/control-plane/mcp/tool-runtime.d.ts +3 -0
- package/dist/apps/control-plane/mcp/tool-runtime.js +3 -0
- package/dist/apps/control-plane/mcp/tool-runtime.js.map +1 -1
- package/dist/apps/control-plane/providers/providers.d.ts +88 -0
- package/dist/apps/control-plane/providers/providers.js.map +1 -1
- package/dist/apps/control-plane/providers/worker-provider-factory.d.ts +3 -0
- package/dist/apps/control-plane/providers/worker-provider-factory.js.map +1 -1
- package/dist/apps/control-plane/supervisor/build-wave-executor.d.ts +3 -0
- package/dist/apps/control-plane/supervisor/build-wave-executor.js +3 -0
- package/dist/apps/control-plane/supervisor/build-wave-executor.js.map +1 -1
- package/dist/apps/control-plane/supervisor/planning-wave-executor.d.ts +3 -0
- package/dist/apps/control-plane/supervisor/planning-wave-executor.js +3 -0
- package/dist/apps/control-plane/supervisor/planning-wave-executor.js.map +1 -1
- package/dist/apps/control-plane/supervisor/qa-wave-executor.d.ts +3 -0
- package/dist/apps/control-plane/supervisor/qa-wave-executor.js +3 -0
- package/dist/apps/control-plane/supervisor/qa-wave-executor.js.map +1 -1
- package/dist/apps/control-plane/supervisor/run-coordinator.d.ts +3 -0
- package/dist/apps/control-plane/supervisor/run-coordinator.js +3 -0
- package/dist/apps/control-plane/supervisor/run-coordinator.js.map +1 -1
- package/dist/apps/control-plane/supervisor/runtime.d.ts +3 -0
- package/dist/apps/control-plane/supervisor/runtime.js +3 -0
- package/dist/apps/control-plane/supervisor/runtime.js.map +1 -1
- package/dist/apps/control-plane/supervisor/session-orchestrator.d.ts +3 -0
- package/dist/apps/control-plane/supervisor/session-orchestrator.js +3 -0
- package/dist/apps/control-plane/supervisor/session-orchestrator.js.map +1 -1
- package/package.json +1 -1
- package/packages/web-dashboard/src/app/analytics/page.tsx +451 -0
- package/packages/web-dashboard/src/app/api/analytics/route.ts +62 -0
- package/packages/web-dashboard/src/app/api/collisions/route.ts +63 -0
- package/packages/web-dashboard/src/app/api/features/[id]/cost/route.ts +29 -0
- package/packages/web-dashboard/src/app/api/features/[id]/review-brief/route.ts +31 -0
- package/packages/web-dashboard/src/app/api/features/[id]/route.ts +5 -8
- package/packages/web-dashboard/src/app/api/features/[id]/test-index/route.ts +31 -0
- package/packages/web-dashboard/src/app/api/flaky/route.ts +20 -0
- package/packages/web-dashboard/src/app/api/policy/budget/route.ts +31 -0
- package/packages/web-dashboard/src/app/api/run/route.ts +162 -0
- package/packages/web-dashboard/src/app/api/status/route.ts +2 -5
- package/packages/web-dashboard/src/app/feature/[id]/page.tsx +112 -0
- package/packages/web-dashboard/src/app/page.tsx +379 -77
- package/packages/web-dashboard/src/components/agent-pipeline-stepper.tsx +100 -0
- package/packages/web-dashboard/src/components/dependency-chains.tsx +58 -0
- package/packages/web-dashboard/src/components/detail-panel.tsx +215 -5
- package/packages/web-dashboard/src/components/feature-card.tsx +5 -0
- package/packages/web-dashboard/src/components/feature-cost-panel.tsx +66 -0
- package/packages/web-dashboard/src/components/feature-list-view.tsx +336 -0
- package/packages/web-dashboard/src/components/gate-step-drilldown.tsx +92 -0
- package/packages/web-dashboard/src/components/kanban-board.tsx +3 -0
- package/packages/web-dashboard/src/components/live-event-feed.tsx +60 -0
- package/packages/web-dashboard/src/components/lock-resource-map.tsx +73 -0
- package/packages/web-dashboard/src/components/plan-revision-timeline.tsx +55 -0
- package/packages/web-dashboard/src/components/plan-risk-annotations.tsx +63 -0
- package/packages/web-dashboard/src/components/plan-scope-tree.tsx +285 -0
- package/packages/web-dashboard/src/components/qa-coverage-map.tsx +174 -0
- package/packages/web-dashboard/src/components/quick-launch-panel.tsx +70 -0
- package/packages/web-dashboard/src/components/review-brief-panel.tsx +75 -0
- package/packages/web-dashboard/src/components/run-health-panel.tsx +85 -0
- package/packages/web-dashboard/src/components/summary-bar.tsx +59 -2
- package/packages/web-dashboard/src/components/verification-signals.tsx +167 -0
- package/packages/web-dashboard/src/lib/analytics-utils.ts +3 -0
- package/packages/web-dashboard/src/lib/aop-client.ts +510 -11
- package/packages/web-dashboard/src/lib/api-envelope.ts +48 -0
- package/packages/web-dashboard/src/lib/authz-adapter.ts +33 -0
- package/packages/web-dashboard/src/lib/dashboard-utils.ts +304 -0
- package/packages/web-dashboard/src/lib/live-feed.ts +218 -0
- package/packages/web-dashboard/src/lib/policy-reader.ts +22 -0
- package/packages/web-dashboard/src/lib/types.ts +114 -0
- package/packages/web-dashboard/src/styles/dashboard.module.css +341 -1
- package/spec-files/{outstanding → completed}/agentic_orchestrator_dashboard_advanced_ux_spec.md +1 -1
- package/spec-files/outstanding/agentic_orchestrator_evidence_integrity_doctor_spec.md +561 -0
- package/spec-files/outstanding/agentic_orchestrator_kernel_simplification_spec.md +834 -0
- package/spec-files/outstanding/agentic_orchestrator_observability_integrity_diagnostics_spec.md +12 -5
- package/spec-files/outstanding/agentic_orchestrator_observability_replay_spec.md +442 -0
- package/spec-files/progress.md +174 -1
|
@@ -0,0 +1,834 @@
|
|
|
1
|
+
# Feature Spec: Kernel Simplification and Service Extraction (AOP)
|
|
2
|
+
|
|
3
|
+
> **Purpose of this document**: Define a systematic refactoring plan to simplify the AopKernel class by extracting cohesive services, reducing its size from 1768 lines to <500 lines, and improving maintainability while preserving all existing behavior and contracts.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 1. Objectives
|
|
8
|
+
|
|
9
|
+
### 1.1 Must-Have Outcomes
|
|
10
|
+
|
|
11
|
+
- **Reduce kernel size**: From 1768 lines to <500 lines (70% reduction)
|
|
12
|
+
- **Extract cohesive services**: Move domain logic into focused service classes
|
|
13
|
+
- **Preserve all behavior**: Zero breaking changes to tool contracts, CLI, or runtime
|
|
14
|
+
- **Maintain test coverage**: All existing tests must pass without modification
|
|
15
|
+
- **Improve maintainability**: Each service has single responsibility
|
|
16
|
+
- **Enable parallel development**: Services can be modified independently
|
|
17
|
+
|
|
18
|
+
### 1.2 Success Criteria
|
|
19
|
+
|
|
20
|
+
- ✅ Kernel class <500 lines
|
|
21
|
+
- ✅ All 67 tool methods delegated to services
|
|
22
|
+
- ✅ Zero test failures
|
|
23
|
+
- ✅ `npm run verify` passes
|
|
24
|
+
- ✅ All existing tool contracts unchanged
|
|
25
|
+
- ✅ Performance unchanged (±5% latency tolerance)
|
|
26
|
+
|
|
27
|
+
### 1.3 Non-Goals
|
|
28
|
+
|
|
29
|
+
- Not changing tool contracts or error codes
|
|
30
|
+
- Not modifying state/index/plan schemas
|
|
31
|
+
- Not replacing file-based storage
|
|
32
|
+
- Not adding new features
|
|
33
|
+
- Not changing CLI commands or flags
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## 2. Current State Analysis
|
|
38
|
+
|
|
39
|
+
### 2.1 Kernel Metrics
|
|
40
|
+
|
|
41
|
+
**File:** `apps/control-plane/src/core/kernel.ts`
|
|
42
|
+
|
|
43
|
+
- **Total lines:** 1768
|
|
44
|
+
- **Class lines:** 1540 (lines 207-1747)
|
|
45
|
+
- **Methods:** 67 async methods
|
|
46
|
+
- **Dependencies:** 15 service instances
|
|
47
|
+
- **Responsibilities:** 12+ distinct concerns
|
|
48
|
+
|
|
49
|
+
### 2.2 Current Responsibilities
|
|
50
|
+
|
|
51
|
+
The kernel currently handles:
|
|
52
|
+
|
|
53
|
+
1. **Configuration loading** (policy, gates, agents, adapters)
|
|
54
|
+
2. **Schema validation** (all artifact types)
|
|
55
|
+
3. **Tool routing** (67 tool methods)
|
|
56
|
+
4. **Feature lifecycle** (init, discover, context)
|
|
57
|
+
5. **State management** (read, write, patch, locks)
|
|
58
|
+
6. **Index management** (read, write, atomic updates)
|
|
59
|
+
7. **Plan operations** (submit, update, get, collision)
|
|
60
|
+
8. **Patch operations** (validate, apply)
|
|
61
|
+
9. **Gate execution** (run, evidence, selection)
|
|
62
|
+
10. **Lock management** (acquire, release, leases)
|
|
63
|
+
11. **Merge operations** (ready_to_merge, cleanup)
|
|
64
|
+
12. **Reporting** (dashboard, summaries)
|
|
65
|
+
13. **QA index** (get, update)
|
|
66
|
+
14. **Cost tracking** (record, get)
|
|
67
|
+
15. **Run lease** (acquire, renew, release)
|
|
68
|
+
16. **Recovery** (state reconstruction)
|
|
69
|
+
|
|
70
|
+
### 2.3 Service Dependencies
|
|
71
|
+
|
|
72
|
+
Current services instantiated in kernel:
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
private readonly runLeaseService: RunLeaseService;
|
|
76
|
+
private readonly lockService: LockService;
|
|
77
|
+
readonly collisionQueueService: CollisionQueueService;
|
|
78
|
+
private readonly reportingService: ReportingService;
|
|
79
|
+
private readonly featureStateService: FeatureStateService;
|
|
80
|
+
private readonly featureLifecycleService: FeatureLifecycleService;
|
|
81
|
+
private readonly planService: PlanService;
|
|
82
|
+
private readonly patchService: PatchService;
|
|
83
|
+
private readonly gateService: GateService;
|
|
84
|
+
private readonly qaIndexService: QaIndexService;
|
|
85
|
+
private readonly mergeService: MergeService;
|
|
86
|
+
private readonly featureDeletionService: FeatureDeletionService;
|
|
87
|
+
private readonly costTrackingService: CostTrackingService;
|
|
88
|
+
private readonly performanceAnalyticsService: PerformanceAnalyticsService;
|
|
89
|
+
private readonly gateSelectionService: GateSelectionService;
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
**Issue:** Kernel implements port interfaces for all these services, creating tight coupling.
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## 3. Refactoring Strategy
|
|
97
|
+
|
|
98
|
+
### 3.1 Phased Approach
|
|
99
|
+
|
|
100
|
+
**Phase 1: Extract Configuration Management** (Week 1)
|
|
101
|
+
|
|
102
|
+
- Create `ConfigurationService`
|
|
103
|
+
- Move policy/gates/agents loading
|
|
104
|
+
- ~200 lines extracted
|
|
105
|
+
|
|
106
|
+
**Phase 2: Extract Core Repositories** (Week 1)
|
|
107
|
+
|
|
108
|
+
- Create `IndexRepository`
|
|
109
|
+
- Create `StateRepository`
|
|
110
|
+
- Move file I/O and locking
|
|
111
|
+
- ~300 lines extracted
|
|
112
|
+
|
|
113
|
+
**Phase 3: Simplify Tool Routing** (Week 2)
|
|
114
|
+
|
|
115
|
+
- Reduce kernel to thin delegation layer
|
|
116
|
+
- All 67 methods become 1-2 line delegations
|
|
117
|
+
- ~400 lines simplified
|
|
118
|
+
|
|
119
|
+
**Phase 4: Extract Utility Functions** (Week 2)
|
|
120
|
+
|
|
121
|
+
- Move helper functions to utility modules
|
|
122
|
+
- ~100 lines extracted
|
|
123
|
+
|
|
124
|
+
**Phase 5: Final Cleanup** (Week 2)
|
|
125
|
+
|
|
126
|
+
- Remove redundant code
|
|
127
|
+
- Optimize imports
|
|
128
|
+
- ~200 lines removed
|
|
129
|
+
|
|
130
|
+
### 3.2 Target Architecture
|
|
131
|
+
|
|
132
|
+
```
|
|
133
|
+
AopKernel (< 500 lines)
|
|
134
|
+
├── ConfigurationService (policy, gates, agents, adapters)
|
|
135
|
+
├── IndexRepository (index read/write, atomic updates)
|
|
136
|
+
├── StateRepository (state read/write, locks)
|
|
137
|
+
├── SchemaRegistry (validation)
|
|
138
|
+
├── ToolRouter (dispatch to services)
|
|
139
|
+
└── Services (existing 15 services)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## 4. Detailed Refactoring Plan
|
|
145
|
+
|
|
146
|
+
### 4.1 Phase 1: Extract Configuration Management
|
|
147
|
+
|
|
148
|
+
#### 4.1.1 Create ConfigurationService
|
|
149
|
+
|
|
150
|
+
**File:** `apps/control-plane/src/core/configuration-service.ts`
|
|
151
|
+
|
|
152
|
+
**Responsibilities:**
|
|
153
|
+
|
|
154
|
+
- Load and merge policy.yaml with defaults
|
|
155
|
+
- Load gates.yaml
|
|
156
|
+
- Load agents.yaml
|
|
157
|
+
- Load adapters.yaml
|
|
158
|
+
- Validate all configurations
|
|
159
|
+
- Provide immutable snapshots
|
|
160
|
+
|
|
161
|
+
**Interface:**
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
export interface ConfigurationServicePort {
|
|
165
|
+
repoRoot: string;
|
|
166
|
+
schemaRegistry: SchemaRegistry;
|
|
167
|
+
configOverrides: KernelConfigOverrides;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export class ConfigurationService {
|
|
171
|
+
constructor(port: ConfigurationServicePort);
|
|
172
|
+
|
|
173
|
+
async loadAll(): Promise<void>;
|
|
174
|
+
getPolicySnapshot(): PolicyConfigSnapshot;
|
|
175
|
+
getGatesConfig(): AnyRecord;
|
|
176
|
+
getAgentsConfig(): AgentsConfigSnapshot;
|
|
177
|
+
getAdaptersConfig(): Record<string, unknown>;
|
|
178
|
+
isLoaded(): boolean;
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
**Lines extracted:** ~200 lines from kernel.load()
|
|
183
|
+
|
|
184
|
+
#### 4.1.2 Update Kernel
|
|
185
|
+
|
|
186
|
+
Remove from kernel:
|
|
187
|
+
|
|
188
|
+
- Policy loading logic
|
|
189
|
+
- Gates loading logic
|
|
190
|
+
- Agents loading logic
|
|
191
|
+
- Adapters loading logic
|
|
192
|
+
|
|
193
|
+
Add to kernel:
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
private readonly configService: ConfigurationService;
|
|
197
|
+
|
|
198
|
+
async load() {
|
|
199
|
+
await this.configService.loadAll();
|
|
200
|
+
this.policy = this.configService.getPolicySnapshot();
|
|
201
|
+
this.gatesConfig = this.configService.getGatesConfig();
|
|
202
|
+
this.agentsConfig = this.configService.getAgentsConfig();
|
|
203
|
+
this.adaptersConfig = this.configService.getAdaptersConfig();
|
|
204
|
+
this.loaded = true;
|
|
205
|
+
}
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
**Benefit:** Kernel.load() reduced from ~90 lines to ~10 lines
|
|
209
|
+
|
|
210
|
+
### 4.2 Phase 2: Extract Core Repositories
|
|
211
|
+
|
|
212
|
+
#### 4.2.1 Create IndexRepository
|
|
213
|
+
|
|
214
|
+
**File:** `apps/control-plane/src/infrastructure/index-repository.ts`
|
|
215
|
+
|
|
216
|
+
**Responsibilities:**
|
|
217
|
+
|
|
218
|
+
- Read/write index.json atomically
|
|
219
|
+
- Provide index locking
|
|
220
|
+
- Handle index schema validation
|
|
221
|
+
- Manage index file path
|
|
222
|
+
|
|
223
|
+
**Interface:**
|
|
224
|
+
|
|
225
|
+
```typescript
|
|
226
|
+
export interface IndexRepositoryPort {
|
|
227
|
+
repoRoot: string;
|
|
228
|
+
instanceId: string;
|
|
229
|
+
schemaRegistry: SchemaRegistry;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export class IndexRepository {
|
|
233
|
+
constructor(port: IndexRepositoryPort);
|
|
234
|
+
|
|
235
|
+
async read(): Promise<AnyRecord>;
|
|
236
|
+
async write(index: AnyRecord): Promise<void>;
|
|
237
|
+
async withLock<T>(operation: () => Promise<T>): Promise<T>;
|
|
238
|
+
getPath(): string;
|
|
239
|
+
}
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
**Lines extracted:** ~150 lines
|
|
243
|
+
|
|
244
|
+
**Methods moved from kernel:**
|
|
245
|
+
|
|
246
|
+
- `readIndex()`
|
|
247
|
+
- `writeIndex()`
|
|
248
|
+
- `withIndexLock()`
|
|
249
|
+
- Index file path logic
|
|
250
|
+
|
|
251
|
+
#### 4.2.2 Create StateRepository
|
|
252
|
+
|
|
253
|
+
**File:** `apps/control-plane/src/infrastructure/state-repository.ts`
|
|
254
|
+
|
|
255
|
+
**Responsibilities:**
|
|
256
|
+
|
|
257
|
+
- Read/write state.md files
|
|
258
|
+
- Parse YAML frontmatter
|
|
259
|
+
- Provide feature-level locking
|
|
260
|
+
- Handle state schema validation
|
|
261
|
+
|
|
262
|
+
**Interface:**
|
|
263
|
+
|
|
264
|
+
```typescript
|
|
265
|
+
export interface StateRepositoryPort {
|
|
266
|
+
repoRoot: string;
|
|
267
|
+
schemaRegistry: SchemaRegistry;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export class StateRepository {
|
|
271
|
+
constructor(port: StateRepositoryPort);
|
|
272
|
+
|
|
273
|
+
async read(featureId: string): Promise<{ frontMatter: AnyRecord; body: string }>;
|
|
274
|
+
async write(featureId: string, frontMatter: AnyRecord, body: string): Promise<void>;
|
|
275
|
+
async withLock<T>(featureId: string, operation: () => Promise<T>): Promise<T>;
|
|
276
|
+
getPath(featureId: string): string;
|
|
277
|
+
}
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
**Lines extracted:** ~150 lines
|
|
281
|
+
|
|
282
|
+
**Methods moved from kernel:**
|
|
283
|
+
|
|
284
|
+
- `readState()`
|
|
285
|
+
- `writeState()`
|
|
286
|
+
- `withFeatureLock()`
|
|
287
|
+
- State file path logic
|
|
288
|
+
- YAML parsing logic
|
|
289
|
+
|
|
290
|
+
#### 4.2.3 Update Services
|
|
291
|
+
|
|
292
|
+
All services currently depend on kernel port interfaces. Update them to depend on repositories:
|
|
293
|
+
|
|
294
|
+
**Before:**
|
|
295
|
+
|
|
296
|
+
```typescript
|
|
297
|
+
export interface PlanServicePort {
|
|
298
|
+
readIndex(): Promise<AnyRecord>;
|
|
299
|
+
writeIndex(index: AnyRecord): Promise<void>;
|
|
300
|
+
withIndexLock<T>(operation: () => Promise<T>): Promise<T>;
|
|
301
|
+
readState(featureId: string): Promise<StateReadResult>;
|
|
302
|
+
// ... 10 more methods
|
|
303
|
+
}
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
**After:**
|
|
307
|
+
|
|
308
|
+
```typescript
|
|
309
|
+
export interface PlanServicePort {
|
|
310
|
+
indexRepository: IndexRepository;
|
|
311
|
+
stateRepository: StateRepository;
|
|
312
|
+
getPolicySnapshot(): AnyRecord;
|
|
313
|
+
planPath(featureId: string): string;
|
|
314
|
+
// ... only domain-specific methods
|
|
315
|
+
}
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
**Benefit:** Port interfaces reduced by 50%, clearer separation of concerns
|
|
319
|
+
|
|
320
|
+
---
|
|
321
|
+
|
|
322
|
+
### 4.3 Phase 3: Simplify Tool Routing
|
|
323
|
+
|
|
324
|
+
#### 4.3.1 Current State
|
|
325
|
+
|
|
326
|
+
Kernel has 67 tool methods that look like:
|
|
327
|
+
|
|
328
|
+
```typescript
|
|
329
|
+
async featureInit(featureId) {
|
|
330
|
+
return await this.featureLifecycleService.featureInit(featureId);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
async planSubmit(featureId, plan, expectedVersion) {
|
|
334
|
+
return await this.planService.planSubmit(featureId, plan, expectedVersion);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
async gatesRun(featureId, profileName, mode) {
|
|
338
|
+
return await this.gateService.gatesRun(featureId, profileName, mode);
|
|
339
|
+
}
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
**Issue:** 67 methods × 3 lines = 200+ lines of pure delegation
|
|
343
|
+
|
|
344
|
+
#### 4.3.2 Refactored Approach
|
|
345
|
+
|
|
346
|
+
**Option A: Direct Service Access (Recommended)**
|
|
347
|
+
|
|
348
|
+
Remove delegation methods entirely. Update ToolRouter to call services directly:
|
|
349
|
+
|
|
350
|
+
```typescript
|
|
351
|
+
// In ToolRouter
|
|
352
|
+
async executeTool(toolName: string, args: AnyRecord, context: ToolContext) {
|
|
353
|
+
const handler = this.handlers.get(toolName);
|
|
354
|
+
if (!handler) {
|
|
355
|
+
throw new Error(`Unknown tool: ${toolName}`);
|
|
356
|
+
}
|
|
357
|
+
return await handler.execute(args, context);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// Tool handlers access services directly
|
|
361
|
+
class PlanSubmitHandler implements ToolHandler {
|
|
362
|
+
constructor(private planService: PlanService) {}
|
|
363
|
+
|
|
364
|
+
async execute(args: AnyRecord, context: ToolContext) {
|
|
365
|
+
return await this.planService.planSubmit(
|
|
366
|
+
args.feature_id,
|
|
367
|
+
args.plan_json,
|
|
368
|
+
args.expected_version
|
|
369
|
+
);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
**Benefit:** Eliminates 200+ lines of delegation code
|
|
375
|
+
|
|
376
|
+
**Option B: Service Registry**
|
|
377
|
+
|
|
378
|
+
Keep kernel as service locator:
|
|
379
|
+
|
|
380
|
+
```typescript
|
|
381
|
+
class AopKernel {
|
|
382
|
+
getService<T>(serviceName: string): T {
|
|
383
|
+
return this.services.get(serviceName) as T;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// Tool handlers get services from kernel
|
|
388
|
+
const planService = kernel.getService<PlanService>('plan');
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
**Recommendation:** Use Option A for cleaner architecture
|
|
392
|
+
|
|
393
|
+
#### 4.3.3 Update Tool Handlers
|
|
394
|
+
|
|
395
|
+
Move tool handlers from inline kernel methods to dedicated handler classes:
|
|
396
|
+
|
|
397
|
+
**File:** `apps/control-plane/src/application/tools/handlers/`
|
|
398
|
+
|
|
399
|
+
```
|
|
400
|
+
handlers/
|
|
401
|
+
├── feature-init-handler.ts
|
|
402
|
+
├── plan-submit-handler.ts
|
|
403
|
+
├── gates-run-handler.ts
|
|
404
|
+
├── locks-acquire-handler.ts
|
|
405
|
+
├── merge-ready-handler.ts
|
|
406
|
+
└── ... (33 total handlers)
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
Each handler:
|
|
410
|
+
|
|
411
|
+
- Implements `ToolHandler` interface
|
|
412
|
+
- Depends on specific services it needs
|
|
413
|
+
- Contains tool-specific validation and orchestration
|
|
414
|
+
|
|
415
|
+
**Lines extracted:** ~400 lines of tool orchestration logic
|
|
416
|
+
|
|
417
|
+
---
|
|
418
|
+
|
|
419
|
+
### 4.4 Phase 4: Extract Utility Functions
|
|
420
|
+
|
|
421
|
+
#### 4.4.1 Create Utility Modules
|
|
422
|
+
|
|
423
|
+
**File:** `apps/control-plane/src/core/utils/path-utils.ts`
|
|
424
|
+
|
|
425
|
+
```typescript
|
|
426
|
+
export function normalizeRepoPathForState(repoRoot: string, absolutePath: string): string;
|
|
427
|
+
export function normalizeFromWorktree(
|
|
428
|
+
repoRoot: string,
|
|
429
|
+
worktreePath: string,
|
|
430
|
+
relativePath: string,
|
|
431
|
+
): string;
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
**File:** `apps/control-plane/src/core/utils/field-readers.ts`
|
|
435
|
+
|
|
436
|
+
```typescript
|
|
437
|
+
export function readStringField(record: AnyRecord, key: string): string | null;
|
|
438
|
+
export function readNumberField(record: AnyRecord, key: string): number | null;
|
|
439
|
+
export function readBooleanField(record: AnyRecord, key: string): boolean | null;
|
|
440
|
+
export function readObjectField(record: AnyRecord, key: string): AnyRecord;
|
|
441
|
+
export function asArray<T>(value: unknown): T[];
|
|
442
|
+
export function normalizeSet(array: string[]): string[];
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
**Lines extracted:** ~100 lines
|
|
446
|
+
|
|
447
|
+
---
|
|
448
|
+
|
|
449
|
+
### 4.5 Phase 5: Final Kernel Structure
|
|
450
|
+
|
|
451
|
+
#### 4.5.1 Target Kernel Class
|
|
452
|
+
|
|
453
|
+
**File:** `apps/control-plane/src/core/kernel.ts` (< 500 lines)
|
|
454
|
+
|
|
455
|
+
```typescript
|
|
456
|
+
export class AopKernel {
|
|
457
|
+
// Core dependencies
|
|
458
|
+
repoRoot: string;
|
|
459
|
+
instanceId: string;
|
|
460
|
+
|
|
461
|
+
// Infrastructure
|
|
462
|
+
private readonly configService: ConfigurationService;
|
|
463
|
+
private readonly indexRepository: IndexRepository;
|
|
464
|
+
private readonly stateRepository: StateRepository;
|
|
465
|
+
schemaRegistry: SchemaRegistry;
|
|
466
|
+
|
|
467
|
+
// Tool infrastructure
|
|
468
|
+
toolRegistry: AnyRecord | null;
|
|
469
|
+
toolHandlers: ToolHandlerRegistry;
|
|
470
|
+
toolRouter: ToolRouter;
|
|
471
|
+
|
|
472
|
+
// Services (unchanged)
|
|
473
|
+
private readonly runLeaseService: RunLeaseService;
|
|
474
|
+
private readonly lockService: LockService;
|
|
475
|
+
// ... (15 services)
|
|
476
|
+
|
|
477
|
+
// Public API
|
|
478
|
+
constructor(repoRoot: string, instanceId: string, configOverrides: KernelConfigOverrides);
|
|
479
|
+
async load(): Promise<void>;
|
|
480
|
+
async ensureLoaded(): Promise<void>;
|
|
481
|
+
async invoke(toolName: string, args: AnyRecord, context: ToolContext): Promise<ToolResponse>;
|
|
482
|
+
|
|
483
|
+
// Configuration access
|
|
484
|
+
getPolicySnapshot(): PolicyConfigSnapshot;
|
|
485
|
+
getGatesConfig(): AnyRecord;
|
|
486
|
+
getAgentsConfig(): AgentsConfigSnapshot;
|
|
487
|
+
|
|
488
|
+
// Repository access (for services)
|
|
489
|
+
getIndexRepository(): IndexRepository;
|
|
490
|
+
getStateRepository(): StateRepository;
|
|
491
|
+
|
|
492
|
+
// Provider management
|
|
493
|
+
setProvider(provider: WorkerProvider): void;
|
|
494
|
+
getProvider(): WorkerProvider | null;
|
|
495
|
+
|
|
496
|
+
// Recovery
|
|
497
|
+
async recoverFromState(): Promise<RecoveryResult>;
|
|
498
|
+
}
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
**Total lines:** ~450 lines
|
|
502
|
+
|
|
503
|
+
**Breakdown:**
|
|
504
|
+
|
|
505
|
+
- Imports and types: ~50 lines
|
|
506
|
+
- Constructor and initialization: ~100 lines
|
|
507
|
+
- Service instantiation: ~100 lines
|
|
508
|
+
- Public API methods: ~50 lines
|
|
509
|
+
- Configuration/repository access: ~50 lines
|
|
510
|
+
- Recovery logic: ~100 lines
|
|
511
|
+
|
|
512
|
+
---
|
|
513
|
+
|
|
514
|
+
## 5. Implementation Plan
|
|
515
|
+
|
|
516
|
+
### 5.1 Week 1: Configuration and Repositories
|
|
517
|
+
|
|
518
|
+
**Day 1-2: ConfigurationService**
|
|
519
|
+
|
|
520
|
+
- Create `ConfigurationService` class
|
|
521
|
+
- Extract policy loading logic
|
|
522
|
+
- Extract gates/agents/adapters loading
|
|
523
|
+
- Add tests
|
|
524
|
+
- Update kernel to use ConfigurationService
|
|
525
|
+
|
|
526
|
+
**Day 3-4: IndexRepository**
|
|
527
|
+
|
|
528
|
+
- Create `IndexRepository` class
|
|
529
|
+
- Extract index read/write/lock logic
|
|
530
|
+
- Add tests
|
|
531
|
+
- Update services to use IndexRepository
|
|
532
|
+
|
|
533
|
+
**Day 5: StateRepository**
|
|
534
|
+
|
|
535
|
+
- Create `StateRepository` class
|
|
536
|
+
- Extract state read/write/lock logic
|
|
537
|
+
- Add tests
|
|
538
|
+
- Update services to use StateRepository
|
|
539
|
+
|
|
540
|
+
**Verification:**
|
|
541
|
+
|
|
542
|
+
- All tests pass
|
|
543
|
+
- Kernel reduced to ~1200 lines
|
|
544
|
+
- No behavior changes
|
|
545
|
+
|
|
546
|
+
### 5.2 Week 2: Tool Routing and Cleanup
|
|
547
|
+
|
|
548
|
+
**Day 1-2: Tool Handler Extraction**
|
|
549
|
+
|
|
550
|
+
- Create handler classes for all 33 tools
|
|
551
|
+
- Update ToolRouter to use handlers
|
|
552
|
+
- Remove delegation methods from kernel
|
|
553
|
+
|
|
554
|
+
**Day 3: Utility Extraction**
|
|
555
|
+
|
|
556
|
+
- Move utility functions to separate modules
|
|
557
|
+
- Update imports across codebase
|
|
558
|
+
|
|
559
|
+
**Day 4: Service Port Updates**
|
|
560
|
+
|
|
561
|
+
- Update all service port interfaces
|
|
562
|
+
- Remove redundant methods
|
|
563
|
+
- Simplify dependencies
|
|
564
|
+
|
|
565
|
+
**Day 5: Final Cleanup and Verification**
|
|
566
|
+
|
|
567
|
+
- Remove dead code
|
|
568
|
+
- Optimize imports
|
|
569
|
+
- Run full test suite
|
|
570
|
+
- Performance benchmarks
|
|
571
|
+
- Documentation updates
|
|
572
|
+
|
|
573
|
+
**Verification:**
|
|
574
|
+
|
|
575
|
+
- Kernel < 500 lines
|
|
576
|
+
- All tests pass
|
|
577
|
+
- Performance within ±5%
|
|
578
|
+
- Zero lint warnings
|
|
579
|
+
|
|
580
|
+
---
|
|
581
|
+
|
|
582
|
+
## 6. Testing Strategy
|
|
583
|
+
|
|
584
|
+
### 6.1 Unit Tests
|
|
585
|
+
|
|
586
|
+
**New Tests Required:**
|
|
587
|
+
|
|
588
|
+
1. **ConfigurationService**
|
|
589
|
+
- Policy loading and merging
|
|
590
|
+
- Gates/agents/adapters loading
|
|
591
|
+
- Validation failures
|
|
592
|
+
- Config overrides
|
|
593
|
+
|
|
594
|
+
2. **IndexRepository**
|
|
595
|
+
- Atomic read/write
|
|
596
|
+
- Lock acquisition
|
|
597
|
+
- Concurrent access
|
|
598
|
+
- Schema validation
|
|
599
|
+
|
|
600
|
+
3. **StateRepository**
|
|
601
|
+
- YAML parsing
|
|
602
|
+
- Feature-level locking
|
|
603
|
+
- Concurrent updates
|
|
604
|
+
- Version conflicts
|
|
605
|
+
|
|
606
|
+
4. **Tool Handlers**
|
|
607
|
+
- Each handler's execute method
|
|
608
|
+
- Argument validation
|
|
609
|
+
- Error handling
|
|
610
|
+
- Service orchestration
|
|
611
|
+
|
|
612
|
+
**Coverage Target:** ≥90% for all new classes
|
|
613
|
+
|
|
614
|
+
### 6.2 Integration Tests
|
|
615
|
+
|
|
616
|
+
**Existing Tests Must Pass:**
|
|
617
|
+
|
|
618
|
+
- All kernel tests in `apps/control-plane/test/kernel.spec.ts`
|
|
619
|
+
- All tool runtime tests
|
|
620
|
+
- All supervisor tests
|
|
621
|
+
- All CLI tests
|
|
622
|
+
|
|
623
|
+
**New Integration Tests:**
|
|
624
|
+
|
|
625
|
+
- End-to-end tool execution through new architecture
|
|
626
|
+
- Multi-feature parallel execution
|
|
627
|
+
- Recovery scenarios
|
|
628
|
+
- Lock contention scenarios
|
|
629
|
+
|
|
630
|
+
### 6.3 Performance Tests
|
|
631
|
+
|
|
632
|
+
**Benchmarks:**
|
|
633
|
+
|
|
634
|
+
- Tool invocation latency (must be within ±5%)
|
|
635
|
+
- Feature initialization time
|
|
636
|
+
- Gate execution time
|
|
637
|
+
- Index/state read/write time
|
|
638
|
+
|
|
639
|
+
**Load Tests:**
|
|
640
|
+
|
|
641
|
+
- 5 features in parallel
|
|
642
|
+
- 100 tool invocations
|
|
643
|
+
- Lock contention under load
|
|
644
|
+
|
|
645
|
+
---
|
|
646
|
+
|
|
647
|
+
## 7. Migration Path
|
|
648
|
+
|
|
649
|
+
### 7.1 Backward Compatibility
|
|
650
|
+
|
|
651
|
+
**Guaranteed:**
|
|
652
|
+
|
|
653
|
+
- All tool contracts unchanged
|
|
654
|
+
- All error codes unchanged
|
|
655
|
+
- All CLI commands unchanged
|
|
656
|
+
- All file formats unchanged
|
|
657
|
+
- All schemas unchanged
|
|
658
|
+
|
|
659
|
+
**Internal Changes Only:**
|
|
660
|
+
|
|
661
|
+
- Service instantiation
|
|
662
|
+
- Port interfaces
|
|
663
|
+
- Internal method signatures
|
|
664
|
+
|
|
665
|
+
### 7.2 Rollback Plan
|
|
666
|
+
|
|
667
|
+
**If Issues Arise:**
|
|
668
|
+
|
|
669
|
+
1. **Immediate:** Revert to previous kernel implementation
|
|
670
|
+
2. **Short-term:** Fix issues in new architecture
|
|
671
|
+
3. **Long-term:** Complete migration with fixes
|
|
672
|
+
|
|
673
|
+
**Rollback Triggers:**
|
|
674
|
+
|
|
675
|
+
- Test failures >5%
|
|
676
|
+
- Performance degradation >10%
|
|
677
|
+
- Production incidents
|
|
678
|
+
- Unresolvable bugs
|
|
679
|
+
|
|
680
|
+
---
|
|
681
|
+
|
|
682
|
+
## 8. Success Metrics
|
|
683
|
+
|
|
684
|
+
### 8.1 Quantitative Metrics
|
|
685
|
+
|
|
686
|
+
- ✅ Kernel lines: 1768 → <500 (70% reduction)
|
|
687
|
+
- ✅ Cyclomatic complexity: Reduced by 60%
|
|
688
|
+
- ✅ Service coupling: Reduced by 50%
|
|
689
|
+
- ✅ Test coverage: Maintained at ≥90%
|
|
690
|
+
- ✅ Performance: Within ±5% of baseline
|
|
691
|
+
|
|
692
|
+
### 8.2 Qualitative Metrics
|
|
693
|
+
|
|
694
|
+
- ✅ Code readability improved
|
|
695
|
+
- ✅ Service responsibilities clear
|
|
696
|
+
- ✅ Easier to add new tools
|
|
697
|
+
- ✅ Easier to modify services
|
|
698
|
+
- ✅ Better error messages
|
|
699
|
+
- ✅ Improved documentation
|
|
700
|
+
|
|
701
|
+
---
|
|
702
|
+
|
|
703
|
+
## 9. Risks and Mitigation
|
|
704
|
+
|
|
705
|
+
### 9.1 Risks
|
|
706
|
+
|
|
707
|
+
**High Risk:**
|
|
708
|
+
|
|
709
|
+
- Breaking existing tool contracts
|
|
710
|
+
- Performance degradation
|
|
711
|
+
- Test failures
|
|
712
|
+
|
|
713
|
+
**Medium Risk:**
|
|
714
|
+
|
|
715
|
+
- Increased complexity in service wiring
|
|
716
|
+
- Circular dependencies between services
|
|
717
|
+
- Configuration loading order issues
|
|
718
|
+
|
|
719
|
+
**Low Risk:**
|
|
720
|
+
|
|
721
|
+
- Documentation gaps
|
|
722
|
+
- Migration time overruns
|
|
723
|
+
|
|
724
|
+
### 9.2 Mitigation Strategies
|
|
725
|
+
|
|
726
|
+
**For Breaking Changes:**
|
|
727
|
+
|
|
728
|
+
- Comprehensive integration tests before merge
|
|
729
|
+
- Staged rollout with feature flags
|
|
730
|
+
- Immediate rollback capability
|
|
731
|
+
|
|
732
|
+
**For Performance:**
|
|
733
|
+
|
|
734
|
+
- Benchmark before/after
|
|
735
|
+
- Profile hot paths
|
|
736
|
+
- Optimize critical sections
|
|
737
|
+
|
|
738
|
+
**For Complexity:**
|
|
739
|
+
|
|
740
|
+
- Clear dependency graphs
|
|
741
|
+
- Explicit initialization order
|
|
742
|
+
- Dependency injection container
|
|
743
|
+
|
|
744
|
+
---
|
|
745
|
+
|
|
746
|
+
## 10. Acceptance Criteria
|
|
747
|
+
|
|
748
|
+
### 10.1 Must Pass
|
|
749
|
+
|
|
750
|
+
- [ ] Kernel class <500 lines
|
|
751
|
+
- [ ] All 67 tool methods delegated or removed
|
|
752
|
+
- [ ] ConfigurationService extracted and tested
|
|
753
|
+
- [ ] IndexRepository extracted and tested
|
|
754
|
+
- [ ] StateRepository extracted and tested
|
|
755
|
+
- [ ] All tool handlers extracted
|
|
756
|
+
- [ ] All utility functions extracted
|
|
757
|
+
- [ ] All existing tests pass
|
|
758
|
+
- [ ] `npm run typecheck` passes
|
|
759
|
+
- [ ] `npm run lint` passes with 0 warnings
|
|
760
|
+
- [ ] Performance within ±5% of baseline
|
|
761
|
+
- [ ] Test coverage ≥90%
|
|
762
|
+
|
|
763
|
+
### 10.2 Documentation
|
|
764
|
+
|
|
765
|
+
- [ ] Architecture diagram updated
|
|
766
|
+
- [ ] Service responsibilities documented
|
|
767
|
+
- [ ] Port interfaces documented
|
|
768
|
+
- [ ] Migration guide created
|
|
769
|
+
- [ ] CLAUDE.md updated
|
|
770
|
+
- [ ] README.md updated
|
|
771
|
+
|
|
772
|
+
---
|
|
773
|
+
|
|
774
|
+
## 11. References
|
|
775
|
+
|
|
776
|
+
### 11.1 Related Documents
|
|
777
|
+
|
|
778
|
+
- `CLAUDE.md` - Architecture patterns and principles
|
|
779
|
+
- `ARCHITECTURE_ADHERENCE_ANALYSIS.md` - Current state analysis
|
|
780
|
+
- `spec-files/completed/agentic_orchestrator_oop_refactor_spec.md` - OOP refactor spec
|
|
781
|
+
- `prompts/agentic-documentation-guide.instructions.md` - Documentation standards
|
|
782
|
+
|
|
783
|
+
### 11.2 Related Code
|
|
784
|
+
|
|
785
|
+
- `apps/control-plane/src/core/kernel.ts` - Current kernel (1768 lines)
|
|
786
|
+
- `apps/control-plane/src/application/services/` - Existing services (24 files)
|
|
787
|
+
- `apps/control-plane/src/application/tools/` - Tool infrastructure
|
|
788
|
+
- `apps/control-plane/test/kernel.spec.ts` - Kernel tests
|
|
789
|
+
|
|
790
|
+
---
|
|
791
|
+
|
|
792
|
+
## 12. Appendix
|
|
793
|
+
|
|
794
|
+
### 12.1 Current Kernel Method Inventory
|
|
795
|
+
|
|
796
|
+
**Configuration (5 methods):**
|
|
797
|
+
|
|
798
|
+
- `load()`, `ensureLoaded()`, `getPolicySnapshot()`, `getGatesConfig()`, `getAgentsConfig()`
|
|
799
|
+
|
|
800
|
+
**Tool Routing (67 methods):**
|
|
801
|
+
|
|
802
|
+
- All tool delegation methods (feature._, plan._, gates._, locks._, etc.)
|
|
803
|
+
|
|
804
|
+
**Infrastructure (10 methods):**
|
|
805
|
+
|
|
806
|
+
- `readIndex()`, `writeIndex()`, `withIndexLock()`
|
|
807
|
+
- `readState()`, `writeState()`, `withFeatureLock()`
|
|
808
|
+
- `validateSchema()`, `readRunLease()`, `writeRunLease()`
|
|
809
|
+
|
|
810
|
+
**Utility (8 methods):**
|
|
811
|
+
|
|
812
|
+
- Path normalization, field readers, array helpers
|
|
813
|
+
|
|
814
|
+
**Total:** 90 methods
|
|
815
|
+
|
|
816
|
+
### 12.2 Target Kernel Method Inventory
|
|
817
|
+
|
|
818
|
+
**Public API (10 methods):**
|
|
819
|
+
|
|
820
|
+
- `constructor()`, `load()`, `ensureLoaded()`, `invoke()`
|
|
821
|
+
- `getPolicySnapshot()`, `getGatesConfig()`, `getAgentsConfig()`
|
|
822
|
+
- `getIndexRepository()`, `getStateRepository()`
|
|
823
|
+
- `setProvider()`, `getProvider()`
|
|
824
|
+
|
|
825
|
+
**Internal (5 methods):**
|
|
826
|
+
|
|
827
|
+
- Service instantiation helpers
|
|
828
|
+
- Recovery logic
|
|
829
|
+
|
|
830
|
+
**Total:** 15 methods (83% reduction)
|
|
831
|
+
|
|
832
|
+
---
|
|
833
|
+
|
|
834
|
+
**End of Specification**
|