coaiajs 0.4.2 → 0.5.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 (84) hide show
  1. package/README.md +7 -4
  2. package/agents/custom_gpt/ceremony-media-proxy.instructions.md +86 -0
  3. package/agents/custom_gpt/ceremony-media-proxy.yml +158 -0
  4. package/agents/custom_gpt/ceremony-observations.instructions.md +38 -5
  5. package/agents/custom_gpt/ceremony-observations.yml +737 -287
  6. package/dist/mcp/config.d.ts.map +1 -1
  7. package/dist/mcp/config.js +13 -1
  8. package/dist/mcp/config.js.map +1 -1
  9. package/dist/mcp/server.js +11 -1
  10. package/dist/mcp/server.js.map +1 -1
  11. package/dist/src/cli.js +17 -4
  12. package/dist/src/cli.js.map +1 -1
  13. package/dist/src/config.d.ts +2 -0
  14. package/dist/src/config.d.ts.map +1 -1
  15. package/dist/src/config.js +10 -2
  16. package/dist/src/config.js.map +1 -1
  17. package/dist/src/index.d.ts +1 -1
  18. package/dist/src/index.d.ts.map +1 -1
  19. package/dist/src/index.js +1 -1
  20. package/dist/src/index.js.map +1 -1
  21. package/dist/src/langfuse/index.d.ts +2 -1
  22. package/dist/src/langfuse/index.d.ts.map +1 -1
  23. package/dist/src/langfuse/index.js +1 -1
  24. package/dist/src/langfuse/index.js.map +1 -1
  25. package/dist/src/langfuse/media.d.ts +30 -0
  26. package/dist/src/langfuse/media.d.ts.map +1 -1
  27. package/dist/src/langfuse/media.js +128 -77
  28. package/dist/src/langfuse/media.js.map +1 -1
  29. package/dist/src/media-upload-proxy.d.ts +32 -0
  30. package/dist/src/media-upload-proxy.d.ts.map +1 -0
  31. package/dist/src/media-upload-proxy.js +210 -0
  32. package/dist/src/media-upload-proxy.js.map +1 -0
  33. package/dist/src/narrative/argument-hygiene.d.ts +46 -0
  34. package/dist/src/narrative/argument-hygiene.d.ts.map +1 -0
  35. package/dist/src/narrative/argument-hygiene.js +155 -0
  36. package/dist/src/narrative/argument-hygiene.js.map +1 -0
  37. package/dist/src/narrative/contract.d.ts +200 -0
  38. package/dist/src/narrative/contract.d.ts.map +1 -0
  39. package/dist/src/narrative/contract.js +274 -0
  40. package/dist/src/narrative/contract.js.map +1 -0
  41. package/dist/src/narrative/github-bridge.d.ts +23 -0
  42. package/dist/src/narrative/github-bridge.d.ts.map +1 -0
  43. package/dist/src/narrative/github-bridge.js +320 -0
  44. package/dist/src/narrative/github-bridge.js.map +1 -0
  45. package/dist/src/narrative/graph-manager.d.ts +83 -2
  46. package/dist/src/narrative/graph-manager.d.ts.map +1 -1
  47. package/dist/src/narrative/graph-manager.js +444 -54
  48. package/dist/src/narrative/graph-manager.js.map +1 -1
  49. package/dist/src/narrative/index.d.ts +24 -3
  50. package/dist/src/narrative/index.d.ts.map +1 -1
  51. package/dist/src/narrative/index.js +36 -15
  52. package/dist/src/narrative/index.js.map +1 -1
  53. package/dist/src/narrative/jsonl-preservation.d.ts +26 -0
  54. package/dist/src/narrative/jsonl-preservation.d.ts.map +1 -0
  55. package/dist/src/narrative/jsonl-preservation.js +293 -0
  56. package/dist/src/narrative/jsonl-preservation.js.map +1 -0
  57. package/dist/src/narrative/jsonl-records.d.ts +31 -0
  58. package/dist/src/narrative/jsonl-records.d.ts.map +1 -0
  59. package/dist/src/narrative/jsonl-records.js +69 -0
  60. package/dist/src/narrative/jsonl-records.js.map +1 -0
  61. package/dist/src/narrative/tool-definitions.d.ts +2 -1
  62. package/dist/src/narrative/tool-definitions.d.ts.map +1 -1
  63. package/dist/src/narrative/tool-definitions.js +134 -1
  64. package/dist/src/narrative/tool-definitions.js.map +1 -1
  65. package/dist/src/narrative/tool-handlers.d.ts.map +1 -1
  66. package/dist/src/narrative/tool-handlers.js +203 -20
  67. package/dist/src/narrative/tool-handlers.js.map +1 -1
  68. package/dist/src/narrative/types.d.ts +1 -1
  69. package/dist/src/narrative/types.d.ts.map +1 -1
  70. package/dist/src/narrative/validation.d.ts +13 -2
  71. package/dist/src/narrative/validation.d.ts.map +1 -1
  72. package/dist/src/narrative/validation.js +19 -4
  73. package/dist/src/narrative/validation.js.map +1 -1
  74. package/dist/src/redis.d.ts +10 -5
  75. package/dist/src/redis.d.ts.map +1 -1
  76. package/dist/src/redis.js +94 -8
  77. package/dist/src/redis.js.map +1 -1
  78. package/dist/src/types.d.ts +189 -0
  79. package/dist/src/types.d.ts.map +1 -1
  80. package/dist/src/types.js.map +1 -1
  81. package/llms-full.txt +73 -7
  82. package/llms.txt +5 -3
  83. package/package.json +11 -2
  84. package/rispecs/03-langfuse-module.spec.md +2 -1
