@dexto/tools-plan 1.6.0 → 1.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/dist/errors.cjs +126 -0
  2. package/dist/errors.js +99 -64
  3. package/dist/index.cjs +36 -0
  4. package/dist/index.d.cts +224 -0
  5. package/dist/index.js +9 -12
  6. package/dist/plan-service-getter.cjs +16 -0
  7. package/dist/plan-service-getter.js +0 -1
  8. package/dist/plan-service.cjs +247 -0
  9. package/dist/plan-service.js +201 -215
  10. package/dist/plan-service.test.cjs +227 -0
  11. package/dist/plan-service.test.js +200 -222
  12. package/dist/tool-factory-config.cjs +38 -0
  13. package/dist/tool-factory-config.js +13 -30
  14. package/dist/tool-factory.cjs +71 -0
  15. package/dist/tool-factory.js +39 -35
  16. package/dist/tool-factory.test.cjs +96 -0
  17. package/dist/tool-factory.test.js +90 -95
  18. package/dist/tools/plan-create-tool.cjs +102 -0
  19. package/dist/tools/plan-create-tool.d.ts.map +1 -1
  20. package/dist/tools/plan-create-tool.js +77 -82
  21. package/dist/tools/plan-create-tool.test.cjs +174 -0
  22. package/dist/tools/plan-create-tool.test.js +142 -134
  23. package/dist/tools/plan-read-tool.cjs +65 -0
  24. package/dist/tools/plan-read-tool.d.ts.map +1 -1
  25. package/dist/tools/plan-read-tool.js +39 -41
  26. package/dist/tools/plan-read-tool.test.cjs +109 -0
  27. package/dist/tools/plan-read-tool.test.js +78 -87
  28. package/dist/tools/plan-review-tool.cjs +98 -0
  29. package/dist/tools/plan-review-tool.d.ts.map +1 -1
  30. package/dist/tools/plan-review-tool.js +73 -87
  31. package/dist/tools/plan-update-tool.cjs +92 -0
  32. package/dist/tools/plan-update-tool.d.ts.map +1 -1
  33. package/dist/tools/plan-update-tool.js +65 -73
  34. package/dist/tools/plan-update-tool.test.cjs +203 -0
  35. package/dist/tools/plan-update-tool.test.js +171 -154
  36. package/dist/types.cjs +44 -0
  37. package/dist/types.js +17 -24
  38. package/package.json +8 -7
