Skip to content

Commit da13302

Browse files
committed
feat(lint): add lint command implementation
1 parent ed9fad2 commit da13302

17 files changed

Lines changed: 828 additions & 93 deletions

File tree

docs/ai/design/feature-lint-command.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,12 @@ graph TD
6464
- `ai-devkit lint --feature <name>`
6565
- `ai-devkit lint --feature <name> --json`
6666
- Internal interfaces
67-
- `runLint(options): Promise<number>`
68-
- `checkBaseDocs(cwd): Promise<LintCheckResult[]>`
69-
- `checkFeatureDocs(cwd, target): Promise<LintCheckResult[]>`
70-
- `checkFeatureWorktree(cwd, target): Promise<LintCheckResult[]>`
71-
- `renderLintOutput(summary, options): void`
67+
- `runLintChecks(options, dependencies?): LintReport`
68+
- `renderLintReport(report, options): void` (in `commands/lint`)
69+
- `normalizeFeatureName(input): string`
70+
- `isInsideGitWorkTreeSync(cwd): boolean`
71+
- `localBranchExistsSync(cwd, branchName): boolean`
72+
- `getWorktreePathsForBranchSync(cwd, branchName): string[]`
7273
- Request/response formats
7374
- Input: CLI flags and current working directory.
7475
- Output:
@@ -89,9 +90,10 @@ graph TD
8990
- JSON formatter for machine-readable mode.
9091
- Backend services/modules
9192
- `commands/lint` command entry.
92-
- `services/lint` for composable checks.
93-
- `utils/feature-name` normalization utility.
94-
- `utils/git` helpers for worktree checks.
93+
- `services/lint/lint.service.ts` for orchestration and business rules only.
94+
- `services/lint/rules/*` for modular validation rules (base docs, feature docs, feature-name, git worktree).
95+
- `util/git` sync helpers for git/worktree checks.
96+
- `util/terminal-ui` for consistent terminal output formatting.
9597
- Database/storage layer
9698
- None.
9799
- Third-party integrations
@@ -122,6 +124,7 @@ graph TD
122124
- Single-responsibility check modules.
123125
- Deterministic output for CI and humans.
124126
- Collect-all-results reporting to surface all issues in one run.
127+
- Avoid shell interpolation for git operations by using argument-based command execution.
125128

126129
## Non-Functional Requirements
127130
**How should the system perform?**

docs/ai/implementation/feature-lint-command.md

Lines changed: 55 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,57 +9,86 @@ description: Technical implementation notes, patterns, and code guidelines
99
## Development Setup
1010
**How do we get started?**
1111

12-
- Prerequisites and dependencies
13-
- Environment setup steps
14-
- Configuration needed
12+
- `npm install` at repository root.
13+
- CLI package local validation commands:
14+
- `npm run lint` (from `packages/cli`)
15+
- `nx run cli:test -- --runInBand lint.test.ts` (from repo root)
1516

1617
## Code Structure
1718
**How is the code organized?**
1819

19-
- Directory structure
20-
- Module organization
21-
- Naming conventions
20+
- `packages/cli/src/cli.ts`
21+
- Registers new `lint` command and options (`--feature`, `--json`).
22+
- `packages/cli/src/commands/lint.ts`
23+
- Command entrypoint that runs checks, renders output, and sets process exit code.
24+
- `packages/cli/src/services/lint/lint.service.ts`
25+
- Core lint orchestration and business logic only (no terminal rendering).
26+
- `packages/cli/src/services/lint/rules/`
27+
- Rule modules split by concern (`base-docs`, `feature-name`, `feature-docs`, `git-worktree`).
28+
- `packages/cli/src/__tests__/services/lint/lint.test.ts`
29+
- Unit coverage for normalization and check outcomes.
30+
- `packages/cli/src/__tests__/commands/lint.test.ts`
31+
- Command-level coverage for orchestration and exit-code behavior.
2232

2333
## Implementation Notes
2434
**Key technical details to remember:**
2535

