@rien7/seji 0.0.0-stage → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/design-surface.mjs +6 -0
- package/bin/postinstall.mjs +19 -0
- package/bin/seji.mjs +573 -0
- package/dist/agent/host.d.mts +34 -0
- package/dist/agent/host.mjs +387 -0
- package/dist/agent/messages.d.mts +9 -0
- package/dist/agent/messages.mjs +70 -0
- package/dist/agent/runtimes.mjs +157 -0
- package/dist/cli/app.mjs +321 -0
- package/dist/cli/appScan.mjs +284 -0
- package/dist/cli/catalog.mjs +78 -0
- package/dist/cli/component.mjs +165 -0
- package/dist/cli/consolidate.mjs +159 -0
- package/dist/cli/cssImport.mjs +68 -0
- package/dist/cli/dev.mjs +335 -0
- package/dist/cli/doctor.mjs +306 -0
- package/dist/cli/init.mjs +338 -0
- package/dist/cli/legacyNames.mjs +266 -0
- package/dist/cli/migrate.mjs +163 -0
- package/dist/cli/prompt.mjs +34 -0
- package/dist/cli/propose.mjs +208 -0
- package/dist/cli/providers.mjs +344 -0
- package/dist/cli/reviewOps.mjs +110 -0
- package/dist/cli/semver.mjs +45 -0
- package/dist/cli/setup.mjs +357 -0
- package/dist/cli/sketches.mjs +47 -0
- package/dist/cli/skills.mjs +150 -0
- package/dist/cli/snapshot.mjs +107 -0
- package/dist/cli/tokenOps.mjs +120 -0
- package/dist/cli/types.mjs +191 -0
- package/dist/cli/updater.mjs +274 -0
- package/dist/components/astIndex.mjs +992 -0
- package/dist/components/ops.mjs +1069 -0
- package/dist/editor/AgentProposalCard.d.ts +10 -0
- package/dist/editor/AgentProposalCard.d.ts.map +1 -0
- package/dist/editor/AgentProposalCard.js +31 -0
- package/dist/editor/AgentProposalCard.js.map +1 -0
- package/dist/editor/App.d.ts +2 -0
- package/dist/editor/App.d.ts.map +1 -0
- package/dist/editor/App.js +2832 -0
- package/dist/editor/App.js.map +1 -0
- package/dist/editor/CanvasHud.d.ts +12 -0
- package/dist/editor/CanvasHud.d.ts.map +1 -0
- package/dist/editor/CanvasHud.js +13 -0
- package/dist/editor/CanvasHud.js.map +1 -0
- package/dist/editor/CanvasSurface.d.ts +31 -0
- package/dist/editor/CanvasSurface.d.ts.map +1 -0
- package/dist/editor/CanvasSurface.js +270 -0
- package/dist/editor/CanvasSurface.js.map +1 -0
- package/dist/editor/CommentPopover.d.ts +17 -0
- package/dist/editor/CommentPopover.d.ts.map +1 -0
- package/dist/editor/CommentPopover.js +62 -0
- package/dist/editor/CommentPopover.js.map +1 -0
- package/dist/editor/Comments.d.ts +13 -0
- package/dist/editor/Comments.d.ts.map +1 -0
- package/dist/editor/Comments.js +41 -0
- package/dist/editor/Comments.js.map +1 -0
- package/dist/editor/ComponentPage.d.ts +28 -0
- package/dist/editor/ComponentPage.d.ts.map +1 -0
- package/dist/editor/ComponentPage.js +55 -0
- package/dist/editor/ComponentPage.js.map +1 -0
- package/dist/editor/ComponentPanel.d.ts +38 -0
- package/dist/editor/ComponentPanel.d.ts.map +1 -0
- package/dist/editor/ComponentPanel.js +275 -0
- package/dist/editor/ComponentPanel.js.map +1 -0
- package/dist/editor/Glyph.d.ts +51 -0
- package/dist/editor/Glyph.d.ts.map +1 -0
- package/dist/editor/Glyph.js +50 -0
- package/dist/editor/Glyph.js.map +1 -0
- package/dist/editor/History.d.ts +7 -0
- package/dist/editor/History.d.ts.map +1 -0
- package/dist/editor/History.js +51 -0
- package/dist/editor/History.js.map +1 -0
- package/dist/editor/Inspector.d.ts +56 -0
- package/dist/editor/Inspector.d.ts.map +1 -0
- package/dist/editor/Inspector.js +510 -0
- package/dist/editor/Inspector.js.map +1 -0
- package/dist/editor/LazyMount.d.ts +10 -0
- package/dist/editor/LazyMount.d.ts.map +1 -0
- package/dist/editor/LazyMount.js +29 -0
- package/dist/editor/LazyMount.js.map +1 -0
- package/dist/editor/LocaleSwitch.d.ts +3 -0
- package/dist/editor/LocaleSwitch.d.ts.map +1 -0
- package/dist/editor/LocaleSwitch.js +9 -0
- package/dist/editor/LocaleSwitch.js.map +1 -0
- package/dist/editor/PreviewFrame.d.ts +10 -0
- package/dist/editor/PreviewFrame.d.ts.map +1 -0
- package/dist/editor/PreviewFrame.js +22 -0
- package/dist/editor/PreviewFrame.js.map +1 -0
- package/dist/editor/ProjectIndex.d.ts +12 -0
- package/dist/editor/ProjectIndex.d.ts.map +1 -0
- package/dist/editor/ProjectIndex.js +43 -0
- package/dist/editor/ProjectIndex.js.map +1 -0
- package/dist/editor/PromoteComponent.d.ts +28 -0
- package/dist/editor/PromoteComponent.d.ts.map +1 -0
- package/dist/editor/PromoteComponent.js +33 -0
- package/dist/editor/PromoteComponent.js.map +1 -0
- package/dist/editor/PromoteForm.d.ts +18 -0
- package/dist/editor/PromoteForm.d.ts.map +1 -0
- package/dist/editor/PromoteForm.js +35 -0
- package/dist/editor/PromoteForm.js.map +1 -0
- package/dist/editor/PromoteToken.d.ts +31 -0
- package/dist/editor/PromoteToken.d.ts.map +1 -0
- package/dist/editor/PromoteToken.js +94 -0
- package/dist/editor/PromoteToken.js.map +1 -0
- package/dist/editor/StatePreviews.d.ts +28 -0
- package/dist/editor/StatePreviews.d.ts.map +1 -0
- package/dist/editor/StatePreviews.js +113 -0
- package/dist/editor/StatePreviews.js.map +1 -0
- package/dist/editor/ValueCombo.d.ts +51 -0
- package/dist/editor/ValueCombo.d.ts.map +1 -0
- package/dist/editor/ValueCombo.js +260 -0
- package/dist/editor/ValueCombo.js.map +1 -0
- package/dist/editor/agent/AgentPanel.d.ts +19 -0
- package/dist/editor/agent/AgentPanel.d.ts.map +1 -0
- package/dist/editor/agent/AgentPanel.js +271 -0
- package/dist/editor/agent/AgentPanel.js.map +1 -0
- package/dist/editor/agent/Markdown.d.ts +5 -0
- package/dist/editor/agent/Markdown.d.ts.map +1 -0
- package/dist/editor/agent/Markdown.js +28 -0
- package/dist/editor/agent/Markdown.js.map +1 -0
- package/dist/editor/agent/agentApi.d.ts +106 -0
- package/dist/editor/agent/agentApi.d.ts.map +1 -0
- package/dist/editor/agent/agentApi.js +66 -0
- package/dist/editor/agent/agentApi.js.map +1 -0
- package/dist/editor/agent/toolLines.d.ts +38 -0
- package/dist/editor/agent/toolLines.d.ts.map +1 -0
- package/dist/editor/agent/toolLines.js +159 -0
- package/dist/editor/agent/toolLines.js.map +1 -0
- package/dist/editor/agent/useAgent.d.ts +15 -0
- package/dist/editor/agent/useAgent.d.ts.map +1 -0
- package/dist/editor/agent/useAgent.js +65 -0
- package/dist/editor/agent/useAgent.js.map +1 -0
- package/dist/editor/api.d.ts +378 -0
- package/dist/editor/api.d.ts.map +1 -0
- package/dist/editor/api.js +247 -0
- package/dist/editor/api.js.map +1 -0
- package/dist/editor/camera.d.ts +18 -0
- package/dist/editor/camera.d.ts.map +1 -0
- package/dist/editor/camera.js +40 -0
- package/dist/editor/camera.js.map +1 -0
- package/dist/editor/canvas.d.ts +25 -0
- package/dist/editor/canvas.d.ts.map +1 -0
- package/dist/editor/canvas.js +35 -0
- package/dist/editor/canvas.js.map +1 -0
- package/dist/editor/changes/ChangesPage.d.ts +25 -0
- package/dist/editor/changes/ChangesPage.d.ts.map +1 -0
- package/dist/editor/changes/ChangesPage.js +132 -0
- package/dist/editor/changes/ChangesPage.js.map +1 -0
- package/dist/editor/changes/changeModel.d.ts +25 -0
- package/dist/editor/changes/changeModel.d.ts.map +1 -0
- package/dist/editor/changes/changeModel.js +81 -0
- package/dist/editor/changes/changeModel.js.map +1 -0
- package/dist/editor/changes/changeState.d.mts +29 -0
- package/dist/editor/changes/changeState.mjs +187 -0
- package/dist/editor/chrome/EditorChrome.d.ts +49 -0
- package/dist/editor/chrome/EditorChrome.d.ts.map +1 -0
- package/dist/editor/chrome/EditorChrome.js +21 -0
- package/dist/editor/chrome/EditorChrome.js.map +1 -0
- package/dist/editor/drafts.d.ts +46 -0
- package/dist/editor/drafts.d.ts.map +1 -0
- package/dist/editor/drafts.js +38 -0
- package/dist/editor/drafts.js.map +1 -0
- package/dist/editor/i18n.d.ts +29 -0
- package/dist/editor/i18n.d.ts.map +1 -0
- package/dist/editor/i18n.js +2320 -0
- package/dist/editor/i18n.js.map +1 -0
- package/dist/editor/iconStroke.d.ts +6 -0
- package/dist/editor/iconStroke.d.ts.map +1 -0
- package/dist/editor/iconStroke.js +6 -0
- package/dist/editor/iconStroke.js.map +1 -0
- package/dist/editor/main.d.ts +2 -0
- package/dist/editor/main.d.ts.map +1 -0
- package/dist/editor/main.js +14 -0
- package/dist/editor/main.js.map +1 -0
- package/dist/editor/model.d.ts +16 -0
- package/dist/editor/model.d.ts.map +1 -0
- package/dist/editor/model.js +11 -0
- package/dist/editor/model.js.map +1 -0
- package/dist/editor/reasons.d.ts +44 -0
- package/dist/editor/reasons.d.ts.map +1 -0
- package/dist/editor/reasons.js +131 -0
- package/dist/editor/reasons.js.map +1 -0
- package/dist/editor/reviewLifecycle.d.ts +8 -0
- package/dist/editor/reviewLifecycle.d.ts.map +1 -0
- package/dist/editor/reviewLifecycle.js +21 -0
- package/dist/editor/reviewLifecycle.js.map +1 -0
- package/dist/editor/styles.css +8737 -0
- package/dist/editor/tokenMatch.d.ts +59 -0
- package/dist/editor/tokenMatch.d.ts.map +1 -0
- package/dist/editor/tokenMatch.js +198 -0
- package/dist/editor/tokenMatch.js.map +1 -0
- package/dist/editor/tokens/ConsolidatePage.d.ts +16 -0
- package/dist/editor/tokens/ConsolidatePage.d.ts.map +1 -0
- package/dist/editor/tokens/ConsolidatePage.js +244 -0
- package/dist/editor/tokens/ConsolidatePage.js.map +1 -0
- package/dist/editor/tokens/TokenActivity.d.ts +18 -0
- package/dist/editor/tokens/TokenActivity.d.ts.map +1 -0
- package/dist/editor/tokens/TokenActivity.js +18 -0
- package/dist/editor/tokens/TokenActivity.js.map +1 -0
- package/dist/editor/tokens/TokenDialogs.d.ts +26 -0
- package/dist/editor/tokens/TokenDialogs.d.ts.map +1 -0
- package/dist/editor/tokens/TokenDialogs.js +119 -0
- package/dist/editor/tokens/TokenDialogs.js.map +1 -0
- package/dist/editor/tokens/TokenList.d.ts +21 -0
- package/dist/editor/tokens/TokenList.d.ts.map +1 -0
- package/dist/editor/tokens/TokenList.js +98 -0
- package/dist/editor/tokens/TokenList.js.map +1 -0
- package/dist/editor/tokens/TokenPage.d.ts +25 -0
- package/dist/editor/tokens/TokenPage.d.ts.map +1 -0
- package/dist/editor/tokens/TokenPage.js +108 -0
- package/dist/editor/tokens/TokenPage.js.map +1 -0
- package/dist/editor/tokens/tokenModel.d.ts +35 -0
- package/dist/editor/tokens/tokenModel.d.ts.map +1 -0
- package/dist/editor/tokens/tokenModel.js +72 -0
- package/dist/editor/tokens/tokenModel.js.map +1 -0
- package/dist/editor/ui/Button.d.ts +3 -0
- package/dist/editor/ui/Button.d.ts.map +1 -0
- package/dist/editor/ui/Button.js +6 -0
- package/dist/editor/ui/Button.js.map +1 -0
- package/dist/editor/ui/CommentBox.d.ts +23 -0
- package/dist/editor/ui/CommentBox.d.ts.map +1 -0
- package/dist/editor/ui/CommentBox.js +41 -0
- package/dist/editor/ui/CommentBox.js.map +1 -0
- package/dist/editor/ui/Icon.d.ts +8 -0
- package/dist/editor/ui/Icon.d.ts.map +1 -0
- package/dist/editor/ui/Icon.js +6 -0
- package/dist/editor/ui/Icon.js.map +1 -0
- package/dist/editor/ui/IconButton.d.ts +11 -0
- package/dist/editor/ui/IconButton.d.ts.map +1 -0
- package/dist/editor/ui/IconButton.js +6 -0
- package/dist/editor/ui/IconButton.js.map +1 -0
- package/dist/editor/ui/NumberInput.d.ts +14 -0
- package/dist/editor/ui/NumberInput.d.ts.map +1 -0
- package/dist/editor/ui/NumberInput.js +6 -0
- package/dist/editor/ui/NumberInput.js.map +1 -0
- package/dist/editor/ui/PageLine.d.ts +14 -0
- package/dist/editor/ui/PageLine.d.ts.map +1 -0
- package/dist/editor/ui/PageLine.js +7 -0
- package/dist/editor/ui/PageLine.js.map +1 -0
- package/dist/editor/ui/SearchPicker.d.ts +41 -0
- package/dist/editor/ui/SearchPicker.d.ts.map +1 -0
- package/dist/editor/ui/SearchPicker.js +82 -0
- package/dist/editor/ui/SearchPicker.js.map +1 -0
- package/dist/editor/ui/Select.d.ts +19 -0
- package/dist/editor/ui/Select.d.ts.map +1 -0
- package/dist/editor/ui/Select.js +12 -0
- package/dist/editor/ui/Select.js.map +1 -0
- package/dist/editor/ui/TokenField.d.ts +14 -0
- package/dist/editor/ui/TokenField.d.ts.map +1 -0
- package/dist/editor/ui/TokenField.js +41 -0
- package/dist/editor/ui/TokenField.js.map +1 -0
- package/dist/editor/ui/TokenPicker.d.ts +31 -0
- package/dist/editor/ui/TokenPicker.d.ts.map +1 -0
- package/dist/editor/ui/TokenPicker.js +26 -0
- package/dist/editor/ui/TokenPicker.js.map +1 -0
- package/dist/editor/useBuildError.d.ts +7 -0
- package/dist/editor/useBuildError.d.ts.map +1 -0
- package/dist/editor/useBuildError.js +30 -0
- package/dist/editor/useBuildError.js.map +1 -0
- package/dist/editor/useLatestRequest.d.ts +22 -0
- package/dist/editor/useLatestRequest.d.ts.map +1 -0
- package/dist/editor/useLatestRequest.js +49 -0
- package/dist/editor/useLatestRequest.js.map +1 -0
- package/dist/editor-bundle/editor.css +2 -0
- package/dist/editor-bundle/editor.js +83 -0
- package/dist/editor-ui.d.ts +15 -0
- package/dist/editor-ui.d.ts.map +1 -0
- package/dist/editor-ui.js +14 -0
- package/dist/editor-ui.js.map +1 -0
- package/dist/inspector/runtime.d.ts +18 -0
- package/dist/inspector/runtime.d.ts.map +1 -0
- package/dist/inspector/runtime.js +1280 -0
- package/dist/inspector/runtime.js.map +1 -0
- package/dist/preview/main.d.ts +3 -0
- package/dist/preview/main.d.ts.map +1 -0
- package/dist/preview/main.js +320 -0
- package/dist/preview/main.js.map +1 -0
- package/dist/preview/preview.css +40 -0
- package/dist/runtime/index.d.ts +3 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +2 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/shared/buildError.d.mts +27 -0
- package/dist/shared/buildError.mjs +141 -0
- package/dist/shared/cameraFit.d.mts +16 -0
- package/dist/shared/cameraFit.mjs +47 -0
- package/dist/shared/canvasLayout.d.mts +13 -0
- package/dist/shared/canvasLayout.mjs +171 -0
- package/dist/shared/commentShots.d.mts +12 -0
- package/dist/shared/commentShots.mjs +53 -0
- package/dist/shared/componentExtract.d.mts +43 -0
- package/dist/shared/componentExtract.mjs +136 -0
- package/dist/shared/componentMeta.d.mts +26 -0
- package/dist/shared/componentMeta.mjs +87 -0
- package/dist/shared/componentOps.d.mts +70 -0
- package/dist/shared/componentOps.mjs +407 -0
- package/dist/shared/componentTarget.d.mts +15 -0
- package/dist/shared/componentTarget.mjs +58 -0
- package/dist/shared/components.d.mts +30 -0
- package/dist/shared/components.mjs +106 -0
- package/dist/shared/consolidateCategories.d.mts +2 -0
- package/dist/shared/consolidateCategories.mjs +6 -0
- package/dist/shared/env.d.mts +4 -0
- package/dist/shared/env.mjs +18 -0
- package/dist/shared/gitChanges.d.mts +2 -0
- package/dist/shared/gitChanges.mjs +30 -0
- package/dist/shared/oklab.d.mts +6 -0
- package/dist/shared/oklab.mjs +56 -0
- package/dist/shared/optimizeEntries.d.mts +5 -0
- package/dist/shared/optimizeEntries.mjs +24 -0
- package/dist/shared/packages.d.mts +11 -0
- package/dist/shared/packages.mjs +96 -0
- package/dist/shared/projectFiles.d.mts +23 -0
- package/dist/shared/projectFiles.mjs +72 -0
- package/dist/shared/prompt.d.mts +20 -0
- package/dist/shared/prompt.mjs +201 -0
- package/dist/shared/proposals.d.mts +11 -0
- package/dist/shared/proposals.mjs +42 -0
- package/dist/shared/protocol.d.ts +122 -0
- package/dist/shared/protocol.d.ts.map +1 -0
- package/dist/shared/protocol.js +7 -0
- package/dist/shared/protocol.js.map +1 -0
- package/dist/shared/reviewArchive.d.mts +4 -0
- package/dist/shared/reviewArchive.mjs +19 -0
- package/dist/shared/reviewStore.d.mts +30 -0
- package/dist/shared/reviewStore.mjs +218 -0
- package/dist/shared/reviewVerify.d.mts +21 -0
- package/dist/shared/reviewVerify.mjs +158 -0
- package/dist/shared/sizeModes.d.mts +15 -0
- package/dist/shared/sizeModes.mjs +53 -0
- package/dist/shared/sketches.d.mts +10 -0
- package/dist/shared/sketches.mjs +64 -0
- package/dist/shared/snapshotCheck.d.mts +13 -0
- package/dist/shared/snapshotCheck.mjs +81 -0
- package/dist/shared/timeout.d.mts +1 -0
- package/dist/shared/timeout.mjs +15 -0
- package/dist/shared/tokens.d.ts +2 -0
- package/dist/shared/tokens.d.ts.map +1 -0
- package/dist/shared/tokens.js +2 -0
- package/dist/shared/tokens.js.map +1 -0
- package/dist/shared/types.d.ts +689 -0
- package/dist/shared/types.d.ts.map +1 -0
- package/dist/shared/types.js +13 -0
- package/dist/shared/types.js.map +1 -0
- package/dist/shared/wheelRouting.d.mts +9 -0
- package/dist/shared/wheelRouting.mjs +31 -0
- package/dist/shared/writeScope.mjs +96 -0
- package/dist/snapshots/diff.d.mts +28 -0
- package/dist/snapshots/diff.mjs +263 -0
- package/dist/snapshots/index.d.mts +110 -0
- package/dist/snapshots/index.mjs +638 -0
- package/dist/snapshots/render.d.mts +24 -0
- package/dist/snapshots/render.mjs +250 -0
- package/dist/snapshots/toolOps.d.mts +25 -0
- package/dist/snapshots/toolOps.mjs +69 -0
- package/dist/tokens/adapters/css.mjs +51 -0
- package/dist/tokens/adapters/cssInCode.mjs +314 -0
- package/dist/tokens/adapters/oxcShared.mjs +80 -0
- package/dist/tokens/adapters/preprocessor.mjs +63 -0
- package/dist/tokens/adapters/registry.mjs +53 -0
- package/dist/tokens/adapters/tailwindcss.mjs +424 -0
- package/dist/tokens/adapters/types.mjs +117 -0
- package/dist/tokens/consolidate/index.d.mts +42 -0
- package/dist/tokens/consolidate/index.mjs +111 -0
- package/dist/tokens/consolidate/normalize.mjs +479 -0
- package/dist/tokens/consolidate/plan.mjs +726 -0
- package/dist/tokens/consolidate/scan.mjs +928 -0
- package/dist/tokens/extract.mjs +441 -0
- package/dist/tokens/moduleData.d.mts +14 -0
- package/dist/tokens/moduleData.mjs +32 -0
- package/dist/tokens/opLock.d.mts +4 -0
- package/dist/tokens/opLock.mjs +108 -0
- package/dist/tokens/ops.d.mts +71 -0
- package/dist/tokens/ops.mjs +1511 -0
- package/dist/tokens/pipeline.mjs +813 -0
- package/dist/tokens/report.d.mts +47 -0
- package/dist/tokens/report.mjs +257 -0
- package/dist/tokens/rewrite/code.mjs +172 -0
- package/dist/tokens/rewrite/css.mjs +154 -0
- package/dist/tokens/rewrite/index.mjs +244 -0
- package/dist/tokens/rewrite/tailwind.mjs +288 -0
- package/dist/tokens/rewrite/text.mjs +116 -0
- package/dist/tokens/rewrite/value.mjs +115 -0
- package/dist/tokens/usage.d.mts +97 -0
- package/dist/tokens/usage.mjs +680 -0
- package/dist/vite/agent.d.ts +21 -0
- package/dist/vite/agent.d.ts.map +1 -0
- package/dist/vite/agent.js +165 -0
- package/dist/vite/agent.js.map +1 -0
- package/dist/vite/events.d.ts +27 -0
- package/dist/vite/events.d.ts.map +1 -0
- package/dist/vite/events.js +156 -0
- package/dist/vite/events.js.map +1 -0
- package/dist/vite/layout.d.ts +2 -0
- package/dist/vite/layout.d.ts.map +1 -0
- package/dist/vite/layout.js +4 -0
- package/dist/vite/layout.js.map +1 -0
- package/dist/vite/plugin.d.ts +40 -0
- package/dist/vite/plugin.d.ts.map +1 -0
- package/dist/vite/plugin.js +1255 -0
- package/dist/vite/plugin.js.map +1 -0
- package/dist/vite/requestGuard.d.mts +3 -0
- package/dist/vite/requestGuard.mjs +43 -0
- package/dist/vite/review.d.ts +11 -0
- package/dist/vite/review.d.ts.map +1 -0
- package/dist/vite/review.js +283 -0
- package/dist/vite/review.js.map +1 -0
- package/package.json +104 -4
- package/skills/seji/SKILL.md +395 -0
- package/skills/seji-authoring/SKILL.md +397 -0
- package/skills/seji-tokens/SKILL.md +432 -0
- package/README.md +0 -3
|
@@ -0,0 +1,638 @@
|
|
|
1
|
+
// Snapshot comparison for review items.
|
|
2
|
+
//
|
|
3
|
+
// For each review item we render the screens it affects (found through the usage index)
|
|
4
|
+
// before the change (baseline) and after it (on verify), pixel-diff them, and store the
|
|
5
|
+
// result on the item (`item.snapshots`). Humans accept or reject each changed snapshot;
|
|
6
|
+
// a rejection reopens the item with the reason so the agent can fix it.
|
|
7
|
+
//
|
|
8
|
+
// Storage (gitignored, regenerated on demand):
|
|
9
|
+
// design/.seji/snapshots/<design>/<item>/before/<design>__<page>__<frame>-<hash>.png
|
|
10
|
+
// /after/…png
|
|
11
|
+
// /diff/…png
|
|
12
|
+
import { createHash, randomUUID } from 'node:crypto'
|
|
13
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
14
|
+
import { dirname, join, relative, resolve, sep } from 'node:path'
|
|
15
|
+
|
|
16
|
+
import { SAFE_DESIGN_ID, mutateReview, readReviewFile, reviewFilePath } from '../shared/reviewStore.mjs'
|
|
17
|
+
import { CAPTURE_STALE_MS, isCapturingBaseline, snapshotCheck, summarizeFrames } from '../shared/snapshotCheck.mjs'
|
|
18
|
+
import { buildUsageIndex } from '../tokens/usage.mjs'
|
|
19
|
+
import { comparePngs } from './diff.mjs'
|
|
20
|
+
import { createRenderer } from './render.mjs'
|
|
21
|
+
|
|
22
|
+
export { isCapturingBaseline, snapshotArchiveHold, snapshotCheck, summarizeFrames } from '../shared/snapshotCheck.mjs'
|
|
23
|
+
|
|
24
|
+
export const SNAPSHOT_DIR = 'design/.seji/snapshots'
|
|
25
|
+
export const SNAPSHOT_KINDS = ['before', 'after', 'diff']
|
|
26
|
+
const DEFAULT_MAX_FRAMES = 60
|
|
27
|
+
|
|
28
|
+
const toPosix = (value) => value.split(sep).join('/')
|
|
29
|
+
const sha1 = (value) => createHash('sha1').update(value).digest('hex')
|
|
30
|
+
const safePart = (value) => String(value).replace(/[^A-Za-z0-9_-]+/g, '_').replace(/^_+|_+$/g, '') || '_'
|
|
31
|
+
|
|
32
|
+
/** Directory name for an item id (ids can contain spaces, `>`, …). */
|
|
33
|
+
export function itemDirName(id) {
|
|
34
|
+
return `${safePart(id).slice(0, 48)}-${sha1(String(id)).slice(0, 8)}`
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const frameKey = ({ design, page, frame }) => `${design}/${page}__${frame}`
|
|
38
|
+
// The hash keeps keys apart that clean to the same name (`a.b` / `a_b`).
|
|
39
|
+
const frameFile = (key) => `${safePart(key.replace('/', '__')).slice(0, 96)}-${sha1(key).slice(0, 8)}.png`
|
|
40
|
+
|
|
41
|
+
function ensureIgnored(root) {
|
|
42
|
+
const base = resolve(root, 'design', '.seji')
|
|
43
|
+
const ignore = join(base, '.gitignore')
|
|
44
|
+
if (existsSync(ignore)) return
|
|
45
|
+
mkdirSync(base, { recursive: true })
|
|
46
|
+
writeFileSync(ignore, '# seji snapshots and caches (regenerated on demand)\n*\n')
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function itemDir(root, design, itemId) {
|
|
50
|
+
if (!SAFE_DESIGN_ID.test(design)) throw new Error(`Invalid design id: ${design}`)
|
|
51
|
+
return resolve(root, SNAPSHOT_DIR, design, itemDirName(itemId))
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function writeImage(root, design, itemId, kind, key, buffer) {
|
|
55
|
+
ensureIgnored(root)
|
|
56
|
+
const file = join(itemDir(root, design, itemId), kind, frameFile(key))
|
|
57
|
+
mkdirSync(dirname(file), { recursive: true })
|
|
58
|
+
writeFileSync(file, buffer)
|
|
59
|
+
return toPosix(relative(root, file))
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Absolute path of a stored snapshot image, or null. Only paths inside the snapshot dir resolve. */
|
|
63
|
+
export function snapshotImagePath(root, design, itemId, key, kind) {
|
|
64
|
+
if (!SNAPSHOT_KINDS.includes(kind) || !SAFE_DESIGN_ID.test(String(design))) return null
|
|
65
|
+
const base = resolve(root, SNAPSHOT_DIR)
|
|
66
|
+
const file = join(itemDir(root, design, itemId), kind, frameFile(key))
|
|
67
|
+
if (!file.startsWith(`${base}${sep}`) || !existsSync(file)) return null
|
|
68
|
+
return file
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Screens a review item affects. Token items use the usage index (screens of the token and of
|
|
73
|
+
* every token that aliases it); node-scoped items use their own frame. Falls back to every
|
|
74
|
+
* artboard of the item's design when nothing narrower is known.
|
|
75
|
+
*/
|
|
76
|
+
export function affectedTargets(item, index) {
|
|
77
|
+
const design = item.design
|
|
78
|
+
// A consolidation replaces literals anywhere in the scanned scope, not only where its
|
|
79
|
+
// subject token is used: the whole design is the honest target.
|
|
80
|
+
if (item.tokenAction === 'consolidate') {
|
|
81
|
+
return [{ design, reason: `consolidation (${item.tokenOp?.plan ?? 'plan'}) replaces literals across the scanned files` }]
|
|
82
|
+
}
|
|
83
|
+
if (item.target?.type === 'token') {
|
|
84
|
+
const tokens = [item.target.token]
|
|
85
|
+
if ((item.tokenAction === 'alias' || item.tokenAction === 'merge') && typeof item.to === 'string') {
|
|
86
|
+
tokens.push(item.to)
|
|
87
|
+
}
|
|
88
|
+
const targets = new Map()
|
|
89
|
+
for (const token of tokens) {
|
|
90
|
+
const report = index?.tokenUsage(token)
|
|
91
|
+
for (const screen of report?.screens ?? []) {
|
|
92
|
+
const key = `${screen.design}\0${screen.page ?? ''}`
|
|
93
|
+
if (!targets.has(key)) {
|
|
94
|
+
targets.set(key, {
|
|
95
|
+
design: screen.design,
|
|
96
|
+
...(screen.page ? { page: screen.page } : {}),
|
|
97
|
+
reason: `${report.token}: ${screen.match.join('; ')}`,
|
|
98
|
+
})
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// A whole-design target covers that design's page targets.
|
|
103
|
+
const whole = new Set([...targets.values()].filter((t) => !t.page).map((t) => t.design))
|
|
104
|
+
const list = [...targets.values()].filter((t) => !t.page || !whole.has(t.design))
|
|
105
|
+
if (list.length) return list
|
|
106
|
+
return [{ design, reason: `usage index found no screens for ${item.target.token}; using design ${design}` }]
|
|
107
|
+
}
|
|
108
|
+
if (item.page && item.frame) {
|
|
109
|
+
const frame = item.frame.startsWith(`${item.page}__`) ? item.frame.slice(item.page.length + 2) : item.frame
|
|
110
|
+
return [{ design, page: item.page, frame, reason: `${item.kind} item on ${item.frame}` }]
|
|
111
|
+
}
|
|
112
|
+
if (item.page) return [{ design, page: item.page, reason: `${item.kind} item on page ${item.page}` }]
|
|
113
|
+
return [{ design, reason: `${item.kind} item scoped to design ${design}` }]
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Expand targets to concrete artboards using the preview manifest of each design. */
|
|
117
|
+
async function expandTargets(renderer, targets, maxFrames) {
|
|
118
|
+
const frames = new Map()
|
|
119
|
+
const missing = []
|
|
120
|
+
for (const target of targets) {
|
|
121
|
+
let manifest
|
|
122
|
+
try {
|
|
123
|
+
manifest = await renderer.frames(target.design)
|
|
124
|
+
} catch (error) {
|
|
125
|
+
missing.push({ ...target, error: error instanceof Error ? error.message : String(error) })
|
|
126
|
+
continue
|
|
127
|
+
}
|
|
128
|
+
const pages = (manifest?.pages ?? []).filter((page) => !target.page || page.id === target.page)
|
|
129
|
+
if (!pages.length) missing.push({ ...target, error: `no page ${target.page ?? ''} in ${target.design}` })
|
|
130
|
+
if (target.frame && pages.length && !pages.some((page) => page.frames.some((frame) => frame.id === target.frame))) {
|
|
131
|
+
missing.push({ ...target, error: `no frame ${target.frame} on page ${target.page} in ${target.design}` })
|
|
132
|
+
}
|
|
133
|
+
for (const page of pages) {
|
|
134
|
+
for (const frame of page.frames) {
|
|
135
|
+
if (target.frame && frame.id !== target.frame) continue
|
|
136
|
+
const entry = {
|
|
137
|
+
design: target.design,
|
|
138
|
+
page: page.id,
|
|
139
|
+
frame: frame.id,
|
|
140
|
+
title: [page.title, frame.title].filter(Boolean).join(' / ') || undefined,
|
|
141
|
+
size: frame.size,
|
|
142
|
+
}
|
|
143
|
+
frames.set(frameKey(entry), { key: frameKey(entry), ...entry })
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
const list = [...frames.values()]
|
|
148
|
+
return { frames: list.slice(0, maxFrames), truncated: Math.max(0, list.length - maxFrames), missing }
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function readItems(root, design, itemIds) {
|
|
152
|
+
const review = readReviewFile(reviewFilePath(root, design))
|
|
153
|
+
if (!review) throw new Error(`no review ledger for ${design}`)
|
|
154
|
+
const items = review.items ?? []
|
|
155
|
+
if (!itemIds) return items
|
|
156
|
+
return itemIds.map((id) => {
|
|
157
|
+
const item = items.find((entry) => entry.id === id)
|
|
158
|
+
if (!item) throw new Error(`review item not found in ${design}: ${id}`)
|
|
159
|
+
return item
|
|
160
|
+
})
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** Write `update(item.snapshots, item)` back to each item under the ledger lock. */
|
|
164
|
+
function patchSnapshots(root, design, updates) {
|
|
165
|
+
if (!updates.size) return
|
|
166
|
+
mutateReview(root, design, (review) => ({
|
|
167
|
+
...review,
|
|
168
|
+
items: review.items.map((item) => {
|
|
169
|
+
const update = updates.get(item.id)
|
|
170
|
+
if (!update) return item
|
|
171
|
+
const next = update(item)
|
|
172
|
+
return next ? { ...next, updatedAt: new Date().toISOString() } : item
|
|
173
|
+
}),
|
|
174
|
+
}))
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const withRenderer = async (options, fn) => {
|
|
178
|
+
const renderer = options.renderer ?? (await createRenderer(options))
|
|
179
|
+
try {
|
|
180
|
+
return await fn(renderer)
|
|
181
|
+
} finally {
|
|
182
|
+
if (!options.renderer) await renderer.close()
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** Render each frame once per run, keyed by frame key. */
|
|
187
|
+
function frameCache(renderer) {
|
|
188
|
+
const cache = new Map()
|
|
189
|
+
return (frame) => {
|
|
190
|
+
if (!cache.has(frame.key)) {
|
|
191
|
+
cache.set(
|
|
192
|
+
frame.key,
|
|
193
|
+
renderer.shoot(frame).then(
|
|
194
|
+
({ image, unstable }) => ({ image, unstable }),
|
|
195
|
+
(error) => ({ error: error instanceof Error ? error.message : String(error) }),
|
|
196
|
+
),
|
|
197
|
+
)
|
|
198
|
+
}
|
|
199
|
+
return cache.get(frame.key)
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const UNSTABLE_ERROR = 'render did not stabilise (consecutive captures differ)'
|
|
204
|
+
const DECISION_FIELDS = ['decision', 'reason', 'decidedAt', 'decidedHash']
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Claim items for a baseline capture: under the ledger lock, mark each item
|
|
208
|
+
* `snapshots.capturingSince` so agents, `verify` and the editor see that a capture is running
|
|
209
|
+
* (and `snapshot wait` can block on it) before any rendering starts. Items that already have
|
|
210
|
+
* a baseline are skipped unless `force`; items another run is capturing are `inProgress`.
|
|
211
|
+
*/
|
|
212
|
+
export function claimBaselines({ root = process.cwd(), design, itemIds, force = false, now = Date.now() } = {}) {
|
|
213
|
+
readItems(root, design, itemIds) // throws on unknown ids
|
|
214
|
+
const token = new Date(now).toISOString()
|
|
215
|
+
const claimed = []
|
|
216
|
+
const inProgress = []
|
|
217
|
+
const skipped = []
|
|
218
|
+
mutateReview(root, design, (review) => {
|
|
219
|
+
const items = review.items.map((item) => {
|
|
220
|
+
if (itemIds && !itemIds.includes(item.id)) return item
|
|
221
|
+
if (item.status === 'archived' || (!force && item.snapshots?.baselineAt)) {
|
|
222
|
+
if (itemIds) skipped.push(item.id)
|
|
223
|
+
return item
|
|
224
|
+
}
|
|
225
|
+
if (isCapturingBaseline(item, now)) {
|
|
226
|
+
inProgress.push(item.id)
|
|
227
|
+
return item
|
|
228
|
+
}
|
|
229
|
+
claimed.push(item.id)
|
|
230
|
+
return { ...item, snapshots: { capturingSince: token }, updatedAt: token }
|
|
231
|
+
})
|
|
232
|
+
return claimed.length ? { ...review, items } : undefined
|
|
233
|
+
})
|
|
234
|
+
return { design, token, claimed, inProgress, skipped }
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** Drop the capture marker `token` from items whose capture did not complete. */
|
|
238
|
+
function releaseClaims(root, design, ids, token) {
|
|
239
|
+
if (!ids.length) return
|
|
240
|
+
mutateReview(root, design, (review) => {
|
|
241
|
+
let changed = false
|
|
242
|
+
const items = review.items.map((item) => {
|
|
243
|
+
if (!ids.includes(item.id) || item.snapshots?.capturingSince !== token || item.snapshots.baselineAt) return item
|
|
244
|
+
changed = true
|
|
245
|
+
const next = { ...item }
|
|
246
|
+
delete next.snapshots
|
|
247
|
+
return next
|
|
248
|
+
})
|
|
249
|
+
return changed ? { ...review, items } : undefined
|
|
250
|
+
})
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Wait until no baseline capture is running for the items (all items of the design when
|
|
255
|
+
* `itemIds` is omitted). This waits on ledger state, not a fixed delay; markers older than
|
|
256
|
+
* CAPTURE_STALE_MS count as interrupted. Returns the ids still capturing at `timeoutMs`.
|
|
257
|
+
*/
|
|
258
|
+
export async function waitForBaselines({
|
|
259
|
+
root = process.cwd(),
|
|
260
|
+
design,
|
|
261
|
+
itemIds,
|
|
262
|
+
timeoutMs = CAPTURE_STALE_MS,
|
|
263
|
+
pollMs = 250,
|
|
264
|
+
} = {}) {
|
|
265
|
+
const deadline = Date.now() + timeoutMs
|
|
266
|
+
for (;;) {
|
|
267
|
+
const capturing = readItems(root, design, itemIds)
|
|
268
|
+
.filter((item) => isCapturingBaseline(item))
|
|
269
|
+
.map((item) => item.id)
|
|
270
|
+
if (!capturing.length || Date.now() >= deadline) return { design, capturing }
|
|
271
|
+
await new Promise((done) => setTimeout(done, Math.min(pollMs, Math.max(0, deadline - Date.now()))))
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/** Render the screens `item` affects now and return its `snapshots` record (images on disk). */
|
|
276
|
+
async function baselineRecord({ root, design, item, renderer, shoot, index, maxFrames }) {
|
|
277
|
+
const targets = affectedTargets(item, index)
|
|
278
|
+
const { frames, truncated, missing } = await expandTargets(renderer, targets, maxFrames)
|
|
279
|
+
rmSync(itemDir(root, design, item.id), { recursive: true, force: true })
|
|
280
|
+
const records = []
|
|
281
|
+
for (const frame of frames) {
|
|
282
|
+
const shot = await shoot(frame)
|
|
283
|
+
if (shot.error) {
|
|
284
|
+
records.push({ ...frame, status: 'error', error: shot.error })
|
|
285
|
+
continue
|
|
286
|
+
}
|
|
287
|
+
records.push({
|
|
288
|
+
...frame,
|
|
289
|
+
before: writeImage(root, design, item.id, 'before', frame.key, shot.image),
|
|
290
|
+
beforeHash: sha1(shot.image),
|
|
291
|
+
status: shot.unstable ? 'error' : 'pending',
|
|
292
|
+
...(shot.unstable ? { unstable: true, error: UNSTABLE_ERROR } : {}),
|
|
293
|
+
})
|
|
294
|
+
}
|
|
295
|
+
return {
|
|
296
|
+
baselineAt: new Date().toISOString(),
|
|
297
|
+
targets: targets.map(({ design: d, page, frame, reason }) => ({ design: d, page, frame, reason })),
|
|
298
|
+
...(truncated ? { truncated } : {}),
|
|
299
|
+
...(missing.length ? { missing } : {}),
|
|
300
|
+
frames: records,
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Baseline of an item that is not in the ledger yet: a tool operation about to write
|
|
306
|
+
* (`hooks.beforeWrite` of runTokenOp / consolidate apply) renders the screens the item will
|
|
307
|
+
* affect from the unchanged source and stores the returned record on the item it records.
|
|
308
|
+
*/
|
|
309
|
+
export async function captureItemBaseline({
|
|
310
|
+
root = process.cwd(),
|
|
311
|
+
item,
|
|
312
|
+
url,
|
|
313
|
+
configFile,
|
|
314
|
+
renderer,
|
|
315
|
+
index: usageIndex,
|
|
316
|
+
maxFrames = DEFAULT_MAX_FRAMES,
|
|
317
|
+
} = {}) {
|
|
318
|
+
const index = usageIndex !== undefined ? usageIndex : await buildUsageIndex({ root })
|
|
319
|
+
return withRenderer({ root, url, configFile, renderer }, (active) =>
|
|
320
|
+
baselineRecord({ root, design: item.design, item, renderer: active, shoot: frameCache(active), index, maxFrames }),
|
|
321
|
+
)
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Capture the "before" baseline for items (all non-archived items of the design when
|
|
326
|
+
* `itemIds` is omitted). Items that already have a baseline are skipped unless `force`.
|
|
327
|
+
* Call this before a tool writes source changes for an item. `claim` passes a
|
|
328
|
+
* claimBaselines() result made earlier (the dev server claims before answering a request).
|
|
329
|
+
* An item whose screens could not be rendered still gets a record (`frames: []` and
|
|
330
|
+
* `missing`), so its snapshot check fails instead of passing on nothing.
|
|
331
|
+
*/
|
|
332
|
+
export async function captureBaselines({
|
|
333
|
+
root = process.cwd(),
|
|
334
|
+
design,
|
|
335
|
+
itemIds,
|
|
336
|
+
force = false,
|
|
337
|
+
url,
|
|
338
|
+
configFile,
|
|
339
|
+
renderer,
|
|
340
|
+
index: usageIndex,
|
|
341
|
+
claim,
|
|
342
|
+
maxFrames = DEFAULT_MAX_FRAMES,
|
|
343
|
+
} = {}) {
|
|
344
|
+
const { token, claimed, inProgress, skipped } = claim ?? claimBaselines({ root, design, itemIds, force })
|
|
345
|
+
const base = { design, captured: [], skipped, ...(inProgress.length ? { inProgress } : {}) }
|
|
346
|
+
if (!claimed.length) return base
|
|
347
|
+
const done = new Set()
|
|
348
|
+
try {
|
|
349
|
+
const items = readItems(root, design, claimed)
|
|
350
|
+
// `index: null` (tests, callers that know the targets) skips the usage scan.
|
|
351
|
+
const index = usageIndex !== undefined ? usageIndex : await buildUsageIndex({ root })
|
|
352
|
+
return await withRenderer({ root, url, configFile, renderer }, async (active) => {
|
|
353
|
+
const shoot = frameCache(active)
|
|
354
|
+
const updates = new Map()
|
|
355
|
+
const captured = []
|
|
356
|
+
for (const item of items) {
|
|
357
|
+
const snapshots = await baselineRecord({ root, design, item, renderer: active, shoot, index, maxFrames })
|
|
358
|
+
// Only complete our own claim: a newer capture or an editor removal wins.
|
|
359
|
+
updates.set(item.id, (current) =>
|
|
360
|
+
current.snapshots?.capturingSince === token ? { ...current, snapshots } : null,
|
|
361
|
+
)
|
|
362
|
+
captured.push({
|
|
363
|
+
id: item.id,
|
|
364
|
+
frames: snapshots.frames.length,
|
|
365
|
+
errors: snapshots.frames.filter((r) => r.error).length,
|
|
366
|
+
...(snapshots.missing ? { missing: snapshots.missing } : {}),
|
|
367
|
+
...(snapshots.truncated ? { truncated: snapshots.truncated } : {}),
|
|
368
|
+
})
|
|
369
|
+
}
|
|
370
|
+
patchSnapshots(root, design, updates)
|
|
371
|
+
for (const id of updates.keys()) done.add(id)
|
|
372
|
+
return { ...base, captured }
|
|
373
|
+
})
|
|
374
|
+
} finally {
|
|
375
|
+
releaseClaims(root, design, claimed.filter((id) => !done.has(id)), token)
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/** Captured items where no screen rendered (every target missing or failed). */
|
|
380
|
+
export function emptyCaptures(result) {
|
|
381
|
+
return result.captured.filter((entry) => entry.frames === entry.errors)
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/** Error text for empty captures, or null. */
|
|
385
|
+
export function emptyCaptureError(result) {
|
|
386
|
+
const empty = emptyCaptures(result)
|
|
387
|
+
if (!empty.length) return null
|
|
388
|
+
return empty
|
|
389
|
+
.map((entry) => {
|
|
390
|
+
const why = (entry.missing ?? [])
|
|
391
|
+
.map((m) => `${m.design}${m.page ? `/${m.page}` : ''}${m.frame ? `__${m.frame}` : ''}: ${m.error}`)
|
|
392
|
+
.join('; ')
|
|
393
|
+
return `no screens rendered for ${entry.id}${why ? `: ${why}` : entry.errors ? ` (${entry.errors} frame(s) failed)` : ''}`
|
|
394
|
+
})
|
|
395
|
+
.join('\n')
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
const STATUS_ORDER = { changed: 0, error: 1, missing: 2, pending: 3, unchanged: 4 }
|
|
399
|
+
|
|
400
|
+
/** Frames with differences first (largest diff ratio first), then errors, then unchanged. */
|
|
401
|
+
export function sortFrames(frames) {
|
|
402
|
+
return [...frames].sort(
|
|
403
|
+
(a, b) =>
|
|
404
|
+
(STATUS_ORDER[a.status] ?? 9) - (STATUS_ORDER[b.status] ?? 9) ||
|
|
405
|
+
(b.diffRatio ?? 0) - (a.diffRatio ?? 0) ||
|
|
406
|
+
a.key.localeCompare(b.key),
|
|
407
|
+
)
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/** Every frame of a design from the preview manifest, by key (or the manifest error). */
|
|
411
|
+
async function currentFrames(renderer, design) {
|
|
412
|
+
try {
|
|
413
|
+
const manifest = await renderer.frames(design)
|
|
414
|
+
const frames = new Map()
|
|
415
|
+
for (const page of manifest?.pages ?? []) {
|
|
416
|
+
for (const frame of page.frames ?? []) frames.set(frameKey({ design, page: page.id, frame: frame.id }), frame)
|
|
417
|
+
}
|
|
418
|
+
return { frames }
|
|
419
|
+
} catch (error) {
|
|
420
|
+
return { error: error instanceof Error ? error.message : String(error) }
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/** A compared frame with the stored decision kept only when it was made on this exact "after" image. */
|
|
425
|
+
function withDecision(record, stored) {
|
|
426
|
+
const next = { ...record }
|
|
427
|
+
for (const field of DECISION_FIELDS) delete next[field]
|
|
428
|
+
if (!stored?.decision || !record.afterHash || stored.decidedHash !== record.afterHash) return next
|
|
429
|
+
for (const field of DECISION_FIELDS) if (stored[field] !== undefined) next[field] = stored[field]
|
|
430
|
+
return next
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Render the "after" state of items with a baseline and diff it against "before". Frames
|
|
435
|
+
* render at their current size from the preview manifest, so a resized artboard shows up as
|
|
436
|
+
* a size change. Decisions survive a re-compare only when the "after" image is
|
|
437
|
+
* byte-identical; they are read from the ledger under the lock when the result is written,
|
|
438
|
+
* so an accept / reject made while the compare ran is kept.
|
|
439
|
+
*/
|
|
440
|
+
export async function compareSnapshots({
|
|
441
|
+
root = process.cwd(),
|
|
442
|
+
design,
|
|
443
|
+
itemIds,
|
|
444
|
+
url,
|
|
445
|
+
configFile,
|
|
446
|
+
renderer,
|
|
447
|
+
diffOptions,
|
|
448
|
+
} = {}) {
|
|
449
|
+
const items = readItems(root, design, itemIds).filter(
|
|
450
|
+
(item) => item.status !== 'archived' && item.snapshots?.baselineAt,
|
|
451
|
+
)
|
|
452
|
+
if (!items.length) return { design, compared: [] }
|
|
453
|
+
return withRenderer({ root, url, configFile, renderer }, async (active) => {
|
|
454
|
+
const shoot = frameCache(active)
|
|
455
|
+
const manifests = new Map()
|
|
456
|
+
const manifestOf = async (name) => {
|
|
457
|
+
if (!manifests.has(name)) manifests.set(name, await currentFrames(active, name))
|
|
458
|
+
return manifests.get(name)
|
|
459
|
+
}
|
|
460
|
+
const results = []
|
|
461
|
+
for (const item of items) {
|
|
462
|
+
const records = []
|
|
463
|
+
for (const frame of item.snapshots.frames ?? []) {
|
|
464
|
+
const base = { ...frame }
|
|
465
|
+
for (const field of ['error', 'unstable', 'after', 'afterHash', 'diff', 'diffPixels', 'diffRatio', 'boxes', 'sizeChange']) {
|
|
466
|
+
delete base[field]
|
|
467
|
+
}
|
|
468
|
+
const beforeFile = frame.before ? resolve(root, frame.before) : null
|
|
469
|
+
if (!beforeFile || !existsSync(beforeFile)) {
|
|
470
|
+
records.push({
|
|
471
|
+
...base,
|
|
472
|
+
status: 'error',
|
|
473
|
+
error:
|
|
474
|
+
frame.error ??
|
|
475
|
+
'baseline image is missing, so this screen cannot be compared; a new baseline would record the changed state, so only recapture from the unchanged source',
|
|
476
|
+
})
|
|
477
|
+
continue
|
|
478
|
+
}
|
|
479
|
+
if (frame.unstable) {
|
|
480
|
+
records.push({ ...base, status: 'error', unstable: true, error: `baseline ${UNSTABLE_ERROR}` })
|
|
481
|
+
continue
|
|
482
|
+
}
|
|
483
|
+
const manifest = await manifestOf(frame.design)
|
|
484
|
+
if (manifest.error) {
|
|
485
|
+
records.push({ ...base, status: 'error', error: manifest.error })
|
|
486
|
+
continue
|
|
487
|
+
}
|
|
488
|
+
const current = manifest.frames.get(frame.key)
|
|
489
|
+
if (!current) {
|
|
490
|
+
records.push({ ...base, status: 'missing', error: `frame ${frame.key} no longer exists` })
|
|
491
|
+
continue
|
|
492
|
+
}
|
|
493
|
+
const target = { ...base, size: current.size }
|
|
494
|
+
const shot = await shoot(target)
|
|
495
|
+
if (shot.error) {
|
|
496
|
+
records.push({
|
|
497
|
+
...target,
|
|
498
|
+
status: /unknown design, page or frame/i.test(shot.error) ? 'missing' : 'error',
|
|
499
|
+
error: shot.error,
|
|
500
|
+
})
|
|
501
|
+
continue
|
|
502
|
+
}
|
|
503
|
+
const result = comparePngs(readFileSync(beforeFile), shot.image, diffOptions)
|
|
504
|
+
const changed = result.diffPixels > 0
|
|
505
|
+
const resized = result.beforeSize.join() !== result.afterSize.join()
|
|
506
|
+
records.push({
|
|
507
|
+
...target,
|
|
508
|
+
after: writeImage(root, design, item.id, 'after', frame.key, shot.image),
|
|
509
|
+
afterHash: sha1(shot.image),
|
|
510
|
+
...(changed ? { diff: writeImage(root, design, item.id, 'diff', frame.key, result.diffPng) } : {}),
|
|
511
|
+
status: shot.unstable ? 'error' : changed ? 'changed' : 'unchanged',
|
|
512
|
+
...(shot.unstable ? { unstable: true, error: UNSTABLE_ERROR } : {}),
|
|
513
|
+
diffPixels: result.diffPixels,
|
|
514
|
+
diffRatio: result.diffRatio,
|
|
515
|
+
boxes: result.boxes,
|
|
516
|
+
...(resized ? { sizeChange: { before: result.beforeSize, after: result.afterSize } } : {}),
|
|
517
|
+
})
|
|
518
|
+
}
|
|
519
|
+
results.push({ item, records, comparedAt: new Date().toISOString() })
|
|
520
|
+
}
|
|
521
|
+
const summaries = new Map()
|
|
522
|
+
const updates = new Map()
|
|
523
|
+
for (const { item, records, comparedAt } of results) {
|
|
524
|
+
const baselineAt = item.snapshots.baselineAt
|
|
525
|
+
updates.set(item.id, (current) => {
|
|
526
|
+
// A baseline recaptured while this ran makes these results meaningless.
|
|
527
|
+
if (current.snapshots?.baselineAt !== baselineAt) return null
|
|
528
|
+
const stored = new Map((current.snapshots.frames ?? []).map((frame) => [frame.key, frame]))
|
|
529
|
+
const frames = sortFrames(records.map((record) => withDecision(record, stored.get(record.key))))
|
|
530
|
+
summaries.set(item.id, summarizeFrames(frames))
|
|
531
|
+
return { ...current, snapshots: { ...current.snapshots, comparedAt, frames } }
|
|
532
|
+
})
|
|
533
|
+
}
|
|
534
|
+
patchSnapshots(root, design, updates)
|
|
535
|
+
return {
|
|
536
|
+
design,
|
|
537
|
+
compared: results.map(({ item }) => ({
|
|
538
|
+
id: item.id,
|
|
539
|
+
...(summaries.get(item.id) ?? { frames: 0, changed: 0, accepted: 0, rejected: 0, errors: 0, superseded: true }),
|
|
540
|
+
})),
|
|
541
|
+
}
|
|
542
|
+
})
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
/** Resolve a user-given frame key (full `design/page__frame` or unique `page__frame` suffix). */
|
|
546
|
+
function matchFrames(frames, keys) {
|
|
547
|
+
if (!keys?.length) return frames.filter((frame) => frame.status === 'changed')
|
|
548
|
+
return keys.map((key) => {
|
|
549
|
+
const hits = frames.filter((frame) => frame.key === key || frame.key.endsWith(`/${key}`))
|
|
550
|
+
if (hits.length !== 1) {
|
|
551
|
+
throw new Error(
|
|
552
|
+
hits.length ? `ambiguous snapshot ${key}: ${hits.map((f) => f.key).join(', ')}` : `no snapshot ${key}`,
|
|
553
|
+
)
|
|
554
|
+
}
|
|
555
|
+
// Only changed screens take a decision; unchanged / failed ones have nothing to judge.
|
|
556
|
+
if (hits[0].status !== 'changed') throw new Error(`snapshot ${hits[0].key} is ${hits[0].status}, not changed`)
|
|
557
|
+
return hits[0]
|
|
558
|
+
})
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* Accept or reject snapshots of one item (all changed snapshots when `frames` is empty).
|
|
563
|
+
* A rejection needs a reason; it marks the frames, reopens the item (status `open`, clears
|
|
564
|
+
* `verifiedAt`) and adds the reason to the item thread so the agent sees it.
|
|
565
|
+
*/
|
|
566
|
+
export function decideSnapshots({ root = process.cwd(), design, itemId, frames: keys, decision, reason }) {
|
|
567
|
+
if (decision !== 'accepted' && decision !== 'rejected') {
|
|
568
|
+
throw new Error('decision must be "accepted" or "rejected"')
|
|
569
|
+
}
|
|
570
|
+
const note = typeof reason === 'string' ? reason.trim() : ''
|
|
571
|
+
if (decision === 'rejected' && !note) throw new Error('rejecting a snapshot requires a reason')
|
|
572
|
+
let result
|
|
573
|
+
mutateReview(root, design, (review) => {
|
|
574
|
+
const index = review.items.findIndex((entry) => entry.id === itemId)
|
|
575
|
+
if (index === -1) throw new Error(`review item not found in ${design}: ${itemId}`)
|
|
576
|
+
const item = review.items[index]
|
|
577
|
+
if (!item.snapshots?.comparedAt) throw new Error(`no compared snapshots on ${itemId}; run verify --snapshots`)
|
|
578
|
+
const targets = matchFrames(item.snapshots.frames ?? [], keys)
|
|
579
|
+
if (!targets.length) throw new Error(`no changed snapshots to ${decision === 'accepted' ? 'accept' : 'reject'} on ${itemId}`)
|
|
580
|
+
const now = new Date().toISOString()
|
|
581
|
+
const chosen = new Set(targets.map((frame) => frame.key))
|
|
582
|
+
const frames = item.snapshots.frames.map((frame) =>
|
|
583
|
+
chosen.has(frame.key)
|
|
584
|
+
? {
|
|
585
|
+
...frame,
|
|
586
|
+
decision,
|
|
587
|
+
decidedAt: now,
|
|
588
|
+
decidedHash: frame.afterHash,
|
|
589
|
+
...(note ? { reason: note } : {}),
|
|
590
|
+
...(decision === 'accepted' && !note ? { reason: undefined } : {}),
|
|
591
|
+
}
|
|
592
|
+
: frame,
|
|
593
|
+
)
|
|
594
|
+
let next = { ...item, snapshots: { ...item.snapshots, frames }, updatedAt: now }
|
|
595
|
+
if (decision === 'rejected') {
|
|
596
|
+
const reply = {
|
|
597
|
+
id: `reply-${randomUUID()}`,
|
|
598
|
+
author: 'human',
|
|
599
|
+
body: `Snapshot rejected (${[...chosen].join(', ')}): ${note}`,
|
|
600
|
+
createdAt: now,
|
|
601
|
+
}
|
|
602
|
+
next = {
|
|
603
|
+
...next,
|
|
604
|
+
status: 'open',
|
|
605
|
+
thread: [...(Array.isArray(item.thread) ? item.thread : []), reply],
|
|
606
|
+
verifiedAt: undefined,
|
|
607
|
+
resolvedAt: undefined,
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
result = { item: next, frames: [...chosen], check: snapshotCheck(next) }
|
|
611
|
+
return { ...review, items: review.items.map((entry, i) => (i === index ? next : entry)) }
|
|
612
|
+
})
|
|
613
|
+
return result
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
/** Snapshot record of one item with image URLs for the editor (`base` = endpoint prefix). */
|
|
617
|
+
export function snapshotView(root, design, itemId, base = '/__seji/api/snapshots/image') {
|
|
618
|
+
const item = readItems(root, design, [itemId])[0]
|
|
619
|
+
const url = (frame, kind) =>
|
|
620
|
+
`${base}?${new URLSearchParams({ design, item: itemId, frame: frame.key, kind })}`
|
|
621
|
+
const snapshots = item.snapshots
|
|
622
|
+
return {
|
|
623
|
+
design,
|
|
624
|
+
item: itemId,
|
|
625
|
+
check: snapshotCheck(item),
|
|
626
|
+
...(snapshots
|
|
627
|
+
? {
|
|
628
|
+
...snapshots,
|
|
629
|
+
frames: sortFrames(snapshots.frames ?? []).map((frame) => ({
|
|
630
|
+
...frame,
|
|
631
|
+
urls: Object.fromEntries(
|
|
632
|
+
SNAPSHOT_KINDS.filter((kind) => frame[kind]).map((kind) => [kind, url(frame, kind)]),
|
|
633
|
+
),
|
|
634
|
+
})),
|
|
635
|
+
}
|
|
636
|
+
: { frames: [] }),
|
|
637
|
+
}
|
|
638
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type SnapshotTarget = { design: string; page: string; frame: string; size: [number, number] }
|
|
2
|
+
export type Renderer = {
|
|
3
|
+
base: string
|
|
4
|
+
frames(design: string): Promise<{
|
|
5
|
+
design: string
|
|
6
|
+
pages: Array<{ id: string; title?: string; frames: Array<{ id: string; title?: string; size: [number, number] }> }>
|
|
7
|
+
}>
|
|
8
|
+
/** `unstable`: no two consecutive captures matched. */
|
|
9
|
+
shoot(target: SnapshotTarget): Promise<{ image: Buffer; unstable: boolean }>
|
|
10
|
+
close(): Promise<void>
|
|
11
|
+
}
|
|
12
|
+
export declare class SnapshotUnavailableError extends Error {}
|
|
13
|
+
export declare function loadPlaywright(root?: string): Promise<unknown>
|
|
14
|
+
export declare function hasPlaywright(root?: string): Promise<boolean>
|
|
15
|
+
export declare function startSnapshotServer(options?: {
|
|
16
|
+
root?: string
|
|
17
|
+
configFile?: string
|
|
18
|
+
}): Promise<{ url: string; close(): Promise<void> }>
|
|
19
|
+
export declare function createRenderer(options?: {
|
|
20
|
+
root?: string
|
|
21
|
+
url?: string
|
|
22
|
+
configFile?: string
|
|
23
|
+
timeoutMs?: number
|
|
24
|
+
}): Promise<Renderer>
|