Skip to content

Commit bbcebaa

Browse files
committed
feat(vscode): harden the VS Code surface and document it as a first-class contract
- mature the preview VS Code extension into a safer, enterprise-grade MCP client with limited Restricted Mode, source-first review flow, persisted focus state, bounded transport handling, and a safer local HTML bridge - add extension-side regression coverage with Node unit tests, local extension-host smoke, and validated preview VSIX packaging - document the extension consistently across README, docs, the contracts book, changelog, and AGENTS with its current capabilities, design decisions, trust model, and limits
1 parent b0efa4a commit bbcebaa

16 files changed

Lines changed: 2532 additions & 387 deletions

AGENTS.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,11 @@ uv run pytest -q tests/test_mcp_service.py tests/test_mcp_server.py
9292
If you touched the VS Code extension surface, also run:
9393

9494
```bash
95+
node --check extensions/vscode-codeclone/src/support.js
9596
node --check extensions/vscode-codeclone/src/mcpClient.js
9697
node --check extensions/vscode-codeclone/src/extension.js
98+
node --test extensions/vscode-codeclone/test/*.test.js
99+
node extensions/vscode-codeclone/test/runExtensionHost.js
97100
```
98101

99102
If you touched VS Code extension packaging metadata (`package.json`,
@@ -102,7 +105,7 @@ smoke:
102105

103106
```bash
104107
cd extensions/vscode-codeclone
105-
NPM_CONFIG_CACHE=/tmp/codeclone-vsce-cache npx @vscode/vsce package --pre-release --out /tmp/codeclone.vsix
108+
vsce package --pre-release --out /tmp/codeclone.vsix
106109
```
107110

108111
---
@@ -458,7 +461,7 @@ If you change a contract-sensitive zone, route docs/tests/approval deliberately.
458461
| Fingerprint-adjacent analysis (`extractor/cfg/normalize/grouping`) | `docs/book/05-core-pipeline.md`, `docs/cfg.md`, `docs/book/14-compatibility-and-versioning.md`, `CHANGELOG.md` | `tests/test_fingerprint.py`, `tests/test_extractor.py`, `tests/test_cfg.py`, golden tests (`tests/test_detector_golden.py`, `tests/test_golden_v2.py`) | always (see Section 1.6) | clone identity / NEW-vs-KNOWN / fingerprint inputs change |
459462
| Suppression semantics/reporting (`suppressions`, extractor dead-code wiring, report/UI counters) | `docs/book/19-inline-suppressions.md`, `docs/book/16-dead-code-contract.md`, `docs/book/08-report.md`, and interface docs if surfaced (`09-cli`, `10-html-render`) | `tests/test_suppressions.py`, `tests/test_extractor.py`, `tests/test_metrics_modules.py`, `tests/test_pipeline_metrics.py`, report/html/cli tests | declaration scope semantics, rule effect, or contract-visible counters/fields change | suppression changes alter active finding output or contract-visible report payload |
460463
| MCP interface (`codeclone/mcp_service.py`, `codeclone/mcp_server.py`, packaging extra/launcher) | `README.md`, `docs/book/20-mcp-interface.md`, `docs/mcp.md`, `docs/book/01-architecture-map.md`, `docs/book/14-compatibility-and-versioning.md`, `CHANGELOG.md` | `tests/test_mcp_service.py`, `tests/test_mcp_server.py`, plus CLI/package tests if launcher/install semantics change | tool/resource shapes, read-only semantics, optional-dependency packaging behavior change | public MCP tool names, resource URIs, launcher/install behavior, or response semantics change |
461-
| VS Code extension surface (`extensions/vscode-codeclone/*`) | `README.md`, `docs/book/21-vscode-extension.md`, `docs/vscode-extension.md`, `docs/book/01-architecture-map.md`, `docs/README.md`, `CHANGELOG.md` | `node --check extensions/vscode-codeclone/src/mcpClient.js`, `node --check extensions/vscode-codeclone/src/extension.js`; package smoke when manifest/assets change | command/view UX, trust/runtime model, source-first review flow, or packaging metadata change | documented commands/views/setup/trust behavior, packaged assets, or publish metadata change |
464+
| VS Code extension surface (`extensions/vscode-codeclone/*`) | `README.md`, `docs/book/21-vscode-extension.md`, `docs/vscode-extension.md`, `docs/book/01-architecture-map.md`, `docs/README.md`, `CHANGELOG.md` | `node --check extensions/vscode-codeclone/src/support.js`, `node --check extensions/vscode-codeclone/src/mcpClient.js`, `node --check extensions/vscode-codeclone/src/extension.js`, `node --test extensions/vscode-codeclone/test/*.test.js`, plus local extension-host smoke and package smoke when surface/manifest/assets change | command/view UX, trust/runtime model, source-first review flow, or packaging metadata change | documented commands/views/setup/trust behavior, packaged assets, or publish metadata change |
462465
| Docs site / sample report publication (`docs/`, `mkdocs.yml`, `.github/workflows/docs.yml`, `scripts/build_docs_example_report.py`) | `docs/README.md`, `docs/publishing.md`, `docs/examples/report.md`, and any contract pages surfaced by the change, `CHANGELOG.md` when user-visible behavior changes | `mkdocs build --strict`, sample-report generation smoke path, and relevant report/html tests if generated examples or embeds change | published docs navigation, sample-report generation, or Pages workflow semantics change | published documentation behavior or sample-report generation contract changes |
463466

464467
Golden rule: do not “fix” failures by snapshot refresh unless the underlying contract change is intentional, documented,

CHANGELOG.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
## [2.0.0b4]
44

55
2.0.0b4 deepens the platform model introduced in b3: MCP becomes more self-guiding, report-only analysis expands with
6-
module-level hotspot ranking, findings and suggestions are separated more cleanly by role, and Health Score
7-
documentation now formalizes how new signal families can be introduced gradually without pretending the scoring model is
8-
static.
6+
module-level hotspot ranking, findings and suggestions are separated more cleanly by role, Health Score documentation
7+
now formalizes phased score-model evolution, and CodeClone gains its first native IDE surface in preview.
98

109
### MCP server
1110

@@ -36,8 +35,13 @@ static.
3635

3736
### IDE integration
3837

39-
- Add a preview VS Code extension as a native, read-only control surface over `codeclone-mcp`, with baseline-aware,
40-
triage-first review flow, guided source-first drill-down, and explicit setup/session semantics.
38+
- Add a preview VS Code extension as the first native IDE surface for `codeclone-mcp`, bringing baseline-aware,
39+
triage-first structural review and guided source-first drill-down into the editor.
40+
- Establish the initial extension interaction model, including explicit setup/session semantics, review-loop navigation,
41+
hotspot focus persistence, lightweight Explorer decorations, safe HTML-report bridging, and accessibility/status
42+
polish.
43+
- Add extension-side regression coverage with Node unit tests, local extension-host smoke, and validated preview `.vsix`
44+
packaging.
4145

4246
## [2.0.0b3] - 20260401
4347

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,16 @@ It is:
200200
- triage-first
201201
- read-only with respect to repository state
202202
- powered by the same `codeclone-mcp` contract surface
203+
- limited in Restricted Mode until workspace trust is granted
204+
205+
It focuses on source-first structural review inside the editor: overview,
206+
hotspots, review loop, changed-files pass, and explicit drill-down into finding,
207+
remediation, or local HTML report when needed.
208+
209+
Docs:
210+
[VS Code extension guide](https://orenlab.github.io/codeclone/vscode-extension/)
211+
·
212+
[VS Code extension contract](https://orenlab.github.io/codeclone/book/21-vscode-extension/)
203213

204214
## Configuration
205215

docs/book/01-architecture-map.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ Main ownership layers:
1313
- Contracts and persistence: baseline, metrics baseline, cache, exit semantics.
1414
- Report model and projections: canonical JSON + deterministic TXT/Markdown/SARIF + explainability facts.
1515
- MCP agent surface: read-only server layer over the same pipeline/report contracts.
16-
- VS Code extension surface: native IDE client over the MCP layer and the same canonical report semantics.
16+
- VS Code extension surface: native IDE client over the MCP layer and the same canonical report semantics, with
17+
limited Restricted Mode and source-first review flow.
1718
- Render layer: HTML rendering and template assets.
1819

1920
## Data model
@@ -30,7 +31,7 @@ Main ownership layers:
3031
| Persistence | `codeclone/baseline.py`, `codeclone/metrics_baseline.py`, `codeclone/cache.py` | Baseline/cache trust/compat/integrity and atomic persistence |
3132
| Runtime orchestration | `codeclone/pipeline.py`, `codeclone/cli.py`, `codeclone/_cli_args.py`, `codeclone/_cli_paths.py`, `codeclone/_cli_summary.py`, `codeclone/_cli_config.py`, `codeclone/ui_messages.py` | CLI UX, stage orchestration, status handling, outputs, error markers |
3233
| MCP agent interface | `codeclone/mcp_service.py`, `codeclone/mcp_server.py` | Read-only MCP tools/resources over canonical analysis and report layers |
33-
| VS Code extension | `extensions/vscode-codeclone/*` | Native VS Code control surface over MCP, with triage-first review and source-first drill-down |
34+
| VS Code extension | `extensions/vscode-codeclone/*` | Native VS Code control surface over MCP, with limited Restricted Mode, triage-first review, and source-first drill-down |
3435
| Rendering | `codeclone/html_report.py`, `codeclone/_html_report/*`, `codeclone/_html_badges.py`, `codeclone/_html_js.py`, `codeclone/_html_escape.py`, `codeclone/_html_snippets.py`, `codeclone/templates.py` | HTML-only view layer over report data |
3536

3637
Refs:

docs/book/21-vscode-extension.md

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ The VS Code extension is:
1616
- read-only with respect to repository state
1717
- baseline-aware and triage-first
1818
- code-centered rather than report-dashboard-centered
19+
- limited in Restricted Mode and fully active only after workspace trust
1920

2021
The extension exists to make the current CodeClone review workflow easier to
2122
use inside the editor. It must not reinterpret report semantics or invent
@@ -49,7 +50,9 @@ It also provides:
4950
- command palette entry points for analysis and review
5051
- one onboarding walkthrough
5152
- markdown detail panels for findings, remediation, help topics, setup help,
52-
and report-only God Module detail
53+
restricted-mode guidance, and report-only God Module detail
54+
- lightweight Explorer file decorations for review-relevant files
55+
- editor-local CodeLens and title actions for the active review target
5356

5457
## Workflow model
5558

@@ -64,6 +67,23 @@ The intended IDE path mirrors CodeClone MCP:
6467
This is deliberately different from a lint-list model. The extension should
6568
prefer guided review over broad enumeration.
6669

70+
## Current capabilities
71+
72+
The extension currently supports:
73+
74+
- full-workspace analysis
75+
- changed-files analysis against a configured git diff reference
76+
- compact overview of structural health, current run state, and baseline drift
77+
- review queues for new regressions, production hotspots, changed-scope
78+
findings, and report-only `God Modules`
79+
- source reveal, peek, canonical finding detail, remediation detail, and
80+
session-local reviewed markers
81+
- bounded MCP help topics inside the IDE
82+
- explicit HTML-report bridge when a local HTML report already exists
83+
84+
These capabilities must remain clients of MCP and canonical report truth rather
85+
than parallel extension-only logic.
86+
6787
## State boundaries
6888

6989
The extension must keep three state classes visibly separate:
@@ -92,16 +112,34 @@ Reviewed markers:
92112

93113
The extension runs as a workspace extension and requires:
94114

95-
- a trusted workspace
96115
- local filesystem access
97116
- local git access for changed-files review
98117
- a local `codeclone-mcp` launcher, or an explicitly configured launcher
99118

100119
For this reason:
101120

102-
- untrusted workspaces are unsupported
121+
- Restricted Mode support is `limited`
122+
- untrusted workspaces may show setup/onboarding/help surfaces only
123+
- local analysis and local MCP startup remain disabled until trust is granted
103124
- virtual workspaces are unsupported
104125

126+
## Design decisions
127+
128+
The extension follows these implementation rules:
129+
130+
- **Native VS Code first**: tree views, status bar, Quick Pick, CodeLens, and
131+
file decorations come before any richer custom UI.
132+
- **Source-first review**: findings prefer `Reveal Source` over immediate
133+
detail panels.
134+
- **Explicit deepening**: canonical finding detail, remediation, and HTML
135+
report bridges remain opt-in actions.
136+
- **Report-only separation**: `God Modules` stay clearly outside findings,
137+
gates, and health dimensions.
138+
- **Safe local HTML bridge**: `Open in HTML Report` must verify that a local
139+
`report.html` exists and is not obviously older than the current run.
140+
- **Session-local workflow state**: reviewed markers may shape the review UX
141+
but must not leak into repository truth.
142+
105143
## UX rules
106144

107145
The extension should preserve these product rules:
@@ -114,6 +152,10 @@ The extension should preserve these product rules:
114152
findings, gates, and health dimensions.
115153
- The extension should minimize noise and avoid duplicating the HTML report in
116154
the sidebar.
155+
- Restricted Mode should still explain what the extension needs, without
156+
pretending local analysis is available before trust is granted.
157+
- Accessibility labels should stay meaningful on tree items and status
158+
surfaces.
117159

118160
## Relationship to other interfaces
119161

@@ -127,3 +169,5 @@ The extension should preserve these product rules:
127169
- Exact view grouping and copy may evolve between beta releases.
128170
- Internal client-side caching and view-model shaping may evolve as long as the
129171
extension remains faithful to MCP and canonical report semantics.
172+
- Explorer decoration styling, review-loop polish, and other non-contract UI
173+
details may evolve without changing the extension contract.

docs/vscode-extension.md

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ CodeClone ships a preview VS Code extension in
66
It is a native IDE surface over `codeclone-mcp` and is designed for
77
baseline-aware, triage-first structural review inside the editor.
88

9-
## What it does
9+
## What it is for
1010

1111
The extension helps you:
1212

@@ -15,6 +15,7 @@ The extension helps you:
1515
- focus on new regressions and production hotspots first
1616
- jump directly to source locations
1717
- open canonical finding or remediation detail only when needed
18+
- inspect report-only God Module candidates without treating them like findings
1819

1920
It does not create a second truth model and it does not mutate the repository.
2021

@@ -44,7 +45,7 @@ codeclone-mcp --help
4445

4546
### Overview
4647

47-
Compact health, current run state, and next-best review action.
48+
Compact health, current run state, baseline drift, and next-best review action.
4849

4950
### Hotspots
5051

@@ -64,6 +65,21 @@ Session-local state:
6465
- reviewed findings
6566
- MCP help topics
6667

68+
## Review model
69+
70+
The extension stays source-first:
71+
72+
- `Review Priorities` and `Next Hotspot` / `Previous Hotspot` drive the review
73+
loop
74+
- `Reveal Source` is the default action for findings
75+
- editor-local actions appear only when the current file matches the active
76+
review target
77+
- Explorer decorations stay lightweight and focus on new, production, or
78+
changed-scope relevance
79+
80+
`Open in HTML Report` exists as an explicit bridge to the richer human report,
81+
not as the primary IDE workflow.
82+
6783
## First-run path
6884

6985
1. Open the `CodeClone` view container.
@@ -75,12 +91,32 @@ If the launcher is missing, use `Setup Help` from the extension.
7591

7692
## Trust model
7793

78-
The extension requires a trusted local workspace and is not intended for
79-
virtual workspaces.
94+
The extension uses a **limited Restricted Mode**:
95+
96+
- onboarding and setup help remain available in untrusted workspaces
97+
- local analysis and the local MCP server stay disabled until workspace trust
98+
is granted
99+
100+
The extension is not intended for virtual workspaces.
80101

81102
That is intentional: CodeClone reads repository contents, local git state, and
82103
the local MCP launcher.
83104

105+
## Design decisions
106+
107+
- native VS Code views first, not a custom report dashboard
108+
- baseline-aware review instead of broad lint-style listing
109+
- report-only layers stay visually separate from findings and health
110+
- repository truth stays in CodeClone MCP and canonical report semantics
111+
112+
## Current limits
113+
114+
- no always-on background analysis
115+
- no `Problems`-panel duplication
116+
- no persistent reviewed markers across MCP sessions
117+
- `Open in HTML Report` opens a local HTML report only when it exists and looks
118+
fresh enough for the current run
119+
84120
## Source of truth
85121

86122
The extension reads the same canonical analysis semantics already exposed by:

extensions/vscode-codeclone/.vscodeignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ DESIGN.md
44
media/.thumb/**
55
media/icon-source.svg
66
*.vsix
7+
test/**

0 commit comments

Comments
 (0)