tavern-harness 0.2.3 → 0.2.5

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.
@@ -776,6 +776,9 @@ export const useStore = create<AppState>((set, get) => ({
776
776
  // 以目标消息的时间戳为切断点:删除它及之后的所有消息(通常为其附属 tool 结果),
777
777
  // 随后重新生成该条回复(重新生成 = 旧回复连同后续内容一起被新回复替换)
778
778
  const messages = snapshotMessages;
779
+ const forcePerformanceGuidance =
780
+ get().settings?.nsfwMode === true &&
781
+ hasPerformanceGuidanceMarkerForReply(messages, message);
779
782
  const toDelete = messages.filter((m) => m.timestamp >= message.timestamp);
780
783
  await deleteContextCompressionsFrom(sessionId, message.timestamp);
781
784
  await db.messages.bulkDelete(toDelete.map((m) => m.id!));
@@ -791,8 +794,11 @@ export const useStore = create<AppState>((set, get) => ({
791
794
  contextTokensLoopIndex: null,
792
795
  });
793
796
 
797
+ // 重新生成始终读取当前会话配置,因此即使原回复生成后修改过破甲指令,
798
+ // 本次临时注入也使用点击重新生成时的最新文本。
799
+ const regenerationSession = (await db.sessions.get(sessionId)) ?? session;
794
800
  let result: TurnResult;
795
- if (session.mode === 'GROUP') {
801
+ if (regenerationSession.mode === 'GROUP') {
796
802
  // 群聊:把被重生成 assistant 的发言人重新置顶(联动发言队列)。
797
803
  // 若该条发言是当前循环某位成员(未知 speakerParticipantId,如收尾回复),
798
804
  // 无法映射到具体成员,则直接按当前队列继续。
@@ -802,9 +808,9 @@ export const useStore = create<AppState>((set, get) => ({
802
808
  .filter((p) => p.participantId === message.speakerParticipantId)
803
809
  .first()) ?? null
804
810
  : null;
805
- result = await continueRegeneratedGroupLoop(session, message, participant);
811
+ result = await continueRegeneratedGroupLoop(regenerationSession, message, participant, forcePerformanceGuidance);
806
812
  } else {
807
- result = await runConversationLoop(session);
813
+ result = await runConversationLoop(regenerationSession, forcePerformanceGuidance);
808
814
  }
809
815
 
810
816
  if (result === 'failed') {
@@ -1619,10 +1625,13 @@ async function handleMagicCommand(session: ChatSession, cmd: string): Promise<vo
1619
1625
  }
1620
1626
  }
1621
1627
 
1628
+ function isBeforeMessage(candidate: ChatMessage, target: ChatMessage): boolean {
1629
+ return candidate.timestamp < target.timestamp ||
1630
+ (candidate.timestamp === target.timestamp && candidate.id! < target.id!);
1631
+ }
1632
+
1622
1633
  function hasPerformanceGuidanceMarkerForUser(messages: ChatMessage[], userMessage: ChatMessage): boolean {
1623
- const earlier = messages
1624
- .filter((message) => message.timestamp < userMessage.timestamp || (message.timestamp === userMessage.timestamp && message.id! < userMessage.id!))
1625
- .reverse();
1634
+ const earlier = messages.filter((message) => isBeforeMessage(message, userMessage)).reverse();
1626
1635
  const previousUserIndex = earlier.findIndex((message) => message.role === 'user');
1627
1636
  const relevant = previousUserIndex < 0 ? earlier : earlier.slice(0, previousUserIndex);
1628
1637
  return relevant.some(
@@ -1630,6 +1639,13 @@ function hasPerformanceGuidanceMarkerForUser(messages: ChatMessage[], userMessag
1630
1639
  );
1631
1640
  }
1632
1641
 
1642
+ function hasPerformanceGuidanceMarkerForReply(messages: ChatMessage[], reply: ChatMessage): boolean {
1643
+ const sourceUser = messages
1644
+ .filter((message) => message.role === 'user' && isBeforeMessage(message, reply))
1645
+ .at(-1);
1646
+ return sourceUser != null && hasPerformanceGuidanceMarkerForUser(messages, sourceUser);
1647
+ }
1648
+
1633
1649
  /** 对话主循环:NPC / STANDARD 直接回复;GROUP 依队列轮转。
1634
1650
  * 返回该轮生成结果(供「重新生成」失败回退判断)。 */
1635
1651
  async function runConversationLoop(session: ChatSession, forcePerformanceGuidance = false): Promise<TurnResult> {
@@ -2796,7 +2812,8 @@ async function continueGroupConversation(sessionId: number, forcePerformanceGuid
2796
2812
  async function continueRegeneratedGroupLoop(
2797
2813
  session: ChatSession,
2798
2814
  editedMessage: ChatMessage,
2799
- editedSpeaker: ChatParticipant | null
2815
+ editedSpeaker: ChatParticipant | null,
2816
+ forcePerformanceGuidance = false,
2800
2817
  ): Promise<TurnResult> {
2801
2818
  const sessionId = session.id!;
2802
2819
  const participants = await db.participants.where('sessionId').equals(sessionId).toArray();
@@ -2804,14 +2821,14 @@ async function continueRegeneratedGroupLoop(
2804
2821
  if (speakerParticipantId == null) {
2805
2822
  // 发言者不可映射 → 仅刷新队列并照常续跑
2806
2823
  await refreshQueueAndSave(sessionId);
2807
- return continueGroupConversation(sessionId);
2824
+ return continueGroupConversation(sessionId, forcePerformanceGuidance);
2808
2825
  }
2809
2826
  const { queue, loopIndex, loopStarted } = refreshQueue(session, participants);
2810
2827
  // 编辑后:该角色“重讲一遍” → 置顶队列,联动发言队列面板与下一轮顺序
2811
2828
  const nextQueue = requeueSpeaker(queue, speakerParticipantId);
2812
2829
  await persistQueue(sessionId, nextQueue, loopIndex, loopStarted);
2813
2830
  await useStore.getState().refreshLiveQueue(sessionId);
2814
- return continueGroupConversation(sessionId);
2831
+ return continueGroupConversation(sessionId, forcePerformanceGuidance);
2815
2832
  }
2816
2833
 
2817
2834
  /** 工具确认在 YOLO 模式下自动批准;执行限额仍挂起等待用户应答。 */
@@ -109,6 +109,72 @@ body {
109
109
  line-height: var(--typography-body-line-height);
110
110
  }
111
111
 
112
+ /* ---------- 首次进入引导 ---------- */
113
+ .opening-guide {
114
+ position: fixed;
115
+ inset: 0;
116
+ z-index: 20000;
117
+ pointer-events: none;
118
+ }
119
+
120
+ .opening-guide-spotlight {
121
+ position: fixed;
122
+ border-radius: 12px;
123
+ /* 只做暗化挖孔,不加描边;挖孔本身即焦点高亮。 */
124
+ box-shadow: 0 0 0 9999px rgb(0 0 0 / 72%);
125
+ transition: inset 180ms ease, width 180ms ease, height 180ms ease;
126
+ pointer-events: none;
127
+ }
128
+
129
+ .opening-guide-card {
130
+ position: fixed;
131
+ width: min(320px, calc(100vw - 24px));
132
+ padding: 18px;
133
+ border: 1px solid color-mix(in srgb, var(--primary) 55%, transparent);
134
+ border-radius: var(--radius);
135
+ background: var(--surface, #fffaf2);
136
+ color: var(--text-primary);
137
+ box-shadow: 0 18px 52px rgb(0 0 0 / 32%);
138
+ pointer-events: auto;
139
+ }
140
+
141
+ .opening-guide-progress {
142
+ color: var(--primary);
143
+ font: var(--font-weight-bold) var(--font-size-caption) / 1 var(--font-family-mono);
144
+ letter-spacing: .08em;
145
+ }
146
+
147
+ .opening-guide-card h2 {
148
+ margin: 10px 0 6px;
149
+ font: var(--typography-title-md-weight) var(--typography-title-md-size) / var(--typography-title-md-line-height) var(--typography-title-md-font);
150
+ }
151
+
152
+ .opening-guide-card p {
153
+ margin: 0;
154
+ color: var(--text-secondary);
155
+ line-height: 1.55;
156
+ }
157
+
158
+ .opening-guide-card button {
159
+ /* 内边距只扩大命中区域;负左外边距抵消它,使文字与上方段落左对齐 */
160
+ margin: 14px 0 0 -8px;
161
+ padding: 4px 8px;
162
+ border: 0;
163
+ background: transparent;
164
+ color: var(--text-muted);
165
+ font-size: var(--font-size-label);
166
+ cursor: pointer;
167
+ /* 反馈只做文字变色,无背景/位移 */
168
+ transition: color 0.16s ease;
169
+ }
170
+ .opening-guide-card button:hover {
171
+ color: var(--text-primary);
172
+ }
173
+ .opening-guide-card button:focus-visible {
174
+ outline: 2px solid var(--primary);
175
+ outline-offset: 2px;
176
+ }
177
+
112
178
  /* ---------- 文字语义工具类 ---------- */
113
179
  .typo-body {
114
180
  font-family: var(--typography-body-font);
@@ -236,6 +302,10 @@ body {
236
302
  .th-scrollbar-thumb.is-visible {
237
303
  opacity: 1;
238
304
  }
305
+ .th-scrollbar-thumb.is-suppressed {
306
+ opacity: 0;
307
+ transition: none;
308
+ }
239
309
  .th-scrollbar-thumb--v {
240
310
  width: 6px;
241
311
  }
@@ -1392,96 +1462,77 @@ body.resizing {
1392
1462
  .dash-hero .actions > .btn {
1393
1463
  height: 40px;
1394
1464
  }
1395
- /* ---------- 与角色继续对话(最近会话列表) ---------- */
1396
- .recent-list {
1465
+ /* ---------- 酒馆说明书 ---------- */
1466
+ .tavern-manual {
1397
1467
  display: flex;
1398
1468
  flex-direction: column;
1399
- gap: 8px;
1400
1469
  }
1401
- .recent-item {
1470
+
1471
+ .manual-chapter {
1402
1472
  display: flex;
1403
1473
  align-items: center;
1404
- gap: 12px;
1474
+ gap: 14px;
1405
1475
  width: 100%;
1406
- text-align: left;
1407
- padding: 10px 12px;
1408
- border: 1px solid var(--border);
1476
+ padding: 16px 18px;
1477
+ border: 1px solid color-mix(in srgb, var(--primary) 30%, var(--border));
1409
1478
  border-radius: var(--radius);
1410
- background: var(--surface);
1479
+ background: color-mix(in srgb, var(--primary) 5%, var(--surface));
1411
1480
  color: var(--text-primary);
1481
+ text-align: left;
1412
1482
  cursor: pointer;
1413
- transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
1483
+ transition: border-color .18s ease, background-color .18s ease, transform .18s ease;
1414
1484
  }
1415
- .recent-item:hover {
1416
- border-color: color-mix(in srgb, var(--primary) 32%, transparent);
1417
- background: color-mix(in srgb, var(--primary) 4%, var(--surface));
1418
- box-shadow: 0 10px 26px color-mix(in srgb, var(--glow) 18%, transparent);
1485
+
1486
+ .manual-chapter:hover {
1487
+ border-color: color-mix(in srgb, var(--primary) 68%, var(--border));
1488
+ background: color-mix(in srgb, var(--primary) 9%, var(--surface));
1489
+ transform: translateY(-1px);
1419
1490
  }
1420
- .recent-item .svc {
1491
+
1492
+ .manual-chapter-icon {
1493
+ display: grid;
1494
+ place-items: center;
1421
1495
  width: 40px;
1422
1496
  height: 40px;
1497
+ flex: 0 0 auto;
1423
1498
  border-radius: 12px;
1424
- flex-shrink: 0;
1425
- }
1426
- .recent-item .svc.svc-single {
1427
- padding: 3px;
1428
- }
1429
- .recent-item .svc.svc-single .avatar {
1430
- width: 100%;
1431
- height: 100%;
1432
- border-radius: 8px;
1433
- box-shadow: none;
1434
- }
1435
- .recent-item .svc .gcollage {
1436
- padding: 2px;
1499
+ background: color-mix(in srgb, var(--primary) 15%, var(--surface));
1500
+ color: var(--primary);
1437
1501
  }
1438
- .recent-meta {
1502
+
1503
+ .manual-chapter-copy {
1504
+ display: flex;
1439
1505
  flex: 1;
1440
1506
  min-width: 0;
1507
+ flex-direction: column;
1508
+ gap: 3px;
1509
+ white-space: normal;
1510
+ overflow-wrap: anywhere;
1441
1511
  }
1442
- .recent-title {
1443
- display: flex;
1444
- align-items: baseline;
1445
- gap: 8px;
1446
- }
1447
- .recent-title-text {
1512
+
1513
+ .manual-chapter-copy strong {
1448
1514
  font-family: var(--font-family-display);
1449
- font-weight: var(--font-weight-bold);
1450
- font-size: var(--font-size-body);
1451
- white-space: nowrap;
1452
- overflow: hidden;
1453
- text-overflow: ellipsis;
1454
- min-width: 0;
1455
- }
1456
- .recent-time {
1457
- flex-shrink: 0;
1458
- font-size: var(--font-size-sm);
1459
- color: var(--text-muted);
1460
- white-space: nowrap;
1515
+ font-size: var(--font-size-title-sm);
1461
1516
  }
1462
- .recent-preview {
1463
- font-size: var(--font-size-md);
1517
+
1518
+ .manual-chapter-copy > span {
1464
1519
  color: var(--text-secondary);
1465
- white-space: nowrap;
1466
- overflow: hidden;
1467
- text-overflow: ellipsis;
1468
- margin-top: 2px;
1520
+ font-size: var(--font-size-body-sm);
1469
1521
  }
1470
- .recent-go {
1471
- display: inline-flex;
1522
+
1523
+ .manual-chapter-action {
1524
+ display: flex;
1472
1525
  align-items: center;
1473
- justify-content: center;
1474
- width: 28px;
1475
- height: 28px;
1476
- border-radius: 8px;
1477
- color: var(--text-muted);
1478
- background: var(--surface-2);
1479
- flex-shrink: 0;
1480
- transition: color 0.18s ease, background 0.18s ease;
1526
+ gap: 6px;
1527
+ flex: 0 0 auto;
1528
+ color: var(--primary);
1529
+ font-weight: var(--font-weight-bold);
1481
1530
  }
1482
- .recent-item:hover .recent-go {
1483
- color: var(--text-accent);
1484
- background: var(--primary-soft);
1531
+
1532
+ @media (max-width: 560px) {
1533
+ .manual-chapter-action {
1534
+ font-size: 0;
1535
+ }
1485
1536
  }
1486
1537
 
1487
1538
  .stat-grid {