@contractspec/module.ai-chat 1.57.0 → 1.59.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/ai-chat.capability.d.ts +2 -0
- package/dist/ai-chat.capability.d.ts.map +1 -0
- package/dist/ai-chat.feature.d.ts +1 -6
- package/dist/ai-chat.feature.d.ts.map +1 -1
- package/dist/ai-chat.operations.d.ts +217 -223
- package/dist/ai-chat.operations.d.ts.map +1 -1
- package/dist/browser/context/index.js +415 -0
- package/dist/browser/core/index.js +336 -0
- package/dist/browser/index.js +2291 -0
- package/dist/browser/presentation/components/index.js +974 -0
- package/dist/browser/presentation/hooks/index.js +556 -0
- package/dist/browser/presentation/index.js +1520 -0
- package/dist/browser/providers/index.js +51 -0
- package/dist/context/chat.test.d.ts +2 -0
- package/dist/context/chat.test.d.ts.map +1 -0
- package/dist/context/context-builder.d.ts +37 -36
- package/dist/context/context-builder.d.ts.map +1 -1
- package/dist/context/file-operations.d.ts +64 -67
- package/dist/context/file-operations.d.ts.map +1 -1
- package/dist/context/index.d.ts +7 -4
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +409 -4
- package/dist/context/workspace-context.d.ts +84 -87
- package/dist/context/workspace-context.d.ts.map +1 -1
- package/dist/core/chat-service.d.ts +56 -60
- package/dist/core/chat-service.d.ts.map +1 -1
- package/dist/core/conversation-store.d.ts +60 -61
- package/dist/core/conversation-store.d.ts.map +1 -1
- package/dist/core/index.d.ts +7 -4
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +330 -3
- package/dist/core/message-types.d.ts +94 -97
- package/dist/core/message-types.d.ts.map +1 -1
- package/dist/docs/ai-chat.docblock.d.ts +2 -0
- package/dist/docs/ai-chat.docblock.d.ts.map +1 -0
- package/dist/docs/index.d.ts +7 -0
- package/dist/docs/index.d.ts.map +1 -0
- package/dist/events.d.ts +103 -109
- package/dist/events.d.ts.map +1 -1
- package/dist/index.d.ts +16 -21
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2286 -23
- package/dist/node/context/index.js +410 -0
- package/dist/node/core/index.js +331 -0
- package/dist/node/index.js +2286 -0
- package/dist/node/presentation/components/index.js +969 -0
- package/dist/node/presentation/hooks/index.js +551 -0
- package/dist/node/presentation/index.js +1515 -0
- package/dist/node/providers/index.js +46 -0
- package/dist/presentation/components/ChatContainer.d.ts +7 -16
- package/dist/presentation/components/ChatContainer.d.ts.map +1 -1
- package/dist/presentation/components/ChatInput.d.ts +17 -30
- package/dist/presentation/components/ChatInput.d.ts.map +1 -1
- package/dist/presentation/components/ChatMessage.d.ts +9 -19
- package/dist/presentation/components/ChatMessage.d.ts.map +1 -1
- package/dist/presentation/components/CodePreview.d.ts +20 -35
- package/dist/presentation/components/CodePreview.d.ts.map +1 -1
- package/dist/presentation/components/ContextIndicator.d.ts +11 -21
- package/dist/presentation/components/ContextIndicator.d.ts.map +1 -1
- package/dist/presentation/components/ModelPicker.d.ts +21 -32
- package/dist/presentation/components/ModelPicker.d.ts.map +1 -1
- package/dist/presentation/components/index.d.ts +10 -7
- package/dist/presentation/components/index.d.ts.map +1 -0
- package/dist/presentation/components/index.js +968 -7
- package/dist/presentation/hooks/index.d.ts +6 -3
- package/dist/presentation/hooks/index.d.ts.map +1 -0
- package/dist/presentation/hooks/index.js +550 -3
- package/dist/presentation/hooks/use-chat.test.d.ts +2 -0
- package/dist/presentation/hooks/use-chat.test.d.ts.map +1 -0
- package/dist/presentation/hooks/useChat.d.ts +50 -54
- package/dist/presentation/hooks/useChat.d.ts.map +1 -1
- package/dist/presentation/hooks/useProviders.d.ts +21 -25
- package/dist/presentation/hooks/useProviders.d.ts.map +1 -1
- package/dist/presentation/index.d.ts +8 -11
- package/dist/presentation/index.d.ts.map +1 -0
- package/dist/presentation/index.js +1515 -12
- package/dist/providers/chat-utilities.d.ts +18 -7
- package/dist/providers/chat-utilities.d.ts.map +1 -1
- package/dist/providers/index.d.ts +8 -3
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +45 -3
- package/dist/schema.d.ts +195 -200
- package/dist/schema.d.ts.map +1 -1
- package/package.json +123 -34
- package/dist/ai-chat.feature.js +0 -102
- package/dist/ai-chat.feature.js.map +0 -1
- package/dist/ai-chat.operations.js +0 -172
- package/dist/ai-chat.operations.js.map +0 -1
- package/dist/context/context-builder.js +0 -148
- package/dist/context/context-builder.js.map +0 -1
- package/dist/context/file-operations.js +0 -175
- package/dist/context/file-operations.js.map +0 -1
- package/dist/context/workspace-context.js +0 -124
- package/dist/context/workspace-context.js.map +0 -1
- package/dist/core/chat-service.js +0 -227
- package/dist/core/chat-service.js.map +0 -1
- package/dist/core/conversation-store.js +0 -109
- package/dist/core/conversation-store.js.map +0 -1
- package/dist/events.js +0 -98
- package/dist/events.js.map +0 -1
- package/dist/presentation/components/ChatContainer.js +0 -63
- package/dist/presentation/components/ChatContainer.js.map +0 -1
- package/dist/presentation/components/ChatInput.js +0 -149
- package/dist/presentation/components/ChatInput.js.map +0 -1
- package/dist/presentation/components/ChatMessage.js +0 -136
- package/dist/presentation/components/ChatMessage.js.map +0 -1
- package/dist/presentation/components/CodePreview.js +0 -127
- package/dist/presentation/components/CodePreview.js.map +0 -1
- package/dist/presentation/components/ContextIndicator.js +0 -97
- package/dist/presentation/components/ContextIndicator.js.map +0 -1
- package/dist/presentation/components/ModelPicker.js +0 -202
- package/dist/presentation/components/ModelPicker.js.map +0 -1
- package/dist/presentation/hooks/useChat.js +0 -172
- package/dist/presentation/hooks/useChat.js.map +0 -1
- package/dist/presentation/hooks/useProviders.js +0 -41
- package/dist/presentation/hooks/useProviders.js.map +0 -1
- package/dist/providers/chat-utilities.js +0 -17
- package/dist/providers/chat-utilities.js.map +0 -1
- package/dist/schema.js +0 -100
- package/dist/schema.js.map +0 -1
package/dist/context/index.js
CHANGED
|
@@ -1,5 +1,410 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { FileOperations, createNodeFileOperations } from "./file-operations.js";
|
|
1
|
+
// @bun
|
|
2
|
+
var __require = import.meta.require;
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
// src/context/workspace-context.ts
|
|
5
|
+
class WorkspaceContext {
|
|
6
|
+
workspacePath;
|
|
7
|
+
allowWrites;
|
|
8
|
+
specs = [];
|
|
9
|
+
files = [];
|
|
10
|
+
initialized = false;
|
|
11
|
+
constructor(config) {
|
|
12
|
+
this.workspacePath = config.workspacePath;
|
|
13
|
+
this.allowWrites = config.allowWrites ?? false;
|
|
14
|
+
}
|
|
15
|
+
async initialize() {
|
|
16
|
+
if (this.initialized)
|
|
17
|
+
return;
|
|
18
|
+
this.initialized = true;
|
|
19
|
+
}
|
|
20
|
+
getSpecs() {
|
|
21
|
+
return this.specs;
|
|
22
|
+
}
|
|
23
|
+
getFiles() {
|
|
24
|
+
return this.files;
|
|
25
|
+
}
|
|
26
|
+
addSpecs(specs) {
|
|
27
|
+
this.specs.push(...specs);
|
|
28
|
+
}
|
|
29
|
+
addFiles(files) {
|
|
30
|
+
this.files.push(...files);
|
|
31
|
+
}
|
|
32
|
+
getSummary() {
|
|
33
|
+
const commands = this.specs.filter((s) => s.type === "command").length;
|
|
34
|
+
const queries = this.specs.filter((s) => s.type === "query").length;
|
|
35
|
+
const events = this.specs.filter((s) => s.type === "event").length;
|
|
36
|
+
const presentations = this.specs.filter((s) => s.type === "presentation").length;
|
|
37
|
+
const tsFiles = this.files.filter((f) => f.extension === ".ts").length;
|
|
38
|
+
const specFiles = this.files.filter((f) => f.isSpec).length;
|
|
39
|
+
return {
|
|
40
|
+
name: this.workspacePath.split("/").pop() ?? "workspace",
|
|
41
|
+
path: this.workspacePath,
|
|
42
|
+
specs: {
|
|
43
|
+
total: this.specs.length,
|
|
44
|
+
commands,
|
|
45
|
+
queries,
|
|
46
|
+
events,
|
|
47
|
+
presentations
|
|
48
|
+
},
|
|
49
|
+
files: {
|
|
50
|
+
total: this.files.length,
|
|
51
|
+
typescript: tsFiles,
|
|
52
|
+
specFiles
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
getContextSummary() {
|
|
57
|
+
const summary = this.getSummary();
|
|
58
|
+
const parts = [
|
|
59
|
+
`Workspace: ${summary.name}`,
|
|
60
|
+
`Path: ${summary.path}`,
|
|
61
|
+
"",
|
|
62
|
+
"### Specs",
|
|
63
|
+
`- Commands: ${summary.specs.commands}`,
|
|
64
|
+
`- Queries: ${summary.specs.queries}`,
|
|
65
|
+
`- Events: ${summary.specs.events}`,
|
|
66
|
+
`- Presentations: ${summary.specs.presentations}`
|
|
67
|
+
];
|
|
68
|
+
if (this.specs.length > 0) {
|
|
69
|
+
parts.push("", "### Available Specs");
|
|
70
|
+
for (const spec of this.specs.slice(0, 20)) {
|
|
71
|
+
parts.push(`- ${spec.name} (${spec.type})`);
|
|
72
|
+
}
|
|
73
|
+
if (this.specs.length > 20) {
|
|
74
|
+
parts.push(`- ... and ${this.specs.length - 20} more`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return parts.join(`
|
|
78
|
+
`);
|
|
79
|
+
}
|
|
80
|
+
findSpecs(query) {
|
|
81
|
+
const lowerQuery = query.toLowerCase();
|
|
82
|
+
return this.specs.filter((s) => s.name.toLowerCase().includes(lowerQuery) || s.description?.toLowerCase().includes(lowerQuery) || s.tags?.some((t) => t.toLowerCase().includes(lowerQuery)));
|
|
83
|
+
}
|
|
84
|
+
findFiles(query) {
|
|
85
|
+
const lowerQuery = query.toLowerCase();
|
|
86
|
+
return this.files.filter((f) => f.path.toLowerCase().includes(lowerQuery) || f.name.toLowerCase().includes(lowerQuery));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async function createWorkspaceContext(path, options) {
|
|
90
|
+
const context = new WorkspaceContext({
|
|
91
|
+
workspacePath: path,
|
|
92
|
+
...options
|
|
93
|
+
});
|
|
94
|
+
await context.initialize();
|
|
95
|
+
return context;
|
|
96
|
+
}
|
|
97
|
+
// src/context/context-builder.ts
|
|
98
|
+
function estimateTokens(text) {
|
|
99
|
+
return Math.ceil(text.length / 4);
|
|
100
|
+
}
|
|
101
|
+
function scoreSpec(spec, query) {
|
|
102
|
+
if (!query)
|
|
103
|
+
return 0.5;
|
|
104
|
+
const lowerQuery = query.toLowerCase();
|
|
105
|
+
let score = 0;
|
|
106
|
+
if (spec.name.toLowerCase().includes(lowerQuery)) {
|
|
107
|
+
score += 0.4;
|
|
108
|
+
}
|
|
109
|
+
if (spec.description?.toLowerCase().includes(lowerQuery)) {
|
|
110
|
+
score += 0.3;
|
|
111
|
+
}
|
|
112
|
+
if (spec.tags?.some((t) => t.toLowerCase().includes(lowerQuery))) {
|
|
113
|
+
score += 0.2;
|
|
114
|
+
}
|
|
115
|
+
return Math.min(score, 1);
|
|
116
|
+
}
|
|
117
|
+
function scoreFile(file, query) {
|
|
118
|
+
if (!query)
|
|
119
|
+
return 0.5;
|
|
120
|
+
const lowerQuery = query.toLowerCase();
|
|
121
|
+
let score = 0;
|
|
122
|
+
if (file.path.toLowerCase().includes(lowerQuery)) {
|
|
123
|
+
score += 0.5;
|
|
124
|
+
}
|
|
125
|
+
if (file.name.toLowerCase().includes(lowerQuery)) {
|
|
126
|
+
score += 0.3;
|
|
127
|
+
}
|
|
128
|
+
if (file.isSpec) {
|
|
129
|
+
score += 0.2;
|
|
130
|
+
}
|
|
131
|
+
return Math.min(score, 1);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
class ContextBuilder {
|
|
135
|
+
context;
|
|
136
|
+
constructor(context) {
|
|
137
|
+
this.context = context;
|
|
138
|
+
}
|
|
139
|
+
build(options = {}) {
|
|
140
|
+
const maxTokens = options.maxTokens ?? 4000;
|
|
141
|
+
const entries = [];
|
|
142
|
+
let totalTokens = 0;
|
|
143
|
+
if (options.includeSpecs?.length) {
|
|
144
|
+
for (const specName of options.includeSpecs) {
|
|
145
|
+
const spec = this.context.getSpecs().find((s) => s.name === specName);
|
|
146
|
+
if (spec) {
|
|
147
|
+
const entry = {
|
|
148
|
+
type: "spec",
|
|
149
|
+
path: spec.path,
|
|
150
|
+
summary: `${spec.type}: ${spec.name}${spec.description ? ` - ${spec.description}` : ""}`,
|
|
151
|
+
relevance: 1
|
|
152
|
+
};
|
|
153
|
+
entries.push(entry);
|
|
154
|
+
totalTokens += estimateTokens(entry.summary ?? "");
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (options.includeFiles?.length) {
|
|
159
|
+
for (const filePath of options.includeFiles) {
|
|
160
|
+
const file = this.context.getFiles().find((f) => f.path === filePath);
|
|
161
|
+
if (file) {
|
|
162
|
+
const entry = {
|
|
163
|
+
type: "file",
|
|
164
|
+
path: file.path,
|
|
165
|
+
summary: `File: ${file.relativePath}`,
|
|
166
|
+
relevance: 1
|
|
167
|
+
};
|
|
168
|
+
entries.push(entry);
|
|
169
|
+
totalTokens += estimateTokens(entry.summary ?? "");
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (options.query) {
|
|
174
|
+
const scoredSpecs = this.context.getSpecs().map((spec) => ({ spec, score: scoreSpec(spec, options.query) })).filter(({ score }) => score > 0.2).sort((a, b) => b.score - a.score);
|
|
175
|
+
for (const { spec, score } of scoredSpecs) {
|
|
176
|
+
if (totalTokens >= maxTokens)
|
|
177
|
+
break;
|
|
178
|
+
if (entries.some((e) => e.path === spec.path))
|
|
179
|
+
continue;
|
|
180
|
+
const entry = {
|
|
181
|
+
type: "spec",
|
|
182
|
+
path: spec.path,
|
|
183
|
+
summary: `${spec.type}: ${spec.name}${spec.description ? ` - ${spec.description}` : ""}`,
|
|
184
|
+
relevance: score
|
|
185
|
+
};
|
|
186
|
+
entries.push(entry);
|
|
187
|
+
totalTokens += estimateTokens(entry.summary ?? "");
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (options.query) {
|
|
191
|
+
const scoredFiles = this.context.getFiles().map((file) => ({ file, score: scoreFile(file, options.query) })).filter(({ score }) => score > 0.2).sort((a, b) => b.score - a.score);
|
|
192
|
+
for (const { file, score } of scoredFiles) {
|
|
193
|
+
if (totalTokens >= maxTokens)
|
|
194
|
+
break;
|
|
195
|
+
if (entries.some((e) => e.path === file.path))
|
|
196
|
+
continue;
|
|
197
|
+
const entry = {
|
|
198
|
+
type: "file",
|
|
199
|
+
path: file.path,
|
|
200
|
+
summary: `File: ${file.relativePath}`,
|
|
201
|
+
relevance: score
|
|
202
|
+
};
|
|
203
|
+
entries.push(entry);
|
|
204
|
+
totalTokens += estimateTokens(entry.summary ?? "");
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
const summary = this.buildSummary(entries);
|
|
208
|
+
return {
|
|
209
|
+
entries,
|
|
210
|
+
summary,
|
|
211
|
+
totalTokensEstimate: totalTokens + estimateTokens(summary)
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
buildSummary(entries) {
|
|
215
|
+
if (entries.length === 0) {
|
|
216
|
+
return this.context.getContextSummary();
|
|
217
|
+
}
|
|
218
|
+
const parts = [];
|
|
219
|
+
const workspaceSummary = this.context.getSummary();
|
|
220
|
+
parts.push(`Workspace: ${workspaceSummary.name}`);
|
|
221
|
+
parts.push("");
|
|
222
|
+
const specs = entries.filter((e) => e.type === "spec");
|
|
223
|
+
if (specs.length > 0) {
|
|
224
|
+
parts.push("### Relevant Specs");
|
|
225
|
+
for (const entry of specs) {
|
|
226
|
+
parts.push(`- ${entry.summary}`);
|
|
227
|
+
}
|
|
228
|
+
parts.push("");
|
|
229
|
+
}
|
|
230
|
+
const files = entries.filter((e) => e.type === "file");
|
|
231
|
+
if (files.length > 0) {
|
|
232
|
+
parts.push("### Relevant Files");
|
|
233
|
+
for (const entry of files) {
|
|
234
|
+
parts.push(`- ${entry.summary}`);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return parts.join(`
|
|
238
|
+
`);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
function createContextBuilder(context) {
|
|
242
|
+
return new ContextBuilder(context);
|
|
243
|
+
}
|
|
244
|
+
// src/context/file-operations.ts
|
|
245
|
+
class FileOperations {
|
|
246
|
+
fs;
|
|
247
|
+
workspacePath;
|
|
248
|
+
allowWrites;
|
|
249
|
+
constructor(fs, workspacePath, allowWrites = false) {
|
|
250
|
+
this.fs = fs;
|
|
251
|
+
this.workspacePath = workspacePath;
|
|
252
|
+
this.allowWrites = allowWrites;
|
|
253
|
+
}
|
|
254
|
+
async read(relativePath) {
|
|
255
|
+
const fullPath = this.resolvePath(relativePath);
|
|
256
|
+
try {
|
|
257
|
+
const content = await this.fs.readFile(fullPath);
|
|
258
|
+
return { success: true, path: relativePath, content };
|
|
259
|
+
} catch (error) {
|
|
260
|
+
return {
|
|
261
|
+
success: false,
|
|
262
|
+
path: relativePath,
|
|
263
|
+
error: error instanceof Error ? error.message : String(error)
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
async write(relativePath, content) {
|
|
268
|
+
if (!this.allowWrites) {
|
|
269
|
+
return {
|
|
270
|
+
success: false,
|
|
271
|
+
path: relativePath,
|
|
272
|
+
error: "File writes are not enabled"
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
const fullPath = this.resolvePath(relativePath);
|
|
276
|
+
try {
|
|
277
|
+
await this.fs.writeFile(fullPath, content);
|
|
278
|
+
return { success: true, path: relativePath };
|
|
279
|
+
} catch (error) {
|
|
280
|
+
return {
|
|
281
|
+
success: false,
|
|
282
|
+
path: relativePath,
|
|
283
|
+
error: error instanceof Error ? error.message : String(error)
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
async execute(operations) {
|
|
288
|
+
const results = [];
|
|
289
|
+
for (const operation of operations) {
|
|
290
|
+
let result;
|
|
291
|
+
switch (operation.type) {
|
|
292
|
+
case "read": {
|
|
293
|
+
const readResult = await this.read(operation.path);
|
|
294
|
+
result = {
|
|
295
|
+
operation,
|
|
296
|
+
success: readResult.success,
|
|
297
|
+
content: readResult.content,
|
|
298
|
+
error: readResult.error
|
|
299
|
+
};
|
|
300
|
+
break;
|
|
301
|
+
}
|
|
302
|
+
case "write":
|
|
303
|
+
case "create": {
|
|
304
|
+
if (!operation.content) {
|
|
305
|
+
result = {
|
|
306
|
+
operation,
|
|
307
|
+
success: false,
|
|
308
|
+
error: "Content is required for write operations"
|
|
309
|
+
};
|
|
310
|
+
} else {
|
|
311
|
+
const writeResult = await this.write(operation.path, operation.content);
|
|
312
|
+
result = {
|
|
313
|
+
operation,
|
|
314
|
+
success: writeResult.success,
|
|
315
|
+
error: writeResult.error
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
break;
|
|
319
|
+
}
|
|
320
|
+
case "delete": {
|
|
321
|
+
if (!this.allowWrites) {
|
|
322
|
+
result = {
|
|
323
|
+
operation,
|
|
324
|
+
success: false,
|
|
325
|
+
error: "File writes are not enabled"
|
|
326
|
+
};
|
|
327
|
+
} else {
|
|
328
|
+
try {
|
|
329
|
+
await this.fs.deleteFile(this.resolvePath(operation.path));
|
|
330
|
+
result = { operation, success: true };
|
|
331
|
+
} catch (error) {
|
|
332
|
+
result = {
|
|
333
|
+
operation,
|
|
334
|
+
success: false,
|
|
335
|
+
error: error instanceof Error ? error.message : String(error)
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
break;
|
|
340
|
+
}
|
|
341
|
+
default:
|
|
342
|
+
result = {
|
|
343
|
+
operation,
|
|
344
|
+
success: false,
|
|
345
|
+
error: `Unknown operation type: ${operation.type}`
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
results.push(result);
|
|
349
|
+
}
|
|
350
|
+
return results;
|
|
351
|
+
}
|
|
352
|
+
resolvePath(relativePath) {
|
|
353
|
+
const normalized = relativePath.replace(/\.\./g, "").replace(/^\//, "");
|
|
354
|
+
return `${this.workspacePath}/${normalized}`;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
function createNodeFileOperations(workspacePath, allowWrites = false) {
|
|
358
|
+
const fs = {
|
|
359
|
+
async readFile(path) {
|
|
360
|
+
const { readFile } = await import("fs/promises");
|
|
361
|
+
return readFile(path, "utf-8");
|
|
362
|
+
},
|
|
363
|
+
async writeFile(path, content) {
|
|
364
|
+
const { writeFile, mkdir } = await import("fs/promises");
|
|
365
|
+
const { dirname } = await import("path");
|
|
366
|
+
await mkdir(dirname(path), { recursive: true });
|
|
367
|
+
await writeFile(path, content, "utf-8");
|
|
368
|
+
},
|
|
369
|
+
async exists(path) {
|
|
370
|
+
const { access } = await import("fs/promises");
|
|
371
|
+
try {
|
|
372
|
+
await access(path);
|
|
373
|
+
return true;
|
|
374
|
+
} catch {
|
|
375
|
+
return false;
|
|
376
|
+
}
|
|
377
|
+
},
|
|
378
|
+
async deleteFile(path) {
|
|
379
|
+
const { unlink } = await import("fs/promises");
|
|
380
|
+
await unlink(path);
|
|
381
|
+
},
|
|
382
|
+
async listFiles(directory, options) {
|
|
383
|
+
const { readdir } = await import("fs/promises");
|
|
384
|
+
const { join } = await import("path");
|
|
385
|
+
const files = [];
|
|
386
|
+
const entries = await readdir(directory, { withFileTypes: true });
|
|
387
|
+
for (const entry of entries) {
|
|
388
|
+
const fullPath = join(directory, entry.name);
|
|
389
|
+
if (entry.isDirectory() && options?.recursive) {
|
|
390
|
+
const subFiles = await this.listFiles(fullPath, options);
|
|
391
|
+
files.push(...subFiles);
|
|
392
|
+
} else if (entry.isFile()) {
|
|
393
|
+
if (!options?.pattern || entry.name.match(new RegExp(options.pattern))) {
|
|
394
|
+
files.push(fullPath);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
return files;
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
return new FileOperations(fs, workspacePath, allowWrites);
|
|
402
|
+
}
|
|
403
|
+
export {
|
|
404
|
+
createWorkspaceContext,
|
|
405
|
+
createNodeFileOperations,
|
|
406
|
+
createContextBuilder,
|
|
407
|
+
WorkspaceContext,
|
|
408
|
+
FileOperations,
|
|
409
|
+
ContextBuilder
|
|
410
|
+
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/context/workspace-context.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Workspace context management
|
|
4
3
|
*
|
|
@@ -8,110 +7,108 @@
|
|
|
8
7
|
/**
|
|
9
8
|
* Spec information for context
|
|
10
9
|
*/
|
|
11
|
-
interface SpecInfo {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
export interface SpecInfo {
|
|
11
|
+
name: string;
|
|
12
|
+
version: string;
|
|
13
|
+
type: 'command' | 'query' | 'event' | 'presentation';
|
|
14
|
+
path: string;
|
|
15
|
+
description?: string;
|
|
16
|
+
tags?: string[];
|
|
18
17
|
}
|
|
19
18
|
/**
|
|
20
19
|
* File information for context
|
|
21
20
|
*/
|
|
22
|
-
interface FileInfo {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
export interface FileInfo {
|
|
22
|
+
path: string;
|
|
23
|
+
relativePath: string;
|
|
24
|
+
name: string;
|
|
25
|
+
extension: string;
|
|
26
|
+
size: number;
|
|
27
|
+
isSpec: boolean;
|
|
29
28
|
}
|
|
30
29
|
/**
|
|
31
30
|
* Workspace summary for context
|
|
32
31
|
*/
|
|
33
|
-
interface WorkspaceSummary {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
32
|
+
export interface WorkspaceSummary {
|
|
33
|
+
name: string;
|
|
34
|
+
path: string;
|
|
35
|
+
specs: {
|
|
36
|
+
total: number;
|
|
37
|
+
commands: number;
|
|
38
|
+
queries: number;
|
|
39
|
+
events: number;
|
|
40
|
+
presentations: number;
|
|
41
|
+
};
|
|
42
|
+
files: {
|
|
43
|
+
total: number;
|
|
44
|
+
typescript: number;
|
|
45
|
+
specFiles: number;
|
|
46
|
+
};
|
|
48
47
|
}
|
|
49
48
|
/**
|
|
50
49
|
* Configuration for workspace context
|
|
51
50
|
*/
|
|
52
|
-
interface WorkspaceContextConfig {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
51
|
+
export interface WorkspaceContextConfig {
|
|
52
|
+
/** Root path of the workspace */
|
|
53
|
+
workspacePath: string;
|
|
54
|
+
/** File patterns to include */
|
|
55
|
+
includePatterns?: string[];
|
|
56
|
+
/** File patterns to exclude */
|
|
57
|
+
excludePatterns?: string[];
|
|
58
|
+
/** Maximum file size to read (bytes) */
|
|
59
|
+
maxFileSize?: number;
|
|
60
|
+
/** Whether to enable file writes */
|
|
61
|
+
allowWrites?: boolean;
|
|
63
62
|
}
|
|
64
63
|
/**
|
|
65
64
|
* Workspace context for AI chat
|
|
66
65
|
*/
|
|
67
|
-
declare class WorkspaceContext {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
66
|
+
export declare class WorkspaceContext {
|
|
67
|
+
readonly workspacePath: string;
|
|
68
|
+
readonly allowWrites: boolean;
|
|
69
|
+
private specs;
|
|
70
|
+
private files;
|
|
71
|
+
private initialized;
|
|
72
|
+
constructor(config: WorkspaceContextConfig);
|
|
73
|
+
/**
|
|
74
|
+
* Initialize the workspace context by scanning files
|
|
75
|
+
*/
|
|
76
|
+
initialize(): Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* Get all discovered specs
|
|
79
|
+
*/
|
|
80
|
+
getSpecs(): SpecInfo[];
|
|
81
|
+
/**
|
|
82
|
+
* Get all discovered files
|
|
83
|
+
*/
|
|
84
|
+
getFiles(): FileInfo[];
|
|
85
|
+
/**
|
|
86
|
+
* Add specs to the context
|
|
87
|
+
*/
|
|
88
|
+
addSpecs(specs: SpecInfo[]): void;
|
|
89
|
+
/**
|
|
90
|
+
* Add files to the context
|
|
91
|
+
*/
|
|
92
|
+
addFiles(files: FileInfo[]): void;
|
|
93
|
+
/**
|
|
94
|
+
* Get a summary of the workspace for context
|
|
95
|
+
*/
|
|
96
|
+
getSummary(): WorkspaceSummary;
|
|
97
|
+
/**
|
|
98
|
+
* Get a context summary for LLM prompts
|
|
99
|
+
*/
|
|
100
|
+
getContextSummary(): string;
|
|
101
|
+
/**
|
|
102
|
+
* Find specs matching a query
|
|
103
|
+
*/
|
|
104
|
+
findSpecs(query: string): SpecInfo[];
|
|
105
|
+
/**
|
|
106
|
+
* Find files matching a query
|
|
107
|
+
*/
|
|
108
|
+
findFiles(query: string): FileInfo[];
|
|
110
109
|
}
|
|
111
110
|
/**
|
|
112
111
|
* Create a workspace context from a path
|
|
113
112
|
*/
|
|
114
|
-
declare function createWorkspaceContext(path: string, options?: Partial<WorkspaceContextConfig>): Promise<WorkspaceContext>;
|
|
115
|
-
//#endregion
|
|
116
|
-
export { FileInfo, SpecInfo, WorkspaceContext, WorkspaceContextConfig, WorkspaceSummary, createWorkspaceContext };
|
|
113
|
+
export declare function createWorkspaceContext(path: string, options?: Partial<WorkspaceContextConfig>): Promise<WorkspaceContext>;
|
|
117
114
|
//# sourceMappingURL=workspace-context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workspace-context.d.ts","
|
|
1
|
+
{"version":3,"file":"workspace-context.d.ts","sourceRoot":"","sources":["../../src/context/workspace-context.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,SAAS,GAAG,OAAO,GAAG,OAAO,GAAG,cAAc,CAAC;IACrD,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE;QACL,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;QACf,aAAa,EAAE,MAAM,CAAC;KACvB,CAAC;IACF,KAAK,EAAE;QACL,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,iCAAiC;IACjC,aAAa,EAAE,MAAM,CAAC;IACtB,+BAA+B;IAC/B,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,+BAA+B;IAC/B,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,wCAAwC;IACxC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oCAAoC;IACpC,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;GAEG;AACH,qBAAa,gBAAgB;IAC3B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAE9B,OAAO,CAAC,KAAK,CAAkB;IAC/B,OAAO,CAAC,KAAK,CAAkB;IAC/B,OAAO,CAAC,WAAW,CAAS;gBAEhB,MAAM,EAAE,sBAAsB;IAK1C;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAQjC;;OAEG;IACH,QAAQ,IAAI,QAAQ,EAAE;IAItB;;OAEG;IACH,QAAQ,IAAI,QAAQ,EAAE;IAItB;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAI;IAIjC;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAI;IAIjC;;OAEG;IACH,UAAU,IAAI,gBAAgB;IA6B9B;;OAEG;IACH,iBAAiB,IAAI,MAAM;IA2B3B;;OAEG;IACH,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,EAAE;IAUpC;;OAEG;IACH,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,EAAE;CAQrC;AAED;;GAEG;AACH,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,OAAO,CAAC,sBAAsB,CAAC,GACxC,OAAO,CAAC,gBAAgB,CAAC,CAO3B"}
|