Skip to content

refactor: address technical debt with modularization and type safety#181

Merged
laynepenney merged 2 commits intomainfrom
refactor/technical-debt
Jan 26, 2026
Merged

refactor: address technical debt with modularization and type safety#181
laynepenney merged 2 commits intomainfrom
refactor/technical-debt

Conversation

@laynepenney
Copy link
Copy Markdown
Collaborator

Summary

Address technical debt in the Codi codebase with four improvements:

1. CLI Module Extraction (~400 lines from index.ts)

  • src/cli/history.ts - Command history management
  • src/cli/pipeline-input.ts - File/glob resolution with security validation
  • src/cli/non-interactive.ts - Single-prompt mode execution
  • src/cli/index.ts - Module re-exports

2. Workflow Type Safety

  • Add BaseWorkflowStep interface and WorkflowStep discriminated union
  • Add 9 type guards (isShellStep, isSwitchModelStep, isLoopStep, etc.)
  • Replace as any casts with proper type narrowing

3. Symbol Index Type Safety

  • Add hasExtendsMetadata type guard
  • Add SymbolMetadataWithExtends interface

4. E2E Test Stability

  • Add waitForOutputFlush() helper to ProcessHarness
  • Use generic patterns and clearOutput() for robustness

5. Plugin System Investigation

  • Create comprehensive docs/PLUGIN-INVESTIGATION.md
  • Security analysis and recommendations
  • API stability assessment
  • Phased re-enablement roadmap

6. Cleanup

  • Remove 62 generated workflow files

Metrics

  • Reduces as any usage from 30+ to 10 instances
  • Extracts ~400 lines from index.ts into focused modules

Test plan

  • pnpm build passes with 0 errors
  • pnpm test passes (2129 tests)
  • Verified workflow type guards work correctly
  • E2E tests stable (previously flaky /compact test now robust)

🤖 Generated with Claude Code

laynepenney and others added 2 commits January 26, 2026 12:58
- Extract ~400 lines from index.ts into src/cli/ modules:
  - history.ts: command history management
  - pipeline-input.ts: file/glob resolution
  - non-interactive.ts: single-prompt mode execution

- Improve workflow type safety with discriminated unions:
  - Add BaseWorkflowStep interface and WorkflowStep union type
  - Add type guards (isShellStep, isSwitchModelStep, etc.)
  - Replace `as any` casts with proper type narrowing

- Fix symbol-index metadata types:
  - Add hasExtendsMetadata type guard
  - Add SymbolMetadataWithExtends interface

- Fix flaky E2E test in commands.e2e.test.ts:
  - Add waitForOutputFlush helper to ProcessHarness
  - Use generic patterns and clearOutput() for robustness

- Create plugin system investigation document:
  - Security analysis and recommendations
  - API stability assessment
  - Phased re-enablement roadmap

Reduces `as any` usage from 30+ to 9 instances.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@laynepenney
Copy link
Copy Markdown
Collaborator Author

Self-Review

Verified

  • ✅ CI passes (Type Check, Ubuntu tests, macOS tests)
  • ✅ +1043/-1553 lines (mostly workflow cleanup deletions)
  • ✅ 78 files changed

Changes Reviewed

  1. CLI Modules - Properly extracted with security validation in pipeline-input.ts
  2. Workflow Type Safety - Discriminated union and type guards correctly implemented
  3. Symbol Index Types - hasExtendsMetadata type guard is correct
  4. E2E Test Fix - waitForOutputFlush and generic patterns for robustness
  5. Plugin Investigation - Comprehensive security analysis and roadmap
  6. Workflow Cleanup - 62 generated files removed

No issues found. Ready to merge.

@laynepenney laynepenney merged commit d3de40e into main Jan 26, 2026
3 checks passed
@laynepenney laynepenney deleted the refactor/technical-debt branch January 26, 2026 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant