coaiajs 0.3.0 → 0.3.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 (179) hide show
  1. package/KINSHIP.md +1 -1
  2. package/README.md +191 -75
  3. package/dist/mcp/config.d.ts.map +1 -0
  4. package/dist/mcp/config.js +0 -2
  5. package/dist/mcp/config.js.map +1 -0
  6. package/dist/mcp/prompts.d.ts.map +1 -0
  7. package/dist/mcp/prompts.js.map +1 -0
  8. package/dist/mcp/resources.d.ts.map +1 -0
  9. package/dist/mcp/resources.js.map +1 -0
  10. package/dist/mcp/server.d.ts.map +1 -0
  11. package/dist/mcp/server.js +1 -1
  12. package/dist/mcp/server.js.map +1 -0
  13. package/dist/mcp/tools/coaiapy-tools.d.ts.map +1 -0
  14. package/dist/mcp/tools/coaiapy-tools.js.map +1 -0
  15. package/dist/mcp/tools/index.d.ts.map +1 -0
  16. package/dist/mcp/tools/index.js.map +1 -0
  17. package/dist/src/audio.d.ts.map +1 -0
  18. package/dist/src/audio.js.map +1 -0
  19. package/dist/src/cli-helpers.d.ts.map +1 -0
  20. package/dist/src/cli-helpers.js.map +1 -0
  21. package/dist/src/cli.d.ts.map +1 -0
  22. package/dist/src/cli.js +1 -0
  23. package/dist/src/cli.js.map +1 -0
  24. package/dist/src/config.d.ts.map +1 -0
  25. package/dist/src/config.js.map +1 -0
  26. package/dist/src/environment.d.ts.map +1 -0
  27. package/dist/src/environment.js.map +1 -0
  28. package/dist/src/github.d.ts.map +1 -0
  29. package/dist/src/github.js.map +1 -0
  30. package/dist/src/index.d.ts +1 -0
  31. package/dist/src/index.d.ts.map +1 -0
  32. package/dist/src/index.js +1 -0
  33. package/dist/src/index.js.map +1 -0
  34. package/dist/src/langfuse/client.d.ts.map +1 -0
  35. package/dist/src/langfuse/client.js.map +1 -0
  36. package/dist/src/langfuse/comments.d.ts.map +1 -0
  37. package/dist/src/langfuse/comments.js.map +1 -0
  38. package/dist/src/langfuse/datasets.d.ts.map +1 -0
  39. package/dist/src/langfuse/datasets.js.map +1 -0
  40. package/dist/src/langfuse/index.d.ts +1 -0
  41. package/dist/src/langfuse/index.d.ts.map +1 -0
  42. package/dist/src/langfuse/index.js.map +1 -0
  43. package/dist/src/langfuse/media.d.ts.map +1 -0
  44. package/dist/src/langfuse/media.js.map +1 -0
  45. package/dist/src/langfuse/observations.d.ts.map +1 -0
  46. package/dist/src/langfuse/observations.js.map +1 -0
  47. package/dist/src/langfuse/prompts.d.ts +5 -1
  48. package/dist/src/langfuse/prompts.d.ts.map +1 -0
  49. package/dist/src/langfuse/prompts.js +16 -3
  50. package/dist/src/langfuse/prompts.js.map +1 -0
  51. package/dist/src/langfuse/scores.d.ts.map +1 -0
  52. package/dist/src/langfuse/scores.js.map +1 -0
  53. package/dist/src/langfuse/traces.d.ts.map +1 -0
  54. package/dist/src/langfuse/traces.js.map +1 -0
  55. package/dist/src/llm.d.ts.map +1 -0
  56. package/dist/src/llm.js.map +1 -0
  57. package/dist/src/narrative/graph-manager.d.ts.map +1 -0
  58. package/dist/src/narrative/graph-manager.js.map +1 -0
  59. package/dist/src/narrative/index.d.ts.map +1 -0
  60. package/dist/src/narrative/index.js.map +1 -0
  61. package/dist/src/narrative/markdown-export.d.ts.map +1 -0
  62. package/dist/src/narrative/markdown-export.js.map +1 -0
  63. package/dist/src/narrative/tool-definitions.d.ts.map +1 -0
  64. package/dist/src/narrative/tool-definitions.js.map +1 -0
  65. package/dist/src/narrative/tool-handlers.d.ts.map +1 -0
  66. package/dist/src/narrative/tool-handlers.js.map +1 -0
  67. package/dist/src/narrative/types.d.ts.map +1 -0
  68. package/dist/src/narrative/types.js.map +1 -0
  69. package/dist/src/narrative/validation.d.ts.map +1 -0
  70. package/dist/src/narrative/validation.js.map +1 -0
  71. package/dist/src/pde/index.d.ts.map +1 -0
  72. package/dist/src/pde/index.js.map +1 -0
  73. package/dist/src/pde/mcp-handlers.d.ts.map +1 -0
  74. package/dist/src/pde/mcp-handlers.js.map +1 -0
  75. package/dist/src/pde/mcp-tools.d.ts.map +1 -0
  76. package/dist/src/pde/mcp-tools.js.map +1 -0
  77. package/dist/src/pde/session-manager.d.ts.map +1 -0
  78. package/dist/src/pde/session-manager.js.map +1 -0
  79. package/dist/src/pde/stc-mapper.d.ts.map +1 -0
  80. package/dist/src/pde/stc-mapper.js.map +1 -0
  81. package/dist/src/pipeline/index.d.ts.map +1 -0
  82. package/dist/src/pipeline/index.js.map +1 -0
  83. package/dist/src/pipeline/template-engine.d.ts.map +1 -0
  84. package/dist/src/pipeline/template-engine.js.map +1 -0
  85. package/dist/src/planning/index.d.ts.map +1 -0
  86. package/dist/src/planning/index.js.map +1 -0
  87. package/dist/src/planning/mcp-handlers.d.ts.map +1 -0
  88. package/dist/src/planning/mcp-handlers.js.map +1 -0
  89. package/dist/src/planning/mcp-tools.d.ts.map +1 -0
  90. package/dist/src/planning/mcp-tools.js.map +1 -0
  91. package/dist/src/planning/plan-parser.d.ts.map +1 -0
  92. package/dist/src/planning/plan-parser.js.map +1 -0
  93. package/dist/src/redis.d.ts.map +1 -0
  94. package/dist/src/redis.js.map +1 -0
  95. package/dist/src/types.d.ts.map +1 -0
  96. package/dist/src/types.js.map +1 -0
  97. package/dist/src/version.d.ts.map +1 -0
  98. package/dist/src/version.js.map +1 -0
  99. package/llms-full.txt +361 -0
  100. package/llms.txt +43 -0
  101. package/package.json +79 -12
  102. package/.claude/settings.local.json +0 -17
  103. package/.claude-plugin/marketplace.json +0 -26
  104. package/articles/academic/NOTES.md +0 -1
  105. package/articles/academic/README.md +0 -1
  106. package/articles/academic/creative-orientation-vs-problem-solving.md +0 -177
  107. package/articles/academic/jsonl-knowledge-graphs-agent-memory.md +0 -142
  108. package/articles/academic/langfuse-observability-llm-pipelines.md +0 -144
  109. package/articles/academic/medicine-wheel-software-architecture.md +0 -163
  110. package/articles/academic/mmot-autonomous-agents.md +0 -156
  111. package/articles/academic/model-context-protocol-interagent.md +0 -161
  112. package/articles/academic/pde-prompt-decomposition.md +0 -186
  113. package/articles/academic/structural-tension-in-ai-agents.md +0 -134
  114. package/articles/reviews/mcp-protocol-design-review.md +0 -170
  115. package/articles/reviews/observability-ai-systems-review.md +0 -176
  116. package/articles/reviews/prompt-engineering-decomposition-review.md +0 -184
  117. package/articles/surveys/agent-orchestration-survey.md +0 -186
  118. package/articles/surveys/knowledge-graph-storage-survey.md +0 -204
  119. package/articles/surveys/structural-tension-methodology-survey.md +0 -154
  120. package/articles/technical/aws-sdk-v3-polly.md +0 -270
  121. package/articles/technical/commander-cli-framework.md +0 -262
  122. package/articles/technical/dotenv-config-patterns.md +0 -360
  123. package/articles/technical/ioredis-vs-redis.md +0 -142
  124. package/articles/technical/langfuse-js-sdk-vs-rest.md +0 -191
  125. package/articles/technical/mcp-sdk-typescript.md +0 -291
  126. package/articles/technical/octokit-github-api.md +0 -293
  127. package/articles/technical/openai-sdk-modern.md +0 -231
  128. package/articles/technical/yaml-parsing-node.md +0 -266
  129. package/articles/technical/zod-runtime-validation.md +0 -212
  130. package/coaiajs-langfuse-claude-plugin/.claude-plugin/marketplace.json +0 -16
  131. package/coaiajs-langfuse-claude-plugin/.claude-plugin/plugin.json +0 -10
  132. package/coaiajs-langfuse-claude-plugin/.mcp.json +0 -8
  133. package/coaiajs-langfuse-claude-plugin/README.md +0 -60
  134. package/mcp/config.ts +0 -225
  135. package/mcp/prompts.ts +0 -131
  136. package/mcp/resources.ts +0 -84
  137. package/mcp/server.ts +0 -519
  138. package/mcp/tools/coaiapy-tools.ts +0 -366
  139. package/mcp/tools/index.ts +0 -4
  140. package/src/audio.ts +0 -76
  141. package/src/cli-helpers.ts +0 -86
  142. package/src/cli.ts +0 -1261
  143. package/src/config.ts +0 -207
  144. package/src/environment.ts +0 -171
  145. package/src/github.ts +0 -143
  146. package/src/index.ts +0 -82
  147. package/src/langfuse/client.ts +0 -105
  148. package/src/langfuse/comments.ts +0 -52
  149. package/src/langfuse/datasets.ts +0 -178
  150. package/src/langfuse/index.ts +0 -37
  151. package/src/langfuse/media.ts +0 -193
  152. package/src/langfuse/observations.ts +0 -155
  153. package/src/langfuse/prompts.ts +0 -157
  154. package/src/langfuse/scores.ts +0 -456
  155. package/src/langfuse/traces.ts +0 -353
  156. package/src/llm.ts +0 -106
  157. package/src/narrative/graph-manager.ts +0 -1358
  158. package/src/narrative/index.ts +0 -188
  159. package/src/narrative/markdown-export.ts +0 -535
  160. package/src/narrative/tool-definitions.ts +0 -635
  161. package/src/narrative/tool-handlers.ts +0 -528
  162. package/src/narrative/types.ts +0 -9
  163. package/src/narrative/validation.ts +0 -179
  164. package/src/pde/index.ts +0 -34
  165. package/src/pde/mcp-handlers.ts +0 -359
  166. package/src/pde/mcp-tools.ts +0 -201
  167. package/src/pde/session-manager.ts +0 -248
  168. package/src/pde/stc-mapper.ts +0 -298
  169. package/src/pipeline/index.ts +0 -7
  170. package/src/pipeline/template-engine.ts +0 -398
  171. package/src/planning/index.ts +0 -32
  172. package/src/planning/mcp-handlers.ts +0 -369
  173. package/src/planning/mcp-tools.ts +0 -155
  174. package/src/planning/plan-parser.ts +0 -587
  175. package/src/redis.ts +0 -111
  176. package/src/types.ts +0 -281
  177. package/src/version.ts +0 -39
  178. package/test/config.test.mjs +0 -93
  179. package/tsconfig.json +0 -26
