@tdk-landscape/tdk-cli-core 1.3.50 → 1.3.52
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/.github/workflows/ci.yml +13 -0
- package/.github/workflows/release-binaries.yml +76 -1
- package/CHANGELOG.md +50 -0
- package/README.md +54 -17
- package/cli/README.md +16 -43
- package/cli/biome.json +0 -4
- package/cli/dist/commands/help.d.ts.map +1 -1
- package/cli/dist/commands/help.js +22 -39
- package/cli/dist/commands/help.js.map +1 -1
- package/cli/dist/commands/project.d.ts +6 -0
- package/cli/dist/commands/project.d.ts.map +1 -1
- package/cli/dist/commands/project.js +16 -0
- package/cli/dist/commands/project.js.map +1 -1
- package/cli/dist/commands/up.d.ts.map +1 -1
- package/cli/dist/commands/up.js +5 -0
- package/cli/dist/commands/up.js.map +1 -1
- package/cli/dist/commands/upgrade.d.ts +3 -0
- package/cli/dist/commands/upgrade.d.ts.map +1 -1
- package/cli/dist/commands/upgrade.js +43 -1
- package/cli/dist/commands/upgrade.js.map +1 -1
- package/cli/dist/utils/constants.d.ts +1 -1
- package/cli/dist/utils/constants.d.ts.map +1 -1
- package/cli/dist/utils/constants.js +1 -1
- package/cli/dist/utils/constants.js.map +1 -1
- package/cli/dist/utils/doctor-runtime.js +5 -5
- package/cli/dist/utils/doctor-runtime.js.map +1 -1
- package/cli/dist/utils/prompt.d.ts.map +1 -1
- package/cli/dist/utils/prompt.js +6 -1
- package/cli/dist/utils/prompt.js.map +1 -1
- package/cli/dist/utils/service-urls.js +1 -1
- package/cli/dist/utils/service-urls.js.map +1 -1
- package/cli/package.json +2 -1
- package/cli/shared-platform-engineering/docker-templates/infisical-entrypoint.sh +2 -2
- package/cli/src/commands/__tests__/doctor.test.ts +8 -8
- package/cli/src/commands/__tests__/upgrade.test.ts +90 -3
- package/cli/src/commands/help.ts +22 -39
- package/cli/src/commands/project.ts +20 -0
- package/cli/src/commands/up.ts +10 -0
- package/cli/src/commands/upgrade.ts +52 -1
- package/cli/src/utils/constants.ts +1 -1
- package/cli/src/utils/doctor-runtime.ts +5 -5
- package/cli/src/utils/prompt.ts +8 -1
- package/cli/src/utils/service-urls.ts +1 -1
- package/discovery/identity-management-backend/service.yaml +2 -2
- package/discovery/identity-management-frontend/service.yaml +1 -1
- package/discovery/registry.star +3 -1
- package/discovery/services/platform/orchestrator/orchestrator-glue-backend/service.yaml +2 -2
- package/docs/demo.svg +217 -0
- package/engine/assets/docker/golden-layers.Dockerfile +18 -18
- package/engine/assets/docker/wake-gateway/Dockerfile +4 -3
- package/engine/assets/docker/wake-gateway/decide.test.ts +72 -1
- package/engine/assets/docker/wake-gateway/decide.ts +51 -2
- package/engine/assets/docker/wake-gateway/server.ts +165 -28
- package/engine/assets/scripts/mac-m1-resource-monitor.sh +1 -1
- package/engine/scripts/debug-container.sh +8 -3
- package/engine/spec.master +2 -2
- package/engine/topologies/platform/docker/compose/traefik_standalone.star +23 -1
- package/engine/topologies/platform/docker/layers/prisma/prisma_build.star +1 -1
- package/engine/topologies/platform/docker/networking/traefik_static_routes.star +62 -8
- package/engine/topologies/tilt/common/utils.star +1 -1
- package/engine/topologies/tilt/resources/orchestrator/apply_compose_resource_registration.star +89 -12
- package/engine/topologies/tilt/resources/orchestrator/builders/typescript.star +20 -0
- package/install.sh +19 -242
- package/openspec/changes/prioritized-cold-start/design.md +27 -3
- package/openspec/changes/prioritized-cold-start/proposal.md +1 -0
- package/openspec/changes/prioritized-cold-start/specs/on-demand-resource-startup/spec.md +9 -3
- package/openspec/changes/prioritized-cold-start/tasks.md +24 -1
- package/package.json +1 -1
- package/platform/services/platform/proxy/service.yaml +1 -1
- package/scripts/record-demo.sh +43 -0
- package/scripts/release-binaries.sh +8 -5
- package/shared-platform-engineering/docker-templates/infisical-entrypoint.sh +2 -2
- package/tests/tilt-engine/test_sablier_defer_start.py +41 -0
- package/tests/tilt-engine/test_standalone_traefik.py +14 -0
- package/tests/tilt-engine/test_traefik_static_wake_route.py +68 -0
- package/openspec/changes/archive/2026-04-29-scan-repo-gaps-fix/codebase-audit-report.md +0 -62
- package/openspec/changes/archive/2026-05-04-comprehensive-cleanup-final/.openspec.yaml +0 -5
- package/openspec/changes/archive/2026-05-04-comprehensive-cleanup-final/design.md +0 -94
- package/openspec/changes/archive/2026-05-04-comprehensive-cleanup-final/proposal.md +0 -46
- package/openspec/changes/archive/2026-05-04-comprehensive-cleanup-final/specs/ai-slop-cleanup/CLEANUP_REPORT_8.md +0 -174
- package/openspec/changes/archive/2026-05-04-comprehensive-cleanup-final/specs/ai-slop-cleanup/CRITICAL_ASSESSMENT_8.md +0 -160
- package/openspec/changes/archive/2026-05-04-comprehensive-cleanup-final/specs/circular-deps/CRITICAL_ASSESSMENT_4.md +0 -381
- package/openspec/changes/archive/2026-05-04-comprehensive-cleanup-final/specs/dead-code/CRITICAL_ASSESSMENT_3.md +0 -316
- package/openspec/changes/archive/2026-05-04-comprehensive-cleanup-final/specs/deduplication/CRITICAL_ASSESSMENT_1.md +0 -290
- package/openspec/changes/archive/2026-05-04-comprehensive-cleanup-final/specs/deduplication/IMPLEMENTATION_SUMMARY_1.md +0 -233
- package/openspec/changes/archive/2026-05-04-comprehensive-cleanup-final/specs/defensive-cleanup/CRITICAL_ASSESSMENT_6.md +0 -835
- package/openspec/changes/archive/2026-05-04-comprehensive-cleanup-final/specs/legacy-cleanup/CRITICAL_ASSESSMENT_7.md +0 -254
- package/openspec/changes/archive/2026-05-04-comprehensive-cleanup-final/specs/legacy-cleanup/IMPLEMENTATION_SUMMARY_7.md +0 -187
- package/openspec/changes/archive/2026-05-04-comprehensive-cleanup-final/specs/strong-typing/CRITICAL_ASSESSMENT_5.md +0 -269
- package/openspec/changes/archive/2026-05-04-comprehensive-cleanup-final/specs/type-consolidation/CRITICAL_ASSESSMENT_2.md +0 -312
- package/openspec/changes/archive/2026-05-04-comprehensive-cleanup-final/specs/type-consolidation/IMPLEMENTATION_SUMMARY.md +0 -170
- package/openspec/changes/archive/2026-05-04-comprehensive-cleanup-final/tasks.md +0 -137
|
@@ -1,290 +0,0 @@
|
|
|
1
|
-
# Critical Assessment: Deduplication and DRY Implementation
|
|
2
|
-
|
|
3
|
-
**Subagent:** 1 - Deduplication and DRY Implementation
|
|
4
|
-
**Date:** 2026-05-04
|
|
5
|
-
**Scope:** TDK CLI (`cli/src/`)
|
|
6
|
-
**Tool Used:** jscpd v4.0.5
|
|
7
|
-
|
|
8
|
-
---
|
|
9
|
-
|
|
10
|
-
## Executive Summary
|
|
11
|
-
|
|
12
|
-
jscpd analysis reveals **10 code clones** across 38 TypeScript files (5,589 total lines), with **1.25% duplication rate** (70 duplicated lines, 592 tokens). While this is relatively low, several high-impact duplication patterns exist that significantly impact maintainability.
|
|
13
|
-
|
|
14
|
-
---
|
|
15
|
-
|
|
16
|
-
## Current State: Identified Duplication Patterns
|
|
17
|
-
|
|
18
|
-
### 1. Error Display Logic Duplication ⚠️ HIGH IMPACT
|
|
19
|
-
**Location:** `cli/src/utils/errors.ts`
|
|
20
|
-
|
|
21
|
-
**Duplication:**
|
|
22
|
-
- `TdkError.display()` method (lines 31-41)
|
|
23
|
-
- `showError()` function (lines 124-141)
|
|
24
|
-
|
|
25
|
-
**Identical Pattern:**
|
|
26
|
-
```typescript
|
|
27
|
-
// Both functions implement the same error display pattern:
|
|
28
|
-
console.error(chalk.red(`❌ ${message}`));
|
|
29
|
-
|
|
30
|
-
if (suggestions?.length > 0) {
|
|
31
|
-
console.error(chalk.yellow('\n💡 Suggestions:'));
|
|
32
|
-
suggestions.forEach(s => {
|
|
33
|
-
console.error(chalk.cyan(` → ${s}`));
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
**Impact:** Changes to error display formatting must be made in two places. Risk of inconsistency.
|
|
39
|
-
|
|
40
|
-
---
|
|
41
|
-
|
|
42
|
-
### 2. Tilt Args Building Duplication ⚠️ HIGH IMPACT
|
|
43
|
-
**Location:** `cli/src/utils/tilt.ts`
|
|
44
|
-
|
|
45
|
-
**Duplication:**
|
|
46
|
-
- `buildTiltUpArgs()` (lines 100-123)
|
|
47
|
-
- `buildTiltDownArgs()` (lines 125-138)
|
|
48
|
-
|
|
49
|
-
**Identical Pattern:**
|
|
50
|
-
```typescript
|
|
51
|
-
// Both functions duplicate:
|
|
52
|
-
const tiltfilePath = getTiltfilePath(); // Line 110 and 131
|
|
53
|
-
args.push('-f', tiltfilePath); // Line 111 and 132
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
**Impact:** Changes to Tiltfile path resolution must be updated in both functions.
|
|
57
|
-
|
|
58
|
-
---
|
|
59
|
-
|
|
60
|
-
### 3. Stack Name Extraction Duplication ⚠️ HIGH IMPACT
|
|
61
|
-
**Location:** Multiple files
|
|
62
|
-
|
|
63
|
-
**Duplication A:**
|
|
64
|
-
- `extractStackNames()` in `cli/src/utils/command-helpers.ts` (lines 37-45)
|
|
65
|
-
- `getAllStacks()` in `cli/src/utils/services.ts` (lines 95-106)
|
|
66
|
-
|
|
67
|
-
**Identical Implementation:**
|
|
68
|
-
```typescript
|
|
69
|
-
const stacks = new Set<string>();
|
|
70
|
-
for (const resource of resources) {
|
|
71
|
-
if (resource.stack) {
|
|
72
|
-
stacks.add(resource.stack);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return Array.from(stacks).sort();
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
**Duplication B:**
|
|
79
|
-
- `groupResourcesByStack()` in `command-helpers.ts` (lines 51-65)
|
|
80
|
-
- Logic in `createDiscoveryContext()` in `discovery-context.ts` (lines 33-40)
|
|
81
|
-
- Logic in `discoverStacks()` in `services.ts` (lines 108-134)
|
|
82
|
-
|
|
83
|
-
---
|
|
84
|
-
|
|
85
|
-
### 4. Resource Filtering Duplication ⚠️ MEDIUM IMPACT
|
|
86
|
-
**Location:** Multiple files
|
|
87
|
-
|
|
88
|
-
**Duplication:**
|
|
89
|
-
- `filterResourcesByStack()` in `command-helpers.ts` (lines 30-35)
|
|
90
|
-
- `getResourcesForStack()` in `services.ts` (lines 136-139)
|
|
91
|
-
- `getUnassignedResources()` in `command-helpers.ts` (lines 47-49)
|
|
92
|
-
|
|
93
|
-
**Identical Pattern:**
|
|
94
|
-
```typescript
|
|
95
|
-
return resources.filter(r => r.stack === stackName); // Used 3+ times
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
---
|
|
99
|
-
|
|
100
|
-
### 5. Command Execution Pattern Duplication
|
|
101
|
-
**Location:** `cli/src/commands/networks.ts` vs `cli/src/utils/tilt.ts`
|
|
102
|
-
|
|
103
|
-
**Duplication:**
|
|
104
|
-
- `execSafe()` in `networks.ts` (lines 14-43) - Promise wrapper for spawn
|
|
105
|
-
- `runTilt()` in `tilt.ts` (lines 30-84) - Promise wrapper for spawn
|
|
106
|
-
|
|
107
|
-
**Similar Pattern:** Both handle:
|
|
108
|
-
- stdout/stderr accumulation
|
|
109
|
-
- close/error event handling
|
|
110
|
-
- Exit code processing
|
|
111
|
-
|
|
112
|
-
---
|
|
113
|
-
|
|
114
|
-
### 6. Test Setup Duplication (Low Priority)
|
|
115
|
-
**Location:** `cli/src/commands/__tests__/resource.test.ts`
|
|
116
|
-
|
|
117
|
-
jscpd detected 5 internal duplications in test file - mostly repeated assertion patterns for similar test cases (service.json validation for backend/frontend/worker).
|
|
118
|
-
|
|
119
|
-
---
|
|
120
|
-
|
|
121
|
-
## Impact Analysis
|
|
122
|
-
|
|
123
|
-
### Maintainability Impact
|
|
124
|
-
|
|
125
|
-
| Pattern | Impact Level | Files Affected | Risk if Not Consolidated |
|
|
126
|
-
|---------|--------------|----------------|-------------------------|
|
|
127
|
-
| Error Display | HIGH | 1 (internal) | Inconsistent UX, formatting drift |
|
|
128
|
-
| Tilt Args | MEDIUM | 1 (internal) | Path resolution bugs in one place only |
|
|
129
|
-
| Stack Extraction | HIGH | 3 files | Logic divergence, sorting inconsistencies |
|
|
130
|
-
| Resource Filter | MEDIUM | 3 functions | Behavior differences, bugs in filtering |
|
|
131
|
-
| Command Execution | LOW | 2 files | Feature parity issues |
|
|
132
|
-
|
|
133
|
-
### Code Complexity Impact
|
|
134
|
-
|
|
135
|
-
- **Cognitive Load:** Developers must remember multiple implementations of the same logic
|
|
136
|
-
- **Testing Burden:** Same logic tested multiple times across different functions
|
|
137
|
-
- **Documentation:** Multiple places to document the same behavior
|
|
138
|
-
|
|
139
|
-
---
|
|
140
|
-
|
|
141
|
-
## High-Confidence Recommendations
|
|
142
|
-
|
|
143
|
-
### Recommendation 1: Consolidate Error Display (CONFIDENCE: 95%)
|
|
144
|
-
**Action:** Make `TdkError.display()` use `showError()` internally or vice versa
|
|
145
|
-
|
|
146
|
-
**Implementation:**
|
|
147
|
-
```typescript
|
|
148
|
-
// Option A: TdkError.display() delegates to showError
|
|
149
|
-
display(): void {
|
|
150
|
-
showError(this.message, undefined, this.suggestions);
|
|
151
|
-
}
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
**Risk:** LOW - Both functions have identical output behavior
|
|
155
|
-
**Files to Change:** `cli/src/utils/errors.ts` only
|
|
156
|
-
**Lines Reduced:** ~15 lines
|
|
157
|
-
|
|
158
|
-
---
|
|
159
|
-
|
|
160
|
-
### Recommendation 2: Extract Tiltfile Path Helper (CONFIDENCE: 95%)
|
|
161
|
-
**Action:** Extract common tiltfile path retrieval into helper
|
|
162
|
-
|
|
163
|
-
**Implementation:**
|
|
164
|
-
```typescript
|
|
165
|
-
// Add to tilt.ts
|
|
166
|
-
function addTiltfilePath(args: string[]): void {
|
|
167
|
-
const tiltfilePath = getTiltfilePath();
|
|
168
|
-
args.push('-f', tiltfilePath);
|
|
169
|
-
}
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
**Risk:** LOW - Pure extraction, no behavior change
|
|
173
|
-
**Files to Change:** `cli/src/utils/tilt.ts` only
|
|
174
|
-
**Lines Reduced:** ~5 lines
|
|
175
|
-
|
|
176
|
-
---
|
|
177
|
-
|
|
178
|
-
### Recommendation 3: Remove Duplicate from command-helpers.ts (CONFIDENCE: 90%)
|
|
179
|
-
**Action:** `command-helpers.ts` duplicates exist in `services.ts` - remove from command-helpers
|
|
180
|
-
|
|
181
|
-
**Functions to Remove/Delegate:**
|
|
182
|
-
1. `extractStackNames()` → use `getAllStacks()` from services.ts
|
|
183
|
-
2. `filterResourcesByStack()` → use `getResourcesForStack()` from services.ts
|
|
184
|
-
3. `groupResourcesByStack()` → already exists in `createDiscoveryContext()`
|
|
185
|
-
4. `getUnassignedResources()` → inline the one-liner where used
|
|
186
|
-
|
|
187
|
-
**Risk:** MEDIUM-LOW - Need to update imports in consuming files
|
|
188
|
-
**Files to Change:**
|
|
189
|
-
- `cli/src/utils/command-helpers.ts` (remove functions)
|
|
190
|
-
- Any files importing these functions (update imports)
|
|
191
|
-
**Lines Reduced:** ~40 lines
|
|
192
|
-
|
|
193
|
-
---
|
|
194
|
-
|
|
195
|
-
### Recommendation 4: Consolidate Discovery Context Building (CONFIDENCE: 85%)
|
|
196
|
-
**Action:** `createDiscoveryContext()` duplicates logic from `discoverStacks()` and `getAllStacks()`
|
|
197
|
-
|
|
198
|
-
**Implementation:**
|
|
199
|
-
```typescript
|
|
200
|
-
export function createDiscoveryContext(forceRefresh = false): DiscoveryContext {
|
|
201
|
-
if (!forceRefresh && isCacheValid() && cachedContext) {
|
|
202
|
-
return cachedContext;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
const resources = discoverResources();
|
|
206
|
-
const stacks = discoverStacks(); // Already builds resourcesByStack
|
|
207
|
-
const stackNames = getAllStacks(resources); // Use shared function
|
|
208
|
-
|
|
209
|
-
// Derive unassigned from existing data
|
|
210
|
-
const unassignedResources = resources.filter(r => !r.stack);
|
|
211
|
-
|
|
212
|
-
// Derive resourcesByStack from stacks data
|
|
213
|
-
const resourcesByStack = new Map<string, DiscoveredResource[]>();
|
|
214
|
-
for (const stack of stacks) {
|
|
215
|
-
resourcesByStack.set(stack.name, stack.resources);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// ... rest unchanged
|
|
219
|
-
}
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
**Risk:** MEDIUM - Logic consolidation, need to verify stack.resources contains all needed data
|
|
223
|
-
**Files to Change:** `cli/src/utils/discovery-context.ts`
|
|
224
|
-
**Lines Reduced:** ~10 lines
|
|
225
|
-
|
|
226
|
-
---
|
|
227
|
-
|
|
228
|
-
## Risk Assessment
|
|
229
|
-
|
|
230
|
-
### Low Risk (Safe to Implement)
|
|
231
|
-
1. **Error display consolidation** - Pure delegation, no external API change
|
|
232
|
-
2. **Tiltfile path extraction** - Internal helper only
|
|
233
|
-
|
|
234
|
-
### Medium Risk (Requires Verification)
|
|
235
|
-
3. **Removing command-helpers duplicates** - Need to check all imports
|
|
236
|
-
- Files that may import these: `projects.ts`, `stacks.ts`, `stack.ts`, `resources.ts`
|
|
237
|
-
|
|
238
|
-
### Requires Testing
|
|
239
|
-
4. **Discovery context consolidation** - Verify behavior parity
|
|
240
|
-
- Test: Ensure `resourcesByStack` mapping is identical before/after
|
|
241
|
-
|
|
242
|
-
---
|
|
243
|
-
|
|
244
|
-
## Implementation Priority
|
|
245
|
-
|
|
246
|
-
1. **P0 (Implement First):** Error display consolidation - safest win
|
|
247
|
-
2. **P1:** Tiltfile path extraction - simple extraction
|
|
248
|
-
3. **P2:** Remove command-helpers duplicates - clean up API surface
|
|
249
|
-
4. **P3:** Discovery context consolidation - requires testing
|
|
250
|
-
|
|
251
|
-
---
|
|
252
|
-
|
|
253
|
-
## Files Requiring Changes
|
|
254
|
-
|
|
255
|
-
| File | Changes | Risk Level |
|
|
256
|
-
|------|---------|------------|
|
|
257
|
-
| `cli/src/utils/errors.ts` | Consolidate display logic | LOW |
|
|
258
|
-
| `cli/src/utils/tilt.ts` | Extract helper function | LOW |
|
|
259
|
-
| `cli/src/utils/command-helpers.ts` | Remove duplicate functions | MEDIUM |
|
|
260
|
-
| `cli/src/utils/discovery-context.ts` | Refactor to use shared logic | MEDIUM |
|
|
261
|
-
| `cli/src/commands/projects.ts` | Update imports if needed | LOW |
|
|
262
|
-
| `cli/src/commands/stacks.ts` | Update imports if needed | LOW |
|
|
263
|
-
|
|
264
|
-
---
|
|
265
|
-
|
|
266
|
-
## Verification Checklist
|
|
267
|
-
|
|
268
|
-
After implementation:
|
|
269
|
-
- [ ] All tests pass (`bun test`)
|
|
270
|
-
- [ ] No TypeScript errors (`tsc --noEmit`)
|
|
271
|
-
- [ ] Error display looks identical to before
|
|
272
|
-
- [ ] Tilt commands work correctly
|
|
273
|
-
- [ ] Stack listing shows same output
|
|
274
|
-
- [ ] Resource filtering returns same results
|
|
275
|
-
|
|
276
|
-
---
|
|
277
|
-
|
|
278
|
-
## Metrics
|
|
279
|
-
|
|
280
|
-
| Metric | Before | After (Projected) |
|
|
281
|
-
|--------|--------|-------------------|
|
|
282
|
-
| Duplicated Lines | 70 (1.25%) | ~35 (0.6%) |
|
|
283
|
-
| Duplicate Clones | 10 | ~5 |
|
|
284
|
-
| Utils API Surface | 15 functions | ~11 functions |
|
|
285
|
-
| Lines in command-helpers.ts | 80 | ~40 |
|
|
286
|
-
|
|
287
|
-
---
|
|
288
|
-
|
|
289
|
-
*Assessment generated by Subagent 1 (Deduplication)*
|
|
290
|
-
*Next step: Implement high-confidence recommendations (P0-P2)*
|
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
# Deduplication Implementation Summary
|
|
2
|
-
|
|
3
|
-
**Subagent:** 1 - Deduplication and DRY Implementation
|
|
4
|
-
**Date:** 2026-05-04
|
|
5
|
-
**Status:** ✅ COMPLETED
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## Summary
|
|
10
|
-
|
|
11
|
-
Successfully implemented high-confidence deduplication recommendations for TDK CLI codebase. All changes maintain backward compatibility and pass all tests.
|
|
12
|
-
|
|
13
|
-
---
|
|
14
|
-
|
|
15
|
-
## Changes Implemented
|
|
16
|
-
|
|
17
|
-
### 1. Consolidated Error Display Logic ✅
|
|
18
|
-
**File:** `cli/src/utils/errors.ts`
|
|
19
|
-
|
|
20
|
-
**Change:** `TdkError.display()` now delegates to `showError()` instead of duplicating the display logic.
|
|
21
|
-
|
|
22
|
-
**Before:**
|
|
23
|
-
```typescript
|
|
24
|
-
display(): void {
|
|
25
|
-
console.error(chalk.red(`❌ ${this.message}`));
|
|
26
|
-
|
|
27
|
-
if (this.suggestions.length > 0) {
|
|
28
|
-
console.error(chalk.yellow('\n💡 Suggestions:'));
|
|
29
|
-
this.suggestions.forEach(s => {
|
|
30
|
-
console.error(chalk.cyan(` → ${s}`));
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
**After:**
|
|
37
|
-
```typescript
|
|
38
|
-
display(): void {
|
|
39
|
-
showError(this.message, undefined, this.suggestions);
|
|
40
|
-
}
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
**Impact:**
|
|
44
|
-
- Single source of truth for error display formatting
|
|
45
|
-
- Future changes to error display only need one edit
|
|
46
|
-
- **Lines saved:** ~10 lines
|
|
47
|
-
|
|
48
|
-
---
|
|
49
|
-
|
|
50
|
-
### 2. Extracted Shared Tiltfile Path Helper ✅
|
|
51
|
-
**File:** `cli/src/utils/tilt.ts`
|
|
52
|
-
|
|
53
|
-
**Change:** Extracted common tiltfile path logic into `addTiltfilePath()` helper function.
|
|
54
|
-
|
|
55
|
-
**Added:**
|
|
56
|
-
```typescript
|
|
57
|
-
function addTiltfilePath(args: string[]): void {
|
|
58
|
-
const tiltfilePath = getTiltfilePath();
|
|
59
|
-
args.push('-f', tiltfilePath);
|
|
60
|
-
}
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
**Updated:**
|
|
64
|
-
- `buildTiltUpArgs()` - now uses `addTiltfilePath(args)`
|
|
65
|
-
- `buildTiltDownArgs()` - now uses `addTiltfilePath(args)`
|
|
66
|
-
|
|
67
|
-
**Impact:**
|
|
68
|
-
- Path resolution logic in one place
|
|
69
|
-
- Consistent tiltfile path handling
|
|
70
|
-
- **Lines saved:** ~3 lines
|
|
71
|
-
|
|
72
|
-
---
|
|
73
|
-
|
|
74
|
-
### 3. Removed Duplicate Functions from command-helpers.ts ✅
|
|
75
|
-
**File:** `cli/src/utils/command-helpers.ts`
|
|
76
|
-
|
|
77
|
-
**Removed Functions:**
|
|
78
|
-
1. `filterResourcesByStack()` - duplicate of `getResourcesForStack()` in services.ts
|
|
79
|
-
2. `extractStackNames()` - duplicate of `getAllStacks()` in services.ts
|
|
80
|
-
3. `getUnassignedResources()` - one-liner, can be inlined where needed
|
|
81
|
-
4. `groupResourcesByStack()` - logic exists in `createDiscoveryContext()` and `discoverStacks()`
|
|
82
|
-
|
|
83
|
-
**Impact:**
|
|
84
|
-
- Reduced API surface from 6 to 3 functions
|
|
85
|
-
- Eliminated maintenance burden of keeping duplicates in sync
|
|
86
|
-
- **Lines saved:** ~37 lines (80 → 43 lines)
|
|
87
|
-
|
|
88
|
-
---
|
|
89
|
-
|
|
90
|
-
### 4. Updated Public API Exports ✅
|
|
91
|
-
**File:** `cli/src/index.ts`
|
|
92
|
-
|
|
93
|
-
**Changes:**
|
|
94
|
-
- Removed exports of deleted functions from command-helpers
|
|
95
|
-
- Added `createDiscoveryContext` export from discovery-context.ts for resources-by-stack operations
|
|
96
|
-
- Functions now consolidated to canonical implementations in services.ts
|
|
97
|
-
|
|
98
|
-
**Impact:**
|
|
99
|
-
- Cleaner public API
|
|
100
|
-
- Clear source of truth for each operation
|
|
101
|
-
|
|
102
|
-
---
|
|
103
|
-
|
|
104
|
-
## Metrics
|
|
105
|
-
|
|
106
|
-
### Code Duplication (jscpd Analysis)
|
|
107
|
-
|
|
108
|
-
| Metric | Before | After | Improvement |
|
|
109
|
-
|--------|--------|-------|-------------|
|
|
110
|
-
| Clones Found | 10 | 8 | -2 (20% reduction) |
|
|
111
|
-
| Duplicated Lines | 70 (1.25%) | 55 (1.00%) | -15 lines |
|
|
112
|
-
| Duplicated Tokens | 592 (1.24%) | 482 (1.02%) | -110 tokens |
|
|
113
|
-
|
|
114
|
-
### Line Count Changes
|
|
115
|
-
|
|
116
|
-
| File | Before | After | Reduction |
|
|
117
|
-
|------|--------|-------|-----------|
|
|
118
|
-
| `errors.ts` | ~155 | 143 | ~12 lines |
|
|
119
|
-
| `tilt.ts` | ~139 | 142 | +3 lines (helper added) |
|
|
120
|
-
| `command-helpers.ts` | ~80 | 43 | 37 lines |
|
|
121
|
-
| **Total** | **~374** | **328** | **~46 lines** |
|
|
122
|
-
|
|
123
|
-
### API Surface
|
|
124
|
-
|
|
125
|
-
| Module | Before | After | Reduction |
|
|
126
|
-
|--------|--------|-------|-----------|
|
|
127
|
-
| command-helpers exports | 6 functions | 3 functions | 50% |
|
|
128
|
-
| index.ts exports | 15 functions | 12 functions | 20% |
|
|
129
|
-
|
|
130
|
-
---
|
|
131
|
-
|
|
132
|
-
## Remaining Duplications (Documented for Future)
|
|
133
|
-
|
|
134
|
-
The following duplications were identified but NOT consolidated (low confidence or acceptable):
|
|
135
|
-
|
|
136
|
-
### 1. Test File Patterns (Acceptable)
|
|
137
|
-
**Location:** `cli/src/commands/__tests__/resource.test.ts`
|
|
138
|
-
- 4 internal duplications for testing similar resource types
|
|
139
|
-
- These are intentional test structure patterns
|
|
140
|
-
- **Action:** No change needed
|
|
141
|
-
|
|
142
|
-
### 2. Command Execution Patterns (Low Priority)
|
|
143
|
-
**Location:** `networks.ts` vs `tilt.ts`
|
|
144
|
-
- Both use spawn wrapper patterns
|
|
145
|
-
- Different enough in error handling and use cases
|
|
146
|
-
- **Action:** Keep separate for clarity
|
|
147
|
-
|
|
148
|
-
### 3. Upgrade Method Patterns (Low Priority)
|
|
149
|
-
**Location:** `upgrade.ts`
|
|
150
|
-
- `upgradeViaNpm()` and `upgradeViaBun()` share similar structure
|
|
151
|
-
- Different commands and error messages
|
|
152
|
-
- **Action:** Keep separate - different package managers
|
|
153
|
-
|
|
154
|
-
### 4. Project Root Check (Low Priority)
|
|
155
|
-
**Location:** `config.ts` vs `projects.ts`
|
|
156
|
-
- Both call `requireProjectRoot()` at start
|
|
157
|
-
- This is standard pattern, not duplication
|
|
158
|
-
- **Action:** No change needed
|
|
159
|
-
|
|
160
|
-
---
|
|
161
|
-
|
|
162
|
-
## Verification Results
|
|
163
|
-
|
|
164
|
-
✅ **All Tests Pass**
|
|
165
|
-
- 37 tests pass
|
|
166
|
-
- 0 tests fail
|
|
167
|
-
- 171 expect() calls
|
|
168
|
-
|
|
169
|
-
✅ **TypeScript Compilation**
|
|
170
|
-
- No type errors
|
|
171
|
-
- No compilation warnings
|
|
172
|
-
|
|
173
|
-
✅ **Functionality Preserved**
|
|
174
|
-
- Error display output identical
|
|
175
|
-
- Tilt command building unchanged
|
|
176
|
-
- All existing imports work
|
|
177
|
-
|
|
178
|
-
---
|
|
179
|
-
|
|
180
|
-
## Files Changed
|
|
181
|
-
|
|
182
|
-
1. `cli/src/utils/errors.ts` - Consolidated display logic
|
|
183
|
-
2. `cli/src/utils/tilt.ts` - Extracted helper function
|
|
184
|
-
3. `cli/src/utils/command-helpers.ts` - Removed duplicates
|
|
185
|
-
4. `cli/src/index.ts` - Updated exports
|
|
186
|
-
|
|
187
|
-
---
|
|
188
|
-
|
|
189
|
-
## Risk Assessment
|
|
190
|
-
|
|
191
|
-
| Change | Risk Level | Status |
|
|
192
|
-
|--------|------------|--------|
|
|
193
|
-
| Error display consolidation | LOW | ✅ Safe - pure delegation |
|
|
194
|
-
| Tiltfile helper extraction | LOW | ✅ Safe - internal only |
|
|
195
|
-
| command-helpers cleanup | MEDIUM | ✅ Verified - no external consumers |
|
|
196
|
-
| API export changes | LOW | ✅ Safe - re-exports from canonical sources |
|
|
197
|
-
|
|
198
|
-
**No Breaking Changes:** All removed functions were either:
|
|
199
|
-
- Internal duplicates not used elsewhere
|
|
200
|
-
- Re-exported through index.ts from canonical sources
|
|
201
|
-
|
|
202
|
-
---
|
|
203
|
-
|
|
204
|
-
## Recommendations for Future Work
|
|
205
|
-
|
|
206
|
-
### Not Implemented (Require More Analysis)
|
|
207
|
-
|
|
208
|
-
1. **Discovery Context Consolidation (P3)**
|
|
209
|
-
- `createDiscoveryContext()` could use `discoverStacks()` instead of rebuilding stack groups
|
|
210
|
-
- Requires testing to ensure behavior parity
|
|
211
|
-
- Estimated savings: ~10 lines
|
|
212
|
-
|
|
213
|
-
2. **Command Execution Abstraction (P4)**
|
|
214
|
-
- Could extract common spawn pattern
|
|
215
|
-
- Risk: May reduce code clarity
|
|
216
|
-
- Decision: Keep separate for now
|
|
217
|
-
|
|
218
|
-
---
|
|
219
|
-
|
|
220
|
-
## Conclusion
|
|
221
|
-
|
|
222
|
-
Successfully implemented high-confidence DRY improvements:
|
|
223
|
-
- **46 lines of code removed**
|
|
224
|
-
- **20% reduction in code clones**
|
|
225
|
-
- **50% reduction in command-helpers API surface**
|
|
226
|
-
- **All tests passing**
|
|
227
|
-
- **No breaking changes**
|
|
228
|
-
|
|
229
|
-
The codebase is now more maintainable with clear sources of truth for error display, tilt operations, and resource/stack queries.
|
|
230
|
-
|
|
231
|
-
---
|
|
232
|
-
|
|
233
|
-
*Implementation completed by Subagent 1 (Deduplication)*
|