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

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