dsh-novel-fanfic 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## v0.2.1(2026-11-21)
4
+
5
+ ### 修复:开启同人工作室后,DSH 里每条消息都返回 400
6
+
7
+ - **现象**:装 0.2.0 并执行 `/fic on` 之后,会话里每条消息都失败:
8
+ `Invalid schema for function 'fic_plan': {"type":"string","description":"…"} is not of type "string"`
9
+ (`INVALID_REQUEST` / status 400)。`/fic on` 会把选择写进 `prefs.json`,**重启后每个新会话都会中招**,
10
+ 与是否在写同人无关;`/fic off` 只对当前进程生效,必须重启 DSH 才恢复。
11
+ - **根因**:六个 `fic_*` 工具把插件内部的「参数名 → 描述对象」表直接交给了 `ctx.tools.register()`。
12
+ 这版 DSH 的 `register()` 收的是编译好的 JSON Schema(简写只对 `defineTool()` 生效),宿主原样透传给模型接口;
13
+ `fic_plan` 新增的参数名 `title` 是 JSON Schema 的注解关键字(值必须是字符串),整份工具定义因此被拒。
14
+ 0.1.0 是同样的写法,但没有参数名踩到保留字,所以只是「模型看不到参数说明」,不会 400。
15
+ - **修复**:`index.js` 新增 `parameterSchema()`,六个工具统一编译成
16
+ `{type:'object', properties, required:[参数名]}`;新增两条回归用例(完整 JSON Schema、参数表不得顶到 schema 根)。
17
+ - **验证**:`node --test` 172/172;`npm run check`;用 DSH 安装包自带的 `assertSupportedJsonSchema`
18
+ 逐个验证 6 个工具的 `parameters` 与 `output.schema`,6/6 通过。
19
+ - **影响面**:只改工具定义的形状,不动 canon / 契约 / 面板 / 存储格式;已导入的项目不需要迁移。
20
+
3
21
  ## v0.2.0(2026-11-21)
4
22
 
5
23
  ### 新增:只读服务 `novelFanfic`
package/README.md CHANGED
@@ -21,7 +21,16 @@
21
21
  导入原著 → 确认 canon → 声明本作设定 → 写一张章节任务卡 → 编译场景契约 → 在工作区写 → 检查 → 登记改动
