coaiajs 0.1.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/CLAUDE.md +56 -0
- package/KINSHIP.md +63 -0
- package/README.md +148 -0
- package/articles/academic/creative-orientation-vs-problem-solving.md +177 -0
- package/articles/academic/jsonl-knowledge-graphs-agent-memory.md +142 -0
- package/articles/academic/langfuse-observability-llm-pipelines.md +144 -0
- package/articles/academic/medicine-wheel-software-architecture.md +163 -0
- package/articles/academic/mmot-autonomous-agents.md +156 -0
- package/articles/academic/model-context-protocol-interagent.md +161 -0
- package/articles/academic/pde-prompt-decomposition.md +186 -0
- package/articles/academic/structural-tension-in-ai-agents.md +134 -0
- package/articles/reviews/mcp-protocol-design-review.md +170 -0
- package/articles/reviews/observability-ai-systems-review.md +176 -0
- package/articles/reviews/prompt-engineering-decomposition-review.md +184 -0
- package/articles/surveys/agent-orchestration-survey.md +186 -0
- package/articles/surveys/knowledge-graph-storage-survey.md +204 -0
- package/articles/surveys/structural-tension-methodology-survey.md +154 -0
- package/articles/technical/aws-sdk-v3-polly.md +270 -0
- package/articles/technical/commander-cli-framework.md +262 -0
- package/articles/technical/dotenv-config-patterns.md +360 -0
- package/articles/technical/ioredis-vs-redis.md +142 -0
- package/articles/technical/langfuse-js-sdk-vs-rest.md +191 -0
- package/articles/technical/mcp-sdk-typescript.md +291 -0
- package/articles/technical/octokit-github-api.md +293 -0
- package/articles/technical/openai-sdk-modern.md +231 -0
- package/articles/technical/yaml-parsing-node.md +266 -0
- package/articles/technical/zod-runtime-validation.md +212 -0
- package/dist/mcp/config.d.ts +14 -0
- package/dist/mcp/config.js +185 -0
- package/dist/mcp/server.d.ts +3 -0
- package/dist/mcp/server.js +324 -0
- package/dist/mcp/tools/coaiapy-tools.d.ts +8 -0
- package/dist/mcp/tools/coaiapy-tools.js +326 -0
- package/dist/mcp/tools/index.d.ts +3 -0
- package/dist/mcp/tools/index.js +3 -0
- package/dist/src/audio.d.ts +12 -0
- package/dist/src/audio.js +57 -0
- package/dist/src/cli-helpers.d.ts +9 -0
- package/dist/src/cli-helpers.js +78 -0
- package/dist/src/cli.d.ts +3 -0
- package/dist/src/cli.js +1086 -0
- package/dist/src/config.d.ts +15 -0
- package/dist/src/config.js +145 -0
- package/dist/src/environment.d.ts +44 -0
- package/dist/src/environment.js +146 -0
- package/dist/src/github.d.ts +47 -0
- package/dist/src/github.js +79 -0
- package/dist/src/langfuse/client.d.ts +30 -0
- package/dist/src/langfuse/client.js +75 -0
- package/dist/src/langfuse/comments.d.ts +16 -0
- package/dist/src/langfuse/comments.js +36 -0
- package/dist/src/langfuse/datasets.d.ts +19 -0
- package/dist/src/langfuse/datasets.js +140 -0
- package/dist/src/langfuse/index.d.ts +13 -0
- package/dist/src/langfuse/index.js +10 -0
- package/dist/src/langfuse/media.d.ts +11 -0
- package/dist/src/langfuse/media.js +167 -0
- package/dist/src/langfuse/observations.d.ts +18 -0
- package/dist/src/langfuse/observations.js +113 -0
- package/dist/src/langfuse/prompts.d.ts +14 -0
- package/dist/src/langfuse/prompts.js +127 -0
- package/dist/src/langfuse/scores.d.ts +54 -0
- package/dist/src/langfuse/scores.js +366 -0
- package/dist/src/langfuse/traces.d.ts +29 -0
- package/dist/src/langfuse/traces.js +225 -0
- package/dist/src/llm.d.ts +23 -0
- package/dist/src/llm.js +76 -0
- package/dist/src/narrative/graph-manager.d.ts +106 -0
- package/dist/src/narrative/graph-manager.js +915 -0
- package/dist/src/narrative/index.d.ts +9 -0
- package/dist/src/narrative/index.js +7 -0
- package/dist/src/narrative/markdown-export.d.ts +21 -0
- package/dist/src/narrative/markdown-export.js +383 -0
- package/dist/src/narrative/tool-definitions.d.ts +21 -0
- package/dist/src/narrative/tool-definitions.js +588 -0
- package/dist/src/narrative/tool-handlers.d.ts +11 -0
- package/dist/src/narrative/tool-handlers.js +462 -0
- package/dist/src/narrative/types.d.ts +2 -0
- package/dist/src/narrative/types.js +2 -0
- package/dist/src/narrative/validation.d.ts +29 -0
- package/dist/src/narrative/validation.js +144 -0
- package/dist/src/pde/index.d.ts +8 -0
- package/dist/src/pde/index.js +8 -0
- package/dist/src/pde/mcp-handlers.d.ts +7 -0
- package/dist/src/pde/mcp-handlers.js +300 -0
- package/dist/src/pde/mcp-tools.d.ts +15 -0
- package/dist/src/pde/mcp-tools.js +191 -0
- package/dist/src/pde/session-manager.d.ts +32 -0
- package/dist/src/pde/session-manager.js +205 -0
- package/dist/src/pde/stc-mapper.d.ts +26 -0
- package/dist/src/pde/stc-mapper.js +234 -0
- package/dist/src/pipeline/index.d.ts +2 -0
- package/dist/src/pipeline/index.js +3 -0
- package/dist/src/pipeline/template-engine.d.ts +20 -0
- package/dist/src/pipeline/template-engine.js +361 -0
- package/dist/src/planning/index.d.ts +7 -0
- package/dist/src/planning/index.js +7 -0
- package/dist/src/planning/mcp-handlers.d.ts +7 -0
- package/dist/src/planning/mcp-handlers.js +310 -0
- package/dist/src/planning/mcp-tools.d.ts +15 -0
- package/dist/src/planning/mcp-tools.js +145 -0
- package/dist/src/planning/plan-parser.d.ts +35 -0
- package/dist/src/planning/plan-parser.js +506 -0
- package/dist/src/redis.d.ts +21 -0
- package/dist/src/redis.js +78 -0
- package/dist/src/types.d.ts +244 -0
- package/dist/src/types.js +8 -0
- package/mcp/config.ts +196 -0
- package/mcp/server.ts +402 -0
- package/mcp/tools/coaiapy-tools.ts +364 -0
- package/mcp/tools/index.ts +4 -0
- package/package.json +52 -0
- package/rispecs/00-coaiajs-platform.spec.md +102 -0
- package/rispecs/01-core-config.spec.md +89 -0
- package/rispecs/02-redis-module.spec.md +62 -0
- package/rispecs/03-langfuse-module.spec.md +101 -0
- package/rispecs/04-narrative-engine.spec.md +185 -0
- package/rispecs/05-pde-engine.spec.md +112 -0
- package/rispecs/06-planning-engine.spec.md +128 -0
- package/rispecs/07-pipeline-templates.spec.md +97 -0
- package/rispecs/08-cli-interface.spec.md +134 -0
- package/rispecs/09-mcp-server.spec.md +140 -0
- package/rispecs/10-audio-module.spec.md +63 -0
- package/rispecs/KINSHIP.md +56 -0
- package/rispecs/README.md +100 -0
- package/src/audio.ts +76 -0
- package/src/cli-helpers.ts +86 -0
- package/src/cli.ts +1223 -0
- package/src/config.ts +172 -0
- package/src/environment.ts +171 -0
- package/src/github.ts +143 -0
- package/src/langfuse/client.ts +105 -0
- package/src/langfuse/comments.ts +52 -0
- package/src/langfuse/datasets.ts +178 -0
- package/src/langfuse/index.ts +33 -0
- package/src/langfuse/media.ts +193 -0
- package/src/langfuse/observations.ts +131 -0
- package/src/langfuse/prompts.ts +157 -0
- package/src/langfuse/scores.ts +456 -0
- package/src/langfuse/traces.ts +276 -0
- package/src/llm.ts +106 -0
- package/src/narrative/graph-manager.ts +1358 -0
- package/src/narrative/index.ts +32 -0
- package/src/narrative/markdown-export.ts +535 -0
- package/src/narrative/tool-definitions.ts +635 -0
- package/src/narrative/tool-handlers.ts +528 -0
- package/src/narrative/types.ts +9 -0
- package/src/narrative/validation.ts +179 -0
- package/src/pde/index.ts +8 -0
- package/src/pde/mcp-handlers.ts +359 -0
- package/src/pde/mcp-tools.ts +201 -0
- package/src/pde/session-manager.ts +248 -0
- package/src/pde/stc-mapper.ts +298 -0
- package/src/pipeline/index.ts +7 -0
- package/src/pipeline/template-engine.ts +398 -0
- package/src/planning/index.ts +13 -0
- package/src/planning/mcp-handlers.ts +369 -0
- package/src/planning/mcp-tools.ts +155 -0
- package/src/planning/plan-parser.ts +587 -0
- package/src/redis.ts +97 -0
- package/src/types.ts +280 -0
- package/tsconfig.json +26 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Planning module — Plan Parser + Plan→STC transformation
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export {
|
|
6
|
+
parsePlan,
|
|
7
|
+
parsePlanContent,
|
|
8
|
+
planToSTC,
|
|
9
|
+
exportToJSONL,
|
|
10
|
+
decompositionResultToPlan,
|
|
11
|
+
} from './plan-parser.js';
|
|
12
|
+
export { PLANNING_MCP_TOOLS } from './mcp-tools.js';
|
|
13
|
+
export { handlePlanningTool } from './mcp-handlers.js';
|
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Planning MCP tool dispatch — handles each tool by calling plan-parser functions
|
|
3
|
+
* Ported from coaia-planning/src/index.ts handler logic
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { promises as fs, readFileSync, existsSync } from 'fs';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
import type { McpToolResult, DecompositionResult, StoredDecomposition } from '../types.js';
|
|
9
|
+
import {
|
|
10
|
+
parsePlan,
|
|
11
|
+
parsePlanContent,
|
|
12
|
+
planToSTC,
|
|
13
|
+
exportToJSONL,
|
|
14
|
+
decompositionResultToPlan,
|
|
15
|
+
} from './plan-parser.js';
|
|
16
|
+
import type { StructuralTensionPlan } from '../types.js';
|
|
17
|
+
|
|
18
|
+
// Cache for parsed plans
|
|
19
|
+
const planCache = new Map<string, StructuralTensionPlan>();
|
|
20
|
+
|
|
21
|
+
function getCachedOrParse(planPath: string): Promise<StructuralTensionPlan> {
|
|
22
|
+
if (planCache.has(planPath)) {
|
|
23
|
+
return Promise.resolve(planCache.get(planPath)!);
|
|
24
|
+
}
|
|
25
|
+
return parsePlan(planPath).then(parsed => {
|
|
26
|
+
planCache.set(planPath, parsed);
|
|
27
|
+
return parsed;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface ChartEntity {
|
|
32
|
+
name: string;
|
|
33
|
+
entityType: string;
|
|
34
|
+
observations: string[];
|
|
35
|
+
metadata?: Record<string, unknown>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function loadExistingCharts(chartsPath: string): ChartEntity[] {
|
|
39
|
+
try {
|
|
40
|
+
if (!existsSync(chartsPath)) return [];
|
|
41
|
+
const content = readFileSync(chartsPath, 'utf-8');
|
|
42
|
+
return content
|
|
43
|
+
.split('\n')
|
|
44
|
+
.filter((line: string) => line.trim())
|
|
45
|
+
.map((line: string) => JSON.parse(line) as ChartEntity);
|
|
46
|
+
} catch {
|
|
47
|
+
return [];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface PlanChange {
|
|
52
|
+
type: 'new_action' | 'completed_action' | 'modified_outcome' | 'modified_reality';
|
|
53
|
+
description: string;
|
|
54
|
+
details: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function detectPlanChanges(parsed: StructuralTensionPlan, existingCharts: ChartEntity[]): PlanChange[] {
|
|
58
|
+
const changes: PlanChange[] = [];
|
|
59
|
+
const existingActions = existingCharts
|
|
60
|
+
.filter(c => c.entityType === 'action_step')
|
|
61
|
+
.map(c => c.observations[0]);
|
|
62
|
+
|
|
63
|
+
for (const step of parsed.actionSteps) {
|
|
64
|
+
if (!existingActions.includes(step.content)) {
|
|
65
|
+
changes.push({
|
|
66
|
+
type: 'new_action',
|
|
67
|
+
description: step.content,
|
|
68
|
+
details: `New action step detected: ${step.content}`,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return changes;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function chartsToPlan(charts: ChartEntity[]): string {
|
|
77
|
+
let md = '';
|
|
78
|
+
|
|
79
|
+
const chartEntity = charts.find(c => c.entityType === 'structural_tension_chart');
|
|
80
|
+
if (chartEntity) {
|
|
81
|
+
const title = chartEntity.name.replace(/_chart$/, '').replace(/_/g, ' ');
|
|
82
|
+
md += `# ${title}\n\n`;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const desiredOutcome = charts.find(c => c.entityType === 'desired_outcome');
|
|
86
|
+
if (desiredOutcome) {
|
|
87
|
+
md += `## Desired Outcome\n\n${desiredOutcome.observations[0]}\n\n`;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const currentReality = charts.find(c => c.entityType === 'current_reality');
|
|
91
|
+
if (currentReality) {
|
|
92
|
+
md += `## Current Reality\n\n${currentReality.observations[0]}\n\n`;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const actionSteps = charts
|
|
96
|
+
.filter(c => c.entityType === 'action_step')
|
|
97
|
+
.sort((a, b) => ((a.metadata?.order as number) || 0) - ((b.metadata?.order as number) || 0));
|
|
98
|
+
|
|
99
|
+
if (actionSteps.length > 0) {
|
|
100
|
+
md += `## Action Steps\n\n`;
|
|
101
|
+
for (const step of actionSteps) {
|
|
102
|
+
const completed = step.metadata?.completionStatus ? '[x]' : '[ ]';
|
|
103
|
+
md += `- ${completed} ${step.observations[0]}\n`;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return md;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export async function handlePlanningTool(
|
|
111
|
+
name: string,
|
|
112
|
+
args: Record<string, unknown>
|
|
113
|
+
): Promise<McpToolResult> {
|
|
114
|
+
try {
|
|
115
|
+
switch (name) {
|
|
116
|
+
case 'parse_plan_structural': {
|
|
117
|
+
let parsed: StructuralTensionPlan;
|
|
118
|
+
|
|
119
|
+
if (args.planPath) {
|
|
120
|
+
const planPath = args.planPath as string;
|
|
121
|
+
parsed = await parsePlan(planPath);
|
|
122
|
+
planCache.set(planPath, parsed);
|
|
123
|
+
} else if (args.planContent) {
|
|
124
|
+
parsed = parsePlanContent(args.planContent as string);
|
|
125
|
+
} else {
|
|
126
|
+
throw new Error('Either planPath or planContent must be provided');
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return {
|
|
130
|
+
content: [{
|
|
131
|
+
type: 'text',
|
|
132
|
+
text: JSON.stringify({
|
|
133
|
+
success: true,
|
|
134
|
+
structuralAnalysis: {
|
|
135
|
+
title: parsed.title,
|
|
136
|
+
filePath: parsed.filePath,
|
|
137
|
+
desiredOutcome: parsed.desiredOutcome ? {
|
|
138
|
+
content: parsed.desiredOutcome.content,
|
|
139
|
+
confidence: parsed.desiredOutcome.confidence,
|
|
140
|
+
} : null,
|
|
141
|
+
currentReality: parsed.currentReality ? {
|
|
142
|
+
content: parsed.currentReality.content,
|
|
143
|
+
confidence: parsed.currentReality.confidence,
|
|
144
|
+
} : null,
|
|
145
|
+
actionSteps: parsed.actionSteps.map(s => ({
|
|
146
|
+
content: s.content,
|
|
147
|
+
confidence: s.confidence,
|
|
148
|
+
canTelescope: !!s.telescopesInto,
|
|
149
|
+
})),
|
|
150
|
+
observations: parsed.observations,
|
|
151
|
+
},
|
|
152
|
+
}, null, 2),
|
|
153
|
+
}],
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
case 'plan_to_stc': {
|
|
158
|
+
const planPath = args.planPath as string;
|
|
159
|
+
const outputPath = (args.outputPath as string) ||
|
|
160
|
+
path.join(process.cwd(), `${path.basename(planPath, '.md')}.stc.jsonl`);
|
|
161
|
+
|
|
162
|
+
const parsed = await getCachedOrParse(planPath);
|
|
163
|
+
|
|
164
|
+
// Override current reality if provided
|
|
165
|
+
if (args.currentReality && parsed.currentReality) {
|
|
166
|
+
parsed.currentReality.content = args.currentReality as string;
|
|
167
|
+
} else if (args.currentReality) {
|
|
168
|
+
parsed.currentReality = {
|
|
169
|
+
type: 'current_reality',
|
|
170
|
+
content: args.currentReality as string,
|
|
171
|
+
confidence: 1.0,
|
|
172
|
+
sourceLines: { start: 0, end: 0 },
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const stc = planToSTC(parsed);
|
|
177
|
+
const jsonl = exportToJSONL(stc);
|
|
178
|
+
|
|
179
|
+
await fs.writeFile(outputPath, jsonl + '\n');
|
|
180
|
+
|
|
181
|
+
return {
|
|
182
|
+
content: [{
|
|
183
|
+
type: 'text',
|
|
184
|
+
text: JSON.stringify({
|
|
185
|
+
success: true,
|
|
186
|
+
chartCreated: {
|
|
187
|
+
title: parsed.title,
|
|
188
|
+
entitiesCount: stc.entities.length,
|
|
189
|
+
relationsCount: stc.relations.length,
|
|
190
|
+
outputPath,
|
|
191
|
+
hasDesiredOutcome: !!parsed.desiredOutcome,
|
|
192
|
+
hasCurrentReality: !!parsed.currentReality,
|
|
193
|
+
actionStepsCount: parsed.actionSteps.length,
|
|
194
|
+
telescopedCount: parsed.actionSteps.filter(s => s.telescopesInto).length,
|
|
195
|
+
},
|
|
196
|
+
}, null, 2),
|
|
197
|
+
}],
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
case 'sync_plan_to_chart': {
|
|
202
|
+
const planPath = args.planPath as string;
|
|
203
|
+
const chartsPath = args.chartsPath as string;
|
|
204
|
+
const dryRun = args.dryRun as boolean || false;
|
|
205
|
+
|
|
206
|
+
const parsed = await getCachedOrParse(planPath);
|
|
207
|
+
const existingCharts = loadExistingCharts(chartsPath);
|
|
208
|
+
const changes = detectPlanChanges(parsed, existingCharts);
|
|
209
|
+
|
|
210
|
+
if (dryRun) {
|
|
211
|
+
return {
|
|
212
|
+
content: [{
|
|
213
|
+
type: 'text',
|
|
214
|
+
text: JSON.stringify({ dryRun: true, changes }, null, 2),
|
|
215
|
+
}],
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// Apply changes: regenerate STC and write
|
|
220
|
+
const stc = planToSTC(parsed);
|
|
221
|
+
const jsonl = exportToJSONL(stc);
|
|
222
|
+
await fs.writeFile(chartsPath, jsonl + '\n');
|
|
223
|
+
|
|
224
|
+
return {
|
|
225
|
+
content: [{
|
|
226
|
+
type: 'text',
|
|
227
|
+
text: JSON.stringify({ success: true, changesApplied: changes }, null, 2),
|
|
228
|
+
}],
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
case 'sync_chart_to_plan': {
|
|
233
|
+
const chartsPath = args.chartsPath as string;
|
|
234
|
+
const planPath = args.planPath as string;
|
|
235
|
+
const dryRun = args.dryRun as boolean || false;
|
|
236
|
+
|
|
237
|
+
const charts = loadExistingCharts(chartsPath);
|
|
238
|
+
const planContent = chartsToPlan(charts);
|
|
239
|
+
|
|
240
|
+
if (dryRun) {
|
|
241
|
+
return {
|
|
242
|
+
content: [{
|
|
243
|
+
type: 'text',
|
|
244
|
+
text: JSON.stringify({ dryRun: true, proposedPlanContent: planContent }, null, 2),
|
|
245
|
+
}],
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
await fs.writeFile(planPath, planContent);
|
|
250
|
+
|
|
251
|
+
return {
|
|
252
|
+
content: [{
|
|
253
|
+
type: 'text',
|
|
254
|
+
text: JSON.stringify({ success: true, planUpdated: planPath }, null, 2),
|
|
255
|
+
}],
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
case 'create_plan_trace': {
|
|
260
|
+
const planPath = args.planPath as string;
|
|
261
|
+
const chartsPath = args.chartsPath as string;
|
|
262
|
+
const sessionId = args.sessionId as string | undefined;
|
|
263
|
+
const metadata = args.metadata as Record<string, unknown> || {};
|
|
264
|
+
|
|
265
|
+
const parsed = await getCachedOrParse(planPath);
|
|
266
|
+
const charts = loadExistingCharts(chartsPath);
|
|
267
|
+
|
|
268
|
+
const traceData = {
|
|
269
|
+
trace_id: `plan-${Date.now()}`,
|
|
270
|
+
name: `📋 Plan→STC: ${parsed.title}`,
|
|
271
|
+
session_id: sessionId,
|
|
272
|
+
input_data: {
|
|
273
|
+
plan_title: parsed.title,
|
|
274
|
+
plan_path: planPath,
|
|
275
|
+
desired_outcome: parsed.desiredOutcome?.content,
|
|
276
|
+
current_reality: parsed.currentReality?.content,
|
|
277
|
+
action_steps: parsed.actionSteps.map(s => s.content),
|
|
278
|
+
},
|
|
279
|
+
output_data: {
|
|
280
|
+
charts_created: charts.length,
|
|
281
|
+
charts_path: chartsPath,
|
|
282
|
+
},
|
|
283
|
+
metadata: {
|
|
284
|
+
...metadata,
|
|
285
|
+
transformation_timestamp: new Date().toISOString(),
|
|
286
|
+
tool: 'coaia-planning',
|
|
287
|
+
},
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
return {
|
|
291
|
+
content: [{
|
|
292
|
+
type: 'text',
|
|
293
|
+
text: JSON.stringify({
|
|
294
|
+
success: true,
|
|
295
|
+
traceData,
|
|
296
|
+
note: 'Use Langfuse MCP to create trace with this data',
|
|
297
|
+
}, null, 2),
|
|
298
|
+
}],
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
case 'pde_to_plan': {
|
|
303
|
+
const workdir = (args.workdir as string) || process.cwd();
|
|
304
|
+
let decomposition: DecompositionResult;
|
|
305
|
+
let originalPrompt: string | undefined = args.original_prompt as string | undefined;
|
|
306
|
+
|
|
307
|
+
if (args.pde_id) {
|
|
308
|
+
const pdeId = args.pde_id as string;
|
|
309
|
+
const pdePath = path.join(workdir, '.pde', `${pdeId}.json`);
|
|
310
|
+
|
|
311
|
+
let data: string;
|
|
312
|
+
try {
|
|
313
|
+
data = await fs.readFile(pdePath, 'utf-8');
|
|
314
|
+
} catch {
|
|
315
|
+
throw new Error(`PDE decomposition not found: ${pdePath}`);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const stored = JSON.parse(data) as StoredDecomposition;
|
|
319
|
+
decomposition = stored.result;
|
|
320
|
+
originalPrompt = originalPrompt || stored.prompt;
|
|
321
|
+
} else if (args.decomposition_result) {
|
|
322
|
+
decomposition = args.decomposition_result as DecompositionResult;
|
|
323
|
+
} else {
|
|
324
|
+
throw new Error('Either pde_id or decomposition_result must be provided');
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const stc = decompositionResultToPlan(decomposition, originalPrompt);
|
|
328
|
+
const jsonl = exportToJSONL(stc);
|
|
329
|
+
|
|
330
|
+
if (args.outputPath) {
|
|
331
|
+
const outPath = path.isAbsolute(args.outputPath as string)
|
|
332
|
+
? args.outputPath as string
|
|
333
|
+
: path.resolve(args.outputPath as string);
|
|
334
|
+
await fs.writeFile(outPath, jsonl + '\n');
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
return {
|
|
338
|
+
content: [{
|
|
339
|
+
type: 'text',
|
|
340
|
+
text: JSON.stringify({
|
|
341
|
+
success: true,
|
|
342
|
+
chartCreated: {
|
|
343
|
+
entitiesCount: stc.entities.length,
|
|
344
|
+
relationsCount: stc.relations.length,
|
|
345
|
+
primaryIntent: `${decomposition.primary.action}: ${decomposition.primary.target}`,
|
|
346
|
+
actionStepsCount: decomposition.actionStack.length,
|
|
347
|
+
ambiguitiesCount: decomposition.ambiguities.length,
|
|
348
|
+
outputPath: args.outputPath || null,
|
|
349
|
+
},
|
|
350
|
+
jsonl,
|
|
351
|
+
}, null, 2),
|
|
352
|
+
}],
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
default:
|
|
357
|
+
throw new Error(`Unknown planning tool: ${name}`);
|
|
358
|
+
}
|
|
359
|
+
} catch (error: unknown) {
|
|
360
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
361
|
+
return {
|
|
362
|
+
content: [{
|
|
363
|
+
type: 'text',
|
|
364
|
+
text: `Error: ${errorMessage}`,
|
|
365
|
+
}],
|
|
366
|
+
isError: true,
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP tool definitions for Planning module (6 tools)
|
|
3
|
+
* Ported from coaia-planning/src/tools/index.ts
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface McpToolDef {
|
|
7
|
+
name: string;
|
|
8
|
+
description: string;
|
|
9
|
+
inputSchema: {
|
|
10
|
+
type: 'object';
|
|
11
|
+
properties: Record<string, unknown>;
|
|
12
|
+
required?: string[];
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const PLANNING_MCP_TOOLS: McpToolDef[] = [
|
|
17
|
+
{
|
|
18
|
+
name: 'parse_plan_structural',
|
|
19
|
+
description: 'Parse a Claude plan as structural tension chart. Extracts desired outcome, current reality, and action steps (which telescope into sub-charts). Returns confidence scores.',
|
|
20
|
+
inputSchema: {
|
|
21
|
+
type: 'object',
|
|
22
|
+
properties: {
|
|
23
|
+
planPath: {
|
|
24
|
+
type: 'string',
|
|
25
|
+
description: 'Path to the Claude plan markdown file',
|
|
26
|
+
},
|
|
27
|
+
planContent: {
|
|
28
|
+
type: 'string',
|
|
29
|
+
description: 'Alternative: raw markdown content (if path not provided)',
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: 'plan_to_stc',
|
|
36
|
+
description: 'Convert plan to structural tension chart (JSONL). Action steps become telescoped STCs with their own desired outcome/current reality.',
|
|
37
|
+
inputSchema: {
|
|
38
|
+
type: 'object',
|
|
39
|
+
properties: {
|
|
40
|
+
planPath: {
|
|
41
|
+
type: 'string',
|
|
42
|
+
description: 'Path to the Claude plan markdown file',
|
|
43
|
+
},
|
|
44
|
+
currentReality: {
|
|
45
|
+
type: 'string',
|
|
46
|
+
description: 'Override: provide current reality if not detected in plan',
|
|
47
|
+
},
|
|
48
|
+
outputPath: {
|
|
49
|
+
type: 'string',
|
|
50
|
+
description: 'Path to write the STC JSONL (default: <planname>.stc.jsonl)',
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
required: ['planPath'],
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: 'sync_plan_to_chart',
|
|
58
|
+
description: 'Plan → Chart sync. When plan changes, update the structural tension chart.',
|
|
59
|
+
inputSchema: {
|
|
60
|
+
type: 'object',
|
|
61
|
+
properties: {
|
|
62
|
+
planPath: {
|
|
63
|
+
type: 'string',
|
|
64
|
+
description: 'Path to the Claude plan markdown file',
|
|
65
|
+
},
|
|
66
|
+
chartsPath: {
|
|
67
|
+
type: 'string',
|
|
68
|
+
description: 'Path to the charts JSONL file',
|
|
69
|
+
},
|
|
70
|
+
dryRun: {
|
|
71
|
+
type: 'boolean',
|
|
72
|
+
description: 'If true, show changes without applying',
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
required: ['planPath', 'chartsPath'],
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: 'sync_chart_to_plan',
|
|
80
|
+
description: 'Chart → Plan sync. When agents modify chart (observations, completions), regenerate plan markdown.',
|
|
81
|
+
inputSchema: {
|
|
82
|
+
type: 'object',
|
|
83
|
+
properties: {
|
|
84
|
+
chartsPath: {
|
|
85
|
+
type: 'string',
|
|
86
|
+
description: 'Path to the charts JSONL file',
|
|
87
|
+
},
|
|
88
|
+
planPath: {
|
|
89
|
+
type: 'string',
|
|
90
|
+
description: 'Path to write the updated plan markdown',
|
|
91
|
+
},
|
|
92
|
+
dryRun: {
|
|
93
|
+
type: 'boolean',
|
|
94
|
+
description: 'If true, show proposed plan without writing',
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
required: ['chartsPath', 'planPath'],
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
name: 'create_plan_trace',
|
|
102
|
+
description: 'Generate Langfuse trace data for plan→STC transformation.',
|
|
103
|
+
inputSchema: {
|
|
104
|
+
type: 'object',
|
|
105
|
+
properties: {
|
|
106
|
+
planPath: {
|
|
107
|
+
type: 'string',
|
|
108
|
+
description: 'Path to the source plan',
|
|
109
|
+
},
|
|
110
|
+
chartsPath: {
|
|
111
|
+
type: 'string',
|
|
112
|
+
description: 'Path to generated charts',
|
|
113
|
+
},
|
|
114
|
+
sessionId: {
|
|
115
|
+
type: 'string',
|
|
116
|
+
description: 'Optional Langfuse session ID',
|
|
117
|
+
},
|
|
118
|
+
metadata: {
|
|
119
|
+
type: 'object',
|
|
120
|
+
description: 'Additional trace metadata',
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
required: ['planPath', 'chartsPath'],
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
name: 'pde_to_plan',
|
|
128
|
+
description: 'Convert a PDE DecompositionResult to a structural tension chart (JSONL). Takes pre-decomposed PDE output and produces coaia-narrative compatible entities and relations.',
|
|
129
|
+
inputSchema: {
|
|
130
|
+
type: 'object',
|
|
131
|
+
properties: {
|
|
132
|
+
pde_id: {
|
|
133
|
+
type: 'string',
|
|
134
|
+
description: 'ID of a stored PDE decomposition in .pde/ folder',
|
|
135
|
+
},
|
|
136
|
+
decomposition_result: {
|
|
137
|
+
type: 'object',
|
|
138
|
+
description: 'Alternative: provide DecompositionResult JSON directly',
|
|
139
|
+
},
|
|
140
|
+
original_prompt: {
|
|
141
|
+
type: 'string',
|
|
142
|
+
description: 'The original prompt (required if providing decomposition_result)',
|
|
143
|
+
},
|
|
144
|
+
outputPath: {
|
|
145
|
+
type: 'string',
|
|
146
|
+
description: 'Path to write the STC JSONL output',
|
|
147
|
+
},
|
|
148
|
+
workdir: {
|
|
149
|
+
type: 'string',
|
|
150
|
+
description: 'Working directory containing .pde/ folder (default: cwd)',
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
];
|