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
@@ -0,0 +1,205 @@
1
+ /**
2
+ * Session Manager — JSONL persistence for PDE sessions in .coaia/pde/<UUID>.jsonl
3
+ * Ported from coaia-pde/src/session-manager.ts
4
+ */
5
+ import { promises as fs } from 'fs';
6
+ import path from 'path';
7
+ import { v4 as uuidv4 } from 'uuid';
8
+ function serializeEntity(entity) {
9
+ return JSON.stringify({ type: 'entity', ...entity });
10
+ }
11
+ function serializeRelation(relation) {
12
+ return JSON.stringify({ type: 'relation', ...relation });
13
+ }
14
+ export class SessionManager {
15
+ baseDir;
16
+ constructor(baseDir) {
17
+ this.baseDir = baseDir || path.join(process.cwd(), '.coaia', 'pde');
18
+ }
19
+ getSessionPath(sessionId) {
20
+ return path.join(this.baseDir, `${sessionId}.jsonl`);
21
+ }
22
+ async ensureBaseDir() {
23
+ await fs.mkdir(this.baseDir, { recursive: true });
24
+ }
25
+ async initSession(originalPrompt, masterChartId, pdeDecompositionId) {
26
+ await this.ensureBaseDir();
27
+ const sessionId = uuidv4();
28
+ const now = new Date().toISOString();
29
+ const session = {
30
+ type: 'pde_session',
31
+ sessionId,
32
+ originalPrompt,
33
+ masterChartId,
34
+ pdeDecompositionId,
35
+ createdAt: now,
36
+ updatedAt: now,
37
+ status: 'active'
38
+ };
39
+ const sessionPath = this.getSessionPath(sessionId);
40
+ await fs.writeFile(sessionPath, JSON.stringify(session) + '\n');
41
+ return session;
42
+ }
43
+ async loadSession(sessionId) {
44
+ const sessionPath = this.getSessionPath(sessionId);
45
+ const data = await fs.readFile(sessionPath, 'utf-8');
46
+ const lines = data.split('\n').filter(line => line.trim());
47
+ let session = null;
48
+ const entities = [];
49
+ const relations = [];
50
+ for (const line of lines) {
51
+ const item = JSON.parse(line);
52
+ if (item.type === 'pde_session') {
53
+ session = item;
54
+ }
55
+ else if (item.type === 'entity') {
56
+ const { type: _discriminator, ...entity } = item;
57
+ entities.push(entity);
58
+ }
59
+ else if (item.type === 'relation') {
60
+ const { type: _discriminator, ...relation } = item;
61
+ relations.push(relation);
62
+ }
63
+ }
64
+ if (!session) {
65
+ throw new Error(`Session ${sessionId} not found or corrupted`);
66
+ }
67
+ return { session, entities, relations };
68
+ }
69
+ async appendEntity(sessionId, entity) {
70
+ const sessionPath = this.getSessionPath(sessionId);
71
+ await fs.appendFile(sessionPath, serializeEntity(entity) + '\n');
72
+ }
73
+ async appendRelation(sessionId, relation) {
74
+ const sessionPath = this.getSessionPath(sessionId);
75
+ await fs.appendFile(sessionPath, serializeRelation(relation) + '\n');
76
+ }
77
+ async updateSession(sessionId, updates) {
78
+ const { session, entities, relations } = await this.loadSession(sessionId);
79
+ const updatedSession = { ...session, ...updates, updatedAt: new Date().toISOString() };
80
+ const sessionPath = this.getSessionPath(sessionId);
81
+ const lines = [
82
+ JSON.stringify(updatedSession),
83
+ ...entities.map(e => serializeEntity(e)),
84
+ ...relations.map(r => serializeRelation(r))
85
+ ];
86
+ await fs.writeFile(sessionPath, lines.join('\n') + '\n');
87
+ }
88
+ async updateEntity(sessionId, entityName, updates) {
89
+ const { session, entities, relations } = await this.loadSession(sessionId);
90
+ const entityIndex = entities.findIndex(e => e.name === entityName);
91
+ if (entityIndex === -1) {
92
+ throw new Error(`Entity ${entityName} not found in session ${sessionId}`);
93
+ }
94
+ entities[entityIndex] = { ...entities[entityIndex], ...updates };
95
+ if (entities[entityIndex].metadata) {
96
+ entities[entityIndex].metadata.updatedAt = new Date().toISOString();
97
+ }
98
+ const sessionPath = this.getSessionPath(sessionId);
99
+ const lines = [
100
+ JSON.stringify(session),
101
+ ...entities.map(e => serializeEntity(e)),
102
+ ...relations.map(r => serializeRelation(r))
103
+ ];
104
+ await fs.writeFile(sessionPath, lines.join('\n') + '\n');
105
+ }
106
+ async listSessions() {
107
+ try {
108
+ await this.ensureBaseDir();
109
+ const files = await fs.readdir(this.baseDir);
110
+ const sessions = [];
111
+ for (const file of files) {
112
+ if (file.endsWith('.jsonl')) {
113
+ try {
114
+ const sessionId = file.replace('.jsonl', '');
115
+ const { session } = await this.loadSession(sessionId);
116
+ sessions.push(session);
117
+ }
118
+ catch {
119
+ // Skip corrupted files
120
+ }
121
+ }
122
+ }
123
+ return sessions.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime());
124
+ }
125
+ catch {
126
+ return [];
127
+ }
128
+ }
129
+ async deleteSession(sessionId) {
130
+ const sessionPath = this.getSessionPath(sessionId);
131
+ await fs.unlink(sessionPath);
132
+ }
133
+ async getSessionFilePath(sessionId) {
134
+ return this.getSessionPath(sessionId);
135
+ }
136
+ // =========================================================================
137
+ // PDE Decomposition File Access (.pde/ directory)
138
+ // =========================================================================
139
+ async listPdeDecompositions(workdir) {
140
+ const pdeDir = path.join(workdir || process.cwd(), '.pde');
141
+ try {
142
+ const entries = await fs.readdir(pdeDir);
143
+ const results = [];
144
+ for (const entry of entries) {
145
+ if (!entry.endsWith('.json'))
146
+ continue;
147
+ try {
148
+ const filePath = path.join(pdeDir, entry);
149
+ const data = await fs.readFile(filePath, 'utf-8');
150
+ const stored = JSON.parse(data);
151
+ if (stored.id && stored.result) {
152
+ results.push({
153
+ id: stored.id,
154
+ timestamp: stored.timestamp,
155
+ prompt: stored.prompt,
156
+ });
157
+ }
158
+ }
159
+ catch {
160
+ // Skip invalid files
161
+ }
162
+ }
163
+ return results.sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime());
164
+ }
165
+ catch {
166
+ return [];
167
+ }
168
+ }
169
+ async loadPdeDecomposition(id, workdir) {
170
+ const pdeDir = path.join(workdir || process.cwd(), '.pde');
171
+ // Try direct {id}.json file first
172
+ const directPath = path.join(pdeDir, `${id}.json`);
173
+ try {
174
+ const data = await fs.readFile(directPath, 'utf-8');
175
+ return JSON.parse(data);
176
+ }
177
+ catch {
178
+ // Not found as direct file — scan for matching id
179
+ }
180
+ // Scan directory for a .json file whose parsed id matches
181
+ try {
182
+ const entries = await fs.readdir(pdeDir);
183
+ for (const entry of entries) {
184
+ if (!entry.endsWith('.json'))
185
+ continue;
186
+ try {
187
+ const filePath = path.join(pdeDir, entry);
188
+ const data = await fs.readFile(filePath, 'utf-8');
189
+ const parsed = JSON.parse(data);
190
+ if (parsed.id === id)
191
+ return parsed;
192
+ }
193
+ catch {
194
+ // Skip invalid
195
+ }
196
+ }
197
+ }
198
+ catch {
199
+ // Directory not found
200
+ }
201
+ return null;
202
+ }
203
+ }
204
+ export const sessionManager = new SessionManager();
205
+ //# sourceMappingURL=session-manager.js.map
@@ -0,0 +1,26 @@
1
+ /**
2
+ * STC Mapper — Transforms mcp-pde DecompositionResult into Entity[]/Relation[]
3
+ * Ported from coaia-pde/src/stc-mapper.ts
4
+ */
5
+ import type { DecompositionResult, Entity, Relation } from '../types.js';
6
+ export declare class StcMapper {
7
+ /**
8
+ * Core method: Transform a DecompositionResult into Entity[]/Relation[].
9
+ */
10
+ mapDecompositionToChart(result: DecompositionResult, originalPrompt: string, options?: {
11
+ pdeId?: string;
12
+ dueDate?: string;
13
+ }): {
14
+ entities: Entity[];
15
+ relations: Relation[];
16
+ chartId: string;
17
+ };
18
+ private addDependencyRelation;
19
+ private formatDesiredOutcome;
20
+ private formatCurrentReality;
21
+ private mapDirectionsToFourDirections;
22
+ private calculateDueDate;
23
+ private distributeActionDates;
24
+ }
25
+ export declare const stcMapper: StcMapper;
26
+ //# sourceMappingURL=stc-mapper.d.ts.map
@@ -0,0 +1,234 @@
1
+ /**
2
+ * STC Mapper — Transforms mcp-pde DecompositionResult into Entity[]/Relation[]
3
+ * Ported from coaia-pde/src/stc-mapper.ts
4
+ */
5
+ import { v4 as uuidv4 } from 'uuid';
6
+ import { URGENCY_DAYS } from '../types.js';
7
+ export class StcMapper {
8
+ /**
9
+ * Core method: Transform a DecompositionResult into Entity[]/Relation[].
10
+ */
11
+ mapDecompositionToChart(result, originalPrompt, options) {
12
+ const chartId = `chart_${uuidv4().substring(0, 8)}`;
13
+ const now = new Date().toISOString();
14
+ const dueDate = options?.dueDate || this.calculateDueDate(result.primary.urgency);
15
+ const fourDirections = this.mapDirectionsToFourDirections(result.directions);
16
+ const entities = [];
17
+ const relations = [];
18
+ // 1. Master chart entity
19
+ entities.push({
20
+ name: `${chartId}_chart`,
21
+ entityType: 'structural_tension_chart',
22
+ observations: [`Master chart for: ${result.primary.action} ${result.primary.target}`],
23
+ metadata: {
24
+ chartId,
25
+ dueDate,
26
+ level: 0,
27
+ phase: 'germination',
28
+ createdAt: now,
29
+ updatedAt: now,
30
+ pdeId: options?.pdeId,
31
+ fourDirections,
32
+ }
33
+ });
34
+ // 2. Desired outcome entity
35
+ const desiredOutcomeObs = [this.formatDesiredOutcome(result.primary)];
36
+ for (const a of result.outputs.artifacts)
37
+ desiredOutcomeObs.push(`Artifact: ${a}`);
38
+ for (const u of result.outputs.updates)
39
+ desiredOutcomeObs.push(`Update: ${u}`);
40
+ for (const c of result.outputs.communications)
41
+ desiredOutcomeObs.push(`Communication: ${c}`);
42
+ entities.push({
43
+ name: `${chartId}_desired_outcome`,
44
+ entityType: 'desired_outcome',
45
+ observations: desiredOutcomeObs,
46
+ metadata: {
47
+ chartId,
48
+ confidence: result.primary.confidence,
49
+ createdAt: now,
50
+ updatedAt: now,
51
+ }
52
+ });
53
+ // 3. Current reality entity
54
+ entities.push({
55
+ name: `${chartId}_current_reality`,
56
+ entityType: 'current_reality',
57
+ observations: this.formatCurrentReality(result.context, result.ambiguities),
58
+ metadata: {
59
+ chartId,
60
+ createdAt: now,
61
+ updatedAt: now,
62
+ }
63
+ });
64
+ // 4. Action step entities from secondary[] + actionStack[]
65
+ const totalActionCount = result.secondary.length + result.actionStack.length;
66
+ const actionDueDates = this.distributeActionDates(new Date(), new Date(dueDate), totalActionCount);
67
+ let actionIndex = 0;
68
+ for (const sec of result.secondary) {
69
+ const actionName = `${chartId}_action_${++actionIndex}`;
70
+ entities.push({
71
+ name: actionName,
72
+ entityType: 'action_step',
73
+ observations: [`${sec.action} ${sec.target}`],
74
+ metadata: {
75
+ chartId,
76
+ dueDate: actionDueDates[actionIndex - 1]?.toISOString(),
77
+ completionStatus: false,
78
+ level: 1,
79
+ parentChart: chartId,
80
+ implicit: sec.implicit,
81
+ confidence: sec.confidence,
82
+ createdAt: now,
83
+ updatedAt: now,
84
+ }
85
+ });
86
+ relations.push({
87
+ from: `${chartId}_chart`,
88
+ to: actionName,
89
+ relationType: 'has_action_step',
90
+ metadata: { createdAt: now }
91
+ });
92
+ relations.push({
93
+ from: actionName,
94
+ to: `${chartId}_desired_outcome`,
95
+ relationType: 'advances_toward',
96
+ metadata: { createdAt: now }
97
+ });
98
+ if (sec.dependency) {
99
+ this.addDependencyRelation(entities, relations, actionName, sec.dependency, now);
100
+ }
101
+ }
102
+ for (const item of result.actionStack) {
103
+ const actionName = `${chartId}_action_${++actionIndex}`;
104
+ entities.push({
105
+ name: actionName,
106
+ entityType: 'action_step',
107
+ observations: [item.text],
108
+ metadata: {
109
+ chartId,
110
+ dueDate: actionDueDates[actionIndex - 1]?.toISOString(),
111
+ completionStatus: item.completed || false,
112
+ level: 1,
113
+ parentChart: chartId,
114
+ direction: item.direction,
115
+ createdAt: now,
116
+ updatedAt: now,
117
+ }
118
+ });
119
+ relations.push({
120
+ from: `${chartId}_chart`,
121
+ to: actionName,
122
+ relationType: 'has_action_step',
123
+ metadata: { createdAt: now }
124
+ });
125
+ relations.push({
126
+ from: actionName,
127
+ to: `${chartId}_desired_outcome`,
128
+ relationType: 'advances_toward',
129
+ metadata: { createdAt: now }
130
+ });
131
+ if (item.dependency) {
132
+ this.addDependencyRelation(entities, relations, actionName, item.dependency, now);
133
+ }
134
+ }
135
+ // 5. Structural relations
136
+ relations.push({
137
+ from: `${chartId}_chart`,
138
+ to: `${chartId}_desired_outcome`,
139
+ relationType: 'has_desired_outcome',
140
+ metadata: { createdAt: now }
141
+ }, {
142
+ from: `${chartId}_chart`,
143
+ to: `${chartId}_current_reality`,
144
+ relationType: 'has_current_reality',
145
+ metadata: { createdAt: now }
146
+ }, {
147
+ from: `${chartId}_current_reality`,
148
+ to: `${chartId}_desired_outcome`,
149
+ relationType: 'creates_tension_with',
150
+ metadata: { createdAt: now }
151
+ });
152
+ return { entities, relations, chartId };
153
+ }
154
+ addDependencyRelation(entities, relations, fromName, dependency, now) {
155
+ const depEntity = entities.find(e => e.entityType === 'action_step' && e.observations[0]?.includes(dependency));
156
+ if (depEntity) {
157
+ relations.push({
158
+ from: fromName,
159
+ to: depEntity.name,
160
+ relationType: 'depends_on',
161
+ metadata: { createdAt: now, context: dependency }
162
+ });
163
+ }
164
+ }
165
+ formatDesiredOutcome(primary) {
166
+ const { action, target } = primary;
167
+ const resultPhrases = {
168
+ create: `Completed ${target}`,
169
+ build: `Functional ${target}`,
170
+ implement: `Working ${target}`,
171
+ write: `Finished ${target}`,
172
+ design: `Complete design for ${target}`,
173
+ develop: `Deployed ${target}`,
174
+ analyze: `Clear understanding of ${target}`,
175
+ integrate: `Fully integrated ${target}`,
176
+ test: `Validated ${target}`,
177
+ fix: `Resolved ${target}`,
178
+ refactor: `Refactored ${target}`,
179
+ };
180
+ for (const [verb, phrase] of Object.entries(resultPhrases)) {
181
+ if (action.startsWith(verb)) {
182
+ return phrase;
183
+ }
184
+ }
185
+ return `Completed: ${action} ${target}`;
186
+ }
187
+ formatCurrentReality(context, ambiguities) {
188
+ const observations = [];
189
+ if (context.files_needed.length > 0) {
190
+ observations.push(`Files to reference: ${context.files_needed.join(', ')}`);
191
+ }
192
+ if (context.tools_required.length > 0) {
193
+ observations.push(`Tools available: ${context.tools_required.join(', ')}`);
194
+ }
195
+ for (const assumption of context.assumptions) {
196
+ observations.push(`Assumption: ${assumption}`);
197
+ }
198
+ for (const ambiguity of ambiguities) {
199
+ observations.push(`⚠️ Ambiguity: ${ambiguity.text} — Suggestion: ${ambiguity.suggestion}`);
200
+ }
201
+ if (observations.length === 0) {
202
+ observations.push('Starting point: No prior work on this goal');
203
+ }
204
+ return observations;
205
+ }
206
+ mapDirectionsToFourDirections(directions) {
207
+ const join = (items) => items.length > 0 ? items.map(i => i.text).join('; ') : null;
208
+ return {
209
+ north_vision: join(directions.north || []),
210
+ east_intention: join(directions.east || []),
211
+ south_emotion: join(directions.south || []),
212
+ west_introspection: join(directions.west || []),
213
+ };
214
+ }
215
+ calculateDueDate(urgency) {
216
+ const days = URGENCY_DAYS[urgency] || URGENCY_DAYS['session'];
217
+ const date = new Date();
218
+ date.setDate(date.getDate() + days);
219
+ return date.toISOString();
220
+ }
221
+ distributeActionDates(start, end, count) {
222
+ if (count === 0)
223
+ return [];
224
+ const totalTime = end.getTime() - start.getTime();
225
+ const interval = totalTime / (count + 1);
226
+ const dates = [];
227
+ for (let i = 1; i <= count; i++) {
228
+ dates.push(new Date(start.getTime() + interval * i));
229
+ }
230
+ return dates;
231
+ }
232
+ }
233
+ export const stcMapper = new StcMapper();
234
+ //# sourceMappingURL=stc-mapper.js.map
@@ -0,0 +1,2 @@
1
+ export { TemplateLoader, TemplateRenderer, MobileTemplateEngine, } from './template-engine.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,3 @@
1
+ // coaiajs/src/pipeline/index.ts — Barrel export
2
+ export { TemplateLoader, TemplateRenderer, MobileTemplateEngine, } from './template-engine.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,20 @@
1
+ import type { PipelineTemplate, PipelineStep } from '../types.js';
2
+ export declare class MobileTemplateEngine {
3
+ renderString(text: string, variables: Record<string, string>): string;
4
+ renderDict(data: Record<string, unknown>, variables: Record<string, string>): Record<string, unknown>;
5
+ private renderList;
6
+ }
7
+ export declare class TemplateLoader {
8
+ private searchPaths;
9
+ constructor();
10
+ private getSearchPaths;
11
+ listTemplates(includePath?: boolean): Array<Record<string, unknown>>;
12
+ loadTemplate(name: string): PipelineTemplate | null;
13
+ saveTemplate(template: PipelineTemplate, location?: 'user' | 'project'): void;
14
+ }
15
+ export declare class TemplateRenderer {
16
+ private engine;
17
+ renderTemplate(template: PipelineTemplate, variables: Record<string, string>): PipelineStep[];
18
+ renderWithJudgeIntegration(template: PipelineTemplate, variables: Record<string, string>, enableJudge?: boolean): PipelineStep[];
19
+ }
20
+ //# sourceMappingURL=template-engine.d.ts.map