@@ -0,0 +1,293 @@
1
+ import { promises as fs } from 'fs';
2
+ import path from 'path';
3
+ // Record classification lives in a pure module so the read contract can import the
4
+ // SAME predicates rather than re-implementing them. See src/jsonl-records.ts.
5
+ import { isObject, removeUndefined, isEntityRecord, isLegacyNarrativeBeatRecord, isRelationRecord, normalizeLegacyNarrativeBeat } from './jsonl-records.js';
6
+ const ENTITY_TOP_LEVEL_KEYS = new Set(['type', 'name', 'entityType', 'observations', 'metadata']);
7
+ const RELATION_TOP_LEVEL_KEYS = new Set(['type', 'from', 'to', 'relationType', 'metadata']);
8
+ const NARRATIVE_BEAT_TOP_LEVEL_KEYS = new Set([
9
+ ...ENTITY_TOP_LEVEL_KEYS,
10
+ 'narrative',
11
+ 'relational_alignment',
12
+ 'four_directions'
13
+ ]);
14
+ const MUTABLE_METADATA_KEYS = new Set([
15
+ 'dueDate',
16
+ 'chartId',
17
+ 'phase',
18
+ 'completionStatus',
19
+ 'completedAt',
20
+ 'parentChart',
21
+ 'parentActionStep',
22
+ 'level',
23
+ 'createdAt',
24
+ 'updatedAt',
25
+ 'act',
26
+ 'type_dramatic',
27
+ 'universes',
28
+ 'timestamp',
29
+ 'elementsOfPerformance',
30
+ 'mmotEvaluations',
31
+ 'relationalAlignment',
32
+ 'fourDirections',
33
+ 'narrative',
34
+ 'isTelescopedChart',
35
+ 'telescopedChartId'
36
+ ]);
37
+ function cloneJson(value) {
38
+ return value === undefined ? value : JSON.parse(JSON.stringify(value));
39
+ }
40
+ function deepEqual(left, right) {
41
+ return JSON.stringify(left) === JSON.stringify(right);
42
+ }
43
+ function relationKey(relation) {
44
+ return `${relation.from}\u0000${relation.to}\u0000${relation.relationType}`;
45
+ }
46
+ function mergePreservedMetadata(originalMetadata, currentMetadata) {
47
+ if (!isObject(originalMetadata) && !isObject(currentMetadata)) {
48
+ return undefined;
49
+ }
50
+ const merged = {
51
+ ...(isObject(currentMetadata) ? currentMetadata : {})
52
+ };
53
+ if (isObject(originalMetadata)) {
54
+ for (const [key, value] of Object.entries(originalMetadata)) {
55
+ if (!(key in merged) && (!MUTABLE_METADATA_KEYS.has(key) || key === 'github')) {
56
+ merged[key] = cloneJson(value);
57
+ }
58
+ }
59
+ }
60
+ return merged;
61
+ }
62
+ function serializeEntity(entity, original) {
63
+ const originalType = original?.type;
64
+ const metadata = mergePreservedMetadata(original?.metadata, entity.metadata);
65
+ if (originalType === 'narrative_beat') {
66
+ const record = {
67
+ ...original,
68
+ type: 'narrative_beat',
69
+ name: entity.name,
70
+ observations: entity.observations
71
+ };
72
+ if ('entityType' in (original || {})) {
73
+ record.entityType = entity.entityType;
74
+ }
75
+ if (metadata) {
76
+ record.metadata = metadata;
77
+ }
78
+ if ('narrative' in (original || {}) && entity.metadata?.narrative !== undefined) {
79
+ record.narrative = cloneJson(entity.metadata.narrative);
80
+ }
81
+ if ('relational_alignment' in (original || {}) && entity.metadata?.relationalAlignment !== undefined) {
82
+ record.relational_alignment = cloneJson(entity.metadata.relationalAlignment);
83
+ }
84
+ if ('four_directions' in (original || {}) && entity.metadata?.fourDirections !== undefined) {
85
+ record.four_directions = cloneJson(entity.metadata.fourDirections);
86
+ }
87
+ return removeUndefined(record);
88
+ }
89
+ return removeUndefined({
90
+ ...original,
91
+ ...entity,
92
+ type: 'entity',
93
+ metadata
94
+ });
95
+ }
96
+ function serializeRelation(relation, original) {
97
+ return removeUndefined({
98
+ ...original,
99
+ ...relation,
100
+ type: 'relation',
101
+ metadata: mergePreservedMetadata(original?.metadata, relation.metadata)
102
+ });
103
+ }
104
+ function findRecord(records, key) {
105
+ return records.find((record) => {
106
+ if ((isEntityRecord(record) || isLegacyNarrativeBeatRecord(record)) && record.name === key) {
107
+ return true;
108
+ }
109
+ if (isRelationRecord(record)) {
110
+ return relationKey(record) === key;
111
+ }
112
+ return false;
113
+ });
114
+ }
115
+ function validateRecordPreservation(beforeRecords, afterRecords, graph) {
116
+ if (!beforeRecords || beforeRecords.length === 0) {
117
+ return;
118
+ }
119
+ const currentEntityNames = new Set(graph.entities.map((entity) => entity.name));
120
+ const currentRelationKeys = new Set(graph.relations.map((relation) => relationKey(relation)));
121
+ const failures = [];
122
+ for (const before of beforeRecords) {
123
+ if (isEntityRecord(before) || isLegacyNarrativeBeatRecord(before)) {
124
+ const name = before.name;
125
+ if (!currentEntityNames.has(name)) {
126
+ continue;
127
+ }
128
+ const after = findRecord(afterRecords, name);
129
+ if (!after) {
130
+ failures.push(`${name}: record missing after write`);
131
+ continue;
132
+ }
133
+ if (before.type === 'narrative_beat' && after.type !== 'narrative_beat') {
134
+ failures.push(`${name}: legacy narrative_beat record type was flattened`);
135
+ }
136
+ const knownKeys = before.type === 'narrative_beat'
137
+ ? NARRATIVE_BEAT_TOP_LEVEL_KEYS
138
+ : ENTITY_TOP_LEVEL_KEYS;
139
+ for (const key of Object.keys(before)) {
140
+ if (!knownKeys.has(key) && !deepEqual(before[key], after[key])) {
141
+ failures.push(`${name}: top-level extension field "${key}" was not preserved`);
142
+ }
143
+ }
144
+ validateMetadata(name, before.metadata, after.metadata, failures);
145
+ }
146
+ if (isRelationRecord(before)) {
147
+ const key = relationKey(before);
148
+ if (!currentRelationKeys.has(key)) {
149
+ continue;
150
+ }
151
+ const after = findRecord(afterRecords, key);
152
+ if (!after) {
153
+ failures.push(`${key}: relation missing after write`);
154
+ continue;
155
+ }
156
+ for (const topLevelKey of Object.keys(before)) {
157
+ if (!RELATION_TOP_LEVEL_KEYS.has(topLevelKey) && !deepEqual(before[topLevelKey], after[topLevelKey])) {
158
+ failures.push(`${key}: relation extension field "${topLevelKey}" was not preserved`);
159
+ }
160
+ }
161
+ validateMetadata(key, before.metadata, after.metadata, failures);
162
+ }
163
+ }
164
+ if (failures.length > 0) {
165
+ throw new Error(`COAIA JSONL metadata preservation failed:\n- ${failures.join('\n- ')}`);
166
+ }
167
+ }
168
+ function validateMetadata(label, beforeMetadata, afterMetadata, failures) {
169
+ if (!isObject(beforeMetadata)) {
170
+ return;
171
+ }
172
+ if (!isObject(afterMetadata)) {
173
+ failures.push(`${label}: metadata object missing after write`);
174
+ return;
175
+ }
176
+ for (const [key, value] of Object.entries(beforeMetadata)) {
177
+ if (!(key in afterMetadata)) {
178
+ failures.push(`${label}: metadata.${key} missing after write`);
179
+ continue;
180
+ }
181
+ if ((key === 'github' || !MUTABLE_METADATA_KEYS.has(key)) && !deepEqual(value, afterMetadata[key])) {
182
+ failures.push(`${label}: metadata.${key} changed unexpectedly`);
183
+ }
184
+ }
185
+ }
186
+ export function parseJsonlMemory(content) {
187
+ const records = content
188
+ .split('\n')
189
+ .filter((line) => line.trim() !== '')
190
+ .map((line) => JSON.parse(line));
191
+ const graph = { entities: [], relations: [], rawRecords: records };
192
+ for (const record of records) {
193
+ if (isEntityRecord(record)) {
194
+ graph.entities.push(record);
195
+ }
196
+ else if (isRelationRecord(record)) {
197
+ graph.relations.push(record);
198
+ }
199
+ else if (isLegacyNarrativeBeatRecord(record)) {
200
+ graph.entities.push(normalizeLegacyNarrativeBeat(record));
201
+ }
202
+ }
203
+ return graph;
204
+ }
205
+ export function serializeJsonlMemory(graph) {
206
+ const rawRecords = graph.rawRecords;
207
+ const emittedEntities = new Set();
208
+ const emittedRelations = new Set();
209
+ const entitiesByName = new Map(graph.entities.map((entity) => [entity.name, entity]));
210
+ const relationsByKey = new Map(graph.relations.map((relation) => [relationKey(relation), relation]));
211
+ const records = [];
212
+ if (rawRecords && rawRecords.length > 0) {
213
+ for (const original of rawRecords) {
214
+ if (isEntityRecord(original) || isLegacyNarrativeBeatRecord(original)) {
215
+ const name = original.name;
216
+ const entity = entitiesByName.get(name);
217
+ if (entity) {
218
+ records.push(serializeEntity(entity, original));
219
+ emittedEntities.add(name);
220
+ }
221
+ continue;
222
+ }
223
+ if (isRelationRecord(original)) {
224
+ const key = relationKey(original);
225
+ const relation = relationsByKey.get(key);
226
+ if (relation) {
227
+ records.push(serializeRelation(relation, original));
228
+ emittedRelations.add(key);
229
+ }
230
+ continue;
231
+ }
232
+ records.push(original);
233
+ }
234
+ }
235
+ for (const entity of graph.entities) {
236
+ if (!emittedEntities.has(entity.name)) {
237
+ records.push(serializeEntity(entity));
238
+ }
239
+ }
240
+ for (const relation of graph.relations) {
241
+ const key = relationKey(relation);
242
+ if (!emittedRelations.has(key)) {
243
+ records.push(serializeRelation(relation));
244
+ }
245
+ }
246
+ validateRecordPreservation(rawRecords, records, graph);
247
+ return `${records.map((record) => JSON.stringify(record)).join('\n')}\n`;
248
+ }
249
+ export async function readJsonlMemoryFile(memoryFilePath) {
250
+ try {
251
+ return parseJsonlMemory(await fs.readFile(memoryFilePath, 'utf-8'));
252
+ }
253
+ catch (error) {
254
+ if (error instanceof Error && 'code' in error && error.code === 'ENOENT') {
255
+ return { entities: [], relations: [], rawRecords: [] };
256
+ }
257
+ throw error;
258
+ }
259
+ }
260
+ /**
261
+ * Write the store atomically: full content to a sibling temp file, then rename over the
262
+ * target. `rename` within a directory is atomic on POSIX, so a concurrent reader sees
263
+ * either the entire previous store or the entire new one — never a truncated prefix and
264
+ * never an empty file.
265
+ *
266
+ * The previous implementation was a bare `fs.writeFile`, which truncates and then
267
+ * writes. A reader landing in that window got a partial store, and — worse — a
268
+ * SYNTACTICALLY VALID partial store, because every whole line before the cut parses
269
+ * fine. That is undetectable by any reader: fewer charts is not distinguishable from
270
+ * fewer charts existing. Six MCP servers currently point at one store file, so the
271
+ * window is real rather than theoretical.
272
+ *
273
+ * WHAT THIS DOES NOT FIX: two processes that both load, then both write, still lose the
274
+ * earlier update — last writer wins, and both report success. Atomicity removes torn
275
+ * READS; it does not provide compare-and-swap. That remains open.
276
+ *
277
+ * The temp file is a sibling so the rename stays on one filesystem; a rename across
278
+ * devices is not atomic and would fail with EXDEV.
279
+ */
280
+ export async function writeJsonlMemoryFile(memoryFilePath, graph) {
281
+ const content = serializeJsonlMemory(graph);
282
+ const dir = path.dirname(memoryFilePath);
283
+ const tmp = path.join(dir, `.${path.basename(memoryFilePath)}.tmp-${process.pid}-${Date.now()}`);
284
+ try {
285
+ await fs.writeFile(tmp, content, 'utf-8');
286
+ await fs.rename(tmp, memoryFilePath);
287
+ }
288
+ catch (error) {
289
+ await fs.unlink(tmp).catch(() => { });
290
+ throw error;
291
+ }
292
+ }
293
+ //# sourceMappingURL=jsonl-preservation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsonl-preservation.js","sourceRoot":"","sources":["../../../src/narrative/jsonl-preservation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,mFAAmF;AACnF,8EAA8E;AAC9E,OAAO,EACL,QAAQ,EACR,eAAe,EACf,cAAc,EACd,2BAA2B,EAC3B,gBAAgB,EAChB,4BAA4B,EAC7B,MAAM,oBAAoB,CAAC;AAE5B,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,cAAc,EAAE,UAAU,CAAC,CAAC,CAAC;AAClG,MAAM,uBAAuB,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,UAAU,CAAC,CAAC,CAAC;AAC5F,MAAM,6BAA6B,GAAG,IAAI,GAAG,CAAC;IAC5C,GAAG,qBAAqB;IACxB,WAAW;IACX,sBAAsB;IACtB,iBAAiB;CAClB,CAAC,CAAC;AACH,MAAM,q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GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,QAAQ,OAAO,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IACjG,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QAC1C,MAAM,EAAE,CAAC,MAAM,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;IACvC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAA6B,CAAC,CAAC,CAAC;QAChE,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Record classification for the JSONL store — pure, no I/O, no imports beyond types.
3
+ *
4
+ * WHY THIS FILE EXISTS
5
+ *
6
+ * These predicates decide what a line in the store IS. They were private to
7
+ * jsonl-preservation.ts, which cannot be imported by a renderer because its first line
8
+ * is `import fs`. So the read contract re-implemented them by hand — and got it wrong:
9
+ * it dropped the legacy `type:"narrative_beat"` dialect this package still writes and
10
+ * reads, losing real beats AND reporting them as corruption.
11
+ *
12
+ * Splitting them out costs nothing and means classification has exactly one definition.
13
+ * jsonl-preservation.ts imports it, so the writer round-trips through these; contract.ts
14
+ * imports it, so a reader classifies identically. They cannot drift, because there is
15
+ * no second copy to drift from.
16
+ */
17
+ import type { Entity, JsonlRecord } from '../types.js';
18
+ export declare function isObject(value: unknown): value is Record<string, unknown>;
19
+ export declare function removeUndefined<T extends Record<string, unknown>>(record: T): T;
20
+ export declare function isEntityRecord(record: JsonlRecord): boolean;
21
+ /**
22
+ * The older on-disk dialect: a beat written with `type:"narrative_beat"` at the top
23
+ * level instead of `type:"entity"` + `entityType:"narrative_beat"`. Still present in
24
+ * live stores, still round-tripped by serializeEntity, still asserted by
25
+ * test-metadata-preservation.js. A reader that does not know this dialect silently
26
+ * renders fewer beats than exist.
27
+ */
28
+ export declare function isLegacyNarrativeBeatRecord(record: JsonlRecord): boolean;
29
+ export declare function isRelationRecord(record: JsonlRecord): boolean;
30
+ export declare function normalizeLegacyNarrativeBeat(record: JsonlRecord): Entity;
31
+ //# sourceMappingURL=jsonl-records.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsonl-records.d.ts","sourceRoot":"","sources":["../../../src/narrative/jsonl-records.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEvD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEzE;AAED,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAO/E;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAE3D;AAED;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAExE;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAK7D;AAED,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAsBxE"}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Record classification for the JSONL store — pure, no I/O, no imports beyond types.
3
+ *
4
+ * WHY THIS FILE EXISTS
5
+ *
6
+ * These predicates decide what a line in the store IS. They were private to
7
+ * jsonl-preservation.ts, which cannot be imported by a renderer because its first line
8
+ * is `import fs`. So the read contract re-implemented them by hand — and got it wrong:
9
+ * it dropped the legacy `type:"narrative_beat"` dialect this package still writes and
10
+ * reads, losing real beats AND reporting them as corruption.
11
+ *
12
+ * Splitting them out costs nothing and means classification has exactly one definition.
13
+ * jsonl-preservation.ts imports it, so the writer round-trips through these; contract.ts
14
+ * imports it, so a reader classifies identically. They cannot drift, because there is
15
+ * no second copy to drift from.
16
+ */
17
+ export function isObject(value) {
18
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
19
+ }
20
+ export function removeUndefined(record) {
21
+ for (const key of Object.keys(record)) {
22
+ if (record[key] === undefined) {
23
+ delete record[key];
24
+ }
25
+ }
26
+ return record;
27
+ }
28
+ export function isEntityRecord(record) {
29
+ return record.type === 'entity' && typeof record.name === 'string';
30
+ }
31
+ /**
32
+ * The older on-disk dialect: a beat written with `type:"narrative_beat"` at the top
33
+ * level instead of `type:"entity"` + `entityType:"narrative_beat"`. Still present in
34
+ * live stores, still round-tripped by serializeEntity, still asserted by
35
+ * test-metadata-preservation.js. A reader that does not know this dialect silently
36
+ * renders fewer beats than exist.
37
+ */
38
+ export function isLegacyNarrativeBeatRecord(record) {
39
+ return record.type === 'narrative_beat' && typeof record.name === 'string';
40
+ }
41
+ export function isRelationRecord(record) {
42
+ return record.type === 'relation' &&
43
+ typeof record.from === 'string' &&
44
+ typeof record.to === 'string' &&
45
+ typeof record.relationType === 'string';
46
+ }
47
+ export function normalizeLegacyNarrativeBeat(record) {
48
+ const metadata = {
49
+ ...(isObject(record.metadata) ? record.metadata : {}),
50
+ narrative: isObject(record.metadata) && record.metadata.narrative !== undefined
51
+ ? record.metadata.narrative
52
+ : record.narrative,
53
+ relationalAlignment: isObject(record.metadata) && record.metadata.relationalAlignment !== undefined
54
+ ? record.metadata.relationalAlignment
55
+ : record.relational_alignment,
56
+ fourDirections: isObject(record.metadata) && record.metadata.fourDirections !== undefined
57
+ ? record.metadata.fourDirections
58
+ : record.four_directions
59
+ };
60
+ return removeUndefined({
61
+ ...record,
62
+ type: 'narrative_beat',
63
+ name: record.name,
64
+ entityType: 'narrative_beat',
65
+ observations: Array.isArray(record.observations) ? record.observations : [],
66
+ metadata: removeUndefined(metadata)
67
+ });
68
+ }
69
+ //# sourceMappingURL=jsonl-records.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsonl-records.js","sourceRoot":"","sources":["../../../src/narrative/jsonl-records.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,MAAM,UAAU,eAAe,CAAoC,MAAS;IAC1E,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QACtC,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,SAAS,EAAE,CAAC;YAC9B,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;QACrB,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,MAAmB;IAChD,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,CAAC;AACrE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,2BAA2B,CAAC,MAAmB;IAC7D,OAAO,MAAM,CAAC,IAAI,KAAK,gBAAgB,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,CAAC;AAC7E,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,MAAmB;IAClD,OAAO,MAAM,CAAC,IAAI,KAAK,UAAU;QAC/B,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ;QAC/B,OAAO,MAAM,CAAC,EAAE,KAAK,QAAQ;QAC7B,OAAO,MAAM,CAAC,YAAY,KAAK,QAAQ,CAAC;AAC5C,CAAC;AAED,MAAM,UAAU,4BAA4B,CAAC,MAAmB;IAC9D,MAAM,QAAQ,GAAG;QACf,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;QACrD,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,SAAS,KAAK,SAAS;YAC7E,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS;YAC3B,CAAC,CAAC,MAAM,CAAC,SAAS;QACpB,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,mBAAmB,KAAK,SAAS;YACjG,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,mBAAmB;YACrC,CAAC,CAAC,MAAM,CAAC,oBAAoB;QAC/B,cAAc,EAAE,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,cAAc,KAAK,SAAS;YACvF,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc;YAChC,CAAC,CAAC,MAAM,CAAC,eAAe;KAC3B,CAAC;IAEF,OAAO,eAAe,CAAC;QACrB,GAAG,MAAM;QACT,IAAI,EAAE,gBAAgB;QACtB,IAAI,EAAE,MAAM,CAAC,IAAc;QAC3B,UAAU,EAAE,gBAAgB;QAC5B,YAAY,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,YAAwB,CAAC,CAAC,CAAC,EAAE;QACvF,QAAQ,EAAE,eAAe,CAAC,QAAQ,CAAC;KACpC,CAAW,CAAC;AACf,CAAC"}
@@ -14,8 +14,9 @@ export interface ToolDefinition {
14
14
  };
