@rien7/seji 0.0.0 → 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 +106 -1
- package/skills/seji/SKILL.md +395 -0
- package/skills/seji-authoring/SKILL.md +397 -0
- package/skills/seji-tokens/SKILL.md +432 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// CLI front for the tool-executed token operations (src/tokens/ops.mjs).
|
|
2
|
+
import { baselineHooks, compareToolItem, toolSnapshotsRequest } from '../snapshots/toolOps.mjs'
|
|
3
|
+
import { TokenOpError, runTokenOp } from '../tokens/ops.mjs'
|
|
4
|
+
|
|
5
|
+
const VALUE_FLAGS = new Map([
|
|
6
|
+
['to', 'to'],
|
|
7
|
+
['into', 'into'],
|
|
8
|
+
['keep', 'keep'],
|
|
9
|
+
['reason', 'reason'],
|
|
10
|
+
['replacement', 'replacement'],
|
|
11
|
+
['mode', 'mode'],
|
|
12
|
+
['description', 'description'],
|
|
13
|
+
['value', 'value'],
|
|
14
|
+
['token', 'token'],
|
|
15
|
+
['scope', 'scope'],
|
|
16
|
+
['property', 'property'],
|
|
17
|
+
['design', 'design'],
|
|
18
|
+
['tier', 'tier'],
|
|
19
|
+
['type', 'type'],
|
|
20
|
+
])
|
|
21
|
+
const BOOLEAN_FLAGS = new Map([
|
|
22
|
+
['dry-run', ['dryRun', true]],
|
|
23
|
+
['no-alias', ['alias', false]],
|
|
24
|
+
['no-replacement', ['noReplacement', true]],
|
|
25
|
+
['force', ['force', true]],
|
|
26
|
+
['snapshots', ['snapshots', true]],
|
|
27
|
+
])
|
|
28
|
+
|
|
29
|
+
// The first positional of each operation.
|
|
30
|
+
const POSITIONAL = {
|
|
31
|
+
rename: 'token',
|
|
32
|
+
merge: 'token',
|
|
33
|
+
deprecate: 'token',
|
|
34
|
+
delete: 'token',
|
|
35
|
+
describe: 'token',
|
|
36
|
+
set: 'token',
|
|
37
|
+
create: 'token',
|
|
38
|
+
'replace-literal': 'literal',
|
|
39
|
+
revert: 'batch',
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function parseTokenOpArgs(op, argv) {
|
|
43
|
+
const args = {}
|
|
44
|
+
const positionals = []
|
|
45
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
46
|
+
const raw = argv[i]
|
|
47
|
+
if (!raw.startsWith('--') || raw === '--') {
|
|
48
|
+
positionals.push(raw)
|
|
49
|
+
continue
|
|
50
|
+
}
|
|
51
|
+
const eq = raw.indexOf('=')
|
|
52
|
+
const name = eq > 2 ? raw.slice(2, eq) : raw.slice(2)
|
|
53
|
+
if (BOOLEAN_FLAGS.has(name)) {
|
|
54
|
+
if (eq > 2) throw new Error(`--${name} takes no value`)
|
|
55
|
+
const [key, value] = BOOLEAN_FLAGS.get(name)
|
|
56
|
+
args[key] = value
|
|
57
|
+
continue
|
|
58
|
+
}
|
|
59
|
+
const key = VALUE_FLAGS.get(name)
|
|
60
|
+
if (!key) {
|
|
61
|
+
// A positional that is itself a CSS name, e.g. `tokens rename --color-ink --to color.text`.
|
|
62
|
+
if (eq === -1 && !positionals.length && /^--[a-zA-Z0-9_-]+$/.test(raw)) {
|
|
63
|
+
positionals.push(raw)
|
|
64
|
+
continue
|
|
65
|
+
}
|
|
66
|
+
throw new Error(`unknown option for tokens ${op}: --${name}`)
|
|
67
|
+
}
|
|
68
|
+
if (eq > 2) {
|
|
69
|
+
args[key] = raw.slice(eq + 1)
|
|
70
|
+
continue
|
|
71
|
+
}
|
|
72
|
+
const next = argv[i + 1]
|
|
73
|
+
if (next === undefined) throw new Error(`--${name} requires a value`)
|
|
74
|
+
// `--to --dry-run`: the next word is another option, not this option's value. (A CSS name
|
|
75
|
+
// such as `--into --color-surface` is still a value.)
|
|
76
|
+
if (next.startsWith('--')) {
|
|
77
|
+
const nextName = next.slice(2).split('=')[0]
|
|
78
|
+
if (VALUE_FLAGS.has(nextName) || BOOLEAN_FLAGS.has(nextName)) throw new Error(`--${name} requires a value`)
|
|
79
|
+
}
|
|
80
|
+
args[key] = next
|
|
81
|
+
i += 1
|
|
82
|
+
}
|
|
83
|
+
if (positionals.length > 1) throw new Error(`unexpected argument: ${positionals[1]}`)
|
|
84
|
+
if (positionals[0] !== undefined) args[POSITIONAL[op]] = positionals[0]
|
|
85
|
+
return args
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Run `seji tokens <op> …`; prints JSON and returns the exit code. */
|
|
89
|
+
export async function runTokenOpCli({ root, op, argv }) {
|
|
90
|
+
let args
|
|
91
|
+
try {
|
|
92
|
+
args = parseTokenOpArgs(op, argv)
|
|
93
|
+
} catch (error) {
|
|
94
|
+
console.error(`seji: ${error instanceof Error ? error.message : String(error)}`)
|
|
95
|
+
return 1
|
|
96
|
+
}
|
|
97
|
+
// `--snapshots`: render the affected screens before the write and compare them after it
|
|
98
|
+
// (a short-lived Vite server each time, so "after" is built from the changed files).
|
|
99
|
+
const { snapshots, ...opArgs } = args
|
|
100
|
+
const request = toolSnapshotsRequest({ kind: 'tokens', op, snapshots, dryRun: opArgs.dryRun })
|
|
101
|
+
if (request.error) {
|
|
102
|
+
console.error(`seji: ${request.error}`)
|
|
103
|
+
return 1
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
const baseline = request.take ? baselineHooks({ root }) : null
|
|
107
|
+
const result = await runTokenOp({ root, op, args: opArgs, ...(baseline ? { hooks: baseline.hooks } : {}) })
|
|
108
|
+
if (baseline) result.snapshots = await compareToolItem({ root, state: baseline.state, result })
|
|
109
|
+
console.log(JSON.stringify(result, null, 2))
|
|
110
|
+
return result.refused ? 2 : 0
|
|
111
|
+
} catch (error) {
|
|
112
|
+
if (error instanceof TokenOpError) {
|
|
113
|
+
console.log(JSON.stringify({ error: error.message, ...(error.details ?? {}) }, null, 2))
|
|
114
|
+
console.error(`seji: ${error.message}`)
|
|
115
|
+
return 1
|
|
116
|
+
}
|
|
117
|
+
console.error(`seji: ${error instanceof Error ? error.message : String(error)}`)
|
|
118
|
+
return 1
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
// Types for design/ without a project dependency. design/tsconfig.json (yours, created once)
|
|
2
|
+
// extends the tool-owned design/.seji/tsconfig.json, which extends the app's tsconfig
|
|
3
|
+
// (so design files type-check like app code), includes design/, and maps
|
|
4
|
+
// `@rien7/design-surface-runtime` to a copy of the running CLI's runtime .d.ts in
|
|
5
|
+
// design/.seji/types/runtime/. The app's own `paths` are kept (rebased). Regenerated by
|
|
6
|
+
// setup, dev and doctor.
|
|
7
|
+
import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
8
|
+
import { dirname, join, relative, resolve, sep } from 'node:path'
|
|
9
|
+
|
|
10
|
+
import { CACHE_PATHS } from '../shared/projectFiles.mjs'
|
|
11
|
+
import { RUNTIME_PACKAGE, ownRuntimeDir, readPackageVersion } from '../shared/packages.mjs'
|
|
12
|
+
import { importFromApp } from './appScan.mjs'
|
|
13
|
+
|
|
14
|
+
const toPosix = (file) => file.split(sep).join('/')
|
|
15
|
+
const relPath = (from, to) => {
|
|
16
|
+
const rel = toPosix(relative(from, to))
|
|
17
|
+
return rel.startsWith('.') ? rel : `./${rel}`
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** JSON with comments and trailing commas (tsconfig), tokenised so strings are never touched. */
|
|
21
|
+
export function parseJsonc(text) {
|
|
22
|
+
let out = ''
|
|
23
|
+
let i = 0
|
|
24
|
+
while (i < text.length) {
|
|
25
|
+
const char = text[i]
|
|
26
|
+
if (char === '"') {
|
|
27
|
+
let j = i + 1
|
|
28
|
+
while (j < text.length && text[j] !== '"') j += text[j] === '\\' ? 2 : 1
|
|
29
|
+
out += text.slice(i, j + 1)
|
|
30
|
+
i = j + 1
|
|
31
|
+
} else if (char === '/' && text[i + 1] === '/') {
|
|
32
|
+
while (i < text.length && text[i] !== '\n') i += 1
|
|
33
|
+
} else if (char === '/' && text[i + 1] === '*') {
|
|
34
|
+
i = text.indexOf('*/', i + 2)
|
|
35
|
+
i = i < 0 ? text.length : i + 2
|
|
36
|
+
} else {
|
|
37
|
+
out += char
|
|
38
|
+
i += 1
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return JSON.parse(out.replace(/,(\s*[}\]])/g, '$1'))
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The app's tsconfig that covers its source: tsconfig.app.json, else tsconfig.json. */
|
|
45
|
+
export function appTsconfig(appRoot) {
|
|
46
|
+
for (const name of ['tsconfig.app.json', 'tsconfig.json']) if (existsSync(join(appRoot, name))) return join(appRoot, name)
|
|
47
|
+
return null
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The app's effective `paths` and their base directory, through TypeScript's own config reader
|
|
52
|
+
* when the app has typescript (follows `extends`), else from the file itself.
|
|
53
|
+
*/
|
|
54
|
+
async function appPaths(appRoot, file) {
|
|
55
|
+
try {
|
|
56
|
+
const mod = await importFromApp(appRoot, 'typescript')
|
|
57
|
+
const ts = mod?.default ?? mod
|
|
58
|
+
if (ts?.readConfigFile) {
|
|
59
|
+
const read = ts.readConfigFile(file, ts.sys.readFile)
|
|
60
|
+
const parsed = ts.parseJsonConfigFileContent(read.config ?? {}, ts.sys, dirname(file), undefined, file)
|
|
61
|
+
const options = parsed.options ?? {}
|
|
62
|
+
return { paths: options.paths ?? null, baseUrl: options.baseUrl ?? null, pathsBase: options.pathsBasePath ?? dirname(file) }
|
|
63
|
+
}
|
|
64
|
+
} catch {
|
|
65
|
+
// fall back to reading the file
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
const options = parseJsonc(readFileSync(file, 'utf8')).compilerOptions ?? {}
|
|
69
|
+
return {
|
|
70
|
+
paths: options.paths ?? null,
|
|
71
|
+
baseUrl: options.baseUrl ? resolve(dirname(file), options.baseUrl) : null,
|
|
72
|
+
pathsBase: dirname(file),
|
|
73
|
+
}
|
|
74
|
+
} catch {
|
|
75
|
+
return { paths: null, baseUrl: null, pathsBase: dirname(file) }
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const STANDALONE = {
|
|
80
|
+
target: 'ES2022',
|
|
81
|
+
lib: ['ES2022', 'DOM', 'DOM.Iterable'],
|
|
82
|
+
jsx: 'react-jsx',
|
|
83
|
+
module: 'ESNext',
|
|
84
|
+
moduleResolution: 'bundler',
|
|
85
|
+
strict: true,
|
|
86
|
+
skipLibCheck: true,
|
|
87
|
+
allowImportingTsExtensions: true,
|
|
88
|
+
resolveJsonModule: true,
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const writeIfChanged = (file, content) => {
|
|
92
|
+
const before = existsSync(file) ? readFileSync(file, 'utf8') : null
|
|
93
|
+
if (before === content) return 'unchanged'
|
|
94
|
+
mkdirSync(dirname(file), { recursive: true })
|
|
95
|
+
writeFileSync(file, content)
|
|
96
|
+
return before === null ? 'created' : 'updated'
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export const USER_TSCONFIG = `{
|
|
100
|
+
"extends": "./.seji/tsconfig.json"
|
|
101
|
+
}
|
|
102
|
+
`
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Write the types: the d.ts copy, the cache tsconfig, and design/tsconfig.json when missing.
|
|
106
|
+
* Returns `[{ file, status }]` (status created | updated | unchanged | skipped | failed).
|
|
107
|
+
*/
|
|
108
|
+
export async function ensureDesignTypes(appRoot, { dryRun = false } = {}) {
|
|
109
|
+
const results = []
|
|
110
|
+
const cacheDir = resolve(appRoot, CACHE_PATHS.types, '..')
|
|
111
|
+
const typesDir = resolve(appRoot, CACHE_PATHS.types, 'runtime')
|
|
112
|
+
const runtimeDir = ownRuntimeDir()
|
|
113
|
+
const dist = runtimeDir && join(runtimeDir, 'dist')
|
|
114
|
+
const dts = dist && existsSync(dist) ? readdirSync(dist).filter((name) => name.endsWith('.d.ts')) : []
|
|
115
|
+
if (!dts.length) {
|
|
116
|
+
results.push({ file: `${CACHE_PATHS.types}/runtime/`, status: 'failed', detail: `${RUNTIME_PACKAGE} type declarations not found next to this CLI` })
|
|
117
|
+
} else if (!dryRun) {
|
|
118
|
+
const version = readPackageVersion(runtimeDir)
|
|
119
|
+
const stamp = join(typesDir, '.version')
|
|
120
|
+
const current = existsSync(stamp) ? readFileSync(stamp, 'utf8').trim() : null
|
|
121
|
+
if (current !== version || dts.some((name) => !existsSync(join(typesDir, name)))) {
|
|
122
|
+
rmSync(typesDir, { recursive: true, force: true })
|
|
123
|
+
mkdirSync(typesDir, { recursive: true })
|
|
124
|
+
for (const name of dts) copyFileSync(join(dist, name), join(typesDir, name))
|
|
125
|
+
writeFileSync(stamp, `${version}\n`)
|
|
126
|
+
results.push({ file: `${CACHE_PATHS.types}/runtime/`, status: current ? 'updated' : 'created', detail: `${RUNTIME_PACKAGE} ${version}` })
|
|
127
|
+
} else results.push({ file: `${CACHE_PATHS.types}/runtime/`, status: 'unchanged' })
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const runtimeTypes = join(typesDir, 'index.d.ts')
|
|
131
|
+
const base = appTsconfig(appRoot)
|
|
132
|
+
const compilerOptions = base ? { noEmit: true } : { ...STANDALONE, noEmit: true }
|
|
133
|
+
const paths = {}
|
|
134
|
+
if (base) {
|
|
135
|
+
const app = await appPaths(appRoot, base)
|
|
136
|
+
if (app.paths) {
|
|
137
|
+
const from = app.baseUrl ?? app.pathsBase
|
|
138
|
+
for (const [key, targets] of Object.entries(app.paths)) {
|
|
139
|
+
// Relative to our baseUrl when the app has one (inherited), else to this config's dir.
|
|
140
|
+
paths[key] = targets.map((target) => (app.baseUrl ? target : relPath(cacheDir, resolve(from, target))))
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
// Always `./`-relative: TypeScript 6+ rejects non-relative `paths` targets (TS5090).
|
|
144
|
+
paths[RUNTIME_PACKAGE] = [app.baseUrl ? relPath(app.baseUrl, runtimeTypes) : relPath(cacheDir, runtimeTypes)]
|
|
145
|
+
} else {
|
|
146
|
+
paths[RUNTIME_PACKAGE] = [relPath(cacheDir, runtimeTypes)]
|
|
147
|
+
}
|
|
148
|
+
compilerOptions.paths = paths
|
|
149
|
+
const config = {
|
|
150
|
+
'//': 'Generated by seji (setup / dev / doctor). Edit design/tsconfig.json instead.',
|
|
151
|
+
...(base ? { extends: relPath(cacheDir, base) } : {}),
|
|
152
|
+
compilerOptions,
|
|
153
|
+
include: ['../**/*.ts', '../**/*.tsx'],
|
|
154
|
+
exclude: ['../**/node_modules'],
|
|
155
|
+
}
|
|
156
|
+
const cacheConfig = resolve(appRoot, CACHE_PATHS.tsconfig)
|
|
157
|
+
const content = `${JSON.stringify(config, null, 2)}\n`
|
|
158
|
+
results.push({ file: CACHE_PATHS.tsconfig, status: dryRun ? (existsSync(cacheConfig) ? 'unchanged' : 'created') : writeIfChanged(cacheConfig, content) })
|
|
159
|
+
|
|
160
|
+
const user = resolve(appRoot, 'design/tsconfig.json')
|
|
161
|
+
if (existsSync(user)) results.push({ file: 'design/tsconfig.json', status: 'skipped' })
|
|
162
|
+
else {
|
|
163
|
+
if (!dryRun) writeIfChanged(user, USER_TSCONFIG)
|
|
164
|
+
results.push({ file: 'design/tsconfig.json', status: 'created' })
|
|
165
|
+
}
|
|
166
|
+
return results
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** For doctor: are the types in place? `{ ok, detail }`. */
|
|
170
|
+
export function designTypesState(appRoot) {
|
|
171
|
+
const user = resolve(appRoot, 'design/tsconfig.json')
|
|
172
|
+
const cache = resolve(appRoot, CACHE_PATHS.tsconfig)
|
|
173
|
+
const types = resolve(appRoot, CACHE_PATHS.types, 'runtime', 'index.d.ts')
|
|
174
|
+
if (!existsSync(user)) return { ok: false, detail: 'design/tsconfig.json is missing' }
|
|
175
|
+
let extendsCache = false
|
|
176
|
+
try {
|
|
177
|
+
const parsed = parseJsonc(readFileSync(user, 'utf8'))
|
|
178
|
+
const ext = [parsed.extends].flat().filter(Boolean)
|
|
179
|
+
extendsCache = ext.some((value) => resolve(dirname(user), value) === cache) || Boolean(parsed.compilerOptions?.paths?.[RUNTIME_PACKAGE])
|
|
180
|
+
} catch {
|
|
181
|
+
return { ok: false, detail: 'design/tsconfig.json is not valid JSON' }
|
|
182
|
+
}
|
|
183
|
+
if (!extendsCache) return { ok: false, warn: true, detail: `design/tsconfig.json does not extend ./.seji/tsconfig.json (${RUNTIME_PACKAGE} types may not resolve)` }
|
|
184
|
+
if (!existsSync(cache) || !existsSync(types)) return { ok: false, detail: 'the runtime type copy in design/.seji/ is missing' }
|
|
185
|
+
const runtimeDir = ownRuntimeDir()
|
|
186
|
+
const version = runtimeDir ? readPackageVersion(runtimeDir) : null
|
|
187
|
+
const stamp = resolve(appRoot, CACHE_PATHS.types, 'runtime', '.version')
|
|
188
|
+
const copied = existsSync(stamp) ? readFileSync(stamp, 'utf8').trim() : null
|
|
189
|
+
if (version && copied !== version) return { ok: false, detail: `runtime types are ${copied ?? 'unversioned'}, the CLI ships ${version}` }
|
|
190
|
+
return { ok: true, detail: `design/tsconfig.json → runtime types ${copied ?? ''}`.trim() }
|
|
191
|
+
}
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
// The global CLI keeps itself on the latest release. One owner: `runUpdater` runs first in every
|
|
2
|
+
// invocation of the global `seji` bin. The global install is npm's (README: always
|
|
3
|
+
// `npm i -g @rien7/seji@latest`, never a pnpm / yarn / bun global).
|
|
4
|
+
//
|
|
5
|
+
// 1. A re-run after an update (SEJI_UPDATED_FROM) refreshes the global skills from
|
|
6
|
+
// its own package and prints one line.
|
|
7
|
+
// 2. Global install: global skills that are missing or outdated are written now (the first
|
|
8
|
+
// command after any install, so nothing relies on postinstall).
|
|
9
|
+
// 3. SEJI_NO_UPDATE=1, or not a global install (project dependency, npx, source
|
|
10
|
+
// checkout) → nothing more.
|
|
11
|
+
// 4. Latest version: the cached answer when it is under an hour old, a cached failure when the
|
|
12
|
+
// last check failed or hung less than 10 minutes ago, else one registry request bounded by a
|
|
13
|
+
// 1.5 s timeout. Offline / any error → continue on this version, silently.
|
|
14
|
+
// 5. Newer → `npm install -g @rien7/seji@latest` (from the home directory), then
|
|
15
|
+
// re-run the same command on the new version with SEJI_UPDATED_FROM=<old>. A copy
|
|
16
|
+
// a pnpm / yarn / bun global installed is not updated: one line says how to reinstall it.
|
|
17
|
+
//
|
|
18
|
+
// Everything with a side effect (fetch, install, locate, re-exec, skills) is injectable for tests.
|
|
19
|
+
import { spawnSync } from 'node:child_process'
|
|
20
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs'
|
|
21
|
+
import { homedir } from 'node:os'
|
|
22
|
+
import { join, resolve } from 'node:path'
|
|
23
|
+
import { fileURLToPath } from 'node:url'
|
|
24
|
+
|
|
25
|
+
import { deleteToolEnv, toolEnv } from '../shared/env.mjs'
|
|
26
|
+
import { compareVersions } from './semver.mjs'
|
|
27
|
+
import { globalSkillStatus, installSkills } from './skills.mjs'
|
|
28
|
+
|
|
29
|
+
export const PACKAGE_NAME = '@rien7/seji'
|
|
30
|
+
export const PACKAGE_DIR = fileURLToPath(new URL('../..', import.meta.url))
|
|
31
|
+
export const CURRENT_VERSION = JSON.parse(readFileSync(join(PACKAGE_DIR, 'package.json'), 'utf8')).version
|
|
32
|
+
export const NO_UPDATE_ENV = 'SEJI_NO_UPDATE'
|
|
33
|
+
export const UPDATED_FROM_ENV = 'SEJI_UPDATED_FROM'
|
|
34
|
+
export const CHECK_TTL_MS = 60 * 60 * 1000
|
|
35
|
+
/** A failed or hung registry check is not repeated for this long (every command would wait otherwise). */
|
|
36
|
+
export const FAILED_CHECK_TTL_MS = 10 * 60 * 1000
|
|
37
|
+
export const FETCH_TIMEOUT_MS = 1500
|
|
38
|
+
const LOCK_STALE_MS = 5 * 60 * 1000
|
|
39
|
+
|
|
40
|
+
export { compareVersions }
|
|
41
|
+
|
|
42
|
+
/** The user cache directory for seji (XDG / macOS / Windows conventions). */
|
|
43
|
+
export function cacheDir({ env = process.env, home = homedir(), platform = process.platform } = {}) {
|
|
44
|
+
if (env.XDG_CACHE_HOME) return join(env.XDG_CACHE_HOME, 'seji')
|
|
45
|
+
if (platform === 'darwin') return join(home, 'Library', 'Caches', 'seji')
|
|
46
|
+
if (platform === 'win32') return join(env.LOCALAPPDATA || join(home, 'AppData', 'Local'), 'seji', 'Cache')
|
|
47
|
+
return join(home, '.cache', 'seji')
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const readJson = (file) => {
|
|
51
|
+
try {
|
|
52
|
+
return JSON.parse(readFileSync(file, 'utf8'))
|
|
53
|
+
} catch {
|
|
54
|
+
return null
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const writeJson = (file, value) => {
|
|
58
|
+
try {
|
|
59
|
+
mkdirSync(resolve(file, '..'), { recursive: true })
|
|
60
|
+
writeFileSync(file, `${JSON.stringify(value, null, 2)}\n`)
|
|
61
|
+
} catch {
|
|
62
|
+
// A cache that cannot be written only costs a registry request next time.
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* How this copy was installed, from its (real) path: `{ global, pm }`.
|
|
68
|
+
* A global install has no project around it (`<prefix>/lib/node_modules/…`) or sits in a package
|
|
69
|
+
* manager's global store; npx caches and project dependencies are not global.
|
|
70
|
+
*/
|
|
71
|
+
export function detectInstall(pkgDir = PACKAGE_DIR, { exists = existsSync } = {}) {
|
|
72
|
+
const path = pkgDir.split('\\').join('/')
|
|
73
|
+
const pm = /\/(?:\.pnpm|pnpm)\//i.test(path) ? 'pnpm' : /\/\.bun\/install\//.test(path) ? 'bun' : /\/yarn\/(?:data\/)?global\/|\/\.config\/yarn\//i.test(path) ? 'yarn' : 'npm'
|
|
74
|
+
const at = path.indexOf('/node_modules/')
|
|
75
|
+
if (at < 0) return { global: false, pm, kind: 'source' }
|
|
76
|
+
if (/\/_npx\//.test(path)) return { global: false, pm, kind: 'npx' }
|
|
77
|
+
if (/\/pnpm\/global\/|\/\.bun\/install\/global\/|\/yarn\/(?:data\/)?global\/|\/\.volta\//i.test(path)) return { global: true, pm, kind: 'global' }
|
|
78
|
+
const base = path.slice(0, at)
|
|
79
|
+
if (exists(join(base, 'package.json'))) return { global: false, pm, kind: 'project' }
|
|
80
|
+
return { global: true, pm, kind: 'global' }
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export const GLOBAL_INSTALL_COMMAND = ['npm', ['install', '-g', `${PACKAGE_NAME}@latest`]]
|
|
84
|
+
export const GLOBAL_INSTALL_TEXT = `npm i -g ${PACKAGE_NAME}@latest`
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 0.6.x: seji also ships the `design-surface` command. npm will not replace a global bin another
|
|
88
|
+
* package owns (EEXIST), so with @rien7/design-surface 0.5.x still installed globally
|
|
89
|
+
* `npm i -g @rien7/seji` fails until the old package is removed.
|
|
90
|
+
*/
|
|
91
|
+
export const OLD_PACKAGE_FIX = `npm rm -g @rien7/design-surface && ${GLOBAL_INSTALL_TEXT}`
|
|
92
|
+
export const oldPackageConflict = (output) => /EEXIST/.test(String(output ?? '')) && /design-surface/.test(String(output ?? ''))
|
|
93
|
+
|
|
94
|
+
/** The one line for a copy that pnpm / yarn / bun installed globally: how to move to npm's. */
|
|
95
|
+
export const reinstallWithNpmText = (pm) =>
|
|
96
|
+
`seji: this copy was installed with ${pm}; updates need npm's global install: ${pm === 'yarn' ? 'yarn global remove' : `${pm} remove -g`} ${PACKAGE_NAME} && ${GLOBAL_INSTALL_TEXT}`
|
|
97
|
+
|
|
98
|
+
/** The npm registry: npm_config_registry (npm sets it for scripts), NPM_CONFIG_REGISTRY, else npmjs. */
|
|
99
|
+
export const registryUrl = (env = process.env) =>
|
|
100
|
+
(env.npm_config_registry || env.NPM_CONFIG_REGISTRY || 'https://registry.npmjs.org').replace(/\/+$/, '')
|
|
101
|
+
|
|
102
|
+
/** One bounded registry request: the `latest` dist-tag's version. Throws on any failure. */
|
|
103
|
+
export async function fetchLatestVersion({ env = process.env, timeoutMs = FETCH_TIMEOUT_MS, fetchImpl = globalThis.fetch } = {}) {
|
|
104
|
+
const registry = registryUrl(env)
|
|
105
|
+
const response = await fetchImpl(`${registry}/${PACKAGE_NAME.replace('/', '%2f')}/latest`, {
|
|
106
|
+
headers: { accept: 'application/json' },
|
|
107
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
108
|
+
})
|
|
109
|
+
if (!response.ok) throw new Error(`registry answered ${response.status}`)
|
|
110
|
+
const body = await response.json()
|
|
111
|
+
if (typeof body?.version !== 'string') throw new Error('registry answer has no version')
|
|
112
|
+
return body.version
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* The latest version, from a fresh cache entry or the registry; null when unknown (offline). A
|
|
117
|
+
* failed or timed-out check is cached for FAILED_CHECK_TTL_MS, so an offline machine pays the
|
|
118
|
+
* timeout once per ten minutes, not on every command.
|
|
119
|
+
*/
|
|
120
|
+
export async function latestVersion({ cacheFile, now = Date.now(), fetchLatest = fetchLatestVersion, ttlMs = CHECK_TTL_MS, failedTtlMs = FAILED_CHECK_TTL_MS } = {}) {
|
|
121
|
+
const cache = readJson(cacheFile) ?? {}
|
|
122
|
+
const fresh = (at, ttl) => typeof at === 'number' && now - at >= 0 && now - at < ttl
|
|
123
|
+
if (typeof cache.latest === 'string' && fresh(cache.checkedAt, ttlMs)) {
|
|
124
|
+
return { latest: cache.latest, source: 'cache', cache }
|
|
125
|
+
}
|
|
126
|
+
if (fresh(cache.failedCheckAt, failedTtlMs)) return { latest: null, source: 'offline-cache', cache }
|
|
127
|
+
try {
|
|
128
|
+
const latest = await fetchLatest()
|
|
129
|
+
const { failedCheckAt, ...rest } = cache
|
|
130
|
+
const next = { ...rest, latest, checkedAt: now }
|
|
131
|
+
writeJson(cacheFile, next)
|
|
132
|
+
return { latest, source: 'registry', cache: next }
|
|
133
|
+
} catch {
|
|
134
|
+
const next = { ...cache, failedCheckAt: now }
|
|
135
|
+
writeJson(cacheFile, next)
|
|
136
|
+
return { latest: null, source: 'offline', cache: next }
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// From the home directory: npm must not pick up a project's .npmrc / workspace around the cwd.
|
|
141
|
+
const defaultInstall = (command, args) => {
|
|
142
|
+
const result = spawnSync(command, args, { cwd: homedir(), encoding: 'utf8', shell: process.platform === 'win32' })
|
|
143
|
+
return { status: result.status ?? 1, output: `${result.stdout ?? ''}${result.stderr ?? ''}${result.error ? String(result.error) : ''}` }
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** The installed global copy's bin, after an install: npm's global root, else this path. */
|
|
147
|
+
const defaultLocate = () => {
|
|
148
|
+
const candidates = []
|
|
149
|
+
const result = spawnSync('npm', ['root', '-g'], { cwd: homedir(), encoding: 'utf8', shell: process.platform === 'win32' })
|
|
150
|
+
const out = String(result.stdout ?? '').trim().split('\n').pop()
|
|
151
|
+
if (result.status === 0 && out) candidates.push(out)
|
|
152
|
+
const dirs = [...candidates.map((root) => join(root, ...PACKAGE_NAME.split('/'))), PACKAGE_DIR]
|
|
153
|
+
return dirs.map((dir) => {
|
|
154
|
+
const version = readJson(join(dir, 'package.json'))?.version ?? null
|
|
155
|
+
return { bin: join(dir, 'bin', 'seji.mjs'), version }
|
|
156
|
+
})
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const defaultReexec = (bin, argv, env) => {
|
|
160
|
+
const result = spawnSync(process.execPath, [bin, ...argv], { stdio: 'inherit', env })
|
|
161
|
+
return result.status ?? 1
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** A lock so concurrent invocations do not install at the same time; false when another holds it. */
|
|
165
|
+
function takeLock(file, now) {
|
|
166
|
+
try {
|
|
167
|
+
if (existsSync(file) && now - statSync(file).mtimeMs > LOCK_STALE_MS) rmSync(file, { force: true })
|
|
168
|
+
mkdirSync(resolve(file, '..'), { recursive: true })
|
|
169
|
+
writeFileSync(file, String(process.pid), { flag: 'wx' })
|
|
170
|
+
return true
|
|
171
|
+
} catch {
|
|
172
|
+
return false
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Run before every command. Returns `{ action, … }`; when `exitCode` is set the command already ran
|
|
178
|
+
* on the new version and the caller exits with it.
|
|
179
|
+
*
|
|
180
|
+
* actions: disabled | not-global | updated (this process is the re-run) | offline | current |
|
|
181
|
+
* non-npm (a pnpm / yarn / bun global; one line, no update) | busy (another process is
|
|
182
|
+
* installing) | install-failed | not-found (installed copy not newer) | reexec (exitCode set)
|
|
183
|
+
* `skills` says whether missing / outdated global skills were written first.
|
|
184
|
+
*/
|
|
185
|
+
export async function runUpdater({
|
|
186
|
+
argv = process.argv.slice(2),
|
|
187
|
+
env = process.env,
|
|
188
|
+
current = CURRENT_VERSION,
|
|
189
|
+
install: installInfo = detectInstall(),
|
|
190
|
+
home = homedir(),
|
|
191
|
+
cache = cacheDir({ env, home }),
|
|
192
|
+
now = Date.now(),
|
|
193
|
+
fetchLatest = (() => fetchLatestVersion({ env })),
|
|
194
|
+
runInstall = defaultInstall,
|
|
195
|
+
locate = defaultLocate,
|
|
196
|
+
reexec = defaultReexec,
|
|
197
|
+
refreshSkills = () => installSkills({ home, env }),
|
|
198
|
+
skillsStatus = () => globalSkillStatus({ home, env }),
|
|
199
|
+
log = (line) => console.error(line),
|
|
200
|
+
} = {}) {
|
|
201
|
+
const cacheFile = join(cache, 'update-check.json')
|
|
202
|
+
const from = toolEnv('UPDATED_FROM', env)
|
|
203
|
+
if (from) {
|
|
204
|
+
// This process is the re-run on the freshly installed version.
|
|
205
|
+
deleteToolEnv('UPDATED_FROM', env)
|
|
206
|
+
let skills = ''
|
|
207
|
+
try {
|
|
208
|
+
const targets = refreshSkills()
|
|
209
|
+
skills = `; skills refreshed in ${targets.map((target) => target.dir).join(', ')}`
|
|
210
|
+
} catch (error) {
|
|
211
|
+
skills = `; skills not refreshed (${error instanceof Error ? error.message : String(error)}): run seji skills install`
|
|
212
|
+
}
|
|
213
|
+
writeJson(cacheFile, { ...(readJson(cacheFile) ?? {}), latest: current, checkedAt: now })
|
|
214
|
+
log(`seji: updated ${from} → ${current}${skills}`)
|
|
215
|
+
return { action: 'updated', from, current }
|
|
216
|
+
}
|
|
217
|
+
// The first command after an install (or after the skills were deleted) writes them: no
|
|
218
|
+
// reliance on postinstall, which some installs skip. Local files only, so also when updates
|
|
219
|
+
// are off or the machine is offline.
|
|
220
|
+
let skills = 'current'
|
|
221
|
+
if (installInfo.global && argv[0] !== 'skills') {
|
|
222
|
+
try {
|
|
223
|
+
const stale = skillsStatus().some((target) => target.legacy?.length || Object.values(target.skills).some((state) => state !== 'current'))
|
|
224
|
+
if (stale) {
|
|
225
|
+
const targets = refreshSkills()
|
|
226
|
+
skills = 'refreshed'
|
|
227
|
+
log(`seji: skills for ${current} written to ${targets.map((target) => target.dir).join(', ')}`)
|
|
228
|
+
}
|
|
229
|
+
} catch (error) {
|
|
230
|
+
skills = 'failed'
|
|
231
|
+
log(`seji: skills not written (${error instanceof Error ? error.message : String(error)}): run seji skills install`)
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (toolEnv('NO_UPDATE', env) === '1') return { action: 'disabled', current, skills }
|
|
235
|
+
if (!installInfo.global) return { action: 'not-global', current, kind: installInfo.kind, skills }
|
|
236
|
+
|
|
237
|
+
const { latest, cache: cached } = await latestVersion({ cacheFile, now, fetchLatest })
|
|
238
|
+
if (!latest) return { action: 'offline', current, skills }
|
|
239
|
+
if (compareVersions(latest, current) <= 0) return { action: 'current', current, latest, skills }
|
|
240
|
+
if (installInfo.pm !== 'npm') {
|
|
241
|
+
log(`${reinstallWithNpmText(installInfo.pm)} (${current} → ${latest})`)
|
|
242
|
+
return { action: 'non-npm', current, latest, pm: installInfo.pm, skills }
|
|
243
|
+
}
|
|
244
|
+
// A failed install of this version is not retried within the hour.
|
|
245
|
+
if (cached.failed?.version === latest && now - cached.failed.at < CHECK_TTL_MS) return { action: 'install-failed', current, latest, retried: false }
|
|
246
|
+
|
|
247
|
+
const lockFile = join(cache, 'update.lock')
|
|
248
|
+
if (!takeLock(lockFile, now)) return { action: 'busy', current, latest }
|
|
249
|
+
try {
|
|
250
|
+
const [command, args] = GLOBAL_INSTALL_COMMAND
|
|
251
|
+
const shown = [command, ...args].join(' ')
|
|
252
|
+
const result = runInstall(command, args)
|
|
253
|
+
if (result.status !== 0) {
|
|
254
|
+
writeJson(cacheFile, { ...cached, failed: { version: latest, at: now } })
|
|
255
|
+
if (oldPackageConflict(result.output)) {
|
|
256
|
+
log(`seji: could not update ${current} → ${latest}: the old @rien7/design-surface package still owns the \`design-surface\` command, so npm refused (EEXIST). Run: ${OLD_PACKAGE_FIX}`)
|
|
257
|
+
return { action: 'install-failed', current, latest, command: shown, conflict: '@rien7/design-surface' }
|
|
258
|
+
}
|
|
259
|
+
const reason = String(result.output ?? '').trim().split('\n').filter(Boolean).pop() ?? `exit ${result.status}`
|
|
260
|
+
log(`seji: could not update ${current} → ${latest} (${shown}: ${reason}); continuing on ${current}`)
|
|
261
|
+
return { action: 'install-failed', current, latest, command: shown }
|
|
262
|
+
}
|
|
263
|
+
const target = locate().find((entry) => entry.version && compareVersions(entry.version, current) > 0)
|
|
264
|
+
if (!target) {
|
|
265
|
+
log(`seji: ${shown} finished but the global copy is still ${current}; continuing on ${current}`)
|
|
266
|
+
return { action: 'not-found', current, latest, command: shown }
|
|
267
|
+
}
|
|
268
|
+
rmSync(lockFile, { force: true })
|
|
269
|
+
const exitCode = reexec(target.bin, argv, { ...env, [UPDATED_FROM_ENV]: current })
|
|
270
|
+
return { action: 'reexec', current, latest: target.version, command: shown, exitCode }
|
|
271
|
+
} finally {
|
|
272
|
+
rmSync(lockFile, { force: true })
|
|
273
|
+
}
|
|
274
|
+
}
|