archgraph-argo 0.1.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 +115 -0
- package/argo/package.json +8 -0
- package/argo/rules/intent-architecture-global-rule.md +45 -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.pdf +0 -0
- package/argo/scripts/ARCHITECTURE.md +57 -0
- package/argo/scripts/archimate32-rules.js +12301 -0
- package/argo/scripts/argo-mcp-server.js +629 -0
- package/argo/scripts/argo-paths.js +77 -0
- package/argo/scripts/ensureArgoHarnessEnvironment.js +340 -0
- package/argo/scripts/generateArchitectureDiffPlantuml.js +466 -0
- package/argo/scripts/graph-rag/ARCHITECTURE.md +192 -0
- package/argo/scripts/graph-rag/canonicalProjectionAuthority.js +45 -0
- package/argo/scripts/graph-rag/defaultSemanticRetrieval.js +969 -0
- package/argo/scripts/graph-rag/embeddingQualificationGate.js +59 -0
- package/argo/scripts/graph-rag/externalProductionConfig.js +74 -0
- package/argo/scripts/graph-rag/liveEmbeddingIndexGate.js +129 -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 +481 -0
- package/argo/scripts/graph-rag/mutationEmbeddingVectorLifecycle.js +1261 -0
- package/argo/scripts/graph-rag/neo4jNativeRetrieval.js +37 -0
- package/argo/scripts/graph-rag/productionGraphRagRuntime.js +1624 -0
- package/argo/scripts/graph-rag/semantic-persistence/ARCHITECTURE.md +51 -0
- package/argo/scripts/graph-rag/semantic-persistence/productionSemanticBackfill.js +241 -0
- package/argo/scripts/graph-rag/semantic-persistence/productionSemanticCheckpointStore.js +99 -0
- package/argo/scripts/graph-rag/semantic-persistence/productionSemanticNeo4jAdapter.js +149 -0
- package/argo/scripts/graph-rag/semantic-persistence/productionSemanticProjectionStore.js +171 -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/systemMetadataCommandAdapter.js +269 -0
- package/argo/scripts/graph-semantics.js +220 -0
- package/argo/scripts/neo4j-system-architecture-store.js +777 -0
- package/argo/scripts/repositoryArgoEnvironment.js +101 -0
- package/argo/scripts/runArchitectureTests.js +583 -0
- package/argo/scripts/semanticOperatorJourneyCli.js +91 -0
- package/argo/scripts/syncSystemArchitectureToNeo4j.js +67 -0
- package/argo/scripts/systemarchitecture-mcp-server.js +2965 -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 +254 -0
- package/argo/scripts/validateTraceProposal.js +181 -0
- package/argo/scripts/validator-mcp-server.js +377 -0
- package/argo/skills/argo-init/SKILL.md +110 -0
- package/bin/argo-deploy.js +12 -0
- package/install-argo.ps1 +112 -0
- package/package.json +28 -0
- 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,269 @@
|
|
|
1
|
+
const { spawnSync } = require('node:child_process');
|
|
2
|
+
const path = require('node:path');
|
|
3
|
+
|
|
4
|
+
const {
|
|
5
|
+
getArgoEnvPath,
|
|
6
|
+
} = require('../argo-paths.js');
|
|
7
|
+
|
|
8
|
+
const CAPABILITY_NAMES = Object.freeze([
|
|
9
|
+
'isSecretFileIgnored',
|
|
10
|
+
'isSecretFileTracked',
|
|
11
|
+
'isSecretFileInsideGitRepository',
|
|
12
|
+
'readCurrentIdentity',
|
|
13
|
+
'readSecretFileAcl',
|
|
14
|
+
]);
|
|
15
|
+
|
|
16
|
+
function createSystemMetadataCommandAdapter(options = {}) {
|
|
17
|
+
requireExactKeys(options, ['repositoryRoot']);
|
|
18
|
+
const repositoryRoot = requireRepositoryRoot(options.repositoryRoot);
|
|
19
|
+
return createAdapter({
|
|
20
|
+
repositoryRoot,
|
|
21
|
+
executeMetadataCommand: spawnSync,
|
|
22
|
+
mutateInvocation: undefined,
|
|
23
|
+
forbiddenValues: [],
|
|
24
|
+
}).adapter;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function createReadinessAttestationMetadataAdapter(options = {}) {
|
|
28
|
+
requireExactKeys(options, ['repositoryRoot']);
|
|
29
|
+
const repositoryRoot = requireRepositoryRoot(options.repositoryRoot);
|
|
30
|
+
const file = path.join(
|
|
31
|
+
options.repositoryRoot,
|
|
32
|
+
'.argo',
|
|
33
|
+
'temp',
|
|
34
|
+
'semantic-readiness-attestation.json',
|
|
35
|
+
);
|
|
36
|
+
const directory = path.dirname(file);
|
|
37
|
+
const environment = sanitizedEnvironment();
|
|
38
|
+
|
|
39
|
+
function spawnExact(executable, args) {
|
|
40
|
+
return spawnSync(executable, args, {
|
|
41
|
+
cwd: repositoryRoot,
|
|
42
|
+
encoding: 'utf8',
|
|
43
|
+
env: { ...environment },
|
|
44
|
+
shell: false,
|
|
45
|
+
windowsHide: true,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return Object.freeze({
|
|
50
|
+
readCurrentIdentity: () => spawnExact('whoami', []),
|
|
51
|
+
readReadinessAttestationDirectoryAcl: () => spawnExact('icacls', [directory]),
|
|
52
|
+
readReadinessAttestationAcl: () => spawnExact('icacls', [file]),
|
|
53
|
+
readReadinessAttestationOwner: () => spawnExact('powershell.exe', [
|
|
54
|
+
'-NoProfile',
|
|
55
|
+
'-NonInteractive',
|
|
56
|
+
'-Command',
|
|
57
|
+
exactOwnerScript(file),
|
|
58
|
+
]),
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function exactOwnerScript(file) {
|
|
63
|
+
const literalPath = String(file).replace(/'/g, "''");
|
|
64
|
+
return `(Get-Acl -LiteralPath '${literalPath}').Owner`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function sanitizedEnvironment() {
|
|
68
|
+
return Object.freeze(Object.fromEntries(
|
|
69
|
+
['PATH', 'Path', 'PATHEXT', 'SystemRoot', 'WINDIR']
|
|
70
|
+
.filter(key => typeof process.env[key] === 'string')
|
|
71
|
+
.map(key => [key, process.env[key]]),
|
|
72
|
+
));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function withSystemMetadataCommandTestComposition(options = {}, callback) {
|
|
76
|
+
requireExactKeys(options, [
|
|
77
|
+
'executeMetadataCommand',
|
|
78
|
+
'forbiddenValues',
|
|
79
|
+
'mutateInvocation',
|
|
80
|
+
'repositoryRoot',
|
|
81
|
+
], true);
|
|
82
|
+
if (typeof options.executeMetadataCommand !== 'function' || typeof callback !== 'function') {
|
|
83
|
+
throw prohibited();
|
|
84
|
+
}
|
|
85
|
+
const composition = createAdapter({
|
|
86
|
+
repositoryRoot: requireRepositoryRoot(options.repositoryRoot),
|
|
87
|
+
executeMetadataCommand: options.executeMetadataCommand,
|
|
88
|
+
mutateInvocation: options.mutateInvocation,
|
|
89
|
+
forbiddenValues: Array.isArray(options.forbiddenValues) ? [...options.forbiddenValues] : [],
|
|
90
|
+
});
|
|
91
|
+
let result;
|
|
92
|
+
let then;
|
|
93
|
+
let asyncRevocationOwner = false;
|
|
94
|
+
try {
|
|
95
|
+
result = callback(composition.adapter);
|
|
96
|
+
if (
|
|
97
|
+
result !== null
|
|
98
|
+
&& (typeof result === 'object' || typeof result === 'function')
|
|
99
|
+
) {
|
|
100
|
+
then = result.then;
|
|
101
|
+
}
|
|
102
|
+
if (typeof then === 'function') {
|
|
103
|
+
asyncRevocationOwner = true;
|
|
104
|
+
return assimilateThenable(result, then, composition.revoke);
|
|
105
|
+
}
|
|
106
|
+
return undefined;
|
|
107
|
+
} finally {
|
|
108
|
+
if (!asyncRevocationOwner) composition.revoke();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async function assimilateThenable(value, then, revoke) {
|
|
113
|
+
try {
|
|
114
|
+
await new Promise((resolve, reject) => {
|
|
115
|
+
then.call(value, resolve, reject);
|
|
116
|
+
});
|
|
117
|
+
return undefined;
|
|
118
|
+
} finally {
|
|
119
|
+
revoke();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function createAdapter({
|
|
124
|
+
repositoryRoot,
|
|
125
|
+
executeMetadataCommand,
|
|
126
|
+
mutateInvocation,
|
|
127
|
+
forbiddenValues,
|
|
128
|
+
}) {
|
|
129
|
+
const canonicalPath = getArgoEnvPath();
|
|
130
|
+
const gitDirectory = path.dirname(canonicalPath);
|
|
131
|
+
const sanitizedEnvironment = Object.freeze(Object.fromEntries(
|
|
132
|
+
['PATH', 'PATHEXT', 'SystemRoot', 'WINDIR']
|
|
133
|
+
.filter(key => typeof process.env[key] === 'string')
|
|
134
|
+
.map(key => [key, process.env[key]]),
|
|
135
|
+
));
|
|
136
|
+
let revoked = false;
|
|
137
|
+
|
|
138
|
+
function invoke(capabilityName, receivedArguments) {
|
|
139
|
+
if (revoked) {
|
|
140
|
+
const error = new Error('TEST_SYSTEM_METADATA_ADAPTER_REVOKED');
|
|
141
|
+
error.category = 'TEST_SYSTEM_METADATA_ADAPTER_REVOKED';
|
|
142
|
+
throw error;
|
|
143
|
+
}
|
|
144
|
+
if (receivedArguments.length !== 0) throw prohibited();
|
|
145
|
+
const expected = buildInvocation(
|
|
146
|
+
capabilityName,
|
|
147
|
+
gitDirectory,
|
|
148
|
+
canonicalPath,
|
|
149
|
+
sanitizedEnvironment,
|
|
150
|
+
);
|
|
151
|
+
const candidate = typeof mutateInvocation === 'function'
|
|
152
|
+
? mutateInvocation(cloneInvocation(expected))
|
|
153
|
+
: expected;
|
|
154
|
+
validateInvocation(candidate, expected, forbiddenValues);
|
|
155
|
+
return executeMetadataCommand(
|
|
156
|
+
candidate.executable,
|
|
157
|
+
[...candidate.args],
|
|
158
|
+
cloneOptions(candidate.options),
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const adapter = Object.create(null);
|
|
163
|
+
for (const capabilityName of CAPABILITY_NAMES) {
|
|
164
|
+
const capability = capabilityName === 'isSecretFileIgnored'
|
|
165
|
+
? (...args) => invoke(capabilityName, args).status === 0
|
|
166
|
+
: capabilityName === 'isSecretFileTracked'
|
|
167
|
+
? (...args) => invoke(capabilityName, args).status === 0
|
|
168
|
+
: (...args) => {
|
|
169
|
+
const result = invoke(capabilityName, args);
|
|
170
|
+
return {
|
|
171
|
+
status: result.status,
|
|
172
|
+
stdout: typeof result.stdout === 'string' ? result.stdout : '',
|
|
173
|
+
};
|
|
174
|
+
};
|
|
175
|
+
Object.freeze(capability);
|
|
176
|
+
Object.defineProperty(adapter, capabilityName, {
|
|
177
|
+
value: capability,
|
|
178
|
+
enumerable: true,
|
|
179
|
+
writable: false,
|
|
180
|
+
configurable: false,
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
Object.freeze(adapter);
|
|
184
|
+
return {
|
|
185
|
+
adapter,
|
|
186
|
+
revoke() {
|
|
187
|
+
revoked = true;
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function buildInvocation(capabilityName, gitDirectory, canonicalPath, environment) {
|
|
193
|
+
const templates = {
|
|
194
|
+
isSecretFileInsideGitRepository: ['git', ['rev-parse', '--is-inside-work-tree']],
|
|
195
|
+
isSecretFileIgnored: ['git', ['check-ignore', '--quiet', '--', '.env']],
|
|
196
|
+
isSecretFileTracked: ['git', ['ls-files', '--error-unmatch', '--', '.env']],
|
|
197
|
+
readCurrentIdentity: ['whoami', []],
|
|
198
|
+
readSecretFileAcl: ['icacls', [canonicalPath]],
|
|
199
|
+
};
|
|
200
|
+
const template = templates[capabilityName];
|
|
201
|
+
if (!template) throw prohibited();
|
|
202
|
+
return {
|
|
203
|
+
executable: template[0],
|
|
204
|
+
args: [...template[1]],
|
|
205
|
+
options: {
|
|
206
|
+
cwd: gitDirectory,
|
|
207
|
+
encoding: 'utf8',
|
|
208
|
+
env: { ...environment },
|
|
209
|
+
shell: false,
|
|
210
|
+
windowsHide: true,
|
|
211
|
+
},
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function validateInvocation(candidate, expected, forbiddenValues) {
|
|
216
|
+
if (!candidate || typeof candidate !== 'object') throw prohibited();
|
|
217
|
+
if (JSON.stringify(candidate) !== JSON.stringify(expected)) throw prohibited();
|
|
218
|
+
const serialized = JSON.stringify(candidate);
|
|
219
|
+
for (const forbiddenValue of forbiddenValues) {
|
|
220
|
+
if (typeof forbiddenValue === 'string' && forbiddenValue && serialized.includes(forbiddenValue)) {
|
|
221
|
+
throw prohibited();
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function cloneInvocation(invocation) {
|
|
227
|
+
return {
|
|
228
|
+
executable: invocation.executable,
|
|
229
|
+
args: [...invocation.args],
|
|
230
|
+
options: cloneOptions(invocation.options),
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function cloneOptions(options) {
|
|
235
|
+
return {
|
|
236
|
+
cwd: options.cwd,
|
|
237
|
+
encoding: options.encoding,
|
|
238
|
+
env: { ...options.env },
|
|
239
|
+
shell: options.shell,
|
|
240
|
+
windowsHide: options.windowsHide,
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function requireExactKeys(value, allowedKeys, optional = false) {
|
|
245
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) throw prohibited();
|
|
246
|
+
const actual = Object.keys(value).sort();
|
|
247
|
+
const allowed = [...allowedKeys].sort();
|
|
248
|
+
if (actual.some(key => !allowed.includes(key))) throw prohibited();
|
|
249
|
+
if (!optional && (actual.length !== allowed.length || actual.some((key, index) => key !== allowed[index]))) {
|
|
250
|
+
throw prohibited();
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function requireRepositoryRoot(value) {
|
|
255
|
+
if (typeof value !== 'string' || value.trim() === '') throw prohibited();
|
|
256
|
+
return path.resolve(value);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function prohibited() {
|
|
260
|
+
const error = new Error('SYSTEM_METADATA_COMMAND_PROHIBITED');
|
|
261
|
+
error.category = 'SYSTEM_METADATA_COMMAND_PROHIBITED';
|
|
262
|
+
return error;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
module.exports = {
|
|
266
|
+
createReadinessAttestationMetadataAdapter,
|
|
267
|
+
createSystemMetadataCommandAdapter,
|
|
268
|
+
withSystemMetadataCommandTestComposition,
|
|
269
|
+
};
|