@yangda611/dsh-scriptor 8.4.3 → 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
@@ -113,17 +113,17 @@ var require_visit = __commonJS({
113
113
  visit.BREAK = BREAK;
114
114
  visit.SKIP = SKIP;
115
115
  visit.REMOVE = REMOVE;
116
- function visit_(key, node, visitor, path79) {
117
- const ctrl = callVisitor(key, node, visitor, path79);
116
+ function visit_(key, node, visitor, path80) {
117
+ const ctrl = callVisitor(key, node, visitor, path80);
118
118
  if (identity4.isNode(ctrl) || identity4.isPair(ctrl)) {
119
- replaceNode(key, path79, ctrl);
120
- return visit_(key, ctrl, visitor, path79);
119
+ replaceNode(key, path80, ctrl);
120
+ return visit_(key, ctrl, visitor, path80);
121
121
  }
122
122
  if (typeof ctrl !== "symbol") {
123
123
  if (identity4.isCollection(node)) {
124
- path79 = Object.freeze(path79.concat(node));
124
+ path80 = Object.freeze(path80.concat(node));
125
125
  for (let i = 0; i < node.items.length; ++i) {
126
- const ci = visit_(i, node.items[i], visitor, path79);
126
+ const ci = visit_(i, node.items[i], visitor, path80);
127
127
  if (typeof ci === "number")
128
128
  i = ci - 1;
129
129
  else if (ci === BREAK)
@@ -134,13 +134,13 @@ var require_visit = __commonJS({
134
134
  }
135
135
  }
136
136
  } else if (identity4.isPair(node)) {
137
- path79 = Object.freeze(path79.concat(node));
138
- const ck = visit_("key", node.key, visitor, path79);
137
+ path80 = Object.freeze(path80.concat(node));
138
+ const ck = visit_("key", node.key, visitor, path80);
139
139
  if (ck === BREAK)
140
140
  return BREAK;
141
141
  else if (ck === REMOVE)
142
142
  node.key = null;
143
- const cv = visit_("value", node.value, visitor, path79);
143
+ const cv = visit_("value", node.value, visitor, path80);
144
144
  if (cv === BREAK)
145
145
  return BREAK;
146
146
  else if (cv === REMOVE)
@@ -161,17 +161,17 @@ var require_visit = __commonJS({
161
161
  visitAsync.BREAK = BREAK;
162
162
  visitAsync.SKIP = SKIP;
163
163
  visitAsync.REMOVE = REMOVE;
164
- async function visitAsync_(key, node, visitor, path79) {
165
- const ctrl = await callVisitor(key, node, visitor, path79);
164
+ async function visitAsync_(key, node, visitor, path80) {
165
+ const ctrl = await callVisitor(key, node, visitor, path80);
166
166
  if (identity4.isNode(ctrl) || identity4.isPair(ctrl)) {
167
- replaceNode(key, path79, ctrl);
168
- return visitAsync_(key, ctrl, visitor, path79);
167
+ replaceNode(key, path80, ctrl);
168
+ return visitAsync_(key, ctrl, visitor, path80);
169
169
  }
170
170
  if (typeof ctrl !== "symbol") {
171
171
  if (identity4.isCollection(node)) {
172
- path79 = Object.freeze(path79.concat(node));
172
+ path80 = Object.freeze(path80.concat(node));
173
173
  for (let i = 0; i < node.items.length; ++i) {
174
- const ci = await visitAsync_(i, node.items[i], visitor, path79);
174
+ const ci = await visitAsync_(i, node.items[i], visitor, path80);
175
175
  if (typeof ci === "number")
176
176
  i = ci - 1;
177
177
  else if (ci === BREAK)
@@ -182,13 +182,13 @@ var require_visit = __commonJS({
182
182
  }
183
183
  }
184
184
  } else if (identity4.isPair(node)) {
185
- path79 = Object.freeze(path79.concat(node));
186
- const ck = await visitAsync_("key", node.key, visitor, path79);
185
+ path80 = Object.freeze(path80.concat(node));
186
+ const ck = await visitAsync_("key", node.key, visitor, path80);
187
187
  if (ck === BREAK)
188
188
  return BREAK;
189
189
  else if (ck === REMOVE)
190
190
  node.key = null;
191
- const cv = await visitAsync_("value", node.value, visitor, path79);
191
+ const cv = await visitAsync_("value", node.value, visitor, path80);
192
192
  if (cv === BREAK)
193
193
  return BREAK;
194
194
  else if (cv === REMOVE)
@@ -215,23 +215,23 @@ var require_visit = __commonJS({
215
215
  }
216
216
  return visitor;
217
217
  }
218
- function callVisitor(key, node, visitor, path79) {
218
+ function callVisitor(key, node, visitor, path80) {
219
219
  if (typeof visitor === "function")
220
- return visitor(key, node, path79);
220
+ return visitor(key, node, path80);
221
221
  if (identity4.isMap(node))
222
- return visitor.Map?.(key, node, path79);
222
+ return visitor.Map?.(key, node, path80);
223
223
  if (identity4.isSeq(node))
224
- return visitor.Seq?.(key, node, path79);
224
+ return visitor.Seq?.(key, node, path80);
225
225
  if (identity4.isPair(node))
226
- return visitor.Pair?.(key, node, path79);
226
+ return visitor.Pair?.(key, node, path80);
227
227
  if (identity4.isScalar(node))
228
- return visitor.Scalar?.(key, node, path79);
228
+ return visitor.Scalar?.(key, node, path80);
229
229
  if (identity4.isAlias(node))
230
- return visitor.Alias?.(key, node, path79);
230
+ return visitor.Alias?.(key, node, path80);
231
231
  return void 0;
232
232
  }
233
- function replaceNode(key, path79, node) {
234
- const parent = path79[path79.length - 1];
233
+ function replaceNode(key, path80, node) {
234
+ const parent = path80[path80.length - 1];
235
235
  if (identity4.isCollection(parent)) {
236
236
  parent.items[key] = node;
237
237
  } else if (identity4.isPair(parent)) {
@@ -841,10 +841,10 @@ var require_Collection = __commonJS({
841
841
  var createNode = require_createNode();
842
842
  var identity4 = require_identity();
843
843
  var Node = require_Node();
844
- function collectionFromPath(schema, path79, value) {
844
+ function collectionFromPath(schema, path80, value) {
845
845
  let v = value;
846
- for (let i = path79.length - 1; i >= 0; --i) {
847
- const k = path79[i];
846
+ for (let i = path80.length - 1; i >= 0; --i) {
847
+ const k = path80[i];
848
848
  if (typeof k === "number" && Number.isInteger(k) && k >= 0) {
849
849
  const a = [];
850
850
  a[k] = v;
@@ -863,7 +863,7 @@ var require_Collection = __commonJS({
863
863
  sourceObjects: /* @__PURE__ */ new Map()
864
864
  });
865
865
  }
866
- var isEmptyPath = (path79) => path79 == null || typeof path79 === "object" && !!path79[Symbol.iterator]().next().done;
866
+ var isEmptyPath = (path80) => path80 == null || typeof path80 === "object" && !!path80[Symbol.iterator]().next().done;
867
867
  var Collection = class extends Node.NodeBase {
868
868
  constructor(type, schema) {
869
869
  super(type);
@@ -893,11 +893,11 @@ var require_Collection = __commonJS({
893
893
  * be a Pair instance or a `{ key, value }` object, which may not have a key
894
894
  * that already exists in the map.
895
895
  */
896
- addIn(path79, value) {
897
- if (isEmptyPath(path79))
896
+ addIn(path80, value) {
897
+ if (isEmptyPath(path80))
898
898
  this.add(value);
899
899
  else {
900
- const [key, ...rest] = path79;
900
+ const [key, ...rest] = path80;
901
901
  const node = this.get(key, true);
902
902
  if (identity4.isCollection(node))
903
903
  node.addIn(rest, value);
@@ -911,8 +911,8 @@ var require_Collection = __commonJS({
911
911
  * Removes a value from the collection.
912
912
  * @returns `true` if the item was found and removed.
913
913
  */
914
- deleteIn(path79) {
915
- const [key, ...rest] = path79;
914
+ deleteIn(path80) {
915
+ const [key, ...rest] = path80;
916
916
  if (rest.length === 0)
917
917
  return this.delete(key);
918
918
  const node = this.get(key, true);
@@ -926,8 +926,8 @@ var require_Collection = __commonJS({
926
926
  * scalar values from their surrounding node; to disable set `keepScalar` to
927
927
  * `true` (collections are always returned intact).
928
928
  */
929
- getIn(path79, keepScalar) {
930
- const [key, ...rest] = path79;
929
+ getIn(path80, keepScalar) {
930
+ const [key, ...rest] = path80;
931
931
  const node = this.get(key, true);
932
932
  if (rest.length === 0)
933
933
  return !keepScalar && identity4.isScalar(node) ? node.value : node;
@@ -945,8 +945,8 @@ var require_Collection = __commonJS({
945
945
  /**
946
946
  * Checks if the collection includes a value with the key `key`.
947
947
  */
948
- hasIn(path79) {
949
- const [key, ...rest] = path79;
948
+ hasIn(path80) {
949
+ const [key, ...rest] = path80;
950
950
  if (rest.length === 0)
951
951
  return this.has(key);
952
952
  const node = this.get(key, true);
@@ -956,8 +956,8 @@ var require_Collection = __commonJS({
956
956
  * Sets a value in this collection. For `!!set`, `value` needs to be a
957
957
  * boolean to add/remove the item from the set.
958
958
  */
959
- setIn(path79, value) {
960
- const [key, ...rest] = path79;
959
+ setIn(path80, value) {
960
+ const [key, ...rest] = path80;
961
961
  if (rest.length === 0) {
962
962
  this.set(key, value);
963
963
  } else {
@@ -3472,9 +3472,9 @@ var require_Document = __commonJS({
3472
3472
  this.contents.add(value);
3473
3473
  }
3474
3474
  /** Adds a value to the document. */
3475
- addIn(path79, value) {
3475
+ addIn(path80, value) {
3476
3476
  if (assertCollection(this.contents))
3477
- this.contents.addIn(path79, value);
3477
+ this.contents.addIn(path80, value);
3478
3478
  }
3479
3479
  /**
3480
3480
  * Create a new `Alias` node, ensuring that the target `node` has the required anchor.
@@ -3549,14 +3549,14 @@ var require_Document = __commonJS({
3549
3549
  * Removes a value from the document.
3550
3550
  * @returns `true` if the item was found and removed.
3551
3551
  */
3552
- deleteIn(path79) {
3553
- if (Collection.isEmptyPath(path79)) {
3552
+ deleteIn(path80) {
3553
+ if (Collection.isEmptyPath(path80)) {
3554
3554
  if (this.contents == null)
3555
3555
  return false;
3556
3556
  this.contents = null;
3557
3557
  return true;
3558
3558
  }
3559
- return assertCollection(this.contents) ? this.contents.deleteIn(path79) : false;
3559
+ return assertCollection(this.contents) ? this.contents.deleteIn(path80) : false;
3560
3560
  }
3561
3561
  /**
3562
3562
  * Returns item at `key`, or `undefined` if not found. By default unwraps
@@ -3571,10 +3571,10 @@ var require_Document = __commonJS({
3571
3571
  * scalar values from their surrounding node; to disable set `keepScalar` to
3572
3572
  * `true` (collections are always returned intact).
3573
3573
  */
3574
- getIn(path79, keepScalar) {
3575
- if (Collection.isEmptyPath(path79))
3574
+ getIn(path80, keepScalar) {
3575
+ if (Collection.isEmptyPath(path80))
3576
3576
  return !keepScalar && identity4.isScalar(this.contents) ? this.contents.value : this.contents;
3577
- return identity4.isCollection(this.contents) ? this.contents.getIn(path79, keepScalar) : void 0;
3577
+ return identity4.isCollection(this.contents) ? this.contents.getIn(path80, keepScalar) : void 0;
3578
3578
  }
3579
3579
  /**
3580
3580
  * Checks if the document includes a value with the key `key`.
@@ -3585,10 +3585,10 @@ var require_Document = __commonJS({
3585
3585
  /**
3586
3586
  * Checks if the document includes a value at `path`.
3587
3587
  */
3588
- hasIn(path79) {
3589
- if (Collection.isEmptyPath(path79))
3588
+ hasIn(path80) {
3589
+ if (Collection.isEmptyPath(path80))
3590
3590
  return this.contents !== void 0;
3591
- return identity4.isCollection(this.contents) ? this.contents.hasIn(path79) : false;
3591
+ return identity4.isCollection(this.contents) ? this.contents.hasIn(path80) : false;
3592
3592
  }
3593
3593
  /**
3594
3594
  * Sets a value in this document. For `!!set`, `value` needs to be a
@@ -3605,13 +3605,13 @@ var require_Document = __commonJS({
3605
3605
  * Sets a value in this document. For `!!set`, `value` needs to be a
3606
3606
  * boolean to add/remove the item from the set.
3607
3607
  */
3608
- setIn(path79, value) {
3609
- if (Collection.isEmptyPath(path79)) {
3608
+ setIn(path80, value) {
3609
+ if (Collection.isEmptyPath(path80)) {
3610
3610
  this.contents = value;
3611
3611
  } else if (this.contents == null) {
3612
- this.contents = Collection.collectionFromPath(this.schema, Array.from(path79), value);
3612
+ this.contents = Collection.collectionFromPath(this.schema, Array.from(path80), value);
3613
3613
  } else if (assertCollection(this.contents)) {
3614
- this.contents.setIn(path79, value);
3614
+ this.contents.setIn(path80, value);
3615
3615
  }
3616
3616
  }
3617
3617
  /**
@@ -5571,9 +5571,9 @@ var require_cst_visit = __commonJS({
5571
5571
  visit.BREAK = BREAK;
5572
5572
  visit.SKIP = SKIP;
5573
5573
  visit.REMOVE = REMOVE;
5574
- visit.itemAtPath = (cst, path79) => {
5574
+ visit.itemAtPath = (cst, path80) => {
5575
5575
  let item = cst;
5576
- for (const [field, index] of path79) {
5576
+ for (const [field, index] of path80) {
5577
5577
  const tok = item?.[field];
5578
5578
  if (tok && "items" in tok) {
5579
5579
  item = tok.items[index];
@@ -5582,23 +5582,23 @@ var require_cst_visit = __commonJS({
5582
5582
  }
5583
5583
  return item;
5584
5584
  };
5585
- visit.parentCollection = (cst, path79) => {
5586
- const parent = visit.itemAtPath(cst, path79.slice(0, -1));
5587
- const field = path79[path79.length - 1][0];
5585
+ visit.parentCollection = (cst, path80) => {
5586
+ const parent = visit.itemAtPath(cst, path80.slice(0, -1));
5587
+ const field = path80[path80.length - 1][0];
5588
5588
  const coll = parent?.[field];
5589
5589
  if (coll && "items" in coll)
5590
5590
  return coll;
5591
5591
  throw new Error("Parent collection not found");
5592
5592
  };
5593
- function _visit(path79, item, visitor) {
5594
- let ctrl = visitor(item, path79);
5593
+ function _visit(path80, item, visitor) {
5594
+ let ctrl = visitor(item, path80);
5595
5595
  if (typeof ctrl === "symbol")
5596
5596
  return ctrl;
5597
5597
  for (const field of ["key", "value"]) {
5598
5598
  const token = item[field];
5599
5599
  if (token && "items" in token) {
5600
5600
  for (let i = 0; i < token.items.length; ++i) {
5601
- const ci = _visit(Object.freeze(path79.concat([[field, i]])), token.items[i], visitor);
5601
+ const ci = _visit(Object.freeze(path80.concat([[field, i]])), token.items[i], visitor);
5602
5602
  if (typeof ci === "number")
5603
5603
  i = ci - 1;
5604
5604
  else if (ci === BREAK)
@@ -5609,10 +5609,10 @@ var require_cst_visit = __commonJS({
5609
5609
  }
5610
5610
  }
5611
5611
  if (typeof ctrl === "function" && field === "key")
5612
- ctrl = ctrl(item, path79);
5612
+ ctrl = ctrl(item, path80);
5613
5613
  }
5614
5614
  }
5615
- return typeof ctrl === "function" ? ctrl(item, path79) : ctrl;
5615
+ return typeof ctrl === "function" ? ctrl(item, path80) : ctrl;
5616
5616
  }
5617
5617
  exports.visit = visit;
5618
5618
  }
@@ -6914,14 +6914,14 @@ var require_parser = __commonJS({
6914
6914
  case "scalar":
6915
6915
  case "single-quoted-scalar":
6916
6916
  case "double-quoted-scalar": {
6917
- const fs66 = this.flowScalar(this.type);
6917
+ const fs67 = this.flowScalar(this.type);
6918
6918
  if (atNextItem || it.value) {
6919
- map.items.push({ start, key: fs66, sep: [] });
6919
+ map.items.push({ start, key: fs67, sep: [] });
6920
6920
  this.onKeyLine = true;
6921
6921
  } else if (it.sep) {
6922
- this.stack.push(fs66);
6922
+ this.stack.push(fs67);
6923
6923
  } else {
6924
- Object.assign(it, { key: fs66, sep: [] });
6924
+ Object.assign(it, { key: fs67, sep: [] });
6925
6925
  this.onKeyLine = true;
6926
6926
  }
6927
6927
  return;
@@ -7049,13 +7049,13 @@ var require_parser = __commonJS({
7049
7049
  case "scalar":
7050
7050
  case "single-quoted-scalar":
7051
7051
  case "double-quoted-scalar": {
7052
- const fs66 = this.flowScalar(this.type);
7052
+ const fs67 = this.flowScalar(this.type);
7053
7053
  if (!it || it.value)
7054
- fc.items.push({ start: [], key: fs66, sep: [] });
7054
+ fc.items.push({ start: [], key: fs67, sep: [] });
7055
7055
  else if (it.sep)
7056
- this.stack.push(fs66);
7056
+ this.stack.push(fs67);
7057
7057
  else
7058
- Object.assign(it, { key: fs66, sep: [] });
7058
+ Object.assign(it, { key: fs67, sep: [] });
7059
7059
  return;
7060
7060
  }
7061
7061
  case "flow-map-end":
@@ -7421,7 +7421,7 @@ var require_pend = __commonJS({
7421
7421
  // ../../node_modules/.pnpm/yauzl@3.4.0/node_modules/yauzl/fd-slicer.js
7422
7422
  var require_fd_slicer = __commonJS({
7423
7423
  "../../node_modules/.pnpm/yauzl@3.4.0/node_modules/yauzl/fd-slicer.js"(exports) {
7424
- var fs66 = __require("fs");
7424
+ var fs67 = __require("fs");
7425
7425
  var util = __require("util");
7426
7426
  var stream = __require("stream");
7427
7427
  var Readable = stream.Readable;
@@ -7441,7 +7441,7 @@ var require_fd_slicer = __commonJS({
7441
7441
  FdSlicer.prototype.read = function(buffer, offset, length, position, callback) {
7442
7442
  var self = this;
7443
7443
  self.pend.go(function(cb) {
7444
- fs66.read(self.fd, buffer, offset, length, position, function(err, bytesRead, buffer2) {
7444
+ fs67.read(self.fd, buffer, offset, length, position, function(err, bytesRead, buffer2) {
7445
7445
  cb();
7446
7446
  callback(err, bytesRead, buffer2);
7447
7447
  });
@@ -7458,7 +7458,7 @@ var require_fd_slicer = __commonJS({
7458
7458
  self.refCount -= 1;
7459
7459
  if (self.refCount < 0) throw new Error("invalid unref");
7460
7460
  if (self.refCount > 0) return;
7461
- fs66.close(self.fd, onCloseDone);
7461
+ fs67.close(self.fd, onCloseDone);
7462
7462
  function onCloseDone(err) {
7463
7463
  if (err) {
7464
7464
  self.emit("error", err);
@@ -7490,7 +7490,7 @@ var require_fd_slicer = __commonJS({
7490
7490
  }
7491
7491
  self.context.pend.go(function(cb) {
7492
7492
  var buffer = Buffer.allocUnsafe(toRead);
7493
- fs66.read(self.context.fd, buffer, 0, toRead, self.pos, function(err, bytesRead) {
7493
+ fs67.read(self.context.fd, buffer, 0, toRead, self.pos, function(err, bytesRead) {
7494
7494
  if (err) {
7495
7495
  self.destroy(err);
7496
7496
  } else if (bytesRead === 0) {
@@ -7850,7 +7850,7 @@ var require_crc32 = __commonJS({
7850
7850
  // ../../node_modules/.pnpm/yauzl@3.4.0/node_modules/yauzl/index.js
7851
7851
  var require_yauzl = __commonJS({
7852
7852
  "../../node_modules/.pnpm/yauzl@3.4.0/node_modules/yauzl/index.js"(exports) {
7853
- var fs66 = __require("fs");
7853
+ var fs67 = __require("fs");
7854
7854
  var zlib = __require("zlib");
7855
7855
  var fd_slicer = require_fd_slicer();
7856
7856
  var util = __require("util");
@@ -7875,9 +7875,9 @@ var require_yauzl = __commonJS({
7875
7875
  exports.Entry = Entry;
7876
7876
  exports.LocalFileHeader = LocalFileHeader;
7877
7877
  exports.RandomAccessReader = RandomAccessReader;
7878
- function openPromise(path79, options2) {
7878
+ function openPromise(path80, options2) {
7879
7879
  return new Promise((resolve22, reject) => {
7880
- open(path79, { ...options2, lazyEntries: true }, function(err, zipfile) {
7880
+ open(path80, { ...options2, lazyEntries: true }, function(err, zipfile) {
7881
7881
  if (err) return reject(err);
7882
7882
  resolve22(zipfile);
7883
7883
  });
@@ -7907,7 +7907,7 @@ var require_yauzl = __commonJS({
7907
7907
  });
7908
7908
  });
7909
7909
  }
7910
- function open(path79, options2, callback) {
7910
+ function open(path80, options2, callback) {
7911
7911
  if (typeof options2 === "function") {
7912
7912
  callback = options2;
7913
7913
  options2 = null;
@@ -7919,10 +7919,10 @@ var require_yauzl = __commonJS({
7919
7919
  if (options2.validateEntrySizes == null) options2.validateEntrySizes = true;
7920
7920
  if (options2.strictFileNames == null) options2.strictFileNames = false;
7921
7921
  if (callback == null) callback = defaultCallback;
7922
- fs66.open(path79, "r", function(err, fd) {
7922
+ fs67.open(path80, "r", function(err, fd) {
7923
7923
  if (err) return callback(err);
7924
7924
  fromFd(fd, options2, function(err2, zipfile) {
7925
- if (err2) fs66.close(fd, defaultCallback);
7925
+ if (err2) fs67.close(fd, defaultCallback);
7926
7926
  callback(err2, zipfile);
7927
7927
  });
7928
7928
  });
@@ -7939,7 +7939,7 @@ var require_yauzl = __commonJS({
7939
7939
  if (options2.validateEntrySizes == null) options2.validateEntrySizes = true;
7940
7940
  if (options2.strictFileNames == null) options2.strictFileNames = false;
7941
7941
  if (callback == null) callback = defaultCallback;
7942
- fs66.fstat(fd, function(err, stats) {
7942
+ fs67.fstat(fd, function(err, stats) {
7943
7943
  if (err) return callback(err);
7944
7944
  var reader = new fd_slicer.FdSlicer(fd);
7945
7945
  fromRandomAccessReader(reader, stats.size, options2, callback);
@@ -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;
@@ -11101,17 +11105,17 @@ Schema.prototype.volatile = function volatile() {
11101
11105
  };
11102
11106
  var resolvers = {};
11103
11107
  var checkedVolatile = /* @__PURE__ */ Symbol("checked-volatile-schema");
11104
- function validateVolatileSchema(schema, path79 = [], blocked = false, seen = /* @__PURE__ */ new Map()) {
11108
+ function validateVolatileSchema(schema, path80 = [], blocked = false, seen = /* @__PURE__ */ new Map()) {
11105
11109
  const states = seen.get(schema) ?? /* @__PURE__ */ new Set();
11106
11110
  if (states.has(blocked)) return;
11107
11111
  states.add(blocked);
11108
11112
  seen.set(schema, states);
11109
- if (schema.meta?.volatile && blocked) throw new ValidationError("volatile fields require a fixed object path without an enclosing volatile field", { path: path79 });
11113
+ if (schema.meta?.volatile && blocked) throw new ValidationError("volatile fields require a fixed object path without an enclosing volatile field", { path: path80 });
11110
11114
  const nested = blocked || !!schema.meta?.volatile;
11111
- if (schema.dict) for (const [key, child] of Object.entries(schema.dict)) validateVolatileSchema(child, [...path79, key], nested, seen);
11112
- if (schema.sKey) validateVolatileSchema(schema.sKey, [...path79, "<key>"], true, seen);
11113
- if (schema.inner && (schema.type !== "lazy" || schema.inner[kSchema])) validateVolatileSchema(schema.inner, [...path79, "*"], true, seen);
11114
- if (schema.list) for (let index = 0; index < schema.list.length; index++) validateVolatileSchema(schema.list[index], [...path79, String(index)], true, seen);
11115
+ if (schema.dict) for (const [key, child] of Object.entries(schema.dict)) validateVolatileSchema(child, [...path80, key], nested, seen);
11116
+ if (schema.sKey) validateVolatileSchema(schema.sKey, [...path80, "<key>"], true, seen);
11117
+ if (schema.inner && (schema.type !== "lazy" || schema.inner[kSchema])) validateVolatileSchema(schema.inner, [...path80, "*"], true, seen);
11118
+ if (schema.list) for (let index = 0; index < schema.list.length; index++) validateVolatileSchema(schema.list[index], [...path80, String(index)], true, seen);
11115
11119
  }
11116
11120
  Schema.extend = function extend(type, resolve22) {
11117
11121
  resolvers[type] = resolve22;
@@ -12958,6 +12962,13 @@ var DOCUMENT_FIELDS = {
12958
12962
  type: "single-line-text",
12959
12963
  owner: "system"
12960
12964
  },
12965
+ /** 建书硬性流程(8.4.4):创建时选定的目标总字数(汉字数),决定篇幅规划;建书前必须问作者拿到答案,不静默用默认值。 */
12966
+ targetTotalWords: {
12967
+ name: "\u76EE\u6807\u603B\u5B57\u6570",
12968
+ description: "\u76EE\u6807\u603B\u5B57\u6570\uFF08\u6C49\u5B57\u6570\uFF09\uFF1B\u521B\u5EFA\u65F6\u9009\u5B9A\uFF0C\u51B3\u5B9A\u7BC7\u5E45\u89C4\u5212",
12969
+ type: "positive-integer",
12970
+ owner: "system"
12971
+ },
12961
12972
  timelineEvent: {
12962
12973
  name: "\u4E8B\u4EF6",
12963
12974
  description: "\u5B9E\u9645\u53D1\u751F\u7684\u4E8B\u4EF6\u63CF\u8FF0\uFF0C\u4E0D\u662F\u4E8B\u4EF6\u6761\u76EE\u7684\u540D\u79F0\u6216\u8BB0\u5F55\u7AE0\u53F7",
@@ -17144,6 +17155,12 @@ function marketOf(concept) {
17144
17155
  function outputFormOf(concept) {
17145
17156
  return concept !== null && concept !== void 0 && isOutputFormValue(concept.\u8F93\u51FA\u5F62\u6001) ? concept.\u8F93\u51FA\u5F62\u6001 : DEFAULT_OUTPUT_FORM;
17146
17157
  }
17158
+ function targetTotalWordsOf(concept) {
17159
+ return concept !== null && concept !== void 0 && typeof concept.\u76EE\u6807\u603B\u5B57\u6570 === "number" && Number.isSafeInteger(concept.\u76EE\u6807\u603B\u5B57\u6570) && concept.\u76EE\u6807\u603B\u5B57\u6570 > 0 ? concept.\u76EE\u6807\u603B\u5B57\u6570 : void 0;
17160
+ }
17161
+ function isTargetTotalWordsValue(value) {
17162
+ return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
17163
+ }
17147
17164
  var \u5FC5\u586B\u96C6 = new Set(\u6784\u60F3\u5FC5\u586B\u8981\u7D20);
17148
17165
  function isConceptBlank(value) {
17149
17166
  if (value === void 0 || value === null) return true;
@@ -17187,6 +17204,7 @@ function parseConcept(text5) {
17187
17204
  const \u72B6\u6001 = r2.data.fields["\u72B6\u6001"] === "\u5DF2\u786E\u8BA4" ? "\u5DF2\u786E\u8BA4" : "\u5019\u9009";
17188
17205
  const \u5E02\u573A = r2.data.fields[DOCUMENT_FIELDS.market.name];
17189
17206
  const \u8F93\u51FA\u5F62\u6001 = r2.data.fields[DOCUMENT_FIELDS.outputForm.name];
17207
+ const \u76EE\u6807\u603B\u5B57\u6570 = r2.data.fields[DOCUMENT_FIELDS.targetTotalWords.name];
17190
17208
  return {
17191
17209
  \u72B6\u6001,
17192
17210
  \u6838\u5FC3\u521B\u610F: bodies["\u6838\u5FC3\u521B\u610F"] ?? "",
@@ -17198,7 +17216,8 @@ function parseConcept(text5) {
17198
17216
  \u660E\u786E\u4E0D\u8981\u4EC0\u4E48: bodies["\u660E\u786E\u4E0D\u8981\u4EC0\u4E48"] ?? "",
17199
17217
  \u8981\u7D20\u72B6\u6001: states,
17200
17218
  ...isMarketValue(\u5E02\u573A) ? { \u5E02\u573A } : {},
17201
- ...isOutputFormValue(\u8F93\u51FA\u5F62\u6001) ? { \u8F93\u51FA\u5F62\u6001 } : {}
17219
+ ...isOutputFormValue(\u8F93\u51FA\u5F62\u6001) ? { \u8F93\u51FA\u5F62\u6001 } : {},
17220
+ ...isTargetTotalWordsValue(\u76EE\u6807\u603B\u5B57\u6570) ? { \u76EE\u6807\u603B\u5B57\u6570 } : {}
17202
17221
  };
17203
17222
  }
17204
17223
  function serializeConcept(concept) {
@@ -17211,10 +17230,12 @@ function serializeConcept(concept) {
17211
17230
  lines.push(body.trim(), "");
17212
17231
  }
17213
17232
  }
17233
+ const totalWords = targetTotalWordsOf(concept);
17214
17234
  return serializeDocument({
17215
17235
  \u72B6\u6001: concept.\u72B6\u6001,
17216
17236
  [DOCUMENT_FIELDS.market.name]: marketOf(concept),
17217
- [DOCUMENT_FIELDS.outputForm.name]: outputFormOf(concept)
17237
+ [DOCUMENT_FIELDS.outputForm.name]: outputFormOf(concept),
17238
+ ...totalWords === void 0 ? {} : { [DOCUMENT_FIELDS.targetTotalWords.name]: totalWords }
17218
17239
  }, lines.join("\n").trimEnd() + "\n");
17219
17240
  }
17220
17241
  function extractElementBodies(body) {
@@ -17997,7 +18018,8 @@ function labeledHeadings(names, state) {
17997
18018
  function resolveContractFields(opts = {}) {
17998
18019
  if (opts.\u5E02\u573A !== void 0 && !isMarketValue(opts.\u5E02\u573A)) throw new Error(`\u5E02\u573A\u53D6\u503C\u975E\u6CD5\uFF1A${String(opts.\u5E02\u573A)}\uFF0C\u53EA\u63A5\u53D7 \u6D77\u5916 / \u4E2D\u6587`);
17999
18020
  if (opts.\u8F93\u51FA\u5F62\u6001 !== void 0 && !isOutputFormValue(opts.\u8F93\u51FA\u5F62\u6001)) throw new Error(`\u8F93\u51FA\u5F62\u6001\u53D6\u503C\u975E\u6CD5\uFF1A${String(opts.\u8F93\u51FA\u5F62\u6001)}\uFF0C\u53EA\u63A5\u53D7 \u77ED\u5267 / \u7535\u5F71\u5267\u672C / \u5C0F\u8BF4`);
18000
- return { \u5E02\u573A: opts.\u5E02\u573A ?? DEFAULT_MARKET, \u8F93\u51FA\u5F62\u6001: opts.\u8F93\u51FA\u5F62\u6001 ?? DEFAULT_OUTPUT_FORM };
18021
+ if (opts.\u76EE\u6807\u603B\u5B57\u6570 !== void 0 && (!Number.isSafeInteger(opts.\u76EE\u6807\u603B\u5B57\u6570) || opts.\u76EE\u6807\u603B\u5B57\u6570 <= 0)) throw new Error(`\u76EE\u6807\u603B\u5B57\u6570\u53D6\u503C\u975E\u6CD5\uFF1A${String(opts.\u76EE\u6807\u603B\u5B57\u6570)}\uFF0C\u53EA\u63A5\u53D7\u6B63\u6574\u6570\u6C49\u5B57\u6570`);
18022
+ return { \u5E02\u573A: opts.\u5E02\u573A ?? DEFAULT_MARKET, \u8F93\u51FA\u5F62\u6001: opts.\u8F93\u51FA\u5F62\u6001 ?? DEFAULT_OUTPUT_FORM, ...opts.\u76EE\u6807\u603B\u5B57\u6570 === void 0 ? {} : { \u76EE\u6807\u603B\u5B57\u6570: opts.\u76EE\u6807\u603B\u5B57\u6570 } };
18001
18023
  }
18002
18024
  function emptyContractBody(bookId2, fieldOpts = {}) {
18003
18025
  const fields = resolveContractFields(fieldOpts);
@@ -18005,10 +18027,11 @@ function emptyContractBody(bookId2, fieldOpts = {}) {
18005
18027
  ...bookId2 === void 0 ? {} : { \u4E66id: bookId2 },
18006
18028
  [BOOK_FORMAT_VERSION_FIELD]: CURRENT_BOOK_FORMAT_VERSION,
18007
18029
  [DOCUMENT_FIELDS.market.name]: fields.\u5E02\u573A,
18008
- [DOCUMENT_FIELDS.outputForm.name]: fields.\u8F93\u51FA\u5F62\u6001
18030
+ [DOCUMENT_FIELDS.outputForm.name]: fields.\u8F93\u51FA\u5F62\u6001,
18031
+ ...fields.\u76EE\u6807\u603B\u5B57\u6570 === void 0 ? {} : { [DOCUMENT_FIELDS.targetTotalWords.name]: fields.\u76EE\u6807\u603B\u5B57\u6570 }
18009
18032
  }, `# \u4F5C\u54C1\u5951\u7EA6
18010
18033
 
18011
- ${labeledHeadings(\u5951\u7EA6\u516D\u90E8, "\u7559\u767D")}`, ["\u4E66id", BOOK_FORMAT_VERSION_FIELD, DOCUMENT_FIELDS.market.name, DOCUMENT_FIELDS.outputForm.name]);
18034
+ ${labeledHeadings(\u5951\u7EA6\u516D\u90E8, "\u7559\u767D")}`, ["\u4E66id", BOOK_FORMAT_VERSION_FIELD, DOCUMENT_FIELDS.market.name, DOCUMENT_FIELDS.outputForm.name, ...fields.\u76EE\u6807\u603B\u5B57\u6570 === void 0 ? [] : [DOCUMENT_FIELDS.targetTotalWords.name]]);
18012
18035
  }
18013
18036
  function emptySkeletonBody() {
18014
18037
  return `# \u6545\u4E8B\u9AA8\u67B6
@@ -18043,7 +18066,8 @@ function scaffoldBookFiles(bookRoot, concept, opts = {}) {
18043
18066
  const parsedConcept = typeof concept === "string" ? parseConcept(concept) : concept;
18044
18067
  const fields = resolveContractFields({
18045
18068
  \u5E02\u573A: opts.\u5E02\u573A ?? (parsedConcept === null ? void 0 : marketOf(parsedConcept)),
18046
- \u8F93\u51FA\u5F62\u6001: opts.\u8F93\u51FA\u5F62\u6001 ?? (parsedConcept === null ? void 0 : outputFormOf(parsedConcept))
18069
+ \u8F93\u51FA\u5F62\u6001: opts.\u8F93\u51FA\u5F62\u6001 ?? (parsedConcept === null ? void 0 : outputFormOf(parsedConcept)),
18070
+ \u76EE\u6807\u603B\u5B57\u6570: opts.\u76EE\u6807\u603B\u5B57\u6570 ?? (parsedConcept === null ? void 0 : targetTotalWordsOf(parsedConcept))
18047
18071
  });
18048
18072
  const ops = [
18049
18073
  { relPath: paths.\u5951\u7EA6(), content: emptyContractBody(opts.bookId, fields) },
@@ -19411,6 +19435,9 @@ function createBook(input) {
19411
19435
  if (input.concept.\u8F93\u51FA\u5F62\u6001 !== void 0 && !isOutputFormValue(input.concept.\u8F93\u51FA\u5F62\u6001)) {
19412
19436
  return { ok: false, reason: `\u8F93\u51FA\u5F62\u6001\u53D6\u503C\u975E\u6CD5\uFF1A${String(input.concept.\u8F93\u51FA\u5F62\u6001)}\uFF0C\u53EA\u63A5\u53D7 \u77ED\u5267 / \u7535\u5F71\u5267\u672C / \u5C0F\u8BF4` };
19413
19437
  }
19438
+ if (input.concept.\u76EE\u6807\u603B\u5B57\u6570 !== void 0 && !isTargetTotalWordsValue(input.concept.\u76EE\u6807\u603B\u5B57\u6570)) {
19439
+ return { ok: false, reason: `\u76EE\u6807\u603B\u5B57\u6570\u53D6\u503C\u975E\u6CD5\uFF1A${String(input.concept.\u76EE\u6807\u603B\u5B57\u6570)}\uFF0C\u53EA\u63A5\u53D7\u6B63\u6574\u6570\u6C49\u5B57\u6570` };
19440
+ }
19414
19441
  try {
19415
19442
  return withBookLock(workspaceRoot, () => {
19416
19443
  const bookId2 = generateBookId(input.\u4E66\u540D);
@@ -19421,7 +19448,7 @@ function createBook(input) {
19421
19448
  try {
19422
19449
  fs32.mkdirSync(bookRoot);
19423
19450
  created = true;
19424
- scaffoldBookFiles(bookRoot, input.concept, { bookId: bookId2, \u5E02\u573A: marketOf(input.concept), \u8F93\u51FA\u5F62\u6001: outputFormOf(input.concept) });
19451
+ scaffoldBookFiles(bookRoot, input.concept, { bookId: bookId2, \u5E02\u573A: marketOf(input.concept), \u8F93\u51FA\u5F62\u6001: outputFormOf(input.concept), \u76EE\u6807\u603B\u5B57\u6570: targetTotalWordsOf(input.concept) });
19425
19452
  const commit = initFirstCommit(bookRoot);
19426
19453
  return { ok: true, bookRoot, bookId: bookId2, commit };
19427
19454
  } catch (err) {
@@ -29083,6 +29110,7 @@ var MEMORY_CATALOG_SOURCE = "plugin:webnovel-memory-catalog";
29083
29110
  var AUTHOR_SAVE_SOURCE = "plugin:webnovel";
29084
29111
  var EDITOR_REQUEST_SOURCE = "plugin:webnovel-editor";
29085
29112
  var DRAFT_LENGTH_SOURCE = "plugin:webnovel-draft-length";
29113
+ var ORPHAN_REPAIR_SOURCE = "plugin:webnovel-orphan";
29086
29114
  function isMemoryCatalogSource(source2) {
29087
29115
  if (source2.kind === MEMORY_CATALOG_SOURCE) return true;
29088
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");
@@ -29313,68 +29341,99 @@ function writingAssignmentOf(agent) {
29313
29341
  }
29314
29342
  return void 0;
29315
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
+ }
29316
29356
  function attachWritingDelegationToAgent(agent) {
29357
+ const existing = attachedDelegations.get(agent);
29358
+ if (existing !== void 0) return existing;
29317
29359
  const context = agent.ctx;
29318
29360
  if (typeof context?.inject !== "function") return void 0;
29319
- const fiber = context.inject(["tools"], (scope2) => {
29320
- scope2.effect(function* () {
29321
- let native;
29322
- let off;
29323
- let updating = false;
29324
- const refresh = () => {
29325
- if (updating) return;
29326
- const current = scope2.tools.get("subagent", agent);
29327
- if (current === native) return;
29328
- updating = true;
29329
- try {
29330
- off?.();
29331
- off = void 0;
29332
- native = current;
29333
- if (!current) return;
29334
- const parameters = current.parameters;
29335
- off = scope2.tools.register({
29336
- ...current,
29337
- name: WRITING_DELEGATE_TOOL,
29338
- 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,
29339
- parameters: {
29340
- ...current.parameters,
29341
- properties: {
29342
- ...parameters.properties,
29343
- role: { type: "string", enum: [...WRITING_ROLES] },
29344
- bookId: { type: "string", description: "\u5DF2\u660E\u786E\u7684\u76EE\u6807\u4E66id\uFF1B\u4EC5\u7528\u4E8E\u4EFB\u52A1\u5F52\u5C5E" },
29345
- 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"]
29346
29395
  },
29347
- required: [...parameters.required ?? [], "role"]
29348
- },
29349
- execute(args, exec) {
29350
- const { role: role2, bookId: bookId2, chapter: chapter2, ...task } = args;
29351
- if (!isRole(role2) || typeof task["prompt"] !== "string" || exec.agent !== agent) {
29352
- throw new Error("\u5199\u4F5C\u59D4\u6D3E\u987B\u6307\u5B9A\u6709\u6548 role\u3001\u4EFB\u52A1 prompt \u548C\u5F53\u524D\u4E3B\u63A7\u3002");
29353
- }
29354
- 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");
29355
- const assignment = { ...typeof bookId2 === "string" ? { bookId: bookId2.trim() } : {}, ...typeof chapter2 === "number" ? { chapter: chapter2 } : {} };
29356
- 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)} -->
29357
29404
  ` : "";
29358
- return creationRole.run({ parent: agent, role: role2, ...assignment }, () => current.execute({
29359
- ...task,
29360
- prompt: marker(role2) + attribution + task["prompt"]
29361
- }, exec));
29362
- }
29363
- });
29364
- } finally {
29365
- updating = false;
29366
- }
29367
- };
29368
- yield () => {
29369
- off?.();
29370
- };
29371
- yield scope2.on("tools/change", refresh);
29372
- 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
+ });
29373
29421
  });
29374
- });
29375
- 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);
29376
29432
  await fiber.dispose();
29377
29433
  };
29434
+ attachedDelegations.set(agent, dispose);
29435
+ liveDelegationDisposes.add(dispose);
29436
+ return dispose;
29378
29437
  }
29379
29438
 
29380
29439
  // src/agent-mode.ts
@@ -29389,9 +29448,6 @@ function writingCapabilityOf(agent) {
29389
29448
  return void 0;
29390
29449
  }
29391
29450
  }
29392
- function isWritingAgent(agent) {
29393
- return writingCapabilityOf(agent) !== void 0;
29394
- }
29395
29451
 
29396
29452
  // src/status-context.ts
29397
29453
  import { createUserMessage as createUserMessage2 } from "@deepseek-ai/dsh-llm";
@@ -32083,7 +32139,7 @@ function createBookUpgradeTools(deps) {
32083
32139
  }
32084
32140
 
32085
32141
  // src/novel-tools.ts
32086
- import * as fs58 from "node:fs";
32142
+ import * as fs59 from "node:fs";
32087
32143
  import * as nodePath3 from "node:path";
32088
32144
 
32089
32145
  // src/design-commit-result.ts
@@ -32519,17 +32575,72 @@ function acceptEditorSuggestion(hub, agent, args) {
32519
32575
  return { ok: true, requestId, delivered: true, message: EDITOR_DELIVERED_MESSAGE };
32520
32576
  }
32521
32577
 
32522
- // ../drafting/src/context.ts
32578
+ // src/study/onboarding.ts
32579
+ var MARKET_VALUES2 = ["\u6D77\u5916", "\u4E2D\u6587"];
32580
+ var OUTPUT_FORM_VALUES2 = ["\u77ED\u5267", "\u7535\u5F71\u5267\u672C", "\u5C0F\u8BF4"];
32581
+ function isMarketValue2(value) {
32582
+ return typeof value === "string" && MARKET_VALUES2.includes(value);
32583
+ }
32584
+ function isOutputFormValue2(value) {
32585
+ return typeof value === "string" && OUTPUT_FORM_VALUES2.includes(value);
32586
+ }
32587
+ var ONBOARDING_DRAFT_RELATIVE = "\u4E66\u623F/\u6784\u60F3/_\u5F85\u5EFA\u4E66.json";
32588
+ function validateOnboardingAnswers(value) {
32589
+ if (value === null || typeof value !== "object") return {};
32590
+ const record4 = value;
32591
+ const out = {};
32592
+ if (isMarketValue2(record4["\u5E02\u573A"])) out.\u5E02\u573A = record4["\u5E02\u573A"];
32593
+ if (isOutputFormValue2(record4["\u8F93\u51FA\u5F62\u6001"])) out.\u8F93\u51FA\u5F62\u6001 = record4["\u8F93\u51FA\u5F62\u6001"];
32594
+ if (typeof record4["\u76EE\u6807\u603B\u5B57\u6570"] === "number" && Number.isSafeInteger(record4["\u76EE\u6807\u603B\u5B57\u6570"]) && record4["\u76EE\u6807\u603B\u5B57\u6570"] > 0) {
32595
+ out.\u76EE\u6807\u603B\u5B57\u6570 = record4["\u76EE\u6807\u603B\u5B57\u6570"];
32596
+ }
32597
+ return out;
32598
+ }
32599
+ function onboardingMissing(answers) {
32600
+ const missing = [];
32601
+ if (answers.\u5E02\u573A === void 0) missing.push("\u5E02\u573A");
32602
+ if (answers.\u8F93\u51FA\u5F62\u6001 === void 0) missing.push("\u8F93\u51FA\u5F62\u6001");
32603
+ if (answers.\u76EE\u6807\u603B\u5B57\u6570 === void 0) missing.push("\u76EE\u6807\u603B\u5B57\u6570");
32604
+ return missing;
32605
+ }
32606
+
32607
+ // src/study/onboarding-store.ts
32523
32608
  import * as fs56 from "node:fs";
32524
32609
  import * as path68 from "node:path";
32610
+ function onboardingDraftPath(workspaceRoot) {
32611
+ return path68.join(workspaceRoot, ...ONBOARDING_DRAFT_RELATIVE.split("/"));
32612
+ }
32613
+ function readOnboardingDraft(workspaceRoot) {
32614
+ try {
32615
+ const raw = fs56.readFileSync(onboardingDraftPath(workspaceRoot), "utf-8");
32616
+ return validateOnboardingAnswers(JSON.parse(raw));
32617
+ } catch {
32618
+ return {};
32619
+ }
32620
+ }
32621
+ function saveOnboardingDraft(workspaceRoot, answers) {
32622
+ const target = onboardingDraftPath(workspaceRoot);
32623
+ fs56.mkdirSync(path68.dirname(target), { recursive: true });
32624
+ fs56.writeFileSync(target, JSON.stringify({ ...answers, updatedAt: (/* @__PURE__ */ new Date()).toISOString() }, null, 2), "utf-8");
32625
+ }
32626
+ function consumeOnboardingDraft(workspaceRoot) {
32627
+ try {
32628
+ fs56.unlinkSync(onboardingDraftPath(workspaceRoot));
32629
+ } catch {
32630
+ }
32631
+ }
32525
32632
 
32526
- // ../drafting/src/write.ts
32633
+ // ../drafting/src/context.ts
32527
32634
  import * as fs57 from "node:fs";
32528
32635
  import * as path69 from "node:path";
32636
+
32637
+ // ../drafting/src/write.ts
32638
+ import * as fs58 from "node:fs";
32639
+ import * as path70 from "node:path";
32529
32640
  var DRAFT_KEYS = ["\u8EAB\u4EFD", "\u7248\u672C", "\u7236\u7248\u672C", "\u751F\u6210\u6A21\u5757", "\u6765\u6E90\u5FEB\u7167", "\u89D2\u8272", "\u9009\u5B9A"];
32530
32641
  function readText12(root, rel) {
32531
32642
  try {
32532
- return fs57.readFileSync(path69.join(root, rel), "utf-8");
32643
+ return fs58.readFileSync(path70.join(root, rel), "utf-8");
32533
32644
  } catch {
32534
32645
  return null;
32535
32646
  }
@@ -32538,9 +32649,9 @@ function draftDir(key) {
32538
32649
  return paths.\u8349\u7A3F\u76EE\u5F55(key.\u5377, key.\u7AE0\u540D);
32539
32650
  }
32540
32651
  function listDraftFiles(bookRoot, key) {
32541
- const abs = path69.join(bookRoot, draftDir(key));
32542
- if (!fs57.existsSync(abs) || !fs57.statSync(abs).isDirectory()) return [];
32543
- return fs57.readdirSync(abs).filter((f) => f.endsWith(".md")).sort((a, b) => a.localeCompare(b, "zh"));
32652
+ const abs = path70.join(bookRoot, draftDir(key));
32653
+ if (!fs58.existsSync(abs) || !fs58.statSync(abs).isDirectory()) return [];
32654
+ return fs58.readdirSync(abs).filter((f) => f.endsWith(".md")).sort((a, b) => a.localeCompare(b, "zh"));
32544
32655
  }
32545
32656
  function parseDraftNo(file) {
32546
32657
  const m = /^稿(\d+)\.md$/.exec(file);
@@ -32549,7 +32660,7 @@ function parseDraftNo(file) {
32549
32660
  function latestVersion(bookRoot, key) {
32550
32661
  let max = null;
32551
32662
  for (const file of listDraftFiles(bookRoot, key)) {
32552
- const text5 = readText12(bookRoot, path69.posix.join(draftDir(key), file));
32663
+ const text5 = readText12(bookRoot, path70.posix.join(draftDir(key), file));
32553
32664
  if (text5 === null) continue;
32554
32665
  const doc = parseDocument(text5);
32555
32666
  if (!doc.ok) continue;
@@ -32576,7 +32687,7 @@ function selectDraftLocked(bookRoot, input) {
32576
32687
  const files = listDraftFiles(bookRoot, input);
32577
32688
  if (!files.includes(target)) return { ok: false, reason: `\u8349\u7A3F\u4E0D\u5B58\u5728:${target}` };
32578
32689
  for (const file of files) {
32579
- const rel = path69.posix.join(dir, file);
32690
+ const rel = path70.posix.join(dir, file);
32580
32691
  const text5 = readText12(bookRoot, rel);
32581
32692
  if (text5 === null) continue;
32582
32693
  const doc = parseDocument(text5);
@@ -32600,7 +32711,7 @@ function writeDraftLocked(bookRoot, input) {
32600
32711
  const parent = latestVersion(bookRoot, key);
32601
32712
  const ver = parent === null ? initialVersion("\u5199\u7A3F") : bumpVersion(parent, "\u5199\u7A3F");
32602
32713
  const file = nextFileName(bookRoot, key);
32603
- const relPath = path69.posix.join(draftDir(key), file);
32714
+ const relPath = path70.posix.join(draftDir(key), file);
32604
32715
  const fields = applyVersionFields(
32605
32716
  {
32606
32717
  \u8EAB\u4EFD: { \u5377: input.\u5377, \u7AE0: input.\u7AE0, \u7AE0\u540D: input.\u7AE0\u540D },
@@ -32632,7 +32743,7 @@ function importAuthorDraftLocked(bookRoot, input) {
32632
32743
  const explicitParent = input.\u7236\u7248\u672C ?? latestVersion(bookRoot, key);
32633
32744
  const ver = explicitParent === null ? initialVersion("\u4F5C\u8005\u7A3F\u5BFC\u5165") : bumpVersion(explicitParent, "\u4F5C\u8005\u7A3F\u5BFC\u5165");
32634
32745
  const file = nextFileName(bookRoot, key);
32635
- const relPath = path69.posix.join(draftDir(key), file);
32746
+ const relPath = path70.posix.join(draftDir(key), file);
32636
32747
  if (input.\u89D2\u8272 === "\u5F85\u5BA1\u7A3F") demoteOtherPendingDrafts(bookRoot, key, relPath);
32637
32748
  const fields = applyVersionFields(
32638
32749
  {
@@ -32788,13 +32899,14 @@ function createNovelTools(deps) {
32788
32899
  },
32789
32900
  {
32790
32901
  name: "novel_create_book",
32791
- 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\u65F6\u5148\u95EE\u4F5C\u8005\u4E24\u4E2A\u95EE\u9898\u518D\u8C03\uFF1A\u8FD9\u4E2A\u9879\u76EE\u9762\u5411\u6D77\u5916\u8FD8\u662F\u4E2D\u6587\u5E02\u573A\uFF08\u5E02\u573A\uFF0C\u4E0D\u586B\u9ED8\u8BA4\u4E2D\u6587\uFF0C\u51B3\u5B9A\u52A0\u8F7D\u54EA\u5957\u9898\u6750\u5E93\uFF09\uFF0C\u8981\u51FA\u77ED\u5267\u3001\u7535\u5F71\u5267\u672C\u8FD8\u662F\u5C0F\u8BF4\uFF08\u8F93\u51FA\u5F62\u6001\uFF0C\u4E0D\u586B\u9ED8\u8BA4\u5C0F\u8BF4\uFF0C\u51B3\u5B9A\u8D70\u54EA\u6761\u6D41\u6C34\u7EBF\uFF09\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",
32792
32903
  parameters: {
32793
32904
  type: "object",
32794
32905
  properties: {
32795
32906
  bookName: { type: "string", description: "\u5C0F\u8BF4\u4E66\u540D\uFF08\u4E0D\u53EF\u542B\u8DEF\u5F84\u5B57\u7B26\u4E0E\u4FDD\u7559\u5B57\uFF09" },
32796
- \u5E02\u573A: { type: "string", enum: [...MARKET_VALUES], description: "\u76EE\u6807\u5E02\u573A\uFF1A\u6D77\u5916\uFF08\u6D77\u5916\u9898\u6750\u5E93\uFF09\u6216\u4E2D\u6587\uFF08\u4E2D\u6587\u9898\u6750\u5E93\uFF09\uFF1B\u53EF\u9009\uFF0C\u4E0D\u586B\u9ED8\u8BA4\u4E2D\u6587\u3002\u9876\u5C42\u53C2\u6570\u4F18\u5148\u4E8E concept \u91CC\u7684\u540C\u540D\u5B57\u6BB5\u3002" },
32797
- \u8F93\u51FA\u5F62\u6001: { type: "string", enum: [...OUTPUT_FORM_VALUES], description: "\u8F93\u51FA\u5F62\u6001\uFF1A\u77ED\u5267\u3001\u7535\u5F71\u5267\u672C\u6216\u5C0F\u8BF4\uFF1B\u53EF\u9009\uFF0C\u4E0D\u586B\u9ED8\u8BA4\u5C0F\u8BF4\u3002\u77ED\u5267\u8D70\u6309\u96C6\u6D41\u6C34\u7EBF\uFF0C\u7535\u5F71\u5267\u672C\u8D70\u5267\u672C\u6D41\u6C34\u7EBF\uFF0C\u5C0F\u8BF4\u8D70\u539F\u957F\u7BC7\u6D41\u6C34\u7EBF\u3002\u9876\u5C42\u53C2\u6570\u4F18\u5148\u4E8E concept \u91CC\u7684\u540C\u540D\u5B57\u6BB5\u3002" },
32907
+ \u5E02\u573A: { type: "string", enum: [...MARKET_VALUES], description: "\u76EE\u6807\u5E02\u573A\uFF1A\u6D77\u5916\uFF08\u6D77\u5916\u9898\u6750\u5E93\uFF09\u6216\u4E2D\u6587\uFF08\u4E2D\u6587\u9898\u6750\u5E93\uFF09\u3002\u5EFA\u4E66\u524D\u5FC5\u987B\u786E\u8BA4\uFF0C\u7F3A\u4E86\u4F1A\u88AB\u62D2\u7EDD\uFF1B\u4F5C\u8005\u660E\u786E\u8BF4\u6309\u9ED8\u8BA4\u624D\u4F20\u4E2D\u6587\u3002\u9876\u5C42\u53C2\u6570\u4F18\u5148\u4E8E concept \u91CC\u7684\u540C\u540D\u5B57\u6BB5\u3002" },
32908
+ \u8F93\u51FA\u5F62\u6001: { type: "string", enum: [...OUTPUT_FORM_VALUES], description: "\u8F93\u51FA\u5F62\u6001\uFF1A\u77ED\u5267\u3001\u7535\u5F71\u5267\u672C\u6216\u5C0F\u8BF4\u3002\u5EFA\u4E66\u524D\u5FC5\u987B\u786E\u8BA4\uFF0C\u7F3A\u4E86\u4F1A\u88AB\u62D2\u7EDD\uFF1B\u4F5C\u8005\u660E\u786E\u8BF4\u6309\u9ED8\u8BA4\u624D\u4F20\u5C0F\u8BF4\u3002\u77ED\u5267\u8D70\u6309\u96C6\u6D41\u6C34\u7EBF\uFF0C\u7535\u5F71\u5267\u672C\u8D70\u5267\u672C\u6D41\u6C34\u7EBF\uFF0C\u5C0F\u8BF4\u8D70\u539F\u957F\u7BC7\u6D41\u6C34\u7EBF\u3002\u9876\u5C42\u53C2\u6570\u4F18\u5148\u4E8E concept \u91CC\u7684\u540C\u540D\u5B57\u6BB5\u3002" },
32909
+ \u76EE\u6807\u603B\u5B57\u6570: { type: "integer", minimum: 1, description: "\u76EE\u6807\u603B\u5B57\u6570\uFF08\u6C49\u5B57\u6570\uFF0C\u6B63\u6574\u6570\uFF09\u3002\u5EFA\u4E66\u524D\u5FC5\u987B\u786E\u8BA4\uFF0C\u7F3A\u4E86\u4F1A\u88AB\u62D2\u7EDD\uFF1B\u4F5C\u8005\u660E\u786E\u8BF4\u6309\u9ED8\u8BA4\u624D\u4F20 1000000\uFF08\u957F\u7BC7\uFF09\u3002\u9876\u5C42\u53C2\u6570\u4F18\u5148\u4E8E concept \u91CC\u7684\u540C\u540D\u5B57\u6BB5\u3002" },
32798
32910
  concept: {
32799
32911
  type: "object",
32800
32912
  description: "\u4F5C\u54C1\u6784\u60F3\u4E03\u8981\u7D20\uFF08\u72B6\u6001\u5FC5\u987B\u4E3A\u5DF2\u786E\u8BA4\uFF09",
@@ -32807,8 +32919,9 @@ function createNovelTools(deps) {
32807
32919
  \u6838\u5FC3\u770B\u70B9: { type: "string" },
32808
32920
  \u5DEE\u5F02\u5316\u65B9\u5411: { type: "string" },
32809
32921
  \u660E\u786E\u4E0D\u8981\u4EC0\u4E48: { type: "string" },
32810
- \u5E02\u573A: { type: "string", enum: [...MARKET_VALUES], description: "\u76EE\u6807\u5E02\u573A\uFF1A\u6D77\u5916\u6216\u4E2D\u6587\uFF1B\u53EF\u9009\uFF0C\u4E0D\u586B\u9ED8\u8BA4\u4E2D\u6587" },
32811
- \u8F93\u51FA\u5F62\u6001: { type: "string", enum: [...OUTPUT_FORM_VALUES], description: "\u8F93\u51FA\u5F62\u6001\uFF1A\u77ED\u5267\u3001\u7535\u5F71\u5267\u672C\u6216\u5C0F\u8BF4\uFF1B\u53EF\u9009\uFF0C\u4E0D\u586B\u9ED8\u8BA4\u5C0F\u8BF4" }
32922
+ \u5E02\u573A: { type: "string", enum: [...MARKET_VALUES], description: "\u76EE\u6807\u5E02\u573A\uFF1A\u6D77\u5916\u6216\u4E2D\u6587\uFF1B\u5EFA\u4E66\u524D\u5FC5\u987B\u786E\u8BA4\uFF0C\u7F3A\u4E86\u4F1A\u88AB\u62D2\u7EDD" },
32923
+ \u8F93\u51FA\u5F62\u6001: { type: "string", enum: [...OUTPUT_FORM_VALUES], description: "\u8F93\u51FA\u5F62\u6001\uFF1A\u77ED\u5267\u3001\u7535\u5F71\u5267\u672C\u6216\u5C0F\u8BF4\uFF1B\u5EFA\u4E66\u524D\u5FC5\u987B\u786E\u8BA4\uFF0C\u7F3A\u4E86\u4F1A\u88AB\u62D2\u7EDD" },
32924
+ \u76EE\u6807\u603B\u5B57\u6570: { type: "integer", minimum: 1, description: "\u76EE\u6807\u603B\u5B57\u6570\uFF08\u6C49\u5B57\u6570\uFF0C\u6B63\u6574\u6570\uFF09\uFF1B\u5EFA\u4E66\u524D\u5FC5\u987B\u786E\u8BA4\uFF0C\u7F3A\u4E86\u4F1A\u88AB\u62D2\u7EDD" }
32812
32925
  },
32813
32926
  required: ["\u72B6\u6001", "\u6838\u5FC3\u521B\u610F", "\u9898\u6750\u4E0E\u76EE\u6807\u8BFB\u8005", "\u4E3B\u89D2\u6838\u5FC3\u6B32\u671B", "\u4E3B\u8981\u51B2\u7A81", "\u6838\u5FC3\u770B\u70B9", "\u5DEE\u5F02\u5316\u65B9\u5411", "\u660E\u786E\u4E0D\u8981\u4EC0\u4E48"]
32814
32927
  }
@@ -32834,13 +32947,24 @@ function createNovelTools(deps) {
32834
32947
  if (root === void 0) return toolFailure("host-unavailable", "\u5DE5\u4F5C\u8303\u56F4\u672A\u5C31\u7EEA\uFF1A\u5DE5\u4F5C\u53F0\u8FD8\u6CA1\u6709\u52A0\u8F7D\u5DE5\u4F5C\u533A");
32835
32948
  const bookName = String(args["bookName"]).trim();
32836
32949
  const concept = args["concept"];
32837
- const \u5E02\u573A = marketOf({ ...concept, \u5E02\u573A: args["\u5E02\u573A"] ?? concept.\u5E02\u573A });
32838
- const \u8F93\u51FA\u5F62\u6001 = outputFormOf({ ...concept, \u8F93\u51FA\u5F62\u6001: args["\u8F93\u51FA\u5F62\u6001"] ?? concept.\u8F93\u51FA\u5F62\u6001 });
32839
- if (args["\u5E02\u573A"] !== void 0 && !isMarketValue(args["\u5E02\u573A"])) return toolFailure("invalid-argument", `\u5E02\u573A\u53D6\u503C\u975E\u6CD5\uFF1A${String(args["\u5E02\u573A"])}\uFF0C\u53EA\u63A5\u53D7 \u6D77\u5916 / \u4E2D\u6587`);
32840
- if (args["\u8F93\u51FA\u5F62\u6001"] !== void 0 && !isOutputFormValue(args["\u8F93\u51FA\u5F62\u6001"])) return toolFailure("invalid-argument", `\u8F93\u51FA\u5F62\u6001\u53D6\u503C\u975E\u6CD5\uFF1A${String(args["\u8F93\u51FA\u5F62\u6001"])}\uFF0C\u53EA\u63A5\u53D7 \u77ED\u5267 / \u7535\u5F71\u5267\u672C / \u5C0F\u8BF4`);
32841
- if (concept.\u5E02\u573A !== void 0 && !isMarketValue(concept.\u5E02\u573A)) return toolFailure("invalid-argument", `concept.\u5E02\u573A\u53D6\u503C\u975E\u6CD5\uFF1A${String(concept.\u5E02\u573A)}\uFF0C\u53EA\u63A5\u53D7 \u6D77\u5916 / \u4E2D\u6587`);
32842
- if (concept.\u8F93\u51FA\u5F62\u6001 !== void 0 && !isOutputFormValue(concept.\u8F93\u51FA\u5F62\u6001)) return toolFailure("invalid-argument", `concept.\u8F93\u51FA\u5F62\u6001\u53D6\u503C\u975E\u6CD5\uFF1A${String(concept.\u8F93\u51FA\u5F62\u6001)}\uFF0C\u53EA\u63A5\u53D7 \u77ED\u5267 / \u7535\u5F71\u5267\u672C / \u5C0F\u8BF4`);
32843
- const res = createBook({ workspaceRoot: root, \u4E66\u540D: bookName, concept: { ...concept, \u5E02\u573A, \u8F93\u51FA\u5F62\u6001 } });
32950
+ const draft = readOnboardingDraft(root);
32951
+ const \u5E02\u573A = args["\u5E02\u573A"] ?? concept.\u5E02\u573A ?? draft.\u5E02\u573A;
32952
+ const \u8F93\u51FA\u5F62\u6001 = args["\u8F93\u51FA\u5F62\u6001"] ?? concept.\u8F93\u51FA\u5F62\u6001 ?? draft.\u8F93\u51FA\u5F62\u6001;
32953
+ const rawWords = args["\u76EE\u6807\u603B\u5B57\u6570"] ?? concept.\u76EE\u6807\u603B\u5B57\u6570 ?? draft.\u76EE\u6807\u603B\u5B57\u6570;
32954
+ const \u76EE\u6807\u603B\u5B57\u6570 = typeof rawWords === "string" ? Number(rawWords) : rawWords;
32955
+ const missing = onboardingMissing({ \u5E02\u573A, \u8F93\u51FA\u5F62\u6001, \u76EE\u6807\u603B\u5B57\u6570 });
32956
+ if (missing.length > 0) {
32957
+ return toolFailure(
32958
+ "invalid-argument",
32959
+ `\u5EFA\u4E66\u524D\u5FC5\u987B\u5148\u786E\u8BA4${missing.join("\u3001")}\uFF0C\u7F3A\u4E86\u4E0D\u80FD\u5EFA\u4E66\u3002`,
32960
+ `\u5148\u95EE\u4F5C\u8005\uFF08\u540C\u4E00\u6761\u6D88\u606F\u4E00\u6B21\u95EE\u5B8C\uFF0C\u5404\u7ED9\u9009\u9879\uFF1B\u4F5C\u8005\u4E5F\u53EF\u4EE5\u5728\u4E66\u623F\u9762\u677F\u70B9\u201C\u65B0\u5EFA\u4E66\u201D\u76F4\u63A5\u70B9\u9009\uFF0C\u9009\u597D\u540E\u76F4\u63A5\u91CD\u8C03\u672C\u5DE5\u5177\uFF09\uFF1A\u5E02\u573A\u2014\u2014\u201C\u8FD9\u4E2A\u9879\u76EE\u9762\u5411\u6D77\u5916\u8FD8\u662F\u4E2D\u6587\u5E02\u573A\uFF1F\u201D\uFF081. \u4E2D\u6587\u2605\u63A8\u8350 2. \u6D77\u5916 3. \u81EA\u5DF1\u6709\u60F3\u6CD5\uFF0C\u624B\u52A8\u8F93\u5165\uFF09\uFF1B\u8F93\u51FA\u5F62\u6001\u2014\u2014\u201C\u8981\u51FA\u77ED\u5267\u3001\u7535\u5F71\u5267\u672C\u8FD8\u662F\u5C0F\u8BF4\uFF1F\u201D\uFF081. \u5C0F\u8BF4\u2605\u63A8\u8350 2. \u77ED\u5267 3. \u7535\u5F71\u5267\u672C 4. \u81EA\u5DF1\u6709\u60F3\u6CD5\uFF0C\u624B\u52A8\u8F93\u5165\uFF09\uFF1B\u76EE\u6807\u603B\u5B57\u6570\u2014\u2014\u201C\u8FD9\u672C\u4E66\u76EE\u6807\u5199\u591A\u5C11\u5B57\uFF1F\u201D\uFF081. \u77ED\u7BC7\xB75\u4E07\u5B57 2. \u4E2D\u7BC7\xB730\u4E07\u5B57 3. \u957F\u7BC7\xB7100\u4E07\u5B57\u2605\u63A8\u8350 4. \u8D85\u957F\u7BC7\xB7200\u4E07\u5B57 5. \u81EA\u5DF1\u6709\u60F3\u6CD5\uFF0C\u624B\u52A8\u8F93\u5165\u5177\u4F53\u6570\u5B57\uFF09\u3002\u62FF\u5230\u7B54\u6848\u518D\u8C03 novel_create_book\uFF0C\u628A\u503C\u4F20\u8FDB\u6765\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\u3002\u4E0D\u8981\u7528\u9ED8\u8BA4\u503C\u76F4\u63A5\u5EFA\u4E66\u3002`
32961
+ );
32962
+ }
32963
+ if (\u5E02\u573A !== void 0 && !isMarketValue(\u5E02\u573A)) return toolFailure("invalid-argument", `\u5E02\u573A\u53D6\u503C\u975E\u6CD5\uFF1A${String(\u5E02\u573A)}\uFF0C\u53EA\u63A5\u53D7 \u6D77\u5916 / \u4E2D\u6587`);
32964
+ if (\u8F93\u51FA\u5F62\u6001 !== void 0 && !isOutputFormValue(\u8F93\u51FA\u5F62\u6001)) return toolFailure("invalid-argument", `\u8F93\u51FA\u5F62\u6001\u53D6\u503C\u975E\u6CD5\uFF1A${String(\u8F93\u51FA\u5F62\u6001)}\uFF0C\u53EA\u63A5\u53D7 \u77ED\u5267 / \u7535\u5F71\u5267\u672C / \u5C0F\u8BF4`);
32965
+ if (!isTargetTotalWordsValue(\u76EE\u6807\u603B\u5B57\u6570)) return toolFailure("invalid-argument", `\u76EE\u6807\u603B\u5B57\u6570\u53D6\u503C\u975E\u6CD5\uFF1A${String(\u76EE\u6807\u603B\u5B57\u6570)}\uFF0C\u53EA\u63A5\u53D7\u6B63\u6574\u6570\u6C49\u5B57\u6570`);
32966
+ const res = createBook({ workspaceRoot: root, \u4E66\u540D: bookName, concept: { ...concept, \u5E02\u573A, \u8F93\u51FA\u5F62\u6001, \u76EE\u6807\u603B\u5B57\u6570 } });
32967
+ if (res.ok) consumeOnboardingDraft(root);
32844
32968
  return res;
32845
32969
  }
32846
32970
  },
@@ -32955,7 +33079,7 @@ function createNovelTools(deps) {
32955
33079
  paths.\u5377\u7EB2(\u5377),
32956
33080
  paths.\u8BA1\u5212\u65F6\u95F4\u7EBF(\u5377),
32957
33081
  paths.\u8FD1\u671F\u7A97\u53E3(\u5377)
32958
- ].filter((p) => fs58.existsSync(nodePath3.join(bookRoot, p)));
33082
+ ].filter((p) => fs59.existsSync(nodePath3.join(bookRoot, p)));
32959
33083
  const commit = commitConfirmed({ bookRoot, paths: seedPaths, prefix: "design", summary: "\u6700\u5C0F\u8BBE\u8BA1\u9AA8\u67B6", provenance: provenanceOf(sessionContext, seedPaths) });
32960
33084
  if (!commit.ok) {
32961
33085
  return { ok: false, reason: `\u6700\u5C0F\u8BBE\u8BA1\u5DF2\u5199\u5165\u4F46\u63D0\u4EA4\u5931\u8D25\uFF08\u91CD\u8DD1\u672C\u5DE5\u5177\u5373\u53EF\u8865\u63D0\u4EA4\uFF09\uFF1A${commit.reason}` };
@@ -33551,7 +33675,7 @@ function createNovelTools(deps) {
33551
33675
  const rel = paths.\u8FD1\u671F\u7A97\u53E3(\u5377);
33552
33676
  let text5 = "";
33553
33677
  try {
33554
- text5 = fs58.readFileSync(nodePath3.join(book.bookRoot, rel), "utf-8");
33678
+ text5 = fs59.readFileSync(nodePath3.join(book.bookRoot, rel), "utf-8");
33555
33679
  } catch {
33556
33680
  text5 = "";
33557
33681
  }
@@ -34247,7 +34371,7 @@ function createNovelTools(deps) {
34247
34371
  const res = archiveRetconRequest({ bookRoot, chapter: \u5B9A\u7A3F\u76F8\u5BF9, request, provenance: provenanceOf(sessionContext) }, (plannedPackageDir) => {
34248
34372
  let \u66F4\u6B63\u540E\u5168\u6587;
34249
34373
  try {
34250
- const src = fs58.readFileSync(nodePath3.join(bookRoot, \u5B9A\u7A3F\u76F8\u5BF9), "utf-8");
34374
+ const src = fs59.readFileSync(nodePath3.join(bookRoot, \u5B9A\u7A3F\u76F8\u5BF9), "utf-8");
34251
34375
  const doc = parseDocument(src);
34252
34376
  if (!doc.ok) return { ok: false, reason: `\u5B9A\u7A3F\u7AE0\u89E3\u6790\u5931\u8D25\uFF1A${doc.detail}` };
34253
34377
  const parent = extractVersionFields(doc.data.fields).\u7248\u672C;
@@ -34275,19 +34399,19 @@ function createNovelTools(deps) {
34275
34399
  const value = optionalText(f);
34276
34400
  return value === null ? [] : [[\u5019\u9009\u6587\u4EF6[f], value]];
34277
34401
  }));
34278
- if (fs58.existsSync(\u5305\u7EDD\u5BF9)) {
34279
- for (const name3 of fs58.readdirSync(\u5305\u7EDD\u5BF9)) {
34402
+ if (fs59.existsSync(\u5305\u7EDD\u5BF9)) {
34403
+ for (const name3 of fs59.readdirSync(\u5305\u7EDD\u5BF9)) {
34280
34404
  const file = nodePath3.join(\u5305\u7EDD\u5BF9, name3);
34281
- const stat = fs58.lstatSync(file);
34282
- if (!contents.has(name3) || !stat.isFile() || stat.isSymbolicLink() || fs58.readFileSync(file, "utf8") !== contents.get(name3)) {
34405
+ const stat = fs59.lstatSync(file);
34406
+ if (!contents.has(name3) || !stat.isFile() || stat.isSymbolicLink() || fs59.readFileSync(file, "utf8") !== contents.get(name3)) {
34283
34407
  return { ok: false, reason: "\u8865\u507F\u5305\u5019\u9009\u51B2\u7A81\uFF0C\u5DF2\u4FDD\u7559\uFF0C\u8BF7\u6838\u5BF9\u540E\u5904\u7406" };
34284
34408
  }
34285
34409
  }
34286
34410
  }
34287
- fs58.mkdirSync(\u5305\u7EDD\u5BF9, { recursive: true });
34411
+ fs59.mkdirSync(\u5305\u7EDD\u5BF9, { recursive: true });
34288
34412
  for (const [name3, value] of contents) {
34289
34413
  const file = nodePath3.join(\u5305\u7EDD\u5BF9, name3);
34290
- if (!fs58.existsSync(file)) fs58.writeFileSync(file, value, { encoding: "utf8", flag: "wx" });
34414
+ if (!fs59.existsSync(file)) fs59.writeFileSync(file, value, { encoding: "utf8", flag: "wx" });
34291
34415
  }
34292
34416
  packageDir = \u5305\u76F8\u5BF9;
34293
34417
  }
@@ -34308,7 +34432,7 @@ function createNovelTools(deps) {
34308
34432
  retconFiles.push({ \u76EE\u6807: \u6458\u8981\u76F8\u5BF9, \u5185\u5BB9: request.\u66F4\u6B63\u540E\u7AE0\u6458\u8981 });
34309
34433
  } else {
34310
34434
  try {
34311
- const \u6458\u8981\u73B0\u6587 = fs58.readFileSync(nodePath3.join(bookRoot, \u6458\u8981\u76F8\u5BF9), "utf-8");
34435
+ const \u6458\u8981\u73B0\u6587 = fs59.readFileSync(nodePath3.join(bookRoot, \u6458\u8981\u76F8\u5BF9), "utf-8");
34312
34436
  retconFiles.push({
34313
34437
  \u76EE\u6807: \u6458\u8981\u76F8\u5BF9,
34314
34438
  \u5185\u5BB9: `> \u3014\u6458\u8981\u8FC7\u671F\u3015\u5B9A\u7A3F\u6B63\u6587\u5DF2\u7ECF\u5403\u4E66\u8865\u507F\u66F4\u6B63,\u672C\u6458\u8981\u5F85\u91CD\u505A(\u5173\u8054\u63D0\u6848 ${String(args["\u63D0\u6848\u7F16\u53F7"] ?? "\uFF08\u672A\u767B\u8BB0\uFF09")})
@@ -34765,8 +34889,8 @@ function finishDesignCommit(bookRoot, writtenPaths, args, defaultSummary, chapte
34765
34889
  import { boundContextSummary, createUserMessage as createUserMessage3 } from "@deepseek-ai/dsh-llm";
34766
34890
 
34767
34891
  // src/study/service.ts
34768
- import * as fs61 from "node:fs";
34769
- import * as path72 from "node:path";
34892
+ import * as fs62 from "node:fs";
34893
+ import * as path73 from "node:path";
34770
34894
 
34771
34895
  // ../../node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/diff/base.js
34772
34896
  var Diff = class {
@@ -34868,16 +34992,16 @@ var Diff = class {
34868
34992
  }
34869
34993
  }
34870
34994
  }
34871
- addToPath(path79, added, removed, oldPosInc, options2) {
34872
- const last = path79.lastComponent;
34995
+ addToPath(path80, added, removed, oldPosInc, options2) {
34996
+ const last = path80.lastComponent;
34873
34997
  if (last && !options2.oneChangePerToken && last.added === added && last.removed === removed) {
34874
34998
  return {
34875
- oldPos: path79.oldPos + oldPosInc,
34999
+ oldPos: path80.oldPos + oldPosInc,
34876
35000
  lastComponent: { count: last.count + 1, added, removed, previousComponent: last.previousComponent }
34877
35001
  };
34878
35002
  } else {
34879
35003
  return {
34880
- oldPos: path79.oldPos + oldPosInc,
35004
+ oldPos: path80.oldPos + oldPosInc,
34881
35005
  lastComponent: { count: 1, added, removed, previousComponent: last }
34882
35006
  };
34883
35007
  }
@@ -35068,7 +35192,7 @@ var text4 = (value) => typeof value === "string" ? value : "";
35068
35192
  var terms = (value) => Array.isArray(value) ? value.flatMap(terms) : typeof value === "string" ? value.split(/[、,,;]/).map((item) => item.trim()).filter(Boolean) : [];
35069
35193
  var wiki = (body) => [...body.matchAll(/\[\[([^\]\n]+)\]\]/g)].map((match) => match[1].split("|")[0].trim());
35070
35194
  var identity3 = (name3) => name3.trim().replace(/[\s「」『』【】()()::,,。!?!?]/g, "").toLowerCase();
35071
- var kindOf = (path79, declared) => typeof declared === "string" && declared.trim() ? { \u4EBA\u7269\u6863\u6848: "\u4EBA\u7269", \u4EBA\u7269\u5173\u7CFB: "\u5173\u7CFB", \u7EC4\u7EC7\u4E0E\u9635\u8425: "\u7EC4\u7EC7", \u5730\u70B9\u4E0E\u7A7A\u95F4: "\u5730\u70B9" }[declared.trim()] ?? declared.trim() : path79.includes("/\u4EBA\u7269\u6863\u6848/") ? "\u4EBA\u7269" : path79.includes("/\u4EBA\u7269\u5173\u7CFB/") ? "\u5173\u7CFB" : path79.includes("/\u7EC4\u7EC7\u4E0E\u9635\u8425/") ? "\u7EC4\u7EC7" : path79.includes("/\u5730\u70B9\u4E0E\u7A7A\u95F4/") ? "\u5730\u70B9" : "\u8BBE\u5B9A";
35195
+ var kindOf = (path80, declared) => typeof declared === "string" && declared.trim() ? { \u4EBA\u7269\u6863\u6848: "\u4EBA\u7269", \u4EBA\u7269\u5173\u7CFB: "\u5173\u7CFB", \u7EC4\u7EC7\u4E0E\u9635\u8425: "\u7EC4\u7EC7", \u5730\u70B9\u4E0E\u7A7A\u95F4: "\u5730\u70B9" }[declared.trim()] ?? declared.trim() : path80.includes("/\u4EBA\u7269\u6863\u6848/") ? "\u4EBA\u7269" : path80.includes("/\u4EBA\u7269\u5173\u7CFB/") ? "\u5173\u7CFB" : path80.includes("/\u7EC4\u7EC7\u4E0E\u9635\u8425/") ? "\u7EC4\u7EC7" : path80.includes("/\u5730\u70B9\u4E0E\u7A7A\u95F4/") ? "\u5730\u70B9" : "\u8BBE\u5B9A";
35072
35196
  function readStoryGraph(source2) {
35073
35197
  const records = [], edges = [], events = [];
35074
35198
  const warnings = [];
@@ -35100,7 +35224,7 @@ function readStoryGraph(source2) {
35100
35224
  aliases.set(name3, values);
35101
35225
  };
35102
35226
  const strings = (fields) => Object.fromEntries(Object.entries(fields).filter((pair) => typeof pair[1] === "string"));
35103
- const fromFields = (id, label2, kind2, path79, line, fields, body) => ({
35227
+ const fromFields = (id, label2, kind2, path80, line, fields, body) => ({
35104
35228
  id,
35105
35229
  label: label2,
35106
35230
  kind: kind2,
@@ -35109,23 +35233,23 @@ function readStoryGraph(source2) {
35109
35233
  chapter: chapter(fields["\u8D77\u59CB\u7AE0"]) ?? chapter(fields["\u751F\u6548\u7AE0"]) ?? chapter(fields["\u7AE0\u53F7"]) ?? entryChapterNo({ \u5B57\u6BB5: strings(fields) }) ?? void 0,
35110
35234
  endChapter: chapter(fields["\u5931\u6548\u7AE0"]),
35111
35235
  revealChapter: chapter(fields["\u62AB\u9732\u7AE0"]) ?? chapter(fields["\u63ED\u793A\u7AE0"]),
35112
- source: { space: "book:" + source2.bookId, path: path79 },
35236
+ source: { space: "book:" + source2.bookId, path: path80 },
35113
35237
  line,
35114
35238
  preview: body.trim().slice(0, 600),
35115
35239
  // Expose authored scalar/list field names as grouping choices without
35116
35240
  // guessing whether 宗门/血脉/师承 means faction, family or another identity.
35117
35241
  affiliations: (id.startsWith("world:") ? Object.entries(fields) : []).filter(([field, value]) => !["\u540D\u79F0", "\u7C7B\u578B", "\u6027\u8D28", "\u72B6\u6001", "\u6765\u6E90", "\u6765\u6E90\u5F15\u7528", "\u7248\u672C", "\u7236\u7248\u672C", "\u751F\u6210\u6A21\u5757", "\u7AE0\u53F7", "\u8D77\u59CB\u7AE0", "\u751F\u6548\u7AE0", "\u5931\u6548\u7AE0", "\u62AB\u9732\u7AE0", "\u63ED\u793A\u7AE0", "\u522B\u540D", "\u5173\u7CFB", "\u5173\u7CFB\u7C7B\u578B", "\u5173\u7CFB\u53CC\u65B9", "\u4E3B\u4F53", "\u5BA2\u4F53"].includes(field) && (typeof value === "string" && !/[\r\n]/.test(value) && value.length <= 128 || Array.isArray(value) && value.length <= 24 && value.every((item) => typeof item === "string" && item.length <= 128 && !/[\r\n]/.test(item)))).flatMap(([field, value]) => terms(value).map((label3) => ({ field, label: label3 })))
35118
35242
  });
35119
- const scan = (path79, depth = 0) => {
35243
+ const scan = (path80, depth = 0) => {
35120
35244
  if (depth > 12) {
35121
- warnings.push({ path: path79, message: "\u76EE\u5F55\u5C42\u7EA7\u8FC7\u6DF1\uFF0C\u672A\u7EE7\u7EED\u8BFB\u53D6" });
35245
+ warnings.push({ path: path80, message: "\u76EE\u5F55\u5C42\u7EA7\u8FC7\u6DF1\uFF0C\u672A\u7EE7\u7EED\u8BFB\u53D6" });
35122
35246
  return;
35123
35247
  }
35124
35248
  let entries;
35125
35249
  try {
35126
- entries = source2.list(path79);
35250
+ entries = source2.list(path80);
35127
35251
  } catch (error) {
35128
- if (error.code !== "not-found") warnings.push({ path: path79, message: "\u8BE5\u76EE\u5F55\u65E0\u6CD5\u8BFB\u53D6" });
35252
+ if (error.code !== "not-found") warnings.push({ path: path80, message: "\u8BE5\u76EE\u5F55\u65E0\u6CD5\u8BFB\u53D6" });
35129
35253
  return;
35130
35254
  }
35131
35255
  for (const entry of entries) {
@@ -35216,26 +35340,26 @@ function readStoryGraph(source2) {
35216
35340
  };
35217
35341
  scan("\u4E16\u754C\u4E66");
35218
35342
  for (const category of LEDGER_NAMES) {
35219
- const path79 = "\u8D26\u672C/" + category + ".md";
35343
+ const path80 = "\u8D26\u672C/" + category + ".md";
35220
35344
  let raw;
35221
35345
  try {
35222
- raw = source2.read(path79);
35346
+ raw = source2.read(path80);
35223
35347
  } catch (error) {
35224
- if (error.code !== "not-found") warnings.push({ path: path79, message: "\u8BE5\u8D26\u672C\u65E0\u6CD5\u8BFB\u53D6" });
35348
+ if (error.code !== "not-found") warnings.push({ path: path80, message: "\u8BE5\u8D26\u672C\u65E0\u6CD5\u8BFB\u53D6" });
35225
35349
  continue;
35226
35350
  }
35227
35351
  const ranges2 = createEvidenceRanges(raw);
35228
- sourceHashes[path79] = ranges2.hash;
35229
- const parsed = parseLedgerHistory(raw, category, path79);
35352
+ sourceHashes[path80] = ranges2.hash;
35353
+ const parsed = parseLedgerHistory(raw, category, path80);
35230
35354
  if (!parsed.ok) {
35231
- warnings.push({ path: path79, message: parsed.reason });
35355
+ warnings.push({ path: path80, message: parsed.reason });
35232
35356
  continue;
35233
35357
  }
35234
35358
  for (const [index, entry] of parsed.entries.entries()) {
35235
- const id = category === "\u65F6\u95F4\u7EBF" ? "event:" + path79 + ":" + entry.\u884C\u53F7 : "ledger:" + category + ":" + identity3(entry.\u540D\u79F0);
35359
+ const id = category === "\u65F6\u95F4\u7EBF" ? "event:" + path80 + ":" + entry.\u884C\u53F7 : "ledger:" + category + ":" + identity3(entry.\u540D\u79F0);
35236
35360
  const content = category === "\u65F6\u95F4\u7EBF" ? renderTimelineContent(entry) : entry.\u6B63\u6587;
35237
35361
  const evidenceId = id + ":" + entry.\u884C\u53F7;
35238
- const base = fromFields(id, entry.\u540D\u79F0, category === "\u65F6\u95F4\u7EBF" ? "\u4E8B\u4EF6" : category, path79, entry.\u884C\u53F7, entry.\u5B57\u6BB5, content);
35362
+ const base = fromFields(id, entry.\u540D\u79F0, category === "\u65F6\u95F4\u7EBF" ? "\u4E8B\u4EF6" : category, path80, entry.\u884C\u53F7, entry.\u5B57\u6BB5, content);
35239
35363
  const recordChapter2 = entryChapterNo(entry) ?? void 0;
35240
35364
  const storyTime = category === "\u65F6\u95F4\u7EBF" ? timelineStoryTime(entry) : void 0;
35241
35365
  const record4 = { ...base, recordChapter: recordChapter2, storyTime, historyBasis: recordChapter2 ? "recorded" : "unknown", evidenceId };
@@ -35256,11 +35380,11 @@ function readStoryGraph(source2) {
35256
35380
  links.push({ record: record4, targets: wiki(content), pair: false });
35257
35381
  }
35258
35382
  }
35259
- const resolve22 = (target, path79) => {
35383
+ const resolve22 = (target, path80) => {
35260
35384
  const name3 = target.replace(/^\[\[|\]\]$/g, "").replace(/@\d+$/, "").replace(/\\/g, "/");
35261
35385
  const found = aliases.get(name3);
35262
35386
  if (found?.size === 1) return [...found][0];
35263
- warnings.push({ path: path79, message: found?.size ? "\u540C\u540D\u6216\u522B\u540D\u4E0D\u552F\u4E00\uFF0C\u672A\u5408\u5E76\uFF1A" + name3 : "\u5F15\u7528\u672A\u627E\u5230\u5BF9\u5E94\u5B9E\u4F53\uFF1A" + name3 });
35387
+ warnings.push({ path: path80, message: found?.size ? "\u540C\u540D\u6216\u522B\u540D\u4E0D\u552F\u4E00\uFF0C\u672A\u5408\u5E76\uFF1A" + name3 : "\u5F15\u7528\u672A\u627E\u5230\u5BF9\u5E94\u5B9E\u4F53\uFF1A" + name3 });
35264
35388
  return void 0;
35265
35389
  };
35266
35390
  for (const item of links) {
@@ -35284,32 +35408,32 @@ function readStoryGraph(source2) {
35284
35408
  const currentBound = (items) => items.map((item) => item.currentOnlyAt === void 0 ? item : { ...item, currentOnlyAt: maxChapter });
35285
35409
  const withChapters = evidence.map((item) => {
35286
35410
  const references = terms(item.fields["\u6765\u6E90"]).map((value) => normalizeNodeKey(value.replace(/^\[\[|\]\]$/g, "").split("|")[0].replace(/@[^/@]+$/, ""))).filter((value) => !!value && /^定稿\/卷\d+\/\d{4}-[^/]+\.md$/.test(value));
35287
- return { ...item, relatedChapters: [...new Set(references)].map((path79) => ({ space: item.source.space, path: path79 })) };
35411
+ return { ...item, relatedChapters: [...new Set(references)].map((path80) => ({ space: item.source.space, path: path80 })) };
35288
35412
  });
35289
35413
  return { bookId: source2.bookId, bookName: source2.bookName, maxChapter, records: currentBound(records), edges: currentBound(edges), events, warnings, evidence: withChapters, entities, sourceHashes, fingerprint: fingerprint2, format: format2 };
35290
35414
  }
35291
35415
 
35292
35416
  // src/study/graph-source.ts
35293
- import * as fs59 from "node:fs";
35294
- import * as path70 from "node:path";
35417
+ import * as fs60 from "node:fs";
35418
+ import * as path71 from "node:path";
35295
35419
  import { createHash as createHash20 } from "node:crypto";
35296
35420
  function readGraphFile(base, relative12) {
35297
35421
  validateAuthorRelativePath(relative12);
35298
- const file = path70.join(base, relative12);
35422
+ const file = path71.join(base, relative12);
35299
35423
  const checkPhysical = () => {
35300
- if (stripDevicePrefix(fs59.realpathSync.native(file)) !== file) throw new AuthorDocumentError("invalid-path", "\u56FE\u8C31\u6765\u6E90\u8DEF\u5F84\u5305\u542B\u94FE\u63A5\u6216\u522B\u540D");
35424
+ if (stripDevicePrefix(fs60.realpathSync.native(file)) !== file) throw new AuthorDocumentError("invalid-path", "\u56FE\u8C31\u6765\u6E90\u8DEF\u5F84\u5305\u542B\u94FE\u63A5\u6216\u522B\u540D");
35301
35425
  };
35302
35426
  checkPhysical();
35303
- const initial = fs59.lstatSync(file);
35427
+ const initial = fs60.lstatSync(file);
35304
35428
  if (!initial.isFile() || initial.isSymbolicLink() || initial.nlink !== 1) throw new AuthorDocumentError("invalid-path", "\u56FE\u8C31\u6765\u6E90\u5FC5\u987B\u662F\u72EC\u7ACB\u7684\u666E\u901A\u6587\u4EF6");
35305
35429
  if (initial.size > 4 * 1024 * 1024) throw new AuthorDocumentError("read-only", "\u56FE\u8C31\u6765\u6E90\u8D85\u8FC74MiB\uFF0C\u672A\u622A\u65AD\u8BFB\u53D6");
35306
- const descriptor = fs59.openSync(file, fs59.constants.O_RDONLY | (fs59.constants.O_NOFOLLOW ?? 0));
35430
+ const descriptor = fs60.openSync(file, fs60.constants.O_RDONLY | (fs60.constants.O_NOFOLLOW ?? 0));
35307
35431
  try {
35308
- const opened = fs59.fstatSync(descriptor);
35432
+ const opened = fs60.fstatSync(descriptor);
35309
35433
  if (opened.dev !== initial.dev || opened.ino !== initial.ino || opened.nlink !== 1) throw new AuthorDocumentError("conflict", "\u56FE\u8C31\u6765\u6E90\u5728\u6253\u5F00\u65F6\u88AB\u66FF\u6362");
35310
- const bytes = fs59.readFileSync(descriptor);
35434
+ const bytes = fs60.readFileSync(descriptor);
35311
35435
  checkPhysical();
35312
- const current = fs59.lstatSync(file), finished = fs59.fstatSync(descriptor);
35436
+ const current = fs60.lstatSync(file), finished = fs60.fstatSync(descriptor);
35313
35437
  if (!current.isFile() || current.nlink !== 1 || current.dev !== opened.dev || current.ino !== opened.ino || finished.size !== opened.size || finished.mtimeMs !== opened.mtimeMs || finished.ctimeMs !== opened.ctimeMs) throw new AuthorDocumentError("conflict", "\u56FE\u8C31\u6765\u6E90\u5728\u8BFB\u53D6\u671F\u95F4\u5DF2\u53D8\u5316");
35314
35438
  if (bytes.length > 4 * 1024 * 1024 || bytes.includes(0)) throw new AuthorDocumentError("read-only", "\u56FE\u8C31\u6765\u6E90\u5927\u5C0F\u6216\u6587\u672C\u683C\u5F0F\u4E0D\u53D7\u652F\u6301");
35315
35439
  try {
@@ -35318,26 +35442,26 @@ function readGraphFile(base, relative12) {
35318
35442
  throw new AuthorDocumentError("read-only", "\u56FE\u8C31\u6765\u6E90\u5FC5\u987B\u4F7F\u7528UTF-8");
35319
35443
  }
35320
35444
  } finally {
35321
- fs59.closeSync(descriptor);
35445
+ fs60.closeSync(descriptor);
35322
35446
  }
35323
35447
  }
35324
35448
  async function readGraphFileAsync(base, relative12, signal) {
35325
35449
  signal?.throwIfAborted();
35326
35450
  validateAuthorRelativePath(relative12);
35327
- const file = path70.join(base, relative12);
35451
+ const file = path71.join(base, relative12);
35328
35452
  const checkPhysical = async () => {
35329
- if (stripDevicePrefix(await fs59.promises.realpath(file)) !== file) throw new AuthorDocumentError("invalid-path", "\u56FE\u8C31\u6765\u6E90\u8DEF\u5F84\u5305\u542B\u94FE\u63A5\u6216\u522B\u540D");
35453
+ if (stripDevicePrefix(await fs60.promises.realpath(file)) !== file) throw new AuthorDocumentError("invalid-path", "\u56FE\u8C31\u6765\u6E90\u8DEF\u5F84\u5305\u542B\u94FE\u63A5\u6216\u522B\u540D");
35330
35454
  };
35331
35455
  await checkPhysical();
35332
- const initial = await fs59.promises.lstat(file);
35456
+ const initial = await fs60.promises.lstat(file);
35333
35457
  if (!initial.isFile() || initial.isSymbolicLink() || initial.nlink !== 1 || initial.size > 4 * 1024 * 1024) throw new AuthorDocumentError("read-only", "\u56FE\u8C31\u6765\u6E90\u4E0D\u662F\u5B89\u5168\u7684\u666E\u901A\u6587\u672C\u6587\u4EF6");
35334
- const handle = await fs59.promises.open(file, fs59.constants.O_RDONLY | (fs59.constants.O_NOFOLLOW ?? 0));
35458
+ const handle = await fs60.promises.open(file, fs60.constants.O_RDONLY | (fs60.constants.O_NOFOLLOW ?? 0));
35335
35459
  try {
35336
35460
  const opened = await handle.stat();
35337
35461
  if (opened.dev !== initial.dev || opened.ino !== initial.ino || opened.nlink !== 1) throw new AuthorDocumentError("conflict", "\u56FE\u8C31\u6765\u6E90\u5728\u6253\u5F00\u65F6\u88AB\u66FF\u6362");
35338
35462
  const bytes = await handle.readFile({ signal });
35339
35463
  await checkPhysical();
35340
- const current = await fs59.promises.lstat(file), finished = await handle.stat();
35464
+ const current = await fs60.promises.lstat(file), finished = await handle.stat();
35341
35465
  if (!current.isFile() || current.nlink !== 1 || current.dev !== opened.dev || current.ino !== opened.ino || finished.size !== opened.size || finished.mtimeMs !== opened.mtimeMs || finished.ctimeMs !== opened.ctimeMs) throw new AuthorDocumentError("conflict", "\u56FE\u8C31\u6765\u6E90\u5728\u8BFB\u53D6\u671F\u95F4\u5DF2\u53D8\u5316");
35342
35466
  if (bytes.length > 4 * 1024 * 1024 || bytes.includes(0)) throw new AuthorDocumentError("read-only", "\u56FE\u8C31\u6765\u6E90\u5927\u5C0F\u6216\u6587\u672C\u683C\u5F0F\u4E0D\u53D7\u652F\u6301");
35343
35467
  try {
@@ -35357,12 +35481,12 @@ async function scanGraphFiles(root, space, signal) {
35357
35481
  if (depth > 12) return;
35358
35482
  try {
35359
35483
  const directory = authorDocumentPath(root, relative12, true);
35360
- const entries = await fs59.promises.readdir(directory, { withFileTypes: true });
35484
+ const entries = await fs60.promises.readdir(directory, { withFileTypes: true });
35361
35485
  const rows = entries.filter((item) => !item.name.startsWith(".") && item.name !== "node_modules").map((item) => ({
35362
35486
  name: item.name,
35363
35487
  directory: item.isDirectory(),
35364
35488
  draft: false,
35365
- ref: { space, path: path70.posix.join(relative12, item.name) },
35489
+ ref: { space, path: path71.posix.join(relative12, item.name) },
35366
35490
  ...item.isSymbolicLink() || !item.isFile() && !item.isDirectory() ? { error: "\u8BE5\u6761\u76EE\u4E0D\u662F\u5B89\u5168\u7684\u666E\u901A\u6587\u4EF6\u6216\u76EE\u5F55" } : {}
35367
35491
  }));
35368
35492
  directories.set(relative12, rows);
@@ -35587,8 +35711,8 @@ function overlayExtractions(graph, extractions) {
35587
35711
  }
35588
35712
 
35589
35713
  // src/indexing/graph-storage.ts
35590
- import * as fs60 from "node:fs";
35591
- import * as path71 from "node:path";
35714
+ import * as fs61 from "node:fs";
35715
+ import * as path72 from "node:path";
35592
35716
  import { createRequire as createRequire2 } from "node:module";
35593
35717
  import { createHash as createHash21, randomUUID as randomUUID8 } from "node:crypto";
35594
35718
  var APPLICATION_ID2 = 1465272113;
@@ -35610,24 +35734,24 @@ function initialGraphState(bookId2) {
35610
35734
  }
35611
35735
  function graphFile(root, name3) {
35612
35736
  if (!/^(?:story-graph\.sqlite(?:-(?:journal|wal|shm))?|story-graph-state\.json|story-graph\.worker\.lock)$/.test(name3)) throw new Error("\u56FE\u8C31\u8FD0\u884C\u6587\u4EF6\u540D\u65E0\u6548");
35613
- const runtime = path71.join(root, ".webnovel");
35614
- for (const [target, directory] of [[runtime, true], [path71.join(runtime, name3), false]]) {
35737
+ const runtime = path72.join(root, ".webnovel");
35738
+ for (const [target, directory] of [[runtime, true], [path72.join(runtime, name3), false]]) {
35615
35739
  try {
35616
- const stat = fs60.lstatSync(target);
35740
+ const stat = fs61.lstatSync(target);
35617
35741
  if (stat.isSymbolicLink() || (directory ? !stat.isDirectory() : !stat.isFile() || stat.nlink !== 1)) throw new Error("\u56FE\u8C31\u7F13\u5B58\u4F4D\u7F6E\u88AB\u94FE\u63A5\u6216\u5176\u4ED6\u6587\u4EF6\u5360\u7528\uFF0C\u5DF2\u4FDD\u7559\u73B0\u573A");
35618
35742
  } catch (error) {
35619
35743
  if (error.code !== "ENOENT") throw error;
35620
35744
  }
35621
35745
  }
35622
- return path71.join(runtime, name3);
35746
+ return path72.join(runtime, name3);
35623
35747
  }
35624
35748
  function readGraphState(root, bookId2) {
35625
35749
  const file = graphFile(root, STATE_NAME);
35626
- if (!fs60.existsSync(file)) return initialGraphState(bookId2);
35627
- if (fs60.statSync(file).size > 32768) throw new Error("\u56FE\u8C31\u63A7\u5236\u8BB0\u5F55\u8FC7\u5927\uFF0C\u5DF2\u4FDD\u7559\u73B0\u573A");
35750
+ if (!fs61.existsSync(file)) return initialGraphState(bookId2);
35751
+ if (fs61.statSync(file).size > 32768) throw new Error("\u56FE\u8C31\u63A7\u5236\u8BB0\u5F55\u8FC7\u5927\uFF0C\u5DF2\u4FDD\u7559\u73B0\u573A");
35628
35752
  let value;
35629
35753
  try {
35630
- value = JSON.parse(fs60.readFileSync(file, "utf8"));
35754
+ value = JSON.parse(fs61.readFileSync(file, "utf8"));
35631
35755
  } catch {
35632
35756
  throw new Error("\u56FE\u8C31\u63A7\u5236\u8BB0\u5F55\u65E0\u6CD5\u89E3\u6790\uFF0C\u5DF2\u4FDD\u7559\u73B0\u573A");
35633
35757
  }
@@ -35637,12 +35761,12 @@ function readGraphState(root, bookId2) {
35637
35761
  function writeGraphState(root, state) {
35638
35762
  const file = graphFile(root, STATE_NAME), temporary = `${file}.${randomUUID8()}.tmp`;
35639
35763
  try {
35640
- fs60.writeFileSync(temporary, JSON.stringify(state) + "\n", { flag: "wx", mode: 384 });
35764
+ fs61.writeFileSync(temporary, JSON.stringify(state) + "\n", { flag: "wx", mode: 384 });
35641
35765
  graphFile(root, STATE_NAME);
35642
- fs60.renameSync(temporary, file);
35766
+ fs61.renameSync(temporary, file);
35643
35767
  } finally {
35644
35768
  try {
35645
- fs60.unlinkSync(temporary);
35769
+ fs61.unlinkSync(temporary);
35646
35770
  } catch {
35647
35771
  }
35648
35772
  }
@@ -35657,10 +35781,10 @@ function changeGraphState(root, bookId2, update) {
35657
35781
  function acquireGraphLease(root) {
35658
35782
  return withBookLockAsync(root, async () => {
35659
35783
  const file = graphFile(root, "story-graph.worker.lock"), token = randomUUID8();
35660
- if (fs60.existsSync(file)) {
35784
+ if (fs61.existsSync(file)) {
35661
35785
  let pid;
35662
35786
  try {
35663
- pid = JSON.parse(fs60.readFileSync(file, "utf8")).pid;
35787
+ pid = JSON.parse(fs61.readFileSync(file, "utf8")).pid;
35664
35788
  } catch {
35665
35789
  throw new Error("\u56FE\u8C31\u4EFB\u52A1\u9501\u65E0\u6CD5\u89E3\u6790\uFF0C\u672A\u6E05\u7406\u539F\u6587\u4EF6");
35666
35790
  }
@@ -35672,12 +35796,12 @@ function acquireGraphLease(root) {
35672
35796
  dead2 = error.code === "ESRCH";
35673
35797
  }
35674
35798
  if (!dead2) throw new Error("\u53E6\u4E00\u56FE\u8C31\u4EFB\u52A1\u6B63\u5728\u8FD0\u884C");
35675
- fs60.unlinkSync(graphFile(root, "story-graph.worker.lock"));
35799
+ fs61.unlinkSync(graphFile(root, "story-graph.worker.lock"));
35676
35800
  }
35677
- fs60.writeFileSync(file, JSON.stringify({ pid: process.pid, token }), { flag: "wx", mode: 384 });
35801
+ fs61.writeFileSync(file, JSON.stringify({ pid: process.pid, token }), { flag: "wx", mode: 384 });
35678
35802
  return () => {
35679
35803
  try {
35680
- if (JSON.parse(fs60.readFileSync(graphFile(root, "story-graph.worker.lock"), "utf8")).token === token) fs60.unlinkSync(file);
35804
+ if (JSON.parse(fs61.readFileSync(graphFile(root, "story-graph.worker.lock"), "utf8")).token === token) fs61.unlinkSync(file);
35681
35805
  } catch {
35682
35806
  }
35683
35807
  };
@@ -35685,20 +35809,20 @@ function acquireGraphLease(root) {
35685
35809
  }
35686
35810
  function graphCacheSignature(root) {
35687
35811
  const file = graphFile(root, CACHE_NAME);
35688
- return fs60.existsSync(file) ? createHash21("sha256").update(fs60.readFileSync(file)).digest("hex") : "missing";
35812
+ return fs61.existsSync(file) ? createHash21("sha256").update(fs61.readFileSync(file)).digest("hex") : "missing";
35689
35813
  }
35690
35814
  function cacheHeader(file) {
35691
- const header2 = Buffer.alloc(100), handle = fs60.openSync(file, "r");
35815
+ const header2 = Buffer.alloc(100), handle = fs61.openSync(file, "r");
35692
35816
  try {
35693
- fs60.readSync(handle, header2, 0, 100, 0);
35817
+ fs61.readSync(handle, header2, 0, 100, 0);
35694
35818
  } finally {
35695
- fs60.closeSync(handle);
35819
+ fs61.closeSync(handle);
35696
35820
  }
35697
35821
  return header2;
35698
35822
  }
35699
35823
  function replaceGraphCache(root, bookId2) {
35700
35824
  const file = graphFile(root, CACHE_NAME);
35701
- if (!fs60.existsSync(file)) return;
35825
+ if (!fs61.existsSync(file)) return;
35702
35826
  const header2 = cacheHeader(file);
35703
35827
  if (header2.subarray(0, 16).toString() !== "SQLite format 3\0" || header2.readUInt32BE(68) !== APPLICATION_ID2) throw new Error("\u8BE5\u4F4D\u7F6E\u4E0D\u662F\u53EF\u786E\u8BA4\u7684\u56FE\u8C31\u7F13\u5B58\uFF0C\u672A\u79FB\u52A8\u539F\u6587\u4EF6");
35704
35828
  let db;
@@ -35718,12 +35842,12 @@ function replaceGraphCache(root, bookId2) {
35718
35842
  try {
35719
35843
  for (const ending of ["", "-journal", "-wal", "-shm"]) {
35720
35844
  const source2 = graphFile(root, CACHE_NAME + ending), target = source2 + suffix;
35721
- if (!fs60.existsSync(source2)) continue;
35722
- fs60.renameSync(source2, target);
35845
+ if (!fs61.existsSync(source2)) continue;
35846
+ fs61.renameSync(source2, target);
35723
35847
  moved.push([source2, target]);
35724
35848
  }
35725
35849
  } catch (error) {
35726
- for (const [source2, target] of moved.reverse()) if (!fs60.existsSync(source2)) fs60.renameSync(target, source2);
35850
+ for (const [source2, target] of moved.reverse()) if (!fs61.existsSync(source2)) fs61.renameSync(target, source2);
35727
35851
  throw error;
35728
35852
  }
35729
35853
  }
@@ -35744,7 +35868,7 @@ function readGraphCache(root, bookId2) {
35744
35868
  let db;
35745
35869
  try {
35746
35870
  const file = graphFile(root, CACHE_NAME);
35747
- if (!fs60.existsSync(file)) return { status: "missing", extractions: [] };
35871
+ if (!fs61.existsSync(file)) return { status: "missing", extractions: [] };
35748
35872
  const header2 = cacheHeader(file);
35749
35873
  if (header2.subarray(0, 16).toString() !== "SQLite format 3\0" || header2.readUInt32BE(68) !== APPLICATION_ID2) throw new Error("\u8BE5\u4F4D\u7F6E\u4E0D\u662F\u53EF\u786E\u8BA4\u7684\u56FE\u8C31\u7F13\u5B58\uFF0C\u672A\u6253\u5F00\u539F\u6587\u4EF6");
35750
35874
  if (header2[18] !== 1 || header2[19] !== 1) throw new Error("\u56FE\u8C31\u7F13\u5B58\u4F7F\u7528\u4E86\u5176\u4ED6\u65E5\u5FD7\u6A21\u5F0F\uFF0C\u8BF7\u663E\u5F0F\u91CD\u5EFA\uFF1B\u8BFB\u53D6\u672A\u521B\u5EFA\u8F85\u52A9\u6587\u4EF6");
@@ -35766,7 +35890,7 @@ function readGraphCache(root, bookId2) {
35766
35890
  }
35767
35891
  }
35768
35892
  function saveGraphCache(root, graph, extraction) {
35769
- const filename = graphFile(root, CACHE_NAME), exists3 = fs60.existsSync(filename);
35893
+ const filename = graphFile(root, CACHE_NAME), exists3 = fs61.existsSync(filename);
35770
35894
  if (exists3) {
35771
35895
  const header2 = cacheHeader(filename);
35772
35896
  if (header2.subarray(0, 16).toString() !== "SQLite format 3\0" || header2.readUInt32BE(68) !== APPLICATION_ID2 || header2[18] !== 1 || header2[19] !== 1) throw new Error("\u56FE\u8C31\u7F13\u5B58\u4E0D\u53EF\u5199\uFF0C\u539F\u6587\u4EF6\u5DF2\u4FDD\u7559");
@@ -35815,9 +35939,9 @@ function routeForDocument(ref2) {
35815
35939
  return "\u6821\u51C6\u4F5C\u54C1\u73B0\u72B6\uFF0C\u518D\u6309\u4FEE\u6539\u5185\u5BB9\u9009\u62E9\u5BF9\u5E94\u8282\u70B9";
35816
35940
  }
35817
35941
  function textOf(target) {
35818
- if (!fs61.existsSync(target) || !fs61.statSync(target).isFile()) throw new AuthorDocumentError("not-found", "\u6587\u4EF6\u4E0D\u5B58\u5728");
35819
- if (fs61.statSync(target).size > MAX_DOCUMENT_BYTES2) throw new AuthorDocumentError("read-only", "\u6587\u4EF6\u8D85\u8FC7 4 MiB\uFF0C\u4E0D\u80FD\u5728\u7F16\u8F91\u5668\u4E2D\u6253\u5F00\uFF1B\u5185\u5BB9\u672A\u622A\u65AD");
35820
- const bytes = fs61.readFileSync(target);
35942
+ if (!fs62.existsSync(target) || !fs62.statSync(target).isFile()) throw new AuthorDocumentError("not-found", "\u6587\u4EF6\u4E0D\u5B58\u5728");
35943
+ if (fs62.statSync(target).size > MAX_DOCUMENT_BYTES2) throw new AuthorDocumentError("read-only", "\u6587\u4EF6\u8D85\u8FC7 4 MiB\uFF0C\u4E0D\u80FD\u5728\u7F16\u8F91\u5668\u4E2D\u6253\u5F00\uFF1B\u5185\u5BB9\u672A\u622A\u65AD");
35944
+ const bytes = fs62.readFileSync(target);
35821
35945
  if (bytes.includes(0)) throw new AuthorDocumentError("read-only", "\u8BE5\u6587\u4EF6\u4E0D\u662F\u6587\u672C\u6587\u4EF6");
35822
35946
  try {
35823
35947
  return new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(bytes);
@@ -35833,24 +35957,54 @@ function fieldLabel(text5) {
35833
35957
  const version = typeof fields["\u7248\u672C"] === "number" || typeof fields["\u7248\u672C"] === "string" ? fields["\u7248\u672C"] : null;
35834
35958
  return { badge, version };
35835
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
+ }
35836
35990
  var StudyService = class {
35837
35991
  workspace;
35838
35992
  constructor(workspace) {
35839
35993
  if (!isFullyQualifiedPath(workspace)) throw new AuthorDocumentError("invalid-path", "\u5DE5\u4F5C\u8303\u56F4\u5FC5\u987B\u662F\u7EDD\u5BF9\u8DEF\u5F84");
35840
35994
  this.workspace = canonicalizePath(workspace);
35841
- if (!fs61.existsSync(this.workspace) || !fs61.statSync(this.workspace).isDirectory()) throw new AuthorDocumentError("not-found", "\u5DE5\u4F5C\u8303\u56F4\u76EE\u5F55\u4E0D\u5B58\u5728");
35995
+ if (!fs62.existsSync(this.workspace) || !fs62.statSync(this.workspace).isDirectory()) throw new AuthorDocumentError("not-found", "\u5DE5\u4F5C\u8303\u56F4\u76EE\u5F55\u4E0D\u5B58\u5728");
35842
35996
  }
35843
35997
  source(space) {
35844
35998
  if (space === "shared") {
35845
35999
  const root2 = authorDocumentPath(this.workspace, "\u4E66\u623F");
35846
- if (!fs61.existsSync(root2)) throw new AuthorDocumentError("not-found", "\u5F53\u524D\u5DE5\u4F5C\u8303\u56F4\u5C1A\u65E0\u5171\u4EAB\u8D44\u6599");
35847
- if (fs61.existsSync(path72.join(root2, paths.\u5951\u7EA6()))) throw new AuthorDocumentError("read-only", "\u5171\u4EAB\u76EE\u5F55\u4E0E\u4E66\u4ED3\u91CD\u53E0\uFF0C\u8BF7\u901A\u8FC7\u4E66\u76EE\u5165\u53E3\u8BBF\u95EE\uFF1B\u5171\u4EAB\u5199\u5165\u5DF2\u5173\u95ED");
36000
+ if (!fs62.existsSync(root2)) throw new AuthorDocumentError("not-found", "\u5F53\u524D\u5DE5\u4F5C\u8303\u56F4\u5C1A\u65E0\u5171\u4EAB\u8D44\u6599");
36001
+ if (fs62.existsSync(path73.join(root2, paths.\u5951\u7EA6()))) throw new AuthorDocumentError("read-only", "\u5171\u4EAB\u76EE\u5F55\u4E0E\u4E66\u4ED3\u91CD\u53E0\uFF0C\u8BF7\u901A\u8FC7\u4E66\u76EE\u5165\u53E3\u8BBF\u95EE\uFF1B\u5171\u4EAB\u5199\u5165\u5DF2\u5173\u95ED");
35848
36002
  return { root: root2, owner: "\u5171\u4EAB\u8D44\u6599" };
35849
36003
  }
35850
36004
  const books = scanWorkspaceBooks(this.workspace).filter((book2) => book2.bookId && "book:" + book2.bookId === space);
35851
36005
  if (books.length !== 1) throw new AuthorDocumentError("not-found", "\u4E66\u76EE\u4E0D\u5B58\u5728\u6216\u4E66id\u4E0D\u552F\u4E00");
35852
36006
  const book = books[0];
35853
- const root = authorDocumentPath(this.workspace, path72.relative(this.workspace, book.root));
36007
+ const root = authorDocumentPath(this.workspace, path73.relative(this.workspace, book.root));
35854
36008
  return { root, owner: book.name, bookId: book.bookId };
35855
36009
  }
35856
36010
  shelf() {
@@ -35865,11 +36019,28 @@ var StudyService = class {
35865
36019
  let shared = false;
35866
36020
  let sharedError;
35867
36021
  try {
35868
- shared = fs61.statSync(this.source("shared").root).isDirectory();
36022
+ shared = fs62.statSync(this.source("shared").root).isDirectory();
35869
36023
  } catch (error) {
35870
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";
35871
36025
  }
35872
- 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 };
36028
+ }
36029
+ /** 建书向导(8.4.4):读待建书草稿——书房面板点选的答案,novel_create_book 找不到参数时作后备。 */
36030
+ readOnboarding() {
36031
+ return readOnboardingDraft(this.workspace);
36032
+ }
36033
+ /** 建书向导:保存作者点选的答案。三项必须齐全,缺项直接报可读错误,不存半成品。 */
36034
+ saveOnboarding(answers) {
36035
+ const validated = validateOnboardingAnswers(answers);
36036
+ const missing = onboardingMissing(validated);
36037
+ if (missing.length > 0) throw new AuthorDocumentError("invalid-document", `\u65B0\u5EFA\u4E66\u8FD8\u5DEE${missing.join("\u3001")}\u6CA1\u9009\uFF0C\u9009\u5B8C\u518D\u4FDD\u5B58`);
36038
+ saveOnboardingDraft(this.workspace, validated);
36039
+ return validated;
36040
+ }
36041
+ /** 建书向导:清除待建书草稿。 */
36042
+ clearOnboarding() {
36043
+ consumeOnboardingDraft(this.workspace);
35873
36044
  }
35874
36045
  indexBook(space) {
35875
36046
  if (space === "shared") throw new AuthorDocumentError("invalid-path", "\u7D22\u5F15\u53EA\u9002\u7528\u4E8E\u6307\u5B9A\u4E66\u4ED3");
@@ -35889,12 +36060,12 @@ var StudyService = class {
35889
36060
  // once for tree badges and a second time for the evidence itself.
35890
36061
  list: (relative12) => {
35891
36062
  const directory = authorDocumentPath(source2.root, relative12, true);
35892
- if (!fs61.existsSync(directory)) throw new AuthorDocumentError("not-found", "\u76EE\u5F55\u4E0D\u5B58\u5728");
35893
- return fs61.readdirSync(directory, { withFileTypes: true }).filter((entry) => !entry.name.startsWith(".") && entry.name !== "node_modules").map((entry) => ({
36063
+ if (!fs62.existsSync(directory)) throw new AuthorDocumentError("not-found", "\u76EE\u5F55\u4E0D\u5B58\u5728");
36064
+ return fs62.readdirSync(directory, { withFileTypes: true }).filter((entry) => !entry.name.startsWith(".") && entry.name !== "node_modules").map((entry) => ({
35894
36065
  name: entry.name,
35895
36066
  directory: entry.isDirectory(),
35896
36067
  draft: false,
35897
- ref: { space, path: path72.posix.join(relative12, entry.name) },
36068
+ ref: { space, path: path73.posix.join(relative12, entry.name) },
35898
36069
  ...entry.isSymbolicLink() || !entry.isDirectory() && !entry.isFile() ? { error: "\u8BE5\u6761\u76EE\u4E0D\u662F\u5B89\u5168\u7684\u666E\u901A\u6587\u4EF6\u6216\u76EE\u5F55" } : {}
35899
36070
  }));
35900
36071
  },
@@ -35964,13 +36135,13 @@ var StudyService = class {
35964
36135
  }
35965
36136
  treeAt(source2, ref2) {
35966
36137
  const directory = authorDocumentPath(source2.root, ref2.path, true);
35967
- if (!fs61.existsSync(directory) || !fs61.statSync(directory).isDirectory()) throw new AuthorDocumentError("not-found", "\u76EE\u5F55\u4E0D\u5B58\u5728");
35968
- return fs61.readdirSync(directory, { withFileTypes: true }).filter((entry) => !entry.name.startsWith(".") && entry.name !== "node_modules").map((entry) => {
35969
- const relative12 = path72.posix.join(ref2.path, entry.name);
36138
+ if (!fs62.existsSync(directory) || !fs62.statSync(directory).isDirectory()) throw new AuthorDocumentError("not-found", "\u76EE\u5F55\u4E0D\u5B58\u5728");
36139
+ return fs62.readdirSync(directory, { withFileTypes: true }).filter((entry) => !entry.name.startsWith(".") && entry.name !== "node_modules").map((entry) => {
36140
+ const relative12 = path73.posix.join(ref2.path, entry.name);
35970
36141
  const item = { ref: { space: ref2.space, path: relative12 }, name: entry.name, directory: entry.isDirectory(), draft: ref2.space !== "shared" && relative12.startsWith("\u8349\u7A3F\u533A") };
35971
36142
  try {
35972
36143
  const target = authorDocumentPath(source2.root, relative12);
35973
- const info = fs61.statSync(target);
36144
+ const info = fs62.statSync(target);
35974
36145
  if (!info.isDirectory() && !info.isFile()) return { ...item, error: "\u4E0D\u652F\u6301\u7684\u6587\u4EF6\u7C7B\u578B" };
35975
36146
  const badge = info.isFile() && entry.name.endsWith(".md") && info.size <= MAX_DOCUMENT_BYTES2 ? fieldLabel(textOf(target)).badge : void 0;
35976
36147
  return { ...item, absolutePath: target, directory: info.isDirectory(), ...badge ? { badge } : {} };
@@ -35988,7 +36159,7 @@ var StudyService = class {
35988
36159
  read(ref2) {
35989
36160
  const source2 = this.source(ref2.space);
35990
36161
  const absolutePath = authorDocumentPath(source2.root, ref2.path);
35991
- ref2 = { ...ref2, path: path72.relative(canonicalizePath(source2.root), absolutePath).split(path72.sep).join("/") };
36162
+ ref2 = { ...ref2, path: path73.relative(canonicalizePath(source2.root), absolutePath).split(path73.sep).join("/") };
35992
36163
  const text5 = textOf(absolutePath);
35993
36164
  const parsed = parseDocument(text5);
35994
36165
  const metadata2 = fieldLabel(text5);
@@ -35996,7 +36167,7 @@ var StudyService = class {
35996
36167
  return {
35997
36168
  ref: ref2,
35998
36169
  owner: source2.owner,
35999
- name: path72.basename(ref2.path),
36170
+ name: path73.basename(ref2.path),
36000
36171
  absolutePath,
36001
36172
  body: parsed.ok ? parsed.data.body : text5,
36002
36173
  hash: documentHash(text5),
@@ -36015,14 +36186,14 @@ var StudyService = class {
36015
36186
  return null;
36016
36187
  }
36017
36188
  }
36018
- absolutePath = path72.resolve(this.workspace, absolutePath);
36189
+ absolutePath = path73.resolve(this.workspace, absolutePath);
36019
36190
  }
36020
36191
  const spaces = this.shelf().books.filter((book) => !book.error).map((book) => book.id);
36021
36192
  spaces.push("shared");
36022
36193
  for (const space of spaces) {
36023
36194
  try {
36024
36195
  const source2 = this.source(space);
36025
- const relative12 = path72.relative(source2.root, absolutePath).split(path72.sep).join("/");
36196
+ const relative12 = path73.relative(source2.root, absolutePath).split(path73.sep).join("/");
36026
36197
  return this.read({ space, path: relative12 });
36027
36198
  } catch {
36028
36199
  }
@@ -36035,7 +36206,7 @@ var StudyService = class {
36035
36206
  const scanned = scanWorkspaceBooks(this.workspace);
36036
36207
  const spaces = scanned.filter((book) => book.bookId && scanned.filter((other) => other.bookId === book.bookId).length === 1).map((book) => "book:" + book.bookId);
36037
36208
  try {
36038
- if (fs61.statSync(this.source("shared").root).isDirectory()) spaces.push("shared");
36209
+ if (fs62.statSync(this.source("shared").root).isDirectory()) spaces.push("shared");
36039
36210
  } catch {
36040
36211
  }
36041
36212
  const term = query.trim().toLocaleLowerCase();
@@ -36102,7 +36273,7 @@ var StudyService = class {
36102
36273
  const status = deriveChapterFacts(facts);
36103
36274
  const pending = findPendingReviewDraft(source2.root, key);
36104
36275
  const candidates = [paths.\u5B9A\u7A3F\u7AE0(key.\u5377, key.\u7AE0, key.\u7AE0\u540D), ...pending ? [pending.relPath] : [], paths.\u786E\u8BA4\u7EC6\u7EB2(key.\u5377, key.\u7AE0, key.\u7AE0\u540D), paths.\u5019\u9009\u7EC6\u7EB2(key.\u5377, key.\u7AE0\u540D)];
36105
- const relative12 = candidates.find((candidate) => fs61.existsSync(path72.join(source2.root, candidate)));
36276
+ const relative12 = candidates.find((candidate) => fs62.existsSync(path73.join(source2.root, candidate)));
36106
36277
  return { volume: key.\u5377, chapter: key.\u7AE0, title: key.\u7AE0\u540D, status: status.\u5EFA\u8BAE.\u73AF\u8282, finalized: facts.\u5DF2\u5B9A\u7A3F, ...relative12 ? { source: { space, path: relative12 } } : {} };
36107
36278
  })
36108
36279
  };
@@ -36630,8 +36801,36 @@ function childEnd(reason) {
36630
36801
  }
36631
36802
 
36632
36803
  // src/study/web.ts
36804
+ function agentRoots(registry2) {
36805
+ if (!registry2) return [];
36806
+ const value = registry2.roots;
36807
+ if (typeof value === "function") {
36808
+ try {
36809
+ const result = value();
36810
+ if (Array.isArray(result)) return result;
36811
+ } catch {
36812
+ }
36813
+ } else if (Array.isArray(value)) {
36814
+ return value;
36815
+ }
36816
+ return [];
36817
+ }
36818
+ function agentList(registry2) {
36819
+ if (!registry2) return [];
36820
+ const value = registry2.list;
36821
+ if (typeof value === "function") {
36822
+ try {
36823
+ const result = value();
36824
+ if (Array.isArray(result)) return result;
36825
+ } catch {
36826
+ }
36827
+ } else if (Array.isArray(value)) {
36828
+ return value;
36829
+ }
36830
+ return [];
36831
+ }
36633
36832
  var STUDY_API_PATH = "/api/webnovel/study/";
36634
- 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"];
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"];
36635
36834
  function graphReaderRequest(input) {
36636
36835
  const result = {};
36637
36836
  for (const key of ["person", "query", "cluster", "relation", "groupField", "evidenceId"]) if (input[key] !== void 0) {
@@ -36805,7 +37004,9 @@ function createStudyHandler(runtime, indexing, workflow = new WorkflowObserver()
36805
37004
  request.signal.throwIfAborted();
36806
37005
  const sessionId = stringOf(input, "sessionId");
36807
37006
  const agent = runtime.agents.get(sessionId);
36808
- if (!agent || !runtime.agents.roots().includes(agent)) throw new AuthorDocumentError("read-only", "\u8BF7\u5728\u5F53\u524D\u4E3B\u4F1A\u8BDD\u4E2D\u6253\u5F00\u4E66\u623F");
37007
+ const roots = agentRoots(runtime.agents);
37008
+ const isRoot = agent !== void 0 && (roots.length > 0 ? roots.includes(agent) : agent.session?.header?.origin !== "subagent");
37009
+ if (!agent || !isRoot) throw new AuthorDocumentError("read-only", "\u8BF7\u5728\u5F53\u524D\u4E3B\u4F1A\u8BDD\u4E2D\u6253\u5F00\u4E66\u623F");
36809
37010
  const cwd = agent.session.header.cwd;
36810
37011
  if (!cwd || !isFullyQualifiedPath(cwd)) throw new AuthorDocumentError("invalid-path", "\u5F53\u524D\u4F1A\u8BDD\u6CA1\u6709\u6709\u6548\u5DE5\u4F5C\u8303\u56F4");
36811
37012
  const service = new StudyService(cwd);
@@ -36936,6 +37137,29 @@ function createStudyHandler(runtime, indexing, workflow = new WorkflowObserver()
36936
37137
  case "retry-commit":
36937
37138
  value = service.retryCommit(refOf(input), stringOf(input, "hash"), stringOf(input, "operationId"), sessionId);
36938
37139
  break;
37140
+ case "onboarding": {
37141
+ const action = typeof input["action"] === "string" ? input["action"] : "read";
37142
+ if (action === "save") value = { saved: service.saveOnboarding(input["answers"]) };
37143
+ else if (action === "clear") {
37144
+ service.clearOnboarding();
37145
+ value = { cleared: true };
37146
+ } else if (action === "read") value = { answers: service.readOnboarding() };
37147
+ else throw new AuthorDocumentError("invalid-document", "\u672A\u77E5\u7684\u5411\u5BFC\u64CD\u4F5C");
37148
+ break;
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
+ }
36939
37163
  default:
36940
37164
  return reply(404, { ok: false, code: "not-found", error: "\u672A\u77E5\u4E66\u623F\u64CD\u4F5C" });
36941
37165
  }
@@ -36984,7 +37208,7 @@ function attachStudyWeb(ctx, indexing, editorRequests = new EditorRequestHub())
36984
37208
  observation[Symbol.dispose]();
36985
37209
  }
36986
37210
  };
36987
- const handler = createStudyHandler(scope2, indexing, workflow, editorRequests, (agent) => isWritingAgent(agent), readChild);
37211
+ const handler = createStudyHandler(scope2, indexing, workflow, editorRequests, () => true, readChild);
36988
37212
  for (const method of METHODS) {
36989
37213
  scope2.connection.fetch.register({ path: STUDY_API_PATH + method, methods: ["POST"], requestBody: "streaming", fetch: handler });
36990
37214
  }
@@ -36998,7 +37222,7 @@ function brandString(value) {
36998
37222
 
36999
37223
  // src/native-write.ts
37000
37224
  import { randomUUID as randomUUID9 } from "node:crypto";
37001
- import * as path73 from "node:path";
37225
+ import * as path74 from "node:path";
37002
37226
  import { ToolExecutionPipeline } from "@deepseek-ai/dsh-tools/pipeline";
37003
37227
  function nativeToolRuntime(ctx) {
37004
37228
  const pipeline = new ToolExecutionPipeline(ctx);
@@ -37029,7 +37253,7 @@ function createNativeWriteBridge(runtime) {
37029
37253
  exec.signal.throwIfAborted();
37030
37254
  const target = resolveInsideBook(root, op.relPath);
37031
37255
  if (!target.ok) throw new Error("\u539F\u751F\u5199\u5165\u76EE\u6807\u4E0D\u5728\u4E66\u4ED3\u5185");
37032
- const file = path73.resolve(root, target.relPath);
37256
+ const file = path74.resolve(root, target.relPath);
37033
37257
  const callId = brandString(`webnovel-write-${randomUUID9()}`);
37034
37258
  pending.set(callId, { parent: exec.token, agent: exec.agent, file, content: op.content });
37035
37259
  try {
@@ -37053,10 +37277,10 @@ function createNativeWriteBridge(runtime) {
37053
37277
  }
37054
37278
 
37055
37279
  // src/indexing/manager.ts
37056
- import * as fs62 from "node:fs";
37280
+ import * as fs63 from "node:fs";
37057
37281
 
37058
37282
  // src/indexing/git.ts
37059
- import * as path74 from "node:path";
37283
+ import * as path75 from "node:path";
37060
37284
  import { execFile } from "node:child_process";
37061
37285
  async function git(root, args) {
37062
37286
  return new Promise((resolve22) => execFile("git", ["--literal-pathspecs", "-C", root, ...args], {
@@ -37082,8 +37306,8 @@ async function bookGitWatchPaths(root) {
37082
37306
  git(root, ["rev-parse", "--path-format=absolute", "--git-common-dir"])
37083
37307
  ]);
37084
37308
  return [...new Set(directories.filter((value) => !!value?.trim()).flatMap((value) => {
37085
- const directory = path74.resolve(root, value.trim());
37086
- return [directory, path74.join(directory, "refs")];
37309
+ const directory = path75.resolve(root, value.trim());
37310
+ return [directory, path75.join(directory, "refs")];
37087
37311
  }))];
37088
37312
  }
37089
37313
 
@@ -37490,7 +37714,7 @@ var BookIndexManager = class {
37490
37714
  for (const directory of await bookGitWatchPaths(record4.book.root)) {
37491
37715
  if (this.closing) return;
37492
37716
  try {
37493
- const watcher = fs62.watch(directory, { recursive: directory.endsWith("refs"), persistent: false }, (_event, filename) => {
37717
+ const watcher = fs63.watch(directory, { recursive: directory.endsWith("refs"), persistent: false }, (_event, filename) => {
37494
37718
  const name3 = filename?.toString().replaceAll("\\", "/");
37495
37719
  if (directory.endsWith("refs") || !name3 || /^(HEAD|packed-refs|refs)(\/|$)/.test(name3)) {
37496
37720
  this.scheduleProbe(record4);
@@ -37864,7 +38088,7 @@ function indexFailureMessage(book, notice) {
37864
38088
  }
37865
38089
 
37866
38090
  // src/reference/host.ts
37867
- import * as path75 from "node:path";
38091
+ import * as path76 from "node:path";
37868
38092
  import { BlockAssembler, createUserMessage as createUserMessage4 } from "@deepseek-ai/dsh-llm";
37869
38093
  var ReferenceHost = class {
37870
38094
  constructor(access) {
@@ -37882,26 +38106,26 @@ var ReferenceHost = class {
37882
38106
  async readFile(agent, workspace, filename, signal) {
37883
38107
  const active = AbortSignal.any([this.shutdown.signal, ...signal ? [signal] : []]);
37884
38108
  active.throwIfAborted();
37885
- const fs66 = this.access.fs(agent);
37886
- if (!fs66) throw new ReferenceError2("fs-unavailable", "DSH \u6587\u4EF6\u670D\u52A1\u4E0D\u53EF\u7528");
37887
- if (!path75.isAbsolute(filename)) throw new ReferenceError2("source-path", "\u8BF7\u9009\u62E9\u539F\u6587\u6587\u4EF6\u7684\u7EDD\u5BF9\u8DEF\u5F84");
37888
- const mapped = fs66.processPathFromHostPath(filename), workspacePath = fs66.processPathFromHostPath(workspace);
38109
+ const fs67 = this.access.fs(agent);
38110
+ if (!fs67) throw new ReferenceError2("fs-unavailable", "DSH \u6587\u4EF6\u670D\u52A1\u4E0D\u53EF\u7528");
38111
+ if (!path76.isAbsolute(filename)) throw new ReferenceError2("source-path", "\u8BF7\u9009\u62E9\u539F\u6587\u6587\u4EF6\u7684\u7EDD\u5BF9\u8DEF\u5F84");
38112
+ const mapped = fs67.processPathFromHostPath(filename), workspacePath = fs67.processPathFromHostPath(workspace);
37889
38113
  if (!mapped || !workspacePath) throw new ReferenceError2("fs-world", "\u8BE5\u6587\u4EF6\u6216\u5DE5\u4F5C\u8303\u56F4\u65E0\u6CD5\u6620\u5C04\u5230\u5F53\u524D\u6267\u884C\u73AF\u5883\uFF1B\u672A\u56DE\u9000\u5230\u5176\u4ED6\u6587\u4EF6\u7CFB\u7EDF\u8BFB\u53D6");
37890
- const info = await fs66.lstat(mapped, void 0, active);
38114
+ const info = await fs67.lstat(mapped, void 0, active);
37891
38115
  if (info?.type !== "file") throw new ReferenceError2("source-type", "\u539F\u6587\u5FC5\u987B\u662F\u660E\u786E\u9009\u5B9A\u7684\u666E\u901A\u6587\u4EF6\uFF0C\u4E0D\u63A5\u53D7\u76EE\u5F55\u6216\u94FE\u63A5");
37892
- let ancestor = path75.dirname(mapped);
37893
- while (path75.dirname(ancestor) !== ancestor) {
37894
- if ((await fs66.lstat(ancestor, void 0, active))?.type !== "directory") throw new ReferenceError2("source-type", "\u539F\u6587\u7684\u7956\u5148\u76EE\u5F55\u5305\u542B\u94FE\u63A5\u6216\u4E0D\u53EF\u8BBF\u95EE\u8DEF\u5F84");
37895
- ancestor = path75.dirname(ancestor);
37896
- }
37897
- const target = await fs66.resolve(mapped, { signal: active });
37898
- const library = await fs66.resolve(path75.join(workspacePath, "\u4E66\u623F/\u53C2\u8003\u4E66"), { signal: active });
37899
- if (fs66.contains(library, target)) throw new ReferenceError2("source-path", "\u539F\u6587\u4EF6\u4E0D\u80FD\u4F4D\u4E8E\u5F85\u6E05\u9664\u7684\u53D7\u7BA1\u53C2\u8003\u5E93\u5185");
37900
- const before = await fs66.stat(target, active);
38116
+ let ancestor = path76.dirname(mapped);
38117
+ while (path76.dirname(ancestor) !== ancestor) {
38118
+ if ((await fs67.lstat(ancestor, void 0, active))?.type !== "directory") throw new ReferenceError2("source-type", "\u539F\u6587\u7684\u7956\u5148\u76EE\u5F55\u5305\u542B\u94FE\u63A5\u6216\u4E0D\u53EF\u8BBF\u95EE\u8DEF\u5F84");
38119
+ ancestor = path76.dirname(ancestor);
38120
+ }
38121
+ const target = await fs67.resolve(mapped, { signal: active });
38122
+ const library = await fs67.resolve(path76.join(workspacePath, "\u4E66\u623F/\u53C2\u8003\u4E66"), { signal: active });
38123
+ if (fs67.contains(library, target)) throw new ReferenceError2("source-path", "\u539F\u6587\u4EF6\u4E0D\u80FD\u4F4D\u4E8E\u5F85\u6E05\u9664\u7684\u53D7\u7BA1\u53C2\u8003\u5E93\u5185");
38124
+ const before = await fs67.stat(target, active);
37901
38125
  if (before?.type !== "file" || before.size !== void 0 && before.size > REFERENCE_LIMITS.sourceBytes) throw new ReferenceError2("source-limit", "\u6E90\u6587\u4EF6\u4E0D\u53EF\u8BFB\u6216\u8D85\u8FC7 64 MiB");
37902
- const bytes = await fs66.readBytes(target, active, REFERENCE_LIMITS.sourceBytes);
37903
- const afterTarget = await fs66.resolve(mapped, { signal: active }), after = await fs66.stat(afterTarget, active);
37904
- const afterPath = await fs66.lstat(mapped, void 0, active);
38126
+ const bytes = await fs67.readBytes(target, active, REFERENCE_LIMITS.sourceBytes);
38127
+ const afterTarget = await fs67.resolve(mapped, { signal: active }), after = await fs67.stat(afterTarget, active);
38128
+ const afterPath = await fs67.lstat(mapped, void 0, active);
37905
38129
  if (afterTarget.targetKey !== target.targetKey || after?.version !== before.version || afterPath?.version !== info.version || afterPath.type !== "file") throw new ReferenceError2("source-changed", "\u6E90\u6587\u4EF6\u5728\u8BFB\u53D6\u671F\u95F4\u53D8\u5316\uFF0C\u8BF7\u91CD\u65B0\u9884\u68C0");
37906
38130
  active.throwIfAborted();
37907
38131
  return bytes;
@@ -38047,8 +38271,8 @@ function createIndexAutoPreference(settings, fallback) {
38047
38271
  }
38048
38272
 
38049
38273
  // src/scripts/deterministic-checks.ts
38050
- import * as fs63 from "node:fs";
38051
- import * as path76 from "node:path";
38274
+ import * as fs64 from "node:fs";
38275
+ import * as path77 from "node:path";
38052
38276
  function parseArgs(argv) {
38053
38277
  const values = /* @__PURE__ */ new Map();
38054
38278
  for (let i = 0; i < argv.length; i += 1) {
@@ -38078,8 +38302,8 @@ function runChecksCli(argv) {
38078
38302
  console.error(`\u524D\u7F6E\u53C2\u6570\u9519\u8BEF\uFF1A${err instanceof Error ? err.message : String(err)}`);
38079
38303
  return 1;
38080
38304
  }
38081
- if (!fs63.existsSync(args.book) || !fs63.statSync(args.book).isDirectory()) {
38082
- console.error(`\u4E66\u4ED3\u4E0D\u5B58\u5728\uFF1A${path76.resolve(args.book)}`);
38305
+ if (!fs64.existsSync(args.book) || !fs64.statSync(args.book).isDirectory()) {
38306
+ console.error(`\u4E66\u4ED3\u4E0D\u5B58\u5728\uFF1A${path77.resolve(args.book)}`);
38083
38307
  return 1;
38084
38308
  }
38085
38309
  try {
@@ -38113,8 +38337,8 @@ function runChecksCli(argv) {
38113
38337
  }
38114
38338
 
38115
38339
  // src/scripts/draft-length-cli.ts
38116
- import * as fs64 from "node:fs";
38117
- import * as path77 from "node:path";
38340
+ import * as fs65 from "node:fs";
38341
+ import * as path78 from "node:path";
38118
38342
  function unverified(reason, exitCode) {
38119
38343
  console.log(JSON.stringify({ \u6838\u9A8C\u6765\u6E90: "\u5F53\u524D\u6587\u4EF6", \u7EDF\u8BA1\u72B6\u6001: "\u672A\u6838\u9A8C", \u539F\u56E0: reason }, null, 2));
38120
38344
  return exitCode;
@@ -38135,14 +38359,14 @@ function draftLengthCli(argv) {
38135
38359
  return unverified("\u987B\u6307\u5B9A\u4E66\u4ED3\u7EDD\u5BF9\u8DEF\u5F84\u53CA\u6B63\u5F0F\u7A3F\u4EF6\u7684\u4ED3\u5185\u76F8\u5BF9\u8DEF\u5F84\uFF0C\u4E0D\u80FD\u4F7F\u7528\u6682\u5B58\u7A3F", 1);
38136
38360
  }
38137
38361
  try {
38138
- if (!fs64.statSync(book).isDirectory()) return unverified("\u4E66\u4ED3\u8DEF\u5F84\u4E0D\u662F\u76EE\u5F55", 1);
38362
+ if (!fs65.statSync(book).isDirectory()) return unverified("\u4E66\u4ED3\u8DEF\u5F84\u4E0D\u662F\u76EE\u5F55", 1);
38139
38363
  const resolved = resolveInsideBook(book, requested);
38140
38364
  if (!resolved.ok) return unverified(resolved.reason, 1);
38141
38365
  const target = draftLengthTarget(resolved.relPath);
38142
38366
  if (target?.\u6587\u672C\u9636\u6BB5 !== "\u8349\u7A3F\u6587\u4EF6") return unverified("\u5B9E\u9645\u76EE\u6807\u4E0D\u662F\u89C4\u8303\u5B8C\u6574\u7A3F", 1);
38143
- const file = path77.join(book, resolved.relPath);
38144
- if (!fs64.statSync(file).isFile()) return unverified("\u7A3F\u4EF6\u76EE\u6807\u4E0D\u662F\u666E\u901A\u6587\u4EF6", 1);
38145
- const text5 = fs64.readFileSync(file, "utf8");
38367
+ const file = path78.join(book, resolved.relPath);
38368
+ if (!fs65.statSync(file).isFile()) return unverified("\u7A3F\u4EF6\u76EE\u6807\u4E0D\u662F\u666E\u901A\u6587\u4EF6", 1);
38369
+ const text5 = fs65.readFileSync(file, "utf8");
38146
38370
  const result = draftLengthFeedback(target, text5, readChapterLength(book));
38147
38371
  console.log(JSON.stringify({ \u6838\u9A8C\u6765\u6E90: "\u5F53\u524D\u6587\u4EF6", ...result }, null, 2));
38148
38372
  return result.\u7EDF\u8BA1\u72B6\u6001 === "\u5DF2\u7EDF\u8BA1" ? 0 : 1;
@@ -38361,8 +38585,8 @@ function exportCli(argv) {
38361
38585
  }
38362
38586
 
38363
38587
  // src/scripts/screenplay-export-cli.ts
38364
- import * as fs65 from "node:fs";
38365
- import * as path78 from "node:path";
38588
+ import * as fs66 from "node:fs";
38589
+ import * as path79 from "node:path";
38366
38590
  function argValue5(argv, name3) {
38367
38591
  const i = argv.indexOf(`--${name3}`);
38368
38592
  return i === -1 ? void 0 : argv[i + 1];
@@ -38423,12 +38647,12 @@ function screenplayExportCli(argv) {
38423
38647
  const \u5206\u955C\u5934raw = argValue5(argv, "\u5206\u955C\u5934")?.trim();
38424
38648
  let \u5206\u955C\u5934\u8868;
38425
38649
  if (\u5206\u955C\u5934raw !== void 0) {
38426
- const shotPath = path78.isAbsolute(\u5206\u955C\u5934raw) ? \u5206\u955C\u5934raw : path78.join(book, \u5206\u955C\u5934raw);
38427
- if (!fs65.existsSync(shotPath) || !fs65.statSync(shotPath).isFile()) {
38650
+ const shotPath = path79.isAbsolute(\u5206\u955C\u5934raw) ? \u5206\u955C\u5934raw : path79.join(book, \u5206\u955C\u5934raw);
38651
+ if (!fs66.existsSync(shotPath) || !fs66.statSync(shotPath).isFile()) {
38428
38652
  console.error(`\u5206\u955C\u5934\u8868\u4E0D\u5B58\u5728\uFF1A${shotPath}`);
38429
38653
  return 1;
38430
38654
  }
38431
- const parsed = parseShotListTable(fs65.readFileSync(shotPath, "utf-8"));
38655
+ const parsed = parseShotListTable(fs66.readFileSync(shotPath, "utf-8"));
38432
38656
  if (!parsed.ok || parsed.shotList === void 0) {
38433
38657
  console.error(`\u5206\u955C\u5934\u8868\u89E3\u6790\u5931\u8D25\uFF1A${parsed.problems.join("\uFF1B")}`);
38434
38658
  return 1;
@@ -38438,13 +38662,13 @@ function screenplayExportCli(argv) {
38438
38662
  const \u603B\u7EB2raw = argValue5(argv, "\u603B\u7EB2")?.trim();
38439
38663
  let \u603B\u7EB2;
38440
38664
  if (\u603B\u7EB2raw !== void 0) {
38441
- const biblePath = path78.isAbsolute(\u603B\u7EB2raw) ? \u603B\u7EB2raw : path78.join(book, \u603B\u7EB2raw);
38442
- if (!fs65.existsSync(biblePath) || !fs65.statSync(biblePath).isFile()) {
38665
+ const biblePath = path79.isAbsolute(\u603B\u7EB2raw) ? \u603B\u7EB2raw : path79.join(book, \u603B\u7EB2raw);
38666
+ if (!fs66.existsSync(biblePath) || !fs66.statSync(biblePath).isFile()) {
38443
38667
  console.error(`\u603B\u7EB2\u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A${biblePath}`);
38444
38668
  return 1;
38445
38669
  }
38446
38670
  try {
38447
- const parsedBible = JSON.parse(fs65.readFileSync(biblePath, "utf-8"));
38671
+ const parsedBible = JSON.parse(fs66.readFileSync(biblePath, "utf-8"));
38448
38672
  if (typeof parsedBible !== "object" || parsedBible === null || Array.isArray(parsedBible)) {
38449
38673
  console.error("\u603B\u7EB2\u89E3\u6790\u5931\u8D25\uFF1A\u603B\u7EB2 JSON \u987B\u4E3A\u5BF9\u8C61\uFF08StoryBibleInput \u4E03\u8282\uFF09");
38450
38674
  return 1;
@@ -38707,6 +38931,16 @@ function apply(ctx, entry) {
38707
38931
  }
38708
38932
  };
38709
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
+ });
38710
38944
  const installedAgents = /* @__PURE__ */ new Map();
38711
38945
  const installedModes = /* @__PURE__ */ new Map();
38712
38946
  const installedRoles = /* @__PURE__ */ new Map();
@@ -38751,7 +38985,7 @@ function apply(ctx, entry) {
38751
38985
  const registry2 = typeof ctx.get === "function" ? ctx.get("workspaceRegistry") : void 0;
38752
38986
  return [
38753
38987
  ...(typeof registry2?.list === "function" ? registry2.list() : []).flatMap((workspace) => workspace.path ? [workspace.path] : []),
38754
- ...[...installedAgents.values()].filter((agent) => isMainAgent(agent) && isWritingAgent(agent)).flatMap((agent) => {
38988
+ ...[...installedAgents.values()].filter((agent) => isMainAgent(agent)).flatMap((agent) => {
38755
38989
  const root = agentWorkspaceRoot(agent);
38756
38990
  return root ? [root] : [];
38757
38991
  })
@@ -38759,8 +38993,10 @@ function apply(ctx, entry) {
38759
38993
  },
38760
38994
  notify: (book, notice) => {
38761
38995
  const registry2 = typeof ctx.get === "function" ? ctx.get("agents") : void 0;
38762
- const agent = registry2?.roots().find((candidate) => (candidate.id === notice.sessionId || candidate.session?.header?.id === notice.sessionId) && registry2.get(candidate.id) === candidate);
38763
- if (!agent || !isMainAgent(agent) || !isWritingAgent(agent) || !agent.session?.header || typeof agent.followup !== "function") return false;
38996
+ const roots = agentRoots(registry2);
38997
+ const candidates = roots.length > 0 ? roots : agentList(registry2);
38998
+ const agent = candidates.find((candidate) => (candidate.id === notice.sessionId || candidate.session?.header?.id === notice.sessionId) && registry2?.get(candidate.id) === candidate);
38999
+ if (!agent || !isMainAgent(agent) || !agent.session?.header || typeof agent.followup !== "function") return false;
38764
39000
  if (bookRootOfBookIdFor(book.bookId, agent) !== book.root) return false;
38765
39001
  return notifySaved(agent, indexFailureMessage(book, notice)).notification === "delivered";
38766
39002
  }
@@ -38836,7 +39072,6 @@ function apply(ctx, entry) {
38836
39072
  };
38837
39073
  }
38838
39074
  function registerToolsInto(agent) {
38839
- if (!isWritingAgent(agent)) return false;
38840
39075
  if (toolKit === void 0) return false;
38841
39076
  if (agentToolOffs.has(agent.id)) return true;
38842
39077
  const registry2 = agentCtxGet(agent, "tools");
@@ -38875,7 +39110,6 @@ function apply(ctx, entry) {
38875
39110
  agentRestrictOffs.clear();
38876
39111
  }
38877
39112
  function restrictNovelToolsInto(agent) {
38878
- if (!isWritingAgent(agent) && writingRoleOf(agent) === void 0) return false;
38879
39113
  if (toolKit === void 0) return false;
38880
39114
  if (agentRestrictOffs.has(agent.id)) return true;
38881
39115
  const tools = agentCtxGet(agent, "tools");
@@ -38962,25 +39196,26 @@ function apply(ctx, entry) {
38962
39196
  const attached = [];
38963
39197
  attachments.set(agentId, attached);
38964
39198
  const rootOf = () => agentWorkspaceRoot(agent);
38965
- if (capability !== void 0 && !isSubagent) {
39199
+ if (!isSubagent) {
38966
39200
  const workspace = rootOf();
38967
39201
  if (workspace) indexing.addWorkspace(workspace);
38968
- try {
38969
- const offPersona = attachPersonaToAgent(agentCtx, void 0, { logger: ctx.logger });
38970
- if (offPersona !== void 0) attached.push(offPersona);
38971
- } catch (err) {
38972
- ctx.logger.warn(`[webnovel-bundle] persona \u6302\u8F7D\u5931\u8D25\uFF08${agentId}\uFF09\uFF1A${err instanceof Error ? err.message : String(err)}`);
38973
- }
38974
- try {
38975
- const offStatus = attachStatusToAgent(agentCtx, { workspaceRoot: rootOf });
38976
- if (offStatus !== void 0) attached.push(offStatus);
38977
- } catch (err) {
38978
- ctx.logger.warn(`[webnovel-bundle] \u72B6\u6001\u6CE8\u5165\u6302\u8F7D\u5931\u8D25\uFF08${agentId}\uFF09\uFF1A${err instanceof Error ? err.message : String(err)}`);
38979
- }
38980
39202
  registerToolsInto(agent);
38981
- const offDelegation = attachWritingDelegationToAgent(agent);
38982
- if (offDelegation !== void 0) attached.push(offDelegation);
38983
- } 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 {
38984
39219
  restrictNovelToolsInto(agent);
38985
39220
  const offWorker = role2 === void 0 ? void 0 : attachWorkerPolicyToAgent(agent, role2);
38986
39221
  if (offWorker !== void 0) attached.push(offWorker);
@@ -39072,6 +39307,7 @@ function apply(ctx, entry) {
39072
39307
  await Promise.all([...installedAgents.values()].map((agent) => detachAgent(agent)));
39073
39308
  await Promise.all(detachJobs);
39074
39309
  disposeAllAgentTools();
39310
+ await disposeAllDelegations();
39075
39311
  await agentsReg.fiber?.dispose?.();
39076
39312
  await presetReg.fiber?.dispose?.();
39077
39313
  };
@@ -39097,6 +39333,7 @@ function apply(ctx, entry) {
39097
39333
  if (!toolsReg.reactive) registerAllInstalled(ctx);
39098
39334
  return () => {
39099
39335
  disposeAllAgentTools();
39336
+ void disposeAllDelegations();
39100
39337
  void toolsReg.fiber?.dispose?.();
39101
39338
  };
39102
39339
  });