raiton 6.10.0-beta.28 → 6.11.1-beta.30
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 +29 -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,10 @@
|
|
|
1
|
+
import { RaitonCommand } from "../core/command.ts";
|
|
2
|
+
export default class CallCommand extends RaitonCommand {
|
|
3
|
+
readonly name = "call";
|
|
4
|
+
readonly description = "Invoke a route with local validation and a structured result";
|
|
5
|
+
register(): void;
|
|
6
|
+
private action;
|
|
7
|
+
private run;
|
|
8
|
+
private resolveReplay;
|
|
9
|
+
private render;
|
|
10
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CliError } from "../bin/cli-output.ts";
|
|
2
|
+
export declare function collect(value: string, previous?: string[]): string[];
|
|
3
|
+
export declare function parsePairs(values: string[] | undefined, label: string): Record<string, string>;
|
|
4
|
+
export declare function parseData(value: string | undefined, workdir: string): any;
|
|
5
|
+
export declare function asCliError(error: unknown, fallbackHint?: string): CliError;
|
|
6
|
+
export declare function parseMethods(value?: string): string[];
|
|
7
|
+
export declare function isFailure(result: {
|
|
8
|
+
contract: {
|
|
9
|
+
input: string;
|
|
10
|
+
output: string;
|
|
11
|
+
};
|
|
12
|
+
response: {
|
|
13
|
+
status: number;
|
|
14
|
+
};
|
|
15
|
+
}, failOn: string[]): boolean;
|
|
16
|
+
export declare function matchStatus(status: number, filter: string): boolean;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RaitonCommand } from "../core/command.ts";
|
|
2
|
+
export default class ExplainCommand extends RaitonCommand {
|
|
3
|
+
readonly name = "explain";
|
|
4
|
+
readonly description = "Explain a captured request: timeline, root cause and next actions";
|
|
5
|
+
register(): void;
|
|
6
|
+
private action;
|
|
7
|
+
private run;
|
|
8
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RaitonCommand } from "../core/command.ts";
|
|
2
|
+
export default class VerifyCommand extends RaitonCommand {
|
|
3
|
+
readonly name = "verify";
|
|
4
|
+
readonly description = "Call route examples and validate status and output contracts";
|
|
5
|
+
register(): void;
|
|
6
|
+
private action;
|
|
7
|
+
private run;
|
|
8
|
+
}
|
|
@@ -6,9 +6,22 @@ export interface RouteInputContract {
|
|
|
6
6
|
params?: ContractSchema;
|
|
7
7
|
headers?: ContractSchema;
|
|
8
8
|
}
|
|
9
|
+
export interface RouteExampleDeclaration {
|
|
10
|
+
name: string;
|
|
11
|
+
body?: any;
|
|
12
|
+
params?: Record<string, any>;
|
|
13
|
+
query?: Record<string, any>;
|
|
14
|
+
headers?: Record<string, any>;
|
|
15
|
+
expectedStatus?: number;
|
|
16
|
+
}
|
|
9
17
|
export interface RouteContract {
|
|
10
18
|
input?: ContractSchema | RouteInputContract;
|
|
11
19
|
output?: ContractSchema;
|
|
20
|
+
/** Declared examples, in declaration order. */
|
|
21
|
+
examples?: RouteExampleDeclaration[];
|
|
22
|
+
/** Development-only source locations of the decorators. */
|
|
23
|
+
inputLocation?: string;
|
|
24
|
+
outputLocation?: string;
|
|
12
25
|
}
|
|
13
26
|
export declare function isCompositeInput(input: any): input is RouteInputContract;
|
|
14
27
|
/**
|
|
@@ -22,6 +35,11 @@ export declare function Input(input: ContractSchema | RouteInputContract): (targ
|
|
|
22
35
|
* default; see `validation.responses` configuration.
|
|
23
36
|
*/
|
|
24
37
|
export declare function Output(output: ContractSchema): (target: any, propertyKey: string | symbol) => void;
|
|
38
|
+
/**
|
|
39
|
+
* Declare a documented, invocable example for a route. `raiton call --example`
|
|
40
|
+
* and `raiton verify` use it directly; the manifest publishes it.
|
|
41
|
+
*/
|
|
42
|
+
export declare function Example(example: RouteExampleDeclaration): (target: any, propertyKey: string | symbol) => void;
|
|
25
43
|
export declare function getRouteContract(target: any, propertyKey?: string | symbol): RouteContract | undefined;
|
|
26
44
|
export interface RouteInputValidationResult {
|
|
27
45
|
success: boolean;
|
|
@@ -1,19 +1,42 @@
|
|
|
1
1
|
import type { ContractIssue } from "./schema.ts";
|
|
2
2
|
export declare const DOCS_BASE_URL = "https://github.com/protorians/raiton/blob/main/docs";
|
|
3
3
|
export declare function docsUrl(path?: string): string;
|
|
4
|
+
export interface ErrorRenderOptions {
|
|
5
|
+
requestId?: string;
|
|
6
|
+
hint?: string;
|
|
7
|
+
/** Development-only contract location. */
|
|
8
|
+
location?: string;
|
|
9
|
+
/** Development-only stack lines. */
|
|
10
|
+
stack?: string[];
|
|
11
|
+
redact?: string[];
|
|
12
|
+
/**
|
|
13
|
+
* When explicitly false, expected/received/location details are omitted:
|
|
14
|
+
* production error bodies never expose internal contract details.
|
|
15
|
+
*/
|
|
16
|
+
development?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare const ERROR_SCHEMA_VERSION = "1.0.0";
|
|
4
19
|
export interface ValidationErrorBody {
|
|
5
20
|
error: true;
|
|
21
|
+
schemaVersion: string;
|
|
6
22
|
code: "VALIDATION_ERROR";
|
|
7
23
|
message: string;
|
|
8
24
|
statusCode: number;
|
|
9
25
|
details: ContractIssue[];
|
|
10
26
|
docsUrl: string;
|
|
27
|
+
requestId?: string;
|
|
28
|
+
hint?: string;
|
|
11
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Mask sensitive received values and attach the contract source location. The
|
|
32
|
+
* rendered error never contains a raw secret, in development or production.
|
|
33
|
+
*/
|
|
34
|
+
export declare function sanitizeIssues(issues: ContractIssue[], options?: ErrorRenderOptions): ContractIssue[];
|
|
12
35
|
/**
|
|
13
36
|
* Stable validation error payload shared by runtime validation and generated
|
|
14
37
|
* clients. Never includes a stack trace or internal field.
|
|
15
38
|
*/
|
|
16
|
-
export declare function validationErrorBody(issues: ContractIssue[], message?: string): ValidationErrorBody;
|
|
39
|
+
export declare function validationErrorBody(issues: ContractIssue[], message?: string, options?: ErrorRenderOptions): ValidationErrorBody;
|
|
17
40
|
/**
|
|
18
41
|
* Thrown before the route handler executes when the input contract fails.
|
|
19
42
|
*/
|
|
@@ -21,7 +44,7 @@ export declare class ContractValidationError extends Error {
|
|
|
21
44
|
readonly issues: ContractIssue[];
|
|
22
45
|
readonly statusCode = 400;
|
|
23
46
|
constructor(issues: ContractIssue[], message?: string);
|
|
24
|
-
render(): ValidationErrorBody;
|
|
47
|
+
render(options?: ErrorRenderOptions): ValidationErrorBody;
|
|
25
48
|
}
|
|
26
49
|
/**
|
|
27
50
|
* Thrown in development when a response does not match its `@Output` contract.
|
|
@@ -31,12 +54,15 @@ export declare class OutputContractError extends Error {
|
|
|
31
54
|
readonly issues: ContractIssue[];
|
|
32
55
|
readonly statusCode = 500;
|
|
33
56
|
constructor(route: string, issues: ContractIssue[]);
|
|
34
|
-
render(): {
|
|
57
|
+
render(options?: ErrorRenderOptions): {
|
|
35
58
|
error: boolean;
|
|
59
|
+
schemaVersion: string;
|
|
36
60
|
code: string;
|
|
37
61
|
statusCode: number;
|
|
38
62
|
message: string;
|
|
39
63
|
details: ContractIssue[];
|
|
40
64
|
docsUrl: string;
|
|
65
|
+
requestId?: string | undefined;
|
|
66
|
+
hint: string;
|
|
41
67
|
};
|
|
42
68
|
}
|
|
@@ -30,6 +30,12 @@ export interface ContractIssue {
|
|
|
30
30
|
path: string;
|
|
31
31
|
code: string;
|
|
32
32
|
message: string;
|
|
33
|
+
/** Expected value, format or constraint (development diagnostics). */
|
|
34
|
+
expected?: string;
|
|
35
|
+
/** Received value summary (development diagnostics, redacted upstream). */
|
|
36
|
+
received?: string;
|
|
37
|
+
/** Contract or decorator source location, when available. */
|
|
38
|
+
location?: string;
|
|
33
39
|
}
|
|
34
40
|
export interface ContractValidationResult<T = unknown> {
|
|
35
41
|
success: boolean;
|
|
@@ -39,6 +45,13 @@ export interface ContractValidationResult<T = unknown> {
|
|
|
39
45
|
export declare function isStandardSchema(value: any): value is StandardSchemaV1;
|
|
40
46
|
export declare function isTypeBoxSchema(value: any): value is TSchema;
|
|
41
47
|
export declare function isContractSchema(value: any): value is ContractSchema;
|
|
48
|
+
/**
|
|
49
|
+
* Human-readable description of the expected value for an issue. Kept short so
|
|
50
|
+
* error bodies stay token-efficient.
|
|
51
|
+
*/
|
|
52
|
+
export declare function describeExpected(schema: any): string | undefined;
|
|
53
|
+
/** Bounded, one-line summary of a received value. */
|
|
54
|
+
export declare function describeReceived(value: any, maxLength?: number): string;
|
|
42
55
|
/**
|
|
43
56
|
* Convert plain JSON Schema (no TypeBox `Kind`) to TypeBox so the value checker
|
|
44
57
|
* can validate it. Already-compiled TypeBox schemas are returned unchanged.
|
|
@@ -3,12 +3,14 @@ import { HttpMethod } from "../framework/enums/http-method.enum.ts";
|
|
|
3
3
|
import { RouteHandlerCallable } from "../types/index.ts";
|
|
4
4
|
import { Injection } from "./injection/index.ts";
|
|
5
5
|
import { HttpsConfigInterface } from "../framework/utilities/https.util.ts";
|
|
6
|
+
import { type DebugRuntimeState } from "../debug/runtime.ts";
|
|
6
7
|
export declare class Application implements ApplicationInterface {
|
|
7
8
|
readonly config: ApplicationConfigInterface;
|
|
8
9
|
private root;
|
|
9
10
|
private _resolvedHttps;
|
|
10
11
|
private readonly _observability;
|
|
11
12
|
private readonly _plugins;
|
|
13
|
+
private _debug?;
|
|
12
14
|
readonly version: string;
|
|
13
15
|
static get container(): typeof Injection;
|
|
14
16
|
constructor(config: ApplicationConfigInterface);
|
|
@@ -21,6 +23,12 @@ export declare class Application implements ApplicationInterface {
|
|
|
21
23
|
get https(): HttpsConfigInterface | undefined;
|
|
22
24
|
setOption<K extends keyof ApplicationConfigInterface>(key: K, value: ApplicationConfigInterface[K]): this;
|
|
23
25
|
setOptions(options: ApplicationConfigInterface): this;
|
|
26
|
+
/**
|
|
27
|
+
* Attach a debug runtime after construction. Used by CLI tooling that
|
|
28
|
+
* boots the application without a socket and then enables the journal for
|
|
29
|
+
* in-process invocation and verification.
|
|
30
|
+
*/
|
|
31
|
+
adoptDebugRuntime(runtime: DebugRuntimeState): this;
|
|
24
32
|
register(plugin: any): this;
|
|
25
33
|
use(mw: any): this;
|
|
26
34
|
route(method: HttpMethod, path: string, handler: RouteHandlerCallable, version?: string): this;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ApplicationInterface } from "../types/application.ts";
|
|
2
|
+
import type { ProjectManifest } from "../manifest/schema.ts";
|
|
3
|
+
import { type DebugRuntimeState } from "./runtime.ts";
|
|
4
|
+
import type { DebugInvocationRequest, DebugInvocationResult, DebugJournalEntry } from "./types.ts";
|
|
5
|
+
/**
|
|
6
|
+
* Enable the journal on an application booted without a socket, so `raiton
|
|
7
|
+
* call` and `raiton verify` can capture the in-process exchange and `explain`
|
|
8
|
+
* can read it back later.
|
|
9
|
+
*/
|
|
10
|
+
export declare function enableCliDebug(application: ApplicationInterface, workdir: string): DebugRuntimeState;
|
|
11
|
+
export declare function baseUrlOf(application?: ApplicationInterface): string;
|
|
12
|
+
export interface RemoteDebugOptions {
|
|
13
|
+
baseUrl: string;
|
|
14
|
+
token?: string;
|
|
15
|
+
timeoutMs?: number;
|
|
16
|
+
}
|
|
17
|
+
export interface RemoteDebugResponse {
|
|
18
|
+
status: number;
|
|
19
|
+
body: any;
|
|
20
|
+
}
|
|
21
|
+
/** Call the HTTP debug surface of a running application. */
|
|
22
|
+
export declare function remoteDebug(options: RemoteDebugOptions, path: string, init?: {
|
|
23
|
+
method?: string;
|
|
24
|
+
body?: any;
|
|
25
|
+
}): Promise<RemoteDebugResponse>;
|
|
26
|
+
/** Probe whether a running application exposes the debug surface. */
|
|
27
|
+
export declare function probeDebug(options: RemoteDebugOptions): Promise<RemoteDebugResponse | undefined>;
|
|
28
|
+
/**
|
|
29
|
+
* Convert an invocation result into a journal entry. Used when the request ran
|
|
30
|
+
* through the CLI's in-process application without an active collector.
|
|
31
|
+
*/
|
|
32
|
+
export declare function entryFromInvocation(manifest: ProjectManifest, spec: DebugInvocationRequest, result: DebugInvocationResult): DebugJournalEntry;
|
|
33
|
+
export declare function appendInvocationEntry(entry: DebugJournalEntry, workdir: string): void;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ContractIssue } from "../contracts/index.ts";
|
|
2
|
+
import { summarizeValue } from "./redaction.ts";
|
|
3
|
+
import type { DebugJournal } from "./journal.ts";
|
|
4
|
+
import type { DebugErrorLike } from "./collector.internal.ts";
|
|
5
|
+
import type { ResolvedDebugConfig } from "./types.ts";
|
|
6
|
+
import type { DebugJournalEntry, DebugRouteSource, DebugValidationIssue, DebugValidationSummary } from "./types.ts";
|
|
7
|
+
export interface DebugCollectorOptions {
|
|
8
|
+
config: ResolvedDebugConfig;
|
|
9
|
+
journal: DebugJournal;
|
|
10
|
+
buildId: string;
|
|
11
|
+
development: boolean;
|
|
12
|
+
}
|
|
13
|
+
/** Convert contract issues to the journal/explanation shape. */
|
|
14
|
+
export declare function toDebugIssues(issues: ContractIssue[] | undefined, redact?: string[]): DebugValidationIssue[];
|
|
15
|
+
/**
|
|
16
|
+
* Request-scoped collector.
|
|
17
|
+
*
|
|
18
|
+
* `start()` allocates one trace only when the journal is enabled. Disabled
|
|
19
|
+
* debug surfaces never call this class at all (see `runtime.ts`).
|
|
20
|
+
*/
|
|
21
|
+
export declare class DebugCollector {
|
|
22
|
+
buildId: string;
|
|
23
|
+
readonly config: ResolvedDebugConfig;
|
|
24
|
+
readonly journal: DebugJournal;
|
|
25
|
+
private readonly development;
|
|
26
|
+
constructor(options: DebugCollectorOptions);
|
|
27
|
+
get enabled(): boolean;
|
|
28
|
+
start(ctx: any): void;
|
|
29
|
+
step(ctx: any, step: string, result?: string, durationMs?: number, detail?: string): void;
|
|
30
|
+
markHandler(ctx: any, executed: boolean): void;
|
|
31
|
+
setSource(ctx: any, source: DebugRouteSource | undefined): void;
|
|
32
|
+
setValidation(ctx: any, summary: DebugValidationSummary | undefined): void;
|
|
33
|
+
setCache(ctx: any, hit: boolean): void;
|
|
34
|
+
setError(ctx: any, error: DebugErrorLike | undefined): void;
|
|
35
|
+
setResponseBody(ctx: any, body: any): void;
|
|
36
|
+
setStatus(ctx: any, status: number): void;
|
|
37
|
+
finish(ctx: any): DebugJournalEntry | undefined;
|
|
38
|
+
ack(ctx: any): void;
|
|
39
|
+
private state;
|
|
40
|
+
}
|
|
41
|
+
export { summarizeValue };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { DebugRouteSource, DebugTimelineStep, DebugValidationSummary } from "./types.ts";
|
|
2
|
+
export interface DebugErrorLike {
|
|
3
|
+
code: string;
|
|
4
|
+
message: string;
|
|
5
|
+
statusCode?: number;
|
|
6
|
+
stack?: string[];
|
|
7
|
+
location?: string;
|
|
8
|
+
}
|
|
9
|
+
/** Request-scoped capture state, attached to `ctx.state.debug`. */
|
|
10
|
+
export interface DebugTraceState {
|
|
11
|
+
startedAt: string;
|
|
12
|
+
startPerf: number;
|
|
13
|
+
requestId: string;
|
|
14
|
+
traceId: string;
|
|
15
|
+
method: string;
|
|
16
|
+
pathname: string;
|
|
17
|
+
timeline: DebugTimelineStep[];
|
|
18
|
+
handlerExecuted: boolean;
|
|
19
|
+
validation?: DebugValidationSummary;
|
|
20
|
+
error?: DebugErrorLike;
|
|
21
|
+
source?: DebugRouteSource;
|
|
22
|
+
cache?: {
|
|
23
|
+
hit: boolean;
|
|
24
|
+
};
|
|
25
|
+
responseBody?: any;
|
|
26
|
+
captured: boolean;
|
|
27
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ResolvedDebugConfig } from "./types.ts";
|
|
2
|
+
export declare function envFlag(name: string): boolean | undefined;
|
|
3
|
+
export interface ResolveDebugOptions {
|
|
4
|
+
development: boolean;
|
|
5
|
+
/** Project root, used to resolve source locations and session files. */
|
|
6
|
+
workdir?: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Resolve the debug section against defaults and environment variables.
|
|
10
|
+
*
|
|
11
|
+
* Production safety: surfaces stay disabled unless `debug.enabled` (or
|
|
12
|
+
* `RAITON_DEBUG`) is explicitly enabled. Even when enabled, the HTTP surface
|
|
13
|
+
* defaults to a loopback-only binding and an optional token.
|
|
14
|
+
*/
|
|
15
|
+
export declare function resolveDebugConfig(options: ResolveDebugOptions): ResolvedDebugConfig;
|
|
16
|
+
/** Constant-time string comparison for tokens. */
|
|
17
|
+
export declare function safeCompare(left: string, right: string): boolean;
|
|
18
|
+
/** Read a debug token from either documented header or a Bearer token. */
|
|
19
|
+
export declare function readDebugToken(headers: any): string | undefined;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example generation from published JSON schemas.
|
|
3
|
+
*
|
|
4
|
+
* Examples are deterministic: the same contract always produces the same
|
|
5
|
+
* example. They are used by the manifest, OpenAPI and `raiton verify`.
|
|
6
|
+
*/
|
|
7
|
+
export interface RouteExample {
|
|
8
|
+
name: string;
|
|
9
|
+
body?: any;
|
|
10
|
+
params?: Record<string, any>;
|
|
11
|
+
query?: Record<string, any>;
|
|
12
|
+
headers?: Record<string, any>;
|
|
13
|
+
expectedStatus?: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Build the smallest valid value for a JSON schema. Optional object properties
|
|
17
|
+
* are omitted so examples stay readable and token-efficient.
|
|
18
|
+
*/
|
|
19
|
+
export declare function exampleForSchema(schema: any, depth?: number): any;
|
|
20
|
+
/** Generate the default example of a route from its published schemas. */
|
|
21
|
+
export declare function defaultExample(input: {
|
|
22
|
+
bodySchema?: any;
|
|
23
|
+
paramsSchema?: any;
|
|
24
|
+
querySchema?: any;
|
|
25
|
+
headersSchema?: any;
|
|
26
|
+
expectedStatus?: number;
|
|
27
|
+
}): RouteExample;
|
|
28
|
+
/**
|
|
29
|
+
* Complete a route example with values for every `:param` in the path. Values
|
|
30
|
+
* are inferred from the parameter contract when available, otherwise `1` is
|
|
31
|
+
* used (valid for strings and integers alike).
|
|
32
|
+
*/
|
|
33
|
+
export declare function fillPathParams(example: RouteExample, routePath: string, paramsSchema?: any): RouteExample;
|
|
34
|
+
export interface RouteErrorDocumentation {
|
|
35
|
+
code: string;
|
|
36
|
+
status: number;
|
|
37
|
+
description?: string;
|
|
38
|
+
}
|
|
39
|
+
/** Documented error codes for a route, derived from its contracts. */
|
|
40
|
+
export declare function errorsForRoute(contract?: {
|
|
41
|
+
input?: any;
|
|
42
|
+
output?: any;
|
|
43
|
+
}): RouteErrorDocumentation[];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DebugExplanation, DebugJournalEntry } from "./types.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Reconstruct the timeline, root cause and next actions from a journal entry.
|
|
4
|
+
* Pure function: no I/O, no side effect.
|
|
5
|
+
*/
|
|
6
|
+
export declare function explainEntry(entry: DebugJournalEntry, options?: {
|
|
7
|
+
verbose?: boolean;
|
|
8
|
+
}): DebugExplanation;
|
|
9
|
+
export declare function explainHuman(explanation: DebugExplanation): string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from "./types.ts";
|
|
2
|
+
export * from "./redaction.ts";
|
|
3
|
+
export * from "./config.ts";
|
|
4
|
+
export * from "./journal.ts";
|
|
5
|
+
export * from "./collector.ts";
|
|
6
|
+
export * from "./runtime.ts";
|
|
7
|
+
export * from "./examples.ts";
|
|
8
|
+
export * from "./invocation.ts";
|
|
9
|
+
export * from "./explain.ts";
|
|
10
|
+
export * from "./requests.ts";
|
|
11
|
+
export * from "./verify.ts";
|
|
12
|
+
export * from "./session.ts";
|
|
13
|
+
export * from "./mcp.ts";
|
|
14
|
+
export * from "./mcp-http.ts";
|
|
15
|
+
export * from "./surface.ts";
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { ApplicationInterface } from "../types/application.ts";
|
|
2
|
+
import type { ProjectManifest, ProjectRouteManifest } from "../manifest/schema.ts";
|
|
3
|
+
import type { ResolvedDebugConfig } from "./types.ts";
|
|
4
|
+
import type { DebugContractStatus, DebugInvocationRequest, DebugInvocationResult, DebugResolvedRequest } from "./types.ts";
|
|
5
|
+
import { DEFAULT_REDACT_KEYS } from "./redaction.ts";
|
|
6
|
+
import { exampleForSchema } from "./examples.ts";
|
|
7
|
+
import type { DebugJournalEntry, DebugReplayComparison } from "./types.ts";
|
|
8
|
+
export declare class DebugInvocationError extends Error {
|
|
9
|
+
readonly code: string;
|
|
10
|
+
readonly hint: string;
|
|
11
|
+
readonly location?: string;
|
|
12
|
+
readonly exitCode: number;
|
|
13
|
+
constructor(message: string, options?: {
|
|
14
|
+
code?: string;
|
|
15
|
+
hint?: string;
|
|
16
|
+
location?: string;
|
|
17
|
+
exitCode?: number;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
export interface InvocationContext {
|
|
21
|
+
manifest: ProjectManifest;
|
|
22
|
+
application?: ApplicationInterface;
|
|
23
|
+
config?: ResolvedDebugConfig;
|
|
24
|
+
baseUrl?: string;
|
|
25
|
+
workdir?: string;
|
|
26
|
+
development?: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface PreparedInvocation {
|
|
29
|
+
resolved: DebugResolvedRequest;
|
|
30
|
+
raw: {
|
|
31
|
+
headers: Record<string, string>;
|
|
32
|
+
query: Record<string, any>;
|
|
33
|
+
params: Record<string, any>;
|
|
34
|
+
body?: any;
|
|
35
|
+
};
|
|
36
|
+
route?: ProjectRouteManifest;
|
|
37
|
+
contract: DebugContractStatus;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Resolve and validate an invocation without sending it.
|
|
41
|
+
*/
|
|
42
|
+
export declare function prepareInvocation(context: InvocationContext, spec: DebugInvocationRequest): Promise<PreparedInvocation>;
|
|
43
|
+
/**
|
|
44
|
+
* Resolve, validate, send and normalize a route invocation. Input validation
|
|
45
|
+
* runs before any handler execution; an invalid payload is never sent.
|
|
46
|
+
*/
|
|
47
|
+
export declare function invokeRoute(context: InvocationContext, spec: DebugInvocationRequest): Promise<DebugInvocationResult>;
|
|
48
|
+
/**
|
|
49
|
+
* Compare a replay with the original journal entry. Captured bodies may be
|
|
50
|
+
* absent in metadata mode, in which case the body comparison is `unknown`.
|
|
51
|
+
*/
|
|
52
|
+
export declare function compareReplay(previous: DebugJournalEntry, result: DebugInvocationResult): DebugReplayComparison;
|
|
53
|
+
export { DEFAULT_REDACT_KEYS, exampleForSchema };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { DebugJournalEntry, DebugJournalFilter } from "./types.ts";
|
|
2
|
+
export declare function estimateEntryBytes(entry: DebugJournalEntry): number;
|
|
3
|
+
export interface DebugJournalOptions {
|
|
4
|
+
capacity?: number;
|
|
5
|
+
ttlMs?: number;
|
|
6
|
+
maxTotalBytes?: number;
|
|
7
|
+
now?: () => number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Bounded in-memory request journal.
|
|
11
|
+
*
|
|
12
|
+
* - O(1) lookup by `requestId` through a Map.
|
|
13
|
+
* - The ring buffer evicts the oldest entry first; the memory footprint never
|
|
14
|
+
* grows with the total number of processed requests.
|
|
15
|
+
* - Entries are stored as references/scalars: serialization is deferred to the
|
|
16
|
+
* reader (`requests`, `explain`, HTTP and MCP tools).
|
|
17
|
+
*/
|
|
18
|
+
export declare class DebugJournal {
|
|
19
|
+
readonly capacity: number;
|
|
20
|
+
readonly ttlMs: number;
|
|
21
|
+
readonly maxTotalBytes: number;
|
|
22
|
+
private readonly now;
|
|
23
|
+
private readonly ring;
|
|
24
|
+
private readonly sizeRing;
|
|
25
|
+
private readonly index;
|
|
26
|
+
private head;
|
|
27
|
+
private count;
|
|
28
|
+
private bytes;
|
|
29
|
+
private dropped;
|
|
30
|
+
private nextPurge;
|
|
31
|
+
private buildId;
|
|
32
|
+
constructor(options?: DebugJournalOptions);
|
|
33
|
+
get size(): number;
|
|
34
|
+
get totalBytes(): number;
|
|
35
|
+
get evicted(): number;
|
|
36
|
+
/** Mark every retained entry from another build as stale (HMR). */
|
|
37
|
+
setBuildId(buildId: string): void;
|
|
38
|
+
push(entry: DebugJournalEntry, estimatedBytes?: number): void;
|
|
39
|
+
get(requestId: string): DebugJournalEntry | undefined;
|
|
40
|
+
last(): DebugJournalEntry | undefined;
|
|
41
|
+
recent(filter?: DebugJournalFilter): DebugJournalEntry[];
|
|
42
|
+
clear(): void;
|
|
43
|
+
private newest;
|
|
44
|
+
private evictOldest;
|
|
45
|
+
private remove;
|
|
46
|
+
private purgeExpired;
|
|
47
|
+
private rebuild;
|
|
48
|
+
}
|
|
49
|
+
export declare function matchStatus(status: number, filter: string): boolean;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { McpServerRegistrationInterface } from "../types/mcp.ts";
|
|
2
|
+
export interface DebugMcpHttpOptions {
|
|
3
|
+
hostname?: string;
|
|
4
|
+
port?: number;
|
|
5
|
+
token?: string;
|
|
6
|
+
scopes?: string[];
|
|
7
|
+
}
|
|
8
|
+
export interface DebugMcpHttpServer {
|
|
9
|
+
url: string;
|
|
10
|
+
close(): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Standalone debug MCP HTTP server used by `raiton mcp debug --http`.
|
|
14
|
+
* The same handler as the application transport is used, so annotations,
|
|
15
|
+
* scopes, audit and error shapes are identical.
|
|
16
|
+
*/
|
|
17
|
+
export declare function serveDebugMcpHttp(entry: McpServerRegistrationInterface, options?: DebugMcpHttpOptions): Promise<DebugMcpHttpServer>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import type { McpServerRegistrationInterface } from "../types/mcp.ts";
|
|
3
|
+
import type { DebugDoctorReport, DebugJournalEntry } from "./types.ts";
|
|
4
|
+
export declare const DEBUG_MCP_SERVER_NAME = "raiton-debug";
|
|
5
|
+
/**
|
|
6
|
+
* Build (or reuse) the debug MCP server registration. Tools reuse the shared
|
|
7
|
+
* MCP handler, so audit, scopes, rate limiting, annotations and both transports
|
|
8
|
+
* behave exactly like application MCP servers.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createDebugMcpEntry(path?: string): McpServerRegistrationInterface;
|
|
11
|
+
export declare function debugMcpToolNames(): string[];
|
|
12
|
+
/** Shared diagnostic used by the `doctor.run` MCP tool and the HTTP surface. */
|
|
13
|
+
export declare function runDebugDoctor(): Promise<DebugDoctorReport>;
|
|
14
|
+
export type { DebugJournalEntry };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Secret redaction and bounded capture helpers.
|
|
3
|
+
*
|
|
4
|
+
* These helpers are dependency-free and safe to import from the error
|
|
5
|
+
* catalogue, the request journal and the CLI: they never throw on circular
|
|
6
|
+
* structures and never mutate their input.
|
|
7
|
+
*/
|
|
8
|
+
export declare const REDACTED = "***";
|
|
9
|
+
/** Header and body keys masked by default. Extend with `debug.journal.redact`. */
|
|
10
|
+
export declare const DEFAULT_REDACT_KEYS: readonly string[];
|
|
11
|
+
export interface RedactOptions {
|
|
12
|
+
keys?: readonly string[];
|
|
13
|
+
/** Maximum depth explored. @default 8 */
|
|
14
|
+
depth?: number;
|
|
15
|
+
/** Maximum items per array. @default 100 */
|
|
16
|
+
maxItems?: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Build a case-insensitive, normalised set from the built-in list and any
|
|
20
|
+
* project-specific keys.
|
|
21
|
+
*/
|
|
22
|
+
export declare function redactionKeys(extra?: readonly string[]): Set<string>;
|
|
23
|
+
export declare function isSensitiveKey(key: string, keys: Set<string>): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Deep-clone a value while masking sensitive keys. The returned value is safe
|
|
26
|
+
* to serialize or store in the journal.
|
|
27
|
+
*/
|
|
28
|
+
export declare function redactValue<T = any>(value: T, options?: RedactOptions): T;
|
|
29
|
+
/**
|
|
30
|
+
* Convert any header container (Headers, Map, plain object) to a redacted
|
|
31
|
+
* plain object.
|
|
32
|
+
*/
|
|
33
|
+
export declare function redactHeaders(headers: any, extraKeys?: readonly string[]): Record<string, string>;
|
|
34
|
+
/** Normalise a header container to a plain, lower-cased object. */
|
|
35
|
+
export declare function headersToObject(headers: any): Record<string, string>;
|
|
36
|
+
export declare function safeStringify(value: unknown): string;
|
|
37
|
+
/**
|
|
38
|
+
* Bound a captured body. The value is serialized once; oversized payloads are
|
|
39
|
+
* replaced by an explicit marker and a bounded preview. The request itself is
|
|
40
|
+
* never affected.
|
|
41
|
+
*/
|
|
42
|
+
export declare function truncateValue(value: any, maxBytes: number): any;
|
|
43
|
+
export declare function byteLength(value: string): number;
|
|
44
|
+
/**
|
|
45
|
+
* One-line summary of a received value, safely bounded. Sensitive field paths
|
|
46
|
+
* are masked by the caller (see `describeIssue`).
|
|
47
|
+
*/
|
|
48
|
+
export declare function summarizeValue(value: any, maxLength?: number): string;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { matchStatus } from "./journal.ts";
|
|
2
|
+
import type { DebugJournalEntry, DebugRequestsList } from "./types.ts";
|
|
3
|
+
export interface ListRequestsOptions {
|
|
4
|
+
since?: string | number;
|
|
5
|
+
status?: string;
|
|
6
|
+
route?: string;
|
|
7
|
+
limit?: number;
|
|
8
|
+
includeBodies?: boolean;
|
|
9
|
+
workdir?: string;
|
|
10
|
+
}
|
|
11
|
+
/** Parse `5m`, `30s`, `2h`, `1000ms` or a number of milliseconds. */
|
|
12
|
+
export declare function parseSince(value?: string | number): number | undefined;
|
|
13
|
+
export interface RequestLookup {
|
|
14
|
+
entry: DebugJournalEntry;
|
|
15
|
+
origin: "journal" | "session";
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Find a request by id in the in-memory journal, then in the bounded CLI
|
|
19
|
+
* session file. Returns `undefined` when neither contains it.
|
|
20
|
+
*/
|
|
21
|
+
export declare function findRequest(requestId: string, workdir?: string): RequestLookup | undefined;
|
|
22
|
+
export declare function lastRequest(workdir?: string): RequestLookup | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* List retained requests, most recent first. Bodies are omitted by default so
|
|
25
|
+
* the output stays token-efficient.
|
|
26
|
+
*/
|
|
27
|
+
export declare function listRequests(options?: ListRequestsOptions): DebugRequestsList;
|
|
28
|
+
/** Used by the HTTP surface when `includeBodies` is requested. */
|
|
29
|
+
export declare function listRequestsWithBodies(options?: ListRequestsOptions): DebugRequestsList & {
|
|
30
|
+
entries: DebugJournalEntry[];
|
|
31
|
+
};
|
|
32
|
+
export { matchStatus };
|
|
33
|
+
/**
|
|
34
|
+
* Resolve the invocation path for a captured entry. Metadata capture omits
|
|
35
|
+
* params, so the concrete path is the only replayable form in that mode.
|
|
36
|
+
*/
|
|
37
|
+
export declare function replayPath(entry: DebugJournalEntry): string;
|