15
15
  }
16
16
  export declare const ALL_TOOL_DEFINITIONS: ToolDefinition[];
17
- export declare const STC_TOOLS: readonly ["create_structural_tension_chart", "manage_action_step", "add_action_step", "telescope_action_step", "remove_action_step", "mark_action_complete", "get_chart_progress", "list_active_charts", "get_chart", "get_action_step", "update_action_progress", "update_current_reality", "update_desired_outcome", "perform_mmot_evaluation"];
17
+ export declare const STC_TOOLS: readonly ["create_structural_tension_chart", "manage_action_step", "add_action_step", "telescope_action_step", "remove_action_step", "mark_action_complete", "get_chart_progress", "list_active_charts", "get_chart", "get_action_step", "update_action_progress", "update_current_reality", "update_desired_outcome", "update_chart_due_date", "link_chart_to_github_issue", "perform_mmot_evaluation"];
18
18
  export declare const NARRATIVE_TOOLS: readonly ["create_narrative_beat", "telescope_narrative_beat", "list_narrative_beats"];
19
+ export declare const WAMPUM_TOOLS: readonly ["create_wampum_belt", "add_wampum_bead", "read_wampum_belt"];
19
20
  export declare const KG_TOOLS: readonly ["create_entities", "create_relations", "add_observations", "delete_entities", "delete_observations", "delete_relations", "search_nodes", "open_nodes", "read_graph"];
