dsh-plugin-prompt-tool 1.0.0 → 2.0.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.
Files changed (95) hide show
  1. package/README.md +38 -29
  2. package/engine/actions/append-context.mjs +49 -0
  3. package/engine/actions/assembly.mjs +150 -0
  4. package/engine/actions/catalog.mjs +92 -0
  5. package/engine/actions/content.mjs +205 -0
  6. package/engine/actions/decision.mjs +54 -0
  7. package/engine/actions/examples.mjs +11 -0
  8. package/engine/actions/guard.mjs +80 -0
  9. package/engine/actions/inbox-prepend.mjs +37 -0
  10. package/engine/actions/index.mjs +100 -0
  11. package/engine/actions/inject-text.mjs +22 -0
  12. package/engine/actions/pre-step-filter.mjs +55 -0
  13. package/engine/actions/registration.mjs +168 -0
  14. package/engine/actions/request-params.mjs +32 -0
  15. package/engine/actions/sdk-strip.mjs +30 -0
  16. package/engine/actions/shared.mjs +71 -0
  17. package/engine/actions.mjs +2 -931
  18. package/engine/branch.mjs +44 -0
  19. package/engine/compaction-epoch.mjs +31 -13
  20. package/engine/compositions/source/local/dev-tool-search.yml +11 -0
  21. package/engine/compositions/source/local/instruction-hint.yml +22 -1
  22. package/engine/compositions/source/local/rule-engine.yml +6 -0
  23. package/engine/condition.mjs +16 -3
  24. package/engine/conditions/anchor.mjs +32 -0
  25. package/engine/conditions/availability.mjs +47 -0
  26. package/engine/conditions/composite.mjs +83 -0
  27. package/engine/conditions/count.mjs +140 -0
  28. package/engine/conditions/evaluation.mjs +41 -0
  29. package/engine/conditions/examples.mjs +11 -0
  30. package/engine/conditions/index.mjs +85 -0
  31. package/engine/conditions/names.mjs +21 -0
  32. package/engine/conditions/phase.mjs +54 -0
  33. package/engine/conditions/preset.mjs +94 -0
  34. package/engine/conditions/scope.mjs +18 -0
  35. package/engine/conditions/session.mjs +22 -0
  36. package/engine/conditions/source.mjs +63 -0
  37. package/engine/conditions/subject.mjs +121 -0
  38. package/engine/conditions/text.mjs +44 -0
  39. package/engine/conditions/values.mjs +32 -0
  40. package/engine/dev-tool-search.mjs +213 -0
  41. package/engine/executor.mjs +55 -6
  42. package/engine/fillers.mjs +23 -16
  43. package/engine/instruction-hint.mjs +34 -22
  44. package/engine/layers.mjs +135 -49
  45. package/engine/order.mjs +4 -1
  46. package/engine/predicates.mjs +2 -753
  47. package/engine/rule-engine.mjs +40 -0
  48. package/engine/rule-runtime.mjs +110 -0
  49. package/engine/rule-spec.mjs +187 -0
  50. package/engine/schema.mjs +16 -5
  51. package/engine/shared.mjs +1 -1
  52. package/engine/strategies.mjs +2 -235
  53. package/engine/subagent-tool-policy-core.mjs +7 -7
  54. package/engine/subagent-tool-policy.mjs +20 -10
  55. package/engine/tool-config-engine.mjs +53 -32
  56. package/engine/trigger-spec.mjs +49 -133
  57. package/lib/client.js +11117 -10860
  58. package/lib/client.js.map +1 -1
  59. package/lib/index.d.mts +82 -139
  60. package/lib/index.mjs +826 -1087
  61. package/lib/migrate-rules.d.mts +1 -0
  62. package/lib/migrate-rules.mjs +39 -0
  63. package/lib/module-package-CHPFweqK.mjs +2 -0
  64. package/lib/module-package-Cnd1_mwx.mjs +2872 -0
  65. package/lib/{paths-BgL42sSM.d.mts → paths-CyP0IkaM.d.mts} +223 -108
  66. package/lib/preset-transfer.d.mts +2 -2
  67. package/lib/preset-transfer.mjs +3 -2
  68. package/lib/{module-package-Cm3fHHlp.mjs → rules-migration-DJ6vASB5.mjs} +13696 -15557
  69. package/modules/ponytail/module.yml +381 -147
  70. package/modules/skill-surface/module.yml +74 -0
  71. package/modules/tool-surface/module.yml +67 -0
  72. package/package.json +5 -1
  73. package/templates/10-pre-step.yml +26 -22
  74. package/templates/14-first-turn-anchor.yml +25 -21
  75. package/templates/15-guide-auto.yml +34 -19
  76. package/templates/16-custom-fallback.yml +27 -15
  77. package/templates/18-placeholder-env-facts.yml +23 -14
  78. package/templates/20-system-section.yml +16 -10
  79. package/templates/30-runtime-context.yml +13 -7
  80. package/templates/40-agent-request.yml +11 -8
  81. package/templates/50-llm-stream.yml +14 -6
  82. package/templates/60-tool-pipeline.yml +15 -9
  83. package/templates/65-turn-stop.yml +19 -12
  84. package/templates/66-subagent-start.yml +12 -7
  85. package/templates/70-subagent-maintenance.yml +35 -29
  86. package/templates/75-subagent-end.yml +10 -5
  87. package/templates/80-tool-surface.yml +66 -0
  88. package/templates/policies/legacy-defaults.yml +34 -0
  89. package/engine/compositions/source/local/prompt-config-engine.yml +0 -7
  90. package/engine/prompt-config-engine.mjs +0 -104
  91. package/engine/trigger-editor-meta.mjs +0 -48
  92. package/modules/ponytail/configs/0000-ponytail-rules.yml +0 -102
  93. package/modules/ponytail/configs/0010-ponytail-level-full.yml +0 -19
  94. package/modules/ponytail/configs/0020-ponytail-level-lite.yml +0 -19
  95. package/modules/ponytail/configs/0030-ponytail-level-ultra.yml +0 -19
@@ -2,7 +2,13 @@ import { parseDocument } from "yaml";
2
2
  //#region src/shared/engine-capabilities.d.ts
3
3
  type ModuleSourceMode = 'explicit' | 'composition' | 'official' | 'unknown';
4
4
  /** 官方九个注入层:与 engine/schema.mjs 的 LAYER_ORDER 同源,改一处必须同步另一处。 */
