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.
- package/LICENSE +201 -0
- package/README.md +107 -0
- package/argo/.env.example +170 -0
- package/argo/defaults/EA-model-template.qea +0 -0
- package/argo/defaults/design/KG/SystemArchitecture.json +128 -0
- package/argo/mcp-bridges/graph-mcp-stdio.js +98 -0
- package/argo/package.json +8 -0
- package/argo/plugins/argo-cost-collector.js +35 -0
- package/argo/plugins/argo-wakeup.js +29 -0
- package/argo/rules/archgraph.instructions.md +189 -0
- package/argo/schema/ImplementationToCodingHandoff.schema.json +252 -0
- package/argo/schema/ImplementationToIntentTraceProposal.schema.json +180 -0
- package/argo/schema/IntentToImplementationHandoff.schema.json +75 -0
- package/argo/schema/SystemArchitecture.schema.json +378 -0
- package/argo/schema/archimate3.2.md +7153 -0
- package/argo/schema/argob-rules.json +12229 -0
- package/argo/schema/argob.config.json +20 -0
- package/argo/scripts/ARCHITECTURE.md +58 -0
- package/argo/scripts/agentSearchDiagnose.js +407 -0
- package/argo/scripts/archimate32-rules.js +12301 -0
- package/argo/scripts/argo-mcp-server.js +952 -0
- package/argo/scripts/argo-paths.js +168 -0
- package/argo/scripts/argob-schema.js +574 -0
- package/argo/scripts/ea-qea-sync-lib.js +1014 -0
- package/argo/scripts/ea-qea-sync.js +110 -0
- package/argo/scripts/ensureArgoHarnessEnvironment.js +451 -0
- package/argo/scripts/external-graph-query.js +162 -0
- package/argo/scripts/generateArchitectureDiffPlantuml.js +466 -0
- package/argo/scripts/graph-rag/ARCHITECTURE.md +192 -0
- package/argo/scripts/graph-rag/agentCostLog.js +179 -0
- package/argo/scripts/graph-rag/canonicalProjectionAuthority.js +45 -0
- package/argo/scripts/graph-rag/defaultSemanticRetrieval.js +1244 -0
- package/argo/scripts/graph-rag/embeddingProviderProfile.js +89 -0
- package/argo/scripts/graph-rag/embeddingQualificationGate.js +59 -0
- package/argo/scripts/graph-rag/externalProductionConfig.js +74 -0
- package/argo/scripts/graph-rag/hybridRetrieval.js +114 -0
- package/argo/scripts/graph-rag/liveEmbeddingIndexGate.js +128 -0
- package/argo/scripts/graph-rag/liveEmbeddingNeo4jBoundary.js +137 -0
- package/argo/scripts/graph-rag/liveEmbeddingProviderClient.js +49 -0
- package/argo/scripts/graph-rag/liveEmbeddingProviderConfig.js +571 -0
- package/argo/scripts/graph-rag/mcpCrashDiagnostics.js +137 -0
- package/argo/scripts/graph-rag/mutationEmbeddingVectorLifecycle.js +1266 -0
- package/argo/scripts/graph-rag/neo4jNativeRetrieval.js +37 -0
- package/argo/scripts/graph-rag/productionGraphRagRuntime.js +1633 -0
- package/argo/scripts/graph-rag/rerankRetrieval.js +201 -0
- package/argo/scripts/graph-rag/semantic-persistence/ARCHITECTURE.md +51 -0
- package/argo/scripts/graph-rag/semantic-persistence/productionSemanticBackfill.js +342 -0
- package/argo/scripts/graph-rag/semantic-persistence/productionSemanticCheckpointStore.js +99 -0
- package/argo/scripts/graph-rag/semantic-persistence/productionSemanticNeo4jAdapter.js +186 -0
- package/argo/scripts/graph-rag/semantic-persistence/productionSemanticProjectionStore.js +171 -0
- package/argo/scripts/graph-rag/semanticAlignmentLock.js +76 -0
- package/argo/scripts/graph-rag/semanticAlignmentRunner.js +131 -0
- package/argo/scripts/graph-rag/semanticInitConfiguration.js +24 -0
- package/argo/scripts/graph-rag/semanticOperatorError.js +38 -0
- package/argo/scripts/graph-rag/semanticOperatorJourney.js +459 -0
- package/argo/scripts/graph-rag/semanticReadinessAttestationStore.js +398 -0
- package/argo/scripts/graph-rag/semanticRecordText.js +75 -0
- package/argo/scripts/graph-rag/systemMetadataCommandAdapter.js +269 -0
- package/argo/scripts/graph-semantics.js +266 -0
- package/argo/scripts/lossless-write-gate.js +500 -0
- package/argo/scripts/neo4j-system-architecture-store.js +1066 -0
- package/argo/scripts/repair-subdiagram-views.js +288 -0
- package/argo/scripts/repositoryArgoEnvironment.js +101 -0
- package/argo/scripts/runArchitectureTests.js +591 -0
- package/argo/scripts/semanticOperatorJourneyCli.js +91 -0
- package/argo/scripts/syncSystemArchitectureToNeo4j.js +67 -0
- package/argo/scripts/systemarchitecture-mcp-server.js +4508 -0
- package/argo/scripts/test-executors/_template.js +58 -0
- package/argo/scripts/test-executors/default.js +199 -0
- package/argo/scripts/validateStageHandoff.js +459 -0
- package/argo/scripts/validateSystemArchitecture.js +261 -0
- package/argo/scripts/validateTraceProposal.js +181 -0
- package/argo/scripts/validator-mcp-server.js +347 -0
- package/argo/skills/agent-search-diagnosis/SKILL.md +60 -0
- package/argo/skills/argo-init/SKILL.md +86 -0
- package/argo/skills/ea-human-reconcile/SKILL.md +40 -0
- package/bin/argo-deploy.js +12 -0
- package/cordis.patch.yml +6 -0
- package/dsh-argo-wakeup/index.js +17 -0
- package/dsh-argo-wakeup/package.json +1 -0
- package/dsh-argo-workspace/index.js +142 -0
- package/dsh-argo-workspace/package.json +1 -0
- package/install-argo.ps1 +1162 -0
- package/package.json +56 -0
- package/vendor/neo4j-driver-6.2.0.tgz +0 -0
|
@@ -0,0 +1,571 @@
|
|
|
1
|
+
const fs = require('node:fs');
|
|
2
|
+
const path = require('node:path');
|
|
3
|
+
const {
|
|
4
|
+
createSystemMetadataCommandAdapter,
|
|
5
|
+
} = require('./systemMetadataCommandAdapter.js');
|
|
6
|
+
const {
|
|
7
|
+
getArgoEnvPath,
|
|
8
|
+
} = require('../argo-paths.js');
|
|
9
|
+
const {
|
|
10
|
+
PROFILE_KEY,
|
|
11
|
+
QUERY_INSTRUCTION_KEY,
|
|
12
|
+
API_KEY: EMBEDDING_API_KEY_KEY,
|
|
13
|
+
PROFILE_APPROVED,
|
|
14
|
+
requireSupportedEmbeddingProfile,
|
|
15
|
+
requireEmbeddingDimensions,
|
|
16
|
+
} = require('./embeddingProviderProfile.js');
|
|
17
|
+
|
|
18
|
+
const CONFIG_KEYS = Object.freeze([
|
|
19
|
+
'ARGO_EMBEDDING_BASE_URL',
|
|
20
|
+
'ARGO_EMBEDDING_MODEL',
|
|
21
|
+
'ARGO_EMBEDDING_PROVIDER',
|
|
22
|
+
'ARGO_EMBEDDING_MODEL_VERSION',
|
|
23
|
+
'ARGO_EMBEDDING_DIMENSIONS',
|
|
24
|
+
'ARGO_NEO4J_DATABASE_URL',
|
|
25
|
+
'ARGO_NEO4J_DATABASE_USERNAME',
|
|
26
|
+
'ARGO_NEO4J_DATABASE_PASSWORD',
|
|
27
|
+
'QWEN_KEY',
|
|
28
|
+
]);
|
|
29
|
+
const OPTIONAL_CONFIG_KEYS = Object.freeze([
|
|
30
|
+
'ARGO_NEO4J_DATABASE',
|
|
31
|
+
]);
|
|
32
|
+
// Semantic-retrieval tuning knobs (purpose-aware thresholds + bounded top-K).
|
|
33
|
+
// They are read by defaultSemanticRetrieval from process.env and whitelisted here
|
|
34
|
+
// so an approved env file may carry them without tripping SECRET_FILE_UNKNOWN_KEY.
|
|
35
|
+
const RETRIEVAL_TUNING_KEYS = Object.freeze([
|
|
36
|
+
'ARGO_SEMANTIC_MEMORY_THRESHOLD',
|
|
37
|
+
'ARGO_SEMANTIC_MEMORY_THRESHOLD_ELEMENT',
|
|
38
|
+
'ARGO_SEMANTIC_MEMORY_THRESHOLD_RELATIONSHIP',
|
|
39
|
+
'ARGO_SEMANTIC_MEMORY_THRESHOLD_VIEW',
|
|
40
|
+
'ARGO_SEMANTIC_AUDIT_THRESHOLD',
|
|
41
|
+
'ARGO_SEMANTIC_AUDIT_THRESHOLD_ELEMENT',
|
|
42
|
+
'ARGO_SEMANTIC_AUDIT_THRESHOLD_RELATIONSHIP',
|
|
43
|
+
'ARGO_SEMANTIC_AUDIT_THRESHOLD_VIEW',
|
|
44
|
+
'ARGO_SEMANTIC_TOP_K',
|
|
45
|
+
// Hybrid (vector + lexical RRF) retrieval (P2). Off unless
|
|
46
|
+
// ARGO_SEMANTIC_HYBRID=1; weights/k/top-K tune the fusion.
|
|
47
|
+
'ARGO_SEMANTIC_HYBRID',
|
|
48
|
+
'ARGO_SEMANTIC_HYBRID_VECTOR_WEIGHT',
|
|
49
|
+
'ARGO_SEMANTIC_HYBRID_LEXICAL_WEIGHT',
|
|
50
|
+
'ARGO_SEMANTIC_HYBRID_RRF_K',
|
|
51
|
+
'ARGO_SEMANTIC_HYBRID_TOP_K',
|
|
52
|
+
// Rerank (P3) tuning + optional dedicated rerank provider. When the provider
|
|
53
|
+
// keys are unset the reranker falls back to the embedding provider (qwen).
|
|
54
|
+
'ARGO_SEMANTIC_RERANK',
|
|
55
|
+
'ARGO_SEMANTIC_RERANK_MODEL',
|
|
56
|
+
'ARGO_SEMANTIC_RERANK_POOL',
|
|
57
|
+
'ARGO_SEMANTIC_RERANK_RETURN',
|
|
58
|
+
'ARGO_SEMANTIC_RERANK_TIMEOUT_MS',
|
|
59
|
+
'ARGO_RERANK_BASE_URL',
|
|
60
|
+
'ARGO_RERANK_API_KEY',
|
|
61
|
+
'ARGO_RERANK_PROVIDER',
|
|
62
|
+
'ARGO_RERANK_MODEL',
|
|
63
|
+
'ARGO_RERANK_DISABLE_THINKING',
|
|
64
|
+
'ARGO_RERANK_THINKING_PARAM',
|
|
65
|
+
]);
|
|
66
|
+
const OPT_IN_KEYS = Object.freeze({
|
|
67
|
+
ARGO_LIVE_PROVIDER_E2E: 'LIVE_PROVIDER_E2E_OPT_IN_REQUIRED',
|
|
68
|
+
ARGO_W31_LIVE_MUTATION_VECTOR_E2E: 'W31_MUTATION_VECTOR_E2E_OPT_IN_REQUIRED',
|
|
69
|
+
});
|
|
70
|
+
const READABLE_KEYS = Object.freeze([
|
|
71
|
+
...CONFIG_KEYS,
|
|
72
|
+
...OPTIONAL_CONFIG_KEYS,
|
|
73
|
+
...RETRIEVAL_TUNING_KEYS,
|
|
74
|
+
PROFILE_KEY,
|
|
75
|
+
QUERY_INSTRUCTION_KEY,
|
|
76
|
+
EMBEDDING_API_KEY_KEY,
|
|
77
|
+
...Object.keys(OPT_IN_KEYS),
|
|
78
|
+
]);
|
|
79
|
+
const LEGACY_KEYS = Object.freeze(['ARGO_NEO4J_URI', 'ARGO_NEO4J_USERNAME', 'ARGO_NEO4J_PASSWORD']);
|
|
80
|
+
// Host / process-level keys: read from the environment at launch, but NOT
|
|
81
|
+
// accepted inside the .env file (see argo/.env.example Part 2). Kept explicit so
|
|
82
|
+
// the coverage test (tests/env-key-coverage.test.js) can prove every env key
|
|
83
|
+
// referenced by argo/scripts is classified — either a .env key, a host-only key,
|
|
84
|
+
// or a legacy alias. This is what prevents "a key the code already uses is still
|
|
85
|
+
// rejected as unknown".
|
|
86
|
+
const HOST_ONLY_ENV_KEYS = Object.freeze([
|
|
87
|
+
'ARGO_ENV_FILE',
|
|
88
|
+
'ARGO_REPO_ROOT',
|
|
89
|
+
'ARGO_SCHEMA_DIR',
|
|
90
|
+
'ARGO_ACTOR_ELEMENT_TYPE',
|
|
91
|
+
'ARGO_EA_QEA',
|
|
92
|
+
'ARGO_WORKSPACE_ROOTS',
|
|
93
|
+
'ARGO_SERVER_PATH',
|
|
94
|
+
'GRAPH_MCP_URL',
|
|
95
|
+
'EA_QEA_DEBUG',
|
|
96
|
+
'WORKSPACE_FOLDER',
|
|
97
|
+
'ARGO_TEST_TIMEOUT_MS',
|
|
98
|
+
'ARGO_MCP_MUTATION_RESPONSE_DEBUG',
|
|
99
|
+
'ARGO_MCP_SEMANTIC_DEDUP',
|
|
100
|
+
'ARGO_MCP_SEMANTIC_DEDUP_THRESHOLD',
|
|
101
|
+
'ARGO_SEMANTIC_DEDUP_THRESHOLD',
|
|
102
|
+
'ARGO_COST_PROFILER',
|
|
103
|
+
'ARGO_COST_TRACE_MAX_BYTES',
|
|
104
|
+
]);
|
|
105
|
+
const PROHIBITED_RUNTIME_FIELD_KEYS = Object.freeze(['neo4jUri', 'embeddingCredential']);
|
|
106
|
+
const SECRET_KEYS = new Set(['ARGO_NEO4J_DATABASE_PASSWORD', 'QWEN_KEY', 'ARGO_RERANK_API_KEY', EMBEDDING_API_KEY_KEY]);
|
|
107
|
+
const APPROVED = Object.freeze({
|
|
108
|
+
ARGO_EMBEDDING_BASE_URL: 'https://llm-clids9mqc5o1mbvb.cn-beijing.maas.aliyuncs.com/compatible-mode/v1',
|
|
109
|
+
ARGO_EMBEDDING_MODEL: 'qwen3.7-text-embedding',
|
|
110
|
+
ARGO_EMBEDDING_PROVIDER: 'alibaba-cloud-model-studio-openai-compatible-cn-beijing',
|
|
111
|
+
ARGO_EMBEDDING_MODEL_VERSION: 'qualification-2026-07-25',
|
|
112
|
+
ARGO_EMBEDDING_DIMENSIONS: '1536',
|
|
113
|
+
});
|
|
114
|
+
const issuedAdapters = new WeakSet();
|
|
115
|
+
const issuedTraces = new WeakSet();
|
|
116
|
+
const invalidTraces = new WeakSet();
|
|
117
|
+
const prohibitedTraces = new WeakSet();
|
|
118
|
+
|
|
119
|
+
async function resolveApprovedLiveConfiguration(options) {
|
|
120
|
+
requireProductionOptions(options);
|
|
121
|
+
const repositoryRoot = requireRoot(options.repositoryRoot);
|
|
122
|
+
return resolveTrusted({
|
|
123
|
+
repositoryRoot,
|
|
124
|
+
requiredOptIns: resolveRequiredOptIns(options),
|
|
125
|
+
adapters: {
|
|
126
|
+
filesystem: fs,
|
|
127
|
+
systemMetadata: createSystemMetadataCommandAdapter({ repositoryRoot }),
|
|
128
|
+
},
|
|
129
|
+
source: createTrustedSource({
|
|
130
|
+
behavior: productionSourceBehavior(repositoryRoot),
|
|
131
|
+
}),
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async function withApprovedLiveConfigurationTestComposition(
|
|
136
|
+
{ sourceBehavior, adapters = {}, observeTrace },
|
|
137
|
+
callback,
|
|
138
|
+
) {
|
|
139
|
+
if (!sourceBehavior || typeof callback !== 'function') throw safeError('SOURCE_ADAPTER_UNTRUSTED');
|
|
140
|
+
const source = createTrustedSource({ behavior: sourceBehavior, observeTrace });
|
|
141
|
+
const resolver = Object.freeze(options => resolveTrusted({
|
|
142
|
+
repositoryRoot: requireRoot(options && options.repositoryRoot),
|
|
143
|
+
requiredOptIns: resolveRequiredOptIns(options),
|
|
144
|
+
adapters,
|
|
145
|
+
source,
|
|
146
|
+
}));
|
|
147
|
+
return callback(resolver);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async function resolveTrusted({
|
|
151
|
+
repositoryRoot,
|
|
152
|
+
requiredOptIns = ['ARGO_LIVE_PROVIDER_E2E'],
|
|
153
|
+
adapters,
|
|
154
|
+
source,
|
|
155
|
+
}) {
|
|
156
|
+
if (!issuedAdapters.has(source)) throw safeError('SOURCE_ADAPTER_UNTRUSTED');
|
|
157
|
+
const filesystem = adapters.filesystem || fs;
|
|
158
|
+
const canonicalFilePath = getArgoEnvPath();
|
|
159
|
+
const configuredFilePath = source.filePath();
|
|
160
|
+
const fileExists = filesystem.existsSync(configuredFilePath);
|
|
161
|
+
if (fileExists || path.resolve(configuredFilePath) !== path.resolve(canonicalFilePath)) {
|
|
162
|
+
preflightFile({
|
|
163
|
+
canonicalFilePath,
|
|
164
|
+
configuredFilePath,
|
|
165
|
+
filesystem,
|
|
166
|
+
adapters,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const processValues = new Map();
|
|
171
|
+
for (const key of [...READABLE_KEYS, ...LEGACY_KEYS, ...PROHIBITED_RUNTIME_FIELD_KEYS]) {
|
|
172
|
+
const envelope = source.readProcessKey(key);
|
|
173
|
+
validateEnvelope(envelope, source, key, null, 'process');
|
|
174
|
+
processValues.set(key, envelope.value);
|
|
175
|
+
}
|
|
176
|
+
if ([...LEGACY_KEYS, ...PROHIBITED_RUNTIME_FIELD_KEYS].some(key => present(processValues.get(key)))) {
|
|
177
|
+
throw safeError('SECRET_SOURCE_PROVENANCE_PROHIBITED');
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const fileValues = new Map();
|
|
181
|
+
if (fileExists) {
|
|
182
|
+
const records = source.readFileEntries(configuredFilePath);
|
|
183
|
+
if (!Array.isArray(records)) throw safeError('SOURCE_TRACE_INVALID');
|
|
184
|
+
for (const record of records) {
|
|
185
|
+
if (!record || !Object.isFrozen(record)) throw safeError('SOURCE_TRACE_UNTRUSTED');
|
|
186
|
+
validateTrace(record.trace, source, record.key, configuredFilePath, 'file');
|
|
187
|
+
if (fileValues.has(record.key)) throw safeError('SECRET_FILE_DUPLICATE_KEY');
|
|
188
|
+
if (!READABLE_KEYS.includes(record.key)) {
|
|
189
|
+
throw safeError(PROHIBITED_RUNTIME_FIELD_KEYS.includes(record.key) || secretLooking(record.key)
|
|
190
|
+
? 'SECRET_FILE_UNKNOWN_KEY'
|
|
191
|
+
: 'LIVE_PROVIDER_CONFIGURATION_REQUIRED');
|
|
192
|
+
}
|
|
193
|
+
fileValues.set(record.key, record.value);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const normalized = {};
|
|
198
|
+
const attribution = {};
|
|
199
|
+
for (const key of CONFIG_KEYS) {
|
|
200
|
+
const processValue = processValues.get(key);
|
|
201
|
+
const fileValue = fileValues.get(key);
|
|
202
|
+
if (present(processValue) && present(fileValue) && processValue !== fileValue) {
|
|
203
|
+
throw safeError(SECRET_KEYS.has(key)
|
|
204
|
+
? 'SECRET_SOURCE_CONFLICT'
|
|
205
|
+
: 'LIVE_PROVIDER_CONFIGURATION_CONFLICT');
|
|
206
|
+
}
|
|
207
|
+
if (present(processValue)) {
|
|
208
|
+
normalized[key] = processValue;
|
|
209
|
+
attribution[key] = 'process';
|
|
210
|
+
} else if (present(fileValue)) {
|
|
211
|
+
normalized[key] = fileValue;
|
|
212
|
+
attribution[key] = 'file';
|
|
213
|
+
} else {
|
|
214
|
+
const error = safeError(SECRET_KEYS.has(key)
|
|
215
|
+
? 'APPROVED_SECRET_REQUIRED'
|
|
216
|
+
: 'LIVE_PROVIDER_CONFIGURATION_REQUIRED');
|
|
217
|
+
error.field = key;
|
|
218
|
+
throw error;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
for (const key of requiredOptIns) {
|
|
222
|
+
const processValue = processValues.get(key);
|
|
223
|
+
const fileValue = fileValues.get(key);
|
|
224
|
+
if (present(processValue) && present(fileValue) && processValue !== fileValue) {
|
|
225
|
+
throw safeError('LIVE_PROVIDER_CONFIGURATION_CONFLICT');
|
|
226
|
+
}
|
|
227
|
+
const selectedValue = present(processValue) ? processValue : fileValue;
|
|
228
|
+
if (selectedValue !== '1') {
|
|
229
|
+
throw safeError(OPT_IN_KEYS[key]);
|
|
230
|
+
}
|
|
231
|
+
attribution[key] = present(processValue) ? 'process' : 'file';
|
|
232
|
+
}
|
|
233
|
+
const profile = requireSupportedEmbeddingProfile(
|
|
234
|
+
selectOptional(processValues, fileValues, PROFILE_KEY),
|
|
235
|
+
);
|
|
236
|
+
const profileConfiguration = buildProfileConfiguration(normalized, profile);
|
|
237
|
+
const embeddingQueryInstruction = selectOptional(processValues, fileValues, QUERY_INSTRUCTION_KEY);
|
|
238
|
+
const explicitEmbeddingApiKey = selectOptional(processValues, fileValues, EMBEDDING_API_KEY_KEY);
|
|
239
|
+
const configuration = Object.freeze({
|
|
240
|
+
...profileConfiguration,
|
|
241
|
+
embeddingQueryInstruction,
|
|
242
|
+
embeddingApiKey: explicitEmbeddingApiKey || normalized.QWEN_KEY,
|
|
243
|
+
neo4jDatabaseUrl: normalized.ARGO_NEO4J_DATABASE_URL,
|
|
244
|
+
neo4jDatabaseUsername: normalized.ARGO_NEO4J_DATABASE_USERNAME,
|
|
245
|
+
neo4jDatabasePassword: normalized.ARGO_NEO4J_DATABASE_PASSWORD,
|
|
246
|
+
neo4jDatabase: optionalDatabaseName(processValues.get('ARGO_NEO4J_DATABASE') || fileValues.get('ARGO_NEO4J_DATABASE'), repositoryRoot),
|
|
247
|
+
qwenKey: normalized.QWEN_KEY,
|
|
248
|
+
});
|
|
249
|
+
return Object.freeze({
|
|
250
|
+
...configuration,
|
|
251
|
+
configuration,
|
|
252
|
+
attribution: Object.freeze({ ...attribution }),
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// Profile-aware embedding identity. `approved` (the default) enforces the
|
|
257
|
+
// human-approved cloud values byte-for-byte; `openai-compatible` accepts the
|
|
258
|
+
// configured self-hosted endpoint verbatim but still fails closed on any missing
|
|
259
|
+
// key or invalid dimension (no implicit default).
|
|
260
|
+
function buildProfileConfiguration(normalized, profileValue) {
|
|
261
|
+
const profile = requireSupportedEmbeddingProfile(profileValue);
|
|
262
|
+
for (const key of [
|
|
263
|
+
'ARGO_EMBEDDING_BASE_URL',
|
|
264
|
+
'ARGO_EMBEDDING_MODEL',
|
|
265
|
+
'ARGO_EMBEDDING_PROVIDER',
|
|
266
|
+
'ARGO_EMBEDDING_MODEL_VERSION',
|
|
267
|
+
]) {
|
|
268
|
+
if (!present(normalized[key])) {
|
|
269
|
+
const error = safeError('LIVE_PROVIDER_CONFIGURATION_REQUIRED');
|
|
270
|
+
error.field = key;
|
|
271
|
+
throw error;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
if (profile === PROFILE_APPROVED) {
|
|
275
|
+
for (const [key, expected] of Object.entries(APPROVED)) {
|
|
276
|
+
if (normalized[key] !== expected) throw safeError('LIVE_PROVIDER_CONFIGURATION_REQUIRED');
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return Object.freeze({
|
|
280
|
+
embeddingProfile: profile,
|
|
281
|
+
embeddingBaseUrl: normalized.ARGO_EMBEDDING_BASE_URL,
|
|
282
|
+
embeddingModel: normalized.ARGO_EMBEDDING_MODEL,
|
|
283
|
+
embeddingProvider: normalized.ARGO_EMBEDDING_PROVIDER,
|
|
284
|
+
embeddingModelVersion: normalized.ARGO_EMBEDDING_MODEL_VERSION,
|
|
285
|
+
embeddingDimensions: requireEmbeddingDimensions(normalized.ARGO_EMBEDDING_DIMENSIONS),
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function selectOptional(processValues, fileValues, key) {
|
|
290
|
+
const processValue = processValues.get(key);
|
|
291
|
+
const fileValue = fileValues.get(key);
|
|
292
|
+
if (present(processValue) && present(fileValue) && processValue !== fileValue) {
|
|
293
|
+
throw safeError(SECRET_KEYS.has(key)
|
|
294
|
+
? 'SECRET_SOURCE_CONFLICT'
|
|
295
|
+
: 'LIVE_PROVIDER_CONFIGURATION_CONFLICT');
|
|
296
|
+
}
|
|
297
|
+
if (present(processValue)) return processValue;
|
|
298
|
+
if (present(fileValue)) return fileValue;
|
|
299
|
+
return '';
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function optionalDatabaseName(value, repositoryRoot) {
|
|
303
|
+
if (present(value)) return String(value).trim();
|
|
304
|
+
const repoName = path.basename(repositoryRoot);
|
|
305
|
+
const normalized = String(repoName)
|
|
306
|
+
.toLowerCase()
|
|
307
|
+
.replace(/[^a-z0-9.-]+/g, '-')
|
|
308
|
+
.replace(/^-+|-+$/g, '')
|
|
309
|
+
.replace(/\.{2,}/g, '.')
|
|
310
|
+
.replace(/-{2,}/g, '-');
|
|
311
|
+
const safe = normalized || 'workspace';
|
|
312
|
+
const prefixed = /^[a-z]/.test(safe) ? safe : `db-${safe}`;
|
|
313
|
+
return prefixed.slice(0, 63);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function createTrustedSource({ behavior, observeTrace }) {
|
|
317
|
+
const adapter = {
|
|
318
|
+
filePath: () => path.resolve(String(behavior.expectedFilePath)),
|
|
319
|
+
readProcessKey(key) {
|
|
320
|
+
const selected = selectProcessOperation(behavior, key);
|
|
321
|
+
return Object.freeze({
|
|
322
|
+
value: selected.read(key),
|
|
323
|
+
trace: issueTrace(selected.makeTrace(key), selected.kind, observeTrace),
|
|
324
|
+
});
|
|
325
|
+
},
|
|
326
|
+
readFileEntries(requestedPath) {
|
|
327
|
+
const selected = selectFileOperation(behavior);
|
|
328
|
+
const entries = selected.read(requestedPath);
|
|
329
|
+
if (!Array.isArray(entries)) return entries;
|
|
330
|
+
return entries.map(([key, value]) => Object.freeze({
|
|
331
|
+
key,
|
|
332
|
+
value,
|
|
333
|
+
trace: issueTrace(selected.makeTrace(key, requestedPath), selected.kind, observeTrace),
|
|
334
|
+
}));
|
|
335
|
+
},
|
|
336
|
+
observeValidation(traceValue, trusted) {
|
|
337
|
+
if (observeTrace) observeTrace(Object.freeze({ phase: 'validated', trace: traceValue, trusted }));
|
|
338
|
+
},
|
|
339
|
+
};
|
|
340
|
+
Object.freeze(adapter);
|
|
341
|
+
issuedAdapters.add(adapter);
|
|
342
|
+
return adapter;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function selectProcessOperation(behavior, key) {
|
|
346
|
+
const mutations = [
|
|
347
|
+
['readCliKey', () => makeTrace('cli', 'cli', key, 'read', [key]), 'prohibited'],
|
|
348
|
+
['readLiteralKey', () => makeTrace('literal', 'literal', key, 'read', [key]), 'prohibited'],
|
|
349
|
+
['readFallbackKey', () => makeTrace('process', null, key, 'fallback', [key]), 'prohibited'],
|
|
350
|
+
['readAliasedProcessKey', () => makeTrace('process', null, key, 'read', ['QWEN_ALIAS', key]), 'prohibited'],
|
|
351
|
+
['readIndirectProcessKey', () => makeTrace('process', null, key, 'indirect', ['configuration', 'credentials', key]), 'prohibited'],
|
|
352
|
+
['readProcessKeyWithForgedTrace', () => makeTrace('process', null, key, 'read', [key]), 'forged'],
|
|
353
|
+
['readProcessKeyWithMutableTrace', () => makeTrace('process', null, key, 'read', [key]), 'mutable'],
|
|
354
|
+
['readProcessKeyWithInvalidTraceSchema', () => ({ sourceKind: 'process' }), 'invalid'],
|
|
355
|
+
['readProcessKeyWithRequestedKeyMismatch', () => makeTrace('process', null, `${key}-mismatch`, 'read', [key]), 'invalid'],
|
|
356
|
+
['readProcessKeyWithMissingTraceField', () => ({
|
|
357
|
+
sourceKind: 'process', path: null, key, operation: 'read',
|
|
358
|
+
}), 'invalid'],
|
|
359
|
+
['readProcessKeyWithExtraTraceField', () => ({
|
|
360
|
+
...makeTrace('process', null, key, 'read', [key]), extra: true,
|
|
361
|
+
}), 'invalid'],
|
|
362
|
+
['readProcessKeyWithWrongTraceFieldType', () => makeTrace('process', null, key, 'read', key), 'invalid'],
|
|
363
|
+
];
|
|
364
|
+
if (key === 'QWEN_KEY') {
|
|
365
|
+
for (const [method, make, kind] of mutations) {
|
|
366
|
+
if (typeof behavior[method] === 'function') return { read: behavior[method], makeTrace: make, kind };
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
return {
|
|
370
|
+
read: behavior.readProcessKey,
|
|
371
|
+
makeTrace: requested => makeTrace('process', null, requested, 'read', [requested]),
|
|
372
|
+
kind: 'issued',
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
function selectFileOperation(behavior) {
|
|
377
|
+
if (typeof behavior.readFileEntriesWithRequestedPathMismatch === 'function') {
|
|
378
|
+
return {
|
|
379
|
+
read: behavior.readFileEntriesWithRequestedPathMismatch,
|
|
380
|
+
makeTrace: (key, requested) => makeTrace('file', `${requested}.mismatch`, key, 'read', [key]),
|
|
381
|
+
kind: 'invalid',
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
return {
|
|
385
|
+
read: behavior.readFileEntries,
|
|
386
|
+
makeTrace: (key, requested) => makeTrace('file', requested, key, 'read', [key]),
|
|
387
|
+
kind: 'issued',
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
function issueTrace(candidate, kind, observeTrace) {
|
|
392
|
+
const aliasChain = Array.isArray(candidate.aliasChain)
|
|
393
|
+
? (kind === 'mutable' ? [...candidate.aliasChain] : Object.freeze([...candidate.aliasChain]))
|
|
394
|
+
: candidate.aliasChain;
|
|
395
|
+
const value = kind === 'mutable'
|
|
396
|
+
? { ...candidate, aliasChain }
|
|
397
|
+
: Object.freeze({ ...candidate, aliasChain });
|
|
398
|
+
if (kind !== 'forged') issuedTraces.add(value);
|
|
399
|
+
if (kind === 'invalid') invalidTraces.add(value);
|
|
400
|
+
if (kind === 'prohibited') prohibitedTraces.add(value);
|
|
401
|
+
if (observeTrace) observeTrace(Object.freeze({ phase: 'issued', trace: value }));
|
|
402
|
+
return value;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function validateEnvelope(envelope, source, key, requestedPath, sourceKind) {
|
|
406
|
+
if (!envelope || !Object.isFrozen(envelope)) throw safeError('SOURCE_TRACE_UNTRUSTED');
|
|
407
|
+
validateTrace(envelope.trace, source, key, requestedPath, sourceKind);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
function validateTrace(value, source, key, requestedPath, sourceKind) {
|
|
411
|
+
const trusted = issuedTraces.has(value)
|
|
412
|
+
&& Object.isFrozen(value)
|
|
413
|
+
&& Object.isFrozen(value && value.aliasChain);
|
|
414
|
+
source.observeValidation(value, trusted);
|
|
415
|
+
if (!trusted) throw safeError('SOURCE_TRACE_UNTRUSTED');
|
|
416
|
+
if (invalidTraces.has(value)) throw safeError('SOURCE_TRACE_INVALID');
|
|
417
|
+
const fields = value && typeof value === 'object' ? Object.keys(value).sort().join(',') : '';
|
|
418
|
+
if (
|
|
419
|
+
fields !== 'aliasChain,key,operation,path,sourceKind'
|
|
420
|
+
|| typeof value.sourceKind !== 'string'
|
|
421
|
+
|| !(value.path === null || typeof value.path === 'string')
|
|
422
|
+
|| typeof value.key !== 'string'
|
|
423
|
+
|| typeof value.operation !== 'string'
|
|
424
|
+
|| !Array.isArray(value.aliasChain)
|
|
425
|
+
|| value.aliasChain.some(item => typeof item !== 'string')
|
|
426
|
+
) {
|
|
427
|
+
throw safeError('SOURCE_TRACE_INVALID');
|
|
428
|
+
}
|
|
429
|
+
if (prohibitedTraces.has(value)) throw safeError('SECRET_SOURCE_PROVENANCE_PROHIBITED');
|
|
430
|
+
if (
|
|
431
|
+
value.sourceKind !== sourceKind
|
|
432
|
+
|| value.path !== requestedPath
|
|
433
|
+
|| value.key !== key
|
|
434
|
+
|| value.operation !== 'read'
|
|
435
|
+
|| value.aliasChain.length !== 1
|
|
436
|
+
|| value.aliasChain[0] !== key
|
|
437
|
+
) {
|
|
438
|
+
throw safeError('SOURCE_TRACE_INVALID');
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
function makeTrace(sourceKind, sourcePath, key, operation, aliasChain) {
|
|
443
|
+
return { sourceKind, path: sourcePath, key, operation, aliasChain };
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
function preflightFile({ canonicalFilePath, configuredFilePath, filesystem, adapters }) {
|
|
447
|
+
if (path.resolve(configuredFilePath) !== path.resolve(canonicalFilePath)) {
|
|
448
|
+
throw safeError('SECRET_FILE_PATH_PROHIBITED');
|
|
449
|
+
}
|
|
450
|
+
const stat = filesystem.lstatSync(configuredFilePath);
|
|
451
|
+
if (!stat.isFile() || stat.isSymbolicLink()) throw safeError('SECRET_FILE_REPARSE_PROHIBITED');
|
|
452
|
+
if (path.resolve(filesystem.realpathSync(configuredFilePath)) !== path.resolve(canonicalFilePath)) {
|
|
453
|
+
throw safeError('SECRET_FILE_PATH_PROHIBITED');
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
let ignored;
|
|
457
|
+
let tracked;
|
|
458
|
+
if (adapters.systemMetadata) {
|
|
459
|
+
const insideRepository = adapters.systemMetadata.isSecretFileInsideGitRepository().status === 0;
|
|
460
|
+
ignored = insideRepository ? adapters.systemMetadata.isSecretFileIgnored() : true;
|
|
461
|
+
tracked = insideRepository ? adapters.systemMetadata.isSecretFileTracked() : false;
|
|
462
|
+
} else {
|
|
463
|
+
ignored = adapters.git.isIgnored(configuredFilePath);
|
|
464
|
+
tracked = adapters.git.isTracked(configuredFilePath);
|
|
465
|
+
}
|
|
466
|
+
// Only the "never committed" guarantee is enforced. OS-level ACL / file-mode
|
|
467
|
+
// hardening is intentionally NOT required (it caused frequent false failures).
|
|
468
|
+
if (tracked) throw safeError('SECRET_FILE_TRACKED');
|
|
469
|
+
if (!ignored) throw safeError('SECRET_FILE_NOT_IGNORED');
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
function productionSourceBehavior(repositoryRoot) {
|
|
473
|
+
return Object.freeze({
|
|
474
|
+
expectedFilePath: getArgoEnvPath(),
|
|
475
|
+
readProcessKey: key => process.env[key],
|
|
476
|
+
readFileEntries: filePath => parseEnv(fs.readFileSync(filePath, 'utf8')),
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
function parseEnv(text) {
|
|
481
|
+
const entries = [];
|
|
482
|
+
for (const raw of String(text).split(/\r?\n/)) {
|
|
483
|
+
const line = raw.trim();
|
|
484
|
+
if (!line || line.startsWith('#')) continue;
|
|
485
|
+
const equals = line.indexOf('=');
|
|
486
|
+
if (equals < 1) throw safeError('SECRET_FILE_INVALID');
|
|
487
|
+
entries.push([line.slice(0, equals).trim(), line.slice(equals + 1)]);
|
|
488
|
+
}
|
|
489
|
+
return entries;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
function requireRoot(value) {
|
|
493
|
+
if (typeof value !== 'string' || value.trim() === '') throw safeError('LIVE_PROVIDER_CONFIGURATION_REQUIRED');
|
|
494
|
+
return path.resolve(value);
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
function requireProductionOptions(options) {
|
|
498
|
+
if (
|
|
499
|
+
!options
|
|
500
|
+
|| typeof options !== 'object'
|
|
501
|
+
|| Array.isArray(options)
|
|
502
|
+
|| !Reflect.ownKeys(options).every(key => (
|
|
503
|
+
key === 'repositoryRoot'
|
|
504
|
+
|| key === 'requiredOptIns'
|
|
505
|
+
|| key === 'useCase'
|
|
506
|
+
))
|
|
507
|
+
|| !Reflect.ownKeys(options).includes('repositoryRoot')
|
|
508
|
+
) {
|
|
509
|
+
throw safeError('SOURCE_ADAPTER_UNTRUSTED');
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
function resolveRequiredOptIns(options) {
|
|
514
|
+
requireProductionOptions(options);
|
|
515
|
+
if (Object.prototype.hasOwnProperty.call(options, 'useCase')) {
|
|
516
|
+
if (
|
|
517
|
+
options.useCase !== 'production-semantic-query'
|
|
518
|
+
|| Object.prototype.hasOwnProperty.call(options, 'requiredOptIns')
|
|
519
|
+
) {
|
|
520
|
+
throw safeError('SOURCE_ADAPTER_UNTRUSTED');
|
|
521
|
+
}
|
|
522
|
+
return [];
|
|
523
|
+
}
|
|
524
|
+
return normalizeRequiredOptIns(options.requiredOptIns);
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
function normalizeRequiredOptIns(value) {
|
|
528
|
+
const requested = value === undefined ? ['ARGO_LIVE_PROVIDER_E2E'] : value;
|
|
529
|
+
if (!Array.isArray(requested) || requested.length === 0) {
|
|
530
|
+
throw safeError('SOURCE_ADAPTER_UNTRUSTED');
|
|
531
|
+
}
|
|
532
|
+
const normalized = [];
|
|
533
|
+
for (const key of requested) {
|
|
534
|
+
if (!Object.prototype.hasOwnProperty.call(OPT_IN_KEYS, key)) {
|
|
535
|
+
throw safeError('SOURCE_ADAPTER_UNTRUSTED');
|
|
536
|
+
}
|
|
537
|
+
if (!normalized.includes(key)) {
|
|
538
|
+
normalized.push(key);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
return normalized;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
function present(value) {
|
|
545
|
+
return typeof value === 'string' && value.trim() !== '';
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
function secretLooking(key) {
|
|
549
|
+
return /(?:key|password|secret|token|credential)/i.test(String(key));
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
function safeError(category) {
|
|
553
|
+
const error = new Error(category);
|
|
554
|
+
error.category = category;
|
|
555
|
+
return error;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
module.exports = {
|
|
559
|
+
resolveApprovedLiveConfiguration,
|
|
560
|
+
withApprovedLiveConfigurationTestComposition,
|
|
561
|
+
buildProfileConfiguration,
|
|
562
|
+
APPROVED_EMBEDDING_VALUES: APPROVED,
|
|
563
|
+
// The authoritative set of keys an approved `.env` file may carry. The
|
|
564
|
+
// committed `.env.example` must document exactly this set (see
|
|
565
|
+
// tests/env-example.test.js); SECRET_KEYS marks the subset that must be
|
|
566
|
+
// preflighted as secrets.
|
|
567
|
+
ENV_FILE_KEYS: READABLE_KEYS,
|
|
568
|
+
ENV_FILE_SECRET_KEYS: Object.freeze(Array.from(SECRET_KEYS)),
|
|
569
|
+
HOST_ONLY_ENV_KEYS,
|
|
570
|
+
ENV_FILE_LEGACY_KEYS: LEGACY_KEYS,
|
|
571
|
+
};
|