picocode-core 0.9.125 → 0.9.126
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/package.json +3 -2
- package/src/tools/read.js +24 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "picocode-core",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.126",
|
|
4
4
|
"description": "The agent runtime behind pico: sessions, tools, subagents, MCP, memory, and model access",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"@prsm/ai": "^1.6.1",
|
|
29
29
|
"diff": "^7.0.0",
|
|
30
30
|
"fast-glob": "^3.3.0",
|
|
31
|
-
"proper-lockfile": "^4.1.2"
|
|
31
|
+
"proper-lockfile": "^4.1.2",
|
|
32
|
+
"unpdf": "^1.8.1"
|
|
32
33
|
}
|
|
33
34
|
}
|
package/src/tools/read.js
CHANGED
|
@@ -1,10 +1,27 @@
|
|
|
1
1
|
import { describeParam } from './recorder.js'
|
|
2
2
|
import { readFile } from 'node:fs/promises'
|
|
3
3
|
import { resolve } from 'node:path'
|
|
4
|
+
import { extractText } from 'unpdf'
|
|
4
5
|
|
|
5
6
|
const MAX_LINES = 2000
|
|
6
7
|
const MAX_LINE_LENGTH = 2000
|
|
7
8
|
|
|
9
|
+
const isPdf = (buffer) => buffer.subarray(0, 5).toString('latin1') === '%PDF-'
|
|
10
|
+
|
|
11
|
+
// a pdf reads as its extracted text, one page after another, so the same
|
|
12
|
+
// offset and limit window applies
|
|
13
|
+
async function pdfLines(buffer) {
|
|
14
|
+
const { text, totalPages } = await extractText(new Uint8Array(buffer), { mergePages: false })
|
|
15
|
+
const pages = Array.isArray(text) ? text : [text]
|
|
16
|
+
const lines = []
|
|
17
|
+
pages.forEach((page, i) => {
|
|
18
|
+
if (i) lines.push('')
|
|
19
|
+
lines.push(`[page ${i + 1} of ${totalPages}]`)
|
|
20
|
+
lines.push(...String(page).split('\n'))
|
|
21
|
+
})
|
|
22
|
+
return lines
|
|
23
|
+
}
|
|
24
|
+
|
|
8
25
|
function isBinary(buffer) {
|
|
9
26
|
const len = Math.min(buffer.length, 8000)
|
|
10
27
|
for (let i = 0; i < len; i++) {
|
|
@@ -27,20 +44,21 @@ export function createRead({ cwd, recorder, tracker }) {
|
|
|
27
44
|
const full = resolve(cwd, path)
|
|
28
45
|
recorder.extra({ title: path })
|
|
29
46
|
const buf = await readFile(full)
|
|
30
|
-
|
|
31
|
-
|
|
47
|
+
const lines = isPdf(buf) ? await pdfLines(buf) : null
|
|
48
|
+
if (!lines && isBinary(buf)) throw new Error(`${path} is a binary file`)
|
|
49
|
+
const source = lines ?? buf.toString('utf-8').split('\n')
|
|
32
50
|
|
|
33
51
|
const start = Math.max(0, offset - 1)
|
|
34
52
|
const count = Math.min(limit, MAX_LINES)
|
|
35
|
-
const sliced =
|
|
53
|
+
const sliced = source.slice(start, start + count)
|
|
36
54
|
const numbered = sliced
|
|
37
55
|
.map((line, i) => `${start + i + 1}\t${line.length > MAX_LINE_LENGTH ? line.slice(0, MAX_LINE_LENGTH) + '…' : line}`)
|
|
38
56
|
.join('\n')
|
|
39
57
|
|
|
40
58
|
recorder.extra({ fullOutput: sliced.join('\n') })
|
|
41
|
-
const result = { content: numbered, totalLines:
|
|
42
|
-
if (start + count <
|
|
43
|
-
result.note = `showing lines ${start + 1}-${start + sliced.length} of ${
|
|
59
|
+
const result = { content: numbered, totalLines: source.length }
|
|
60
|
+
if (start + count < source.length) {
|
|
61
|
+
result.note = `showing lines ${start + 1}-${start + sliced.length} of ${source.length}`
|
|
44
62
|
}
|
|
45
63
|
const context = tracker.check(full)
|
|
46
64
|
if (context.length) result.context_from_agents_md = context
|