2636
### Core Features
27-
- Feature 1: Implementation approach
28-
- Feature 2: Implementation approach
29-
- Feature 3: Implementation approach
37+
- Base readiness checks validate `docs/ai/{requirements,design,planning,implementation,testing}/README.md`.
38+
- Feature mode normalizes `feature-<name>` and `<name>` into a shared `normalizedName`.
39+
- Feature names are validated as kebab-case before running feature-level checks.
40+
- Feature mode validates lifecycle docs:
41+
- `docs/ai/{phase}/feature-<normalizedName>.md`
42+
- Git validation behavior:
43+
- Missing git repository => required failure.
44+
- Missing `feature-<name>` branch => required failure.
45+
- Missing dedicated worktree for branch => warning only.
46+
- Reporter supports:
47+
- human-readable checklist output
48+
- JSON report output with summary and per-check metadata
3049

3150
### Patterns & Best Practices
32-
- Design patterns being used
33-
- Code style guidelines
34-
- Common utilities/helpers
51+
- `runLintChecks` accepts injected dependencies (`cwd`, `existsSync`, `execFileSync`) for testability.
52+
- Check results use a normalized shape (`LintCheckResult`) so rendering and JSON use one source of truth.
53+
- Required failures drive exit code; warnings are advisory only.
3554

3655
## Integration Points
3756
**How do pieces connect?**
3857

39-
- API integration details
40-
- Database connections
41-
- Third-party service setup
58+
- CLI wiring: Commander action in `packages/cli/src/cli.ts` calls `lintCommand`.
59+
- `lintCommand` delegates to `runLintChecks` then `renderLintReport`.
60+
- `lint.service` composes rule modules and uses `util/git` sync helpers to query `git rev-parse`, `git show-ref`, and `git worktree list --porcelain`.
61+
- `commands/lint` owns `renderLintReport` and uses `util/terminal-ui` for consistent user-facing output.
4262

4363
## Error Handling
4464
**How do we handle failures?**
4565

46-
- Error handling strategy
47-
- Logging approach
48-
- Retry/fallback mechanisms
66+
- Git command failures are converted into deterministic lint results (miss or warn), not thrown errors.
67+
- Missing files are reported with explicit path and remediation guidance.
68+
- Output includes suggested fixes (for example `npx ai-devkit init`, `git worktree add ...`).
4969

5070
## Performance Considerations
5171
**How do we keep it fast?**
5272

53-
- Optimization strategies
54-
- Caching approach
55-
- Query optimization
56-
- Resource management
73+
- Uses direct existence checks and small git commands only.
74+
- No recursive repository scans or network calls.
5775

5876
## Security Notes
5977
**What security measures are in place?**
6078

61-
- Authentication/authorization
62-
- Input validation
63-
- Data encryption
64-
- Secrets management
79+
- Read-only filesystem and git metadata checks only.
80+
- No mutation of repository state.
81+
- Git commands use argument-based process execution (`execFileSync`) to avoid shell interpolation risks from user input.
6582

83+
## Phase 6 Check Implementation
84+
85+
- Design/requirements alignment: aligned for command surface, normalization, check categories, and exit behavior.
86+
- Deviations and gaps:
87+
- Full CLI binary execution via `npm run dev -- lint ...` is currently blocked by unrelated pre-existing TypeScript errors in `src/commands/memory.ts`.
88+
89+
## Phase 8 Code Review
90+
91+
- Blocking issue found and resolved:
92+
- `packages/cli/src/services/lint/lint.service.ts`: replaced shell-command interpolation with argument-based git execution and added feature-name validation.
93+
- Remaining non-blocking gap:
94+
- Full CLI binary execution remains blocked by unrelated pre-existing TypeScript issues outside this feature.

docs/ai/planning/feature-lint-command.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,36 @@ description: Break down work into actionable tasks and estimate timeline
99
## Milestones
1010
**What are the major checkpoints?**
1111

12-
- [ ] Milestone 1: Lint requirements/design approved
13-
- [ ] Milestone 2: `ai-devkit lint` base + feature checks implemented
14-
- [ ] Milestone 3: Tests, docs, and rollout complete
12+
- [x] Milestone 1: Lint requirements/design approved
13+
- [x] Milestone 2: `ai-devkit lint` base + feature checks implemented
14+
- [x] Milestone 3: Tests, docs, and rollout complete
1515

1616
## Task Breakdown
1717
**What specific work needs to be done?**
1818

