docs: record CAD semantic context and vector crop planning notes

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-16 16:42:34 +08:00
parent ac6f1d84af
commit e7a0cc0b86
3 changed files with 264 additions and 1 deletions
+89
View File
@@ -1,5 +1,35 @@
# Progress Log
## Session: 2026-07-15 (CAD Semantics and Crop)
### Phase 23
- Loaded the repository workflow plus planning, frontend, and Go implementation guidance.
- Added the CAD semantic-context and non-destructive crop request as new phases without changing unrelated work.
- Fixed the product invariants: preserve the source, create a sibling crop, and keep model semantics out of visible chat copy.
- Completed the end-to-end design across worker metadata, durable node context, hidden Agent Chat content, vector crop UI, sibling placement, and PostgreSQL persistence.
- Added the optional `semanticContext` node field to the API specification before generated/server implementation.
### Phase 24
- Added versioned CAD metadata containing bounded source/format/unit, drawing bounds, layer/block/entity counts, visible text, and crop-intersection entries.
- Persisted compact node semantic context through the API/domain/PostgreSQL/SQLC/canvas snapshot paths.
- Added hidden `cad-context` Agent Chat contents: model prompt and memory retain them, while optimistic and persisted user copy exclude them.
- Added vector-toolbar crop, transparent WebP output, crop-specific semantic filtering, right-side sibling placement, source preservation, and automatic selection/reference of the new crop.
- Focused Go application/logic/PostgreSQL tests pass; frontend typecheck and all 16 frontend tests pass.
- Repaired legacy GBK CAD labels and locked the behavior with a focused converter regression.
- Re-ran both supplied files: exact DXF semantics complete in 0.37s and exact DWG semantics in 11s, with bounded contexts of 1,050 and 1,912 characters respectively.
- Increased vector crop raster output to a 2048px long edge so small selections from large drawings remain useful to the image model; sibling canvas display stays bounded to 220-640px.
### Phase 25
- All 20 frontend tests pass, including CAD conversion, GBK labels, semantic crop filtering, immutable sibling creation, readable crop sizing, hidden model context, WebP submission, and vector recognition.
- `go mod tidy`, full `go test ./...`, `go build ./...`, API validation, locale parsing, frontend production build, and `git diff --check` pass.
- Browser setup again reported no available backend, so live crop/hover/request inspection could not be repeated; the active Vite preview still responds at `http://127.0.0.1:5174`.
- Restored the repository's pre-existing `frontend/next-env.d.ts` development route import after production builds.
### Phase 26
- Documented CAD semantic metadata, hidden Agent Chat context, durable node persistence, and non-destructive crop behavior in the root README and API guide.
- Completed final scope review without reverting unrelated worktree changes.
- Started an isolated updated backend on `http://127.0.0.1:8889` and the verified production frontend on `http://127.0.0.1:5175`; the proxied health endpoint returns the updated service successfully.
## Session: 2026-07-15 (Vector Reference Follow-up)
### Phases 21-22
@@ -105,6 +135,65 @@
## Session: 2026-07-15
- Started Phase 27 after reproducing the warning directly from the source stack: `.canvas-stage` uses React `onWheel`, and its handler calls `preventDefault()` at the reported line under a passive delegated listener.
- Added the listener-registration regression first; its red run fails because the non-passive canvas wheel adapter does not yet exist.
- Added the element-level wheel adapter, switched the canvas to the latest viewport ref, removed React `onWheel`, and preserved the existing interactive-surface bypass behavior.
- The focused non-passive registration/cleanup test, TypeScript build, and diff check now pass.
- Added Phase 28 after confirming Crop existed only in the selected-image/vector floating toolbar, not in `workspace-toolbar` as requested.
- Browser instrumentation found that the first native-listener effect ran before the project canvas mounted. Bound the effect to `project.id` so the non-passive listener attaches when `.canvas-stage` appears.
- Added the Crop icon immediately after Text, with a visible disabled state, active crop state, and selection-tool handoff before opening the existing overlay.
- Full frontend verification passes with 21 tests and both Next/Vite production builds. The supplied DWG still converts in about 10.5 seconds to a 9.06 MB semantic SVG with 748 reusable block instances.
- Browser verification confirms `Text -> Crop -> Image` ordering, disabled/enabled Crop states, active state, one mounted crop overlay, functional 100% -> 91% wheel zoom, and no passive-listener warnings.
- Restarted the verified frontend preview on `http://127.0.0.1:5175` against the existing updated backend on port 8889.
- Started Phase 29 from the enlarged single-image screenshot: the workspace Crop target currently resolves only from `selectedImageNode`, so the button remains disabled even though there is one obvious image target.
- Added visible-stage crop geometry regressions first; the red run failed on the intentionally missing viewport geometry exports.
- Added shared crop viewport geometry, single-visible-image target resolution, deferred auto-selection crop entry, and selection-anchored crop controls.
- All 23 frontend tests and the Next/Vite production build pass.
- Browser verification confirms the exact enlarged-single-image case and the multi-image ambiguity guard; the updated preview is running at `http://127.0.0.1:5175`.
- Confirmed the final compatibility boundary: old project CAD nodes will not be migrated or heuristically enriched; the user will re-upload source DWG/DXF files so every retained CAD node uses the current semantic conversion contract.
- Re-ran the final verification after removing legacy recovery scope: all 20 frontend tests, full Go tests, API validation, locale parsing, Go build, Next build, Vite build, and diff checks pass.
- Restored Next's development route type import after production build and restarted the updated preview at `http://127.0.0.1:5175`; its backend proxy to `http://127.0.0.1:8889` returns HTTP 200.
## Session: 2026-07-16
### Phase 31: Canvas Performance and LeaferJS Evaluation
- **Status:** complete
- Started a diagnosis-only performance pass after the user reported canvas lag and pointed to `leaferjs/leafer-ui` as the reference engine.
- The evaluation will establish browser frame-time and long-task baselines before deciding whether LeaferJS should replace the full renderer or only the high-cost visual layer.
- Mapped the current renderer as React/DOM with viewport state updates and full-array node updates on high-frequency interaction.
- Reviewed LeaferJS's retained scene tree, Canvas renderer, hit testing, interaction, and editor capabilities; vendor benchmark claims remain unverified for the application's CAD/image workload.
- Identified viewport-dependent props and fresh per-node callbacks/objects that defeat a simple memoization fix, plus full-document alignment and node-array work on each drag event.
- Confirmed the current LeaferJS package baseline (2.2.2, MIT) and kept dependency installation out of the diagnosis phase.
- Found per-update persistence effect/timer churn and prepared a node-count-scaled Playwright baseline for zoom and drag interactions.
- Reproduced near-linear interaction degradation from 100 to 500 to 1000 nodes, reaching roughly 83ms p95 frame intervals at 1000 nodes.
- Ran the differential control on the same 1000-node DOM: direct world and node transforms held about 9.2ms p95, confirming React-path overhead as the primary bottleneck.
- The initial exact-DWG paint fixture used the raw worker intermediate and correctly failed SVG decoding; switched the probe to capture the normalized asset from the real browser upload path.
- Captured the final 8.87 MB SVG from the real UI upload and measured a single CAD node at 158-192ms p95 during zoom.
- Proved the cached-texture control: a one-time 1200 x 839 transparent WebP display preview reduced the same interaction to 9.2ms p95 while leaving the source contract separable.
- Confirmed that both the general retained renderer and complex-vector texture caching are required; neither optimization alone covers the reported workload.
- Mapped LeaferJS `App` ground/tree/sky layers, imperative `zoomLayer`, image caching, and editor events onto the existing canvas domain and React overlay responsibilities.
- Benchmarked LeaferJS itself rather than relying on vendor claims: 1000 rectangles held 9.2ms p95, compared with about 83ms in the current React path.
- Demonstrated that raw complex SVG remains slow in Leafer (275.4ms p95), while an application-owned transparent WebP texture restores 9.1ms p95.
- Completed the evaluation with an incremental renderer-adapter and vector texture-LOD recommendation; no production dependency or renderer code was changed during diagnosis.
### Phase 32: Leafer Renderer and Vector Texture Cache
- **Status:** in_progress
- Started the production implementation after user approval, using the existing `CanvasNode[]` and SVG/CAD semantic contracts as the source of truth.
- Chosen boundary: persist a separate render-preview URL, render supported visual nodes through LeaferJS, and keep React UI/overlays plus source-based crop/export/model behavior.
- Traced the explicit canvas-node field through the API/domain/PostgreSQL/snapshot layers and the paired source/preview upload changes needed for atomic vector imports.
### Phase 30: Native-Resolution Vector Crop Fidelity
- **Status:** in_progress
- Reproduced the user-visible symptom from the supplied comparison: the cropped transparent WebP has substantially thicker CAD strokes and degraded text/detail than the source SVG.
- Ranked the likely causes: low-resolution SVG rasterization followed by pixel upscaling, incorrect viewBox mapping, display-size mismatch, then WebP compression.
- Started a focused regression loop around SVG viewBox cropping and final-resolution rendering while preserving the existing raster crop path.
- Added the red regression for normalized crop mapping against a non-zero SVG viewBox, then implemented the mapping and final-size source preparation.
- Moved the browser SVG rewrite into the exported `createCroppedSvgRasterSource` production seam; `CanvasWorkspace` now draws the rewritten crop once at its final output dimensions while raster images retain the existing source-rectangle crop.
- Chromium verification measured a representative non-scaling CAD stroke at 82px through the old low-resolution upscale and 4px through the new native crop, unchanged after transparent WebP encoding.
- Reconfirmed that crop-specific CAD context travels with the sibling reference as hidden `cad-context` and remains available to the image-generation backend.
- Full verification passes: 24 frontend tests, `pnpm exec tsc -b`, `go test ./...`, `go build ./...`, Next/Vite production builds, and `git diff --check`.
- Restored Next's development route type import after the production build and restarted the updated preview at `http://127.0.0.1:5175`; the page and backend proxy return HTTP 200 with no browser console errors.
### Phase 15: CAD Import Discovery and Design
- **Status:** in_progress
- Loaded the repository go-zero instructions plus the applicable Go, frontend, and file-planning skills.