archgraph-argo-beta 0.27.0-beta.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 (85) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +107 -0
  3. package/argo/.env.example +170 -0
  4. package/argo/defaults/EA-model-template.qea +0 -0
  5. package/argo/defaults/design/KG/SystemArchitecture.json +128 -0
  6. package/argo/mcp-bridges/graph-mcp-stdio.js +98 -0
  7. package/argo/package.json +8 -0
  8. package/argo/plugins/argo-cost-collector.js +35 -0
  9. package/argo/plugins/argo-wakeup.js +29 -0
  10. package/argo/rules/archgraph.instructions.md +189 -0
  11. package/argo/schema/ImplementationToCodingHandoff.schema.json +252 -0
  12. package/argo/schema/ImplementationToIntentTraceProposal.schema.json +180 -0
  13. package/argo/schema/IntentToImplementationHandoff.schema.json +75 -0
  14. package/argo/schema/SystemArchitecture.schema.json +378 -0
  15. package/argo/schema/archimate3.2.md +7153 -0
  16. package/argo/schema/argob-rules.json +12229 -0
  17. package/argo/schema/argob.config.json +20 -0
  18. package/argo/scripts/ARCHITECTURE.md +58 -0
  19. package/argo/scripts/agentSearchDiagnose.js +407 -0
  20. package/argo/scripts/archimate32-rules.js +12301 -0
  21. package/argo/scripts/argo-mcp-server.js +952 -0
  22. package/argo/scripts/argo-paths.js +168 -0
  23. package/argo/scripts/argob-schema.js +574 -0
  24. package/argo/scripts/ea-qea-sync-lib.js +1014 -0
  25. package/argo/scripts/ea-qea-sync.js +110 -0
  26. package/argo/scripts/ensureArgoHarnessEnvironment.js +451 -0
  27. package/argo/scripts/external-graph-query.js +162 -0
  28. package/argo/scripts/generateArchitectureDiffPlantuml.js +466 -0
  29. package/argo/scripts/graph-rag/ARCHITECTURE.md +192 -0
  30. package/argo/scripts/graph-rag/agentCostLog.js +179 -0
  31. package/argo/scripts/graph-rag/canonicalProjectionAuthority.js +45 -0
  32. package/argo/scripts/graph-rag/defaultSemanticRetrieval.js +1244 -0
  33. package/argo/scripts/graph-rag/embeddingProviderProfile.js +89 -0
  34. package/argo/scripts/graph-rag/embeddingQualificationGate.js +59 -0
  35. package/argo/scripts/graph-rag/externalProductionConfig.js +74 -0
  36. package/argo/scripts/graph-rag/hybridRetrieval.js +114 -0
  37. package/argo/scripts/graph-rag/liveEmbeddingIndexGate.js +128 -0
  38. package/argo/scripts/graph-rag/liveEmbeddingNeo4jBoundary.js +137 -0
  39. package/argo/scripts/graph-rag/liveEmbeddingProviderClient.js +49 -0
  40. package/argo/scripts/graph-rag/liveEmbeddingProviderConfig.js +571 -0
  41. package/argo/scripts/graph-rag/mcpCrashDiagnostics.js +137 -0
  42. package/argo/scripts/graph-rag/mutationEmbeddingVectorLifecycle.js +1266 -0
  43. package/argo/scripts/graph-rag/neo4jNativeRetrieval.js +37 -0
  44. package/argo/scripts/graph-rag/productionGraphRagRuntime.js +1633 -0
  45. package/argo/scripts/graph-rag/rerankRetrieval.js +201 -0
  46. package/argo/scripts/graph-rag/semantic-persistence/ARCHITECTURE.md +51 -0
  47. package/argo/scripts/graph-rag/semantic-persistence/productionSemanticBackfill.js +342 -0
  48. package/argo/scripts/graph-rag/semantic-persistence/productionSemanticCheckpointStore.js +99 -0
  49. package/argo/scripts/graph-rag/semantic-persistence/productionSemanticNeo4jAdapter.js +186 -0
  50. package/argo/scripts/graph-rag/semantic-persistence/productionSemanticProjectionStore.js +171 -0
  51. package/argo/scripts/graph-rag/semanticAlignmentLock.js +76 -0
  52. package/argo/scripts/graph-rag/semanticAlignmentRunner.js +131 -0
  53. package/argo/scripts/graph-rag/semanticInitConfiguration.js +24 -0
  54. package/argo/scripts/graph-rag/semanticOperatorError.js +38 -0
  55. package/argo/scripts/graph-rag/semanticOperatorJourney.js +459 -0
  56. package/argo/scripts/graph-rag/semanticReadinessAttestationStore.js +398 -0
  57. package/argo/scripts/graph-rag/semanticRecordText.js +75 -0
  58. package/argo/scripts/graph-rag/systemMetadataCommandAdapter.js +269 -0
  59. package/argo/scripts/graph-semantics.js +266 -0
  60. package/argo/scripts/lossless-write-gate.js +500 -0
  61. package/argo/scripts/neo4j-system-architecture-store.js +1066 -0
  62. package/argo/scripts/repair-subdiagram-views.js +288 -0
  63. package/argo/scripts/repositoryArgoEnvironment.js +101 -0
  64. package/argo/scripts/runArchitectureTests.js +591 -0
  65. package/argo/scripts/semanticOperatorJourneyCli.js +91 -0
  66. package/argo/scripts/syncSystemArchitectureToNeo4j.js +67 -0
  67. package/argo/scripts/systemarchitecture-mcp-server.js +4508 -0
  68. package/argo/scripts/test-executors/_template.js +58 -0
  69. package/argo/scripts/test-executors/default.js +199 -0
  70. package/argo/scripts/validateStageHandoff.js +459 -0
  71. package/argo/scripts/validateSystemArchitecture.js +261 -0
  72. package/argo/scripts/validateTraceProposal.js +181 -0
  73. package/argo/scripts/validator-mcp-server.js +347 -0
  74. package/argo/skills/agent-search-diagnosis/SKILL.md +60 -0
  75. package/argo/skills/argo-init/SKILL.md +86 -0
  76. package/argo/skills/ea-human-reconcile/SKILL.md +40 -0
  77. package/bin/argo-deploy.js +12 -0
  78. package/cordis.patch.yml +6 -0
  79. package/dsh-argo-wakeup/index.js +17 -0
  80. package/dsh-argo-wakeup/package.json +1 -0
  81. package/dsh-argo-workspace/index.js +142 -0
  82. package/dsh-argo-workspace/package.json +1 -0
  83. package/install-argo.ps1 +1162 -0
  84. package/package.json +56 -0
  85. package/vendor/neo4j-driver-6.2.0.tgz +0 -0
