Skip to content

feat(mcp): add a lint-templates agent tool - #415

Merged
erkamyaman merged 1 commit into
mainfrom
feat/mcp-lint-templates
Oct 15, 2026
Merged

erkamyaman merged 1 commit into
mainfrom
feat/mcp-lint-templates

Conversation

@erkamyaman

@erkamyaman erkamyaman commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

What and why

The "template diagnostics lint-templates tool" item from #372.

pangular:lint-templates parses every component template in the project (inline template and templateUrl files) and reports problems, in the same finding format as lint-pipes.

Rule Severity Finds
template-parse-error error what the Angular parser reports, @for without track included
track-by-index warning track $index (or an alias of it) on a loop whose body reads a field of the item; form-array rows bound by index are exempt
img-missing-alt warning <img> without alt, [alt] or [attr.alt], unless hidden or presentational
click-without-key warning (click) on a non-interactive native element with no key handler, unless hidden or presentational
legacy-control-flow info *ngIf, *ngFor, *ngSwitchCase, *ngSwitchDefault (Angular 17+ only)
ngclass-ngstyle info [ngClass] or [ngStyle]
  • Parser: it loads the project's own @angular/compiler (resolved from the project's package.json) and walks the same AST Angular compiles, so there are no regexes and no new dependency. Without a compiler the answer says so. A failed load is not cached.
  • Templates: it reuses templatesIn, sourceRoots and walkFiles from the pipes scan. Escapes in quoted inline templates keep their length, so line numbers match the file; a backtick template with ${} is skipped.
  • Cache: findings per template, keyed by its text, so unchanged templates are not parsed again and an edit shows up on the next call.
  • Arguments: rule, file (path substring), severity, limit (default 50, max 200). Unknown rules or severities are rejected.
  • Output: markdown with a summary line, errors first, then by file and line. Declares the markdown output schema. Parse-error messages go through redactText.
  • Registration: inspector components, not page-bound, so the stdio server keeps it.

On the demo app's 31 templates it reports nothing and takes about 200 ms.

Left out

  • Method calls in bindings: whether a call reads a signal can't be told from the template alone.
  • It is not part of the audit aggregation and has no panel RPC yet.

Docs: a lint-templates section in agents/tools.md (tool count, arguments and rules), inspectors/components.md, the structured-output table in agents/mcp-server.md, security.md next to lint-pipes, and a row in the shipped pangular-inspector skill.

Refs #372.

How it was verified

  • pnpm commit:check
  • pnpm format:check
  • pnpm typecheck
  • pnpm test:devtools (3168). New template-lint.test.ts (27 tests) with the workspace's real compiler: parse errors with correct lines (inline, templateUrl, escaped quotes, ${} skipped); positive and negative cases for each rule; rules inside nested blocks; the legacy rule off below Angular 17; the no-compiler answer; the cache (no re-parse, re-parse after an edit, finding gone after a fix); filters, unknown arguments, limit and the tool handler.
  • pnpm skills:check
  • Docs in apps/docs updated and pnpm docs:build passes
  • No change in app, so no extension:build

Summary by CodeRabbit

  • New Features

    • Added a template-checking tool that finds common Angular template errors and accessibility issues, including missing image descriptions and click handlers without keyboard support.
    • Narrow results by rule, file, or severity, and limit the number of findings shown.
  • Documentation

    • Updated the tools and security guides with details about template checks and how their results are presented. Clarified that source-scanning tools inspect project files rather than page content.

It parses every component template with the project's own @angular/compiler and reports parse errors, track $index on object lists, images without alt, click handlers without a key handler, legacy structural directives and ngClass or ngStyle bindings.

Refs #372.
@github-actions github-actions Bot added area: package The ng-devtools package (packages/ng-devtools) area: agents MCP server, agent tools and resources area: docs The documentation site labels Oct 15, 2026
@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 451f695a-57a1-4a7a-8e54-7a29dd6bcf04
📥 Commits

Reviewing files that changed from the base of the PR and between 8a69357 and ff7f891.

📒 Files selected for processing: 12
  • apps/docs/src/content/agents/mcp-server.md
  • apps/docs/src/content/agents/tools.md
  • apps/docs/src/content/inspectors/components.md
  • apps/docs/src/content/security.md
  • packages/devtools/skills/pangular-inspector/SKILL.md
  • packages/devtools/src/__tests__/fixtures/agent-metadata-derived.json
  • packages/devtools/src/__tests__/tool-metadata.test.ts
  • packages/devtools/src/config.ts
  • packages/devtools/src/devframe.ts
  • packages/devtools/src/rpc/__tests__/template-lint.test.ts
  • packages/devtools/src/rpc/template-lint-tool.ts
  • packages/devtools/src/rpc/template-lint.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

📝 Walkthrough

