ultracode 5.4.0 → 5.6.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/dist/chunks/analysis-tool-handlers-GH5FDEWW.js +817 -0
- package/dist/chunks/analysis-tool-handlers-IXP4MWZX.js +817 -0
- package/dist/chunks/analysis-tool-handlers-LC2BTQYK.js +13 -0
- package/dist/chunks/analysis-tool-handlers-QYFKQPFL.js +817 -0
- package/dist/chunks/autodoc-tool-handlers-2HF6ERYN.js +1112 -0
- package/dist/chunks/autodoc-tool-handlers-4OGQJ7C3.js +1112 -0
- package/dist/chunks/autodoc-tool-handlers-N736CB56.js +138 -0
- package/dist/chunks/autodoc-tool-handlers-NQYBY6U4.js +1112 -0
- package/dist/chunks/branch-tool-handlers-KW3H4FJK.js +276 -0
- package/dist/chunks/branch-tool-handlers-QOUDZKJ2.js +276 -0
- package/dist/chunks/branch-tool-handlers-RB2U36KI.js +2 -0
- package/dist/chunks/branch-tool-handlers-ZHJM6PDK.js +276 -0
- package/dist/chunks/chunk-2Z6OQPYC.js +656 -0
- package/dist/chunks/chunk-3MQ7LRPN.js +322 -0
- package/dist/chunks/chunk-4W6QYGXZ.js +10 -0
- package/dist/chunks/chunk-533NFGUG.js +1 -0
- package/dist/chunks/chunk-5NUPOPWM.js +1 -0
- package/dist/chunks/chunk-AK4HIPA2.js +322 -0
- package/dist/chunks/chunk-B3H5NS3I.js +656 -0
- package/dist/chunks/chunk-DPTZHDST.js +4 -0
- package/dist/chunks/chunk-E5HQWLU5.js +322 -0
- package/dist/chunks/chunk-EOH25B5P.js +572 -0
- package/dist/chunks/chunk-ESV6F6E3.js +3179 -0
- package/dist/chunks/chunk-FPELPFER.js +924 -0
- package/dist/chunks/chunk-G6J42I55.js +161 -0
- package/dist/chunks/chunk-GCQE7ZYW.js +1 -0
- package/dist/chunks/chunk-GTIF6MOX.js +1 -0
- package/dist/chunks/chunk-I6STSSAK.js +2 -0
- package/dist/chunks/chunk-J2WBGTK2.js +4697 -0
- package/dist/chunks/chunk-KAYOX5EB.js +4697 -0
- package/dist/chunks/chunk-KPMTACOT.js +656 -0
- package/dist/chunks/chunk-L376GZ44.js +3179 -0
- package/dist/chunks/chunk-LCTOTHDA.js +15 -0
- package/dist/chunks/chunk-LEDJ7GVQ.js +316 -0
- package/dist/chunks/chunk-LH4OUKNZ.js +277 -0
- package/dist/chunks/chunk-O6IE2MEZ.js +161 -0
- package/dist/chunks/chunk-OEXPCY3F.js +316 -0
- package/dist/chunks/chunk-OMXOLFDN.js +924 -0
- package/dist/chunks/chunk-PLPBXWOU.js +3179 -0
- package/dist/chunks/chunk-PWLE5DN2.js +572 -0
- package/dist/chunks/chunk-PY43JPWL.js +447 -0
- package/dist/chunks/chunk-Q3B4EB7A.js +15 -0
- package/dist/chunks/chunk-Q5LPVLXA.js +337 -0
- package/dist/chunks/chunk-QIRZHZK2.js +5 -0
- package/dist/chunks/chunk-ROQ27LSL.js +924 -0
- package/dist/chunks/chunk-S5Q7BD6J.js +572 -0
- package/dist/chunks/chunk-SAMX3HJQ.js +337 -0
- package/dist/chunks/chunk-SV3WKUNV.js +1 -0
- package/dist/chunks/chunk-TCHCDCDO.js +167 -0
- package/dist/chunks/chunk-TR3HS7U6.js +316 -0
- package/dist/chunks/chunk-TUWE6FCW.js +167 -0
- package/dist/chunks/chunk-TVOTA7EE.js +277 -0
- package/dist/chunks/chunk-VS44D772.js +337 -0
- package/dist/chunks/chunk-WIE3G5ES.js +167 -0
- package/dist/chunks/chunk-XG3ACLWR.js +5 -0
- package/dist/chunks/chunk-XJ2Z5QQO.js +1 -0
- package/dist/chunks/chunk-XK2NY7RB.js +277 -0
- package/dist/chunks/chunk-Y4F7NZFZ.js +4700 -0
- package/dist/chunks/chunk-YS75L3ZS.js +161 -0
- package/dist/chunks/chunk-ZVG5HHI3.js +15 -0
- package/dist/chunks/dev-agent-DDDIVWOF.js +1 -0
- package/dist/chunks/dev-agent-E2VCFKXN.js +1624 -0
- package/dist/chunks/dev-agent-KJNSU5KQ.js +1624 -0
- package/dist/chunks/dev-agent-NDERYIPV.js +1624 -0
- package/dist/chunks/faiss-provider-7R4BQDIV.js +12 -0
- package/dist/chunks/faiss-provider-7ZFRSDN5.js +12 -0
- package/dist/chunks/faiss-provider-SXB7FTLB.js +1 -0
- package/dist/chunks/faiss-provider-TKLBEUSH.js +12 -0
- package/dist/chunks/file-tool-handlers-5DODQXGF.js +1027 -0
- package/dist/chunks/file-tool-handlers-KGHLE4KR.js +1027 -0
- package/dist/chunks/file-tool-handlers-KTOQ4NFS.js +12 -0
- package/dist/chunks/file-tool-handlers-V4SFUDQB.js +1027 -0
- package/dist/chunks/graph-metrics-tool-handlers-3AV4X4ZY.js +65 -0
- package/dist/chunks/graph-metrics-tool-handlers-3VMDQHJ6.js +65 -0
- package/dist/chunks/graph-metrics-tool-handlers-BZ6E6YHF.js +1 -0
- package/dist/chunks/graph-metrics-tool-handlers-IYBGSXL7.js +65 -0
- package/dist/chunks/graph-storage-factory-2CQ2RPDV.js +13 -0
- package/dist/chunks/graph-storage-factory-C5SMMYL6.js +13 -0
- package/dist/chunks/graph-storage-factory-EEO2V3GJ.js +1 -0
- package/dist/chunks/graph-storage-factory-WBCTXP34.js +13 -0
- package/dist/chunks/history-tool-handlers-AS7OQFZI.js +1 -0
- package/dist/chunks/history-tool-handlers-FSNJYXV2.js +208 -0
- package/dist/chunks/history-tool-handlers-JZAH4EIQ.js +208 -0
- package/dist/chunks/history-tool-handlers-KCSCXZ7T.js +208 -0
- package/dist/chunks/incremental-updater-A2EL4QXU.js +14 -0
- package/dist/chunks/incremental-updater-EQIKBVY2.js +14 -0
- package/dist/chunks/incremental-updater-JFGRPH3B.js +14 -0
- package/dist/chunks/incremental-updater-S5BAAGHP.js +1 -0
- package/dist/chunks/indexer-agent-ASKY7JPG.js +1 -0
- package/dist/chunks/indexer-agent-NKAOF323.js +21 -0
- package/dist/chunks/indexer-agent-PJN5IOKQ.js +21 -0
- package/dist/chunks/indexer-agent-WRJFWKZX.js +21 -0
- package/dist/chunks/indexing-pipeline-D4P2O72Z.js +249 -0
- package/dist/chunks/indexing-pipeline-L7C543N4.js +1 -0
- package/dist/chunks/indexing-pipeline-NHPRN3AB.js +249 -0
- package/dist/chunks/indexing-pipeline-ZAXCZU22.js +249 -0
- package/dist/chunks/layered-faiss-provider-62CNW54X.js +1 -0
- package/dist/chunks/layered-faiss-provider-O7L77GFX.js +12 -0
- package/dist/chunks/layered-faiss-provider-RVHLHLPK.js +12 -0
- package/dist/chunks/layered-faiss-provider-YT7EDIJI.js +12 -0
- package/dist/chunks/merge-agent-3RF7VFF5.js +2481 -0
- package/dist/chunks/merge-agent-JCKTCBCE.js +2481 -0
- package/dist/chunks/merge-agent-VCL7OXPN.js +2481 -0
- package/dist/chunks/merge-agent-ZGK24WVF.js +11 -0
- package/dist/chunks/merge-tool-handlers-GV2LOIKU.js +277 -0
- package/dist/chunks/merge-tool-handlers-TYDWU5X2.js +277 -0
- package/dist/chunks/merge-tool-handlers-U7X2ZO2M.js +1 -0
- package/dist/chunks/merge-tool-handlers-YH62ZLPJ.js +277 -0
- package/dist/chunks/pattern-tool-handlers-76NF5JDS.js +13 -0
- package/dist/chunks/pattern-tool-handlers-IJAGEIVD.js +1549 -0
- package/dist/chunks/pattern-tool-handlers-VA5WYA62.js +1549 -0
- package/dist/chunks/pattern-tool-handlers-WQ6UBMJS.js +1549 -0
- package/dist/chunks/query-agent-36ADGCFZ.js +1 -0
- package/dist/chunks/query-agent-H22CR5N5.js +191 -0
- package/dist/chunks/query-agent-K2UGZS4M.js +191 -0
- package/dist/chunks/query-agent-YJCEHOXD.js +191 -0
- package/dist/chunks/semantic-agent-AC7CBEDE.js +6381 -0
- package/dist/chunks/semantic-agent-HK5X6CKU.js +6381 -0
- package/dist/chunks/semantic-agent-KONIKEGW.js +6381 -0
- package/dist/chunks/semantic-agent-LH6IZ2L7.js +137 -0
- package/dist/chunks/semantic-tool-handlers-5LMSH2U7.js +3 -0
- package/dist/chunks/semantic-tool-handlers-735UMO7Y.js +817 -0
- package/dist/chunks/semantic-tool-handlers-BNUYPP7X.js +817 -0
- package/dist/chunks/semantic-tool-handlers-MYZPEUD2.js +817 -0
- package/dist/chunks/snapshot-tool-handlers-6SIHZT2F.js +201 -0
- package/dist/chunks/snapshot-tool-handlers-DS4P3KOT.js +201 -0
- package/dist/chunks/snapshot-tool-handlers-JYHRFPC7.js +201 -0
- package/dist/chunks/snapshot-tool-handlers-YEHMAT3L.js +1 -0
- package/dist/chunks/storage-paths-A3C7WHHG.js +8 -0
- package/dist/chunks/storage-paths-HDYH7WPM.js +1 -0
- package/dist/chunks/storage-paths-IMFRHBWF.js +8 -0
- package/dist/chunks/storage-paths-P3PUSMUD.js +8 -0
- package/dist/chunks/taint-tool-handlers-CWESOOMQ.js +68 -0
- package/dist/chunks/taint-tool-handlers-OG3NVVP3.js +1 -0
- package/dist/chunks/taint-tool-handlers-ON3G3FA7.js +68 -0
- package/dist/chunks/taint-tool-handlers-P4P5J6DB.js +68 -0
- package/dist/chunks/tracing-tool-handlers-4BDCXTZZ.js +3935 -0
- package/dist/chunks/tracing-tool-handlers-6FPNM7HX.js +3935 -0
- package/dist/chunks/tracing-tool-handlers-LQTQ5SKK.js +89 -0
- package/dist/chunks/tracing-tool-handlers-XRQX2DTS.js +3935 -0
- package/dist/chunks/validation-tool-handlers-DZUG7KYY.js +2 -0
- package/dist/chunks/validation-tool-handlers-O6TGFSH5.js +555 -0
- package/dist/chunks/validation-tool-handlers-RREUYKIR.js +555 -0
- package/dist/chunks/validation-tool-handlers-XPWSMS37.js +555 -0
- package/dist/index.js +13 -13
- package/dist/roslyn-addon/.build-hash +1 -1
- package/dist/roslyn-addon/ILGPU.Algorithms.dll +0 -0
- package/dist/roslyn-addon/ILGPU.dll +0 -0
- package/dist/roslyn-addon/UltraCode.CSharp.deps.json +35 -0
- package/dist/roslyn-addon/UltraCode.CSharp.dll +0 -0
- package/package.json +1 -1
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import { init_logging, log } from './chunk-VCCBEJQ5.js';
|
|
2
|
+
|
|
3
|
+
// src/core/di-container.ts
|
|
4
|
+
init_logging();
|
|
5
|
+
var DIContainer = class _DIContainer {
|
|
6
|
+
services = /* @__PURE__ */ new Map();
|
|
7
|
+
resolutionStack = /* @__PURE__ */ new Set();
|
|
8
|
+
disposed = false;
|
|
9
|
+
constructor() {
|
|
10
|
+
this.registerInstance("DIContainer", this);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Register a service with factory function
|
|
14
|
+
*/
|
|
15
|
+
register(name, factory, lifetime = "singleton" /* SINGLETON */, dependencies = []) {
|
|
16
|
+
this.ensureNotDisposed();
|
|
17
|
+
if (this.services.has(name)) {
|
|
18
|
+
throw new Error(`Service '${name}' is already registered`);
|
|
19
|
+
}
|
|
20
|
+
const descriptor = {
|
|
21
|
+
name,
|
|
22
|
+
factory,
|
|
23
|
+
lifetime,
|
|
24
|
+
dependencies
|
|
25
|
+
};
|
|
26
|
+
this.services.set(name, descriptor);
|
|
27
|
+
log.i("DICONTAINER", "svc_registered", { name, lifetime });
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Register a singleton service (convenience method)
|
|
31
|
+
*/
|
|
32
|
+
registerSingleton(name, factory, dependencies = []) {
|
|
33
|
+
this.register(name, factory, "singleton" /* SINGLETON */, dependencies);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Register a transient service (convenience method)
|
|
37
|
+
*/
|
|
38
|
+
registerTransient(name, factory, dependencies = []) {
|
|
39
|
+
this.register(name, factory, "transient" /* TRANSIENT */, dependencies);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Register an existing instance as singleton
|
|
43
|
+
*/
|
|
44
|
+
registerInstance(name, instance) {
|
|
45
|
+
this.ensureNotDisposed();
|
|
46
|
+
if (this.services.has(name)) {
|
|
47
|
+
throw new Error(`Service '${name}' is already registered`);
|
|
48
|
+
}
|
|
49
|
+
const descriptor = {
|
|
50
|
+
name,
|
|
51
|
+
factory: () => instance,
|
|
52
|
+
lifetime: "singleton" /* SINGLETON */,
|
|
53
|
+
instance
|
|
54
|
+
};
|
|
55
|
+
this.services.set(name, descriptor);
|
|
56
|
+
log.i("DICONTAINER", "inst_registered", { name });
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Update an existing singleton instance (useful for project context switches)
|
|
60
|
+
*/
|
|
61
|
+
updateInstance(name, instance) {
|
|
62
|
+
this.ensureNotDisposed();
|
|
63
|
+
const descriptor = this.services.get(name);
|
|
64
|
+
if (!descriptor) {
|
|
65
|
+
this.registerInstance(name, instance);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (descriptor.lifetime !== "singleton" /* SINGLETON */) {
|
|
69
|
+
throw new Error(`Cannot update non-singleton service '${name}'`);
|
|
70
|
+
}
|
|
71
|
+
descriptor.instance = instance;
|
|
72
|
+
descriptor.factory = () => instance;
|
|
73
|
+
log.i("DICONTAINER", "inst_updated", { name });
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Register an agent factory
|
|
77
|
+
*/
|
|
78
|
+
registerAgent(agentType, factory, dependencies = []) {
|
|
79
|
+
const serviceName = `Agent:${agentType}`;
|
|
80
|
+
this.register(serviceName, factory, "singleton" /* SINGLETON */, dependencies);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Resolve a service by name with circular dependency detection
|
|
84
|
+
*/
|
|
85
|
+
async resolve(name) {
|
|
86
|
+
this.ensureNotDisposed();
|
|
87
|
+
const descriptor = this.services.get(name);
|
|
88
|
+
if (!descriptor) {
|
|
89
|
+
throw new Error(`Service '${name}' is not registered`);
|
|
90
|
+
}
|
|
91
|
+
if (this.resolutionStack.has(name)) {
|
|
92
|
+
const cycle = Array.from(this.resolutionStack).join(" -> ");
|
|
93
|
+
throw new Error(`Circular dependency detected: ${cycle} -> ${name}`);
|
|
94
|
+
}
|
|
95
|
+
if (descriptor.lifetime === "singleton" /* SINGLETON */ && descriptor.instance !== void 0) {
|
|
96
|
+
return descriptor.instance;
|
|
97
|
+
}
|
|
98
|
+
this.resolutionStack.add(name);
|
|
99
|
+
try {
|
|
100
|
+
const instance = await descriptor.factory(this);
|
|
101
|
+
if (descriptor.lifetime === "singleton" /* SINGLETON */) {
|
|
102
|
+
descriptor.instance = instance;
|
|
103
|
+
}
|
|
104
|
+
return instance;
|
|
105
|
+
} finally {
|
|
106
|
+
this.resolutionStack.delete(name);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Resolve an agent by type
|
|
111
|
+
*/
|
|
112
|
+
async resolveAgent(agentType) {
|
|
113
|
+
const serviceName = `Agent:${agentType}`;
|
|
114
|
+
return this.resolve(serviceName);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Check if service is registered
|
|
118
|
+
*/
|
|
119
|
+
has(name) {
|
|
120
|
+
return this.services.has(name);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Check if agent is registered
|
|
124
|
+
*/
|
|
125
|
+
hasAgent(agentType) {
|
|
126
|
+
return this.has(`Agent:${agentType}`);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Get all registered service names
|
|
130
|
+
*/
|
|
131
|
+
getServiceNames() {
|
|
132
|
+
return Array.from(this.services.keys());
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Get all registered agent types
|
|
136
|
+
*/
|
|
137
|
+
getAgentTypes() {
|
|
138
|
+
const agentTypes = [];
|
|
139
|
+
for (const name of this.services.keys()) {
|
|
140
|
+
if (name.startsWith("Agent:")) {
|
|
141
|
+
agentTypes.push(name.slice(6));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return agentTypes;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Get dependency graph for a service
|
|
148
|
+
*/
|
|
149
|
+
getDependencyGraph(name) {
|
|
150
|
+
const descriptor = this.services.get(name);
|
|
151
|
+
if (!descriptor) {
|
|
152
|
+
return [];
|
|
153
|
+
}
|
|
154
|
+
return descriptor.dependencies || [];
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Clear all transient instances (keep singletons)
|
|
158
|
+
*/
|
|
159
|
+
clearTransients() {
|
|
160
|
+
for (const descriptor of this.services.values()) {
|
|
161
|
+
if (descriptor.lifetime === "transient" /* TRANSIENT */) {
|
|
162
|
+
delete descriptor.instance;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
log.i("DICONTAINER", "transients_cleared");
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Clear cached agent instances (to force recreation with new context)
|
|
169
|
+
* Used when project context switches and agents need new SQLiteManager
|
|
170
|
+
*/
|
|
171
|
+
clearAgentInstances() {
|
|
172
|
+
let cleared = 0;
|
|
173
|
+
for (const [name, descriptor] of this.services) {
|
|
174
|
+
if (name.startsWith("Agent:") && descriptor.instance !== void 0) {
|
|
175
|
+
delete descriptor.instance;
|
|
176
|
+
cleared++;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
log.i("DICONTAINER", "agents_cleared", { count: cleared });
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Clear all registrations (useful for testing)
|
|
183
|
+
*/
|
|
184
|
+
clear() {
|
|
185
|
+
this.services.clear();
|
|
186
|
+
this.resolutionStack.clear();
|
|
187
|
+
this.disposed = false;
|
|
188
|
+
log.i("DICONTAINER", "container_cleared");
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Dispose all services and clear container
|
|
192
|
+
*/
|
|
193
|
+
async dispose() {
|
|
194
|
+
if (this.disposed) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
log.i("DICONTAINER", "disposing");
|
|
198
|
+
this.disposed = true;
|
|
199
|
+
const descriptors = Array.from(this.services.values()).reverse();
|
|
200
|
+
for (const descriptor of descriptors) {
|
|
201
|
+
if (descriptor.instance && this.isDisposable(descriptor.instance)) {
|
|
202
|
+
try {
|
|
203
|
+
await descriptor.instance.dispose();
|
|
204
|
+
log.i("DICONTAINER", "disposed_svc", { name: descriptor.name });
|
|
205
|
+
} catch (error) {
|
|
206
|
+
log.w("DICONTAINER", "dispose_fail", { name: descriptor.name, err: String(error) });
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
this.services.clear();
|
|
211
|
+
this.resolutionStack.clear();
|
|
212
|
+
log.i("DICONTAINER", "disposed");
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Check if object implements Disposable interface
|
|
216
|
+
*/
|
|
217
|
+
isDisposable(obj) {
|
|
218
|
+
return obj !== null && typeof obj === "object" && "dispose" in obj && typeof obj.dispose === "function";
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Ensure container is not disposed
|
|
222
|
+
*/
|
|
223
|
+
ensureNotDisposed() {
|
|
224
|
+
if (this.disposed) {
|
|
225
|
+
throw new Error("DIContainer has been disposed");
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Create a child container (scoped)
|
|
230
|
+
*/
|
|
231
|
+
createScope() {
|
|
232
|
+
const scope = new _DIContainer();
|
|
233
|
+
for (const [name, descriptor] of this.services) {
|
|
234
|
+
if (descriptor.lifetime === "singleton" /* SINGLETON */) {
|
|
235
|
+
scope.services.set(name, { ...descriptor, instance: void 0 });
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return scope;
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
var globalContainer = null;
|
|
242
|
+
function getGlobalContainer() {
|
|
243
|
+
if (!globalContainer) {
|
|
244
|
+
globalContainer = new DIContainer();
|
|
245
|
+
}
|
|
246
|
+
return globalContainer;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// src/core/agent-registry.ts
|
|
250
|
+
init_logging();
|
|
251
|
+
async function registerAllAgents(container) {
|
|
252
|
+
log.i("AGENTREG", "registering_all");
|
|
253
|
+
container.registerAgent("dev" /* DEV */, async (_c) => {
|
|
254
|
+
const { DevAgent } = await import('./dev-agent-KJNSU5KQ.js');
|
|
255
|
+
return new DevAgent();
|
|
256
|
+
});
|
|
257
|
+
container.registerAgent("semantic" /* SEMANTIC */, async (_c) => {
|
|
258
|
+
const { SemanticAgent } = await import('./semantic-agent-HK5X6CKU.js');
|
|
259
|
+
return new SemanticAgent();
|
|
260
|
+
});
|
|
261
|
+
container.registerAgent("dora" /* DORA */, async (_c) => {
|
|
262
|
+
const { DoraAgent } = await import('./dora-agent-NNYRSIBQ.js');
|
|
263
|
+
return new DoraAgent();
|
|
264
|
+
});
|
|
265
|
+
container.registerAgent("parser" /* PARSER */, async (_c) => {
|
|
266
|
+
const { ParserAgent } = await import('./parser-agent-FCJ2YDLD.js');
|
|
267
|
+
return new ParserAgent();
|
|
268
|
+
});
|
|
269
|
+
container.registerAgent("indexer" /* INDEXER */, async (_c) => {
|
|
270
|
+
const { IndexerAgent } = await import('./indexer-agent-WRJFWKZX.js');
|
|
271
|
+
const agent = new IndexerAgent();
|
|
272
|
+
await agent.initialize();
|
|
273
|
+
return agent;
|
|
274
|
+
});
|
|
275
|
+
container.registerAgent("query" /* QUERY */, async (_c) => {
|
|
276
|
+
const { QueryAgent } = await import('./query-agent-H22CR5N5.js');
|
|
277
|
+
return new QueryAgent();
|
|
278
|
+
});
|
|
279
|
+
container.registerAgent("merge" /* MERGE */, async (_c) => {
|
|
280
|
+
const { MergeAgent } = await import('./merge-agent-3RF7VFF5.js');
|
|
281
|
+
let repoPath = process.cwd();
|
|
282
|
+
let branchManager;
|
|
283
|
+
try {
|
|
284
|
+
const config = await _c.resolve("Config");
|
|
285
|
+
if (config?.directory) {
|
|
286
|
+
repoPath = config.directory;
|
|
287
|
+
}
|
|
288
|
+
} catch {
|
|
289
|
+
}
|
|
290
|
+
try {
|
|
291
|
+
branchManager = await _c.resolve("BranchManager");
|
|
292
|
+
} catch {
|
|
293
|
+
}
|
|
294
|
+
return new MergeAgent({
|
|
295
|
+
repoPath,
|
|
296
|
+
fastPathEnabled: true,
|
|
297
|
+
semanticMatchingEnabled: true,
|
|
298
|
+
semanticThreshold: 0.7,
|
|
299
|
+
autoResolveConflicts: false,
|
|
300
|
+
branchManager
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
log.i("AGENTREG", "all_registered");
|
|
304
|
+
}
|
|
305
|
+
async function getOrCreateAgent(container, conductor, agentType) {
|
|
306
|
+
const existing = conductor.getAgentsByType(agentType);
|
|
307
|
+
if (existing.length > 0) {
|
|
308
|
+
return existing[0];
|
|
309
|
+
}
|
|
310
|
+
if (!container.hasAgent(agentType)) {
|
|
311
|
+
throw new Error(`Agent ${agentType} is not registered in DI container`);
|
|
312
|
+
}
|
|
313
|
+
const agent = await container.resolveAgent(agentType);
|
|
314
|
+
await agent.initialize();
|
|
315
|
+
log.i("AGENTREG", "agent_init", { type: agentType });
|
|
316
|
+
conductor.register(agent);
|
|
317
|
+
return agent;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
export { getGlobalContainer, getOrCreateAgent, registerAllAgents };
|
|
321
|
+
//# sourceMappingURL=chunk-3MQ7LRPN.js.map
|
|
322
|
+
//# sourceMappingURL=chunk-3MQ7LRPN.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {d}from'./chunk-PY43JPWL.js';import {existsSync,readFileSync,writeFileSync}from'fs';import N from'path';function b(c){let a=[],o=/(?:`([^`]+\.(?:ts|js|tsx|jsx|py|go|rs|java|kt|swift|cpp|c|h)):(\d+)`|([a-zA-Z0-9_\-/.]+\.(?:ts|js|tsx|jsx|py|go|rs|java|kt|swift|cpp|c|h)):(\d+))/g,e;for(;(e=o.exec(c))!==null;){let n=e[1]||e[3],s=e[2]||e[4];n&&s&&a.push({original:e[0],filePath:n,lineNumber:parseInt(s,10),startIndex:e.index,endIndex:e.index+e[0].length});}let i=/\[([^\]]+)\]\(([^)]+\.(?:ts|js|tsx|jsx|py|go|rs|java|kt|swift|cpp|c|h))(?:#L(\d+))?\)/g;for(;(e=i.exec(c))!==null;){let n=e[2];n&&a.push({original:e[0],filePath:n,lineNumber:e[3]?parseInt(e[3],10):void 0,startIndex:e.index,endIndex:e.index+e[0].length});}return a}function h(c){let a=c.split(`
|
|
2
|
+
`),o=[],e=null,i=[];for(let n=0;n<a.length;n++){let s=a[n]??"",r=s.match(/^(#{1,6})\s+(.+)$/);if(r?.[2])e&&(e.content=i.join(`
|
|
3
|
+
`),e.endLine=n-1,o.push(e)),e={title:r[2],content:"",startLine:n,endLine:n,relatedEntities:[]},i=[];else if(e){i.push(s);let l=s.match(/`([A-Z][a-zA-Z0-9_]+)`/g);if(l)for(let d of l){let t=d.slice(1,-1);e.relatedEntities.includes(t)||e.relatedEntities.push(t);}}}return e&&(e.content=i.join(`
|
|
4
|
+
`),e.endLine=a.length-1,o.push(e)),o}async function C(c,a,o){let e=[],i=b(a),n=h(a),s=new Set;for(let t of n)for(let p of t.relatedEntities)s.add(p);let r=/`([A-Z][a-zA-Z0-9_]+)`/g,l;for(;(l=r.exec(a))!==null;)l[1]&&s.add(l[1]);for(let t of o)s.has(t.name)||e.push({type:"added",entityId:t.id,entityName:t.name,entityType:t.type,filePath:t.filePath,newLineNumber:t.location?.start?.line,timestamp:new Date});let d=new Set(o.map(t=>t.name));for(let t of s)d.has(t)||e.push({type:"deleted",entityName:t,entityType:"unknown",filePath:c,timestamp:new Date});for(let t of i)if(t.lineNumber&&t.entityName){let p=o.find(f=>f.name===t.entityName);p&&p.location?.start?.line!==t.lineNumber&&e.push({type:"moved",entityId:p.id,entityName:p.name,entityType:p.type,filePath:p.filePath,oldLineNumber:t.lineNumber,newLineNumber:p.location?.start?.line,timestamp:new Date});}return e}function L(c,a){let o=c,e=new Map;for(let s of a)if(s.type==="moved"&&s.oldLineNumber&&s.newLineNumber){let r=`${s.filePath}:${s.oldLineNumber}`;e.set(r,{old:s.oldLineNumber,new:s.newLineNumber});}let i=/(`[^`]+\.(?:ts|js|tsx|jsx)):(\d+)`/g;o=o.replace(i,(s,r,l)=>{let d=parseInt(l,10);for(let[t,p]of e)if(t.endsWith(`:${d}`))return `${r}:${p.new}\``;return s});let n=/(\[[^\]]+\]\([^)]+\.(?:ts|js|tsx|jsx))#L(\d+)\)/g;return o=o.replace(n,(s,r,l)=>{let d=parseInt(l,10);for(let[t,p]of e)if(t.endsWith(`:${d}`))return `${r}#L${p.new})`;return s}),o}function S(c,a,o){let e=h(c),i=h(a),n=[],s=new Set;for(let r of e){let l=i.find(d=>d.title===r.title);if(l){s.add(l.title);let d=o.filter(t=>t.type==="added").map(t=>t.entityName);if(d.length>0&&r.title.toLowerCase().includes("export")){n.push(`## ${r.title}`),n.push(r.content),n.push(""),n.push("### Added"),n.push("");for(let t of d)n.push(`- \`${t}\` *(added ${new Date().toISOString().split("T")[0]})*`);n.push("");}else n.push(`## ${r.title}`),n.push(r.content);}else n.push(`## ${r.title}`),n.push(r.content);}for(let r of i)s.has(r.title)||e.some(d=>d.title===r.title)||(n.push(""),n.push(`## ${r.title}`),n.push(r.content));return n.join(`
|
|
5
|
+
`)}function $(c,a){if(a.length===0)return c;let o=c;if(!o.includes("## Deprecated")&&!o.includes("## Deleted")){let e=new Date().toISOString().split("T")[0],i=["","## Deleted","","*The following items were removed from the codebase:*",""];for(let n of a)i.push(`- ~~\`${n.entityName}\`~~ *(removed ${e})*`);i.push(""),o+=i.join(`
|
|
6
|
+
`);}else {let e=new Date().toISOString().split("T")[0],i=o.indexOf("## Deleted");if(i!==-1){let n=o.indexOf(`
|
|
7
|
+
|
|
8
|
+
`,i)+2,s=a.map(r=>`- ~~\`${r.entityName}\`~~ *(removed ${e})*`).join(`
|
|
9
|
+
`);o=o.slice(0,n)+s+`
|
|
10
|
+
`+o.slice(n);}}for(let e of a){let i=new RegExp(`\`${e.entityName}\`(?![^~]*~~)`,"g");o=o.replace(i,`~~\`${e.entityName}\`~~`);}return o}async function j(c,a,o,e={}){let i={docPath:a,updated:false,changes:[]};if(!existsSync(a))return i.updated=true,i.newContent=o,i.changes.push({type:"created_new",description:"Created new documentation file"}),i;let s=readFileSync(a,"utf-8"),l=await(await d()).searchEntitiesInDirectory(c),d$1=await C(c,s,l);if(d$1.length===0)return i;let t=s,p=d$1.filter(u=>u.type==="moved");p.length>0&&(t=L(t,p),i.changes.push({type:"reference_updated",description:`Updated ${p.length} line/file references`}));let f=d$1.filter(u=>u.type==="added");f.length>0&&(t=S(t,o,f),i.changes.push({type:"content_added",description:`Added documentation for ${f.length} new entities: ${f.map(u=>u.entityName).join(", ")}`}));let m=d$1.filter(u=>u.type==="deleted");return m.length>0&&(t=$(t,m),i.changes.push({type:"content_marked_deleted",description:`Marked ${m.length} deleted entities: ${m.map(u=>u.entityName).join(", ")}`})),e.useLlm&&e.llmEnhancer&&f.length>0&&(t=await e.llmEnhancer(t,f)),t!==s&&(i.updated=true,i.newContent=t),i}async function I(c,a={}){let o=[],{scanModules:e,generateModuleReadme:i}=await import('./doc-generator-65KNH633.js'),n=await e(c);for(let s of n){let r=N.join(s.path,"AUTODOC.md"),l=i(s),d=await j(s.path,r,l,{useLlm:a.useLlm,llmEnhancer:a.llmEnhancer});d.updated&&!a.preview&&d.newContent&&writeFileSync(r,d.newContent,"utf-8"),o.push(d);}return o}export{b as a,h as b,C as c,L as d,S as e,$ as f,j as g,I as h};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {b}from'./chunk-DPTZHDST.js';import {b as b$1}from'./chunk-IFKMF76K.js';import {c,b as b$2,e,d}from'./chunk-I6STSSAK.js';import {I,s,n}from'./chunk-SV3WKUNV.js';import {c as c$1}from'./chunk-AIZJT6AG.js';import {R,I as I$1,M}from'./chunk-4BI7EBPQ.js';import {existsSync,mkdirSync,readFileSync,writeFileSync}from'fs';import {dirname,join}from'path';R();I();var C={dimensions:384,indexType:"hnsw",hnswM:32,hnswEfConstruction:200,hnswEfSearch:64,autoSaveThreshold:5e4};function v(r,t,e){let s$1=s(t),a=e?s(e):s$1;return {baseIndex:join(r,`faiss-${a}.bin`),baseIds:join(r,`faiss-${a}.bin.ids.json`),baseMeta:join(r,"faiss-base.meta.json"),deltaIndex:join(r,`faiss-${s$1}.delta.bin`),deltaIds:join(r,`faiss-${s$1}.delta.ids.json`),deltaMeta:join(r,`faiss-${s$1}.delta.meta.json`),tombstones:join(r,`faiss-${s$1}.tombstones.json`)}}var y=class r{config;client=null;isInitialized=false;projectPath="";projectHash="";currentBranch=null;baseBranch=null;isOnBaseBranch=false;baseIdSet=new Set;deltaIdSet=new Set;tombstones=new Set;baseUnsavedCount=0;deltaUnsavedCount=0;static MAX_DELTA_SIZE=5e3;initializePromise=null;constructor(t={}){this.config={...C,...t};}get initialized(){return this.isInitialized}getDimensions(){return this.config.dimensions}setDimensions(t){this.config.dimensions!==t&&(I$1.i("LAYERED_FAISS","dimensions_updated",{from:this.config.dimensions,to:t}),this.config.dimensions=t);}async initialize(t,e,s){return this.initializePromise&&this.projectHash===e?this.initializePromise:(this.projectHash&&this.projectHash!==e&&(I$1.i("LAYERED_FAISS","project_switch",{from:this.projectHash,to:e}),this.isInitialized&&(I$1.i("LAYERED_FAISS","saving_before_switch",{project:this.projectHash,baseUnsaved:this.baseUnsavedCount,deltaUnsaved:this.deltaUnsavedCount}),await this.save()),this.isInitialized=false,this.initializePromise=null),this.initializePromise=this.initializeInternal(t,e,s),this.initializePromise)}async initializeInternal(t,e,s$1){try{this.projectPath=t,this.projectHash=e,this.currentBranch=s(s$1),this.baseIdSet.clear(),this.deltaIdSet.clear(),this.tombstones.clear(),this.baseUnsavedCount=0,this.deltaUnsavedCount=0;let a=n(t);return existsSync(a)||mkdirSync(a,{recursive:!0}),this.client=b(),await this.client.start()?(this.baseBranch=c(t),this.isOnBaseBranch=this.baseBranch===this.currentBranch,I$1.i("LAYERED_FAISS","init",{project:e,current:this.currentBranch,base:this.baseBranch,isOnBase:this.isOnBaseBranch}),await this.loadLayers(),this.isInitialized=!0,!0):(I$1.e("LAYERED_FAISS","client_start_fail"),!1)}catch(a){return I$1.e("LAYERED_FAISS","init_fail",{err:String(a)}),this.initializePromise=null,false}}async loadLayers(){let t=n(this.projectPath),e=v(t,this.currentBranch,this.baseBranch);I$1.d("LAYERED_FAISS","load_layers",{projectDir:t,projectPath:this.projectPath,currentBranch:this.currentBranch,baseBranch:this.baseBranch,baseIndexPath:e.baseIndex,baseIndexExists:existsSync(e.baseIndex),baseIdsPath:e.baseIds,baseIdsExists:existsSync(e.baseIds)}),await this.loadBaseLayer(e),this.isOnBaseBranch||await this.loadDeltaLayer(e);}async loadBaseLayer(t){let e={dimensions:this.config.dimensions,indexType:this.config.indexType,metric:"l2",hnswM:this.config.hnswM,hnswEfConstruction:this.config.hnswEfConstruction,hnswEfSearch:this.config.hnswEfSearch},s=existsSync(t.baseIndex),a=s?t.baseIndex:void 0;if(await this.client.faissInitialize(e,a),s&&existsSync(t.baseIds))try{let o=readFileSync(t.baseIds,"utf-8"),f=JSON.parse(o);this.baseIdSet=new Set(f),I$1.d("LAYERED_FAISS","base_ids_loaded",{count:this.baseIdSet.size});}catch(o){I$1.w("LAYERED_FAISS","base_ids_load_fail",{err:String(o)});}let d=await this.client.faissGetStats();I$1.i("LAYERED_FAISS","base_loaded",{vectors:d.totalVectors,ids:this.baseIdSet.size,fromFile:s});}async loadDeltaLayer(t){if(existsSync(t.tombstones))try{let e=readFileSync(t.tombstones,"utf-8"),s=JSON.parse(e);this.tombstones=new Set(s),I$1.d("LAYERED_FAISS","tombstones_loaded",{count:this.tombstones.size});}catch(e){I$1.w("LAYERED_FAISS","tombstones_load_fail",{err:String(e)});}if(existsSync(t.deltaIds))try{let e=readFileSync(t.deltaIds,"utf-8"),s=JSON.parse(e);this.deltaIdSet=new Set(s),I$1.d("LAYERED_FAISS","delta_ids_loaded",{count:this.deltaIdSet.size});}catch(e){I$1.w("LAYERED_FAISS","delta_ids_load_fail",{err:String(e)});}}async switchBranch(t){let e=s(t);if(this.currentBranch!==e){if(I$1.i("LAYERED_FAISS","branch_switch",{from:this.currentBranch,to:e}),await this.save(),this.currentBranch=e,this.isOnBaseBranch=this.baseBranch===e,this.deltaIdSet.clear(),this.tombstones.clear(),this.deltaUnsavedCount=0,!this.isOnBaseBranch){let s=n(this.projectPath),a=v(s,e,this.baseBranch);await this.loadDeltaLayer(a);}I$1.i("LAYERED_FAISS","branch_switched",{branch:e,isOnBase:this.isOnBaseBranch,deltaIds:this.deltaIdSet.size,tombstones:this.tombstones.size});}}async search(t,e){if(!this.isInitialized||!this.client)return I$1.w("LAYERED_FAISS","search called but not initialized",{isInit:this.isInitialized,hasClient:!!this.client}),[];let s=b$1(t);I$1.d("LAYERED_FAISS","search",{inputLen:t.length,normalizedLen:s.length,limit:e,normalizedSample:Array.from(s.slice(0,3))});let a=Math.min(e*2,200),d=[],o=new Set;!this.isOnBaseBranch&&this.deltaIdSet.size>0,I$1.d("LAYERED_FAISS","calling faissSearch",{vectorLen:s.length,vectorType:s.constructor.name,searchLimit:a});let f=await this.client.faissSearch(s,a);for(let n of f)o.has(n.id)||this.tombstones.has(n.id)||this.deltaIdSet.has(n.id)||(d.push({id:n.id,similarity:1-n.distance,source:"base"}),o.add(n.id));for(let n of this.deltaIdSet)if(!o.has(n)&&d.length<e){let h=f.find(B=>B.id===n);h&&(d.push({id:h.id,similarity:1-h.distance,source:"delta"}),o.add(n));}return d.sort((n,h)=>h.similarity-n.similarity).slice(0,e)}async searchForVectorStore(t,e){return (await this.search(t,e)).map(a=>({id:a.id,content:"",similarity:a.similarity,metadata:{source:a.source}}))}async add(t){if(!this.isInitialized||!this.client)return {success:false,target:"base",error:"Not initialized"};let e=b$1(t.vector);return this.isOnBaseBranch?(await this.client.faissAdd([t.id],e),this.baseIdSet.add(t.id),this.baseUnsavedCount++,this.baseUnsavedCount>=this.config.autoSaveThreshold&&await this.saveBase(),{success:true,target:"base"}):(this.tombstones.delete(t.id),this.deltaIdSet.add(t.id),this.deltaUnsavedCount++,I$1.i("LAYERED_FAISS","add_to_delta",{id:t.id.slice(0,50),branch:this.currentBranch,deltaUnsaved:this.deltaUnsavedCount}),await this.client.faissAdd([t.id],e),this.deltaUnsavedCount>=this.config.autoSaveThreshold&&await this.saveDelta(),{success:true,target:"delta"})}async addBatch(t){if(t.length===0)return [];if(!this.isInitialized||!this.client)return t.map(()=>({success:false,target:"base",error:"Not initialized"}));I$1.d("LAYERED_FAISS","addBatch_called",{count:t.length,branch:this.currentBranch,isOnBase:this.isOnBaseBranch});let e=performance.now(),s=[],a=this.config.dimensions,d=new Float32Array(t.length*a);for(let n=0;n<t.length;n++){let h=t[n],B=b$1(h.vector);s.push(h.id),d.set(B,n*a),this.isOnBaseBranch?this.baseIdSet.add(h.id):(this.tombstones.delete(h.id),this.deltaIdSet.add(h.id));}await this.client.faissAdd(s,d),this.isOnBaseBranch?(this.baseUnsavedCount+=t.length,this.baseUnsavedCount>=this.config.autoSaveThreshold&&await this.saveBase()):(this.deltaUnsavedCount+=t.length,this.deltaUnsavedCount>=this.config.autoSaveThreshold&&await this.saveDelta());let o=performance.now()-e;I$1.i("LAYERED_FAISS","addBatch_complete",{count:t.length,elapsed:`${o.toFixed(1)}ms`,speed:`${Math.round(t.length/(o/1e3))}/s`,target:this.isOnBaseBranch?"base":"delta",deltaIdSetSize:this.deltaIdSet.size,tombstonesSize:this.tombstones.size}),!this.isOnBaseBranch&&this.deltaIdSet.size>r.MAX_DELTA_SIZE&&(I$1.i("LAYERED_FAISS","auto_merge_delta",{deltaSize:this.deltaIdSet.size,tombstones:this.tombstones.size,threshold:r.MAX_DELTA_SIZE}),M("LAYERED_FAISS",{deltaSize:this.deltaIdSet.size,tombstones:this.tombstones.size}),await this.saveBase(),c$1(true)&&I$1.d("LAYERED_FAISS","gc_after_merge"));let f=this.isOnBaseBranch?"base":"delta";return t.map(()=>({success:true,target:f}))}async remove(t){for(let e of t)await this.removeOne(e);}async removeOne(t){return !this.isInitialized||!this.client?{success:false,action:"not_found"}:this.isOnBaseBranch?this.baseIdSet.has(t)?(await this.client.faissRemove([t]),this.baseIdSet.delete(t),this.baseUnsavedCount++,{success:true,action:"removed_from_base"}):{success:false,action:"not_found"}:this.deltaIdSet.has(t)?(this.deltaIdSet.delete(t),this.deltaUnsavedCount++,{success:true,action:"removed_from_delta"}):this.baseIdSet.has(t)?(this.tombstones.add(t),this.deltaUnsavedCount++,{success:true,action:"added_tombstone"}):{success:false,action:"not_found"}}has(t){return this.tombstones.has(t)?false:this.deltaIdSet.has(t)||this.baseIdSet.has(t)}getExistingIds(t){let e=new Set;for(let s of t)this.has(s)&&e.add(s);return e}async save(){I$1.i("LAYERED_FAISS","save_called",{branch:this.currentBranch,isOnBase:this.isOnBaseBranch,baseUnsaved:this.baseUnsavedCount,deltaUnsaved:this.deltaUnsavedCount}),this.baseUnsavedCount>0&&await this.saveBase(),this.deltaUnsavedCount>0?await this.saveDelta():this.isOnBaseBranch||I$1.w("LAYERED_FAISS","delta_not_saved_zero_unsaved",{branch:this.currentBranch,deltaIdSetSize:this.deltaIdSet.size});}async saveBase(){if(!this.client||!this.isInitialized)return;let t=n(this.projectPath),e$1=v(t,this.currentBranch,this.baseBranch);try{let s=dirname(e$1.baseIndex);existsSync(s)||mkdirSync(s,{recursive:!0}),await this.client.faissSave(e$1.baseIndex),writeFileSync(e$1.baseIds,JSON.stringify([...this.baseIdSet]),"utf-8"),b$2(this.projectPath)?e(this.projectPath,this.baseIdSet.size):(d(this.projectPath,this.currentBranch,this.config.dimensions,this.baseIdSet.size),this.baseBranch=this.currentBranch,I$1.i("LAYERED_FAISS","base_meta_created",{branch:this.currentBranch})),this.baseUnsavedCount=0,I$1.i("LAYERED_FAISS","base_saved",{vectors:this.baseIdSet.size});}catch(s){I$1.e("LAYERED_FAISS","base_save_fail",{err:String(s)});}}async saveDelta(){if(!this.isInitialized||this.isOnBaseBranch||!this.client)return;let t=n(this.projectPath),e=v(t,this.currentBranch,this.baseBranch);try{let s=dirname(e.deltaIds);existsSync(s)||mkdirSync(s,{recursive:!0}),await this.client.faissSave(e.deltaIndex||e.baseIndex),writeFileSync(e.deltaIds,JSON.stringify([...this.deltaIdSet]),"utf-8"),writeFileSync(e.tombstones,JSON.stringify([...this.tombstones]),"utf-8");let a={branchName:this.currentBranch,baseBranch:this.baseBranch,deltaVectorCount:this.deltaIdSet.size,tombstoneCount:this.tombstones.size,createdAt:Date.now(),updatedAt:Date.now()};writeFileSync(e.deltaMeta,JSON.stringify(a,null,2),"utf-8"),this.deltaUnsavedCount=0,I$1.i("LAYERED_FAISS","delta_saved",{branch:this.currentBranch,deltaIds:this.deltaIdSet.size,tombstones:this.tombstones.size});}catch(s){I$1.e("LAYERED_FAISS","delta_save_fail",{err:String(s)});}}async getStats(){let t=this.baseIdSet.size,e=this.deltaIdSet.size,s=this.tombstones.size,a=t+e-s;return {totalVectors:Math.max(0,a),baseVectors:t,deltaVectors:e,tombstones:s,currentBranch:this.currentBranch,baseBranch:this.baseBranch,isOnBaseBranch:this.isOnBaseBranch}}async count(){return (await this.getStats()).totalVectors}async close(){this.isInitialized&&(await this.save(),this.isInitialized=false,this.initializePromise=null,I$1.i("LAYERED_FAISS","closed",{project:this.projectHash,branch:this.currentBranch}));}},l=null;function N(r){return l?r?.dimensions&&r.dimensions!==l.getDimensions()&&l.setDimensions(r.dimensions):l=new y(r),l}async function $(){l&&(await l.close(),l=null);}export{y as a,N as b,$ as c};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {b as b$1}from'./chunk-DPTZHDST.js';import {b as b$2}from'./chunk-IFKMF76K.js';import {a}from'./chunk-I6STSSAK.js';import {I,s,B as B$1}from'./chunk-SV3WKUNV.js';import {R,I as I$1}from'./chunk-4BI7EBPQ.js';import {existsSync,mkdirSync,writeFileSync,readFileSync,unlinkSync}from'fs';import {dirname}from'path';R();I();var C={dimensions:768,indexType:"hnsw",hnswM:32,hnswEfConstruction:200,hnswEfSearch:64,autoSaveThreshold:5e3,persistPath:""},v=class{config;client=null;isInitialized=false;unsavedCount=0;lastSaveTime=0;pendingSave=null;saveScheduled=false;projectHash="default";branchName="main";idSet=new Set;initializePromise=null;constructor(i={}){this.config={...C,...i};}async setProjectContext(i,t="main"){let e=s(t),n=B$1(i,e);if(!(this.projectHash===i&&this.branchName===e))if(this.isInitialized&&this.client){I$1.i("FAISS","Switching project context",{from:{projectHash:this.projectHash,branchName:this.branchName},to:{projectHash:i,branchName:e}}),this.unsavedCount>0&&await this.save(),this.saveIdSet(),this.projectHash=i,this.branchName=e,this.config.persistPath=n,this.idSet.clear(),this.unsavedCount=0;let a=existsSync(n)?n:void 0,c={dimensions:this.config.dimensions,indexType:this.config.indexType,metric:"l2",hnswM:this.config.hnswM,hnswEfConstruction:this.config.hnswEfConstruction,hnswEfSearch:this.config.hnswEfSearch};await this.client.faissInitialize(c,a),a&&this.loadIdSet();let o=await this.client.faissGetStats();I$1.i("FAISS","Switched to new context",{projectHash:i,branchName:e,vectors:o.totalVectors,idSetSize:this.idSet.size});}else this.projectHash=i,this.branchName=e,this.config.persistPath=n,I$1.d("FAISS","Project context set",{projectHash:this.projectHash,branchName:this.branchName,persistPath:this.config.persistPath});}async initialize(){return this.isInitialized?true:this.initializePromise?this.initializePromise:(this.initializePromise=this.initializeInternal(),this.initializePromise)}async initializeInternal(){try{if(I$1.i("FAISS","Initializing..."),this.client=b$1(),!await this.client.start())return I$1.e("FAISS","Failed to start Faiss client"),!1;let t={dimensions:this.config.dimensions,indexType:this.config.indexType,metric:"l2",hnswM:this.config.hnswM,hnswEfConstruction:this.config.hnswEfConstruction,hnswEfSearch:this.config.hnswEfSearch},e=existsSync(this.config.persistPath)?this.config.persistPath:void 0;if(e){let a=this.loadIndexMetadata();a&&a.dimensions!==this.config.dimensions&&(I$1.w("FAISS","Dimension mismatch - dropping old index",{savedDimensions:a.dimensions,configDimensions:this.config.dimensions,indexPath:e}),this.deleteIndexFiles(),e=void 0);}await this.client.faissInitialize(t,e),e&&this.loadIdSet(),this.isInitialized=!0,this.lastSaveTime=Date.now();let n=await this.client.faissGetStats();return I$1.i("FAISS","Initialized",{indexType:this.config.indexType,dimensions:this.config.dimensions,vectors:n.totalVectors,loaded:!!e,idSetSize:this.idSet.size}),!0}catch(i){return I$1.e("FAISS","Initialization failed",{error:i.message}),false}}async close(){this.unsavedCount>0&&await this.save(),this.client&&this.isInitialized&&await this.client.stop(),this.idSet.clear(),this.isInitialized=false;}async add(i){if(!this.client||!this.isInitialized)throw new Error("FaissProvider not initialized");await this.client.faissAdd([i.id],Array.from(i.vector)),this.idSet.add(i.id),this.unsavedCount++,this.unsavedCount>=this.config.autoSaveThreshold&&await this.save();}async addBatch(i){if(!this.client||!this.isInitialized)throw new Error("FaissProvider not initialized");if(i.length===0)return;let t=performance.now(),e=r=>{let l=(performance.now()-t).toFixed(1);I$1.i("FAISS",r,{elapsedMs:l});},n=this.config.dimensions,a=i.length,c=new Array(a),o=new Float32Array(a*n);for(let r=0;r<a;r++){let l=i[r];c[r]=l.id;let y=b$2(l.vector);o.set(y,r*n),this.idSet.add(l.id);}e("F1_PREPARE_VECTORS"),await this.client.faissAdd(c,o),e("F2_FAISS_ADD"),this.unsavedCount+=a,I$1.d("FAISS","Added embeddings",{count:a,unsaved:this.unsavedCount}),this.unsavedCount>=this.config.autoSaveThreshold&&!this.saveScheduled&&(this.saveScheduled=true,this.pendingSave=this.save().catch(r=>I$1.w("FAISS","Background save failed",{error:r.message})).finally(()=>{this.saveScheduled=false,this.pendingSave=null;}));}async waitForPendingSave(){this.pendingSave&&await this.pendingSave;}async search(i,t=10){if(!this.client||!this.isInitialized)throw new Error("FaissProvider not initialized");let e=b$2(i);return (await this.client.faissSearch(e,t)).map(a=>({id:a.id,similarity:a.score,content:""}))}async batchSearch(i,t=10){if(!this.client||!this.isInitialized)throw new Error("FaissProvider not initialized");let e=this.config.dimensions,n=i.length,a=new Float32Array(n*e);for(let o=0;o<n;o++){let r=b$2(i[o]);a.set(r,o*e);}return (await this.client.faissBatchSearch(a,n,t)).map(o=>o.map(r=>({id:r.id,similarity:r.score,content:""})))}async save(){if(!this.client||!this.isInitialized)throw new Error("FaissProvider not initialized");if(this.unsavedCount!==0)try{let i=dirname(this.config.persistPath);existsSync(i)||mkdirSync(i,{recursive:!0}),await this.client.faissSave(this.config.persistPath),this.saveIdSet(),this.saveIndexMetadata();let t=this.unsavedCount;this.unsavedCount=0,this.lastSaveTime=Date.now(),I$1.i("FAISS","Index saved",{path:this.config.persistPath,savedCount:t,idSetSize:this.idSet.size});}catch(i){throw I$1.e("FAISS","Failed to save index",{error:i.message}),i}}getIdSetPath(){return `${this.config.persistPath}.ids.json`}saveIdSet(){if(!this.config.persistPath)return;let i=this.getIdSetPath();try{let t=Array.from(this.idSet);writeFileSync(i,JSON.stringify(t),"utf-8"),I$1.d("FAISS","ID set saved",{path:i,size:this.idSet.size});}catch(t){I$1.w("FAISS","Failed to save ID set",{error:t.message});}}loadIdSet(){let i=this.getIdSetPath();if(!existsSync(i)){let t=`${this.config.persistPath}.content.json`;if(existsSync(t))try{let e=readFileSync(t,"utf-8"),n=JSON.parse(e);this.idSet.clear();for(let a of Object.keys(n))this.idSet.add(a);I$1.i("FAISS","Migrated IDs from legacy content cache",{size:this.idSet.size}),this.saveIdSet();return}catch{}I$1.d("FAISS","No ID set file found",{path:i});return}try{let t=readFileSync(i,"utf-8"),e=JSON.parse(t);this.idSet.clear();for(let n of e)this.idSet.add(n);I$1.i("FAISS","ID set loaded",{path:i,size:this.idSet.size});}catch(t){I$1.w("FAISS","Failed to load ID set",{error:t.message});}}getMetadataPath(){return `${this.config.persistPath}.meta.json`}saveIndexMetadata(){if(!this.config.persistPath)return;let i=this.getMetadataPath();try{let t={dimensions:this.config.dimensions,indexType:this.config.indexType,savedAt:Date.now()};writeFileSync(i,JSON.stringify(t),"utf-8"),I$1.d("FAISS","Index metadata saved",{path:i,dimensions:t.dimensions}),this.ensureBaseMetadata();}catch(t){I$1.w("FAISS","Failed to save index metadata",{error:t.message});}}ensureBaseMetadata(){let i=a(this.projectHash);if(!existsSync(i))try{let t={baseBranch:this.branchName,vectorCount:this.idSet.size,createdAt:Date.now(),updatedAt:Date.now(),dimensions:this.config.dimensions,indexType:this.config.indexType},e=dirname(i);existsSync(e)||mkdirSync(e,{recursive:!0}),writeFileSync(i,JSON.stringify(t,null,2),"utf-8"),I$1.i("FAISS","Base metadata created",{branch:this.branchName,path:i,vectors:this.idSet.size});}catch(t){I$1.w("FAISS","Failed to create base metadata",{error:t.message});}}loadIndexMetadata(){let i=this.getMetadataPath();if(!existsSync(i))return null;try{let t=readFileSync(i,"utf-8");return JSON.parse(t)}catch(t){return I$1.w("FAISS","Failed to load index metadata",{error:t.message}),null}}deleteIndexFiles(){let i=[this.config.persistPath,this.getIdSetPath(),this.getMetadataPath()];for(let t of i)if(t&&existsSync(t))try{unlinkSync(t),I$1.d("FAISS","Deleted index file",{path:t});}catch(e){I$1.w("FAISS","Failed to delete file",{path:t,error:e.message});}this.idSet.clear(),this.unsavedCount=0;}async flush(){await this.waitForPendingSave();let i=this.unsavedCount;return i>0&&await this.save(),i}async flushAndSave(){await this.waitForPendingSave(),await this.save();}async train(i){if(!this.client||!this.isInitialized)throw new Error("FaissProvider not initialized");let t=[];for(let e of i)t.push(...Array.from(e));await this.client.faissTrain(new Float32Array(t),i.length),I$1.i("FAISS","Trained index",{vectorCount:i.length});}async getStats(){let i=this.client?await this.client.getStats():null;return {totalVectors:i?.totalVectors??0,unsavedCount:this.unsavedCount,lastSaveTime:this.lastSaveTime,idSetSize:this.idSet.size,faissStats:i}}isReady(){return this.isInitialized&&this.client?.isRunning()===true}async getVectorCount(){return (await this.getStats()).totalVectors}getExistingIds(i){let t=new Set;for(let e of i)this.idSet.has(e)&&t.add(e);return t}hasId(i){return this.idSet.has(i)}async remove(i){if(!this.client||!this.isInitialized)throw new Error("FaissProvider not initialized");await this.client.faissRemove(i);for(let t of i)this.idSet.delete(t);I$1.d("FAISS","Removed embeddings",{count:i.length});}},h=null;function b(f){return h||(h=new v(f)),h}async function B(f){let i=b(f);return await i.initialize()?i:null}async function V(){h&&(await h.close(),h=null);}export{v as a,b,B as c,V as d};
|