dsh-hashline-edit 0.3.3 → 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,310 +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. Every preset the
2035
- deployment declares is seeded automatically, including ones added after first boot.
2036
-
2037
- Each file is one tool section:
2038
-
2039
- - \`read.md\` -> \`tool:read\`
2040
- - \`apply-patch.md\` -> \`tool:apply_patch\`
2041
- - \`undo_last_edit.md\` -> \`tool:undo_last_edit\`
2042
-
2043
- ## Customize
2044
-
2045
- Edit the \`<section>.md\` file for the preset and section you want to change \u2014
2046
- the file body IS the text the model reads for that section. Files are read once
2047
- per agent when it is created (\`agent/created\`), so edits apply to new sessions.
2048
-
2049
- An optional YAML front-matter fence places the section at a custom position in
2050
- the assembled system prompt:
2051
-
2052
- ---
2053
- order: 1100
2054
- ---
2055
-
2056
- <section text>
2057
-
2058
- A file without front-matter keeps the default order. A malformed fence (a
2059
- missing closing \`---\`, a non-integer \`order\`, an unknown key) falls back to the
2060
- compiled default instead of reaching the model.
2061
-
2062
- ## Fallback
2063
-
2064
- A preset with no directory here, or a missing section file, falls back to the
2065
- compiled defaults in the plugin bundle. To customize a preset that has no
2066
- seeded directory, copy a seeded one to its name. A deployment without an
2067
- agent-presets service resolves the stable \`default\` preset directory, which is
2068
- seeded here like the shipped presets.
2069
- `;
2070
- var GUIDANCE_HOME_README_ZH = `# dsh-hashline-edit \u6307\u5F15
2071
-
2072
- \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
2073
- \u63D2\u4EF6\u4F1A\u4E3A\u968F\u9644\u7684 preset\uFF08\`standard\`\u3001\`ptc\`\u3001\`minimal\`\u3001\`cordis\`\uFF09\u5199\u5165\u7F16\u8BD1\u5185\u7F6E\u7684
2074
- \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
2075
- \u7A7A\u767D\u6587\u4EF6\u5219\u56DE\u9000\u5230\u9ED8\u8BA4\u5185\u5BB9\u3002\u4E4B\u540E\u65B0\u589E\u7684\u9884\u8BBE\u4F1A\u5728\u4E0B\u6B21\u52A0\u8F7D\u65F6\u81EA\u52A8\u79CD\u5B50\u3002
2076
-
2077
- \u6BCF\u4E2A\u6587\u4EF6\u5BF9\u5E94\u4E00\u4E2A\u5DE5\u5177\u7247\u6BB5\uFF1A
2078
-
2079
- - \`read.md\` -> \`tool:read\`
2080
- - \`apply-patch.md\` -> \`tool:apply_patch\`
2081
- - \`undo_last_edit.md\` -> \`tool:undo_last_edit\`
2082
-
2083
- ## \u81EA\u5B9A\u4E49
2084
-
2085
- \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
2086
- \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
2087
-
2088
- \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
2089
-
2090
- ---
2091
- order: 1100
2092
- ---
2093
-
2094
- <\u7247\u6BB5\u6587\u672C>
2095
-
2096
- \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
2097
- \`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
2098
-
2099
- ## \u56DE\u9000
2100
-
2101
- \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
2102
- \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
2103
- 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
2104
- \u4E00\u6837\u5728\u8FD9\u91CC\u521D\u59CB\u5316\u3002
2105
- `;
2106
- function seededContent(section) {
2107
- return `---
2108
- order: ${section.defaultOrder}
2109
- ---
2110
-
2111
- ${section.renderDefault()}`;
2112
- }
2113
- var SEED_STATE_FILE = ".seeded.json";
2114
- function seedHash(value) {
2115
- return createHash("sha256").update(value, "utf-8").digest("hex");
2116
- }
2117
- async function readSeedState(homeDir) {
2118
- const state = /* @__PURE__ */ new Map();
2119
- try {
2120
- const parsed = JSON.parse(await readFile3(join6(homeDir, SEED_STATE_FILE), "utf-8"));
2121
- const files = parsed?.files;
2122
- if (files !== null && typeof files === "object") {
2123
- for (const [key, value] of Object.entries(files)) {
2124
- if (typeof value === "string") state.set(key, value);
2125
- }
2126
- }
2127
- } catch {
2128
- }
2129
- return state;
2130
- }
2131
- async function writeSeedState(homeDir, state) {
2132
- const merged = {};
2133
- try {
2134
- const parsed = JSON.parse(await readFile3(join6(homeDir, SEED_STATE_FILE), "utf-8"));
2135
- const files = parsed?.files;
2136
- if (files !== null && typeof files === "object") {
2137
- for (const [key, value] of Object.entries(files)) {
2138
- if (typeof value === "string") merged[key] = value;
2139
- }
2140
- }
2141
- } catch {
2142
- }
2143
- for (const [key, value] of state) merged[key] = value;
2144
- await writeFile3(
2145
- join6(homeDir, SEED_STATE_FILE),
2146
- `${JSON.stringify({ version: 1, files: merged }, null, 2)}
2147
- `,
2148
- { encoding: "utf-8" }
2149
- );
2150
- }
2151
- async function reconcileOverride(path, section, state, key) {
2152
- const desired = seededContent(section);
2153
- const desiredHash = seedHash(desired);
2154
- let content;
2155
- try {
2156
- content = await readFile3(path, "utf-8");
2157
- } catch (error) {
2158
- if (errCode(error) !== "ENOENT") throw error;
2159
- await writeFile3(path, desired, { encoding: "utf-8", flag: "wx" }).catch(
2160
- (writeError) => {
2161
- if (errCode(writeError) === "EEXIST") return;
2162
- throw writeError;
2163
- }
2164
- );
2165
- state.set(key, desiredHash);
2166
- return;
2167
- }
2168
- const contentHash = seedHash(content);
2169
- if (contentHash === desiredHash) {
2170
- state.set(key, desiredHash);
2171
- return;
2172
- }
2173
- if (isBlankOverride(content)) {
2174
- await writeFile3(path, desired, { encoding: "utf-8" });
2175
- state.set(key, desiredHash);
2176
- return;
2177
- }
2178
- const seededHash = state.get(key);
2179
- if (seededHash !== void 0 && contentHash === seededHash) {
2180
- await writeFile3(path, desired, { encoding: "utf-8" });
2181
- state.set(key, desiredHash);
2182
- }
2183
- }
2184
- async function ensurePresetGuidance(homeDir, discoverPresets) {
2185
- await mkdir3(homeDir, { recursive: true });
2186
- const seedState = await readSeedState(homeDir);
2187
- const seededPresets = new Set(SEEDED_PRESETS);
2188
- if (discoverPresets !== void 0) {
2189
- for (const id of await discoverPresets()) seededPresets.add(id);
2190
- }
2191
- await Promise.all(
2192
- Array.from(seededPresets).map(async (preset) => {
2193
- const directory = join6(homeDir, preset);
2194
- await mkdir3(directory, { recursive: true });
2195
- await Promise.all(
2196
- GUIDANCE_SECTIONS2.map(
2197
- (section) => reconcileOverride(
2198
- join6(directory, section.file),
2199
- section,
2200
- seedState,
2201
- `${preset}/${section.file}`
2202
- )
2203
- )
2204
- );
2205
- })
2206
- );
2207
- const entries = await readdir2(homeDir, { withFileTypes: true });
2208
- await Promise.all(
2209
- entries.filter((entry) => entry.isDirectory() && !seededPresets.has(entry.name)).map(async (entry) => {
2210
- const directory = join6(homeDir, entry.name);
2211
- const existing = new Set(await readdir2(directory));
2212
- await Promise.all(
2213
- GUIDANCE_SECTIONS2.filter((section) => existing.has(section.file)).map(
2214
- (section) => reconcileOverride(
2215
- join6(directory, section.file),
2216
- section,
2217
- seedState,
2218
- `${entry.name}/${section.file}`
2219
- )
2220
- )
2221
- );
2222
- })
2223
- );
2224
- await writeSeedState(homeDir, seedState);
2225
- const homeFiles = new Set(await readdir2(homeDir));
2226
- const readmes = [
2227
- ["README.md", GUIDANCE_HOME_README],
2228
- ["README.zh.md", GUIDANCE_HOME_README_ZH]
2229
- ];
2230
- await Promise.all(
2231
- readmes.map(async ([file, content]) => {
2232
- if (homeFiles.has(file)) return;
2233
- await writeFile3(join6(homeDir, file), content, { encoding: "utf-8", flag: "wx" }).catch(
2234
- (error) => {
2235
- if (errCode(error) === "EEXIST") return;
2236
- throw error;
2237
- }
2238
- );
2239
- })
2240
- );
2241
- }
2242
- async function readPresetIds(rootCtx) {
2243
- const get = rootCtx.get;
2244
- if (typeof get !== "function") return [];
2245
- const service = get.call(rootCtx, "agentPresets");
2246
- if (service === void 0 || typeof service.list !== "function") return [];
2247
- try {
2248
- const rows = await service.list();
2249
- return rows.map((row) => row.id).filter((id) => typeof id === "string" && id.length > 0);
2250
- } catch {
2251
- return [];
2252
- }
2253
- }
2254
- function guidanceHomeDir(env = process.env) {
2255
- return join6(resolveDshHome(void 0, env), "plugins", PLUGIN_NAME, "guidance");
2256
- }
2257
1924
  function registryFor(ctx) {
2258
1925
  const candidate = ctx.systemPrompt;
2259
1926
  if (candidate === void 0 || typeof candidate.section !== "function") return void 0;
2260
1927
  return candidate;
2261
1928
  }
