dsh-hashline-edit 0.3.2 → 0.3.4

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/index.js CHANGED
@@ -1868,13 +1868,6 @@ function commandOf(args) {
1868
1868
  return typeof command === "string" && command.length > 0 ? command : void 0;
1869
1869
  }
1870
1870
 
1871
- // dsh/guidance.ts
1872
- import { readFileSync as readFileSync2, statSync as statSync2 } from "node:fs";
1873
- import { createHash } from "node:crypto";
1874
- import { mkdir as mkdir3, readFile as readFile3, readdir as readdir2, writeFile as writeFile3 } from "node:fs/promises";
1875
- import { join as join6 } from "node:path";
1876
- import { resolveDshHome } from "@deepseek-ai/dsh-home-paths";
1877
-
1878
1871
  // src/prompts.ts
1879
1872
  import { readFileSync } from "node:fs";
1880
1873
  function applyReplacements(content, replacements) {
@@ -1896,39 +1889,6 @@ function loadGuide(relativePath2, replacements) {
1896
1889
  }
1897
1890
 
1898
1891
  // dsh/guidance.ts
1899
- var PLUGIN_NAME = "dsh-hashline-edit";
1900
- function stripCR(line) {
1901
- return line.endsWith("\r") ? line.slice(0, -1) : line;
1902
- }
1903
- function startsWithFenceLine(content) {
1904
- return stripCR(content.split("\n")[0] ?? "") === "---";
1905
- }
1906
- function parseSectionFile(content) {
1907
- const lines = content.split("\n");
1908
- if (stripCR(lines[0] ?? "") !== "---") return { text: content };
1909
- const close = lines.findIndex((line, index) => index > 0 && stripCR(line) === "---");
1910
- if (close < 0) return { text: content, malformed: true, reason: "missing closing fence" };
1911
- let order;
1912
- for (let index = 1; index < close; index += 1) {
1913
- const line = stripCR(lines[index] ?? "");
1914
- if (line.trim() === "") continue;
1915
- const key = line.split(":")[0]?.trim() ?? "";
1916
- const match = /^order:\s*(-?\d+)\s*$/.exec(line);
1917
- if (match === null) {
1918
- const value = line.slice(line.indexOf(":") + 1).trim();
1919
- return key === "order" ? { text: content, malformed: true, reason: `non-integer order '${value}'` } : { text: content, malformed: true, reason: `unknown key '${key}'` };
1920
- }
1921
- order = Number.parseInt(match[1] ?? "0", 10);
1922
- }
1923
- const body = lines.slice(close + 1);
1924
- let bodyStart = 0;
1925
- while (bodyStart < body.length && (body[bodyStart] ?? "").trim() === "") bodyStart += 1;
1926
- return order === void 0 ? { text: body.slice(bodyStart).join("\n") } : { order, text: body.slice(bodyStart).join("\n") };
1927
- }
1928
- function isBlankOverride(content) {
1929
- const parsed = parseSectionFile(content);
1930
- return parsed.malformed !== true && parsed.order === void 0 && parsed.text.trim() === "" && !startsWithFenceLine(content);
1931
- }
1932
1892
  function guidanceText(intro, lines) {
1933
1893
  const bullets = lines.map((line) => `- ${line}`).join("\n");
1934
1894
  return `${intro}
@@ -1938,17 +1898,14 @@ ${bullets}`;
1938
1898
  var GUIDANCE_SECTIONS2 = [
1939
1899
  {
1940
1900
  name: "tool:read",
1941
- file: "read.md",
1942
1901
  defaultOrder: 1100,
1943
1902
  orderName: "TOOL_READ",
1944
1903
  renderDefault: () => guidanceText(loadP("../prompts/read.md"), loadGuide("../prompts/read-guidelines.md"))
1945
1904
  },
1946
1905
  {
1947
1906
  name: "tool:apply_patch",
1948
- file: "apply-patch.md",
1949
1907
  defaultOrder: 1350,
1950
1908
  orderName: "TOOL_APPLY_PATCH",
1951
- // WHY: the description and bullets are the compiled prompt sources, so the section can never disagree with the tool schema description.
1952
1909
  renderDefault: () => guidanceText(
1953
1910
  loadP("../prompts/apply-patch.md"),
1954
1911
  loadGuide("../prompts/apply-patch-guidelines.md")
@@ -1956,8 +1913,6 @@ var GUIDANCE_SECTIONS2 = [
1956
1913
  },
1957
1914
  {
1958
1915
  name: "tool:undo_last_edit",
1959
- file: "undo_last_edit.md",
1960
- // WHY: this section sits immediately after the apply_patch slot it annotates; there is no TOOL_UNDO slot.
1961
1916
  defaultOrder: 1360,
1962
1917
  renderDefault: () => guidanceText(
1963
1918
  loadP("../prompts/undo-last-edit.md"),
@@ -1966,293 +1921,11 @@ var GUIDANCE_SECTIONS2 = [
1966
1921
  }
1967
1922
  ];
1968
1923
  var SECTION_BY_NAME = new Map(GUIDANCE_SECTIONS2.map((section) => [section.name, section]));
1969
- var overrideCache = /* @__PURE__ */ new Map();
1970
- function overrideKey(path) {
1971
- try {
1972
- const stat4 = statSync2(path);
1973
- return `${stat4.mtimeMs}:${stat4.size}`;
1974
- } catch (error) {
1975
- if (errCode(error) === "ENOENT") return "missing";
1976
- throw error;
1977
- }
1978
- }
1979
- function readOverride(path) {
1980
- const key = overrideKey(path);
1981
- const cached = overrideCache.get(path);
1982
- if (cached !== void 0 && cached.key === key) return cached.content;
1983
- const content = key === "missing" ? void 0 : readFileSync2(path, "utf-8");
1984
- overrideCache.set(path, { key, content });
1985
- return content;
1986
- }
1987
- function resolveSection(name2, options) {
1988
- const section = SECTION_BY_NAME.get(name2);
1989
- if (section === void 0) throw new Error(`unknown guidance section: ${name2}`);
1990
- const defaultOrder = options.defaultOrder?.(section) ?? section.defaultOrder;
1991
- if (options.presetId === void 0) {
1992
- return { order: defaultOrder, text: section.renderDefault() };
1993
- }
1994
- const path = join6(options.homeDir, options.presetId, section.file);
1995
- const content = readOverride(path);
1996
- if (content === void 0) return { order: defaultOrder, text: section.renderDefault() };
1997
- const parsed = parseSectionFile(content);
1998
- if (parsed.malformed === true) {
1999
- return {
2000
- order: defaultOrder,
2001
- text: section.renderDefault(),
2002
- malformed: { file: path, reason: parsed.reason ?? "malformed override" }
2003
- };
2004
- }
2005
- if (isBlankOverride(content)) {
2006
- return { order: defaultOrder, text: section.renderDefault() };
2007
- }
2008
- return { order: parsed.order ?? defaultOrder, text: parsed.text };
2009
- }
2010
- function composeSections(presetId, homeDir, defaultOrder) {
2011
- return GUIDANCE_SECTIONS2.map((section) => {
2012
- const resolved = resolveSection(section.name, {
2013
- ...presetId === void 0 ? {} : { presetId },
2014
- homeDir,
2015
- ...defaultOrder === void 0 ? {} : { defaultOrder }
2016
- });
2017
- return {
2018
- name: section.name,
2019
- order: resolved.order,
2020
- text: resolved.text,
2021
- ...resolved.malformed === void 0 ? {} : { malformed: resolved.malformed }
2022
- };
2023
- });
2024
- }
2025
- var FALLBACK_PRESET_ID = "default";
2026
- var DEFAULT_PRESETS = ["standard", "ptc", "minimal", "cordis"];
2027
- var SEEDED_PRESETS = [...DEFAULT_PRESETS, FALLBACK_PRESET_ID];
2028
- var GUIDANCE_HOME_README = `# dsh-hashline-edit guidance
2029
-
2030
- Each agent preset has its own guidance directory here: \`<preset>/<section>.md\`.
2031
- On first boot the plugin seeds the shipped presets (\`standard\`, \`ptc\`,
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.
2035
-
2036
- Each file is one tool section:
2037
-
2038
- - \`read.md\` -> \`tool:read\`
2039
- - \`apply-patch.md\` -> \`tool:apply_patch\`
2040
- - \`undo_last_edit.md\` -> \`tool:undo_last_edit\`
2041
-
2042
- ## Customize
2043
-
2044
- Edit the \`<section>.md\` file for the preset and section you want to change \u2014
2045
- the file body IS the text the model reads for that section. Files are read once
2046
- per agent when it is created (\`agent/created\`), so edits apply to new sessions.
2047
-
2048
- An optional YAML front-matter fence places the section at a custom position in
2049
- the assembled system prompt:
2050
-
2051
- ---
2052
- order: 1100
2053
- ---
2054
-
2055
- <section text>
2056
-
2057
- A file without front-matter keeps the default order. A malformed fence (a
2058
- missing closing \`---\`, a non-integer \`order\`, an unknown key) falls back to the
2059
- compiled default instead of reaching the model.
2060
-
2061
- ## Fallback
2062
-
2063
- A preset with no directory here, or a missing section file, falls back to the
2064
- compiled defaults in the plugin bundle. To customize a preset that has no
2065
- seeded directory, copy a seeded one to its name. A deployment without an
2066
- agent-presets service resolves the stable \`default\` preset directory, which is
2067
- seeded here like the shipped presets.
2068
- `;
2069
- var GUIDANCE_HOME_README_ZH = `# dsh-hashline-edit \u6307\u5F15
2070
-
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
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
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
2075
-
2076
- \u6BCF\u4E2A\u6587\u4EF6\u5BF9\u5E94\u4E00\u4E2A\u5DE5\u5177\u7247\u6BB5\uFF1A
2077
-
2078
- - \`read.md\` -> \`tool:read\`
2079
- - \`apply-patch.md\` -> \`tool:apply_patch\`
2080
- - \`undo_last_edit.md\` -> \`tool:undo_last_edit\`
2081
-
2082
- ## \u81EA\u5B9A\u4E49
2083
-
2084
- \u7F16\u8F91\u4F60\u60F3\u4FEE\u6539\u7684 preset \u4E0E\u7247\u6BB5\u7684 \`<section>.md\` \u6587\u4EF6\u5373\u53EF\u2014\u2014\u6587\u4EF6\u6B63\u6587\u5C31\u662F\u8BE5\u7247\u6BB5\u5448
2085
- \u73B0\u7ED9\u6A21\u578B\u7684\u6587\u672C\u3002\u6587\u4EF6\u5728 agent \u521B\u5EFA\u65F6\uFF08\`agent/created\`\uFF09\u8BFB\u53D6\u4E00\u6B21\uFF0C\u56E0\u6B64\u4FEE\u6539\u53EA\u5F71\u54CD\u65B0\u4F1A\u8BDD\u3002
2086
-
2087
- \u53EF\u4EE5\u7528\u53EF\u9009\u7684 YAML front-matter \u6805\u680F\u628A\u7247\u6BB5\u653E\u5230\u7EC4\u88C5\u540E\u7CFB\u7EDF\u63D0\u793A\u4E2D\u7684\u81EA\u5B9A\u4E49\u4F4D\u7F6E\uFF1A
2088
-
2089
- ---
2090
- order: 1100
2091
- ---
2092
-
2093
- <\u7247\u6BB5\u6587\u672C>
2094
-
2095
- \u6CA1\u6709 front-matter \u7684\u6587\u4EF6\u4FDD\u6301\u9ED8\u8BA4\u987A\u5E8F\u3002\u683C\u5F0F\u9519\u8BEF\u7684\u6805\u680F\uFF08\u7F3A\u5C11\u6536\u5C3E \`---\`\u3001\u975E\u6574\u6570
2096
- \`order\`\u3001\u672A\u77E5\u952E\uFF09\u4F1A\u56DE\u9000\u5230\u7F16\u8BD1\u5185\u7F6E\u9ED8\u8BA4\u503C\uFF0C\u800C\u4E0D\u4F1A\u76F4\u63A5\u5448\u73B0\u7ED9\u6A21\u578B\u3002
2097
-
2098
- ## \u56DE\u9000
2099
-
2100
- \u8FD9\u91CC\u6CA1\u6709\u5BF9\u5E94\u76EE\u5F55\u7684 preset\u3001\u6216\u7F3A\u5931\u67D0\u4E2A\u7247\u6BB5\u6587\u4EF6\u65F6\uFF0C\u4F1A\u56DE\u9000\u5230\u63D2\u4EF6\u5305\u5185\u7684\u7F16\u8BD1\u5185\u7F6E\u9ED8\u8BA4
2101
- \u503C\u3002\u8981\u81EA\u5B9A\u4E49\u6CA1\u6709\u79CD\u5B50\u76EE\u5F55\u7684 preset\uFF0C\u628A\u4E00\u4E2A\u79CD\u5B50\u76EE\u5F55\u590D\u5236\u6210\u5B83\u7684\u540D\u5B57\u5373\u53EF\u3002\u6CA1\u6709
2102
- agent-presets \u670D\u52A1\u7684\u90E8\u7F72\u4F1A\u89E3\u6790\u7A33\u5B9A\u7684 \`default\` preset \u76EE\u5F55\uFF0C\u5B83\u4E5F\u4F1A\u50CF\u968F\u9644 preset
2103
- \u4E00\u6837\u5728\u8FD9\u91CC\u521D\u59CB\u5316\u3002
2104
- `;
2105
- function seededContent(section) {
2106
- return `---
2107
- order: ${section.defaultOrder}
2108
- ---
2109
-
2110
- ${section.renderDefault()}`;
2111
- }
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);
2153
- let content;
2154
- try {
2155
- content = await readFile3(path, "utf-8");
2156
- } catch (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);
2181
- }
2182
- }
2183
- async function ensurePresetGuidance(homeDir) {
2184
- await mkdir3(homeDir, { recursive: true });
2185
- const seedState = await readSeedState(homeDir);
2186
- await Promise.all(
2187
- SEEDED_PRESETS.map(async (preset) => {
2188
- const directory = join6(homeDir, preset);
2189
- await mkdir3(directory, { recursive: true });
2190
- await Promise.all(
2191
- GUIDANCE_SECTIONS2.map(
2192
- (section) => reconcileOverride(
2193
- join6(directory, section.file),
2194
- section,
2195
- seedState,
2196
- `${preset}/${section.file}`
2197
- )
2198
- )
2199
- );
2200
- })
2201
- );
2202
- const entries = await readdir2(homeDir, { withFileTypes: true });
2203
- await Promise.all(
2204
- entries.filter((entry) => entry.isDirectory() && !SEEDED_PRESETS.includes(entry.name)).map(async (entry) => {
2205
- const directory = join6(homeDir, entry.name);
2206
- const existing = new Set(await readdir2(directory));
2207
- await Promise.all(
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
- )
2216
- );
2217
- })
2218
- );
2219
- await writeSeedState(homeDir, seedState);
2220
- const homeFiles = new Set(await readdir2(homeDir));
2221
- const readmes = [
2222
- ["README.md", GUIDANCE_HOME_README],
2223
- ["README.zh.md", GUIDANCE_HOME_README_ZH]
2224
- ];
2225
- await Promise.all(
2226
- readmes.map(async ([file, content]) => {
2227
- if (homeFiles.has(file)) return;
2228
- await writeFile3(join6(homeDir, file), content, { encoding: "utf-8", flag: "wx" }).catch(
2229
- (error) => {
2230
- if (errCode(error) === "EEXIST") return;
2231
- throw error;
2232
- }
2233
- );
2234
- })
2235
- );
2236
- }
2237
- function guidanceHomeDir(env = process.env) {
2238
- return join6(resolveDshHome(void 0, env), "plugins", PLUGIN_NAME, "guidance");
2239
- }
2240
1924
  function registryFor(ctx) {
2241
1925
  const candidate = ctx.systemPrompt;
2242
1926
  if (candidate === void 0 || typeof candidate.section !== "function") return void 0;
2243
1927
  return candidate;
2244
1928
  }
2245
- function presetIdFor(rootCtx, agentCtx) {
2246
- const get = rootCtx.get;
2247
- if (typeof get !== "function") return void 0;
2248
- const service = get.call(rootCtx, "agentPresets");
2249
- if (service === void 0 || typeof service.composedPreset !== "function") return void 0;
2250
- try {
2251
- return service.composedPreset(agentCtx);
2252
- } catch {
2253
- return void 0;
2254
- }
2255
- }
2256
1929
  function warn2(rootCtx, message) {
2257
1930
  const logger = rootCtx.logger;
2258
1931
  if (typeof logger?.warn === "function") logger.warn(`dsh-hashline-edit: ${message}`);
@@ -2270,37 +1943,6 @@ function orderResolver(registry) {
2270
1943
  }
2271
1944
  };
2272
1945
  }
2273
- function compiledSections(orderFor) {
2274
- return GUIDANCE_SECTIONS2.map((section) => ({
2275
- name: section.name,
2276
- order: orderFor(section),
2277
- text: section.renderDefault()
2278
- }));
2279
- }
2280
- function resolveSectionText(rootCtx, section, presetId, homeDir, orderFor, warned) {
2281
- try {
2282
- const resolved = resolveSection(section.name, { presetId, homeDir, defaultOrder: orderFor });
2283
- const malformed = resolved.malformed;
2284
- if (malformed !== void 0 && !warned.has(malformed.file)) {
2285
- warned.add(malformed.file);
2286
- warn2(
2287
- rootCtx,
2288
- `ignoring malformed guidance override ${malformed.file}: ${malformed.reason}; using compiled default`
2289
- );
2290
- }
2291
- return resolved.text;
2292
- } catch (error) {
2293
- const file = join6(homeDir, presetId, section.file);
2294
- if (!warned.has(file)) {
2295
- warned.add(file);
2296
- warn2(
2297
- rootCtx,
2298
- `guidance section ${section.name} could not be re-read; using compiled default: ${error instanceof Error ? error.message : String(error)}`
2299
- );
2300
- }
2301
- return section.renderDefault();
2302
- }
2303
- }
2304
1946
  function sectionEnabled(name2, toggles) {
2305
1947
  if (toggles === void 0) return true;
2306
1948
  if (name2 === "tool:read") return toggles.read;
@@ -2316,42 +1958,15 @@ function registerGuidanceSections(rootCtx, agentCtx, enabled) {
2316
1958
  };
2317
1959
  }
2318
1960
  const orderFor = orderResolver(registry);
2319
- const presetId = presetIdFor(rootCtx, agentCtx) ?? FALLBACK_PRESET_ID;
2320
- const homeDir = guidanceHomeDir();
2321
- void ensurePresetGuidance(homeDir).catch((error) => {
2322
- warn2(
2323
- rootCtx,
2324
- `guidance materialization failed for ${homeDir}: ${error instanceof Error ? error.message : String(error)}`
2325
- );
2326
- });
2327
- let sections;
2328
- try {
2329
- sections = composeSections(presetId, homeDir, orderFor);
2330
- } catch (error) {
2331
- warn2(
2332
- rootCtx,
2333
- `guidance resolution failed; using compiled defaults: ${error instanceof Error ? error.message : String(error)}`
2334
- );
2335
- sections = compiledSections(orderFor);
2336
- }
2337
1961
  const disposers = [];
2338
- const warned = /* @__PURE__ */ new Set();
2339
- for (let index = 0; index < sections.length; index++) {
2340
- const section = sections[index];
2341
- const definition = GUIDANCE_SECTIONS2[index];
2342
- if (!sectionEnabled(definition.name, enabled)) continue;
2343
- if (section.malformed !== void 0) {
2344
- warn2(
2345
- rootCtx,
2346
- `ignoring malformed guidance override ${section.malformed.file}: ${section.malformed.reason}; using compiled default`
2347
- );
2348
- }
1962
+ for (const section of GUIDANCE_SECTIONS2) {
1963
+ if (!sectionEnabled(section.name, enabled)) continue;
2349
1964
  try {
2350
1965
  disposers.push(
2351
1966
  registry.section({
2352
1967
  name: section.name,
2353
- order: section.order,
2354
- text: () => resolveSectionText(rootCtx, definition, presetId, homeDir, orderFor, warned)
1968
+ order: orderFor(section),
1969
+ text: section.renderDefault()
2355
1970
  })
2356
1971
  );
2357
1972
  } catch (error) {
@@ -3123,9 +2738,9 @@ import { isAbsolute as isAbsolute5, resolve as resolvePath } from "node:path";
3123
2738
 
3124
2739
  // src/hash-store.ts
3125
2740
  import { closeSync, existsSync as existsSync2, fstatSync, openSync, readSync } from "node:fs";
3126
- import { rename as rename3, mkdir as mkdir4 } from "node:fs/promises";
2741
+ import { rename as rename3, mkdir as mkdir3 } from "node:fs/promises";
3127
2742
  import { DatabaseSync } from "node:sqlite";
3128
- import { join as join7, dirname as dirname5 } from "node:path";
2743
+ import { join as join6, dirname as dirname5 } from "node:path";
3129
2744
 
3130
2745
  // src/store-kernel/constants.ts
3131
2746
  var HASH_STORE_BUSY_TIMEOUT = 250;
@@ -3253,15 +2868,15 @@ function markRun(db, key, now) {
3253
2868
 
3254
2869
  // src/hash-store.ts
3255
2870
  function hashStorePath() {
3256
- return join7(stateRoot(), "hash-store.sqlite");
2871
+ return join6(stateRoot(), "hash-store.sqlite");
3257
2872
  }
3258
2873
  function legacyHashStorePath() {
3259
- return join7(stateRoot(), "hash-store.json");
2874
+ return join6(stateRoot(), "hash-store.json");
3260
2875
  }
3261
2876
  async function ensureStateRoot() {
3262
2877
  const root = stateRoot();
3263
2878
  try {
3264
- await mkdir4(root, { recursive: true });
2879
+ await mkdir3(root, { recursive: true });
3265
2880
  } catch {
3266
2881
  throw new DomainError("E_ACCESS", { path: root, kind: "denied", access: "write" });
3267
2882
  }
@@ -5655,7 +5270,7 @@ function deleteVacuumSnapshots(db, snapshotIds) {
5655
5270
  }
5656
5271
 
5657
5272
  // src/snapshot-store/migrate.ts
5658
- import { readFile as readFile4, rename as rename4 } from "node:fs/promises";
5273
+ import { readFile as readFile3, rename as rename4 } from "node:fs/promises";
5659
5274
  function isValidSnapshot(value) {
5660
5275
  if (typeof value !== "object" || value === null) return false;
5661
5276
  const v = value;
@@ -5666,7 +5281,7 @@ async function migrateLegacyStore(db) {
5666
5281
  const legacyPath = legacyHashStorePath();
5667
5282
  let content;
5668
5283
  try {
5669
- content = await readFile4(legacyPath, "utf-8");
5284
+ content = await readFile3(legacyPath, "utf-8");
5670
5285
  } catch (error) {
5671
5286
  if (errCode(error) === "ENOENT") return;
5672
5287
  reportDiagnostic("snapshot-store", "Failed to read legacy hash store for migration:", error);
@@ -7372,12 +6987,12 @@ function planWindows(target, resolver) {
7372
6987
  }
7373
6988
 
7374
6989
  // src/read-expansion/audit.ts
7375
- import { appendFileSync as appendFileSync3, mkdirSync as mkdirSync4, renameSync as renameSync3, statSync as statSync3 } from "node:fs";
7376
- import { dirname as dirname6, join as join8 } from "node:path";
6990
+ import { appendFileSync as appendFileSync3, mkdirSync as mkdirSync4, renameSync as renameSync3, statSync as statSync2 } from "node:fs";
6991
+ import { dirname as dirname6, join as join7 } from "node:path";
7377
6992
  var READ_EXPANSION_LOG_NAME = "read-expansion.log";
7378
6993
  var READ_EXPANSION_LOG_MAX_BYTES = 1024 * 1024;
7379
6994
  function readExpansionLogPath() {
7380
- return join8(stateRoot(), READ_EXPANSION_LOG_NAME);
6995
+ return join7(stateRoot(), READ_EXPANSION_LOG_NAME);
7381
6996
  }
7382
6997
  var rungRecordedSessions = /* @__PURE__ */ new Set();
7383
6998
  var runtimeAbsentSessions = /* @__PURE__ */ new Set();
@@ -7415,7 +7030,7 @@ function appendRecord2(fields) {
7415
7030
  function rotateIfOversize2(path, incomingBytes) {
7416
7031
  let current = 0;
7417
7032
  try {
7418
- current = statSync3(path).size;
7033
+ current = statSync2(path).size;
7419
7034
  } catch {
7420
7035
  return;
7421
7036
  }
@@ -7425,7 +7040,7 @@ function rotateIfOversize2(path, incomingBytes) {
7425
7040
 
7426
7041
  // src/read-expansion/ast-provider.ts
7427
7042
  import { readdirSync as readdirSync2 } from "node:fs";
7428
- import { readFile as readFile5 } from "node:fs/promises";
7043
+ import { readFile as readFile4 } from "node:fs/promises";
7429
7044
 
7430
7045
  // src/read-expansion/ast-span.ts
7431
7046
  function scopeLineRange(node) {
@@ -7454,9 +7069,9 @@ function findEnclosingScope(root, requestedStart, requestedEnd, scopeKinds) {
7454
7069
  }
7455
7070
 
7456
7071
  // src/read-expansion/grammar-cache.ts
7457
- import { createHash as createHash2 } from "node:crypto";
7458
- import { existsSync as existsSync3, mkdirSync as mkdirSync5, readFileSync as readFileSync3, renameSync as renameSync4, rmSync, writeFileSync as writeFileSync2 } from "node:fs";
7459
- import { dirname as dirname7, join as join9 } from "node:path";
7072
+ import { createHash } from "node:crypto";
7073
+ import { existsSync as existsSync3, mkdirSync as mkdirSync5, readFileSync as readFileSync2, renameSync as renameSync4, rmSync, writeFileSync as writeFileSync2 } from "node:fs";
7074
+ import { dirname as dirname7, join as join8 } from "node:path";
7460
7075
 
7461
7076
  // src/read-expansion/grammar-manifest.ts
7462
7077
  var GRAMMAR_MANIFEST = {
@@ -7529,10 +7144,10 @@ var FETCH_HARD_TIMEOUT_MS = 3e4;
7529
7144
  var COLD = /* @__PURE__ */ Symbol("cold");
7530
7145
  var inFlight = /* @__PURE__ */ new Map();
7531
7146
  function grammarCacheRoot(root) {
7532
- return root ?? join9(stateRoot(), "grammars");
7147
+ return root ?? join8(stateRoot(), "grammars");
7533
7148
  }
7534
7149
  function grammarCachePath(language, entry, cacheRoot) {
7535
- return join9(
7150
+ return join8(
7536
7151
  grammarCacheRoot(cacheRoot),
7537
7152
  `${language}-${entry.version}-${entry.sha256.slice(0, 16)}.wasm`
7538
7153
  );
@@ -7544,13 +7159,13 @@ function discardCachedGrammar(path) {
7544
7159
  }
7545
7160
  }
7546
7161
  function sha256Hex(bytes) {
7547
- return createHash2("sha256").update(bytes).digest("hex");
7162
+ return createHash("sha256").update(bytes).digest("hex");
7548
7163
  }
7549
7164
  function readVerifiedCache(path, expected) {
7550
7165
  if (!existsSync3(path)) return void 0;
7551
7166
  let bytes;
7552
7167
  try {
7553
- bytes = readFileSync3(path);
7168
+ bytes = readFileSync2(path);
7554
7169
  } catch {
7555
7170
  discardCachedGrammar(path);
7556
7171
  return void 0;
@@ -7942,7 +7557,7 @@ function isOffsetWindow(window) {
7942
7557
  }
7943
7558
  async function defaultReadText(path) {
7944
7559
  try {
7945
- return await readFile5(path, "utf-8");
7560
+ return await readFile4(path, "utf-8");
7946
7561
  } catch {
7947
7562
  return void 0;
7948
7563
  }
@@ -8093,7 +7708,7 @@ function createAstSpanProvider(options = {}) {
8093
7708
  }
8094
7709
 
8095
7710
  // src/read-expansion/markdown-provider.ts
8096
- import { readFile as readFile6 } from "node:fs/promises";
7711
+ import { readFile as readFile5 } from "node:fs/promises";
8097
7712
 
8098
7713
  // src/read-expansion/text-lines.ts
8099
7714
  function splitVisibleLines(text) {
@@ -8190,7 +7805,7 @@ function isMarkdownPath(path) {
8190
7805
  }
8191
7806
  async function defaultReadText2(path) {
8192
7807
  try {
8193
- return await readFile6(path, "utf-8");
7808
+ return await readFile5(path, "utf-8");
8194
7809
  } catch {
8195
7810
  return void 0;
8196
7811
  }
@@ -8217,7 +7832,7 @@ function createMarkdownSpanProvider(options = {}) {
8217
7832
  }
8218
7833
 
8219
7834
  // src/read-expansion/bash-provider.ts
8220
- import { readFile as readFile7 } from "node:fs/promises";
7835
+ import { readFile as readFile6 } from "node:fs/promises";
8221
7836
 
8222
7837
  // src/read-expansion/line-arithmetic.ts
8223
7838
  function lineBreaksIn(text, endExclusive) {
@@ -8263,7 +7878,7 @@ function isShellPath(path) {
8263
7878
  }
8264
7879
  async function defaultReadText3(path) {
8265
7880
  try {
8266
- return await readFile7(path, "utf-8");
7881
+ return await readFile6(path, "utf-8");
8267
7882
  } catch {
8268
7883
  return void 0;
8269
7884
  }
@@ -8344,7 +7959,7 @@ function createBashSpanProvider(options = {}) {
8344
7959
  }
8345
7960
 
8346
7961
  // src/read-expansion/paragraph-provider.ts
8347
- import { readFile as readFile8 } from "node:fs/promises";
7962
+ import { readFile as readFile7 } from "node:fs/promises";
8348
7963
 
8349
7964
  // src/read-expansion/paragraph-section.ts
8350
7965
  function findParagraph(text, requestedStart, requestedEnd) {
@@ -8385,7 +8000,7 @@ function isDataPath(path) {
8385
8000
  }
8386
8001
  async function defaultReadText4(path) {
8387
8002
  try {
8388
- return await readFile8(path, "utf-8");
8003
+ return await readFile7(path, "utf-8");
8389
8004
  } catch {
8390
8005
  return void 0;
8391
8006
  }
@@ -8830,15 +8445,15 @@ import {
8830
8445
  constants as constants5,
8831
8446
  existsSync as existsSync4,
8832
8447
  mkdirSync as mkdirSync6,
8833
- readFileSync as readFileSync4,
8448
+ readFileSync as readFileSync3,
8834
8449
  renameSync as renameSync5,
8835
8450
  unlinkSync as unlinkSync2,
8836
8451
  writeFileSync as writeFileSync3
8837
8452
  } from "node:fs";
8838
- import { dirname as dirname8, join as join10, sep as sep3 } from "node:path";
8453
+ import { dirname as dirname8, join as join9, sep as sep3 } from "node:path";
8839
8454
  var CONFIG_SCHEMA_ID = "https://github.com/Rianico/pi-better-edit/schemas/pi-better-edit.json";
8840
8455
  function configFilePath(scope, cwd) {
8841
- return scope === "global" ? join10(settingsRoot(), SETTINGS_FILE_NAME) : join10(cwd, PROJECT_SETTINGS_REL);
8456
+ return scope === "global" ? join9(settingsRoot(), SETTINGS_FILE_NAME) : join9(cwd, PROJECT_SETTINGS_REL);
8842
8457
  }
8843
8458
  function readScopeConfig(scope, cwd, onWarn) {
8844
8459
  const path = configFilePath(scope, cwd);
@@ -8902,7 +8517,7 @@ function reasonOf2(error) {
8902
8517
  function readConfigObject(path, onWarn) {
8903
8518
  let raw;
8904
8519
  try {
8905
- raw = readFileSync4(path, "utf-8");
8520
+ raw = readFileSync3(path, "utf-8");
8906
8521
  } catch (error) {
8907
8522
  if (!isMissingFile(error)) onWarn?.(`cannot read config ${path}: ${reasonOf2(error)}`);
8908
8523
  return void 0;
@@ -1,35 +1,25 @@
1
- import type { Context } from "@deepseek-ai/cordis";
2
- /** The parsed content of one override file. */
3
- export interface ParsedSection {
4
- /** Front-matter `order`, when present and valid. */
5
- order?: number;
6
- /** The section text: the file body, or the whole file when no fence is present. */
7
- text: string;
8
- /** True when a leading `---` fence is present but does not parse. */
9
- malformed?: boolean;
10
- /** Human-readable parse reason, present only when `malformed` is true. */
11
- reason?: string;
12
- }
13
- /**
14
- * Parse an override file. Only a leading `---` fence whose lines are empty or
15
- * `order: <integer>` is accepted; anything else is pure prose (the whole file
16
- * as text). A leading `---` that does not parse (no closing fence, unknown
17
- * key, non-integer value) is malformed and must resolve to the compiled default.
18
- */
19
- export declare function parseSectionFile(content: string): ParsedSection;
20
1
  /**
21
- * True when an override file is blank: whitespace-only body and no front-matter
22
- * fence. This is the "I want the default" spelling, so a boot-time heal
23
- * re-seeds such a file; a valid fence (even keyless) is a deliberate blank and
24
- * is left alone, as is a malformed file whose body may be salvageable.
2
+ * Hashline guidance sections for the dsh host layer.
3
+ *
4
+ * Three prompt sections are owned here — `tool:read`, `tool:apply_patch` and
5
+ * `tool:undo_last_edit` — because the hashline tools shadow the preset's
6
+ * built-ins and must bring their own brief. The compiled default text IS the
7
+ * pi-side guidance (`prompts/*.md`) loaded through `src/prompts.ts`, so the dsh
8
+ * and pi hosts cannot drift about the tool contract.
9
+ *
10
+ * Injection is STATIC: each section registers its bundled default text once, the
11
+ * same way the agent-teams plugin registers its constant `systemPrompt` section.
12
+ * There are no runtime user-override files and no per-step re-resolution — the
13
+ * guidance a session sees is exactly what the installed bundle ships, so the
14
+ * single control point is `prompts/*.md` + a rebuild/upgrade.
15
+ *
16
+ * @module dsh-hashline-edit/guidance
25
17
  */
26
- export declare function isBlankOverride(content: string): boolean;
18
+ import type { Context } from "@deepseek-ai/cordis";
27
19
  /** One overridable tool section. */
28
20
  export interface GuidanceSection {
29
21
  /** Registry section name, e.g. `tool:apply_patch`. */
30
22
  readonly name: string;
31
- /** Override file name inside a preset directory, e.g. `apply-patch.md`. */
32
- readonly file: string;
33
23
  /** Order used when the harness registry names no slot for this section. */
34
24
  readonly defaultOrder: number;
35
25
  /** The `systemPrompt.getSectionOrder` slot this section shadows, when one exists. */
@@ -37,89 +27,22 @@ export interface GuidanceSection {
37
27
  /** The compiled default text. */
38
28
  renderDefault(): string;
39
29
  }
40
- /**
41
- * The three sections, in default-order sequence. Read and undo reuse the pi
42
- * host's prompt sources; apply_patch owns the v4 mutation guidance.
43
- */
30
+ /** The three sections, in default-order sequence. */
44
31
  export declare const GUIDANCE_SECTIONS: readonly GuidanceSection[];
45
32
  /** Render the compiled default text for one section. */
46
33
  export declare function renderSectionDefault(name: string): string;
47
- /** One resolved section, ready for the systemPrompt registry. */
48
- export interface SectionOverride {
49
- readonly name: string;
50
- readonly order: number;
51
- readonly text: string;
52
- /** Set when the override file was malformed and the compiled default was used. */
53
- readonly malformed?: {
54
- readonly file: string;
55
- readonly reason: string;
56
- };
57
- }
58
- /** Options for resolving one section's guidance. */
59
- export interface ResolveGuidanceOptions {
60
- /** Agent preset id, or undefined to skip the preset layer. */
61
- presetId?: string;
62
- /** Plugin guidance home (`<DSH_HOME>/plugins/dsh-hashline-edit/guidance`). */
63
- homeDir: string;
64
- /** Live harness slot for a section, when the registry exposes one. */
65
- defaultOrder?: (section: GuidanceSection) => number;
66
- }
67
- /** The resolved text and order for one section. */
68
- export interface GuidanceResolution {
69
- readonly order: number;
70
- readonly text: string;
71
- /** Set when the override file was malformed and the compiled default was used. */
72
- readonly malformed?: {
73
- readonly file: string;
74
- readonly reason: string;
75
- };
76
- }
77
- /**
78
- * Resolve one section: the preset override file wins when it exists; a blank
79
- * file advances to the compiled default; a malformed file resolves to the
80
- * compiled default and reports itself; any other read error propagates.
81
- */
82
- export declare function resolveSection(name: string, options: ResolveGuidanceOptions): GuidanceResolution;
83
- /** Resolve all three sections for a preset (`undefined` = the compiled defaults). */
84
- export declare function composeSections(presetId: string | undefined, homeDir: string, defaultOrder?: (section: GuidanceSection) => number): SectionOverride[];
85
- /**
86
- * The stable preset id used when the composition exposes no `agentPresets`
87
- * service (or resolves no preset): the override surface must still exist for a
88
- * deployment that shadows the tools without the preset machinery. It never
89
- * collides with a harness preset name, so a deployment that later mounts
90
- * `agentPresets` keeps its own directories untouched.
91
- */
92
- export declare const FALLBACK_PRESET_ID = "default";
93
- /** The presets shipped by the dsh harness, each seeded with editable guidance. */
94
- export declare const DEFAULT_PRESETS: readonly string[];
95
- /**
96
- * Materialize the per-preset guidance home: seed the shipped presets and the
97
- * `default` fallback, heal blank files in every existing preset directory, and
98
- * write the READMEs.
99
- * Idempotent and concurrency-safe (`wx`), so a user-edited file always wins.
100
- * Custom preset directories present on disk are healed like the shipped ones
101
- * but never fabricated.
102
- */
103
- export declare function ensurePresetGuidance(homeDir: string): Promise<void>;
104
- /** The plugin guidance home: `<DSH_HOME>/plugins/dsh-hashline-edit/guidance`. */
105
- export declare function guidanceHomeDir(env?: Record<string, string | undefined>): string;
106
- /**
107
- * Register the three hashline guidance sections on one agent's own scope layer,
108
- * shadowing the preset's built-in tool guidance. The seam is synchronous (it
109
- * returns the exact disposer for the agent effect): override files are read
110
- * synchronously at agent creation.
111
- *
112
- * Override materialization is kicked off here (idempotently, once per agent
113
- * install). A composition without an `agentPresets` service resolves the stable
114
- * `default` preset, so its override files still seed and resolve; a composed
115
- * preset keeps winning whenever the service names one. The compiled defaults
116
- * come from the shared prompt sources, so the plugin package must ship
117
- * `prompts/` for them to load.
118
- */
119
- /** Which feature tools are enabled, so a disabled tool's guidance section is not registered. */
34
+ /** Which sections to register: all enabled when no toggles are passed. */
120
35
  export interface GuidanceToggles {
121
36
  readonly read: boolean;
122
37
  readonly applyPatch: boolean;
123
38
  readonly undo: boolean;
124
39
  }
40
+ /**
41
+ * Register the enabled guidance sections with STATIC bundled text.
42
+ *
43
+ * WHY static: the guidance is part of the plugin bundle, injected once per agent
44
+ * the same way the agent-teams plugin registers its constant `systemPrompt`
45
+ * section. There is no override file to read and no per-step re-resolution, so the
46
+ * text a session sees is exactly what the installed version ships.
47
+ */
125
48
  export declare function registerGuidanceSections(rootCtx: Context, agentCtx: Context, enabled?: GuidanceToggles): () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-hashline-edit",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
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",
@@ -79,7 +79,6 @@
79
79
  "@deepseek-ai/cordis": "4.1.0",
80
80
  "@deepseek-ai/dsh-agent": "0.2.2-rc.1",
81
81
  "@deepseek-ai/dsh-fs": "0.2.2-rc.1",
82
- "@deepseek-ai/dsh-home-paths": "0.2.2-rc.1",
83
82
  "@deepseek-ai/dsh-sandbox": "0.2.2-rc.1",
84
83
  "@deepseek-ai/dsh-tools": "0.2.2-rc.1",
85
84
  "@deepseek-ai/schemastery": "3.19.0",
@@ -104,7 +103,6 @@
104
103
  "@deepseek-ai/cordis": "~4.1.0",
105
104
  "@deepseek-ai/dsh-agent": ">=0.2.2-rc.1 <0.2.3-0",
106
105
  "@deepseek-ai/dsh-fs": ">=0.2.2-rc.1 <0.2.3-0",
107
- "@deepseek-ai/dsh-home-paths": ">=0.2.2-rc.1 <0.2.3-0",
108
106
  "@deepseek-ai/dsh-sandbox": ">=0.2.2-rc.1 <0.2.3-0",
109
107
  "@deepseek-ai/dsh-tools": ">=0.2.2-rc.1 <0.2.3-0"
110
108
  },