@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.
- package/dist/errors.cjs +126 -0
- package/dist/errors.js +99 -64
- package/dist/index.cjs +36 -0
- package/dist/index.d.cts +224 -0
- package/dist/index.js +9 -12
- package/dist/plan-service-getter.cjs +16 -0
- package/dist/plan-service-getter.js +0 -1
- package/dist/plan-service.cjs +247 -0
- package/dist/plan-service.js +201 -215
- package/dist/plan-service.test.cjs +227 -0
- package/dist/plan-service.test.js +200 -222
- package/dist/tool-factory-config.cjs +38 -0
- package/dist/tool-factory-config.js +13 -30
- package/dist/tool-factory.cjs +71 -0
- package/dist/tool-factory.js +39 -35
- package/dist/tool-factory.test.cjs +96 -0
- package/dist/tool-factory.test.js +90 -95
- package/dist/tools/plan-create-tool.cjs +102 -0
- package/dist/tools/plan-create-tool.d.ts.map +1 -1
- package/dist/tools/plan-create-tool.js +77 -82
- package/dist/tools/plan-create-tool.test.cjs +174 -0
- package/dist/tools/plan-create-tool.test.js +142 -134
- package/dist/tools/plan-read-tool.cjs +65 -0
- package/dist/tools/plan-read-tool.d.ts.map +1 -1
- package/dist/tools/plan-read-tool.js +39 -41
- package/dist/tools/plan-read-tool.test.cjs +109 -0
- package/dist/tools/plan-read-tool.test.js +78 -87
- package/dist/tools/plan-review-tool.cjs +98 -0
- package/dist/tools/plan-review-tool.d.ts.map +1 -1
- package/dist/tools/plan-review-tool.js +73 -87
- package/dist/tools/plan-update-tool.cjs +92 -0
- package/dist/tools/plan-update-tool.d.ts.map +1 -1
- package/dist/tools/plan-update-tool.js +65 -73
- package/dist/tools/plan-update-tool.test.cjs +203 -0
- package/dist/tools/plan-update-tool.test.js +171 -154
- package/dist/types.cjs +44 -0
- package/dist/types.js +17 -24
- package/package.json +8 -7
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var plan_read_tool_exports = {};
|
|
20
|
+
__export(plan_read_tool_exports, {
|
|
21
|
+
createPlanReadTool: () => createPlanReadTool
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(plan_read_tool_exports);
|
|
24
|
+
var import_zod = require("zod");
|
|
25
|
+
var import_core = require("@dexto/core");
|
|
26
|
+
var import_errors = require("../errors.js");
|
|
27
|
+
const PlanReadInputSchema = import_zod.z.object({}).strict();
|
|
28
|
+
function createPlanReadTool(getPlanService) {
|
|
29
|
+
return (0, import_core.defineTool)({
|
|
30
|
+
id: "plan_read",
|
|
31
|
+
description: "Read the current implementation plan for this session. Returns the plan content and metadata including status. Use markdown checkboxes (- [ ] and - [x]) in the content to track progress.",
|
|
32
|
+
inputSchema: PlanReadInputSchema,
|
|
33
|
+
presentation: {
|
|
34
|
+
describeHeader: () => (0, import_core.createLocalToolCallHeader)({
|
|
35
|
+
title: "Read Plan"
|
|
36
|
+
})
|
|
37
|
+
},
|
|
38
|
+
async execute(_input, context) {
|
|
39
|
+
const resolvedPlanService = await getPlanService(context);
|
|
40
|
+
if (!context.sessionId) {
|
|
41
|
+
throw import_errors.PlanError.sessionIdRequired();
|
|
42
|
+
}
|
|
43
|
+
const plan = await resolvedPlanService.read(context.sessionId);
|
|
44
|
+
if (!plan) {
|
|
45
|
+
return {
|
|
46
|
+
exists: false,
|
|
47
|
+
message: `No plan found for this session. Use plan_create to create one.`
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
exists: true,
|
|
52
|
+
path: resolvedPlanService.getPlanPath(context.sessionId),
|
|
53
|
+
content: plan.content,
|
|
54
|
+
status: plan.meta.status,
|
|
55
|
+
title: plan.meta.title,
|
|
56
|
+
createdAt: new Date(plan.meta.createdAt).toISOString(),
|
|
57
|
+
updatedAt: new Date(plan.meta.updatedAt).toISOString()
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
63
|
+
0 && (module.exports = {
|
|
64
|
+
createPlanReadTool
|
|
65
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plan-read-tool.d.ts","sourceRoot":"","sources":["../../src/tools/plan-read-tool.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,IAAI,EAAwB,MAAM,aAAa,CAAC;AAC9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAGnE,QAAA,MAAM,mBAAmB,iDAAwB,CAAC;AAElD;;GAEG;AACH,wBAAgB,kBAAkB,CAC9B,cAAc,EAAE,iBAAiB,GAClC,IAAI,CAAC,OAAO,mBAAmB,CAAC,
|
|
1
|
+
{"version":3,"file":"plan-read-tool.d.ts","sourceRoot":"","sources":["../../src/tools/plan-read-tool.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,IAAI,EAAwB,MAAM,aAAa,CAAC;AAC9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAGnE,QAAA,MAAM,mBAAmB,iDAAwB,CAAC;AAElD;;GAEG;AACH,wBAAgB,kBAAkB,CAC9B,cAAc,EAAE,iBAAiB,GAClC,IAAI,CAAC,OAAO,mBAAmB,CAAC,CAuClC"}
|
|
@@ -1,43 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* Reads the current implementation plan for the session.
|
|
5
|
-
* No approval needed - read-only operation.
|
|
6
|
-
*/
|
|
7
|
-
import { z } from 'zod';
|
|
8
|
-
import { defineTool } from '@dexto/core';
|
|
9
|
-
import { PlanError } from '../errors.js';
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { createLocalToolCallHeader, defineTool } from "@dexto/core";
|
|
3
|
+
import { PlanError } from "../errors.js";
|
|
10
4
|
const PlanReadInputSchema = z.object({}).strict();
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
5
|
+
function createPlanReadTool(getPlanService) {
|
|
6
|
+
return defineTool({
|
|
7
|
+
id: "plan_read",
|
|
8
|
+
description: "Read the current implementation plan for this session. Returns the plan content and metadata including status. Use markdown checkboxes (- [ ] and - [x]) in the content to track progress.",
|
|
9
|
+
inputSchema: PlanReadInputSchema,
|
|
10
|
+
presentation: {
|
|
11
|
+
describeHeader: () => createLocalToolCallHeader({
|
|
12
|
+
title: "Read Plan"
|
|
13
|
+
})
|
|
14
|
+
},
|
|
15
|
+
async execute(_input, context) {
|
|
16
|
+
const resolvedPlanService = await getPlanService(context);
|
|
17
|
+
if (!context.sessionId) {
|
|
18
|
+
throw PlanError.sessionIdRequired();
|
|
19
|
+
}
|
|
20
|
+
const plan = await resolvedPlanService.read(context.sessionId);
|
|
21
|
+
if (!plan) {
|
|
22
|
+
return {
|
|
23
|
+
exists: false,
|
|
24
|
+
message: `No plan found for this session. Use plan_create to create one.`
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
exists: true,
|
|
29
|
+
path: resolvedPlanService.getPlanPath(context.sessionId),
|
|
30
|
+
content: plan.content,
|
|
31
|
+
status: plan.meta.status,
|
|
32
|
+
title: plan.meta.title,
|
|
33
|
+
createdAt: new Date(plan.meta.createdAt).toISOString(),
|
|
34
|
+
updatedAt: new Date(plan.meta.updatedAt).toISOString()
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
});
|
|
43
38
|
}
|
|
39
|
+
export {
|
|
40
|
+
createPlanReadTool
|
|
41
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
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_read_tool = require("./plan-read-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_read 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-read-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)("execute", () => {
|
|
70
|
+
(0, import_vitest.it)("should return exists: false when no plan exists", async () => {
|
|
71
|
+
const tool = (0, import_plan_read_tool.createPlanReadTool)(async () => planService);
|
|
72
|
+
const sessionId = "test-session";
|
|
73
|
+
const result = await tool.execute({}, createToolContext(logger, { sessionId }));
|
|
74
|
+
(0, import_vitest.expect)(result.exists).toBe(false);
|
|
75
|
+
(0, import_vitest.expect)(result.message).toContain("No plan found");
|
|
76
|
+
});
|
|
77
|
+
(0, import_vitest.it)("should return plan content and metadata when plan exists", async () => {
|
|
78
|
+
const tool = (0, import_plan_read_tool.createPlanReadTool)(async () => planService);
|
|
79
|
+
const sessionId = "test-session";
|
|
80
|
+
const content = "# My Plan\n\nSome content";
|
|
81
|
+
const title = "My Plan Title";
|
|
82
|
+
await planService.create(sessionId, content, { title });
|
|
83
|
+
const result = await tool.execute({}, createToolContext(logger, { sessionId }));
|
|
84
|
+
(0, import_vitest.expect)(result.exists).toBe(true);
|
|
85
|
+
(0, import_vitest.expect)(result.content).toBe(content);
|
|
86
|
+
(0, import_vitest.expect)(result.status).toBe("draft");
|
|
87
|
+
(0, import_vitest.expect)(result.title).toBe(title);
|
|
88
|
+
(0, import_vitest.expect)(result.path).toBe(path.join(tempDir, sessionId, "plan.md"));
|
|
89
|
+
});
|
|
90
|
+
(0, import_vitest.it)("should return ISO timestamps", async () => {
|
|
91
|
+
const tool = (0, import_plan_read_tool.createPlanReadTool)(async () => planService);
|
|
92
|
+
const sessionId = "test-session";
|
|
93
|
+
await planService.create(sessionId, "# Plan");
|
|
94
|
+
const result = await tool.execute({}, createToolContext(logger, { sessionId }));
|
|
95
|
+
(0, import_vitest.expect)(result.createdAt).toMatch(/^\d{4}-\d{2}-\d{2}T/);
|
|
96
|
+
(0, import_vitest.expect)(result.updatedAt).toMatch(/^\d{4}-\d{2}-\d{2}T/);
|
|
97
|
+
});
|
|
98
|
+
(0, import_vitest.it)("should throw error when sessionId is missing", async () => {
|
|
99
|
+
const tool = (0, import_plan_read_tool.createPlanReadTool)(async () => planService);
|
|
100
|
+
try {
|
|
101
|
+
await tool.execute({}, createToolContext(logger));
|
|
102
|
+
import_vitest.expect.fail("Should have thrown an error");
|
|
103
|
+
} catch (error) {
|
|
104
|
+
(0, import_vitest.expect)(error).toBeInstanceOf(import_core.DextoRuntimeError);
|
|
105
|
+
(0, import_vitest.expect)(error.code).toBe(import_errors.PlanErrorCode.SESSION_ID_REQUIRED);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
});
|
|
@@ -1,95 +1,86 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import * as os from 'node:os';
|
|
10
|
-
import { createPlanReadTool } from './plan-read-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 { createPlanReadTool } from "./plan-read-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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
27
|
+
return { logger, ...overrides };
|
|
33
28
|
}
|
|
34
|
-
describe(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
29
|
+
describe("plan_read 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-read-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("execute", () => {
|
|
47
|
+
it("should return exists: false when no plan exists", async () => {
|
|
48
|
+
const tool = createPlanReadTool(async () => planService);
|
|
49
|
+
const sessionId = "test-session";
|
|
50
|
+
const result = await tool.execute({}, createToolContext(logger, { sessionId }));
|
|
51
|
+
expect(result.exists).toBe(false);
|
|
52
|
+
expect(result.message).toContain("No plan found");
|
|
44
53
|
});
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
54
|
+
it("should return plan content and metadata when plan exists", async () => {
|
|
55
|
+
const tool = createPlanReadTool(async () => planService);
|
|
56
|
+
const sessionId = "test-session";
|
|
57
|
+
const content = "# My Plan\n\nSome content";
|
|
58
|
+
const title = "My Plan Title";
|
|
59
|
+
await planService.create(sessionId, content, { title });
|
|
60
|
+
const result = await tool.execute({}, createToolContext(logger, { sessionId }));
|
|
61
|
+
expect(result.exists).toBe(true);
|
|
62
|
+
expect(result.content).toBe(content);
|
|
63
|
+
expect(result.status).toBe("draft");
|
|
64
|
+
expect(result.title).toBe(title);
|
|
65
|
+
expect(result.path).toBe(path.join(tempDir, sessionId, "plan.md"));
|
|
52
66
|
});
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
});
|
|
61
|
-
it('should return plan content and metadata when plan exists', async () => {
|
|
62
|
-
const tool = createPlanReadTool(async () => planService);
|
|
63
|
-
const sessionId = 'test-session';
|
|
64
|
-
const content = '# My Plan\n\nSome content';
|
|
65
|
-
const title = 'My Plan Title';
|
|
66
|
-
await planService.create(sessionId, content, { title });
|
|
67
|
-
const result = (await tool.execute({}, createToolContext(logger, { sessionId })));
|
|
68
|
-
expect(result.exists).toBe(true);
|
|
69
|
-
expect(result.content).toBe(content);
|
|
70
|
-
expect(result.status).toBe('draft');
|
|
71
|
-
expect(result.title).toBe(title);
|
|
72
|
-
expect(result.path).toBe(path.join(tempDir, sessionId, 'plan.md'));
|
|
73
|
-
});
|
|
74
|
-
it('should return ISO timestamps', async () => {
|
|
75
|
-
const tool = createPlanReadTool(async () => planService);
|
|
76
|
-
const sessionId = 'test-session';
|
|
77
|
-
await planService.create(sessionId, '# Plan');
|
|
78
|
-
const result = (await tool.execute({}, createToolContext(logger, { sessionId })));
|
|
79
|
-
// Should be ISO format
|
|
80
|
-
expect(result.createdAt).toMatch(/^\d{4}-\d{2}-\d{2}T/);
|
|
81
|
-
expect(result.updatedAt).toMatch(/^\d{4}-\d{2}-\d{2}T/);
|
|
82
|
-
});
|
|
83
|
-
it('should throw error when sessionId is missing', async () => {
|
|
84
|
-
const tool = createPlanReadTool(async () => planService);
|
|
85
|
-
try {
|
|
86
|
-
await tool.execute({}, createToolContext(logger));
|
|
87
|
-
expect.fail('Should have thrown an error');
|
|
88
|
-
}
|
|
89
|
-
catch (error) {
|
|
90
|
-
expect(error).toBeInstanceOf(DextoRuntimeError);
|
|
91
|
-
expect(error.code).toBe(PlanErrorCode.SESSION_ID_REQUIRED);
|
|
92
|
-
}
|
|
93
|
-
});
|
|
67
|
+
it("should return ISO timestamps", async () => {
|
|
68
|
+
const tool = createPlanReadTool(async () => planService);
|
|
69
|
+
const sessionId = "test-session";
|
|
70
|
+
await planService.create(sessionId, "# Plan");
|
|
71
|
+
const result = await tool.execute({}, createToolContext(logger, { sessionId }));
|
|
72
|
+
expect(result.createdAt).toMatch(/^\d{4}-\d{2}-\d{2}T/);
|
|
73
|
+
expect(result.updatedAt).toMatch(/^\d{4}-\d{2}-\d{2}T/);
|
|
94
74
|
});
|
|
75
|
+
it("should throw error when sessionId is missing", async () => {
|
|
76
|
+
const tool = createPlanReadTool(async () => planService);
|
|
77
|
+
try {
|
|
78
|
+
await tool.execute({}, createToolContext(logger));
|
|
79
|
+
expect.fail("Should have thrown an error");
|
|
80
|
+
} catch (error) {
|
|
81
|
+
expect(error).toBeInstanceOf(DextoRuntimeError);
|
|
82
|
+
expect(error.code).toBe(PlanErrorCode.SESSION_ID_REQUIRED);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
});
|
|
95
86
|
});
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var plan_review_tool_exports = {};
|
|
20
|
+
__export(plan_review_tool_exports, {
|
|
21
|
+
createPlanReviewTool: () => createPlanReviewTool
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(plan_review_tool_exports);
|
|
24
|
+
var import_zod = require("zod");
|
|
25
|
+
var import_core = require("@dexto/core");
|
|
26
|
+
var import_errors = require("../errors.js");
|
|
27
|
+
const PlanReviewInputSchema = import_zod.z.object({
|
|
28
|
+
summary: import_zod.z.string().optional().describe("Brief summary of the plan for context (shown above the plan content)")
|
|
29
|
+
}).strict();
|
|
30
|
+
function createPlanReviewTool(getPlanService) {
|
|
31
|
+
return (0, import_core.defineTool)({
|
|
32
|
+
id: "plan_review",
|
|
33
|
+
description: "Request user review of the current plan. Shows the full plan content for review with options to approve, request changes, or reject. Use after creating or updating a plan to get user approval before implementation.",
|
|
34
|
+
inputSchema: PlanReviewInputSchema,
|
|
35
|
+
presentation: {
|
|
36
|
+
describeHeader: (input) => (0, import_core.createLocalToolCallHeader)({
|
|
37
|
+
title: "Review Plan",
|
|
38
|
+
...input.summary ? { argsText: (0, import_core.truncateForHeader)(input.summary, 140) } : {}
|
|
39
|
+
}),
|
|
40
|
+
/**
|
|
41
|
+
* Generate preview showing the plan content for review.
|
|
42
|
+
* The ApprovalPrompt component detects plan_review and shows custom options.
|
|
43
|
+
*/
|
|
44
|
+
preview: async (input, context) => {
|
|
45
|
+
const resolvedPlanService = await getPlanService(context);
|
|
46
|
+
const { summary } = input;
|
|
47
|
+
if (!context.sessionId) {
|
|
48
|
+
throw import_errors.PlanError.sessionIdRequired();
|
|
49
|
+
}
|
|
50
|
+
const plan = await resolvedPlanService.read(context.sessionId);
|
|
51
|
+
if (!plan) {
|
|
52
|
+
throw import_errors.PlanError.planNotFound(context.sessionId);
|
|
53
|
+
}
|
|
54
|
+
let displayContent = plan.content;
|
|
55
|
+
if (summary) {
|
|
56
|
+
displayContent = `## Summary
|
|
57
|
+
${summary}
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
${plan.content}`;
|
|
62
|
+
}
|
|
63
|
+
const lineCount = displayContent.split("\n").length;
|
|
64
|
+
const planPath = resolvedPlanService.getPlanPath(context.sessionId);
|
|
65
|
+
return {
|
|
66
|
+
type: "file",
|
|
67
|
+
title: "Review Plan",
|
|
68
|
+
path: planPath,
|
|
69
|
+
operation: "read",
|
|
70
|
+
// 'read' indicates this is for viewing, not creating/modifying
|
|
71
|
+
content: displayContent,
|
|
72
|
+
size: Buffer.byteLength(displayContent, "utf8"),
|
|
73
|
+
lineCount
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
async execute(_input, context) {
|
|
78
|
+
const resolvedPlanService = await getPlanService(context);
|
|
79
|
+
if (!context.sessionId) {
|
|
80
|
+
throw import_errors.PlanError.sessionIdRequired();
|
|
81
|
+
}
|
|
82
|
+
const plan = await resolvedPlanService.read(context.sessionId);
|
|
83
|
+
if (!plan) {
|
|
84
|
+
throw import_errors.PlanError.planNotFound(context.sessionId);
|
|
85
|
+
}
|
|
86
|
+
await resolvedPlanService.updateMeta(context.sessionId, { status: "approved" });
|
|
87
|
+
return {
|
|
88
|
+
approved: true,
|
|
89
|
+
message: "Plan approved. You may now proceed with implementation.",
|
|
90
|
+
planStatus: "approved"
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
96
|
+
0 && (module.exports = {
|
|
97
|
+
createPlanReviewTool
|
|
98
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plan-review-tool.d.ts","sourceRoot":"","sources":["../../src/tools/plan-review-tool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,IAAI,EAAyC,MAAM,aAAa,CAAC;AAC/E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAGnE,QAAA,MAAM,qBAAqB;;;;;;EAOd,CAAC;AAEd;;;;GAIG;AACH,wBAAgB,oBAAoB,CAChC,cAAc,EAAE,iBAAiB,GAClC,IAAI,CAAC,OAAO,qBAAqB,CAAC,
|
|
1
|
+
{"version":3,"file":"plan-review-tool.d.ts","sourceRoot":"","sources":["../../src/tools/plan-review-tool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,IAAI,EAAyC,MAAM,aAAa,CAAC;AAC/E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAGnE,QAAA,MAAM,qBAAqB;;;;;;EAOd,CAAC;AAEd;;;;GAIG;AACH,wBAAgB,oBAAoB,CAChC,cAAc,EAAE,iBAAiB,GAClC,IAAI,CAAC,OAAO,qBAAqB,CAAC,CA2EpC"}
|