prelude-context 1.0.0 → 1.2.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 +46 -9
- package/dist/bin/prelude.js +9 -0
- package/dist/bin/prelude.js.map +1 -1
- package/dist/src/commands/decision.d.ts.map +1 -1
- package/dist/src/commands/decision.js +4 -1
- package/dist/src/commands/decision.js.map +1 -1
- package/dist/src/commands/export.d.ts.map +1 -1
- package/dist/src/commands/export.js +4 -1
- package/dist/src/commands/export.js.map +1 -1
- package/dist/src/commands/init.d.ts.map +1 -1
- package/dist/src/commands/init.js +8 -1
- package/dist/src/commands/init.js.map +1 -1
- package/dist/src/commands/share.d.ts.map +1 -1
- package/dist/src/commands/share.js +4 -1
- package/dist/src/commands/share.js.map +1 -1
- package/dist/src/commands/update.d.ts +11 -0
- package/dist/src/commands/update.d.ts.map +1 -0
- package/dist/src/commands/update.js +186 -0
- package/dist/src/commands/update.js.map +1 -0
- package/dist/src/commands/watch.d.ts.map +1 -1
- package/dist/src/commands/watch.js +4 -1
- package/dist/src/commands/watch.js.map +1 -1
- package/dist/src/core/merger.d.ts +48 -0
- package/dist/src/core/merger.d.ts.map +1 -0
- package/dist/src/core/merger.js +221 -0
- package/dist/src/core/merger.js.map +1 -0
- package/dist/src/core/state-manager.d.ts +62 -0
- package/dist/src/core/state-manager.d.ts.map +1 -0
- package/dist/src/core/state-manager.js +156 -0
- package/dist/src/core/state-manager.js.map +1 -0
- package/dist/src/runtime/context.d.ts +3 -0
- package/dist/src/runtime/context.d.ts.map +1 -0
- package/dist/src/runtime/context.js +17 -0
- package/dist/src/runtime/context.js.map +1 -0
- package/dist/src/schema/state.d.ts +157 -0
- package/dist/src/schema/state.d.ts.map +1 -0
- package/dist/src/schema/state.js +49 -0
- package/dist/src/schema/state.js.map +1 -0
- package/package.json +11 -12
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merger.d.ts","sourceRoot":"","sources":["../../../src/core/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
|
+
stateManager;
|
|
6
|
+
constructor(stateManager) {
|
|
7
|
+
this.stateManager = stateManager;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Merge project context
|
|
11
|
+
*/
|
|
12
|
+
mergeProject(existing, inferred) {
|
|
13
|
+
const changes = [];
|
|
14
|
+
const merged = { ...inferred };
|
|
15
|
+
// Always preserve manual fields
|
|
16
|
+
const manualFields = this.stateManager.getManualFields('project.json');
|
|
17
|
+
for (const field of manualFields) {
|
|
18
|
+
const existingValue = this.getNestedValue(existing, field);
|
|
19
|
+
const inferredValue = this.getNestedValue(inferred, field);
|
|
20
|
+
if (existingValue !== undefined) {
|
|
21
|
+
this.setNestedValue(merged, field, existingValue);
|
|
22
|
+
if (JSON.stringify(existingValue) !== JSON.stringify(inferredValue)) {
|
|
23
|
+
changes.push({
|
|
24
|
+
field,
|
|
25
|
+
type: 'preserved',
|
|
26
|
+
oldValue: inferredValue,
|
|
27
|
+
newValue: existingValue,
|
|
28
|
+
reason: 'Manually edited field preserved',
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// Always preserve certain fields (only if they actually exist)
|
|
34
|
+
const preserveFields = ['team', 'goals'];
|
|
35
|
+
for (const field of preserveFields) {
|
|
36
|
+
const existingValue = existing[field];
|
|
37
|
+
const inferredValue = inferred[field];
|
|
38
|
+
// Only preserve if it exists in existing AND is different from inferred
|
|
39
|
+
if (existingValue !== undefined && existingValue !== null &&
|
|
40
|
+
JSON.stringify(existingValue) !== JSON.stringify(inferredValue)) {
|
|
41
|
+
merged[field] = existingValue;
|
|
42
|
+
changes.push({
|
|
43
|
+
field,
|
|
44
|
+
type: 'preserved',
|
|
45
|
+
newValue: existingValue,
|
|
46
|
+
reason: 'User-maintained field',
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// Check for new inferred changes
|
|
51
|
+
for (const key of Object.keys(inferred)) {
|
|
52
|
+
if (preserveFields.includes(key) || manualFields.includes(key)) {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const oldValue = existing[key];
|
|
56
|
+
const newValue = inferred[key];
|
|
57
|
+
if (JSON.stringify(oldValue) !== JSON.stringify(newValue)) {
|
|
58
|
+
if (oldValue === undefined) {
|
|
59
|
+
changes.push({
|
|
60
|
+
field: key,
|
|
61
|
+
type: 'added',
|
|
62
|
+
newValue,
|
|
63
|
+
reason: 'New inferred value',
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
changes.push({
|
|
68
|
+
field: key,
|
|
69
|
+
type: 'modified',
|
|
70
|
+
oldValue,
|
|
71
|
+
newValue,
|
|
72
|
+
reason: 'Codebase changed',
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// Update timestamp
|
|
78
|
+
merged.updatedAt = new Date().toISOString();
|
|
79
|
+
return { merged, changes };
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Merge stack context
|
|
83
|
+
*/
|
|
84
|
+
mergeStack(existing, inferred) {
|
|
85
|
+
const changes = [];
|
|
86
|
+
const merged = { ...inferred };
|
|
87
|
+
// Check for removed dependencies
|
|
88
|
+
const existingDeps = new Set([
|
|
89
|
+
...(existing.frameworks || []),
|
|
90
|
+
...(existing.buildTools || []),
|
|
91
|
+
...(existing.testingFrameworks || []),
|
|
92
|
+
...(existing.styling || []),
|
|
93
|
+
]);
|
|
94
|
+
const inferredDeps = new Set([
|
|
95
|
+
...(inferred.frameworks || []),
|
|
96
|
+
...(inferred.buildTools || []),
|
|
97
|
+
...(inferred.testingFrameworks || []),
|
|
98
|
+
...(inferred.styling || []),
|
|
99
|
+
]);
|
|
100
|
+
for (const dep of existingDeps) {
|
|
101
|
+
if (!inferredDeps.has(dep)) {
|
|
102
|
+
changes.push({
|
|
103
|
+
field: 'dependencies',
|
|
104
|
+
type: 'removed',
|
|
105
|
+
oldValue: dep,
|
|
106
|
+
reason: 'No longer detected in project',
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
for (const dep of inferredDeps) {
|
|
111
|
+
if (!existingDeps.has(dep)) {
|
|
112
|
+
changes.push({
|
|
113
|
+
field: 'dependencies',
|
|
114
|
+
type: 'added',
|
|
115
|
+
newValue: dep,
|
|
116
|
+
reason: 'New dependency detected',
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return { merged, changes };
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Merge architecture context
|
|
124
|
+
*/
|
|
125
|
+
mergeArchitecture(existing, inferred) {
|
|
126
|
+
const changes = [];
|
|
127
|
+
const merged = { ...inferred };
|
|
128
|
+
// Preserve manual patterns
|
|
129
|
+
const manualFields = this.stateManager.getManualFields('architecture.json');
|
|
130
|
+
if (manualFields.includes('patterns')) {
|
|
131
|
+
merged.patterns = existing.patterns;
|
|
132
|
+
changes.push({
|
|
133
|
+
field: 'patterns',
|
|
134
|
+
type: 'preserved',
|
|
135
|
+
newValue: existing.patterns,
|
|
136
|
+
reason: 'Manually specified patterns',
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
// Merge directories (new + preserved manual)
|
|
140
|
+
if (existing.directories && inferred.directories) {
|
|
141
|
+
const existingDirPaths = new Set(existing.directories.map(d => d.path));
|
|
142
|
+
const inferredDirPaths = new Set(inferred.directories.map(d => d.path));
|
|
143
|
+
// Find removed directories
|
|
144
|
+
for (const dir of existing.directories) {
|
|
145
|
+
if (!inferredDirPaths.has(dir.path)) {
|
|
146
|
+
changes.push({
|
|
147
|
+
field: 'directories',
|
|
148
|
+
type: 'removed',
|
|
149
|
+
oldValue: dir.path,
|
|
150
|
+
reason: 'Directory no longer exists',
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
// Find new directories
|
|
155
|
+
for (const dir of inferred.directories) {
|
|
156
|
+
if (!existingDirPaths.has(dir.path)) {
|
|
157
|
+
changes.push({
|
|
158
|
+
field: 'directories',
|
|
159
|
+
type: 'added',
|
|
160
|
+
newValue: dir.path,
|
|
161
|
+
reason: 'New directory detected',
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return { merged, changes };
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Merge constraints context
|
|
170
|
+
*/
|
|
171
|
+
mergeConstraints(existing, inferred) {
|
|
172
|
+
const changes = [];
|
|
173
|
+
const merged = { ...inferred };
|
|
174
|
+
// Preserve user-added preferences
|
|
175
|
+
if (existing.preferences && existing.preferences.length > 0) {
|
|
176
|
+
const manualPreferences = existing.preferences.filter(pref => this.stateManager.isManuallyEdited('constraints.json', `preferences.${pref.category}`));
|
|
177
|
+
merged.preferences = [
|
|
178
|
+
...(inferred.preferences || []),
|
|
179
|
+
...manualPreferences,
|
|
180
|
+
];
|
|
181
|
+
if (manualPreferences.length > 0) {
|
|
182
|
+
changes.push({
|
|
183
|
+
field: 'preferences',
|
|
184
|
+
type: 'preserved',
|
|
185
|
+
newValue: manualPreferences,
|
|
186
|
+
reason: 'User-defined preferences preserved',
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
// Merge mustUse/mustNotUse (combine inferred + manual)
|
|
191
|
+
if (existing.mustUse) {
|
|
192
|
+
const manual = existing.mustUse.filter(item => this.stateManager.isManuallyEdited('constraints.json', `mustUse.${item}`));
|
|
193
|
+
merged.mustUse = [...new Set([...(inferred.mustUse || []), ...manual])];
|
|
194
|
+
}
|
|
195
|
+
if (existing.mustNotUse) {
|
|
196
|
+
const manual = existing.mustNotUse.filter(item => this.stateManager.isManuallyEdited('constraints.json', `mustNotUse.${item}`));
|
|
197
|
+
merged.mustNotUse = [...new Set([...(inferred.mustNotUse || []), ...manual])];
|
|
198
|
+
}
|
|
199
|
+
return { merged, changes };
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Helper to get nested value by path
|
|
203
|
+
*/
|
|
204
|
+
getNestedValue(obj, path) {
|
|
205
|
+
return path.split('.').reduce((curr, key) => curr?.[key], obj);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Helper to set nested value by path
|
|
209
|
+
*/
|
|
210
|
+
setNestedValue(obj, path, value) {
|
|
211
|
+
const keys = path.split('.');
|
|
212
|
+
const lastKey = keys.pop();
|
|
213
|
+
const target = keys.reduce((curr, key) => {
|
|
214
|
+
if (!curr[key])
|
|
215
|
+
curr[key] = {};
|
|
216
|
+
return curr[key];
|
|
217
|
+
}, obj);
|
|
218
|
+
target[lastKey] = value;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
//# sourceMappingURL=merger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merger.js","sourceRoot":"","sources":["../../../src/core/merger.ts"],"names":[],"mappings":"AAoBA;;GAEG;AACH,MAAM,OAAO,aAAa;IACJ;IAApB,YAAoB,YAA0B;QAA1B,iBAAY,GAAZ,YAAY,CAAc;IAAG,CAAC;IAElD;;OAEG;IACH,YAAY,CAAC,QAAiB,EAAE,QAAiB;QAC/C,MAAM,OAAO,GAAkB,EAAE,CAAC;QAClC,MAAM,MAAM,GAAY,EAAE,GAAG,QAAQ,EAAE,CAAC;QAExC,gCAAgC;QAChC,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC;QAEvE,KAAK,MAAM,KAAK,IAAI,YAAY,EAAE,CAAC;YACjC,MAAM,aAAa,GAAG,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;YAC3D,MAAM,aAAa,GAAG,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;YAE3D,IAAI,aAAa,KAAK,SAAS,EAAE,CAAC;gBAChC,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,KAAK,EAAE,aAAa,C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import type { PreludeState, FieldState } from '../schema/state.js';
|
|
2
|
+
/**
|
|
3
|
+
* Manages Prelude state tracking
|
|
4
|
+
*/
|
|
5
|
+
export declare class StateManager {
|
|
6
|
+
private state;
|
|
7
|
+
private contextDir;
|
|
8
|
+
constructor(contextDir: string);
|
|
9
|
+
/**
|
|
10
|
+
* Load state from disk or create new
|
|
11
|
+
*/
|
|
12
|
+
private loadState;
|
|
13
|
+
/**
|
|
14
|
+
* Save state to disk
|
|
15
|
+
*/
|
|
16
|
+
save(): void;
|
|
17
|
+
/**
|
|
18
|
+
* Create backup of current state
|
|
19
|
+
*/
|
|
20
|
+
backup(): void;
|
|
21
|
+
/**
|
|
22
|
+
* Hash a value for change detection
|
|
23
|
+
*/
|
|
24
|
+
private hash;
|
|
25
|
+
/**
|
|
26
|
+
* Track a field as inferred
|
|
27
|
+
*/
|
|
28
|
+
trackInferred(file: string, fieldPath: string, value: any): void;
|
|
29
|
+
/**
|
|
30
|
+
* Track a field as manually edited
|
|
31
|
+
*/
|
|
32
|
+
trackManual(file: string, fieldPath: string, value: any): void;
|
|
33
|
+
/**
|
|
34
|
+
* Check if a field was manually edited
|
|
35
|
+
*/
|
|
36
|
+
isManuallyEdited(file: string, fieldPath: string): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Check if inferred value changed
|
|
39
|
+
*/
|
|
40
|
+
hasInferredChanged(file: string, fieldPath: string, newValue: any): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Get field state
|
|
43
|
+
*/
|
|
44
|
+
getFieldState(file: string, fieldPath: string): FieldState | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Get file state
|
|
47
|
+
*/
|
|
48
|
+
private getFileState;
|
|
49
|
+
/**
|
|
50
|
+
* Get or create file state
|
|
51
|
+
*/
|
|
52
|
+
private getOrCreateFileState;
|
|
53
|
+
/**
|
|
54
|
+
* Get all manually edited fields for a file
|
|
55
|
+
*/
|
|
56
|
+
getManualFields(file: string): string[];
|
|
57
|
+
/**
|
|
58
|
+
* Get current state
|
|
59
|
+
*/
|
|
60
|
+
getState(): PreludeState;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=state-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-manager.d.ts","sourceRoot":"","sources":["../../../src/core/state-manager.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAa,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAQ9E;;GAEG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,KAAK,CAAe;IAC5B,OAAO,CAAC,UAAU,CAAS;gBAEf,UAAU,EAAE,MAAM;IAK9B;;OAEG;IACH,OAAO,CAAC,SAAS;IAejB;;OAEG;IACH,IAAI,IAAI,IAAI;IAgBZ;;OAEG;IACH,MAAM,IAAI,IAAI;IAad;;OAEG;IACH,OAAO,CAAC,IAAI;IAOZ;;OAEG;IACH,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI;IAQhE;;OAEG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI;IAO9D;;OAEG;IACH,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO;IAQ1D;;OAEG;IACH,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,GAAG,OAAO;IAW3E;;OAEG;IACH,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAKtE;;OAEG;IACH,OAAO,CAAC,YAAY;IAIpB;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAe5B;;OAEG;IACH,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE;IASvC;;OAEG;IACH,QAAQ,IAAI,YAAY;CAGzB"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'fs';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import { createHash } from 'crypto';
|
|
4
|
+
import { createInitialState, trackField } from '../schema/state.js';
|
|
5
|
+
const STATE_DIR = '.context/.prelude';
|
|
6
|
+
const STATE_FILE = join(STATE_DIR, 'state.json');
|
|
7
|
+
const HISTORY_DIR = join(STATE_DIR, 'history');
|
|
8
|
+
/**
|
|
9
|
+
* Manages Prelude state tracking
|
|
10
|
+
*/
|
|
11
|
+
export class StateManager {
|
|
12
|
+
state;
|
|
13
|
+
contextDir;
|
|
14
|
+
constructor(contextDir) {
|
|
15
|
+
this.contextDir = contextDir;
|
|
16
|
+
this.state = this.loadState();
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Load state from disk or create new
|
|
20
|
+
*/
|
|
21
|
+
loadState() {
|
|
22
|
+
const statePath = join(this.contextDir, '.prelude', 'state.json');
|
|
23
|
+
if (existsSync(statePath)) {
|
|
24
|
+
try {
|
|
25
|
+
const content = readFileSync(statePath, 'utf-8');
|
|
26
|
+
return JSON.parse(content);
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
console.warn('Failed to load state, creating new:', error);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return createInitialState();
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Save state to disk
|
|
36
|
+
*/
|
|
37
|
+
save() {
|
|
38
|
+
const stateDir = join(this.contextDir, '.prelude');
|
|
39
|
+
const statePath = join(stateDir, 'state.json');
|
|
40
|
+
// Ensure directories exist
|
|
41
|
+
if (!existsSync(stateDir)) {
|
|
42
|
+
mkdirSync(stateDir, { recursive: true });
|
|
43
|
+
}
|
|
44
|
+
// Update timestamp
|
|
45
|
+
this.state.lastUpdate = new Date().toISOString();
|
|
46
|
+
// Write state
|
|
47
|
+
writeFileSync(statePath, JSON.stringify(this.state, null, 2));
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Create backup of current state
|
|
51
|
+
*/
|
|
52
|
+
backup() {
|
|
53
|
+
const historyDir = join(this.contextDir, '.prelude', 'history');
|
|
54
|
+
if (!existsSync(historyDir)) {
|
|
55
|
+
mkdirSync(historyDir, { recursive: true });
|
|
56
|
+
}
|
|
57
|
+
const timestamp = new Date().toISOString().replace(/:/g, '-').replace(/\..+/, '');
|
|
58
|
+
const backupPath = join(historyDir, `${timestamp}.json`);
|
|
59
|
+
writeFileSync(backupPath, JSON.stringify(this.state, null, 2));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Hash a value for change detection
|
|
63
|
+
*/
|
|
64
|
+
hash(value) {
|
|
65
|
+
return createHash('sha256')
|
|
66
|
+
.update(JSON.stringify(value))
|
|
67
|
+
.digest('hex')
|
|
68
|
+
.substring(0, 16);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Track a field as inferred
|
|
72
|
+
*/
|
|
73
|
+
trackInferred(file, fieldPath, value) {
|
|
74
|
+
const fileState = this.getOrCreateFileState(file);
|
|
75
|
+
const valueHash = this.hash(value);
|
|
76
|
+
fileState.fields[fieldPath] = trackField(value, 'inferred', valueHash);
|
|
77
|
+
fileState.lastUpdated = new Date().toISOString();
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Track a field as manually edited
|
|
81
|
+
*/
|
|
82
|
+
trackManual(file, fieldPath, value) {
|
|
83
|
+
const fileState = this.getOrCreateFileState(file);
|
|
84
|
+
fileState.fields[fieldPath] = trackField(value, 'manual');
|
|
85
|
+
fileState.lastUpdated = new Date().toISOString();
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Check if a field was manually edited
|
|
89
|
+
*/
|
|
90
|
+
isManuallyEdited(file, fieldPath) {
|
|
91
|
+
const fileState = this.getFileState(file);
|
|
92
|
+
if (!fileState)
|
|
93
|
+
return false;
|
|
94
|
+
const fieldState = fileState.fields[fieldPath];
|
|
95
|
+
return fieldState?.source === 'manual';
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Check if inferred value changed
|
|
99
|
+
*/
|
|
100
|
+
hasInferredChanged(file, fieldPath, newValue) {
|
|
101
|
+
const fileState = this.getFileState(file);
|
|
102
|
+
if (!fileState)
|
|
103
|
+
return true;
|
|
104
|
+
const fieldState = fileState.fields[fieldPath];
|
|
105
|
+
if (!fieldState)
|
|
106
|
+
return true;
|
|
107
|
+
const newHash = this.hash(newValue);
|
|
108
|
+
return fieldState.inferredHash !== newHash;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Get field state
|
|
112
|
+
*/
|
|
113
|
+
getFieldState(file, fieldPath) {
|
|
114
|
+
const fileState = this.getFileState(file);
|
|
115
|
+
return fileState?.fields[fieldPath];
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Get file state
|
|
119
|
+
*/
|
|
120
|
+
getFileState(file) {
|
|
121
|
+
return this.state.files.find(f => f.file === file);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Get or create file state
|
|
125
|
+
*/
|
|
126
|
+
getOrCreateFileState(file) {
|
|
127
|
+
let fileState = this.getFileState(file);
|
|
128
|
+
if (!fileState) {
|
|
129
|
+
fileState = {
|
|
130
|
+
file,
|
|
131
|
+
lastUpdated: new Date().toISOString(),
|
|
132
|
+
fields: {},
|
|
133
|
+
};
|
|
134
|
+
this.state.files.push(fileState);
|
|
135
|
+
}
|
|
136
|
+
return fileState;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Get all manually edited fields for a file
|
|
140
|
+
*/
|
|
141
|
+
getManualFields(file) {
|
|
142
|
+
const fileState = this.getFileState(file);
|
|
143
|
+
if (!fileState)
|
|
144
|
+
return [];
|
|
145
|
+
return Object.entries(fileState.fields)
|
|
146
|
+
.filter(([_, state]) => state.source === 'manual')
|
|
147
|
+
.map(([path, _]) => path);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Get current state
|
|
151
|
+
*/
|
|
152
|
+
getState() {
|
|
153
|
+
return this.state;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=state-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-manager.js","sourceRoot":"","sources":["../../../src/core/state-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AACxE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGpE,MAAM,SAAS,GAAG,mBAAmB,CAAC;AACtC,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;AACjD,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;AAE/C;;GAEG;AACH,MAAM,OAAO,YAAY;IACf,KAAK,CAAe;IACpB,UAAU,CAAS;IAE3B,YAAY,UAAkB;QAC5B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;IAChC,CAAC;IAED;;OAEG;IACK,SAAS;QACf,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,UAAU,EAAE,YAAY,CAAC,CAAC;QAElE,IAAI,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;YAC1B,IAAI,CAAC;gBACH,MAAM,OAAO,GAAG,YAAY,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;gBACjD,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAC7B,CAAC;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B,CAAC;IAED;;OAEG;IACH,eAAe,CAAC,IAAY;QAC1B,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;QAC1C,IAAI,CAAC,SAAS;YAAE,OAAO,EAAE,CAAC;QAE1B,OAAO,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC;aACpC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,KAAK,QAAQ,CAAC;aACjD,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/runtime/context.ts"],"names":[],"mappings":"AAEA,wBAAgB,kBAAkB,IAAI,MAAM,CAK3C;AAED,wBAAgB,wBAAwB,CAAC,WAAW,EAAE,MAAM,UAU3D"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
export function resolvePreludeRoot() {
|
|
3
|
+
if (process.env.PRELUDE_ROOT) {
|
|
4
|
+
return path.resolve(process.env.PRELUDE_ROOT);
|
|
5
|
+
}
|
|
6
|
+
return path.join(process.cwd(), ".context");
|
|
7
|
+
}
|
|
8
|
+
export function resolveProjectContextDir(projectName) {
|
|
9
|
+
const root = resolvePreludeRoot();
|
|
10
|
+
// If PRELUDE_ROOT is set → external brain mode
|
|
11
|
+
if (process.env.PRELUDE_ROOT) {
|
|
12
|
+
return path.join(root, projectName);
|
|
13
|
+
}
|
|
14
|
+
// Embedded mode
|
|
15
|
+
return root;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/runtime/context.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,MAAM,UAAU,kBAAkB;IAChC,IAAI,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IAChD,CAAC;IACD,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,UAAU,CAAC,CAAC;AAC9C,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,WAAmB;IAC1D,MAAM,IAAI,GAAG,kBAAkB,EAAE,CAAC;IAElC,+CAA+C;IAC/C,IAAI,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;IACtC,CAAC;IAED,gBAAgB;IAChB,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Tracks which fields are inferred vs manually edited
|
|
4
|
+
* Stored in .context/.prelude/state.json
|
|
5
|
+
*/
|
|
6
|
+
export declare const FieldStateSchema: z.ZodObject<{
|
|
7
|
+
value: z.ZodAny;
|
|
8
|
+
source: z.ZodEnum<["inferred", "manual", "merged"]>;
|
|
9
|
+
lastInferred: z.ZodOptional<z.ZodString>;
|
|
10
|
+
lastModified: z.ZodOptional<z.ZodString>;
|
|
11
|
+
inferredHash: z.ZodOptional<z.ZodString>;
|
|
12
|
+
}, "strip", z.ZodTypeAny, {
|
|
13
|
+
source: "inferred" | "manual" | "merged";
|
|
14
|
+
value?: any;
|
|
15
|
+
lastInferred?: string | undefined;
|
|
16
|
+
lastModified?: string | undefined;
|
|
17
|
+
inferredHash?: string | undefined;
|
|
18
|
+
}, {
|
|
19
|
+
source: "inferred" | "manual" | "merged";
|
|
20
|
+
value?: any;
|
|
21
|
+
lastInferred?: string | undefined;
|
|
22
|
+
lastModified?: string | undefined;
|
|
23
|
+
inferredHash?: string | undefined;
|
|
24
|
+
}>;
|
|
25
|
+
export declare const FileStateSchema: z.ZodObject<{
|
|
26
|
+
file: z.ZodString;
|
|
27
|
+
lastUpdated: z.ZodString;
|
|
28
|
+
fields: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
29
|
+
value: z.ZodAny;
|
|
30
|
+
source: z.ZodEnum<["inferred", "manual", "merged"]>;
|
|
31
|
+
lastInferred: z.ZodOptional<z.ZodString>;
|
|
32
|
+
lastModified: z.ZodOptional<z.ZodString>;
|
|
33
|
+
inferredHash: z.ZodOptional<z.ZodString>;
|
|
34
|
+
}, "strip", z.ZodTypeAny, {
|
|
35
|
+
source: "inferred" | "manual" | "merged";
|
|
36
|
+
value?: any;
|
|
37
|
+
lastInferred?: string | undefined;
|
|
38
|
+
lastModified?: string | undefined;
|
|
39
|
+
inferredHash?: string | undefined;
|
|
40
|
+
}, {
|
|
41
|
+
source: "inferred" | "manual" | "merged";
|
|
42
|
+
value?: any;
|
|
43
|
+
lastInferred?: string | undefined;
|
|
44
|
+
lastModified?: string | undefined;
|
|
45
|
+
inferredHash?: string | undefined;
|
|
46
|
+
}>>;
|
|
47
|
+
}, "strip", z.ZodTypeAny, {
|
|
48
|
+
file: string;
|
|
49
|
+
lastUpdated: string;
|
|
50
|
+
fields: Record<string, {
|
|
51
|
+
source: "inferred" | "manual" | "merged";
|
|
52
|
+
value?: any;
|
|
53
|
+
lastInferred?: string | undefined;
|
|
54
|
+
lastModified?: string | undefined;
|
|
55
|
+
inferredHash?: string | undefined;
|
|
56
|
+
}>;
|
|
57
|
+
}, {
|
|
58
|
+
file: string;
|
|
59
|
+
lastUpdated: string;
|
|
60
|
+
fields: Record<string, {
|
|
61
|
+
source: "inferred" | "manual" | "merged";
|
|
62
|
+
value?: any;
|
|
63
|
+
lastInferred?: string | undefined;
|
|
64
|
+
lastModified?: string | undefined;
|
|
65
|
+
inferredHash?: string | undefined;
|
|
66
|
+
}>;
|
|
67
|
+
}>;
|
|
68
|
+
export declare const PreludeStateSchema: z.ZodObject<{
|
|
69
|
+
version: z.ZodDefault<z.ZodString>;
|
|
70
|
+
initialized: z.ZodString;
|
|
71
|
+
lastUpdate: z.ZodString;
|
|
72
|
+
files: z.ZodArray<z.ZodObject<{
|
|
73
|
+
file: z.ZodString;
|
|
74
|
+
lastUpdated: z.ZodString;
|
|
75
|
+
fields: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
76
|
+
value: z.ZodAny;
|
|
77
|
+
source: z.ZodEnum<["inferred", "manual", "merged"]>;
|
|
78
|
+
lastInferred: z.ZodOptional<z.ZodString>;
|
|
79
|
+
lastModified: z.ZodOptional<z.ZodString>;
|
|
80
|
+
inferredHash: z.ZodOptional<z.ZodString>;
|
|
81
|
+
}, "strip", z.ZodTypeAny, {
|
|
82
|
+
source: "inferred" | "manual" | "merged";
|
|
83
|
+
value?: any;
|
|
84
|
+
lastInferred?: string | undefined;
|
|
85
|
+
lastModified?: string | undefined;
|
|
86
|
+
inferredHash?: string | undefined;
|
|
87
|
+
}, {
|
|
88
|
+
source: "inferred" | "manual" | "merged";
|
|
89
|
+
value?: any;
|
|
90
|
+
lastInferred?: string | undefined;
|
|
91
|
+
lastModified?: string | undefined;
|
|
92
|
+
inferredHash?: string | undefined;
|
|
93
|
+
}>>;
|
|
94
|
+
}, "strip", z.ZodTypeAny, {
|
|
95
|
+
file: string;
|
|
96
|
+
lastUpdated: string;
|
|
97
|
+
fields: Record<string, {
|
|
98
|
+
source: "inferred" | "manual" | "merged";
|
|
99
|
+
value?: any;
|
|
100
|
+
lastInferred?: string | undefined;
|
|
101
|
+
lastModified?: string | undefined;
|
|
102
|
+
inferredHash?: string | undefined;
|
|
103
|
+
}>;
|
|
104
|
+
}, {
|
|
105
|
+
file: string;
|
|
106
|
+
lastUpdated: string;
|
|
107
|
+
fields: Record<string, {
|
|
108
|
+
source: "inferred" | "manual" | "merged";
|
|
109
|
+
value?: any;
|
|
110
|
+
lastInferred?: string | undefined;
|
|
111
|
+
lastModified?: string | undefined;
|
|
112
|
+
inferredHash?: string | undefined;
|
|
113
|
+
}>;
|
|
114
|
+
}>, "many">;
|
|
115
|
+
}, "strip", z.ZodTypeAny, {
|
|
116
|
+
version: string;
|
|
117
|
+
files: {
|
|
118
|
+
file: string;
|
|
119
|
+
lastUpdated: string;
|
|
120
|
+
fields: Record<string, {
|
|
121
|
+
source: "inferred" | "manual" | "merged";
|
|
122
|
+
value?: any;
|
|
123
|
+
lastInferred?: string | undefined;
|
|
124
|
+
lastModified?: string | undefined;
|
|
125
|
+
inferredHash?: string | undefined;
|
|
126
|
+
}>;
|
|
127
|
+
}[];
|
|
128
|
+
initialized: string;
|
|
129
|
+
lastUpdate: string;
|
|
130
|
+
}, {
|
|
131
|
+
files: {
|
|
132
|
+
file: string;
|
|
133
|
+
lastUpdated: string;
|
|
134
|
+
fields: Record<string, {
|
|
135
|
+
source: "inferred" | "manual" | "merged";
|
|
136
|
+
value?: any;
|
|
137
|
+
lastInferred?: string | undefined;
|
|
138
|
+
lastModified?: string | undefined;
|
|
139
|
+
inferredHash?: string | undefined;
|
|
140
|
+
}>;
|
|
141
|
+
}[];
|
|
142
|
+
initialized: string;
|
|
143
|
+
lastUpdate: string;
|
|
144
|
+
version?: string | undefined;
|
|
145
|
+
}>;
|
|
146
|
+
export type FieldState = z.infer<typeof FieldStateSchema>;
|
|
147
|
+
export type FileState = z.infer<typeof FileStateSchema>;
|
|
148
|
+
export type PreludeState = z.infer<typeof PreludeStateSchema>;
|
|
149
|
+
/**
|
|
150
|
+
* Helper to create initial state
|
|
151
|
+
*/
|
|
152
|
+
export declare function createInitialState(): PreludeState;
|
|
153
|
+
/**
|
|
154
|
+
* Helper to track a field
|
|
155
|
+
*/
|
|
156
|
+
export declare function trackField(value: any, source: 'inferred' | 'manual' | 'merged', inferredHash?: string): FieldState;
|
|
157
|
+
//# sourceMappingURL=state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/schema/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;GAGG;AAEH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;EAM3B,CAAC;AAEH,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAI1B,CAAC;AAEH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAK7B,CAAC;AAEH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAC1D,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AACxD,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE9D;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,YAAY,CAQjD;AAED;;GAEG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,GAAG,EACV,MAAM,EAAE,UAAU,GAAG,QAAQ,GAAG,QAAQ,EACxC,YAAY,CAAC,EAAE,MAAM,GACpB,UAAU,CASZ"}
|