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,101 @@
|
|
|
1
|
+
# 03 — Langfuse Module
|
|
2
|
+
|
|
3
|
+
> Full Langfuse observability integration via REST API.
|
|
4
|
+
|
|
5
|
+
## Desired Outcome
|
|
6
|
+
|
|
7
|
+
A comprehensive Langfuse client covering traces, observations, prompts, datasets, scores, score configs, comments, media, and projects — enabling full observability of CoAiA agent sessions through a clean TypeScript API.
|
|
8
|
+
|
|
9
|
+
## Structural Tension
|
|
10
|
+
|
|
11
|
+
**Current Reality:**
|
|
12
|
+
- `src/langfuse/` directory exists but is empty
|
|
13
|
+
- Types defined in `src/types.ts`: `ScoreCategory`, `ScoreConfig`
|
|
14
|
+
- coaiapy's `cofuse.py` is 4,480 lines covering: traces, observations (spans/generations/events), prompts, datasets, scores, score configs, comments, media, projects
|
|
15
|
+
- cofuse.py uses raw `requests` library against Langfuse REST API
|
|
16
|
+
- No MCP tools exist for Langfuse in any parent project
|
|
17
|
+
|
|
18
|
+
**Desired Outcome:**
|
|
19
|
+
TypeScript Langfuse client with:
|
|
20
|
+
- All REST endpoints from cofuse.py ported to `fetch`-based client
|
|
21
|
+
- Lazy client initialization (no connection until first call)
|
|
22
|
+
- Type-safe request/response with Zod validation
|
|
23
|
+
- 8 MCP tools for interactive Langfuse operations
|
|
24
|
+
- Support for both self-hosted and cloud Langfuse instances
|
|
25
|
+
|
|
26
|
+
## API Surface
|
|
27
|
+
|
|
28
|
+
### Traces
|
|
29
|
+
```typescript
|
|
30
|
+
listTraces(params?: { page?, limit?, userId?, name?, tags? }): Promise<Trace[]>
|
|
31
|
+
getTrace(traceId: string): Promise<Trace>
|
|
32
|
+
createTrace(input: CreateTraceInput): Promise<Trace>
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Observations
|
|
36
|
+
```typescript
|
|
37
|
+
listObservations(params?: { traceId?, type?, name? }): Promise<Observation[]>
|
|
38
|
+
getObservation(observationId: string): Promise<Observation>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Prompts
|
|
42
|
+
```typescript
|
|
43
|
+
listPrompts(params?: { name?, label? }): Promise<Prompt[]>
|
|
44
|
+
getPrompt(name: string, version?: number): Promise<Prompt>
|
|
45
|
+
createPrompt(input: CreatePromptInput): Promise<Prompt>
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Datasets
|
|
49
|
+
```typescript
|
|
50
|
+
listDatasets(): Promise<Dataset[]>
|
|
51
|
+
getDataset(name: string): Promise<Dataset>
|
|
52
|
+
createDataset(input: CreateDatasetInput): Promise<Dataset>
|
|
53
|
+
listDatasetItems(datasetName: string): Promise<DatasetItem[]>
|
|
54
|
+
createDatasetItem(input: CreateDatasetItemInput): Promise<DatasetItem>
|
|
55
|
+
listDatasetRuns(datasetName: string): Promise<DatasetRun[]>
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Scores
|
|
59
|
+
```typescript
|
|
60
|
+
listScores(params?: { traceId?, name?, configId? }): Promise<Score[]>
|
|
61
|
+
createScore(input: CreateScoreInput): Promise<Score>
|
|
62
|
+
listScoreConfigs(): Promise<ScoreConfig[]>
|
|
63
|
+
createScoreConfig(input: CreateScoreConfigInput): Promise<ScoreConfig>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Comments
|
|
67
|
+
```typescript
|
|
68
|
+
listComments(params?: { traceId?, objectType? }): Promise<Comment[]>
|
|
69
|
+
createComment(input: CreateCommentInput): Promise<Comment>
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Media & Projects
|
|
73
|
+
```typescript
|
|
74
|
+
getMedia(mediaId: string): Promise<Media>
|
|
75
|
+
listProjects(): Promise<Project[]>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## MCP Tools (8)
|
|
79
|
+
|
|
80
|
+
| Tool | Description |
|
|
81
|
+
|------|-------------|
|
|
82
|
+
| `langfuse_list_traces` | List traces with filters |
|
|
83
|
+
| `langfuse_get_trace` | Get trace details with observations |
|
|
84
|
+
| `langfuse_list_prompts` | List prompt templates |
|
|
85
|
+
| `langfuse_get_prompt` | Get specific prompt by name/version |
|
|
86
|
+
| `langfuse_list_datasets` | List available datasets |
|
|
87
|
+
| `langfuse_list_scores` | List scores with filters |
|
|
88
|
+
| `langfuse_create_score` | Score a trace or observation |
|
|
89
|
+
| `langfuse_list_score_configs` | List scoring configurations |
|
|
90
|
+
|
|
91
|
+
## Authentication
|
|
92
|
+
|
|
93
|
+
Langfuse REST API uses Basic auth: `base64(publicKey:secretKey)`. Config provides `langfuse_public_key`, `langfuse_secret_key`, and `langfuse_host` (default: `https://cloud.langfuse.com`).
|
|
94
|
+
|
|
95
|
+
## Quality Criteria
|
|
96
|
+
|
|
97
|
+
- ✅ Every endpoint in cofuse.py has a TypeScript equivalent
|
|
98
|
+
- ✅ Pagination handled transparently (auto-page through results when needed)
|
|
99
|
+
- ✅ Auth failure returns clear error, not cryptic 401
|
|
100
|
+
- ✅ Missing credentials detected at call time, not import time
|
|
101
|
+
- ✅ Response types validated with Zod before returning
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
# 04 — Narrative Engine
|
|
2
|
+
|
|
3
|
+
> JSONL knowledge graph with structural tension charts, narrative beats, and MMOT self-evaluation.
|
|
4
|
+
|
|
5
|
+
This is the most complex module — the heart of CoAiA's creative advancement system.
|
|
6
|
+
|
|
7
|
+
## Desired Outcome
|
|
8
|
+
|
|
9
|
+
A KnowledgeGraphManager that provides full CRUD for entities and relations stored in append-only JSONL, implements the complete structural tension chart lifecycle (create → telescope → advance → complete), supports narrative beat creation with multi-universe perspectives, and enables MMOT autonomous self-evaluation — all through a single TypeScript class.
|
|
10
|
+
|
|
11
|
+
## Structural Tension
|
|
12
|
+
|
|
13
|
+
**Current Reality:**
|
|
14
|
+
- `src/narrative/` directory exists but is empty
|
|
15
|
+
- Types fully defined in `src/types.ts`: `Entity`, `EntityMetadata`, `Relation`, `RelationMetadata`, `KnowledgeGraph`, `McpToolResult`
|
|
16
|
+
- coaia-narrative v0.12.0 has a working implementation:
|
|
17
|
+
- `graph-manager.ts` (1,294 lines) — the core engine
|
|
18
|
+
- `tool-definitions.ts` — 27 MCP tool schemas
|
|
19
|
+
- `tool-handlers.ts` — tool implementation connecting MCP to graph manager
|
|
20
|
+
- `tool-groups.ts` — tool filtering by group (STC_TOOLS, KG_TOOLS, CORE_TOOLS)
|
|
21
|
+
- `types.ts` — type definitions (absorbed into coaiajs `src/types.ts`)
|
|
22
|
+
- coaia-narrative rispecs are the most mature (15 specs) — detailed behavioral specifications exist for every capability
|
|
23
|
+
|
|
24
|
+
**Desired Outcome:**
|
|
25
|
+
Narrative engine in `src/narrative/` that:
|
|
26
|
+
- Implements `KnowledgeGraphManager` with identical behavior to coaia-narrative
|
|
27
|
+
- Stores all data in append-only JSONL format
|
|
28
|
+
- Manages the full STC lifecycle
|
|
29
|
+
- Supports narrative beats with dramatic typing and multi-universe perspectives
|
|
30
|
+
- Enables MMOT evaluation with Elements of Performance
|
|
31
|
+
- Exposes 28 MCP tools (27 from coaia-narrative + 1 new)
|
|
32
|
+
|
|
33
|
+
## Core Class: KnowledgeGraphManager
|
|
34
|
+
|
|
35
|
+
### JSONL Storage
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
class KnowledgeGraphManager {
|
|
39
|
+
constructor(memoryFilePath: string)
|
|
40
|
+
loadGraph(): Promise<KnowledgeGraph>
|
|
41
|
+
saveGraph(): Promise<void>
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
The JSONL file is the single source of truth. Each line is a JSON event:
|
|
46
|
+
- `{"type":"entity","data":{...}}` — entity creation/update
|
|
47
|
+
- `{"type":"relation","data":{...}}` — relation creation
|
|
48
|
+
- `{"type":"observation","data":{...}}` — observation added to entity
|
|
49
|
+
|
|
50
|
+
On load: replay all events to reconstruct in-memory graph. On write: append new events. This append-only design prevents corruption from interrupted writes.
|
|
51
|
+
|
|
52
|
+
### Knowledge Graph CRUD
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
// Entities
|
|
56
|
+
createEntities(entities: Entity[]): Promise<Entity[]>
|
|
57
|
+
deleteEntities(entityNames: string[]): Promise<void>
|
|
58
|
+
addObservations(observations: {entityName: string, contents: string[]}[]): Promise<void>
|
|
59
|
+
deleteObservations(deletions: {entityName: string, observations: string[]}[]): Promise<void>
|
|
60
|
+
|
|
61
|
+
// Relations
|
|
62
|
+
createRelations(relations: Relation[]): Promise<Relation[]>
|
|
63
|
+
deleteRelations(relations: {from: string, to: string, relationType: string}[]): Promise<void>
|
|
64
|
+
|
|
65
|
+
// Queries
|
|
66
|
+
searchNodes(query: string): Promise<Entity[]>
|
|
67
|
+
openNodes(names: string[]): Promise<Entity[]>
|
|
68
|
+
readGraph(): Promise<KnowledgeGraph>
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Structural Tension Chart Lifecycle
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
CREATE → TELESCOPE → ADVANCE → COMPLETE
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
**Create:** Desired outcome + current reality + optional action steps → chart entity + related entities + auto-distributed due dates. Validates creative orientation (no problem-solving language) and delayed resolution (no "ready to begin" in current reality).
|
|
78
|
+
|
|
79
|
+
**Telescope:** Break an action step into a sub-chart with its own desired outcome, current reality, and action steps. Inherits due date constraints from parent.
|
|
80
|
+
|
|
81
|
+
**Advance:** Mark action step complete → completion flows into parent current reality as fact. Update progress without completion via progress observations.
|
|
82
|
+
|
|
83
|
+
**Complete:** All action steps done → chart marked complete. Phase transitions: germination → assimilation → completion.
|
|
84
|
+
|
|
85
|
+
### STC Tools
|
|
86
|
+
|
|
87
|
+
| Tool | Purpose |
|
|
88
|
+
|------|---------|
|
|
89
|
+
| `create_structural_tension_chart` | Create master chart |
|
|
90
|
+
| `list_active_charts` | Overview all charts with progress |
|
|
91
|
+
| `get_chart` | Full chart details |
|
|
92
|
+
| `get_chart_progress` | Progress metrics and next action |
|
|
93
|
+
| `manage_action_step` | Add or telescope action steps (unified) |
|
|
94
|
+
| `mark_action_complete` | Complete an action, flow to parent reality |
|
|
95
|
+
| `update_action_progress` | Track progress without completion |
|
|
96
|
+
| `update_current_reality` | Add observations to current reality |
|
|
97
|
+
| `update_desired_outcome` | Modify chart goal |
|
|
98
|
+
| `get_action_step` | Get telescoped action step details |
|
|
99
|
+
| `remove_action_step` | Delete action step from chart |
|
|
100
|
+
|
|
101
|
+
### Narrative Beat System
|
|
102
|
+
|
|
103
|
+
Narrative beats document story progression within a structural tension chart. Each beat has:
|
|
104
|
+
- **Act** (1, 2, or 3) — three-act dramatic structure
|
|
105
|
+
- **Dramatic type** — Exposition, Rising Action, Climax, Resolution, Discovery, Crisis, Integration
|
|
106
|
+
- **Universes** — perspectives: Engineer World, Ceremony World, Story Engine World
|
|
107
|
+
- **Prose** — character-level narrative
|
|
108
|
+
- **Lessons** — extracted insights
|
|
109
|
+
|
|
110
|
+
| Tool | Purpose |
|
|
111
|
+
|------|---------|
|
|
112
|
+
| `create_narrative_beat` | Create dramatic beat within chart |
|
|
113
|
+
| `telescope_narrative_beat` | Break beat into sub-beats |
|
|
114
|
+
| `list_narrative_beats` | List beats for a chart |
|
|
115
|
+
|
|
116
|
+
### MMOT Evaluation
|
|
117
|
+
|
|
118
|
+
Managerial Moment of Truth — autonomous self-evaluation against Elements of Performance:
|
|
119
|
+
|
|
120
|
+
1. **Acknowledge** — Compare expected vs delivered output
|
|
121
|
+
2. **Analyze** — What dynamics caused the gap?
|
|
122
|
+
3. **Update** — Write findings into current reality
|
|
123
|
+
4. **Recommit** — Add corrective action steps if needed
|
|
124
|
+
|
|
125
|
+
Supports directional perspectives: South (design/structure), East (narrative/execution), West (embodied/execution), North (wisdom/design).
|
|
126
|
+
|
|
127
|
+
| Tool | Purpose |
|
|
128
|
+
|------|---------|
|
|
129
|
+
| `perform_mmot_evaluation` | Run MMOT self-evaluation on chart |
|
|
130
|
+
| `init_llm_guidance` | Provide methodology guidance to LLMs |
|
|
131
|
+
|
|
132
|
+
### Knowledge Graph Tools
|
|
133
|
+
|
|
134
|
+
| Tool | Purpose |
|
|
135
|
+
|------|---------|
|
|
136
|
+
| `create_entities` | Add entities to graph |
|
|
137
|
+
| `create_relations` | Create relationships |
|
|
138
|
+
| `add_observations` | Add facts to entities |
|
|
139
|
+
| `search_nodes` | Full-text search |
|
|
140
|
+
| `open_nodes` | Retrieve specific entities |
|
|
141
|
+
| `read_graph` | Export complete graph |
|
|
142
|
+
| `delete_entities` | Remove entities |
|
|
143
|
+
| `delete_relations` | Remove relationships |
|
|
144
|
+
| `delete_observations` | Remove observations |
|
|
145
|
+
|
|
146
|
+
## Creative Orientation Validation
|
|
147
|
+
|
|
148
|
+
Desired outcomes are validated against problem-solving language:
|
|
149
|
+
- **Reject**: fix, solve, eliminate, prevent, stop, avoid, reduce, remove
|
|
150
|
+
- **Accept**: create, build, establish, develop, design, manifest, achieve
|
|
151
|
+
|
|
152
|
+
Current reality is validated against false readiness:
|
|
153
|
+
- **Reject**: ready to, prepared to, all set, ready for, set to
|
|
154
|
+
- **Accept**: specific factual assessments
|
|
155
|
+
|
|
156
|
+
Error messages teach the principle, not just reject the input.
|
|
157
|
+
|
|
158
|
+
## Date Distribution
|
|
159
|
+
|
|
160
|
+
When action steps are created without explicit due dates:
|
|
161
|
+
```
|
|
162
|
+
totalTime = endDate - startDate
|
|
163
|
+
stepInterval = totalTime / (stepCount + 1)
|
|
164
|
+
dates[i] = startDate + (stepInterval * i)
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Related Rispecs
|
|
168
|
+
|
|
169
|
+
- `coaia-narrative/rispecs/structural_tension_chart_creation.spec.md` — detailed STC creation behavior
|
|
170
|
+
- `coaia-narrative/rispecs/telescoping_hierarchical_advancement.spec.md` — telescoping rules
|
|
171
|
+
- `coaia-narrative/rispecs/advancing_pattern_tracking.spec.md` — completion flow
|
|
172
|
+
- `coaia-narrative/rispecs/storage_knowledge_graph.spec.md` — JSONL format specification
|
|
173
|
+
- `coaia-narrative/rispecs/mmot_evaluation_loop.spec.md` — MMOT phases
|
|
174
|
+
- `coaia-narrative/rispecs/narrative_beat_creation.spec.md` — beat system
|
|
175
|
+
- `coaia-narrative/rispecs/mcp_api_specification.spec.md` — tool schemas (28 tools)
|
|
176
|
+
|
|
177
|
+
## Quality Criteria
|
|
178
|
+
|
|
179
|
+
- ✅ JSONL output is byte-compatible with coaia-narrative output
|
|
180
|
+
- ✅ All 27 coaia-narrative MCP tools produce identical results
|
|
181
|
+
- ✅ Graph loads correctly from existing coaia-narrative JSONL files
|
|
182
|
+
- ✅ Creative orientation validation matches coaia-narrative behavior exactly
|
|
183
|
+
- ✅ STC lifecycle (create → telescope → advance → complete) is complete
|
|
184
|
+
- ✅ MMOT evaluation writes findings into current reality
|
|
185
|
+
- ✅ Narrative beats support all dramatic types and universe perspectives
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# 05 — PDE Engine
|
|
2
|
+
|
|
3
|
+
> Prompt Decomposition Engine with PDE→STC transformation and session management.
|
|
4
|
+
|
|
5
|
+
## Desired Outcome
|
|
6
|
+
|
|
7
|
+
A PDE module that transforms `DecompositionResult` objects into coaia-narrative-compatible JSONL, creating Structural Tension Charts from decomposed prompts — bridging the gap between intent extraction (EAST direction) and strategic action planning (NORTH direction).
|
|
8
|
+
|
|
9
|
+
## Structural Tension
|
|
10
|
+
|
|
11
|
+
**Current Reality:**
|
|
12
|
+
- `src/pde/` directory exists but is empty
|
|
13
|
+
- PDE types fully defined in `src/types.ts`: `DecompositionResult`, `PrimaryIntent`, `SecondaryIntent`, `DirectionMap`, `ActionItem`, `AmbiguityFlag`, `StoredDecomposition`, `PdeSession`
|
|
14
|
+
- coaia-pde v0.1.1 has a working implementation:
|
|
15
|
+
- `stc-mapper.ts` (~300 lines) — transforms DecompositionResult → Entity[]/Relation[]
|
|
16
|
+
- `session-manager.ts` — persists PDE sessions as JSONL
|
|
17
|
+
- `mcp-server.ts` — 12 MCP tools
|
|
18
|
+
- coaia-pde rispec exists: `pde-to-stc-transformation.rispec.md` — defines the Four Directions → STC mapping
|
|
19
|
+
|
|
20
|
+
**Desired Outcome:**
|
|
21
|
+
PDE engine in `src/pde/` that:
|
|
22
|
+
- Accepts a `DecompositionResult` from any PDE implementation
|
|
23
|
+
- Transforms it into coaia-narrative-compatible JSONL entities and relations
|
|
24
|
+
- Manages PDE sessions with JSONL persistence
|
|
25
|
+
- Exposes 12 MCP tools
|
|
26
|
+
|
|
27
|
+
## Four Directions → STC Mapping
|
|
28
|
+
|
|
29
|
+
| PDE Direction | STC Component | Rationale |
|
|
30
|
+
|--------------|---------------|-----------|
|
|
31
|
+
| 🌅 EAST (Vision) | **Desired Outcome** | What wants to emerge = what we want to create |
|
|
32
|
+
| 🔥 SOUTH (Analysis) | **Current Reality** | What must be understood = where we are now |
|
|
33
|
+
| 🌊 WEST (Validation) | **Structural Tension** | What must be reflected upon = the tension |
|
|
34
|
+
| ❄️ NORTH (Action) | **Action Steps** | What must be done = steps to resolve tension |
|
|
35
|
+
|
|
36
|
+
### Field Mapping
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
primary.target → STC title / desired outcome summary
|
|
40
|
+
primary.action → STC action verb
|
|
41
|
+
directions.east[] → STC desired_outcome (vision statements)
|
|
42
|
+
directions.south[] → STC current_reality (analysis statements)
|
|
43
|
+
directions.west[] → STC structural_tension (validation/reflection)
|
|
44
|
+
directions.north[] → STC action_steps (execution items)
|
|
45
|
+
actionStack[] → STC action_steps (ordered, with dependencies)
|
|
46
|
+
secondary[].confidence → STC action step priority weighting
|
|
47
|
+
ambiguities[] → STC current_reality gaps / tension sources
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Core API
|
|
51
|
+
|
|
52
|
+
### StcMapper
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
class StcMapper {
|
|
56
|
+
mapToEntities(result: DecompositionResult): { entities: Entity[], relations: Relation[] }
|
|
57
|
+
previewMapping(result: DecompositionResult): StcPreview
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
interface StcPreview {
|
|
61
|
+
desiredOutcome: string;
|
|
62
|
+
currentReality: string;
|
|
63
|
+
actionSteps: { title: string; priority: number }[];
|
|
64
|
+
tensions: string[];
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### SessionManager
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
class SessionManager {
|
|
72
|
+
constructor(pdeDir: string) // default: '.pde/'
|
|
73
|
+
createSession(decomposition: DecompositionResult): Promise<PdeSession>
|
|
74
|
+
getSession(sessionId: string): Promise<PdeSession | null>
|
|
75
|
+
listSessions(): Promise<PdeSession[]>
|
|
76
|
+
transformToStc(sessionId: string): Promise<{ chartId: string; jsonlPath: string }>
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## MCP Tools (12)
|
|
81
|
+
|
|
82
|
+
| Tool | Purpose |
|
|
83
|
+
|------|---------|
|
|
84
|
+
| `pde_decompose` | Build prompts for LLM-driven decomposition |
|
|
85
|
+
| `pde_parse_response` | Parse LLM response into DecompositionResult |
|
|
86
|
+
| `pde_get` | Retrieve stored decomposition by ID |
|
|
87
|
+
| `pde_list` | List stored decompositions |
|
|
88
|
+
| `pde_export_markdown` | Export as git-diffable markdown |
|
|
89
|
+
| `pde_to_stc` | Transform decomposition into STC |
|
|
90
|
+
| `pde_preview_stc` | Preview STC mapping without creating |
|
|
91
|
+
| `pde_create_session` | Create new PDE session |
|
|
92
|
+
| `pde_get_session` | Get session details |
|
|
93
|
+
| `pde_list_sessions` | List all sessions |
|
|
94
|
+
| `pde_session_status` | Get session transformation status |
|
|
95
|
+
| `pde_bridge_plan` | Bridge to planning engine |
|
|
96
|
+
|
|
97
|
+
## Relation to Planning Engine
|
|
98
|
+
|
|
99
|
+
PDE and planning are parallel input paths converging on narrative JSONL:
|
|
100
|
+
|
|
101
|
+
```
|
|
102
|
+
mcp-pde → .pde/ → coaiajs pde-engine → narrative JSONL → STC
|
|
103
|
+
Claude Plan mode → plan.md → coaiajs planning-engine → narrative JSONL → STC
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Quality Criteria
|
|
107
|
+
|
|
108
|
+
- ✅ StcMapper produces entities/relations compatible with narrative engine's JSONL format
|
|
109
|
+
- ✅ All 12 coaia-pde MCP tools produce identical results
|
|
110
|
+
- ✅ PDE sessions are persisted as `.pde/*.json` files
|
|
111
|
+
- ✅ Preview mapping shows the transformation without side effects
|
|
112
|
+
- ✅ Ambiguities from decomposition surface as tension sources in the STC
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# 06 — Planning Engine
|
|
2
|
+
|
|
3
|
+
> Plan parsing and bidirectional plan↔STC synchronization.
|
|
4
|
+
|
|
5
|
+
## Desired Outcome
|
|
6
|
+
|
|
7
|
+
A planning module that parses markdown plans (particularly Claude Plan mode output) into `StructuralTensionPlan` objects, converts them to STC entities, and supports bidirectional sync — so changes to the plan update the STC and vice versa.
|
|
8
|
+
|
|
9
|
+
## Structural Tension
|
|
10
|
+
|
|
11
|
+
**Current Reality:**
|
|
12
|
+
- `src/planning/` directory exists but is empty
|
|
13
|
+
- Types defined in `src/types.ts`: `StructuralTensionPlan`, `StructuralElement`
|
|
14
|
+
- coaia-planning v0.1.0 has a working implementation:
|
|
15
|
+
- `plan-parser.ts` (821 lines) — parses markdown plans into structured objects
|
|
16
|
+
- `tools/index.ts` — 5 MCP tools + 1 PDE bridge tool
|
|
17
|
+
- No rispecs exist for coaia-planning — this is the first specification
|
|
18
|
+
|
|
19
|
+
**Desired Outcome:**
|
|
20
|
+
Planning engine in `src/planning/` that:
|
|
21
|
+
- Parses markdown plans into `StructuralTensionPlan` objects
|
|
22
|
+
- Converts plans to narrative-engine-compatible STC entities
|
|
23
|
+
- Supports bidirectional plan↔STC sync
|
|
24
|
+
- Exposes 6 MCP tools
|
|
25
|
+
|
|
26
|
+
## Plan Format
|
|
27
|
+
|
|
28
|
+
The parser handles markdown plans with this structure:
|
|
29
|
+
|
|
30
|
+
```markdown
|
|
31
|
+
# Plan Title
|
|
32
|
+
|
|
33
|
+
## Goal
|
|
34
|
+
What this plan aims to create.
|
|
35
|
+
|
|
36
|
+
## Current State
|
|
37
|
+
Where things stand right now.
|
|
38
|
+
|
|
39
|
+
## Steps
|
|
40
|
+
1. [ ] First action item
|
|
41
|
+
- Detail about first item
|
|
42
|
+
2. [x] Completed item
|
|
43
|
+
3. [ ] Third item
|
|
44
|
+
- Sub-detail A
|
|
45
|
+
- Sub-detail B
|
|
46
|
+
|
|
47
|
+
## Notes
|
|
48
|
+
Additional context.
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Core API
|
|
52
|
+
|
|
53
|
+
### PlanParser
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
class PlanParser {
|
|
57
|
+
parse(markdown: string): StructuralTensionPlan
|
|
58
|
+
parseFile(filePath: string): Promise<StructuralTensionPlan>
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
interface StructuralTensionPlan {
|
|
62
|
+
title: string;
|
|
63
|
+
desiredOutcome: string;
|
|
64
|
+
currentReality: string;
|
|
65
|
+
elements: StructuralElement[];
|
|
66
|
+
metadata?: Record<string, unknown>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
interface StructuralElement {
|
|
70
|
+
title: string;
|
|
71
|
+
description?: string;
|
|
72
|
+
completed: boolean;
|
|
73
|
+
subElements?: StructuralElement[];
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### PlanToStcConverter
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
class PlanToStcConverter {
|
|
81
|
+
toEntities(plan: StructuralTensionPlan): { entities: Entity[], relations: Relation[] }
|
|
82
|
+
fromStc(chartId: string, graph: KnowledgeGraph): StructuralTensionPlan
|
|
83
|
+
sync(plan: StructuralTensionPlan, chartId: string, graph: KnowledgeGraph): SyncResult
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
interface SyncResult {
|
|
87
|
+
newEntities: Entity[];
|
|
88
|
+
updatedEntities: Entity[];
|
|
89
|
+
removedEntities: string[];
|
|
90
|
+
conflicts: SyncConflict[];
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Bidirectional Sync
|
|
95
|
+
|
|
96
|
+
Plan → STC:
|
|
97
|
+
- Plan `Goal` maps to chart desired outcome
|
|
98
|
+
- Plan `Current State` maps to chart current reality
|
|
99
|
+
- Plan `Steps` map to chart action steps
|
|
100
|
+
- Completed steps (`[x]`) map to completed actions
|
|
101
|
+
- Sub-items map to telescoped action steps
|
|
102
|
+
|
|
103
|
+
STC → Plan:
|
|
104
|
+
- Chart desired outcome maps to plan `Goal`
|
|
105
|
+
- Chart current reality maps to plan `Current State`
|
|
106
|
+
- Action steps map to plan `Steps` with checkbox state
|
|
107
|
+
- Progress observations map to sub-items
|
|
108
|
+
|
|
109
|
+
Conflict resolution: STC wins by default (it is the source of truth). Conflicts are reported in `SyncResult.conflicts` for human review.
|
|
110
|
+
|
|
111
|
+
## MCP Tools (6)
|
|
112
|
+
|
|
113
|
+
| Tool | Purpose |
|
|
114
|
+
|------|---------|
|
|
115
|
+
| `plan_parse` | Parse markdown plan into structured object |
|
|
116
|
+
| `plan_to_stc` | Convert parsed plan to STC entities |
|
|
117
|
+
| `plan_from_stc` | Generate plan markdown from STC |
|
|
118
|
+
| `plan_sync` | Bidirectional sync between plan and STC |
|
|
119
|
+
| `plan_diff` | Show differences between plan and STC |
|
|
120
|
+
| `plan_bridge_pde` | Import PDE decomposition as plan |
|
|
121
|
+
|
|
122
|
+
## Quality Criteria
|
|
123
|
+
|
|
124
|
+
- ✅ Parses Claude Plan mode output without modification
|
|
125
|
+
- ✅ Checkbox state (`[ ]` / `[x]`) maps correctly to action completion
|
|
126
|
+
- ✅ Sub-items preserved through parse → STC → plan round-trip
|
|
127
|
+
- ✅ Bidirectional sync detects and reports conflicts
|
|
128
|
+
- ✅ Generated markdown is readable and re-parseable
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# 07 — Pipeline Templates
|
|
2
|
+
|
|
3
|
+
> Pipeline template engine with variable substitution and conditional rendering.
|
|
4
|
+
|
|
5
|
+
## Desired Outcome
|
|
6
|
+
|
|
7
|
+
A template engine that loads pipeline definitions, renders them with `{{variable}}` substitution, supports conditionals and built-in functions, and executes multi-step pipelines — enabling reusable agent workflows defined in YAML or JSON.
|
|
8
|
+
|
|
9
|
+
## Structural Tension
|
|
10
|
+
|
|
11
|
+
**Current Reality:**
|
|
12
|
+
- `src/pipeline/` directory exists but is empty
|
|
13
|
+
- Types defined in `src/types.ts`: `PipelineVariable`, `PipelineStep`, `PipelineTemplate`
|
|
14
|
+
- coaiapy has two relevant files:
|
|
15
|
+
- `pipeline.py` — loads and executes pipeline templates
|
|
16
|
+
- `mobile_template.py` — a specific pipeline template for mobile workflows
|
|
17
|
+
- Pipeline templates use `{{variable}}` Mustache-style substitution
|
|
18
|
+
- No MCP tools exist for pipelines in any parent project
|
|
19
|
+
|
|
20
|
+
**Desired Outcome:**
|
|
21
|
+
Pipeline engine in `src/pipeline/` that:
|
|
22
|
+
- Loads templates from YAML/JSON files
|
|
23
|
+
- Renders templates with variable substitution
|
|
24
|
+
- Supports conditionals (`{{#if condition}}...{{/if}}`)
|
|
25
|
+
- Provides built-in functions (`{{now}}`, `{{uuid}}`, `{{env.VAR}}`)
|
|
26
|
+
- Executes multi-step pipelines with step dependencies
|
|
27
|
+
- Exposes 3 MCP tools
|
|
28
|
+
|
|
29
|
+
## Template Format
|
|
30
|
+
|
|
31
|
+
```yaml
|
|
32
|
+
name: session-init
|
|
33
|
+
description: Initialize a CoAiA agent session
|
|
34
|
+
variables:
|
|
35
|
+
- name: session_id
|
|
36
|
+
required: true
|
|
37
|
+
- name: agent_name
|
|
38
|
+
default: "unnamed"
|
|
39
|
+
- name: trace_id
|
|
40
|
+
default: "{{uuid}}"
|
|
41
|
+
steps:
|
|
42
|
+
- name: create-trace
|
|
43
|
+
action: langfuse.createTrace
|
|
44
|
+
params:
|
|
45
|
+
name: "{{agent_name}}-session"
|
|
46
|
+
sessionId: "{{session_id}}"
|
|
47
|
+
metadata:
|
|
48
|
+
traceId: "{{trace_id}}"
|
|
49
|
+
- name: init-redis
|
|
50
|
+
action: redis.tash
|
|
51
|
+
params:
|
|
52
|
+
key: "session:{{session_id}}"
|
|
53
|
+
value: '{"agent":"{{agent_name}}","started":"{{now}}"}'
|
|
54
|
+
ttl: 86400
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Core API
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
class PipelineEngine {
|
|
61
|
+
loadTemplate(pathOrName: string): Promise<PipelineTemplate>
|
|
62
|
+
render(template: PipelineTemplate, variables: Record<string, string>): PipelineTemplate
|
|
63
|
+
execute(template: PipelineTemplate, variables: Record<string, string>): Promise<PipelineResult>
|
|
64
|
+
listTemplates(directory?: string): Promise<string[]>
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
interface PipelineResult {
|
|
68
|
+
success: boolean;
|
|
69
|
+
steps: { name: string; status: 'success' | 'failed' | 'skipped'; output?: unknown; error?: string }[];
|
|
70
|
+
duration: number;
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Built-in Functions
|
|
75
|
+
|
|
76
|
+
| Function | Output |
|
|
77
|
+
|----------|--------|
|
|
78
|
+
| `{{now}}` | ISO 8601 timestamp |
|
|
79
|
+
| `{{uuid}}` | Random UUID v4 |
|
|
80
|
+
| `{{env.VAR_NAME}}` | Environment variable value |
|
|
81
|
+
| `{{date.YYYY-MM-DD}}` | Formatted date |
|
|
82
|
+
|
|
83
|
+
## MCP Tools (3)
|
|
84
|
+
|
|
85
|
+
| Tool | Purpose |
|
|
86
|
+
|------|---------|
|
|
87
|
+
| `pipeline_list` | List available pipeline templates |
|
|
88
|
+
| `pipeline_render` | Render template with variables (preview) |
|
|
89
|
+
| `pipeline_execute` | Execute pipeline with variables |
|
|
90
|
+
|
|
91
|
+
## Quality Criteria
|
|
92
|
+
|
|
93
|
+
- ✅ Templates load from both YAML and JSON formats
|
|
94
|
+
- ✅ Missing required variables produce clear error with variable name
|
|
95
|
+
- ✅ Default values applied when optional variables are absent
|
|
96
|
+
- ✅ Built-in functions resolve at render time
|
|
97
|
+
- ✅ Step execution is sequential; failure stops pipeline unless step is marked optional
|