clanka 0.26.1 → 0.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -3
- package/dist/Acp.test.js +0 -1
- package/dist/Acp.test.js.map +1 -1
- package/dist/AcpImage.test.js +0 -1
- package/dist/AcpImage.test.js.map +1 -1
- package/dist/Agent.d.ts.map +1 -1
- package/dist/Agent.js +1 -2
- package/dist/Agent.js.map +1 -1
- package/dist/Agent.test.js +0 -1
- package/dist/Agent.test.js.map +1 -1
- package/dist/AgentCallerConfig.test.js +0 -1
- package/dist/AgentCallerConfig.test.js.map +1 -1
- package/dist/AgentExecutor.d.ts +2 -3
- package/dist/AgentExecutor.d.ts.map +1 -1
- package/dist/AgentExecutor.js +4 -13
- package/dist/AgentExecutor.js.map +1 -1
- package/dist/AgentImage.test.js +0 -1
- package/dist/AgentImage.test.js.map +1 -1
- package/dist/AgentSkills.test.js +0 -2
- package/dist/AgentSkills.test.js.map +1 -1
- package/dist/AgentTools.d.ts +2 -235
- package/dist/AgentTools.d.ts.map +1 -1
- package/dist/AgentTools.js +2 -32
- package/dist/AgentTools.js.map +1 -1
- package/dist/ClaudeAgent.test.js +0 -1
- package/dist/ClaudeAgent.test.js.map +1 -1
- package/dist/McpServers.d.ts +20 -1
- package/dist/McpServers.d.ts.map +1 -1
- package/dist/McpServers.js +12 -5
- package/dist/McpServers.js.map +1 -1
- package/dist/McpServers.test.js +115 -0
- package/dist/McpServers.test.js.map +1 -1
- package/dist/ScriptFormatting.d.ts +5 -0
- package/dist/ScriptFormatting.d.ts.map +1 -1
- package/dist/ScriptFormatting.js +255 -53
- package/dist/ScriptFormatting.js.map +1 -1
- package/dist/ScriptFormatting.test.js +16 -0
- package/dist/ScriptFormatting.test.js.map +1 -1
- package/dist/bin/{Latch-DOdbsGMQ.mjs → Latch-BE6_TYRL.mjs} +1 -1
- package/dist/bin/{McpClient-B-FFG6Pg.mjs → McpClient-DCt4v5W5.mjs} +2 -2
- package/dist/bin/{OutputFormatter-DhhP2i-7.mjs → OutputFormatter-DaFv_C_I.mjs} +2 -3
- package/dist/bin/{Schema-CFdSO6iH.mjs → Schema-B3MiG1aD.mjs} +204 -568
- package/dist/bin/cli.mjs +5098 -2472
- package/dist/bin/{upgrade-C4aOEWJH.mjs → upgrade-WqgIU_21.mjs} +3 -3
- package/dist/cli.js +2 -25
- package/dist/cli.js.map +1 -1
- package/dist/fixtures/McpFakeServer.d.ts +4 -0
- package/dist/fixtures/McpFakeServer.d.ts.map +1 -1
- package/dist/fixtures/McpFakeServer.js +13 -0
- package/dist/fixtures/McpFakeServer.js.map +1 -1
- package/dist/index.d.ts +0 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -7
- package/src/Acp.test.ts +0 -1
- package/src/AcpImage.test.ts +0 -1
- package/src/Agent.test.ts +0 -1
- package/src/Agent.ts +0 -4
- package/src/AgentCallerConfig.test.ts +0 -1
- package/src/AgentExecutor.ts +4 -16
- package/src/AgentImage.test.ts +0 -1
- package/src/AgentSkills.test.ts +0 -2
- package/src/AgentTools.ts +4 -41
- package/src/ClaudeAgent.test.ts +0 -1
- package/src/McpServers.test.ts +198 -0
- package/src/McpServers.ts +44 -4
- package/src/ScriptFormatting.test.ts +20 -0
- package/src/ScriptFormatting.ts +234 -47
- package/src/cli.ts +1 -56
- package/src/fixtures/McpFakeServer.ts +17 -1
- package/src/index.ts +0 -10
- package/dist/ChunkRepo.d.ts +0 -173
- package/dist/ChunkRepo.d.ts.map +0 -1
- package/dist/ChunkRepo.js +0 -168
- package/dist/ChunkRepo.js.map +0 -1
- package/dist/ChunkRepo.test.d.ts +0 -2
- package/dist/ChunkRepo.test.d.ts.map +0 -1
- package/dist/ChunkRepo.test.js +0 -63
- package/dist/ChunkRepo.test.js.map +0 -1
- package/dist/CodeChunker.d.ts +0 -84
- package/dist/CodeChunker.d.ts.map +0 -1
- package/dist/CodeChunker.js +0 -658
- package/dist/CodeChunker.js.map +0 -1
- package/dist/CodeChunker.test.d.ts +0 -2
- package/dist/CodeChunker.test.d.ts.map +0 -1
- package/dist/CodeChunker.test.js +0 -434
- package/dist/CodeChunker.test.js.map +0 -1
- package/dist/SemanticSearch/Service.d.ts +0 -31
- package/dist/SemanticSearch/Service.d.ts.map +0 -1
- package/dist/SemanticSearch/Service.js +0 -29
- package/dist/SemanticSearch/Service.js.map +0 -1
- package/dist/SemanticSearch.d.ts +0 -34
- package/dist/SemanticSearch.d.ts.map +0 -1
- package/dist/SemanticSearch.js +0 -171
- package/dist/SemanticSearch.js.map +0 -1
- package/dist/SemanticSearch.test.d.ts +0 -2
- package/dist/SemanticSearch.test.d.ts.map +0 -1
- package/dist/SemanticSearch.test.js +0 -34
- package/dist/SemanticSearch.test.js.map +0 -1
- package/dist/Sqlite.d.ts +0 -15
- package/dist/Sqlite.d.ts.map +0 -1
- package/dist/Sqlite.js +0 -44
- package/dist/Sqlite.js.map +0 -1
- package/dist/bin/AiError-DBaKz35C.mjs +0 -2723
- package/dist/bin/SemanticSearch-C3a7LAQr.mjs +0 -2558
- package/src/ChunkRepo.test.ts +0 -89
- package/src/ChunkRepo.ts +0 -260
- package/src/CodeChunker.test.ts +0 -493
- package/src/CodeChunker.ts +0 -1018
- package/src/SemanticSearch/Service.ts +0 -50
- package/src/SemanticSearch.test.ts +0 -51
- package/src/SemanticSearch.ts +0 -282
- package/src/Sqlite.ts +0 -60
package/src/CodeChunker.test.ts
DELETED
|
@@ -1,493 +0,0 @@
|
|
|
1
|
-
import { assert, describe, expect, it } from "@effect/vitest"
|
|
2
|
-
import {
|
|
3
|
-
chunkFileContent,
|
|
4
|
-
isMeaningfulFile,
|
|
5
|
-
isProbablyMinified,
|
|
6
|
-
} from "./CodeChunker.ts"
|
|
7
|
-
import { readFileSync } from "node:fs"
|
|
8
|
-
import { join } from "node:path"
|
|
9
|
-
|
|
10
|
-
describe("isMeaningfulFile", () => {
|
|
11
|
-
it("keeps source and documentation files", () => {
|
|
12
|
-
expect(isMeaningfulFile("src/index.ts")).toBe(true)
|
|
13
|
-
expect(isMeaningfulFile("README.md")).toBe(true)
|
|
14
|
-
expect(isMeaningfulFile("docs/guide.mdx")).toBe(true)
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
it("filters lock files and minified artifacts", () => {
|
|
18
|
-
expect(isMeaningfulFile("pnpm-lock.yaml")).toBe(false)
|
|
19
|
-
expect(isMeaningfulFile("vendor/jquery.min.js")).toBe(false)
|
|
20
|
-
expect(isMeaningfulFile("public/app.js.map")).toBe(false)
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
it("filters generated and dependency directories", () => {
|
|
24
|
-
expect(isMeaningfulFile("node_modules/pkg/index.js")).toBe(false)
|
|
25
|
-
expect(isMeaningfulFile("dist/index.js")).toBe(false)
|
|
26
|
-
expect(isMeaningfulFile("coverage/index.html")).toBe(false)
|
|
27
|
-
})
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
describe("isProbablyMinified", () => {
|
|
31
|
-
it("detects very large single-line payloads", () => {
|
|
32
|
-
expect(isProbablyMinified("x".repeat(2500))).toBe(true)
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
it("does not flag normal source content", () => {
|
|
36
|
-
const source = [
|
|
37
|
-
"export const a = 1",
|
|
38
|
-
"export const b = 2",
|
|
39
|
-
"export const c = 3",
|
|
40
|
-
].join("\n")
|
|
41
|
-
expect(isProbablyMinified(source)).toBe(false)
|
|
42
|
-
})
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
describe("chunkFileContent", () => {
|
|
46
|
-
it("splits TypeScript into AST chunks with metadata", () => {
|
|
47
|
-
const content = [
|
|
48
|
-
"// alpha docs",
|
|
49
|
-
"export const alpha = 1",
|
|
50
|
-
"// beta docs",
|
|
51
|
-
"function beta() {",
|
|
52
|
-
" return alpha",
|
|
53
|
-
"}",
|
|
54
|
-
"class Example {",
|
|
55
|
-
" // gamma docs",
|
|
56
|
-
" gamma() {",
|
|
57
|
-
" return beta()",
|
|
58
|
-
" }",
|
|
59
|
-
"}",
|
|
60
|
-
].join("\n")
|
|
61
|
-
|
|
62
|
-
const chunks = chunkFileContent("src\\example.ts", content, {
|
|
63
|
-
chunkSize: 10,
|
|
64
|
-
chunkOverlap: 2,
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
expect(chunks).toHaveLength(4)
|
|
68
|
-
expect(chunks[0]).toMatchObject({
|
|
69
|
-
path: "src/example.ts",
|
|
70
|
-
startLine: 1,
|
|
71
|
-
endLine: 2,
|
|
72
|
-
name: "alpha",
|
|
73
|
-
type: "variable",
|
|
74
|
-
parent: undefined,
|
|
75
|
-
content: ["// alpha docs", "export const alpha = 1"].join("\n"),
|
|
76
|
-
})
|
|
77
|
-
expect(chunks[1]).toMatchObject({
|
|
78
|
-
startLine: 3,
|
|
79
|
-
endLine: 6,
|
|
80
|
-
name: "beta",
|
|
81
|
-
type: "function",
|
|
82
|
-
parent: undefined,
|
|
83
|
-
content: [
|
|
84
|
-
"// beta docs",
|
|
85
|
-
"function beta() {",
|
|
86
|
-
" return alpha",
|
|
87
|
-
"}",
|
|
88
|
-
].join("\n"),
|
|
89
|
-
})
|
|
90
|
-
expect(chunks[2]).toMatchObject({
|
|
91
|
-
startLine: 7,
|
|
92
|
-
endLine: 12,
|
|
93
|
-
name: "Example",
|
|
94
|
-
type: "class",
|
|
95
|
-
parent: undefined,
|
|
96
|
-
content: [
|
|
97
|
-
"class Example {",
|
|
98
|
-
" // gamma docs",
|
|
99
|
-
" gamma() {",
|
|
100
|
-
" return beta()",
|
|
101
|
-
" }",
|
|
102
|
-
"}",
|
|
103
|
-
].join("\n"),
|
|
104
|
-
})
|
|
105
|
-
expect(chunks[3]).toMatchObject({
|
|
106
|
-
startLine: 8,
|
|
107
|
-
endLine: 11,
|
|
108
|
-
name: "gamma",
|
|
109
|
-
type: "method",
|
|
110
|
-
parent: "class Example",
|
|
111
|
-
content: [
|
|
112
|
-
" // gamma docs",
|
|
113
|
-
" gamma() {",
|
|
114
|
-
" return beta()",
|
|
115
|
-
" }",
|
|
116
|
-
].join("\n"),
|
|
117
|
-
})
|
|
118
|
-
|
|
119
|
-
expect(
|
|
120
|
-
chunkFileContent("src/example.ts", content, {
|
|
121
|
-
chunkSize: 10,
|
|
122
|
-
chunkOverlap: 2,
|
|
123
|
-
})[0],
|
|
124
|
-
).toEqual(chunks[0])
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
it("splits large AST ranges using chunk settings", () => {
|
|
128
|
-
const content = [
|
|
129
|
-
"export function large() {",
|
|
130
|
-
...Array.from(
|
|
131
|
-
{ length: 60 },
|
|
132
|
-
(_, index) =>
|
|
133
|
-
" const line" + String(index + 1) + " = " + String(index + 1),
|
|
134
|
-
),
|
|
135
|
-
"}",
|
|
136
|
-
].join("\n")
|
|
137
|
-
|
|
138
|
-
const chunks = chunkFileContent("src/large.ts", content, {
|
|
139
|
-
chunkSize: 20,
|
|
140
|
-
chunkOverlap: 5,
|
|
141
|
-
})
|
|
142
|
-
|
|
143
|
-
expect(chunks).toHaveLength(4)
|
|
144
|
-
expect(chunks[0]).toMatchObject({
|
|
145
|
-
startLine: 1,
|
|
146
|
-
endLine: 20,
|
|
147
|
-
name: "large",
|
|
148
|
-
type: "function",
|
|
149
|
-
parent: undefined,
|
|
150
|
-
})
|
|
151
|
-
expect(chunks[1]).toMatchObject({
|
|
152
|
-
startLine: 16,
|
|
153
|
-
endLine: 35,
|
|
154
|
-
})
|
|
155
|
-
expect(chunks[2]).toMatchObject({
|
|
156
|
-
startLine: 31,
|
|
157
|
-
endLine: 50,
|
|
158
|
-
})
|
|
159
|
-
expect(chunks[3]).toMatchObject({
|
|
160
|
-
startLine: 46,
|
|
161
|
-
endLine: 62,
|
|
162
|
-
})
|
|
163
|
-
})
|
|
164
|
-
|
|
165
|
-
it("limits AST chunks by character count and drops punctuation-only segments", () => {
|
|
166
|
-
const content = [
|
|
167
|
-
"export function demo() {",
|
|
168
|
-
" const alpha = 1",
|
|
169
|
-
" const beta = 2",
|
|
170
|
-
" return alpha + beta",
|
|
171
|
-
"}",
|
|
172
|
-
].join("\n")
|
|
173
|
-
|
|
174
|
-
const chunks = chunkFileContent("src/demo.ts", content, {
|
|
175
|
-
chunkSize: 20,
|
|
176
|
-
chunkOverlap: 1,
|
|
177
|
-
chunkMaxCharacters: 21,
|
|
178
|
-
})
|
|
179
|
-
|
|
180
|
-
expect(chunks.every((chunk) => chunk.content.length <= 21)).toBe(true)
|
|
181
|
-
expect(chunks).toHaveLength(5)
|
|
182
|
-
expect(chunks).toMatchObject([
|
|
183
|
-
{
|
|
184
|
-
startLine: 1,
|
|
185
|
-
endLine: 1,
|
|
186
|
-
name: "demo",
|
|
187
|
-
type: "function",
|
|
188
|
-
content: "export function demo(",
|
|
189
|
-
},
|
|
190
|
-
{
|
|
191
|
-
startLine: 1,
|
|
192
|
-
endLine: 1,
|
|
193
|
-
name: "demo",
|
|
194
|
-
type: "function",
|
|
195
|
-
content: ") {",
|
|
196
|
-
},
|
|
197
|
-
{
|
|
198
|
-
startLine: 2,
|
|
199
|
-
endLine: 2,
|
|
200
|
-
name: "demo",
|
|
201
|
-
type: "function",
|
|
202
|
-
content: " const alpha = 1",
|
|
203
|
-
},
|
|
204
|
-
{
|
|
205
|
-
startLine: 3,
|
|
206
|
-
endLine: 3,
|
|
207
|
-
name: "demo",
|
|
208
|
-
type: "function",
|
|
209
|
-
content: " const beta = 2",
|
|
210
|
-
},
|
|
211
|
-
{
|
|
212
|
-
startLine: 4,
|
|
213
|
-
endLine: 4,
|
|
214
|
-
name: "demo",
|
|
215
|
-
type: "function",
|
|
216
|
-
content: " return alpha + beta",
|
|
217
|
-
},
|
|
218
|
-
])
|
|
219
|
-
})
|
|
220
|
-
|
|
221
|
-
it("limits line-window chunks by character count while preserving overlap", () => {
|
|
222
|
-
const content = ["aaaaa", "bbbbb", "ccccc", "ddddd"].join("\n")
|
|
223
|
-
|
|
224
|
-
const chunks = chunkFileContent("docs/notes.txt", content, {
|
|
225
|
-
chunkSize: 4,
|
|
226
|
-
chunkOverlap: 1,
|
|
227
|
-
chunkMaxCharacters: 11,
|
|
228
|
-
})
|
|
229
|
-
|
|
230
|
-
expect(chunks).toHaveLength(3)
|
|
231
|
-
expect(chunks).toMatchObject([
|
|
232
|
-
{
|
|
233
|
-
startLine: 1,
|
|
234
|
-
endLine: 2,
|
|
235
|
-
content: ["aaaaa", "bbbbb"].join("\n"),
|
|
236
|
-
},
|
|
237
|
-
{
|
|
238
|
-
startLine: 2,
|
|
239
|
-
endLine: 3,
|
|
240
|
-
content: ["bbbbb", "ccccc"].join("\n"),
|
|
241
|
-
},
|
|
242
|
-
{
|
|
243
|
-
startLine: 3,
|
|
244
|
-
endLine: 4,
|
|
245
|
-
content: ["ccccc", "ddddd"].join("\n"),
|
|
246
|
-
},
|
|
247
|
-
])
|
|
248
|
-
})
|
|
249
|
-
|
|
250
|
-
it.each(["src/long.ts", "docs/long.txt"])(
|
|
251
|
-
"splits oversized lines in %s without losing content or line metadata",
|
|
252
|
-
(path) => {
|
|
253
|
-
const longLine = ` const value = "${"x".repeat(25_000)}"`
|
|
254
|
-
const content = [
|
|
255
|
-
"function demo() {",
|
|
256
|
-
longLine,
|
|
257
|
-
" return value",
|
|
258
|
-
"}",
|
|
259
|
-
].join("\n")
|
|
260
|
-
const chunks = chunkFileContent(path, content, {
|
|
261
|
-
chunkSize: 30,
|
|
262
|
-
chunkOverlap: 1,
|
|
263
|
-
chunkMaxCharacters: 10_000,
|
|
264
|
-
})
|
|
265
|
-
|
|
266
|
-
expect(chunks.length).toBeGreaterThan(0)
|
|
267
|
-
expect(chunks.every((chunk) => chunk.content.length <= 10_000)).toBe(true)
|
|
268
|
-
const pieces = chunks.filter((chunk) => chunk.startLine === 2)
|
|
269
|
-
expect(pieces).toHaveLength(3)
|
|
270
|
-
expect(pieces.map((chunk) => chunk.content).join("")).toBe(longLine)
|
|
271
|
-
for (const piece of pieces) {
|
|
272
|
-
expect(piece).toMatchObject({ path, startLine: 2, endLine: 2 })
|
|
273
|
-
if (path.endsWith(".ts")) {
|
|
274
|
-
expect(piece).toMatchObject({ name: "demo", type: "function" })
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
expect(
|
|
278
|
-
chunks.some((chunk) => chunk.content.includes("return value")),
|
|
279
|
-
).toBe(true)
|
|
280
|
-
},
|
|
281
|
-
)
|
|
282
|
-
|
|
283
|
-
it("preserves a line exactly at the character limit", () => {
|
|
284
|
-
const line = "x".repeat(10_000)
|
|
285
|
-
const chunks = chunkFileContent(
|
|
286
|
-
"docs/limit.txt",
|
|
287
|
-
`before\n${line}\nafter`,
|
|
288
|
-
{
|
|
289
|
-
chunkSize: 30,
|
|
290
|
-
chunkOverlap: 0,
|
|
291
|
-
chunkMaxCharacters: 10_000,
|
|
292
|
-
},
|
|
293
|
-
)
|
|
294
|
-
|
|
295
|
-
expect(chunks.map((chunk) => chunk.content)).toEqual([
|
|
296
|
-
"before",
|
|
297
|
-
line,
|
|
298
|
-
"after",
|
|
299
|
-
])
|
|
300
|
-
})
|
|
301
|
-
|
|
302
|
-
it("keeps only the first oversized class segment when methods are present", () => {
|
|
303
|
-
const content = [
|
|
304
|
-
"class Example {",
|
|
305
|
-
" first() {",
|
|
306
|
-
" const a = 1",
|
|
307
|
-
" const b = 2",
|
|
308
|
-
" return a + b",
|
|
309
|
-
" }",
|
|
310
|
-
"",
|
|
311
|
-
" second() {",
|
|
312
|
-
" const c = 3",
|
|
313
|
-
" const d = 4",
|
|
314
|
-
" return c + d",
|
|
315
|
-
" }",
|
|
316
|
-
"}",
|
|
317
|
-
].join("\n")
|
|
318
|
-
|
|
319
|
-
const chunks = chunkFileContent("src/example.ts", content, {
|
|
320
|
-
chunkSize: 6,
|
|
321
|
-
chunkOverlap: 1,
|
|
322
|
-
})
|
|
323
|
-
|
|
324
|
-
const classChunks = chunks.filter((chunk) => chunk.type === "class")
|
|
325
|
-
expect(classChunks).toHaveLength(1)
|
|
326
|
-
expect(classChunks[0]).toMatchObject({
|
|
327
|
-
startLine: 1,
|
|
328
|
-
endLine: 6,
|
|
329
|
-
name: "Example",
|
|
330
|
-
type: "class",
|
|
331
|
-
parent: undefined,
|
|
332
|
-
})
|
|
333
|
-
|
|
334
|
-
expect(chunks.filter((chunk) => chunk.type === "method")).toMatchObject([
|
|
335
|
-
{
|
|
336
|
-
startLine: 2,
|
|
337
|
-
endLine: 6,
|
|
338
|
-
name: "first",
|
|
339
|
-
parent: "class Example",
|
|
340
|
-
},
|
|
341
|
-
{
|
|
342
|
-
startLine: 8,
|
|
343
|
-
endLine: 12,
|
|
344
|
-
name: "second",
|
|
345
|
-
parent: "class Example",
|
|
346
|
-
},
|
|
347
|
-
])
|
|
348
|
-
})
|
|
349
|
-
|
|
350
|
-
it("includes preceding comments in AST chunks", () => {
|
|
351
|
-
const content = [
|
|
352
|
-
"// alpha docs",
|
|
353
|
-
"export const alpha = 1",
|
|
354
|
-
"/**",
|
|
355
|
-
" * beta docs",
|
|
356
|
-
" */",
|
|
357
|
-
"function beta() {",
|
|
358
|
-
" return alpha",
|
|
359
|
-
"}",
|
|
360
|
-
"class Example {",
|
|
361
|
-
" // gamma docs",
|
|
362
|
-
" gamma() {",
|
|
363
|
-
" return beta()",
|
|
364
|
-
" }",
|
|
365
|
-
"}",
|
|
366
|
-
].join("\n")
|
|
367
|
-
|
|
368
|
-
const chunks = chunkFileContent("src/example.ts", content, {
|
|
369
|
-
chunkSize: 20,
|
|
370
|
-
chunkOverlap: 2,
|
|
371
|
-
})
|
|
372
|
-
|
|
373
|
-
expect(chunks).toHaveLength(4)
|
|
374
|
-
expect(chunks[0]).toMatchObject({
|
|
375
|
-
startLine: 1,
|
|
376
|
-
endLine: 2,
|
|
377
|
-
name: "alpha",
|
|
378
|
-
type: "variable",
|
|
379
|
-
content: ["// alpha docs", "export const alpha = 1"].join("\n"),
|
|
380
|
-
})
|
|
381
|
-
expect(chunks[1]).toMatchObject({
|
|
382
|
-
startLine: 3,
|
|
383
|
-
endLine: 8,
|
|
384
|
-
name: "beta",
|
|
385
|
-
type: "function",
|
|
386
|
-
content: [
|
|
387
|
-
"/**",
|
|
388
|
-
" * beta docs",
|
|
389
|
-
" */",
|
|
390
|
-
"function beta() {",
|
|
391
|
-
" return alpha",
|
|
392
|
-
"}",
|
|
393
|
-
].join("\n"),
|
|
394
|
-
})
|
|
395
|
-
expect(chunks[3]).toMatchObject({
|
|
396
|
-
startLine: 10,
|
|
397
|
-
endLine: 13,
|
|
398
|
-
name: "gamma",
|
|
399
|
-
type: "method",
|
|
400
|
-
parent: "class Example",
|
|
401
|
-
content: [
|
|
402
|
-
" // gamma docs",
|
|
403
|
-
" gamma() {",
|
|
404
|
-
" return beta()",
|
|
405
|
-
" }",
|
|
406
|
-
].join("\n"),
|
|
407
|
-
})
|
|
408
|
-
})
|
|
409
|
-
|
|
410
|
-
it("falls back to line windows for unsupported languages", () => {
|
|
411
|
-
const content = [
|
|
412
|
-
"line 1",
|
|
413
|
-
"line 2",
|
|
414
|
-
"line 3",
|
|
415
|
-
"line 4",
|
|
416
|
-
"line 5",
|
|
417
|
-
"line 6",
|
|
418
|
-
].join("\n")
|
|
419
|
-
|
|
420
|
-
const chunks = chunkFileContent("docs\\notes.txt", content, {
|
|
421
|
-
chunkSize: 3,
|
|
422
|
-
chunkOverlap: 1,
|
|
423
|
-
})
|
|
424
|
-
|
|
425
|
-
expect(chunks).toHaveLength(3)
|
|
426
|
-
expect(chunks[0]).toMatchObject({
|
|
427
|
-
path: "docs/notes.txt",
|
|
428
|
-
startLine: 1,
|
|
429
|
-
endLine: 3,
|
|
430
|
-
name: undefined,
|
|
431
|
-
type: undefined,
|
|
432
|
-
parent: undefined,
|
|
433
|
-
content: ["line 1", "line 2", "line 3"].join("\n"),
|
|
434
|
-
})
|
|
435
|
-
expect(chunks[1]).toMatchObject({
|
|
436
|
-
startLine: 3,
|
|
437
|
-
endLine: 5,
|
|
438
|
-
name: undefined,
|
|
439
|
-
type: undefined,
|
|
440
|
-
parent: undefined,
|
|
441
|
-
content: ["line 3", "line 4", "line 5"].join("\n"),
|
|
442
|
-
})
|
|
443
|
-
expect(chunks[2]).toMatchObject({
|
|
444
|
-
startLine: 5,
|
|
445
|
-
endLine: 6,
|
|
446
|
-
name: undefined,
|
|
447
|
-
type: undefined,
|
|
448
|
-
parent: undefined,
|
|
449
|
-
content: ["line 5", "line 6"].join("\n"),
|
|
450
|
-
})
|
|
451
|
-
})
|
|
452
|
-
|
|
453
|
-
it("drops minified-like content", () => {
|
|
454
|
-
const chunks = chunkFileContent("src/bundle.js", "x".repeat(3000), {
|
|
455
|
-
chunkSize: 30,
|
|
456
|
-
chunkOverlap: 0,
|
|
457
|
-
})
|
|
458
|
-
expect(chunks).toEqual([])
|
|
459
|
-
})
|
|
460
|
-
|
|
461
|
-
it("seperates class methods into their own chunks", () => {
|
|
462
|
-
const fixture = readFileSync(
|
|
463
|
-
join(__dirname, "fixtures", "fiber.txt"),
|
|
464
|
-
"utf-8",
|
|
465
|
-
)
|
|
466
|
-
const chunks = chunkFileContent("src/fiber.ts", fixture, {
|
|
467
|
-
chunkSize: 30,
|
|
468
|
-
chunkOverlap: 0,
|
|
469
|
-
})
|
|
470
|
-
const runLoopChunk = chunks.find((chunk) => chunk.name === "runLoop")
|
|
471
|
-
assert(runLoopChunk, "Expected to find a chunk for the runLoop method")
|
|
472
|
-
assert.strictEqual(runLoopChunk.type, "method")
|
|
473
|
-
})
|
|
474
|
-
|
|
475
|
-
it("chunks ts namespaces", () => {
|
|
476
|
-
const fixture = readFileSync(
|
|
477
|
-
join(__dirname, "fixtures", "yieldable.txt"),
|
|
478
|
-
"utf-8",
|
|
479
|
-
)
|
|
480
|
-
const chunks = chunkFileContent("src/Effect.ts", fixture, {
|
|
481
|
-
chunkSize: 30,
|
|
482
|
-
chunkOverlap: 0,
|
|
483
|
-
})
|
|
484
|
-
const names = chunks.map((chunk) => chunk.name)
|
|
485
|
-
assert.deepStrictEqual(names, ["Yieldable", "Any", "Success"])
|
|
486
|
-
const parents = chunks.map((chunk) => chunk.parent)
|
|
487
|
-
assert.deepStrictEqual(parents, [
|
|
488
|
-
undefined,
|
|
489
|
-
"namespace Yieldable",
|
|
490
|
-
"namespace Yieldable",
|
|
491
|
-
])
|
|
492
|
-
})
|
|
493
|
-
})
|