dsh-hashline-edit 0.3.0 → 0.3.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.
Files changed (2) hide show
  1. package/lib/index.js +92 -30
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -48,7 +48,7 @@ import {
48
48
  import { dirname as dirname2, join as join4, parse, resolve, sep } from "node:path";
49
49
 
50
50
  // src/hashline/alphabet.ts
51
- var HASH_LEN = true ? 4 : resolveAnchorWidth(process.env);
51
+ var HASH_LEN = true ? 3 : resolveAnchorWidth(process.env);
52
52
  var ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
53
53
  var ALPHA_SAFE = ALPHA.replace(/-/g, "\\-");
54
54
  var ALPHA_RE = new RegExp(`^[${ALPHA_SAFE}]+$`);
@@ -1870,6 +1870,7 @@ function commandOf(args) {
1870
1870
 
1871
1871
  // dsh/guidance.ts
1872
1872
  import { readFileSync as readFileSync2, statSync as statSync2 } from "node:fs";
1873
+ import { createHash } from "node:crypto";
1873
1874
  import { mkdir as mkdir3, readFile as readFile3, readdir as readdir2, writeFile as writeFile3 } from "node:fs/promises";
1874
1875
  import { join as join6 } from "node:path";
1875
1876
  import { resolveDshHome } from "@deepseek-ai/dsh-home-paths";
@@ -2028,8 +2029,9 @@ var GUIDANCE_HOME_README = `# dsh-hashline-edit guidance
2028
2029
 
2029
2030
  Each agent preset has its own guidance directory here: \`<preset>/<section>.md\`.
2030
2031
  On first boot the plugin seeds the shipped presets (\`standard\`, \`ptc\`,
2031
- \`minimal\`, \`cordis\`) with the compiled defaults; existing files are never
2032
- overwritten, so your edits survive.
2032
+ \`minimal\`, \`cordis\`) with the compiled defaults. Files you edit are never
2033
+ overwritten; a file left untouched at the shipped default is refreshed when the
2034
+ plugin is upgraded, and a blank file falls back to that default.
2033
2035
 
2034
2036
  Each file is one tool section:
2035
2037
 
@@ -2068,7 +2070,8 @@ var GUIDANCE_HOME_README_ZH = `# dsh-hashline-edit \u6307\u5F15
2068
2070
 
2069
2071
  \u6BCF\u4E2A agent preset \u5728\u8FD9\u91CC\u90FD\u6709\u81EA\u5DF1\u7684\u6307\u5F15\u76EE\u5F55\uFF1A\`<preset>/<section>.md\`\u3002\u9996\u6B21\u542F\u52A8\u65F6
2070
2072
  \u63D2\u4EF6\u4F1A\u4E3A\u968F\u9644\u7684 preset\uFF08\`standard\`\u3001\`ptc\`\u3001\`minimal\`\u3001\`cordis\`\uFF09\u5199\u5165\u7F16\u8BD1\u5185\u7F6E\u7684
2071
- \u9ED8\u8BA4\u5185\u5BB9\uFF1B\u5DF2\u6709\u6587\u4EF6\u7EDD\u4E0D\u88AB\u8986\u76D6\uFF0C\u56E0\u6B64\u4F60\u7684\u7F16\u8F91\u4F1A\u4FDD\u7559\u3002
2073
+ \u9ED8\u8BA4\u5185\u5BB9\u3002\u4F60\u7F16\u8F91\u8FC7\u7684\u6587\u4EF6\u7EDD\u4E0D\u88AB\u8986\u76D6\uFF1B\u4ECD\u4FDD\u6301\u968F\u9644\u9ED8\u8BA4\u5185\u5BB9\u7684\u6587\u4EF6\u4F1A\u5728\u63D2\u4EF6\u5347\u7EA7\u65F6\u5237\u65B0\uFF0C
2074
+ \u7A7A\u767D\u6587\u4EF6\u5219\u56DE\u9000\u5230\u9ED8\u8BA4\u5185\u5BB9\u3002
2072
2075
 
2073
2076
  \u6BCF\u4E2A\u6587\u4EF6\u5BF9\u5E94\u4E00\u4E2A\u5DE5\u5177\u7247\u6BB5\uFF1A
2074
2077
 
@@ -2106,39 +2109,93 @@ order: ${section.defaultOrder}
2106
2109
 
2107
2110
  ${section.renderDefault()}`;
2108
2111
  }
2109
- async function healBlankOverride(path, section) {
2112
+ var SEED_STATE_FILE = ".seeded.json";
2113
+ function seedHash(value) {
2114
+ return createHash("sha256").update(value, "utf-8").digest("hex");
2115
+ }
2116
+ async function readSeedState(homeDir) {
2117
+ const state = /* @__PURE__ */ new Map();
2118
+ try {
2119
+ const parsed = JSON.parse(await readFile3(join6(homeDir, SEED_STATE_FILE), "utf-8"));
2120
+ const files = parsed?.files;
2121
+ if (files !== null && typeof files === "object") {
2122
+ for (const [key, value] of Object.entries(files)) {
2123
+ if (typeof value === "string") state.set(key, value);
2124
+ }
2125
+ }
2126
+ } catch {
2127
+ }
2128
+ return state;
2129
+ }
2130
+ async function writeSeedState(homeDir, state) {
2131
+ const merged = {};
2132
+ try {
2133
+ const parsed = JSON.parse(await readFile3(join6(homeDir, SEED_STATE_FILE), "utf-8"));
2134
+ const files = parsed?.files;
2135
+ if (files !== null && typeof files === "object") {
2136
+ for (const [key, value] of Object.entries(files)) {
2137
+ if (typeof value === "string") merged[key] = value;
2138
+ }
2139
+ }
2140
+ } catch {
2141
+ }
2142
+ for (const [key, value] of state) merged[key] = value;
2143
+ await writeFile3(
2144
+ join6(homeDir, SEED_STATE_FILE),
2145
+ `${JSON.stringify({ version: 1, files: merged }, null, 2)}
2146
+ `,
2147
+ { encoding: "utf-8" }
2148
+ );
2149
+ }
2150
+ async function reconcileOverride(path, section, state, key) {
2151
+ const desired = seededContent(section);
2152
+ const desiredHash = seedHash(desired);
2110
2153
  let content;
2111
2154
  try {
2112
2155
  content = await readFile3(path, "utf-8");
2113
2156
  } catch (error) {
2114
- if (errCode(error) === "ENOENT") return;
2115
- throw error;
2157
+ if (errCode(error) !== "ENOENT") throw error;
2158
+ await writeFile3(path, desired, { encoding: "utf-8", flag: "wx" }).catch(
2159
+ (writeError) => {
2160
+ if (errCode(writeError) === "EEXIST") return;
2161
+ throw writeError;
2162
+ }
2163
+ );
2164
+ state.set(key, desiredHash);
2165
+ return;
2166
+ }
2167
+ const contentHash = seedHash(content);
2168
+ if (contentHash === desiredHash) {
2169
+ state.set(key, desiredHash);
2170
+ return;
2171
+ }
2172
+ if (isBlankOverride(content)) {
2173
+ await writeFile3(path, desired, { encoding: "utf-8" });
2174
+ state.set(key, desiredHash);
2175
+ return;
2176
+ }
2177
+ const seededHash = state.get(key);
2178
+ if (seededHash !== void 0 && contentHash === seededHash) {
2179
+ await writeFile3(path, desired, { encoding: "utf-8" });
2180
+ state.set(key, desiredHash);
2116
2181
  }
2117
- if (!isBlankOverride(content)) return;
2118
- await writeFile3(path, seededContent(section), { encoding: "utf-8" });
2119
2182
  }
2120
2183
  async function ensurePresetGuidance(homeDir) {
2121
2184
  await mkdir3(homeDir, { recursive: true });
2185
+ const seedState = await readSeedState(homeDir);
2122
2186
  await Promise.all(
2123
2187
  SEEDED_PRESETS.map(async (preset) => {
2124
2188
  const directory = join6(homeDir, preset);
2125
2189
  await mkdir3(directory, { recursive: true });
2126
- const existing = new Set(await readdir2(directory));
2127
2190
  await Promise.all(
2128
- GUIDANCE_SECTIONS2.map(async (section) => {
2129
- const path = join6(directory, section.file);
2130
- if (existing.has(section.file)) {
2131
- await healBlankOverride(path, section);
2132
- return;
2133
- }
2134
- await writeFile3(path, seededContent(section), {
2135
- encoding: "utf-8",
2136
- flag: "wx"
2137
- }).catch((error) => {
2138
- if (errCode(error) === "EEXIST") return;
2139
- throw error;
2140
- });
2141
- })
2191
+ GUIDANCE_SECTIONS2.map(
2192
+ (section) => reconcileOverride(
2193
+ join6(directory, section.file),
2194
+ section,
2195
+ seedState,
2196
+ `${preset}/${section.file}`
2197
+ )
2198
+ )
2142
2199
  );
2143
2200
  })
2144
2201
  );
@@ -2148,13 +2205,18 @@ async function ensurePresetGuidance(homeDir) {
2148
2205
  const directory = join6(homeDir, entry.name);
2149
2206
  const existing = new Set(await readdir2(directory));
2150
2207
  await Promise.all(
2151
- GUIDANCE_SECTIONS2.map(async (section) => {
2152
- if (!existing.has(section.file)) return;
2153
- await healBlankOverride(join6(directory, section.file), section);
2154
- })
2208
+ GUIDANCE_SECTIONS2.filter((section) => existing.has(section.file)).map(
2209
+ (section) => reconcileOverride(
2210
+ join6(directory, section.file),
2211
+ section,
2212
+ seedState,
2213
+ `${entry.name}/${section.file}`
2214
+ )
2215
+ )
2155
2216
  );
2156
2217
  })
2157
2218
  );
2219
+ await writeSeedState(homeDir, seedState);
2158
2220
  const homeFiles = new Set(await readdir2(homeDir));
2159
2221
  const readmes = [
2160
2222
  ["README.md", GUIDANCE_HOME_README],
@@ -7392,7 +7454,7 @@ function findEnclosingScope(root, requestedStart, requestedEnd, scopeKinds) {
7392
7454
  }
7393
7455
 
7394
7456
  // src/read-expansion/grammar-cache.ts
7395
- import { createHash } from "node:crypto";
7457
+ import { createHash as createHash2 } from "node:crypto";
7396
7458
  import { existsSync as existsSync3, mkdirSync as mkdirSync5, readFileSync as readFileSync3, renameSync as renameSync4, rmSync, writeFileSync as writeFileSync2 } from "node:fs";
7397
7459
  import { dirname as dirname7, join as join9 } from "node:path";
7398
7460
 
@@ -7482,7 +7544,7 @@ function discardCachedGrammar(path) {
7482
7544
  }
7483
7545
  }
7484
7546
  function sha256Hex(bytes) {
7485
- return createHash("sha256").update(bytes).digest("hex");
7547
+ return createHash2("sha256").update(bytes).digest("hex");
7486
7548
  }
7487
7549
  function readVerifiedCache(path, expected) {
7488
7550
  if (!existsSync3(path)) return void 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-hashline-edit",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "Hash-anchored read/apply_patch tools for DeepSeek Harness (dsh). Every line gets a unique 3- or 4-char hash (A-Za-z0-9, configurable) that stays stable across edits; apply_patch is the only file-mutation entry point and commits one patch batch per transaction. Undo persists across restarts.",
5
5
  "keywords": [
6
6
  "anchors",