@michengai/dsh-archive-manager 1.0.5 → 1.0.6

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.
@@ -29,6 +29,26 @@ function decodeRepairLog(bytes, compressed) {
29
29
  if (!text.endsWith("\n")) throw new Error("\u65E5\u5FD7\u672B\u5C3E\u4E0D\u5B8C\u6574\uFF0C\u4E0D\u80FD\u81EA\u52A8\u4FEE\u590D");
30
30
  return text.trimEnd().split("\n").map((line) => record(JSON.parse(line)));
31
31
  }
32
+ function pluginSource(plugin, extra = {}) {
33
+ return { kind: "plugin", plugin, ...extra };
34
+ }
35
+ function assertKnownHintShape(source, kind) {
36
+ if (Object.keys(source).some((key) => !["kind", "form"].includes(key)) || source.form !== "hint") throw new Error("\u65E7\u7248\u63D0\u793A\u6765\u6E90 " + kind + " \u5F62\u72B6\u672A\u77E5\uFF0C\u9700\u4EBA\u5DE5\u68C0\u67E5");
37
+ }
38
+ const LEGACY_SOURCE_RULES = [
39
+ { kind: "automation", convert: (source) => pluginSource("dsh-automation", { form: "notice", summary: JSON.stringify(source) }) },
40
+ // 早期工作区参考文档提示,现由 dsh-agent-instructions 承担。不保留 form:hint,v0 插件来源不接受该值。
41
+ { kind: "instruction-hint", convert: (source) => {
42
+ assertKnownHintShape(source, "instruction-hint");
43
+ return pluginSource("agent-instructions");
44
+ } },
45
+ // 早期会话工作约定已被宿主移除,只保留归属,正文不动。
46
+ { kind: "delivery-contract", convert: (source) => {
47
+ assertKnownHintShape(source, "delivery-contract");
48
+ return pluginSource("delivery-contract");
49
+ } }
50
+ ];
51
+ const LEGACY_SOURCE_RULES_BY_KIND = new Map(LEGACY_SOURCE_RULES.map((rule) => [rule.kind, rule]));
32
52
  function normalizeAutomationSources(input) {
33
53
  const rows = structuredClone(input);
34
54
  let count = 0;
@@ -38,11 +58,12 @@ function normalizeAutomationSources(input) {
38
58
  const candidate = message.source;
39
59
  if (!candidate || typeof candidate !== "object") return;
40
60
  const source = record(candidate);
41
- if (source?.kind !== "automation") return;
42
- if (Object.keys(source).some((key) => !["kind", "automationId", "runId", "scheduledFor"].includes(key)) || !["automationId", "runId", "scheduledFor"].every((key) => typeof source[key] === "string" && source[key].length > 0 && source[key].length < 512) || !Number.isFinite(Date.parse(String(source.scheduledFor)))) {
61
+ const rule = typeof source.kind === "string" ? LEGACY_SOURCE_RULES_BY_KIND.get(source.kind) : void 0;
62
+ if (!rule) return;
63
+ if (rule.kind === "automation" && (Object.keys(source).some((key) => !["kind", "automationId", "runId", "scheduledFor"].includes(key)) || !["automationId", "runId", "scheduledFor"].every((key) => typeof source[key] === "string" && source[key].length > 0 && source[key].length < 512) || !Number.isFinite(Date.parse(String(source.scheduledFor))))) {
43
64
  throw new Error("\u81EA\u52A8\u5316\u5F52\u5C5E\u4FE1\u606F\u4E0D\u5B8C\u6574\u6216\u5B58\u5728\u672A\u77E5\u5B57\u6BB5\uFF0C\u9700\u4EBA\u5DE5\u68C0\u67E5");
44
65
  }
45
- message.source = { kind: "plugin", plugin: "dsh-automation", form: "notice", summary: JSON.stringify(source) };
66
+ message.source = rule.convert(source);
46
67
  count++;
47
68
  };
48
69
  for (const row of rows.slice(1)) {
@@ -88,7 +109,7 @@ async function prepareAutomationRepair({ directory, target, sessionId, format })
88
109
  const rows = decodeRepairLog(bytes, source.endsWith(".zstd"));
89
110
  if (rows[0]?.type !== "session" || rows[0]?.version !== 0 || rows[0]?.id !== sessionId) throw new Error("\u65E5\u5FD7\u8EAB\u4EFD\u6216\u7248\u672C\u4E0D\u5339\u914D\uFF0C\u4E0D\u80FD\u81EA\u52A8\u4FEE\u590D");
90
111
  const normalized = normalizeAutomationSources(rows);
91
- if (!normalized.count) throw new Error("\u672A\u627E\u5230\u7B26\u5408\u4FEE\u590D\u89C4\u5219\u7684\u81EA\u52A8\u5316\u6765\u6E90");
112
+ if (!normalized.count) throw new Error("\u672A\u627E\u5230\u7B26\u5408\u4FEE\u590D\u89C4\u5219\u7684\u65E7\u7248\u6765\u6E90");
92
113
  const restore = format.createRestore(normalized.rows[0]);
93
114
  normalized.rows.slice(1).forEach((row) => restore.decodeRow(row));
94
115
  const artifact = restore.finish();
package/lib/workspace.js CHANGED
@@ -413,8 +413,8 @@ var ArchiveWorkspaceRegistry = class extends WorkspaceRegistry {
413
413
  repairable: true,
414
414
  token: plan.token,
415
415
  count: plan.count,
416
- reason: plan.correctingFrame ? "\u53D1\u73B0\u65E7\u7248\u4FEE\u590D\u7684\u538B\u7F29\u5E27\u95EE\u9898\uFF0C\u5DF2\u901A\u8FC7\u5BBF\u4E3B\u8BFB\u53D6\u6821\u9A8C" : `\u53D1\u73B0 ${plan.count} \u5904\u65E7\u81EA\u52A8\u5316\u6765\u6E90\uFF0C\u5DF2\u901A\u8FC7\u5BBF\u4E3B\u683C\u5F0F\u8F6C\u6362\u6821\u9A8C`,
417
- advice: "\u5C06\u6765\u6E90\u8F6C\u6362\u4E3A dsh-automation \u63D2\u4EF6\u5F52\u5C5E\uFF0C\u4FDD\u7559\u4EFB\u52A1\u4FE1\u606F\u4E0E\u6B63\u6587\uFF0C\u751F\u6210\u65B0\u7248\u65E5\u5FD7\uFF1B\u65E7\u65E5\u5FD7\u539F\u6837\u4FDD\u7559\u3002\u8BF7\u786E\u4FDD\u5176\u4ED6 DSH \u8FDB\u7A0B\u672A\u6253\u5F00\u8BE5\u4F1A\u8BDD\u3002"
416
+ reason: plan.correctingFrame ? "\u53D1\u73B0\u65E7\u7248\u4FEE\u590D\u7684\u538B\u7F29\u5E27\u95EE\u9898\uFF0C\u5DF2\u901A\u8FC7\u5BBF\u4E3B\u8BFB\u53D6\u6821\u9A8C" : `\u53D1\u73B0 ${plan.count} \u5904\u65E7\u7248\u6765\u6E90\uFF0C\u5DF2\u901A\u8FC7\u5BBF\u4E3B\u683C\u5F0F\u8F6C\u6362\u6821\u9A8C`,
417
+ advice: "\u5C06\u6765\u6E90\u6539\u5199\u4E3A\u5BBF\u4E3B\u652F\u6301\u7684\u63D2\u4EF6\u5F52\u5C5E\uFF0C\u4FDD\u7559\u6B63\u6587\uFF0C\u751F\u6210\u65B0\u7248\u65E5\u5FD7\uFF1B\u65E7\u65E5\u5FD7\u539F\u6837\u4FDD\u7559\u3002\u8BF7\u786E\u4FDD\u5176\u4ED6 DSH \u8FDB\u7A0B\u672A\u6253\u5F00\u8BE5\u4F1A\u8BDD\u3002"
418
418
  };
419
419
  } catch (error) {
420
420
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@michengai/dsh-archive-manager",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "NPM-installable DSH Web plugin for managing archived sessions.",
5
5
  "type": "module",
6
6
  "packageManager": "pnpm@11.22.0",