Skip to content

Commit f8397f6

Browse files
committed
feat(): docs and cleanup
1 parent 80d3611 commit f8397f6

File tree

6 files changed

+24
-18
lines changed

6 files changed

+24
-18
lines changed

docs/component-refactoring-flow.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,12 @@ The rule implements a comprehensive validation process:
234234
### Tools used
235235

236236
- `build_component_contract` - Creates post-refactor component contract
237-
- Parameters: `componentFile`, `dsComponentName` (set to "AUTO")
237+
- Parameters: `saveLocation`, `templateFile`, `styleFile`, `typescriptFile`, `dsComponentName`
238238
- Returns: updated contract path with refactored component state
239239
- Purpose: Capture final component state for comparison
240240

241241
- `diff_component_contract` - Compares baseline and updated contracts
242-
- Parameters: `contractBeforePath`, `contractAfterPath`, `dsComponentName` (set to "AUTO")
242+
- Parameters: `saveLocation`, `contractBeforePath`, `contractAfterPath`, `dsComponentName`
243243
- Returns: detailed diff analysis showing specific changes
244244
- Purpose: Identify and analyze all modifications made during refactoring
245245

docs/contracts.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,17 @@ Because contracts track every public-facing facet of a component, any refactor t
6565
Rules taking care about the contract building during the workflow, but if you need to build it "manually" say in the chat:
6666

6767
```
68-
build_component_contract(<component-file.ts>, dsComponentName)
68+
build_component_contract(saveLocation, templateFile, styleFile, typescriptFile, dsComponentName)
6969
```
7070

71-
> Replace `<component-file.ts>` with the path to your component and set `dsComponentName` to the design-system component (e.g., `DsBadge`). The tool analyses the template, TypeScript, and styles, then saves a timestamped `*.contract.json` to
72-
> `.cursor/tmp/contracts/<ds-component-kebab>/`.
71+
> Replace the parameters with:
72+
> - `saveLocation`: Path where to save the contract file (supports absolute and relative paths)
73+
> - `templateFile`: Path to the component template file (.html or .ts for inline)
74+
> - `styleFile`: Path to the component style file (.scss, .css, etc.)
75+
> - `typescriptFile`: Path to the TypeScript component file (.ts)
76+
> - `dsComponentName`: Optional design system component name (e.g., `DsBadge`)
77+
>
78+
> The tool analyses the template, TypeScript, and styles, then saves the contract to your specified location.
7379
7480
## When to Build a Contract
7581

@@ -160,10 +166,13 @@ What happens when QA finds a bug or a reviewer requests changes **after** the in
160166
3. **Locate the original baseline contract** – this is the contract that was captured for the initial state (usually the very first timestamp in the folder).
161167
4. **Generate a diff** between the baseline and the latest contract:
162168
```
163-
User: diff_component_contract(<baseline>.contract.json, <latest>.contract.json, dsComponentName)
169+
User: diff_component_contract(saveLocation, contractBeforePath, contractAfterPath, dsComponentName)
164170
```
165-
The diff file will land under
166-
`.cursor/tmp/contracts/<ds-component-kebab>/diffs/`.
171+
> Replace the parameters with:
172+
> - `saveLocation`: Path where to save the diff result file (supports absolute and relative paths)
173+
> - `contractBeforePath`: Path to the baseline contract file
174+
> - `contractAfterPath`: Path to the latest contract file
175+
> - `dsComponentName`: Optional design system component name
167176
5. **Review the diff output using AI** – attach the diff and ask it to analyze it.
168177
* If only intentional changes appear, proceed to merge / re-test.
169178
* If unexpected API, DOM, or style changes surface, iterate on the fix and repeat steps 1-4.

docs/ds-refactoring-flow.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ This is your last chance to make changes before opening the pull request.
566566
- Features: Automatic ESLint config resolution, comprehensive rule coverage
567567