5
- type EngineLayer = 'pre-step' | 'system-section' | 'runtime-context' | 'agent-request' | 'llm-stream' | 'tool-pipeline' | 'turn-stop' | 'subagent-start' | 'subagent-end';
5
+ type InjectionPoint = 'pre-step' | 'system-section' | 'runtime-context' | 'agent-request' | 'llm-stream' | 'tool-pipeline' | 'turn-stop' | 'subagent-start' | 'subagent-end';
6
+ /** 旧公开类型名只作输入兼容。 */
7
+ /**
8
+ * 九层顺序的共享副本:宿主是旧版本(不下发 meta.layerOrder)时前端退化用它,
9
+ * 而不是各自再写一份层序清单。
10
+ */
11
+ declare const INJECTION_POINT_ORDER: readonly InjectionPoint[];
6
12
  interface ModuleFacts {
7
13
  declaredModules: string[] | null;
8
14
  effectiveModules: string[] | null;
@@ -13,13 +19,13 @@ interface ModuleFacts {
13
19
  /** 策略段真实存在;能力声明仍在并不代表策略已开启。 */
14
20
  subagentToolPolicyEnabled?: boolean;
15
21
  }
16
- interface EngineCapability {
22
+ interface ModuleCapability {
17
23
  id: string;
18
24
  moduleKeys: readonly string[];
19
25
  rowIds: readonly string[];
20
- displayLayer: EngineLayer;
26
+ displayLayer: InjectionPoint;
21
27
  /** 真实跨层影响的相关层(只在确有第二通道时登记,避免把归属铺满九层)。 */
22
- relatedLayers?: readonly EngineLayer[];
28
+ relatedLayers?: readonly InjectionPoint[];
23
29
  /**
24
30
  * 该能力拥有的 preset 顶层数据段(不是行级 config)。
25
31
  * 创建时若段缺失则写入 `skeleton`(保证"模块在 ⇒ 数据在");删除时一并移除该段。
@@ -32,16 +38,16 @@ interface EngineCapability {
32
38
  };
33
39
  }
34
40
  /** 首期只登记已有 typed editor 的能力,避免万能 key/value 表单。 */
35
- declare const ENGINE_CAPABILITIES: readonly EngineCapability[];
41
+ declare const MODULE_CAPABILITIES: readonly ModuleCapability[];
36
42
  /**
37
43
  * 编辑组 = 前端一张可编辑卡(能力卡或专用卡)的主归属层。
38
44
  * id 必须是代码里真实存在的 card / 展开键名,不新增臆造 id。
39
45
  */
40
46
  interface EngineEditorGroup {
41
47
  id: string;
42
- displayLayer: EngineLayer;
48
+ displayLayer: InjectionPoint;
43
49
  /** 真实跨层影响的相关层(只有确有第二通道时才写)。 */
44
- relatedLayers?: readonly EngineLayer[];
50
+ relatedLayers?: readonly InjectionPoint[];
45
51
  /** 真实生效通道的只读说明键(如 'agent-request' / 'system-section'):供 UI 显示「实际生效通道」,
46
52
  * 只写代码里可核对的事实,不承诺未验证的通道。 */
47
53
  hook: string;
@@ -60,13 +66,15 @@ interface EngineRecipe {
60
66
  * 空表天然让组合项整个消失。
61
67
  */
62
68
  declare const ENGINE_RECIPES: readonly EngineRecipe[];
63
- declare function engineCapability(id: string): EngineCapability | undefined;
69
+ declare function moduleCapability(id: string): ModuleCapability | undefined;
64
70
  declare function engineRecipe(id: string): EngineRecipe | undefined;
65
71
  /** 显式模块声明中的实际能力;包含当前参数与顶层策略所需的装配。
66
72
  * 创建补声明由 host 单独检查 declaredModules;官方组合行不伪装成可编辑能力。 */
67
- declare function isEngineCapabilityPresent(id: string, facts: ModuleFacts | undefined): boolean;
73
+ declare function isModuleCapabilityPresent(id: string, facts: ModuleFacts | undefined): boolean;
68
74
  /** custom tool 的运行时名称缺省回落 id;保存前拒绝会导致同层注册失败的重复项。 */
69
75
  declare function validateCustomToolIdentities(tools: readonly unknown[]): string[];
76
+ /** 已发布名称只在此边界保留,内部使用模块能力与插入点命名。 */
77
+ type EngineLayer = InjectionPoint;
70
78
  //#endregion
71
79
  //#region src/shared/instructions.d.ts
72
80
  /**
@@ -176,6 +184,88 @@ interface PersonaSpec {
176
184
  includeRuntimeContext?: boolean;
177
185
  }
178
186
  //#endregion
187
+ //#region src/shared/rules.d.ts
188
+ /** 一张独立配置卡的判断树;原语与组合的合法形状由引擎唯一校验。 */
189
+ type RuleCondition = Record<string, unknown>;
190
+ /** 动作拥有稳定身份;其执行点由动作目录推导,不能任意指定宿主事件。 */
191
+ interface RuleAction extends Record<string, unknown> {
192
+ id: string;
193
+ kind: string;
194
+ channelOrder?: number;
195
+ waterfallPosition?: 'default' | 'outermost';
196
+ }
197
+ /**
198
+ * module.yml.rules 的单一规则定义;层用于呈现归属,不建立跨层执行顺序。
199
+ *
200
+ * **旧名 `when`/`do` 已随引擎重构退役**(不再作为兼容输入),全链路只有 `if`/`then`/`else`。
201
+ * 定义迁移由 YAML Document API 改键名完成,注释与未知字段原地保留。
202
+ */
203
+ interface RuleDefinition {
204
+ id: string;
205
+ name?: string;
206
+ enabled?: boolean;
207
+ layer?: EngineLayer;
208
+ group?: string;
209
+ exclusive?: boolean;
210
+ /** 分支条件;缺省 = 无条件。 */
211
+ if?: RuleCondition;
212
+ /** 动作列表。 */
213
+ then: RuleAction[];
214
+ /** `if` 不命中时执行;与 `then` 结构互斥(编译期按 `not(if)` 展开)。 */
215
+ else?: RuleAction[];
216
+ }
217
+ /** 显式旧身份使改名、删除与 configOrder 在同一事务中更新。 */
218
+ interface RuleEdit {
219
+ previousId: string | null;
220
+ rule: RuleDefinition | null;
221
+ /** 正文编辑不拥有启停与互斥状态;修改状态须显式声明并校验 settings 版本。 */
222
+ settingsChanged?: boolean;
223
+ }
224
+ interface RuleRevisions {
225
+ rules: Record<string, string>;
226
+ settings: string;
227
+ variables: string;
228
+ }
229
+ interface RulesRequest {
230
+ expectedModuleId?: string;
231
+ /** 旧公开输入仅在边界归一。 */
232
+ expectedPresetId?: string;
233
+ expectedRevision?: string;
234
+ expectedRevisions?: Partial<RuleRevisions>;
235
+ edits?: RuleEdit[];
236
+ /** 显式启用目标;保存端同时停用同模块互斥组的其他卡。 */
237
+ activateRuleId?: string;
238
+ validateOnly?: boolean;
239
+ /** 只重新发布已提交定义,不能与规则修改或候选校验混用。 */
240
+ refreshOnly?: boolean;
241
+ }
242
+ interface RuleEditorMeta {
243
+ predicates: Array<{
244
+ kind: string;
245
+ example: Record<string, unknown>;
246
+ }>;
247
+ composites: string[];
248
+ actions: Array<{
249
+ kind: string;
250
+ example: Record<string, unknown>;
251
+ channel: string;
252
+ phase: string;
253
+ supportsWhen: boolean;
254
+ lifecycle?: 'event' | 'registration';
255
+ }>;
256
+ waterfallPositions: string[];
257
+ }
258
+ interface RulesSnapshot {
259
+ rules: RuleDefinition[];
260
+ revisions: RuleRevisions;
261
+ /** 仅旧客户端兼容输入,不是规范响应的版本来源。 */
262
+ revision?: string;
263
+ meta: RuleEditorMeta;
264
+ persisted?: boolean;
265
+ publicationPending?: boolean;
266
+ publicationError?: string;
267
+ }
268
+ //#endregion
179
269
  //#region src/shared/module-config-order.d.ts
180
270
  /** 配置卡身份与排序快照;序号归模块定义,正文不进入排序载荷。 */
181
271
  interface ModuleConfigIdentity {
@@ -233,14 +323,14 @@ interface AssetImportRequest extends ImportChoices {
233
323
  expectedSourceDigest?: string;
234
324
  expectedPreviewRevision?: string;
235
325
  }
236
- interface PresetExportRequest {
326
+ interface ModuleExportRequest {
237
327
  id: string;
238
328
  mode?: 'definition' | 'zip';
239
329
  preview?: boolean;
240
330
  expectedRevision?: string;
241
331
  memoryChoices?: Record<string, 'include' | 'exclude'>;
242
332
  }
243
- interface PresetExportResult {
333
+ interface ModuleExportResult {
244
334
  id: string;
245
335
  name: string;
246
336
  content: string;
@@ -372,7 +462,6 @@ declare const BRIDGE_ENDPOINTS: {
372
462
  readonly models: "/models";
373
463
  readonly modelReasoning: "/model-reasoning";
374
464
  readonly mutate: "/mutate";
375
- readonly configsValidate: "/configs-validate";
376
465
  readonly skillsList: "/skills-list";
377
466
  readonly skillPolicy: "/skill-policy";
378
467
  readonly skillRead: "/skill-read";
@@ -386,17 +475,18 @@ declare const BRIDGE_ENDPOINTS: {
386
475
  readonly promptConfigs: "/prompt-configs";
387
476
  readonly agentsFile: "/agents-file";
388
477
  readonly instructionsPolicy: "/instructions-policy";
389
- readonly presetContent: "/preset-content";
478
+ readonly moduleContent: "/module-content";
390
479
  readonly importPreset: "/import-preset";
391
480
  readonly paramOverrides: "/param-overrides";
392
481
  readonly triggers: "/triggers";
482
+ readonly rules: "/rules";
393
483
  readonly persona: "/persona";
394
- readonly presetVariables: "/preset-variables";
484
+ readonly moduleVariables: "/module-variables";
395
485
  readonly customTools: "/custom-tools";
396
- readonly importPresetPackage: "/import-preset-package";
486
+ readonly importModulePackage: "/import-module-package";
397
487
  readonly assetUpload: "/asset-upload";
398
488
  readonly assetRelease: "/asset-release";
399
- readonly exportPreset: "/export-preset";
489
+ readonly exportModule: "/export-module";
400
490
  readonly moduleDelete: "/module-delete";
401
491
  readonly moduleClone: "/module-clone";
402
492
  readonly moduleDuplicate: "/module-duplicate";
@@ -405,14 +495,12 @@ declare const BRIDGE_ENDPOINTS: {
405
495
  readonly moduleConfigOrder: "/module-config-order";
406
496
  readonly charactersImport: "/characters-import";
407
497
  readonly charactersImportStream: "/characters-import-stream";
408
- readonly charactersList: "/characters-list";
409
- readonly charactersDelete: "/characters-delete";
410
- readonly charactersApply: "/characters-apply";
411
- readonly charactersRemove: "/characters-remove";
498
+ readonly moduleMerge: "/module-merge";
499
+ readonly moduleUnmerge: "/module-unmerge";
412
500
  readonly subagentToolPolicy: "/subagent-tool-policy";
413
501
  readonly subagentToolPolicyPreview: "/subagent-tool-policy-preview";
414
502
  readonly toolSurface: "/tool-surface";
415
- readonly engineCapability: "/engine-capability";
503
+ readonly moduleCapability: "/module-capability";
416
504
  readonly worldBookDiagnostics: "/world-book-diagnostics";
417
505
  };
418
506
  type BridgeEndpoint = (typeof BRIDGE_ENDPOINTS)[keyof typeof BRIDGE_ENDPOINTS];
@@ -423,6 +511,18 @@ type BridgeErrorPayload = {
423
511
  message?: string;
424
512
  conflicts?: string[];
425
513
  };
514
+ /** 插件可编辑模块的身份与展示元数据;不可渲染的项保留身份供用户修复。 */
515
+ interface ModuleSummary {
516
+ id: string;
517
+ name: string;
518
+ user?: boolean;
519
+ renderable?: boolean;
520
+ description?: string;
521
+ meta?: Record<string, unknown>;
522
+ broken?: string;
523
+ /** 是否在存储根 `config.yml` 的启用表里(启用即参与运行时装配)。 */
524
+ enabled?: boolean;
525
+ }
426
526
  /**
427
527
  * 端点级请求体契约(body 形状;无请求体端点 = undefined)。
428
528
  * 与 BRIDGE_ENDPOINTS 一一对应:新增端点必须同时补请求/响应映射,否则编译期断言失败。
@@ -447,10 +547,6 @@ interface BridgeRequestMap {
447
547
  ops: unknown[];
448
548
  expectedRevision?: number;
449
549
  };
450
- configsValidate: {
451
- promptConfigs: unknown[];
452
- strategyDir?: string;
453
- };
454
550
  /** 技能清单:按会话工作区扫描官方六类技能根,调用策略取自各技能文件的 frontmatter。 */
455
551
  skillsList: {
456
552
  sessionId?: string;
@@ -529,39 +625,42 @@ interface BridgeRequestMap {
529
625
  policy?: InstructionPolicyPatch;
530
626
  expectedRevision?: string | null;
531
627
  } | undefined;
532
- presetContent: undefined;
628
+ moduleContent: undefined;
533
629
  importPreset: {
534
630
  contents: Array<{
535
631
  scope: 'preset' | 'agents';
536
632
  content: string;
537
633
  }>;
538
- expectedPresetId?: string;
634
+ expectedModuleId?: string;
539
635
  };
540
636
  paramOverrides: {
541
637
  overrides?: Record<string, unknown>;
542
638
  promptConfigs?: unknown[];
543
639
  rebuild?: boolean;
544
- expectedPresetId?: string;
640
+ expectedModuleId?: string;
545
641
  };
546
642
  triggers: {
547
- expectedPresetId: string;
643
+ expectedModuleId: string;
548
644
  triggers?: unknown[];
549
645
  expectedRevision?: string;
550
646
  validateOnly?: boolean;
551
647
  };
648
+ rules: RulesRequest;
552
649
  /** 顶层 persona 段读写(官方 @deepseek-ai/dsh-persona 行 config 同构);省略 persona 键 = 读取。 */
553
650
  persona: {
554
651
  persona?: PersonaSpec | null;
555
- expectedPresetId?: string;
652
+ expectedModuleId?: string;
556
653
  } | undefined;
557
- presetVariables: {
654
+ moduleVariables: {
558
655
  variables?: Record<string, string>;
559
656
  enabled?: boolean;
560
- expectedPresetId?: string;
657
+ expectedModuleId?: string;
658
+ expectedRevisions?: Partial<RuleRevisions>;
659
+ refreshOnly?: boolean;
561
660
  };
562
661
  customTools: {
563
662
  customTools?: unknown[];
564
- expectedPresetId?: string;
663
+ expectedModuleId?: string;
565
664
  } | undefined;
566
665
  /**
567
666
  * 模块包导入(原生/ST/PNG/ZIP)。`preview: true` 只转换并返回报告,不写目标;
@@ -572,12 +671,12 @@ interface BridgeRequestMap {
572
671
  * (`state: 'needs-order-selection'`),提交时仍无法明确对应则拒绝。
573
672
  * 上述参数只接受声明的类型,其它类型一律 400(见 docs/SillyTavern.md)。
574
673
  */
575
- importPresetPackage: AssetImportRequest;
674
+ importModulePackage: AssetImportRequest;
576
675
  assetUpload: undefined;
577
676
  assetRelease: {
578
677
  sourceId: string;
579
678
  };
580
- exportPreset: PresetExportRequest;
679
+ exportModule: ModuleExportRequest;
581
680
  moduleDelete: {
582
681
  id: string;
583
682
  };
@@ -602,22 +701,18 @@ interface BridgeRequestMap {
602
701
  entries: ModuleConfigIdentity[];
603
702
  expectedRevision: string;
604
703
  } | undefined;
605
- /** 角色卡 PNG/JSON/YAML 导入;预览不写角色库,提交必验版本,目标和选组均绑定预览。 */
704
+ /** 角色卡来源导入为普通模块;预览只读,提交与模块安装共用版本边界。 */
606
705
  charactersImport: AssetImportRequest;
607
706
  charactersImportStream: undefined;
608
- charactersList: undefined;
609
- charactersDelete: {
610
- id: string;
611
- };
612
- charactersApply: {
707
+ moduleMerge: {
613
708
  id: string;
614
709
  };
615
- charactersRemove: {
710
+ moduleUnmerge: {
616
711
  id: string;
617
712
  };
618
713
  subagentToolPolicy: {
619
714
  policy?: unknown;
620
- expectedPresetId?: string;
715
+ expectedModuleId?: string;
621
716
  } | undefined;
622
717
  subagentToolPolicyPreview: {
623
718
  tool?: string;
@@ -636,14 +731,14 @@ interface BridgeRequestMap {
636
731
  presetId: string;
637
732
  sessionId?: never;
638
733
  };
639
- engineCapability: ({
734
+ moduleCapability: ({
640
735
  action: 'create' | 'remove';
641
736
  capabilityId: string;
642
737
  } | {
643
738
  action: 'create-recipe';
644
739
  recipeId: string;
645
740
  }) & {
646
- expectedPresetId?: string;
741
+ expectedModuleId?: string;
647
742
  };
648
743
  /** 只读世界书诊断:只回当前授权会话最近一次选择的观测记录。 */
649
744
  worldBookDiagnostics: {
@@ -826,16 +921,6 @@ interface BridgeValueMap {
826
921
  reasoning: ModelReasoningView;
827
922
  };
828
923
  mutate: BridgeSettingsView;
829
- configsValidate: {
830
- valid: boolean;
831
- errors: Array<{
832
- index: number;
833
- id: string;
834
- message: string;
835
- }>;
836
- configs?: unknown[];
837
- files?: unknown[];
838
- };
839
924
  /** 技能清单 + 引用目录 + 技能根(客户端据此渲染来源分组与调用策略)。 */
840
925
  skillsList: SkillsCatalogSnapshot & {
841
926
  folders: string[];
@@ -882,7 +967,7 @@ interface BridgeValueMap {
882
967
  exists: boolean;
883
968
  error?: string;
884
969
  };
885
- presetContent: Record<string, unknown>;
970
+ moduleContent: Record<string, unknown>;
886
971
  importPreset: {
887
972
  scopes: Array<'preset' | 'agents'>;
888
973
  };
@@ -896,17 +981,22 @@ interface BridgeValueMap {
896
981
  revision: string;
897
982
  meta: TriggerEditorMeta;
898
983
  };
984
+ rules: RulesSnapshot;
899
985
  persona: {
900
986
  persona: PersonaSpec | null;
901
987
  };
902
- presetVariables: {
988
+ moduleVariables: {
903
989
  variables: Record<string, string>;
904
990
  enabled: boolean;
991
+ revisions: RuleRevisions;
992
+ persisted?: boolean;
993
+ publicationPending?: boolean;
994
+ publicationError?: string;
905
995
  };
906
996
  customTools: {
907
997
  customTools?: unknown[];
908
998
  };
909
- importPresetPackage: {
999
+ importModulePackage: {
910
1000
  id?: string;
911
1001
  backupPath?: string;
912
1002
  preview?: boolean;
@@ -928,7 +1018,7 @@ interface BridgeValueMap {
928
1018
  assetRelease: {
929
1019
  released: boolean;
930
1020
  };
931
- exportPreset: PresetExportResult;
1021
+ exportModule: ModuleExportResult;
932
1022
  moduleDelete: {
933
1023
  id: string;
934
1024
  };
@@ -961,23 +1051,11 @@ interface BridgeValueMap {
961
1051
  id: string;
962
1052
  name: string;
963
1053
  };
964
- charactersList: {
965
- characters: Array<{
966
- id: string;
967
- name: string;
968
- description?: string;
969
- hasAvatar: boolean;
970
- imported: boolean;
971
- }>;
972
- };
973
- charactersDelete: {
974
- id: string;
975
- };
976
- charactersApply: {
1054
+ moduleMerge: {
977
1055
  id: string;
978
1056
  count: number;
979
1057
  };
980
- charactersRemove: {
1058
+ moduleUnmerge: {
981
1059
  id: string;
982
1060
  count: number;
983
1061
  };
@@ -999,7 +1077,7 @@ interface BridgeValueMap {
999
1077
  description: string;
1000
1078
  }>;
1001
1079
  };
1002
- engineCapability: {
1080
+ moduleCapability: {
1003
1081
  changed: boolean;
1004
1082
  addedModules?: string[];
1005
1083
  removedModules?: string[];
@@ -1014,6 +1092,22 @@ interface BridgeValueMap {
1014
1092
  };
1015
1093
  }
1016
1094
  //#endregion
1095
+ //#region src/host/module-storage.d.ts
1096
+ interface ModuleDefinitionSnapshot {
1097
+ dir: string;
1098
+ file: string;
1099
+ text: string;
1100
+ doc: ReturnType<typeof parseDocument>;
1101
+ source: Record<string, unknown>;
1102
+ revision: string;
1103
+ revisions: RuleRevisions;
1104
+ rules: RuleDefinition[];
1105
+ configOrder: Record<string, number>;
1106
+ variables: Record<string, string>;
1107
+ variablesEnabled: boolean;
1108
+ }
1109
+ declare function withModuleDefinition$1(directory: string, mutate: (doc: ReturnType<typeof parseDocument>, source: Record<string, unknown>) => void): ModuleDefinitionSnapshot;
1110
+ //#endregion
1017
1111
  //#region src/host/manifest.d.ts
1018
1112
  /**
1019
1113
  * 模块目录确实存在于本插件存储根(身份判定与官方登记状态无关)。
@@ -1044,8 +1138,6 @@ interface ModuleSpec {
1044
1138
  params?: Record<string, unknown>;
1045
1139
  /** 共享引擎参数按编辑组的主归属插入点存储;规则实例仍拥有各自 params。 */
1046
1140
  layerSettings?: Record<string, Record<string, unknown>>;
1047
- /** 兼容读取诊断,不写回模块定义。 */
1048
- legacyParamWarnings?: string[];
1049
1141
  /** 顶层人设段(官方 @deepseek-ai/dsh-persona 行同构):prefix/suffix/complete/includeRuntimeContext。 */
1050
1142
  persona?: PersonaSpec;
1051
1143
  /** 模块级模板变量({{key}} 插值源;与 layerSettings 分离,顶层 variables 段)。 */
@@ -1054,18 +1146,16 @@ interface ModuleSpec {
1054
1146
  customTools?: unknown[];
1055
1147
  /** 子代理实例级工具策略(subagentToolPolicy 顶层领域段;缺省 = 官方 delegation 行为)。 */
1056
1148
  subagentToolPolicy?: Record<string, unknown>;
1057
- /**
1058
- * 触发器声明(`triggers` 顶层段):`{ id, channel, when?, do, … }` 的数组。
1059
- * 声明**由模块提供**(引擎不带默认),物化为 `triggers.yml` 后由 `declared-triggers`
1060
- * 运行时模块读入并注册;形状与校验归 `engine/trigger-spec.mjs` 的声明编译器。
1061
- */
1149
+ /** @deprecated 仅标记旧导入形状;loadModuleSpec 拒绝,须先离线迁移。 */
1062
1150
  triggers?: unknown[];
1063
1151
  /** 模板变量插值开关(缺省 true = 启用;false = 停用,writePreset 不生成变量文件)。 */
1064
1152
  variablesEnabled?: boolean;
1065
- /** 可选:模板自定义提示词配置覆盖(纯数据,不使用模板语法)。 */
1153
+ /** @deprecated 仅标记旧导入形状;loadModuleSpec 拒绝,须先离线迁移。 */
1066
1154
  promptConfigs?: unknown[];
1067
1155
  /** 配置卡的持久文件序号;跨模块UI排序只改此轻量元数据。 */
1068
1156
  configOrder?: Record<string, number>;
1157
+ /** 模块唯一的条件→动作定义;旧源只供离线迁移器读取。 */
1158
+ rules?: RuleDefinition[];
1069
1159
  /** 可选:引擎组合模块行参数直写(行级 map config 浅合并;参数桥未覆盖的键生效,参数桥优先)。 */
1070
1160
  moduleConfigs?: Record<string, Record<string, unknown>>;
1071
1161
  upstream?: Record<string, unknown>;
@@ -1074,16 +1164,14 @@ interface ModuleSpec {
1074
1164
  * 从模块 module.yml 的 modules 清单移除一个模块 id(YAML Document 保留注释
1075
1165
  * 与其余字段)。返回是否发生修改;文件缺失或没有该模块时返回 false。
1076
1166
  */
1077
- declare function removePresetModule(dir: string, moduleId: string): boolean;
1167
+ declare function removeModuleCapabilityDeclaration(dir: string, moduleId: string): boolean;
1078
1168
  /** 加载某个模块模板的单一参数文件 modules/<name>/module.yml。 */
1079
- declare function loadModuleSpec(dir: string, options?: {
1080
- legacyParams?: boolean;
1081
- }): ModuleSpec;
1169
+ declare function loadModuleSpec(dir: string): ModuleSpec;
1082
1170
  /** 模块根:本插件的存储根(~/.dsh/.prompt-tool),导入/新建/种子化的模块都放这里。 */
1083
1171
  declare function userModulesDir(): string;
1084
1172
  /**
1085
1173
  * 解析模块模板目录:当前模块根优先,包内模板回退;不读取其他部署根的同名模块。
1086
- * 目录名与声明的 preset.yml id 一致;不扫描其他目录的 id 别名。
1174
+ * 目录名与声明的 module.yml id 一致;不扫描其他目录的 id 别名。
1087
1175
  */
1088
1176
  declare function resolveModuleDir(template: string, moduleRoot?: string): string;
1089
1177
  /** 本插件模块清单;所有目录按同一身份与组合源规则列举。 */
@@ -1101,11 +1189,11 @@ declare function listBuiltinTemplates(): Array<{
1101
1189
  name: string;
1102
1190
  }>;
1103
1191
  /** 按包内同名目录补建缺失的内置模块;已有目录的定义、生成物和资源保持原样。 */
1104
- declare function ensurePresetSeed(root?: string): {
1192
+ declare function ensureModuleSeed(root?: string): {
1105
1193
  created: string[];
1106
1194
  };
1107
1195
  /** 从包内同名目录复制模块;autoSuffix=true 时递增目录名并同步定义身份。 */
1108
- declare function cloneBuiltinPreset(id: string, autoSuffix?: boolean, moduleRoot?: string): {
1196
+ declare function cloneBuiltinModule(id: string, autoSuffix?: boolean, moduleRoot?: string): {
1109
1197
  ok: true;
1110
1198
  id: string;
1111
1199
  } | {
@@ -1113,27 +1201,33 @@ declare function cloneBuiltinPreset(id: string, autoSuffix?: boolean, moduleRoot
1113
1201
  message: string;
1114
1202
  };
1115
1203
  /**
1116
- * 保存模块参数:写 layerSettings(merge)/ promptConfigs(整体替换)。
1117
- * parseDocument 保留注释与未知键(preset.yml 模板含大量注释);空值键删除('' / [],
1204
+ * 保存部署能力参数与模板变量;规则写入只走 module-rules 的版本事务。
1205
+ * parseDocument 保留注释与未知键(module.yml 模板含大量注释);空值键删除('' / [],
1118
1206
  * 回落模板/引擎默认;0 与 false 照常写入——语义与函数内注释、docs §3 一致)。
1119
1207
  */
1120
- declare function saveModuleParams(moduleRoot: string, templateName: string, params: Record<string, unknown> | undefined, promptConfigs: unknown[] | undefined, variables?: Record<string, string>, variablesEnabled?: boolean): void;
1208
+ declare function saveModuleParams(moduleRoot: string, templateName: string, params: Record<string, unknown> | undefined, promptConfigs: unknown[] | undefined, variables?: Record<string, string>, variablesEnabled?: boolean, expectedRevisions?: Partial<RuleRevisions>): void;
1121
1209
  /**
1122
1210
  * 保存激活模块的顶层 persona 段(官方 `@deepseek-ai/dsh-persona` 行 config 同构)。
1123
1211
  * null = 删除该段(回落宿主部署人设);默认值不落键(见 personaRowConfig)。
1124
1212
  */
1125
- declare function savePresetPersona(moduleRoot: string, templateName: string, persona: PersonaSpec | null): void;
1213
+ declare function saveModulePersona(moduleRoot: string, templateName: string, persona: PersonaSpec | null): void;
1214
+ /** 模块文件读-改-写(parseDocument 保留注释与未知键;mutate 内 setIn/deleteIn)。
1215
+ * 角色卡库(characters)与世界书工具(world-book-tools)共用此入口,避免
1216
+ * 各自实现 parseDocument 往返。写盘走原子替换,失败保留旧文件。 */
1217
+ declare function withModuleDefinition(moduleDir: string, mutate: (doc: ReturnType<typeof parseDocument>, source: Record<string, unknown>) => void): ReturnType<typeof withModuleDefinition$1>;
1218
+ /** 向 module.yml 的 modules 追加功能模块;空数组保持按需装配语义。 */
1219
+ declare function appendModuleCapabilities(doc: ReturnType<typeof parseDocument>, additions: readonly string[]): void;
1126
1220
  /** 删除具有合法身份的模块目录(模块根/<id>);隐藏备份不经公共接口删除。
1127
1221
  * 仅作用于插件自有模块根,包内置模板不受影响;路径越界与非法 id 拒绝。
1128
1222
  * 模块不在宿主预设注册表里,删除后无需撤销官方登记;调用方按需重建当前模块。 */
1129
- declare function removeUserPreset(id: string, moduleRoot?: string): {
1223
+ declare function removeUserModule(id: string, moduleRoot?: string): {
1130
1224
  ok: true;
1131
1225
  } | {
1132
1226
  ok: false;
1133
1227
  message: string;
1134
1228
  };
1135
1229
  /** 当前 layerSettings 与显式运行参数合并;不从旧磁盘 params 段回退取值。 */
1136
- declare function resolvePresetParams(spec: ModuleSpec, runtime: Record<string, unknown>): Record<string, unknown>;
1230
+ declare function resolveModuleParams(spec: ModuleSpec, runtime: Record<string, unknown>): Record<string, unknown>;
1137
1231
  /**
1138
1232
  * 参数桥:params 扁平键 → 引擎模块行 config 对象(取代旧 __TOKEN__ 文本渲染)。
1139
1233
  *
@@ -1159,29 +1253,29 @@ declare function applyModuleConfigs(raw: string, configs: Record<string, Record<
1159
1253
  * 显式模块及当前参数/策略所需的装配是可编辑插件能力;官方组合 row 仅保留为运行事实。
1160
1254
  */
1161
1255
  declare function resolveModuleFacts(spec: ModuleSpec, templateDir?: string, editable?: boolean): ModuleFacts;
1162
- type EngineCapabilityCreateRequest = {
1256
+ type ModuleCapabilityCreateRequest = {
1163
1257
  action: 'create';
1164
1258
  capabilityId: string;
1165
1259
  } | {
1166
1260
  action: 'create-recipe';
1167
1261
  recipeId: string;
1168
1262
  };
1169
- interface EngineCapabilityCreateResult {
1263
+ interface ModuleCapabilityCreateResult {
1170
1264
  changed: boolean;
1171
1265
  addedModules: string[];
1172
1266
  capabilityIds: string[];
1173
1267
  }
1174
- interface EngineCapabilityRemoveResult {
1268
+ interface ModuleCapabilityRemoveResult {
1175
1269
  changed: boolean;
1176
1270
  removedModules: string[];
1177
1271
  capabilityIds: string[];
1178
1272
  }
1179
1273
  /** 在内存候选文档中展开能力/recipe,校验成功后一次原子替换 module.yml。 */
1180
- declare function createEngineCapabilityInPreset(moduleDir: string, request: EngineCapabilityCreateRequest): EngineCapabilityCreateResult;
1274
+ declare function createModuleCapability(moduleDir: string, request: ModuleCapabilityCreateRequest): ModuleCapabilityCreateResult;
1181
1275
  /** 删除能力:模块声明、顶层数据段,以及该能力的**显式参数与行配置**一起移除。
1182
1276
  * 参数在 ⇒ 装配在(见 impliedModulesFromParams):留下参数会让移除立刻被隐含装配拉回来,
1183
1277
  * 所以"移除能力"必须是完整移除。未登记参数、其他能力的数据与未知字段一律不动。 */
1184
- declare function removeEngineCapabilityFromPreset(moduleDir: string, capabilityId: string): EngineCapabilityRemoveResult;
1278
+ declare function removeModuleCapability(moduleDir: string, capabilityId: string): ModuleCapabilityRemoveResult;
1185
1279
  /**
1186
1280
  * 模块组合渲染完整链路:模块装配 → 参数桥(moduleConfigs + params)行级合并。
1187
1281
  * 合并优先级:参数桥(params/UI 基础层) > moduleConfigs(模板/ST 行级直写) > 行默认。
@@ -1197,8 +1291,19 @@ declare function renderComposition(spec: ModuleSpec, runtime: Record<string, unk
1197
1291
  * meta.stDroppedMarkers——防止设置 dump 与位置占位污染 promptConfigs 与注入。 */
1198
1292
  /** 显式文本求值工具;导入本身仅 prepare,避免执行禁用卡的副作用。 */
1199
1293
  declare function processStText(text: string, cardName: string, variables: Record<string, string | number>): string;
1294
+ /** 合并后的最终 id 映射:来源索引 → 该来源 promptConfigs 下标 → 合并后的配置 id。 */
1295
+ type MergeIdMap = Map<number, Map<number, string>>;
1296
+ /**
1297
+ * 合并多个转换结果为一个预设,并返回「来源 + 生成配置下标 → 最终 id」的同一份映射。
1298
+ *
1299
+ * 报告必须消费这份映射,而不是按后缀规则另行推测:后缀分配只发生在这里一次。
1300
+ */
1301
+ declare function mergeStModulesWithReport(specs: ModuleSpec[]): {
1302
+ spec: ModuleSpec;
1303
+ idMap: MergeIdMap;
1304
+ };
1200
1305
  /** 合并多个转换结果为一个预设(角色卡 × 响应预设 → 单预设)。 */
1201
- declare function mergeStPresets(specs: ModuleSpec[]): ModuleSpec;
1306
+ declare function mergeStModules(specs: ModuleSpec[]): ModuleSpec;
1202
1307
  /** 转换选项:多 prompt_order 分组时显式选择来源角色,避免照搬「默认任取首组」。 */
1203
1308
  interface StConversionOptions {
1204
1309
  characterId?: string;
@@ -1209,12 +1314,20 @@ interface StOrderGroupSummary {
1209
1314
  entries: number;
1210
1315
  }
1211
1316
  /** SillyTavern JSON 预设卡片 → 本项目 ModuleSpec(导入端点直接消费)。 */
1212
- declare function convertStToPreset(card: unknown, baseName: string, options?: StConversionOptions): ModuleSpec;
1317
+ declare function convertStToModule(card: unknown, baseName: string, options?: StConversionOptions): ModuleSpec;
1318
+ /**
1319
+ * 同源转换 + 结构化报告:预览与实际提交共用这一个纯函数实现,
1320
+ * 报告只是派生元数据(不进 module.yml、不作写入凭证)。
1321
+ */
1322
+ declare function convertStToModuleWithReport(card: unknown, baseName: string, options?: StConversionOptions): {
1323
+ spec: ModuleSpec;
1324
+ report: StConversionReport;
1325
+ };
1213
1326
  /** ST 导入预设 id:必须是官方 agent-presets 可发现的目录名(PRESET_ID =
1214
1327
  * /^[a-z0-9][a-z0-9-]*$/——含中文的目录会被宿主 discovery 静默跳过,会话
1215
1328
  * resume 报 preset not found)。文件名 slug 化(去中文);纯中文名退化为
1216
1329
  * st-<文件名短哈希>(唯一且合法);显示名 name 仍保留中文原名。 */
1217
- declare function stPresetId(baseName: string): string;
1330
+ declare function stModuleId(baseName: string): string;
1218
1331
  //#endregion
1219
1332
  //#region src/host/import-source.d.ts
1220
1333
  type PreparedImport = {
@@ -1241,11 +1354,11 @@ type PreparedImport = {
1241
1354
  declare function prepareImport(input: AssetFile[], target: 'preset' | 'character', choices?: ImportChoices): PreparedImport;
1242
1355
  //#endregion
1243
1356
  //#region src/host/module-package.d.ts
1244
- declare function expandPresetSource(input: AssetFile[]): Promise<AssetFile[]>;
1357
+ declare function expandModuleSource(input: AssetFile[]): Promise<AssetFile[]>;
1245
1358
  type ReadyImport = Extract<ReturnType<typeof prepareImport>, {
1246
1359
  state: 'ready';
1247
1360
  }>;
1248
- declare function presetImportPreview(root: string, files: AssetFile[], request: AssetImportRequest): {
1361
+ declare function moduleImportPreview(root: string, files: AssetFile[], request: AssetImportRequest): {
1249
1362
  prepared: ReadyImport;
1250
1363
  summary: AssetSummary;
1251
1364
  sourceDigest: string;
@@ -1253,11 +1366,13 @@ declare function presetImportPreview(root: string, files: AssetFile[], request:
1253
1366
  } | Exclude<ReturnType<typeof prepareImport>, {
1254
1367
  state: 'ready';
1255
1368
  }>;
1256
- declare function installPresetPackage(root: string, files: AssetFile[], request: AssetImportRequest): Promise<{
1369
+ declare function installModulePackage(root: string, files: AssetFile[], request: AssetImportRequest, options?: {
1370
+ preserveAssets?: boolean;
1371
+ }): Promise<{
1257
1372
  id: string;
1258
1373
  backupPath?: string;
1259
1374
  }>;
1260
- declare function exportPresetPackage(root: string, request: PresetExportRequest): Promise<PresetExportResult>;
1375
+ declare function exportModulePackage(root: string, request: ModuleExportRequest): Promise<ModuleExportResult>;
1261
1376
  //#endregion
1262
1377
  //#region src/host/paths.d.ts
1263
1378
  /** 用户技能根:官方 `user-dsh` 技能根,也是本插件创建、复制导入与回收站的落点。
@@ -1272,4 +1387,4 @@ declare const USER_SKILLS_DIR: string;
1272
1387
  */
1273
1388
  declare const MODULES_DIR: string;
1274
1389
  //#endregion
1275
- export { AssetFile as $, resolveModuleFacts as A, MAX_BRIDGE_BODY_BYTES as B, loadModuleSpec as C, removeUserPreset as D, removePresetModule as E, BRIDGE_ENDPOINTS as F, SkillInvocation as G, SETTINGS_BRIDGE_PREFIX as H, BridgeEndpoint as I, SkillSourceKind as J, SkillPolicyChange as K, BridgeErrorPayload as L, saveModuleParams as M, savePresetPersona as N, renderComposition as O, userModulesDir as P, scopeOfInvocation as Q, BridgeRequestMap as R, listModules as S, removeEngineCapabilityFromPreset as T, SkillCatalogEntry as U, MAX_CHARACTER_CARD_STREAM_BYTES as V, SkillContentSnapshot as W, SkillsState as X, SkillsCatalogSnapshot as Y, invocationForScope as Z, buildModuleConfigsFromParams as _, installPresetPackage as a, MAX_INSTRUCTION_FILE_BYTES as at, ensurePresetSeed as b, convertStToPreset as c, EngineCapability as ct, stPresetId as d, engineCapability as dt, ImportChoices as et, EngineCapabilityCreateRequest as f, engineRecipe as ft, applyModuleConfigs as g, ModuleSpec as h, exportPresetPackage as i, InstructionFileStatus as it, resolvePresetParams as j, resolveModuleDir as k, mergeStPresets as l, ModuleFacts as lt, EngineCapabilityRemoveResult as m, validateCustomToolIdentities as mt, USER_SKILLS_DIR as n, InstructionContextView as nt, presetImportPreview as o, ENGINE_CAPABILITIES as ot, EngineCapabilityCreateResult as p, isEngineCapabilityPresent as pt, SkillPolicyScope as q, expandPresetSource as r, InstructionFileSnapshot as rt, StConversionOptions as s, ENGINE_RECIPES as st, MODULES_DIR as t, INSTRUCTION_FILE_STATUSES as tt, processStText as u, ModuleSourceMode as ut, cloneBuiltinPreset as v, moduleDirExists as w, listBuiltinTemplates as x, createEngineCapabilityInPreset as y, BridgeValueMap as z };
1390
+ export { SkillSourceKind as $, removeUserModule as A, BridgeEndpoint as B, ensureModuleSeed as C, moduleCapability as Ct, moduleDirExists as D, loadModuleSpec as E, saveModuleParams as F, MAX_CHARACTER_CARD_STREAM_BYTES as G, BridgeRequestMap as H, saveModulePersona as I, SkillCatalogEntry as J, ModuleSummary as K, userModulesDir as L, resolveModuleDir as M, resolveModuleFacts as N, removeModuleCapability as O, resolveModuleParams as P, SkillPolicyScope as Q, withModuleDefinition as R, createModuleCapability as S, isModuleCapabilityPresent as St, listModules as T, BridgeValueMap as U, BridgeErrorPayload as V, MAX_BRIDGE_BODY_BYTES as W, SkillInvocation as X, SkillContentSnapshot as Y, SkillPolicyChange as Z, ModuleSpec as _, MODULE_CAPABILITIES as _t, installModulePackage as a, ImportChoices as at, buildModuleConfigsFromParams as b, ModuleSourceMode as bt, convertStToModule as c, RuleDefinition as ct, mergeStModulesWithReport as d, InstructionFileSnapshot as dt, SkillsCatalogSnapshot as et, processStText as f, InstructionFileStatus as ft, ModuleCapabilityRemoveResult as g, InjectionPoint as gt, ModuleCapabilityCreateResult as h, INJECTION_POINT_ORDER as ht, exportModulePackage as i, AssetFile as it, renderComposition as j, removeModuleCapabilityDeclaration as k, convertStToModuleWithReport as l, INSTRUCTION_FILE_STATUSES as lt, ModuleCapabilityCreateRequest as m, ENGINE_RECIPES as mt, USER_SKILLS_DIR as n, invocationForScope as nt, moduleImportPreview as o, ModuleExportRequest as ot, stModuleId as p, MAX_INSTRUCTION_FILE_BYTES as pt, SETTINGS_BRIDGE_PREFIX as q, expandModuleSource as r, scopeOfInvocation as rt, StConversionOptions as s, ModuleExportResult as st, MODULES_DIR as t, SkillsState as tt, mergeStModules as u, InstructionContextView as ut, appendModuleCapabilities as v, ModuleCapability as vt, listBuiltinTemplates as w, validateCustomToolIdentities as wt, cloneBuiltinModule as x, engineRecipe as xt, applyModuleConfigs as y, ModuleFacts as yt, BRIDGE_ENDPOINTS as z };