midas-mcp 5.23.0 → 5.43.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/dist/analyzer.d.ts.map +1 -1
- package/dist/analyzer.js +9 -2
- package/dist/analyzer.js.map +1 -1
- package/dist/context.d.ts +264 -5
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +634 -7
- package/dist/context.js.map +1 -1
- package/dist/experiments/recursive-planning/recursive-session.d.ts +201 -0
- package/dist/experiments/recursive-planning/recursive-session.d.ts.map +1 -0
- package/dist/experiments/recursive-planning/recursive-session.js +348 -0
- package/dist/experiments/recursive-planning/recursive-session.js.map +1 -0
- package/dist/experiments/recursive-planning/recursive-session.test.d.ts +19 -0
- package/dist/experiments/recursive-planning/recursive-session.test.d.ts.map +1 -0
- package/dist/experiments/recursive-planning/recursive-session.test.js +799 -0
- package/dist/experiments/recursive-planning/recursive-session.test.js.map +1 -0
- package/dist/gameplan-tracker.d.ts +63 -0
- package/dist/gameplan-tracker.d.ts.map +1 -0
- package/dist/gameplan-tracker.js +330 -0
- package/dist/gameplan-tracker.js.map +1 -0
- package/dist/preflight.d.ts +140 -0
- package/dist/preflight.d.ts.map +1 -0
- package/dist/preflight.js +1100 -0
- package/dist/preflight.js.map +1 -0
- package/dist/security.d.ts.map +1 -1
- package/dist/security.js +22 -2
- package/dist/security.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +9 -4
- package/dist/server.js.map +1 -1
- package/dist/state/phase.d.ts.map +1 -1
- package/dist/state/phase.js +58 -8
- package/dist/state/phase.js.map +1 -1
- package/dist/tools/gameplan.d.ts +49 -0
- package/dist/tools/gameplan.d.ts.map +1 -0
- package/dist/tools/gameplan.js +79 -0
- package/dist/tools/gameplan.js.map +1 -0
- package/dist/tools/index.d.ts +2 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +6 -2
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/preflight.d.ts +121 -0
- package/dist/tools/preflight.d.ts.map +1 -0
- package/dist/tools/preflight.js +144 -0
- package/dist/tools/preflight.js.map +1 -0
- package/dist/tools/verify.js +2 -2
- package/dist/tools/verify.js.map +1 -1
- package/dist/tracker.d.ts.map +1 -1
- package/dist/tracker.js +38 -2
- package/dist/tracker.js.map +1 -1
- package/dist/tui.js +53 -53
- package/dist/tui.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursive Planning Session
|
|
3
|
+
*
|
|
4
|
+
* TRM-inspired recursive refinement for AI-assisted development.
|
|
5
|
+
*
|
|
6
|
+
* Based on "Less is More: Recursive Reasoning with Tiny Networks" (Jolicoeur-Martineau, 2025)
|
|
7
|
+
*
|
|
8
|
+
* Core concepts:
|
|
9
|
+
* - x: input/requirements (stable across iterations)
|
|
10
|
+
* - z: latent reasoning state (accumulated learning, chain-of-thought)
|
|
11
|
+
* - y: current answer/implementation state
|
|
12
|
+
*
|
|
13
|
+
* Key patterns:
|
|
14
|
+
* 1. Deep supervision: multiple refinement iterations (Nsup=16 default)
|
|
15
|
+
* 2. Recursive z refinement: reasoning improves with each cycle
|
|
16
|
+
* 3. Answer refinement: y improves given z
|
|
17
|
+
* 4. Adaptive halting: stop when correct, don't waste iterations
|
|
18
|
+
* 5. State persistence: z carries forward, preventing "forgetting"
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* A single iteration snapshot
|
|
22
|
+
*/
|
|
23
|
+
export interface IterationSnapshot {
|
|
24
|
+
iteration: number;
|
|
25
|
+
z: string;
|
|
26
|
+
y: string;
|
|
27
|
+
confidence: number;
|
|
28
|
+
duration?: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Session state - the core x, y, z from TRM
|
|
32
|
+
*/
|
|
33
|
+
export interface SessionState {
|
|
34
|
+
/** x: Input requirements/context (stable) */
|
|
35
|
+
x: string;
|
|
36
|
+
/** y: Current answer/implementation */
|
|
37
|
+
y: string;
|
|
38
|
+
/** z: Latent reasoning (accumulated) */
|
|
39
|
+
z: string;
|
|
40
|
+
/** Current iteration number */
|
|
41
|
+
iteration: number;
|
|
42
|
+
/** Whether session has halted */
|
|
43
|
+
halted: boolean;
|
|
44
|
+
/** Reason for halting (if halted) */
|
|
45
|
+
haltReason: string | null;
|
|
46
|
+
/** History of all iterations */
|
|
47
|
+
history: IterationSnapshot[];
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Session configuration
|
|
51
|
+
*/
|
|
52
|
+
export interface SessionConfig {
|
|
53
|
+
/** Maximum iterations (Nsup in TRM, default 16) */
|
|
54
|
+
maxIterations: number;
|
|
55
|
+
/** Number of latent recursions per iteration (T in TRM, default 1) */
|
|
56
|
+
latentRecursions: number;
|
|
57
|
+
/** Project path for persistence */
|
|
58
|
+
projectPath: string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Full session object
|
|
62
|
+
*/
|
|
63
|
+
export interface RecursiveSession {
|
|
64
|
+
id: string;
|
|
65
|
+
state: SessionState;
|
|
66
|
+
config: SessionConfig;
|
|
67
|
+
createdAt: number;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Halt decision
|
|
71
|
+
*/
|
|
72
|
+
export interface HaltDecision {
|
|
73
|
+
shouldHalt: boolean;
|
|
74
|
+
confidence: number;
|
|
75
|
+
reason: string;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Refinement result
|
|
79
|
+
*/
|
|
80
|
+
export interface RefinementResult {
|
|
81
|
+
z: string;
|
|
82
|
+
duration: number;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Answer refinement result
|
|
86
|
+
*/
|
|
87
|
+
export interface AnswerRefinementResult {
|
|
88
|
+
y: string;
|
|
89
|
+
duration: number;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Iteration result
|
|
93
|
+
*/
|
|
94
|
+
export interface IterationResult {
|
|
95
|
+
state: SessionState;
|
|
96
|
+
duration: number;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Session run result
|
|
100
|
+
*/
|
|
101
|
+
export interface SessionRunResult {
|
|
102
|
+
session: RecursiveSession;
|
|
103
|
+
state: SessionState;
|
|
104
|
+
totalDuration: number;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Refiner function types
|
|
108
|
+
*/
|
|
109
|
+
export type ReasoningRefiner = (x: string, y: string, z: string) => string;
|
|
110
|
+
export type AnswerRefiner = (y: string, z: string) => string;
|
|
111
|
+
export type HaltChecker = (x: string, y: string, z: string) => HaltDecision;
|
|
112
|
+
/**
|
|
113
|
+
* Session refiners configuration
|
|
114
|
+
*/
|
|
115
|
+
export interface SessionRefiners {
|
|
116
|
+
reasoningRefiner: ReasoningRefiner;
|
|
117
|
+
answerRefiner: AnswerRefiner;
|
|
118
|
+
haltChecker: HaltChecker;
|
|
119
|
+
latentRecursions?: number;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Create a new recursive session
|
|
123
|
+
*/
|
|
124
|
+
export declare function createSession(options: {
|
|
125
|
+
x: string;
|
|
126
|
+
y?: string;
|
|
127
|
+
z?: string;
|
|
128
|
+
projectPath: string;
|
|
129
|
+
maxIterations?: number;
|
|
130
|
+
latentRecursions?: number;
|
|
131
|
+
resume?: boolean;
|
|
132
|
+
}): RecursiveSession;
|
|
133
|
+
/**
|
|
134
|
+
* Serialize session state to JSON
|
|
135
|
+
*/
|
|
136
|
+
export declare function serializeState(state: SessionState): string;
|
|
137
|
+
/**
|
|
138
|
+
* Deserialize session state from JSON
|
|
139
|
+
*/
|
|
140
|
+
export declare function deserializeState(json: string): SessionState;
|
|
141
|
+
/**
|
|
142
|
+
* Refine reasoning (z) given x, y, and current z
|
|
143
|
+
*
|
|
144
|
+
* This is the core "latent recursion" from TRM:
|
|
145
|
+
* z = net(x, y, z)
|
|
146
|
+
*/
|
|
147
|
+
export declare function refineReasoning(options: {
|
|
148
|
+
x: string;
|
|
149
|
+
y: string;
|
|
150
|
+
z: string;
|
|
151
|
+
refiner: ReasoningRefiner;
|
|
152
|
+
}): RefinementResult;
|
|
153
|
+
/**
|
|
154
|
+
* Refine answer (y) given current y and z
|
|
155
|
+
*
|
|
156
|
+
* This is the answer update from TRM:
|
|
157
|
+
* y = net(y, z)
|
|
158
|
+
*/
|
|
159
|
+
export declare function refineAnswer(options: {
|
|
160
|
+
y: string;
|
|
161
|
+
z: string;
|
|
162
|
+
refiner: AnswerRefiner;
|
|
163
|
+
}): AnswerRefinementResult;
|
|
164
|
+
/**
|
|
165
|
+
* Merge old and new reasoning, with length cap
|
|
166
|
+
*/
|
|
167
|
+
export declare function mergeReasoning(oldZ: string, newZ: string): string;
|
|
168
|
+
/**
|
|
169
|
+
* Check if session should halt
|
|
170
|
+
*/
|
|
171
|
+
export declare function checkHalt(options: {
|
|
172
|
+
x: string;
|
|
173
|
+
y: string;
|
|
174
|
+
z: string;
|
|
175
|
+
iteration?: number;
|
|
176
|
+
maxIterations?: number;
|
|
177
|
+
checker: HaltChecker;
|
|
178
|
+
}): HaltDecision;
|
|
179
|
+
/**
|
|
180
|
+
* Calculate confidence based on state
|
|
181
|
+
*/
|
|
182
|
+
export declare function calculateConfidence(x: string, y: string, z: string): number;
|
|
183
|
+
/**
|
|
184
|
+
* Run a single iteration of the recursive refinement loop
|
|
185
|
+
*
|
|
186
|
+
* Pattern from TRM:
|
|
187
|
+
* 1. Refine z (latent reasoning) - potentially T times
|
|
188
|
+
* 2. Refine y (answer) based on z
|
|
189
|
+
* 3. Check if should halt
|
|
190
|
+
*/
|
|
191
|
+
export declare function runIteration(state: SessionState, refiners: SessionRefiners): IterationResult;
|
|
192
|
+
/**
|
|
193
|
+
* Run a full recursive session until halt
|
|
194
|
+
*
|
|
195
|
+
* This implements the "deep supervision" loop from TRM:
|
|
196
|
+
* for step in range(N_supervision):
|
|
197
|
+
* z, y = refine(x, y, z)
|
|
198
|
+
* if should_halt: break
|
|
199
|
+
*/
|
|
200
|
+
export declare function runSession(session: RecursiveSession, refiners: SessionRefiners): SessionRunResult;
|
|
201
|
+
//# sourceMappingURL=recursive-session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recursive-session.d.ts","sourceRoot":"","sources":["../../../src/experiments/recursive-planning/recursive-session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAUH;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,6CAA6C;IAC7C,CAAC,EAAE,MAAM,CAAC;IACV,uCAAuC;IACvC,CAAC,EAAE,MAAM,CAAC;IACV,wCAAwC;IACxC,CAAC,EAAE,MAAM,CAAC;IACV,+BAA+B;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,iCAAiC;IACjC,MAAM,EAAE,OAAO,CAAC;IAChB,qCAAqC;IACrC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,gCAAgC;IAChC,OAAO,EAAE,iBAAiB,EAAE,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,mDAAmD;IACnD,aAAa,EAAE,MAAM,CAAC;IACtB,sEAAsE;IACtE,gBAAgB,EAAE,MAAM,CAAC;IACzB,mCAAmC;IACnC,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,YAAY,CAAC;IACpB,MAAM,EAAE,aAAa,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;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,EAAE,YAAY,EACnB,QAAQ,EAAE,eAAe,GACxB,eAAe,CAiEjB;AAMD;;;;;;;GAOG;AACH,wBAAgB,UAAU,CACxB,OAAO,EAAE,gBAAgB,EACzB,QAAQ,EAAE,eAAe,GACxB,gBAAgB,CAgDlB"}
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursive Planning Session
|
|
3
|
+
*
|
|
4
|
+
* TRM-inspired recursive refinement for AI-assisted development.
|
|
5
|
+
*
|
|
6
|
+
* Based on "Less is More: Recursive Reasoning with Tiny Networks" (Jolicoeur-Martineau, 2025)
|
|
7
|
+
*
|
|
8
|
+
* Core concepts:
|
|
9
|
+
* - x: input/requirements (stable across iterations)
|
|
10
|
+
* - z: latent reasoning state (accumulated learning, chain-of-thought)
|
|
11
|
+
* - y: current answer/implementation state
|
|
12
|
+
*
|
|
13
|
+
* Key patterns:
|
|
14
|
+
* 1. Deep supervision: multiple refinement iterations (Nsup=16 default)
|
|
15
|
+
* 2. Recursive z refinement: reasoning improves with each cycle
|
|
16
|
+
* 3. Answer refinement: y improves given z
|
|
17
|
+
* 4. Adaptive halting: stop when correct, don't waste iterations
|
|
18
|
+
* 5. State persistence: z carries forward, preventing "forgetting"
|
|
19
|
+
*/
|
|
20
|
+
import { existsSync, mkdirSync, readFileSync } from 'fs';
|
|
21
|
+
import writeFileAtomic from 'write-file-atomic';
|
|
22
|
+
import { join } from 'path';
|
|
23
|
+
// ============================================================================
|
|
24
|
+
// CONSTANTS
|
|
25
|
+
// ============================================================================
|
|
26
|
+
const MIDAS_DIR = '.midas';
|
|
27
|
+
const SESSION_FILE = 'recursive-session.json';
|
|
28
|
+
const MAX_REASONING_LENGTH = 8000;
|
|
29
|
+
const DEFAULT_MAX_ITERATIONS = 16; // Nsup from TRM paper
|
|
30
|
+
const DEFAULT_LATENT_RECURSIONS = 1; // T from TRM paper (simplified default)
|
|
31
|
+
// ============================================================================
|
|
32
|
+
// SESSION CREATION
|
|
33
|
+
// ============================================================================
|
|
34
|
+
/**
|
|
35
|
+
* Generate unique session ID
|
|
36
|
+
*/
|
|
37
|
+
function generateSessionId() {
|
|
38
|
+
return `session_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Create a new recursive session
|
|
42
|
+
*/
|
|
43
|
+
export function createSession(options) {
|
|
44
|
+
const { x, y = '', z = '', projectPath, maxIterations = DEFAULT_MAX_ITERATIONS, latentRecursions = DEFAULT_LATENT_RECURSIONS, resume = false, } = options;
|
|
45
|
+
// Try to resume from disk if requested
|
|
46
|
+
if (resume) {
|
|
47
|
+
const existingState = loadSessionState(projectPath);
|
|
48
|
+
if (existingState && existingState.x === x) {
|
|
49
|
+
return {
|
|
50
|
+
id: generateSessionId(),
|
|
51
|
+
state: existingState,
|
|
52
|
+
config: {
|
|
53
|
+
maxIterations,
|
|
54
|
+
latentRecursions,
|
|
55
|
+
projectPath,
|
|
56
|
+
},
|
|
57
|
+
createdAt: Date.now(),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
id: generateSessionId(),
|
|
63
|
+
state: {
|
|
64
|
+
x,
|
|
65
|
+
y,
|
|
66
|
+
z,
|
|
67
|
+
iteration: 0,
|
|
68
|
+
halted: false,
|
|
69
|
+
haltReason: null,
|
|
70
|
+
history: [],
|
|
71
|
+
},
|
|
72
|
+
config: {
|
|
73
|
+
maxIterations,
|
|
74
|
+
latentRecursions,
|
|
75
|
+
projectPath,
|
|
76
|
+
},
|
|
77
|
+
createdAt: Date.now(),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
// ============================================================================
|
|
81
|
+
// STATE SERIALIZATION
|
|
82
|
+
// ============================================================================
|
|
83
|
+
/**
|
|
84
|
+
* Serialize session state to JSON
|
|
85
|
+
*/
|
|
86
|
+
export function serializeState(state) {
|
|
87
|
+
return JSON.stringify(state, null, 2);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Deserialize session state from JSON
|
|
91
|
+
*/
|
|
92
|
+
export function deserializeState(json) {
|
|
93
|
+
try {
|
|
94
|
+
const data = JSON.parse(json);
|
|
95
|
+
return {
|
|
96
|
+
x: data.x ?? '',
|
|
97
|
+
y: data.y ?? '',
|
|
98
|
+
z: data.z ?? '',
|
|
99
|
+
iteration: data.iteration ?? 0,
|
|
100
|
+
halted: data.halted ?? false,
|
|
101
|
+
haltReason: data.haltReason ?? null,
|
|
102
|
+
history: data.history ?? [],
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
return {
|
|
107
|
+
x: '',
|
|
108
|
+
y: '',
|
|
109
|
+
z: '',
|
|
110
|
+
iteration: 0,
|
|
111
|
+
halted: false,
|
|
112
|
+
haltReason: null,
|
|
113
|
+
history: [],
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Save session state to disk
|
|
119
|
+
*/
|
|
120
|
+
function saveSessionState(projectPath, state) {
|
|
121
|
+
try {
|
|
122
|
+
const dir = join(projectPath, MIDAS_DIR);
|
|
123
|
+
if (!existsSync(dir)) {
|
|
124
|
+
mkdirSync(dir, { recursive: true });
|
|
125
|
+
}
|
|
126
|
+
const path = join(dir, SESSION_FILE);
|
|
127
|
+
writeFileAtomic.sync(path, serializeState(state));
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
// Ignore save errors
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Load session state from disk
|
|
135
|
+
*/
|
|
136
|
+
function loadSessionState(projectPath) {
|
|
137
|
+
try {
|
|
138
|
+
const path = join(projectPath, MIDAS_DIR, SESSION_FILE);
|
|
139
|
+
if (!existsSync(path))
|
|
140
|
+
return null;
|
|
141
|
+
const json = readFileSync(path, 'utf-8');
|
|
142
|
+
return deserializeState(json);
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
// ============================================================================
|
|
149
|
+
// REFINEMENT FUNCTIONS
|
|
150
|
+
// ============================================================================
|
|
151
|
+
/**
|
|
152
|
+
* Refine reasoning (z) given x, y, and current z
|
|
153
|
+
*
|
|
154
|
+
* This is the core "latent recursion" from TRM:
|
|
155
|
+
* z = net(x, y, z)
|
|
156
|
+
*/
|
|
157
|
+
export function refineReasoning(options) {
|
|
158
|
+
const { x, y, z, refiner } = options;
|
|
159
|
+
const start = Date.now();
|
|
160
|
+
const newZ = refiner(x, y, z);
|
|
161
|
+
return {
|
|
162
|
+
z: newZ,
|
|
163
|
+
duration: Date.now() - start,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Refine answer (y) given current y and z
|
|
168
|
+
*
|
|
169
|
+
* This is the answer update from TRM:
|
|
170
|
+
* y = net(y, z)
|
|
171
|
+
*/
|
|
172
|
+
export function refineAnswer(options) {
|
|
173
|
+
const { y, z, refiner } = options;
|
|
174
|
+
const start = Date.now();
|
|
175
|
+
const newY = refiner(y, z);
|
|
176
|
+
return {
|
|
177
|
+
y: newY,
|
|
178
|
+
duration: Date.now() - start,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Merge old and new reasoning, with length cap
|
|
183
|
+
*/
|
|
184
|
+
export function mergeReasoning(oldZ, newZ) {
|
|
185
|
+
if (!oldZ)
|
|
186
|
+
return newZ;
|
|
187
|
+
if (!newZ)
|
|
188
|
+
return oldZ;
|
|
189
|
+
const merged = `${oldZ}\n${newZ}`;
|
|
190
|
+
// Cap length to prevent unbounded growth
|
|
191
|
+
if (merged.length > MAX_REASONING_LENGTH) {
|
|
192
|
+
// Keep the most recent reasoning (tail)
|
|
193
|
+
return merged.slice(-MAX_REASONING_LENGTH);
|
|
194
|
+
}
|
|
195
|
+
return merged;
|
|
196
|
+
}
|
|
197
|
+
// ============================================================================
|
|
198
|
+
// HALTING
|
|
199
|
+
// ============================================================================
|
|
200
|
+
/**
|
|
201
|
+
* Check if session should halt
|
|
202
|
+
*/
|
|
203
|
+
export function checkHalt(options) {
|
|
204
|
+
const { x, y, z, iteration = 0, maxIterations = 16, checker } = options;
|
|
205
|
+
// Force halt at max iterations
|
|
206
|
+
if (iteration >= maxIterations) {
|
|
207
|
+
return {
|
|
208
|
+
shouldHalt: true,
|
|
209
|
+
confidence: calculateConfidence(x, y, z),
|
|
210
|
+
reason: `Reached max iterations (${maxIterations})`,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
return checker(x, y, z);
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Calculate confidence based on state
|
|
217
|
+
*/
|
|
218
|
+
export function calculateConfidence(x, y, z) {
|
|
219
|
+
if (!y)
|
|
220
|
+
return 0;
|
|
221
|
+
// Simple heuristic: more reasoning iterations = higher confidence
|
|
222
|
+
const iterations = (z.match(/iteration:/g) || []).length;
|
|
223
|
+
// Base confidence + iteration bonus, capped at 100
|
|
224
|
+
const base = 20;
|
|
225
|
+
const iterationBonus = iterations * 15;
|
|
226
|
+
return Math.min(100, base + iterationBonus);
|
|
227
|
+
}
|
|
228
|
+
// ============================================================================
|
|
229
|
+
// ITERATION
|
|
230
|
+
// ============================================================================
|
|
231
|
+
/**
|
|
232
|
+
* Run a single iteration of the recursive refinement loop
|
|
233
|
+
*
|
|
234
|
+
* Pattern from TRM:
|
|
235
|
+
* 1. Refine z (latent reasoning) - potentially T times
|
|
236
|
+
* 2. Refine y (answer) based on z
|
|
237
|
+
* 3. Check if should halt
|
|
238
|
+
*/
|
|
239
|
+
export function runIteration(state, refiners) {
|
|
240
|
+
const { reasoningRefiner, answerRefiner, haltChecker, latentRecursions = DEFAULT_LATENT_RECURSIONS, } = refiners;
|
|
241
|
+
const start = Date.now();
|
|
242
|
+
// Clone state to avoid mutation
|
|
243
|
+
let newState = {
|
|
244
|
+
...state,
|
|
245
|
+
history: [...state.history],
|
|
246
|
+
};
|
|
247
|
+
// Step 1: Refine z (latent reasoning) - T times
|
|
248
|
+
let currentZ = newState.z;
|
|
249
|
+
for (let t = 0; t < latentRecursions; t++) {
|
|
250
|
+
const result = refineReasoning({
|
|
251
|
+
x: newState.x,
|
|
252
|
+
y: newState.y,
|
|
253
|
+
z: currentZ,
|
|
254
|
+
refiner: reasoningRefiner,
|
|
255
|
+
});
|
|
256
|
+
currentZ = result.z;
|
|
257
|
+
}
|
|
258
|
+
newState.z = currentZ;
|
|
259
|
+
// Step 2: Refine y (answer) based on z
|
|
260
|
+
const answerResult = refineAnswer({
|
|
261
|
+
y: newState.y,
|
|
262
|
+
z: newState.z,
|
|
263
|
+
refiner: answerRefiner,
|
|
264
|
+
});
|
|
265
|
+
newState.y = answerResult.y;
|
|
266
|
+
// Step 3: Increment iteration and record history
|
|
267
|
+
newState.iteration++;
|
|
268
|
+
const confidence = calculateConfidence(newState.x, newState.y, newState.z);
|
|
269
|
+
newState.history.push({
|
|
270
|
+
iteration: newState.iteration,
|
|
271
|
+
z: newState.z,
|
|
272
|
+
y: newState.y,
|
|
273
|
+
confidence,
|
|
274
|
+
});
|
|
275
|
+
// Step 4: Check halt condition
|
|
276
|
+
const haltDecision = checkHalt({
|
|
277
|
+
x: newState.x,
|
|
278
|
+
y: newState.y,
|
|
279
|
+
z: newState.z,
|
|
280
|
+
iteration: newState.iteration,
|
|
281
|
+
checker: haltChecker,
|
|
282
|
+
});
|
|
283
|
+
if (haltDecision.shouldHalt) {
|
|
284
|
+
newState.halted = true;
|
|
285
|
+
newState.haltReason = haltDecision.reason;
|
|
286
|
+
}
|
|
287
|
+
return {
|
|
288
|
+
state: newState,
|
|
289
|
+
duration: Date.now() - start,
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
// ============================================================================
|
|
293
|
+
// FULL SESSION RUN
|
|
294
|
+
// ============================================================================
|
|
295
|
+
/**
|
|
296
|
+
* Run a full recursive session until halt
|
|
297
|
+
*
|
|
298
|
+
* This implements the "deep supervision" loop from TRM:
|
|
299
|
+
* for step in range(N_supervision):
|
|
300
|
+
* z, y = refine(x, y, z)
|
|
301
|
+
* if should_halt: break
|
|
302
|
+
*/
|
|
303
|
+
export function runSession(session, refiners) {
|
|
304
|
+
const start = Date.now();
|
|
305
|
+
let currentState = { ...session.state };
|
|
306
|
+
// Handle zero or negative maxIterations
|
|
307
|
+
if (session.config.maxIterations <= 0) {
|
|
308
|
+
currentState.halted = true;
|
|
309
|
+
currentState.haltReason = 'maxIterations is 0';
|
|
310
|
+
saveSessionState(session.config.projectPath, currentState);
|
|
311
|
+
return {
|
|
312
|
+
session,
|
|
313
|
+
state: currentState,
|
|
314
|
+
totalDuration: Date.now() - start,
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
// Deep supervision loop
|
|
318
|
+
while (!currentState.halted && currentState.iteration < session.config.maxIterations) {
|
|
319
|
+
try {
|
|
320
|
+
const result = runIteration(currentState, {
|
|
321
|
+
...refiners,
|
|
322
|
+
latentRecursions: refiners.latentRecursions ?? session.config.latentRecursions,
|
|
323
|
+
});
|
|
324
|
+
currentState = result.state;
|
|
325
|
+
}
|
|
326
|
+
catch (error) {
|
|
327
|
+
// Handle refiner errors gracefully
|
|
328
|
+
currentState.halted = true;
|
|
329
|
+
currentState.haltReason = `Refinement error: ${error instanceof Error ? error.message : 'unknown'}`;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
// Ensure halted at max iterations
|
|
333
|
+
if (!currentState.halted && currentState.iteration >= session.config.maxIterations) {
|
|
334
|
+
currentState.halted = true;
|
|
335
|
+
currentState.haltReason = `Reached max iterations (${session.config.maxIterations})`;
|
|
336
|
+
}
|
|
337
|
+
// Persist state
|
|
338
|
+
saveSessionState(session.config.projectPath, currentState);
|
|
339
|
+
return {
|
|
340
|
+
session: {
|
|
341
|
+
...session,
|
|
342
|
+
state: currentState,
|
|
343
|
+
},
|
|
344
|
+
state: currentState,
|
|
345
|
+
totalDuration: Date.now() - start,
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
//# sourceMappingURL=recursive-session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recursive-session.js","sourceRoot":"","sources":["../../../src/experiments/recursive-planning/recursive-session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AACzD,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAsH5B,+EAA+E;AAC/E,YAAY;AACZ,+EAA+E;AAE/E,MAAM,SAAS,GAAG,QAAQ,CAAC;AAC3B,MAAM,YAAY,GAAG,wBAAwB,CAAC;AAC9C,MAAM,oBAAoB,GAAG,IAAI,CAAC;AAClC,MAAM,sBAAsB,GAAG,EAAE,CAAC,CAAE,sBAAsB;AAC1D,MAAM,yBAAyB,GAAG,CAAC,CAAC,CAAE,wCAAwC;AAE9E,+EAA+E;AAC/E,mBAAmB;AACnB,+EAA+E;AAE/E;;GAEG;AACH,SAAS,iBAAiB;IACxB,OAAO,WAAW,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;AACxF,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,OAQ7B;IACC,MAAM,EACJ,CAAC,EACD,CAAC,GAAG,EAAE,EACN,CAAC,GAAG,EAAE,EACN,WAAW,EACX,aAAa,GAAG,sBAAsB,EACtC,gBAAgB,GAAG,yBAAyB,EAC5C,MAAM,GAAG,KAAK,GACf,GAAG,OAAO,CAAC;IAEZ,uCAAuC;IACvC,IAAI,MAAM,EAAE,CAAC;QACX,MAAM,aAAa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,CAAC,gBAAgB;aAC/E,CAAC,CAAC;YACH,YAAY,GAAG,MAAM,CAAC,KAAK,CAAC;QAC9B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,mCAAmC;YACnC,YAAY,CAAC,MAAM,GAAG,IAAI,CAAC;YAC3B,YAAY,CAAC,UAAU,GAAG,qBAAqB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;QACtG,CAAC;IACH,CAAC;IAED,kCAAkC;IAClC,IAAI,CAAC,YAAY,CAAC,MAAM,IAAI,YAAY,CAAC,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC;QACnF,YAAY,CAAC,MAAM,GAAG,IAAI,CAAC;QAC3B,YAAY,CAAC,UAAU,GAAG,2BAA2B,OAAO,CAAC,MAAM,CAAC,aAAa,GAAG,CAAC;IACvF,CAAC;IAED,gBAAgB;IAChB,gBAAgB,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;IAE3D,OAAO;QACL,OAAO,EAAE;YACP,GAAG,OAAO;YACV,KAAK,EAAE,YAAY;SACpB;QACD,KAAK,EAAE,YAAY;QACnB,aAAa,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK;KAClC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursive Planning Session - Tests
|
|
3
|
+
*
|
|
4
|
+
* TDD-first implementation of TRM-inspired recursive planning.
|
|
5
|
+
*
|
|
6
|
+
* Core concepts from the TRM paper:
|
|
7
|
+
* - x: input/requirements (stable across iterations)
|
|
8
|
+
* - z: latent reasoning state (accumulated learning, like chain-of-thought)
|
|
9
|
+
* - y: current answer/implementation state
|
|
10
|
+
*
|
|
11
|
+
* Key behaviors:
|
|
12
|
+
* 1. Deep supervision: multiple refinement iterations
|
|
13
|
+
* 2. Recursive z refinement: reasoning improves with each cycle
|
|
14
|
+
* 3. Answer refinement: y improves given z
|
|
15
|
+
* 4. Adaptive halting: stop when correct, don't waste iterations
|
|
16
|
+
* 5. State persistence: z carries forward, preventing "forgetting"
|
|
17
|
+
*/
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=recursive-session.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recursive-session.test.d.ts","sourceRoot":"","sources":["../../../src/experiments/recursive-planning/recursive-session.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG"}
|