dsh-hashline-edit 0.3.1 → 0.3.3
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 +112 -33
- package/lib/types/dsh/guidance.d.ts +1 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1870,6 +1870,7 @@ function commandOf(args) {
|
|
|
1870
1870
|
|
|
1871
1871
|
// dsh/guidance.ts
|
|
1872
1872
|
import { readFileSync as readFileSync2, statSync as statSync2 } from "node:fs";
|
|
1873
|
+
import { createHash } from "node:crypto";
|
|
1873
1874
|
import { mkdir as mkdir3, readFile as readFile3, readdir as readdir2, writeFile as writeFile3 } from "node:fs/promises";
|
|
1874
1875
|
import { join as join6 } from "node:path";
|
|
1875
1876
|
import { resolveDshHome } from "@deepseek-ai/dsh-home-paths";
|
|
@@ -2028,8 +2029,10 @@ var GUIDANCE_HOME_README = `# dsh-hashline-edit guidance
|
|
|
2028
2029
|
|
|
2029
2030
|
Each agent preset has its own guidance directory here: \`<preset>/<section>.md\`.
|
|
2030
2031
|
On first boot the plugin seeds the shipped presets (\`standard\`, \`ptc\`,
|
|
2031
|
-
\`minimal\`, \`cordis\`) with the compiled defaults
|
|
2032
|
-
overwritten
|
|
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.
|
|
2033
2036
|
|
|
2034
2037
|
Each file is one tool section:
|
|
2035
2038
|
|
|
@@ -2068,7 +2071,8 @@ var GUIDANCE_HOME_README_ZH = `# dsh-hashline-edit \u6307\u5F15
|
|
|
2068
2071
|
|
|
2069
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
|
|
2070
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
|
|
2071
|
-
\u9ED8\u8BA4\u5185\u5BB9\
|
|
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
|
|
2072
2076
|
|
|
2073
2077
|
\u6BCF\u4E2A\u6587\u4EF6\u5BF9\u5E94\u4E00\u4E2A\u5DE5\u5177\u7247\u6BB5\uFF1A
|
|
2074
2078
|
|
|
@@ -2106,55 +2110,118 @@ order: ${section.defaultOrder}
|
|
|
2106
2110
|
|
|
2107
2111
|
${section.renderDefault()}`;
|
|
2108
2112
|
}
|
|
2109
|
-
|
|
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);
|
|
2110
2154
|
let content;
|
|
2111
2155
|
try {
|
|
2112
2156
|
content = await readFile3(path, "utf-8");
|
|
2113
2157
|
} catch (error) {
|
|
2114
|
-
if (errCode(error)
|
|
2115
|
-
|
|
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);
|
|
2116
2182
|
}
|
|
2117
|
-
if (!isBlankOverride(content)) return;
|
|
2118
|
-
await writeFile3(path, seededContent(section), { encoding: "utf-8" });
|
|
2119
2183
|
}
|
|
2120
|
-
async function ensurePresetGuidance(homeDir) {
|
|
2184
|
+
async function ensurePresetGuidance(homeDir, discoverPresets) {
|
|
2121
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
|
+
}
|
|
2122
2191
|
await Promise.all(
|
|
2123
|
-
|
|
2192
|
+
Array.from(seededPresets).map(async (preset) => {
|
|
2124
2193
|
const directory = join6(homeDir, preset);
|
|
2125
2194
|
await mkdir3(directory, { recursive: true });
|
|
2126
|
-
const existing = new Set(await readdir2(directory));
|
|
2127
2195
|
await Promise.all(
|
|
2128
|
-
GUIDANCE_SECTIONS2.map(
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
flag: "wx"
|
|
2137
|
-
}).catch((error) => {
|
|
2138
|
-
if (errCode(error) === "EEXIST") return;
|
|
2139
|
-
throw error;
|
|
2140
|
-
});
|
|
2141
|
-
})
|
|
2196
|
+
GUIDANCE_SECTIONS2.map(
|
|
2197
|
+
(section) => reconcileOverride(
|
|
2198
|
+
join6(directory, section.file),
|
|
2199
|
+
section,
|
|
2200
|
+
seedState,
|
|
2201
|
+
`${preset}/${section.file}`
|
|
2202
|
+
)
|
|
2203
|
+
)
|
|
2142
2204
|
);
|
|
2143
2205
|
})
|
|
2144
2206
|
);
|
|
2145
2207
|
const entries = await readdir2(homeDir, { withFileTypes: true });
|
|
2146
2208
|
await Promise.all(
|
|
2147
|
-
entries.filter((entry) => entry.isDirectory() && !
|
|
2209
|
+
entries.filter((entry) => entry.isDirectory() && !seededPresets.has(entry.name)).map(async (entry) => {
|
|
2148
2210
|
const directory = join6(homeDir, entry.name);
|
|
2149
2211
|
const existing = new Set(await readdir2(directory));
|
|
2150
2212
|
await Promise.all(
|
|
2151
|
-
GUIDANCE_SECTIONS2.
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
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
|
+
)
|
|
2155
2221
|
);
|
|
2156
2222
|
})
|
|
2157
2223
|
);
|
|
2224
|
+
await writeSeedState(homeDir, seedState);
|
|
2158
2225
|
const homeFiles = new Set(await readdir2(homeDir));
|
|
2159
2226
|
const readmes = [
|
|
2160
2227
|
["README.md", GUIDANCE_HOME_README],
|
|
@@ -2172,6 +2239,18 @@ async function ensurePresetGuidance(homeDir) {
|
|
|
2172
2239
|
})
|
|
2173
2240
|
);
|
|
2174
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
|
+
}
|
|
2175
2254
|
function guidanceHomeDir(env = process.env) {
|
|
2176
2255
|
return join6(resolveDshHome(void 0, env), "plugins", PLUGIN_NAME, "guidance");
|
|
2177
2256
|
}
|
|
@@ -2256,7 +2335,7 @@ function registerGuidanceSections(rootCtx, agentCtx, enabled) {
|
|
|
2256
2335
|
const orderFor = orderResolver(registry);
|
|
2257
2336
|
const presetId = presetIdFor(rootCtx, agentCtx) ?? FALLBACK_PRESET_ID;
|
|
2258
2337
|
const homeDir = guidanceHomeDir();
|
|
2259
|
-
void ensurePresetGuidance(homeDir).catch((error) => {
|
|
2338
|
+
void ensurePresetGuidance(homeDir, () => readPresetIds(rootCtx)).catch((error) => {
|
|
2260
2339
|
warn2(
|
|
2261
2340
|
rootCtx,
|
|
2262
2341
|
`guidance materialization failed for ${homeDir}: ${error instanceof Error ? error.message : String(error)}`
|
|
@@ -7392,7 +7471,7 @@ function findEnclosingScope(root, requestedStart, requestedEnd, scopeKinds) {
|
|
|
7392
7471
|
}
|
|
7393
7472
|
|
|
7394
7473
|
// src/read-expansion/grammar-cache.ts
|
|
7395
|
-
import { createHash } from "node:crypto";
|
|
7474
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
7396
7475
|
import { existsSync as existsSync3, mkdirSync as mkdirSync5, readFileSync as readFileSync3, renameSync as renameSync4, rmSync, writeFileSync as writeFileSync2 } from "node:fs";
|
|
7397
7476
|
import { dirname as dirname7, join as join9 } from "node:path";
|
|
7398
7477
|
|
|
@@ -7482,7 +7561,7 @@ function discardCachedGrammar(path) {
|
|
|
7482
7561
|
}
|
|
7483
7562
|
}
|
|
7484
7563
|
function sha256Hex(bytes) {
|
|
7485
|
-
return
|
|
7564
|
+
return createHash2("sha256").update(bytes).digest("hex");
|
|
7486
7565
|
}
|
|
7487
7566
|
function readVerifiedCache(path, expected) {
|
|
7488
7567
|
if (!existsSync3(path)) return void 0;
|
|
@@ -100,7 +100,7 @@ export declare const DEFAULT_PRESETS: readonly string[];
|
|
|
100
100
|
* Custom preset directories present on disk are healed like the shipped ones
|
|
101
101
|
* but never fabricated.
|
|
102
102
|
*/
|
|
103
|
-
export declare function ensurePresetGuidance(homeDir: string): Promise<void>;
|
|
103
|
+
export declare function ensurePresetGuidance(homeDir: string, discoverPresets?: () => Promise<readonly string[]>): Promise<void>;
|
|
104
104
|
/** The plugin guidance home: `<DSH_HOME>/plugins/dsh-hashline-edit/guidance`. */
|
|
105
105
|
export declare function guidanceHomeDir(env?: Record<string, string | undefined>): string;
|
|
106
106
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-hashline-edit",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
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",
|