WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit e8d0cf9

Browse files
Merge pull request #23 from push-based/feature/add-save-as-file-option
feat(angular-mcp-server): add violation grouping tool
2 parents 2fe0087 + 891e7f8 commit e8d0cf9

26 files changed

+1197
-192
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,11 @@ my-angular-workspace/
186186

187187
### Component Analysis
188188

189-
- **`report-violations`**: Report deprecated CSS usage in a directory with configurable grouping format
189+
- **`report-violations`**: Report deprecated CSS usage for a specific component in a directory. Supports optional file output with statistics.
190+
191+
- **`report-all-violations`**: Report all deprecated CSS usage across all components in a directory. Supports optional file output with statistics.
192+
193+
- **`group-violations`**: Creates balanced work distribution groups from violations reports using bin-packing algorithm. Maintains path exclusivity and directory boundaries for parallel development.
190194

191195
- **`report-deprecated-css`**: Report deprecated CSS classes found in styling files
192196

docs/tools.md

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
1-
# Design System Tools for AI Agents
1+
# Angular MCP Tools for AI Agents
22

3-
This document provides comprehensive guidance for AI agents working with Angular Design System (DS) migration and analysis tools. Each tool is designed to support automated refactoring, validation, and analysis workflows.
3+
This document provides comprehensive guidance for AI agents working with Angular migration and analysis tools. Each tool is designed to support automated refactoring, validation, and analysis workflows.
44

55
## Tool Categories
66

77
### 🔍 Project Analysis Tools
88

99
#### `report-violations`
10-
**Purpose**: Identifies deprecated DS CSS usage patterns in Angular projects
11-
**AI Usage**: Use as the first step in migration workflows to identify all violations before planning refactoring
10+
**Purpose**: Identifies deprecated CSS usage patterns for a specific component in Angular projects
11+
**AI Usage**: Use when you need to analyze violations for a specific component before planning refactoring
1212
**Key Parameters**:
1313
- `directory`: Target analysis directory (use relative paths like `./src/app`)
14-
- `componentName`: DS component class name (e.g., `DsButton`)
14+
- `componentName`: Component class name (e.g., `DsButton`)
1515
- `groupBy`: `"file"` or `"folder"` for result organization
16-
**Output**: Structured violation reports grouped by file or folder
17-
**Best Practice**: Always run this before other migration tools to establish baseline
16+
- `saveAsFile`: Optional boolean - if `true`, saves report to `tmp/.angular-toolkit-mcp/violations-report/<componentName>/<directory>-violations.json`
17+
**Output**:
18+
- Default: Structured violation reports grouped by file or folder
19+
- With `saveAsFile: true`: File path and statistics (components, files, lines)
20+
**Best Practice**: Use `saveAsFile: true` when you need to persist results for later processing or grouping workflows
1821

1922
#### `report-all-violations`
20-
**Purpose**: Reports all deprecated DS CSS usage for every DS component within a directory
23+
**Purpose**: Reports all deprecated CSS usage for every component within a directory
2124
**AI Usage**: Use for a fast, global inventory of violations across the codebase before narrowing to specific components
2225
**Key Parameters**:
2326
- `directory`: Target analysis directory (use relative paths like `./src/app`)
24-
- `groupBy`: `"file"` or `"folder"` for result organization (default: `"file"`)
25-
**Output**: Structured violation reports grouped by file or folder covering all DS components
26-
**Best Practice**: Use to discover all violations and establish the baseline for subsequent refactoring.
27+
- `groupBy`: `"component"` or `"file"` for result organization (default: `"component"`)
28+
- `saveAsFile`: Optional boolean - if `true`, saves report to `tmp/.angular-toolkit-mcp/violations-report/<directory>-violations.json`
29+
**Output**:
30+
- Default: Structured violation reports grouped by component or file covering all components
31+
- With `saveAsFile: true`: File path and statistics (components, files, lines)
32+
**Best Practice**: Use `saveAsFile: true` to persist results for grouping workflows or large-scale migration planning. The saved file can be used as input for work distribution grouping tools.
2733

2834
#### `get-project-dependencies`
2935
**Purpose**: Analyzes project structure, dependencies, and buildability
@@ -34,6 +40,21 @@ This document provides comprehensive guidance for AI agents working with Angular
3440
**Output**: Dependency analysis, buildable/publishable status, peer dependencies
3541
**Best Practice**: Use to understand project constraints before recommending changes
3642

