@wangnanshan/dsh-nanshan-session-manager 1.1.9 → 1.4.2

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/client.js +1223 -194
  2. package/index.js +282 -0
  3. package/package.json +1 -1
package/client.js CHANGED
@@ -9,6 +9,68 @@ window.__ModuleLoader__.load({
9
9
  const NS = 'nanshan-session-manager';
10
10
  const PACKAGE_NAME = '@wangnanshan/dsh-nanshan-session-manager';
11
11
  const FILTERS = ['all', 'running', 'open', 'archived', 'subagent', 'pinned', 'migration'];
12
+ const MODULES = [
13
+ { id: 'session', key: 'module.session', icon: 'archive' },
14
+ { id: 'rule', key: 'module.rule', icon: 'branch' },
15
+ ];
16
+
17
+ const RULE_SCOPES = ['global', 'workspace', 'session'];
18
+
19
+ async function apiFetch(path, options = {}) {
20
+ const response = await fetch(`${API}${path}`, {
21
+ ...options,
22
+ credentials: 'same-origin',
23
+ headers: { accept: 'application/json', ...(options.headers || {}) },
24
+ });
25
+ const data = await response.json().catch(() => ({}));
26
+ if (!response.ok || !data.ok) {
27
+ const err = new Error(data?.message || `HTTP ${response.status}`);
28
+ err.status = response.status;
29
+ throw err;
30
+ }
31
+ return data;
32
+ }
33
+
34
+ async function loadRulesApi() {
35
+ const data = await apiFetch('/rules');
36
+ return data.rules || {};
37
+ }
38
+
39
+ async function createRuleApi(rule) {
40
+ const data = await apiFetch('/rules/create', {
41
+ method: 'POST',
42
+ headers: { 'content-type': 'application/json' },
43
+ body: JSON.stringify(rule),
44
+ });
45
+ return data.rule;
46
+ }
47
+
48
+ async function updateRuleApi(rule) {
49
+ const data = await apiFetch('/rules/update', {
50
+ method: 'POST',
51
+ headers: { 'content-type': 'application/json' },
52
+ body: JSON.stringify(rule),
53
+ });
54
+ return data.rule;
55
+ }
56
+
57
+ async function deleteRuleApi(id) {
58
+ const data = await apiFetch('/rules/delete', {
59
+ method: 'POST',
60
+ headers: { 'content-type': 'application/json' },
61
+ body: JSON.stringify({ id }),
62
+ });
63
+ return data.rule;
64
+ }
65
+
66
+ async function toggleRuleApi(id, enabled) {
67
+ const data = await apiFetch('/rules/toggle', {
68
+ method: 'POST',
69
+ headers: { 'content-type': 'application/json' },
70
+ body: JSON.stringify({ id, enabled }),
71
+ });
72
+ return data.rule;
73
+ }
12
74
 
13
75
  const DICTIONARIES = {
14
76
  zh: {
@@ -159,6 +221,77 @@ window.__ModuleLoader__.load({
159
221
  'relative.minutes': '{n} 分钟前',
160
222
  'relative.hours': '{n} 小时前',
161
223
  'relative.days': '{n} 天前',
224
+ 'module.session': '会话管理',
225
+ 'module.session.desc': '浏览、筛选、导入导出和删除会话',
226
+ 'module.rule': '规则管理',
227
+ 'module.rule.desc': '管理 AI 助手行为规则与提示词',
228
+ 'module.rule.placeholder': '规则管理功能正在开发中…',
229
+ 'rule.title': '规则列表',
230
+ 'rule.titleMeta': '共 {total} 条 · {enabled} 启用',
231
+ 'rule.new': '新建规则',
232
+ 'rule.empty': '还没有任何规则',
233
+ 'rule.emptyBody': '规则可以在全局、工作区、单个会话范围内约束 AI 助手的行为。',
234
+ 'rule.emptyCta': '创建第一条规则',
235
+ 'rule.emptyFiltered': '当前筛选条件下没有规则',
236
+ 'rule.showMore': '展开',
237
+ 'rule.showLess': '收起',
238
+ 'rule.listColTitle': '标题',
239
+ 'rule.listColScope': '作用范围',
240
+ 'rule.listColTarget': '作用对象',
241
+ 'rule.listColUpdated': '最近更新',
242
+ 'rule.listColActions': '操作',
243
+ 'rule.scope.global': '全局',
244
+ 'rule.scope.globalHint': '作用于所有会话',
245
+ 'rule.scope.workspace': '工作区',
246
+ 'rule.scope.workspaceHint': '仅在指定工作区生效',
247
+ 'rule.scope.workspacePick': '选择工作区',
248
+ 'rule.scope.session': '会话',
249
+ 'rule.scope.sessionHint': '仅在指定会话生效',
250
+ 'rule.scope.sessionPick': '选择会话',
251
+ 'rule.picker.workspaceTitle': '选择工作区',
252
+ 'rule.picker.sessionTitle': '选择会话',
253
+ 'rule.picker.search': '搜索…',
254
+ 'rule.picker.empty': '暂无数据',
255
+ 'rule.picker.selected': '已选 {n} 项',
256
+ 'rule.filter.all': '全部规则',
257
+ 'rule.filter.enabled': '已启用',
258
+ 'rule.filter.disabled': '已禁用',
259
+ 'rule.filter.scope': '按作用范围',
260
+ 'rule.filter.scopeAll': '全部范围',
261
+ 'rule.filter.scopeGlobal': '全局',
262
+ 'rule.filter.scopeWorkspace': '工作区',
263
+ 'rule.filter.scopeSession': '会话',
264
+ 'rule.target.global': '—',
265
+ 'rule.toggleOn': '启用',
266
+ 'rule.toggleOff': '禁用',
267
+ 'rule.edit': '编辑',
268
+ 'rule.delete': '删除',
269
+ 'rule.deleteConfirmTitle': '删除规则?',
270
+ 'rule.deleteConfirmBody': '删除后无法恢复,确定要删除 "{title}" 吗?',
271
+ 'rule.form.newTitle': '新建规则',
272
+ 'rule.form.editTitle': '编辑规则',
273
+ 'rule.form.titleLabel': '规则标题',
274
+ 'rule.form.titlePlaceholder': '用一句话描述这条规则的作用',
275
+ 'rule.form.contentLabel': '规则内容',
276
+ 'rule.form.contentPlaceholder': '输入自然语言提示词或行为约束…',
277
+ 'rule.form.scopeLabel': '作用范围',
278
+ 'rule.form.targetLabel': '作用对象',
279
+ 'rule.form.targetPlaceholder': '选择或输入作用对象 ID',
280
+ 'rule.form.markdownHint': '规则内容支持 Markdown 格式(# 标题、**粗体**、- 列表、`代码` 等)',
281
+ 'rule.form.editMode': '编辑',
282
+ 'rule.form.previewMode': '预览',
283
+ 'rule.form.enabledLabel': '启用',
284
+ 'rule.form.save': '保存',
285
+ 'rule.form.cancel': '取消',
286
+ 'rule.form.delete': '删除',
287
+ 'rule.form.titleEmpty': '请填写规则标题',
288
+ 'rule.form.contentEmpty': '请填写规则内容',
289
+ 'rule.form.targetRequired': '作用范围为「{scope}」时必须指定作用对象',
290
+ 'rule.saved': '规则已保存',
291
+ 'rule.created': '规则已创建',
292
+ 'rule.deleted': '规则已删除',
293
+ 'rule.loadError': '规则加载失败',
294
+ 'rule.saveError': '规则保存失败',
162
295
  },
163
296
  en: {
164
297
  'nav.title': '【南山】Session Management Assistant',
@@ -308,6 +441,77 @@ window.__ModuleLoader__.load({
308
441
  'relative.minutes': '{n} min ago',
309
442
  'relative.hours': '{n} h ago',
310
443
  'relative.days': '{n} d ago',
444
+ 'module.session': 'Session Manager',
445
+ 'module.session.desc': 'Browse, filter, import, export and delete sessions',
446
+ 'module.rule': 'Rule Manager',
447
+ 'module.rule.desc': 'Manage AI assistant behavior rules and prompts',
448
+ 'module.rule.placeholder': 'Rule management is under development…',
449
+ 'rule.title': 'Rules',
450
+ 'rule.titleMeta': '{total} rules · {enabled} active',
451
+ 'rule.new': 'New Rule',
452
+ 'rule.empty': 'No rules yet',
453
+ 'rule.emptyBody': 'Rules constrain the AI assistant behaviour at global, workspace or session scope.',
454
+ 'rule.emptyCta': 'Create your first rule',
455
+ 'rule.emptyFiltered': 'No rules match the current filter',
456
+ 'rule.listColTitle': 'Title',
457
+ 'rule.listColScope': 'Scope',
458
+ 'rule.listColTarget': 'Target',
459
+ 'rule.listColUpdated': 'Updated',
460
+ 'rule.listColActions': 'Actions',
461
+ 'rule.scope.global': 'Global',
462
+ 'rule.scope.globalHint': 'Applies to all sessions',
463
+ 'rule.scope.workspace': 'Workspace',
464
+ 'rule.scope.workspaceHint': 'Only in the specified workspace',
465
+ 'rule.scope.workspacePick': 'Pick workspace',
466
+ 'rule.scope.session': 'Session',
467
+ 'rule.scope.sessionHint': 'Only in the specified session',
468
+ 'rule.scope.sessionPick': 'Pick session',
469
+ 'rule.picker.workspaceTitle': 'Select workspaces',
470
+ 'rule.picker.sessionTitle': 'Select sessions',
471
+ 'rule.picker.search': 'Search…',
472
+ 'rule.picker.empty': 'No data',
473
+ 'rule.picker.selected': '{n} selected',
474
+ 'rule.filter.all': 'All rules',
475
+ 'rule.filter.enabled': 'Active',
476
+ 'rule.filter.disabled': 'Disabled',
477
+ 'rule.filter.scope': 'By scope',
478
+ 'rule.filter.scopeAll': 'Any scope',
479
+ 'rule.filter.scopeGlobal': 'Global',
480
+ 'rule.filter.scopeWorkspace': 'Workspace',
481
+ 'rule.filter.scopeSession': 'Session',
482
+ 'rule.target.global': '—',
483
+ 'rule.toggleOn': 'Enable',
484
+ 'rule.toggleOff': 'Disable',
485
+ 'rule.edit': 'Edit',
486
+ 'rule.delete': 'Delete',
487
+ 'rule.deleteConfirmTitle': 'Delete rule?',
488
+ 'rule.deleteConfirmBody': 'This cannot be undone. Delete "{title}"?',
489
+ 'rule.form.newTitle': 'New Rule',
490
+ 'rule.form.editTitle': 'Edit Rule',
491
+ 'rule.form.titleLabel': 'Rule title',
492
+ 'rule.form.titlePlaceholder': 'One sentence describing this rule',
493
+ 'rule.form.contentLabel': 'Rule content',
494
+ 'rule.form.contentPlaceholder': 'Natural-language prompt or behaviour constraints…',
495
+ 'rule.form.scopeLabel': 'Scope',
496
+ 'rule.form.targetLabel': 'Target',
497
+ 'rule.form.targetPlaceholder': 'Select or enter target ID',
498
+ 'rule.form.markdownHint': 'Content supports Markdown (## headings, **bold**, - lists, `code` etc.)',
499
+ 'rule.form.editMode': 'Edit',
500
+ 'rule.form.previewMode': 'Preview',
501
+ 'rule.form.enabledLabel': 'Enabled',
502
+ 'rule.form.save': 'Save',
503
+ 'rule.form.cancel': 'Cancel',
504
+ 'rule.form.delete': 'Delete',
505
+ 'rule.form.titleEmpty': 'Please enter a rule title',
506
+ 'rule.form.contentEmpty': 'Please enter rule content',
507
+ 'rule.form.targetRequired': 'Target is required when scope is "{scope}"',
508
+ 'rule.saved': 'Rule saved',
509
+ 'rule.created': 'Rule created',
510
+ 'rule.showMore': 'Show more',
511
+ 'rule.showLess': 'Show less',
512
+ 'rule.deleted': 'Rule deleted',
513
+ 'rule.loadError': 'Failed to load rules',
514
+ 'rule.saveError': 'Failed to save rule',
311
515
  },
312
516
  };
313
517
 
@@ -330,8 +534,8 @@ window.__ModuleLoader__.load({
330
534
  --nsm-green: var(--dsw-alias-state-success-primary);
331
535
  --nsm-amber: var(--dsw-alias-state-warn-primary);
332
536
  --nsm-violet: var(--dsw-alias-state-done-primary);
333
- --nsm-radius: 9px;
334
- --nsm-radius-sm: 6px;
537
+ --nsm-radius: 8px;
538
+ --nsm-radius-sm: 5px;
335
539
  --nsm-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, "Helvetica Neue", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
336
540
  height: 100%;
337
541
  overflow-y: auto;
@@ -367,13 +571,14 @@ window.__ModuleLoader__.load({
367
571
  .nsm__button--ghost { border-color: transparent; background: transparent; color: var(--nsm-secondary); }
368
572
  .nsm__button--ghost:hover:not(:disabled) { background: var(--nsm-hover); color: var(--nsm-text); }
369
573
  .nsm__button--small { height: 26px; padding: 0 8px; font-size: 11.5px; }
370
- .nsm__stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin-top: 24px; border: 1px solid var(--nsm-border); border-radius: var(--nsm-radius); background: var(--nsm-surface); overflow: hidden; }
371
- .nsm__stat { position: relative; padding: 14px 16px; border-left: 1px solid var(--nsm-border); background: transparent; }
372
- .nsm__stat:first-child { border-left: 0; }
574
+ .nsm__stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); padding: 4px; border-radius: var(--nsm-radius); background: transparent; gap: 4px; }
575
+ .nsm__stat { position: relative; padding: 14px 16px; border-radius: var(--nsm-radius); background: var(--nsm-surface); border: 1px solid var(--nsm-border); }
576
+ .nsm__stat:first-child { }
577
+ .nsm__stat + .nsm__stat { }
373
578
  .nsm__stat::after { display: none; }
374
579
  .nsm__stat-label { display: block; font-size: 11px; font-weight: 500; line-height: 1.4; color: var(--nsm-tertiary); }
375
580
  .nsm__stat-value { display: block; margin-top: 3px; font-family: var(--nsm-font); font-size: 20px; font-weight: 600; line-height: 1.2; letter-spacing: -.02em; color: var(--nsm-text); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
376
- .nsm__toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 16px; padding: 8px; border: 1px solid var(--nsm-border); border-radius: var(--nsm-radius); background: var(--nsm-surface); }
581
+ .nsm__toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 12px; padding: 10px 14px; border: 1px solid var(--nsm-border); border-radius: var(--nsm-radius); background: var(--nsm-surface); }
377
582
  .nsm__viewtabs { display: flex; align-items: center; flex: none; gap: 2px; padding: 2px; border: 1px solid var(--nsm-border); border-radius: var(--nsm-radius-sm); background: var(--nsm-muted-surface); }
378
583
  .nsm__viewtab { appearance: none; display: inline-flex; align-items: center; justify-content: center; gap: 5px; height: 26px; padding: 0 10px; border: 1px solid transparent; border-radius: 5px; background: transparent; color: var(--nsm-secondary); font-size: 11.5px; font-weight: 500; line-height: 1; white-space: nowrap; cursor: pointer; }
379
584
  .nsm__viewtab:hover { color: var(--nsm-text); background: var(--nsm-hover); }
@@ -385,7 +590,7 @@ window.__ModuleLoader__.load({
385
590
  .nsm__search-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--nsm-tertiary); pointer-events: none; }
386
591
  .nsm__search input { width: 100%; height: 30px; padding: 0 30px 0 32px; border: 1px solid var(--nsm-border-strong); border-radius: var(--nsm-radius-sm); background: var(--nsm-bg); color: var(--nsm-text); font-size: 12px; outline: none; transition: border-color .12s ease, box-shadow .12s ease; }
387
592
  .nsm__search input::placeholder { color: var(--nsm-tertiary); }
388
- .nsm__search input:focus { border-color: var(--nsm-accent); box-shadow: 0 0 0 3px var(--nsm-accent-soft); }
593
+ .nsm__search input:focus { border-color: var(--nsm-accent); }
389
594
  .nsm__search-clear { position: absolute; right: 3px; top: 50%; transform: translateY(-50%); display: grid; place-items: center; width: 24px; height: 24px; padding: 0; border: 0; border-radius: 4px; background: transparent; color: var(--nsm-tertiary); cursor: pointer; }
390
595
  .nsm__search-clear:hover { background: var(--nsm-hover); color: var(--nsm-text); }
391
596
  .nsm__toolbar-spacer { flex: 1 1 auto; }
@@ -398,7 +603,7 @@ window.__ModuleLoader__.load({
398
603
  .nsm__filter.is-active .nsm__filter-count { color: inherit; opacity: .72; }
399
604
  .nsm__layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; margin-top: 16px; }
400
605
  .nsm__tree-card { min-width: 0; border: 1px solid var(--nsm-border); border-radius: var(--nsm-radius); background: var(--nsm-surface); overflow: hidden; }
401
- .nsm__tree-head { display: flex; align-items: center; gap: 8px; min-height: 42px; padding: 0 14px; border-bottom: 1px solid var(--nsm-border); background: transparent; }
606
+ .nsm__tree-head { display: flex; align-items: center; gap: 8px; min-height: 36px; padding: 0 14px; border-bottom: 1px solid var(--nsm-border); background: transparent; }
402
607
  .nsm__tree-head h2 { margin: 0; font-family: var(--nsm-font); font-size: 12.5px; font-weight: 600; line-height: 1.4; letter-spacing: -.01em; color: var(--nsm-text); }
403
608
  .nsm__tree-head-meta { margin-left: auto; color: var(--nsm-tertiary); font-size: 11px; font-variant-numeric: tabular-nums; white-space: nowrap; }
404
609
  .nsm__tree-body { padding: 4px 6px 8px; }
@@ -489,7 +694,8 @@ window.__ModuleLoader__.load({
489
694
  .nsm__fact button { appearance: none; padding: 0; border: 0; background: none; color: inherit; font: inherit; text-align: left; word-break: break-word; cursor: pointer; }
490
695
  .nsm__fact button:hover { color: var(--nsm-accent); text-decoration: underline; text-underline-offset: 2px; }
491
696
  .nsm__detail-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--nsm-border); }
492
- .nsm__import-card { background: var(--nsm-surface); }
697
+ .nsm__import-card { background: transparent; border: none; padding: 0; }
698
+ .nsm__import-card .nsm__card-head { display: none; }
493
699
  .nsm__import-card .nsm__button { margin-top: 2px; }
494
700
  .nsm__empty { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 240px; padding: 32px 20px; text-align: center; }
495
701
  .nsm__empty-mark { display: grid; place-items: center; width: 48px; height: 48px; padding: 8px; border: 1px solid var(--nsm-accent-line); border-radius: 9px; background: linear-gradient(145deg, color-mix(in srgb, var(--nsm-accent) 14%, transparent), color-mix(in srgb, var(--nsm-accent) 4%, transparent)); color: var(--nsm-accent); }
@@ -503,7 +709,7 @@ window.__ModuleLoader__.load({
503
709
  @keyframes nsm-spin { to { transform: rotate(360deg); } }
504
710
  .nsm__error { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 240px; padding: 28px; text-align: center; }
505
711
  .nsm__error p { margin: 0 0 14px; color: var(--nsm-danger); font-size: 12px; line-height: 1.6; }
506
- .nsm__report { margin: 0 0 14px; padding: 10px 12px; border: 1px solid var(--nsm-border); border-radius: var(--nsm-radius-sm); background: var(--nsm-surface); }
712
+ .nsm__report { margin: 0 0 14px; padding: 10px 12px; border: 1px solid var(--nsm-border); border-radius: var(--nsm-radius-sm); background: var(--nsm-muted-surface); }
507
713
  .nsm__report-head { display: flex; align-items: center; gap: 8px; color: var(--nsm-text); font-size: 12px; font-weight: 500; }
508
714
  .nsm__report-head .nsm__icon-button { margin-left: auto; }
509
715
  .nsm__report ul { margin: 6px 0 0; padding-left: 18px; color: var(--nsm-tertiary); font-size: 11px; line-height: 1.6; }
@@ -514,7 +720,17 @@ window.__ModuleLoader__.load({
514
720
  .nsm__footer-copy:hover { background: var(--nsm-hover); color: var(--nsm-text); border-color: var(--nsm-border-strong); }
515
721
  .nsm__footer-copy:focus-visible { outline: 2px solid var(--nsm-accent); outline-offset: 1px; }
516
722
  .nsm__modal { position: fixed; inset: 0; z-index: 1200; display: grid; place-items: center; padding: 22px; background: rgba(15, 17, 21, .38); backdrop-filter: blur(2px); }
517
- .nsm__dialog { box-sizing: border-box; width: min(440px, 100%); max-height: min(620px, 90vh); overflow: auto; padding: 20px; border: 1px solid var(--nsm-border); border-radius: 10px; background: var(--nsm-surface); box-shadow: var(--dsw-shadow-lv3, 0 12px 32px rgba(0, 0, 0, .16)); }
723
+ .nsm__modal-card { box-sizing: border-box; width: min(520px, 100%); max-height: min(90vh, 780px); overflow: auto; padding: 18px 20px 16px; border: none; border-radius: 12px; background: var(--nsm-surface); box-shadow: 0 20px 48px rgba(0, 0, 0, .12), 0 4px 12px rgba(0, 0, 0, .08); }
724
+ .nsm__form-card { width: min(90vw, 1100px); max-height: min(90vh, 860px); padding: 20px 24px 18px; }
725
+ .nsm__confirm-card { width: min(400px, 100%); }
726
+ .nsm__modal-head { display: flex; align-items: center; justify-content: space-between; margin: 0 0 14px; }
727
+ .nsm__modal-head h3 { margin: 0; font-family: var(--nsm-font); font-size: 14px; font-weight: 600; letter-spacing: -.01em; color: var(--nsm-text); }
728
+ .nsm__modal-body { margin: 0 0 6px; font-size: 12px; line-height: 1.65; color: var(--nsm-secondary); }
729
+ .nsm__modal-close { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; border: none; border-radius: var(--nsm-radius-sm); background: transparent; color: var(--nsm-secondary); cursor: pointer; transition: background-color .12s ease, color .12s ease; }
730
+ .nsm__modal-close:hover { background: var(--nsm-hover); color: var(--nsm-text); }
731
+ .nsm__form-input.is-error,
732
+ .nsm__form-textarea.is-error { border-color: #ef4444; box-shadow: 0 0 0 2px rgba(239, 68, 68, .12); }
733
+ .nsm__dialog { box-sizing: border-box; width: min(440px, 100%); max-height: min(620px, 90vh); overflow: auto; padding: 20px; border: none; border-radius: 12px; background: var(--nsm-surface); box-shadow: 0 20px 48px rgba(0, 0, 0, .12), 0 4px 12px rgba(0, 0, 0, .08); }
518
734
  .nsm__dialog h2 { margin: 0 0 8px; font-family: var(--nsm-font); font-size: 16px; font-weight: 600; line-height: 1.35; letter-spacing: -.01em; }
519
735
  .nsm__dialog-warning { margin: 0 0 12px; color: var(--nsm-secondary); font-size: 12px; line-height: 1.65; }
520
736
  .nsm__dialog-list { margin: 0 0 12px; padding: 8px 10px; list-style: none; border: 1px solid var(--nsm-border); border-radius: var(--nsm-radius-sm); background: var(--nsm-muted-surface); font-size: 11.5px; line-height: 1.75; }
@@ -533,12 +749,163 @@ window.__ModuleLoader__.load({
533
749
  .nsm__toast-action:hover { background: rgba(255, 255, 255, .16); }
534
750
  @keyframes nsm-toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
535
751
  .nsm__sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
752
+ /* ── Module workspace (sidebar + content) ── */
753
+ .nsm__workspace { display: grid; grid-template-columns: 180px minmax(0, 1fr); gap: 16px; align-items: start; margin-top: 24px; }
754
+ .nsm__sidebar { display: flex; flex-direction: column; gap: 4px; position: sticky; top: 16px; padding: 4px; border: none; border-radius: 0; background: transparent; }
755
+ .nsm__module { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid transparent; border-radius: var(--nsm-radius-sm); background: transparent; cursor: pointer; transition: background-color .12s ease, border-color .12s ease; text-align: left; color: var(--nsm-secondary); }
756
+ .nsm__module:hover { background: var(--nsm-hover); color: var(--nsm-text); }
757
+ .nsm__module:focus-visible { outline: 2px solid var(--nsm-accent); outline-offset: -2px; }
758
+ .nsm__module.is-active { border-color: var(--nsm-accent-line); background: var(--nsm-accent-soft); color: var(--nsm-accent); }
759
+ .nsm__module-icon { display: grid; place-items: center; width: 22px; height: 22px; color: currentColor; }
760
+ .nsm__module-icon svg { width: 14px; height: 14px; }
761
+ .nsm__module-label { font-family: var(--nsm-font); font-size: 12px; font-weight: 600; line-height: 1.3; letter-spacing: -.005em; }
762
+ .nsm__main { min-width: 0; display: flex; flex-direction: column; gap: 0; padding: 0; border: none; border-radius: 0; background: transparent; }
763
+ .nsm__pane { display: flex; flex-direction: column; gap: 16px; }
764
+ /* Rule manager placeholder */
765
+ .nsm__rule-placeholder { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 320px; padding: 32px 24px; text-align: center; border: 1px dashed var(--nsm-border); border-radius: var(--nsm-radius); background: var(--nsm-surface); }
766
+ .nsm__rule-placeholder-mark { display: grid; place-items: center; width: 56px; height: 56px; padding: 10px; border: 1px solid var(--nsm-border-strong); border-radius: 12px; color: var(--nsm-tertiary); background: var(--nsm-muted-surface); }
767
+ .nsm__rule-placeholder-mark svg { display: block; width: 100%; height: 100%; }
768
+ .nsm__rule-placeholder h2 { margin: 14px 0 4px; font-family: var(--nsm-font); font-size: 15px; font-weight: 600; line-height: 1.4; letter-spacing: -.01em; color: var(--nsm-text); }
769
+ .nsm__rule-placeholder p { max-width: 360px; margin: 0; color: var(--nsm-tertiary); font-size: 11.5px; line-height: 1.6; }
770
+ /* ── Rule Manager (v1.4 Linear/Vercel style) ── */
771
+ .nsm__rules-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 0; border: none; border-radius: 0; background: transparent; }
772
+ .nsm__rules-toolbar-head { display: flex; align-items: center; gap: 8px; margin-right: auto; }
773
+ .nsm__rules-title { font-family: var(--nsm-font); font-size: 13px; font-weight: 600; color: var(--nsm-text); letter-spacing: -.005em; }
774
+ .nsm__rules-meta { font-size: 10.5px; color: var(--nsm-tertiary); }
775
+ .nsm__rules-filter { display: inline-flex; gap: 4px; }
776
+ .nsm__rules-filter-group { display: inline-flex; gap: 4px; padding: 2px; border: 1px solid var(--nsm-border); border-radius: var(--nsm-radius-sm); background: var(--nsm-bg); }
777
+ .nsm__rules-filter-btn { font-family: var(--nsm-font); font-size: 10.5px; font-weight: 500; padding: 4px 10px; border: none; border-radius: var(--nsm-radius-sm); background: transparent; color: var(--nsm-secondary); cursor: pointer; transition: background-color .12s ease, color .12s ease; }
778
+ .nsm__rules-filter-btn:hover { color: var(--nsm-text); }
779
+ .nsm__rules-filter-btn.is-active { background: var(--nsm-accent-soft); color: var(--nsm-accent); }
780
+ .nsm__rules-list { display: flex; flex-direction: column; gap: 10px; }
781
+
782
+ /* ── v1.4 rule card ── */
783
+ .nsm__rule-card { display: flex; flex-direction: column; gap: 10px; padding: 16px 18px; border: 1px solid var(--nsm-border); border-radius: 10px; background: var(--nsm-surface); transition: border-color .15s ease, background-color .15s ease; }
784
+ .nsm__rule-card:hover { border-color: var(--nsm-border-strong); }
785
+ .nsm__rule-card.is-disabled { opacity: .55; }
786
+ .nsm__rule-card-head { display: flex; align-items: center; gap: 10px; }
787
+ .nsm__rule-card-title { flex: 1 1 auto; min-width: 0; font-family: var(--nsm-font); font-size: 13.5px; font-weight: 600; color: var(--nsm-text); line-height: 1.4; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
788
+ .nsm__rule-card-title.is-disabled { color: var(--nsm-tertiary); text-decoration: line-through; }
789
+ .nsm__rule-card-meta { flex-shrink: 0; display: inline-flex; align-items: center; gap: 8px; font-size: 10.5px; color: var(--nsm-tertiary); font-variant-numeric: tabular-nums; }
790
+ .nsm__rule-card-body { font-family: var(--nsm-mono); font-size: 11.5px; line-height: 1.6; color: var(--nsm-secondary); }
791
+ .nsm__rule-card-content { white-space: pre-wrap; word-break: break-word; overflow: hidden; transition: max-height .25s ease; }
792
+ .nsm__rule-card-content.is-collapsed { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; max-height: 3.2em; }
793
+ .nsm__rule-card-toggle { font-family: var(--nsm-font); font-size: 11px; font-weight: 500; padding: 2px 0; border: none; background: transparent; color: var(--nsm-accent); cursor: pointer; margin-top: 2px; letter-spacing: .01em; }
794
+ .nsm__rule-card-toggle:hover { text-decoration: underline; }
795
+
796
+ /* Foot: scope tabs + picker + actions */
797
+ .nsm__rule-card-foot { display: flex; align-items: center; gap: 10px; padding-top: 10px; border-top: 1px solid var(--nsm-border); }
798
+ .nsm__rule-card-foot .nsm__toggle { margin-left: 0; }
799
+ .nsm__rule-card-foot .nsm__icon-btn { width: 28px; height: 28px; }
800
+ .nsm__rule-card-foot-spacer { flex: 1 1 auto; }
801
+
802
+ /* Segmented scope tabs */
803
+ .nsm__scope-tabs { display: inline-flex; align-items: center; padding: 2px; border: 1px solid var(--nsm-border); border-radius: 7px; background: var(--nsm-bg); gap: 1px; }
804
+ .nsm__scope-tab { font-family: var(--nsm-font); font-size: 11px; font-weight: 500; padding: 4px 10px; border: none; border-radius: 5px; background: transparent; color: var(--nsm-secondary); cursor: pointer; transition: background-color .12s ease, color .12s ease; white-space: nowrap; }
805
+ .nsm__scope-tab:not(.is-active):hover { color: var(--nsm-text); background: var(--nsm-hover); }
806
+ .nsm__scope-tab.is-active { background: var(--nsm-text); color: var(--nsm-surface); font-weight: 600; box-shadow: none; }
807
+ .nsm__scope-tab.is-active:hover { color: var(--nsm-surface); }
808
+
809
+ /* Global scope hint */
810
+ .nsm__scope-global-hint { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; color: var(--nsm-tertiary); padding: 3px 10px; background: rgba(59, 130, 246, .08); border-radius: 999px; white-space: nowrap; }
811
+ .nsm__scope-global-hint::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: #3b82f6; }
812
+
813
+ /* Picker button (workspace/session) */
814
+ .nsm__scope-picker-btn { display: inline-flex; align-items: center; gap: 6px; font-family: var(--nsm-font); font-size: 11px; font-weight: 500; padding: 4px 12px; border: 1px solid var(--nsm-border); border-radius: 7px; background: var(--nsm-surface); color: var(--nsm-text); cursor: pointer; transition: border-color .12s ease, background-color .12s ease; white-space: nowrap; }
815
+ .nsm__scope-picker-btn:hover { border-color: var(--nsm-border-strong); background: var(--nsm-hover); }
816
+ .nsm__scope-picker-btn[data-scope="workspace"] { color: #10b981; }
817
+ .nsm__scope-picker-btn[data-scope="session"] { color: #f59e0b; }
818
+ .nsm__scope-picker-btn .nsm__scope-count { display: inline-flex; align-items: center; justify-content: center; min-width: 16px; height: 16px; padding: 0 5px; border-radius: 8px; font-size: 10px; font-weight: 600; background: var(--nsm-bg); color: var(--nsm-secondary); font-variant-numeric: tabular-nums; }
819
+
820
+ /* ── Picker modal (tree selection) ── */
821
+ .nsm__picker { display: flex; flex-direction: column; gap: 0; }
822
+ .nsm__picker-search { box-sizing: border-box; width: 100%; padding: 8px 10px; border: 1px solid var(--nsm-border); border-radius: var(--nsm-radius-sm); background: var(--nsm-bg); color: var(--nsm-text); font-family: var(--nsm-font); font-size: 12px; }
823
+ .nsm__picker-search:focus { outline: none; border-color: var(--nsm-accent); }
824
+ .nsm__picker-tree { max-height: 52vh; overflow: auto; margin-top: 10px; }
825
+ .nsm__picker-group { border-bottom: 1px solid var(--nsm-border); }
826
+ .nsm__picker-group:last-child { border-bottom: none; }
827
+ .nsm__picker-group-head { display: flex; align-items: center; gap: 6px; padding: 8px 4px; font-size: 11.5px; font-weight: 600; color: var(--nsm-text); font-family: var(--nsm-font); }
828
+ .nsm__picker-group-arrow { font-size: 9px; color: var(--nsm-tertiary); transition: transform .15s ease; cursor: pointer; user-select: none; width: 12px; display: inline-block; text-align: center; }
829
+ .nsm__picker-group-arrow.is-open { transform: rotate(90deg); }
830
+ .nsm__picker-group-label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
831
+ .nsm__picker-group-count { font-size: 10.5px; color: var(--nsm-tertiary); font-weight: 400; }
832
+ .nsm__picker-month { padding: 6px 4px 4px 20px; font-size: 10.5px; font-weight: 500; color: var(--nsm-tertiary); }
833
+ .nsm__picker-item { display: flex; align-items: center; gap: 8px; padding: 6px 4px 6px 28px; cursor: pointer; border-radius: 5px; transition: background-color .1s ease; }
834
+ .nsm__picker-item:hover { background: var(--nsm-hover); }
835
+ .nsm__picker-item.is-workspace { padding-left: 4px; }
836
+ .nsm__picker-item-label { flex: 1 1 auto; min-width: 0; font-size: 11.5px; color: var(--nsm-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
837
+ .nsm__picker-item-meta { font-size: 10px; color: var(--nsm-tertiary); font-variant-numeric: tabular-nums; }
838
+ .nsm__picker-actions { display: flex; justify-content: space-between; align-items: center; padding-top: 12px; border-top: 1px solid var(--nsm-border); margin-top: 4px; }
839
+ .nsm__picker-actions .nsm__picker-selected-info { font-size: 11px; color: var(--nsm-tertiary); }
840
+ .nsm__picker-actions .nsm__modal-footer { border-top: none; margin: 0; padding: 0; display: flex; gap: 8px; }
841
+ .nsm__rule-title-link { font-family: var(--nsm-font); font-size: 12.5px; font-weight: 500; color: var(--nsm-text); cursor: pointer; transition: color .12s ease; display: flex; align-items: center; gap: 8px; }
842
+ .nsm__rule-title-link:hover { color: var(--nsm-accent); }
843
+ .nsm__rule-title-link.is-disabled { color: var(--nsm-tertiary); text-decoration: line-through; }
844
+ .nsm__rule-content-preview { display: block; margin-top: 2px; max-width: 320px; font-size: 11px; color: var(--nsm-tertiary); line-height: 1.45; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
845
+ .nsm__rule-scope-cell { min-width: 72px; }
846
+ .nsm__scope-pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 10px; font-size: 10.5px; font-weight: 500; line-height: 1.5; }
847
+ .nsm__scope-pill[data-scope="global"] { background: rgba(59, 130, 246, .12); color: #3b82f6; }
848
+ .nsm__scope-pill[data-scope="workspace"] { background: rgba(16, 185, 129, .12); color: #10b981; }
849
+ .nsm__scope-pill[data-scope="session"] { background: rgba(245, 158, 11, .12); color: #f59e0b; }
850
+ .nsm__rule-target-cell { min-width: 120px; max-width: 200px; color: var(--nsm-tertiary); font-family: var(--nsm-mono); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
851
+ .nsm__rule-updated-cell { min-width: 80px; color: var(--nsm-tertiary); font-size: 11px; }
852
+ .nsm__rule-actions { display: inline-flex; align-items: center; gap: 4px; }
853
+ /* Toggle switch */
854
+ .nsm__toggle { position: relative; display: inline-block; width: 28px; height: 16px; flex-shrink: 0; }
855
+ .nsm__toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
856
+ .nsm__toggle-track { position: absolute; inset: 0; border-radius: 8px; background: var(--nsm-border); transition: background-color .15s ease; cursor: pointer; }
857
+ .nsm__toggle-track::after { content: ''; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: 50%; background: #fff; transition: transform .15s ease; }
858
+ .nsm__toggle input:checked + .nsm__toggle-track { background: var(--nsm-accent); }
859
+ .nsm__toggle input:checked + .nsm__toggle-track::after { transform: translateX(12px); }
860
+ .nsm__toggle input:focus-visible + .nsm__toggle-track { outline: 2px solid var(--nsm-accent); outline-offset: 1px; }
861
+ .nsm__icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; border: none; border-radius: var(--nsm-radius-sm); background: transparent; color: var(--nsm-secondary); cursor: pointer; transition: background-color .12s ease, color .12s ease; }
862
+ .nsm__icon-btn:hover { background: var(--nsm-hover); color: var(--nsm-text); }
863
+ .nsm__icon-btn.is-danger:hover { background: rgba(239, 68, 68, .1); color: #ef4444; }
864
+ /* Rule form in modal */
865
+ .nsm__form { display: flex; flex-direction: column; gap: 14px; }
866
+ .nsm__form-field { display: flex; flex-direction: column; gap: 6px; }
867
+ .nsm__form-label { font-family: var(--nsm-font); font-size: 11.5px; font-weight: 600; color: var(--nsm-secondary); letter-spacing: .01em; }
868
+ .nsm__form-input,
869
+ .nsm__form-textarea,
870
+ .nsm__form-select { width: 100%; box-sizing: border-box; padding: 8px 10px; border: 1px solid var(--nsm-border); border-radius: var(--nsm-radius-sm); background: var(--nsm-bg); color: var(--nsm-text); font-family: inherit; font-size: 12.5px; line-height: 1.5; transition: border-color .12s ease, box-shadow .12s ease; }
871
+ .nsm__form-input:focus,
872
+ .nsm__form-textarea:focus,
873
+ .nsm__form-select:focus { outline: none; border-color: var(--nsm-accent); }
874
+ .nsm__form-textarea { min-height: 320px; resize: vertical; font-family: var(--nsm-mono); font-size: 11.5px; line-height: 1.55; }
875
+ .nsm__form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
876
+ .nsm__form-label-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
877
+ .nsm__form-preview-btn { font-family: var(--nsm-font); font-size: 11px; font-weight: 500; padding: 2px 10px; border: 1px solid var(--nsm-border); border-radius: var(--nsm-radius-sm); background: var(--nsm-bg); color: var(--nsm-secondary); cursor: pointer; transition: background-color .12s ease, color .12s ease, border-color .12s ease; }
878
+ .nsm__form-preview-btn:hover { border-color: var(--nsm-accent-line); color: var(--nsm-accent); background: var(--nsm-accent-soft); }
879
+ .nsm__markdown-preview { box-sizing: border-box; min-height: 320px; max-height: 60vh; overflow: auto; padding: 18px 20px; border: 1px solid var(--nsm-border); border-radius: var(--nsm-radius-sm); background: var(--nsm-muted-surface); font-size: 12.5px; line-height: 1.7; color: var(--nsm-text); }
880
+ .nsm__markdown-preview h1, .nsm__markdown-preview h2, .nsm__markdown-preview h3 { font-family: var(--nsm-font); margin: 10px 0 6px; font-weight: 600; color: var(--nsm-text); }
881
+ .nsm__markdown-preview h1 { font-size: 17px; }
882
+ .nsm__markdown-preview h2 { font-size: 15px; }
883
+ .nsm__markdown-preview h3 { font-size: 13.5px; }
884
+ .nsm__markdown-preview p { margin: 4px 0; }
885
+ .nsm__markdown-preview ul { margin: 6px 0 6px 20px; padding: 0; }
886
+ .nsm__markdown-preview li { margin: 2px 0; }
887
+ .nsm__markdown-preview strong { color: var(--nsm-text); }
888
+ .nsm__markdown-preview em { color: var(--nsm-secondary); font-style: italic; }
889
+ .nsm__markdown-preview code { font-family: var(--nsm-mono); font-size: 11.5px; padding: 1px 5px; border-radius: 3px; background: rgba(0,0,0,.06); color: #b91c1c; }
890
+ .nsm__form-target { display: flex; flex-direction: column; gap: 6px; }
891
+ .nsm__form-target-row { display: flex; gap: 8px; align-items: stretch; }
892
+ .nsm__form-target-row .nsm__form-input { flex: 1 1 200px; }
893
+ .nsm__form-enable { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border: none; border-radius: var(--nsm-radius-sm); background: var(--nsm-muted-surface); }
894
+ .nsm__form-enable-label { font-size: 12px; color: var(--nsm-text); }
895
+ .nsm__modal-footer { display: flex; gap: 8px; justify-content: flex-end; padding-top: 10px; border-top: 1px solid var(--nsm-border); margin-top: 6px; }
896
+ .nsm__modal-footer .nsm__button--danger { margin-right: auto; }
897
+ @media (max-width: 600px) {
898
+ .nsm__form-row { grid-template-columns: 1fr; }
899
+ }
536
900
  @media (max-width: 1080px) {
537
901
  .nsm__layout { grid-template-columns: minmax(0, 1fr); }
538
902
  .nsm__aside { position: static; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
539
903
  .nsm__detail-card { grid-column: span 2; }
540
904
  }
541
905
  @media (max-width: 900px) {
906
+ .nsm__workspace { grid-template-columns: 1fr; }
907
+ .nsm__sidebar { position: static; flex-direction: row; overflow-x: auto; padding: 6px; }
908
+ .nsm__module { flex: 1 1 45%; min-width: 140px; }
542
909
  .nsm__stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
543
910
  .nsm__stat:nth-child(3) { border-left: 0; border-top: 1px solid var(--nsm-border); }
544
911
  .nsm__stat:nth-child(4) { border-top: 1px solid var(--nsm-border); }
@@ -616,6 +983,9 @@ window.__ModuleLoader__.load({
616
983
  if (name === 'pin') return h('svg', common, h('path', { d: 'M9.7 2.6 13.4 6.3l-1.9.5-2.6 2.6-.2 2.1-1.3-1.3-2.6 2.6-.9-.9 2.6-2.6L5.2 8l2.1-.2 2.6-2.6.5-1.9Z' }));
617
984
  if (name === 'alert') return h('svg', common, h('path', { d: 'M8 2.5 14 13H2L8 2.5Z' }), h('path', { d: 'M8 6.2v3.1M8 11.4v.1' }));
618
985
  if (name === 'clock') return h('svg', common, h('circle', { cx: 8, cy: 8, r: 5.6 }), h('path', { d: 'M8 4.8V8l2.2 1.4' }));
986
+ if (name === 'edit') return h('svg', common, h('path', { d: 'M4.2 10.6 10.4 4.4l2.8 2.8L7 13.4H4.2z' }), h('path', { d: 'M10.8 4l2.8 2.8' }));
987
+ if (name === 'save') return h('svg', common, h('path', { d: 'M3.2 3.2h7.2l4 4V12.8H3.2z' }), h('path', { d: 'M6.4 12.8V9.2h3.2v3.6' }));
988
+ if (name === 'plus') return h('svg', common, h('path', { d: 'M8 3.2v9.6M3.2 8h9.6' }));
619
989
  return h('svg', common, h('circle', { cx: 8, cy: 8, r: 5 }));
620
990
  }
621
991
 
@@ -660,6 +1030,183 @@ window.__ModuleLoader__.load({
660
1030
  );
661
1031
  }
662
1032
 
1033
+ function ConfirmModal(props) {
1034
+ const { title, body, danger, confirmLabel, cancelLabel, onConfirm, onCancel, t } = props;
1035
+ const overlayRef = React.useRef(null);
1036
+ React.useEffect(() => {
1037
+ function onKey(e) {
1038
+ if (e.key === 'Escape') onCancel?.();
1039
+ }
1040
+ document.addEventListener('keydown', onKey);
1041
+ return () => document.removeEventListener('keydown', onKey);
1042
+ }, [onCancel]);
1043
+ return h('div', {
1044
+ className: 'nsm__modal is-open',
1045
+ role: 'dialog',
1046
+ 'aria-modal': 'true',
1047
+ 'aria-labelledby': 'nsm-confirm-title',
1048
+ ref: overlayRef,
1049
+ onClick: (e) => { if (e.target === overlayRef.current) onCancel?.(); },
1050
+ },
1051
+ h('div', { className: 'nsm__modal-card nsm__confirm-card' },
1052
+ h('div', { className: 'nsm__modal-head' },
1053
+ h('h3', { id: 'nsm-confirm-title' }, title),
1054
+ ),
1055
+ h('div', { className: 'nsm__modal-body' },
1056
+ h('p', null, body),
1057
+ ),
1058
+ h('div', { className: 'nsm__modal-footer' },
1059
+ h('button', { type: 'button', className: 'nsm__button', onClick: onCancel }, cancelLabel || t('rule.form.cancel')),
1060
+ h('button', {
1061
+ type: 'button',
1062
+ className: `nsm__button${danger ? ' nsm__button--danger' : ' nsm__button--primary'}`,
1063
+ onClick: onConfirm,
1064
+ autoFocus: true,
1065
+ }, confirmLabel || t('rule.form.save')),
1066
+ ),
1067
+ ));
1068
+ }
1069
+
1070
+ // Minimal markdown → inline HTML (safe, no external deps)
1071
+ function renderMarkdown(md) {
1072
+ if (!md) return '';
1073
+ // 转义 HTML
1074
+ const escaped = String(md)
1075
+ .replace(/&/g, '&')
1076
+ .replace(/</g, '&lt;')
1077
+ .replace(/>/g, '&gt;');
1078
+ const lines = escaped.split('\n');
1079
+ const out = [];
1080
+ let inList = false;
1081
+ for (const rawLine of lines) {
1082
+ const line = rawLine.replace(/\s+$/, '');
1083
+ if (!line.trim()) {
1084
+ if (inList) { out.push('</ul>'); inList = false; }
1085
+ continue;
1086
+ }
1087
+ // Headings
1088
+ const h = line.match(/^(#{1,3})\s+(.+)$/);
1089
+ if (h) {
1090
+ if (inList) { out.push('</ul>'); inList = false; }
1091
+ const level = h[1].length;
1092
+ out.push(`<h${level}>${h[2]}</h${level}>`);
1093
+ continue;
1094
+ }
1095
+ // List items
1096
+ const li = line.match(/^[-*]\s+(.+)$/);
1097
+ if (li) {
1098
+ if (!inList) { out.push('<ul>'); inList = true; }
1099
+ out.push(`<li>${li[1]}</li>`);
1100
+ continue;
1101
+ }
1102
+ // Numbered list
1103
+ const nl = line.match(/^\d+\.\s+(.+)$/);
1104
+ if (nl) {
1105
+ if (!inList) { out.push('<ul>'); inList = true; }
1106
+ out.push(`<li>${nl[1]}</li>`);
1107
+ continue;
1108
+ }
1109
+ if (inList) { out.push('</ul>'); inList = false; }
1110
+ // Inline: **bold** *italic* `code`
1111
+ let inline = line
1112
+ .replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>')
1113
+ .replace(/\*(.+?)\*/g, '<em>$1</em>')
1114
+ .replace(/`([^`]+)`/g, '<code>$1</code>');
1115
+ out.push(`<p>${inline}</p>`);
1116
+ }
1117
+ if (inList) out.push('</ul>');
1118
+ return out.join('');
1119
+ }
1120
+
1121
+ function RuleFormModal(props) {
1122
+ const { form, onClose, onChange, onSave, onDelete, t } = props;
1123
+ const [titleErr, setTitleErr] = React.useState(false);
1124
+ const [contentErr, setContentErr] = React.useState(false);
1125
+ const [preview, setPreview] = React.useState(false);
1126
+ const overlayRef = React.useRef(null);
1127
+ const titleRef = React.useRef(null);
1128
+
1129
+ React.useEffect(() => {
1130
+ titleRef.current?.focus();
1131
+ }, []);
1132
+
1133
+ React.useEffect(() => {
1134
+ function onKey(e) { if (e.key === 'Escape') onClose?.(); }
1135
+ document.addEventListener('keydown', onKey);
1136
+ return () => document.removeEventListener('keydown', onKey);
1137
+ }, [onClose]);
1138
+
1139
+ function handleSubmit(e) {
1140
+ e.preventDefault?.();
1141
+ const titleEmpty = !form?.title?.trim();
1142
+ const contentEmpty = !form?.content?.trim();
1143
+ setTitleErr(titleEmpty);
1144
+ setContentErr(contentEmpty);
1145
+ if (titleEmpty || contentEmpty) return;
1146
+ onSave?.({ title: form.title.trim(), content: form.content.trim() });
1147
+ }
1148
+
1149
+ function onKeydown(e) {
1150
+ if ((e.metaKey || e.ctrlKey) && e.key === 'Enter') handleSubmit(e);
1151
+ }
1152
+
1153
+ return h('div', {
1154
+ className: 'nsm__modal is-open', role: 'dialog', 'aria-modal': 'true',
1155
+ 'aria-labelledby': 'nsm-rule-form-title', ref: overlayRef,
1156
+ onClick: (e) => { if (e.target === overlayRef.current) onClose?.(); },
1157
+ },
1158
+ h('div', { className: 'nsm__modal-card nsm__form-card nsm__form-card--rule' },
1159
+ h('div', { className: 'nsm__modal-head' },
1160
+ h('h3', { id: 'nsm-rule-form-title' }, form?.id ? t('rule.form.editTitle') : t('rule.form.newTitle')),
1161
+ h('button', { type: 'button', className: 'nsm__modal-close', 'aria-label': t('rule.form.cancel'), onClick: onClose }, h(Glyph, { name: 'close', size: 14 })),
1162
+ ),
1163
+ h('form', { className: 'nsm__form', onSubmit: handleSubmit, onKeyDown: onKeydown },
1164
+ h('div', { className: 'nsm__form-field' },
1165
+ h('label', { className: 'nsm__form-label', htmlFor: 'nsm-rule-title' }, t('rule.form.titleLabel')),
1166
+ h('input', {
1167
+ id: 'nsm-rule-title', ref: titleRef,
1168
+ type: 'text',
1169
+ className: `nsm__form-input${titleErr ? ' is-error' : ''}`,
1170
+ value: form?.title || '',
1171
+ placeholder: t('rule.form.titlePlaceholder'),
1172
+ maxLength: 120,
1173
+ onChange: (e) => { setTitleErr(false); onChange?.({ title: e.target.value }); },
1174
+ }),
1175
+ ),
1176
+ h('div', { className: 'nsm__form-field' },
1177
+ h('div', { className: 'nsm__form-label-row' },
1178
+ h('label', { className: 'nsm__form-label', htmlFor: 'nsm-rule-content' }, t('rule.form.contentLabel')),
1179
+ h('button', {
1180
+ type: 'button', className: 'nsm__form-preview-btn',
1181
+ onClick: () => setPreview((v) => !v),
1182
+ }, preview ? t('rule.form.editMode') : t('rule.form.previewMode')),
1183
+ ),
1184
+ preview
1185
+ ? h('div', {
1186
+ className: 'nsm__markdown-preview',
1187
+ dangerouslySetInnerHTML: { __html: renderMarkdown(form?.content || '') },
1188
+ })
1189
+ : h('textarea', {
1190
+ id: 'nsm-rule-content',
1191
+ className: `nsm__form-textarea${contentErr ? ' is-error' : ''}`,
1192
+ value: form?.content || '',
1193
+ placeholder: t('rule.form.contentPlaceholder'),
1194
+ rows: 12,
1195
+ onChange: (e) => { setContentErr(false); onChange?.({ content: e.target.value }); },
1196
+ }),
1197
+ h('p', { className: 'nsm__form-hint' }, t('rule.form.markdownHint')),
1198
+ ),
1199
+ h('div', { className: 'nsm__modal-footer' },
1200
+ onDelete
1201
+ ? h('button', { type: 'button', className: 'nsm__button nsm__button--danger', onClick: onDelete }, t('rule.form.delete'))
1202
+ : null,
1203
+ h('button', { type: 'button', className: 'nsm__button', onClick: onClose }, t('rule.form.cancel')),
1204
+ h('button', { type: 'submit', className: 'nsm__button nsm__button--primary' }, h(Glyph, { name: 'save', size: 12 }), t('rule.form.save')),
1205
+ ),
1206
+ ),
1207
+ ));
1208
+ }
1209
+
663
1210
  return {
664
1211
  inject: ['slots'],
665
1212
  apply(ctx) {
@@ -896,6 +1443,15 @@ window.__ModuleLoader__.load({
896
1443
  const [importReport, setImportReport] = React.useState(null);
897
1444
  const [toast, setToast] = React.useState(null);
898
1445
  const [dragActive, setDragActive] = React.useState(false);
1446
+ const [activeModule, setActiveModule] = React.useState('session');
1447
+ const [rulesData, setRulesData] = React.useState({});
1448
+ const [rulesStatus, setRulesStatus] = React.useState('idle');
1449
+ const [ruleForm, setRuleForm] = React.useState(null);
1450
+ const [deleteRuleId, setDeleteRuleId] = React.useState(null);
1451
+ const [collapsedRules, setCollapsedRules] = React.useState({});
1452
+ const [picker, setPicker] = React.useState(null); // { ruleId, scope, targets, expanded, search }
1453
+ const [sessionsData, setSessionsData] = React.useState(null); // tree data for picker
1454
+ const rulesLoadedRef = React.useRef(false);
899
1455
  const dataRef = React.useRef(null);
900
1456
  const dragDepth = React.useRef(0);
901
1457
  const fileInputRef = React.useRef(null);
@@ -906,6 +1462,173 @@ window.__ModuleLoader__.load({
906
1462
  setToast({ kind, text, action, seq: toastSeq.current });
907
1463
  }, []);
908
1464
 
1465
+ // ── Rule module helpers ──
1466
+ const loadRules = React.useCallback(async () => {
1467
+ setRulesStatus('loading');
1468
+ try {
1469
+ const rules = await loadRulesApi();
1470
+ setRulesData(rules);
1471
+ rulesLoadedRef.current = true;
1472
+ setRulesStatus('ready');
1473
+ } catch (err) {
1474
+ setRulesStatus('error');
1475
+ showToast('error', t('rule.loadError'));
1476
+ }
1477
+ }, [showToast, t]);
1478
+
1479
+ // Auto-load rules when switching to rule module for the first time
1480
+ React.useEffect(() => {
1481
+ if (activeModule === 'rule' && !rulesLoadedRef.current) {
1482
+ loadRules();
1483
+ }
1484
+ }, [activeModule, loadRules]);
1485
+
1486
+ const handleToggleRule = React.useCallback(async (id, enabled) => {
1487
+ // Optimistic update
1488
+ setRulesData((prev) => {
1489
+ const next = { ...prev };
1490
+ if (next[id]) next[id] = { ...next[id], enabled, updatedAt: Date.now() };
1491
+ return next;
1492
+ });
1493
+ try {
1494
+ await toggleRuleApi(id, enabled);
1495
+ } catch {
1496
+ // Revert
1497
+ setRulesData((prev) => {
1498
+ const next = { ...prev };
1499
+ if (next[id]) next[id] = { ...next[id], enabled: !enabled };
1500
+ return next;
1501
+ });
1502
+ showToast('error', t('rule.saveError'));
1503
+ }
1504
+ }, [showToast, t]);
1505
+
1506
+ const handleScopeChange = React.useCallback(async (id, nextScope) => {
1507
+ const targets = nextScope === 'global' ? [] : (rulesData[id]?.targets || []);
1508
+ // Optimistic
1509
+ setRulesData((prev) => {
1510
+ const next = { ...prev };
1511
+ if (next[id]) next[id] = { ...next[id], scope: nextScope, targets, updatedAt: Date.now() };
1512
+ return next;
1513
+ });
1514
+ try {
1515
+ await updateRuleApi({ id, scope: nextScope, targets });
1516
+ } catch {
1517
+ setRulesData((prev) => ({ ...prev }));
1518
+ showToast('error', t('rule.saveError'));
1519
+ }
1520
+ }, [rulesData, showToast, t]);
1521
+
1522
+ // Lazy-load sessions tree data for picker
1523
+ const ensureSessionsData = React.useCallback(async () => {
1524
+ if (sessionsData && sessionsData.length) return sessionsData;
1525
+ try {
1526
+ const data = await apiFetch('');
1527
+ const sessions = Array.isArray(data?.sessions) ? data.sessions : [];
1528
+ setSessionsData(sessions);
1529
+ return sessions;
1530
+ } catch {
1531
+ return [];
1532
+ }
1533
+ }, [sessionsData]);
1534
+
1535
+ const openPicker = React.useCallback(async (ruleId, scope, existingTargets) => {
1536
+ await ensureSessionsData();
1537
+ setPicker({
1538
+ ruleId,
1539
+ scope,
1540
+ targets: Array.isArray(existingTargets) ? [...existingTargets] : [],
1541
+ expanded: {},
1542
+ search: '',
1543
+ });
1544
+ }, [ensureSessionsData]);
1545
+
1546
+ const closePicker = React.useCallback(() => setPicker(null), []);
1547
+
1548
+ const handlePickerConfirm = React.useCallback(async () => {
1549
+ if (!picker) return;
1550
+ try {
1551
+ await updateRuleApi({ id: picker.ruleId, scope: picker.scope, targets: picker.targets });
1552
+ setRulesData((prev) => {
1553
+ const next = { ...prev };
1554
+ if (next[picker.ruleId]) next[picker.ruleId] = { ...next[picker.ruleId], scope: picker.scope, targets: picker.targets, updatedAt: Date.now() };
1555
+ return next;
1556
+ });
1557
+ showToast('ok', t('rule.saved'));
1558
+ setPicker(null);
1559
+ } catch {
1560
+ showToast('error', t('rule.saveError'));
1561
+ }
1562
+ }, [picker, showToast, t]);
1563
+
1564
+ const togglePickerTarget = React.useCallback((targetId) => {
1565
+ setPicker((prev) => {
1566
+ if (!prev) return prev;
1567
+ const has = prev.targets.includes(targetId);
1568
+ return { ...prev, targets: has ? prev.targets.filter((t) => t !== targetId) : [...prev.targets, targetId] };
1569
+ });
1570
+ }, []);
1571
+
1572
+ const togglePickerGroup = React.useCallback((key) => {
1573
+ setPicker((prev) => prev ? { ...prev, expanded: { ...prev.expanded, [key]: !prev.expanded[key] } } : prev);
1574
+ }, []);
1575
+
1576
+ const toggleRuleCollapsed = React.useCallback((id) => {
1577
+ setCollapsedRules((prev) => ({ ...prev, [id]: !prev[id] }));
1578
+ }, []);
1579
+
1580
+ const handleDeleteRule = React.useCallback(async (id) => {
1581
+ try {
1582
+ await deleteRuleApi(id);
1583
+ setRulesData((prev) => {
1584
+ const next = { ...prev };
1585
+ delete next[id];
1586
+ return next;
1587
+ });
1588
+ setDeleteRuleId(null);
1589
+ showToast('ok', t('rule.deleted'));
1590
+ } catch {
1591
+ showToast('error', t('rule.saveError'));
1592
+ }
1593
+ }, [showToast, t]);
1594
+
1595
+ const handleSaveRule = React.useCallback(async (form) => {
1596
+ try {
1597
+ let saved;
1598
+ if (form.id) {
1599
+ // Update: only title + content (scope/enabled not exposed in UI)
1600
+ saved = await updateRuleApi({ id: form.id, title: form.title, content: form.content });
1601
+ showToast('ok', t('rule.saved'));
1602
+ } else {
1603
+ // Create: default scope=global, enabled=true
1604
+ saved = await createRuleApi({ title: form.title, content: form.content, scope: 'global', targets: [], enabled: false });
1605
+ showToast('ok', t('rule.created'));
1606
+ }
1607
+ setRulesData((prev) => ({ ...prev, [saved.id]: saved }));
1608
+ setRuleForm(null);
1609
+ } catch (err) {
1610
+ showToast('error', t('rule.saveError'));
1611
+ }
1612
+ }, [showToast, t]);
1613
+
1614
+ // Computed: filtered + sorted rules
1615
+ const computedRules = React.useMemo(() => {
1616
+ const all = Object.values(rulesData);
1617
+ all.sort((a, b) => b.updatedAt - a.updatedAt);
1618
+ return all;
1619
+ }, [rulesData]);
1620
+
1621
+ const ruleStats = React.useMemo(() => {
1622
+ const total = Object.keys(rulesData).length;
1623
+ let enabled = 0;
1624
+ const byScope = { global: 0, workspace: 0, session: 0 };
1625
+ for (const r of Object.values(rulesData)) {
1626
+ if (r.enabled) enabled++;
1627
+ byScope[r.scope] = (byScope[r.scope] || 0) + 1;
1628
+ }
1629
+ return { total, enabled, byScope };
1630
+ }, [rulesData]);
1631
+
909
1632
  const fetchList = React.useCallback(async (signal) => {
910
1633
  const response = await fetch(API, { method: 'GET', credentials: 'same-origin', headers: { accept: 'application/json' }, signal });
911
1634
  const payload = await response.json().catch(() => null);
@@ -1767,207 +2490,513 @@ window.__ModuleLoader__.load({
1767
2490
  ));
1768
2491
  }
1769
2492
 
1770
- if (data) {
1771
- content.push(h('section', { key: 'stats', className: 'nsm__stats' },
1772
- h('div', { className: 'nsm__stat' }, h('span', { className: 'nsm__stat-label' }, t('stats.total')), h('span', { className: 'nsm__stat-value' }, String(stats.total))),
1773
- h('div', { className: 'nsm__stat' }, h('span', { className: 'nsm__stat-label' }, t('stats.live')), h('span', { className: 'nsm__stat-value' }, String(stats.live))),
1774
- h('div', { className: 'nsm__stat' }, h('span', { className: 'nsm__stat-label' }, t('stats.groups')), h('span', { className: 'nsm__stat-value' }, String(stats.groups))),
1775
- h('div', { className: 'nsm__stat' }, h('span', { className: 'nsm__stat-label' }, t('stats.size')), h('span', { className: 'nsm__stat-value' }, formatBytes(stats.bytes))),
1776
- ));
1777
- }
2493
+ // ── Module workspace: sidebar (navigation) + main (content) ──
2494
+ const mainContent = [];
1778
2495
 
1779
- content.push(h('div', { key: 'toolbar', className: 'nsm__toolbar' },
1780
- h('div', { className: 'nsm__viewtabs', role: 'tablist' },
2496
+ if (activeModule === 'session') {
2497
+ const pane = [];
2498
+
2499
+ if (data) {
2500
+ pane.push(h('section', { key: 'stats', className: 'nsm__stats' },
2501
+ h('div', { className: 'nsm__stat' }, h('span', { className: 'nsm__stat-label' }, t('stats.total')), h('span', { className: 'nsm__stat-value' }, String(stats.total))),
2502
+ h('div', { className: 'nsm__stat' }, h('span', { className: 'nsm__stat-label' }, t('stats.live')), h('span', { className: 'nsm__stat-value' }, String(stats.live))),
2503
+ h('div', { className: 'nsm__stat' }, h('span', { className: 'nsm__stat-label' }, t('stats.groups')), h('span', { className: 'nsm__stat-value' }, String(stats.groups))),
2504
+ h('div', { className: 'nsm__stat' }, h('span', { className: 'nsm__stat-label' }, t('stats.size')), h('span', { className: 'nsm__stat-value' }, formatBytes(stats.bytes))),
2505
+ ));
2506
+ }
2507
+
2508
+ pane.push(h('div', { key: 'toolbar', className: 'nsm__toolbar' },
2509
+ h('div', { className: 'nsm__viewtabs', role: 'tablist' },
2510
+ h('button', {
2511
+ type: 'button',
2512
+ role: 'tab',
2513
+ 'aria-selected': view === 'sessions' ? 'true' : 'false',
2514
+ className: `nsm__viewtab${view === 'sessions' ? ' is-active' : ''}`,
2515
+ onClick: () => setView('sessions'),
2516
+ }, t('view.sessions')),
2517
+ h('button', {
2518
+ type: 'button',
2519
+ role: 'tab',
2520
+ 'aria-selected': view === 'trash' ? 'true' : 'false',
2521
+ className: `nsm__viewtab${view === 'trash' ? ' is-active' : ''}`,
2522
+ onClick: () => setView('trash'),
2523
+ }, t('view.trash'), h('span', { className: 'nsm__tab-count' }, String(trash.length))),
2524
+ ),
2525
+ h('div', { className: 'nsm__search' },
2526
+ h('span', { className: 'nsm__search-icon' }, h(Glyph, { name: 'search', size: 14 })),
2527
+ h('input', {
2528
+ type: 'search',
2529
+ value: query,
2530
+ placeholder: view === 'trash' ? t('search.trashPlaceholder') : t('search.placeholder'),
2531
+ 'aria-label': view === 'trash' ? t('search.trashPlaceholder') : t('search.placeholder'),
2532
+ onChange: (event) => setQuery(event.target.value),
2533
+ }),
2534
+ query !== '' ? h('button', {
2535
+ type: 'button',
2536
+ className: 'nsm__search-clear',
2537
+ title: t('search.clear'),
2538
+ 'aria-label': t('search.clear'),
2539
+ onClick: () => setQuery(''),
2540
+ }, h(Glyph, { name: 'close', size: 12 })) : null,
2541
+ ),
2542
+ h(Check, {
2543
+ checked: activeAllSelected,
2544
+ mixed: activeSomeSelected,
2545
+ label: t('action.selectAll'),
2546
+ onChange: (next) => view === 'trash' ? toggleTrashSelected(visibleTrashIds, next) : toggleSelected(visibleIds, next),
2547
+ }),
1781
2548
  h('button', {
1782
2549
  type: 'button',
1783
- role: 'tab',
1784
- 'aria-selected': view === 'sessions' ? 'true' : 'false',
1785
- className: `nsm__viewtab${view === 'sessions' ? ' is-active' : ''}`,
1786
- onClick: () => setView('sessions'),
1787
- }, t('view.sessions')),
2550
+ className: 'nsm__button nsm__button--small nsm__button--ghost',
2551
+ disabled: activeVisibleIds.length === 0 && activeSelectionCount === 0,
2552
+ onClick: activeSelectionCount > 0
2553
+ ? () => { if (view === 'trash') setSelectedTrashIds([]); else setSelectedIds([]); }
2554
+ : () => { if (view === 'trash') toggleTrashSelected(visibleTrashIds, true); else toggleSelected(visibleIds, true); },
2555
+ }, activeSelectionCount > 0 ? t('action.clearSelection') : t('action.selectAll')),
2556
+ h('span', { className: 'nsm__toolbar-spacer' }),
2557
+ h('button', { type: 'button', className: 'nsm__button nsm__button--small nsm__button--ghost', onClick: expandAll }, t('action.expandAll')),
2558
+ h('button', { type: 'button', className: 'nsm__button nsm__button--small nsm__button--ghost', onClick: collapseAll }, t('action.collapseAll')),
1788
2559
  h('button', {
1789
2560
  type: 'button',
1790
- role: 'tab',
1791
- 'aria-selected': view === 'trash' ? 'true' : 'false',
1792
- className: `nsm__viewtab${view === 'trash' ? ' is-active' : ''}`,
1793
- onClick: () => setView('trash'),
1794
- }, t('view.trash'), h('span', { className: 'nsm__tab-count' }, String(trash.length))),
1795
- ),
1796
- h('div', { className: 'nsm__search' },
1797
- h('span', { className: 'nsm__search-icon' }, h(Glyph, { name: 'search', size: 14 })),
1798
- h('input', {
1799
- type: 'search',
1800
- value: query,
1801
- placeholder: view === 'trash' ? t('search.trashPlaceholder') : t('search.placeholder'),
1802
- 'aria-label': view === 'trash' ? t('search.trashPlaceholder') : t('search.placeholder'),
1803
- onChange: (event) => setQuery(event.target.value),
1804
- }),
1805
- query !== '' ? h('button', {
1806
- type: 'button',
1807
- className: 'nsm__search-clear',
1808
- title: t('search.clear'),
1809
- 'aria-label': t('search.clear'),
1810
- onClick: () => setQuery(''),
1811
- }, h(Glyph, { name: 'close', size: 12 })) : null,
1812
- ),
1813
- h(Check, {
1814
- checked: activeAllSelected,
1815
- mixed: activeSomeSelected,
1816
- label: t('action.selectAll'),
1817
- onChange: (next) => view === 'trash' ? toggleTrashSelected(visibleTrashIds, next) : toggleSelected(visibleIds, next),
1818
- }),
1819
- h('button', {
1820
- type: 'button',
1821
- className: 'nsm__button nsm__button--small nsm__button--ghost',
1822
- disabled: activeVisibleIds.length === 0 && activeSelectionCount === 0,
1823
- onClick: activeSelectionCount > 0
1824
- ? () => { if (view === 'trash') setSelectedTrashIds([]); else setSelectedIds([]); }
1825
- : () => { if (view === 'trash') toggleTrashSelected(visibleTrashIds, true); else toggleSelected(visibleIds, true); },
1826
- }, activeSelectionCount > 0 ? t('action.clearSelection') : t('action.selectAll')),
1827
- h('span', { className: 'nsm__toolbar-spacer' }),
1828
- h('button', { type: 'button', className: 'nsm__button nsm__button--small nsm__button--ghost', onClick: expandAll }, t('action.expandAll')),
1829
- h('button', { type: 'button', className: 'nsm__button nsm__button--small nsm__button--ghost', onClick: collapseAll }, t('action.collapseAll')),
1830
- h('button', {
1831
- type: 'button',
1832
- className: 'nsm__button nsm__button--small',
1833
- disabled: status === 'refreshing' || status === 'loading',
1834
- onClick: async () => {
1835
- await load({ silent: true });
1836
- await refreshNative();
1837
- showToast('ok', t('toast.refreshed'));
1838
- },
1839
- }, h(Glyph, { name: 'refresh', size: 12 }), t('action.refresh')),
1840
- ));
1841
-
1842
- if (data && view === 'sessions') {
1843
- content.push(h('div', { key: 'filters', className: 'nsm__filters', role: 'group', 'aria-label': t('filter.label') },
1844
- FILTERS.map((id) => h('button', {
1845
- key: id,
1846
- type: 'button',
1847
- className: `nsm__filter${stateFilter === id ? ' is-active' : ''}`,
1848
- 'aria-pressed': stateFilter === id ? 'true' : 'false',
1849
- onClick: () => setStateFilter(id),
1850
- }, t(`filter.${id}`), h('span', { className: 'nsm__filter-count' }, String(filterCounts[id] || 0)))),
2561
+ className: 'nsm__button nsm__button--small',
2562
+ disabled: status === 'refreshing' || status === 'loading',
2563
+ onClick: async () => {
2564
+ await load({ silent: true });
2565
+ await refreshNative();
2566
+ showToast('ok', t('toast.refreshed'));
2567
+ },
2568
+ }, h(Glyph, { name: 'refresh', size: 12 }), t('action.refresh')),
1851
2569
  ));
1852
- }
1853
2570
 
1854
- if (status === 'loading' && !data) {
1855
- content.push(h('div', { key: 'loading', className: 'nsm__loading' }, h('span', { className: 'nsm__spinner' }), h('span', null, t('loading'))));
1856
- } else if (status === 'error' && !data) {
1857
- content.push(h('div', { key: 'error', className: 'nsm__error' },
1858
- h('p', null, error || t('error.load')),
1859
- h('button', { type: 'button', className: 'nsm__button', onClick: () => load({}) }, t('action.retry')),
1860
- ));
1861
- } else if (data) {
1862
- content.push(h('div', { key: 'layout', className: 'nsm__layout' },
1863
- h('section', { key: 'tree', className: 'nsm__tree-card' },
1864
- h('div', { className: 'nsm__tree-head' },
1865
- h('h2', null, view === 'trash' ? t('trash.title') : t('tree.title')),
1866
- h('span', { className: 'nsm__tree-head-meta' }, view === 'trash'
1867
- ? trashCount(visibleTrash.length)
1868
- : sessionCount(visibleSessions.length)),
1869
- ),
1870
- h('div', { className: 'nsm__tree-body', role: 'tree', 'aria-label': view === 'trash' ? t('trash.title') : t('page.title') },
1871
- view === 'trash'
1872
- ? (visibleTrash.length === 0
1873
- ? h('div', { className: 'nsm__empty' },
1874
- h('span', { className: 'nsm__empty-mark nsm__empty-mark--trash' }, h(Glyph, { name: 'trash', size: 52 })),
1875
- h('h2', null, normalizedQuery === '' ? t('trash.empty') : t('tree.emptyFiltered')),
1876
- h('p', null, normalizedQuery === '' ? t('trash.emptyBody') : t('tree.emptyFilteredBody')),
1877
- normalizedQuery === ''
1878
- ? h('button', { type: 'button', className: 'nsm__button', onClick: () => setView('sessions') }, t('view.sessions'))
1879
- : h('button', { type: 'button', className: 'nsm__button', onClick: () => setQuery('') }, t('search.clear')),
1880
- )
1881
- : trashGroups.map(renderTrashGroup))
1882
- : (visibleSessions.length === 0
1883
- ? h('div', { className: 'nsm__empty' },
1884
- h('span', { className: 'nsm__empty-mark' }, h(PageMark, { size: 64 })),
1885
- h('h2', null, normalizedQuery === '' && stateFilter === 'all' ? t('empty.title') : t('tree.emptyFiltered')),
1886
- h('p', null, normalizedQuery === '' && stateFilter === 'all' ? t('empty.body') : t('tree.emptyFilteredBody')),
1887
- normalizedQuery === '' && stateFilter === 'all'
1888
- ? h('button', { type: 'button', className: 'nsm__button nsm__button--primary', onClick: () => fileInputRef.current && fileInputRef.current.click() }, t('empty.cta'))
1889
- : h('button', { type: 'button', className: 'nsm__button', onClick: () => { setQuery(''); setStateFilter('all'); } }, t('search.clear')),
1890
- )
1891
- : groups.map(renderGroup)),
1892
- ),
1893
- ),
1894
- h('aside', { key: 'aside', className: 'nsm__aside' },
1895
- h('section', { className: 'nsm__card' },
1896
- h('div', { className: 'nsm__card-head' }, h('h2', null, view === 'trash'
1897
- ? (selectedTrashEntries.length > 0 ? tr('selection.count', { n: selectedTrashEntries.length }) : t('selection.none'))
1898
- : (selectedSessions.length > 0 ? tr('selection.count', { n: selectedSessions.length }) : t('selection.none')))),
1899
- (view === 'trash' ? selectedTrashEntries.length > 0 : selectedSessions.length > 0)
1900
- ? h('p', { className: 'nsm__selection-size' }, tr('selection.size', { size: formatBytes(view === 'trash' ? selectedTrashBytes : selectedBytes) }))
1901
- : null,
1902
- h('div', { className: 'nsm__selection-actions' },
1903
- view === 'trash' ? [
1904
- h('button', {
1905
- key: 'restore',
1906
- type: 'button',
1907
- className: 'nsm__button nsm__button--primary',
1908
- disabled: selectedTrashEntries.length === 0 || busy,
1909
- onClick: () => restoreEntries(selectedTrashEntries.map((entry) => entry.trashId)),
1910
- }, h(Glyph, { name: 'restore', size: 13 }), t('trash.restoreSelected')),
1911
- h('button', {
1912
- key: 'purge',
1913
- type: 'button',
1914
- className: 'nsm__button nsm__button--danger',
1915
- disabled: selectedTrashEntries.length === 0 || busy,
1916
- onClick: () => requestPurge(selectedTrashEntries.map((entry) => entry.trashId)),
1917
- }, h(Glyph, { name: 'trash', size: 13 }), t('trash.purgeSelected')),
1918
- ] : [
1919
- h('button', {
1920
- key: 'export',
1921
- type: 'button',
1922
- className: 'nsm__button',
1923
- disabled: selectedSessions.length === 0,
1924
- onClick: () => exportSessions(selectedSessions.map((session) => session.id)),
1925
- }, h(Glyph, { name: 'export', size: 13 }), t('action.exportSelected')),
1926
- h('button', {
1927
- key: 'delete',
1928
- type: 'button',
1929
- className: 'nsm__button nsm__button--danger',
1930
- disabled: !canDeleteSelected || busy,
1931
- onClick: () => requestDelete(selectedSessions.map((session) => session.id)),
1932
- }, h(Glyph, { name: 'trash', size: 13 }), t('action.deleteSelected')),
1933
- ],
2571
+ if (data && view === 'sessions') {
2572
+ pane.push(h('div', { key: 'filters', className: 'nsm__filters', role: 'group', 'aria-label': t('filter.label') },
2573
+ FILTERS.map((id) => h('button', {
2574
+ key: id,
2575
+ type: 'button',
2576
+ className: `nsm__filter${stateFilter === id ? ' is-active' : ''}`,
2577
+ 'aria-pressed': stateFilter === id ? 'true' : 'false',
2578
+ onClick: () => setStateFilter(id),
2579
+ }, t(`filter.${id}`), h('span', { className: 'nsm__filter-count' }, String(filterCounts[id] || 0)))),
2580
+ ));
2581
+ }
2582
+
2583
+ if (status === 'loading' && !data) {
2584
+ pane.push(h('div', { key: 'loading', className: 'nsm__loading' }, h('span', { className: 'nsm__spinner' }), h('span', null, t('loading'))));
2585
+ } else if (status === 'error' && !data) {
2586
+ pane.push(h('div', { key: 'error', className: 'nsm__error' },
2587
+ h('p', null, error || t('error.load')),
2588
+ h('button', { type: 'button', className: 'nsm__button', onClick: () => load({}) }, t('action.retry')),
2589
+ ));
2590
+ } else if (data) {
2591
+ pane.push(h('div', { key: 'layout', className: 'nsm__layout' },
2592
+ h('section', { key: 'tree', className: 'nsm__tree-card' },
2593
+ h('div', { className: 'nsm__tree-head' },
2594
+ h('h2', null, view === 'trash' ? t('trash.title') : t('tree.title')),
2595
+ h('span', { className: 'nsm__tree-head-meta' }, view === 'trash'
2596
+ ? trashCount(visibleTrash.length)
2597
+ : sessionCount(visibleSessions.length)),
2598
+ ),
2599
+ h('div', { className: 'nsm__tree-body', role: 'tree', 'aria-label': view === 'trash' ? t('trash.title') : t('page.title') },
2600
+ view === 'trash'
2601
+ ? (visibleTrash.length === 0
2602
+ ? h('div', { className: 'nsm__empty' },
2603
+ h('span', { className: 'nsm__empty-mark nsm__empty-mark--trash' }, h(Glyph, { name: 'trash', size: 52 })),
2604
+ h('h2', null, normalizedQuery === '' ? t('trash.empty') : t('tree.emptyFiltered')),
2605
+ h('p', null, normalizedQuery === '' ? t('trash.emptyBody') : t('tree.emptyFilteredBody')),
2606
+ normalizedQuery === ''
2607
+ ? h('button', { type: 'button', className: 'nsm__button', onClick: () => setView('sessions') }, t('view.sessions'))
2608
+ : h('button', { type: 'button', className: 'nsm__button', onClick: () => setQuery('') }, t('search.clear')),
2609
+ )
2610
+ : trashGroups.map(renderTrashGroup))
2611
+ : (visibleSessions.length === 0
2612
+ ? h('div', { className: 'nsm__empty' },
2613
+ h('span', { className: 'nsm__empty-mark' }, h(PageMark, { size: 64 })),
2614
+ h('h2', null, normalizedQuery === '' && stateFilter === 'all' ? t('empty.title') : t('tree.emptyFiltered')),
2615
+ h('p', null, normalizedQuery === '' && stateFilter === 'all' ? t('empty.body') : t('tree.emptyFilteredBody')),
2616
+ normalizedQuery === '' && stateFilter === 'all'
2617
+ ? h('button', { type: 'button', className: 'nsm__button nsm__button--primary', onClick: () => fileInputRef.current && fileInputRef.current.click() }, t('empty.cta'))
2618
+ : h('button', { type: 'button', className: 'nsm__button', onClick: () => { setQuery(''); setStateFilter('all'); } }, t('search.clear')),
2619
+ )
2620
+ : groups.map(renderGroup)),
1934
2621
  ),
1935
- h('p', { className: 'nsm__hint' }, view === 'trash' ? t('selection.trashHint') : t('selection.hint')),
1936
2622
  ),
1937
- renderDetail(),
1938
- h('section', { className: 'nsm__card nsm__import-card' },
1939
- h('div', { className: 'nsm__card-head' }, h('h2', null, t('import.title'))),
1940
- h('p', { className: 'nsm__hint', style: { marginTop: 0 } }, t('import.hint')),
1941
- h('button', {
1942
- type: 'button',
1943
- className: 'nsm__button',
1944
- disabled: importing,
1945
- onClick: () => fileInputRef.current && fileInputRef.current.click(),
1946
- }, h(Glyph, { name: 'import', size: 13 }), importing ? t('action.importing') : t('action.import')),
2623
+ h('aside', { key: 'aside', className: 'nsm__aside' },
2624
+ h('section', { className: 'nsm__card' },
2625
+ h('div', { className: 'nsm__card-head' }, h('h2', null, view === 'trash'
2626
+ ? (selectedTrashEntries.length > 0 ? tr('selection.count', { n: selectedTrashEntries.length }) : t('selection.none'))
2627
+ : (selectedSessions.length > 0 ? tr('selection.count', { n: selectedSessions.length }) : t('selection.none')))),
2628
+ (view === 'trash' ? selectedTrashEntries.length > 0 : selectedSessions.length > 0)
2629
+ ? h('p', { className: 'nsm__selection-size' }, tr('selection.size', { size: formatBytes(view === 'trash' ? selectedTrashBytes : selectedBytes) }))
2630
+ : null,
2631
+ h('div', { className: 'nsm__selection-actions' },
2632
+ view === 'trash' ? [
2633
+ h('button', {
2634
+ key: 'restore',
2635
+ type: 'button',
2636
+ className: 'nsm__button nsm__button--primary',
2637
+ disabled: selectedTrashEntries.length === 0 || busy,
2638
+ onClick: () => restoreEntries(selectedTrashEntries.map((entry) => entry.trashId)),
2639
+ }, h(Glyph, { name: 'restore', size: 13 }), t('trash.restoreSelected')),
2640
+ h('button', {
2641
+ key: 'purge',
2642
+ type: 'button',
2643
+ className: 'nsm__button nsm__button--danger',
2644
+ disabled: selectedTrashEntries.length === 0 || busy,
2645
+ onClick: () => requestPurge(selectedTrashEntries.map((entry) => entry.trashId)),
2646
+ }, h(Glyph, { name: 'trash', size: 13 }), t('trash.purgeSelected')),
2647
+ ] : [
2648
+ h('button', {
2649
+ key: 'export',
2650
+ type: 'button',
2651
+ className: 'nsm__button',
2652
+ disabled: selectedSessions.length === 0,
2653
+ onClick: () => exportSessions(selectedSessions.map((session) => session.id)),
2654
+ }, h(Glyph, { name: 'export', size: 13 }), t('action.exportSelected')),
2655
+ h('button', {
2656
+ key: 'delete',
2657
+ type: 'button',
2658
+ className: 'nsm__button nsm__button--danger',
2659
+ disabled: !canDeleteSelected || busy,
2660
+ onClick: () => requestDelete(selectedSessions.map((session) => session.id)),
2661
+ }, h(Glyph, { name: 'trash', size: 13 }), t('action.deleteSelected')),
2662
+ ],
2663
+ ),
2664
+ h('p', { className: 'nsm__hint' }, view === 'trash' ? t('selection.trashHint') : t('selection.hint')),
2665
+ ),
2666
+ renderDetail(),
2667
+ h('section', { className: 'nsm__card nsm__import-card' },
2668
+ h('div', { className: 'nsm__card-head' }, h('h2', null, t('import.title'))),
2669
+ h('p', { className: 'nsm__hint', style: { marginTop: 0 } }, t('import.hint')),
2670
+ h('button', {
2671
+ type: 'button',
2672
+ className: 'nsm__button',
2673
+ disabled: importing,
2674
+ onClick: () => fileInputRef.current && fileInputRef.current.click(),
2675
+ }, h(Glyph, { name: 'import', size: 13 }), importing ? t('action.importing') : t('action.import')),
2676
+ ),
1947
2677
  ),
2678
+ ));
2679
+
2680
+ if (data.sessionRoot) {
2681
+ pane.push(h('footer', { key: 'footer', className: 'nsm__footer' },
2682
+ h('div', { className: 'nsm__footer-line' },
2683
+ h('span', null, `${t('footer.storage')} `, h('code', null, data.sessionRoot)),
2684
+ ),
2685
+ h('div', { className: 'nsm__footer-line' },
2686
+ h('span', null, t('footer.package'), h('code', null, PACKAGE_NAME)),
2687
+ h('button', {
2688
+ type: 'button',
2689
+ className: 'nsm__footer-copy',
2690
+ title: t('action.copyPackage'),
2691
+ 'aria-label': t('action.copyPackage'),
2692
+ onClick: () => copyId(PACKAGE_NAME),
2693
+ }, h(Glyph, { name: 'copy', size: 11 })),
2694
+ ),
2695
+ h('div', { className: 'nsm__footer-line' }, h('span', null, t('footer.note'))),
2696
+ ));
2697
+ }
2698
+ }
2699
+
2700
+ mainContent.push(h('div', { key: 'pane-session', className: 'nsm__pane nsm__pane--session' }, ...pane));
2701
+ } else {
2702
+ const pane = [];
2703
+
2704
+ // ── Toolbar ──
2705
+ pane.push(h('div', { key: 'rule-toolbar', className: 'nsm__rules-toolbar' },
2706
+ h('div', { className: 'nsm__rules-toolbar-head' },
2707
+ h('span', { className: 'nsm__rules-title' }, t('rule.title')),
2708
+ h('span', { className: 'nsm__rules-meta' }, tr('rule.titleMeta', { total: ruleStats.total, enabled: ruleStats.enabled })),
1948
2709
  ),
2710
+ h('button', {
2711
+ type: 'button', className: 'nsm__button',
2712
+ disabled: rulesStatus === 'loading',
2713
+ onClick: () => setRuleForm({ id: null, title: '', content: '' }),
2714
+ }, h(Glyph, { name: 'plus', size: 12 }), t('rule.new')),
1949
2715
  ));
1950
2716
 
1951
- if (data.sessionRoot) {
1952
- content.push(h('footer', { key: 'footer', className: 'nsm__footer' },
1953
- h('div', { className: 'nsm__footer-line' },
1954
- h('span', null, `${t('footer.storage')} `, h('code', null, data.sessionRoot)),
1955
- ),
1956
- h('div', { className: 'nsm__footer-line' },
1957
- h('span', null, t('footer.package'), h('code', null, PACKAGE_NAME)),
1958
- h('button', {
1959
- type: 'button',
1960
- className: 'nsm__footer-copy',
1961
- title: t('action.copyPackage'),
1962
- 'aria-label': t('action.copyPackage'),
1963
- onClick: () => copyId(PACKAGE_NAME),
1964
- }, h(Glyph, { name: 'copy', size: 11 })),
2717
+ // ── Rules list ──
2718
+ if (rulesStatus === 'loading') {
2719
+ pane.push(h('div', { key: 'rule-loading', className: 'nsm__loading' },
2720
+ h('span', { className: 'nsm__spinner' }), h('span', null, t('loading'))));
2721
+ } else if (rulesStatus === 'error') {
2722
+ pane.push(h('div', { key: 'rule-error', className: 'nsm__error' },
2723
+ h('p', null, t('rule.loadError')),
2724
+ h('button', { type: 'button', className: 'nsm__button', onClick: loadRules }, t('action.retry'))));
2725
+ } else if (computedRules.length === 0) {
2726
+ pane.push(h('div', { key: 'rule-empty', className: 'nsm__empty' },
2727
+ h('span', { className: 'nsm__empty-mark' }, h(Glyph, { name: 'branch', size: 52 })),
2728
+ h('h2', null, t('rule.empty')),
2729
+ h('p', null, t('rule.emptyBody')),
2730
+ h('button', { type: 'button', className: 'nsm__button nsm__button--primary', onClick: () => setRuleForm({ id: null, title: '', content: '' }) }, t('rule.emptyCta'))));
2731
+ } else {
2732
+ pane.push(h('div', { key: 'rule-list', className: 'nsm__rules-list' },
2733
+ computedRules.map((rule) => {
2734
+ const isCollapsed = collapsedRules[rule.id] !== false; // default collapsed
2735
+ return h('div', {
2736
+ key: rule.id,
2737
+ className: `nsm__rule-card${rule.enabled ? '' : ' is-disabled'}`,
2738
+ },
2739
+ // ── Head: title + updatedAt ──
2740
+ h('div', { className: 'nsm__rule-card-head' },
2741
+ h('div', {
2742
+ className: `nsm__rule-card-title${rule.enabled ? '' : ' is-disabled'}`,
2743
+ title: rule.title || '(untitled)',
2744
+ }, rule.title || '(untitled)'),
2745
+ h('span', { className: 'nsm__rule-card-meta' },
2746
+ relativeTime(rule.updatedAt),
2747
+ ),
2748
+ ),
2749
+ // ── Body: content (collapsible) ──
2750
+ h('div', { className: 'nsm__rule-card-body' },
2751
+ h('div', {
2752
+ className: `nsm__rule-card-content${isCollapsed ? ' is-collapsed' : ''}`,
2753
+ }, rule.content),
2754
+ rule.content && rule.content.length > 40
2755
+ ? h('button', {
2756
+ type: 'button',
2757
+ className: 'nsm__rule-card-toggle',
2758
+ onClick: () => toggleRuleCollapsed(rule.id),
2759
+ }, isCollapsed ? t('rule.showMore') : t('rule.showLess'))
2760
+ : null,
2761
+ ),
2762
+ // ── Foot: scope segmented tabs + scope indicator + toggle + edit + delete ──
2763
+ h('div', { className: 'nsm__rule-card-foot' },
2764
+ // Scope segmented tabs
2765
+ h('div', { className: 'nsm__scope-tabs', role: 'tablist' },
2766
+ ['global', 'workspace', 'session'].map((scope) =>
2767
+ h('button', {
2768
+ key: scope,
2769
+ type: 'button',
2770
+ role: 'tab',
2771
+ className: `nsm__scope-tab${rule.scope === scope ? ' is-active' : ''}`,
2772
+ title: t(`rule.scope.${scope}Hint`),
2773
+ onClick: () => handleScopeChange(rule.id, scope),
2774
+ }, t(`rule.scope.${scope}`)),
2775
+ ),
2776
+ ),
2777
+ // Scope-specific indicator
2778
+ rule.scope === 'global'
2779
+ ? h('span', { className: 'nsm__scope-global-hint' }, t('rule.scope.globalHint'))
2780
+ : h('button', {
2781
+ type: 'button',
2782
+ className: 'nsm__scope-picker-btn',
2783
+ 'data-scope': rule.scope,
2784
+ onClick: () => openPicker(rule.id, rule.scope, rule.targets || []),
2785
+ },
2786
+ t(`rule.scope.${rule.scope}Pick`),
2787
+ h('span', { className: 'nsm__scope-count' }, (rule.targets || []).length || '0'),
2788
+ ),
2789
+ h('div', { className: 'nsm__rule-card-foot-spacer' }),
2790
+ h('label', { className: 'nsm__toggle', title: rule.enabled ? t('rule.toggleOff') : t('rule.toggleOn') },
2791
+ h('input', { type: 'checkbox', checked: rule.enabled, onChange: (e) => handleToggleRule(rule.id, e.target.checked) }),
2792
+ h('span', { className: 'nsm__toggle-track' }),
2793
+ ),
2794
+ h('button', {
2795
+ type: 'button', className: 'nsm__icon-btn',
2796
+ title: t('rule.edit'), 'aria-label': t('rule.edit'),
2797
+ onClick: () => setRuleForm({ id: rule.id, title: rule.title, content: rule.content }),
2798
+ }, h(Glyph, { name: 'edit', size: 13 })),
2799
+ h('button', {
2800
+ type: 'button', className: 'nsm__icon-btn is-danger',
2801
+ title: t('rule.delete'), 'aria-label': t('rule.delete'),
2802
+ onClick: () => setDeleteRuleId(rule.id),
2803
+ }, h(Glyph, { name: 'trash', size: 13 })),
2804
+ ),
2805
+ );
2806
+ }),
2807
+ ));
2808
+ }
2809
+
2810
+ // ── Rule form modal ──
2811
+ if (ruleForm) {
2812
+ pane.push(h(RuleFormModal, {
2813
+ key: 'rule-form-modal',
2814
+ form: ruleForm,
2815
+ onClose: () => setRuleForm(null),
2816
+ onChange: (patch) => setRuleForm((prev) => ({ ...prev, ...patch })),
2817
+ onSave: (form) => handleSaveRule(form),
2818
+ onDelete: ruleForm.id ? () => { setDeleteRuleId(ruleForm.id); setRuleForm(null); } : null,
2819
+ t,
2820
+ }));
2821
+ }
2822
+
2823
+ // ── Delete confirm modal ──
2824
+ if (deleteRuleId) {
2825
+ const target = rulesData[deleteRuleId];
2826
+ pane.push(h(ConfirmModal, {
2827
+ key: 'rule-delete-confirm',
2828
+ title: t('rule.deleteConfirmTitle'),
2829
+ body: tr('rule.deleteConfirmBody', { title: target?.title || deleteRuleId }),
2830
+ danger: true,
2831
+ confirmLabel: t('rule.delete'),
2832
+ onConfirm: () => handleDeleteRule(deleteRuleId),
2833
+ onCancel: () => setDeleteRuleId(null),
2834
+ t,
2835
+ }));
2836
+ }
2837
+
2838
+ // ── Scope picker modal (tree selection — unified) ──
2839
+ if (picker) {
2840
+ const sessions = Array.isArray(sessionsData) ? sessionsData : [];
2841
+ const isSessionPicker = picker.scope === 'session';
2842
+
2843
+ // Build workspace → [sessions] groups (workspace is an object: {id,title,path})
2844
+ const byWs = {};
2845
+ sessions.forEach((s) => {
2846
+ const raw = s?.workspace;
2847
+ const wsId = (raw && typeof raw === 'object' ? raw.id : raw) || '(unassigned)';
2848
+ const wsTitle = (raw && typeof raw === 'object' ? (raw.title || raw.path) : raw) || '(unassigned)';
2849
+ const wsPath = (raw && typeof raw === 'object' ? raw.path : '') || '';
2850
+ if (!byWs[wsId]) byWs[wsId] = { id: wsId, title: wsTitle, path: wsPath, sessions: [] };
2851
+ byWs[wsId].sessions.push(s);
2852
+ });
2853
+ const groups = Object.values(byWs).sort((a, b) => a.title.localeCompare(b.title));
2854
+
2855
+ const q = (picker.search || '').toLowerCase().trim();
2856
+ const filterMatch = (str) => !q || String(str).toLowerCase().includes(q);
2857
+
2858
+ const renderCheckbox = (checked) => h('input', {
2859
+ type: 'checkbox',
2860
+ checked: !!checked,
2861
+ onChange: () => {},
2862
+ readOnly: true,
2863
+ style: { flexShrink: 0, margin: 0 },
2864
+ });
2865
+
2866
+ const tree = groups.map((ws) => {
2867
+ const wsName = ws.title;
2868
+ const wsKey = `ws:${ws.id}`;
2869
+ const isOpen = picker.expanded[wsKey] !== false;
2870
+ const anySessionMatch = ws.sessions.some((s) => filterMatch(s.title || s.id));
2871
+
2872
+ // Determine target value based on scope (workspace scope targets workspace id)
2873
+ const wsTarget = ws.id;
2874
+ const wsChecked = isSessionPicker
2875
+ ? ws.sessions.every((s) => picker.targets.includes(s.id))
2876
+ : picker.targets.includes(wsTarget);
2877
+
2878
+ // Group sessions by month
2879
+ const byMonth = {};
2880
+ ws.sessions.forEach((s) => {
2881
+ const m = new Date(s?.updatedAt || s?.createdAt || Date.now()).toISOString().slice(0, 7);
2882
+ if (!byMonth[m]) byMonth[m] = [];
2883
+ byMonth[m].push(s);
2884
+ });
2885
+ const months = Object.keys(byMonth).sort((a, b) => b.localeCompare(a));
2886
+
2887
+ // Filter-out workspace if no match
2888
+ const wsMatch = isSessionPicker
2889
+ ? !q || anySessionMatch || filterMatch(wsName)
2890
+ : !q || filterMatch(wsName);
2891
+
2892
+ if (!wsMatch) return null;
2893
+
2894
+ // Click handler for ws group head
2895
+ const onWsToggle = () => {
2896
+ if (isSessionPicker) {
2897
+ // Session picker → toggle all session ids under this ws
2898
+ const allIds = ws.sessions.map((s) => s.id);
2899
+ const allIn = allIds.every((id) => picker.targets.includes(id));
2900
+ setPicker((prev) => {
2901
+ if (!prev) return prev;
2902
+ const rest = prev.targets.filter((t) => !allIds.includes(t));
2903
+ return { ...prev, targets: allIn ? rest : [...rest, ...allIds] };
2904
+ });
2905
+ } else {
2906
+ // Workspace picker → toggle workspace id
2907
+ togglePickerTarget(wsTarget);
2908
+ }
2909
+ };
2910
+
2911
+ return h('div', { key: wsKey, className: 'nsm__picker-group' },
2912
+ h('div', { className: 'nsm__picker-group-head', onClick: onWsToggle, style: { cursor: 'pointer' } },
2913
+ h('span', {
2914
+ className: `nsm__picker-group-arrow${isOpen ? ' is-open' : ''}`,
2915
+ onClick: (e) => { e.stopPropagation(); togglePickerGroup(wsKey); },
2916
+ style: { cursor: 'pointer' },
2917
+ }, '▶'),
2918
+ renderCheckbox(wsChecked),
2919
+ h('span', { className: 'nsm__picker-group-label', title: ws.path || wsName }, wsName),
2920
+ h('span', { className: 'nsm__picker-group-count' }, `${ws.sessions.length} 会话`),
2921
+ ),
2922
+ isOpen && isSessionPicker ? months.map((m) => {
2923
+ const monthSessions = byMonth[m];
2924
+ return h('div', { key: m },
2925
+ h('div', { className: 'nsm__picker-month' }, m),
2926
+ monthSessions.map((s) => {
2927
+ if (!filterMatch(s.title || s.id)) return null;
2928
+ const checked = picker.targets.includes(s.id);
2929
+ return h('div', {
2930
+ key: s.id, className: 'nsm__picker-item',
2931
+ onClick: () => togglePickerTarget(s.id),
2932
+ },
2933
+ renderCheckbox(checked),
2934
+ h('span', { className: 'nsm__picker-item-label', title: s.title || s.id }, s.title || s.id),
2935
+ h('span', { className: 'nsm__picker-item-meta' }, relativeTime(s.updatedAt || s.createdAt)),
2936
+ );
2937
+ }).filter(Boolean),
2938
+ );
2939
+ }) : null,
2940
+ );
2941
+ }).filter(Boolean);
2942
+
2943
+ pane.push(h('div', {
2944
+ key: 'rule-scope-picker',
2945
+ className: 'nsm__modal',
2946
+ onClick: closePicker,
2947
+ },
2948
+ h('div', { className: 'nsm__modal-card', onClick: (e) => e.stopPropagation(), style: { width: 'min(640px, 90vw)', maxHeight: 'min(72vh, 600px)' } },
2949
+ h('div', { className: 'nsm__modal-head' },
2950
+ h('h3', null, isSessionPicker ? t('rule.picker.sessionTitle') : t('rule.picker.workspaceTitle')),
2951
+ h('button', { className: 'nsm__modal-close', onClick: closePicker }, '✕'),
2952
+ ),
2953
+ h('div', { className: 'nsm__picker' },
2954
+ h('input', {
2955
+ className: 'nsm__picker-search',
2956
+ type: 'text',
2957
+ placeholder: t('rule.picker.search'),
2958
+ value: picker.search,
2959
+ onChange: (e) => setPicker((p) => p ? { ...p, search: e.target.value } : p),
2960
+ autoFocus: true,
2961
+ }),
2962
+ h('div', { className: 'nsm__picker-tree' },
2963
+ tree.length
2964
+ ? tree
2965
+ : h('div', { style: { padding: '24px', textAlign: 'center', color: 'var(--nsm-tertiary)', fontSize: '11.5px' } }, t('rule.picker.empty')),
2966
+ ),
2967
+ ),
2968
+ h('div', { className: 'nsm__picker-actions' },
2969
+ h('span', { className: 'nsm__picker-selected-info' }, tr('rule.picker.selected', { n: picker.targets.length })),
2970
+ h('div', { className: 'nsm__modal-footer' },
2971
+ h('button', { type: 'button', className: 'nsm__button', onClick: closePicker }, t('action.cancel')),
2972
+ h('button', { type: 'button', className: 'nsm__button nsm__button--primary', onClick: handlePickerConfirm }, t('action.save')),
2973
+ ),
2974
+ ),
1965
2975
  ),
1966
- h('div', { className: 'nsm__footer-line' }, h('span', null, t('footer.note'))),
1967
2976
  ));
1968
2977
  }
2978
+
2979
+ mainContent.push(h('div', { key: 'pane-rule', className: 'nsm__pane nsm__pane--rule' }, ...pane));
1969
2980
  }
1970
2981
 
2982
+ // ── Assemble workspace: sidebar + main ──
2983
+ content.push(h('div', { key: 'workspace', className: 'nsm__workspace' },
2984
+ h('nav', { key: 'sidebar', className: 'nsm__sidebar', role: 'navigation' },
2985
+ MODULES.map((mod) => h('button', {
2986
+ key: mod.id,
2987
+ type: 'button',
2988
+ role: 'tab',
2989
+ 'aria-selected': activeModule === mod.id ? 'true' : 'false',
2990
+ className: `nsm__module${activeModule === mod.id ? ' is-active' : ''}`,
2991
+ onClick: () => setActiveModule(mod.id),
2992
+ },
2993
+ h('span', { className: 'nsm__module-icon' }, h(Glyph, { name: mod.icon, size: 14 })),
2994
+ h('span', { className: 'nsm__module-label' }, t(mod.key)),
2995
+ )),
2996
+ ),
2997
+ h('div', { key: 'main', className: 'nsm__main' }, mainContent),
2998
+ ));
2999
+
1971
3000
  if (dragActive) {
1972
3001
  content.push(h('div', { key: 'drop', className: 'nsm__drop' },
1973
3002
  h('div', { className: 'nsm__drop-card' },