@specforge/cli 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +781 -0
- package/bin/specforge +21 -0
- package/dist/channel.d.ts +27 -0
- package/dist/channel.d.ts.map +1 -0
- package/dist/channel.js +22 -0
- package/dist/channel.js.map +1 -0
- package/dist/cli/commands/configure.d.ts +16 -0
- package/dist/cli/commands/configure.d.ts.map +1 -0
- package/dist/cli/commands/configure.js +186 -0
- package/dist/cli/commands/configure.js.map +1 -0
- package/dist/cli/commands/configure.types.d.ts +110 -0
- package/dist/cli/commands/configure.types.d.ts.map +1 -0
- package/dist/cli/commands/configure.types.js +82 -0
- package/dist/cli/commands/configure.types.js.map +1 -0
- package/dist/cli/commands/debug/call.d.ts +14 -0
- package/dist/cli/commands/debug/call.d.ts.map +1 -0
- package/dist/cli/commands/debug/call.js +96 -0
- package/dist/cli/commands/debug/call.js.map +1 -0
- package/dist/cli/commands/debug/index.d.ts +12 -0
- package/dist/cli/commands/debug/index.d.ts.map +1 -0
- package/dist/cli/commands/debug/index.js +14 -0
- package/dist/cli/commands/debug/index.js.map +1 -0
- package/dist/cli/commands/debug/register.d.ts +11 -0
- package/dist/cli/commands/debug/register.d.ts.map +1 -0
- package/dist/cli/commands/debug/register.js +78 -0
- package/dist/cli/commands/debug/register.js.map +1 -0
- package/dist/cli/commands/debug/test.d.ts +13 -0
- package/dist/cli/commands/debug/test.d.ts.map +1 -0
- package/dist/cli/commands/debug/test.js +91 -0
- package/dist/cli/commands/debug/test.js.map +1 -0
- package/dist/cli/commands/debug/tools.d.ts +13 -0
- package/dist/cli/commands/debug/tools.d.ts.map +1 -0
- package/dist/cli/commands/debug/tools.js +86 -0
- package/dist/cli/commands/debug/tools.js.map +1 -0
- package/dist/cli/commands/debug/types.d.ts +119 -0
- package/dist/cli/commands/debug/types.d.ts.map +1 -0
- package/dist/cli/commands/debug/types.js +36 -0
- package/dist/cli/commands/debug/types.js.map +1 -0
- package/dist/cli/commands/debug/whoami.d.ts +13 -0
- package/dist/cli/commands/debug/whoami.d.ts.map +1 -0
- package/dist/cli/commands/debug/whoami.js +131 -0
- package/dist/cli/commands/debug/whoami.js.map +1 -0
- package/dist/cli/commands/doctor.d.ts +16 -0
- package/dist/cli/commands/doctor.d.ts.map +1 -0
- package/dist/cli/commands/doctor.js +413 -0
- package/dist/cli/commands/doctor.js.map +1 -0
- package/dist/cli/commands/doctor.types.d.ts +180 -0
- package/dist/cli/commands/doctor.types.d.ts.map +1 -0
- package/dist/cli/commands/doctor.types.js +140 -0
- package/dist/cli/commands/doctor.types.js.map +1 -0
- package/dist/cli/commands/feedback.d.ts +27 -0
- package/dist/cli/commands/feedback.d.ts.map +1 -0
- package/dist/cli/commands/feedback.js +262 -0
- package/dist/cli/commands/feedback.js.map +1 -0
- package/dist/cli/commands/feedback.types.d.ts +116 -0
- package/dist/cli/commands/feedback.types.d.ts.map +1 -0
- package/dist/cli/commands/feedback.types.js +65 -0
- package/dist/cli/commands/feedback.types.js.map +1 -0
- package/dist/cli/commands/index.d.ts +15 -0
- package/dist/cli/commands/index.d.ts.map +1 -0
- package/dist/cli/commands/index.js +21 -0
- package/dist/cli/commands/index.js.map +1 -0
- package/dist/cli/commands/init.d.ts +17 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/init.js +773 -0
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/cli/commands/init.types.d.ts +193 -0
- package/dist/cli/commands/init.types.d.ts.map +1 -0
- package/dist/cli/commands/init.types.js +29 -0
- package/dist/cli/commands/init.types.js.map +1 -0
- package/dist/cli/commands/invitations.d.ts +31 -0
- package/dist/cli/commands/invitations.d.ts.map +1 -0
- package/dist/cli/commands/invitations.js +250 -0
- package/dist/cli/commands/invitations.js.map +1 -0
- package/dist/cli/commands/login.d.ts +40 -0
- package/dist/cli/commands/login.d.ts.map +1 -0
- package/dist/cli/commands/login.js +139 -0
- package/dist/cli/commands/login.js.map +1 -0
- package/dist/cli/commands/members.d.ts +55 -0
- package/dist/cli/commands/members.d.ts.map +1 -0
- package/dist/cli/commands/members.js +296 -0
- package/dist/cli/commands/members.js.map +1 -0
- package/dist/cli/commands/scaffold/agent-types.d.ts +54 -0
- package/dist/cli/commands/scaffold/agent-types.d.ts.map +1 -0
- package/dist/cli/commands/scaffold/agent-types.js +22 -0
- package/dist/cli/commands/scaffold/agent-types.js.map +1 -0
- package/dist/cli/commands/scaffold/display.d.ts +56 -0
- package/dist/cli/commands/scaffold/display.d.ts.map +1 -0
- package/dist/cli/commands/scaffold/display.js +217 -0
- package/dist/cli/commands/scaffold/display.js.map +1 -0
- package/dist/cli/commands/scaffold/files.d.ts +99 -0
- package/dist/cli/commands/scaffold/files.d.ts.map +1 -0
- package/dist/cli/commands/scaffold/files.js +122 -0
- package/dist/cli/commands/scaffold/files.js.map +1 -0
- package/dist/cli/commands/scaffold/index.d.ts +13 -0
- package/dist/cli/commands/scaffold/index.d.ts.map +1 -0
- package/dist/cli/commands/scaffold/index.js +12 -0
- package/dist/cli/commands/scaffold/index.js.map +1 -0
- package/dist/cli/commands/scaffold/register.d.ts +11 -0
- package/dist/cli/commands/scaffold/register.d.ts.map +1 -0
- package/dist/cli/commands/scaffold/register.js +11 -0
- package/dist/cli/commands/scaffold/register.js.map +1 -0
- package/dist/cli/commands/scaffold/scaffold.d.ts +11 -0
- package/dist/cli/commands/scaffold/scaffold.d.ts.map +1 -0
- package/dist/cli/commands/scaffold/scaffold.js +728 -0
- package/dist/cli/commands/scaffold/scaffold.js.map +1 -0
- package/dist/cli/commands/scaffold/targets.d.ts +60 -0
- package/dist/cli/commands/scaffold/targets.d.ts.map +1 -0
- package/dist/cli/commands/scaffold/targets.js +251 -0
- package/dist/cli/commands/scaffold/targets.js.map +1 -0
- package/dist/cli/commands/scaffold/types.d.ts +170 -0
- package/dist/cli/commands/scaffold/types.d.ts.map +1 -0
- package/dist/cli/commands/scaffold/types.js +12 -0
- package/dist/cli/commands/scaffold/types.js.map +1 -0
- package/dist/cli/commands/scaffold/utils.d.ts +89 -0
- package/dist/cli/commands/scaffold/utils.d.ts.map +1 -0
- package/dist/cli/commands/scaffold/utils.js +401 -0
- package/dist/cli/commands/scaffold/utils.js.map +1 -0
- package/dist/cli/commands/status.d.ts +19 -0
- package/dist/cli/commands/status.d.ts.map +1 -0
- package/dist/cli/commands/status.js +124 -0
- package/dist/cli/commands/status.js.map +1 -0
- package/dist/cli/commands/status.types.d.ts +37 -0
- package/dist/cli/commands/status.types.d.ts.map +1 -0
- package/dist/cli/commands/status.types.js +7 -0
- package/dist/cli/commands/status.types.js.map +1 -0
- package/dist/cli/commands/switch.d.ts +18 -0
- package/dist/cli/commands/switch.d.ts.map +1 -0
- package/dist/cli/commands/switch.js +134 -0
- package/dist/cli/commands/switch.js.map +1 -0
- package/dist/cli/commands/switch.types.d.ts +123 -0
- package/dist/cli/commands/switch.types.d.ts.map +1 -0
- package/dist/cli/commands/switch.types.js +46 -0
- package/dist/cli/commands/switch.types.js.map +1 -0
- package/dist/cli/config/agent-teams.types.d.ts +120 -0
- package/dist/cli/config/agent-teams.types.d.ts.map +1 -0
- package/dist/cli/config/agent-teams.types.js +23 -0
- package/dist/cli/config/agent-teams.types.js.map +1 -0
- package/dist/cli/config/index.d.ts +13 -0
- package/dist/cli/config/index.d.ts.map +1 -0
- package/dist/cli/config/index.js +7 -0
- package/dist/cli/config/index.js.map +1 -0
- package/dist/cli/config/loader.d.ts +114 -0
- package/dist/cli/config/loader.d.ts.map +1 -0
- package/dist/cli/config/loader.js +198 -0
- package/dist/cli/config/loader.js.map +1 -0
- package/dist/cli/config/paths.d.ts +107 -0
- package/dist/cli/config/paths.d.ts.map +1 -0
- package/dist/cli/config/paths.js +79 -0
- package/dist/cli/config/paths.js.map +1 -0
- package/dist/cli/config/planning-sessions-registry.d.ts +52 -0
- package/dist/cli/config/planning-sessions-registry.d.ts.map +1 -0
- package/dist/cli/config/planning-sessions-registry.js +46 -0
- package/dist/cli/config/planning-sessions-registry.js.map +1 -0
- package/dist/cli/config/types.d.ts +186 -0
- package/dist/cli/config/types.d.ts.map +1 -0
- package/dist/cli/config/types.js +27 -0
- package/dist/cli/config/types.js.map +1 -0
- package/dist/cli/config/validation.d.ts +62 -0
- package/dist/cli/config/validation.d.ts.map +1 -0
- package/dist/cli/config/validation.js +133 -0
- package/dist/cli/config/validation.js.map +1 -0
- package/dist/cli/config/writer.d.ts +153 -0
- package/dist/cli/config/writer.d.ts.map +1 -0
- package/dist/cli/config/writer.js +168 -0
- package/dist/cli/config/writer.js.map +1 -0
- package/dist/cli/index.d.ts +30 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +142 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/middleware/auth-guard.d.ts +107 -0
- package/dist/cli/middleware/auth-guard.d.ts.map +1 -0
- package/dist/cli/middleware/auth-guard.js +97 -0
- package/dist/cli/middleware/auth-guard.js.map +1 -0
- package/dist/cli/middleware/error-handler.d.ts +133 -0
- package/dist/cli/middleware/error-handler.d.ts.map +1 -0
- package/dist/cli/middleware/error-handler.js +139 -0
- package/dist/cli/middleware/error-handler.js.map +1 -0
- package/dist/cli/middleware/index.d.ts +6 -0
- package/dist/cli/middleware/index.d.ts.map +1 -0
- package/dist/cli/middleware/index.js +3 -0
- package/dist/cli/middleware/index.js.map +1 -0
- package/dist/cli/templates/agents/content/core/sfag-orchestrator.d.ts +9 -0
- package/dist/cli/templates/agents/content/core/sfag-orchestrator.d.ts.map +1 -0
- package/dist/cli/templates/agents/content/core/sfag-orchestrator.js +160 -0
- package/dist/cli/templates/agents/content/core/sfag-orchestrator.js.map +1 -0
- package/dist/cli/templates/agents/content/core/sfag-spec-creator.d.ts +9 -0
- package/dist/cli/templates/agents/content/core/sfag-spec-creator.d.ts.map +1 -0
- package/dist/cli/templates/agents/content/core/sfag-spec-creator.js +343 -0
- package/dist/cli/templates/agents/content/core/sfag-spec-creator.js.map +1 -0
- package/dist/cli/templates/agents/content/core/sfag-ticket-implementer.d.ts +9 -0
- package/dist/cli/templates/agents/content/core/sfag-ticket-implementer.d.ts.map +1 -0
- package/dist/cli/templates/agents/content/core/sfag-ticket-implementer.js +254 -0
- package/dist/cli/templates/agents/content/core/sfag-ticket-implementer.js.map +1 -0
- package/dist/cli/templates/agents/content/research/sfag-package-researcher.d.ts +8 -0
- package/dist/cli/templates/agents/content/research/sfag-package-researcher.d.ts.map +1 -0
- package/dist/cli/templates/agents/content/research/sfag-package-researcher.js +128 -0
- package/dist/cli/templates/agents/content/research/sfag-package-researcher.js.map +1 -0
- package/dist/cli/templates/agents/index.d.ts +23 -0
- package/dist/cli/templates/agents/index.d.ts.map +1 -0
- package/dist/cli/templates/agents/index.js +29 -0
- package/dist/cli/templates/agents/index.js.map +1 -0
- package/dist/cli/templates/commands.d.ts +17 -0
- package/dist/cli/templates/commands.d.ts.map +1 -0
- package/dist/cli/templates/commands.js +78 -0
- package/dist/cli/templates/commands.js.map +1 -0
- package/dist/cli/templates/content/sf-blockers.d.ts +7 -0
- package/dist/cli/templates/content/sf-blockers.d.ts.map +1 -0
- package/dist/cli/templates/content/sf-blockers.js +69 -0
- package/dist/cli/templates/content/sf-blockers.js.map +1 -0
- package/dist/cli/templates/content/sf-commit.d.ts +7 -0
- package/dist/cli/templates/content/sf-commit.d.ts.map +1 -0
- package/dist/cli/templates/content/sf-commit.js +79 -0
- package/dist/cli/templates/content/sf-commit.js.map +1 -0
- package/dist/cli/templates/content/sf-context.d.ts +7 -0
- package/dist/cli/templates/content/sf-context.d.ts.map +1 -0
- package/dist/cli/templates/content/sf-context.js +63 -0
- package/dist/cli/templates/content/sf-context.js.map +1 -0
- package/dist/cli/templates/content/sf-help.d.ts +7 -0
- package/dist/cli/templates/content/sf-help.d.ts.map +1 -0
- package/dist/cli/templates/content/sf-help.js +42 -0
- package/dist/cli/templates/content/sf-help.js.map +1 -0
- package/dist/cli/templates/content/sf-init.d.ts +7 -0
- package/dist/cli/templates/content/sf-init.d.ts.map +1 -0
- package/dist/cli/templates/content/sf-init.js +62 -0
- package/dist/cli/templates/content/sf-init.js.map +1 -0
- package/dist/cli/templates/content/sf-reset.d.ts +7 -0
- package/dist/cli/templates/content/sf-reset.d.ts.map +1 -0
- package/dist/cli/templates/content/sf-reset.js +67 -0
- package/dist/cli/templates/content/sf-reset.js.map +1 -0
- package/dist/cli/templates/content/sf-search.d.ts +7 -0
- package/dist/cli/templates/content/sf-search.d.ts.map +1 -0
- package/dist/cli/templates/content/sf-search.js +63 -0
- package/dist/cli/templates/content/sf-search.js.map +1 -0
- package/dist/cli/templates/content/sf-status.d.ts +7 -0
- package/dist/cli/templates/content/sf-status.d.ts.map +1 -0
- package/dist/cli/templates/content/sf-status.js +62 -0
- package/dist/cli/templates/content/sf-status.js.map +1 -0
- package/dist/cli/templates/index.d.ts +8 -0
- package/dist/cli/templates/index.d.ts.map +1 -0
- package/dist/cli/templates/index.js +17 -0
- package/dist/cli/templates/index.js.map +1 -0
- package/dist/cli/ui/banner.d.ts +38 -0
- package/dist/cli/ui/banner.d.ts.map +1 -0
- package/dist/cli/ui/banner.js +89 -0
- package/dist/cli/ui/banner.js.map +1 -0
- package/dist/cli/ui/colors.d.ts +76 -0
- package/dist/cli/ui/colors.d.ts.map +1 -0
- package/dist/cli/ui/colors.js +67 -0
- package/dist/cli/ui/colors.js.map +1 -0
- package/dist/cli/ui/index.d.ts +7 -0
- package/dist/cli/ui/index.d.ts.map +1 -0
- package/dist/cli/ui/index.js +4 -0
- package/dist/cli/ui/index.js.map +1 -0
- package/dist/cli/ui/output.d.ts +117 -0
- package/dist/cli/ui/output.d.ts.map +1 -0
- package/dist/cli/ui/output.js +83 -0
- package/dist/cli/ui/output.js.map +1 -0
- package/dist/cli/ui/spinner.d.ts +120 -0
- package/dist/cli/ui/spinner.d.ts.map +1 -0
- package/dist/cli/ui/spinner.js +158 -0
- package/dist/cli/ui/spinner.js.map +1 -0
- package/dist/cli/ui/time.d.ts +54 -0
- package/dist/cli/ui/time.d.ts.map +1 -0
- package/dist/cli/ui/time.js +119 -0
- package/dist/cli/ui/time.js.map +1 -0
- package/dist/client/api-client.d.ts +123 -0
- package/dist/client/api-client.d.ts.map +1 -0
- package/dist/client/api-client.js +105 -0
- package/dist/client/api-client.js.map +1 -0
- package/dist/client/cli-client.d.ts +26 -0
- package/dist/client/cli-client.d.ts.map +1 -0
- package/dist/client/cli-client.js +20 -0
- package/dist/client/cli-client.js.map +1 -0
- package/dist/config/index.d.ts +78 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +79 -0
- package/dist/config/index.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +73 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/format.d.ts +126 -0
- package/dist/lib/format.d.ts.map +1 -0
- package/dist/lib/format.js +71 -0
- package/dist/lib/format.js.map +1 -0
- package/dist/lib/index.d.ts +11 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +45 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/monorepo-detector.d.ts +31 -0
- package/dist/lib/monorepo-detector.d.ts.map +1 -0
- package/dist/lib/monorepo-detector.js +188 -0
- package/dist/lib/monorepo-detector.js.map +1 -0
- package/dist/lib/prompt-generator.d.ts +65 -0
- package/dist/lib/prompt-generator.d.ts.map +1 -0
- package/dist/lib/prompt-generator.js +162 -0
- package/dist/lib/prompt-generator.js.map +1 -0
- package/dist/lib/strategy-analyzer.d.ts +59 -0
- package/dist/lib/strategy-analyzer.d.ts.map +1 -0
- package/dist/lib/strategy-analyzer.js +91 -0
- package/dist/lib/strategy-analyzer.js.map +1 -0
- package/dist/lib/workflow-definitions.d.ts +41 -0
- package/dist/lib/workflow-definitions.d.ts.map +1 -0
- package/dist/lib/workflow-definitions.js +497 -0
- package/dist/lib/workflow-definitions.js.map +1 -0
- package/dist/patterns/index.d.ts +9 -0
- package/dist/patterns/index.d.ts.map +1 -0
- package/dist/patterns/index.js +21 -0
- package/dist/patterns/index.js.map +1 -0
- package/dist/patterns/inheritance.d.ts +193 -0
- package/dist/patterns/inheritance.d.ts.map +1 -0
- package/dist/patterns/inheritance.js +125 -0
- package/dist/patterns/inheritance.js.map +1 -0
- package/dist/server.d.ts +44 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +91 -0
- package/dist/server.js.map +1 -0
- package/dist/tools/core/context-helper.d.ts +50 -0
- package/dist/tools/core/context-helper.d.ts.map +1 -0
- package/dist/tools/core/context-helper.js +49 -0
- package/dist/tools/core/context-helper.js.map +1 -0
- package/dist/tools/core/index.d.ts +2 -0
- package/dist/tools/core/index.d.ts.map +1 -0
- package/dist/tools/core/index.js +2 -0
- package/dist/tools/core/index.js.map +1 -0
- package/dist/tools/index.d.ts +58 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +1499 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/transport/__tests__/resolve-endpoint.test.d.ts +6 -0
- package/dist/transport/__tests__/resolve-endpoint.test.d.ts.map +1 -0
- package/dist/transport/index.d.ts +6 -0
- package/dist/transport/index.d.ts.map +1 -0
- package/dist/transport/index.js +5 -0
- package/dist/transport/index.js.map +1 -0
- package/dist/transport/interface.d.ts +25 -0
- package/dist/transport/interface.d.ts.map +1 -0
- package/dist/transport/interface.js +1 -0
- package/dist/transport/interface.js.map +1 -0
- package/dist/transport/remote.d.ts +38 -0
- package/dist/transport/remote.d.ts.map +1 -0
- package/dist/transport/remote.js +107 -0
- package/dist/transport/remote.js.map +1 -0
- package/dist/transport/resolve-endpoint.d.ts +58 -0
- package/dist/transport/resolve-endpoint.d.ts.map +1 -0
- package/dist/transport/resolve-endpoint.js +146 -0
- package/dist/transport/resolve-endpoint.js.map +1 -0
- package/dist/types/index.d.ts +212 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +16 -0
- package/dist/types/index.js.map +1 -0
- package/dist/validation/index.d.ts +86 -0
- package/dist/validation/index.d.ts.map +1 -0
- package/dist/validation/index.js +392 -0
- package/dist/validation/index.js.map +1 -0
- package/dist/validation/ticket-validation.d.ts +162 -0
- package/dist/validation/ticket-validation.d.ts.map +1 -0
- package/dist/validation/ticket-validation.js +188 -0
- package/dist/validation/ticket-validation.js.map +1 -0
- package/package.json +69 -0
- package/src/cli/templates/agents/content/core/sfag-orchestrator.ts +165 -0
- package/src/cli/templates/agents/content/core/sfag-spec-creator.ts +348 -0
- package/src/cli/templates/agents/content/core/sfag-ticket-implementer.ts +259 -0
- package/src/cli/templates/agents/content/research/sfag-package-researcher.ts +132 -0
- package/src/cli/templates/agents/index.ts +47 -0
- package/src/cli/templates/commands.ts +90 -0
- package/src/cli/templates/content/sf-blockers.ts +71 -0
- package/src/cli/templates/content/sf-commit.ts +81 -0
- package/src/cli/templates/content/sf-context.ts +65 -0
- package/src/cli/templates/content/sf-help.ts +44 -0
- package/src/cli/templates/content/sf-init.ts +64 -0
- package/src/cli/templates/content/sf-reset.ts +69 -0
- package/src/cli/templates/content/sf-search.ts +65 -0
- package/src/cli/templates/content/sf-status.ts +64 -0
- package/src/cli/templates/index.ts +16 -0
- package/src/cli/templates/skills/specforge-conventions.md +114 -0
- package/src/cli/templates/skills/specforge-orchestrator.md +409 -0
- package/src/cli/templates/skills/specforge-validator.md +128 -0
- package/src/cli/templates/skills/specforge-worker.md +412 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/tools/index.ts"],"sourcesContent":["/**\n * MCP Tools Registry\n *\n * This module defines and exports all available MCP tools.\n * 22 tools organized into: Queries, Lifecycle, Mutation, Utilities, Orchestration.\n */\n\nimport { ApiClient } from '../client/api-client.js';\nimport {\n ValidationError,\n ApiError,\n validateToolArgs,\n formatMCPError,\n transformError,\n MCPErrorResponse,\n} from '../validation/index.js';\nimport { injectContext, injectContextRequired } from './core/context-helper.js';\nimport { tryLoadProjectConfig, saveProjectConfig } from '../cli/config/index.js';\nimport {\n appendPlanningSessionRegistry,\n markPlanningSessionRegistryCompleted,\n} from '../cli/config/planning-sessions-registry.js';\n\n/**\n * Tool definition matching MCP protocol schema\n */\nexport interface Tool {\n name: string;\n description: string;\n inputSchema: {\n type: 'object';\n properties: Record<string, unknown>;\n required?: string[];\n };\n}\n\n/**\n * Get list of all available tools\n *\n * @returns Array of tool definitions (22 tools)\n */\nexport function getTools(): Tool[] {\n const tools: Tool[] = [\n // ========================================================================\n // Queries (6)\n // ========================================================================\n {\n name: 'get',\n description: 'Get a single entity by type and ID.',\n inputSchema: {\n type: 'object',\n properties: {\n type: {\n type: 'string',\n enum: ['project', 'specification', 'epic', 'ticket', 'implementation_session'],\n description: 'Entity type to retrieve',\n },\n id: {\n type: 'string',\n description: 'Entity ID (for project, specification, epic, ticket)',\n },\n specificationId: {\n type: 'string',\n description: 'Specification ID (for implementation_session)',\n },\n },\n required: ['type'],\n },\n },\n {\n name: 'list',\n description: 'List entities by type.',\n inputSchema: {\n type: 'object',\n properties: {\n type: {\n type: 'string',\n enum: ['projects', 'specifications', 'epics', 'tickets'],\n description: 'Entity type to list',\n },\n projectId: {\n type: 'string',\n description: 'Filter by project (for specifications)',\n },\n specificationId: {\n type: 'string',\n description: 'Filter by specification (for epics, tickets)',\n },\n epicId: {\n type: 'string',\n description: 'Filter by epic (for tickets)',\n },\n },\n required: ['type'],\n },\n },\n {\n name: 'search',\n description: `Unified ticket search with multiple filter options.\n\nCombines:\n- Full-text search (query)\n- File matching (files) - replaces find_tickets_by_file\n- Tag filtering (tags) - replaces find_tickets_by_tag\n- Related tickets (relatedTo) - replaces find_related_tickets\n- Status, complexity, priority filters\n\nAt least one of: query, files, tags, or relatedTo is required.\nAt least one scope filter (projectId, specificationId, or epicId) is required.`,\n inputSchema: {\n type: 'object',\n properties: {\n query: {\n type: 'string',\n description: 'Full-text search query',\n },\n files: {\n type: 'array',\n items: { type: 'string' },\n description: 'Glob patterns to match ticket files (e.g., \"**/channel/*.ts\")',\n },\n tags: {\n type: 'array',\n items: { type: 'string' },\n description: 'Tags to filter by',\n },\n matchAllTags: {\n type: 'boolean',\n description: 'If true, match all tags (AND). If false, match any (OR). Default: false',\n },\n relatedTo: {\n type: 'string',\n description: 'Find tickets related to this ticket ID (by tags, files, tech stack)',\n },\n status: {\n type: 'array',\n items: {\n type: 'string',\n enum: ['pending', 'ready', 'active', 'done'],\n },\n description: 'Filter by status',\n },\n complexity: {\n type: 'array',\n items: {\n type: 'string',\n enum: ['small', 'medium', 'large', 'xlarge'],\n },\n description: 'Filter by complexity',\n },\n priority: {\n type: 'array',\n items: {\n type: 'string',\n enum: ['low', 'medium', 'high', 'critical'],\n },\n description: 'Filter by priority',\n },\n projectId: {\n type: 'string',\n description: 'Limit search to project',\n },\n specificationId: {\n type: 'string',\n description: 'Limit search to specification',\n },\n epicId: {\n type: 'string',\n description: 'Limit search to epic',\n },\n limit: {\n type: 'number',\n description: 'Maximum results (default: 20, max: 100)',\n },\n offset: {\n type: 'number',\n description: 'Pagination offset (default: 0)',\n },\n fields: {\n type: 'array',\n items: {\n type: 'string',\n enum: [\n 'id',\n 'epicId',\n 'ticketNumber',\n 'title',\n 'description',\n 'status',\n 'priority',\n 'complexity',\n 'estimatedHours',\n 'actualHours',\n 'acceptanceCriteria',\n 'implementation',\n 'technicalDetails',\n 'notes',\n 'tags',\n 'blockReason',\n 'progress',\n 'testsPassed',\n 'order',\n 'startedAt',\n 'completedAt',\n 'createdAt',\n 'updatedAt',\n ],\n },\n description:\n 'Select specific fields to return. Returns all fields if not specified. id is always included.',\n },\n },\n },\n },\n {\n name: 'get_next_actionable_tickets',\n description: 'Get tickets with status \"ready\" (all dependencies satisfied). Use start_work_session() to begin work on these tickets.',\n inputSchema: {\n type: 'object',\n properties: {\n specificationId: {\n type: 'string',\n description: 'The ID of the specification (optional if projectId provided)',\n },\n projectId: {\n type: 'string',\n description: 'The ID of the project to get actionable tickets across all specifications',\n },\n limit: {\n type: 'number',\n description: 'Maximum number of tickets to return (default: 5)',\n },\n },\n },\n },\n {\n name: 'get_blocked_tickets',\n description: 'Get tickets with status \"pending\" and their statusReason explaining why they are blocked (unsatisfied dependencies or external block)',\n inputSchema: {\n type: 'object',\n properties: {\n specificationId: {\n type: 'string',\n description: 'The ID of the specification',\n },\n },\n required: ['specificationId'],\n },\n },\n {\n name: 'get_report',\n description: `Generate unified reports for implementation, time tracking, blockers, work summary, or active sessions.\n\nReport types:\n- 'implementation': Progress, velocity, completions (replaces get_implementation_summary)\n- 'time': Estimated vs actual hours (replaces get_time_report)\n- 'blockers': Blocked tickets with reasons (replaces get_blockers_report)\n- 'work': Completed work summary from WorkSession records (replaces get_work_summary)\n- 'implementation_analysis': Deeper implementation insights\n- 'sessions': Live planning/work/review sessions for a project (requires scope='project')\n\nFormat options:\n- 'json': Full structured data (default)\n- 'summary': Condensed text summary`,\n inputSchema: {\n type: 'object',\n properties: {\n type: {\n type: 'string',\n enum: ['implementation', 'time', 'blockers', 'work', 'implementation_analysis', 'sessions'],\n description: 'Type of report to generate',\n },\n scope: {\n type: 'string',\n enum: ['project', 'specification', 'epic'],\n description: \"Scope of the report. 'sessions' requires scope='project'.\",\n },\n scopeId: {\n type: 'string',\n description: 'ID of the scoped entity (projectId, specificationId, or epicId)',\n },\n startDate: {\n type: 'string',\n description: 'Start date for work report (ISO 8601)',\n },\n endDate: {\n type: 'string',\n description: 'End date for work report (ISO 8601)',\n },\n },\n required: ['type', 'scope', 'scopeId'],\n },\n },\n\n // ========================================================================\n // Lifecycle (10)\n // ========================================================================\n {\n name: 'start_planning_session',\n description: 'Start or resume a guided planning session for a specification. Project-scoped lock: only one active planning session per project (the project is derived from the spec — you do not pass it). Calling with the same spec resumes the existing session (idempotent). Calling with a different spec while one is active returns a rejection with the active session details. Planning is independent of implementation and review — they can run concurrently.',\n inputSchema: {\n type: 'object',\n properties: {\n specificationId: {\n type: 'string',\n description: 'The specification to plan. Optional — defaults to the active spec in the local config (.specforge/config.json), so you normally omit it. Do NOT pass projectId; it is derived from the spec.',\n },\n },\n // Nothing is required: specificationId falls back to local config, and the\n // returned sessionId is persisted + injected into subsequent calls.\n required: [],\n },\n },\n {\n name: 'action_planning_session',\n description: \"Execute a planning action within an active session. Wraps all planning operations (create/update epics, tickets, dependencies, blueprints) and read operations (get_ticket for inspecting details, gps for full readiness X-ray worst-first) with automatic status tracking. The spec status advances or regresses automatically based on the action type and gate checks. Returns updated progress, blockers, and next suggested actions after every call. Use responseDetail to control verbosity: 'minimal' (~80 tokens) for rapid iteration, 'standard' (~200 tokens, default) for normal work, 'full' (~500 tokens) for debugging.\",\n inputSchema: {\n type: 'object',\n properties: {\n operation: {\n type: 'object',\n description: 'The operation to perform. Must include a \"type\" field. Per-op required fields are declared in `oneOf` below — agents should consult their own tool schema parser for the exact shape per type. Do NOT pass sessionId/projectId/specificationId: the active planning session is injected from local config.',\n properties: {\n type: {\n type: 'string',\n enum: [\n 'set_metadata',\n 'create_epic',\n 'update_epic',\n 'create_ticket',\n 'update_ticket',\n 'delete_epic',\n 'delete_ticket',\n 'add_dependencies',\n 'remove_dependency',\n 'create_blueprint',\n 'link_blueprint',\n 'update_blueprint',\n 'delete_blueprint',\n 'unlink_blueprint',\n 'get_ticket',\n 'get_status',\n 'gps',\n ],\n description: 'The type of planning operation to perform',\n },\n },\n required: ['type'],\n oneOf: [\n {\n properties: { type: { const: 'set_metadata' } },\n required: ['type'],\n },\n {\n properties: {\n type: { const: 'create_epic' },\n title: { type: 'string', minLength: 1, description: 'Epic title (non-empty)' },\n description: { type: 'string', minLength: 1, description: 'What this epic delivers' },\n objective: { type: 'string', minLength: 1, description: 'Goal achieved for the user' },\n goals: { type: 'array', items: { type: 'string' } },\n acceptanceCriteria: { type: 'array', items: { type: 'string' } },\n tickets: { type: 'array', description: 'Optional bulk-create tickets within the epic' },\n },\n required: ['type', 'title', 'description', 'objective'],\n },\n {\n properties: {\n type: { const: 'update_epic' },\n epicId: { type: 'string', description: 'Epic id; use list_epics or lookup_epic to find' },\n },\n required: ['type', 'epicId'],\n },\n {\n properties: {\n type: { const: 'create_ticket' },\n epicId: { type: 'string', description: 'Parent epic id' },\n title: { type: 'string', minLength: 1, description: 'Ticket title (non-empty)' },\n description: { type: 'string' },\n ticketType: { type: 'string', enum: ['implementation', 'verification'], description: 'Ticket type — implementation (default) or verification (tests/QA). Drives which fields the readiness rubric expects.' },\n priority: { type: 'string', enum: ['high', 'medium', 'low'] },\n complexity: { type: 'string', enum: ['small', 'medium', 'large', 'xlarge'] },\n acceptanceCriteria: { type: 'array', items: { type: 'string' } },\n implementationSteps: { type: 'array', items: { type: 'string' }, description: 'Implementation steps; persisted as TicketImplementationStep rows' },\n dependsOn: { type: 'array', items: { type: 'string' }, description: 'Other ticket ids this depends on; created post-insert' },\n },\n required: ['type', 'epicId', 'title'],\n },\n {\n properties: {\n type: { const: 'update_ticket' },\n ticketId: { type: 'string', description: 'Ticket id; use list_tickets or lookup_ticket to find' },\n },\n required: ['type', 'ticketId'],\n },\n {\n properties: {\n type: { const: 'delete_epic' },\n epicId: { type: 'string', description: 'Epic id; cascades to all tickets in the epic' },\n },\n required: ['type', 'epicId'],\n },\n {\n properties: {\n type: { const: 'delete_ticket' },\n ticketId: { type: 'string' },\n },\n required: ['type', 'ticketId'],\n },\n {\n properties: {\n type: { const: 'add_dependencies' },\n dependencies: {\n type: 'array',\n minItems: 1,\n maxItems: 100,\n description: 'Up to 100 dependency pairs. Valid pairs commit; malformed pairs come back in failed[] with a per-entry reason.',\n items: {\n type: 'object',\n properties: {\n ticketId: { type: 'string', description: 'The dependent ticket' },\n dependsOnId: { type: 'string', description: 'The blocker ticket' },\n type: { type: 'string', enum: ['requires', 'blocks'], description: 'Defaults to \"requires\"' },\n },\n required: ['ticketId', 'dependsOnId'],\n },\n },\n },\n required: ['type', 'dependencies'],\n },\n {\n properties: {\n type: { const: 'remove_dependency' },\n dependencyId: { type: 'string' },\n },\n required: ['type', 'dependencyId'],\n },\n {\n properties: {\n type: { const: 'remove_dependency' },\n ticketId: { type: 'string' },\n dependsOnId: { type: 'string' },\n },\n required: ['type', 'ticketId', 'dependsOnId'],\n },\n {\n properties: {\n type: { const: 'create_blueprint' },\n title: { type: 'string', minLength: 1, description: 'Blueprint title (non-empty)' },\n content: { type: 'string', description: 'Body. Mermaid format extracts ```mermaid``` fences automatically.' },\n format: { type: 'string', description: 'Defaults to \"mermaid\"' },\n category: { type: 'string' },\n description: { type: 'string' },\n tags: { type: 'array', items: { type: 'string' } },\n },\n required: ['type', 'title'],\n },\n {\n properties: {\n type: { const: 'update_blueprint' },\n blueprintId: { type: 'string' },\n },\n required: ['type', 'blueprintId'],\n },\n {\n properties: {\n type: { const: 'delete_blueprint' },\n blueprintId: { type: 'string' },\n },\n required: ['type', 'blueprintId'],\n },\n {\n properties: {\n type: { const: 'link_blueprint' },\n ticketId: { type: 'string' },\n blueprintId: { type: 'string' },\n context: { type: 'string', description: 'Optional context annotation' },\n section: { type: 'string', description: 'Optional section reference' },\n },\n required: ['type', 'ticketId', 'blueprintId'],\n },\n {\n properties: {\n type: { const: 'unlink_blueprint' },\n referenceId: { type: 'string' },\n },\n required: ['type', 'referenceId'],\n },\n {\n properties: {\n type: { const: 'unlink_blueprint' },\n ticketId: { type: 'string' },\n blueprintId: { type: 'string' },\n },\n required: ['type', 'ticketId', 'blueprintId'],\n },\n {\n properties: {\n type: { const: 'get_ticket' },\n ticketId: { type: 'string' },\n include: { type: 'array', items: { type: 'string', enum: ['dependencies', 'testStatus', 'statusReason'] } },\n },\n required: ['type', 'ticketId'],\n },\n {\n properties: { type: { const: 'get_status' } },\n required: ['type'],\n },\n {\n properties: {\n type: { const: 'gps' },\n responseDetail: { type: 'string', enum: ['minimal', 'standard', 'full'] },\n },\n required: ['type'],\n },\n ],\n },\n responseDetail: {\n type: 'string',\n enum: ['minimal', 'standard', 'full'],\n description: 'Response detail level: minimal (~80 tokens), standard (~200, default), full (~500)',\n },\n },\n required: ['operation'],\n },\n },\n {\n name: 'complete_planning_session',\n description: \"Complete the planning session and submit the spec for final review. Spec must be in 'planning' status. Runs the planning gate (consistency checks + readinessThreshold from project/spec settings). Transitions the spec directly to 'ready' on pass. Takes no arguments — the active planning session is injected from local config.\",\n inputSchema: {\n type: 'object',\n // No inputs: the active planning session (sessionId) is injected from\n // local config (.specforge/config.json). Do NOT pass sessionId/projectId/specificationId.\n properties: {},\n required: [],\n },\n },\n {\n name: 'start_work_session',\n description: 'Start working on a ticket. Returns full ticket details (description, implementation steps, AC, technicalDetails, codeReferences, typeReferences, tags, notes, complexity, priority) alongside checklistState and workSessionId. No need to call get_ticket separately. Returns error with statusReason if ticket is pending.',\n inputSchema: {\n type: 'object',\n properties: {\n ticketId: {\n type: 'string',\n description: 'The ID of the ticket to start',\n },\n },\n required: ['ticketId'],\n },\n },\n {\n name: 'action_work_session',\n description: `Update checklist state during an active WorkSession. Combines step completion, AC validation, test result reporting, file tracking, reference review confirmation, and discovery reporting into a single atomic operation. All state changes are recorded on the WorkSession and its related validation/completion records.\n\nUse this instead of calling update_ticket for checklist changes. Provides:\n- Step completion (individual or bulk via WorkSessionStepCompletion)\n- Acceptance criteria validation (individual or bulk via WorkSessionACValidation)\n- Test result reporting (merged by test type via WorkSessionTestResult)\n- File tracking (created, modified, deleted on WorkSession)\n- Discovery reporting (create discoveries for blockers, bugs, tech debt)\n- Blocker management (set block reason; requires existing discovery)\n- Reference review tracking (codeSnippetsReviewed, typeReferencesReviewed)\n- Auto-calculated progress percentage\n- Completion readiness hints\n\nIMPORTANT: All acceptance criteria must be validated and all implementation steps must be completed via this tool before calling complete_work_session. The completion gate enforces this.\n\nIf the ticket has codeReferences or typeReferences, set codeSnippetsReviewed/typeReferencesReviewed to true after reviewing them — completion readiness will block until these are confirmed.\n\nSet getTicket: true to fetch full ticket details in the response — useful for re-reading ticket context mid-implementation. Can be the sole operation or combined with other actions.`,\n inputSchema: {\n type: 'object',\n properties: {\n ticketId: {\n type: 'string',\n description: 'The ID of the ticket being worked on (must be in active status)',\n },\n steps: {\n type: 'array',\n description: 'Individual step completion updates',\n items: {\n type: 'object',\n properties: {\n index: {\n type: 'number',\n description: 'Zero-based index of the step in the implementation.steps array',\n },\n completed: {\n type: 'boolean',\n description: 'Whether the step is completed',\n },\n notes: {\n type: 'string',\n description: 'Optional note about this step',\n },\n },\n required: ['index', 'completed'],\n },\n },\n allStepsDone: {\n type: 'boolean',\n description: 'Shortcut: mark all steps as completed',\n },\n acceptanceCriteria: {\n type: 'array',\n description: 'Individual AC validation updates',\n items: {\n type: 'object',\n properties: {\n index: {\n type: 'number',\n description: 'Zero-based index of the AC in the acceptanceCriteria array',\n },\n validated: {\n type: 'boolean',\n description: 'Whether the AC is validated',\n },\n notes: {\n type: 'string',\n description: 'Optional note about this AC',\n },\n },\n required: ['index', 'validated'],\n },\n },\n allACValidated: {\n type: 'boolean',\n description: 'Shortcut: mark all acceptance criteria as validated',\n },\n testResults: {\n type: 'array',\n description: 'Test result reports to append (merged by testType)',\n items: {\n type: 'object',\n properties: {\n testType: {\n type: 'string',\n description: 'Type of test (e.g., \"unit\", \"integration\", \"e2e\", \"lint\", \"typeCheck\")',\n },\n passed: {\n type: 'number',\n description: 'Number of tests that passed',\n },\n failed: {\n type: 'number',\n description: 'Number of tests that failed',\n },\n skipped: {\n type: 'number',\n description: 'Number of tests skipped',\n },\n command: {\n type: 'string',\n description: 'Command used to run the tests',\n },\n output: {\n type: 'string',\n description: 'Test output (truncated if needed)',\n },\n duration: {\n type: 'number',\n description: 'Duration in milliseconds',\n },\n suites: {\n type: 'array',\n description: 'Optional suite-level breakdown',\n items: {\n type: 'object',\n properties: {\n name: { type: 'string', description: 'Suite name' },\n passed: { type: 'number', description: 'Passed tests in suite' },\n failed: { type: 'number', description: 'Failed tests in suite' },\n skipped: { type: 'number', description: 'Skipped tests in suite' },\n duration: { type: 'number', description: 'Suite duration in ms' },\n },\n required: ['name', 'passed', 'failed'],\n },\n },\n tests: {\n type: 'array',\n description: 'Optional individual test breakdown',\n items: {\n type: 'object',\n properties: {\n name: { type: 'string', description: 'Test name' },\n suite: { type: 'string', description: 'Parent suite name' },\n status: { type: 'string', enum: ['passed', 'failed', 'skipped'], description: 'Test result' },\n duration: { type: 'number', description: 'Test duration in ms' },\n },\n required: ['name', 'status'],\n },\n },\n },\n required: ['testType', 'passed', 'failed'],\n },\n },\n notes: {\n type: 'string',\n description: 'Additional notes to append to the ticket',\n },\n filesCreated: {\n type: 'array',\n items: { type: 'string' },\n description: 'Files created during this session. Accumulated incrementally.',\n },\n filesModified: {\n type: 'array',\n items: { type: 'string' },\n description: 'Files modified during this session. Accumulated incrementally.',\n },\n filesDeleted: {\n type: 'array',\n items: { type: 'string' },\n description: 'Files deleted during this session. Accumulated incrementally.',\n },\n discovery: {\n type: 'object',\n description: 'Create a discovery (observation about the implementation). Use this to report blockers, bugs, tech debt, scope changes, etc.',\n properties: {\n description: { type: 'string', description: 'Description of the discovery' },\n type: { type: 'string', description: 'Discovery type: bug, tech_debt, blocker, clarification, scope_change, dependency, risk, ticket, epic' },\n severity: { type: 'string', description: 'Severity: blocker, critical, major, minor' },\n suggestedTitle: { type: 'string', description: 'Suggested title for the new ticket/epic' },\n suggestedPriority: { type: 'string', description: 'Suggested priority: high, medium, low' },\n relatedFiles: { type: 'array', items: { type: 'string' }, description: 'Related file paths' },\n notes: { type: 'string', description: 'Additional notes' },\n },\n required: ['description'],\n },\n blockReason: {\n type: 'string',\n description: 'Set a blocker on this ticket. Requires an existing discovery (create via discovery parameter first).',\n },\n getTicket: {\n type: 'boolean',\n description: 'Fetch full ticket details. Can be the sole operation or combined with other actions.',\n },\n includeFullContext: {\n type: 'boolean',\n description: 'Include full implementation context in response',\n },\n codeSnippetsReviewed: {\n type: 'boolean',\n description: 'Confirm that code snippets (codeReferences) on the ticket have been reviewed. Required before completion when the ticket has non-empty codeReferences.',\n },\n typeReferencesReviewed: {\n type: 'boolean',\n description: 'Confirm that type references (typeReferences) on the ticket have been reviewed. Required before completion when the ticket has non-empty typeReferences.',\n },\n },\n required: ['ticketId'],\n },\n },\n {\n name: 'complete_work_session',\n description:\n 'Mark a ticket as complete and finalize the active WorkSession. Transitions active -> done. Session data (files, test results, time) is stored on the WorkSession record.\\n\\n' +\n 'All acceptance criteria must be validated and all implementation steps must be completed via action_work_session before calling this. The completion gate enforces this — shortcuts are not available.\\n\\n' +\n 'Automatically recalculates status for dependent tickets and returns cascade info.\\n\\n' +\n 'Optional validation flags can be provided to report test results inline:\\n' +\n '- tests: Unit/integration test results\\n' +\n '- lint: Linting results\\n' +\n '- typeCheck: TypeScript type checking\\n' +\n '- build: Build/compilation results',\n inputSchema: {\n type: 'object',\n properties: {\n ticketId: {\n type: 'string',\n description: 'The ID of the ticket',\n },\n summary: {\n type: 'string',\n description: 'Summary of work completed',\n },\n filesModified: {\n type: 'array',\n items: { type: 'string' },\n description: 'List of files modified',\n },\n filesCreated: {\n type: 'array',\n items: { type: 'string' },\n description: 'List of files created',\n },\n filesDeleted: {\n type: 'array',\n items: { type: 'string' },\n description: 'List of files deleted',\n },\n actualHours: {\n type: 'number',\n description: 'Actual hours spent on the ticket',\n },\n validation: {\n type: 'object',\n description: 'Detailed validation flags for reporting test/lint/build results',\n properties: {\n tests: {\n type: 'string',\n enum: ['passed', 'failed', 'skipped', 'na'],\n description: 'Unit/integration test results',\n },\n lint: {\n type: 'string',\n enum: ['passed', 'failed', 'skipped', 'na'],\n description: 'Linting results',\n },\n typeCheck: {\n type: 'string',\n enum: ['passed', 'failed', 'skipped', 'na'],\n description: 'TypeScript type checking results',\n },\n build: {\n type: 'string',\n enum: ['passed', 'failed', 'skipped', 'na'],\n description: 'Build/compilation results',\n },\n notes: {\n type: 'string',\n description: 'Additional validation notes',\n },\n },\n },\n },\n required: ['ticketId', 'summary'],\n },\n },\n {\n name: 'start_review_session',\n description: 'Start the implementation review lifecycle. Runs the implementation gate and either auto-transitions to \"reviewed\" (on pass) or transitions to \"in_review\" with an active ReviewSession (on fail). Creates correction tickets via action_review_session, then call complete_review_session.',\n inputSchema: {\n type: 'object',\n properties: {\n specificationId: {\n type: 'string',\n description: 'The ID of the specification to review (must be in ready_for_review status)',\n },\n },\n required: ['specificationId'],\n },\n },\n {\n name: 'action_review_session',\n description: 'Address findings in an active review session. Create correction tickets inline or dismiss findings with justification. Only available when specification is in \"in_review\" status.',\n inputSchema: {\n type: 'object',\n properties: {\n specificationId: {\n type: 'string',\n description: 'The ID of the specification',\n },\n reviewSessionId: {\n type: 'string',\n description: 'The review session ID (auto-detected if omitted)',\n },\n findingsAddressed: {\n type: 'array',\n description: 'Findings to address in this action',\n items: {\n type: 'object',\n properties: {\n findingId: {\n type: 'string',\n description: 'The finding ID to address',\n },\n action: {\n type: 'string',\n enum: ['correction_ticket', 'dismissed'],\n description: 'How to address the finding',\n },\n correctionTicket: {\n type: 'object',\n description: 'Inline ticket creation params (required for correction_ticket action)',\n properties: {\n epicId: { type: 'string', description: 'Epic to add the correction ticket to' },\n title: { type: 'string', description: 'Ticket title' },\n description: { type: 'string', description: 'Ticket description' },\n ticketType: { type: 'string', enum: ['implementation', 'verification'], description: 'Ticket type — defaults to implementation.' },\n priority: { type: 'string', enum: ['low', 'medium', 'high', 'critical'] },\n complexity: { type: 'string', enum: ['small', 'medium', 'large', 'xlarge'] },\n estimatedHours: { type: 'number' },\n acceptanceCriteria: { type: 'array', items: { type: 'string' } },\n implementationSteps: { type: 'array', items: { type: 'string' }, description: 'Implementation steps; persisted as TicketImplementationStep rows' },\n tags: { type: 'array', items: { type: 'string' } },\n },\n required: ['epicId', 'title'],\n },\n justification: {\n type: 'string',\n description: 'Required justification when action is \"dismissed\"',\n },\n },\n required: ['findingId', 'action'],\n },\n },\n notes: {\n type: 'string',\n description: 'Optional notes for this review action',\n },\n },\n required: ['specificationId'],\n },\n },\n {\n name: 'complete_review_session',\n description: 'Complete an active review session. All error-severity findings must be addressed. If correction tickets exist, transitions to \"in_progress\". If all findings dismissed, triggers user confirmation flow.',\n inputSchema: {\n type: 'object',\n properties: {\n specificationId: {\n type: 'string',\n description: 'The ID of the specification',\n },\n reviewSessionId: {\n type: 'string',\n description: 'The review session ID (auto-detected if omitted)',\n },\n summary: {\n type: 'string',\n description: 'Optional completion summary',\n },\n confirmAllDismissed: {\n type: 'boolean',\n description: 'Set to true when all findings were dismissed to trigger user confirmation flow',\n },\n },\n required: ['specificationId'],\n },\n },\n {\n name: 'reopen_specification',\n description: 'Reopen a specification in \"ready\" status, regressing to \"planning\". After reopening, call start_planning_session to begin a new planning session.',\n inputSchema: {\n type: 'object',\n properties: {\n specificationId: {\n type: 'string',\n description: 'The ID of the specification to reopen',\n },\n },\n required: ['specificationId'],\n },\n },\n\n // Spec creation is a HUMAN bootstrap step, NOT an agent MCP tool: specs are\n // created via `specforge init` (cli-rest surface), which also writes the new\n // spec id into the local config so the agent's per-call injection finds it.\n // The agent assumes the spec already exists and starts from\n // `start_planning_session`. (Backend keeps `create_specification` REST-only;\n // it was never dispatchable on /local.)\n\n // ========================================================================\n // Utilities (3)\n // ========================================================================\n {\n name: 'feedback',\n description: `Submit and manage feedback about MCP tools. Operations:\n- submit: Submit new feedback (requires category, summary)\n- list: List recent feedback entries\n- get: Get a specific feedback entry by ID`,\n inputSchema: {\n type: 'object',\n properties: {\n operation: {\n type: 'string',\n enum: ['submit', 'list', 'get'],\n description: 'The operation to perform',\n },\n // For submit operation\n category: {\n type: 'string',\n enum: ['bug', 'feature_request', 'usability', 'documentation', 'performance'],\n description: 'Feedback category (required for submit)',\n },\n summary: {\n type: 'string',\n description: 'Brief summary of the feedback (required for submit)',\n },\n severity: {\n type: 'string',\n enum: ['critical', 'high', 'medium', 'low'],\n description: 'Severity level (default: medium)',\n },\n tool: {\n type: 'string',\n description: 'Which MCP tool this relates to',\n },\n toolOperation: {\n type: 'string',\n description: 'Specific operation within the tool',\n },\n details: {\n type: 'string',\n description: 'Extended description',\n },\n expected: {\n type: 'string',\n description: 'Expected behavior',\n },\n actual: {\n type: 'string',\n description: 'Actual behavior',\n },\n errorMessage: {\n type: 'string',\n description: 'Error message if reporting a bug',\n },\n ticketId: {\n type: 'string',\n description: 'Related ticket ID',\n },\n // For list operation\n limit: {\n type: 'number',\n description: 'Maximum entries to return (default: 10)',\n },\n categoryFilter: {\n type: 'string',\n enum: ['bug', 'feature_request', 'usability', 'documentation', 'performance'],\n description: 'Filter by category',\n },\n // For get operation\n feedbackId: {\n type: 'string',\n description: 'Feedback ID to retrieve (required for get)',\n },\n },\n required: ['operation'],\n },\n },\n {\n name: 'reset_work_session',\n description: 'Reset tickets to pending/ready status (calculated from dependencies). Returns statusCalculation showing how many became pending vs ready.',\n inputSchema: {\n type: 'object',\n properties: {\n specificationId: {\n type: 'string',\n description: 'The specification containing the tickets',\n },\n ticketIds: {\n type: 'array',\n items: { type: 'string' },\n description: 'Specific ticket IDs to reset',\n },\n fromTicketId: {\n type: 'string',\n description: 'Reset this ticket and all its dependents',\n },\n epicId: {\n type: 'string',\n description: 'Reset all tickets in this epic',\n },\n allTickets: {\n type: 'boolean',\n description: 'Reset all tickets in the specification',\n },\n resetDependents: {\n type: 'boolean',\n description: 'Also reset tickets that depend on the specified tickets (default: false)',\n },\n includeCompleted: {\n type: 'boolean',\n description: 'Include tickets with done status in the reset (default: false)',\n },\n preserveNotes: {\n type: 'boolean',\n description: 'Keep existing notes on tickets (default: true)',\n },\n clearTestResults: {\n type: 'boolean',\n description: 'Clear test result history (default: false)',\n },\n },\n required: ['specificationId'],\n },\n },\n {\n name: 'link_pull_request',\n description: 'Associate a pull request with a ticket',\n inputSchema: {\n type: 'object',\n properties: {\n ticketId: {\n type: 'string',\n description: 'The ID of the ticket',\n },\n prNumber: {\n type: 'number',\n description: 'PR number (provide this or prUrl)',\n },\n prUrl: {\n type: 'string',\n description: 'Full PR URL (GitHub, GitLab, or Bitbucket)',\n },\n title: {\n type: 'string',\n description: 'PR title',\n },\n author: {\n type: 'string',\n description: 'PR author',\n },\n repoUrl: {\n type: 'string',\n description: 'Repository URL (required if using prNumber)',\n },\n },\n required: ['ticketId'],\n },\n },\n\n // ========================================================================\n // Orchestration (2)\n // ========================================================================\n {\n name: 'get_critical_path',\n description: 'Get the critical execution path for a specification.',\n inputSchema: {\n type: 'object',\n properties: {\n specificationId: {\n type: 'string',\n description: 'Specification ID',\n },\n },\n required: ['specificationId'],\n },\n },\n {\n name: 'get_dependency_tree',\n description: 'Get the full dependency tree for a specification.',\n inputSchema: {\n type: 'object',\n properties: {\n specificationId: {\n type: 'string',\n description: 'Specification ID',\n },\n },\n required: ['specificationId'],\n },\n },\n ];\n\n return tools;\n}\n\n/**\n * Tool handler type - processes arguments and returns a result\n */\ntype ToolHandler = (\n apiClient: ApiClient,\n args: Record<string, unknown>\n) => Promise<unknown>;\n\n/**\n * Retry configuration for transient failures\n */\nconst RETRY_CONFIG = {\n maxRetries: 3,\n initialDelayMs: 500,\n maxDelayMs: 5000,\n backoffMultiplier: 2,\n};\n\n/**\n * Transient error patterns that should trigger retry\n */\nconst TRANSIENT_ERROR_PATTERNS = [\n /ETIMEDOUT/i,\n /ECONNRESET/i,\n /ECONNREFUSED/i,\n /socket hang up/i,\n /network error/i,\n /too many requests/i,\n /rate limit/i,\n /5\\d{2}/, // 5xx status codes\n];\n\n/**\n * Check if an error is transient and should be retried\n */\nfunction isTransientError(error: Error): boolean {\n return TRANSIENT_ERROR_PATTERNS.some(pattern =>\n pattern.test(error.message)\n );\n}\n\n/**\n * Sleep for a given number of milliseconds\n */\nfunction sleep(ms: number): Promise<void> {\n return new Promise(resolve => setTimeout(resolve, ms));\n}\n\n/**\n * Execute a function with retry logic for transient failures\n */\nasync function withRetry<T>(\n fn: () => Promise<T>,\n toolName: string,\n debug: boolean\n): Promise<T> {\n let lastError: Error | null = null;\n let delay = RETRY_CONFIG.initialDelayMs;\n\n for (let attempt = 1; attempt <= RETRY_CONFIG.maxRetries; attempt++) {\n try {\n return await fn();\n } catch (error) {\n lastError = error instanceof Error ? error : new Error(String(error));\n\n if (attempt < RETRY_CONFIG.maxRetries && isTransientError(lastError)) {\n if (debug) {\n console.error(\n `[DEBUG] Tool ${toolName} attempt ${attempt} failed with transient error, retrying in ${delay}ms:`,\n lastError.message\n );\n }\n await sleep(delay);\n delay = Math.min(delay * RETRY_CONFIG.backoffMultiplier, RETRY_CONFIG.maxDelayMs);\n } else {\n break;\n }\n }\n }\n\n throw lastError;\n}\n\n/**\n * Create tool handlers that call the API with proper request formatting\n *\n * @param apiClient - The API client to use for making requests\n * @returns Record of tool handlers keyed by tool name\n */\nexport function createToolHandlers(\n apiClient: ApiClient\n): Record<string, ToolHandler> {\n // Agent `/local` path (M9, approach A): the transport returns the raw M8 body;\n // interpret the envelope here. Lifecycle → unwrap to `agentResponse`; standard\n // error → throw the composed guidance prose (M9.3); raw success → pass through.\n const callLocal = async <T = unknown>(\n op: string,\n args: Record<string, unknown>,\n ): Promise<T> => {\n const body = await apiClient.getTransport().execute<Record<string, unknown>>(op, args);\n if (body && typeof body === 'object') {\n if (body.kind === 'standard_error') {\n // M9.3: the error-guidance composer's `guidance.prose` is the canonical\n // agent-facing message (same verbatim convention as lifecycle guidance);\n // surface it for query-tool errors, falling back to `message` (and to a\n // generic line for INTERNAL, where guidance is always null).\n const guidance = body.guidance as { prose?: unknown } | null | undefined;\n const prose = guidance && typeof guidance.prose === 'string' ? guidance.prose : undefined;\n throw new Error(\n prose ?? (typeof body.message === 'string' ? body.message : `Operation failed: ${op}`),\n );\n }\n if (body.kind === 'lifecycle' && 'agentResponse' in body) {\n return body.agentResponse as T;\n }\n }\n return body as T;\n };\n\n return {\n // ========================================================================\n // Queries — forward the canonical super-tools straight through (the backend\n // owns the `type` dispatch; M9 dropped the old granular-op fan-out).\n // ========================================================================\n get: async (_client, args) => {\n if (!args.type) throw new Error('Missing required argument: type');\n // Project/spec ids inject from config when the agent omits them.\n const withCtx = injectContext(args, ['projectId', 'specificationId']);\n return await callLocal('get', withCtx);\n },\n\n list: async (_client, args) => {\n if (!args.type) throw new Error('Missing required argument: type');\n const withCtx = injectContext(args, ['projectId', 'specificationId']);\n return await callLocal('list', withCtx);\n },\n\n search: async (_client, args) => {\n if (!args.query && !args.files && !args.tags && !args.relatedTo) {\n throw new Error('At least one filter is required: query, files, tags, or relatedTo');\n }\n const withCtx = injectContext(args, ['projectId', 'specificationId']);\n if (!withCtx.projectId && !withCtx.specificationId && !withCtx.epicId) {\n throw new Error('One of projectId, specificationId, or epicId is required. Run \"specforge switch\" or provide explicitly.');\n }\n return await callLocal('search', withCtx);\n },\n\n get_next_actionable_tickets: async (_client, args) => {\n // Inject projectId/specificationId from .specforge.json if not provided\n const argsWithContext = injectContext(args, ['projectId', 'specificationId']);\n\n // Either specificationId or projectId is required (after injection)\n if (!argsWithContext.specificationId && !argsWithContext.projectId) {\n throw new Error('Either specificationId or projectId is required. Set working context with \"specforge switch\" or provide explicitly.');\n }\n return await callLocal('get_next_actionable_tickets', {\n specificationId: argsWithContext.specificationId,\n projectId: argsWithContext.projectId,\n limit: argsWithContext.limit ?? 5,\n });\n },\n\n get_blocked_tickets: async (_client, args) => {\n // Inject specificationId from .specforge.json if not provided\n const argsWithContext = injectContext(args, ['specificationId']);\n\n if (!argsWithContext.specificationId) {\n throw new Error('specificationId is required. Set working context with \"specforge switch\" or provide explicitly.');\n }\n return await callLocal('get_blocked_tickets', {\n specificationId: argsWithContext.specificationId,\n });\n },\n\n get_report: async (_client, args) => {\n validateRequired(args, 'type', 'scope', 'scopeId');\n return await callLocal('get_report', {\n type: args.type,\n scope: args.scope,\n scopeId: args.scopeId,\n format: args.format ?? 'json',\n startDate: args.startDate,\n endDate: args.endDate,\n });\n },\n\n // ========================================================================\n // Lifecycle\n // ========================================================================\n // Planning lifecycle (M9.6b) — identity/session injected from the\n // `.specforge` config; SPS persists the session id, a `closed` status\n // clears it. Payloads match the post-M8 boundary (SPS {specificationId};\n // APS {sessionId, operation:{type,...}}; CPS {sessionId}).\n start_planning_session: async (_client, args) => {\n const cfg = tryLoadProjectConfig();\n const specificationId = (args.specificationId as string) ?? cfg?.specificationId;\n if (!specificationId) {\n throw new Error('No active specification. Run `specforge switch <spec-id>` or pass specificationId.');\n }\n const agentResponse = await callLocal<{ sessionId?: string }>(\n 'start_planning_session',\n { specificationId },\n );\n if (agentResponse?.sessionId) {\n saveProjectConfig({ planningSessionId: agentResponse.sessionId });\n appendPlanningSessionRegistry({\n specificationId,\n planningSessionId: agentResponse.sessionId,\n startedAt: new Date().toISOString(),\n });\n }\n return agentResponse;\n },\n\n action_planning_session: async (_client, args) => {\n if (!args.operation || typeof args.operation !== 'object') {\n throw new Error('Missing required argument: operation (e.g. { type: \"get_planning_status\" })');\n }\n const cfg = tryLoadProjectConfig();\n const sessionId = (args.sessionId as string) ?? cfg?.planningSessionId;\n if (!sessionId) {\n throw new Error('No active planning session. Call start_planning_session first.');\n }\n const agentResponse = await callLocal<{ planningStatus?: string }>(\n 'action_planning_session',\n { sessionId, operation: args.operation },\n );\n // Close detection: clear the persisted session id once it closes.\n if (agentResponse?.planningStatus === 'closed' && cfg?.specificationId) {\n saveProjectConfig({ planningSessionId: undefined });\n markPlanningSessionRegistryCompleted({\n specificationId: cfg.specificationId,\n completedAt: new Date().toISOString(),\n });\n }\n return agentResponse;\n },\n\n complete_planning_session: async (_client, args) => {\n const cfg = tryLoadProjectConfig();\n const sessionId = (args.sessionId as string) ?? cfg?.planningSessionId;\n if (!sessionId) {\n throw new Error('No active planning session. Call start_planning_session first.');\n }\n // CPS-success flips to awaiting_human_review (not closed) — keep the id.\n return await callLocal('complete_planning_session', { sessionId });\n },\n\n start_work_session: async (_client, args) => {\n validateRequired(args, 'ticketId');\n return await callLocal('start_work_session', {\n ticketId: args.ticketId,\n });\n },\n\n action_work_session: async (_client, args) => {\n validateRequired(args, 'ticketId');\n return await callLocal('action_work_session', {\n ticketId: args.ticketId,\n steps: args.steps,\n allStepsDone: args.allStepsDone,\n acceptanceCriteria: args.acceptanceCriteria,\n allACValidated: args.allACValidated,\n testResults: args.testResults,\n notes: args.notes,\n filesCreated: args.filesCreated,\n filesModified: args.filesModified,\n filesDeleted: args.filesDeleted,\n discovery: args.discovery,\n blockReason: args.blockReason,\n getTicket: args.getTicket,\n includeFullContext: args.includeFullContext,\n codeSnippetsReviewed: args.codeSnippetsReviewed,\n typeReferencesReviewed: args.typeReferencesReviewed,\n });\n },\n\n complete_work_session: async (_client, args) => {\n validateRequired(args, 'ticketId', 'summary');\n return await callLocal('complete_work_session', {\n ticketId: args.ticketId,\n summary: args.summary,\n filesModified: args.filesModified,\n filesCreated: args.filesCreated,\n filesDeleted: args.filesDeleted,\n actualHours: args.actualHours,\n validation: args.validation,\n });\n },\n\n start_review_session: async (_client, args) => {\n const argsWithContext = injectContextRequired(args, ['specificationId']);\n return await callLocal('start_review_session', {\n specificationId: argsWithContext.specificationId,\n });\n },\n\n action_review_session: async (_client, args) => {\n const argsWithContext = injectContextRequired(args, ['specificationId']);\n return await callLocal('action_review_session', {\n specificationId: argsWithContext.specificationId,\n reviewSessionId: args.reviewSessionId,\n findingsAddressed: args.findingsAddressed,\n notes: args.notes,\n });\n },\n\n complete_review_session: async (_client, args) => {\n const argsWithContext = injectContextRequired(args, ['specificationId']);\n return await callLocal('complete_review_session', {\n specificationId: argsWithContext.specificationId,\n reviewSessionId: args.reviewSessionId,\n summary: args.summary,\n confirmAllDismissed: args.confirmAllDismissed,\n });\n },\n\n reopen_specification: async (_client, args) => {\n const argsWithContext = injectContextRequired(args, ['specificationId']);\n return await callLocal('reopen_specification', {\n specificationId: argsWithContext.specificationId,\n });\n },\n\n // ========================================================================\n // Mutation\n // ========================================================================\n\n // ========================================================================\n // Utilities\n // ========================================================================\n feedback: async (_client, args) => {\n // M9.7: origin is server-derived from the `X-SpecForge-Origin` header\n // (default `mcp` on the agent transport) — never a request-body `source`.\n return await callLocal('feedback', args);\n },\n\n reset_work_session: async (_client, args) => {\n validateRequired(args, 'specificationId');\n return await callLocal('reset_work_session', {\n specificationId: args.specificationId,\n ticketIds: args.ticketIds,\n fromTicketId: args.fromTicketId,\n epicId: args.epicId,\n allTickets: args.allTickets,\n targetStatus: args.targetStatus,\n resetDependents: args.resetDependents,\n includeCompleted: args.includeCompleted,\n preserveNotes: args.preserveNotes,\n clearTestResults: args.clearTestResults,\n });\n },\n\n link_pull_request: async (_client, args) => {\n validateRequired(args, 'ticketId');\n if (!args.prNumber && !args.prUrl) {\n throw new Error('Either prNumber or prUrl must be provided');\n }\n return await callLocal('link_pull_request', {\n ticketId: args.ticketId,\n prNumber: args.prNumber,\n prUrl: args.prUrl,\n title: args.title,\n author: args.author,\n repoUrl: args.repoUrl,\n });\n },\n\n // ========================================================================\n // Orchestration\n // ========================================================================\n get_critical_path: async (_client, args) => {\n const argsWithContext = injectContext(args, ['specificationId']);\n if (!argsWithContext.specificationId) {\n throw new Error('specificationId is required');\n }\n return await callLocal('get_critical_path', {\n specificationId: argsWithContext.specificationId,\n });\n },\n\n get_dependency_tree: async (_client, args) => {\n const argsWithContext = injectContext(args, ['specificationId']);\n if (!argsWithContext.specificationId) {\n throw new Error('specificationId is required');\n }\n return await callLocal('get_dependency_tree', {\n specificationId: argsWithContext.specificationId,\n });\n },\n };\n}\n\n/**\n * Validate that required arguments are present\n * @throws Error if any required argument is missing\n */\nfunction validateRequired(args: Record<string, unknown>, ...required: string[]): void {\n for (const field of required) {\n if (args[field] === undefined || args[field] === null || args[field] === '') {\n throw new Error(`Missing required argument: ${field}`);\n }\n }\n}\n\n// Create a cached instance of tool handlers\nlet cachedHandlers: Record<string, ToolHandler> | null = null;\n\n/**\n * Reset the cached tool handlers (for testing purposes)\n */\nexport function resetToolHandlers(): void {\n cachedHandlers = null;\n}\n\n/**\n * Handle a tool call by routing to the appropriate handler\n *\n * @param apiClient - The API client to use for making requests\n * @param toolName - Name of the tool being called\n * @param args - Arguments passed to the tool\n * @param debug - Whether to enable debug logging\n * @returns Promise resolving to the tool result\n */\nexport async function handleToolCall(\n apiClient: ApiClient,\n toolName: string,\n args: Record<string, unknown>,\n debug: boolean = false\n): Promise<unknown> {\n const startTime = Date.now();\n\n // Create handlers if not cached\n if (!cachedHandlers) {\n cachedHandlers = createToolHandlers(apiClient);\n }\n\n // Get the handler for this tool\n const handler = cachedHandlers[toolName];\n if (!handler) {\n throw new Error(`Unknown tool: ${toolName}`);\n }\n\n if (debug) {\n console.error(`[DEBUG] Calling tool: ${toolName}`, {\n args: JSON.stringify(args),\n });\n }\n\n try {\n // Run comprehensive validation before executing\n validateToolArgs(toolName, args);\n\n // Execute with retry logic\n const result = await withRetry(\n () => handler(apiClient, args),\n toolName,\n debug\n );\n\n const duration = Date.now() - startTime;\n if (debug) {\n console.error(`[DEBUG] Tool ${toolName} completed in ${duration}ms`);\n }\n\n return result;\n } catch (error) {\n const duration = Date.now() - startTime;\n\n // Transform error for proper handling\n const transformedError = transformError(error);\n const message = transformedError.message;\n\n if (debug) {\n console.error(`[DEBUG] Tool ${toolName} failed after ${duration}ms:`, message);\n if (transformedError instanceof ValidationError) {\n console.error(`[DEBUG] Validation field: ${transformedError.field}, code: ${transformedError.code}`);\n }\n }\n\n // Rethrow with context\n if (transformedError instanceof ValidationError) {\n throw transformedError;\n }\n if (transformedError instanceof ApiError) {\n throw transformedError;\n }\n throw new Error(`Tool ${toolName} failed: ${message}`);\n }\n}\n\n/**\n * Handle a tool call and return MCP-formatted response\n * This wraps handleToolCall with proper error formatting for MCP protocol\n */\nexport async function handleToolCallSafe(\n apiClient: ApiClient,\n toolName: string,\n args: Record<string, unknown>,\n debug: boolean = false\n): Promise<unknown | MCPErrorResponse> {\n try {\n return await handleToolCall(apiClient, toolName, args, debug);\n } catch (error) {\n const err = error instanceof Error ? error : new Error(String(error));\n return formatMCPError(err);\n }\n}\n\n// Re-export validation utilities for use by other modules\nexport {\n ValidationError,\n ApiError,\n validateToolArgs,\n formatMCPError,\n transformError,\n type MCPErrorResponse,\n} from '../validation/index.js';\n"],"mappings":"AAQA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,eAAe,6BAA6B;AACrD,SAAS,sBAAsB,yBAAyB;AACxD;AAAA,EACE;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"file":"resolve-endpoint.test.d.ts","sourceRoot":"","sources":["../../../src/transport/__tests__/resolve-endpoint.test.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/transport/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,YAAY,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,KAAK,qBAAqB,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/transport/index.ts"],"sourcesContent":["/**\n * Transport layer exports\n */\n\nexport type { ITransport } from './interface.js';\nexport { RemoteTransport, type RemoteTransportConfig } from './remote.js';\n"],"mappings":"AAKA,SAAS,uBAAmD;","names":[]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ITransport — Transport layer abstraction
|
|
3
|
+
*
|
|
4
|
+
* Decouples tool handlers from the HTTP client implementation.
|
|
5
|
+
* Implementations: RemoteTransport (HTTP POST), LocalTransport (direct core.handle, OSS future).
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Transport origin (M9.7) — surfaces the calling context to the backend via the
|
|
9
|
+
* `X-SpecForge-Origin` header. The backend reads it server-side (it is NOT a
|
|
10
|
+
* client-supplied request field) to stamp e.g. feedback provenance. Agent/MCP
|
|
11
|
+
* traffic is `mcp` (the default); the human CLI surface sends `cli`; `web` is
|
|
12
|
+
* the webapp.
|
|
13
|
+
*/
|
|
14
|
+
export type TransportOrigin = 'mcp' | 'cli' | 'web';
|
|
15
|
+
export interface ITransport {
|
|
16
|
+
/**
|
|
17
|
+
* Execute an operation against the SpecForge backend.
|
|
18
|
+
*
|
|
19
|
+
* @param operation - Operation name (e.g. 'list_projects')
|
|
20
|
+
* @param args - Operation arguments
|
|
21
|
+
* @returns Operation result
|
|
22
|
+
*/
|
|
23
|
+
execute<T = unknown>(operation: string, args: Record<string, unknown>): Promise<T>;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../src/transport/interface.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;GAMG;AACH,MAAM,MAAM,eAAe,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;AAEpD,MAAM,WAAW,UAAU;IACzB;;;;;;OAMG;IACH,OAAO,CAAC,CAAC,GAAG,OAAO,EACjB,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,OAAO,CAAC,CAAC,CAAC,CAAC;CACf"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=interface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RemoteTransport — HTTP POST transport to SpecForge API Gateway
|
|
3
|
+
*
|
|
4
|
+
* Extracted from ApiClient.call() to implement ITransport.
|
|
5
|
+
*
|
|
6
|
+
* Endpoint resolution: when `config.apiUrl` matches `CHANNEL.endpoint.primary`
|
|
7
|
+
* (i.e. no `SPECFORGE_API_URL` override is active), the transport delegates
|
|
8
|
+
* to `resolveEndpoint` on the first call so the URL flows from the
|
|
9
|
+
* canary-channel client probe (PLAN-canary-channel.md §D) — primary first,
|
|
10
|
+
* fallback on DNS-class failure, cached for 5 min. On a 401/403 the cache
|
|
11
|
+
* is invalidated so the next call re-probes.
|
|
12
|
+
*/
|
|
13
|
+
import type { ITransport, TransportOrigin } from './interface.js';
|
|
14
|
+
export interface RemoteTransportConfig {
|
|
15
|
+
apiUrl: string;
|
|
16
|
+
apiKey: string;
|
|
17
|
+
debug?: boolean;
|
|
18
|
+
timeout?: number;
|
|
19
|
+
/**
|
|
20
|
+
* Calling context, sent as the `X-SpecForge-Origin` header (M9.7). Defaults to
|
|
21
|
+
* `mcp` (agent traffic); the human CLI surface passes `cli`.
|
|
22
|
+
*/
|
|
23
|
+
origin?: TransportOrigin;
|
|
24
|
+
}
|
|
25
|
+
export declare class RemoteTransport implements ITransport {
|
|
26
|
+
private config;
|
|
27
|
+
/** Resolved URL pinned for this transport instance after the first call. */
|
|
28
|
+
private resolvedUrl;
|
|
29
|
+
constructor(config: RemoteTransportConfig);
|
|
30
|
+
/**
|
|
31
|
+
* Pick the URL for this call. When `config.apiUrl` is the channel default,
|
|
32
|
+
* defer to the resolver. Otherwise (env override / explicit test fixture),
|
|
33
|
+
* use the configured URL directly.
|
|
34
|
+
*/
|
|
35
|
+
private pickUrl;
|
|
36
|
+
execute<T = unknown>(operation: string, args: Record<string, unknown>): Promise<T>;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=remote.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remote.d.ts","sourceRoot":"","sources":["../../src/transport/remote.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAQlE,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,MAAM,CAAC,EAAE,eAAe,CAAC;CAC1B;AAKD,qBAAa,eAAgB,YAAW,UAAU;IAChD,OAAO,CAAC,MAAM,CAAwB;IACtC,4EAA4E;IAC5E,OAAO,CAAC,WAAW,CAAuB;gBAE9B,MAAM,EAAE,qBAAqB;IAIzC;;;;OAIG;YACW,OAAO;IAiBf,OAAO,CAAC,CAAC,GAAG,OAAO,EACvB,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,OAAO,CAAC,CAAC,CAAC;CAkEd"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { CHANNEL } from "../channel.js";
|
|
2
|
+
import {
|
|
3
|
+
resolveEndpoint,
|
|
4
|
+
invalidate,
|
|
5
|
+
shouldInvalidateOnStatus
|
|
6
|
+
} from "./resolve-endpoint.js";
|
|
7
|
+
const DEFAULT_TIMEOUT = 3e4;
|
|
8
|
+
const MCP_CACHE_KEY = "mcp-endpoint-cache";
|
|
9
|
+
class RemoteTransport {
|
|
10
|
+
config;
|
|
11
|
+
/** Resolved URL pinned for this transport instance after the first call. */
|
|
12
|
+
resolvedUrl = null;
|
|
13
|
+
constructor(config) {
|
|
14
|
+
this.config = config;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Pick the URL for this call. When `config.apiUrl` is the channel default,
|
|
18
|
+
* defer to the resolver. Otherwise (env override / explicit test fixture),
|
|
19
|
+
* use the configured URL directly.
|
|
20
|
+
*/
|
|
21
|
+
async pickUrl() {
|
|
22
|
+
if (this.resolvedUrl) return this.resolvedUrl;
|
|
23
|
+
const useResolver = this.config.apiUrl === CHANNEL.endpoint.primary;
|
|
24
|
+
if (!useResolver) {
|
|
25
|
+
this.resolvedUrl = this.config.apiUrl;
|
|
26
|
+
return this.resolvedUrl;
|
|
27
|
+
}
|
|
28
|
+
this.resolvedUrl = await resolveEndpoint({
|
|
29
|
+
...CHANNEL.endpoint,
|
|
30
|
+
cacheKey: MCP_CACHE_KEY
|
|
31
|
+
});
|
|
32
|
+
if (this.config.debug) {
|
|
33
|
+
console.log(`[RemoteTransport] Resolved MCP endpoint: ${this.resolvedUrl}`);
|
|
34
|
+
}
|
|
35
|
+
return this.resolvedUrl;
|
|
36
|
+
}
|
|
37
|
+
async execute(operation, args) {
|
|
38
|
+
const timeout = this.config.timeout ?? DEFAULT_TIMEOUT;
|
|
39
|
+
const controller = new AbortController();
|
|
40
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
41
|
+
try {
|
|
42
|
+
if (this.config.debug) {
|
|
43
|
+
console.log(`[RemoteTransport] Calling operation: ${operation}`, {
|
|
44
|
+
args: Object.keys(args)
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
const url = await this.pickUrl();
|
|
48
|
+
const response = await fetch(url, {
|
|
49
|
+
method: "POST",
|
|
50
|
+
headers: {
|
|
51
|
+
"Content-Type": "application/json",
|
|
52
|
+
Authorization: `Bearer ${this.config.apiKey}`,
|
|
53
|
+
// M9.7: server-derived feedback/telemetry provenance. The backend
|
|
54
|
+
// reads this header (never a request-body `source` field).
|
|
55
|
+
"X-SpecForge-Origin": this.config.origin ?? "mcp"
|
|
56
|
+
},
|
|
57
|
+
body: JSON.stringify({ operation, args }),
|
|
58
|
+
signal: controller.signal
|
|
59
|
+
});
|
|
60
|
+
clearTimeout(timeoutId);
|
|
61
|
+
if (!response.ok) {
|
|
62
|
+
if (shouldInvalidateOnStatus(response.status) && this.config.apiUrl === CHANNEL.endpoint.primary) {
|
|
63
|
+
await invalidate(MCP_CACHE_KEY);
|
|
64
|
+
this.resolvedUrl = null;
|
|
65
|
+
}
|
|
66
|
+
const errorText = await response.text();
|
|
67
|
+
const statusMessage = getStatusMessage(response.status);
|
|
68
|
+
throw new Error(
|
|
69
|
+
`API request failed: ${response.status} ${statusMessage}
|
|
70
|
+
${errorText}`
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
const body = await response.json();
|
|
74
|
+
if (this.config.debug) {
|
|
75
|
+
console.log(`[RemoteTransport] Operation completed: ${operation}`);
|
|
76
|
+
}
|
|
77
|
+
return body;
|
|
78
|
+
} catch (error) {
|
|
79
|
+
clearTimeout(timeoutId);
|
|
80
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
81
|
+
throw new Error(
|
|
82
|
+
`Request timed out after ${timeout}ms for operation: ${operation}`
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function getStatusMessage(status) {
|
|
90
|
+
const messages = {
|
|
91
|
+
400: "Bad Request",
|
|
92
|
+
401: "Unauthorized - Check your API key",
|
|
93
|
+
403: "Forbidden - Insufficient permissions",
|
|
94
|
+
404: "Not Found",
|
|
95
|
+
429: "Too Many Requests - Rate limit exceeded",
|
|
96
|
+
500: "Internal Server Error",
|
|
97
|
+
501: "Not Implemented",
|
|
98
|
+
502: "Bad Gateway",
|
|
99
|
+
503: "Service Unavailable",
|
|
100
|
+
504: "Gateway Timeout"
|
|
101
|
+
};
|
|
102
|
+
return messages[status] || "Unknown Error";
|
|
103
|
+
}
|
|
104
|
+
export {
|
|
105
|
+
RemoteTransport
|
|
106
|
+
};
|
|
107
|
+
//# sourceMappingURL=remote.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/transport/remote.ts"],"sourcesContent":["/**\n * RemoteTransport — HTTP POST transport to SpecForge API Gateway\n *\n * Extracted from ApiClient.call() to implement ITransport.\n *\n * Endpoint resolution: when `config.apiUrl` matches `CHANNEL.endpoint.primary`\n * (i.e. no `SPECFORGE_API_URL` override is active), the transport delegates\n * to `resolveEndpoint` on the first call so the URL flows from the\n * canary-channel client probe (PLAN-canary-channel.md §D) — primary first,\n * fallback on DNS-class failure, cached for 5 min. On a 401/403 the cache\n * is invalidated so the next call re-probes.\n */\n\nimport type { ITransport, TransportOrigin } from './interface.js';\nimport { CHANNEL } from '../channel.js';\nimport {\n resolveEndpoint,\n invalidate,\n shouldInvalidateOnStatus,\n} from './resolve-endpoint.js';\n\nexport interface RemoteTransportConfig {\n apiUrl: string;\n apiKey: string;\n debug?: boolean;\n timeout?: number;\n /**\n * Calling context, sent as the `X-SpecForge-Origin` header (M9.7). Defaults to\n * `mcp` (agent traffic); the human CLI surface passes `cli`.\n */\n origin?: TransportOrigin;\n}\n\nconst DEFAULT_TIMEOUT = 30000;\nconst MCP_CACHE_KEY = 'mcp-endpoint-cache';\n\nexport class RemoteTransport implements ITransport {\n private config: RemoteTransportConfig;\n /** Resolved URL pinned for this transport instance after the first call. */\n private resolvedUrl: string | null = null;\n\n constructor(config: RemoteTransportConfig) {\n this.config = config;\n }\n\n /**\n * Pick the URL for this call. When `config.apiUrl` is the channel default,\n * defer to the resolver. Otherwise (env override / explicit test fixture),\n * use the configured URL directly.\n */\n private async pickUrl(): Promise<string> {\n if (this.resolvedUrl) return this.resolvedUrl;\n const useResolver = this.config.apiUrl === CHANNEL.endpoint.primary;\n if (!useResolver) {\n this.resolvedUrl = this.config.apiUrl;\n return this.resolvedUrl;\n }\n this.resolvedUrl = await resolveEndpoint({\n ...CHANNEL.endpoint,\n cacheKey: MCP_CACHE_KEY,\n });\n if (this.config.debug) {\n console.log(`[RemoteTransport] Resolved MCP endpoint: ${this.resolvedUrl}`);\n }\n return this.resolvedUrl;\n }\n\n async execute<T = unknown>(\n operation: string,\n args: Record<string, unknown>\n ): Promise<T> {\n const timeout = this.config.timeout ?? DEFAULT_TIMEOUT;\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), timeout);\n\n try {\n if (this.config.debug) {\n console.log(`[RemoteTransport] Calling operation: ${operation}`, {\n args: Object.keys(args),\n });\n }\n\n const url = await this.pickUrl();\n const response = await fetch(url, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${this.config.apiKey}`,\n // M9.7: server-derived feedback/telemetry provenance. The backend\n // reads this header (never a request-body `source` field).\n 'X-SpecForge-Origin': this.config.origin ?? 'mcp',\n },\n body: JSON.stringify({ operation, args }),\n signal: controller.signal,\n });\n\n clearTimeout(timeoutId);\n\n if (!response.ok) {\n // Auth failures may indicate the channel was rotated under us;\n // invalidate so the next call re-probes.\n if (\n shouldInvalidateOnStatus(response.status) &&\n this.config.apiUrl === CHANNEL.endpoint.primary\n ) {\n await invalidate(MCP_CACHE_KEY);\n this.resolvedUrl = null;\n }\n const errorText = await response.text();\n const statusMessage = getStatusMessage(response.status);\n throw new Error(\n `API request failed: ${response.status} ${statusMessage}\\n${errorText}`\n );\n }\n\n // Transport is a dumb pipe (M9, approach A): return the raw response body.\n // Response-shape interpretation lives in the consumer that owns the\n // contract — `ApiClient.call` unwraps the `/cli` `{ data } / { error }`\n // shape; the agent `/local` path interprets the M8 envelope itself.\n const body = (await response.json()) as T;\n\n if (this.config.debug) {\n console.log(`[RemoteTransport] Operation completed: ${operation}`);\n }\n\n return body;\n } catch (error) {\n clearTimeout(timeoutId);\n if (error instanceof Error && error.name === 'AbortError') {\n throw new Error(\n `Request timed out after ${timeout}ms for operation: ${operation}`\n );\n }\n throw error;\n }\n }\n}\n\nfunction getStatusMessage(status: number): string {\n const messages: Record<number, string> = {\n 400: 'Bad Request',\n 401: 'Unauthorized - Check your API key',\n 403: 'Forbidden - Insufficient permissions',\n 404: 'Not Found',\n 429: 'Too Many Requests - Rate limit exceeded',\n 500: 'Internal Server Error',\n 501: 'Not Implemented',\n 502: 'Bad Gateway',\n 503: 'Service Unavailable',\n 504: 'Gateway Timeout',\n };\n return messages[status] || 'Unknown Error';\n}\n"],"mappings":"AAcA,SAAS,eAAe;AACxB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAcP,MAAM,kBAAkB;AACxB,MAAM,gBAAgB;AAEf,MAAM,gBAAsC;AAAA,EACzC;AAAA;AAAA,EAEA,cAA6B;AAAA,EAErC,YAAY,QAA+B;AACzC,SAAK,SAAS;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAc,UAA2B;AACvC,QAAI,KAAK,YAAa,QAAO,KAAK;AAClC,UAAM,cAAc,KAAK,OAAO,WAAW,QAAQ,SAAS;AAC5D,QAAI,CAAC,aAAa;AAChB,WAAK,cAAc,KAAK,OAAO;AAC/B,aAAO,KAAK;AAAA,IACd;AACA,S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AK;AAElC,UAAI,KAAK,OAAO,OAAO;AACrB,gBAAQ,IAAI,0CAA0C,SAAS,EAAE;AAAA,MACnE;AAEA,aAAO;AAAA,IACT,SAAS,OAAO;AACd,mBAAa,SAAS;AACtB,UAAI,iBAAiB,SAAS,MAAM,SAAS,cAAc;AACzD,cAAM,IAAI;AAAA,UACR,2BAA2B,OAAO,qBAAqB,SAAS;AAAA,QAClE;AAAA,MACF;AACA,YAAM;AAAA,IACR;AAAA,EACF;AACF;AAEA,SAAS,iBAAiB,QAAwB;AAChD,QAAM,WAAmC;AAAA,IACvC,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,EACP;AACA,SAAO,SAAS,MAAM,KAAK;AAC7B;","names":[]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Endpoint resolver — picks `primary` or `fallback` per the canary-channel
|
|
3
|
+
* client probe contract (PLAN-canary-channel.md §D).
|
|
4
|
+
*
|
|
5
|
+
* Cache file: `${homedir}/${CHANNEL.configDir}/${cacheKey}.json`. TTL: 5 min.
|
|
6
|
+
*
|
|
7
|
+
* Probe: GET `healthPrimary` with a 2 s timeout. On success → cache `primary`
|
|
8
|
+
* and return it. On a DNS-class failure (`ENOTFOUND`, `ENETUNREACH`, TLS
|
|
9
|
+
* handshake, `AbortError` from the timeout) → probe `healthFallback`. On
|
|
10
|
+
* success → cache `fallback` and return it. Both fail → throw a clear
|
|
11
|
+
* network error.
|
|
12
|
+
*
|
|
13
|
+
* `5xx`, `429`, `401`, `403` from the real call do NOT trigger fallover —
|
|
14
|
+
* those mean the backend is reachable but rejecting. Callers handle them
|
|
15
|
+
* directly and may invalidate the cache via `invalidate(cacheKey)` on
|
|
16
|
+
* auth-class failures so the next call re-probes.
|
|
17
|
+
*/
|
|
18
|
+
export interface ResolveEndpointInput {
|
|
19
|
+
/** Primary URL — production target on stable, dev target on canary. */
|
|
20
|
+
primary: string;
|
|
21
|
+
/** Fallback URL — used on DNS-class failure of primary. */
|
|
22
|
+
fallback: string;
|
|
23
|
+
/** `GET`-able probe target on the primary surface. */
|
|
24
|
+
healthPrimary: string;
|
|
25
|
+
/** `GET`-able probe target on the fallback surface. */
|
|
26
|
+
healthFallback: string;
|
|
27
|
+
/** Filename stem for the cache file under `~/${CHANNEL.configDir}/`. */
|
|
28
|
+
cacheKey: string;
|
|
29
|
+
}
|
|
30
|
+
export interface ResolveEndpointOptions {
|
|
31
|
+
/** Override the per-call probe timeout (ms). Default 2000. */
|
|
32
|
+
probeTimeoutMs?: number;
|
|
33
|
+
/** Override the cache TTL (ms). Default 5 minutes. */
|
|
34
|
+
cacheTtlMs?: number;
|
|
35
|
+
/** Override the cache directory (testing). Default `os.homedir()`. */
|
|
36
|
+
cacheBaseDir?: string;
|
|
37
|
+
/** Override the channel config dir (testing). Default `CHANNEL.configDir`. */
|
|
38
|
+
configDir?: string;
|
|
39
|
+
/** Inject a custom probe function (testing). Default uses `fetch`. */
|
|
40
|
+
probe?: (url: string, signal: AbortSignal) => Promise<Response>;
|
|
41
|
+
}
|
|
42
|
+
export declare const DEFAULT_PROBE_TIMEOUT_MS = 2000;
|
|
43
|
+
export declare const DEFAULT_CACHE_TTL_MS: number;
|
|
44
|
+
/**
|
|
45
|
+
* Resolve a usable endpoint URL by checking the cache, then probing.
|
|
46
|
+
* Throws when both probes fail.
|
|
47
|
+
*/
|
|
48
|
+
export declare function resolveEndpoint(input: ResolveEndpointInput, opts?: ResolveEndpointOptions): Promise<string>;
|
|
49
|
+
/** Wipe the cache for a given key — call on auth-class failures. */
|
|
50
|
+
export declare function invalidate(cacheKey: string, opts?: ResolveEndpointOptions): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Helper: should the caller invalidate the cache after this status?
|
|
53
|
+
* 401/403 from a real call are auth-class; tomorrow's call should re-probe
|
|
54
|
+
* in case the operator pointed the channel elsewhere.
|
|
55
|
+
*/
|
|
56
|
+
export declare function shouldInvalidateOnStatus(status: number): boolean;
|
|
57
|
+
export { CHANNEL } from '../channel.js';
|
|
58
|
+
//# sourceMappingURL=resolve-endpoint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-endpoint.d.ts","sourceRoot":"","sources":["../../src/transport/resolve-endpoint.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAQH,MAAM,WAAW,oBAAoB;IACnC,uEAAuE;IACvE,OAAO,EAAE,MAAM,CAAC;IAChB,2DAA2D;IAC3D,QAAQ,EAAE,MAAM,CAAC;IACjB,sDAAsD;IACtD,aAAa,EAAE,MAAM,CAAC;IACtB,uDAAuD;IACvD,cAAc,EAAE,MAAM,CAAC;IACvB,wEAAwE;IACxE,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,sBAAsB;IACrC,8DAA8D;IAC9D,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,sDAAsD;IACtD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,sEAAsE;IACtE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,8EAA8E;IAC9E,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sEAAsE;IACtE,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;CACjE;AAED,eAAO,MAAM,wBAAwB,OAAQ,CAAC;AAC9C,eAAO,MAAM,oBAAoB,QAAiB,CAAC;AA4GnD;;;GAGG;AACH,wBAAsB,eAAe,CACnC,KAAK,EAAE,oBAAoB,EAC3B,IAAI,GAAE,sBAA2B,GAChC,OAAO,CAAC,MAAM,CAAC,CAwCjB;AAED,oEAAoE;AACpE,wBAAsB,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI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