43+
#### `group-violations`
44+
**Purpose**: Creates balanced work distribution groups from violations reports for parallel development
45+
**AI Usage**: Use after `report-all-violations` to organize violations into balanced work groups for team distribution
46+
**Key Parameters**:
47+
- `fileName`: Name of violations JSON file in `tmp/.angular-toolkit-mcp/violations-report/` (e.g., `"packages-poker-core-lib-violations.json"`)
48+
- `minGroups`: Minimum number of groups (default: 3)
49+
- `maxGroups`: Maximum number of groups (default: 5)
50+
- `variance`: Acceptable variance percentage for balance (default: 20)
51+
**Output**:
52+
- Work groups with balanced violation counts
53+
- Individual JSON and Markdown files per group
54+
- Metadata with validation results
55+
- Saved to `tmp/.angular-toolkit-mcp/violation-groups/<reportName>/`
56+
**Best Practice**: Use after saving violations with `saveAsFile: true`. The tool accepts both component-grouped and file-grouped reports. Groups maintain path exclusivity (each file in exactly one group) and preserve directory boundaries to enable parallel development without merge conflicts.
57+
3758
#### `report-deprecated-css`
3859
**Purpose**: Scans styling files for deprecated CSS classes
3960
**AI Usage**: Complement violation reports with style-specific analysis
@@ -147,8 +168,9 @@ This document provides comprehensive guidance for AI agents working with Angular
147168
### 1. Discovery & Analysis Workflow
148169
```
149170
1. list-ds-components → Discover available DS components
150-
2. report-violations → Identify all violations
151-
3. get-project-dependencies → Analyze project structure
171+
2. report-all-violations (saveAsFile: true) → Identify all violations and save to file
172+
3. group-violations → Create balanced work distribution groups
173+
4. get-project-dependencies → Analyze project structure
152174
```
153175

154176
### 2. Planning & Preparation Workflow

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@ import { buildComponentContract } from './utils/build-contract.js';
77
import { generateContractSummary } from '../shared/utils/contract-file-ops.js';
88
import { ContractResult } from './models/types.js';
99
import { resolveCrossPlatformPath } from '../../shared/utils/cross-platform-path.js';
10+
import {
11+
OUTPUT_SUBDIRS,
12+
resolveDefaultSaveLocation,
13+
} from '../../shared/constants.js';
1014
import { createHash } from 'node:crypto';
15+
import { dirname } from 'node:path';
16+
import { mkdir, writeFile } from 'node:fs/promises';
1117

1218
interface BuildComponentContractOptions extends BaseHandlerOptions {
13-
saveLocation: string;
19+
saveLocation?: string;
1420
templateFile?: string;
1521
styleFile?: string;
1622
typescriptFile: string;
@@ -36,6 +42,13 @@ export const buildComponentContractHandler = createHandler<
3642
typescriptFile,
3743
);
3844

45+
const defaultSaveLocation = resolveDefaultSaveLocation(
46+
saveLocation,
47+
OUTPUT_SUBDIRS.CONTRACTS,
48+
typescriptFile,
49+
'-contract.json',
50+
);
51+
3952
// If templateFile or styleFile are not provided, use the TypeScript file path
4053
// This indicates inline template/styles
4154
const effectiveTemplatePath = templateFile
@@ -55,10 +68,11 @@ export const buildComponentContractHandler = createHandler<
5568
const contractString = JSON.stringify(contract, null, 2);
5669
const hash = createHash('sha256').update(contractString).digest('hex');
5770

58-
const effectiveSaveLocation = resolveCrossPlatformPath(cwd, saveLocation);
71+
const effectiveSaveLocation = resolveCrossPlatformPath(
72+
cwd,
73+
defaultSaveLocation,
74+
);
5975

60-
const { mkdir, writeFile } = await import('node:fs/promises');
61-
const { dirname } = await import('node:path');
6276
await mkdir(dirname(effectiveSaveLocation), { recursive: true });
6377

