@1agh/maude 2.0.8 → 2.1.1
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/README.md +2 -1
- package/apps/hub/src/project-transactions/kernel.mjs +13 -7
- package/apps/studio/access/closure.ts +86 -10
- package/apps/studio/access/filters.ts +18 -1
- package/apps/studio/access/request.ts +8 -0
- package/apps/studio/acp/design-write-verb.ts +12 -2
- package/apps/studio/acp/env.ts +7 -2
- package/apps/studio/acp/index.ts +15 -4
- package/apps/studio/acp/login-state.ts +22 -5
- package/apps/studio/acp/may-scope.ts +38 -1
- package/apps/studio/acp/plugin-bootstrap.ts +13 -1
- package/apps/studio/acp/probe.ts +11 -4
- package/apps/studio/actions/agents.ts +110 -28
- package/apps/studio/actions/canvas-keys.ts +4 -2
- package/apps/studio/actions/ctx.ts +3 -0
- package/apps/studio/actions/defs/annotation.ts +84 -2
- package/apps/studio/actions/defs/app.ts +28 -1
- package/apps/studio/actions/defs/edit.ts +13 -0
- package/apps/studio/actions/defs/export.ts +12 -0
- package/apps/studio/actions/defs/sync.ts +18 -0
- package/apps/studio/actions/defs/video.ts +9 -0
- package/apps/studio/actions/documents.ts +6 -1
- package/apps/studio/actions/keymap.gen.ts +147 -9
- package/apps/studio/actions/menu.ts +5 -1
- package/apps/studio/actions/types.ts +4 -2
- package/apps/studio/actions/verbs.ts +9 -0
- package/apps/studio/actions.manifest.json +300 -45
- package/apps/studio/actions.parity.json +19 -1
- package/apps/studio/ai/save-hold.ts +2 -1
- package/apps/studio/ai/write-claim-scope.ts +7 -1
- package/apps/studio/ai/write-claim.ts +154 -3
- package/apps/studio/annotations/ai-read.ts +42 -6
- package/apps/studio/annotations/ai-write.ts +145 -2
- package/apps/studio/annotations/board-ops.ts +34 -3
- package/apps/studio/annotations/checklist-ops.ts +374 -0
- package/apps/studio/annotations/elements/checkitem.model.ts +129 -0
- package/apps/studio/annotations/elements/sticky.model.ts +54 -2
- package/apps/studio/annotations/ops.ts +30 -0
- package/apps/studio/annotations/registry.ts +9 -1
- package/apps/studio/annotations/templates.ts +4 -2
- package/apps/studio/annotations/text-steps.ts +114 -10
- package/apps/studio/annotations/ui/checklist-wire.ts +129 -0
- package/apps/studio/annotations/ui/checklist.tsx +429 -0
- package/apps/studio/annotations/ui/element-node.tsx +48 -2
- package/apps/studio/annotations/ui/template-place.ts +11 -1
- package/apps/studio/annotations/v1-adapter.ts +22 -3
- package/apps/studio/annotations-context-toolbar.tsx +12 -0
- package/apps/studio/annotations-layer.tsx +442 -49
- package/apps/studio/annotations-model.ts +4 -2
- package/apps/studio/api.ts +148 -21
- package/apps/studio/artboard-live-gate.tsx +54 -17
- package/apps/studio/artboard-still-persist.ts +166 -0
- package/apps/studio/artboard-still-raster.ts +6 -2
- package/apps/studio/artboard-still.ts +390 -20
- package/apps/studio/asset-added.ts +154 -0
- package/apps/studio/asset-details.ts +46 -3
- package/apps/studio/asset-origins.ts +5 -3
- package/apps/studio/asset-trash.ts +6 -1
- package/apps/studio/bin/_agent-browser-safe.mjs +3 -4
- package/apps/studio/bin/_annotate-post.mjs +14 -5
- package/apps/studio/bin/_audio-search.mjs +8 -2
- package/apps/studio/bin/_curl-local.mjs +7 -4
- package/apps/studio/bin/_desktop-locate.sh +145 -0
- package/apps/studio/bin/_ds-check-live.mjs +2 -1
- package/apps/studio/bin/_exports.mjs +38 -2
- package/apps/studio/bin/_history.mjs +79 -8
- package/apps/studio/bin/_import-asset.mjs +14 -9
- package/apps/studio/bin/_import-figma.mjs +510 -98
- package/apps/studio/bin/_index-cli.mjs +10 -21
- package/apps/studio/bin/_ingest-footage.mjs +24 -6
- package/apps/studio/bin/_media-probe.mjs +232 -0
- package/apps/studio/bin/_perf-probe-open.mjs +6 -0
- package/apps/studio/bin/_perf-probe-safari.mjs +6 -0
- package/apps/studio/bin/_perf-probe-studio.mjs +6 -1
- package/apps/studio/bin/_perf-probe.mjs +8 -3
- package/apps/studio/bin/_perf-sweep-shared.mjs +789 -0
- package/apps/studio/bin/_perf-sweep.mjs +240 -0
- package/apps/studio/bin/_record-shot.sh +33 -8
- package/apps/studio/bin/_screenshot-playwright.mjs +45 -2
- package/apps/studio/bin/_studio-verb.mjs +8 -3
- package/apps/studio/bin/_thumb-route.mjs +21 -0
- package/apps/studio/bin/_thumbs-playwright.mjs +83 -1
- package/apps/studio/bin/_transcribe.mjs +22 -6
- package/apps/studio/bin/_unsynced-refs.mjs +22 -0
- package/apps/studio/bin/_url-guard.mjs +120 -5
- package/apps/studio/bin/_url-guard.sh +29 -7
- package/apps/studio/bin/_video-limits.mjs +104 -0
- package/apps/studio/bin/_video-playwright.mjs +119 -19
- package/apps/studio/bin/_video-proxy.mjs +130 -0
- package/apps/studio/bin/_write-claim.mjs +38 -16
- package/apps/studio/bin/annotate.mjs +12 -2
- package/apps/studio/bin/canvas-rects.sh +19 -4
- package/apps/studio/bin/chat-open.sh +7 -1
- package/apps/studio/bin/draw-proof.sh +6 -2
- package/apps/studio/bin/generate.sh +32 -10
- package/apps/studio/bin/handoff.sh +2 -2
- package/apps/studio/bin/perf.sh +96 -15
- package/apps/studio/bin/photo-adjust.sh +6 -3
- package/apps/studio/bin/photo-bg-remove.sh +2 -2
- package/apps/studio/bin/prep.sh +21 -4
- package/apps/studio/bin/read-annotations.mjs +3 -0
- package/apps/studio/bin/runtime-health.sh +27 -1
- package/apps/studio/bin/screenshot.sh +152 -12
- package/apps/studio/bin/server-up.sh +64 -6
- package/apps/studio/bin/smoke.sh +43 -8
- package/apps/studio/bin/to-lottie.sh +3 -2
- package/apps/studio/bin/video-proxy.sh +27 -0
- package/apps/studio/bin/visual-sanity.sh +3 -1
- package/apps/studio/bridge/dgn-protocol.ts +157 -1
- package/apps/studio/bridge/mode-shows.ts +8 -6
- package/apps/studio/bridge/still-webp.ts +233 -0
- package/apps/studio/build.ts +18 -0
- package/apps/studio/canvas-build.ts +93 -11
- package/apps/studio/canvas-comment-mount.tsx +53 -8
- package/apps/studio/canvas-edit.ts +34 -1
- package/apps/studio/canvas-lib-module.ts +210 -0
- package/apps/studio/canvas-lib.tsx +3 -12
- package/apps/studio/canvas-pipeline.ts +111 -5
- package/apps/studio/canvas-shell.tsx +8 -11
- package/apps/studio/canvas-theme-pill.tsx +5 -3
- package/apps/studio/check/index.ts +12 -5
- package/apps/studio/check/video.ts +18 -2
- package/apps/studio/client/app.jsx +65 -7
- package/apps/studio/client/clipboard-relay.ts +193 -16
- package/apps/studio/client/comments-overlay.css +18 -0
- package/apps/studio/client/export-center.jsx +30 -0
- package/apps/studio/client/generate-dialog.jsx +49 -4
- package/apps/studio/client/github.js +7 -0
- package/apps/studio/client/home/HomeAccountsRow.jsx +221 -0
- package/apps/studio/client/home/HomeConnection.jsx +111 -0
- package/apps/studio/client/home/home-accounts-model.js +110 -1
- package/apps/studio/client/home/home-api.js +9 -2
- package/apps/studio/client/home/home-app.jsx +126 -13
- package/apps/studio/client/home/home-model.js +69 -1
- package/apps/studio/client/home/home-where-model.js +105 -0
- package/apps/studio/client/home/home.css +239 -1
- package/apps/studio/client/hooks/use-canvas-bridge.jsx +173 -98
- package/apps/studio/client/hooks/use-palette-and-panels.jsx +5 -1
- package/apps/studio/client/hooks/use-tabs.jsx +11 -4
- package/apps/studio/client/panels/DiffView.jsx +7 -1
- package/apps/studio/client/panels/TeamProjects.jsx +137 -134
- package/apps/studio/client/panels/chat-context.js +2 -0
- package/apps/studio/client/panels/slash-commands.gen.js +13 -13
- package/apps/studio/client/selection-scope.js +16 -9
- package/apps/studio/client/share-link.js +12 -0
- package/apps/studio/client/shell/viewport.jsx +11 -1
- package/apps/studio/client/shell-events.js +8 -0
- package/apps/studio/client/styles/3-kit-maude-v2.css +16 -0
- package/apps/studio/client/styles/_index.css +4 -0
- package/apps/studio/client/v2/ai/Feed.jsx +1 -1
- package/apps/studio/client/v2/ai/OfferCard.jsx +34 -0
- package/apps/studio/client/v2/ai/activity-line.js +54 -1
- package/apps/studio/client/v2/ai/ai-offer.js +21 -1
- package/apps/studio/client/v2/ai/run-model.js +3 -1
- package/apps/studio/client/v2/annotations/vote-store.js +28 -4
- package/apps/studio/client/v2/assets/asset-drop-session.js +37 -2
- package/apps/studio/client/v2/assets/canvas-drop-catcher.jsx +7 -5
- package/apps/studio/client/v2/assets/details-model.js +1 -1
- package/apps/studio/client/v2/assets/details.jsx +5 -0
- package/apps/studio/client/v2/assets/tile-drag.js +11 -7
- package/apps/studio/client/v2/comments/comments-panel.jsx +22 -3
- package/apps/studio/client/v2/create/duplicate-done.js +6 -2
- package/apps/studio/client/v2/diagnostics/diagnostics-host.jsx +1 -0
- package/apps/studio/client/v2/diagnostics/diagnostics-model.js +32 -2
- package/apps/studio/client/v2/diagnostics/diagnostics-sheet.jsx +35 -8
- package/apps/studio/client/v2/diagnostics/diagnostics.css +34 -0
- package/apps/studio/client/v2/diagnostics/sync-details/sync-details-model.js +113 -3
- package/apps/studio/client/v2/diagnostics/sync-details/sync-details.jsx +343 -6
- package/apps/studio/client/v2/diagnostics/sync-details/unsynced-refs.js +55 -0
- package/apps/studio/client/v2/ds/review.css +1 -1
- package/apps/studio/client/v2/export/exports-model.js +7 -0
- package/apps/studio/client/v2/export/exports-panel.jsx +1 -0
- package/apps/studio/client/v2/export/job-row.jsx +32 -2
- package/apps/studio/client/v2/handoff/ready-card.jsx +1 -1
- package/apps/studio/client/v2/history/compare-view.jsx +1 -0
- package/apps/studio/client/v2/inspector/css-write.js +6 -1
- package/apps/studio/client/v2/inspector/frame.jsx +28 -4
- package/apps/studio/client/v2/inspector/kinds/clip-model.js +51 -0
- package/apps/studio/client/v2/inspector/kinds/clip.jsx +75 -2
- package/apps/studio/client/v2/inspector/model.js +21 -0
- package/apps/studio/client/v2/inspector/sections/fill.jsx +12 -3
- package/apps/studio/client/v2/inspector/sections/recent-colours.js +8 -5
- package/apps/studio/client/v2/inspector/view-mode.jsx +11 -1
- package/apps/studio/client/v2/link-server/LinkServerDialog.jsx +492 -0
- package/apps/studio/client/v2/link-server/LinkServerHost.jsx +42 -0
- package/apps/studio/client/v2/link-server/link-server-api.js +142 -0
- package/apps/studio/client/v2/link-server/link-server-model.js +438 -0
- package/apps/studio/client/v2/link-server/link-server.css +109 -0
- package/apps/studio/client/v2/onboarding/AdvancedSheets.jsx +31 -86
- package/apps/studio/client/v2/onboarding/onboarding-model.js +1 -18
- package/apps/studio/client/v2/preview/link-follow.js +4 -2
- package/apps/studio/client/v2/preview/preview-chrome-host.jsx +16 -6
- package/apps/studio/client/v2/search/help-model.js +2 -0
- package/apps/studio/client/v2/search/search-keywords.js +3 -2
- package/apps/studio/client/v2/settings/account.jsx +4 -2
- package/apps/studio/client/v2/settings/advanced-section.jsx +344 -137
- package/apps/studio/client/v2/settings/connection-row.jsx +3 -59
- package/apps/studio/client/v2/settings/connections-section.jsx +118 -425
- package/apps/studio/client/v2/settings/general-section.jsx +155 -24
- package/apps/studio/client/v2/settings/project-sync-settings.jsx +4 -3
- package/apps/studio/client/v2/settings/reset-section.jsx +14 -3
- package/apps/studio/client/v2/settings/settings-card.jsx +142 -0
- package/apps/studio/client/v2/settings/settings-cards.js +220 -0
- package/apps/studio/client/v2/settings/settings-handlers.js +7 -6
- package/apps/studio/client/v2/settings/settings-model.js +100 -31
- package/apps/studio/client/v2/settings/settings-sheet.jsx +25 -6
- package/apps/studio/client/v2/settings/settings.css +374 -64
- package/apps/studio/client/v2/settings/this-project-card.jsx +730 -0
- package/apps/studio/client/v2/settings/this-project-model.js +172 -0
- package/apps/studio/client/v2/settings/use-connections.js +3 -2
- package/apps/studio/client/v2/settings/use-open-card.js +37 -0
- package/apps/studio/client/v2/share/share-sheet.jsx +28 -11
- package/apps/studio/client/v2/shell/api-session-boot.js +6 -0
- package/apps/studio/client/v2/shell/api-session.js +126 -0
- package/apps/studio/client/v2/shell/connection-state.js +197 -0
- package/apps/studio/client/v2/shell/floating-panels.css +31 -1
- package/apps/studio/client/v2/shell/image-pick.js +61 -8
- package/apps/studio/client/v2/shell/menu-aim.js +43 -0
- package/apps/studio/client/v2/shell/menu-runner.js +25 -7
- package/apps/studio/client/v2/shell/occlusion-insets.js +18 -1
- package/apps/studio/client/v2/shell/project-account-bus.js +36 -0
- package/apps/studio/client/v2/shell/project-account-card.jsx +357 -148
- package/apps/studio/client/v2/shell/project-account-model.js +272 -149
- package/apps/studio/client/v2/shell/project-account-toast.js +66 -0
- package/apps/studio/client/v2/shell/project-account.css +237 -0
- package/apps/studio/client/v2/shell/project-pill.jsx +52 -6
- package/apps/studio/client/v2/shell/share-cluster-host.jsx +166 -83
- package/apps/studio/client/v2/shell/shell-parity.js +3 -2
- package/apps/studio/client/v2/shell/shell-parity.json +71 -36
- package/apps/studio/client/v2/shell/still-bridge.js +194 -0
- package/apps/studio/client/v2/shell/still-store.js +319 -0
- package/apps/studio/client/v2/shell/use-account.js +2 -0
- package/apps/studio/client/v2/shell/use-tool-panels.js +2 -1
- package/apps/studio/client/v2/signin/use-signin.js +1 -1
- package/apps/studio/client/v2/timeline/Timeline.jsx +15 -0
- package/apps/studio/client/v2/timeline/frame-handle-model.js +142 -0
- package/apps/studio/client/v2/timeline/frame-handle.jsx +151 -0
- package/apps/studio/clip-ops.ts +126 -8
- package/apps/studio/cloud/endpoints.ts +29 -4
- package/apps/studio/collab/ai-activity.ts +10 -8
- package/apps/studio/collab/awareness-bridge.ts +34 -9
- package/apps/studio/collab/index.ts +3 -0
- package/apps/studio/collab/registry.ts +41 -10
- package/apps/studio/comment-reattach.ts +149 -0
- package/apps/studio/comments/mine-stamp.ts +15 -7
- package/apps/studio/comments/ops.ts +52 -8
- package/apps/studio/comments-overlay.tsx +146 -9
- package/apps/studio/dist/client.bundle.js +892 -885
- package/apps/studio/dist/comment-mount.js +2 -2
- package/apps/studio/dist/styles.css +1 -1
- package/apps/studio/dom-selection.ts +87 -18
- package/apps/studio/ds/board/directions.css +8 -0
- package/apps/studio/ds/board/outline.tsx +16 -0
- package/apps/studio/ds/canvas-check.ts +6 -0
- package/apps/studio/edit-ops/clip/reframe.ts +19 -3
- package/apps/studio/edit-ops/clip-carry.ts +602 -0
- package/apps/studio/edit-ops/clipboard.ts +318 -23
- package/apps/studio/edit-ops/dispatch.ts +20 -2
- package/apps/studio/edit-ops/scope-names.ts +249 -40
- package/apps/studio/edit-ops/slot-defaults.ts +3 -0
- package/apps/studio/edit-ops/types.ts +6 -0
- package/apps/studio/editing/align-bar.tsx +33 -9
- package/apps/studio/editing/artboard-actions.ts +5 -0
- package/apps/studio/editing/artboard-menu.tsx +6 -2
- package/apps/studio/editing/click-to-type.ts +1 -1
- package/apps/studio/editing/clip-words.ts +48 -0
- package/apps/studio/editing/clipboard.ts +21 -6
- package/apps/studio/editing/declared-background.ts +25 -0
- package/apps/studio/editing/index.tsx +3 -0
- package/apps/studio/editing/object-keys.ts +4 -4
- package/apps/studio/editing/object-menu.tsx +13 -3
- package/apps/studio/editing/pen/points.tsx +61 -0
- package/apps/studio/editing/text-in-place.tsx +11 -0
- package/apps/studio/editing/video-frame-handle.tsx +425 -0
- package/apps/studio/exporters/capture-prepass.ts +374 -0
- package/apps/studio/exporters/degraded.ts +148 -0
- package/apps/studio/exporters/hub-render-door.ts +28 -2
- package/apps/studio/exporters/index.ts +3 -1
- package/apps/studio/exporters/job-budget.ts +93 -0
- package/apps/studio/exporters/jobs.ts +215 -28
- package/apps/studio/exporters/parity-check.ts +254 -0
- package/apps/studio/exporters/remote.ts +209 -15
- package/apps/studio/exporters/svg-inline.ts +87 -0
- package/apps/studio/exporters/video-render-lib.ts +88 -26
- package/apps/studio/exporters/video.ts +29 -6
- package/apps/studio/figma/assets.ts +58 -43
- package/apps/studio/figma/codegen-fonts.ts +100 -0
- package/apps/studio/figma/fig-decode.ts +390 -25
- package/apps/studio/figma/fig-kiwi.ts +18 -4
- package/apps/studio/figma/fig-vector.ts +59 -3
- package/apps/studio/figma/sanitize.ts +2 -0
- package/apps/studio/figma/style-map.ts +293 -48
- package/apps/studio/figma/to-artboard.ts +455 -69
- package/apps/studio/figma/to-strokes.ts +44 -11
- package/apps/studio/figma/types.ts +13 -0
- package/apps/studio/footage/schema.ts +3 -3
- package/apps/studio/generation/adapters/elevenlabs.ts +7 -1
- package/apps/studio/generation/adapters/groq.ts +8 -1
- package/apps/studio/generation/spend.ts +312 -0
- package/apps/studio/generation/types.ts +12 -0
- package/apps/studio/handoff/run.ts +1 -1
- package/apps/studio/handoff/targets.ts +2 -2
- package/apps/studio/handoff/write-scopes.ts +1 -1
- package/apps/studio/history/describe-annotations.ts +4 -0
- package/apps/studio/home/accounts.ts +30 -11
- package/apps/studio/home/cloud.ts +6 -1
- package/apps/studio/home/create-local.ts +32 -3
- package/apps/studio/home/hub-health.ts +76 -0
- package/apps/studio/home/routes.ts +15 -4
- package/apps/studio/http.ts +438 -86
- package/apps/studio/imported-module-ids.ts +91 -0
- package/apps/studio/inspect.ts +2 -0
- package/apps/studio/migrate/hub.ts +8 -1
- package/apps/studio/notifications.tsx +47 -5
- package/apps/studio/paths.ts +10 -1
- package/apps/studio/port.ts +3 -2
- package/apps/studio/preview/preview-camera.tsx +15 -382
- package/apps/studio/readiness.ts +10 -1
- package/apps/studio/release-build.ts +51 -0
- package/apps/studio/routes/agent.ts +188 -9
- package/apps/studio/routes/ai.ts +43 -11
- package/apps/studio/routes/annotations.ts +27 -1
- package/apps/studio/routes/assets.ts +18 -1
- package/apps/studio/routes/canvas-origin.ts +12 -9
- package/apps/studio/routes/cloud-move.ts +15 -0
- package/apps/studio/routes/edit.ts +3 -0
- package/apps/studio/routes/export.ts +51 -0
- package/apps/studio/routes/generate.ts +42 -12
- package/apps/studio/routes/hub-link-folder.ts +334 -0
- package/apps/studio/routes/hub-signin.ts +78 -1
- package/apps/studio/routes/index.ts +9 -1
- package/apps/studio/routes/shell.ts +217 -5
- package/apps/studio/routes/sync.ts +136 -8
- package/apps/studio/routes/votes.ts +2 -1
- package/apps/studio/schema/annotations.v2.schema.json +143 -1
- package/apps/studio/schema/beats.v1.schema.json +1 -1
- package/apps/studio/schema/edl.v1.schema.json +1 -1
- package/apps/studio/schema/formats.ts +3 -3
- package/apps/studio/schema/transcript.v1.schema.json +1 -1
- package/apps/studio/server.ts +142 -43
- package/apps/studio/shell/api-key.ts +503 -0
- package/apps/studio/shell/attest.ts +59 -0
- package/apps/studio/shell/capture-url.ts +20 -0
- package/apps/studio/shell/cli-yield.ts +276 -0
- package/apps/studio/shell/clip-transfer.ts +302 -0
- package/apps/studio/shell/key-file.ts +108 -0
- package/apps/studio/shell/server-json.ts +75 -0
- package/apps/studio/shell/worktree.ts +19 -0
- package/apps/studio/spoof-chars.ts +9 -0
- package/apps/studio/studio-page-host.ts +1 -1
- package/apps/studio/sync/accepted-cold-start.ts +144 -8
- package/apps/studio/sync/accepted-link.ts +76 -29
- package/apps/studio/sync/action-stage.ts +575 -44
- package/apps/studio/sync/adopt-held.ts +85 -0
- package/apps/studio/sync/ctl-heal.ts +58 -0
- package/apps/studio/sync/file-ledger.ts +38 -4
- package/apps/studio/sync/file-membership.ts +16 -1
- package/apps/studio/sync/file-plane.ts +289 -22
- package/apps/studio/sync/held-deletes.ts +86 -5
- package/apps/studio/sync/hub-link.ts +8 -0
- package/apps/studio/sync/index.ts +196 -12
- package/apps/studio/sync/journal-client.ts +50 -4
- package/apps/studio/sync/link-consent.ts +22 -75
- package/apps/studio/sync/link-survey.ts +252 -0
- package/apps/studio/sync/local-kernel.ts +296 -8
- package/apps/studio/sync/projection.ts +22 -3
- package/apps/studio/sync/seed-progress.ts +12 -0
- package/apps/studio/sync/source-recovery.ts +59 -3
- package/apps/studio/sync/status.ts +19 -2
- package/apps/studio/sync/unsynced-refs.ts +397 -0
- package/apps/studio/sync/writer-registry.ts +20 -0
- package/apps/studio/thumbs/service.ts +4 -1
- package/apps/studio/tool-palette.tsx +23 -0
- package/apps/studio/ui-prefs.ts +40 -0
- package/apps/studio/use-agent-presence.tsx +2 -2
- package/apps/studio/use-canvas-keys.ts +6 -1
- package/apps/studio/video/format-ids.ts +2 -2
- package/apps/studio/video/inject.ts +31 -0
- package/apps/studio/video/media-risk.ts +58 -0
- package/apps/studio/video/object-fit.ts +137 -0
- package/apps/studio/video/provider-transcript.ts +141 -0
- package/apps/studio/whats-new.json +137 -0
- package/apps/studio/workspace-mode.ts +1 -0
- package/apps/studio/ws.ts +5 -0
- package/cli/commands/design.mjs +119 -8
- package/cli/lib/bash-guard.mjs +366 -6
- package/cli/lib/confine-read.mjs +1 -0
- package/cli/lib/design-help.gen.mjs +3 -2
- package/cli/lib/design-hook.mjs +387 -81
- package/cli/lib/design-link.mjs +16 -1
- package/cli/lib/design-open.mjs +49 -3
- package/cli/lib/desktop-locate.mjs +770 -0
- package/cli/lib/handoff.mjs +1 -1
- package/cli/lib/hook-state.mjs +291 -0
- package/cli/lib/pkg-root.mjs +65 -13
- package/cli/lib/studio-locate.mjs +59 -16
- package/package.json +15 -8
- package/plugins/design/templates/_shell.html +13 -0
- package/apps/studio/client/v2/onboarding/HubSheet.jsx +0 -212
- package/apps/studio/client/v2/shell/account-card-model.js +0 -114
- package/apps/studio/client/v2/shell/account-card.jsx +0 -189
|
@@ -0,0 +1,503 @@
|
|
|
1
|
+
// The loopback API key for credential routes — contract `client/v2/contracts/sec-loopback-bearer.md`.
|
|
2
|
+
//
|
|
3
|
+
// A credential route uses a credential this computer holds for the person (the GitHub token, a
|
|
4
|
+
// cloud or team-server credential, a provider key) or spends their money. A caller that is not a
|
|
5
|
+
// browser sends no `Origin`, so `sameOriginWrite` let it through, and a loopback `Host` passed the
|
|
6
|
+
// DNS-rebind guard: any local process could use those credentials. Such a caller now needs the
|
|
7
|
+
// per-spawn key; a browser caller still needs to be same-origin.
|
|
8
|
+
//
|
|
9
|
+
// The key comes from `MAUDE_SHELL_API_KEY` (64 hex), read once at first import and deleted from
|
|
10
|
+
// `process.env` — nothing this server spawns inherits it (scrubAgentEnv also drops every
|
|
11
|
+
// `MAUDE_SHELL_*`, acp/env.ts). Without it the server mints one per process and writes it nowhere.
|
|
12
|
+
// It is never written to `_server.json` or anywhere in the project.
|
|
13
|
+
//
|
|
14
|
+
// Phase 2 (contract §7): a server whose starter handed it a key (the desktop app, for every
|
|
15
|
+
// project spawn) is in REQUIRED mode — every main-origin request needs the key, the app's own
|
|
16
|
+
// page included (`mainOriginKeyRefusal`, wired in server.ts on the main listener only). The page
|
|
17
|
+
// trades the key for an HttpOnly session cookie once; a browser opened from the terminal trades a
|
|
18
|
+
// one-time launch token in its opening URL for the same cookie.
|
|
19
|
+
|
|
20
|
+
import { createHash, createHmac, randomBytes, timingSafeEqual } from 'node:crypto';
|
|
21
|
+
|
|
22
|
+
import { isLoopbackHost } from '../sync/loopback.ts';
|
|
23
|
+
import { isWorkspaceMode } from '../workspace-mode.ts';
|
|
24
|
+
import { isCliRole } from './cli-yield.ts';
|
|
25
|
+
|
|
26
|
+
export const API_KEY_ENV = 'MAUDE_SHELL_API_KEY';
|
|
27
|
+
export const API_KEY_HEADER = 'x-maude-api-key';
|
|
28
|
+
const KEY_RE = /^[0-9a-fA-F]{64}$/;
|
|
29
|
+
|
|
30
|
+
/** Phase 1: the GitHub routes. Phase 2 families are listed in the contract §4. */
|
|
31
|
+
const CREDENTIAL_ROUTE_RE = /^\/_api\/github\//;
|
|
32
|
+
|
|
33
|
+
export function isCredentialRoute(pathname: string): boolean {
|
|
34
|
+
return CREDENTIAL_ROUTE_RE.test(pathname);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Read the key from `env` and delete it there. A malformed key reads as none (fail closed). */
|
|
38
|
+
export function takeApiKey(env: Record<string, string | undefined> = process.env): string | null {
|
|
39
|
+
const v = env[API_KEY_ENV];
|
|
40
|
+
delete env[API_KEY_ENV];
|
|
41
|
+
if (!v) return null;
|
|
42
|
+
if (!KEY_RE.test(v)) {
|
|
43
|
+
console.warn(`[maude] ${API_KEY_ENV} is not 64 hex characters; a fresh key is used instead.`);
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
return v;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const ENV_KEY = takeApiKey(process.env);
|
|
50
|
+
const BOOT_KEY = ENV_KEY ?? randomBytes(32).toString('hex');
|
|
51
|
+
/**
|
|
52
|
+
* §7.5 — a terminal-started server (role `cli`: `maude design serve`, `server-up`) mints its own
|
|
53
|
+
* key, writes it to the per-user key file (shell/key-file.ts) and opens with a launch token.
|
|
54
|
+
*/
|
|
55
|
+
const TERMINAL_ROLE = ENV_KEY === null && isCliRole(process.env);
|
|
56
|
+
/**
|
|
57
|
+
* re-check F — with the canvas-origin split off (`MAUDE_CANVAS_ORIGIN_SPLIT=0`, server.ts) there is
|
|
58
|
+
* no capture origin to mint a frame capability for, so the key-less headless captures (exports,
|
|
59
|
+
* thumbnails, helpers) cannot render, and canvas code runs on the main origin with the page's own
|
|
60
|
+
* session anyway. A terminal starter in that mode therefore stays key-less (phase 1). The desktop
|
|
61
|
+
* app never turns the split off; a key it hands over keeps required mode either way.
|
|
62
|
+
*/
|
|
63
|
+
const CANVAS_SPLIT_OFF = /^(0|false|off|no)$/i.test(process.env.MAUDE_CANVAS_ORIGIN_SPLIT ?? '');
|
|
64
|
+
const TERMINAL_REQUIRED = TERMINAL_ROLE && !CANVAS_SPLIT_OFF;
|
|
65
|
+
|
|
66
|
+
/** re-check F — a terminal server left key-less because the split is off (the boot line says so). */
|
|
67
|
+
export function terminalKeylessForSplitOff(): boolean {
|
|
68
|
+
return TERMINAL_ROLE && CANVAS_SPLIT_OFF && !isWorkspaceMode();
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* §7.1 — a starter handed this process its key (the desktop app), or a terminal starter asked
|
|
72
|
+
* for one (§7.5): every main-origin caller needs it. A server started with neither (a bare
|
|
73
|
+
* `bun server.ts`, a test harness) keeps phase 1: credential routes only.
|
|
74
|
+
*/
|
|
75
|
+
const BOOT_REQUIRED = ENV_KEY !== null || TERMINAL_REQUIRED;
|
|
76
|
+
|
|
77
|
+
/** This process's key (in-process launch-URL minting, phase 2b). */
|
|
78
|
+
export function bootApiKey(): string {
|
|
79
|
+
return BOOT_KEY;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** §7.5 — did this server mint its own key as a terminal-started server (it writes the key file)? */
|
|
83
|
+
export function terminalKeyMode(): boolean {
|
|
84
|
+
return TERMINAL_REQUIRED && !isWorkspaceMode();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** §7.1 — is this server in required mode? */
|
|
88
|
+
export function apiKeyRequired(): boolean {
|
|
89
|
+
return BOOT_REQUIRED && !isWorkspaceMode();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function presentedKey(req: Request): string | null {
|
|
93
|
+
const h = req.headers.get(API_KEY_HEADER);
|
|
94
|
+
if (h) return h;
|
|
95
|
+
const auth = req.headers.get('authorization');
|
|
96
|
+
const m = auth ? /^Bearer\s+(\S+)$/i.exec(auth) : null;
|
|
97
|
+
return m ? m[1] : null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function keyMatches(presented: string, key: string): boolean {
|
|
101
|
+
const a = Buffer.from(presented, 'utf8');
|
|
102
|
+
const b = Buffer.from(key, 'utf8');
|
|
103
|
+
return a.length === b.length && timingSafeEqual(a, b);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function sameHostOrigin(req: Request, origin: string): boolean {
|
|
107
|
+
try {
|
|
108
|
+
return new URL(origin).host === new URL(req.url).host;
|
|
109
|
+
} catch {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const refuse = (status: 401 | 403, error: string) =>
|
|
115
|
+
Response.json({ ok: false, error }, { status, headers: { 'Cache-Control': 'no-store' } });
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* `null` = let the route's own gates decide. A Response = refused here. `opts` exists for tests;
|
|
119
|
+
* the server passes nothing (its boot key, and workspace mode from the environment).
|
|
120
|
+
*/
|
|
121
|
+
export function credentialRouteRefusal(
|
|
122
|
+
req: Request,
|
|
123
|
+
opts: { key?: string; workspace?: boolean } = {}
|
|
124
|
+
): Response | null {
|
|
125
|
+
let pathname: string;
|
|
126
|
+
try {
|
|
127
|
+
pathname = new URL(req.url).pathname;
|
|
128
|
+
} catch {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
if (!isCredentialRoute(pathname)) return null;
|
|
132
|
+
// A cell: the hub proxy authenticated the request, and the secret-bearing families are pruned.
|
|
133
|
+
if (opts.workspace ?? isWorkspaceMode()) return null;
|
|
134
|
+
const presented = presentedKey(req);
|
|
135
|
+
if (presented !== null)
|
|
136
|
+
return keyMatches(presented, opts.key ?? BOOT_KEY) ? null : refuse(401, 'api-key-invalid');
|
|
137
|
+
const origin = req.headers.get('origin');
|
|
138
|
+
const site = req.headers.get('sec-fetch-site');
|
|
139
|
+
if (!origin && !site) return refuse(401, 'api-key-required');
|
|
140
|
+
if (origin && !sameHostOrigin(req, origin)) return refuse(403, 'cross-origin rejected');
|
|
141
|
+
if (site && site !== 'same-origin' && site !== 'none')
|
|
142
|
+
return refuse(403, 'cross-origin rejected');
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/* ------------------------------------------------------------------ phase 2 (contract §7) */
|
|
147
|
+
|
|
148
|
+
export const SESSION_PATH = '/_api/shell/session';
|
|
149
|
+
export const LAUNCH_PARAM = 'maude-launch';
|
|
150
|
+
const LAUNCH_DOMAIN = 'maude-launch/1';
|
|
151
|
+
/** re-check G — a capture helper's own browser: its token and session are kept apart from the person's. */
|
|
152
|
+
const HELPER_LAUNCH_DOMAIN = 'maude-launch-helper/1';
|
|
153
|
+
const COOKIE_NAME_DOMAIN = 'maude-cookie-name/1';
|
|
154
|
+
export const LAUNCH_TTL_SEC = 300;
|
|
155
|
+
/** §7.2 — a session not used for this long is gone (the page trades its key or a fresh link again). */
|
|
156
|
+
export const SESSION_IDLE_MS = 12 * 60 * 60 * 1000;
|
|
157
|
+
/** re-check D — and none lives longer than this, used or not (a leaked cookie dies within a day). */
|
|
158
|
+
export const SESSION_MAX_AGE_MS = 24 * 60 * 60 * 1000;
|
|
159
|
+
/** re-check G — a helper's session (a capture, a perf run) is never used again once it is done. */
|
|
160
|
+
export const HELPER_SESSION_IDLE_MS = 30 * 60 * 1000;
|
|
161
|
+
const LAUNCH_RE = /^(h?)(\d{1,12})\.([0-9a-f]{32})\.([0-9a-f]{64})$/;
|
|
162
|
+
const SESSION_VALUE_RE = /^[0-9a-f]{64}$/;
|
|
163
|
+
const MAX_USED_NONCES = 4096;
|
|
164
|
+
const MAX_SESSIONS = 256;
|
|
165
|
+
/** re-check G — the helpers' own budget: a run of captures never pushes out the person's session. */
|
|
166
|
+
const MAX_HELPER_SESSIONS = 32;
|
|
167
|
+
const SHELL_OWN_CREDENTIAL_RE =
|
|
168
|
+
/^\/_api\/shell\/(status|attest|clip-export|clip-asset|clip-import)$/;
|
|
169
|
+
|
|
170
|
+
const hmacHex = (key: string, msg: string) => createHmac('sha256', key).update(msg).digest('hex');
|
|
171
|
+
const sha256Hex = (v: string) => createHash('sha256').update(v).digest('hex');
|
|
172
|
+
const noStore = { 'Cache-Control': 'no-store' };
|
|
173
|
+
|
|
174
|
+
/** The session cookie's name: per key, so two servers on 127.0.0.1 never overwrite each other's. */
|
|
175
|
+
export function sessionCookieName(key: string): string {
|
|
176
|
+
return `maude_k_${hmacHex(key, COOKIE_NAME_DOMAIN).slice(0, 12)}`;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* §7.2 — the live sessions: sha256(cookie value) → { last use, opened, helper } (ms). The value is
|
|
181
|
+
* random and held only in this process (never derived from the key), so a leaked cookie dies with
|
|
182
|
+
* idleness, its 24 h lifetime or a restart. Helper sessions (a capture's own browser) have their
|
|
183
|
+
* own budget and a short idle expiry, so they never evict the person's.
|
|
184
|
+
*/
|
|
185
|
+
export type SessionRec = { seen: number; born: number; helper: boolean };
|
|
186
|
+
export type SessionStore = Map<string, SessionRec>;
|
|
187
|
+
const SESSIONS: SessionStore = new Map();
|
|
188
|
+
|
|
189
|
+
function sessionExpired(rec: SessionRec, nowMs: number): boolean {
|
|
190
|
+
const idle = rec.helper ? HELPER_SESSION_IDLE_MS : SESSION_IDLE_MS;
|
|
191
|
+
return nowMs - rec.seen > idle || nowMs - rec.born > SESSION_MAX_AGE_MS;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function sessionLive(store: SessionStore, value: string, nowMs: number): boolean {
|
|
195
|
+
if (!SESSION_VALUE_RE.test(value)) return false;
|
|
196
|
+
const id = sha256Hex(value);
|
|
197
|
+
const rec = store.get(id);
|
|
198
|
+
if (rec === undefined) return false;
|
|
199
|
+
if (sessionExpired(rec, nowMs)) {
|
|
200
|
+
store.delete(id);
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
rec.seen = nowMs;
|
|
204
|
+
return true;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* A fresh session. Each exchange rotates: the session the caller presented, if any, is dropped. At
|
|
209
|
+
* the cap, the least recently used session of the SAME kind goes (a helper never evicts the person).
|
|
210
|
+
*/
|
|
211
|
+
function openSession(
|
|
212
|
+
store: SessionStore,
|
|
213
|
+
nowMs: number,
|
|
214
|
+
replacing: string | null,
|
|
215
|
+
helper = false
|
|
216
|
+
): string {
|
|
217
|
+
if (replacing) store.delete(sha256Hex(replacing));
|
|
218
|
+
for (const [id, rec] of store) if (sessionExpired(rec, nowMs)) store.delete(id);
|
|
219
|
+
const cap = helper ? MAX_HELPER_SESSIONS : MAX_SESSIONS;
|
|
220
|
+
for (;;) {
|
|
221
|
+
let count = 0;
|
|
222
|
+
let oldest: string | null = null;
|
|
223
|
+
let at = Number.POSITIVE_INFINITY;
|
|
224
|
+
for (const [id, rec] of store) {
|
|
225
|
+
if (rec.helper !== helper) continue;
|
|
226
|
+
count++;
|
|
227
|
+
if (rec.seen < at) {
|
|
228
|
+
at = rec.seen;
|
|
229
|
+
oldest = id;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (count < cap || oldest === null) break;
|
|
233
|
+
store.delete(oldest);
|
|
234
|
+
}
|
|
235
|
+
const value = randomBytes(32).toString('hex');
|
|
236
|
+
store.set(sha256Hex(value), { seen: nowMs, born: nowMs, helper });
|
|
237
|
+
return value;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function setCookieHeader(key: string, value: string): string {
|
|
241
|
+
return `${sessionCookieName(key)}=${value}; Path=/; HttpOnly; SameSite=Strict`;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* A one-time launch token (§7.4): `<ts>.<nonce>.<mac>`. Anyone holding the key can mint one. A
|
|
246
|
+
* `helper` token (`h<ts>.<nonce>.<mac>`, its own MAC domain) opens a helper session (re-check G).
|
|
247
|
+
*/
|
|
248
|
+
export function mintLaunchToken(
|
|
249
|
+
key: string,
|
|
250
|
+
nowSec = Math.floor(Date.now() / 1000),
|
|
251
|
+
kind: 'person' | 'helper' = 'person'
|
|
252
|
+
): string {
|
|
253
|
+
const nonce = randomBytes(16).toString('hex');
|
|
254
|
+
const ts = String(Math.floor(nowSec));
|
|
255
|
+
const helper = kind === 'helper';
|
|
256
|
+
const domain = helper ? HELPER_LAUNCH_DOMAIN : LAUNCH_DOMAIN;
|
|
257
|
+
return `${helper ? 'h' : ''}${ts}.${nonce}.${hmacHex(key, `${domain}\n${ts}\n${nonce}`)}`;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/** Used launch nonces → the token's own `ts` (unix s). Only an expired entry is ever dropped. */
|
|
261
|
+
export type NonceStore = Map<string, number>;
|
|
262
|
+
const USED_NONCES: NonceStore = new Map();
|
|
263
|
+
|
|
264
|
+
function cookieValue(req: Request, name: string): string | null {
|
|
265
|
+
const raw = req.headers.get('cookie');
|
|
266
|
+
if (!raw) return null;
|
|
267
|
+
for (const part of raw.split(';')) {
|
|
268
|
+
const i = part.indexOf('=');
|
|
269
|
+
if (i > 0 && part.slice(0, i).trim() === name) return part.slice(i + 1).trim();
|
|
270
|
+
}
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/** §7.3 — answered without a credential. */
|
|
275
|
+
function isExempt(method: string, pathname: string): boolean {
|
|
276
|
+
if (SHELL_OWN_CREDENTIAL_RE.test(pathname)) return true;
|
|
277
|
+
if (method !== 'GET' && method !== 'HEAD') return false;
|
|
278
|
+
return (
|
|
279
|
+
pathname === '/_health' ||
|
|
280
|
+
pathname === '/' ||
|
|
281
|
+
pathname === '/index.html' ||
|
|
282
|
+
pathname === '/_canvas-shell' ||
|
|
283
|
+
pathname === '/_canvas-shell.html' ||
|
|
284
|
+
// The team server's page sends the person's own browser back here; that browser never held
|
|
285
|
+
// the app's session. The route acts only on a `state` this process minted, once, and the code
|
|
286
|
+
// is worthless without the PKCE verifier that never left it (routes/hub-signin.ts).
|
|
287
|
+
pathname === '/_api/hub-signin/return' ||
|
|
288
|
+
pathname.startsWith('/_client/') ||
|
|
289
|
+
pathname.startsWith('/_canvas-runtime/')
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* §7.8 — routes only the person may call: a browser session on a same-origin request, never the
|
|
295
|
+
* header key every helper and verb sends. (Spend approval and spend limits depend on the body; their
|
|
296
|
+
* routes ask `personRequest` themselves, in http.ts.)
|
|
297
|
+
*/
|
|
298
|
+
const PERSON_ONLY: readonly (readonly [string, RegExp])[] = [
|
|
299
|
+
['POST', /^\/_api\/git\/push$/],
|
|
300
|
+
['POST', /^\/_api\/share\/invites(\/[^/]+\/resend)?$/],
|
|
301
|
+
['POST', /^\/_api\/cloud\/(attach|attach\/code|move|signin\/start)$/],
|
|
302
|
+
// 2.1.1 — THIS folder joins the person's team server (routes/hub-link-folder.ts)
|
|
303
|
+
['POST', /^\/_api\/hub\/link-folder$/],
|
|
304
|
+
// 2.1.1 T8 — a team-server sign-in, and saving a team-server credential, are the person's acts like
|
|
305
|
+
// the Maude Cloud sign-in above: the return hop needs no key, so starting it must need a person.
|
|
306
|
+
// The address check is the dialog's own step, so a key holder never uses it as a network probe.
|
|
307
|
+
['POST', /^\/_api\/hub\/link$/],
|
|
308
|
+
['POST', /^\/_api\/hub-signin\/(start|check)$/],
|
|
309
|
+
];
|
|
310
|
+
|
|
311
|
+
export function isPersonOnlyRoute(method: string, pathname: string): boolean {
|
|
312
|
+
return PERSON_ONLY.some(([m, re]) => m === method && re.test(pathname));
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* The session cookie, counted only same-origin: the canvas origin is the same host on another port,
|
|
317
|
+
* which a cookie treats as same-site. An `Origin` naming another host never rides it either (an
|
|
318
|
+
* engine that sends no Fetch Metadata). Returns the live value, else null.
|
|
319
|
+
*/
|
|
320
|
+
function sessionCookieOf(
|
|
321
|
+
req: Request,
|
|
322
|
+
key: string,
|
|
323
|
+
store: SessionStore,
|
|
324
|
+
nowMs: number
|
|
325
|
+
): string | null {
|
|
326
|
+
const site = req.headers.get('sec-fetch-site');
|
|
327
|
+
if (site && site !== 'same-origin' && site !== 'none') return null;
|
|
328
|
+
const origin = req.headers.get('origin');
|
|
329
|
+
if (origin && !sameHostOrigin(req, origin)) return null;
|
|
330
|
+
const got = cookieValue(req, sessionCookieName(key));
|
|
331
|
+
return got !== null && sessionLive(store, got, nowMs) ? got : null;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function loopbackHostHeader(req: Request): boolean {
|
|
335
|
+
const host = req.headers.get('host');
|
|
336
|
+
if (!host) return false;
|
|
337
|
+
try {
|
|
338
|
+
return isLoopbackHost(new URL(`http://${host}`).hostname);
|
|
339
|
+
} catch {
|
|
340
|
+
return false;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/** What authenticated a main-origin request (recorded by the gate, read by `requestCredential`). */
|
|
345
|
+
export type RequestCredential = 'key' | 'session';
|
|
346
|
+
const CREDENTIAL_OF = new WeakMap<Request, RequestCredential>();
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* §7.3 — the credential the gate saw on this request, on an exempt path too (`/_canvas-shell` mints a
|
|
350
|
+
* frame capability only for an authenticated caller). null = none, or the gate did not run.
|
|
351
|
+
*/
|
|
352
|
+
export function requestCredential(req: Request): RequestCredential | null {
|
|
353
|
+
return CREDENTIAL_OF.get(req) ?? null;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* §7.8 — is this request the person at the studio page? In required mode: a browser session (the
|
|
358
|
+
* cookie, never the header key) on a `Sec-Fetch-Site: same-origin` request whose `Origin` is this
|
|
359
|
+
* server. Outside required mode (phase 1, a cell behind its proxy) the old rule: a browser sends
|
|
360
|
+
* `Origin` on a write, the CLI never does.
|
|
361
|
+
*/
|
|
362
|
+
export function personRequest(req: Request, opts: { required?: boolean } = {}): boolean {
|
|
363
|
+
const origin = req.headers.get('origin');
|
|
364
|
+
if (!(opts.required ?? apiKeyRequired())) return !!origin;
|
|
365
|
+
if (CREDENTIAL_OF.get(req) !== 'session') return false;
|
|
366
|
+
if (req.headers.get('sec-fetch-site') !== 'same-origin') return false;
|
|
367
|
+
return !!origin && sameHostOrigin(req, origin);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
function redirectWithoutLaunch(url: URL): Response {
|
|
371
|
+
url.searchParams.delete(LAUNCH_PARAM);
|
|
372
|
+
return new Response(null, {
|
|
373
|
+
status: 303,
|
|
374
|
+
headers: {
|
|
375
|
+
Location: `${url.pathname}${url.search}`,
|
|
376
|
+
'Referrer-Policy': 'no-referrer',
|
|
377
|
+
...noStore,
|
|
378
|
+
},
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
type GateOpts = {
|
|
383
|
+
key?: string;
|
|
384
|
+
required?: boolean;
|
|
385
|
+
workspace?: boolean;
|
|
386
|
+
usedNonces?: NonceStore;
|
|
387
|
+
sessions?: SessionStore;
|
|
388
|
+
/** unix seconds */
|
|
389
|
+
now?: number;
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
const plainText = (status: number, text: string) =>
|
|
393
|
+
new Response(text, {
|
|
394
|
+
status,
|
|
395
|
+
headers: { 'Content-Type': 'text/plain; charset=utf-8', ...noStore },
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
function launchExchange(
|
|
399
|
+
url: URL,
|
|
400
|
+
key: string,
|
|
401
|
+
used: NonceStore,
|
|
402
|
+
sessions: SessionStore,
|
|
403
|
+
now: number
|
|
404
|
+
): Response {
|
|
405
|
+
const m = LAUNCH_RE.exec(url.searchParams.get(LAUNCH_PARAM) ?? '');
|
|
406
|
+
const helper = m?.[1] === 'h';
|
|
407
|
+
const ts = m?.[2] ?? '';
|
|
408
|
+
const nonce = m?.[3] ?? '';
|
|
409
|
+
const fresh = !!m && now - Number(ts) <= LAUNCH_TTL_SEC && Number(ts) - now <= 30;
|
|
410
|
+
const domain = helper ? HELPER_LAUNCH_DOMAIN : LAUNCH_DOMAIN;
|
|
411
|
+
if (
|
|
412
|
+
!m ||
|
|
413
|
+
!fresh ||
|
|
414
|
+
used.has(nonce) ||
|
|
415
|
+
!keyMatches(m[4], hmacHex(key, `${domain}\n${ts}\n${nonce}`))
|
|
416
|
+
) {
|
|
417
|
+
return plainText(
|
|
418
|
+
401,
|
|
419
|
+
'This Maude link has expired or was already used. Open the project again from Maude, or run `maude design server-up --open`.'
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
if (used.size >= MAX_USED_NONCES) {
|
|
423
|
+
// only a token past its lifetime can be forgotten: a forgotten live one would open twice
|
|
424
|
+
for (const [nonce, ts] of used) if (now - ts > LAUNCH_TTL_SEC) used.delete(nonce);
|
|
425
|
+
if (used.size >= MAX_USED_NONCES)
|
|
426
|
+
return plainText(
|
|
427
|
+
429,
|
|
428
|
+
'Too many Maude links were opened at once. Try again in a few minutes.'
|
|
429
|
+
);
|
|
430
|
+
}
|
|
431
|
+
used.set(nonce, Number(ts));
|
|
432
|
+
url.searchParams.delete(LAUNCH_PARAM);
|
|
433
|
+
return new Response(null, {
|
|
434
|
+
status: 303,
|
|
435
|
+
headers: {
|
|
436
|
+
Location: `${url.pathname}${url.search}`,
|
|
437
|
+
'Set-Cookie': setCookieHeader(key, openSession(sessions, now * 1000, null, helper)),
|
|
438
|
+
'Referrer-Policy': 'no-referrer',
|
|
439
|
+
...noStore,
|
|
440
|
+
},
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* §7 — the required-mode gate for the MAIN listener (server.ts runs it first on the routes map and
|
|
446
|
+
* in `fetch`, before any WebSocket upgrade). `null` = pass on to the route. It answers the two
|
|
447
|
+
* exchanges itself: `POST /_api/shell/session` (key → cookie) and `GET /?maude-launch=` (one-time
|
|
448
|
+
* token → cookie). `opts` exists for tests; the server passes nothing.
|
|
449
|
+
*/
|
|
450
|
+
export function mainOriginKeyRefusal(req: Request, opts: GateOpts = {}): Response | null {
|
|
451
|
+
if (opts.workspace ?? isWorkspaceMode()) return null;
|
|
452
|
+
if (!(opts.required ?? BOOT_REQUIRED)) return null;
|
|
453
|
+
const key = opts.key ?? BOOT_KEY;
|
|
454
|
+
const sessions = opts.sessions ?? SESSIONS;
|
|
455
|
+
const now = opts.now ?? Math.floor(Date.now() / 1000);
|
|
456
|
+
const nowMs = opts.now !== undefined ? opts.now * 1000 : Date.now();
|
|
457
|
+
let url: URL;
|
|
458
|
+
try {
|
|
459
|
+
url = new URL(req.url);
|
|
460
|
+
} catch {
|
|
461
|
+
return refuse(401, 'api-key-required');
|
|
462
|
+
}
|
|
463
|
+
const { pathname } = url;
|
|
464
|
+
const method = req.method.toUpperCase();
|
|
465
|
+
const read = method === 'GET' || method === 'HEAD';
|
|
466
|
+
const launch =
|
|
467
|
+
read && (pathname === '/' || pathname === '/index.html') && url.searchParams.has(LAUNCH_PARAM);
|
|
468
|
+
// C7 — the two exchanges answer a loopback Host only: a rebound name never gets a session
|
|
469
|
+
if ((launch || pathname === SESSION_PATH) && !loopbackHostHeader(req))
|
|
470
|
+
return refuse(403, 'local request required');
|
|
471
|
+
|
|
472
|
+
const cookie = sessionCookieOf(req, key, sessions, nowMs);
|
|
473
|
+
if (launch) {
|
|
474
|
+
// a page that already holds the session (a reload, a helper navigating twice) just drops the
|
|
475
|
+
// parameter — its token stays unspent and unchecked
|
|
476
|
+
if (cookie) return redirectWithoutLaunch(url);
|
|
477
|
+
return launchExchange(url, key, opts.usedNonces ?? USED_NONCES, sessions, now);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
const presented = presentedKey(req);
|
|
481
|
+
if (pathname === SESSION_PATH) {
|
|
482
|
+
if (method !== 'POST') return new Response('Method not allowed', { status: 405 });
|
|
483
|
+
if (presented === null) return refuse(401, 'api-key-required');
|
|
484
|
+
if (!keyMatches(presented, key)) return refuse(401, 'api-key-invalid');
|
|
485
|
+
return new Response(null, {
|
|
486
|
+
status: 204,
|
|
487
|
+
headers: {
|
|
488
|
+
'Set-Cookie': setCookieHeader(key, openSession(sessions, nowMs, cookie)),
|
|
489
|
+
...noStore,
|
|
490
|
+
},
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
const keyOk = presented !== null && keyMatches(presented, key);
|
|
495
|
+
if (keyOk) CREDENTIAL_OF.set(req, 'key');
|
|
496
|
+
else if (presented === null && cookie) CREDENTIAL_OF.set(req, 'session');
|
|
497
|
+
if (isExempt(method, pathname)) return null;
|
|
498
|
+
if (presented !== null && !keyOk) return refuse(401, 'api-key-invalid');
|
|
499
|
+
if (!keyOk && !cookie) return refuse(401, 'api-key-required');
|
|
500
|
+
if (isPersonOnlyRoute(method, pathname) && !personRequest(req, { required: true }))
|
|
501
|
+
return refuse(403, 'person-only');
|
|
502
|
+
return null;
|
|
503
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// The per-spawn attest key — #206 (DDR-250 decision 2; contract
|
|
2
|
+
// `client/v2/contracts/206-cli-reuses-desktop.md` §3).
|
|
3
|
+
//
|
|
4
|
+
// The desktop app mints `MAUDE_SHELL_ATTEST_KEY` for every sidecar spawn and writes the same key
|
|
5
|
+
// into its own registry (`<app_data_dir>/servers.json`). A terminal `maude design` verb (or a
|
|
6
|
+
// CLI-role server deciding whether to step down, shell/cli-yield.ts) believes a port only after
|
|
7
|
+
// the server there answers a fresh nonce with
|
|
8
|
+
//
|
|
9
|
+
// mac = HMAC-SHA256(key, "maude-attest/1\n" + nonce + "\n" + rootId + "\n" + port) (hex)
|
|
10
|
+
//
|
|
11
|
+
// The key is the registry's `attestKey` string as written (64 hex characters), used as its UTF-8
|
|
12
|
+
// bytes. `rootId` is http.ts `rootIdentity` of the server's repo root; `port` is the port the
|
|
13
|
+
// server itself BOUND (never the request's Host), so a listener relaying a challenge to a real
|
|
14
|
+
// sidecar answers for the sidecar's port and not its own.
|
|
15
|
+
//
|
|
16
|
+
// The key is read once, at first import, and deleted from `process.env`: nothing this server
|
|
17
|
+
// spawns inherits it (scrubAgentEnv drops every `MAUDE_SHELL_*` as well, acp/env.ts).
|
|
18
|
+
|
|
19
|
+
import { createHash, createHmac, timingSafeEqual } from 'node:crypto';
|
|
20
|
+
|
|
21
|
+
export const ATTEST_ENV = 'MAUDE_SHELL_ATTEST_KEY';
|
|
22
|
+
export const ATTEST_KEY_RE = /^[0-9a-fA-F]{64}$/;
|
|
23
|
+
export const ATTEST_NONCE_RE = /^[0-9a-fA-F]{32}$/;
|
|
24
|
+
export const ATTEST_DOMAIN = 'maude-attest/1';
|
|
25
|
+
|
|
26
|
+
/** Read the key from `env` and delete it there. A malformed key reads as none (fail closed). */
|
|
27
|
+
export function takeAttestKey(
|
|
28
|
+
env: Record<string, string | undefined> = process.env
|
|
29
|
+
): string | null {
|
|
30
|
+
const v = env[ATTEST_ENV];
|
|
31
|
+
delete env[ATTEST_ENV];
|
|
32
|
+
if (!v) return null;
|
|
33
|
+
if (!ATTEST_KEY_RE.test(v)) {
|
|
34
|
+
console.warn(`[maude] ${ATTEST_ENV} is not 64 hex characters; this server is not attestable.`);
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
return v;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const BOOT_KEY = takeAttestKey(process.env);
|
|
41
|
+
|
|
42
|
+
/** The key this process was spawned with (null: not an app sidecar, so never attestable). */
|
|
43
|
+
export function bootAttestKey(): string | null {
|
|
44
|
+
return BOOT_KEY;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function attestMac(key: string, nonce: string, rootId: string, port: number): string {
|
|
48
|
+
return createHmac('sha256', key)
|
|
49
|
+
.update(`${ATTEST_DOMAIN}\n${nonce}\n${rootId}\n${port}`)
|
|
50
|
+
.digest('hex');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Constant-time compare of two MACs (hashed first, so a length difference leaks nothing). */
|
|
54
|
+
export function macMatches(got: unknown, want: string): boolean {
|
|
55
|
+
if (typeof got !== 'string' || !got) return false;
|
|
56
|
+
const a = createHash('sha256').update(got).digest();
|
|
57
|
+
const b = createHash('sha256').update(want).digest();
|
|
58
|
+
return timingSafeEqual(a, b);
|
|
59
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// The server's own captures (exporters, thumbnails) — contract `client/v2/contracts/sec-loopback-bearer.md` §7.3.
|
|
2
|
+
//
|
|
3
|
+
// A key-required server mints a frame capability on its `/_canvas-shell` 307 only for a caller that
|
|
4
|
+
// sent the key or the page's session. The headless browsers the server spawns itself send neither,
|
|
5
|
+
// so the server resolves the redirect in-process instead: the URL it hands them already points at
|
|
6
|
+
// the capture origin, with the capability for the one canvas it names. Leaf module: http.ts installs
|
|
7
|
+
// the resolver; the exporters and the thumbnail service only call `localCaptureUrl`.
|
|
8
|
+
|
|
9
|
+
type Resolver = (url: string) => string;
|
|
10
|
+
let resolver: Resolver | null = null;
|
|
11
|
+
|
|
12
|
+
/** http.ts — once per server. */
|
|
13
|
+
export function setLocalCaptureResolver(fn: Resolver | null): void {
|
|
14
|
+
resolver = fn;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** A main-origin `/_canvas-shell` URL → the capture-origin URL a headless child opens. */
|
|
18
|
+
export function localCaptureUrl(url: string): string {
|
|
19
|
+
return resolver ? resolver(url) : url;
|
|
20
|
+
}
|