22
22
  ```
23
23
 
24
- ## 这个版本(v0.2.0)
24
+ ## v0.2.1 修复:0.2.0 会让 DSH 的所有对话返回 400
25
+
26
+ **如果你装过 0.2.0 并执行过 `/fic on`,请升级到 0.2.1 并重启 DSH。** 0.2.0 里六个 `fic_*` 工具把内部参数表直接当
27
+ JSON Schema 交给了宿主,而新增的 `fic_plan` 有个参数叫 `title`——它正好是 JSON Schema 的注解关键字。后果是开启同人工具后
28
+ 每条消息都失败(`Invalid schema for function 'fic_plan': … is not of type "string"`),而且 `/fic on` 会被记住,
29
+ 重启后**每个新会话**都中招,与是否在写同人无关。
30
+
31
+ 临时自救:在会话里 `/fic off`,然后**重启 DSH**(`/fic off` 只对当前进程生效)。升级到 0.2.1 则不需要这一步。
32
+
33
+ ## 这个版本(v0.2.1,功能面同 0.2.0)
25
34
 
26
35
  - **只读服务 `novelFanfic`**:`identity / getStatus / getRevision / getContract / getCanonSummary / onDidChange`。
27
36
  别的插件(舞台监督)能按能力读到「这一章的契约是哪一版」,不用猜。服务只读、永不读夹具。
package/index.js CHANGED
@@ -38,6 +38,22 @@ const DEFAULTS = {
38
38
  fixture: 'dsh-novel-fanfic/fixtures/fixture-a',
39
39
  };
40
40
 
41
+ /** 把插件内部的参数字段简写编译成宿主和模型 API 都接受的 JSON Schema。 */
42
+ function parameterSchema(fields) {
43
+ const properties = {};
44
+ const required = [];
45
+ for (const [name, definition] of Object.entries(fields)) {
46
+ const { required: isRequired, ...property } = definition;
47
+ properties[name] = property;
48
+ if (isRequired === true) required.push(name);
49
+ }
50
+ return {
51
+ type: 'object',
52
+ properties,
53
+ ...(required.length ? { required } : {}),
54
+ };
55
+ }
56
+
41
57
  /** 从 start 向上找含夹具的开发 checkout(cordis.patch.yml 的 root 没生效时的兜底)。 */
42
58
  function findRepoRoot(start) {
43
59
  let dir = path.resolve(start);
@@ -267,10 +283,10 @@ export function apply(ctx, config = {}) {
267
283
  description:
268
284
  '查看同人工作室的当前状态:夹具章节数、canon 各桶的 confirmed 数量、本作设定条数、未裁决的设定矛盾、契约漂移。'
269
285
  + '在任何 fic_* 操作前先用它确认项目已经导入原著。插件需先 /fic on。',
270
- parameters: {
286
+ parameters: parameterSchema({
271
287
  project: { type: 'string', description: '项目名(.dsh-novel-fanfic/<project>),默认取插件配置。' },
272
288
  root: { type: 'string', description: '工作目录,默认取插件配置。' },
273
- },
289
+ }),
274
290
  output: output(),
275
291
  async execute(args) {
276
292
  const lines = [];
@@ -301,7 +317,7 @@ export function apply(ctx, config = {}) {
301
317
  '管理原著来源。action=import(file=本地 txt/md 路径,UTF-8 或 GB18030,≤20MB,重复文件会被 sha256 拦下)、'
302
318
  + 'action=list(列出已导入的章节)、action=read(chapter=chNNN,读该章正文)、action=index(读确定性索引:人物候选/称呼/统计)。'
303
319
  + '导入只做存储与分章,不生成 canon;canon 走提案与人工确认。',
304
- parameters: {
320
+ parameters: parameterSchema({
305
321
  action: {
306
322
  type: 'string',
307
323
  required: true,
@@ -313,7 +329,7 @@ export function apply(ctx, config = {}) {
313
329
  limit: { type: 'integer', description: 'action=read 时最多返回多少字,默认 4000。' },
314
330
  project: { type: 'string', description: '项目名。' },
315
331
  root: { type: 'string', description: '工作目录。' },
316
- },
332
+ }),
317
333
  output: output(),
318
334
  async execute(args) {
319
335
  const c = ctxOf(args || {});
@@ -367,12 +383,12 @@ export function apply(ctx, config = {}) {
367
383
  '取某一章的写作契约(九段:视角/在场/称呼/知情/世界规则/时间线/禁忌/不确定/锚点;有本作设定时最前面多一段【本作】,'
368
384
  + '本作优先于原著),由 canon 确定性编译,不接受自由发挥。chapter=ch002 取单章;chapter=all 列出各章摘要。'
369
385
  + '写这一章之前必须先把契约读进来。',
370
- parameters: {
386
+ parameters: parameterSchema({
371
387
  chapter: { type: 'string', required: true, description: '章 id,如 ch002;all 表示全部。' },
372
388
  source: { type: 'string', enum: ['fixture', 'canon'], description: '数据源:fixture(夹具,默认)或 canon(已导入的项目)。' },
373
389
  project: { type: 'string', description: '项目名。' },
374
390
  root: { type: 'string', description: '工作目录。' },
375
- },
391
+ }),
376
392
  output: output(),
377
393
  async execute(args) {
378
394
  const loaded = await canonOf(args || {}, args?.source);
@@ -412,7 +428,7 @@ export function apply(ctx, config = {}) {
412
428
  + '未声明私设、20 字复制、契约遗漏。text 或 file 二选一,chapter 指定场景。返回每条 finding 的'
413
429
  + '「在哪、凭什么、跟哪条设定冲突」;作者登记过的本作设定会放过同类 finding,并在 suppressed 里列出,'
414
430
  + '不改稿、不评分。',
415
- parameters: {
431
+ parameters: parameterSchema({
416
432
  chapter: { type: 'string', required: true, description: '章 id,如 ch004。' },
417
433
  text: { type: 'string', description: '要检查的正文(不必带【标签】行)。' },
418
434
  file: { type: 'string', description: '或从本地文件读取。' },
@@ -420,7 +436,7 @@ export function apply(ctx, config = {}) {
420
436
  source: { type: 'string', enum: ['fixture', 'canon'], description: '数据源:fixture(夹具,默认)或 canon(已导入的项目)。' },
421
437
  project: { type: 'string', description: '项目名。' },
422
438
  root: { type: 'string', description: '工作目录。' },
423
- },
439
+ }),
424
440
  output: output(),
425
441
  async execute(args) {
426
442
  let raw = String(args?.text || '');
@@ -474,7 +490,7 @@ export function apply(ctx, config = {}) {
474
490
  + '它不是契约、不是 canon、不是 beat 的决策账本:只落 project/chapters/<章>/mission.json,'
475
491
  + '删掉不影响契约编译;唯一进契约的地方是 openQuestions(进「不确定」段)。'
476
492
  + '字段都可选,三行也算一张卡。',
477
- parameters: {
493
+ parameters: parameterSchema({
478
494
  chapter: { type: 'string', required: true, description: '章 id,如 ch002' },
479
495
  action: { type: 'string', enum: ['get', 'set', 'clear'], description: '默认 get' },
480
496
  title: { type: 'string', description: '这一章的一句话标题' },
@@ -492,7 +508,7 @@ export function apply(ctx, config = {}) {
492
508
  source_chapter: { type: 'string', description: '对应原著章(本作章 ≠ 原著章,可不同)' },
493
509
  project: { type: 'string', description: '项目名' },
494
510
  root: { type: 'string', description: '工作目录' },
495
- },
511
+ }),
496
512
  output: output(),
497
513
  async execute(args) {
498
514
  const c = ctxOf(args || {});
@@ -557,7 +573,7 @@ export function apply(ctx, config = {}) {
557
573
  description:
558
574
  '在已导入的原著里检索能支撑写作的原文片段:返回章节、偏移、原句与命中理由。用它核对「这个人叫什么、'
559
575
  + '这里发生过什么」,不要凭记忆。entities 传人物/地名可提高命中精度。',
560
- parameters: {
576
+ parameters: parameterSchema({
561
577
  question: { type: 'string', required: true, description: '要查的问题,或要核对的事实,如「裴照什么时候改口叫阿砚」。' },
562
578
  entities: { type: 'array', items: { type: 'string' }, description: '相关实体(人物名、地点),可选。' },
563
579
  chapter_range: { type: 'array', items: { type: 'string' }, description: '限制章节范围,如 ["ch001","ch003"],可选。' },
@@ -565,7 +581,7 @@ export function apply(ctx, config = {}) {
565
581
  source: { type: 'string', enum: ['fixture', 'canon'], description: '数据源:fixture(夹具,默认)或 canon(已导入的项目)。' },
566
582
  project: { type: 'string', description: '项目名。' },
567
583
  root: { type: 'string', description: '工作目录。' },
568
- },
584
+ }),
569
585
  output: output(),
570
586
  async execute(args) {
571
587
  const { canon } = await canonOf(args || {}, args?.source);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-novel-fanfic",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "把原著导入,就能拥有一套专属的同人创作资料库。人物关系、剧情经历、世界规则,随时查阅;你想改写的人物命运、关系和剧情,也能按本作设定记录下来。写作时帮你理清人物知情、时间线和场景细节,写完还能检查人物 OOC、设定冲突和剧情前后矛盾。原著只是参考,你的故事由你决定。",
5
5
  "type": "module",
6
6
  "exports": {