@@ -0,0 +1,398 @@
1
+ const crypto = require('node:crypto');
2
+ const fs = require('node:fs');
3
+ const path = require('node:path');
4
+
5
+ const ATTESTATION_PATH = '.argo/temp/semantic-readiness-attestation.json';
6
+ const SCHEMA_VERSION = '1.0';
7
+ const ACL_REMEDIATION = 'Restrict .argo/temp and semantic-readiness-attestation.json ownership and ACLs to the current OS identity and SYSTEM, then run semantic readiness again';
8
+ const FIELDS = Object.freeze([
9
+ 'schemaVersion',
10
+ 'authorizationOperation',
11
+ 'graphPath',
12
+ 'verified',
13
+ 'canonicalVersion',
14
+ 'contentVersion',
15
+ 'indexVersion',
16
+ 'completedChannels',
17
+ 'missingChannels',
18
+ 'mismatchedChannels',
19
+ 'fullSnapshotFallback',
20
+ 'canonicalDigest',
21
+ 'integrityDigest',
22
+ ]);
23
+
24
+ function createSemanticReadinessAttestationStore(options = {}) {
25
+ const repositoryRoot = path.resolve(options.repositoryRoot);
26
+ const graphPath = normalizeGraphPath(options.graphPath);
27
+ const metadataAdapter = options.metadataAdapter;
28
+ const attestationPath = path.join(repositoryRoot, ...ATTESTATION_PATH.split('/'));
29
+ const directoryPath = path.dirname(attestationPath);
30
+ const canonicalPath = path.join(repositoryRoot, ...graphPath.split('/'));
31
+
32
+ return Object.freeze({
33
+ record(readiness) {
34
+ const record = buildRecord(readiness, {
35
+ repositoryRoot,
36
+ graphPath,
37
+ canonicalPath,
38
+ });
39
+ writeAttestationAtomically(record, {
40
+ attestationPath,
41
+ directoryPath,
42
+ metadataAdapter,
43
+ });
44
+ return Object.freeze(record);
45
+ },
46
+
47
+ read() {
48
+ if (!fs.existsSync(attestationPath)) return null;
49
+ assertPathTrust(attestationPath, directoryPath);
50
+ let record;
51
+ try {
52
+ record = JSON.parse(fs.readFileSync(attestationPath, 'utf8'));
53
+ } catch {
54
+ throw attestationError('SEMANTIC_READINESS_ATTESTATION_INVALID');
55
+ }
56
+ assertRecord(record, repositoryRoot);
57
+ assertOperatingSystemTrust({
58
+ attestationPath,
59
+ directoryPath,
60
+ metadataAdapter,
61
+ });
62
+ if (digestFile(canonicalPath) !== record.canonicalDigest) {
63
+ throw attestationError('SEMANTIC_READINESS_ATTESTATION_STALE');
64
+ }
65
+ return Object.freeze(record);
66
+ },
67
+
68
+ clear() {
69
+ try {
70
+ fs.rmSync(attestationPath, { force: true });
71
+ } catch {
72
+ throw attestationError('SEMANTIC_READINESS_ATTESTATION_INVALID');
73
+ }
74
+ },
75
+
76
+ validate(attestation, readiness) {
77
+ assertOperatingSystemTrust({
78
+ attestationPath,
79
+ directoryPath,
80
+ metadataAdapter,
81
+ });
82
+ if (digestFile(canonicalPath) !== attestation.canonicalDigest) return false;
83
+ return exactReadinessMatch(attestation, readiness);
84
+ },
85
+ });
86
+ }
87
+
88
+ function buildRecord(readiness, context) {
89
+ const record = {
90
+ schemaVersion: SCHEMA_VERSION,
91
+ authorizationOperation: 'verifyReadiness',
92
+ graphPath: context.graphPath,
93
+ verified: readiness.verified === true,
94
+ canonicalVersion: readiness.canonicalVersion,
95
+ contentVersion: readiness.contentVersion,
96
+ indexVersion: readiness.indexVersion,
97
+ completedChannels: copyChannels(readiness.completedChannels),
98
+ missingChannels: copyChannels(readiness.missingChannels),
99
+ mismatchedChannels: copyChannels(readiness.mismatchedChannels),
100
+ fullSnapshotFallback: false,
101
+ canonicalDigest: digestFile(context.canonicalPath),
102
+ };
103
+ record.integrityDigest = integrityDigest(record, context.repositoryRoot);
104
+ assertRecord(record, context.repositoryRoot);
105
+ return record;
106
+ }
107
+
108
+ function writeAttestationAtomically(readiness, context) {
109
+ fs.mkdirSync(context.directoryPath, { recursive: true, mode: 0o700 });
110
+ assertPathTrust(undefined, context.directoryPath);
111
+ const temporaryPath = `${context.attestationPath}.${process.pid}.${crypto.randomBytes(12).toString('hex')}.tmp`;
112
+ let descriptor;
113
+ try {
114
+ descriptor = fs.openSync(temporaryPath, 'wx', 0o600);
115
+ fs.writeSync(descriptor, `${JSON.stringify(readiness)}\n`, null, 'utf8');
116
+ fs.fsyncSync(descriptor);
117
+ fs.closeSync(descriptor);
118
+ descriptor = undefined;
119
+ fs.renameSync(temporaryPath, context.attestationPath);
120
+ assertMetadataResult(context.metadataAdapter.readReadinessAttestationAcl());
121
+ assertMetadataResult(context.metadataAdapter.readReadinessAttestationOwner());
122
+ assertOperatingSystemTrust(context);
123
+ if (process.platform === 'win32') {
124
+ if (path.dirname(temporaryPath) !== path.dirname(context.attestationPath)) {
125
+ throw attestationError('ATTESTATION_RENAME_VOLUME_CHANGED');
126
+ }
127
+ recordDirectoryFlushFallback('WINDOWS_DIRECTORY_FSYNC_UNSUPPORTED_SAME_DIRECTORY_RENAME');
128
+ } else {
129
+ const directoryDescriptor = fs.openSync(path.dirname(context.attestationPath), 'r');
130
+ fs.fsyncSync(directoryDescriptor);
131
+ fs.closeSync(directoryDescriptor);
132
+ }
133
+ return readiness;
134
+ } catch (error) {
135
+ if (descriptor !== undefined) {
136
+ try {
137
+ fs.closeSync(descriptor);
138
+ } catch {}
139
+ }
140
+ try {
141
+ fs.rmSync(temporaryPath, { force: true });
142
+ } catch {}
143
+ if (error && error.category) throw error;
144
+ throw attestationError('SEMANTIC_READINESS_ATTESTATION_UNTRUSTED');
145
+ }
146
+ }
147
+
148
+ function assertRecord(record, repositoryRoot) {
149
+ if (!record || typeof record !== 'object' || Array.isArray(record)) {
150
+ throw attestationError('SEMANTIC_READINESS_ATTESTATION_INVALID');
151
+ }
152
+ if (
153
+ Object.keys(record).sort().join('\n') !== [...FIELDS].sort().join('\n')
154
+ || record.schemaVersion !== SCHEMA_VERSION
155
+ || record.authorizationOperation !== 'verifyReadiness'
156
+ || record.verified !== true
157
+ || record.fullSnapshotFallback !== false
158
+ || !isString(record.graphPath)
159
+ || !isString(record.canonicalVersion)
160
+ || !isString(record.contentVersion)
161
+ || !isString(record.indexVersion)
162
+ || !isString(record.canonicalDigest)
163
+ || !isString(record.integrityDigest)
164
+ || !areChannels(record.completedChannels)
165
+ || !areChannels(record.missingChannels)
166
+ || !areChannels(record.mismatchedChannels)
167
+ || record.integrityDigest !== integrityDigest(record, repositoryRoot)
168
+ ) {
169
+ throw attestationError('SEMANTIC_READINESS_ATTESTATION_INVALID');
170
+ }
171
+ }
172
+
173
+ function assertPathTrust(attestationPath, directoryPath) {
174
+ let directory;
175
+ try {
176
+ directory = fs.lstatSync(directoryPath);
177
+ } catch {
178
+ throw attestationError('SEMANTIC_READINESS_ATTESTATION_UNTRUSTED');
179
+ }
180
+ if (!directory.isDirectory() || directory.isSymbolicLink()) {
181
+ throw attestationError('SEMANTIC_READINESS_ATTESTATION_UNTRUSTED');
182
+ }
183
+ if (!attestationPath) return;
184
+ let file;
185
+ try {
186
+ file = fs.lstatSync(attestationPath);
187
+ } catch {
188
+ throw attestationError('SEMANTIC_READINESS_ATTESTATION_UNTRUSTED');
189
+ }
190
+ if (!file.isFile() || file.isSymbolicLink()) {
191
+ throw attestationError('SEMANTIC_READINESS_ATTESTATION_UNTRUSTED');
192
+ }
193
+ }
194
+
195
+ function assertOperatingSystemTrust(context) {
196
+ assertPathTrust(context.attestationPath, context.directoryPath);
197
+ if (process.platform === 'win32') {
198
+ const identity = assertCommandSucceeded(context.metadataAdapter, 'readCurrentIdentity');
199
+ const directoryAcl = normalizeWindowsAclEvidence(assertCommandSucceeded(
200
+ context.metadataAdapter,
201
+ 'readReadinessAttestationDirectoryAcl',
202
+ ), context.directoryPath);
203
+ const fileAcl = normalizeWindowsAclEvidence(
204
+ assertCommandSucceeded(context.metadataAdapter, 'readReadinessAttestationAcl'),
205
+ context.attestationPath,
206
+ );
207
+ const owner = assertCommandSucceeded(
208
+ context.metadataAdapter,
209
+ 'readReadinessAttestationOwner',
210
+ );
211
+ assertWindowsAclTrust({ identity, owner, directoryAcl, fileAcl });
212
+ return;
213
+ }
214
+ const file = fs.lstatSync(context.attestationPath);
215
+ const directory = fs.lstatSync(context.directoryPath);
216
+ if (
217
+ (file.mode & 0o077) !== 0
218
+ || (directory.mode & 0o077) !== 0
219
+ || (typeof process.getuid === 'function'
220
+ && (file.uid !== process.getuid() || directory.uid !== process.getuid()))
221
+ ) {
222
+ throw attestationError('SEMANTIC_READINESS_ATTESTATION_UNTRUSTED');
223
+ }
224
+ }
225
+
226
+ function assertCommandSucceeded(adapter, capability) {
227
+ if (!adapter || typeof adapter[capability] !== 'function') {
228
+ throw attestationError('SEMANTIC_READINESS_ATTESTATION_UNTRUSTED');
229
+ }
230
+ const result = adapter[capability]();
231
+ if (!result || result.status !== 0 || typeof result.stdout !== 'string') {
232
+ throw attestationError('SEMANTIC_READINESS_ATTESTATION_UNTRUSTED');
233
+ }
234
+ return result.stdout;
235
+ }
236
+
237
+ function assertMetadataResult(result) {
238
+ if (!result || result.status !== 0 || typeof result.stdout !== 'string') {
239
+ throw attestationError('SEMANTIC_READINESS_ATTESTATION_UNTRUSTED');
240
+ }
241
+ return result.stdout;
242
+ }
243
+
244
+ function exactReadinessMatch(attestation, readiness) {
245
+ return Boolean(
246
+ readiness
247
+ && readiness.verified === true
248
+ && attestation.canonicalVersion === readiness.canonicalVersion
249
+ && attestation.contentVersion === readiness.contentVersion
250
+ && attestation.indexVersion === readiness.indexVersion
251
+ && sameArray(attestation.completedChannels, readiness.completedChannels)
252
+ && sameArray(attestation.missingChannels, readiness.missingChannels)
253
+ && sameArray(attestation.mismatchedChannels, readiness.mismatchedChannels)
254
+ && readiness.fullSnapshotFallback === false
255
+ );
256
+ }
257
+
258
+ function integrityDigest(record, repositoryRoot) {
259
+ const evidence = {};
260
+ for (const field of FIELDS) {
261
+ if (field !== 'integrityDigest') evidence[field] = record[field];
262
+ }
263
+ return digest(`${path.resolve(repositoryRoot)}\n${JSON.stringify(evidence)}`);
264
+ }
265
+
266
+ function digestFile(filePath) {
267
+ try {
268
+ return digest(fs.readFileSync(filePath));
269
+ } catch {
270
+ throw attestationError('SEMANTIC_READINESS_ATTESTATION_INVALID');
271
+ }
272
+ }
273
+
274
+ function digest(value) {
275
+ return crypto.createHash('sha256').update(value).digest('hex');
276
+ }
277
+
278
+ function copyChannels(value) {
279
+ return Array.isArray(value) ? [...value] : [];
280
+ }
281
+
282
+ function sameArray(left, right) {
283
+ return Array.isArray(left)
284
+ && Array.isArray(right)
285
+ && left.length === right.length
286
+ && left.every((value, index) => value === right[index]);
287
+ }
288
+
289
+ function areChannels(value) {
290
+ return Array.isArray(value) && value.every(isString);
291
+ }
292
+
293
+ function isString(value) {
294
+ return typeof value === 'string' && value.length > 0;
295
+ }
296
+
297
+ function normalizeGraphPath(value) {
298
+ if (typeof value !== 'string' || value.trim() === '') {
299
+ throw new TypeError('graphPath is required');
300
+ }
301
+ return value.replace(/\\/g, '/').replace(/^\/+/, '');
302
+ }
303
+
304
+ function normalizeIdentity(value) {
305
+ return String(value).trim().toLowerCase();
306
+ }
307
+
308
+ function normalizeWindowsAclEvidence(value, subjectPath) {
309
+ const lines = String(value).split(/\r?\n/)
310
+ .map(line => line.trim())
311
+ .filter(line => (
312
+ line
313
+ && !/^Successfully processed \d+ files?; Failed processing \d+ files?$/i.test(line)
314
+ && !/\b\d+\b.*;\s*.*\b\d+\b/.test(line)
315
+ ));
316
+ if (lines.length > 0) {
317
+ const prefix = String(subjectPath);
318
+ if (lines[0].toLowerCase().startsWith(prefix.toLowerCase())) {
319
+ lines[0] = lines[0].slice(prefix.length).trim();
320
+ }
321
+ }
322
+ return lines.filter(Boolean).join('\n');
323
+ }
324
+
325
+ function parseWindowsAcl(value) {
326
+ const lines = String(value).split(/\r?\n/).filter(Boolean);
327
+ if (lines.length === 0) throw windowsTrustError();
328
+ return lines.map(line => {
329
+ const match = line.match(/^(.+?):((?:\([^)]*\))+?)$/);
330
+ if (!match) throw windowsTrustError();
331
+ const flags = Array.from(
332
+ match[2].matchAll(/\(([^)]*)\)/g),
333
+ entry => entry[1].toUpperCase(),
334
+ );
335
+ return {
336
+ principal: normalizeIdentity(match[1]),
337
+ denied: flags.includes('DENY'),
338
+ permissions: flags
339
+ .filter(flag => !['DENY', 'I', 'OI', 'CI', 'IO'].includes(flag))
340
+ .flatMap(flag => flag.split(',')),
341
+ };
342
+ });
343
+ }
344
+
345
+ function grantsProtectedAccess(entry) {
346
+ return entry.permissions.some(permission => /^(?:F|M|RX|R|W|D|DE|RC|WDAC|WO|S|AS|MA|GR|GW|GE|GA|RD|WD|AD|REA|WEA|X|DC|RA|WA)$/.test(permission));
347
+ }
348
+
349
+ function grantsRequiredIdentityAccess(entry) {
350
+ return entry.permissions.some(permission => permission === 'F' || permission === 'M');
351
+ }
352
+
353
+ function windowsTrustError() {
354
+ const error = new Error('SEMANTIC_READINESS_ATTESTATION_UNTRUSTED');
355
+ error.category = 'SEMANTIC_READINESS_ATTESTATION_UNTRUSTED';
356
+ error.fullSnapshotFallback = false;
357
+ error.action = ACL_REMEDIATION;
358
+ return error;
359
+ }
360
+
361
+ function assertWindowsAclTrust({ identity, owner, directoryAcl, fileAcl }) {
362
+ const current = normalizeIdentity(identity);
363
+ if (!current || normalizeIdentity(owner) !== current) throw windowsTrustError();
364
+ for (const acl of [directoryAcl, fileAcl]) {
365
+ const entries = parseWindowsAcl(acl);
366
+ const currentEntries = entries.filter(entry => entry.principal === current);
367
+ if (
368
+ !currentEntries.some(entry => !entry.denied && grantsRequiredIdentityAccess(entry))
369
+ || currentEntries.some(entry => entry.denied && grantsProtectedAccess(entry))
370
+ || entries.some(entry => (
371
+ !entry.denied
372
+ && grantsProtectedAccess(entry)
373
+ && entry.principal !== current
374
+ && entry.principal !== 'nt authority\\system'
375
+ ))
376
+ ) {
377
+ throw windowsTrustError();
378
+ }
379
+ }
380
+ }
381
+
382
+ function recordDirectoryFlushFallback(reason) {
383
+ return Object.freeze({ reason });
384
+ }
385
+
386
+ function attestationError(category) {
387
+ const error = new Error(category);
388
+ error.category = category;
389
+ error.fullSnapshotFallback = false;
390
+ error.action = category === 'SEMANTIC_READINESS_ATTESTATION_UNTRUSTED'
391
+ ? ACL_REMEDIATION
392
+ : 'Run semantic readiness verification again before semantic query';
393
+ return error;
394
+ }
395
+
396
+ module.exports = {
397
+ createSemanticReadinessAttestationStore,
398
+ };
@@ -0,0 +1,75 @@
1
+ 'use strict';
2
+
3
+ // Curated embedding text for a canonical semantic record.
4
+ //
5
+ // The canonical JSON (design/KG/SystemArchitecture.json) remains the structural
6
+ // source of truth. The vector index, however, only encodes the human-meaningful
7
+ // fields of each record — never ids, endpoint ids, view member-id arrays, or
8
+ // JSON syntax — because embedding the raw object measurably dilutes retrieval
9
+ // (most severely for Views, whose member-id arrays dominate the text, and for
10
+ // Relationships, which are mostly structural). Both the full backfill and the
11
+ // incremental mutation lifecycle MUST embed through this single composer so the
12
+ // indexed text is identical across both paths.
13
+
14
+ function meaningful(value) {
15
+ return typeof value === 'string' && value.trim() !== '';
16
+ }
17
+
18
+ function formatAttributes(attributes) {
19
+ if (!Array.isArray(attributes)) {
20
+ return [];
21
+ }
22
+ const lines = [];
23
+ for (const attribute of attributes) {
24
+ if (!attribute || !meaningful(attribute.name)) {
25
+ continue;
26
+ }
27
+ const detail = meaningful(attribute.value)
28
+ ? attribute.value
29
+ : (meaningful(attribute.description) ? attribute.description : '');
30
+ lines.push(detail ? `${attribute.name.trim()}: ${detail.trim()}` : attribute.name.trim());
31
+ }
32
+ return lines;
33
+ }
34
+
35
+ function buildSemanticRecordText(channel, object) {
36
+ const record = object && typeof object === 'object' ? object : {};
37
+ const lines = [];
38
+ const add = value => {
39
+ if (meaningful(value)) {
40
+ lines.push(value.trim());
41
+ }
42
+ };
43
+
44
+ if (channel === 'ArchitectureRelationship' || channel === 'Relationship') {
45
+ add(record.statement);
46
+ add(record.name);
47
+ add(record.description);
48
+ add(record.document);
49
+ lines.push(...formatAttributes(record.attributes));
50
+ return lines.join('\n');
51
+ }
52
+
53
+ if (channel === 'View') {
54
+ add(record.view_name);
55
+ add(record.description);
56
+ return lines.join('\n');
57
+ }
58
+
59
+ // Element (default channel)
60
+ add(record.type);
61
+ add(record.name);
62
+ add(record.alias);
63
+ add(record.description);
64
+ lines.push(...formatAttributes(record.attributes));
65
+ if (Array.isArray(record.testcases)) {
66
+ for (const testcase of record.testcases) {
67
+ if (testcase && meaningful(testcase.description)) {
68
+ lines.push(testcase.description.trim());
69
+ }
70
+ }
71
+ }
72
+ return lines.join('\n');
73
+ }
74
+
75
+ module.exports = { buildSemanticRecordText };