6478
const contractData = {

packages/angular-mcp-server/src/lib/tools/ds/component-contract/builder/models/schema.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { ToolSchemaOptions } from '@push-based/models';
2-
import { COMMON_ANNOTATIONS } from '../../../shared/index.js';
2+
import {
3+
COMMON_ANNOTATIONS,
4+
DEFAULT_OUTPUT_BASE,
5+
OUTPUT_SUBDIRS,
6+
} from '../../../shared/index.js';
37

48
/**
59
* Schema for building component contracts
@@ -13,8 +17,7 @@ export const buildComponentContractSchema: ToolSchemaOptions = {
1317
properties: {
1418
saveLocation: {
1519
type: 'string',
16-
description:
17-
'Path where to save the contract file. Supports both absolute and relative paths.',
20+
description: `Path where to save the contract file. Supports both absolute and relative paths. If not provided, defaults to ${DEFAULT_OUTPUT_BASE}/${OUTPUT_SUBDIRS.CONTRACTS}/<component-name>-contract.json. When building contracts for comparison, use descriptive names like <component-name>-before-contract.json or <component-name>-after-contract.json to distinguish between refactoring phases.`,
1821
},
1922
templateFile: {
2023
type: 'string',
@@ -37,7 +40,7 @@ export const buildComponentContractSchema: ToolSchemaOptions = {
3740
default: '',
3841
},
3942
},
40-
required: ['saveLocation', 'typescriptFile'],
43+
required: ['typescriptFile'],
4144
},
4245
annotations: {
4346
title: 'Build Component Contract',

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import {
66
resolveCrossPlatformPath,
77
normalizePathsInObject,
88
} from '../../shared/utils/cross-platform-path.js';
9+
import {
10+
OUTPUT_SUBDIRS,
11+
resolveDefaultSaveLocation,
12+
} from '../../shared/constants.js';
913
import { diffComponentContractSchema } from './models/schema.js';
1014
import type { DomPathDictionary } from '../shared/models/types.js';
1115
import { loadContract } from '../shared/utils/contract-file-ops.js';
@@ -15,10 +19,11 @@ import {
1519
generateDiffSummary,
1620
} from './utils/diff-utils.js';
1721
import { writeFile, mkdir } from 'node:fs/promises';
22+
import { dirname } from 'node:path';
1823
import diff from 'microdiff';
1924

2025
interface DiffComponentContractOptions extends BaseHandlerOptions {
21-
saveLocation: string;
26+
saveLocation?: string;
2227
contractBeforePath: string;
2328
contractAfterPath: string;
2429
dsComponentName?: string;
@@ -46,6 +51,14 @@ export const diffComponentContractHandler = createHandler<
4651
);
4752
const effectiveAfterPath = resolveCrossPlatformPath(cwd, contractAfterPath);
4853

54+
const defaultSaveLocation = resolveDefaultSaveLocation(
55+
saveLocation,
56+
OUTPUT_SUBDIRS.CONTRACT_DIFFS,
57+
contractBeforePath,
58+
'-diff.json',
59+
'-contract.json',
60+
);
61+
4962
const contractBefore = await loadContract(effectiveBeforePath);
5063
const contractAfter = await loadContract(effectiveAfterPath);
5164

@@ -68,9 +81,11 @@ export const diffComponentContractHandler = createHandler<
6881

6982
const normalizedDiffData = normalizePathsInObject(diffData, workspaceRoot);
7083

71-
const effectiveSaveLocation = resolveCrossPlatformPath(cwd, saveLocation);
84+
const effectiveSaveLocation = resolveCrossPlatformPath(
85+
cwd,
86+
defaultSaveLocation,
87+
);
7288

73-
const { dirname } = await import('node:path');
7489
await mkdir(dirname(effectiveSaveLocation), { recursive: true });
7590

7691
const diffFilePath = effectiveSaveLocation;

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { ToolSchemaOptions } from '@push-based/models';
2-
import { COMMON_ANNOTATIONS } from '../../../shared/index.js';
2+
import {
3+
COMMON_ANNOTATIONS,
4+
DEFAULT_OUTPUT_BASE,
5+
OUTPUT_SUBDIRS,
6+
} from '../../../shared/index.js';
37

48
/**
59
* Schema for diffing component contracts
@@ -13,26 +17,23 @@ export const diffComponentContractSchema: ToolSchemaOptions = {
1317
properties: {
1418
saveLocation: {
1519
type: 'string',
16-
description:
17-
'Path where to save the diff result file. Supports both absolute and relative paths.',
20+
description: `Path where to save the diff result file. Supports both absolute and relative paths. If not provided, defaults to ${DEFAULT_OUTPUT_BASE}/${OUTPUT_SUBDIRS.CONTRACT_DIFFS}/<component-name>-diff.json`,
1821
},
1922
contractBeforePath: {
2023
type: 'string',
21-
description:
22-
'Path to the contract file before refactoring. Supports both absolute and relative paths.',
24+
description: `Path to the contract file before refactoring. Supports both absolute and relative paths. Typically located at ${DEFAULT_OUTPUT_BASE}/${OUTPUT_SUBDIRS.CONTRACTS}/<component-name>-before-contract.json`,
2325
},
2426
contractAfterPath: {
2527
type: 'string',
26-
description:
27-
'Path to the contract file after refactoring. Supports both absolute and relative paths.',
28+
description: `Path to the contract file after refactoring. Supports both absolute and relative paths. Typically located at ${DEFAULT_OUTPUT_BASE}/${OUTPUT_SUBDIRS.CONTRACTS}/<component-name>-after-contract.json`,
2829
},
2930
dsComponentName: {
3031
type: 'string',
3132
description: 'The name of the design system component being used',
3233
default: '',
3334
},
3435
},
35-
required: ['saveLocation', 'contractBeforePath', 'contractAfterPath'],
36+
required: ['contractBeforePath', 'contractAfterPath'],
3637
},
3738
annotations: {
3839
title: 'Diff Component Contract',

packages/angular-mcp-server/src/lib/tools/ds/ds.tools.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { join } from 'node:path';
99
import {
1010
reportViolationsTools,
1111
reportAllViolationsTools,
12+
groupViolationsTools,
1213
} from './report-violations/index.js';
1314

1415
export const componentCoverageToolsSchema: ToolSchemaOptions = {
@@ -137,4 +138,5 @@ export const dsTools = [
137138
...componentCoverageTools,
138139
...reportViolationsTools,
139140
...reportAllViolationsTools,
141+
...groupViolationsTools,
140142
];

0 commit comments

Comments
 (0)