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.
Files changed (162) hide show
  1. package/CLAUDE.md +56 -0
  2. package/KINSHIP.md +63 -0
  3. package/README.md +148 -0
  4. package/articles/academic/creative-orientation-vs-problem-solving.md +177 -0
  5. package/articles/academic/jsonl-knowledge-graphs-agent-memory.md +142 -0
  6. package/articles/academic/langfuse-observability-llm-pipelines.md +144 -0
  7. package/articles/academic/medicine-wheel-software-architecture.md +163 -0
  8. package/articles/academic/mmot-autonomous-agents.md +156 -0
  9. package/articles/academic/model-context-protocol-interagent.md +161 -0
  10. package/articles/academic/pde-prompt-decomposition.md +186 -0
  11. package/articles/academic/structural-tension-in-ai-agents.md +134 -0
  12. package/articles/reviews/mcp-protocol-design-review.md +170 -0
  13. package/articles/reviews/observability-ai-systems-review.md +176 -0
  14. package/articles/reviews/prompt-engineering-decomposition-review.md +184 -0
  15. package/articles/surveys/agent-orchestration-survey.md +186 -0
  16. package/articles/surveys/knowledge-graph-storage-survey.md +204 -0
  17. package/articles/surveys/structural-tension-methodology-survey.md +154 -0
  18. package/articles/technical/aws-sdk-v3-polly.md +270 -0
  19. package/articles/technical/commander-cli-framework.md +262 -0
  20. package/articles/technical/dotenv-config-patterns.md +360 -0
  21. package/articles/technical/ioredis-vs-redis.md +142 -0
  22. package/articles/technical/langfuse-js-sdk-vs-rest.md +191 -0
  23. package/articles/technical/mcp-sdk-typescript.md +291 -0
  24. package/articles/technical/octokit-github-api.md +293 -0
  25. package/articles/technical/openai-sdk-modern.md +231 -0
  26. package/articles/technical/yaml-parsing-node.md +266 -0
  27. package/articles/technical/zod-runtime-validation.md +212 -0
  28. package/dist/mcp/config.d.ts +14 -0
  29. package/dist/mcp/config.js +185 -0
  30. package/dist/mcp/server.d.ts +3 -0
  31. package/dist/mcp/server.js +324 -0
  32. package/dist/mcp/tools/coaiapy-tools.d.ts +8 -0
  33. package/dist/mcp/tools/coaiapy-tools.js +326 -0
  34. package/dist/mcp/tools/index.d.ts +3 -0
  35. package/dist/mcp/tools/index.js +3 -0
  36. package/dist/src/audio.d.ts +12 -0
  37. package/dist/src/audio.js +57 -0
  38. package/dist/src/cli-helpers.d.ts +9 -0
  39. package/dist/src/cli-helpers.js +78 -0
  40. package/dist/src/cli.d.ts +3 -0
  41. package/dist/src/cli.js +1086 -0
  42. package/dist/src/config.d.ts +15 -0
  43. package/dist/src/config.js +145 -0
  44. package/dist/src/environment.d.ts +44 -0
  45. package/dist/src/environment.js +146 -0
  46. package/dist/src/github.d.ts +47 -0
  47. package/dist/src/github.js +79 -0
  48. package/dist/src/langfuse/client.d.ts +30 -0
  49. package/dist/src/langfuse/client.js +75 -0
  50. package/dist/src/langfuse/comments.d.ts +16 -0
  51. package/dist/src/langfuse/comments.js +36 -0
  52. package/dist/src/langfuse/datasets.d.ts +19 -0
  53. package/dist/src/langfuse/datasets.js +140 -0
  54. package/dist/src/langfuse/index.d.ts +13 -0
  55. package/dist/src/langfuse/index.js +10 -0
  56. package/dist/src/langfuse/media.d.ts +11 -0
  57. package/dist/src/langfuse/media.js +167 -0
  58. package/dist/src/langfuse/observations.d.ts +18 -0
  59. package/dist/src/langfuse/observations.js +113 -0
  60. package/dist/src/langfuse/prompts.d.ts +14 -0
  61. package/dist/src/langfuse/prompts.js +127 -0
  62. package/dist/src/langfuse/scores.d.ts +54 -0
  63. package/dist/src/langfuse/scores.js +366 -0
  64. package/dist/src/langfuse/traces.d.ts +29 -0
  65. package/dist/src/langfuse/traces.js +225 -0
  66. package/dist/src/llm.d.ts +23 -0
  67. package/dist/src/llm.js +76 -0
  68. package/dist/src/narrative/graph-manager.d.ts +106 -0
  69. package/dist/src/narrative/graph-manager.js +915 -0
  70. package/dist/src/narrative/index.d.ts +9 -0
  71. package/dist/src/narrative/index.js +7 -0
  72. package/dist/src/narrative/markdown-export.d.ts +21 -0
  73. package/dist/src/narrative/markdown-export.js +383 -0
  74. package/dist/src/narrative/tool-definitions.d.ts +21 -0
  75. package/dist/src/narrative/tool-definitions.js +588 -0
  76. package/dist/src/narrative/tool-handlers.d.ts +11 -0
  77. package/dist/src/narrative/tool-handlers.js +462 -0
  78. package/dist/src/narrative/types.d.ts +2 -0
  79. package/dist/src/narrative/types.js +2 -0
  80. package/dist/src/narrative/validation.d.ts +29 -0
  81. package/dist/src/narrative/validation.js +144 -0
  82. package/dist/src/pde/index.d.ts +8 -0
  83. package/dist/src/pde/index.js +8 -0
  84. package/dist/src/pde/mcp-handlers.d.ts +7 -0
  85. package/dist/src/pde/mcp-handlers.js +300 -0
  86. package/dist/src/pde/mcp-tools.d.ts +15 -0
  87. package/dist/src/pde/mcp-tools.js +191 -0
  88. package/dist/src/pde/session-manager.d.ts +32 -0
  89. package/dist/src/pde/session-manager.js +205 -0
  90. package/dist/src/pde/stc-mapper.d.ts +26 -0
  91. package/dist/src/pde/stc-mapper.js +234 -0
  92. package/dist/src/pipeline/index.d.ts +2 -0
  93. package/dist/src/pipeline/index.js +3 -0
  94. package/dist/src/pipeline/template-engine.d.ts +20 -0
  95. package/dist/src/pipeline/template-engine.js +361 -0
  96. package/dist/src/planning/index.d.ts +7 -0
  97. package/dist/src/planning/index.js +7 -0
  98. package/dist/src/planning/mcp-handlers.d.ts +7 -0
  99. package/dist/src/planning/mcp-handlers.js +310 -0
  100. package/dist/src/planning/mcp-tools.d.ts +15 -0
  101. package/dist/src/planning/mcp-tools.js +145 -0
  102. package/dist/src/planning/plan-parser.d.ts +35 -0
  103. package/dist/src/planning/plan-parser.js +506 -0
  104. package/dist/src/redis.d.ts +21 -0
  105. package/dist/src/redis.js +78 -0
  106. package/dist/src/types.d.ts +244 -0
  107. package/dist/src/types.js +8 -0
  108. package/mcp/config.ts +196 -0
  109. package/mcp/server.ts +402 -0
  110. package/mcp/tools/coaiapy-tools.ts +364 -0
  111. package/mcp/tools/index.ts +4 -0
  112. package/package.json +52 -0
  113. package/rispecs/00-coaiajs-platform.spec.md +102 -0
  114. package/rispecs/01-core-config.spec.md +89 -0
  115. package/rispecs/02-redis-module.spec.md +62 -0
  116. package/rispecs/03-langfuse-module.spec.md +101 -0
  117. package/rispecs/04-narrative-engine.spec.md +185 -0
  118. package/rispecs/05-pde-engine.spec.md +112 -0
  119. package/rispecs/06-planning-engine.spec.md +128 -0
  120. package/rispecs/07-pipeline-templates.spec.md +97 -0
  121. package/rispecs/08-cli-interface.spec.md +134 -0
  122. package/rispecs/09-mcp-server.spec.md +140 -0
  123. package/rispecs/10-audio-module.spec.md +63 -0
  124. package/rispecs/KINSHIP.md +56 -0
  125. package/rispecs/README.md +100 -0
  126. package/src/audio.ts +76 -0
  127. package/src/cli-helpers.ts +86 -0
  128. package/src/cli.ts +1223 -0
  129. package/src/config.ts +172 -0
  130. package/src/environment.ts +171 -0
  131. package/src/github.ts +143 -0
  132. package/src/langfuse/client.ts +105 -0
  133. package/src/langfuse/comments.ts +52 -0
  134. package/src/langfuse/datasets.ts +178 -0
  135. package/src/langfuse/index.ts +33 -0
  136. package/src/langfuse/media.ts +193 -0
  137. package/src/langfuse/observations.ts +131 -0
  138. package/src/langfuse/prompts.ts +157 -0
  139. package/src/langfuse/scores.ts +456 -0
  140. package/src/langfuse/traces.ts +276 -0
  141. package/src/llm.ts +106 -0
  142. package/src/narrative/graph-manager.ts +1358 -0
  143. package/src/narrative/index.ts +32 -0
  144. package/src/narrative/markdown-export.ts +535 -0
  145. package/src/narrative/tool-definitions.ts +635 -0
  146. package/src/narrative/tool-handlers.ts +528 -0
  147. package/src/narrative/types.ts +9 -0
  148. package/src/narrative/validation.ts +179 -0
  149. package/src/pde/index.ts +8 -0
  150. package/src/pde/mcp-handlers.ts +359 -0
  151. package/src/pde/mcp-tools.ts +201 -0
  152. package/src/pde/session-manager.ts +248 -0
  153. package/src/pde/stc-mapper.ts +298 -0
  154. package/src/pipeline/index.ts +7 -0
  155. package/src/pipeline/template-engine.ts +398 -0
  156. package/src/planning/index.ts +13 -0
  157. package/src/planning/mcp-handlers.ts +369 -0
  158. package/src/planning/mcp-tools.ts +155 -0
  159. package/src/planning/plan-parser.ts +587 -0
  160. package/src/redis.ts +97 -0
  161. package/src/types.ts +280 -0
  162. package/tsconfig.json +26 -0