20
21
  export declare const CORE_TOOLS: readonly ["list_active_charts", "create_structural_tension_chart", "add_action_step", "mark_action_complete"];
21
22
  //# sourceMappingURL=tool-definitions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tool-definitions.d.ts","sourceRoot":"","sources":["../../../src/narrative/tool-definitions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE;QACX,IAAI,EAAE,MAAM,CAAC;QACb,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACpC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;KACrB,CAAC;CACH;AAED,eAAO,MAAM,oBAAoB,EAAE,cAAc,EA6jBhD,CAAC;AAIF,eAAO,MAAM,SAAS,mVAeZ,CAAC;AAEX,eAAO,MAAM,eAAe,wFAIlB,CAAC;AAEX,eAAO,MAAM,QAAQ,gLAUX,CAAC;AAEX,eAAO,MAAM,UAAU,+GAKb,CAAC"}
1
+ {"version":3,"file":"tool-definitions.d.ts","sourceRoot":"","sources":["../../../src/narrative/tool-definitions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE;QACX,IAAI,EAAE,MAAM,CAAC;QACb,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACpC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;KACrB,CAAC;CACH;AAED,eAAO,MAAM,oBAAoB,EAAE,cAAc,EAmsBhD,CAAC;AAIF,eAAO,MAAM,SAAS,0YAiBZ,CAAC;AAEX,eAAO,MAAM,eAAe,wFAIlB,CAAC;AAEX,eAAO,MAAM,YAAY,wEAIf,CAAC;AAEX,eAAO,MAAM,QAAQ,gLAUX,CAAC;AAEX,eAAO,MAAM,UAAU,+GAKb,CAAC"}
@@ -216,6 +216,10 @@ export const ALL_TOOL_DEFINITIONS = [
216
216
  },
217
217
  description: 'Optional Elements of Performance for MMOT evaluation — criteria the agent uses to self-assess output',
218
218
  },