@@ -1,83 +1,78 @@
1
- /**
2
- * Plan Create Tool
3
- *
4
- * Creates a new implementation plan for the current session.
5
- * Shows a preview for approval before saving.
6
- */
7
- import { z } from 'zod';
8
- import { defineTool } from '@dexto/core';
9
- import { PlanError } from '../errors.js';
10
- const PlanCreateInputSchema = z
11
- .object({
12
- title: z.string().describe('Plan title (e.g., "Add User Authentication")'),
13
- content: z
14
- .string()
15
- .describe('Plan content in markdown format. Use - [ ] and - [x] for checkboxes to track progress.'),
16
- })
17
- .strict();
18
- /**
19
- * Creates the plan_create tool
20
- */
21
- export function createPlanCreateTool(getPlanService) {
22
- return defineTool({
23
- id: 'plan_create',
24
- displayName: 'Plan',
25
- description: 'Create a new implementation plan for the current session. Shows the plan for approval before saving. Use markdown format for the plan content with clear steps and file references.',
26
- inputSchema: PlanCreateInputSchema,
27
- /**
28
- * Generate preview for approval UI
29
- */
30
- generatePreview: async (input, context) => {
31
- const { content } = input;
32
- if (!context.sessionId) {
33
- throw PlanError.sessionIdRequired();
34
- }
35
- const resolvedPlanService = await getPlanService(context);
36
- // Check if plan already exists
37
- const exists = await resolvedPlanService.exists(context.sessionId);
38
- if (exists) {
39
- throw PlanError.planAlreadyExists(context.sessionId);
40
- }
41
- // Return preview for approval UI
42
- const lineCount = content.split('\n').length;
43
- const planPath = resolvedPlanService.getPlanPath(context.sessionId);
44
- return {
45
- type: 'file',
46
- path: planPath,
47
- operation: 'create',
48
- content,
49
- size: Buffer.byteLength(content, 'utf8'),
50
- lineCount,
51
- };
52
- },
53
- async execute(input, context) {
54
- const { title, content } = input;
55
- if (!context.sessionId) {
56
- throw PlanError.sessionIdRequired();
57
- }
58
- const resolvedPlanService = await getPlanService(context);
59
- // Keep consistent with generatePreview: fail early if plan already exists.
60
- // (PlanService.create also guards this, but this keeps the control flow obvious.)
61
- const exists = await resolvedPlanService.exists(context.sessionId);
62
- if (exists) {
63
- throw PlanError.planAlreadyExists(context.sessionId);
64
- }
65
- const plan = await resolvedPlanService.create(context.sessionId, content, { title });
66
- const planPath = resolvedPlanService.getPlanPath(context.sessionId);
67
- const _display = {
68
- type: 'file',
69
- path: planPath,
70
- operation: 'create',
71
- size: Buffer.byteLength(content, 'utf8'),
72
- lineCount: content.split('\n').length,
73
- };
74
- return {
75
- success: true,
76
- path: planPath,
77
- status: plan.meta.status,
78
- title: plan.meta.title,
79
- _display,
80
- };
81
- },
82
- });
1
+ import { z } from "zod";
2
+ import { createLocalToolCallHeader, defineTool, truncateForHeader } from "@dexto/core";
3
+ import { PlanError } from "../errors.js";
4
+ const PlanCreateInputSchema = z.object({
5
+ title: z.string().describe('Plan title (e.g., "Add User Authentication")'),
6
+ content: z.string().describe(
7
+ "Plan content in markdown format. Use - [ ] and - [x] for checkboxes to track progress."
8
+ )
9
+ }).strict();
10
+ function createPlanCreateTool(getPlanService) {
11
+ return defineTool({
12
+ id: "plan_create",
13
+ description: "Create a new implementation plan for the current session. Shows the plan for approval before saving. Use markdown format for the plan content with clear steps and file references.",
14
+ inputSchema: PlanCreateInputSchema,
15
+ presentation: {
16
+ describeHeader: (input) => createLocalToolCallHeader({
17
+ title: "Create Plan",
18
+ argsText: truncateForHeader(input.title, 140)
19
+ }),
20
+ /**
21
+ * Generate preview for approval UI
22
+ */
23
+ preview: async (input, context) => {
24
+ const { content } = input;
25
+ if (!context.sessionId) {
26
+ throw PlanError.sessionIdRequired();
27
+ }
28
+ const resolvedPlanService = await getPlanService(context);
29
+ const exists = await resolvedPlanService.exists(context.sessionId);
30
+ if (exists) {
31
+ throw PlanError.planAlreadyExists(context.sessionId);
32
+ }
33
+ const lineCount = content.split("\n").length;
34
+ const planPath = resolvedPlanService.getPlanPath(context.sessionId);
35
+ return {
36
+ type: "file",
37
+ title: "Create Plan",
38
+ path: planPath,
39
+ operation: "create",
40
+ content,
41
+ size: Buffer.byteLength(content, "utf8"),
42
+ lineCount
43
+ };
44
+ }
45
+ },
46
+ async execute(input, context) {
47
+ const { title, content } = input;
48
+ if (!context.sessionId) {
49
+ throw PlanError.sessionIdRequired();
50
+ }
51
+ const resolvedPlanService = await getPlanService(context);
52
+ const exists = await resolvedPlanService.exists(context.sessionId);
53
+ if (exists) {
54
+ throw PlanError.planAlreadyExists(context.sessionId);
55
+ }
56
+ const plan = await resolvedPlanService.create(context.sessionId, content, { title });
57
+ const planPath = resolvedPlanService.getPlanPath(context.sessionId);
58
+ const _display = {
59
+ type: "file",
60
+ title: "Create Plan",
61
+ path: planPath,
62
+ operation: "create",
63
+ size: Buffer.byteLength(content, "utf8"),
64
+ lineCount: content.split("\n").length
65
+ };
66
+ return {
67
+ success: true,
68
+ path: planPath,
69
+ status: plan.meta.status,
70
+ title: plan.meta.title,
71
+ _display
72
+ };
73
+ }
74
+ });
83
75
  }
76
+ export {
77
+ createPlanCreateTool
78
+ };
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (let key of __getOwnPropNames(from))
11
+ if (!__hasOwnProp.call(to, key) && key !== except)
12
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ }
14
+ return to;
15
+ };
16
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
+ // If the importer is in node compatibility mode or this is not an ESM
18
+ // file that has been converted to a CommonJS file using a Babel-
19
+ // compatible transform (i.e. "__esModule" has not been set), then set
20
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ var import_vitest = require("vitest");
25
+ var path = __toESM(require("node:path"), 1);
26
+ var fs = __toESM(require("node:fs/promises"), 1);
27
+ var os = __toESM(require("node:os"), 1);
28
+ var import_plan_create_tool = require("./plan-create-tool.js");
29
+ var import_plan_service = require("../plan-service.js");
30
+ var import_errors = require("../errors.js");
31
+ var import_core = require("@dexto/core");
32
+ const createMockLogger = () => {
33
+ const logger = {
34
+ debug: import_vitest.vi.fn(),
35
+ silly: import_vitest.vi.fn(),
36
+ info: import_vitest.vi.fn(),
37
+ warn: import_vitest.vi.fn(),
38
+ error: import_vitest.vi.fn(),
39
+ trackException: import_vitest.vi.fn(),
40
+ createChild: import_vitest.vi.fn(() => logger),
41
+ createFileOnlyChild: import_vitest.vi.fn(() => logger),
42
+ setLevel: import_vitest.vi.fn(),
43
+ getLevel: import_vitest.vi.fn(() => "debug"),
44
+ getLogFilePath: import_vitest.vi.fn(() => null),
45
+ destroy: import_vitest.vi.fn(async () => void 0)
46
+ };
47
+ return logger;
48
+ };
49
+ function createToolContext(logger, overrides = {}) {
50
+ return { logger, ...overrides };
51
+ }
52
+ (0, import_vitest.describe)("plan_create tool", () => {
53
+ let logger;
54
+ let tempDir;
55
+ let planService;
56
+ (0, import_vitest.beforeEach)(async () => {
57
+ logger = createMockLogger();
58
+ const rawTempDir = await fs.mkdtemp(path.join(os.tmpdir(), "dexto-plan-create-test-"));
59
+ tempDir = await fs.realpath(rawTempDir);
60
+ planService = new import_plan_service.PlanService({ basePath: tempDir }, logger);
61
+ import_vitest.vi.clearAllMocks();
62
+ });
63
+ (0, import_vitest.afterEach)(async () => {
64
+ try {
65
+ await fs.rm(tempDir, { recursive: true, force: true });
66
+ } catch {
67
+ }
68
+ });
69
+ (0, import_vitest.describe)("generatePreview", () => {
70
+ (0, import_vitest.it)("should return FileDisplayData for new plan", async () => {
71
+ const tool = (0, import_plan_create_tool.createPlanCreateTool)(async () => planService);
72
+ const sessionId = "test-session";
73
+ const content = "# Implementation Plan\n\n## Steps\n1. First step";
74
+ const previewFn = tool.presentation?.preview;
75
+ (0, import_vitest.expect)(previewFn).toBeDefined();
76
+ const preview = await previewFn(
77
+ { title: "Test Plan", content },
78
+ createToolContext(logger, { sessionId })
79
+ );
80
+ (0, import_vitest.expect)(preview.type).toBe("file");
81
+ (0, import_vitest.expect)(preview.title).toBe("Create Plan");
82
+ (0, import_vitest.expect)(preview.operation).toBe("create");
83
+ (0, import_vitest.expect)(preview.path).toContain(sessionId);
84
+ (0, import_vitest.expect)(preview.path).toMatch(/plan\.md$/);
85
+ (0, import_vitest.expect)(preview.content).toBe(content);
86
+ (0, import_vitest.expect)(preview.lineCount).toBe(4);
87
+ });
88
+ (0, import_vitest.it)("should throw error when sessionId is missing", async () => {
89
+ const tool = (0, import_plan_create_tool.createPlanCreateTool)(async () => planService);
90
+ const previewFn = tool.presentation?.preview;
91
+ (0, import_vitest.expect)(previewFn).toBeDefined();
92
+ try {
93
+ await previewFn({ title: "Test", content: "# Plan" }, createToolContext(logger));
94
+ import_vitest.expect.fail("Should have thrown an error");
95
+ } catch (error) {
96
+ (0, import_vitest.expect)(error).toBeInstanceOf(import_core.DextoRuntimeError);
97
+ (0, import_vitest.expect)(error.code).toBe(import_errors.PlanErrorCode.SESSION_ID_REQUIRED);
98
+ }
99
+ });
100
+ (0, import_vitest.it)("should throw error when plan already exists", async () => {
101
+ const tool = (0, import_plan_create_tool.createPlanCreateTool)(async () => planService);
102
+ const sessionId = "test-session";
103
+ const previewFn = tool.presentation?.preview;
104
+ (0, import_vitest.expect)(previewFn).toBeDefined();
105
+ await planService.create(sessionId, "# Existing Plan");
106
+ try {
107
+ await previewFn(
108
+ { title: "New Plan", content: "# New Content" },
109
+ createToolContext(logger, { sessionId })
110
+ );
111
+ import_vitest.expect.fail("Should have thrown an error");
112
+ } catch (error) {
113
+ (0, import_vitest.expect)(error).toBeInstanceOf(import_core.DextoRuntimeError);
114
+ (0, import_vitest.expect)(error.code).toBe(import_errors.PlanErrorCode.PLAN_ALREADY_EXISTS);
115
+ }
116
+ });
117
+ });
118
+ (0, import_vitest.describe)("execute", () => {
119
+ (0, import_vitest.it)("should create plan and return success", async () => {
120
+ const tool = (0, import_plan_create_tool.createPlanCreateTool)(async () => planService);
121
+ const sessionId = "test-session";
122
+ const content = "# Implementation Plan";
123
+ const title = "My Plan";
124
+ const result = await tool.execute(
125
+ { title, content },
126
+ createToolContext(logger, { sessionId })
127
+ );
128
+ (0, import_vitest.expect)(result.success).toBe(true);
129
+ (0, import_vitest.expect)(result.path).toContain(sessionId);
130
+ (0, import_vitest.expect)(result.path).toMatch(/plan\.md$/);
131
+ (0, import_vitest.expect)(result.status).toBe("draft");
132
+ (0, import_vitest.expect)(result.title).toBe(title);
133
+ });
134
+ (0, import_vitest.it)("should throw error when plan already exists", async () => {
135
+ const tool = (0, import_plan_create_tool.createPlanCreateTool)(async () => planService);
136
+ const sessionId = "test-session";
137
+ await planService.create(sessionId, "# Existing Plan");
138
+ try {
139
+ await tool.execute(
140
+ { title: "New Plan", content: "# New content" },
141
+ createToolContext(logger, { sessionId })
142
+ );
143
+ import_vitest.expect.fail("Should have thrown an error");
144
+ } catch (error) {
145
+ (0, import_vitest.expect)(error).toBeInstanceOf(import_core.DextoRuntimeError);
146
+ (0, import_vitest.expect)(error.code).toBe(import_errors.PlanErrorCode.PLAN_ALREADY_EXISTS);
147
+ }
148
+ });
149
+ (0, import_vitest.it)("should throw error when sessionId is missing", async () => {
150
+ const tool = (0, import_plan_create_tool.createPlanCreateTool)(async () => planService);
151
+ try {
152
+ await tool.execute({ title: "Test", content: "# Plan" }, createToolContext(logger));
153
+ import_vitest.expect.fail("Should have thrown an error");
154
+ } catch (error) {
155
+ (0, import_vitest.expect)(error).toBeInstanceOf(import_core.DextoRuntimeError);
156
+ (0, import_vitest.expect)(error.code).toBe(import_errors.PlanErrorCode.SESSION_ID_REQUIRED);
157
+ }
158
+ });
159
+ (0, import_vitest.it)("should include _display data in result", async () => {
160
+ const tool = (0, import_plan_create_tool.createPlanCreateTool)(async () => planService);
161
+ const sessionId = "test-session";
162
+ const content = "# Plan\n## Steps";
163
+ const result = await tool.execute(
164
+ { title: "Plan", content },
165
+ createToolContext(logger, { sessionId })
166
+ );
167
+ (0, import_vitest.expect)(result._display).toBeDefined();
168
+ (0, import_vitest.expect)(result._display.type).toBe("file");
169
+ (0, import_vitest.expect)(result._display.title).toBe("Create Plan");
170
+ (0, import_vitest.expect)(result._display.operation).toBe("create");
171
+ (0, import_vitest.expect)(result._display.lineCount).toBe(2);
172
+ });
173
+ });
174
+ });
@@ -1,143 +1,151 @@
1
- /**
2
- * Plan Create Tool Tests
3
- *
4
- * Tests for the plan_create tool including preview generation.
5
- */
6
- import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
7
- import * as path from 'node:path';
8
- import * as fs from 'node:fs/promises';
9
- import * as os from 'node:os';
10
- import { createPlanCreateTool } from './plan-create-tool.js';
11
- import { PlanService } from '../plan-service.js';
12
- import { PlanErrorCode } from '../errors.js';
13
- import { DextoRuntimeError } from '@dexto/core';
14
- // Create mock logger
1
+ import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
2
+ import * as path from "node:path";
3
+ import * as fs from "node:fs/promises";
4
+ import * as os from "node:os";
5
+ import { createPlanCreateTool } from "./plan-create-tool.js";
6
+ import { PlanService } from "../plan-service.js";
7
+ import { PlanErrorCode } from "../errors.js";
8
+ import { DextoRuntimeError } from "@dexto/core";
15
9
  const createMockLogger = () => {
16
- const logger = {
17
- debug: vi.fn(),
18
- silly: vi.fn(),
19
- info: vi.fn(),
20
- warn: vi.fn(),
21
- error: vi.fn(),
22
- trackException: vi.fn(),
23
- createChild: vi.fn(() => logger),
24
- setLevel: vi.fn(),
25
- getLevel: vi.fn(() => 'debug'),
26
- getLogFilePath: vi.fn(() => null),
27
- destroy: vi.fn(async () => undefined),
28
- };
29
- return logger;
10
+ const logger = {
11
+ debug: vi.fn(),
12
+ silly: vi.fn(),
13
+ info: vi.fn(),
14
+ warn: vi.fn(),
15
+ error: vi.fn(),
16
+ trackException: vi.fn(),
17
+ createChild: vi.fn(() => logger),
18
+ createFileOnlyChild: vi.fn(() => logger),
19
+ setLevel: vi.fn(),
20
+ getLevel: vi.fn(() => "debug"),
21
+ getLogFilePath: vi.fn(() => null),
22
+ destroy: vi.fn(async () => void 0)
23
+ };
24
+ return logger;
30
25
  };
