heyspex 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +14 -0
- package/README.md +21 -0
- package/bin/hs.mjs +1089 -104
- package/bin/spexcode.mjs +262 -0
- package/dev-factory/engine/worktree.mjs +740 -0
- package/dev-factory/lib/code-repo-root.mjs +67 -0
- package/dev-factory/lib/context-budget.mjs +84 -0
- package/dev-factory/lib/epic-detect.mjs +190 -0
- package/dev-factory/lib/fleet-queue-file.mjs +846 -0
- package/dev-factory/lib/fleet-queue.mjs +426 -0
- package/dev-factory/lib/fleet-state.mjs +14 -18
- package/dev-factory/lib/model-catalog.mjs +338 -0
- package/dev-factory/lib/seat-context.mjs +199 -0
- package/dev-factory/lib/spec-io.mjs +93 -0
- package/dev-factory/lib/sufficiency-score.mjs +8 -2
- package/dev-factory/lib/worktree-allocator.mjs +744 -0
- package/dev-factory/model-catalog.json +222 -0
- package/dist/cli/hs-check.mjs +1127 -103
- package/dist/cli/hs-claim.mjs +981 -63
- package/dist/cli/hs-connect.mjs +10059 -1729
- package/dist/cli/hs-defer.mjs +5507 -3072
- package/dist/cli/hs-dev.mjs +576 -0
- package/dist/cli/hs-env.mjs +416 -302
- package/dist/cli/hs-index-rebuild.mjs +7334 -0
- package/dist/cli/hs-index-reconcile.mjs +8138 -0
- package/dist/cli/hs-init.mjs +2840 -149
- package/dist/cli/hs-install.mjs +7214 -594
- package/dist/cli/hs-join.mjs +10640 -2421
- package/dist/cli/hs-vault-pull.mjs +8157 -6370
- package/dist/cli/hs-vault-push.mjs +6433 -0
- package/dist/cli/hs-vault.mjs +4029 -1555
- package/dist/cli/hs-workspace.mjs +2702 -538
- package/dist/cli-templates/customer-vault/specs/entity-model.md +594 -601
- package/dist/cli-templates/customer-vault/specs/protocols/canonical-frontmatter-templates.md +110 -177
- package/dist/cli-templates/customer-vault/specs/protocols/destructive-action-checklist.md +122 -0
- package/dist/cli-templates/customer-vault/specs/protocols/memory-protocol.md +13 -15
- package/dist/cli-templates/customer-vault/specs/protocols/session-close-protocol.md +91 -0
- package/dist/cli-templates/customer-vault/specs/protocols/spec-hierarchy.md +150 -168
- package/dist/cli-templates/customer-vault/specs/protocols/spec-summary-authoring.md +83 -0
- package/dist/cli-templates/harness-commands/claude/hs-auto.md +36 -0
- package/dist/cli-templates/harness-commands/claude/hs-backfill.md +28 -0
- package/dist/cli-templates/harness-commands/claude/hs-capture.md +62 -0
- package/dist/cli-templates/harness-commands/claude/hs-defer.md +29 -0
- package/dist/cli-templates/harness-commands/claude/hs-dev.md +20 -0
- package/dist/cli-templates/harness-commands/claude/hs-doctor.md +32 -0
- package/dist/cli-templates/harness-commands/claude/hs-ground.md +30 -0
- package/dist/cli-templates/harness-commands/claude/hs-handoff.md +33 -0
- package/dist/cli-templates/harness-commands/claude/hs-log.md +27 -0
- package/dist/cli-templates/harness-commands/claude/hs-next.md +29 -0
- package/dist/cli-templates/harness-commands/claude/hs-promote.md +70 -0
- package/dist/cli-templates/harness-commands/claude/hs-push.md +35 -0
- package/dist/cli-templates/harness-commands/claude/hs-qc.md +27 -0
- package/dist/cli-templates/harness-commands/claude/hs-res.md +63 -0
- package/dist/cli-templates/harness-commands/claude/hs-resolve.md +23 -0
- package/dist/cli-templates/harness-commands/claude/hs-review.md +23 -0
- package/dist/cli-templates/harness-commands/claude/hs-view.md +28 -0
- package/dist/cli-templates/harness-commands/claude/kill-ports.md +32 -0
- package/dist/cli-templates/harness-commands/claude/prototype.md +91 -0
- package/dist/cli-templates/harness-commands/cursor/hs-auto.md +40 -0
- package/dist/cli-templates/harness-commands/cursor/hs-backfill.md +31 -0
- package/dist/cli-templates/harness-commands/cursor/hs-capture.md +65 -0
- package/dist/cli-templates/harness-commands/cursor/hs-defer.md +32 -0
- package/dist/cli-templates/harness-commands/cursor/hs-dev.md +24 -0
- package/dist/cli-templates/harness-commands/cursor/hs-doctor.md +36 -0
- package/dist/cli-templates/harness-commands/cursor/hs-ground.md +33 -0
- package/dist/cli-templates/harness-commands/cursor/hs-handoff.md +37 -0
- package/dist/cli-templates/harness-commands/cursor/hs-log.md +31 -0
- package/dist/cli-templates/harness-commands/cursor/hs-next.md +32 -0
- package/dist/cli-templates/harness-commands/cursor/hs-promote.md +73 -0
- package/dist/cli-templates/harness-commands/cursor/hs-push.md +38 -0
- package/dist/cli-templates/harness-commands/cursor/hs-qc.md +30 -0
- package/dist/cli-templates/harness-commands/cursor/hs-res.md +67 -0
- package/dist/cli-templates/harness-commands/cursor/hs-resolve.md +26 -0
- package/dist/cli-templates/harness-commands/cursor/hs-review.md +26 -0
- package/dist/cli-templates/harness-commands/cursor/hs-view.md +32 -0
- package/dist/cli-templates/harness-commands/cursor/kill-ports.md +35 -0
- package/dist/cli-templates/harness-commands/cursor/prototype.md +95 -0
- package/docs/copilot-plugin-install.md +162 -0
- package/docs/driving-heyspex-from-copilot.md +165 -0
- package/docs/mcp-client-config.md +259 -6
- package/package.json +249 -124
- package/plugins/heyspex/.claude-plugin/plugin.json +12 -0
- package/plugins/heyspex/.cursor-plugin/plugin.json +15 -0
- package/plugins/heyspex/.mcp.json +12 -0
- package/plugins/heyspex/README.md +309 -0
- package/plugins/heyspex/bin/launch-mcp.mjs +95 -0
- package/plugins/heyspex/bin/run-hook.mjs +80 -0
- package/plugins/heyspex/hooks/cursor-hooks.json +308 -0
- package/plugins/heyspex/hooks/hooks.json +418 -0
- package/plugins/heyspex/mcp.json +13 -0
- package/scripts/check-mcp-freshness.mjs +17 -9
- package/scripts/claude-hooks/_env-vault-events.mjs +68 -0
- package/scripts/claude-hooks/_guardrail-events.mjs +96 -0
- package/scripts/claude-hooks/_guardrail-loader.mjs +494 -0
- package/scripts/claude-hooks/_intent-classifier-router.mjs +456 -0
- package/scripts/claude-hooks/_intent-classifier-semantic.mjs +356 -0
- package/scripts/claude-hooks/_run.mjs +413 -0
- package/scripts/claude-hooks/_transcript-text.mjs +60 -0
- package/scripts/claude-hooks/_vault-retrieval.mjs +322 -0
- package/scripts/claude-hooks/agent-spawn-delegation-gate.mjs +133 -0
- package/scripts/claude-hooks/capture-execution-gate.mjs +51 -0
- package/scripts/claude-hooks/capture-workflow-gate.mjs +11 -0
- package/scripts/claude-hooks/check-auto-memory-budget.mjs +396 -0
- package/scripts/claude-hooks/check-claude-md-budget.mjs +327 -0
- package/scripts/claude-hooks/check-mcp-freshness-hook.mjs +14 -0
- package/scripts/claude-hooks/claim-before-code-gate.mjs +11 -0
- package/scripts/claude-hooks/claim-liveness-shared.mjs +577 -0
- package/scripts/claude-hooks/close-terminal-on-ship.mjs +64 -0
- package/scripts/claude-hooks/coo-denylist-gate.mjs +11 -0
- package/scripts/claude-hooks/coo-guard-check.mjs +11 -0
- package/scripts/claude-hooks/deep-research-cost-gate.mjs +11 -0
- package/scripts/claude-hooks/dev-server-task-reminder.mjs +15 -0
- package/scripts/claude-hooks/diagnose-capture-reminder.mjs +11 -0
- package/scripts/claude-hooks/directive-obligation-gate.mjs +11 -0
- package/scripts/claude-hooks/emit-claim-status.mjs +41 -0
- package/scripts/claude-hooks/enforce-session-sequence.mjs +11 -0
- package/scripts/claude-hooks/enforce-vault-naming.mjs +11 -0
- package/scripts/claude-hooks/env-vault-guard.mjs +11 -0
- package/scripts/claude-hooks/epic-milestone-phrasing-gate.mjs +11 -0
- package/scripts/claude-hooks/git-identity-guard.mjs +11 -0
- package/scripts/claude-hooks/git-reflog-audit.mjs +15 -0
- package/scripts/claude-hooks/git-stash-gate.mjs +11 -0
- package/scripts/claude-hooks/guard-auto-memory-writes.mjs +137 -0
- package/scripts/claude-hooks/id-display-format-gate.mjs +11 -0
- package/scripts/claude-hooks/inject-communication-style.mjs +86 -0
- package/scripts/claude-hooks/inject-coo-seat.mjs +78 -0
- package/scripts/claude-hooks/inject-dev-server-awareness.mjs +11 -0
- package/scripts/claude-hooks/inject-doctrine.mjs +13 -0
- package/scripts/claude-hooks/inject-vault-context.mjs +14 -0
- package/scripts/claude-hooks/intent-classifier-trigger.mjs +279 -0
- package/scripts/claude-hooks/log-session-activity.mjs +341 -0
- package/scripts/claude-hooks/naughty-list-gate.mjs +11 -0
- package/scripts/claude-hooks/notify-status-flip.mjs +72 -0
- package/scripts/claude-hooks/plan-exit-ingest-gate.mjs +170 -0
- package/scripts/claude-hooks/plan-ingest-close-reminder.mjs +66 -0
- package/scripts/claude-hooks/plan-review-gate.mjs +11 -0
- package/scripts/claude-hooks/preflight-reminder.mjs +262 -0
- package/scripts/claude-hooks/protected-action-intent.mjs +221 -0
- package/scripts/claude-hooks/research-method-guard.mjs +398 -0
- package/scripts/claude-hooks/research-protocol-gate.mjs +11 -0
- package/scripts/claude-hooks/session-end.mjs +451 -0
- package/scripts/claude-hooks/settings-write-gate.mjs +11 -0
- package/scripts/claude-hooks/settlement-check-gate.mjs +39 -0
- package/scripts/claude-hooks/status-flip-detect.mjs +17 -0
- package/scripts/claude-hooks/terminal-close-shared.mjs +426 -0
- package/scripts/claude-hooks/terminal-close-watcher.mjs +122 -0
- package/scripts/claude-hooks/vault-mirror-catchup.mjs +11 -0
- package/scripts/claude-hooks/vault-write-tier-guard.mjs +11 -0
- package/scripts/claude-hooks/wip-checkpoint.mjs +302 -0
- package/scripts/cursor-hooks/manifest.mjs +281 -0
- package/scripts/dev-server-status.mjs +34 -13
- package/scripts/dev-server-stop.mjs +313 -0
- package/scripts/heyspex-mode.mjs +288 -0
- package/scripts/hs-auto-resolve.mjs +240 -0
- package/scripts/hs-auto-source.mjs +398 -0
- package/scripts/hs-auto.mjs +134 -0
- package/scripts/hs-capture-cli.mjs +326 -0
- package/scripts/hs-classifier.mjs +136 -0
- package/scripts/hs-companion.mjs +88 -0
- package/scripts/hs-gateway.mjs +115 -0
- package/scripts/hs-mode.mjs +125 -0
- package/scripts/hs-next.mjs +441 -0
- package/scripts/hs-settings.mjs +338 -0
- package/scripts/hs-view.mjs +496 -0
- package/scripts/hs-worktree.mjs +201 -0
- package/scripts/install-claude-code-hooks.mjs +272 -0
- package/scripts/install-cursor-hooks.mjs +471 -0
- package/scripts/lib/agent-env-markers.mjs +38 -0
- package/scripts/lib/console-url-resolver.mjs +199 -61
- package/scripts/lib/customer-kit.mjs +1203 -0
- package/scripts/lib/dev-mode.mjs +249 -32
- package/scripts/lib/directive-obligations.mjs +349 -0
- package/scripts/lib/heyspex-home.mjs +72 -0
- package/scripts/lib/hook-dispositions.mjs +210 -0
- package/scripts/lib/hook-vault-header.mjs +30 -0
- package/scripts/lib/hs-command.mjs +277 -0
- package/scripts/lib/hs-companion-settings.mjs +472 -0
- package/scripts/lib/hs-source-branch.mjs +196 -0
- package/scripts/lib/hs-source-commit.mjs +59 -5
- package/scripts/lib/hs-source-identity.mjs +526 -0
- package/scripts/lib/hs-source-log.mjs +13 -22
- package/scripts/lib/hs-source-preflight.mjs +18 -4
- package/scripts/lib/hs-source-push.mjs +386 -307
- package/scripts/lib/hs-worktree-args.mjs +115 -0
- package/scripts/lib/shared-path-helpers.mjs +134 -0
- package/scripts/lib/standalone-doctor.mjs +540 -3
- package/scripts/lib/subagent-git-lock.mjs +109 -0
- package/scripts/lib/template-pin.mjs +34 -0
- package/scripts/lib/window-placement.mjs +109 -0
- package/scripts/provenance-lib.mjs +91 -0
- package/scripts/stamp-provenance-on-edit.mjs +222 -0
- package/scripts/wip-ledger-health.mjs +653 -0
- package/spexharness/doctrine/baseline/SPEXCODE-DOCTRINE.baseline.json +29 -0
- package/spexharness/src/adapters/audit.mjs +197 -0
- package/spexharness/src/adapters/claude-code.mjs +449 -0
- package/spexharness/src/adapters/copilot.mjs +236 -0
- package/spexharness/src/adapters/detect-harness.mjs +34 -0
- package/spexharness/src/chat/tui/ansi.mjs +448 -0
- package/spexharness/src/chat/tui/palette.mjs +22 -0
- package/spexharness/src/chat/tui/select.mjs +208 -0
- package/spexharness/src/config-root.mjs +54 -0
- package/spexharness/src/context-budget.mjs +141 -0
- package/spexharness/src/dev-server-control.mjs +389 -0
- package/spexharness/src/doctrine/behaviour.mjs +371 -0
- package/spexharness/src/doctrine/corpus.mjs +733 -0
- package/spexharness/src/doctrine/inject.mjs +338 -0
- package/spexharness/src/doctrine/merge.mjs +184 -0
- package/spexharness/src/doctrine/sources.mjs +252 -0
- package/spexharness/src/doctrine/synthesize.mjs +401 -0
- package/spexharness/src/doctrine/vault-source.mjs +574 -0
- package/spexharness/src/doctrine/writer.mjs +176 -0
- package/spexharness/src/events.mjs +84 -0
- package/spexharness/src/gates/_shell-write-targets.mjs +77 -0
- package/spexharness/src/gates/capture-workflow-gate.mjs +202 -0
- package/spexharness/src/gates/claim-before-code-gate.decide.mjs +33 -0
- package/spexharness/src/gates/claim-before-code-gate.mjs +129 -0
- package/spexharness/src/gates/deep-research-cost-gate.mjs +275 -0
- package/spexharness/src/gates/diagnose-capture-reminder.mjs +112 -0
- package/spexharness/src/gates/directive-obligation-gate.decide.mjs +132 -0
- package/spexharness/src/gates/directive-obligation-gate.mjs +183 -0
- package/spexharness/src/gates/enforce-session-sequence.mjs +895 -0
- package/spexharness/src/gates/enforce-vault-naming.mjs +215 -0
- package/spexharness/src/gates/epic-milestone-phrasing-gate.mjs +233 -0
- package/spexharness/src/gates/git-identity-guard.decide.mjs +436 -0
- package/spexharness/src/gates/git-identity-guard.mjs +61 -0
- package/spexharness/src/gates/git-reflog-audit.mjs +151 -0
- package/spexharness/src/gates/git-stash-gate.decide.mjs +361 -0
- package/spexharness/src/gates/git-stash-gate.mjs +159 -0
- package/spexharness/src/gates/id-display-format-gate.mjs +190 -0
- package/spexharness/src/gates/inject-doctrine-gate.mjs +89 -0
- package/spexharness/src/gates/inject-vault-context.mjs +239 -0
- package/spexharness/src/gates/naughty-list-gate.mjs +213 -0
- package/spexharness/src/gates/plan-review-gate.mjs +233 -0
- package/spexharness/src/gates/preflight-reminder-gate.mjs +265 -0
- package/spexharness/src/gates/research-protocol-gate.mjs +175 -0
- package/spexharness/src/gates/settings-write-gate.decide.mjs +96 -0
- package/spexharness/src/gates/settings-write-gate.mjs +104 -0
- package/spexharness/src/gates/vault-mirror-catchup.mjs +124 -0
- package/spexharness/src/gates/vault-write-tier-guard.decide.mjs +125 -0
- package/spexharness/src/gates/vault-write-tier-guard.mjs +42 -0
- package/spexharness/src/git-reflog-audit.mjs +294 -0
- package/spexharness/src/intent-classifier.mjs +196 -0
- package/spexharness/src/intent-directive.mjs +626 -0
- package/spexharness/src/profile/learn.mjs +551 -0
- package/spexharness/src/profile/proposals.mjs +357 -0
- package/spexharness/src/profile/vault-inclusion.mjs +386 -0
- package/spexharness/src/redact.mjs +151 -0
- package/spexharness/src/rule-table.mjs +849 -0
- package/spexharness/src/seat-context.mjs +122 -0
- package/spexharness/src/session-bootstrap.mjs +512 -0
- package/spexharness/src/session-record.mjs +815 -0
- package/spexharness/src/token-inventory.mjs +207 -0
- package/vendor/heyspex-mcp/account-switch.mjs +96 -0
- package/vendor/heyspex-mcp/alignment-gate.mjs +315 -1
- package/vendor/heyspex-mcp/blocker-resolver.mjs +37 -2
- package/vendor/heyspex-mcp/breakdown-ladder.mjs +119 -4
- package/vendor/heyspex-mcp/breakdown-source.mjs +271 -0
- package/vendor/heyspex-mcp/breakdown-writer.mjs +23 -3
- package/vendor/heyspex-mcp/capture-buffer-patches.mjs +77 -8
- package/vendor/heyspex-mcp/capture-channel.mjs +55 -5
- package/vendor/heyspex-mcp/capture-console-client.mjs +117 -3
- package/vendor/heyspex-mcp/capture-focus.mjs +1061 -31
- package/vendor/heyspex-mcp/capture-outbox.mjs +15 -5
- package/vendor/heyspex-mcp/capture-sources.mjs +195 -0
- package/vendor/heyspex-mcp/capture-tools.mjs +1264 -0
- package/vendor/heyspex-mcp/claim-tools.mjs +1147 -0
- package/vendor/heyspex-mcp/cli-verbs.mjs +2074 -0
- package/vendor/heyspex-mcp/cli.mjs +207 -15524
- package/vendor/heyspex-mcp/close-branch-report.mjs +102 -0
- package/vendor/heyspex-mcp/cloud-tool-surface.mjs +128 -0
- package/vendor/heyspex-mcp/cloud-vault-writes.mjs +602 -0
- package/vendor/heyspex-mcp/config-seed.yaml +15 -0
- package/vendor/heyspex-mcp/config-settings.mjs +290 -7
- package/vendor/heyspex-mcp/console-fetch.mjs +822 -17
- package/vendor/heyspex-mcp/console-transport.mjs +172 -0
- package/vendor/heyspex-mcp/credentials.mjs +585 -0
- package/vendor/heyspex-mcp/defer-spec.mjs +44 -4
- package/vendor/heyspex-mcp/deferred-reclaim.mjs +29 -3
- package/vendor/heyspex-mcp/design-handlers.mjs +31 -0
- package/vendor/heyspex-mcp/design-tools.mjs +4 -1
- package/vendor/heyspex-mcp/dev-factory-bridge.mjs +4 -4
- package/vendor/heyspex-mcp/dev-mode-core.mjs +45 -0
- package/vendor/heyspex-mcp/dev-tools.mjs +131 -0
- package/vendor/heyspex-mcp/diagnose-handlers.mjs +54 -0
- package/vendor/heyspex-mcp/events-tools.mjs +207 -0
- package/vendor/heyspex-mcp/filing-tools.mjs +723 -0
- package/vendor/heyspex-mcp/fleet-handlers.mjs +37 -0
- package/vendor/heyspex-mcp/fleet-queue-tools.mjs +71 -15
- package/vendor/heyspex-mcp/focus-tools.mjs +190 -0
- package/vendor/heyspex-mcp/folder-trust-store.mjs +60 -0
- package/vendor/heyspex-mcp/http-transport.mjs +302 -0
- package/vendor/heyspex-mcp/list-tools.mjs +257 -0
- package/vendor/heyspex-mcp/login-handoff.mjs +15 -1
- package/vendor/heyspex-mcp/mcp-config.mjs +107 -0
- package/vendor/heyspex-mcp/memory-tools.mjs +523 -0
- package/vendor/heyspex-mcp/mvp-mode.mjs +53 -6
- package/vendor/heyspex-mcp/obligation-backstop.mjs +103 -0
- package/vendor/heyspex-mcp/occupied-keys.mjs +142 -0
- package/vendor/heyspex-mcp/on-deck-brief.mjs +3377 -0
- package/vendor/heyspex-mcp/on-deck-scheduler.mjs +1708 -0
- package/vendor/heyspex-mcp/package-root.mjs +32 -0
- package/vendor/heyspex-mcp/peer-presence.mjs +8 -1
- package/vendor/heyspex-mcp/plan-ground.mjs +621 -652
- package/vendor/heyspex-mcp/plan-push.mjs +908 -22
- package/vendor/heyspex-mcp/plan-review.mjs +124 -30
- package/vendor/heyspex-mcp/preflight-gate.mjs +0 -0
- package/vendor/heyspex-mcp/procedure-handlers.mjs +327 -0
- package/vendor/heyspex-mcp/procedure-tools.mjs +1181 -970
- package/vendor/heyspex-mcp/promote-capture.mjs +388 -69
- package/vendor/heyspex-mcp/promote-diagnose.mjs +74 -0
- package/vendor/heyspex-mcp/promote-research-to-diagnose.mjs +9 -2
- package/vendor/heyspex-mcp/promote-research.mjs +666 -53
- package/vendor/heyspex-mcp/promotion-helpers.mjs +251 -0
- package/vendor/heyspex-mcp/prompts.mjs +1460 -0
- package/vendor/heyspex-mcp/read-path.mjs +191 -15
- package/vendor/heyspex-mcp/receipt-shape.mjs +146 -0
- package/vendor/heyspex-mcp/recipe-handlers.mjs +117 -0
- package/vendor/heyspex-mcp/regen-tasks.mjs +210 -3
- package/vendor/heyspex-mcp/register-spec.mjs +266 -54
- package/vendor/heyspex-mcp/request-context.mjs +83 -0
- package/vendor/heyspex-mcp/research-focus.mjs +207 -4
- package/vendor/heyspex-mcp/research-handlers.mjs +625 -0
- package/vendor/heyspex-mcp/research-tools.mjs +4 -4
- package/vendor/heyspex-mcp/response-budget.mjs +348 -0
- package/vendor/heyspex-mcp/review-focus.mjs +25 -1
- package/vendor/heyspex-mcp/roadmap-default.mjs +70 -0
- package/vendor/heyspex-mcp/search-specs.mjs +280 -0
- package/vendor/heyspex-mcp/seat-block-ledger.mjs +113 -0
- package/vendor/heyspex-mcp/seat-identity.mjs +2 -6
- package/vendor/heyspex-mcp/session-owner.mjs +109 -0
- package/vendor/heyspex-mcp/session-tools.mjs +162 -0
- package/vendor/heyspex-mcp/settings-registry.mjs +232 -0
- package/vendor/heyspex-mcp/settings-tools.mjs +85 -12
- package/vendor/heyspex-mcp/spec-edit-tools.mjs +453 -0
- package/vendor/heyspex-mcp/spec-id-lib.mjs +93 -17
- package/vendor/heyspex-mcp/split-research.mjs +304 -56
- package/vendor/heyspex-mcp/stdio-rpc.mjs +22 -0
- package/vendor/heyspex-mcp/submit-for-review.mjs +150 -7
- package/vendor/heyspex-mcp/summary-contract.mjs +105 -0
- package/vendor/heyspex-mcp/summary-write-tools.mjs +228 -0
- package/vendor/heyspex-mcp/symptom-query.mjs +146 -0
- package/vendor/heyspex-mcp/test-helpers.mjs +123 -1
- package/vendor/heyspex-mcp/tool-catalog.mjs +2819 -0
- package/vendor/heyspex-mcp/tool-dispatch.mjs +657 -0
- package/vendor/heyspex-mcp/tool-helpers.mjs +325 -0
- package/vendor/heyspex-mcp/validate-linkage.mjs +414 -27
- package/vendor/heyspex-mcp/vault-io.mjs +720 -0
- package/vendor/heyspex-mcp/vault-less-endpoints.mjs +52 -0
- package/vendor/heyspex-mcp/vault-resolve.mjs +554 -68
- package/vendor/heyspex-mcp/verify-reproduction.mjs +270 -30
- package/vendor/heyspex-mcp/whoami.mjs +92 -0
- package/vendor/heyspex-mcp/write-outbox.mjs +512 -0
package/dist/cli/hs-claim.mjs
CHANGED
|
@@ -1,9 +1,307 @@
|
|
|
1
1
|
import { createRequire as __hsCreateRequire } from 'node:module';
|
|
2
2
|
const require = __hsCreateRequire(import.meta.url);
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __esm = (fn, res) => function __init() {
|
|
5
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
// scripts/lib/heyspex-home.mjs
|
|
9
|
+
import { homedir } from "node:os";
|
|
10
|
+
function heyspexHome(env = process.env) {
|
|
11
|
+
const override = env?.HEYSPEX_HOME;
|
|
12
|
+
if (typeof override === "string" && override.trim().length > 0) {
|
|
13
|
+
return override.trim();
|
|
14
|
+
}
|
|
15
|
+
return homedir();
|
|
16
|
+
}
|
|
17
|
+
var init_heyspex_home = __esm({
|
|
18
|
+
"scripts/lib/heyspex-home.mjs"() {
|
|
19
|
+
"use strict";
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// vendor/heyspex-mcp/credentials.mjs
|
|
24
|
+
import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
25
|
+
import os, { homedir as homedir2 } from "node:os";
|
|
26
|
+
import { dirname as dirname2, join as join2, resolve } from "node:path";
|
|
27
|
+
function credentialsFilePath(homeDir = heyspexHome()) {
|
|
28
|
+
return join2(homeDir, ".heyspex", "credentials.yaml");
|
|
29
|
+
}
|
|
30
|
+
function parseMcpToken(raw) {
|
|
31
|
+
if (typeof raw !== "string" || raw.length === 0) return null;
|
|
32
|
+
const token = raw.match(MCP_TOKEN_LINE_RE)?.[1]?.trim();
|
|
33
|
+
return token ? token : null;
|
|
34
|
+
}
|
|
35
|
+
function isValidAccountId(id) {
|
|
36
|
+
return typeof id === "string" && ACCOUNT_ID_RE.test(id);
|
|
37
|
+
}
|
|
38
|
+
function topLevelScalar(raw, key) {
|
|
39
|
+
const re = new RegExp(`^${key}:[ \\t]*["']?([^"'\\r\\n#]+)`, "m");
|
|
40
|
+
const value = raw.match(re)?.[1]?.trim();
|
|
41
|
+
return value ? value : null;
|
|
42
|
+
}
|
|
43
|
+
function decodeScalar(text) {
|
|
44
|
+
const t = text.trim();
|
|
45
|
+
if (t === "" || t === "null" || t === "~") return null;
|
|
46
|
+
if (t.startsWith('"')) {
|
|
47
|
+
try {
|
|
48
|
+
const v = JSON.parse(t);
|
|
49
|
+
return typeof v === "string" && v ? v : null;
|
|
50
|
+
} catch {
|
|
51
|
+
return t.replace(/^"|"$/g, "") || null;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (t.startsWith("'")) return t.replace(/^'|'$/g, "") || null;
|
|
55
|
+
const bare = t.replace(/\s+#.*$/, "").trim();
|
|
56
|
+
return bare || null;
|
|
57
|
+
}
|
|
58
|
+
function emptyAccount() {
|
|
59
|
+
return { mcp_token: null, console_url: null, email: null, paired_at: null };
|
|
60
|
+
}
|
|
61
|
+
function findAccountsBlock(lines) {
|
|
62
|
+
const start = lines.findIndex((l) => /^accounts:[ \t]*(#.*)?$/.test(l));
|
|
63
|
+
if (start < 0) return null;
|
|
64
|
+
let end = start + 1;
|
|
65
|
+
while (end < lines.length && (lines[end].trim() === "" || /^[ \t]/.test(lines[end]))) end += 1;
|
|
66
|
+
while (end > start + 1 && lines[end - 1].trim() === "") end -= 1;
|
|
67
|
+
return { start, end };
|
|
68
|
+
}
|
|
69
|
+
function parseAccountsBlock(lines) {
|
|
70
|
+
const accounts = {};
|
|
71
|
+
const block = findAccountsBlock(lines);
|
|
72
|
+
if (!block) return accounts;
|
|
73
|
+
let current = null;
|
|
74
|
+
for (const line of lines.slice(block.start + 1, block.end)) {
|
|
75
|
+
const header = line.match(/^ {2}([^\s:#][^:]*):[ \t]*(#.*)?$/);
|
|
76
|
+
if (header) {
|
|
77
|
+
const id = decodeScalar(header[1]);
|
|
78
|
+
current = isValidAccountId(id) ? id : null;
|
|
79
|
+
if (current) accounts[current] = emptyAccount();
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
const field = line.match(/^ {4}([a-z_]+):(.*)$/);
|
|
83
|
+
if (field && current && ACCOUNT_FIELDS.includes(field[1])) {
|
|
84
|
+
accounts[current][field[1]] = decodeScalar(field[2]);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return accounts;
|
|
88
|
+
}
|
|
89
|
+
function parseCredentialsStore(raw) {
|
|
90
|
+
const text = typeof raw === "string" ? raw : "";
|
|
91
|
+
if (topLevelScalar(text, "schema_version") !== String(CREDENTIALS_SCHEMA_VERSION)) {
|
|
92
|
+
const token = parseMcpToken(text);
|
|
93
|
+
if (!token) return { schemaVersion: 1, currentAccountId: null, accounts: {} };
|
|
94
|
+
return {
|
|
95
|
+
schemaVersion: 1,
|
|
96
|
+
currentAccountId: LEGACY_ACCOUNT_ID,
|
|
97
|
+
accounts: {
|
|
98
|
+
[LEGACY_ACCOUNT_ID]: { ...emptyAccount(), mcp_token: token, console_url: topLevelScalar(text, "console_url") }
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
const accounts = parseAccountsBlock(text.split(/\r?\n/));
|
|
103
|
+
const current = topLevelScalar(text, "current_account_id");
|
|
104
|
+
return {
|
|
105
|
+
schemaVersion: 2,
|
|
106
|
+
currentAccountId: current && accounts[current] ? current : null,
|
|
107
|
+
accounts
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function resolveBearer({ envToken, credentialsText, accountId, legacyAccountId } = {}) {
|
|
111
|
+
const fromEnv = typeof envToken === "string" ? envToken.trim() : "";
|
|
112
|
+
if (fromEnv) return { token: fromEnv, source: "env" };
|
|
113
|
+
const store = parseCredentialsStore(credentialsText);
|
|
114
|
+
let entry;
|
|
115
|
+
if (typeof accountId === "string" && accountId.trim()) {
|
|
116
|
+
const wanted = accountId.trim();
|
|
117
|
+
entry = store.accounts[wanted];
|
|
118
|
+
if (!entry && store.schemaVersion === 1 && legacyAccountId && wanted === legacyAccountId) {
|
|
119
|
+
entry = store.accounts[LEGACY_ACCOUNT_ID];
|
|
120
|
+
}
|
|
121
|
+
} else {
|
|
122
|
+
entry = store.currentAccountId ? store.accounts[store.currentAccountId] : void 0;
|
|
123
|
+
}
|
|
124
|
+
if (entry?.mcp_token) return { token: entry.mcp_token, source: "credentials-file" };
|
|
125
|
+
return { token: null, source: null };
|
|
126
|
+
}
|
|
127
|
+
function readTextOrNull(read, path2) {
|
|
128
|
+
try {
|
|
129
|
+
const raw = read(path2);
|
|
130
|
+
return typeof raw === "string" ? raw : null;
|
|
131
|
+
} catch {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function readLegacyConfigAccountId(read, homeDir) {
|
|
136
|
+
const raw = readTextOrNull(read, join2(homeDir, ".heyspex", "config.yaml"));
|
|
137
|
+
const value = raw?.match(CONFIG_ACCOUNT_ID_RE)?.[1]?.trim() ?? "";
|
|
138
|
+
return value || null;
|
|
139
|
+
}
|
|
140
|
+
function readBearer({ env = process.env, homeDir = heyspexHome(), readFile, accountId } = {}) {
|
|
141
|
+
const read = readFile ?? ((p) => readFileSync(p, "utf8"));
|
|
142
|
+
const credentialsText = readTextOrNull(read, credentialsFilePath(homeDir));
|
|
143
|
+
const named = typeof accountId === "string" && accountId.trim() ? accountId.trim() : null;
|
|
144
|
+
const legacyAccountId = named && parseCredentialsStore(credentialsText).schemaVersion === 1 ? readLegacyConfigAccountId(read, homeDir) : null;
|
|
145
|
+
return resolveBearer({ envToken: env?.[MCP_TOKEN_ENV], credentialsText, accountId: named, legacyAccountId });
|
|
146
|
+
}
|
|
147
|
+
function readCurrentAccountId({ homeDir = heyspexHome(), readFile } = {}) {
|
|
148
|
+
const read = readFile ?? ((p) => readFileSync(p, "utf8"));
|
|
149
|
+
const store = parseCredentialsStore(readTextOrNull(read, credentialsFilePath(homeDir)));
|
|
150
|
+
if (store.schemaVersion === 2 && store.currentAccountId && store.currentAccountId !== LEGACY_ACCOUNT_ID) {
|
|
151
|
+
return store.currentAccountId;
|
|
152
|
+
}
|
|
153
|
+
if (store.schemaVersion === 2 && store.currentAccountId === null) return null;
|
|
154
|
+
return readLegacyConfigAccountId(read, homeDir);
|
|
155
|
+
}
|
|
156
|
+
var MCP_TOKEN_ENV, MCP_TOKEN_LINE_RE, CREDENTIALS_SCHEMA_VERSION, LEGACY_ACCOUNT_ID, ACCOUNT_FIELDS, ACCOUNT_ID_RE, CONFIG_ACCOUNT_ID_RE;
|
|
157
|
+
var init_credentials = __esm({
|
|
158
|
+
"vendor/heyspex-mcp/credentials.mjs"() {
|
|
159
|
+
"use strict";
|
|
160
|
+
init_heyspex_home();
|
|
161
|
+
MCP_TOKEN_ENV = "HEYSPEX_MCP_TOKEN";
|
|
162
|
+
MCP_TOKEN_LINE_RE = /^mcp_token:[ \t]*["']?([^"'\r\n#]+)/m;
|
|
163
|
+
CREDENTIALS_SCHEMA_VERSION = 2;
|
|
164
|
+
LEGACY_ACCOUNT_ID = "legacy";
|
|
165
|
+
ACCOUNT_FIELDS = ["mcp_token", "console_url", "email", "paired_at"];
|
|
166
|
+
ACCOUNT_ID_RE = /^[A-Za-z0-9][A-Za-z0-9_.@+-]*$/;
|
|
167
|
+
CONFIG_ACCOUNT_ID_RE = /^account_id:\s*["']?([^"'\r\n#]+)/m;
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
// scripts/lib/dev-mode.mjs
|
|
172
|
+
import { mkdirSync as mkdirSync4, readFileSync as readFileSync7, writeFileSync as writeFileSync4 } from "node:fs";
|
|
173
|
+
import { homedir as homedir7 } from "node:os";
|
|
174
|
+
import { join as join8 } from "node:path";
|
|
175
|
+
function devModeFilePath(homeDir = heyspexHome()) {
|
|
176
|
+
return join8(homeDir, ".heyspex", DEV_MODE_FILENAME);
|
|
177
|
+
}
|
|
178
|
+
function normalizeMode(raw) {
|
|
179
|
+
const v = String(raw ?? "").trim().toLowerCase();
|
|
180
|
+
if (v === "prod" || v === "production") return { mode: "prod", reliance: "cloud" };
|
|
181
|
+
if (v === "dev") return { mode: "dev", reliance: null };
|
|
182
|
+
if (v === "local") return { mode: "dev", reliance: "local" };
|
|
183
|
+
if (v === "cloud") return { mode: "dev", reliance: "cloud" };
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
function normalizeReliance(raw) {
|
|
187
|
+
const v = String(raw ?? "").trim().toLowerCase();
|
|
188
|
+
return v === "local" || v === "cloud" ? v : null;
|
|
189
|
+
}
|
|
190
|
+
function deriveSemantics(mode, reliance) {
|
|
191
|
+
const effectiveReliance = mode === "prod" ? "cloud" : reliance ?? "local";
|
|
192
|
+
const local = mode === "dev" && effectiveReliance === "local";
|
|
193
|
+
return {
|
|
194
|
+
reliance: effectiveReliance,
|
|
195
|
+
consoleUrl: local ? LOCAL_CONSOLE_URL : CLOUD_CONSOLE_URL,
|
|
196
|
+
readTier: local ? "disk" : "neon",
|
|
197
|
+
vaultWriteMode: local ? "local" : "cloud"
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
function readLocalDevModeRecord({ homeDir = heyspexHome(), readFile = defaultReadFile } = {}) {
|
|
201
|
+
let raw;
|
|
202
|
+
try {
|
|
203
|
+
raw = readFile(devModeFilePath(homeDir));
|
|
204
|
+
} catch {
|
|
205
|
+
return { record: null, parseError: null };
|
|
206
|
+
}
|
|
207
|
+
try {
|
|
208
|
+
const parsed = JSON.parse(raw);
|
|
209
|
+
const mode = parsed?.mode === "prod" || parsed?.mode === "dev" ? parsed.mode : null;
|
|
210
|
+
const reliance = normalizeReliance(parsed?.reliance);
|
|
211
|
+
if (!mode || mode === "dev" && !reliance) {
|
|
212
|
+
return { record: null, parseError: `invalid dev-mode record: ${JSON.stringify(parsed)}` };
|
|
213
|
+
}
|
|
214
|
+
return {
|
|
215
|
+
record: {
|
|
216
|
+
mode,
|
|
217
|
+
reliance: mode === "prod" ? "cloud" : reliance,
|
|
218
|
+
console_url: typeof parsed.console_url === "string" ? parsed.console_url : null,
|
|
219
|
+
updated_at: typeof parsed.updated_at === "string" ? parsed.updated_at : null,
|
|
220
|
+
source: typeof parsed.source === "string" ? parsed.source : null
|
|
221
|
+
},
|
|
222
|
+
parseError: null
|
|
223
|
+
};
|
|
224
|
+
} catch (err) {
|
|
225
|
+
return { record: null, parseError: `unparseable dev-mode.json: ${String(err?.message ?? err)}` };
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
function resolveDevMode({
|
|
229
|
+
env = process.env,
|
|
230
|
+
homeDir = heyspexHome(),
|
|
231
|
+
readFile = defaultReadFile,
|
|
232
|
+
cloudSetting = void 0
|
|
233
|
+
} = {}) {
|
|
234
|
+
const local = readLocalDevModeRecord({ homeDir, readFile });
|
|
235
|
+
const cloudKnown = cloudSetting !== void 0;
|
|
236
|
+
const cloudValue = cloudKnown && cloudSetting ? {
|
|
237
|
+
mode: cloudSetting.mode === "dev" ? "dev" : "prod",
|
|
238
|
+
reliance: normalizeReliance(cloudSetting.reliance) ?? "cloud"
|
|
239
|
+
} : null;
|
|
240
|
+
let mode;
|
|
241
|
+
let reliance;
|
|
242
|
+
let source;
|
|
243
|
+
let relianceSource;
|
|
244
|
+
const envParsed = normalizeMode(env.HEYSPEX_DEV_MODE);
|
|
245
|
+
if (envParsed) {
|
|
246
|
+
mode = envParsed.mode;
|
|
247
|
+
const envReliance = envParsed.reliance ?? normalizeReliance(env.HEYSPEX_DEV_RELIANCE);
|
|
248
|
+
reliance = envReliance ?? "local";
|
|
249
|
+
source = "env";
|
|
250
|
+
relianceSource = envReliance ? "env" : "assumed-local";
|
|
251
|
+
} else if (local.record) {
|
|
252
|
+
mode = local.record.mode;
|
|
253
|
+
reliance = local.record.reliance;
|
|
254
|
+
source = "local-override";
|
|
255
|
+
} else if (cloudValue) {
|
|
256
|
+
mode = cloudValue.mode;
|
|
257
|
+
reliance = cloudValue.reliance;
|
|
258
|
+
source = "cloud-setting";
|
|
259
|
+
} else {
|
|
260
|
+
mode = "prod";
|
|
261
|
+
reliance = "cloud";
|
|
262
|
+
source = "default";
|
|
263
|
+
}
|
|
264
|
+
const semantics = deriveSemantics(mode, reliance);
|
|
265
|
+
const consoleUrl = source === "local-override" && local.record?.console_url ? local.record.console_url.replace(/\/+$/, "") : semantics.consoleUrl;
|
|
266
|
+
const staleAgainstCloud = source === "local-override" && cloudValue !== null && (cloudValue.mode !== mode || mode === "dev" && cloudValue.reliance !== semantics.reliance);
|
|
267
|
+
return {
|
|
268
|
+
mode,
|
|
269
|
+
reliance: semantics.reliance,
|
|
270
|
+
consoleUrl,
|
|
271
|
+
readTier: semantics.readTier,
|
|
272
|
+
vaultWriteMode: semantics.vaultWriteMode,
|
|
273
|
+
sources: {
|
|
274
|
+
mode: source,
|
|
275
|
+
reliance: relianceSource ?? source,
|
|
276
|
+
consoleUrl: source === "local-override" && local.record?.console_url ? "local-override" : "derived",
|
|
277
|
+
readTier: "derived",
|
|
278
|
+
vaultWriteMode: "derived"
|
|
279
|
+
},
|
|
280
|
+
localOverride: {
|
|
281
|
+
present: local.record !== null,
|
|
282
|
+
record: local.record,
|
|
283
|
+
parseError: local.parseError,
|
|
284
|
+
staleAgainstCloud
|
|
285
|
+
},
|
|
286
|
+
cloudSetting: { known: cloudKnown, value: cloudValue }
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
var CLOUD_CONSOLE_URL, LOCAL_CONSOLE_URL, DEV_MODE_FILENAME, defaultReadFile;
|
|
290
|
+
var init_dev_mode = __esm({
|
|
291
|
+
"scripts/lib/dev-mode.mjs"() {
|
|
292
|
+
"use strict";
|
|
293
|
+
init_heyspex_home();
|
|
294
|
+
init_credentials();
|
|
295
|
+
CLOUD_CONSOLE_URL = "https://app.heyspex.com";
|
|
296
|
+
LOCAL_CONSOLE_URL = "http://localhost:3000";
|
|
297
|
+
DEV_MODE_FILENAME = "dev-mode.json";
|
|
298
|
+
defaultReadFile = (p) => readFileSync7(p, "utf8");
|
|
299
|
+
}
|
|
300
|
+
});
|
|
3
301
|
|
|
4
302
|
// spex-console/bin/hs-claim.ts
|
|
5
|
-
import { readFileSync as
|
|
6
|
-
import
|
|
303
|
+
import { readFileSync as readFileSync9 } from "node:fs";
|
|
304
|
+
import process3 from "node:process";
|
|
7
305
|
|
|
8
306
|
// spex-console/src/lib/work-stages.ts
|
|
9
307
|
var WORK_STAGES = [
|
|
@@ -46,12 +344,383 @@ function resolveAgentIdentity(argAgent, argSession) {
|
|
|
46
344
|
}
|
|
47
345
|
|
|
48
346
|
// spex-console/src/lib/cli/control-shared.ts
|
|
49
|
-
import
|
|
50
|
-
|
|
51
|
-
|
|
347
|
+
import path from "node:path";
|
|
348
|
+
|
|
349
|
+
// scripts/lib/hs-command.mjs
|
|
350
|
+
import { existsSync } from "node:fs";
|
|
351
|
+
import { delimiter, dirname, join } from "node:path";
|
|
352
|
+
import { fileURLToPath } from "node:url";
|
|
353
|
+
var HS_BIN_NAME = "hs";
|
|
354
|
+
var HS_DISPATCHER_PATH = (() => {
|
|
355
|
+
try {
|
|
356
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
357
|
+
return join(dirname(dirname(here)), "bin", "hs.mjs");
|
|
358
|
+
} catch {
|
|
359
|
+
return null;
|
|
360
|
+
}
|
|
361
|
+
})();
|
|
362
|
+
function shellQuote(p) {
|
|
363
|
+
return /[\\\s]/.test(p) ? `"${p}"` : p;
|
|
364
|
+
}
|
|
365
|
+
var HS_DISPATCHER_PREFIX = HS_DISPATCHER_PATH ? `node ${shellQuote(HS_DISPATCHER_PATH)}` : HS_BIN_NAME;
|
|
366
|
+
function candidateNames(name, env) {
|
|
367
|
+
if (process.platform !== "win32") return [name];
|
|
368
|
+
const pathext = (env.PATHEXT || ".COM;.EXE;.BAT;.CMD").split(";").map((e) => e.trim().toLowerCase()).filter(Boolean);
|
|
369
|
+
const extensions = [.../* @__PURE__ */ new Set([...pathext, ".ps1"])];
|
|
370
|
+
return [name, ...extensions.map((ext) => name + ext)];
|
|
371
|
+
}
|
|
372
|
+
function findOnPath(name, { env = process.env, exists = existsSync } = {}) {
|
|
373
|
+
try {
|
|
374
|
+
const raw = env.PATH ?? env.Path ?? env.path ?? "";
|
|
375
|
+
for (const dir of String(raw).split(delimiter)) {
|
|
376
|
+
const trimmed = dir.trim().replace(/^"(.*)"$/, "$1");
|
|
377
|
+
if (!trimmed) continue;
|
|
378
|
+
for (const candidate of candidateNames(name, env)) {
|
|
379
|
+
const full = join(trimmed, candidate);
|
|
380
|
+
try {
|
|
381
|
+
if (exists(full)) return full;
|
|
382
|
+
} catch {
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
} catch {
|
|
387
|
+
}
|
|
388
|
+
return null;
|
|
389
|
+
}
|
|
390
|
+
var cached = null;
|
|
391
|
+
var HS_ON_PATH_OVERRIDE_ENV = "HEYSPEX_HS_ON_PATH";
|
|
392
|
+
function onPathOverride(env) {
|
|
393
|
+
const raw = String(env?.[HS_ON_PATH_OVERRIDE_ENV] ?? "");
|
|
394
|
+
if (raw === "1") return true;
|
|
395
|
+
if (raw === "0") return false;
|
|
396
|
+
return void 0;
|
|
397
|
+
}
|
|
398
|
+
function describeHsCommand({ env, exists, useCache = true } = {}) {
|
|
399
|
+
const injected = env !== void 0 || exists !== void 0;
|
|
400
|
+
const effectiveEnv = env ?? process.env;
|
|
401
|
+
const override = onPathOverride(effectiveEnv);
|
|
402
|
+
if (override !== void 0) {
|
|
403
|
+
return {
|
|
404
|
+
onPath: override,
|
|
405
|
+
prefix: override ? HS_BIN_NAME : HS_DISPATCHER_PREFIX,
|
|
406
|
+
resolvedPath: null,
|
|
407
|
+
dispatcherPath: HS_DISPATCHER_PATH
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
if (useCache && !injected && cached) return cached;
|
|
411
|
+
const resolvedPath = findOnPath(HS_BIN_NAME, {
|
|
412
|
+
env: env ?? process.env,
|
|
413
|
+
exists: exists ?? existsSync
|
|
414
|
+
});
|
|
415
|
+
const answer = {
|
|
416
|
+
onPath: resolvedPath !== null,
|
|
417
|
+
prefix: resolvedPath !== null ? HS_BIN_NAME : HS_DISPATCHER_PREFIX,
|
|
418
|
+
resolvedPath,
|
|
419
|
+
dispatcherPath: HS_DISPATCHER_PATH
|
|
420
|
+
};
|
|
421
|
+
if (useCache && !injected) cached = answer;
|
|
422
|
+
return answer;
|
|
423
|
+
}
|
|
424
|
+
function hsCommand(args = "", options = {}) {
|
|
425
|
+
let prefix = HS_DISPATCHER_PREFIX;
|
|
426
|
+
try {
|
|
427
|
+
prefix = describeHsCommand(options).prefix;
|
|
428
|
+
} catch {
|
|
429
|
+
}
|
|
430
|
+
const tail = String(args ?? "").trim();
|
|
431
|
+
return tail ? `${prefix} ${tail}` : prefix;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
// vendor/heyspex-mcp/console-fetch.mjs
|
|
435
|
+
init_heyspex_home();
|
|
436
|
+
init_credentials();
|
|
437
|
+
import { readFileSync as readFileSync5 } from "node:fs";
|
|
438
|
+
import { homedir as homedir5 } from "node:os";
|
|
439
|
+
import { join as join6 } from "node:path";
|
|
440
|
+
|
|
441
|
+
// vendor/heyspex-mcp/session-owner.mjs
|
|
442
|
+
init_heyspex_home();
|
|
443
|
+
init_credentials();
|
|
444
|
+
import { readFileSync as readFileSync2 } from "node:fs";
|
|
445
|
+
import { homedir as homedir3 } from "node:os";
|
|
446
|
+
import { join as join3 } from "node:path";
|
|
447
|
+
function resolveSessionOwnerUncached({ env = process.env, homeDir = heyspexHome(), readFile } = {}) {
|
|
448
|
+
const fromEnv = typeof env?.HS_ACCOUNT_ID === "string" ? env.HS_ACCOUNT_ID.trim() : "";
|
|
449
|
+
if (fromEnv) return fromEnv;
|
|
450
|
+
return readCurrentAccountId({ homeDir, readFile });
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
// vendor/heyspex-mcp/vault-less-endpoints.mjs
|
|
454
|
+
var VAULT_LESS_ENDPOINTS = Object.freeze([
|
|
455
|
+
"* /api/mcp/session",
|
|
456
|
+
"* /api/mcp/pairing-codes",
|
|
457
|
+
"POST /api/vaults",
|
|
458
|
+
"GET /api/vaults",
|
|
459
|
+
"POST /api/workspaces",
|
|
460
|
+
"GET /api/workspaces",
|
|
461
|
+
"* /api/admin/dev-mode"
|
|
462
|
+
]);
|
|
463
|
+
function pathnameOf(path2) {
|
|
464
|
+
const raw = String(path2 ?? "").split("?")[0].split("#")[0];
|
|
465
|
+
const noTrailing = raw.length > 1 ? raw.replace(/\/+$/, "") : raw;
|
|
466
|
+
return noTrailing || "/";
|
|
467
|
+
}
|
|
468
|
+
function isVaultLessEndpoint(method, path2) {
|
|
469
|
+
const m = String(method || "GET").toUpperCase();
|
|
470
|
+
const pathname = pathnameOf(path2);
|
|
471
|
+
return VAULT_LESS_ENDPOINTS.some((row) => {
|
|
472
|
+
const [rowMethod, rowPath] = row.split(" ");
|
|
473
|
+
return rowPath === pathname && (rowMethod === "*" || rowMethod === m);
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
// vendor/heyspex-mcp/write-outbox.mjs
|
|
478
|
+
import {
|
|
479
|
+
readdirSync,
|
|
480
|
+
readFileSync as readFileSync3,
|
|
481
|
+
writeFileSync as writeFileSync2,
|
|
482
|
+
mkdirSync as mkdirSync2,
|
|
483
|
+
existsSync as existsSync2,
|
|
484
|
+
renameSync as renameSync2,
|
|
485
|
+
rmSync
|
|
486
|
+
} from "node:fs";
|
|
487
|
+
import { basename, join as join4, isAbsolute as isAbsolute2 } from "node:path";
|
|
488
|
+
|
|
489
|
+
// scripts/lib/shared-path-helpers.mjs
|
|
490
|
+
import { isAbsolute, resolve as resolve2, sep } from "node:path";
|
|
491
|
+
|
|
492
|
+
// vendor/heyspex-mcp/vault-resolve.mjs
|
|
493
|
+
init_heyspex_home();
|
|
494
|
+
import { existsSync as existsSync3, readFileSync as readFileSync4 } from "node:fs";
|
|
495
|
+
import { homedir as homedir4, tmpdir } from "node:os";
|
|
496
|
+
import { dirname as dirname3, join as join5, resolve as resolve3 } from "node:path";
|
|
497
|
+
|
|
498
|
+
// vendor/heyspex-mcp/console-fetch.mjs
|
|
499
|
+
var VAULT_NOT_REGISTERED = "VAULT_NOT_REGISTERED";
|
|
500
|
+
var VaultNotRegisteredError = class extends Error {
|
|
501
|
+
/**
|
|
502
|
+
* @param {string | null | undefined} repoRootAbs the root the resolver settled on
|
|
503
|
+
* @param {string | null | undefined} source the resolver tier that produced it
|
|
504
|
+
* @param {{ reason?: 'unregistered' | 'legacy-id', legacyId?: string | null }} [detail]
|
|
505
|
+
*/
|
|
506
|
+
constructor(repoRootAbs, source, { reason = "unregistered", legacyId = null } = {}) {
|
|
507
|
+
const root = typeof repoRootAbs === "string" && repoRootAbs.trim() ? repoRootAbs.trim() : null;
|
|
508
|
+
const where = root ? ` (${root})` : "";
|
|
509
|
+
const why = reason === "legacy-id" ? `This repo${where} is registered on this machine under a legacy id (\`${legacyId}\`), not the vault id the console knows, and its heyspex.yaml carries no \`vault_id\` to stand in for it, ` : `This repo${where} is not connected to a HeySpex vault on this machine (\`hs connect\` has not registered it), `;
|
|
510
|
+
super(
|
|
511
|
+
why + `so the console call was refused before it was sent. Run \`${hsCommand("connect")}\`${root ? ` in ${root}` : ""} to ${reason === "legacy-id" ? "re-register" : "connect"} it, then try again. Nothing was sent.`
|
|
512
|
+
);
|
|
513
|
+
this.name = "VaultNotRegisteredError";
|
|
514
|
+
this.code = VAULT_NOT_REGISTERED;
|
|
515
|
+
this.reason = reason;
|
|
516
|
+
this.repoRootAbs = root;
|
|
517
|
+
this.source = typeof source === "string" ? source : null;
|
|
518
|
+
this.legacyId = legacyId;
|
|
519
|
+
}
|
|
520
|
+
};
|
|
521
|
+
var CLOUD_VAULT_ID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
522
|
+
function isCloudVaultId(value) {
|
|
523
|
+
return typeof value === "string" && CLOUD_VAULT_ID_RE.test(value.trim());
|
|
524
|
+
}
|
|
525
|
+
var MARKER_VAULT_ID_RE = /^vault_id:[ \t]*["']?([^"'\r\n#]+)/m;
|
|
526
|
+
function readMarkerVaultId(repoRootAbs, { readFile } = {}) {
|
|
527
|
+
if (typeof repoRootAbs !== "string" || !repoRootAbs.trim()) return null;
|
|
528
|
+
const read = readFile ?? ((p) => readFileSync5(p, "utf8"));
|
|
529
|
+
try {
|
|
530
|
+
const raw = read(join6(repoRootAbs, "heyspex.yaml"));
|
|
531
|
+
const value = String(raw ?? "").match(MARKER_VAULT_ID_RE)?.[1]?.trim() ?? "";
|
|
532
|
+
return value || null;
|
|
533
|
+
} catch {
|
|
534
|
+
return null;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
function cloudVaultIdFor(resolved, { readMarkerVaultId: readMarker = readMarkerVaultId } = {}) {
|
|
538
|
+
const rowId = resolved.vaultId.trim();
|
|
539
|
+
if (isCloudVaultId(rowId)) return rowId;
|
|
540
|
+
const marker = readMarker(resolved.repoRootAbs);
|
|
541
|
+
if (isCloudVaultId(marker)) return marker.trim();
|
|
542
|
+
throw new VaultNotRegisteredError(resolved.repoRootAbs, resolved.source, { reason: "legacy-id", legacyId: rowId });
|
|
543
|
+
}
|
|
544
|
+
var SCOPE_REFUSAL_CODES = Object.freeze(["VAULT_SCOPE_MISMATCH", "ACCOUNT_MISMATCH", "VAULT_NOT_REGISTERED"]);
|
|
545
|
+
|
|
546
|
+
// spex-console/src/lib/cli/control-shared.ts
|
|
547
|
+
init_credentials();
|
|
548
|
+
|
|
549
|
+
// spex-console/src/lib/vault-registry/registry-file.ts
|
|
550
|
+
import { existsSync as existsSync4, mkdirSync as mkdirSync3, readFileSync as readFileSync6, renameSync as renameSync3, writeFileSync as writeFileSync3 } from "node:fs";
|
|
551
|
+
import { dirname as dirname4, join as join7, resolve as resolve4 } from "node:path";
|
|
552
|
+
|
|
553
|
+
// spex-console/src/lib/heyspex-home.ts
|
|
554
|
+
import { homedir as homedir6 } from "node:os";
|
|
555
|
+
function heyspexHome2(env = process.env) {
|
|
556
|
+
const override = env?.HEYSPEX_HOME;
|
|
557
|
+
if (typeof override === "string" && override.trim().length > 0) {
|
|
558
|
+
return override.trim();
|
|
559
|
+
}
|
|
560
|
+
return homedir6();
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
// spex-console/src/lib/vault-registry/types.ts
|
|
564
|
+
var LEGACY_REGISTRY_ACCOUNT_ID = "legacy";
|
|
565
|
+
var VAULT_REGISTRY_SCHEMA_VERSION = 2;
|
|
566
|
+
function emptyVaultRegistry() {
|
|
567
|
+
return {
|
|
568
|
+
schema_version: VAULT_REGISTRY_SCHEMA_VERSION,
|
|
569
|
+
current_account_id: null,
|
|
570
|
+
accounts: {},
|
|
571
|
+
workspaces: [],
|
|
572
|
+
vaults: []
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
// spex-console/src/lib/vault-registry/registry-file.ts
|
|
577
|
+
function vaultRegistryDir(opts = {}) {
|
|
578
|
+
return opts.registryDir ?? join7(heyspexHome2(), ".heyspex");
|
|
579
|
+
}
|
|
580
|
+
function vaultRegistryFilePath(opts = {}) {
|
|
581
|
+
return join7(vaultRegistryDir(opts), "registry.json");
|
|
582
|
+
}
|
|
583
|
+
function isNonEmptyString(v) {
|
|
584
|
+
return typeof v === "string" && v.trim().length > 0;
|
|
585
|
+
}
|
|
586
|
+
function accountOf(o) {
|
|
587
|
+
return isNonEmptyString(o.account_id) ? o.account_id : LEGACY_REGISTRY_ACCOUNT_ID;
|
|
588
|
+
}
|
|
589
|
+
function normalizeWorkspace(raw) {
|
|
590
|
+
if (!raw || typeof raw !== "object") return null;
|
|
591
|
+
const o = raw;
|
|
592
|
+
if (!isNonEmptyString(o.id)) return null;
|
|
593
|
+
if (!isNonEmptyString(o.display_name)) return null;
|
|
594
|
+
if (!isNonEmptyString(o.created_at)) return null;
|
|
595
|
+
const record = {
|
|
596
|
+
id: o.id,
|
|
597
|
+
display_name: o.display_name,
|
|
598
|
+
created_at: o.created_at,
|
|
599
|
+
archived: o.archived === true,
|
|
600
|
+
account_id: accountOf(o)
|
|
601
|
+
};
|
|
602
|
+
if (isNonEmptyString(o.github_org)) record.github_org = o.github_org;
|
|
603
|
+
return record;
|
|
604
|
+
}
|
|
605
|
+
function normalizeVault(raw) {
|
|
606
|
+
if (!raw || typeof raw !== "object") return null;
|
|
607
|
+
const o = raw;
|
|
608
|
+
if (!isNonEmptyString(o.id)) return null;
|
|
609
|
+
if (!isNonEmptyString(o.workspace_id)) return null;
|
|
610
|
+
if (!isNonEmptyString(o.display_name)) return null;
|
|
611
|
+
if (!isNonEmptyString(o.repo_root_abs)) return null;
|
|
612
|
+
if (typeof o.schema_version !== "number") return null;
|
|
613
|
+
if (!isNonEmptyString(o.registered_at)) return null;
|
|
614
|
+
const record = {
|
|
615
|
+
id: o.id,
|
|
616
|
+
workspace_id: o.workspace_id,
|
|
617
|
+
display_name: o.display_name,
|
|
618
|
+
repo_root_abs: o.repo_root_abs,
|
|
619
|
+
schema_version: o.schema_version,
|
|
620
|
+
registered_at: o.registered_at,
|
|
621
|
+
archived: o.archived === true,
|
|
622
|
+
account_id: accountOf(o)
|
|
623
|
+
};
|
|
624
|
+
if (isNonEmptyString(o.github_remote)) record.github_remote = o.github_remote;
|
|
625
|
+
return record;
|
|
626
|
+
}
|
|
627
|
+
function normalizeStoredPointers(raw) {
|
|
628
|
+
const o = raw && typeof raw === "object" ? raw : {};
|
|
629
|
+
const out = {};
|
|
630
|
+
for (const field of ["active_vault_id", "active_workspace_id"]) {
|
|
631
|
+
const v = o[field];
|
|
632
|
+
if (v === null || isNonEmptyString(v)) out[field] = v;
|
|
633
|
+
}
|
|
634
|
+
return out;
|
|
635
|
+
}
|
|
636
|
+
function normalizePointers(raw) {
|
|
637
|
+
const o = raw && typeof raw === "object" ? raw : {};
|
|
638
|
+
return {
|
|
639
|
+
active_vault_id: isNonEmptyString(o.active_vault_id) ? o.active_vault_id : null,
|
|
640
|
+
active_workspace_id: isNonEmptyString(o.active_workspace_id) ? o.active_workspace_id : null
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
function registryFileSchemaOf(json) {
|
|
644
|
+
if (!json || typeof json !== "object" || Array.isArray(json)) return null;
|
|
645
|
+
return json.schema_version === 2 ? 2 : 1;
|
|
646
|
+
}
|
|
647
|
+
function parseVaultRegistryFile(json) {
|
|
648
|
+
const schema = registryFileSchemaOf(json);
|
|
649
|
+
if (schema === null) return emptyVaultRegistry();
|
|
650
|
+
const o = json;
|
|
651
|
+
const workspacesRaw = Array.isArray(o.workspaces) ? o.workspaces : [];
|
|
652
|
+
const workspaces = workspacesRaw.map(normalizeWorkspace).filter((w) => w !== null);
|
|
653
|
+
const vaultsRaw = Array.isArray(o.vaults) ? o.vaults : [];
|
|
654
|
+
const vaults = vaultsRaw.map(normalizeVault).filter((v) => v !== null);
|
|
655
|
+
if (schema === 1) {
|
|
656
|
+
const legacy = normalizePointers(o);
|
|
657
|
+
const hasLegacyState = legacy.active_vault_id !== null || legacy.active_workspace_id !== null || workspaces.length > 0 || vaults.length > 0;
|
|
658
|
+
return {
|
|
659
|
+
schema_version: VAULT_REGISTRY_SCHEMA_VERSION,
|
|
660
|
+
current_account_id: hasLegacyState ? LEGACY_REGISTRY_ACCOUNT_ID : null,
|
|
661
|
+
accounts: hasLegacyState ? { [LEGACY_REGISTRY_ACCOUNT_ID]: legacy } : {},
|
|
662
|
+
workspaces,
|
|
663
|
+
vaults
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
const accounts = {};
|
|
667
|
+
if (o.accounts && typeof o.accounts === "object" && !Array.isArray(o.accounts)) {
|
|
668
|
+
for (const [id, pointers] of Object.entries(o.accounts)) {
|
|
669
|
+
if (isNonEmptyString(id)) accounts[id] = normalizeStoredPointers(pointers);
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
return {
|
|
673
|
+
schema_version: VAULT_REGISTRY_SCHEMA_VERSION,
|
|
674
|
+
current_account_id: isNonEmptyString(o.current_account_id) ? o.current_account_id : null,
|
|
675
|
+
accounts,
|
|
676
|
+
workspaces,
|
|
677
|
+
vaults
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
function readRegistryJson(opts) {
|
|
681
|
+
const filePath = vaultRegistryFilePath(opts);
|
|
682
|
+
if (!existsSync4(filePath)) return { kind: "missing" };
|
|
683
|
+
try {
|
|
684
|
+
const raw = readFileSync6(filePath, "utf8");
|
|
685
|
+
const json = JSON.parse(raw);
|
|
686
|
+
if (registryFileSchemaOf(json) === null) return { kind: "unreadable" };
|
|
687
|
+
return { kind: "ok", raw, json };
|
|
688
|
+
} catch {
|
|
689
|
+
return { kind: "unreadable" };
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
function inspectVaultRegistry(opts = {}) {
|
|
693
|
+
const read = readRegistryJson(opts);
|
|
694
|
+
if (read.kind !== "ok") {
|
|
695
|
+
return {
|
|
696
|
+
registry: emptyVaultRegistry(),
|
|
697
|
+
file_schema_version: null,
|
|
698
|
+
registry_unreadable: read.kind === "unreadable"
|
|
699
|
+
};
|
|
700
|
+
}
|
|
701
|
+
return {
|
|
702
|
+
registry: parseVaultRegistryFile(read.json),
|
|
703
|
+
file_schema_version: registryFileSchemaOf(read.json),
|
|
704
|
+
registry_unreadable: false
|
|
705
|
+
};
|
|
706
|
+
}
|
|
707
|
+
function loadVaultRegistry(opts = {}) {
|
|
708
|
+
return inspectVaultRegistry(opts).registry;
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
// spex-console/src/lib/cli/control-shared.ts
|
|
52
712
|
var EXIT = {
|
|
53
713
|
/** Success. */
|
|
54
714
|
OK: 0,
|
|
715
|
+
/**
|
|
716
|
+
* A read-only CHECK ran correctly and its answer is "no" — `hs connect
|
|
717
|
+
* --check` on an unconnected repo. Distinct from {@link EXIT.USAGE} so a
|
|
718
|
+
* script can tell "you typed the command wrong" from "the command worked,
|
|
719
|
+
* the repo is not connected". Both were `1` until 2026-09-18, which made
|
|
720
|
+
* `--check` unusable in a conditional: every caller had to parse stdout to
|
|
721
|
+
* find out which of the two had happened.
|
|
722
|
+
*/
|
|
723
|
+
CHECK_FAILED: 2,
|
|
55
724
|
/** Usage error — unknown subcommand/flag, or a missing required argument. */
|
|
56
725
|
USAGE: 1,
|
|
57
726
|
/** Claim race lost — the spec is already claimed by another agent (409). */
|
|
@@ -73,31 +742,94 @@ var EXIT = {
|
|
|
73
742
|
* from `USAGE`/`INVALID_ARG` — this is an authorization refusal, not a
|
|
74
743
|
* malformed command.
|
|
75
744
|
*/
|
|
76
|
-
FORBIDDEN: 15
|
|
745
|
+
FORBIDDEN: 15,
|
|
746
|
+
/**
|
|
747
|
+
* A CLOUD write refused because no account id could be resolved (no
|
|
748
|
+
* `HS_ACCOUNT_ID` env var, no `account_id:` in `~/.heyspex/config.yaml`) --
|
|
749
|
+
* `resolveCloudAccountIdOrRefuse` in `vault-workspace-shared.ts`
|
|
750
|
+
* ([[HS-YU1S-UAGY-TASK-cloud-writes-refuse-without-a]]). Distinct from
|
|
751
|
+
* `FORBIDDEN` -- this is "not signed in at all", not "signed in but not
|
|
752
|
+
* authorized for this override".
|
|
753
|
+
*/
|
|
754
|
+
SIGN_IN_REQUIRED: 16,
|
|
755
|
+
/**
|
|
756
|
+
* Signed in, but the account a repo would be attached to was not confirmed:
|
|
757
|
+
* a non-interactive install/connect with no matching `--account` / `--yes`,
|
|
758
|
+
* an `account_id` that disagrees with the bearer's user, or the human
|
|
759
|
+
* aborting the identity prompt (`install-identity.ts`,
|
|
760
|
+
* [[HS-HAQI-KODY-DIAG-hs-install-and-hs-connect-bind-a-new]]).
|
|
761
|
+
*/
|
|
762
|
+
IDENTITY_UNCONFIRMED: 17,
|
|
763
|
+
/**
|
|
764
|
+
* The repo this verb runs in is not registered on this machine (no
|
|
765
|
+
* `~/.heyspex/registry.json` row for its root, or a legacy slug row with no
|
|
766
|
+
* cloud `vault_id` in its heyspex.yaml), so the call was refused LOCALLY —
|
|
767
|
+
* nothing was sent. Names `hs connect`
|
|
768
|
+
* ([[HS-MVG4-WW9R-TASK-mcp-and-hs-name-account-vault-on-every]]).
|
|
769
|
+
*/
|
|
770
|
+
VAULT_NOT_REGISTERED: 18,
|
|
771
|
+
/**
|
|
772
|
+
* The local half of a setup verb (`hs connect`, `hs vault *`, `hs workspace
|
|
773
|
+
* *`) was written but the CLOUD half did not land -- the console refused
|
|
774
|
+
* it or was never reached. The verb's receipt names the failed half and the
|
|
775
|
+
* exact command to re-run
|
|
776
|
+
* ([[HS-STCY-WW9R-TASK-add-a-shared-receipt-that-reads-back]], invariant 6).
|
|
777
|
+
* Distinct from {@link EXIT.WRITE_FAILED} so a script can tell "re-run to
|
|
778
|
+
* sync the cloud" from a generic server failure.
|
|
779
|
+
*/
|
|
780
|
+
CLOUD_WRITE_FAILED: 19,
|
|
781
|
+
/**
|
|
782
|
+
* The repo's committed `heyspex.yaml` records `account: <A>` but the machine
|
|
783
|
+
* is signed in as another account, so `hs connect` refused and wrote
|
|
784
|
+
* nothing (marker, registry, cloud). Repair: `hs login --switch-account <A>`
|
|
785
|
+
* ([[HS-VWUD-WW9R-TASK-record-the-connecting-account-in]], invariant 4).
|
|
786
|
+
*/
|
|
787
|
+
ACCOUNT_MISMATCH: 20,
|
|
788
|
+
/**
|
|
789
|
+
* Both sides of a setup verb's receipt were read back and still DISAGREE
|
|
790
|
+
* after a short bounded re-read of the cloud side (a briefly stale read is
|
|
791
|
+
* absorbed first). The write may well have landed; what the verb cannot
|
|
792
|
+
* claim is that this machine and the console now say the same thing. The
|
|
793
|
+
* receipt prints the diffs and the command to re-run
|
|
794
|
+
* ([[HS-FKSR-WW9R-TASK-make-one-hs-connect-run-create-a-cloud]], invariant 6).
|
|
795
|
+
* Distinct from {@link EXIT.CLOUD_WRITE_FAILED} (a write that did not land).
|
|
796
|
+
*/
|
|
797
|
+
RECEIPT_DISAGREE: 21
|
|
77
798
|
};
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return match?.[1];
|
|
83
|
-
} catch {
|
|
84
|
-
return void 0;
|
|
85
|
-
}
|
|
799
|
+
var VAULT_ID_HEADER = "x-heyspex-vault-id";
|
|
800
|
+
var ACCOUNT_ID_HEADER = "x-heyspex-account-id";
|
|
801
|
+
function readPairedBearer(opts = {}) {
|
|
802
|
+
return readBearer(opts);
|
|
86
803
|
}
|
|
87
|
-
function
|
|
804
|
+
function readPairedToken(opts = {}) {
|
|
805
|
+
return readPairedBearer(opts).token ?? void 0;
|
|
806
|
+
}
|
|
807
|
+
function bearerHeaderFor(consoleUrl, opts = {}) {
|
|
88
808
|
try {
|
|
89
809
|
const host = new URL(consoleUrl).hostname;
|
|
90
810
|
if (host === "localhost" || host === "127.0.0.1" || host === "0.0.0.0" || host === "::1") {
|
|
91
811
|
return {};
|
|
92
812
|
}
|
|
93
|
-
const token = readPairedToken();
|
|
813
|
+
const token = readPairedToken(opts);
|
|
94
814
|
return token ? { authorization: `Bearer ${token}` } : {};
|
|
95
815
|
} catch {
|
|
96
816
|
return {};
|
|
97
817
|
}
|
|
98
818
|
}
|
|
819
|
+
function scopeHeadersFor(scope, method, path2) {
|
|
820
|
+
if (scope === "none") {
|
|
821
|
+
if (!isVaultLessEndpoint(method, path2)) {
|
|
822
|
+
throw new Error(
|
|
823
|
+
`controlRequest: scope "none" is only allowed for the vault-less endpoints (${VAULT_LESS_ENDPOINTS.join(", ")}); ${method.toUpperCase()} ${path2} is vault-scoped and must name { accountId, vaultId }.`
|
|
824
|
+
);
|
|
825
|
+
}
|
|
826
|
+
return {};
|
|
827
|
+
}
|
|
828
|
+
return { [VAULT_ID_HEADER]: scope.vaultId, [ACCOUNT_ID_HEADER]: scope.accountId };
|
|
829
|
+
}
|
|
99
830
|
async function controlRequest(deps, req) {
|
|
100
831
|
const url = `${deps.consoleUrl}${req.path}`;
|
|
832
|
+
const scopeHeaders = scopeHeadersFor(deps.scope, req.method, req.path);
|
|
101
833
|
let res;
|
|
102
834
|
try {
|
|
103
835
|
res = await deps.fetchImpl(url, {
|
|
@@ -108,7 +840,10 @@ async function controlRequest(deps, req) {
|
|
|
108
840
|
// authenticates every control call; loopback never asked, so the header
|
|
109
841
|
// is attached only when the target is non-loopback and a paired token
|
|
110
842
|
// exists. Same `hsmcp_` bearer the MCP server presents.
|
|
111
|
-
...bearerHeaderFor(deps.consoleUrl)
|
|
843
|
+
...bearerHeaderFor(deps.consoleUrl),
|
|
844
|
+
// Invariant 2: name the vault and the account on every call, or the
|
|
845
|
+
// console serves whatever its leftover pointer says.
|
|
846
|
+
...scopeHeaders
|
|
112
847
|
},
|
|
113
848
|
...req.body !== void 0 ? { body: JSON.stringify(req.body) } : {}
|
|
114
849
|
});
|
|
@@ -178,6 +913,72 @@ function parseTtl(token) {
|
|
|
178
913
|
}
|
|
179
914
|
return { value: n };
|
|
180
915
|
}
|
|
916
|
+
function normalizeRoot(p) {
|
|
917
|
+
return path.resolve(p).replace(/[\\/]+/g, "/").replace(/\/+$/, "").toLowerCase();
|
|
918
|
+
}
|
|
919
|
+
function resolveControlScope(input) {
|
|
920
|
+
const target = normalizeRoot(input.vaultRoot);
|
|
921
|
+
const row = input.vaults.find((v) => normalizeRoot(v.repo_root_abs) === target) ?? null;
|
|
922
|
+
if (!row) {
|
|
923
|
+
return {
|
|
924
|
+
ok: false,
|
|
925
|
+
error: {
|
|
926
|
+
code: EXIT.VAULT_NOT_REGISTERED,
|
|
927
|
+
message: `this repo (${input.vaultRoot}) is not connected to a HeySpex vault on this machine (\`hs connect\` has not registered it), so the call was refused before it was sent. Run \`${hsCommand("connect")}\` in ${input.vaultRoot}, then try again.`,
|
|
928
|
+
payload: {
|
|
929
|
+
ok: false,
|
|
930
|
+
error: "vault_not_registered",
|
|
931
|
+
reason: "unregistered",
|
|
932
|
+
vault_root: input.vaultRoot
|
|
933
|
+
},
|
|
934
|
+
isError: true
|
|
935
|
+
}
|
|
936
|
+
};
|
|
937
|
+
}
|
|
938
|
+
let vaultId;
|
|
939
|
+
try {
|
|
940
|
+
vaultId = cloudVaultIdFor(
|
|
941
|
+
{ vaultId: row.id, repoRootAbs: row.repo_root_abs, source: "registry" },
|
|
942
|
+
input.readMarkerVaultId ? { readMarkerVaultId: input.readMarkerVaultId } : {}
|
|
943
|
+
);
|
|
944
|
+
} catch (err) {
|
|
945
|
+
if (!(err instanceof VaultNotRegisteredError)) throw err;
|
|
946
|
+
const refused = err;
|
|
947
|
+
return {
|
|
948
|
+
ok: false,
|
|
949
|
+
error: {
|
|
950
|
+
code: EXIT.VAULT_NOT_REGISTERED,
|
|
951
|
+
message: refused.message,
|
|
952
|
+
payload: {
|
|
953
|
+
ok: false,
|
|
954
|
+
error: "vault_not_registered",
|
|
955
|
+
reason: refused.reason ?? "legacy-id",
|
|
956
|
+
vault_root: input.vaultRoot,
|
|
957
|
+
legacy_id: refused.legacyId ?? row.id
|
|
958
|
+
},
|
|
959
|
+
isError: true
|
|
960
|
+
}
|
|
961
|
+
};
|
|
962
|
+
}
|
|
963
|
+
const accountId = input.accountId?.trim() ?? "";
|
|
964
|
+
if (!accountId) {
|
|
965
|
+
return {
|
|
966
|
+
ok: false,
|
|
967
|
+
error: {
|
|
968
|
+
code: EXIT.SIGN_IN_REQUIRED,
|
|
969
|
+
message: `no HeySpex account is configured on this machine (\`hs login\` has not been run), so the call was refused before it was sent. Run \`${hsCommand("login")}\` on this machine, then try again.`,
|
|
970
|
+
payload: { ok: false, error: "sign_in_required", vault_root: input.vaultRoot },
|
|
971
|
+
isError: true
|
|
972
|
+
}
|
|
973
|
+
};
|
|
974
|
+
}
|
|
975
|
+
return { ok: true, scope: { accountId, vaultId } };
|
|
976
|
+
}
|
|
977
|
+
function resolveControlScopeFromMachine(vaultRoot, opts = {}) {
|
|
978
|
+
const registry = loadVaultRegistry(opts.registry);
|
|
979
|
+
const accountId = resolveSessionOwnerUncached({ env: opts.env, homeDir: opts.homeDir });
|
|
980
|
+
return resolveControlScope({ vaultRoot, accountId, vaults: registry.vaults });
|
|
981
|
+
}
|
|
181
982
|
|
|
182
983
|
// spex-console/src/lib/cli/claim.ts
|
|
183
984
|
function parseClaimArgs(argv) {
|
|
@@ -441,41 +1242,121 @@ var HELP = [
|
|
|
441
1242
|
" 12 console-unreachable \xB7 13 server-error \xB7 14 neon-required"
|
|
442
1243
|
].join("\n");
|
|
443
1244
|
|
|
444
|
-
// spex-console/src/lib/cli/defer.ts
|
|
445
|
-
import { readFileSync as readFileSync3 } from "node:fs";
|
|
446
|
-
import os from "node:os";
|
|
447
|
-
import path from "node:path";
|
|
448
|
-
|
|
449
1245
|
// scripts/lib/console-url-resolver.mjs
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
import {
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
function
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
1246
|
+
init_heyspex_home();
|
|
1247
|
+
init_dev_mode();
|
|
1248
|
+
import { readFileSync as readFileSync8 } from "node:fs";
|
|
1249
|
+
import { homedir as homedir8 } from "node:os";
|
|
1250
|
+
import { join as join9 } from "node:path";
|
|
1251
|
+
var DEFAULT_CONSOLE_URL = LOCAL_CONSOLE_URL;
|
|
1252
|
+
function trimTrailingSlash(url) {
|
|
1253
|
+
return url.replace(/\/+$/, "");
|
|
1254
|
+
}
|
|
1255
|
+
var LOOPBACK_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "::1", "[::1]", "0.0.0.0"]);
|
|
1256
|
+
function isLoopbackConsoleUrl(url) {
|
|
1257
|
+
if (typeof url !== "string" || !url) return false;
|
|
460
1258
|
try {
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
1259
|
+
return LOOPBACK_HOSTS.has(new URL(url).hostname.toLowerCase());
|
|
1260
|
+
} catch {
|
|
1261
|
+
return false;
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
var staleLoopbackCredentialsWarned = false;
|
|
1265
|
+
function warnStaleLoopbackCredentialsOnce(credentialsUrl, derivedUrl, { log }) {
|
|
1266
|
+
if (staleLoopbackCredentialsWarned) return;
|
|
1267
|
+
staleLoopbackCredentialsWarned = true;
|
|
1268
|
+
try {
|
|
1269
|
+
log(
|
|
1270
|
+
`[heyspex] ignoring console_url ${credentialsUrl} from ~/.heyspex/credentials.yaml: the resolved reliance is cloud, and a loopback console cannot serve it \u2014 using ${derivedUrl} (set HEYSPEX_CONSOLE_URL to override explicitly, or run \`hs dev mode:local\` to go back to a local console).
|
|
1271
|
+
`
|
|
1272
|
+
);
|
|
1273
|
+
} catch {
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
function readCredentialsConsoleUrl({ homeDir = heyspexHome(), readFile = defaultReadFile2 } = {}) {
|
|
1277
|
+
try {
|
|
1278
|
+
const raw = readFile(join9(homeDir, ".heyspex", "credentials.yaml"));
|
|
1279
|
+
const match = String(raw ?? "").match(/^console_url:\s*["']?([^"'\r\n#]+)/m);
|
|
465
1280
|
const value = match?.[1]?.trim();
|
|
466
|
-
|
|
1281
|
+
return value && value.length > 0 ? trimTrailingSlash(value) : null;
|
|
467
1282
|
} catch {
|
|
1283
|
+
return null;
|
|
468
1284
|
}
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
1285
|
+
}
|
|
1286
|
+
function defaultReadFile2(p) {
|
|
1287
|
+
return readFileSync8(p, "utf8");
|
|
1288
|
+
}
|
|
1289
|
+
function readDiscoveryFileConsoleUrl(repoRoot, { readDiscovery: readDiscovery2 = defaultReadFile2 } = {}) {
|
|
1290
|
+
if (!repoRoot) return null;
|
|
1291
|
+
try {
|
|
1292
|
+
const discovery = String(readDiscovery2(join9(repoRoot, ".heyspex", "console-url")) ?? "").trim();
|
|
1293
|
+
if (discovery.length > 0) return trimTrailingSlash(discovery);
|
|
1294
|
+
} catch {
|
|
1295
|
+
}
|
|
1296
|
+
return null;
|
|
1297
|
+
}
|
|
1298
|
+
var ConsoleUrlUnresolvedError = class extends Error {
|
|
1299
|
+
constructor() {
|
|
1300
|
+
super(
|
|
1301
|
+
"resolveConsoleUrl: local reliance with no HEYSPEX_CONSOLE_URL env, no console_url: in ~/.heyspex/credentials.yaml, and no .heyspex/console-url discovery file \u2014 refusing to silently fall back to the localhost:3000 default in strict mode."
|
|
1302
|
+
);
|
|
1303
|
+
this.name = "ConsoleUrlUnresolvedError";
|
|
1304
|
+
}
|
|
1305
|
+
};
|
|
1306
|
+
function resolveModeEnvelope({ env, homeDir }) {
|
|
1307
|
+
try {
|
|
1308
|
+
const resolved = resolveDevMode({ env, homeDir });
|
|
1309
|
+
return {
|
|
1310
|
+
reliance: resolved.reliance === "cloud" ? "cloud" : "local",
|
|
1311
|
+
consoleUrl: resolved.consoleUrl || DEFAULT_CONSOLE_URL
|
|
1312
|
+
};
|
|
1313
|
+
} catch {
|
|
1314
|
+
return { reliance: "local", consoleUrl: DEFAULT_CONSOLE_URL };
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
function resolveConsoleUrl({
|
|
1318
|
+
repoRoot,
|
|
1319
|
+
env = process.env,
|
|
1320
|
+
homeDir = heyspexHome(),
|
|
1321
|
+
strict = false,
|
|
1322
|
+
devMode,
|
|
1323
|
+
log = (line) => process.stderr.write(line),
|
|
1324
|
+
readFile = defaultReadFile2,
|
|
1325
|
+
readDiscovery: readDiscovery2 = defaultReadFile2
|
|
1326
|
+
} = {}) {
|
|
1327
|
+
const envUrl = env.HEYSPEX_CONSOLE_URL?.trim();
|
|
1328
|
+
if (envUrl) return trimTrailingSlash(envUrl);
|
|
1329
|
+
const mode = devMode ?? resolveModeEnvelope({ env, homeDir });
|
|
1330
|
+
const cloud = mode.reliance === "cloud";
|
|
1331
|
+
const derivedUrl = trimTrailingSlash(
|
|
1332
|
+
cloud && isLoopbackConsoleUrl(mode.consoleUrl) ? CLOUD_CONSOLE_URL : mode.consoleUrl || DEFAULT_CONSOLE_URL
|
|
1333
|
+
);
|
|
1334
|
+
const credentialsUrl = readCredentialsConsoleUrl({ homeDir, readFile });
|
|
1335
|
+
if (credentialsUrl) {
|
|
1336
|
+
if (cloud && isLoopbackConsoleUrl(credentialsUrl)) {
|
|
1337
|
+
warnStaleLoopbackCredentialsOnce(credentialsUrl, derivedUrl, { log });
|
|
1338
|
+
} else {
|
|
1339
|
+
return credentialsUrl;
|
|
476
1340
|
}
|
|
477
1341
|
}
|
|
478
|
-
|
|
1342
|
+
if (!cloud) {
|
|
1343
|
+
const discoveryUrl = readDiscoveryFileConsoleUrl(repoRoot, { readDiscovery: readDiscovery2 });
|
|
1344
|
+
if (discoveryUrl) return discoveryUrl;
|
|
1345
|
+
if (strict) throw new ConsoleUrlUnresolvedError();
|
|
1346
|
+
}
|
|
1347
|
+
return derivedUrl;
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
// spex-console/src/lib/cli/defer.ts
|
|
1351
|
+
function resolveSpexConsoleUrl(vaultRoot, readDiscovery2, opts = {}) {
|
|
1352
|
+
return resolveConsoleUrl({
|
|
1353
|
+
repoRoot: vaultRoot,
|
|
1354
|
+
env: opts.env,
|
|
1355
|
+
homeDir: opts.homeDir,
|
|
1356
|
+
readFile: opts.readFile,
|
|
1357
|
+
readDiscovery: readDiscovery2,
|
|
1358
|
+
log: opts.log
|
|
1359
|
+
});
|
|
479
1360
|
}
|
|
480
1361
|
var HELP2 = [
|
|
481
1362
|
"Usage:",
|
|
@@ -499,43 +1380,80 @@ var HELP2 = [
|
|
|
499
1380
|
"Exit codes: 0 ok \xB7 1 usage \xB7 10 not-found \xB7 11 bad-arg \xB7 12 console-unreachable \xB7 13 write-failed"
|
|
500
1381
|
].join("\n");
|
|
501
1382
|
|
|
1383
|
+
// spex-console/bin/run-entry.ts
|
|
1384
|
+
import process2 from "node:process";
|
|
1385
|
+
var BinExit = class extends Error {
|
|
1386
|
+
code;
|
|
1387
|
+
constructor(code) {
|
|
1388
|
+
super(`exit ${code}`);
|
|
1389
|
+
this.name = "BinExit";
|
|
1390
|
+
this.code = code;
|
|
1391
|
+
}
|
|
1392
|
+
};
|
|
1393
|
+
function runEntry(name, main2, options = {}) {
|
|
1394
|
+
const { fallbackCode = 1, unhandledLabel = "unhandled" } = options;
|
|
1395
|
+
void (async () => {
|
|
1396
|
+
try {
|
|
1397
|
+
await main2();
|
|
1398
|
+
} catch (err) {
|
|
1399
|
+
if (err instanceof BinExit) {
|
|
1400
|
+
process2.exitCode = err.code;
|
|
1401
|
+
return;
|
|
1402
|
+
}
|
|
1403
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
1404
|
+
process2.stderr.write(`${name}: ${unhandledLabel}: ${message}
|
|
1405
|
+
`);
|
|
1406
|
+
process2.exitCode = fallbackCode;
|
|
1407
|
+
}
|
|
1408
|
+
})();
|
|
1409
|
+
}
|
|
1410
|
+
|
|
502
1411
|
// spex-console/bin/hs-claim.ts
|
|
503
1412
|
function readDiscovery(p) {
|
|
504
1413
|
try {
|
|
505
|
-
return
|
|
1414
|
+
return readFileSync9(p, "utf-8");
|
|
506
1415
|
} catch {
|
|
507
1416
|
return null;
|
|
508
1417
|
}
|
|
509
1418
|
}
|
|
510
1419
|
async function main() {
|
|
511
|
-
const vaultRoot =
|
|
1420
|
+
const vaultRoot = process3.env.HS_VAULT_ROOT;
|
|
512
1421
|
if (!vaultRoot) {
|
|
513
|
-
|
|
1422
|
+
process3.stderr.write(
|
|
514
1423
|
"hs claim: HS_VAULT_ROOT is not set (the dispatcher must resolve and pass it).\n"
|
|
515
1424
|
);
|
|
516
|
-
|
|
1425
|
+
process3.exitCode = EXIT.USAGE;
|
|
1426
|
+
return;
|
|
517
1427
|
}
|
|
518
|
-
const parsed = parseClaimArgs(
|
|
1428
|
+
const parsed = parseClaimArgs(process3.argv.slice(3));
|
|
519
1429
|
if (parsed.help) {
|
|
520
|
-
|
|
1430
|
+
process3.stdout.write(`${HELP}
|
|
521
1431
|
`);
|
|
522
|
-
|
|
1432
|
+
process3.exitCode = EXIT.OK;
|
|
1433
|
+
return;
|
|
523
1434
|
}
|
|
524
1435
|
if (parsed.error) {
|
|
525
|
-
|
|
1436
|
+
process3.stderr.write(`hs claim: ${parsed.error.message}
|
|
526
1437
|
`);
|
|
527
|
-
|
|
1438
|
+
process3.exitCode = parsed.error.code;
|
|
1439
|
+
return;
|
|
528
1440
|
}
|
|
529
1441
|
const consoleUrl = resolveSpexConsoleUrl(vaultRoot, readDiscovery);
|
|
530
|
-
const
|
|
531
|
-
|
|
1442
|
+
const scoped = resolveControlScopeFromMachine(vaultRoot);
|
|
1443
|
+
if (!scoped.ok) {
|
|
1444
|
+
process3.stderr.write(`hs claim: ${scoped.error.message}
|
|
1445
|
+
`);
|
|
1446
|
+
process3.exitCode = scoped.error.code;
|
|
1447
|
+
return;
|
|
1448
|
+
}
|
|
1449
|
+
const result = await runClaim(parsed.args, {
|
|
1450
|
+
fetchImpl: fetch,
|
|
1451
|
+
consoleUrl,
|
|
1452
|
+
scope: scoped.scope
|
|
1453
|
+
});
|
|
1454
|
+
const sink = result.isError ? process3.stderr : process3.stdout;
|
|
532
1455
|
sink.write(`${parsed.args.json ? JSON.stringify(result.payload) : result.message}
|
|
533
1456
|
`);
|
|
534
|
-
|
|
1457
|
+
process3.exitCode = result.code;
|
|
535
1458
|
}
|
|
536
|
-
|
|
537
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
538
|
-
process2.stderr.write(`hs claim: unhandled: ${message}
|
|
539
|
-
`);
|
|
540
|
-
process2.exit(EXIT.WRITE_FAILED);
|
|
541
|
-
});
|
|
1459
|
+
runEntry("hs claim", main, { fallbackCode: EXIT.WRITE_FAILED });
|