raiton 6.10.0-beta.28 → 6.11.0-beta.29
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/CHANGELOG.md +23 -0
- package/README.md +19 -0
- package/benchmarks/README.md +15 -0
- package/benchmarks/ai-debug.json +145 -0
- package/benchmarks/ai-debug.md +64 -0
- package/benchmarks/latest.json +71 -71
- package/benchmarks/latest.md +25 -25
- package/build/bin/index.mjs +6028 -2098
- package/build/types/commands/call.command.d.ts +10 -0
- package/build/types/commands/debug.shared.d.ts +16 -0
- package/build/types/commands/explain.command.d.ts +8 -0
- package/build/types/commands/mcp.command.d.ts +1 -0
- package/build/types/commands/requests.command.d.ts +8 -0
- package/build/types/commands/verify.command.d.ts +8 -0
- package/build/types/contracts/decorators.d.ts +18 -0
- package/build/types/contracts/errors.d.ts +29 -3
- package/build/types/contracts/schema.d.ts +13 -0
- package/build/types/core/application.d.ts +8 -0
- package/build/types/debug/cli.d.ts +33 -0
- package/build/types/debug/collector.d.ts +41 -0
- package/build/types/debug/collector.internal.d.ts +27 -0
- package/build/types/debug/config.d.ts +19 -0
- package/build/types/debug/examples.d.ts +43 -0
- package/build/types/debug/explain.d.ts +9 -0
- package/build/types/debug/index.d.ts +15 -0
- package/build/types/debug/invocation.d.ts +53 -0
- package/build/types/debug/journal.d.ts +49 -0
- package/build/types/debug/mcp-http.d.ts +17 -0
- package/build/types/debug/mcp.d.ts +14 -0
- package/build/types/debug/redaction.d.ts +48 -0
- package/build/types/debug/requests.d.ts +37 -0
- package/build/types/debug/runtime.d.ts +52 -0
- package/build/types/debug/session.d.ts +21 -0
- package/build/types/debug/source.d.ts +17 -0
- package/build/types/debug/surface.d.ts +10 -0
- package/build/types/debug/types.d.ts +271 -0
- package/build/types/debug/verify.d.ts +23 -0
- package/build/types/framework/errors/catalog.d.ts +16 -1
- package/build/types/manifest/schema.d.ts +64 -0
- package/build/types/types/config.d.ts +50 -0
- package/docs/AGENTS.md +1 -1
- package/docs/CLAUDE.md +1 -1
- package/docs/generated/cli/commands.md +5 -0
- package/docs/generated/config-schema.json +93 -0
- package/docs/generated/manifest-schema.json +76 -0
- package/docs/generated/manifest.json +20 -3
- package/docs/llms-full.txt +183 -4
- package/docs/llms.txt +6 -1
- package/docs/user-guide/README.md +1 -0
- package/docs/user-guide/cli.md +5 -0
- package/docs/user-guide/config.md +18 -0
- package/docs/user-guide/debug.md +130 -0
- package/package.json +3 -1
- package/scripts/bench-ai-debug.ts +572 -0
- package/source/bin/commands.registry.ts +8 -0
- package/source/commands/call.command.ts +247 -0
- package/source/commands/debug.shared.ts +90 -0
- package/source/commands/docs.command.ts +6 -0
- package/source/commands/explain.command.ts +119 -0
- package/source/commands/mcp.command.ts +64 -0
- package/source/commands/requests.command.ts +137 -0
- package/source/commands/verify.command.ts +173 -0
- package/source/contracts/decorators.ts +67 -2
- package/source/contracts/errors.ts +64 -5
- package/source/contracts/schema.ts +61 -0
- package/source/core/application.ts +120 -12
- package/source/core/builder.ts +4 -0
- package/source/core/config/config.ts +11 -0
- package/source/core/config/schema.ts +143 -0
- package/source/core/router/handler.ts +162 -13
- package/source/debug/cli.ts +206 -0
- package/source/debug/collector.internal.ts +27 -0
- package/source/debug/collector.ts +294 -0
- package/source/debug/config.ts +142 -0
- package/source/debug/examples.ts +188 -0
- package/source/debug/explain.ts +187 -0
- package/source/debug/index.ts +15 -0
- package/source/debug/invocation.ts +695 -0
- package/source/debug/journal.ts +249 -0
- package/source/debug/mcp-http.ts +145 -0
- package/source/debug/mcp.ts +410 -0
- package/source/debug/redaction.ts +225 -0
- package/source/debug/requests.ts +136 -0
- package/source/debug/runtime.ts +181 -0
- package/source/debug/session.ts +107 -0
- package/source/debug/source.ts +95 -0
- package/source/debug/surface.ts +375 -0
- package/source/debug/types.ts +311 -0
- package/source/debug/verify.ts +186 -0
- package/source/framework/errors/catalog.ts +57 -11
- package/source/framework/mcp/handler.ts +9 -1
- package/source/framework/utilities/openapi.utils.impl.ts +28 -0
- package/source/manifest/introspect.ts +5 -0
- package/source/manifest/manifest.ts +24 -1
- package/source/manifest/schema.ts +52 -1
- package/source/types/config.ts +56 -0
|
@@ -0,0 +1,572 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
/**
|
|
3
|
+
* Benchmarks de la spec 003 — debug runtime assisté par IA.
|
|
4
|
+
*
|
|
5
|
+
* Le harnais mesure deux choses :
|
|
6
|
+
* 1. le coût d'un journal de requêtes en mémoire (prototype de référence) ;
|
|
7
|
+
* 2. l'économie de tokens des artefacts produits par les futures commandes
|
|
8
|
+
* (`call`, `explain`, `verify`) par rapport à un parcours manuel.
|
|
9
|
+
*
|
|
10
|
+
* Les mesures de performance sont réelles. Les économies de tokens sont des
|
|
11
|
+
* projections explicitement marquées « Estimé » : elles comparent des tailles
|
|
12
|
+
* d'artefacts mesurées à des sorties de référence représentatives.
|
|
13
|
+
*
|
|
14
|
+
* Exemples :
|
|
15
|
+
* bun run bench:ai
|
|
16
|
+
* bun run bench:ai --check
|
|
17
|
+
* bun run bench:ai --json --no-write
|
|
18
|
+
*/
|
|
19
|
+
import fs from "node:fs";
|
|
20
|
+
import os from "node:os";
|
|
21
|
+
import path from "node:path";
|
|
22
|
+
import {spawnSync} from "node:child_process";
|
|
23
|
+
import {encode} from "gpt-tokenizer";
|
|
24
|
+
import {DebugJournal} from "../source/debug/journal.ts";
|
|
25
|
+
import type {DebugJournalEntry} from "../source/debug/types.ts";
|
|
26
|
+
|
|
27
|
+
const REPO = path.resolve(import.meta.dir, "..");
|
|
28
|
+
const FIXTURE = path.join(REPO, "tests/fixtures/project");
|
|
29
|
+
const CAPACITY = 1_000;
|
|
30
|
+
const WRITE_ITERATIONS = 200_000;
|
|
31
|
+
const LOOKUP_ITERATIONS = 50_000;
|
|
32
|
+
const SERIALIZE_ITERATIONS = 20_000;
|
|
33
|
+
|
|
34
|
+
interface Percentiles {
|
|
35
|
+
p50: number;
|
|
36
|
+
p90: number;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
interface JournalRecord {
|
|
40
|
+
requestId: string;
|
|
41
|
+
method: string;
|
|
42
|
+
route: string;
|
|
43
|
+
status: number;
|
|
44
|
+
durationMs: number;
|
|
45
|
+
body: unknown;
|
|
46
|
+
headers: Record<string, string>;
|
|
47
|
+
issues: Array<{path: string; code: string; message: string}>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function percentile(samples: number[], p: number): number {
|
|
51
|
+
const sorted = [...samples].sort((a, b) => a - b);
|
|
52
|
+
return sorted[Math.min(sorted.length - 1, Math.floor(sorted.length * p))];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function summarize(samples: number[]): Percentiles {
|
|
56
|
+
return {p50: percentile(samples, 0.5), p90: percentile(samples, 0.9)};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function tokens(text: string): number {
|
|
60
|
+
return encode(text).length;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function referenceRecord(index: number): JournalRecord {
|
|
64
|
+
return {
|
|
65
|
+
requestId: `req-${index.toString(16).padStart(12, "0")}`,
|
|
66
|
+
method: "POST",
|
|
67
|
+
route: "/api/users/:id",
|
|
68
|
+
status: 400,
|
|
69
|
+
durationMs: 3.21,
|
|
70
|
+
body: {email: "ada@example.com", name: "Ada Lovelace", nested: {a: 1, b: [1, 2, 3]}},
|
|
71
|
+
headers: {"content-type": "application/json", "user-agent": "bench"},
|
|
72
|
+
issues: [{path: "/email", code: "format", message: "must be an email"}],
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Prototype de référence : ring buffer borné, index par requestId et
|
|
78
|
+
* sérialisation différée. Il ne s'agit pas de l'implémentation finale ; le
|
|
79
|
+
* harnais vérifie que l'approche tient dans le budget avant intégration.
|
|
80
|
+
*/
|
|
81
|
+
function journalPrototype() {
|
|
82
|
+
const ring: Array<JournalRecord | undefined> = new Array(CAPACITY);
|
|
83
|
+
let head = 0;
|
|
84
|
+
|
|
85
|
+
for (let index = 0; index < 10_000; index++) {
|
|
86
|
+
ring[head] = referenceRecord(index);
|
|
87
|
+
head = (head + 1) % CAPACITY;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const writeSamples: number[] = [];
|
|
91
|
+
for (let index = 0; index < WRITE_ITERATIONS; index++) {
|
|
92
|
+
const record = referenceRecord(index);
|
|
93
|
+
const started = performance.now();
|
|
94
|
+
ring[head] = record;
|
|
95
|
+
head = (head + 1) % CAPACITY;
|
|
96
|
+
writeSamples.push((performance.now() - started) * 1000);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
for (let index = 0; index < CAPACITY; index++) ring[index] = referenceRecord(index);
|
|
100
|
+
const target = ring[777]!;
|
|
101
|
+
|
|
102
|
+
const linearSamples: number[] = [];
|
|
103
|
+
for (let index = 0; index < LOOKUP_ITERATIONS; index++) {
|
|
104
|
+
const started = performance.now();
|
|
105
|
+
for (const record of ring) {
|
|
106
|
+
if (record?.requestId === target.requestId) break;
|
|
107
|
+
}
|
|
108
|
+
linearSamples.push((performance.now() - started) * 1000);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const index_ = new Map(ring.map(record => [record!.requestId, record!]));
|
|
112
|
+
const mapSamples: number[] = [];
|
|
113
|
+
for (let index = 0; index < LOOKUP_ITERATIONS; index++) {
|
|
114
|
+
const started = performance.now();
|
|
115
|
+
index_.get(target.requestId);
|
|
116
|
+
mapSamples.push((performance.now() - started) * 1000);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const serializeSamples: number[] = [];
|
|
120
|
+
for (let index = 0; index < SERIALIZE_ITERATIONS; index++) {
|
|
121
|
+
const started = performance.now();
|
|
122
|
+
JSON.stringify(target);
|
|
123
|
+
serializeSamples.push((performance.now() - started) * 1000);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
capacity: CAPACITY,
|
|
128
|
+
recordBytes: new TextEncoder().encode(JSON.stringify(target)).byteLength,
|
|
129
|
+
write: summarize(writeSamples),
|
|
130
|
+
linearLookup: summarize(linearSamples),
|
|
131
|
+
mapLookup: summarize(mapSamples),
|
|
132
|
+
serialize: summarize(serializeSamples),
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function realJournal(full = true) {
|
|
137
|
+
const journal = new DebugJournal({capacity: CAPACITY, ttlMs: 900_000, maxTotalBytes: 8 * 1024 * 1024});
|
|
138
|
+
const startedAt = new Date().toISOString();
|
|
139
|
+
const record = (index: number): DebugJournalEntry => ({
|
|
140
|
+
schemaVersion: "1.0.0",
|
|
141
|
+
requestId: `req-${index.toString(16).padStart(12, "0")}`,
|
|
142
|
+
traceId: "4bf92f3577b34da6a3ce929d0e0e4736",
|
|
143
|
+
startedAt,
|
|
144
|
+
request: {
|
|
145
|
+
method: "POST",
|
|
146
|
+
route: "/api/users/:id",
|
|
147
|
+
pattern: "/users/:id",
|
|
148
|
+
path: "/api/users/42",
|
|
149
|
+
...(full ? {
|
|
150
|
+
query: {expand: "team"},
|
|
151
|
+
headers: {"content-type": "application/json", authorization: "***"},
|
|
152
|
+
body: {email: "ada@example.com", name: "Ada Lovelace"},
|
|
153
|
+
} : {}),
|
|
154
|
+
},
|
|
155
|
+
response: {
|
|
156
|
+
status: 400,
|
|
157
|
+
durationMs: 3.21,
|
|
158
|
+
...(full ? {body: {error: true, code: "VALIDATION_ERROR"}} : {}),
|
|
159
|
+
},
|
|
160
|
+
source: {
|
|
161
|
+
file: "source/controllers/users.controller.ts",
|
|
162
|
+
line: 24,
|
|
163
|
+
controller: "UsersController",
|
|
164
|
+
handler: "create",
|
|
165
|
+
decorator: '@Post("/")',
|
|
166
|
+
},
|
|
167
|
+
timeline: [
|
|
168
|
+
{step: "middleware", durationMs: 0.08, result: "ok"},
|
|
169
|
+
{step: "validation:input", durationMs: 0.31, result: "rejected"},
|
|
170
|
+
{step: "handler", result: "not-executed"},
|
|
171
|
+
],
|
|
172
|
+
validation: {
|
|
173
|
+
ok: false,
|
|
174
|
+
issues: [{path: "/email", code: "invalid_format", expected: "format:email", received: "ada@", message: "must be an email"}],
|
|
175
|
+
},
|
|
176
|
+
error: {code: "VALIDATION_ERROR", message: "Invalid request"},
|
|
177
|
+
release: {hmr: false, buildId: "bench"},
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
for (let index = 0; index < CAPACITY; index++) journal.push(record(index), full ? undefined : 512);
|
|
181
|
+
|
|
182
|
+
const writeSamples: number[] = [];
|
|
183
|
+
for (let index = 0; index < WRITE_ITERATIONS; index++) {
|
|
184
|
+
const record_ = record(index);
|
|
185
|
+
const started = performance.now();
|
|
186
|
+
journal.push(record_, full ? undefined : 512);
|
|
187
|
+
writeSamples.push((performance.now() - started) * 1000);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const targetEntry = record(999_999);
|
|
191
|
+
journal.push(targetEntry, full ? undefined : 512);
|
|
192
|
+
const target = targetEntry.requestId;
|
|
193
|
+
const mapSamples: number[] = [];
|
|
194
|
+
for (let index = 0; index < LOOKUP_ITERATIONS; index++) {
|
|
195
|
+
const started = performance.now();
|
|
196
|
+
journal.get(target);
|
|
197
|
+
mapSamples.push((performance.now() - started) * 1000);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const entry = journal.last()!;
|
|
201
|
+
const serializeSamples: number[] = [];
|
|
202
|
+
for (let index = 0; index < SERIALIZE_ITERATIONS; index++) {
|
|
203
|
+
const started = performance.now();
|
|
204
|
+
JSON.stringify(entry);
|
|
205
|
+
serializeSamples.push((performance.now() - started) * 1000);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return {
|
|
209
|
+
capacity: journal.capacity,
|
|
210
|
+
size: journal.size,
|
|
211
|
+
totalBytes: journal.totalBytes,
|
|
212
|
+
recordBytes: new TextEncoder().encode(JSON.stringify(entry)).byteLength,
|
|
213
|
+
write: summarize(writeSamples),
|
|
214
|
+
mapLookup: summarize(mapSamples),
|
|
215
|
+
serialize: summarize(serializeSamples),
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function runCli(args: string[], cwd: string): {ok: boolean; stdout: string; stderr: string} {
|
|
220
|
+
const result = spawnSync("bun", [path.join(REPO, "source/bin/index.ts"), ...args], {
|
|
221
|
+
cwd,
|
|
222
|
+
encoding: "utf-8",
|
|
223
|
+
timeout: 120_000,
|
|
224
|
+
});
|
|
225
|
+
return {ok: result.status === 0, stdout: result.stdout ?? "", stderr: result.stderr ?? ""};
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function fileTokens(relative: string): {file: string; bytes: number; tokens: number} {
|
|
229
|
+
const absolute = path.join(REPO, relative);
|
|
230
|
+
const text = fs.readFileSync(absolute, "utf-8");
|
|
231
|
+
return {file: relative, bytes: Buffer.byteLength(text), tokens: tokens(text)};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function artifactTokens() {
|
|
235
|
+
const staticFiles = [
|
|
236
|
+
fileTokens("docs/llms.txt"),
|
|
237
|
+
fileTokens("docs/AGENTS.md"),
|
|
238
|
+
fileTokens("README.md"),
|
|
239
|
+
fileTokens("tests/fixtures/project/source/controllers/items.controller.ts"),
|
|
240
|
+
];
|
|
241
|
+
|
|
242
|
+
const manifest = runCli(["inspect", "--json"], FIXTURE);
|
|
243
|
+
const routes = runCli(["routes", "--json"], FIXTURE);
|
|
244
|
+
|
|
245
|
+
const directory = fs.mkdtempSync(path.join(os.tmpdir(), "raiton-bench-ai-"));
|
|
246
|
+
const openapiFile = path.join(directory, "openapi.json");
|
|
247
|
+
const openapi = runCli(["openapi", "export", "--out", openapiFile, "--force"], FIXTURE);
|
|
248
|
+
const openapiTokens = openapi.ok && fs.existsSync(openapiFile)
|
|
249
|
+
? tokens(fs.readFileSync(openapiFile, "utf-8"))
|
|
250
|
+
: 0;
|
|
251
|
+
fs.rmSync(directory, {recursive: true, force: true});
|
|
252
|
+
|
|
253
|
+
const samples = {
|
|
254
|
+
explain: tokens(SAMPLE_EXPLAIN),
|
|
255
|
+
call: tokens(SAMPLE_CALL),
|
|
256
|
+
verify: tokens(SAMPLE_VERIFY),
|
|
257
|
+
baselineLog: tokens(SAMPLE_BASELINE_LOG),
|
|
258
|
+
curlResponse: tokens(SAMPLE_CURL_RESPONSE),
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
return {
|
|
262
|
+
files: staticFiles,
|
|
263
|
+
project: {
|
|
264
|
+
manifest: manifest.ok ? tokens(manifest.stdout) : 0,
|
|
265
|
+
routes: routes.ok ? tokens(routes.stdout) : 0,
|
|
266
|
+
openapi: openapiTokens,
|
|
267
|
+
},
|
|
268
|
+
samples,
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Scénarios de comparaison. Les valeurs de base sont des tailles d'artefacts
|
|
274
|
+
* mesurées ; les sorties « avec feature » sont les échantillons ci-dessous.
|
|
275
|
+
* Les hypothèses sont volontairement conservatrices : on ne compte pas les
|
|
276
|
+
* gains de tours, de commandes ni de contexte système.
|
|
277
|
+
*/
|
|
278
|
+
function tokenProjections(artifacts: ReturnType<typeof artifactTokens>) {
|
|
279
|
+
const tokens_ = artifacts.samples;
|
|
280
|
+
const project = artifacts.project;
|
|
281
|
+
// Contexte minimal déjà chargé par un agent au début d'une session.
|
|
282
|
+
const fixedContext = artifacts.files[1].tokens;
|
|
283
|
+
|
|
284
|
+
const scenarios = [
|
|
285
|
+
{
|
|
286
|
+
name: "Diagnostiquer un 400 de validation",
|
|
287
|
+
baseline: artifacts.files[3].tokens + tokens_.baselineLog + project.routes,
|
|
288
|
+
feature: tokens_.explain,
|
|
289
|
+
assumptions: "Contrôleur (174) + extrait de logs (299) + routes (486) contre une explication structurée (408).",
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
name: "Invoquer une route inconnue",
|
|
293
|
+
baseline: artifacts.files[3].tokens + project.routes + tokens_.curlResponse,
|
|
294
|
+
feature: tokens_.call,
|
|
295
|
+
assumptions: "Contrôleur (174) + routes (486) + réponse curl (73) contre une invocation structurée (227).",
|
|
296
|
+
},
|
|
297
|
+
{
|
|
298
|
+
name: "Invoquer une route connue (contexte chaud)",
|
|
299
|
+
baseline: artifacts.files[3].tokens + tokens_.curlResponse,
|
|
300
|
+
feature: tokens_.call,
|
|
301
|
+
assumptions: "Contrôleur (174) + réponse curl (73) contre une invocation structurée (227) : borne basse réaliste.",
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
name: "Vérifier les contrats après modification",
|
|
305
|
+
baseline: project.openapi + artifacts.files[3].tokens,
|
|
306
|
+
feature: tokens_.verify,
|
|
307
|
+
assumptions: "OpenAPI (938) + contrôleur (174) contre un rapport de vérification compact (138).",
|
|
308
|
+
},
|
|
309
|
+
].map(scenario => {
|
|
310
|
+
const incremental = scenario.baseline > 0 ? (scenario.baseline - scenario.feature) / scenario.baseline : 0;
|
|
311
|
+
const fresh = (scenario.baseline + fixedContext) > 0
|
|
312
|
+
? (scenario.baseline - scenario.feature) / (scenario.baseline + fixedContext)
|
|
313
|
+
: 0;
|
|
314
|
+
return {...scenario, incremental, fresh};
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
return {
|
|
318
|
+
fixedContext,
|
|
319
|
+
scenarios,
|
|
320
|
+
medianIncremental: percentile(scenarios.map(scenario => scenario.incremental), 0.5),
|
|
321
|
+
medianFresh: percentile(scenarios.map(scenario => scenario.fresh), 0.5),
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
const SAMPLE_EXPLAIN = JSON.stringify({
|
|
326
|
+
schemaVersion: "1.0.0",
|
|
327
|
+
requestId: "req-0000000001a2",
|
|
328
|
+
request: {
|
|
329
|
+
method: "POST",
|
|
330
|
+
route: "/api/users",
|
|
331
|
+
pattern: "/users",
|
|
332
|
+
status: 400,
|
|
333
|
+
durationMs: 2.41,
|
|
334
|
+
traceId: "4bf92f3577b34da6a3ce929d0e0e4736",
|
|
335
|
+
},
|
|
336
|
+
source: {
|
|
337
|
+
file: "source/controllers/users.controller.ts",
|
|
338
|
+
line: 24,
|
|
339
|
+
controller: "UsersController",
|
|
340
|
+
handler: "create",
|
|
341
|
+
decorator: "@Post(\"/\")",
|
|
342
|
+
},
|
|
343
|
+
timeline: [
|
|
344
|
+
{step: "middleware:cors", durationMs: 0.08},
|
|
345
|
+
{step: "middleware:auth", durationMs: 0.22, result: "ok"},
|
|
346
|
+
{step: "validation:input", durationMs: 0.31, result: "rejected"},
|
|
347
|
+
{step: "handler", result: "not-executed"},
|
|
348
|
+
],
|
|
349
|
+
diagnosis: {
|
|
350
|
+
code: "VALIDATION_ERROR",
|
|
351
|
+
message: "Invalid request",
|
|
352
|
+
issues: [{path: "/email", code: "format", expected: "email", received: "ada@", message: "must be an email"}],
|
|
353
|
+
hint: "The handler was not executed; fix the email field or relax the contract.",
|
|
354
|
+
},
|
|
355
|
+
nextActions: [
|
|
356
|
+
"raiton why POST /api/users",
|
|
357
|
+
"raiton call POST /api/users --data '{\"email\":\"ada@example.com\"}'",
|
|
358
|
+
"raiton inspect --json",
|
|
359
|
+
],
|
|
360
|
+
}, null, 2);
|
|
361
|
+
|
|
362
|
+
const SAMPLE_CALL = JSON.stringify({
|
|
363
|
+
schemaVersion: "1.0.0",
|
|
364
|
+
request: {
|
|
365
|
+
method: "POST",
|
|
366
|
+
path: "/api/users",
|
|
367
|
+
headers: {"content-type": "application/json", authorization: "Bearer ***"},
|
|
368
|
+
body: {email: "ada@example.com", name: "Ada Lovelace"},
|
|
369
|
+
},
|
|
370
|
+
response: {
|
|
371
|
+
status: 201,
|
|
372
|
+
durationMs: 4.12,
|
|
373
|
+
requestId: "req-0000000001ac",
|
|
374
|
+
traceId: "4bf92f3577b34da6a3ce929d0e0e4736",
|
|
375
|
+
body: {id: 42, email: "ada@example.com", name: "Ada Lovelace"},
|
|
376
|
+
},
|
|
377
|
+
contract: {input: "valid", output: "valid"},
|
|
378
|
+
nextActions: ["raiton explain req-0000000001ac"],
|
|
379
|
+
}, null, 2);
|
|
380
|
+
|
|
381
|
+
const SAMPLE_VERIFY = JSON.stringify({
|
|
382
|
+
schemaVersion: "1.0.0",
|
|
383
|
+
summary: {routes: 2, passed: 1, failed: 1, durationMs: 18},
|
|
384
|
+
failures: [{
|
|
385
|
+
method: "POST",
|
|
386
|
+
path: "/api/items",
|
|
387
|
+
code: "OUTPUT_VALIDATION_ERROR",
|
|
388
|
+
issue: "/id expected integer",
|
|
389
|
+
source: "source/controllers/items.controller.ts:24",
|
|
390
|
+
}],
|
|
391
|
+
nextActions: ["raiton call POST /api/items --data '{\"name\":\"Raiton\"}'"],
|
|
392
|
+
}, null, 2);
|
|
393
|
+
|
|
394
|
+
const SAMPLE_BASELINE_LOG = [
|
|
395
|
+
"[2026-11-27T18:05:50.941Z] INFO POST /api/users request_id=req-0000000001a2",
|
|
396
|
+
"[2026-11-27T18:05:50.941Z] INFO POST /api/users/42 request_id=req-0000000001a3",
|
|
397
|
+
"[2026-11-27T18:05:50.942Z] INFO GET /api/users request_id=req-0000000001a4",
|
|
398
|
+
"[2026-11-27T18:05:50.943Z] WARN [contract] POST /users rejected request request_id=req-0000000001a2",
|
|
399
|
+
"[2026-11-27T18:05:50.943Z] ERROR Failed to execute UsersController.create handler request_id=req-0000000001a6",
|
|
400
|
+
"Error: Invalid request",
|
|
401
|
+
" at UsersController.create (/app/source/controllers/users.controller.ts:24:18)",
|
|
402
|
+
" at async createHandler (/app/source/core/router/handler.ts:88:31)",
|
|
403
|
+
" at async Router.resolve (/app/source/core/router/router.ts:64:22)",
|
|
404
|
+
"[2026-11-27T18:05:50.944Z] INFO POST /api/users request_id=req-0000000001a7",
|
|
405
|
+
"[2026-11-27T18:05:50.945Z] WARN [contract] POST /users rejected request request_id=req-0000000001aa",
|
|
406
|
+
].join("\n");
|
|
407
|
+
|
|
408
|
+
const SAMPLE_CURL_RESPONSE = JSON.stringify({
|
|
409
|
+
status: 201,
|
|
410
|
+
headers: {"content-type": "application/json", "x-request-id": "req-0000000001ac"},
|
|
411
|
+
body: {id: 42, email: "ada@example.com", name: "Ada Lovelace"},
|
|
412
|
+
}, null, 2);
|
|
413
|
+
|
|
414
|
+
function formatTable(title: string, rows: string[][], headers: string[]): string {
|
|
415
|
+
return [
|
|
416
|
+
`### ${title}`,
|
|
417
|
+
"",
|
|
418
|
+
`| ${headers.join(" | ")} |`,
|
|
419
|
+
`| ${headers.map(() => "---").join(" | ")} |`,
|
|
420
|
+
...rows.map(row => `| ${row.join(" | ")} |`),
|
|
421
|
+
].join("\n");
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
function main() {
|
|
425
|
+
const journal = journalPrototype();
|
|
426
|
+
const real = realJournal(true);
|
|
427
|
+
const realMetadata = realJournal(false);
|
|
428
|
+
const artifacts = artifactTokens();
|
|
429
|
+
const projections = tokenProjections(artifacts);
|
|
430
|
+
|
|
431
|
+
let referenceHttpP50 = 0;
|
|
432
|
+
const latest = path.join(REPO, "benchmarks/latest.json");
|
|
433
|
+
if (fs.existsSync(latest)) {
|
|
434
|
+
try {
|
|
435
|
+
const report = JSON.parse(fs.readFileSync(latest, "utf-8"));
|
|
436
|
+
referenceHttpP50 = Number(report?.http?.threeHundredLast?.p50 ?? 0);
|
|
437
|
+
} catch {
|
|
438
|
+
referenceHttpP50 = 0;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
const writeOverhead = referenceHttpP50 > 0 ? journal.write.p50 / referenceHttpP50 : 0;
|
|
443
|
+
const fullOverhead = referenceHttpP50 > 0
|
|
444
|
+
? (journal.write.p50 + journal.serialize.p50) / referenceHttpP50
|
|
445
|
+
: 0;
|
|
446
|
+
|
|
447
|
+
const report = {
|
|
448
|
+
generatedAt: new Date().toISOString(),
|
|
449
|
+
environment: {
|
|
450
|
+
runtime: `Bun ${Bun.version}`,
|
|
451
|
+
node: process.version,
|
|
452
|
+
platform: `${process.platform}-${process.arch}`,
|
|
453
|
+
cpus: os.cpus().length,
|
|
454
|
+
},
|
|
455
|
+
journal,
|
|
456
|
+
realJournal: real,
|
|
457
|
+
realMetadataJournal: realMetadata,
|
|
458
|
+
referenceHttpP50,
|
|
459
|
+
overhead: {write: writeOverhead, full: fullOverhead},
|
|
460
|
+
artifacts,
|
|
461
|
+
projections,
|
|
462
|
+
};
|
|
463
|
+
|
|
464
|
+
const markdown = [
|
|
465
|
+
"# Raiton AI debug benchmark",
|
|
466
|
+
"",
|
|
467
|
+
`Généré le ${report.generatedAt} · Bun ${Bun.version} · ${report.environment.platform}`,
|
|
468
|
+
"",
|
|
469
|
+
"Ce rapport couvre la spec 003. Les mesures de performance sont réelles ;",
|
|
470
|
+
"les économies de tokens sont des projections marquées « Estimé ».",
|
|
471
|
+
"",
|
|
472
|
+
formatTable("Journal de requêtes — implémentation réelle (µs / opération)", [
|
|
473
|
+
["Métadonnées — écriture", realMetadata.write.p50.toFixed(3), realMetadata.write.p90.toFixed(3), `${realMetadata.recordBytes} o`],
|
|
474
|
+
["Métadonnées — recherche indexée", realMetadata.mapLookup.p50.toFixed(3), realMetadata.mapLookup.p90.toFixed(3), ""],
|
|
475
|
+
["Complet — écriture", real.write.p50.toFixed(3), real.write.p90.toFixed(3), `${real.recordBytes} o`],
|
|
476
|
+
["Complet — recherche indexée", real.mapLookup.p50.toFixed(3), real.mapLookup.p90.toFixed(3), ""],
|
|
477
|
+
["Sérialisation d'une entrée complète", real.serialize.p50.toFixed(3), real.serialize.p90.toFixed(3), ""],
|
|
478
|
+
["Mémoire (1 000 entrées, complètes)", `${(real.totalBytes / 1024).toFixed(0)} Kio`, "", `≤ 8 Mio`],
|
|
479
|
+
], ["Opération", "p50", "p90", "Taille"]),
|
|
480
|
+
"",
|
|
481
|
+
formatTable("Journal de requêtes — prototype (µs / opération)", [
|
|
482
|
+
["Écriture ring buffer", journal.write.p50.toFixed(3), journal.write.p90.toFixed(3), `${journal.recordBytes} o`],
|
|
483
|
+
["Recherche linéaire (1 000 entrées)", journal.linearLookup.p50.toFixed(3), journal.linearLookup.p90.toFixed(3), ""],
|
|
484
|
+
["Recherche indexée (Map)", journal.mapLookup.p50.toFixed(3), journal.mapLookup.p90.toFixed(3), ""],
|
|
485
|
+
["Sérialisation d'un enregistrement", journal.serialize.p50.toFixed(3), journal.serialize.p90.toFixed(3), ""],
|
|
486
|
+
], ["Opération", "p50", "p90", "Taille"]),
|
|
487
|
+
"",
|
|
488
|
+
referenceHttpP50 > 0
|
|
489
|
+
? `Référence pile HTTP (spec 001) : **${referenceHttpP50.toFixed(3)} µs** p50. ` +
|
|
490
|
+
`Surcoût capture métadonnées : **${(writeOverhead * 100).toFixed(2)} %** ; ` +
|
|
491
|
+
`capture + sérialisation immédiate : **${(fullOverhead * 100).toFixed(2)} %**.`
|
|
492
|
+
: "Référence pile HTTP indisponible : exécuter `bun run bench` d'abord.",
|
|
493
|
+
"",
|
|
494
|
+
formatTable("Artefacts — tokens mesurés (cl100k_base)", [
|
|
495
|
+
...artifacts.files.map(file => [file.file, String(file.bytes), String(file.tokens)]),
|
|
496
|
+
["manifeste du projet fixture", "", String(artifacts.project.manifest)],
|
|
497
|
+
["routes du projet fixture", "", String(artifacts.project.routes)],
|
|
498
|
+
["OpenAPI du projet fixture", "", String(artifacts.project.openapi)],
|
|
499
|
+
["sortie explain (échantillon)", "", String(artifacts.samples.explain)],
|
|
500
|
+
["sortie call (échantillon)", "", String(artifacts.samples.call)],
|
|
501
|
+
["rapport verify (échantillon)", "", String(artifacts.samples.verify)],
|
|
502
|
+
["extrait de logs (échantillon)", "", String(artifacts.samples.baselineLog)],
|
|
503
|
+
["réponse curl (échantillon)", "", String(artifacts.samples.curlResponse)],
|
|
504
|
+
], ["Artefact", "Octets", "Tokens"]),
|
|
505
|
+
"",
|
|
506
|
+
formatTable("Économie de tokens par scénario (Estimé)", [
|
|
507
|
+
...projections.scenarios.map(scenario => [
|
|
508
|
+
scenario.name,
|
|
509
|
+
String(Math.round(scenario.baseline)),
|
|
510
|
+
String(Math.round(scenario.feature)),
|
|
511
|
+
`${(scenario.incremental * 100).toFixed(1)} %`,
|
|
512
|
+
`${(scenario.fresh * 100).toFixed(1)} %`,
|
|
513
|
+
]),
|
|
514
|
+
["Médiane", "", "", `${(projections.medianIncremental * 100).toFixed(1)} %`, `${(projections.medianFresh * 100).toFixed(1)} %`],
|
|
515
|
+
], ["Scénario", "Sans feature", "Avec feature", "Économie incrémentale", "Économie session neuve"]),
|
|
516
|
+
"",
|
|
517
|
+
`Contexte fixe retenu pour la session neuve : **${projections.fixedContext} tokens** (AGENTS.md seul).`,
|
|
518
|
+
"",
|
|
519
|
+
"Hypothèses :",
|
|
520
|
+
...projections.scenarios.map(scenario => `- **${scenario.name}** : ${scenario.assumptions}`),
|
|
521
|
+
"",
|
|
522
|
+
].join("\n");
|
|
523
|
+
|
|
524
|
+
console.log(markdown);
|
|
525
|
+
|
|
526
|
+
const outDir = process.argv.includes("--out")
|
|
527
|
+
? path.resolve(process.argv[process.argv.indexOf("--out") + 1])
|
|
528
|
+
: path.join(REPO, "benchmarks");
|
|
529
|
+
if (!process.argv.includes("--no-write")) {
|
|
530
|
+
fs.mkdirSync(outDir, {recursive: true});
|
|
531
|
+
fs.writeFileSync(path.join(outDir, "ai-debug.md"), markdown + "\n", "utf-8");
|
|
532
|
+
fs.writeFileSync(path.join(outDir, "ai-debug.json"), JSON.stringify(report, null, 2) + "\n", "utf-8");
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
if (process.argv.includes("--json")) {
|
|
536
|
+
console.log("\n```json");
|
|
537
|
+
console.log(JSON.stringify(report, null, 2));
|
|
538
|
+
console.log("```");
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
if (process.argv.includes("--check")) {
|
|
542
|
+
const failures: string[] = [];
|
|
543
|
+
const check = (label: string, value: number, budget: number, unit = "") => {
|
|
544
|
+
if (value > budget) failures.push(`${label}: ${value.toFixed(3)}${unit} > ${budget}${unit}`);
|
|
545
|
+
};
|
|
546
|
+
|
|
547
|
+
// Budgets de la spec 003, annexe metrics.
|
|
548
|
+
check("écriture journal (p50)", journal.write.p50, Number(process.env.BENCH_AI_JOURNAL_WRITE_US ?? 0.5), " µs");
|
|
549
|
+
check("recherche indexée (p50)", journal.mapLookup.p50, Number(process.env.BENCH_AI_LOOKUP_US ?? 1), " µs");
|
|
550
|
+
check("sérialisation explain (p50)", journal.serialize.p50, Number(process.env.BENCH_AI_SERIALIZE_US ?? 2), " µs");
|
|
551
|
+
check("écriture journal réel complet (p50)", real.write.p50, Number(process.env.BENCH_AI_REAL_WRITE_FULL_US ?? 1.5), " µs");
|
|
552
|
+
check("écriture journal réel métadonnées (p50)", realMetadata.write.p50, Number(process.env.BENCH_AI_REAL_WRITE_US ?? 0.5), " µs");
|
|
553
|
+
check("recherche indexée réelle (p50)", real.mapLookup.p50, Number(process.env.BENCH_AI_REAL_LOOKUP_US ?? 1), " µs");
|
|
554
|
+
check("sérialisation réelle (p50)", real.serialize.p50, Number(process.env.BENCH_AI_REAL_SERIALIZE_US ?? 2), " µs");
|
|
555
|
+
if (real.totalBytes > 8 * 1024 * 1024) {
|
|
556
|
+
failures.push(`mémoire journal: ${(real.totalBytes / 1024 / 1024).toFixed(2)} Mio > 8 Mio`);
|
|
557
|
+
}
|
|
558
|
+
if (projections.medianFresh < 0.4) {
|
|
559
|
+
failures.push(`économie médiane de tokens (session neuve): ${(projections.medianFresh * 100).toFixed(1)} % < 40 % (projection)`);
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
if (failures.length) {
|
|
563
|
+
console.error("\nBudgets IA dépassés :");
|
|
564
|
+
for (const failure of failures) console.error(` - ${failure}`);
|
|
565
|
+
process.exitCode = 1;
|
|
566
|
+
} else {
|
|
567
|
+
console.log("\nBudgets spec 003 respectés (projections incluses).");
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
main();
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import ArtifactCommand from "../commands/artifact.command.ts";
|
|
2
2
|
import BuildCommand from "../commands/build.command.ts";
|
|
3
|
+
import CallCommand from "../commands/call.command.ts";
|
|
3
4
|
import ClientCommand from "../commands/client.command.ts";
|
|
4
5
|
import ContractCommand from "../commands/contract.command.ts";
|
|
5
6
|
import DevelopCommand from "../commands/develop.command.ts";
|
|
6
7
|
import DocsCommand from "../commands/docs.command.ts";
|
|
7
8
|
import DoctorCommand from "../commands/doctor.command.ts";
|
|
9
|
+
import ExplainCommand from "../commands/explain.command.ts";
|
|
8
10
|
import GenerateCommand from "../commands/generate.command.ts";
|
|
9
11
|
import InspectCommand from "../commands/inspect.command.ts";
|
|
10
12
|
import McpCommand from "../commands/mcp.command.ts";
|
|
11
13
|
import NewCommand from "../commands/new.command.ts";
|
|
12
14
|
import OpenApiCommand from "../commands/openapi.command.ts";
|
|
15
|
+
import RequestsCommand from "../commands/requests.command.ts";
|
|
13
16
|
import RoutesCommand from "../commands/routes.command.ts";
|
|
14
17
|
import StartCommand from "../commands/start.command.ts";
|
|
18
|
+
import VerifyCommand from "../commands/verify.command.ts";
|
|
15
19
|
import WhyCommand from "../commands/why.command.ts";
|
|
16
20
|
import type {Command} from "commander";
|
|
17
21
|
import type {RaitonCommand} from "../core/index.ts";
|
|
@@ -25,6 +29,10 @@ export const RaitonCommandsRegistry: RaitonCommandConstructor[] = [
|
|
|
25
29
|
RoutesCommand,
|
|
26
30
|
InspectCommand,
|
|
27
31
|
WhyCommand,
|
|
32
|
+
CallCommand,
|
|
33
|
+
RequestsCommand,
|
|
34
|
+
ExplainCommand,
|
|
35
|
+
VerifyCommand,
|
|
28
36
|
DoctorCommand,
|
|
29
37
|
OpenApiCommand,
|
|
30
38
|
ClientCommand,
|