2262
- function presetIdFor(rootCtx, agentCtx) {
2263
- const get = rootCtx.get;
2264
- if (typeof get !== "function") return void 0;
2265
- const service = get.call(rootCtx, "agentPresets");
2266
- if (service === void 0 || typeof service.composedPreset !== "function") return void 0;
2267
- try {
2268
- return service.composedPreset(agentCtx);
2269
- } catch {
2270
- return void 0;
2271
- }
2272
- }
2273
1929
  function warn2(rootCtx, message) {
2274
1930
  const logger = rootCtx.logger;
2275
1931
  if (typeof logger?.warn === "function") logger.warn(`dsh-hashline-edit: ${message}`);
@@ -2287,37 +1943,6 @@ function orderResolver(registry) {
2287
1943
  }
2288
1944
  };
2289
1945
  }
2290
- function compiledSections(orderFor) {
2291
- return GUIDANCE_SECTIONS2.map((section) => ({
2292
- name: section.name,
2293
- order: orderFor(section),
2294
- text: section.renderDefault()
2295
- }));
2296
- }
2297
- function resolveSectionText(rootCtx, section, presetId, homeDir, orderFor, warned) {
2298
- try {
2299
- const resolved = resolveSection(section.name, { presetId, homeDir, defaultOrder: orderFor });
2300
- const malformed = resolved.malformed;
2301
- if (malformed !== void 0 && !warned.has(malformed.file)) {
2302
- warned.add(malformed.file);
2303
- warn2(
2304
- rootCtx,
2305
- `ignoring malformed guidance override ${malformed.file}: ${malformed.reason}; using compiled default`
2306
- );
2307
- }
2308
- return resolved.text;
2309
- } catch (error) {
2310
- const file = join6(homeDir, presetId, section.file);
2311
- if (!warned.has(file)) {
2312
- warned.add(file);
2313
- warn2(
2314
- rootCtx,
2315
- `guidance section ${section.name} could not be re-read; using compiled default: ${error instanceof Error ? error.message : String(error)}`
2316
- );
2317
- }
2318
- return section.renderDefault();
2319
- }
2320
- }
2321
1946
  function sectionEnabled(name2, toggles) {
2322
1947
  if (toggles === void 0) return true;
2323
1948
  if (name2 === "tool:read") return toggles.read;
@@ -2333,42 +1958,15 @@ function registerGuidanceSections(rootCtx, agentCtx, enabled) {
2333
1958
  };
2334
1959
  }
