coaia-visualizer 1.6.0 → 1.6.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.
- package/.dockerignore +9 -0
- package/COMPLETE_IMPLEMENTATION_REPORT.md +215 -0
- package/QUICK_START_MCP_TESTING.md +236 -0
- package/README.md +1 -1
- package/README_TELESCOPED_NAVIGATION.md +247 -0
- package/STC.md +24 -0
- package/STCGOAL.md +0 -0
- package/STCISSUE.md +48 -0
- package/STCKIN.md +0 -0
- package/STCMASTERY.md +0 -0
- package/STUDY_REPORT.md +510 -0
- package/app/page.tsx +4 -23
- package/cli.ts +8 -0
- package/components/chart-detail-editable.tsx +3 -2
- package/components/chart-detail.tsx +1 -6
- package/components/edit-action-step.tsx +0 -2
- package/components/metadata-projections.tsx +208 -0
- package/components/relation-graph.tsx +27 -91
- package/components.json +21 -0
- package/direct-test.sh +180 -0
- package/dist/cli.js +7 -0
- package/dist/skill.js +342 -0
- package/docker-compose.test.yml +69 -0
- package/index.tsx +0 -26
- package/jgwill.coaia-visualizer-8--496dca71-d476-4ac9-ba9f-376add118dd8--260208.txt +2612 -0
- package/lib/chart-editor.ts +13 -13
- package/lib/jsonl-parser.ts +55 -8
- package/lib/jsonl-preservation.ts +405 -0
- package/lib/types.ts +32 -15
- package/mcp/dist/api-client.d.ts +138 -0
- package/mcp/dist/api-client.d.ts.map +1 -0
- package/mcp/dist/api-client.js +115 -0
- package/mcp/dist/api-client.js.map +1 -0
- package/mcp/dist/index.d.ts +2 -0
- package/mcp/dist/index.d.ts.map +1 -0
- package/mcp/dist/index.js +286 -0
- package/mcp/dist/index.js.map +1 -0
- package/mcp/dist/tools/index.d.ts +18 -0
- package/mcp/dist/tools/index.d.ts.map +1 -0
- package/mcp/dist/tools/index.js +322 -0
- package/mcp/dist/tools/index.js.map +1 -0
- package/mcp/package-lock.json +210 -0
- package/package.json +2 -27
- package/rispecs/github-project-runtime-memory-integration.spec.md +381 -0
- package/skill.ts +385 -0
- package/test-data/test-master.jsonl +11 -0
- package/test-results/.last-run.json +4 -0
- package/test-scripts/README.md +325 -0
- package/test-scripts/rich-jsonl-preservation.spec.ts +118 -0
- package/test-scripts/run-all-tests.sh +38 -0
- package/test-scripts/test-01-basic-operations.sh +87 -0
- package/test-scripts/test-02-telescope-creation.sh +91 -0
- package/test-scripts/test-03-navigation.sh +87 -0
- package/test-scripts/test-global-cli.spec.ts +220 -0
- package/test-scripts/verify-global-cli.sh +87 -0
- package/tsconfig.json +41 -0
- package/components/github-provenance.tsx +0 -226
- package/lib/github-provenance.ts +0 -316
package/lib/chart-editor.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// lib/chart-editor.ts - Chart editing logic
|
|
2
2
|
|
|
3
3
|
import type { EntityRecord, RelationRecord, ParsedData } from "./types"
|
|
4
|
+
import { buildMetadataWarnings, buildRecordProjections, serializeParsedData } from "./jsonl-preservation"
|
|
5
|
+
import { buildRiseSpecs } from "./jsonl-parser"
|
|
4
6
|
|
|
5
7
|
export interface ChartUpdate {
|
|
6
8
|
type:
|
|
@@ -20,11 +22,13 @@ export interface ChartUpdate {
|
|
|
20
22
|
export class ChartEditor {
|
|
21
23
|
private entities: Map<string, EntityRecord>
|
|
22
24
|
private relations: RelationRecord[]
|
|
25
|
+
private rawRecords: NonNullable<ParsedData["rawRecords"]>
|
|
23
26
|
|
|
24
27
|
constructor(parsedData: ParsedData) {
|
|
25
28
|
// Clone data to avoid mutations
|
|
26
29
|
this.entities = new Map(parsedData.entities)
|
|
27
30
|
this.relations = [...parsedData.relations]
|
|
31
|
+
this.rawRecords = [...(parsedData.rawRecords || [])]
|
|
28
32
|
}
|
|
29
33
|
|
|
30
34
|
private resolveStructuralChart(chartRef: string): { entityName: string; chartId: string; entity: EntityRecord } | null {
|
|
@@ -520,19 +524,11 @@ export class ChartEditor {
|
|
|
520
524
|
}
|
|
521
525
|
|
|
522
526
|
exportToJSONL(): string {
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
// Export relations
|
|
531
|
-
for (const relation of this.relations) {
|
|
532
|
-
lines.push(JSON.stringify(relation))
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
return lines.join("\n") + "\n"
|
|
527
|
+
return serializeParsedData({
|
|
528
|
+
entities: this.entities,
|
|
529
|
+
relations: this.relations,
|
|
530
|
+
rawRecords: this.rawRecords,
|
|
531
|
+
})
|
|
536
532
|
}
|
|
537
533
|
|
|
538
534
|
getUpdatedData(): ParsedData {
|
|
@@ -615,6 +611,10 @@ export class ChartEditor {
|
|
|
615
611
|
relations: this.relations,
|
|
616
612
|
charts: chartsArray,
|
|
617
613
|
rootCharts: rootCharts,
|
|
614
|
+
rawRecords: this.rawRecords,
|
|
615
|
+
projections: buildRecordProjections(this.entities),
|
|
616
|
+
preservationWarnings: buildMetadataWarnings(this.rawRecords),
|
|
617
|
+
riseSpecs: buildRiseSpecs(chartsArray),
|
|
618
618
|
}
|
|
619
619
|
}
|
|
620
620
|
}
|
package/lib/jsonl-parser.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Chart, EntityRecord, JSONLRecord, ParsedData, RawJSONLRecord, RelationRecord, RiseSpecProjection } from "./types"
|
|
2
|
+
import { buildMetadataWarnings, buildRecordProjections, normalizeJsonlRecord } from "./jsonl-preservation"
|
|
2
3
|
|
|
3
|
-
export function parseJSONL(content: string):
|
|
4
|
+
export function parseJSONL(content: string): RawJSONLRecord[] {
|
|
4
5
|
const lines = content.trim().split("\n")
|
|
5
|
-
const records:
|
|
6
|
+
const records: RawJSONLRecord[] = []
|
|
6
7
|
|
|
7
8
|
for (const line of lines) {
|
|
8
9
|
if (!line.trim()) continue
|
|
@@ -17,7 +18,44 @@ export function parseJSONL(content: string): JSONLRecord[] {
|
|
|
17
18
|
return records
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
function firstObservation(entity?: EntityRecord): string {
|
|
22
|
+
return entity?.observations?.[0] || ""
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function asStringList(value: unknown): string[] {
|
|
26
|
+
if (Array.isArray(value)) {
|
|
27
|
+
return value.map((item) => typeof item === "string" ? item : JSON.stringify(item))
|
|
28
|
+
}
|
|
29
|
+
if (typeof value === "string" && value.trim()) {
|
|
30
|
+
return [value]
|
|
31
|
+
}
|
|
32
|
+
return []
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function buildRiseSpecs(charts: Chart[]): RiseSpecProjection[] {
|
|
36
|
+
return charts.map((chart) => {
|
|
37
|
+
const metadata = chart.chartEntity.metadata || {}
|
|
38
|
+
const rise = metadata.rise || metadata.riseSpec || metadata.spec || {}
|
|
39
|
+
const incompleteActions = chart.actions.filter((action) => action.metadata?.completionStatus !== true)
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
chartId: chart.id,
|
|
43
|
+
desiredOutcome: firstObservation(chart.desiredOutcome),
|
|
44
|
+
currentReality: chart.currentReality?.observations || [],
|
|
45
|
+
naturalProgression: [
|
|
46
|
+
...asStringList(rise.naturalProgression || metadata.naturalProgression),
|
|
47
|
+
...incompleteActions.slice(0, 3).map((action) => action.observations?.[0]).filter(Boolean),
|
|
48
|
+
],
|
|
49
|
+
remainingBlockers: asStringList(rise.remainingBlockers || rise.blockers || metadata.remainingBlockers || metadata.blockers),
|
|
50
|
+
nextOperations: [
|
|
51
|
+
...asStringList(rise.nextOperations || metadata.nextOperations),
|
|
52
|
+
...incompleteActions.slice(0, 5).map((action) => action.observations?.[0]).filter(Boolean),
|
|
53
|
+
],
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function organizeData(records: RawJSONLRecord[]): ParsedData {
|
|
21
59
|
const entities = new Map<string, EntityRecord>()
|
|
22
60
|
const relations: RelationRecord[] = []
|
|
23
61
|
const charts = new Map<string, Chart>()
|
|
@@ -26,10 +64,15 @@ export function organizeData(records: JSONLRecord[]): ParsedData {
|
|
|
26
64
|
|
|
27
65
|
// First pass: separate entities and relations
|
|
28
66
|
for (const record of records) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
67
|
+
const normalized = normalizeJsonlRecord(record)
|
|
68
|
+
if (!normalized) {
|
|
69
|
+
continue
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (normalized.type === "entity") {
|
|
73
|
+
entities.set(normalized.name, normalized)
|
|
74
|
+
} else if (normalized.type === "relation") {
|
|
75
|
+
relations.push(normalized)
|
|
33
76
|
}
|
|
34
77
|
}
|
|
35
78
|
|
|
@@ -163,6 +206,10 @@ export function organizeData(records: JSONLRecord[]): ParsedData {
|
|
|
163
206
|
entities,
|
|
164
207
|
relations,
|
|
165
208
|
rootCharts,
|
|
209
|
+
rawRecords: records,
|
|
210
|
+
projections: buildRecordProjections(entities),
|
|
211
|
+
preservationWarnings: buildMetadataWarnings(records),
|
|
212
|
+
riseSpecs: buildRiseSpecs(Array.from(charts.values())),
|
|
166
213
|
}
|
|
167
214
|
}
|
|
168
215
|
|
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
EntityRecord,
|
|
3
|
+
MetadataWarning,
|
|
4
|
+
ParsedData,
|
|
5
|
+
RawJSONLRecord,
|
|
6
|
+
RecordProjections,
|
|
7
|
+
RelationRecord,
|
|
8
|
+
} from "./types"
|
|
9
|
+
|
|
10
|
+
const UPSTREAM_ISSUE = "https://github.com/avadisabelle/coaia-narrative/issues/35"
|
|
11
|
+
|
|
12
|
+
const ENTITY_TOP_LEVEL_KEYS = new Set(["type", "name", "entityType", "observations", "metadata"])
|
|
13
|
+
const RELATION_TOP_LEVEL_KEYS = new Set(["type", "from", "to", "relationType", "metadata"])
|
|
14
|
+
const NARRATIVE_BEAT_TOP_LEVEL_KEYS = new Set([
|
|
15
|
+
...ENTITY_TOP_LEVEL_KEYS,
|
|
16
|
+
"narrative",
|
|
17
|
+
"relational_alignment",
|
|
18
|
+
"four_directions",
|
|
19
|
+
])
|
|
20
|
+
const MUTABLE_METADATA_KEYS = new Set([
|
|
21
|
+
"dueDate",
|
|
22
|
+
"chartId",
|
|
23
|
+
"phase",
|
|
24
|
+
"completionStatus",
|
|
25
|
+
"completedAt",
|
|
26
|
+
"parentChart",
|
|
27
|
+
"parentActionStep",
|
|
28
|
+
"level",
|
|
29
|
+
"createdAt",
|
|
30
|
+
"updatedAt",
|
|
31
|
+
"act",
|
|
32
|
+
"type_dramatic",
|
|
33
|
+
"universes",
|
|
34
|
+
"timestamp",
|
|
35
|
+
"elementsOfPerformance",
|
|
36
|
+
"mmotEvaluations",
|
|
37
|
+
"relationalAlignment",
|
|
38
|
+
"fourDirections",
|
|
39
|
+
"narrative",
|
|
40
|
+
"isTelescopedChart",
|
|
41
|
+
"telescopedChartId",
|
|
42
|
+
])
|
|
43
|
+
|
|
44
|
+
function isObject(value: unknown): value is Record<string, any> {
|
|
45
|
+
return typeof value === "object" && value !== null && !Array.isArray(value)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function cloneJson<T>(value: T): T {
|
|
49
|
+
return value === undefined ? value : JSON.parse(JSON.stringify(value))
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function deepEqual(left: unknown, right: unknown): boolean {
|
|
53
|
+
return JSON.stringify(left) === JSON.stringify(right)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function removeUndefined<T extends Record<string, any>>(record: T): T {
|
|
57
|
+
for (const key of Object.keys(record)) {
|
|
58
|
+
if (record[key] === undefined) {
|
|
59
|
+
delete record[key]
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return record
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function relationKey(relation: Pick<RelationRecord, "from" | "to" | "relationType">): string {
|
|
66
|
+
return `${relation.from}\u0000${relation.to}\u0000${relation.relationType}`
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function isEntityLikeRecord(record: RawJSONLRecord): boolean {
|
|
70
|
+
return (record.type === "entity" || record.type === "narrative_beat") && typeof record.name === "string"
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function isRelationLikeRecord(record: RawJSONLRecord): boolean {
|
|
74
|
+
return (
|
|
75
|
+
record.type === "relation" &&
|
|
76
|
+
typeof record.from === "string" &&
|
|
77
|
+
typeof record.to === "string" &&
|
|
78
|
+
typeof record.relationType === "string"
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function normalizeJsonlRecord(record: RawJSONLRecord): EntityRecord | RelationRecord | null {
|
|
83
|
+
if (record.type === "entity" && typeof record.name === "string") {
|
|
84
|
+
return {
|
|
85
|
+
...record,
|
|
86
|
+
type: "entity",
|
|
87
|
+
observations: Array.isArray(record.observations) ? record.observations : [],
|
|
88
|
+
metadata: isObject(record.metadata) ? record.metadata : {},
|
|
89
|
+
} as EntityRecord
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (record.type === "narrative_beat" && typeof record.name === "string") {
|
|
93
|
+
const metadata = {
|
|
94
|
+
...(isObject(record.metadata) ? record.metadata : {}),
|
|
95
|
+
narrative: isObject(record.metadata) && record.metadata.narrative !== undefined
|
|
96
|
+
? record.metadata.narrative
|
|
97
|
+
: record.narrative,
|
|
98
|
+
relationalAlignment: isObject(record.metadata) && record.metadata.relationalAlignment !== undefined
|
|
99
|
+
? record.metadata.relationalAlignment
|
|
100
|
+
: record.relational_alignment,
|
|
101
|
+
fourDirections: isObject(record.metadata) && record.metadata.fourDirections !== undefined
|
|
102
|
+
? record.metadata.fourDirections
|
|
103
|
+
: record.four_directions,
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return removeUndefined({
|
|
107
|
+
...record,
|
|
108
|
+
type: "entity",
|
|
109
|
+
name: record.name as string,
|
|
110
|
+
entityType: "narrative_beat",
|
|
111
|
+
observations: Array.isArray(record.observations) ? record.observations : [],
|
|
112
|
+
metadata: removeUndefined(metadata),
|
|
113
|
+
}) as EntityRecord
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (isRelationLikeRecord(record)) {
|
|
117
|
+
return {
|
|
118
|
+
...record,
|
|
119
|
+
type: "relation",
|
|
120
|
+
metadata: isObject(record.metadata) ? record.metadata : {},
|
|
121
|
+
} as RelationRecord
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return null
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function mergePreservedMetadata(originalMetadata: unknown, currentMetadata: unknown): Record<string, any> {
|
|
128
|
+
const merged = {
|
|
129
|
+
...(isObject(currentMetadata) ? currentMetadata : {}),
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (isObject(originalMetadata)) {
|
|
133
|
+
for (const [key, value] of Object.entries(originalMetadata)) {
|
|
134
|
+
if (!(key in merged) && (!MUTABLE_METADATA_KEYS.has(key) || key === "github")) {
|
|
135
|
+
merged[key] = cloneJson(value)
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return merged
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function serializeEntity(entity: EntityRecord, original?: RawJSONLRecord): RawJSONLRecord {
|
|
144
|
+
const metadata = mergePreservedMetadata(original?.metadata, entity.metadata)
|
|
145
|
+
|
|
146
|
+
if (original?.type === "narrative_beat") {
|
|
147
|
+
const record: RawJSONLRecord = {
|
|
148
|
+
...original,
|
|
149
|
+
type: "narrative_beat",
|
|
150
|
+
name: entity.name,
|
|
151
|
+
observations: entity.observations,
|
|
152
|
+
metadata,
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if ("entityType" in original) {
|
|
156
|
+
record.entityType = entity.entityType
|
|
157
|
+
}
|
|
158
|
+
if ("narrative" in original && entity.metadata?.narrative !== undefined) {
|
|
159
|
+
record.narrative = cloneJson(entity.metadata.narrative)
|
|
160
|
+
}
|
|
161
|
+
if ("relational_alignment" in original && entity.metadata?.relationalAlignment !== undefined) {
|
|
162
|
+
record.relational_alignment = cloneJson(entity.metadata.relationalAlignment)
|
|
163
|
+
}
|
|
164
|
+
if ("four_directions" in original && entity.metadata?.fourDirections !== undefined) {
|
|
165
|
+
record.four_directions = cloneJson(entity.metadata.fourDirections)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return removeUndefined(record)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return removeUndefined({
|
|
172
|
+
...original,
|
|
173
|
+
...entity,
|
|
174
|
+
type: "entity",
|
|
175
|
+
metadata,
|
|
176
|
+
})
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function serializeRelation(relation: RelationRecord, original?: RawJSONLRecord): RawJSONLRecord {
|
|
180
|
+
return removeUndefined({
|
|
181
|
+
...original,
|
|
182
|
+
...relation,
|
|
183
|
+
type: "relation",
|
|
184
|
+
metadata: mergePreservedMetadata(original?.metadata, relation.metadata),
|
|
185
|
+
})
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function findRecord(records: RawJSONLRecord[], key: string): RawJSONLRecord | undefined {
|
|
189
|
+
return records.find((record) => {
|
|
190
|
+
if (isEntityLikeRecord(record) && record.name === key) return true
|
|
191
|
+
if (isRelationLikeRecord(record)) return relationKey(record as RelationRecord) === key
|
|
192
|
+
return false
|
|
193
|
+
})
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function validateMetadata(label: string, beforeMetadata: unknown, afterMetadata: unknown, failures: string[]): void {
|
|
197
|
+
if (!isObject(beforeMetadata)) return
|
|
198
|
+
if (!isObject(afterMetadata)) {
|
|
199
|
+
failures.push(`${label}: metadata object missing after write`)
|
|
200
|
+
return
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
for (const [key, value] of Object.entries(beforeMetadata)) {
|
|
204
|
+
if (!(key in afterMetadata)) {
|
|
205
|
+
failures.push(`${label}: metadata.${key} missing after write`)
|
|
206
|
+
continue
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if ((key === "github" || !MUTABLE_METADATA_KEYS.has(key)) && !deepEqual(value, afterMetadata[key])) {
|
|
210
|
+
failures.push(`${label}: metadata.${key} changed unexpectedly`)
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function validateRecordPreservation(
|
|
216
|
+
beforeRecords: RawJSONLRecord[],
|
|
217
|
+
afterRecords: RawJSONLRecord[],
|
|
218
|
+
entities: Map<string, EntityRecord>,
|
|
219
|
+
relations: RelationRecord[],
|
|
220
|
+
): void {
|
|
221
|
+
const relationKeys = new Set(relations.map((relation) => relationKey(relation)))
|
|
222
|
+
const failures: string[] = []
|
|
223
|
+
|
|
224
|
+
for (const before of beforeRecords) {
|
|
225
|
+
if (isEntityLikeRecord(before)) {
|
|
226
|
+
const name = before.name as string
|
|
227
|
+
if (!entities.has(name)) continue
|
|
228
|
+
|
|
229
|
+
const after = findRecord(afterRecords, name)
|
|
230
|
+
if (!after) {
|
|
231
|
+
failures.push(`${name}: record missing after write`)
|
|
232
|
+
continue
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (before.type === "narrative_beat" && after.type !== "narrative_beat") {
|
|
236
|
+
failures.push(`${name}: legacy narrative_beat record type was flattened`)
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const knownKeys = before.type === "narrative_beat" ? NARRATIVE_BEAT_TOP_LEVEL_KEYS : ENTITY_TOP_LEVEL_KEYS
|
|
240
|
+
for (const key of Object.keys(before)) {
|
|
241
|
+
if (!knownKeys.has(key) && !deepEqual(before[key], after[key])) {
|
|
242
|
+
failures.push(`${name}: top-level extension field "${key}" was not preserved`)
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
validateMetadata(name, before.metadata, after.metadata, failures)
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (isRelationLikeRecord(before)) {
|
|
249
|
+
const key = relationKey(before as RelationRecord)
|
|
250
|
+
if (!relationKeys.has(key)) continue
|
|
251
|
+
|
|
252
|
+
const after = findRecord(afterRecords, key)
|
|
253
|
+
if (!after) {
|
|
254
|
+
failures.push(`${key}: relation missing after write`)
|
|
255
|
+
continue
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
for (const topLevelKey of Object.keys(before)) {
|
|
259
|
+
if (!RELATION_TOP_LEVEL_KEYS.has(topLevelKey) && !deepEqual(before[topLevelKey], after[topLevelKey])) {
|
|
260
|
+
failures.push(`${key}: relation extension field "${topLevelKey}" was not preserved`)
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
validateMetadata(key, before.metadata, after.metadata, failures)
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
if (failures.length > 0) {
|
|
268
|
+
throw new Error(`COAIA JSONL metadata preservation failed:\n- ${failures.join("\n- ")}`)
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export function buildRecordProjections(entities: Map<string, EntityRecord>): RecordProjections {
|
|
273
|
+
const allEntities = Array.from(entities.values())
|
|
274
|
+
return {
|
|
275
|
+
chartRecords: allEntities.filter((entity) => entity.entityType === "structural_tension_chart"),
|
|
276
|
+
actionStepRecords: allEntities.filter((entity) => entity.entityType === "action_step" || entity.metadata?.isTelescopedChart),
|
|
277
|
+
narrativeBeatRecords: allEntities.filter((entity) => entity.entityType === "narrative_beat"),
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export function buildMetadataWarnings(records: RawJSONLRecord[]): MetadataWarning[] {
|
|
282
|
+
const warnings: MetadataWarning[] = []
|
|
283
|
+
|
|
284
|
+
for (const record of records) {
|
|
285
|
+
if (!isEntityLikeRecord(record) && !isRelationLikeRecord(record)) continue
|
|
286
|
+
|
|
287
|
+
const recordName = record.name || [record.from, record.to, record.relationType].filter(Boolean).join(" -> ")
|
|
288
|
+
const metadata = record.metadata
|
|
289
|
+
|
|
290
|
+
if (!isObject(metadata)) {
|
|
291
|
+
warnings.push({
|
|
292
|
+
severity: "warning",
|
|
293
|
+
recordName,
|
|
294
|
+
recordType: record.type,
|
|
295
|
+
message: "Record has no metadata object; provenance and extension fields may already be flattened.",
|
|
296
|
+
upstreamIssue: UPSTREAM_ISSUE,
|
|
297
|
+
})
|
|
298
|
+
continue
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
if (record.github && !metadata.github) {
|
|
302
|
+
warnings.push({
|
|
303
|
+
severity: "warning",
|
|
304
|
+
recordName,
|
|
305
|
+
recordType: record.type,
|
|
306
|
+
message: "GitHub provenance exists outside metadata.github; this shape is suspicious for preservation-aware tools.",
|
|
307
|
+
upstreamIssue: UPSTREAM_ISSUE,
|
|
308
|
+
})
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
const normalized = normalizeJsonlRecord(record)
|
|
312
|
+
if (normalized && "entityType" in normalized) {
|
|
313
|
+
if (
|
|
314
|
+
["structural_tension_chart", "action_step", "desired_outcome", "current_reality", "narrative_beat"].includes(
|
|
315
|
+
normalized.entityType,
|
|
316
|
+
) &&
|
|
317
|
+
!normalized.metadata?.chartId
|
|
318
|
+
) {
|
|
319
|
+
warnings.push({
|
|
320
|
+
severity: "warning",
|
|
321
|
+
recordName: normalized.name,
|
|
322
|
+
recordType: normalized.entityType,
|
|
323
|
+
message: "COAIA entity is missing metadata.chartId, so chart/action projection may be incomplete.",
|
|
324
|
+
upstreamIssue: UPSTREAM_ISSUE,
|
|
325
|
+
})
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
if (
|
|
329
|
+
normalized.entityType === "narrative_beat" &&
|
|
330
|
+
!normalized.metadata?.narrative &&
|
|
331
|
+
!record.narrative &&
|
|
332
|
+
normalized.observations.length <= 1
|
|
333
|
+
) {
|
|
334
|
+
warnings.push({
|
|
335
|
+
severity: "warning",
|
|
336
|
+
recordName: normalized.name,
|
|
337
|
+
recordType: normalized.entityType,
|
|
338
|
+
message: "Narrative beat appears flattened: no narrative metadata or rich beat payload is visible.",
|
|
339
|
+
upstreamIssue: UPSTREAM_ISSUE,
|
|
340
|
+
})
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
if (record.type === "narrative_beat") {
|
|
345
|
+
warnings.push({
|
|
346
|
+
severity: "warning",
|
|
347
|
+
recordName,
|
|
348
|
+
recordType: "narrative_beat",
|
|
349
|
+
message: "Legacy narrative_beat shape detected. It is rendered separately and preserved on save.",
|
|
350
|
+
upstreamIssue: UPSTREAM_ISSUE,
|
|
351
|
+
})
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
return warnings
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
export function serializeParsedData(data: Pick<ParsedData, "entities" | "relations" | "rawRecords">): string {
|
|
359
|
+
const rawRecords = data.rawRecords || []
|
|
360
|
+
const emittedEntities = new Set<string>()
|
|
361
|
+
const emittedRelations = new Set<string>()
|
|
362
|
+
const records: RawJSONLRecord[] = []
|
|
363
|
+
|
|
364
|
+
for (const original of rawRecords) {
|
|
365
|
+
if (isEntityLikeRecord(original)) {
|
|
366
|
+
const entity = data.entities.get(original.name)
|
|
367
|
+
if (entity) {
|
|
368
|
+
records.push(serializeEntity(entity, original))
|
|
369
|
+
emittedEntities.add(entity.name)
|
|
370
|
+
}
|
|
371
|
+
continue
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
if (isRelationLikeRecord(original)) {
|
|
375
|
+
const key = relationKey(original as RelationRecord)
|
|
376
|
+
const relation = data.relations.find((candidate) => relationKey(candidate) === key)
|
|
377
|
+
if (relation) {
|
|
378
|
+
records.push(serializeRelation(relation, original))
|
|
379
|
+
emittedRelations.add(key)
|
|
380
|
+
}
|
|
381
|
+
continue
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
records.push(original)
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
for (const entity of data.entities.values()) {
|
|
388
|
+
if (!emittedEntities.has(entity.name)) {
|
|
389
|
+
records.push(serializeEntity(entity))
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
for (const relation of data.relations) {
|
|
394
|
+
const key = relationKey(relation)
|
|
395
|
+
if (!emittedRelations.has(key)) {
|
|
396
|
+
records.push(serializeRelation(relation))
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
validateRecordPreservation(rawRecords, records, data.entities, data.relations)
|
|
401
|
+
|
|
402
|
+
return `${records.map((record) => JSON.stringify(record)).join("\n")}\n`
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
export { UPSTREAM_ISSUE }
|
package/lib/types.ts
CHANGED
|
@@ -3,33 +3,46 @@
|
|
|
3
3
|
export interface EntityRecord {
|
|
4
4
|
type: "entity"
|
|
5
5
|
name: string
|
|
6
|
-
entityType:
|
|
7
|
-
| "structural_tension_chart"
|
|
8
|
-
| "desired_outcome"
|
|
9
|
-
| "current_reality"
|
|
10
|
-
| "action_step"
|
|
11
|
-
| "narrative_beat"
|
|
12
|
-
| "custom"
|
|
13
|
-
| (string & {})
|
|
6
|
+
entityType: "structural_tension_chart" | "desired_outcome" | "current_reality" | "action_step" | "narrative_beat"
|
|
14
7
|
observations: string[]
|
|
15
8
|
metadata: Record<string, any>
|
|
9
|
+
[key: string]: any
|
|
16
10
|
}
|
|
17
11
|
|
|
18
12
|
export interface RelationRecord {
|
|
19
13
|
type: "relation"
|
|
20
14
|
from: string
|
|
21
15
|
to: string
|
|
22
|
-
relationType:
|
|
23
|
-
| "contains"
|
|
24
|
-
| "creates_tension_with"
|
|
25
|
-
| "advances_toward"
|
|
26
|
-
| "documents"
|
|
27
|
-
| "custom"
|
|
28
|
-
| (string & {})
|
|
16
|
+
relationType: "contains" | "creates_tension_with" | "advances_toward" | "documents"
|
|
29
17
|
metadata: Record<string, any>
|
|
18
|
+
[key: string]: any
|
|
30
19
|
}
|
|
31
20
|
|
|
32
21
|
export type JSONLRecord = EntityRecord | RelationRecord
|
|
22
|
+
export type RawJSONLRecord = Record<string, any>
|
|
23
|
+
|
|
24
|
+
export interface MetadataWarning {
|
|
25
|
+
severity: "warning" | "error"
|
|
26
|
+
recordName?: string
|
|
27
|
+
recordType?: string
|
|
28
|
+
message: string
|
|
29
|
+
upstreamIssue?: string
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface RecordProjections {
|
|
33
|
+
chartRecords: EntityRecord[]
|
|
34
|
+
actionStepRecords: EntityRecord[]
|
|
35
|
+
narrativeBeatRecords: EntityRecord[]
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface RiseSpecProjection {
|
|
39
|
+
chartId: string
|
|
40
|
+
desiredOutcome: string
|
|
41
|
+
currentReality: string[]
|
|
42
|
+
naturalProgression: string[]
|
|
43
|
+
remainingBlockers: string[]
|
|
44
|
+
nextOperations: string[]
|
|
45
|
+
}
|
|
33
46
|
|
|
34
47
|
export interface Chart {
|
|
35
48
|
id: string
|
|
@@ -49,4 +62,8 @@ export interface ParsedData {
|
|
|
49
62
|
entities: Map<string, EntityRecord>
|
|
50
63
|
relations: RelationRecord[]
|
|
51
64
|
rootCharts: Chart[]
|
|
65
|
+
rawRecords?: RawJSONLRecord[]
|
|
66
|
+
projections?: RecordProjections
|
|
67
|
+
preservationWarnings?: MetadataWarning[]
|
|
68
|
+
riseSpecs?: RiseSpecProjection[]
|
|
52
69
|
}
|