iaip-mcp-pde 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +187 -0
  2. package/dist/cli.d.ts +18 -0
  3. package/dist/cli.d.ts.map +1 -0
  4. package/dist/cli.js +385 -0
  5. package/dist/cli.js.map +1 -0
  6. package/dist/index.d.ts +15 -0
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +34 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/mcp-server.d.ts +59 -0
  11. package/dist/mcp-server.d.ts.map +1 -0
  12. package/dist/mcp-server.js +293 -0
  13. package/dist/mcp-server.js.map +1 -0
  14. package/dist/parser.d.ts +19 -0
  15. package/dist/parser.d.ts.map +1 -0
  16. package/dist/parser.js +89 -0
  17. package/dist/parser.js.map +1 -0
  18. package/dist/pde-engine.d.ts +54 -0
  19. package/dist/pde-engine.d.ts.map +1 -0
  20. package/dist/pde-engine.js +85 -0
  21. package/dist/pde-engine.js.map +1 -0
  22. package/dist/prompts.d.ts +10 -0
  23. package/dist/prompts.d.ts.map +1 -0
  24. package/dist/prompts.js +93 -0
  25. package/dist/prompts.js.map +1 -0
  26. package/dist/storage.d.ts +44 -0
  27. package/dist/storage.d.ts.map +1 -0
  28. package/dist/storage.js +369 -0
  29. package/dist/storage.js.map +1 -0
  30. package/dist/types.d.ts +108 -0
  31. package/dist/types.d.ts.map +1 -0
  32. package/dist/types.js +24 -0
  33. package/dist/types.js.map +1 -0
  34. package/package.json +63 -0
  35. package/rispecs/pde-data-models.rispec.md +182 -0
  36. package/rispecs/pde-overview.rispec.md +157 -0
  37. package/rispecs/pde-parent-child-schema.rispec.md +525 -0
  38. package/rispecs/pde-prompts.rispec.md +144 -0
  39. package/rispecs/pde-resources.rispec.md +101 -0
  40. package/rispecs/pde-tools.rispec.md +179 -0
  41. package/rispecs/relation-to-mcp-structural-thinking.kin.md +66 -0
  42. package/scenarios/01-simple-decomposition.md +88 -0
  43. package/scenarios/02-multi-intent-workflow.md +112 -0
  44. package/scenarios/03-ceremonial-alignment.md +155 -0
  45. package/scenarios/04-dependency-resolution.md +163 -0
  46. package/scenarios/05-checkpoint-recovery.md +171 -0