219
+ githubIssue: {
220
+ type: 'string',
221
+ description: "Optional GitHub issue this chart is written from, as the FULL path 'owner/repo#number' (e.g. jgwill/coaiajs#1). A bare '#number' is rejected — charts travel between repositories, and a bare number cites the wrong project once the chart is read elsewhere.",
222
+ },
219
223
  },
220
224
  required: ['desiredOutcome', 'currentReality', 'dueDate'],
221
225
  },
@@ -300,7 +304,12 @@ export const ALL_TOOL_DEFINITIONS = [
300
304
  initialActionSteps: {
301
305
  type: 'array',
302
306
  items: { type: 'string' },
303
- description: 'Optional list of initial action steps for the telescoped chart',
307
+ description: "Optional list of initial action steps for the telescoped chart. Also accepted as 'actionSteps', the name its sibling create_structural_tension_chart uses for the same concept.",
308
+ },
309
+ actionSteps: {
310
+ type: 'array',
311
+ items: { type: 'string' },
312
+ description: "Alias for 'initialActionSteps'. Present because create_structural_tension_chart names this same concept 'actionSteps'; supplying either works.",
304
313
  },
305
314
  },
306
315
  required: ['actionStepName', 'newCurrentReality'],
@@ -423,6 +432,29 @@ export const ALL_TOOL_DEFINITIONS = [
423
432
  required: ['chartId', 'newDesiredOutcome'],
424
433
  },
