dsh-hashline-edit 0.3.3 → 0.3.5
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 +116 -445
- package/lib/types/dsh/guidance.d.ts +26 -103
- package/package.json +1 -3
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 ?
|
|
51
|
+
var HASH_LEN = true ? 4 : 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}]+$`);
|
|
@@ -1484,6 +1484,20 @@ function skipPythonMember(lines, start) {
|
|
|
1484
1484
|
while (index < lines.length && /^ {8,}\S/u.test(lines[index] ?? "")) index += 1;
|
|
1485
1485
|
return index;
|
|
1486
1486
|
}
|
|
1487
|
+
function toolsOfContext(context) {
|
|
1488
|
+
const direct = context?.tools;
|
|
1489
|
+
if (direct !== void 0 && (typeof direct.restrict === "function" || typeof direct.guard === "function" || typeof direct.get === "function")) {
|
|
1490
|
+
return direct;
|
|
1491
|
+
}
|
|
1492
|
+
try {
|
|
1493
|
+
const viaGet = context?.get?.("tools");
|
|
1494
|
+
if (viaGet !== void 0 && (typeof viaGet.restrict === "function" || typeof viaGet.guard === "function" || typeof viaGet.get === "function")) {
|
|
1495
|
+
return viaGet;
|
|
1496
|
+
}
|
|
1497
|
+
} catch {
|
|
1498
|
+
}
|
|
1499
|
+
return void 0;
|
|
1500
|
+
}
|
|
1487
1501
|
function warn(rootCtx, message) {
|
|
1488
1502
|
try {
|
|
1489
1503
|
rootCtx.logger?.warn?.(`dsh-hashline-edit: ${message}`);
|
|
@@ -1493,7 +1507,7 @@ function warn(rootCtx, message) {
|
|
|
1493
1507
|
function toolExists(rootCtx, agentCtx, name2, scope) {
|
|
1494
1508
|
const visible = (context) => {
|
|
1495
1509
|
try {
|
|
1496
|
-
const tools = context
|
|
1510
|
+
const tools = toolsOfContext(context);
|
|
1497
1511
|
if (typeof tools?.get !== "function") return false;
|
|
1498
1512
|
return (scope === void 0 ? tools.get(name2) : tools.get(name2, scope)) !== void 0;
|
|
1499
1513
|
} catch {
|
|
@@ -1506,6 +1520,7 @@ function registerNativeToolHiding(rootCtx, agentCtx, config) {
|
|
|
1506
1520
|
if (!hideLayerEnabled(config)) return () => {
|
|
1507
1521
|
};
|
|
1508
1522
|
const agent = agentCtx;
|
|
1523
|
+
const tools = toolsOfContext(agent);
|
|
1509
1524
|
const configured = hiddenNames(config);
|
|
1510
1525
|
const hidden = new Set(configured);
|
|
1511
1526
|
const restrictable = new Set(
|
|
@@ -1517,7 +1532,7 @@ function registerNativeToolHiding(rootCtx, agentCtx, config) {
|
|
|
1517
1532
|
const attemptRestrict = (names) => {
|
|
1518
1533
|
if (names.length === 0) return void 0;
|
|
1519
1534
|
try {
|
|
1520
|
-
const dispose2 =
|
|
1535
|
+
const dispose2 = tools?.restrict?.({ deny: [...names] });
|
|
1521
1536
|
return dispose2 === void 0 ? void 0 : dispose2;
|
|
1522
1537
|
} catch (error) {
|
|
1523
1538
|
restrictError = error;
|
|
@@ -1539,7 +1554,7 @@ function registerNativeToolHiding(rootCtx, agentCtx, config) {
|
|
|
1539
1554
|
return result;
|
|
1540
1555
|
});
|
|
1541
1556
|
if (disposeAssemble !== void 0) disposers.push(disposeAssemble);
|
|
1542
|
-
const disposeGuard =
|
|
1557
|
+
const disposeGuard = tools?.guard?.(
|
|
1543
1558
|
(execution) => hidden.has(execution.name) ? nativeWriteDenial(config.toolName, execution.name) : void 0
|
|
1544
1559
|
);
|
|
1545
1560
|
if (disposeGuard !== void 0) disposers.push(disposeGuard);
|
|
@@ -1868,13 +1883,6 @@ function commandOf(args) {
|
|
|
1868
1883
|
return typeof command === "string" && command.length > 0 ? command : void 0;
|
|
1869
1884
|
}
|
|
1870
1885
|
|
|
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
1886
|
// src/prompts.ts
|
|
1879
1887
|
import { readFileSync } from "node:fs";
|
|
1880
1888
|
function applyReplacements(content, replacements) {
|
|
@@ -1896,39 +1904,6 @@ function loadGuide(relativePath2, replacements) {
|
|
|
1896
1904
|
}
|
|
1897
1905
|
|
|
1898
1906
|
// 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
1907
|
function guidanceText(intro, lines) {
|
|
1933
1908
|
const bullets = lines.map((line) => `- ${line}`).join("\n");
|
|
1934
1909
|
return `${intro}
|
|
@@ -1938,17 +1913,14 @@ ${bullets}`;
|
|
|
1938
1913
|
var GUIDANCE_SECTIONS2 = [
|
|
1939
1914
|
{
|
|
1940
1915
|
name: "tool:read",
|
|
1941
|
-
file: "read.md",
|
|
1942
1916
|
defaultOrder: 1100,
|
|
1943
1917
|
orderName: "TOOL_READ",
|
|
1944
1918
|
renderDefault: () => guidanceText(loadP("../prompts/read.md"), loadGuide("../prompts/read-guidelines.md"))
|
|
1945
1919
|
},
|
|
1946
1920
|
{
|
|
1947
1921
|
name: "tool:apply_patch",
|
|
1948
|
-
file: "apply-patch.md",
|
|
1949
1922
|
defaultOrder: 1350,
|
|
1950
1923
|
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
1924
|
renderDefault: () => guidanceText(
|
|
1953
1925
|
loadP("../prompts/apply-patch.md"),
|
|
1954
1926
|
loadGuide("../prompts/apply-patch-guidelines.md")
|
|
@@ -1956,8 +1928,6 @@ var GUIDANCE_SECTIONS2 = [
|
|
|
1956
1928
|
},
|
|
1957
1929
|
{
|
|
1958
1930
|
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
1931
|
defaultOrder: 1360,
|
|
1962
1932
|
renderDefault: () => guidanceText(
|
|
1963
1933
|
loadP("../prompts/undo-last-edit.md"),
|
|
@@ -1966,310 +1936,11 @@ var GUIDANCE_SECTIONS2 = [
|
|
|
1966
1936
|
}
|
|
1967
1937
|
];
|
|
1968
1938
|
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
1939
|
function registryFor(ctx) {
|
|
2258
1940
|
const candidate = ctx.systemPrompt;
|
|
2259
1941
|
if (candidate === void 0 || typeof candidate.section !== "function") return void 0;
|
|
2260
1942
|
return candidate;
|
|
2261
1943
|
}
|
|
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
1944
|
function warn2(rootCtx, message) {
|
|
2274
1945
|
const logger = rootCtx.logger;
|
|
2275
1946
|
if (typeof logger?.warn === "function") logger.warn(`dsh-hashline-edit: ${message}`);
|
|
@@ -2287,37 +1958,6 @@ function orderResolver(registry) {
|
|
|
2287
1958
|
}
|
|
2288
1959
|
};
|
|
2289
1960
|
}
|
|
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
1961
|
function sectionEnabled(name2, toggles) {
|
|
2322
1962
|
if (toggles === void 0) return true;
|
|
2323
1963
|
if (name2 === "tool:read") return toggles.read;
|
|
@@ -2333,42 +1973,15 @@ function registerGuidanceSections(rootCtx, agentCtx, enabled) {
|
|
|
2333
1973
|
};
|
|
2334
1974
|
}
|
|
2335
1975
|
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
1976
|
const disposers = [];
|
|
2355
|
-
const
|
|
2356
|
-
|
|
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
|
-
}
|
|
1977
|
+
for (const section of GUIDANCE_SECTIONS2) {
|
|
1978
|
+
if (!sectionEnabled(section.name, enabled)) continue;
|
|
2366
1979
|
try {
|
|
2367
1980
|
disposers.push(
|
|
2368
1981
|
registry.section({
|
|
2369
1982
|
name: section.name,
|
|
2370
|
-
order: section
|
|
2371
|
-
text: ()
|
|
1983
|
+
order: orderFor(section),
|
|
1984
|
+
text: section.renderDefault()
|
|
2372
1985
|
})
|
|
2373
1986
|
);
|
|
2374
1987
|
} catch (error) {
|
|
@@ -3140,9 +2753,9 @@ import { isAbsolute as isAbsolute5, resolve as resolvePath } from "node:path";
|
|
|
3140
2753
|
|
|
3141
2754
|
// src/hash-store.ts
|
|
3142
2755
|
import { closeSync, existsSync as existsSync2, fstatSync, openSync, readSync } from "node:fs";
|
|
3143
|
-
import { rename as rename3, mkdir as
|
|
2756
|
+
import { rename as rename3, mkdir as mkdir3 } from "node:fs/promises";
|
|
3144
2757
|
import { DatabaseSync } from "node:sqlite";
|
|
3145
|
-
import { join as
|
|
2758
|
+
import { join as join6, dirname as dirname5 } from "node:path";
|
|
3146
2759
|
|
|
3147
2760
|
// src/store-kernel/constants.ts
|
|
3148
2761
|
var HASH_STORE_BUSY_TIMEOUT = 250;
|
|
@@ -3270,15 +2883,15 @@ function markRun(db, key, now) {
|
|
|
3270
2883
|
|
|
3271
2884
|
// src/hash-store.ts
|
|
3272
2885
|
function hashStorePath() {
|
|
3273
|
-
return
|
|
2886
|
+
return join6(stateRoot(), "hash-store.sqlite");
|
|
3274
2887
|
}
|
|
3275
2888
|
function legacyHashStorePath() {
|
|
3276
|
-
return
|
|
2889
|
+
return join6(stateRoot(), "hash-store.json");
|
|
3277
2890
|
}
|
|
3278
2891
|
async function ensureStateRoot() {
|
|
3279
2892
|
const root = stateRoot();
|
|
3280
2893
|
try {
|
|
3281
|
-
await
|
|
2894
|
+
await mkdir3(root, { recursive: true });
|
|
3282
2895
|
} catch {
|
|
3283
2896
|
throw new DomainError("E_ACCESS", { path: root, kind: "denied", access: "write" });
|
|
3284
2897
|
}
|
|
@@ -5672,7 +5285,7 @@ function deleteVacuumSnapshots(db, snapshotIds) {
|
|
|
5672
5285
|
}
|
|
5673
5286
|
|
|
5674
5287
|
// src/snapshot-store/migrate.ts
|
|
5675
|
-
import { readFile as
|
|
5288
|
+
import { readFile as readFile3, rename as rename4 } from "node:fs/promises";
|
|
5676
5289
|
function isValidSnapshot(value) {
|
|
5677
5290
|
if (typeof value !== "object" || value === null) return false;
|
|
5678
5291
|
const v = value;
|
|
@@ -5683,7 +5296,7 @@ async function migrateLegacyStore(db) {
|
|
|
5683
5296
|
const legacyPath = legacyHashStorePath();
|
|
5684
5297
|
let content;
|
|
5685
5298
|
try {
|
|
5686
|
-
content = await
|
|
5299
|
+
content = await readFile3(legacyPath, "utf-8");
|
|
5687
5300
|
} catch (error) {
|
|
5688
5301
|
if (errCode(error) === "ENOENT") return;
|
|
5689
5302
|
reportDiagnostic("snapshot-store", "Failed to read legacy hash store for migration:", error);
|
|
@@ -7389,12 +7002,12 @@ function planWindows(target, resolver) {
|
|
|
7389
7002
|
}
|
|
7390
7003
|
|
|
7391
7004
|
// src/read-expansion/audit.ts
|
|
7392
|
-
import { appendFileSync as appendFileSync3, mkdirSync as mkdirSync4, renameSync as renameSync3, statSync as
|
|
7393
|
-
import { dirname as dirname6, join as
|
|
7005
|
+
import { appendFileSync as appendFileSync3, mkdirSync as mkdirSync4, renameSync as renameSync3, statSync as statSync2 } from "node:fs";
|
|
7006
|
+
import { dirname as dirname6, join as join7 } from "node:path";
|
|
7394
7007
|
var READ_EXPANSION_LOG_NAME = "read-expansion.log";
|
|
7395
7008
|
var READ_EXPANSION_LOG_MAX_BYTES = 1024 * 1024;
|
|
7396
7009
|
function readExpansionLogPath() {
|
|
7397
|
-
return
|
|
7010
|
+
return join7(stateRoot(), READ_EXPANSION_LOG_NAME);
|
|
7398
7011
|
}
|
|
7399
7012
|
var rungRecordedSessions = /* @__PURE__ */ new Set();
|
|
7400
7013
|
var runtimeAbsentSessions = /* @__PURE__ */ new Set();
|
|
@@ -7432,7 +7045,7 @@ function appendRecord2(fields) {
|
|
|
7432
7045
|
function rotateIfOversize2(path, incomingBytes) {
|
|
7433
7046
|
let current = 0;
|
|
7434
7047
|
try {
|
|
7435
|
-
current =
|
|
7048
|
+
current = statSync2(path).size;
|
|
7436
7049
|
} catch {
|
|
7437
7050
|
return;
|
|
7438
7051
|
}
|
|
@@ -7442,7 +7055,7 @@ function rotateIfOversize2(path, incomingBytes) {
|
|
|
7442
7055
|
|
|
7443
7056
|
// src/read-expansion/ast-provider.ts
|
|
7444
7057
|
import { readdirSync as readdirSync2 } from "node:fs";
|
|
7445
|
-
import { readFile as
|
|
7058
|
+
import { readFile as readFile4 } from "node:fs/promises";
|
|
7446
7059
|
|
|
7447
7060
|
// src/read-expansion/ast-span.ts
|
|
7448
7061
|
function scopeLineRange(node) {
|
|
@@ -7471,9 +7084,9 @@ function findEnclosingScope(root, requestedStart, requestedEnd, scopeKinds) {
|
|
|
7471
7084
|
}
|
|
7472
7085
|
|
|
7473
7086
|
// src/read-expansion/grammar-cache.ts
|
|
7474
|
-
import { createHash
|
|
7475
|
-
import { existsSync as existsSync3, mkdirSync as mkdirSync5, readFileSync as
|
|
7476
|
-
import { dirname as dirname7, join as
|
|
7087
|
+
import { createHash } from "node:crypto";
|
|
7088
|
+
import { existsSync as existsSync3, mkdirSync as mkdirSync5, readFileSync as readFileSync2, renameSync as renameSync4, rmSync, writeFileSync as writeFileSync2 } from "node:fs";
|
|
7089
|
+
import { dirname as dirname7, join as join8 } from "node:path";
|
|
7477
7090
|
|
|
7478
7091
|
// src/read-expansion/grammar-manifest.ts
|
|
7479
7092
|
var GRAMMAR_MANIFEST = {
|
|
@@ -7546,10 +7159,10 @@ var FETCH_HARD_TIMEOUT_MS = 3e4;
|
|
|
7546
7159
|
var COLD = /* @__PURE__ */ Symbol("cold");
|
|
7547
7160
|
var inFlight = /* @__PURE__ */ new Map();
|
|
7548
7161
|
function grammarCacheRoot(root) {
|
|
7549
|
-
return root ??
|
|
7162
|
+
return root ?? join8(stateRoot(), "grammars");
|
|
7550
7163
|
}
|
|
7551
7164
|
function grammarCachePath(language, entry, cacheRoot) {
|
|
7552
|
-
return
|
|
7165
|
+
return join8(
|
|
7553
7166
|
grammarCacheRoot(cacheRoot),
|
|
7554
7167
|
`${language}-${entry.version}-${entry.sha256.slice(0, 16)}.wasm`
|
|
7555
7168
|
);
|
|
@@ -7561,13 +7174,13 @@ function discardCachedGrammar(path) {
|
|
|
7561
7174
|
}
|
|
7562
7175
|
}
|
|
7563
7176
|
function sha256Hex(bytes) {
|
|
7564
|
-
return
|
|
7177
|
+
return createHash("sha256").update(bytes).digest("hex");
|
|
7565
7178
|
}
|
|
7566
7179
|
function readVerifiedCache(path, expected) {
|
|
7567
7180
|
if (!existsSync3(path)) return void 0;
|
|
7568
7181
|
let bytes;
|
|
7569
7182
|
try {
|
|
7570
|
-
bytes =
|
|
7183
|
+
bytes = readFileSync2(path);
|
|
7571
7184
|
} catch {
|
|
7572
7185
|
discardCachedGrammar(path);
|
|
7573
7186
|
return void 0;
|
|
@@ -7959,7 +7572,7 @@ function isOffsetWindow(window) {
|
|
|
7959
7572
|
}
|
|
7960
7573
|
async function defaultReadText(path) {
|
|
7961
7574
|
try {
|
|
7962
|
-
return await
|
|
7575
|
+
return await readFile4(path, "utf-8");
|
|
7963
7576
|
} catch {
|
|
7964
7577
|
return void 0;
|
|
7965
7578
|
}
|
|
@@ -8110,7 +7723,7 @@ function createAstSpanProvider(options = {}) {
|
|
|
8110
7723
|
}
|
|
8111
7724
|
|
|
8112
7725
|
// src/read-expansion/markdown-provider.ts
|
|
8113
|
-
import { readFile as
|
|
7726
|
+
import { readFile as readFile5 } from "node:fs/promises";
|
|
8114
7727
|
|
|
8115
7728
|
// src/read-expansion/text-lines.ts
|
|
8116
7729
|
function splitVisibleLines(text) {
|
|
@@ -8207,7 +7820,7 @@ function isMarkdownPath(path) {
|
|
|
8207
7820
|
}
|
|
8208
7821
|
async function defaultReadText2(path) {
|
|
8209
7822
|
try {
|
|
8210
|
-
return await
|
|
7823
|
+
return await readFile5(path, "utf-8");
|
|
8211
7824
|
} catch {
|
|
8212
7825
|
return void 0;
|
|
8213
7826
|
}
|
|
@@ -8234,7 +7847,7 @@ function createMarkdownSpanProvider(options = {}) {
|
|
|
8234
7847
|
}
|
|
8235
7848
|
|
|
8236
7849
|
// src/read-expansion/bash-provider.ts
|
|
8237
|
-
import { readFile as
|
|
7850
|
+
import { readFile as readFile6 } from "node:fs/promises";
|
|
8238
7851
|
|
|
8239
7852
|
// src/read-expansion/line-arithmetic.ts
|
|
8240
7853
|
function lineBreaksIn(text, endExclusive) {
|
|
@@ -8280,7 +7893,7 @@ function isShellPath(path) {
|
|
|
8280
7893
|
}
|
|
8281
7894
|
async function defaultReadText3(path) {
|
|
8282
7895
|
try {
|
|
8283
|
-
return await
|
|
7896
|
+
return await readFile6(path, "utf-8");
|
|
8284
7897
|
} catch {
|
|
8285
7898
|
return void 0;
|
|
8286
7899
|
}
|
|
@@ -8361,7 +7974,7 @@ function createBashSpanProvider(options = {}) {
|
|
|
8361
7974
|
}
|
|
8362
7975
|
|
|
8363
7976
|
// src/read-expansion/paragraph-provider.ts
|
|
8364
|
-
import { readFile as
|
|
7977
|
+
import { readFile as readFile7 } from "node:fs/promises";
|
|
8365
7978
|
|
|
8366
7979
|
// src/read-expansion/paragraph-section.ts
|
|
8367
7980
|
function findParagraph(text, requestedStart, requestedEnd) {
|
|
@@ -8402,7 +8015,7 @@ function isDataPath(path) {
|
|
|
8402
8015
|
}
|
|
8403
8016
|
async function defaultReadText4(path) {
|
|
8404
8017
|
try {
|
|
8405
|
-
return await
|
|
8018
|
+
return await readFile7(path, "utf-8");
|
|
8406
8019
|
} catch {
|
|
8407
8020
|
return void 0;
|
|
8408
8021
|
}
|
|
@@ -8847,15 +8460,15 @@ import {
|
|
|
8847
8460
|
constants as constants5,
|
|
8848
8461
|
existsSync as existsSync4,
|
|
8849
8462
|
mkdirSync as mkdirSync6,
|
|
8850
|
-
readFileSync as
|
|
8463
|
+
readFileSync as readFileSync3,
|
|
8851
8464
|
renameSync as renameSync5,
|
|
8852
8465
|
unlinkSync as unlinkSync2,
|
|
8853
8466
|
writeFileSync as writeFileSync3
|
|
8854
8467
|
} from "node:fs";
|
|
8855
|
-
import { dirname as dirname8, join as
|
|
8468
|
+
import { dirname as dirname8, join as join9, sep as sep3 } from "node:path";
|
|
8856
8469
|
var CONFIG_SCHEMA_ID = "https://github.com/Rianico/pi-better-edit/schemas/pi-better-edit.json";
|
|
8857
8470
|
function configFilePath(scope, cwd) {
|
|
8858
|
-
return scope === "global" ?
|
|
8471
|
+
return scope === "global" ? join9(settingsRoot(), SETTINGS_FILE_NAME) : join9(cwd, PROJECT_SETTINGS_REL);
|
|
8859
8472
|
}
|
|
8860
8473
|
function readScopeConfig(scope, cwd, onWarn) {
|
|
8861
8474
|
const path = configFilePath(scope, cwd);
|
|
@@ -8919,7 +8532,7 @@ function reasonOf2(error) {
|
|
|
8919
8532
|
function readConfigObject(path, onWarn) {
|
|
8920
8533
|
let raw;
|
|
8921
8534
|
try {
|
|
8922
|
-
raw =
|
|
8535
|
+
raw = readFileSync3(path, "utf-8");
|
|
8923
8536
|
} catch (error) {
|
|
8924
8537
|
if (!isMissingFile(error)) onWarn?.(`cannot read config ${path}: ${reasonOf2(error)}`);
|
|
8925
8538
|
return void 0;
|
|
@@ -13873,7 +13486,7 @@ function registerWriteHook(rootCtx, agentCtx, io, observations) {
|
|
|
13873
13486
|
|
|
13874
13487
|
// dsh/index.ts
|
|
13875
13488
|
var name = "dsh-hashline-edit";
|
|
13876
|
-
var inject = ["tools", "systemPrompt"];
|
|
13489
|
+
var inject = ["agents", "tools", "systemPrompt"];
|
|
13877
13490
|
var Config = Schema.object({
|
|
13878
13491
|
read: Schema.boolean().default(true).volatile(),
|
|
13879
13492
|
applyPatch: Schema.boolean().default(true).volatile(),
|
|
@@ -13899,9 +13512,27 @@ function resolveSwitches(config = {}) {
|
|
|
13899
13512
|
undo: switchValue(fields.undo, false)
|
|
13900
13513
|
};
|
|
13901
13514
|
}
|
|
13515
|
+
function toolsOfAgent(agent) {
|
|
13516
|
+
const direct = agent.ctx.tools;
|
|
13517
|
+
if (direct !== void 0 && typeof direct.register === "function") {
|
|
13518
|
+
return direct;
|
|
13519
|
+
}
|
|
13520
|
+
try {
|
|
13521
|
+
const viaGet = agent.ctx.get?.("tools");
|
|
13522
|
+
if (viaGet !== void 0 && typeof viaGet.register === "function") {
|
|
13523
|
+
return viaGet;
|
|
13524
|
+
}
|
|
13525
|
+
} catch {
|
|
13526
|
+
}
|
|
13527
|
+
return void 0;
|
|
13528
|
+
}
|
|
13902
13529
|
function installAgentTools(rootCtx, agent, metrics, config = {}) {
|
|
13903
13530
|
const switches = resolveSwitches(config);
|
|
13904
13531
|
return agent.ctx.effect(() => {
|
|
13532
|
+
const agentTools = toolsOfAgent(agent);
|
|
13533
|
+
if (agentTools === void 0) {
|
|
13534
|
+
throw new Error("agent tools registry is unavailable; cannot register hashline tools");
|
|
13535
|
+
}
|
|
13905
13536
|
const io = createLocalFileIO();
|
|
13906
13537
|
const sandbox = new FsSandboxController(rootCtx);
|
|
13907
13538
|
const fsService = rootCtx.get("fs");
|
|
@@ -13918,7 +13549,7 @@ function installAgentTools(rootCtx, agent, metrics, config = {}) {
|
|
|
13918
13549
|
try {
|
|
13919
13550
|
if (switches.read) {
|
|
13920
13551
|
const spanProvider = createDefaultReadSpanProvider(coreIo);
|
|
13921
|
-
disposers.push(
|
|
13552
|
+
disposers.push(agentTools.register(buildReadTool(deps, { spanProvider })));
|
|
13922
13553
|
}
|
|
13923
13554
|
if (switches.applyPatch) {
|
|
13924
13555
|
const applyPatch = registerApplyPatchTool(rootCtx, agent, deps);
|
|
@@ -13933,7 +13564,7 @@ function installAgentTools(rootCtx, agent, metrics, config = {}) {
|
|
|
13933
13564
|
}
|
|
13934
13565
|
}
|
|
13935
13566
|
if (switches.undo) {
|
|
13936
|
-
disposers.push(
|
|
13567
|
+
disposers.push(agentTools.register(buildUndoTool(deps)));
|
|
13937
13568
|
}
|
|
13938
13569
|
disposers.push(registerGuidanceSections(rootCtx, agent.ctx, switches));
|
|
13939
13570
|
if (switches.read) {
|
|
@@ -13952,8 +13583,10 @@ function installAgentTools(rootCtx, agent, metrics, config = {}) {
|
|
|
13952
13583
|
}
|
|
13953
13584
|
function registerApplyPatchTool(rootCtx, agent, deps) {
|
|
13954
13585
|
try {
|
|
13586
|
+
const agentTools = toolsOfAgent(agent);
|
|
13587
|
+
if (agentTools === void 0) throw new Error("agent tools registry is unavailable");
|
|
13955
13588
|
const definition = buildApplyPatchTool(deps);
|
|
13956
|
-
return { name: definition.name, dispose:
|
|
13589
|
+
return { name: definition.name, dispose: agentTools.register(definition) };
|
|
13957
13590
|
} catch (error) {
|
|
13958
13591
|
warnVia3(
|
|
13959
13592
|
rootCtx,
|
|
@@ -13974,13 +13607,20 @@ function warnVia3(rootCtx, message) {
|
|
|
13974
13607
|
var pluginStates = /* @__PURE__ */ new WeakMap();
|
|
13975
13608
|
function liveAgentsFrom(rootCtx) {
|
|
13976
13609
|
try {
|
|
13977
|
-
const service = rootCtx.get("agents");
|
|
13610
|
+
const service = rootCtx.agents ?? rootCtx.get("agents");
|
|
13978
13611
|
return typeof service?.list === "function" ? service.list() : [];
|
|
13979
13612
|
} catch {
|
|
13980
13613
|
return [];
|
|
13981
13614
|
}
|
|
13982
13615
|
}
|
|
13983
13616
|
function apply(rootCtx, config = {}) {
|
|
13617
|
+
const switches = resolveSwitches(config);
|
|
13618
|
+
if (typeof rootCtx.systemPrompt?.section === "function") {
|
|
13619
|
+
rootCtx.effect(
|
|
13620
|
+
() => registerGuidanceSections(rootCtx, rootCtx, switches),
|
|
13621
|
+
"dsh-hashline-edit: root guidance"
|
|
13622
|
+
);
|
|
13623
|
+
}
|
|
13984
13624
|
const metrics = createToolMetrics(
|
|
13985
13625
|
metricSinkFromEnv(process.env, (error) => {
|
|
13986
13626
|
rootCtx.logger.warn(
|
|
@@ -13988,6 +13628,37 @@ function apply(rootCtx, config = {}) {
|
|
|
13988
13628
|
);
|
|
13989
13629
|
})
|
|
13990
13630
|
);
|
|
13631
|
+
if (typeof rootCtx.tools?.register === "function") {
|
|
13632
|
+
const rootIo = createLocalFileIO();
|
|
13633
|
+
const rootDeps = {
|
|
13634
|
+
io: rootIo,
|
|
13635
|
+
sandbox: new FsSandboxController(rootCtx),
|
|
13636
|
+
coreIo: createCoreReadIo(rootIo),
|
|
13637
|
+
...metrics === void 0 ? {} : { metrics }
|
|
13638
|
+
};
|
|
13639
|
+
rootCtx.effect(() => {
|
|
13640
|
+
const disposers = [];
|
|
13641
|
+
try {
|
|
13642
|
+
if (switches.read) {
|
|
13643
|
+
disposers.push(rootCtx.tools.register(buildReadTool(rootDeps, {
|
|
13644
|
+
spanProvider: createDefaultReadSpanProvider(rootDeps.coreIo)
|
|
13645
|
+
})));
|
|
13646
|
+
}
|
|
13647
|
+
if (switches.applyPatch) {
|
|
13648
|
+
disposers.push(rootCtx.tools.register(buildApplyPatchTool(rootDeps)));
|
|
13649
|
+
}
|
|
13650
|
+
if (switches.undo) {
|
|
13651
|
+
disposers.push(rootCtx.tools.register(buildUndoTool(rootDeps)));
|
|
13652
|
+
}
|
|
13653
|
+
} catch (error) {
|
|
13654
|
+
disposeReverse(disposers);
|
|
13655
|
+
rootCtx.logger.warn(
|
|
13656
|
+
`dsh-hashline-edit: root tool registration failed: ${error instanceof Error ? error.message : String(error)}`
|
|
13657
|
+
);
|
|
13658
|
+
}
|
|
13659
|
+
return () => disposeReverse(disposers);
|
|
13660
|
+
}, "dsh-hashline-edit: root tools");
|
|
13661
|
+
}
|
|
13991
13662
|
let state = pluginStates.get(rootCtx);
|
|
13992
13663
|
if (state === void 0) {
|
|
13993
13664
|
state = { agents: /* @__PURE__ */ new Set(), installs: /* @__PURE__ */ new Map() };
|
|
@@ -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
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
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
|
-
|
|
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
|
-
/**
|
|
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
|
+
"version": "0.3.5",
|
|
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
|
},
|