package/dist/index.js ADDED
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /**
4
+ * PDE-MCP v2 Entry Point
5
+ * Starts the Model Context Protocol server for Prompt Decomposition Engine.
6
+ *
7
+ * Also re-exports core engine, parser, prompts, storage for programmatic use.
8
+ * CLI: ./cli.ts (bin: mcp-pde)
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.startServer = exports.decompositionToMarkdown = exports.listDecompositions = exports.loadDecomposition = exports.saveDecomposition = exports.formatUserMessage = exports.buildSystemPrompt = exports.actionStackToMarkdown = exports.parseDecompositionResponse = exports.PDEParseError = exports.PdeEngine = void 0;
12
+ const mcp_server_js_1 = require("./mcp-server.js");
13
+ (0, mcp_server_js_1.startServer)().catch((error) => {
14
+ console.error('Failed to start PDE MCP server:', error);
15
+ process.exit(1);
16
+ });
17
+ // Re-export for library usage
18
+ var pde_engine_js_1 = require("./pde-engine.js");
19
+ Object.defineProperty(exports, "PdeEngine", { enumerable: true, get: function () { return pde_engine_js_1.PdeEngine; } });
20
+ Object.defineProperty(exports, "PDEParseError", { enumerable: true, get: function () { return pde_engine_js_1.PDEParseError; } });
21
+ var parser_js_1 = require("./parser.js");
22
+ Object.defineProperty(exports, "parseDecompositionResponse", { enumerable: true, get: function () { return parser_js_1.parseDecompositionResponse; } });
23
+ Object.defineProperty(exports, "actionStackToMarkdown", { enumerable: true, get: function () { return parser_js_1.actionStackToMarkdown; } });
24
+ var prompts_js_1 = require("./prompts.js");
25
+ Object.defineProperty(exports, "buildSystemPrompt", { enumerable: true, get: function () { return prompts_js_1.buildSystemPrompt; } });
26
+ Object.defineProperty(exports, "formatUserMessage", { enumerable: true, get: function () { return prompts_js_1.formatUserMessage; } });
27
+ var storage_js_1 = require("./storage.js");
28
+ Object.defineProperty(exports, "saveDecomposition", { enumerable: true, get: function () { return storage_js_1.saveDecomposition; } });
29
+ Object.defineProperty(exports, "loadDecomposition", { enumerable: true, get: function () { return storage_js_1.loadDecomposition; } });
30
+ Object.defineProperty(exports, "listDecompositions", { enumerable: true, get: function () { return storage_js_1.listDecompositions; } });
31
+ Object.defineProperty(exports, "decompositionToMarkdown", { enumerable: true, get: function () { return storage_js_1.decompositionToMarkdown; } });
32
+ var mcp_server_js_2 = require("./mcp-server.js");
33
+ Object.defineProperty(exports, "startServer", { enumerable: true, get: function () { return mcp_server_js_2.startServer; } });
34
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AACA;;;;;;GAMG;;;AAEH,mDAA8C;AAE9C,IAAA,2BAAW,GAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IAC5B,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,KAAK,CAAC,CAAC;IACxD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC;AAEH,8BAA8B;AAC9B,iDAA2D;AAAlD,0GAAA,SAAS,OAAA;AAAE,8GAAA,aAAa,OAAA;AACjC,yCAAgF;AAAvE,uHAAA,0BAA0B,OAAA;AAAE,kHAAA,qBAAqB,OAAA;AAC1D,2CAAoE;AAA3D,+GAAA,iBAAiB,OAAA;AAAE,+GAAA,iBAAiB,OAAA;AAC7C,2CAAiH;AAAxG,+GAAA,iBAAiB,OAAA;AAAE,+GAAA,iBAAiB,OAAA;AAAE,gHAAA,kBAAkB,OAAA;AAAE,qHAAA,uBAAuB,OAAA;AAC1F,iDAA8C;AAArC,4GAAA,WAAW,OAAA"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * MCP Server for PDE v2
3
+ *
4
+ * Implements Model Context Protocol server with LLM-driven Prompt Decomposition Engine.
5
+ *
6
+ * Tools:
7
+ * pde_decompose - Build system prompt for LLM decomposition, or parse LLM response
8
+ * pde_parse_response - Parse an LLM response into DecompositionResult and store it
9
+ * pde_get - Retrieve a stored decomposition by ID
10
+ * pde_list - List stored decompositions
11
+ * pde_export_markdown - Export a decomposition as markdown
12
+ *
13
+ * Resources:
14
+ * pde://schema/decomposition-result - The DecompositionResult JSON schema
15
+ * pde://directions - Four Directions metadata
16
+ *
17
+ * Prompts:
18
+ * pde-decompose - The system prompt for LLM-driven decomposition
19
+ */
20
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
21
+ import { PdeEngine } from './pde-engine.js';
22
+ declare const engine: PdeEngine;
23
+ declare const server: Server<{
24
+ method: string;
25
+ params?: {
26
+ [x: string]: unknown;
27
+ _meta?: {
28
+ [x: string]: unknown;
29
+ progressToken?: string | number | undefined;
30
+ "io.modelcontextprotocol/related-task"?: {
31
+ taskId: string;
32
+ } | undefined;
33
+ } | undefined;
34
+ } | undefined;
35
+ }, {
36
+ method: string;
37
+ params?: {
38
+ [x: string]: unknown;
39
+ _meta?: {
40
+ [x: string]: unknown;
41
+ progressToken?: string | number | undefined;
42
+ "io.modelcontextprotocol/related-task"?: {
43
+ taskId: string;
44
+ } | undefined;
45
+ } | undefined;
46
+ } | undefined;
47
+ }, {
48
+ [x: string]: unknown;
49
+ _meta?: {
50
+ [x: string]: unknown;
51
+ progressToken?: string | number | undefined;
52
+ "io.modelcontextprotocol/related-task"?: {
53
+ taskId: string;
54
+ } | undefined;
55
+ } | undefined;
56
+ }>;
57
+ export declare function startServer(): Promise<void>;
58
+ export { server, engine };
59
+ //# sourceMappingURL=mcp-server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-server.d.ts","sourceRoot":"","sources":["../src/mcp-server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAWnE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAY5C,QAAA,MAAM,MAAM,WAAkB,CAAC;AAE/B,QAAA,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAGX,CAAC;AA0RF,wBAAsB,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAIjD;AAED,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC"}
@@ -0,0 +1,293 @@
1
+ "use strict";
2
+ /**
3
+ * MCP Server for PDE v2
4
+ *
5
+ * Implements Model Context Protocol server with LLM-driven Prompt Decomposition Engine.
6
+ *
7
+ * Tools:
8
+ * pde_decompose - Build system prompt for LLM decomposition, or parse LLM response
9
+ * pde_parse_response - Parse an LLM response into DecompositionResult and store it
10
+ * pde_get - Retrieve a stored decomposition by ID
11
+ * pde_list - List stored decompositions
12
+ * pde_export_markdown - Export a decomposition as markdown
13
+ *
14
+ * Resources:
15
+ * pde://schema/decomposition-result - The DecompositionResult JSON schema
16
+ * pde://directions - Four Directions metadata
17
+ *
18
+ * Prompts:
19
+ * pde-decompose - The system prompt for LLM-driven decomposition
20
+ */
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.engine = exports.server = void 0;
23
+ exports.startServer = startServer;
24
+ const index_js_1 = require("@modelcontextprotocol/sdk/server/index.js");
25
+ const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
26
+ const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
27
+ const pde_engine_js_1 = require("./pde-engine.js");
28
+ const types_js_2 = require("./types.js");
29
+ const prompts_js_1 = require("./prompts.js");
30
+ const engine = new pde_engine_js_1.PdeEngine();
31
+ exports.engine = engine;
32
+ const server = new index_js_1.Server({ name: 'pde-mcp', version: '2.0.0' }, { capabilities: { tools: {}, resources: {}, prompts: {} } });
33
+ exports.server = server;
34
+ // ============================================================================
35
+ // Tools
36
+ // ============================================================================
37
+ server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => ({
38
+ tools: [
39
+ {
40
+ name: 'pde_decompose',
41
+ description: 'Build system prompt + user message for LLM-driven prompt decomposition. Send the returned systemPrompt and userMessage to your LLM, then call pde_parse_response with the result.',
42
+ inputSchema: {
43
+ type: 'object',
44
+ properties: {
45
+ prompt: { type: 'string', description: 'The complex prompt to decompose' },
46
+ options: {
47
+ type: 'object',
48
+ properties: {
49
+ extractImplicit: { type: 'boolean', default: true, description: 'Extract implicit intents from hedging language' },
50
+ mapDependencies: { type: 'boolean', default: true, description: 'Map dependencies between actions' },
51
+ },
52
+ },
53
+ parent_pde_id: { type: 'string', description: 'UUID of parent PDE for parent-child nesting' },
54
+ },
55
+ required: ['prompt'],
56
+ },
57
+ },
58
+ {
59
+ name: 'pde_parse_response',
60
+ description: 'Parse an LLM response (from pde_decompose prompt) into structured DecompositionResult JSON and store it in .pde/ folder.',
61
+ inputSchema: {
62
+ type: 'object',
63
+ properties: {
64
+ llm_response: { type: 'string', description: 'The raw LLM response text containing the DecompositionResult JSON' },
65
+ original_prompt: { type: 'string', description: 'The original user prompt that was decomposed' },
66
+ workdir: { type: 'string', description: 'Working directory for .pde/ storage (defaults to cwd)' },
67
+ parent_pde_id: { type: 'string', description: 'UUID of parent PDE for parent-child nesting' },
68
+ options: {
69
+ type: 'object',
70
+ properties: {
71
+ extractImplicit: { type: 'boolean', default: true },
72
+ mapDependencies: { type: 'boolean', default: true },
73
+ },
74
+ },
75
+ },
76
+ required: ['llm_response', 'original_prompt'],
77
+ },
78
+ },
79
+ {
80
+ name: 'pde_get',
81
+ description: 'Retrieve a stored decomposition by ID from .pde/ folder',
82
+ inputSchema: {
83
+ type: 'object',
84
+ properties: {
85
+ id: { type: 'string', description: 'Decomposition ID' },
86
+ workdir: { type: 'string', description: 'Working directory' },
87
+ },
88
+ required: ['id'],
89
+ },
90
+ },
91
+ {
92
+ name: 'pde_list',
93
+ description: 'List stored decompositions from .pde/ folder',
94
+ inputSchema: {
95
+ type: 'object',
96
+ properties: {
97
+ workdir: { type: 'string', description: 'Working directory' },
98
+ limit: { type: 'number', default: 10 },
99
+ parent_id: { type: 'string', description: 'Filter to children of a specific parent PDE UUID' },
100
+ },
101
+ },
102
+ },
103
+ {
104
+ name: 'pde_export_markdown',
105
+ description: 'Export a stored decomposition as a git-diffable markdown document with Four Directions headers',
106
+ inputSchema: {
107
+ type: 'object',
108
+ properties: {
109
+ id: { type: 'string', description: 'Decomposition ID' },
110
+ workdir: { type: 'string', description: 'Working directory' },
111
+ },
112
+ required: ['id'],
113
+ },
114
+ },
115
+ ],
116
+ }));
117
+ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
118
+ const { name, arguments: args } = request.params;
119
+ try {
120
+ switch (name) {
121
+ case 'pde_decompose': {
122
+ const input = args;
123
+ if (!input?.prompt) {
124
+ return { content: [{ type: 'text', text: 'Missing required parameter: prompt' }], isError: true };
125
+ }
126
+ const { systemPrompt, userMessage } = engine.buildPrompt(input.prompt, input.options);
127
+ return {
128
+ content: [{
129
+ type: 'text',
130
+ text: JSON.stringify({
131
+ instructions: 'Send systemPrompt as system message and userMessage as user message to your LLM. Then call pde_parse_response with the LLM output.',
132
+ systemPrompt,
133
+ userMessage,
134
+ original_prompt: input.prompt,
135
+ ...(input.parent_pde_id ? { parent_pde_id: input.parent_pde_id } : {}),
136
+ }, null, 2),
137
+ }],
138
+ };
139
+ }
140
+ case 'pde_parse_response': {
141
+ const { llm_response, original_prompt, workdir, options, parent_pde_id } = args;
142
+ if (!llm_response || !original_prompt) {
143
+ return { content: [{ type: 'text', text: 'Missing required: llm_response and original_prompt' }], isError: true };
144
+ }
145
+ const stored = engine.parseAndStore(llm_response, original_prompt, options, workdir, parent_pde_id);
146
+ return {
147
+ content: [{ type: 'text', text: JSON.stringify(stored, null, 2) }],
148
+ };
149
+ }
150
+ case 'pde_get': {
151
+ const { id, workdir } = args;
152
+ const stored = engine.get(id, workdir);
153
+ if (!stored) {
154
+ return { content: [{ type: 'text', text: `Decomposition ${id} not found` }], isError: true };
155
+ }
156
+ return { content: [{ type: 'text', text: JSON.stringify(stored, null, 2) }] };
157
+ }
158
+ case 'pde_list': {
159
+ const { workdir, limit, parent_id } = (args || {});
160
+ const items = parent_id
161
+ ? engine.listChildren(parent_id, workdir)
162
+ : engine.list(workdir, limit);
163
+ const limited = limit && !parent_id ? items.slice(0, limit) : items;
164
+ const summary = limited.map(d => ({
165
+ id: d.id,
166
+ timestamp: d.timestamp,
167
+ primaryAction: `${d.result.primary.action} ${d.result.primary.target}`,
168
+ secondaryCount: d.result.secondary.length,
169
+ ambiguityCount: d.result.ambiguities.length,
170
+ actionStackCount: d.result.actionStack.length,
171
+ ...(d.parent_pde_id ? { parent_pde_id: d.parent_pde_id } : {}),
172
+ ...(d.folder_name ? { folder_name: d.folder_name } : {}),
173
+ }));
174
+ return { content: [{ type: 'text', text: JSON.stringify(summary, null, 2) }] };
175
+ }
176
+ case 'pde_export_markdown': {
177
+ const { id, workdir } = args;
178
+ const md = engine.exportMarkdown(id, workdir);
179
+ if (!md) {
180
+ return { content: [{ type: 'text', text: `Decomposition ${id} not found` }], isError: true };
181
+ }
182
+ return { content: [{ type: 'text', text: md }] };
183
+ }
184
+ default:
185
+ return { content: [{ type: 'text', text: `Unknown tool: ${name}` }], isError: true };
186
+ }
187
+ }
188
+ catch (error) {
189
+ return {
190
+ content: [{ type: 'text', text: `Error: ${error instanceof Error ? error.message : String(error)}` }],
191
+ isError: true,
192
+ };
193
+ }
194
+ });
195
+ // ============================================================================
196
+ // Resources
197
+ // ============================================================================
198
+ server.setRequestHandler(types_js_1.ListResourcesRequestSchema, async () => ({
199
+ resources: [
200
+ {
201
+ uri: 'pde://schema/decomposition-result',
202
+ name: 'DecompositionResult Schema',
203
+ description: 'The canonical JSON schema for prompt decomposition output (primary/secondary intents, context, directions, action stack, ambiguities)',
204
+ mimeType: 'application/json',
205
+ },
206
+ {
207
+ uri: 'pde://directions',
208
+ name: 'Four Directions',
209
+ description: 'Medicine Wheel direction metadata: EAST=Vision, SOUTH=Analysis, WEST=Validation, NORTH=Action',
210
+ mimeType: 'application/json',
211
+ },
212
+ ],
213
+ }));
214
+ server.setRequestHandler(types_js_1.ReadResourceRequestSchema, async (request) => {
215
+ const { uri } = request.params;
216
+ switch (uri) {
217
+ case 'pde://schema/decomposition-result':
218
+ return {
219
+ contents: [{
220
+ uri,
221
+ mimeType: 'application/json',
222
+ text: JSON.stringify({
223
+ description: 'DecompositionResult — the output of PDE prompt decomposition',
224
+ schema: {
225
+ primary: { action: 'string', target: 'string', urgency: 'immediate|session|persistent', confidence: '0.0-1.0' },
226
+ secondary: [{ action: 'string', target: 'string', implicit: 'boolean', dependency: 'string|null', confidence: '0.0-1.0' }],
227
+ context: { files_needed: ['string'], tools_required: ['string'], assumptions: ['string'] },
228
+ outputs: { artifacts: ['string'], updates: ['string'], communications: ['string'] },
229
+ directions: { east: [{ text: 'string', confidence: '0.0-1.0', implicit: 'boolean' }], south: '...', west: '...', north: '...' },
230
+ actionStack: [{ text: 'string', direction: 'east|south|west|north', dependency: 'string|null', completed: 'boolean' }],
231
+ ambiguities: [{ text: 'string', suggestion: 'string' }],
232
+ },
233
+ }, null, 2),
234
+ }],
235
+ };
236
+ case 'pde://directions':
237
+ return {
238
+ contents: [{
239
+ uri,
240
+ mimeType: 'application/json',
241
+ text: JSON.stringify(types_js_2.DIRECTION_META, null, 2),
242
+ }],
243
+ };
244
+ default:
245
+ throw new Error(`Unknown resource: ${uri}`);
246
+ }
247
+ });
248
+ // ============================================================================
249
+ // Prompts
250
+ // ============================================================================
251
+ server.setRequestHandler(types_js_1.ListPromptsRequestSchema, async () => ({
252
+ prompts: [
253
+ {
254
+ name: 'pde-decompose',
255
+ description: 'System prompt for LLM-driven prompt decomposition. Returns system + user messages to send to your LLM.',
256
+ arguments: [
257
+ { name: 'userPrompt', description: 'The prompt to decompose', required: true },
258
+ { name: 'extractImplicit', description: 'Extract implicit intents (default: true)', required: false },
259
+ { name: 'mapDependencies', description: 'Map dependencies (default: true)', required: false },
260
+ ],
261
+ },
262
+ ],
263
+ }));
264
+ server.setRequestHandler(types_js_1.GetPromptRequestSchema, async (request) => {
265
+ const { name, arguments: promptArgs } = request.params;
266
+ if (name !== 'pde-decompose') {
267
+ throw new Error(`Unknown prompt: ${name}`);
268
+ }
269
+ const opts = {
270
+ extractImplicit: promptArgs?.extractImplicit !== 'false',
271
+ mapDependencies: promptArgs?.mapDependencies !== 'false',
272
+ };
273
+ return {
274
+ messages: [
275
+ {
276
+ role: 'user',
277
+ content: {
278
+ type: 'text',
279
+ text: `${(0, prompts_js_1.buildSystemPrompt)(opts)}\n\n${(0, prompts_js_1.formatUserMessage)(promptArgs?.userPrompt || '')}`,
280
+ },
281
+ },
282
+ ],
283
+ };
284
+ });
285
+ // ============================================================================
286
+ // Server Startup
287
+ // ============================================================================
288
+ async function startServer() {
289
+ const transport = new stdio_js_1.StdioServerTransport();
290
+ await server.connect(transport);
291
+ console.error('PDE MCP Server v2 started');
292
+ }
293
+ //# sourceMappingURL=mcp-server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-server.js","sourceRoot":"","sources":["../src/mcp-server.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;GAkBG;;;AAwTH,kCAIC;AA1TD,wEAAmE;AACnE,wEAAiF;AACjF,iEAO4C;AAE5C,mDAA4C;AAC5C,yCAQoB;AACpB,6CAAoE;AAEpE,MAAM,MAAM,GAAG,IAAI,yBAAS,EAAE,CAAC;AAqSd,wBAAM;AAnSvB,MAAM,MAAM,GAAG,IAAI,iBAAM,CACvB,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,EACrC,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,CAC5D,CAAC;AAgSO,wBAAM;AA9Rf,+EAA+E;AAC/E,QAAQ;AACR,+EAA+E;AAE/E,MAAM,CAAC,iBAAiB,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KAAK,CAAC,mBAAmB,IAAI,EAAE,CAAC,CAAC;IAC7C,CAAC;IAED,MAAM,IAAI,GAAG;QACX,eAAe,EAAE,UAAU,EAAE,eAAe,KAAK,OAAO;QACxD,eAAe,EAAE,UAAU,EAAE,eAAe,KAAK,OAAO;KACzD,CAAC;IAEF,OAAO;QACL,QAAQ,EAAE;YACR;gBACE,IAAI,EAAE,MAAM;gBACZ,OAAO,EAAE;oBACP,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,GAAG,IAAA,8BAAiB,EAAC,IAAI,CAAC,OAAO,IAAA,8BAAiB,EAAC,UAAU,EAAE,UAAU,IAAI,EAAE,CAAC,EAAE;iBACzF;aACF;SACF;KACF,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,+EAA+E;AAC/E,iBAAiB;AACjB,+EAA+E;AAExE,KAAK,UAAU,WAAW;IAC/B,MAAM,SAAS,GAAG,IAAI,+BAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,OAAO,CAAC,KAAK,CAAC,2BAA2B,CAAC,CAAC;AAC7C,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * PDE Parser - Response Parser for LLM text → DecompositionResult
3
+ *
4
+ * Lineage: IAIP/lib/pde/parser.ts → mcp-pde/src/parser.ts
5
+ * Handles JSON extraction from markdown code blocks, raw JSON, etc.
6
+ */
7
+ import type { DecompositionResult } from "./types.js";
8
+ export declare class PDEParseError extends Error {
9
+ rawResponse: string;
10
+ parseAttempt?: string | undefined;
11
+ constructor(message: string, rawResponse: string, parseAttempt?: string | undefined);
12
+ }
13
+ export declare function parseDecompositionResponse(responseText: string): DecompositionResult;
14
+ export declare function actionStackToMarkdown(items: Array<{
15
+ text: string;
16
+ completed?: boolean;
17
+ dependency?: string | null;
18
+ }>): string;
19
+ //# sourceMappingURL=parser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtD,qBAAa,aAAc,SAAQ,KAAK;IAG7B,WAAW,EAAE,MAAM;IACnB,YAAY,CAAC,EAAE,MAAM;gBAF5B,OAAO,EAAE,MAAM,EACR,WAAW,EAAE,MAAM,EACnB,YAAY,CAAC,EAAE,MAAM,YAAA;CAK/B;AAwDD,wBAAgB,0BAA0B,CAAC,YAAY,EAAE,MAAM,GAAG,mBAAmB,CASpF;AAED,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC,GAC9E,MAAM,CAQR"}
package/dist/parser.js ADDED
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ /**
3
+ * PDE Parser - Response Parser for LLM text → DecompositionResult
4
+ *
5
+ * Lineage: IAIP/lib/pde/parser.ts → mcp-pde/src/parser.ts
6
+ * Handles JSON extraction from markdown code blocks, raw JSON, etc.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.PDEParseError = void 0;
10
+ exports.parseDecompositionResponse = parseDecompositionResponse;
11
+ exports.actionStackToMarkdown = actionStackToMarkdown;
12
+ class PDEParseError extends Error {
13
+ rawResponse;
14
+ parseAttempt;
15
+ constructor(message, rawResponse, parseAttempt) {
16
+ super(message);
17
+ this.rawResponse = rawResponse;
18
+ this.parseAttempt = parseAttempt;
19
+ this.name = "PDEParseError";
20
+ }
21
+ }
22
+ exports.PDEParseError = PDEParseError;
23
+ function extractJsonString(responseText) {
24
+ const codeBlockMatch = responseText.match(/```(?:json)?\s*([\s\S]*?)```/);
25
+ if (codeBlockMatch)
26
+ return codeBlockMatch[1].trim();
27
+ const trimmed = responseText.trim();
28
+ if (trimmed.startsWith("{"))
29
+ return trimmed;
30
+ const firstBrace = responseText.indexOf("{");
31
+ const lastBrace = responseText.lastIndexOf("}");
32
+ if (firstBrace !== -1 && lastBrace > firstBrace) {
33
+ return responseText.substring(firstBrace, lastBrace + 1);
34
+ }
35
+ throw new PDEParseError("No JSON found in LLM response", responseText);
36
+ }
37
+ function normalizeResult(raw) {
38
+ const primary = raw.primary;
39
+ if (!primary || !primary.action || !primary.target) {
40
+ throw new PDEParseError("Missing or invalid 'primary' field", JSON.stringify(raw));
41
+ }
42
+ if (typeof primary.confidence !== "number")
43
+ primary.confidence = 0.8;
44
+ if (!primary.urgency)
45
+ primary.urgency = "session";
46
+ const ensureArray = (val) => Array.isArray(val) ? val : [];
47
+ const context = (raw.context || {});
48
+ const outputs = (raw.outputs || {});
49
+ const directions = (raw.directions || {});
50
+ return {
51
+ primary,
52
+ secondary: ensureArray(raw.secondary),
53
+ context: {
54
+ files_needed: ensureArray(context.files_needed),
55
+ tools_required: ensureArray(context.tools_required),
56
+ assumptions: ensureArray(context.assumptions),
57
+ },
58
+ outputs: {
59
+ artifacts: ensureArray(outputs.artifacts),
60
+ updates: ensureArray(outputs.updates),
61
+ communications: ensureArray(outputs.communications),
62
+ },
63
+ directions: {
64
+ east: ensureArray(directions.east),
65
+ south: ensureArray(directions.south),
66
+ west: ensureArray(directions.west),
67
+ north: ensureArray(directions.north),
68
+ },
69
+ actionStack: ensureArray(raw.actionStack),
70
+ ambiguities: ensureArray(raw.ambiguities),
71
+ };
72
+ }
73
+ function parseDecompositionResponse(responseText) {
74
+ const jsonString = extractJsonString(responseText);
75
+ let parsed;
76
+ try {
77
+ parsed = JSON.parse(jsonString);
78
+ }
79
+ catch (e) {
80
+ throw new PDEParseError(`Invalid JSON: ${e.message}`, responseText, jsonString);
81
+ }
82
+ return normalizeResult(parsed);
83
+ }
84
+ function actionStackToMarkdown(items) {
85
+ return items
86
+ .map((item) => `- [${item.completed ? "x" : " "}] ${item.text}${item.dependency ? ` (depends on: ${item.dependency})` : ""}`)
87
+ .join("\n");
88
+ }
89
+ //# sourceMappingURL=parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser.js","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAqEH,gEASC;AAED,sDAUC;AAtFD,MAAa,aAAc,SAAQ,KAAK;IAG7B;IACA;IAHT,YACE,OAAe,EACR,WAAmB,EACnB,YAAqB;QAE5B,KAAK,CAAC,OAAO,CAAC,CAAC;QAHR,gBAAW,GAAX,WAAW,CAAQ;QACnB,iBAAY,GAAZ,YAAY,CAAS;QAG5B,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC9B,CAAC;CACF;AATD,sCASC;AAED,SAAS,iBAAiB,CAAC,YAAoB;IAC7C,MAAM,cAAc,GAAG,YAAY,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAC1E,IAAI,cAAc;QAAE,OAAO,cAAc,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAEpD,MAAM,OAAO,GAAG,YAAY,CAAC,IAAI,EAAE,CAAC;IACpC,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,OAAO,CAAC;IAE5C,MAAM,UAAU,GAAG,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC7C,MAAM,SAAS,GAAG,YAAY,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IAChD,IAAI,UAAU,KAAK,CAAC,CAAC,IAAI,SAAS,GAAG,UAAU,EAAE,CAAC;QAChD,OAAO,YAAY,CAAC,SAAS,CAAC,UAAU,EAAE,SAAS,GAAG,CAAC,CAAC,CAAC;IAC3D,CAAC;IAED,MAAM,IAAI,aAAa,CAAC,+BAA+B,EAAE,YAAY,CAAC,CAAC;AACzE,CAAC;AAED,SAAS,eAAe,CAAC,GAA4B;IACnD,MAAM,OAAO,GAAG,GAAG,CAAC,OAAyC,CAAC;IAC9D,IAAI,CAAC,OAA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;YAClC,KAAK,EAAE,WAAW,CAAC,UAAU,CAAC,KAAK,CAAC;YACpC,IAAI,EAAE,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC;YAClC,KAAK,EAAE,WAAW,CAAC,UAAU,CAAC,KAAK,CAAC;SACrC;QACD,WAAW,EAAE,WAAW,CAAC,GAAG,CAAC,WAAW,CAAC;QACzC,WAAW,EAAE,WAAW,CAAC,GAAG,CAAC,WAAW,CAAC;KAC1C,CAAC;AACJ,CAAC;AAED,SAAgB,0BAA0B,CAAC,YAAoB;IAC7D,MAAM,UAAU,GAAG,iBAAiB,CAAC,YAAY,CAAC,CAAC;IACnD,IAAI,MAA+B,CAAC;IACpC,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAClC,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,IAAI,aAAa,CAAC,iBAAkB,CAAW,CAAC,OAAO,EAAE,EAAE,YAAY,EAAE,UAAU,CAAC,CAAC;IAC7F,CAAC;IACD,OAAO,eAAe,CAAC,MAAM,CAAC,CAAC;AACjC,CAAC;AAED,SAAgB,qBAAqB,CACnC,KAA+E;IAE/E,OAAO,KAAK;SACT,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACZ,MAAM,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,KAAK,IAAI,CAAC,IAAI,GAC5C,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,iBAAiB,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,EAC1D,EAAE,CACH;SACA,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * PDE Engine v2
3
+ *
4
+ * LLM-driven Prompt Decomposition Engine.
5
+ * Uses system prompts (from IAIP/lib/pde lineage) to instruct an LLM to produce
6
+ * structured DecompositionResult JSON, then parses and stores the result.
7
+ *
8
+ * The LLM call itself is NOT embedded here — the MCP tool receives the prompt,
9
+ * builds the system prompt, and the calling agent (Copilot, Gemini, mia-code)
10
+ * feeds it to their LLM. The engine then parses the LLM response.
11
+ *
12
+ * For direct decomposition without external LLM, use decomposeWithResponse()
13
+ * after getting the LLM response yourself.
14
+ */
15
+ import { type DecompositionResult, type DecompositionOptions, type StoredDecomposition } from './types.js';
16
+ import { PDEParseError } from './parser.js';
17
+ export declare class PdeEngine {
18
+ private defaultWorkdir;
19
+ constructor(workdir?: string);
20
+ /**
21
+ * Build the system prompt + user message for the calling LLM.
22
+ * The caller sends these to their LLM provider, then calls parseAndStore() with the response.
23
+ */
24
+ buildPrompt(prompt: string, options?: Partial<DecompositionOptions>): {
25
+ systemPrompt: string;
26
+ userMessage: string;
27
+ };
28
+ /**
29
+ * Parse an LLM response text into DecompositionResult and persist it.
30
+ */
31
+ parseAndStore(llmResponse: string, originalPrompt: string, options?: Partial<DecompositionOptions>, workdir?: string, parentPdeId?: string): StoredDecomposition;
32
+ /**
33
+ * Parse an LLM response text into DecompositionResult without storing.
34
+ */
35
+ parse(llmResponse: string): DecompositionResult;
36
+ /**
37
+ * Get a stored decomposition by ID.
38
+ */
39
+ get(id: string, workdir?: string): StoredDecomposition | null;
40
+ /**
41
+ * List stored decompositions.
42
+ */
43
+ list(workdir?: string, limit?: number): StoredDecomposition[];
44
+ /**
45
+ * List children of a specific parent PDE.
46
+ */
47
+ listChildren(parentId: string, workdir?: string): StoredDecomposition[];
48
+ /**
49
+ * Export a decomposition to markdown.
50
+ */
51
+ exportMarkdown(id: string, workdir?: string): string | null;
52
+ }
53
+ export { PDEParseError };
54
+ //# sourceMappingURL=pde-engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pde-engine.d.ts","sourceRoot":"","sources":["../src/pde-engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,m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