425
434
  },
435
+ {
436
+ name: 'update_chart_due_date',
437
+ description: 'Change the date a chart is due after it was created. Works for BOTH master charts AND action step charts. Moves the chart and its desired outcome together. Open action steps keep their own dates unless redistributeActionSteps is true; the count still falling after the new date is reported either way. The change is recorded as an observation on the chart.',
438
+ inputSchema: {
439
+ type: 'object',
440
+ properties: {
441
+ chartId: {
442
+ type: 'string',
443
+ description: "ID of the chart to update (works for master charts like 'chart_123' or action step charts like 'chart_456')",
444
+ },
445
+ newDueDate: {
446
+ type: 'string',
447
+ description: "New due date as an ISO date string (e.g. '2026-09-30T12:00:00Z')",
448
+ },
449
+ redistributeActionSteps: {
450
+ type: 'boolean',
451
+ default: false,
452
+ description: 'When true, open action steps and telescoped child charts are redistributed evenly between now and the new due date. When false (default), their dates are left as the caller set them.',
453
+ },
454
+ },
455
+ required: ['chartId', 'newDueDate'],
456
+ },
457
+ },
426
458
  {
427
459
  name: 'perform_mmot_evaluation',
428
460
  description: "Autonomous MMOT (Managerial Moment of Truth) self-evaluation on a structural tension chart. The agent compares produced output against defined Elements of Performance, acknowledges discrepancy, analyzes dynamics, updates the chart, and recommits or redirects. Runs the four Creator's Moment of Truth steps: acknowledge → analyze → update → recommit. Can be called from any directional perspective (South/East/West/North) for collective inquiry.",
@@ -545,6 +577,100 @@ export const ALL_TOOL_DEFINITIONS = [
545
577
  },
546
578
  },
