dsh-tiddlywiki 0.30.64 → 0.31.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/docs/CHANGELOG.md +3 -1
- package/docs/features.md +4 -2
- package/lib/client.js +8 -11
- package/lib/index.js +813 -215
- package/lib/index.js.map +1 -1
- package/package.json +4 -3
- package/src/client/index.ts +20 -20
- package/src/client/quick-note-dock.ts +8 -28
- package/src/client/rightbar-tab.ts +31 -0
- package/src/client/styles-css.ts +6 -9
- package/src/client/wiki-scope-dock.ts +34 -92
- package/src/host/command-note.ts +131 -0
- package/src/host/prompt.ts +59 -3
- package/src/host/skill-install.ts +77 -0
- package/src/host/tool-output-schemas.ts +235 -0
- package/src/host/tools-attach.ts +2 -0
- package/src/host/tools-git.ts +3 -0
- package/src/host/tools-notes-lifecycle.ts +3 -0
- package/src/host/tools-notes-structure.ts +4 -0
- package/src/host/tools-notes-write.ts +61 -5
- package/src/host/tools-read.ts +45 -2
- package/src/host/tools-support.ts +5 -0
- package/src/index-startup.ts +30 -11
- package/src/index.ts +33 -0
- package/src/sdk.ts +17 -7
- package/src/client/scope-seat.ts +0 -114
package/lib/index.js
CHANGED
|
@@ -1382,7 +1382,12 @@ function defineTool(options) {
|
|
|
1382
1382
|
description: options.description,
|
|
1383
1383
|
parameters,
|
|
1384
1384
|
output: {
|
|
1385
|
-
|
|
1385
|
+
/**
|
|
1386
|
+
* The registry DOES read this (v0.30.66): DSH validates the returned value
|
|
1387
|
+
* against it on every call. Unset → `{}` = no constraint, i.e. the old
|
|
1388
|
+
* behaviour. Tools that declare a schema get an exit check for free.
|
|
1389
|
+
*/
|
|
1390
|
+
schema: options.output.schema !== void 0 ? compileValue(options.output.schema) : {},
|
|
1386
1391
|
render(args, value) {
|
|
1387
1392
|
return options.output.render(args, value);
|
|
1388
1393
|
}
|
|
@@ -3000,6 +3005,243 @@ function requireWiki(deps, sessionId) {
|
|
|
3000
3005
|
return scope.client;
|
|
3001
3006
|
}
|
|
3002
3007
|
//#endregion
|
|
3008
|
+
//#region src/host/tool-output-schemas.ts
|
|
3009
|
+
const STRINGS = {
|
|
3010
|
+
type: "array",
|
|
3011
|
+
items: { type: "string" }
|
|
3012
|
+
};
|
|
3013
|
+
/** 一条检索/最近命中。`modified` 可空 → 不声明。 */
|
|
3014
|
+
const HIT = {
|
|
3015
|
+
type: "object",
|
|
3016
|
+
additionalProperties: true,
|
|
3017
|
+
properties: {
|
|
3018
|
+
title: { type: "string" },
|
|
3019
|
+
tags: STRINGS,
|
|
3020
|
+
snippet: { type: "string" }
|
|
3021
|
+
}
|
|
3022
|
+
};
|
|
3023
|
+
const SEARCH_RESULT = {
|
|
3024
|
+
type: "object",
|
|
3025
|
+
additionalProperties: true,
|
|
3026
|
+
properties: {
|
|
3027
|
+
query: { type: "string" },
|
|
3028
|
+
total: { type: "number" },
|
|
3029
|
+
scope: {
|
|
3030
|
+
type: "string",
|
|
3031
|
+
enum: ["workspace", "all"]
|
|
3032
|
+
},
|
|
3033
|
+
fellBack: { type: "boolean" },
|
|
3034
|
+
results: {
|
|
3035
|
+
type: "array",
|
|
3036
|
+
items: HIT
|
|
3037
|
+
},
|
|
3038
|
+
tags: STRINGS
|
|
3039
|
+
}
|
|
3040
|
+
};
|
|
3041
|
+
const RECENT_RESULT = {
|
|
3042
|
+
type: "object",
|
|
3043
|
+
additionalProperties: true,
|
|
3044
|
+
properties: { results: {
|
|
3045
|
+
type: "array",
|
|
3046
|
+
items: HIT
|
|
3047
|
+
} }
|
|
3048
|
+
};
|
|
3049
|
+
const TAG_LIST_RESULT = {
|
|
3050
|
+
type: "object",
|
|
3051
|
+
additionalProperties: true,
|
|
3052
|
+
properties: {
|
|
3053
|
+
count: { type: "number" },
|
|
3054
|
+
total: { type: "number" },
|
|
3055
|
+
truncated: { type: "boolean" },
|
|
3056
|
+
tags: {
|
|
3057
|
+
type: "array",
|
|
3058
|
+
items: {
|
|
3059
|
+
type: "object",
|
|
3060
|
+
additionalProperties: true,
|
|
3061
|
+
properties: {
|
|
3062
|
+
tag: { type: "string" },
|
|
3063
|
+
count: { type: "number" }
|
|
3064
|
+
}
|
|
3065
|
+
}
|
|
3066
|
+
}
|
|
3067
|
+
}
|
|
3068
|
+
};
|
|
3069
|
+
const GET_RESULT = {
|
|
3070
|
+
type: "object",
|
|
3071
|
+
additionalProperties: true,
|
|
3072
|
+
properties: {
|
|
3073
|
+
notFound: { type: "boolean" },
|
|
3074
|
+
title: { type: "string" },
|
|
3075
|
+
text: { type: "string" },
|
|
3076
|
+
textTotalChars: { type: "number" },
|
|
3077
|
+
offset: { type: "number" },
|
|
3078
|
+
tags: STRINGS,
|
|
3079
|
+
fields: {
|
|
3080
|
+
type: "object",
|
|
3081
|
+
additionalProperties: true
|
|
3082
|
+
}
|
|
3083
|
+
}
|
|
3084
|
+
};
|
|
3085
|
+
const PUT_RESULT = {
|
|
3086
|
+
type: "object",
|
|
3087
|
+
additionalProperties: true,
|
|
3088
|
+
properties: {
|
|
3089
|
+
ok: { type: "boolean" },
|
|
3090
|
+
title: { type: "string" },
|
|
3091
|
+
tags: STRINGS
|
|
3092
|
+
}
|
|
3093
|
+
};
|
|
3094
|
+
const BATCH_RESULT = {
|
|
3095
|
+
type: "object",
|
|
3096
|
+
additionalProperties: true,
|
|
3097
|
+
properties: {
|
|
3098
|
+
ok: { type: "boolean" },
|
|
3099
|
+
written: { type: "number" },
|
|
3100
|
+
skipped: { type: "number" },
|
|
3101
|
+
failed: { type: "number" },
|
|
3102
|
+
items: {
|
|
3103
|
+
type: "array",
|
|
3104
|
+
items: {
|
|
3105
|
+
type: "object",
|
|
3106
|
+
additionalProperties: true,
|
|
3107
|
+
properties: {
|
|
3108
|
+
title: { type: "string" },
|
|
3109
|
+
written: { type: "boolean" },
|
|
3110
|
+
skipped: { type: "boolean" },
|
|
3111
|
+
failed: { type: "boolean" }
|
|
3112
|
+
}
|
|
3113
|
+
}
|
|
3114
|
+
}
|
|
3115
|
+
}
|
|
3116
|
+
};
|
|
3117
|
+
const APPEND_RESULT = {
|
|
3118
|
+
type: "object",
|
|
3119
|
+
additionalProperties: true,
|
|
3120
|
+
properties: {
|
|
3121
|
+
ok: { type: "boolean" },
|
|
3122
|
+
title: { type: "string" },
|
|
3123
|
+
mode: {
|
|
3124
|
+
type: "string",
|
|
3125
|
+
enum: ["append", "prepend"]
|
|
3126
|
+
},
|
|
3127
|
+
created: { type: "boolean" },
|
|
3128
|
+
added: { type: "number" },
|
|
3129
|
+
total: { type: "number" }
|
|
3130
|
+
}
|
|
3131
|
+
};
|
|
3132
|
+
const REPLACE_RESULT = {
|
|
3133
|
+
type: "object",
|
|
3134
|
+
additionalProperties: true,
|
|
3135
|
+
properties: {
|
|
3136
|
+
ok: { type: "boolean" },
|
|
3137
|
+
title: { type: "string" },
|
|
3138
|
+
replaced: { type: "number" },
|
|
3139
|
+
found: { type: "boolean" },
|
|
3140
|
+
total: { type: "number" }
|
|
3141
|
+
}
|
|
3142
|
+
};
|
|
3143
|
+
const RENAME_RESULT = {
|
|
3144
|
+
type: "object",
|
|
3145
|
+
additionalProperties: true,
|
|
3146
|
+
properties: {
|
|
3147
|
+
ok: { type: "boolean" },
|
|
3148
|
+
from: { type: "string" },
|
|
3149
|
+
to: { type: "string" },
|
|
3150
|
+
refsUpdated: { type: "number" },
|
|
3151
|
+
refsTiddlers: { type: "number" }
|
|
3152
|
+
}
|
|
3153
|
+
};
|
|
3154
|
+
const DELETE_RESULT = {
|
|
3155
|
+
type: "object",
|
|
3156
|
+
additionalProperties: true,
|
|
3157
|
+
properties: {
|
|
3158
|
+
ok: { type: "boolean" },
|
|
3159
|
+
title: { type: "string" }
|
|
3160
|
+
}
|
|
3161
|
+
};
|
|
3162
|
+
const TRASH_RESULT = {
|
|
3163
|
+
type: "object",
|
|
3164
|
+
additionalProperties: true,
|
|
3165
|
+
properties: {
|
|
3166
|
+
action: { type: "string" },
|
|
3167
|
+
message: { type: "string" }
|
|
3168
|
+
}
|
|
3169
|
+
};
|
|
3170
|
+
const BACKLINK_RESULT = {
|
|
3171
|
+
type: "object",
|
|
3172
|
+
additionalProperties: true,
|
|
3173
|
+
properties: {
|
|
3174
|
+
title: { type: "string" },
|
|
3175
|
+
total: { type: "number" },
|
|
3176
|
+
linkCount: { type: "number" },
|
|
3177
|
+
tagCount: { type: "number" },
|
|
3178
|
+
items: {
|
|
3179
|
+
type: "array",
|
|
3180
|
+
items: {
|
|
3181
|
+
type: "object",
|
|
3182
|
+
additionalProperties: true,
|
|
3183
|
+
properties: {
|
|
3184
|
+
title: { type: "string" },
|
|
3185
|
+
refs: { type: "number" },
|
|
3186
|
+
via: {
|
|
3187
|
+
type: "string",
|
|
3188
|
+
enum: ["link", "tag"]
|
|
3189
|
+
}
|
|
3190
|
+
}
|
|
3191
|
+
}
|
|
3192
|
+
}
|
|
3193
|
+
}
|
|
3194
|
+
};
|
|
3195
|
+
const ATTACH_RESULT = {
|
|
3196
|
+
type: "object",
|
|
3197
|
+
additionalProperties: true,
|
|
3198
|
+
properties: {
|
|
3199
|
+
ok: { type: "boolean" },
|
|
3200
|
+
title: { type: "string" },
|
|
3201
|
+
mime: { type: "string" },
|
|
3202
|
+
bytes: { type: "number" },
|
|
3203
|
+
chars: { type: "number" },
|
|
3204
|
+
encoding: {
|
|
3205
|
+
type: "string",
|
|
3206
|
+
enum: ["text", "base64"]
|
|
3207
|
+
}
|
|
3208
|
+
}
|
|
3209
|
+
};
|
|
3210
|
+
const LINT_RESULT = {
|
|
3211
|
+
type: "object",
|
|
3212
|
+
additionalProperties: true,
|
|
3213
|
+
properties: {
|
|
3214
|
+
scanned: { type: "number" },
|
|
3215
|
+
checks: STRINGS,
|
|
3216
|
+
unknownChecks: STRINGS,
|
|
3217
|
+
issues: {
|
|
3218
|
+
type: "array",
|
|
3219
|
+
items: {
|
|
3220
|
+
type: "object",
|
|
3221
|
+
additionalProperties: true,
|
|
3222
|
+
properties: {
|
|
3223
|
+
kind: { type: "string" },
|
|
3224
|
+
count: { type: "number" },
|
|
3225
|
+
hint: { type: "string" },
|
|
3226
|
+
samples: STRINGS
|
|
3227
|
+
}
|
|
3228
|
+
}
|
|
3229
|
+
}
|
|
3230
|
+
}
|
|
3231
|
+
};
|
|
3232
|
+
/**
|
|
3233
|
+
* git 工具:只有 `ok` + `message` 在**每一条**返回路径上(成功、无远端、冲突、
|
|
3234
|
+
* 异常)都存在,其余字段都是按情况出现(`push`/`changed`/`restartFailed`…)。
|
|
3235
|
+
*/
|
|
3236
|
+
const GIT_RESULT = {
|
|
3237
|
+
type: "object",
|
|
3238
|
+
additionalProperties: true,
|
|
3239
|
+
properties: {
|
|
3240
|
+
ok: { type: "boolean" },
|
|
3241
|
+
message: { type: "string" }
|
|
3242
|
+
}
|
|
3243
|
+
};
|
|
3244
|
+
//#endregion
|
|
3003
3245
|
//#region src/host/text-util.ts
|
|
3004
3246
|
/**
|
|
3005
3247
|
* Small text/date helpers shared by the host modules (v0.20.0, extended v0.22.8).
|
|
@@ -3042,6 +3284,17 @@ function formatLocalMinute(value) {
|
|
|
3042
3284
|
*
|
|
3043
3285
|
* @module dsh-tiddlywiki/host/tools-read
|
|
3044
3286
|
*/
|
|
3287
|
+
/**
|
|
3288
|
+
* 单条工具回执的文本预算(v0.30.66)。
|
|
3289
|
+
*
|
|
3290
|
+
* 与 `tiddlywiki_get` 的分页同一个理由:DSH 宿主对单条工具结果有 `spill-policy`
|
|
3291
|
+
* (`maxInlineTokens: 12500`,超了换成首尾预览 + 落盘)与
|
|
3292
|
+
* `compaction-tool-result-pruner`(8192 字符,压缩压力下剪掉中间)两道闸。
|
|
3293
|
+
* 列表类工具(search / lint)的条数上限管不住**字节数**(200 条命中照样能到
|
|
3294
|
+
* 40KB),所以这里再加一道按字符的预算,并且**自己**把"省略了多少条"说清楚 ——
|
|
3295
|
+
* 比让宿主拦腰剪断可读得多。
|
|
3296
|
+
*/
|
|
3297
|
+
const RENDER_TEXT_BUDGET_CHARS = 12e3;
|
|
3045
3298
|
function searchTool(env) {
|
|
3046
3299
|
const { deps, requireWiki } = env;
|
|
3047
3300
|
return defineTool({
|
|
@@ -3082,29 +3335,41 @@ function searchTool(env) {
|
|
|
3082
3335
|
description: "可选:返回条数上限(默认 30,最大 200)"
|
|
3083
3336
|
}
|
|
3084
3337
|
},
|
|
3085
|
-
output: {
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
const
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3338
|
+
output: {
|
|
3339
|
+
schema: SEARCH_RESULT,
|
|
3340
|
+
render: (_args, value) => {
|
|
3341
|
+
const filters = [];
|
|
3342
|
+
if (value.tags.length > 0) filters.push(`tags=${value.tags.join(",")}`);
|
|
3343
|
+
if (value.since !== null) filters.push(`since=${value.since}`);
|
|
3344
|
+
if (value.type !== null) filters.push(`type=${value.type}`);
|
|
3345
|
+
if (value.field !== null) filters.push(`field=${value.field}${value.value !== null ? `=${value.value}` : ""}`);
|
|
3346
|
+
let scope = "";
|
|
3347
|
+
if (value.workspace !== null && value.scope === "workspace") scope = ` · 已在工作区 ws/${value.workspace} 内缩小范围`;
|
|
3348
|
+
else if (value.workspace !== null && value.fellBack) scope = ` · 工作区 ws/${value.workspace} 内 0 条,已扩大到全库`;
|
|
3349
|
+
const head = `TiddlyWiki 搜索「${value.query}」${filters.length > 0 ? ` (${filters.join(" · ")})` : ""}:命中 ${value.total} 条${scope}(按相关度排序)。`;
|
|
3350
|
+
const lines = [head];
|
|
3351
|
+
if (value.results.length === 0) lines.push("没有匹配的 tiddler。");
|
|
3352
|
+
let shown = 0;
|
|
3353
|
+
let usedChars = head.length;
|
|
3354
|
+
for (const r of value.results) {
|
|
3355
|
+
const tags = r.tags.length > 0 ? ` [${r.tags.join(", ")}]` : "";
|
|
3356
|
+
const modified = r.modified !== null ? ` (${r.modified})` : "";
|
|
3357
|
+
const row = `- ${r.title}${tags}${modified}`;
|
|
3358
|
+
const cost = row.length + (r.snippet.length > 0 ? r.snippet.length + 4 : 1);
|
|
3359
|
+
if (shown > 0 && usedChars + cost > RENDER_TEXT_BUDGET_CHARS) break;
|
|
3360
|
+
lines.push(row);
|
|
3361
|
+
if (r.snippet.length > 0) lines.push(` ${r.snippet}`);
|
|
3362
|
+
usedChars += cost;
|
|
3363
|
+
shown++;
|
|
3364
|
+
}
|
|
3365
|
+
if (shown < value.results.length) lines.push(`(受回执体量预算限制:本次只展开前 ${shown} 条,另外 ${value.results.length - shown} 条命中未列出 —— 用更精确的 query / tag / field 收窄,或直接 tiddlywiki_get 读标题)`);
|
|
3366
|
+
if (value.total > value.results.length) lines.push(`(另有 ${value.total - value.results.length} 条未展开,可用 tiddlywiki_get 读取具体标题,或提高 limit)`);
|
|
3367
|
+
return [{
|
|
3368
|
+
type: "text",
|
|
3369
|
+
text: lines.join("\n")
|
|
3370
|
+
}];
|
|
3101
3371
|
}
|
|
3102
|
-
|
|
3103
|
-
return [{
|
|
3104
|
-
type: "text",
|
|
3105
|
-
text: lines.join("\n")
|
|
3106
|
-
}];
|
|
3107
|
-
} },
|
|
3372
|
+
},
|
|
3108
3373
|
execute: async (args, exec) => {
|
|
3109
3374
|
const wiki = requireWiki(sessionIdOf(exec));
|
|
3110
3375
|
const options = {
|
|
@@ -3160,19 +3425,22 @@ function recentTool(env) {
|
|
|
3160
3425
|
description: "可选:只返回修改时间不早于该 ISO 时间的 tiddler"
|
|
3161
3426
|
}
|
|
3162
3427
|
},
|
|
3163
|
-
output: {
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3428
|
+
output: {
|
|
3429
|
+
schema: RECENT_RESULT,
|
|
3430
|
+
render: (_args, value) => {
|
|
3431
|
+
const lines = [`TiddlyWiki 最近修改(最近 ${value.results.length} 条${value.since !== null ? `,since=${value.since}` : ""}):`];
|
|
3432
|
+
if (value.results.length === 0) lines.push("暂无笔记。");
|
|
3433
|
+
for (const r of value.results) {
|
|
3434
|
+
const tags = r.tags.length > 0 ? ` [${r.tags.join(", ")}]` : "";
|
|
3435
|
+
lines.push(`- ${r.title}${tags} (${r.modified ?? "?"})`);
|
|
3436
|
+
if (r.snippet.length > 0) lines.push(` ${r.snippet}`);
|
|
3437
|
+
}
|
|
3438
|
+
return [{
|
|
3439
|
+
type: "text",
|
|
3440
|
+
text: lines.join("\n")
|
|
3441
|
+
}];
|
|
3170
3442
|
}
|
|
3171
|
-
|
|
3172
|
-
type: "text",
|
|
3173
|
-
text: lines.join("\n")
|
|
3174
|
-
}];
|
|
3175
|
-
} },
|
|
3443
|
+
},
|
|
3176
3444
|
execute: async (args, exec) => {
|
|
3177
3445
|
const items = await requireWiki(sessionIdOf(exec)).recent(args.limit ?? 15, args.since);
|
|
3178
3446
|
return {
|
|
@@ -3196,19 +3464,22 @@ function listTagsTool(env) {
|
|
|
3196
3464
|
type: "integer",
|
|
3197
3465
|
description: "可选:最多返回多少个标签(按使用次数降序),默认 200,上限 1000。"
|
|
3198
3466
|
} },
|
|
3199
|
-
output: {
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3467
|
+
output: {
|
|
3468
|
+
schema: TAG_LIST_RESULT,
|
|
3469
|
+
render: (_args, value) => {
|
|
3470
|
+
if (value.tags.length === 0) return [{
|
|
3471
|
+
type: "text",
|
|
3472
|
+
text: "知识库暂无标签。"
|
|
3473
|
+
}];
|
|
3474
|
+
const lines = [value.truncated ? `现有标签(共 ${value.total} 个,仅列出使用最多的 ${value.tags.length} 个,按使用次数降序):` : `现有标签(${value.total} 个,按使用次数降序):`];
|
|
3475
|
+
for (const t of value.tags) lines.push(`- ${t.tag} × ${t.count}`);
|
|
3476
|
+
if (value.truncated) lines.push(`(其余 ${value.total - value.tags.length} 个较少使用的标签未列出;需要时可提高 limit 重试)`);
|
|
3477
|
+
return [{
|
|
3478
|
+
type: "text",
|
|
3479
|
+
text: lines.join("\n")
|
|
3480
|
+
}];
|
|
3481
|
+
}
|
|
3482
|
+
},
|
|
3212
3483
|
execute: async (args, exec) => {
|
|
3213
3484
|
const stats = await requireWiki(sessionIdOf(exec)).tagStats();
|
|
3214
3485
|
const limit = typeof args.limit === "number" && Number.isFinite(args.limit) ? Math.max(1, Math.min(Math.floor(args.limit), 1e3)) : 200;
|
|
@@ -3242,15 +3513,18 @@ function backlinksTool(env) {
|
|
|
3242
3513
|
description: "可选:最多返回多少条(默认 30,最大 200)"
|
|
3243
3514
|
}
|
|
3244
3515
|
},
|
|
3245
|
-
output: {
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3516
|
+
output: {
|
|
3517
|
+
schema: BACKLINK_RESULT,
|
|
3518
|
+
render: (_args, value) => {
|
|
3519
|
+
const lines = [`「${value.title}」的反向链接:${value.total} 条(引用 ${value.linkCount} · 标签 ${value.tagCount})`];
|
|
3520
|
+
if (value.items.length === 0) lines.push("没有任何笔记引用它。");
|
|
3521
|
+
for (const item of value.items) lines.push(`- ${item.title}(${item.via === "tag" ? "标签" : `${item.refs} 处引用`})`);
|
|
3522
|
+
return [{
|
|
3523
|
+
type: "text",
|
|
3524
|
+
text: lines.join("\n")
|
|
3525
|
+
}];
|
|
3526
|
+
}
|
|
3527
|
+
},
|
|
3254
3528
|
execute: async (args, exec) => {
|
|
3255
3529
|
const wiki = requireWiki(sessionIdOf(exec));
|
|
3256
3530
|
const target = args.title.trim();
|
|
@@ -3306,20 +3580,32 @@ function lintTool(env) {
|
|
|
3306
3580
|
description: "可选:`stale` 检查里「长期未改动」的阈值天数(默认 180)。只影响候选的判定,不影响 valid-until / review-after 的硬判定"
|
|
3307
3581
|
}
|
|
3308
3582
|
},
|
|
3309
|
-
output: {
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
lines.push(
|
|
3316
|
-
|
|
3583
|
+
output: {
|
|
3584
|
+
schema: LINT_RESULT,
|
|
3585
|
+
render: (_args, value) => {
|
|
3586
|
+
const ran = value.checks.length > 0 ? value.checks.join(", ") : "(无)";
|
|
3587
|
+
const lines = [`知识库体检:扫描 ${value.scanned} 条文本笔记,已检查 ${ran},发现 ${value.issues.reduce((sum, i) => sum + i.count, 0)} 个问题。`];
|
|
3588
|
+
if (value.unknownChecks.length > 0) lines.push(`⚠️ 忽略了无法识别的检查名:${value.unknownChecks.join(", ")}——合法值只有 ${LINT_CHECKS.join(" / ")}`);
|
|
3589
|
+
if (value.issues.length === 0) lines.push(value.checks.length === 0 ? "没有运行任何检查(请求的检查名全部无法识别)。" : "没有发现问题。");
|
|
3590
|
+
let usedChars = lines.join("\n").length;
|
|
3591
|
+
for (const issue of value.issues) {
|
|
3592
|
+
lines.push(`- ${issue.kind}:${issue.count} 处 — ${issue.hint}`);
|
|
3593
|
+
let shown = 0;
|
|
3594
|
+
for (const sample of issue.samples) {
|
|
3595
|
+
const cost = sample.length + 8;
|
|
3596
|
+
if (shown > 0 && usedChars + cost > RENDER_TEXT_BUDGET_CHARS) break;
|
|
3597
|
+
lines.push(` · ${sample}`);
|
|
3598
|
+
usedChars += cost;
|
|
3599
|
+
shown++;
|
|
3600
|
+
}
|
|
3601
|
+
if (shown < issue.samples.length) lines.push(` …其余 ${issue.samples.length - shown} 条示例省略(回执体量预算;可用 limit 逐类收敛,或用 tiddlywiki_search 精确定位)`);
|
|
3602
|
+
}
|
|
3603
|
+
return [{
|
|
3604
|
+
type: "text",
|
|
3605
|
+
text: lines.join("\n")
|
|
3606
|
+
}];
|
|
3317
3607
|
}
|
|
3318
|
-
|
|
3319
|
-
type: "text",
|
|
3320
|
-
text: lines.join("\n")
|
|
3321
|
-
}];
|
|
3322
|
-
} },
|
|
3608
|
+
},
|
|
3323
3609
|
execute: async (args, exec) => {
|
|
3324
3610
|
const wiki = requireWiki(sessionIdOf(exec));
|
|
3325
3611
|
const limit = Math.max(1, Math.min(args.limit ?? 10, 100));
|
|
@@ -3551,41 +3837,64 @@ function getTool(env) {
|
|
|
3551
3837
|
const { requireWiki } = env;
|
|
3552
3838
|
return defineTool({
|
|
3553
3839
|
name: "tiddlywiki_get",
|
|
3554
|
-
description:
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
|
|
3840
|
+
description: `读取一个 TiddlyWiki tiddler 的内容(标题、正文、标签、自定义字段)。二进制 tiddler(图片等附件)只返回元数据,不返回 base64 正文。
|
|
3841
|
+
|
|
3842
|
+
正文按字符分页返回(默认 ${DEFAULT_GET_LIMIT_CHARS} 字符,上限 ${MAX_GET_LIMIT_CHARS}):超长笔记会被**明确标注**已截断,并按回执里的 offset 继续读。分页是刻意的 —— 单条工具结果过大会在上下文压缩时被宿主拦腰截断(DSH 的 spill/pruner 预算),那时既不完整也看不出切口在哪。`,
|
|
3843
|
+
parameters: {
|
|
3844
|
+
title: {
|
|
3845
|
+
type: "string",
|
|
3846
|
+
description: "tiddler 标题(精确匹配)",
|
|
3847
|
+
required: true
|
|
3848
|
+
},
|
|
3849
|
+
offset: {
|
|
3850
|
+
type: "integer",
|
|
3851
|
+
description: "可选:从正文第几个字符开始返回(默认 0)。截断回执会告出下一页的 offset"
|
|
3852
|
+
},
|
|
3853
|
+
limit: {
|
|
3854
|
+
type: "integer",
|
|
3855
|
+
description: `可选:本次返回的字符数上限(默认 ${DEFAULT_GET_LIMIT_CHARS},最大 ${MAX_GET_LIMIT_CHARS})`
|
|
3856
|
+
}
|
|
3857
|
+
},
|
|
3858
|
+
output: {
|
|
3859
|
+
schema: GET_RESULT,
|
|
3860
|
+
render: (_args, value) => {
|
|
3861
|
+
if (value.notFound) return [{
|
|
3862
|
+
type: "text",
|
|
3863
|
+
text: `tiddler「${value.title}」不存在。可用 tiddlywiki_search 检索,或用 tiddlywiki_put 新建。`
|
|
3864
|
+
}];
|
|
3865
|
+
if (value.binary === true) {
|
|
3866
|
+
const lines = [`tiddler「${value.title}」是二进制附件(type=${value.binaryType ?? "?"},base64 正文约 ${value.binaryChars ?? 0} 字符),不返回正文。`];
|
|
3867
|
+
if (value.tags.length > 0) lines.push(`标签: ${value.tags.join(", ")}`);
|
|
3868
|
+
if (value.modified !== null) lines.push(`修改: ${value.modified}`);
|
|
3869
|
+
const fields = Object.entries(value.fields);
|
|
3870
|
+
if (fields.length > 0) lines.push(`字段: ${fields.map(([k, v]) => `${k}=${String(v)}`).join(", ")}`);
|
|
3871
|
+
lines.push(`如需查看附件本身,可打开 [${value.title}](/dsh-tiddlywiki/tw/#${encodeURIComponent(value.title)})。`);
|
|
3872
|
+
return [{
|
|
3873
|
+
type: "text",
|
|
3874
|
+
text: lines.join("\n")
|
|
3875
|
+
}];
|
|
3876
|
+
}
|
|
3877
|
+
const lines = [`tiddler「${value.title}」`];
|
|
3567
3878
|
if (value.tags.length > 0) lines.push(`标签: ${value.tags.join(", ")}`);
|
|
3568
3879
|
if (value.modified !== null) lines.push(`修改: ${value.modified}`);
|
|
3569
3880
|
const fields = Object.entries(value.fields);
|
|
3570
3881
|
if (fields.length > 0) lines.push(`字段: ${fields.map(([k, v]) => `${k}=${String(v)}`).join(", ")}`);
|
|
3571
|
-
|
|
3882
|
+
if (value.textTotalChars > value.text.length || value.offset > 0) {
|
|
3883
|
+
const from = value.offset;
|
|
3884
|
+
const to = value.offset + value.text.length;
|
|
3885
|
+
lines.push(`--- 正文 ${from}–${to} / 共 ${value.textTotalChars} 字符 ---`);
|
|
3886
|
+
} else lines.push("--- 全文 ---");
|
|
3887
|
+
lines.push(value.text.length > 0 ? value.text : "(空)");
|
|
3888
|
+
if (value.textTotalChars > value.offset + value.text.length) {
|
|
3889
|
+
const next = value.offset + value.text.length;
|
|
3890
|
+
lines.push(`⚠️ 正文未读完:还有 ${value.textTotalChars - next} 字符。继续用 tiddlywiki_get({ title: ${JSON.stringify(value.title)}, offset: ${next} }) 读取下一页(不要凭这一页的截断内容做整体改写)。`);
|
|
3891
|
+
}
|
|
3572
3892
|
return [{
|
|
3573
3893
|
type: "text",
|
|
3574
3894
|
text: lines.join("\n")
|
|
3575
3895
|
}];
|
|
3576
3896
|
}
|
|
3577
|
-
|
|
3578
|
-
if (value.tags.length > 0) lines.push(`标签: ${value.tags.join(", ")}`);
|
|
3579
|
-
if (value.modified !== null) lines.push(`修改: ${value.modified}`);
|
|
3580
|
-
const fields = Object.entries(value.fields);
|
|
3581
|
-
if (fields.length > 0) lines.push(`字段: ${fields.map(([k, v]) => `${k}=${String(v)}`).join(", ")}`);
|
|
3582
|
-
lines.push("--- 全文 ---");
|
|
3583
|
-
lines.push(value.text.length > 0 ? value.text : "(空)");
|
|
3584
|
-
return [{
|
|
3585
|
-
type: "text",
|
|
3586
|
-
text: lines.join("\n")
|
|
3587
|
-
}];
|
|
3588
|
-
} },
|
|
3897
|
+
},
|
|
3589
3898
|
execute: async (args, exec) => {
|
|
3590
3899
|
if (isBlockedProxyTitle(args.title)) throw new Error(`tiddlywiki_get: 「${args.title}」属于插件自身命名空间($:/plugins/dsh-tiddlywiki/),可能含密钥,工具层拒绝读取。需要看配置请让人类在 DSH 设置页查看。`);
|
|
3591
3900
|
const t = await requireWiki(sessionIdOf(exec)).get(args.title);
|
|
@@ -3595,13 +3904,20 @@ function getTool(env) {
|
|
|
3595
3904
|
text: "",
|
|
3596
3905
|
tags: [],
|
|
3597
3906
|
fields: {},
|
|
3598
|
-
modified: null
|
|
3907
|
+
modified: null,
|
|
3908
|
+
textTotalChars: 0,
|
|
3909
|
+
offset: 0
|
|
3599
3910
|
};
|
|
3600
3911
|
const binary = isBinaryType(typeof t.type === "string" ? t.type : void 0);
|
|
3912
|
+
const full = binary ? "" : t.text ?? "";
|
|
3913
|
+
const offset = clampGetOffset(args.offset, full.length);
|
|
3914
|
+
const limit = clampGetLimit(args.limit);
|
|
3601
3915
|
const result = {
|
|
3602
3916
|
notFound: false,
|
|
3603
3917
|
title: t.title,
|
|
3604
|
-
text:
|
|
3918
|
+
text: full.slice(offset, offset + limit),
|
|
3919
|
+
textTotalChars: full.length,
|
|
3920
|
+
offset,
|
|
3605
3921
|
tags: t.tags ?? [],
|
|
3606
3922
|
fields: pickFields(t),
|
|
3607
3923
|
modified: toIsoDateString(t.modified)
|
|
@@ -3615,6 +3931,31 @@ function getTool(env) {
|
|
|
3615
3931
|
}
|
|
3616
3932
|
});
|
|
3617
3933
|
}
|
|
3934
|
+
/**
|
|
3935
|
+
* 单条工具结果的字符预算(v0.30.66)。
|
|
3936
|
+
*
|
|
3937
|
+
* 为什么是 12,000:DSH 宿主对**单条**工具结果有两道闸 —— `spill-policy` 的
|
|
3938
|
+
* `maxInlineTokens: 12500`(超了换成「首尾预览 + Omitted N bytes + 落盘路径」)
|
|
3939
|
+
* 与 `compaction-tool-result-pruner` 的 8192/4096/1024(压缩压力下把头尾之外剪掉)。
|
|
3940
|
+
* 中文大约 1 token/字符,所以 12,000 字符对中英混排都落在预算内。分页**由我们**
|
|
3941
|
+
* 做,模型能看到明确的页码与下一页 offset —— 比让宿主在中间剪一刀可读得多。
|
|
3942
|
+
*/
|
|
3943
|
+
const DEFAULT_GET_LIMIT_CHARS = 12e3;
|
|
3944
|
+
const MAX_GET_LIMIT_CHARS = 8e4;
|
|
3945
|
+
/** 把 `limit` 夹到 [1, MAX];未给/非法值回落默认。 */
|
|
3946
|
+
function clampGetLimit(value) {
|
|
3947
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return DEFAULT_GET_LIMIT_CHARS;
|
|
3948
|
+
const n = Math.trunc(value);
|
|
3949
|
+
if (n < 1) return DEFAULT_GET_LIMIT_CHARS;
|
|
3950
|
+
return Math.min(n, MAX_GET_LIMIT_CHARS);
|
|
3951
|
+
}
|
|
3952
|
+
/** 把 `offset` 夹到 [0, totalChars](越界读取返回空片段而不是报错)。 */
|
|
3953
|
+
function clampGetOffset(value, totalChars) {
|
|
3954
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return 0;
|
|
3955
|
+
const n = Math.trunc(value);
|
|
3956
|
+
if (n < 0) return 0;
|
|
3957
|
+
return Math.min(n, totalChars);
|
|
3958
|
+
}
|
|
3618
3959
|
function putTool(env) {
|
|
3619
3960
|
const { deps, requireWiki } = env;
|
|
3620
3961
|
return defineTool({
|
|
@@ -3655,21 +3996,24 @@ function putTool(env) {
|
|
|
3655
3996
|
}
|
|
3656
3997
|
},
|
|
3657
3998
|
normalizeArgs: normalizeFieldsInArgs,
|
|
3658
|
-
output: {
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
|
|
3662
|
-
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
if (
|
|
3999
|
+
output: {
|
|
4000
|
+
schema: PUT_RESULT,
|
|
4001
|
+
render: (_args, value) => {
|
|
4002
|
+
const lines = [`已写入 tiddler「${value.title}」`];
|
|
4003
|
+
if (value.workspace !== void 0) lines.push(`已自动标记工作区: ws/${value.workspace}(字段 ${WORKSPACE_FIELD})`);
|
|
4004
|
+
if (value.tags.length > 0) lines.push(`标签: ${value.tags.join(", ")}`);
|
|
4005
|
+
if (value.type !== null) lines.push(`类型: ${value.type}${value.typeDefaulted === true ? "(新建且未指定,已默认 markdown)" : ""}`);
|
|
4006
|
+
if (value.typeChanged !== void 0) lines.push(`⚠️ 内容类型已从 ${value.typeChanged.from} 改为 ${value.typeChanged.to}(覆盖前请确认这是你要的)`);
|
|
4007
|
+
if (value.fields !== null) {
|
|
4008
|
+
const entries = Object.entries(value.fields);
|
|
4009
|
+
if (entries.length > 0) lines.push(`字段: ${entries.map(([k, v]) => `${k}=${String(v)}`).join(", ")}`);
|
|
4010
|
+
}
|
|
4011
|
+
return [{
|
|
4012
|
+
type: "text",
|
|
4013
|
+
text: lines.join("\n")
|
|
4014
|
+
}];
|
|
3667
4015
|
}
|
|
3668
|
-
|
|
3669
|
-
type: "text",
|
|
3670
|
-
text: lines.join("\n")
|
|
3671
|
-
}];
|
|
3672
|
-
} },
|
|
4016
|
+
},
|
|
3673
4017
|
execute: async (args, exec) => {
|
|
3674
4018
|
const wiki = requireWiki(sessionIdOf(exec));
|
|
3675
4019
|
if (args.title.trim().length === 0) throw new Error("tiddlywiki_put: title 不能为空");
|
|
@@ -3755,17 +4099,20 @@ function batchPutTool(env) {
|
|
|
3755
4099
|
...args,
|
|
3756
4100
|
items: normalizeBatchItemsFields(args.items)
|
|
3757
4101
|
}),
|
|
3758
|
-
output: {
|
|
3759
|
-
|
|
3760
|
-
|
|
3761
|
-
const
|
|
3762
|
-
|
|
4102
|
+
output: {
|
|
4103
|
+
schema: BATCH_RESULT,
|
|
4104
|
+
render: (_args, value) => {
|
|
4105
|
+
const lines = [`批量写入完成:成功 ${value.written},跳过 ${value.skipped},失败 ${value.failed},共 ${value.items.length} 条。`];
|
|
4106
|
+
for (const r of value.items) {
|
|
4107
|
+
const ws = r.workspace !== void 0 ? `(已标记工作区 ws/${r.workspace})` : "";
|
|
4108
|
+
lines.push(`- ${r.title}:${r.written ? `已写入${ws}` : r.skipped ? "已跳过(存在)" : `失败(${r.error ?? "未知错误"})`}`);
|
|
4109
|
+
}
|
|
4110
|
+
return [{
|
|
4111
|
+
type: "text",
|
|
4112
|
+
text: lines.join("\n")
|
|
4113
|
+
}];
|
|
3763
4114
|
}
|
|
3764
|
-
|
|
3765
|
-
type: "text",
|
|
3766
|
-
text: lines.join("\n")
|
|
3767
|
-
}];
|
|
3768
|
-
} },
|
|
4115
|
+
},
|
|
3769
4116
|
execute: async (args, exec) => {
|
|
3770
4117
|
const wiki = requireWiki(sessionIdOf(exec));
|
|
3771
4118
|
const list = Array.isArray(args.items) ? args.items : [];
|
|
@@ -3890,19 +4237,22 @@ function renameTool(env) {
|
|
|
3890
4237
|
description: "可选:true 时忽略 expectedModified/expectedRevision 强制重命名(默认 false)"
|
|
3891
4238
|
}
|
|
3892
4239
|
},
|
|
3893
|
-
output: {
|
|
3894
|
-
|
|
3895
|
-
|
|
3896
|
-
|
|
3897
|
-
|
|
3898
|
-
|
|
4240
|
+
output: {
|
|
4241
|
+
schema: RENAME_RESULT,
|
|
4242
|
+
render: (_args, value) => {
|
|
4243
|
+
const lines = [`已重命名「${value.from}」→「${value.to}」`];
|
|
4244
|
+
lines.push(`更新了 ${value.refsUpdated} 处引用(${value.refsTiddlers} 个 tiddler)`);
|
|
4245
|
+
if ((value.refsSkipped ?? 0) > 0) {
|
|
4246
|
+
const names = (value.skippedTitles ?? []).join("、");
|
|
4247
|
+
lines.push(`跳过了 ${value.refsSkipped} 个引用者(遍历期间被改动过,未覆盖)${names.length > 0 ? `:${names}` : ""}`);
|
|
4248
|
+
}
|
|
4249
|
+
if (value.warning !== void 0) lines.push(`注意: ${value.warning}`);
|
|
4250
|
+
return [{
|
|
4251
|
+
type: "text",
|
|
4252
|
+
text: lines.join("\n")
|
|
4253
|
+
}];
|
|
3899
4254
|
}
|
|
3900
|
-
|
|
3901
|
-
return [{
|
|
3902
|
-
type: "text",
|
|
3903
|
-
text: lines.join("\n")
|
|
3904
|
-
}];
|
|
3905
|
-
} },
|
|
4255
|
+
},
|
|
3906
4256
|
execute: async (args, exec) => {
|
|
3907
4257
|
const wiki = requireWiki(sessionIdOf(exec));
|
|
3908
4258
|
const { oldTitle, newTitle } = args;
|
|
@@ -4036,17 +4386,20 @@ function appendTool(env) {
|
|
|
4036
4386
|
}
|
|
4037
4387
|
},
|
|
4038
4388
|
normalizeArgs: normalizeFieldsInArgs,
|
|
4039
|
-
output: {
|
|
4040
|
-
|
|
4041
|
-
|
|
4042
|
-
|
|
4043
|
-
|
|
4044
|
-
|
|
4045
|
-
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
|
|
4049
|
-
|
|
4389
|
+
output: {
|
|
4390
|
+
schema: APPEND_RESULT,
|
|
4391
|
+
render: (_args, value) => {
|
|
4392
|
+
const headingNote = value.heading === null ? "" : value.headingMatched === false ? ` · ⚠️ 未找到标题「${value.heading}」,已改为追加到文末` : ` · 段落「${value.heading}」`;
|
|
4393
|
+
const lines = [`${value.created ? "已新建并写入" : "已增量写入"} tiddler「${value.title}」(${value.mode}${headingNote}):新增 ${value.added} 字符,现共 ${value.total} 字符。`];
|
|
4394
|
+
if (value.type !== null) lines.push(`类型: ${value.type}${value.typeDefaulted === true ? "(新建且未指定,已默认 markdown)" : ""}`);
|
|
4395
|
+
if (value.typeChanged !== void 0) lines.push(`⚠️ 内容类型已从 ${value.typeChanged.from} 改为 ${value.typeChanged.to}`);
|
|
4396
|
+
if (value.workspace !== void 0) lines.push(`已自动标记工作区: ws/${value.workspace}(字段 ${WORKSPACE_FIELD})`);
|
|
4397
|
+
return [{
|
|
4398
|
+
type: "text",
|
|
4399
|
+
text: lines.join("\n")
|
|
4400
|
+
}];
|
|
4401
|
+
}
|
|
4402
|
+
},
|
|
4050
4403
|
execute: async (args, exec) => {
|
|
4051
4404
|
const wiki = requireWiki(sessionIdOf(exec));
|
|
4052
4405
|
const title = args.title.trim();
|
|
@@ -4135,16 +4488,19 @@ function replaceTool(env) {
|
|
|
4135
4488
|
description: "可选:true 时忽略 expectedModified/expectedRevision 强制替换(默认 false)"
|
|
4136
4489
|
}
|
|
4137
4490
|
},
|
|
4138
|
-
output: {
|
|
4139
|
-
|
|
4140
|
-
|
|
4141
|
-
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
|
|
4147
|
-
|
|
4491
|
+
output: {
|
|
4492
|
+
schema: REPLACE_RESULT,
|
|
4493
|
+
render: (_args, value) => {
|
|
4494
|
+
if (value.found === false) return [{
|
|
4495
|
+
type: "text",
|
|
4496
|
+
text: `⚠️ tiddler「${value.title}」里没找到要替换的原文,未做任何改动。请先 tiddlywiki_get 读原文、确认要替换的精确子串。`
|
|
4497
|
+
}];
|
|
4498
|
+
return [{
|
|
4499
|
+
type: "text",
|
|
4500
|
+
text: `已替换 tiddler「${value.title}」:命中 ${value.replaced} 处,现共 ${value.total} 字符。`
|
|
4501
|
+
}];
|
|
4502
|
+
}
|
|
4503
|
+
},
|
|
4148
4504
|
execute: async (args, exec) => {
|
|
4149
4505
|
const wiki = requireWiki(sessionIdOf(exec));
|
|
4150
4506
|
const title = args.title.trim();
|
|
@@ -4222,10 +4578,13 @@ function deleteTool(env) {
|
|
|
4222
4578
|
description: "可选:true 时忽略 expectedModified/expectedRevision 强制删除(默认 false)"
|
|
4223
4579
|
}
|
|
4224
4580
|
},
|
|
4225
|
-
output: {
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
|
|
4581
|
+
output: {
|
|
4582
|
+
schema: DELETE_RESULT,
|
|
4583
|
+
render: (_args, value) => [{
|
|
4584
|
+
type: "text",
|
|
4585
|
+
text: value.trashed === true ? `已把 tiddler「${value.title}」移入回收站${value.trashTitle !== void 0 ? `(${value.trashTitle},可用 tiddlywiki_trash action=restore 恢复)` : "(可用 tiddlywiki_trash action=restore 恢复)"}。` : `已永久删除 tiddler「${value.title}」。`
|
|
4586
|
+
}]
|
|
4587
|
+
},
|
|
4229
4588
|
execute: async (args, exec) => {
|
|
4230
4589
|
const wiki = requireWiki(sessionIdOf(exec));
|
|
4231
4590
|
const existing = await wiki.get(args.title);
|
|
@@ -4318,14 +4677,17 @@ function trashTool(env) {
|
|
|
4318
4677
|
description: "action=list 的返回上限(默认 30,最大 200)"
|
|
4319
4678
|
}
|
|
4320
4679
|
},
|
|
4321
|
-
output: {
|
|
4322
|
-
|
|
4323
|
-
|
|
4324
|
-
|
|
4325
|
-
|
|
4326
|
-
|
|
4327
|
-
|
|
4328
|
-
|
|
4680
|
+
output: {
|
|
4681
|
+
schema: TRASH_RESULT,
|
|
4682
|
+
render: (_args, value) => {
|
|
4683
|
+
const lines = [`回收站 ${value.action}:${value.message}`];
|
|
4684
|
+
for (const item of value.items ?? []) lines.push(`- ${item.title}(删除于 ${item.at ?? "?"}${item.of !== void 0 ? `,原名「${item.of}」` : ""})`);
|
|
4685
|
+
return [{
|
|
4686
|
+
type: "text",
|
|
4687
|
+
text: lines.join("\n")
|
|
4688
|
+
}];
|
|
4689
|
+
}
|
|
4690
|
+
},
|
|
4329
4691
|
execute: async (args, exec) => {
|
|
4330
4692
|
const wiki = requireWiki(sessionIdOf(exec));
|
|
4331
4693
|
const trashbin = await listTrashbin(wiki, (wikitext) => wiki.render({
|
|
@@ -5502,17 +5864,20 @@ function attachTool(env) {
|
|
|
5502
5864
|
description: "可选:true 时忽略 expectedModified/expectedRevision,允许覆盖同名 tiddler(默认 false;即便覆盖也会保留其 tags 与自定义字段)"
|
|
5503
5865
|
}
|
|
5504
5866
|
},
|
|
5505
|
-
output: {
|
|
5506
|
-
|
|
5507
|
-
|
|
5508
|
-
|
|
5509
|
-
|
|
5510
|
-
|
|
5511
|
-
|
|
5512
|
-
|
|
5513
|
-
|
|
5514
|
-
|
|
5515
|
-
|
|
5867
|
+
output: {
|
|
5868
|
+
schema: ATTACH_RESULT,
|
|
5869
|
+
render: (_args, value) => {
|
|
5870
|
+
const size = value.encoding === "base64" ? `base64 约 ${value.chars} 字符` : `纯文本 ${value.chars} 字符`;
|
|
5871
|
+
const lines = [`已保存附件「${value.title}」(${value.mime},${value.bytes} 字节,${size})`];
|
|
5872
|
+
if (value.source !== null) lines.push(`来源: ${value.source}`);
|
|
5873
|
+
if (value.embedInto !== null) lines.push(`已嵌入笔记「${value.embedInto}」`);
|
|
5874
|
+
lines.push(`打开: [${value.title}](/dsh-tiddlywiki/tw/#${encodeURIComponent(value.title)})`);
|
|
5875
|
+
return [{
|
|
5876
|
+
type: "text",
|
|
5877
|
+
text: lines.join("\n")
|
|
5878
|
+
}];
|
|
5879
|
+
}
|
|
5880
|
+
},
|
|
5516
5881
|
execute: async (args, exec) => {
|
|
5517
5882
|
const wiki = requireWiki(sessionIdOf(exec));
|
|
5518
5883
|
const title = args.title.trim();
|
|
@@ -6204,6 +6569,47 @@ function escapePromptBraces(text) {
|
|
|
6204
6569
|
*/
|
|
6205
6570
|
const WRITE_RULES = `### 写入约定
|
|
6206
6571
|
- 写入被拒(说明刚有人(在 TW 编辑器里)改过)时**重读一遍再决定**,不要用 \`force\` 硬覆盖。`;
|
|
6572
|
+
/**
|
|
6573
|
+
* Governance block: WHEN to come and look (v0.30.66).
|
|
6574
|
+
*
|
|
6575
|
+
* WHY IT HAS TO BE HERE, AND WHY IT IS FIRST
|
|
6576
|
+
* ------------------------------------------
|
|
6577
|
+
* 插件过去只讲「怎么写」—— 写入约定 / 同步纪律 / 笔记约定 —— 全是写侧规则,
|
|
6578
|
+
* 没有一句讲"什么时候该来查"。工具面小的时候这没问题(模型只有几十个工具可选,
|
|
6579
|
+
* 看到 `tiddlywiki_search` 的 description 就会想起来);工具面一大就不行了:
|
|
6580
|
+
* 2026-10-26 实测同一个 profile 的会话里模型可见工具从 57 个涨到 243 个
|
|
6581
|
+
* (MCP 批量接入),作者随即报「新会话不会主动去查找 wiki 了」。注入本身没坏
|
|
6582
|
+
* (`system/message` 里逐字可查),坏的是**没有任何一条规则要求它先查**。
|
|
6583
|
+
*
|
|
6584
|
+
* 这条属于「schema 表达不了的约定」里最典型的一类:**时机**。参数/返回契约在
|
|
6585
|
+
* 各工具 schema 里,而"什么时候该调"只能写在提示词里。
|
|
6586
|
+
*/
|
|
6587
|
+
const READ_RULES = `### 先查再答
|
|
6588
|
+
- 问题可能已沉淀成笔记(项目背景、历史决策、"之前记过的东西"):**先 \`tiddlywiki_search\`**,命中不足再放宽词或换 tag/field,别凭记忆答;读整篇用 \`tiddlywiki_get\`,超长会分页、按回执里的 offset 续读。`;
|
|
6589
|
+
/**
|
|
6590
|
+
* Governance block: 时效 / 去重 / 不写流水账 (v0.30.66, 作者 2026-10-26 提出)。
|
|
6591
|
+
*
|
|
6592
|
+
* THE FAILURE IT FIXES
|
|
6593
|
+
* --------------------
|
|
6594
|
+
* 作者的原话:「agent 在 wiki 里很喜欢写入一些时效性很短的东西,换个会话基本
|
|
6595
|
+
* 就很难用上了;以及同样的事情,写了多个内容有差异的东西」——即
|
|
6596
|
+
* ① 写了**短命内容**却没有任何"什么时候还有效"的标记 →
|
|
6597
|
+
* 下一个会话读到它,既不知道能不能用,也不知道该不该清;
|
|
6598
|
+
* ② 同一件事被写成**多份互相矛盾**的笔记(没有"先搜再写/原地改"的纪律)→
|
|
6599
|
+
* 人和后续 Agent 都不敢用任何一份;
|
|
6600
|
+
* ③ 每次改动都在正文**追加变更流水**("2026-10-26 改了什么")→
|
|
6601
|
+
* 信息膨胀,而真正有用的始终只有那一小段"现在怎么做"。
|
|
6602
|
+
*
|
|
6603
|
+
* 这三条都是**时机与纪律**,任何工具 schema 都表达不了(schema 只说怎么调,不说
|
|
6604
|
+
* 什么时候该写、该改、该清),所以只能落在提示词里 —— 也正是这个 block 存在的
|
|
6605
|
+
* 理由。它会明显推高 slim 的长度预算,这是刻意的:宁可多 400 字符,也不要每个
|
|
6606
|
+
* 新会话都重新踩一遍"读完不知道能不能信、信了又被下一份笔记打脸"。
|
|
6607
|
+
*/
|
|
6608
|
+
const LIFECYCLE_RULES = `### 时效与去重(写之前先搜,别留短命内容)
|
|
6609
|
+
- **一件事只留一处权威表述**:先 \`tiddlywiki_search\`;命中就**原地改那一节**,别另起一篇 —— 同主题两份说法不一致,后续会话和人类都不敢用。
|
|
6610
|
+
- 每条笔记要能看出**还有效到什么时候**:会过期的写 \`valid-until: YYYY-MM-DD\`,该复查的写 \`review-after: YYYY-MM-DD\`,长期不变的正文开头写明「长期有效」;说不清时效的("今天试了一下")**别写进 wiki**。
|
|
6611
|
+
- **不写流水账**:不要追加"某日改了什么"这类变更流水(git 历史里就有),只留「现在正确的做法」。运营日志/复盘/踩坑存档可按时间追加,但正文必须自带存档标记。
|
|
6612
|
+
- **读到就先判时效**:过期 / 被取代 / 与现状不符 → 当场更新那一处,或明确说"这条已过期、建议清理",别照着旧内容答;被取代的写 \`superseded-by: [[新笔记]]\` + \`superseded\` 标签并**保留旧笔记**。**淘汰只由人决定**,别自行删除。`;
|
|
6207
6613
|
/** Governance block: the three-step git discipline + conflict recovery. */
|
|
6208
6614
|
const SYNC_RULES = `### 同步纪律
|
|
6209
6615
|
- 开工先 \`tiddlywiki_git_sync action=pull\`,收工 \`action=sync\`。
|
|
@@ -6237,7 +6643,6 @@ function noteRules(linkBase) {
|
|
|
6237
6643
|
return `### 笔记约定
|
|
6238
6644
|
- wiki 是长期记忆:会议纪要、决策记录、调研笔记、随手的想法都存成独立 tiddler(tag 用 inbox/meeting/decision 等便于检索)。
|
|
6239
6645
|
- **值得做但不在当前范围内的想法**:写成独立 tiddler、打 \`todo\`,正文简述来源(会话 / 工作区 / 项目背景),由用户决定是否继续。
|
|
6240
|
-
- **阶段性内容标时效**:会过期的笔记带 \`valid-until: YYYY-MM-DD\`(硬过期)或 \`review-after: YYYY-MM-DD\`(该复查);被取代时写 \`superseded-by: [[新笔记]]\` 并打 \`superseded\` 标签、**保留旧笔记**。**淘汰只由人决定**,不要自行删除。
|
|
6241
6646
|
- \`agent-written\` 由工具自动补打,别手动加或删;人类编辑过 Agent 笔记后补 \`human-edited\`。
|
|
6242
6647
|
- **笔记内引用**:写 \`[[标题]]\`(文字不同写 \`[[标题|文字]]\`),别用 \`[标题](url)\`(当外链、URL 带空格即失效)。
|
|
6243
6648
|
- **聊天里引用笔记**:写 ${linkBase === "/dsh-tiddlywiki/tw/" ? `\`[标题](${linkBase}#标题)\`(空格等特殊字符做 URL 编码;中文可直写)` : `\`[标题](${linkBase}#标题)\`——**多库:必须写上面横幅里那个库 id**(否则会开到别的库);空格等特殊字符做 URL 编码(中文可直写)`},点它打开 TW 面板。`;
|
|
@@ -6255,11 +6660,25 @@ const PUBLISH_RULE = `- **对外发布前**:先读 [[发布元数据规范]]
|
|
|
6255
6660
|
* Governance blocks that MUST survive in every mode — exported so
|
|
6256
6661
|
* `scripts/verify-prompt.mjs` can assert a re-write never silently drops one.
|
|
6257
6662
|
*/
|
|
6258
|
-
const PROMPT_GOVERNANCE_BLOCKS =
|
|
6259
|
-
|
|
6260
|
-
|
|
6261
|
-
|
|
6262
|
-
|
|
6663
|
+
const PROMPT_GOVERNANCE_BLOCKS = governanceBlocks(noteRules(TW_LINK_BASE), false);
|
|
6664
|
+
/**
|
|
6665
|
+
* The governance blocks **in injection order** — the single source for both the
|
|
6666
|
+
* built body and the exported list the guard iterates (v0.30.66).
|
|
6667
|
+
*
|
|
6668
|
+
* Why a function: the previous code had the exported list AND a hand-written
|
|
6669
|
+
* array inside `buildPromptText`, so adding a block to one of them silently
|
|
6670
|
+
* produced a prompt the guard still considered complete. `verify-prompt.mjs`
|
|
6671
|
+
* caught exactly that when `READ_RULES` was added.
|
|
6672
|
+
*/
|
|
6673
|
+
function governanceBlocks(notes, wechat) {
|
|
6674
|
+
return [
|
|
6675
|
+
READ_RULES,
|
|
6676
|
+
LIFECYCLE_RULES,
|
|
6677
|
+
WRITE_RULES,
|
|
6678
|
+
SYNC_RULES,
|
|
6679
|
+
wechat ? `${notes}\n${PUBLISH_RULE}` : notes
|
|
6680
|
+
];
|
|
6681
|
+
}
|
|
6263
6682
|
/**
|
|
6264
6683
|
* One line per tool: `bullet \`name\`(p1, p2?, …)`; `?` marks an optional
|
|
6265
6684
|
* parameter. Shared by the `full` prompt catalogue and by the TW-side doc seed
|
|
@@ -6311,12 +6730,7 @@ function buildPromptText(options) {
|
|
|
6311
6730
|
const override = typeof options.override === "string" ? options.override.trim() : "";
|
|
6312
6731
|
const intro = normalizePromptMode(options.mode) === "full" ? fullIntro(tools) : slimIntro(tools.length);
|
|
6313
6732
|
const notes = noteRules(options.linkBase ?? "/dsh-tiddlywiki/tw/");
|
|
6314
|
-
const body = override.length > 0 ? escapePromptBraces(override) : [
|
|
6315
|
-
intro,
|
|
6316
|
-
WRITE_RULES,
|
|
6317
|
-
SYNC_RULES,
|
|
6318
|
-
options.wechat === true ? `${notes}\n${PUBLISH_RULE}` : notes
|
|
6319
|
-
].join("\n\n");
|
|
6733
|
+
const body = override.length > 0 ? escapePromptBraces(override) : [intro, ...governanceBlocks(notes, options.wechat === true)].join("\n\n");
|
|
6320
6734
|
const extra = typeof options.extra === "string" ? escapePromptBraces(options.extra.trim()) : "";
|
|
6321
6735
|
return extra.length > 0 ? `${body}\n\n${extra}` : body;
|
|
6322
6736
|
}
|
|
@@ -9024,7 +9438,10 @@ function gitSyncTool(env) {
|
|
|
9024
9438
|
description: "commit 信息(可选,仅 sync 的本地 commit 使用)"
|
|
9025
9439
|
}
|
|
9026
9440
|
},
|
|
9027
|
-
output: {
|
|
9441
|
+
output: {
|
|
9442
|
+
schema: GIT_RESULT,
|
|
9443
|
+
render: (_args, value) => renderSync(value)
|
|
9444
|
+
},
|
|
9028
9445
|
execute: async (args, exec) => {
|
|
9029
9446
|
const action = args.action;
|
|
9030
9447
|
/**
|
|
@@ -9153,18 +9570,21 @@ function gitResolveTool(env) {
|
|
|
9153
9570
|
description: "可选:要解决哪一个知识库所在的仓库(传 tiddlywiki_git_sync 回执里的库 id)。不传 = 当前会话作用域的那个库;多库各有独立仓库时**必须传**,否则可能改错仓库。"
|
|
9154
9571
|
}
|
|
9155
9572
|
},
|
|
9156
|
-
output: {
|
|
9157
|
-
|
|
9158
|
-
|
|
9159
|
-
|
|
9160
|
-
|
|
9161
|
-
|
|
9162
|
-
|
|
9163
|
-
|
|
9164
|
-
|
|
9165
|
-
|
|
9166
|
-
|
|
9167
|
-
|
|
9573
|
+
output: {
|
|
9574
|
+
schema: GIT_RESULT,
|
|
9575
|
+
render: (_args, value) => {
|
|
9576
|
+
const lines = [`git resolve ${value.action}: ${value.ok ? "成功" : "失败"}`];
|
|
9577
|
+
lines.push(` ${value.message}`);
|
|
9578
|
+
if (value.repo !== void 0) lines.push(`仓库: ${value.repo}${value.wikis !== void 0 && value.wikis.length > 0 ? `(库 ${value.wikis.join("、")})` : ""}`);
|
|
9579
|
+
if (value.files !== void 0 && value.files.length > 0) lines.push(`涉及文件: ${value.files.join(", ")}`);
|
|
9580
|
+
if (value.commit !== void 0) lines.push(`本地 commit: ${value.commit}`);
|
|
9581
|
+
if (value.status !== void 0) lines.push(`状态: ${gitStatusBits(value.status)}`);
|
|
9582
|
+
return [{
|
|
9583
|
+
type: "text",
|
|
9584
|
+
text: lines.join("\n")
|
|
9585
|
+
}];
|
|
9586
|
+
}
|
|
9587
|
+
},
|
|
9168
9588
|
execute: async (args, exec) => {
|
|
9169
9589
|
const target = await resolveResolveTarget(deps, args.wiki, deps.scope(sessionIdOf(exec)).dir);
|
|
9170
9590
|
const dir = target.dir;
|
|
@@ -16333,6 +16753,61 @@ function defaultSkillRoot() {
|
|
|
16333
16753
|
return dshHomePath("skills");
|
|
16334
16754
|
}
|
|
16335
16755
|
/**
|
|
16756
|
+
* Split a `SKILL.md` into `{name, description, whenToUse?, content}`.
|
|
16757
|
+
*
|
|
16758
|
+
* Hand-rolled on purpose: the only structured part we need is the four-line
|
|
16759
|
+
* frontmatter at the top, and pulling a YAML parser in for that would add a
|
|
16760
|
+
* runtime dependency to a plugin whose pitch is "no build surprises".
|
|
16761
|
+
* Tolerant by design — anything unexpected returns `undefined` and the caller
|
|
16762
|
+
* falls back to the file installer.
|
|
16763
|
+
*/
|
|
16764
|
+
function parseSkillText(text) {
|
|
16765
|
+
const normalised = text.replace(/\r\n/g, "\n");
|
|
16766
|
+
const match = /^---\n([\s\S]*?)\n---\n?/.exec(normalised);
|
|
16767
|
+
if (match === null) return void 0;
|
|
16768
|
+
const front = match[1] ?? "";
|
|
16769
|
+
const field = (key) => {
|
|
16770
|
+
const value = new RegExp(`^${key}:[ \\t]*(.+)$`, "m").exec(front)?.[1];
|
|
16771
|
+
return value === void 0 ? void 0 : value.trim();
|
|
16772
|
+
};
|
|
16773
|
+
const name = field("name");
|
|
16774
|
+
const description = field("description");
|
|
16775
|
+
if (name === void 0 || name.length === 0 || description === void 0 || description.length === 0) return void 0;
|
|
16776
|
+
if (!/^[a-z0-9]+(-[a-z0-9]+)*$/.test(name)) return void 0;
|
|
16777
|
+
const content = normalised.slice(match[0].length).trim();
|
|
16778
|
+
if (content.length === 0) return void 0;
|
|
16779
|
+
const whenToUse = field("whenToUse");
|
|
16780
|
+
return {
|
|
16781
|
+
name,
|
|
16782
|
+
description,
|
|
16783
|
+
...whenToUse !== void 0 && whenToUse.length > 0 ? { whenToUse } : {},
|
|
16784
|
+
content
|
|
16785
|
+
};
|
|
16786
|
+
}
|
|
16787
|
+
/**
|
|
16788
|
+
* Register the split-wiki skill **in memory** through the host's skill registry.
|
|
16789
|
+
*
|
|
16790
|
+
* Returns the registry's disposer, or `undefined` when the shipped text cannot be
|
|
16791
|
+
* parsed (the caller then falls back to writing the file). Never throws: a skill
|
|
16792
|
+
* that fails to register must not take startup down.
|
|
16793
|
+
*/
|
|
16794
|
+
function registerSplitSkill(skills, text) {
|
|
16795
|
+
const parsed = parseSkillText(text);
|
|
16796
|
+
if (parsed === void 0) return void 0;
|
|
16797
|
+
try {
|
|
16798
|
+
return skills.register({
|
|
16799
|
+
...parsed,
|
|
16800
|
+
invocation: {
|
|
16801
|
+
modelInvocable: true,
|
|
16802
|
+
userInvocable: true
|
|
16803
|
+
}
|
|
16804
|
+
});
|
|
16805
|
+
} catch (err) {
|
|
16806
|
+
console.warn("[dsh-tiddlywiki] 拆库 skill 注册失败(改用文件安装):", err);
|
|
16807
|
+
return;
|
|
16808
|
+
}
|
|
16809
|
+
}
|
|
16810
|
+
/**
|
|
16336
16811
|
* Read the skill that ships inside this package.
|
|
16337
16812
|
*
|
|
16338
16813
|
* Two candidates because the same module runs from two places: `lib/index.js`
|
|
@@ -16417,19 +16892,29 @@ function createStartupStage(deps) {
|
|
|
16417
16892
|
const start = async () => {
|
|
16418
16893
|
try {
|
|
16419
16894
|
/**
|
|
16420
|
-
* Ship the 「拆分知识库」 skill FIRST (v0.28.0).
|
|
16895
|
+
* Ship the 「拆分知识库」 skill FIRST (v0.28.0; in-memory since v0.30.66).
|
|
16896
|
+
*
|
|
16897
|
+
* Two delivery paths, best one first:
|
|
16898
|
+
* · **registry** (`ctx.skills.register`) — the skill lives in memory, is
|
|
16899
|
+
* disposed with the plugin, and never writes into the user's home.
|
|
16900
|
+
* · **file** (`$DSH_HOME/skills/…`) — fallback for hosts without a skill
|
|
16901
|
+
* registry. It only ever touches its own marked file.
|
|
16421
16902
|
*
|
|
16422
|
-
*
|
|
16423
|
-
*
|
|
16424
|
-
* start, fails to start, or the user is mid-migration with a broken config.
|
|
16425
|
-
* A plugin cannot register a skill ROOT, so writing into the user's own root
|
|
16426
|
-
* is the only zero-config path; it only ever touches its own file (the
|
|
16427
|
-
* marker line decides — see host/skill-install.ts).
|
|
16903
|
+
* Deliberately independent of the wiki: it must still happen when the wiki
|
|
16904
|
+
* is slow, broken, or mid-migration.
|
|
16428
16905
|
*/
|
|
16429
16906
|
try {
|
|
16430
|
-
const
|
|
16431
|
-
|
|
16432
|
-
|
|
16907
|
+
const text = await readBundledSkillText();
|
|
16908
|
+
const skills = deps.skills?.();
|
|
16909
|
+
const dispose = skills !== void 0 && text !== void 0 ? registerSplitSkill(skills, text) : void 0;
|
|
16910
|
+
if (dispose !== void 0) {
|
|
16911
|
+
deps.pushDisposer(dispose);
|
|
16912
|
+
console.info("[dsh-tiddlywiki] 拆库 skill:已注册到宿主 skill 注册表(内存,无文件写入)");
|
|
16913
|
+
} else {
|
|
16914
|
+
const installed = await installSplitSkill();
|
|
16915
|
+
if (installed.action === "failed") console.warn("[dsh-tiddlywiki] 拆库 skill 安装失败:", installed.error);
|
|
16916
|
+
else console.info(`[dsh-tiddlywiki] 拆库 skill:${installed.action}(${installed.path})`);
|
|
16917
|
+
}
|
|
16433
16918
|
} catch (err) {
|
|
16434
16919
|
console.warn("[dsh-tiddlywiki] 拆库 skill 安装异常:", err);
|
|
16435
16920
|
}
|
|
@@ -16492,6 +16977,106 @@ function createStartupStage(deps) {
|
|
|
16492
16977
|
return { start };
|
|
16493
16978
|
}
|
|
16494
16979
|
//#endregion
|
|
16980
|
+
//#region src/host/command-note.ts
|
|
16981
|
+
/**
|
|
16982
|
+
* `/note <标题>\n<正文>` —— 把一条笔记直接写进当前会话的知识库(v0.30.66)。
|
|
16983
|
+
*
|
|
16984
|
+
* WHY A SLASH COMMAND
|
|
16985
|
+
* -------------------
|
|
16986
|
+
* 快速笔记卡是"打开一张卡、填三四个字段、保存"的三步流程;用户真正想要记一句话时,
|
|
16987
|
+
* 那三步全是摩擦。DSH 的 `ctx.commands.register()` 提供的正是这个形态:命令**直接
|
|
16988
|
+
* 作用于 agent**、不产生模型消息、不进上下文(`recordInput` 语义),所以"随手记"
|
|
16989
|
+
* 不必先跟模型说一句话、也就不会污染对话。
|
|
16990
|
+
*
|
|
16991
|
+
* WHY IT REFUSES TO OVERWRITE
|
|
16992
|
+
* ---------------------------
|
|
16993
|
+
* 作者 2026-10-26 的核心抱怨之一是「同样的事情写了多个内容有差异的东西」。一个
|
|
16994
|
+
* `/note` 命令最容易造成的正是这个:同一标题再写一次。所以同名笔记**已存在就拒绝**
|
|
16995
|
+
* 并指路(让用户用编辑器改、或让 agent 用 `tiddlywiki_replace`/`put` 按并发令牌改),
|
|
16996
|
+
* 而不是第二次静默覆盖第一版。
|
|
16997
|
+
*
|
|
16998
|
+
* @module dsh-tiddlywiki/host/command-note
|
|
16999
|
+
*/
|
|
17000
|
+
/** The command's stable identity (also what `/help` lists). */
|
|
17001
|
+
const NOTE_COMMAND_NAME = "note";
|
|
17002
|
+
/** Longest title we derive from a single-line invocation. */
|
|
17003
|
+
const DERIVED_TITLE_CHARS = 30;
|
|
17004
|
+
/**
|
|
17005
|
+
* Split `/note` input into `{title, body}`.
|
|
17006
|
+
*
|
|
17007
|
+
* 规则(刻意简单,写在 `/help` 的 hint 里):
|
|
17008
|
+
* · 第一行 = 标题,其余行 = 正文;
|
|
17009
|
+
* · 只有一行时,把这一行同时当标题(截到 30 字符)与正文 —— 记一句话不该被
|
|
17010
|
+
* "标题必填"挡回去,但也不该产生一个空正文的笔记。
|
|
17011
|
+
*
|
|
17012
|
+
* @returns `undefined` when the input carries no text at all.
|
|
17013
|
+
*/
|
|
17014
|
+
function parseNoteInput(rawInput) {
|
|
17015
|
+
const text = rawInput.replace(/\r\n/g, "\n").trim();
|
|
17016
|
+
if (text.length === 0) return void 0;
|
|
17017
|
+
const lines = text.split("\n");
|
|
17018
|
+
const firstLine = (lines[0] ?? "").trim();
|
|
17019
|
+
const rest = lines.slice(1).join("\n").trim();
|
|
17020
|
+
if (rest.length === 0) return {
|
|
17021
|
+
title: firstLine.length > DERIVED_TITLE_CHARS ? `${firstLine.slice(0, DERIVED_TITLE_CHARS)}…` : firstLine,
|
|
17022
|
+
body: firstLine
|
|
17023
|
+
};
|
|
17024
|
+
return {
|
|
17025
|
+
title: firstLine.length === 0 ? (rest.split("\n")[0] ?? "").slice(0, DERIVED_TITLE_CHARS) : firstLine,
|
|
17026
|
+
body: rest
|
|
17027
|
+
};
|
|
17028
|
+
}
|
|
17029
|
+
/**
|
|
17030
|
+
* Register `/note` on the host's command registry.
|
|
17031
|
+
*
|
|
17032
|
+
* Returns the registry's disposer. Never throws at registration time: a host
|
|
17033
|
+
* without a command registry simply gets no command.
|
|
17034
|
+
*/
|
|
17035
|
+
function registerNoteCommand(commands, deps) {
|
|
17036
|
+
return commands.register({
|
|
17037
|
+
name: NOTE_COMMAND_NAME,
|
|
17038
|
+
description: "把一条笔记写进当前会话的知识库(第一行当标题,其余行当正文)",
|
|
17039
|
+
input: { hint: "<标题>\n<正文>" },
|
|
17040
|
+
definitionId: "dsh-tiddlywiki/note",
|
|
17041
|
+
handler: async ({ agent, rawInput }) => {
|
|
17042
|
+
const parsed = parseNoteInput(typeof rawInput === "string" ? rawInput : "");
|
|
17043
|
+
if (parsed === void 0) return {
|
|
17044
|
+
kind: "error",
|
|
17045
|
+
text: "用法:/note <标题>\n<正文>(至少要有一行文字)"
|
|
17046
|
+
};
|
|
17047
|
+
const sessionId = typeof agent?.id === "string" && agent.id.length > 0 ? agent.id : void 0;
|
|
17048
|
+
const scope = deps.scope(sessionId);
|
|
17049
|
+
if (scope.client === void 0) return {
|
|
17050
|
+
kind: "error",
|
|
17051
|
+
text: `这条命令用不了:${scope.reason ?? "当前会话没有可用的知识库"}`
|
|
17052
|
+
};
|
|
17053
|
+
if (await scope.client.get(parsed.title) !== void 0) return {
|
|
17054
|
+
kind: "error",
|
|
17055
|
+
text: `「${parsed.title}」已经存在(${scope.label ?? "当前知识库"})。要改请用编辑器,或让 Agent 用 tiddlywiki_get + tiddlywiki_put 按并发令牌更新;换标题再加一次也可以。`
|
|
17056
|
+
};
|
|
17057
|
+
const mark = deps.workspaceMarkEnabled?.() === true && sessionId !== void 0 ? workspaceMarkFromCwd(deps.workspaceName?.(sessionId)) : void 0;
|
|
17058
|
+
const fields = {};
|
|
17059
|
+
const tags = ["inbox"];
|
|
17060
|
+
if (mark !== void 0) {
|
|
17061
|
+
tags.push(mark.tag);
|
|
17062
|
+
fields[WORKSPACE_FIELD] = mark.id;
|
|
17063
|
+
}
|
|
17064
|
+
const { tiddler } = buildWriteTiddler(parsed.title, parsed.body, {
|
|
17065
|
+
tags,
|
|
17066
|
+
fields,
|
|
17067
|
+
agentTag: false
|
|
17068
|
+
});
|
|
17069
|
+
await scope.client.put(tiddler);
|
|
17070
|
+
deps.autoCommit();
|
|
17071
|
+
const where = scope.label !== void 0 ? `(${scope.label})` : "";
|
|
17072
|
+
return {
|
|
17073
|
+
kind: "success",
|
|
17074
|
+
text: `已写入「${parsed.title}」${where}`
|
|
17075
|
+
};
|
|
17076
|
+
}
|
|
17077
|
+
});
|
|
17078
|
+
}
|
|
17079
|
+
//#endregion
|
|
16495
17080
|
//#region src/index-prompt.ts
|
|
16496
17081
|
/**
|
|
16497
17082
|
* dsh-tiddlywiki — host half: the system-prompt section wiring (v0.21.0).
|
|
@@ -16854,6 +17439,17 @@ function apply(ctx, rawConfig = {}) {
|
|
|
16854
17439
|
workspaceMarkEnabled: () => effectiveWorkspaceMark()
|
|
16855
17440
|
};
|
|
16856
17441
|
disposers.push(...registerTiddlywikiTools(ctx, toolsDeps));
|
|
17442
|
+
try {
|
|
17443
|
+
const commands = ctx.get("commands");
|
|
17444
|
+
if (commands !== void 0) disposers.push(registerNoteCommand(commands, {
|
|
17445
|
+
scope: toolScope,
|
|
17446
|
+
workspaceName: toolsDeps.workspaceName,
|
|
17447
|
+
workspaceMarkEnabled: toolsDeps.workspaceMarkEnabled,
|
|
17448
|
+
autoCommit: toolsDeps.autoCommit
|
|
17449
|
+
}));
|
|
17450
|
+
} catch (err) {
|
|
17451
|
+
console.warn("[dsh-tiddlywiki] /note 命令注册失败:", err);
|
|
17452
|
+
}
|
|
16857
17453
|
applyPrompt();
|
|
16858
17454
|
let disposed = false;
|
|
16859
17455
|
/**
|
|
@@ -16887,7 +17483,9 @@ function apply(ctx, rawConfig = {}) {
|
|
|
16887
17483
|
applyPrompt,
|
|
16888
17484
|
clipBridge,
|
|
16889
17485
|
effectiveBridge,
|
|
16890
|
-
defaultCurrentLocation: () => wikiViews.defaultCurrentLocation()
|
|
17486
|
+
defaultCurrentLocation: () => wikiViews.defaultCurrentLocation(),
|
|
17487
|
+
skills: () => ctx.get("skills"),
|
|
17488
|
+
pushDisposer: (dispose) => disposers.push(dispose)
|
|
16891
17489
|
});
|
|
16892
17490
|
/**
|
|
16893
17491
|
* The CONTROL FILE as the settings page edits it — deliberately NOT the
|
|
@@ -16988,6 +17586,6 @@ function apply(ctx, rawConfig = {}) {
|
|
|
16988
17586
|
}, "dsh-tiddlywiki: host teardown");
|
|
16989
17587
|
}
|
|
16990
17588
|
//#endregion
|
|
16991
|
-
export { AGENT_WRITTEN_TAG, ALL_ARTICLES_MARKER_TITLE, ALL_ARTICLES_TEXT, ALL_ARTICLES_TITLE, ANON_USERNAME, AutoCommitter, CLIP_BRIDGE_BOOKMARKLET, CLIP_BRIDGE_DEFAULT_PORT, CLIP_BRIDGE_DOC_TEXT, CLIP_BRIDGE_DOC_TITLE, CLIP_BRIDGE_DRAG_HREF, CLIP_BRIDGE_MARKER_TITLE, ClipBridge, ConfigPatchError, ConfigStore, ConfigUnreadableError, DEFAULT_NOTE_TYPE, DEFAULT_PROMPT_MODE, DEFAULT_WECHAT_ADAPTER, DEFAULT_WECHAT_COMMAND, DEFAULT_WIKI_ID, DEFAULT_WIKI_MODE, DOC_NOTE_TAG, DOC_NOTE_TEXT, DOC_NOTE_TITLE, DSH_DOCS_TAG, GitConflictStateError, GitFace, HOME_DEFAULT_TIDDLERS, HOME_INDEX_ITEMS, HOME_INDEX_MARKER_TITLE, HUMAN_EDITED_TAG, LOCATION_STATE_VERSION, MARKDOWN_PLUGIN, MASKED_SECRET, MENUBAR_THEME_MARKER_TITLE, MENUBAR_THEME_TEXT, MENUBAR_THEME_TIDDLER, MISSING_TYPE_FILTER, PATH_PREFIX, PROMPT_GOVERNANCE_BLOCKS, PROMPT_MODES, PROMPT_SECTION_NAME, PROMPT_SECTION_ORDER, READY_HARD_FACTOR, READY_POLL_MS, READY_SLOW_POLL_MS, READY_TIMEOUT_DEFAULT_MS, READY_TIMEOUT_MAX_MS, READY_TIMEOUT_MIN_MS, RENDER_BUNDLE_TEXT, RENDER_MARKER_TITLE, RENDER_PLUGIN_FILE, RENDER_PLUGIN_TITLE, RESERVED_WIKI_IDS, RepoCommitters, SEED_DEFS, SEED_MARKER_VERSION, SEND_TO_AGENT_BUNDLE_TEXT, SEND_TO_AGENT_MARKER_TITLE, SEND_TO_AGENT_PLUGIN_TITLE, SESSION_SCOPE_MAX_AGE_MS, SESSION_SCOPE_VERSION, SESSION_SUMMARY_PREFIX, SKILL_FILE_NAME, SPLIT_SKILL_DIR, SPLIT_SKILL_MARKER, STARTER_DOCS_ITEMS, STARTER_DOCS_MARKER_TITLE, TEXT_LIST_FILTER, TRASH_INDEX_TITLE, TRASH_PREFIX, TW_PROXY_PATH, TW_PROXY_PREFIX, TW_WEB_HOST_DEFAULT, TW_WEB_HOST_TIDDLER, TiddlyWebClient, TrashIndexUnavailableError, UI_STYLES_MARKER_TITLE, UI_STYLE_ITEMS, WECHAT_ADAPTERS, WECHAT_ADAPTER_FILES, WECHAT_ADAPTER_MARKER, WECHAT_DOCS_MARKER_TITLE, WECHAT_DOCS_TEXT, WECHAT_DOCS_TITLE, WECHAT_PUBLISH_BUNDLE_TEXT, WECHAT_PUBLISH_MARKER_TITLE, WECHAT_PUBLISH_PLUGIN_TITLE, WIKI_ICON_NAMES, WIKI_MODES, WIKI_REGISTRY_VERSION, WORKSPACE_FIELD, WORKSPACE_TAG_PREFIX, WechatPublishRunner, WikiFarm, WikiInstance, WikiServer, WriteConflictError, apply, applyWikiAction, assertNoConflict, assertPublicImageUrl, awaitReady, buildBinaryTiddler, buildClipTiddler, buildImageNoteTiddler, buildPromptText, buildPublishInvocation, buildVersionInvocation, buildWriteTiddler, bundledCatalog, capOutput, checkAllSeeds, checkWechatReady, cleanTiddler, clearLocationState, createGitLayer, createMutationLock, deepMerge, defaultAdaptersDir, defaultEntry, defaultLocationStateFile, defaultRegistryFile, defaultSessionScopeFile, defaultSkillRoot, defaultWechatJobDir, defineTool, deriveWikiId, describeConflict, describePrompt, describeUnreadableConfig, docNoteText, downloadClipImage, drainThenStop, dshHomePath, ensureLanguage, ensurePlugin, ensureTiddlerTimestamps, entryLocation, entryPath, escapeInline, escapePromptBraces, expandEnvPath, findEntry, findPathConflicts, flattenTiddlerFields, flushPendingWrites, formatTiddlerDate, hashText, hostAllowed, imageExtensionForMime, inject, insertIntoSection, installSplitSkill, interpretPublishOutcome, isBinaryType, isInsidePath, isJunkTag, isPrivateAddress, isSafeCliValue, isSafeDsn, isSafeSessionId, isSafeUrl, listWikiCandidates, locationPath, maskConfigSecrets, name, needsRestartAfterSeeds, normalizeConfigPatch, normalizeEntry, normalizeFieldsArg, normalizeLocation, normalizePromptMode, normalizePromptPreview, normalizeReadyTimeoutMs, normalizeThemes, normalizeWechatConfig, normalizeWikiIcon, normalizeWikiId, normalizeWorkspaceName, openInTwEditor, parseClipPayload, parseSeedMarker, parseTiddlerDate, pathComparisonKey, pickImageMime, pinLanguageTiddler, proxyBaseFor, pruneScopes, readActiveThemeName, readBundledSkillText, readLocationState, readRegistry, readSeedMarker, readSessionScopes, readWikiInfo, readyHardTimeoutMs, registerAdminRoutes, registerRoutes, registerTiddlywikiTools, removeSeedById, removeWiki, resolveAgentScope, resolveClipTitle, resolveNodeExecutable, resolveTwRoot, resolveWikiRoot, runAllSeeds, runSeedById, sanitizeTwFragment, scanAdapterDir, scopeBanner, seedAllArticles, seedClipBridge, seedDocNote, seedHomeIndex, seedMenubarTheme, seedRenderRoute, seedSendToAgent, seedStarterDocs, seedUiStyles, seedWechatDocs, seedWechatPublish, setSessionScope, singleEntryRegistry, stoppedWikiFromRequest, stoppedWikiMessage, stripMaskedSecrets, switchWiki, tailOf, targetRuntimeFor, tiddlywikiToolSummary, toIsoDateString, toolSignatureLines, unseedClipBridge, unseedWechatDocs, unseedWechatPublish, upsertWiki, validateRegistry, waitForFileWrite, wikiIdFromRequest, withScopeBanner, workspaceMarkFromCwd, workspaceNameFromCwd, workspaceTagName, writeLocationState, writeRegistry, writeSeedMarker, writeSessionScopes, writeSessionSummary, writeWikiInfo };
|
|
17589
|
+
export { AGENT_WRITTEN_TAG, ALL_ARTICLES_MARKER_TITLE, ALL_ARTICLES_TEXT, ALL_ARTICLES_TITLE, ANON_USERNAME, AutoCommitter, CLIP_BRIDGE_BOOKMARKLET, CLIP_BRIDGE_DEFAULT_PORT, CLIP_BRIDGE_DOC_TEXT, CLIP_BRIDGE_DOC_TITLE, CLIP_BRIDGE_DRAG_HREF, CLIP_BRIDGE_MARKER_TITLE, ClipBridge, ConfigPatchError, ConfigStore, ConfigUnreadableError, DEFAULT_NOTE_TYPE, DEFAULT_PROMPT_MODE, DEFAULT_WECHAT_ADAPTER, DEFAULT_WECHAT_COMMAND, DEFAULT_WIKI_ID, DEFAULT_WIKI_MODE, DOC_NOTE_TAG, DOC_NOTE_TEXT, DOC_NOTE_TITLE, DSH_DOCS_TAG, GitConflictStateError, GitFace, HOME_DEFAULT_TIDDLERS, HOME_INDEX_ITEMS, HOME_INDEX_MARKER_TITLE, HUMAN_EDITED_TAG, LOCATION_STATE_VERSION, MARKDOWN_PLUGIN, MASKED_SECRET, MENUBAR_THEME_MARKER_TITLE, MENUBAR_THEME_TEXT, MENUBAR_THEME_TIDDLER, MISSING_TYPE_FILTER, NOTE_COMMAND_NAME, PATH_PREFIX, PROMPT_GOVERNANCE_BLOCKS, PROMPT_MODES, PROMPT_SECTION_NAME, PROMPT_SECTION_ORDER, READY_HARD_FACTOR, READY_POLL_MS, READY_SLOW_POLL_MS, READY_TIMEOUT_DEFAULT_MS, READY_TIMEOUT_MAX_MS, READY_TIMEOUT_MIN_MS, RENDER_BUNDLE_TEXT, RENDER_MARKER_TITLE, RENDER_PLUGIN_FILE, RENDER_PLUGIN_TITLE, RESERVED_WIKI_IDS, RepoCommitters, SEED_DEFS, SEED_MARKER_VERSION, SEND_TO_AGENT_BUNDLE_TEXT, SEND_TO_AGENT_MARKER_TITLE, SEND_TO_AGENT_PLUGIN_TITLE, SESSION_SCOPE_MAX_AGE_MS, SESSION_SCOPE_VERSION, SESSION_SUMMARY_PREFIX, SKILL_FILE_NAME, SPLIT_SKILL_DIR, SPLIT_SKILL_MARKER, STARTER_DOCS_ITEMS, STARTER_DOCS_MARKER_TITLE, TEXT_LIST_FILTER, TRASH_INDEX_TITLE, TRASH_PREFIX, TW_PROXY_PATH, TW_PROXY_PREFIX, TW_WEB_HOST_DEFAULT, TW_WEB_HOST_TIDDLER, TiddlyWebClient, TrashIndexUnavailableError, UI_STYLES_MARKER_TITLE, UI_STYLE_ITEMS, WECHAT_ADAPTERS, WECHAT_ADAPTER_FILES, WECHAT_ADAPTER_MARKER, WECHAT_DOCS_MARKER_TITLE, WECHAT_DOCS_TEXT, WECHAT_DOCS_TITLE, WECHAT_PUBLISH_BUNDLE_TEXT, WECHAT_PUBLISH_MARKER_TITLE, WECHAT_PUBLISH_PLUGIN_TITLE, WIKI_ICON_NAMES, WIKI_MODES, WIKI_REGISTRY_VERSION, WORKSPACE_FIELD, WORKSPACE_TAG_PREFIX, WechatPublishRunner, WikiFarm, WikiInstance, WikiServer, WriteConflictError, apply, applyWikiAction, assertNoConflict, assertPublicImageUrl, awaitReady, buildBinaryTiddler, buildClipTiddler, buildImageNoteTiddler, buildPromptText, buildPublishInvocation, buildVersionInvocation, buildWriteTiddler, bundledCatalog, capOutput, checkAllSeeds, checkWechatReady, cleanTiddler, clearLocationState, createGitLayer, createMutationLock, deepMerge, defaultAdaptersDir, defaultEntry, defaultLocationStateFile, defaultRegistryFile, defaultSessionScopeFile, defaultSkillRoot, defaultWechatJobDir, defineTool, deriveWikiId, describeConflict, describePrompt, describeUnreadableConfig, docNoteText, downloadClipImage, drainThenStop, dshHomePath, ensureLanguage, ensurePlugin, ensureTiddlerTimestamps, entryLocation, entryPath, escapeInline, escapePromptBraces, expandEnvPath, findEntry, findPathConflicts, flattenTiddlerFields, flushPendingWrites, formatTiddlerDate, hashText, hostAllowed, imageExtensionForMime, inject, insertIntoSection, installSplitSkill, interpretPublishOutcome, isBinaryType, isInsidePath, isJunkTag, isPrivateAddress, isSafeCliValue, isSafeDsn, isSafeSessionId, isSafeUrl, listWikiCandidates, locationPath, maskConfigSecrets, name, needsRestartAfterSeeds, normalizeConfigPatch, normalizeEntry, normalizeFieldsArg, normalizeLocation, normalizePromptMode, normalizePromptPreview, normalizeReadyTimeoutMs, normalizeThemes, normalizeWechatConfig, normalizeWikiIcon, normalizeWikiId, normalizeWorkspaceName, openInTwEditor, parseClipPayload, parseNoteInput, parseSeedMarker, parseSkillText, parseTiddlerDate, pathComparisonKey, pickImageMime, pinLanguageTiddler, proxyBaseFor, pruneScopes, readActiveThemeName, readBundledSkillText, readLocationState, readRegistry, readSeedMarker, readSessionScopes, readWikiInfo, readyHardTimeoutMs, registerAdminRoutes, registerNoteCommand, registerRoutes, registerSplitSkill, registerTiddlywikiTools, removeSeedById, removeWiki, resolveAgentScope, resolveClipTitle, resolveNodeExecutable, resolveTwRoot, resolveWikiRoot, runAllSeeds, runSeedById, sanitizeTwFragment, scanAdapterDir, scopeBanner, seedAllArticles, seedClipBridge, seedDocNote, seedHomeIndex, seedMenubarTheme, seedRenderRoute, seedSendToAgent, seedStarterDocs, seedUiStyles, seedWechatDocs, seedWechatPublish, setSessionScope, singleEntryRegistry, stoppedWikiFromRequest, stoppedWikiMessage, stripMaskedSecrets, switchWiki, tailOf, targetRuntimeFor, tiddlywikiToolSummary, toIsoDateString, toolSignatureLines, unseedClipBridge, unseedWechatDocs, unseedWechatPublish, upsertWiki, validateRegistry, waitForFileWrite, wikiIdFromRequest, withScopeBanner, workspaceMarkFromCwd, workspaceNameFromCwd, workspaceTagName, writeLocationState, writeRegistry, writeSeedMarker, writeSessionScopes, writeSessionSummary, writeWikiInfo };
|
|
16992
17590
|
|
|
16993
17591
|
//# sourceMappingURL=index.js.map
|