@uniqbit/mate-core 0.18.5 → 1.0.0-canary.2
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/marketplace.json +14 -0
- package/claude-capability-plugins/companion-mentions/.claude-plugin/plugin.json +8 -0
- package/claude-capability-plugins/companion-mentions/hooks/companion.ts +457 -0
- package/claude-capability-plugins/companion-mentions/hooks/hooks.json +1 -0
- package/claude-capability-plugins/companion-mentions/hooks/register.ts +403 -0
- package/claude-plugin/hooks/companion-instructions.mjs +9 -0
- package/claude-plugin/hooks/hooks.json +21 -2
- package/claude-plugin/hooks/tokensave-route.mjs +52 -0
- package/opencode-plugin/src/server.ts +4 -0
- package/opencode-plugin/src/tui.tsx +2 -0
- package/opencode-plugin/tui.tsx +2 -0
- package/package.json +52 -15
- package/src/brand/art.generated.ts +69 -0
- package/src/brand/index.ts +12 -0
- package/src/brand/palette.ts +19 -0
- package/src/brand/svg.generated.ts +8 -0
- package/src/brand/terminal.ts +88 -0
- package/src/brand/types.ts +33 -0
- package/src/cli/commands/artifact/apply-context.ts +275 -0
- package/src/cli/commands/artifact/artifact.ts +12 -0
- package/src/cli/commands/artifact/delivery/archive.ts +125 -0
- package/src/cli/commands/artifact/delivery/branch-flags.ts +55 -0
- package/src/cli/commands/artifact/delivery/environment.ts +127 -0
- package/src/cli/commands/artifact/delivery/link.ts +174 -0
- package/src/cli/commands/artifact/delivery/output.ts +89 -0
- package/src/cli/commands/artifact/finish/command.ts +83 -8
- package/src/cli/commands/artifact/finish/engine.ts +91 -14
- package/src/cli/commands/artifact/finish/finisher.ts +10 -0
- package/src/cli/commands/artifact/finish/git.ts +132 -19
- package/src/cli/commands/artifact/finish/openspec.ts +182 -138
- package/src/cli/commands/artifact/finish/secret-scan.ts +43 -0
- package/src/cli/commands/artifact/finish/worktree-cleanup.ts +92 -0
- package/src/cli/commands/artifact/pending/command.ts +31 -3
- package/src/cli/commands/artifact/pending/discovery.ts +21 -57
- package/src/cli/commands/cap/graphify.ts +52 -3
- package/src/cli/commands/cap/index-cmd.ts +71 -15
- package/src/cli/commands/cap/openspec.ts +13 -25
- package/src/cli/commands/cap/tokensave.ts +7 -5
- package/src/cli/commands/companion/link.ts +14 -1
- package/src/cli/commands/companion/open.ts +68 -46
- package/src/cli/commands/companion/sync.ts +10 -0
- package/src/cli/commands/companion/tui.ts +17 -7
- package/src/cli/commands/companion/update.ts +143 -48
- package/src/cli/commands/doctor.ts +195 -7
- package/src/cli/commands/factory/factory.ts +301 -0
- package/src/cli/commands/install.ts +133 -9
- package/src/cli/commands/launch/shared.ts +16 -11
- package/src/cli/commands/plugin/install.ts +9 -4
- package/src/cli/commands/plugin/plugin.ts +3 -2
- package/src/cli/commands/report/adapter.ts +11 -2
- package/src/cli/commands/report/contract.ts +21 -0
- package/src/cli/commands/report/highlight.ts +34 -4
- package/src/cli/commands/report/index.ts +20 -1
- package/src/cli/commands/report/markdown.ts +110 -0
- package/src/cli/commands/report/palette.ts +118 -0
- package/src/cli/commands/report/renderer.ts +456 -153
- package/src/cli/commands/report/types.ts +16 -0
- package/src/cli/commands/session/context.ts +102 -0
- package/src/cli/commands/setup.ts +50 -24
- package/src/cli/commands/studio/factory-credential.ts +49 -0
- package/src/cli/commands/studio/index.ts +29 -2
- package/src/cli/commands/studio/openspec-cli.ts +10 -58
- package/src/cli/commands/studio/payload.ts +249 -15
- package/src/cli/commands/studio/routes.ts +41 -6
- package/src/cli/commands/studio/selection.ts +161 -17
- package/src/cli/commands/studio/server.ts +404 -324
- package/src/cli/commands/studio/services.ts +60 -0
- package/src/cli/commands/studio/studio-app.ts +67 -0
- package/src/cli/commands/studio/terminal-assets.ts +21 -33
- package/src/cli/commands/studio/terminal.ts +85 -15
- package/src/cli/commands/studio/views/model.ts +18 -0
- package/src/cli/commands/studio/views/vault/markdown-tree.ts +267 -0
- package/src/cli/commands/studio/views/vault/view.ts +185 -0
- package/src/cli/commands/studio/workset-session.ts +131 -0
- package/src/cli/commands/unwrap.ts +8 -0
- package/src/cli/commands/update.ts +27 -1
- package/src/cli/commands/working/cleanup.ts +10 -1
- package/src/cli/commands/working/link.ts +76 -0
- package/src/cli/commands/working/working.ts +10 -0
- package/src/cli/commands/working/worktree.ts +356 -0
- package/src/cli/commands/wrap.ts +5 -13
- package/src/cli/companion-link-wizard.tsx +2 -0
- package/src/cli/companion-selector.tsx +2 -0
- package/src/cli/confirm.ts +2 -0
- package/src/cli/install-plan.tsx +127 -160
- package/src/cli/launch-selector.tsx +2 -0
- package/src/cli/main.ts +22 -1
- package/src/cli/parse-flags.ts +32 -6
- package/src/cli/repo-list-table.tsx +2 -0
- package/src/cli/setup-selector.tsx +86 -151
- package/src/cli/usage.ts +14 -0
- package/src/create-mate.ts +5 -4
- package/src/hooks/companion-instructions.ts +190 -0
- package/src/hooks/hook-io.ts +63 -0
- package/src/hooks/session-banner.ts +21 -29
- package/src/hooks/session-guidance.ts +9 -17
- package/src/hooks/session-prepare.ts +115 -28
- package/src/hooks/tokensave-route.ts +26 -0
- package/src/hooks/validate-artifact-path.ts +82 -24
- package/src/index.ts +4 -0
- package/src/lib/apply-context/fingerprint.ts +174 -0
- package/src/lib/apply-context/protocol.ts +193 -0
- package/src/lib/change-layout.ts +154 -0
- package/src/lib/components/confirm-prompt.tsx +21 -9
- package/src/lib/components/select-menu.tsx +10 -3
- package/src/lib/components/spinner.tsx +4 -2
- package/src/lib/components/startup-progress.tsx +227 -41
- package/src/lib/components/text-input-display.tsx +2 -0
- package/src/lib/components/wizard-footer.tsx +2 -0
- package/src/lib/components/wizard-header.tsx +16 -12
- package/src/lib/context-mode-package.ts +24 -11
- package/src/lib/delivery/archive-change.ts +166 -0
- package/src/lib/delivery/branches.ts +132 -0
- package/src/lib/delivery/environment.ts +35 -0
- package/src/lib/delivery/forge.ts +279 -0
- package/src/lib/delivery/merge-git.ts +261 -0
- package/src/lib/delivery/overlap.ts +209 -0
- package/src/lib/delivery/record-delivery.ts +283 -0
- package/src/lib/delivery/record.ts +403 -0
- package/src/lib/delivery/refresh.ts +268 -0
- package/src/lib/delivery/repository-access.ts +141 -0
- package/src/lib/delivery/resolve-branch.ts +162 -0
- package/src/lib/delivery/stages.ts +111 -0
- package/src/lib/delivery/token.ts +24 -0
- package/src/lib/factory/attach-client.ts +113 -0
- package/src/lib/factory/attach.ts +178 -0
- package/src/lib/factory/broker.ts +190 -0
- package/src/lib/factory/bun-commands.ts +39 -0
- package/src/lib/factory/client.ts +92 -0
- package/src/lib/factory/command.ts +61 -0
- package/src/lib/factory/credential-store.ts +153 -0
- package/src/lib/factory/frames.ts +77 -0
- package/src/lib/factory/ids.ts +58 -0
- package/src/lib/factory/keyed-serial.ts +27 -0
- package/src/lib/factory/outcomes/actions.ts +114 -0
- package/src/lib/factory/outcomes/index.ts +381 -0
- package/src/lib/factory/outcomes/lifecycle.ts +205 -0
- package/src/lib/factory/outcomes/runs.ts +81 -0
- package/src/lib/factory/outcomes/sessions.ts +38 -0
- package/src/lib/factory/prepare.ts +49 -0
- package/src/lib/factory/pty.ts +103 -0
- package/src/lib/factory/runner/companion-context.ts +178 -0
- package/src/lib/factory/runner/control.ts +92 -0
- package/src/lib/factory/runner/harness-agent.ts +250 -0
- package/src/lib/factory/runner/live.ts +159 -0
- package/src/lib/factory/runner/questions.ts +22 -0
- package/src/lib/factory/runner/rank.ts +26 -0
- package/src/lib/factory/runner/run-policy.ts +12 -0
- package/src/lib/factory/runner/run.ts +199 -0
- package/src/lib/factory/runner/scheduler.ts +416 -0
- package/src/lib/factory/runner/state.ts +233 -0
- package/src/lib/factory/runner/workflow.ts +542 -0
- package/src/lib/factory/runtime.ts +972 -0
- package/src/lib/factory/sandbox.ts +292 -0
- package/src/lib/factory/worktree-branch.ts +17 -0
- package/src/lib/frontmatter.ts +18 -0
- package/src/lib/install.ts +66 -14
- package/src/lib/live-progress.ts +36 -0
- package/src/lib/member-choices.ts +67 -0
- package/src/lib/opencode-plugin-package.ts +5 -5
- package/src/lib/openspec-cli.ts +116 -0
- package/src/lib/openspec-scopes.ts +86 -0
- package/src/lib/orchestrator/adapters/base.ts +55 -22
- package/src/lib/orchestrator/adapters/claude-args.ts +50 -0
- package/src/lib/orchestrator/adapters/claude.ts +54 -41
- package/src/lib/orchestrator/adapters/opencode.ts +2 -0
- package/src/lib/orchestrator/config-store.ts +3 -2
- package/src/lib/orchestrator/editor.ts +31 -25
- package/src/lib/orchestrator/openspec-store.ts +14 -54
- package/src/lib/orchestrator/projection-claude-commands.ts +36 -0
- package/src/lib/orchestrator/projection-claude-links.ts +159 -0
- package/src/lib/orchestrator/projection-claude-skills.ts +19 -137
- package/src/lib/orchestrator/projection-entries.ts +100 -34
- package/src/lib/orchestrator/projection-opencode-copies.ts +32 -15
- package/src/lib/orchestrator/projection-openspec-store.ts +54 -9
- package/src/lib/orchestrator/projection-runtime-documents.ts +15 -6
- package/src/lib/orchestrator/projection-types.ts +36 -1
- package/src/lib/orchestrator/refresh-working-claude-links.ts +87 -0
- package/src/lib/orchestrator/session-context-link.ts +67 -0
- package/src/lib/orchestrator/session-prepare.ts +45 -5
- package/src/lib/orchestrator/setup-compatibilities.ts +56 -70
- package/src/lib/orchestrator/types.ts +7 -2
- package/src/lib/orchestrator/working-repo-projection.ts +50 -7
- package/src/lib/orchestrator/workspace-document.ts +105 -0
- package/src/lib/orchestrator/wrap-pass.ts +22 -1
- package/src/lib/package-paths.ts +37 -0
- package/src/lib/runtime-directory-refresh.ts +17 -1
- package/src/lib/workset/record.ts +513 -0
- package/src/lib/workset/repositories.ts +55 -0
- package/src/lib/workset/stage.ts +148 -0
- package/src/lib/workset/stages.ts +113 -0
- package/src/lib/workset/worktree-index.ts +116 -0
- package/src/lib/workset/worktree.ts +830 -0
- package/src/opencode/companion-hooks.ts +109 -7
- package/src/opencode/companion-policy.ts +37 -18
- package/src/opencode/enter-worktree.ts +72 -0
- package/src/opencode/projected-guidance.ts +4 -1
- package/src/opencode/session-prepare.ts +2 -1
- package/src/opencode/tui.tsx +13 -6
- package/src/plugins.ts +1 -0
- package/src/runtime/artifact-refusal.ts +63 -0
- package/src/runtime/claude-delivery-plan.ts +107 -8
- package/src/runtime/commit-attribution-guard.ts +181 -0
- package/src/runtime/companion-git.ts +52 -10
- package/src/runtime/companion-guidance.ts +20 -8
- package/src/runtime/companion-instructions.ts +340 -0
- package/src/runtime/companion-lock.ts +30 -7
- package/src/runtime/env.ts +48 -3
- package/src/runtime/error-message.ts +4 -0
- package/src/runtime/git-layout.ts +219 -0
- package/src/runtime/index.ts +29 -0
- package/src/runtime/managed-block.ts +117 -0
- package/src/runtime/markdown-scan.ts +266 -0
- package/src/runtime/physical-path.ts +111 -0
- package/src/runtime/policy.ts +50 -2
- package/src/runtime/projected-flag.ts +7 -0
- package/src/runtime/projected-guidance.ts +1 -0
- package/src/runtime/runtime-directory.ts +5 -0
- package/src/runtime/runtime-document-manifest.ts +62 -11
- package/src/runtime/secret-guard.ts +162 -0
- package/src/runtime/secret-patterns.ts +397 -0
- package/src/runtime/secret-scan.ts +90 -0
- package/src/runtime/session-context.ts +98 -0
- package/src/runtime/session-kind.ts +13 -0
- package/src/runtime/shell-heredoc.ts +81 -0
- package/src/runtime/tokensave-route.ts +152 -0
- package/src/runtime/wrap-state.ts +44 -2
- package/src/runtime/write-atomic.ts +64 -0
- package/src/studio.ts +124 -0
- package/src/templates/capabilities/openspec-cap/mate-minimal/schema.yaml +14 -10
- package/src/templates/capabilities/openspec-cap/mate-minimal/templates/spec.md +3 -5
- package/src/templates/capabilities/openspec-cap/mate-v1/schema.yaml +18 -102
- package/src/templates/capabilities/openspec-cap/mate-v1/templates/spec.md +3 -5
- package/src/templates/capabilities/openspec-cap/openspec-conventions.yaml +20 -14
- package/src/templates/mate-skills/THIRD-PARTY-NOTICES.md +40 -0
- package/src/templates/mate-skills/agents/mate-apply-change/SKILL.md +134 -0
- package/src/templates/mate-skills/agents/mate-apply-change/references/mate-compact-apply.md +47 -0
- package/src/templates/mate-skills/agents/mate-apply-change/references/openspec-apply-change.md +200 -0
- package/src/templates/mate-skills/agents/mate-archive-change/SKILL.md +86 -0
- package/src/templates/mate-skills/{claude/mate-openspec-backfill → agents/mate-backfill-spec}/SKILL.md +11 -4
- package/src/templates/mate-skills/agents/mate-clarify-intent/SKILL.md +110 -0
- package/src/templates/mate-skills/agents/mate-explore-change/SKILL.md +66 -0
- package/src/templates/mate-skills/agents/mate-explore-change/references/openspec-explore.md +350 -0
- package/src/templates/mate-skills/agents/mate-grill-me/SKILL.md +11 -4
- package/src/templates/mate-skills/agents/mate-grill-with-docs/SKILL.md +2 -2
- package/src/templates/mate-skills/agents/mate-interview-me/SKILL.md +12 -5
- package/src/templates/mate-skills/agents/mate-propose-change/SKILL.md +108 -0
- package/src/templates/mate-skills/agents/mate-propose-change/references/mate-revise.md +47 -0
- package/src/templates/mate-skills/agents/mate-propose-change/references/openspec-propose.md +169 -0
- package/src/templates/mate-skills/agents/mate-propose-change/references/openspec-update-change.md +103 -0
- package/src/templates/mate-skills/agents/{mate-artifact-publish → mate-publish-artifact}/SKILL.md +111 -24
- package/src/templates/mate-skills/{claude/mate-artifact-publish → agents/mate-publish-artifact}/references/openspec.md +8 -5
- package/src/templates/mate-skills/agents/mate-show-me/SKILL.md +95 -16
- package/src/templates/mate-skills/agents/mate-simplify-code/SKILL.md +87 -68
- package/src/templates/mate-skills/claude/mate-apply-change/SKILL.md +134 -0
- package/src/templates/mate-skills/claude/mate-apply-change/references/mate-compact-apply.md +47 -0
- package/src/templates/mate-skills/claude/mate-apply-change/references/openspec-apply-change.md +200 -0
- package/src/templates/mate-skills/claude/mate-archive-change/SKILL.md +86 -0
- package/src/templates/mate-skills/{agents/mate-openspec-backfill → claude/mate-backfill-spec}/SKILL.md +11 -4
- package/src/templates/mate-skills/claude/mate-clarify-intent/SKILL.md +110 -0
- package/src/templates/mate-skills/claude/mate-explore-change/SKILL.md +66 -0
- package/src/templates/mate-skills/claude/mate-explore-change/references/openspec-explore.md +350 -0
- package/src/templates/mate-skills/claude/mate-grill-me/SKILL.md +11 -4
- package/src/templates/mate-skills/claude/mate-grill-with-docs/SKILL.md +2 -2
- package/src/templates/mate-skills/claude/mate-interview-me/SKILL.md +12 -5
- package/src/templates/mate-skills/claude/mate-propose-change/SKILL.md +108 -0
- package/src/templates/mate-skills/claude/mate-propose-change/references/mate-revise.md +47 -0
- package/src/templates/mate-skills/claude/mate-propose-change/references/openspec-propose.md +169 -0
- package/src/templates/mate-skills/claude/mate-propose-change/references/openspec-update-change.md +103 -0
- package/src/templates/mate-skills/claude/{mate-artifact-publish → mate-publish-artifact}/SKILL.md +111 -24
- package/src/templates/mate-skills/{agents/mate-artifact-publish → claude/mate-publish-artifact}/references/openspec.md +8 -5
- package/src/templates/mate-skills/claude/mate-show-me/SKILL.md +95 -16
- package/src/templates/mate-skills/claude/mate-simplify-code/SKILL.md +87 -68
- package/src/templates/mate-skills/openspec-references.ts +142 -0
- package/src/templates/root/TEMPLATE_AGENTS.md +2 -2
- package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +3938 -391
- package/src/tools/setup/capabilities/companion-mentions.ts +27 -0
- package/src/tools/setup/capabilities/context-mode.ts +56 -7
- package/src/tools/setup/capabilities/graphify-gate.ts +31 -0
- package/src/tools/setup/capabilities/graphify-secrets.ts +243 -0
- package/src/tools/setup/capabilities/graphify.ts +46 -7
- package/src/tools/setup/capabilities/openspec.ts +163 -272
- package/src/tools/setup/capabilities/react-doctor.ts +8 -1
- package/src/tools/setup/capabilities/rtk.ts +4 -0
- package/src/tools/setup/capabilities/tokensave.ts +113 -71
- package/src/tools/setup/context-services.ts +9 -17
- package/src/tools/setup/dynamic-plugins/install.ts +24 -28
- package/src/tools/setup/engine.ts +100 -23
- package/src/tools/setup/install-contract.ts +8 -0
- package/src/tools/setup/managed-output.ts +51 -0
- package/src/tools/setup/mate-skill-copies.ts +51 -0
- package/src/tools/setup/mate.ts +86 -11
- package/src/tools/setup/package-managers/uv.ts +73 -11
- package/src/tools/setup/plugin.ts +40 -0
- package/src/tools/setup/plugins/guidance.ts +7 -4
- package/src/tools/setup/providers/agent-file-sections.ts +4 -2
- package/src/tools/setup/providers/claude-attribution.ts +65 -0
- package/src/tools/setup/providers/claude-plugin-folders.ts +625 -0
- package/src/tools/setup/providers/claude-plugin-hooks.ts +51 -19
- package/src/tools/setup/providers/claude-worktree-plugins.ts +122 -0
- package/src/tools/setup/providers/claude.ts +290 -8
- package/src/tools/setup/providers/opencode.ts +180 -1
- package/src/tools/setup/utils.ts +18 -4
- package/src/tools/setup/working-repo-cleanup.ts +29 -1
- package/src/tools/setup/working-repo-local-state.ts +252 -75
- package/src/tools/setup.ts +183 -26
- package/studio-dist/client/assets/companion-view-Csva26Ir.js +1 -0
- package/studio-dist/client/assets/delivery-path-DJMpRmiY.js +1 -0
- package/studio-dist/client/assets/dist-Dm7MtyHc.js +5 -0
- package/studio-dist/client/assets/factory-B7l9ZQyx.js +4 -0
- package/studio-dist/client/assets/index-n6uo_92S.js +40 -0
- package/studio-dist/client/assets/preload-helper-BLdHbfdN.js +1 -0
- package/studio-dist/client/assets/prepaint-CD5OpmTM.js +24 -0
- package/studio-dist/client/assets/queries-CN3JwMBX.js +1 -0
- package/studio-dist/client/assets/react-CabXf2Ds.js +1 -0
- package/studio-dist/client/assets/report-time-Dc-KOqQu.js +1 -0
- package/studio-dist/client/assets/reports-C01RsnMA.js +1 -0
- package/studio-dist/client/assets/rolldown-runtime-WkwZ5CU-.js +1 -0
- package/studio-dist/client/assets/routes-4pbC-2Hj.js +1 -0
- package/studio-dist/client/assets/skills-CihQganl.js +1 -0
- package/studio-dist/client/assets/spec-areas-C2L48N4C.js +1 -0
- package/studio-dist/client/assets/specs-D24_35_K.js +1 -0
- package/studio-dist/client/assets/studio-DKxfi691.css +1 -0
- package/studio-dist/client/assets/studio-queries-rvbJupCy.js +3 -0
- package/studio-dist/client/assets/terminal-eU5fzQzv.css +1 -0
- package/studio-dist/client/assets/vault-Bd4CQiTK.js +1 -0
- package/studio-dist/client/assets/warnings-V_Ys51wJ.js +1 -0
- package/studio-dist/client/assets/wasm-inline-C2en61B5.js +1 -0
- package/studio-dist/client/assets/workflow-BJejeVwQ.js +1 -0
- package/studio-dist/server/assets/__23tanstack-start-server-fn-resolver-BQKuMdJW.js +3881 -0
- package/studio-dist/server/assets/_tanstack-start-manifest_v.js +85 -0
- package/studio-dist/server/assets/actions-Bvgj9eb8.js +54 -0
- package/studio-dist/server/assets/actions-D8erOphH.js +44 -0
- package/studio-dist/server/assets/companion-view-aBady57v.js +33 -0
- package/studio-dist/server/assets/createServerFn-F5sAOF8V.js +459 -0
- package/studio-dist/server/assets/createServerRpc-tK2lE9R2.js +11 -0
- package/studio-dist/server/assets/delivery-path-BkKNjgkf.js +778 -0
- package/studio-dist/server/assets/dist-DpJWKyCm.js +5582 -0
- package/studio-dist/server/assets/empty-plugin-adapters-Cipd4ZH4.js +4 -0
- package/studio-dist/server/assets/factory-D6xnjedJ.js +2385 -0
- package/studio-dist/server/assets/factory-DT3UzHlh.js +68 -0
- package/studio-dist/server/assets/model-PyPALjii.js +18 -0
- package/studio-dist/server/assets/prepaint-BMke0fo1.js +41 -0
- package/studio-dist/server/assets/queries-Ag2iL8q2.js +107 -0
- package/studio-dist/server/assets/react-COs0LHn-.js +51 -0
- package/studio-dist/server/assets/report-time-DAfzln-N.js +8 -0
- package/studio-dist/server/assets/reports-BnUNJVtx.js +126 -0
- package/studio-dist/server/assets/rolldown-runtime-DYf_mQCB.js +34 -0
- package/studio-dist/server/assets/router-BH--drIx.js +4298 -0
- package/studio-dist/server/assets/routes-khSDK1bV.js +361 -0
- package/studio-dist/server/assets/search-JAKurDNh.js +36 -0
- package/studio-dist/server/assets/shell-CboT2f66.js +51 -0
- package/studio-dist/server/assets/skills-MWYnWoKs.js +106 -0
- package/studio-dist/server/assets/spec-areas-DcnO6vW-.js +16 -0
- package/studio-dist/server/assets/specs-DE3w8hZP.js +155 -0
- package/studio-dist/server/assets/start-BW5ovN0k.js +33 -0
- package/studio-dist/server/assets/studio-BeltxxKt.js +216 -0
- package/studio-dist/server/assets/studio-queries-CLnP9kGu.js +3365 -0
- package/studio-dist/server/assets/utils-C9CX1kcy.js +221 -0
- package/studio-dist/server/assets/vault-BGulVoNh.js +70 -0
- package/studio-dist/server/assets/vault-CuyyhLyB.js +832 -0
- package/studio-dist/server/assets/views-Bd7cRr27.js +82 -0
- package/studio-dist/server/assets/warnings-BH05rOuG.js +15 -0
- package/studio-dist/server/assets/wasm-inline-CNeBKGwC.js +3 -0
- package/studio-dist/server/assets/workflow-BSuIKWqH.js +42 -0
- package/studio-dist/server/server.js +16220 -0
- package/wrappers/bin/graphify +52 -4
- package/wrappers/bin/openspec +33 -9
- package/wrappers/lib/graphify-gate.mjs +8 -0
- package/src/cli/commands/studio/views/client.ts +0 -654
- package/src/cli/commands/studio/views/companion-picker.tsx +0 -95
- package/src/cli/commands/studio/views/companion-selector.tsx +0 -94
- package/src/cli/commands/studio/views/dashboard/changes.tsx +0 -107
- package/src/cli/commands/studio/views/dashboard/index.tsx +0 -19
- package/src/cli/commands/studio/views/document.tsx +0 -842
- package/src/cli/commands/studio/views/error.tsx +0 -20
- package/src/cli/commands/studio/views/reports/index.tsx +0 -49
- package/src/cli/commands/studio/views/selection-fields.tsx +0 -14
- package/src/cli/commands/studio/views/skills/index.tsx +0 -87
- package/src/cli/commands/studio/views/specs/index.tsx +0 -157
- package/src/cli/commands/studio/views/styles.ts +0 -519
- package/src/cli/commands/studio/views/terminal.tsx +0 -484
- package/src/cli/commands/studio/views/vault/state.ts +0 -43
- package/src/cli/commands/studio/views/warnings.tsx +0 -21
- package/src/cli/commands/studio/views/workflow/index.tsx +0 -21
- package/src/cli/commands/studio/views/workflow/steps.ts +0 -337
- package/src/cli/commands/studio/views/workflow/transcript.tsx +0 -190
- package/src/lib/components/theme.ts +0 -2
- package/src/tools/setup/git-utils.ts +0 -30
- package/src/tools/setup/runtime-documents.ts +0 -291
|
@@ -9,27 +9,55 @@ import {
|
|
|
9
9
|
} from "./access";
|
|
10
10
|
import { MERMAID_RUNTIME_URL } from "../report/renderer";
|
|
11
11
|
import { collectStudioInventory, type StudioInventory } from "./inventory";
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
assembleCompanionPayload,
|
|
14
|
+
readCompanionWorksetStages,
|
|
15
|
+
type StudioCompanionResponse,
|
|
16
|
+
} from "./payload";
|
|
13
17
|
import { createReportStore, isReportId, REPORT_LIMITS, type ReportStore } from "./reports";
|
|
18
|
+
import { isWorksetId, WorksetError } from "../../../lib/workset/record";
|
|
19
|
+
import type { WorksetWithStage } from "../../../lib/workset/stages";
|
|
20
|
+
import type { LiveViewer } from "../../../lib/factory/runner/live";
|
|
21
|
+
import {
|
|
22
|
+
createFactoryOutcomes,
|
|
23
|
+
type FactoryOutcomes,
|
|
24
|
+
type Outcomes,
|
|
25
|
+
type OutcomesPorts,
|
|
26
|
+
recordOutcomes,
|
|
27
|
+
} from "../../../lib/factory/outcomes";
|
|
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";
|
|
14
32
|
import {
|
|
33
|
+
FACTORY_CREDENTIAL_ROUTE,
|
|
34
|
+
FACTORY_WORKSETS_ROUTE,
|
|
15
35
|
REPORTS_ROUTE,
|
|
16
36
|
REPORT_VIEW_PREFIX,
|
|
37
|
+
STUDIO_EVENTS_ROUTE,
|
|
17
38
|
STUDIO_HOSTNAME,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
39
|
+
type StudioEvent,
|
|
40
|
+
TERMINAL_ASSET_PREFIX,
|
|
41
|
+
TERMINAL_SESSIONS_END_ROUTE,
|
|
42
|
+
TERMINAL_SESSIONS_ROUTE,
|
|
43
|
+
TERMINAL_SOCKET_ROUTE,
|
|
44
|
+
VAULT_EVENTS_ROUTE,
|
|
21
45
|
} from "./routes";
|
|
22
46
|
import {
|
|
23
47
|
COMPANION_DIGEST_PATTERN,
|
|
24
48
|
COMPANION_PARAM,
|
|
25
49
|
companionDigest,
|
|
50
|
+
modePolicy,
|
|
26
51
|
parse,
|
|
27
52
|
parseVaultSelection,
|
|
28
53
|
resolveCompanion,
|
|
29
|
-
type
|
|
54
|
+
type StudioModePolicy,
|
|
55
|
+
type StudioProfile,
|
|
56
|
+
type StudioSelection,
|
|
30
57
|
} from "./selection";
|
|
58
|
+
import { errorMessage } from "../../../runtime/error-message";
|
|
31
59
|
import { createStudioSnapshotCache, type StudioSnapshotCache } from "./snapshot";
|
|
32
|
-
import type { StudioPage
|
|
60
|
+
import type { StudioPage } from "./views/model";
|
|
33
61
|
import { createVaultManager, resolveVaultPath, VaultPathError, type VaultManager } from "./vault";
|
|
34
62
|
import {
|
|
35
63
|
DEFAULT_DETACH_MINUTES,
|
|
@@ -37,6 +65,8 @@ import {
|
|
|
37
65
|
type TerminalConnection,
|
|
38
66
|
type TerminalRegistryOptions,
|
|
39
67
|
} from "./terminal";
|
|
68
|
+
import type { StudioFormField, StudioServices } from "./services";
|
|
69
|
+
import { studioAppAsset, type StudioApp } from "./studio-app";
|
|
40
70
|
import { terminalAsset } from "./terminal-assets";
|
|
41
71
|
import {
|
|
42
72
|
createLaunchResolver,
|
|
@@ -46,8 +76,8 @@ import {
|
|
|
46
76
|
|
|
47
77
|
export { STUDIO_HOSTNAME } from "./routes";
|
|
48
78
|
|
|
49
|
-
/**
|
|
50
|
-
const
|
|
79
|
+
/** Where Start's server functions are called; the only POSTs the application makes. */
|
|
80
|
+
const STUDIO_APP_CALL_PREFIX = "/_serverFn/";
|
|
51
81
|
|
|
52
82
|
/** The socket Bun hands a WebSocket handler; `data` is what the upgrade attached. */
|
|
53
83
|
export interface StudioSocket {
|
|
@@ -101,13 +131,21 @@ export interface StudioServerHandle {
|
|
|
101
131
|
export interface StudioServerDeps {
|
|
102
132
|
collectStudioInventory?: () => Promise<StudioInventory>;
|
|
103
133
|
assembleCompanionPayload?: (companionPath: string) => Promise<StudioCompanionResponse>;
|
|
104
|
-
renderDocument?: (page: StudioPage) => string | Promise<string>;
|
|
105
134
|
serve?: (options: StudioServeOptions) => StudioBoundServer;
|
|
106
135
|
snapshots?: StudioSnapshotCache;
|
|
107
136
|
vault?: VaultManager;
|
|
108
137
|
reports?: ReportStore;
|
|
109
138
|
terminal?: Partial<TerminalRegistryOptions>;
|
|
110
139
|
launchableAgents?: typeof launchableAgents;
|
|
140
|
+
/**
|
|
141
|
+
* The factory's Outcomes, built from the ports Studio creates first for the companion it
|
|
142
|
+
* serves; from the environment in factory mode when absent.
|
|
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;
|
|
111
149
|
}
|
|
112
150
|
|
|
113
151
|
export interface StudioServerOptions {
|
|
@@ -127,45 +165,23 @@ export interface StudioServerOptions {
|
|
|
127
165
|
idleTimeout?: number;
|
|
128
166
|
/** Terminal launches skip companion Git synchronization. */
|
|
129
167
|
noGit?: boolean;
|
|
168
|
+
/** Which Studio modes are enabled; `standard` when absent. Never read from a request. */
|
|
169
|
+
profile?: StudioProfile;
|
|
170
|
+
/** Studio's built application, loaded by the studio command. */
|
|
171
|
+
app?: StudioApp | null;
|
|
130
172
|
}
|
|
131
173
|
|
|
132
|
-
/**
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
async function renderVaultView(page: StudioPage): Promise<string> {
|
|
142
|
-
const views = await import("./views/document");
|
|
143
|
-
return views.renderVaultView(page);
|
|
144
|
-
}
|
|
174
|
+
/** Answered to a document request when no Studio build is installed; carries no companion data. */
|
|
175
|
+
const MISSING_BUILD_PAGE = `<!doctype html>
|
|
176
|
+
<html lang="en">
|
|
177
|
+
<head><meta charset="utf-8"><title>Mate Studio</title></head>
|
|
178
|
+
<body><p>Studio's application build is missing. Run <code>bun run build</code> in <code>packages/mate-studio</code>, then reload.</p></body>
|
|
179
|
+
</html>
|
|
180
|
+
`;
|
|
145
181
|
|
|
146
|
-
|
|
147
|
-
const views = await import("./views/document");
|
|
148
|
-
return views.renderVaultChildren(page);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
async function renderVaultMatches(page: StudioPage, query: string): Promise<string> {
|
|
152
|
-
const views = await import("./views/document");
|
|
153
|
-
return views.renderVaultMatches(page, query);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/** Keep the CLI entry free of eager Studio view imports. */
|
|
157
|
-
async function collectVaultState(
|
|
158
|
-
vault: VaultManager,
|
|
159
|
-
companionPath: string,
|
|
160
|
-
selection: StudioVaultSelection,
|
|
161
|
-
options: { tree: "prefetch" | "await" },
|
|
162
|
-
): Promise<StudioVaultPage> {
|
|
163
|
-
const { vaultState } = await import("./views/vault/state");
|
|
164
|
-
return vaultState(vault, companionPath, selection, options);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
function html(body: string): Response {
|
|
182
|
+
function html(body: string, status = 200): Response {
|
|
168
183
|
return new Response(body, {
|
|
184
|
+
status,
|
|
169
185
|
headers: { "content-type": "text/html; charset=utf-8", "cache-control": "no-store" },
|
|
170
186
|
});
|
|
171
187
|
}
|
|
@@ -179,6 +195,59 @@ const TOKEN_REQUIRED_PAGE = `<!doctype html>
|
|
|
179
195
|
If the token was pinned with <code>--token</code> or <code>MATE_STUDIO_TOKEN</code>,
|
|
180
196
|
open this address with <code>?token=</code> followed by that value.</p></main></body></html>`;
|
|
181
197
|
|
|
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
|
+
/**
|
|
202
|
+
* What a route is, for its guard. A read needs the token where the invocation requires it
|
|
203
|
+
* for reading; a write also needs the same origin, the token for saving and, when it names
|
|
204
|
+
* a reason, the write path; a terminal call needs the token for the terminal and, when
|
|
205
|
+
* privileged, the same origin; a session call is checked by its own bearer credential only.
|
|
206
|
+
*/
|
|
207
|
+
type RouteKind =
|
|
208
|
+
| { kind: "read"; methods: readonly string[] }
|
|
209
|
+
| { kind: "write"; methods: readonly string[]; writable?: string }
|
|
210
|
+
| { kind: "terminal"; methods: readonly string[]; privileged: boolean }
|
|
211
|
+
| { kind: "session"; methods: readonly string[] };
|
|
212
|
+
|
|
213
|
+
const ORIGIN_REASON = {
|
|
214
|
+
write: "a change must come from Studio's own page",
|
|
215
|
+
terminal: "the terminal is reachable only from Studio's own page",
|
|
216
|
+
} as const;
|
|
217
|
+
|
|
218
|
+
const READS = ["GET", "HEAD"] as const;
|
|
219
|
+
|
|
220
|
+
/** Every route core answers, by kind; the rest are reads the application answers. */
|
|
221
|
+
function routeOf(url: URL, method: string, hasApp: boolean): RouteKind {
|
|
222
|
+
const { pathname } = url;
|
|
223
|
+
if (pathname === REPORTS_ROUTE && method === "POST")
|
|
224
|
+
return { kind: "session", methods: ["POST"] };
|
|
225
|
+
if (pathname === FACTORY_CREDENTIAL_ROUTE) {
|
|
226
|
+
return method === "GET" || method === "HEAD"
|
|
227
|
+
? { kind: "read", methods: [method] }
|
|
228
|
+
: {
|
|
229
|
+
kind: "write",
|
|
230
|
+
methods: [method],
|
|
231
|
+
writable: "start Studio with --writable to set the agent credential",
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
if (pathname === TERMINAL_SOCKET_ROUTE) {
|
|
235
|
+
return { kind: "terminal", methods: READS, privileged: true };
|
|
236
|
+
}
|
|
237
|
+
if (pathname === TERMINAL_SESSIONS_END_ROUTE) {
|
|
238
|
+
return { kind: "terminal", methods: ["POST"], privileged: true };
|
|
239
|
+
}
|
|
240
|
+
if (pathname.startsWith(`${TERMINAL_SOCKET_ROUTE}/`)) {
|
|
241
|
+
return { kind: "terminal", methods: READS, privileged: false };
|
|
242
|
+
}
|
|
243
|
+
// A server function is a read when called with GET and a write when called with POST; the
|
|
244
|
+
// write path for its changes is checked by the services it calls.
|
|
245
|
+
if (hasApp && pathname.startsWith(STUDIO_APP_CALL_PREFIX) && method === "POST") {
|
|
246
|
+
return { kind: "write", methods: ["POST"] };
|
|
247
|
+
}
|
|
248
|
+
return { kind: "read", methods: READS };
|
|
249
|
+
}
|
|
250
|
+
|
|
182
251
|
function refused(reason: string, status: number): Response {
|
|
183
252
|
return new Response(JSON.stringify({ reason }), {
|
|
184
253
|
status,
|
|
@@ -204,14 +273,10 @@ const REPORT_CSP = [
|
|
|
204
273
|
"connect-src 'none'",
|
|
205
274
|
].join("; ");
|
|
206
275
|
|
|
207
|
-
/**
|
|
208
|
-
interface
|
|
209
|
-
type: "report-published";
|
|
210
|
-
/** Digest of the companion the report belongs to. */
|
|
211
|
-
companion: string;
|
|
276
|
+
/** A published report as open pages are told of it; carries no path and no content. */
|
|
277
|
+
interface PublishedReport {
|
|
212
278
|
id: string;
|
|
213
279
|
title: string;
|
|
214
|
-
createdAt: number;
|
|
215
280
|
}
|
|
216
281
|
|
|
217
282
|
/**
|
|
@@ -244,9 +309,17 @@ async function readCapped(request: Request, limit: number): Promise<string | nul
|
|
|
244
309
|
return over ? null : Buffer.concat(chunks).toString("utf8");
|
|
245
310
|
}
|
|
246
311
|
|
|
312
|
+
const NOT_WRITABLE = "start Studio with --writable to create or start Worksets";
|
|
313
|
+
|
|
247
314
|
const TOKEN_REASON =
|
|
248
315
|
"Studio's access token is required; open the address Studio printed when it started";
|
|
249
316
|
|
|
317
|
+
const NO_COMPANION = "no registered companion was selected";
|
|
318
|
+
|
|
319
|
+
function notFound(): Response {
|
|
320
|
+
return new Response("not found", { status: 404 });
|
|
321
|
+
}
|
|
322
|
+
|
|
250
323
|
function json(value: unknown, status = 200): Response {
|
|
251
324
|
return new Response(JSON.stringify(value), {
|
|
252
325
|
status,
|
|
@@ -257,12 +330,13 @@ function json(value: unknown, status = 200): Response {
|
|
|
257
330
|
interface StudioFetch {
|
|
258
331
|
(request: Request, server?: StudioUpgrader): Promise<Response | undefined>;
|
|
259
332
|
terminal: TerminalRegistry | null;
|
|
333
|
+
services: StudioServices;
|
|
260
334
|
close(): Promise<void>;
|
|
261
335
|
}
|
|
262
336
|
|
|
263
337
|
export interface StudioFetchOptions extends Pick<
|
|
264
338
|
StudioServerOptions,
|
|
265
|
-
"writable" | "launchCompanion" | "noGit" | "detachMinutes"
|
|
339
|
+
"writable" | "launchCompanion" | "noGit" | "detachMinutes" | "profile"
|
|
266
340
|
> {
|
|
267
341
|
access?: StudioAccess;
|
|
268
342
|
/** Loopback origin the terminal's processes publish to; read at spawn. */
|
|
@@ -271,6 +345,8 @@ export interface StudioFetchOptions extends Pick<
|
|
|
271
345
|
publicOrigin?: string | null;
|
|
272
346
|
/** Enables the terminal; the invocation sets its default detach window. */
|
|
273
347
|
terminal?: boolean;
|
|
348
|
+
/** Studio's built application; paths the handler does not serve itself go to it. */
|
|
349
|
+
app?: StudioApp | null;
|
|
274
350
|
}
|
|
275
351
|
|
|
276
352
|
/**
|
|
@@ -288,11 +364,42 @@ export function createStudioFetch(
|
|
|
288
364
|
): StudioFetch {
|
|
289
365
|
const inventory = deps.collectStudioInventory ?? collectStudioInventory;
|
|
290
366
|
const companion = deps.assembleCompanionPayload ?? assembleCompanionPayload;
|
|
291
|
-
const render = deps.renderDocument ?? renderStudioDocument;
|
|
292
367
|
const snapshots =
|
|
293
368
|
deps.snapshots ?? createStudioSnapshotCache({ assembleCompanionPayload: companion });
|
|
294
369
|
const vault = deps.vault ?? createVaultManager();
|
|
295
370
|
const writable = options.writable === true;
|
|
371
|
+
const policy = modePolicy(options.profile ?? "standard");
|
|
372
|
+
const broker = deps.factoryClient !== undefined ? deps.factoryClient : factoryClient();
|
|
373
|
+
const reports = deps.reports ?? createReportStore();
|
|
374
|
+
const stagesOf = deps.worksetStages ?? ((path: string) => readCompanionWorksetStages(path));
|
|
375
|
+
// Created before the terminal and the Outcomes, so neither needs the other.
|
|
376
|
+
const sessions = new LiveSessions();
|
|
377
|
+
const launchCompanion = options.launchCompanion ?? null;
|
|
378
|
+
const outcomesPorts = (companionPath: string): OutcomesPorts => ({
|
|
379
|
+
stages: () => stagesOf(companionPath),
|
|
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));
|
|
296
403
|
const access =
|
|
297
404
|
options.access ??
|
|
298
405
|
createStudioAccess({
|
|
@@ -301,11 +408,9 @@ export function createStudioFetch(
|
|
|
301
408
|
hostname: STUDIO_HOSTNAME,
|
|
302
409
|
port: () => 80,
|
|
303
410
|
});
|
|
304
|
-
const reports = deps.reports ?? createReportStore();
|
|
305
411
|
void reports.cleanup().catch(() => {});
|
|
306
412
|
const publicOrigin = options.publicOrigin ? normalizeOrigin(options.publicOrigin) : null;
|
|
307
|
-
const reportListeners = new Map<string, Set<(event:
|
|
308
|
-
const launchCompanion = options.launchCompanion ?? null;
|
|
413
|
+
const reportListeners = new Map<string, Set<(event: PublishedReport) => void>>();
|
|
309
414
|
const agentsFor = deps.launchableAgents ?? launchableAgents;
|
|
310
415
|
const terminal = options.terminal
|
|
311
416
|
? new TerminalRegistry({
|
|
@@ -316,12 +421,25 @@ export function createStudioFetch(
|
|
|
316
421
|
launchableAgents: (companionPath) => agentsFor(companionPath),
|
|
317
422
|
}),
|
|
318
423
|
mateCommand: process.argv.slice(0, 2),
|
|
424
|
+
sessions,
|
|
425
|
+
...(process.env[FACTORY_BROKER_ENV]
|
|
426
|
+
? {
|
|
427
|
+
resolveWorkset: createWorksetResolver({
|
|
428
|
+
collectInventory: inventory,
|
|
429
|
+
launchCompanion,
|
|
430
|
+
mateCommand: process.argv.slice(0, 2),
|
|
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
|
+
: {}),
|
|
319
438
|
noGit: options.noGit === true,
|
|
320
439
|
reportUrl: options.reportOrigin,
|
|
321
440
|
...deps.terminal,
|
|
322
441
|
})
|
|
323
442
|
: null;
|
|
324
|
-
|
|
325
443
|
/** Stores a report for the live terminal session holding the bearer credential. */
|
|
326
444
|
const publishReport = async (request: Request): Promise<Response> => {
|
|
327
445
|
const token = readBearer(request);
|
|
@@ -350,13 +468,7 @@ export function createStudioFetch(
|
|
|
350
468
|
html: body.html,
|
|
351
469
|
});
|
|
352
470
|
for (const notify of reportListeners.get(digest) ?? []) {
|
|
353
|
-
notify({
|
|
354
|
-
type: "report-published",
|
|
355
|
-
companion: digest,
|
|
356
|
-
id: stored.id,
|
|
357
|
-
title: stored.title,
|
|
358
|
-
createdAt: stored.createdAt,
|
|
359
|
-
});
|
|
471
|
+
notify({ id: stored.id, title: stored.title });
|
|
360
472
|
}
|
|
361
473
|
const path = `${REPORT_VIEW_PREFIX}${stored.id}`;
|
|
362
474
|
return json({
|
|
@@ -366,6 +478,121 @@ export function createStudioFetch(
|
|
|
366
478
|
});
|
|
367
479
|
};
|
|
368
480
|
|
|
481
|
+
/** One document's model, with the factory, report and terminal state its address needs. */
|
|
482
|
+
const collectPage = async (url: URL): Promise<StudioPage> => {
|
|
483
|
+
const page = await collectStudioPage(url, policy, inventory, snapshots, vault, writable);
|
|
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
|
+
}
|
|
490
|
+
page.renderedAt = Date.now();
|
|
491
|
+
page.factoryRuns = page.companion ? await outcomesFor(page.companion.path).runs() : null;
|
|
492
|
+
if (terminal) {
|
|
493
|
+
const target = await effectiveLaunchCompanion(
|
|
494
|
+
page.inventory,
|
|
495
|
+
launchCompanion,
|
|
496
|
+
page.selection.companionDigest,
|
|
497
|
+
);
|
|
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
|
+
page.terminal = {
|
|
506
|
+
pinned: launchCompanion !== null,
|
|
507
|
+
target: target ? { path: target.path, digest: companionDigest(target.path) } : null,
|
|
508
|
+
agents: target ? await agentsFor(target.path) : [],
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
return page;
|
|
512
|
+
};
|
|
513
|
+
|
|
514
|
+
/** A registered companion by digest, or a refusal the caller reports. */
|
|
515
|
+
const companionPathOf = async (digest: string): Promise<string> => {
|
|
516
|
+
const selected = await selectedCompanion(digest || null, inventory);
|
|
517
|
+
if (!selected) throw new WorksetError(NO_COMPANION);
|
|
518
|
+
return selected.path;
|
|
519
|
+
};
|
|
520
|
+
|
|
521
|
+
/** Viewers of a companion's board, by digest; told when an Outcome or run changes. */
|
|
522
|
+
const boardListeners = new Map<string, Set<() => void>>();
|
|
523
|
+
const boardChanged = (digest: string) => {
|
|
524
|
+
for (const notify of boardListeners.get(digest) ?? []) notify();
|
|
525
|
+
};
|
|
526
|
+
if (outcomes) {
|
|
527
|
+
const digest = companionDigest(outcomes.companionPath);
|
|
528
|
+
outcomes.onChanged(() => boardChanged(digest));
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
const services: StudioServices = {
|
|
532
|
+
writable,
|
|
533
|
+
factoryMode: broker !== null,
|
|
534
|
+
modePolicy: policy,
|
|
535
|
+
page: collectPage,
|
|
536
|
+
worksetAction: async (digest, id, action, field: StudioFormField) => {
|
|
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
|
+
},
|
|
546
|
+
vault: async (digest, request) => {
|
|
547
|
+
const { vaultView } = await import("./views/vault/view");
|
|
548
|
+
return vaultView(vault, await companionPathOf(digest), request);
|
|
549
|
+
},
|
|
550
|
+
vaultChildren: async (digest, dir) => {
|
|
551
|
+
const { vaultChildren } = await import("./views/vault/view");
|
|
552
|
+
return vaultChildren(vault, await companionPathOf(digest), dir);
|
|
553
|
+
},
|
|
554
|
+
vaultMatches: async (digest, query) => {
|
|
555
|
+
const { vaultMatches } = await import("./views/vault/view");
|
|
556
|
+
return vaultMatches(vault, await companionPathOf(digest), query);
|
|
557
|
+
},
|
|
558
|
+
vaultSave: async (digest, path, content, token) => {
|
|
559
|
+
if (!writable) throw new VaultPathError("start Studio with --writable to enable saving");
|
|
560
|
+
return vault.save(await companionPathOf(digest), path, content, token);
|
|
561
|
+
},
|
|
562
|
+
};
|
|
563
|
+
const app = options.app ?? null;
|
|
564
|
+
|
|
565
|
+
/** The route's refusal under its kind, decided once before it acts (design D4); `null` lets it act. */
|
|
566
|
+
const refusalFor = (
|
|
567
|
+
route: Exclude<RouteKind, { kind: "session" }>,
|
|
568
|
+
request: Request,
|
|
569
|
+
url: URL,
|
|
570
|
+
acceptedOrigin: string,
|
|
571
|
+
): Response | null => {
|
|
572
|
+
if (access.requires("read") && !access.hasToken(request)) {
|
|
573
|
+
if (url.pathname !== "/") return refused(TOKEN_REASON, 401);
|
|
574
|
+
return html(TOKEN_REQUIRED_PAGE, 401);
|
|
575
|
+
}
|
|
576
|
+
if (route.kind === "read") return null;
|
|
577
|
+
if (route.kind === "terminal" && !terminal) {
|
|
578
|
+
return refused("start Studio with --writable --terminal to enable the terminal", 404);
|
|
579
|
+
}
|
|
580
|
+
const privileged = route.kind === "write" || route.privileged;
|
|
581
|
+
if (privileged && !access.originMatches(request, acceptedOrigin)) {
|
|
582
|
+
return refused(ORIGIN_REASON[route.kind], 403);
|
|
583
|
+
}
|
|
584
|
+
if (
|
|
585
|
+
access.requires(route.kind === "write" ? "save" : "terminal") &&
|
|
586
|
+
!access.hasToken(request)
|
|
587
|
+
) {
|
|
588
|
+
return refused(TOKEN_REASON, 401);
|
|
589
|
+
}
|
|
590
|
+
if (route.kind === "write" && route.writable && !writable) {
|
|
591
|
+
return refused(route.writable, 403);
|
|
592
|
+
}
|
|
593
|
+
return null;
|
|
594
|
+
};
|
|
595
|
+
|
|
369
596
|
const handler = async (
|
|
370
597
|
request: Request,
|
|
371
598
|
server?: StudioUpgrader,
|
|
@@ -377,23 +604,11 @@ export function createStudioFetch(
|
|
|
377
604
|
const exchanged = exchangeStudioToken(request, access, acceptedOrigin);
|
|
378
605
|
if (exchanged) return exchanged;
|
|
379
606
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
const isSave = url.pathname === "/api/vault/save";
|
|
385
|
-
const isEnd = url.pathname === "/api/terminal/sessions/end";
|
|
386
|
-
const isPost = isSave || isEnd;
|
|
387
|
-
if (isPost && request.method !== "POST") {
|
|
388
|
-
return new Response(`${isSave ? "vault save" : "ending a session"} requires POST`, {
|
|
389
|
-
status: 405,
|
|
390
|
-
headers: { allow: "POST" },
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
if (!READ_METHODS.has(request.method) && !(isPost && request.method === "POST")) {
|
|
394
|
-
return new Response("studio serves read requests only", {
|
|
607
|
+
const route = routeOf(url, request.method, app !== null);
|
|
608
|
+
if (!route.methods.includes(request.method)) {
|
|
609
|
+
return new Response(`${request.method} is not served here`, {
|
|
395
610
|
status: 405,
|
|
396
|
-
headers: { allow:
|
|
611
|
+
headers: { allow: route.methods.join(", ") },
|
|
397
612
|
});
|
|
398
613
|
}
|
|
399
614
|
|
|
@@ -402,18 +617,14 @@ export function createStudioFetch(
|
|
|
402
617
|
? new Response(null, { status: response.status, headers: response.headers })
|
|
403
618
|
: response;
|
|
404
619
|
|
|
405
|
-
if (
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
return respond(new Response(page.body, { status: 401, headers: page.headers }));
|
|
409
|
-
}
|
|
410
|
-
return respond(refused(TOKEN_REASON, 401));
|
|
411
|
-
}
|
|
620
|
+
if (route.kind === "session") return publishReport(request);
|
|
621
|
+
const refusal = refusalFor(route, request, url, acceptedOrigin);
|
|
622
|
+
if (refusal) return respond(refusal);
|
|
412
623
|
|
|
413
624
|
if (url.pathname === REPORTS_ROUTE) {
|
|
414
625
|
const digest = url.searchParams.get(COMPANION_PARAM) ?? "";
|
|
415
626
|
if (!COMPANION_DIGEST_PATTERN.test(digest)) {
|
|
416
|
-
return respond(json({ reason:
|
|
627
|
+
return respond(json({ reason: NO_COMPANION }, 400));
|
|
417
628
|
}
|
|
418
629
|
return respond(json({ reports: await reports.list(digest) }));
|
|
419
630
|
}
|
|
@@ -421,7 +632,7 @@ export function createStudioFetch(
|
|
|
421
632
|
if (url.pathname.startsWith(REPORT_VIEW_PREFIX)) {
|
|
422
633
|
const id = url.pathname.slice(REPORT_VIEW_PREFIX.length);
|
|
423
634
|
const stored = isReportId(id) ? await reports.read(id) : null;
|
|
424
|
-
if (stored === null) return respond(
|
|
635
|
+
if (stored === null) return respond(notFound());
|
|
425
636
|
return respond(
|
|
426
637
|
new Response(stored, {
|
|
427
638
|
headers: {
|
|
@@ -435,32 +646,31 @@ export function createStudioFetch(
|
|
|
435
646
|
);
|
|
436
647
|
}
|
|
437
648
|
|
|
438
|
-
if (url.pathname
|
|
439
|
-
|
|
649
|
+
if (url.pathname === FACTORY_CREDENTIAL_ROUTE) {
|
|
650
|
+
if (broker === null) return respond(notFound());
|
|
651
|
+
return respond(await factoryCredentialResponse(broker, request));
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
if (app) {
|
|
655
|
+
const asset = await studioAppAsset(app, url.pathname);
|
|
440
656
|
if (asset) return respond(asset);
|
|
441
657
|
}
|
|
442
658
|
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
if (
|
|
451
|
-
return respond(refused("the terminal is reachable only from Studio's own page", 403));
|
|
452
|
-
}
|
|
453
|
-
if (access.requires("terminal") && !access.hasToken(request)) {
|
|
454
|
-
return respond(refused(TOKEN_REASON, 401));
|
|
455
|
-
}
|
|
456
|
-
if (url.pathname === "/api/terminal") {
|
|
659
|
+
// The terminal's asset prefix is core's own, with or without the terminal.
|
|
660
|
+
if (url.pathname.startsWith(TERMINAL_ASSET_PREFIX)) {
|
|
661
|
+
const asset = terminal ? await terminalAsset(url.pathname) : null;
|
|
662
|
+
return respond(asset ?? notFound());
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
if (route.kind === "terminal" && terminal) {
|
|
666
|
+
if (url.pathname === TERMINAL_SOCKET_ROUTE) {
|
|
457
667
|
if (request.headers.get("upgrade")?.toLowerCase() !== "websocket" || !server) {
|
|
458
668
|
return respond(refused("the terminal is a WebSocket endpoint", 426));
|
|
459
669
|
}
|
|
460
670
|
if (server.upgrade(request, { data: {} })) return undefined;
|
|
461
671
|
return respond(refused("the terminal connection could not be upgraded", 400));
|
|
462
672
|
}
|
|
463
|
-
if (url.pathname ===
|
|
673
|
+
if (url.pathname === TERMINAL_SESSIONS_ROUTE) {
|
|
464
674
|
const now = Date.now();
|
|
465
675
|
return respond(
|
|
466
676
|
json({
|
|
@@ -470,12 +680,13 @@ export function createStudioFetch(
|
|
|
470
680
|
companion: companionDigest(session.companionPath),
|
|
471
681
|
companionPath: session.companionPath,
|
|
472
682
|
attached: session.attached,
|
|
683
|
+
...(session.workset ? { workset: session.workset } : {}),
|
|
473
684
|
ageSeconds: Math.max(0, Math.round((now - session.startedAt) / 1000)),
|
|
474
685
|
})),
|
|
475
686
|
}),
|
|
476
687
|
);
|
|
477
688
|
}
|
|
478
|
-
if (
|
|
689
|
+
if (url.pathname === TERMINAL_SESSIONS_END_ROUTE) {
|
|
479
690
|
let body: { id?: unknown };
|
|
480
691
|
try {
|
|
481
692
|
body = (await request.json()) as typeof body;
|
|
@@ -487,198 +698,50 @@ export function createStudioFetch(
|
|
|
487
698
|
}
|
|
488
699
|
return respond(json({ ended: body.id }));
|
|
489
700
|
}
|
|
490
|
-
return respond(
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
if (url.pathname === "/api/vault/tree") {
|
|
494
|
-
const selection = parseVaultSelection(url);
|
|
495
|
-
const selected = await selectedCompanion(selection.companionDigest, inventory);
|
|
496
|
-
if (!selected) return respond(json({ reason: "no registered companion was selected" }, 400));
|
|
497
|
-
try {
|
|
498
|
-
return respond(json(await vault.tree(selected.path, selection.refresh)));
|
|
499
|
-
} catch (error) {
|
|
500
|
-
return respond(
|
|
501
|
-
json({ reason: error instanceof Error ? error.message : String(error) }, 400),
|
|
502
|
-
);
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
if (url.pathname === "/api/vault/view") {
|
|
507
|
-
const collected = await inventory();
|
|
508
|
-
const selection = parseVaultSelection(url);
|
|
509
|
-
const companion = resolveCompanion(collected, selection.companionDigest);
|
|
510
|
-
if (!companion) return respond(json({ reason: "no registered companion was selected" }, 400));
|
|
511
|
-
const state = await collectVaultState(vault, companion.path, selection, { tree: "await" });
|
|
512
|
-
return respond(
|
|
513
|
-
new Response(
|
|
514
|
-
await renderVaultView({
|
|
515
|
-
inventory: collected,
|
|
516
|
-
selection,
|
|
517
|
-
companion,
|
|
518
|
-
payload: null,
|
|
519
|
-
error: null,
|
|
520
|
-
collectedAt: null,
|
|
521
|
-
writable,
|
|
522
|
-
vault: state,
|
|
523
|
-
terminal: null,
|
|
524
|
-
}),
|
|
525
|
-
{ headers: { "content-type": "text/html; charset=utf-8", "cache-control": "no-store" } },
|
|
526
|
-
),
|
|
527
|
-
);
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
if (url.pathname === VAULT_DIR_ROUTE || url.pathname === VAULT_FILTER_ROUTE) {
|
|
531
|
-
const selection = parseVaultSelection(url);
|
|
532
|
-
const selected = await selectedCompanion(selection.companionDigest, inventory);
|
|
533
|
-
if (!selected) return respond(json({ reason: "no registered companion was selected" }, 400));
|
|
534
|
-
let listed;
|
|
535
|
-
try {
|
|
536
|
-
listed = await vault.tree(selected.path);
|
|
537
|
-
} catch (error) {
|
|
538
|
-
return respond(
|
|
539
|
-
json({ reason: error instanceof Error ? error.message : String(error) }, 400),
|
|
540
|
-
);
|
|
541
|
-
}
|
|
542
|
-
const page: StudioPage = {
|
|
543
|
-
inventory: await inventory(),
|
|
544
|
-
selection,
|
|
545
|
-
companion: selected,
|
|
546
|
-
payload: null,
|
|
547
|
-
error: null,
|
|
548
|
-
collectedAt: null,
|
|
549
|
-
writable,
|
|
550
|
-
vault: {
|
|
551
|
-
tree: listed.tree,
|
|
552
|
-
open: null,
|
|
553
|
-
refusal: null,
|
|
554
|
-
incoming: null,
|
|
555
|
-
overwritten: null,
|
|
556
|
-
watching: listed.watching,
|
|
557
|
-
warning: listed.warning,
|
|
558
|
-
generation: listed.generation,
|
|
559
|
-
},
|
|
560
|
-
terminal: null,
|
|
561
|
-
};
|
|
562
|
-
const headers = {
|
|
563
|
-
"content-type": "text/html; charset=utf-8",
|
|
564
|
-
"cache-control": "no-store",
|
|
565
|
-
"x-vault-generation": String(listed.generation),
|
|
566
|
-
};
|
|
567
|
-
if (url.pathname === VAULT_FILTER_ROUTE) {
|
|
568
|
-
const matches = await renderVaultMatches(page, url.searchParams.get("q") ?? "");
|
|
569
|
-
return respond(new Response(matches, { headers }));
|
|
570
|
-
}
|
|
571
|
-
const children = await renderVaultChildren(page);
|
|
572
|
-
if (children === null) {
|
|
573
|
-
return respond(json({ reason: "that folder is not in the listed tree" }, 404));
|
|
574
|
-
}
|
|
575
|
-
return respond(new Response(children, { headers }));
|
|
701
|
+
return respond(notFound());
|
|
576
702
|
}
|
|
577
703
|
|
|
578
|
-
if (url.pathname ===
|
|
579
|
-
const
|
|
580
|
-
const selected = await selectedCompanion(
|
|
581
|
-
if (!selected) return respond(json({ reason:
|
|
704
|
+
if (url.pathname === STUDIO_EVENTS_ROUTE) {
|
|
705
|
+
const digest = url.searchParams.get(COMPANION_PARAM) ?? "";
|
|
706
|
+
const selected = await selectedCompanion(digest || null, inventory);
|
|
707
|
+
if (!selected) return respond(json({ reason: NO_COMPANION }, 400));
|
|
582
708
|
server?.timeout?.(request, 0);
|
|
583
|
-
|
|
584
|
-
return respond(
|
|
585
|
-
changeStream(vault, selected.path, reportsOnly, (notify) => {
|
|
586
|
-
const digest = companionDigest(selected.path);
|
|
587
|
-
const set = reportListeners.get(digest) ?? new Set();
|
|
588
|
-
set.add(notify);
|
|
589
|
-
reportListeners.set(digest, set);
|
|
590
|
-
return () => {
|
|
591
|
-
set.delete(notify);
|
|
592
|
-
if (set.size === 0) reportListeners.delete(digest);
|
|
593
|
-
};
|
|
594
|
-
}),
|
|
595
|
-
);
|
|
709
|
+
return respond(studioEvents(vault, selected.path, boardListeners, reportListeners));
|
|
596
710
|
}
|
|
597
711
|
|
|
598
|
-
if (url.pathname ===
|
|
599
|
-
const selection = parseVaultSelection(url);
|
|
712
|
+
if (url.pathname === VAULT_EVENTS_ROUTE) {
|
|
713
|
+
const selection = parseVaultSelection(url, policy);
|
|
600
714
|
const selected = await selectedCompanion(selection.companionDigest, inventory);
|
|
601
|
-
if (!selected) return respond(json({ reason:
|
|
602
|
-
try {
|
|
603
|
-
return respond(json(await vault.open(selected.path, selection.openPath ?? "")));
|
|
604
|
-
} catch (error) {
|
|
605
|
-
return respond(
|
|
606
|
-
json({ reason: error instanceof Error ? error.message : String(error) }, 400),
|
|
607
|
-
);
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
if (url.pathname === "/api/vault/events") {
|
|
612
|
-
const selection = parseVaultSelection(url);
|
|
613
|
-
const selected = await selectedCompanion(selection.companionDigest, inventory);
|
|
614
|
-
if (!selected) return respond(json({ reason: "no registered companion was selected" }, 400));
|
|
715
|
+
if (!selected) return respond(json({ reason: NO_COMPANION }, 400));
|
|
615
716
|
try {
|
|
616
717
|
const opened = await resolveVaultPath(selected.path, selection.openPath ?? "");
|
|
617
718
|
server?.timeout?.(request, 0);
|
|
618
719
|
return respond(vaultEvents(vault, selected.path, opened.relative));
|
|
619
720
|
} catch (error) {
|
|
620
|
-
return respond(
|
|
621
|
-
json({ reason: error instanceof Error ? error.message : String(error) }, 400),
|
|
622
|
-
);
|
|
721
|
+
return respond(json({ reason: errorMessage(error) }, 400));
|
|
623
722
|
}
|
|
624
723
|
}
|
|
625
724
|
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
if (
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
let body: { companion?: string; path?: string; content?: string; token?: string };
|
|
636
|
-
try {
|
|
637
|
-
body = (await request.json()) as typeof body;
|
|
638
|
-
} catch {
|
|
639
|
-
return respond(json({ reason: "save requires a JSON body" }, 400));
|
|
640
|
-
}
|
|
641
|
-
const selected = await selectedCompanion(
|
|
642
|
-
typeof body.companion === "string" ? body.companion : null,
|
|
643
|
-
inventory,
|
|
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
|
+
}),
|
|
644
734
|
);
|
|
645
|
-
if (!selected || typeof body.path !== "string" || typeof body.content !== "string") {
|
|
646
|
-
return respond(
|
|
647
|
-
json({ reason: "save requires a registered companion, path, and content" }, 400),
|
|
648
|
-
);
|
|
649
|
-
}
|
|
650
|
-
try {
|
|
651
|
-
const result = await vault.save(selected.path, body.path, body.content, body.token);
|
|
652
|
-
return respond(json(result, result.kind === "conflict" ? 409 : 200));
|
|
653
|
-
} catch (error) {
|
|
654
|
-
return respond(
|
|
655
|
-
json(
|
|
656
|
-
{ reason: error instanceof Error ? error.message : String(error) },
|
|
657
|
-
error instanceof VaultPathError ? 400 : 500,
|
|
658
|
-
),
|
|
659
|
-
);
|
|
660
|
-
}
|
|
661
735
|
}
|
|
662
736
|
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
const target = await effectiveLaunchCompanion(
|
|
668
|
-
page.inventory,
|
|
669
|
-
launchCompanion,
|
|
670
|
-
page.selection.companionDigest,
|
|
671
|
-
);
|
|
672
|
-
page.terminal = {
|
|
673
|
-
pinned: launchCompanion !== null,
|
|
674
|
-
target: target ? { path: target.path, digest: companionDigest(target.path) } : null,
|
|
675
|
-
agents: target ? await agentsFor(target.path) : [],
|
|
676
|
-
};
|
|
677
|
-
}
|
|
678
|
-
return respond(html(await render(page)));
|
|
737
|
+
// Everything else is the application's: its documents, views and server functions.
|
|
738
|
+
if (app) return respond(await app.fetch(request, { context: { studio: services } }));
|
|
739
|
+
if (url.pathname === "/") return respond(html(MISSING_BUILD_PAGE));
|
|
740
|
+
return respond(notFound());
|
|
679
741
|
};
|
|
680
742
|
|
|
681
743
|
handler.terminal = terminal;
|
|
744
|
+
handler.services = services;
|
|
682
745
|
handler.close = async () => {
|
|
683
746
|
vault.stop();
|
|
684
747
|
await terminal?.stopAll();
|
|
@@ -724,49 +787,79 @@ function eventStream(
|
|
|
724
787
|
});
|
|
725
788
|
}
|
|
726
789
|
|
|
727
|
-
function vaultEvents(vault: VaultManager, companionPath: string, requestedPath: string): Response {
|
|
728
|
-
return eventStream("studio vault events", (send) =>
|
|
729
|
-
vault.subscribe(companionPath, requestedPath, send),
|
|
730
|
-
);
|
|
731
|
-
}
|
|
732
|
-
|
|
733
790
|
/**
|
|
734
|
-
*
|
|
735
|
-
*
|
|
736
|
-
* `reportsOnly` skips the vault subscription, which starts a watcher and listing.
|
|
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.
|
|
737
793
|
*/
|
|
738
|
-
function
|
|
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
|
+
/** One stream per page, so a view updates in place instead of reloading (design D7). */
|
|
807
|
+
function studioEvents(
|
|
739
808
|
vault: VaultManager,
|
|
740
809
|
companionPath: string,
|
|
741
|
-
|
|
742
|
-
|
|
810
|
+
boards: Map<string, Set<() => void>>,
|
|
811
|
+
reports: Map<string, Set<(event: PublishedReport) => void>>,
|
|
743
812
|
): Response {
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
const
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
813
|
+
const digest = companionDigest(companionPath);
|
|
814
|
+
const join = <T>(map: Map<string, Set<T>>, listener: T) => {
|
|
815
|
+
const set = map.get(digest) ?? new Set<T>();
|
|
816
|
+
set.add(listener);
|
|
817
|
+
map.set(digest, set);
|
|
818
|
+
return () => {
|
|
819
|
+
set.delete(listener);
|
|
820
|
+
if (set.size === 0) map.delete(digest);
|
|
821
|
+
};
|
|
822
|
+
};
|
|
823
|
+
return eventStream("studio events", (send: (event: StudioEvent) => void) => {
|
|
824
|
+
const leaveBoard = join(boards, () => send({ type: "board" }));
|
|
825
|
+
const leaveReports = join(reports, (report) =>
|
|
826
|
+
send({ type: "reports", id: report.id, title: report.title }),
|
|
827
|
+
);
|
|
828
|
+
const stopTree = vault.subscribeTree(companionPath, (generation) =>
|
|
829
|
+
send({ type: "vault-tree", generation }),
|
|
830
|
+
);
|
|
751
831
|
return () => {
|
|
752
|
-
|
|
832
|
+
leaveBoard();
|
|
833
|
+
leaveReports();
|
|
753
834
|
stopTree();
|
|
754
835
|
};
|
|
755
836
|
});
|
|
756
837
|
}
|
|
757
838
|
|
|
839
|
+
function vaultEvents(vault: VaultManager, companionPath: string, requestedPath: string): Response {
|
|
840
|
+
return eventStream("studio vault events", (send) =>
|
|
841
|
+
vault.subscribe(companionPath, requestedPath, send),
|
|
842
|
+
);
|
|
843
|
+
}
|
|
844
|
+
|
|
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
|
+
|
|
758
850
|
/**
|
|
759
851
|
* One rendered document's worth of state. An absent or unresolvable companion
|
|
760
852
|
* is not a failure: the page renders the selector and the server keeps serving.
|
|
761
853
|
*/
|
|
762
854
|
async function collectStudioPage(
|
|
763
855
|
url: URL,
|
|
856
|
+
policy: StudioModePolicy,
|
|
764
857
|
collectInventory: () => Promise<StudioInventory>,
|
|
765
858
|
snapshots: StudioSnapshotCache,
|
|
766
859
|
vault: VaultManager,
|
|
767
860
|
writable: boolean,
|
|
768
861
|
): Promise<StudioPage> {
|
|
769
|
-
const selection = parse(url);
|
|
862
|
+
const selection = parse(url, policy);
|
|
770
863
|
const inventory = await collectInventory();
|
|
771
864
|
const companion = resolveCompanion(inventory, selection.companionDigest);
|
|
772
865
|
const page: StudioPage = {
|
|
@@ -781,19 +874,8 @@ async function collectStudioPage(
|
|
|
781
874
|
terminal: null,
|
|
782
875
|
};
|
|
783
876
|
|
|
784
|
-
if (!companion) {
|
|
785
|
-
vault.deactivate();
|
|
786
|
-
return page;
|
|
787
|
-
}
|
|
788
|
-
|
|
789
|
-
if (selection.view === "vault") {
|
|
790
|
-
return {
|
|
791
|
-
...page,
|
|
792
|
-
vault: await collectVaultState(vault, companion.path, selection, { tree: "prefetch" }),
|
|
793
|
-
};
|
|
794
|
-
}
|
|
795
|
-
|
|
796
877
|
vault.deactivate();
|
|
878
|
+
if (!companion) return page;
|
|
797
879
|
|
|
798
880
|
try {
|
|
799
881
|
const snapshot = await snapshots.read(companion.path, selection.refresh);
|
|
@@ -805,7 +887,7 @@ async function collectStudioPage(
|
|
|
805
887
|
...page,
|
|
806
888
|
error: {
|
|
807
889
|
companionPath: companion.path,
|
|
808
|
-
reason:
|
|
890
|
+
reason: errorMessage(error),
|
|
809
891
|
},
|
|
810
892
|
};
|
|
811
893
|
}
|
|
@@ -826,15 +908,15 @@ function bunServe(options: StudioServeOptions): StudioBoundServer {
|
|
|
826
908
|
return runtime.serve(options);
|
|
827
909
|
}
|
|
828
910
|
|
|
911
|
+
/** An IPv6 literal in brackets, as a URL needs it; any other host as it is. */
|
|
912
|
+
function urlHost(hostname: string): string {
|
|
913
|
+
return hostname.includes(":") && !hostname.startsWith("[") ? `[${hostname}]` : hostname;
|
|
914
|
+
}
|
|
915
|
+
|
|
829
916
|
/** Where a process on this host reaches the server: loopback for wildcard binds. */
|
|
830
917
|
function reportOrigin(hostname: string, port: number): string {
|
|
831
918
|
const wildcard = hostname === "0.0.0.0" || hostname === "::" || hostname === "[::]";
|
|
832
|
-
|
|
833
|
-
? "127.0.0.1"
|
|
834
|
-
: hostname.includes(":") && !hostname.startsWith("[")
|
|
835
|
-
? `[${hostname}]`
|
|
836
|
-
: hostname;
|
|
837
|
-
return `http://${host}:${port}`;
|
|
919
|
+
return `http://${wildcard ? "127.0.0.1" : urlHost(hostname)}:${port}`;
|
|
838
920
|
}
|
|
839
921
|
|
|
840
922
|
/**
|
|
@@ -867,6 +949,8 @@ export function startStudioServer(
|
|
|
867
949
|
detachMinutes: options.detachMinutes,
|
|
868
950
|
launchCompanion: options.launchCompanion,
|
|
869
951
|
noGit: options.noGit,
|
|
952
|
+
profile: options.profile,
|
|
953
|
+
app: options.app,
|
|
870
954
|
});
|
|
871
955
|
const registry = fetchHandler.terminal;
|
|
872
956
|
const server = serve({
|
|
@@ -903,12 +987,8 @@ export function startStudioServer(
|
|
|
903
987
|
: {}),
|
|
904
988
|
});
|
|
905
989
|
boundPort = server.port;
|
|
906
|
-
const
|
|
907
|
-
|
|
908
|
-
? "localhost"
|
|
909
|
-
: hostname.includes(":") && !hostname.startsWith("[")
|
|
910
|
-
? `[${hostname}]`
|
|
911
|
-
: hostname;
|
|
990
|
+
const loopback = hostname === STUDIO_HOSTNAME || hostname === "localhost" || hostname === "::1";
|
|
991
|
+
const urlHostname = loopback ? "localhost" : urlHost(hostname);
|
|
912
992
|
|
|
913
993
|
return {
|
|
914
994
|
url: `http://${urlHostname}:${server.port}`,
|