@ksm0709/context 0.0.7 → 0.0.8
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/context.js +1579 -0
- package/package.json +8 -2
package/dist/context.js
ADDED
|
@@ -0,0 +1,1579 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/context.ts
|
|
3
|
+
import { join as join4 } from "path";
|
|
4
|
+
|
|
5
|
+
// node_modules/jsonc-parser/lib/esm/impl/scanner.js
|
|
6
|
+
function createScanner(text, ignoreTrivia = false) {
|
|
7
|
+
const len = text.length;
|
|
8
|
+
let pos = 0, value = "", tokenOffset = 0, token = 16, lineNumber = 0, lineStartOffset = 0, tokenLineStartOffset = 0, prevTokenLineStartOffset = 0, scanError = 0;
|
|
9
|
+
function scanHexDigits(count, exact) {
|
|
10
|
+
let digits = 0;
|
|
11
|
+
let value2 = 0;
|
|
12
|
+
while (digits < count || !exact) {
|
|
13
|
+
let ch = text.charCodeAt(pos);
|
|
14
|
+
if (ch >= 48 && ch <= 57) {
|
|
15
|
+
value2 = value2 * 16 + ch - 48;
|
|
16
|
+
} else if (ch >= 65 && ch <= 70) {
|
|
17
|
+
value2 = value2 * 16 + ch - 65 + 10;
|
|
18
|
+
} else if (ch >= 97 && ch <= 102) {
|
|
19
|
+
value2 = value2 * 16 + ch - 97 + 10;
|
|
20
|
+
} else {
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
pos++;
|
|
24
|
+
digits++;
|
|
25
|
+
}
|
|
26
|
+
if (digits < count) {
|
|
27
|
+
value2 = -1;
|
|
28
|
+
}
|
|
29
|
+
return value2;
|
|
30
|
+
}
|
|
31
|
+
function setPosition(newPosition) {
|
|
32
|
+
pos = newPosition;
|
|
33
|
+
value = "";
|
|
34
|
+
tokenOffset = 0;
|
|
35
|
+
token = 16;
|
|
36
|
+
scanError = 0;
|
|
37
|
+
}
|
|
38
|
+
function scanNumber() {
|
|
39
|
+
let start = pos;
|
|
40
|
+
if (text.charCodeAt(pos) === 48) {
|
|
41
|
+
pos++;
|
|
42
|
+
} else {
|
|
43
|
+
pos++;
|
|
44
|
+
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
45
|
+
pos++;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (pos < text.length && text.charCodeAt(pos) === 46) {
|
|
49
|
+
pos++;
|
|
50
|
+
if (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
51
|
+
pos++;
|
|
52
|
+
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
53
|
+
pos++;
|
|
54
|
+
}
|
|
55
|
+
} else {
|
|
56
|
+
scanError = 3;
|
|
57
|
+
return text.substring(start, pos);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
let end = pos;
|
|
61
|
+
if (pos < text.length && (text.charCodeAt(pos) === 69 || text.charCodeAt(pos) === 101)) {
|
|
62
|
+
pos++;
|
|
63
|
+
if (pos < text.length && text.charCodeAt(pos) === 43 || text.charCodeAt(pos) === 45) {
|
|
64
|
+
pos++;
|
|
65
|
+
}
|
|
66
|
+
if (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
67
|
+
pos++;
|
|
68
|
+
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
69
|
+
pos++;
|
|
70
|
+
}
|
|
71
|
+
end = pos;
|
|
72
|
+
} else {
|
|
73
|
+
scanError = 3;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return text.substring(start, end);
|
|
77
|
+
}
|
|
78
|
+
function scanString() {
|
|
79
|
+
let result = "", start = pos;
|
|
80
|
+
while (true) {
|
|
81
|
+
if (pos >= len) {
|
|
82
|
+
result += text.substring(start, pos);
|
|
83
|
+
scanError = 2;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
const ch = text.charCodeAt(pos);
|
|
87
|
+
if (ch === 34) {
|
|
88
|
+
result += text.substring(start, pos);
|
|
89
|
+
pos++;
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
if (ch === 92) {
|
|
93
|
+
result += text.substring(start, pos);
|
|
94
|
+
pos++;
|
|
95
|
+
if (pos >= len) {
|
|
96
|
+
scanError = 2;
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
const ch2 = text.charCodeAt(pos++);
|
|
100
|
+
switch (ch2) {
|
|
101
|
+
case 34:
|
|
102
|
+
result += '"';
|
|
103
|
+
break;
|
|
104
|
+
case 92:
|
|
105
|
+
result += "\\";
|
|
106
|
+
break;
|
|
107
|
+
case 47:
|
|
108
|
+
result += "/";
|
|
109
|
+
break;
|
|
110
|
+
case 98:
|
|
111
|
+
result += "\b";
|
|
112
|
+
break;
|
|
113
|
+
case 102:
|
|
114
|
+
result += "\f";
|
|
115
|
+
break;
|
|
116
|
+
case 110:
|
|
117
|
+
result += `
|
|
118
|
+
`;
|
|
119
|
+
break;
|
|
120
|
+
case 114:
|
|
121
|
+
result += "\r";
|
|
122
|
+
break;
|
|
123
|
+
case 116:
|
|
124
|
+
result += "\t";
|
|
125
|
+
break;
|
|
126
|
+
case 117:
|
|
127
|
+
const ch3 = scanHexDigits(4, true);
|
|
128
|
+
if (ch3 >= 0) {
|
|
129
|
+
result += String.fromCharCode(ch3);
|
|
130
|
+
} else {
|
|
131
|
+
scanError = 4;
|
|
132
|
+
}
|
|
133
|
+
break;
|
|
134
|
+
default:
|
|
135
|
+
scanError = 5;
|
|
136
|
+
}
|
|
137
|
+
start = pos;
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
if (ch >= 0 && ch <= 31) {
|
|
141
|
+
if (isLineBreak(ch)) {
|
|
142
|
+
result += text.substring(start, pos);
|
|
143
|
+
scanError = 2;
|
|
144
|
+
break;
|
|
145
|
+
} else {
|
|
146
|
+
scanError = 6;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
pos++;
|
|
150
|
+
}
|
|
151
|
+
return result;
|
|
152
|
+
}
|
|
153
|
+
function scanNext() {
|
|
154
|
+
value = "";
|
|
155
|
+
scanError = 0;
|
|
156
|
+
tokenOffset = pos;
|
|
157
|
+
lineStartOffset = lineNumber;
|
|
158
|
+
prevTokenLineStartOffset = tokenLineStartOffset;
|
|
159
|
+
if (pos >= len) {
|
|
160
|
+
tokenOffset = len;
|
|
161
|
+
return token = 17;
|
|
162
|
+
}
|
|
163
|
+
let code = text.charCodeAt(pos);
|
|
164
|
+
if (isWhiteSpace(code)) {
|
|
165
|
+
do {
|
|
166
|
+
pos++;
|
|
167
|
+
value += String.fromCharCode(code);
|
|
168
|
+
code = text.charCodeAt(pos);
|
|
169
|
+
} while (isWhiteSpace(code));
|
|
170
|
+
return token = 15;
|
|
171
|
+
}
|
|
172
|
+
if (isLineBreak(code)) {
|
|
173
|
+
pos++;
|
|
174
|
+
value += String.fromCharCode(code);
|
|
175
|
+
if (code === 13 && text.charCodeAt(pos) === 10) {
|
|
176
|
+
pos++;
|
|
177
|
+
value += `
|
|
178
|
+
`;
|
|
179
|
+
}
|
|
180
|
+
lineNumber++;
|
|
181
|
+
tokenLineStartOffset = pos;
|
|
182
|
+
return token = 14;
|
|
183
|
+
}
|
|
184
|
+
switch (code) {
|
|
185
|
+
case 123:
|
|
186
|
+
pos++;
|
|
187
|
+
return token = 1;
|
|
188
|
+
case 125:
|
|
189
|
+
pos++;
|
|
190
|
+
return token = 2;
|
|
191
|
+
case 91:
|
|
192
|
+
pos++;
|
|
193
|
+
return token = 3;
|
|
194
|
+
case 93:
|
|
195
|
+
pos++;
|
|
196
|
+
return token = 4;
|
|
197
|
+
case 58:
|
|
198
|
+
pos++;
|
|
199
|
+
return token = 6;
|
|
200
|
+
case 44:
|
|
201
|
+
pos++;
|
|
202
|
+
return token = 5;
|
|
203
|
+
case 34:
|
|
204
|
+
pos++;
|
|
205
|
+
value = scanString();
|
|
206
|
+
return token = 10;
|
|
207
|
+
case 47:
|
|
208
|
+
const start = pos - 1;
|
|
209
|
+
if (text.charCodeAt(pos + 1) === 47) {
|
|
210
|
+
pos += 2;
|
|
211
|
+
while (pos < len) {
|
|
212
|
+
if (isLineBreak(text.charCodeAt(pos))) {
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
pos++;
|
|
216
|
+
}
|
|
217
|
+
value = text.substring(start, pos);
|
|
218
|
+
return token = 12;
|
|
219
|
+
}
|
|
220
|
+
if (text.charCodeAt(pos + 1) === 42) {
|
|
221
|
+
pos += 2;
|
|
222
|
+
const safeLength = len - 1;
|
|
223
|
+
let commentClosed = false;
|
|
224
|
+
while (pos < safeLength) {
|
|
225
|
+
const ch = text.charCodeAt(pos);
|
|
226
|
+
if (ch === 42 && text.charCodeAt(pos + 1) === 47) {
|
|
227
|
+
pos += 2;
|
|
228
|
+
commentClosed = true;
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
pos++;
|
|
232
|
+
if (isLineBreak(ch)) {
|
|
233
|
+
if (ch === 13 && text.charCodeAt(pos) === 10) {
|
|
234
|
+
pos++;
|
|
235
|
+
}
|
|
236
|
+
lineNumber++;
|
|
237
|
+
tokenLineStartOffset = pos;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
if (!commentClosed) {
|
|
241
|
+
pos++;
|
|
242
|
+
scanError = 1;
|
|
243
|
+
}
|
|
244
|
+
value = text.substring(start, pos);
|
|
245
|
+
return token = 13;
|
|
246
|
+
}
|
|
247
|
+
value += String.fromCharCode(code);
|
|
248
|
+
pos++;
|
|
249
|
+
return token = 16;
|
|
250
|
+
case 45:
|
|
251
|
+
value += String.fromCharCode(code);
|
|
252
|
+
pos++;
|
|
253
|
+
if (pos === len || !isDigit(text.charCodeAt(pos))) {
|
|
254
|
+
return token = 16;
|
|
255
|
+
}
|
|
256
|
+
case 48:
|
|
257
|
+
case 49:
|
|
258
|
+
case 50:
|
|
259
|
+
case 51:
|
|
260
|
+
case 52:
|
|
261
|
+
case 53:
|
|
262
|
+
case 54:
|
|
263
|
+
case 55:
|
|
264
|
+
case 56:
|
|
265
|
+
case 57:
|
|
266
|
+
value += scanNumber();
|
|
267
|
+
return token = 11;
|
|
268
|
+
default:
|
|
269
|
+
while (pos < len && isUnknownContentCharacter(code)) {
|
|
270
|
+
pos++;
|
|
271
|
+
code = text.charCodeAt(pos);
|
|
272
|
+
}
|
|
273
|
+
if (tokenOffset !== pos) {
|
|
274
|
+
value = text.substring(tokenOffset, pos);
|
|
275
|
+
switch (value) {
|
|
276
|
+
case "true":
|
|
277
|
+
return token = 8;
|
|
278
|
+
case "false":
|
|
279
|
+
return token = 9;
|
|
280
|
+
case "null":
|
|
281
|
+
return token = 7;
|
|
282
|
+
}
|
|
283
|
+
return token = 16;
|
|
284
|
+
}
|
|
285
|
+
value += String.fromCharCode(code);
|
|
286
|
+
pos++;
|
|
287
|
+
return token = 16;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
function isUnknownContentCharacter(code) {
|
|
291
|
+
if (isWhiteSpace(code) || isLineBreak(code)) {
|
|
292
|
+
return false;
|
|
293
|
+
}
|
|
294
|
+
switch (code) {
|
|
295
|
+
case 125:
|
|
296
|
+
case 93:
|
|
297
|
+
case 123:
|
|
298
|
+
case 91:
|
|
299
|
+
case 34:
|
|
300
|
+
case 58:
|
|
301
|
+
case 44:
|
|
302
|
+
case 47:
|
|
303
|
+
return false;
|
|
304
|
+
}
|
|
305
|
+
return true;
|
|
306
|
+
}
|
|
307
|
+
function scanNextNonTrivia() {
|
|
308
|
+
let result;
|
|
309
|
+
do {
|
|
310
|
+
result = scanNext();
|
|
311
|
+
} while (result >= 12 && result <= 15);
|
|
312
|
+
return result;
|
|
313
|
+
}
|
|
314
|
+
return {
|
|
315
|
+
setPosition,
|
|
316
|
+
getPosition: () => pos,
|
|
317
|
+
scan: ignoreTrivia ? scanNextNonTrivia : scanNext,
|
|
318
|
+
getToken: () => token,
|
|
319
|
+
getTokenValue: () => value,
|
|
320
|
+
getTokenOffset: () => tokenOffset,
|
|
321
|
+
getTokenLength: () => pos - tokenOffset,
|
|
322
|
+
getTokenStartLine: () => lineStartOffset,
|
|
323
|
+
getTokenStartCharacter: () => tokenOffset - prevTokenLineStartOffset,
|
|
324
|
+
getTokenError: () => scanError
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
function isWhiteSpace(ch) {
|
|
328
|
+
return ch === 32 || ch === 9;
|
|
329
|
+
}
|
|
330
|
+
function isLineBreak(ch) {
|
|
331
|
+
return ch === 10 || ch === 13;
|
|
332
|
+
}
|
|
333
|
+
function isDigit(ch) {
|
|
334
|
+
return ch >= 48 && ch <= 57;
|
|
335
|
+
}
|
|
336
|
+
var CharacterCodes;
|
|
337
|
+
(function(CharacterCodes2) {
|
|
338
|
+
CharacterCodes2[CharacterCodes2["lineFeed"] = 10] = "lineFeed";
|
|
339
|
+
CharacterCodes2[CharacterCodes2["carriageReturn"] = 13] = "carriageReturn";
|
|
340
|
+
CharacterCodes2[CharacterCodes2["space"] = 32] = "space";
|
|
341
|
+
CharacterCodes2[CharacterCodes2["_0"] = 48] = "_0";
|
|
342
|
+
CharacterCodes2[CharacterCodes2["_1"] = 49] = "_1";
|
|
343
|
+
CharacterCodes2[CharacterCodes2["_2"] = 50] = "_2";
|
|
344
|
+
CharacterCodes2[CharacterCodes2["_3"] = 51] = "_3";
|
|
345
|
+
CharacterCodes2[CharacterCodes2["_4"] = 52] = "_4";
|
|
346
|
+
CharacterCodes2[CharacterCodes2["_5"] = 53] = "_5";
|
|
347
|
+
CharacterCodes2[CharacterCodes2["_6"] = 54] = "_6";
|
|
348
|
+
CharacterCodes2[CharacterCodes2["_7"] = 55] = "_7";
|
|
349
|
+
CharacterCodes2[CharacterCodes2["_8"] = 56] = "_8";
|
|
350
|
+
CharacterCodes2[CharacterCodes2["_9"] = 57] = "_9";
|
|
351
|
+
CharacterCodes2[CharacterCodes2["a"] = 97] = "a";
|
|
352
|
+
CharacterCodes2[CharacterCodes2["b"] = 98] = "b";
|
|
353
|
+
CharacterCodes2[CharacterCodes2["c"] = 99] = "c";
|
|
354
|
+
CharacterCodes2[CharacterCodes2["d"] = 100] = "d";
|
|
355
|
+
CharacterCodes2[CharacterCodes2["e"] = 101] = "e";
|
|
356
|
+
CharacterCodes2[CharacterCodes2["f"] = 102] = "f";
|
|
357
|
+
CharacterCodes2[CharacterCodes2["g"] = 103] = "g";
|
|
358
|
+
CharacterCodes2[CharacterCodes2["h"] = 104] = "h";
|
|
359
|
+
CharacterCodes2[CharacterCodes2["i"] = 105] = "i";
|
|
360
|
+
CharacterCodes2[CharacterCodes2["j"] = 106] = "j";
|
|
361
|
+
CharacterCodes2[CharacterCodes2["k"] = 107] = "k";
|
|
362
|
+
CharacterCodes2[CharacterCodes2["l"] = 108] = "l";
|
|
363
|
+
CharacterCodes2[CharacterCodes2["m"] = 109] = "m";
|
|
364
|
+
CharacterCodes2[CharacterCodes2["n"] = 110] = "n";
|
|
365
|
+
CharacterCodes2[CharacterCodes2["o"] = 111] = "o";
|
|
366
|
+
CharacterCodes2[CharacterCodes2["p"] = 112] = "p";
|
|
367
|
+
CharacterCodes2[CharacterCodes2["q"] = 113] = "q";
|
|
368
|
+
CharacterCodes2[CharacterCodes2["r"] = 114] = "r";
|
|
369
|
+
CharacterCodes2[CharacterCodes2["s"] = 115] = "s";
|
|
370
|
+
CharacterCodes2[CharacterCodes2["t"] = 116] = "t";
|
|
371
|
+
CharacterCodes2[CharacterCodes2["u"] = 117] = "u";
|
|
372
|
+
CharacterCodes2[CharacterCodes2["v"] = 118] = "v";
|
|
373
|
+
CharacterCodes2[CharacterCodes2["w"] = 119] = "w";
|
|
374
|
+
CharacterCodes2[CharacterCodes2["x"] = 120] = "x";
|
|
375
|
+
CharacterCodes2[CharacterCodes2["y"] = 121] = "y";
|
|
376
|
+
CharacterCodes2[CharacterCodes2["z"] = 122] = "z";
|
|
377
|
+
CharacterCodes2[CharacterCodes2["A"] = 65] = "A";
|
|
378
|
+
CharacterCodes2[CharacterCodes2["B"] = 66] = "B";
|
|
379
|
+
CharacterCodes2[CharacterCodes2["C"] = 67] = "C";
|
|
380
|
+
CharacterCodes2[CharacterCodes2["D"] = 68] = "D";
|
|
381
|
+
CharacterCodes2[CharacterCodes2["E"] = 69] = "E";
|
|
382
|
+
CharacterCodes2[CharacterCodes2["F"] = 70] = "F";
|
|
383
|
+
CharacterCodes2[CharacterCodes2["G"] = 71] = "G";
|
|
384
|
+
CharacterCodes2[CharacterCodes2["H"] = 72] = "H";
|
|
385
|
+
CharacterCodes2[CharacterCodes2["I"] = 73] = "I";
|
|
386
|
+
CharacterCodes2[CharacterCodes2["J"] = 74] = "J";
|
|
387
|
+
CharacterCodes2[CharacterCodes2["K"] = 75] = "K";
|
|
388
|
+
CharacterCodes2[CharacterCodes2["L"] = 76] = "L";
|
|
389
|
+
CharacterCodes2[CharacterCodes2["M"] = 77] = "M";
|
|
390
|
+
CharacterCodes2[CharacterCodes2["N"] = 78] = "N";
|
|
391
|
+
CharacterCodes2[CharacterCodes2["O"] = 79] = "O";
|
|
392
|
+
CharacterCodes2[CharacterCodes2["P"] = 80] = "P";
|
|
393
|
+
CharacterCodes2[CharacterCodes2["Q"] = 81] = "Q";
|
|
394
|
+
CharacterCodes2[CharacterCodes2["R"] = 82] = "R";
|
|
395
|
+
CharacterCodes2[CharacterCodes2["S"] = 83] = "S";
|
|
396
|
+
CharacterCodes2[CharacterCodes2["T"] = 84] = "T";
|
|
397
|
+
CharacterCodes2[CharacterCodes2["U"] = 85] = "U";
|
|
398
|
+
CharacterCodes2[CharacterCodes2["V"] = 86] = "V";
|
|
399
|
+
CharacterCodes2[CharacterCodes2["W"] = 87] = "W";
|
|
400
|
+
CharacterCodes2[CharacterCodes2["X"] = 88] = "X";
|
|
401
|
+
CharacterCodes2[CharacterCodes2["Y"] = 89] = "Y";
|
|
402
|
+
CharacterCodes2[CharacterCodes2["Z"] = 90] = "Z";
|
|
403
|
+
CharacterCodes2[CharacterCodes2["asterisk"] = 42] = "asterisk";
|
|
404
|
+
CharacterCodes2[CharacterCodes2["backslash"] = 92] = "backslash";
|
|
405
|
+
CharacterCodes2[CharacterCodes2["closeBrace"] = 125] = "closeBrace";
|
|
406
|
+
CharacterCodes2[CharacterCodes2["closeBracket"] = 93] = "closeBracket";
|
|
407
|
+
CharacterCodes2[CharacterCodes2["colon"] = 58] = "colon";
|
|
408
|
+
CharacterCodes2[CharacterCodes2["comma"] = 44] = "comma";
|
|
409
|
+
CharacterCodes2[CharacterCodes2["dot"] = 46] = "dot";
|
|
410
|
+
CharacterCodes2[CharacterCodes2["doubleQuote"] = 34] = "doubleQuote";
|
|
411
|
+
CharacterCodes2[CharacterCodes2["minus"] = 45] = "minus";
|
|
412
|
+
CharacterCodes2[CharacterCodes2["openBrace"] = 123] = "openBrace";
|
|
413
|
+
CharacterCodes2[CharacterCodes2["openBracket"] = 91] = "openBracket";
|
|
414
|
+
CharacterCodes2[CharacterCodes2["plus"] = 43] = "plus";
|
|
415
|
+
CharacterCodes2[CharacterCodes2["slash"] = 47] = "slash";
|
|
416
|
+
CharacterCodes2[CharacterCodes2["formFeed"] = 12] = "formFeed";
|
|
417
|
+
CharacterCodes2[CharacterCodes2["tab"] = 9] = "tab";
|
|
418
|
+
})(CharacterCodes || (CharacterCodes = {}));
|
|
419
|
+
|
|
420
|
+
// node_modules/jsonc-parser/lib/esm/impl/string-intern.js
|
|
421
|
+
var cachedSpaces = new Array(20).fill(0).map((_, index) => {
|
|
422
|
+
return " ".repeat(index);
|
|
423
|
+
});
|
|
424
|
+
var maxCachedValues = 200;
|
|
425
|
+
var cachedBreakLinesWithSpaces = {
|
|
426
|
+
" ": {
|
|
427
|
+
"\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
428
|
+
return `
|
|
429
|
+
` + " ".repeat(index);
|
|
430
|
+
}),
|
|
431
|
+
"\r": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
432
|
+
return "\r" + " ".repeat(index);
|
|
433
|
+
}),
|
|
434
|
+
"\r\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
435
|
+
return `\r
|
|
436
|
+
` + " ".repeat(index);
|
|
437
|
+
})
|
|
438
|
+
},
|
|
439
|
+
"\t": {
|
|
440
|
+
"\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
441
|
+
return `
|
|
442
|
+
` + "\t".repeat(index);
|
|
443
|
+
}),
|
|
444
|
+
"\r": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
445
|
+
return "\r" + "\t".repeat(index);
|
|
446
|
+
}),
|
|
447
|
+
"\r\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
448
|
+
return `\r
|
|
449
|
+
` + "\t".repeat(index);
|
|
450
|
+
})
|
|
451
|
+
}
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
// node_modules/jsonc-parser/lib/esm/impl/parser.js
|
|
455
|
+
var ParseOptions;
|
|
456
|
+
(function(ParseOptions2) {
|
|
457
|
+
ParseOptions2.DEFAULT = {
|
|
458
|
+
allowTrailingComma: false
|
|
459
|
+
};
|
|
460
|
+
})(ParseOptions || (ParseOptions = {}));
|
|
461
|
+
function parse(text, errors = [], options = ParseOptions.DEFAULT) {
|
|
462
|
+
let currentProperty = null;
|
|
463
|
+
let currentParent = [];
|
|
464
|
+
const previousParents = [];
|
|
465
|
+
function onValue(value) {
|
|
466
|
+
if (Array.isArray(currentParent)) {
|
|
467
|
+
currentParent.push(value);
|
|
468
|
+
} else if (currentProperty !== null) {
|
|
469
|
+
currentParent[currentProperty] = value;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
const visitor = {
|
|
473
|
+
onObjectBegin: () => {
|
|
474
|
+
const object = {};
|
|
475
|
+
onValue(object);
|
|
476
|
+
previousParents.push(currentParent);
|
|
477
|
+
currentParent = object;
|
|
478
|
+
currentProperty = null;
|
|
479
|
+
},
|
|
480
|
+
onObjectProperty: (name) => {
|
|
481
|
+
currentProperty = name;
|
|
482
|
+
},
|
|
483
|
+
onObjectEnd: () => {
|
|
484
|
+
currentParent = previousParents.pop();
|
|
485
|
+
},
|
|
486
|
+
onArrayBegin: () => {
|
|
487
|
+
const array = [];
|
|
488
|
+
onValue(array);
|
|
489
|
+
previousParents.push(currentParent);
|
|
490
|
+
currentParent = array;
|
|
491
|
+
currentProperty = null;
|
|
492
|
+
},
|
|
493
|
+
onArrayEnd: () => {
|
|
494
|
+
currentParent = previousParents.pop();
|
|
495
|
+
},
|
|
496
|
+
onLiteralValue: onValue,
|
|
497
|
+
onError: (error, offset, length) => {
|
|
498
|
+
errors.push({ error, offset, length });
|
|
499
|
+
}
|
|
500
|
+
};
|
|
501
|
+
visit(text, visitor, options);
|
|
502
|
+
return currentParent[0];
|
|
503
|
+
}
|
|
504
|
+
function visit(text, visitor, options = ParseOptions.DEFAULT) {
|
|
505
|
+
const _scanner = createScanner(text, false);
|
|
506
|
+
const _jsonPath = [];
|
|
507
|
+
let suppressedCallbacks = 0;
|
|
508
|
+
function toNoArgVisit(visitFunction) {
|
|
509
|
+
return visitFunction ? () => suppressedCallbacks === 0 && visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
|
|
510
|
+
}
|
|
511
|
+
function toOneArgVisit(visitFunction) {
|
|
512
|
+
return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
|
|
513
|
+
}
|
|
514
|
+
function toOneArgVisitWithPath(visitFunction) {
|
|
515
|
+
return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice()) : () => true;
|
|
516
|
+
}
|
|
517
|
+
function toBeginVisit(visitFunction) {
|
|
518
|
+
return visitFunction ? () => {
|
|
519
|
+
if (suppressedCallbacks > 0) {
|
|
520
|
+
suppressedCallbacks++;
|
|
521
|
+
} else {
|
|
522
|
+
let cbReturn = visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice());
|
|
523
|
+
if (cbReturn === false) {
|
|
524
|
+
suppressedCallbacks = 1;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
} : () => true;
|
|
528
|
+
}
|
|
529
|
+
function toEndVisit(visitFunction) {
|
|
530
|
+
return visitFunction ? () => {
|
|
531
|
+
if (suppressedCallbacks > 0) {
|
|
532
|
+
suppressedCallbacks--;
|
|
533
|
+
}
|
|
534
|
+
if (suppressedCallbacks === 0) {
|
|
535
|
+
visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter());
|
|
536
|
+
}
|
|
537
|
+
} : () => true;
|
|
538
|
+
}
|
|
539
|
+
const onObjectBegin = toBeginVisit(visitor.onObjectBegin), onObjectProperty = toOneArgVisitWithPath(visitor.onObjectProperty), onObjectEnd = toEndVisit(visitor.onObjectEnd), onArrayBegin = toBeginVisit(visitor.onArrayBegin), onArrayEnd = toEndVisit(visitor.onArrayEnd), onLiteralValue = toOneArgVisitWithPath(visitor.onLiteralValue), onSeparator = toOneArgVisit(visitor.onSeparator), onComment = toNoArgVisit(visitor.onComment), onError = toOneArgVisit(visitor.onError);
|
|
540
|
+
const disallowComments = options && options.disallowComments;
|
|
541
|
+
const allowTrailingComma = options && options.allowTrailingComma;
|
|
542
|
+
function scanNext() {
|
|
543
|
+
while (true) {
|
|
544
|
+
const token = _scanner.scan();
|
|
545
|
+
switch (_scanner.getTokenError()) {
|
|
546
|
+
case 4:
|
|
547
|
+
handleError(14);
|
|
548
|
+
break;
|
|
549
|
+
case 5:
|
|
550
|
+
handleError(15);
|
|
551
|
+
break;
|
|
552
|
+
case 3:
|
|
553
|
+
handleError(13);
|
|
554
|
+
break;
|
|
555
|
+
case 1:
|
|
556
|
+
if (!disallowComments) {
|
|
557
|
+
handleError(11);
|
|
558
|
+
}
|
|
559
|
+
break;
|
|
560
|
+
case 2:
|
|
561
|
+
handleError(12);
|
|
562
|
+
break;
|
|
563
|
+
case 6:
|
|
564
|
+
handleError(16);
|
|
565
|
+
break;
|
|
566
|
+
}
|
|
567
|
+
switch (token) {
|
|
568
|
+
case 12:
|
|
569
|
+
case 13:
|
|
570
|
+
if (disallowComments) {
|
|
571
|
+
handleError(10);
|
|
572
|
+
} else {
|
|
573
|
+
onComment();
|
|
574
|
+
}
|
|
575
|
+
break;
|
|
576
|
+
case 16:
|
|
577
|
+
handleError(1);
|
|
578
|
+
break;
|
|
579
|
+
case 15:
|
|
580
|
+
case 14:
|
|
581
|
+
break;
|
|
582
|
+
default:
|
|
583
|
+
return token;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
function handleError(error, skipUntilAfter = [], skipUntil = []) {
|
|
588
|
+
onError(error);
|
|
589
|
+
if (skipUntilAfter.length + skipUntil.length > 0) {
|
|
590
|
+
let token = _scanner.getToken();
|
|
591
|
+
while (token !== 17) {
|
|
592
|
+
if (skipUntilAfter.indexOf(token) !== -1) {
|
|
593
|
+
scanNext();
|
|
594
|
+
break;
|
|
595
|
+
} else if (skipUntil.indexOf(token) !== -1) {
|
|
596
|
+
break;
|
|
597
|
+
}
|
|
598
|
+
token = scanNext();
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
function parseString(isValue) {
|
|
603
|
+
const value = _scanner.getTokenValue();
|
|
604
|
+
if (isValue) {
|
|
605
|
+
onLiteralValue(value);
|
|
606
|
+
} else {
|
|
607
|
+
onObjectProperty(value);
|
|
608
|
+
_jsonPath.push(value);
|
|
609
|
+
}
|
|
610
|
+
scanNext();
|
|
611
|
+
return true;
|
|
612
|
+
}
|
|
613
|
+
function parseLiteral() {
|
|
614
|
+
switch (_scanner.getToken()) {
|
|
615
|
+
case 11:
|
|
616
|
+
const tokenValue = _scanner.getTokenValue();
|
|
617
|
+
let value = Number(tokenValue);
|
|
618
|
+
if (isNaN(value)) {
|
|
619
|
+
handleError(2);
|
|
620
|
+
value = 0;
|
|
621
|
+
}
|
|
622
|
+
onLiteralValue(value);
|
|
623
|
+
break;
|
|
624
|
+
case 7:
|
|
625
|
+
onLiteralValue(null);
|
|
626
|
+
break;
|
|
627
|
+
case 8:
|
|
628
|
+
onLiteralValue(true);
|
|
629
|
+
break;
|
|
630
|
+
case 9:
|
|
631
|
+
onLiteralValue(false);
|
|
632
|
+
break;
|
|
633
|
+
default:
|
|
634
|
+
return false;
|
|
635
|
+
}
|
|
636
|
+
scanNext();
|
|
637
|
+
return true;
|
|
638
|
+
}
|
|
639
|
+
function parseProperty() {
|
|
640
|
+
if (_scanner.getToken() !== 10) {
|
|
641
|
+
handleError(3, [], [2, 5]);
|
|
642
|
+
return false;
|
|
643
|
+
}
|
|
644
|
+
parseString(false);
|
|
645
|
+
if (_scanner.getToken() === 6) {
|
|
646
|
+
onSeparator(":");
|
|
647
|
+
scanNext();
|
|
648
|
+
if (!parseValue()) {
|
|
649
|
+
handleError(4, [], [2, 5]);
|
|
650
|
+
}
|
|
651
|
+
} else {
|
|
652
|
+
handleError(5, [], [2, 5]);
|
|
653
|
+
}
|
|
654
|
+
_jsonPath.pop();
|
|
655
|
+
return true;
|
|
656
|
+
}
|
|
657
|
+
function parseObject() {
|
|
658
|
+
onObjectBegin();
|
|
659
|
+
scanNext();
|
|
660
|
+
let needsComma = false;
|
|
661
|
+
while (_scanner.getToken() !== 2 && _scanner.getToken() !== 17) {
|
|
662
|
+
if (_scanner.getToken() === 5) {
|
|
663
|
+
if (!needsComma) {
|
|
664
|
+
handleError(4, [], []);
|
|
665
|
+
}
|
|
666
|
+
onSeparator(",");
|
|
667
|
+
scanNext();
|
|
668
|
+
if (_scanner.getToken() === 2 && allowTrailingComma) {
|
|
669
|
+
break;
|
|
670
|
+
}
|
|
671
|
+
} else if (needsComma) {
|
|
672
|
+
handleError(6, [], []);
|
|
673
|
+
}
|
|
674
|
+
if (!parseProperty()) {
|
|
675
|
+
handleError(4, [], [2, 5]);
|
|
676
|
+
}
|
|
677
|
+
needsComma = true;
|
|
678
|
+
}
|
|
679
|
+
onObjectEnd();
|
|
680
|
+
if (_scanner.getToken() !== 2) {
|
|
681
|
+
handleError(7, [2], []);
|
|
682
|
+
} else {
|
|
683
|
+
scanNext();
|
|
684
|
+
}
|
|
685
|
+
return true;
|
|
686
|
+
}
|
|
687
|
+
function parseArray() {
|
|
688
|
+
onArrayBegin();
|
|
689
|
+
scanNext();
|
|
690
|
+
let isFirstElement = true;
|
|
691
|
+
let needsComma = false;
|
|
692
|
+
while (_scanner.getToken() !== 4 && _scanner.getToken() !== 17) {
|
|
693
|
+
if (_scanner.getToken() === 5) {
|
|
694
|
+
if (!needsComma) {
|
|
695
|
+
handleError(4, [], []);
|
|
696
|
+
}
|
|
697
|
+
onSeparator(",");
|
|
698
|
+
scanNext();
|
|
699
|
+
if (_scanner.getToken() === 4 && allowTrailingComma) {
|
|
700
|
+
break;
|
|
701
|
+
}
|
|
702
|
+
} else if (needsComma) {
|
|
703
|
+
handleError(6, [], []);
|
|
704
|
+
}
|
|
705
|
+
if (isFirstElement) {
|
|
706
|
+
_jsonPath.push(0);
|
|
707
|
+
isFirstElement = false;
|
|
708
|
+
} else {
|
|
709
|
+
_jsonPath[_jsonPath.length - 1]++;
|
|
710
|
+
}
|
|
711
|
+
if (!parseValue()) {
|
|
712
|
+
handleError(4, [], [4, 5]);
|
|
713
|
+
}
|
|
714
|
+
needsComma = true;
|
|
715
|
+
}
|
|
716
|
+
onArrayEnd();
|
|
717
|
+
if (!isFirstElement) {
|
|
718
|
+
_jsonPath.pop();
|
|
719
|
+
}
|
|
720
|
+
if (_scanner.getToken() !== 4) {
|
|
721
|
+
handleError(8, [4], []);
|
|
722
|
+
} else {
|
|
723
|
+
scanNext();
|
|
724
|
+
}
|
|
725
|
+
return true;
|
|
726
|
+
}
|
|
727
|
+
function parseValue() {
|
|
728
|
+
switch (_scanner.getToken()) {
|
|
729
|
+
case 3:
|
|
730
|
+
return parseArray();
|
|
731
|
+
case 1:
|
|
732
|
+
return parseObject();
|
|
733
|
+
case 10:
|
|
734
|
+
return parseString(true);
|
|
735
|
+
default:
|
|
736
|
+
return parseLiteral();
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
scanNext();
|
|
740
|
+
if (_scanner.getToken() === 17) {
|
|
741
|
+
if (options.allowEmptyContent) {
|
|
742
|
+
return true;
|
|
743
|
+
}
|
|
744
|
+
handleError(4, [], []);
|
|
745
|
+
return false;
|
|
746
|
+
}
|
|
747
|
+
if (!parseValue()) {
|
|
748
|
+
handleError(4, [], []);
|
|
749
|
+
return false;
|
|
750
|
+
}
|
|
751
|
+
if (_scanner.getToken() !== 17) {
|
|
752
|
+
handleError(9, [], []);
|
|
753
|
+
}
|
|
754
|
+
return true;
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
// node_modules/jsonc-parser/lib/esm/main.js
|
|
758
|
+
var ScanError;
|
|
759
|
+
(function(ScanError2) {
|
|
760
|
+
ScanError2[ScanError2["None"] = 0] = "None";
|
|
761
|
+
ScanError2[ScanError2["UnexpectedEndOfComment"] = 1] = "UnexpectedEndOfComment";
|
|
762
|
+
ScanError2[ScanError2["UnexpectedEndOfString"] = 2] = "UnexpectedEndOfString";
|
|
763
|
+
ScanError2[ScanError2["UnexpectedEndOfNumber"] = 3] = "UnexpectedEndOfNumber";
|
|
764
|
+
ScanError2[ScanError2["InvalidUnicode"] = 4] = "InvalidUnicode";
|
|
765
|
+
ScanError2[ScanError2["InvalidEscapeCharacter"] = 5] = "InvalidEscapeCharacter";
|
|
766
|
+
ScanError2[ScanError2["InvalidCharacter"] = 6] = "InvalidCharacter";
|
|
767
|
+
})(ScanError || (ScanError = {}));
|
|
768
|
+
var SyntaxKind;
|
|
769
|
+
(function(SyntaxKind2) {
|
|
770
|
+
SyntaxKind2[SyntaxKind2["OpenBraceToken"] = 1] = "OpenBraceToken";
|
|
771
|
+
SyntaxKind2[SyntaxKind2["CloseBraceToken"] = 2] = "CloseBraceToken";
|
|
772
|
+
SyntaxKind2[SyntaxKind2["OpenBracketToken"] = 3] = "OpenBracketToken";
|
|
773
|
+
SyntaxKind2[SyntaxKind2["CloseBracketToken"] = 4] = "CloseBracketToken";
|
|
774
|
+
SyntaxKind2[SyntaxKind2["CommaToken"] = 5] = "CommaToken";
|
|
775
|
+
SyntaxKind2[SyntaxKind2["ColonToken"] = 6] = "ColonToken";
|
|
776
|
+
SyntaxKind2[SyntaxKind2["NullKeyword"] = 7] = "NullKeyword";
|
|
777
|
+
SyntaxKind2[SyntaxKind2["TrueKeyword"] = 8] = "TrueKeyword";
|
|
778
|
+
SyntaxKind2[SyntaxKind2["FalseKeyword"] = 9] = "FalseKeyword";
|
|
779
|
+
SyntaxKind2[SyntaxKind2["StringLiteral"] = 10] = "StringLiteral";
|
|
780
|
+
SyntaxKind2[SyntaxKind2["NumericLiteral"] = 11] = "NumericLiteral";
|
|
781
|
+
SyntaxKind2[SyntaxKind2["LineCommentTrivia"] = 12] = "LineCommentTrivia";
|
|
782
|
+
SyntaxKind2[SyntaxKind2["BlockCommentTrivia"] = 13] = "BlockCommentTrivia";
|
|
783
|
+
SyntaxKind2[SyntaxKind2["LineBreakTrivia"] = 14] = "LineBreakTrivia";
|
|
784
|
+
SyntaxKind2[SyntaxKind2["Trivia"] = 15] = "Trivia";
|
|
785
|
+
SyntaxKind2[SyntaxKind2["Unknown"] = 16] = "Unknown";
|
|
786
|
+
SyntaxKind2[SyntaxKind2["EOF"] = 17] = "EOF";
|
|
787
|
+
})(SyntaxKind || (SyntaxKind = {}));
|
|
788
|
+
var parse2 = parse;
|
|
789
|
+
var ParseErrorCode;
|
|
790
|
+
(function(ParseErrorCode2) {
|
|
791
|
+
ParseErrorCode2[ParseErrorCode2["InvalidSymbol"] = 1] = "InvalidSymbol";
|
|
792
|
+
ParseErrorCode2[ParseErrorCode2["InvalidNumberFormat"] = 2] = "InvalidNumberFormat";
|
|
793
|
+
ParseErrorCode2[ParseErrorCode2["PropertyNameExpected"] = 3] = "PropertyNameExpected";
|
|
794
|
+
ParseErrorCode2[ParseErrorCode2["ValueExpected"] = 4] = "ValueExpected";
|
|
795
|
+
ParseErrorCode2[ParseErrorCode2["ColonExpected"] = 5] = "ColonExpected";
|
|
796
|
+
ParseErrorCode2[ParseErrorCode2["CommaExpected"] = 6] = "CommaExpected";
|
|
797
|
+
ParseErrorCode2[ParseErrorCode2["CloseBraceExpected"] = 7] = "CloseBraceExpected";
|
|
798
|
+
ParseErrorCode2[ParseErrorCode2["CloseBracketExpected"] = 8] = "CloseBracketExpected";
|
|
799
|
+
ParseErrorCode2[ParseErrorCode2["EndOfFileExpected"] = 9] = "EndOfFileExpected";
|
|
800
|
+
ParseErrorCode2[ParseErrorCode2["InvalidCommentToken"] = 10] = "InvalidCommentToken";
|
|
801
|
+
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfComment"] = 11] = "UnexpectedEndOfComment";
|
|
802
|
+
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfString"] = 12] = "UnexpectedEndOfString";
|
|
803
|
+
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfNumber"] = 13] = "UnexpectedEndOfNumber";
|
|
804
|
+
ParseErrorCode2[ParseErrorCode2["InvalidUnicode"] = 14] = "InvalidUnicode";
|
|
805
|
+
ParseErrorCode2[ParseErrorCode2["InvalidEscapeCharacter"] = 15] = "InvalidEscapeCharacter";
|
|
806
|
+
ParseErrorCode2[ParseErrorCode2["InvalidCharacter"] = 16] = "InvalidCharacter";
|
|
807
|
+
})(ParseErrorCode || (ParseErrorCode = {}));
|
|
808
|
+
|
|
809
|
+
// src/lib/config.ts
|
|
810
|
+
import { readFileSync } from "fs";
|
|
811
|
+
import { join } from "path";
|
|
812
|
+
|
|
813
|
+
// src/constants.ts
|
|
814
|
+
var DEFAULTS = {
|
|
815
|
+
configPath: ".opencode/context/config.jsonc",
|
|
816
|
+
promptDir: ".opencode/context/prompts",
|
|
817
|
+
turnStartFile: "turn-start.md",
|
|
818
|
+
turnEndFile: "turn-end.md",
|
|
819
|
+
knowledgeSources: ["AGENTS.md"],
|
|
820
|
+
knowledgeDir: "docs",
|
|
821
|
+
templateDir: ".opencode/context/templates",
|
|
822
|
+
indexFilename: "INDEX.md",
|
|
823
|
+
maxDomainDepth: 2
|
|
824
|
+
};
|
|
825
|
+
var LIMITS = {
|
|
826
|
+
maxPromptFileSize: 64 * 1024,
|
|
827
|
+
maxIndexEntries: 100,
|
|
828
|
+
maxTotalInjectionSize: 128 * 1024,
|
|
829
|
+
maxScanDepth: 3,
|
|
830
|
+
maxSummaryLength: 100,
|
|
831
|
+
maxIndexFileSize: 32 * 1024
|
|
832
|
+
};
|
|
833
|
+
|
|
834
|
+
// src/lib/config.ts
|
|
835
|
+
function getDefaultConfig() {
|
|
836
|
+
return {
|
|
837
|
+
prompts: {
|
|
838
|
+
turnStart: join(DEFAULTS.promptDir, DEFAULTS.turnStartFile),
|
|
839
|
+
turnEnd: join(DEFAULTS.promptDir, DEFAULTS.turnEndFile)
|
|
840
|
+
},
|
|
841
|
+
knowledge: {
|
|
842
|
+
dir: DEFAULTS.knowledgeDir,
|
|
843
|
+
sources: [...DEFAULTS.knowledgeSources],
|
|
844
|
+
mode: "auto",
|
|
845
|
+
indexFilename: DEFAULTS.indexFilename,
|
|
846
|
+
maxDomainDepth: DEFAULTS.maxDomainDepth
|
|
847
|
+
}
|
|
848
|
+
};
|
|
849
|
+
}
|
|
850
|
+
function mergeWithDefaults(partial) {
|
|
851
|
+
const defaults = getDefaultConfig();
|
|
852
|
+
return {
|
|
853
|
+
prompts: {
|
|
854
|
+
turnStart: partial.prompts?.turnStart ?? defaults.prompts.turnStart,
|
|
855
|
+
turnEnd: partial.prompts?.turnEnd ?? defaults.prompts.turnEnd
|
|
856
|
+
},
|
|
857
|
+
knowledge: {
|
|
858
|
+
dir: partial.knowledge?.dir ?? defaults.knowledge.dir,
|
|
859
|
+
sources: partial.knowledge?.sources ?? defaults.knowledge.sources,
|
|
860
|
+
mode: partial.knowledge?.mode ?? defaults.knowledge.mode,
|
|
861
|
+
indexFilename: partial.knowledge?.indexFilename ?? defaults.knowledge.indexFilename,
|
|
862
|
+
maxDomainDepth: partial.knowledge?.maxDomainDepth ?? defaults.knowledge.maxDomainDepth
|
|
863
|
+
}
|
|
864
|
+
};
|
|
865
|
+
}
|
|
866
|
+
function loadConfig(projectDir) {
|
|
867
|
+
const configPath = join(projectDir, DEFAULTS.configPath);
|
|
868
|
+
try {
|
|
869
|
+
const raw = readFileSync(configPath, "utf-8");
|
|
870
|
+
const parsed = parse2(raw);
|
|
871
|
+
if (!parsed || typeof parsed !== "object")
|
|
872
|
+
return getDefaultConfig();
|
|
873
|
+
return mergeWithDefaults(parsed);
|
|
874
|
+
} catch {
|
|
875
|
+
return getDefaultConfig();
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
// src/lib/knowledge-index.ts
|
|
880
|
+
import { readdirSync, readFileSync as readFileSync2, statSync, existsSync } from "fs";
|
|
881
|
+
import { join as join2, relative, extname } from "path";
|
|
882
|
+
function extractSummary(filePath) {
|
|
883
|
+
try {
|
|
884
|
+
const content = readFileSync2(filePath, "utf-8");
|
|
885
|
+
const firstNonEmpty = content.split(`
|
|
886
|
+
`).find((line) => line.trim().length > 0);
|
|
887
|
+
if (!firstNonEmpty)
|
|
888
|
+
return "";
|
|
889
|
+
return firstNonEmpty.trim().slice(0, LIMITS.maxSummaryLength);
|
|
890
|
+
} catch {
|
|
891
|
+
return "";
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
function scanDir(dir, projectDir, depth, entries) {
|
|
895
|
+
if (depth > LIMITS.maxScanDepth)
|
|
896
|
+
return;
|
|
897
|
+
if (entries.length >= LIMITS.maxIndexEntries)
|
|
898
|
+
return;
|
|
899
|
+
try {
|
|
900
|
+
const items = readdirSync(dir);
|
|
901
|
+
for (const item of items) {
|
|
902
|
+
if (entries.length >= LIMITS.maxIndexEntries)
|
|
903
|
+
break;
|
|
904
|
+
const fullPath = join2(dir, item);
|
|
905
|
+
try {
|
|
906
|
+
const stat = statSync(fullPath);
|
|
907
|
+
if (stat.isDirectory()) {
|
|
908
|
+
scanDir(fullPath, projectDir, depth + 1, entries);
|
|
909
|
+
} else if (stat.isFile() && extname(item) === ".md") {
|
|
910
|
+
entries.push({
|
|
911
|
+
filename: relative(projectDir, fullPath),
|
|
912
|
+
summary: extractSummary(fullPath)
|
|
913
|
+
});
|
|
914
|
+
}
|
|
915
|
+
} catch {}
|
|
916
|
+
}
|
|
917
|
+
} catch {}
|
|
918
|
+
}
|
|
919
|
+
function buildKnowledgeIndex(projectDir, sources) {
|
|
920
|
+
const entries = [];
|
|
921
|
+
for (const source of sources) {
|
|
922
|
+
if (entries.length >= LIMITS.maxIndexEntries)
|
|
923
|
+
break;
|
|
924
|
+
const fullPath = join2(projectDir, source);
|
|
925
|
+
if (!existsSync(fullPath))
|
|
926
|
+
continue;
|
|
927
|
+
try {
|
|
928
|
+
const stat = statSync(fullPath);
|
|
929
|
+
if (stat.isFile() && extname(source) === ".md") {
|
|
930
|
+
entries.push({
|
|
931
|
+
filename: source,
|
|
932
|
+
summary: extractSummary(fullPath)
|
|
933
|
+
});
|
|
934
|
+
} else if (stat.isDirectory()) {
|
|
935
|
+
scanDir(fullPath, projectDir, 1, entries);
|
|
936
|
+
}
|
|
937
|
+
} catch {}
|
|
938
|
+
}
|
|
939
|
+
return entries;
|
|
940
|
+
}
|
|
941
|
+
function formatKnowledgeIndex(entries) {
|
|
942
|
+
if (entries.length === 0)
|
|
943
|
+
return "";
|
|
944
|
+
const lines = ["## Available Knowledge", ""];
|
|
945
|
+
for (const entry of entries) {
|
|
946
|
+
lines.push(`- ${entry.filename}${entry.summary ? ` \u2014 ${entry.summary}` : ""}`);
|
|
947
|
+
}
|
|
948
|
+
return lines.join(`
|
|
949
|
+
`);
|
|
950
|
+
}
|
|
951
|
+
function countMdFiles(dir, indexFilename) {
|
|
952
|
+
try {
|
|
953
|
+
const items = readdirSync(dir);
|
|
954
|
+
return items.filter((item) => extname(item) === ".md" && item !== indexFilename && statSync(join2(dir, item)).isFile()).length;
|
|
955
|
+
} catch {
|
|
956
|
+
return 0;
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
function scanDomainsRecursive(baseDir, projectDir, indexFilename, currentDepth, maxDepth, results) {
|
|
960
|
+
if (currentDepth > maxDepth)
|
|
961
|
+
return;
|
|
962
|
+
try {
|
|
963
|
+
const items = readdirSync(baseDir);
|
|
964
|
+
for (const item of items) {
|
|
965
|
+
const fullPath = join2(baseDir, item);
|
|
966
|
+
try {
|
|
967
|
+
if (!statSync(fullPath).isDirectory())
|
|
968
|
+
continue;
|
|
969
|
+
const indexPath = join2(fullPath, indexFilename);
|
|
970
|
+
if (existsSync(indexPath) && statSync(indexPath).isFile()) {
|
|
971
|
+
const rawContent = readFileSync2(indexPath, "utf-8");
|
|
972
|
+
const indexContent = rawContent.slice(0, LIMITS.maxIndexFileSize);
|
|
973
|
+
results.push({
|
|
974
|
+
domain: item,
|
|
975
|
+
path: relative(projectDir, fullPath),
|
|
976
|
+
indexContent,
|
|
977
|
+
noteCount: countMdFiles(fullPath, indexFilename)
|
|
978
|
+
});
|
|
979
|
+
}
|
|
980
|
+
scanDomainsRecursive(fullPath, projectDir, indexFilename, currentDepth + 1, maxDepth, results);
|
|
981
|
+
} catch {}
|
|
982
|
+
}
|
|
983
|
+
} catch {}
|
|
984
|
+
}
|
|
985
|
+
function scanDomains(projectDir, knowledgeDir, indexFilename, maxDepth) {
|
|
986
|
+
const baseDir = join2(projectDir, knowledgeDir);
|
|
987
|
+
if (!existsSync(baseDir))
|
|
988
|
+
return [];
|
|
989
|
+
const results = [];
|
|
990
|
+
scanDomainsRecursive(baseDir, projectDir, indexFilename, 1, maxDepth, results);
|
|
991
|
+
return results;
|
|
992
|
+
}
|
|
993
|
+
function detectKnowledgeMode(projectDir, knowledgeDir, indexFilename, configMode) {
|
|
994
|
+
if (configMode !== "auto")
|
|
995
|
+
return configMode;
|
|
996
|
+
const domains = scanDomains(projectDir, knowledgeDir, indexFilename, 1);
|
|
997
|
+
return domains.length > 0 ? "domain" : "flat";
|
|
998
|
+
}
|
|
999
|
+
function formatDomainIndex(index) {
|
|
1000
|
+
const hasDomains = index.domains.length > 0;
|
|
1001
|
+
const hasFiles = index.individualFiles.length > 0;
|
|
1002
|
+
if (!hasDomains && !hasFiles)
|
|
1003
|
+
return "";
|
|
1004
|
+
const lines = ["## Available Knowledge", ""];
|
|
1005
|
+
if (hasDomains) {
|
|
1006
|
+
lines.push("### Domains", "");
|
|
1007
|
+
for (const domain of index.domains) {
|
|
1008
|
+
lines.push(`#### ${domain.path}/ (${domain.noteCount} notes)`, "");
|
|
1009
|
+
lines.push(domain.indexContent, "");
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
if (hasFiles) {
|
|
1013
|
+
if (hasDomains) {
|
|
1014
|
+
lines.push("### Individual Files", "");
|
|
1015
|
+
}
|
|
1016
|
+
for (const file of index.individualFiles) {
|
|
1017
|
+
lines.push(`- ${file.filename}${file.summary ? ` \u2014 ${file.summary}` : ""}`);
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
return lines.join(`
|
|
1021
|
+
`);
|
|
1022
|
+
}
|
|
1023
|
+
function collectRootFiles(projectDir, knowledgeDir, indexFilename) {
|
|
1024
|
+
const baseDir = join2(projectDir, knowledgeDir);
|
|
1025
|
+
if (!existsSync(baseDir))
|
|
1026
|
+
return [];
|
|
1027
|
+
const entries = [];
|
|
1028
|
+
try {
|
|
1029
|
+
const items = readdirSync(baseDir);
|
|
1030
|
+
for (const item of items) {
|
|
1031
|
+
const fullPath = join2(baseDir, item);
|
|
1032
|
+
try {
|
|
1033
|
+
const stat = statSync(fullPath);
|
|
1034
|
+
if (stat.isFile() && extname(item) === ".md" && item !== indexFilename) {
|
|
1035
|
+
entries.push({
|
|
1036
|
+
filename: relative(projectDir, fullPath),
|
|
1037
|
+
summary: extractSummary(fullPath)
|
|
1038
|
+
});
|
|
1039
|
+
}
|
|
1040
|
+
} catch {}
|
|
1041
|
+
}
|
|
1042
|
+
} catch {}
|
|
1043
|
+
return entries;
|
|
1044
|
+
}
|
|
1045
|
+
function buildKnowledgeIndexV2(projectDir, knowledgeConfig) {
|
|
1046
|
+
const dir = knowledgeConfig.dir ?? "docs";
|
|
1047
|
+
const indexFilename = knowledgeConfig.indexFilename ?? "INDEX.md";
|
|
1048
|
+
const maxDepth = knowledgeConfig.maxDomainDepth ?? 2;
|
|
1049
|
+
const configMode = knowledgeConfig.mode ?? "auto";
|
|
1050
|
+
const mode = detectKnowledgeMode(projectDir, dir, indexFilename, configMode);
|
|
1051
|
+
if (mode === "flat") {
|
|
1052
|
+
const allSources = [dir, ...knowledgeConfig.sources].filter(Boolean);
|
|
1053
|
+
const entries = buildKnowledgeIndex(projectDir, allSources);
|
|
1054
|
+
return { mode: "flat", domains: [], individualFiles: entries };
|
|
1055
|
+
}
|
|
1056
|
+
const domains = scanDomains(projectDir, dir, indexFilename, maxDepth);
|
|
1057
|
+
const rootFiles = collectRootFiles(projectDir, dir, indexFilename);
|
|
1058
|
+
const sourcesEntries = [];
|
|
1059
|
+
for (const source of knowledgeConfig.sources) {
|
|
1060
|
+
const fullPath = join2(projectDir, source);
|
|
1061
|
+
if (!existsSync(fullPath))
|
|
1062
|
+
continue;
|
|
1063
|
+
try {
|
|
1064
|
+
const stat = statSync(fullPath);
|
|
1065
|
+
if (stat.isFile() && extname(source) === ".md") {
|
|
1066
|
+
sourcesEntries.push({
|
|
1067
|
+
filename: source,
|
|
1068
|
+
summary: extractSummary(fullPath)
|
|
1069
|
+
});
|
|
1070
|
+
}
|
|
1071
|
+
} catch {}
|
|
1072
|
+
}
|
|
1073
|
+
const individualFiles = [...rootFiles, ...sourcesEntries];
|
|
1074
|
+
return { mode: "domain", domains, individualFiles };
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
// src/lib/prompt-reader.ts
|
|
1078
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
1079
|
+
function readPromptFile(filePath) {
|
|
1080
|
+
try {
|
|
1081
|
+
const content = readFileSync3(filePath, "utf-8");
|
|
1082
|
+
if (content.length > LIMITS.maxPromptFileSize) {
|
|
1083
|
+
return content.slice(0, LIMITS.maxPromptFileSize);
|
|
1084
|
+
}
|
|
1085
|
+
return content;
|
|
1086
|
+
} catch {
|
|
1087
|
+
return "";
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
// src/lib/scaffold.ts
|
|
1092
|
+
import { existsSync as existsSync2, mkdirSync, readFileSync as readFileSync4, writeFileSync } from "fs";
|
|
1093
|
+
import { join as join3 } from "path";
|
|
1094
|
+
|
|
1095
|
+
// src/version.ts
|
|
1096
|
+
var PLUGIN_VERSION = "0.0.6";
|
|
1097
|
+
|
|
1098
|
+
// src/lib/scaffold.ts
|
|
1099
|
+
var DEFAULT_CONFIG = `{
|
|
1100
|
+
// Context Plugin Configuration
|
|
1101
|
+
// See: https://github.com/ksm0709/context
|
|
1102
|
+
"prompts": {
|
|
1103
|
+
"turnStart": ".opencode/context/prompts/turn-start.md",
|
|
1104
|
+
"turnEnd": ".opencode/context/prompts/turn-end.md"
|
|
1105
|
+
},
|
|
1106
|
+
"knowledge": {
|
|
1107
|
+
"dir": "docs",
|
|
1108
|
+
"sources": ["AGENTS.md"]
|
|
1109
|
+
}
|
|
1110
|
+
}`;
|
|
1111
|
+
var DEFAULT_TURN_START = `## Knowledge Context
|
|
1112
|
+
|
|
1113
|
+
\uC774 \uD504\uB85C\uC81D\uD2B8\uB294 **\uC81C\uD154\uCE74\uC2A4\uD150(Zettelkasten)** \uBC29\uC2DD\uC73C\uB85C \uC9C0\uC2DD\uC744 \uAD00\uB9AC\uD569\uB2C8\uB2E4.
|
|
1114
|
+
\uC138\uC158 \uAC04 \uCEE8\uD14D\uC2A4\uD2B8\uB97C \uBCF4\uC874\uD558\uC5EC, \uC774\uC804 \uC138\uC158\uC758 \uACB0\uC815/\uD328\uD134/\uC2E4\uC218\uAC00 \uB2E4\uC74C \uC138\uC158\uC5D0\uC11C \uC7AC\uD65C\uC6A9\uB429\uB2C8\uB2E4.
|
|
1115
|
+
|
|
1116
|
+
### \uC81C\uD154\uCE74\uC2A4\uD150 \uD575\uC2EC \uC6D0\uCE59
|
|
1117
|
+
|
|
1118
|
+
1. **\uC6D0\uC790\uC131** -- \uD558\uB098\uC758 \uB178\uD2B8 = \uD558\uB098\uC758 \uC8FC\uC81C. \uC5EC\uB7EC \uC8FC\uC81C\uB97C \uC11E\uC9C0 \uB9C8\uC138\uC694.
|
|
1119
|
+
2. **\uC5F0\uACB0** -- \uBAA8\uB4E0 \uB178\uD2B8\uB294 [[wikilink]]\uB85C \uAD00\uB828 \uB178\uD2B8\uC5D0 \uC5F0\uACB0. \uACE0\uB9BD\uB41C \uB178\uD2B8\uB294 \uBC1C\uACAC\uB418\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.
|
|
1120
|
+
3. **\uC790\uAE30 \uC5B8\uC5B4** -- \uBCF5\uC0AC-\uBD99\uC5EC\uB123\uAE30\uAC00 \uC544\uB2CC, \uD575\uC2EC\uC744 \uC774\uD574\uD558\uACE0 \uAC04\uACB0\uD558\uAC8C \uC11C\uC220\uD558\uC138\uC694.
|
|
1121
|
+
|
|
1122
|
+
### \uC791\uC5C5 \uC804 \uD544\uC218
|
|
1123
|
+
|
|
1124
|
+
- \uC544\uB798 **Available Knowledge** \uBAA9\uB85D\uC5D0\uC11C \uD604\uC7AC \uC791\uC5C5\uACFC \uAD00\uB828\uB41C \uBB38\uC11C\uB97C **\uBA3C\uC800** \uC77D\uC73C\uC138\uC694
|
|
1125
|
+
- \uB3C4\uBA54\uC778 \uD3F4\uB354 \uAD6C\uC870\uAC00 \uC788\uB2E4\uBA74 INDEX.md\uC758 \uC694\uC57D\uC744 \uCC38\uACE0\uD558\uC5EC \uD544\uC694\uD55C \uB178\uD2B8\uB9CC \uC120\uD0DD\uC801\uC73C\uB85C \uC77D\uC73C\uC138\uC694
|
|
1126
|
+
- \uBB38\uC11C \uB0B4 [[\uB9C1\uD06C]]\uB97C \uB530\uB77C\uAC00\uBA70 \uAD00\uB828 \uB178\uD2B8\uB97C \uD0D0\uC0C9\uD558\uC138\uC694 -- \uB9C1\uD06C\uB97C \uB193\uCE58\uBA74 \uC911\uC694\uD55C \uB9E5\uB77D\uC744 \uC783\uC2B5\uB2C8\uB2E4
|
|
1127
|
+
- \uC9C0\uC2DD \uD30C\uC77C\uC5D0 \uAE30\uB85D\uB41C \uC544\uD0A4\uD14D\uCC98 \uACB0\uC815, \uD328\uD134, \uC81C\uC57D\uC0AC\uD56D\uC744 \uBC18\uB4DC\uC2DC \uB530\uB974\uC138\uC694
|
|
1128
|
+
|
|
1129
|
+
### \uAC1C\uBC1C \uC6D0\uCE59
|
|
1130
|
+
|
|
1131
|
+
- **TDD** (Test-Driven Development): \uD14C\uC2A4\uD2B8\uB97C \uBA3C\uC800 \uC791\uC131\uD558\uACE0(RED), \uAD6C\uD604\uD558\uC5EC \uD1B5\uACFC\uC2DC\uD0A8 \uB4A4(GREEN), \uB9AC\uD329\uD1A0\uB9C1\uD558\uC138\uC694
|
|
1132
|
+
- **DDD** (Domain-Driven Design): \uB3C4\uBA54\uC778 \uAC1C\uB150\uC744 \uCF54\uB4DC \uAD6C\uC870\uC5D0 \uBC18\uC601\uD558\uC138\uC694. \uD0C0\uC785\uACFC \uBAA8\uB4C8\uC740 \uBE44\uC988\uB2C8\uC2A4 \uB3C4\uBA54\uC778\uC744 \uAE30\uC900\uC73C\uB85C \uBD84\uB9AC\uD558\uC138\uC694
|
|
1133
|
+
- **\uD14C\uC2A4\uD2B8 \uCEE4\uBC84\uB9AC\uC9C0**: \uC0C8\uB85C \uC791\uC131\uD558\uAC70\uB098 \uBCC0\uACBD\uD55C \uCF54\uB4DC\uB294 \uD14C\uC2A4\uD2B8 \uCEE4\uBC84\uB9AC\uC9C0 80% \uC774\uC0C1\uC744 \uBAA9\uD45C\uB85C \uD558\uC138\uC694. \uAD6C\uD604 \uC804\uC5D0 \uD14C\uC2A4\uD2B8\uBD80\uD130 \uC791\uC131\uD558\uBA74 \uC790\uC5F0\uC2A4\uB7FD\uAC8C \uB2EC\uC131\uB429\uB2C8\uB2E4
|
|
1134
|
+
|
|
1135
|
+
### \uC6B0\uC120\uC21C\uC704
|
|
1136
|
+
|
|
1137
|
+
- AGENTS.md\uC758 \uC9C0\uC2DC\uC0AC\uD56D\uC774 \uD56D\uC0C1 \uCD5C\uC6B0\uC120
|
|
1138
|
+
- \uC9C0\uC2DD \uB178\uD2B8\uC758 \uACB0\uC815\uC0AC\uD56D > \uC77C\uBC18\uC801 \uAD00\uD589
|
|
1139
|
+
- \uC9C0\uC2DD \uB178\uD2B8\uC5D0 \uC5C6\uB294 \uC0C8\uB85C\uC6B4 \uACB0\uC815\uC740 \uC791\uC5C5 \uC644\uB8CC \uC2DC \uAE30\uB85D\uD558\uC138\uC694
|
|
1140
|
+
`;
|
|
1141
|
+
var DEFAULT_TURN_END = `## \uC791\uC5C5 \uB9C8\uBB34\uB9AC \uCCB4\uD06C\uB9AC\uC2A4\uD2B8
|
|
1142
|
+
|
|
1143
|
+
\uC791\uC5C5\uC744 \uC644\uB8CC\uD558\uAE30 \uC804\uC5D0 \uBC18\uB4DC\uC2DC:
|
|
1144
|
+
|
|
1145
|
+
### \uD004\uB9AC\uD2F0 \uBCF4\uC7A5
|
|
1146
|
+
|
|
1147
|
+
- [ ] \uBCC0\uACBD\uD55C \uCF54\uB4DC\uC5D0 \uB300\uD574 lint \uC2E4\uD589
|
|
1148
|
+
- [ ] \uBCC0\uACBD\uD55C \uCF54\uB4DC\uC5D0 \uB300\uD574 formatter \uC2E4\uD589 (lint\uC640 \uBCC4\uAC1C)
|
|
1149
|
+
- [ ] \uAE30\uC874 \uD14C\uC2A4\uD2B8 \uD1B5\uACFC \uD655\uC778
|
|
1150
|
+
- [ ] \uBCC0\uACBD \uBC94\uC704 \uD655\uC778: \uC694\uCCAD\uACFC \uBB34\uAD00\uD55C \uD30C\uC77C\uC744 \uAC74\uB4DC\uB9AC\uC9C0 \uC54A\uC558\uB294\uAC00?
|
|
1151
|
+
- [ ] \uC0C8\uB85C \uC791\uC131\uD558\uAC70\uB098 \uBCC0\uACBD\uD55C \uCF54\uB4DC\uC758 \uD14C\uC2A4\uD2B8 \uCEE4\uBC84\uB9AC\uC9C0 80% \uC774\uC0C1 \uB2EC\uC131
|
|
1152
|
+
|
|
1153
|
+
### \uC9C0\uC2DD \uC815\uB9AC (Zettelkasten)
|
|
1154
|
+
|
|
1155
|
+
\uC544\uB798 \uC0C1\uD669\uC5D0 \uD574\uB2F9\uD558\uBA74, \uD574\uB2F9 \uD15C\uD50C\uB9BF \uD30C\uC77C\uC744 \uC77D\uACE0 \uADF8 \uAD6C\uC870\uC5D0 \uB9DE\uCDB0 \uB178\uD2B8\uB97C \uC791\uC131\uD558\uC138\uC694.
|
|
1156
|
+
|
|
1157
|
+
| \uC0C1\uD669 | \uD15C\uD50C\uB9BF | \uD30C\uC77C\uBA85 \uD328\uD134 |
|
|
1158
|
+
| ------------------------------- | --------------------------------------------------- | --------------------------- |
|
|
1159
|
+
| \uC544\uD0A4\uD14D\uCC98/\uAE30\uC220 \uC2A4\uD0DD \uC911\uB300 \uACB0\uC815 | [ADR](.opencode/context/templates/adr.md) | \`adr-NNN-\uC81C\uBAA9.md\` |
|
|
1160
|
+
| \uBC18\uBCF5 \uC0AC\uC6A9\uD560 \uCF54\uB4DC \uD328\uD134 \uBC1C\uACAC | [Pattern](.opencode/context/templates/pattern.md) | \`pattern-\uC81C\uBAA9.md\` |
|
|
1161
|
+
| \uBE44\uC790\uBA85\uD55C \uBC84\uADF8 \uD574\uACB0 | [Bug](.opencode/context/templates/bug.md) | \`bug-\uC81C\uBAA9.md\` |
|
|
1162
|
+
| \uC678\uBD80 API/\uB77C\uC774\uBE0C\uB7EC\uB9AC \uC608\uC0C1\uC678 \uB3D9\uC791 | [Gotcha](.opencode/context/templates/gotcha.md) | \`gotcha-\uB77C\uC774\uBE0C\uB7EC\uB9AC-\uC81C\uBAA9.md\` |
|
|
1163
|
+
| \uC791\uC740 \uAE30\uC220\uC801 \uC120\uD0DD | [Decision](.opencode/context/templates/decision.md) | \`decision-\uC81C\uBAA9.md\` |
|
|
1164
|
+
| \uBAA8\uB4C8/\uD504\uB85C\uC81D\uD2B8 \uAC1C\uC694 \uD544\uC694 | [Context](.opencode/context/templates/context.md) | \`context-\uC81C\uBAA9.md\` |
|
|
1165
|
+
| \uBC18\uBCF5 \uAC00\uB2A5\uD55C \uD504\uB85C\uC138\uC2A4 \uC815\uB9BD | [Runbook](.opencode/context/templates/runbook.md) | \`runbook-\uC81C\uBAA9.md\` |
|
|
1166
|
+
| \uC2E4\uD5D8/\uB514\uBC84\uAE45 \uC911 \uD559\uC2B5 | [Insight](.opencode/context/templates/insight.md) | \`insight-\uC81C\uBAA9.md\` |
|
|
1167
|
+
|
|
1168
|
+
- [ ] \uC704 \uC0C1\uD669\uC5D0 \uD574\uB2F9\uD558\uB294 \uBC1C\uACAC\uC774 \uC788\uC5C8\uB2E4\uBA74 \uB178\uD2B8\uB97C \uC791\uC131\uD588\uB294\uAC00?
|
|
1169
|
+
- [ ] \uAD00\uB828 \uAE30\uC874 \uB178\uD2B8\uC5D0 [[\uB9C1\uD06C]]\uB97C \uCD94\uAC00\uD588\uB294\uAC00?
|
|
1170
|
+
- [ ] \uAE30\uC874 \uB178\uD2B8\uC758 \uB0B4\uC6A9\uC774 \uBCC0\uACBD\uC0AC\uD56D\uACFC \uBD88\uC77C\uCE58\uD558\uBA74 \uC5C5\uB370\uC774\uD2B8\uD588\uB294\uAC00?
|
|
1171
|
+
- [ ] \uB178\uD2B8\uB97C \uB3C4\uBA54\uC778 \uD3F4\uB354\uC5D0 \uC800\uC7A5\uD588\uB2E4\uBA74 \uD574\uB2F9 INDEX.md\uC5D0 \uCD94\uAC00\uD588\uB294\uAC00?
|
|
1172
|
+
|
|
1173
|
+
#### \uB178\uD2B8 \uC791\uC131 \uADDC\uCE59
|
|
1174
|
+
|
|
1175
|
+
- \uCCAB \uC904: \uBA85\uD655\uD55C \uC81C\uBAA9 (\`# Title\`)
|
|
1176
|
+
- \uD575\uC2EC \uB0B4\uC6A9\uC744 \uC790\uC2E0\uC758 \uC5B8\uC5B4\uB85C \uAC04\uACB0\uD558\uAC8C \uC11C\uC220
|
|
1177
|
+
- \uAD00\uB828 \uB178\uD2B8\uB97C \`[[relative/path/file.md]]\` \uD615\uD0DC\uC758 wikilink\uB85C \uC5F0\uACB0
|
|
1178
|
+
- knowledge \uB514\uB809\uD1A0\uB9AC (\uAE30\uBCF8: \`docs/\`)\uC5D0 \uC800\uC7A5. \uB3C4\uBA54\uC778 \uD3F4\uB354\uAC00 \uC788\uB2E4\uBA74 \uC801\uC808\uD55C \uB3C4\uBA54\uC778\uC5D0 \uC800\uC7A5
|
|
1179
|
+
`;
|
|
1180
|
+
var DEFAULT_ADR_TEMPLATE = `# ADR-NNN: [\uC81C\uBAA9]
|
|
1181
|
+
|
|
1182
|
+
## \uC0C1\uD0DC
|
|
1183
|
+
|
|
1184
|
+
Accepted | Deprecated | Superseded by [[ADR-YYY]]
|
|
1185
|
+
|
|
1186
|
+
## \uB9E5\uB77D
|
|
1187
|
+
|
|
1188
|
+
\uC774 \uACB0\uC815\uC744 \uB0B4\uB9AC\uAC8C \uB41C \uBC30\uACBD/\uBB38\uC81C \uC0C1\uD669
|
|
1189
|
+
|
|
1190
|
+
## \uACB0\uC815
|
|
1191
|
+
|
|
1192
|
+
\uBB34\uC5C7\uC744 \uC5B4\uB5BB\uAC8C \uD558\uAE30\uB85C \uD588\uB294\uC9C0
|
|
1193
|
+
|
|
1194
|
+
## \uACB0\uACFC
|
|
1195
|
+
|
|
1196
|
+
### \uAE0D\uC815\uC801
|
|
1197
|
+
|
|
1198
|
+
- ...
|
|
1199
|
+
|
|
1200
|
+
### \uBD80\uC815\uC801 (\uD2B8\uB808\uC774\uB4DC\uC624\uD504)
|
|
1201
|
+
|
|
1202
|
+
- ...
|
|
1203
|
+
|
|
1204
|
+
## \uAD00\uB828 \uB178\uD2B8
|
|
1205
|
+
|
|
1206
|
+
- [[\uAD00\uB828-\uACB0\uC815.md]] / [[\uAD00\uB828-\uD328\uD134.md]]
|
|
1207
|
+
`;
|
|
1208
|
+
var DEFAULT_PATTERN_TEMPLATE = `# Pattern: [\uD328\uD134 \uC774\uB984]
|
|
1209
|
+
|
|
1210
|
+
## \uBB38\uC81C
|
|
1211
|
+
|
|
1212
|
+
\uC774 \uD328\uD134\uC774 \uD574\uACB0\uD558\uB294 \uBB38\uC81C
|
|
1213
|
+
|
|
1214
|
+
## \uD574\uBC95
|
|
1215
|
+
|
|
1216
|
+
// \uD328\uD134\uC758 \uB300\uD45C\uC801 \uC608\uC2DC \uCF54\uB4DC
|
|
1217
|
+
|
|
1218
|
+
## \uC0AC\uC6A9 \uC2DC\uC810
|
|
1219
|
+
|
|
1220
|
+
- \uC774\uB7F4 \uB54C \uC0AC\uC6A9
|
|
1221
|
+
|
|
1222
|
+
## \uC0AC\uC6A9\uD558\uC9C0 \uB9D0 \uAC83
|
|
1223
|
+
|
|
1224
|
+
- \uC774\uB7F4 \uB54C\uB294 \uC0AC\uC6A9 \uAE08\uC9C0 (\uC548\uD2F0\uD328\uD134 \uACBD\uACE0)
|
|
1225
|
+
|
|
1226
|
+
## \uCF54\uB4DC\uBCA0\uC774\uC2A4 \uB0B4 \uC608\uC2DC
|
|
1227
|
+
|
|
1228
|
+
- [[\uACBD\uB85C/\uD30C\uC77C.ts]] -- \uC2E4\uC81C \uC801\uC6A9 \uC0AC\uB840
|
|
1229
|
+
|
|
1230
|
+
## \uAD00\uB828 \uD328\uD134
|
|
1231
|
+
|
|
1232
|
+
- [[\uB300\uC548-\uD328\uD134.md]] / [[\uBCF4\uC644-\uD328\uD134.md]]
|
|
1233
|
+
`;
|
|
1234
|
+
var DEFAULT_BUG_TEMPLATE = `# Bug: [\uAC04\uB2E8\uD55C \uC124\uBA85]
|
|
1235
|
+
|
|
1236
|
+
## \uC99D\uC0C1
|
|
1237
|
+
|
|
1238
|
+
- \uC5D0\uB7EC \uBA54\uC2DC\uC9C0: \`...\`
|
|
1239
|
+
- \uAD00\uCC30\uB41C \uB3D9\uC791: ...
|
|
1240
|
+
|
|
1241
|
+
## \uC6D0\uC778
|
|
1242
|
+
|
|
1243
|
+
\uC2E4\uC81C \uC6D0\uC778 \uBD84\uC11D
|
|
1244
|
+
|
|
1245
|
+
## \uD574\uACB0
|
|
1246
|
+
|
|
1247
|
+
// \uC218\uC815 \uCF54\uB4DC
|
|
1248
|
+
|
|
1249
|
+
## \uC608\uBC29
|
|
1250
|
+
|
|
1251
|
+
\uD5A5\uD6C4 \uAC19\uC740 \uBB38\uC81C\uB97C \uBC29\uC9C0\uD558\uB294 \uBC29\uBC95
|
|
1252
|
+
|
|
1253
|
+
## \uAD00\uB828 \uB178\uD2B8
|
|
1254
|
+
|
|
1255
|
+
- [[\uC720\uC0AC-\uBC84\uADF8.md]] / [[\uC608\uBC29-\uD328\uD134.md]]
|
|
1256
|
+
`;
|
|
1257
|
+
var DEFAULT_GOTCHA_TEMPLATE = `# Gotcha: [\uB77C\uC774\uBE0C\uB7EC\uB9AC] -- [\uD568\uC815 \uC124\uBA85]
|
|
1258
|
+
|
|
1259
|
+
## \uC608\uC0C1 vs \uC2E4\uC81C
|
|
1260
|
+
|
|
1261
|
+
\uC608\uC0C1\uD55C \uB3D9\uC791\uACFC \uC2E4\uC81C \uB3D9\uC791\uC758 \uCC28\uC774
|
|
1262
|
+
|
|
1263
|
+
## \uC6B0\uD68C\uBC95
|
|
1264
|
+
|
|
1265
|
+
// \uC791\uB3D9\uD558\uB294 \uD574\uACB0 \uCF54\uB4DC
|
|
1266
|
+
|
|
1267
|
+
## \uC6D0\uC778 (\uC54C\uB824\uC9C4 \uACBD\uC6B0)
|
|
1268
|
+
|
|
1269
|
+
\uC65C \uC774\uB807\uAC8C \uB3D9\uC791\uD558\uB294\uC9C0
|
|
1270
|
+
|
|
1271
|
+
## \uAD00\uB828
|
|
1272
|
+
|
|
1273
|
+
- \uC774\uC288: [GitHub issue / \uBB38\uC11C \uB9C1\uD06C]
|
|
1274
|
+
- [[\uAD00\uB828-gotcha.md]]
|
|
1275
|
+
`;
|
|
1276
|
+
var DEFAULT_DECISION_TEMPLATE = `# Decision: [\uC81C\uBAA9]
|
|
1277
|
+
|
|
1278
|
+
## \uACB0\uC815
|
|
1279
|
+
|
|
1280
|
+
\uBB34\uC5C7\uC744 \uC120\uD0DD\uD588\uB294\uC9C0
|
|
1281
|
+
|
|
1282
|
+
## \uADFC\uAC70
|
|
1283
|
+
|
|
1284
|
+
\uC65C \uC774\uAC83\uC744 \uC120\uD0DD\uD588\uB294\uC9C0
|
|
1285
|
+
|
|
1286
|
+
## \uACE0\uB824\uD55C \uB300\uC548
|
|
1287
|
+
|
|
1288
|
+
- \uB300\uC548 1: \uD0C8\uB77D \uC774\uC720
|
|
1289
|
+
- \uB300\uC548 2: \uD0C8\uB77D \uC774\uC720
|
|
1290
|
+
|
|
1291
|
+
## \uAD00\uB828 \uB178\uD2B8
|
|
1292
|
+
|
|
1293
|
+
- [[\uAD00\uB828-ADR.md]] / [[\uAD00\uB828-\uD328\uD134.md]]
|
|
1294
|
+
`;
|
|
1295
|
+
var DEFAULT_CONTEXT_TEMPLATE = `# Context: [\uD504\uB85C\uC81D\uD2B8/\uBAA8\uB4C8\uBA85]
|
|
1296
|
+
|
|
1297
|
+
## \uAC1C\uC694
|
|
1298
|
+
|
|
1299
|
+
\uBB34\uC5C7\uC774\uACE0 \uBB34\uC5C7\uC744 \uD558\uB294\uC9C0
|
|
1300
|
+
|
|
1301
|
+
## \uAE30\uC220 \uC2A4\uD0DD
|
|
1302
|
+
|
|
1303
|
+
- \uC5B8\uC5B4 / \uD504\uB808\uC784\uC6CC\uD06C / \uC8FC\uC694 \uB77C\uC774\uBE0C\uB7EC\uB9AC
|
|
1304
|
+
|
|
1305
|
+
## \uC544\uD0A4\uD14D\uCC98
|
|
1306
|
+
|
|
1307
|
+
\uACE0\uC218\uC900 \uAD6C\uC870\uC640 \uD328\uD134
|
|
1308
|
+
|
|
1309
|
+
## \uCEE8\uBCA4\uC158
|
|
1310
|
+
|
|
1311
|
+
- \uD30C\uC77C \uAD6C\uC870 / \uB124\uC774\uBC0D / \uD14C\uC2A4\uD2B8 \uBC29\uC2DD
|
|
1312
|
+
|
|
1313
|
+
## \uC9C4\uC785\uC810
|
|
1314
|
+
|
|
1315
|
+
- [[src/index.ts]] / [[config.json]]
|
|
1316
|
+
|
|
1317
|
+
## \uAD00\uB828 \uB178\uD2B8
|
|
1318
|
+
|
|
1319
|
+
- [[\uAD00\uB828-context.md]] / [[\uC8FC\uC694-ADR.md]]
|
|
1320
|
+
`;
|
|
1321
|
+
var DEFAULT_RUNBOOK_TEMPLATE = `# Runbook: [\uC808\uCC28 \uC774\uB984]
|
|
1322
|
+
|
|
1323
|
+
## \uBAA9\uC801
|
|
1324
|
+
|
|
1325
|
+
\uC774 \uC808\uCC28\uAC00 \uB2EC\uC131\uD558\uB294 \uAC83
|
|
1326
|
+
|
|
1327
|
+
## \uC0AC\uC804 \uC870\uAC74
|
|
1328
|
+
|
|
1329
|
+
- \uD544\uC694\uD55C \uAC83 1
|
|
1330
|
+
|
|
1331
|
+
## \uB2E8\uACC4
|
|
1332
|
+
|
|
1333
|
+
1. \uCCAB \uBC88\uC9F8 \uB2E8\uACC4
|
|
1334
|
+
2. \uB450 \uBC88\uC9F8 \uB2E8\uACC4
|
|
1335
|
+
|
|
1336
|
+
## \uD655\uC778 \uBC29\uBC95
|
|
1337
|
+
|
|
1338
|
+
\uC131\uACF5\uD588\uB294\uC9C0 \uD655\uC778\uD558\uB294 \uBC29\uBC95
|
|
1339
|
+
|
|
1340
|
+
## \uBB38\uC81C \uD574\uACB0
|
|
1341
|
+
|
|
1342
|
+
| \uC99D\uC0C1 | \uD574\uACB0 |
|
|
1343
|
+
| ------ | --------------- |
|
|
1344
|
+
| \uC774\uC288 1 | [[\uAD00\uB828-bug.md]] |
|
|
1345
|
+
|
|
1346
|
+
## \uAD00\uB828 \uB178\uD2B8
|
|
1347
|
+
|
|
1348
|
+
- [[\uAD00\uB828-runbook.md]] / [[\uAD00\uB828-context.md]]
|
|
1349
|
+
`;
|
|
1350
|
+
var DEFAULT_INSIGHT_TEMPLATE = `# Insight: [\uBC1C\uACAC \uC81C\uBAA9]
|
|
1351
|
+
|
|
1352
|
+
## \uBC1C\uACAC
|
|
1353
|
+
|
|
1354
|
+
\uBB34\uC5C7\uC744 \uC54C\uAC8C \uB418\uC5C8\uB294\uC9C0
|
|
1355
|
+
|
|
1356
|
+
## \uB9E5\uB77D
|
|
1357
|
+
|
|
1358
|
+
\uC5B4\uB5BB\uAC8C \uBC1C\uACAC\uD588\uB294\uC9C0 (\uC5B4\uB5A4 \uC791\uC5C5 \uC911, \uC5B4\uB5A4 \uC2E4\uD5D8)
|
|
1359
|
+
|
|
1360
|
+
## \uC2DC\uC0AC\uC810
|
|
1361
|
+
|
|
1362
|
+
\uC774\uAC83\uC774 \uD5A5\uD6C4 \uC791\uC5C5\uC5D0 \uBBF8\uCE58\uB294 \uC601\uD5A5
|
|
1363
|
+
|
|
1364
|
+
## \uC801\uC6A9
|
|
1365
|
+
|
|
1366
|
+
\uC774 \uBC1C\uACAC\uC744 \uBC14\uD0D5\uC73C\uB85C \uC5B4\uB5BB\uAC8C \uD589\uB3D9\uC744 \uBC14\uAFD4\uC57C \uD558\uB294\uC9C0
|
|
1367
|
+
|
|
1368
|
+
## \uAD00\uB828 \uB178\uD2B8
|
|
1369
|
+
|
|
1370
|
+
- [[\uAD00\uB828-insight.md]] / [[\uC601\uD5A5\uBC1B\uB294-\uD328\uD134.md]] / [[\uAD00\uB828-ADR.md]]
|
|
1371
|
+
`;
|
|
1372
|
+
var DEFAULT_INDEX_TEMPLATE = `# [Domain] Domain
|
|
1373
|
+
|
|
1374
|
+
Overview: [1-2 sentence description of this domain]
|
|
1375
|
+
|
|
1376
|
+
## Notes
|
|
1377
|
+
|
|
1378
|
+
| File | Summary | Read When... |
|
|
1379
|
+
|------|---------|--------------|
|
|
1380
|
+
| [[example.md]] | Example summary | Working on X |
|
|
1381
|
+
|
|
1382
|
+
## Related Domains
|
|
1383
|
+
|
|
1384
|
+
- [[../other-domain/INDEX.md]] -- Description
|
|
1385
|
+
`;
|
|
1386
|
+
var TEMPLATE_FILES = {
|
|
1387
|
+
"adr.md": DEFAULT_ADR_TEMPLATE,
|
|
1388
|
+
"pattern.md": DEFAULT_PATTERN_TEMPLATE,
|
|
1389
|
+
"bug.md": DEFAULT_BUG_TEMPLATE,
|
|
1390
|
+
"gotcha.md": DEFAULT_GOTCHA_TEMPLATE,
|
|
1391
|
+
"decision.md": DEFAULT_DECISION_TEMPLATE,
|
|
1392
|
+
"context.md": DEFAULT_CONTEXT_TEMPLATE,
|
|
1393
|
+
"runbook.md": DEFAULT_RUNBOOK_TEMPLATE,
|
|
1394
|
+
"insight.md": DEFAULT_INSIGHT_TEMPLATE,
|
|
1395
|
+
"index.md": DEFAULT_INDEX_TEMPLATE
|
|
1396
|
+
};
|
|
1397
|
+
function scaffoldIfNeeded(projectDir) {
|
|
1398
|
+
const contextDir = join3(projectDir, ".opencode", "context");
|
|
1399
|
+
if (existsSync2(contextDir)) {
|
|
1400
|
+
return false;
|
|
1401
|
+
}
|
|
1402
|
+
try {
|
|
1403
|
+
const promptsDir = join3(contextDir, "prompts");
|
|
1404
|
+
mkdirSync(promptsDir, { recursive: true });
|
|
1405
|
+
const templatesDir = join3(contextDir, "templates");
|
|
1406
|
+
mkdirSync(templatesDir, { recursive: true });
|
|
1407
|
+
writeFileSync(join3(contextDir, "config.jsonc"), DEFAULT_CONFIG, "utf-8");
|
|
1408
|
+
writeFileSync(join3(promptsDir, DEFAULTS.turnStartFile), DEFAULT_TURN_START, "utf-8");
|
|
1409
|
+
writeFileSync(join3(promptsDir, DEFAULTS.turnEndFile), DEFAULT_TURN_END, "utf-8");
|
|
1410
|
+
for (const [filename, content] of Object.entries(TEMPLATE_FILES)) {
|
|
1411
|
+
writeFileSync(join3(templatesDir, filename), content, "utf-8");
|
|
1412
|
+
}
|
|
1413
|
+
writeVersion(contextDir, PLUGIN_VERSION);
|
|
1414
|
+
return true;
|
|
1415
|
+
} catch {
|
|
1416
|
+
return false;
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
function updateScaffold(projectDir) {
|
|
1420
|
+
const contextDir = join3(projectDir, ".opencode", "context");
|
|
1421
|
+
mkdirSync(join3(contextDir, "prompts"), { recursive: true });
|
|
1422
|
+
mkdirSync(join3(contextDir, "templates"), { recursive: true });
|
|
1423
|
+
const templateEntries = Object.fromEntries(Object.entries(TEMPLATE_FILES).map(([filename, content]) => [`templates/${filename}`, content]));
|
|
1424
|
+
const templates = {
|
|
1425
|
+
"config.jsonc": DEFAULT_CONFIG,
|
|
1426
|
+
[`prompts/${DEFAULTS.turnStartFile}`]: DEFAULT_TURN_START,
|
|
1427
|
+
[`prompts/${DEFAULTS.turnEndFile}`]: DEFAULT_TURN_END,
|
|
1428
|
+
...templateEntries
|
|
1429
|
+
};
|
|
1430
|
+
const updated = [];
|
|
1431
|
+
for (const [path, content] of Object.entries(templates)) {
|
|
1432
|
+
const filePath = join3(contextDir, path);
|
|
1433
|
+
try {
|
|
1434
|
+
const existing = readFileSync4(filePath, "utf-8");
|
|
1435
|
+
if (existing === content)
|
|
1436
|
+
continue;
|
|
1437
|
+
} catch {}
|
|
1438
|
+
writeFileSync(filePath, content, "utf-8");
|
|
1439
|
+
updated.push(path);
|
|
1440
|
+
}
|
|
1441
|
+
writeVersion(contextDir, PLUGIN_VERSION);
|
|
1442
|
+
return updated;
|
|
1443
|
+
}
|
|
1444
|
+
function getStoredVersion(projectDir) {
|
|
1445
|
+
try {
|
|
1446
|
+
return readFileSync4(join3(projectDir, ".opencode", "context", ".version"), "utf-8").trim();
|
|
1447
|
+
} catch {
|
|
1448
|
+
return null;
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
function writeVersion(contextDir, version) {
|
|
1452
|
+
writeFileSync(join3(contextDir, ".version"), version, "utf-8");
|
|
1453
|
+
}
|
|
1454
|
+
function autoUpdateTemplates(projectDir) {
|
|
1455
|
+
const contextDir = join3(projectDir, ".opencode", "context");
|
|
1456
|
+
if (!existsSync2(contextDir))
|
|
1457
|
+
return [];
|
|
1458
|
+
const stored = getStoredVersion(projectDir);
|
|
1459
|
+
if (stored === PLUGIN_VERSION)
|
|
1460
|
+
return [];
|
|
1461
|
+
mkdirSync(join3(contextDir, "templates"), { recursive: true });
|
|
1462
|
+
const updated = [];
|
|
1463
|
+
for (const [filename, content] of Object.entries(TEMPLATE_FILES)) {
|
|
1464
|
+
const filePath = join3(contextDir, "templates", filename);
|
|
1465
|
+
try {
|
|
1466
|
+
const existing = readFileSync4(filePath, "utf-8");
|
|
1467
|
+
if (existing === content)
|
|
1468
|
+
continue;
|
|
1469
|
+
} catch {}
|
|
1470
|
+
writeFileSync(filePath, content, "utf-8");
|
|
1471
|
+
updated.push(`templates/${filename}`);
|
|
1472
|
+
}
|
|
1473
|
+
writeVersion(contextDir, PLUGIN_VERSION);
|
|
1474
|
+
return updated;
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
// src/context.ts
|
|
1478
|
+
var plugin = async ({ directory, client }) => {
|
|
1479
|
+
const scaffolded = scaffoldIfNeeded(directory);
|
|
1480
|
+
if (scaffolded) {
|
|
1481
|
+
await client.app.log({
|
|
1482
|
+
body: {
|
|
1483
|
+
service: "context",
|
|
1484
|
+
level: "info",
|
|
1485
|
+
message: "Scaffold created at .opencode/context/"
|
|
1486
|
+
}
|
|
1487
|
+
});
|
|
1488
|
+
} else {
|
|
1489
|
+
const autoUpdated = autoUpdateTemplates(directory);
|
|
1490
|
+
if (autoUpdated.length > 0) {
|
|
1491
|
+
await client.app.log({
|
|
1492
|
+
body: {
|
|
1493
|
+
service: "context",
|
|
1494
|
+
level: "info",
|
|
1495
|
+
message: `Auto-updated ${autoUpdated.length} template(s): ${autoUpdated.join(", ")}`
|
|
1496
|
+
}
|
|
1497
|
+
});
|
|
1498
|
+
}
|
|
1499
|
+
}
|
|
1500
|
+
const config = loadConfig(directory);
|
|
1501
|
+
return {
|
|
1502
|
+
config: async (cfg) => {
|
|
1503
|
+
cfg.command ??= {};
|
|
1504
|
+
cfg.command["context-update"] = {
|
|
1505
|
+
template: "",
|
|
1506
|
+
description: "Update context scaffold files to latest plugin version"
|
|
1507
|
+
};
|
|
1508
|
+
},
|
|
1509
|
+
"command.execute.before": async (input, output) => {
|
|
1510
|
+
if (input.command !== "context-update")
|
|
1511
|
+
return;
|
|
1512
|
+
const updated = updateScaffold(directory);
|
|
1513
|
+
const text = updated.length === 0 ? "All scaffold files are already up to date." : `Updated ${updated.length} file(s):
|
|
1514
|
+
${updated.map((f) => `- ${f}`).join(`
|
|
1515
|
+
`)}`;
|
|
1516
|
+
const now = Date.now();
|
|
1517
|
+
output.parts.splice(0, output.parts.length, {
|
|
1518
|
+
id: `context-update-${now}`,
|
|
1519
|
+
sessionID: input.sessionID,
|
|
1520
|
+
messageID: `context-update-msg-${now}`,
|
|
1521
|
+
type: "text",
|
|
1522
|
+
text
|
|
1523
|
+
});
|
|
1524
|
+
},
|
|
1525
|
+
"experimental.chat.messages.transform": async (_input, output) => {
|
|
1526
|
+
if (output.messages.length === 0)
|
|
1527
|
+
return;
|
|
1528
|
+
const lastUserMsg = output.messages.filter((m) => m.info.role === "user").at(-1);
|
|
1529
|
+
if (!lastUserMsg)
|
|
1530
|
+
return;
|
|
1531
|
+
const turnStartPath = join4(directory, config.prompts.turnStart ?? join4(DEFAULTS.promptDir, DEFAULTS.turnStartFile));
|
|
1532
|
+
const turnStart = readPromptFile(turnStartPath);
|
|
1533
|
+
const knowledgeIndex = buildKnowledgeIndexV2(directory, config.knowledge);
|
|
1534
|
+
const indexContent = knowledgeIndex.mode === "flat" ? formatKnowledgeIndex(knowledgeIndex.individualFiles) : formatDomainIndex(knowledgeIndex);
|
|
1535
|
+
const combinedContent = [turnStart, indexContent].filter(Boolean).join(`
|
|
1536
|
+
|
|
1537
|
+
`);
|
|
1538
|
+
if (combinedContent) {
|
|
1539
|
+
lastUserMsg.parts.push({
|
|
1540
|
+
id: `context-turn-start-${Date.now()}`,
|
|
1541
|
+
sessionID: lastUserMsg.info.sessionID,
|
|
1542
|
+
messageID: lastUserMsg.info.id,
|
|
1543
|
+
type: "text",
|
|
1544
|
+
text: combinedContent
|
|
1545
|
+
});
|
|
1546
|
+
}
|
|
1547
|
+
const turnEndPath = join4(directory, config.prompts.turnEnd ?? join4(DEFAULTS.promptDir, DEFAULTS.turnEndFile));
|
|
1548
|
+
const turnEnd = readPromptFile(turnEndPath);
|
|
1549
|
+
if (!turnEnd)
|
|
1550
|
+
return;
|
|
1551
|
+
const msgId = `context-turn-end-${Date.now()}`;
|
|
1552
|
+
output.messages.push({
|
|
1553
|
+
info: {
|
|
1554
|
+
id: msgId,
|
|
1555
|
+
sessionID: lastUserMsg.info.sessionID,
|
|
1556
|
+
role: "user",
|
|
1557
|
+
time: { created: Date.now() },
|
|
1558
|
+
agent: lastUserMsg.info.agent,
|
|
1559
|
+
model: lastUserMsg.info.model
|
|
1560
|
+
},
|
|
1561
|
+
parts: [
|
|
1562
|
+
{
|
|
1563
|
+
id: `context-turn-end-part-${Date.now()}`,
|
|
1564
|
+
sessionID: lastUserMsg.info.sessionID,
|
|
1565
|
+
messageID: msgId,
|
|
1566
|
+
type: "text",
|
|
1567
|
+
text: `<system-reminder>
|
|
1568
|
+
${turnEnd}
|
|
1569
|
+
</system-reminder>`
|
|
1570
|
+
}
|
|
1571
|
+
]
|
|
1572
|
+
});
|
|
1573
|
+
}
|
|
1574
|
+
};
|
|
1575
|
+
};
|
|
1576
|
+
var context_default = plugin;
|
|
1577
|
+
export {
|
|
1578
|
+
context_default as default
|
|
1579
|
+
};
|