dsh-prompt-pool 1.3.0 → 1.4.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.
Files changed (3) hide show
  1. package/README.md +1 -0
  2. package/client.js +2222 -173
  3. package/package.json +1 -1
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.3.0';
22
+ const PLUGIN_VERSION = '1.4.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';
@@ -64,7 +64,7 @@ window.__ModuleLoader__.load({
64
64
  'button.pending': '待发送 {n} 条',
65
65
  'panel.title': '提示池',
66
66
  'panel.close': '关闭',
67
- 'panel.capture': '存草稿',
67
+ 'panel.capture': '保存草稿',
68
68
  'panel.captureHint': '把输入框里的内容复制一份存进池子(图片附件一起存);输入框里的字会保留',
69
69
  'panel.resize': '拖动调整高度,双击还原',
70
70
  'panel.resizeWidth': '拖动调整宽度,双击还原',
@@ -98,12 +98,11 @@ window.__ModuleLoader__.load({
98
98
  'mention.sessionClosed': '会话未打开,无法读取技能目录',
99
99
  'mention.failed': '读取失败',
100
100
  'mention.timeout': '读取超时:宿主没有响应(可能没有活跃会话)',
101
- 'row.insert': '插入到输入框',
101
+ 'row.insert': '生成草稿',
102
102
  'row.select': '加入待发送队列',
103
103
  'row.duplicate': '复制一份,追加到池子末尾',
104
104
  'page.title': '提示池',
105
105
  'tab.description': '暂存、编辑、编排你的提示词,按住顺序一次性释放',
106
- 'page.count': '共 {n} 条',
107
106
  'page.search': '搜索标题或内容…',
108
107
  'page.empty': '还没有内容。点右上角「+ 提示词」开始。',
109
108
  'page.emptyOftenuse': '还没有常用条目。把条目的「分组」改成「常用」即可。',
@@ -115,6 +114,16 @@ window.__ModuleLoader__.load({
115
114
  'settings.open': '提示池设置',
116
115
  'settings.button': '设置',
117
116
  'settings.tab.order': '分组',
117
+ 'settings.defaultTab': '打开时默认选中',
118
+ 'settings.defaultTabNotes': '批注',
119
+ 'settings.defaultTabWorkspace': '当前工作区',
120
+ 'settings.defaultTabOther': '其他',
121
+ 'settings.tab.notes': '批注',
122
+ 'settings.notesIntro': '批注和当前会话绑定。\n在正文中添加的批注同时也会出现在提示池的【批注】页面,也可以把它存为提示词,或直接插入会话输入框。',
123
+ 'settings.notesKeepDraft': '生成草稿后,仍旧保留',
124
+ 'settings.notesKeepDraftHint': '关闭后,生成草稿成功的批注会从列表移除。',
125
+ 'settings.notesKeepStore': '存为提示词后,仍旧保留',
126
+ 'settings.notesKeepStoreHint': '关闭后,存成提示词成功的批注会从列表移除。',
118
127
  'settings.table': '分组的顺序与显示',
119
128
  'settings.tableHint': '箭头调整先后顺序;右侧三列决定这一组怎么显示。',
120
129
  'settings.tableGroup': '分组',
@@ -206,9 +215,41 @@ window.__ModuleLoader__.load({
206
215
  'status.savedPartialTo': '已存入「{group}」,但 {n} 个附件没有保存',
207
216
  'capture.title': '存到哪个分组?',
208
217
  'menu.title': '添加到提示池',
218
+ 'menu.pool': '+ 提示词',
219
+ 'menu.group': '提示池',
209
220
  'menu.copy': '复制',
210
221
  'menu.copied': '已复制',
211
222
  'menu.copyFailed': '复制失败:请按 {shortcut}',
223
+ 'note.add': '+ 批注',
224
+ 'note.title': '批注',
225
+ 'note.placeholder': '写点什么:回答、疑问或修改意见',
226
+ 'note.empty': '没有匹配的批注',
227
+ 'note.emptyIntro': '还没有批注。在会话区选中一句话,右键「+ 批注」即可添加。',
228
+ 'note.save': '保存',
229
+ 'note.cancel': '取消',
230
+ 'note.delete': '删除',
231
+ 'note.compose': '生成草稿',
232
+ 'note.composeHint': '把列表中全部批注生成一份草稿放入对话框',
233
+ 'note.composeStoreHint': '把列表中全部批注存成一条提示词',
234
+ 'note.insert': '插入',
235
+ 'note.locate': '定位',
236
+ 'note.locateFailed': '这条批注暂时找不到原文(回复可能被折叠或改写了)。',
237
+ 'note.deleteConfirm': '删除这条批注?',
238
+ 'note.default': '默认',
239
+ 'note.reset': '重置位置',
240
+ 'note.store': '存成提示词',
241
+ 'note.stored': '已存入 {group}',
242
+ 'note.composeStore': '存成提示词',
243
+ 'note.composeStored': '已存成提示词到 {group}',
244
+ 'note.inserted': '已插入输入框',
245
+ 'note.insertFailed': '输入框暂不可用,稍后再试',
246
+ 'note.quoteMissing': '这条批注暂时找不到原文位置(回复可能被折叠或改写了)。',
247
+ 'note.kind.comment': '意见',
248
+ 'note.kind.question': '提问',
249
+ 'note.kind.agree': '同意',
250
+ 'note.kind.disagree': '反对',
251
+ 'note.kind.idea': '想法',
252
+ 'note.kind.todo': '待办',
212
253
  'menu.last': '上次',
213
254
  'menu.count': '{n} 条',
214
255
  'menu.saved': '已加入「{group}」',
@@ -275,12 +316,11 @@ window.__ModuleLoader__.load({
275
316
  'mention.sessionClosed': 'The session is not open, so the catalog is unavailable',
276
317
  'mention.failed': 'Failed to load',
277
318
  'mention.timeout': 'Timed out: the host did not answer (no live session?)',
278
- 'row.insert': 'Insert into the composer',
319
+ 'row.insert': 'Generate draft',
279
320
  'row.select': 'Add to the send queue',
280
321
  'row.duplicate': 'Duplicate and append to the pool',
281
322
  'page.title': 'Prompt pool',
282
323
  'tab.description': 'Stage, edit and arrange prompts, then release them in order',
283
- 'page.count': '{n} items',
284
324
  'page.search': 'Search title or text…',
285
325
  'page.empty': 'Nothing yet. Use “+ Prompt” in the top right.',
286
326
  'page.emptyOftenuse': 'Nothing here yet. Set an item’s group to Frequent.',
@@ -292,6 +332,16 @@ window.__ModuleLoader__.load({
292
332
  'settings.open': 'Prompt pool settings',
293
333
  'settings.button': 'Settings',
294
334
  'settings.tab.order': 'Groups',
335
+ 'settings.defaultTab': 'Open on',
336
+ 'settings.defaultTabNotes': 'Annotations',
337
+ 'settings.defaultTabWorkspace': 'Current workspace',
338
+ 'settings.defaultTabOther': 'Other',
339
+ 'settings.tab.notes': 'Annotations',
340
+ 'settings.notesIntro': 'Annotations are bound to the current session.\nAnnotations added in the transcript also appear in the prompt pool\'s Annotations tab; they can also be saved as a prompt or inserted straight into the conversation composer.',
341
+ 'settings.notesKeepDraft': 'Keep annotations after generating a draft',
342
+ 'settings.notesKeepDraftHint': 'Turned off, annotations leave the list once a draft is generated.',
343
+ 'settings.notesKeepStore': 'Keep annotations after saving as a prompt',
344
+ 'settings.notesKeepStoreHint': 'Turned off, annotations leave the list once saved as a prompt.',
295
345
  'settings.table': 'Group order and display',
296
346
  'settings.tableHint': 'Use the arrows to reorder; the three columns decide how each family shows up.',
297
347
  'settings.tableGroup': 'Group',
@@ -383,9 +433,41 @@ window.__ModuleLoader__.load({
383
433
  'status.savedPartialTo': 'Saved to {group}; {n} attachment(s) were not captured',
384
434
  'capture.title': 'Save to which group?',
385
435
  'menu.title': 'Add to the prompt pool',
436
+ 'menu.pool': '+ Prompt',
437
+ 'menu.group': 'Prompt pool',
386
438
  'menu.copy': 'Copy',
387
439
  'menu.copied': 'Copied',
388
440
  'menu.copyFailed': 'Copy failed: press {shortcut}',
441
+ 'note.add': '+ Annotate',
442
+ 'note.title': 'Annotations',
443
+ 'note.placeholder': 'Write an answer, a question or a correction',
444
+ 'note.empty': 'No matching annotations',
445
+ 'note.emptyIntro': 'No annotations yet. Select a passage in the conversation area and right-click “+ Annotate” to add one.',
446
+ 'note.save': 'Save',
447
+ 'note.cancel': 'Cancel',
448
+ 'note.delete': 'Delete',
449
+ 'note.compose': 'Generate draft',
450
+ 'note.composeHint': 'Turn every annotation in the list into one draft in the composer',
451
+ 'note.composeStoreHint': 'Save every annotation in the list as one prompt',
452
+ 'note.insert': 'Insert',
453
+ 'note.locate': 'Locate',
454
+ 'note.locateFailed': 'This note cannot find its passage right now (the reply may be folded or rewritten).',
455
+ 'note.deleteConfirm': 'Delete this annotation?',
456
+ 'note.default': 'Default',
457
+ 'note.reset': 'Reset position',
458
+ 'note.store': 'Save as prompt',
459
+ 'note.stored': 'Saved to {group}',
460
+ 'note.composeStore': 'Save as prompt',
461
+ 'note.composeStored': 'Saved as a prompt in {group}',
462
+ 'note.inserted': 'Inserted into the composer',
463
+ 'note.insertFailed': 'The composer is not available; try again',
464
+ 'note.quoteMissing': 'This note cannot find its text right now (the reply may be folded or rewritten).',
465
+ 'note.kind.comment': 'Note',
466
+ 'note.kind.question': 'Question',
467
+ 'note.kind.agree': 'Agree',
468
+ 'note.kind.disagree': 'Disagree',
469
+ 'note.kind.idea': 'Idea',
470
+ 'note.kind.todo': 'To do',
389
471
  'menu.last': 'Last used',
390
472
  'menu.count': '{n} item(s)',
391
473
  'menu.saved': 'Added to {group}',
@@ -1028,6 +1110,26 @@ window.__ModuleLoader__.load({
1028
1110
  ];
1029
1111
  }
1030
1112
 
1113
+ /**
1114
+ * The tab a freshly opened pool lands on. An unavailable preference (a
1115
+ * deleted group, a hidden workspace, no annotations yet) falls back to all.
1116
+ */
1117
+ function resolveDefaultTab(pref, tabs, currentWorkspaceId, hasNotes) {
1118
+ if (!pref) return '';
1119
+ const ids = (tabs || []).map((tab) => tab.id);
1120
+ // The annotation tab always exists now, so the preference always applies.
1121
+ if (pref === 'notes') return 'notes';
1122
+ if (pref === '__workspace__') {
1123
+ const id = currentWorkspaceId ? 'workspace:' + currentWorkspaceId : '';
1124
+ return id && ids.indexOf(id) >= 0 ? id : 'all';
1125
+ }
1126
+ if (pref.indexOf('tab:') === 0) {
1127
+ const id = pref.slice(4);
1128
+ return ids.indexOf(id) >= 0 ? id : 'all';
1129
+ }
1130
+ return '';
1131
+ }
1132
+
1031
1133
  /** Small chooser: where should the captured draft go? */
1032
1134
  function CaptureMenu(props) {
1033
1135
  useEffect(() => {
@@ -1603,6 +1705,14 @@ window.__ModuleLoader__.load({
1603
1705
  queueCollapsed: settings.queueCollapsed === true,
1604
1706
  // The group the right-click menu offered last, so it can lead the list.
1605
1707
  lastCaptureGroup: typeof settings.lastCaptureGroup === 'string' ? settings.lastCaptureGroup : '',
1708
+ // Annotations: where their markers draw, not what they hold.
1709
+ notesHighlight: settings.notesHighlight !== false,
1710
+ // Which tab a freshly opened pool lands on: notes, this workspace, or a
1711
+ // concrete tab ("tab:<id>").
1712
+ defaultTab: typeof settings.defaultTab === 'string' ? settings.defaultTab : '',
1713
+ // Annotations survive the two actions unless the user opts out.
1714
+ noteKeepAfterDraft: settings.noteKeepAfterDraft !== false,
1715
+ noteKeepAfterStore: settings.noteKeepAfterStore !== false,
1606
1716
  // Whether an item leaves the pool after it is used.
1607
1717
  keepAfterInsert: settings.keepAfterInsert !== false,
1608
1718
  keepAfterQueue: settings.keepAfterQueue !== false,
@@ -2381,7 +2491,15 @@ window.__ModuleLoader__.load({
2381
2491
  h('path', { d: 'M4.3 7.6H2.6A1.2 1.2 0 0 1 1.4 6.4V2.6A1.2 1.2 0 0 1 2.6 1.4h3.8a1.2 1.2 0 0 1 1.2 1.2v1.7' }),
2382
2492
  );
2383
2493
  case 'insert':
2384
- return h('svg', base, h('path', { d: 'M1.8 3.4v5.2M2 6h5.2M5.4 3.9L7.6 6 5.4 8.1' }), h('path', { d: 'M9.2 2.2h.8v7.6h-.8' }));
2494
+ // The same glyph as an annotation's "generate draft" action: an arrow
2495
+ // dropping into the composer box.
2496
+ return h(
2497
+ 'svg',
2498
+ { width: 15, height: 15, viewBox: '0 0 20 20', fill: 'none', stroke: 'currentColor', strokeWidth: 1.6, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true },
2499
+ h('path', { d: 'M3.6 12.4h12.8v3.4H3.6z' }),
2500
+ h('path', { d: 'M10 3v6.4' }),
2501
+ h('path', { d: 'M7.4 6.9 10 9.4l2.6-2.5' }),
2502
+ );
2385
2503
  case 'close':
2386
2504
  return h('svg', base, h('path', { d: 'M3 3l6 6M9 3l-6 6' }));
2387
2505
  case 'chevronDown':
@@ -2792,6 +2910,7 @@ window.__ModuleLoader__.load({
2792
2910
  type: 'button',
2793
2911
  className: 'pp-tab',
2794
2912
  'data-active': active ? 'true' : 'false',
2913
+ 'data-group': tab.group,
2795
2914
  title: tab.category ? translate('tab.renameHint') : undefined,
2796
2915
  onClick: () => props.onSelect(tab.id),
2797
2916
  onDoubleClick: tab.category ? () => setRenaming({ id: tab.id, name: tab.label, original: tab.label }) : undefined,
@@ -2899,6 +3018,7 @@ window.__ModuleLoader__.load({
2899
3018
  const state = usePoolState();
2900
3019
  const storage = useStorageState();
2901
3020
  const releaseInfo = useReleaseState();
3021
+ const noteBar = useNoteStatus();
2902
3022
  const queueCollapsed = state.settings && state.settings.queueCollapsed === true;
2903
3023
  const workspaces = useWorkspaceDir();
2904
3024
  const sessionHint = useSessionDir().sessionId;
@@ -2917,14 +3037,32 @@ window.__ModuleLoader__.load({
2917
3037
  return pool.length > 0 ? pool[pool.length - 1] : '';
2918
3038
  })();
2919
3039
  const activeSessionId = pageSessionId || sessionHint || workspaceSession || '';
2920
- const tabs = buildTabs(state.categories, workspaceList, state.settings, currentWorkspaceId);
3040
+ const notesState = useNotesState();
3041
+ const notesList = notesState.items
3042
+ .filter((note) => note.sessionId === activeSessionId)
3043
+ .sort((left, right) => (left.order - right.order) || (left.createdAt - right.createdAt));
3044
+ const baseTabs = buildTabs(state.categories, workspaceList, state.settings, currentWorkspaceId);
3045
+ // The annotation tab is always present, so the feature stays discoverable.
3046
+ const tabs = [{ id: 'notes', label: translate('note.title'), group: 'notes' }, ...baseTabs];
2921
3047
  const captureGroups = captureChoices(state.categories, workspaceList, currentWorkspaceId, state.settings);
2922
- const tabCounts = tabCountsOf(state.items);
3048
+ const tabCounts = {
3049
+ ...tabCountsOf(state.items),
3050
+ notes: notesList.length,
3051
+ };
2923
3052
  const [tab, setPageTab] = useState(() => pageTabState.get().id || 'all');
2924
3053
  const setTab = (id) => {
2925
3054
  pageTabState.set({ id });
2926
3055
  setPageTab(id);
2927
3056
  };
3057
+ // The page opens on the tab chosen in Settings (once per mount).
3058
+ const defaultAppliedRef = useRef(false);
3059
+ useEffect(() => {
3060
+ if (defaultAppliedRef.current) return;
3061
+ defaultAppliedRef.current = true;
3062
+ const pref = normalizeSettings(state.settings).defaultTab;
3063
+ const resolved = resolveDefaultTab(pref, tabs, currentWorkspaceId, notesList.length > 0);
3064
+ if (resolved) setTab(resolved);
3065
+ }, []);
2928
3066
  const [query, setQuery] = useState('');
2929
3067
  const [settingsOpen, setSettingsOpen] = useState(false);
2930
3068
  const [pendingCategory, setPendingCategory] = useState(null);
@@ -3090,6 +3228,75 @@ window.__ModuleLoader__.load({
3090
3228
  );
3091
3229
  };
3092
3230
 
3231
+ /** The page has no composer, so the mounted panel inserts the reply. */
3232
+ const composeSessionNotes = () => {
3233
+ let result;
3234
+ try {
3235
+ result = bridge.request({ type: 'compose-notes' });
3236
+ } catch (_error) {
3237
+ return false;
3238
+ }
3239
+ const ok = Boolean(result && result.ok);
3240
+ if (ok && normalizeSettings(state.settings).noteKeepAfterDraft === false) {
3241
+ notesActions.clearSession(activeSessionId);
3242
+ }
3243
+ return ok;
3244
+ };
3245
+
3246
+ /** The page cannot write the composer, so the mounted panel inserts the note. */
3247
+ const insertNote = (note) => {
3248
+ let result;
3249
+ try {
3250
+ result = bridge.request({ type: 'insert-text', text: composeNoteLine(note) });
3251
+ } catch (_error) {
3252
+ return false;
3253
+ }
3254
+ return Boolean(result && result.ok);
3255
+ };
3256
+
3257
+ /** Store the session's annotations as one prompt, from the page header. */
3258
+ const storeNotesPrompt = (event) => {
3259
+ const choices = captureChoices(state.categories, workspaceList, currentWorkspaceId, state.settings);
3260
+ const preferred = currentWorkspaceId && choices.some((entry) => entry.value === 'workspace:' + currentWorkspaceId)
3261
+ ? 'workspace:' + currentWorkspaceId
3262
+ : BUILTIN_GROUP.oftenuse;
3263
+ const ordered = choices.some((entry) => entry.value === preferred)
3264
+ ? [...choices.filter((entry) => entry.value === preferred), ...choices.filter((entry) => entry.value !== preferred)]
3265
+ : choices;
3266
+ const rect = event && event.currentTarget && event.currentTarget.getBoundingClientRect
3267
+ ? event.currentTarget.getBoundingClientRect()
3268
+ : null;
3269
+ notePrompt.set({
3270
+ open: true,
3271
+ target: { kind: 'reply' },
3272
+ choices: ordered,
3273
+ defaultValue: preferred,
3274
+ anchor: rect
3275
+ ? { left: Math.round(rect.left), right: Math.round(rect.right), top: Math.round(rect.top), bottom: Math.round(rect.bottom) }
3276
+ : { left: 120, right: 160, top: 60, bottom: 90 },
3277
+ token: Date.now(),
3278
+ onPick: (group) => {
3279
+ closeNotePrompt();
3280
+ if (!group) return;
3281
+ const text = composeNotesReply(notesList);
3282
+ poolActions.add({
3283
+ id: uid(),
3284
+ group,
3285
+ title: draftTitle(text),
3286
+ body: text,
3287
+ images: [],
3288
+ createdAt: Date.now(),
3289
+ updatedAt: Date.now(),
3290
+ });
3291
+ if (normalizeSettings(state.settings).noteKeepAfterStore === false) {
3292
+ notesActions.clearSession(activeSessionId);
3293
+ }
3294
+ const resolved = resolveGroup(group, state.categories, workspaceList);
3295
+ showToast(translate('note.composeStored', { group: resolved ? resolved.label : translate('row.noCategory') }), 'ok');
3296
+ },
3297
+ });
3298
+ };
3299
+
3093
3300
  /** The page cannot read the composer, so the mounted panel performs it. */
3094
3301
  const captureDraft = (group) => {
3095
3302
  let result;
@@ -3245,18 +3452,23 @@ window.__ModuleLoader__.load({
3245
3452
  h(
3246
3453
  'div',
3247
3454
  { className: 'pp-page-head' },
3248
- h('span', { className: 'pp-page-title' }, translate('page.title')),
3249
- h('span', { className: 'pp-page-sub' }, translate('page.count', { n: state.items.length })),
3250
- h('span', { className: 'pp-grow' }),
3251
3455
  h('input', {
3456
+ key: 'search',
3252
3457
  className: 'pp-search',
3253
3458
  value: query,
3254
3459
  placeholder: translate('page.search'),
3255
3460
  'aria-label': translate('page.search'),
3256
3461
  onChange: (event) => setQuery(event.target.value),
3257
3462
  }),
3258
- h('button', { type: 'button', className: 'pp-mini', onClick: create }, '+ ', translate('page.new')),
3259
- h('button', { type: 'button', className: 'pp-mini', title: translate('panel.captureHint'), onClick: openCapture }, translate('panel.capture')),
3463
+ tab === 'notes'
3464
+ ? [
3465
+ h('button', { key: 'store', type: 'button', className: 'pp-mini', title: translate('note.composeStoreHint'), onClick: storeNotesPrompt }, translate('note.composeStore')),
3466
+ h('button', { key: 'draft', type: 'button', className: 'pp-mini', title: translate('note.composeHint'), onClick: composeSessionNotes }, translate('note.compose')),
3467
+ ]
3468
+ : [
3469
+ h('button', { key: 'new', type: 'button', className: 'pp-mini', onClick: create }, '+ ', translate('page.new')),
3470
+ h('button', { key: 'capture', type: 'button', className: 'pp-mini', title: translate('panel.captureHint'), onClick: openCapture }, translate('panel.capture')),
3471
+ ],
3260
3472
  h(SettingsButton, { active: settingsOpen, onClick: () => setSettingsOpen(!settingsOpen) }),
3261
3473
  ),
3262
3474
  h(
@@ -3327,7 +3539,20 @@ window.__ModuleLoader__.load({
3327
3539
  { className: 'pp-page-body', ref: pageListRef },
3328
3540
  settingsOpen
3329
3541
  ? h(PromptPoolSettings, { currentWorkspaceId })
3330
- : nestedView
3542
+ : tab === 'notes'
3543
+ ? h(NotesView, {
3544
+ notes: notesList,
3545
+ sessionId: activeSessionId,
3546
+ onCompose: composeSessionNotes,
3547
+ onInsertNote: insertNote,
3548
+ hideActions: true,
3549
+ filter: query,
3550
+ categories: state.categories,
3551
+ workspaces: workspaceList,
3552
+ currentWorkspaceId,
3553
+ settings: state.settings,
3554
+ })
3555
+ : nestedView
3331
3556
  ? renderWorkspacePanes({
3332
3557
  rail: nestedView.rail,
3333
3558
  items: nestedView.scoped,
@@ -3356,6 +3581,9 @@ window.__ModuleLoader__.load({
3356
3581
  h(
3357
3582
  'div',
3358
3583
  { className: 'pp-queue-dock' },
3584
+ tab === 'notes' && noteBar.text
3585
+ ? h('div', { className: 'pp-notes-bar', 'data-kind': noteBar.kind, role: 'status' }, noteBar.text)
3586
+ : null,
3359
3587
  notice
3360
3588
  ? h(
3361
3589
  'div',
@@ -3376,7 +3604,7 @@ window.__ModuleLoader__.load({
3376
3604
  : null,
3377
3605
  )
3378
3606
  : null,
3379
- settingsOpen
3607
+ settingsOpen || tab === 'notes'
3380
3608
  ? null
3381
3609
  : renderTrayCard({
3382
3610
  entries: state.tray,
@@ -3433,6 +3661,15 @@ window.__ModuleLoader__.load({
3433
3661
  poolActions.setSetting('hiddenWorkspaces', next);
3434
3662
  };
3435
3663
  const [section, setSection] = useState('order');
3664
+ const tabOptions = buildTabs(state.categories, wsItems, settings, wsCurrentId);
3665
+ const defaultTab = settings.defaultTab || '';
3666
+ const defaultTabMode = defaultTab === 'notes'
3667
+ ? 'notes'
3668
+ : defaultTab === '__workspace__'
3669
+ ? 'workspace'
3670
+ : defaultTab.indexOf('tab:') === 0
3671
+ ? 'custom'
3672
+ : '';
3436
3673
  const [seedKeepEdited, setSeedKeepEdited] = useState(true);
3437
3674
  const [seedConfirm, setSeedConfirm] = useState(false);
3438
3675
  const [seedStatus, setSeedStatus] = useState('');
@@ -3470,7 +3707,7 @@ window.__ModuleLoader__.load({
3470
3707
  }),
3471
3708
  h('span', null, translate(label)),
3472
3709
  ),
3473
- h('div', { className: 'pp-hint pp-set-hint' }, translate(hint)),
3710
+ hint ? h('div', { className: 'pp-hint pp-set-hint' }, translate(hint)) : null,
3474
3711
  );
3475
3712
  return h(
3476
3713
  'div',
@@ -3511,6 +3748,25 @@ window.__ModuleLoader__.load({
3511
3748
  },
3512
3749
  translate('settings.tab.prompts'),
3513
3750
  ),
3751
+ h(
3752
+ 'button',
3753
+ {
3754
+ type: 'button',
3755
+ className: 'pp-tab',
3756
+ 'data-active': section === 'notes' ? 'true' : 'false',
3757
+ onClick: () => setSection('notes'),
3758
+ },
3759
+ translate('settings.tab.notes'),
3760
+ ),
3761
+ ),
3762
+ h(
3763
+ 'div',
3764
+ { className: 'pp-set-group pp-set-card', style: { display: section === 'notes' ? '' : 'none' } },
3765
+ h('div', { className: 'pp-hint pp-set-intro' }, translate('settings.notesIntro')),
3766
+ h('div', { className: 'pp-set-divider' }),
3767
+ check('noteKeepAfterDraft', 'settings.notesKeepDraft', 'settings.notesKeepDraftHint'),
3768
+ h('div', { className: 'pp-set-divider' }),
3769
+ check('noteKeepAfterStore', 'settings.notesKeepStore', 'settings.notesKeepStoreHint'),
3514
3770
  ),
3515
3771
  h(
3516
3772
  'div',
@@ -3589,6 +3845,59 @@ window.__ModuleLoader__.load({
3589
3845
  ),
3590
3846
  ),
3591
3847
  ),
3848
+ h(
3849
+ 'div',
3850
+ { className: 'pp-set-group pp-set-card', style: { display: section === 'order' ? '' : 'none' } },
3851
+ h('div', { className: 'pp-set-label' }, translate('settings.defaultTab')),
3852
+ h(
3853
+ 'div',
3854
+ { className: 'pp-set-radios' },
3855
+ [
3856
+ { mode: 'notes', key: 'settings.defaultTabNotes', value: 'notes' },
3857
+ { mode: 'workspace', key: 'settings.defaultTabWorkspace', value: '__workspace__' },
3858
+ { mode: 'custom', key: 'settings.defaultTabOther', value: '' },
3859
+ ].map((entry) => h(
3860
+ 'div',
3861
+ { key: entry.mode, className: 'pp-set-radio-row' },
3862
+ h(
3863
+ 'label',
3864
+ { className: 'pp-set-radio' },
3865
+ h('input', {
3866
+ type: 'radio',
3867
+ name: 'pp-default-tab',
3868
+ checked: defaultTabMode === entry.mode,
3869
+ onChange: () => {
3870
+ if (entry.mode === 'custom') {
3871
+ const previous = defaultTab.indexOf('tab:') === 0 ? defaultTab : '';
3872
+ const first = tabOptions[0];
3873
+ poolActions.setSetting('defaultTab', previous || (first ? 'tab:' + first.id : ''));
3874
+ return;
3875
+ }
3876
+ poolActions.setSetting('defaultTab', entry.value);
3877
+ },
3878
+ }),
3879
+ h('span', null, translate(entry.key)),
3880
+ ),
3881
+ entry.mode === 'custom'
3882
+ ? h(
3883
+ 'select',
3884
+ {
3885
+ className: 'pp-select',
3886
+ // Always visible next to "other"; picking a tab here also
3887
+ // switches the choice to it.
3888
+ value: defaultTabMode === 'custom' ? defaultTab.slice(4) : (tabOptions[0] ? tabOptions[0].id : ''),
3889
+ onChange: (event) => poolActions.setSetting('defaultTab', 'tab:' + event.target.value),
3890
+ },
3891
+ tabOptions.map((tab) => h(
3892
+ 'option',
3893
+ { key: tab.id, value: tab.id },
3894
+ tab.label,
3895
+ )),
3896
+ )
3897
+ : null,
3898
+ )),
3899
+ ),
3900
+ ),
3592
3901
  h(
3593
3902
  'div',
3594
3903
  { className: 'pp-set-group pp-set-card', style: { display: section === 'order' ? '' : 'none' } },
@@ -4003,166 +4312,1675 @@ window.__ModuleLoader__.load({
4003
4312
  );
4004
4313
  }
4005
4314
 
4006
- // --------------------------------------------------- conversation selection
4315
+ // ------------------------------------------------------------------ notes
4007
4316
  /**
4008
- * Right-click destinations for text selected in the conversation. The host
4009
- * opens this surface at the pointer; the top level keeps Copy (the menu
4010
- * replaces the browser's own) and one pool entry whose submenu lists the
4011
- * groups on show. Picking a group stores the selection there, and the group
4012
- * used last time leads that submenu. The surface only exists while the Chat
4013
- * view is mounted, and a selection lost between the gesture and this mount
4014
- * leaves it with nothing to offer.
4317
+ * Annotations on a rendered assistant reply. They are stored by value (the
4318
+ * quoted text plus its surroundings) instead of by DOM node, so a re-render,
4319
+ * a fold or a paging remount costs the pin only until the text is back.
4015
4320
  */
4016
- function SelectionMenu(props) {
4017
- useLocaleTick();
4018
- const state = usePoolState();
4019
- const published = useWorkspaceDir();
4020
- // The Chat view can read the workspace roster itself; the module store is
4021
- // the fallback for a host that does not hand `useWorkspaces` to this seat.
4022
- const snapshot = typeof props.useWorkspaces === 'function' ? props.useWorkspaces(selectAllInput) : undefined;
4023
- const workspaces = snapshot ? workspaceEntriesOf(snapshot) : published.items || [];
4024
- const currentWorkspaceId = snapshot ? currentWorkspaceOf(snapshot, props.sessionId) : published.currentId || '';
4025
- // The gesture captured the text before this surface mounted; keeping it in
4026
- // state means a collapsed selection cannot empty the menu mid-click.
4027
- const [body] = useState(() => {
4028
- const text = typeof props.readText === 'function' ? props.readText() : null;
4029
- return typeof text === 'string' ? text.replace(/\r\n?/g, '\n').trim() : '';
4030
- });
4031
- const [done, setDone] = useState(null);
4032
- // The group list lives one level down; Copy stays at the top.
4033
- const [submenu, setSubmenu] = useState(false);
4034
- const timer = useRef(0);
4035
- const dismiss = typeof props.dismiss === 'function' ? props.dismiss : () => {};
4321
+ const NOTES_KEY = 'dsh.prompt-pool.notes.v1';
4322
+ const NOTES_SINGLETON = '__dshPromptPoolNotesV1';
4323
+ /** One Highlight object carries every annotated range. */
4324
+ const NOTE_HIGHLIGHT = 'prompt-pool-note';
4325
+ /** The always-open note card: fixed width so the gutter test is exact. */
4326
+ /** Narrower columns fall back to numbered pins instead of cards. */
4327
+ /** Tallest a card can get, for the occlusion test against a floating panel. */
4328
+
4329
+ /** Bumped when badge placement changes, so old chips are rebuilt in place. */
4330
+ const NOTE_CHIP_VERSION = '3';
4331
+
4332
+ /** Annotation kinds: the glyph, tint and label drive the badge and highlight. */
4333
+ const NOTE_KINDS = [
4334
+ { id: 'comment', icon: '✎', tint: '255,191,36', label: 'note.kind.comment' },
4335
+ { id: 'question', icon: '?', tint: '244,114,114', label: 'note.kind.question' },
4336
+ { id: 'agree', icon: '✓', tint: '74,222,128', label: 'note.kind.agree' },
4337
+ { id: 'disagree', icon: '✕', tint: '239,68,68', label: 'note.kind.disagree' },
4338
+ { id: 'idea', icon: '💡', tint: '96,165,250', label: 'note.kind.idea' },
4339
+ { id: 'todo', icon: '□', tint: '251,191,36', label: 'note.kind.todo' },
4340
+ ];
4341
+ const NOTE_KIND_IDS = NOTE_KINDS.map((kind) => kind.id);
4342
+ const NOTE_KIND_DEFAULT = 'comment';
4343
+ /** Inline annotations are a short badge: ten characters at most. */
4344
+ const NOTE_BODY_MAX = 10;
4345
+
4346
+ function noteKind(kind) {
4347
+ return NOTE_KINDS.find((entry) => entry.id === kind) || NOTE_KINDS[0];
4348
+ }
4036
4349
 
4037
- useEffect(() => () => window.clearTimeout(timer.current), []);
4038
- useEffect(() => {
4039
- // The selection was gone before the surface mounted; nothing to offer.
4040
- if (!body) dismiss();
4041
- }, [body, dismiss]);
4350
+ /** The visible badge text, whitespace-collapsed and capped. */
4351
+ function noteBodyText(body) {
4352
+ const text = String(body || '').replace(/\s+/g, ' ').trim();
4353
+ return text.length > NOTE_BODY_MAX ? text.slice(0, NOTE_BODY_MAX) + '…' : text;
4354
+ }
4042
4355
 
4043
- if (!body) return null;
4356
+ /** Keep only fields the annotation UI reads; anything else is dropped. */
4357
+ function normalizeNote(raw) {
4358
+ if (!raw || typeof raw !== 'object') return null;
4359
+ const quote = typeof raw.quote === 'string' ? raw.quote : '';
4360
+ if (!quote.trim()) return null;
4361
+ return {
4362
+ id: typeof raw.id === 'string' && raw.id ? raw.id : uid(),
4363
+ sessionId: typeof raw.sessionId === 'string' ? raw.sessionId : '',
4364
+ nodeKey: typeof raw.nodeKey === 'string' ? raw.nodeKey : '',
4365
+ quote,
4366
+ prefix: typeof raw.prefix === 'string' ? raw.prefix : '',
4367
+ suffix: typeof raw.suffix === 'string' ? raw.suffix : '',
4368
+ offset: Number.isFinite(Number(raw.offset)) ? Number(raw.offset) : 0,
4369
+ order: Number.isFinite(Number(raw.order)) ? Number(raw.order) : 0,
4370
+ kind: NOTE_KIND_IDS.indexOf(raw.kind) >= 0 ? raw.kind : NOTE_KIND_DEFAULT,
4371
+ // Where the user dragged this note's card, relative to its passage.
4372
+ dx: Number.isFinite(Number(raw.dx)) ? Number(raw.dx) : 0,
4373
+ dy: Number.isFinite(Number(raw.dy)) ? Number(raw.dy) : 0,
4374
+ // Set once the note was promoted into a pool group; the row keeps it
4375
+ // visible with a "stored" marker instead of deleting the record.
4376
+ promotedGroup: typeof raw.promotedGroup === 'string' ? raw.promotedGroup : '',
4377
+ promotedAt: Number.isFinite(Number(raw.promotedAt)) ? Number(raw.promotedAt) : 0,
4378
+ body: typeof raw.body === 'string' ? raw.body : '',
4379
+ createdAt: Number.isFinite(Number(raw.createdAt)) ? Number(raw.createdAt) : Date.now(),
4380
+ updatedAt: Number.isFinite(Number(raw.updatedAt)) ? Number(raw.updatedAt) : Date.now(),
4381
+ };
4382
+ }
4044
4383
 
4045
- const choices = captureChoices(state.categories, workspaces, currentWorkspaceId, state.settings);
4046
- const last = state.settings && state.settings.lastCaptureGroup;
4047
- const remembered = choices.find((choice) => choice.value === last) || null;
4048
- const ordered = remembered ? [remembered, ...choices.filter((choice) => choice !== remembered)] : choices;
4049
- const counts = {};
4050
- for (const item of state.items) {
4051
- const group = groupOf(item);
4052
- counts[group] = (counts[group] || 0) + 1;
4384
+ function loadNotes() {
4385
+ try {
4386
+ const raw = localStorage.getItem(NOTES_KEY);
4387
+ const parsed = raw ? JSON.parse(raw) : null;
4388
+ const items = Array.isArray(parsed && parsed.items) ? parsed.items.map(normalizeNote).filter(Boolean) : [];
4389
+ return { version: 1, items };
4390
+ } catch (_error) {
4391
+ return { version: 1, items: [] };
4053
4392
  }
4393
+ }
4054
4394
 
4055
- const pick = (choice) => {
4056
- if (done) return;
4057
- const now = Date.now();
4058
- poolActions.add({
4059
- id: uid(),
4060
- group: choice.value,
4061
- title: draftTitle(body),
4062
- body,
4063
- images: [],
4064
- createdAt: now,
4065
- updatedAt: now,
4395
+ const notes = (() => {
4396
+ if (typeof window === 'undefined') return createStore({ version: 1, items: [] });
4397
+ if (!window[NOTES_SINGLETON]) window[NOTES_SINGLETON] = createStore(loadNotes());
4398
+ return window[NOTES_SINGLETON];
4399
+ })();
4400
+
4401
+ function mutateNotes(fn) {
4402
+ const prev = notes.get();
4403
+ const next = fn(prev);
4404
+ if (!next || next === prev) return;
4405
+ notes.set(next);
4406
+ try {
4407
+ localStorage.setItem(NOTES_KEY, JSON.stringify(next));
4408
+ } catch (_error) {
4409
+ /* a full store keeps the in-memory copy; the pool reports write failures */
4410
+ }
4411
+ }
4412
+
4413
+ const notesActions = {
4414
+ add(note) {
4415
+ mutateNotes((state) => ({ ...state, items: [...state.items, note] }));
4416
+ return note;
4417
+ },
4418
+ patch(id, fields) {
4419
+ mutateNotes((state) => ({
4420
+ ...state,
4421
+ items: state.items.map((note) => (note.id === id ? { ...note, ...fields, updatedAt: Date.now() } : note)),
4422
+ }));
4423
+ },
4424
+ remove(id) {
4425
+ mutateNotes((state) => (state.items.some((note) => note.id === id)
4426
+ ? { ...state, items: state.items.filter((note) => note.id !== id) }
4427
+ : null));
4428
+ },
4429
+ clearSession(sessionId) {
4430
+ mutateNotes((state) => {
4431
+ const items = state.items.filter((note) => note.sessionId !== sessionId);
4432
+ return items.length === state.items.length ? null : { ...state, items };
4066
4433
  });
4067
- // Remembering the destination makes the next right-click a single pick.
4068
- poolActions.setSetting('lastCaptureGroup', choice.value);
4069
- // The write can fail on a full or blocked store; say so instead of
4070
- // claiming a save the pool would lose on reload.
4071
- const failed = storageState.get().failed === true;
4072
- setDone({ kind: failed ? 'failed' : 'saved', label: choice.label });
4073
- timer.current = window.setTimeout(() => dismiss(), failed ? 2600 : 900);
4074
- };
4434
+ },
4435
+ /** Drop every drag offset in one session: the cards return to their anchors. */
4436
+ resetPositions(sessionId) {
4437
+ mutateNotes((state) => {
4438
+ let touched = false;
4439
+ const items = state.items.map((note) => {
4440
+ if (note.sessionId !== sessionId) return note;
4441
+ if ((note.dx || 0) === 0 && (note.dy || 0) === 0) return note;
4442
+ touched = true;
4443
+ return { ...note, dx: 0, dy: 0 };
4444
+ });
4445
+ return touched ? { ...state, items } : null;
4446
+ });
4447
+ },
4448
+ };
4075
4449
 
4076
- /**
4077
- * The menu replaces the browser's own menu, so it has to keep Copy. The
4078
- * selection is already captured, and the click still counts as a gesture.
4079
- */
4080
- const copySelection = () => {
4081
- if (done) return;
4082
- const copied = copyText(body);
4083
- setDone({ kind: copied ? 'copied' : 'copyFailed' });
4084
- // A failed copy stays up so the shortcut hint can be read and used.
4085
- if (copied) timer.current = window.setTimeout(() => dismiss(), 900);
4086
- };
4450
+ /**
4451
+ * A frame-level toast. The notes views live inside the composer overlay or a
4452
+ * sidebar column, so an inline status would be clipped or lost in the list;
4453
+ * the toast is appended to the body and floats above every surface.
4454
+ */
4455
+ let toastNode = null;
4456
+ let toastTimer = 0;
4457
+ function ensureToastStyle() {
4458
+ if (typeof document === 'undefined') return;
4459
+ if (document.querySelector('style[data-pp-toast]')) return;
4460
+ const style = document.createElement('style');
4461
+ style.setAttribute('data-pp-toast', '');
4462
+ style.textContent = '.pp-toast{position:fixed;left:50%;bottom:30px;z-index:2147483000;max-width:min(520px,calc(100vw - 32px));padding:7px 13px;border-radius:8px;background:rgba(24,24,26,.94);color:#fff;font-size:12px;line-height:1.5;box-shadow:0 12px 30px rgba(0,0,0,.28);opacity:0;transform:translate(-50%,8px);transition:opacity .16s ease,transform .16s ease;pointer-events:none;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.pp-toast[data-show="true"]{opacity:1;transform:translate(-50%,0)}.pp-toast[data-kind="error"]{background:rgba(160,38,38,.95)}';
4463
+ document.head.appendChild(style);
4464
+ }
4465
+ function showToast(text, kind) {
4466
+ if (typeof document === 'undefined' || !text) return;
4467
+ ensureToastStyle();
4468
+ if (!toastNode) {
4469
+ toastNode = document.createElement('div');
4470
+ toastNode.className = 'pp-toast';
4471
+ toastNode.setAttribute('role', 'status');
4472
+ document.body.appendChild(toastNode);
4473
+ }
4474
+ toastNode.textContent = text;
4475
+ toastNode.setAttribute('data-kind', kind === 'error' ? 'error' : 'ok');
4476
+ toastNode.setAttribute('data-show', 'true');
4477
+ window.clearTimeout(toastTimer);
4478
+ toastTimer = window.setTimeout(() => {
4479
+ if (toastNode) toastNode.removeAttribute('data-show');
4480
+ }, 2300);
4481
+ }
4087
4482
 
4088
- /** Open the destination submenu; a click serves touch, hover serves mouse. */
4089
- const openGroups = () => {
4090
- if (done !== null) return;
4091
- setSubmenu(true);
4092
- };
4483
+ /** The session whose transcript is on screen; published by the notes layer. */
4484
+ const chatView = (() => {
4485
+ if (typeof window === 'undefined') return createStore({ sessionId: '' });
4486
+ if (!window.__dshPromptPoolNotesViewV1) window.__dshPromptPoolNotesViewV1 = createStore({ sessionId: '' });
4487
+ return window.__dshPromptPoolNotesViewV1;
4488
+ })();
4489
+ /** A newly captured anchor waiting for the overlay to open its editor. */
4490
+ const noteDraft = (() => {
4491
+ if (typeof window === 'undefined') return createStore({ anchor: null, sessionId: '', token: 0 });
4492
+ if (!window.__dshPromptPoolNotesDraftV1) window.__dshPromptPoolNotesDraftV1 = createStore({ anchor: null, sessionId: '', token: 0 });
4493
+ return window.__dshPromptPoolNotesDraftV1;
4494
+ })();
4495
+ /** A request to scroll to one annotation and open it. */
4496
+ const noteFocus = (() => {
4497
+ if (typeof window === 'undefined') return createStore({ id: '', token: 0 });
4498
+ if (!window.__dshPromptPoolNotesFocusV1) window.__dshPromptPoolNotesFocusV1 = createStore({ id: '', token: 0 });
4499
+ return window.__dshPromptPoolNotesFocusV1;
4500
+ })();
4093
4501
 
4094
- const error = done !== null && (done.kind === 'failed' || done.kind === 'copyFailed');
4095
- const shortcut = /Mac|iPhone|iPad/.test(typeof navigator === 'undefined' ? '' : String(navigator.userAgent || '')) ? '⌘C' : 'Ctrl+C';
4096
- const doneText = done === null
4097
- ? ''
4098
- : done.kind === 'saved'
4099
- ? translate('menu.saved', { group: done.label })
4100
- : done.kind === 'copied'
4101
- ? translate('menu.copied')
4102
- : done.kind === 'copyFailed'
4103
- ? translate('menu.copyFailed', { shortcut })
4104
- : translate('status.storageFailed');
4502
+ /**
4503
+ * The "pick a group" popup for storing a prompt. It lives in the frame
4504
+ * overlay (not in the pool list) so it can float over the panel instead of
4505
+ * pushing content around or being clipped by the list.
4506
+ */
4507
+ const notePrompt = (() => {
4508
+ const empty = { open: false, target: null, choices: [], anchor: null, defaultValue: '', onPick: null, token: 0 };
4509
+ if (typeof window === 'undefined') return createStore(empty);
4510
+ if (!window.__dshPromptPoolNotePromptV1) window.__dshPromptPoolNotePromptV1 = createStore(empty);
4511
+ return window.__dshPromptPoolNotePromptV1;
4512
+ })();
4513
+ const closeNotePrompt = () => notePrompt.set({ open: false, target: null, choices: [], anchor: null, defaultValue: '', onPick: null, token: 0 });
4514
+
4515
+ /** The "delete this annotation?" popup; the confirmation floats, never inline. */
4516
+ const noteConfirm = (() => {
4517
+ const empty = { open: false, anchor: null, onConfirm: null, token: 0 };
4518
+ if (typeof window === 'undefined') return createStore(empty);
4519
+ if (!window.__dshPromptPoolNoteConfirmV1) window.__dshPromptPoolNoteConfirmV1 = createStore(empty);
4520
+ return window.__dshPromptPoolNoteConfirmV1;
4521
+ })();
4522
+ const closeNoteConfirm = () => noteConfirm.set({ open: false, anchor: null, onConfirm: null, token: 0 });
4523
+
4524
+ /** A short status line in the annotations tab's bottom strip (locate misses). */
4525
+ const noteStatus = (() => {
4526
+ const empty = { text: '', kind: '', token: 0 };
4527
+ if (typeof window === 'undefined') return createStore(empty);
4528
+ if (!window.__dshPromptPoolNoteStatusV1) window.__dshPromptPoolNoteStatusV1 = createStore(empty);
4529
+ return window.__dshPromptPoolNoteStatusV1;
4530
+ })();
4531
+ function showNoteStatus(text, kind) {
4532
+ const token = Date.now();
4533
+ noteStatus.set({ text: String(text || ''), kind: kind === 'error' ? 'error' : 'ok', token });
4534
+ if (typeof window !== 'undefined') {
4535
+ window.setTimeout(() => {
4536
+ if (noteStatus.get().token === token) noteStatus.set({ text: '', kind: '', token: 0 });
4537
+ }, 2800);
4538
+ }
4539
+ }
4540
+ function openNoteConfirm(run, event) {
4541
+ const rect = event && event.currentTarget && event.currentTarget.getBoundingClientRect
4542
+ ? event.currentTarget.getBoundingClientRect()
4543
+ : null;
4544
+ noteConfirm.set({
4545
+ open: true,
4546
+ anchor: rect
4547
+ ? { left: Math.round(rect.left), right: Math.round(rect.right), top: Math.round(rect.top), bottom: Math.round(rect.bottom) }
4548
+ : { left: 120, right: 160, top: 90, bottom: 120 },
4549
+ onConfirm: typeof run === 'function' ? run : null,
4550
+ token: Date.now(),
4551
+ });
4552
+ }
4105
4553
 
4106
- return h(
4107
- 'div',
4108
- {
4109
- className: 'pp-selwrap',
4110
- role: 'menu',
4111
- 'aria-label': translate('menu.title'),
4112
- // Keep the browser selection alive while the pointer is over the menu.
4113
- onPointerDown: (event) => event.preventDefault(),
4114
- },
4115
- h('style', { key: 'css' }, MENU_CSS),
4116
- done !== null
4117
- ? h(
4118
- 'div',
4119
- { key: 'done', className: 'pp-selmenu pp-seldonecard' },
4120
- h(
4121
- 'div',
4122
- { className: 'pp-seldone', 'data-kind': error ? 'error' : 'ok', role: 'status' },
4123
- h('span', { key: 'mark', className: 'pp-seldone-mark', 'aria-hidden': true }, error ? '!' : '✓'),
4124
- h('span', { key: 'text', className: 'pp-seldone-text' }, doneText),
4125
- ),
4126
- )
4127
- : [
4128
- h(
4129
- 'div',
4130
- { key: 'main', className: 'pp-selmenu' },
4131
- h(
4132
- 'button',
4133
- {
4134
- key: 'copy',
4135
- type: 'button',
4136
- role: 'menuitem',
4137
- className: 'pp-selrow',
4138
- onClick: copySelection,
4139
- // Moving back to the first row folds the submenu away.
4140
- onPointerEnter: () => setSubmenu(false),
4141
- },
4142
- h('span', { key: 'name', className: 'pp-selname' }, translate('menu.copy')),
4143
- h('span', { key: 'key', className: 'pp-selkey' }, shortcut),
4144
- ),
4145
- h('div', { key: 'rule', className: 'pp-selrule', role: 'separator' }),
4146
- h(
4147
- 'button',
4148
- {
4149
- key: 'pool',
4150
- type: 'button',
4151
- role: 'menuitem',
4152
- className: 'pp-selrow',
4153
- 'aria-haspopup': 'menu',
4154
- 'aria-expanded': submenu,
4155
- onClick: openGroups,
4156
- onPointerEnter: openGroups,
4554
+ const useNotesState = () => useSyncExternalStore(notes.subscribe, notes.get, notes.get);
4555
+ const useChatView = () => useSyncExternalStore(chatView.subscribe, chatView.get, chatView.get);
4556
+ const useNoteDraft = () => useSyncExternalStore(noteDraft.subscribe, noteDraft.get, noteDraft.get);
4557
+ const useNoteFocus = () => useSyncExternalStore(noteFocus.subscribe, noteFocus.get, noteFocus.get);
4558
+ const useNotePrompt = () => useSyncExternalStore(notePrompt.subscribe, notePrompt.get, notePrompt.get);
4559
+ const useNoteConfirm = () => useSyncExternalStore(noteConfirm.subscribe, noteConfirm.get, noteConfirm.get);
4560
+ const useNoteStatus = () => useSyncExternalStore(noteStatus.subscribe, noteStatus.get, noteStatus.get);
4561
+
4562
+ /** One line of quote text for a row, a pin tooltip or the composed reply. */
4563
+ function noteQuoteText(quote, limit) {
4564
+ const text = String(quote || '').replace(/\s+/g, ' ').trim();
4565
+ const max = limit || 80;
4566
+ return text.length > max ? text.slice(0, max) + '…' : text;
4567
+ }
4568
+
4569
+ /** The reply a session's annotations produce: numbered, each with its quote. */
4570
+ /** One note as a prompt line, without a number (single-note drafts). */
4571
+ function composeNoteLine(note) {
4572
+ const kind = noteKind(note.kind);
4573
+ const label = translate(kind.label);
4574
+ const body = String(note.body || '').replace(/\s+/g, ' ').trim();
4575
+ return `【${label}】「${noteQuoteText(note.quote)}」${body ? ':' + body : ''}`;
4576
+ }
4577
+
4578
+ /** The reply a session's annotations produce: numbered, each with its quote. */
4579
+ function composeNotesReply(list) {
4580
+ return list
4581
+ .slice()
4582
+ .sort((left, right) => (left.order - right.order) || (left.createdAt - right.createdAt))
4583
+ .map((note, index) => `${index + 1}. ${composeNoteLine(note)}`)
4584
+ .join('\n');
4585
+ }
4586
+
4587
+ /** The selection's start as an index into the element's plain textContent. */
4588
+ function textOffsetIn(source, container, offset) {
4589
+ try {
4590
+ const walker = document.createTreeWalker(source, typeof NodeFilter === 'undefined' ? 4 : NodeFilter.SHOW_TEXT);
4591
+ let total = 0;
4592
+ let node = walker.nextNode();
4593
+ while (node) {
4594
+ if (node === container) return total + offset;
4595
+ total += node.nodeValue ? node.nodeValue.length : 0;
4596
+ node = walker.nextNode();
4597
+ }
4598
+ if (container.nodeType !== 1) return total;
4599
+ // An element boundary: sum the text before its child at `offset`.
4600
+ let before = 0;
4601
+ const probe = document.createRange();
4602
+ probe.selectNodeContents(source);
4603
+ try {
4604
+ probe.setEnd(container, offset);
4605
+ } catch (_error) {
4606
+ return total;
4607
+ }
4608
+ const inner = document.createTreeWalker(source, typeof NodeFilter === 'undefined' ? 4 : NodeFilter.SHOW_TEXT);
4609
+ let text = inner.nextNode();
4610
+ while (text) {
4611
+ const nodeRange = document.createRange();
4612
+ nodeRange.selectNodeContents(text);
4613
+ if (probe.compareBoundaryPoints(Range.END_TO_END, nodeRange) >= 0) {
4614
+ before += text.nodeValue ? text.nodeValue.length : 0;
4615
+ }
4616
+ text = inner.nextNode();
4617
+ }
4618
+ return before;
4619
+ } catch (_error) {
4620
+ return 0;
4621
+ }
4622
+ }
4623
+
4624
+ /**
4625
+ * Capture the selected assistant text as a value anchor. Runs while the
4626
+ * gesture still owns the selection, so it reads the live DOM once and never
4627
+ * depends on that DOM again.
4628
+ */
4629
+ function captureNoteAnchor(sessionId) {
4630
+ try {
4631
+ if (typeof document === 'undefined') return null;
4632
+ const selection = document.getSelection();
4633
+ if (!selection || selection.rangeCount === 0 || selection.isCollapsed) return null;
4634
+ const range = selection.getRangeAt(0);
4635
+ if (!range || range.collapsed) return null;
4636
+ const startNode = range.startContainer;
4637
+ const startElement = startNode && startNode.nodeType === 1 ? startNode : startNode && startNode.parentElement;
4638
+ const endNode = range.endContainer;
4639
+ const endElement = endNode && endNode.nodeType === 1 ? endNode : endNode && endNode.parentElement;
4640
+ if (!startElement || !startElement.closest || !endElement || !endElement.closest) return null;
4641
+ const source = startElement.closest('[data-text-interaction-source]');
4642
+ if (!source || endElement.closest('[data-text-interaction-source]') !== source) return null;
4643
+ const row = source.closest('[data-chat-flow-kind]');
4644
+ if (!row || row.getAttribute('data-chat-flow-kind') !== 'assistant-step') return null;
4645
+ const keyed = source.closest('[data-chat-node-key]');
4646
+ const nodeKey = keyed ? keyed.getAttribute('data-chat-node-key') || '' : '';
4647
+ if (!nodeKey) return null;
4648
+ const rawQuote = range.toString();
4649
+ const quote = rawQuote.trim();
4650
+ if (!quote) return null;
4651
+ // A browser selection often starts on the whitespace that ends the
4652
+ // previous line; trimmed here so the anchor (and its inline badge) starts
4653
+ // on the first visible character instead of the line above.
4654
+ const lead = rawQuote.length - rawQuote.trimStart().length;
4655
+ // Offsets are stored against the element's textContent (block boundaries
4656
+ // are not characters there), which is also what resolution walks.
4657
+ const offset = textOffsetIn(source, range.startContainer, range.startOffset) + lead;
4658
+ const text = source.textContent || '';
4659
+ const prefix = text.slice(Math.max(0, offset - 24), offset);
4660
+ const suffix = text.slice(offset + quote.length, offset + quote.length + 24);
4661
+ let rowIndex = 0;
4662
+ const scroll = noteChatRoot(sessionId);
4663
+ if (scroll) {
4664
+ const rows = scroll.querySelectorAll('[data-chat-node-key]');
4665
+ // A row that is not in this list (a nested copy, a paging remount) must
4666
+ // sort last rather than first: order 0 would put a later note above the
4667
+ // earlier ones and drag their cards down with it.
4668
+ const at = Array.prototype.indexOf.call(rows, keyed);
4669
+ rowIndex = at >= 0 ? at : rows.length;
4670
+ }
4671
+ return { nodeKey, quote, prefix, suffix, offset, order: rowIndex * 1000000 + offset };
4672
+ } catch (_error) {
4673
+ return null;
4674
+ }
4675
+ }
4676
+
4677
+ /**
4678
+ * Find the stored quote inside one element's text. Context match wins over
4679
+ * the stored offset, because a reply can be re-rendered with different
4680
+ * neighbour nodes while its text stays the same.
4681
+ */
4682
+ function locateQuote(text, quote, prefix, suffix, offset) {
4683
+ if (!text || !quote) return -1;
4684
+ let best = -1;
4685
+ let bestScore = -Infinity;
4686
+ let index = text.indexOf(quote);
4687
+ while (index >= 0) {
4688
+ let score = 0;
4689
+ if (prefix && text.slice(Math.max(0, index - prefix.length), index) === prefix) score += 2;
4690
+ if (suffix && text.slice(index + quote.length, index + quote.length + suffix.length) === suffix) score += 2;
4691
+ score -= Math.abs(index - offset) / Math.max(1, text.length);
4692
+ if (score > bestScore) {
4693
+ bestScore = score;
4694
+ best = index;
4695
+ }
4696
+ index = text.indexOf(quote, index + 1);
4697
+ }
4698
+ return best;
4699
+ }
4700
+
4701
+ /** Collapse whitespace runs for a tolerant comparison. */
4702
+ function collapseWhitespace(value) {
4703
+ return String(value || '').replace(/\s+/g, ' ').trim();
4704
+ }
4705
+
4706
+ /** One collapsed string plus, per character, its index in the original. */
4707
+ function collapsedText(text) {
4708
+ const chars = [];
4709
+ const positions = [];
4710
+ let pendingSpace = false;
4711
+ for (let index = 0; index < text.length; index += 1) {
4712
+ const char = text[index];
4713
+ if (/\s/u.test(char)) {
4714
+ pendingSpace = chars.length > 0;
4715
+ continue;
4716
+ }
4717
+ if (pendingSpace) {
4718
+ chars.push(' ');
4719
+ positions.push(index);
4720
+ pendingSpace = false;
4721
+ }
4722
+ chars.push(char);
4723
+ positions.push(index);
4724
+ }
4725
+ return { text: chars.join(''), positions };
4726
+ }
4727
+
4728
+ /**
4729
+ * The span of one quoted passage inside a source's text. The exact match wins;
4730
+ * a re-render can serialize the same words with different whitespace, so a
4731
+ * collapsed comparison is the fallback.
4732
+ */
4733
+ function findQuoteSpan(text, quote, prefix, suffix, offset) {
4734
+ if (!text || !quote) return null;
4735
+ // Older anchors may carry the whitespace that ended the previous line; the
4736
+ // passage itself starts on the first visible character.
4737
+ const clean = String(quote).trim();
4738
+ if (!clean) return null;
4739
+ const exact = locateQuote(text, clean, prefix, suffix, offset);
4740
+ if (exact >= 0) return { start: exact, end: exact + clean.length };
4741
+ const target = collapseWhitespace(clean);
4742
+ if (!target) return null;
4743
+ const collapsed = collapsedText(text);
4744
+ const at = collapsed.text.indexOf(target);
4745
+ if (at < 0) return null;
4746
+ const start = collapsed.positions[at];
4747
+ const end = collapsed.positions[at + target.length - 1] + 1;
4748
+ return end > start ? { start, end } : null;
4749
+ }
4750
+
4751
+ /** Build a live DOM Range for a character span of one element's text. */
4752
+ function rangeFromTextOffset(source, start, length) {
4753
+ if (typeof document === 'undefined' || length <= 0) return null;
4754
+ try {
4755
+ const walker = document.createTreeWalker(source, typeof NodeFilter === 'undefined' ? 4 : NodeFilter.SHOW_TEXT);
4756
+ let node = walker.nextNode();
4757
+ let consumed = 0;
4758
+ let from = null;
4759
+ while (node) {
4760
+ const size = node.nodeValue ? node.nodeValue.length : 0;
4761
+ if (from === null && consumed + size >= start) from = { node, offset: start - consumed };
4762
+ if (from !== null && consumed + size >= start + length) {
4763
+ const range = document.createRange();
4764
+ range.setStart(from.node, from.offset);
4765
+ range.setEnd(node, start + length - consumed);
4766
+ return range;
4767
+ }
4768
+ consumed += size;
4769
+ node = walker.nextNode();
4770
+ }
4771
+ } catch (_error) {
4772
+ /* a half-built tree during a re-render */
4773
+ }
4774
+ return null;
4775
+ }
4776
+
4777
+ /**
4778
+ * The main conversation's scroll container. The sidebar renders session
4779
+ * previews with the same conversation attributes, so pick the container that
4780
+ * belongs to this session and owns the composer (previews own neither).
4781
+ */
4782
+ function noteChatRoot(sessionId) {
4783
+ if (typeof document === 'undefined') return null;
4784
+ const candidates = Array.from(document.querySelectorAll('[data-conversation-scroll]'));
4785
+ if (candidates.length === 0) return null;
4786
+ const sameSession = sessionId
4787
+ ? candidates.filter((element) => {
4788
+ const owner = element.closest('[data-conversation-session]');
4789
+ return owner !== null && owner.getAttribute('data-conversation-session') === sessionId;
4790
+ })
4791
+ : [];
4792
+ const pool = sameSession.length > 0 ? sameSession : candidates;
4793
+ const withComposer = pool.filter((element) => element.querySelector('[data-composer-seat]') !== null);
4794
+ const preferred = withComposer.length > 0 ? withComposer : pool;
4795
+ let best = null;
4796
+ let bestWidth = 0;
4797
+ for (const element of preferred) {
4798
+ const rect = element.getBoundingClientRect();
4799
+ if (rect.height > 0 && rect.width > bestWidth) {
4800
+ best = element;
4801
+ bestWidth = rect.width;
4802
+ }
4803
+ }
4804
+ return best || preferred[0] || null;
4805
+ }
4806
+
4807
+
4808
+ /** Resolve an anchor or a stored note to its live range and transcript row. */
4809
+ function resolveNote(anchor, root) {
4810
+ if (!root || !anchor || typeof document === 'undefined') return null;
4811
+ const rows = root.querySelectorAll('[data-chat-node-key]');
4812
+ // Prefer the row the note was captured from; if its key changed, the same
4813
+ // words can still be found elsewhere in the transcript.
4814
+ const ordered = [];
4815
+ const rest = [];
4816
+ for (const row of rows) {
4817
+ if (row.getAttribute('data-chat-node-key') === anchor.nodeKey) ordered.push(row);
4818
+ else rest.push(row);
4819
+ }
4820
+ for (const row of [...ordered, ...rest]) {
4821
+ const sources = row.querySelectorAll('[data-text-interaction-source]');
4822
+ for (const source of sources) {
4823
+ const text = source.textContent || '';
4824
+ const span = findQuoteSpan(text, anchor.quote, anchor.prefix, anchor.suffix, anchor.offset);
4825
+ if (!span) continue;
4826
+ const range = rangeFromTextOffset(source, span.start, span.end - span.start);
4827
+ if (range) return { range, row };
4828
+ }
4829
+ }
4830
+ return null;
4831
+ }
4832
+
4833
+ /** The range alone, for callers that only need to paint or scroll it. */
4834
+ function resolveNoteRange(anchor, root) {
4835
+ const resolved = resolveNote(anchor, root);
4836
+ return resolved ? resolved.range : null;
4837
+ }
4838
+
4839
+ /** Paint every annotated range, tinted by its kind. */
4840
+ function applyNoteHighlights(items) {
4841
+ try {
4842
+ // The module has its own `CSS` string for the pool panel, so reach for
4843
+ // the browser namespace explicitly.
4844
+ const registry = typeof globalThis === 'undefined' ? undefined : globalThis.CSS;
4845
+ const HighlightType = typeof globalThis === 'undefined' ? undefined : globalThis.Highlight;
4846
+ if (!registry || !registry.highlights || typeof HighlightType !== 'function') return;
4847
+ for (const id of NOTE_KIND_IDS) registry.highlights.delete(NOTE_HIGHLIGHT + '-' + id);
4848
+ if (!items || items.length === 0) return;
4849
+ const buckets = new Map();
4850
+ for (const item of items) {
4851
+ if (!item || !item.range) continue;
4852
+ const id = noteKind(item.kind).id;
4853
+ if (!buckets.has(id)) buckets.set(id, []);
4854
+ buckets.get(id).push(item.range);
4855
+ }
4856
+ for (const [id, ranges] of buckets) {
4857
+ registry.highlights.set(NOTE_HIGHLIGHT + '-' + id, new HighlightType(...ranges));
4858
+ }
4859
+ } catch (_error) {
4860
+ /* older engines: the inline badges still work */
4861
+ }
4862
+ }
4863
+
4864
+ /**
4865
+ * Pins, highlights and the inline editor, drawn into the frame-wide overlay.
4866
+ * The markdown DOM is never touched: live ranges are measured and the layer is
4867
+ * positioned over them, so selection, copy and the host's rendering still work.
4868
+ */
4869
+ function NotesLayer() {
4870
+ useLocaleTick();
4871
+ const notesState = useNotesState();
4872
+ const view = useChatView();
4873
+ const draft = useNoteDraft();
4874
+ const focus = useNoteFocus();
4875
+ const prompt = useNotePrompt();
4876
+ const confirm = useNoteConfirm();
4877
+ const pool = usePoolState();
4878
+ const [editing, setEditing] = useState(null);
4879
+ const [body, setBody] = useState('');
4880
+ const [kind, setKind] = useState(NOTE_KIND_DEFAULT);
4881
+ const [missing, setMissing] = useState(false);
4882
+ const [anchorPoint, setAnchorPoint] = useState(null);
4883
+ const bubbleRef = useRef(null);
4884
+ const frameRef = useRef(0);
4885
+ const sessionId = view.sessionId;
4886
+ const sessionNotes = notesState.items
4887
+ .filter((note) => note.sessionId === sessionId)
4888
+ .sort((left, right) => (left.order - right.order) || (left.createdAt - right.createdAt));
4889
+ const notesRef = useRef(sessionNotes);
4890
+ notesRef.current = sessionNotes;
4891
+ // The open editor's passage: highlighted (and tinted by the pending kind)
4892
+ // before anything is saved, and dropped again when the bubble closes.
4893
+ const draftRef = useRef(null);
4894
+ draftRef.current = editing ? { id: editing.id || '', anchor: editing.anchor || null, kind } : null;
4895
+ const highlightOn = !pool.settings || pool.settings.notesHighlight !== false;
4896
+ const highlightRef = useRef(highlightOn);
4897
+ highlightRef.current = highlightOn;
4898
+
4899
+ /**
4900
+ * The last visible character of a passage. Trailing whitespace in the
4901
+ * selection is skipped so the badge sits right after the text.
4902
+ */
4903
+ const visibleEnd = (range) => {
4904
+ try {
4905
+ const take = (node, offset) => {
4906
+ const data = node.nodeValue || '';
4907
+ let at = Math.min(offset, data.length);
4908
+ while (at > 0 && /\s/.test(data[at - 1])) at -= 1;
4909
+ return at > 0 ? { node, offset: at } : null;
4910
+ };
4911
+ if (range.endContainer.nodeType === 3) {
4912
+ const hit = take(range.endContainer, range.endOffset);
4913
+ if (hit) return hit;
4914
+ }
4915
+ const walker = document.createTreeWalker(range.commonAncestorContainer, typeof NodeFilter === 'undefined' ? 4 : NodeFilter.SHOW_TEXT);
4916
+ let node = walker.nextNode();
4917
+ let last = null;
4918
+ while (node) {
4919
+ const position = range.comparePoint(node, 0);
4920
+ if (position === 1) break;
4921
+ if (position === 0 || node === range.startContainer) last = node;
4922
+ node = walker.nextNode();
4923
+ }
4924
+ if (last) {
4925
+ const hit = take(last, last.nodeValue ? last.nodeValue.length : 0);
4926
+ if (hit) return hit;
4927
+ }
4928
+ } catch (_error) {
4929
+ /* fall back to the range's own end */
4930
+ }
4931
+ return { node: range.endContainer, offset: range.endOffset };
4932
+ };
4933
+
4934
+ /**
4935
+ * The inline badge: a short chip inserted right before the passage. It is
4936
+ * foreign to the host's React tree, so it is re-inserted whenever a
4937
+ * re-render drops it; the chip itself carries no text the transcript would
4938
+ * copy (it is user-select:none and clickable).
4939
+ */
4940
+ const insertChip = (range, note, meta, shown) => {
4941
+ if (!range || !range.startContainer) return;
4942
+ try {
4943
+ const chip = document.createElement('span');
4944
+ chip.className = 'pp-note-inline';
4945
+ chip.setAttribute('data-pp-inline', note.id);
4946
+ chip.setAttribute('data-kind', meta.id);
4947
+ chip.setAttribute('data-text', shown);
4948
+ chip.setAttribute('data-version', NOTE_CHIP_VERSION);
4949
+ chip.setAttribute('role', 'button');
4950
+ chip.setAttribute('tabindex', '0');
4951
+ chip.setAttribute('title', shown ? `${translate(meta.label)}:${shown}` : translate(meta.label));
4952
+ const icon = document.createElement('span');
4953
+ icon.className = 'pp-note-inline-icon';
4954
+ icon.textContent = meta.icon;
4955
+ const text = document.createElement('span');
4956
+ text.className = 'pp-note-inline-text';
4957
+ // A kind-only note is just its glyph.
4958
+ text.textContent = shown;
4959
+ chip.appendChild(icon);
4960
+ if (shown) chip.appendChild(text);
4961
+ const open = (event) => {
4962
+ event.preventDefault();
4963
+ event.stopPropagation();
4964
+ openNote(note.id);
4965
+ };
4966
+ chip.addEventListener('click', open);
4967
+ chip.addEventListener('pointerdown', (event) => {
4968
+ // Keep the pointer from starting a text selection; the click itself
4969
+ // still has to reach the badge.
4970
+ event.stopPropagation();
4971
+ });
4972
+ chip.addEventListener('keydown', (event) => {
4973
+ if (event.key === 'Enter' || event.key === ' ') open(event);
4974
+ });
4975
+ const at = document.createRange();
4976
+ const end = visibleEnd(range);
4977
+ at.setStart(end.node, end.offset);
4978
+ at.collapse(true);
4979
+ at.insertNode(chip);
4980
+ } catch (_error) {
4981
+ /* the passage moved or the node refused insertion; the tab still lists it */
4982
+ }
4983
+ };
4984
+
4985
+ const syncChips = () => {
4986
+ if (typeof document === 'undefined') return;
4987
+ const root = noteChatRoot(sessionId);
4988
+ if (!root) return;
4989
+ const wanted = new Map();
4990
+ for (const note of notesRef.current) wanted.set(note.id, note);
4991
+ // A fresh layer (or a session switch) rebuilds every badge once, so
4992
+ // anchors placed by an older insertion rule are corrected too.
4993
+ const resetKey = sessionId;
4994
+ const fresh = chipResetRef.current !== resetKey;
4995
+ chipResetRef.current = resetKey;
4996
+ if (fresh) {
4997
+ for (const chip of root.querySelectorAll('[data-pp-inline]')) chip.remove();
4998
+ }
4999
+ for (const chip of root.querySelectorAll('[data-pp-inline]')) {
5000
+ if (!wanted.has(chip.getAttribute('data-pp-inline'))) chip.remove();
5001
+ }
5002
+ for (const note of wanted.values()) {
5003
+ const meta = noteKind(note.kind);
5004
+ const shown = noteBodyText(note.body);
5005
+ const existing = root.querySelector('[data-pp-inline="' + note.id + '"]');
5006
+ if (existing) {
5007
+ const same = existing.getAttribute('data-kind') === meta.id
5008
+ && existing.getAttribute('data-text') === shown
5009
+ && existing.getAttribute('data-version') === NOTE_CHIP_VERSION;
5010
+ if (same) continue;
5011
+ existing.remove();
5012
+ }
5013
+ const hit = resolveNote(note, root);
5014
+ if (!hit) continue;
5015
+ // A streaming row rebuilds every token; only settled text keeps a badge.
5016
+ if (hit.row && hit.row.querySelector('[data-streaming]')) continue;
5017
+ insertChip(hit.range, note, meta, shown);
5018
+ }
5019
+ };
5020
+ const syncRef = useRef(syncChips);
5021
+ syncRef.current = syncChips;
5022
+ const chipResetRef = useRef('');
5023
+
5024
+ const measure = useCallback(() => {
5025
+ const list = notesRef.current;
5026
+ const root = noteChatRoot(sessionId);
5027
+ if (!root || list.length === 0) {
5028
+ applyNoteHighlights([]);
5029
+ return;
5030
+ }
5031
+ const items = [];
5032
+ for (const note of list) {
5033
+ const hit = resolveNote(note, root);
5034
+ if (hit) items.push({ id: note.id, range: hit.range, kind: note.kind });
5035
+ }
5036
+ // The open bubble's passage is underlined immediately, following the
5037
+ // pending kind until Save or Cancel.
5038
+ const draftNote = draftRef.current;
5039
+ if (draftNote) {
5040
+ if (draftNote.id) {
5041
+ const at = items.findIndex((item) => item.id === draftNote.id);
5042
+ if (at >= 0) items[at] = { ...items[at], kind: draftNote.kind };
5043
+ else {
5044
+ const note = notesRef.current.find((entry) => entry.id === draftNote.id);
5045
+ const hit = note ? resolveNote(note, root) : null;
5046
+ if (hit) items.push({ id: draftNote.id, range: hit.range, kind: draftNote.kind });
5047
+ }
5048
+ } else if (draftNote.anchor) {
5049
+ const range = resolveNoteRange(draftNote.anchor, root);
5050
+ if (range) items.push({ id: '', range, kind: draftNote.kind });
5051
+ }
5052
+ }
5053
+ if (highlightRef.current) applyNoteHighlights(items);
5054
+ else applyNoteHighlights([]);
5055
+ }, [sessionId]);
5056
+
5057
+ useEffect(() => {
5058
+ if (typeof document === 'undefined') return undefined;
5059
+ const root = noteChatRoot(sessionId);
5060
+ if (!root || notesRef.current.length === 0) {
5061
+ applyNoteHighlights([]);
5062
+ return undefined;
5063
+ }
5064
+ // The flow can mount after the effect (switching back to Chat from another
5065
+ // view); the observer below schedules a measure once its rows appear.
5066
+ const schedule = () => {
5067
+ if (frameRef.current) return;
5068
+ const run = () => {
5069
+ frameRef.current = 0;
5070
+ measure();
5071
+ syncRef.current();
5072
+ };
5073
+ frameRef.current = typeof window !== 'undefined' && window.requestAnimationFrame
5074
+ ? window.requestAnimationFrame(run)
5075
+ : window.setTimeout(run, 16);
5076
+ };
5077
+ root.addEventListener('scroll', schedule, true);
5078
+ window.addEventListener('resize', schedule);
5079
+ const resizer = typeof ResizeObserver === 'function' ? new ResizeObserver(schedule) : null;
5080
+ if (resizer) resizer.observe(root);
5081
+ const observer = typeof MutationObserver === 'function' ? new MutationObserver(schedule) : null;
5082
+ if (observer) observer.observe(root, { childList: true, subtree: true, characterData: true });
5083
+ schedule();
5084
+ return () => {
5085
+ root.removeEventListener('scroll', schedule, true);
5086
+ window.removeEventListener('resize', schedule);
5087
+ if (resizer) resizer.disconnect();
5088
+ if (observer) observer.disconnect();
5089
+ if (frameRef.current && typeof window !== 'undefined' && window.cancelAnimationFrame) window.cancelAnimationFrame(frameRef.current);
5090
+ frameRef.current = 0;
5091
+ };
5092
+ }, [measure, sessionId, sessionNotes.length]);
5093
+
5094
+ // Adding, editing or deleting a note redraws the inline badges; the text
5095
+ // itself never changes.
5096
+ useEffect(() => {
5097
+ syncRef.current();
5098
+ }, [notesState.items, sessionId]);
5099
+
5100
+ useEffect(() => {
5101
+ if (!draft.anchor || (draft.sessionId && draft.sessionId !== sessionId)) return;
5102
+ setEditing({ id: '', anchor: draft.anchor, body: '' });
5103
+ setBody('');
5104
+ setKind(NOTE_KIND_DEFAULT);
5105
+ setMissing(false);
5106
+ // The bubble follows the passage, so the note is written where it belongs.
5107
+ const root = noteChatRoot(sessionId);
5108
+ const range = root ? resolveNoteRange(draft.anchor, root) : null;
5109
+ if (range && root) {
5110
+ const rect = range.getBoundingClientRect();
5111
+ setAnchorPoint({ x: rect.right, y: Math.round(rect.top + rect.height / 2) });
5112
+ const box = root.getBoundingClientRect();
5113
+ if (rect.top < box.top + 40 || rect.bottom > box.bottom - 40) {
5114
+ root.scrollTop += rect.top - box.top - Math.min(120, box.height / 3);
5115
+ }
5116
+ } else {
5117
+ setAnchorPoint(null);
5118
+ }
5119
+ noteDraft.set({ anchor: null, sessionId: '', token: 0 });
5120
+ }, [draft.anchor, draft.sessionId, draft.token, sessionId]);
5121
+
5122
+ // The open bubble's passage is underlined while it is being written; a
5123
+ // kind switch re-tints it live instead of waiting for Save.
5124
+ useEffect(() => {
5125
+ measure();
5126
+ }, [editing, kind, measure]);
5127
+
5128
+ // The floating popups (group picker, delete confirmation); a click outside
5129
+ // or Escape puts them away without changing anything.
5130
+ useEffect(() => {
5131
+ if ((!prompt.open && !confirm.open) || typeof document === 'undefined') return undefined;
5132
+ const onDown = (event) => {
5133
+ const element = event.target instanceof Element ? event.target : null;
5134
+ if (element && element.closest && element.closest('.pp-note-prompt')) return;
5135
+ closeNotePrompt();
5136
+ closeNoteConfirm();
5137
+ };
5138
+ const onKey = (event) => {
5139
+ if (event.key !== 'Escape') return;
5140
+ closeNotePrompt();
5141
+ closeNoteConfirm();
5142
+ };
5143
+ document.addEventListener('pointerdown', onDown, true);
5144
+ document.addEventListener('keydown', onKey, true);
5145
+ return () => {
5146
+ document.removeEventListener('pointerdown', onDown, true);
5147
+ document.removeEventListener('keydown', onKey, true);
5148
+ };
5149
+ }, [prompt.open, prompt.token, confirm.open, confirm.token]);
5150
+
5151
+ useEffect(() => {
5152
+ if (!focus.id) return;
5153
+ const note = notesState.items.find((entry) => entry.id === focus.id);
5154
+ const wantsEditor = focus.edit === true;
5155
+ noteFocus.set({ id: '', token: 0, edit: false });
5156
+ if (!note) return;
5157
+ const root = noteChatRoot(sessionId);
5158
+ const range = root ? resolveNoteRange(note, root) : null;
5159
+ // 定位 means locate: scroll the passage into view (editing is explicit).
5160
+ // only an explicit edit opens the bubble.
5161
+ if (!wantsEditor) {
5162
+ if (!range || !root) return;
5163
+ const rect = range.getBoundingClientRect();
5164
+ const box = root.getBoundingClientRect();
5165
+ if (rect.top < box.top + 40 || rect.bottom > box.bottom - 40) {
5166
+ root.scrollTop += rect.top - box.top - Math.min(120, box.height / 3);
5167
+ }
5168
+ return;
5169
+ }
5170
+ setEditing({ id: note.id, anchor: null, body: note.body });
5171
+ setBody(note.body);
5172
+ setMissing(!range);
5173
+ if (range) {
5174
+ setAnchorPoint({ x: range.getBoundingClientRect().right, y: Math.round(range.getBoundingClientRect().top + range.getBoundingClientRect().height / 2) });
5175
+ } else {
5176
+ setAnchorPoint(null);
5177
+ }
5178
+ if (range && root) {
5179
+ const rect = range.getBoundingClientRect();
5180
+ const box = root.getBoundingClientRect();
5181
+ if (rect.top < box.top + 40 || rect.bottom > box.bottom - 40) {
5182
+ root.scrollTop += rect.top - box.top - Math.min(120, box.height / 3);
5183
+ }
5184
+ }
5185
+ }, [focus.id, focus.token, notesState.items]);
5186
+
5187
+
5188
+ useEffect(() => {
5189
+ if (highlightOn) return;
5190
+ applyNoteHighlights([]);
5191
+ }, [highlightOn]);
5192
+
5193
+ useEffect(() => () => {
5194
+ applyNoteHighlights([]);
5195
+ }, []);
5196
+
5197
+
5198
+ /** Open one saved note; its pin is on screen, so the bubble anchors there. */
5199
+ const openNote = (id) => {
5200
+ const note = notesRef.current.find((entry) => entry.id === id);
5201
+ if (!note) return;
5202
+ setEditing({ id, anchor: null, body: note.body });
5203
+ setBody(note.body);
5204
+ setKind(noteKind(note.kind).id);
5205
+ setMissing(false);
5206
+ const root = noteChatRoot(sessionId);
5207
+ const range = root ? resolveNoteRange(note, root) : null;
5208
+ if (range) {
5209
+ const rect = range.getBoundingClientRect();
5210
+ setAnchorPoint({ x: rect.right, y: Math.round(rect.top + rect.height / 2) });
5211
+ } else {
5212
+ setAnchorPoint(null);
5213
+ }
5214
+ };
5215
+
5216
+ const cancelEditing = () => {
5217
+ setEditing(null);
5218
+ setBody('');
5219
+ setMissing(false);
5220
+ setAnchorPoint(null);
5221
+ };
5222
+
5223
+ const save = () => {
5224
+ if (!editing) return;
5225
+ const value = body.trim();
5226
+ if (editing.id) {
5227
+ notesActions.patch(editing.id, { body: value, kind });
5228
+ } else if (editing.anchor) {
5229
+ notesActions.add({
5230
+ id: uid(),
5231
+ sessionId,
5232
+ nodeKey: editing.anchor.nodeKey,
5233
+ quote: editing.anchor.quote,
5234
+ prefix: editing.anchor.prefix,
5235
+ suffix: editing.anchor.suffix,
5236
+ offset: editing.anchor.offset,
5237
+ order: editing.anchor.order,
5238
+ kind,
5239
+ body: value,
5240
+ createdAt: Date.now(),
5241
+ updatedAt: Date.now(),
5242
+ });
5243
+ }
5244
+ setEditing(null);
5245
+ setBody('');
5246
+ setAnchorPoint(null);
5247
+ };
5248
+
5249
+ const removeEditing = () => {
5250
+ if (!editing || !editing.id) return;
5251
+ notesActions.remove(editing.id);
5252
+ setEditing(null);
5253
+ setBody('');
5254
+ setAnchorPoint(null);
5255
+ };
5256
+
5257
+ // Clicking anywhere else saves a non-empty note and drops an empty draft.
5258
+ useEffect(() => {
5259
+ if (!editing || typeof document === 'undefined') return undefined;
5260
+ const onDown = (event) => {
5261
+ const bubble = bubbleRef.current;
5262
+ if (bubble && event.target instanceof Node && bubble.contains(event.target)) return;
5263
+ const element = event.target instanceof Element ? event.target : null;
5264
+ if (element && element.closest && element.closest('.pp-note-prompt')) return;
5265
+ if (body.trim()) save();
5266
+ else cancelEditing();
5267
+ };
5268
+ document.addEventListener('pointerdown', onDown, true);
5269
+ return () => document.removeEventListener('pointerdown', onDown, true);
5270
+ });
5271
+
5272
+ const onEditorKeyDown = (event) => {
5273
+ if (event.key === 'Escape') {
5274
+ event.preventDefault();
5275
+ cancelEditing();
5276
+ return;
5277
+ }
5278
+ if (event.key === 'Enter' && (event.metaKey || event.ctrlKey)) {
5279
+ event.preventDefault();
5280
+ save();
5281
+ }
5282
+ };
5283
+
5284
+ const editingNote = editing && editing.id ? sessionNotes.find((note) => note.id === editing.id) : null;
5285
+ const point = anchorPoint;
5286
+ const docElement = typeof document === 'undefined' ? null : document.documentElement;
5287
+ const viewportWidth = typeof window === 'undefined'
5288
+ ? 0
5289
+ : Math.min(window.innerWidth, (docElement && docElement.clientWidth) || window.innerWidth);
5290
+ const viewportHeight = typeof window === 'undefined'
5291
+ ? 0
5292
+ : Math.min(window.innerHeight, (docElement && docElement.clientHeight) || window.innerHeight);
5293
+ // The bubble opens on the passage's right, but flips to its left when the
5294
+ // right edge would land on the window border or its scrollbar (the save
5295
+ // button used to sit on the scrollbar and could not be clicked).
5296
+ const bubbleStyle = point && viewportWidth > 0
5297
+ ? (() => {
5298
+ const width = 300;
5299
+ const margin = 16;
5300
+ const right = point.x + 14;
5301
+ const left = right + width <= viewportWidth - margin
5302
+ ? right
5303
+ : Math.max(margin, point.x - width - 14);
5304
+ const top = Math.min(Math.max(margin, point.y - 24), Math.max(margin, viewportHeight - 250));
5305
+ return {
5306
+ left: Math.round(Math.max(margin, Math.min(left, viewportWidth - width - margin))) + 'px',
5307
+ top: Math.round(top) + 'px',
5308
+ };
5309
+ })()
5310
+ : { left: '50%', top: '38%', transform: 'translate(-50%, -50%)' };
5311
+
5312
+ // The group popup: anchored under the button that opened it, flipped above
5313
+ // when it would leave the frame, and always in the overlay (never clipped
5314
+ // by the pool list).
5315
+ const placePopup = (anchor, width, height) => {
5316
+ if (!anchor) return null;
5317
+ const docElement = typeof document === 'undefined' ? null : document.documentElement;
5318
+ const vw = typeof window === 'undefined' ? 0 : Math.min(window.innerWidth, (docElement && docElement.clientWidth) || window.innerWidth);
5319
+ const vh = typeof window === 'undefined' ? 0 : Math.min(window.innerHeight, (docElement && docElement.clientHeight) || window.innerHeight);
5320
+ // Right-aligned with the button when left-alignment would leave the frame.
5321
+ const left = anchor.left + width + 8 <= vw ? anchor.left : anchor.right - width;
5322
+ const x = Math.max(8, Math.min(left, Math.max(8, vw - width - 8)));
5323
+ let y = anchor.bottom + 6;
5324
+ if (y + height > vh - 8) y = Math.max(8, anchor.top - height - 6);
5325
+ return { left: Math.round(x) + 'px', top: Math.round(y) + 'px' };
5326
+ };
5327
+ const promptStyle = prompt.open && prompt.anchor ? placePopup(prompt.anchor, 210, 280) : null;
5328
+ const confirmStyle = confirm.open && confirm.anchor ? placePopup(confirm.anchor, 240, 110) : null;
5329
+
5330
+ return h(
5331
+ 'div',
5332
+ { className: 'pp-note-layer' },
5333
+ h('style', { key: 'css' }, NOTES_CSS),
5334
+ prompt.open && promptStyle
5335
+ ? h(
5336
+ 'div',
5337
+ {
5338
+ key: 'prompt',
5339
+ className: 'pp-note-prompt',
5340
+ style: promptStyle,
5341
+ role: 'dialog',
5342
+ 'aria-label': translate('capture.title'),
5343
+ onPointerDown: (event) => event.stopPropagation(),
5344
+ },
5345
+ h('div', { key: 'title', className: 'pp-note-prompt-title' }, translate('capture.title')),
5346
+ h(
5347
+ 'div',
5348
+ { key: 'list', className: 'pp-note-prompt-list' },
5349
+ (prompt.choices || []).map((choice) => h(
5350
+ 'button',
5351
+ {
5352
+ key: choice.value,
5353
+ type: 'button',
5354
+ className: 'pp-note-prompt-row',
5355
+ onClick: () => {
5356
+ const pick = notePrompt.get().onPick;
5357
+ if (typeof pick === 'function') pick(choice.value);
5358
+ },
5359
+ },
5360
+ h('span', { key: 'name', className: 'pp-note-prompt-name' }, choice.label),
5361
+ choice.value === prompt.defaultValue
5362
+ ? h('span', { key: 'default', className: 'pp-note-prompt-tag' }, translate('note.default'))
5363
+ : null,
5364
+ )),
5365
+ ),
5366
+ h('div', { key: 'sep', className: 'pp-note-prompt-sep' }),
5367
+ h('button', { key: 'cancel', type: 'button', className: 'pp-note-prompt-row pp-note-prompt-cancel', onClick: () => closeNotePrompt() }, translate('note.cancel')),
5368
+ )
5369
+ : null,
5370
+ confirm.open && confirmStyle
5371
+ ? h(
5372
+ 'div',
5373
+ {
5374
+ key: 'confirm',
5375
+ className: 'pp-note-prompt',
5376
+ style: confirmStyle,
5377
+ role: 'alertdialog',
5378
+ 'aria-label': translate('note.deleteConfirm'),
5379
+ onPointerDown: (event) => event.stopPropagation(),
5380
+ },
5381
+ h('div', { key: 'msg', className: 'pp-note-prompt-message' }, translate('note.deleteConfirm')),
5382
+ h(
5383
+ 'div',
5384
+ { key: 'actions', className: 'pp-note-prompt-actions' },
5385
+ h('button', { key: 'no', type: 'button', className: 'pp-note-btn', onClick: () => closeNoteConfirm() }, translate('note.cancel')),
5386
+ h(
5387
+ 'button',
5388
+ {
5389
+ key: 'yes',
5390
+ type: 'button',
5391
+ className: 'pp-note-btn pp-note-btn-danger',
5392
+ onClick: () => {
5393
+ const run = noteConfirm.get().onConfirm;
5394
+ closeNoteConfirm();
5395
+ if (typeof run === 'function') run();
5396
+ },
5397
+ },
5398
+ translate('note.delete'),
5399
+ ),
5400
+ ),
5401
+ )
5402
+ : null,
5403
+ editing
5404
+ ? h(
5405
+ 'div',
5406
+ {
5407
+ key: 'bubble',
5408
+ ref: bubbleRef,
5409
+ className: 'pp-note-bubble',
5410
+ style: { ...bubbleStyle, '--pp-bubble-tint': noteKind(kind).tint },
5411
+ 'data-kind': kind,
5412
+ onPointerDown: (event) => event.stopPropagation(),
5413
+ },
5414
+ h(
5415
+ 'div',
5416
+ { className: 'pp-note-bubble-quote' },
5417
+ h('span', { className: 'pp-note-bubble-quote-icon' }, noteKind(kind).icon),
5418
+ noteQuoteText(editingNote ? editingNote.quote : editing.anchor.quote, 10),
5419
+ ),
5420
+ missing
5421
+ ? h(
5422
+ 'div',
5423
+ { className: 'pp-note-bubble-hint' },
5424
+ translate('note.quoteMissing'),
5425
+ )
5426
+ : null,
5427
+ h(
5428
+ 'div',
5429
+ { className: 'pp-note-kinds' },
5430
+ NOTE_KINDS.map((entry) => h(
5431
+ 'button',
5432
+ {
5433
+ key: entry.id,
5434
+ type: 'button',
5435
+ className: 'pp-note-kind',
5436
+ 'data-kind': entry.id,
5437
+ 'data-active': kind === entry.id ? 'true' : 'false',
5438
+ onClick: () => setKind(entry.id),
5439
+ },
5440
+ h('span', { className: 'pp-note-kind-icon' }, entry.icon),
5441
+ translate(entry.label),
5442
+ )),
5443
+ ),
5444
+ h('textarea', {
5445
+ className: 'pp-note-input',
5446
+ value: body,
5447
+ rows: 2,
5448
+ maxLength: NOTE_BODY_MAX,
5449
+ placeholder: translate('note.placeholder'),
5450
+ autoFocus: true,
5451
+ onChange: (event) => setBody(event.target.value),
5452
+ onKeyDown: onEditorKeyDown,
5453
+ }),
5454
+ h(
5455
+ 'div',
5456
+ { className: 'pp-note-bubble-foot' },
5457
+ editingNote
5458
+ ? h(
5459
+ 'button',
5460
+ {
5461
+ key: 'remove',
5462
+ type: 'button',
5463
+ className: 'pp-note-btn pp-note-btn-quiet-danger',
5464
+ onClick: (event) => openNoteConfirm(removeEditing, event),
5465
+ },
5466
+ translate('note.delete'),
5467
+ )
5468
+ : null,
5469
+ h(
5470
+ 'span',
5471
+ { key: 'limit', className: 'pp-note-limit' },
5472
+ h('span', { className: 'pp-note-limit-count' }, `${body.trim().length}/${NOTE_BODY_MAX}`),
5473
+ ),
5474
+ h(
5475
+ 'div',
5476
+ { key: 'acts', className: 'pp-note-bubble-actions' },
5477
+ h('button', { type: 'button', className: 'pp-note-btn', onClick: cancelEditing }, translate('note.cancel')),
5478
+ h(
5479
+ 'button',
5480
+ { type: 'button', className: 'pp-note-btn pp-note-btn-primary', onClick: save },
5481
+ translate('note.save'),
5482
+ ),
5483
+ ),
5484
+ ),
5485
+ )
5486
+ : null,
5487
+ );
5488
+ }
5489
+
5490
+ /**
5491
+ * The session's annotations, shown as a tab inside both prompt-pool views.
5492
+ * A note can be promoted into a pool group (defaulting to this session's
5493
+ * workspace); the caller keeps the compose path: the composer panel inserts
5494
+ * directly, the sidebar page asks the panel over the bridge.
5495
+ */
5496
+ /** Tiny stroke icons for the annotation row actions. */
5497
+ function NoteActionIcon(props) {
5498
+ const kind = props.kind;
5499
+ const common = {
5500
+ width: 14,
5501
+ height: 14,
5502
+ viewBox: '0 0 20 20',
5503
+ fill: 'none',
5504
+ stroke: 'currentColor',
5505
+ strokeWidth: 1.6,
5506
+ strokeLinecap: 'round',
5507
+ strokeLinejoin: 'round',
5508
+ 'aria-hidden': true,
5509
+ style: { display: 'block' },
5510
+ };
5511
+ if (kind === 'edit') {
5512
+ return h('svg', common, h('path', { d: 'M4 16l.6-3.6 9-9a1.7 1.7 0 0 1 2.4 2.4l-9 9L4 16z' }));
5513
+ }
5514
+ if (kind === 'insert') {
5515
+ return h(
5516
+ 'svg',
5517
+ common,
5518
+ h('path', { d: 'M3.6 12.4h12.8v3.4H3.6z' }),
5519
+ h('path', { d: 'M10 3v6.4' }),
5520
+ h('path', { d: 'M7.4 6.9 10 9.4l2.6-2.5' }),
5521
+ );
5522
+ }
5523
+ if (kind === 'store') {
5524
+ return h(
5525
+ 'svg',
5526
+ common,
5527
+ h('path', { d: 'M10 3v7' }),
5528
+ h('path', { d: 'M7 7.2 10 10l3-2.8' }),
5529
+ h('path', { d: 'M3.6 13.6v2.6h12.8v-2.6' }),
5530
+ );
5531
+ }
5532
+ if (kind === 'locate') {
5533
+ return h(
5534
+ 'svg',
5535
+ common,
5536
+ h('circle', { cx: 10, cy: 10, r: 4.6 }),
5537
+ h('path', { d: 'M10 2.2v2.6M10 15.2v2.6M2.2 10h2.6M15.2 10h2.6' }),
5538
+ );
5539
+ }
5540
+ return h(
5541
+ 'svg',
5542
+ common,
5543
+ h('path', { d: 'M4 6h12' }),
5544
+ h('path', { d: 'M8 6V4h4v2' }),
5545
+ h('path', { d: 'M6 6l.7 10h6.6L14 6' }),
5546
+ );
5547
+ }
5548
+
5549
+ function NotesView(props) {
5550
+ useLocaleTick();
5551
+ const list = Array.isArray(props.notes) ? props.notes : [];
5552
+ const sessionId = typeof props.sessionId === 'string' ? props.sessionId : '';
5553
+ const categories = Array.isArray(props.categories) ? props.categories : [];
5554
+ const workspaceList = Array.isArray(props.workspaces) ? props.workspaces : [];
5555
+ const currentWorkspaceId = typeof props.currentWorkspaceId === 'string' ? props.currentWorkspaceId : '';
5556
+ const filter = typeof props.filter === 'string' ? props.filter.trim().toLowerCase() : '';
5557
+ const matches = (note) => !filter
5558
+ || String(note.quote || '').toLowerCase().indexOf(filter) >= 0
5559
+ || String(note.body || '').toLowerCase().indexOf(filter) >= 0
5560
+ || translate(noteKind(note.kind).label).toLowerCase().indexOf(filter) >= 0;
5561
+
5562
+ const flash = (text, kind) => showToast(text, kind);
5563
+
5564
+ const compose = () => {
5565
+ let ok = false;
5566
+ try {
5567
+ ok = props.onCompose() === true;
5568
+ } catch (_error) {
5569
+ ok = false;
5570
+ }
5571
+ if (ok && normalizeSettings(props.settings).noteKeepAfterDraft === false) {
5572
+ notesActions.clearSession(sessionId);
5573
+ }
5574
+ flash(ok ? translate('note.inserted') : translate('note.insertFailed'), ok ? 'ok' : 'error');
5575
+ };
5576
+
5577
+ const labelOfGroup = (group) => {
5578
+ const resolved = resolveGroup(group, categories, workspaceList);
5579
+ return resolved ? resolved.label : translate('row.noCategory');
5580
+ };
5581
+
5582
+ // The workspace this session belongs to leads the chooser; 常用 is the
5583
+ // fallback when the workspace family is hidden or unknown.
5584
+ const choices = captureChoices(categories, workspaceList, currentWorkspaceId, props.settings);
5585
+ const preferred = currentWorkspaceId && choices.some((entry) => entry.value === 'workspace:' + currentWorkspaceId)
5586
+ ? 'workspace:' + currentWorkspaceId
5587
+ : BUILTIN_GROUP.oftenuse;
5588
+ const ordered = choices.some((entry) => entry.value === preferred)
5589
+ ? [...choices.filter((entry) => entry.value === preferred), ...choices.filter((entry) => entry.value !== preferred)]
5590
+ : choices;
5591
+
5592
+ const promote = (note, group) => {
5593
+ poolActions.add({
5594
+ id: uid(),
5595
+ group,
5596
+ title: draftTitle(note.quote),
5597
+ // The prompt carries the quoted passage, so inserting it into the
5598
+ // composer later still has the original text (the title is only a label).
5599
+ body: composeNoteLine(note),
5600
+ images: [],
5601
+ createdAt: Date.now(),
5602
+ updatedAt: Date.now(),
5603
+ });
5604
+ if (normalizeSettings(props.settings).noteKeepAfterStore === false) {
5605
+ notesActions.remove(note.id);
5606
+ } else {
5607
+ // The record stays: the row keeps a "stored" marker so the note is not
5608
+ // silently lost from the conversation it belongs to.
5609
+ notesActions.patch(note.id, { promotedGroup: group, promotedAt: Date.now() });
5610
+ }
5611
+ flash(translate('note.stored', { group: labelOfGroup(group) }), 'ok');
5612
+ };
5613
+
5614
+ /** Compose the annotations into one prompt and file it in a group. */
5615
+ const storePrompt = (group) => {
5616
+ const text = composeNotesReply(list);
5617
+ poolActions.add({
5618
+ id: uid(),
5619
+ group,
5620
+ title: draftTitle(text),
5621
+ body: text,
5622
+ images: [],
5623
+ createdAt: Date.now(),
5624
+ updatedAt: Date.now(),
5625
+ });
5626
+ if (normalizeSettings(props.settings).noteKeepAfterStore === false) {
5627
+ notesActions.clearSession(sessionId);
5628
+ }
5629
+ flash(translate('note.composeStored', { group: labelOfGroup(group) }), 'ok');
5630
+ };
5631
+
5632
+ /** Open the group popup just under the button that asked for it. */
5633
+ const openPrompt = (target, event) => {
5634
+ const rect = event && event.currentTarget && event.currentTarget.getBoundingClientRect
5635
+ ? event.currentTarget.getBoundingClientRect()
5636
+ : null;
5637
+ notePrompt.set({
5638
+ open: true,
5639
+ target,
5640
+ choices: ordered,
5641
+ defaultValue: preferred,
5642
+ anchor: rect
5643
+ ? { left: Math.round(rect.left), right: Math.round(rect.right), top: Math.round(rect.top), bottom: Math.round(rect.bottom) }
5644
+ : { left: Math.round((window.innerWidth || 0) / 2), right: Math.round((window.innerWidth || 0) / 2) + 40, top: 60, bottom: 90 },
5645
+ onPick: (group) => {
5646
+ closeNotePrompt();
5647
+ if (!group) return;
5648
+ if (target && target.kind === 'note' && target.note) promote(target.note, group);
5649
+ else storePrompt(group);
5650
+ },
5651
+ token: Date.now(),
5652
+ });
5653
+ };
5654
+
5655
+ /** Scroll the transcript to this note. */
5656
+ const locate = (note) => {
5657
+ const root = noteChatRoot(sessionId);
5658
+ const hit = root ? resolveNote(note, root) : null;
5659
+ if (!hit) {
5660
+ showNoteStatus(translate('note.locateFailed'), 'error');
5661
+ return;
5662
+ }
5663
+ const rect = hit.range.getBoundingClientRect();
5664
+ const box = root.getBoundingClientRect();
5665
+ if (rect.top < box.top + 40 || rect.bottom > box.bottom - 40) {
5666
+ root.scrollTop += rect.top - box.top - Math.min(120, box.height / 3);
5667
+ }
5668
+ noteFocus.set({ id: note.id, token: Date.now(), edit: false });
5669
+ };
5670
+
5671
+ /** Insert one note (as a one-line prompt) into the composer. */
5672
+ const insertNote = (note) => {
5673
+ let ok = false;
5674
+ try {
5675
+ ok = props.onInsertNote ? props.onInsertNote(note) === true : false;
5676
+ } catch (_error) {
5677
+ ok = false;
5678
+ }
5679
+ if (ok && normalizeSettings(props.settings).noteKeepAfterDraft === false) {
5680
+ notesActions.remove(note.id);
5681
+ }
5682
+ flash(ok ? translate('note.inserted') : translate('note.insertFailed'), ok ? 'ok' : 'error');
5683
+ };
5684
+
5685
+ return h(
5686
+ 'div',
5687
+ { className: 'pp-notes pp-notes-embedded' },
5688
+ h('style', { key: 'css' }, NOTES_CSS),
5689
+ props.hideActions !== true || list.some((note) => (note.dx || 0) !== 0 || (note.dy || 0) !== 0)
5690
+ ? h(
5691
+ 'div',
5692
+ { className: 'pp-notes-head' },
5693
+ h('span', { className: 'pp-notes-grow' }),
5694
+ props.hideActions !== true
5695
+ ? [
5696
+ h(
5697
+ 'button',
5698
+ { key: 'compose-store', type: 'button', className: 'pp-note-btn pp-note-btn-primary', onClick: (event) => openPrompt({ kind: 'reply' }, event) },
5699
+ translate('note.composeStore'),
5700
+ ),
5701
+ h('button', { key: 'compose', type: 'button', className: 'pp-note-btn', onClick: compose }, translate('note.compose')),
5702
+ ]
5703
+ : null,
5704
+ list.some((note) => (note.dx || 0) !== 0 || (note.dy || 0) !== 0)
5705
+ ? h(
5706
+ 'button',
5707
+ { key: 'reset', type: 'button', className: 'pp-note-link', onClick: () => notesActions.resetPositions(sessionId) },
5708
+ translate('note.reset'),
5709
+ )
5710
+ : null,
5711
+ )
5712
+ : null,
5713
+ h(
5714
+ 'div',
5715
+ { className: 'pp-notes-list' },
5716
+ list.map((note, index) => {
5717
+ if (!matches(note)) return null;
5718
+ const meta = noteKind(note.kind);
5719
+ return h(
5720
+ 'div',
5721
+ {
5722
+ className: 'pp-notes-row',
5723
+ key: note.id,
5724
+ 'data-promoted': note.promotedGroup ? 'true' : undefined,
5725
+ },
5726
+ h(
5727
+ 'button',
5728
+ {
5729
+ type: 'button',
5730
+ className: 'pp-note-icon pp-note-insert',
5731
+ title: translate('note.insert'),
5732
+ 'aria-label': translate('note.insert'),
5733
+ onClick: () => insertNote(note),
5734
+ },
5735
+ h(NoteActionIcon, { kind: 'insert' }),
5736
+ ),
5737
+ h(
5738
+ 'button',
5739
+ {
5740
+ type: 'button',
5741
+ className: 'pp-note-icon pp-note-locate',
5742
+ title: translate('note.locate'),
5743
+ 'aria-label': translate('note.locate'),
5744
+ onClick: () => locate(note),
5745
+ },
5746
+ h(NoteActionIcon, { kind: 'locate' }),
5747
+ ),
5748
+ h('span', { className: 'pp-notes-n' }, String(index + 1)),
5749
+ h(
5750
+ 'div',
5751
+ { className: 'pp-notes-main' },
5752
+ h(
5753
+ 'div',
5754
+ { className: 'pp-notes-quote', title: note.quote },
5755
+ h('span', { className: 'pp-notes-kind', 'data-kind': meta.id, title: translate(meta.label) }, meta.icon),
5756
+ h('span', { className: 'pp-notes-quote-text' }, noteQuoteText(note.quote)),
5757
+ note.promotedGroup
5758
+ ? h('span', { className: 'pp-notes-tag' }, translate('note.stored', { group: labelOfGroup(note.promotedGroup) }))
5759
+ : null,
5760
+ ),
5761
+ h('div', { className: 'pp-notes-text' }, note.body || translate(meta.label)),
5762
+ ),
5763
+ h(
5764
+ 'button',
5765
+ {
5766
+ type: 'button',
5767
+ className: 'pp-note-icon',
5768
+ title: translate('note.store'),
5769
+ 'aria-label': translate('note.store'),
5770
+ onClick: (event) => openPrompt({ kind: 'note', note }, event),
5771
+ },
5772
+ h(NoteActionIcon, { kind: 'store' }),
5773
+ ),
5774
+ h(
5775
+ 'button',
5776
+ {
5777
+ type: 'button',
5778
+ className: 'pp-note-icon pp-note-link-danger',
5779
+ title: translate('note.delete'),
5780
+ 'aria-label': translate('note.delete'),
5781
+ onClick: (event) => openNoteConfirm(() => notesActions.remove(note.id), event),
5782
+ },
5783
+ h(NoteActionIcon, { kind: 'delete' }),
5784
+ ),
5785
+ );
5786
+ }),
5787
+ ),
5788
+ list.length === 0
5789
+ ? h('div', { key: 'intro', className: 'pp-notes-empty' }, translate('note.emptyIntro'))
5790
+ : filter && !list.some(matches)
5791
+ ? h('div', { key: 'empty', className: 'pp-notes-empty' }, translate('note.empty'))
5792
+ : null,
5793
+ );
5794
+ }
5795
+
5796
+ // --------------------------------------------------- conversation selection
5797
+ /**
5798
+ * Right-click destinations for text selected in the conversation. The host
5799
+ * opens this surface at the pointer; the top level keeps Copy (the menu
5800
+ * replaces the browser's own) and one pool entry whose submenu lists the
5801
+ * groups on show. Picking a group stores the selection there, and the group
5802
+ * used last time leads that submenu. The surface only exists while the Chat
5803
+ * view is mounted, and a selection lost between the gesture and this mount
5804
+ * leaves it with nothing to offer.
5805
+ */
5806
+ function SelectionMenu(props) {
5807
+ useLocaleTick();
5808
+ const state = usePoolState();
5809
+ const published = useWorkspaceDir();
5810
+ // The Chat view can read the workspace roster itself; the module store is
5811
+ // the fallback for a host that does not hand `useWorkspaces` to this seat.
5812
+ const snapshot = typeof props.useWorkspaces === 'function' ? props.useWorkspaces(selectAllInput) : undefined;
5813
+ const workspaces = snapshot ? workspaceEntriesOf(snapshot) : published.items || [];
5814
+ const currentWorkspaceId = snapshot ? currentWorkspaceOf(snapshot, props.sessionId) : published.currentId || '';
5815
+ // The gesture captured the text before this surface mounted; keeping it in
5816
+ // state means a collapsed selection cannot empty the menu mid-click.
5817
+ const [body] = useState(() => {
5818
+ const text = typeof props.readText === 'function' ? props.readText() : null;
5819
+ return typeof text === 'string' ? text.replace(/\r\n?/g, '\n').trim() : '';
5820
+ });
5821
+ const [done, setDone] = useState(null);
5822
+ // The group list lives one level down; Copy stays at the top.
5823
+ const [submenu, setSubmenu] = useState(false);
5824
+ // Annotating needs the assistant row and its text, captured while the
5825
+ // selection still owns the DOM.
5826
+ const [anchor] = useState(() => captureNoteAnchor(props.sessionId));
5827
+ const timer = useRef(0);
5828
+ const dismiss = typeof props.dismiss === 'function' ? props.dismiss : () => {};
5829
+
5830
+ useEffect(() => () => window.clearTimeout(timer.current), []);
5831
+ useEffect(() => {
5832
+ // The selection was gone before the surface mounted; nothing to offer.
5833
+ if (!body) dismiss();
5834
+ }, [body, dismiss]);
5835
+
5836
+ if (!body) return null;
5837
+
5838
+ const choices = captureChoices(state.categories, workspaces, currentWorkspaceId, state.settings);
5839
+ const last = state.settings && state.settings.lastCaptureGroup;
5840
+ const remembered = choices.find((choice) => choice.value === last) || null;
5841
+ const ordered = remembered ? [remembered, ...choices.filter((choice) => choice !== remembered)] : choices;
5842
+ const counts = {};
5843
+ for (const item of state.items) {
5844
+ const group = groupOf(item);
5845
+ counts[group] = (counts[group] || 0) + 1;
5846
+ }
5847
+
5848
+ const pick = (choice) => {
5849
+ if (done) return;
5850
+ const now = Date.now();
5851
+ poolActions.add({
5852
+ id: uid(),
5853
+ group: choice.value,
5854
+ title: draftTitle(body),
5855
+ body,
5856
+ images: [],
5857
+ createdAt: now,
5858
+ updatedAt: now,
5859
+ });
5860
+ // Remembering the destination makes the next right-click a single pick.
5861
+ poolActions.setSetting('lastCaptureGroup', choice.value);
5862
+ // The write can fail on a full or blocked store; say so instead of
5863
+ // claiming a save the pool would lose on reload.
5864
+ const failed = storageState.get().failed === true;
5865
+ setDone({ kind: failed ? 'failed' : 'saved', label: choice.label });
5866
+ timer.current = window.setTimeout(() => dismiss(), failed ? 2600 : 900);
5867
+ };
5868
+
5869
+ /**
5870
+ * The menu replaces the browser's own menu, so it has to keep Copy. The
5871
+ * selection is already captured, and the click still counts as a gesture.
5872
+ */
5873
+ const copySelection = () => {
5874
+ if (done) return;
5875
+ const copied = copyText(body);
5876
+ setDone({ kind: copied ? 'copied' : 'copyFailed' });
5877
+ // A failed copy stays up so the shortcut hint can be read and used.
5878
+ if (copied) timer.current = window.setTimeout(() => dismiss(), 900);
5879
+ };
5880
+
5881
+ /** Open the destination submenu; a click serves touch, hover serves mouse. */
5882
+ const openGroups = () => {
5883
+ if (done !== null) return;
5884
+ setSubmenu(true);
5885
+ };
5886
+
5887
+ /** Hand the captured anchor to the overlay, which opens its editor. */
5888
+ const startNote = () => {
5889
+ if (!anchor) return;
5890
+ noteDraft.set({ anchor, sessionId: props.sessionId || '', token: Date.now() });
5891
+ dismiss();
5892
+ };
5893
+
5894
+ const error = done !== null && (done.kind === 'failed' || done.kind === 'copyFailed');
5895
+ const shortcut = /Mac|iPhone|iPad/.test(typeof navigator === 'undefined' ? '' : String(navigator.userAgent || '')) ? '⌘C' : 'Ctrl+C';
5896
+ const doneText = done === null
5897
+ ? ''
5898
+ : done.kind === 'saved'
5899
+ ? translate('menu.saved', { group: done.label })
5900
+ : done.kind === 'copied'
5901
+ ? translate('menu.copied')
5902
+ : done.kind === 'copyFailed'
5903
+ ? translate('menu.copyFailed', { shortcut })
5904
+ : translate('status.storageFailed');
5905
+
5906
+ return h(
5907
+ 'div',
5908
+ {
5909
+ className: 'pp-selwrap',
5910
+ role: 'menu',
5911
+ 'aria-label': translate('menu.title'),
5912
+ // Keep the browser selection alive while the pointer is over the menu.
5913
+ onPointerDown: (event) => event.preventDefault(),
5914
+ },
5915
+ h('style', { key: 'css' }, MENU_CSS),
5916
+ done !== null
5917
+ ? h(
5918
+ 'div',
5919
+ { key: 'done', className: 'pp-selmenu pp-seldonecard' },
5920
+ h(
5921
+ 'div',
5922
+ { className: 'pp-seldone', 'data-kind': error ? 'error' : 'ok', role: 'status' },
5923
+ h('span', { key: 'mark', className: 'pp-seldone-mark', 'aria-hidden': true }, error ? '!' : '✓'),
5924
+ h('span', { key: 'text', className: 'pp-seldone-text' }, doneText),
5925
+ ),
5926
+ )
5927
+ : [
5928
+ h(
5929
+ 'div',
5930
+ { key: 'main', className: 'pp-selmenu' },
5931
+ h(
5932
+ 'button',
5933
+ {
5934
+ key: 'copy',
5935
+ type: 'button',
5936
+ role: 'menuitem',
5937
+ className: 'pp-selrow',
5938
+ onClick: copySelection,
5939
+ // Moving back to the first row folds the submenu away.
5940
+ onPointerEnter: () => setSubmenu(false),
5941
+ },
5942
+ h('span', { key: 'name', className: 'pp-selname' }, translate('menu.copy')),
5943
+ h('span', { key: 'key', className: 'pp-selkey' }, shortcut),
5944
+ ),
5945
+ h(
5946
+ 'div',
5947
+ { key: 'poolgroup', className: 'pp-selgroup' },
5948
+ h('div', { key: 'label', className: 'pp-selgroup-label' }, h(PromptPoolIcon, { key: 'icon', size: 12 }), translate('menu.group')),
5949
+ anchor
5950
+ ? h(
5951
+ 'button',
5952
+ {
5953
+ key: 'note',
5954
+ type: 'button',
5955
+ role: 'menuitem',
5956
+ className: 'pp-selrow',
5957
+ onClick: startNote,
5958
+ onPointerEnter: () => setSubmenu(false),
5959
+ },
5960
+ h('span', { key: 'name', className: 'pp-selname' }, translate('note.add')),
5961
+ )
5962
+ : null,
5963
+ h(
5964
+ 'button',
5965
+ {
5966
+ key: 'pool',
5967
+ type: 'button',
5968
+ role: 'menuitem',
5969
+ className: 'pp-selrow',
5970
+ 'aria-haspopup': 'menu',
5971
+ 'aria-expanded': submenu,
5972
+ onClick: openGroups,
5973
+ onPointerEnter: openGroups,
4157
5974
  },
4158
- h('span', { key: 'name', className: 'pp-selname' }, translate('menu.title')),
5975
+ h('span', { key: 'name', className: 'pp-selname' }, translate('menu.pool')),
4159
5976
  h('span', { key: 'chev', className: 'pp-selchev', 'aria-hidden': true }, '▸'),
4160
5977
  ),
5978
+ ),
4161
5979
  ),
4162
5980
  submenu
4163
5981
  ? h(
4164
5982
  'div',
4165
- { key: 'groups', className: 'pp-selpanel', role: 'menu', 'aria-label': translate('menu.title') },
5983
+ { key: 'groups', className: 'pp-selpanel', role: 'menu', 'aria-label': translate('menu.pool') },
4166
5984
  h(
4167
5985
  'div',
4168
5986
  { key: 'list', className: 'pp-sellist' },
@@ -4205,13 +6023,22 @@ window.__ModuleLoader__.load({
4205
6023
  const storage = useStorageState();
4206
6024
  const releaseInfo = useReleaseState();
4207
6025
  const view = useUiState();
6026
+ const noteBar = useNoteStatus();
4208
6027
  const workspaces = useWorkspaceDir();
4209
6028
  const sessionHint = useSessionDir().sessionId;
6029
+ const notesState = useNotesState();
6030
+ const notesSessionId = typeof props.sessionId === 'string' ? props.sessionId : '';
6031
+ const notesList = notesState.items
6032
+ .filter((note) => note.sessionId === notesSessionId)
6033
+ .sort((left, right) => (left.order - right.order) || (left.createdAt - right.createdAt));
4210
6034
 
4211
6035
  // This view can read the workspace roster; publish it for both views.
4212
6036
  const wsSnapshot = typeof props.useWorkspaces === 'function' ? props.useWorkspaces(selectAllInput) : undefined;
4213
6037
  useEffect(() => {
4214
6038
  sessionDir.set({ sessionId: props.sessionId || '' });
6039
+ // The overlay is root-scoped; this session-scoped seat tells it which
6040
+ // transcript the annotation cards belong to.
6041
+ chatView.set({ sessionId: props.sessionId || '' });
4215
6042
  }, [props.sessionId]);
4216
6043
  const wsEntries = workspaceEntriesOf(wsSnapshot);
4217
6044
  const wsCurrent = currentWorkspaceOf(wsSnapshot, props.sessionId);
@@ -4845,11 +6672,76 @@ window.__ModuleLoader__.load({
4845
6672
 
4846
6673
  // The sidebar tab has no composer access, so it posts commands here.
4847
6674
  const bridgeRef = useRef(null);
4848
- bridgeRef.current = { insert: insertItem, release, capture: captureDraft };
6675
+ /** The annotations tab's reply: numbered, each note quotes its passage. */
6676
+ /** Write a block of text into the composer through the host's actions. */
6677
+ const insertComposerText = (text) => {
6678
+ const actions = props.inputActions;
6679
+ if (!actions || typeof actions.insertText !== 'function') return false;
6680
+ try {
6681
+ const span = typeof actions.captureInsertion === 'function' ? actions.captureInsertion() : undefined;
6682
+ return actions.insertText(text, span) === true;
6683
+ } catch (_error) {
6684
+ return false;
6685
+ }
6686
+ };
6687
+ const composeSessionNotes = () => insertComposerText(composeNotesReply(notesList));
6688
+ const insertNoteText = (note) => insertComposerText(composeNoteLine(note));
6689
+
6690
+ /** Store the session's annotations as one prompt, from the panel header. */
6691
+ const storeNotesPrompt = (event) => {
6692
+ const choices = captureChoices(state.categories, workspaces.items, currentWorkspaceId, state.settings);
6693
+ const preferred = currentWorkspaceId && choices.some((entry) => entry.value === 'workspace:' + currentWorkspaceId)
6694
+ ? 'workspace:' + currentWorkspaceId
6695
+ : BUILTIN_GROUP.oftenuse;
6696
+ const ordered = choices.some((entry) => entry.value === preferred)
6697
+ ? [...choices.filter((entry) => entry.value === preferred), ...choices.filter((entry) => entry.value !== preferred)]
6698
+ : choices;
6699
+ const rect = event && event.currentTarget && event.currentTarget.getBoundingClientRect
6700
+ ? event.currentTarget.getBoundingClientRect()
6701
+ : null;
6702
+ notePrompt.set({
6703
+ open: true,
6704
+ target: { kind: 'reply' },
6705
+ choices: ordered,
6706
+ defaultValue: preferred,
6707
+ anchor: rect
6708
+ ? { left: Math.round(rect.left), right: Math.round(rect.right), top: Math.round(rect.top), bottom: Math.round(rect.bottom) }
6709
+ : { left: 120, right: 160, top: 60, bottom: 90 },
6710
+ token: Date.now(),
6711
+ onPick: (group) => {
6712
+ closeNotePrompt();
6713
+ if (!group) return;
6714
+ const text = composeNotesReply(notesList);
6715
+ poolActions.add({
6716
+ id: uid(),
6717
+ group,
6718
+ title: draftTitle(text),
6719
+ body: text,
6720
+ images: [],
6721
+ createdAt: Date.now(),
6722
+ updatedAt: Date.now(),
6723
+ });
6724
+ if (normalizeSettings(state.settings).noteKeepAfterStore === false) {
6725
+ notesActions.clearSession(notesSessionId);
6726
+ }
6727
+ const resolved = resolveGroup(group, state.categories, workspaces.items);
6728
+ showToast(translate('note.composeStored', { group: resolved ? resolved.label : translate('row.noCategory') }), 'ok');
6729
+ },
6730
+ });
6731
+ };
6732
+
6733
+ bridgeRef.current = { insert: insertItem, release, capture: captureDraft, composeNotes: composeSessionNotes, insertText: insertComposerText };
4849
6734
  useEffect(() => {
4850
6735
  return bridge.listen((command) => {
4851
6736
  const api = bridgeRef.current;
4852
6737
  if (!api || !command) return { ok: false, reason: 'unavailable' };
6738
+ if (command.type === 'compose-notes') {
6739
+ return { ok: api.composeNotes() === true };
6740
+ }
6741
+ if (command.type === 'insert-text') {
6742
+ if (typeof command.text !== 'string') return { ok: false, reason: 'bad-command' };
6743
+ return { ok: api.insertText(command.text) === true };
6744
+ }
4853
6745
  if (command.type === 'insert') {
4854
6746
  if (typeof command.text !== 'string') return { ok: false, reason: 'bad-command' };
4855
6747
  return Promise.resolve(api.insert({ body: command.text, images: normalizeImages(command.images) }))
@@ -4881,11 +6773,31 @@ window.__ModuleLoader__.load({
4881
6773
  });
4882
6774
  }, []);
4883
6775
 
6776
+ // The panel lands on the Settings default each time it opens. The tab list
6777
+ // is built here because render-time tabs are computed after this hook.
6778
+ const wasOpenRef = useRef(false);
6779
+ useEffect(() => {
6780
+ const open = view.open === true;
6781
+ if (open && !wasOpenRef.current) {
6782
+ const pref = normalizeSettings(state.settings).defaultTab;
6783
+ const baseTabs = buildTabs(state.categories, workspaces.items, state.settings, currentWorkspaceId);
6784
+ const resolved = resolveDefaultTab(pref, baseTabs, currentWorkspaceId, notesList.length > 0);
6785
+ if (resolved) setTab(resolved);
6786
+ }
6787
+ wasOpenRef.current = open;
6788
+ }, [view.open]);
6789
+
4884
6790
  if (!view.open) return null;
4885
6791
 
4886
6792
  const panelCount = state.items.length;
4887
6793
  const captureGroups = captureChoices(state.categories, workspaces.items, currentWorkspaceId, state.settings);
4888
- const tabCounts = tabCountsOf(state.items);
6794
+ const baseTabs = buildTabs(state.categories, workspaces.items, state.settings, currentWorkspaceId);
6795
+ // The annotation tab is always present, so the feature stays discoverable.
6796
+ const tabs = [{ id: 'notes', label: translate('note.title'), group: 'notes' }, ...baseTabs];
6797
+ const tabCounts = {
6798
+ ...tabCountsOf(state.items),
6799
+ notes: notesList.length,
6800
+ };
4889
6801
 
4890
6802
  // A folded family renders its groups as chips inside one tab.
4891
6803
  const customGroups = state.categories.map((category) => ({ id: 'custom:' + category.id, name: category.name }));
@@ -4985,18 +6897,29 @@ window.__ModuleLoader__.load({
4985
6897
  h(
4986
6898
  'div',
4987
6899
  { className: 'pp-page-head' },
4988
- h('span', { className: 'pp-page-title' }, translate('panel.title')),
4989
- h('span', { className: 'pp-page-sub' }, translate('page.count', { n: panelCount })),
4990
- h('span', { className: 'pp-grow' }),
6900
+ h(
6901
+ 'span',
6902
+ { className: 'pp-page-title pp-panel-title' },
6903
+ h(PromptPoolIcon, { key: 'icon', size: 16 }),
6904
+ translate('panel.title'),
6905
+ ),
4991
6906
  h('input', {
6907
+ key: 'search',
4992
6908
  className: 'pp-search',
4993
6909
  value: query,
4994
6910
  placeholder: translate('page.search'),
4995
6911
  'aria-label': translate('page.search'),
4996
6912
  onChange: (event) => setQuery(event.target.value),
4997
6913
  }),
4998
- h('button', { type: 'button', className: 'pp-mini', onClick: newItem }, '+ ', translate('page.new')),
4999
- h('button', { type: 'button', className: 'pp-mini', title: translate('panel.captureHint'), onClick: openCapture }, translate('panel.capture')),
6914
+ tab === 'notes'
6915
+ ? [
6916
+ h('button', { key: 'store', type: 'button', className: 'pp-mini', title: translate('note.composeStoreHint'), onClick: storeNotesPrompt }, translate('note.composeStore')),
6917
+ h('button', { key: 'draft', type: 'button', className: 'pp-mini', title: translate('note.composeHint'), onClick: composeSessionNotes }, translate('note.compose')),
6918
+ ]
6919
+ : [
6920
+ h('button', { key: 'new', type: 'button', className: 'pp-mini', onClick: newItem }, '+ ', translate('page.new')),
6921
+ h('button', { key: 'capture', type: 'button', className: 'pp-mini', title: translate('panel.captureHint'), onClick: openCapture }, translate('panel.capture')),
6922
+ ],
5000
6923
  h(SettingsButton, { active: settingsOpen, onClick: () => setSettingsOpen(!settingsOpen) }),
5001
6924
  h(IconButton, {
5002
6925
  name: 'pin',
@@ -5014,7 +6937,7 @@ window.__ModuleLoader__.load({
5014
6937
  'div',
5015
6938
  { className: 'pp-bar', style: { padding: '8px 12px 2px' } },
5016
6939
  h(TabBar, {
5017
- tabs: buildTabs(state.categories, workspaces.items, state.settings, currentWorkspaceId),
6940
+ tabs,
5018
6941
  counts: tabCounts,
5019
6942
  active: tab,
5020
6943
  ...tabHandlers((next) => {
@@ -5078,7 +7001,20 @@ window.__ModuleLoader__.load({
5078
7001
  { className: 'pp-list', ref: listRef },
5079
7002
  settingsOpen
5080
7003
  ? h(PromptPoolSettings, { currentWorkspaceId })
5081
- : nestedView
7004
+ : tab === 'notes'
7005
+ ? h(NotesView, {
7006
+ notes: notesList,
7007
+ sessionId: notesSessionId,
7008
+ onCompose: composeSessionNotes,
7009
+ onInsertNote: insertNoteText,
7010
+ hideActions: true,
7011
+ filter: query,
7012
+ categories: state.categories,
7013
+ workspaces: workspaces.items,
7014
+ currentWorkspaceId,
7015
+ settings: state.settings,
7016
+ })
7017
+ : nestedView
5082
7018
  ? renderWorkspacePanes({
5083
7019
  rail: nestedView.rail,
5084
7020
  items: nestedView.scoped,
@@ -5107,6 +7043,9 @@ window.__ModuleLoader__.load({
5107
7043
  h(
5108
7044
  'div',
5109
7045
  { className: 'pp-panel-dock' },
7046
+ tab === 'notes' && noteBar.text
7047
+ ? h('div', { className: 'pp-notes-bar', 'data-kind': noteBar.kind, role: 'status' }, noteBar.text)
7048
+ : null,
5110
7049
  notice
5111
7050
  ? h(
5112
7051
  'div',
@@ -5127,7 +7066,7 @@ window.__ModuleLoader__.load({
5127
7066
  : null,
5128
7067
  )
5129
7068
  : null,
5130
- !settingsOpen
7069
+ !settingsOpen && tab !== 'notes'
5131
7070
  ? renderTrayCard({
5132
7071
  entries: tray,
5133
7072
  queuePending: queue.length,
@@ -5217,10 +7156,20 @@ window.__ModuleLoader__.load({
5217
7156
  '.pp-x:hover{background:var(--pp-hover);color:var(--pp-ink)}' +
5218
7157
  '.pp-bar{display:flex;align-items:center;gap:6px;padding:0 12px 8px;flex-wrap:wrap}' +
5219
7158
  '.pp-tab{height:24px;padding:0 9px;border-radius:7px;border:1px solid transparent;background:transparent;color:var(--pp-ink-2);font:inherit;font-size:12px;cursor:pointer}' +
7159
+ '.pp-tab:not([data-active="true"]){color:color-mix(in srgb,var(--pp-accent) 78%,var(--pp-ink-2))}' +
7160
+ '.pp-tab[data-group="notes"]:not([data-active="true"]){color:#8a6200}' +
5220
7161
  '.pp-tab:hover{background:var(--pp-hover)}' +
5221
7162
  '.pp-tab[data-active="true"]{border-color:var(--pp-accent);background:var(--pp-accent-soft);color:var(--pp-accent);font-weight:600}' +
7163
+ '.pp-tab[data-group="notes"][data-active="true"]{border-color:rgba(232,176,40,.9);background:rgba(232,176,40,.2);color:#9a6b00}' +
7164
+ '.pp-tab[data-group="notes"] .pp-tab-count{background:rgba(232,176,40,.22);color:#8a6200}' +
5222
7165
  '.pp-tab-count{margin-left:5px;padding:0 5px;vertical-align:1px;border-radius:999px;background:color-mix(in srgb, currentColor 12%, transparent);color:inherit;font-size:10px;font-weight:600;line-height:16px;height:16px;display:inline-flex;align-items:center}' +
7166
+ '.pp-tab:not([data-group="notes"]) .pp-tab-count{background:color-mix(in srgb,var(--pp-accent) 12%,transparent);color:var(--pp-accent)}' +
5223
7167
  '.pp-tab-add{padding:0 7px;color:var(--pp-ink-2)}' +
7168
+ '.pp-select{height:26px;min-width:170px;max-width:100%;padding:0 8px;border:1px solid var(--pp-line);border-radius:7px;background:var(--pp-surface);color:var(--pp-ink);font:inherit;font-size:12px}' +
7169
+ '.pp-set-intro{white-space:pre-line}' +
7170
+ '.pp-set-radios{display:flex;flex-direction:column;gap:4px;padding:2px 0 4px}' +
7171
+ '.pp-set-radio-row{display:flex;align-items:center;gap:10px}' +
7172
+ '.pp-set-radio{display:inline-flex;align-items:center;gap:6px;cursor:pointer}' +
5224
7173
  '.pp-tab-addwrap{display:inline-flex;align-items:center}' +
5225
7174
  '.pp-tab-sep{flex:none;width:1px;height:16px;margin:0 7px;background:color-mix(in srgb, var(--pp-ink-2) 45%, transparent)}' +
5226
7175
  '.pp-tab-x{margin-left:4px;padding:0 2px;border-radius:4px;font-size:11px;line-height:1;color:var(--pp-ink-2);cursor:pointer}' +
@@ -5246,6 +7195,7 @@ window.__ModuleLoader__.load({
5246
7195
  '.pp-page{position:relative;display:flex;flex-direction:column;height:100%;min-height:0;background:var(--dsw-alias-bg-base);color:var(--pp-ink);font-size:13px;line-height:1.5}' +
5247
7196
  '.pp-page-head{display:flex;align-items:center;gap:8px;padding:12px 12px 8px;border-bottom:1px solid var(--pp-line);flex-wrap:wrap}' +
5248
7197
  '.pp-page-title{font-size:14px;font-weight:600}' +
7198
+ '.pp-panel-title{display:inline-flex;align-items:center;gap:6px;flex:none;margin-right:2px}' +
5249
7199
  '.pp-page-sub{color:var(--pp-ink-2);font-size:12px}' +
5250
7200
  '.pp-search{height:26px;flex:1;min-width:120px;border:1px solid var(--pp-line);border-radius:8px;background:var(--pp-surface);color:inherit;font:inherit;font-size:12px;padding:0 9px;outline:none}' +
5251
7201
  '.pp-search:focus{border-color:var(--pp-accent)}' +
@@ -5313,7 +7263,7 @@ window.__ModuleLoader__.load({
5313
7263
  '.pp-page-item:hover .pp-actions{opacity:1}' +
5314
7264
  '.pp-empty{padding:22px 16px;color:var(--pp-ink-2);text-align:center;font-size:12px}' +
5315
7265
  '.pp-row{display:flex;align-items:flex-start;gap:8px;padding:7px 8px;border-radius:8px}' +
5316
- '.pp-row:hover{background:var(--pp-hover)}' +
7266
+ '.pp-row:hover{background:color-mix(in srgb,var(--pp-accent) 10%,transparent)}' +
5317
7267
  '.pp-toggle{width:26px;height:26px;flex:none;margin-top:-1px;border:0;border-radius:6px;background:transparent;color:var(--pp-ink-2);cursor:pointer;display:inline-flex;align-items:center;justify-content:center;padding:0}' +
5318
7268
  '.pp-toggle:hover{background:var(--pp-hover);color:var(--pp-ink)}' +
5319
7269
  '.pp-toggle[data-selected="true"]{color:var(--pp-accent)}' +
@@ -5386,6 +7336,8 @@ window.__ModuleLoader__.load({
5386
7336
  '.pp-status[data-kind="error"]{color:var(--pp-danger)}' +
5387
7337
  '.pp-status[data-kind="ok"]{color:var(--pp-ok)}' +
5388
7338
  '.pp-queue-dock,.pp-panel-dock{position:relative;flex:none;display:flex;flex-direction:column}' +
7339
+ '.pp-notes-bar{margin:0 10px 10px;padding:8px 12px;border:1px solid color-mix(in srgb,var(--pp-danger) 30%,var(--pp-line-2));border-radius:9px;background:color-mix(in srgb,var(--pp-danger) 9%,transparent);color:var(--pp-danger);font-size:12px;line-height:1.5}' +
7340
+ '.pp-notes-bar[data-kind="ok"]{border-color:color-mix(in srgb,var(--pp-ok) 30%,var(--pp-line-2));background:color-mix(in srgb,var(--pp-ok) 9%,transparent);color:var(--pp-ok)}' +
5389
7341
  '.pp-status-float{position:absolute;left:10px;right:auto;width:max-content;max-width:calc(100% - 20px);bottom:100%;margin-bottom:6px;padding:6px 12px;border:1px solid var(--pp-line-2);border-radius:8px;background:var(--pp-surface);box-shadow:0 4px 14px rgba(0,0,0,.10);z-index:5;pointer-events:none;animation:pp-status-in .16s ease}' +
5390
7342
  '.pp-panel .pp-status-float{pointer-events:auto}' +
5391
7343
  // The page's status float stays click-through, so only the undo link takes clicks.
@@ -5409,6 +7361,8 @@ window.__ModuleLoader__.load({
5409
7361
  '.pp-seldonecard{width:280px}' +
5410
7362
  '.pp-sellist{display:flex;flex-direction:column;min-height:0;overflow-y:auto}' +
5411
7363
  '.pp-selrule{height:1px;margin:3px 4px;background:var(--pp-line)}' +
7364
+ '.pp-selgroup{display:flex;flex-direction:column;margin-top:4px;padding:3px 3px 4px;border:1px solid var(--pp-line);border-radius:8px;background:color-mix(in srgb,var(--pp-ink) 3%,transparent)}' +
7365
+ '.pp-selgroup-label{display:flex;align-items:center;gap:4px;padding:1px 8px 3px;color:var(--pp-ink-2);font-size:10px;letter-spacing:.02em}' +
5412
7366
  '.pp-selrow{display:flex;align-items:center;gap:8px;width:100%;height:26px;padding:0 8px;border:0;border-radius:6px;background:transparent;color:var(--pp-ink);font:inherit;font-size:12px;text-align:left;cursor:pointer}' +
5413
7367
  '.pp-selrow:hover,.pp-selrow:focus-visible{background:color-mix(in srgb,var(--pp-accent) 11%,transparent)}' +
5414
7368
  '.pp-selrow:focus-visible{outline:2px solid var(--pp-accent);outline-offset:-2px}' +
@@ -5423,6 +7377,96 @@ window.__ModuleLoader__.load({
5423
7377
  '.pp-seldone-mark{flex:none;color:var(--pp-ok);font-size:12px}' +
5424
7378
  '.pp-seldone[data-kind="error"] .pp-seldone-mark{color:var(--pp-danger)}';
5425
7379
 
7380
+ /**
7381
+ * Annotations live in the frame overlay and in the composer dock, so they
7382
+ * carry their own tokens and controls. The highlight rule is global: the
7383
+ * Highlight API paints ranges that the markdown DOM never contains.
7384
+ */
7385
+ const NOTES_CSS =
7386
+ '::highlight(prompt-pool-note-comment){text-decoration-line:underline;text-decoration-style:solid;text-decoration-color:rgba(255,191,36,.95);text-decoration-thickness:1px;text-underline-offset:2px}' +
7387
+ '::highlight(prompt-pool-note-question){text-decoration-line:underline;text-decoration-style:solid;text-decoration-color:rgba(244,114,114,.95);text-decoration-thickness:1px;text-underline-offset:2px}' +
7388
+ '::highlight(prompt-pool-note-agree){text-decoration-line:underline;text-decoration-style:solid;text-decoration-color:rgba(74,222,128,.95);text-decoration-thickness:1px;text-underline-offset:2px}' +
7389
+ '::highlight(prompt-pool-note-disagree){text-decoration-line:underline;text-decoration-style:solid;text-decoration-color:rgba(239,68,68,.95);text-decoration-thickness:1px;text-underline-offset:2px}' +
7390
+ '::highlight(prompt-pool-note-idea){text-decoration-line:underline;text-decoration-style:solid;text-decoration-color:rgba(96,165,250,.95);text-decoration-thickness:1px;text-underline-offset:2px}' +
7391
+ '::highlight(prompt-pool-note-todo){text-decoration-line:underline;text-decoration-style:dashed;text-decoration-color:rgba(251,191,36,.95);text-decoration-thickness:1px;text-underline-offset:2px}' +
7392
+ '.pp-note-layer{--pp-note-accent:var(--dsw-alias-state-business-primary,var(--dsw-alias-brand-primary));--pp-note-ink:var(--dsw-alias-label-primary);--pp-note-ink-2:var(--dsw-alias-label-secondary);--pp-note-line:var(--dsw-alias-border-l1);--pp-note-surface:var(--dsw-alias-bg-overlay);--pp-note-hover:color-mix(in srgb,var(--pp-note-ink) 8%,transparent);--pp-note-danger:var(--dsw-alias-state-error-primary);--pp-note-ok:var(--dsw-alias-state-success-primary);position:fixed;inset:0;z-index:2147482000;pointer-events:none}' +
7393
+ '.pp-note-bubble{position:fixed;z-index:1;display:flex;flex-direction:column;gap:8px;width:310px;max-width:calc(100vw - 24px);max-height:calc(100vh - 24px);overflow:auto;box-sizing:border-box;padding:11px;border:1px solid var(--pp-note-line);border-radius:12px;background:var(--pp-note-surface);box-shadow:0 18px 48px rgba(0,0,0,.22),0 2px 6px rgba(0,0,0,.08);color:var(--pp-note-ink);font-size:12px;line-height:1.5;text-align:left;pointer-events:auto}' +
7394
+ '.pp-note-bubble-quote{box-sizing:border-box;padding:6px 8px;border-radius:8px;background:rgba(var(--pp-bubble-tint),.10);color:var(--pp-note-ink-2);font-size:11px;line-height:1.5;display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:2;overflow:hidden}.pp-note-bubble-quote-icon{margin-right:4px;color:rgb(var(--pp-bubble-tint))}' +
7395
+ '.pp-note-bubble-hint{color:var(--pp-note-danger);font-size:11px}' +
7396
+
7397
+ '.pp-note-input{width:100%;box-sizing:border-box;min-height:48px;max-height:120px;padding:6px 8px;border:1px solid var(--pp-note-line);border-radius:8px;background:color-mix(in srgb,var(--pp-note-ink) 3%,transparent);color:inherit;font:inherit;font-size:12px;line-height:1.5;resize:none;outline:none}' +
7398
+ '.pp-note-input:focus{border-color:rgba(var(--pp-bubble-tint),.9);box-shadow:0 0 0 2px rgba(var(--pp-bubble-tint),.14)}' +
7399
+ '.pp-note-bubble-foot{display:flex;align-items:center;gap:8px}.pp-note-bubble-ask{flex:1;color:var(--pp-note-ink-2);font-size:11px;line-height:1.4}.pp-note-bubble-actions{display:flex;gap:6px;margin-left:auto}.pp-note-bubble .pp-note-btn{height:24px;padding:0 9px;font-size:11px;border-radius:7px}.pp-note-btn-quiet-danger{border-color:transparent;background:transparent;color:var(--pp-note-danger)}.pp-note-btn-quiet-danger:hover{background:rgba(var(--pp-note-danger-rgb,239,68,68),.10)}' +
7400
+ '.pp-note-btn{height:24px;padding:0 10px;border:1px solid var(--pp-note-line);border-radius:7px;background:transparent;color:var(--pp-note-ink);font:inherit;font-size:12px;cursor:pointer;white-space:nowrap}' +
7401
+ '.pp-note-btn:hover{background:var(--pp-note-hover)}' +
7402
+ '.pp-note-btn:disabled{opacity:.45;cursor:default}' +
7403
+ '.pp-note-btn-primary{border-color:var(--pp-note-accent);background:var(--pp-note-accent);color:#fff}' +
7404
+ '.pp-note-btn-primary:hover{background:var(--pp-note-accent);filter:brightness(1.05)}' +
7405
+ '.pp-note-btn-danger{color:var(--pp-note-danger);border-color:color-mix(in srgb,var(--pp-note-danger) 40%,transparent)}' +
7406
+ '.pp-note-btn-danger:hover{background:color-mix(in srgb,var(--pp-note-danger) 10%,transparent)}' +
7407
+ '.pp-notes{--pp-note-accent:var(--dsw-alias-state-business-primary,var(--dsw-alias-brand-primary));--pp-note-ink:var(--dsw-alias-label-primary);--pp-note-ink-2:var(--dsw-alias-label-secondary);--pp-note-line:var(--dsw-alias-border-l1);--pp-note-surface:var(--dsw-alias-bg-overlay);--pp-note-hover:color-mix(in srgb,var(--pp-note-ink) 8%,transparent);--pp-note-danger:var(--dsw-alias-state-error-primary);--pp-note-ok:var(--dsw-alias-state-success-primary);display:flex;flex-direction:column;box-sizing:border-box;width:100%;border:1px solid var(--pp-note-line);border-radius:10px;background:color-mix(in srgb,var(--dsw-alias-state-warn-primary,#e0a800) 5%,var(--dsw-alias-bg-base,#fff));color:var(--pp-note-ink);font-size:12px;line-height:1.5}' +
7408
+ '.pp-notes-embedded{border:0;border-radius:0;background:transparent}' +
7409
+ '.pp-notes-embedded .pp-notes-head{padding:8px 2px 4px}' +
7410
+ '.pp-notes-embedded .pp-notes-list{max-height:none;overflow:visible;padding:0}' +
7411
+ '.pp-notes-embedded .pp-notes-row{background:transparent}' +
7412
+ '.pp-notes-head{display:flex;align-items:center;gap:8px;flex-wrap:wrap;min-height:32px;padding:5px 10px}' +
7413
+ '.pp-notes-title{font-weight:600}' +
7414
+ '.pp-notes-count{color:var(--pp-note-ink-2);font-size:11px;font-variant-numeric:tabular-nums}' +
7415
+ '.pp-notes-status{font-size:11px}' +
7416
+ '.pp-notes-status[data-kind="error"]{color:var(--pp-note-danger)}' +
7417
+ '.pp-notes-status[data-kind="ok"]{color:var(--pp-note-ok)}' +
7418
+ '.pp-notes-grow{flex:1;min-width:8px}' +
7419
+ '.pp-notes-ask{color:var(--pp-note-ink-2);font-size:11px}' +
7420
+ '.pp-notes-list{display:flex;flex-direction:column;gap:4px;max-height:180px;overflow-y:auto;padding:0 8px 8px}' +
7421
+ '.pp-notes-row{display:flex;align-items:flex-start;gap:8px;padding:6px 7px;border:1px solid transparent;border-radius:8px;background:transparent}' +
7422
+ '.pp-notes-row:hover{background:rgba(232,176,40,.22)}' +
7423
+ '.pp-notes-n{flex:none;min-width:16px;height:16px;margin-top:1px;border-radius:999px;background:rgba(232,176,40,.22);color:var(--pp-note-ink-2);font-size:10px;line-height:16px;text-align:center}' +
7424
+ '.pp-notes-main{flex:1;min-width:0}' +
7425
+ '.pp-notes-quote{display:flex;align-items:center;gap:6px;color:var(--pp-note-ink-2);font-size:11px;white-space:nowrap;overflow:hidden}' +
7426
+ '.pp-notes-quote-text{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis}' +
7427
+ '.pp-notes-empty{padding:14px 12px;color:var(--pp-note-ink-2);font-size:12px;line-height:1.6}' +
7428
+ '.pp-notes-tag{flex:none;padding:0 5px;border-radius:5px;background:color-mix(in srgb,var(--dsw-alias-state-success-primary,#2f9e63) 14%,transparent);color:var(--dsw-alias-state-success-primary,#2f9e63);font-size:10px;line-height:16px}' +
7429
+ '.pp-notes-row[data-promoted="true"]{border-color:color-mix(in srgb,var(--dsw-alias-state-success-primary,#2f9e63) 35%,var(--pp-note-line))}' +
7430
+ '.pp-notes-kind{flex:none;display:inline-flex;align-items:center;justify-content:center;width:15px;height:15px;margin-right:4px;border-radius:4px;background:rgba(var(--pp-inline-tint),.18);color:rgb(var(--pp-inline-tint));font-size:10px;line-height:1}' +
7431
+ '.pp-note-inline[data-kind="comment"],.pp-notes-kind[data-kind="comment"],.pp-note-kind[data-kind="comment"]{--pp-inline-tint:255,191,36}' +
7432
+ '.pp-note-inline[data-kind="question"],.pp-notes-kind[data-kind="question"],.pp-note-kind[data-kind="question"]{--pp-inline-tint:244,114,114}' +
7433
+ '.pp-note-inline[data-kind="agree"],.pp-notes-kind[data-kind="agree"],.pp-note-kind[data-kind="agree"]{--pp-inline-tint:74,222,128}' +
7434
+ '.pp-note-inline[data-kind="disagree"],.pp-notes-kind[data-kind="disagree"],.pp-note-kind[data-kind="disagree"]{--pp-inline-tint:239,68,68}' +
7435
+ '.pp-note-inline[data-kind="idea"],.pp-notes-kind[data-kind="idea"],.pp-note-kind[data-kind="idea"]{--pp-inline-tint:96,165,250}' +
7436
+ '.pp-note-inline[data-kind="todo"],.pp-notes-kind[data-kind="todo"],.pp-note-kind[data-kind="todo"]{--pp-inline-tint:251,191,36}' +
7437
+ '.pp-note-inline{display:inline-flex;align-items:center;gap:3px;height:17px;margin:0 1px 0 4px;padding:0 5px;border:1px dashed rgba(var(--pp-inline-tint),.85);border-radius:5px;background:rgba(var(--pp-inline-tint),.15);color:inherit;font:inherit;font-size:11px;line-height:17px;vertical-align:middle;white-space:nowrap;user-select:none;-webkit-user-select:none;cursor:pointer}' +
7438
+ '.pp-note-inline-icon{font-size:10px;line-height:1;color:rgb(var(--pp-inline-tint))}' +
7439
+ '.pp-note-inline-text{white-space:nowrap}' +
7440
+ '.pp-note-inline:hover{border-color:rgb(var(--pp-inline-tint));background:rgba(var(--pp-inline-tint),.26)}' +
7441
+ '.pp-note-kinds{display:flex;flex-wrap:wrap;gap:2px;margin:0}' +
7442
+ '.pp-note-kind{display:inline-flex;align-items:center;gap:3px;height:20px;padding:0 5px;border:1px solid var(--pp-note-line);border-radius:999px;background:transparent;color:var(--pp-note-ink-2);font:inherit;font-size:10.5px;cursor:pointer}' +
7443
+ '.pp-note-kind[data-active="true"]{border-color:rgba(var(--pp-inline-tint),.9);color:var(--pp-note-ink);background:rgba(var(--pp-inline-tint),.16)}' +
7444
+ '.pp-note-kind-icon{font-size:10px;line-height:1;color:rgb(var(--pp-inline-tint))}' +
7445
+ '.pp-note-limit{color:var(--pp-note-ink-2);font-size:10px;font-variant-numeric:tabular-nums}' +
7446
+ '.pp-note-limit-count{font-variant-numeric:tabular-nums}' +
7447
+ '.pp-note-prompt{position:fixed;z-index:3;display:flex;flex-direction:column;gap:2px;width:210px;box-sizing:border-box;padding:5px;border:1px solid var(--pp-note-line);border-radius:10px;background:var(--pp-note-surface);box-shadow:0 14px 34px rgba(0,0,0,.2);color:var(--pp-note-ink);font-size:12px;line-height:1.5;text-align:left;pointer-events:auto}' +
7448
+ '.pp-note-prompt-title{padding:2px 8px 4px;color:var(--pp-note-ink-2);font-size:11px}' +
7449
+ '.pp-note-prompt-list{display:flex;flex-direction:column;max-height:250px;overflow-y:auto}' +
7450
+ '.pp-note-prompt-row{display:flex;align-items:center;gap:6px;width:100%;height:26px;padding:0 8px;border:0;border-radius:6px;background:transparent;color:var(--pp-note-ink);font:inherit;font-size:12px;text-align:left;cursor:pointer}' +
7451
+ '.pp-note-prompt-row:hover,.pp-note-prompt-row:focus-visible{background:var(--pp-note-hover);outline:none}' +
7452
+ '.pp-note-prompt-name{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}' +
7453
+ '.pp-note-prompt-tag{flex:none;padding:0 5px;border-radius:5px;background:rgba(var(--pp-bubble-tint,232,176,40),.16);color:var(--pp-note-ink-2);font-size:10px;line-height:16px}' +
7454
+ '.pp-note-prompt-sep{height:1px;margin:3px 6px;background:var(--pp-note-line)}' +
7455
+ '.pp-note-prompt-cancel{color:var(--pp-note-ink-2)}' +
7456
+ '.pp-note-prompt-message{padding:2px 8px;color:var(--pp-note-ink);font-size:12px;line-height:1.5}' +
7457
+ '.pp-note-prompt-actions{display:flex;justify-content:flex-end;gap:6px;padding:2px}' +
7458
+ '.pp-note-groups{display:flex;flex-direction:column;gap:4px;margin:2px 0 6px;padding:8px;border:1px solid var(--pp-note-line);border-radius:8px;background:var(--pp-note-surface)}' +
7459
+ '.pp-note-groups-title{font-size:11px;color:var(--pp-note-ink-2)}' +
7460
+ '.pp-note-groups-list{display:flex;flex-wrap:wrap;gap:4px}' +
7461
+ '.pp-note-group{display:inline-flex;align-items:center;gap:4px;height:24px;padding:0 9px;border:1px solid var(--pp-note-line);border-radius:7px;background:transparent;color:var(--pp-note-ink);font:inherit;font-size:12px;cursor:pointer;white-space:nowrap}' +
7462
+ '.pp-note-group:hover{border-color:var(--pp-note-accent)}' +
7463
+ '.pp-note-group[data-default="true"]{border-color:var(--pp-note-accent);background:color-mix(in srgb,var(--pp-note-accent) 10%,transparent)}' +
7464
+ '.pp-note-group-default{font-size:10px;color:var(--pp-note-accent)}' +
7465
+ '.pp-notes-text{white-space:pre-wrap;word-break:break-word;display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:2;overflow:hidden}' +
7466
+ '.pp-note-link{border:0;background:transparent;color:var(--pp-note-ink-2);font:inherit;font-size:11px;cursor:pointer;padding:2px 0;white-space:nowrap}' +
7467
+ '.pp-note-link:hover{color:var(--pp-note-ink);text-decoration:underline;text-underline-offset:2px}' +
7468
+ '.pp-note-link-danger:hover{color:var(--pp-note-danger)}.pp-note-icon{display:inline-flex;align-items:center;justify-content:center;flex:none;width:22px;height:22px;padding:0;border:1px solid transparent;border-radius:6px;background:transparent;color:var(--pp-note-ink-2);cursor:pointer}.pp-note-icon:hover{background:var(--pp-note-hover);color:var(--pp-note-ink)}.pp-note-icon.pp-note-link-danger:hover{color:var(--pp-note-danger)}.pp-note-ask{display:inline-flex;align-items:center;gap:4px;color:var(--pp-note-ink-2);font-size:11px;white-space:nowrap}';
7469
+
5426
7470
  // ------------------------------------------------------------------- plugin
5427
7471
  return {
5428
7472
  inject: ['slots', 'locale'],
@@ -5529,6 +7573,14 @@ window.__ModuleLoader__.load({
5529
7573
  SelectionMenu,
5530
7574
  ),
5531
7575
  );
7576
+ // Annotations: cards and the inline editor in the frame overlay; the list
7577
+ // and the composed reply live in the prompt pool views' annotation tab.
7578
+ ctx.slots.inject('shell.overlay', () =>
7579
+ ctx.slots.register(
7580
+ { name: 'shell.overlay', id: 'prompt-pool-notes', order: 30, label: () => translate('note.title') },
7581
+ NotesLayer,
7582
+ ),
7583
+ );
5532
7584
 
5533
7585
  ctx.slots.inject('settings.section', () =>
5534
7586
  ctx.slots.register(
@@ -5636,7 +7688,4 @@ window.__ModuleLoader__.load({
5636
7688
  },
5637
7689
  };
5638
7690
  },
5639
- });
5640
-
5641
-
5642
-
7691
+ });