@yangda611/dsh-scriptor 8.4.4 → 8.4.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.
package/lib/index.js CHANGED
@@ -10635,6 +10635,10 @@ var require_saxes = __commonJS({
10635
10635
  }
10636
10636
  });
10637
10637
 
10638
+ // src/index.ts
10639
+ import * as skillFilesystem from "@deepseek-ai/dsh-skill-filesystem";
10640
+ import { fileURLToPath } from "node:url";
10641
+
10638
10642
  // ../../node_modules/.pnpm/@deepseek-ai+cosmokit@1.9.0/node_modules/@deepseek-ai/cosmokit/lib/index.js
10639
10643
  function isNullable(value) {
10640
10644
  return value === null || value === void 0;
@@ -29106,6 +29110,7 @@ var MEMORY_CATALOG_SOURCE = "plugin:webnovel-memory-catalog";
29106
29110
  var AUTHOR_SAVE_SOURCE = "plugin:webnovel";
29107
29111
  var EDITOR_REQUEST_SOURCE = "plugin:webnovel-editor";
29108
29112
  var DRAFT_LENGTH_SOURCE = "plugin:webnovel-draft-length";
29113
+ var ORPHAN_REPAIR_SOURCE = "plugin:webnovel-orphan";
29109
29114
  function isMemoryCatalogSource(source2) {
29110
29115
  if (source2.kind === MEMORY_CATALOG_SOURCE) return true;
29111
29116
  return String(source2.kind) === "runtime-context" && "form" in source2 && source2.form === "snapshot" && "sections" in source2 && Array.isArray(source2.sections) && source2.sections.some((section) => section?.name === "webnovel.memory");
@@ -29336,68 +29341,99 @@ function writingAssignmentOf(agent) {
29336
29341
  }
29337
29342
  return void 0;
29338
29343
  }
29344
+ var attachedDelegations = /* @__PURE__ */ new WeakMap();
29345
+ var liveDelegationDisposes = /* @__PURE__ */ new Set();
29346
+ async function disposeAllDelegations() {
29347
+ const disposals = [...liveDelegationDisposes];
29348
+ liveDelegationDisposes.clear();
29349
+ await Promise.all(disposals.map(async (dispose) => {
29350
+ try {
29351
+ await dispose();
29352
+ } catch {
29353
+ }
29354
+ }));
29355
+ }
29339
29356
  function attachWritingDelegationToAgent(agent) {
29357
+ const existing = attachedDelegations.get(agent);
29358
+ if (existing !== void 0) return existing;
29340
29359
  const context = agent.ctx;
29341
29360
  if (typeof context?.inject !== "function") return void 0;
29342
- const fiber = context.inject(["tools"], (scope2) => {
29343
- scope2.effect(function* () {
29344
- let native;
29345
- let off;
29346
- let updating = false;
29347
- const refresh = () => {
29348
- if (updating) return;
29349
- const current = scope2.tools.get("subagent", agent);
29350
- if (current === native) return;
29351
- updating = true;
29352
- try {
29353
- off?.();
29354
- off = void 0;
29355
- native = current;
29356
- if (!current) return;
29357
- const parameters = current.parameters;
29358
- off = scope2.tools.register({
29359
- ...current,
29360
- name: WRITING_DELEGATE_TOOL,
29361
- description: "\u59D4\u6D3E\u5C0F\u8BF4\u751F\u4EA7\u4EFB\u52A1\uFF0C\u6309 role \u7ED1\u5B9A\u8BE5\u5B9E\u4F8B\u7684\u89C4\u7EA6\u548C\u6743\u9650\u3002drafting \u4E3A\u8D77\u8349\uFF0Cpolish \u4E3A\u6DA6\u8272\uFF0Crevision \u4E3A\u6539\u7A3F\u3002review \u4E3A\u5BA1\u8BFB\uFF0Csettle \u4E3A\u6C89\u6DC0\u5BF9\u8D26\u3002screenplay \u4E3A\u7535\u5F71\u5267\u672C\u6539\u7F16\uFF0Cshortdrama \u4E3A\u77ED\u5267\u7BA1\u7EBF\u3002\u660E\u786E\u76EE\u6807\u4E66\u548C\u7AE0\u8282\u65F6\u586B\u5199 bookId\u3001chapter\uFF0C\u4F9B\u8FDB\u5EA6\u5F52\u5C5E\uFF1B\u672A\u660E\u786E\u65F6\u4E0D\u8981\u731C\u586B\u3002\u666E\u901A\u7814\u7A76\u548C\u5DE5\u5177\u4EFB\u52A1\u4F7F\u7528 subagent\u3002\n" + current.description,
29362
- parameters: {
29363
- ...current.parameters,
29364
- properties: {
29365
- ...parameters.properties,
29366
- role: { type: "string", enum: [...WRITING_ROLES] },
29367
- bookId: { type: "string", description: "\u5DF2\u660E\u786E\u7684\u76EE\u6807\u4E66id\uFF1B\u4EC5\u7528\u4E8E\u4EFB\u52A1\u5F52\u5C5E" },
29368
- chapter: { type: "integer", minimum: 1, description: "\u5DF2\u660E\u786E\u7684\u5168\u4E66\u7AE0\u53F7\uFF1B\u4EC5\u7528\u4E8E\u4EFB\u52A1\u5F52\u5C5E" }
29361
+ let fiber;
29362
+ try {
29363
+ fiber = context.inject(["tools"], (scope2) => {
29364
+ const host2 = scope2;
29365
+ if (typeof host2.effect !== "function" || typeof host2.tools !== "object" || host2.tools === null) return;
29366
+ scope2.effect(function* () {
29367
+ let native;
29368
+ let off;
29369
+ let updating = false;
29370
+ const refresh = () => {
29371
+ if (updating) return;
29372
+ const current = scope2.tools.get("subagent", agent);
29373
+ const registered = scope2.tools.get(WRITING_DELEGATE_TOOL, agent);
29374
+ if (current === native && registered) return;
29375
+ updating = true;
29376
+ try {
29377
+ off?.();
29378
+ off = void 0;
29379
+ native = current;
29380
+ if (!current) return;
29381
+ const parameters = current.parameters;
29382
+ off = scope2.tools.register({
29383
+ ...current,
29384
+ name: WRITING_DELEGATE_TOOL,
29385
+ description: "\u59D4\u6D3E\u5C0F\u8BF4\u751F\u4EA7\u4EFB\u52A1\uFF0C\u6309 role \u7ED1\u5B9A\u8BE5\u5B9E\u4F8B\u7684\u89C4\u7EA6\u548C\u6743\u9650\u3002drafting \u4E3A\u8D77\u8349\uFF0Cpolish \u4E3A\u6DA6\u8272\uFF0Crevision \u4E3A\u6539\u7A3F\u3002review \u4E3A\u5BA1\u8BFB\uFF0Csettle \u4E3A\u6C89\u6DC0\u5BF9\u8D26\u3002screenplay \u4E3A\u7535\u5F71\u5267\u672C\u6539\u7F16\uFF0Cshortdrama \u4E3A\u77ED\u5267\u7BA1\u7EBF\u3002\u660E\u786E\u76EE\u6807\u4E66\u548C\u7AE0\u8282\u65F6\u586B\u5199 bookId\u3001chapter\uFF0C\u4F9B\u8FDB\u5EA6\u5F52\u5C5E\uFF1B\u672A\u660E\u786E\u65F6\u4E0D\u8981\u731C\u586B\u3002\u666E\u901A\u7814\u7A76\u548C\u5DE5\u5177\u4EFB\u52A1\u4F7F\u7528 subagent\u3002\n" + current.description,
29386
+ parameters: {
29387
+ ...current.parameters,
29388
+ properties: {
29389
+ ...parameters.properties,
29390
+ role: { type: "string", enum: [...WRITING_ROLES] },
29391
+ bookId: { type: "string", description: "\u5DF2\u660E\u786E\u7684\u76EE\u6807\u4E66id\uFF1B\u4EC5\u7528\u4E8E\u4EFB\u52A1\u5F52\u5C5E" },
29392
+ chapter: { type: "integer", minimum: 1, description: "\u5DF2\u660E\u786E\u7684\u5168\u4E66\u7AE0\u53F7\uFF1B\u4EC5\u7528\u4E8E\u4EFB\u52A1\u5F52\u5C5E" }
29393
+ },
29394
+ required: [...parameters.required ?? [], "role"]
29369
29395
  },
29370
- required: [...parameters.required ?? [], "role"]
29371
- },
29372
- execute(args, exec) {
29373
- const { role: role2, bookId: bookId2, chapter: chapter2, ...task } = args;
29374
- if (!isRole(role2) || typeof task["prompt"] !== "string" || exec.agent !== agent) {
29375
- throw new Error("\u5199\u4F5C\u59D4\u6D3E\u987B\u6307\u5B9A\u6709\u6548 role\u3001\u4EFB\u52A1 prompt \u548C\u5F53\u524D\u4E3B\u63A7\u3002");
29376
- }
29377
- if (bookId2 !== void 0 && (typeof bookId2 !== "string" || !bookId2.trim() || bookId2.length > 256 || /[\r\n<>]/.test(bookId2)) || chapter2 !== void 0 && (typeof chapter2 !== "number" || !Number.isSafeInteger(chapter2) || chapter2 < 1)) throw new Error("\u59D4\u6D3E\u7684\u4E66id\u6216\u7AE0\u53F7\u65E0\u6548");
29378
- const assignment = { ...typeof bookId2 === "string" ? { bookId: bookId2.trim() } : {}, ...typeof chapter2 === "number" ? { chapter: chapter2 } : {} };
29379
- const attribution = Object.keys(assignment).length ? `<!-- scriptor-assignment:v1:${JSON.stringify(assignment)} -->
29396
+ execute(args, exec) {
29397
+ const { role: role2, bookId: bookId2, chapter: chapter2, ...task } = args;
29398
+ if (!isRole(role2) || typeof task["prompt"] !== "string" || exec.agent !== agent) {
29399
+ throw new Error("\u5199\u4F5C\u59D4\u6D3E\u987B\u6307\u5B9A\u6709\u6548 role\u3001\u4EFB\u52A1 prompt \u548C\u5F53\u524D\u4E3B\u63A7\u3002");
29400
+ }
29401
+ if (bookId2 !== void 0 && (typeof bookId2 !== "string" || !bookId2.trim() || bookId2.length > 256 || /[\r\n<>]/.test(bookId2)) || chapter2 !== void 0 && (typeof chapter2 !== "number" || !Number.isSafeInteger(chapter2) || chapter2 < 1)) throw new Error("\u59D4\u6D3E\u7684\u4E66id\u6216\u7AE0\u53F7\u65E0\u6548");
29402
+ const assignment = { ...typeof bookId2 === "string" ? { bookId: bookId2.trim() } : {}, ...typeof chapter2 === "number" ? { chapter: chapter2 } : {} };
29403
+ const attribution = Object.keys(assignment).length ? `<!-- scriptor-assignment:v1:${JSON.stringify(assignment)} -->
29380
29404
  ` : "";
29381
- return creationRole.run({ parent: agent, role: role2, ...assignment }, () => current.execute({
29382
- ...task,
29383
- prompt: marker(role2) + attribution + task["prompt"]
29384
- }, exec));
29385
- }
29386
- });
29387
- } finally {
29388
- updating = false;
29389
- }
29390
- };
29391
- yield () => {
29392
- off?.();
29393
- };
29394
- yield scope2.on("tools/change", refresh);
29395
- refresh();
29405
+ return creationRole.run({ parent: agent, role: role2, ...assignment }, () => current.execute({
29406
+ ...task,
29407
+ prompt: marker(role2) + attribution + task["prompt"]
29408
+ }, exec));
29409
+ }
29410
+ });
29411
+ } finally {
29412
+ updating = false;
29413
+ }
29414
+ };
29415
+ yield () => {
29416
+ off?.();
29417
+ };
29418
+ yield scope2.on("tools/change", refresh);
29419
+ refresh();
29420
+ });
29396
29421
  });
29397
- });
29398
- return async () => {
29422
+ } catch {
29423
+ return void 0;
29424
+ }
29425
+ if (fiber === void 0 || typeof fiber.dispose !== "function") return void 0;
29426
+ let disposed = false;
29427
+ const dispose = async () => {
29428
+ if (disposed) return;
29429
+ disposed = true;
29430
+ attachedDelegations.delete(agent);
29431
+ liveDelegationDisposes.delete(dispose);
29399
29432
  await fiber.dispose();
29400
29433
  };
29434
+ attachedDelegations.set(agent, dispose);
29435
+ liveDelegationDisposes.add(dispose);
29436
+ return dispose;
29401
29437
  }
29402
29438
 
29403
29439
  // src/agent-mode.ts
@@ -29412,9 +29448,6 @@ function writingCapabilityOf(agent) {
29412
29448
  return void 0;
29413
29449
  }
29414
29450
  }
29415
- function isWritingAgent(agent) {
29416
- return writingCapabilityOf(agent) !== void 0;
29417
- }
29418
29451
 
29419
29452
  // src/status-context.ts
29420
29453
  import { createUserMessage as createUserMessage2 } from "@deepseek-ai/dsh-llm";
@@ -32866,7 +32899,7 @@ function createNovelTools(deps) {
32866
32899
  },
32867
32900
  {
32868
32901
  name: "novel_create_book",
32869
- description: "\u65B0\u5EFA\u4E00\u90E8\u957F\u7BC7\u5C0F\u8BF4\u5E76\u521D\u59CB\u5316\u89C4\u8303\u4E66\u4ED3\u3002\u524D\u7F6E\u8981\u6C42\uFF1A\u4E03\u4E2A\u6784\u60F3\u5B57\u6BB5\u9F50\u5168\u3001\u6838\u5FC3\u521B\u610F\u4E0E\u9898\u6750\u76EE\u6807\u8BFB\u8005\u660E\u786E\uFF0C\u5176\u4F59\u53EF\u7559\u767D\uFF1B\u4F5C\u8005\u5DF2\u786E\u8BA4\u7ACB\u9879\u3002\u5EFA\u4E66\u524D\u5FC5\u987B\u5148\u95EE\u4F5C\u8005\u4E09\u4E2A\u95EE\u9898\u518D\u8C03\uFF0C\u7F3A\u4EFB\u4F55\u4E00\u4E2A\u90FD\u4F1A\u88AB\u76F4\u63A5\u62D2\u7EDD\uFF1A\u8FD9\u4E2A\u9879\u76EE\u9762\u5411\u6D77\u5916\u8FD8\u662F\u4E2D\u6587\u5E02\u573A\uFF08\u5E02\u573A\uFF09\uFF0C\u8981\u51FA\u77ED\u5267\u3001\u7535\u5F71\u5267\u672C\u8FD8\u662F\u5C0F\u8BF4\uFF08\u8F93\u51FA\u5F62\u6001\uFF09\uFF0C\u8FD9\u672C\u4E66\u76EE\u6807\u5199\u591A\u5C11\u5B57\uFF08\u76EE\u6807\u603B\u5B57\u6570\uFF0C\u6C49\u5B57\u6570\uFF09\u3002\u4E09\u4E2A\u503C\u7F3A\u4E00\u4E0D\u53EF\uFF1B\u4F5C\u8005\u660E\u786E\u8BF4\u201C\u5C31\u6309\u9ED8\u8BA4\u6765\u201D\u624D\u4F20\u9ED8\u8BA4\uFF08\u4E2D\u6587 / \u5C0F\u8BF4 / 100\u4E07\u5B57\uFF09\uFF0C\u4E0D\u8981\u7528\u9ED8\u8BA4\u503C\u6084\u6084\u5EFA\u4E66\u3002\u4F5C\u8005\u4E5F\u53EF\u4EE5\u5728\u4E66\u623F\u9762\u677F\u70B9\u201C\u65B0\u5EFA\u4E66\u201D\u76F4\u63A5\u70B9\u9009\uFF0C\u9009\u597D\u540E\u4E0D\u7528\u5728\u804A\u5929\u91CC\u518D\u95EE\u3002",
32902
+ description: "\u65B0\u5EFA\u4E00\u90E8\u957F\u7BC7\u5C0F\u8BF4\u5E76\u521D\u59CB\u5316\u89C4\u8303\u4E66\u4ED3\u3002\u524D\u7F6E\u8981\u6C42\uFF1A\u4E03\u4E2A\u6784\u60F3\u5B57\u6BB5\u9F50\u5168\u3001\u6838\u5FC3\u521B\u610F\u4E0E\u9898\u6750\u76EE\u6807\u8BFB\u8005\u660E\u786E\uFF0C\u5176\u4F59\u53EF\u7559\u767D\uFF1B\u4F5C\u8005\u5DF2\u786E\u8BA4\u7ACB\u9879\u3002\u5EFA\u4E66\u524D\u5FC5\u987B\u5148\u95EE\u4F5C\u8005\u4E09\u4E2A\u95EE\u9898\u518D\u8C03\uFF0C\u7F3A\u4EFB\u4F55\u4E00\u4E2A\u90FD\u4F1A\u88AB\u76F4\u63A5\u62D2\u7EDD\uFF1A\u8FD9\u4E2A\u9879\u76EE\u9762\u5411\u6D77\u5916\u8FD8\u662F\u4E2D\u6587\u5E02\u573A\uFF08\u5E02\u573A\uFF09\uFF0C\u8981\u51FA\u77ED\u5267\u3001\u7535\u5F71\u5267\u672C\u8FD8\u662F\u5C0F\u8BF4\uFF08\u8F93\u51FA\u5F62\u6001\uFF09\uFF0C\u8FD9\u672C\u4E66\u76EE\u6807\u5199\u591A\u5C11\u5B57\uFF08\u76EE\u6807\u603B\u5B57\u6570\uFF0C\u6C49\u5B57\u6570\uFF09\u3002\u4E09\u4E2A\u503C\u7F3A\u4E00\u4E0D\u53EF\uFF1B\u4F5C\u8005\u660E\u786E\u8BF4\u201C\u5C31\u6309\u9ED8\u8BA4\u6765\u201D\u624D\u4F20\u9ED8\u8BA4\uFF08\u4E2D\u6587 / \u5C0F\u8BF4 / 100\u4E07\u5B57\uFF09\uFF0C\u4E0D\u8981\u7528\u9ED8\u8BA4\u503C\u6084\u6084\u5EFA\u4E66\u3002\u4F5C\u8005\u4E5F\u53EF\u4EE5\u5728\u4E66\u623F\u9762\u677F\u70B9\u201C\u65B0\u5EFA\u4E66\u201D\u76F4\u63A5\u70B9\u9009\uFF0C\u9009\u597D\u540E\u4E0D\u7528\u5728\u804A\u5929\u91CC\u518D\u95EE\u3002\u5EFA\u4E66\u53EA\u80FD\u8C03\u672C\u5DE5\u5177\uFF0C\u7981\u6B62\u7528\u6587\u4EF6\u5DE5\u5177\u624B\u5199\u4E66\u7C4D\u4FE1\u606F\u3001\u5927\u7EB2\u6216\u7AE0\u8282\u6587\u4EF6\u6765\u5192\u5145\u5EFA\u4E66\u3002\u5982\u679C\u5F53\u524D\u4F1A\u8BDD\u6CA1\u6709\u672C\u5DE5\u5177\uFF0C\u660E\u786E\u544A\u8BC9\u4F5C\u8005\u6CA1\u6709\u5EFA\u4E66\u5DE5\u5177\uFF0C\u4E0D\u8981\u624B\u5199\u4E66\u7A3F\u6587\u4EF6\u3002",
32870
32903
  parameters: {
32871
32904
  type: "object",
32872
32905
  properties: {
@@ -35924,6 +35957,36 @@ function fieldLabel(text5) {
35924
35957
  const version = typeof fields["\u7248\u672C"] === "number" || typeof fields["\u7248\u672C"] === "string" ? fields["\u7248\u672C"] : null;
35925
35958
  return { badge, version };
35926
35959
  }
35960
+ var ORPHAN_SIGNALS = ["\u4E66\u7C4D\u4FE1\u606F.json", "\u6545\u4E8B\u5927\u7EB2.md", "\u5927\u7EB2.md"];
35961
+ function orphanSignals(dir) {
35962
+ let entries;
35963
+ try {
35964
+ entries = fs62.readdirSync(dir);
35965
+ } catch {
35966
+ return void 0;
35967
+ }
35968
+ const found = entries.filter((name3) => ORPHAN_SIGNALS.includes(name3) || /^第.+章/.test(name3)).sort();
35969
+ return found.length > 0 ? found : void 0;
35970
+ }
35971
+ function scanOrphanDrafts(workspace, bookNames) {
35972
+ const orphans = [];
35973
+ const scanLevel = (parent, prefix, skip) => {
35974
+ let entries;
35975
+ try {
35976
+ entries = fs62.readdirSync(parent, { withFileTypes: true });
35977
+ } catch {
35978
+ return;
35979
+ }
35980
+ for (const entry of entries) {
35981
+ if (!entry.isDirectory() || skip.has(entry.name)) continue;
35982
+ const signals = orphanSignals(path73.join(parent, entry.name));
35983
+ if (signals !== void 0) orphans.push({ name: entry.name, path: prefix + entry.name, detail: `\u542B ${signals.join("\u3001")}` });
35984
+ }
35985
+ };
35986
+ scanLevel(workspace, "", /* @__PURE__ */ new Set([...bookNames, "\u4E66\u623F"]));
35987
+ scanLevel(path73.join(workspace, "\u4E66\u623F"), "\u4E66\u623F/", /* @__PURE__ */ new Set());
35988
+ return orphans;
35989
+ }
35927
35990
  var StudyService = class {
35928
35991
  workspace;
35929
35992
  constructor(workspace) {
@@ -35960,7 +36023,8 @@ var StudyService = class {
35960
36023
  } catch (error) {
35961
36024
  if (error.code !== "ENOENT" && !(error instanceof AuthorDocumentError && error.code === "not-found")) sharedError = error instanceof Error ? error.message : "\u5171\u4EAB\u8D44\u6599\u4E0D\u53EF\u8BBF\u95EE";
35962
36025
  }
35963
- return { workspace: this.workspace, books, shared, ...sharedError ? { sharedError } : {} };
36026
+ const orphans = scanOrphanDrafts(this.workspace, new Set(scanned.map((book) => book.name)));
36027
+ return { workspace: this.workspace, books, shared, ...sharedError ? { sharedError } : {}, orphans };
35964
36028
  }
35965
36029
  /** 建书向导(8.4.4):读待建书草稿——书房面板点选的答案,novel_create_book 找不到参数时作后备。 */
35966
36030
  readOnboarding() {
@@ -36766,7 +36830,7 @@ function agentList(registry2) {
36766
36830
  return [];
36767
36831
  }
36768
36832
  var STUDY_API_PATH = "/api/webnovel/study/";
36769
- var METHODS = ["shelf", "tree", "read", "resolve", "search", "chapters", "graph", "graph-view", "graph-preview", "graph-control", "book-inspection", "workflow", "save", "notify", "retry-commit", "index-status", "index-control", "ask", "ask-cancel", "suggestions", "onboarding"];
36833
+ var METHODS = ["shelf", "tree", "read", "resolve", "search", "chapters", "graph", "graph-view", "graph-preview", "graph-control", "book-inspection", "workflow", "save", "notify", "retry-commit", "index-status", "index-control", "ask", "ask-cancel", "suggestions", "onboarding", "orphan-repair"];
36770
36834
  function graphReaderRequest(input) {
36771
36835
  const result = {};
36772
36836
  for (const key of ["person", "query", "cluster", "relation", "groupField", "evidenceId"]) if (input[key] !== void 0) {
@@ -37083,6 +37147,19 @@ function createStudyHandler(runtime, indexing, workflow = new WorkflowObserver()
37083
37147
  else throw new AuthorDocumentError("invalid-document", "\u672A\u77E5\u7684\u5411\u5BFC\u64CD\u4F5C");
37084
37148
  break;
37085
37149
  }
37150
+ case "orphan-repair": {
37151
+ const relPath = stringOf(input, "path");
37152
+ const orphan = (service.shelf().orphans ?? []).find((item) => item.path === relPath);
37153
+ if (!orphan) throw new AuthorDocumentError("not-found", "\u6CA1\u6709\u627E\u5230\u8FD9\u4E2A\u672A\u6309\u89C4\u8303\u5EFA\u7ACB\u7684\u4E66\u7A3F\u76EE\u5F55\uFF0C\u8BF7\u5237\u65B0\u4E66\u623F\u540E\u91CD\u8BD5");
37154
+ const message = `\u4E66\u623F\u53D1\u73B0\u672A\u6309\u89C4\u8303\u5EFA\u7ACB\u7684\u4E66\u7A3F\u76EE\u5F55\u300A${orphan.name}\u300B\uFF08${orphan.path}\uFF0C${orphan.detail}\uFF09\uFF0C\u7F3A\u4F5C\u54C1\u5951\u7EA6\uFF08\u4F5C\u54C1\u5951\u7EA6/\u5951\u7EA6.md\uFF09\uFF0C\u6240\u4EE5\u6CA1\u51FA\u73B0\u5728\u300C\u6211\u7684\u4F5C\u54C1\u300D\u91CC\u3002\u8BF7\u7528 novel_create_book \u91CD\u65B0\u5EFA\u4E66\uFF08\u4E66\u540D\u3001\u5E02\u573A\u3001\u8F93\u51FA\u5F62\u6001\u3001\u76EE\u6807\u603B\u5B57\u6570\u5148\u95EE\u4F5C\u8005\uFF0C\u4E66\u623F\u5411\u5BFC\u5DF2\u4FDD\u5B58\u7684\u9009\u62E9\u76F4\u63A5\u7528\uFF09\uFF0C\u518D\u628A\u5DF2\u6709\u5185\u5BB9\uFF08\u5927\u7EB2\u3001\u7AE0\u8282\uFF09\u6309\u89C4\u8303\u8FC1\u8FDB\u65B0\u4E66\u4ED3\uFF1B\u8FC1\u5B8C\u544A\u8BC9\u4F5C\u8005\u4E66\u5DF2\u51FA\u73B0\u5728\u300C\u6211\u7684\u4F5C\u54C1\u300D\u91CC\u3002\u5982\u679C\u5DF2\u6709\u5185\u5BB9\u4E0D\u503C\u5F97\u8FC1\uFF0C\u4E5F\u8BF7\u660E\u786E\u544A\u8BC9\u4F5C\u8005\uFF0C\u4E0D\u8981\u624B\u5199\u6587\u4EF6\u5192\u5145\u5EFA\u4E66\u3002`;
37155
+ try {
37156
+ agent.followup(createUserMessage3({ content: [{ type: "text", text: message }], source: { kind: ORPHAN_REPAIR_SOURCE } }));
37157
+ } catch {
37158
+ throw new Error("\u4E3B\u63A7\u6CA1\u6709\u6536\u5230\u8BF7\u6C42");
37159
+ }
37160
+ value = { requested: true, path: orphan.path };
37161
+ break;
37162
+ }
37086
37163
  default:
37087
37164
  return reply(404, { ok: false, code: "not-found", error: "\u672A\u77E5\u4E66\u623F\u64CD\u4F5C" });
37088
37165
  }
@@ -37131,7 +37208,7 @@ function attachStudyWeb(ctx, indexing, editorRequests = new EditorRequestHub())
37131
37208
  observation[Symbol.dispose]();
37132
37209
  }
37133
37210
  };
37134
- const handler = createStudyHandler(scope2, indexing, workflow, editorRequests, (agent) => isWritingAgent(agent), readChild);
37211
+ const handler = createStudyHandler(scope2, indexing, workflow, editorRequests, () => true, readChild);
37135
37212
  for (const method of METHODS) {
37136
37213
  scope2.connection.fetch.register({ path: STUDY_API_PATH + method, methods: ["POST"], requestBody: "streaming", fetch: handler });
37137
37214
  }
@@ -38854,6 +38931,16 @@ function apply(ctx, entry) {
38854
38931
  }
38855
38932
  };
38856
38933
  if (typeof ctx.provide === "function") ctx.provide("webnovelHost", writingHost);
38934
+ step(ctx, "webnovel:bundled-skills", () => {
38935
+ const fiber = typeof ctx.plugin === "function" ? ctx.plugin(skillFilesystem, {
38936
+ providerName: "webnovel-bundled",
38937
+ includeDefaultRoots: true,
38938
+ bundledSkillDir: fileURLToPath(new URL("../skills/", import.meta.url))
38939
+ }) : void 0;
38940
+ return () => {
38941
+ void fiber?.dispose?.();
38942
+ };
38943
+ });
38857
38944
  const installedAgents = /* @__PURE__ */ new Map();
38858
38945
  const installedModes = /* @__PURE__ */ new Map();
38859
38946
  const installedRoles = /* @__PURE__ */ new Map();
@@ -38898,7 +38985,7 @@ function apply(ctx, entry) {
38898
38985
  const registry2 = typeof ctx.get === "function" ? ctx.get("workspaceRegistry") : void 0;
38899
38986
  return [
38900
38987
  ...(typeof registry2?.list === "function" ? registry2.list() : []).flatMap((workspace) => workspace.path ? [workspace.path] : []),
38901
- ...[...installedAgents.values()].filter((agent) => isMainAgent(agent) && isWritingAgent(agent)).flatMap((agent) => {
38988
+ ...[...installedAgents.values()].filter((agent) => isMainAgent(agent)).flatMap((agent) => {
38902
38989
  const root = agentWorkspaceRoot(agent);
38903
38990
  return root ? [root] : [];
38904
38991
  })
@@ -38909,7 +38996,7 @@ function apply(ctx, entry) {
38909
38996
  const roots = agentRoots(registry2);
38910
38997
  const candidates = roots.length > 0 ? roots : agentList(registry2);
38911
38998
  const agent = candidates.find((candidate) => (candidate.id === notice.sessionId || candidate.session?.header?.id === notice.sessionId) && registry2?.get(candidate.id) === candidate);
38912
- if (!agent || !isMainAgent(agent) || !isWritingAgent(agent) || !agent.session?.header || typeof agent.followup !== "function") return false;
38999
+ if (!agent || !isMainAgent(agent) || !agent.session?.header || typeof agent.followup !== "function") return false;
38913
39000
  if (bookRootOfBookIdFor(book.bookId, agent) !== book.root) return false;
38914
39001
  return notifySaved(agent, indexFailureMessage(book, notice)).notification === "delivered";
38915
39002
  }
@@ -38985,7 +39072,6 @@ function apply(ctx, entry) {
38985
39072
  };
38986
39073
  }
38987
39074
  function registerToolsInto(agent) {
38988
- if (!isWritingAgent(agent)) return false;
38989
39075
  if (toolKit === void 0) return false;
38990
39076
  if (agentToolOffs.has(agent.id)) return true;
38991
39077
  const registry2 = agentCtxGet(agent, "tools");
@@ -39024,7 +39110,6 @@ function apply(ctx, entry) {
39024
39110
  agentRestrictOffs.clear();
39025
39111
  }
39026
39112
  function restrictNovelToolsInto(agent) {
39027
- if (!isWritingAgent(agent) && writingRoleOf(agent) === void 0) return false;
39028
39113
  if (toolKit === void 0) return false;
39029
39114
  if (agentRestrictOffs.has(agent.id)) return true;
39030
39115
  const tools = agentCtxGet(agent, "tools");
@@ -39111,25 +39196,26 @@ function apply(ctx, entry) {
39111
39196
  const attached = [];
39112
39197
  attachments.set(agentId, attached);
39113
39198
  const rootOf = () => agentWorkspaceRoot(agent);
39114
- if (capability !== void 0 && !isSubagent) {
39199
+ if (!isSubagent) {
39115
39200
  const workspace = rootOf();
39116
39201
  if (workspace) indexing.addWorkspace(workspace);
39117
- try {
39118
- const offPersona = attachPersonaToAgent(agentCtx, void 0, { logger: ctx.logger });
39119
- if (offPersona !== void 0) attached.push(offPersona);
39120
- } catch (err) {
39121
- ctx.logger.warn(`[webnovel-bundle] persona \u6302\u8F7D\u5931\u8D25\uFF08${agentId}\uFF09\uFF1A${err instanceof Error ? err.message : String(err)}`);
39122
- }
39123
- try {
39124
- const offStatus = attachStatusToAgent(agentCtx, { workspaceRoot: rootOf });
39125
- if (offStatus !== void 0) attached.push(offStatus);
39126
- } catch (err) {
39127
- ctx.logger.warn(`[webnovel-bundle] \u72B6\u6001\u6CE8\u5165\u6302\u8F7D\u5931\u8D25\uFF08${agentId}\uFF09\uFF1A${err instanceof Error ? err.message : String(err)}`);
39128
- }
39129
39202
  registerToolsInto(agent);
39130
- const offDelegation = attachWritingDelegationToAgent(agent);
39131
- if (offDelegation !== void 0) attached.push(offDelegation);
39132
- } else if (isSubagent && (capability !== void 0 || role2 !== void 0)) {
39203
+ attachWritingDelegationToAgent(agent);
39204
+ if (capability !== void 0) {
39205
+ try {
39206
+ const offPersona = attachPersonaToAgent(agentCtx, void 0, { logger: ctx.logger });
39207
+ if (offPersona !== void 0) attached.push(offPersona);
39208
+ } catch (err) {
39209
+ ctx.logger.warn(`[webnovel-bundle] persona \u6302\u8F7D\u5931\u8D25\uFF08${agentId}\uFF09\uFF1A${err instanceof Error ? err.message : String(err)}`);
39210
+ }
39211
+ try {
39212
+ const offStatus = attachStatusToAgent(agentCtx, { workspaceRoot: rootOf });
39213
+ if (offStatus !== void 0) attached.push(offStatus);
39214
+ } catch (err) {
39215
+ ctx.logger.warn(`[webnovel-bundle] \u72B6\u6001\u6CE8\u5165\u6302\u8F7D\u5931\u8D25\uFF08${agentId}\uFF09\uFF1A${err instanceof Error ? err.message : String(err)}`);
39216
+ }
39217
+ }
39218
+ } else {
39133
39219
  restrictNovelToolsInto(agent);
39134
39220
  const offWorker = role2 === void 0 ? void 0 : attachWorkerPolicyToAgent(agent, role2);
39135
39221
  if (offWorker !== void 0) attached.push(offWorker);
@@ -39221,6 +39307,7 @@ function apply(ctx, entry) {
39221
39307
  await Promise.all([...installedAgents.values()].map((agent) => detachAgent(agent)));
39222
39308
  await Promise.all(detachJobs);
39223
39309
  disposeAllAgentTools();
39310
+ await disposeAllDelegations();
39224
39311
  await agentsReg.fiber?.dispose?.();
39225
39312
  await presetReg.fiber?.dispose?.();
39226
39313
  };
@@ -39246,6 +39333,7 @@ function apply(ctx, entry) {
39246
39333
  if (!toolsReg.reactive) registerAllInstalled(ctx);
39247
39334
  return () => {
39248
39335
  disposeAllAgentTools();
39336
+ void disposeAllDelegations();
39249
39337
  void toolsReg.fiber?.dispose?.();
39250
39338
  };
39251
39339
  });
package/lib/preset.js CHANGED
@@ -2,19 +2,12 @@ import { createRequire as __createRequire } from 'node:module'
2
2
  const require = __createRequire(import.meta.url)
3
3
 
4
4
  // src/preset.ts
5
- import * as skillFilesystem from "@deepseek-ai/dsh-skill-filesystem";
6
- import { fileURLToPath } from "node:url";
7
5
  var name = "scriptor-writing-preset";
8
6
  var inject = ["skills", "webnovelHost"];
9
7
  function apply(ctx) {
10
8
  const capability = { mode: "writing", disposed: false };
11
9
  ctx.provide("webnovelWriting", capability);
12
10
  const host = ctx.webnovelHost;
13
- ctx.plugin(skillFilesystem, {
14
- providerName: "webnovel-bundled",
15
- includeDefaultRoots: true,
16
- bundledSkillDir: fileURLToPath(new URL("../skills/", import.meta.url))
17
- });
18
11
  const changed = async () => {
19
12
  try {
20
13
  ctx.root.emit("webnovel/writing-capability-updated");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yangda611/dsh-scriptor",
3
- "version": "8.4.4",
3
+ "version": "8.4.6",
4
4
  "type": "module",
5
5
  "main": "./lib/index.js",
6
6
  "exports": {
@@ -235,6 +235,8 @@ user-invocable: false
235
235
 
236
236
  小说生产任务使用 `novel_delegate`,保留原生委派参数,必须按下表传 `role`。运行时只向该实例注入对应规约和工具权限;普通研究、工具诊断仍使用原生 `subagent`,不会因标题提到写作而受到这些限制。
237
237
 
238
+ 工具自查节制:确认插件或工具状态时,不要反复调用 `plugin_manager` 的只读查询(list_plugins/list_bundles)——每次调用都要重新走 danger-full-access 审批,会卡在审批循环里。一次调用后用结果;版本信息优先读插件包内文件。
239
+
238
240
  | 任务 | role | 子代理交付权限 |
239
241
  | --- | --- | --- |
240
242
  | 正文起草 | `drafting` | 原生读写与搜索;起草篇幅调整规则 |
@@ -31,12 +31,13 @@ user-invocable: false
31
31
  3. **呈报确认**:七要素整理为构想草案,用通用写工具落 `<工作范围>/书房/构想/<书名或代称>.md`,再呈作者;获明确同意后调 `novel_create_book`,七个要素字段一个不缺地给全,`concept.状态` 必须为「已确认」。
32
32
 
33
33
  **建书前先定市场、输出形态与目标总字数**(调 `novel_create_book` 之前,**三项放在同一条消息里一次问完**,各给选项,大白话,别用术语;**三项是硬关卡**:缺任何一项工具都会直接拒绝,不许用默认值悄悄建书——默认值只在作者明确说“就按默认来”时才用):
34
+ - **先查书房面板的答案再问**:问之前先用读工具看 `<工作范围>/书房/构想/_待建书.json`(书房面板“新建书”向导保存的答案)。三项都在文件里就直接用文件里的值,**不要在聊天里再问一遍**;缺哪项只问缺的那项;问的时候预选值用文件里已有的值,**不要用下面技能内置的默认值(长篇·100万字)当预选**。文件不存在或三项不全时,才按下面三项一次问完。建书成功后这个文件会被消费删除,下一本书重新选。
34
35
  - 市场——“这个项目面向海外还是中文市场?”:1. 中文(★推荐,默认)——给国内观众,用中文题材库(赘婿、战神、霸总等);2. 海外——给海外观众,用海外题材库(狼人、亿万富翁、黑手党等);3. 自己有想法,手动输入。作者不选默认 `中文`。
35
36
  - 输出形态——“要出短剧、电影剧本还是小说?”:1. 小说(★推荐,默认)——长篇小说,走原来的写章流程;2. 短剧——一集一集的短剧,走分集大纲 → 单集剧本 → 审读;3. 电影剧本——一部电影的剧本,走故事稿 → 分场大纲 → 剧本草稿 → 审读;4. 自己有想法,手动输入。作者不选默认 `小说`。
36
37
  - 目标总字数——“这本书目标写多少字?”:1. 短篇·5万字;2. 中篇·30万字;3. 长篇·100万字(★推荐,默认);4. 超长篇·200万字;5. 自己有想法,手动输入具体数字。作者不选默认 `100万字`。这个数写进作品契约 frontmatter(`目标总字数`),用来规划篇幅;每章的字数另在定调时商定(`章节篇幅`),不是同一个数。
37
38
  - **书房面板也能点**:作者可以在书房面板点“新建书”,三项点选卡片点三下就保存好;选好后聊天里不用再问,直接调 `novel_create_book` 即可(工具会读取面板保存的选择)。作者在面板选好后,不要在聊天里重复问。
38
39
  - 三项一旦写入作品契约 frontmatter(`市场` / `输出形态` / `目标总字数`),建书后不再静默改写;作者之后想改,走契约修订流程。旧书没有这些字段时按默认值(中文 / 小说)处理,目标总字数缺失时不自动补写。
39
- 4. **跃迁**:建书由工具完成——书仓脚手架、构想快照冻结、书id 写入契约、`vol:` 首次提交(草稿区不入库),设计面跃迁为「作品定调」。**建书不自动切书**:拿 `novel_create_book` 返回的 `bookId` 调 `novel_select_book` 落定当前书,再向作者说明去向——**默认走快速开写**(《定调设计》路径 A:一次起草、作者过目确认);只有作者明确说要逐部细聊、深度定制时,才走深度定制(《定调设计》路径 B:逐部细聊)。
40
+ 4. **跃迁**:建书由工具完成——书仓脚手架、构想快照冻结、书id 写入契约、`vol:` 首次提交(草稿区不入库),设计面跃迁为「作品定调」。**建书不自动切书**:拿 `novel_create_book` 返回的 `bookId` 调 `novel_select_book` 落定当前书,再向作者说明去向——**默认走快速开写**(《定调设计》路径 A:一次起草、作者过目确认);只有作者明确说要逐部细聊、深度定制时,才走深度定制(《定调设计》路径 B:逐部细聊)。**建书只能调 `novel_create_book`,禁止用文件工具手写书籍信息、大纲或章节文件来冒充建书;没有建书工具时,明确告诉作者没有建书工具,不要手写书稿文件。**
40
41
 
41
42
  ## 工具
42
43