@agent-facets/viper-plans-mcp 1.3.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Julian Coy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,93 @@
1
+ # VIPER Plans
2
+
3
+ VIPER planning and execution for AI coding agents, shipped two ways:
4
+
5
+ - **`viper-plans`** — a [facet](https://agentfacets.io) with the VIPER skills and commands.
6
+ - **`@agent-facets/viper-plans-mcp`** — the MCP server that stores the plans those commands write.
7
+
8
+ ## The MCP server
9
+
10
+ `@agent-facets/viper-plans-mcp` is a stdio MCP server that owns plan storage under
11
+ `<workspace>/.opencode/plans/<plan>/<artifact>.md`. It requires **Node 20 or newer** and is launched
12
+ on demand with `npx`, so nothing is installed into your project.
13
+
14
+ ```jsonc
15
+ {
16
+ "mcp": {
17
+ "viper-plans": {
18
+ "type": "local",
19
+ "command": ["npx", "-y", "@agent-facets/viper-plans-mcp@1.3.0"]
20
+ }
21
+ }
22
+ }
23
+ ```
24
+
25
+ Installing the `viper-plans` facet writes that configuration for you:
26
+
27
+ ```sh
28
+ facet add viper-plans --accept-mcp
29
+ ```
30
+
31
+ ### Tools
32
+
33
+ | Tool | Arguments | Result |
34
+ |---------------------|--------------------------------------------------------------|-----------------------------------|
35
+ | `viper-write-plan` | `plan`, `artifact?`, `content` | Creates or replaces an artifact |
36
+ | `viper-read-plan` | `plan`, `artifact?` | Returns the artifact's content |
37
+ | `viper-edit-plan` | `plan`, `artifact?`, `oldString`, `newString`, `replaceAll?` | Exact-string replacement in place |
38
+ | `viper-list-plans` | — | Every plan and its artifacts |
39
+ | `viper-delete-plan` | `plan` | Deletes a plan directory |
40
+
41
+ `artifact` defaults to `plan`, and one trailing `.md` is stripped from it. Plan and artifact names
42
+ must match `^[A-Za-z0-9][A-Za-z0-9_-]*$`.
43
+
44
+ Every tool answers with human-readable text and a validated structured result. Failures are ordinary
45
+ results carrying `success: false` and a specific `reason`, so a model can read and recover from them.
46
+
47
+ ### Storage and safety
48
+
49
+ - The workspace root is the server process's working directory, which is the project directory the
50
+ host launched it from. Plans always resolve beneath `<workspace>/.opencode/plans/`.
51
+ - Paths are containment-checked after symlink resolution; nothing outside the workspace is read,
52
+ written, or deleted.
53
+ - Writes are atomic — a uniquely named sibling temporary file is renamed over the target.
54
+ - `viper-edit-plan` refuses to edit an artifact this server has not read or written, and refuses
55
+ again if the content changed since then.
56
+
57
+ ## The facet
58
+
59
+ The facet ships the `viper-planning` and `viper-execution-rules` skills plus the `viper-plan`,
60
+ `viper-run`, and `viper-continue` commands. The commands prefer the MCP tools above and fall back to
61
+ ordinary file operations when they are unavailable, so the facet works with or without the server.
62
+
63
+ ## Development
64
+
65
+ ```sh
66
+ mise exec -- bun install
67
+ mise exec -- bun run format
68
+ mise exec -- bun check
69
+ ```
70
+
71
+ `facet build --verify` validates the facet itself.
72
+
73
+ ## Releasing
74
+
75
+ `package.json` holds the one version everything else is checked against — the facet, the version its
76
+ server declaration launches, and the README example — by `bun run check:version`.
77
+
78
+ Publishing a GitHub Release tagged `v<version>` runs `.github/workflows/publish.yml`, which reruns
79
+ every check, packs one tarball, prints its contents, and publishes that exact file. npm authenticates
80
+ the workflow through OIDC trusted publishing and attaches a provenance attestation, so no npm token
81
+ exists anywhere in the repository.
82
+
83
+ Trusted publishing cannot mint the first version of a package, so `1.3.0` was published by hand from
84
+ a verified tarball. The npm trusted publisher is configured for organization `agent-facets`,
85
+ repository `viper-plans`, workflow `publish.yml`, allowing `npm publish`; every release after the
86
+ bootstrap goes through it.
87
+
88
+ Publishing the facet is separate: `facet build` then `facet publish`, from a merged commit whose
89
+ declared package version is already on npm.
90
+
91
+ ## License
92
+
93
+ MIT
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Replace a file's contents in one step: write a sibling temporary file, then
3
+ * rename it over the target. A reader either sees the previous content or the
4
+ * new content, never a partial write.
5
+ *
6
+ * The temporary name carries the pid and random bytes because two writers
7
+ * sharing one predictable temp path corrupt each other's output.
8
+ */
9
+ export declare function atomicWriteFile(path: string, data: string): Promise<void>;
@@ -0,0 +1,23 @@
1
+ import { randomBytes } from 'node:crypto';
2
+ import { rename, unlink, writeFile } from 'node:fs/promises';
3
+ import { basename, dirname, join } from 'node:path';
4
+ /**
5
+ * Replace a file's contents in one step: write a sibling temporary file, then
6
+ * rename it over the target. A reader either sees the previous content or the
7
+ * new content, never a partial write.
8
+ *
9
+ * The temporary name carries the pid and random bytes because two writers
10
+ * sharing one predictable temp path corrupt each other's output.
11
+ */
12
+ export async function atomicWriteFile(path, data) {
13
+ const temporary = join(dirname(path), `.${basename(path)}.${process.pid}.${randomBytes(6).toString('hex')}.tmp`);
14
+ try {
15
+ await writeFile(temporary, data, 'utf8');
16
+ await rename(temporary, path);
17
+ }
18
+ catch (error) {
19
+ await unlink(temporary).catch(() => undefined);
20
+ throw error;
21
+ }
22
+ }
23
+ //# sourceMappingURL=atomic-write.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"atomic-write.js","sourceRoot":"","sources":["../src/atomic-write.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC5D,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEnD;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,IAAY,EAAE,IAAY;IAC9D,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,GAAG,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;IAChH,IAAI,CAAC;QACH,MAAM,SAAS,CAAC,SAAS,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;QACxC,MAAM,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,CAAA;IAC/B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,MAAM,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA;QAC9C,MAAM,KAAK,CAAA;IACb,CAAC;AACH,CAAC"}
@@ -0,0 +1,221 @@
1
+ /**
2
+ * The name grammar shared by plans and artifacts, inherited verbatim from the
3
+ * OpenCode-native VIPER tools this server replaces. It is what makes a name
4
+ * safe to join onto a path: `.`, `..`, `/`, and `\` cannot appear in it.
5
+ */
6
+ export declare const NAME_PATTERN: RegExp;
7
+ /** Artifact used when a caller does not name one. */
8
+ export declare const DEFAULT_ARTIFACT = "plan";
9
+ /** Extension every artifact carries on disk. */
10
+ export declare const ARTIFACT_EXTENSION = ".md";
11
+ /** Workspace-relative directory that holds every plan. */
12
+ export declare const PLANS_DIRECTORY: readonly ['.opencode', 'plans'];
13
+ export declare const TOOL_NAMES: {
14
+ readonly write: 'viper-write-plan';
15
+ readonly read: 'viper-read-plan';
16
+ readonly edit: 'viper-edit-plan';
17
+ readonly list: 'viper-list-plans';
18
+ readonly delete: 'viper-delete-plan';
19
+ };
20
+ export declare function isValidName(value: string): boolean;
21
+ /**
22
+ * Resolve the artifact a caller asked for: the default when absent, with one
23
+ * trailing `.md` removed so `plan` and `plan.md` address the same file. Read,
24
+ * write, and edit all normalize through here, which the native tools did not —
25
+ * their read path rejected `plan.md` that their write path accepted.
26
+ */
27
+ export declare function normalizeArtifact(artifact: string | undefined): string;
28
+ export declare const WritePlanInput: import("arktype/internal/variants/object.ts").ObjectType<{
29
+ plan: string;
30
+ artifact?: string;
31
+ content: string;
32
+ }, {}>;
33
+ export declare const ReadPlanInput: import("arktype/internal/variants/object.ts").ObjectType<{
34
+ plan: string;
35
+ artifact?: string;
36
+ }, {}>;
37
+ export declare const EditPlanInput: import("arktype/internal/variants/object.ts").ObjectType<{
38
+ plan: string;
39
+ artifact?: string;
40
+ oldString: string;
41
+ newString: string;
42
+ replaceAll?: boolean;
43
+ }, {}>;
44
+ export declare const ListPlansInput: import("arktype/internal/variants/object.ts").ObjectType<object, {}>;
45
+ export declare const DeletePlanInput: import("arktype/internal/variants/object.ts").ObjectType<{
46
+ plan: string;
47
+ }, {}>;
48
+ export declare const WritePlanOutput: import("arktype/internal/variants/object.ts").ObjectType<{
49
+ success: false;
50
+ reason: "invalid_name";
51
+ name: string;
52
+ message: string;
53
+ } | {
54
+ success: false;
55
+ reason: "invalid_artifact";
56
+ artifact: string;
57
+ message: string;
58
+ } | {
59
+ success: false;
60
+ reason: "empty_content";
61
+ message: string;
62
+ } | {
63
+ success: false;
64
+ reason: "unsafe_path";
65
+ path: string;
66
+ message: string;
67
+ } | {
68
+ success: false;
69
+ reason: "io_error";
70
+ operation: string;
71
+ message: string;
72
+ } | {
73
+ success: true;
74
+ plan: string;
75
+ artifact: string;
76
+ path: string;
77
+ }, {}>;
78
+ export declare const ReadPlanOutput: import("arktype/internal/variants/object.ts").ObjectType<{
79
+ success: false;
80
+ reason: "invalid_name";
81
+ name: string;
82
+ message: string;
83
+ } | {
84
+ success: false;
85
+ reason: "invalid_artifact";
86
+ artifact: string;
87
+ message: string;
88
+ } | {
89
+ success: false;
90
+ reason: "not_found";
91
+ plan: string;
92
+ artifact: string;
93
+ message: string;
94
+ } | {
95
+ success: false;
96
+ reason: "unsafe_path";
97
+ path: string;
98
+ message: string;
99
+ } | {
100
+ success: false;
101
+ reason: "io_error";
102
+ operation: string;
103
+ message: string;
104
+ } | {
105
+ success: true;
106
+ plan: string;
107
+ artifact: string;
108
+ path: string;
109
+ content: string;
110
+ }, {}>;
111
+ export declare const EditPlanOutput: import("arktype/internal/variants/object.ts").ObjectType<{
112
+ success: false;
113
+ reason: "invalid_name";
114
+ name: string;
115
+ message: string;
116
+ } | {
117
+ success: false;
118
+ reason: "invalid_artifact";
119
+ artifact: string;
120
+ message: string;
121
+ } | {
122
+ success: false;
123
+ reason: "not_found";
124
+ plan: string;
125
+ artifact: string;
126
+ message: string;
127
+ } | {
128
+ success: false;
129
+ reason: "unsafe_path";
130
+ path: string;
131
+ message: string;
132
+ } | {
133
+ success: false;
134
+ reason: "must_read_first";
135
+ plan: string;
136
+ artifact: string;
137
+ message: string;
138
+ } | {
139
+ success: false;
140
+ reason: "stale_read";
141
+ plan: string;
142
+ artifact: string;
143
+ message: string;
144
+ } | {
145
+ success: false;
146
+ reason: "no_change";
147
+ plan: string;
148
+ artifact: string;
149
+ message: string;
150
+ } | {
151
+ success: false;
152
+ reason: "old_string_not_found";
153
+ plan: string;
154
+ artifact: string;
155
+ message: string;
156
+ } | {
157
+ success: false;
158
+ reason: "ambiguous_match";
159
+ plan: string;
160
+ artifact: string;
161
+ count: number;
162
+ message: string;
163
+ } | {
164
+ success: false;
165
+ reason: "io_error";
166
+ operation: string;
167
+ message: string;
168
+ } | {
169
+ success: true;
170
+ plan: string;
171
+ artifact: string;
172
+ path: string;
173
+ replacements: number;
174
+ }, {}>;
175
+ export declare const ListPlansOutput: import("arktype/internal/variants/object.ts").ObjectType<{
176
+ success: false;
177
+ reason: "io_error";
178
+ operation: string;
179
+ message: string;
180
+ } | {
181
+ success: true;
182
+ plans: {
183
+ name: string;
184
+ artifacts: string[];
185
+ }[];
186
+ }, {}>;
187
+ export declare const DeletePlanOutput: import("arktype/internal/variants/object.ts").ObjectType<{
188
+ success: false;
189
+ reason: "invalid_name";
190
+ name: string;
191
+ message: string;
192
+ } | {
193
+ success: false;
194
+ reason: "plan_not_found";
195
+ plan: string;
196
+ message: string;
197
+ } | {
198
+ success: false;
199
+ reason: "unsafe_path";
200
+ path: string;
201
+ message: string;
202
+ } | {
203
+ success: false;
204
+ reason: "io_error";
205
+ operation: string;
206
+ message: string;
207
+ } | {
208
+ success: true;
209
+ plan: string;
210
+ path: string;
211
+ }, {}>;
212
+ export type WritePlanArgs = typeof WritePlanInput.infer;
213
+ export type ReadPlanArgs = typeof ReadPlanInput.infer;
214
+ export type EditPlanArgs = typeof EditPlanInput.infer;
215
+ export type DeletePlanArgs = typeof DeletePlanInput.infer;
216
+ export type WritePlanResult = typeof WritePlanOutput.infer;
217
+ export type ReadPlanResult = typeof ReadPlanOutput.infer;
218
+ export type EditPlanResult = typeof EditPlanOutput.infer;
219
+ export type ListPlansResult = typeof ListPlansOutput.infer;
220
+ export type DeletePlanResult = typeof DeletePlanOutput.infer;
221
+ export type PlanResult = WritePlanResult | ReadPlanResult | EditPlanResult | ListPlansResult | DeletePlanResult;
@@ -0,0 +1,191 @@
1
+ import { type } from 'arktype';
2
+ /**
3
+ * The name grammar shared by plans and artifacts, inherited verbatim from the
4
+ * OpenCode-native VIPER tools this server replaces. It is what makes a name
5
+ * safe to join onto a path: `.`, `..`, `/`, and `\` cannot appear in it.
6
+ */
7
+ export const NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
8
+ /** Artifact used when a caller does not name one. */
9
+ export const DEFAULT_ARTIFACT = 'plan';
10
+ /** Extension every artifact carries on disk. */
11
+ export const ARTIFACT_EXTENSION = '.md';
12
+ /** Workspace-relative directory that holds every plan. */
13
+ export const PLANS_DIRECTORY = ['.opencode', 'plans'];
14
+ export const TOOL_NAMES = {
15
+ write: 'viper-write-plan',
16
+ read: 'viper-read-plan',
17
+ edit: 'viper-edit-plan',
18
+ list: 'viper-list-plans',
19
+ delete: 'viper-delete-plan',
20
+ };
21
+ export function isValidName(value) {
22
+ return NAME_PATTERN.test(value);
23
+ }
24
+ /**
25
+ * Resolve the artifact a caller asked for: the default when absent, with one
26
+ * trailing `.md` removed so `plan` and `plan.md` address the same file. Read,
27
+ * write, and edit all normalize through here, which the native tools did not —
28
+ * their read path rejected `plan.md` that their write path accepted.
29
+ */
30
+ export function normalizeArtifact(artifact) {
31
+ const requested = artifact ?? DEFAULT_ARTIFACT;
32
+ return requested.endsWith(ARTIFACT_EXTENSION) ? requested.slice(0, -ARTIFACT_EXTENSION.length) : requested;
33
+ }
34
+ // ---------------------------------------------------------------------------
35
+ // Failure variants
36
+ // ---------------------------------------------------------------------------
37
+ const InvalidName = type({
38
+ success: 'false',
39
+ reason: "'invalid_name'",
40
+ name: 'string',
41
+ message: 'string',
42
+ });
43
+ const InvalidArtifact = type({
44
+ success: 'false',
45
+ reason: "'invalid_artifact'",
46
+ artifact: 'string',
47
+ message: 'string',
48
+ });
49
+ const EmptyContent = type({
50
+ success: 'false',
51
+ reason: "'empty_content'",
52
+ message: 'string',
53
+ });
54
+ const NotFound = type({
55
+ success: 'false',
56
+ reason: "'not_found'",
57
+ plan: 'string',
58
+ artifact: 'string',
59
+ message: 'string',
60
+ });
61
+ const PlanNotFound = type({
62
+ success: 'false',
63
+ reason: "'plan_not_found'",
64
+ plan: 'string',
65
+ message: 'string',
66
+ });
67
+ const UnsafePath = type({
68
+ success: 'false',
69
+ reason: "'unsafe_path'",
70
+ path: 'string',
71
+ message: 'string',
72
+ });
73
+ const MustReadFirst = type({
74
+ success: 'false',
75
+ reason: "'must_read_first'",
76
+ plan: 'string',
77
+ artifact: 'string',
78
+ message: 'string',
79
+ });
80
+ const StaleRead = type({
81
+ success: 'false',
82
+ reason: "'stale_read'",
83
+ plan: 'string',
84
+ artifact: 'string',
85
+ message: 'string',
86
+ });
87
+ const NoChange = type({
88
+ success: 'false',
89
+ reason: "'no_change'",
90
+ plan: 'string',
91
+ artifact: 'string',
92
+ message: 'string',
93
+ });
94
+ const OldStringNotFound = type({
95
+ success: 'false',
96
+ reason: "'old_string_not_found'",
97
+ plan: 'string',
98
+ artifact: 'string',
99
+ message: 'string',
100
+ });
101
+ const AmbiguousMatch = type({
102
+ success: 'false',
103
+ reason: "'ambiguous_match'",
104
+ plan: 'string',
105
+ artifact: 'string',
106
+ count: 'number.integer >= 2',
107
+ message: 'string',
108
+ });
109
+ const IoError = type({
110
+ success: 'false',
111
+ reason: "'io_error'",
112
+ operation: 'string',
113
+ message: 'string',
114
+ });
115
+ // ---------------------------------------------------------------------------
116
+ // Tool inputs
117
+ // ---------------------------------------------------------------------------
118
+ // Names are plain strings here on purpose. Rejecting a malformed name in the
119
+ // input schema would surface it as a protocol-level validation error; the
120
+ // handlers answer with an `invalid_name` result the model can act on instead.
121
+ export const WritePlanInput = type({
122
+ plan: type('string').describe('Plan name (letters, digits, hyphens, and underscores)'),
123
+ 'artifact?': type('string').describe('Artifact name; defaults to "plan"'),
124
+ content: type('string').describe('Full markdown content of the artifact'),
125
+ });
126
+ export const ReadPlanInput = type({
127
+ plan: type('string').describe('Plan name to read'),
128
+ 'artifact?': type('string').describe('Artifact name; defaults to "plan"'),
129
+ });
130
+ export const EditPlanInput = type({
131
+ plan: type('string').describe('Plan name to edit'),
132
+ 'artifact?': type('string').describe('Artifact name; defaults to "plan"'),
133
+ oldString: type('string').describe('Exact text to replace; include surrounding context to make it unique'),
134
+ newString: type('string').describe('Replacement text'),
135
+ 'replaceAll?': type('boolean').describe('Replace every occurrence instead of requiring a unique match'),
136
+ });
137
+ export const ListPlansInput = type({});
138
+ export const DeletePlanInput = type({
139
+ plan: type('string').describe('Plan name to delete, including all of its artifacts'),
140
+ });
141
+ // ---------------------------------------------------------------------------
142
+ // Tool outputs
143
+ // ---------------------------------------------------------------------------
144
+ const WriteSuccess = type({
145
+ success: 'true',
146
+ plan: 'string',
147
+ artifact: 'string',
148
+ path: 'string',
149
+ });
150
+ const ReadSuccess = type({
151
+ success: 'true',
152
+ plan: 'string',
153
+ artifact: 'string',
154
+ path: 'string',
155
+ content: 'string',
156
+ });
157
+ const EditSuccess = type({
158
+ success: 'true',
159
+ plan: 'string',
160
+ artifact: 'string',
161
+ path: 'string',
162
+ replacements: 'number.integer >= 1',
163
+ });
164
+ const ListSuccess = type({
165
+ success: 'true',
166
+ plans: type({ name: 'string', artifacts: 'string[]' }).array(),
167
+ });
168
+ const DeleteSuccess = type({
169
+ success: 'true',
170
+ plan: 'string',
171
+ path: 'string',
172
+ });
173
+ export const WritePlanOutput = WriteSuccess.or(InvalidName)
174
+ .or(InvalidArtifact)
175
+ .or(EmptyContent)
176
+ .or(UnsafePath)
177
+ .or(IoError);
178
+ export const ReadPlanOutput = ReadSuccess.or(InvalidName).or(InvalidArtifact).or(NotFound).or(UnsafePath).or(IoError);
179
+ export const EditPlanOutput = EditSuccess.or(InvalidName)
180
+ .or(InvalidArtifact)
181
+ .or(NotFound)
182
+ .or(MustReadFirst)
183
+ .or(StaleRead)
184
+ .or(NoChange)
185
+ .or(OldStringNotFound)
186
+ .or(AmbiguousMatch)
187
+ .or(UnsafePath)
188
+ .or(IoError);
189
+ export const ListPlansOutput = ListSuccess.or(IoError);
190
+ export const DeletePlanOutput = DeleteSuccess.or(InvalidName).or(PlanNotFound).or(UnsafePath).or(IoError);
191
+ //# sourceMappingURL=contracts.js.map
@@ -0,0 +1 @@
1
+ {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}
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/build/index.js ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env node
2
+ import { serveStdio } from '@modelcontextprotocol/server/stdio';
3
+ import { createServer } from './server.js';
4
+ import { readPackageVersion } from './version.js';
5
+ import { resolveWorkspaceRoot } from './workspace.js';
6
+ const root = await resolveWorkspaceRoot();
7
+ const version = await readPackageVersion();
8
+ const handle = serveStdio(() => createServer(root, version));
9
+ // stdout carries JSON-RPC; anything this process says goes to stderr.
10
+ console.error(`viper-plans MCP server ${version} serving plans in ${root}`);
11
+ for (const signal of ['SIGINT', 'SIGTERM']) {
12
+ process.on(signal, () => {
13
+ void handle.close().finally(() => process.exit(0));
14
+ });
15
+ }
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAA;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AAErD,MAAM,IAAI,GAAG,MAAM,oBAAoB,EAAE,CAAA;AACzC,MAAM,OAAO,GAAG,MAAM,kBAAkB,EAAE,CAAA;AAE1C,MAAM,MAAM,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAA;AAE5D,sEAAsE;AACtE,OAAO,CAAC,KAAK,CAAC,0BAA0B,OAAO,qBAAqB,IAAI,EAAE,CAAC,CAAA;AAE3E,KAAK,MAAM,MAAM,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAU,EAAE,CAAC;IACpD,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE;QACtB,KAAK,MAAM,CAAC,KAAK,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;IACpD,CAAC,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { type DeletePlanArgs, type DeletePlanResult, type EditPlanArgs, type EditPlanResult, type ListPlansResult, type ReadPlanArgs, type ReadPlanResult, type WritePlanArgs, type WritePlanResult } from './contracts.js';
2
+ export declare function writePlan(root: string, args: WritePlanArgs): Promise<WritePlanResult>;
3
+ export declare function readPlan(root: string, args: ReadPlanArgs): Promise<ReadPlanResult>;
4
+ export declare function editPlan(root: string, args: EditPlanArgs): Promise<EditPlanResult>;
5
+ export declare function listPlans(root: string): Promise<ListPlansResult>;
6
+ export declare function deletePlan(root: string, args: DeletePlanArgs): Promise<DeletePlanResult>;
@@ -0,0 +1,271 @@
1
+ import { access, mkdir, readdir, readFile, rm } from 'node:fs/promises';
2
+ import { atomicWriteFile } from './atomic-write.js';
3
+ import { ARTIFACT_EXTENSION, isValidName, normalizeArtifact, } from './contracts.js';
4
+ import { digestOf, forgetUnder, recordSeen, seenDigest, withPathLock } from './read-tracker.js';
5
+ import { artifactPath, ensureContained, planDirectory, plansDirectory } from './workspace.js';
6
+ export async function writePlan(root, args) {
7
+ if (args.content.trim() === '') {
8
+ return { success: false, reason: 'empty_content', message: 'Plan content must not be empty.' };
9
+ }
10
+ const target = await resolveArtifactTarget(root, args.plan, args.artifact);
11
+ if (!target.ok)
12
+ return target.failure;
13
+ const { artifact, path } = target;
14
+ return await withPathLock(path, async () => {
15
+ try {
16
+ await mkdir(planDirectory(root, args.plan), { recursive: true });
17
+ await atomicWriteFile(path, args.content);
18
+ }
19
+ catch (error) {
20
+ return ioError('write', error);
21
+ }
22
+ recordSeen(path, args.content);
23
+ return { success: true, plan: args.plan, artifact, path };
24
+ });
25
+ }
26
+ export async function readPlan(root, args) {
27
+ const target = await resolveArtifactTarget(root, args.plan, args.artifact);
28
+ if (!target.ok)
29
+ return target.failure;
30
+ const { artifact, path } = target;
31
+ return await withPathLock(path, async () => {
32
+ let content;
33
+ try {
34
+ content = await readFile(path, 'utf8');
35
+ }
36
+ catch (error) {
37
+ if (errorCode(error) === 'ENOENT')
38
+ return notFound(args.plan, artifact);
39
+ return ioError('read', error);
40
+ }
41
+ recordSeen(path, content);
42
+ return { success: true, plan: args.plan, artifact, path, content };
43
+ });
44
+ }
45
+ export async function editPlan(root, args) {
46
+ const target = await resolveArtifactTarget(root, args.plan, args.artifact);
47
+ if (!target.ok)
48
+ return target.failure;
49
+ const { artifact, path } = target;
50
+ return await withPathLock(path, async () => {
51
+ let current;
52
+ try {
53
+ current = await readFile(path, 'utf8');
54
+ }
55
+ catch (error) {
56
+ if (errorCode(error) === 'ENOENT')
57
+ return notFound(args.plan, artifact);
58
+ return ioError('read', error);
59
+ }
60
+ const seen = seenDigest(path);
61
+ if (seen === undefined) {
62
+ return {
63
+ success: false,
64
+ reason: 'must_read_first',
65
+ plan: args.plan,
66
+ artifact,
67
+ message: `Read ${artifact} with viper-read-plan (or write it with viper-write-plan) before editing it.`,
68
+ };
69
+ }
70
+ if (seen !== digestOf(current)) {
71
+ return {
72
+ success: false,
73
+ reason: 'stale_read',
74
+ plan: args.plan,
75
+ artifact,
76
+ message: `${artifact} changed since it was last read. Re-read it with viper-read-plan before editing.`,
77
+ };
78
+ }
79
+ if (args.oldString === args.newString) {
80
+ return {
81
+ success: false,
82
+ reason: 'no_change',
83
+ plan: args.plan,
84
+ artifact,
85
+ message: 'oldString and newString are identical, so the edit would change nothing.',
86
+ };
87
+ }
88
+ const matches = countOccurrences(current, args.oldString);
89
+ if (matches === 0) {
90
+ return {
91
+ success: false,
92
+ reason: 'old_string_not_found',
93
+ plan: args.plan,
94
+ artifact,
95
+ message: `oldString does not appear in ${artifact}.`,
96
+ };
97
+ }
98
+ if (matches > 1 && args.replaceAll !== true) {
99
+ return {
100
+ success: false,
101
+ reason: 'ambiguous_match',
102
+ plan: args.plan,
103
+ artifact,
104
+ count: matches,
105
+ message: `oldString appears ${matches} times. Add surrounding context to make it unique, or set replaceAll.`,
106
+ };
107
+ }
108
+ const updated = replaceLiteral(current, args.oldString, args.newString, args.replaceAll === true);
109
+ try {
110
+ await atomicWriteFile(path, updated);
111
+ }
112
+ catch (error) {
113
+ return ioError('write', error);
114
+ }
115
+ recordSeen(path, updated);
116
+ return {
117
+ success: true,
118
+ plan: args.plan,
119
+ artifact,
120
+ path,
121
+ replacements: args.replaceAll === true ? matches : 1,
122
+ };
123
+ });
124
+ }
125
+ export async function listPlans(root) {
126
+ const directory = plansDirectory(root);
127
+ let names;
128
+ try {
129
+ const entries = await readdir(directory, { withFileTypes: true });
130
+ names = entries.filter((entry) => entry.isDirectory()).map((entry) => entry.name);
131
+ }
132
+ catch (error) {
133
+ if (errorCode(error) === 'ENOENT')
134
+ return { success: true, plans: [] };
135
+ return ioError('list', error);
136
+ }
137
+ const plans = [];
138
+ for (const name of names.sort()) {
139
+ if (!isValidName(name))
140
+ continue;
141
+ const contained = await ensureContained(root, planDirectory(root, name));
142
+ if (!contained.ok)
143
+ continue;
144
+ let files;
145
+ try {
146
+ files = await readdir(contained.path);
147
+ }
148
+ catch (error) {
149
+ if (errorCode(error) === 'ENOENT')
150
+ continue;
151
+ return ioError('list', error);
152
+ }
153
+ const artifacts = files
154
+ .filter((file) => file.endsWith(ARTIFACT_EXTENSION))
155
+ .map((file) => file.slice(0, -ARTIFACT_EXTENSION.length))
156
+ .filter(isValidName)
157
+ .sort();
158
+ plans.push({ name, artifacts });
159
+ }
160
+ return { success: true, plans };
161
+ }
162
+ export async function deletePlan(root, args) {
163
+ if (!isValidName(args.plan))
164
+ return invalidName(args.plan);
165
+ const directory = planDirectory(root, args.plan);
166
+ const contained = await ensureContained(root, directory);
167
+ if (!contained.ok)
168
+ return unsafePath(contained.path, contained.message);
169
+ return await withPathLock(directory, async () => {
170
+ try {
171
+ await access(directory);
172
+ }
173
+ catch {
174
+ return {
175
+ success: false,
176
+ reason: 'plan_not_found',
177
+ plan: args.plan,
178
+ message: `No plan named ${args.plan} exists.`,
179
+ };
180
+ }
181
+ try {
182
+ await rm(directory, { recursive: true, force: true });
183
+ }
184
+ catch (error) {
185
+ return ioError('delete', error);
186
+ }
187
+ forgetUnder(directory);
188
+ return { success: true, plan: args.plan, path: directory };
189
+ });
190
+ }
191
+ /**
192
+ * The guard every artifact-addressed operation shares: a valid plan name, a
193
+ * normalized and valid artifact name, and a resolved path that really lives
194
+ * beneath the plans directory.
195
+ */
196
+ async function resolveArtifactTarget(root, plan, requestedArtifact) {
197
+ if (!isValidName(plan))
198
+ return { ok: false, failure: invalidName(plan) };
199
+ const artifact = normalizeArtifact(requestedArtifact);
200
+ if (!isValidName(artifact))
201
+ return { ok: false, failure: invalidArtifact(artifact) };
202
+ const path = artifactPath(root, plan, artifact);
203
+ const contained = await ensureContained(root, path);
204
+ if (!contained.ok)
205
+ return { ok: false, failure: unsafePath(contained.path, contained.message) };
206
+ return { ok: true, artifact, path };
207
+ }
208
+ function invalidName(name) {
209
+ return {
210
+ success: false,
211
+ reason: 'invalid_name',
212
+ name,
213
+ message: `"${name}" is not a valid plan name. Use letters, digits, hyphens, and underscores, starting with a letter or digit.`,
214
+ };
215
+ }
216
+ function invalidArtifact(artifact) {
217
+ return {
218
+ success: false,
219
+ reason: 'invalid_artifact',
220
+ artifact,
221
+ message: `"${artifact}" is not a valid artifact name. Use letters, digits, hyphens, and underscores, starting with a letter or digit.`,
222
+ };
223
+ }
224
+ function notFound(plan, artifact) {
225
+ return {
226
+ success: false,
227
+ reason: 'not_found',
228
+ plan,
229
+ artifact,
230
+ message: `${plan}/${artifact} does not exist.`,
231
+ };
232
+ }
233
+ function unsafePath(path, message) {
234
+ return { success: false, reason: 'unsafe_path', path, message };
235
+ }
236
+ function ioError(operation, error) {
237
+ return { success: false, reason: 'io_error', operation, message: describeError(error) };
238
+ }
239
+ function describeError(error) {
240
+ return error instanceof Error ? error.message : String(error);
241
+ }
242
+ function errorCode(error) {
243
+ if (typeof error === 'object' && error !== null && 'code' in error) {
244
+ const { code } = error;
245
+ if (typeof code === 'string')
246
+ return code;
247
+ }
248
+ return undefined;
249
+ }
250
+ function countOccurrences(haystack, needle) {
251
+ if (needle === '')
252
+ return 0;
253
+ let count = 0;
254
+ let index = haystack.indexOf(needle);
255
+ while (index !== -1) {
256
+ count += 1;
257
+ index = haystack.indexOf(needle, index + needle.length);
258
+ }
259
+ return count;
260
+ }
261
+ /**
262
+ * Replace without `String.prototype.replace`: a plan can legitimately contain
263
+ * `$&`, `` $` ``, or `$1`, which that method would expand inside `newString`.
264
+ */
265
+ function replaceLiteral(source, oldString, newString, all) {
266
+ if (all)
267
+ return source.split(oldString).join(newString);
268
+ const index = source.indexOf(oldString);
269
+ return source.slice(0, index) + newString + source.slice(index + oldString.length);
270
+ }
271
+ //# sourceMappingURL=plan-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plan-store.js","sourceRoot":"","sources":["../src/plan-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAA;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EACL,kBAAkB,EAKlB,WAAW,EAEX,iBAAiB,GAKlB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAC/F,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAE7F,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,IAAY,EAAE,IAAmB;IAC/D,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QAC/B,OAAO,EAAE,OAAO,EAAE,KAAK,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AAc,EAAE,SAAiB,EAAE,SAAiB,EAAE,GAAY;IACxF,IAAI,GAAG;QAAE,OAAO,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;IACvD,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;IACvC,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,GAAG,SAAS,CAAC,MAAM,CAAC,CAAA;AACpF,CAAC"}
@@ -0,0 +1,10 @@
1
+ export declare function digestOf(content: string): string;
2
+ export declare function recordSeen(path: string, content: string): void;
3
+ export declare function seenDigest(path: string): string | undefined;
4
+ /** Drop every tracked artifact inside a directory that no longer exists. */
5
+ export declare function forgetUnder(directory: string): void;
6
+ /**
7
+ * Run `operation` with no other operation on the same path in flight, so a
8
+ * read-modify-write cycle inside this process cannot interleave with another.
9
+ */
10
+ export declare function withPathLock<T>(path: string, operation: () => Promise<T>): Promise<T>;
@@ -0,0 +1,62 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { sep } from 'node:path';
3
+ /**
4
+ * Read tracking for the edit guard, and serialization of the writes that
5
+ * update it. Both live for the lifetime of this server process, which is
6
+ * exactly the scope the guard protects: an edit is allowed when THIS server
7
+ * has seen the artifact's current bytes.
8
+ *
9
+ * The recorded value is a digest of the content rather than an mtime, so an
10
+ * edit is refused whenever the bytes changed — including changes a coarse
11
+ * filesystem timestamp cannot distinguish from the read that preceded them.
12
+ *
13
+ * Both maps are keyed by absolute path, so two workspaces served by one
14
+ * process never share an entry.
15
+ */
16
+ const digests = new Map();
17
+ const chains = new Map();
18
+ export function digestOf(content) {
19
+ return createHash('sha256').update(content, 'utf8').digest('hex');
20
+ }
21
+ export function recordSeen(path, content) {
22
+ digests.set(path, digestOf(content));
23
+ }
24
+ export function seenDigest(path) {
25
+ return digests.get(path);
26
+ }
27
+ /** Drop every tracked artifact inside a directory that no longer exists. */
28
+ export function forgetUnder(directory) {
29
+ const prefix = directory.endsWith(sep) ? directory : `${directory}${sep}`;
30
+ for (const path of digests.keys()) {
31
+ if (path === directory || path.startsWith(prefix))
32
+ digests.delete(path);
33
+ }
34
+ }
35
+ /**
36
+ * Run `operation` with no other operation on the same path in flight, so a
37
+ * read-modify-write cycle inside this process cannot interleave with another.
38
+ */
39
+ export async function withPathLock(path, operation) {
40
+ const existing = chains.get(path);
41
+ const previous = existing?.tail ?? Promise.resolve();
42
+ let release = () => undefined;
43
+ const held = new Promise((resolve) => {
44
+ release = resolve;
45
+ });
46
+ const chain = { tail: previous.then(() => held), depth: (existing?.depth ?? 0) + 1 };
47
+ chains.set(path, chain);
48
+ await previous;
49
+ try {
50
+ return await operation();
51
+ }
52
+ finally {
53
+ release();
54
+ const current = chains.get(path);
55
+ if (current) {
56
+ current.depth -= 1;
57
+ if (current.depth === 0)
58
+ chains.delete(path);
59
+ }
60
+ }
61
+ }
62
+ //# sourceMappingURL=read-tracker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-tracker.js","sourceRoot":"","sources":["../src/read-tracker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AAE/B;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAA;AAOzC,MAAM,MAAM,GAAG,IAAI,GAAG,EAAiB,CAAA;AAEvC,MAAM,UAAU,QAAQ,CAAC,OAAe;IACtC,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AACnE,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,IAAY,EAAE,OAAe;IACtD,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,OAAO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AAM,SAAS,EAAE,CAAA;IAC1B,CAAC;YAAS,CAAC;QACT,OAAO,EAAE,CAAA;QACT,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QAChC,IAAI,OAAO,EAAE,CAAC;YACZ,OAAO,CAAC,KAAK,IAAI,CAAC,CAAA;YAClB,IAAI,OAAO,CAAC,KAAK,KAAK,CAAC;gBAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QAC9C,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { McpServer } from '@modelcontextprotocol/server';
2
+ export declare function createServer(root: string, version: string): McpServer;
@@ -0,0 +1,77 @@
1
+ import { McpServer } from '@modelcontextprotocol/server';
2
+ import { DeletePlanInput, DeletePlanOutput, EditPlanInput, EditPlanOutput, ListPlansInput, ListPlansOutput, ReadPlanInput, ReadPlanOutput, TOOL_NAMES, WritePlanInput, WritePlanOutput, } from './contracts.js';
3
+ import { deletePlan, editPlan, listPlans, readPlan, writePlan } from './plan-store.js';
4
+ export function createServer(root, version) {
5
+ const server = new McpServer({ name: 'viper-plans', version });
6
+ server.registerTool(TOOL_NAMES.write, {
7
+ title: 'Write a VIPER plan artifact',
8
+ description: 'Create or replace a VIPER plan artifact under .opencode/plans/<plan>/<artifact>.md. Replaces the artifact outright, and records it as read so it can be edited afterwards.',
9
+ inputSchema: WritePlanInput,
10
+ outputSchema: WritePlanOutput,
11
+ annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true },
12
+ }, async (args) => {
13
+ const result = await writePlan(root, args);
14
+ return result.success
15
+ ? succeeded(`Wrote ${result.plan}/${result.artifact} to ${result.path}.`, result)
16
+ : failed(result);
17
+ });
18
+ server.registerTool(TOOL_NAMES.read, {
19
+ title: 'Read a VIPER plan artifact',
20
+ description: 'Read a VIPER plan artifact. Reading is required before editing it, and re-reading is how a stale edit is recovered from.',
21
+ inputSchema: ReadPlanInput,
22
+ outputSchema: ReadPlanOutput,
23
+ annotations: { readOnlyHint: true },
24
+ }, async (args) => {
25
+ const result = await readPlan(root, args);
26
+ return result.success ? succeeded(result.content, result) : failed(result);
27
+ });
28
+ server.registerTool(TOOL_NAMES.edit, {
29
+ title: 'Edit a VIPER plan artifact',
30
+ description: 'Replace exact text inside a VIPER plan artifact. The artifact must have been read or written by this server and be unchanged since. oldString must match exactly once unless replaceAll is set.',
31
+ inputSchema: EditPlanInput,
32
+ outputSchema: EditPlanOutput,
33
+ annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false },
34
+ }, async (args) => {
35
+ const result = await editPlan(root, args);
36
+ return result.success
37
+ ? succeeded(`Made ${result.replacements} replacement${result.replacements === 1 ? '' : 's'} in ${result.plan}/${result.artifact}.`, result)
38
+ : failed(result);
39
+ });
40
+ server.registerTool(TOOL_NAMES.list, {
41
+ title: 'List VIPER plans',
42
+ description: 'List every VIPER plan in the workspace with the artifacts it contains.',
43
+ inputSchema: ListPlansInput,
44
+ outputSchema: ListPlansOutput,
45
+ annotations: { readOnlyHint: true },
46
+ }, async () => {
47
+ const result = await listPlans(root);
48
+ if (!result.success)
49
+ return failed(result);
50
+ const text = result.plans.length === 0
51
+ ? 'No plans found.'
52
+ : result.plans.map((plan) => `${plan.name}: ${plan.artifacts.join(', ') || '(no artifacts)'}`).join('\n');
53
+ return succeeded(text, result);
54
+ });
55
+ server.registerTool(TOOL_NAMES.delete, {
56
+ title: 'Delete a VIPER plan',
57
+ description: 'Delete a VIPER plan directory and every artifact inside it. This cannot be undone.',
58
+ inputSchema: DeletePlanInput,
59
+ outputSchema: DeletePlanOutput,
60
+ annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true },
61
+ }, async (args) => {
62
+ const result = await deletePlan(root, args);
63
+ return result.success ? succeeded(`Deleted ${result.plan} (${result.path}).`, result) : failed(result);
64
+ });
65
+ return server;
66
+ }
67
+ function succeeded(text, structuredContent) {
68
+ return { content: [{ type: 'text', text }], structuredContent };
69
+ }
70
+ function failed(result) {
71
+ return {
72
+ content: [{ type: 'text', text: result.message }],
73
+ structuredContent: result,
74
+ isError: true,
75
+ };
76
+ }
77
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AACxD,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,cAAc,EACd,eAAe,EACf,aAAa,EACb,cAAc,EACd,UAAU,EACV,cAAc,EACd,eAAe,GAChB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAEtF,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,OAAe;IACxD,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,CAAC,CAAA;IAE9D,MAAM,CAAC,YAAY,CACjB,UAAU,CAAC,KAAK,EAChB;QACE,KAAK,EAAE,6BAA6B;QACpC,WAAW,EACT,4KAA4K;QAC9K,WAAW,EAAE,cAAc;QAC3B,YAAY,EAAE,eAAe;QAC7B,WAAW,EAAE,EAAE,YAAY,EAAE,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE;KAClF,EACD,KAAK,EAAE,IAAI,EAAE,EAAE;QACb,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;QAC1C,OAAO,MAAM,CAAC,OAAO;YACnB,CAAC,CAAC,SAAS,CAAC,SAAS,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,QAAQ,OAAO,MAAM,CAAC,IAAI,GAAG,EAAE,MAAM,CAAC;YACjF,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IACpB,CAAC,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AM,CAAC,CAAA;IACxG,CAAC,CACF,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AAED,SAAS,SAAS,CAAI,IAAY,EAAE,iBAAoB;IACtD,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,CAAC,EAAE,iBAAiB,EAAE,CAAA;AAC1E,CAAC;AAED,SAAS,MAAM,CAAgC,MAAS;IACtD,OAAO;QACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC;QAC1D,iBAAiB,EAAE,MAAM;QACzB,OAAO,EAAE,IAAa;KACvB,CAAA;AACH,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The package's own version, read from the manifest that ships beside the
3
+ * compiled output. Reading it keeps package.json the only place the version
4
+ * is written; the server, the facet's declaration, and the release tag are all
5
+ * checked against it.
6
+ */
7
+ export declare function readPackageVersion(): Promise<string>;
@@ -0,0 +1,17 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { dirname, join } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { type } from 'arktype';
5
+ const PackageManifest = type({ version: 'string >= 1' });
6
+ /**
7
+ * The package's own version, read from the manifest that ships beside the
8
+ * compiled output. Reading it keeps package.json the only place the version
9
+ * is written; the server, the facet's declaration, and the release tag are all
10
+ * checked against it.
11
+ */
12
+ export async function readPackageVersion() {
13
+ const manifestPath = join(dirname(fileURLToPath(import.meta.url)), '..', 'package.json');
14
+ const manifest = PackageManifest.assert(JSON.parse(await readFile(manifestPath, 'utf8')));
15
+ return manifest.version;
16
+ }
17
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAE9B,MAAM,eAAe,GAAG,IAAI,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC,CAAA;AAExD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB;IACtC,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,cAAc,CAAC,CAAA;IACxF,MAAM,QAAQ,GAAG,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC,CAAC,CAAA;IACzF,OAAO,QAAQ,CAAC,OAAO,CAAA;AACzB,CAAC"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * The directory plans are stored beneath. MCP roots would be the protocol's
3
+ * answer here, but they are deprecated as of the 2026-07-28 revision, so the
4
+ * server takes the working directory the host launched it in — the same
5
+ * project directory the VIPER commands read and write through their fallback
6
+ * file operations.
7
+ */
8
+ export declare function resolveWorkspaceRoot(): Promise<string>;
9
+ export declare function plansDirectory(root: string): string;
10
+ export declare function planDirectory(root: string, plan: string): string;
11
+ export declare function artifactPath(root: string, plan: string, artifact: string): string;
12
+ export type ContainmentResult = {
13
+ ok: true;
14
+ path: string;
15
+ } | {
16
+ ok: false;
17
+ path: string;
18
+ message: string;
19
+ };
20
+ /**
21
+ * Confirm a path really lives beneath the plans directory once symlinks are
22
+ * followed. The name grammar already rules out traversal in what a caller
23
+ * sends, so this catches the case the grammar cannot see: a plan directory or
24
+ * artifact on disk that is a symlink out of the workspace.
25
+ */
26
+ export declare function ensureContained(root: string, target: string): Promise<ContainmentResult>;
@@ -0,0 +1,77 @@
1
+ import { realpath } from 'node:fs/promises';
2
+ import { isAbsolute, join, relative, resolve, sep } from 'node:path';
3
+ import { ARTIFACT_EXTENSION, PLANS_DIRECTORY } from './contracts.js';
4
+ /**
5
+ * The directory plans are stored beneath. MCP roots would be the protocol's
6
+ * answer here, but they are deprecated as of the 2026-07-28 revision, so the
7
+ * server takes the working directory the host launched it in — the same
8
+ * project directory the VIPER commands read and write through their fallback
9
+ * file operations.
10
+ */
11
+ export async function resolveWorkspaceRoot() {
12
+ return await realpath(process.cwd());
13
+ }
14
+ export function plansDirectory(root) {
15
+ return join(root, ...PLANS_DIRECTORY);
16
+ }
17
+ export function planDirectory(root, plan) {
18
+ return join(plansDirectory(root), plan);
19
+ }
20
+ export function artifactPath(root, plan, artifact) {
21
+ return join(planDirectory(root, plan), `${artifact}${ARTIFACT_EXTENSION}`);
22
+ }
23
+ /**
24
+ * Confirm a path really lives beneath the plans directory once symlinks are
25
+ * followed. The name grammar already rules out traversal in what a caller
26
+ * sends, so this catches the case the grammar cannot see: a plan directory or
27
+ * artifact on disk that is a symlink out of the workspace.
28
+ */
29
+ export async function ensureContained(root, target) {
30
+ const plansRoot = plansDirectory(root);
31
+ const lexical = resolve(target);
32
+ if (lexical !== target || !isUnder(plansRoot, lexical)) {
33
+ return { ok: false, path: target, message: `${target} is outside the plans directory` };
34
+ }
35
+ const [resolvedRoot, resolvedTarget] = await Promise.all([
36
+ resolveThroughLinks(plansRoot),
37
+ resolveThroughLinks(target),
38
+ ]);
39
+ if (!isUnder(resolvedRoot, resolvedTarget)) {
40
+ return {
41
+ ok: false,
42
+ path: target,
43
+ message: `${target} resolves to ${resolvedTarget}, which is outside the plans directory`,
44
+ };
45
+ }
46
+ return { ok: true, path: target };
47
+ }
48
+ function isUnder(parent, candidate) {
49
+ if (candidate === parent)
50
+ return true;
51
+ const rel = relative(parent, candidate);
52
+ return rel !== '' && !rel.startsWith(`..${sep}`) && rel !== '..' && !isAbsolute(rel);
53
+ }
54
+ /**
55
+ * Resolve `target` against the filesystem as far as it exists, then re-append
56
+ * the segments that do not exist yet. `realpath` alone cannot be used because
57
+ * a plan directory is routinely created by the very call being checked.
58
+ */
59
+ async function resolveThroughLinks(target) {
60
+ const pending = [];
61
+ let current = resolve(target);
62
+ for (;;) {
63
+ try {
64
+ const real = await realpath(current);
65
+ return pending.length === 0 ? real : join(real, ...pending);
66
+ }
67
+ catch {
68
+ const parent = resolve(current, '..');
69
+ if (parent === current)
70
+ return join(current, ...pending);
71
+ const segment = relative(parent, current);
72
+ pending.unshift(segment);
73
+ current = parent;
74
+ }
75
+ }
76
+ }
77
+ //# sourceMappingURL=workspace.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workspace.js","sourceRoot":"","sources":["../src/workspace.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AACpE,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAEpE;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB;IACxC,OAAO,MAAM,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAA;AACtC,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,OAAO,IAAI,CAAC,IAAI,EAAE,GAAG,eAAe,CAAC,CAAA;AACvC,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,IAAY,EAAE,IAAY;IACtD,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,CAAA;AACzC,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,IAAY,EAAE,QAAgB;IACvE,OAAO,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,GAAG,QAAQ,GAAG,kBAAkB,EAAE,CAAC,CAAA;AAC5E,CAAC;AAID;;;;;GAKG;AACH,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AAE,CAAA;IAC5B,IAAI,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IAE7B,SAAS,CAAC;QACR,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,CAAA;YACpC,OAAO,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,OAAO,CAAC,CAAA;QAC7D,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;YACrC,IAAI,MAAM,KAAK,OAAO;gBAAE,OAAO,IAAI,CAAC,OAAO,EAAE,GAAG,OAAO,CAAC,CAAA;YACxD,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;YACzC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;YACxB,OAAO,GAAG,MAAM,CAAA;QAClB,CAAC;IACH,CAAC;AACH,CAAC"}
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@agent-facets/viper-plans-mcp",
3
+ "version": "1.3.0",
4
+ "description": "MCP server exposing VIPER plan storage tools (write, read, edit, list, delete) over stdio",
5
+ "keywords": [
6
+ "mcp",
7
+ "modelcontextprotocol",
8
+ "viper",
9
+ "planning",
10
+ "agent",
11
+ "opencode"
12
+ ],
13
+ "license": "MIT",
14
+ "author": "Julian Coy <julian@agentfacets.io>",
15
+ "homepage": "https://github.com/agent-facets/viper-plans#readme",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/agent-facets/viper-plans.git"
19
+ },
20
+ "bugs": {
21
+ "url": "https://github.com/agent-facets/viper-plans/issues"
22
+ },
23
+ "type": "module",
24
+ "packageManager": "bun@1.3.14",
25
+ "engines": {
26
+ "node": ">=20"
27
+ },
28
+ "bin": {
29
+ "viper-plans-mcp": "./build/index.js"
30
+ },
31
+ "exports": {
32
+ ".": {
33
+ "types": "./build/index.d.ts",
34
+ "default": "./build/index.js"
35
+ }
36
+ },
37
+ "files": [
38
+ "build",
39
+ "README.md",
40
+ "LICENSE"
41
+ ],
42
+ "publishConfig": {
43
+ "access": "public"
44
+ },
45
+ "scripts": {
46
+ "build": "tsc -p tsconfig.json",
47
+ "format": "biome check --write --unsafe .",
48
+ "check": "turbo run check:format check:types check:version build test check:facet",
49
+ "check:format": "biome check --error-on-warnings .",
50
+ "check:types": "tsc -p tsconfig.check.json",
51
+ "test": "bun test",
52
+ "prepack": "bun run build",
53
+ "check:version": "bun run scripts/check-version.ts",
54
+ "check:facet": "facet build --verify"
55
+ },
56
+ "dependencies": {
57
+ "@modelcontextprotocol/server": "2.0.0",
58
+ "arktype": "2.2.3"
59
+ },
60
+ "devDependencies": {
61
+ "@biomejs/biome": "2.5.9",
62
+ "@modelcontextprotocol/client": "2.0.0",
63
+ "@types/bun": "1.3.14",
64
+ "@types/node": "24.13.3",
65
+ "turbo": "2.10.4",
66
+ "typescript": "7.0.2"
67
+ }
68
+ }