@uniqbit/mate-core 1.0.0-canary.3 → 1.0.0-canary.6
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/claude-capability-plugins/companion-mentions/.claude-plugin/plugin.json +1 -1
- package/claude-capability-plugins/companion-mentions/hooks/register.ts +1 -1
- package/claude-plugin/hooks/hooks.json +61 -1
- package/claude-plugin/hooks/rtk-worktree-git.mjs +58 -0
- package/claude-plugin/hooks/session-attention.mjs +10 -0
- package/claude-plugin/hooks/session-end.mjs +9 -0
- package/claude-plugin/hooks/session-guidance.mjs +1 -1
- package/claude-plugin/hooks/workflow-turn.mjs +68 -0
- package/opencode-plugin/src/companion.ts +6 -0
- package/opencode-plugin/src/server.ts +46 -4
- package/package.json +5 -2
- package/src/cli/commands/artifact/apply-context.ts +1 -0
- package/src/cli/commands/artifact/artifact.ts +16 -0
- package/src/cli/commands/artifact/delivery/archive.ts +37 -112
- package/src/cli/commands/artifact/delivery/branch-flags.ts +19 -1
- package/src/cli/commands/artifact/delivery/environment.ts +32 -72
- package/src/cli/commands/artifact/delivery/link.ts +69 -33
- package/src/cli/commands/artifact/delivery/output.ts +34 -5
- package/src/cli/commands/artifact/delivery/resolve.ts +101 -0
- package/src/cli/commands/artifact/delivery/submit.ts +164 -0
- package/src/cli/commands/artifact/delivery/take.ts +45 -0
- package/src/cli/commands/artifact/extract-repo-name.ts +1 -1
- package/src/cli/commands/artifact/finish/command.ts +455 -43
- package/src/cli/commands/artifact/finish/engine.ts +79 -61
- package/src/cli/commands/artifact/finish/finisher.ts +5 -12
- package/src/cli/commands/artifact/finish/git.ts +9 -10
- package/src/cli/commands/artifact/finish/openspec.ts +22 -177
- package/src/cli/commands/artifact/finish/secret-scan.ts +5 -43
- package/src/cli/commands/artifact/finish/worktree-cleanup.ts +57 -7
- package/src/cli/commands/artifact/pending/command.ts +119 -6
- package/src/cli/commands/artifact/pending/discovery.ts +7 -11
- package/src/cli/commands/artifact/project/command.ts +60 -0
- package/src/cli/commands/companion/companion.ts +1 -1
- package/src/cli/commands/companion/link.ts +36 -4
- package/src/cli/commands/companion/list.ts +70 -14
- package/src/cli/commands/companion/open.ts +40 -12
- package/src/cli/commands/companion/sync.ts +18 -0
- package/src/cli/commands/companion/update.ts +4 -19
- package/src/cli/commands/doctor.ts +122 -0
- package/src/cli/commands/install.ts +48 -36
- package/src/cli/commands/launch/claude.ts +2 -0
- package/src/cli/commands/launch/shared.ts +33 -6
- package/src/cli/commands/plugin/install.ts +27 -11
- package/src/cli/commands/report/index.ts +180 -184
- package/src/cli/commands/report/markdown.ts +67 -72
- package/src/cli/commands/session/prepare.ts +32 -4
- package/src/cli/commands/session/registry.ts +90 -0
- package/src/cli/commands/shared/companion-selection.ts +3 -1
- package/src/cli/commands/studio/access.ts +6 -14
- package/src/cli/commands/studio/areas.ts +112 -33
- package/src/cli/commands/studio/companion-add.ts +72 -0
- package/src/cli/commands/studio/companion-removal.ts +86 -0
- package/src/cli/commands/studio/graph-model.ts +61 -0
- package/src/cli/commands/studio/graph.ts +336 -0
- package/src/cli/commands/studio/index.ts +4 -4
- package/src/{lib/factory/outcomes/sessions.ts → cli/commands/studio/live-sessions.ts} +26 -2
- package/src/cli/commands/studio/mate-inventory.ts +1 -1
- package/src/cli/commands/studio/payload.ts +223 -30
- package/src/cli/commands/studio/reports.ts +19 -18
- package/src/cli/commands/studio/routes.ts +5 -18
- package/src/cli/commands/studio/selection.ts +12 -5
- package/src/cli/commands/studio/server.ts +321 -198
- package/src/cli/commands/studio/service-host.ts +266 -0
- package/src/cli/commands/studio/services.ts +54 -16
- package/src/cli/commands/studio/skill-files.ts +133 -0
- package/src/cli/commands/studio/studio-app.ts +1 -0
- package/src/cli/commands/studio/terminal.ts +45 -3
- package/src/cli/commands/studio/vault.ts +259 -84
- package/src/cli/commands/studio/views/model.ts +1 -14
- package/src/cli/commands/studio/views/vault/markdown-tree.ts +343 -10
- package/src/cli/commands/unwrap.ts +11 -0
- package/src/cli/commands/update.ts +28 -8
- package/src/cli/commands/vscode/release-vsix.json +4 -0
- package/src/cli/commands/vscode/setup.ts +213 -0
- package/src/cli/commands/vscode/vsix.ts +114 -0
- package/src/cli/commands/workflow/workflow.ts +516 -0
- package/src/cli/commands/working/cleanup.ts +73 -17
- package/src/cli/commands/working/worktree.ts +227 -36
- package/src/cli/commands/wrap.ts +33 -7
- package/src/cli/main.ts +48 -12
- package/src/cli/repo-list-table.tsx +73 -37
- package/src/cli/usage.ts +25 -9
- package/src/factory-host.ts +69 -0
- package/src/hooks/companion-instructions.ts +35 -16
- package/src/hooks/hook-io.ts +18 -1
- package/src/hooks/rtk-worktree-git.ts +48 -0
- package/src/hooks/session-banner.ts +30 -3
- package/src/hooks/session-end.ts +10 -0
- package/src/hooks/session-guidance.ts +10 -6
- package/src/hooks/session-prepare.ts +47 -31
- package/src/hooks/session-register.ts +199 -0
- package/src/hooks/tokensave-route.ts +7 -3
- package/src/hooks/validate-artifact-path.ts +53 -14
- package/src/hooks/workflow-turn.ts +219 -0
- package/src/lib/apply-context/fingerprint.ts +2 -1
- package/src/lib/apply-context/protocol.ts +2 -2
- package/src/lib/artifact-trailer.ts +27 -0
- package/src/lib/change-layout.ts +83 -38
- package/src/lib/delivery/branch-template.ts +114 -0
- package/src/lib/delivery/branches.ts +34 -14
- package/src/lib/delivery/checkout.ts +103 -0
- package/src/lib/delivery/environment.ts +131 -7
- package/src/lib/delivery/merge-git.ts +282 -26
- package/src/lib/delivery/overlap.ts +68 -16
- package/src/lib/delivery/record-delivery.ts +253 -57
- package/src/lib/delivery/record.ts +229 -53
- package/src/lib/delivery/refresh.ts +222 -141
- package/src/lib/delivery/remote.ts +66 -0
- package/src/lib/delivery/repository-access.ts +19 -60
- package/src/lib/delivery/resolve-branch.ts +318 -50
- package/src/lib/delivery/stages.ts +83 -50
- package/src/lib/delivery/staging/apply-chain.ts +164 -0
- package/src/lib/delivery/staging/artifact-type.ts +101 -0
- package/src/lib/delivery/staging/declared-type.ts +277 -0
- package/src/lib/delivery/staging/naming.ts +64 -0
- package/src/lib/delivery/staging/openspec-type.ts +135 -0
- package/src/lib/delivery/staging/pending-edit.ts +291 -0
- package/src/lib/delivery/staging/pending.ts +780 -0
- package/src/lib/delivery/staging/project.ts +373 -0
- package/src/lib/delivery/staging/publish.ts +1024 -0
- package/src/lib/delivery/staging/refs.ts +258 -0
- package/src/lib/delivery/staging/registry.ts +73 -0
- package/src/lib/delivery/staging/replay.ts +308 -0
- package/src/lib/delivery/staging/requirement-blocks.ts +10 -0
- package/src/lib/delivery/staging/resolve.ts +264 -0
- package/src/lib/delivery/staging/settle-linked.ts +290 -0
- package/src/lib/delivery/staging/submit.ts +929 -0
- package/src/lib/delivery/staging/worktree.ts +130 -0
- package/src/lib/delivery/submit-change.ts +443 -0
- package/src/lib/git-key.ts +15 -0
- package/src/lib/install.ts +2 -0
- package/src/lib/opencode-server.ts +238 -0
- package/src/lib/openspec-canonical-frontmatter.ts +159 -0
- package/src/lib/orchestrator/adapters/base.ts +31 -20
- package/src/lib/orchestrator/adapters/claude.ts +162 -4
- package/src/lib/orchestrator/adapters/opencode.ts +55 -2
- package/src/lib/orchestrator/checkout-adoption.ts +125 -0
- package/src/lib/orchestrator/companion-git-sync.ts +152 -16
- package/src/lib/orchestrator/companion-hub.ts +6 -1
- package/src/lib/orchestrator/companion-registry-store.ts +6 -2
- package/src/lib/orchestrator/editor.ts +2 -2
- package/src/lib/orchestrator/engine-floor.ts +48 -0
- package/src/lib/orchestrator/framework-context.ts +41 -15
- package/src/lib/orchestrator/global-config-store.ts +11 -0
- package/src/lib/orchestrator/launcher.ts +49 -3
- package/src/lib/orchestrator/projection-claude-commands.ts +2 -2
- package/src/lib/orchestrator/projection-claude-entry.ts +42 -21
- package/src/lib/orchestrator/projection-claude-links.ts +83 -11
- package/src/lib/orchestrator/projection-claude-skills.ts +30 -4
- package/src/lib/orchestrator/projection-companion-link.ts +12 -1
- package/src/lib/orchestrator/projection-entries.ts +22 -18
- package/src/lib/orchestrator/projection-opencode-copies.ts +65 -21
- package/src/lib/orchestrator/projection-runtime-documents.ts +66 -43
- package/src/lib/orchestrator/projection-types.ts +28 -1
- package/src/lib/orchestrator/refresh-working-claude-links.ts +4 -1
- package/src/lib/orchestrator/registry-checkouts.ts +177 -0
- package/src/lib/orchestrator/repository-link.ts +216 -57
- package/src/lib/orchestrator/serving-claude-wrap.ts +43 -0
- package/src/lib/orchestrator/session-context-link.ts +11 -5
- package/src/lib/orchestrator/session-prepare.ts +53 -8
- package/src/lib/orchestrator/setup-compatibilities.ts +1 -1
- package/src/lib/orchestrator/types.ts +9 -0
- package/src/lib/orchestrator/umbrella-checkouts.ts +102 -0
- package/src/lib/orchestrator/working-repo-projection.ts +24 -4
- package/src/lib/orchestrator/workspace-inventory.ts +5 -1
- package/src/lib/orchestrator/wrap-pass.ts +1 -0
- package/src/lib/prebuilt-workspace-prepare.ts +2 -1
- package/src/lib/prebuilt-workspace.ts +1 -0
- package/src/lib/public-npm.ts +105 -43
- package/src/lib/session-attribution.ts +52 -0
- package/src/lib/session-state.ts +356 -0
- package/src/lib/session-stop.ts +64 -0
- package/src/lib/update-checker.ts +7 -1
- package/src/lib/usage/aggregate.ts +202 -0
- package/src/lib/usage/cache.ts +87 -0
- package/src/lib/usage/claude-pricing.ts +71 -0
- package/src/lib/usage/claude.ts +189 -0
- package/src/lib/usage/collect.ts +56 -0
- package/src/lib/usage/opencode.ts +188 -0
- package/src/lib/usage/records.ts +80 -0
- package/src/lib/usage/rtk-database.ts +72 -0
- package/src/lib/usage/savings.ts +209 -0
- package/src/lib/usage/scope.ts +182 -0
- package/src/lib/usage/source.ts +102 -0
- package/src/lib/usage/types.ts +143 -0
- package/src/lib/usage/window.ts +37 -0
- package/src/lib/workflow/declaration.ts +6 -0
- package/src/lib/workflow/handoff.ts +90 -0
- package/src/lib/workflow/hook-trust.ts +108 -0
- package/src/lib/workflow/position.ts +524 -0
- package/src/lib/workflow/report.ts +79 -0
- package/src/lib/workflow/work.ts +106 -0
- package/src/lib/workset/factory-local.ts +157 -0
- package/src/lib/workset/record.ts +45 -11
- package/src/lib/workset/repositories.ts +118 -25
- package/src/lib/workset/stage.ts +4 -2
- package/src/lib/workset/stages.ts +64 -4
- package/src/lib/workset/worktree-include.ts +161 -0
- package/src/lib/workset/worktree-index.ts +6 -2
- package/src/lib/workset/worktree.ts +665 -89
- package/src/opencode/background-server.ts +145 -0
- package/src/opencode/companion-hooks.ts +55 -14
- package/src/opencode/companion-policy.ts +20 -7
- package/src/opencode/enter-worktree.ts +254 -6
- package/src/opencode/projected-guidance.ts +7 -3
- package/src/opencode/session-register.ts +176 -0
- package/src/opencode/turn-hook.ts +241 -0
- package/src/playbooks/companion-guidance.ts +6 -3
- package/src/plugin-api.ts +42 -0
- package/src/runtime/artifact-trailers.ts +63 -0
- package/src/runtime/claude-bg-isolation.ts +138 -0
- package/src/runtime/claude-delivery-plan.ts +14 -3
- package/src/runtime/claude-hook-group.ts +2 -0
- package/src/runtime/companion-git-state.ts +155 -10
- package/src/runtime/companion-git.ts +96 -13
- package/src/runtime/companion-guidance.ts +107 -8
- package/src/runtime/companion-instructions.ts +1 -1
- package/src/runtime/companion-sync.ts +109 -21
- package/src/runtime/current-branch.ts +24 -0
- package/src/runtime/entered-worktree.ts +24 -0
- package/src/runtime/env-names.ts +2 -2
- package/src/runtime/env.ts +16 -9
- package/src/runtime/forge-remote.ts +48 -0
- package/src/runtime/git-layout.ts +185 -24
- package/src/runtime/git-tracked.ts +60 -0
- package/src/runtime/json-fields.ts +8 -0
- package/src/runtime/launch-env-guard.ts +65 -0
- package/src/runtime/opencode-server-record.ts +136 -0
- package/src/runtime/pending-records.ts +533 -0
- package/src/runtime/projected-guidance.ts +6 -2
- package/src/runtime/projection.ts +40 -6
- package/src/runtime/publication-secret-scan.ts +45 -0
- package/src/runtime/repo-destination.ts +72 -0
- package/src/runtime/repo-local.ts +29 -2
- package/src/runtime/rtk-git-guard.ts +66 -0
- package/src/runtime/runtime-document-manifest.ts +229 -19
- package/src/runtime/runtime-document-manifest.typecheck.ts +10 -0
- package/src/runtime/secret-guard.ts +9 -2
- package/src/runtime/secret-patterns.ts +3 -2
- package/src/runtime/secret-policy-weakening.ts +122 -0
- package/src/runtime/serving-claude-wrap.ts +41 -0
- package/src/runtime/session-context.ts +4 -3
- package/src/runtime/session-registry.ts +434 -0
- package/src/runtime/skill-prefix.ts +75 -0
- package/src/runtime/submitted-arrivals.ts +547 -0
- package/src/runtime/tokensave-route.ts +10 -5
- package/src/runtime/turn-state.d.mts +14 -0
- package/src/runtime/turn-state.mjs +93 -0
- package/src/runtime/umbrella-children.ts +52 -0
- package/src/runtime/umbrella-folder.ts +84 -0
- package/src/runtime/workflow/change-folders.ts +66 -0
- package/src/runtime/workflow/declaration.ts +720 -0
- package/src/runtime/workflow/globs.ts +85 -0
- package/src/runtime/workflow/next-handoff-process.ts +98 -0
- package/src/runtime/workflow/turn.ts +309 -0
- package/src/runtime/workflow/workflow.ts +262 -0
- package/src/runtime/wrap-state.ts +36 -13
- package/src/studio.ts +73 -19
- package/src/templates/capabilities/openspec-cap/{mate-v1 → mate-full}/schema.yaml +3 -3
- package/src/templates/capabilities/openspec-cap/{mate-v1 → mate-full}/templates/design.md +1 -1
- package/src/templates/capabilities/openspec-cap/{mate-v1 → mate-full}/templates/proposal.md +1 -1
- package/src/templates/capabilities/openspec-cap/{mate-v1 → mate-full}/templates/tasks.md +1 -1
- package/src/templates/capabilities/openspec-cap/mate-minimal/schema.yaml +3 -3
- package/src/templates/mate-skills/agents/mate-apply-change/SKILL.md +147 -46
- package/src/templates/mate-skills/agents/mate-apply-change/references/openspec-apply-change.md +1 -1
- package/src/templates/mate-skills/agents/mate-archive-change/SKILL.md +7 -75
- package/src/templates/mate-skills/agents/mate-clarify-intent/SKILL.md +13 -7
- package/src/templates/mate-skills/agents/mate-domain-modeling/SKILL.md +10 -0
- package/src/templates/mate-skills/agents/mate-explore-change/SKILL.md +46 -14
- package/src/templates/mate-skills/agents/mate-propose-change/SKILL.md +51 -38
- package/src/templates/mate-skills/agents/mate-propose-change/references/mate-revise.md +14 -10
- package/src/templates/mate-skills/agents/mate-propose-change/references/openspec-update-change.md +1 -1
- package/src/templates/mate-skills/agents/mate-publish-artifact/SKILL.md +113 -87
- package/src/templates/mate-skills/agents/mate-publish-artifact/references/openspec.md +111 -100
- package/src/templates/mate-skills/agents/mate-show-me/SKILL.md +11 -5
- package/src/templates/mate-skills/agents/mate-simplify-code/SKILL.md +16 -6
- package/src/templates/mate-skills/agents/mate-submit-change/SKILL.md +114 -0
- package/src/templates/mate-skills/claude/mate-apply-change/SKILL.md +147 -46
- package/src/templates/mate-skills/claude/mate-apply-change/references/openspec-apply-change.md +1 -1
- package/src/templates/mate-skills/claude/mate-archive-change/SKILL.md +7 -75
- package/src/templates/mate-skills/claude/mate-clarify-intent/SKILL.md +13 -7
- package/src/templates/mate-skills/claude/mate-domain-modeling/SKILL.md +10 -0
- package/src/templates/mate-skills/claude/mate-explore-change/SKILL.md +46 -14
- package/src/templates/mate-skills/claude/mate-propose-change/SKILL.md +51 -38
- package/src/templates/mate-skills/claude/mate-propose-change/references/mate-revise.md +14 -10
- package/src/templates/mate-skills/claude/mate-propose-change/references/openspec-update-change.md +1 -1
- package/src/templates/mate-skills/claude/mate-publish-artifact/SKILL.md +113 -87
- package/src/templates/mate-skills/claude/mate-publish-artifact/references/openspec.md +111 -100
- package/src/templates/mate-skills/claude/mate-show-me/SKILL.md +11 -5
- package/src/templates/mate-skills/claude/mate-simplify-code/SKILL.md +16 -6
- package/src/templates/mate-skills/claude/mate-submit-change/SKILL.md +114 -0
- package/src/templates/mate-skills/openspec-references.ts +3 -2
- package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +1301 -154
- package/src/tools/setup/capabilities/openspec.ts +54 -15
- package/src/tools/setup/capabilities/rtk.ts +98 -5
- package/src/tools/setup/capabilities/tokensave.ts +3 -2
- package/src/tools/setup/dynamic-plugins/api.ts +38 -0
- package/src/tools/setup/dynamic-plugins/audiences.ts +65 -21
- package/src/tools/setup/dynamic-plugins/frozen.ts +32 -13
- package/src/tools/setup/dynamic-plugins/host.ts +2 -32
- package/src/tools/setup/dynamic-plugins/hydrate.ts +8 -7
- package/src/tools/setup/dynamic-plugins/install.ts +24 -22
- package/src/tools/setup/dynamic-plugins/loader.ts +11 -7
- package/src/tools/setup/dynamic-plugins/paths.ts +30 -10
- package/src/tools/setup/dynamic-plugins/verify.ts +10 -7
- package/src/tools/setup/dynamic-plugins/workspaces.ts +153 -0
- package/src/tools/setup/engine.ts +20 -1
- package/src/tools/setup/mate.ts +5 -3
- package/src/tools/setup/package-managers/bun.ts +8 -8
- package/src/tools/setup/plugin.ts +9 -1
- package/src/tools/setup/plugins/gitignore.ts +15 -9
- package/src/tools/setup/plugins/guidance.ts +4 -2
- package/src/tools/setup/providers/claude-plugin-hooks.ts +56 -0
- package/src/tools/setup/providers/claude.ts +64 -7
- package/src/tools/setup/service-registry.ts +69 -0
- package/src/tools/setup/service.ts +233 -0
- package/src/tools/setup/utils.ts +28 -5
- package/src/tools/setup/working-repo-cleanup.ts +2 -2
- package/src/tools/setup/working-repo-local-state.ts +2 -0
- package/src/tools/setup.ts +25 -14
- package/studio-dist/client/assets/app-BFVyWHGo.css +2 -0
- package/studio-dist/client/assets/button-D6LrRkOG.js +1 -0
- package/studio-dist/client/assets/combobox-Dk2MMZWE.js +1 -0
- package/studio-dist/client/assets/companion-view-BVaZNtiI.js +1 -0
- package/studio-dist/client/assets/fields-D_FYhxQr.js +1 -0
- package/studio-dist/client/assets/getting-started-ByWRg7hC.js +1 -0
- package/studio-dist/client/assets/getting-started-DZSjYC-b.js +1 -0
- package/studio-dist/client/assets/getting-started._topic-C6OyQ4G6.js +1 -0
- package/studio-dist/client/assets/getting-started.index-BkmPHdEm.js +1 -0
- package/studio-dist/client/assets/graph-7jm2XzyL.js +2 -0
- package/studio-dist/client/assets/graph-canvas-DDuzsNSx.js +3242 -0
- package/studio-dist/client/assets/guides-D9VTjWXP.js +1 -0
- package/studio-dist/client/assets/index-BBmFpG4y.js +40 -0
- package/studio-dist/client/assets/jsx-runtime-MZURdZre.js +1 -0
- package/studio-dist/client/assets/markdown-view-RL5YvfZg.js +1 -0
- package/studio-dist/client/assets/panel-B8F8sOKQ.js +1 -0
- package/studio-dist/client/assets/plugins._service._view-CynxTbMx.js +1 -0
- package/studio-dist/client/assets/queries-axYk2u9L.js +1 -0
- package/studio-dist/client/assets/react-r45OnJCw.js +27 -0
- package/studio-dist/client/assets/reports-BCAyXh6p.js +1 -0
- package/studio-dist/client/assets/routes-BFPqq89E.js +1 -0
- package/studio-dist/client/assets/skills-DTks_uBx.js +1 -0
- package/studio-dist/client/assets/specs-DU1kqcp5.js +1 -0
- package/studio-dist/client/assets/specs-view-omrd_5P3.js +1 -0
- package/studio-dist/client/assets/steps-DhIFuAZy.js +1 -0
- package/studio-dist/client/assets/store-DJ5cncKA.js +1 -0
- package/studio-dist/client/assets/studio-BR9j15J0.js +100 -0
- package/studio-dist/client/assets/studio-queries-CFP_yTpr.js +2 -0
- package/studio-dist/client/assets/usage-CHmwtkoM.js +55 -0
- package/studio-dist/client/assets/useBaseQuery-BlC-AZ35.js +1 -0
- package/studio-dist/client/assets/useSelector-AYcH7lB0.js +2 -0
- package/studio-dist/client/assets/vault-DRg8MScm.js +1 -0
- package/studio-dist/client/assets/warnings-UHFy6HAp.js +1 -0
- package/studio-dist/client/assets/workflow-Bv9vSfVV.js +1 -0
- package/studio-dist/server/assets/__23tanstack-start-server-fn-resolver-DAbZ6fzY.js +106 -0
- package/studio-dist/server/assets/_tanstack-start-manifest_v.js +86 -31
- package/studio-dist/server/assets/button-BfoNadNR.js +8193 -0
- package/studio-dist/server/assets/combobox-oxUI6r4V.js +2089 -0
- package/studio-dist/server/assets/{companion-view-aBady57v.js → companion-view-DHUjPpA0.js} +13 -7
- package/studio-dist/server/assets/companions-kBrJZAd6.js +31 -0
- package/studio-dist/server/assets/{createServerRpc-tK2lE9R2.js → createServerRpc-bFKFpGFG.js} +1 -1
- package/studio-dist/server/assets/fields-BD_c65T1.js +1190 -0
- package/studio-dist/server/assets/getting-started-7P0oyWaM.js +67 -0
- package/studio-dist/server/assets/getting-started-B136TP57.js +4 -0
- package/studio-dist/server/assets/getting-started._topic-B1mV0kGz.js +13 -0
- package/studio-dist/server/assets/getting-started.index-CeGtvUsm.js +13 -0
- package/studio-dist/server/assets/graph-BWtmJOH2.js +16 -0
- package/studio-dist/server/assets/graph-DSDVEELZ.js +801 -0
- package/studio-dist/server/assets/graph-canvas-CID9Nksc.js +21066 -0
- package/studio-dist/server/assets/graph-wire-BdSUx0G5.js +58 -0
- package/studio-dist/server/assets/guides-BLJenHwQ.js +5 -0
- package/studio-dist/server/assets/guides-Bm3RbUB-.js +13 -0
- package/studio-dist/server/assets/guides.server-rHHqRuzV.js +66 -0
- package/studio-dist/server/assets/jsx-runtime-Bt0s0YKS.js +451 -0
- package/studio-dist/server/assets/markdown-view-D3v9x-cM.js +105 -0
- package/studio-dist/server/assets/panel-yqOl5GMU.js +169 -0
- package/studio-dist/server/assets/plugins._service._view-DwqJX7s9.js +92 -0
- package/studio-dist/server/assets/queries-DYmGrhNO.js +32 -0
- package/studio-dist/server/assets/react-BO0uMhpm.js +89 -0
- package/studio-dist/server/assets/redirect-BaZ_QyqF.js +39 -0
- package/studio-dist/server/assets/reports-7yaPz7aP.js +147 -0
- package/studio-dist/server/assets/reports-C4Y_Jd-x.js +18 -0
- package/studio-dist/server/assets/router-Dnoq5auE.js +12844 -0
- package/studio-dist/server/assets/routes-Cok4p3mK.js +768 -0
- package/studio-dist/server/assets/{search-JAKurDNh.js → search-DUK7Jl6f.js} +21 -2
- package/studio-dist/server/assets/{shell-CboT2f66.js → shell-DNVXedgE.js} +16 -6
- package/studio-dist/server/assets/skills-D8qdXSku.js +267 -0
- package/studio-dist/server/assets/skills-pKmuAs0F.js +28 -0
- package/studio-dist/server/assets/specs-DeHYUNFp.js +51 -0
- package/studio-dist/server/assets/specs-view-BGn-5Ik_.js +425 -0
- package/studio-dist/server/assets/{start-BW5ovN0k.js → start-h3ICWwd2.js} +4 -1
- package/studio-dist/server/assets/steps-CV7Yk7L7.js +224 -0
- package/studio-dist/server/assets/store-CWDGIp6x.js +280 -0
- package/studio-dist/server/assets/studio-CB94np48.js +10437 -0
- package/studio-dist/server/assets/studio-queries-BqZGBE70.js +1335 -0
- package/studio-dist/server/assets/usage-M6Gi6Km7.js +25584 -0
- package/studio-dist/server/assets/usage-j5jR9gX9.js +24 -0
- package/studio-dist/server/assets/{studio-queries-CLnP9kGu.js → useBaseQuery-Tv_QJt9r.js} +4 -1318
- package/studio-dist/server/assets/{__23tanstack-start-server-fn-resolver-BQKuMdJW.js → useSelector-DUmCUXAs.js} +4 -498
- package/studio-dist/server/assets/vault-PqVmssmW.js +1035 -0
- package/studio-dist/server/assets/{vault-BGulVoNh.js → vault-lBlvSyD4.js} +19 -4
- package/studio-dist/server/assets/{views-Bd7cRr27.js → views-CsFp1i1G.js} +10 -9
- package/studio-dist/server/assets/warnings-BDs34j_m.js +24 -0
- package/studio-dist/server/assets/workflow-T0eEldsa.js +687 -0
- package/studio-dist/server/server.js +429 -9
- package/src/cli/commands/factory/factory.ts +0 -301
- package/src/cli/commands/report/collector.ts +0 -288
- package/src/cli/commands/studio/factory-credential.ts +0 -49
- package/src/cli/commands/studio/workset-session.ts +0 -131
- package/src/lib/delivery/archive-change.ts +0 -166
- package/src/lib/delivery/forge.ts +0 -279
- package/src/lib/delivery/token.ts +0 -24
- package/src/lib/factory/attach-client.ts +0 -113
- package/src/lib/factory/attach.ts +0 -178
- package/src/lib/factory/broker.ts +0 -190
- package/src/lib/factory/bun-commands.ts +0 -39
- package/src/lib/factory/client.ts +0 -92
- package/src/lib/factory/command.ts +0 -61
- package/src/lib/factory/credential-store.ts +0 -153
- package/src/lib/factory/frames.ts +0 -77
- package/src/lib/factory/ids.ts +0 -58
- package/src/lib/factory/outcomes/actions.ts +0 -114
- package/src/lib/factory/outcomes/index.ts +0 -381
- package/src/lib/factory/outcomes/lifecycle.ts +0 -205
- package/src/lib/factory/outcomes/runs.ts +0 -81
- package/src/lib/factory/prepare.ts +0 -49
- package/src/lib/factory/pty.ts +0 -103
- package/src/lib/factory/runner/companion-context.ts +0 -178
- package/src/lib/factory/runner/control.ts +0 -92
- package/src/lib/factory/runner/harness-agent.ts +0 -250
- package/src/lib/factory/runner/live.ts +0 -159
- package/src/lib/factory/runner/questions.ts +0 -22
- package/src/lib/factory/runner/rank.ts +0 -26
- package/src/lib/factory/runner/run-policy.ts +0 -12
- package/src/lib/factory/runner/run.ts +0 -199
- package/src/lib/factory/runner/scheduler.ts +0 -416
- package/src/lib/factory/runner/state.ts +0 -233
- package/src/lib/factory/runner/workflow.ts +0 -542
- package/src/lib/factory/runtime.ts +0 -972
- package/src/lib/factory/sandbox.ts +0 -292
- package/src/lib/factory/worktree-branch.ts +0 -17
- package/src/templates/capabilities/openspec-cap/mate-v1/templates/explore-brief.md +0 -25
- package/studio-dist/client/assets/companion-view-Csva26Ir.js +0 -1
- package/studio-dist/client/assets/delivery-path-DJMpRmiY.js +0 -1
- package/studio-dist/client/assets/factory-B7l9ZQyx.js +0 -4
- package/studio-dist/client/assets/index-n6uo_92S.js +0 -40
- package/studio-dist/client/assets/prepaint-CD5OpmTM.js +0 -24
- package/studio-dist/client/assets/queries-CN3JwMBX.js +0 -1
- package/studio-dist/client/assets/react-CabXf2Ds.js +0 -1
- package/studio-dist/client/assets/report-time-Dc-KOqQu.js +0 -1
- package/studio-dist/client/assets/reports-C01RsnMA.js +0 -1
- package/studio-dist/client/assets/rolldown-runtime-WkwZ5CU-.js +0 -1
- package/studio-dist/client/assets/routes-4pbC-2Hj.js +0 -1
- package/studio-dist/client/assets/skills-CihQganl.js +0 -1
- package/studio-dist/client/assets/spec-areas-C2L48N4C.js +0 -1
- package/studio-dist/client/assets/specs-D24_35_K.js +0 -1
- package/studio-dist/client/assets/studio-DKxfi691.css +0 -1
- package/studio-dist/client/assets/studio-queries-rvbJupCy.js +0 -3
- package/studio-dist/client/assets/vault-Bd4CQiTK.js +0 -1
- package/studio-dist/client/assets/warnings-V_Ys51wJ.js +0 -1
- package/studio-dist/client/assets/workflow-BJejeVwQ.js +0 -1
- package/studio-dist/server/assets/actions-Bvgj9eb8.js +0 -54
- package/studio-dist/server/assets/createServerFn-F5sAOF8V.js +0 -459
- package/studio-dist/server/assets/delivery-path-BkKNjgkf.js +0 -778
- package/studio-dist/server/assets/factory-D6xnjedJ.js +0 -2385
- package/studio-dist/server/assets/factory-DT3UzHlh.js +0 -68
- package/studio-dist/server/assets/prepaint-BMke0fo1.js +0 -41
- package/studio-dist/server/assets/queries-Ag2iL8q2.js +0 -107
- package/studio-dist/server/assets/react-COs0LHn-.js +0 -51
- package/studio-dist/server/assets/report-time-DAfzln-N.js +0 -8
- package/studio-dist/server/assets/reports-BnUNJVtx.js +0 -126
- package/studio-dist/server/assets/rolldown-runtime-DYf_mQCB.js +0 -34
- package/studio-dist/server/assets/router-BH--drIx.js +0 -4298
- package/studio-dist/server/assets/routes-khSDK1bV.js +0 -361
- package/studio-dist/server/assets/skills-MWYnWoKs.js +0 -106
- package/studio-dist/server/assets/spec-areas-DcnO6vW-.js +0 -16
- package/studio-dist/server/assets/specs-DE3w8hZP.js +0 -155
- package/studio-dist/server/assets/studio-BeltxxKt.js +0 -216
- package/studio-dist/server/assets/vault-CuyyhLyB.js +0 -832
- package/studio-dist/server/assets/warnings-BH05rOuG.js +0 -15
- package/studio-dist/server/assets/workflow-BSuIKWqH.js +0 -42
- /package/src/lib/{factory/keyed-serial.ts → keyed-serial.ts} +0 -0
- /package/src/templates/capabilities/openspec-cap/{mate-v1 → mate-full}/templates/spec.md +0 -0
|
@@ -7,33 +7,35 @@ import {
|
|
|
7
7
|
type StudioAccess,
|
|
8
8
|
type StudioInvocation,
|
|
9
9
|
} from "./access";
|
|
10
|
+
import { realpath } from "node:fs/promises";
|
|
11
|
+
import path from "node:path";
|
|
12
|
+
|
|
10
13
|
import { MERMAID_RUNTIME_URL } from "../report/renderer";
|
|
11
|
-
import { collectStudioInventory, type StudioInventory } from "./inventory";
|
|
12
14
|
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
} from "./
|
|
15
|
+
CompanionRemovalError,
|
|
16
|
+
deletableWithin,
|
|
17
|
+
deleteRegisteredCompanion,
|
|
18
|
+
} from "./companion-removal";
|
|
19
|
+
import { collectStudioInventory, type StudioInventory } from "./inventory";
|
|
20
|
+
import { assembleCompanionPayload, type StudioCompanionResponse } from "./payload";
|
|
17
21
|
import { createReportStore, isReportId, REPORT_LIMITS, type ReportStore } from "./reports";
|
|
18
|
-
import {
|
|
19
|
-
import type {
|
|
20
|
-
import
|
|
22
|
+
import { WorksetError } from "../../../lib/workset/record";
|
|
23
|
+
import type { PluginService, StudioSocketHandler } from "../../../tools/setup/service";
|
|
24
|
+
import { registeredServices } from "../../../tools/setup/service-registry";
|
|
25
|
+
import { addCompanionByPath, addCompanionByUrl } from "./companion-add";
|
|
26
|
+
import { LiveSessions } from "./live-sessions";
|
|
21
27
|
import {
|
|
22
|
-
|
|
23
|
-
type
|
|
24
|
-
|
|
25
|
-
type
|
|
26
|
-
|
|
27
|
-
} from "
|
|
28
|
-
import { LiveSessions } from "../../../lib/factory/outcomes/sessions";
|
|
29
|
-
import { FACTORY_BROKER_ENV, factoryClient, type FactoryClient } from "../../../lib/factory/client";
|
|
30
|
-
import { factoryCredentialResponse } from "./factory-credential";
|
|
31
|
-
import { createWorksetResolver } from "./workset-session";
|
|
28
|
+
guardedSocket,
|
|
29
|
+
type MatchedServiceRoute,
|
|
30
|
+
mountStudioServices,
|
|
31
|
+
type MountedServices,
|
|
32
|
+
NO_SERVICES,
|
|
33
|
+
} from "./service-host";
|
|
32
34
|
import {
|
|
33
|
-
FACTORY_CREDENTIAL_ROUTE,
|
|
34
|
-
FACTORY_WORKSETS_ROUTE,
|
|
35
35
|
REPORTS_ROUTE,
|
|
36
36
|
REPORT_VIEW_PREFIX,
|
|
37
|
+
SERVICE_ASSET_PREFIX,
|
|
38
|
+
SERVICE_ROUTE_PREFIX,
|
|
37
39
|
STUDIO_EVENTS_ROUTE,
|
|
38
40
|
STUDIO_HOSTNAME,
|
|
39
41
|
type StudioEvent,
|
|
@@ -50,12 +52,13 @@ import {
|
|
|
50
52
|
modePolicy,
|
|
51
53
|
parse,
|
|
52
54
|
parseVaultSelection,
|
|
55
|
+
REFRESH_PARAM,
|
|
53
56
|
resolveCompanion,
|
|
54
57
|
type StudioModePolicy,
|
|
55
58
|
type StudioProfile,
|
|
56
|
-
type StudioSelection,
|
|
57
59
|
} from "./selection";
|
|
58
60
|
import { errorMessage } from "../../../runtime/error-message";
|
|
61
|
+
import type { SpecGraphCache } from "./graph";
|
|
59
62
|
import { createStudioSnapshotCache, type StudioSnapshotCache } from "./snapshot";
|
|
60
63
|
import type { StudioPage } from "./views/model";
|
|
61
64
|
import { createVaultManager, resolveVaultPath, VaultPathError, type VaultManager } from "./vault";
|
|
@@ -65,7 +68,8 @@ import {
|
|
|
65
68
|
type TerminalConnection,
|
|
66
69
|
type TerminalRegistryOptions,
|
|
67
70
|
} from "./terminal";
|
|
68
|
-
import type {
|
|
71
|
+
import type { StudioServices } from "./services";
|
|
72
|
+
import type { UsageCache } from "../../../lib/usage/cache";
|
|
69
73
|
import { studioAppAsset, type StudioApp } from "./studio-app";
|
|
70
74
|
import { terminalAsset } from "./terminal-assets";
|
|
71
75
|
import {
|
|
@@ -81,7 +85,8 @@ const STUDIO_APP_CALL_PREFIX = "/_serverFn/";
|
|
|
81
85
|
|
|
82
86
|
/** The socket Bun hands a WebSocket handler; `data` is what the upgrade attached. */
|
|
83
87
|
export interface StudioSocket {
|
|
84
|
-
|
|
88
|
+
/** A terminal connection, or a service's socket. */
|
|
89
|
+
data: { connection?: TerminalConnection; service?: StudioSocketHandler };
|
|
85
90
|
send(data: string | Uint8Array): number;
|
|
86
91
|
getBufferedAmount(): number;
|
|
87
92
|
ping(): void;
|
|
@@ -135,17 +140,13 @@ export interface StudioServerDeps {
|
|
|
135
140
|
snapshots?: StudioSnapshotCache;
|
|
136
141
|
vault?: VaultManager;
|
|
137
142
|
reports?: ReportStore;
|
|
143
|
+
usage?: UsageCache;
|
|
138
144
|
terminal?: Partial<TerminalRegistryOptions>;
|
|
139
145
|
launchableAgents?: typeof launchableAgents;
|
|
140
|
-
/**
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
factoryOutcomes?: (portsFor: (companionPath: string) => OutcomesPorts) => FactoryOutcomes | null;
|
|
145
|
-
/** A companion's Workset stages; read from OpenSpec when absent. */
|
|
146
|
-
worksetStages?: (companionPath: string) => Promise<{ worksets: WorksetWithStage[] }>;
|
|
147
|
-
/** The factory broker's client; from the environment when absent, null outside factory mode. */
|
|
148
|
-
factoryClient?: FactoryClient | null;
|
|
146
|
+
/** The plugin services Studio mounts; the registered plugins' when absent. */
|
|
147
|
+
services?: readonly PluginService[];
|
|
148
|
+
/** The environment services read their connection from; `process.env` when absent. */
|
|
149
|
+
env?: NodeJS.ProcessEnv;
|
|
149
150
|
}
|
|
150
151
|
|
|
151
152
|
export interface StudioServerOptions {
|
|
@@ -156,7 +157,7 @@ export interface StudioServerOptions {
|
|
|
156
157
|
terminal?: boolean;
|
|
157
158
|
allowedHosts?: string[];
|
|
158
159
|
publicOrigin?: string | null;
|
|
159
|
-
/** Operator-pinned token; generated per start when absent
|
|
160
|
+
/** Operator-pinned token; generated per start when absent. */
|
|
160
161
|
token?: string | null;
|
|
161
162
|
detachMinutes?: number;
|
|
162
163
|
/** Pins every terminal launch to this registered companion. */
|
|
@@ -195,9 +196,6 @@ const TOKEN_REQUIRED_PAGE = `<!doctype html>
|
|
|
195
196
|
If the token was pinned with <code>--token</code> or <code>MATE_STUDIO_TOKEN</code>,
|
|
196
197
|
open this address with <code>?token=</code> followed by that value.</p></main></body></html>`;
|
|
197
198
|
|
|
198
|
-
/** A Workset's run log, or its live stream when the second group matched. */
|
|
199
|
-
const FACTORY_LOG = new RegExp(`^${FACTORY_WORKSETS_ROUTE}/([^/]+)/log(/stream)?$`);
|
|
200
|
-
|
|
201
199
|
/**
|
|
202
200
|
* What a route is, for its guard. A read needs the token where the invocation requires it
|
|
203
201
|
* for reading; a write also needs the same origin, the token for saving and, when it names
|
|
@@ -217,20 +215,32 @@ const ORIGIN_REASON = {
|
|
|
217
215
|
|
|
218
216
|
const READS = ["GET", "HEAD"] as const;
|
|
219
217
|
|
|
218
|
+
/** A service route by the access its method declares; a WebSocket is guarded like a write. */
|
|
219
|
+
function serviceRouteKind(matched: MatchedServiceRoute, method: string): RouteKind {
|
|
220
|
+
const access = matched.access;
|
|
221
|
+
if (!access) return { kind: "read", methods: matched.methods };
|
|
222
|
+
if (access.kind === "read") return { kind: "read", methods: [method] };
|
|
223
|
+
if (access.kind === "socket") return { kind: "write", methods: [method] };
|
|
224
|
+
return {
|
|
225
|
+
kind: "write",
|
|
226
|
+
methods: [method],
|
|
227
|
+
...(access.writable ? { writable: access.writable } : {}),
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
|
|
220
231
|
/** Every route core answers, by kind; the rest are reads the application answers. */
|
|
221
|
-
function routeOf(
|
|
232
|
+
function routeOf(
|
|
233
|
+
url: URL,
|
|
234
|
+
method: string,
|
|
235
|
+
hasApp: boolean,
|
|
236
|
+
service: MatchedServiceRoute | null,
|
|
237
|
+
): RouteKind {
|
|
222
238
|
const { pathname } = url;
|
|
223
239
|
if (pathname === REPORTS_ROUTE && method === "POST")
|
|
224
240
|
return { kind: "session", methods: ["POST"] };
|
|
225
|
-
if (
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
: {
|
|
229
|
-
kind: "write",
|
|
230
|
-
methods: [method],
|
|
231
|
-
writable: "start Studio with --writable to set the agent credential",
|
|
232
|
-
};
|
|
233
|
-
}
|
|
241
|
+
if (service) return serviceRouteKind(service, method);
|
|
242
|
+
// A service that is not mounted answers nothing, whatever the method.
|
|
243
|
+
if (pathname.startsWith(SERVICE_ROUTE_PREFIX)) return { kind: "read", methods: [method] };
|
|
234
244
|
if (pathname === TERMINAL_SOCKET_ROUTE) {
|
|
235
245
|
return { kind: "terminal", methods: READS, privileged: true };
|
|
236
246
|
}
|
|
@@ -292,6 +302,7 @@ async function readCapped(request: Request, limit: number): Promise<string | nul
|
|
|
292
302
|
let size = 0;
|
|
293
303
|
let over = Number.isFinite(declared) && declared > limit;
|
|
294
304
|
for (;;) {
|
|
305
|
+
// oxlint-disable-next-line no-await-in-loop -- stream chunks arrive in order
|
|
295
306
|
const { done, value } = await reader.read();
|
|
296
307
|
if (done) break;
|
|
297
308
|
size += value.byteLength;
|
|
@@ -299,6 +310,7 @@ async function readCapped(request: Request, limit: number): Promise<string | nul
|
|
|
299
310
|
if (over) {
|
|
300
311
|
chunks.length = 0;
|
|
301
312
|
if (size > limit * 4) {
|
|
313
|
+
// oxlint-disable-next-line no-await-in-loop -- same stream
|
|
302
314
|
await reader.cancel();
|
|
303
315
|
break;
|
|
304
316
|
}
|
|
@@ -309,8 +321,6 @@ async function readCapped(request: Request, limit: number): Promise<string | nul
|
|
|
309
321
|
return over ? null : Buffer.concat(chunks).toString("utf8");
|
|
310
322
|
}
|
|
311
323
|
|
|
312
|
-
const NOT_WRITABLE = "start Studio with --writable to create or start Worksets";
|
|
313
|
-
|
|
314
324
|
const TOKEN_REASON =
|
|
315
325
|
"Studio's access token is required; open the address Studio printed when it started";
|
|
316
326
|
|
|
@@ -331,6 +341,8 @@ interface StudioFetch {
|
|
|
331
341
|
(request: Request, server?: StudioUpgrader): Promise<Response | undefined>;
|
|
332
342
|
terminal: TerminalRegistry | null;
|
|
333
343
|
services: StudioServices;
|
|
344
|
+
/** Settles once every plugin service is mounted. */
|
|
345
|
+
ready: Promise<MountedServices>;
|
|
334
346
|
close(): Promise<void>;
|
|
335
347
|
}
|
|
336
348
|
|
|
@@ -367,39 +379,17 @@ export function createStudioFetch(
|
|
|
367
379
|
const snapshots =
|
|
368
380
|
deps.snapshots ?? createStudioSnapshotCache({ assembleCompanionPayload: companion });
|
|
369
381
|
const vault = deps.vault ?? createVaultManager();
|
|
382
|
+
/** Created on the first Graph request, so other views never load the graph index. */
|
|
383
|
+
let graphs: Promise<SpecGraphCache> | null = null;
|
|
370
384
|
const writable = options.writable === true;
|
|
371
385
|
const policy = modePolicy(options.profile ?? "standard");
|
|
372
|
-
const broker = deps.factoryClient !== undefined ? deps.factoryClient : factoryClient();
|
|
373
386
|
const reports = deps.reports ?? createReportStore();
|
|
374
|
-
const
|
|
375
|
-
// Created before the terminal and the
|
|
387
|
+
const env = deps.env ?? process.env;
|
|
388
|
+
// Created before the terminal and the services, so neither needs the other.
|
|
376
389
|
const sessions = new LiveSessions();
|
|
377
390
|
const launchCompanion = options.launchCompanion ?? null;
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
reports: {
|
|
381
|
-
publish: (report) => reports.publish(companionDigest(companionPath), report),
|
|
382
|
-
ids: async () =>
|
|
383
|
-
(await reports.list(companionDigest(companionPath))).map((report) => report.id),
|
|
384
|
-
},
|
|
385
|
-
sessions,
|
|
386
|
-
});
|
|
387
|
-
const outcomes = (() => {
|
|
388
|
-
try {
|
|
389
|
-
if (deps.factoryOutcomes) return deps.factoryOutcomes(outcomesPorts);
|
|
390
|
-
return createFactoryOutcomes(launchCompanion, outcomesPorts(launchCompanion ?? ""));
|
|
391
|
-
} catch (error) {
|
|
392
|
-
process.stderr.write(
|
|
393
|
-
`mate studio: the factory runner did not start: ${(error as Error).message}\n`,
|
|
394
|
-
);
|
|
395
|
-
return null;
|
|
396
|
-
}
|
|
397
|
-
})();
|
|
398
|
-
/** A companion's Outcomes: the factory's for the companion it runs, record-only otherwise. */
|
|
399
|
-
const outcomesFor = (companionPath: string): Outcomes =>
|
|
400
|
-
outcomes?.companionPath === companionPath
|
|
401
|
-
? outcomes
|
|
402
|
-
: recordOutcomes(companionPath, () => stagesOf(companionPath));
|
|
391
|
+
/** The mounted services; none until they are, and every request waits for them. */
|
|
392
|
+
let services: MountedServices = NO_SERVICES;
|
|
403
393
|
const access =
|
|
404
394
|
options.access ??
|
|
405
395
|
createStudioAccess({
|
|
@@ -412,7 +402,7 @@ export function createStudioFetch(
|
|
|
412
402
|
const publicOrigin = options.publicOrigin ? normalizeOrigin(options.publicOrigin) : null;
|
|
413
403
|
const reportListeners = new Map<string, Set<(event: PublishedReport) => void>>();
|
|
414
404
|
const agentsFor = deps.launchableAgents ?? launchableAgents;
|
|
415
|
-
const terminal = options.terminal
|
|
405
|
+
const terminal: TerminalRegistry | null = options.terminal
|
|
416
406
|
? new TerminalRegistry({
|
|
417
407
|
detachMs: (options.detachMinutes ?? DEFAULT_DETACH_MINUTES[access.invocation]) * 60_000,
|
|
418
408
|
resolveLaunch: createLaunchResolver({
|
|
@@ -422,19 +412,12 @@ export function createStudioFetch(
|
|
|
422
412
|
}),
|
|
423
413
|
mateCommand: process.argv.slice(0, 2),
|
|
424
414
|
sessions,
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
env: process.env,
|
|
432
|
-
noGit: options.noGit === true,
|
|
433
|
-
// A person in control continues the factory's own conversation.
|
|
434
|
-
takenOver: async (id) => (outcomes ? outcomes.takenOver(id) : null),
|
|
435
|
-
}),
|
|
436
|
-
}
|
|
437
|
-
: {}),
|
|
415
|
+
resolveWorkset: async (id, digest, sessionId) =>
|
|
416
|
+
(await ready).worksetSessions?.resolve(id, digest, sessionId) ?? {
|
|
417
|
+
reason: "no service of this Studio starts Workset sessions",
|
|
418
|
+
},
|
|
419
|
+
onWorksetExit: async (id, companionPath) =>
|
|
420
|
+
(await ready).worksetSessions?.onExit?.(id, companionPath),
|
|
438
421
|
noGit: options.noGit === true,
|
|
439
422
|
reportUrl: options.reportOrigin,
|
|
440
423
|
...deps.terminal,
|
|
@@ -470,38 +453,24 @@ export function createStudioFetch(
|
|
|
470
453
|
for (const notify of reportListeners.get(digest) ?? []) {
|
|
471
454
|
notify({ id: stored.id, title: stored.title });
|
|
472
455
|
}
|
|
473
|
-
const
|
|
456
|
+
const viewPath = `${REPORT_VIEW_PREFIX}${stored.id}`;
|
|
474
457
|
return json({
|
|
475
458
|
id: stored.id,
|
|
476
|
-
path,
|
|
477
|
-
...(publicOrigin ? { url: `${publicOrigin}${
|
|
459
|
+
path: viewPath,
|
|
460
|
+
...(publicOrigin ? { url: `${publicOrigin}${viewPath}` } : {}),
|
|
478
461
|
});
|
|
479
462
|
};
|
|
480
463
|
|
|
481
|
-
/** One document's model, with the
|
|
464
|
+
/** One document's model, with the terminal state its address needs. */
|
|
482
465
|
const collectPage = async (url: URL): Promise<StudioPage> => {
|
|
483
|
-
const page = await collectStudioPage(url, policy, inventory, snapshots,
|
|
484
|
-
if (page.payload && page.companion && isAnalystOverview(page.selection)) {
|
|
485
|
-
page.reports = await reports.list(companionDigest(page.companion.path)).then(
|
|
486
|
-
(listed) => listed.map(({ id, title, createdAt }) => ({ id, title, createdAt })),
|
|
487
|
-
() => null,
|
|
488
|
-
);
|
|
489
|
-
}
|
|
466
|
+
const page = await collectStudioPage(url, policy, inventory, snapshots, writable);
|
|
490
467
|
page.renderedAt = Date.now();
|
|
491
|
-
page.factoryRuns = page.companion ? await outcomesFor(page.companion.path).runs() : null;
|
|
492
468
|
if (terminal) {
|
|
493
469
|
const target = await effectiveLaunchCompanion(
|
|
494
470
|
page.inventory,
|
|
495
471
|
launchCompanion,
|
|
496
472
|
page.selection.companionDigest,
|
|
497
473
|
);
|
|
498
|
-
page.worksetSessions = process.env[FACTORY_BROKER_ENV]
|
|
499
|
-
? Object.fromEntries(
|
|
500
|
-
terminal
|
|
501
|
-
.list()
|
|
502
|
-
.flatMap((session) => (session.workset ? [[session.workset.id, session.id]] : [])),
|
|
503
|
-
)
|
|
504
|
-
: null;
|
|
505
474
|
page.terminal = {
|
|
506
475
|
pinned: launchCompanion !== null,
|
|
507
476
|
target: target ? { path: target.path, digest: companionDigest(target.path) } : null,
|
|
@@ -523,26 +492,84 @@ export function createStudioFetch(
|
|
|
523
492
|
const boardChanged = (digest: string) => {
|
|
524
493
|
for (const notify of boardListeners.get(digest) ?? []) notify();
|
|
525
494
|
};
|
|
526
|
-
if (outcomes) {
|
|
527
|
-
const digest = companionDigest(outcomes.companionPath);
|
|
528
|
-
outcomes.onChanged(() => boardChanged(digest));
|
|
529
|
-
}
|
|
530
495
|
|
|
531
|
-
const
|
|
496
|
+
const ready: Promise<MountedServices> = mountStudioServices(
|
|
497
|
+
deps.services ?? registeredServices(),
|
|
498
|
+
{
|
|
499
|
+
writable,
|
|
500
|
+
noGit: options.noGit === true,
|
|
501
|
+
launchCompanion,
|
|
502
|
+
mateCommand: process.argv.slice(0, 2),
|
|
503
|
+
env,
|
|
504
|
+
companionPath: companionPathOf,
|
|
505
|
+
companionSnapshot: async (digest, { refresh = false } = {}) => {
|
|
506
|
+
await companionPathOf(digest);
|
|
507
|
+
const url = new URL("http://studio.local/");
|
|
508
|
+
url.searchParams.set(COMPANION_PARAM, digest);
|
|
509
|
+
if (refresh) url.searchParams.set(REFRESH_PARAM, "1");
|
|
510
|
+
const page = await collectPage(url);
|
|
511
|
+
return {
|
|
512
|
+
payload: page.payload,
|
|
513
|
+
error: page.error?.reason ?? null,
|
|
514
|
+
collectedAt: page.collectedAt,
|
|
515
|
+
};
|
|
516
|
+
},
|
|
517
|
+
companionDigest,
|
|
518
|
+
launchTarget: async (digest) =>
|
|
519
|
+
(await effectiveLaunchCompanion(await inventory(), launchCompanion, digest))?.path ?? null,
|
|
520
|
+
boardChanged: (companionPath) => boardChanged(companionDigest(companionPath)),
|
|
521
|
+
reports: {
|
|
522
|
+
publish: (companionPath, report) => reports.publish(companionDigest(companionPath), report),
|
|
523
|
+
ids: async (companionPath) =>
|
|
524
|
+
(await reports.list(companionDigest(companionPath))).map((report) => report.id),
|
|
525
|
+
},
|
|
526
|
+
terminal: {
|
|
527
|
+
enabled: terminal !== null,
|
|
528
|
+
sessions: () =>
|
|
529
|
+
(terminal?.list() ?? []).map((session) => ({
|
|
530
|
+
id: session.id,
|
|
531
|
+
companionPath: session.companionPath,
|
|
532
|
+
...(session.workset ? { workset: session.workset } : {}),
|
|
533
|
+
})),
|
|
534
|
+
busy: () => sessions.busy(),
|
|
535
|
+
onEnded: (listener) => sessions.onEnded(listener),
|
|
536
|
+
close: (companionPath, worksetId, reason) =>
|
|
537
|
+
sessions.close(companionPath, worksetId, reason),
|
|
538
|
+
},
|
|
539
|
+
},
|
|
540
|
+
).then((mounted) => {
|
|
541
|
+
services = mounted;
|
|
542
|
+
return mounted;
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
/** A service route called from inside Studio: the route's `writable` refusal applies. */
|
|
546
|
+
const callService = async (request: Request): Promise<Response> => {
|
|
547
|
+
const current = await ready;
|
|
548
|
+
const url = new URL(request.url);
|
|
549
|
+
const matched = current.match(url.pathname, request.method);
|
|
550
|
+
if (!matched?.route.handle) return notFound();
|
|
551
|
+
const guard = matched.access;
|
|
552
|
+
if (!guard || guard.kind === "socket") {
|
|
553
|
+
return new Response(`${request.method} is not served here`, { status: 405 });
|
|
554
|
+
}
|
|
555
|
+
if (guard.kind === "write" && guard.writable && !writable) {
|
|
556
|
+
return refused(guard.writable, 403);
|
|
557
|
+
}
|
|
558
|
+
return matched.route.handle(request, { path: matched.path, url, keepOpen: () => {} });
|
|
559
|
+
};
|
|
560
|
+
|
|
561
|
+
let usage: Promise<UsageCache> | undefined = deps.usage && Promise.resolve(deps.usage);
|
|
562
|
+
const studioServices: StudioServices = {
|
|
532
563
|
writable,
|
|
533
|
-
|
|
564
|
+
services: () => services.summaries(),
|
|
565
|
+
keepsFolder: (companionPath) => {
|
|
566
|
+
const folder = services.companions?.folder;
|
|
567
|
+
return folder !== undefined && !deletableWithin(companionPath, folder);
|
|
568
|
+
},
|
|
569
|
+
addsCompanions: () => services.companions !== null,
|
|
534
570
|
modePolicy: policy,
|
|
535
571
|
page: collectPage,
|
|
536
|
-
|
|
537
|
-
if (!writable) throw new WorksetError(NOT_WRITABLE);
|
|
538
|
-
await outcomesFor(await companionPathOf(digest)).act(id, action, field);
|
|
539
|
-
boardChanged(digest);
|
|
540
|
-
},
|
|
541
|
-
createOutcome: async (digest, field) => {
|
|
542
|
-
if (!writable) throw new WorksetError(NOT_WRITABLE);
|
|
543
|
-
await outcomesFor(await companionPathOf(digest)).create(field);
|
|
544
|
-
boardChanged(digest);
|
|
545
|
-
},
|
|
572
|
+
callService,
|
|
546
573
|
vault: async (digest, request) => {
|
|
547
574
|
const { vaultView } = await import("./views/vault/view");
|
|
548
575
|
return vaultView(vault, await companionPathOf(digest), request);
|
|
@@ -555,9 +582,77 @@ export function createStudioFetch(
|
|
|
555
582
|
const { vaultMatches } = await import("./views/vault/view");
|
|
556
583
|
return vaultMatches(vault, await companionPathOf(digest), query);
|
|
557
584
|
},
|
|
558
|
-
|
|
585
|
+
vaultPreview: async (digest, filePath, content) => {
|
|
586
|
+
await companionPathOf(digest);
|
|
587
|
+
const { markdownTree } = await import("./views/vault/markdown-tree");
|
|
588
|
+
return markdownTree(content, filePath);
|
|
589
|
+
},
|
|
590
|
+
vaultSave: async (digest, filePath, content, token) => {
|
|
559
591
|
if (!writable) throw new VaultPathError("start Studio with --writable to enable saving");
|
|
560
|
-
return vault.save(await companionPathOf(digest),
|
|
592
|
+
return vault.save(await companionPathOf(digest), filePath, content, token);
|
|
593
|
+
},
|
|
594
|
+
graph: async (digest) => {
|
|
595
|
+
const companionPath = await companionPathOf(digest);
|
|
596
|
+
graphs ??= import("./graph").then(({ createSpecGraphCache }) => createSpecGraphCache());
|
|
597
|
+
return (await graphs).read(companionPath);
|
|
598
|
+
},
|
|
599
|
+
reports: async (digest) => {
|
|
600
|
+
await companionPathOf(digest);
|
|
601
|
+
return reports.list(digest);
|
|
602
|
+
},
|
|
603
|
+
usage: async (digest, request) => {
|
|
604
|
+
const companionPath = await companionPathOf(digest);
|
|
605
|
+
// A failed load is forgotten so Refresh can retry it.
|
|
606
|
+
usage ??= import("../../../lib/usage/cache")
|
|
607
|
+
.then(({ createUsageCache }) => createUsageCache())
|
|
608
|
+
.catch((error: unknown) => {
|
|
609
|
+
usage = undefined;
|
|
610
|
+
throw error;
|
|
611
|
+
});
|
|
612
|
+
return (await usage).read(companionPath, request);
|
|
613
|
+
},
|
|
614
|
+
skillPreview: async (digest, agent, name, file) => {
|
|
615
|
+
const { readSkillPreview } = await import("./skill-files");
|
|
616
|
+
return readSkillPreview(await companionPathOf(digest), agent, name, file);
|
|
617
|
+
},
|
|
618
|
+
deleteCompanion: async (digest) => {
|
|
619
|
+
if (!writable) {
|
|
620
|
+
throw new CompanionRemovalError("start Studio with --writable to delete companions");
|
|
621
|
+
}
|
|
622
|
+
const companionPath = await companionPathOf(digest);
|
|
623
|
+
const mounted = await ready;
|
|
624
|
+
const pinned = [launchCompanion, ...mounted.pinnedCompanions()].filter(
|
|
625
|
+
(entry): entry is string => typeof entry === "string" && entry !== "",
|
|
626
|
+
);
|
|
627
|
+
// Real paths, so a symlinked start path still protects its folder.
|
|
628
|
+
const target = await realOrResolved(companionPath);
|
|
629
|
+
const pinnedReal = await Promise.all(pinned.map((entry) => realOrResolved(entry)));
|
|
630
|
+
if (pinnedReal.includes(target)) {
|
|
631
|
+
throw new CompanionRemovalError(
|
|
632
|
+
"Studio was started for this companion; it is not deleted.",
|
|
633
|
+
);
|
|
634
|
+
}
|
|
635
|
+
// With a companion source, only a folder in its directory is deleted.
|
|
636
|
+
const folder = mounted.companions?.folder;
|
|
637
|
+
const { deletedFolder } = await deleteRegisteredCompanion(
|
|
638
|
+
companionPath,
|
|
639
|
+
folder === undefined ? {} : { deleteWithin: folder },
|
|
640
|
+
);
|
|
641
|
+
return { deletedFolder };
|
|
642
|
+
},
|
|
643
|
+
addCompanion: async (input) => {
|
|
644
|
+
if (!writable) return { ok: false, reason: "start Studio with --writable to add companions" };
|
|
645
|
+
const source = (await ready).companions;
|
|
646
|
+
if (source === null) {
|
|
647
|
+
return { ok: false, reason: "adding companions needs a service that provides them" };
|
|
648
|
+
}
|
|
649
|
+
const added =
|
|
650
|
+
input.kind === "url"
|
|
651
|
+
? await addCompanionByUrl(input.url, { source })
|
|
652
|
+
: await addCompanionByPath(input.path, {});
|
|
653
|
+
return added.ok
|
|
654
|
+
? { ok: true, digest: companionDigest(added.companionPath), existing: added.existing }
|
|
655
|
+
: added;
|
|
561
656
|
},
|
|
562
657
|
};
|
|
563
658
|
const app = options.app ?? null;
|
|
@@ -593,7 +688,7 @@ export function createStudioFetch(
|
|
|
593
688
|
return null;
|
|
594
689
|
};
|
|
595
690
|
|
|
596
|
-
const
|
|
691
|
+
const dispatch = async (
|
|
597
692
|
request: Request,
|
|
598
693
|
server?: StudioUpgrader,
|
|
599
694
|
): Promise<Response | undefined> => {
|
|
@@ -604,7 +699,9 @@ export function createStudioFetch(
|
|
|
604
699
|
const exchanged = exchangeStudioToken(request, access, acceptedOrigin);
|
|
605
700
|
if (exchanged) return exchanged;
|
|
606
701
|
|
|
607
|
-
|
|
702
|
+
await ready;
|
|
703
|
+
const serviceRoute = services.match(url.pathname, request.method);
|
|
704
|
+
const route = routeOf(url, request.method, app !== null, serviceRoute);
|
|
608
705
|
if (!route.methods.includes(request.method)) {
|
|
609
706
|
return new Response(`${request.method} is not served here`, {
|
|
610
707
|
status: 405,
|
|
@@ -646,9 +743,32 @@ export function createStudioFetch(
|
|
|
646
743
|
);
|
|
647
744
|
}
|
|
648
745
|
|
|
649
|
-
if (
|
|
650
|
-
|
|
651
|
-
|
|
746
|
+
if (serviceRoute?.access) {
|
|
747
|
+
const context = {
|
|
748
|
+
path: serviceRoute.path,
|
|
749
|
+
url,
|
|
750
|
+
keepOpen: () => server?.timeout?.(request, 0),
|
|
751
|
+
};
|
|
752
|
+
if (serviceRoute.access.kind === "socket") {
|
|
753
|
+
if (request.headers.get("upgrade")?.toLowerCase() !== "websocket" || !server) {
|
|
754
|
+
return respond(refused("this route is a WebSocket endpoint", 426));
|
|
755
|
+
}
|
|
756
|
+
const handler = serviceRoute.route.socket?.(request, context) ?? null;
|
|
757
|
+
if (!handler) return respond(refused("the service refused the connection", 403));
|
|
758
|
+
const service = guardedSocket(handler, (message) =>
|
|
759
|
+
process.stderr.write(`mate studio: ${message}\n`),
|
|
760
|
+
);
|
|
761
|
+
if (server.upgrade(request, { data: { service } })) return undefined;
|
|
762
|
+
return respond(refused("the connection could not be upgraded", 400));
|
|
763
|
+
}
|
|
764
|
+
if (!serviceRoute.route.handle) return respond(notFound());
|
|
765
|
+
return respond(await serviceRoute.route.handle(request, context));
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
if (url.pathname.startsWith(SERVICE_ROUTE_PREFIX)) return respond(notFound());
|
|
769
|
+
|
|
770
|
+
if (url.pathname.startsWith(SERVICE_ASSET_PREFIX)) {
|
|
771
|
+
return respond((await services.asset(url.pathname)) ?? notFound());
|
|
652
772
|
}
|
|
653
773
|
|
|
654
774
|
if (app) {
|
|
@@ -722,33 +842,49 @@ export function createStudioFetch(
|
|
|
722
842
|
}
|
|
723
843
|
}
|
|
724
844
|
|
|
725
|
-
const logMatch = FACTORY_LOG.exec(url.pathname);
|
|
726
|
-
if (logMatch) {
|
|
727
|
-
const id = decodeURIComponent(logMatch[1]!);
|
|
728
|
-
if (!outcomes || !isWorksetId(id)) return respond(notFound());
|
|
729
|
-
if (logMatch[2]) return respond(logStream(outcomes, id));
|
|
730
|
-
return respond(
|
|
731
|
-
new Response(await outcomes.log(id), {
|
|
732
|
-
headers: { "content-type": "text/plain; charset=utf-8", "cache-control": "no-store" },
|
|
733
|
-
}),
|
|
734
|
-
);
|
|
735
|
-
}
|
|
736
|
-
|
|
737
845
|
// Everything else is the application's: its documents, views and server functions.
|
|
738
|
-
if (app) return respond(await app.fetch(request, { context: { studio:
|
|
846
|
+
if (app) return respond(await app.fetch(request, { context: { studio: studioServices } }));
|
|
739
847
|
if (url.pathname === "/") return respond(html(MISSING_BUILD_PAGE));
|
|
740
848
|
return respond(notFound());
|
|
741
849
|
};
|
|
742
850
|
|
|
851
|
+
// One place for every response, so refusals and the app's documents cannot miss it.
|
|
852
|
+
const handler = async (
|
|
853
|
+
request: Request,
|
|
854
|
+
server?: StudioUpgrader,
|
|
855
|
+
): Promise<Response | undefined> => {
|
|
856
|
+
const response = await dispatch(request, server);
|
|
857
|
+
if (!response || new URL(request.url).pathname.startsWith(REPORT_VIEW_PREFIX)) return response;
|
|
858
|
+
return forbidFraming(response);
|
|
859
|
+
};
|
|
860
|
+
|
|
743
861
|
handler.terminal = terminal;
|
|
744
|
-
handler.services =
|
|
862
|
+
handler.services = studioServices;
|
|
863
|
+
handler.ready = ready;
|
|
745
864
|
handler.close = async () => {
|
|
746
865
|
vault.stop();
|
|
747
866
|
await terminal?.stopAll();
|
|
867
|
+
await (await ready).close();
|
|
748
868
|
};
|
|
749
869
|
return handler;
|
|
750
870
|
}
|
|
751
871
|
|
|
872
|
+
/** A copy, because an app response such as `Response.redirect` has immutable headers. */
|
|
873
|
+
function forbidFraming(response: Response): Response {
|
|
874
|
+
const headers = new Headers(response.headers);
|
|
875
|
+
headers.set("x-frame-options", "DENY");
|
|
876
|
+
const policy = headers.get("content-security-policy")?.replace(/[;\s]+$/, "");
|
|
877
|
+
headers.set(
|
|
878
|
+
"content-security-policy",
|
|
879
|
+
policy ? `${policy}; frame-ancestors 'none'` : "frame-ancestors 'none'",
|
|
880
|
+
);
|
|
881
|
+
return new Response(response.body, {
|
|
882
|
+
status: response.status,
|
|
883
|
+
statusText: response.statusText,
|
|
884
|
+
headers,
|
|
885
|
+
});
|
|
886
|
+
}
|
|
887
|
+
|
|
752
888
|
async function selectedCompanion(
|
|
753
889
|
digest: string | null,
|
|
754
890
|
collectInventory: () => Promise<StudioInventory>,
|
|
@@ -756,13 +892,17 @@ async function selectedCompanion(
|
|
|
756
892
|
return resolveCompanion(await collectInventory(), digest);
|
|
757
893
|
}
|
|
758
894
|
|
|
895
|
+
function realOrResolved(entry: string): Promise<string> {
|
|
896
|
+
return realpath(entry).catch(() => path.resolve(entry));
|
|
897
|
+
}
|
|
898
|
+
|
|
759
899
|
/** Server-sent events: `subscribe` gets a send function and returns its unsubscribe. */
|
|
760
900
|
function eventStream(
|
|
761
901
|
greeting: string,
|
|
762
902
|
subscribe: (send: (event: unknown) => void) => () => void,
|
|
763
903
|
): Response {
|
|
764
904
|
const encoder = new TextEncoder();
|
|
765
|
-
let unsubscribe
|
|
905
|
+
let unsubscribe: (() => void) | undefined;
|
|
766
906
|
const stream = new ReadableStream<Uint8Array>({
|
|
767
907
|
start(controller) {
|
|
768
908
|
controller.enqueue(encoder.encode(`: ${greeting}\n\n`));
|
|
@@ -770,12 +910,12 @@ function eventStream(
|
|
|
770
910
|
try {
|
|
771
911
|
controller.enqueue(encoder.encode(`data: ${JSON.stringify(event)}\n\n`));
|
|
772
912
|
} catch {
|
|
773
|
-
unsubscribe();
|
|
913
|
+
unsubscribe?.();
|
|
774
914
|
}
|
|
775
915
|
});
|
|
776
916
|
},
|
|
777
917
|
cancel() {
|
|
778
|
-
unsubscribe();
|
|
918
|
+
unsubscribe?.();
|
|
779
919
|
},
|
|
780
920
|
});
|
|
781
921
|
return new Response(stream, {
|
|
@@ -787,22 +927,6 @@ function eventStream(
|
|
|
787
927
|
});
|
|
788
928
|
}
|
|
789
929
|
|
|
790
|
-
/**
|
|
791
|
-
* A Workset's run log as it grows: one `replay` (the stored log and the text still
|
|
792
|
-
* streaming), then the live events. Read-only; leaving never touches the run.
|
|
793
|
-
*/
|
|
794
|
-
function logStream(live: { watch(id: string): LiveViewer }, id: string): Response {
|
|
795
|
-
return eventStream("studio factory log", (send) => {
|
|
796
|
-
const viewer = live.watch(id);
|
|
797
|
-
void (async () => {
|
|
798
|
-
send({ type: "replay", ...(await viewer.replay) });
|
|
799
|
-
// oxlint-disable-next-line no-await-in-loop -- events arrive one at a time, in order
|
|
800
|
-
for (let event = await viewer.next(); event; event = await viewer.next()) send(event);
|
|
801
|
-
})().catch(() => viewer.close());
|
|
802
|
-
return () => viewer.close();
|
|
803
|
-
});
|
|
804
|
-
}
|
|
805
|
-
|
|
806
930
|
/** One stream per page, so a view updates in place instead of reloading (design D7). */
|
|
807
931
|
function studioEvents(
|
|
808
932
|
vault: VaultManager,
|
|
@@ -842,11 +966,6 @@ function vaultEvents(vault: VaultManager, companionPath: string, requestedPath:
|
|
|
842
966
|
);
|
|
843
967
|
}
|
|
844
968
|
|
|
845
|
-
/** Reports are not part of the snapshot: this Overview lists them at render time. */
|
|
846
|
-
function isAnalystOverview(selection: StudioSelection): boolean {
|
|
847
|
-
return selection.studioMode === "analysis" && selection.view === "dashboard";
|
|
848
|
-
}
|
|
849
|
-
|
|
850
969
|
/**
|
|
851
970
|
* One rendered document's worth of state. An absent or unresolvable companion
|
|
852
971
|
* is not a failure: the page renders the selector and the server keeps serving.
|
|
@@ -856,7 +975,6 @@ async function collectStudioPage(
|
|
|
856
975
|
policy: StudioModePolicy,
|
|
857
976
|
collectInventory: () => Promise<StudioInventory>,
|
|
858
977
|
snapshots: StudioSnapshotCache,
|
|
859
|
-
vault: VaultManager,
|
|
860
978
|
writable: boolean,
|
|
861
979
|
): Promise<StudioPage> {
|
|
862
980
|
const selection = parse(url, policy);
|
|
@@ -874,7 +992,6 @@ async function collectStudioPage(
|
|
|
874
992
|
terminal: null,
|
|
875
993
|
};
|
|
876
994
|
|
|
877
|
-
vault.deactivate();
|
|
878
995
|
if (!companion) return page;
|
|
879
996
|
|
|
880
997
|
try {
|
|
@@ -958,33 +1075,39 @@ export function startStudioServer(
|
|
|
958
1075
|
hostname,
|
|
959
1076
|
idleTimeout: options.idleTimeout ?? STUDIO_IDLE_TIMEOUT_SECONDS,
|
|
960
1077
|
fetch: fetchHandler,
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
close: (code, reason) => ws.close(code, reason),
|
|
970
|
-
});
|
|
971
|
-
},
|
|
972
|
-
message(ws, message) {
|
|
973
|
-
void ws.data.connection?.message(message);
|
|
974
|
-
},
|
|
975
|
-
close(ws) {
|
|
976
|
-
ws.data.connection?.closed();
|
|
977
|
-
},
|
|
978
|
-
pong(ws) {
|
|
979
|
-
ws.data.connection?.pong();
|
|
980
|
-
},
|
|
981
|
-
idleTimeout: 0,
|
|
982
|
-
sendPings: false,
|
|
983
|
-
backpressureLimit: 2 * 1024 * 1024,
|
|
984
|
-
maxPayloadLength: 256 * 1024,
|
|
985
|
-
},
|
|
1078
|
+
websocket: {
|
|
1079
|
+
open(ws) {
|
|
1080
|
+
if (ws.data.service) {
|
|
1081
|
+
ws.data.service.open({
|
|
1082
|
+
send: (data) => void ws.send(data),
|
|
1083
|
+
close: (code, reason) => ws.close(code, reason),
|
|
1084
|
+
});
|
|
1085
|
+
return;
|
|
986
1086
|
}
|
|
987
|
-
|
|
1087
|
+
if (!registry) return ws.close(1008, "the terminal is not enabled");
|
|
1088
|
+
ws.data.connection = registry.connect({
|
|
1089
|
+
send: (data) => void ws.send(data),
|
|
1090
|
+
bufferedAmount: () => ws.getBufferedAmount(),
|
|
1091
|
+
ping: () => ws.ping(),
|
|
1092
|
+
close: (code, reason) => ws.close(code, reason),
|
|
1093
|
+
});
|
|
1094
|
+
},
|
|
1095
|
+
message(ws, message) {
|
|
1096
|
+
if (ws.data.service) return ws.data.service.message(message);
|
|
1097
|
+
void ws.data.connection?.message(message);
|
|
1098
|
+
},
|
|
1099
|
+
close(ws) {
|
|
1100
|
+
if (ws.data.service) return ws.data.service.close();
|
|
1101
|
+
ws.data.connection?.closed();
|
|
1102
|
+
},
|
|
1103
|
+
pong(ws) {
|
|
1104
|
+
ws.data.connection?.pong();
|
|
1105
|
+
},
|
|
1106
|
+
idleTimeout: 0,
|
|
1107
|
+
sendPings: false,
|
|
1108
|
+
backpressureLimit: 2 * 1024 * 1024,
|
|
1109
|
+
maxPayloadLength: 256 * 1024,
|
|
1110
|
+
},
|
|
988
1111
|
});
|
|
989
1112
|
boundPort = server.port;
|
|
990
1113
|
const loopback = hostname === STUDIO_HOSTNAME || hostname === "localhost" || hostname === "::1";
|