reasonix 0.2.2 → 0.3.0-alpha.1
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 +23 -0
- package/dist/cli/index.js +714 -105
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +270 -2
- package/dist/index.js +327 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -612,6 +612,13 @@ interface TranscriptRecord {
|
|
|
612
612
|
* stability, not to a different system prompt.
|
|
613
613
|
*/
|
|
614
614
|
prefixHash?: string;
|
|
615
|
+
/**
|
|
616
|
+
* Structured plan state extracted by the Pillar 2 harvester. Present on
|
|
617
|
+
* assistant_final records when harvest was enabled and produced non-empty
|
|
618
|
+
* state. Omitted entirely when harvest is off or produced nothing —
|
|
619
|
+
* absence means "no data", not "empty plan".
|
|
620
|
+
*/
|
|
621
|
+
planState?: TypedPlanState;
|
|
615
622
|
/** Optional error message (role === "error"). */
|
|
616
623
|
error?: string;
|
|
617
624
|
}
|
|
@@ -690,6 +697,12 @@ interface ReplayStats extends SessionSummary {
|
|
|
690
697
|
userTurns: number;
|
|
691
698
|
/** Count of tool-role records (tool calls executed). */
|
|
692
699
|
toolCalls: number;
|
|
700
|
+
/** Count of assistant_final records that carry a non-empty planState (harvest signal). */
|
|
701
|
+
harvestedTurns: number;
|
|
702
|
+
/** Sum of uncertainties across all harvested turns — a proxy for "how much did R1 hedge?" */
|
|
703
|
+
totalUncertainties: number;
|
|
704
|
+
/** Sum of subgoals across all harvested turns. */
|
|
705
|
+
totalSubgoals: number;
|
|
693
706
|
}
|
|
694
707
|
/**
|
|
695
708
|
* Parse a transcript file and compute replay stats. Throws only on I/O
|
|
@@ -770,6 +783,261 @@ interface RenderOptions {
|
|
|
770
783
|
declare function renderSummaryTable(report: DiffReport, _opts?: RenderOptions): string;
|
|
771
784
|
declare function renderMarkdown(report: DiffReport): string;
|
|
772
785
|
|
|
786
|
+
/**
|
|
787
|
+
* MCP (Model Context Protocol) type definitions.
|
|
788
|
+
*
|
|
789
|
+
* Hand-rolled rather than importing @modelcontextprotocol/sdk because:
|
|
790
|
+
* - Reasonix's value-add isn't reimplementing the protocol, but *caching*
|
|
791
|
+
* it. Owning the types lets us tune them for our integration (strip
|
|
792
|
+
* fields we don't use, add the ones we do like Reasonix's prefixHash).
|
|
793
|
+
* - Zero dependencies — consistent with how we wrote the DeepSeek client.
|
|
794
|
+
* - If Anthropic bumps the SDK and introduces a breaking change, we're
|
|
795
|
+
* insulated as long as we keep up with the spec itself.
|
|
796
|
+
*
|
|
797
|
+
* Spec reference: https://spec.modelcontextprotocol.io/ (2024-11-05 draft
|
|
798
|
+
* at time of writing). Only the subset Reasonix consumes is modeled here —
|
|
799
|
+
* tools list/call + init handshake. Resources and prompts are deferred.
|
|
800
|
+
*
|
|
801
|
+
* Transport note: the wire format for stdio MCP is **newline-delimited
|
|
802
|
+
* JSON** (NDJSON), not the LSP-style Content-Length header framing that
|
|
803
|
+
* some readers might expect. One JSON-RPC message per line.
|
|
804
|
+
*/
|
|
805
|
+
type JsonRpcId = string | number;
|
|
806
|
+
interface JsonRpcRequest<P = unknown> {
|
|
807
|
+
jsonrpc: "2.0";
|
|
808
|
+
id: JsonRpcId;
|
|
809
|
+
method: string;
|
|
810
|
+
params?: P;
|
|
811
|
+
}
|
|
812
|
+
interface JsonRpcNotification<P = unknown> {
|
|
813
|
+
jsonrpc: "2.0";
|
|
814
|
+
method: string;
|
|
815
|
+
params?: P;
|
|
816
|
+
}
|
|
817
|
+
interface JsonRpcSuccess<R = unknown> {
|
|
818
|
+
jsonrpc: "2.0";
|
|
819
|
+
id: JsonRpcId;
|
|
820
|
+
result: R;
|
|
821
|
+
}
|
|
822
|
+
interface JsonRpcError {
|
|
823
|
+
jsonrpc: "2.0";
|
|
824
|
+
id: JsonRpcId | null;
|
|
825
|
+
error: {
|
|
826
|
+
/** JSON-RPC standard codes: -32700 parse, -32600 invalid request, -32601 method not found, -32602 invalid params, -32603 internal. MCP also defines its own range. */
|
|
827
|
+
code: number;
|
|
828
|
+
message: string;
|
|
829
|
+
data?: unknown;
|
|
830
|
+
};
|
|
831
|
+
}
|
|
832
|
+
type JsonRpcResponse<R = unknown> = JsonRpcSuccess<R> | JsonRpcError;
|
|
833
|
+
type JsonRpcMessage = JsonRpcRequest | JsonRpcNotification | JsonRpcSuccess | JsonRpcError;
|
|
834
|
+
interface McpClientInfo {
|
|
835
|
+
name: string;
|
|
836
|
+
version: string;
|
|
837
|
+
}
|
|
838
|
+
interface InitializeResult {
|
|
839
|
+
protocolVersion: string;
|
|
840
|
+
serverInfo: {
|
|
841
|
+
name: string;
|
|
842
|
+
version: string;
|
|
843
|
+
};
|
|
844
|
+
capabilities: {
|
|
845
|
+
tools?: {
|
|
846
|
+
listChanged?: boolean;
|
|
847
|
+
};
|
|
848
|
+
resources?: unknown;
|
|
849
|
+
prompts?: unknown;
|
|
850
|
+
};
|
|
851
|
+
instructions?: string;
|
|
852
|
+
}
|
|
853
|
+
interface McpToolSchema {
|
|
854
|
+
/** JSON Schema — compatible with Reasonix's tools.ts JSONSchema shape. */
|
|
855
|
+
type?: string;
|
|
856
|
+
properties?: Record<string, unknown>;
|
|
857
|
+
required?: string[];
|
|
858
|
+
[extra: string]: unknown;
|
|
859
|
+
}
|
|
860
|
+
interface McpTool {
|
|
861
|
+
name: string;
|
|
862
|
+
description?: string;
|
|
863
|
+
/** MCP calls this `inputSchema`. Reasonix's `parameters` field is the same concept. */
|
|
864
|
+
inputSchema: McpToolSchema;
|
|
865
|
+
}
|
|
866
|
+
interface ListToolsResult {
|
|
867
|
+
tools: McpTool[];
|
|
868
|
+
nextCursor?: string;
|
|
869
|
+
}
|
|
870
|
+
interface McpContentBlockText {
|
|
871
|
+
type: "text";
|
|
872
|
+
text: string;
|
|
873
|
+
}
|
|
874
|
+
interface McpContentBlockImage {
|
|
875
|
+
type: "image";
|
|
876
|
+
data: string;
|
|
877
|
+
mimeType: string;
|
|
878
|
+
}
|
|
879
|
+
/** MCP result content is an array of typed blocks. Reasonix consumes only text for now — image blocks get stringified with a placeholder. */
|
|
880
|
+
type McpContentBlock = McpContentBlockText | McpContentBlockImage;
|
|
881
|
+
interface CallToolResult {
|
|
882
|
+
content: McpContentBlock[];
|
|
883
|
+
/** True = tool raised an error; the content describes it. */
|
|
884
|
+
isError?: boolean;
|
|
885
|
+
}
|
|
886
|
+
/** Current MCP protocol version Reasonix is coded against. */
|
|
887
|
+
declare const MCP_PROTOCOL_VERSION = "2024-11-05";
|
|
888
|
+
/** Type guard — success vs error response. */
|
|
889
|
+
declare function isJsonRpcError(msg: JsonRpcResponse): msg is JsonRpcError;
|
|
890
|
+
|
|
891
|
+
/**
|
|
892
|
+
* Stdio transport for MCP.
|
|
893
|
+
*
|
|
894
|
+
* MCP's stdio wire format is **newline-delimited JSON** (one JSON-RPC
|
|
895
|
+
* message per line). We spawn the server as a child process, write
|
|
896
|
+
* frames to its stdin, parse its stdout line-by-line as they arrive.
|
|
897
|
+
*
|
|
898
|
+
* Transport is abstracted behind an interface so unit tests can fake it
|
|
899
|
+
* with an in-process duplex pair — spawning real servers in unit tests
|
|
900
|
+
* is flaky and slow.
|
|
901
|
+
*/
|
|
902
|
+
|
|
903
|
+
/**
|
|
904
|
+
* A transport sends JSON-RPC messages upstream and surfaces messages
|
|
905
|
+
* arriving downstream via an async iterator. One instance per server
|
|
906
|
+
* connection.
|
|
907
|
+
*/
|
|
908
|
+
interface McpTransport {
|
|
909
|
+
/** Send one JSON-RPC message. Resolves when the bytes are accepted. */
|
|
910
|
+
send(message: JsonRpcMessage): Promise<void>;
|
|
911
|
+
/** Async iterator over incoming messages. Ends when the connection closes. */
|
|
912
|
+
messages(): AsyncIterableIterator<JsonRpcMessage>;
|
|
913
|
+
/** Close the underlying resource (kill child process, close streams). */
|
|
914
|
+
close(): Promise<void>;
|
|
915
|
+
}
|
|
916
|
+
interface StdioTransportOptions {
|
|
917
|
+
/** Argv to spawn. First element is the command. */
|
|
918
|
+
command: string;
|
|
919
|
+
args?: string[];
|
|
920
|
+
/** Env overlay — merged over process.env unless replaceEnv=true. */
|
|
921
|
+
env?: Record<string, string>;
|
|
922
|
+
/** When true, only the env above is visible to the child. Default false. */
|
|
923
|
+
replaceEnv?: boolean;
|
|
924
|
+
/** CWD for the child. Default: process.cwd(). */
|
|
925
|
+
cwd?: string;
|
|
926
|
+
}
|
|
927
|
+
/**
|
|
928
|
+
* Spawn `command args...` as a child process and use its stdin/stdout as
|
|
929
|
+
* an MCP transport. Stderr is forwarded to the parent's stderr so server
|
|
930
|
+
* diagnostics are still visible.
|
|
931
|
+
*/
|
|
932
|
+
declare class StdioTransport implements McpTransport {
|
|
933
|
+
private readonly child;
|
|
934
|
+
private readonly queue;
|
|
935
|
+
private readonly waiters;
|
|
936
|
+
private closed;
|
|
937
|
+
private stdoutBuffer;
|
|
938
|
+
constructor(opts: StdioTransportOptions);
|
|
939
|
+
send(message: JsonRpcMessage): Promise<void>;
|
|
940
|
+
messages(): AsyncIterableIterator<JsonRpcMessage>;
|
|
941
|
+
close(): Promise<void>;
|
|
942
|
+
/** Parse incoming stdout chunks into NDJSON messages. */
|
|
943
|
+
private onStdout;
|
|
944
|
+
private onClose;
|
|
945
|
+
private push;
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
/**
|
|
949
|
+
* MCP client — request/response correlation, initialize handshake,
|
|
950
|
+
* tools/list, tools/call. Built on top of a McpTransport so the same
|
|
951
|
+
* logic works against a real stdio server or an in-process fake.
|
|
952
|
+
*/
|
|
953
|
+
|
|
954
|
+
interface McpClientOptions {
|
|
955
|
+
transport: McpTransport;
|
|
956
|
+
clientInfo?: McpClientInfo;
|
|
957
|
+
/** Per-request timeout. Default 60s. */
|
|
958
|
+
requestTimeoutMs?: number;
|
|
959
|
+
}
|
|
960
|
+
declare class McpClient {
|
|
961
|
+
private readonly transport;
|
|
962
|
+
private readonly clientInfo;
|
|
963
|
+
private readonly requestTimeoutMs;
|
|
964
|
+
private readonly pending;
|
|
965
|
+
private nextId;
|
|
966
|
+
private readerStarted;
|
|
967
|
+
private initialized;
|
|
968
|
+
private _serverCapabilities;
|
|
969
|
+
constructor(opts: McpClientOptions);
|
|
970
|
+
/** Server's advertised capabilities, available after initialize(). */
|
|
971
|
+
get serverCapabilities(): InitializeResult["capabilities"];
|
|
972
|
+
/**
|
|
973
|
+
* Complete the initialize → initialized handshake. Must be called
|
|
974
|
+
* before any other method (otherwise compliant servers reject).
|
|
975
|
+
*/
|
|
976
|
+
initialize(): Promise<InitializeResult>;
|
|
977
|
+
/** List tools the server exposes. */
|
|
978
|
+
listTools(): Promise<ListToolsResult>;
|
|
979
|
+
/** Invoke a tool by name. Returns the raw MCP result (caller unwraps content). */
|
|
980
|
+
callTool(name: string, args?: Record<string, unknown>): Promise<CallToolResult>;
|
|
981
|
+
/** Close the transport and reject any outstanding requests. */
|
|
982
|
+
close(): Promise<void>;
|
|
983
|
+
private assertInitialized;
|
|
984
|
+
private request;
|
|
985
|
+
private startReaderIfNeeded;
|
|
986
|
+
private readLoop;
|
|
987
|
+
private dispatch;
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
/**
|
|
991
|
+
* Bridge: register an MCP server's tools into a Reasonix ToolRegistry.
|
|
992
|
+
*
|
|
993
|
+
* This is the integration surface. Once done, `CacheFirstLoop` sees the
|
|
994
|
+
* MCP tools as if they were native — they inherit Cache-First + repair
|
|
995
|
+
* (scavenge / truncation / storm) automatically. That's the payoff: any
|
|
996
|
+
* MCP ecosystem tool, wrapped in Reasonix's Pillar 1 + Pillar 3 benefits.
|
|
997
|
+
*/
|
|
998
|
+
|
|
999
|
+
interface BridgeOptions {
|
|
1000
|
+
/**
|
|
1001
|
+
* Prefix prepended to every MCP tool name when registered. Defaults to
|
|
1002
|
+
* empty (no prefix). Useful when bridging multiple servers into one
|
|
1003
|
+
* registry and names collide — e.g. `fs` + `gh` both exposing `search`.
|
|
1004
|
+
*/
|
|
1005
|
+
namePrefix?: string;
|
|
1006
|
+
/** Registry to populate. Creates a fresh one if omitted. */
|
|
1007
|
+
registry?: ToolRegistry;
|
|
1008
|
+
/** Auto-flatten deep schemas (Pillar 3). Defaults to the registry's own default (true). */
|
|
1009
|
+
autoFlatten?: boolean;
|
|
1010
|
+
}
|
|
1011
|
+
interface BridgeResult {
|
|
1012
|
+
registry: ToolRegistry;
|
|
1013
|
+
/** Names actually registered (may differ from MCP names when a prefix is applied). */
|
|
1014
|
+
registeredNames: string[];
|
|
1015
|
+
/** Names the server listed but the bridge skipped (e.g. invalid schemas). */
|
|
1016
|
+
skipped: Array<{
|
|
1017
|
+
name: string;
|
|
1018
|
+
reason: string;
|
|
1019
|
+
}>;
|
|
1020
|
+
}
|
|
1021
|
+
/**
|
|
1022
|
+
* Walk a connected `McpClient`'s tools/list result, register each into a
|
|
1023
|
+
* Reasonix `ToolRegistry`. Each registered `fn` proxies through the
|
|
1024
|
+
* client's tools/call. Tool results are flattened into a string (joining
|
|
1025
|
+
* text blocks with newlines, prefixing image blocks as placeholders) so
|
|
1026
|
+
* they fit Reasonix's existing tool-dispatch contract.
|
|
1027
|
+
*/
|
|
1028
|
+
declare function bridgeMcpTools(client: McpClient, opts?: BridgeOptions): Promise<BridgeResult>;
|
|
1029
|
+
/**
|
|
1030
|
+
* Turn an MCP CallToolResult into a string — the contract Reasonix's
|
|
1031
|
+
* ToolRegistry.dispatch returns. We:
|
|
1032
|
+
* - join text blocks with newlines (most common case)
|
|
1033
|
+
* - stringify image blocks as placeholders (LLM can't use bytes anyway
|
|
1034
|
+
* in Reasonix's current surface; image support comes with multimodal
|
|
1035
|
+
* prompts later)
|
|
1036
|
+
* - prefix error results with "ERROR: " so the calling model sees the
|
|
1037
|
+
* failure clearly even through JSON mode
|
|
1038
|
+
*/
|
|
1039
|
+
declare function flattenMcpResult(result: CallToolResult): string;
|
|
1040
|
+
|
|
773
1041
|
/**
|
|
774
1042
|
* User-level config storage for the Reasonix CLI.
|
|
775
1043
|
*
|
|
@@ -797,6 +1065,6 @@ declare function redactKey(key: string): string;
|
|
|
797
1065
|
|
|
798
1066
|
/** Reasonix — DeepSeek-native agent framework. Library entry point. */
|
|
799
1067
|
|
|
800
|
-
declare const VERSION = "0.
|
|
1068
|
+
declare const VERSION = "0.3.0-alpha.1";
|
|
801
1069
|
|
|
802
|
-
export { AppendOnlyLog, type BranchOptions, type BranchProgress, type BranchResult, type BranchSample, type BranchSelector, type BranchSummary, CacheFirstLoop, type CacheFirstLoopOptions, type ChatMessage, type ChatResponse, DeepSeekClient, type DeepSeekClientOptions, type RenderOptions as DiffRenderOptions, type DiffReport, type DiffSide, type EventRole, type FlattenDecision, type HarvestOptions, ImmutablePrefix, type ImmutablePrefixOptions, type JSONSchema, type LoopEvent, 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, 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, claudeEquivalentCost, computeReplayStats, costUsd, defaultConfigPath, defaultSelector, deleteSession, diffTranscripts, emptyPlanState, fetchWithRetry, flattenSchema, harvest, isPlanStateEmpty, isPlausibleKey, listSessions, loadApiKey, loadDotenv, loadSessionMessages, nestArguments, openTranscriptFile, parseTranscript, readConfig, readTranscript, recordFromLoopEvent, redactKey, renderMarkdown as renderDiffMarkdown, renderSummaryTable as renderDiffSummary, repairTruncatedJson, replayFromFile, runBranches, sanitizeName as sanitizeSessionName, saveApiKey, scavengeToolCalls, sessionPath, sessionsDir, similarity, writeConfig, writeMeta, writeRecord };
|
|
1070
|
+
export { AppendOnlyLog, type BranchOptions, type BranchProgress, type BranchResult, type BranchSample, type BranchSelector, type BranchSummary, type BridgeOptions, type BridgeResult, CacheFirstLoop, type CacheFirstLoopOptions, type CallToolResult, type ChatMessage, type ChatResponse, DeepSeekClient, type DeepSeekClientOptions, type RenderOptions as DiffRenderOptions, type DiffReport, type DiffSide, type EventRole, type FlattenDecision, type HarvestOptions, ImmutablePrefix, type ImmutablePrefixOptions, type InitializeResult, type JSONSchema, type JsonRpcMessage, type JsonRpcRequest, type JsonRpcResponse, type ListToolsResult, type LoopEvent, MCP_PROTOCOL_VERSION, McpClient, type McpClientOptions, type McpContentBlock, type McpTool, type McpToolSchema, type McpTransport, 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, 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, bridgeMcpTools, claudeEquivalentCost, computeReplayStats, costUsd, defaultConfigPath, defaultSelector, deleteSession, diffTranscripts, emptyPlanState, fetchWithRetry, flattenMcpResult, flattenSchema, harvest, isJsonRpcError, isPlanStateEmpty, isPlausibleKey, listSessions, loadApiKey, loadDotenv, loadSessionMessages, nestArguments, openTranscriptFile, parseTranscript, readConfig, readTranscript, recordFromLoopEvent, redactKey, renderMarkdown as renderDiffMarkdown, renderSummaryTable as renderDiffSummary, repairTruncatedJson, replayFromFile, runBranches, sanitizeName as sanitizeSessionName, saveApiKey, scavengeToolCalls, sessionPath, sessionsDir, similarity, writeConfig, writeMeta, writeRecord };
|