dsh-better-edit 0.1.0 → 0.1.2

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/lib/write-hook.js CHANGED
@@ -9,6 +9,7 @@ import { normFromText } from './file-reader.js';
9
9
  import { fmtReadPreview, MAX_HASH_LINES } from './read-render.js';
10
10
  import { recordServed, clearDriftReported } from './served-store.js';
11
11
  import { execCwd, execSessionKey } from './dsh-context.js';
12
+ import { withWorkspace } from './workspace.js';
12
13
  const AUTO_READ_HEADING = '--- Auto-read (hashline anchors) ---';
13
14
  /**
14
15
  * Register the post-write auto-read listener on the calling agent's scope.
@@ -23,50 +24,54 @@ const AUTO_READ_HEADING = '--- Auto-read (hashline anchors) ---';
23
24
  */
24
25
  export function registerWriteHook(rootCtx, agentCtx, io) {
25
26
  return agentCtx.on('tools/post-execute', async (exec, result, next) => {
26
- const decision = await next();
27
- if (exec.name !== 'write' ||
28
- result.isError ||
29
- decision.kind !== 'accept') {
30
- return decision;
31
- }
32
- const decisionContent = decision.content ?? result.content;
33
- const rawPath = exec.arguments
34
- ?.file_path ?? exec.arguments
35
- ?.path;
36
- if (typeof rawPath !== 'string')
37
- return decision;
38
- try {
39
- const cwd = execCwd(exec);
40
- const sessionKey = execSessionKey(exec);
41
- const signal = exec.signal;
42
- const absolutePath = await io.resolve(rawPath, cwd, signal);
43
- const rawText = await io.readText(absolutePath, signal);
44
- const { normalized, fileHashes, hadUtf8DecodeErrors } = await normFromText({
45
- absolutePath,
46
- rawText,
47
- displayPath: rawPath,
48
- signal,
49
- maxLines: MAX_HASH_LINES,
27
+ return withWorkspace(execCwd(exec), async () => {
28
+ return withWorkspace(execCwd(exec), async () => {
29
+ const decision = await next();
30
+ if (exec.name !== 'write' ||
31
+ result.isError ||
32
+ decision.kind !== 'accept') {
33
+ return decision;
34
+ }
35
+ const decisionContent = decision.content ?? result.content;
36
+ const rawPath = exec.arguments
37
+ ?.file_path ?? exec.arguments
38
+ ?.path;
39
+ if (typeof rawPath !== 'string')
40
+ return decision;
41
+ try {
42
+ const cwd = execCwd(exec);
43
+ const sessionKey = execSessionKey(exec);
44
+ const signal = exec.signal;
45
+ const absolutePath = await io.resolve(rawPath, cwd, signal);
46
+ const rawText = await io.readText(absolutePath, signal);
47
+ const { normalized, fileHashes, hadUtf8DecodeErrors } = await normFromText({
48
+ absolutePath,
49
+ rawText,
50
+ displayPath: rawPath,
51
+ signal,
52
+ maxLines: MAX_HASH_LINES,
53
+ });
54
+ const preview = await fmtReadPreview(normalized, {}, fileHashes, absolutePath);
55
+ if (preview.served.length > 0) {
56
+ await recordServed(sessionKey, absolutePath, preview.served);
57
+ }
58
+ await clearDriftReported(sessionKey, absolutePath);
59
+ const text = hadUtf8DecodeErrors
60
+ ? `${preview.text}\n\n[Non-UTF-8 bytes shown as U+FFFD; editing rewrites the file as UTF-8.]`
61
+ : preview.text;
62
+ return {
63
+ kind: 'accept',
64
+ content: [
65
+ ...(decisionContent),
66
+ { type: 'text', text: `\n\n${AUTO_READ_HEADING}\n${text}` },
67
+ ],
68
+ };
69
+ }
70
+ catch (error) {
71
+ rootCtx.logger.warn(`dsh-better-edit: auto-read after write failed: ${error instanceof Error ? error.message : String(error)}`);
72
+ return decision;
73
+ }
50
74
  });
51
- const preview = await fmtReadPreview(normalized, {}, fileHashes, absolutePath);
52
- if (preview.served.length > 0) {
53
- await recordServed(sessionKey, absolutePath, preview.served);
54
- }
55
- await clearDriftReported(sessionKey, absolutePath);
56
- const text = hadUtf8DecodeErrors
57
- ? `${preview.text}\n\n[Non-UTF-8 bytes shown as U+FFFD; editing rewrites the file as UTF-8.]`
58
- : preview.text;
59
- return {
60
- kind: 'accept',
61
- content: [
62
- ...(decisionContent),
63
- { type: 'text', text: `\n\n${AUTO_READ_HEADING}\n${text}` },
64
- ],
65
- };
66
- }
67
- catch (error) {
68
- rootCtx.logger.warn(`dsh-better-edit: auto-read after write failed: ${error instanceof Error ? error.message : String(error)}`);
69
- return decision;
70
- }
75
+ });
71
76
  });
72
77
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-better-edit",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "description": "Hash-anchored read/edit/batch_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",