1919
### Phase 1: Foundation
20-
- [ ] Task 1.1: Audit current CLI command registration and identify insertion point for `lint`
21-
- [ ] Task 1.2: Extract/reimplement `check-docs.sh` base and feature doc checks in TypeScript utilities
22-
- [ ] Task 1.3: Implement feature-name normalization utility (`foo` and `feature-foo` -> `foo`)
23-
- [ ] Task 1.4: Define shared lint result model and formatter (`ok/miss/warn`, remediation hints)
20+
- [x] Task 1.1: Audit current CLI command registration and identify insertion point for `lint`
21+
- [x] Task 1.2: Extract/reimplement `check-docs.sh` base and feature doc checks in TypeScript utilities
22+
- [x] Task 1.3: Implement feature-name normalization utility (`foo` and `feature-foo` -> `foo`)
23+
- [x] Task 1.4: Define shared lint result model and formatter (`ok/miss/warn`, remediation hints)
2424

2525
### Phase 2: Core Features
26-
- [ ] Task 2.1: Add `ai-devkit lint` command handler with base workspace checks
27-
- [ ] Task 2.2: Add `--feature <name>` mode with feature doc checks across all lifecycle phases
28-
- [ ] Task 2.3: Add git checks for `feature-<name>` branch/worktree presence and mapping
29-
- [ ] Task 2.4: Ensure proper exit codes and summary output for CI compatibility
26+
- [x] Task 2.1: Add `ai-devkit lint` command handler with base workspace checks
27+
- [x] Task 2.2: Add `--feature <name>` mode with feature doc checks across all lifecycle phases
28+
- [x] Task 2.3: Add git checks for `feature-<name>` branch/worktree presence and mapping
29+
- [x] Task 2.4: Ensure proper exit codes and summary output for CI compatibility
3030

3131
### Phase 3: Integration & Polish
32-
- [ ] Task 3.1: Update help text and README command documentation
33-
- [ ] Task 3.2: Decide whether to keep `skills/dev-lifecycle/scripts/check-docs.sh` as wrapper or migrate references to `ai-devkit lint`
34-
- [ ] Task 3.3: Add actionable remediation guidance in failures (`npx ai-devkit init`, worktree creation command)
35-
- [ ] Task 3.4: Validate behavior against existing lifecycle docs and feature naming conventions
32+
- [x] Task 3.1: Update help text and README command documentation
33+
- [x] Task 3.2: Decide whether to keep `skills/dev-lifecycle/scripts/check-docs.sh` as wrapper or migrate references to `ai-devkit lint`
34+
- [x] Task 3.3: Add actionable remediation guidance in failures (`npx ai-devkit init`, worktree creation command)
35+
- [x] Task 3.4: Validate behavior against existing lifecycle docs and feature naming conventions
3636

3737
### Phase 4: Validation
38-
- [ ] Task 4.1: Unit tests for base docs checks and feature docs checks
39-
- [ ] Task 4.2: Unit tests for feature normalization and git/worktree validation logic
40-
- [ ] Task 4.3: Integration tests for CLI exit codes and terminal output
41-
- [ ] Task 4.4: Manual verification on repositories with and without required docs/worktrees
38+
- [x] Task 4.1: Unit tests for base docs checks and feature docs checks
39+
- [x] Task 4.2: Unit tests for feature normalization and git/worktree validation logic
40+
- [x] Task 4.3: Integration tests for CLI exit codes and terminal output
41+
- [x] Task 4.4: Manual verification on repositories with and without required docs/worktrees
4242

4343
## Dependencies
4444
**What needs to happen in what order?**

docs/ai/testing/feature-lint-command.md

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,73 +9,67 @@ description: Define testing approach, test cases, and quality assurance
99
## Test Coverage Goals
1010
**What level of testing do we aim for?**
1111

12-
- Unit test coverage target (default: 100% of new/changed code)
13-
- Integration test scope (critical paths + error handling)
14-
- End-to-end test scenarios (key user journeys)
15-
- Alignment with requirements/design acceptance criteria
12+
- Unit target: 100% of new/changed lint utilities and feature normalization logic.
13+
- Integration target: CLI command invocation, rendered output categories, and exit code behavior.
14+
- Manual target: run lint flows on real workspace states (healthy and missing prerequisites).
1615

1716
## Unit Tests
1817
**What individual components need testing?**
1918