547
579
  },
580
+ {
581
+ name: 'link_chart_to_github_issue',
582
+ description: "Record on an existing chart the GitHub issue it was written from. The reference must be the full 'owner/repo#number' path.",
583
+ inputSchema: {
584
+ type: 'object',
585
+ properties: {
586
+ chartId: { type: 'string', description: 'ID of the chart to link' },
587
+ githubIssue: {
588
+ type: 'string',
589
+ description: "GitHub issue as the FULL path 'owner/repo#number' (e.g. jgwill/coaiajs#1). A bare '#number' is rejected.",
590
+ },
591
+ },
592
+ required: ['chartId', 'githubIssue'],
593
+ },
594
+ },
595
+ {
596
+ name: 'create_wampum_belt',
597
+ description: 'Create a Wampum Belt: a non-linear mnemonic grid that runs in parallel with linear narrative beats.',
598
+ inputSchema: {
599
+ type: 'object',
600
+ properties: {
601
+ title: { type: 'string', description: 'Name of this Wampum belt' },
602
+ purpose: { type: 'string', description: 'What this belt encodes or remembers' },
603
+ rows: { type: 'number', description: 'Grid row count (default 1)' },
604
+ cols: { type: 'number', description: 'Grid column count (default 1)' },
605
+ },
606
+ required: ['title', 'purpose'],
607
+ },
608
+ },
609
+ {
610
+ name: 'add_wampum_bead',
611
+ description: 'Add a bead at a grid position with mnemonic anchor, optional relational readings, and optional ceremony/accountability links.',
612
+ inputSchema: {
613
+ type: 'object',
614
+ properties: {
615
+ beltId: { type: 'string', description: 'Target belt ID' },
616
+ mnemonic: { type: 'string', description: 'Short anchor phrase for this bead' },
617
+ color: {
618
+ type: 'string',
619
+ enum: ['white', 'purple', 'black', 'mixed'],
620
+ description: 'Bead color',
621
+ },
622
+ position: {
623
+ type: 'object',
624
+ properties: {
625
+ row: { type: 'number' },
626
+ col: { type: 'number' },
627
+ },
628
+ required: ['row', 'col'],
629
+ },
630
+ reading: { type: 'string', description: 'Canonical meaning for the bead' },
631
+ relationalReadings: {
632
+ type: 'object',
633
+ description: 'Optional perspective-specific readings (left/center/right/row:N/col:N)',
634
+ },
635
+ ceremonyLink: {
636
+ type: 'object',
637
+ properties: {
638
+ ceremonyType: {
639
+ type: 'string',
640
+ enum: ['commitment', 'accountability', 'witness', 'renewal'],
641
+ },
642
+ chartId: { type: 'string' },
643
+ beatName: { type: 'string' },
644
+ witnessNames: { type: 'array', items: { type: 'string' } },
645
+ renewalDate: { type: 'string' },
646
+ notes: { type: 'string' },
647
+ },
648
+ required: ['ceremonyType'],
649
+ },
650
+ observations: { type: 'array', items: { type: 'string' } },
651
+ },
652
+ required: ['beltId', 'mnemonic', 'color', 'position', 'reading'],
653
+ },
654
+ },
655
+ {
656
+ name: 'read_wampum_belt',
657
+ description: 'Read a Wampum Belt in full, or read a bead by position with relational interpretation.',
658
+ inputSchema: {
659
+ type: 'object',
660
+ properties: {
661
+ beltId: { type: 'string', description: 'Wampum belt ID' },
662
+ position: {
663
+ type: 'object',
664
+ properties: {
665
+ row: { type: 'number' },
666
+ col: { type: 'number' },
667
+ },
668
+ required: ['row', 'col'],
669
+ },
670
+ },
671
+ required: ['beltId'],
672
+ },
673
+ },
548
674
  ];
549
675
  // ─── Tool Group Subsets ─────────────────────────────────────────────
550
676
  export const STC_TOOLS = [
@@ -561,6 +687,8 @@ export const STC_TOOLS = [
561
687
  'update_action_progress',
562
688
  'update_current_reality',
563
689
  'update_desired_outcome',
690
+ 'update_chart_due_date',
691
+ 'link_chart_to_github_issue',
564
692
  'perform_mmot_evaluation',
565
693
  ];
566
694
  export const NARRATIVE_TOOLS = [
@@ -568,6 +696,11 @@ export const NARRATIVE_TOOLS = [
568
696
  'telescope_narrative_beat',
569
697
  'list_narrative_beats',
570
698
  ];
699
+ export const WAMPUM_TOOLS = [
700
+ 'create_wampum_belt',
701
+ 'add_wampum_bead',
702
+ 'read_wampum_belt',
703
+ ];
571
704
  export const KG_TOOLS = [
572
705
  'create_entities',
573
706
  'create_relations',