dsh-plugin-prompt-tool 2.0.1 → 3.0.0
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/README.md +100 -233
- package/engine/actions/append-context.mjs +3 -24
- package/engine/actions/assembly.mjs +70 -94
- package/engine/actions/catalog.mjs +65 -28
- package/engine/actions/content.mjs +8 -152
- package/engine/actions/examples.mjs +8 -4
- package/engine/actions/inbox-prepend.mjs +5 -7
- package/engine/actions/index.mjs +17 -9
- package/engine/actions/inject-text.mjs +24 -4
- package/engine/actions/pre-step-filter.mjs +3 -4
- package/engine/actions/registration.mjs +20 -28
- package/engine/actions/request-params.mjs +21 -1
- package/engine/actions/shared.mjs +23 -15
- package/engine/actions/stream-output.mjs +26 -0
- package/engine/actions/tool-gate.mjs +31 -0
- package/engine/actions/tool-result.mjs +36 -0
- package/engine/actions/tool-visibility.mjs +248 -0
- package/engine/agent-capability.mjs +67 -0
- package/engine/anchor-match.mjs +14 -21
- package/engine/audience.d.mts +2 -0
- package/engine/audience.mjs +102 -0
- package/engine/branch.d.mts +4 -0
- package/engine/branch.mjs +62 -19
- package/engine/compaction-epoch.d.mts +25 -0
- package/engine/compaction-epoch.mjs +27 -4
- package/engine/compositions/source/local/filesystem-editor.yml +3 -3
- package/engine/compositions/source/local/instruction-hint.yml +4 -7
- package/engine/compositions/source/local/module-file-tools.yml +2 -0
- package/engine/compositions/source/local/module-import-tools.yml +4 -0
- package/engine/compositions/source/local/module-manifest-tools.yml +2 -0
- package/engine/compositions/source/local/module-rule-tools.yml +5 -0
- package/engine/compositions/source/local/module-variable-tools.yml +5 -0
- package/engine/compositions/source/local/present-as.yml +26 -0
- package/engine/compositions/source/local/tool-config-engine.yml +2 -3
- package/engine/compositions/source/local/tool-search.yml +11 -0
- package/engine/condition-facts.mjs +84 -0
- package/engine/conditions/anchor.mjs +63 -23
- package/engine/conditions/availability.mjs +1 -1
- package/engine/conditions/composite.mjs +4 -4
- package/engine/conditions/count.mjs +43 -13
- package/engine/conditions/evaluation.mjs +74 -19
- package/engine/conditions/examples.mjs +2 -1
- package/engine/conditions/index.d.mts +15 -0
- package/engine/conditions/index.mjs +23 -9
- package/engine/conditions/operators.mjs +4 -0
- package/engine/conditions/phase.mjs +10 -5
- package/engine/conditions/preset.mjs +1 -1
- package/engine/conditions/session.mjs +8 -2
- package/engine/conditions/subject.mjs +144 -65
- package/engine/conditions/text.mjs +26 -8
- package/engine/conditions/variable.mjs +83 -0
- package/engine/context-activation.d.mts +11 -0
- package/engine/{st-world-book.mjs → context-activation.mjs} +104 -64
- package/engine/delivery.d.mts +2 -0
- package/engine/delivery.mjs +93 -0
- package/engine/discovery.d.mts +38 -0
- package/engine/discovery.mjs +146 -0
- package/engine/env-safety.mjs +14 -0
- package/engine/executor.d.mts +28 -0
- package/engine/executor.mjs +290 -205
- package/engine/fillers.mjs +39 -8
- package/engine/fixed-registration.mjs +12 -0
- package/engine/history.mjs +71 -0
- package/engine/instruction-blocks.d.mts +13 -0
- package/engine/instruction-blocks.mjs +21 -0
- package/engine/instruction-files.d.mts +5 -0
- package/engine/instruction-files.mjs +97 -0
- package/engine/instruction-hint.mjs +69 -103
- package/engine/interpolate.d.mts +7 -0
- package/engine/interpolate.mjs +44 -13
- package/engine/layers.mjs +165 -230
- package/engine/machine-paths.mjs +40 -0
- package/engine/module-file-tools.mjs +8 -0
- package/engine/module-import-tools.mjs +10 -0
- package/engine/module-manifest-tools.mjs +8 -0
- package/engine/module-rule-tools.mjs +10 -0
- package/engine/module-variable-tools.mjs +10 -0
- package/engine/order.d.mts +14 -0
- package/engine/order.mjs +0 -3
- package/engine/path-safety.d.mts +2 -0
- package/engine/path-safety.mjs +58 -0
- package/engine/pre-step-source.d.mts +69 -0
- package/engine/pre-step-source.mjs +103 -0
- package/engine/present-as.mjs +77 -0
- package/engine/promotion-pool.d.mts +9 -0
- package/engine/promotion-pool.mjs +69 -0
- package/engine/record.mjs +2 -0
- package/engine/rule-engine.mjs +3 -2
- package/engine/rule-facts.d.mts +11 -0
- package/engine/rule-facts.mjs +60 -0
- package/engine/rule-runtime.d.mts +46 -0
- package/engine/rule-runtime.mjs +98 -13
- package/engine/rule-spec.d.mts +106 -0
- package/engine/rule-spec.mjs +302 -28
- package/engine/run-code-env.mjs +73 -19
- package/engine/schema.mjs +165 -243
- package/engine/sdk-strip.mjs +2 -2
- package/engine/service-names.d.mts +10 -0
- package/engine/service-names.mjs +10 -0
- package/engine/shared.d.mts +21 -0
- package/engine/shared.mjs +47 -26
- package/engine/skill-search.mjs +125 -53
- package/engine/source-kind.d.mts +9 -0
- package/engine/source-kind.mjs +16 -0
- package/engine/strategy-ids.mjs +5 -0
- package/engine/template-evaluation.d.mts +16 -0
- package/engine/template-evaluation.mjs +178 -0
- package/engine/template-frame.d.mts +16 -0
- package/engine/template-frame.mjs +69 -0
- package/engine/tool-config-engine.mjs +39 -35
- package/engine/tool-definition.d.mts +4 -0
- package/engine/tool-definition.mjs +5 -1
- package/engine/tool-git-bash.mjs +5 -1
- package/engine/tool-scope.mjs +22 -0
- package/engine/{dev-tool-search.mjs → tool-search.mjs} +63 -65
- package/engine/trigger.mjs +15 -270
- package/engine/vendor/yaml/dist/compose/resolve-flow-scalar.js +19 -18
- package/engine/vendor/yaml/dist/nodes/Alias.js +25 -23
- package/engine/vendor/yaml/package.json +1 -1
- package/lib/client.js +8312 -6724
- package/lib/client.js.map +1 -1
- package/lib/index.d.mts +37 -762
- package/lib/index.mjs +26919 -5791
- package/modules/ponytail/module.yml +83 -203
- package/modules/ptc-mode/module.yml +45 -0
- package/modules/soul/assets/core-hard.md +6 -0
- package/modules/soul/assets/criteria.md +12 -0
- package/modules/soul/assets/echo.md +12 -0
- package/modules/soul/assets/layers.md +11 -0
- package/modules/soul/assets/ledger.md +9 -0
- package/modules/soul/assets/manifest.yml +20 -0
- package/modules/soul/assets/reference/00-layers.md +27 -0
- package/modules/soul/assets/reference/01-criteria.md +32 -0
- package/modules/soul/assets/reference/02-echo.md +158 -0
- package/modules/soul/assets/reference/03-vital.md +183 -0
- package/modules/soul/assets/reference/04-manifest.json +106 -0
- package/modules/soul/assets/reference/05-doctor.md +67 -0
- package/modules/soul/assets/reference/06-reference.md +189 -0
- package/modules/soul/assets/reference/07-bundle.json +431 -0
- package/modules/soul/assets/reference/08-/350/270/251/345/235/221/345/256/236/345/275/225.md +59 -0
- package/modules/soul/assets/reference/09-dev-workflow.md +109 -0
- package/modules/soul/assets/reference/10-echo-anatomy.md +100 -0
- package/modules/soul/assets/reference/11-self.md +80 -0
- package/modules/soul/assets/reference/12-ledger.md +159 -0
- package/modules/soul/assets/reference/README.md +10 -0
- package/modules/soul/assets/templates/agents-template.md +6 -0
- package/modules/soul/assets/vital.md +9 -0
- package/modules/soul/module.yml +311 -0
- package/modules/superpowers/module.yml +122 -0
- package/modules/tool-surface/module.yml +51 -47
- package/package.json +40 -41
- package/skills/dsh-module/SKILL.md +119 -0
- package/skills/dsh-module/reference.md +185 -0
- package/templates/10-pre-step.yml +2 -3
- package/templates/14-first-turn-anchor.yml +10 -14
- package/templates/15-guide-auto.yml +32 -28
- package/templates/16-custom-fallback.yml +33 -21
- package/templates/20-system-section.yml +1 -4
- package/templates/50-llm-stream.yml +4 -10
- package/templates/60-tool-pipeline.yml +12 -10
- package/templates/63-append-context.yml +20 -0
- package/templates/64-pre-step-filter.yml +23 -0
- package/templates/65-turn-stop.yml +2 -2
- package/templates/67-inbox-prepend.yml +22 -0
- package/templates/70-subagent-maintenance.yml +9 -10
- package/templates/75-subagent-end.yml +2 -2
- package/templates/80-tool-surface.yml +41 -57
- package/templates/tools/40-delegate-module-import.yml +22 -0
- package/templates/tools/50-delegate-module-rules.yml +14 -0
- package/templates/tools/60-delegate-module-variables.yml +17 -0
- package/templates/tools/70-delegate-module-rules-edit.yml +31 -0
- package/engine/actions/decision.mjs +0 -54
- package/engine/actions/guard.mjs +0 -80
- package/engine/actions/sdk-strip.mjs +0 -30
- package/engine/character-tools.mjs +0 -8
- package/engine/classify-task.mjs +0 -53
- package/engine/compositions/library/agent-instructions.yml +0 -9
- package/engine/compositions/library/command-goal.yml +0 -7
- package/engine/compositions/library/compaction.yml +0 -22
- package/engine/compositions/library/delegation-ptc.yml +0 -58
- package/engine/compositions/library/delegation.yml +0 -56
- package/engine/compositions/library/persistent-shell.yml +0 -50
- package/engine/compositions/library/planning.yml +0 -26
- package/engine/compositions/library/skill-filesystem-cordis.yml +0 -10
- package/engine/compositions/library/skill-filesystem.yml +0 -7
- package/engine/compositions/library/tool-ask-user.yml +0 -7
- package/engine/compositions/library/tool-bash.yml +0 -8
- package/engine/compositions/library/tool-cordis.yml +0 -7
- package/engine/compositions/library/tool-fs-search.yml +0 -9
- package/engine/compositions/library/tool-fs.yml +0 -7
- package/engine/compositions/library/tool-goal.yml +0 -7
- package/engine/compositions/library/tool-jobs.yml +0 -7
- package/engine/compositions/library/tool-plugin-manager-disabled.yml +0 -8
- package/engine/compositions/library/tool-plugin-manager.yml +0 -8
- package/engine/compositions/library/tool-present.yml +0 -7
- package/engine/compositions/library/tool-presentation.yml +0 -9
- package/engine/compositions/library/tool-pwsh.yml +0 -8
- package/engine/compositions/library/tool-skill.yml +0 -7
- package/engine/compositions/library/tool-todo.yml +0 -9
- package/engine/compositions/library/tool-web.yml +0 -10
- package/engine/compositions/source/local/character-tools.yml +0 -5
- package/engine/compositions/source/local/declared-triggers.yml +0 -12
- package/engine/compositions/source/local/dev-tool-search.yml +0 -11
- package/engine/compositions/source/local/session-var-tools.yml +0 -5
- package/engine/compositions/source/local/subagent-tool-policy.yml +0 -21
- package/engine/compositions/source/local/world-book-tools.yml +0 -5
- package/engine/condition.mjs +0 -96
- package/engine/declared-triggers.mjs +0 -93
- package/engine/session-var-tools.mjs +0 -8
- package/engine/session-vars.mjs +0 -54
- package/engine/st-macros.d.mts +0 -22
- package/engine/st-macros.mjs +0 -208
- package/engine/st-render.mjs +0 -109
- package/engine/st-world-book.d.mts +0 -10
- package/engine/subagent-tool-policy-core.mjs +0 -400
- package/engine/subagent-tool-policy.mjs +0 -352
- package/engine/trigger-spec.mjs +0 -173
- package/engine/world-book-tools.mjs +0 -8
- package/lib/migrate-rules.d.mts +0 -1
- package/lib/migrate-rules.mjs +0 -39
- package/lib/module-package-CHPFweqK.mjs +0 -2
- package/lib/module-package-Cnd1_mwx.mjs +0 -2872
- package/lib/paths-CyP0IkaM.d.mts +0 -1390
- package/lib/preset-transfer.d.mts +0 -2
- package/lib/preset-transfer.mjs +0 -3
- package/lib/rules-migration-DJ6vASB5.mjs +0 -15334
- package/templates/policies/legacy-defaults.yml +0 -34
- package/templates/tools/40-delegate-character.yml +0 -15
- package/templates/tools/50-delegate-worldbook.yml +0 -15
- package/templates/tools/60-delegate-session-var.yml +0 -15
- package/templates/tools/70-delegate-worldbook-upsert.yml +0 -36
package/engine/interpolate.mjs
CHANGED
|
@@ -13,12 +13,14 @@
|
|
|
13
13
|
* - 键字符集:字母数字、下划线、点、中文、连字符(与 ST setvar/getvar 一致)。
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
import {
|
|
16
|
+
import { currentEvents } from './history.mjs'
|
|
17
|
+
import { machinePaths } from './machine-paths.mjs'
|
|
17
18
|
import { createHash } from 'node:crypto'
|
|
18
19
|
|
|
19
20
|
/** 会话事件中最后一条指定类型消息的文本(事件倒序扫描;无则空串)。 */
|
|
20
21
|
function lastMessageOf(session, type) {
|
|
21
|
-
|
|
22
|
+
// 这两个宏是官方按**模型可见消息**求值的运行时事实,压缩遮蔽掉的旧正文不再是「最后一条」。
|
|
23
|
+
const events = currentEvents(session)
|
|
22
24
|
for (let index = events.length - 1; index >= 0; index--) {
|
|
23
25
|
const event = events[index]
|
|
24
26
|
if (event?.type !== type) continue
|
|
@@ -95,29 +97,45 @@ const DYNAMIC_MACROS = {
|
|
|
95
97
|
pipe: () => '|',
|
|
96
98
|
}
|
|
97
99
|
|
|
98
|
-
/**
|
|
100
|
+
/** 内置变量:路径类事实取机器路径事实的唯一来源(无会话上下文时回退进程 cwd);两条插值通道同源。 */
|
|
99
101
|
function builtinVariables(session) {
|
|
100
|
-
return
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
102
|
+
return machinePaths(session)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** 内置变量名的单一来源:从 builtinVariables 的键派生(惰性,不在 import 期取 cwd)。 */
|
|
106
|
+
let builtinNames
|
|
107
|
+
function builtinNameSet() {
|
|
108
|
+
return (builtinNames ??= new Set(Object.keys(builtinVariables())))
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* 保留名判定(保留名的唯一判据,写入与读取共用):内建名大小写敏感(`dsh_home`
|
|
113
|
+
* 不是内建),动态宏名大小写不敏感(`TIME` 即 `time`)。会话变量不得占用这些名字,
|
|
114
|
+
* 否则字面值会遮蔽内建事实与动态宏。
|
|
115
|
+
*/
|
|
116
|
+
export function isReservedInterpolationName(key) {
|
|
117
|
+
const name = String(key ?? '')
|
|
118
|
+
return builtinNameSet().has(name) || Object.hasOwn(DYNAMIC_MACROS, name.toLowerCase())
|
|
105
119
|
}
|
|
106
120
|
|
|
107
121
|
/** 模板变量插值:配置 variables 优先,ST 运行时宏次之,内置 {{DSH_HOME}} / {{WORKSPACE}} / {{CWD}} 兜底。 */
|
|
108
122
|
export function interpolateVariables(text, variables, session, keep, sourceId = '') {
|
|
109
123
|
const builtins = builtinVariables(session)
|
|
110
124
|
const active = new Set()
|
|
125
|
+
// pick 只为「同会话、同模板、同一次出现」稳定:整段正文 input 不进 seed,
|
|
126
|
+
// 否则无关正文长度一变取值就漂移;出现序号让同一正文里的多处 pick 各自取值。
|
|
127
|
+
// sourceId 必须只依赖标识(模板名、条目 id/键位):省略时所有调用位置共用同一个 seed。
|
|
128
|
+
let pickCount = 0
|
|
111
129
|
// 限制展开增加的字符数、递归深度与工作量;原始正文不截断,失败引用留给出口清洗。
|
|
112
130
|
let remainingChars = 1024 * 1024
|
|
113
131
|
let remainingExpansions = 4096
|
|
114
132
|
function render(input, depth = 0) {
|
|
115
|
-
return normalizeMacroSyntax(input).replace(REFERENCE_RE, (whole, key, arg
|
|
133
|
+
return normalizeMacroSyntax(input).replace(REFERENCE_RE, (whole, key, arg) => {
|
|
116
134
|
if (arg === undefined && keep?.has(key)) return `{{${key}}}`
|
|
117
135
|
if (active.has(key)) return whole
|
|
118
136
|
let value
|
|
119
137
|
if (Object.hasOwn(variables, key)) value = String(variables[key] ?? '')
|
|
120
|
-
else if (key.toLowerCase() === 'pick') value = pickRandom(arg, JSON.stringify([session?.id ?? '', sourceId,
|
|
138
|
+
else if (key.toLowerCase() === 'pick') value = pickRandom(arg, JSON.stringify([session?.id ?? '', sourceId, pickCount++]))
|
|
121
139
|
else if (Object.hasOwn(DYNAMIC_MACROS, key.toLowerCase())) value = DYNAMIC_MACROS[key.toLowerCase()](arg, session)
|
|
122
140
|
else if (Object.hasOwn(builtins, key)) value = builtins[key]
|
|
123
141
|
else return whole
|
|
@@ -142,9 +160,11 @@ export function interpolateVariables(text, variables, session, keep, sourceId =
|
|
|
142
160
|
* 静态层插值:配置 variables 优先,ST 运行时宏取空串,内置路径变量按无会话语义解析。
|
|
143
161
|
* @param keep 需要交给官方变量通道按 assembly 求值的名字(运行时事实与已注册变量)——
|
|
144
162
|
* 命中即原样保留引用,不做静态替换。
|
|
163
|
+
* @param sourceId 调用点的稳定身份(模板名等只依赖标识的串),只影响 {{pick}} 的 seed;
|
|
164
|
+
* 缺省时与传 `''` 等价(所有位置共用 seed)。
|
|
145
165
|
*/
|
|
146
|
-
export function interpolateStatic(text, variables, keep) {
|
|
147
|
-
return interpolateVariables(text, variables, undefined, keep)
|
|
166
|
+
export function interpolateStatic(text, variables, keep, sourceId) {
|
|
167
|
+
return interpolateVariables(text, variables, undefined, keep, sourceId)
|
|
148
168
|
}
|
|
149
169
|
|
|
150
170
|
/**
|
|
@@ -188,7 +208,6 @@ const MACRO_SINGLE_COLON_RE = new RegExp(`\\{\\{\\s*(${MACRO_ALIASES})\\s*:(?!:)
|
|
|
188
208
|
|
|
189
209
|
/**
|
|
190
210
|
* ST 宏写法归一:{{roll 1d6}} / {{roll:1d6}} → {{roll::1d6}}。
|
|
191
|
-
* 与 `src/host/sillytavern.ts` 的导入期归一同源(两处物理隔离,改动需同步)。
|
|
192
211
|
*/
|
|
193
212
|
export function normalizeMacroSyntax(text) {
|
|
194
213
|
return text
|
|
@@ -196,6 +215,18 @@ export function normalizeMacroSyntax(text) {
|
|
|
196
215
|
.replace(MACRO_SINGLE_COLON_RE, (_whole, macro, arg) => `{{${String(macro).toLowerCase()}::${arg}}}`)
|
|
197
216
|
}
|
|
198
217
|
|
|
218
|
+
/**
|
|
219
|
+
* 按已声明键集合剥离引用(`variablesEnabled=false` 的编译期清洗):命中声明键的
|
|
220
|
+
* `{{键}}` / `{{ 键 }}` / `{{键::参数}}` 整段移除,未声明键与内置引用原样保留。
|
|
221
|
+
* 纯函数(内部用 `replace` 调用 `REFERENCE_RE`):不导出带 `/g` 的正则,否则
|
|
222
|
+
* 调用方的 `lastIndex` 会互相污染。
|
|
223
|
+
*/
|
|
224
|
+
export function stripDeclaredRefs(text, keys) {
|
|
225
|
+
return typeof text === 'string'
|
|
226
|
+
? text.replace(REFERENCE_RE, (whole, key) => keys.has(key) ? '' : whole)
|
|
227
|
+
: text
|
|
228
|
+
}
|
|
229
|
+
|
|
199
230
|
/**
|
|
200
231
|
* 官方插值通道(system-section / runtime-context)专用清洗。
|
|
201
232
|
*
|