dsh-vscode-mode 0.33.1 → 0.35.0
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/README.md +22 -4
- package/lib/client.excel.js +3 -3
- package/lib/client.js +61 -60
- package/lib/client.js.map +1 -1
- package/lib/index.js +520 -19
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/skills/dsh-vscodemode-html-plan/SKILL.md +23 -0
- package/skills/dsh-vscodemode-html-plan/references/blocks.md +14 -0
- package/skills/dsh-vscodemode-html-plan/runtime/htmlplan.css +20 -0
- package/skills/dsh-vscodemode-html-plan/runtime/htmlplan.js +36 -1
- package/skills/dsh-vscodemode-html-plan/runtime/pack.mjs +35 -4
- package/skills/dsh-vscodemode-html-plan/runtime/plan.mjs +17 -6
- package/src/client/composerState.ts +64 -0
- package/src/client/htmlPlan/HtmlPlanPanel.ts +8 -3
- package/src/client/htmlPlan/planPage.ts +31 -1
- package/src/client/sidebar/panels/FileExplorer.ts +3 -14
- package/src/client/sidebar/panels/SvnPanel.ts +12 -3
- package/src/client/styles/editor.css +43 -5
- package/src/client/svnStatus.ts +25 -1
- package/src/client/ui/ConversationDiffDock.ts +21 -2
- package/src/client/ui/SvnCommitDialog.ts +10 -2
- package/src/client/ui/SvnUpdateDialog.ts +58 -12
- package/src/client/ui/icons.ts +52 -4
- package/src/client/ui/svnIcons.ts +99 -0
- package/src/client/ui/useSvnEntryKinds.ts +77 -0
- package/src/htmlPlanAttachments.ts +362 -0
- package/src/htmlPlanCommand.ts +257 -18
- package/src/shared/rpc.ts +3 -0
- package/src/shared/svn.ts +9 -0
- package/src/svn.ts +50 -2
package/lib/index.js
CHANGED
|
@@ -32109,6 +32109,73 @@ function createSvnRpc(deps) {
|
|
|
32109
32109
|
};
|
|
32110
32110
|
},
|
|
32111
32111
|
/**
|
|
32112
|
+
* 批量判型(窗口行图标用):`svn status` 与 `svn update` 的输出都不带 kind,
|
|
32113
|
+
* 只能逐条查磁盘。口径与 svn.fileSizes 同型:上限护栏 + 单条失败按 missing +
|
|
32114
|
+
* 分批并发保序(批 16),个别路径查不到不影响整批。
|
|
32115
|
+
* @author ddj 2026年11月23号
|
|
32116
|
+
* @param args.sessionId 会话 id
|
|
32117
|
+
* @param args.paths 工作副本相对路径列表(host 权威上限 PATH_KINDS_CAP)
|
|
32118
|
+
* @returns 路径 → 类型(file/dir/missing),顺序与输入一致
|
|
32119
|
+
*/
|
|
32120
|
+
"svn.pathKinds": async (args) => {
|
|
32121
|
+
const sc = await requireSvnSession(ctx, args.sessionId);
|
|
32122
|
+
if ("err" in sc) return {
|
|
32123
|
+
ok: false,
|
|
32124
|
+
error: sc.err
|
|
32125
|
+
};
|
|
32126
|
+
const list = Array.isArray(args.paths) ? args.paths.slice(0, 200) : [];
|
|
32127
|
+
if (!list.length) return {
|
|
32128
|
+
ok: true,
|
|
32129
|
+
kinds: []
|
|
32130
|
+
};
|
|
32131
|
+
const fs = ctx.get("fs");
|
|
32132
|
+
if (!fs?.resolve || !fs?.stat) return {
|
|
32133
|
+
ok: false,
|
|
32134
|
+
error: "缺少 fs"
|
|
32135
|
+
};
|
|
32136
|
+
/**
|
|
32137
|
+
* 单条判型:路径越界或查询异常都按 missing(客户端只据此决定图标,不再推测)。
|
|
32138
|
+
* @author ddj 2026年11月23号
|
|
32139
|
+
* @param raw 调用方给的路径
|
|
32140
|
+
* @returns 归一后的相对路径与类型
|
|
32141
|
+
*/
|
|
32142
|
+
const kindOne = async (raw) => {
|
|
32143
|
+
const rel = safeRel(raw);
|
|
32144
|
+
if (rel === null || rel === "") return {
|
|
32145
|
+
path: String(raw ?? ""),
|
|
32146
|
+
kind: "missing"
|
|
32147
|
+
};
|
|
32148
|
+
try {
|
|
32149
|
+
const resolved = await fs.resolve(rel, { cwd: sc.cwd });
|
|
32150
|
+
const info = await fs.stat(resolved);
|
|
32151
|
+
if (!info) return {
|
|
32152
|
+
path: rel,
|
|
32153
|
+
kind: "missing"
|
|
32154
|
+
};
|
|
32155
|
+
if (info.type === "directory") return {
|
|
32156
|
+
path: rel,
|
|
32157
|
+
kind: "dir"
|
|
32158
|
+
};
|
|
32159
|
+
return {
|
|
32160
|
+
path: rel,
|
|
32161
|
+
kind: info.type === "file" ? "file" : "missing"
|
|
32162
|
+
};
|
|
32163
|
+
} catch {
|
|
32164
|
+
return {
|
|
32165
|
+
path: rel,
|
|
32166
|
+
kind: "missing"
|
|
32167
|
+
};
|
|
32168
|
+
}
|
|
32169
|
+
};
|
|
32170
|
+
const kinds = [];
|
|
32171
|
+
const BATCH = 16;
|
|
32172
|
+
for (let start = 0; start < list.length; start += BATCH) kinds.push(...await Promise.all(list.slice(start, start + BATCH).map(kindOne)));
|
|
32173
|
+
return {
|
|
32174
|
+
ok: true,
|
|
32175
|
+
kinds
|
|
32176
|
+
};
|
|
32177
|
+
},
|
|
32178
|
+
/**
|
|
32112
32179
|
* AI 智能整理分析(只读):拉最新变更 → 附 diff 上下文(超限降级 paths-only)→
|
|
32113
32180
|
* LLM 流式产出 JSON → normalizeAiPlan 以真实清单白名单归一。任何失败零执行只报错。
|
|
32114
32181
|
* @author ddj 2026年09月23号
|
|
@@ -35254,6 +35321,269 @@ function unknownTypeMessage(type) {
|
|
|
35254
35321
|
const known = debuggerDecls().map((d) => d.type + (d.available ? "" : "(" + (d.reason ?? "不可用") + ")")).join(" / ");
|
|
35255
35322
|
return "未发现调试类型「" + type + "」的适配器(已识别:" + (known || "无,请安装带调试器的扩展") + ")";
|
|
35256
35323
|
}
|
|
35324
|
+
/** 媒体类型 → 扩展名(文件名缺失时兜底)。 */
|
|
35325
|
+
const MIME_EXT = {
|
|
35326
|
+
"image/png": ".png",
|
|
35327
|
+
"image/jpeg": ".jpg",
|
|
35328
|
+
"image/webp": ".webp",
|
|
35329
|
+
"image/gif": ".gif",
|
|
35330
|
+
"application/pdf": ".pdf",
|
|
35331
|
+
"text/plain": ".txt",
|
|
35332
|
+
"text/markdown": ".md",
|
|
35333
|
+
"text/csv": ".csv",
|
|
35334
|
+
"application/json": ".json",
|
|
35335
|
+
"application/zip": ".zip"
|
|
35336
|
+
};
|
|
35337
|
+
/** 派生 slug 时跳过的常见虚词(只影响可读性,不改变语义)。 */
|
|
35338
|
+
const STOP_WORDS = /* @__PURE__ */ new Set([
|
|
35339
|
+
"a",
|
|
35340
|
+
"an",
|
|
35341
|
+
"the",
|
|
35342
|
+
"and",
|
|
35343
|
+
"or",
|
|
35344
|
+
"to",
|
|
35345
|
+
"of",
|
|
35346
|
+
"in",
|
|
35347
|
+
"on",
|
|
35348
|
+
"for",
|
|
35349
|
+
"with",
|
|
35350
|
+
"add",
|
|
35351
|
+
"new"
|
|
35352
|
+
]);
|
|
35353
|
+
/** Windows 保留文件名。 */
|
|
35354
|
+
const RESERVED_NAME = /^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/i;
|
|
35355
|
+
/**
|
|
35356
|
+
* 取异常的展示文案。
|
|
35357
|
+
* @author ddj 2026年11月24号
|
|
35358
|
+
* @param error 捕获值
|
|
35359
|
+
* @returns 可读文案
|
|
35360
|
+
*/
|
|
35361
|
+
function messageOf$1(error) {
|
|
35362
|
+
if (error instanceof Error) return error.message;
|
|
35363
|
+
return String(error ?? "未知错误");
|
|
35364
|
+
}
|
|
35365
|
+
/**
|
|
35366
|
+
* 按媒体类型取扩展名。
|
|
35367
|
+
* @author ddj 2026年11月24号
|
|
35368
|
+
* @param mediaType 媒体类型
|
|
35369
|
+
* @returns 形如 `.png` 的扩展名;未知类型返回空串
|
|
35370
|
+
*/
|
|
35371
|
+
function extensionOf(mediaType) {
|
|
35372
|
+
const value = String(mediaType ?? "").toLowerCase();
|
|
35373
|
+
const known = MIME_EXT[value];
|
|
35374
|
+
if (known) return known;
|
|
35375
|
+
const match = /^[a-z]+\/([a-z0-9.+-]+)$/.exec(value);
|
|
35376
|
+
if (!match) return "";
|
|
35377
|
+
const suffix = match[1].replace(/[^a-z0-9]/g, "").slice(0, 5);
|
|
35378
|
+
return suffix ? "." + suffix : "";
|
|
35379
|
+
}
|
|
35380
|
+
/**
|
|
35381
|
+
* 把过长的文件名裁到上限,优先保住扩展名。
|
|
35382
|
+
* @author ddj 2026年11月24号
|
|
35383
|
+
* @param name 已清洗过的文件名
|
|
35384
|
+
* @param limit 长度上限
|
|
35385
|
+
* @returns 裁好的文件名
|
|
35386
|
+
*/
|
|
35387
|
+
function trimName(name, limit) {
|
|
35388
|
+
if (name.length <= limit) return name;
|
|
35389
|
+
const dot = name.lastIndexOf(".");
|
|
35390
|
+
const suffix = dot > 0 && name.length - dot <= 9 ? name.slice(dot) : "";
|
|
35391
|
+
return (suffix ? name.slice(0, dot) : name).slice(0, Math.max(1, limit - suffix.length)) + suffix;
|
|
35392
|
+
}
|
|
35393
|
+
/**
|
|
35394
|
+
* 清洗附件文件名:去目录、去控制字符与 Windows 非法字符、补扩展名、避开保留名。
|
|
35395
|
+
* @author ddj 2026年11月24号
|
|
35396
|
+
* @param raw 原始显示名(可能为空或带路径)
|
|
35397
|
+
* @param index 提交顺序(兜底命名用)
|
|
35398
|
+
* @param kind 来源类型
|
|
35399
|
+
* @param mediaType 媒体类型(缺扩展名时补)
|
|
35400
|
+
* @returns 可安全写进 assets/ 的文件名
|
|
35401
|
+
*/
|
|
35402
|
+
function safeFileName(raw, index, kind, mediaType = "") {
|
|
35403
|
+
const text = String(raw ?? "").replace(/\\/g, "/");
|
|
35404
|
+
let name = text.slice(text.lastIndexOf("/") + 1).replace(/[\u0000-\u001f\u007f<>:"|?*]/g, "").replace(/^[.\s]+|[.\s]+$/g, "").slice(0, 80);
|
|
35405
|
+
if (!name) name = (kind === "image" ? "image-" : "file-") + String(index + 1) + (extensionOf(mediaType) || (kind === "image" ? ".png" : ".bin"));
|
|
35406
|
+
else if (!/\.[a-z0-9]{1,8}$/i.test(name)) {
|
|
35407
|
+
const suffix = extensionOf(mediaType);
|
|
35408
|
+
if (suffix) name += suffix;
|
|
35409
|
+
}
|
|
35410
|
+
name = trimName(name, 80);
|
|
35411
|
+
if (RESERVED_NAME.test(name)) name = "_" + name;
|
|
35412
|
+
return name;
|
|
35413
|
+
}
|
|
35414
|
+
/**
|
|
35415
|
+
* 让同名附件错开(大小写不敏感,贴合 Windows 语义)。
|
|
35416
|
+
* @author ddj 2026年11月24号
|
|
35417
|
+
* @param name 候选文件名
|
|
35418
|
+
* @param used 已占用的文件名(小写)
|
|
35419
|
+
* @returns 唯一的文件名,并登记进 used
|
|
35420
|
+
*/
|
|
35421
|
+
function uniqueFileName(name, used) {
|
|
35422
|
+
if (!used.has(name.toLowerCase())) {
|
|
35423
|
+
used.add(name.toLowerCase());
|
|
35424
|
+
return name;
|
|
35425
|
+
}
|
|
35426
|
+
const dot = name.lastIndexOf(".");
|
|
35427
|
+
const base = dot > 0 ? name.slice(0, dot) : name;
|
|
35428
|
+
const suffix = dot > 0 ? name.slice(dot) : "";
|
|
35429
|
+
for (let serial = 2; serial < 100; serial += 1) {
|
|
35430
|
+
const candidate = base + "-" + String(serial) + suffix;
|
|
35431
|
+
if (used.has(candidate.toLowerCase())) continue;
|
|
35432
|
+
used.add(candidate.toLowerCase());
|
|
35433
|
+
return candidate;
|
|
35434
|
+
}
|
|
35435
|
+
const fallback = base + "-" + String(Date.now()) + suffix;
|
|
35436
|
+
used.add(fallback.toLowerCase());
|
|
35437
|
+
return fallback;
|
|
35438
|
+
}
|
|
35439
|
+
/**
|
|
35440
|
+
* 生成本地时间戳 `YYYYMMDD-HHmm`(slug 兜底用)。
|
|
35441
|
+
* @author ddj 2026年11月24号
|
|
35442
|
+
* @param at 时间点
|
|
35443
|
+
* @returns 13 位时间戳片段
|
|
35444
|
+
*/
|
|
35445
|
+
function stampOf(at) {
|
|
35446
|
+
const pad = (value) => String(value).padStart(2, "0");
|
|
35447
|
+
return String(at.getFullYear()) + pad(at.getMonth() + 1) + pad(at.getDate()) + "-" + pad(at.getHours()) + pad(at.getMinutes());
|
|
35448
|
+
}
|
|
35449
|
+
/**
|
|
35450
|
+
* 从任务文本派生固定 slug:取前几个 ASCII 词;词太少或没有可用词时用时间戳。
|
|
35451
|
+
* 中文任务里零散出现的单个短 ASCII 词(如 html)不足以当目录名,走时间戳兜底。
|
|
35452
|
+
* @author ddj 2026年11月24号
|
|
35453
|
+
* @param task 任务文本(可能全是中文)
|
|
35454
|
+
* @param at 时间点(兜底时间戳)
|
|
35455
|
+
* @returns kebab-case slug(只含小写字母、数字与连字符)
|
|
35456
|
+
*/
|
|
35457
|
+
function slugFromTask(task, at = /* @__PURE__ */ new Date()) {
|
|
35458
|
+
const meaningful = (String(task ?? "").toLowerCase().match(/[a-z0-9]+/g) ?? []).filter((word) => !STOP_WORDS.has(word)).slice(0, 4);
|
|
35459
|
+
return (meaningful.length >= 2 || meaningful.length === 1 && meaningful[0].length >= 6 ? meaningful.join("-").slice(0, 40).replace(/-+/g, "-").replace(/^-|-$/g, "") : "") || "attach-" + stampOf(at);
|
|
35460
|
+
}
|
|
35461
|
+
/**
|
|
35462
|
+
* 字节数的人类可读写法。
|
|
35463
|
+
* @author ddj 2026年11月24号
|
|
35464
|
+
* @param bytes 字节数
|
|
35465
|
+
* @returns 如 `812 KB`;非法值返回空串
|
|
35466
|
+
*/
|
|
35467
|
+
function formatBytes(bytes) {
|
|
35468
|
+
const value = Number(bytes);
|
|
35469
|
+
if (!Number.isFinite(value) || value <= 0) return "";
|
|
35470
|
+
if (value >= 1048576) return (value / 1024 / 1024).toFixed(1) + " MB";
|
|
35471
|
+
if (value >= 1024) return String(Math.round(value / 1024)) + " KB";
|
|
35472
|
+
return String(value) + " B";
|
|
35473
|
+
}
|
|
35474
|
+
/**
|
|
35475
|
+
* 从一个内容块里取出引用视图。
|
|
35476
|
+
* @author ddj 2026年11月24号
|
|
35477
|
+
* @param block 命令收到的内容块
|
|
35478
|
+
* @returns 引用视图;不是图片/文件块时 null
|
|
35479
|
+
*/
|
|
35480
|
+
function refOf(block) {
|
|
35481
|
+
if (block === null || typeof block !== "object") return null;
|
|
35482
|
+
const row = block;
|
|
35483
|
+
const kind = row.type === "image" ? "image" : row.type === "file" ? "file" : "";
|
|
35484
|
+
if (!kind || row.attachment === null || typeof row.attachment !== "object") return null;
|
|
35485
|
+
const ref = row.attachment;
|
|
35486
|
+
return {
|
|
35487
|
+
raw: row.attachment,
|
|
35488
|
+
id: typeof ref.attachmentId === "string" ? ref.attachmentId : "",
|
|
35489
|
+
name: typeof ref.name === "string" ? ref.name : "",
|
|
35490
|
+
mediaType: typeof ref.mediaType === "string" ? ref.mediaType : "",
|
|
35491
|
+
kind
|
|
35492
|
+
};
|
|
35493
|
+
}
|
|
35494
|
+
/**
|
|
35495
|
+
* 把附件按提交顺序写进 plans/<slug>/assets/。
|
|
35496
|
+
*
|
|
35497
|
+
* 单个附件失败只记进 skipped,不影响其余附件;取消信号在每轮开始时检查。
|
|
35498
|
+
* @author ddj 2026年11月24号
|
|
35499
|
+
* @param deps 内容块、slug 与读写能力
|
|
35500
|
+
* @returns 已写入与被跳过的附件清单
|
|
35501
|
+
*/
|
|
35502
|
+
async function stageAttachments(deps) {
|
|
35503
|
+
const slug = String(deps.slug ?? "");
|
|
35504
|
+
const dir = "plans/" + slug + "/assets";
|
|
35505
|
+
const maxBytes = deps.maxBytes ?? 26214400;
|
|
35506
|
+
const maxCount = deps.maxCount ?? 12;
|
|
35507
|
+
const files = [];
|
|
35508
|
+
const skipped = [];
|
|
35509
|
+
const used = /* @__PURE__ */ new Set();
|
|
35510
|
+
const seen = /* @__PURE__ */ new Set();
|
|
35511
|
+
for (const [index, block] of deps.blocks.entries()) {
|
|
35512
|
+
if (deps.signal?.aborted) break;
|
|
35513
|
+
const ref = refOf(block);
|
|
35514
|
+
if (!ref) {
|
|
35515
|
+
skipped.push({
|
|
35516
|
+
name: "attachment-" + String(index + 1),
|
|
35517
|
+
reason: "不是可用的图片或文件引用"
|
|
35518
|
+
});
|
|
35519
|
+
continue;
|
|
35520
|
+
}
|
|
35521
|
+
if (ref.id && seen.has(ref.id)) continue;
|
|
35522
|
+
if (ref.id) seen.add(ref.id);
|
|
35523
|
+
const name = uniqueFileName(safeFileName(ref.name, index, ref.kind, ref.mediaType), used);
|
|
35524
|
+
if (files.length >= maxCount) {
|
|
35525
|
+
skipped.push({
|
|
35526
|
+
name,
|
|
35527
|
+
reason: "超过 " + String(maxCount) + " 个附件上限"
|
|
35528
|
+
});
|
|
35529
|
+
continue;
|
|
35530
|
+
}
|
|
35531
|
+
try {
|
|
35532
|
+
const bytes = ref.kind === "image" ? await deps.readImage(ref.raw, deps.signal) : await deps.readFile(ref.raw, deps.signal);
|
|
35533
|
+
if (bytes.byteLength > maxBytes) {
|
|
35534
|
+
skipped.push({
|
|
35535
|
+
name,
|
|
35536
|
+
reason: "超过 " + formatBytes(maxBytes)
|
|
35537
|
+
});
|
|
35538
|
+
continue;
|
|
35539
|
+
}
|
|
35540
|
+
const relativePath = dir + "/" + name;
|
|
35541
|
+
await deps.write(relativePath, bytes);
|
|
35542
|
+
files.push({
|
|
35543
|
+
name,
|
|
35544
|
+
relativePath,
|
|
35545
|
+
bytes: bytes.byteLength,
|
|
35546
|
+
kind: ref.kind
|
|
35547
|
+
});
|
|
35548
|
+
} catch (error) {
|
|
35549
|
+
skipped.push({
|
|
35550
|
+
name,
|
|
35551
|
+
reason: messageOf$1(error)
|
|
35552
|
+
});
|
|
35553
|
+
}
|
|
35554
|
+
}
|
|
35555
|
+
return {
|
|
35556
|
+
slug,
|
|
35557
|
+
dir,
|
|
35558
|
+
files,
|
|
35559
|
+
skipped
|
|
35560
|
+
};
|
|
35561
|
+
}
|
|
35562
|
+
/**
|
|
35563
|
+
* 生成交给 agent 的附件说明段(路径、类型、大小、页面写法)。
|
|
35564
|
+
* @author ddj 2026年11月24号
|
|
35565
|
+
* @param stage 落盘结果
|
|
35566
|
+
* @returns 逐行文本;没有附件时返回空数组
|
|
35567
|
+
*/
|
|
35568
|
+
function attachmentLines(stage) {
|
|
35569
|
+
const lines = [];
|
|
35570
|
+
if (stage.files.length) {
|
|
35571
|
+
lines.push("附件已保存(页面里必须引用,不要复制到别处):");
|
|
35572
|
+
for (const file of stage.files) {
|
|
35573
|
+
const size = formatBytes(file.bytes);
|
|
35574
|
+
const kindText = file.kind === "image" ? "图片" : "文件";
|
|
35575
|
+
lines.push("- " + file.relativePath + "(" + kindText + (size ? "," + size : "") + ")");
|
|
35576
|
+
}
|
|
35577
|
+
lines.push("页面里用 <doc-attach label=\"随附材料\"><doc-file src=\"assets/<文件名>\">显示名</doc-file></doc-attach> 引用;");
|
|
35578
|
+
lines.push("图片先用 read_image 看清内容;文档或日志用 read 读原文。");
|
|
35579
|
+
lines.push("打包成功后 plans/" + stage.slug + "/assets/ 会被删除;要再打包一次就先给 plan.mjs 加 --keep-assets。");
|
|
35580
|
+
}
|
|
35581
|
+
if (stage.skipped.length) {
|
|
35582
|
+
lines.push("以下附件没能落盘,本次不要引用:");
|
|
35583
|
+
for (const item of stage.skipped) lines.push("- " + item.name + ":" + item.reason);
|
|
35584
|
+
}
|
|
35585
|
+
return lines;
|
|
35586
|
+
}
|
|
35257
35587
|
//#endregion
|
|
35258
35588
|
//#region src/htmlPlanCommand.ts
|
|
35259
35589
|
/**
|
|
@@ -35264,12 +35594,16 @@ function unknownTypeMessage(type) {
|
|
|
35264
35594
|
* - 处理器调用官方 /plan 命令并带上本插件的技能指令,官方 plan 处理器会
|
|
35265
35595
|
* 进入计划模式并用 agent.steer 把这段指令作为用户消息送出;
|
|
35266
35596
|
* - 因此这里不自行构造 UserMessage、不碰 plan 模式内部状态,官方不可用时直接报错(fail closed)。
|
|
35597
|
+
*
|
|
35598
|
+
* 附件:命令声明 input.attachments,官方执行器把 composer 的图片/文件入库后再交给本处理器。
|
|
35599
|
+
* 处理器把字节复制到 plans/<slug>/assets/(agent 与打包脚本都读得到的工作区内路径),
|
|
35600
|
+
* 并把路径写进指令;失败只降级为说明文字,绝不阻断进入计划模式。
|
|
35267
35601
|
* @author ddj 2026年11月21号
|
|
35268
35602
|
*/
|
|
35269
35603
|
/** 命令名(官方语法:小写字母开头,允许数字/_/-)。 */
|
|
35270
35604
|
const HTML_PLAN_COMMAND = "html-plan";
|
|
35271
35605
|
/** 命令描述(出现在 / 菜单与命令目录)。 */
|
|
35272
|
-
const HTML_PLAN_DESCRIPTION = "用 HTML 计划页进入计划模式:/html-plan
|
|
35606
|
+
const HTML_PLAN_DESCRIPTION = "用 HTML 计划页进入计划模式:/html-plan <任务>(可附图片或文件)";
|
|
35273
35607
|
/** 计划指令模板版本(改文案时便于测试断言)。 */
|
|
35274
35608
|
const HTML_PLAN_INSTRUCTION_HEAD = "请使用技能 dsh-vscodemode-html-plan 规划下面的任务,并按 DSH 计划模式提交:";
|
|
35275
35609
|
/** 裸 /html-plan 的指令:先问清任务,再产出 HTML 计划页。 */
|
|
@@ -35303,34 +35637,171 @@ function parseHtmlPlanInput(rawInput) {
|
|
|
35303
35637
|
}
|
|
35304
35638
|
/**
|
|
35305
35639
|
* 构造交给 agent 的计划指令:点名技能、产出路径、打包、标记行与审批方式。
|
|
35640
|
+
* 有附件时用命令固定下来的 slug,并把附件段插在步骤之后。
|
|
35306
35641
|
* @author ddj 2026年11月21号
|
|
35307
35642
|
* @param task 用户任务文本
|
|
35643
|
+
* @param delegate 委派开关(null = 未指定)
|
|
35644
|
+
* @param extras 固定 slug 与附件说明
|
|
35308
35645
|
* @returns 完整用户消息正文
|
|
35309
35646
|
*/
|
|
35310
|
-
function buildHtmlPlanInstruction(task, delegate = null) {
|
|
35647
|
+
function buildHtmlPlanInstruction(task, delegate = null, extras = {}) {
|
|
35311
35648
|
const objective = String(task ?? "").trim();
|
|
35649
|
+
const slug = typeof extras.slug === "string" && /^[a-z0-9][a-z0-9-]*$/i.test(extras.slug) ? extras.slug : "";
|
|
35650
|
+
const pagePath = slug ? "plans/" + slug + "/plan.html" : "plans/<slug>/plan.html";
|
|
35651
|
+
const packedPath = slug ? "plans/" + slug + "/plan.packed.html" : "plans/<slug>/plan.packed.html";
|
|
35652
|
+
const command = slug ? "node <技能目录>/runtime/plan.mjs " + slug + " --root <工作区>" : "node <技能目录>/runtime/plan.mjs <slug> --root <工作区>";
|
|
35653
|
+
const check = slug ? "plan.mjs " + slug + " --check" : "plan.mjs <slug> --check";
|
|
35312
35654
|
const steps = [
|
|
35313
|
-
"1. 先读相关代码与文件,按技能规则写
|
|
35314
|
-
"2. 用一条命令打包:
|
|
35655
|
+
"1. 先读相关代码与文件,按技能规则写 " + pagePath + (slug ? "(slug 已固定,不要另起目录)。" : "(slug 用 kebab-case)。"),
|
|
35656
|
+
"2. 用一条命令打包:" + command + ",它会复制运行时、pack、清理;再跑 " + check + " 确认 plan.packed.html 在位。",
|
|
35315
35657
|
"3. 计划模式允许写 plans/ 下的计划文件:不要因为「在计划模式」跳过写页面,更不要让我退出计划模式来生成。",
|
|
35316
|
-
"4. 页面确认生成后,才调用 exit_plan_mode:正文第一行必须是「# 计划:<标题>」,并单独一行「HTML 计划页:
|
|
35658
|
+
"4. 页面确认生成后,才调用 exit_plan_mode:正文第一行必须是「# 计划:<标题>」,并单独一行「HTML 计划页:" + packedPath + "」;没生成成功就别写这一行,改交 Markdown 计划并说明原因。",
|
|
35317
35659
|
"5. 计划正文同时给出 3~6 行摘要与待决策清单;不要绕过计划模式直接开工。"
|
|
35318
35660
|
];
|
|
35661
|
+
const attachment = (extras.attachmentLines ?? []).filter((line) => typeof line === "string" && line.trim() !== "");
|
|
35319
35662
|
const extra = delegate === null ? "" : delegate ? HTML_PLAN_DELEGATE_INSTRUCTION : HTML_PLAN_SINGLE_AGENT_INSTRUCTION;
|
|
35320
35663
|
return [
|
|
35321
35664
|
HTML_PLAN_INSTRUCTION_HEAD,
|
|
35322
35665
|
...steps,
|
|
35323
|
-
...
|
|
35666
|
+
...attachment.length ? ["", ...attachment] : [],
|
|
35667
|
+
...extra ? [String(steps.length + 1) + ". " + extra] : [],
|
|
35324
35668
|
"",
|
|
35325
35669
|
"任务:" + objective
|
|
35326
35670
|
].join("\n");
|
|
35327
35671
|
}
|
|
35328
|
-
/**
|
|
35672
|
+
/**
|
|
35673
|
+
* 取异常的展示文案。
|
|
35674
|
+
* @author ddj 2026年11月21号
|
|
35675
|
+
* @param error 捕获值
|
|
35676
|
+
* @returns 可读文案
|
|
35677
|
+
*/
|
|
35329
35678
|
function messageOf(error) {
|
|
35330
35679
|
if (error instanceof Error) return error.message;
|
|
35331
35680
|
return String(error ?? "未知错误");
|
|
35332
35681
|
}
|
|
35333
35682
|
/**
|
|
35683
|
+
* 把流式字节拼成一个 Uint8Array(附件可能是任意长度,不假设单块)。
|
|
35684
|
+
* @author ddj 2026年11月24号
|
|
35685
|
+
* @param source 按顺序产出的字节块
|
|
35686
|
+
* @returns 拼接后的字节
|
|
35687
|
+
*/
|
|
35688
|
+
async function readChunks(source) {
|
|
35689
|
+
const parts = [];
|
|
35690
|
+
let total = 0;
|
|
35691
|
+
for await (const part of source) {
|
|
35692
|
+
parts.push(part);
|
|
35693
|
+
total += part.byteLength;
|
|
35694
|
+
}
|
|
35695
|
+
const merged = new Uint8Array(total);
|
|
35696
|
+
let offset = 0;
|
|
35697
|
+
for (const part of parts) {
|
|
35698
|
+
merged.set(part, offset);
|
|
35699
|
+
offset += part.byteLength;
|
|
35700
|
+
}
|
|
35701
|
+
return merged;
|
|
35702
|
+
}
|
|
35703
|
+
/**
|
|
35704
|
+
* 归一化附件存储返回的字节。
|
|
35705
|
+
* @author ddj 2026年11月24号
|
|
35706
|
+
* @param value 服务返回值
|
|
35707
|
+
* @returns 字节视图
|
|
35708
|
+
* @throws 无法识别时抛错(由上层记入 skipped)
|
|
35709
|
+
*/
|
|
35710
|
+
function toBytes(value) {
|
|
35711
|
+
if (value instanceof Uint8Array) return value;
|
|
35712
|
+
if (value instanceof ArrayBuffer) return new Uint8Array(value);
|
|
35713
|
+
if (ArrayBuffer.isView(value)) return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
35714
|
+
throw new Error("附件存储返回了无法识别的字节");
|
|
35715
|
+
}
|
|
35716
|
+
/**
|
|
35717
|
+
* 回滚本次写入的附件:逐个删除文件,再尝试移除空目录。
|
|
35718
|
+
* @author ddj 2026年11月24号
|
|
35719
|
+
* @param workspace 工作区绝对路径
|
|
35720
|
+
* @param stage 落盘结果
|
|
35721
|
+
* @returns 完成后的 Promise(单步失败只忽略)
|
|
35722
|
+
*/
|
|
35723
|
+
async function rollbackStage(workspace, stage) {
|
|
35724
|
+
for (const file of stage.files) try {
|
|
35725
|
+
await unlink(join(workspace, file.relativePath));
|
|
35726
|
+
} catch {}
|
|
35727
|
+
try {
|
|
35728
|
+
await rmdir(join(workspace, stage.dir));
|
|
35729
|
+
} catch {}
|
|
35730
|
+
}
|
|
35731
|
+
/**
|
|
35732
|
+
* 默认附件准备:把 composer 的图片/文件复制到 plans/<slug>/assets/。
|
|
35733
|
+
*
|
|
35734
|
+
* 任何失败(服务缺失、读字节失败、写盘失败)都降级成说明行,不阻断进入计划模式;
|
|
35735
|
+
* 只有 /plan 调用失败时才会回滚本次写入。
|
|
35736
|
+
* @author ddj 2026年11月24号
|
|
35737
|
+
* @param hostCtx 宿主上下文
|
|
35738
|
+
* @param invocation 官方命令调用
|
|
35739
|
+
* @param task 任务文本(派生 slug)
|
|
35740
|
+
* @returns 附件准备结果
|
|
35741
|
+
*/
|
|
35742
|
+
async function stagePlanFiles(hostCtx, invocation, task) {
|
|
35743
|
+
const empty = {
|
|
35744
|
+
slug: null,
|
|
35745
|
+
count: 0,
|
|
35746
|
+
lines: [],
|
|
35747
|
+
rollback: async () => {}
|
|
35748
|
+
};
|
|
35749
|
+
const blocks = Array.isArray(invocation?.attachments) ? invocation.attachments.filter(Boolean) : [];
|
|
35750
|
+
if (!blocks.length) return empty;
|
|
35751
|
+
const ctx = hostCtx;
|
|
35752
|
+
const session = (invocation?.agent)?.session;
|
|
35753
|
+
const workspace = typeof ctx?.get === "function" ? cwdOfSession(ctx, session) : null;
|
|
35754
|
+
const store = typeof ctx?.get === "function" ? ctx.get("attachments") : void 0;
|
|
35755
|
+
const readImage = store?.readImage;
|
|
35756
|
+
const readFileStream = store?.readFileStream;
|
|
35757
|
+
if (!workspace || typeof readImage !== "function" || typeof readFileStream !== "function") return {
|
|
35758
|
+
slug: null,
|
|
35759
|
+
count: 0,
|
|
35760
|
+
lines: ["附件读取失败:当前会话没有可用工作区或附件存储;本次按无附件规划。"],
|
|
35761
|
+
rollback: async () => {}
|
|
35762
|
+
};
|
|
35763
|
+
const slug = slugFromTask(task);
|
|
35764
|
+
try {
|
|
35765
|
+
const stage = await stageAttachments({
|
|
35766
|
+
blocks,
|
|
35767
|
+
slug,
|
|
35768
|
+
signal: invocation.signal,
|
|
35769
|
+
readImage: async (ref, signal) => toBytes((await readImage(ref, signal)).data),
|
|
35770
|
+
readFile: async (ref, signal) => readChunks(readFileStream(ref, signal)),
|
|
35771
|
+
write: async (relativePath, bytes) => {
|
|
35772
|
+
const absolute = join(workspace, relativePath);
|
|
35773
|
+
await mkdir(dirname(absolute), { recursive: true });
|
|
35774
|
+
await writeFile(absolute, bytes);
|
|
35775
|
+
}
|
|
35776
|
+
});
|
|
35777
|
+
return {
|
|
35778
|
+
slug,
|
|
35779
|
+
count: stage.files.length,
|
|
35780
|
+
lines: attachmentLines(stage),
|
|
35781
|
+
rollback: () => rollbackStage(workspace, stage)
|
|
35782
|
+
};
|
|
35783
|
+
} catch (error) {
|
|
35784
|
+
return {
|
|
35785
|
+
slug: null,
|
|
35786
|
+
count: 0,
|
|
35787
|
+
lines: ["附件读取失败:" + messageOf(error) + ";本次按无附件规划。"],
|
|
35788
|
+
rollback: async () => {}
|
|
35789
|
+
};
|
|
35790
|
+
}
|
|
35791
|
+
}
|
|
35792
|
+
/**
|
|
35793
|
+
* 回滚但不覆盖原始错误。
|
|
35794
|
+
* @author ddj 2026年11月24号
|
|
35795
|
+
* @param prep 附件准备结果(可能为空)
|
|
35796
|
+
* @returns 完成后的 Promise
|
|
35797
|
+
*/
|
|
35798
|
+
async function rollbackOf(prep) {
|
|
35799
|
+
if (!prep) return;
|
|
35800
|
+
try {
|
|
35801
|
+
await prep.rollback();
|
|
35802
|
+
} catch {}
|
|
35803
|
+
}
|
|
35804
|
+
/**
|
|
35334
35805
|
* 构造 /html-plan 命令定义(导出便于单测直接调用 handler)。
|
|
35335
35806
|
* @author ddj 2026年11月21号
|
|
35336
35807
|
* @param commands 官方命令运行时
|
|
@@ -35339,10 +35810,14 @@ function messageOf(error) {
|
|
|
35339
35810
|
*/
|
|
35340
35811
|
function htmlPlanCommandDefinition(commands, options = {}) {
|
|
35341
35812
|
const instructionOf = typeof options.instructionOf === "function" ? options.instructionOf : buildHtmlPlanInstruction;
|
|
35813
|
+
const prepareAttachments = typeof options.prepareAttachments === "function" ? options.prepareAttachments : (invocation, task) => stagePlanFiles(options.hostCtx, invocation, task);
|
|
35342
35814
|
return {
|
|
35343
35815
|
name: HTML_PLAN_COMMAND,
|
|
35344
35816
|
description: HTML_PLAN_DESCRIPTION,
|
|
35345
|
-
input: {
|
|
35817
|
+
input: {
|
|
35818
|
+
hint: "<任务描述>(可附图片或文件)",
|
|
35819
|
+
attachments: true
|
|
35820
|
+
},
|
|
35346
35821
|
/** @private @author ddj 2026年11月21号 @param invocation 官方命令调用。 @returns 成功/错误结算。 */
|
|
35347
35822
|
handler: async (invocation) => {
|
|
35348
35823
|
const parsed = parseHtmlPlanInput(invocation?.rawInput);
|
|
@@ -35352,23 +35827,46 @@ function htmlPlanCommandDefinition(commands, options = {}) {
|
|
|
35352
35827
|
text: "无法进入计划模式:官方 /plan 命令不可用"
|
|
35353
35828
|
};
|
|
35354
35829
|
const signal = invocation?.signal instanceof AbortSignal ? invocation.signal : new AbortController().signal;
|
|
35830
|
+
let prep = null;
|
|
35355
35831
|
try {
|
|
35356
|
-
|
|
35357
|
-
|
|
35358
|
-
|
|
35359
|
-
|
|
35360
|
-
|
|
35361
|
-
|
|
35832
|
+
prep = await prepareAttachments(invocation, task);
|
|
35833
|
+
} catch (error) {
|
|
35834
|
+
prep = {
|
|
35835
|
+
slug: null,
|
|
35836
|
+
count: 0,
|
|
35837
|
+
lines: ["附件读取失败:" + messageOf(error)],
|
|
35838
|
+
rollback: async () => {}
|
|
35362
35839
|
};
|
|
35363
|
-
|
|
35364
|
-
|
|
35365
|
-
|
|
35840
|
+
}
|
|
35841
|
+
try {
|
|
35842
|
+
const delegateNote = parsed.delegate === null ? "" : "\n" + (parsed.delegate ? HTML_PLAN_DELEGATE_INSTRUCTION : HTML_PLAN_SINGLE_AGENT_INSTRUCTION);
|
|
35843
|
+
const extras = {
|
|
35844
|
+
slug: prep?.slug ?? null,
|
|
35845
|
+
attachmentLines: prep?.lines ?? []
|
|
35366
35846
|
};
|
|
35847
|
+
const message = task ? instructionOf(task, parsed.delegate, extras) : HTML_PLAN_BARE_INSTRUCTION + delegateNote + (prep?.lines.length ? "\n\n" + prep.lines.join("\n") : "");
|
|
35848
|
+
const execution = await commands.execute(invocation?.agent, "/plan " + message, [], signal);
|
|
35849
|
+
if (!execution) {
|
|
35850
|
+
await rollbackOf(prep);
|
|
35851
|
+
return {
|
|
35852
|
+
kind: "error",
|
|
35853
|
+
text: "无法进入计划模式:官方 /plan 命令不可用"
|
|
35854
|
+
};
|
|
35855
|
+
}
|
|
35856
|
+
if (execution.result?.kind !== "success") {
|
|
35857
|
+
await rollbackOf(prep);
|
|
35858
|
+
return {
|
|
35859
|
+
kind: "error",
|
|
35860
|
+
text: "无法进入计划模式:" + String(execution.result?.text ?? "未知原因")
|
|
35861
|
+
};
|
|
35862
|
+
}
|
|
35863
|
+
const saved = prep && prep.count > 0 && prep.slug ? "(" + String(prep.count) + " 个附件在 plans/" + prep.slug + "/assets/)" : "";
|
|
35367
35864
|
return {
|
|
35368
35865
|
kind: "success",
|
|
35369
|
-
text: task ? "HTML 计划模式已开启:正在生成 HTML 计划页…" : "HTML 计划模式已开启:请描述要规划的任务"
|
|
35866
|
+
text: (task ? "HTML 计划模式已开启:正在生成 HTML 计划页…" : "HTML 计划模式已开启:请描述要规划的任务") + saved
|
|
35370
35867
|
};
|
|
35371
35868
|
} catch (error) {
|
|
35869
|
+
await rollbackOf(prep);
|
|
35372
35870
|
return {
|
|
35373
35871
|
kind: "error",
|
|
35374
35872
|
text: "无法进入计划模式:" + messageOf(error)
|
|
@@ -35398,7 +35896,10 @@ function installHtmlPlanCommand(ctx, options = {}) {
|
|
|
35398
35896
|
log.warn("/html-plan 未注册:commands 服务不支持 register");
|
|
35399
35897
|
return;
|
|
35400
35898
|
}
|
|
35401
|
-
const mount = () => commands.register(htmlPlanCommandDefinition(commands,
|
|
35899
|
+
const mount = () => commands.register(htmlPlanCommandDefinition(commands, {
|
|
35900
|
+
...options,
|
|
35901
|
+
hostCtx: sctx
|
|
35902
|
+
}));
|
|
35402
35903
|
try {
|
|
35403
35904
|
if (typeof commandCtx.effect === "function") commandCtx.effect(mount, "vscode-mode: html-plan command");
|
|
35404
35905
|
else mount();
|