2335
1960
  const orderFor = orderResolver(registry);
2336
- const presetId = presetIdFor(rootCtx, agentCtx) ?? FALLBACK_PRESET_ID;
2337
- const homeDir = guidanceHomeDir();
2338
- void ensurePresetGuidance(homeDir, () => readPresetIds(rootCtx)).catch((error) => {
2339
- warn2(
2340
- rootCtx,
2341
- `guidance materialization failed for ${homeDir}: ${error instanceof Error ? error.message : String(error)}`
2342
- );
2343
- });
2344
- let sections;
2345
- try {
2346
- sections = composeSections(presetId, homeDir, orderFor);
2347
- } catch (error) {
2348
- warn2(
2349
- rootCtx,
2350
- `guidance resolution failed; using compiled defaults: ${error instanceof Error ? error.message : String(error)}`
2351
- );
2352
- sections = compiledSections(orderFor);
2353
- }
2354
1961
  const disposers = [];
2355
- const warned = /* @__PURE__ */ new Set();
2356
- for (let index = 0; index < sections.length; index++) {
2357
- const section = sections[index];
2358
- const definition = GUIDANCE_SECTIONS2[index];
2359
- if (!sectionEnabled(definition.name, enabled)) continue;
2360
- if (section.malformed !== void 0) {
2361
- warn2(
2362
- rootCtx,
2363
- `ignoring malformed guidance override ${section.malformed.file}: ${section.malformed.reason}; using compiled default`
2364
- );
2365
- }
1962
+ for (const section of GUIDANCE_SECTIONS2) {
1963
+ if (!sectionEnabled(section.name, enabled)) continue;
2366
1964
  try {
2367
1965
  disposers.push(
2368
1966
  registry.section({
2369
1967
  name: section.name,
2370
- order: section.order,
2371
- text: () => resolveSectionText(rootCtx, definition, presetId, homeDir, orderFor, warned)
1968
+ order: orderFor(section),
1969
+ text: section.renderDefault()
2372
1970
  })
2373
1971
  );
2374
1972
  } catch (error) {
@@ -3140,9 +2738,9 @@ import { isAbsolute as isAbsolute5, resolve as resolvePath } from "node:path";
3140
2738
 
3141
2739
  // src/hash-store.ts
3142
2740
  import { closeSync, existsSync as existsSync2, fstatSync, openSync, readSync } from "node:fs";
3143
- import { rename as rename3, mkdir as mkdir4 } from "node:fs/promises";
2741
+ import { rename as rename3, mkdir as mkdir3 } from "node:fs/promises";
3144
2742
  import { DatabaseSync } from "node:sqlite";
3145
- import { join as join7, dirname as dirname5 } from "node:path";
2743
+ import { join as join6, dirname as dirname5 } from "node:path";
3146
2744
 
3147
2745
  // src/store-kernel/constants.ts
3148
2746
  var HASH_STORE_BUSY_TIMEOUT = 250;
@@ -3270,15 +2868,15 @@ function markRun(db, key, now) {
3270
2868
 
3271
2869
  // src/hash-store.ts
3272
2870
  function hashStorePath() {
3273
- return join7(stateRoot(), "hash-store.sqlite");
2871
+ return join6(stateRoot(), "hash-store.sqlite");
3274
2872
  }
3275
2873
  function legacyHashStorePath() {
3276
- return join7(stateRoot(), "hash-store.json");
2874
+ return join6(stateRoot(), "hash-store.json");
3277
2875
  }
3278
2876
  async function ensureStateRoot() {
3279
2877
  const root = stateRoot();
3280
2878
  try {
3281
- await mkdir4(root, { recursive: true });
2879
+ await mkdir3(root, { recursive: true });
3282
2880
  } catch {
3283
2881
  throw new DomainError("E_ACCESS", { path: root, kind: "denied", access: "write" });
3284
2882
  }
@@ -5672,7 +5270,7 @@ function deleteVacuumSnapshots(db, snapshotIds) {
5672
5270
  }
5673
5271
 
5674
5272
  // src/snapshot-store/migrate.ts
5675
- import { readFile as readFile4, rename as rename4 } from "node:fs/promises";
5273
+ import { readFile as readFile3, rename as rename4 } from "node:fs/promises";
5676
5274
  function isValidSnapshot(value) {
5677
5275
  if (typeof value !== "object" || value === null) return false;
5678
5276
  const v = value;
@@ -5683,7 +5281,7 @@ async function migrateLegacyStore(db) {
5683
5281
  const legacyPath = legacyHashStorePath();
5684
5282
  let content;
5685
5283
  try {
5686
- content = await readFile4(legacyPath, "utf-8");
5284
+ content = await readFile3(legacyPath, "utf-8");
5687
5285
  } catch (error) {
5688
5286
  if (errCode(error) === "ENOENT") return;
5689
5287
  reportDiagnostic("snapshot-store", "Failed to read legacy hash store for migration:", error);
@@ -7389,12 +6987,12 @@ function planWindows(target, resolver) {
7389
6987
  }
7390
6988
 
7391
6989
  // src/read-expansion/audit.ts
7392
- import { appendFileSync as appendFileSync3, mkdirSync as mkdirSync4, renameSync as renameSync3, statSync as statSync3 } from "node:fs";
7393
- 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";
7394
6992
  var READ_EXPANSION_LOG_NAME = "read-expansion.log";
7395
6993
  var READ_EXPANSION_LOG_MAX_BYTES = 1024 * 1024;
7396
6994
  function readExpansionLogPath() {
7397
- return join8(stateRoot(), READ_EXPANSION_LOG_NAME);
6995
+ return join7(stateRoot(), READ_EXPANSION_LOG_NAME);
7398
6996
  }
7399
6997
  var rungRecordedSessions = /* @__PURE__ */ new Set();
7400
6998
  var runtimeAbsentSessions = /* @__PURE__ */ new Set();
@@ -7432,7 +7030,7 @@ function appendRecord2(fields) {
7432
7030
  function rotateIfOversize2(path, incomingBytes) {
7433
7031
  let current = 0;
7434
7032
  try {
7435
- current = statSync3(path).size;
7033
+ current = statSync2(path).size;
7436
7034
  } catch {
7437
7035
  return;
7438
7036
  }
@@ -7442,7 +7040,7 @@ function rotateIfOversize2(path, incomingBytes) {
7442
7040
 
7443
7041
  // src/read-expansion/ast-provider.ts
7444
7042
  import { readdirSync as readdirSync2 } from "node:fs";
7445
- import { readFile as readFile5 } from "node:fs/promises";
7043
+ import { readFile as readFile4 } from "node:fs/promises";
7446
7044
 
7447
7045
  // src/read-expansion/ast-span.ts
7448
7046
  function scopeLineRange(node) {
@@ -7471,9 +7069,9 @@ function findEnclosingScope(root, requestedStart, requestedEnd, scopeKinds) {
7471
7069
  }
7472
7070
 
7473
7071
  // src/read-expansion/grammar-cache.ts
7474
- import { createHash as createHash2 } from "node:crypto";
7475
- import { existsSync as existsSync3, mkdirSync as mkdirSync5, readFileSync as readFileSync3, renameSync as renameSync4, rmSync, writeFileSync as writeFileSync2 } from "node:fs";
7476
- 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";
7477
7075
 
7478
7076
  // src/read-expansion/grammar-manifest.ts
7479
7077
  var GRAMMAR_MANIFEST = {
@@ -7546,10 +7144,10 @@ var FETCH_HARD_TIMEOUT_MS = 3e4;
7546
7144
  var COLD = /* @__PURE__ */ Symbol("cold");
7547
7145
  var inFlight = /* @__PURE__ */ new Map();
7548
7146
  function grammarCacheRoot(root) {
7549
- return root ?? join9(stateRoot(), "grammars");
7147
+ return root ?? join8(stateRoot(), "grammars");
7550
7148
  }
7551
7149
  function grammarCachePath(language, entry, cacheRoot) {
7552
- return join9(
7150
+ return join8(
7553
7151
  grammarCacheRoot(cacheRoot),
7554
7152
  `${language}-${entry.version}-${entry.sha256.slice(0, 16)}.wasm`
7555
7153
  );
@@ -7561,13 +7159,13 @@ function discardCachedGrammar(path) {
7561
7159
  }
7562
7160
  }
7563
7161
  function sha256Hex(bytes) {
7564
- return createHash2("sha256").update(bytes).digest("hex");
7162
+ return createHash("sha256").update(bytes).digest("hex");
7565
7163
  }
7566
7164
  function readVerifiedCache(path, expected) {
7567
7165
  if (!existsSync3(path)) return void 0;
7568
7166
  let bytes;
7569
7167
  try {
7570
- bytes = readFileSync3(path);
7168
+ bytes = readFileSync2(path);
7571
7169
  } catch {
7572
7170
  discardCachedGrammar(path);
7573
7171
  return void 0;
@@ -7959,7 +7557,7 @@ function isOffsetWindow(window) {
7959
7557
  }
7960
7558
  async function defaultReadText(path) {
7961
7559
  try {
7962
- return await readFile5(path, "utf-8");
7560
+ return await readFile4(path, "utf-8");
7963
7561
  } catch {
7964
7562
  return void 0;
7965
7563
  }
@@ -8110,7 +7708,7 @@ function createAstSpanProvider(options = {}) {
8110
7708
  }
8111
7709
 
8112
7710
  // src/read-expansion/markdown-provider.ts
8113
- import { readFile as readFile6 } from "node:fs/promises";
7711
+ import { readFile as readFile5 } from "node:fs/promises";
8114
7712
 
8115
7713
  // src/read-expansion/text-lines.ts
8116
7714
  function splitVisibleLines(text) {
@@ -8207,7 +7805,7 @@ function isMarkdownPath(path) {
8207
7805
  }
8208
7806
  async function defaultReadText2(path) {
8209
7807
  try {
8210
- return await readFile6(path, "utf-8");
7808
+ return await readFile5(path, "utf-8");
8211
7809
  } catch {
8212
7810
  return void 0;
8213
7811
  }
@@ -8234,7 +7832,7 @@ function createMarkdownSpanProvider(options = {}) {
8234
7832
  }
8235
7833
 
8236
7834
  // src/read-expansion/bash-provider.ts
8237
- import { readFile as readFile7 } from "node:fs/promises";
7835
+ import { readFile as readFile6 } from "node:fs/promises";
8238
7836
 
8239
7837
  // src/read-expansion/line-arithmetic.ts
8240
7838
  function lineBreaksIn(text, endExclusive) {
@@ -8280,7 +7878,7 @@ function isShellPath(path) {
8280
7878
  }
8281
7879
  async function defaultReadText3(path) {
8282
7880
  try {
8283
- return await readFile7(path, "utf-8");
7881
+ return await readFile6(path, "utf-8");
8284
7882
  } catch {
8285
7883
  return void 0;
8286
7884
  }
@@ -8361,7 +7959,7 @@ function createBashSpanProvider(options = {}) {
8361
7959
  }
8362
7960
 
8363
7961
  // src/read-expansion/paragraph-provider.ts
8364
- import { readFile as readFile8 } from "node:fs/promises";
7962
+ import { readFile as readFile7 } from "node:fs/promises";
8365
7963
 
8366
7964
  // src/read-expansion/paragraph-section.ts
8367
7965
  function findParagraph(text, requestedStart, requestedEnd) {
@@ -8402,7 +8000,7 @@ function isDataPath(path) {
8402
8000
  }
8403
8001
  async function defaultReadText4(path) {
8404
8002
  try {
8405
- return await readFile8(path, "utf-8");
8003
+ return await readFile7(path, "utf-8");
8406
8004
  } catch {
8407
8005
  return void 0;
8408
8006
  }
@@ -8847,15 +8445,15 @@ import {
8847
8445
  constants as constants5,
8848
8446
  existsSync as existsSync4,
8849
8447
  mkdirSync as mkdirSync6,
8850
- readFileSync as readFileSync4,
8448
+ readFileSync as readFileSync3,
8851
8449
  renameSync as renameSync5,
8852
8450
  unlinkSync as unlinkSync2,
8853
8451
  writeFileSync as writeFileSync3
8854
8452
  } from "node:fs";
8855
- 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";
8856
8454
  var CONFIG_SCHEMA_ID = "https://github.com/Rianico/pi-better-edit/schemas/pi-better-edit.json";
8857
8455
  function configFilePath(scope, cwd) {
8858
- 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);
8859
8457
  }
8860
8458
  function readScopeConfig(scope, cwd, onWarn) {
8861
8459
  const path = configFilePath(scope, cwd);
@@ -8919,7 +8517,7 @@ function reasonOf2(error) {
8919
8517
  function readConfigObject(path, onWarn) {
8920
8518
  let raw;
8921
8519
  try {
8922
- raw = readFileSync4(path, "utf-8");
8520
+ raw = readFileSync3(path, "utf-8");
8923
8521
  } catch (error) {
8924
8522
  if (!isMissingFile(error)) onWarn?.(`cannot read config ${path}: ${reasonOf2(error)}`);
8925
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, discoverPresets?: () => Promise<readonly 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.3",
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
  },