package/src/types.ts ADDED
@@ -0,0 +1,280 @@
1
+ // coaiajs/src/types.ts — Shared types
2
+ // Union of coaia-narrative + coaia-pde + coaia-planning type systems
3
+
4
+ // ─── Knowledge Graph Core ────────────────────────────────────────────
5
+
6
+ export interface Entity {
7
+ name: string;
8
+ entityType: string;
9
+ observations: string[];
10
+ metadata?: EntityMetadata;
11
+ }
12
+
13
+ export interface EntityMetadata {
14
+ dueDate?: string;
15
+ chartId?: string;
16
+ phase?: 'germination' | 'assimilation' | 'completion';
17
+ completionStatus?: boolean;
18
+ parentChart?: string;
19
+ parentActionStep?: string;
20
+ level?: number;
21
+ createdAt?: string;
22
+ updatedAt?: string;
23
+ direction?: string;
24
+ confidence?: number;
25
+ implicit?: boolean;
26
+ pdeId?: string;
27
+ act?: number;
28
+ type_dramatic?: string;
29
+ universes?: string[];
30
+ timestamp?: string;
31
+ elementsOfPerformance?: Array<{ description: string; type: 'DESIGN' | 'EXECUTION' }>;
32
+ mmotEvaluations?: Array<{
33
+ phase: 'acknowledge' | 'analyze' | 'update' | 'recommit';
34
+ assessment: string;
35
+ direction?: 'South' | 'East' | 'West' | 'North';
36
+ timestamp: string;
37
+ }>;
38
+ relationalAlignment?: {
39
+ assessed: boolean;
40
+ score: number | null;
41
+ principles: string[];
42
+ };
43
+ fourDirections?: {
44
+ north_vision: string | null;
45
+ east_intention: string | null;
46
+ south_emotion: string | null;
47
+ west_introspection: string | null;
48
+ };
49
+ narrative?: {
50
+ description: string;
51
+ prose: string;
52
+ lessons: string[];
53
+ };
54
+ order?: number;
55
+ }
56
+
57
+ export interface Relation {
58
+ from: string;
59
+ to: string;
60
+ relationType: string;
61
+ metadata?: RelationMetadata;
62
+ }
63
+
64
+ export interface RelationMetadata {
65
+ createdAt?: string;
66
+ strength?: number;
67
+ context?: string;
68
+ description?: string;
69
+ }
70
+
71
+ export interface KnowledgeGraph {
72
+ entities: Entity[];
73
+ relations: Relation[];
74
+ }
75
+
76
+ export interface McpToolResult {
77
+ content: Array<{ type: string; text: string }>;
78
+ isError?: boolean;
79
+ }
80
+
81
+ // ─── PDE Types ───────────────────────────────────────────────────────
82
+
83
+ export type Urgency = 'immediate' | 'session' | 'persistent';
84
+ export type Direction = 'east' | 'south' | 'west' | 'north';
85
+
86
+ export interface PrimaryIntent {
87
+ action: string;
88
+ target: string;
89
+ urgency: Urgency;
90
+ confidence: number;
91
+ }
92
+
93
+ export interface SecondaryIntent {
94
+ action: string;
95
+ target: string;
96
+ implicit: boolean;
97
+ dependency: string | null;
98
+ confidence: number;
99
+ }
100
+
101
+ export interface ContextRequirements {
102
+ files_needed: string[];
103
+ tools_required: string[];
104
+ assumptions: string[];
105
+ }
106
+
107
+ export interface ExpectedOutputs {
108
+ artifacts: string[];
109
+ updates: string[];
110
+ communications: string[];
111
+ }
112
+
113
+ export interface DirectionItem {
114
+ text: string;
115
+ confidence: number;
116
+ implicit: boolean;
117
+ }
118
+
119
+ export type DirectionMap = Record<Direction, DirectionItem[]>;
120
+
121
+ export interface ActionItem {
122
+ text: string;
123
+ direction: Direction;
124
+ dependency: string | null;
125
+ completed?: boolean;
126
+ }
127
+
128
+ export interface AmbiguityFlag {
129
+ text: string;
130
+ suggestion: string;
131
+ }
132
+
133
+ export interface DecompositionResult {
134
+ primary: PrimaryIntent;
135
+ secondary: SecondaryIntent[];
136
+ context: ContextRequirements;
137
+ outputs: ExpectedOutputs;
138
+ directions: DirectionMap;
139
+ actionStack: ActionItem[];
140
+ ambiguities: AmbiguityFlag[];
141
+ }
142
+
143
+ export interface StoredDecomposition {
144
+ id: string;
145
+ timestamp: string;
146
+ prompt: string;
147
+ result: DecompositionResult;
148
+ options: DecompositionOptions;
149
+ markdownPath?: string;
150
+ }
151
+
152
+ export interface DecompositionOptions {
153
+ extractImplicit: boolean;
154
+ mapDependencies: boolean;
155
+ }
156
+
157
+ export interface PdeSession {
158
+ type: 'pde_session';
159
+ sessionId: string;
160
+ originalPrompt: string;
161
+ masterChartId: string;
162
+ pdeDecompositionId?: string;
163
+ createdAt: string;
164
+ updatedAt: string;
165
+ status: 'active' | 'completed' | 'abandoned';
166
+ metadata?: Record<string, unknown>;
167
+ }
168
+
169
+ export const URGENCY_DAYS: Record<string, number> = {
170
+ immediate: 1,
171
+ session: 7,
172
+ persistent: 30,
173
+ };
174
+
175
+ // ─── Plan Parser Types ───────────────────────────────────────────────
176
+
177
+ export interface StructuralElement {
178
+ type: 'desired_outcome' | 'current_reality' | 'action_step' | 'observation';
179
+ content: string;
180
+ confidence: number;
181
+ sourceLines: { start: number; end: number };
182
+ telescopesInto?: StructuralTensionPlan;
183
+ }
184
+
185
+ export interface StructuralTensionPlan {
186
+ title: string;
187
+ filePath: string;
188
+ desiredOutcome: StructuralElement | null;
189
+ currentReality: StructuralElement | null;
190
+ actionSteps: StructuralElement[];
191
+ observations: string[];
192
+ metadata: {
193
+ parsedAt: string;
194
+ telescopeLevel: number;
195
+ parentAction?: string;
196
+ dueDate?: string;
197
+ completionStatus: 'pending' | 'in_progress' | 'completed';
198
+ };
199
+ }
200
+
201
+ // ─── Langfuse Types ──────────────────────────────────────────────────
202
+
203
+ export interface ScoreCategory {
204
+ label: string;
205
+ value: number;
206
+ }
207
+
208
+ export interface ScoreConfig {
209
+ name: string;
210
+ dataType: 'NUMERIC' | 'CATEGORICAL' | 'BOOLEAN';
211
+ description?: string;
212
+ categories?: ScoreCategory[];
213
+ minValue?: number;
214
+ maxValue?: number;
215
+ isArchived?: boolean;
216
+ }
217
+
218
+ // ─── Pipeline Types ──────────────────────────────────────────────────
219
+
220
+ export interface PipelineVariable {
221
+ name: string;
222
+ type: string;
223
+ required: boolean;
224
+ default?: string;
225
+ description?: string;
226
+ choices?: string[];
227
+ }
228
+
229
+ export interface PipelineStep {
230
+ name: string;
231
+ observationType: string;
232
+ description?: string;
233
+ parent?: string;
234
+ variables?: Record<string, string>;
235
+ metadata?: Record<string, unknown>;
236
+ conditional?: string;
237
+ }
238
+
239
+ export interface PipelineTemplate {
240
+ name: string;
241
+ version: string;
242
+ description: string;
243
+ author?: string;
244
+ createdAt?: string;
245
+ variables: PipelineVariable[];
246
+ steps: PipelineStep[];
247
+ extends?: string;
248
+ metadata?: Record<string, unknown>;
249
+ }
250
+
251
+ // ─── Config Types ────────────────────────────────────────────────────
252
+
253
+ export interface CoaiaConfig {
254
+ redis?: {
255
+ url?: string;
256
+ host?: string;
257
+ port?: number;
258
+ password?: string;
259
+ upstashUrl?: string;
260
+ upstashToken?: string;
261
+ };
262
+ langfuse?: {
263
+ publicKey?: string;
264
+ secretKey?: string;
265
+ baseUrl?: string;
266
+ };
267
+ openai?: {
268
+ apiKey?: string;
269
+ model?: string;
270
+ };
271
+ aws?: {
272
+ accessKeyId?: string;
273
+ secretAccessKey?: string;
274
+ region?: string;
275
+ };
276
+ github?: {
277
+ token?: string;
278
+ };
279
+ [key: string]: unknown;
280
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "strict": true,
7
+ "esModuleInterop": true,
8
+ "outDir": "./dist",
9
+ "rootDir": ".",
10
+ "declaration": true,
11
+ "declarationMap": true,
12
+ "sourceMap": true,
13
+ "skipLibCheck": true,
14
+ "forceConsistentCasingInFileNames": true,
15
+ "resolveJsonModule": true
16
+ },
17
+ "include": [
18
+ "src/**/*",
19
+ "mcp/**/*"
20
+ ],
21
+ "exclude": [
22
+ "node_modules",
23
+ "dist",
24
+ "tests"
25
+ ]
26
+ }