@unrdf/kgc-probe 26.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +414 -0
- package/package.json +81 -0
- package/src/agents/index.mjs +1402 -0
- package/src/artifact.mjs +405 -0
- package/src/cli.mjs +932 -0
- package/src/config.mjs +115 -0
- package/src/guards.mjs +1213 -0
- package/src/index.mjs +347 -0
- package/src/merge.mjs +196 -0
- package/src/observation.mjs +193 -0
- package/src/orchestrator.mjs +315 -0
- package/src/probe.mjs +58 -0
- package/src/probes/CONCURRENCY-PROBE.md +256 -0
- package/src/probes/README.md +275 -0
- package/src/probes/concurrency.mjs +1175 -0
- package/src/probes/filesystem.mjs +731 -0
- package/src/probes/filesystem.test.mjs +244 -0
- package/src/probes/network.mjs +503 -0
- package/src/probes/performance.mjs +816 -0
- package/src/probes/persistence.mjs +785 -0
- package/src/probes/runtime.mjs +589 -0
- package/src/probes/tooling.mjs +454 -0
- package/src/probes/tooling.test.mjs +372 -0
- package/src/probes/verify-execution.mjs +131 -0
- package/src/probes/verify-guards.mjs +73 -0
- package/src/probes/wasm.mjs +715 -0
- package/src/receipt.mjs +197 -0
- package/src/receipts/index.mjs +813 -0
- package/src/reporter.example.mjs +223 -0
- package/src/reporter.mjs +555 -0
- package/src/reporters/markdown.mjs +355 -0
- package/src/reporters/rdf.mjs +383 -0
- package/src/storage/index.mjs +827 -0
- package/src/types.mjs +1028 -0
- package/src/utils/errors.mjs +397 -0
- package/src/utils/index.mjs +32 -0
- package/src/utils/logger.mjs +236 -0
- package/src/vocabulary.ttl +169 -0
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* KGC Probe Reporter - Usage Example
|
|
3
|
+
*
|
|
4
|
+
* This example demonstrates how to use the reporter module to:
|
|
5
|
+
* 1. Convert observations to RDF/Turtle format
|
|
6
|
+
* 2. Derive high-level capabilities and constraints
|
|
7
|
+
* 3. Generate human-readable Markdown reports
|
|
8
|
+
*
|
|
9
|
+
* NOTE: Run after installing dependencies:
|
|
10
|
+
* pnpm install --filter @unrdf/kgc-probe
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// ===== Example 1: Basic Usage =====
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
observationsToRdf,
|
|
17
|
+
generateReport,
|
|
18
|
+
deriveClaims,
|
|
19
|
+
} from './reporter.mjs';
|
|
20
|
+
|
|
21
|
+
// Sample observations from probes
|
|
22
|
+
const observations = [
|
|
23
|
+
{
|
|
24
|
+
method: 'probeRuntime',
|
|
25
|
+
domain: 'runtime',
|
|
26
|
+
timestamp: Date.now(),
|
|
27
|
+
outputs: {
|
|
28
|
+
node: process.version,
|
|
29
|
+
v8: process.versions.v8,
|
|
30
|
+
worker_threads: true,
|
|
31
|
+
platform: process.platform,
|
|
32
|
+
arch: process.arch,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
method: 'probeWasm',
|
|
37
|
+
domain: 'wasm',
|
|
38
|
+
timestamp: Date.now() + 100,
|
|
39
|
+
outputs: {
|
|
40
|
+
available: typeof WebAssembly !== 'undefined',
|
|
41
|
+
maxMemory: '2GB',
|
|
42
|
+
compileTime: 2.5,
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
method: 'probeFilesystem',
|
|
47
|
+
domain: 'filesystem',
|
|
48
|
+
timestamp: Date.now() + 200,
|
|
49
|
+
outputs: {
|
|
50
|
+
allowedPaths: ['/tmp', '/workspace', process.cwd()],
|
|
51
|
+
canWrite: true,
|
|
52
|
+
canRead: true,
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
method: 'probeFilesystemSensitive',
|
|
57
|
+
domain: 'filesystem',
|
|
58
|
+
timestamp: Date.now() + 300,
|
|
59
|
+
guardDecision: 'denied',
|
|
60
|
+
error: 'Access to /etc denied by filesystem guard',
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
method: 'probeNetwork',
|
|
64
|
+
domain: 'network',
|
|
65
|
+
timestamp: Date.now() + 400,
|
|
66
|
+
outputs: {
|
|
67
|
+
allowedUrls: [
|
|
68
|
+
'https://api.unrdf.dev',
|
|
69
|
+
'https://data.example.org',
|
|
70
|
+
],
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
method: 'probeNetworkExternal',
|
|
75
|
+
domain: 'network',
|
|
76
|
+
timestamp: Date.now() + 500,
|
|
77
|
+
guardDecision: 'denied',
|
|
78
|
+
error: 'Network request blocked: URL not in allowlist',
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
method: 'probeBenchmarkQuad',
|
|
82
|
+
domain: 'performance',
|
|
83
|
+
timestamp: Date.now() + 600,
|
|
84
|
+
outputs: {
|
|
85
|
+
operation: 'quad insertion',
|
|
86
|
+
executionTime: 15.3,
|
|
87
|
+
iterations: 10000,
|
|
88
|
+
opsPerSec: 653.59,
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
method: 'probeBenchmarkQuery',
|
|
93
|
+
domain: 'performance',
|
|
94
|
+
timestamp: Date.now() + 700,
|
|
95
|
+
outputs: {
|
|
96
|
+
operation: 'SPARQL query',
|
|
97
|
+
executionTime: 42.1,
|
|
98
|
+
iterations: 1000,
|
|
99
|
+
opsPerSec: 23.75,
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
];
|
|
103
|
+
|
|
104
|
+
// ===== Example 2: Convert to RDF/Turtle =====
|
|
105
|
+
|
|
106
|
+
console.log('='.repeat(70));
|
|
107
|
+
console.log('RDF/Turtle Serialization');
|
|
108
|
+
console.log('='.repeat(70));
|
|
109
|
+
|
|
110
|
+
const turtle = observationsToRdf(observations);
|
|
111
|
+
console.log(turtle);
|
|
112
|
+
console.log('\n');
|
|
113
|
+
|
|
114
|
+
// ===== Example 3: Derive Claims =====
|
|
115
|
+
|
|
116
|
+
console.log('='.repeat(70));
|
|
117
|
+
console.log('Derived Claims');
|
|
118
|
+
console.log('='.repeat(70));
|
|
119
|
+
|
|
120
|
+
const { capabilities, constraints } = deriveClaims(observations);
|
|
121
|
+
|
|
122
|
+
console.log('\nCAPABILITIES:');
|
|
123
|
+
capabilities.forEach((cap, i) => {
|
|
124
|
+
console.log(`\n${i + 1}. ${cap.title}`);
|
|
125
|
+
console.log(` ${cap.description}`);
|
|
126
|
+
console.log(` Evidence: ${cap.evidence.join(', ')}`);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
console.log('\nCONSTRAINTS:');
|
|
130
|
+
constraints.forEach((cons, i) => {
|
|
131
|
+
console.log(`\n${i + 1}. ${cons.title}`);
|
|
132
|
+
console.log(` ${cons.description}`);
|
|
133
|
+
console.log(` Evidence: ${cons.evidence.join(', ')}`);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
console.log('\n');
|
|
137
|
+
|
|
138
|
+
// ===== Example 4: Generate Markdown Report =====
|
|
139
|
+
|
|
140
|
+
console.log('='.repeat(70));
|
|
141
|
+
console.log('Markdown Report');
|
|
142
|
+
console.log('='.repeat(70));
|
|
143
|
+
|
|
144
|
+
const report = generateReport(observations);
|
|
145
|
+
console.log(report);
|
|
146
|
+
|
|
147
|
+
// ===== Example 5: Save to Files =====
|
|
148
|
+
|
|
149
|
+
import fs from 'fs/promises';
|
|
150
|
+
import path from 'path';
|
|
151
|
+
|
|
152
|
+
const outputDir = './output';
|
|
153
|
+
|
|
154
|
+
try {
|
|
155
|
+
await fs.mkdir(outputDir, { recursive: true });
|
|
156
|
+
|
|
157
|
+
// Save RDF
|
|
158
|
+
await fs.writeFile(
|
|
159
|
+
path.join(outputDir, 'observations.ttl'),
|
|
160
|
+
turtle,
|
|
161
|
+
'utf-8'
|
|
162
|
+
);
|
|
163
|
+
console.log(`\n✅ RDF saved to ${path.join(outputDir, 'observations.ttl')}`);
|
|
164
|
+
|
|
165
|
+
// Save claims as JSON
|
|
166
|
+
await fs.writeFile(
|
|
167
|
+
path.join(outputDir, 'claims.json'),
|
|
168
|
+
JSON.stringify({ capabilities, constraints }, null, 2),
|
|
169
|
+
'utf-8'
|
|
170
|
+
);
|
|
171
|
+
console.log(`✅ Claims saved to ${path.join(outputDir, 'claims.json')}`);
|
|
172
|
+
|
|
173
|
+
// Save report
|
|
174
|
+
await fs.writeFile(
|
|
175
|
+
path.join(outputDir, 'report.md'),
|
|
176
|
+
report,
|
|
177
|
+
'utf-8'
|
|
178
|
+
);
|
|
179
|
+
console.log(`✅ Report saved to ${path.join(outputDir, 'report.md')}\n`);
|
|
180
|
+
} catch (error) {
|
|
181
|
+
console.error('Error saving files:', error.message);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// ===== Example 6: Validate Observations =====
|
|
185
|
+
|
|
186
|
+
import { ObservationSchema } from './reporter.mjs';
|
|
187
|
+
|
|
188
|
+
console.log('='.repeat(70));
|
|
189
|
+
console.log('Observation Validation');
|
|
190
|
+
console.log('='.repeat(70));
|
|
191
|
+
|
|
192
|
+
try {
|
|
193
|
+
observations.forEach((obs, i) => {
|
|
194
|
+
ObservationSchema.parse(obs);
|
|
195
|
+
console.log(`✅ Observation ${i + 1} (${obs.method}) is valid`);
|
|
196
|
+
});
|
|
197
|
+
console.log('\nAll observations validated successfully!\n');
|
|
198
|
+
} catch (error) {
|
|
199
|
+
console.error('❌ Validation failed:', error.message);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// ===== Example 7: Custom Observation =====
|
|
203
|
+
|
|
204
|
+
console.log('='.repeat(70));
|
|
205
|
+
console.log('Custom Observation Example');
|
|
206
|
+
console.log('='.repeat(70));
|
|
207
|
+
|
|
208
|
+
const customObs = [
|
|
209
|
+
{
|
|
210
|
+
method: 'probeCustomResource',
|
|
211
|
+
domain: 'custom',
|
|
212
|
+
timestamp: Date.now(),
|
|
213
|
+
outputs: {
|
|
214
|
+
resourceType: 'GPU',
|
|
215
|
+
available: false,
|
|
216
|
+
reason: 'Not supported in environment',
|
|
217
|
+
},
|
|
218
|
+
guardDecision: 'allowed',
|
|
219
|
+
},
|
|
220
|
+
];
|
|
221
|
+
|
|
222
|
+
const customReport = generateReport(customObs);
|
|
223
|
+
console.log(customReport);
|