dsh-prompt-pool 1.2.0 → 1.3.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 +2 -1
- package/client.js +357 -61
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Prompt pool · 提示池
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/dsh-prompt-pool)
|
|
3
|
+
[](https://www.npmjs.com/package/dsh-prompt-pool) [](https://dshfind.com/en/plugins/Ganttfly/dsh-prompt-pool?ref=badge)
|
|
4
4
|
|
|
5
5
|
A staging pool for prompts inside DeepSeek Harness: park a draft without sending it, arrange a playlist
|
|
6
6
|
of prompt items, and release the batch into the composer's send queue in order.
|
|
@@ -8,6 +8,7 @@ of prompt items, and release the batch into the composer's send queue in order.
|
|
|
8
8
|

|
|
9
9
|
|
|
10
10
|
- Composer trigger beside the send controls (accent + count while something is queued)
|
|
11
|
+
- Starter prompts follow the host language; Settings can reset them in the current interface language, keeping edits as ordinary items
|
|
11
12
|
- Composer panel with search, group tabs, row actions and a send-queue card
|
|
12
13
|
- Right-click on selected conversation text to copy it or save it into a group (the last destination leads the menu)
|
|
13
14
|
- Full-height page in the right sidebar (native tab on DSH 0.2+, `dsh-better-sidebar` fallback)
|
package/client.js
CHANGED
|
@@ -19,7 +19,7 @@ window.__ModuleLoader__.load({
|
|
|
19
19
|
const NATIVE_TAB_ID = 'dsh-prompt-pool';
|
|
20
20
|
const NATIVE_TAB_KIND = 'prompt-pool';
|
|
21
21
|
/** Shown in the settings about card; keep in step with plugin/package.json. */
|
|
22
|
-
const PLUGIN_VERSION = '1.
|
|
22
|
+
const PLUGIN_VERSION = '1.3.0';
|
|
23
23
|
const PLUGIN_AUTHOR = 'GanttShen';
|
|
24
24
|
/** Replace once the public repository exists; the row hides while it is empty. */
|
|
25
25
|
const PLUGIN_REPO = 'https://github.com/Ganttfly/dsh-prompt-pool';
|
|
@@ -134,6 +134,17 @@ window.__ModuleLoader__.load({
|
|
|
134
134
|
'settings.keepInsertHint': '关闭后,插入成功的条目会从池子移出;提示条上的「撤销」可以恢复。',
|
|
135
135
|
'settings.keepQueue': '加入待发送队列后,仍旧保留在池子中',
|
|
136
136
|
'settings.keepQueueHint': '关闭后,条目一加入队列就从池子移出;队列里的那一条不受影响。',
|
|
137
|
+
'settings.seedCard': '内置提示词',
|
|
138
|
+
'settings.seedHint': '当前有 {builtin} 条内置提示词,其中 {edited} 条已编辑。重置只影响内置条目,自定义条目和队列不受影响。',
|
|
139
|
+
'settings.seedLanguageZh': '中文',
|
|
140
|
+
'settings.seedLanguageEn': 'English',
|
|
141
|
+
'settings.seedNote': '将按当前界面语言「{language}」重置。',
|
|
142
|
+
'settings.seedKeepEdited': '保留已编辑的内置条目',
|
|
143
|
+
'settings.seedKeepEditedHint': '勾选后,编辑过的内置条目会转成普通条目保留;未勾选则一起删除。',
|
|
144
|
+
'settings.seedResetButton': '重置内置提示词',
|
|
145
|
+
'settings.seedResetTitle': '重置内置提示词?',
|
|
146
|
+
'settings.seedResetConfirm': '将移除 {removed} 条内置提示词,保留 {kept} 条编辑为普通条目,并按「{language}」重新写入 {added} 条。',
|
|
147
|
+
'settings.seedResetDone': '已重置:移除 {removed} 条,保留 {kept} 条编辑,写入 {added} 条。',
|
|
137
148
|
'settings.about': '插件信息',
|
|
138
149
|
'settings.aboutAuthor': '作者',
|
|
139
150
|
'settings.aboutRepo': '仓库',
|
|
@@ -300,6 +311,17 @@ window.__ModuleLoader__.load({
|
|
|
300
311
|
'settings.keepInsertHint': 'Turned off, an inserted item leaves the pool; the toast offers an undo.',
|
|
301
312
|
'settings.keepQueue': 'Keep it in the pool after adding it to the send queue',
|
|
302
313
|
'settings.keepQueueHint': 'Turned off, the item leaves the pool as soon as it is queued; the queued copy stays.',
|
|
314
|
+
'settings.seedCard': 'Built-in prompts',
|
|
315
|
+
'settings.seedHint': 'The pool has {builtin} built-in prompts, {edited} of them edited. Resetting only touches built-ins; custom items and the queue are left alone.',
|
|
316
|
+
'settings.seedLanguageZh': 'Chinese',
|
|
317
|
+
'settings.seedLanguageEn': 'English',
|
|
318
|
+
'settings.seedNote': 'Resets in the current interface language: {language}.',
|
|
319
|
+
'settings.seedKeepEdited': 'Keep edited built-in items',
|
|
320
|
+
'settings.seedKeepEditedHint': 'Checked, edited built-ins become ordinary items; unchecked, they are removed too.',
|
|
321
|
+
'settings.seedResetButton': 'Reset built-in prompts',
|
|
322
|
+
'settings.seedResetTitle': 'Reset built-in prompts?',
|
|
323
|
+
'settings.seedResetConfirm': 'Remove {removed} built-in prompts, keep {kept} edited as ordinary items, and add {added} in {language}.',
|
|
324
|
+
'settings.seedResetDone': 'Reset: {removed} removed, {kept} edits kept, {added} added.',
|
|
303
325
|
'settings.about': 'Plugin info',
|
|
304
326
|
'settings.aboutAuthor': 'Author',
|
|
305
327
|
'settings.aboutRepo': 'Repository',
|
|
@@ -829,6 +851,8 @@ window.__ModuleLoader__.load({
|
|
|
829
851
|
images,
|
|
830
852
|
createdAt: Number.isFinite(raw.createdAt) ? raw.createdAt : now,
|
|
831
853
|
updatedAt: Number.isFinite(raw.updatedAt) ? raw.updatedAt : now,
|
|
854
|
+
...(raw.seed === true ? { seed: true } : {}),
|
|
855
|
+
...(raw.locale === 'zh' || raw.locale === 'en' ? { locale: raw.locale } : {}),
|
|
832
856
|
};
|
|
833
857
|
}
|
|
834
858
|
|
|
@@ -1163,6 +1187,23 @@ window.__ModuleLoader__.load({
|
|
|
1163
1187
|
});
|
|
1164
1188
|
}
|
|
1165
1189
|
|
|
1190
|
+
/** Confirmation before the built-in set is replaced with a fresh language batch. */
|
|
1191
|
+
function SeedResetConfirm(props) {
|
|
1192
|
+
return h(ConfirmModal, {
|
|
1193
|
+
label: translate('settings.seedResetTitle'),
|
|
1194
|
+
text: translate('settings.seedResetConfirm', {
|
|
1195
|
+
removed: props.removed,
|
|
1196
|
+
kept: props.kept,
|
|
1197
|
+
added: props.added,
|
|
1198
|
+
language: props.language,
|
|
1199
|
+
}),
|
|
1200
|
+
cancelText: translate('row.cancel'),
|
|
1201
|
+
confirmText: translate('settings.seedResetButton'),
|
|
1202
|
+
onCancel: props.onCancel,
|
|
1203
|
+
onConfirm: props.onConfirm,
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1166
1207
|
/** The workspace rail, or just its items when there is nothing to switch between. */
|
|
1167
1208
|
function renderWorkspacePanes(props) {
|
|
1168
1209
|
const rail = props.rail || [];
|
|
@@ -1258,97 +1299,176 @@ window.__ModuleLoader__.load({
|
|
|
1258
1299
|
}
|
|
1259
1300
|
|
|
1260
1301
|
function emptyPool() {
|
|
1261
|
-
return { version: POOL_VERSION, categories: [], items: [], tray: [], settings: normalizeSettings(undefined), seeded:
|
|
1302
|
+
return { version: POOL_VERSION, categories: [], items: [], tray: [], settings: normalizeSettings(undefined), seeded: SEED_LEVEL };
|
|
1262
1303
|
}
|
|
1263
1304
|
|
|
1264
1305
|
/**
|
|
1265
1306
|
* First-run content: five behaviour switches that stay valid as one-liners.
|
|
1266
|
-
* They land in the 常用 group and stay ordinary, deletable items.
|
|
1307
|
+
* They land in the 常用 / Frequent group and stay ordinary, deletable items.
|
|
1308
|
+
* The locale is fixed at first run; switching languages later does not rewrite
|
|
1309
|
+
* items the user may already have edited.
|
|
1267
1310
|
*/
|
|
1268
|
-
const SEED_PROMPTS =
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1311
|
+
const SEED_PROMPTS = {
|
|
1312
|
+
zh: [
|
|
1313
|
+
['seed:plan-first', '先给方案', '先列改动清单:要改哪些文件、每处改什么、怎么验证。等我确认后再动手。'],
|
|
1314
|
+
['seed:scope-guard', '不动无关代码', '只改与目标直接相关的行;看到别的问题只记录,不顺手修。'],
|
|
1315
|
+
[
|
|
1316
|
+
'seed:pre-delivery',
|
|
1317
|
+
'交付前自检',
|
|
1318
|
+
'交付前给一条最小验证(命令或测试),并回答三件事:最可能出问题的地方、怎么回滚、哪些假设我没验证过。',
|
|
1319
|
+
],
|
|
1320
|
+
['seed:stop-restate', '停下重述', '停一下:重述我的原始要求和当前实际在做的事,指出偏差,再决定继续还是回退。'],
|
|
1321
|
+
['seed:commands', '给命令不给描述', '需要我操作时直接给可粘贴的命令、路径或代码块。'],
|
|
1322
|
+
],
|
|
1323
|
+
en: [
|
|
1324
|
+
[
|
|
1325
|
+
'seed:plan-first',
|
|
1326
|
+
'Plan first',
|
|
1327
|
+
'List the changes before touching code: which files, what changes in each, and how you will verify. Wait for my go-ahead before editing.',
|
|
1328
|
+
],
|
|
1329
|
+
[
|
|
1330
|
+
'seed:scope-guard',
|
|
1331
|
+
'Stay in scope',
|
|
1332
|
+
'Change only the lines directly related to the goal. If you spot other issues, note them instead of fixing them.',
|
|
1333
|
+
],
|
|
1334
|
+
[
|
|
1335
|
+
'seed:pre-delivery',
|
|
1336
|
+
'Check before delivery',
|
|
1337
|
+
'Before delivering, give one minimal verification (a command or test) and answer three things: what is most likely to break, how to roll back, and which assumptions I have not verified.',
|
|
1338
|
+
],
|
|
1339
|
+
[
|
|
1340
|
+
'seed:stop-restate',
|
|
1341
|
+
'Stop and restate',
|
|
1342
|
+
'Pause: restate my original request and what you are actually doing, call out the drift, then decide whether to continue or roll back.',
|
|
1343
|
+
],
|
|
1344
|
+
[
|
|
1345
|
+
'seed:commands',
|
|
1346
|
+
'Commands, not prose',
|
|
1347
|
+
'When I need to act, give me commands, paths, or code blocks I can paste directly.',
|
|
1348
|
+
],
|
|
1275
1349
|
],
|
|
1276
|
-
|
|
1277
|
-
['seed:commands', '给命令不给描述', '需要我操作时直接给可粘贴的命令、路径或代码块。'],
|
|
1278
|
-
];
|
|
1350
|
+
};
|
|
1279
1351
|
|
|
1280
1352
|
/** Templates: each one has a hole to fill and a shape the answer must take. */
|
|
1281
|
-
const SEED_TEMPLATES =
|
|
1282
|
-
[
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1353
|
+
const SEED_TEMPLATES = {
|
|
1354
|
+
zh: [
|
|
1355
|
+
[
|
|
1356
|
+
'seed:review',
|
|
1357
|
+
'代码审查',
|
|
1358
|
+
'审阅 {{贴 diff 或文件}}:先用一句话给结论(能否合入、卡在哪);再按「阻塞 / 建议 / 可选」分级列问题,每条给行号、触发条件、修法。不要重述代码在做什么。',
|
|
1359
|
+
],
|
|
1360
|
+
[
|
|
1361
|
+
'seed:options',
|
|
1362
|
+
'方案对比',
|
|
1363
|
+
'针对 {{决策点}} 给 2–3 个候选方案,用表格对比:改动范围、风险、回滚难度、后续维护成本;最后给推荐项和一句理由。',
|
|
1364
|
+
],
|
|
1365
|
+
[
|
|
1366
|
+
'seed:acceptance',
|
|
1367
|
+
'验收清单',
|
|
1368
|
+
'为 {{功能名}} 输出可勾选清单,按「正常路径 / 边界 / 失败恢复」分组;每条写成一个可观察的结果,能被执行或验证。',
|
|
1369
|
+
],
|
|
1370
|
+
[
|
|
1371
|
+
'seed:changelog',
|
|
1372
|
+
'变更说明',
|
|
1373
|
+
'按 Keep a Changelog 写 {{版本号}} 的变更说明:动词开头、一条一个变更、修复与新增不混在同一条;破坏性变更单独列一节。',
|
|
1374
|
+
],
|
|
1375
|
+
[
|
|
1376
|
+
'seed:explain',
|
|
1377
|
+
'解释这段代码',
|
|
1378
|
+
'解释 {{代码或模块}}:先用一句话说它解决什么问题,再说依赖的关键不变量、最容易踩的坑、以及改动时不能破坏的东西。',
|
|
1379
|
+
],
|
|
1296
1380
|
],
|
|
1297
|
-
[
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1381
|
+
en: [
|
|
1382
|
+
[
|
|
1383
|
+
'seed:review',
|
|
1384
|
+
'Code review',
|
|
1385
|
+
'Review {{paste a diff or file}}: open with a one-sentence verdict (mergeable, and where it is blocked), then list issues as Blocking / Suggestion / Optional, each with line number, trigger, and fix. Do not restate what the code does.',
|
|
1386
|
+
],
|
|
1387
|
+
[
|
|
1388
|
+
'seed:options',
|
|
1389
|
+
'Compare options',
|
|
1390
|
+
'For {{decision point}}, give 2–3 candidates in a table comparing change scope, risk, rollback difficulty, and maintenance cost. End with the recommended option and one reason.',
|
|
1391
|
+
],
|
|
1392
|
+
[
|
|
1393
|
+
'seed:acceptance',
|
|
1394
|
+
'Acceptance checklist',
|
|
1395
|
+
'For {{feature name}}, output a checkable list grouped by Happy path / Edge cases / Failure recovery; each line must be an observable result that can be executed or verified.',
|
|
1396
|
+
],
|
|
1397
|
+
[
|
|
1398
|
+
'seed:changelog',
|
|
1399
|
+
'Changelog entry',
|
|
1400
|
+
'Write the {{version}} entry in Keep a Changelog style: start each line with a verb, one change per line, and do not mix fixes with additions. Give breaking changes their own section.',
|
|
1401
|
+
],
|
|
1402
|
+
[
|
|
1403
|
+
'seed:explain',
|
|
1404
|
+
'Explain this code',
|
|
1405
|
+
'Explain {{code or module}}: one sentence on the problem it solves, then the key invariants it relies on, the most likely pitfalls, and what must not break when changing it.',
|
|
1406
|
+
],
|
|
1301
1407
|
],
|
|
1302
|
-
|
|
1303
|
-
'seed:explain',
|
|
1304
|
-
'解释这段代码',
|
|
1305
|
-
'解释 {{代码或模块}}:先用一句话说它解决什么问题,再说依赖的关键不变量、最容易踩的坑、以及改动时不能破坏的东西。',
|
|
1306
|
-
],
|
|
1307
|
-
];
|
|
1408
|
+
};
|
|
1308
1409
|
|
|
1309
1410
|
/** A build bumps this and adds one batch; older pools receive only the new batch. */
|
|
1310
1411
|
/** Bump when the stored item shape changes: older pools are reseeded, not migrated. */
|
|
1311
1412
|
const POOL_VERSION = 2;
|
|
1312
1413
|
|
|
1313
1414
|
const SEED_LEVEL = 2;
|
|
1415
|
+
const SEED_TOTAL = SEED_PROMPTS.en.length + SEED_TEMPLATES.en.length;
|
|
1314
1416
|
|
|
1315
|
-
function seedItem([id, title, body], group, now) {
|
|
1316
|
-
return { id, group, title, body, createdAt: now, updatedAt: now };
|
|
1417
|
+
function seedItem([id, title, body], group, now, locale) {
|
|
1418
|
+
return { id, group, title, body, seed: true, locale, createdAt: now, updatedAt: now };
|
|
1317
1419
|
}
|
|
1318
1420
|
|
|
1319
|
-
|
|
1421
|
+
/**
|
|
1422
|
+
* Every built-in id knows both language variants. The locale marker on a
|
|
1423
|
+
* saved item plus an exact title/body match is what proves it is still the
|
|
1424
|
+
* untouched built-in rather than a user edit.
|
|
1425
|
+
*/
|
|
1426
|
+
const SEED_CATALOG = new Map();
|
|
1427
|
+
function registerSeedBatch(entries, locale, level, group) {
|
|
1428
|
+
for (const [id, title, body] of entries) {
|
|
1429
|
+
const record = SEED_CATALOG.get(id) || { level, group, content: {} };
|
|
1430
|
+
record.content[locale] = { title, body };
|
|
1431
|
+
SEED_CATALOG.set(id, record);
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
registerSeedBatch(SEED_PROMPTS.zh, 'zh', 1, BUILTIN_GROUP.oftenuse);
|
|
1435
|
+
registerSeedBatch(SEED_PROMPTS.en, 'en', 1, BUILTIN_GROUP.oftenuse);
|
|
1436
|
+
registerSeedBatch(SEED_TEMPLATES.zh, 'zh', 2, BUILTIN_GROUP.template);
|
|
1437
|
+
registerSeedBatch(SEED_TEMPLATES.en, 'en', 2, BUILTIN_GROUP.template);
|
|
1438
|
+
|
|
1439
|
+
function seedsAbove(level, now, locale) {
|
|
1440
|
+
const language = locale === 'zh' ? 'zh' : 'en';
|
|
1320
1441
|
const batches = [
|
|
1321
|
-
{ level: 1, items: SEED_PROMPTS.map((entry) => seedItem(entry, BUILTIN_GROUP.oftenuse, now)) },
|
|
1322
|
-
{ level: 2, items: SEED_TEMPLATES.map((entry) => seedItem(entry, BUILTIN_GROUP.template, now)) },
|
|
1442
|
+
{ level: 1, items: SEED_PROMPTS[language].map((entry) => seedItem(entry, BUILTIN_GROUP.oftenuse, now, language)) },
|
|
1443
|
+
{ level: 2, items: SEED_TEMPLATES[language].map((entry) => seedItem(entry, BUILTIN_GROUP.template, now, language)) },
|
|
1323
1444
|
];
|
|
1324
1445
|
return batches.filter((batch) => batch.level > level).reduce((list, batch) => list.concat(batch.items), []);
|
|
1325
1446
|
}
|
|
1326
1447
|
|
|
1327
|
-
|
|
1448
|
+
/**
|
|
1449
|
+
* An untitled empty pool is not the same as a deliberate empty one: it waits
|
|
1450
|
+
* for apply() so the first-run seeds can follow the host locale.
|
|
1451
|
+
*/
|
|
1452
|
+
function pendingPool() {
|
|
1328
1453
|
return {
|
|
1329
1454
|
version: POOL_VERSION,
|
|
1330
1455
|
categories: [],
|
|
1331
|
-
items:
|
|
1456
|
+
items: [],
|
|
1332
1457
|
tray: [],
|
|
1333
1458
|
settings: normalizeSettings(undefined),
|
|
1334
|
-
seeded:
|
|
1459
|
+
seeded: 0,
|
|
1335
1460
|
};
|
|
1336
1461
|
}
|
|
1337
1462
|
|
|
1338
|
-
function seedItems(existing, level) {
|
|
1463
|
+
function seedItems(existing, level, locale) {
|
|
1339
1464
|
const taken = new Set(existing.map((item) => item.id));
|
|
1340
|
-
return seedsAbove(level, Date.now()).filter((item) => !taken.has(item.id));
|
|
1465
|
+
return seedsAbove(level, Date.now(), locale).filter((item) => !taken.has(item.id));
|
|
1341
1466
|
}
|
|
1342
1467
|
|
|
1343
1468
|
function loadPool() {
|
|
1344
1469
|
try {
|
|
1345
1470
|
const raw = localStorage.getItem(STORAGE_KEY);
|
|
1346
|
-
if (!raw)
|
|
1347
|
-
// Brand-new install only: an existing (even empty) pool is never reseeded.
|
|
1348
|
-
const seeded = seededPool();
|
|
1349
|
-
persist(seeded);
|
|
1350
|
-
return seeded;
|
|
1351
|
-
}
|
|
1471
|
+
if (!raw) return pendingPool();
|
|
1352
1472
|
const parsed = JSON.parse(raw);
|
|
1353
1473
|
const storedVersion = parsed && typeof parsed.version === 'number' ? parsed.version : 1;
|
|
1354
1474
|
if (storedVersion < POOL_VERSION) {
|
|
@@ -1360,12 +1480,8 @@ window.__ModuleLoader__.load({
|
|
|
1360
1480
|
/* the backup is best effort; the pool itself still loads */
|
|
1361
1481
|
}
|
|
1362
1482
|
}
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
if (storedVersion >= POOL_VERSION && level >= SEED_LEVEL) return pool;
|
|
1366
|
-
const migrated = level >= SEED_LEVEL ? pool : { ...pool, items: [...pool.items, ...seedItems(pool.items, level)], seeded: SEED_LEVEL };
|
|
1367
|
-
persist(migrated);
|
|
1368
|
-
return migrated;
|
|
1483
|
+
// Seed batches are added in apply(), where the host locale is known.
|
|
1484
|
+
return normalizePool(parsed);
|
|
1369
1485
|
} catch (_error) {
|
|
1370
1486
|
return emptyPool();
|
|
1371
1487
|
}
|
|
@@ -1634,6 +1750,76 @@ window.__ModuleLoader__.load({
|
|
|
1634
1750
|
}
|
|
1635
1751
|
}
|
|
1636
1752
|
|
|
1753
|
+
/**
|
|
1754
|
+
* Screenshot/test override: setting this key to 'en' or 'zh' makes the
|
|
1755
|
+
* plugin's own copy and its new seed batches use that language without
|
|
1756
|
+
* changing the host UI. Unset in normal use.
|
|
1757
|
+
*/
|
|
1758
|
+
const PREVIEW_LOCALE_KEY = 'dsh.prompt-pool.preview-locale';
|
|
1759
|
+
|
|
1760
|
+
function previewLocaleId() {
|
|
1761
|
+
try {
|
|
1762
|
+
const value = localStorage.getItem(PREVIEW_LOCALE_KEY);
|
|
1763
|
+
return value === 'zh' || value === 'en' ? value : null;
|
|
1764
|
+
} catch (_error) {
|
|
1765
|
+
return null;
|
|
1766
|
+
}
|
|
1767
|
+
}
|
|
1768
|
+
|
|
1769
|
+
/** The host locale at first run; unsupported locales fall back to English seeds. */
|
|
1770
|
+
function activeLocaleId() {
|
|
1771
|
+
const preview = previewLocaleId();
|
|
1772
|
+
if (preview) return preview;
|
|
1773
|
+
try {
|
|
1774
|
+
const snapshot =
|
|
1775
|
+
localeCtx && typeof localeCtx.getLocale === 'function'
|
|
1776
|
+
? localeCtx.getLocale()
|
|
1777
|
+
: localeCtx && typeof localeCtx.getSnapshot === 'function'
|
|
1778
|
+
? localeCtx.getSnapshot()
|
|
1779
|
+
: null;
|
|
1780
|
+
const active = snapshot && (snapshot.active || snapshot.id || snapshot.locale || snapshot.language);
|
|
1781
|
+
if (typeof active === 'string' && active) return active.toLowerCase().startsWith('zh') ? 'zh' : 'en';
|
|
1782
|
+
} catch (_error) {
|
|
1783
|
+
/* a locale service that cannot answer still gets the document fallback */
|
|
1784
|
+
}
|
|
1785
|
+
try {
|
|
1786
|
+
const htmlLang = typeof document !== 'undefined' && document.documentElement ? document.documentElement.lang : '';
|
|
1787
|
+
if (typeof htmlLang === 'string' && htmlLang) return htmlLang.toLowerCase().startsWith('zh') ? 'zh' : 'en';
|
|
1788
|
+
} catch (_error) {
|
|
1789
|
+
/* no document in a non-browser host */
|
|
1790
|
+
}
|
|
1791
|
+
return 'en';
|
|
1792
|
+
}
|
|
1793
|
+
|
|
1794
|
+
/**
|
|
1795
|
+
* Add the missing seed batches now that apply() knows the host locale. A
|
|
1796
|
+
* brand-new pool is seeded only here; an existing pool keeps every saved
|
|
1797
|
+
* item, and its ids prevent a batch from being duplicated.
|
|
1798
|
+
*/
|
|
1799
|
+
function seedPoolIfNeeded() {
|
|
1800
|
+
const current = pool.get();
|
|
1801
|
+
const level = current.seeded === true ? SEED_LEVEL : Number(current.seeded) || 0;
|
|
1802
|
+
if (level >= SEED_LEVEL) return;
|
|
1803
|
+
const missing = seedItems(current.items, level, activeLocaleId());
|
|
1804
|
+
const next = { ...current, items: [...current.items, ...missing], seeded: SEED_LEVEL };
|
|
1805
|
+
persist(next);
|
|
1806
|
+
pool.set(next);
|
|
1807
|
+
}
|
|
1808
|
+
|
|
1809
|
+
/** Which language variant this item still exactly matches, or null once edited. */
|
|
1810
|
+
function seedContentLocale(item, record) {
|
|
1811
|
+
for (const locale of ['zh', 'en']) {
|
|
1812
|
+
const content = record.content[locale];
|
|
1813
|
+
if (content && item.title === content.title && item.body === content.body) return locale;
|
|
1814
|
+
}
|
|
1815
|
+
return null;
|
|
1816
|
+
}
|
|
1817
|
+
|
|
1818
|
+
/** An extra image also counts as an edit, because a reset would lose it. */
|
|
1819
|
+
function seedIsEdited(item, record) {
|
|
1820
|
+
return seedContentLocale(item, record) === null || (Array.isArray(item.images) && item.images.length > 0);
|
|
1821
|
+
}
|
|
1822
|
+
|
|
1637
1823
|
function mutate(fn) {
|
|
1638
1824
|
const prev = pool.get();
|
|
1639
1825
|
const next = fn(prev);
|
|
@@ -1647,6 +1833,40 @@ window.__ModuleLoader__.load({
|
|
|
1647
1833
|
mutate((state) => ({ ...state, items: [...state.items, item] }));
|
|
1648
1834
|
return item;
|
|
1649
1835
|
},
|
|
1836
|
+
/**
|
|
1837
|
+
* Replace every built-in item with a fresh set in `target`. A kept edit
|
|
1838
|
+
* becomes an ordinary item with a new id, so the incoming set can use the
|
|
1839
|
+
* canonical ids without a duplicate. Custom items and the tray are untouched.
|
|
1840
|
+
*/
|
|
1841
|
+
resetBuiltins(target, keepEdited) {
|
|
1842
|
+
const language = target === 'zh' ? 'zh' : 'en';
|
|
1843
|
+
const current = pool.get();
|
|
1844
|
+
const now = Date.now();
|
|
1845
|
+
const items = [];
|
|
1846
|
+
let removed = 0;
|
|
1847
|
+
let kept = 0;
|
|
1848
|
+
for (const item of current.items) {
|
|
1849
|
+
const record = SEED_CATALOG.get(item.id);
|
|
1850
|
+
if (!record) {
|
|
1851
|
+
items.push(item);
|
|
1852
|
+
continue;
|
|
1853
|
+
}
|
|
1854
|
+
if (keepEdited && seedIsEdited(item, record)) {
|
|
1855
|
+
const preserved = { ...item, id: uid() };
|
|
1856
|
+
delete preserved.seed;
|
|
1857
|
+
delete preserved.locale;
|
|
1858
|
+
items.push(preserved);
|
|
1859
|
+
kept += 1;
|
|
1860
|
+
} else {
|
|
1861
|
+
removed += 1;
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
const fresh = seedsAbove(0, now, language);
|
|
1865
|
+
const next = { ...current, items: [...items, ...fresh], seeded: SEED_LEVEL };
|
|
1866
|
+
persist(next);
|
|
1867
|
+
pool.set(next);
|
|
1868
|
+
return { removed, kept, added: fresh.length, language };
|
|
1869
|
+
},
|
|
1650
1870
|
/** Copy one pool item (current text) and append the copy last. */
|
|
1651
1871
|
duplicateItem(id) {
|
|
1652
1872
|
mutate((state) => {
|
|
@@ -3213,6 +3433,21 @@ window.__ModuleLoader__.load({
|
|
|
3213
3433
|
poolActions.setSetting('hiddenWorkspaces', next);
|
|
3214
3434
|
};
|
|
3215
3435
|
const [section, setSection] = useState('order');
|
|
3436
|
+
const [seedKeepEdited, setSeedKeepEdited] = useState(true);
|
|
3437
|
+
const [seedConfirm, setSeedConfirm] = useState(false);
|
|
3438
|
+
const [seedStatus, setSeedStatus] = useState('');
|
|
3439
|
+
const seedItems = state.items.filter((item) => SEED_CATALOG.has(item.id));
|
|
3440
|
+
const editedSeeds = seedItems.filter((item) => seedIsEdited(item, SEED_CATALOG.get(item.id)));
|
|
3441
|
+
const seedLanguageLabel = translate(
|
|
3442
|
+
activeLocaleId() === 'zh' ? 'settings.seedLanguageZh' : 'settings.seedLanguageEn',
|
|
3443
|
+
);
|
|
3444
|
+
const seedRemoveCount = seedItems.length - (seedKeepEdited ? editedSeeds.length : 0);
|
|
3445
|
+
const seedKeptCount = seedKeepEdited ? editedSeeds.length : 0;
|
|
3446
|
+
const resetSeeds = () => {
|
|
3447
|
+
const result = poolActions.resetBuiltins(activeLocaleId(), seedKeepEdited);
|
|
3448
|
+
setSeedConfirm(false);
|
|
3449
|
+
setSeedStatus(translate('settings.seedResetDone', result));
|
|
3450
|
+
};
|
|
3216
3451
|
const moveOrder = (index, delta) => {
|
|
3217
3452
|
const order = settings.order.slice();
|
|
3218
3453
|
const to = index + delta;
|
|
@@ -3285,6 +3520,48 @@ window.__ModuleLoader__.load({
|
|
|
3285
3520
|
h('div', { className: 'pp-set-divider' }),
|
|
3286
3521
|
check('keepAfterQueue', 'settings.keepQueue', 'settings.keepQueueHint'),
|
|
3287
3522
|
),
|
|
3523
|
+
h(
|
|
3524
|
+
'div',
|
|
3525
|
+
{ className: 'pp-set-group pp-set-card', style: { display: section === 'prompts' ? '' : 'none' } },
|
|
3526
|
+
h('div', { className: 'pp-set-label' }, translate('settings.seedCard')),
|
|
3527
|
+
h(
|
|
3528
|
+
'div',
|
|
3529
|
+
{ className: 'pp-hint' },
|
|
3530
|
+
translate('settings.seedHint', { builtin: seedItems.length, edited: editedSeeds.length }),
|
|
3531
|
+
),
|
|
3532
|
+
h(
|
|
3533
|
+
'label',
|
|
3534
|
+
{ className: 'pp-set-row' },
|
|
3535
|
+
h('input', {
|
|
3536
|
+
type: 'checkbox',
|
|
3537
|
+
name: 'seedKeepEdited',
|
|
3538
|
+
checked: seedKeepEdited,
|
|
3539
|
+
onChange: () => setSeedKeepEdited((value) => !value),
|
|
3540
|
+
}),
|
|
3541
|
+
h('span', null, translate('settings.seedKeepEdited')),
|
|
3542
|
+
),
|
|
3543
|
+
h('div', { className: 'pp-hint pp-set-hint' }, translate('settings.seedKeepEditedHint')),
|
|
3544
|
+
h(
|
|
3545
|
+
'div',
|
|
3546
|
+
{ className: 'pp-set-actions' },
|
|
3547
|
+
h(
|
|
3548
|
+
'span',
|
|
3549
|
+
{ className: 'pp-hint pp-set-note' },
|
|
3550
|
+
translate('settings.seedNote', { language: seedLanguageLabel }),
|
|
3551
|
+
),
|
|
3552
|
+
h(
|
|
3553
|
+
'button',
|
|
3554
|
+
{
|
|
3555
|
+
type: 'button',
|
|
3556
|
+
className: 'pp-mini',
|
|
3557
|
+
'data-pp': 'seed-reset',
|
|
3558
|
+
onClick: () => setSeedConfirm(true),
|
|
3559
|
+
},
|
|
3560
|
+
translate('settings.seedResetButton'),
|
|
3561
|
+
),
|
|
3562
|
+
),
|
|
3563
|
+
seedStatus ? h('div', { className: 'pp-hint' }, seedStatus) : null,
|
|
3564
|
+
),
|
|
3288
3565
|
h(
|
|
3289
3566
|
'div',
|
|
3290
3567
|
{ className: 'pp-set-group pp-set-card', style: { display: section === 'workspace' ? '' : 'none' } },
|
|
@@ -3399,6 +3676,16 @@ window.__ModuleLoader__.load({
|
|
|
3399
3676
|
)
|
|
3400
3677
|
: null,
|
|
3401
3678
|
),
|
|
3679
|
+
seedConfirm
|
|
3680
|
+
? h(SeedResetConfirm, {
|
|
3681
|
+
removed: seedRemoveCount,
|
|
3682
|
+
kept: seedKeptCount,
|
|
3683
|
+
added: SEED_TOTAL,
|
|
3684
|
+
language: seedLanguageLabel,
|
|
3685
|
+
onCancel: () => setSeedConfirm(false),
|
|
3686
|
+
onConfirm: resetSeeds,
|
|
3687
|
+
})
|
|
3688
|
+
: null,
|
|
3402
3689
|
);
|
|
3403
3690
|
}
|
|
3404
3691
|
|
|
@@ -4988,6 +5275,8 @@ window.__ModuleLoader__.load({
|
|
|
4988
5275
|
'.pp-set-ws-tag{margin-left:6px;padding:0 5px;border-radius:5px;background:var(--pp-accent-soft);color:var(--pp-accent);font-size:10px}' +
|
|
4989
5276
|
'.pp-set-ws-path{margin-left:auto;color:var(--pp-ink-2);font-size:11px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:340px}' +
|
|
4990
5277
|
'.pp-set-label{font-size:12px;color:var(--pp-ink-2);margin:2px 0 4px}' +
|
|
5278
|
+
'.pp-set-note{margin-right:auto;padding:0;line-height:1.4}' +
|
|
5279
|
+
'.pp-set-actions{display:flex;align-items:center;justify-content:flex-end;gap:8px;margin-top:8px}' +
|
|
4991
5280
|
'.pp-set-card{padding:10px 12px;border:1px solid var(--pp-line-2);border-radius:10px;background:var(--pp-surface);box-shadow:0 1px 3px rgba(0,0,0,.08)}' +
|
|
4992
5281
|
'.pp-set-card .pp-set-label{margin:0 0 6px;font-size:12px;font-weight:600;color:var(--pp-ink)}' +
|
|
4993
5282
|
'.pp-set-card .pp-set-row{padding:3px 0}' +
|
|
@@ -5140,6 +5429,7 @@ window.__ModuleLoader__.load({
|
|
|
5140
5429
|
apply(ctx) {
|
|
5141
5430
|
localeCtx = ctx.locale;
|
|
5142
5431
|
pluginCtx = ctx;
|
|
5432
|
+
seedPoolIfNeeded();
|
|
5143
5433
|
// Optional services: bind late, and stay idle when they never mount.
|
|
5144
5434
|
const bindOptional = (names, assign) => {
|
|
5145
5435
|
const run = (target) => {
|
|
@@ -5208,7 +5498,13 @@ window.__ModuleLoader__.load({
|
|
|
5208
5498
|
});
|
|
5209
5499
|
if (ctx.locale && typeof ctx.locale.register === 'function' && typeof ctx.locale.bind === 'function') {
|
|
5210
5500
|
ctx.effect(() => ctx.locale.register(NS, { zh: ZH, en: EN }));
|
|
5211
|
-
|
|
5501
|
+
const preview = previewLocaleId();
|
|
5502
|
+
if (preview) {
|
|
5503
|
+
const table = preview === 'zh' ? ZH : EN;
|
|
5504
|
+
translate = (key, params) => interpolate(table[key] || key, params);
|
|
5505
|
+
} else {
|
|
5506
|
+
translate = ctx.locale.bind(NS);
|
|
5507
|
+
}
|
|
5212
5508
|
}
|
|
5213
5509
|
// The composer keeps two pieces: the trigger beside the input, and the
|
|
5214
5510
|
// overlay panel. The overlay stays mounted even while closed, which is
|
package/package.json
CHANGED