@yanzc/claude-pro 0.7.8 → 0.9.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 +37 -58
- package/package.json +1 -1
- package/src/agent.js +127 -25
- package/src/cache.js +18 -0
- package/src/commands.js +24 -28
- package/src/config.js +8 -2
- package/src/filestate.js +1 -1
- package/src/keepalive.js +129 -0
- package/src/main.js +12 -39
- package/src/mcp.js +58 -13
- package/src/peers.js +6 -75
- package/src/prompts.js +3 -3
- package/src/remote.js +77 -33
- package/src/runtime.js +3 -0
- package/src/session.js +48 -15
- package/src/supervisor.js +4 -6
- package/src/tools/bash.js +30 -14
- package/src/tools/files.js +366 -62
- package/src/tools/index.js +3 -1
- package/src/tools/search.js +14 -10
- package/src/tools/web.js +14 -6
- package/src/ui/ansi.js +24 -9
- package/src/ui/repl.js +314 -305
- package/src/ui/screen.js +38 -11
- package/src/updater.js +7 -3
- package/src/utils/clipboard.js +16 -75
- package/src/utils/diff.js +21 -3
- package/src/utils/dirs.js +136 -0
- package/src/utils/encoding.js +187 -0
- package/src/utils/paths.js +46 -5
- package/src/utils/shell.js +90 -19
- package/src/attach.js +0 -146
- package/src/background.js +0 -514
- package/src/connect.js +0 -79
- package/src/history.js +0 -163
- package/src/host.js +0 -1474
- package/src/ui/vterm.js +0 -62
package/src/tools/search.js
CHANGED
|
@@ -7,6 +7,7 @@ import path from 'node:path';
|
|
|
7
7
|
import { spawn } from 'node:child_process';
|
|
8
8
|
import { resolvePath, displayPath } from '../utils/paths.js';
|
|
9
9
|
import { ripgrepPath } from '../utils/shell.js';
|
|
10
|
+
import { decodeText as decodeFile } from '../utils/encoding.js';
|
|
10
11
|
|
|
11
12
|
const IGNORED_DIRS = new Set(['node_modules', '.git', '.svn', '.hg', '__pycache__', '.venv', 'dist-newstyle']);
|
|
12
13
|
|
|
@@ -240,14 +241,9 @@ async function collectFiles(base, globs, exts, signal) {
|
|
|
240
241
|
return files;
|
|
241
242
|
}
|
|
242
243
|
|
|
243
|
-
// Text of a file, or null for binary files
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
if (buf[0] === 0xFE && buf[1] === 0xFF) return new TextDecoder('utf-16be').decode(buf.subarray(2));
|
|
247
|
-
if (buf.subarray(0, 8000).includes(0)) return null;
|
|
248
|
-
const text = buf.toString('utf8');
|
|
249
|
-
return text.charCodeAt(0) === 0xFEFF ? text.slice(1) : text;
|
|
250
|
-
}
|
|
244
|
+
// Text of a file, or null for binary files: UTF-16 with a BOM as ripgrep does it, and GBK files as Read shows them
|
|
245
|
+
// (so that a Chinese word is found in them too).
|
|
246
|
+
const decodeText = (buf) => decodeFile(buf, { writable: false })?.text ?? null;
|
|
251
247
|
|
|
252
248
|
const clip = (line) => (line.length > MAX_COLUMNS ? `${line.slice(0, MAX_COLUMNS)} [... omitted end of long line]` : line);
|
|
253
249
|
|
|
@@ -255,8 +251,16 @@ function runRg(bin, args, cwd, signal) {
|
|
|
255
251
|
return new Promise((resolve) => {
|
|
256
252
|
const child = spawn(bin, args, { cwd, windowsHide: true, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
257
253
|
let out = '', err = '';
|
|
258
|
-
|
|
259
|
-
|
|
254
|
+
// Decoded as a stream (a Chinese path or line can be split between two chunks), and rg is stopped once
|
|
255
|
+
// there is more than will ever be shown instead of scanning on.
|
|
256
|
+
child.stdout.setEncoding('utf8');
|
|
257
|
+
child.stderr.setEncoding('utf8');
|
|
258
|
+
child.stdout.on('data', (d) => {
|
|
259
|
+
if (out.length >= 20_000_000) return;
|
|
260
|
+
out += d;
|
|
261
|
+
if (out.length >= 20_000_000) { out = out.slice(0, out.lastIndexOf('\n') + 1); child.kill(); }
|
|
262
|
+
});
|
|
263
|
+
child.stderr.on('data', (d) => { if (err.length < 100_000) err += d; });
|
|
260
264
|
const onAbort = () => child.kill();
|
|
261
265
|
signal?.addEventListener('abort', onAbort, { once: true });
|
|
262
266
|
child.on('close', (code) => { signal?.removeEventListener('abort', onAbort); resolve({ code, out, err }); });
|
package/src/tools/web.js
CHANGED
|
@@ -210,17 +210,25 @@ async function searchDuckDuckGo(query, signal) {
|
|
|
210
210
|
body: new URLSearchParams({ q: query }).toString(),
|
|
211
211
|
signal: withTimeout(signal),
|
|
212
212
|
});
|
|
213
|
-
|
|
213
|
+
return parseDuckDuckGo(await res.text());
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// The results of DuckDuckGo's HTML page, one block per result link. (One regex with an optional snippet group after
|
|
217
|
+
// a lazy gap never took the snippet: the gap matched nothing, and every snippet came back empty.)
|
|
218
|
+
export function parseDuckDuckGo(html) {
|
|
214
219
|
const results = [];
|
|
215
|
-
const
|
|
216
|
-
let
|
|
217
|
-
|
|
218
|
-
|
|
220
|
+
const starts = [...html.matchAll(/<a[^>]+class="result__a"/g)].map((m) => m.index);
|
|
221
|
+
for (let i = 0; i < starts.length && results.length < 10; i++) {
|
|
222
|
+
const block = html.slice(starts[i], starts[i + 1] ?? html.length);
|
|
223
|
+
const a = /^<a[^>]+href="([^"]+)"[^>]*>([\s\S]*?)<\/a>/.exec(block);
|
|
224
|
+
if (!a) continue;
|
|
225
|
+
let href = decodeEntities(a[1]);
|
|
219
226
|
const uddg = /[?&]uddg=([^&]+)/.exec(href);
|
|
220
227
|
if (uddg) href = decodeURIComponent(uddg[1]);
|
|
221
228
|
if (href.startsWith('//')) href = 'https:' + href;
|
|
222
229
|
if (/duckduckgo\.com\/y\.js/.test(href)) continue; // ads
|
|
223
|
-
|
|
230
|
+
const s = /class="result__snippet"[^>]*>([\s\S]*?)<\/(?:a|div|td)>/.exec(block);
|
|
231
|
+
results.push({ title: decodeEntities(a[2].replace(/<[^>]+>/g, '')).trim(), url: href, snippet: s ? decodeEntities(s[1].replace(/<[^>]+>/g, '')).trim() : '' });
|
|
224
232
|
}
|
|
225
233
|
return results;
|
|
226
234
|
}
|
package/src/ui/ansi.js
CHANGED
|
@@ -192,17 +192,32 @@ export function wordWrap(line, width) {
|
|
|
192
192
|
return lines;
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
+
// Cut a (possibly ANSI colored) string to `width` columns, ending in `ellipsis` when it was longer. It reads only as
|
|
196
|
+
// far as the width reaches: the live region calls it every frame on queued messages, tool input and commands of any
|
|
197
|
+
// length, and measuring all of a 200 KB paste first took some 50 ms a frame.
|
|
195
198
|
export function truncate(s, width, ellipsis = '…') {
|
|
196
|
-
|
|
197
|
-
let
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
199
|
+
const room = width - stringWidth(ellipsis);
|
|
200
|
+
let out = '', w = 0;
|
|
201
|
+
let cut = null; // what fits before the ellipsis, once the string has gone past `room`
|
|
202
|
+
const take = (text) => { // true: the string is wider than `width`
|
|
203
|
+
for (const { segment: g } of segmenter.segment(text)) {
|
|
204
|
+
const gw = graphemeWidth(g);
|
|
205
|
+
if (cut === null && w + gw > room) cut = out;
|
|
206
|
+
if (w + gw > width) return true;
|
|
207
|
+
out += g;
|
|
208
|
+
w += gw;
|
|
209
|
+
}
|
|
210
|
+
return false;
|
|
211
|
+
};
|
|
212
|
+
const re = new RegExp(ANSI_RE.source, 'g');
|
|
213
|
+
let last = 0, m;
|
|
214
|
+
while ((m = re.exec(s))) {
|
|
215
|
+
if (m.index > last && take(s.slice(last, m.index))) return cut + ellipsis + (colorEnabled ? '\x1b[0m' : '');
|
|
216
|
+
out += m[0];
|
|
217
|
+
last = m.index + m[0].length;
|
|
204
218
|
}
|
|
205
|
-
return
|
|
219
|
+
if (last < s.length && take(s.slice(last))) return cut + ellipsis + (colorEnabled ? '\x1b[0m' : '');
|
|
220
|
+
return s;
|
|
206
221
|
}
|
|
207
222
|
|
|
208
223
|
export function padEnd(s, width) {
|