reasonix 0.4.5 → 0.4.9
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/dist/cli/index.js +993 -203
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +174 -14
- package/dist/index.js +486 -60
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -405,11 +405,22 @@ declare class SessionStats {
|
|
|
405
405
|
summary(): SessionSummary;
|
|
406
406
|
}
|
|
407
407
|
|
|
408
|
+
/**
|
|
409
|
+
* Per-call context a tool `fn` can optionally consume. Today the only
|
|
410
|
+
* field is `signal`, plumbed through so long-running tools (MCP calls,
|
|
411
|
+
* HTTP requests) can abort when the user presses Esc. Omitted fields
|
|
412
|
+
* stay optional — tools written against the pre-0.4.9 signature keep
|
|
413
|
+
* working; they just ignore cancellation, which is fine for fast
|
|
414
|
+
* local work where "await finishes" happens before the next tick anyway.
|
|
415
|
+
*/
|
|
416
|
+
interface ToolCallContext {
|
|
417
|
+
signal?: AbortSignal;
|
|
418
|
+
}
|
|
408
419
|
interface ToolDefinition<A = any, R = any> {
|
|
409
420
|
name: string;
|
|
410
421
|
description?: string;
|
|
411
422
|
parameters?: JSONSchema;
|
|
412
|
-
fn: (args: A) => R | Promise<R>;
|
|
423
|
+
fn: (args: A, ctx?: ToolCallContext) => R | Promise<R>;
|
|
413
424
|
}
|
|
414
425
|
interface ToolRegistryOptions {
|
|
415
426
|
/**
|
|
@@ -430,7 +441,9 @@ declare class ToolRegistry {
|
|
|
430
441
|
/** True if a registered tool's schema was flattened for the model. */
|
|
431
442
|
wasFlattened(name: string): boolean;
|
|
432
443
|
specs(): ToolSpec[];
|
|
433
|
-
dispatch(name: string, argumentsRaw: string | Record<string, unknown
|
|
444
|
+
dispatch(name: string, argumentsRaw: string | Record<string, unknown>, opts?: {
|
|
445
|
+
signal?: AbortSignal;
|
|
446
|
+
}): Promise<string>;
|
|
434
447
|
}
|
|
435
448
|
|
|
436
449
|
type EventRole = "assistant_delta" | "assistant_final"
|
|
@@ -547,11 +560,13 @@ declare class CacheFirstLoop {
|
|
|
547
560
|
private _turn;
|
|
548
561
|
private _streamPreference;
|
|
549
562
|
/**
|
|
550
|
-
*
|
|
551
|
-
*
|
|
552
|
-
*
|
|
563
|
+
* AbortController per active turn. Threaded through the DeepSeek
|
|
564
|
+
* HTTP calls AND every tool dispatch so Esc actually cancels the
|
|
565
|
+
* in-flight network/subprocess work — not "we'll get to it after
|
|
566
|
+
* the current call finishes." Re-created at the start of each
|
|
567
|
+
* `step()` (the prior turn's signal has already fired).
|
|
553
568
|
*/
|
|
554
|
-
private
|
|
569
|
+
private _turnAbort;
|
|
555
570
|
constructor(opts: CacheFirstLoopOptions);
|
|
556
571
|
/**
|
|
557
572
|
* Shrink the log by re-truncating oversized tool results to a tighter
|
|
@@ -578,11 +593,12 @@ declare class CacheFirstLoop {
|
|
|
578
593
|
configure(opts: ReconfigurableOptions): void;
|
|
579
594
|
private buildMessages;
|
|
580
595
|
/**
|
|
581
|
-
* Signal the currently-running {@link step}
|
|
582
|
-
*
|
|
583
|
-
*
|
|
584
|
-
*
|
|
585
|
-
*
|
|
596
|
+
* Signal the currently-running {@link step} to stop **now**. Cancels
|
|
597
|
+
* the in-flight network request (DeepSeek HTTP/SSE) AND any tool call
|
|
598
|
+
* currently dispatching (MCP `notifications/cancelled` + promise
|
|
599
|
+
* reject). The loop itself also sees `signal.aborted` at each
|
|
600
|
+
* iteration boundary and exits quickly instead of looping again.
|
|
601
|
+
* Called by the TUI on Esc.
|
|
586
602
|
*/
|
|
587
603
|
abort(): void;
|
|
588
604
|
/**
|
|
@@ -634,6 +650,50 @@ declare function healLoadedMessages(messages: ChatMessage[], maxChars: number):
|
|
|
634
650
|
*/
|
|
635
651
|
declare function formatLoopError(err: Error): string;
|
|
636
652
|
|
|
653
|
+
/**
|
|
654
|
+
* Built-in filesystem tools for `reasonix code`.
|
|
655
|
+
*
|
|
656
|
+
* Why native instead of the official `@modelcontextprotocol/server-filesystem`:
|
|
657
|
+
* - No subprocess overhead — every call is 50-200 ms cheaper.
|
|
658
|
+
* - Schema shapes tuned for R1: `edit_file` takes a single
|
|
659
|
+
* SEARCH/REPLACE string instead of `string="false"`-encoded
|
|
660
|
+
* JSON arrays, which was the biggest single source of DSML
|
|
661
|
+
* hallucinations in 0.4.x.
|
|
662
|
+
* - Sandbox enforcement lives here so Reasonix can reason about
|
|
663
|
+
* it (tests cover path-traversal, symlink-escape, and the
|
|
664
|
+
* cwd-outside-root case) rather than trusting an external server.
|
|
665
|
+
* - No `npx install` / network dependency in `reasonix code`.
|
|
666
|
+
*
|
|
667
|
+
* Tool names + argument shapes intentionally mirror the official
|
|
668
|
+
* filesystem server so R1's muscle memory carries over. The only
|
|
669
|
+
* intentional divergence is `edit_file`, noted above.
|
|
670
|
+
*/
|
|
671
|
+
|
|
672
|
+
interface FilesystemToolsOptions {
|
|
673
|
+
/** Absolute directory the tools may read/write. Paths outside this are refused. */
|
|
674
|
+
rootDir: string;
|
|
675
|
+
/**
|
|
676
|
+
* When `false`, register only read-side tools (read_file, list_directory,
|
|
677
|
+
* search_files, get_file_info, directory_tree). Useful for read-only
|
|
678
|
+
* workflows where the model should never mutate the tree. Default: true.
|
|
679
|
+
*/
|
|
680
|
+
allowWriting?: boolean;
|
|
681
|
+
/**
|
|
682
|
+
* Cap for a single file read, in bytes. Prevents a stray `read_file`
|
|
683
|
+
* on a multi-GB blob from OOM'ing Node. 2 MB is enough for any realistic
|
|
684
|
+
* source file (the biggest single-file TypeScript project checked in to
|
|
685
|
+
* GitHub is ~500 KB); pass higher when working with data files.
|
|
686
|
+
*/
|
|
687
|
+
maxReadBytes?: number;
|
|
688
|
+
/**
|
|
689
|
+
* Cap for total bytes returned from search_files / directory_tree /
|
|
690
|
+
* grep, so the model can't accidentally pull down the whole tree as
|
|
691
|
+
* one giant string. 256 KB by default.
|
|
692
|
+
*/
|
|
693
|
+
maxListBytes?: number;
|
|
694
|
+
}
|
|
695
|
+
declare function registerFilesystemTools(registry: ToolRegistry, opts: FilesystemToolsOptions): ToolRegistry;
|
|
696
|
+
|
|
637
697
|
/**
|
|
638
698
|
* Session persistence.
|
|
639
699
|
*
|
|
@@ -974,6 +1034,26 @@ interface ListToolsResult {
|
|
|
974
1034
|
tools: McpTool[];
|
|
975
1035
|
nextCursor?: string;
|
|
976
1036
|
}
|
|
1037
|
+
/**
|
|
1038
|
+
* Server → client notification emitted during a long-running request
|
|
1039
|
+
* that the client subscribed to via `_meta.progressToken`. `progress`
|
|
1040
|
+
* and `total` are typically matched units (files scanned, bytes
|
|
1041
|
+
* processed, etc.); `total` may be missing when the server can't
|
|
1042
|
+
* estimate the upper bound up front.
|
|
1043
|
+
*/
|
|
1044
|
+
interface ProgressNotificationParams {
|
|
1045
|
+
progressToken: string | number;
|
|
1046
|
+
progress: number;
|
|
1047
|
+
total?: number;
|
|
1048
|
+
message?: string;
|
|
1049
|
+
}
|
|
1050
|
+
/** Values a `ProgressHandler` receives — `progressToken` is already matched away. */
|
|
1051
|
+
interface McpProgressInfo {
|
|
1052
|
+
progress: number;
|
|
1053
|
+
total?: number;
|
|
1054
|
+
message?: string;
|
|
1055
|
+
}
|
|
1056
|
+
type McpProgressHandler = (info: McpProgressInfo) => void;
|
|
977
1057
|
interface McpContentBlockText {
|
|
978
1058
|
type: "text";
|
|
979
1059
|
text: string;
|
|
@@ -1152,9 +1232,20 @@ declare class McpClient {
|
|
|
1152
1232
|
private readerStarted;
|
|
1153
1233
|
private initialized;
|
|
1154
1234
|
private _serverCapabilities;
|
|
1235
|
+
private _serverInfo;
|
|
1236
|
+
private _protocolVersion;
|
|
1237
|
+
private _instructions;
|
|
1238
|
+
private readonly progressHandlers;
|
|
1239
|
+
private nextProgressToken;
|
|
1155
1240
|
constructor(opts: McpClientOptions);
|
|
1156
1241
|
/** Server's advertised capabilities, available after initialize(). */
|
|
1157
1242
|
get serverCapabilities(): InitializeResult["capabilities"];
|
|
1243
|
+
/** Server's self-reported name + version, available after initialize(). */
|
|
1244
|
+
get serverInfo(): InitializeResult["serverInfo"];
|
|
1245
|
+
/** Protocol version the server agreed to during the handshake. */
|
|
1246
|
+
get protocolVersion(): string;
|
|
1247
|
+
/** Optional free-form instructions the server provides at handshake. */
|
|
1248
|
+
get serverInstructions(): string | undefined;
|
|
1158
1249
|
/**
|
|
1159
1250
|
* Complete the initialize → initialized handshake. Must be called
|
|
1160
1251
|
* before any other method (otherwise compliant servers reject).
|
|
@@ -1162,8 +1253,26 @@ declare class McpClient {
|
|
|
1162
1253
|
initialize(): Promise<InitializeResult>;
|
|
1163
1254
|
/** List tools the server exposes. */
|
|
1164
1255
|
listTools(): Promise<ListToolsResult>;
|
|
1165
|
-
/**
|
|
1166
|
-
|
|
1256
|
+
/**
|
|
1257
|
+
* Invoke a tool by name. When `onProgress` is supplied, attaches a
|
|
1258
|
+
* fresh progress token so the server can send incremental updates
|
|
1259
|
+
* via `notifications/progress`; they're routed to the callback until
|
|
1260
|
+
* the final response arrives (or the request times out, in which
|
|
1261
|
+
* case the handler is simply dropped — no extra notification).
|
|
1262
|
+
*
|
|
1263
|
+
* When `signal` is supplied, aborting it:
|
|
1264
|
+
* 1) fires `notifications/cancelled` to the server (MCP 2024-11-05
|
|
1265
|
+
* way of saying "forget this request, I no longer care"), and
|
|
1266
|
+
* 2) rejects the pending promise immediately with an AbortError,
|
|
1267
|
+
* so the caller doesn't have to wait for the subprocess to
|
|
1268
|
+
* finish its in-flight file write or network request.
|
|
1269
|
+
* The server MAY still emit a late response; we drop it in dispatch
|
|
1270
|
+
* since the request id is gone from `pending`.
|
|
1271
|
+
*/
|
|
1272
|
+
callTool(name: string, args?: Record<string, unknown>, opts?: {
|
|
1273
|
+
onProgress?: McpProgressHandler;
|
|
1274
|
+
signal?: AbortSignal;
|
|
1275
|
+
}): Promise<CallToolResult>;
|
|
1167
1276
|
/**
|
|
1168
1277
|
* List resources the server exposes. Supports a pagination cursor;
|
|
1169
1278
|
* callers interested in the full set should loop on `nextCursor`.
|
|
@@ -1279,6 +1388,19 @@ interface BridgeOptions {
|
|
|
1279
1388
|
* legitimately want bigger payloads can raise it explicitly.
|
|
1280
1389
|
*/
|
|
1281
1390
|
maxResultChars?: number;
|
|
1391
|
+
/**
|
|
1392
|
+
* Callback fired for every `notifications/progress` frame the server
|
|
1393
|
+
* emits during any bridged tool call. Includes the registered
|
|
1394
|
+
* (prefix-applied) tool name so a multi-server UI can attribute
|
|
1395
|
+
* progress correctly. Absent → no `_meta.progressToken` is sent and
|
|
1396
|
+
* the server won't emit progress for these calls.
|
|
1397
|
+
*/
|
|
1398
|
+
onProgress?: (info: {
|
|
1399
|
+
toolName: string;
|
|
1400
|
+
progress: number;
|
|
1401
|
+
total?: number;
|
|
1402
|
+
message?: string;
|
|
1403
|
+
}) => void;
|
|
1282
1404
|
}
|
|
1283
1405
|
/**
|
|
1284
1406
|
* 32,000 chars ≈ 8k English tokens, or ~16k CJK tokens. Small enough to
|
|
@@ -1370,6 +1492,44 @@ interface SseMcpSpec {
|
|
|
1370
1492
|
type McpSpec = StdioMcpSpec | SseMcpSpec;
|
|
1371
1493
|
declare function parseMcpSpec(input: string): McpSpec;
|
|
1372
1494
|
|
|
1495
|
+
/**
|
|
1496
|
+
* Gather a full inspection report from an initialized MCP client:
|
|
1497
|
+
* server info, capabilities, tools, resources, prompts. Methods the
|
|
1498
|
+
* server doesn't support come back as `{ supported: false }` instead
|
|
1499
|
+
* of throwing, so a CLI or UI can render a consistent "what this
|
|
1500
|
+
* server exposes" summary even against minimal implementations.
|
|
1501
|
+
*
|
|
1502
|
+
* Pure with respect to I/O beyond the passed-in client — the CLI
|
|
1503
|
+
* layer owns argument parsing, connection setup, and printing.
|
|
1504
|
+
*/
|
|
1505
|
+
|
|
1506
|
+
interface InspectionReport {
|
|
1507
|
+
protocolVersion: string;
|
|
1508
|
+
serverInfo: {
|
|
1509
|
+
name: string;
|
|
1510
|
+
version: string;
|
|
1511
|
+
};
|
|
1512
|
+
capabilities: Record<string, unknown>;
|
|
1513
|
+
instructions?: string;
|
|
1514
|
+
tools: SectionResult<McpTool>;
|
|
1515
|
+
resources: SectionResult<McpResource>;
|
|
1516
|
+
prompts: SectionResult<McpPrompt>;
|
|
1517
|
+
}
|
|
1518
|
+
type SectionResult<T> = {
|
|
1519
|
+
supported: true;
|
|
1520
|
+
items: T[];
|
|
1521
|
+
} | {
|
|
1522
|
+
supported: false;
|
|
1523
|
+
reason: string;
|
|
1524
|
+
};
|
|
1525
|
+
/**
|
|
1526
|
+
* Run an inspection against a **already-initialized** client. Caller
|
|
1527
|
+
* is responsible for `initialize()` before this and `close()` after.
|
|
1528
|
+
* We keep this pure so unit tests can feed in a FakeMcpTransport and
|
|
1529
|
+
* verify the aggregate shape without spinning up a real process.
|
|
1530
|
+
*/
|
|
1531
|
+
declare function inspectMcpServer(client: McpClient): Promise<InspectionReport>;
|
|
1532
|
+
|
|
1373
1533
|
/**
|
|
1374
1534
|
* Aider-style SEARCH/REPLACE edit blocks.
|
|
1375
1535
|
*
|
|
@@ -1532,4 +1692,4 @@ declare function redactKey(key: string): string;
|
|
|
1532
1692
|
|
|
1533
1693
|
declare const VERSION = "0.4.3";
|
|
1534
1694
|
|
|
1535
|
-
export { AppendOnlyLog, type ApplyResult, type ApplyStatus, type BranchOptions, type BranchProgress, type BranchResult, type BranchSample, type BranchSelector, type BranchSummary, type BridgeOptions, type BridgeResult, CODE_SYSTEM_PROMPT, CacheFirstLoop, type CacheFirstLoopOptions, type CallToolResult, type ChatMessage, type ChatResponse, DEFAULT_MAX_RESULT_CHARS, DeepSeekClient, type DeepSeekClientOptions, type RenderOptions as DiffRenderOptions, type DiffReport, type DiffSide, type EditBlock, type EditSnapshot, type EventRole, type FlattenDecision, type FlattenOptions, type GetPromptResult, type HarvestOptions, ImmutablePrefix, type ImmutablePrefixOptions, type InitializeResult, type JSONSchema, type JsonRpcMessage, type JsonRpcRequest, type JsonRpcResponse, type ListPromptsResult, type ListResourcesResult, type ListToolsResult, type LoopEvent, MCP_PROTOCOL_VERSION, McpClient, type McpClientOptions, type McpContentBlock, type McpPrompt, type McpPromptArgument, type McpPromptMessage, type McpPromptResourceBlock, type McpResource, type McpResourceContents, type McpResourceContentsBlob, type McpResourceContentsText, type McpSpec, type McpTool, type McpToolSchema, type McpTransport, type ReadResourceResult, type ReadTranscriptResult, type ReasonixConfig, type ReconfigurableOptions, type RepairReport, type ReplayStats, type RetryInfo, type RetryOptions, type Role, type ScavengeOptions, type ScavengeResult, type SessionInfo, SessionStats, type SessionSummary, type SseMcpSpec, SseTransport, type SseTransportOptions, type StdioMcpSpec, StdioTransport, type StdioTransportOptions, StormBreaker, type StreamChunk, type ToolCall, ToolCallRepair, type ToolCallRepairOptions, type ToolDefinition, type ToolFunctionSpec, ToolRegistry, type ToolSpec, type TranscriptMeta, type TranscriptRecord, type TruncationRepairResult, type TurnPair, type TurnStats, type TypedPlanState, Usage, VERSION, VolatileScratch, aggregateBranchUsage, analyzeSchema, appendSessionMessage, applyEditBlock, applyEditBlocks, bridgeMcpTools, claudeEquivalentCost, codeSystemPrompt, computeReplayStats, costUsd, defaultConfigPath, defaultSelector, deleteSession, diffTranscripts, emptyPlanState, fetchWithRetry, flattenMcpResult, flattenSchema, formatLoopError, harvest, healLoadedMessages, isJsonRpcError, isPlanStateEmpty, isPlausibleKey, listSessions, loadApiKey, loadDotenv, loadSessionMessages, nestArguments, openTranscriptFile, parseEditBlocks, parseMcpSpec, parseTranscript, readConfig, readTranscript, recordFromLoopEvent, redactKey, renderMarkdown as renderDiffMarkdown, renderSummaryTable as renderDiffSummary, repairTruncatedJson, replayFromFile, restoreSnapshots, runBranches, sanitizeName as sanitizeSessionName, saveApiKey, scavengeToolCalls, sessionPath, sessionsDir, similarity, snapshotBeforeEdits, stripHallucinatedToolMarkup, truncateForModel, writeConfig, writeMeta, writeRecord };
|
|
1695
|
+
export { AppendOnlyLog, type ApplyResult, type ApplyStatus, type BranchOptions, type BranchProgress, type BranchResult, type BranchSample, type BranchSelector, type BranchSummary, type BridgeOptions, type BridgeResult, CODE_SYSTEM_PROMPT, CacheFirstLoop, type CacheFirstLoopOptions, type CallToolResult, type ChatMessage, type ChatResponse, DEFAULT_MAX_RESULT_CHARS, DeepSeekClient, type DeepSeekClientOptions, type RenderOptions as DiffRenderOptions, type DiffReport, type DiffSide, type EditBlock, type EditSnapshot, type EventRole, type FilesystemToolsOptions, type FlattenDecision, type FlattenOptions, type GetPromptResult, type HarvestOptions, ImmutablePrefix, type ImmutablePrefixOptions, type InitializeResult, type InspectionReport, type JSONSchema, type JsonRpcMessage, type JsonRpcRequest, type JsonRpcResponse, type ListPromptsResult, type ListResourcesResult, type ListToolsResult, type LoopEvent, MCP_PROTOCOL_VERSION, McpClient, type McpClientOptions, type McpContentBlock, type McpProgressHandler, type McpProgressInfo, type McpPrompt, type McpPromptArgument, type McpPromptMessage, type McpPromptResourceBlock, type McpResource, type McpResourceContents, type McpResourceContentsBlob, type McpResourceContentsText, type McpSpec, type McpTool, type McpToolSchema, type McpTransport, type ProgressNotificationParams, type ReadResourceResult, type ReadTranscriptResult, type ReasonixConfig, type ReconfigurableOptions, type RepairReport, type ReplayStats, type RetryInfo, type RetryOptions, type Role, type ScavengeOptions, type ScavengeResult, type SectionResult, type SessionInfo, SessionStats, type SessionSummary, type SseMcpSpec, SseTransport, type SseTransportOptions, type StdioMcpSpec, StdioTransport, type StdioTransportOptions, StormBreaker, type StreamChunk, type ToolCall, type ToolCallContext, ToolCallRepair, type ToolCallRepairOptions, type ToolDefinition, type ToolFunctionSpec, ToolRegistry, type ToolSpec, type TranscriptMeta, type TranscriptRecord, type TruncationRepairResult, type TurnPair, type TurnStats, type TypedPlanState, Usage, VERSION, VolatileScratch, aggregateBranchUsage, analyzeSchema, appendSessionMessage, applyEditBlock, applyEditBlocks, bridgeMcpTools, claudeEquivalentCost, codeSystemPrompt, computeReplayStats, costUsd, defaultConfigPath, defaultSelector, deleteSession, diffTranscripts, emptyPlanState, fetchWithRetry, flattenMcpResult, flattenSchema, formatLoopError, harvest, healLoadedMessages, inspectMcpServer, isJsonRpcError, isPlanStateEmpty, isPlausibleKey, listSessions, loadApiKey, loadDotenv, loadSessionMessages, nestArguments, openTranscriptFile, parseEditBlocks, parseMcpSpec, parseTranscript, readConfig, readTranscript, recordFromLoopEvent, redactKey, registerFilesystemTools, renderMarkdown as renderDiffMarkdown, renderSummaryTable as renderDiffSummary, repairTruncatedJson, replayFromFile, restoreSnapshots, runBranches, sanitizeName as sanitizeSessionName, saveApiKey, scavengeToolCalls, sessionPath, sessionsDir, similarity, snapshotBeforeEdits, stripHallucinatedToolMarkup, truncateForModel, writeConfig, writeMeta, writeRecord };
|