@vitest-agent/mcp 6.0.1 → 6.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/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ToolRefusal, ToolRefusal as ToolRefusal$1 } from "@effected/mcp";
2
- import { Context, Effect, Layer, Schema, Stdio } from "effect";
3
- import { DataReader, DataStore, ProjectDiscovery, SessionContext } from "@vitest-agent/engine";
2
+ import { Context, Effect, Layer, Schema, Scope, Stdio } from "effect";
4
3
  import { McpServer, Tool, Toolkit } from "effect/ai";
4
+ import { DataReader, DataStore, ProjectDiscovery, SessionContext } from "@vitest-agent/engine";
5
5
  import "@effected/git";
6
6
  import "@effected/mcp/node";
7
7
  import "@vitest-agent/sdk";
@@ -115,12 +115,14 @@ export declare class McpSession extends McpSession_base {
115
115
  static readonly layerTest: (overrides: Pick<McpSessionOptions, "cwd"> & Partial<McpSessionOptions>) => Layer.Layer<McpSession>;
116
116
  }
117
117
  /**
118
- * Every framing prompt as one layer; merged into `ServerLayer` beside the
119
- * toolkit registration. Requires `McpSession` for `tdd-resume`'s default.
118
+ * Every framing prompt as one layer; merged into `ServerLayer`'s
119
+ * registrations beside the toolkit, so the transport supplies `McpServer`.
120
+ * Requires `McpSession` per request for
121
+ * `tdd-resume`'s default, met by the server's request-services middleware.
120
122
  *
121
123
  * @public
122
124
  */
123
- export declare const PromptsLayer: Layer.Layer<never, never, McpSession>;
125
+ export declare const PromptsLayer: Layer.Layer<never, never, McpServer.McpServer | McpServer.McpRequest<"Requires", McpSession>>;
124
126
  /**
125
127
  * The platform services the stdio transport needs.
126
128
  *
@@ -149,19 +151,20 @@ export declare const SERVER_INSTRUCTIONS: string;
149
151
  /**
150
152
  * The server layer: every tool registered through `McpToolkit.layer` (strict
151
153
  * by default, every unknown key named in one `InvalidParams`) plus the six
152
- * framing prompts, over `McpStdio.layer`.
154
+ * framing prompts, passed to `McpStdio.layer` as its `registrations` so they
155
+ * are built before the first request, with build-time logs on stderr.
153
156
  *
154
157
  * `McpStdio.layer` serves `McpStdio.protocols` — the stateless `2026-07-28`
155
158
  * adapter first, then `2025-11-25` and `2025-06-18` — provides
156
159
  * `LogToStderr` (stdout is the JSON-RPC wire) to everything it provides, and
157
160
  * answers a malformed stdin line itself instead of wedging core's decoder.
158
- * It is provided, not merged, so the output stays `never`; a test registers
159
- * extra tools beside it through the shared module-level `McpServer` registry.
161
+ * Its output is what `McpStdio.layer` returns: the `McpServer` it serves
162
+ * and the `Scope` request marker the transport discharges.
160
163
  *
161
164
  * @param options - the advertised server version
162
165
  * @public
163
166
  */
164
- export declare const ServerLayer: (options: ServerLayerOptions) => Layer.Layer<never, never, PlatformServices | McpSession | DataReader | DataStore | ProjectDiscovery>;
167
+ export declare const ServerLayer: (options: ServerLayerOptions) => Layer.Layer<McpServer.McpServer | McpServer.McpRequest<"Requires", Scope.Scope>, never, PlatformServices | McpSession | DataReader | DataStore | ProjectDiscovery>;
165
168
  /**
166
169
  * The `acceptance_metrics` tool's success payload.
167
170
  *
@@ -4452,14 +4455,16 @@ export declare const Kit: Toolkit.Toolkit<{
4452
4455
  }, import("@vitest-agent/engine").DataReader>;
4453
4456
  }>;
4454
4457
  /**
4455
- * The handler for each tool in {@link Kit}, keyed by tool name. The seven
4456
- * action-keyed tools are `Tool.dynamic` (a union root cannot be a `Tool.make`
4457
- * parameters schema), so their handlers take the raw payload and decode it
4458
- * through `McpToolkit.unionHandler`.
4458
+ * Builds the handler for each tool in {@link Kit}: reads `DataReader` /
4459
+ * `DataStore` once into the idempotent-replay store and wraps the write
4460
+ * tools once over it (`@effected/mcp`'s `ToolReplay` guidance for a server:
4461
+ * read the store when the handlers are built, never per call). Both services
4462
+ * are fixed for the life of the server, the same instances the server's
4463
+ * request middleware provides to each call.
4459
4464
  *
4460
4465
  * @public
4461
4466
  */
