@miller-tech/uap 1.5.0 → 1.5.3

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.
@@ -0,0 +1,320 @@
1
+ # Model Routing CLI Selection & UAP Compliance Analysis
2
+
3
+ ## Current Issues Identified
4
+
5
+ ### 1. Missing 'task' Role in Model Routing
6
+
7
+ **File**: `src/models/types.ts` (line 15)
8
+
9
+ ```typescript
10
+ export type ModelRole = 'planner' | 'executor' | 'reviewer' | 'fallback';
11
+ ```
12
+
13
+ The routing rules support `'task'` as a target role, but the type definition is missing this value.
14
+
15
+ ### 2. Null Issues in Router
16
+
17
+ **File**: `src/models/router.ts`
18
+
19
+ - Line 117: `preset` can be undefined when model preset doesn't exist
20
+ - Line 468: No fallback when executor model is not found
21
+ - Line 13: Import uses `ModelPresets` but no null check before access
22
+
23
+ ### 3. Missing CLI Command for Model Selection
24
+
25
+ **Current**: `uap model status`, `route`, `plan`, `compare` exist
26
+ **Missing**: Interactive CLI to select models per purpose at runtime
27
+
28
+ ---
29
+
30
+ ## UAP Compliance Correctness Analysis
31
+
32
+ ### Compliant Features ✅
33
+
34
+ 1. **Multi-model architecture types** - Properly defined in `types.ts`
35
+ 2. **Routing rules with priorities** - Implemented in `router.ts`
36
+ 3. **Task classification** - Complexity-based routing works correctly
37
+ 4. **Planner/Executor separation** - Implemented with validation
38
+ 5. **Cost estimation** - Built into router
39
+ 6. **Fallback mechanisms** - Present in all critical paths
40
+
41
+ ### Non-Compliant Features ❌
42
+
43
+ 1. **Missing 'task' role** - Type definition incomplete
44
+ 2. **No null safety** - Multiple undefined access patterns
45
+ 3. **Incomplete CLI** - No interactive model selection
46
+ 4. **TypeScript build issues** - May fail on missing presets
47
+ 5. **No validation for role assignments** - Can assign non-existent models to roles
48
+
49
+ ---
50
+
51
+ ## Performance Analysis
52
+
53
+ ### Current Implementation Performance
54
+
55
+ | Feature | Performance | Notes |
56
+ | ------------------- | ----------- | ------------------------------- |
57
+ | Task Classification | O(1) | Keyword matching is fast |
58
+ | Model Selection | O(n) | Iterates through routing rules |
59
+ | Plan Creation | O(n\*m) | n=subtasks, m=complexity levels |
60
+ | Routing Analysis | O(n) | Full rule evaluation |
61
+
62
+ ### Bottlenecks Identified
63
+
64
+ 1. **Routing rules iteration** - Can be optimized with indexing
65
+ 2. **Keyword matching** - Linear scan through all keywords
66
+ 3. **No caching** - Classification recalculated each time
67
+ 4. **Model lookup** - Map is efficient but presets initialization is synchronous
68
+
69
+ ---
70
+
71
+ ## Optimization Options
72
+
73
+ ### Option 1: Quick Fixes (Recommended for Immediate Use)
74
+
75
+ **Priority**: High | **Effort**: Low | **Impact**: Medium
76
+
77
+ #### A. Fix Missing 'task' Role
78
+
79
+ ```typescript
80
+ // src/models/types.ts line 15
81
+ export type ModelRole = 'planner' | 'executor' | 'reviewer' | 'fallback' | 'task';
82
+ ```
83
+
84
+ #### B. Add Null Safety to Router
85
+
86
+ ```typescript
87
+ // src/models/router.ts line 117-120
88
+ if (preset) {
89
+ this.models.set(modelDef, preset);
90
+ }
91
+ // Add check before accessing preset throughout
92
+ ```
93
+
94
+ #### C. Add Role Assignment Validation
95
+
96
+ ```typescript
97
+ // In ModelRouter constructor
98
+ private validateRoleAssignments(): void {
99
+ const roles = this.config.roles || {};
100
+ for (const [role, modelId] of Object.entries(roles)) {
101
+ if (!this.models.has(modelId)) {
102
+ console.warn(`Role ${role} assigned to non-existent model ${modelId}`);
103
+ }
104
+ }
105
+ }
106
+ ```
107
+
108
+ ### Option 2: CLI Enhancement (User-Friendly Selection)
109
+
110
+ **Priority**: High | **Effort**: Medium | **Impact**: High
111
+
112
+ #### A. Add Interactive Model Selector
113
+
114
+ ```typescript
115
+ // src/cli/model.ts - New command
116
+ program
117
+ .command('model:select')
118
+ .description('Interactively select models for each role')
119
+ .option('--planner <id>', 'Model ID for planning role')
120
+ .option('--executor <id>', 'Model ID for execution role')
121
+ .option('--reviewer <id>', 'Model ID for review role')
122
+ .option('--fallback <id>', 'Model ID for fallback role')
123
+ .option(
124
+ '--strategy <strategy>',
125
+ 'Routing strategy: balanced|cost-optimized|performance-first|adaptive'
126
+ )
127
+ .option('--save', 'Save configuration to .uap.json')
128
+ .action(async (options) => {
129
+ // Interactive selection logic
130
+ });
131
+ ```
132
+
133
+ #### B. Add Preset Browser
134
+
135
+ ```typescript
136
+ // Show available presets with details
137
+ uap model presets --verbose
138
+ ```
139
+
140
+ #### C. Add Configuration Export
141
+
142
+ ```typescript
143
+ // Export current config as JSON/YAML
144
+ uap model export --format json > model-config.json
145
+ ```
146
+
147
+ ### Option 3: Performance Optimizations
148
+
149
+ **Priority**: Medium | **Effort**: Medium | **Impact**: High
150
+
151
+ #### A. Add Classification Caching
152
+
153
+ ```typescript
154
+ class ModelRouter {
155
+ private classificationCache = new Map<string, TaskClassificationResult>();
156
+
157
+ classifyTask(taskDescription: string): TaskClassificationResult {
158
+ const cacheKey = taskDescription.toLowerCase().trim();
159
+ if (this.classificationCache.has(cacheKey)) {
160
+ return this.classificationCache.get(cacheKey)!;
161
+ }
162
+ // ... existing logic ...
163
+ const result = /* classification logic */;
164
+ this.classificationCache.set(cacheKey, result);
165
+ return result;
166
+ }
167
+ }
168
+ ```
169
+
170
+ #### B. Optimize Keyword Matching
171
+
172
+ ```typescript
173
+ // Pre-compile keyword patterns for faster matching
174
+ private complexityPatterns: Map<TaskComplexity, RegExp[]> = new Map();
175
+ private taskTypePatterns: Map<string, RegExp[]> = new Map();
176
+
177
+ private buildPatternIndex(): void {
178
+ for (const [level, keywords] of Object.entries(COMPLEXITY_KEYWORDS)) {
179
+ this.complexityPatterns.set(level as TaskComplexity,
180
+ keywords.map(kw => new RegExp(`\\b${kw}\\b`, 'i')));
181
+ }
182
+ }
183
+ ```
184
+
185
+ #### C. Add Routing Rule Indexing
186
+
187
+ ```typescript
188
+ // Group rules by condition for O(1) lookup
189
+ private complexityIndex: Map<TaskComplexity, RoutingRule[]> = new Map();
190
+ type TaskTypeIndex: Map<string, RoutingRule[]> = new Map();
191
+
192
+ private buildIndexes(): void {
193
+ for (const rule of this.routingRules) {
194
+ if (rule.complexity) {
195
+ const rules = this.complexityIndex.get(rule.complexity) || [];
196
+ rules.push(rule);
197
+ this.complexityIndex.set(rule.complexity, rules);
198
+ }
199
+ }
200
+ }
201
+ ```
202
+
203
+ ### Option 4: Enhanced Validation & Diagnostics
204
+
205
+ **Priority**: Medium | **Effort**: Low | **Impact**: Medium
206
+
207
+ #### A. Add Model Health Check
208
+
209
+ ```typescript
210
+ // src/cli/model.ts
211
+ async function healthCheckCommand(): Promise<void> {
212
+ const config = loadConfig();
213
+ const mmConfig = getMultiModelConfig(config);
214
+ const router = createRouter(mmConfig);
215
+
216
+ console.log('=== Model Health Check ===\n');
217
+
218
+ // Check all assigned models exist
219
+ const roles = mmConfig.roles || {};
220
+ let hasErrors = false;
221
+ for (const [role, modelId] of Object.entries(roles)) {
222
+ if (!router.getModel(modelId)) {
223
+ console.error(`❌ ${role}: Model '${modelId}' not found`);
224
+ hasErrors = true;
225
+ } else {
226
+ console.log(`✓ ${role}: ${modelId} (OK)`);
227
+ }
228
+ }
229
+
230
+ if (hasErrors) {
231
+ process.exitCode = 1;
232
+ }
233
+ }
234
+ ```
235
+
236
+ #### B. Add Configuration Diff
237
+
238
+ ```typescript
239
+ // Compare current config with defaults
240
+ uap model diff
241
+ ```
242
+
243
+ #### C. Add Simulation Mode
244
+
245
+ ```typescript
246
+ // Test routing without execution
247
+ uap model simulate --task "<task description>" --dry-run
248
+ ```
249
+
250
+ ---
251
+
252
+ ## Recommended Implementation Plan
253
+
254
+ ### Phase 1: Critical Fixes (1-2 hours)
255
+
256
+ 1. ✅ Fix missing 'task' role type definition
257
+ 2. ✅ Add null safety checks in router
258
+ 3. ✅ Add role assignment validation
259
+ 4. ✅ Run build to verify TypeScript compilation
260
+
261
+ ### Phase 2: CLI Enhancement (2-3 hours)
262
+
263
+ 1. ✅ Add `uap model select` interactive command
264
+ 2. ✅ Add `uap model presets` listing
265
+ 3. ✅ Add `uap model export` for config backup
266
+ 4. ✅ Add `uap model health` diagnostic
267
+
268
+ ### Phase 3: Performance (4-6 hours)
269
+
270
+ 1. ✅ Add classification caching
271
+ 2. ✅ Optimize keyword matching with precompiled patterns
272
+ 3. ✅ Index routing rules for faster lookup
273
+ 4. ✅ Benchmark before/after performance
274
+
275
+ ### Phase 4: Validation & Testing (2-3 hours)
276
+
277
+ 1. ✅ Add comprehensive unit tests for router
278
+ 2. ✅ Add integration tests for CLI commands
279
+ 3. ✅ Create sample configurations for testing
280
+ 4. ✅ Document all new commands
281
+
282
+ ---
283
+
284
+ ## Implementation Priority Matrix
285
+
286
+ | Task | Priority | Effort | Impact | Phase |
287
+ | ------------------------ | -------- | ------ | ------ | ----- |
288
+ | Fix 'task' role type | High | Low | High | 1 |
289
+ | Add null safety | High | Low | High | 1 |
290
+ | CLI interactive selector | High | Medium | High | 2 |
291
+ | Role validation | High | Low | Medium | 1 |
292
+ | Classification cache | Medium | Low | Medium | 3 |
293
+ | Keyword optimization | Medium | Medium | Low | 3 |
294
+ | Health check command | Medium | Low | Medium | 2 |
295
+ | Rule indexing | Medium | Medium | Medium | 3 |
296
+
297
+ ---
298
+
299
+ ## UAP Compliance Checklist
300
+
301
+ After implementation, verify:
302
+
303
+ - [ ] All model roles properly typed and validated
304
+ - [ ] No undefined/null access patterns in router
305
+ - [ ] CLI commands for model selection work interactively
306
+ - [ ] Build passes without errors
307
+ - [ ] All existing tests pass
308
+ - [ ] New commands documented in CLI help
309
+ - [ ] Performance improvements verified with benchmarks
310
+ - [ ] Configuration export/import works correctly
311
+
312
+ ---
313
+
314
+ ## Next Steps
315
+
316
+ 1. **Start with Phase 1** - Critical fixes to prevent runtime errors
317
+ 2. **Run `npm run build`** after each phase to verify compilation
318
+ 3. **Test with sample tasks** to verify routing correctness
319
+ 4. **Document changes** in CHANGELOG.md
320
+ 5. **Create migration guide** if breaking changes are introduced
@@ -0,0 +1,245 @@
1
+ # Policy Gate for Mandatory Testing & Deployment - Implementation Complete
2
+
3
+ ## Overview
4
+
5
+ This implementation adds a **mandatory policy gate** that enforces testing and deployment verification before any task can be marked as DONE, COMPLETE, or CLOSED.
6
+
7
+ ## What Was Implemented
8
+
9
+ ### 1. Policy File Created ✅
10
+
11
+ **File**: `src/policies/schemas/policies/mandatory-testing-deployment.md`
12
+
13
+ This policy defines rules for:
14
+
15
+ - Testing requirements before task completion
16
+ - Deployment verification for production changes
17
+ - Quality gate enforcement (lint, type-check, coverage)
18
+ - Documentation requirements
19
+
20
+ ### 2. Policy Gate Enhancement ✅
21
+
22
+ **File**: `src/policies/policy-gate.ts`
23
+
24
+ Added automatic detection and enforcement for task completion operations:
25
+
26
+ - Detects when operations involve: complete, done, finish, close, resolve, merge, deploy, release
27
+ - Forces review-stage policy checks during task completion
28
+ - Blocks completion if REQUIRED policies are violated
29
+ - Provides clear error messages explaining what's missing
30
+
31
+ **Key Method**: `isTaskCompletionOperation()`
32
+
33
+ ```typescript
34
+ private isTaskCompletionOperation(
35
+ operation: string,
36
+ args: Record<string, unknown>
37
+ ): boolean {
38
+ // Detects completion-related operations and forces review-stage enforcement
39
+ }
40
+ ```
41
+
42
+ ### 3. CLI Commands Added ✅
43
+
44
+ **File**: `src/cli/policy.ts`
45
+
46
+ New policy management commands:
47
+
48
+ ```bash
49
+ # List all policies
50
+ uap policy list
51
+
52
+ # Install a built-in policy
53
+ uap policy install mandatory-testing-deployment
54
+
55
+ # Enable a policy
56
+ uap policy enable <policy-id>
57
+
58
+ # Disable a policy
59
+ uap policy disable <policy-id>
60
+
61
+ # Show detailed policy status
62
+ uap policy status
63
+ ```
64
+
65
+ ### 4. Policy Installer Script ✅
66
+
67
+ **File**: `scripts/install-policy.ts`
68
+
69
+ One-command installation script:
70
+
71
+ ```bash
72
+ node scripts/install-policy.js # Install all mandatory policies
73
+ node scripts/install-policy.js mandatory-testing-deployment # Install specific policy
74
+ ```
75
+
76
+ ### 5. CLAUDE.md Updated ✅
77
+
78
+ **File**: `CLAUDE.md`
79
+
80
+ Added mandatory policy enforcement section to the Completion Gate:
81
+
82
+ - Lists all verification requirements
83
+ - Defines what NOT to do when marking tasks complete
84
+ - Provides commands to verify compliance
85
+
86
+ ### 6. CLI Registration ✅
87
+
88
+ **File**: `src/bin/cli.ts`
89
+
90
+ Registered policy commands in main CLI entry point.
91
+
92
+ ## How It Works
93
+
94
+ ### Policy Enforcement Flow
95
+
96
+ 1. **Task Completion Detected**
97
+ - When you use commands like `task close`, `task release`, or any operation containing "complete", "done", etc.
98
+ - The policy gate automatically detects this as a task completion operation
99
+
100
+ 2. **Review Stage Enforcement**
101
+ - Before allowing the operation to proceed, the policy gate checks all policies with enforcement stage `review`
102
+ - If the `mandatory-testing-deployment` policy is installed and active, it will be enforced
103
+
104
+ 3. **Policy Validation**
105
+ - The policy extracts rules from its markdown content
106
+ - Checks for anti-patterns like "skip test", "no coverage", etc.
107
+ - Blocks completion if violations are detected
108
+
109
+ 4. **Error Messages**
110
+ ```
111
+ Task completion blocked by policy: Mandatory Testing and Deployment Verification.
112
+ Reasons: [Mandatory Testing and Deployment Verification] Rule "Testing Requirement" violated: detected anti-pattern "incomplete test"
113
+ ```
114
+
115
+ ## Usage Examples
116
+
117
+ ### Install the Policy
118
+
119
+ ```bash
120
+ # Option 1: Use CLI command
121
+ uap policy install mandatory-testing-deployment
122
+
123
+ # Option 2: Use installer script
124
+ node scripts/install-policy.js
125
+ ```
126
+
127
+ ### Verify Installation
128
+
129
+ ```bash
130
+ uap policy list
131
+ ```
132
+
133
+ Expected output:
134
+
135
+ ```
136
+ === UAP Policy Status ===
137
+
138
+ Total Policies: 1
139
+
140
+ ✓ Mandatory Testing and Deployment Verification
141
+ Status: Enabled
142
+ Level: REQUIRED
143
+ Category: testing
144
+ Stage: review
145
+ Version: 1
146
+ ```
147
+
148
+ ### Test Enforcement
149
+
150
+ Try to close a task without completing required checks:
151
+
152
+ ```bash
153
+ uap task close <task-id>
154
+ ```
155
+
156
+ If the policy is enforced, you'll get an error message explaining what's missing.
157
+
158
+ ## Files Modified/Created
159
+
160
+ | File | Status | Description |
161
+ | --------------------------------------------------------------- | -------- | ------------------------------------------ |
162
+ | `src/policies/schemas/policies/mandatory-testing-deployment.md` | Created | Policy definition file |
163
+ | `src/policies/policy-gate.ts` | Modified | Added task completion detection |
164
+ | `src/cli/policy.ts` | Created | Policy management CLI commands |
165
+ | `scripts/install-policy.ts` | Created | One-command policy installer |
166
+ | `CLAUDE.md` | Modified | Added mandatory policy enforcement section |
167
+ | `src/bin/cli.ts` | Modified | Registered policy commands |
168
+
169
+ ## Build Verification
170
+
171
+ All changes compile successfully:
172
+
173
+ ```bash
174
+ $ npm run build
175
+ > @miller-tech/uap@1.5.0 build
176
+ > tsc
177
+ ```
178
+
179
+ No TypeScript errors or type mismatches.
180
+
181
+ ## Next Steps
182
+
183
+ ### 1. Install the Policy
184
+
185
+ ```bash
186
+ node scripts/install-policy.js
187
+ ```
188
+
189
+ ### 2. Verify Installation
190
+
191
+ ```bash
192
+ uap policy list
193
+ ```
194
+
195
+ ### 3. Test Enforcement
196
+
197
+ Try completing a task to verify the policy blocks incomplete work.
198
+
199
+ ### 4. Customize (Optional)
200
+
201
+ Edit `src/policies/schemas/policies/mandatory-testing-deployment.md` to add custom rules for your project.
202
+
203
+ ## Policy Rules Summary
204
+
205
+ The installed policy enforces these checks:
206
+
207
+ 1. **Testing Requirement**
208
+ - Keywords: done, complete, finish, close, resolve, merge
209
+ - Anti-patterns: incomplete test, no test coverage, untested code, skip test
210
+
211
+ 2. **Deployment Verification Required**
212
+ - Keywords: deploy, production, release, push, merge
213
+ - Anti-patterns: unverified deployment, no smoke test, deployment failed
214
+
215
+ 3. **Quality Gate Enforcement**
216
+ - Keywords: quality, lint, type-check, coverage, security
217
+ - Anti-patterns: disable lint, bypass type check, low coverage, security warning
218
+
219
+ 4. **Documentation Requirement**
220
+ - Keywords: document, readme, api, changelog, migration
221
+ - Anti-patterns: no documentation, missing changelog, undocumented change
222
+
223
+ ## Benefits
224
+
225
+ ✅ **Prevents incomplete work** from being marked as done
226
+ ✅ **Enforces quality standards** across all tasks
227
+ ✅ **Provides clear feedback** when requirements aren't met
228
+ ✅ **Automated enforcement** through policy gate system
229
+ ✅ **Easy to install** with one command
230
+ ✅ **Customizable** for project-specific needs
231
+
232
+ ## Compliance with UAP Protocol
233
+
234
+ This implementation follows the UAP protocol completion gate requirements:
235
+
236
+ - ✅ Testing verification required
237
+ - ✅ Build verification required
238
+ - ✅ Quality checks enforced
239
+ - ✅ Clear error messages provided
240
+ - ✅ Automated enforcement through policy system
241
+
242
+ ---
243
+
244
+ _Implementation Date: 2026-03-18_
245
+ _Status: Complete and Production Ready_
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miller-tech/uap",
3
- "version": "1.5.0",
3
+ "version": "1.5.3",
4
4
  "description": "Autonomous AI agent memory system with CLAUDE.md protocol enforcement",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -31,6 +31,9 @@
31
31
  "install:all": "bash scripts/install.sh",
32
32
  "install:cloakbrowser": "tsx scripts/install-cloakbrowser.ts",
33
33
  "postinstall": "echo '\n✨ Run: npx universal-agent-protocol init --interactive'",
34
+ "version:patch": "bash scripts/version-bump.sh patch",
35
+ "version:minor": "bash scripts/version-bump.sh minor",
36
+ "version:major": "bash scripts/version-bump.sh major",
34
37
  "update-uap": "bash scripts/update-uap-compliance.sh",
35
38
  "verify-uap": "bash scripts/verify-compliance.sh",
36
39
  "check-claude": "bash scripts/verify-compliance.sh"