@yuaone/core 0.5.0 → 0.7.0
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 +50 -6
- package/dist/agent-loop.d.ts +36 -0
- package/dist/agent-loop.d.ts.map +1 -1
- package/dist/agent-loop.js +504 -97
- 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 +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/llm-client.d.ts +11 -2
- package/dist/llm-client.d.ts.map +1 -1
- package/dist/llm-client.js +23 -8
- package/dist/llm-client.js.map +1 -1
- 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/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,149 @@
|
|
|
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
|
+
import type { WorldStateSnapshot } from "../world-state.js";
|
|
8
|
+
export interface FileState {
|
|
9
|
+
path: string;
|
|
10
|
+
exists: boolean;
|
|
11
|
+
/** SHA-256 hex digest of file content */
|
|
12
|
+
hash: string;
|
|
13
|
+
lines: number;
|
|
14
|
+
lastModified: number;
|
|
15
|
+
}
|
|
16
|
+
export interface BuildState {
|
|
17
|
+
status: "pass" | "fail" | "unknown" | "running";
|
|
18
|
+
errors: string[];
|
|
19
|
+
/** Epoch ms of last run */
|
|
20
|
+
lastRun: number;
|
|
21
|
+
buildTool: string;
|
|
22
|
+
}
|
|
23
|
+
export interface TestState {
|
|
24
|
+
status: "pass" | "fail" | "unknown" | "running";
|
|
25
|
+
failingTests: string[];
|
|
26
|
+
/** Epoch ms of last run */
|
|
27
|
+
lastRun: number;
|
|
28
|
+
testRunner: string;
|
|
29
|
+
}
|
|
30
|
+
export interface GitState {
|
|
31
|
+
branch: string;
|
|
32
|
+
dirty: boolean;
|
|
33
|
+
stagedFiles: string[];
|
|
34
|
+
uncommittedFiles: string[];
|
|
35
|
+
/** Short commit hash */
|
|
36
|
+
lastCommit: string;
|
|
37
|
+
}
|
|
38
|
+
export interface DepsState {
|
|
39
|
+
packageManager: string;
|
|
40
|
+
missing: string[];
|
|
41
|
+
outdated: string[];
|
|
42
|
+
}
|
|
43
|
+
export interface WorldState {
|
|
44
|
+
files: Map<string, FileState>;
|
|
45
|
+
build: BuildState;
|
|
46
|
+
test: TestState;
|
|
47
|
+
git: GitState;
|
|
48
|
+
deps: DepsState;
|
|
49
|
+
timestamp: number;
|
|
50
|
+
}
|
|
51
|
+
/** A patch entry for the files map — describes a single file add/update or removal */
|
|
52
|
+
export interface FilePatch {
|
|
53
|
+
type: "set" | "delete";
|
|
54
|
+
path: string;
|
|
55
|
+
/** Present when type === "set" */
|
|
56
|
+
state?: FileState;
|
|
57
|
+
}
|
|
58
|
+
/** A minimal delta — only the sub-trees that actually changed */
|
|
59
|
+
export interface StatePatch {
|
|
60
|
+
files?: FilePatch[];
|
|
61
|
+
build?: Partial<BuildState>;
|
|
62
|
+
test?: Partial<TestState>;
|
|
63
|
+
git?: Partial<GitState>;
|
|
64
|
+
deps?: Partial<DepsState>;
|
|
65
|
+
}
|
|
66
|
+
/** History entry stores a patch, not a full state copy */
|
|
67
|
+
export interface PatchHistoryEntry {
|
|
68
|
+
action: string;
|
|
69
|
+
timestamp: number;
|
|
70
|
+
patch: StatePatch;
|
|
71
|
+
/** Estimated size of this patch in bytes */
|
|
72
|
+
memorySizeBytes: number;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* @deprecated Use PatchHistoryEntry instead.
|
|
76
|
+
* Kept for backward-compatibility with any code that imports StateHistoryEntry.
|
|
77
|
+
*/
|
|
78
|
+
export type StateHistoryEntry = PatchHistoryEntry;
|
|
79
|
+
export interface MemoryStats {
|
|
80
|
+
baseSnapshotBytes: number;
|
|
81
|
+
totalPatchBytes: number;
|
|
82
|
+
totalBytes: number;
|
|
83
|
+
entryCount: number;
|
|
84
|
+
largestPatchBytes: number;
|
|
85
|
+
}
|
|
86
|
+
export declare class StateStore {
|
|
87
|
+
/** Immutable base — never mutated after construction */
|
|
88
|
+
private readonly base;
|
|
89
|
+
/** Current materialized state (kept up to date on every update) */
|
|
90
|
+
private current;
|
|
91
|
+
private patches;
|
|
92
|
+
private readonly maxPatches;
|
|
93
|
+
constructor(initial: WorldState, maxPatches?: number);
|
|
94
|
+
/** Returns the current materialized state (already computed — O(1)). */
|
|
95
|
+
getState(): WorldState;
|
|
96
|
+
/**
|
|
97
|
+
* Apply a StatePatch: saves patch to history, updates current in-place (structurally).
|
|
98
|
+
* O(k) where k = number of file entries in the patch, not total file count.
|
|
99
|
+
*/
|
|
100
|
+
update(patch: StatePatch, action: string): void;
|
|
101
|
+
/**
|
|
102
|
+
* Compute a StatePatch by diffing before and after WorldState objects.
|
|
103
|
+
* Useful for callers who already have the new state and want to store the delta.
|
|
104
|
+
*/
|
|
105
|
+
static diffStates(before: WorldState, after: WorldState): StatePatch;
|
|
106
|
+
/** Look up a single file's current state — O(1). */
|
|
107
|
+
getFileState(path: string): FileState | undefined;
|
|
108
|
+
/**
|
|
109
|
+
* Reconstruct the historical state after applying the first `index + 1` patches.
|
|
110
|
+
* O(index × avg_patch_size).
|
|
111
|
+
*/
|
|
112
|
+
getStateAt(index: number): WorldState;
|
|
113
|
+
/**
|
|
114
|
+
* Returns change history for a specific file path across all patch entries.
|
|
115
|
+
* For each patch that touched the file, returns the before/after FileState.
|
|
116
|
+
*/
|
|
117
|
+
getFileHistory(path: string): Array<{
|
|
118
|
+
action: string;
|
|
119
|
+
before: FileState | undefined;
|
|
120
|
+
after: FileState;
|
|
121
|
+
}>;
|
|
122
|
+
/** Return memory usage stats for monitoring/debugging. */
|
|
123
|
+
getMemoryStats(): MemoryStats;
|
|
124
|
+
/**
|
|
125
|
+
* Trim oldest patches if total patch memory exceeds `maxBytes`.
|
|
126
|
+
* Returns the number of patches trimmed.
|
|
127
|
+
* Default limit is 5 MB.
|
|
128
|
+
*/
|
|
129
|
+
trimIfNeeded(maxBytes?: number): number;
|
|
130
|
+
/**
|
|
131
|
+
* Format current state as a string for injection into an LLM prompt.
|
|
132
|
+
* Pass `compact = true` for a single-line summary.
|
|
133
|
+
*/
|
|
134
|
+
formatForPrompt(compact?: boolean): string;
|
|
135
|
+
/**
|
|
136
|
+
* Convert to WorldStateSnapshot for backward compatibility with existing code.
|
|
137
|
+
*/
|
|
138
|
+
toSnapshot(): WorldStateSnapshot;
|
|
139
|
+
/**
|
|
140
|
+
* Create StateStore from an existing WorldStateSnapshot.
|
|
141
|
+
* The files Map starts empty since snapshots don't carry per-file info.
|
|
142
|
+
*/
|
|
143
|
+
static fromSnapshot(snapshot: WorldStateSnapshot, _projectPath: string): StateStore;
|
|
144
|
+
/**
|
|
145
|
+
* Get last N patch history entries (most recent last).
|
|
146
|
+
*/
|
|
147
|
+
getHistory(limit?: number): PatchHistoryEntry[];
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=state-store.d.ts.map
|
|
@@ -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;IACz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,GAAG,UAAU;IASrC;;;OAGG;IACH,cAAc,CACZ,IAAI,EAAE,MAAM,GACX,KAAK,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;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 @@
|
|
|
1
|
+
{"version":3,"file":"state-store.js","sourceRoot":"","sources":["../../src/world-model/state-store.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAiGH,2BAA2B;AAE3B;;;GAGG;AACH,SAAS,iBAAiB,CAAC,KAAiB;IAC1C,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;QAChB,KAAK,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,gCAAgC;IACrE,CAAC;IACD,IAAI,KAAK,CAAC,KAAK;QAAE,KAAK,IAAI,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC;IAC7D,IAAI,KAAK,CAAC,IAAI;QAAE,KAAK,IAAI,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;IAC3D,IAAI,KAAK,CAAC,GAAG;QAAE,KAAK,IAAI,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;IACzD,IAAI,KAAK,CAAC,IAAI;QAAE,KAAK,IAAI,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;IAC3D,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;GAGG;AACH,SAAS,oBAAoB,CAAC,KAAiB;IAC7C,IAAI,KAAK,GAAG,GAAG,CAAC,CAAC,yBAAyB;IAC1C,KAAK,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,GAAG,GAAG,CAAC;IAChC,KAAK,IAAI,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC;IAC5C,KAAK,IAAI,IAAI,CAAC,SAAS,CAAC,KAAK,C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AQ,CAAC,IAAI,CAAC,cAAc;gBAC5C,OAAO,EAAE,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC;gBACnC,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"}
|