@@ -1,266 +0,0 @@
1
- # YAML Parsing in Node.js: Technical Assessment for CoAiA.js
2
-
3
- > Package selection brief — YAML parser for pipeline templates, session files, and config loading replacing coaiapy's PyYAML
4
-
5
- ## Summary & Recommendation
6
-
7
- **Use `yaml` v2.x** (the npm package named simply `yaml`). Despite `js-yaml` having higher download numbers, the modern `yaml` package offers streaming support for large files, comment preservation (critical for human-edited pipeline templates), and a cleaner API. CoAiA pipeline templates are user-authored YAML that benefits from round-trip fidelity — comments survive parse→stringify cycles.
8
-
9
- **Pin:** `"yaml": "^2.6.0"`
10
-
11
- ## What We're Replacing
12
-
13
- Coaiapy uses PyYAML for pipeline template loading:
14
-
15
- ```python
16
- # coaiapy/pipeline.py — PyYAML pattern
17
- import yaml
18
-
19
- # Load pipeline template
20
- for template_file in search_path.glob("*.yaml"):
21
- with open(yaml_file, 'r') as f:
22
- data = yaml.safe_load(f) # Parse YAML → dict
23
-
24
- # Pipeline template format:
25
- # name: "trace-session"
26
- # version: "1.0"
27
- # variables:
28
- # - name: session_id
29
- # type: string
30
- # required: true
31
- # steps:
32
- # - name: create_trace
33
- # observation_type: SPAN
34
- ```
35
-
36
- PyYAML's `safe_load` works well; the JavaScript equivalent needs the same safety guarantees plus TypeScript types.
37
-
38
- ## Options Compared
39
-
40
- | Feature | yaml v2.6 | js-yaml v4.1 |
41
- |---------|-----------|-------------|
42
- | Weekly npm downloads | ~80M | ~130M |
43
- | GitHub stars | ~1,600 | ~6,500 |
44
- | Parse speed (typical files) | Good | Faster (~10%) |
45
- | Stringify speed | Faster | Slower |
46
- | Streaming support | ✅ Parse & stringify | ❌ Memory only |
47
- | Comment preservation | ✅ Round-trip fidelity | ❌ Comments lost |
48
- | Anchor/alias support | ✅ Full | ✅ Full |
49
- | Custom tags | ✅ Flexible API | ✅ Schema-based |
50
- | TypeScript | Native types | `@types/js-yaml` |
51
- | YAML 1.2 compliance | ✅ Full | ⚠️ Mostly |
52
- | Security (CVEs) | None known | CVE-2025-64718 (fixed in 4.1.1) |
53
- | API style | `parse(str)`, `stringify(obj)` | `load(str)`, `dump(obj)` |
54
- | Bundle size | ~45KB | ~30KB |
55
- | Dependencies | 0 | 0 |
56
-
57
- ## API Overview
58
-
59
- ### Basic Parse & Stringify
60
-
61
- ```typescript
62
- import { parse, stringify } from 'yaml';
63
- import { readFile, writeFile } from 'fs/promises';
64
-
65
- // Parse YAML file
66
- async function loadYaml<T>(filePath: string): Promise<T> {
67
- const content = await readFile(filePath, 'utf-8');
68
- return parse(content) as T;
69
- }
70
-
71
- // Stringify to YAML
72
- async function saveYaml(filePath: string, data: unknown): Promise<void> {
73
- const yamlStr = stringify(data, {
74
- indent: 2,
75
- lineWidth: 120,
76
- });
77
- await writeFile(filePath, yamlStr, 'utf-8');
78
- }
79
- ```
80
-
81
- ### Pipeline Template Loading (replacing pipeline.py)
82
-
83
- ```typescript
84
- import { parse } from 'yaml';
85
- import { readFile } from 'fs/promises';
86
- import { glob } from 'glob';
87
- import { z } from 'zod';
88
-
89
- // Schema (validated with Zod after YAML parse)
90
- const PipelineTemplateSchema = z.object({
91
- name: z.string().min(1),
92
- version: z.string().default('1.0'),
93
- variables: z.array(z.object({
94
- name: z.string().min(1),
95
- type: z.enum(['string', 'number', 'boolean', 'list']).default('string'),
96
- required: z.boolean().default(true),
97
- default: z.unknown().optional(),
98
- choices: z.array(z.unknown()).optional(),
99
- })).default([]),
100
- steps: z.array(z.object({
101
- name: z.string().min(1),
102
- observation_type: z.enum(['EVENT', 'SPAN', 'GENERATION']).default('EVENT'),
103
- conditional: z.string().optional(),
104
- })).min(1),
105
- });
106
-
107
- type PipelineTemplate = z.infer<typeof PipelineTemplateSchema>;
108
-
109
- async function loadPipelineTemplates(templateDir: string): Promise<Map<string, PipelineTemplate>> {
110
- const templates = new Map<string, PipelineTemplate>();
111
- const files = await glob('*.yaml', { cwd: templateDir, absolute: true });
112
-
113
- for (const file of files) {
114
- const raw = parse(await readFile(file, 'utf-8'));
115
- const template = PipelineTemplateSchema.parse(raw);
116
- templates.set(template.name, template);
117
- }
118
-
119
- return templates;
120
- }
121
- ```
122
-
123
- ### Comment-Preserving Round-Trip (unique to `yaml` package)
124
-
125
- ```typescript
126
- import { parseDocument, stringify } from 'yaml';
127
- import { readFile, writeFile } from 'fs/promises';
128
-
129
- // Load, modify, save — preserving user comments
130
- async function updateTemplateVersion(filePath: string, newVersion: string): Promise<void> {
131
- const content = await readFile(filePath, 'utf-8');
132
- const doc = parseDocument(content); // Preserves comments, anchors, formatting
133
-
134
- doc.set('version', newVersion);
135
-
136
- await writeFile(filePath, doc.toString(), 'utf-8');
137
- // Original comments and formatting are preserved!
138
- }
139
-
140
- // Example input:
141
- // # Pipeline for session tracing
142
- // name: trace-session
143
- // version: "1.0" # Bump this on changes
144
- //
145
- // After update, the comment "# Bump this on changes" survives
146
- ```
147
-
148
- ### Session File Persistence
149
-
150
- ```typescript
151
- import { parse, stringify } from 'yaml';
152
- import { readFile, writeFile } from 'fs/promises';
153
-
154
- interface SessionFile {
155
- id: string;
156
- created: string;
157
- traces: { id: string; name: string; status: string }[];
158
- charts: { id: string; outcome: string }[];
159
- metadata: Record<string, unknown>;
160
- }
161
-
162
- async function saveSession(filePath: string, session: SessionFile): Promise<void> {
163
- await writeFile(filePath, stringify(session, {
164
- indent: 2,
165
- lineWidth: 120,
166
- sortMapEntries: false, // Preserve insertion order
167
- }), 'utf-8');
168
- }
169
-
170
- async function loadSession(filePath: string): Promise<SessionFile> {
171
- const content = await readFile(filePath, 'utf-8');
172
- return parse(content) as SessionFile;
173
- }
174
- ```
175
-
176
- ### Streaming for Large Files
177
-
178
- ```typescript
179
- import { parseAllDocuments } from 'yaml';
180
- import { createReadStream } from 'fs';
181
-
182
- // Stream-parse a multi-document YAML file
183
- async function parseMultiDoc(filePath: string) {
184
- const content = await readFile(filePath, 'utf-8');
185
- const docs = parseAllDocuments(content);
186
-
187
- for (const doc of docs) {
188
- if (doc.errors.length > 0) {
189
- console.error(`Parse errors in ${filePath}:`, doc.errors);
190
- continue;
191
- }
192
- yield doc.toJSON();
193
- }
194
- }
195
- ```
196
-
197
- ### Config File Loading
198
-
199
- ```typescript
200
- import { parse } from 'yaml';
201
- import { readFile } from 'fs/promises';
202
- import { existsSync } from 'fs';
203
-
204
- // Load coaia.json or coaia.yaml config
205
- async function loadConfigFile(configPath: string): Promise<Record<string, unknown>> {
206
- if (!existsSync(configPath)) return {};
207
-
208
- const content = await readFile(configPath, 'utf-8');
209
-
210
- if (configPath.endsWith('.yaml') || configPath.endsWith('.yml')) {
211
- return parse(content) ?? {};
212
- }
213
- if (configPath.endsWith('.json')) {
214
- return JSON.parse(content);
215
- }
216
-
217
- // Try YAML first (superset of JSON)
218
- try {
219
- return parse(content) ?? {};
220
- } catch {
221
- return JSON.parse(content);
222
- }
223
- }
224
- ```
225
-
226
- ## Integration Plan
227
-
228
- 1. **Core utility:** `src/yaml.ts` — typed `loadYaml<T>()` and `saveYaml()` wrappers
229
- 2. **Pipeline templates:** `src/pipeline/template-loader.ts` — YAML template discovery + Zod validation
230
- 3. **Session files:** `src/session/file.ts` — YAML session persistence
231
- 4. **Config loading:** `src/config.ts` — support `.yaml` config alongside `.json`
232
- 5. **Round-trip editing:** Use `parseDocument()` for user-facing template modifications
233
- 6. **Multi-doc:** Support `---` separated YAML documents for batch operations
234
-
235
- ## Why Not js-yaml?
236
-
237
- 1. **Comment preservation**: Pipeline templates are human-authored; losing comments on round-trip is unacceptable
238
- 2. **Security**: CVE-2025-64718 (prototype pollution) was a recent concern; `yaml` has a clean record
239
- 3. **YAML 1.2**: Full compliance matters for interop with other tools
240
- 4. **Streaming**: Future-proofing for large narrative JSONL files converted to/from YAML
241
- 5. **TypeScript**: Native types without DefinitelyTyped dependency
242
-
243
- The ~10% parse speed advantage of js-yaml is irrelevant for config/template files (sub-millisecond either way).
244
-
245
- ## Version & Ecosystem
246
-
247
- | Metric | Value |
248
- |--------|-------|
249
- | Current version | 2.6.x (2026) |
250
- | Weekly downloads | ~80M |
251
- | TypeScript | Native types |
252
- | Dependencies | 0 |
253
- | YAML spec | 1.2 compliant |
254
- | Comment round-trip | ✅ Full support |
255
- | Streaming | ✅ Parse & stringify |
256
- | Node.js compat | ≥14 (we target ≥20) |
257
- | License | ISC |
258
-
259
- ## References
260
-
261
- - npm: https://www.npmjs.com/package/yaml
262
- - GitHub: https://github.com/eemeli/yaml
263
- - js-yaml: https://www.npmjs.com/package/js-yaml
264
- - Comparison: https://npm-compare.com/js-yaml,yaml
265
- - Performance: https://github.com/eemeli/yaml/discussions/358
266
- - CVE-2025-64718: https://www.cvedetails.com/cve/CVE-2025-64718/
@@ -1,212 +0,0 @@
1
- # Zod Runtime Validation: Technical Assessment for CoAiA.js
2
-
3
- > Package selection brief — TypeScript-first schema validation replacing coaia-narrative's custom 181-line validation.ts
4
-
5
- ## Summary & Recommendation
6
-
7
- **Use `zod` v4.x** as the unified validation layer for all coaiajs modules. Zod replaces coaia-narrative's custom `validation.ts` (181 lines of hand-rolled recursive validation) with a standard, composable, type-inferring schema library. The MCP SDK already requires Zod as a peer dependency for tool argument schemas — using it everywhere eliminates dual validation code.
8
-
9
- **Pin:** `"zod": "^4.0.0"` (v4.3.6 stable, required by `@modelcontextprotocol/sdk`)
10
-
11
- ## What We're Replacing
12
-
13
- coaia-narrative has a custom `validation.ts` implementing recursive schema validation:
14
-
15
- ```typescript
16
- // coaia-narrative/src/validation.ts — 181 lines of custom validation
17
- type ValidationType = 'string' | 'number' | 'boolean' | 'array' | 'object' | 'date' | 'enum';
18
-
19
- interface ValidationRule {
20
- type: ValidationType;
21
- required?: boolean;
22
- minLength?: number;
23
- maxLength?: number;
24
- pattern?: RegExp;
25
- minValue?: number;
26
- maxValue?: number;
27
- enumValues?: (string | number)[];
28
- items?: ValidationRule; // array items schema
29
- properties?: Record<string, ValidationRule>; // object properties
30
- }
31
-
32
- export function validate(args: any, schema: ValidationSchema): { valid: boolean; error?: string }
33
- ```
34
-
35
- Pre-built schemas: `stringArray()`, `entityArray()`, `relationArray()`, `isoDate()`, `nonEmptyString()`.
36
-
37
- This works but: no type inference, no composition, no transform/coerce, no JSON Schema export, and every new validation type requires manual code.
38
-
39
- ## Options Compared
40
-
41
- | Feature | Zod v4 | Custom validation.ts | io-ts | Yup |
42
- |---------|--------|---------------------|-------|-----|
43
- | Type inference | ✅ Automatic `z.infer<>` | ❌ Manual types | ✅ (verbose) | ⚠️ Partial |
44
- | Schema composition | ✅ `.merge()`, `.extend()`, `.pick()` | ❌ Manual nesting | ✅ | ✅ |
45
- | MCP SDK compat | ✅ Required peer dep | ❌ N/A | ❌ | ❌ |
46
- | JSON Schema export | ✅ `toJSONSchema()` | ❌ N/A | ❌ | ❌ |
47
- | Transform/coerce | ✅ `.transform()`, `.coerce` | ❌ N/A | ❌ | ✅ |
48
- | Error messages | ✅ Structured `ZodError` | ⚠️ Single string | ⚠️ Verbose | ✅ |
49
- | Bundle size | ~2KB gzip (core) | ~3KB | ~15KB | ~12KB |
50
- | Weekly downloads | ~100M+ | N/A | ~8M | ~15M |
51
- | Performance (v4) | 14x faster strings, 7x faster arrays vs v3 | Adequate | Slower | Slower |
52
-
53
- ## API Overview
54
-
55
- ### Replacing Custom Schemas
56
-
57
- ```typescript
58
- import { z } from 'zod';
59
-
60
- // Replaces: ValidationSchemas.nonEmptyString()
61
- const NonEmptyString = z.string().min(1);
62
-
63
- // Replaces: ValidationSchemas.isoDate()
64
- const IsoDate = z.string().datetime();
65
-
66
- // Replaces: ValidationSchemas.stringArray(minLength)
67
- const StringArray = (min = 0) => z.array(z.string()).min(min);
68
-
69
- // Replaces: ValidationSchemas.entityArray()
70
- const Entity = z.object({
71
- name: z.string().min(1),
72
- entityType: z.string().min(1),
73
- observations: z.array(z.string()).default([]),
74
- });
75
- const EntityArray = z.array(Entity).min(1);
76
-
77
- // Replaces: ValidationSchemas.relationArray()
78
- const Relation = z.object({
79
- from: z.string().min(1),
80
- to: z.string().min(1),
81
- relationType: z.string().min(1),
82
- });
83
- const RelationArray = z.array(Relation);
84
- ```
85
-
86
- ### Structural Tension Chart Schema
87
-
88
- ```typescript
89
- const ChartSchema = z.object({
90
- id: z.string().min(1),
91
- desiredOutcome: z.string().min(1),
92
- currentReality: z.string().min(1),
93
- dueDate: z.string().datetime().optional(),
94
- actionSteps: z.array(z.object({
95
- title: z.string().min(1),
96
- status: z.enum(['pending', 'in_progress', 'done', 'blocked']),
97
- currentReality: z.string().optional(),
98
- })).default([]),
99
- createdAt: z.string().datetime(),
100
- updatedAt: z.string().datetime(),
101
- });
102
-
103
- type Chart = z.infer<typeof ChartSchema>; // TypeScript type auto-generated
104
- ```
105
-
106
- ### MCP Tool Argument Validation
107
-
108
- ```typescript
109
- import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
110
- import { z } from 'zod';
111
-
112
- const server = new McpServer({ name: 'coaiajs', version: '1.0.0' });
113
-
114
- // Zod schemas ARE the MCP tool input schemas — zero duplication
115
- server.tool(
116
- 'create_chart',
117
- 'Create a structural tension chart',
118
- {
119
- desiredOutcome: z.string().describe('What you want to CREATE'),
120
- currentReality: z.string().describe('Factual assessment of current state'),
121
- dueDate: z.string().datetime().optional().describe('Target date (ISO 8601)'),
122
- actionSteps: z.array(z.string()).optional().describe('Initial action steps'),
123
- },
124
- async ({ desiredOutcome, currentReality, dueDate, actionSteps }) => {
125
- // Arguments are already validated and typed
126
- const chart = await createChart({ desiredOutcome, currentReality, dueDate, actionSteps });
127
- return { content: [{ type: 'text', text: JSON.stringify(chart) }] };
128
- }
129
- );
130
- ```
131
-
132
- ### Pipeline Template Validation
133
-
134
- ```typescript
135
- // Replaces coaiapy's pipeline.py validate_variables()
136
- const PipelineVariable = z.object({
137
- name: z.string().min(1),
138
- type: z.enum(['string', 'number', 'boolean', 'list']).default('string'),
139
- required: z.boolean().default(true),
140
- default: z.unknown().optional(),
141
- choices: z.array(z.unknown()).optional(),
142
- });
143
-
144
- const PipelineTemplate = z.object({
145
- name: z.string().min(1),
146
- version: z.string().default('1.0'),
147
- variables: z.array(PipelineVariable).default([]),
148
- steps: z.array(z.object({
149
- name: z.string().min(1),
150
- observation_type: z.enum(['EVENT', 'SPAN', 'GENERATION']).default('EVENT'),
151
- conditional: z.string().optional(),
152
- })).min(1),
153
- });
154
-
155
- // Validate and get typed result
156
- function loadTemplate(raw: unknown): PipelineTemplate {
157
- return PipelineTemplate.parse(raw); // throws ZodError on invalid
158
- }
159
- ```
160
-
161
- ### Error Handling
162
-
163
- ```typescript
164
- import { z } from 'zod';
165
-
166
- function validateSafe<T>(schema: z.ZodSchema<T>, data: unknown): { valid: true; data: T } | { valid: false; error: string } {
167
- const result = schema.safeParse(data);
168
- if (result.success) {
169
- return { valid: true, data: result.data };
170
- }
171
- // Structured error messages
172
- const messages = result.error.issues.map(i => `${i.path.join('.')}: ${i.message}`);
173
- return { valid: false, error: messages.join('; ') };
174
- }
175
- ```
176
-
177
- ## Integration Plan
178
-
179
- 1. **Shared schemas:** `src/schemas/` directory with reusable Zod schemas
180
- - `chart.ts` — ChartSchema, ActionStepSchema
181
- - `entity.ts` — Entity, Relation schemas (replaces validation.ts)
182
- - `pipeline.ts` — PipelineTemplate, PipelineVariable
183
- - `session.ts` — Session, Trace schemas
184
- 2. **MCP tools:** Direct Zod schemas in tool definitions (no separate validation layer)
185
- 3. **Config validation:** Zod for config file/env var validation at startup
186
- 4. **JSON Schema export:** `toJSONSchema()` for documentation and interop
187
- 5. **Migration:** Delete coaia-narrative's `validation.ts`, import from `@coaiajs/schemas`
188
-
189
- ### @zod/mini for Future Frontend
190
-
191
- If coaiajs adds a web UI, use `@zod/mini` (~1.9KB) for client-side validation with the same schemas.
192
-
193
- ## Version & Ecosystem
194
-
195
- | Metric | Value |
196
- |--------|-------|
197
- | Current version | 4.3.6 (Jan 2026) |
198
- | Weekly downloads | ~100M+ |
199
- | TypeScript | First-class, type inference is the core value |
200
- | Bundle size | ~2KB gzip (core), ~1.9KB (@zod/mini) |
201
- | MCP SDK | Required peer dependency |
202
- | JSON Schema | `toJSONSchema()` built-in |
203
- | Node.js compat | Any (zero native deps) |
204
- | License | MIT |
205
-
206
- ## References
207
-
208
- - npm: https://www.npmjs.com/package/zod
209
- - GitHub: https://github.com/colinhacks/zod
210
- - v4 announcement: https://www.infoq.com/news/2025/08/zod-v4-available/
211
- - What's new in v4: https://basicutils.com/learn/zod/whats-new-in-zod-v4
212
- - MCP SDK peer dep: https://www.npmjs.com/package/@modelcontextprotocol/sdk
@@ -1,16 +0,0 @@
1
- {
2
- "name": "coaiajs-marketplace",
3
- "owner": { "name": "Guillaume Isabelle", "email": "jgi@jgwill.com", "url": "https://github.com/jgwill" },
4
- "metadata": { "description": "CoAIA Claude Code plugins", "version": "0.3.0" },
5
- "plugins": [
6
- {
7
- "name": "coaiajs-langfuse",
8
- "source": "./",
9
- "description": "CoAIA unified MCP — 64+ tools (structural tension, narrative graph, PDE, planning, Redis tash/fetch, Langfuse tracing).",
10
- "version": "0.3.0",
11
- "author": { "name": "Guillaume Isabelle", "url": "https://github.com/jgwill" },
12
- "license": "MIT",
13
- "keywords": ["coaia", "mcp", "structural-tension", "narrative", "pde", "planning", "langfuse"]
14
- }
15
- ]
16
- }
@@ -1,10 +0,0 @@
1
- {
2
- "name": "coaiajs-langfuse",
3
- "description": "CoAIA unified MCP for Claude Code — 64+ tools across structural-tension charts, narrative knowledge graph, Prompt Decomposition Engine (PDE), action planning, Redis tash/fetch, and Langfuse tracing. Bundles the published `coaiajs` npm package's `coaiajs-mcp` server via npx.",
4
- "version": "0.3.0",
5
- "author": { "name": "Guillaume Isabelle", "email": "jgi@jgwill.com", "url": "https://github.com/jgwill" },
6
- "homepage": "https://github.com/jgwill/coaiajs/tree/master/coaiajs-langfuse-claude-plugin",
7
- "repository": "https://github.com/jgwill/coaiajs",
8
- "license": "MIT",
9
- "keywords": ["coaia", "mcp", "structural-tension", "narrative", "pde", "planning", "langfuse"]
10
- }
@@ -1,8 +0,0 @@
1
- {
2
- "mcpServers": {
3
- "coaia": {
4
- "command": "npx",
5
- "args": ["-y", "--package=coaiajs", "coaiajs-mcp"]
6
- }
7
- }
8
- }
@@ -1,60 +0,0 @@
1
- # coaiajs-langfuse — Claude Code Plugin
2
-
3
- A Claude Code plugin that registers the `coaiajs-mcp` server — 64+ tools, 3 prompts, and 3 resources — as an MCP server inside Claude Code. It does not bundle its own copy of the server; it launches the published `coaiajs` npm package on demand via `npx`:
4
-
5
- ```
6
- npx -y --package=coaiajs coaiajs-mcp
7
- ```
8
-
9
- That command is declared in `.mcp.json` at the root of this plugin, which Claude Code auto-loads on install.
10
-
11
- ## Install
12
-
13
- From a marketplace source (GitHub):
14
-
15
- ```
16
- claude plugin marketplace add https://github.com/jgwill/coaiajs
17
- claude plugin install coaiajs-langfuse@coaiajs-marketplace
18
- ```
19
-
20
- Or from a local checkout:
21
-
22
- ```
23
- claude plugin marketplace add /a/src/coaiajs/coaiajs-langfuse-claude-plugin
24
- claude plugin install coaiajs-langfuse@coaiajs-marketplace
25
- ```
26
-
27
- Confirm it registered:
28
-
29
- ```
30
- claude plugin list
31
- ```
32
-
33
- ## Tool families
34
-
35
- - **Structural-tension charts** — desired outcome / current reality / action steps, the core CoAIA data model.
36
- - **Narrative knowledge graph** — entities, relations, and graph queries (from coaia-narrative).
37
- - **PDE (Prompt Decomposition Engine)** — decompose complex prompts into actionable intent maps.
38
- - **Action planning** — structural tension plans and action-step management (from coaia-planning).
39
- - **Redis tash/fetch** — SET/GET shorthand against a Redis store.
40
- - **Langfuse tracing** — trace, span, and observation tools for Langfuse-backed observability.
41
-
42
- ## Environment variables
43
-
44
- The server boots with no configuration — it connects to nothing at import time. Individual tool families activate only when their own credentials are present in the environment Claude Code runs in:
45
-
46
- | Variable | Used by |
47
- | --- | --- |
48
- | `REDIS_URL` | tash/fetch |
49
- | `OPENAI_API_KEY` | LLM-backed tools |
50
- | `LANGFUSE_PUBLIC_KEY` | Langfuse tracing |
51
- | `LANGFUSE_SECRET_KEY` | Langfuse tracing |
52
- | `LANGFUSE_BASE_URL` | Langfuse tracing |
53
- | `GITHUB_TOKEN` | GitHub-integration tools |
54
- | AWS credentials (`AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, etc.) | Polly audio tools |
55
-
56
- None of these are set by the plugin itself — they are inherited from whatever shell/environment Claude Code is launched in. Set them in your shell profile, `.env`, or however you normally manage secrets for this machine.
57
-
58
- ## Versioning
59
-
60
- This plugin tracks the published npm `coaiajs` package rather than vendoring source. `.mcp.json` calls `npx -y --package=coaiajs coaiajs-mcp`, which always resolves the latest published version at launch time. To pin a specific version, edit `.mcp.json` and change `--package=coaiajs` to `--package=coaiajs@<version>` (e.g. `coaiajs@0.3.0`).