dsh-better-edit 0.4.1 → 0.5.1
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/CHANGELOG.md +26 -1
- package/README.md +2 -1
- package/lib/contract.js +1 -1
- package/lib/edit-response.js +14 -11
- package/lib/encoding.js +308 -0
- package/lib/file-view.js +1 -1
- package/lib/fs-bridge.js +266 -4
- package/lib/fs-write.js +15 -6
- package/lib/hash-store.js +1 -1
- package/lib/hashline/anchor-pipeline.js +278 -43
- package/lib/hashline/hash-assign.js +18 -3
- package/lib/hashline/index.js +1 -1
- package/lib/prompts.js +14 -11
- package/lib/read-and-serve.js +5 -0
- package/lib/store-config.js +132 -2
- package/lib/tool-read.js +24 -4
- package/lib/types/contract.d.ts +1 -0
- package/lib/types/encoding.d.ts +46 -0
- package/lib/types/file-view.d.ts +1 -0
- package/lib/types/fs-bridge.d.ts +12 -1
- package/lib/types/hashline/anchor-pipeline.d.ts +7 -0
- package/lib/types/hashline/hash-assign.d.ts +2 -0
- package/lib/types/hashline/index.d.ts +1 -1
- package/lib/types/read-and-serve.d.ts +3 -0
- package/lib/types/store-config.d.ts +10 -1
- package/package.json +21 -3
package/lib/store-config.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { homedir } from "node:os";
|
|
8
8
|
import { isAbsolute, join } from "node:path";
|
|
9
|
-
import { readFileSync, statSync } from "node:fs";
|
|
9
|
+
import { readFileSync, statSync, appendFileSync } from "node:fs";
|
|
10
10
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
11
11
|
import { resolveDshHome } from "@deepseek-ai/dsh-home-paths";
|
|
12
12
|
import { z } from "zod";
|
|
@@ -46,6 +46,11 @@ function parseSimpleYaml(content) {
|
|
|
46
46
|
continue;
|
|
47
47
|
const key = line.slice(0, colon).trim();
|
|
48
48
|
let value = line.slice(colon + 1).trim();
|
|
49
|
+
if (value.startsWith("[") && value.endsWith("]")) {
|
|
50
|
+
value = value.slice(1, -1);
|
|
51
|
+
out[key] = value;
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
49
54
|
value = stripQuotes(value);
|
|
50
55
|
value = stripInlineComment(value);
|
|
51
56
|
out[key] = value;
|
|
@@ -69,6 +74,13 @@ function parseAutoGitIgnoreRaw(v) {
|
|
|
69
74
|
return false;
|
|
70
75
|
return undefined;
|
|
71
76
|
}
|
|
77
|
+
function parseSupportedEncodingsRaw(v) {
|
|
78
|
+
const inner = v.trim().replace(/^\[/, "").replace(/\]$/, "");
|
|
79
|
+
const items = inner.split(/[ ,;]+/).map((s) => s.trim().toLowerCase()).filter((s) => s.length > 0);
|
|
80
|
+
if (items.length === 0)
|
|
81
|
+
return undefined;
|
|
82
|
+
return items;
|
|
83
|
+
}
|
|
72
84
|
// ---- Zod schema (single source of truth) ----
|
|
73
85
|
const StoreConfigSchema = z.object({
|
|
74
86
|
storeDir: z
|
|
@@ -76,6 +88,9 @@ const StoreConfigSchema = z.object({
|
|
|
76
88
|
.default("central")
|
|
77
89
|
.transform((v) => normalizeStoreDir(v) ?? "central"), // where the store lives: "central" (default, in $DSH_HOME/.../runtime/<name>-<hash8>/) | "workspace" (legacy <ws>/.dsh_better_edit/) | "/abs/path" (custom root)
|
|
78
90
|
autoGitignore: z.boolean().default(false), // workspace only: auto-append ".dsh_better_edit/" to .gitignore when .git exists but entry missing (false = warn once)
|
|
91
|
+
autoGuessEncoding: z.boolean().default(false), // VS Code files.autoGuessEncoding — deterministic BOM→UTF-8 first, model-assisted top-3 only when true
|
|
92
|
+
normalizeToUtf8: z.boolean().default(false), // when true, legacy files (GBK etc.) migrate to UTF-8 on first edit/write
|
|
93
|
+
supportedEncodings: z.array(z.string()).default(["gbk", "big5", "shift_jis", "euc-kr", "windows-1251", "iso-8859-1"]),
|
|
79
94
|
undo_ttl_s: z.number().int().min(-1).default(604800), // undo history TTL in seconds; -1 = keep forever (default 604800 = 7 days)
|
|
80
95
|
storeMaxAgeS: z.number().int().min(1).default(2592000), // central janitor: max idle age in seconds before evicting runtime/<name>-<hash8>/ (default 2592000 = 30 days)
|
|
81
96
|
storeMaxTotalBytes: z.number().int().min(0).default(524288000), // central janitor: max total bytes under runtime/ before LRU eviction (default 524288000 = 500 MB)
|
|
@@ -86,6 +101,9 @@ let cachedMtimeMs;
|
|
|
86
101
|
let cachedYamlPath;
|
|
87
102
|
let cachedEnvStoreDir;
|
|
88
103
|
let cachedEnvAutoGitignore;
|
|
104
|
+
let cachedEnvAutoGuessEncoding;
|
|
105
|
+
let cachedEnvNormalizeToUtf8;
|
|
106
|
+
let cachedEnvSupportedEncodings;
|
|
89
107
|
function configYamlPath() {
|
|
90
108
|
return join(resolveDshHome(), "plugins", "dsh-better-edit", "config.yaml");
|
|
91
109
|
}
|
|
@@ -102,6 +120,14 @@ storeDir: central
|
|
|
102
120
|
# workspace only: when .git exists but .gitignore lacks .dsh_better_edit/, true = auto-append ".dsh_better_edit/", false = warn once
|
|
103
121
|
autoGitignore: false
|
|
104
122
|
|
|
123
|
+
# encoding: deterministic BOM→UTF-8 first, guessing only when autoGuessEncoding:true
|
|
124
|
+
# when true, FS_NOT_TEXT scores supportedEncodings and surfaces top-3 previews for model pick
|
|
125
|
+
autoGuessEncoding: false
|
|
126
|
+
# when true, legacy files (GBK etc.) migrate to UTF-8 on first write
|
|
127
|
+
normalizeToUtf8: false
|
|
128
|
+
# allowlist scored for top-3 previews when autoGuessEncoding:true
|
|
129
|
+
supportedEncodings: [gbk, big5, shift_jis, euc-kr, windows-1251, iso-8859-1]
|
|
130
|
+
|
|
105
131
|
# undo history TTL in seconds; -1 = keep forever (default 604800 = 7 days)
|
|
106
132
|
undo_ttl_s: 604800
|
|
107
133
|
|
|
@@ -217,6 +243,27 @@ function fsAdapter() {
|
|
|
217
243
|
}
|
|
218
244
|
}
|
|
219
245
|
}
|
|
246
|
+
if (parsed.autoGuessEncoding !== undefined) {
|
|
247
|
+
const b = parseAutoGitIgnoreRaw(parsed.autoGuessEncoding);
|
|
248
|
+
if (b === undefined)
|
|
249
|
+
console.warn(`dsh-better-edit: autoGuessEncoding "${parsed.autoGuessEncoding}" invalid — expected true|false`);
|
|
250
|
+
else
|
|
251
|
+
out.autoGuessEncoding = b;
|
|
252
|
+
}
|
|
253
|
+
if (parsed.normalizeToUtf8 !== undefined) {
|
|
254
|
+
const b = parseAutoGitIgnoreRaw(parsed.normalizeToUtf8);
|
|
255
|
+
if (b === undefined)
|
|
256
|
+
console.warn(`dsh-better-edit: normalizeToUtf8 "${parsed.normalizeToUtf8}" invalid — expected true|false`);
|
|
257
|
+
else
|
|
258
|
+
out.normalizeToUtf8 = b;
|
|
259
|
+
}
|
|
260
|
+
if (parsed.supportedEncodings !== undefined) {
|
|
261
|
+
const arr = parseSupportedEncodingsRaw(parsed.supportedEncodings);
|
|
262
|
+
if (arr === undefined)
|
|
263
|
+
console.warn(`dsh-better-edit: supportedEncodings "${parsed.supportedEncodings}" invalid`);
|
|
264
|
+
else
|
|
265
|
+
out.supportedEncodings = arr;
|
|
266
|
+
}
|
|
220
267
|
if (parsed.storeMaxTotalBytes !== undefined) {
|
|
221
268
|
const n = Number(parsed.storeMaxTotalBytes);
|
|
222
269
|
const res = z.number().int().min(0).safeParse(n);
|
|
@@ -254,6 +301,30 @@ function envAdapter(base) {
|
|
|
254
301
|
}
|
|
255
302
|
}
|
|
256
303
|
}
|
|
304
|
+
const envGuess = process.env.DSH_BETTER_EDIT_AUTO_GUESS_ENCODING;
|
|
305
|
+
if (envGuess !== undefined) {
|
|
306
|
+
const b = parseAutoGitIgnoreRaw(envGuess);
|
|
307
|
+
if (b === undefined)
|
|
308
|
+
console.warn(`dsh-better-edit: DSH_BETTER_EDIT_AUTO_GUESS_ENCODING invalid — expected true|false`);
|
|
309
|
+
else
|
|
310
|
+
out.autoGuessEncoding = b;
|
|
311
|
+
}
|
|
312
|
+
const envNorm = process.env.DSH_BETTER_EDIT_NORMALIZE_TO_UTF8;
|
|
313
|
+
if (envNorm !== undefined) {
|
|
314
|
+
const b = parseAutoGitIgnoreRaw(envNorm);
|
|
315
|
+
if (b === undefined)
|
|
316
|
+
console.warn(`dsh-better-edit: DSH_BETTER_EDIT_NORMALIZE_TO_UTF8 invalid — expected true|false`);
|
|
317
|
+
else
|
|
318
|
+
out.normalizeToUtf8 = b;
|
|
319
|
+
}
|
|
320
|
+
const envSup = process.env.DSH_BETTER_EDIT_SUPPORTED_ENCODINGS;
|
|
321
|
+
if (envSup !== undefined) {
|
|
322
|
+
const arr = parseSupportedEncodingsRaw(envSup);
|
|
323
|
+
if (arr === undefined)
|
|
324
|
+
console.warn(`dsh-better-edit: DSH_BETTER_EDIT_SUPPORTED_ENCODINGS invalid`);
|
|
325
|
+
else
|
|
326
|
+
out.supportedEncodings = arr;
|
|
327
|
+
}
|
|
257
328
|
const envAuto = process.env.DSH_BETTER_EDIT_AUTO_GITIGNORE;
|
|
258
329
|
if (envAuto !== undefined) {
|
|
259
330
|
const b = parseAutoGitIgnoreRaw(envAuto);
|
|
@@ -266,6 +337,46 @@ function envAdapter(base) {
|
|
|
266
337
|
}
|
|
267
338
|
return out;
|
|
268
339
|
}
|
|
340
|
+
function complementMissingFieldsSync(yamlPath, yamlPartial) {
|
|
341
|
+
// Best-effort: append missing canonical keys with defaults, preserving existing content.
|
|
342
|
+
// Only runs when the file exists (mtime !== undefined) and some canonical key is absent.
|
|
343
|
+
const missingLines = [];
|
|
344
|
+
if (yamlPartial.storeDir === undefined)
|
|
345
|
+
missingLines.push("storeDir: central");
|
|
346
|
+
if (yamlPartial.autoGitignore === undefined)
|
|
347
|
+
missingLines.push("autoGitignore: false");
|
|
348
|
+
if (yamlPartial.autoGuessEncoding === undefined)
|
|
349
|
+
missingLines.push("autoGuessEncoding: false");
|
|
350
|
+
if (yamlPartial.normalizeToUtf8 === undefined)
|
|
351
|
+
missingLines.push("normalizeToUtf8: false");
|
|
352
|
+
if (yamlPartial.supportedEncodings === undefined)
|
|
353
|
+
missingLines.push("supportedEncodings: [gbk, big5, shift_jis, euc-kr, windows-1251, iso-8859-1]");
|
|
354
|
+
if (yamlPartial.undo_ttl_s === undefined)
|
|
355
|
+
missingLines.push("undo_ttl_s: 604800");
|
|
356
|
+
if (yamlPartial.storeMaxAgeS === undefined)
|
|
357
|
+
missingLines.push("storeMaxAgeS: 2592000");
|
|
358
|
+
if (yamlPartial.storeMaxTotalBytes === undefined)
|
|
359
|
+
missingLines.push("storeMaxTotalBytes: 524288000");
|
|
360
|
+
if (missingLines.length === 0)
|
|
361
|
+
return;
|
|
362
|
+
try {
|
|
363
|
+
// Ensure we don't duplicate if file was concurrently complemented — re-read raw keys.
|
|
364
|
+
const raw = readFileSync(yamlPath, "utf-8");
|
|
365
|
+
const parsed = parseSimpleYaml(raw);
|
|
366
|
+
// Re-check against raw parsed (aliases for storeMaxAgeS already handled via yamlPartial, but double-check).
|
|
367
|
+
const stillMissing = missingLines.filter((line) => {
|
|
368
|
+
const key = line.split(":")[0].trim();
|
|
369
|
+
return parsed[key] === undefined;
|
|
370
|
+
});
|
|
371
|
+
if (stillMissing.length === 0)
|
|
372
|
+
return;
|
|
373
|
+
const suffix = (raw.endsWith("\n") || raw.length === 0 ? "" : "\n") + stillMissing.join("\n") + "\n";
|
|
374
|
+
appendFileSync(yamlPath, suffix, "utf-8");
|
|
375
|
+
}
|
|
376
|
+
catch {
|
|
377
|
+
// best-effort: ENOENT (file deleted between stat and read) or permission — ignore
|
|
378
|
+
}
|
|
379
|
+
}
|
|
269
380
|
// ---- public load (merged, cached) ----
|
|
270
381
|
export function loadConfig() {
|
|
271
382
|
const yamlPath = configYamlPath();
|
|
@@ -277,15 +388,28 @@ export function loadConfig() {
|
|
|
277
388
|
// no yaml file — fall through to defaults/cache miss
|
|
278
389
|
}
|
|
279
390
|
const envStoreDir = process.env.DSH_BETTER_EDIT_STORE_DIR;
|
|
391
|
+
const envGuess = process.env.DSH_BETTER_EDIT_AUTO_GUESS_ENCODING;
|
|
392
|
+
const envNorm = process.env.DSH_BETTER_EDIT_NORMALIZE_TO_UTF8;
|
|
393
|
+
const envSup = process.env.DSH_BETTER_EDIT_SUPPORTED_ENCODINGS;
|
|
280
394
|
const envAuto = process.env.DSH_BETTER_EDIT_AUTO_GITIGNORE;
|
|
281
395
|
if (cachedConfig !== undefined &&
|
|
282
396
|
cachedMtimeMs === mtime &&
|
|
283
397
|
cachedYamlPath === yamlPath &&
|
|
284
398
|
cachedEnvStoreDir === envStoreDir &&
|
|
285
|
-
cachedEnvAutoGitignore === envAuto
|
|
399
|
+
cachedEnvAutoGitignore === envAuto &&
|
|
400
|
+
cachedEnvAutoGuessEncoding === envGuess &&
|
|
401
|
+
cachedEnvNormalizeToUtf8 === envNorm &&
|
|
402
|
+
cachedEnvSupportedEncodings === envSup) {
|
|
286
403
|
return cachedConfig;
|
|
287
404
|
}
|
|
288
405
|
const yamlPartial = fsAdapter();
|
|
406
|
+
if (mtime !== undefined) {
|
|
407
|
+
complementMissingFieldsSync(yamlPath, yamlPartial);
|
|
408
|
+
try {
|
|
409
|
+
mtime = statSync(yamlPath).mtimeMs;
|
|
410
|
+
}
|
|
411
|
+
catch { }
|
|
412
|
+
}
|
|
289
413
|
const envPartial = envAdapter({ ...DEFAULT_CONFIG, ...yamlPartial });
|
|
290
414
|
const merged = { ...DEFAULT_CONFIG, ...yamlPartial, ...envPartial };
|
|
291
415
|
// final Zod validation + normalization (expand abs, fallback)
|
|
@@ -305,6 +429,9 @@ export function loadConfig() {
|
|
|
305
429
|
cachedYamlPath = yamlPath;
|
|
306
430
|
cachedEnvStoreDir = envStoreDir;
|
|
307
431
|
cachedEnvAutoGitignore = envAuto;
|
|
432
|
+
cachedEnvAutoGuessEncoding = envGuess;
|
|
433
|
+
cachedEnvNormalizeToUtf8 = envNorm;
|
|
434
|
+
cachedEnvSupportedEncodings = envSup;
|
|
308
435
|
return cfg;
|
|
309
436
|
}
|
|
310
437
|
// For tests: reset cache
|
|
@@ -314,4 +441,7 @@ export function _resetConfigCache() {
|
|
|
314
441
|
cachedYamlPath = undefined;
|
|
315
442
|
cachedEnvStoreDir = undefined;
|
|
316
443
|
cachedEnvAutoGitignore = undefined;
|
|
444
|
+
cachedEnvAutoGuessEncoding = undefined;
|
|
445
|
+
cachedEnvNormalizeToUtf8 = undefined;
|
|
446
|
+
cachedEnvSupportedEncodings = undefined;
|
|
317
447
|
}
|
package/lib/tool-read.js
CHANGED
|
@@ -9,6 +9,7 @@ import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
|
9
9
|
import { normalizeRequest as normReq, assertReadRequest, pathSchema } from "./contract.js";
|
|
10
10
|
import { readAndServe } from "./read-and-serve.js";
|
|
11
11
|
import { READ_DESCRIPTION } from "./prompts.js";
|
|
12
|
+
import { normalizeEncoding } from "./encoding.js";
|
|
12
13
|
import { execCwd, execSessionKey } from "./session-view.js";
|
|
13
14
|
import { withWorkspace } from "./session-view.js";
|
|
14
15
|
/**
|
|
@@ -32,30 +33,49 @@ export function buildReadTool(io) {
|
|
|
32
33
|
type: "number",
|
|
33
34
|
description: "Maximum number of lines to read",
|
|
34
35
|
},
|
|
36
|
+
encoding: {
|
|
37
|
+
type: "string",
|
|
38
|
+
description: "Text encoding for Reopen with Encoding (e.g. gbk, shift_jis, windows-1251). Case-insensitive.",
|
|
39
|
+
},
|
|
35
40
|
},
|
|
36
41
|
output: {
|
|
37
|
-
schema: { type: "string" },
|
|
38
|
-
render: (_args, value) =>
|
|
42
|
+
schema: { type: "object", properties: { text: { type: "string", required: true }, warning: { type: "string" } }, additionalProperties: false },
|
|
43
|
+
render: (_args, value) => {
|
|
44
|
+
const v = value;
|
|
45
|
+
if (typeof v === "string")
|
|
46
|
+
return [{ type: "text", text: v }];
|
|
47
|
+
const blocks = [{ type: "text", text: v.text }];
|
|
48
|
+
if (v.warning)
|
|
49
|
+
blocks.push({ type: "text", text: v.warning });
|
|
50
|
+
return blocks;
|
|
51
|
+
},
|
|
39
52
|
},
|
|
40
53
|
async execute(args, exec) {
|
|
41
54
|
return withWorkspace(execCwd(exec), async () => {
|
|
42
55
|
const cwd = execCwd(exec);
|
|
43
56
|
const sessionKey = execSessionKey(exec);
|
|
44
57
|
const signal = exec.signal;
|
|
58
|
+
const encoding = args.encoding;
|
|
59
|
+
if (encoding !== undefined) {
|
|
60
|
+
const norm = normalizeEncoding(String(encoding));
|
|
61
|
+
if (!norm)
|
|
62
|
+
throw new Error(`[E_BAD_ENCODING] Unknown encoding: ${String(encoding)}. Supported: utf8, gbk, big5, shift_jis, euc-kr, windows-1251, iso-8859-1`);
|
|
63
|
+
}
|
|
45
64
|
const canonical = normReq(args);
|
|
46
65
|
assertReadRequest(canonical);
|
|
47
66
|
const rawPath = canonical.path;
|
|
48
|
-
const { text, absolutePath } = await readAndServe(io, rawPath, cwd, {
|
|
67
|
+
const { text, absolutePath, warning } = await readAndServe(io, rawPath, cwd, {
|
|
49
68
|
sessionKey,
|
|
50
69
|
signal,
|
|
51
70
|
offset: canonical.offset,
|
|
52
71
|
limit: canonical.limit,
|
|
72
|
+
encoding: encoding,
|
|
53
73
|
});
|
|
54
74
|
// Record the present observation with the fs policy gate so later
|
|
55
75
|
// built-in write/edit calls see this file as observed at the
|
|
56
76
|
// version the model just read (a no-op when no policy listens).
|
|
57
77
|
await io.emitObserved(absolutePath, exec, signal);
|
|
58
|
-
return text;
|
|
78
|
+
return warning ? { text, warning } : { text };
|
|
59
79
|
});
|
|
60
80
|
},
|
|
61
81
|
});
|
package/lib/types/contract.d.ts
CHANGED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VS Code encoding model — pure helpers for BOM→UTF-8→model-assisted top-3.
|
|
3
|
+
* No jschardet; heuristic scoring + iconv-lite rendering.
|
|
4
|
+
* @module dsh-better-edit/encoding
|
|
5
|
+
*/
|
|
6
|
+
export declare const SUPPORTED_ENCODINGS: readonly ["gbk", "big5", "shift_jis", "euc-kr", "windows-1251", "iso-8859-1"];
|
|
7
|
+
export type SupportedEncoding = (typeof SUPPORTED_ENCODINGS)[number];
|
|
8
|
+
/** Canonicalize case-insensitive encoding param, strip -_ . */
|
|
9
|
+
export declare function normalizeEncoding(input: string): string | undefined;
|
|
10
|
+
export declare function isSupportedEncoding(enc: string): boolean;
|
|
11
|
+
export interface BomInfo {
|
|
12
|
+
encoding: string;
|
|
13
|
+
bomLen: number;
|
|
14
|
+
hasBOM: boolean;
|
|
15
|
+
}
|
|
16
|
+
export declare function detectBom(bytes: Uint8Array): BomInfo | undefined;
|
|
17
|
+
export declare function isValidUtf8(bytes: Uint8Array): boolean;
|
|
18
|
+
export interface CandidatePreview {
|
|
19
|
+
encoding: string;
|
|
20
|
+
sample: string;
|
|
21
|
+
score: number;
|
|
22
|
+
}
|
|
23
|
+
export declare function scoreText(text: string, enc: string): number;
|
|
24
|
+
/** Decode bytes under enc via iconv-lite, return text or undefined on failure. */
|
|
25
|
+
export declare function decodeBytes(bytes: Uint8Array, enc: string): string | undefined;
|
|
26
|
+
export declare function encodeText(text: string, enc: string): Uint8Array | undefined;
|
|
27
|
+
/** Top-3 candidates for autoGuess: decode each allowlist enc, score, sort. */
|
|
28
|
+
export declare function top3Candidates(bytes: Uint8Array, allowlist: string[]): CandidatePreview[];
|
|
29
|
+
export declare function hasReplacementChar(text: string): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Try chardet (runk/node-chardet) for autoGuess when available.
|
|
32
|
+
* Dynamically imports 'chardet' (optionalDep) and returns canonical encoding
|
|
33
|
+
* if confidence >=45 and allowlist-accepted and decodable without �.
|
|
34
|
+
* Falls back to heuristic when chardet unavailable/low confidence.
|
|
35
|
+
*/
|
|
36
|
+
export declare function detectWithChardet(bytes: Uint8Array, allowlist: string[]): Promise<string | undefined>;
|
|
37
|
+
/**
|
|
38
|
+
* Chardet-based Top-3 for E_NOT_TEXT (primary) and autoGuess.
|
|
39
|
+
* Returns chardet candidates filtered by allowlist and decodable, else empty.
|
|
40
|
+
*/
|
|
41
|
+
export declare function chardetTop3Candidates(bytes: Uint8Array, allowlist: string[]): Promise<Array<{
|
|
42
|
+
encoding: string;
|
|
43
|
+
confidence: number;
|
|
44
|
+
sample: string;
|
|
45
|
+
}>>;
|
|
46
|
+
export declare function getTop3Candidates(bytes: Uint8Array, allowlist: string[]): Promise<CandidatePreview[]>;
|
package/lib/types/file-view.d.ts
CHANGED
|
@@ -128,6 +128,7 @@ export interface PreviewOpts {
|
|
|
128
128
|
limit?: number;
|
|
129
129
|
}
|
|
130
130
|
export interface ReadViewOpts extends PreviewOpts {
|
|
131
|
+
encoding?: string;
|
|
131
132
|
signal?: AbortSignal;
|
|
132
133
|
}
|
|
133
134
|
export declare function preview(content: string, hashes: string[], opts?: PreviewOpts, absolutePath?: string): Promise<{
|
package/lib/types/fs-bridge.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export interface FileIO {
|
|
|
23
23
|
/** Resolve a (possibly relative) request path against the session cwd to a canonical absolute path. */
|
|
24
24
|
resolve(path: string, cwd: string, signal?: AbortSignal): Promise<string>;
|
|
25
25
|
/** Read whole text; missing files, directories, and binary content throw. */
|
|
26
|
-
readText(absolutePath: string, signal?: AbortSignal): Promise<string>;
|
|
26
|
+
readText(absolutePath: string, signal?: AbortSignal, encoding?: string): Promise<string>;
|
|
27
27
|
/**
|
|
28
28
|
* Atomically write whole text, preserving mode when the file exists. On the
|
|
29
29
|
* dsh backend this dispatches `fs/write-intent` (policy guard), stamps the
|
|
@@ -53,6 +53,17 @@ export interface FileIO {
|
|
|
53
53
|
* @returns the mapped error, rethrown.
|
|
54
54
|
*/
|
|
55
55
|
export declare function mapFsError(error: unknown, displayPath: string): never;
|
|
56
|
+
export interface FileEncodingState {
|
|
57
|
+
encoding: string;
|
|
58
|
+
hasBOM: boolean;
|
|
59
|
+
version: string | undefined;
|
|
60
|
+
}
|
|
61
|
+
export declare function getAutoGuessFooter(targetKey: string): string | undefined;
|
|
62
|
+
export declare function setAutoGuessFooter(targetKey: string, footer: string): void;
|
|
63
|
+
export declare function clearAutoGuessFooter(targetKey?: string): void;
|
|
64
|
+
export declare function getEncodingState(targetKey: string): FileEncodingState | undefined;
|
|
65
|
+
export declare function setEncodingState(targetKey: string, state: FileEncodingState): void;
|
|
66
|
+
export declare function clearEncodingState(targetKey?: string): void;
|
|
56
67
|
/** FileIO over the deployment's `ctx.fs` service. */
|
|
57
68
|
export declare function ctxFsIO(fs: FileSystem, ctx: Context): FileIO;
|
|
58
69
|
/** FileIO over the host filesystem directly (tests, previews, fallback). */
|
|
@@ -85,6 +85,13 @@ export declare class AnchorMismatchError extends Error {
|
|
|
85
85
|
constructor(message: string, servedRows: ServedRow[]);
|
|
86
86
|
}
|
|
87
87
|
export declare function isAnchorMismatch(error: unknown): error is AnchorMismatchError;
|
|
88
|
+
export declare function findEditHashEcho(replacementLines: string[], served: readonly (string | null)[], startLine: number): {
|
|
89
|
+
k: number;
|
|
90
|
+
hash: string;
|
|
91
|
+
} | undefined;
|
|
92
|
+
export declare class EditHashEchoError extends AnchorMismatchError {
|
|
93
|
+
constructor(message: string, servedRows?: ServedRow[]);
|
|
94
|
+
}
|
|
88
95
|
export declare function buildRangeEcho(startLine: number, endLine: number, fileHashes: string[]): ServedRow[];
|
|
89
96
|
export declare function fmtServedRows(rows: ServedRow[], fileLines: string[]): string;
|
|
90
97
|
export declare function verifyServedRange(args: {
|
|
@@ -16,6 +16,8 @@ export declare const HASH_SEP = "\u2502";
|
|
|
16
16
|
export declare const HASH_SPACE: number;
|
|
17
17
|
export declare const MAX_HASH_LINES: number;
|
|
18
18
|
export declare const HASH_PROBE_STRIDE: number;
|
|
19
|
+
export declare function rememberHashCanon(hash: string, canonText: string): void;
|
|
20
|
+
export declare function getCanonForHash(hash: string): string | undefined;
|
|
19
21
|
export declare const HL_PREFIX_PLUS_RE: RegExp;
|
|
20
22
|
export declare const HL_PREFIX_MINUS_RE: RegExp;
|
|
21
23
|
export declare const HL_BARE_PREFIX_RE: RegExp;
|
|
@@ -9,5 +9,5 @@ export { parseHashRef, parseText } from "./parse.js";
|
|
|
9
9
|
export type { Anchor } from "./parse.js";
|
|
10
10
|
export { resEdit } from "./anchor-pipeline.js";
|
|
11
11
|
export type { HEdit, HTEdit, NEdit, BDup, AutoFix } from "./anchor-pipeline.js";
|
|
12
|
-
export { applyEdit, fmtRegion, changedRange, buildIdx, ServedRejectionError, AnchorMismatchError, isServedRejection, isAnchorMismatch, verifyServedRange, buildRangeEcho, fmtServedRows, } from "./anchor-pipeline.js";
|
|
12
|
+
export { applyEdit, fmtRegion, changedRange, buildIdx, ServedRejectionError, AnchorMismatchError, EditHashEchoError, findEditHashEcho, isServedRejection, isAnchorMismatch, verifyServedRange, buildRangeEcho, fmtServedRows, } from "./anchor-pipeline.js";
|
|
13
13
|
export type { ServedRow, ResolvedRange, ServedCode, } from "./anchor-pipeline.js";
|
|
@@ -12,6 +12,7 @@ import type { ServedRow } from "./hashline/served.js";
|
|
|
12
12
|
/** Appended when the file had non-UTF-8 bytes; editing rewrites it as UTF-8. */
|
|
13
13
|
export declare const UTF8_REWRITE_NOTE = "[Non-UTF-8 bytes shown as U+FFFD; editing rewrites the file as UTF-8.]";
|
|
14
14
|
export interface ReadAndServeOptions {
|
|
15
|
+
encoding?: string;
|
|
15
16
|
/** The session whose served rows these lines belong to. */
|
|
16
17
|
sessionKey: string;
|
|
17
18
|
signal?: AbortSignal;
|
|
@@ -20,6 +21,8 @@ export interface ReadAndServeOptions {
|
|
|
20
21
|
limit?: number;
|
|
21
22
|
}
|
|
22
23
|
export interface ReadAndServeResult {
|
|
24
|
+
/** Optional auto-guess warning, separate block. */
|
|
25
|
+
warning?: string;
|
|
23
26
|
/** The model-facing read text, including the UTF-8 note when applicable. */
|
|
24
27
|
text: string;
|
|
25
28
|
/** The rows recorded as served (empty when nothing was shown). */
|
|
@@ -3,25 +3,34 @@ export declare function expand(filePath: string): string;
|
|
|
3
3
|
declare const StoreConfigSchema: z.ZodObject<{
|
|
4
4
|
storeDir: z.ZodEffects<z.ZodDefault<z.ZodString>, string, string | undefined>;
|
|
5
5
|
autoGitignore: z.ZodDefault<z.ZodBoolean>;
|
|
6
|
+
autoGuessEncoding: z.ZodDefault<z.ZodBoolean>;
|
|
7
|
+
normalizeToUtf8: z.ZodDefault<z.ZodBoolean>;
|
|
8
|
+
supportedEncodings: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
6
9
|
undo_ttl_s: z.ZodDefault<z.ZodNumber>;
|
|
7
10
|
storeMaxAgeS: z.ZodDefault<z.ZodNumber>;
|
|
8
11
|
storeMaxTotalBytes: z.ZodDefault<z.ZodNumber>;
|
|
9
12
|
}, "strip", z.ZodTypeAny, {
|
|
10
13
|
storeDir: string;
|
|
11
14
|
autoGitignore: boolean;
|
|
15
|
+
autoGuessEncoding: boolean;
|
|
16
|
+
normalizeToUtf8: boolean;
|
|
17
|
+
supportedEncodings: string[];
|
|
12
18
|
undo_ttl_s: number;
|
|
13
19
|
storeMaxAgeS: number;
|
|
14
20
|
storeMaxTotalBytes: number;
|
|
15
21
|
}, {
|
|
16
22
|
storeDir?: string | undefined;
|
|
17
23
|
autoGitignore?: boolean | undefined;
|
|
24
|
+
autoGuessEncoding?: boolean | undefined;
|
|
25
|
+
normalizeToUtf8?: boolean | undefined;
|
|
26
|
+
supportedEncodings?: string[] | undefined;
|
|
18
27
|
undo_ttl_s?: number | undefined;
|
|
19
28
|
storeMaxAgeS?: number | undefined;
|
|
20
29
|
storeMaxTotalBytes?: number | undefined;
|
|
21
30
|
}>;
|
|
22
31
|
export type StoreConfig = z.infer<typeof StoreConfigSchema>;
|
|
23
32
|
/** Default config.yaml content with comments — generated when the file does not exist. */
|
|
24
|
-
export declare const DEFAULT_CONFIG_YAML = "# dsh-better-edit config\n# Location: $DSH_HOME/plugins/dsh-better-edit/config.yaml\n# Docs: https://github.com/Rianico/dsh-better-edit#configuration\n# Generated with defaults on first load \u2014 edit or delete freely.\n# DB files are disposable caches \u2014 safe to delete, rebuilt on next `read`.\n\n# where the store lives: \"central\" (default, in $DSH_HOME/.../runtime/<name>-<hash8>/) | \"workspace\" (legacy <ws>/.dsh_better_edit/) | \"/abs/path\" (custom root)\nstoreDir: central\n\n# workspace only: when .git exists but .gitignore lacks .dsh_better_edit/, true = auto-append \".dsh_better_edit/\", false = warn once\nautoGitignore: false\n\n# undo history TTL in seconds; -1 = keep forever (default 604800 = 7 days)\nundo_ttl_s: 604800\n\n# central janitor: max idle age in seconds before evicting runtime/<name>-<hash8>/ (default 2592000 = 30 days)\nstoreMaxAgeS: 2592000\n\n# central janitor: max total bytes under runtime/ before LRU eviction (default 524288000 = 500 MB)\nstoreMaxTotalBytes: 524288000\n";
|
|
33
|
+
export declare const DEFAULT_CONFIG_YAML = "# dsh-better-edit config\n# Location: $DSH_HOME/plugins/dsh-better-edit/config.yaml\n# Docs: https://github.com/Rianico/dsh-better-edit#configuration\n# Generated with defaults on first load \u2014 edit or delete freely.\n# DB files are disposable caches \u2014 safe to delete, rebuilt on next `read`.\n\n# where the store lives: \"central\" (default, in $DSH_HOME/.../runtime/<name>-<hash8>/) | \"workspace\" (legacy <ws>/.dsh_better_edit/) | \"/abs/path\" (custom root)\nstoreDir: central\n\n# workspace only: when .git exists but .gitignore lacks .dsh_better_edit/, true = auto-append \".dsh_better_edit/\", false = warn once\nautoGitignore: false\n\n# encoding: deterministic BOM\u2192UTF-8 first, guessing only when autoGuessEncoding:true\n# when true, FS_NOT_TEXT scores supportedEncodings and surfaces top-3 previews for model pick\nautoGuessEncoding: false\n# when true, legacy files (GBK etc.) migrate to UTF-8 on first write\nnormalizeToUtf8: false\n# allowlist scored for top-3 previews when autoGuessEncoding:true\nsupportedEncodings: [gbk, big5, shift_jis, euc-kr, windows-1251, iso-8859-1]\n\n# undo history TTL in seconds; -1 = keep forever (default 604800 = 7 days)\nundo_ttl_s: 604800\n\n# central janitor: max idle age in seconds before evicting runtime/<name>-<hash8>/ (default 2592000 = 30 days)\nstoreMaxAgeS: 2592000\n\n# central janitor: max total bytes under runtime/ before LRU eviction (default 524288000 = 500 MB)\nstoreMaxTotalBytes: 524288000\n";
|
|
25
34
|
/**
|
|
26
35
|
* Ensure a default config.yaml exists in the plugin home.
|
|
27
36
|
* Idempotent and concurrent-safe (wx) — never overwrites an existing file.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-better-edit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Hash-anchored read/edit/undo_last_edit tools for DeepSeek Harness (dsh). Every line gets a unique 3-char hash (A-Za-z0-9) that stays stable across edits; stale or ambiguous anchors are rejected, never fuzzy-matched. Undo persists across restarts.",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"diff": "^8.0.2",
|
|
58
58
|
"file-type": "^21.3.0",
|
|
59
|
+
"iconv-lite": "^0.6.3",
|
|
59
60
|
"xxhash-wasm": "^1.1.0",
|
|
60
61
|
"zod": "^3.25.76"
|
|
61
62
|
},
|
|
@@ -63,7 +64,7 @@
|
|
|
63
64
|
"node": "^22.19.0 || >=24.0.0"
|
|
64
65
|
},
|
|
65
66
|
"scripts": {
|
|
66
|
-
"prepare": "tsc -p tsconfig.json",
|
|
67
|
+
"prepare": "tsc -p tsconfig.json && husky",
|
|
67
68
|
"build": "tsc -p tsconfig.json",
|
|
68
69
|
"typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json",
|
|
69
70
|
"test": "vitest run",
|
|
@@ -71,9 +72,17 @@
|
|
|
71
72
|
"prepublishOnly": "npm run typecheck && npm test && node scripts/assert-tagged.mjs",
|
|
72
73
|
"benchmark": "node benchmark/run.mjs",
|
|
73
74
|
"postpublish": "node scripts/tag-current.mjs",
|
|
74
|
-
"release": "node scripts/release.mjs"
|
|
75
|
+
"release": "node scripts/release.mjs",
|
|
76
|
+
"lint": "biome check .",
|
|
77
|
+
"lint:fix": "biome check --write .",
|
|
78
|
+
"format": "biome check --write .",
|
|
79
|
+
"format:check": "biome check .",
|
|
80
|
+
"test:coverage": "vitest run --coverage"
|
|
75
81
|
},
|
|
76
82
|
"devDependencies": {
|
|
83
|
+
"@biomejs/biome": "^2.1.0",
|
|
84
|
+
"@commitlint/cli": "^21.2.2",
|
|
85
|
+
"@commitlint/config-conventional": "^21.2.2",
|
|
77
86
|
"@deepseek-ai/cordis": "^4.0.1",
|
|
78
87
|
"@deepseek-ai/dsh-agent": "0.1.0-rc.6",
|
|
79
88
|
"@deepseek-ai/dsh-fs": "0.1.0-rc.6",
|
|
@@ -81,10 +90,19 @@
|
|
|
81
90
|
"@deepseek-ai/dsh-sandbox": "^0.1.0-rc.6",
|
|
82
91
|
"@deepseek-ai/dsh-session": "0.1.0-rc.6",
|
|
83
92
|
"@deepseek-ai/dsh-tools": "0.1.0-rc.6",
|
|
93
|
+
"@semantic-release/changelog": "^7.0.0",
|
|
94
|
+
"@semantic-release/git": "^11.0.1",
|
|
95
|
+
"@semantic-release/github": "^12.0.9",
|
|
84
96
|
"@types/node": "^24.0.0",
|
|
85
97
|
"@vitest/coverage-v8": "^4.1.10",
|
|
98
|
+
"conventional-changelog-conventionalcommits": "^8.0.0",
|
|
99
|
+
"husky": "^9.1.7",
|
|
86
100
|
"js-tiktoken": "1.0.21",
|
|
101
|
+
"semantic-release": "^25.0.9",
|
|
87
102
|
"typescript": "^5.8.0",
|
|
88
103
|
"vitest": "^4.1.8"
|
|
104
|
+
},
|
|
105
|
+
"optionalDependencies": {
|
|
106
|
+
"chardet": "2.2.0"
|
|
89
107
|
}
|
|
90
108
|
}
|