20-
### Component/Module 1
21-
- [ ] Test case 1: [Description] (covers scenario / branch)
22-
- [ ] Test case 2: [Description] (covers edge case / error handling)
23-
- [ ] Additional coverage: [Description]
24-
25-
### Component/Module 2
26-
- [ ] Test case 1: [Description]
27-
- [ ] Test case 2: [Description]
28-
- [ ] Additional coverage: [Description]
19+
### `packages/cli/src/services/lint/lint.service.ts` + `packages/cli/src/services/lint/rules/*`
20+
- [x] Feature name normalization accepts both `lint-command` and `feature-lint-command`.
21+
- [x] Invalid feature names fail fast as required failures before git checks run.
22+
- [x] Base docs missing case returns required failures and non-zero exit code.
23+
- [x] Branch exists + no dedicated worktree returns pass with warning.
24+
- [x] Missing feature branch returns required failure.
25+
- [x] Non-git directory in feature mode returns required failure.
2926

3027
## Integration Tests
3128
**How do we test component interactions?**
3229

33-
- [ ] Integration scenario 1
34-
- [ ] Integration scenario 2
35-
- [ ] API endpoint tests
36-
- [ ] Integration scenario 3 (failure mode / rollback)
30+
- [x] Command-level test verifies `lintCommand` calls `runLintChecks` and `renderLintReport` with parsed options.
31+
- [x] Command-level test verifies `process.exitCode` is set from report exit code (`0` and `1` paths).
32+
- [x] Output rendering tests verify human-readable sections and `--json` serialization behavior.
3733

3834
## End-to-End Tests
3935
**What user flows need validation?**
4036

41-
- [ ] User flow 1: [Description]
42-
- [ ] User flow 2: [Description]
43-
- [ ] Critical path testing
44-
- [ ] Regression of adjacent features
37+
- [x] Real workspace state (current repo) via utility execution: feature check passes with required checks satisfied.
38+
- [x] Missing docs scenario (temporary directory): required failures and non-zero exit code.
39+
- [x] Branch exists/no dedicated worktree scenario (temporary git repo): warning-only worktree result with zero exit code.
4540

4641
## Test Data
4742
**What data do we use for testing?**
4843

49-
- Test fixtures and mocks
50-
- Seed data requirements
51-
- Test database setup
44+
- Dependency-injected stubs for `existsSync` and `execFileSync`.
45+
- Synthetic git command outputs for branch/worktree combinations.
5246

5347
## Test Reporting & Coverage
5448
**How do we verify and communicate test results?**
5549

56-
- Coverage commands and thresholds (`npm run test -- --coverage`)
57-
- Coverage gaps (files/functions below 100% and rationale)
58-
- Links to test reports or dashboards
59-
- Manual testing outcomes and sign-off
50+
- Executed:
51+
- `nx run cli:test -- --runInBand lint.test.ts` (pass, 2 suites / 9 tests)
52+
- `npm run lint` in `packages/cli` (pass with pre-existing repo warnings unrelated to lint command)
53+
- Manual verification runs:
54+
- Current repo + `feature=lint-command`: pass `true`, exit code `0`, zero required failures.
55+
- Temporary directory with no docs: pass `false`, exit code `1`, required failures `5`.
56+
- Temporary git repo with `feature-sample` branch but no dedicated worktree: pass `true`, exit code `0`, git warning present.
57+
- Current gap:
58+
- Full CLI binary invocation (`npm run dev -- lint ...`) remains blocked by unrelated pre-existing TypeScript issues in `src/commands/memory.ts`.
6059

6160
## Manual Testing
6261
**What requires human validation?**
6362

64-
- UI/UX testing checklist (include accessibility)
65-
- Browser/device compatibility
66-
- Smoke tests after deployment
63+
- Validate output readability and remediation commands in terminal.
64+
- Validate warning-only behavior when worktree is missing but branch exists.
65+
- Validate JSON consumers in CI pipelines that parse `--json` output.
6766

6867
## Performance Testing
6968
**How do we validate performance?**
7069

71-
- Load testing scenarios
72-
- Stress testing approach
73-
- Performance benchmarks
70+
- Confirm command remains sub-second for standard repository size during manual verification.
7471

7572
## Bug Tracking
7673
**How do we manage issues?**
7774

78-
- Issue tracking process
79-
- Bug severity levels
80-
- Regression testing strategy
81-
75+
- Track unrelated pre-existing TypeScript issues in `src/commands/memory.ts` separately from this feature.

0 commit comments

Comments
 (0)