4462
- export declare const toolHandlers: {
4467
+ export declare const toolHandlers: Effect.Effect<{
4463
4468
  ping: typeof handlePing;
4464
4469
  help: typeof handleHelp;
4465
4470
  test_status: typeof handleTestStatus;
@@ -4478,7 +4483,7 @@ export declare const toolHandlers: {
4478
4483
  acceptance_metrics: typeof handleAcceptanceMetrics;
4479
4484
  triage_brief: typeof handleTriageBrief;
4480
4485
  wrapup_prompt: typeof handleWrapupPrompt;
4481
- inventory: (payload: unknown) => import("effect/Effect").Effect<{
4486
+ inventory: (payload: unknown) => Effect.Effect<{
4482
4487
  readonly inventoryKind: "project";
4483
4488
  readonly count: number;
4484
4489
  readonly projects: readonly {
@@ -4575,7 +4580,7 @@ export declare const toolHandlers: {
4575
4580
  }[];
4576
4581
  }[];
4577
4582
  }, import("effect/ai/McpSchema").InvalidParams, import("@vitest-agent/engine").DataReader>;
4578
- test: (payload: unknown) => import("effect/Effect").Effect<{
4583
+ test: (payload: unknown) => Effect.Effect<{
4579
4584
  readonly action: "list";
4580
4585
  readonly count: number;
4581
4586
  readonly groups: readonly {
@@ -4685,7 +4690,7 @@ export declare const toolHandlers: {
4685
4690
  readonly candidateModules?: readonly string[] | undefined;
4686
4691
  }, import("effect/ai/McpSchema").InvalidParams, import("@vitest-agent/engine").DataReader>;
4687
4692
  register_agent: typeof handleRegisterAgent;
4688
- note: (payload: unknown) => import("effect/Effect").Effect<{
4693
+ note: (payload: unknown) => Effect.Effect<{
4689
4694
  readonly action: "create";
4690
4695
  readonly id: number;
4691
4696
  } | {
@@ -4754,7 +4759,7 @@ export declare const toolHandlers: {
4754
4759
  readonly updatedAt: string;
4755
4760
  }[];
4756
4761
  }, import("effect/ai/McpSchema").InvalidParams, import("@vitest-agent/engine").DataReader | import("@vitest-agent/engine").DataStore>;
4757
- hypothesis: (payload: unknown) => import("effect/Effect").Effect<{
4762
+ hypothesis: (payload: unknown) => Effect.Effect<{
4758
4763
  readonly action: "record";
4759
4764
  readonly id: number;
4760
4765
  } | {
@@ -4773,7 +4778,7 @@ export declare const toolHandlers: {
4773
4778
  readonly _idempotentReplay?: true;
4774
4779
  readonly action: "validate";
4775
4780
  }, import("effect/ai/McpSchema").InvalidParams | import("@effected/mcp").ToolRefusal, import("@vitest-agent/engine").DataReader | import("@vitest-agent/engine").DataStore | McpSession>;
4776
- tdd_task: (payload: unknown) => import("effect/Effect").Effect<{
4781
+ tdd_task: (payload: unknown) => Effect.Effect<{
4777
4782
  readonly action: "get";
4778
4783
  readonly found: true;
4779
4784
  readonly task: {
@@ -4859,7 +4864,7 @@ export declare const toolHandlers: {
4859
4864
  readonly outcome: "abandoned" | "blocked" | "succeeded";
4860
4865
  }, import("effect/ai/McpSchema").InvalidParams | import("@effected/mcp").ToolRefusal, import("@vitest-agent/engine").DataReader | import("@vitest-agent/engine").DataStore>;
4861
4866
  tdd_phase_transition_request: typeof handlePhaseTransitionRequest;
4862
- tdd_goal: (payload: unknown) => import("effect/Effect").Effect<{
4867
+ tdd_goal: (payload: unknown) => Effect.Effect<{
4863
4868
  readonly ok: false;
4864
4869
  readonly error: {
4865
4870
  readonly message: string;
@@ -4999,7 +5004,7 @@ export declare const toolHandlers: {
4999
5004
  readonly createdAt: string;
5000
5005
  };
5001
5006
  }, import("effect/ai/McpSchema").InvalidParams, import("@vitest-agent/engine").DataReader | import("@vitest-agent/engine").DataStore>;
5002
- tdd_behavior: (payload: unknown) => import("effect/Effect").Effect<{
5007
+ tdd_behavior: (payload: unknown) => Effect.Effect<{
5003
5008
  readonly ok: false;
5004
5009
  readonly error: {
5005
5010
  readonly message: string;
@@ -5155,9 +5160,10 @@ export declare const toolHandlers: {
5155
5160
  tdd_artifact_list: typeof handleTddArtifactList;
5156
5161
  tdd_progress_push: typeof handleTddProgressPush;
5157
5162
  run_tests: typeof handleRunTests;
5158
- };
5163
+ }, never, import("@vitest-agent/engine").DataReader | import("@vitest-agent/engine").DataStore>;
5159
5164
  /**
5160
- * The handlers layer: provides `Tool.HandlersFor<typeof Kit.tools>`.
5165
+ * The handlers layer: provides `Tool.HandlersFor<typeof Kit.tools>`, built
5166
+ * from {@link toolHandlers}, so it requires `DataReader` / `DataStore`.
5161
5167
  *
5162
5168
  * @public
5163
5169
  */
@@ -6934,7 +6940,7 @@ export declare const ToolsLayer: import("effect/Layer").Layer<import("effect/ai/
6934
6940
  readonly failure: import("effect/Schema").Never;
6935
6941
  readonly failureMode: "error";
6936
6942
  }, import("@vitest-agent/engine").DataReader>;
6937
- }>, never, never>;
6943
+ }>, never, import("@vitest-agent/engine").DataReader | import("@vitest-agent/engine").DataStore>;
6938
6944
  /**
6939
6945
  * Success-shaped envelope returned by TDD CRUD tools when a known TDD error occurs.
6940
6946
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitest-agent/mcp",
3
- "version": "6.0.1",
3
+ "version": "6.1.0",
4
4
  "private": false,
5
5
  "description": "Model Context Protocol server for vitest-agent. Exposes 30 tools for agent access to test data, TDD lifecycle, and session management.",
6
6
  "keywords": [
@@ -43,16 +43,16 @@
43
43
  "vitest-agent-mcp": "bin/vitest-agent-mcp.js"
44
44
  },
45
45
  "dependencies": {
46
- "@effect/platform-node": "^4.0.7",
47
- "@effected/commands": "^0.18.0",
48
- "@effected/engine": "^0.10.0",
49
- "@effected/git": "^0.27.0",
50
- "@effected/glob": "^0.16.0",
51
- "@effected/mcp": "^0.11.0",
52
- "@effected/walker": "^0.22.0",
53
- "@vitest-agent/engine": "3.0.1",
54
- "@vitest-agent/sdk": "9.0.1",
55
- "effect": "^4.0.7"
46
+ "@effect/platform-node": "~4.1.1",
47
+ "@effected/commands": "^0.19.0",
48
+ "@effected/engine": "^0.11.0",
49
+ "@effected/git": "^0.29.0",
50
+ "@effected/glob": "^0.17.0",
51
+ "@effected/mcp": "^0.12.0",
52
+ "@effected/walker": "^0.24.0",
53
+ "@vitest-agent/engine": "3.1.0",
54
+ "@vitest-agent/sdk": "9.0.2",
55
+ "effect": "~4.1.1"
56
56
  },
57
57
  "peerDependencies": {
58
58
  "vitest": "^5.0.0"
package/prompts/layer.js CHANGED
@@ -103,8 +103,10 @@ const Wrapup = McpServer.prompt({
103
103
  }
104
104
  });
105
105
  /**
106
- * Every framing prompt as one layer; merged into `ServerLayer` beside the
107
- * toolkit registration. Requires `McpSession` for `tdd-resume`'s default.
106
+ * Every framing prompt as one layer; merged into `ServerLayer`'s
107
+ * registrations beside the toolkit, so the transport supplies `McpServer`.
108
+ * Requires `McpSession` per request for
109
+ * `tdd-resume`'s default, met by the server's request-services middleware.
108
110
  *
109
111
  * @public
110
112
  */
package/replay.js CHANGED
@@ -79,15 +79,19 @@ const makeReplayStore = Effect.gen(function* () {
79
79
  };
80
80
  });
81
81
  /**
82
- * `ToolReplay.wrap` for one write tool, with the replay store built from the
83
- * handler's own `DataReader` / `DataStore`, so the wrapped handler requires
84
- * exactly what the bare one did.
82
+ * `ToolReplay.wrap` for one write tool over an already-built `store`: the
83
+ * production form. `toolHandlers` reads `DataReader` / `DataStore` once when
84
+ * the handlers layer is built ({@link makeReplayStore}) and wraps each write
85
+ * tool once here, so the replay codec is derived once and `wrap`'s wiring
86
+ * check (a `:` in the tool name) fails the server build instead of the first
87
+ * call. With the store supplied, the wrapped handler requires exactly what
88
+ * the bare one did.
85
89
  *
86
90
  * @internal
87
91
  */
88
- const replayed = (options) => (handler) => (params) => Effect.flatMap(makeReplayStore, (store) => ToolReplay.wrap({
92
+ const replayWith = (store) => (options) => (handler) => ToolReplay.wrap({
89
93
  ...options,
90
94
  store
91
- })(handler)(params));
95
+ })(handler);
92
96
 
93
- export { hypothesisReplayKey, makeReplayStore, replayed, tddBehaviorReplayKey, tddGoalReplayKey, tddTaskReplayKey };
97
+ export { hypothesisReplayKey, makeReplayStore, replayWith, tddBehaviorReplayKey, tddGoalReplayKey, tddTaskReplayKey };
package/server.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import { PromptsLayer } from "./prompts/layer.js";
2
2
  import { Kit, ToolsLayer } from "./toolkit.js";
3
3
  import { McpStdio, McpToolkit } from "@effected/mcp";
4
- import { Layer } from "effect";
4
+ import { Effect, Layer } from "effect";
5
+ import { McpServer } from "effect/ai";
5
6
 
6
7
  // src/server.ts
7
8
  /** One-line human summary agents see on `serverInfo.description`. */
@@ -24,25 +25,40 @@ const SERVER_INSTRUCTIONS = [
24
25
  "An isError result means the call itself failed and carries no structuredContent. Its text either names what to fix (invalid params, or a refused call such as an unknown id, often ending 'Try <tool>.' with the tool to call next) or is a generic internal-error message (the server logged the detail). Fix the call, or report the internal failure rather than retrying it unchanged."
25
26
  ].join("\n");
26
27
  /**
28
+ * Meets every registration's request-level dependencies. A tool's declared
29
+ * `dependencies` (and a prompt's services) are per-request
30
+ * `McpServer.McpRequest<"Requires", S>` requirements that only MCP middleware
31
+ * discharges; every one of ours is fixed for the life of the server, so the
32
+ * middleware reads them once when it is built and provides the same context
33
+ * to every request. `McpServer` itself is read from the transport, for
34
+ * `tdd_progress_push`'s `notifications/message` frame.
35
+ */
36
+ const RequestServices = McpServer.middleware()(Effect.gen(function* () {
37
+ const context = yield* Effect.context();
38
+ return (effect) => Effect.provideContext(effect, context);
39
+ }));
40
+ /**
27
41
  * The server layer: every tool registered through `McpToolkit.layer` (strict
28
42
  * by default, every unknown key named in one `InvalidParams`) plus the six
29
- * framing prompts, over `McpStdio.layer`.
43
+ * framing prompts, passed to `McpStdio.layer` as its `registrations` so they
44
+ * are built before the first request, with build-time logs on stderr.
30
45
  *
31
46
  * `McpStdio.layer` serves `McpStdio.protocols` — the stateless `2026-07-28`
32
47
  * adapter first, then `2025-11-25` and `2025-06-18` — provides
33
48
  * `LogToStderr` (stdout is the JSON-RPC wire) to everything it provides, and
34
49
  * answers a malformed stdin line itself instead of wedging core's decoder.
35
- * It is provided, not merged, so the output stays `never`; a test registers
36
- * extra tools beside it through the shared module-level `McpServer` registry.
50
+ * Its output is what `McpStdio.layer` returns: the `McpServer` it serves
51
+ * and the `Scope` request marker the transport discharges.
37
52
  *
38
53
  * @param options - the advertised server version
39
54
  * @public
40
55
  */
41
- const ServerLayer = (options) => Layer.mergeAll(McpToolkit.layer(Kit).pipe(Layer.provide(ToolsLayer)), PromptsLayer).pipe(Layer.provide(McpStdio.layer({
56
+ const ServerLayer = (options) => McpStdio.layer({
42
57
  name: "vitest-agent",
43
58
  version: options.version,
44
59
  description: DESCRIPTION,
45
- instructions: SERVER_INSTRUCTIONS
46
- })));
60
+ instructions: SERVER_INSTRUCTIONS,
61
+ registrations: Layer.mergeAll(McpToolkit.layer(Kit).pipe(Layer.provide(ToolsLayer)), PromptsLayer).pipe(Layer.provide(RequestServices.layer))
62
+ });
47
63
 
48
64
  export { SERVER_INSTRUCTIONS, ServerLayer };
package/toolkit.js CHANGED
@@ -1,4 +1,4 @@
1
- import { hypothesisReplayKey, replayed, tddBehaviorReplayKey, tddGoalReplayKey, tddTaskReplayKey } from "./replay.js";
1
+ import { hypothesisReplayKey, makeReplayStore, replayWith, tddBehaviorReplayKey, tddGoalReplayKey, tddTaskReplayKey } from "./replay.js";
2
2
  import { acceptanceMetricsTool, handleAcceptanceMetrics } from "./tools/acceptance-metrics.js";
3
3
  import { cacheHealthTool, handleCacheHealth } from "./tools/cache-health.js";
4
4
  import { commitChangesTool, handleCommitChanges } from "./tools/commit-changes.js";
@@ -30,6 +30,7 @@ import { handleTriageBrief, triageBriefTool } from "./tools/triage-brief.js";
30
30
  import { handleTurnSearch, turnSearchTool } from "./tools/turn-search.js";
31
31
  import { handleWrapupPrompt, wrapupPromptTool } from "./tools/wrapup-prompt.js";
32
32
  import { McpToolkit } from "@effected/mcp";
33
+ import { Effect } from "effect";
33
34
  import { Toolkit } from "effect/ai";
34
35
 
35
36
  // src/toolkit.ts
@@ -40,66 +41,82 @@ import { Toolkit } from "effect/ai";
40
41
  */
41
42
  const Kit = Toolkit.make(pingTool, helpTool, testStatusTool, testOverviewTool, testCoverageTool, testHistoryTool, testTrendsTool, testErrorsTool, fileCoverageTool, settingsListTool, cacheHealthTool, configureTool, commitChangesTool, turnSearchTool, failureSignatureGetTool, acceptanceMetricsTool, triageBriefTool, wrapupPromptTool, inventoryTool, testTool, registerAgentTool, noteTool, hypothesisTool, tddTaskTool, tddPhaseTransitionRequestTool, tddGoalTool, tddBehaviorTool, tddArtifactListTool, tddProgressPushTool, runTestsTool);
42
43
  /**
43
- * The handler for each tool in {@link Kit}, keyed by tool name. The seven
44
- * action-keyed tools are `Tool.dynamic` (a union root cannot be a `Tool.make`
45
- * parameters schema), so their handlers take the raw payload and decode it
46
- * through `McpToolkit.unionHandler`.
44
+ * The handler for each tool in {@link Kit}, keyed by tool name, with the four
45
+ * replayable write tools wrapped once over `store`. The seven action-keyed
46
+ * tools are `Tool.dynamic` (a union root cannot be a `Tool.make` parameters
47
+ * schema), so their handlers take the raw payload and decode it through
48
+ * `McpToolkit.unionHandler`.
47
49
  *
48
- * @public
50
+ * @internal
49
51
  */
50
- const toolHandlers = {
51
- ping: handlePing,
52
- help: handleHelp,
53
- test_status: handleTestStatus,
54
- test_overview: handleTestOverview,
55
- test_coverage: handleTestCoverage,
56
- test_history: handleTestHistory,
57
- test_trends: handleTestTrends,
58
- test_errors: handleTestErrors,
59
- file_coverage: handleFileCoverage,
60
- settings_list: handleSettingsList,
61
- cache_health: handleCacheHealth,
62
- configure: handleConfigure,
63
- commit_changes: handleCommitChanges,
64
- turn_search: handleTurnSearch,
65
- failure_signature_get: handleFailureSignatureGet,
66
- acceptance_metrics: handleAcceptanceMetrics,
67
- triage_brief: handleTriageBrief,
68
- wrapup_prompt: handleWrapupPrompt,
69
- inventory: McpToolkit.unionHandler(inventoryTool, handleInventory),
70
- test: McpToolkit.unionHandler(testTool, handleTest),
71
- register_agent: handleRegisterAgent,
72
- note: McpToolkit.unionHandler(noteTool, handleNote),
73
- hypothesis: McpToolkit.unionHandler(hypothesisTool, replayed({
74
- tool: "hypothesis",
75
- success: HypothesisResult,
76
- key: hypothesisReplayKey
77
- })(handleHypothesis)),
78
- tdd_task: McpToolkit.unionHandler(tddTaskTool, replayed({
79
- tool: "tdd_task",
80
- success: TddTaskResult,
81
- key: tddTaskReplayKey
82
- })(handleTddTask)),
83
- tdd_phase_transition_request: handlePhaseTransitionRequest,
84
- tdd_goal: McpToolkit.unionHandler(tddGoalTool, replayed({
85
- tool: "tdd_goal",
86
- success: TddGoalResult,
87
- key: tddGoalReplayKey
88
- })(handleTddGoal)),
89
- tdd_behavior: McpToolkit.unionHandler(tddBehaviorTool, replayed({
90
- tool: "tdd_behavior",
91
- success: TddBehaviorResult,
92
- key: tddBehaviorReplayKey
93
- })(handleTddBehavior)),
94
- tdd_artifact_list: handleTddArtifactList,
95
- tdd_progress_push: handleTddProgressPush,
96
- run_tests: handleRunTests
52
+ const makeToolHandlers = (store) => {
53
+ const replayed = replayWith(store);
54
+ return {
55
+ ping: handlePing,
56
+ help: handleHelp,
57
+ test_status: handleTestStatus,
58
+ test_overview: handleTestOverview,
59
+ test_coverage: handleTestCoverage,
60
+ test_history: handleTestHistory,
61
+ test_trends: handleTestTrends,
62
+ test_errors: handleTestErrors,
63
+ file_coverage: handleFileCoverage,
64
+ settings_list: handleSettingsList,
65
+ cache_health: handleCacheHealth,
66
+ configure: handleConfigure,
67
+ commit_changes: handleCommitChanges,
68
+ turn_search: handleTurnSearch,
69
+ failure_signature_get: handleFailureSignatureGet,
70
+ acceptance_metrics: handleAcceptanceMetrics,
71
+ triage_brief: handleTriageBrief,
72
+ wrapup_prompt: handleWrapupPrompt,
73
+ inventory: McpToolkit.unionHandler(inventoryTool, handleInventory),
74
+ test: McpToolkit.unionHandler(testTool, handleTest),
75
+ register_agent: handleRegisterAgent,
76
+ note: McpToolkit.unionHandler(noteTool, handleNote),
77
+ hypothesis: McpToolkit.unionHandler(hypothesisTool, replayed({
78
+ tool: "hypothesis",
79
+ success: HypothesisResult,
80
+ key: hypothesisReplayKey
81
+ })(handleHypothesis)),
82
+ tdd_task: McpToolkit.unionHandler(tddTaskTool, replayed({
83
+ tool: "tdd_task",
84
+ success: TddTaskResult,
85
+ key: tddTaskReplayKey
86
+ })(handleTddTask)),
87
+ tdd_phase_transition_request: handlePhaseTransitionRequest,
88
+ tdd_goal: McpToolkit.unionHandler(tddGoalTool, replayed({
89
+ tool: "tdd_goal",
90
+ success: TddGoalResult,
91
+ key: tddGoalReplayKey
92
+ })(handleTddGoal)),
93
+ tdd_behavior: McpToolkit.unionHandler(tddBehaviorTool, replayed({
94
+ tool: "tdd_behavior",
95
+ success: TddBehaviorResult,
96
+ key: tddBehaviorReplayKey
97
+ })(handleTddBehavior)),
98
+ tdd_artifact_list: handleTddArtifactList,
99
+ tdd_progress_push: handleTddProgressPush,
100
+ run_tests: handleRunTests
101
+ };
97
102
  };
98
103
  /**
99
- * The handlers layer: provides `Tool.HandlersFor<typeof Kit.tools>`.
104
+ * Builds the handler for each tool in {@link Kit}: reads `DataReader` /
105
+ * `DataStore` once into the idempotent-replay store and wraps the write
106
+ * tools once over it (`@effected/mcp`'s `ToolReplay` guidance for a server:
107
+ * read the store when the handlers are built, never per call). Both services
108
+ * are fixed for the life of the server, the same instances the server's
109
+ * request middleware provides to each call.
110
+ *
111
+ * @public
112
+ */
113
+ const toolHandlers = Effect.map(makeReplayStore, makeToolHandlers);
114
+ /**
115
+ * The handlers layer: provides `Tool.HandlersFor<typeof Kit.tools>`, built
116
+ * from {@link toolHandlers}, so it requires `DataReader` / `DataStore`.
100
117
  *
101
118
  * @public
102
119
  */
103
120
  const ToolsLayer = Kit.toLayer(toolHandlers);
104
121
 
105
- export { Kit, ToolsLayer, toolHandlers };
122
+ export { Kit, ToolsLayer, makeToolHandlers, toolHandlers };
@@ -3,10 +3,8 @@ import { ToolOutputSchema } from "@effected/mcp";
3
3
  import { Context, Data, Effect, FileSystem, Layer, Option, Path, Result, Schema } from "effect";
4
4
  import { Tool } from "effect/ai";
5
5
  import { DataReader, DataStore } from "@vitest-agent/engine";
6
- import { AgentReport, RunDiagnostics, SuggestedActionRecord, VITEST_CONFIG_FILES, buildAgentReport, buildConsoleLeaks, coerceErrorField, collectConsoleLeakEntries, formatScopedCoverageNote, readStrayOutput, suggestedActionsFromRunDiagnostics } from "@vitest-agent/sdk";
7
- import { Exclusive, ProcessScope } from "@effected/engine";
8
- import { stat } from "node:fs/promises";
9
- import { isAbsolute, resolve } from "node:path";
6
+ import { AgentReport, RunDiagnostics, SuggestedActionRecord, VITEST_CONFIG_FILES, buildAgentReport, buildConsoleLeaks, collectConsoleLeakEntries, formatScopedCoverageNote, readStrayOutput, suggestedActionsFromRunDiagnostics } from "@vitest-agent/sdk";
7
+ import { ErrorText, Exclusive, ProcessScope } from "@effected/engine";
10
8
  import { fileURLToPath } from "node:url";
11
9
  import * as NodeChildProcessSpawner from "@effect/platform-node/NodeChildProcessSpawner";
12
10
  import * as NodeFileSystem from "@effect/platform-node/NodeFileSystem";
@@ -265,8 +263,6 @@ const resolveConfigAnchoredRoot = (startDir) => Effect.gen(function* () {
265
263
  const NodeFsPath = Layer.mergeAll(NodeFileSystem.layer, NodePath.layer);
266
264
  /** The Node platform the promise-shaped run body walks the real disk with; bound once so it memoizes. */
267
265
  const NodeWalkPlatform = Git.layer.pipe(Layer.provide(NodeChildProcessSpawner.layer), Layer.provideMerge(NodeFsPath));
268
- /** Run a never-failing platform walk against the real disk. */
269
- const runOnNodePlatform = (effect) => Effect.runPromise(Effect.provide(effect, NodeWalkPlatform));
270
266
  /**
271
267
  * Validate an optional caller-supplied `projectRoot` against `ctxCwd`
272
268
  * (the MCP server's boot-time root). `undefined` anchors at the directory
@@ -286,26 +282,24 @@ const runOnNodePlatform = (effect) => Effect.runPromise(Effect.provide(effect, N
286
282
  *
287
283
  * @internal exported for tests
288
284
  */
289
- async function validateProjectRoot(projectRoot, ctxCwd) {
285
+ const validateProjectRoot = Effect.fn("run_tests.validateProjectRoot")(function* (projectRoot, ctxCwd) {
290
286
  if (projectRoot === void 0) return {
291
287
  ok: true,
292
- root: await runOnNodePlatform(resolveConfigAnchoredRoot(ctxCwd))
288
+ root: yield* resolveConfigAnchoredRoot(ctxCwd)
293
289
  };
294
- const resolvedRoot = resolve(ctxCwd, projectRoot);
295
- let isDirectory;
296
- try {
297
- isDirectory = (await stat(resolvedRoot)).isDirectory();
298
- } catch {
299
- return {
300
- ok: false,
301
- message: `projectRoot "${resolvedRoot}" does not exist (ctx.cwd is "${ctxCwd}").`
302
- };
303
- }
304
- if (!isDirectory) return {
290
+ const path = yield* Path.Path;
291
+ const fs = yield* FileSystem.FileSystem;
292
+ const resolvedRoot = path.resolve(ctxCwd, projectRoot);
293
+ const info = yield* fs.stat(resolvedRoot).pipe(Effect.option, Effect.catchDefect(() => Effect.succeedNone));
294
+ if (Option.isNone(info)) return {
295
+ ok: false,
296
+ message: `projectRoot "${resolvedRoot}" does not exist (ctx.cwd is "${ctxCwd}").`
297
+ };
298
+ if (info.value.type !== "Directory") return {
305
299
  ok: false,
306
300
  message: `projectRoot "${resolvedRoot}" is not a directory (ctx.cwd is "${ctxCwd}").`
307
301
  };
308
- const [rootCommonDir, cwdCommonDir] = await runOnNodePlatform(Effect.all([gitCommonDir(resolvedRoot), gitCommonDir(ctxCwd)], { concurrency: 2 }));
302
+ const [rootCommonDir, cwdCommonDir] = yield* Effect.all([gitCommonDir(resolvedRoot), gitCommonDir(ctxCwd)], { concurrency: 2 });
309
303
  if (rootCommonDir === null || cwdCommonDir === null || rootCommonDir !== cwdCommonDir) return {
310
304
  ok: false,
311
305
  message: `projectRoot "${resolvedRoot}" does not belong to the same git repository as ctx.cwd "${ctxCwd}".`
@@ -314,7 +308,7 @@ async function validateProjectRoot(projectRoot, ctxCwd) {
314
308
  ok: true,
315
309
  root: resolvedRoot
316
310
  };
317
- }
311
+ });
318
312
  /**
319
313
  * The tree identity for `dir` (`Git.treeIdentity`: its physical toplevel and
320
314
  * the shared common dir, from one `git rev-parse`), or `None` when git cannot
@@ -332,16 +326,17 @@ const treeIdentityOf = (dir) => Effect.flatMap(Git, (git) => git.treeIdentity(di
332
326
  *
333
327
  * @internal exported for tests
334
328
  */
335
- async function checkCallerWorktree(callerCwd, resolvedRoot) {
336
- if (callerCwd === void 0 || callerCwd === "" || !isAbsolute(callerCwd)) return {
329
+ const checkCallerWorktree = Effect.fn("run_tests.checkCallerWorktree")(function* (callerCwd, resolvedRoot) {
330
+ const path = yield* Path.Path;
331
+ if (callerCwd === void 0 || callerCwd === "" || !path.isAbsolute(callerCwd)) return {
337
332
  ok: true,
338
333
  root: resolvedRoot
339
334
  };
340
- if (!await stat(callerCwd).then((s) => s.isDirectory(), () => false)) return {
335
+ if (!(yield* (yield* FileSystem.FileSystem).stat(callerCwd).pipe(Effect.map((info) => info.type === "Directory"), Effect.orElseSucceed(() => false), Effect.catchDefect(() => Effect.succeed(false))))) return {
341
336
  ok: true,
342
337
  root: resolvedRoot
343
338
  };
344
- const [caller, root] = await runOnNodePlatform(Effect.all([treeIdentityOf(callerCwd), treeIdentityOf(resolvedRoot)], { concurrency: 2 }));
339
+ const [caller, root] = yield* Effect.all([treeIdentityOf(callerCwd), treeIdentityOf(resolvedRoot)], { concurrency: 2 });
345
340
  if (Option.isNone(caller) || Option.isNone(root)) return {
346
341
  ok: true,
347
342
  root: resolvedRoot
@@ -354,7 +349,7 @@ async function checkCallerWorktree(callerCwd, resolvedRoot) {
354
349
  ok: false,
355
350
  message: `This call came from the working tree "${caller.value.toplevel}" but the Vitest root resolved to "${root.value.toplevel}", a different working tree of the same repository, so the run would report results for the wrong tree. Pass projectRoot (the absolute path of your own working tree, "${caller.value.toplevel}") to run there.`
356
351
  };
357
- }
352
+ });
358
353
  /**
359
354
  * Issue #303: resolve `vitest/node` anchored at the run's project root
360
355
  * instead of the bare `"vitest/node"` specifier, which resolves relative to
@@ -519,7 +514,7 @@ function deriveRunScope(input) {
519
514
  hasFilter
520
515
  });
521
516
  } catch (err) {
522
- return Result.fail(err instanceof Error ? err.message : String(err));
517
+ return Result.fail(ErrorText.describe(err));
523
518
  }
524
519
  }
525
520
  /**
@@ -590,17 +585,14 @@ function toOkPayload(args) {
590
585
  */
591
586
  const makeBestEffortFork = (services) => (effect) => Effect.runFork(Effect.provideContext(effect.pipe(Effect.ignore), services));
592
587
  /**
593
- * A rejected step's message. Exception-safe: a hostile thrown value (a
594
- * throwing `message` getter or `toString`) still yields a string, so the
595
- * `{ kind: "error" }` envelope always comes back.
588
+ * A rejected step's message: `ErrorText.describe`, which is total, so a
589
+ * hostile thrown value (a throwing `message` getter or `toString`) still
590
+ * yields a string and the `{ kind: "error" }` envelope always comes back. A
591
+ * plain `{ message }` object reads as its message and any other object as its
592
+ * JSON, never `[object Object]`. Deliberately not `ErrorText.of`: the
593
+ * envelope carries the rejected value's own message, not its cause chain.
596
594
  */
597
- const errorMessage = (err) => {
598
- try {
599
- return err instanceof Error ? err.message : String(err);
600
- } catch {
601
- return coerceErrorField(err, "message") ?? "<unserializable error>";
602
- }
603
- };
595
+ const errorMessage = (err) => ErrorText.describe(err);
604
596
  /**
605
597
  * A promise-returning Vitest step, run through the lane's promise. By default
606
598
  * an interrupt aborts, then waits for the promise to settle; `abandon` resumes
@@ -708,13 +700,13 @@ const runTestsBody = (input, ctx) => Effect.gen(function* () {
708
700
  message: derived.failure
709
701
  };
710
702
  const scope = derived.success;
711
- const projectRootValidation = yield* Effect.promise(() => validateProjectRoot(input.projectRoot, ctx.cwd));
703
+ const projectRootValidation = yield* onNodePlatform(validateProjectRoot(input.projectRoot, ctx.cwd));
712
704
  if (!projectRootValidation.ok) return {
713
705
  kind: "error",
714
706
  message: projectRootValidation.message
715
707
  };
716
708
  const resolvedRoot = projectRootValidation.root;
717
- const callerCheck = yield* Effect.promise(() => checkCallerWorktree(input._callerCwd, resolvedRoot));
709
+ const callerCheck = yield* onNodePlatform(checkCallerWorktree(input._callerCwd, resolvedRoot));
718
710
  if (!callerCheck.ok) return {
719
711
  kind: "error",
720
712
  message: callerCheck.message
package/version.js CHANGED
@@ -7,6 +7,6 @@
7
7
  *
8
8
  * @public
9
9
  */
10
- const CURRENT_MCP_VERSION = "6.0.1";
10
+ const CURRENT_MCP_VERSION = "6.1.0";
11
11
 
12
12
  export { CURRENT_MCP_VERSION };