feat(cli): TypeScript refactor with modular architecture#10
feat(cli): TypeScript refactor with modular architecture#10therichardngai-wolf wants to merge 9 commits intotherichardngai-code:mainfrom
Conversation
Created CLI infrastructure: - src/cli/types.ts: All TypeScript interfaces - src/cli/api-client.ts: Type-safe HTTP client - src/cli/formatters/colors.ts: ANSI color helpers - src/cli/formatters/date.ts: Date formatting utilities - src/cli/formatters/table.ts: ASCII table formatter - src/cli/formatters/index.ts: Re-exports All files < 200 LOC, TypeScript strict mode compatible.
Added TypeScript command modules: - commands/task.ts: list, get, create, update - commands/session.ts: list, get - commands/server.ts: start (with legacy mode support) - commands/index.ts: re-exports - index.ts: CLI program setup and runner All files < 200 LOC, TypeScript strict mode compatible.
Added monitoring command modules: - commands/approval.ts: list, get, approve, reject - commands/watch.ts: real-time session monitoring - commands/status.ts: server status overview All files < 200 LOC, TypeScript strict mode compatible.
Added advanced command modules: - commands/hook.ts: list, provision, unprovision, sync - commands/agent.ts: list, get - commands/project.ts: list, get, create, update, delete - commands/data.ts: export, import All files < 200 LOC, TypeScript strict mode compatible.
Updated bin/cli.js to use compiled TypeScript CLI. All commands now available via 'npx notecode [command]'. Commands available: - server start - task list/get/create/update - session list/get - approval list/get/approve/reject - watch, status - hook list/provision/unprovision/sync - agent list/get - project list/get/create/update/delete - export/import
Fixed isLegacyInvocation() to recognize export/import commands, preventing them from triggering legacy server start mode.
Changed hook provision/unprovision to use PATCH /api/settings instead of non-existent /api/cli-hooks/approval-gate/provision endpoint. Enabling approvalGate in settings auto-provisions the hook. Disabling approvalGate auto-unprovisions the hook.
New command structure: - notecode approval-gate enable [--project <id>] [--timeout <s>] - notecode approval-gate disable [--project <id>] Removed from hook command: - hook provision (now: approval-gate enable) - hook unprovision (now: approval-gate disable) Kept in hook command: - hook list - hook sync
… create New options: - --permission-mode (default, acceptEdits, bypassPermissions) - --allow-tools (comma-separated allowlist) - --block-tools (comma-separated blocklist) - --provider (anthropic, google, openai) - --model (model name) - --skills (comma-separated) - --context-files (comma-separated paths)
therichardngai-code
left a comment
There was a problem hiding this comment.
Review: Request Changes
Good work converting to TypeScript and modular architecture — addresses all feedback from PR #2. However, 3 critical runtime issues found that must be fixed before merge.
🔴 Must Fix
1. Missing commander dependency
All command files import commander but it's not in any package.json (root or backend).
import { Command } from 'commander'; // Every command fileImpact: Runtime crash — ERR_MODULE_NOT_FOUND on any CLI invocation.
Fix: Add "commander": "^14.0.3" to backend/package.json dependencies.
2. Remove agent.ts command — endpoint doesn't exist
CLI calls GET /api/agents and GET /api/agents/:id, but no such endpoint exists in the backend.
The Agent entity exists in domain layer, but agents are only accessible via:
GET /api/projects/:projectId/discovery/agents
There is no standalone /api/agents controller.
Impact: notecode agent list and notecode agent get will always 404.
Fix: Remove agent.ts command entirely (YAGNI), or rewrite to use the correct project-scoped discovery endpoint.
3. Wrong endpoint path for import
CLI calls:
post(options.apiUrl, '/api/import', ...)But backend endpoint is:
app.post('/api/backup/import', ...) // backup.controller.ts:71Impact: notecode import <file> will always 404.
Fix: Change to /api/backup/import and verify request body matches what backup.controller.ts expects.
🟡 Should Fix
4. task.ts exceeds 200 LOC limit
backend/src/cli/commands/task.ts is 230 lines (project limit: < 200 LOC).
Fix: Split into smaller modules (e.g., task-list.ts + task-mutations.ts).
✅ What's Good
- TypeScript with proper type definitions ✅
- Modular architecture (18 files) ✅
- Inside
backend/src/cli/(correct location) ✅ - Formatters split under 200 LOC ✅
- Backward compatible server startup ✅
--jsonflag on all commands ✅
Please fix the 3 critical items and resubmit.
Summary
Refactored the NoteCode CLI from a single 1,046-line JavaScript file to a modular TypeScript architecture.
Changes
Architecture
Commands
notecode server startnotecode task list/get/create/updatenotecode session list/getnotecode approval list/get/approve/rejectnotecode approval-gate enable/disablenotecode hook list/syncnotecode project list/get/create/update/deletenotecode statusnotecode watchnotecode export/importTask Create Options
Full options now available:
--permission-mode(default, acceptEdits, bypassPermissions)--allow-tools/--block-tools--provider/--model--skills/--context-filesTesting