@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
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
|
|
3
3
|
import type { ClaudeHookGroup } from "./claude-hook-group";
|
|
4
|
+
import { otherServingClaudeWrapRoot } from "./serving-claude-wrap";
|
|
4
5
|
import type { SessionKind } from "./session-kind";
|
|
5
6
|
import { NOT_WRAPPED, readWrapStateSync, type WrapState } from "./wrap-state";
|
|
6
7
|
|
|
@@ -166,7 +167,17 @@ function planChannels(
|
|
|
166
167
|
}
|
|
167
168
|
}
|
|
168
169
|
|
|
169
|
-
/**
|
|
170
|
-
|
|
171
|
-
|
|
170
|
+
/**
|
|
171
|
+
* For session-start hooks: the plan of a plain session in the Checkout at
|
|
172
|
+
* `checkoutRoot`, from a lenient read; no root, not wrapped. Planned from the
|
|
173
|
+
* wrap serving it while that one is wrapped for Claude, else from its own:
|
|
174
|
+
* Claude Code loads both settings files there, and each hook group runs from
|
|
175
|
+
* the one that carries it (design Decisions 1 and 12).
|
|
176
|
+
*/
|
|
177
|
+
export function unmanagedClaudeDelivery(checkoutRoot: string | undefined): ClaudeDeliveryPlan {
|
|
178
|
+
if (!checkoutRoot) return planClaudeDelivery("unmanaged", NOT_WRAPPED);
|
|
179
|
+
const other = otherServingClaudeWrapRoot(checkoutRoot);
|
|
180
|
+
const serving = other ? readWrapStateSync(other) : null;
|
|
181
|
+
const wrap = serving?.runtimes.has("claude") ? serving : readWrapStateSync(checkoutRoot);
|
|
182
|
+
return planClaudeDelivery("unmanaged", wrap);
|
|
172
183
|
}
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* Every write is best-effort. An unwritable record degrades to "a
|
|
12
12
|
* synchronization is due", which is the safe direction.
|
|
13
13
|
*/
|
|
14
|
-
import { createHash } from "node:crypto";
|
|
14
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
15
15
|
import fs from "node:fs";
|
|
16
16
|
import os from "node:os";
|
|
17
17
|
import path from "node:path";
|
|
@@ -30,11 +30,22 @@ export interface CompanionForkRecord {
|
|
|
30
30
|
checkedAt: string;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
/** A change folder this checkout submitted, as it was pushed. */
|
|
34
|
+
export interface SubmittedFolder {
|
|
35
|
+
/** SHA-256 over the folder's relative file paths and contents. */
|
|
36
|
+
digest: string;
|
|
37
|
+
/** The same without the Delivery Record; absent on a record of an earlier Mate. */
|
|
38
|
+
content?: string;
|
|
39
|
+
submittedAt: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
33
42
|
export interface CompanionGitRecord {
|
|
34
43
|
syncedAt?: string;
|
|
35
44
|
/** Set while the last unattended run left work for a human; cleared on completion. */
|
|
36
45
|
unfinishedReason?: string;
|
|
37
46
|
fork?: CompanionForkRecord;
|
|
47
|
+
/** Change folders this checkout submitted, by companion-relative path. */
|
|
48
|
+
submitted?: Record<string, SubmittedFolder>;
|
|
38
49
|
}
|
|
39
50
|
|
|
40
51
|
/** `HOME` first, matching the guard: a projected hook runs with whatever the session set. */
|
|
@@ -73,20 +84,122 @@ export function readCompanionGitRecord(
|
|
|
73
84
|
}
|
|
74
85
|
}
|
|
75
86
|
|
|
76
|
-
/**
|
|
87
|
+
/**
|
|
88
|
+
* Best-effort: a failure to record never fails its caller. Written to a temporary file and
|
|
89
|
+
* renamed, so a concurrent reader never sees a partial record.
|
|
90
|
+
*/
|
|
77
91
|
export function writeCompanionGitRecord(
|
|
78
92
|
companionPath: string,
|
|
79
93
|
record: CompanionGitRecord,
|
|
80
94
|
homeDir?: string,
|
|
81
95
|
): boolean {
|
|
82
96
|
const target = companionGitStatePath(companionPath, homeDir);
|
|
97
|
+
const temporary = `${target}.${process.pid}.tmp`;
|
|
83
98
|
try {
|
|
84
99
|
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
85
|
-
fs.writeFileSync(
|
|
100
|
+
fs.writeFileSync(temporary, `${JSON.stringify(record, null, 2)}\n`, "utf8");
|
|
101
|
+
fs.renameSync(temporary, target);
|
|
86
102
|
return true;
|
|
87
103
|
} catch {
|
|
104
|
+
fs.rmSync(temporary, { force: true });
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** A lock older than this was left by a writer that died holding it. */
|
|
110
|
+
const LOCK_STALE_MS = 10_000;
|
|
111
|
+
/** How long a writer waits for the lock before it writes unlocked. */
|
|
112
|
+
const LOCK_WAIT_MS = 2_000;
|
|
113
|
+
|
|
114
|
+
function sleepSync(ms: number): void {
|
|
115
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Takes the record's lock file and returns its token, unique so it tells this lock apart
|
|
120
|
+
* from one taken after it; null when it cannot within {@link LOCK_WAIT_MS}.
|
|
121
|
+
*/
|
|
122
|
+
function acquireLock(lock: string): string | null {
|
|
123
|
+
const giveUpAt = Date.now() + LOCK_WAIT_MS;
|
|
124
|
+
const token = `${process.pid} ${randomUUID()}`;
|
|
125
|
+
for (;;) {
|
|
126
|
+
try {
|
|
127
|
+
fs.mkdirSync(path.dirname(lock), { recursive: true });
|
|
128
|
+
fs.writeFileSync(lock, token, { flag: "wx" });
|
|
129
|
+
return token;
|
|
130
|
+
} catch (error) {
|
|
131
|
+
if ((error as NodeJS.ErrnoException).code !== "EEXIST") return null;
|
|
132
|
+
}
|
|
133
|
+
if (breakStaleLock(lock)) continue;
|
|
134
|
+
if (Date.now() >= giveUpAt) return null;
|
|
135
|
+
sleepSync(20);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function readLockToken(lock: string): string | null {
|
|
140
|
+
try {
|
|
141
|
+
return fs.readFileSync(lock, "utf8");
|
|
142
|
+
} catch {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** A lock file left longer than {@link LOCK_STALE_MS}; never a directory or other entry. */
|
|
148
|
+
function isStale(file: string): boolean {
|
|
149
|
+
try {
|
|
150
|
+
const stat = fs.statSync(file);
|
|
151
|
+
return stat.isFile() && Date.now() - stat.mtimeMs > LOCK_STALE_MS;
|
|
152
|
+
} catch {
|
|
153
|
+
// Gone meanwhile, or unreadable; waiting decides.
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Removes `lock` when a dead writer left it; true when it did. Breakers take `<lock>.break`
|
|
160
|
+
* first, so only one checks and removes at a time and none can delete a lock another breaker
|
|
161
|
+
* let a waiter retake. A breaker that died holding it is removed once stale.
|
|
162
|
+
*/
|
|
163
|
+
function breakStaleLock(lock: string): boolean {
|
|
164
|
+
if (!isStale(lock)) return false;
|
|
165
|
+
const breaker = `${lock}.break`;
|
|
166
|
+
try {
|
|
167
|
+
fs.writeFileSync(breaker, "", { flag: "wx" });
|
|
168
|
+
} catch {
|
|
169
|
+
if (isStale(breaker)) fs.rmSync(breaker, { force: true });
|
|
88
170
|
return false;
|
|
89
171
|
}
|
|
172
|
+
try {
|
|
173
|
+
if (!isStale(lock)) return false;
|
|
174
|
+
fs.rmSync(lock, { force: true });
|
|
175
|
+
return true;
|
|
176
|
+
} finally {
|
|
177
|
+
fs.rmSync(breaker, { force: true });
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Reads the record, applies `update` and writes the result under the record's lock, so
|
|
183
|
+
* concurrent sessions never drop each other's fields. Writes unlocked when the lock stays
|
|
184
|
+
* taken, as best-effort bookkeeping should.
|
|
185
|
+
*/
|
|
186
|
+
function updateCompanionGitRecord(
|
|
187
|
+
companionPath: string,
|
|
188
|
+
update: (record: CompanionGitRecord) => CompanionGitRecord,
|
|
189
|
+
homeDir?: string,
|
|
190
|
+
): boolean {
|
|
191
|
+
const lock = `${companionGitStatePath(companionPath, homeDir)}.lock`;
|
|
192
|
+
const token = acquireLock(lock);
|
|
193
|
+
try {
|
|
194
|
+
return writeCompanionGitRecord(
|
|
195
|
+
companionPath,
|
|
196
|
+
update(readCompanionGitRecord(companionPath, homeDir)),
|
|
197
|
+
homeDir,
|
|
198
|
+
);
|
|
199
|
+
} finally {
|
|
200
|
+
// Only its own: a lock held past the stale age may have been broken and retaken.
|
|
201
|
+
if (token !== null && readLockToken(lock) === token) fs.rmSync(lock, { force: true });
|
|
202
|
+
}
|
|
90
203
|
}
|
|
91
204
|
|
|
92
205
|
export function recordCompanionSync(
|
|
@@ -94,8 +207,11 @@ export function recordCompanionSync(
|
|
|
94
207
|
at: Date = new Date(),
|
|
95
208
|
homeDir?: string,
|
|
96
209
|
): boolean {
|
|
97
|
-
|
|
98
|
-
|
|
210
|
+
return updateCompanionGitRecord(
|
|
211
|
+
companionPath,
|
|
212
|
+
({ unfinishedReason: _cleared, ...record }) => ({ ...record, syncedAt: at.toISOString() }),
|
|
213
|
+
homeDir,
|
|
214
|
+
);
|
|
99
215
|
}
|
|
100
216
|
|
|
101
217
|
/**
|
|
@@ -109,8 +225,11 @@ export function recordCompanionSyncUnfinished(
|
|
|
109
225
|
reason: string,
|
|
110
226
|
homeDir?: string,
|
|
111
227
|
): boolean {
|
|
112
|
-
|
|
113
|
-
|
|
228
|
+
return updateCompanionGitRecord(
|
|
229
|
+
companionPath,
|
|
230
|
+
({ syncedAt: _stale, ...record }) => ({ ...record, unfinishedReason: reason }),
|
|
231
|
+
homeDir,
|
|
232
|
+
);
|
|
114
233
|
}
|
|
115
234
|
|
|
116
235
|
function withinInterval(stamp: string | undefined, intervalMs: number, now: Date): boolean {
|
|
@@ -147,10 +266,36 @@ export function recordForkVerdict(
|
|
|
147
266
|
at: Date = new Date(),
|
|
148
267
|
homeDir?: string,
|
|
149
268
|
): boolean {
|
|
150
|
-
|
|
151
|
-
|
|
269
|
+
return updateCompanionGitRecord(
|
|
270
|
+
companionPath,
|
|
271
|
+
(record) => ({ ...record, fork: { ...verdict, checkedAt: at.toISOString() } }),
|
|
272
|
+
homeDir,
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/** The change folders this checkout submitted, by companion-relative path. */
|
|
277
|
+
export function readSubmittedFolders(
|
|
278
|
+
companionPath: string,
|
|
279
|
+
homeDir?: string,
|
|
280
|
+
): Record<string, SubmittedFolder> {
|
|
281
|
+
const submitted = readCompanionGitRecord(companionPath, homeDir).submitted;
|
|
282
|
+
return submitted && typeof submitted === "object" ? submitted : {};
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/** Records `folders` as submitted from this checkout and forgets `forget`; best effort. */
|
|
286
|
+
export function updateSubmittedFolders(
|
|
287
|
+
companionPath: string,
|
|
288
|
+
folders: Record<string, SubmittedFolder>,
|
|
289
|
+
forget: readonly string[] = [],
|
|
290
|
+
homeDir?: string,
|
|
291
|
+
): boolean {
|
|
292
|
+
return updateCompanionGitRecord(
|
|
152
293
|
companionPath,
|
|
153
|
-
|
|
294
|
+
(record) => {
|
|
295
|
+
const submitted = { ...record.submitted, ...folders };
|
|
296
|
+
for (const folder of forget) delete submitted[folder];
|
|
297
|
+
return { ...record, submitted };
|
|
298
|
+
},
|
|
154
299
|
homeDir,
|
|
155
300
|
);
|
|
156
301
|
}
|
|
@@ -33,6 +33,42 @@ export function outputLines(stdout: string): string[] {
|
|
|
33
33
|
.filter(Boolean);
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Blob contents by spec from the output of `git cat-file --batch` fed `specs`, one per line.
|
|
38
|
+
* Per spec, in order: `<oid> <type> <size>\n<contents>\n`, or `<spec> missing\n`; missing
|
|
39
|
+
* and non-blob objects are left out. Null when the output is cut off or malformed.
|
|
40
|
+
*/
|
|
41
|
+
export function parseBlobBatch(out: Buffer, specs: readonly string[]): Map<string, string> | null {
|
|
42
|
+
const blobs = new Map<string, string>();
|
|
43
|
+
let offset = 0;
|
|
44
|
+
for (const spec of specs) {
|
|
45
|
+
const end = out.indexOf(10, offset);
|
|
46
|
+
if (end < 0) return null;
|
|
47
|
+
const line = out.subarray(offset, end).toString("utf8");
|
|
48
|
+
offset = end + 1;
|
|
49
|
+
// The spec is echoed, spaces and all, so these are read off the end.
|
|
50
|
+
if (line.endsWith(" missing") || line.endsWith(" ambiguous")) continue;
|
|
51
|
+
const header = line.split(" ");
|
|
52
|
+
if (header.length !== 3) continue;
|
|
53
|
+
const size = Number(header[2]);
|
|
54
|
+
if (!Number.isInteger(size) || offset + size > out.length) return null;
|
|
55
|
+
if (header[1] === "blob") blobs.set(spec, out.subarray(offset, offset + size).toString("utf8"));
|
|
56
|
+
offset += size + 1;
|
|
57
|
+
}
|
|
58
|
+
return blobs;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Paths of a `-z` listing, unquoted, so a non-ASCII path survives. */
|
|
62
|
+
export function nulPaths(stdout: string): string[] {
|
|
63
|
+
return stdout.split("\0").filter(Boolean);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Git option that reads pathspecs as plain paths. A change name may hold `*`, `?` or `[`, and
|
|
68
|
+
* on the inbox it is a teammate's: as a pattern it would match other changes' folders.
|
|
69
|
+
*/
|
|
70
|
+
export const LITERAL_PATHSPECS: readonly string[] = ["--literal-pathspecs"];
|
|
71
|
+
|
|
36
72
|
/** Matches Git progress-meter lines such as `Updating files: 76% (11340/14790)` or `..., done.` */
|
|
37
73
|
const GIT_PROGRESS_LINE = /^\S.*?: +\d+% \(\d+\/\d+\)(?:, done\.)?$/;
|
|
38
74
|
|
|
@@ -184,10 +220,15 @@ export interface CompanionGitOptions {
|
|
|
184
220
|
export interface CompanionGit {
|
|
185
221
|
/** Local command, captured. */
|
|
186
222
|
run(args: readonly string[]): Promise<GitResult>;
|
|
223
|
+
/**
|
|
224
|
+
* Contents of the blobs `ids` by id, decoded as text, read in one `git cat-file --batch`
|
|
225
|
+
* however many there are. Ids that name no blob are left out; null when the command fails.
|
|
226
|
+
*/
|
|
227
|
+
readBlobs(ids: readonly string[]): Promise<Map<string, string> | null>;
|
|
187
228
|
/** `git fetch <args>`, SSH first for HTTP(S) remotes. */
|
|
188
229
|
fetch(args?: readonly string[]): Promise<NetworkGitResult>;
|
|
189
|
-
/** `git push <args>`, SSH first for HTTP(S) remotes. */
|
|
190
|
-
push(args?: readonly string[]): Promise<NetworkGitResult>;
|
|
230
|
+
/** `git <gitOptions> push <args>`, SSH first for HTTP(S) remotes. */
|
|
231
|
+
push(args?: readonly string[], gitOptions?: readonly string[]): Promise<NetworkGitResult>;
|
|
191
232
|
/** Clones `url` into `destination` (relative to the operation's directory), SSH first for HTTP(S). */
|
|
192
233
|
clone(url: string, destination: string, options?: { branch?: string }): Promise<NetworkGitResult>;
|
|
193
234
|
upstreamTarget(): Promise<UpstreamTarget | null>;
|
|
@@ -226,14 +267,15 @@ function spawnGit(
|
|
|
226
267
|
cwd: string,
|
|
227
268
|
args: readonly string[],
|
|
228
269
|
env: Record<string, string | undefined>,
|
|
229
|
-
options: { interactive: boolean; timeoutMs?: number },
|
|
230
|
-
): Promise<GitResult> {
|
|
270
|
+
options: { interactive: boolean; timeoutMs?: number; input?: string },
|
|
271
|
+
): Promise<GitResult & { bytes?: Buffer }> {
|
|
231
272
|
return new Promise((resolve) => {
|
|
232
273
|
let settled = false;
|
|
233
274
|
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
234
275
|
const stdout: Buffer[] = [];
|
|
235
276
|
const stderr: Buffer[] = [];
|
|
236
|
-
const
|
|
277
|
+
const piped = options.input !== undefined;
|
|
278
|
+
const finish = (result: GitResult & { bytes?: Buffer }) => {
|
|
237
279
|
if (settled) return;
|
|
238
280
|
settled = true;
|
|
239
281
|
if (timer) clearTimeout(timer);
|
|
@@ -246,7 +288,9 @@ function spawnGit(
|
|
|
246
288
|
cwd,
|
|
247
289
|
env,
|
|
248
290
|
/** Interactive output goes to stderr so a caller's stdout (e.g. `--json`) stays clean. */
|
|
249
|
-
stdio: options.interactive
|
|
291
|
+
stdio: options.interactive
|
|
292
|
+
? ["inherit", 2, "inherit"]
|
|
293
|
+
: [piped ? "pipe" : "ignore", "pipe", "pipe"],
|
|
250
294
|
});
|
|
251
295
|
} catch (error) {
|
|
252
296
|
finish({ status: 1, stdout: "", stderr: (error as Error).message });
|
|
@@ -256,8 +300,18 @@ function spawnGit(
|
|
|
256
300
|
child.stderr?.on("data", (chunk: Buffer) => stderr.push(chunk));
|
|
257
301
|
child.once("error", (error) => finish({ status: 1, stdout: "", stderr: error.message }));
|
|
258
302
|
child.once("close", (status) =>
|
|
259
|
-
finish({
|
|
303
|
+
finish({
|
|
304
|
+
status: status ?? 1,
|
|
305
|
+
// Byte offsets matter to a caller that pipes input; the others read text.
|
|
306
|
+
...(piped ? { stdout: "", bytes: Buffer.concat(stdout) } : { stdout: decode(stdout) }),
|
|
307
|
+
stderr: decode(stderr),
|
|
308
|
+
}),
|
|
260
309
|
);
|
|
310
|
+
if (piped) {
|
|
311
|
+
// A command that exits early closes the pipe; its status reports the failure.
|
|
312
|
+
child.stdin?.on("error", () => {});
|
|
313
|
+
child.stdin?.end(options.input);
|
|
314
|
+
}
|
|
261
315
|
if (options.timeoutMs !== undefined) {
|
|
262
316
|
/** Resolved without awaiting `close`: an SSH grandchild may hold the pipes open. */
|
|
263
317
|
timer = setTimeout(
|
|
@@ -313,6 +367,8 @@ export function companionGit(
|
|
|
313
367
|
): CompanionGit {
|
|
314
368
|
const baseEnv: Record<string, string | undefined> = {
|
|
315
369
|
...gitEnvironment(options.env ?? process.env),
|
|
370
|
+
// Failures are told apart by Git's English messages.
|
|
371
|
+
LC_ALL: "C",
|
|
316
372
|
...(options.indexFile ? { GIT_INDEX_FILE: options.indexFile } : {}),
|
|
317
373
|
};
|
|
318
374
|
const mayPrompt = options.prompt === "if-terminal" && deps.isTerminal();
|
|
@@ -327,8 +383,12 @@ export function companionGit(
|
|
|
327
383
|
async function exec(
|
|
328
384
|
args: readonly string[],
|
|
329
385
|
env: Record<string, string | undefined>,
|
|
330
|
-
{
|
|
331
|
-
|
|
386
|
+
{
|
|
387
|
+
interactive = false,
|
|
388
|
+
capMs,
|
|
389
|
+
input,
|
|
390
|
+
}: { interactive?: boolean; capMs?: number; input?: string } = {},
|
|
391
|
+
): Promise<GitResult & { bytes?: Buffer }> {
|
|
332
392
|
const remaining = deadline - Date.now();
|
|
333
393
|
if (remaining <= 0) {
|
|
334
394
|
return {
|
|
@@ -342,11 +402,24 @@ export function companionGit(
|
|
|
342
402
|
return spawnGit(cwd, args, env, {
|
|
343
403
|
interactive,
|
|
344
404
|
timeoutMs: Number.isFinite(timeoutMs) ? timeoutMs : undefined,
|
|
405
|
+
...(input === undefined ? {} : { input }),
|
|
345
406
|
});
|
|
346
407
|
}
|
|
347
408
|
|
|
348
409
|
const run = (args: readonly string[]) => exec(args, capturedEnv, { capMs: options.commandCapMs });
|
|
349
410
|
|
|
411
|
+
async function readBlobs(ids: readonly string[]): Promise<Map<string, string> | null> {
|
|
412
|
+
const blobs = new Map<string, string>();
|
|
413
|
+
if (ids.length === 0) return blobs;
|
|
414
|
+
const result = await exec(["cat-file", "--batch"], capturedEnv, {
|
|
415
|
+
capMs: options.commandCapMs,
|
|
416
|
+
input: `${ids.join("\n")}\n`,
|
|
417
|
+
});
|
|
418
|
+
const out = result.bytes;
|
|
419
|
+
if (result.status !== 0 || !out) return null;
|
|
420
|
+
return parseBlobBatch(out, ids);
|
|
421
|
+
}
|
|
422
|
+
|
|
350
423
|
/**
|
|
351
424
|
* `never` appends `BatchMode=yes` to the SSH command Git would use anyway
|
|
352
425
|
* (`GIT_SSH_COMMAND`, `GIT_SSH`, `core.sshCommand`, then `ssh`), so SSH
|
|
@@ -405,8 +478,9 @@ export function companionGit(
|
|
|
405
478
|
|
|
406
479
|
return {
|
|
407
480
|
run,
|
|
481
|
+
readBlobs,
|
|
408
482
|
fetch: (args = []) => remoteNetwork(["fetch", ...args]),
|
|
409
|
-
push: (args = []) => remoteNetwork(["push", ...args]),
|
|
483
|
+
push: (args = [], gitOptions = []) => remoteNetwork([...gitOptions, "push", ...args]),
|
|
410
484
|
async clone(url, destination, { branch } = {}) {
|
|
411
485
|
const cloneArgs = ["clone", ...(branch ? ["--branch", branch] : []), url, destination];
|
|
412
486
|
const ssh = toSshUrl(url);
|
|
@@ -432,7 +506,8 @@ export function companionGit(
|
|
|
432
506
|
};
|
|
433
507
|
}
|
|
434
508
|
|
|
435
|
-
|
|
509
|
+
/** `remote/branch` as an upstream target; undefined when it has no `/`. */
|
|
510
|
+
export function parseRemoteRef(stdout: string): UpstreamTarget | undefined {
|
|
436
511
|
const ref = stdout.trim();
|
|
437
512
|
const separator = ref.indexOf("/");
|
|
438
513
|
if (separator <= 0 || separator === ref.length - 1) return undefined;
|
|
@@ -449,11 +524,19 @@ async function resolveUpstreamTarget(
|
|
|
449
524
|
): Promise<UpstreamTarget | null> {
|
|
450
525
|
const upstream = await run(["rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{u}"]);
|
|
451
526
|
const configured = parseRemoteRef(upstream.stdout);
|
|
452
|
-
if (upstream.status === 0 && configured)
|
|
527
|
+
if (upstream.status === 0 && configured) {
|
|
528
|
+
return configured.remote.startsWith("-") || configured.branch.startsWith("-")
|
|
529
|
+
? null
|
|
530
|
+
: configured;
|
|
531
|
+
}
|
|
453
532
|
|
|
454
533
|
const remoteHead = await run(["symbolic-ref", "--short", "refs/remotes/origin/HEAD"]);
|
|
455
534
|
const fromRemoteHead = parseRemoteRef(remoteHead.stdout);
|
|
456
|
-
if (remoteHead.status === 0 && fromRemoteHead)
|
|
535
|
+
if (remoteHead.status === 0 && fromRemoteHead) {
|
|
536
|
+
return fromRemoteHead.remote.startsWith("-") || fromRemoteHead.branch.startsWith("-")
|
|
537
|
+
? null
|
|
538
|
+
: fromRemoteHead;
|
|
539
|
+
}
|
|
457
540
|
|
|
458
541
|
for (const branch of ["main", "master"]) {
|
|
459
542
|
// oxlint-disable-next-line no-await-in-loop -- the steps are a decision chain
|
|
@@ -2,6 +2,8 @@ import path from "node:path";
|
|
|
2
2
|
|
|
3
3
|
import { FRAMEWORK_NAME } from "./framework";
|
|
4
4
|
import { GUIDANCE_FILE_VERSION, type MateGuidanceFile } from "./guidance";
|
|
5
|
+
import { readWorkflow } from "./workflow/declaration";
|
|
6
|
+
import type { DeclaredArtifactType } from "./workflow/workflow";
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* The guidance builders, on the session-runtime side of core.
|
|
@@ -32,6 +34,80 @@ export interface GuidanceContext {
|
|
|
32
34
|
* a caller that cannot tell never drops the rule.
|
|
33
35
|
*/
|
|
34
36
|
secretGuardrails?: boolean;
|
|
37
|
+
/** The artifact types the companion's workflow declares; each gets its reading rule. */
|
|
38
|
+
artifactTypes?: readonly GuidanceArtifactType[];
|
|
39
|
+
/** The skill stages the companion declares; absent when it declares none. */
|
|
40
|
+
stages?: readonly GuidanceStage[];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** The paths of a declared artifact type its reading rule is built from. */
|
|
44
|
+
export type GuidanceArtifactType = Pick<
|
|
45
|
+
DeclaredArtifactType,
|
|
46
|
+
"name" | "change" | "published" | "archive"
|
|
47
|
+
>;
|
|
48
|
+
|
|
49
|
+
/** A declared stage as the rule names it: its id, its skills in order, or that people review. */
|
|
50
|
+
export interface GuidanceStage {
|
|
51
|
+
id: string;
|
|
52
|
+
steps: string[];
|
|
53
|
+
review?: true;
|
|
54
|
+
optional?: true;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface DeclaredGuidance {
|
|
58
|
+
artifactTypes: GuidanceArtifactType[];
|
|
59
|
+
stages?: GuidanceStage[];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* What `companionPath`'s workflow adds to the guidance: its artifact types, and its declared
|
|
64
|
+
* stages when one runs a skill of the companion's own; Mate's stage skills report themselves, so
|
|
65
|
+
* a path of those alone needs no rule. An invalid declaration adds nothing, which keeps the
|
|
66
|
+
* built-in rules alone; the session banner names its problems.
|
|
67
|
+
*/
|
|
68
|
+
export function declaredGuidance(companionPath: string): DeclaredGuidance {
|
|
69
|
+
const verdict = readWorkflow(companionPath);
|
|
70
|
+
if (!verdict.ok) return { artifactTypes: [] };
|
|
71
|
+
const { artifacts, stages } = verdict.workflow;
|
|
72
|
+
const ownSkills = stages.some(
|
|
73
|
+
(stage) => stage.kind === "skill" && stage.steps.some((step) => !step.own),
|
|
74
|
+
);
|
|
75
|
+
if (!ownSkills) return { artifactTypes: artifacts };
|
|
76
|
+
return {
|
|
77
|
+
artifactTypes: artifacts,
|
|
78
|
+
stages: stages.map((stage) => ({
|
|
79
|
+
id: stage.id,
|
|
80
|
+
steps: stage.kind === "skill" ? stage.steps.map((step) => step.skill) : [],
|
|
81
|
+
...(stage.kind === "review" ? { review: true as const } : {}),
|
|
82
|
+
...(stage.optional ? { optional: true as const } : {}),
|
|
83
|
+
})),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The declared Delivery Path, and the one thing a skill its author wrote does not do: report
|
|
89
|
+
* itself. Everything else, change or none, comes from what `workflow done` prints.
|
|
90
|
+
*/
|
|
91
|
+
function stagesRule(stages: readonly GuidanceStage[]): string {
|
|
92
|
+
const order = stages
|
|
93
|
+
.map((stage) => {
|
|
94
|
+
const what = stage.review ? "reviewed by people" : stage.steps.join(", then ");
|
|
95
|
+
return `${stage.id} (${what}${stage.optional ? ", optional" : ""})`;
|
|
96
|
+
})
|
|
97
|
+
.join("; ");
|
|
98
|
+
return ` <rule id="workflow-stages" severity="critical">This companion's Delivery Path, declared in .mate/config/workflow.yaml, in order: ${order}. When one of these skills finishes without running ${FRAMEWORK_NAME} workflow done itself, run ${FRAMEWORK_NAME} workflow done "<skill>", adding the change name when there is one, and end your response with a final "## Next steps" section listing the actions it prints, running none of them.</rule>`;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** `notes/{name}/` → `notes/`. */
|
|
102
|
+
const folderOf = (template: string): string => template.replace(/\{[a-z]+\}\/?$/, "");
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* What agents read as current for a declared type, on the model of the built-in
|
|
106
|
+
* `openspec-publish` rule. Its submitted folders have no `touches`, so one is read only when named.
|
|
107
|
+
*/
|
|
108
|
+
function artifactTypeRule(type: GuidanceArtifactType): string {
|
|
109
|
+
const history = type.archive ? ` ${folderOf(type.archive)} is history.` : "";
|
|
110
|
+
return ` <rule id="artifact-${type.name}" severity="critical">${type.name}: ${type.published.join(", ")} is current. A submitted folder under ${folderOf(type.change)} is not the truth until publication lands it on the companion's default branch and is never current: read one only when the user names it, and revise one only when named (${FRAMEWORK_NAME} artifact take "<name>" when it is missing, then resubmit).${history}</rule>`;
|
|
35
111
|
}
|
|
36
112
|
|
|
37
113
|
const SECRET_HANDLING_RULE = ` <rule id="secret-handling" severity="critical">Never read, print, copy, or write secret files (.env, .env.*, keys, certificates, credential files such as .npmrc or .netrc) or secret values. To learn which variables exist, read only the example files (.env.example, .env.sample, .env.template, .env.dist). Refer to a secret by its variable name only. Do not print environment variables that may hold secrets. When a secret must be set or rotated, ask the user to do it instead of writing it yourself. Guarded calls are blocked; the companion's framework.yaml secrets block is the user's switch, not yours.</rule>`;
|
|
@@ -48,6 +124,13 @@ export function hasTokensaveCapability(capabilities: GuidanceCapability[] = []):
|
|
|
48
124
|
return capabilities.some((capability) => capability.name === "tokensave");
|
|
49
125
|
}
|
|
50
126
|
|
|
127
|
+
export function hasRtkCapability(capabilities: GuidanceCapability[] = []): boolean {
|
|
128
|
+
return capabilities.some((capability) => capability.name === "rtk");
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** Claude only: no other runtime isolates a session it moved into a worktree. */
|
|
132
|
+
const ENTERED_WORKTREE_GIT_RULE = ` <rule id="entered-worktree-git" severity="critical">After EnterWorktree moves this session into a linked worktree, run every git command as RTK_DISABLED=1 git ... (for example RTK_DISABLED=1 git status): Claude Code's worktree guard refuses git run through RTK there. Run other commands as usual.</rule>`;
|
|
133
|
+
|
|
51
134
|
export const GRAPHIFY_SHARED_COMPANION_PATH_CONTRACT =
|
|
52
135
|
"$MATE_ARTIFACT_PATH/.graphify/$MATE_REPO_ID/graphify-out/";
|
|
53
136
|
export const GRAPHIFY_COMPANION_PATH_CONTRACT =
|
|
@@ -107,7 +190,8 @@ export function buildCodebaseExplorationGuidanceSection(
|
|
|
107
190
|
|
|
108
191
|
/**
|
|
109
192
|
* Build just the `<companion-policy>` XML block: paths, CLI tools, and
|
|
110
|
-
* mandatory rules (including the capability-gated `openspec-publish` rule
|
|
193
|
+
* mandatory rules (including the capability-gated `openspec-publish` rule, and
|
|
194
|
+
* with `enteredWorktreeGit` the RTK-gated `entered-worktree-git` rule).
|
|
111
195
|
* Does not include codebase-exploration guidance — see
|
|
112
196
|
* `buildCompanionGuidance` for the merged single-string form, or call
|
|
113
197
|
* `buildCodebaseExplorationGuidanceSection` directly when that guidance is
|
|
@@ -115,7 +199,7 @@ export function buildCodebaseExplorationGuidanceSection(
|
|
|
115
199
|
*/
|
|
116
200
|
export function buildCompanionPolicyXml(
|
|
117
201
|
context: GuidanceContext,
|
|
118
|
-
options: { wrapperBinPath: string },
|
|
202
|
+
options: { wrapperBinPath: string; enteredWorktreeGit?: boolean },
|
|
119
203
|
): string {
|
|
120
204
|
const { wrapperBinPath } = options;
|
|
121
205
|
const lines = [
|
|
@@ -152,9 +236,8 @@ export function buildCompanionPolicyXml(
|
|
|
152
236
|
lines.splice(
|
|
153
237
|
lines.indexOf(" </mandatory-rules>"),
|
|
154
238
|
0,
|
|
155
|
-
` <rule id="artifact-location" severity="critical">Agent artifacts MUST go to ${context.companionPath}, NEVER ${context.repository.path}. Artifacts include plans, specs, ADRs, todos, notes, handoffs, reasoning docs, and scratch files.</rule>`,
|
|
239
|
+
` <rule id="artifact-location" severity="critical">Agent artifacts MUST go to ${context.companionPath}, NEVER ${context.repository.path}, which holds product code (README, docs, source, tests). Artifacts include plans, specs, ADRs, todos, notes, handoffs, reasoning docs, and scratch files.</rule>`,
|
|
156
240
|
` <rule id="pre-write-classification" severity="critical">Before ANY write, classify the target as product-code or agent-artifact. If unsure, treat it as agent-artifact.</rule>`,
|
|
157
|
-
` <rule id="product-code-location" severity="critical">Product code (README, docs, source, tests) belongs in the working-repository path; agent artifacts in the companion-repository path.</rule>`,
|
|
158
241
|
` <rule id="local-artifact-exception" severity="critical">Write an artifact in the working repository only when its exact path is gitignored AND intentionally local-only.</rule>`,
|
|
159
242
|
` <rule id="guardrail" severity="critical">Bad artifact writes to the working repository are rejected. The guardrail resolves relative paths against ${context.repository.path} and does not follow cd, so write artifacts, including shell redirects and tee, with absolute paths under ${context.companionPath}.</rule>`,
|
|
160
243
|
` <rule id="companion-multi-repository" severity="critical">This Companion Repository may serve multiple Working Repositories; the working-repository path is this session's single primary Working Repository (the product-code plane), not the full set. The Companion Repository is the shared artifact and context plane.</rule>`,
|
|
@@ -181,10 +264,18 @@ export function buildCompanionPolicyXml(
|
|
|
181
264
|
if (hasOpenspecCapability(context.capabilities)) {
|
|
182
265
|
lines.push(
|
|
183
266
|
` <rule id="openspec-scope" severity="critical">In OpenSpec, the frontmatter repository identifies the Working Repository; areas are repository-relative paths within that repository. Canonical specs use repository plus flat areas; change artifacts use paired scopes entries. In a monorepo, an Area normally stops at the package root. A cross-repository change may declare multiple scopes, but each resulting spec remains owned by one repository, and each requirement must bind its Area explicitly.</rule>`,
|
|
184
|
-
` <rule id="openspec-publish" severity="critical">
|
|
267
|
+
` <rule id="openspec-publish" severity="critical">Submit publishes nothing: it pushes an OpenSpec change folder (state: submitted) to the inbox mate/inbox to await its merge. A submitted change is not the truth: only publication lands it on the companion's default branch. openspec/specs/ is current; ${FRAMEWORK_NAME} artifact project "<name>" shows the unpublished outcome. ${FRAMEWORK_NAME} artifact pending --json lists them with author, touched requirements, ref and path; read one (git show <ref>:<path>/<file>) only where it touches your work or the user names it; implement or revise one only when the user names it: ${FRAMEWORK_NAME} artifact take "<name>" brings it into the checkout when it is missing there, then resubmit it with mate-submit-change. Publish only through mate-publish-artifact (${FRAMEWORK_NAME} artifact publish "<name>" --json), after the user selects and confirms the commit and push, for a Delivery Group whose delivery branch is merged. It creates no tag. Never hand-commit or hand-tag one. Publish archives submitted changes and never submits: submitting is a precondition (mate-submit-change, before the merge).</rule>`,
|
|
185
268
|
);
|
|
186
269
|
}
|
|
187
270
|
|
|
271
|
+
for (const type of context.artifactTypes ?? []) lines.push(artifactTypeRule(type));
|
|
272
|
+
|
|
273
|
+
if (context.stages?.length) lines.push(stagesRule(context.stages));
|
|
274
|
+
|
|
275
|
+
if (options.enteredWorktreeGit && hasRtkCapability(context.capabilities)) {
|
|
276
|
+
lines.push(ENTERED_WORKTREE_GIT_RULE);
|
|
277
|
+
}
|
|
278
|
+
|
|
188
279
|
lines.push(" </mandatory-rules>");
|
|
189
280
|
|
|
190
281
|
lines.push("</companion-policy>");
|
|
@@ -196,13 +287,14 @@ export function buildCompanionPolicyXml(
|
|
|
196
287
|
* Build the merged single-string guidance: the companion-policy XML plus
|
|
197
288
|
* codebase-exploration guidance appended when graphify or tokensave is
|
|
198
289
|
* enabled. Used by providers (e.g. Claude) that inject one combined prompt
|
|
199
|
-
* fragment rather than delivering exploration guidance separately
|
|
290
|
+
* fragment rather than delivering exploration guidance separately; only that
|
|
291
|
+
* form carries the Claude-only `entered-worktree-git` rule.
|
|
200
292
|
*/
|
|
201
293
|
export function buildCompanionGuidance(
|
|
202
294
|
context: GuidanceContext,
|
|
203
295
|
options: { wrapperBinPath: string },
|
|
204
296
|
): string {
|
|
205
|
-
const lines = [buildCompanionPolicyXml(context, options)];
|
|
297
|
+
const lines = [buildCompanionPolicyXml(context, { ...options, enteredWorktreeGit: true })];
|
|
206
298
|
|
|
207
299
|
const graphifyEnabled = hasGraphifyCapability(context.capabilities);
|
|
208
300
|
const tokensaveEnabled = hasTokensaveCapability(context.capabilities);
|
|
@@ -236,7 +328,12 @@ export function buildCompanionGuidance(
|
|
|
236
328
|
*/
|
|
237
329
|
export function buildOpenCodeGuidance(
|
|
238
330
|
capabilities: GuidanceCapability[],
|
|
239
|
-
options: {
|
|
331
|
+
options: {
|
|
332
|
+
companionScoped?: boolean;
|
|
333
|
+
secretGuardrails?: boolean;
|
|
334
|
+
artifactTypes?: readonly GuidanceArtifactType[];
|
|
335
|
+
stages?: readonly GuidanceStage[];
|
|
336
|
+
} = {},
|
|
240
337
|
): MateGuidanceFile {
|
|
241
338
|
const repository = options.companionScoped
|
|
242
339
|
? undefined
|
|
@@ -247,6 +344,8 @@ export function buildOpenCodeGuidance(
|
|
|
247
344
|
repository,
|
|
248
345
|
capabilities,
|
|
249
346
|
secretGuardrails: options.secretGuardrails,
|
|
347
|
+
...(options.artifactTypes ? { artifactTypes: options.artifactTypes } : {}),
|
|
348
|
+
...(options.stages ? { stages: options.stages } : {}),
|
|
250
349
|
},
|
|
251
350
|
{ wrapperBinPath: "$MATE_WRAPPER_BIN_PATH" },
|
|
252
351
|
);
|
|
@@ -183,7 +183,7 @@ function segment(
|
|
|
183
183
|
];
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
-
function escapeAttribute(value: string): string {
|
|
186
|
+
export function escapeAttribute(value: string): string {
|
|
187
187
|
return value.replaceAll("&", "&").replaceAll('"', """).replaceAll("<", "<");
|
|
188
188
|
}
|
|
189
189
|
|