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,89 @@
1
+ 'use strict';
2
+
3
+ // Embedding provider profile (ArchGraph ARGO).
4
+ //
5
+ // The semantic-retrieval embedding backend is either the human-approved cloud
6
+ // profile (`approved`, the default, byte-for-byte unchanged) or a self-hosted
7
+ // OpenAI-compatible endpoint (`openai-compatible`) for intranet / offline
8
+ // deployments. This module owns the profile vocabulary, the dimension contract,
9
+ // and the query-side instruction composition so the live configuration resolver
10
+ // and the retrieval runtime share one implementation.
11
+
12
+ const PROFILE_KEY = 'ARGO_EMBEDDING_PROFILE';
13
+ const QUERY_INSTRUCTION_KEY = 'ARGO_EMBEDDING_QUERY_INSTRUCTION';
14
+ const API_KEY = 'ARGO_EMBEDDING_API_KEY';
15
+ const PROFILE_APPROVED = 'approved';
16
+ const PROFILE_OPENAI_COMPATIBLE = 'openai-compatible';
17
+ const SUPPORTED_EMBEDDING_PROFILES = Object.freeze([PROFILE_APPROVED, PROFILE_OPENAI_COMPATIBLE]);
18
+ const DEFAULT_EMBEDDING_DIMENSIONS = 1536;
19
+
20
+ function resolveEmbeddingProfile(value) {
21
+ const normalized = typeof value === 'string' ? value.trim().toLowerCase() : '';
22
+ return normalized === '' ? PROFILE_APPROVED : normalized;
23
+ }
24
+
25
+ function isApprovedEmbeddingProfile(value) {
26
+ return resolveEmbeddingProfile(value) === PROFILE_APPROVED;
27
+ }
28
+
29
+ function requireSupportedEmbeddingProfile(value) {
30
+ const profile = resolveEmbeddingProfile(value);
31
+ if (!SUPPORTED_EMBEDDING_PROFILES.includes(profile)) {
32
+ throw profileError('EMBEDDING_PROFILE_UNSUPPORTED');
33
+ }
34
+ return profile;
35
+ }
36
+
37
+ function resolveEmbeddingDimensions(value, fallback = DEFAULT_EMBEDDING_DIMENSIONS) {
38
+ const parsed = typeof value === 'string' && value.trim() !== '' ? Number(value) : NaN;
39
+ return Number.isInteger(parsed) && parsed > 0 ? parsed : fallback;
40
+ }
41
+
42
+ function requireEmbeddingDimensions(value) {
43
+ const parsed = typeof value === 'string' && value.trim() !== '' ? Number(value) : NaN;
44
+ if (!Number.isInteger(parsed) || parsed <= 0) {
45
+ throw profileError('EMBEDDING_DIMENSIONS_INVALID');
46
+ }
47
+ return parsed;
48
+ }
49
+
50
+ // The query-side input may carry an instruction prefix (e.g. gte-Qwen2's
51
+ // "Instruct: <task>\nQuery: <query>"); document-side input stays raw so stored
52
+ // vectors are never polluted by a query-only prefix. The prefix commonly comes
53
+ // from a single-line `.env` value, so `\n`/`\r`/`\t` escapes are decoded here.
54
+ function normalizeInstruction(instruction) {
55
+ if (typeof instruction !== 'string') return '';
56
+ return instruction
57
+ .replace(/\\r\\n/g, '\n')
58
+ .replace(/\\n/g, '\n')
59
+ .replace(/\\r/g, '\r')
60
+ .replace(/\\t/g, '\t');
61
+ }
62
+
63
+ function composeQueryEmbeddingInput(text, instruction) {
64
+ const query = text == null ? '' : String(text);
65
+ const prefix = normalizeInstruction(instruction);
66
+ return prefix === '' ? query : `${prefix}${query}`;
67
+ }
68
+
69
+ function profileError(category) {
70
+ const error = new Error(category);
71
+ error.category = category;
72
+ return error;
73
+ }
74
+
75
+ module.exports = {
76
+ PROFILE_KEY,
77
+ QUERY_INSTRUCTION_KEY,
78
+ API_KEY,
79
+ PROFILE_APPROVED,
80
+ PROFILE_OPENAI_COMPATIBLE,
81
+ SUPPORTED_EMBEDDING_PROFILES,
82
+ DEFAULT_EMBEDDING_DIMENSIONS,
83
+ resolveEmbeddingProfile,
84
+ isApprovedEmbeddingProfile,
85
+ requireSupportedEmbeddingProfile,
86
+ resolveEmbeddingDimensions,
87
+ requireEmbeddingDimensions,
88
+ composeQueryEmbeddingInput,
89
+ };
@@ -0,0 +1,59 @@
1
+ function evaluateEmbeddingQualification(qualification) {
2
+ const supplied = qualification && typeof qualification === 'object'
3
+ ? qualification
4
+ : {};
5
+
6
+ if (supplied.approvedByHuman !== true) {
7
+ throw blockingError(
8
+ 'EMBEDDING_QUALIFICATION_REQUIRED',
9
+ 'Embedding configuration requires explicit human approval',
10
+ 'approvedByHuman',
11
+ );
12
+ }
13
+
14
+ if (supplied.source === 'implicit-default') {
15
+ throw blockingError(
16
+ 'IMPLICIT_EMBEDDING_DEFAULT_PROHIBITED',
17
+ 'Implicit embedding defaults cannot qualify index delivery',
18
+ 'source',
19
+ );
20
+ }
21
+
22
+ for (const field of ['provider', 'model', 'version']) {
23
+ if (typeof supplied[field] !== 'string' || supplied[field].trim().length === 0) {
24
+ throw blockingError(
25
+ 'EMBEDDING_CONFIGURATION_REQUIRED',
26
+ `${field} must be explicitly supplied`,
27
+ field,
28
+ );
29
+ }
30
+ }
31
+
32
+ if (!Number.isInteger(supplied.dimensions) || supplied.dimensions <= 0) {
33
+ throw blockingError(
34
+ 'EMBEDDING_CONFIGURATION_REQUIRED',
35
+ 'dimensions must be an explicitly supplied positive integer',
36
+ 'dimensions',
37
+ );
38
+ }
39
+
40
+ return {
41
+ status: 'approved',
42
+ approvedByHuman: true,
43
+ provider: supplied.provider.trim(),
44
+ model: supplied.model.trim(),
45
+ version: supplied.version.trim(),
46
+ dimensions: supplied.dimensions,
47
+ };
48
+ }
49
+
50
+ function blockingError(category, message, field) {
51
+ const error = new Error(message);
52
+ error.category = category;
53
+ error.field = field;
54
+ return error;
55
+ }
56
+
57
+ module.exports = {
58
+ evaluateEmbeddingQualification,
59
+ };
@@ -0,0 +1,74 @@
1
+ const REQUIRED_FIELDS = [
2
+ 'neo4jUri',
3
+ 'neo4jUsername',
4
+ 'neo4jPassword',
5
+ 'embeddingCredential',
6
+ ];
7
+ const APPROVED_SOURCE_KEYS = new Map([
8
+ ['neo4jUri', 'ARGO_NEO4J_DATABASE_URL'],
9
+ ['neo4jUsername', 'ARGO_NEO4J_DATABASE_USERNAME'],
10
+ ['neo4jPassword', 'ARGO_NEO4J_DATABASE_PASSWORD'],
11
+ ['embeddingCredential', 'QWEN_KEY'],
12
+ ]);
13
+
14
+ function resolveExternalProductionConfig(configuration, context = {}) {
15
+ const supplied = configuration && typeof configuration === 'object'
16
+ ? configuration
17
+ : {};
18
+ validateApprovedSourceKeys(context.sourceKeys);
19
+
20
+ for (const field of REQUIRED_FIELDS) {
21
+ const value = supplied[field];
22
+ if (typeof value !== 'string' || value.trim().length === 0) {
23
+ throw blockingError(
24
+ 'EXTERNAL_CREDENTIALS_REQUIRED',
25
+ `${field} is required for ${context.operation || 'production operation'}`,
26
+ field,
27
+ );
28
+ }
29
+ }
30
+
31
+ return {
32
+ neo4jUri: supplied.neo4jUri.trim(),
33
+ neo4jUsername: supplied.neo4jUsername.trim(),
34
+ neo4jPassword: supplied.neo4jPassword,
35
+ embeddingCredential: supplied.embeddingCredential,
36
+ ...(supplied.neo4jDatabase === undefined
37
+ ? {}
38
+ : { neo4jDatabase: supplied.neo4jDatabase }),
39
+ };
40
+ }
41
+
42
+ function validateApprovedSourceKeys(sourceKeys) {
43
+ if (sourceKeys === undefined) {
44
+ return;
45
+ }
46
+ if (!(sourceKeys instanceof Map)) {
47
+ throw blockingError(
48
+ 'UNAPPROVED_RUNTIME_CONFIG_SOURCE',
49
+ 'runtime configuration source provenance is invalid',
50
+ 'sourceKeys',
51
+ );
52
+ }
53
+
54
+ for (const field of REQUIRED_FIELDS) {
55
+ if (sourceKeys.get(field) !== APPROVED_SOURCE_KEYS.get(field)) {
56
+ throw blockingError(
57
+ 'UNAPPROVED_RUNTIME_CONFIG_SOURCE',
58
+ `${field} is not resolved from its approved source`,
59
+ field,
60
+ );
61
+ }
62
+ }
63
+ }
64
+
65
+ function blockingError(category, message, field) {
66
+ const error = new Error(message);
67
+ error.category = category;
68
+ error.field = field;
69
+ return error;
70
+ }
71
+
72
+ module.exports = {
73
+ resolveExternalProductionConfig,
74
+ };
@@ -0,0 +1,114 @@
1
+ 'use strict';
2
+
3
+ // Hybrid retrieval fusion (P2). Pure, dependency-free helpers so the fusion
4
+ // logic is fully unit-testable and the production retrieval path can stay
5
+ // additive: when hybrid is OFF nothing here is invoked.
6
+ //
7
+ // Design:
8
+ // - vector (dense) and lexical (full-text/BM25) ranked lists are fused with
9
+ // Reciprocal Rank Fusion: score(id) = sum over lists of 1/(k + rank).
10
+ // - RRF needs no score normalization between the two very different score
11
+ // scales, and guarantees the union is retained (recall can only increase).
12
+
13
+ const DEFAULT_RRF_K = 60;
14
+ const DEFAULT_HYBRID_TOP_K = 16;
15
+ // Vector-first weighting: the dense channel is the stronger signal on this
16
+ // graph, so lexical only nudges the ranking and rescues misses.
17
+ const DEFAULT_VECTOR_WEIGHT = 3;
18
+ const DEFAULT_LEXICAL_WEIGHT = 1;
19
+
20
+ function isHybridEnabled(env = process.env) {
21
+ return String((env && env.ARGO_SEMANTIC_HYBRID) || '') === '1';
22
+ }
23
+
24
+ function hybridWeights(env = process.env) {
25
+ const vector = Number(env && env.ARGO_SEMANTIC_HYBRID_VECTOR_WEIGHT);
26
+ const lexical = Number(env && env.ARGO_SEMANTIC_HYBRID_LEXICAL_WEIGHT);
27
+ return [
28
+ Number.isFinite(vector) && vector >= 0 ? vector : DEFAULT_VECTOR_WEIGHT,
29
+ Number.isFinite(lexical) && lexical >= 0 ? lexical : DEFAULT_LEXICAL_WEIGHT,
30
+ ];
31
+ }
32
+
33
+ function hybridTopK(env = process.env) {
34
+ const value = Number(env && env.ARGO_SEMANTIC_HYBRID_TOP_K);
35
+ return Number.isInteger(value) && value > 0 ? value : DEFAULT_HYBRID_TOP_K;
36
+ }
37
+
38
+ function rrfK(env = process.env) {
39
+ const value = Number(env && env.ARGO_SEMANTIC_HYBRID_RRF_K);
40
+ return Number.isFinite(value) && value > 0 ? value : DEFAULT_RRF_K;
41
+ }
42
+
43
+ // Lucene full-text queries reject raw punctuation (e.g. "A --(Flow)--> B") and
44
+ // blow the maxClauseCount on very long text (long Chinese descriptions become
45
+ // hundreds of single-character clauses). Truncate first, then escape the
46
+ // reserved query-syntax characters so any intent/name/statement is literal.
47
+ // Returns '' for blank input (caller skips).
48
+ const MAX_FULLTEXT_QUERY_LENGTH = 256;
49
+
50
+ function sanitizeFulltextQuery(text) {
51
+ const value = String(text === undefined || text === null ? '' : text)
52
+ .trim()
53
+ .slice(0, MAX_FULLTEXT_QUERY_LENGTH);
54
+ if (!value) return '';
55
+ return value
56
+ .replace(/&&/g, '\\&\\&')
57
+ .replace(/\|\|/g, '\\|\\|')
58
+ .replace(/([+\-!(){}[\]^"~*?:\\/])/g, '\\$1');
59
+ }
60
+
61
+ // Fuse ranked record lists by id (canonicalIdentity). Each list is expected to be
62
+ // already sorted best-first. Returns records carrying the fused `score`, with
63
+ // the first-seen record object preserved (so downstream keeps its fields).
64
+ function rrfFuse(lists, options = {}) {
65
+ const k = Number.isFinite(options.k) && options.k > 0 ? options.k : DEFAULT_RRF_K;
66
+ const weights = Array.isArray(options.weights) ? options.weights : [];
67
+ const byId = new Map();
68
+ (Array.isArray(lists) ? lists : []).forEach((list, listIndex) => {
69
+ const weight = Number.isFinite(weights[listIndex]) && weights[listIndex] >= 0 ? weights[listIndex] : 1;
70
+ (Array.isArray(list) ? list : []).forEach((record, rank) => {
71
+ if (!record || !record.id) return;
72
+ const entry = byId.get(record.id) || { id: record.id, record, score: 0, matchedLists: 0 };
73
+ entry.score += weight / (k + rank + 1);
74
+ entry.matchedLists += 1;
75
+ if (!entry.record) entry.record = record;
76
+ byId.set(record.id, entry);
77
+ });
78
+ });
79
+ return [...byId.values()]
80
+ .sort((left, right) => (right.score - left.score) || String(left.id).localeCompare(String(right.id)))
81
+ .map(entry => Object.freeze({
82
+ ...entry.record,
83
+ id: entry.id,
84
+ canonicalIdentity: entry.id,
85
+ score: entry.score,
86
+ rrfScore: entry.score,
87
+ matchedLists: entry.matchedLists,
88
+ }));
89
+ }
90
+
91
+ // Fuse the two per-channel seed lists. With an empty lexical list this preserves
92
+ // the vector ordering (RRF on a single list is order-preserving) — which is what
93
+ // makes "hybrid ON but no lexical hit" behave like the vector-only baseline.
94
+ function fuseChannelSeeds({ vectorSeeds = [], lexicalSeeds = [], k = DEFAULT_RRF_K, limit, weights } = {}) {
95
+ const fused = rrfFuse([
96
+ Array.isArray(vectorSeeds) ? vectorSeeds.filter(Boolean) : [],
97
+ Array.isArray(lexicalSeeds) ? lexicalSeeds.filter(Boolean) : [],
98
+ ], { k, ...(Array.isArray(weights) ? { weights } : {}) });
99
+ return Number.isInteger(limit) && limit > 0 ? fused.slice(0, limit) : fused;
100
+ }
101
+
102
+ module.exports = {
103
+ DEFAULT_RRF_K,
104
+ DEFAULT_HYBRID_TOP_K,
105
+ DEFAULT_VECTOR_WEIGHT,
106
+ DEFAULT_LEXICAL_WEIGHT,
107
+ isHybridEnabled,
108
+ hybridTopK,
109
+ hybridWeights,
110
+ rrfK,
111
+ rrfFuse,
112
+ fuseChannelSeeds,
113
+ sanitizeFulltextQuery,
114
+ };
@@ -0,0 +1,128 @@
1
+ const { evaluateEmbeddingQualification } = require('./embeddingQualificationGate.js');
2
+ const { createLiveEmbeddingProviderClient } = require('./liveEmbeddingProviderClient.js');
3
+
4
+ const IDENTITY_FIELDS = Object.freeze([
5
+ 'canonicalIdentity',
6
+ 'canonicalVersion',
7
+ 'contentIdentity',
8
+ 'contentVersion',
9
+ 'indexIdentity',
10
+ 'indexVersion',
11
+ ]);
12
+
13
+ function buildSemanticIndexEvidenceRecord(input = {}) {
14
+ const qualification = input.qualification && typeof input.qualification === 'object'
15
+ ? input.qualification
16
+ : {};
17
+ const objectType = input.objectType || 'Element';
18
+ const objectId = input.objectId || input.id || `${objectType.toLowerCase()}-record`;
19
+ const indexVersion = input.indexVersion || incrementVersion(input.contentVersion || input.canonicalVersion);
20
+ return Object.freeze({
21
+ objectType,
22
+ objectId,
23
+ channel: input.channel || channelForObjectType(objectType),
24
+ canonicalVersion: input.canonicalVersion || 'canonical-v1',
25
+ contentVersion: input.contentVersion || 'content-v1',
26
+ indexVersion,
27
+ provider: input.provider || qualification.provider || 'approved-test-provider',
28
+ model: input.model || qualification.model || 'approved-test-model',
29
+ version: input.version || input.modelVersion || qualification.version || '2026-07-24',
30
+ modelVersion: input.modelVersion || qualification.version || '2026-07-24',
31
+ dimensions: input.dimensions || qualification.dimensions || 1536,
32
+ ...(Array.isArray(input.vector) ? { vector: [...input.vector] } : {}),
33
+ });
34
+ }
35
+
36
+ function createLiveEmbeddingIndexGate(dependencies = {}) {
37
+ const { configuration, transport, indexBoundary } = dependencies;
38
+ if (!configuration || !indexBoundary || typeof indexBoundary.writeEvidence !== 'function') {
39
+ throw safeError('LIVE_PROVIDER_E2E_BOUNDARY_MISSING');
40
+ }
41
+ const client = createLiveEmbeddingProviderClient({ configuration, transport });
42
+ return Object.freeze({
43
+ async executeApprovedEmbedding(input) {
44
+ const qualification = evaluateEmbeddingQualification(input && input.qualification);
45
+ requireApprovedConfiguration(configuration, qualification);
46
+ requireInput(input);
47
+ const vector = await client.embed(input.input);
48
+ if (
49
+ vector.length !== configuration.embeddingDimensions
50
+ || vector.some(value => typeof value !== 'number' || !Number.isFinite(value))
51
+ ) {
52
+ throw safeError('LIVE_PROVIDER_RESPONSE_INVALID');
53
+ }
54
+ const evidence = {
55
+ provider: qualification.provider,
56
+ model: qualification.model,
57
+ qualificationVersion: qualification.version,
58
+ dimensions: qualification.dimensions,
59
+ ...Object.fromEntries(IDENTITY_FIELDS.map(field => [field, input[field]])),
60
+ vector,
61
+ };
62
+ try {
63
+ await indexBoundary.writeEvidence(evidence);
64
+ } catch {
65
+ throw safeError('LIVE_PROVIDER_INDEX_WRITE_PROHIBITED');
66
+ }
67
+ return Object.freeze({
68
+ qualification: Object.freeze({ ...qualification }),
69
+ vector,
70
+ evidence: Object.freeze(evidence),
71
+ });
72
+ },
73
+ });
74
+ }
75
+
76
+ function requireApprovedConfiguration(configuration, qualification) {
77
+ if (
78
+ qualification.provider !== configuration.embeddingProvider
79
+ || qualification.model !== configuration.embeddingModel
80
+ || qualification.version !== configuration.embeddingModelVersion
81
+ || qualification.dimensions !== configuration.embeddingDimensions
82
+ ) {
83
+ throw safeError('LIVE_PROVIDER_INDEX_WRITE_PROHIBITED');
84
+ }
85
+ }
86
+
87
+ function requireInput(input) {
88
+ if (!input || typeof input.input !== 'string' || input.input.trim() === '') {
89
+ throw safeError('LIVE_PROVIDER_INDEX_WRITE_PROHIBITED');
90
+ }
91
+ for (const field of IDENTITY_FIELDS) {
92
+ if (typeof input[field] !== 'string' || input[field].trim() === '') {
93
+ throw safeError('LIVE_PROVIDER_INDEX_WRITE_PROHIBITED');
94
+ }
95
+ }
96
+ }
97
+
98
+ function safeError(category) {
99
+ const error = new Error(category);
100
+ error.category = category;
101
+ return error;
102
+ }
103
+
104
+ function channelForObjectType(objectType) {
105
+ if (objectType === 'ArchitectureRelationship') {
106
+ return 'relationships';
107
+ }
108
+ if (objectType === 'View') {
109
+ return 'views';
110
+ }
111
+ return 'elements';
112
+ }
113
+
114
+ function incrementVersion(value) {
115
+ if (typeof value !== 'string' || value.trim() === '') {
116
+ return 'index-v1';
117
+ }
118
+ const numericSuffix = value.match(/^(.*?)(\d+)$/);
119
+ if (!numericSuffix) {
120
+ return `${value}-indexed`;
121
+ }
122
+ return `${numericSuffix[1]}${Number(numericSuffix[2]) + 1}`;
123
+ }
124
+
125
+ module.exports = {
126
+ buildSemanticIndexEvidenceRecord,
127
+ createLiveEmbeddingIndexGate,
128
+ };
@@ -0,0 +1,137 @@
1
+ async function createApprovedNeo4jBoundary({ configuration, neo4j, logger }) {
2
+ if (
3
+ !configuration
4
+ || !neo4j
5
+ || !neo4j.auth
6
+ || typeof neo4j.auth.basic !== 'function'
7
+ || typeof neo4j.driver !== 'function'
8
+ ) {
9
+ throw safeError('LIVE_PROVIDER_NEO4J_BOUNDARY_MISSING');
10
+ }
11
+ const uri = requireValue(configuration, 'neo4jDatabaseUrl');
12
+ const username = requireValue(configuration, 'neo4jDatabaseUsername');
13
+ const password = requireValue(configuration, 'neo4jDatabasePassword');
14
+ let driver;
15
+ try {
16
+ const authentication = neo4j.auth.basic(username, password);
17
+ driver = neo4j.driver(uri, authentication);
18
+ await driver.verifyConnectivity();
19
+ } catch {
20
+ if (driver && typeof driver.close === 'function') {
21
+ try { await driver.close(); } catch {}
22
+ }
23
+ throw safeError('LIVE_PROVIDER_OPERATION_FAILED');
24
+ }
25
+
26
+ let closed = false;
27
+ async function query(cypher, parameters) {
28
+ if (closed) throw safeError('LIVE_PROVIDER_OPERATION_FAILED');
29
+ const session = driver.session();
30
+ try {
31
+ return await session.run(cypher, parameters);
32
+ } catch {
33
+ throw safeError('LIVE_PROVIDER_OPERATION_FAILED');
34
+ } finally {
35
+ try { await session.close(); } catch {}
36
+ }
37
+ }
38
+
39
+ return Object.freeze({
40
+ async countWrites(runId) {
41
+ const result = await query(
42
+ 'MATCH (e:ArgoLiveEmbeddingEvidence { runId: $runId }) RETURN count(e) AS count',
43
+ { runId },
44
+ );
45
+ const count = result.records[0].get('count');
46
+ return count && typeof count.toNumber === 'function' ? count.toNumber() : Number(count);
47
+ },
48
+ async writeEvidence(runId, evidence) {
49
+ if (evidence === undefined) {
50
+ evidence = runId;
51
+ runId = evidence.runId;
52
+ }
53
+ const normalized = normalizeEvidence(evidence);
54
+ await query(
55
+ 'CREATE (e:ArgoLiveEmbeddingEvidence { runId: $runId, vector: $vector, provider: $provider, model: $model, qualificationVersion: $qualificationVersion, dimensions: $dimensions, canonicalIdentity: $canonicalIdentity, canonicalVersion: $canonicalVersion, contentIdentity: $contentIdentity, contentVersion: $contentVersion, indexIdentity: $indexIdentity, indexVersion: $indexVersion })',
56
+ { runId, ...normalized },
57
+ );
58
+ },
59
+ async readEvidence(runId) {
60
+ const result = await query(
61
+ 'MATCH (e:ArgoLiveEmbeddingEvidence { runId: $runId }) RETURN e { .runId, .provider, .model, .qualificationVersion, .dimensions, .canonicalIdentity, .canonicalVersion, .contentIdentity, .contentVersion, .indexIdentity, .indexVersion, .vector } AS evidence',
62
+ { runId },
63
+ );
64
+ return result.records.map(record => normalizeNeo4jValue(record.get('evidence')));
65
+ },
66
+ async queryVectorEvidence(runId, vector, canonicalIdentities) {
67
+ if (!Array.isArray(vector) || vector.length !== 1536 || !Array.isArray(canonicalIdentities)) {
68
+ throw safeError('LIVE_PROVIDER_OPERATION_FAILED');
69
+ }
70
+ await query(
71
+ 'CREATE VECTOR INDEX argo_live_embedding_vector IF NOT EXISTS FOR (e:ArgoLiveEmbeddingEvidence) ON (e.vector) OPTIONS { indexConfig: { `vector.dimensions`: 1536, `vector.similarity_function`: "cosine" } }',
72
+ {},
73
+ );
74
+ const result = await query(
75
+ 'CALL db.index.vector.queryNodes("argo_live_embedding_vector", $limit, $vector) YIELD node, score WHERE node.runId = $runId AND node.canonicalIdentity IN $canonicalIdentities RETURN node { .canonicalIdentity, .canonicalVersion, .contentVersion, .indexVersion, .provider, .model, .qualificationVersion, .dimensions, .vector } AS evidence, score',
76
+ {
77
+ runId,
78
+ vector,
79
+ canonicalIdentities,
80
+ limit: Math.max(1, canonicalIdentities.length * 4),
81
+ },
82
+ );
83
+ return result.records.map(record => normalizeNeo4jValue(record.get('evidence')));
84
+ },
85
+ async cleanup(runId) {
86
+ await query('MATCH (e:ArgoLiveEmbeddingEvidence { runId: $runId }) DELETE e', { runId });
87
+ return this.countWrites(runId);
88
+ },
89
+ async close() {
90
+ if (closed) return;
91
+ closed = true;
92
+ try {
93
+ await driver.close();
94
+ } catch {
95
+ throw safeError('LIVE_PROVIDER_OPERATION_FAILED');
96
+ }
97
+ },
98
+ });
99
+ }
100
+
101
+ function normalizeEvidence(evidence) {
102
+ const fields = [
103
+ 'provider', 'model', 'qualificationVersion', 'dimensions', 'canonicalIdentity',
104
+ 'canonicalVersion', 'contentIdentity', 'contentVersion', 'indexIdentity', 'indexVersion', 'vector',
105
+ ];
106
+ if (!evidence || fields.some(field => evidence[field] === undefined)) {
107
+ throw safeError('LIVE_PROVIDER_OPERATION_FAILED');
108
+ }
109
+ return Object.fromEntries(fields.map(field => [field, evidence[field]]));
110
+ }
111
+
112
+ function normalizeNeo4jValue(evidence) {
113
+ if (!evidence) return evidence;
114
+ const dimensions = evidence.dimensions;
115
+ return {
116
+ ...evidence,
117
+ dimensions: dimensions && typeof dimensions.toNumber === 'function'
118
+ ? dimensions.toNumber()
119
+ : dimensions,
120
+ };
121
+ }
122
+
123
+ function requireValue(configuration, field) {
124
+ const value = configuration[field];
125
+ if (typeof value !== 'string' || value.trim() === '') {
126
+ throw safeError('LIVE_PROVIDER_NEO4J_BOUNDARY_MISSING');
127
+ }
128
+ return value;
129
+ }
130
+
131
+ function safeError(category) {
132
+ const error = new Error(category);
133
+ error.category = category;
134
+ return error;
135
+ }
136
+
137
+ module.exports = { createApprovedNeo4jBoundary };
@@ -0,0 +1,49 @@
1
+ function createLiveEmbeddingProviderClient({ configuration, transport }) {
2
+ if (!configuration || !transport || typeof transport.request !== 'function') {
3
+ throw safeError('LIVE_PROVIDER_CONFIGURATION_REQUIRED');
4
+ }
5
+ return Object.freeze({
6
+ async embed(input) {
7
+ let response;
8
+ try {
9
+ response = await transport.request(
10
+ `${configuration.embeddingBaseUrl}/embeddings`,
11
+ {
12
+ method: 'POST',
13
+ headers: {
14
+ Authorization: `Bearer ${configuration.embeddingApiKey || configuration.qwenKey}`,
15
+ 'Content-Type': 'application/json',
16
+ },
17
+ body: JSON.stringify({
18
+ input,
19
+ model: configuration.embeddingModel,
20
+ dimensions: configuration.embeddingDimensions,
21
+ }),
22
+ },
23
+ );
24
+ } catch {
25
+ throw safeError('LIVE_PROVIDER_REQUEST_FAILED');
26
+ }
27
+ if (!response || response.ok !== true || typeof response.json !== 'function') {
28
+ throw safeError('LIVE_PROVIDER_REQUEST_FAILED');
29
+ }
30
+ let payload;
31
+ try {
32
+ payload = await response.json();
33
+ } catch {
34
+ throw safeError('LIVE_PROVIDER_RESPONSE_INVALID');
35
+ }
36
+ const vector = payload && payload.data && payload.data[0] && payload.data[0].embedding;
37
+ if (!Array.isArray(vector)) throw safeError('LIVE_PROVIDER_RESPONSE_INVALID');
38
+ return vector;
39
+ },
40
+ });
41
+ }
42
+
43
+ function safeError(category) {
44
+ const error = new Error(category);
45
+ error.category = category;
46
+ return error;
47
+ }
48
+
49
+ module.exports = { createLiveEmbeddingProviderClient };