@dexto/tools-plan 1.5.7
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/.dexto-plugin/plugin.json +7 -0
- package/LICENSE +44 -0
- package/dist/errors.d.ts +56 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +66 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +39 -0
- package/dist/plan-service.d.ts +77 -0
- package/dist/plan-service.d.ts.map +1 -0
- package/dist/plan-service.js +227 -0
- package/dist/plan-service.test.d.ts +7 -0
- package/dist/plan-service.test.d.ts.map +1 -0
- package/dist/plan-service.test.js +220 -0
- package/dist/tool-provider.d.ts +44 -0
- package/dist/tool-provider.d.ts.map +1 -0
- package/dist/tool-provider.js +81 -0
- package/dist/tool-provider.test.d.ts +7 -0
- package/dist/tool-provider.test.d.ts.map +1 -0
- package/dist/tool-provider.test.js +185 -0
- package/dist/tools/plan-create-tool.d.ts +13 -0
- package/dist/tools/plan-create-tool.d.ts.map +1 -0
- package/dist/tools/plan-create-tool.js +72 -0
- package/dist/tools/plan-create-tool.test.d.ts +7 -0
- package/dist/tools/plan-create-tool.test.d.ts.map +1 -0
- package/dist/tools/plan-create-tool.test.js +118 -0
- package/dist/tools/plan-read-tool.d.ts +13 -0
- package/dist/tools/plan-read-tool.d.ts.map +1 -0
- package/dist/tools/plan-read-tool.js +40 -0
- package/dist/tools/plan-read-tool.test.d.ts +7 -0
- package/dist/tools/plan-read-tool.test.d.ts.map +1 -0
- package/dist/tools/plan-read-tool.test.js +83 -0
- package/dist/tools/plan-review-tool.d.ts +22 -0
- package/dist/tools/plan-review-tool.d.ts.map +1 -0
- package/dist/tools/plan-review-tool.js +84 -0
- package/dist/tools/plan-update-tool.d.ts +13 -0
- package/dist/tools/plan-update-tool.d.ts.map +1 -0
- package/dist/tools/plan-update-tool.js +72 -0
- package/dist/tools/plan-update-tool.test.d.ts +7 -0
- package/dist/tools/plan-update-tool.test.d.ts.map +1 -0
- package/dist/tools/plan-update-tool.test.js +151 -0
- package/dist/types.d.ts +57 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +26 -0
- package/package.json +40 -0
- package/skills/plan/SKILL.md +102 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
Elastic License 2.0 (ELv2)
|
|
2
|
+
|
|
3
|
+
**Acceptance**
|
|
4
|
+
By using the software, you agree to all of the terms and conditions below.
|
|
5
|
+
|
|
6
|
+
**Copyright License**
|
|
7
|
+
The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations and conditions below
|
|
8
|
+
|
|
9
|
+
**Limitations**
|
|
10
|
+
You may not provide the software to third parties as a hosted or managed service, where the service provides users with access to any substantial set of the features or functionality of the software.
|
|
11
|
+
|
|
12
|
+
You may not move, change, disable, or circumvent the license key functionality in the software, and you may not remove or obscure any functionality in the software that is protected by the license key.
|
|
13
|
+
|
|
14
|
+
You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law.
|
|
15
|
+
|
|
16
|
+
**Patents**
|
|
17
|
+
The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
|
|
18
|
+
|
|
19
|
+
**Notices**
|
|
20
|
+
You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms.
|
|
21
|
+
|
|
22
|
+
If you modify the software, you must include in any modified copies of the software prominent notices stating that you have modified the software.
|
|
23
|
+
|
|
24
|
+
**No Other Rights**
|
|
25
|
+
These terms do not imply any licenses other than those expressly granted in these terms.
|
|
26
|
+
|
|
27
|
+
**Termination**
|
|
28
|
+
If you use the software in violation of these terms, such use is not licensed, and your licenses will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your licenses will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your licenses to terminate automatically and permanently.
|
|
29
|
+
|
|
30
|
+
**No Liability**
|
|
31
|
+
As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.
|
|
32
|
+
|
|
33
|
+
**Definitions**
|
|
34
|
+
The _licensor_ is the entity offering these terms, and the _software_ is the software the licensor makes available under these terms, including any portion of it.
|
|
35
|
+
|
|
36
|
+
_you_ refers to the individual or entity agreeing to these terms.
|
|
37
|
+
|
|
38
|
+
_your company_ is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. _control_ means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
|
|
39
|
+
|
|
40
|
+
_your licenses_ are all the licenses granted to you for the software under these terms.
|
|
41
|
+
|
|
42
|
+
_use_ means anything you do with the software requiring one of your licenses.
|
|
43
|
+
|
|
44
|
+
_trademark_ means trademarks, service marks, and similar rights.
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plan Error Factory
|
|
3
|
+
*
|
|
4
|
+
* Provides typed errors for plan operations following the DextoRuntimeError pattern.
|
|
5
|
+
*/
|
|
6
|
+
import { DextoRuntimeError } from '@dexto/core';
|
|
7
|
+
/**
|
|
8
|
+
* Error codes for plan operations
|
|
9
|
+
*/
|
|
10
|
+
export declare const PlanErrorCode: {
|
|
11
|
+
/** Plan already exists for session */
|
|
12
|
+
readonly PLAN_ALREADY_EXISTS: "PLAN_ALREADY_EXISTS";
|
|
13
|
+
/** Plan not found for session */
|
|
14
|
+
readonly PLAN_NOT_FOUND: "PLAN_NOT_FOUND";
|
|
15
|
+
/** Invalid plan content */
|
|
16
|
+
readonly INVALID_PLAN_CONTENT: "INVALID_PLAN_CONTENT";
|
|
17
|
+
/** Session ID required */
|
|
18
|
+
readonly SESSION_ID_REQUIRED: "SESSION_ID_REQUIRED";
|
|
19
|
+
/** Invalid session ID (path traversal attempt) */
|
|
20
|
+
readonly INVALID_SESSION_ID: "INVALID_SESSION_ID";
|
|
21
|
+
/** Checkpoint not found */
|
|
22
|
+
readonly CHECKPOINT_NOT_FOUND: "CHECKPOINT_NOT_FOUND";
|
|
23
|
+
/** Storage operation failed */
|
|
24
|
+
readonly STORAGE_ERROR: "STORAGE_ERROR";
|
|
25
|
+
};
|
|
26
|
+
export type PlanErrorCodeType = (typeof PlanErrorCode)[keyof typeof PlanErrorCode];
|
|
27
|
+
/**
|
|
28
|
+
* Error factory for plan operations
|
|
29
|
+
*/
|
|
30
|
+
export declare const PlanError: {
|
|
31
|
+
/**
|
|
32
|
+
* Plan already exists for the given session
|
|
33
|
+
*/
|
|
34
|
+
planAlreadyExists(sessionId: string): DextoRuntimeError;
|
|
35
|
+
/**
|
|
36
|
+
* Plan not found for the given session
|
|
37
|
+
*/
|
|
38
|
+
planNotFound(sessionId: string): DextoRuntimeError;
|
|
39
|
+
/**
|
|
40
|
+
* Session ID is required for plan operations
|
|
41
|
+
*/
|
|
42
|
+
sessionIdRequired(): DextoRuntimeError;
|
|
43
|
+
/**
|
|
44
|
+
* Invalid session ID (path traversal attempt)
|
|
45
|
+
*/
|
|
46
|
+
invalidSessionId(sessionId: string): DextoRuntimeError;
|
|
47
|
+
/**
|
|
48
|
+
* Checkpoint not found in plan
|
|
49
|
+
*/
|
|
50
|
+
checkpointNotFound(checkpointId: string, sessionId: string): DextoRuntimeError;
|
|
51
|
+
/**
|
|
52
|
+
* Storage operation failed
|
|
53
|
+
*/
|
|
54
|
+
storageError(operation: string, sessionId: string, cause?: Error): DextoRuntimeError;
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,iBAAiB,EAAa,MAAM,aAAa,CAAC;AAE3D;;GAEG;AACH,eAAO,MAAM,aAAa;IACtB,sCAAsC;;IAEtC,iCAAiC;;IAEjC,2BAA2B;;IAE3B,0BAA0B;;IAE1B,kDAAkD;;IAElD,2BAA2B;;IAE3B,+BAA+B;;CAEzB,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,OAAO,aAAa,CAAC,CAAC;AAEnF;;GAEG;AACH,eAAO,MAAM,SAAS;IAClB;;OAEG;iCAC0B,MAAM,GAAG,iBAAiB;IAWvD;;OAEG;4BACqB,MAAM,GAAG,iBAAiB;IAWlD;;OAEG;yBACkB,iBAAiB;IAWtC;;OAEG;gCACyB,MAAM,GAAG,iBAAiB;IAWtD;;OAEG;qCAC8B,MAAM,aAAa,MAAM,GAAG,iBAAiB;IAW9E;;OAEG;4BACqB,MAAM,aAAa,MAAM,UAAU,KAAK,GAAG,iBAAiB;CAUvF,CAAC"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plan Error Factory
|
|
3
|
+
*
|
|
4
|
+
* Provides typed errors for plan operations following the DextoRuntimeError pattern.
|
|
5
|
+
*/
|
|
6
|
+
import { DextoRuntimeError, ErrorType } from '@dexto/core';
|
|
7
|
+
/**
|
|
8
|
+
* Error codes for plan operations
|
|
9
|
+
*/
|
|
10
|
+
export const PlanErrorCode = {
|
|
11
|
+
/** Plan already exists for session */
|
|
12
|
+
PLAN_ALREADY_EXISTS: 'PLAN_ALREADY_EXISTS',
|
|
13
|
+
/** Plan not found for session */
|
|
14
|
+
PLAN_NOT_FOUND: 'PLAN_NOT_FOUND',
|
|
15
|
+
/** Invalid plan content */
|
|
16
|
+
INVALID_PLAN_CONTENT: 'INVALID_PLAN_CONTENT',
|
|
17
|
+
/** Session ID required */
|
|
18
|
+
SESSION_ID_REQUIRED: 'SESSION_ID_REQUIRED',
|
|
19
|
+
/** Invalid session ID (path traversal attempt) */
|
|
20
|
+
INVALID_SESSION_ID: 'INVALID_SESSION_ID',
|
|
21
|
+
/** Checkpoint not found */
|
|
22
|
+
CHECKPOINT_NOT_FOUND: 'CHECKPOINT_NOT_FOUND',
|
|
23
|
+
/** Storage operation failed */
|
|
24
|
+
STORAGE_ERROR: 'STORAGE_ERROR',
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Error factory for plan operations
|
|
28
|
+
*/
|
|
29
|
+
export const PlanError = {
|
|
30
|
+
/**
|
|
31
|
+
* Plan already exists for the given session
|
|
32
|
+
*/
|
|
33
|
+
planAlreadyExists(sessionId) {
|
|
34
|
+
return new DextoRuntimeError(PlanErrorCode.PLAN_ALREADY_EXISTS, 'plan', ErrorType.USER, `A plan already exists for session '${sessionId}'. Use plan_update to modify it.`, { sessionId }, 'Use plan_update to modify the existing plan, or plan_read to view it.');
|
|
35
|
+
},
|
|
36
|
+
/**
|
|
37
|
+
* Plan not found for the given session
|
|
38
|
+
*/
|
|
39
|
+
planNotFound(sessionId) {
|
|
40
|
+
return new DextoRuntimeError(PlanErrorCode.PLAN_NOT_FOUND, 'plan', ErrorType.NOT_FOUND, `No plan found for session '${sessionId}'.`, { sessionId }, 'Use plan_create to create a new plan for this session.');
|
|
41
|
+
},
|
|
42
|
+
/**
|
|
43
|
+
* Session ID is required for plan operations
|
|
44
|
+
*/
|
|
45
|
+
sessionIdRequired() {
|
|
46
|
+
return new DextoRuntimeError(PlanErrorCode.SESSION_ID_REQUIRED, 'plan', ErrorType.USER, 'Session ID is required for plan operations.', {}, 'Ensure the tool is called within a valid session context.');
|
|
47
|
+
},
|
|
48
|
+
/**
|
|
49
|
+
* Invalid session ID (path traversal attempt)
|
|
50
|
+
*/
|
|
51
|
+
invalidSessionId(sessionId) {
|
|
52
|
+
return new DextoRuntimeError(PlanErrorCode.INVALID_SESSION_ID, 'plan', ErrorType.USER, `Invalid session ID: '${sessionId}' contains invalid path characters.`, { sessionId }, 'Session IDs must not contain path traversal characters like "..".');
|
|
53
|
+
},
|
|
54
|
+
/**
|
|
55
|
+
* Checkpoint not found in plan
|
|
56
|
+
*/
|
|
57
|
+
checkpointNotFound(checkpointId, sessionId) {
|
|
58
|
+
return new DextoRuntimeError(PlanErrorCode.CHECKPOINT_NOT_FOUND, 'plan', ErrorType.NOT_FOUND, `Checkpoint '${checkpointId}' not found in plan for session '${sessionId}'.`, { checkpointId, sessionId }, 'Use plan_read to view available checkpoints.');
|
|
59
|
+
},
|
|
60
|
+
/**
|
|
61
|
+
* Storage operation failed
|
|
62
|
+
*/
|
|
63
|
+
storageError(operation, sessionId, cause) {
|
|
64
|
+
return new DextoRuntimeError(PlanErrorCode.STORAGE_ERROR, 'plan', ErrorType.SYSTEM, `Failed to ${operation} plan for session '${sessionId}': ${cause?.message || 'unknown error'}`, { operation, sessionId, cause: cause?.message }, 'Check file system permissions and try again.');
|
|
65
|
+
},
|
|
66
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @dexto/tools-plan
|
|
3
|
+
*
|
|
4
|
+
* Implementation planning tools with session-linked plans.
|
|
5
|
+
* Provides tools for creating, reading, updating, and tracking plans.
|
|
6
|
+
*
|
|
7
|
+
* This package is a Dexto plugin that automatically registers:
|
|
8
|
+
* - Custom tool provider: plan-tools
|
|
9
|
+
* - Skill: plan (planning mode instructions)
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
* 1. Install the package
|
|
13
|
+
* 2. The plugin discovery will find .dexto-plugin/plugin.json
|
|
14
|
+
* 3. Tools and skill are automatically registered
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Path to the plugin directory containing .dexto-plugin manifest.
|
|
18
|
+
* Use this in image definitions to declare bundled plugins.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* import { PLUGIN_PATH } from '@dexto/tools-plan';
|
|
23
|
+
*
|
|
24
|
+
* export default defineImage({
|
|
25
|
+
* bundledPlugins: [PLUGIN_PATH],
|
|
26
|
+
* // ...
|
|
27
|
+
* });
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare const PLUGIN_PATH: string;
|
|
31
|
+
export { planToolsProvider } from './tool-provider.js';
|
|
32
|
+
export { PlanService } from './plan-service.js';
|
|
33
|
+
export type { Plan, PlanMeta, PlanStatus, PlanServiceOptions, PlanUpdateResult } from './types.js';
|
|
34
|
+
export { PlanError, PlanErrorCode, type PlanErrorCodeType } from './errors.js';
|
|
35
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAOH;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,WAAW,QAAgC,CAAC;AAGzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAGvD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhD,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAGnG,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @dexto/tools-plan
|
|
3
|
+
*
|
|
4
|
+
* Implementation planning tools with session-linked plans.
|
|
5
|
+
* Provides tools for creating, reading, updating, and tracking plans.
|
|
6
|
+
*
|
|
7
|
+
* This package is a Dexto plugin that automatically registers:
|
|
8
|
+
* - Custom tool provider: plan-tools
|
|
9
|
+
* - Skill: plan (planning mode instructions)
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
* 1. Install the package
|
|
13
|
+
* 2. The plugin discovery will find .dexto-plugin/plugin.json
|
|
14
|
+
* 3. Tools and skill are automatically registered
|
|
15
|
+
*/
|
|
16
|
+
import * as path from 'node:path';
|
|
17
|
+
import { fileURLToPath } from 'node:url';
|
|
18
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
19
|
+
/**
|
|
20
|
+
* Path to the plugin directory containing .dexto-plugin manifest.
|
|
21
|
+
* Use this in image definitions to declare bundled plugins.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* import { PLUGIN_PATH } from '@dexto/tools-plan';
|
|
26
|
+
*
|
|
27
|
+
* export default defineImage({
|
|
28
|
+
* bundledPlugins: [PLUGIN_PATH],
|
|
29
|
+
* // ...
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export const PLUGIN_PATH = path.resolve(__dirname, '..');
|
|
34
|
+
// Tool provider (for direct registration if needed)
|
|
35
|
+
export { planToolsProvider } from './tool-provider.js';
|
|
36
|
+
// Service (for advanced use cases)
|
|
37
|
+
export { PlanService } from './plan-service.js';
|
|
38
|
+
// Error utilities
|
|
39
|
+
export { PlanError, PlanErrorCode } from './errors.js';
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plan Service
|
|
3
|
+
*
|
|
4
|
+
* Handles storage and retrieval of implementation plans.
|
|
5
|
+
* Plans are stored in .dexto/plans/{sessionId}/ with:
|
|
6
|
+
* - plan.md: The plan content
|
|
7
|
+
* - plan-meta.json: Metadata (status, checkpoints, timestamps)
|
|
8
|
+
*/
|
|
9
|
+
import type { IDextoLogger } from '@dexto/core';
|
|
10
|
+
import type { Plan, PlanMeta, PlanServiceOptions, PlanUpdateResult } from './types.js';
|
|
11
|
+
/**
|
|
12
|
+
* Service for managing implementation plans.
|
|
13
|
+
*/
|
|
14
|
+
export declare class PlanService {
|
|
15
|
+
private basePath;
|
|
16
|
+
private logger;
|
|
17
|
+
constructor(options: PlanServiceOptions, logger?: IDextoLogger);
|
|
18
|
+
/**
|
|
19
|
+
* Resolves and validates a session directory path.
|
|
20
|
+
* Prevents path traversal attacks by ensuring the resolved path stays within basePath.
|
|
21
|
+
*/
|
|
22
|
+
private resolveSessionDir;
|
|
23
|
+
/**
|
|
24
|
+
* Gets the directory path for a session's plan
|
|
25
|
+
*/
|
|
26
|
+
private getPlanDir;
|
|
27
|
+
/**
|
|
28
|
+
* Gets the path to the plan content file.
|
|
29
|
+
* Public accessor for tools that need to display the path.
|
|
30
|
+
*/
|
|
31
|
+
getPlanPath(sessionId: string): string;
|
|
32
|
+
/**
|
|
33
|
+
* Gets the path to the plan metadata file
|
|
34
|
+
*/
|
|
35
|
+
private getMetaPath;
|
|
36
|
+
/**
|
|
37
|
+
* Checks if a plan exists for the given session
|
|
38
|
+
*/
|
|
39
|
+
exists(sessionId: string): Promise<boolean>;
|
|
40
|
+
/**
|
|
41
|
+
* Creates a new plan for the session
|
|
42
|
+
*
|
|
43
|
+
* @throws PlanError.planAlreadyExists if plan already exists
|
|
44
|
+
* @throws PlanError.storageError on filesystem errors
|
|
45
|
+
*/
|
|
46
|
+
create(sessionId: string, content: string, options?: {
|
|
47
|
+
title?: string;
|
|
48
|
+
}): Promise<Plan>;
|
|
49
|
+
/**
|
|
50
|
+
* Reads the plan for the given session
|
|
51
|
+
*
|
|
52
|
+
* @returns The plan or null if not found
|
|
53
|
+
*/
|
|
54
|
+
read(sessionId: string): Promise<Plan | null>;
|
|
55
|
+
/**
|
|
56
|
+
* Updates the plan content for the given session
|
|
57
|
+
*
|
|
58
|
+
* @throws PlanError.planNotFound if plan doesn't exist
|
|
59
|
+
* @throws PlanError.storageError on filesystem errors
|
|
60
|
+
*/
|
|
61
|
+
update(sessionId: string, content: string): Promise<PlanUpdateResult>;
|
|
62
|
+
/**
|
|
63
|
+
* Updates the plan metadata (status, title)
|
|
64
|
+
*
|
|
65
|
+
* @throws PlanError.planNotFound if plan doesn't exist
|
|
66
|
+
* @throws PlanError.storageError on filesystem errors
|
|
67
|
+
*/
|
|
68
|
+
updateMeta(sessionId: string, updates: Partial<Pick<PlanMeta, 'status' | 'title'>>): Promise<PlanMeta>;
|
|
69
|
+
/**
|
|
70
|
+
* Deletes the plan for the given session
|
|
71
|
+
*
|
|
72
|
+
* @throws PlanError.planNotFound if plan doesn't exist
|
|
73
|
+
* @throws PlanError.storageError on filesystem errors
|
|
74
|
+
*/
|
|
75
|
+
delete(sessionId: string): Promise<void>;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=plan-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan-service.d.ts","sourceRoot":"","sources":["../src/plan-service.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAMvF;;GAEG;AACH,qBAAa,WAAW;IACpB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,MAAM,CAA2B;gBAE7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,CAAC,EAAE,YAAY;IAK9D;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IAWzB;;OAEG;IACH,OAAO,CAAC,UAAU;IAIlB;;;OAGG;IACI,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;IAI7C;;OAEG;IACH,OAAO,CAAC,WAAW;IAInB;;OAEG;IACG,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAKjD;;;;;OAKG;IACG,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAoC7F;;;;OAIG;IACG,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;IAmDnD;;;;;OAKG;IACG,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAqC3E;;;;;OAKG;IACG,UAAU,CACZ,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,CAAC,GACrD,OAAO,CAAC,QAAQ,CAAC;IA2BpB;;;;;OAKG;IACG,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAYjD"}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plan Service
|
|
3
|
+
*
|
|
4
|
+
* Handles storage and retrieval of implementation plans.
|
|
5
|
+
* Plans are stored in .dexto/plans/{sessionId}/ with:
|
|
6
|
+
* - plan.md: The plan content
|
|
7
|
+
* - plan-meta.json: Metadata (status, checkpoints, timestamps)
|
|
8
|
+
*/
|
|
9
|
+
import * as fs from 'node:fs/promises';
|
|
10
|
+
import * as path from 'node:path';
|
|
11
|
+
import { existsSync } from 'node:fs';
|
|
12
|
+
import { PlanMetaSchema } from './types.js';
|
|
13
|
+
import { PlanError } from './errors.js';
|
|
14
|
+
const PLAN_FILENAME = 'plan.md';
|
|
15
|
+
const META_FILENAME = 'plan-meta.json';
|
|
16
|
+
/**
|
|
17
|
+
* Service for managing implementation plans.
|
|
18
|
+
*/
|
|
19
|
+
export class PlanService {
|
|
20
|
+
basePath;
|
|
21
|
+
logger;
|
|
22
|
+
constructor(options, logger) {
|
|
23
|
+
this.basePath = options.basePath;
|
|
24
|
+
this.logger = logger;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Resolves and validates a session directory path.
|
|
28
|
+
* Prevents path traversal attacks by ensuring the resolved path stays within basePath.
|
|
29
|
+
*/
|
|
30
|
+
resolveSessionDir(sessionId) {
|
|
31
|
+
const base = path.resolve(this.basePath);
|
|
32
|
+
const resolved = path.resolve(base, sessionId);
|
|
33
|
+
const rel = path.relative(base, resolved);
|
|
34
|
+
// Check for path traversal (upward traversal)
|
|
35
|
+
if (rel.startsWith('..') || path.isAbsolute(rel)) {
|
|
36
|
+
throw PlanError.invalidSessionId(sessionId);
|
|
37
|
+
}
|
|
38
|
+
return resolved;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Gets the directory path for a session's plan
|
|
42
|
+
*/
|
|
43
|
+
getPlanDir(sessionId) {
|
|
44
|
+
return this.resolveSessionDir(sessionId);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Gets the path to the plan content file.
|
|
48
|
+
* Public accessor for tools that need to display the path.
|
|
49
|
+
*/
|
|
50
|
+
getPlanPath(sessionId) {
|
|
51
|
+
return path.join(this.getPlanDir(sessionId), PLAN_FILENAME);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Gets the path to the plan metadata file
|
|
55
|
+
*/
|
|
56
|
+
getMetaPath(sessionId) {
|
|
57
|
+
return path.join(this.getPlanDir(sessionId), META_FILENAME);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Checks if a plan exists for the given session
|
|
61
|
+
*/
|
|
62
|
+
async exists(sessionId) {
|
|
63
|
+
const planPath = this.getPlanPath(sessionId);
|
|
64
|
+
return existsSync(planPath);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Creates a new plan for the session
|
|
68
|
+
*
|
|
69
|
+
* @throws PlanError.planAlreadyExists if plan already exists
|
|
70
|
+
* @throws PlanError.storageError on filesystem errors
|
|
71
|
+
*/
|
|
72
|
+
async create(sessionId, content, options) {
|
|
73
|
+
// Check if plan already exists
|
|
74
|
+
if (await this.exists(sessionId)) {
|
|
75
|
+
throw PlanError.planAlreadyExists(sessionId);
|
|
76
|
+
}
|
|
77
|
+
const planDir = this.getPlanDir(sessionId);
|
|
78
|
+
const now = Date.now();
|
|
79
|
+
// Create metadata
|
|
80
|
+
const meta = {
|
|
81
|
+
sessionId,
|
|
82
|
+
status: 'draft',
|
|
83
|
+
title: options?.title,
|
|
84
|
+
createdAt: now,
|
|
85
|
+
updatedAt: now,
|
|
86
|
+
};
|
|
87
|
+
try {
|
|
88
|
+
// Ensure directory exists
|
|
89
|
+
await fs.mkdir(planDir, { recursive: true });
|
|
90
|
+
// Write plan content and metadata
|
|
91
|
+
await Promise.all([
|
|
92
|
+
fs.writeFile(this.getPlanPath(sessionId), content, 'utf-8'),
|
|
93
|
+
fs.writeFile(this.getMetaPath(sessionId), JSON.stringify(meta, null, 2), 'utf-8'),
|
|
94
|
+
]);
|
|
95
|
+
this.logger?.debug(`Created plan for session ${sessionId}`);
|
|
96
|
+
return { content, meta };
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
throw PlanError.storageError('create', sessionId, error);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Reads the plan for the given session
|
|
104
|
+
*
|
|
105
|
+
* @returns The plan or null if not found
|
|
106
|
+
*/
|
|
107
|
+
async read(sessionId) {
|
|
108
|
+
if (!(await this.exists(sessionId))) {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
const [content, metaContent] = await Promise.all([
|
|
113
|
+
fs.readFile(this.getPlanPath(sessionId), 'utf-8'),
|
|
114
|
+
fs.readFile(this.getMetaPath(sessionId), 'utf-8'),
|
|
115
|
+
]);
|
|
116
|
+
const metaParsed = JSON.parse(metaContent);
|
|
117
|
+
const metaResult = PlanMetaSchema.safeParse(metaParsed);
|
|
118
|
+
if (!metaResult.success) {
|
|
119
|
+
this.logger?.warn(`Invalid plan metadata for session ${sessionId}, using defaults`);
|
|
120
|
+
// Return with minimal metadata if parsing fails
|
|
121
|
+
return {
|
|
122
|
+
content,
|
|
123
|
+
meta: {
|
|
124
|
+
sessionId,
|
|
125
|
+
status: 'draft',
|
|
126
|
+
createdAt: Date.now(),
|
|
127
|
+
updatedAt: Date.now(),
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
return { content, meta: metaResult.data };
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
const err = error;
|
|
135
|
+
// ENOENT means file doesn't exist - return null (expected case)
|
|
136
|
+
if (err.code === 'ENOENT') {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
// JSON parse errors (SyntaxError) mean corrupted data - treat as not found
|
|
140
|
+
// but log for debugging
|
|
141
|
+
if (error instanceof SyntaxError) {
|
|
142
|
+
this.logger?.error(`Failed to read plan for session ${sessionId}: ${error.message}`);
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
// For real I/O errors (permission denied, disk issues), throw to surface the issue
|
|
146
|
+
this.logger?.error(`Failed to read plan for session ${sessionId}: ${err.message ?? String(err)}`);
|
|
147
|
+
throw PlanError.storageError('read', sessionId, err);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Updates the plan content for the given session
|
|
152
|
+
*
|
|
153
|
+
* @throws PlanError.planNotFound if plan doesn't exist
|
|
154
|
+
* @throws PlanError.storageError on filesystem errors
|
|
155
|
+
*/
|
|
156
|
+
async update(sessionId, content) {
|
|
157
|
+
const existing = await this.read(sessionId);
|
|
158
|
+
if (!existing) {
|
|
159
|
+
throw PlanError.planNotFound(sessionId);
|
|
160
|
+
}
|
|
161
|
+
const oldContent = existing.content;
|
|
162
|
+
const now = Date.now();
|
|
163
|
+
// Update metadata
|
|
164
|
+
const updatedMeta = {
|
|
165
|
+
...existing.meta,
|
|
166
|
+
updatedAt: now,
|
|
167
|
+
};
|
|
168
|
+
try {
|
|
169
|
+
await Promise.all([
|
|
170
|
+
fs.writeFile(this.getPlanPath(sessionId), content, 'utf-8'),
|
|
171
|
+
fs.writeFile(this.getMetaPath(sessionId), JSON.stringify(updatedMeta, null, 2), 'utf-8'),
|
|
172
|
+
]);
|
|
173
|
+
this.logger?.debug(`Updated plan for session ${sessionId}`);
|
|
174
|
+
return {
|
|
175
|
+
oldContent,
|
|
176
|
+
newContent: content,
|
|
177
|
+
meta: updatedMeta,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
throw PlanError.storageError('update', sessionId, error);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Updates the plan metadata (status, title)
|
|
186
|
+
*
|
|
187
|
+
* @throws PlanError.planNotFound if plan doesn't exist
|
|
188
|
+
* @throws PlanError.storageError on filesystem errors
|
|
189
|
+
*/
|
|
190
|
+
async updateMeta(sessionId, updates) {
|
|
191
|
+
const existing = await this.read(sessionId);
|
|
192
|
+
if (!existing) {
|
|
193
|
+
throw PlanError.planNotFound(sessionId);
|
|
194
|
+
}
|
|
195
|
+
const updatedMeta = {
|
|
196
|
+
...existing.meta,
|
|
197
|
+
...updates,
|
|
198
|
+
updatedAt: Date.now(),
|
|
199
|
+
};
|
|
200
|
+
try {
|
|
201
|
+
await fs.writeFile(this.getMetaPath(sessionId), JSON.stringify(updatedMeta, null, 2), 'utf-8');
|
|
202
|
+
this.logger?.debug(`Updated plan metadata for session ${sessionId}`);
|
|
203
|
+
return updatedMeta;
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
throw PlanError.storageError('update metadata', sessionId, error);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Deletes the plan for the given session
|
|
211
|
+
*
|
|
212
|
+
* @throws PlanError.planNotFound if plan doesn't exist
|
|
213
|
+
* @throws PlanError.storageError on filesystem errors
|
|
214
|
+
*/
|
|
215
|
+
async delete(sessionId) {
|
|
216
|
+
if (!(await this.exists(sessionId))) {
|
|
217
|
+
throw PlanError.planNotFound(sessionId);
|
|
218
|
+
}
|
|
219
|
+
try {
|
|
220
|
+
await fs.rm(this.getPlanDir(sessionId), { recursive: true, force: true });
|
|
221
|
+
this.logger?.debug(`Deleted plan for session ${sessionId}`);
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
throw PlanError.storageError('delete', sessionId, error);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan-service.test.d.ts","sourceRoot":"","sources":["../src/plan-service.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|