@yangda611/dsh-scriptor 8.4.9 → 8.4.11

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.
Files changed (36) hide show
  1. package/README.md +9 -9
  2. package/lib/cli.js +299 -14
  3. package/lib/client.js +53 -53
  4. package/lib/index.js +1459 -473
  5. package/package.json +1 -1
  6. package/presets/writing.patch.yml +3 -3
  7. package/skills/novel-design/SKILL.md +8 -9
  8. package/skills/novel-director/SKILL.md +20 -6
  9. package/skills/novel-drafting/SKILL.md +5 -14
  10. package/skills/novel-inspiration/SKILL.md +4 -2
  11. package/skills/novel-outline/SKILL.md +4 -4
  12. package/skills/novel-polish/SKILL.md +1 -1
  13. package/skills/novel-polish//345/267/245/345/272/217/1-/350/241/250/350/276/276/346/270/205/347/220/206.md +1 -1
  14. package/skills/novel-polish//345/267/245/345/272/217/2-/350/212/202/345/245/217/344/270/216/351/207/215/345/241/221.md +5 -5
  15. package/skills/novel-review/SKILL.md +1 -1
  16. package/skills/novel-review//345/272/225/346/234/254//345/205/250/351/207/217/345/256/241/350/257/273.md +2 -2
  17. package/skills/novel-review//345/272/225/346/234/254//347/253/240/350/212/202/347/273/223/346/236/204/345/256/241/350/257/273.md +2 -2
  18. package/skills/novel-review//345/272/225/346/234/254//350/212/202/345/245/217/344/270/216/345/274/240/345/212/233/345/256/241/350/257/273.md +2 -2
  19. package/skills/novel-revision//345/272/225/346/234/254//346/224/271/347/250/277/347/253/240/347/250/213.md +1 -1
  20. package/skills/novel-screenplay/SKILL.md +22 -5
  21. package/skills/novel-screenplay//345/267/245/345/272/217/1-/346/225/205/344/272/213/347/250/277/344/270/216/344/272/272/347/211/251/345/260/217/344/274/240.md +20 -0
  22. package/skills/novel-screenplay//345/267/245/345/272/217/2-/345/210/206/345/234/272/345/244/247/347/272/262/344/270/216/344/270/211/345/271/225/350/212/202/346/213/215.md +23 -0
  23. package/skills/novel-screenplay//345/267/245/345/272/217/3-/350/247/206/350/247/211/345/212/250/344/275/234/344/270/216/346/275/234/345/217/260/350/257/215/345/257/271/347/231/275.md +21 -0
  24. package/skills/novel-screenplay//345/267/245/345/272/217/4-/345/211/247/346/234/254/347/262/276/344/277/256/344/270/216/346/224/271/347/250/277.md +16 -0
  25. package/skills/novel-screenplay//345/272/225/346/234/254//345/205/250/351/207/217/345/256/241/350/257/273.md +18 -20
  26. package/skills/novel-settle/SKILL.md +10 -6
  27. package/skills/novel-shortdrama/SKILL.md +29 -14
  28. package/skills/novel-shortdrama//345/217/202/350/200/203//344/277/235/346/212/244/346/200/247/345/217/215/344/276/213/351/233/206.md +19 -0
  29. package/skills/novel-shortdrama//345/217/202/350/200/203//345/217/260/350/257/215/344/270/203/347/273/264/350/257/212/346/226/255.md +19 -0
  30. package/skills/novel-shortdrama//345/217/202/350/200/203//345/274/200/347/257/207/351/222/251/345/255/220/344/270/216/346/226/255/347/253/240/345/205/254/345/274/217.md +44 -0
  31. package/skills/novel-shortdrama//345/217/202/350/200/203//346/203/205/347/273/252/346/265/201/345/215/225/345/205/203/351/223/276/344/270/216/345/276/200/350/277/224/346/263/225.md +31 -0
  32. package/skills/novel-shortdrama//345/217/202/350/200/203//346/210/217/345/211/247/345/267/245/350/211/272/345/261/202.md +40 -0
  33. package/skills/novel-shortdrama//345/217/202/350/200/203//351/242/230/346/235/220/344/270/216/347/210/275/347/202/271/351/200/237/346/237/245.md +23 -0
  34. package/skills/novel-shortdrama//345/267/245/345/272/217//345/210/206/351/233/206/345/244/247/347/272/262.md +26 -23
  35. package/skills/novel-shortdrama//345/267/245/345/272/217//345/215/225/351/233/206/345/211/247/346/234/254.md +29 -22
  36. package/skills/novel-shortdrama//345/272/225/346/234/254//347/237/255/345/211/247/345/256/241/350/257/273.md +34 -41
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, path81) {
117
- const ctrl = callVisitor(key, node, visitor, path81);
116
+ function visit_(key, node, visitor, path82) {
117
+ const ctrl = callVisitor(key, node, visitor, path82);
118
118
  if (identity4.isNode(ctrl) || identity4.isPair(ctrl)) {
119
- replaceNode(key, path81, ctrl);
120
- return visit_(key, ctrl, visitor, path81);
119
+ replaceNode(key, path82, ctrl);
120
+ return visit_(key, ctrl, visitor, path82);
121
121
  }
122
122
  if (typeof ctrl !== "symbol") {
123
123
  if (identity4.isCollection(node)) {
124
- path81 = Object.freeze(path81.concat(node));
124
+ path82 = Object.freeze(path82.concat(node));
125
125
  for (let i = 0; i < node.items.length; ++i) {
126
- const ci = visit_(i, node.items[i], visitor, path81);
126
+ const ci = visit_(i, node.items[i], visitor, path82);
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
- path81 = Object.freeze(path81.concat(node));
138
- const ck = visit_("key", node.key, visitor, path81);
137
+ path82 = Object.freeze(path82.concat(node));
138
+ const ck = visit_("key", node.key, visitor, path82);
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, path81);
143
+ const cv = visit_("value", node.value, visitor, path82);
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, path81) {
165
- const ctrl = await callVisitor(key, node, visitor, path81);
164
+ async function visitAsync_(key, node, visitor, path82) {
165
+ const ctrl = await callVisitor(key, node, visitor, path82);
166
166
  if (identity4.isNode(ctrl) || identity4.isPair(ctrl)) {
167
- replaceNode(key, path81, ctrl);
168
- return visitAsync_(key, ctrl, visitor, path81);
167
+ replaceNode(key, path82, ctrl);
168
+ return visitAsync_(key, ctrl, visitor, path82);
169
169
  }
170
170
  if (typeof ctrl !== "symbol") {
171
171
  if (identity4.isCollection(node)) {
172
- path81 = Object.freeze(path81.concat(node));
172
+ path82 = Object.freeze(path82.concat(node));
173
173
  for (let i = 0; i < node.items.length; ++i) {
174
- const ci = await visitAsync_(i, node.items[i], visitor, path81);
174
+ const ci = await visitAsync_(i, node.items[i], visitor, path82);
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
- path81 = Object.freeze(path81.concat(node));
186
- const ck = await visitAsync_("key", node.key, visitor, path81);
185
+ path82 = Object.freeze(path82.concat(node));
186
+ const ck = await visitAsync_("key", node.key, visitor, path82);
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, path81);
191
+ const cv = await visitAsync_("value", node.value, visitor, path82);
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, path81) {
218
+ function callVisitor(key, node, visitor, path82) {
219
219
  if (typeof visitor === "function")
220
- return visitor(key, node, path81);
220
+ return visitor(key, node, path82);
221
221
  if (identity4.isMap(node))
222
- return visitor.Map?.(key, node, path81);
222
+ return visitor.Map?.(key, node, path82);
223
223
  if (identity4.isSeq(node))
224
- return visitor.Seq?.(key, node, path81);
224
+ return visitor.Seq?.(key, node, path82);
225
225
  if (identity4.isPair(node))
226
- return visitor.Pair?.(key, node, path81);
226
+ return visitor.Pair?.(key, node, path82);
227
227
  if (identity4.isScalar(node))
228
- return visitor.Scalar?.(key, node, path81);
228
+ return visitor.Scalar?.(key, node, path82);
229
229
  if (identity4.isAlias(node))
230
- return visitor.Alias?.(key, node, path81);
230
+ return visitor.Alias?.(key, node, path82);
231
231
  return void 0;
232
232
  }
233
- function replaceNode(key, path81, node) {
234
- const parent = path81[path81.length - 1];
233
+ function replaceNode(key, path82, node) {
234
+ const parent = path82[path82.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, path81, value) {
844
+ function collectionFromPath(schema, path82, value) {
845
845
  let v = value;
846
- for (let i = path81.length - 1; i >= 0; --i) {
847
- const k = path81[i];
846
+ for (let i = path82.length - 1; i >= 0; --i) {
847
+ const k = path82[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 = (path81) => path81 == null || typeof path81 === "object" && !!path81[Symbol.iterator]().next().done;
866
+ var isEmptyPath = (path82) => path82 == null || typeof path82 === "object" && !!path82[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(path81, value) {
897
- if (isEmptyPath(path81))
896
+ addIn(path82, value) {
897
+ if (isEmptyPath(path82))
898
898
  this.add(value);
899
899
  else {
900
- const [key, ...rest] = path81;
900
+ const [key, ...rest] = path82;
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(path81) {
915
- const [key, ...rest] = path81;
914
+ deleteIn(path82) {
915
+ const [key, ...rest] = path82;
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(path81, keepScalar) {
930
- const [key, ...rest] = path81;
929
+ getIn(path82, keepScalar) {
930
+ const [key, ...rest] = path82;
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(path81) {
949
- const [key, ...rest] = path81;
948
+ hasIn(path82) {
949
+ const [key, ...rest] = path82;
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(path81, value) {
960
- const [key, ...rest] = path81;
959
+ setIn(path82, value) {
960
+ const [key, ...rest] = path82;
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(path81, value) {
3475
+ addIn(path82, value) {
3476
3476
  if (assertCollection(this.contents))
3477
- this.contents.addIn(path81, value);
3477
+ this.contents.addIn(path82, 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(path81) {
3553
- if (Collection.isEmptyPath(path81)) {
3552
+ deleteIn(path82) {
3553
+ if (Collection.isEmptyPath(path82)) {
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(path81) : false;
3559
+ return assertCollection(this.contents) ? this.contents.deleteIn(path82) : 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(path81, keepScalar) {
3575
- if (Collection.isEmptyPath(path81))
3574
+ getIn(path82, keepScalar) {
3575
+ if (Collection.isEmptyPath(path82))
3576
3576
  return !keepScalar && identity4.isScalar(this.contents) ? this.contents.value : this.contents;
3577
- return identity4.isCollection(this.contents) ? this.contents.getIn(path81, keepScalar) : void 0;
3577
+ return identity4.isCollection(this.contents) ? this.contents.getIn(path82, 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(path81) {
3589
- if (Collection.isEmptyPath(path81))
3588
+ hasIn(path82) {
3589
+ if (Collection.isEmptyPath(path82))
3590
3590
  return this.contents !== void 0;
3591
- return identity4.isCollection(this.contents) ? this.contents.hasIn(path81) : false;
3591
+ return identity4.isCollection(this.contents) ? this.contents.hasIn(path82) : 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(path81, value) {
3609
- if (Collection.isEmptyPath(path81)) {
3608
+ setIn(path82, value) {
3609
+ if (Collection.isEmptyPath(path82)) {
3610
3610
  this.contents = value;
3611
3611
  } else if (this.contents == null) {
3612
- this.contents = Collection.collectionFromPath(this.schema, Array.from(path81), value);
3612
+ this.contents = Collection.collectionFromPath(this.schema, Array.from(path82), value);
3613
3613
  } else if (assertCollection(this.contents)) {
3614
- this.contents.setIn(path81, value);
3614
+ this.contents.setIn(path82, 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, path81) => {
5574
+ visit.itemAtPath = (cst, path82) => {
5575
5575
  let item = cst;
5576
- for (const [field, index] of path81) {
5576
+ for (const [field, index] of path82) {
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, path81) => {
5586
- const parent = visit.itemAtPath(cst, path81.slice(0, -1));
5587
- const field = path81[path81.length - 1][0];
5585
+ visit.parentCollection = (cst, path82) => {
5586
+ const parent = visit.itemAtPath(cst, path82.slice(0, -1));
5587
+ const field = path82[path82.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(path81, item, visitor) {
5594
- let ctrl = visitor(item, path81);
5593
+ function _visit(path82, item, visitor) {
5594
+ let ctrl = visitor(item, path82);
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(path81.concat([[field, i]])), token.items[i], visitor);
5601
+ const ci = _visit(Object.freeze(path82.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, path81);
5612
+ ctrl = ctrl(item, path82);
5613
5613
  }
5614
5614
  }
5615
- return typeof ctrl === "function" ? ctrl(item, path81) : ctrl;
5615
+ return typeof ctrl === "function" ? ctrl(item, path82) : 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 fs68 = this.flowScalar(this.type);
6917
+ const fs69 = this.flowScalar(this.type);
6918
6918
  if (atNextItem || it.value) {
6919
- map.items.push({ start, key: fs68, sep: [] });
6919
+ map.items.push({ start, key: fs69, sep: [] });
6920
6920
  this.onKeyLine = true;
6921
6921
  } else if (it.sep) {
6922
- this.stack.push(fs68);
6922
+ this.stack.push(fs69);
6923
6923
  } else {
6924
- Object.assign(it, { key: fs68, sep: [] });
6924
+ Object.assign(it, { key: fs69, 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 fs68 = this.flowScalar(this.type);
7052
+ const fs69 = this.flowScalar(this.type);
7053
7053
  if (!it || it.value)
7054
- fc.items.push({ start: [], key: fs68, sep: [] });
7054
+ fc.items.push({ start: [], key: fs69, sep: [] });
7055
7055
  else if (it.sep)
7056
- this.stack.push(fs68);
7056
+ this.stack.push(fs69);
7057
7057
  else
7058
- Object.assign(it, { key: fs68, sep: [] });
7058
+ Object.assign(it, { key: fs69, 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 fs68 = __require("fs");
7424
+ var fs69 = __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
- fs68.read(self.fd, buffer, offset, length, position, function(err, bytesRead, buffer2) {
7444
+ fs69.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
- fs68.close(self.fd, onCloseDone);
7461
+ fs69.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
- fs68.read(self.context.fd, buffer, 0, toRead, self.pos, function(err, bytesRead) {
7493
+ fs69.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 fs68 = __require("fs");
7853
+ var fs69 = __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(path81, options2) {
7878
+ function openPromise(path82, options2) {
7879
7879
  return new Promise((resolve22, reject) => {
7880
- open(path81, { ...options2, lazyEntries: true }, function(err, zipfile) {
7880
+ open(path82, { ...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(path81, options2, callback) {
7910
+ function open(path82, 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
- fs68.open(path81, "r", function(err, fd) {
7922
+ fs69.open(path82, "r", function(err, fd) {
7923
7923
  if (err) return callback(err);
7924
7924
  fromFd(fd, options2, function(err2, zipfile) {
7925
- if (err2) fs68.close(fd, defaultCallback);
7925
+ if (err2) fs69.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
- fs68.fstat(fd, function(err, stats) {
7942
+ fs69.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);
@@ -11105,17 +11105,17 @@ Schema.prototype.volatile = function volatile() {
11105
11105
  };
11106
11106
  var resolvers = {};
11107
11107
  var checkedVolatile = /* @__PURE__ */ Symbol("checked-volatile-schema");
11108
- function validateVolatileSchema(schema, path81 = [], blocked = false, seen = /* @__PURE__ */ new Map()) {
11108
+ function validateVolatileSchema(schema, path82 = [], blocked = false, seen = /* @__PURE__ */ new Map()) {
11109
11109
  const states = seen.get(schema) ?? /* @__PURE__ */ new Set();
11110
11110
  if (states.has(blocked)) return;
11111
11111
  states.add(blocked);
11112
11112
  seen.set(schema, states);
11113
- if (schema.meta?.volatile && blocked) throw new ValidationError("volatile fields require a fixed object path without an enclosing volatile field", { path: path81 });
11113
+ if (schema.meta?.volatile && blocked) throw new ValidationError("volatile fields require a fixed object path without an enclosing volatile field", { path: path82 });
11114
11114
  const nested = blocked || !!schema.meta?.volatile;
11115
- if (schema.dict) for (const [key, child] of Object.entries(schema.dict)) validateVolatileSchema(child, [...path81, key], nested, seen);
11116
- if (schema.sKey) validateVolatileSchema(schema.sKey, [...path81, "<key>"], true, seen);
11117
- if (schema.inner && (schema.type !== "lazy" || schema.inner[kSchema])) validateVolatileSchema(schema.inner, [...path81, "*"], true, seen);
11118
- if (schema.list) for (let index = 0; index < schema.list.length; index++) validateVolatileSchema(schema.list[index], [...path81, String(index)], true, seen);
11115
+ if (schema.dict) for (const [key, child] of Object.entries(schema.dict)) validateVolatileSchema(child, [...path82, key], nested, seen);
11116
+ if (schema.sKey) validateVolatileSchema(schema.sKey, [...path82, "<key>"], true, seen);
11117
+ if (schema.inner && (schema.type !== "lazy" || schema.inner[kSchema])) validateVolatileSchema(schema.inner, [...path82, "*"], true, seen);
11118
+ if (schema.list) for (let index = 0; index < schema.list.length; index++) validateVolatileSchema(schema.list[index], [...path82, String(index)], true, seen);
11119
11119
  }
11120
11120
  Schema.extend = function extend(type, resolve22) {
11121
11121
  resolvers[type] = resolve22;
@@ -14515,7 +14515,8 @@ function trueSourceTool(relPath) {
14515
14515
  [/^大纲\/卷规划\/[^/]+\/(卷纲|计划时间线|卷摘要)\.md$/, "novel_confirm_volume_outline"],
14516
14516
  [/^世界书\//, "novel_confirm_worldbook_entry\uFF08\u8BBE\u8BA1\u6761\u76EE\uFF09\uFF1B\u5DF2\u5165\u6863\u4E8B\u5B9E\u66F4\u6B63\u8D70 novel_apply_retcon"],
14517
14517
  [/^账本\//, "novel_settle_chapter\uFF08\u65B0\u589E\u6C89\u6DC0\uFF09\uFF1B\u5DF2\u5165\u6863\u6761\u76EE\u66F4\u6B63\u8D70 novel_apply_retcon"],
14518
- [/^本书记忆\//, "novel_record_memory\uFF08\u672C\u4E66\u8303\u56F4\uFF09\uFF1B\u5B9A\u7A3F\u5019\u9009\u968F novel_settle_chapter \u6C89\u6DC0"]
14518
+ [/^本书记忆\//, "novel_record_memory\uFF08\u672C\u4E66\u8303\u56F4\uFF09\uFF1B\u5B9A\u7A3F\u5019\u9009\u968F novel_settle_chapter \u6C89\u6DC0"],
14519
+ [/^剧本\/短剧\//, "novel_shortdrama_settle_episode\uFF08\u5B9A\u7A3F\u5165\u6863\uFF09\uFF1B\u8349\u7A3F\u8BF7\u7528 novel_shortdrama_render_episode"]
14519
14520
  ];
14520
14521
  const tool = rules.find(([pattern2]) => pattern2.test(relPath))?.[1];
14521
14522
  return tool === void 0 ? "\u8BF7\u6539\u7528\u5BF9\u5E94\u7684\u4E13\u7528\u5DE5\u5177\u3002" : `\u8BF7\u6539\u7528 ${tool}\u3002`;
@@ -14784,7 +14785,7 @@ function formatCommitMessage(input) {
14784
14785
 
14785
14786
  // ../core/src/commit/paths.ts
14786
14787
  import * as path16 from "node:path";
14787
- var ALLOWED_TOP = /* @__PURE__ */ new Set(["\u5B9A\u7A3F", "\u5927\u7EB2", "\u4E16\u754C\u4E66", "\u8D26\u672C", "\u672C\u4E66\u8BB0\u5FC6", "\u4F5C\u54C1\u5951\u7EA6", "\u6784\u60F3"]);
14788
+ var ALLOWED_TOP = /* @__PURE__ */ new Set(["\u5B9A\u7A3F", "\u5267\u672C", "\u5927\u7EB2", "\u4E16\u754C\u4E66", "\u8D26\u672C", "\u672C\u4E66\u8BB0\u5FC6", "\u4F5C\u54C1\u5951\u7EA6", "\u6784\u60F3"]);
14788
14789
  var REJECT_TOP = /* @__PURE__ */ new Set(["\u77E5\u8BC6\u5E93", "profiles", "books", "\u8349\u7A3F\u533A"]);
14789
14790
  function toPosix(rel) {
14790
14791
  return rel.split(/[\\/]/).join("/");
@@ -20428,7 +20429,7 @@ function validateStoryDraft(story) {
20428
20429
  if (story.\u5173\u952E\u8F6C\u6298.length === 0) errors.push("\u6CA1\u6709\u5173\u952E\u8F6C\u6298");
20429
20430
  if (story.\u7ED3\u5C3E.trim() === "") errors.push("\u300C\u7ED3\u5C3E\u300D\u4E3A\u7A7A");
20430
20431
  for (const c of story.\u4EBA\u7269) {
20431
- if (!/动机|想要|想|目标|害怕|怕|非.*不可|渴望|执念/.test(c.\u5C0F\u4F20)) {
20432
+ if (!/动机|想要|想|目标|害怕|怕|非.*不可|渴望|执念|旨在|必须|为了|保住|查明|洗清|掩盖|夺回|守护|阻止|复仇/.test(c.\u5C0F\u4F20)) {
20432
20433
  warnings.push(`\u4EBA\u7269\u300C${c.\u59D3\u540D}\u300D\u7684\u5C0F\u4F20\u91CC\u6CA1\u5199\u6E05\u52A8\u673A\uFF08\u60F3\u8981\u4EC0\u4E48\u3001\u4E3A\u4EC0\u4E48\u975E\u8981\u4E0D\u53EF\uFF09\uFF0C\u5267\u672C\u7EE7\u627F\u4E0D\u4E86\u8FD9\u4E2A\u4EBA\u7269\u7684\u6DF1\u5EA6`);
20433
20434
  }
20434
20435
  }
@@ -21646,8 +21647,8 @@ var EPISODE_SETTING_RE = /^场景环境[::]\s*(.+?)\s*$/;
21646
21647
  var EPISODE_SOUND_RE = /^【环境声[::](.+)】$/;
21647
21648
  var EPISODE_SUBTITLE_RE = /^【字幕[::](.+)】$/;
21648
21649
  var EPISODE_DIALOGUE_RE = /^([^::((]{1,15}?)(?:[((]([^))]+)[))])?[::](.+)$/;
21649
- var EPISODE_BEAT_OPEN_RE = /^-\s*开场冲突:\s*第\s*(\d+)\s*秒/;
21650
- var EPISODE_BEAT_HOOK_RE = /^-\s*结尾钩子:\s*第\s*(\d+)\s*秒/;
21650
+ var EPISODE_BEAT_OPEN_RE = /^-\s*开场冲突[::]\s*(?:第\s*)?(\d+)\s*(?:秒|s)/i;
21651
+ var EPISODE_BEAT_HOOK_RE = /^-\s*结尾钩子[::]\s*(?:第\s*)?(\d+)\s*(?:秒|s)/i;
21651
21652
  function parseShotTimecode(raw, where, problems) {
21652
21653
  const value = raw.trim();
21653
21654
  if (value === "\u2014" || value === "") return { \u5F00\u59CB\u79D2: null, \u7ED3\u675F\u79D2: null };
@@ -21713,8 +21714,9 @@ function parseEpisodeScript(text5) {
21713
21714
  if (\u753B\u5E45 !== "\u7AD6\u5C4F" && \u753B\u5E45 !== "\u6A2A\u5C4F") problems.push(`\u5355\u96C6\u5267\u672C\u7F3A\u5C11\u6216\u5199\u9519\u753B\u5E45\uFF08\u5E94\u4E3A \u7AD6\u5C4F \u6216 \u6A2A\u5C4F\uFF09\uFF1A${\u753B\u5E45raw ?? "\u65E0"}`);
21714
21715
  const \u65F6\u957Fraw = episodeMetaValue(lines, "\u65F6\u957F");
21715
21716
  const \u65F6\u957F\u79D2 = \u65F6\u957Fraw === void 0 ? NaN : Number(/(\d+)/.exec(\u65F6\u957Fraw)?.[1]);
21716
- const \u94A9\u5B50\u7C7B\u578B = episodeMetaValue(lines, "\u94A9\u5B50\u7C7B\u578B");
21717
- if (\u94A9\u5B50\u7C7B\u578B !== "\u8EAB\u4EFD" && \u94A9\u5B50\u7C7B\u578B !== "\u60C5\u611F" && \u94A9\u5B50\u7C7B\u578B !== "\u987F\u609F") problems.push(`\u5355\u96C6\u5267\u672C\u7F3A\u5C11\u6216\u5199\u9519\u94A9\u5B50\u7C7B\u578B\uFF08\u8EAB\u4EFD/\u60C5\u611F/\u987F\u609F\uFF09\uFF1A${\u94A9\u5B50\u7C7B\u578B ?? "\u65E0"}`);
21717
+ const rawHook = episodeMetaValue(lines, "\u94A9\u5B50\u7C7B\u578B");
21718
+ const \u94A9\u5B50\u7C7B\u578B = rawHook === void 0 ? void 0 : rawHook.replace(/钩$/, "").trim();
21719
+ if (\u94A9\u5B50\u7C7B\u578B !== "\u8EAB\u4EFD" && \u94A9\u5B50\u7C7B\u578B !== "\u60C5\u611F" && \u94A9\u5B50\u7C7B\u578B !== "\u987F\u609F") problems.push(`\u5355\u96C6\u5267\u672C\u7F3A\u5C11\u6216\u5199\u9519\u94A9\u5B50\u7C7B\u578B\uFF08\u8EAB\u4EFD/\u60C5\u611F/\u987F\u609F\uFF09\uFF1A${rawHook ?? "\u65E0"}`);
21718
21720
  const \u6838\u5FC3\u60F3\u6CD5 = episodeMetaValue(lines, "\u6838\u5FC3\u60F3\u6CD5") ?? "";
21719
21721
  const \u723D\u70B9 = episodeMetaValue(lines, "\u723D\u70B9") ?? "";
21720
21722
  const \u7ED3\u5C3E\u60AC\u5FF5 = episodeMetaValue(lines, "\u7ED3\u5C3E\u60AC\u5FF5") ?? "";
@@ -21815,7 +21817,7 @@ function parseEpisodeScript(text5) {
21815
21817
  const twist = /^-\s*反转[::]\s*(.+?)\s*$/.exec(line);
21816
21818
  if (twist) {
21817
21819
  const value = twist[1].trim();
21818
- \u53CD\u8F6C\u79D2 = value === "\u65E0" ? [] : [...value.matchAll(/第\s*(\d+)\s*秒/g)].map((m) => Number(m[1]));
21820
+ \u53CD\u8F6C\u79D2 = value === "\u65E0" ? [] : [...value.matchAll(/(?:第\s*)?(\d+)\s*(?:秒|s)/gi)].map((m) => Number(m[1]));
21819
21821
  continue;
21820
21822
  }
21821
21823
  continue;
@@ -21952,6 +21954,223 @@ function parseEpisodeScript(text5) {
21952
21954
  return { ok: true, problems, episode };
21953
21955
  }
21954
21956
 
21957
+ // ../core/src/shortdrama/episode-checks.ts
21958
+ var REDLINE_RE = /断肢|开膛|破肚|身首异处|凌迟|活埋|注射死刑|吸毒|制毒|自杀方法|下蛊害人|蛊毒害人|真实的国家机关/;
21959
+ var OPEN_BAN_RE = /拉窗帘|太阳升起|醒过来|闹钟响|起床洗漱|开车上班|喝咖啡闲聊|悠闲的清晨|阳光明媚的早晨/;
21960
+ var WEAK_MICRO_ACT_RE = /眼神微动|眼神微闪|目光微闪|目光微动|微微一怔|若有所思|陷入沉思|嘴角微扬|嘴角微勾|推了半寸|移了半寸/;
21961
+ var STRONG_ACT_MARKERS = /砸|摔|甩|拍|踹|踢|扇|掀|撞|掐|抓|拽|扯|泼|烧|点燃|撕|跪|瘫|倒地|跌|扔|抛|夺|抢|掏出|抽出|拔出|按住|挡|躲|冲上|扑|抱住|拖|绑|堵住|捂|翻过|推翻|推开|推倒|举|亮出|亮明|逼近|踉跄|后退|转身|起身|站起|碎|裂|滚落|滑落|溅|冒出|涨红|攥|捏|摁|特写|推给|滑到|递/;
21962
+ var JARGON_RIDDLE_RE = /法则缝隙|气运锚点|因果闭环|维度坍缩|高维投影|底层逻辑闭环|赋能矩阵/;
21963
+ var PLAIN_GROUNDING_RE = /就是|赔|钱|万|亿|块|命|破产|坐牢|退婚|滚出|抵押|合同|房子|股权|死|活/;
21964
+ var ABSTRACT_EMOTION_CUE_RE = /^[((]?\s*(?:开心|难过|生气|愤怒|悲伤|伤心|高兴|邪魅|伤感|激动)\s*[))]?$/;
21965
+ var COMMON_TYPOS_RE = /竞然|迫不急待|按耐不住|走头无路|一愁莫展|再接再励|出奇不意/;
21966
+ function netChars(text5) {
21967
+ return Array.from(text5.replace(/[\s,。!?;:、“”‘’()()【】\[\]《》—…·\-]/g, "")).length;
21968
+ }
21969
+ function stripShotTag(text5) {
21970
+ return text5.replace(/^△\s*【镜头\d+[^】]*】\s*/, "").replace(/^△\s*/, "").trim();
21971
+ }
21972
+ function extractCraftUnits(script) {
21973
+ const epTag = `\u96C6${String(script.\u96C6).padStart(3, "0")}`;
21974
+ const units = [];
21975
+ for (const scene of script.\u573A\u666F) {
21976
+ const loc = `${epTag}/\u573A${String(scene.\u573A).padStart(2, "0")}`;
21977
+ if (scene.\u955C\u5934 && scene.\u955C\u5934.length > 0) {
21978
+ for (const shot of scene.\u955C\u5934) {
21979
+ const shotLoc = `${loc}/\u955C${String(shot.\u955C\u5934\u53F7).padStart(2, "0")}`;
21980
+ for (const line of shot.\u63CF\u5199) {
21981
+ if (line.trim() !== "") {
21982
+ units.push({ kind: "action", location: shotLoc, text: line.trim(), shotInterleaved: true });
21983
+ }
21984
+ }
21985
+ for (const line of shot.\u53F0\u8BCD) {
21986
+ if (line.\u53F0\u8BCD.trim() !== "") {
21987
+ units.push({
21988
+ kind: "dialogue",
21989
+ location: shotLoc,
21990
+ text: line.\u53F0\u8BCD.trim(),
21991
+ shotInterleaved: true,
21992
+ ...line.\u62EC\u53F7\u63D0\u793A ? { cue: line.\u62EC\u53F7\u63D0\u793A } : {}
21993
+ });
21994
+ }
21995
+ }
21996
+ }
21997
+ } else {
21998
+ const env = (scene.\u573A\u666F\u73AF\u5883 ?? scene.\u52A8\u4F5C).trim();
21999
+ if (env !== "") {
22000
+ units.push({ kind: "action", location: loc, text: env, shotInterleaved: false });
22001
+ }
22002
+ for (const line of scene.\u53F0\u8BCD) {
22003
+ if (line.\u53F0\u8BCD.trim() !== "") {
22004
+ units.push({
22005
+ kind: "dialogue",
22006
+ location: loc,
22007
+ text: line.\u53F0\u8BCD.trim(),
22008
+ shotInterleaved: false,
22009
+ ...line.\u62EC\u53F7\u63D0\u793A ? { cue: line.\u62EC\u53F7\u63D0\u793A } : {}
22010
+ });
22011
+ }
22012
+ }
22013
+ }
22014
+ }
22015
+ return units;
22016
+ }
22017
+ function pushFinding(list, \u8BC1\u636E\u4F4D\u7F6E, \u4E25\u91CD\u7A0B\u5EA6, \u662F\u5426\u5EFA\u8BAE\u963B\u65AD, \u95EE\u9898\u8BF4\u660E, \u4FEE\u6539\u5EFA\u8BAE) {
22018
+ list.push({
22019
+ \u6A21\u5757\u540D: "\u77ED\u5267\u5BA1\u8BFB",
22020
+ \u8BC1\u636E\u4F4D\u7F6E,
22021
+ \u4E25\u91CD\u7A0B\u5EA6,
22022
+ \u662F\u5426\u5EFA\u8BAE\u963B\u65AD,
22023
+ \u95EE\u9898\u8BF4\u660E,
22024
+ \u4FEE\u6539\u5EFA\u8BAE,
22025
+ \u5EFA\u8BAE\u8FD4\u56DE\u8282\u70B9: "\u5355\u96C6\u5267\u672C",
22026
+ \u5904\u7F6E\u72B6\u6001: "\u5F85\u5904\u7406"
22027
+ });
22028
+ }
22029
+ function checkEpisodeCraft(script) {
22030
+ const findings = [];
22031
+ const units = extractCraftUnits(script);
22032
+ if (units.length === 0) return findings;
22033
+ const epTag = `\u96C6${String(script.\u96C6).padStart(3, "0")}`;
22034
+ const fullText = units.map((u) => u.text).join("\n");
22035
+ const redline = REDLINE_RE.exec(fullText);
22036
+ if (redline !== null) {
22037
+ pushFinding(
22038
+ findings,
22039
+ epTag,
22040
+ "\u9AD8",
22041
+ true,
22042
+ `\u5408\u89C4\u7EA2\u7EBF\uFF08E10\uFF09\uFF1A\u547D\u4E2D\u77ED\u5267\u5E73\u53F0\u9AD8\u5371\u8FDD\u7981\u8BCD\u300C${redline[0]}\u300D\u3002`,
22043
+ "\u5220\u9664\u6216\u66FF\u6362\u4E3A\u5408\u6CD5\u53EF\u62CD\u7684\u5177\u4F53\u620F\u5267\u51B2\u7A81\u7EC6\u8282\u3002"
22044
+ );
22045
+ }
22046
+ const headText = units.slice(0, 3).map((u) => u.text).join(" ");
22047
+ const openBan = OPEN_BAN_RE.exec(headText);
22048
+ if (openBan !== null) {
22049
+ pushFinding(
22050
+ findings,
22051
+ units[0].location,
22052
+ "\u4E2D",
22053
+ false,
22054
+ `\u5F00\u7BC7\u5E9F\u955C\u5934\uFF08E5\uFF09\uFF1A\u5F00\u7BC7\u524D 3 \u62CD\u51FA\u73B0\u6162\u70ED\u65E5\u5E38\u94FA\u57AB\u300C${openBan[0]}\u300D\uFF0C\u5BB9\u6613\u9519\u5931\u9EC4\u91D1 3 \u79D2\u7559\u5B58\u3002`,
22055
+ "\u780D\u6389\u8D77\u5E8A/\u51FA\u95E8/\u559D\u5496\u5561\u94FA\u57AB\uFF0C\u9996\u955C\u76F4\u63A5\u5207\u5165\u51B2\u7A81\u6216\u5012\u8BA1\u65F6\u6B7B\u7EBF\u52A8\u4F5C\u3002"
22056
+ );
22057
+ }
22058
+ let consecutiveDlgLines = 0;
22059
+ let consecutiveDlgChars = 0;
22060
+ let dryRunWarned = false;
22061
+ let densityWarned = false;
22062
+ let totalDlgChars = 0;
22063
+ let totalActChars = 0;
22064
+ for (let i = 0; i < units.length; i += 1) {
22065
+ const unit = units[i];
22066
+ const typo = COMMON_TYPOS_RE.exec(unit.text);
22067
+ if (typo !== null) {
22068
+ pushFinding(
22069
+ findings,
22070
+ unit.location,
22071
+ "\u4F4E",
22072
+ false,
22073
+ `\u9AD8\u9891\u540C\u97F3\u9519\u522B\u5B57\uFF08E22\uFF09\uFF1A\u7591\u4F3C\u9519\u522B\u5B57\u300C${typo[0]}\u300D\u3002`,
22074
+ "\u6838\u5BF9\u5E76\u4FEE\u6B63\u7528\u5B57\uFF08\u5982\u7ADF\u7136/\u8FEB\u4E0D\u53CA\u5F85/\u6309\u637A\u4E0D\u4F4F/\u8D70\u6295\u65E0\u8DEF/\u4E00\u7B79\u83AB\u5C55/\u518D\u63A5\u518D\u5389/\u51FA\u5176\u4E0D\u610F\uFF09\u3002"
22075
+ );
22076
+ }
22077
+ if (unit.kind === "action") {
22078
+ consecutiveDlgLines = 0;
22079
+ consecutiveDlgChars = 0;
22080
+ const cleanAct = stripShotTag(unit.text);
22081
+ const actLen = netChars(cleanAct);
22082
+ totalActChars += actLen;
22083
+ if (actLen > 45) {
22084
+ pushFinding(
22085
+ findings,
22086
+ unit.location,
22087
+ "\u4F4E",
22088
+ false,
22089
+ `\u52A8\u4F5C\u63CF\u5199\u8FC7\u957F\uFF08E20\uFF09\uFF1A\u5355\u6761\u52A8\u4F5C\u63CF\u5199\u51C0\u5B57\u6570\u4E3A ${actLen} \u5B57\uFF0C\u8D85\u51FA\u5355\u955C\u53EF\u8BFB\u5EFA\u8BAE\uFF0840\u201345 \u5B57\uFF09\u3002`,
22090
+ "\u62C6\u5206\u4E3A\u4E24\u4E2A\u77ED\u4FC3\u53EF\u62CD\u7684\u955C\u5934\u62CD\uFF0C\u6216\u780D\u6389\u975E\u89C6\u89C9\u5FC3\u7406\u8D58\u8BED\u3002"
22091
+ );
22092
+ }
22093
+ if (WEAK_MICRO_ACT_RE.test(cleanAct) && !STRONG_ACT_MARKERS.test(cleanAct)) {
22094
+ pushFinding(
22095
+ findings,
22096
+ unit.location,
22097
+ "\u4F4E",
22098
+ false,
22099
+ `\u65E0\u6548\u5FAE\u52A8\u4F5C\uFF08E26\uFF09\uFF1A\u52A8\u4F5C\u63CF\u5199\u300C${cleanAct}\u300D\u4EC5\u4F9D\u8D56\u865A\u5FAE\u795E\u6001\uFF0C\u7F3A\u4E4F\u53EF\u89C1\u7269\u7406\u52A8\u4F5C\u652F\u6491\u3002`,
22100
+ "\u8865\u4E00\u4E2A\u8089\u773C\u53EF\u89C1\u7684\u5F3A\u7269\u7406\u52A8\u4F5C\u6807\u8BB0\uFF08\u7838/\u6454/\u6309/\u4EAE\u724C/\u8F6C\u8EAB/\u6454\uFF09\uFF0C\u6216\u6539\u4E3A\u5177\u4F53\u624B\u5934\u52A8\u4F5C\u3002"
22101
+ );
22102
+ }
22103
+ continue;
22104
+ }
22105
+ consecutiveDlgLines += 1;
22106
+ const dlgLen = netChars(unit.text);
22107
+ consecutiveDlgChars += dlgLen;
22108
+ totalDlgChars += dlgLen;
22109
+ if (!dryRunWarned && unit.shotInterleaved && consecutiveDlgLines > 6) {
22110
+ dryRunWarned = true;
22111
+ pushFinding(
22112
+ findings,
22113
+ unit.location,
22114
+ "\u4E2D",
22115
+ false,
22116
+ `\u5E72\u804A\u65AD\u5C42\uFF08E24\uFF09\uFF1A\u5DF2\u8FDE\u7EED\u51FA\u73B0 ${consecutiveDlgLines} \u53E5\u7EAF\u5BF9\u767D\u800C\u65E0\u89C6\u89C9\u52A8\u4F5C \u25B3 \u63D2\u5165\uFF0C\u753B\u9762\u6613\u6CA6\u4E3A\u7AD9\u6869\u5E7F\u64AD\u5267\u3002`,
22117
+ "\u6BCF 2\u20134 \u53E5\u5BF9\u767D\u7A7F\u63D2 1 \u6761\u53EF\u89C1\u7269\u7406\u52A8\u4F5C\u3001\u795E\u6001\u53CD\u5E94\u7279\u5199\u6216\u7269\u8BC1\u64CD\u4F5C\u955C\u5934\u3002"
22118
+ );
22119
+ }
22120
+ if (!densityWarned && consecutiveDlgChars > 95) {
22121
+ densityWarned = true;
22122
+ pushFinding(
22123
+ findings,
22124
+ unit.location,
22125
+ "\u4F4E",
22126
+ false,
22127
+ `15 \u79D2\u7A97\u53E3\u53F0\u8BCD\u8FC7\u5BC6\uFF08E19\uFF09\uFF1A\u8FDE\u7EED\u5BF9\u767D\u5DF2\u8FBE ${consecutiveDlgChars} \u5B57\uFF08\u8D85\u51FA 15 \u79D2\u7A97\u53E3\u53C2\u8003\u5BB9\u91CF\uFF09\uFF0C\u5EFA\u8BAE\u63D2\u5165\u52A8\u4F5C\u505C\u987F\u6362\u6C14\u3002`,
22128
+ "\u5728\u4E2D\u95F4\u5207\u5165\u4E00\u6761\u5BF9\u624B\u53CD\u5E94\u6216\u9053\u5177\u52A8\u4F5C\u6253\u65AD\u53E3\u64AD\u611F\u3002"
22129
+ );
22130
+ }
22131
+ if (unit.cue && ABSTRACT_EMOTION_CUE_RE.test(unit.cue.trim())) {
22132
+ pushFinding(
22133
+ findings,
22134
+ unit.location,
22135
+ "\u4F4E",
22136
+ false,
22137
+ `\u8868\u6F14\u8BED\u6C14\u8FC7\u4E8E\u62BD\u8C61\uFF08E18a\uFF09\uFF1A\u62EC\u53F7\u63D0\u793A\u300C${unit.cue}\u300D\u53EA\u6709\u62BD\u8C61\u60C5\u7EEA\u6807\u7B7E\uFF0C\u4E0D\u5229\u4E8E\u6F14\u5458\u4E0E\u58F0\u97F3\u6307\u5BFC\u843D\u5730\u3002`,
22138
+ "\u6539\u5199\u4E3A\u53EF\u8868\u6F14\u7684\u58F0\u5B66\u4E0E\u8EAB\u4F53\u63D0\u793A\uFF08\u5982\u201C\u538B\u4F4E\u58F0\u97F3\u3001\u7B11\u610F\u4E0D\u8FBE\u773C\u5E95\u201D\u6216\u8BED\u901F/\u97F3\u91CF/\u5C3E\u97F3\u63CF\u8FF0\uFF09\u3002"
22139
+ );
22140
+ }
22141
+ const riddle = JARGON_RIDDLE_RE.exec(unit.text);
22142
+ if (riddle !== null) {
22143
+ const nextDlg = units.slice(i + 1, i + 3).find((u) => u.kind === "dialogue")?.text ?? "";
22144
+ if (!PLAIN_GROUNDING_RE.test(unit.text) && !PLAIN_GROUNDING_RE.test(nextDlg)) {
22145
+ pushFinding(
22146
+ findings,
22147
+ unit.location,
22148
+ "\u4F4E",
22149
+ false,
22150
+ `\u9ED1\u8BDD\u672A\u4F5C\u5927\u767D\u8BDD\u6362\u7B97\uFF08E25\uFF09\uFF1A\u53F0\u8BCD\u51FA\u73B0\u62BD\u8C61\u8BBE\u5B9A\u8BCD\u300C${riddle[0]}\u300D\uFF0C\u4E14\u540C\u8F6E\u6216\u4E0B\u4E00\u53E5\u672A\u76F4\u7ED9\u767D\u8BDD\u5229\u5BB3\u7ED3\u8BBA\u3002`,
22151
+ "\u5F53\u53E5\u6216\u7D27\u63A5\u4E0B\u4E00\u53E5\u7528\u5927\u767D\u8BDD\u70B9\u900F\u503C\u591A\u5C11\u94B1\u3001\u72AF\u4EC0\u4E48\u7F6A\u6216\u8C01\u8F93\u8C01\u8D62\u3002"
22152
+ );
22153
+ }
22154
+ }
22155
+ }
22156
+ const hasInterleavedShots = units.some((u) => u.shotInterleaved);
22157
+ const dlgCount = units.filter((u) => u.kind === "dialogue").length;
22158
+ if (hasInterleavedShots && dlgCount >= 6 && totalDlgChars + totalActChars > 0) {
22159
+ const ratio = totalDlgChars / (totalDlgChars + totalActChars);
22160
+ if (ratio > 0.72) {
22161
+ pushFinding(
22162
+ findings,
22163
+ epTag,
22164
+ "\u4F4E",
22165
+ false,
22166
+ `\u89C6\u542C\u52A8\u4F5C\u5360\u6BD4\u504F\u4F4E\uFF08E21\uFF09\uFF1A\u672C\u96C6\u5BF9\u767D\u5B57\u6570\u5360\u6BD4 ${(ratio * 100).toFixed(0)}%\uFF08\u9AD8\u4E8E 70% \u53C2\u8003\u7EBF\uFF09\uFF0C\u89C6\u542C\u8C03\u5EA6\u7565\u5355\u8584\u3002`,
22167
+ "\u5220\u51CF\u53E3\u6C34\u590D\u8FF0\u53E5\uFF0C\u5C06\u5FC3\u7406\u51B2\u7A81\u6539\u7528\u8EAB\u4EFD\u53CD\u5DEE\u5FD9\u6D3B\u6216\u7269\u8BC1\u5BF9\u6297\u955C\u5934\u6F14\u51FA\u3002"
22168
+ );
22169
+ }
22170
+ }
22171
+ return findings;
22172
+ }
22173
+
21955
22174
  // ../core/src/shortdrama/review.ts
21956
22175
  function epNo(\u96C6) {
21957
22176
  return `\u96C6${String(\u96C6).padStart(3, "0")}`;
@@ -21991,10 +22210,10 @@ function reviewShortDramaEpisode(input) {
21991
22210
  if (n2 > MAX_DIALOGUE_CHARS) {
21992
22211
  push2(
21993
22212
  `${ep}/${sceneNo(scene.\u573A)}`,
21994
- "\u4E2D",
22213
+ "\u4F4E",
21995
22214
  false,
21996
22215
  `${line.\u89D2\u8272}\u7684\u53F0\u8BCD ${n2} \u5B57\uFF0C\u8D85\u8FC7\u5355\u53E5 ${MAX_DIALOGUE_CHARS} \u5B57\u4E0A\u9650\uFF1A\u300C${line.\u53F0\u8BCD}\u300D\u3002`,
21997
- "\u62C6\u6210\u4E24\u53E5\u77ED\u53F0\u8BCD\uFF0C\u6216\u6539\u6210\u52A8\u4F5C\u884C\uFF08\u5BF9\u767D\u5373\u884C\u52A8\uFF0C\u77ED\u53E5\u624D\u6709\u529B\uFF09\u3002",
22216
+ \u5267\u672C.\u753B\u5E45 === "\u6A2A\u5C4F" ? "\u6A2A\u5C4F\u5141\u8BB8\u66F4\u81EA\u7136\u7684\u6F5C\u53F0\u8BCD\u4E0E\u957F\u5BF9\u767D\uFF0C\u4EC5\u4F5C\u53C2\u8003\uFF1B\u82E5\u53E3\u64AD\u504F\u957F\u518D\u9002\u5F53\u62C6\u5206\u3002" : "\u7AD6\u5C4F\u53F0\u8BCD\u5B9C\u77ED\u4FC3\u6709\u529B\uFF0C\u53EF\u6309\u9700\u8981\u62C6\u6210\u4E24\u53E5\u77ED\u53F0\u8BCD\u6216\u7528\u52A8\u4F5C\u620F\u627F\u63A5\uFF08\u6B64\u9879\u4EC5\u5EFA\u8BAE\uFF0C\u4E0D\u963B\u65AD\u5B9A\u7A3F\uFF09\u3002",
21998
22217
  "\u5355\u96C6\u5267\u672C"
21999
22218
  );
22000
22219
  }
@@ -22026,6 +22245,7 @@ function reviewShortDramaEpisode(input) {
22026
22245
  if (\u5267\u672C.\u7ED3\u5C3E\u60AC\u5FF5.trim() !== \u5927\u7EB2.\u7ED3\u5C3E\u60AC\u5FF5.trim()) {
22027
22246
  push2(ep, "\u9AD8", true, "\u7ED3\u5C3E\u60AC\u5FF5\u4E0E\u5927\u7EB2\u4E0D\u4E00\u81F4\uFF1A\u5FC5\u987B\u5207\u5728\u540C\u4E00\u4E2A\u95EE\u9898\u4E0A\u3002", "\u4EE5\u5927\u7EB2\u4E3A\u51C6\u6539\u5267\u672C\u7ED3\u5C3E\uFF0C\u6216\u56DE\u5206\u96C6\u5927\u7EB2\u6539\u60AC\u5FF5\u3002", "\u5206\u96C6\u5927\u7EB2");
22028
22247
  }
22248
+ findings.push(...checkEpisodeCraft(\u5267\u672C));
22029
22249
  return findings;
22030
22250
  }
22031
22251
 
@@ -22485,6 +22705,12 @@ var \u6750\u6599\u9884\u7B97 = {
22485
22705
  \u65F6\u95F4\u7EBF\u6700\u8FD1\u6761\u6570: 20,
22486
22706
  \u6587\u98CE\u6700\u8FD1\u6761\u6570: 5
22487
22707
  };
22708
+ var \u9AD8\u8D28\u91CF\u6750\u6599\u9884\u7B97 = {
22709
+ \u4E0A\u4E00\u7AE0\u672B\u5C3E\u5B57\u6570: 8e3,
22710
+ \u6700\u8FD1\u7AE0\u6458\u8981\u6570: 12,
22711
+ \u65F6\u95F4\u7EBF\u6700\u8FD1\u6761\u6570: 60,
22712
+ \u6587\u98CE\u6700\u8FD1\u6761\u6570: 20
22713
+ };
22488
22714
 
22489
22715
  // ../core/src/assembly/supplements.ts
22490
22716
  import * as path42 from "node:path";
@@ -22727,6 +22953,28 @@ function collectWorldbookRels(body) {
22727
22953
  }
22728
22954
  return rels;
22729
22955
  }
22956
+ function listWorldbookFiles(bookRoot) {
22957
+ const wbRoot = resolveInsideBook3(bookRoot, "\u4E16\u754C\u4E66");
22958
+ if (wbRoot === null || !fs38.existsSync(wbRoot)) return [];
22959
+ const out = [];
22960
+ const visit = (absDir, relPrefix) => {
22961
+ let entries;
22962
+ try {
22963
+ entries = fs38.readdirSync(absDir, { withFileTypes: true });
22964
+ } catch {
22965
+ return;
22966
+ }
22967
+ for (const entry of entries) {
22968
+ if (entry.isSymbolicLink()) continue;
22969
+ const rel = `${relPrefix}/${entry.name}`;
22970
+ const abs = path43.join(absDir, entry.name);
22971
+ if (entry.isDirectory()) visit(abs, rel);
22972
+ else if (entry.isFile() && entry.name.endsWith(".md")) out.push(rel);
22973
+ }
22974
+ };
22975
+ visit(wbRoot, "\u4E16\u754C\u4E66");
22976
+ return out.sort((a, b) => a.localeCompare(b, "zh"));
22977
+ }
22730
22978
  function sliceFile(bookRoot, rel) {
22731
22979
  const abs = resolveInsideBook3(bookRoot, rel);
22732
22980
  if (abs === null) return { text: "", missing: true };
@@ -22794,6 +23042,7 @@ function renderLedgerEntry(entry) {
22794
23042
  return lines.join("\n");
22795
23043
  }
22796
23044
  function computeBaseMaterials(bookRoot, input) {
23045
+ const budget = input.\u8D28\u91CF\u6A21\u5F0F === true ? \u9AD8\u8D28\u91CF\u6750\u6599\u9884\u7B97 : \u6750\u6599\u9884\u7B97;
22797
23046
  const dir = paths.\u6750\u6599\u5305\u76EE\u5F55(input.\u5377, input.\u7AE0\u540D);
22798
23047
  const confirmedRel = paths.\u786E\u8BA4\u7EC6\u7EB2(input.\u5377, input.\u7AE0, input.\u7AE0\u540D);
22799
23048
  const confirmedText = readText8(bookRoot, confirmedRel);
@@ -22836,8 +23085,20 @@ function computeBaseMaterials(bookRoot, input) {
22836
23085
  const outlineBody = confirmedDoc.data.body.trim();
22837
23086
  if (outlineBody === "") gaps.push("\u786E\u8BA4\u7EC6\u7EB2\u6B63\u6587\u4E3A\u7A7A");
22838
23087
  const hardLines = parsed.constraints.filter((c) => c.mark === "\u786C").map((c) => c.line);
22839
- const worldRels = collectWorldbookRels(`${outlineBody}
23088
+ const explicitWorldRels = collectWorldbookRels(`${outlineBody}
22840
23089
  ${sourceLines3.join("\n")}`);
23090
+ const worldRelSet = new Set(explicitWorldRels);
23091
+ const worldRels = [...explicitWorldRels];
23092
+ if (input.\u8D28\u91CF\u6A21\u5F0F === true) {
23093
+ for (const rel of listWorldbookFiles(bookRoot)) {
23094
+ if (worldRelSet.has(rel)) continue;
23095
+ const stem = path43.posix.basename(rel, ".md");
23096
+ if (stem.length >= 2 && outlineBody.includes(stem)) {
23097
+ worldRelSet.add(rel);
23098
+ worldRels.push(rel);
23099
+ }
23100
+ }
23101
+ }
22841
23102
  const worldSlices = [];
22842
23103
  for (const rel of worldRels) {
22843
23104
  const sliced = sliceFile(bookRoot, rel);
@@ -22865,6 +23126,7 @@ ${worldText || "\uFF08\u672C\u7AE0\u8FB9\u754C\u5185\u65E0\u5DF2\u751F\u6548\u4E
22865
23126
  let \u8854\u63A5\u5B8C\u6574 = "\u5B8C\u6574";
22866
23127
  const chapters = listChapters(bookRoot).filter((k) => k.\u7AE0 > 0);
22867
23128
  const prev = chapters.find((k) => k.\u7AE0 === input.\u7AE0 - 1) ?? null;
23129
+ let prevBodyText = "";
22868
23130
  if (prev !== null && prev.\u5377 < input.\u5377) {
22869
23131
  const prevVolSummaryRel = paths.\u5377\u6458\u8981(prev.\u5377);
22870
23132
  const prevVolSummary = readText8(bookRoot, prevVolSummaryRel);
@@ -22887,12 +23149,13 @@ ${bodyOnly(prevVolSummary)}`);
22887
23149
  \u8854\u63A5Parts.push("\uFF08\u65E0\u4E0A\u4E00\u7AE0\u5B9A\u7A3F\uFF09");
22888
23150
  \u8854\u63A5\u5B8C\u6574 = "\u7A7A";
22889
23151
  } else {
22890
- \u8854\u63A5Parts.push(tailByParagraph(bodyOnly(prevText), \u6750\u6599\u9884\u7B97.\u4E0A\u4E00\u7AE0\u672B\u5C3E\u5B57\u6570));
23152
+ prevBodyText = bodyOnly(prevText);
23153
+ \u8854\u63A5Parts.push(tailByParagraph(prevBodyText, budget.\u4E0A\u4E00\u7AE0\u672B\u5C3E\u5B57\u6570));
22891
23154
  \u8854\u63A5Sources.push(prevRel);
22892
23155
  }
22893
23156
  }
22894
23157
  const summaries = [];
22895
- for (let no = input.\u7AE0 - \u6750\u6599\u9884\u7B97.\u6700\u8FD1\u7AE0\u6458\u8981\u6570; no < input.\u7AE0; no += 1) {
23158
+ for (let no = input.\u7AE0 - budget.\u6700\u8FD1\u7AE0\u6458\u8981\u6570; no < input.\u7AE0; no += 1) {
22896
23159
  if (no <= 0) continue;
22897
23160
  const ck = chapters.find((k) => k.\u7AE0 === no);
22898
23161
  if (ck === void 0) continue;
@@ -22922,7 +23185,7 @@ ${content}`);
22922
23185
  return ch === null || ch <= input.\u7AE0;
22923
23186
  });
22924
23187
  const tlExcluded = tlEntriesAll.length - tlEntries.length;
22925
- const recent = tlEntries.slice(-\u6750\u6599\u9884\u7B97.\u65F6\u95F4\u7EBF\u6700\u8FD1\u6761\u6570);
23188
+ const recent = tlEntries.slice(-budget.\u65F6\u95F4\u7EBF\u6700\u8FD1\u6761\u6570);
22926
23189
  const terms2 = \u65F6\u7A7A.split(/[,,、;;。!!??\s]+/).map((t2) => t2.trim()).filter((t2) => t2.length >= 2);
22927
23190
  const hits = tlEntries.filter((e) => {
22928
23191
  const content = renderTimelineContent(e);
@@ -22971,14 +23234,36 @@ ${content}`);
22971
23234
  const \u5951\u7EA6Body = \u5951\u7EA6 === null ? null : bodyOnly(\u5951\u7EA6);
22972
23235
  const \u5377\u7EB2Body = \u5377\u7EB2 === null ? null : bodyOnly(\u5377\u7EB2);
22973
23236
  const \u5951\u7EA6\u7981\u533A = \u5951\u7EA6Body === null ? null : extractSection(\u5951\u7EA6Body, "\u521B\u4F5C\u7981\u533A\u4E0E\u4E0D\u53EF\u59A5\u534F\u9879");
23237
+ const contractTitles = input.\u8D28\u91CF\u6A21\u5F0F === true ? ["\u9898\u6750\u4E0E\u8BFB\u8005\u5B9A\u4F4D", "\u6838\u5FC3\u770B\u70B9\u4E0E\u5DEE\u5F02\u5316", "\u9605\u8BFB\u4F53\u9A8C\u4E0E\u60C5\u7EEA\u627F\u8BFA", "\u4E3B\u89D2\u539F\u5219\u4E0E\u5173\u7CFB\u8FB9\u754C", "\u53D9\u4E8B\u65B9\u5F0F\u4E0E\u6587\u98CE\u57FA\u8C03"] : ["\u53D9\u4E8B\u65B9\u5F0F\u4E0E\u6587\u98CE\u57FA\u8C03"];
22974
23238
  const \u6682\u5B9AParts = [];
22975
- for (const title of ["\u53D9\u4E8B\u65B9\u5F0F\u4E0E\u6587\u98CE\u57FA\u8C03"]) {
23239
+ for (const title of contractTitles) {
22976
23240
  const section = \u5951\u7EA6Body === null ? null : extractSection(\u5951\u7EA6Body, title);
22977
23241
  if (section !== null && section !== "") \u6682\u5B9AParts.push(`### \u5951\u7EA6\xB7${title}
22978
23242
 
22979
23243
  ${section}`);
22980
23244
  }
22981
23245
  const \u5377\u7EB2\u53C2\u8003 = findVolumeReferences(\u5377\u7EB2, input.\u5377, input.\u7AE0\u540D);
23246
+ if (input.\u8D28\u91CF\u6A21\u5F0F === true) {
23247
+ const \u9AA8\u67B6Raw = readText8(bookRoot, paths.\u6545\u4E8B\u9AA8\u67B6());
23248
+ const \u9AA8\u67B6Body = \u9AA8\u67B6Raw === null ? "" : bodyOnly(\u9AA8\u67B6Raw);
23249
+ if (\u9AA8\u67B6Body !== "") {
23250
+ \u6682\u5B9AParts.push(`### \u4E0A\u5C42\xB7\u6545\u4E8B\u9AA8\u67B6\u6458\u8981
23251
+
23252
+ ${Array.from(\u9AA8\u67B6Body).slice(0, 1800).join("")}`);
23253
+ }
23254
+ const \u5E03\u5C40Raw = readText8(bookRoot, paths.\u5206\u5377\u5E03\u5C40());
23255
+ const \u5E03\u5C40Body = \u5E03\u5C40Raw === null ? "" : bodyOnly(\u5E03\u5C40Raw);
23256
+ if (\u5E03\u5C40Body !== "") {
23257
+ \u6682\u5B9AParts.push(`### \u4E0A\u5C42\xB7\u5206\u5377\u5E03\u5C40\u6458\u8981
23258
+
23259
+ ${Array.from(\u5E03\u5C40Body).slice(0, 1500).join("")}`);
23260
+ }
23261
+ if (\u5377\u7EB2\u53C2\u8003.\u81EA\u52A8\u5B9A\u4F4D === "\u672A\u547D\u4E2D" && \u5377\u7EB2Body !== null && \u5377\u7EB2Body !== "") {
23262
+ \u6682\u5B9AParts.push(`### \u672C\u5377\u5927\u7EB2\u6982\u89C8\uFF08\u672A\u9010\u7AE0\u7CBE\u786E\u70B9\u540D\uFF0C\u4F9B\u8FDE\u7EED\u63A8\u6F14\u53C2\u8003\uFF09
23263
+
23264
+ ${Array.from(\u5377\u7EB2Body).slice(0, 2200).join("")}`);
23265
+ }
23266
+ }
22982
23267
  const \u6682\u5B9A\u884C = [\u5951\u7EA6Body ?? "", \u5377\u7EB2Body ?? ""].join("\n").split("\n").filter((line) => line.includes("\u3014\u6682\u5B9A\u3015") || line.includes("\u3014\u7559\u767D\u3015"));
22983
23268
  if (\u6682\u5B9A\u884C.length > 0) \u6682\u5B9AParts.push(["### \u6682\u5B9A\u4E0E\u7559\u767D", "", ...\u6682\u5B9A\u884C].join("\n"));
22984
23269
  const \u6682\u5B9ABody = \u6682\u5B9AParts.join("\n\n") || "\uFF08\u65E0\uFF09";
@@ -23013,7 +23298,8 @@ ${section}`);
23013
23298
  \u6587\u98CE\u95EE\u9898.push(`${indexRel}:\u672C\u4E66\u8BB0\u5FC6\u7D22\u5F15\u7F3A\u5931\uFF0C\u5DF2\u4FDD\u7559\u53EF\u8BFB\u6587\u98CE\u6761\u76EE\uFF0C\u4E0D\u80FD\u89C6\u4E3A\u5B8C\u6574\u6750\u6599`);
23014
23299
  }
23015
23300
  const named = styleEntries.filter((e) => outlineBody.includes(`[[${e.\u540D\u79F0}]]`) || outlineBody.includes(e.\u540D\u79F0));
23016
- const chosen = named.length > 0 ? named : styleEntries.slice(-\u6750\u6599\u9884\u7B97.\u6587\u98CE\u6700\u8FD1\u6761\u6570);
23301
+ const recentStyles = styleEntries.slice(-budget.\u6587\u98CE\u6700\u8FD1\u6761\u6570);
23302
+ const chosen = input.\u8D28\u91CF\u6A21\u5F0F === true ? [...named, ...recentStyles.filter((e) => !named.some((n2) => n2.\u540D\u79F0 === e.\u540D\u79F0))] : named.length > 0 ? named : recentStyles;
23017
23303
  const selected = chosen;
23018
23304
  if (selected.length > 0) {
23019
23305
  \u6587\u98CEParts.push(["### \u6761\u76EE\u6B63\u6587", "", ...selected.map((e) => `## ${e.\u540D\u79F0}
@@ -29271,37 +29557,23 @@ var savePolicy = `\u3010\u8349\u7A3F\u4FDD\u5B58\u3011
29271
29557
  \u5B8C\u6574\u7A3F\u6B63\u6587\u6709\u4FEE\u6539\u65F6\u53E6\u5B58\u7A3F<N+1>.md\uFF0C\u7236\u7248\u672C\u6307\u5411\u6E90\u7A3F\uFF0C\u65E7\u5B8C\u6574\u7A3F\u6B63\u6587\u4E0D\u8986\u76D6\u3002
29272
29558
  \u4EC5\u4E3A\u6B63\u786E\u4EA4\u4ED8\u800C\u8C03\u6574\u89D2\u8272\u3001\u9009\u5B9A\u6807\u8BB0\u65F6\uFF0C\u4FDD\u7559\u6B63\u6587\u53CA\u5176\u4F59\u5143\u6570\u636E\uFF0C\u4E0D\u4F2A\u9020\u65B0\u7248\u672C\u3002
29273
29559
  \u62A5\u544A\u51C6\u786E\u4EA4\u4ED8\u8DEF\u5F84\u3001\u65B0\u5199\u6216\u590D\u7528\u3001\u7EDF\u8BA1\u6765\u6E90\u53CA\u672A\u51B3\u9879\u3002\u7BC7\u5E45\u8FBE\u6807\u4E0D\u4EE3\u8868\u5BA1\u8BFB\u901A\u8FC7\u3002`;
29274
- var longWriteRecovery = `\u3010\u957F\u6587\u672C\u5199\u5165\u6062\u590D\u3011
29275
- \u65B0\u6587\u4EF6\u8D85\u8FC7 400 \u5B57\u7B26\u65F6\uFF0C\u9996\u6B21\u4FDD\u5B58\u5C31\u5206\u6BB5\u3002
29276
- \u5148 read \u76EE\u6807\uFF0C\u786E\u8BA4\u4E0D\u5B58\u5728\uFF1B\u5176\u4ED6\u8BFB\u53D6\u9519\u8BEF\u5373\u505C\u3002
29277
- \u5148 write \u6B63\u786E\u5934\u90E8\u548C\u672C\u4EFB\u52A1\u521B\u5EFA\u7684\u552F\u4E00\u968F\u673A ASCII \u5C3E\u6807\u8BB0\u3002
29278
- \u9996\u6B21 write \u7684\u5185\u5BB9\u4E5F\u9650 400 \u5B57\u7B26\u3002
29279
- \u6BCF\u6B21 edit \u53EA\u66FF\u6362\u5C3E\u6807\u8BB0\uFF0Cnew_string \u542B\u6807\u8BB0\u9650 400 \u5B57\u7B26\u3002
29280
- \u6BCF\u6BB5\u6210\u529F\u540E\u624D\u63D0\u4EA4\u4E0B\u4E00\u6BB5\uFF0C\u4E0D\u5E76\u884C\u6539\u540C\u4E00\u6587\u4EF6\u3002
29281
- \u672B\u6BB5\u4E5F\u9650 400 \u5B57\u7B26\uFF0C\u66FF\u6362\u65F6\u79FB\u9664\u6807\u8BB0\u3002
29282
- read \u6587\u4EF6\u672B\u5C3E\uFF0C\u786E\u8BA4\u6807\u8BB0\u5DF2\u79FB\u9664\u3001\u4EA4\u4ED8\u5B8C\u6574\u3002
29283
- \u9519\u8BEF\u4FE1\u606F\uFF1AUnterminated string in JSON\u3002
29284
- \u9519\u8BEF\u4FE1\u606F\uFF1AMalformed response\u3002
29285
- \u51FA\u73B0\u4EFB\u4E00\u9519\u8BEF\uFF0C\u5148 read \u76EE\u6807\u3002
29286
- \u4E0D\u8981\u91CD\u590D\u63D0\u4EA4\u76F8\u540C\u7684\u957F\u53C2\u6570\u3002
29287
- edit \u5931\u8D25\u540E\u5148 read\uFF0C\u53EA\u5728\u5DF2\u5199\u672B\u5C3E\u4E0E\u672C\u4EFB\u52A1\u6807\u8BB0\u660E\u786E\u65F6\u7EED\u5199\u3002
29288
- \u76EE\u6807\u5DF2\u6709\u5185\u5BB9\u4E14\u65E0\u672C\u4EFB\u52A1\u6807\u8BB0\u65F6\uFF0C\u505C\u6B62\u5E76\u62A5\u544A\u4E3B\u63A7\u3002
29289
- \u65E0\u6CD5\u786E\u8BA4\u7EED\u5199\u8FB9\u754C\u65F6\uFF0C\u505C\u6B62\uFF1B\u4E0D\u5F97\u8986\u76D6\u6216\u731C\u8865\u3002
29290
- \u6B64\u65B9\u6CD5\u4EC5\u6784\u5EFA\u65B0\u6587\u672C\uFF0C\u4E0D\u6539\u5DF2\u6709\u6B63\u6587\u3002`;
29560
+ var longWriteRecovery = `\u3010\u957F\u6587\u672C\u5199\u5165\u4E0E\u5F02\u5E38\u5904\u7406\u3011
29561
+ \u6B63\u5E38\u5199\u5165\u8BF7\u76F4\u63A5\u4E00\u6B21\u63D0\u4EA4\u5B8C\u6574\u6B63\u6587\u6216\u5267\u672C\uFF0C\u4FDD\u6301\u53D9\u4E8B\u8BED\u6D41\u3001\u5BF9\u767D\u4EA4\u950B\u4E0E\u620F\u5267\u8282\u594F\u7684\u5B8C\u6574\u8FDE\u8D2F\uFF0C\u4E0D\u8981\u4EBA\u4E3A\u5207\u6210 400 \u5B57\u788E\u7247\u3002
29562
+ \u4EC5\u5F53\u5DE5\u5177\u8FD4\u56DE\u300CUnterminated string in JSON\u300D\u6216\u300CMalformed response\u300D\u7B49\u53C2\u6570\u622A\u65AD\u9519\u8BEF\u65F6\uFF0C\u624D\u542F\u7528\u5206\u6BB5\u6062\u590D\uFF1A
29563
+ 1. \u5148 read \u76EE\u6807\uFF0C\u786E\u8BA4\u5DF2\u5199\u672B\u5C3E\u4E0E\u8FB9\u754C\uFF1B\u4E0D\u8981\u91CD\u590D\u63D0\u4EA4\u76F8\u540C\u7684\u957F\u53C2\u6570\u3002
29564
+ 2. \u6309\u81EA\u7136\u573A\u666F\u6216\u5927\u6BB5\u843D\u987A\u5E8F\u8FFD\u52A0\uFF08\u4F7F\u7528\u968F\u673A ASCII \u5C3E\u6807\u8BB0\u5E76\u9010\u6BB5 edit \u66FF\u6362\uFF09\uFF0C\u672B\u6BB5\u79FB\u9664\u6807\u8BB0\u5E76\u56DE\u8BFB\u786E\u8BA4\u5B8C\u6574\u3002
29565
+ 3. \u76EE\u6807\u5DF2\u6709\u5185\u5BB9\u4E14\u7EED\u5199\u8FB9\u754C\u4E0D\u660E\u65F6\u505C\u6B62\u5E76\u62A5\u544A\u4E3B\u63A7\uFF0C\u4E0D\u5F97\u8986\u76D6\u6216\u731C\u8865\u3002`;
29291
29566
  var rolePolicies = {
29292
29567
  drafting: `\u3010\u5F53\u524D\u89D2\u8272\uFF1A\u6B63\u6587\u8D77\u8349\u3011
29293
- \u7B2C\u4E00\u4EFD\u5B8C\u6574\u7A3F\u4EE5\u5DF2\u786E\u8BA4\u7684\u5951\u7EA6\u7BC7\u5E45\u533A\u95F4\u4E3A\u76EE\u6807\u3002\u672A\u914D\u7F6E\u3001\u672A\u786E\u8BA4\u6216\u914D\u7F6E\u9519\u8BEF\u65F6\u5982\u5B9E\u8BF4\u660E\uFF0C\u4E0D\u7F16\u9020\u8303\u56F4\u3002
29294
- \u4E2D\u9014\u68C0\u67E5\u53EF\u9009\uFF1A\u5728\u81EA\u7136\u60C5\u8282\u8282\u70B9\u4FDD\u5B58\u540C\u76EE\u5F55\u7A3F<N>.\u8D77\u8349\u4E2D.txt\uFF0C\u4F9D\u636E\u7D2F\u8BA1\u5B57\u6570\u7EE7\u7EED\u5199\u4F5C\u3002
29295
- \u6682\u5B58\u4E0D\u662F\u5B8C\u6574\u7A3F\uFF0C\u4E0D\u5360\u7A3F\u53F7\uFF0C\u672A\u8FBE\u5230\u6574\u7AE0\u4E0B\u9650\u4E0D\u662F\u95EE\u9898\u3002\u6682\u5B58\u4FDD\u7559\u4F9B\u6062\u590D\uFF0C\u4E0D\u5F53\u6210\u6B63\u5F0F\u4EA4\u4ED8\u3002
29568
+ \u56F4\u7ED5\u4EBA\u7269\u6B32\u671B\u3001\u538B\u529B\u5347\u7EA7\u4E0E\u5177\u4F53\u573A\u666F\u7EC6\u8282\u5C55\u5F00\u53D9\u4E8B\uFF0C\u7528\u52A8\u4F5C\u3001\u5BF9\u767D\u548C\u611F\u5B98\u7EC6\u8282\u628A\u620F\u6F14\u51FA\u6765\uFF0C\u907F\u514D\u7A7A\u6D1E\u6982\u62EC\u548C\u5957\u8BDD\u5806\u780C\u3002
29569
+ \u7B2C\u4E00\u4EFD\u5B8C\u6574\u7A3F\u4EE5\u5951\u7EA6\u7BC7\u5E45\u533A\u95F4\u4E3A\u76EE\u6807\uFF1B\u672A\u914D\u7F6E\u6216\u672A\u786E\u8BA4\u65F6\u4E0D\u7F16\u9020\u8303\u56F4\u3002
29570
+ \u4E2D\u9014\u68C0\u67E5\u53EF\u9009\uFF1A\u9700\u8981\u65F6\u53EF\u4FDD\u5B58\u540C\u76EE\u5F55\u7A3F<N>.\u8D77\u8349\u4E2D.txt\u3002
29296
29571
  \u5B8C\u6210\u540E\u4FDD\u5B58\u6B63\u5F0F\u7A3F<N>.md\uFF0C\u5E26\u9F50 frontmatter \u548C\u300C## \u8349\u7A3F\u5019\u9009\u4E8B\u5B9E\u300D\u3002
29297
- \u9996\u4EFD\u5B8C\u6574\u7A3F\u5728\u8303\u56F4\u5185\u5C31\u7ED3\u675F\uFF1B\u8D8A\u754C\u6700\u591A\u505A\u4E00\u8F6E\u4EC5\u4E3A\u7BC7\u5E45\u7684\u8C03\u6574\uFF0C\u4E5F\u53EF\u4FDD\u7559\u73B0\u7A3F\u8BF4\u660E\u539F\u56E0\u3002
29298
- \u8C03\u6574\u4FDD\u62A4\u5DF2\u786E\u8BA4\u4E8B\u5B9E\u3001\u91CD\u8981\u9009\u62E9\u3001\u4EA4\u6613\u6761\u4EF6\u3001\u52A8\u4F5C\u56E0\u679C\u548C\u6709\u529F\u80FD\u7EC6\u8282\uFF0C\u4E0D\u673A\u68B0\u586B\u5145\u6216\u5220\u53E5\u3002
29299
- \u4FEE\u6B63\u7A3F\u65B0\u589E\u7A3F\u53F7\u548C\u7236\u7248\u672C\uFF0C\u6700\u7EC8\u4EA4\u4ED8\u7A3F\u9009\u5B9A\u4E3A true\uFF0C\u65E7\u9009\u5B9A\u6807\u8BB0\u6E05\u4E3A false\u3002
29300
- \u6700\u591A\u4E00\u6B21\u7BC7\u5E45\u8C03\u6574\u540E\u7ED3\u675F\u8D77\u8349\uFF0C\u4ECD\u8D8A\u754C\u4E5F\u5982\u5B9E\u4EA4\u63A5\u3002\u65E7\u7A3F\u6807\u8BB0\u7F16\u8F91\u7684\u56DE\u6267\u4E0D\u89E6\u53D1\u989D\u5916\u8C03\u6574\u3002`,
29572
+ \u9996\u4EFD\u5B8C\u6574\u7A3F\u5728\u8303\u56F4\u5185\u5C31\u7ED3\u675F\uFF1B\u8D8A\u754C\u65F6\u6700\u591A\u4E00\u6B21\u7BC7\u5E45\u8C03\u6574\uFF08\u4FDD\u62A4\u56E0\u679C\u3001\u5BF9\u767D\u950B\u8292\u4E0E\u6838\u5FC3\u7EC6\u8282\uFF0C\u4E0D\u673A\u68B0\u6CE8\u6C34\u6216\u786C\u5220\uFF09\uFF0C\u4ECD\u8D8A\u754C\u5982\u5B9E\u4EA4\u63A5\u3002`,
29301
29573
  polish: `\u3010\u5F53\u524D\u89D2\u8272\uFF1A\u6DA6\u8272\u3011
29302
- \u53EA\u6539\u6709\u660E\u786E\u95EE\u9898\u7684\u8868\u8FBE\uFF0C\u4FDD\u62A4\u4E8B\u5B9E\u3001\u542B\u4E49\u3001\u4FE1\u606F\u6765\u6E90\u548C\u786E\u5B9A\u7A0B\u5EA6\uFF0C\u4E0D\u4E3A\u63A5\u8FD1\u76EE\u6807\u5B57\u6570\u8FFD\u52A0\u538B\u7F29\u3002
29303
- \u5019\u9009\u4E8B\u5B9E\u6BB5\u539F\u6837\u4FDD\u7559\u3002\u6BCF\u6279\u6709\u5B9E\u9645\u4FEE\u6539\u624D\u7559\u65B0\u7A3F\uFF0C\u65E0\u4FEE\u6539\u590D\u7528\u6E90\u7A3F\u5E76\u7EE7\u7EED\u68C0\u67E5\u540E\u7EED\u6279\u6B21\uFF0C\u4E0D\u5F3A\u5236\u751F\u6210\u4E24\u7248\u3002
29304
- \u4FDD\u771F\u98CE\u9669\u4E0D\u6E05\u7A7A\uFF1B\u6709\u672A\u51B3\u98CE\u9669\u7684\u7A3F\u4E0D\u63D0\u5347\u4E3A\u5F85\u5BA1\u7A3F\u3002\u5177\u4F53\u6279\u6B21\u4E0E\u4EA4\u4ED8\u5143\u6570\u636E\u6309\u4E3B\u63A7\u63D0\u4F9B\u7684\u5DE5\u5E8F\u6267\u884C\u3002`,
29574
+ \u4FDD\u62A4\u6838\u5FC3\u5267\u60C5\u4E8B\u5B9E\u3001\u56E0\u679C\u903B\u8F91\u4E0E\u4FE1\u606F\u8FB9\u754C\u4E0D\u53D8\uFF1B\u5728\u6B64\u524D\u63D0\u4E0B\uFF0C\u653E\u624B\u63D0\u5347\u753B\u9762\u8D28\u611F\u3001\u53E5\u6BB5\u547C\u5438\u3001\u5BF9\u767D\u6F5C\u53F0\u8BCD\u4E0E\u4EBA\u7269\u58F0\u97F3\u8FA8\u8BC6\u5EA6\u3002
29575
+ \u628A\u5E72\u762A\u7684\u6982\u62EC\u5F0F\u53D9\u8FF0\u3001\u91CD\u590D\u5FC3\u7406\u72EC\u767D\u548C\u5178\u578B AI \u5957\u8BDD\u6539\u5199\u4E3A\u751F\u52A8\u514B\u5236\u7684\u52A8\u4F5C\u4E0E\u4EA4\u950B\uFF0C\u4F46\u4FDD\u7559\u539F\u7A3F\u771F\u6B63\u6709\u6548\u7684\u72EC\u7279\u8868\u8FBE\u3002
29576
+ \u5019\u9009\u4E8B\u5B9E\u6BB5\u539F\u6837\u4FDD\u7559\u3002\u6BCF\u6279\u6709\u5B9E\u9645\u4FEE\u6539\u624D\u7559\u65B0\u7248\uFF0C\u65E0\u95EE\u9898\u5219\u590D\u7528\u6E90\u7A3F\u5E76\u7EE7\u7EED\u68C0\u67E5\u540E\u7EED\u6279\u6B21\u3002\u5177\u4F53\u6279\u6B21\u4E0E\u4EA4\u4ED8\u5143\u6570\u636E\u6309\u4E3B\u63A7\u63D0\u4F9B\u7684\u5DE5\u5E8F\u6267\u884C\u3002`,
29305
29577
  revision: `\u3010\u5F53\u524D\u89D2\u8272\uFF1A\u6539\u7A3F\u3011
29306
29578
  \u6539\u7A3F\u53EA\u6309\u5DF2\u6388\u6743\u5904\u7F6E\u8FD4\u56DE\u6574\u7A3F\u65B0\u7248\u53CA\u300C\u53D1\u73B0\u9879\u2192\u6539\u52A8\u300D\u6620\u5C04\uFF0C\u4E0D\u76F4\u63A5\u5199\u6587\u4EF6\uFF0C\u7531\u4E3B\u63A7\u6279\u91CF\u843D\u5B9E\u3002`,
29307
29579
  review: `\u3010\u5F53\u524D\u89D2\u8272\uFF1A\u5BA1\u8BFB\u3011
@@ -29309,21 +29581,17 @@ var rolePolicies = {
29309
29581
  settle: `\u3010\u5F53\u524D\u89D2\u8272\uFF1A\u6C89\u6DC0\u5BF9\u8D26\u3011
29310
29582
  \u6C89\u6DC0\u5BF9\u8D26\u53EA\u8BFB\u4E0D\u5199\uFF0C\u6309\u4EFB\u52A1\u5E95\u672C\u8FD4\u56DE\u5019\u9009\uFF1B\u8BA1\u5212\u3001\u63A8\u6D4B\u548C\u4EBA\u7269\u8BC1\u8A00\u4E0D\u5192\u5145\u5DF2\u53D1\u751F\u4E8B\u5B9E\uFF0C\u4E0D\u76F4\u63A5\u4FEE\u6539\u8D26\u672C\u3002`,
29311
29583
  screenplay: `\u3010\u5F53\u524D\u89D2\u8272\uFF1A\u7535\u5F71\u5267\u672C\u6539\u7F16\u3011
29312
- \u53EA\u5728\u5951\u7EA6\u8F93\u51FA\u5F62\u6001=\u7535\u5F71\u5267\u672C\u65F6\u8D70\u672C\u7BA1\u7EBF\u3002
29313
- \u5267\u672C\u6309\u6545\u4E8B\u7A3F\u3001\u5206\u573A\u5927\u7EB2\u3001\u5267\u672C\u8349\u7A3F\u3001\u5BA1\u8BFB\u56DB\u6B65\u63A8\u8FDB\u3002
29314
- \u4E2D\u95F4\u7A3F\u653E\u8349\u7A3F\u533A/\u5267\u672C/\uFF0C\u6587\u4EF6\u540D\u4F9D\u6B21\u4E3A\u6545\u4E8B\u7A3F.md\u3001\u5206\u573A\u5927\u7EB2.md\u3001\u5267\u672C\u8349\u7A3F.md\u3002
29315
- \u5B9A\u7A3F\u53EA\u8BA4\u5267\u672C/\u7535\u5F71/\u5267\u672C.md\u3002
29316
- \u573A\u666F\u6807\u9898\u5199\u4E3A\u201C\u573A\u53F7 INT./EXT. \u5730\u70B9 - \u65F6\u95F4\u201D\u3002
29317
- \u52A8\u4F5C\u884C\u7528\u73B0\u5728\u65F6\uFF0C\u53EA\u5199\u53EF\u89C1\u6216\u53EF\u542C\u5185\u5BB9\u3002
29584
+ \u53EA\u5728\u5951\u7EA6\u8F93\u51FA\u5F62\u6001=\u7535\u5F71\u5267\u672C\u65F6\u8D70\u672C\u7BA1\u7EBF\uFF0C\u6CE8\u91CD\u89C6\u89C9\u5316\u52A8\u4F5C\u3001\u6F5C\u53F0\u8BCD\u5BF9\u767D\u4E0E\u4E09\u5E55\u620F\u5267\u5F20\u529B\u3002
29585
+ \u5267\u672C\u6309\u6545\u4E8B\u7A3F\u3001\u5206\u573A\u5927\u7EB2\u3001\u5267\u672C\u8349\u7A3F\u3001\u5BA1\u8BFB\u63A8\u8FDB\uFF1B\u4E2D\u95F4\u7A3F\u653E\u8349\u7A3F\u533A/\u5267\u672C/\uFF0C\u5B9A\u7A3F\u53EA\u8BA4\u5267\u672C/\u7535\u5F71/\u5267\u672C.md\u3002
29586
+ \u573A\u666F\u6807\u9898\u5199\u4E3A\u201C\u573A\u53F7 INT./EXT. \u5730\u70B9 - \u65F6\u95F4\u201D\uFF0C\u52A8\u4F5C\u884C\u7528\u73B0\u5728\u65F6\uFF0C\u53EA\u5199\u53EF\u89C1\u6216\u53EF\u542C\u5185\u5BB9\u3002
29318
29587
  \u89D2\u8272\u540D\u5168\u5927\u5199\uFF0C\u540E\u63A5\u53F0\u8BCD\u548C\u62EC\u53F7\u63D0\u793A\uFF1B\u505C\u987F\u53EA\u7528 (pause)\uFF0C\u4E0D\u7528 (beat)\u3002
29319
29588
  \u97F3\u6548\u5199\u8FDB\u52A8\u4F5C\u884C\uFF0C\u4E0D\u7528 SFX:/MUSIC: \u72EC\u5360\u884C\uFF1B\u97F3\u4E50\u4E0E\u955C\u5934\u63D0\u793A\u4E0D\u8FDB\u7F16\u5267\u5C42\u3002
29320
- \u5BA1\u8BFB\u4E09\u6A21\u5757\u8DD1\u5B8C\u518D\u5B9A\u7A3F\uFF0C\u4EFB\u4E00\u9AD8\u7EA7\u522B\u53D1\u73B0\u9879\u5373\u963B\u65AD\uFF0C\u4E0D\u628A\u5F85\u5199\u5360\u4F4D\u5F53\u6210\u7A3F\u3002`,
29589
+ \u5BA1\u8BFB\u65E0\u9AD8\u7EA7\u522B\u963B\u65AD\u9879\u4E14\u65E0\u3010\u5F85\u5199\u3011\u5360\u4F4D\u540E\u518D\u5B9A\u7A3F\u3002`,
29321
29590
  shortdrama: `\u3010\u5F53\u524D\u89D2\u8272\uFF1A\u77ED\u5267\u7BA1\u7EBF\u3011
29322
- \u53EA\u5728\u5951\u7EA6\u8F93\u51FA\u5F62\u6001=\u77ED\u5267\u65F6\u8D70\u672C\u7BA1\u7EBF\u3002\u6309\u5206\u96C6\u94A9\u5B50/\u723D\u70B9\u5927\u7EB2\u2192\u5355\u96C6\u5267\u672C\u2192\u5BA1\u8BFB\u8D70\uFF0C\u6BCF\u96C6\u4E00\u4E2A\u6838\u5FC3\u60F3\u6CD5\uFF1B\u5B9A\u7A3F\u53EA\u8BA4\u5267\u672C/\u77ED\u5267/\u96C6001.md \u8D77\u3002
29323
- \u7AD6\u5C4F\u4E0E\u6A2A\u5C4F\u8282\u594F\u5206\u5F00\uFF0C\u4E0D\u6DF7\u7528\u3002\u7AD6\u5C4F\u6BCF\u96C6 60\u2013120 \u79D2\uFF0C5 \u79D2\u5185\u8D77\u51B2\u7A81\u3002
29324
- \u6BCF 20\u201330 \u79D2\u5B89\u6392\u53CD\u8F6C\uFF0C\u7ED3\u5C3E 5\u201310 \u79D2\u7559\u60AC\u5FF5\u3002
29325
- \u6A2A\u5C4F\u6BCF\u96C6 10\u201320 \u5206\u949F\uFF0C\u5177\u5907\u8D77\u627F\u8F6C\u5408\u3002
29326
- \u6BCF\u96C6\u8DD1\u8282\u62CD\u68C0\u67E5\u5668\uFF0C\u4E0D\u901A\u8FC7\u7684\u96C6\u4E0D\u8FDB\u5B9A\u7A3F\u3002\u53F0\u8BCD\u8981\u77ED\uFF08\u4E00\u884C\u7EA6 <12 \u5B57\uFF09\uFF0C\u53F0\u8BCD\u5373\u884C\u52A8\u3002`
29591
+ \u53EA\u5728\u5951\u7EA6\u8F93\u51FA\u5F62\u6001=\u77ED\u5267\u65F6\u8D70\u672C\u7BA1\u7EBF\u3002\u4E00\u96C6\u56F4\u7ED5\u4E00\u4E2A\u6838\u5FC3\u60F3\u6CD5\u5199\u900F\uFF0C\u4EBA\u7269\u4EA4\u950B\u950B\u5229\u3001\u6F5C\u53F0\u8BCD\u4E0E\u53CD\u5E94\u5177\u4F53\uFF0C\u4E0D\u8981\u5199\u6210\u5E72\u762A\u53E3\u53F7\u3002
29592
+ \u7AD6\u5C4F 60\u2013120 \u79D2\uFF082\u20134 \u573A\uFF0C3\u20135 \u79D2\u8FDB\u51B2\u7A81\u3001\u7ED3\u5C3E\u7559\u94A9\u5B50\uFF09\uFF1B\u6A2A\u5C4F 10\u201320 \u5206\u949F\uFF08\u6CE8\u91CD\u8D77\u627F\u8F6C\u5408\u3001\u94FA\u57AB\u4E0E\u60C5\u7EEA\u5F20\u529B\uFF09\u3002
29593
+ \u4F7F\u7528\u65B0\u7248\u5206\u955C\u683C\u5F0F\uFF08\u573A\u5934\u300C\u96C6-\u573A \u65E5/\u591C\uFF0F\u5185/\u5916 \u5730\u70B9\u300D\u3001\u4EBA\u7269\u884C\u3001\u573A\u666F\u73AF\u5883\u3001\u25B3\u3010\u955C\u5934NN\uFF5C\u2026\u3011\u3001\u5BF9\u767D\u3001\u6DE1\u51FA\u4E0E\u8282\u62CD\u8868\uFF09\uFF0C\u505C\u987F\u53EA\u7528 (pause)\u3002
29594
+ \u5B9A\u7A3F\u53EA\u8BA4\u5267\u672C/\u77ED\u5267/\u96C6001.md \u8D77\uFF0C\u6BCF\u96C6\u8FC7\u8282\u62CD\u68C0\u67E5\u4E0E\u5BA1\u8BFB\u540E\u5165\u6863\u3002`
29327
29595
  };
29328
29596
  function workerPolicyFor(role2) {
29329
29597
  const canWrite = role2 === "drafting" || role2 === "polish" || role2 === "screenplay" || role2 === "shortdrama";
@@ -29403,17 +29671,22 @@ var NOVEL_TOOL_NAMES = [
29403
29671
  "novel_note_pending",
29404
29672
  "novel_get_book_progress",
29405
29673
  "novel_editor_suggest",
29406
- // 影视剧扩展(muse-dev 阶段 2 电影剧本 / 阶段 3 短剧)
29674
+ "novel_authorize_batch",
29675
+ // 影视剧扩展(muse-dev 阶段 2 电影剧本 / 阶段 3 短剧 + 半自动落盘/定稿闭环)
29407
29676
  "novel_screenplay_check_contract",
29408
29677
  "novel_screenplay_validate_story",
29409
29678
  "novel_screenplay_build_outline",
29410
29679
  "novel_screenplay_build_draft",
29411
29680
  "novel_screenplay_review",
29412
29681
  "novel_screenplay_render",
29682
+ "novel_screenplay_save_draft",
29683
+ "novel_screenplay_settle",
29413
29684
  "novel_shortdrama_plan_episodes",
29414
29685
  "novel_shortdrama_render_episode",
29415
29686
  "novel_shortdrama_check_beats",
29416
- "novel_shortdrama_review_episode"
29687
+ "novel_shortdrama_review_episode",
29688
+ "novel_shortdrama_settle_episode",
29689
+ "novel_shortdrama_save_script"
29417
29690
  ];
29418
29691
  var WRITING_DELEGATE_TOOL = "novel_delegate";
29419
29692
  var NOVEL_CONDITIONAL_TOOL_NAMES = [WRITING_DELEGATE_TOOL];
@@ -30424,6 +30697,124 @@ function createReferenceTools(deps) {
30424
30697
  ].map(actionTool);
30425
30698
  }
30426
30699
 
30700
+ // src/screenplay-tools.ts
30701
+ import * as fs55 from "node:fs";
30702
+ import * as path67 from "node:path";
30703
+
30704
+ // src/approval-snapshot.ts
30705
+ import * as fs53 from "node:fs";
30706
+ import * as path65 from "node:path";
30707
+ import { createHash as createHash19 } from "node:crypto";
30708
+ function captureApprovalFiles(root, relatives, request) {
30709
+ try {
30710
+ const files = [];
30711
+ const visit = (relative12) => {
30712
+ const target = authorDocumentPath(root, relative12);
30713
+ try {
30714
+ const stat = fs53.statSync(target);
30715
+ if (stat.isDirectory()) {
30716
+ const names = fs53.readdirSync(target).sort();
30717
+ files.push([relative12 + "/", JSON.stringify(names)]);
30718
+ for (const name3 of names) visit(path65.posix.join(relative12, name3));
30719
+ } else if (stat.isFile()) {
30720
+ files.push([relative12, createHash19("sha256").update(fs53.readFileSync(target)).digest("hex")]);
30721
+ } else throw new Error(`\u4E0D\u662F\u666E\u901A\u6587\u4EF6\u6216\u76EE\u5F55\uFF1A${relative12}`);
30722
+ } catch (error) {
30723
+ if (error.code === "ENOENT") {
30724
+ files.push([relative12, null]);
30725
+ return;
30726
+ }
30727
+ throw error;
30728
+ }
30729
+ };
30730
+ for (const relative12 of [...new Set(relatives)].sort()) visit(relative12);
30731
+ return { ok: true, fingerprint: createHash19("sha256").update(JSON.stringify([canonicalizePath(root), request, files])).digest("hex") };
30732
+ } catch (error) {
30733
+ return { ok: false, reason: `\u65E0\u6CD5\u6838\u5BF9\u4F5C\u8005\u88C1\u51B3\u5185\u5BB9\uFF1A${error instanceof Error ? error.message : String(error)}` };
30734
+ }
30735
+ }
30736
+
30737
+ // src/tool-failure.ts
30738
+ var NEXT_STEP = {
30739
+ "invalid-argument": "\u6309 reason \u4FEE\u6B63\u53C2\u6570\u540E\u91CD\u65B0\u8C03\u7528\u3002",
30740
+ "book-not-found": "\u8C03\u7528 novel_select_book \u6838\u5BF9\u4E66\u76EE\u548C\u4E66id\uFF0C\u518D\u91CD\u65B0\u8C03\u7528\u3002",
30741
+ "book-locked": "\u7B49\u51E0\u79D2\u540E\u91CD\u8BD5\u4E00\u6B21\u3002\u4ECD\u7136\u5931\u8D25\u65F6\uFF0C\u8BF7\u4F5C\u8005\u68C0\u67E5\u662F\u5426\u5F00\u7740\u5176\u4ED6\u5199\u4F5C\u7A97\u53E3\u3002",
30742
+ "lock-interrupted": "\u7B49 30 \u79D2\u540E\u91CD\u8BD5\u4E00\u6B21\u3002\u786E\u8BA4\u6301\u6709\u8FDB\u7A0B\u9000\u51FA\u7684 acquire.lock \u4F1A\u81EA\u52A8\u56DE\u6536\uFF1B\u5F52\u5C5E\u4E0D\u660E\u65F6\uFF0C\u8BF7\u4F5C\u8005\u6838\u5BF9\u5E76\u786E\u8BA4\u6CA1\u6709\u5176\u4ED6\u5199\u4F5C\u7A97\u53E3\u540E\u518D\u6E05\u7406\u3002",
30743
+ "runtime-link": "\u672C\u6B21\u6CA1\u6709\u5199\u5165\u3002\u8BF7\u4F5C\u8005\u6838\u5BF9 reason \u4E2D\u7684\u8FD0\u884C\u8DEF\u5F84\uFF0C\u4FDD\u7559\u8BC1\u636E\uFF0C\u4E0D\u8981\u7528\u94FE\u63A5\u66FF\u4EE3\u4E66\u4ED3\u8FD0\u884C\u76EE\u5F55\u3002",
30744
+ "transaction-conflict": "\u5148\u628A\u9694\u79BB\u4E8B\u52A1\u7684\u5907\u4EFD\u548C\u5F53\u524D\u6587\u4EF6\u5448\u62A5\u4F5C\u8005\u3002\u5904\u7406\u51B2\u7A81\u540E\u518D\u5199\u5165\uFF0C\u76EE\u6807\u672A\u77E5\u65F6\u6682\u505C\u6240\u6709\u5199\u5165\u3002",
30745
+ "author-declined": "\u4E0D\u8981\u91CD\u65B0\u8C03\u7528\u672C\u5DE5\u5177\u3002\u5148\u95EE\u4F5C\u8005\u8981\u6539\u4EC0\u4E48\uFF0C\u518D\u6309\u56DE\u7B54\u56DE\u5230\u5BF9\u5E94\u8282\u70B9\u3002",
30746
+ "author-cancelled": "\u672C\u6B21\u6CA1\u6709\u5199\u5165\u3002\u7B49\u4F5C\u8005\u660E\u786E\u6279\u51C6\u540E\uFF0C\u518D\u8C03\u7528\u672C\u5DE5\u5177\u3002",
30747
+ "approval-stale": "\u65E7\u6279\u51C6\u5DF2\u5931\u6548\u3002\u91CD\u65B0\u5448\u62A5\u4F5C\u8005\uFF0C\u83B7\u5F97\u65B0\u7684\u6279\u51C6\u540E\u518D\u8C03\u7528\u3002",
30748
+ "source-conflict": "\u4E0D\u8981\u7528\u76F8\u540C\u53C2\u6570\u91CD\u8BD5\u3002\u628A\u51B2\u7A81\u539F\u6587\u5448\u62A5\u4F5C\u8005\uFF0C\u7531\u4F5C\u8005\u51B3\u5B9A\u4FDD\u7559\u54EA\u4E00\u4EFD\u3002",
30749
+ "parse-error": "\u6309 reason \u6307\u51FA\u7684\u4F4D\u7F6E\u4FEE\u6B63\u5185\u5BB9\uFF0C\u518D\u91CD\u65B0\u8C03\u7528\u4E00\u6B21\u3002\u4ECD\u7136\u5931\u8D25\u65F6\uFF0C\u628A reason \u539F\u6587\u544A\u8BC9\u4F5C\u8005\u3002",
30750
+ "host-unavailable": "\u672C\u6B21\u6CA1\u6709\u5199\u5165\u3002\u8BF7\u4F5C\u8005\u91CD\u542F\u5DE5\u4F5C\u53F0\uFF0C\u6216\u6838\u5BF9 DSH \u7248\u672C\u662F\u5426\u4E0E\u63D2\u4EF6\u914D\u5957\u3002",
30751
+ "partial-commit": "\u6587\u4EF6\u5DF2\u5199\u5165\u4F46\u8FD8\u6CA1\u6709\u63D0\u4EA4\u3002\u7528\u76F8\u540C\u53C2\u6570\u91CD\u65B0\u8C03\u7528\u672C\u5DE5\u5177\u5373\u53EF\u8865\u63D0\u4EA4\u3002",
30752
+ internal: "\u4E0D\u8981\u7528\u76F8\u540C\u53C2\u6570\u53CD\u590D\u91CD\u8BD5\u3002\u628A reason \u539F\u6587\u544A\u8BC9\u4F5C\u8005\u3002"
30753
+ };
30754
+ function toolFailure(code, reason, next = NEXT_STEP[code]) {
30755
+ return { ok: false, code, reason, next };
30756
+ }
30757
+ function notApproved(reason) {
30758
+ return /取消|abort/i.test(reason) ? toolFailure("author-cancelled", `\u4F5C\u8005\u88C1\u51B3\u5DF2\u53D6\u6D88\uFF0C\u6CA1\u6709\u505A\u51FA\u51B3\u5B9A\uFF08${reason}\uFF09\uFF0C\u672C\u6B21\u6CA1\u6709\u5199\u5165`) : toolFailure("author-declined", `\u672A\u83B7\u4F5C\u8005\u6279\u51C6\uFF1A${reason}`);
30759
+ }
30760
+ function errorText3(error) {
30761
+ return error instanceof Error ? error.message : String(error);
30762
+ }
30763
+ function expectedFailure(error) {
30764
+ const seen = /* @__PURE__ */ new Set();
30765
+ for (let current = error; current instanceof Error && !seen.has(current); current = current.cause) {
30766
+ seen.add(current);
30767
+ if (current instanceof BookLockError || current instanceof TransactionConflictError) return toolFailure(current.code, errorText3(error));
30768
+ if (current instanceof SettlementParseError) return toolFailure("parse-error", errorText3(error));
30769
+ }
30770
+ return void 0;
30771
+ }
30772
+ function failureFrom(error, prefix = "") {
30773
+ const known = expectedFailure(error);
30774
+ const reason = `${prefix}${errorText3(error)}`;
30775
+ return known === void 0 ? toolFailure(classifyReason(reason), reason) : { ...known, reason };
30776
+ }
30777
+ var RULES2 = [
30778
+ ["lock-interrupted", /锁获取曾中断|acquire\.lock/],
30779
+ ["book-locked", /书仓写入锁定中|书仓.*锁定/],
30780
+ ["partial-commit", /提交失败|未形成提交|已落盘但未提交/],
30781
+ ["author-declined", /未获作者批准|作者.{0,4}(驳回|拒绝)/],
30782
+ ["author-cancelled", /裁决.{0,2}取消|作者关闭了裁决|作者已取消/],
30783
+ ["approval-stale", /等待作者裁决期间|旧批准/],
30784
+ ["source-conflict", /冲突|已隔离|只增不改|已被另行修改/],
30785
+ ["host-unavailable", /裁决窗口|工作范围未就绪|未配置|不可用|尚未就绪/],
30786
+ ["book-not-found", /书id|bookId|书目/],
30787
+ ["parse-error", /解析失败|未分类正文|无法解析|第 \d+ 行:/],
30788
+ ["invalid-argument", /必须|不能为空|不得|非法|不合法|必填|为空|缺少|不存在|过长|超过|不支持|须/]
30789
+ ];
30790
+ function classifyReason(reason) {
30791
+ for (const [code, pattern2] of RULES2) if (pattern2.test(reason)) return code;
30792
+ return "internal";
30793
+ }
30794
+ function normalizeFailure(result) {
30795
+ if (result === null || typeof result !== "object") return result;
30796
+ const value = result;
30797
+ if (value["ok"] !== false) return result;
30798
+ let reason = typeof value["reason"] === "string" ? value["reason"] : void 0;
30799
+ if (reason === void 0 || reason.trim() === "") {
30800
+ reason = chineseReason(value["\u539F\u56E0"]) ?? chineseReason(value["\u95EE\u9898"]);
30801
+ }
30802
+ if (reason === void 0 || reason.trim() === "") return result;
30803
+ const known = typeof value["code"] === "string" && value["code"] in NEXT_STEP ? value["code"] : void 0;
30804
+ const code = typeof value["code"] === "string" ? value["code"] : classifyReason(reason);
30805
+ const next = typeof value["next"] === "string" && value["next"] !== "" ? value["next"] : NEXT_STEP[known ?? (code in NEXT_STEP ? code : classifyReason(reason))];
30806
+ return { ...value, reason, code, next };
30807
+ }
30808
+ function chineseReason(field) {
30809
+ if (typeof field === "string" && field.trim() !== "") return field;
30810
+ if (Array.isArray(field) && field.length > 0) return field.map(String).join("\uFF1B");
30811
+ return void 0;
30812
+ }
30813
+ var FAILURE_FIELDS = {
30814
+ code: { type: "string", description: "\u5931\u8D25\u7C7B\u522B\uFF08\u5982 invalid-argument\u3001book-locked\u3001author-declined\uFF09\uFF0C\u6210\u529F\u65F6\u4E0D\u8FD4\u56DE" },
30815
+ next: { type: "string", description: "\u5931\u8D25\u540E\u7684\u4E0B\u4E00\u6B65\uFF0C\u6210\u529F\u65F6\u4E0D\u8FD4\u56DE" }
30816
+ };
30817
+
30427
30818
  // ../review/src/finding.ts
30428
30819
  function makeFinding(partial) {
30429
30820
  const \u5904\u7F6E\u72B6\u6001 = partial.\u5904\u7F6E\u72B6\u6001 ?? "\u5F85\u5904\u7406";
@@ -30654,8 +31045,8 @@ function registerDefaultChecks() {
30654
31045
  }
30655
31046
 
30656
31047
  // ../review/src/run.ts
30657
- import * as fs53 from "node:fs";
30658
- import * as path65 from "node:path";
31048
+ import * as fs54 from "node:fs";
31049
+ import * as path66 from "node:path";
30659
31050
 
30660
31051
  // ../review/src/film-drama.ts
30661
31052
  var \u5267\u672C\u5BF9\u767D\u5BA1\u8BFB\u540D = "\u5267\u672C\u5BF9\u767D\u5BA1\u8BFB";
@@ -30860,7 +31251,7 @@ function computeEpisodeFindings(input) {
30860
31251
  // ../review/src/run.ts
30861
31252
  function readText11(root, rel) {
30862
31253
  try {
30863
- return fs53.readFileSync(path65.join(root, rel), "utf-8");
31254
+ return fs54.readFileSync(path66.join(root, rel), "utf-8");
30864
31255
  } catch {
30865
31256
  return null;
30866
31257
  }
@@ -31319,12 +31710,12 @@ function createScreenplayTools(deps = {}) {
31319
31710
  },
31320
31711
  render: (_args, value) => renderOutput(value)
31321
31712
  },
31322
- execute: (args) => {
31713
+ execute: (args, exec) => {
31323
31714
  let \u5E02\u573A = enumArg(args, "\u5E02\u573A");
31324
31715
  let \u8F93\u51FA\u5F62\u6001 = enumArg(args, "\u8F93\u51FA\u5F62\u6001");
31325
31716
  const bookId2 = enumArg(args, "bookId");
31326
31717
  if (bookId2 !== void 0 && deps.bookRootOfBookId !== void 0 && deps.readContractFields !== void 0) {
31327
- const root = deps.bookRootOfBookId(bookId2);
31718
+ const root = deps.bookRootOfBookId(bookId2, exec?.agent);
31328
31719
  const fields = root === void 0 ? void 0 : deps.readContractFields(root);
31329
31720
  if (typeof fields?.\u5E02\u573A === "string") \u5E02\u573A = fields.\u5E02\u573A;
31330
31721
  if (typeof fields?.\u8F93\u51FA\u5F62\u6001 === "string") \u8F93\u51FA\u5F62\u6001 = fields.\u8F93\u51FA\u5F62\u6001;
@@ -31527,93 +31918,234 @@ function createScreenplayTools(deps = {}) {
31527
31918
  \u539F\u56E0: []
31528
31919
  };
31529
31920
  }
31921
+ },
31922
+ {
31923
+ name: "novel_screenplay_save_draft",
31924
+ description: "\u4FDD\u5B58\u7535\u5F71\u5267\u672C\u8349\u7A3F\u533A\u6587\u4EF6\uFF08\u6545\u4E8B\u7A3F.md / \u5206\u573A\u5927\u7EB2.md / \u5267\u672C\u8349\u7A3F.md\uFF09\u5230\u8349\u7A3F\u533A/\u5267\u672C/\uFF0C\u6821\u9A8C\u7ED3\u6784\u540E\u539F\u5B50\u843D\u76D8\u5E76\u8BFB\u56DE\u6838\u9A8C\uFF0C\u514D\u53BB\u5206\u6BB5\u624B\u5199\u7F16\u8F91\u3002",
31925
+ parameters: {
31926
+ type: "object",
31927
+ properties: {
31928
+ bookId: { type: "string", description: "\u5F53\u524D\u7535\u5F71\u5267\u672C\u7684\u4E66id\uFF08\u5FC5\u586B\uFF09" },
31929
+ \u7C7B\u578B: { type: "string", enum: ["\u6545\u4E8B\u7A3F", "\u5206\u573A\u5927\u7EB2", "\u5267\u672C\u8349\u7A3F"], description: "\u8349\u7A3F\u5DE5\u4EF6\u7C7B\u578B" },
31930
+ \u6B63\u6587: { type: "string", description: "\u5B8C\u6574 Markdown \u6B63\u6587" }
31931
+ },
31932
+ required: ["bookId", "\u7C7B\u578B", "\u6B63\u6587"]
31933
+ },
31934
+ output: {
31935
+ schema: {
31936
+ type: "object",
31937
+ properties: {
31938
+ ok: { type: "boolean" },
31939
+ path: { type: "string" },
31940
+ saved: { type: "boolean" },
31941
+ \u8B66\u544A: { type: "array", items: { type: "string" } },
31942
+ message: { type: "string" },
31943
+ reason: { type: "string" }
31944
+ },
31945
+ required: ["ok"]
31946
+ },
31947
+ render: (_args, value) => renderOutput(value)
31948
+ },
31949
+ execute: async (args, exec) => {
31950
+ const bookId2 = enumArg(args, "bookId");
31951
+ if (!bookId2 || !deps.bookRootOfBookId) return toolFailure("book-not-found", "bookId \u5FC5\u586B\uFF0C\u8BF7\u5148\u6838\u5BF9\u5F53\u524D\u4E66\u76EE\u3002");
31952
+ const bookRoot = deps.bookRootOfBookId(bookId2, exec?.agent);
31953
+ if (!bookRoot) return toolFailure("book-not-found", `\u4E66id\u4E0D\u5B58\u5728\u6216\u4E0D\u552F\u4E00\uFF1A${bookId2}`);
31954
+ if (readExistingContract(bookRoot).fields["\u8F93\u51FA\u5F62\u6001"] !== "\u7535\u5F71\u5267\u672C") {
31955
+ return toolFailure("invalid-argument", "\u4F5C\u54C1\u5951\u7EA6\u7684\u8F93\u51FA\u5F62\u6001\u5FC5\u987B\u662F\u7535\u5F71\u5267\u672C\uFF0C\u4E0D\u80FD\u4FDD\u5B58\u7535\u5F71\u5267\u672C\u8349\u7A3F\u3002");
31956
+ }
31957
+ if (!deps.writeDraft) return toolFailure("host-unavailable", "\u5F53\u524D\u73AF\u5883\u672A\u6302\u8F7D\u4E66\u4ED3\u5199\u5165\u901A\u9053\uFF0C\u65E0\u6CD5\u4FDD\u5B58\u5267\u672C\u8349\u7A3F\u3002");
31958
+ const kind2 = enumArg(args, "\u7C7B\u578B");
31959
+ if (kind2 !== "\u6545\u4E8B\u7A3F" && kind2 !== "\u5206\u573A\u5927\u7EB2" && kind2 !== "\u5267\u672C\u8349\u7A3F") {
31960
+ return toolFailure("invalid-argument", `\u7C7B\u578B\u5FC5\u987B\u662F \u6545\u4E8B\u7A3F / \u5206\u573A\u5927\u7EB2 / \u5267\u672C\u8349\u7A3F\uFF08\u6536\u5230\uFF1A${String(args["\u7C7B\u578B"] ?? "\u672A\u4F20")}\uFF09`);
31961
+ }
31962
+ const content = textArg(args, "\u6B63\u6587");
31963
+ if (content.trim() === "") return toolFailure("invalid-argument", "\u6B63\u6587\u4E0D\u80FD\u4E3A\u7A7A\u3002");
31964
+ const warnings = [];
31965
+ if (kind2 === "\u6545\u4E8B\u7A3F") {
31966
+ const parsed = parseStoryDraft(content);
31967
+ if (parsed.story === void 0) return { ...toolFailure("parse-error", `\u6545\u4E8B\u7A3F\u683C\u5F0F\u6709\u8BEF\uFF1A${parsed.problems.join("\uFF1B")}`), saved: false };
31968
+ const v = validateStoryDraft(parsed.story);
31969
+ if (v.errors.length > 0) return { ...toolFailure("parse-error", `\u6545\u4E8B\u7A3F\u6821\u9A8C\u5931\u8D25\uFF1A${v.errors.join("\uFF1B")}`), saved: false };
31970
+ warnings.push(...v.warnings);
31971
+ } else if (kind2 === "\u5206\u573A\u5927\u7EB2") {
31972
+ const parsed = parseSceneOutline(content);
31973
+ if (parsed.outline === void 0) return { ...toolFailure("parse-error", `\u5206\u573A\u5927\u7EB2\u683C\u5F0F\u6709\u8BEF\uFF1A${parsed.problems.join("\uFF1B")}`), saved: false };
31974
+ const v = validateSceneOutline(parsed.outline);
31975
+ if (v.errors.length > 0) return { ...toolFailure("parse-error", `\u5206\u573A\u5927\u7EB2\u6821\u9A8C\u5931\u8D25\uFF1A${v.errors.join("\uFF1B")}`), saved: false };
31976
+ warnings.push(...v.warnings);
31977
+ } else {
31978
+ const parsed = parseScreenplay(content);
31979
+ if (parsed.draft === void 0) return { ...toolFailure("parse-error", `\u5267\u672C\u8349\u7A3F\u683C\u5F0F\u6709\u8BEF\uFF1A${parsed.problems.join("\uFF1B")}`), saved: false };
31980
+ warnings.push(...validateScreenplay(parsed.draft).map((f) => `${f.\u6A21\u5757\u540D}\u3014${f.\u4E25\u91CD\u7A0B\u5EA6}\u3015${f.\u8BC1\u636E\u4F4D\u7F6E}\uFF1A${f.\u95EE\u9898\u8BF4\u660E}`));
31981
+ }
31982
+ const draftRel = `\u8349\u7A3F\u533A/\u5267\u672C/${kind2}.md`;
31983
+ const access = gateFileAccess(bookRoot, draftRel);
31984
+ if (!access.allow || access.zone !== "\u8349\u7A3F\u533A") {
31985
+ return { ...toolFailure("runtime-link", `\u5267\u672C\u8349\u7A3F\u76EE\u6807\u5FC5\u987B\u7559\u5728\u8349\u7A3F\u533A\uFF1A${access.allow ? draftRel : access.reason}`), saved: false };
31986
+ }
31987
+ const normalized = content.endsWith("\n") ? content : `${content}
31988
+ `;
31989
+ try {
31990
+ exec?.signal?.throwIfAborted();
31991
+ await deps.writeDraft(bookRoot, { relPath: draftRel, content: normalized }, exec);
31992
+ if (fs55.readFileSync(path67.join(bookRoot, draftRel), "utf8") !== normalized) {
31993
+ return { ...toolFailure("internal", "\u5267\u672C\u8349\u7A3F\u4FDD\u5B58\u540E\u8BFB\u56DE\u6B63\u6587\u4E0D\u4E00\u81F4\uFF0C\u8BF7\u6838\u5BF9\u6587\u4EF6\u3002"), saved: false };
31994
+ }
31995
+ return { ok: true, path: draftRel, saved: true, \u8B66\u544A: warnings, message: `\u7535\u5F71\u5267\u672C\u300C${kind2}\u300D\u5DF2\u4FDD\u5B58\u81F3 ${draftRel}\u3002` };
31996
+ } catch (error) {
31997
+ if (exec?.signal?.aborted) throw error;
31998
+ return { ...failureFrom(error, "\u4FDD\u5B58\u7535\u5F71\u5267\u672C\u8349\u7A3F\u5931\u8D25\uFF1A"), saved: false };
31999
+ }
32000
+ }
32001
+ },
32002
+ {
32003
+ name: "novel_screenplay_settle",
32004
+ description: "\u7535\u5F71\u5267\u672C\u5B9A\u7A3F\u5165\u6863\uFF1A\u6821\u9A8C\u8349\u7A3F\u533A/\u5267\u672C/\u5267\u672C\u8349\u7A3F.md \u65E0\u9AD8\u7EA7\u522B\u963B\u65AD\u9879\u540E\uFF0C\u7ECF\u4F5C\u8005\u6279\u51C6\uFF08\u6216\u6279\u91CF\u6258\u7BA1\u6388\u6743\uFF09\u539F\u5B50\u5199\u5165\u771F\u6E90 \u5267\u672C/\u7535\u5F71/\u5267\u672C.md \u5E76\u6267\u884C\u5355\u6B21 ch: Git \u63D0\u4EA4\u3002",
32005
+ parameters: {
32006
+ type: "object",
32007
+ properties: {
32008
+ bookId: { type: "string", description: "\u5F53\u524D\u7535\u5F71\u5267\u672C\u7684\u4E66id\uFF08\u5FC5\u586B\uFF09" },
32009
+ summary: { type: "string", description: "\u63D0\u4EA4\u6458\u8981\uFF08\u5982 \u7535\u5F71\u5267\u672C\u5B9A\u7A3F\uFF09" },
32010
+ \u7247\u957F: { type: "string", enum: ["\u957F\u7247", "\u77ED\u7247"], description: "\u957F\u7247\u6216\u77ED\u7247\uFF0C\u9ED8\u8BA4 \u957F\u7247" }
32011
+ },
32012
+ required: ["bookId", "summary"]
32013
+ },
32014
+ output: {
32015
+ schema: {
32016
+ type: "object",
32017
+ properties: {
32018
+ ok: { type: "boolean" },
32019
+ path: { type: "string" },
32020
+ draftPath: { type: "string" },
32021
+ alreadyCommitted: { type: "boolean" },
32022
+ message: { type: "string" },
32023
+ reason: { type: "string" }
32024
+ },
32025
+ required: ["ok"]
32026
+ },
32027
+ render: (_args, value) => renderOutput(value)
32028
+ },
32029
+ execute: async (args, exec) => {
32030
+ const bookId2 = enumArg(args, "bookId");
32031
+ if (!bookId2 || !deps.bookRootOfBookId) return toolFailure("book-not-found", "bookId \u5FC5\u586B\uFF0C\u8BF7\u5148\u6838\u5BF9\u5F53\u524D\u4E66\u76EE\u3002");
32032
+ const bookRoot = deps.bookRootOfBookId(bookId2, exec?.agent);
32033
+ if (!bookRoot) return toolFailure("book-not-found", `\u4E66id\u4E0D\u5B58\u5728\u6216\u4E0D\u552F\u4E00\uFF1A${bookId2}`);
32034
+ if (readExistingContract(bookRoot).fields["\u8F93\u51FA\u5F62\u6001"] !== "\u7535\u5F71\u5267\u672C") {
32035
+ return toolFailure("invalid-argument", "\u4F5C\u54C1\u5951\u7EA6\u7684\u8F93\u51FA\u5F62\u6001\u5FC5\u987B\u662F\u7535\u5F71\u5267\u672C\uFF0C\u4E0D\u80FD\u8D70\u7535\u5F71\u5267\u672C\u5B9A\u7A3F\u3002");
32036
+ }
32037
+ const mode = deps.automationMode?.() ?? "manual";
32038
+ const batchMatch = mode !== "manual" ? deps.batchStore?.match(bookRoot, exec, "screenplay") : void 0;
32039
+ if (!batchMatch && !deps.askFn) return toolFailure("host-unavailable", "\u88C1\u51B3\u901A\u9053\u4E0D\u53EF\u7528\uFF1A\u5F53\u524D\u73AF\u5883\u65E0\u6CD5\u5F39\u51FA\u4F5C\u8005\u88C1\u51B3\u7A97\u53E3\uFF0C\u672C\u6B21\u6CA1\u6709\u5199\u5165\u3002");
32040
+ const summary = textArg(args, "summary").trim();
32041
+ if (summary === "") return toolFailure("invalid-argument", "summary \u4E0D\u80FD\u4E3A\u7A7A\u3002");
32042
+ const draftRel = "\u8349\u7A3F\u533A/\u5267\u672C/\u5267\u672C\u8349\u7A3F.md";
32043
+ const outlineRel = "\u8349\u7A3F\u533A/\u5267\u672C/\u5206\u573A\u5927\u7EB2.md";
32044
+ const finalRel = screenplayFinalPath();
32045
+ let draftAbs;
32046
+ let finalAbs;
32047
+ try {
32048
+ draftAbs = authorDocumentPath(bookRoot, draftRel);
32049
+ finalAbs = authorDocumentPath(bookRoot, finalRel);
32050
+ } catch (error) {
32051
+ if (error instanceof AuthorDocumentError && error.code === "invalid-path") {
32052
+ return toolFailure("runtime-link", `\u5267\u672C\u8DEF\u5F84\u4E0D\u5F97\u7ECF\u8FC7\u76EE\u5F55\u94FE\u63A5\uFF1A${error.message}`);
32053
+ }
32054
+ return failureFrom(error, "\u5267\u672C\u8DEF\u5F84\u6821\u9A8C\u5931\u8D25\uFF1A");
32055
+ }
32056
+ let draftText;
32057
+ try {
32058
+ draftText = fs55.readFileSync(draftAbs, "utf8");
32059
+ } catch (error) {
32060
+ if (error.code === "ENOENT") {
32061
+ return toolFailure("invalid-argument", `\u5267\u672C\u8349\u7A3F\u4E0D\u5B58\u5728\uFF1A${draftRel}\uFF0C\u8BF7\u5148\u8C03\u7528 novel_screenplay_save_draft \u4FDD\u5B58\u5267\u672C\u8349\u7A3F\u3002`);
32062
+ }
32063
+ return failureFrom(error, "\u8BFB\u53D6\u5267\u672C\u8349\u7A3F\u5931\u8D25\uFF1A");
32064
+ }
32065
+ const parsedDraft = parseScreenplay(draftText);
32066
+ if (parsedDraft.draft === void 0) {
32067
+ return toolFailure("parse-error", `\u5267\u672C\u8349\u7A3F\u89E3\u6790\u5931\u8D25\uFF08${draftRel}\uFF09\uFF1A${parsedDraft.problems.join("\uFF1B")}`);
32068
+ }
32069
+ let outlineText = "";
32070
+ let parsedOutline;
32071
+ try {
32072
+ const outlineAbs = authorDocumentPath(bookRoot, outlineRel);
32073
+ if (fs55.existsSync(outlineAbs)) {
32074
+ outlineText = fs55.readFileSync(outlineAbs, "utf8");
32075
+ parsedOutline = parseSceneOutline(outlineText);
32076
+ }
32077
+ } catch {
32078
+ }
32079
+ const \u7247\u957F = enumArg(args, "\u7247\u957F") === "\u77ED\u7247" ? "\u77ED\u7247" : "\u957F\u7247";
32080
+ const review = computeScreenplayFindings({
32081
+ \u5267\u672C\u8349\u7A3F: parsedDraft.draft,
32082
+ \u5267\u672C\u8349\u7A3F\u6587\u672C: draftText,
32083
+ ...parsedOutline?.outline !== void 0 ? { \u5206\u573A\u5927\u7EB2: parsedOutline.outline, \u5206\u573A\u5927\u7EB2\u6587\u672C: outlineText } : {},
32084
+ \u7247\u957F
32085
+ });
32086
+ if (review.\u662F\u5426\u963B\u65AD) {
32087
+ const blockers = review.findings.filter((f) => f.\u4E25\u91CD\u7A0B\u5EA6 === "\u9AD8").map((f) => `${f.\u8BC1\u636E\u4F4D\u7F6E}\uFF1A${f.\u95EE\u9898\u8BF4\u660E}`).join("\uFF1B");
32088
+ return toolFailure("invalid-argument", `\u5267\u672C\u8349\u7A3F\u5B58\u5728\u963B\u65AD\u9879\uFF0C\u4E0D\u80FD\u5B9A\u7A3F\uFF1A${blockers}`);
32089
+ }
32090
+ if (fs55.existsSync(finalAbs) && fs55.readFileSync(finalAbs, "utf8") !== draftText) {
32091
+ return toolFailure("source-conflict", `\u5B9A\u7A3F\u53EA\u589E\u4E0D\u6539\uFF1A\u76EE\u6807 ${finalRel} \u5DF2\u5B58\u5728\u4E14\u5185\u5BB9\u4E0D\u540C\uFF0C\u672C\u6B21\u6CA1\u6709\u5199\u5165\u3002`);
32092
+ }
32093
+ const approvalFiles = [draftRel, finalRel, paths.\u5951\u7EA6()];
32094
+ const approvalReq = { bookId: bookId2, summary, \u7247\u957F };
32095
+ const before = captureApprovalFiles(bookRoot, approvalFiles, approvalReq);
32096
+ if (!before.ok) return before;
32097
+ let approvalRecordLine;
32098
+ if (batchMatch) {
32099
+ approvalRecordLine = `\u88C1\u51B3\u8BB0\u5F55\uFF1A${batchMatch.\u88C1\u51B3\u8BB0\u5F55}`;
32100
+ } else {
32101
+ const decision = await askAuthor(
32102
+ deps.askFn,
32103
+ "\u5B9A\u7A3F\u5165\u6863",
32104
+ { \u8303\u56F4: finalRel, \u6458\u8981: `\u7535\u5F71\u5267\u672C\u300A${parsedDraft.draft.\u6807\u9898}\u300B\uFF08${parsedDraft.draft.\u573A.length} \u573A\uFF0C\u4F30\u7B97 ${estimatePages(parsedDraft.draft)} \u9875\uFF09\uFF5C${summary}` },
32105
+ { agent: exec?.agent, signal: exec?.signal }
32106
+ );
32107
+ if (!decision.ok) return notApproved(decision.reason);
32108
+ if (exec?.signal?.aborted) return toolFailure("author-cancelled", "\u4F5C\u8005\u88C1\u51B3\u5DF2\u53D6\u6D88\uFF0C\u672C\u6B21\u6CA1\u6709\u5199\u5165\u3002");
32109
+ if (decision.\u51B3\u5B9A !== "\u5DF2\u6279\u51C6") return toolFailure("author-declined", `\u672A\u83B7\u4F5C\u8005\u6279\u51C6\uFF1A\u4F5C\u8005${decision.\u51B3\u5B9A}\uFF0C\u7535\u5F71\u5267\u672C\u6CA1\u6709\u5165\u6863\u3002`);
32110
+ approvalRecordLine = `\u88C1\u51B3\u8BB0\u5F55\uFF1A\u4F5C\u8005\u4E8E ${(/* @__PURE__ */ new Date()).toISOString()} \u6279\u51C6\u5B9A\u7A3F\u5165\u6863\uFF08kind=${decision.kind}, \u51B3\u5B9A=${decision.\u51B3\u5B9A}\uFF09`;
32111
+ }
32112
+ const provenance2 = deps.provenanceOf?.(exec, [finalRel]);
32113
+ return withBookWrite(bookRoot, () => {
32114
+ if (exec?.signal?.aborted) return toolFailure("author-cancelled", "\u4F5C\u8005\u88C1\u51B3\u5DF2\u53D6\u6D88\uFF0C\u672C\u6B21\u6CA1\u6709\u5199\u5165\u3002");
32115
+ const after = captureApprovalFiles(bookRoot, approvalFiles, approvalReq);
32116
+ if (!after.ok || after.fingerprint !== before.fingerprint) {
32117
+ return toolFailure("approval-stale", "\u5267\u672C\u8349\u7A3F\u6216\u5951\u7EA6\u5728\u7B49\u5F85\u88C1\u51B3\u671F\u95F4\u5DF2\u53D8\u5316\uFF0C\u65E7\u6279\u51C6\u4E0D\u53EF\u4F7F\u7528\u3002");
32118
+ }
32119
+ const res = archiveChapter({
32120
+ bookRoot,
32121
+ files: [{ \u76EE\u6807: finalRel, \u5185\u5BB9: draftText, sha256: draftHashOf(draftText) }],
32122
+ summary,
32123
+ lines: [
32124
+ `\u7535\u5F71\u5267\u672C\u5B9A\u7A3F\uFF1A${parsedDraft.draft.\u6807\u9898}`,
32125
+ `\u6765\u6E90\u8349\u7A3F\uFF1A${draftRel}`,
32126
+ `\u573A\u6B21\uFF1A${parsedDraft.draft.\u573A.length} \u573A\uFF08${\u7247\u957F}\uFF09`,
32127
+ approvalRecordLine
32128
+ ],
32129
+ provenance: provenance2
32130
+ });
32131
+ if (!res.ok) return { ok: false, reason: res.reason };
32132
+ return {
32133
+ ok: true,
32134
+ path: finalRel,
32135
+ draftPath: draftRel,
32136
+ alreadyCommitted: res.alreadyCommitted === true,
32137
+ ...batchMatch ? { batchId: batchMatch.batchId } : {},
32138
+ message: res.alreadyCommitted === true ? `\u7535\u5F71\u5267\u672C\u6B64\u524D\u5DF2\u6838\u5B9E\u5B9A\u7A3F\u5165\u6863\uFF08${res.message}\uFF09\uFF1A${finalRel}` : `\u7535\u5F71\u5267\u672C\u5B9A\u7A3F\u5B8C\u6210\uFF08${res.message}\uFF09\uFF0C\u5DF2\u5165\u6863\uFF1A${res.dests.join("\u3001")}`
32139
+ };
32140
+ }, provenance2);
32141
+ }
31530
32142
  }
31531
32143
  ];
31532
32144
  }
31533
32145
 
31534
32146
  // src/shortdrama-tools.ts
31535
- import * as fs54 from "node:fs";
31536
- import * as path66 from "node:path";
31537
-
31538
- // src/tool-failure.ts
31539
- var NEXT_STEP = {
31540
- "invalid-argument": "\u6309 reason \u4FEE\u6B63\u53C2\u6570\u540E\u91CD\u65B0\u8C03\u7528\u3002",
31541
- "book-not-found": "\u8C03\u7528 novel_select_book \u6838\u5BF9\u4E66\u76EE\u548C\u4E66id\uFF0C\u518D\u91CD\u65B0\u8C03\u7528\u3002",
31542
- "book-locked": "\u7B49\u51E0\u79D2\u540E\u91CD\u8BD5\u4E00\u6B21\u3002\u4ECD\u7136\u5931\u8D25\u65F6\uFF0C\u8BF7\u4F5C\u8005\u68C0\u67E5\u662F\u5426\u5F00\u7740\u5176\u4ED6\u5199\u4F5C\u7A97\u53E3\u3002",
31543
- "lock-interrupted": "\u7B49 30 \u79D2\u540E\u91CD\u8BD5\u4E00\u6B21\u3002\u786E\u8BA4\u6301\u6709\u8FDB\u7A0B\u9000\u51FA\u7684 acquire.lock \u4F1A\u81EA\u52A8\u56DE\u6536\uFF1B\u5F52\u5C5E\u4E0D\u660E\u65F6\uFF0C\u8BF7\u4F5C\u8005\u6838\u5BF9\u5E76\u786E\u8BA4\u6CA1\u6709\u5176\u4ED6\u5199\u4F5C\u7A97\u53E3\u540E\u518D\u6E05\u7406\u3002",
31544
- "runtime-link": "\u672C\u6B21\u6CA1\u6709\u5199\u5165\u3002\u8BF7\u4F5C\u8005\u6838\u5BF9 reason \u4E2D\u7684\u8FD0\u884C\u8DEF\u5F84\uFF0C\u4FDD\u7559\u8BC1\u636E\uFF0C\u4E0D\u8981\u7528\u94FE\u63A5\u66FF\u4EE3\u4E66\u4ED3\u8FD0\u884C\u76EE\u5F55\u3002",
31545
- "transaction-conflict": "\u5148\u628A\u9694\u79BB\u4E8B\u52A1\u7684\u5907\u4EFD\u548C\u5F53\u524D\u6587\u4EF6\u5448\u62A5\u4F5C\u8005\u3002\u5904\u7406\u51B2\u7A81\u540E\u518D\u5199\u5165\uFF0C\u76EE\u6807\u672A\u77E5\u65F6\u6682\u505C\u6240\u6709\u5199\u5165\u3002",
31546
- "author-declined": "\u4E0D\u8981\u91CD\u65B0\u8C03\u7528\u672C\u5DE5\u5177\u3002\u5148\u95EE\u4F5C\u8005\u8981\u6539\u4EC0\u4E48\uFF0C\u518D\u6309\u56DE\u7B54\u56DE\u5230\u5BF9\u5E94\u8282\u70B9\u3002",
31547
- "author-cancelled": "\u672C\u6B21\u6CA1\u6709\u5199\u5165\u3002\u7B49\u4F5C\u8005\u660E\u786E\u6279\u51C6\u540E\uFF0C\u518D\u8C03\u7528\u672C\u5DE5\u5177\u3002",
31548
- "approval-stale": "\u65E7\u6279\u51C6\u5DF2\u5931\u6548\u3002\u91CD\u65B0\u5448\u62A5\u4F5C\u8005\uFF0C\u83B7\u5F97\u65B0\u7684\u6279\u51C6\u540E\u518D\u8C03\u7528\u3002",
31549
- "source-conflict": "\u4E0D\u8981\u7528\u76F8\u540C\u53C2\u6570\u91CD\u8BD5\u3002\u628A\u51B2\u7A81\u539F\u6587\u5448\u62A5\u4F5C\u8005\uFF0C\u7531\u4F5C\u8005\u51B3\u5B9A\u4FDD\u7559\u54EA\u4E00\u4EFD\u3002",
31550
- "parse-error": "\u6309 reason \u6307\u51FA\u7684\u4F4D\u7F6E\u4FEE\u6B63\u5185\u5BB9\uFF0C\u518D\u91CD\u65B0\u8C03\u7528\u4E00\u6B21\u3002\u4ECD\u7136\u5931\u8D25\u65F6\uFF0C\u628A reason \u539F\u6587\u544A\u8BC9\u4F5C\u8005\u3002",
31551
- "host-unavailable": "\u672C\u6B21\u6CA1\u6709\u5199\u5165\u3002\u8BF7\u4F5C\u8005\u91CD\u542F\u5DE5\u4F5C\u53F0\uFF0C\u6216\u6838\u5BF9 DSH \u7248\u672C\u662F\u5426\u4E0E\u63D2\u4EF6\u914D\u5957\u3002",
31552
- "partial-commit": "\u6587\u4EF6\u5DF2\u5199\u5165\u4F46\u8FD8\u6CA1\u6709\u63D0\u4EA4\u3002\u7528\u76F8\u540C\u53C2\u6570\u91CD\u65B0\u8C03\u7528\u672C\u5DE5\u5177\u5373\u53EF\u8865\u63D0\u4EA4\u3002",
31553
- internal: "\u4E0D\u8981\u7528\u76F8\u540C\u53C2\u6570\u53CD\u590D\u91CD\u8BD5\u3002\u628A reason \u539F\u6587\u544A\u8BC9\u4F5C\u8005\u3002"
31554
- };
31555
- function toolFailure(code, reason, next = NEXT_STEP[code]) {
31556
- return { ok: false, code, reason, next };
31557
- }
31558
- function errorText3(error) {
31559
- return error instanceof Error ? error.message : String(error);
31560
- }
31561
- function expectedFailure(error) {
31562
- const seen = /* @__PURE__ */ new Set();
31563
- for (let current = error; current instanceof Error && !seen.has(current); current = current.cause) {
31564
- seen.add(current);
31565
- if (current instanceof BookLockError || current instanceof TransactionConflictError) return toolFailure(current.code, errorText3(error));
31566
- if (current instanceof SettlementParseError) return toolFailure("parse-error", errorText3(error));
31567
- }
31568
- return void 0;
31569
- }
31570
- function failureFrom(error, prefix = "") {
31571
- const known = expectedFailure(error);
31572
- const reason = `${prefix}${errorText3(error)}`;
31573
- return known === void 0 ? toolFailure(classifyReason(reason), reason) : { ...known, reason };
31574
- }
31575
- var RULES2 = [
31576
- ["lock-interrupted", /锁获取曾中断|acquire\.lock/],
31577
- ["book-locked", /书仓写入锁定中|书仓.*锁定/],
31578
- ["partial-commit", /提交失败|未形成提交|已落盘但未提交/],
31579
- ["author-declined", /未获作者批准|作者.{0,4}(驳回|拒绝)/],
31580
- ["author-cancelled", /裁决.{0,2}取消|作者关闭了裁决|作者已取消/],
31581
- ["approval-stale", /等待作者裁决期间|旧批准/],
31582
- ["source-conflict", /冲突|已隔离|只增不改|已被另行修改/],
31583
- ["host-unavailable", /裁决窗口|工作范围未就绪|未配置|不可用|尚未就绪/],
31584
- ["book-not-found", /书id|bookId|书目/],
31585
- ["parse-error", /解析失败|未分类正文|无法解析|第 \d+ 行:/],
31586
- ["invalid-argument", /必须|不能为空|不得|非法|不合法|必填|为空|缺少|不存在|过长|超过|不支持|须/]
31587
- ];
31588
- function classifyReason(reason) {
31589
- for (const [code, pattern2] of RULES2) if (pattern2.test(reason)) return code;
31590
- return "internal";
31591
- }
31592
- function normalizeFailure(result) {
31593
- if (result === null || typeof result !== "object") return result;
31594
- const value = result;
31595
- if (value["ok"] !== false) return result;
31596
- let reason = typeof value["reason"] === "string" ? value["reason"] : void 0;
31597
- if (reason === void 0 || reason.trim() === "") {
31598
- reason = chineseReason(value["\u539F\u56E0"]) ?? chineseReason(value["\u95EE\u9898"]);
31599
- }
31600
- if (reason === void 0 || reason.trim() === "") return result;
31601
- const known = typeof value["code"] === "string" && value["code"] in NEXT_STEP ? value["code"] : void 0;
31602
- const code = typeof value["code"] === "string" ? value["code"] : classifyReason(reason);
31603
- const next = typeof value["next"] === "string" && value["next"] !== "" ? value["next"] : NEXT_STEP[known ?? (code in NEXT_STEP ? code : classifyReason(reason))];
31604
- return { ...value, reason, code, next };
31605
- }
31606
- function chineseReason(field) {
31607
- if (typeof field === "string" && field.trim() !== "") return field;
31608
- if (Array.isArray(field) && field.length > 0) return field.map(String).join("\uFF1B");
31609
- return void 0;
31610
- }
31611
- var FAILURE_FIELDS = {
31612
- code: { type: "string", description: "\u5931\u8D25\u7C7B\u522B\uFF08\u5982 invalid-argument\u3001book-locked\u3001author-declined\uFF09\uFF0C\u6210\u529F\u65F6\u4E0D\u8FD4\u56DE" },
31613
- next: { type: "string", description: "\u5931\u8D25\u540E\u7684\u4E0B\u4E00\u6B65\uFF0C\u6210\u529F\u65F6\u4E0D\u8FD4\u56DE" }
31614
- };
31615
-
31616
- // src/shortdrama-tools.ts
32147
+ import * as fs56 from "node:fs";
32148
+ import * as path68 from "node:path";
31617
32149
  function asRecord2(value, name3) {
31618
32150
  if (typeof value !== "object" || value === null || Array.isArray(value)) {
31619
32151
  throw new Error(`${name3} \u5FC5\u987B\u662F\u4E00\u4E2A\u5BF9\u8C61`);
@@ -31903,10 +32435,284 @@ var SHORTDRAMA_TOOL_DEFINITIONS = [
31903
32435
  \u5F85\u56DE\u5199\u6A21\u5757: ["\u77ED\u5267\u5BA1\u8BFB\uFF08\u8BED\u4E49\uFF09"]
31904
32436
  };
31905
32437
  })
32438
+ },
32439
+ {
32440
+ name: "novel_shortdrama_settle_episode",
32441
+ description: "\u77ED\u5267\u5355\u96C6\u5B9A\u7A3F\u5165\u6863\uFF1A\u5FC5\u4F20 bookId\u3001\u96C6\uFF081\u2013100\uFF09\u548C summary\u3002\u6838\u5BF9\u5951\u7EA6\u8F93\u51FA\u5F62\u6001=\u77ED\u5267\u3001\u6821\u9A8C\u8349\u7A3F\u533A/\u5267\u672C/\u77ED\u5267/\u96C6NNN.md \u4E14\u68C0\u67E5\u5206\u96C6\u5BA1\u8BFB\u8BB0\u5F55\u72B6\u6001\u540E\uFF0C\u5F39\u51FA\u4F5C\u8005\u88C1\u51B3\u7A97\u53E3\uFF1B\u4EC5\u5728\u4F5C\u8005\u660E\u786E\u6279\u51C6\u540E\u5C06\u5355\u96C6\u5267\u672C\u539F\u5B50\u5199\u5165 \u5267\u672C/\u77ED\u5267/\u96C6NNN.md \u5E76\u505A\u5355\u6B21 ch: Git \u63D0\u4EA4\u3002\u5B9A\u7A3F\u53EA\u589E\u4E0D\u6539\uFF1B\u672A\u83B7\u6279\u51C6\u4E25\u7981\u5165\u6863\u3002",
32442
+ parameters: {
32443
+ type: "object",
32444
+ properties: {
32445
+ bookId: { type: "string", description: "\u5F53\u524D\u77ED\u5267\u7684\u4E66id\uFF08\u5FC5\u586B\uFF09" },
32446
+ \u96C6: { type: "integer", description: "\u96C6\u53F7\uFF0C1\u2013100" },
32447
+ summary: { type: "string", description: "\u63D0\u4EA4\u6458\u8981\uFF08\u5982 \u96C6001 \u7B49\u4E86\u4E09\u5E74\u7684\u9762\uFF09" }
32448
+ },
32449
+ required: ["bookId", "\u96C6", "summary"]
32450
+ },
32451
+ output: {
32452
+ schema: {
32453
+ type: "object",
32454
+ properties: {
32455
+ ok: { type: "boolean", description: "\u662F\u5426\u6210\u529F" },
32456
+ path: { type: "string", description: "\u5DF2\u5B9A\u7A3F\u5267\u672C\u8DEF\u5F84\uFF08\u5267\u672C/\u77ED\u5267/\u96C6NNN.md\uFF09" },
32457
+ draftPath: { type: "string", description: "\u6765\u6E90\u8349\u7A3F\u8DEF\u5F84\uFF08\u8349\u7A3F\u533A/\u5267\u672C/\u77ED\u5267/\u96C6NNN.md\uFF09" },
32458
+ \u96C6: { type: "integer", description: "\u96C6\u53F7" },
32459
+ \u6807\u9898: { type: "string", description: "\u672C\u96C6\u6807\u9898" },
32460
+ alreadyCommitted: { type: "boolean", description: "\u662F\u5426\u6B64\u524D\u5DF2\u6838\u5B9E\u540C\u4E00\u63D0\u4EA4\uFF0C\u672A\u91CD\u590D\u5199\u5165" },
32461
+ \u5BA1\u8BFB\u72B6\u6001: { type: "string", description: "\u672C\u96C6\u5206\u96C6\u5BA1\u8BFB\u8BB0\u5F55\u6838\u5BF9\u7ED3\u679C" },
32462
+ message: { type: "string", description: "\u7ED3\u679C\u8BF4\u660E\uFF08\u542B\u5165\u6863\u53BB\u5904\uFF09" },
32463
+ reason: { type: "string", description: "\u5931\u8D25\u539F\u56E0" }
32464
+ },
32465
+ required: ["ok"]
32466
+ },
32467
+ render: (_args, value) => [{ type: "text", text: JSON.stringify(value, null, 2) }]
32468
+ },
32469
+ execute: () => toolFailure("host-unavailable", "\u88C1\u51B3\u901A\u9053\u4E0D\u53EF\u7528\uFF1A\u5F53\u524D\u73AF\u5883\u65E0\u6CD5\u5F39\u51FA\u4F5C\u8005\u88C1\u51B3\u7A97\u53E3\uFF0C\u672C\u6B21\u6CA1\u6709\u5199\u5165")
32470
+ },
32471
+ {
32472
+ name: "novel_shortdrama_save_script",
32473
+ description: "\u76F4\u63A5\u4FDD\u5B58\u77ED\u5267\u5355\u96C6 Markdown \u5267\u672C\u6587\u672C\u5230\u8349\u7A3F\u533A\uFF08\u514D\u53BB\u9010\u53E5\u62FC\u5D4C\u5957 JSON\uFF0C\u63D0\u5347\u521B\u4F5C\u8FDE\u8D2F\u6027\uFF09\u3002\u6821\u9A8C\u683C\u5F0F\u4E0E\u96C6\u53F7\u540E\u539F\u5B50\u5199\u5165\u8349\u7A3F\u533A/\u5267\u672C/\u77ED\u5267/\u96C6NNN.md\uFF0C\u8BFB\u56DE\u6838\u9A8C\u4E00\u81F4\u8FD4\u56DE saved=true\u3002",
32474
+ parameters: {
32475
+ type: "object",
32476
+ properties: {
32477
+ bookId: { type: "string", description: "\u5F53\u524D\u77ED\u5267\u7684\u4E66id\uFF08\u5FC5\u586B\uFF09" },
32478
+ \u96C6: { type: "integer", description: "\u96C6\u53F7\uFF0C1\u2013100\uFF08\u987B\u4E0E\u6B63\u6587 # \u96C6NNN\uFF1A\u6807\u9898 \u4E00\u81F4\uFF09" },
32479
+ \u6B63\u6587: { type: "string", description: "\u7B26\u5408\u77ED\u5267\u683C\u5F0F\u7684\u5355\u96C6\u5B8C\u6574 Markdown \u5267\u672C\u6587\u672C\uFF08\u542B\u96C6\u5143\u6570\u636E\u30011-1 \u65E5\uFF0F\u5185 \u5730\u70B9 \u573A\u5934\u3001\u955C\u5934\u5757\u3001\u5BF9\u767D\u3001\u6DE1\u51FA\u4E0E\u8282\u62CD\u8868\uFF09" }
32480
+ },
32481
+ required: ["bookId", "\u96C6", "\u6B63\u6587"]
32482
+ },
32483
+ output: {
32484
+ schema: {
32485
+ type: "object",
32486
+ properties: {
32487
+ ok: { type: "boolean" },
32488
+ path: { type: "string" },
32489
+ finalPath: { type: "string" },
32490
+ saved: { type: "boolean" },
32491
+ \u8B66\u544A: { type: "array", items: { type: "string" } },
32492
+ message: { type: "string" },
32493
+ reason: { type: "string" }
32494
+ },
32495
+ required: ["ok"]
32496
+ },
32497
+ render: (_args, value) => [{ type: "text", text: JSON.stringify(value, null, 2) }]
32498
+ },
32499
+ execute: () => toolFailure("host-unavailable", "\u5F53\u524D\u73AF\u5883\u672A\u6302\u8F7D\u4E66\u4ED3\u5199\u5165\u901A\u9053\uFF0C\u65E0\u6CD5\u4FDD\u5B58\u77ED\u5267\u8349\u7A3F")
31906
32500
  }
31907
32501
  ];
32502
+ function resolveShortdramaBook(deps, rawBookId, exec, action) {
32503
+ const bookId2 = typeof rawBookId === "string" ? rawBookId.trim() : "";
32504
+ if (bookId2 === "") return toolFailure("book-not-found", "bookId \u5FC5\u586B\uFF0C\u8BF7\u5148\u6838\u5BF9\u5F53\u524D\u77ED\u5267\u4E66\u76EE\u3002");
32505
+ const bookRoot = deps.bookRootOfBookId(bookId2, exec?.agent);
32506
+ if (bookRoot === void 0) return toolFailure("book-not-found", `\u4E66id\u4E0D\u5B58\u5728\u6216\u4E0D\u552F\u4E00\uFF1A${bookId2}`);
32507
+ if (readExistingContract(bookRoot).fields["\u8F93\u51FA\u5F62\u6001"] !== "\u77ED\u5267") {
32508
+ return toolFailure("invalid-argument", `\u4F5C\u54C1\u5951\u7EA6\u7684\u8F93\u51FA\u5F62\u6001\u5FC5\u987B\u662F\u77ED\u5267\uFF0C\u4E0D\u80FD${action}\u3002`);
32509
+ }
32510
+ return { ok: true, bookId: bookId2, bookRoot };
32511
+ }
32512
+ function episodeReviewSummary(bookRoot, \u96C6, draftText, canonicalText) {
32513
+ const record4 = loadEpisodeReviewRecord(bookRoot, \u96C6);
32514
+ if (record4 === null) return `\u672A\u627E\u5230\u5BA1\u8BFB\u8BB0\u5F55\uFF08${paths.\u77ED\u5267\u5BA1\u6838\u8BB0\u5F55(\u96C6)}\uFF09`;
32515
+ const validHashes = [draftHashOf(draftText), ...canonicalText ? [draftHashOf(canonicalText)] : []];
32516
+ if (record4.\u5BA1\u7A3F\u54C8\u5E0C === void 0 || !validHashes.includes(record4.\u5BA1\u7A3F\u54C8\u5E0C)) return "\u5BA1\u8BFB\u8BB0\u5F55\u5DF2\u8FC7\u671F\uFF08\u5F53\u524D\u8349\u7A3F\u4E0E\u88AB\u5BA1\u7A3F\u4EF6\u54C8\u5E0C\u4E0D\u4E00\u81F4\uFF09";
32517
+ const pendingModules = Object.entries(record4.\u6A21\u5757).filter(([, state]) => !state.\u5B8C\u6210 || state.\u5F85\u56DE\u5199 === true).map(([name3]) => name3);
32518
+ if (!record4.\u5B8C\u6210 || Object.keys(record4.\u6A21\u5757).length === 0 || pendingModules.length > 0) {
32519
+ return pendingModules.length > 0 ? `\u5BA1\u8BFB\u672A\u5B8C\u6210\uFF08\u5F85\u5B8C\u6210\u6A21\u5757\uFF1A${pendingModules.join("\u3001")}\uFF09` : "\u5BA1\u8BFB\u5C1A\u672A\u5168\u90E8\u5B8C\u6210";
32520
+ }
32521
+ const pendingFindings = record4.\u95EE\u9898.filter((item) => !item.\u5904\u7F6E\u72B6\u6001 || item.\u5904\u7F6E\u72B6\u6001 === "\u5F85\u5904\u7406").length;
32522
+ if (pendingFindings > 0) return `\u5BA1\u8BFB\u5DF2\u56DE\u5199\uFF0C\u4ECD\u6709 ${pendingFindings} \u9879\u53D1\u73B0\u9879\u5F85\u5904\u7F6E`;
32523
+ return "\u5BA1\u8BFB\u901A\u8FC7\uFF08\u6A21\u5757\u9F50\u5168\u4E14\u96F6\u9879\u5F85\u5904\u7F6E\uFF09";
32524
+ }
32525
+ function resolvePlainBookFile(bookRoot, relPath) {
32526
+ try {
32527
+ return { ok: true, absPath: authorDocumentPath(bookRoot, relPath) };
32528
+ } catch (error) {
32529
+ if (error instanceof AuthorDocumentError && error.code === "invalid-path") {
32530
+ return toolFailure("runtime-link", `\u77ED\u5267\u8DEF\u5F84\u5FC5\u987B\u662F\u666E\u901A\u6587\u4EF6\u4E14\u4E0D\u5F97\u7ECF\u8FC7\u94FE\u63A5\uFF1A${relPath}\uFF08${error.message}\uFF09`);
32531
+ }
32532
+ return failureFrom(error, "\u77ED\u5267\u8DEF\u5F84\u6821\u9A8C\u5931\u8D25\uFF1A");
32533
+ }
32534
+ }
32535
+ async function executeSettleEpisode(deps, args, exec) {
32536
+ let resolved;
32537
+ try {
32538
+ resolved = resolveShortdramaBook(deps, args["bookId"], exec, "\u8D70\u77ED\u5267\u5B9A\u7A3F");
32539
+ } catch (error) {
32540
+ return failureFrom(error, "\u77ED\u5267\u5355\u96C6\u5B9A\u7A3F\u5931\u8D25\uFF1A");
32541
+ }
32542
+ if (!resolved.ok) return resolved;
32543
+ const { bookId: bookId2, bookRoot } = resolved;
32544
+ const rawEp = args["\u96C6"];
32545
+ if (typeof rawEp !== "number" || !Number.isSafeInteger(rawEp) || rawEp < 1 || rawEp > 100) {
32546
+ return toolFailure("invalid-argument", `\u96C6\u5FC5\u987B\u662F 1\u2013100 \u7684\u6574\u6570\uFF08\u6536\u5230\uFF1A${String(rawEp ?? "\u672A\u4F20")}\uFF09`);
32547
+ }
32548
+ const \u96C6 = rawEp;
32549
+ const mode = deps.automationMode?.() ?? "manual";
32550
+ const batchMatch = mode !== "manual" ? deps.batchStore?.match(bookRoot, exec, "episode", \u96C6) : void 0;
32551
+ if (!batchMatch && !deps.askFn) return toolFailure("host-unavailable", "\u88C1\u51B3\u901A\u9053\u4E0D\u53EF\u7528\uFF1A\u5F53\u524D\u73AF\u5883\u65E0\u6CD5\u5F39\u51FA\u4F5C\u8005\u88C1\u51B3\u7A97\u53E3\uFF0C\u672C\u6B21\u6CA1\u6709\u5199\u5165");
32552
+ const summary = typeof args["summary"] === "string" ? args["summary"].trim() : "";
32553
+ if (summary === "") {
32554
+ return toolFailure("invalid-argument", "summary \u4E0D\u80FD\u4E3A\u7A7A\uFF0C\u8BF7\u586B\u5199\u672C\u6B21\u5B9A\u7A3F\u63D0\u4EA4\u6458\u8981\uFF08\u5982\u300C\u96C6001 \u5B9A\u7A3F\u300D\uFF09\u3002");
32555
+ }
32556
+ const finalRel = paths.\u77ED\u5267\u96C6(\u96C6);
32557
+ const draftRel = `\u8349\u7A3F\u533A/${finalRel}`;
32558
+ const draftAccess = gateFileAccess(bookRoot, draftRel);
32559
+ if (!draftAccess.allow || draftAccess.zone !== "\u8349\u7A3F\u533A") {
32560
+ return toolFailure("runtime-link", `\u77ED\u5267\u8349\u7A3F\u5FC5\u987B\u7559\u5728\u8349\u7A3F\u533A\uFF0C\u8BF7\u6838\u5BF9\u76EE\u5F55\u94FE\u63A5\uFF1A${draftAccess.allow ? draftRel : draftAccess.reason}`);
32561
+ }
32562
+ const draftPathCheck = resolvePlainBookFile(bookRoot, draftRel);
32563
+ if (!draftPathCheck.ok) return draftPathCheck;
32564
+ const finalPathCheck = resolvePlainBookFile(bookRoot, finalRel);
32565
+ if (!finalPathCheck.ok) return finalPathCheck;
32566
+ let draftText;
32567
+ try {
32568
+ draftText = fs56.readFileSync(draftPathCheck.absPath, "utf8");
32569
+ } catch (error) {
32570
+ if (error.code === "ENOENT") {
32571
+ return toolFailure("invalid-argument", `\u77ED\u5267\u5355\u96C6\u8349\u7A3F\u4E0D\u5B58\u5728\uFF1A${draftRel}\uFF0C\u8BF7\u5148\u8C03\u7528 novel_shortdrama_render_episode \u6216 novel_shortdrama_save_script \u4FDD\u5B58\u8349\u7A3F\u3002`);
32572
+ }
32573
+ return failureFrom(error, "\u77ED\u5267\u5355\u96C6\u8349\u7A3F\u8BFB\u53D6\u5931\u8D25\uFF1A");
32574
+ }
32575
+ const parsed = parseEpisodeScript(draftText);
32576
+ if (!parsed.ok || parsed.episode === void 0) {
32577
+ return toolFailure("parse-error", `\u77ED\u5267\u5355\u96C6\u8349\u7A3F\u89E3\u6790\u5931\u8D25\uFF08${draftRel}\uFF09\uFF1A${parsed.problems.join("\uFF1B")}`);
32578
+ }
32579
+ if (parsed.episode.\u96C6 !== \u96C6) {
32580
+ return toolFailure("invalid-argument", `\u8349\u7A3F\u96C6\u53F7\u4E0D\u4E00\u81F4\uFF1A\u671F\u671B\u96C6${\u96C6}\uFF0C\u6587\u4EF6\u5185\u4E3A\u96C6${parsed.episode.\u96C6}`);
32581
+ }
32582
+ if (fs56.existsSync(finalPathCheck.absPath)) {
32583
+ const existingFinal = fs56.readFileSync(finalPathCheck.absPath, "utf8");
32584
+ if (existingFinal !== draftText) {
32585
+ return toolFailure("source-conflict", `\u5B9A\u7A3F\u53EA\u589E\u4E0D\u6539\uFF1A\u76EE\u6807 ${finalRel} \u5DF2\u5B58\u5728\u4E14\u5185\u5BB9\u4E0D\u540C\uFF0C\u672C\u6B21\u6CA1\u6709\u5199\u5165\u3002\u8BF7\u628A\u51B2\u7A81\u5448\u62A5\u4F5C\u8005\u3002`);
32586
+ }
32587
+ }
32588
+ const approvalFiles = [draftRel, finalRel, paths.\u5951\u7EA6(), paths.\u77ED\u5267\u5BA1\u6838\u8BB0\u5F55(\u96C6)];
32589
+ const approvalReq = { bookId: bookId2, \u96C6, summary };
32590
+ const before = captureApprovalFiles(bookRoot, approvalFiles, approvalReq);
32591
+ if (!before.ok) return before;
32592
+ const ep = parsed.episode;
32593
+ const reviewStatus = episodeReviewSummary(bookRoot, \u96C6, draftText, renderEpisodeScript(ep).\u5185\u5BB9);
32594
+ const approvalSummary = [
32595
+ `\u96C6${episodeNo(\u96C6)}\uFF1A${ep.\u6807\u9898}\uFF08${ep.\u753B\u5E45}\uFF0C${ep.\u65F6\u957F\u79D2} \u79D2\uFF0C${ep.\u573A\u666F.length} \u573A\uFF0C\u53F0\u8BCD ${totalDialogueChars(ep.\u573A\u666F)} \u5B57\uFF09`,
32596
+ `\u6765\u6E90\u8349\u7A3F\uFF1A${draftRel}`,
32597
+ `\u5BA1\u8BFB\u72B6\u6001\uFF1A${reviewStatus}`,
32598
+ `\u63D0\u4EA4\u6458\u8981\uFF1A${summary}`
32599
+ ].join("\uFF5C");
32600
+ let approvalRecordLine;
32601
+ if (batchMatch) {
32602
+ approvalRecordLine = `\u88C1\u51B3\u8BB0\u5F55\uFF1A${batchMatch.\u88C1\u51B3\u8BB0\u5F55}`;
32603
+ } else {
32604
+ const decision = await askAuthor(
32605
+ deps.askFn,
32606
+ "\u5B9A\u7A3F\u5165\u6863",
32607
+ { \u8303\u56F4: finalRel, \u6458\u8981: approvalSummary },
32608
+ { agent: exec?.agent, signal: exec?.signal }
32609
+ );
32610
+ if (!decision.ok) return notApproved(decision.reason);
32611
+ if (exec?.signal?.aborted) return toolFailure("author-cancelled", "\u4F5C\u8005\u88C1\u51B3\u5DF2\u53D6\u6D88\uFF08\u4F1A\u8BDD\u5DF2\u4E2D\u6B62\uFF09\uFF0C\u6CA1\u6709\u505A\u51FA\u51B3\u5B9A\uFF0C\u672C\u6B21\u6CA1\u6709\u5199\u5165");
32612
+ if (decision.\u51B3\u5B9A !== "\u5DF2\u6279\u51C6") return toolFailure("author-declined", `\u672A\u83B7\u4F5C\u8005\u6279\u51C6\uFF1A\u4F5C\u8005${decision.\u51B3\u5B9A}\uFF0C\u672C\u96C6\u6CA1\u6709\u5165\u6863`);
32613
+ approvalRecordLine = `\u88C1\u51B3\u8BB0\u5F55\uFF1A\u4F5C\u8005\u4E8E ${(/* @__PURE__ */ new Date()).toISOString()} \u6279\u51C6\u5B9A\u7A3F\u5165\u6863\uFF08kind=${decision.kind}, \u51B3\u5B9A=${decision.\u51B3\u5B9A}\uFF09`;
32614
+ }
32615
+ const provenance2 = deps.provenanceOf?.(exec, [finalRel]);
32616
+ return withBookWrite(bookRoot, () => {
32617
+ if (exec?.signal?.aborted) return toolFailure("author-cancelled", "\u4F5C\u8005\u88C1\u51B3\u5DF2\u53D6\u6D88\uFF08\u4F1A\u8BDD\u5DF2\u4E2D\u6B62\uFF09\uFF0C\u6CA1\u6709\u505A\u51FA\u51B3\u5B9A\uFF0C\u672C\u6B21\u6CA1\u6709\u5199\u5165");
32618
+ const current = resolveShortdramaBook(deps, bookId2, exec, "\u8D70\u77ED\u5267\u5B9A\u7A3F");
32619
+ if (!current.ok || current.bookRoot !== bookRoot) {
32620
+ return toolFailure("approval-stale", "\u7B49\u5F85\u4F5C\u8005\u88C1\u51B3\u671F\u95F4\u4E66id\u6216\u5F52\u5C5E\u5DF2\u53D8\u5316\uFF0C\u672C\u6B21\u6CA1\u6709\u5199\u5165", "\u8C03\u7528 novel_select_book \u6838\u5BF9\u4E66\u76EE\uFF0C\u518D\u91CD\u65B0\u5448\u62A5\u4F5C\u8005\u3002");
32621
+ }
32622
+ const after = captureApprovalFiles(bookRoot, approvalFiles, approvalReq);
32623
+ if (!after.ok || after.fingerprint !== before.fingerprint) {
32624
+ return toolFailure("approval-stale", "\u77ED\u5267\u5355\u96C6\u8349\u7A3F\u6216\u5BA1\u8BFB\u72B6\u6001\u5728\u7B49\u5F85\u4F5C\u8005\u88C1\u51B3\u671F\u95F4\u5DF2\u53D8\u5316\uFF0C\u65E7\u6279\u51C6\u4E0D\u53EF\u4F7F\u7528");
32625
+ }
32626
+ try {
32627
+ const res = archiveChapter({
32628
+ bookRoot,
32629
+ files: [{ \u76EE\u6807: finalRel, \u5185\u5BB9: draftText, sha256: draftHashOf(draftText) }],
32630
+ summary,
32631
+ lines: [
32632
+ `\u77ED\u5267\u5355\u96C6\u5B9A\u7A3F\uFF1A\u96C6${episodeNo(\u96C6)} ${ep.\u6807\u9898}`,
32633
+ `\u6765\u6E90\u8349\u7A3F\uFF1A${draftRel}`,
32634
+ `\u5BA1\u8BFB\u72B6\u6001\uFF1A${reviewStatus}`,
32635
+ approvalRecordLine
32636
+ ],
32637
+ provenance: provenance2
32638
+ });
32639
+ if (!res.ok) return { ok: false, reason: res.reason };
32640
+ return {
32641
+ ok: true,
32642
+ path: finalRel,
32643
+ draftPath: draftRel,
32644
+ \u96C6,
32645
+ \u6807\u9898: ep.\u6807\u9898,
32646
+ alreadyCommitted: res.alreadyCommitted === true,
32647
+ \u5BA1\u8BFB\u72B6\u6001: reviewStatus,
32648
+ ...batchMatch ? { batchId: batchMatch.batchId } : {},
32649
+ message: res.alreadyCommitted === true ? `\u672C\u96C6\u6B64\u524D\u5DF2\u6838\u5B9E\u5B9A\u7A3F\u5165\u6863\uFF08${res.message}\uFF09\uFF0C\u65E0\u9700\u91CD\u590D\u63D0\u4EA4\uFF1A${finalRel}` : `\u77ED\u5267\u5355\u96C6\u5B9A\u7A3F\u5B8C\u6210\uFF08${res.message}\uFF09\uFF0C\u5DF2\u5165\u6863\uFF1A${res.dests.join("\u3001")}`
32650
+ };
32651
+ } catch (error) {
32652
+ return failureFrom(error, "\u77ED\u5267\u5355\u96C6\u5B9A\u7A3F\u5931\u8D25\uFF1A");
32653
+ }
32654
+ }, provenance2);
32655
+ }
32656
+ async function executeSaveScript(deps, args, exec) {
32657
+ try {
32658
+ const resolved = resolveShortdramaBook(deps, args["bookId"], exec, "\u4FDD\u5B58\u77ED\u5267\u8349\u7A3F");
32659
+ if (!resolved.ok) return resolved;
32660
+ const { bookRoot: root } = resolved;
32661
+ const rawEp = args["\u96C6"];
32662
+ if (typeof rawEp !== "number" || !Number.isSafeInteger(rawEp) || rawEp < 1 || rawEp > 100) {
32663
+ return toolFailure("invalid-argument", `\u96C6\u5FC5\u987B\u662F 1\u2013100 \u7684\u6574\u6570\uFF08\u6536\u5230\uFF1A${String(rawEp ?? "\u672A\u4F20")}\uFF09`);
32664
+ }
32665
+ const rawText = typeof args["\u6B63\u6587"] === "string" ? args["\u6B63\u6587"].trim() : "";
32666
+ if (rawText === "") {
32667
+ return toolFailure("invalid-argument", "\u6B63\u6587\u4E0D\u80FD\u4E3A\u7A7A\uFF0C\u8BF7\u4F20\u5165\u5355\u96C6\u5267\u672C Markdown \u5168\u6587\u3002");
32668
+ }
32669
+ const parsed = parseEpisodeScript(rawText);
32670
+ if (!parsed.ok || parsed.episode === void 0) {
32671
+ return { ...toolFailure("parse-error", `\u77ED\u5267\u683C\u5F0F\u6821\u9A8C\u672A\u901A\u8FC7\uFF1A${parsed.problems.join("\uFF1B")}`), saved: false };
32672
+ }
32673
+ if (parsed.episode.\u96C6 !== rawEp) {
32674
+ return { ...toolFailure("invalid-argument", `\u96C6\u53F7\u4E0D\u4E00\u81F4\uFF1A\u53C2\u6570\u4E3A\u96C6${rawEp}\uFF0C\u6B63\u6587\u6807\u9898\u4E3A\u96C6${parsed.episode.\u96C6}`), saved: false };
32675
+ }
32676
+ const rendered = renderEpisodeScript(parsed.episode);
32677
+ const draftPath = `\u8349\u7A3F\u533A/${rendered.path}`;
32678
+ const access = gateFileAccess(root, draftPath);
32679
+ if (!access.allow || access.zone !== "\u8349\u7A3F\u533A") {
32680
+ return toolFailure("runtime-link", `\u77ED\u5267\u8349\u7A3F\u76EE\u6807\u5FC5\u987B\u7559\u5728\u8349\u7A3F\u533A\uFF0C\u8BF7\u6838\u5BF9\u76EE\u5F55\u94FE\u63A5\uFF1A${access.allow ? draftPath : access.reason}`);
32681
+ }
32682
+ const normalized = rawText.endsWith("\n") ? rawText : `${rawText}
32683
+ `;
32684
+ exec?.signal?.throwIfAborted();
32685
+ await deps.writeDraft(root, { relPath: draftPath, content: normalized }, exec);
32686
+ if (fs56.readFileSync(path68.join(root, draftPath), "utf8") !== normalized) {
32687
+ return { ...toolFailure("internal", "\u77ED\u5267\u8349\u7A3F\u4FDD\u5B58\u540E\u8BFB\u56DE\u6B63\u6587\u4E0D\u4E00\u81F4\uFF0C\u8BF7\u6838\u5BF9\u5B9E\u9645\u6587\u4EF6\u540E\u518D\u7EE7\u7EED\u3002"), saved: false };
32688
+ }
32689
+ return {
32690
+ ok: true,
32691
+ path: draftPath,
32692
+ finalPath: rendered.path,
32693
+ saved: true,
32694
+ \u8B66\u544A: rendered.\u8B66\u544A,
32695
+ message: `\u77ED\u5267\u7B2C ${rawEp} \u96C6\u8349\u7A3F\u5DF2\u4FDD\u5B58\uFF08${draftPath}\uFF09\uFF0C\u5C1A\u5F85\u8282\u62CD\u68C0\u67E5\u3001\u5BA1\u8BFB\u4E0E\u5B9A\u7A3F\u5165\u6863\u3002`
32696
+ };
32697
+ } catch (error) {
32698
+ if (exec?.signal?.aborted) throw error;
32699
+ return { ...failureFrom(error, "\u77ED\u5267\u8349\u7A3F\u4FDD\u5B58\u5931\u8D25\uFF1A"), saved: false };
32700
+ }
32701
+ }
31908
32702
  function createShortdramaTools(deps) {
31909
32703
  return SHORTDRAMA_TOOL_DEFINITIONS.map((tool) => {
32704
+ if (tool.name === "novel_shortdrama_settle_episode") {
32705
+ return {
32706
+ ...tool,
32707
+ execute: (args, exec) => executeSettleEpisode(deps, args, exec)
32708
+ };
32709
+ }
32710
+ if (tool.name === "novel_shortdrama_save_script") {
32711
+ return {
32712
+ ...tool,
32713
+ execute: (args, exec) => executeSaveScript(deps, args, exec)
32714
+ };
32715
+ }
31910
32716
  if (tool.name !== "novel_shortdrama_render_episode") return tool;
31911
32717
  const parameters = tool.parameters;
31912
32718
  return {
@@ -31918,19 +32724,17 @@ function createShortdramaTools(deps) {
31918
32724
  required: ["bookId", ...parameters.required]
31919
32725
  },
31920
32726
  execute: async (args, exec) => {
31921
- const bookId2 = typeof args["bookId"] === "string" ? args["bookId"].trim() : "";
31922
- if (bookId2 === "") return toolFailure("book-not-found", "bookId \u5FC5\u586B\uFF0C\u8BF7\u5148\u6838\u5BF9\u5F53\u524D\u77ED\u5267\u4E66\u76EE\u3002");
31923
32727
  try {
31924
- const root = deps.bookRootOfBookId(bookId2, exec?.agent);
31925
- if (root === void 0) return toolFailure("book-not-found", `\u4E66id\u4E0D\u5B58\u5728\u6216\u4E0D\u552F\u4E00\uFF1A${bookId2}`);
31926
- if (readExistingContract(root).fields["\u8F93\u51FA\u5F62\u6001"] !== "\u77ED\u5267") return toolFailure("invalid-argument", "\u4F5C\u54C1\u5951\u7EA6\u7684\u8F93\u51FA\u5F62\u6001\u5FC5\u987B\u662F\u77ED\u5267\uFF0C\u4E0D\u80FD\u4FDD\u5B58\u5230\u5176\u4ED6\u9879\u76EE\u3002");
32728
+ const resolved = resolveShortdramaBook(deps, args["bookId"], exec, "\u4FDD\u5B58\u5230\u5176\u4ED6\u9879\u76EE");
32729
+ if (!resolved.ok) return resolved;
32730
+ const { bookRoot: root } = resolved;
31927
32731
  const rendered = renderEpisodeScript(args);
31928
32732
  const draftPath = `\u8349\u7A3F\u533A/${rendered.path}`;
31929
32733
  const access = gateFileAccess(root, draftPath);
31930
32734
  if (!access.allow || access.zone !== "\u8349\u7A3F\u533A") return toolFailure("runtime-link", `\u77ED\u5267\u8349\u7A3F\u76EE\u6807\u5FC5\u987B\u7559\u5728\u8349\u7A3F\u533A\uFF0C\u8BF7\u6838\u5BF9\u76EE\u5F55\u94FE\u63A5\uFF1A${access.allow ? draftPath : access.reason}`);
31931
32735
  exec?.signal?.throwIfAborted();
31932
32736
  await deps.writeDraft(root, { relPath: draftPath, content: rendered.\u5185\u5BB9 }, exec);
31933
- if (fs54.readFileSync(path66.join(root, draftPath), "utf8") !== rendered.\u5185\u5BB9) {
32737
+ if (fs56.readFileSync(path68.join(root, draftPath), "utf8") !== rendered.\u5185\u5BB9) {
31934
32738
  return { ...toolFailure("internal", "\u77ED\u5267\u8349\u7A3F\u4FDD\u5B58\u540E\u8BFB\u56DE\u6B63\u6587\u4E0D\u4E00\u81F4\uFF0C\u8BF7\u6838\u5BF9\u5B9E\u9645\u6587\u4EF6\u540E\u518D\u7EE7\u7EED\u3002"), saved: false };
31935
32739
  }
31936
32740
  return { ok: true, ...rendered, path: draftPath, finalPath: rendered.path, saved: true, message: "\u77ED\u5267\u8349\u7A3F\u5DF2\u4FDD\u5B58\u5E76\u8BFB\u56DE\u6838\u9A8C\uFF0C\u5C1A\u5F85\u8282\u62CD\u68C0\u67E5\u3001\u5BA1\u8BFB\u548C\u4F5C\u8005\u786E\u8BA4\u3002" };
@@ -31943,38 +32747,89 @@ function createShortdramaTools(deps) {
31943
32747
  });
31944
32748
  }
31945
32749
 
31946
- // src/approval-snapshot.ts
31947
- import * as fs55 from "node:fs";
31948
- import * as path67 from "node:path";
31949
- import { createHash as createHash19 } from "node:crypto";
31950
- function captureApprovalFiles(root, relatives, request) {
31951
- try {
31952
- const files = [];
31953
- const visit = (relative12) => {
31954
- const target = authorDocumentPath(root, relative12);
31955
- try {
31956
- const stat = fs55.statSync(target);
31957
- if (stat.isDirectory()) {
31958
- const names = fs55.readdirSync(target).sort();
31959
- files.push([relative12 + "/", JSON.stringify(names)]);
31960
- for (const name3 of names) visit(path67.posix.join(relative12, name3));
31961
- } else if (stat.isFile()) {
31962
- files.push([relative12, createHash19("sha256").update(fs55.readFileSync(target)).digest("hex")]);
31963
- } else throw new Error(`\u4E0D\u662F\u666E\u901A\u6587\u4EF6\u6216\u76EE\u5F55\uFF1A${relative12}`);
31964
- } catch (error) {
31965
- if (error.code === "ENOENT") {
31966
- files.push([relative12, null]);
31967
- return;
31968
- }
31969
- throw error;
31970
- }
32750
+ // src/batch-approval.ts
32751
+ import { randomUUID as randomUUID8 } from "node:crypto";
32752
+ var DEFAULT_BATCH_TTL_MS = 4 * 60 * 60 * 1e3;
32753
+ function sessionKeyOf(exec) {
32754
+ return exec?.agent?.session?.header?.id ?? exec?.agent?.id ?? "default-session";
32755
+ }
32756
+ function storeKey(bookRoot, sessionKey) {
32757
+ return `${canonicalizePath(bookRoot)}::${sessionKey}`;
32758
+ }
32759
+ var BatchApprovalStore = class {
32760
+ grants = /* @__PURE__ */ new Map();
32761
+ async authorize(params) {
32762
+ if (!params.askFn) {
32763
+ return { ok: false, code: "host-unavailable", reason: "\u88C1\u51B3\u901A\u9053\u4E0D\u53EF\u7528\uFF1A\u5F53\u524D\u73AF\u5883\u65E0\u6CD5\u5F39\u51FA\u4F5C\u8005\u88C1\u51B3\u7A97\u53E3\uFF0C\u672A\u6388\u4E88\u6279\u91CF\u6258\u7BA1\u3002" };
32764
+ }
32765
+ const decision = await askAuthor(
32766
+ params.askFn,
32767
+ "\u5B9A\u7A3F\u5165\u6863",
32768
+ {
32769
+ \u8303\u56F4: `\u6279\u91CF\u6258\u7BA1\uFF08${params.\u8303\u56F4}\uFF09`,
32770
+ \u6458\u8981: params.\u6458\u8981
32771
+ },
32772
+ { agent: params.exec?.agent, signal: params.exec?.signal }
32773
+ );
32774
+ if (params.exec?.signal?.aborted) {
32775
+ return { ok: false, code: "author-cancelled", reason: "\u4F5C\u8005\u88C1\u51B3\u5DF2\u53D6\u6D88\uFF08\u4F1A\u8BDD\u5DF2\u4E2D\u6B62\uFF09\uFF0C\u672A\u6388\u4E88\u6279\u91CF\u6258\u7BA1\u3002" };
32776
+ }
32777
+ if (!decision.ok) {
32778
+ return { ok: false, code: classifyReason(decision.reason), reason: decision.reason };
32779
+ }
32780
+ if (decision.\u51B3\u5B9A !== "\u5DF2\u6279\u51C6") {
32781
+ return { ok: false, code: "author-declined", reason: `\u672A\u83B7\u4F5C\u8005\u6279\u51C6\uFF1A\u4F5C\u8005${decision.\u51B3\u5B9A}\uFF0C\u672A\u6388\u4E88\u6279\u91CF\u6258\u7BA1\u3002` };
32782
+ }
32783
+ const sessionKey = sessionKeyOf(params.exec);
32784
+ const normalizedRoot = canonicalizePath(params.bookRoot);
32785
+ const now = Date.now();
32786
+ const grant = {
32787
+ batchId: randomUUID8().slice(0, 8),
32788
+ bookRoot: normalizedRoot,
32789
+ sessionKey,
32790
+ \u8303\u56F4: params.\u8303\u56F4,
32791
+ targetType: params.targetType ?? "all",
32792
+ ...params.\u8D77\u53F7 === void 0 ? {} : { \u8D77\u53F7: params.\u8D77\u53F7 },
32793
+ ...params.\u6B62\u53F7 === void 0 ? {} : { \u6B62\u53F7: params.\u6B62\u53F7 },
32794
+ authorizedAt: new Date(now).toISOString(),
32795
+ kind: decision.kind,
32796
+ \u51B3\u5B9A: decision.\u51B3\u5B9A,
32797
+ expiresAt: now + DEFAULT_BATCH_TTL_MS
32798
+ };
32799
+ this.grants.set(storeKey(normalizedRoot, sessionKey), grant);
32800
+ return { ok: true, grant };
32801
+ }
32802
+ match(bookRoot, exec, targetType, itemNumber) {
32803
+ const key = storeKey(bookRoot, sessionKeyOf(exec));
32804
+ const grant = this.grants.get(key);
32805
+ if (grant === void 0) return void 0;
32806
+ if (Date.now() > grant.expiresAt) {
32807
+ this.grants.delete(key);
32808
+ return void 0;
32809
+ }
32810
+ if (grant.targetType !== "all" && grant.targetType !== targetType) return void 0;
32811
+ if (itemNumber !== void 0) {
32812
+ if (grant.\u8D77\u53F7 !== void 0 && itemNumber < grant.\u8D77\u53F7) return void 0;
32813
+ if (grant.\u6B62\u53F7 !== void 0 && itemNumber > grant.\u6B62\u53F7) return void 0;
32814
+ }
32815
+ return {
32816
+ batchId: grant.batchId,
32817
+ \u8303\u56F4: grant.\u8303\u56F4,
32818
+ \u88C1\u51B3\u8BB0\u5F55: `\u4F5C\u8005\u4E8E ${grant.authorizedAt} \u6279\u91CF\u6279\u51C6\u5B9A\u7A3F\u6258\u7BA1\uFF08batch=${grant.batchId}, \u8303\u56F4=${grant.\u8303\u56F4}, kind=${grant.kind}, \u51B3\u5B9A=${grant.\u51B3\u5B9A}\uFF09`
31971
32819
  };
31972
- for (const relative12 of [...new Set(relatives)].sort()) visit(relative12);
31973
- return { ok: true, fingerprint: createHash19("sha256").update(JSON.stringify([canonicalizePath(root), request, files])).digest("hex") };
31974
- } catch (error) {
31975
- return { ok: false, reason: `\u65E0\u6CD5\u6838\u5BF9\u4F5C\u8005\u88C1\u51B3\u5185\u5BB9\uFF1A${error instanceof Error ? error.message : String(error)}` };
31976
32820
  }
31977
- }
32821
+ clear(bookRoot, exec) {
32822
+ this.grants.delete(storeKey(bookRoot, sessionKeyOf(exec)));
32823
+ }
32824
+ hasAnyForSession(exec) {
32825
+ const key = sessionKeyOf(exec);
32826
+ const now = Date.now();
32827
+ for (const grant of this.grants.values()) {
32828
+ if (grant.sessionKey === key && now <= grant.expiresAt) return true;
32829
+ }
32830
+ return false;
32831
+ }
32832
+ };
31978
32833
 
31979
32834
  // src/story-status.ts
31980
32835
  function readStoryStatus(bookRoot) {
@@ -32079,8 +32934,8 @@ var MAINTENANCE_OUTPUT = {
32079
32934
  };
32080
32935
 
32081
32936
  // src/book-upgrade-tools.ts
32082
- import fs56 from "node:fs";
32083
- import path68 from "node:path";
32937
+ import fs57 from "node:fs";
32938
+ import path69 from "node:path";
32084
32939
  import { validateJsonSchemaValue as validateJsonSchemaValue2 } from "@deepseek-ai/dsh-tools";
32085
32940
 
32086
32941
  // src/book-upgrade-output.ts
@@ -32160,8 +33015,8 @@ var BOOK_UPGRADE_WRITE_OUTPUT = {
32160
33015
  var marker2 = { maintenance: "book-upgrade" };
32161
33016
  var cancelled = () => ({ ...marker2, ...toolFailure("author-cancelled", "\u4E66\u4ED3\u5347\u7EA7\u8BF7\u6C42\u5DF2\u53D6\u6D88\uFF0C\u672C\u6B21\u4E0D\u7EE7\u7EED\u5199\u5165\u3002") });
32162
33017
  var identity2 = (root) => {
32163
- const real = fs56.realpathSync.native(root);
32164
- return process.platform === "win32" ? path68.resolve(real).toLowerCase() : path68.resolve(real);
33018
+ const real = fs57.realpathSync.native(root);
33019
+ return process.platform === "win32" ? path69.resolve(real).toLowerCase() : path69.resolve(real);
32165
33020
  };
32166
33021
  function provenance(exec) {
32167
33022
  if (exec === void 0) return void 0;
@@ -32315,7 +33170,7 @@ function createBookUpgradeTools(deps) {
32315
33170
  }
32316
33171
 
32317
33172
  // src/novel-tools.ts
32318
- import * as fs60 from "node:fs";
33173
+ import * as fs61 from "node:fs";
32319
33174
  import * as nodePath3 from "node:path";
32320
33175
 
32321
33176
  // src/design-commit-result.ts
@@ -32781,14 +33636,14 @@ function onboardingMissing(answers) {
32781
33636
  }
32782
33637
 
32783
33638
  // src/study/onboarding-store.ts
32784
- import * as fs57 from "node:fs";
32785
- import * as path69 from "node:path";
33639
+ import * as fs58 from "node:fs";
33640
+ import * as path70 from "node:path";
32786
33641
  function onboardingDraftPath(workspaceRoot) {
32787
- return path69.join(workspaceRoot, ...ONBOARDING_DRAFT_RELATIVE.split("/"));
33642
+ return path70.join(workspaceRoot, ...ONBOARDING_DRAFT_RELATIVE.split("/"));
32788
33643
  }
32789
33644
  function readOnboardingDraft(workspaceRoot) {
32790
33645
  try {
32791
- const raw = fs57.readFileSync(onboardingDraftPath(workspaceRoot), "utf-8");
33646
+ const raw = fs58.readFileSync(onboardingDraftPath(workspaceRoot), "utf-8");
32792
33647
  return validateOnboardingAnswers(JSON.parse(raw));
32793
33648
  } catch {
32794
33649
  return {};
@@ -32796,27 +33651,27 @@ function readOnboardingDraft(workspaceRoot) {
32796
33651
  }
32797
33652
  function saveOnboardingDraft(workspaceRoot, answers) {
32798
33653
  const target = onboardingDraftPath(workspaceRoot);
32799
- fs57.mkdirSync(path69.dirname(target), { recursive: true });
32800
- fs57.writeFileSync(target, JSON.stringify({ ...answers, updatedAt: (/* @__PURE__ */ new Date()).toISOString() }, null, 2), "utf-8");
33654
+ fs58.mkdirSync(path70.dirname(target), { recursive: true });
33655
+ fs58.writeFileSync(target, JSON.stringify({ ...answers, updatedAt: (/* @__PURE__ */ new Date()).toISOString() }, null, 2), "utf-8");
32801
33656
  }
32802
33657
  function consumeOnboardingDraft(workspaceRoot) {
32803
33658
  try {
32804
- fs57.unlinkSync(onboardingDraftPath(workspaceRoot));
33659
+ fs58.unlinkSync(onboardingDraftPath(workspaceRoot));
32805
33660
  } catch {
32806
33661
  }
32807
33662
  }
32808
33663
 
32809
33664
  // ../drafting/src/context.ts
32810
- import * as fs58 from "node:fs";
32811
- import * as path70 from "node:path";
32812
-
32813
- // ../drafting/src/write.ts
32814
33665
  import * as fs59 from "node:fs";
32815
33666
  import * as path71 from "node:path";
33667
+
33668
+ // ../drafting/src/write.ts
33669
+ import * as fs60 from "node:fs";
33670
+ import * as path72 from "node:path";
32816
33671
  var DRAFT_KEYS = ["\u8EAB\u4EFD", "\u7248\u672C", "\u7236\u7248\u672C", "\u751F\u6210\u6A21\u5757", "\u6765\u6E90\u5FEB\u7167", "\u89D2\u8272", "\u9009\u5B9A"];
32817
33672
  function readText12(root, rel) {
32818
33673
  try {
32819
- return fs59.readFileSync(path71.join(root, rel), "utf-8");
33674
+ return fs60.readFileSync(path72.join(root, rel), "utf-8");
32820
33675
  } catch {
32821
33676
  return null;
32822
33677
  }
@@ -32825,9 +33680,9 @@ function draftDir(key) {
32825
33680
  return paths.\u8349\u7A3F\u76EE\u5F55(key.\u5377, key.\u7AE0\u540D);
32826
33681
  }
32827
33682
  function listDraftFiles(bookRoot, key) {
32828
- const abs = path71.join(bookRoot, draftDir(key));
32829
- if (!fs59.existsSync(abs) || !fs59.statSync(abs).isDirectory()) return [];
32830
- return fs59.readdirSync(abs).filter((f) => f.endsWith(".md")).sort((a, b) => a.localeCompare(b, "zh"));
33683
+ const abs = path72.join(bookRoot, draftDir(key));
33684
+ if (!fs60.existsSync(abs) || !fs60.statSync(abs).isDirectory()) return [];
33685
+ return fs60.readdirSync(abs).filter((f) => f.endsWith(".md")).sort((a, b) => a.localeCompare(b, "zh"));
32831
33686
  }
32832
33687
  function parseDraftNo(file) {
32833
33688
  const m = /^稿(\d+)\.md$/.exec(file);
@@ -32836,7 +33691,7 @@ function parseDraftNo(file) {
32836
33691
  function latestVersion(bookRoot, key) {
32837
33692
  let max = null;
32838
33693
  for (const file of listDraftFiles(bookRoot, key)) {
32839
- const text5 = readText12(bookRoot, path71.posix.join(draftDir(key), file));
33694
+ const text5 = readText12(bookRoot, path72.posix.join(draftDir(key), file));
32840
33695
  if (text5 === null) continue;
32841
33696
  const doc = parseDocument(text5);
32842
33697
  if (!doc.ok) continue;
@@ -32863,7 +33718,7 @@ function selectDraftLocked(bookRoot, input) {
32863
33718
  const files = listDraftFiles(bookRoot, input);
32864
33719
  if (!files.includes(target)) return { ok: false, reason: `\u8349\u7A3F\u4E0D\u5B58\u5728:${target}` };
32865
33720
  for (const file of files) {
32866
- const rel = path71.posix.join(dir, file);
33721
+ const rel = path72.posix.join(dir, file);
32867
33722
  const text5 = readText12(bookRoot, rel);
32868
33723
  if (text5 === null) continue;
32869
33724
  const doc = parseDocument(text5);
@@ -32887,7 +33742,7 @@ function writeDraftLocked(bookRoot, input) {
32887
33742
  const parent = latestVersion(bookRoot, key);
32888
33743
  const ver = parent === null ? initialVersion("\u5199\u7A3F") : bumpVersion(parent, "\u5199\u7A3F");
32889
33744
  const file = nextFileName(bookRoot, key);
32890
- const relPath = path71.posix.join(draftDir(key), file);
33745
+ const relPath = path72.posix.join(draftDir(key), file);
32891
33746
  const fields = applyVersionFields(
32892
33747
  {
32893
33748
  \u8EAB\u4EFD: { \u5377: input.\u5377, \u7AE0: input.\u7AE0, \u7AE0\u540D: input.\u7AE0\u540D },
@@ -32919,7 +33774,7 @@ function importAuthorDraftLocked(bookRoot, input) {
32919
33774
  const explicitParent = input.\u7236\u7248\u672C ?? latestVersion(bookRoot, key);
32920
33775
  const ver = explicitParent === null ? initialVersion("\u4F5C\u8005\u7A3F\u5BFC\u5165") : bumpVersion(explicitParent, "\u4F5C\u8005\u7A3F\u5BFC\u5165");
32921
33776
  const file = nextFileName(bookRoot, key);
32922
- const relPath = path71.posix.join(draftDir(key), file);
33777
+ const relPath = path72.posix.join(draftDir(key), file);
32923
33778
  const fields = applyVersionFields(
32924
33779
  {
32925
33780
  \u8EAB\u4EFD: { \u5377: input.\u5377, \u7AE0: input.\u7AE0, \u7AE0\u540D: input.\u7AE0\u540D },
@@ -32950,6 +33805,7 @@ function provenanceOf(ctx, targets) {
32950
33805
  }
32951
33806
  var NOVEL_TEST_TOOL_NAMES = ["novel_seed_min_design"];
32952
33807
  function createNovelTools(deps) {
33808
+ const batchStore = new BatchApprovalStore();
32953
33809
  async function writeNative(root, op, exec) {
32954
33810
  if (deps.nativeWrite === void 0) throw new Error("DSH \u539F\u751F write \u4E0D\u53EF\u7528\uFF0C\u62D2\u7EDD\u65E0\u7248\u672C\u4FDD\u62A4\u7684\u5199\u5165");
32955
33811
  updateOperationTargets(root, void 0, [op.relPath]);
@@ -32984,7 +33840,6 @@ function createNovelTools(deps) {
32984
33840
  if (\u7AE0\u540D === "") return { ok: false, reason: "\u7AE0\u540D\u4E0D\u80FD\u4E3A\u7A7A\uFF08\u987B\u4E0E\u8FD1\u671F\u7A97\u53E3\u6761\u76EE\u9010\u5B57\u4E00\u81F4\uFF09" };
32985
33841
  return { ok: true, key: { \u5377, \u7AE0, \u7AE0\u540D } };
32986
33842
  };
32987
- const notApproved = (reason) => /取消|abort/i.test(reason) ? toolFailure("author-cancelled", `\u4F5C\u8005\u88C1\u51B3\u5DF2\u53D6\u6D88\uFF0C\u6CA1\u6709\u505A\u51FA\u51B3\u5B9A\uFF08${reason}\uFF09\uFF0C\u672C\u6B21\u6CA1\u6709\u5199\u5165`) : toolFailure("author-declined", `\u672A\u83B7\u4F5C\u8005\u6279\u51C6\uFF1A${reason}`);
32988
33843
  const memoryProperties = {
32989
33844
  \u540D\u79F0: { type: "string", description: "\u4E00\u4E8B\u4E00\u6761\uFF1B\u540C\u4E00\u4E8B\u9879\u6CBF\u7528\u5DF2\u6709\u540D\u79F0" },
32990
33845
  \u63CF\u8FF0: { type: "string", description: "\u4E00\u53E5\u8BDD\u8BF4\u660E\u4EE5\u540E\u4F55\u65F6\u9700\u8981\u8FD9\u6761\u8BB0\u5FC6" },
@@ -33076,14 +33931,14 @@ function createNovelTools(deps) {
33076
33931
  },
33077
33932
  {
33078
33933
  name: "novel_create_book",
33079
- 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\u3002\u5E02\u573A\uFF1A\u8FD9\u4E2A\u9879\u76EE\u9762\u5411\u6D77\u5916\u8FD8\u662F\u4E2D\u6587\u5E02\u573A\uFF1F\u8F93\u51FA\u5F62\u6001\uFF1A\u8981\u51FA\u77ED\u5267\u3001\u7535\u5F71\u5267\u672C\u8FD8\u662F\u5C0F\u8BF4\uFF1F\u76EE\u6807\u603B\u5B57\u6570\uFF08\u6C49\u5B57\u6570\uFF09\uFF1A\u8FD9\u672C\u4E66\u76EE\u6807\u5199\u591A\u5C11\u5B57\uFF1F\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",
33934
+ description: "\u65B0\u5EFA\u4F5C\u54C1\u5E76\u521D\u59CB\u5316\u89C4\u8303\u4E66\u4ED3\uFF08\u652F\u6301\u77ED\u5267\u3001\u7535\u5F71\u5267\u672C\u3001\u5C0F\u8BF4\uFF09\u3002\u524D\u7F6E\u8981\u6C42\uFF1A\u4E03\u4E2A\u6784\u60F3\u5B57\u6BB5\u9F50\u5168\uFF08\u672A\u5B9A\u5904\u53EF\u586B\u7559\u767D\uFF09\uFF1B\u4F5C\u8005\u5DF2\u786E\u8BA4\u7ACB\u9879\u3002\u5EFA\u4E66\u524D\u9700\u660E\u786E\u5E02\u573A\uFF08\u4E2D\u6587/\u6D77\u5916\uFF09\u4E0E\u8F93\u51FA\u5F62\u6001\uFF08\u77ED\u5267/\u7535\u5F71\u5267\u672C/\u5C0F\u8BF4\uFF09\uFF1B\u77ED\u5267\u4E0E\u7535\u5F71\u5267\u672C\u53EF\u7701\u7565\u76EE\u6807\u603B\u5B57\u6570\uFF08\u5DE5\u5177\u81EA\u52A8\u6309\u5F62\u6001\u6298\u7B97\uFF09\uFF0C\u5C0F\u8BF4\u9700\u660E\u786E\u76EE\u6807\u603B\u5B57\u6570\u3002\u82E5\u4E66\u623F\u9762\u677F\u300C\u65B0\u5EFA\u4E66\u300D\u5411\u5BFC\u5DF2\u4FDD\u5B58 _\u5F85\u5EFA\u4E66.json\uFF0C\u76F4\u63A5\u6CBF\u7528\u5176\u503C\uFF0C\u4E0D\u8981\u91CD\u590D\u8BE2\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",
33080
33935
  parameters: {
33081
33936
  type: "object",
33082
33937
  properties: {
33083
- bookName: { type: "string", description: "\u5C0F\u8BF4\u4E66\u540D\uFF08\u4E0D\u53EF\u542B\u8DEF\u5F84\u5B57\u7B26\u4E0E\u4FDD\u7559\u5B57\uFF09" },
33084
- \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" },
33085
- \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" },
33086
- \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" },
33938
+ bookName: { type: "string", description: "\u4F5C\u54C1\u4E66\u540D\uFF08\u4E0D\u53EF\u542B\u8DEF\u5F84\u5B57\u7B26\u4E0E\u4FDD\u7559\u5B57\uFF09" },
33939
+ \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\u9876\u5C42\u53C2\u6570\u4F18\u5148\u4E8E concept \u91CC\u7684\u540C\u540D\u5B57\u6BB5\u3002" },
33940
+ \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\u77ED\u5267\u8D70\u6309\u96C6\u6D41\u6C34\u7EBF\uFF0C\u7535\u5F71\u5267\u672C\u8D70\u5267\u672C\u6D41\u6C34\u7EBF\uFF0C\u5C0F\u8BF4\u8D70\u957F\u7BC7\u6D41\u6C34\u7EBF\u3002\u9876\u5C42\u53C2\u6570\u4F18\u5148\u4E8E concept \u91CC\u7684\u540C\u540D\u5B57\u6BB5\u3002" },
33941
+ \u76EE\u6807\u603B\u5B57\u6570: { type: "integer", minimum: 1, description: "\u76EE\u6807\u603B\u5B57\u6570\uFF08\u6C49\u5B57\u6570\uFF0C\u6B63\u6574\u6570\uFF1B\u77ED\u5267\u4E0E\u7535\u5F71\u5267\u672C\u53EF\u7701\u7565\u81EA\u52A8\u6298\u7B97\uFF1B\u5C0F\u8BF4\u9700\u786E\u8BA4\uFF09\u3002\u9876\u5C42\u53C2\u6570\u4F18\u5148\u4E8E concept \u91CC\u7684\u540C\u540D\u5B57\u6BB5\u3002" },
33087
33942
  concept: {
33088
33943
  type: "object",
33089
33944
  description: "\u4F5C\u54C1\u6784\u60F3\u4E03\u8981\u7D20\uFF08\u72B6\u6001\u5FC5\u987B\u4E3A\u5DF2\u786E\u8BA4\uFF09",
@@ -33096,9 +33951,9 @@ function createNovelTools(deps) {
33096
33951
  \u6838\u5FC3\u770B\u70B9: { type: "string" },
33097
33952
  \u5DEE\u5F02\u5316\u65B9\u5411: { type: "string" },
33098
33953
  \u660E\u786E\u4E0D\u8981\u4EC0\u4E48: { type: "string" },
33099
- \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" },
33100
- \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" },
33101
- \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" }
33954
+ \u5E02\u573A: { type: "string", enum: [...MARKET_VALUES], description: "\u76EE\u6807\u5E02\u573A\uFF1A\u6D77\u5916\u6216\u4E2D\u6587" },
33955
+ \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" },
33956
+ \u76EE\u6807\u603B\u5B57\u6570: { type: "integer", minimum: 1, description: "\u76EE\u6807\u603B\u5B57\u6570\uFF08\u6C49\u5B57\u6570\uFF0C\u6B63\u6574\u6570\uFF09" }
33102
33957
  },
33103
33958
  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"]
33104
33959
  }
@@ -33128,13 +33983,17 @@ function createNovelTools(deps) {
33128
33983
  const \u5E02\u573A = args["\u5E02\u573A"] ?? concept.\u5E02\u573A ?? draft.\u5E02\u573A;
33129
33984
  const \u8F93\u51FA\u5F62\u6001 = args["\u8F93\u51FA\u5F62\u6001"] ?? concept.\u8F93\u51FA\u5F62\u6001 ?? draft.\u8F93\u51FA\u5F62\u6001;
33130
33985
  const rawWords = args["\u76EE\u6807\u603B\u5B57\u6570"] ?? concept.\u76EE\u6807\u603B\u5B57\u6570 ?? draft.\u76EE\u6807\u603B\u5B57\u6570;
33131
- const \u76EE\u6807\u603B\u5B57\u6570 = typeof rawWords === "string" ? Number(rawWords) : rawWords;
33986
+ let \u76EE\u6807\u603B\u5B57\u6570 = typeof rawWords === "string" ? Number(rawWords) : rawWords;
33987
+ if (\u76EE\u6807\u603B\u5B57\u6570 === void 0 && (\u8F93\u51FA\u5F62\u6001 === "\u77ED\u5267" || \u8F93\u51FA\u5F62\u6001 === "\u7535\u5F71\u5267\u672C")) {
33988
+ \u76EE\u6807\u603B\u5B57\u6570 = \u8F93\u51FA\u5F62\u6001 === "\u77ED\u5267" ? 1e5 : 5e4;
33989
+ }
33132
33990
  const missing = onboardingMissing({ \u5E02\u573A, \u8F93\u51FA\u5F62\u6001, \u76EE\u6807\u603B\u5B57\u6570 });
33133
33991
  if (missing.length > 0) {
33992
+ const draftHint = Object.keys(draft).length > 0 ? `\uFF08\u5411\u5BFC\u8349\u7A3F\u5DF2\u6709\uFF1A${JSON.stringify(draft)}\uFF09` : "";
33134
33993
  return toolFailure(
33135
33994
  "invalid-argument",
33136
- `\u5EFA\u4E66\u524D\u5FC5\u987B\u5148\u786E\u8BA4${missing.join("\u3001")}\uFF0C\u7F3A\u4E86\u4E0D\u80FD\u5EFA\u4E66\u3002`,
33137
- `\u5148\u95EE\u4F5C\u8005\uFF0C\u540C\u4E00\u6761\u6D88\u606F\u4E00\u6B21\u95EE\u5B8C\uFF0C\u5404\u7ED9\u9009\u9879\u3002\u4F5C\u8005\u4E5F\u53EF\u4EE5\u5728\u4E66\u623F\u9762\u677F\u70B9\u201C\u65B0\u5EFA\u4E66\u201D\u76F4\u63A5\u70B9\u9009\uFF1B\u9009\u597D\u540E\u76F4\u63A5\u91CD\u8C03\u672C\u5DE5\u5177\u3002\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\uFF09\uFF1B\u53E6\u53EF\u9009\uFF1A5. \u81EA\u5DF1\u6709\u60F3\u6CD5\uFF0C\u624B\u52A8\u8F93\u5165\u5177\u4F53\u6570\u5B57\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`
33995
+ `\u5EFA\u4E66\u524D\u5FC5\u987B\u5148\u786E\u8BA4${missing.join("\u3001")}\uFF0C\u7F3A\u4E86\u4E0D\u80FD\u5EFA\u4E66\u3002${draftHint}`,
33996
+ `\u5148\u95EE\u4F5C\u8005\uFF0C\u540C\u4E00\u6761\u6D88\u606F\u4E00\u6B21\u95EE\u5B8C\u7F3A\u5931\u9879${draftHint}\uFF1B\u4F5C\u8005\u4E5F\u53EF\u4EE5\u5728\u4E66\u623F\u9762\u677F\u70B9\u201C\u65B0\u5EFA\u4E66\u201D\u76F4\u63A5\u70B9\u9009\u3002\u5E02\u573A\uFF081. \u4E2D\u6587 2. \u6D77\u5916\uFF09\uFF1B\u8F93\u51FA\u5F62\u6001\uFF081. \u77ED\u5267 2. \u7535\u5F71\u5267\u672C 3. \u5C0F\u8BF4\uFF09\uFF1B\u76EE\u6807\u603B\u5B57\u6570\uFF08\u4EC5\u5C0F\u8BF4\u5FC5\u586B\uFF1A1. \u77ED\u7BC7\xB75\u4E07\u5B57 2. \u4E2D\u7BC7\xB730\u4E07\u5B57 3. \u957F\u7BC7\xB7100\u4E07\u5B57 4. \u8D85\u957F\u7BC7\xB7200\u4E07\u5B57\uFF0C\u6216\u76F4\u63A5\u8F93\u6570\u5B57\uFF09\u3002\u62FF\u5230\u7B54\u6848\u518D\u8C03 novel_create_book\u3002`
33138
33997
  );
33139
33998
  }
33140
33999
  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`);
@@ -33256,7 +34115,7 @@ function createNovelTools(deps) {
33256
34115
  paths.\u5377\u7EB2(\u5377),
33257
34116
  paths.\u8BA1\u5212\u65F6\u95F4\u7EBF(\u5377),
33258
34117
  paths.\u8FD1\u671F\u7A97\u53E3(\u5377)
33259
- ].filter((p) => fs60.existsSync(nodePath3.join(bookRoot, p)));
34118
+ ].filter((p) => fs61.existsSync(nodePath3.join(bookRoot, p)));
33260
34119
  const commit = commitConfirmed({ bookRoot, paths: seedPaths, prefix: "design", summary: "\u6700\u5C0F\u8BBE\u8BA1\u9AA8\u67B6", provenance: provenanceOf(sessionContext, seedPaths) });
33261
34120
  if (!commit.ok) {
33262
34121
  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}` };
@@ -33586,20 +34445,33 @@ function createNovelTools(deps) {
33586
34445
  render: (_args, value) => [{ type: "text", text: JSON.stringify(value, null, 2) }]
33587
34446
  },
33588
34447
  execute: async (args, sessionContext) => {
33589
- if (!deps.askFn) return toolFailure("host-unavailable", "\u88C1\u51B3\u901A\u9053\u4E0D\u53EF\u7528\uFF1A\u5F53\u524D\u73AF\u5883\u65E0\u6CD5\u5F39\u51FA\u4F5C\u8005\u88C1\u51B3\u7A97\u53E3\uFF0C\u672C\u6B21\u6CA1\u6709\u5199\u5165");
34448
+ const mode = deps.automationMode?.() ?? "manual";
34449
+ if (!deps.askFn && (mode === "manual" || !batchStore.hasAnyForSession(sessionContext))) {
34450
+ return toolFailure("host-unavailable", "\u88C1\u51B3\u901A\u9053\u4E0D\u53EF\u7528\uFF1A\u5F53\u524D\u73AF\u5883\u65E0\u6CD5\u5F39\u51FA\u4F5C\u8005\u88C1\u51B3\u7A97\u53E3\uFF0C\u672C\u6B21\u6CA1\u6709\u5199\u5165");
34451
+ }
33590
34452
  const book = resolveBook(args, sessionContext);
33591
34453
  if (!book.ok) return book;
33592
34454
  const bookRoot = book.bookRoot;
33593
34455
  const keyResult = chapterKeyOf(args);
33594
34456
  if (!keyResult.ok) return keyResult;
33595
34457
  const key = keyResult.key;
34458
+ const batchMatch = mode !== "manual" ? batchStore.match(bookRoot, sessionContext, "chapter", key.\u7AE0) : void 0;
34459
+ if (!batchMatch && !deps.askFn) return toolFailure("host-unavailable", "\u88C1\u51B3\u901A\u9053\u4E0D\u53EF\u7528\uFF1A\u5F53\u524D\u73AF\u5883\u65E0\u6CD5\u5F39\u51FA\u4F5C\u8005\u88C1\u51B3\u7A97\u53E3\uFF0C\u672C\u6B21\u6CA1\u6709\u5199\u5165");
33596
34460
  const approvalFiles = [paths.\u5F85\u5B9A\u7A3F\u5305\u76EE\u5F55(key.\u5377, key.\u7AE0\u540D), paths.\u5951\u7EA6()];
33597
34461
  const before = captureApprovalFiles(bookRoot, approvalFiles, args);
33598
34462
  if (!before.ok) return before;
33599
- const decision = await askAuthor(deps.askFn, "\u5B9A\u7A3F\u5165\u6863", { \u8303\u56F4: `\u5377${key.\u5377.toString().padStart(2, "0")}/${key.\u7AE0\u540D}` }, { agent: sessionContext?.agent, signal: sessionContext?.signal });
33600
- if (!decision.ok) return notApproved(decision.reason);
33601
- if (sessionContext?.signal?.aborted) return toolFailure("author-cancelled", "\u4F5C\u8005\u88C1\u51B3\u5DF2\u53D6\u6D88\uFF08\u4F1A\u8BDD\u5DF2\u4E2D\u6B62\uFF09\uFF0C\u6CA1\u6709\u505A\u51FA\u51B3\u5B9A\uFF0C\u672C\u6B21\u6CA1\u6709\u5199\u5165");
33602
- const \u88C1\u51B3 = decision.\u51B3\u5B9A === "\u5DF2\u6279\u51C6" ? "\u5DF2\u6279\u51C6" : "\u5DF2\u9000\u56DE";
34463
+ let \u88C1\u51B3;
34464
+ let \u88C1\u51B3\u8BB0\u5F55\u6587\u672C;
34465
+ if (batchMatch) {
34466
+ \u88C1\u51B3 = "\u5DF2\u6279\u51C6";
34467
+ \u88C1\u51B3\u8BB0\u5F55\u6587\u672C = batchMatch.\u88C1\u51B3\u8BB0\u5F55;
34468
+ } else {
34469
+ const decision = await askAuthor(deps.askFn, "\u5B9A\u7A3F\u5165\u6863", { \u8303\u56F4: `\u5377${key.\u5377.toString().padStart(2, "0")}/${key.\u7AE0\u540D}` }, { agent: sessionContext?.agent, signal: sessionContext?.signal });
34470
+ if (!decision.ok) return notApproved(decision.reason);
34471
+ if (sessionContext?.signal?.aborted) return toolFailure("author-cancelled", "\u4F5C\u8005\u88C1\u51B3\u5DF2\u53D6\u6D88\uFF08\u4F1A\u8BDD\u5DF2\u4E2D\u6B62\uFF09\uFF0C\u6CA1\u6709\u505A\u51FA\u51B3\u5B9A\uFF0C\u672C\u6B21\u6CA1\u6709\u5199\u5165");
34472
+ \u88C1\u51B3 = decision.\u51B3\u5B9A === "\u5DF2\u6279\u51C6" ? "\u5DF2\u6279\u51C6" : "\u5DF2\u9000\u56DE";
34473
+ \u88C1\u51B3\u8BB0\u5F55\u6587\u672C = `\u4F5C\u8005\u4E8E ${(/* @__PURE__ */ new Date()).toISOString()} \u6279\u51C6\u5B9A\u7A3F\u5165\u6863\uFF08kind=${decision.kind}, \u51B3\u5B9A=${decision.\u51B3\u5B9A}\uFF09`;
34474
+ }
33603
34475
  return withBookWrite(bookRoot, () => {
33604
34476
  if (sessionContext?.signal?.aborted) return toolFailure("author-cancelled", "\u4F5C\u8005\u88C1\u51B3\u5DF2\u53D6\u6D88\uFF08\u4F1A\u8BDD\u5DF2\u4E2D\u6B62\uFF09\uFF0C\u6CA1\u6709\u505A\u51FA\u51B3\u5B9A\uFF0C\u672C\u6B21\u6CA1\u6709\u5199\u5165");
33605
34477
  const currentBook = resolveBook(args, sessionContext);
@@ -33608,7 +34480,7 @@ function createNovelTools(deps) {
33608
34480
  if (!current.ok || current.fingerprint !== before.fingerprint) return toolFailure("approval-stale", "\u5F85\u5B9A\u7A3F\u5305\u5728\u7B49\u5F85\u4F5C\u8005\u88C1\u51B3\u671F\u95F4\u5DF2\u53D8\u5316\uFF0C\u65E7\u6279\u51C6\u4E0D\u53EF\u4F7F\u7528");
33609
34481
  const decisionWrite = writeSettlementDecision(bookRoot, key, \u88C1\u51B3);
33610
34482
  if (\u88C1\u51B3 !== "\u5DF2\u6279\u51C6") {
33611
- return toolFailure("author-declined", `\u672A\u83B7\u4F5C\u8005\u6279\u51C6\uFF1A\u4F5C\u8005${decision.\u51B3\u5B9A}\uFF0C\u672C\u7AE0\u6CA1\u6709\u5165\u6863`);
34483
+ return toolFailure("author-declined", `\u672A\u83B7\u4F5C\u8005\u6279\u51C6\uFF1A\u4F5C\u8005\u9000\u56DE\uFF0C\u672C\u7AE0\u6CA1\u6709\u5165\u6863`);
33612
34484
  }
33613
34485
  if (!decisionWrite.ok) return { ok: false, reason: decisionWrite.reason };
33614
34486
  try {
@@ -33616,11 +34488,15 @@ function createNovelTools(deps) {
33616
34488
  bookRoot,
33617
34489
  packageDir: paths.\u5F85\u5B9A\u7A3F\u5305\u76EE\u5F55(key.\u5377, key.\u7AE0\u540D),
33618
34490
  summary: String(args["summary"]).trim(),
33619
- settlement: { \u7AE0\u8282: key, \u6279\u51C6: true, \u88C1\u51B3\u8BB0\u5F55: `\u4F5C\u8005\u4E8E ${(/* @__PURE__ */ new Date()).toISOString()} \u6279\u51C6\u5B9A\u7A3F\u5165\u6863\uFF08kind=${decision.kind}, \u51B3\u5B9A=${decision.\u51B3\u5B9A}\uFF09` },
34491
+ settlement: { \u7AE0\u8282: key, \u6279\u51C6: true, \u88C1\u51B3\u8BB0\u5F55: \u88C1\u51B3\u8BB0\u5F55\u6587\u672C },
33620
34492
  provenance: provenanceOf(sessionContext)
33621
34493
  });
33622
34494
  if (!res.ok) return { ok: false, reason: res.reason };
33623
- return { ok: true, message: `\u5B9A\u7A3F\u6C89\u6DC0\u5B8C\u6210\uFF08${res.message}\uFF09\uFF0C\u5165\u6863\uFF1A${res.dests.join("\u3001")}` };
34495
+ return {
34496
+ ok: true,
34497
+ ...batchMatch ? { batchId: batchMatch.batchId } : {},
34498
+ message: `\u5B9A\u7A3F\u6C89\u6DC0\u5B8C\u6210\uFF08${res.message}\uFF09\uFF0C\u5165\u6863\uFF1A${res.dests.join("\u3001")}`
34499
+ };
33624
34500
  } catch (err) {
33625
34501
  return failureFrom(err, `\u5B9A\u7A3F\u6C89\u6DC0\u5931\u8D25\uFF1A`);
33626
34502
  }
@@ -33852,7 +34728,7 @@ function createNovelTools(deps) {
33852
34728
  const rel = paths.\u8FD1\u671F\u7A97\u53E3(\u5377);
33853
34729
  let text5 = "";
33854
34730
  try {
33855
- text5 = fs60.readFileSync(nodePath3.join(book.bookRoot, rel), "utf-8");
34731
+ text5 = fs61.readFileSync(nodePath3.join(book.bookRoot, rel), "utf-8");
33856
34732
  } catch {
33857
34733
  text5 = "";
33858
34734
  }
@@ -34046,6 +34922,7 @@ function createNovelTools(deps) {
34046
34922
  \u5377,
34047
34923
  \u7AE0,
34048
34924
  \u7AE0\u540D,
34925
+ \u8D28\u91CF\u6A21\u5F0F: true,
34049
34926
  ...Array.isArray(args["\u8865\u5145\u64CD\u4F5C"]) ? { \u8865\u5145\u64CD\u4F5C: args["\u8865\u5145\u64CD\u4F5C"] } : {},
34050
34927
  ...typeof args["\u6750\u6599\u6E05\u5355\u54C8\u5E0C"] === "string" ? { \u6750\u6599\u6E05\u5355\u54C8\u5E0C: args["\u6750\u6599\u6E05\u5355\u54C8\u5E0C"] } : {}
34051
34928
  };
@@ -34548,7 +35425,7 @@ function createNovelTools(deps) {
34548
35425
  const res = archiveRetconRequest({ bookRoot, chapter: \u5B9A\u7A3F\u76F8\u5BF9, request, provenance: provenanceOf(sessionContext) }, (plannedPackageDir) => {
34549
35426
  let \u66F4\u6B63\u540E\u5168\u6587;
34550
35427
  try {
34551
- const src = fs60.readFileSync(nodePath3.join(bookRoot, \u5B9A\u7A3F\u76F8\u5BF9), "utf-8");
35428
+ const src = fs61.readFileSync(nodePath3.join(bookRoot, \u5B9A\u7A3F\u76F8\u5BF9), "utf-8");
34552
35429
  const doc = parseDocument(src);
34553
35430
  if (!doc.ok) return { ok: false, reason: `\u5B9A\u7A3F\u7AE0\u89E3\u6790\u5931\u8D25\uFF1A${doc.detail}` };
34554
35431
  const parent = extractVersionFields(doc.data.fields).\u7248\u672C;
@@ -34576,19 +35453,19 @@ function createNovelTools(deps) {
34576
35453
  const value = optionalText(f);
34577
35454
  return value === null ? [] : [[\u5019\u9009\u6587\u4EF6[f], value]];
34578
35455
  }));
34579
- if (fs60.existsSync(\u5305\u7EDD\u5BF9)) {
34580
- for (const name3 of fs60.readdirSync(\u5305\u7EDD\u5BF9)) {
35456
+ if (fs61.existsSync(\u5305\u7EDD\u5BF9)) {
35457
+ for (const name3 of fs61.readdirSync(\u5305\u7EDD\u5BF9)) {
34581
35458
  const file = nodePath3.join(\u5305\u7EDD\u5BF9, name3);
34582
- const stat = fs60.lstatSync(file);
34583
- if (!contents.has(name3) || !stat.isFile() || stat.isSymbolicLink() || fs60.readFileSync(file, "utf8") !== contents.get(name3)) {
35459
+ const stat = fs61.lstatSync(file);
35460
+ if (!contents.has(name3) || !stat.isFile() || stat.isSymbolicLink() || fs61.readFileSync(file, "utf8") !== contents.get(name3)) {
34584
35461
  return { ok: false, reason: "\u8865\u507F\u5305\u5019\u9009\u51B2\u7A81\uFF0C\u5DF2\u4FDD\u7559\uFF0C\u8BF7\u6838\u5BF9\u540E\u5904\u7406" };
34585
35462
  }
34586
35463
  }
34587
35464
  }
34588
- fs60.mkdirSync(\u5305\u7EDD\u5BF9, { recursive: true });
35465
+ fs61.mkdirSync(\u5305\u7EDD\u5BF9, { recursive: true });
34589
35466
  for (const [name3, value] of contents) {
34590
35467
  const file = nodePath3.join(\u5305\u7EDD\u5BF9, name3);
34591
- if (!fs60.existsSync(file)) fs60.writeFileSync(file, value, { encoding: "utf8", flag: "wx" });
35468
+ if (!fs61.existsSync(file)) fs61.writeFileSync(file, value, { encoding: "utf8", flag: "wx" });
34592
35469
  }
34593
35470
  packageDir = \u5305\u76F8\u5BF9;
34594
35471
  }
@@ -34609,7 +35486,7 @@ function createNovelTools(deps) {
34609
35486
  retconFiles.push({ \u76EE\u6807: \u6458\u8981\u76F8\u5BF9, \u5185\u5BB9: request.\u66F4\u6B63\u540E\u7AE0\u6458\u8981 });
34610
35487
  } else {
34611
35488
  try {
34612
- const \u6458\u8981\u73B0\u6587 = fs60.readFileSync(nodePath3.join(bookRoot, \u6458\u8981\u76F8\u5BF9), "utf-8");
35489
+ const \u6458\u8981\u73B0\u6587 = fs61.readFileSync(nodePath3.join(bookRoot, \u6458\u8981\u76F8\u5BF9), "utf-8");
34613
35490
  retconFiles.push({
34614
35491
  \u76EE\u6807: \u6458\u8981\u76F8\u5BF9,
34615
35492
  \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")})
@@ -34884,14 +35761,89 @@ ${\u6458\u8981\u73B0\u6587}`
34884
35761
  render: (_args, value) => [{ type: "text", text: JSON.stringify(value, null, 2) }]
34885
35762
  },
34886
35763
  execute: (args, sessionContext) => acceptEditorSuggestion(deps.editorRequests, sessionContext?.agent, args)
35764
+ },
35765
+ {
35766
+ name: "novel_authorize_batch",
35767
+ description: "\u534A\u81EA\u52A8\u4E24\u6B65\u8D70\u6388\u6743\u5165\u53E3\uFF1A\u5F39\u51FA\u4E00\u6B21\u4F5C\u8005\u88C1\u51B3\u5361\uFF0C\u8BF7\u4F5C\u8005\u786E\u8BA4\u672C\u6279\u6B21\u8BBE\u8BA1/\u89C4\u5212\u65B9\u5411\u5E76\u6279\u51C6\u540E\u7EED\u6279\u91CF\u751F\u6210\u4E0E\u5B9A\u7A3F\u5165\u6863\uFF08\u5982 \u96C6001\u2013\u96C6005 / \u7B2C1\u20133\u7AE0 / \u7535\u5F71\u5267\u672C\u5168\u7247\uFF09\u3002\u6279\u51C6\u540E\uFF0C\u672C\u4F1A\u8BDD\u5185\u8BE5\u8303\u56F4\u5185\u7684 novel_settle_chapter / novel_shortdrama_settle_episode / novel_screenplay_settle \u5C06\u81EA\u52A8\u63A8\u8FDB\uFF0C\u4E0D\u518D\u9010\u7AE0\u9010\u96C6\u5F39\u7A97\u3002",
35768
+ parameters: {
35769
+ type: "object",
35770
+ properties: {
35771
+ bookId: { type: "string", description: "\u4E66id\uFF08\u5FC5\u586B\uFF09" },
35772
+ \u8303\u56F4: { type: "string", description: "\u672C\u6B21\u6279\u51C6\u7684\u8303\u56F4\u8BF4\u660E\uFF08\u5982\u300C\u96C6001\u2013\u96C6005\u300D\u300C\u7B2C1\u20133\u7AE0\u300D\u300C\u7535\u5F71\u5267\u672C\u5168\u7247\u300D\uFF09" },
35773
+ \u6458\u8981: { type: "string", description: "\u5DF2\u5448\u62A5\u7684\u8BBE\u8BA1\u4E0E\u5927\u7EB2\u6838\u5FC3\u6458\u8981\uFF0C\u5C55\u793A\u5728\u88C1\u51B3\u5361\u4F9B\u4F5C\u8005\u4E00\u6B21\u786E\u8BA4" },
35774
+ \u76EE\u6807\u7C7B\u578B: { type: "string", enum: ["chapter", "episode", "screenplay", "all"], description: "\u6258\u7BA1\u76EE\u6807\u7C7B\u578B\uFF0C\u9ED8\u8BA4 all" },
35775
+ \u8D77\u53F7: { type: "integer", minimum: 1, description: "\u53EF\u9009\u8D77\u59CB\u7AE0\u53F7\u6216\u96C6\u53F7" },
35776
+ \u6B62\u53F7: { type: "integer", minimum: 1, description: "\u53EF\u9009\u7ED3\u675F\u7AE0\u53F7\u6216\u96C6\u53F7" }
35777
+ },
35778
+ required: ["bookId", "\u8303\u56F4", "\u6458\u8981"]
35779
+ },
35780
+ output: {
35781
+ schema: {
35782
+ type: "object",
35783
+ properties: {
35784
+ ok: { type: "boolean" },
35785
+ batchId: { type: "string" },
35786
+ \u8303\u56F4: { type: "string" },
35787
+ automationMode: { type: "string" },
35788
+ message: { type: "string" },
35789
+ reason: { type: "string" }
35790
+ },
35791
+ required: ["ok"]
35792
+ },
35793
+ render: (_args, value) => [{ type: "text", text: JSON.stringify(value, null, 2) }]
35794
+ },
35795
+ execute: async (args, sessionContext) => {
35796
+ const book = resolveBook(args, sessionContext);
35797
+ if (!book.ok) return book;
35798
+ const \u8303\u56F4 = String(args["\u8303\u56F4"] ?? "").trim();
35799
+ const \u6458\u8981 = String(args["\u6458\u8981"] ?? "").trim();
35800
+ if (\u8303\u56F4 === "" || \u6458\u8981 === "") return toolFailure("invalid-argument", "\u8303\u56F4\u4E0E\u6458\u8981\u4E0D\u80FD\u4E3A\u7A7A\u3002");
35801
+ const mode = deps.automationMode?.() ?? "semi-auto";
35802
+ if (mode === "manual") {
35803
+ return toolFailure("invalid-argument", "\u5F53\u524D\u504F\u597D\u4E3A\u300C\u4E25\u683C\u9010\u9879\u786E\u8BA4\uFF08manual\uFF09\u300D\uFF0C\u4E0D\u652F\u6301\u6279\u91CF\u6258\u7BA1\uFF1B\u8BF7\u9010\u7AE0/\u9010\u96C6\u88C1\u51B3\uFF0C\u6216\u5728\u63D2\u4EF6\u8BBE\u7F6E\u5207\u6362\u4E3A\u534A\u81EA\u52A8\u4E24\u6B65\u8D70\u3002");
35804
+ }
35805
+ const targetType = ["chapter", "episode", "screenplay", "all"].includes(String(args["\u76EE\u6807\u7C7B\u578B"])) ? String(args["\u76EE\u6807\u7C7B\u578B"]) : "all";
35806
+ const \u8D77\u53F7 = typeof args["\u8D77\u53F7"] === "number" && Number.isSafeInteger(args["\u8D77\u53F7"]) ? args["\u8D77\u53F7"] : void 0;
35807
+ const \u6B62\u53F7 = typeof args["\u6B62\u53F7"] === "number" && Number.isSafeInteger(args["\u6B62\u53F7"]) ? args["\u6B62\u53F7"] : void 0;
35808
+ const granted = await batchStore.authorize({
35809
+ askFn: deps.askFn,
35810
+ bookRoot: book.bookRoot,
35811
+ \u8303\u56F4,
35812
+ \u6458\u8981,
35813
+ targetType,
35814
+ \u8D77\u53F7,
35815
+ \u6B62\u53F7,
35816
+ exec: sessionContext
35817
+ });
35818
+ if (!granted.ok) return toolFailure(granted.code, granted.reason);
35819
+ return {
35820
+ ok: true,
35821
+ batchId: granted.grant.batchId,
35822
+ \u8303\u56F4,
35823
+ automationMode: mode,
35824
+ message: `\u4F5C\u8005\u5DF2\u6279\u51C6\u6279\u91CF\u6258\u7BA1\uFF08${\u8303\u56F4}\uFF0Cbatch=${granted.grant.batchId}\uFF09\u3002\u73B0\u5728\u8BF7\u76F4\u63A5\u8FDE\u7EED\u5B8C\u6210\u672C\u6279\u89C4\u5212\u3001\u8D77\u8349/\u5267\u672C\u3001\u7CBE\u4FEE\u4E0E\u5B9A\u7A3F\u5165\u6863\uFF0C\u4E2D\u9014\u4E0D\u518D\u9010\u4E2A\u5F39\u7A97\u8BE2\u95EE\u3002`
35825
+ };
35826
+ }
34887
35827
  }
34888
35828
  ];
34889
35829
  tools.push(
34890
35830
  ...createScreenplayTools({
34891
35831
  bookRootOfBookId: deps.bookRootOfBookId,
34892
- readContractFields: (bookRoot) => readExistingContract(bookRoot).fields
35832
+ readContractFields: (bookRoot) => readExistingContract(bookRoot).fields,
35833
+ writeDraft: writeNative,
35834
+ askFn: deps.askFn,
35835
+ provenanceOf,
35836
+ automationMode: deps.automationMode,
35837
+ batchStore
34893
35838
  }),
34894
- ...createShortdramaTools({ bookRootOfBookId: deps.bookRootOfBookId, writeDraft: writeNative })
35839
+ ...createShortdramaTools({
35840
+ bookRootOfBookId: deps.bookRootOfBookId,
35841
+ writeDraft: writeNative,
35842
+ askFn: deps.askFn,
35843
+ provenanceOf,
35844
+ automationMode: deps.automationMode,
35845
+ batchStore
35846
+ })
34895
35847
  );
34896
35848
  const locked = /* @__PURE__ */ new Set([
34897
35849
  "novel_new_outline_draft",
@@ -34912,9 +35864,16 @@ ${\u6458\u8981\u73B0\u6587}`
34912
35864
  "novel_record_proposal",
34913
35865
  "novel_resolve_proposal",
34914
35866
  "novel_note_pending",
34915
- "novel_shortdrama_render_episode"
35867
+ "novel_shortdrama_render_episode",
35868
+ "novel_shortdrama_save_script",
35869
+ "novel_screenplay_save_draft"
35870
+ ]);
35871
+ const nativeTools = /* @__PURE__ */ new Set([
35872
+ ...NATIVE_DESIGN_TOOLS,
35873
+ "novel_shortdrama_render_episode",
35874
+ "novel_shortdrama_save_script",
35875
+ "novel_screenplay_save_draft"
34916
35876
  ]);
34917
- const nativeTools = /* @__PURE__ */ new Set([...NATIVE_DESIGN_TOOLS, "novel_shortdrama_render_episode"]);
34918
35877
  const registered = deps.testTools === true ? tools : tools.filter((tool) => !NOVEL_TEST_TOOL_NAMES.includes(tool.name));
34919
35878
  const guarded = registered.map((tool) => {
34920
35879
  if (!locked.has(tool.name)) return tool;
@@ -35070,8 +36029,8 @@ function finishDesignCommit(bookRoot, writtenPaths, args, defaultSummary, chapte
35070
36029
  import { boundContextSummary, createUserMessage as createUserMessage3 } from "@deepseek-ai/dsh-llm";
35071
36030
 
35072
36031
  // src/study/service.ts
35073
- import * as fs63 from "node:fs";
35074
- import * as path74 from "node:path";
36032
+ import * as fs64 from "node:fs";
36033
+ import * as path75 from "node:path";
35075
36034
 
35076
36035
  // ../../node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/diff/base.js
35077
36036
  var Diff = class {
@@ -35173,16 +36132,16 @@ var Diff = class {
35173
36132
  }
35174
36133
  }
35175
36134
  }
35176
- addToPath(path81, added, removed, oldPosInc, options2) {
35177
- const last = path81.lastComponent;
36135
+ addToPath(path82, added, removed, oldPosInc, options2) {
36136
+ const last = path82.lastComponent;
35178
36137
  if (last && !options2.oneChangePerToken && last.added === added && last.removed === removed) {
35179
36138
  return {
35180
- oldPos: path81.oldPos + oldPosInc,
36139
+ oldPos: path82.oldPos + oldPosInc,
35181
36140
  lastComponent: { count: last.count + 1, added, removed, previousComponent: last.previousComponent }
35182
36141
  };
35183
36142
  } else {
35184
36143
  return {
35185
- oldPos: path81.oldPos + oldPosInc,
36144
+ oldPos: path82.oldPos + oldPosInc,
35186
36145
  lastComponent: { count: 1, added, removed, previousComponent: last }
35187
36146
  };
35188
36147
  }
@@ -35373,7 +36332,7 @@ var text4 = (value) => typeof value === "string" ? value : "";
35373
36332
  var terms = (value) => Array.isArray(value) ? value.flatMap(terms) : typeof value === "string" ? value.split(/[、,,;]/).map((item) => item.trim()).filter(Boolean) : [];
35374
36333
  var wiki = (body) => [...body.matchAll(/\[\[([^\]\n]+)\]\]/g)].map((match) => match[1].split("|")[0].trim());
35375
36334
  var identity3 = (name3) => name3.trim().replace(/[\s「」『』【】()()::,,。!?!?]/g, "").toLowerCase();
35376
- var kindOf = (path81, 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() : path81.includes("/\u4EBA\u7269\u6863\u6848/") ? "\u4EBA\u7269" : path81.includes("/\u4EBA\u7269\u5173\u7CFB/") ? "\u5173\u7CFB" : path81.includes("/\u7EC4\u7EC7\u4E0E\u9635\u8425/") ? "\u7EC4\u7EC7" : path81.includes("/\u5730\u70B9\u4E0E\u7A7A\u95F4/") ? "\u5730\u70B9" : "\u8BBE\u5B9A";
36335
+ var kindOf = (path82, 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() : path82.includes("/\u4EBA\u7269\u6863\u6848/") ? "\u4EBA\u7269" : path82.includes("/\u4EBA\u7269\u5173\u7CFB/") ? "\u5173\u7CFB" : path82.includes("/\u7EC4\u7EC7\u4E0E\u9635\u8425/") ? "\u7EC4\u7EC7" : path82.includes("/\u5730\u70B9\u4E0E\u7A7A\u95F4/") ? "\u5730\u70B9" : "\u8BBE\u5B9A";
35377
36336
  function readStoryGraph(source2) {
35378
36337
  const records = [], edges = [], events = [];
35379
36338
  const warnings = [];
@@ -35405,7 +36364,7 @@ function readStoryGraph(source2) {
35405
36364
  aliases.set(name3, values);
35406
36365
  };
35407
36366
  const strings = (fields) => Object.fromEntries(Object.entries(fields).filter((pair) => typeof pair[1] === "string"));
35408
- const fromFields = (id, label2, kind2, path81, line, fields, body) => ({
36367
+ const fromFields = (id, label2, kind2, path82, line, fields, body) => ({
35409
36368
  id,
35410
36369
  label: label2,
35411
36370
  kind: kind2,
@@ -35414,23 +36373,23 @@ function readStoryGraph(source2) {
35414
36373
  chapter: chapter(fields["\u8D77\u59CB\u7AE0"]) ?? chapter(fields["\u751F\u6548\u7AE0"]) ?? chapter(fields["\u7AE0\u53F7"]) ?? entryChapterNo({ \u5B57\u6BB5: strings(fields) }) ?? void 0,
35415
36374
  endChapter: chapter(fields["\u5931\u6548\u7AE0"]),
35416
36375
  revealChapter: chapter(fields["\u62AB\u9732\u7AE0"]) ?? chapter(fields["\u63ED\u793A\u7AE0"]),
35417
- source: { space: "book:" + source2.bookId, path: path81 },
36376
+ source: { space: "book:" + source2.bookId, path: path82 },
35418
36377
  line,
35419
36378
  preview: body.trim().slice(0, 600),
35420
36379
  // Expose authored scalar/list field names as grouping choices without
35421
36380
  // guessing whether 宗门/血脉/师承 means faction, family or another identity.
35422
36381
  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 })))
35423
36382
  });
35424
- const scan = (path81, depth = 0) => {
36383
+ const scan = (path82, depth = 0) => {
35425
36384
  if (depth > 12) {
35426
- warnings.push({ path: path81, message: "\u76EE\u5F55\u5C42\u7EA7\u8FC7\u6DF1\uFF0C\u672A\u7EE7\u7EED\u8BFB\u53D6" });
36385
+ warnings.push({ path: path82, message: "\u76EE\u5F55\u5C42\u7EA7\u8FC7\u6DF1\uFF0C\u672A\u7EE7\u7EED\u8BFB\u53D6" });
35427
36386
  return;
35428
36387
  }
35429
36388
  let entries;
35430
36389
  try {
35431
- entries = source2.list(path81);
36390
+ entries = source2.list(path82);
35432
36391
  } catch (error) {
35433
- if (error.code !== "not-found") warnings.push({ path: path81, message: "\u8BE5\u76EE\u5F55\u65E0\u6CD5\u8BFB\u53D6" });
36392
+ if (error.code !== "not-found") warnings.push({ path: path82, message: "\u8BE5\u76EE\u5F55\u65E0\u6CD5\u8BFB\u53D6" });
35434
36393
  return;
35435
36394
  }
35436
36395
  for (const entry of entries) {
@@ -35521,26 +36480,26 @@ function readStoryGraph(source2) {
35521
36480
  };
35522
36481
  scan("\u4E16\u754C\u4E66");
35523
36482
  for (const category of LEDGER_NAMES) {
35524
- const path81 = "\u8D26\u672C/" + category + ".md";
36483
+ const path82 = "\u8D26\u672C/" + category + ".md";
35525
36484
  let raw;
35526
36485
  try {
35527
- raw = source2.read(path81);
36486
+ raw = source2.read(path82);
35528
36487
  } catch (error) {
35529
- if (error.code !== "not-found") warnings.push({ path: path81, message: "\u8BE5\u8D26\u672C\u65E0\u6CD5\u8BFB\u53D6" });
36488
+ if (error.code !== "not-found") warnings.push({ path: path82, message: "\u8BE5\u8D26\u672C\u65E0\u6CD5\u8BFB\u53D6" });
35530
36489
  continue;
35531
36490
  }
35532
36491
  const ranges2 = createEvidenceRanges(raw);
35533
- sourceHashes[path81] = ranges2.hash;
35534
- const parsed = parseLedgerHistory(raw, category, path81);
36492
+ sourceHashes[path82] = ranges2.hash;
36493
+ const parsed = parseLedgerHistory(raw, category, path82);
35535
36494
  if (!parsed.ok) {
35536
- warnings.push({ path: path81, message: parsed.reason });
36495
+ warnings.push({ path: path82, message: parsed.reason });
35537
36496
  continue;
35538
36497
  }
35539
36498
  for (const [index, entry] of parsed.entries.entries()) {
35540
- const id = category === "\u65F6\u95F4\u7EBF" ? "event:" + path81 + ":" + entry.\u884C\u53F7 : "ledger:" + category + ":" + identity3(entry.\u540D\u79F0);
36499
+ const id = category === "\u65F6\u95F4\u7EBF" ? "event:" + path82 + ":" + entry.\u884C\u53F7 : "ledger:" + category + ":" + identity3(entry.\u540D\u79F0);
35541
36500
  const content = category === "\u65F6\u95F4\u7EBF" ? renderTimelineContent(entry) : entry.\u6B63\u6587;
35542
36501
  const evidenceId = id + ":" + entry.\u884C\u53F7;
35543
- const base = fromFields(id, entry.\u540D\u79F0, category === "\u65F6\u95F4\u7EBF" ? "\u4E8B\u4EF6" : category, path81, entry.\u884C\u53F7, entry.\u5B57\u6BB5, content);
36502
+ const base = fromFields(id, entry.\u540D\u79F0, category === "\u65F6\u95F4\u7EBF" ? "\u4E8B\u4EF6" : category, path82, entry.\u884C\u53F7, entry.\u5B57\u6BB5, content);
35544
36503
  const recordChapter2 = entryChapterNo(entry) ?? void 0;
35545
36504
  const storyTime = category === "\u65F6\u95F4\u7EBF" ? timelineStoryTime(entry) : void 0;
35546
36505
  const record4 = { ...base, recordChapter: recordChapter2, storyTime, historyBasis: recordChapter2 ? "recorded" : "unknown", evidenceId };
@@ -35561,11 +36520,11 @@ function readStoryGraph(source2) {
35561
36520
  links.push({ record: record4, targets: wiki(content), pair: false });
35562
36521
  }
35563
36522
  }
35564
- const resolve22 = (target, path81) => {
36523
+ const resolve22 = (target, path82) => {
35565
36524
  const name3 = target.replace(/^\[\[|\]\]$/g, "").replace(/@\d+$/, "").replace(/\\/g, "/");
35566
36525
  const found = aliases.get(name3);
35567
36526
  if (found?.size === 1) return [...found][0];
35568
- warnings.push({ path: path81, 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 });
36527
+ warnings.push({ path: path82, 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 });
35569
36528
  return void 0;
35570
36529
  };
35571
36530
  for (const item of links) {
@@ -35589,32 +36548,32 @@ function readStoryGraph(source2) {
35589
36548
  const currentBound = (items) => items.map((item) => item.currentOnlyAt === void 0 ? item : { ...item, currentOnlyAt: maxChapter });
35590
36549
  const withChapters = evidence.map((item) => {
35591
36550
  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));
35592
- return { ...item, relatedChapters: [...new Set(references)].map((path81) => ({ space: item.source.space, path: path81 })) };
36551
+ return { ...item, relatedChapters: [...new Set(references)].map((path82) => ({ space: item.source.space, path: path82 })) };
35593
36552
  });
35594
36553
  return { bookId: source2.bookId, bookName: source2.bookName, maxChapter, records: currentBound(records), edges: currentBound(edges), events, warnings, evidence: withChapters, entities, sourceHashes, fingerprint: fingerprint2, format: format2 };
35595
36554
  }
35596
36555
 
35597
36556
  // src/study/graph-source.ts
35598
- import * as fs61 from "node:fs";
35599
- import * as path72 from "node:path";
36557
+ import * as fs62 from "node:fs";
36558
+ import * as path73 from "node:path";
35600
36559
  import { createHash as createHash20 } from "node:crypto";
35601
36560
  function readGraphFile(base, relative12) {
35602
36561
  validateAuthorRelativePath(relative12);
35603
- const file = path72.join(base, relative12);
36562
+ const file = path73.join(base, relative12);
35604
36563
  const checkPhysical = () => {
35605
- if (stripDevicePrefix(fs61.realpathSync.native(file)) !== file) throw new AuthorDocumentError("invalid-path", "\u56FE\u8C31\u6765\u6E90\u8DEF\u5F84\u5305\u542B\u94FE\u63A5\u6216\u522B\u540D");
36564
+ if (stripDevicePrefix(fs62.realpathSync.native(file)) !== file) throw new AuthorDocumentError("invalid-path", "\u56FE\u8C31\u6765\u6E90\u8DEF\u5F84\u5305\u542B\u94FE\u63A5\u6216\u522B\u540D");
35606
36565
  };
35607
36566
  checkPhysical();
35608
- const initial = fs61.lstatSync(file);
36567
+ const initial = fs62.lstatSync(file);
35609
36568
  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");
35610
36569
  if (initial.size > 4 * 1024 * 1024) throw new AuthorDocumentError("read-only", "\u56FE\u8C31\u6765\u6E90\u8D85\u8FC74MiB\uFF0C\u672A\u622A\u65AD\u8BFB\u53D6");
35611
- const descriptor = fs61.openSync(file, fs61.constants.O_RDONLY | (fs61.constants.O_NOFOLLOW ?? 0));
36570
+ const descriptor = fs62.openSync(file, fs62.constants.O_RDONLY | (fs62.constants.O_NOFOLLOW ?? 0));
35612
36571
  try {
35613
- const opened = fs61.fstatSync(descriptor);
36572
+ const opened = fs62.fstatSync(descriptor);
35614
36573
  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");
35615
- const bytes = fs61.readFileSync(descriptor);
36574
+ const bytes = fs62.readFileSync(descriptor);
35616
36575
  checkPhysical();
35617
- const current = fs61.lstatSync(file), finished = fs61.fstatSync(descriptor);
36576
+ const current = fs62.lstatSync(file), finished = fs62.fstatSync(descriptor);
35618
36577
  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");
35619
36578
  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");
35620
36579
  try {
@@ -35623,26 +36582,26 @@ function readGraphFile(base, relative12) {
35623
36582
  throw new AuthorDocumentError("read-only", "\u56FE\u8C31\u6765\u6E90\u5FC5\u987B\u4F7F\u7528UTF-8");
35624
36583
  }
35625
36584
  } finally {
35626
- fs61.closeSync(descriptor);
36585
+ fs62.closeSync(descriptor);
35627
36586
  }
35628
36587
  }
35629
36588
  async function readGraphFileAsync(base, relative12, signal) {
35630
36589
  signal?.throwIfAborted();
35631
36590
  validateAuthorRelativePath(relative12);
35632
- const file = path72.join(base, relative12);
36591
+ const file = path73.join(base, relative12);
35633
36592
  const checkPhysical = async () => {
35634
- if (stripDevicePrefix(await fs61.promises.realpath(file)) !== file) throw new AuthorDocumentError("invalid-path", "\u56FE\u8C31\u6765\u6E90\u8DEF\u5F84\u5305\u542B\u94FE\u63A5\u6216\u522B\u540D");
36593
+ if (stripDevicePrefix(await fs62.promises.realpath(file)) !== file) throw new AuthorDocumentError("invalid-path", "\u56FE\u8C31\u6765\u6E90\u8DEF\u5F84\u5305\u542B\u94FE\u63A5\u6216\u522B\u540D");
35635
36594
  };
35636
36595
  await checkPhysical();
35637
- const initial = await fs61.promises.lstat(file);
36596
+ const initial = await fs62.promises.lstat(file);
35638
36597
  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");
35639
- const handle = await fs61.promises.open(file, fs61.constants.O_RDONLY | (fs61.constants.O_NOFOLLOW ?? 0));
36598
+ const handle = await fs62.promises.open(file, fs62.constants.O_RDONLY | (fs62.constants.O_NOFOLLOW ?? 0));
35640
36599
  try {
35641
36600
  const opened = await handle.stat();
35642
36601
  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");
35643
36602
  const bytes = await handle.readFile({ signal });
35644
36603
  await checkPhysical();
35645
- const current = await fs61.promises.lstat(file), finished = await handle.stat();
36604
+ const current = await fs62.promises.lstat(file), finished = await handle.stat();
35646
36605
  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");
35647
36606
  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");
35648
36607
  try {
@@ -35662,12 +36621,12 @@ async function scanGraphFiles(root, space, signal) {
35662
36621
  if (depth > 12) return;
35663
36622
  try {
35664
36623
  const directory = authorDocumentPath(root, relative12, true);
35665
- const entries = await fs61.promises.readdir(directory, { withFileTypes: true });
36624
+ const entries = await fs62.promises.readdir(directory, { withFileTypes: true });
35666
36625
  const rows = entries.filter((item) => !item.name.startsWith(".") && item.name !== "node_modules").map((item) => ({
35667
36626
  name: item.name,
35668
36627
  directory: item.isDirectory(),
35669
36628
  draft: false,
35670
- ref: { space, path: path72.posix.join(relative12, item.name) },
36629
+ ref: { space, path: path73.posix.join(relative12, item.name) },
35671
36630
  ...item.isSymbolicLink() || !item.isFile() && !item.isDirectory() ? { error: "\u8BE5\u6761\u76EE\u4E0D\u662F\u5B89\u5168\u7684\u666E\u901A\u6587\u4EF6\u6216\u76EE\u5F55" } : {}
35672
36631
  }));
35673
36632
  directories.set(relative12, rows);
@@ -35892,10 +36851,10 @@ function overlayExtractions(graph, extractions) {
35892
36851
  }
35893
36852
 
35894
36853
  // src/indexing/graph-storage.ts
35895
- import * as fs62 from "node:fs";
35896
- import * as path73 from "node:path";
36854
+ import * as fs63 from "node:fs";
36855
+ import * as path74 from "node:path";
35897
36856
  import { createRequire as createRequire2 } from "node:module";
35898
- import { createHash as createHash21, randomUUID as randomUUID8 } from "node:crypto";
36857
+ import { createHash as createHash21, randomUUID as randomUUID9 } from "node:crypto";
35899
36858
  var APPLICATION_ID2 = 1465272113;
35900
36859
  var CACHE_NAME = "story-graph.sqlite";
35901
36860
  var STATE_NAME = "story-graph-state.json";
@@ -35915,24 +36874,24 @@ function initialGraphState(bookId2) {
35915
36874
  }
35916
36875
  function graphFile(root, name3) {
35917
36876
  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");
35918
- const runtime = path73.join(root, ".webnovel");
35919
- for (const [target, directory] of [[runtime, true], [path73.join(runtime, name3), false]]) {
36877
+ const runtime = path74.join(root, ".webnovel");
36878
+ for (const [target, directory] of [[runtime, true], [path74.join(runtime, name3), false]]) {
35920
36879
  try {
35921
- const stat = fs62.lstatSync(target);
36880
+ const stat = fs63.lstatSync(target);
35922
36881
  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");
35923
36882
  } catch (error) {
35924
36883
  if (error.code !== "ENOENT") throw error;
35925
36884
  }
35926
36885
  }
35927
- return path73.join(runtime, name3);
36886
+ return path74.join(runtime, name3);
35928
36887
  }
35929
36888
  function readGraphState(root, bookId2) {
35930
36889
  const file = graphFile(root, STATE_NAME);
35931
- if (!fs62.existsSync(file)) return initialGraphState(bookId2);
35932
- if (fs62.statSync(file).size > 32768) throw new Error("\u56FE\u8C31\u63A7\u5236\u8BB0\u5F55\u8FC7\u5927\uFF0C\u5DF2\u4FDD\u7559\u73B0\u573A");
36890
+ if (!fs63.existsSync(file)) return initialGraphState(bookId2);
36891
+ if (fs63.statSync(file).size > 32768) throw new Error("\u56FE\u8C31\u63A7\u5236\u8BB0\u5F55\u8FC7\u5927\uFF0C\u5DF2\u4FDD\u7559\u73B0\u573A");
35933
36892
  let value;
35934
36893
  try {
35935
- value = JSON.parse(fs62.readFileSync(file, "utf8"));
36894
+ value = JSON.parse(fs63.readFileSync(file, "utf8"));
35936
36895
  } catch {
35937
36896
  throw new Error("\u56FE\u8C31\u63A7\u5236\u8BB0\u5F55\u65E0\u6CD5\u89E3\u6790\uFF0C\u5DF2\u4FDD\u7559\u73B0\u573A");
35938
36897
  }
@@ -35940,14 +36899,14 @@ function readGraphState(root, bookId2) {
35940
36899
  return value;
35941
36900
  }
35942
36901
  function writeGraphState(root, state) {
35943
- const file = graphFile(root, STATE_NAME), temporary = `${file}.${randomUUID8()}.tmp`;
36902
+ const file = graphFile(root, STATE_NAME), temporary = `${file}.${randomUUID9()}.tmp`;
35944
36903
  try {
35945
- fs62.writeFileSync(temporary, JSON.stringify(state) + "\n", { flag: "wx", mode: 384 });
36904
+ fs63.writeFileSync(temporary, JSON.stringify(state) + "\n", { flag: "wx", mode: 384 });
35946
36905
  graphFile(root, STATE_NAME);
35947
- fs62.renameSync(temporary, file);
36906
+ fs63.renameSync(temporary, file);
35948
36907
  } finally {
35949
36908
  try {
35950
- fs62.unlinkSync(temporary);
36909
+ fs63.unlinkSync(temporary);
35951
36910
  } catch {
35952
36911
  }
35953
36912
  }
@@ -35961,11 +36920,11 @@ function changeGraphState(root, bookId2, update) {
35961
36920
  }
35962
36921
  function acquireGraphLease(root) {
35963
36922
  return withBookLockAsync(root, async () => {
35964
- const file = graphFile(root, "story-graph.worker.lock"), token = randomUUID8();
35965
- if (fs62.existsSync(file)) {
36923
+ const file = graphFile(root, "story-graph.worker.lock"), token = randomUUID9();
36924
+ if (fs63.existsSync(file)) {
35966
36925
  let pid;
35967
36926
  try {
35968
- pid = JSON.parse(fs62.readFileSync(file, "utf8")).pid;
36927
+ pid = JSON.parse(fs63.readFileSync(file, "utf8")).pid;
35969
36928
  } catch {
35970
36929
  throw new Error("\u56FE\u8C31\u4EFB\u52A1\u9501\u65E0\u6CD5\u89E3\u6790\uFF0C\u672A\u6E05\u7406\u539F\u6587\u4EF6");
35971
36930
  }
@@ -35977,12 +36936,12 @@ function acquireGraphLease(root) {
35977
36936
  dead2 = error.code === "ESRCH";
35978
36937
  }
35979
36938
  if (!dead2) throw new Error("\u53E6\u4E00\u56FE\u8C31\u4EFB\u52A1\u6B63\u5728\u8FD0\u884C");
35980
- fs62.unlinkSync(graphFile(root, "story-graph.worker.lock"));
36939
+ fs63.unlinkSync(graphFile(root, "story-graph.worker.lock"));
35981
36940
  }
35982
- fs62.writeFileSync(file, JSON.stringify({ pid: process.pid, token }), { flag: "wx", mode: 384 });
36941
+ fs63.writeFileSync(file, JSON.stringify({ pid: process.pid, token }), { flag: "wx", mode: 384 });
35983
36942
  return () => {
35984
36943
  try {
35985
- if (JSON.parse(fs62.readFileSync(graphFile(root, "story-graph.worker.lock"), "utf8")).token === token) fs62.unlinkSync(file);
36944
+ if (JSON.parse(fs63.readFileSync(graphFile(root, "story-graph.worker.lock"), "utf8")).token === token) fs63.unlinkSync(file);
35986
36945
  } catch {
35987
36946
  }
35988
36947
  };
@@ -35990,20 +36949,20 @@ function acquireGraphLease(root) {
35990
36949
  }
35991
36950
  function graphCacheSignature(root) {
35992
36951
  const file = graphFile(root, CACHE_NAME);
35993
- return fs62.existsSync(file) ? createHash21("sha256").update(fs62.readFileSync(file)).digest("hex") : "missing";
36952
+ return fs63.existsSync(file) ? createHash21("sha256").update(fs63.readFileSync(file)).digest("hex") : "missing";
35994
36953
  }
35995
36954
  function cacheHeader(file) {
35996
- const header2 = Buffer.alloc(100), handle = fs62.openSync(file, "r");
36955
+ const header2 = Buffer.alloc(100), handle = fs63.openSync(file, "r");
35997
36956
  try {
35998
- fs62.readSync(handle, header2, 0, 100, 0);
36957
+ fs63.readSync(handle, header2, 0, 100, 0);
35999
36958
  } finally {
36000
- fs62.closeSync(handle);
36959
+ fs63.closeSync(handle);
36001
36960
  }
36002
36961
  return header2;
36003
36962
  }
36004
36963
  function replaceGraphCache(root, bookId2) {
36005
36964
  const file = graphFile(root, CACHE_NAME);
36006
- if (!fs62.existsSync(file)) return;
36965
+ if (!fs63.existsSync(file)) return;
36007
36966
  const header2 = cacheHeader(file);
36008
36967
  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");
36009
36968
  let db;
@@ -36019,16 +36978,16 @@ function replaceGraphCache(root, bookId2) {
36019
36978
  } catch {
36020
36979
  }
36021
36980
  }
36022
- const suffix = `.replaced-${randomUUID8()}`, moved = [];
36981
+ const suffix = `.replaced-${randomUUID9()}`, moved = [];
36023
36982
  try {
36024
36983
  for (const ending of ["", "-journal", "-wal", "-shm"]) {
36025
36984
  const source2 = graphFile(root, CACHE_NAME + ending), target = source2 + suffix;
36026
- if (!fs62.existsSync(source2)) continue;
36027
- fs62.renameSync(source2, target);
36985
+ if (!fs63.existsSync(source2)) continue;
36986
+ fs63.renameSync(source2, target);
36028
36987
  moved.push([source2, target]);
36029
36988
  }
36030
36989
  } catch (error) {
36031
- for (const [source2, target] of moved.reverse()) if (!fs62.existsSync(source2)) fs62.renameSync(target, source2);
36990
+ for (const [source2, target] of moved.reverse()) if (!fs63.existsSync(source2)) fs63.renameSync(target, source2);
36032
36991
  throw error;
36033
36992
  }
36034
36993
  }
@@ -36049,7 +37008,7 @@ function readGraphCache(root, bookId2) {
36049
37008
  let db;
36050
37009
  try {
36051
37010
  const file = graphFile(root, CACHE_NAME);
36052
- if (!fs62.existsSync(file)) return { status: "missing", extractions: [] };
37011
+ if (!fs63.existsSync(file)) return { status: "missing", extractions: [] };
36053
37012
  const header2 = cacheHeader(file);
36054
37013
  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");
36055
37014
  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");
@@ -36071,7 +37030,7 @@ function readGraphCache(root, bookId2) {
36071
37030
  }
36072
37031
  }
36073
37032
  function saveGraphCache(root, graph, extraction) {
36074
- const filename = graphFile(root, CACHE_NAME), exists3 = fs62.existsSync(filename);
37033
+ const filename = graphFile(root, CACHE_NAME), exists3 = fs63.existsSync(filename);
36075
37034
  if (exists3) {
36076
37035
  const header2 = cacheHeader(filename);
36077
37036
  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");
@@ -36120,9 +37079,9 @@ function routeForDocument(ref2) {
36120
37079
  return "\u6821\u51C6\u4F5C\u54C1\u73B0\u72B6\uFF0C\u518D\u6309\u4FEE\u6539\u5185\u5BB9\u9009\u62E9\u5BF9\u5E94\u8282\u70B9";
36121
37080
  }
36122
37081
  function textOf(target) {
36123
- if (!fs63.existsSync(target) || !fs63.statSync(target).isFile()) throw new AuthorDocumentError("not-found", "\u6587\u4EF6\u4E0D\u5B58\u5728");
36124
- if (fs63.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");
36125
- const bytes = fs63.readFileSync(target);
37082
+ if (!fs64.existsSync(target) || !fs64.statSync(target).isFile()) throw new AuthorDocumentError("not-found", "\u6587\u4EF6\u4E0D\u5B58\u5728");
37083
+ if (fs64.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");
37084
+ const bytes = fs64.readFileSync(target);
36126
37085
  if (bytes.includes(0)) throw new AuthorDocumentError("read-only", "\u8BE5\u6587\u4EF6\u4E0D\u662F\u6587\u672C\u6587\u4EF6");
36127
37086
  try {
36128
37087
  return new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(bytes);
@@ -36142,7 +37101,7 @@ var ORPHAN_SIGNALS = ["\u4E66\u7C4D\u4FE1\u606F.json", "\u6545\u4E8B\u5927\u7EB2
36142
37101
  function orphanSignals(dir) {
36143
37102
  let entries;
36144
37103
  try {
36145
- entries = fs63.readdirSync(dir);
37104
+ entries = fs64.readdirSync(dir);
36146
37105
  } catch {
36147
37106
  return void 0;
36148
37107
  }
@@ -36154,18 +37113,18 @@ function scanOrphanDrafts(workspace, bookNames) {
36154
37113
  const scanLevel = (parent, prefix, skip) => {
36155
37114
  let entries;
36156
37115
  try {
36157
- entries = fs63.readdirSync(parent, { withFileTypes: true });
37116
+ entries = fs64.readdirSync(parent, { withFileTypes: true });
36158
37117
  } catch {
36159
37118
  return;
36160
37119
  }
36161
37120
  for (const entry of entries) {
36162
37121
  if (!entry.isDirectory() || skip.has(entry.name)) continue;
36163
- const signals = orphanSignals(path74.join(parent, entry.name));
37122
+ const signals = orphanSignals(path75.join(parent, entry.name));
36164
37123
  if (signals !== void 0) orphans.push({ name: entry.name, path: prefix + entry.name, detail: `\u542B ${signals.join("\u3001")}` });
36165
37124
  }
36166
37125
  };
36167
37126
  scanLevel(workspace, "", /* @__PURE__ */ new Set([...bookNames, "\u4E66\u623F"]));
36168
- scanLevel(path74.join(workspace, "\u4E66\u623F"), "\u4E66\u623F/", /* @__PURE__ */ new Set());
37127
+ scanLevel(path75.join(workspace, "\u4E66\u623F"), "\u4E66\u623F/", /* @__PURE__ */ new Set());
36169
37128
  return orphans;
36170
37129
  }
36171
37130
  var StudyService = class {
@@ -36173,19 +37132,19 @@ var StudyService = class {
36173
37132
  constructor(workspace) {
36174
37133
  if (!isFullyQualifiedPath(workspace)) throw new AuthorDocumentError("invalid-path", "\u5DE5\u4F5C\u8303\u56F4\u5FC5\u987B\u662F\u7EDD\u5BF9\u8DEF\u5F84");
36175
37134
  this.workspace = canonicalizePath(workspace);
36176
- if (!fs63.existsSync(this.workspace) || !fs63.statSync(this.workspace).isDirectory()) throw new AuthorDocumentError("not-found", "\u5DE5\u4F5C\u8303\u56F4\u76EE\u5F55\u4E0D\u5B58\u5728");
37135
+ if (!fs64.existsSync(this.workspace) || !fs64.statSync(this.workspace).isDirectory()) throw new AuthorDocumentError("not-found", "\u5DE5\u4F5C\u8303\u56F4\u76EE\u5F55\u4E0D\u5B58\u5728");
36177
37136
  }
36178
37137
  source(space) {
36179
37138
  if (space === "shared") {
36180
37139
  const root2 = authorDocumentPath(this.workspace, "\u4E66\u623F");
36181
- if (!fs63.existsSync(root2)) throw new AuthorDocumentError("not-found", "\u5F53\u524D\u5DE5\u4F5C\u8303\u56F4\u5C1A\u65E0\u5171\u4EAB\u8D44\u6599");
36182
- if (fs63.existsSync(path74.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");
37140
+ if (!fs64.existsSync(root2)) throw new AuthorDocumentError("not-found", "\u5F53\u524D\u5DE5\u4F5C\u8303\u56F4\u5C1A\u65E0\u5171\u4EAB\u8D44\u6599");
37141
+ if (fs64.existsSync(path75.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");
36183
37142
  return { root: root2, owner: "\u5171\u4EAB\u8D44\u6599" };
36184
37143
  }
36185
37144
  const books = scanWorkspaceBooks(this.workspace).filter((book2) => book2.bookId && "book:" + book2.bookId === space);
36186
37145
  if (books.length !== 1) throw new AuthorDocumentError("not-found", "\u4E66\u76EE\u4E0D\u5B58\u5728\u6216\u4E66id\u4E0D\u552F\u4E00");
36187
37146
  const book = books[0];
36188
- const root = authorDocumentPath(this.workspace, path74.relative(this.workspace, book.root));
37147
+ const root = authorDocumentPath(this.workspace, path75.relative(this.workspace, book.root));
36189
37148
  return { root, owner: book.name, bookId: book.bookId };
36190
37149
  }
36191
37150
  shelf() {
@@ -36200,7 +37159,7 @@ var StudyService = class {
36200
37159
  let shared = false;
36201
37160
  let sharedError;
36202
37161
  try {
36203
- shared = fs63.statSync(this.source("shared").root).isDirectory();
37162
+ shared = fs64.statSync(this.source("shared").root).isDirectory();
36204
37163
  } catch (error) {
36205
37164
  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";
36206
37165
  }
@@ -36241,12 +37200,12 @@ var StudyService = class {
36241
37200
  // once for tree badges and a second time for the evidence itself.
36242
37201
  list: (relative12) => {
36243
37202
  const directory = authorDocumentPath(source2.root, relative12, true);
36244
- if (!fs63.existsSync(directory)) throw new AuthorDocumentError("not-found", "\u76EE\u5F55\u4E0D\u5B58\u5728");
36245
- return fs63.readdirSync(directory, { withFileTypes: true }).filter((entry) => !entry.name.startsWith(".") && entry.name !== "node_modules").map((entry) => ({
37203
+ if (!fs64.existsSync(directory)) throw new AuthorDocumentError("not-found", "\u76EE\u5F55\u4E0D\u5B58\u5728");
37204
+ return fs64.readdirSync(directory, { withFileTypes: true }).filter((entry) => !entry.name.startsWith(".") && entry.name !== "node_modules").map((entry) => ({
36246
37205
  name: entry.name,
36247
37206
  directory: entry.isDirectory(),
36248
37207
  draft: false,
36249
- ref: { space, path: path74.posix.join(relative12, entry.name) },
37208
+ ref: { space, path: path75.posix.join(relative12, entry.name) },
36250
37209
  ...entry.isSymbolicLink() || !entry.isDirectory() && !entry.isFile() ? { error: "\u8BE5\u6761\u76EE\u4E0D\u662F\u5B89\u5168\u7684\u666E\u901A\u6587\u4EF6\u6216\u76EE\u5F55" } : {}
36251
37210
  }));
36252
37211
  },
@@ -36316,13 +37275,13 @@ var StudyService = class {
36316
37275
  }
36317
37276
  treeAt(source2, ref2) {
36318
37277
  const directory = authorDocumentPath(source2.root, ref2.path, true);
36319
- if (!fs63.existsSync(directory) || !fs63.statSync(directory).isDirectory()) throw new AuthorDocumentError("not-found", "\u76EE\u5F55\u4E0D\u5B58\u5728");
36320
- return fs63.readdirSync(directory, { withFileTypes: true }).filter((entry) => !entry.name.startsWith(".") && entry.name !== "node_modules").map((entry) => {
36321
- const relative12 = path74.posix.join(ref2.path, entry.name);
37278
+ if (!fs64.existsSync(directory) || !fs64.statSync(directory).isDirectory()) throw new AuthorDocumentError("not-found", "\u76EE\u5F55\u4E0D\u5B58\u5728");
37279
+ return fs64.readdirSync(directory, { withFileTypes: true }).filter((entry) => !entry.name.startsWith(".") && entry.name !== "node_modules").map((entry) => {
37280
+ const relative12 = path75.posix.join(ref2.path, entry.name);
36322
37281
  const item = { ref: { space: ref2.space, path: relative12 }, name: entry.name, directory: entry.isDirectory(), draft: ref2.space !== "shared" && relative12.startsWith("\u8349\u7A3F\u533A") };
36323
37282
  try {
36324
37283
  const target = authorDocumentPath(source2.root, relative12);
36325
- const info = fs63.statSync(target);
37284
+ const info = fs64.statSync(target);
36326
37285
  if (!info.isDirectory() && !info.isFile()) return { ...item, error: "\u4E0D\u652F\u6301\u7684\u6587\u4EF6\u7C7B\u578B" };
36327
37286
  const badge = info.isFile() && entry.name.endsWith(".md") && info.size <= MAX_DOCUMENT_BYTES2 ? fieldLabel(textOf(target)).badge : void 0;
36328
37287
  return { ...item, absolutePath: target, directory: info.isDirectory(), ...badge ? { badge } : {} };
@@ -36340,7 +37299,7 @@ var StudyService = class {
36340
37299
  read(ref2) {
36341
37300
  const source2 = this.source(ref2.space);
36342
37301
  const absolutePath = authorDocumentPath(source2.root, ref2.path);
36343
- ref2 = { ...ref2, path: path74.relative(canonicalizePath(source2.root), absolutePath).split(path74.sep).join("/") };
37302
+ ref2 = { ...ref2, path: path75.relative(canonicalizePath(source2.root), absolutePath).split(path75.sep).join("/") };
36344
37303
  const text5 = textOf(absolutePath);
36345
37304
  const parsed = parseDocument(text5);
36346
37305
  const metadata2 = fieldLabel(text5);
@@ -36348,7 +37307,7 @@ var StudyService = class {
36348
37307
  return {
36349
37308
  ref: ref2,
36350
37309
  owner: source2.owner,
36351
- name: path74.basename(ref2.path),
37310
+ name: path75.basename(ref2.path),
36352
37311
  absolutePath,
36353
37312
  body: parsed.ok ? parsed.data.body : text5,
36354
37313
  hash: documentHash(text5),
@@ -36367,14 +37326,14 @@ var StudyService = class {
36367
37326
  return null;
36368
37327
  }
36369
37328
  }
36370
- absolutePath = path74.resolve(this.workspace, absolutePath);
37329
+ absolutePath = path75.resolve(this.workspace, absolutePath);
36371
37330
  }
36372
37331
  const spaces = this.shelf().books.filter((book) => !book.error).map((book) => book.id);
36373
37332
  spaces.push("shared");
36374
37333
  for (const space of spaces) {
36375
37334
  try {
36376
37335
  const source2 = this.source(space);
36377
- const relative12 = path74.relative(source2.root, absolutePath).split(path74.sep).join("/");
37336
+ const relative12 = path75.relative(source2.root, absolutePath).split(path75.sep).join("/");
36378
37337
  return this.read({ space, path: relative12 });
36379
37338
  } catch {
36380
37339
  }
@@ -36387,7 +37346,7 @@ var StudyService = class {
36387
37346
  const scanned = scanWorkspaceBooks(this.workspace);
36388
37347
  const spaces = scanned.filter((book) => book.bookId && scanned.filter((other) => other.bookId === book.bookId).length === 1).map((book) => "book:" + book.bookId);
36389
37348
  try {
36390
- if (fs63.statSync(this.source("shared").root).isDirectory()) spaces.push("shared");
37349
+ if (fs64.statSync(this.source("shared").root).isDirectory()) spaces.push("shared");
36391
37350
  } catch {
36392
37351
  }
36393
37352
  const term = query.trim().toLocaleLowerCase();
@@ -36454,7 +37413,7 @@ var StudyService = class {
36454
37413
  const status = deriveChapterFacts(facts);
36455
37414
  const pending = findPendingReviewDraft(source2.root, key);
36456
37415
  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)];
36457
- const relative12 = candidates.find((candidate) => fs63.existsSync(path74.join(source2.root, candidate)));
37416
+ const relative12 = candidates.find((candidate) => fs64.existsSync(path75.join(source2.root, candidate)));
36458
37417
  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 } } : {} };
36459
37418
  })
36460
37419
  };
@@ -37402,8 +38361,8 @@ function brandString(value) {
37402
38361
  }
37403
38362
 
37404
38363
  // src/native-write.ts
37405
- import { randomUUID as randomUUID9 } from "node:crypto";
37406
- import * as path75 from "node:path";
38364
+ import { randomUUID as randomUUID10 } from "node:crypto";
38365
+ import * as path76 from "node:path";
37407
38366
  import { ToolExecutionPipeline } from "@deepseek-ai/dsh-tools/pipeline";
37408
38367
  function nativeToolRuntime(ctx) {
37409
38368
  const pipeline = new ToolExecutionPipeline(ctx);
@@ -37434,8 +38393,8 @@ function createNativeWriteBridge(runtime) {
37434
38393
  exec.signal.throwIfAborted();
37435
38394
  const target = resolveInsideBook(root, op.relPath);
37436
38395
  if (!target.ok) throw new Error("\u539F\u751F\u5199\u5165\u76EE\u6807\u4E0D\u5728\u4E66\u4ED3\u5185");
37437
- const file = path75.resolve(root, target.relPath);
37438
- const callId = brandString(`webnovel-write-${randomUUID9()}`);
38396
+ const file = path76.resolve(root, target.relPath);
38397
+ const callId = brandString(`webnovel-write-${randomUUID10()}`);
37439
38398
  pending.set(callId, { parent: exec.token, agent: exec.agent, file, content: op.content });
37440
38399
  try {
37441
38400
  const result = await runtime.execute({
@@ -37458,10 +38417,10 @@ function createNativeWriteBridge(runtime) {
37458
38417
  }
37459
38418
 
37460
38419
  // src/indexing/manager.ts
37461
- import * as fs64 from "node:fs";
38420
+ import * as fs65 from "node:fs";
37462
38421
 
37463
38422
  // src/indexing/git.ts
37464
- import * as path76 from "node:path";
38423
+ import * as path77 from "node:path";
37465
38424
  import { execFile } from "node:child_process";
37466
38425
  async function git(root, args) {
37467
38426
  return new Promise((resolve22) => execFile("git", ["--literal-pathspecs", "-C", root, ...args], {
@@ -37487,8 +38446,8 @@ async function bookGitWatchPaths(root) {
37487
38446
  git(root, ["rev-parse", "--path-format=absolute", "--git-common-dir"])
37488
38447
  ]);
37489
38448
  return [...new Set(directories.filter((value) => !!value?.trim()).flatMap((value) => {
37490
- const directory = path76.resolve(root, value.trim());
37491
- return [directory, path76.join(directory, "refs")];
38449
+ const directory = path77.resolve(root, value.trim());
38450
+ return [directory, path77.join(directory, "refs")];
37492
38451
  }))];
37493
38452
  }
37494
38453
 
@@ -37895,7 +38854,7 @@ var BookIndexManager = class {
37895
38854
  for (const directory of await bookGitWatchPaths(record4.book.root)) {
37896
38855
  if (this.closing) return;
37897
38856
  try {
37898
- const watcher = fs64.watch(directory, { recursive: directory.endsWith("refs"), persistent: false }, (_event, filename) => {
38857
+ const watcher = fs65.watch(directory, { recursive: directory.endsWith("refs"), persistent: false }, (_event, filename) => {
37899
38858
  const name3 = filename?.toString().replaceAll("\\", "/");
37900
38859
  if (directory.endsWith("refs") || !name3 || /^(HEAD|packed-refs|refs)(\/|$)/.test(name3)) {
37901
38860
  this.scheduleProbe(record4);
@@ -38269,7 +39228,7 @@ function indexFailureMessage(book, notice) {
38269
39228
  }
38270
39229
 
38271
39230
  // src/reference/host.ts
38272
- import * as path77 from "node:path";
39231
+ import * as path78 from "node:path";
38273
39232
  import { BlockAssembler, createUserMessage as createUserMessage4 } from "@deepseek-ai/dsh-llm";
38274
39233
  var ReferenceHost = class {
38275
39234
  constructor(access) {
@@ -38287,26 +39246,26 @@ var ReferenceHost = class {
38287
39246
  async readFile(agent, workspace, filename, signal) {
38288
39247
  const active = AbortSignal.any([this.shutdown.signal, ...signal ? [signal] : []]);
38289
39248
  active.throwIfAborted();
38290
- const fs68 = this.access.fs(agent);
38291
- if (!fs68) throw new ReferenceError2("fs-unavailable", "DSH \u6587\u4EF6\u670D\u52A1\u4E0D\u53EF\u7528");
38292
- if (!path77.isAbsolute(filename)) throw new ReferenceError2("source-path", "\u8BF7\u9009\u62E9\u539F\u6587\u6587\u4EF6\u7684\u7EDD\u5BF9\u8DEF\u5F84");
38293
- const mapped = fs68.processPathFromHostPath(filename), workspacePath = fs68.processPathFromHostPath(workspace);
39249
+ const fs69 = this.access.fs(agent);
39250
+ if (!fs69) throw new ReferenceError2("fs-unavailable", "DSH \u6587\u4EF6\u670D\u52A1\u4E0D\u53EF\u7528");
39251
+ if (!path78.isAbsolute(filename)) throw new ReferenceError2("source-path", "\u8BF7\u9009\u62E9\u539F\u6587\u6587\u4EF6\u7684\u7EDD\u5BF9\u8DEF\u5F84");
39252
+ const mapped = fs69.processPathFromHostPath(filename), workspacePath = fs69.processPathFromHostPath(workspace);
38294
39253
  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");
38295
- const info = await fs68.lstat(mapped, void 0, active);
39254
+ const info = await fs69.lstat(mapped, void 0, active);
38296
39255
  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");
38297
- let ancestor = path77.dirname(mapped);
38298
- while (path77.dirname(ancestor) !== ancestor) {
38299
- if ((await fs68.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");
38300
- ancestor = path77.dirname(ancestor);
38301
- }
38302
- const target = await fs68.resolve(mapped, { signal: active });
38303
- const library = await fs68.resolve(path77.join(workspacePath, "\u4E66\u623F/\u53C2\u8003\u4E66"), { signal: active });
38304
- if (fs68.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");
38305
- const before = await fs68.stat(target, active);
39256
+ let ancestor = path78.dirname(mapped);
39257
+ while (path78.dirname(ancestor) !== ancestor) {
39258
+ if ((await fs69.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");
39259
+ ancestor = path78.dirname(ancestor);
39260
+ }
39261
+ const target = await fs69.resolve(mapped, { signal: active });
39262
+ const library = await fs69.resolve(path78.join(workspacePath, "\u4E66\u623F/\u53C2\u8003\u4E66"), { signal: active });
39263
+ if (fs69.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");
39264
+ const before = await fs69.stat(target, active);
38306
39265
  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");
38307
- const bytes = await fs68.readBytes(target, active, REFERENCE_LIMITS.sourceBytes);
38308
- const afterTarget = await fs68.resolve(mapped, { signal: active }), after = await fs68.stat(afterTarget, active);
38309
- const afterPath = await fs68.lstat(mapped, void 0, active);
39266
+ const bytes = await fs69.readBytes(target, active, REFERENCE_LIMITS.sourceBytes);
39267
+ const afterTarget = await fs69.resolve(mapped, { signal: active }), after = await fs69.stat(afterTarget, active);
39268
+ const afterPath = await fs69.lstat(mapped, void 0, active);
38310
39269
  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");
38311
39270
  active.throwIfAborted();
38312
39271
  return bytes;
@@ -38368,7 +39327,9 @@ var ReferenceHost = class {
38368
39327
  var WEBNOVEL_SETTINGS_NAMESPACE = "webnovel";
38369
39328
  var VISUAL_MODES = ["workflow", "graph", "chapters"];
38370
39329
  var GRAPH_PERSPECTIVES = ["author", "reader"];
39330
+ var AUTOMATION_MODES = ["semi-auto", "auto", "manual"];
38371
39331
  var DEFAULT_WEBNOVEL_PREFERENCES = {
39332
+ automationMode: "semi-auto",
38372
39333
  autoIndexOnCommit: false,
38373
39334
  showVisualTab: true,
38374
39335
  showLayoutSwap: true,
@@ -38389,6 +39350,9 @@ function isVisualMode(value) {
38389
39350
  function isGraphPerspective(value) {
38390
39351
  return typeof value === "string" && GRAPH_PERSPECTIVES.includes(value);
38391
39352
  }
39353
+ function isAutomationMode(value) {
39354
+ return typeof value === "string" && AUTOMATION_MODES.includes(value);
39355
+ }
38392
39356
  function hasExplicitAutoIndex(raw) {
38393
39357
  return isRecord(raw) && typeof raw.autoIndexOnCommit === "boolean";
38394
39358
  }
@@ -38396,6 +39360,7 @@ function normalizeWebnovelPreferences(raw) {
38396
39360
  const source2 = isRecord(raw) ? raw : {};
38397
39361
  const bool = (key) => typeof source2[key] === "boolean" ? source2[key] : DEFAULT_WEBNOVEL_PREFERENCES[key];
38398
39362
  return {
39363
+ automationMode: isAutomationMode(source2.automationMode) ? source2.automationMode : DEFAULT_WEBNOVEL_PREFERENCES.automationMode,
38399
39364
  autoIndexOnCommit: bool("autoIndexOnCommit"),
38400
39365
  showVisualTab: bool("showVisualTab"),
38401
39366
  showLayoutSwap: bool("showLayoutSwap"),
@@ -38414,6 +39379,7 @@ function validateWebnovelPreferences(raw) {
38414
39379
  }
38415
39380
  if (raw.defaultVisualMode !== void 0 && !isVisualMode(raw.defaultVisualMode)) throw new Error("\u9ED8\u8BA4\u53EF\u89C6\u5316\u5B50\u89C6\u56FE\u65E0\u6548");
38416
39381
  if (raw.defaultGraphPerspective !== void 0 && !isGraphPerspective(raw.defaultGraphPerspective)) throw new Error("\u4EBA\u7269\u5173\u7CFB\u9ED8\u8BA4\u89C6\u89D2\u65E0\u6548");
39382
+ if (raw.automationMode !== void 0 && !isAutomationMode(raw.automationMode)) throw new Error("\u521B\u4F5C\u6D41\u7A0B\u81EA\u52A8\u5316\u6A21\u5F0F\u65E0\u6548");
38417
39383
  return raw;
38418
39384
  }
38419
39385
 
@@ -38452,8 +39418,8 @@ function createIndexAutoPreference(settings, fallback) {
38452
39418
  }
38453
39419
 
38454
39420
  // src/scripts/deterministic-checks.ts
38455
- import * as fs65 from "node:fs";
38456
- import * as path78 from "node:path";
39421
+ import * as fs66 from "node:fs";
39422
+ import * as path79 from "node:path";
38457
39423
  function parseArgs(argv) {
38458
39424
  const values = /* @__PURE__ */ new Map();
38459
39425
  for (let i = 0; i < argv.length; i += 1) {
@@ -38483,8 +39449,8 @@ function runChecksCli(argv) {
38483
39449
  console.error(`\u524D\u7F6E\u53C2\u6570\u9519\u8BEF\uFF1A${err instanceof Error ? err.message : String(err)}`);
38484
39450
  return 1;
38485
39451
  }
38486
- if (!fs65.existsSync(args.book) || !fs65.statSync(args.book).isDirectory()) {
38487
- console.error(`\u4E66\u4ED3\u4E0D\u5B58\u5728\uFF1A${path78.resolve(args.book)}`);
39452
+ if (!fs66.existsSync(args.book) || !fs66.statSync(args.book).isDirectory()) {
39453
+ console.error(`\u4E66\u4ED3\u4E0D\u5B58\u5728\uFF1A${path79.resolve(args.book)}`);
38488
39454
  return 1;
38489
39455
  }
38490
39456
  try {
@@ -38518,8 +39484,8 @@ function runChecksCli(argv) {
38518
39484
  }
38519
39485
 
38520
39486
  // src/scripts/draft-length-cli.ts
38521
- import * as fs66 from "node:fs";
38522
- import * as path79 from "node:path";
39487
+ import * as fs67 from "node:fs";
39488
+ import * as path80 from "node:path";
38523
39489
  function unverified(reason, exitCode) {
38524
39490
  console.log(JSON.stringify({ \u6838\u9A8C\u6765\u6E90: "\u5F53\u524D\u6587\u4EF6", \u7EDF\u8BA1\u72B6\u6001: "\u672A\u6838\u9A8C", \u539F\u56E0: reason }, null, 2));
38525
39491
  return exitCode;
@@ -38540,14 +39506,14 @@ function draftLengthCli(argv) {
38540
39506
  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);
38541
39507
  }
38542
39508
  try {
38543
- if (!fs66.statSync(book).isDirectory()) return unverified("\u4E66\u4ED3\u8DEF\u5F84\u4E0D\u662F\u76EE\u5F55", 1);
39509
+ if (!fs67.statSync(book).isDirectory()) return unverified("\u4E66\u4ED3\u8DEF\u5F84\u4E0D\u662F\u76EE\u5F55", 1);
38544
39510
  const resolved = resolveInsideBook(book, requested);
38545
39511
  if (!resolved.ok) return unverified(resolved.reason, 1);
38546
39512
  const target = draftLengthTarget(resolved.relPath);
38547
39513
  if (target?.\u6587\u672C\u9636\u6BB5 !== "\u8349\u7A3F\u6587\u4EF6") return unverified("\u5B9E\u9645\u76EE\u6807\u4E0D\u662F\u89C4\u8303\u5B8C\u6574\u7A3F", 1);
38548
- const file = path79.join(book, resolved.relPath);
38549
- if (!fs66.statSync(file).isFile()) return unverified("\u7A3F\u4EF6\u76EE\u6807\u4E0D\u662F\u666E\u901A\u6587\u4EF6", 1);
38550
- const text5 = fs66.readFileSync(file, "utf8");
39514
+ const file = path80.join(book, resolved.relPath);
39515
+ if (!fs67.statSync(file).isFile()) return unverified("\u7A3F\u4EF6\u76EE\u6807\u4E0D\u662F\u666E\u901A\u6587\u4EF6", 1);
39516
+ const text5 = fs67.readFileSync(file, "utf8");
38551
39517
  const result = draftLengthFeedback(target, text5, readChapterLength(book));
38552
39518
  console.log(JSON.stringify({ \u6838\u9A8C\u6765\u6E90: "\u5F53\u524D\u6587\u4EF6", ...result }, null, 2));
38553
39519
  return result.\u7EDF\u8BA1\u72B6\u6001 === "\u5DF2\u7EDF\u8BA1" ? 0 : 1;
@@ -38613,7 +39579,7 @@ function materialsCli(argv) {
38613
39579
  return 1;
38614
39580
  }
38615
39581
  try {
38616
- const c = computeMaterials(book, { \u5377, \u7AE0, \u7AE0\u540D });
39582
+ const c = computeMaterials(book, { \u5377, \u7AE0, \u7AE0\u540D, \u8D28\u91CF\u6A21\u5F0F: true });
38617
39583
  console.log(JSON.stringify({
38618
39584
  ok: c.ok,
38619
39585
  \u72B6\u6001: c.\u72B6\u6001,
@@ -38766,8 +39732,8 @@ function exportCli(argv) {
38766
39732
  }
38767
39733
 
38768
39734
  // src/scripts/screenplay-export-cli.ts
38769
- import * as fs67 from "node:fs";
38770
- import * as path80 from "node:path";
39735
+ import * as fs68 from "node:fs";
39736
+ import * as path81 from "node:path";
38771
39737
  function argValue5(argv, name3) {
38772
39738
  const i = argv.indexOf(`--${name3}`);
38773
39739
  return i === -1 ? void 0 : argv[i + 1];
@@ -38828,12 +39794,12 @@ function screenplayExportCli(argv) {
38828
39794
  const \u5206\u955C\u5934raw = argValue5(argv, "\u5206\u955C\u5934")?.trim();
38829
39795
  let \u5206\u955C\u5934\u8868;
38830
39796
  if (\u5206\u955C\u5934raw !== void 0) {
38831
- const shotPath = path80.isAbsolute(\u5206\u955C\u5934raw) ? \u5206\u955C\u5934raw : path80.join(book, \u5206\u955C\u5934raw);
38832
- if (!fs67.existsSync(shotPath) || !fs67.statSync(shotPath).isFile()) {
39797
+ const shotPath = path81.isAbsolute(\u5206\u955C\u5934raw) ? \u5206\u955C\u5934raw : path81.join(book, \u5206\u955C\u5934raw);
39798
+ if (!fs68.existsSync(shotPath) || !fs68.statSync(shotPath).isFile()) {
38833
39799
  console.error(`\u5206\u955C\u5934\u8868\u4E0D\u5B58\u5728\uFF1A${shotPath}`);
38834
39800
  return 1;
38835
39801
  }
38836
- const parsed = parseShotListTable(fs67.readFileSync(shotPath, "utf-8"));
39802
+ const parsed = parseShotListTable(fs68.readFileSync(shotPath, "utf-8"));
38837
39803
  if (!parsed.ok || parsed.shotList === void 0) {
38838
39804
  console.error(`\u5206\u955C\u5934\u8868\u89E3\u6790\u5931\u8D25\uFF1A${parsed.problems.join("\uFF1B")}`);
38839
39805
  return 1;
@@ -38843,13 +39809,13 @@ function screenplayExportCli(argv) {
38843
39809
  const \u603B\u7EB2raw = argValue5(argv, "\u603B\u7EB2")?.trim();
38844
39810
  let \u603B\u7EB2;
38845
39811
  if (\u603B\u7EB2raw !== void 0) {
38846
- const biblePath = path80.isAbsolute(\u603B\u7EB2raw) ? \u603B\u7EB2raw : path80.join(book, \u603B\u7EB2raw);
38847
- if (!fs67.existsSync(biblePath) || !fs67.statSync(biblePath).isFile()) {
39812
+ const biblePath = path81.isAbsolute(\u603B\u7EB2raw) ? \u603B\u7EB2raw : path81.join(book, \u603B\u7EB2raw);
39813
+ if (!fs68.existsSync(biblePath) || !fs68.statSync(biblePath).isFile()) {
38848
39814
  console.error(`\u603B\u7EB2\u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A${biblePath}`);
38849
39815
  return 1;
38850
39816
  }
38851
39817
  try {
38852
- const parsedBible = JSON.parse(fs67.readFileSync(biblePath, "utf-8"));
39818
+ const parsedBible = JSON.parse(fs68.readFileSync(biblePath, "utf-8"));
38853
39819
  if (typeof parsedBible !== "object" || parsedBible === null || Array.isArray(parsedBible)) {
38854
39820
  console.error("\u603B\u7EB2\u89E3\u6790\u5931\u8D25\uFF1A\u603B\u7EB2 JSON \u987B\u4E3A\u5BF9\u8C61\uFF08StoryBibleInput \u4E03\u8282\uFF09");
38855
39821
  return 1;
@@ -38947,6 +39913,7 @@ function volumeSummaryCli(argv) {
38947
39913
  // src/index.ts
38948
39914
  var name2 = "webnovel-bundle";
38949
39915
  var PreferenceSchema = Schema.object({
39916
+ automationMode: Schema.union([...AUTOMATION_MODES]).default(DEFAULT_WEBNOVEL_PREFERENCES.automationMode).description("\u521B\u4F5C\u6D41\u7A0B \xB7 \u81EA\u52A8\u5316\u6A21\u5F0F\uFF08semi-auto=\u534A\u81EA\u52A8\u4E24\u6B65\u8D70\uFF0Cauto=\u5168\u81EA\u52A8\u6258\u7BA1\uFF0Cmanual=\u4E25\u683C\u9010\u9879\u786E\u8BA4\uFF09"),
38950
39917
  autoIndexOnCommit: Schema.boolean().description("\u68C0\u7D22 \xB7 \u63D0\u4EA4\u540E\u81EA\u52A8\u66F4\u65B0\u5B9A\u7A3F\u7D22\u5F15"),
38951
39918
  showVisualTab: Schema.boolean().default(DEFAULT_WEBNOVEL_PREFERENCES.showVisualTab).description("\u53EF\u89C6\u5316 \xB7 \u5BF9\u8BDD\u533A\u6807\u7B7E"),
38952
39919
  showLayoutSwap: Schema.boolean().default(DEFAULT_WEBNOVEL_PREFERENCES.showLayoutSwap).description("\u5DE5\u4F5C\u53F0 \xB7 \u5E03\u5C40\u4E92\u6362\u6309\u94AE"),
@@ -39220,6 +40187,23 @@ function apply(ctx, entry) {
39220
40187
  });
39221
40188
  const editorRequests = new EditorRequestHub();
39222
40189
  attachStudyWeb(ctx, indexing, editorRequests);
40190
+ const readAutomationMode = () => {
40191
+ try {
40192
+ const settings = ctxGet(ctx, "settings");
40193
+ const doc = settings?.describe?.().find((item) => item.ns === WEBNOVEL_SETTINGS_NAMESPACE);
40194
+ if (doc?.value !== void 0) return normalizeWebnovelPreferences(doc.value).automationMode;
40195
+ } catch {
40196
+ }
40197
+ if (entry && typeof entry.get === "function") {
40198
+ try {
40199
+ return normalizeWebnovelPreferences(entry.get()).automationMode;
40200
+ } catch {
40201
+ }
40202
+ } else if (entry !== void 0) {
40203
+ return normalizeWebnovelPreferences(entry).automationMode;
40204
+ }
40205
+ return DEFAULT_WEBNOVEL_PREFERENCES.automationMode;
40206
+ };
39223
40207
  function ensureToolKit(scope2) {
39224
40208
  if (toolKit !== void 0) return;
39225
40209
  const questions = ctxGet(scope2, "userQuestions");
@@ -39237,6 +40221,7 @@ function apply(ctx, entry) {
39237
40221
  workspaceRoot: (agent) => agentWorkspaceRoot(agent),
39238
40222
  bookRootOfBookId: (bookId2, agent) => bookRootOfBookIdFor(bookId2, agent),
39239
40223
  askFn,
40224
+ automationMode: readAutomationMode,
39240
40225
  nativeWrite: bridge?.write,
39241
40226
  // 测试/走查专用工具(seed 占位设计)只在显式开启时注册,作者环境看不到
39242
40227
  testTools: process.env["WEBNOVEL_TEST_TOOLS"] === "1",
@@ -39528,6 +40513,7 @@ function apply(ctx, entry) {
39528
40513
  void indexing.refresh();
39529
40514
  }
39530
40515
  export {
40516
+ AUTOMATION_MODES,
39531
40517
  Config,
39532
40518
  DEFAULT_WEBNOVEL_PREFERENCES,
39533
40519
  NOVEL_CONDITIONAL_TOOL_NAMES,