31
26
  function createToolContext(logger, overrides = {}) {
32
- return { logger, ...overrides };
27
+ return { logger, ...overrides };
33
28
  }
34
- describe('plan_create tool', () => {
35
- let logger;
36
- let tempDir;
37
- let planService;
38
- beforeEach(async () => {
39
- logger = createMockLogger();
40
- // Create temp directory for testing
41
- const rawTempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'dexto-plan-create-test-'));
42
- tempDir = await fs.realpath(rawTempDir);
43
- planService = new PlanService({ basePath: tempDir }, logger);
44
- vi.clearAllMocks();
29
+ describe("plan_create tool", () => {
30
+ let logger;
31
+ let tempDir;
32
+ let planService;
33
+ beforeEach(async () => {
34
+ logger = createMockLogger();
35
+ const rawTempDir = await fs.mkdtemp(path.join(os.tmpdir(), "dexto-plan-create-test-"));
36
+ tempDir = await fs.realpath(rawTempDir);
37
+ planService = new PlanService({ basePath: tempDir }, logger);
38
+ vi.clearAllMocks();
39
+ });
40
+ afterEach(async () => {
41
+ try {
42
+ await fs.rm(tempDir, { recursive: true, force: true });
43
+ } catch {
44
+ }
45
+ });
46
+ describe("generatePreview", () => {
47
+ it("should return FileDisplayData for new plan", async () => {
48
+ const tool = createPlanCreateTool(async () => planService);
49
+ const sessionId = "test-session";
50
+ const content = "# Implementation Plan\n\n## Steps\n1. First step";
51
+ const previewFn = tool.presentation?.preview;
52
+ expect(previewFn).toBeDefined();
53
+ const preview = await previewFn(
54
+ { title: "Test Plan", content },
55
+ createToolContext(logger, { sessionId })
56
+ );
57
+ expect(preview.type).toBe("file");
58
+ expect(preview.title).toBe("Create Plan");
59
+ expect(preview.operation).toBe("create");
60
+ expect(preview.path).toContain(sessionId);
61
+ expect(preview.path).toMatch(/plan\.md$/);
62
+ expect(preview.content).toBe(content);
63
+ expect(preview.lineCount).toBe(4);
45
64
  });
46
- afterEach(async () => {
47
- try {
48
- await fs.rm(tempDir, { recursive: true, force: true });
49
- }
50
- catch {
51
- // Ignore cleanup errors
52
- }
65
+ it("should throw error when sessionId is missing", async () => {
66
+ const tool = createPlanCreateTool(async () => planService);
67
+ const previewFn = tool.presentation?.preview;
68
+ expect(previewFn).toBeDefined();
69
+ try {
70
+ await previewFn({ title: "Test", content: "# Plan" }, createToolContext(logger));
71
+ expect.fail("Should have thrown an error");
72
+ } catch (error) {
73
+ expect(error).toBeInstanceOf(DextoRuntimeError);
74
+ expect(error.code).toBe(PlanErrorCode.SESSION_ID_REQUIRED);
75
+ }
53
76
  });
54
- describe('generatePreview', () => {
55
- it('should return FileDisplayData for new plan', async () => {
56
- const tool = createPlanCreateTool(async () => planService);
57
- const sessionId = 'test-session';
58
- const content = '# Implementation Plan\n\n## Steps\n1. First step';
59
- const preview = (await tool.generatePreview({ title: 'Test Plan', content }, createToolContext(logger, { sessionId })));
60
- expect(preview.type).toBe('file');
61
- expect(preview.operation).toBe('create');
62
- // Path is now absolute, check it ends with the expected suffix
63
- expect(preview.path).toContain(sessionId);
64
- expect(preview.path).toMatch(/plan\.md$/);
65
- expect(preview.content).toBe(content);
66
- expect(preview.lineCount).toBe(4);
67
- });
68
- it('should throw error when sessionId is missing', async () => {
69
- const tool = createPlanCreateTool(async () => planService);
70
- try {
71
- await tool.generatePreview({ title: 'Test', content: '# Plan' }, createToolContext(logger));
72
- expect.fail('Should have thrown an error');
73
- }
74
- catch (error) {
75
- expect(error).toBeInstanceOf(DextoRuntimeError);
76
- expect(error.code).toBe(PlanErrorCode.SESSION_ID_REQUIRED);
77
- }
78
- });
79
- it('should throw error when plan already exists', async () => {
80
- const tool = createPlanCreateTool(async () => planService);
81
- const sessionId = 'test-session';
82
- // Create existing plan
83
- await planService.create(sessionId, '# Existing Plan');
84
- try {
85
- await tool.generatePreview({ title: 'New Plan', content: '# New Content' }, createToolContext(logger, { sessionId }));
86
- expect.fail('Should have thrown an error');
87
- }
88
- catch (error) {
89
- expect(error).toBeInstanceOf(DextoRuntimeError);
90
- expect(error.code).toBe(PlanErrorCode.PLAN_ALREADY_EXISTS);
91
- }
92
- });
77
+ it("should throw error when plan already exists", async () => {
78
+ const tool = createPlanCreateTool(async () => planService);
79
+ const sessionId = "test-session";
80
+ const previewFn = tool.presentation?.preview;
81
+ expect(previewFn).toBeDefined();
82
+ await planService.create(sessionId, "# Existing Plan");
83
+ try {
84
+ await previewFn(
85
+ { title: "New Plan", content: "# New Content" },
86
+ createToolContext(logger, { sessionId })
87
+ );
88
+ expect.fail("Should have thrown an error");
89
+ } catch (error) {
90
+ expect(error).toBeInstanceOf(DextoRuntimeError);
91
+ expect(error.code).toBe(PlanErrorCode.PLAN_ALREADY_EXISTS);
92
+ }
93
93
  });
94
- describe('execute', () => {
95
- it('should create plan and return success', async () => {
96
- const tool = createPlanCreateTool(async () => planService);
97
- const sessionId = 'test-session';
98
- const content = '# Implementation Plan';
99
- const title = 'My Plan';
100
- const result = (await tool.execute({ title, content }, createToolContext(logger, { sessionId })));
101
- expect(result.success).toBe(true);
102
- // Path is now absolute, check it ends with the expected suffix
103
- expect(result.path).toContain(sessionId);
104
- expect(result.path).toMatch(/plan\.md$/);
105
- expect(result.status).toBe('draft');
106
- expect(result.title).toBe(title);
107
- });
108
- it('should throw error when plan already exists', async () => {
109
- const tool = createPlanCreateTool(async () => planService);
110
- const sessionId = 'test-session';
111
- await planService.create(sessionId, '# Existing Plan');
112
- try {
113
- await tool.execute({ title: 'New Plan', content: '# New content' }, createToolContext(logger, { sessionId }));
114
- expect.fail('Should have thrown an error');
115
- }
116
- catch (error) {
117
- expect(error).toBeInstanceOf(DextoRuntimeError);
118
- expect(error.code).toBe(PlanErrorCode.PLAN_ALREADY_EXISTS);
119
- }
120
- });
121
- it('should throw error when sessionId is missing', async () => {
122
- const tool = createPlanCreateTool(async () => planService);
123
- try {
124
- await tool.execute({ title: 'Test', content: '# Plan' }, createToolContext(logger));
125
- expect.fail('Should have thrown an error');
126
- }
127
- catch (error) {
128
- expect(error).toBeInstanceOf(DextoRuntimeError);
129
- expect(error.code).toBe(PlanErrorCode.SESSION_ID_REQUIRED);
130
- }
131
- });
132
- it('should include _display data in result', async () => {
133
- const tool = createPlanCreateTool(async () => planService);
134
- const sessionId = 'test-session';
135
- const content = '# Plan\n## Steps';
136
- const result = (await tool.execute({ title: 'Plan', content }, createToolContext(logger, { sessionId })));
137
- expect(result._display).toBeDefined();
138
- expect(result._display.type).toBe('file');
139
- expect(result._display.operation).toBe('create');
140
- expect(result._display.lineCount).toBe(2);
141
- });
94
+ });
95
+ describe("execute", () => {
96
+ it("should create plan and return success", async () => {
97
+ const tool = createPlanCreateTool(async () => planService);
98
+ const sessionId = "test-session";
99
+ const content = "# Implementation Plan";
100
+ const title = "My Plan";
101
+ const result = await tool.execute(
102
+ { title, content },
103
+ createToolContext(logger, { sessionId })
104
+ );
105
+ expect(result.success).toBe(true);
106
+ expect(result.path).toContain(sessionId);
107
+ expect(result.path).toMatch(/plan\.md$/);
108
+ expect(result.status).toBe("draft");
109
+ expect(result.title).toBe(title);
142
110
  });
111
+ it("should throw error when plan already exists", async () => {
112
+ const tool = createPlanCreateTool(async () => planService);
113
+ const sessionId = "test-session";
114
+ await planService.create(sessionId, "# Existing Plan");
115
+ try {
116
+ await tool.execute(
117
+ { title: "New Plan", content: "# New content" },
118
+ createToolContext(logger, { sessionId })
119
+ );
120
+ expect.fail("Should have thrown an error");
121
+ } catch (error) {
122
+ expect(error).toBeInstanceOf(DextoRuntimeError);
123
+ expect(error.code).toBe(PlanErrorCode.PLAN_ALREADY_EXISTS);
124
+ }
125
+ });
126
+ it("should throw error when sessionId is missing", async () => {
127
+ const tool = createPlanCreateTool(async () => planService);
128
+ try {
129
+ await tool.execute({ title: "Test", content: "# Plan" }, createToolContext(logger));
130
+ expect.fail("Should have thrown an error");
131
+ } catch (error) {
132
+ expect(error).toBeInstanceOf(DextoRuntimeError);
133
+ expect(error.code).toBe(PlanErrorCode.SESSION_ID_REQUIRED);
134
+ }
135
+ });
136
+ it("should include _display data in result", async () => {
137
+ const tool = createPlanCreateTool(async () => planService);
138
+ const sessionId = "test-session";
139
+ const content = "# Plan\n## Steps";
140
+ const result = await tool.execute(
141
+ { title: "Plan", content },
142
+ createToolContext(logger, { sessionId })
143
+ );
144
+ expect(result._display).toBeDefined();
145
+ expect(result._display.type).toBe("file");
146
+ expect(result._display.title).toBe("Create Plan");
147
+ expect(result._display.operation).toBe("create");
148
+ expect(result._display.lineCount).toBe(2);
149
+ });
150
+ });
143
151
  });