@yuaone/core 0.6.1 → 0.7.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/agent-loop.d.ts +38 -0
- package/dist/agent-loop.d.ts.map +1 -1
- package/dist/agent-loop.js +532 -117
- package/dist/agent-loop.js.map +1 -1
- package/dist/code-indexer.d.ts +50 -0
- package/dist/code-indexer.d.ts.map +1 -0
- package/dist/code-indexer.js +199 -0
- package/dist/code-indexer.js.map +1 -0
- package/dist/failure-recovery.d.ts +15 -2
- package/dist/failure-recovery.d.ts.map +1 -1
- package/dist/failure-recovery.js +53 -2
- package/dist/failure-recovery.js.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/llm-client.d.ts +20 -2
- package/dist/llm-client.d.ts.map +1 -1
- package/dist/llm-client.js +213 -8
- package/dist/llm-client.js.map +1 -1
- package/dist/llm-orchestrator.d.ts +74 -0
- package/dist/llm-orchestrator.d.ts.map +1 -0
- package/dist/llm-orchestrator.js +144 -0
- package/dist/llm-orchestrator.js.map +1 -0
- package/dist/planner/index.d.ts +9 -0
- package/dist/planner/index.d.ts.map +1 -0
- package/dist/planner/index.js +5 -0
- package/dist/planner/index.js.map +1 -0
- package/dist/planner/milestone-checker.d.ts +48 -0
- package/dist/planner/milestone-checker.d.ts.map +1 -0
- package/dist/planner/milestone-checker.js +113 -0
- package/dist/planner/milestone-checker.js.map +1 -0
- package/dist/planner/plan-evaluator.d.ts +35 -0
- package/dist/planner/plan-evaluator.d.ts.map +1 -0
- package/dist/planner/plan-evaluator.js +92 -0
- package/dist/planner/plan-evaluator.js.map +1 -0
- package/dist/planner/replanning-engine.d.ts +37 -0
- package/dist/planner/replanning-engine.d.ts.map +1 -0
- package/dist/planner/replanning-engine.js +130 -0
- package/dist/planner/replanning-engine.js.map +1 -0
- package/dist/planner/risk-estimator.d.ts +44 -0
- package/dist/planner/risk-estimator.d.ts.map +1 -0
- package/dist/planner/risk-estimator.js +108 -0
- package/dist/planner/risk-estimator.js.map +1 -0
- package/dist/types.d.ts +12 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/world-model/index.d.ts +8 -0
- package/dist/world-model/index.d.ts.map +1 -0
- package/dist/world-model/index.js +5 -0
- package/dist/world-model/index.js.map +1 -0
- package/dist/world-model/simulation-engine.d.ts +58 -0
- package/dist/world-model/simulation-engine.d.ts.map +1 -0
- package/dist/world-model/simulation-engine.js +191 -0
- package/dist/world-model/simulation-engine.js.map +1 -0
- package/dist/world-model/state-store.d.ts +149 -0
- package/dist/world-model/state-store.d.ts.map +1 -0
- package/dist/world-model/state-store.js +379 -0
- package/dist/world-model/state-store.js.map +1 -0
- package/dist/world-model/state-updater.d.ts +35 -0
- package/dist/world-model/state-updater.d.ts.map +1 -0
- package/dist/world-model/state-updater.js +131 -0
- package/dist/world-model/state-updater.js.map +1 -0
- package/dist/world-model/transition-model.d.ts +54 -0
- package/dist/world-model/transition-model.d.ts.map +1 -0
- package/dist/world-model/transition-model.js +240 -0
- package/dist/world-model/transition-model.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-store.d.ts","sourceRoot":"","sources":["../../src/world-model/state-store.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAI5D,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;IAChB,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,CAAC;IAChD,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,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AAC;QAAC,MAAM,EAAE,SAAS,GAAG,SAAS,CAAC;QAAC,KAAK,EAAE,SAAS,CAAA;KAAE,CAAC;IAqB7E,0DAA0D;IAC1D,cAAc,IAAI,WAAW;IAmB7B;;;;OAIG;IACH,YAAY,CAAC,QAAQ,SAAkB,GAAG,MAAM;IAWhD;;;OAGG;IACH,eAAe,CAAC,OAAO,UAAQ,GAAG,MAAM;IAiCxC;;OAEG;IACH,UAAU,IAAI,kBAAkB;IAgEhC;;;OAGG;IACH,MAAM,CAAC,YAAY,CAAC,QAAQ,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,GAAG,UAAU;IAwCnF;;OAEG;IACH,UAAU,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,iBAAiB,EAAE;CAIhD"}
|
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module world-model/state-store
|
|
3
|
+
* @description Richer WorldState with per-file tracking and history.
|
|
4
|
+
* Uses an immutable base + delta patch architecture instead of full deep clones.
|
|
5
|
+
* History stores only what changed (StatePatch) rather than full WorldState copies.
|
|
6
|
+
*/
|
|
7
|
+
// ─── Internal Helpers ───
|
|
8
|
+
/**
|
|
9
|
+
* Estimate the memory footprint of a patch in bytes.
|
|
10
|
+
* Not exact — used for trimming heuristics.
|
|
11
|
+
*/
|
|
12
|
+
function estimatePatchSize(patch) {
|
|
13
|
+
let bytes = 0;
|
|
14
|
+
if (patch.files) {
|
|
15
|
+
bytes += patch.files.length * 200; // avg FileState JSON ~200 bytes
|
|
16
|
+
}
|
|
17
|
+
if (patch.build)
|
|
18
|
+
bytes += JSON.stringify(patch.build).length;
|
|
19
|
+
if (patch.test)
|
|
20
|
+
bytes += JSON.stringify(patch.test).length;
|
|
21
|
+
if (patch.git)
|
|
22
|
+
bytes += JSON.stringify(patch.git).length;
|
|
23
|
+
if (patch.deps)
|
|
24
|
+
bytes += JSON.stringify(patch.deps).length;
|
|
25
|
+
return bytes;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Estimate the base snapshot size in bytes.
|
|
29
|
+
* Approximates by counting Map entries + scalar fields.
|
|
30
|
+
*/
|
|
31
|
+
function estimateSnapshotSize(state) {
|
|
32
|
+
let bytes = 200; // scalar fields overhead
|
|
33
|
+
bytes += state.files.size * 200;
|
|
34
|
+
bytes += JSON.stringify(state.build).length;
|
|
35
|
+
bytes += JSON.stringify(state.test).length;
|
|
36
|
+
bytes += JSON.stringify(state.git).length;
|
|
37
|
+
bytes += JSON.stringify(state.deps).length;
|
|
38
|
+
return bytes;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Apply a patch to produce a NEW WorldState (never mutates the input).
|
|
42
|
+
* Uses structural sharing — unchanged Map/objects are not cloned.
|
|
43
|
+
*/
|
|
44
|
+
function applyPatch(state, patch) {
|
|
45
|
+
const next = { ...state, timestamp: Date.now() };
|
|
46
|
+
if (patch.files) {
|
|
47
|
+
// Clone the Map only when files actually change
|
|
48
|
+
next.files = new Map(state.files);
|
|
49
|
+
for (const fp of patch.files) {
|
|
50
|
+
if (fp.type === "set" && fp.state !== undefined) {
|
|
51
|
+
next.files.set(fp.path, fp.state);
|
|
52
|
+
}
|
|
53
|
+
else if (fp.type === "delete") {
|
|
54
|
+
next.files.delete(fp.path);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (patch.build !== undefined)
|
|
59
|
+
next.build = { ...state.build, ...patch.build };
|
|
60
|
+
if (patch.test !== undefined)
|
|
61
|
+
next.test = { ...state.test, ...patch.test };
|
|
62
|
+
if (patch.git !== undefined)
|
|
63
|
+
next.git = { ...state.git, ...patch.git };
|
|
64
|
+
if (patch.deps !== undefined)
|
|
65
|
+
next.deps = { ...state.deps, ...patch.deps };
|
|
66
|
+
return next;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Produce a StatePatch by comparing two WorldState values.
|
|
70
|
+
* Only includes sub-trees that differ.
|
|
71
|
+
*/
|
|
72
|
+
function diffStates(before, after) {
|
|
73
|
+
const patch = {};
|
|
74
|
+
// Files: find added/changed/deleted entries
|
|
75
|
+
const filePatches = [];
|
|
76
|
+
for (const [path, afterFile] of after.files) {
|
|
77
|
+
const beforeFile = before.files.get(path);
|
|
78
|
+
if (beforeFile === undefined ||
|
|
79
|
+
beforeFile.hash !== afterFile.hash ||
|
|
80
|
+
beforeFile.exists !== afterFile.exists ||
|
|
81
|
+
beforeFile.lines !== afterFile.lines ||
|
|
82
|
+
beforeFile.lastModified !== afterFile.lastModified) {
|
|
83
|
+
filePatches.push({ type: "set", path, state: afterFile });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
for (const path of before.files.keys()) {
|
|
87
|
+
if (!after.files.has(path)) {
|
|
88
|
+
filePatches.push({ type: "delete", path });
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (filePatches.length > 0)
|
|
92
|
+
patch.files = filePatches;
|
|
93
|
+
// Build
|
|
94
|
+
if (JSON.stringify(before.build) !== JSON.stringify(after.build)) {
|
|
95
|
+
patch.build = { ...after.build };
|
|
96
|
+
}
|
|
97
|
+
// Test
|
|
98
|
+
if (JSON.stringify(before.test) !== JSON.stringify(after.test)) {
|
|
99
|
+
patch.test = { ...after.test };
|
|
100
|
+
}
|
|
101
|
+
// Git
|
|
102
|
+
if (JSON.stringify(before.git) !== JSON.stringify(after.git)) {
|
|
103
|
+
patch.git = { ...after.git };
|
|
104
|
+
}
|
|
105
|
+
// Deps
|
|
106
|
+
if (JSON.stringify(before.deps) !== JSON.stringify(after.deps)) {
|
|
107
|
+
patch.deps = { ...after.deps };
|
|
108
|
+
}
|
|
109
|
+
return patch;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Replay all patches from a base state up to (and including) the entry at `index`.
|
|
113
|
+
*/
|
|
114
|
+
function replayPatches(base, patches, upTo) {
|
|
115
|
+
let state = base;
|
|
116
|
+
for (let i = 0; i <= upTo && i < patches.length; i++) {
|
|
117
|
+
state = applyPatch(state, patches[i].patch);
|
|
118
|
+
}
|
|
119
|
+
return state;
|
|
120
|
+
}
|
|
121
|
+
// ─── StateStore ───
|
|
122
|
+
export class StateStore {
|
|
123
|
+
/** Immutable base — never mutated after construction */
|
|
124
|
+
base;
|
|
125
|
+
/** Current materialized state (kept up to date on every update) */
|
|
126
|
+
current;
|
|
127
|
+
patches;
|
|
128
|
+
maxPatches;
|
|
129
|
+
constructor(initial, maxPatches = 20) {
|
|
130
|
+
// Shallow-clone the initial state so callers can't mutate it from outside
|
|
131
|
+
this.base = {
|
|
132
|
+
...initial,
|
|
133
|
+
files: new Map(initial.files),
|
|
134
|
+
build: { ...initial.build, errors: [...initial.build.errors] },
|
|
135
|
+
test: { ...initial.test, failingTests: [...initial.test.failingTests] },
|
|
136
|
+
git: {
|
|
137
|
+
...initial.git,
|
|
138
|
+
stagedFiles: [...initial.git.stagedFiles],
|
|
139
|
+
uncommittedFiles: [...initial.git.uncommittedFiles],
|
|
140
|
+
},
|
|
141
|
+
deps: {
|
|
142
|
+
...initial.deps,
|
|
143
|
+
missing: [...initial.deps.missing],
|
|
144
|
+
outdated: [...initial.deps.outdated],
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
// current starts as the same value as base (structural sharing is fine here)
|
|
148
|
+
this.current = this.base;
|
|
149
|
+
this.patches = [];
|
|
150
|
+
this.maxPatches = maxPatches;
|
|
151
|
+
}
|
|
152
|
+
/** Returns the current materialized state (already computed — O(1)). */
|
|
153
|
+
getState() {
|
|
154
|
+
return this.current;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Apply a StatePatch: saves patch to history, updates current in-place (structurally).
|
|
158
|
+
* O(k) where k = number of file entries in the patch, not total file count.
|
|
159
|
+
*/
|
|
160
|
+
update(patch, action) {
|
|
161
|
+
const memorySizeBytes = estimatePatchSize(patch);
|
|
162
|
+
this.patches.push({ action, timestamp: Date.now(), patch, memorySizeBytes });
|
|
163
|
+
// Trim oldest patches if over the limit
|
|
164
|
+
if (this.patches.length > this.maxPatches) {
|
|
165
|
+
this.patches.splice(0, this.patches.length - this.maxPatches);
|
|
166
|
+
}
|
|
167
|
+
// Advance current state
|
|
168
|
+
this.current = applyPatch(this.current, patch);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Compute a StatePatch by diffing before and after WorldState objects.
|
|
172
|
+
* Useful for callers who already have the new state and want to store the delta.
|
|
173
|
+
*/
|
|
174
|
+
static diffStates(before, after) {
|
|
175
|
+
return diffStates(before, after);
|
|
176
|
+
}
|
|
177
|
+
/** Look up a single file's current state — O(1). */
|
|
178
|
+
getFileState(path) {
|
|
179
|
+
return this.current.files.get(path);
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Reconstruct the historical state after applying the first `index + 1` patches.
|
|
183
|
+
* O(index × avg_patch_size).
|
|
184
|
+
*/
|
|
185
|
+
getStateAt(index) {
|
|
186
|
+
if (index < 0 || index >= this.patches.length) {
|
|
187
|
+
throw new RangeError(`getStateAt: index ${index} out of range [0, ${this.patches.length - 1}]`);
|
|
188
|
+
}
|
|
189
|
+
return replayPatches(this.base, this.patches, index);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Returns change history for a specific file path across all patch entries.
|
|
193
|
+
* For each patch that touched the file, returns the before/after FileState.
|
|
194
|
+
*/
|
|
195
|
+
getFileHistory(path) {
|
|
196
|
+
const result = [];
|
|
197
|
+
// Walk patches; maintain a running "previous state" for this file
|
|
198
|
+
let prevFileState = this.base.files.get(path);
|
|
199
|
+
for (const entry of this.patches) {
|
|
200
|
+
if (!entry.patch.files)
|
|
201
|
+
continue;
|
|
202
|
+
const fp = entry.patch.files.find((f) => f.path === path);
|
|
203
|
+
if (!fp)
|
|
204
|
+
continue;
|
|
205
|
+
if (fp.type === "set" && fp.state !== undefined) {
|
|
206
|
+
result.push({ action: entry.action, before: prevFileState, after: fp.state });
|
|
207
|
+
prevFileState = fp.state;
|
|
208
|
+
}
|
|
209
|
+
// "delete" patches don't have an "after" FileState — skip for history purposes
|
|
210
|
+
}
|
|
211
|
+
return result;
|
|
212
|
+
}
|
|
213
|
+
/** Return memory usage stats for monitoring/debugging. */
|
|
214
|
+
getMemoryStats() {
|
|
215
|
+
const baseSnapshotBytes = estimateSnapshotSize(this.base);
|
|
216
|
+
let totalPatchBytes = 0;
|
|
217
|
+
let largestPatchBytes = 0;
|
|
218
|
+
for (const entry of this.patches) {
|
|
219
|
+
totalPatchBytes += entry.memorySizeBytes;
|
|
220
|
+
if (entry.memorySizeBytes > largestPatchBytes) {
|
|
221
|
+
largestPatchBytes = entry.memorySizeBytes;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return {
|
|
225
|
+
baseSnapshotBytes,
|
|
226
|
+
totalPatchBytes,
|
|
227
|
+
totalBytes: baseSnapshotBytes + totalPatchBytes,
|
|
228
|
+
entryCount: this.patches.length,
|
|
229
|
+
largestPatchBytes,
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Trim oldest patches if total patch memory exceeds `maxBytes`.
|
|
234
|
+
* Returns the number of patches trimmed.
|
|
235
|
+
* Default limit is 5 MB.
|
|
236
|
+
*/
|
|
237
|
+
trimIfNeeded(maxBytes = 5 * 1024 * 1024) {
|
|
238
|
+
let trimmed = 0;
|
|
239
|
+
while (this.patches.length > 0) {
|
|
240
|
+
const stats = this.getMemoryStats();
|
|
241
|
+
if (stats.totalBytes <= maxBytes)
|
|
242
|
+
break;
|
|
243
|
+
this.patches.shift();
|
|
244
|
+
trimmed++;
|
|
245
|
+
}
|
|
246
|
+
return trimmed;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Format current state as a string for injection into an LLM prompt.
|
|
250
|
+
* Pass `compact = true` for a single-line summary.
|
|
251
|
+
*/
|
|
252
|
+
formatForPrompt(compact = false) {
|
|
253
|
+
const s = this.current;
|
|
254
|
+
const stats = this.getMemoryStats();
|
|
255
|
+
if (compact) {
|
|
256
|
+
return [
|
|
257
|
+
`[World State] git:${s.git.branch}(${s.git.dirty ? "dirty" : "clean"})`,
|
|
258
|
+
`build:${s.build.status} test:${s.test.status}`,
|
|
259
|
+
`files_tracked:${s.files.size} history:${stats.entryCount}patches(${Math.round(stats.totalBytes / 1024)}KB)`,
|
|
260
|
+
].join(" | ");
|
|
261
|
+
}
|
|
262
|
+
const lines = [
|
|
263
|
+
"## Current World State",
|
|
264
|
+
`**Git**: branch=${s.git.branch}, ${s.git.dirty ? `dirty (${s.git.uncommittedFiles.length} files)` : "clean"}`,
|
|
265
|
+
`**Build**: ${s.build.status}${s.build.errors.length ? ` — ${s.build.errors.length} errors` : ""}`,
|
|
266
|
+
`**Tests**: ${s.test.status}${s.test.failingTests.length ? ` — failing: ${s.test.failingTests.join(", ")}` : ""}`,
|
|
267
|
+
`**Files tracked**: ${s.files.size}`,
|
|
268
|
+
`**State history**: ${stats.entryCount} patches, ${Math.round(stats.totalBytes / 1024)}KB`,
|
|
269
|
+
];
|
|
270
|
+
if (s.git.uncommittedFiles.length > 0) {
|
|
271
|
+
lines.push(`**Uncommitted**: ${s.git.uncommittedFiles.slice(0, 5).join(", ")}${s.git.uncommittedFiles.length > 5 ? " ..." : ""}`);
|
|
272
|
+
}
|
|
273
|
+
if (s.build.errors.length > 0) {
|
|
274
|
+
lines.push(`**Build errors**: ${s.build.errors.slice(0, 3).join("; ")}`);
|
|
275
|
+
}
|
|
276
|
+
return lines.join("\n");
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Convert to WorldStateSnapshot for backward compatibility with existing code.
|
|
280
|
+
*/
|
|
281
|
+
toSnapshot() {
|
|
282
|
+
const { build, test, git, deps, files, timestamp } = this.current;
|
|
283
|
+
const buildLastResult = build.status === "running" ? "unknown" : build.status;
|
|
284
|
+
const knownBuildTools = ["tsc", "webpack", "vite", "esbuild"];
|
|
285
|
+
const buildTool = knownBuildTools.includes(build.buildTool)
|
|
286
|
+
? build.buildTool
|
|
287
|
+
: "unknown";
|
|
288
|
+
const testLastResult = test.status === "running" ? "unknown" : test.status;
|
|
289
|
+
const knownTestRunners = ["jest", "vitest", "mocha", "node:test"];
|
|
290
|
+
const testRunner = knownTestRunners.includes(test.testRunner)
|
|
291
|
+
? test.testRunner
|
|
292
|
+
: "unknown";
|
|
293
|
+
const knownPMs = ["npm", "pnpm", "yarn", "bun"];
|
|
294
|
+
const packageManager = knownPMs.includes(deps.packageManager)
|
|
295
|
+
? deps.packageManager
|
|
296
|
+
: "unknown";
|
|
297
|
+
const recentlyChanged = [];
|
|
298
|
+
for (const [path, fileState] of files) {
|
|
299
|
+
if (fileState.exists)
|
|
300
|
+
recentlyChanged.push(path);
|
|
301
|
+
}
|
|
302
|
+
return {
|
|
303
|
+
git: {
|
|
304
|
+
branch: git.branch,
|
|
305
|
+
status: git.dirty ? "dirty" : "clean",
|
|
306
|
+
uncommittedFiles: [...git.uncommittedFiles],
|
|
307
|
+
recentCommits: [],
|
|
308
|
+
hasConflicts: false,
|
|
309
|
+
},
|
|
310
|
+
build: {
|
|
311
|
+
lastResult: buildLastResult,
|
|
312
|
+
errors: [...build.errors],
|
|
313
|
+
buildTool,
|
|
314
|
+
},
|
|
315
|
+
test: {
|
|
316
|
+
lastResult: testLastResult,
|
|
317
|
+
failingTests: [...test.failingTests],
|
|
318
|
+
testRunner,
|
|
319
|
+
},
|
|
320
|
+
deps: {
|
|
321
|
+
packageManager,
|
|
322
|
+
outdated: [...deps.outdated],
|
|
323
|
+
missing: [...deps.missing],
|
|
324
|
+
},
|
|
325
|
+
files: {
|
|
326
|
+
recentlyChanged,
|
|
327
|
+
totalFiles: files.size,
|
|
328
|
+
},
|
|
329
|
+
errors: { recentRuntimeErrors: [] },
|
|
330
|
+
collectedAt: new Date(timestamp).toISOString(),
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Create StateStore from an existing WorldStateSnapshot.
|
|
335
|
+
* The files Map starts empty since snapshots don't carry per-file info.
|
|
336
|
+
*/
|
|
337
|
+
static fromSnapshot(snapshot, _projectPath) {
|
|
338
|
+
const buildStatus = snapshot.build.lastResult === "unknown" ? "unknown" : snapshot.build.lastResult;
|
|
339
|
+
const testStatus = snapshot.test.lastResult === "unknown" ? "unknown" : snapshot.test.lastResult;
|
|
340
|
+
const initial = {
|
|
341
|
+
files: new Map(),
|
|
342
|
+
build: {
|
|
343
|
+
status: buildStatus,
|
|
344
|
+
errors: [...snapshot.build.errors],
|
|
345
|
+
lastRun: 0,
|
|
346
|
+
buildTool: snapshot.build.buildTool,
|
|
347
|
+
},
|
|
348
|
+
test: {
|
|
349
|
+
status: testStatus,
|
|
350
|
+
failingTests: [...snapshot.test.failingTests],
|
|
351
|
+
lastRun: 0,
|
|
352
|
+
testRunner: snapshot.test.testRunner,
|
|
353
|
+
},
|
|
354
|
+
git: {
|
|
355
|
+
branch: snapshot.git.branch,
|
|
356
|
+
dirty: snapshot.git.status === "dirty",
|
|
357
|
+
stagedFiles: [],
|
|
358
|
+
uncommittedFiles: [...snapshot.git.uncommittedFiles],
|
|
359
|
+
lastCommit: snapshot.git.recentCommits.length > 0 ? snapshot.git.recentCommits[0].hash : "",
|
|
360
|
+
},
|
|
361
|
+
deps: {
|
|
362
|
+
packageManager: snapshot.deps.packageManager,
|
|
363
|
+
missing: [...snapshot.deps.missing],
|
|
364
|
+
outdated: [...snapshot.deps.outdated],
|
|
365
|
+
},
|
|
366
|
+
timestamp: new Date(snapshot.collectedAt).getTime(),
|
|
367
|
+
};
|
|
368
|
+
return new StateStore(initial);
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Get last N patch history entries (most recent last).
|
|
372
|
+
*/
|
|
373
|
+
getHistory(limit) {
|
|
374
|
+
if (limit === undefined)
|
|
375
|
+
return [...this.patches];
|
|
376
|
+
return this.patches.slice(-limit);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
//# sourceMappingURL=state-store.js.map
|
|
@@ -0,0 +1 @@
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,QAAQ,EAAE,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC;aACtC;YACD,SAAS,EAAE,IAAI,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,OAAO,EAAE;SACpD,CAAC;QAEF,OAAO,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC;IACjC,CAAC;IAED;;OAEG;IACH,UAAU,CAAC,KAAc;QACvB,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;QAClD,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;CACF"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module world-model/state-updater
|
|
3
|
+
* @description Updates the StateStore after actual tool execution.
|
|
4
|
+
* Translates real tool results into WorldState patches so the world model
|
|
5
|
+
* stays in sync with disk/git/build truth.
|
|
6
|
+
*/
|
|
7
|
+
import type { ToolResult } from "../types.js";
|
|
8
|
+
import type { StateStore } from "./state-store.js";
|
|
9
|
+
import type { FileState, StatePatch } from "./state-store.js";
|
|
10
|
+
export declare class StateUpdater {
|
|
11
|
+
private stateStore;
|
|
12
|
+
private projectPath;
|
|
13
|
+
constructor(stateStore: StateStore, projectPath: string);
|
|
14
|
+
/**
|
|
15
|
+
* Main method: call after every tool execution.
|
|
16
|
+
* Applies the appropriate patch to the StateStore based on the tool and result.
|
|
17
|
+
*/
|
|
18
|
+
applyToolResult(tool: string, args: Record<string, unknown>, result: ToolResult): Promise<StatePatch>;
|
|
19
|
+
/**
|
|
20
|
+
* Read a file from disk and return its FileState.
|
|
21
|
+
* Returns null if the file cannot be read (e.g. does not exist).
|
|
22
|
+
*/
|
|
23
|
+
refreshFileState(filePath: string): Promise<FileState | null>;
|
|
24
|
+
/**
|
|
25
|
+
* Parse build command output (tsc / webpack / vite / etc.) and update the
|
|
26
|
+
* build state in the StateStore.
|
|
27
|
+
*/
|
|
28
|
+
parseBuildOutput(output: string, success: boolean): void;
|
|
29
|
+
/**
|
|
30
|
+
* Parse test command output (jest / vitest / mocha / pytest / etc.) and
|
|
31
|
+
* update the test state in the StateStore.
|
|
32
|
+
*/
|
|
33
|
+
parseTestOutput(output: string, success: boolean): void;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=state-updater.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-updater.d.ts","sourceRoot":"","sources":["../../src/world-model/state-updater.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAI9D,qBAAa,YAAY;IAErB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,WAAW;gBADX,UAAU,EAAE,UAAU,EACtB,WAAW,EAAE,MAAM;IAG7B;;;OAGG;IACG,eAAe,CACnB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,MAAM,EAAE,UAAU,GACjB,OAAO,CAAC,UAAU,CAAC;IAiEtB;;;OAGG;IACG,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;IAiBnE;;;OAGG;IACH,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI;IAkBxD;;;OAGG;IACH,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI;CAiBxD"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module world-model/state-updater
|
|
3
|
+
* @description Updates the StateStore after actual tool execution.
|
|
4
|
+
* Translates real tool results into WorldState patches so the world model
|
|
5
|
+
* stays in sync with disk/git/build truth.
|
|
6
|
+
*/
|
|
7
|
+
import { createHash } from "node:crypto";
|
|
8
|
+
import { readFile, stat } from "node:fs/promises";
|
|
9
|
+
import { resolve } from "node:path";
|
|
10
|
+
// ─── StateUpdater ───
|
|
11
|
+
export class StateUpdater {
|
|
12
|
+
stateStore;
|
|
13
|
+
projectPath;
|
|
14
|
+
constructor(stateStore, projectPath) {
|
|
15
|
+
this.stateStore = stateStore;
|
|
16
|
+
this.projectPath = projectPath;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Main method: call after every tool execution.
|
|
20
|
+
* Applies the appropriate patch to the StateStore based on the tool and result.
|
|
21
|
+
*/
|
|
22
|
+
async applyToolResult(tool, args, result) {
|
|
23
|
+
const toolLower = tool.toLowerCase();
|
|
24
|
+
// ── File write / edit ──────────────────────────────────────────────────
|
|
25
|
+
if (toolLower === "file_write" || toolLower === "file_edit") {
|
|
26
|
+
const rawPath = args["path"] ?? args["file_path"];
|
|
27
|
+
const filePath = typeof rawPath === "string" ? rawPath : null;
|
|
28
|
+
if (result.success && filePath !== null) {
|
|
29
|
+
const fileState = await this.refreshFileState(filePath);
|
|
30
|
+
if (fileState) {
|
|
31
|
+
const currentGit = this.stateStore.getState().git;
|
|
32
|
+
const uncommittedFiles = Array.from(new Set([...currentGit.uncommittedFiles, filePath]));
|
|
33
|
+
const patch = {
|
|
34
|
+
files: [{ type: "set", path: filePath, state: fileState }],
|
|
35
|
+
build: { status: "unknown" },
|
|
36
|
+
test: { status: "unknown" },
|
|
37
|
+
git: { dirty: true, uncommittedFiles },
|
|
38
|
+
};
|
|
39
|
+
this.stateStore.update(patch, `${tool}:${filePath}`);
|
|
40
|
+
return patch;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return {};
|
|
44
|
+
}
|
|
45
|
+
// ── Shell exec ────────────────────────────────────────────────────────
|
|
46
|
+
if (toolLower === "shell_exec") {
|
|
47
|
+
const command = typeof args["command"] === "string" ? args["command"] : "";
|
|
48
|
+
if (/tsc|build|compile/i.test(command)) {
|
|
49
|
+
this.parseBuildOutput(result.output, result.success);
|
|
50
|
+
}
|
|
51
|
+
else if (/test|jest|vitest|mocha|pytest/i.test(command)) {
|
|
52
|
+
this.parseTestOutput(result.output, result.success);
|
|
53
|
+
}
|
|
54
|
+
// Patch was already applied inside the parse methods
|
|
55
|
+
return {};
|
|
56
|
+
}
|
|
57
|
+
// ── Git ops ───────────────────────────────────────────────────────────
|
|
58
|
+
if (toolLower === "git_ops") {
|
|
59
|
+
const operation = args["operation"] ?? args["command"];
|
|
60
|
+
const opStr = typeof operation === "string" ? operation : "";
|
|
61
|
+
if (opStr === "commit") {
|
|
62
|
+
const patch = {
|
|
63
|
+
git: { dirty: false, uncommittedFiles: [], stagedFiles: [] },
|
|
64
|
+
};
|
|
65
|
+
this.stateStore.update(patch, "git:commit");
|
|
66
|
+
return patch;
|
|
67
|
+
}
|
|
68
|
+
return {};
|
|
69
|
+
}
|
|
70
|
+
// ── Unknown / read-only tools ─────────────────────────────────────────
|
|
71
|
+
return {};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Read a file from disk and return its FileState.
|
|
75
|
+
* Returns null if the file cannot be read (e.g. does not exist).
|
|
76
|
+
*/
|
|
77
|
+
async refreshFileState(filePath) {
|
|
78
|
+
const absPath = resolve(this.projectPath, filePath);
|
|
79
|
+
const content = await readFile(absPath, "utf-8").catch(() => null);
|
|
80
|
+
if (content === null)
|
|
81
|
+
return null;
|
|
82
|
+
const stats = await stat(absPath);
|
|
83
|
+
const hash = createHash("sha256").update(content).digest("hex").slice(0, 16);
|
|
84
|
+
return {
|
|
85
|
+
path: filePath,
|
|
86
|
+
exists: true,
|
|
87
|
+
hash,
|
|
88
|
+
lines: content.split("\n").length,
|
|
89
|
+
lastModified: stats.mtimeMs,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Parse build command output (tsc / webpack / vite / etc.) and update the
|
|
94
|
+
* build state in the StateStore.
|
|
95
|
+
*/
|
|
96
|
+
parseBuildOutput(output, success) {
|
|
97
|
+
const errorLines = output
|
|
98
|
+
.split("\n")
|
|
99
|
+
.filter((line) => /error TS\d+|Error:/i.test(line))
|
|
100
|
+
.slice(0, 10)
|
|
101
|
+
.map((line) => line.trim());
|
|
102
|
+
const patch = {
|
|
103
|
+
build: {
|
|
104
|
+
status: success ? "pass" : "fail",
|
|
105
|
+
errors: errorLines,
|
|
106
|
+
lastRun: Date.now(),
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
this.stateStore.update(patch, "build:result");
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Parse test command output (jest / vitest / mocha / pytest / etc.) and
|
|
113
|
+
* update the test state in the StateStore.
|
|
114
|
+
*/
|
|
115
|
+
parseTestOutput(output, success) {
|
|
116
|
+
const failingTests = output
|
|
117
|
+
.split("\n")
|
|
118
|
+
.filter((line) => /✗|FAIL|×|failed/i.test(line))
|
|
119
|
+
.slice(0, 10)
|
|
120
|
+
.map((line) => line.trim());
|
|
121
|
+
const patch = {
|
|
122
|
+
test: {
|
|
123
|
+
status: success ? "pass" : "fail",
|
|
124
|
+
failingTests,
|
|
125
|
+
lastRun: Date.now(),
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
this.stateStore.update(patch, "test:result");
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=state-updater.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-updater.js","sourceRoot":"","sources":["../../src/world-model/state-updater.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;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C,CAAC;QAE9B,MAAM,KAAK,GAAe;YACxB,KAAK,EAAE;gBACL,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM;gBACjC,MAAM,EAAE,UAAU;gBAClB,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE;aACpB;SACF,CAAC;QAEF,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;IAChD,CAAC;IAED;;;OAGG;IACH,eAAe,CAAC,MAAc,EAAE,OAAgB;QAC9C,MAAM,YAAY,GAAG,MAAM;aACxB,KAAK,CAAC,IAAI,CAAC;aACX,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;aAC/C,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;aACZ,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAE9B,MAAM,KAAK,GAAe;YACxB,IAAI,EAAE;gBACJ,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM;gBACjC,YAAY;gBACZ,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE;aACpB;SACF,CAAC;QAEF,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IAC/C,CAAC;CACF"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module world-model/transition-model
|
|
3
|
+
* @description Predicts how each tool call will change the WorldState.
|
|
4
|
+
* Uses rule-based heuristics with calibration via actual outcomes.
|
|
5
|
+
*/
|
|
6
|
+
import type { WorldState } from "./state-store.js";
|
|
7
|
+
export interface StateDelta {
|
|
8
|
+
/** Files that will be modified */
|
|
9
|
+
filesChanged: string[];
|
|
10
|
+
/** Files that will be created */
|
|
11
|
+
filesCreated: string[];
|
|
12
|
+
/** Files that will be deleted */
|
|
13
|
+
filesDeleted: string[];
|
|
14
|
+
/** Does this action require a build re-run? */
|
|
15
|
+
buildInvalidated: boolean;
|
|
16
|
+
/** Does this action require a test re-run? */
|
|
17
|
+
testInvalidated: boolean;
|
|
18
|
+
/** Will git become dirty? */
|
|
19
|
+
gitDirty: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface StateTransition {
|
|
22
|
+
tool: string;
|
|
23
|
+
args: Record<string, unknown>;
|
|
24
|
+
expectedDelta: StateDelta;
|
|
25
|
+
/** 0.0 to 1.0 */
|
|
26
|
+
failureProbability: number;
|
|
27
|
+
/** Explanation for this probability */
|
|
28
|
+
reasoning: string;
|
|
29
|
+
}
|
|
30
|
+
export declare class TransitionModel {
|
|
31
|
+
private history;
|
|
32
|
+
/** Per tool-type accuracy for calibration */
|
|
33
|
+
private accuracy;
|
|
34
|
+
constructor();
|
|
35
|
+
/**
|
|
36
|
+
* Predict what will happen when a tool is called with given args.
|
|
37
|
+
* Uses rule-based heuristics + calibration multipliers.
|
|
38
|
+
*/
|
|
39
|
+
predict(tool: string, args: Record<string, unknown>, currentState: WorldState): StateTransition;
|
|
40
|
+
/**
|
|
41
|
+
* After actual execution, calibrate the model's accuracy for this tool type.
|
|
42
|
+
* Uses a simple exponential moving average on the multiplier.
|
|
43
|
+
*/
|
|
44
|
+
calibrate(predicted: StateTransition, actual: StateDelta, success: boolean): void;
|
|
45
|
+
/**
|
|
46
|
+
* Predict the final WorldState after executing a sequence of tool calls.
|
|
47
|
+
* Applies each transition's expected delta to produce the final state.
|
|
48
|
+
*/
|
|
49
|
+
predictSequence(tools: Array<{
|
|
50
|
+
tool: string;
|
|
51
|
+
args: Record<string, unknown>;
|
|
52
|
+
}>, initialState: WorldState): WorldState;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=transition-model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transition-model.d.ts","sourceRoot":"","sources":["../../src/world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