568568
- `build_component_contract` - Creates contracts for refactored components
569-
- Parameters: `directory`, `templateFile`, `styleFile`, `typescriptFile`, `dsComponentName`
569+
- Parameters: `saveLocation`, `templateFile`, `styleFile`, `typescriptFile`, `dsComponentName`
570570
- Returns: JSON contract with public API, DOM structure, and styles
571571
- Purpose: Capture post-refactoring component state
572572

@@ -576,9 +576,9 @@ This is your last chance to make changes before opening the pull request.
576576
- Purpose: Identify before/after contract pairs for comparison
577577

578578
- `diff_component_contract` - Compares component contracts
579-
- Parameters: `directory`, `contractBeforePath`, `contractAfterPath`, `dsComponentName`
579+
- Parameters: `saveLocation`, `contractBeforePath`, `contractAfterPath`, `dsComponentName`
580580
- Returns: Detailed diff highlighting changes in API, DOM, and styles
581-
- Saves: Diff files to `.cursor/tmp/contracts/<component>/diffs/`
581+
- Saves: Diff files to the specified saveLocation path
582582

583583
### Flow
584584

docs/tools.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,20 +113,22 @@ This document provides comprehensive guidance for AI agents working with Angular
113113
**Purpose**: Creates static surface contracts for component templates and styles
114114
**AI Usage**: Generate contracts before refactoring to track breaking changes
115115
**Key Parameters**:
116-
- `directory`: Component directory
116+
- `saveLocation`: Path where to save the contract file (supports absolute and relative paths)
117117
- `templateFile`: Template file name (.html or .ts for inline)
118118
- `styleFile`: Style file name (.scss, .css, etc.)
119119
- `typescriptFile`: TypeScript component file (.ts)
120+
- `dsComponentName`: Optional design system component name
120121
**Output**: Component contract file with API surface
121122
**Best Practice**: Create contracts before major refactoring for comparison
122123

123124
#### `diff_component_contract`
124125
**Purpose**: Compares before/after contracts to identify breaking changes
125126
**AI Usage**: Validate that refactoring doesn't introduce breaking changes
126127
**Key Parameters**:
127-
- `directory`: Component directory
128+
- `saveLocation`: Path where to save the diff result file (supports absolute and relative paths)
128129
- `contractBeforePath`: Path to pre-refactoring contract
129130
- `contractAfterPath`: Path to post-refactoring contract
131+
- `dsComponentName`: Optional design system component name
130132
**Output**: Diff analysis showing breaking changes
131133
**Best Practice**: Essential validation step after component modifications
132134

packages/angular-mcp-server/src/lib/tools/ds/component-contract/builder/build-component-contract.tool.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,11 @@ export const buildComponentContractHandler = createHandler<
4343
effectiveTypescriptPath,
4444
);
4545

46-
// Custom save logic using the provided saveLocation
4746
const contractString = JSON.stringify(contract, null, 2);
4847
const hash = require('node:crypto').createHash('sha256').update(contractString).digest('hex');
4948

5049
const effectiveSaveLocation = resolveCrossPlatformPath(cwd, saveLocation);
5150

52-
// Ensure directory exists
5351
const { mkdir, writeFile } = await import('node:fs/promises');
5452
const { dirname } = await import('node:path');
5553
await mkdir(dirname(effectiveSaveLocation), { recursive: true });

packages/angular-mcp-server/src/lib/tools/ds/component-contract/diff/diff-component-contract.tool.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,10 @@ export const diffComponentContractHandler = createHandler<
5858
summary: generateDiffSummary(processedResult, groupedChanges),
5959
};
6060

61-
// Normalize absolute paths to relative paths for portability
6261
const normalizedDiffData = normalizePathsInObject(diffData, workspaceRoot);
6362

64-
// Use the provided saveLocation
6563
const effectiveSaveLocation = resolveCrossPlatformPath(cwd, saveLocation);
6664

67-
// Ensure directory exists
6865
const { dirname } = await import('node:path');
6966
await mkdir(dirname(effectiveSaveLocation), { recursive: true });
7067

0 commit comments

Comments
 (0)