The change adds a compiler-backed tool that scans component templates and returns filtered Markdown findings. It registers the tool with the components inspector and updates its tests and documentation.

Changes: Template linting

Layer / File(s) Summary
Compiler-backed scanning
packages/devtools/src/rpc/template-lint.ts, packages/devtools/src/rpc/__tests__/template-lint.test.ts
Loads the project’s @angular/compiler, scans component source files, extracts templates, and caches findings for unchanged template text.
Template parsing and findings
packages/devtools/src/rpc/template-lint.ts, packages/devtools/src/rpc/__tests__/template-lint.test.ts
Parses templates and reports parser errors, legacy control flow, selected binding patterns, accessibility findings, and index-based loop tracking.
Tool output and agent integration
packages/devtools/src/rpc/template-lint-tool.ts, packages/devtools/src/config.ts, packages/devtools/src/devframe.ts, packages/devtools/src/__tests__/*, packages/devtools/skills/pangular-inspector/SKILL.md, apps/docs/src/content/agents/*, apps/docs/src/content/inspectors/components.md, apps/docs/src/content/security.md
Formats findings as Markdown, registers the tool with the components inspector, and updates tool metadata, tests, skill guidance, and documentation.

Priority: ➖ Normal

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Agent
  participant templateLintTool
  participant lintTemplates
  participant templateLintText
  Agent->>templateLintTool: invoke with working directory and filters
  templateLintTool->>lintTemplates: scan project templates
  lintTemplates-->>templateLintTool: return findings
  templateLintTool->>templateLintText: format findings with filters
  templateLintText-->>Agent: return Markdown result
Loading
Merge Risk: ⚪ Minimal · up to ff7f8

The new template-lint tool is ready to merge after normal checks; no actionable issue was established.

Security architecture risk: 🟡 Moderate · up to ff7f8

Template linting is available in read-only mode but executes the project's installed compiler with the server account's permissions. A malicious or replaced compiler could therefore reach beyond the scanned workspace. Existing configuration controls limit availability, but the policy for trusting project dependencies is unclear.

Retained concerns

  • Medium · security · inferred: The new read-only source-analysis path executes project-resolved dependency code in the server process. If an attacker controls the resolved @angular/compiler package, an otherwise read-only lint invocation can execute its initialization code with the server account's filesystem, environment and network access. This also applies to source-only stdio operation; workspace scan containment does not constrain module execution. The intended project-dependency trust policy remains unresolved.
Security review details

Security Blast Radius

  • inferred — The conditional execution exposure is the server process's account, not merely the workspace files selected for scanning. Exploitation requires control of the resolved compiler dependency and a lint invocation; the tool arguments alone provide neither dependency replacement nor arbitrary module selection. No tenant-wide or production-service reach is established.

Security Findings and Attack Paths

  • inferred — A substituted project compiler can run initialization code when the new lint handler imports it, before the parseTemplate check. Read-only classification does not stop this transition. This is a conditional architecture concern, not a demonstrated unauthenticated remote exploit or a claim that template expressions themselves are executed.

Trust Boundaries and Controls

  • observed — Central registration applies the existing exposure gate, safety metadata and handler wrapper. Disabling the Components inspector or its agent-tool switch suppresses this tool through normal configuration resolution. Read-only mode retains it because its safety defaults to read; that is an exposure classification, not module-execution isolation.

Resilience and Maintainability Implications

  • inferred — Failed-load cleanup and compiler/project-scoped finding caches reduce stale partial-result and cross-project reuse risks. These mechanisms do not roll back side effects of an imported module, and successful compiler caching does not refresh dependency trust after replacement.

Hardening Proposals

  • proposed — Make project-code execution an explicit trust decision, especially for source-only and read-only operation. For untrusted projects, use a trusted parser dependency or an isolated, least-privilege parsing process; document that read-only metadata does not sandbox project dependencies.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 21 functions across 6 files. (6 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely identifies the main change: adding the lint-templates agent tool.
Full details: Docstring Coverage

Explanation

Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 21 functions across 6 files. (6 skipped: 6 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@nx-cloud

nx-cloud Bot commented Oct 15, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit ff7f891

Command Status Duration Result
nx affected -t test build ✅ Succeeded 1m 38s View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-10-15 21:46:27 UTC

@cloudflare-workers-and-pages

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Failed ❌

View logs ↗
ff7f891 2026-10-15T21:47:09.034Z View logs ↗

@erkamyaman
erkamyaman merged commit df84e58 into main Oct 15, 2026
8 of 10 checks passed
@erkamyaman
erkamyaman deleted the feat/mcp-lint-templates branch October 15, 2026 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: agents MCP server, agent tools and resources area: docs The documentation site area: package The ng-devtools package (packages/ng-devtools)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant