dsh-capability-switch 0.0.0-stage → 1.4.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.js ADDED
@@ -0,0 +1,808 @@
1
+ window.__ModuleLoader__.load({
2
+ id: 'dsh-capability-switch',
3
+ factory(require) {
4
+ const React = require('react')
5
+ const h = React.createElement
6
+ const { useCallback, useEffect, useMemo, useState } = React
7
+ const BASE = '/__dsh-capability-switch'
8
+ const PANEL = 'capability-switch'
9
+ const NS = 'capabilitySwitch'
10
+ const MCP_NAME = /^[A-Za-z0-9_-]{1,32}$/
11
+ let activeSessionId = null
12
+ let translate = null
13
+
14
+ const MESSAGES = {
15
+ zh: {
16
+ nav: '能力管理', title: 'Skills 与 MCP', subtitle: '集中管理本机技能与当前 DSH 配置中的 MCP 服务。',
17
+ skills: 'Skills', mcp: 'MCP', search: '搜索名称、描述、命令或路径', refresh: '刷新', addSkill: '新建技能', addMcp: '添加 MCP', syncSkills: '从 Agent 目录同步', importMcp: '从应用导入',
18
+ display: '显示设置', enabled: '已启用', disabled: '已停用', edit: '编辑', remove: '删除', test: '测试连接', restart: '重新连接',
19
+ user: '用户级', projectWritable: '项目', projectReadonly: '项目只读', directory: '目录技能', file: '单文件技能', noItems: '没有匹配条目', noSkills: '尚未安装用户级技能', noMcp: '尚未配置 MCP 服务',
20
+ agentSource: 'Agent 目录', dshSource: 'DSH 目录', standalone: '独立实例', registered: '插件注册', runtimeUnmanaged: '由独立插件实例管理', readonly: '只读',
21
+ loading: '正在读取本机配置…', creating: '正在创建…', discardChanges: '有未保存的修改,确定关闭吗?', loadFailed: '读取配置失败', retry: '重试', save: '保存', cancel: '取消', close: '关闭', create: '创建',
22
+ formMode: '表单', jsonMode: 'JSON', jsonHelp: '支持 mcpServers 包装对象或单个服务器配置;新建时可一次保存多个服务器。', jsonOneServer: '编辑时 JSON 只能包含一个 MCP 服务器', jsonNameFixed: '编辑时不能修改 MCP 名称,当前名称为',
23
+ mode: '编辑方式', standaloneEditHint: '独立实例可直接编辑连接参数;启停仍使用开关。', transportHttp: 'SSE / Streamable HTTP', transportHttpHelp: 'DSH 通过 Streamable HTTP 承载 SSE 流。',
24
+ workspaceImpactTitle: '修改影响范围', workspaceImpactHint: '将直接修改 {workspace} 工作区的 .agents/skills 项目技能。该工作区后续会话会读取新内容,正在运行的会话可能需要重新加载。',
25
+ workspaceReadonlyTitle: '只读技能', workspaceReadonlyHint: '{workspace} 的 .dsh/skills 由 DSH 管理,只能查看。',
26
+ workspaceEditImpact: '正在修改 {workspace} 工作区的项目技能;保存后该工作区后续会话会读取新内容。',
27
+ workspaceDeleteImpact: '删除会影响 {workspace} 工作区中后续使用该技能的会话。',
28
+ workspaceScanWarnings: '部分工作区技能读取失败,其他工作区仍可正常使用。',
29
+ name: '名称', description: '描述', body: '正文', content: 'SKILL.md 内容', path: '路径', transport: '连接类型', command: '启动命令',
30
+ args: '参数(每行一个)', cwd: '工作目录(可选)', env: '环境变量(JSON 对象)', url: '服务 URL', headers: '请求头(JSON 对象)',
31
+ enableNow: '保存后立即启用', createSkillTitle: '新建技能', editSkillTitle: '编辑技能', editMcpTitle: '编辑 MCP', addMcpTitle: '添加 MCP',
32
+ scope: '技能范围', userScope: '用户级', projectScope: '项目级', projectScopeHelp: '项目级技能写入所选工作区的 .agents/skills。',
33
+ workspace: '工作区', workspaceHelp: '项目级技能会写入所选工作区的 .agents/skills。',
34
+ existingWorkspace: '已有工作区', newWorkspace: '新建工作区', selectWorkspace: '选择工作区',
35
+ workspaceName: '工作区名称', workspaceParent: '父目录', workspaceParentHelp: '留空时使用 ~/Documents。支持 ~ 路径。',
36
+ newWorkspaceHint: '会创建目录并注册为 DSH 工作区。', workspaceRequired: '请选择或新建一个工作区。', currentWorkspace: '当前会话工作区',
37
+ skillNameHelp: '小写字母、数字、连字符或下划线;创建后作为目录名。', mcpNameHelp: '1–32 位字母、数字、连字符或下划线;编辑时不可改名。',
38
+ deleteSkillTitle: '删除技能', deleteMcpTitle: '删除 MCP', deleteSkillText: '同步技能为软链接时只移除 DSH 链接,Agent 源文件保持不变;本地新建或真实目录会移入 DSH 回收目录。',
39
+ deleteMcpText: '将从当前 DSH profile 的配置中移除此 MCP,运行中的连接也会关闭。', confirmDelete: '确认删除',
40
+ saved: '已保存', created: '已创建', deleted: '已删除并移入回收目录', unlinked: '已移除 DSH 软链接,Agent 源文件未删除', mcpDeleted: '已从当前配置删除', mcpRemovedStandalone: '已删除独立 MCP,插件配置变更已保存', mcpRemovedRestart: '已删除独立 MCP,重启 DSH 后完成卸载', mcpRestartRequired: '已保存,重启 DSH 后生效', updated: '配置已更新',
41
+ testOk: '连接成功,发现 {count} 个工具', testFailed: '连接测试失败:{message}', restarted: '已重新发起连接',
42
+ syncDone: 'Skills 同步完成:新增 {added},更新 {updated},跳过 {skipped},失败 {failed}', syncStateError: ';同步状态保存失败:', importDone: 'MCP 导入完成:新增 {added},跳过 {skipped}', sourceErrors: ';{count} 个来源读取失败',
43
+ prefsTitle: '自定义显示', sidebarVisible: '在左侧边栏显示入口', sidebarLabel: '入口名称', defaultTab: '默认打开',
44
+ showDescriptions: '显示描述与配置摘要', compactRows: '使用紧凑行距', prefsSaved: '显示偏好已保存到 DSH 配置',
45
+ preferencesHint: '这些偏好保存在当前 DSH profile 中,重启后仍会保留。设置页始终保留,便于恢复侧边栏入口。',
46
+ userSkillsDir: '用户级技能目录', readonlyHint: '用户级和所有已注册工作区的 .agents 项目技能支持编辑、启停和删除;跨工作区修改会提示影响范围。',
47
+ connected: '已连接', connecting: '连接中', reconnecting: '等待重连', failed: '连接失败', waiting: '等待凭据', closed: '已关闭',
48
+ unknownStatus: '未知状态', toolCount: '{count} 个工具', invalidJson: 'JSON 格式不正确', empty: '暂无描述',
49
+ importTitle: '从应用导入 MCP', importHelp: '只读扫描其他应用的用户级配置。请手动选择条目;默认导入为停用,不修改来源文件。预览后配置变化会拒绝导入。',
50
+ noImports: '没有发现可导入的 MCP', existing: '已存在', importAction: '导入选中项', scanFailed: '扫描失败', conflict: '配置冲突',
51
+ enableImports: '导入后立即启用', importEnableHint: '启用 stdio MCP 会启动对应的本机命令,请确认来源和命令可信。',
52
+ syncTitle: '从 Agent 目录同步 Skills', syncHelp: '选择同步方式后,从 Agent 目录同步到 DSH。已有目标会先备份,再替换;Agent 来源目录保持不变。',
53
+ syncMode: '同步方式', symlinkMode: '只用软链接', symlinkHelp: 'Windows 需要开启开发者模式',
54
+ copyMode: '只用复制', copyHelp: '占用更多空间,更新后会重新复制',
55
+ copyImpact: '复制模式下编辑或删除只影响 DSH 副本,不会修改 Agent 源文件。',
56
+ syncAction: '确认同步', newItem: '建立链接', updateItem: '更新链接', newCopy: '复制', updateCopy: '更新副本', localEditItem: '本地已修改', conflictItem: '来源与副本均已变化', errorItem: '读取失败', localEditHint: 'DSH 副本在上次同步后被修改;同步会先备份再覆盖。', conflictHint: '来源和 DSH 副本都变化了;请确认是否覆盖本地副本。', unchangedItem: '链接正常', noChanges: '没有需要同步的变更', backupLocation: '备份目录', partialFailure: '部分条目失败',
57
+ selectAll: '全选', clearAll: '全不选', selectedCount: '已选 {count} 项', takeoverHint: '技能接管已启用(所有模式):仅隐藏全局 Agent 目录;DSH 用户技能和项目级技能仍会扫描加载。全局 Agent 目录仅用于同步。',
58
+ standaloneHint: '独立 MCP 可在本插件中编辑连接参数、启停或删除。', registeredHint: '由其他 DSH 插件动态注册。',
59
+ },
60
+ en: {
61
+ nav: 'Capabilities', title: 'Skills & MCP', subtitle: 'Manage local skills and MCP servers in the active DSH profile.',
62
+ skills: 'Skills', mcp: 'MCP', search: 'Search names, descriptions, commands, or paths', refresh: 'Refresh', addSkill: 'New skill', addMcp: 'Add MCP', syncSkills: 'Sync from Agent directory', importMcp: 'Import from apps',
63
+ display: 'Display settings', enabled: 'Enabled', disabled: 'Disabled', edit: 'Edit', remove: 'Delete', test: 'Test connection', restart: 'Reconnect',
64
+ user: 'User', projectWritable: 'Project', projectReadonly: 'Project read-only', directory: 'Directory', file: 'Single file', noItems: 'No matching entries', noSkills: 'No user skills installed', noMcp: 'No MCP servers configured',
65
+ agentSource: 'Agent directory', dshSource: 'DSH directory', standalone: 'Standalone', registered: 'Plugin registered', runtimeUnmanaged: 'Managed by a standalone plugin instance', readonly: 'Read-only',
66
+ loading: 'Reading local configuration…', creating: 'Creating…', discardChanges: 'Discard unsaved changes and close?', loadFailed: 'Could not read configuration', retry: 'Retry', save: 'Save', cancel: 'Cancel', close: 'Close', create: 'Create',
67
+ formMode: 'Form', jsonMode: 'JSON', jsonHelp: 'Accepts an mcpServers wrapper or a single server object; new JSON can create multiple servers at once.', jsonOneServer: 'Editing accepts exactly one MCP server in JSON', jsonNameFixed: 'The MCP name cannot change while editing; current name:',
68
+ mode: 'Editor', standaloneEditHint: 'Standalone connection settings are editable here; use the toggle for enablement.', transportHttp: 'SSE / Streamable HTTP', transportHttpHelp: 'DSH carries SSE streams over Streamable HTTP.',
69
+ workspaceImpactTitle: 'Impact of this change', workspaceImpactHint: 'This directly changes project skills in {workspace}/.agents/skills. Later sessions in that workspace will read the new content; running sessions may need to reload.',
70
+ workspaceReadonlyTitle: 'Read-only skill', workspaceReadonlyHint: '{workspace}/.dsh/skills is managed by DSH and is view-only.',
71
+ workspaceEditImpact: 'You are editing a project skill in {workspace}; later sessions in that workspace will read the new content.',
72
+ workspaceDeleteImpact: 'Deleting this affects later sessions in {workspace} that use the skill.',
73
+ workspaceScanWarnings: 'Some workspace skill directories could not be read; other workspaces remain available.',
74
+ name: 'Name', description: 'Description', body: 'Body', content: 'SKILL.md content', path: 'Path', transport: 'Transport', command: 'Command',
75
+ args: 'Arguments (one per line)', cwd: 'Working directory (optional)', env: 'Environment (JSON object)', url: 'Server URL', headers: 'Headers (JSON object)',
76
+ enableNow: 'Enable after saving', createSkillTitle: 'New skill', editSkillTitle: 'Edit skill', editMcpTitle: 'Edit MCP', addMcpTitle: 'Add MCP',
77
+ scope: 'Skill scope', userScope: 'User', projectScope: 'Project', projectScopeHelp: 'Project skills are written to .agents/skills in the selected workspace.',
78
+ workspace: 'Workspace', workspaceHelp: 'Project skills are written to .agents/skills in the selected workspace.',
79
+ existingWorkspace: 'Existing workspace', newWorkspace: 'New workspace', selectWorkspace: 'Select workspace',
80
+ workspaceName: 'Workspace name', workspaceParent: 'Parent directory', workspaceParentHelp: 'Defaults to ~/Documents. ~ paths are supported.',
81
+ newWorkspaceHint: 'The directory is created and registered as a DSH workspace.', workspaceRequired: 'Select or create a workspace.', currentWorkspace: 'Current session workspace',
82
+ skillNameHelp: 'Lowercase letters, numbers, hyphens, or underscores; used as the directory name.', mcpNameHelp: '1–32 letters, numbers, hyphens, or underscores; immutable while editing.',
83
+ deleteSkillTitle: 'Delete skill', deleteMcpTitle: 'Delete MCP', deleteSkillText: 'Deleting a synced skill removes only the DSH symlink and keeps the Agent source. Locally created skills or real directories move to the DSH trash directory.',
84
+ deleteMcpText: 'This removes the MCP from the active DSH profile and closes its running connection.', confirmDelete: 'Delete',
85
+ saved: 'Saved', created: 'Created', deleted: 'Moved to the trash directory', unlinked: 'Removed the DSH symlink; the Agent source was not deleted', mcpDeleted: 'Removed from the active configuration', mcpRemovedStandalone: 'Standalone MCP deleted; the plugin configuration change was saved', mcpRemovedRestart: 'Standalone MCP deleted; restart DSH to finish unloading it', mcpRestartRequired: 'Saved; restart DSH to apply', updated: 'Configuration updated',
86
+ testOk: 'Connected; found {count} tools', testFailed: 'Connection test failed: {message}', restarted: 'Reconnection started',
87
+ syncDone: 'Skills synchronized: {added} added, {updated} updated, {skipped} unchanged, {failed} failed', syncStateError: '; sync state could not be saved: ', importDone: 'MCP import complete: {added} added, {skipped} skipped', sourceErrors: '; {count} sources could not be read',
88
+ prefsTitle: 'Customize display', sidebarVisible: 'Show an entry in the left sidebar', sidebarLabel: 'Entry label', defaultTab: 'Open by default',
89
+ showDescriptions: 'Show descriptions and configuration summaries', compactRows: 'Use compact rows', prefsSaved: 'Display preferences saved to the DSH configuration',
90
+ preferencesHint: 'Preferences persist in the active DSH profile. The Settings page always remains available so you can restore the sidebar entry.',
91
+ userSkillsDir: 'User skill directory', readonlyHint: 'User and .agents project skills in every registered workspace support editing, toggling, and deletion; cross-workspace edits show their impact.',
92
+ connected: 'Connected', connecting: 'Connecting', reconnecting: 'Reconnecting', failed: 'Failed', waiting: 'Waiting for credentials', closed: 'Closed',
93
+ unknownStatus: 'Unknown status', toolCount: '{count} tools', invalidJson: 'Invalid JSON', empty: 'No description',
94
+ importTitle: 'Import MCP from apps', importHelp: 'Reads user-level configs without changing them. Select entries manually; imports are disabled by default. A changed source invalidates the preview.',
95
+ noImports: 'No importable MCP servers found', existing: 'Already exists', importAction: 'Import selected', scanFailed: 'Scan failed', conflict: 'Conflicting configs',
96
+ enableImports: 'Enable immediately after import', importEnableHint: 'Enabling a stdio MCP starts its local command. Only enable sources and commands you trust.',
97
+ syncTitle: 'Sync Skills from Agent directory', syncHelp: 'Choose a sync mode to copy skills from the Agent directory into DSH. Existing targets are backed up before replacement; Agent sources are unchanged.',
98
+ syncMode: 'Sync mode', symlinkMode: 'Symlink only', symlinkHelp: 'Windows requires Developer Mode',
99
+ copyMode: 'Copy only', copyHelp: 'Uses more space; copies are recreated on updates',
100
+ copyImpact: 'Copy mode edits and deletes only the DSH copy; Agent source files stay unchanged.',
101
+ syncAction: 'Confirm sync', newItem: 'Create link', updateItem: 'Update link', newCopy: 'Copy', updateCopy: 'Update copy', localEditItem: 'Locally modified', conflictItem: 'Both changed', errorItem: 'Read failed', localEditHint: 'The DSH copy changed since the last sync; syncing backs it up before replacing it.', conflictHint: 'The source and DSH copy both changed; confirm before overwriting the local copy.', unchangedItem: 'Linked', noChanges: 'No changes to synchronize', backupLocation: 'Backup directory', partialFailure: 'Some items failed',
102
+ selectAll: 'Select all', clearAll: 'Clear all', selectedCount: '{count} selected', takeoverHint: 'Skill takeover is active in every mode: only the global Agent directory is hidden; DSH user and project skills still load. The global Agent directory is used only for sync.',
103
+ standaloneHint: 'Standalone MCP connection settings can be edited, enabled, disabled, or deleted here.', registeredHint: 'Dynamically registered by another DSH plugin.',
104
+ },
105
+ }
106
+
107
+ function createPreferenceStore(initial) {
108
+ let current = initial
109
+ const listeners = new Set()
110
+ return {
111
+ getSnapshot: () => current,
112
+ subscribe: listener => { listeners.add(listener); return () => listeners.delete(listener) },
113
+ set: next => { current = next; for (const listener of listeners) listener() },
114
+ }
115
+ }
116
+
117
+ function t(key, vars) {
118
+ let value = translate ? translate(key, vars) : (MESSAGES.zh[key] || key)
119
+ if (!translate && vars) for (const name of Object.keys(vars)) value = value.replaceAll('{' + name + '}', String(vars[name]))
120
+ return value
121
+ }
122
+
123
+ const CSS = [
124
+ '.dsh-caps{--caps-pad:24px;color:var(--dsw-alias-label-primary);font-size:13px;line-height:1.5;height:100%;overflow-y:auto;overscroll-behavior:contain;box-sizing:border-box;background:var(--dsw-alias-bg-base);}',
125
+ '.dsh-caps *{box-sizing:border-box}.dsh-caps button,.dsh-caps input,.dsh-caps textarea,.dsh-caps select{font:inherit}',
126
+ '.dsh-caps-shell{max-width:1080px;margin:0 auto;padding:28px var(--caps-pad) 48px;}',
127
+ '.dsh-caps-header{display:flex;align-items:flex-start;justify-content:space-between;gap:20px;margin-bottom:24px;}',
128
+ '.dsh-caps-title{font-size:24px;line-height:1.25;font-weight:650;letter-spacing:-.02em;margin:0 0 7px;}',
129
+ '.dsh-caps-subtitle{color:var(--dsw-alias-label-secondary);margin:0;max-width:620px;}',
130
+ '.dsh-caps-actions{display:flex;align-items:center;gap:8px;flex-wrap:wrap;}',
131
+ '.dsh-caps-btn{border:.5px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-secondary);border-radius:7px;min-height:32px;padding:5px 11px;cursor:pointer;display:inline-flex;align-items:center;justify-content:center;gap:6px;white-space:nowrap;}',
132
+ '.dsh-caps-btn:hover:not(:disabled){background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-primary);}',
133
+ '.dsh-caps-btn:focus-visible,.dsh-caps-tab:focus-visible,.dsh-caps-switch:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:2px;}',
134
+ '.dsh-caps-btn:disabled,.dsh-caps-switch:disabled{opacity:.48;cursor:not-allowed;}',
135
+ '.dsh-caps-primary{background:var(--dsw-alias-brand-primary);color:var(--dsw-alias-label-on-color);border-color:transparent;}',
136
+ '.dsh-caps-primary:hover:not(:disabled){background:var(--dsw-alias-brand-primary);color:var(--dsw-alias-label-on-color);opacity:.9;}',
137
+ '.dsh-caps-danger{color:var(--dsw-alias-state-error-primary);}',
138
+ '.dsh-caps-tabs{display:flex;gap:4px;border-bottom:.5px solid var(--dsw-alias-border-l1);margin-bottom:16px;}',
139
+ '.dsh-caps-tab{border:0;border-bottom:2px solid transparent;background:transparent;color:var(--dsw-alias-label-secondary);padding:9px 14px;margin-bottom:-.5px;cursor:pointer;display:flex;gap:8px;align-items:center;}',
140
+ '.dsh-caps-tab[aria-pressed=true]{color:var(--dsw-alias-label-primary);border-bottom-color:var(--dsw-alias-brand-primary);font-weight:600;}',
141
+ '.dsh-caps-count{font-size:11px;min-width:20px;padding:0 5px;border-radius:10px;background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-secondary);}',
142
+ '.dsh-caps-toolbar{display:flex;gap:10px;margin-bottom:16px;}.dsh-caps-search{position:relative;flex:1;}',
143
+ '.dsh-caps-input,.dsh-caps-select,.dsh-caps-textarea{width:100%;border:.5px solid var(--dsw-alias-border-l1);border-radius:7px;background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);padding:8px 10px;outline:none;}',
144
+ '.dsh-caps-input:focus,.dsh-caps-select:focus,.dsh-caps-textarea:focus{border-color:var(--dsw-alias-brand-primary);box-shadow:0 0 0 2px color-mix(in srgb,var(--dsw-alias-brand-primary) 20%,transparent);}',
145
+ '.dsh-caps-search .dsh-caps-input{padding-left:32px;}.dsh-caps-search-icon{position:absolute;left:10px;top:9px;color:var(--dsw-alias-label-secondary);pointer-events:none;}',
146
+ '.dsh-caps-list{display:flex;flex-direction:column;gap:10px;}',
147
+ '.dsh-caps-row{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:16px;align-items:center;border:.5px solid var(--dsw-alias-border-l2);border-radius:10px;background:var(--dsw-alias-bg-layer-1);padding:15px 16px;}',
148
+ '.dsh-caps-compact .dsh-caps-row{padding:9px 12px;gap:10px;}.dsh-caps-main{min-width:0;}',
149
+ '.dsh-caps-name-row{display:flex;align-items:center;gap:8px;min-width:0;flex-wrap:wrap;}.dsh-caps-name{font-weight:600;font-size:14px;overflow-wrap:anywhere;}',
150
+ '.dsh-caps-badge{display:inline-flex;align-items:center;border-radius:4px;padding:1px 6px;font-size:11px;line-height:18px;background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-secondary);}',
151
+ '.dsh-caps-description{color:var(--dsw-alias-label-secondary);margin-top:5px;overflow-wrap:anywhere;}.dsh-caps-path{color:var(--dsw-alias-label-secondary);font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:11px;margin-top:6px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}',
152
+ '.dsh-caps-row-actions{display:flex;align-items:center;justify-content:flex-end;gap:6px;flex-wrap:wrap;}',
153
+ '.dsh-caps-row-readonly .dsh-caps-row-actions{opacity:.82;}',
154
+ '.dsh-caps-info-wrap{position:relative;display:inline-flex;align-items:center;}.dsh-caps-info{display:inline-grid;place-items:center;width:20px;height:20px;padding:0;border:0;border-radius:50%;background:transparent;color:var(--dsw-alias-label-secondary);cursor:help;}.dsh-caps-info:hover,.dsh-caps-info[aria-expanded="true"]{background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-primary);}',
155
+ '.dsh-caps-info:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-focus-ring-color,var(--dsw-alias-brand-primary));outline-offset:1px;}',
156
+ '.dsh-caps-tip{position:absolute;top:calc(100% + 7px);left:0;z-index:12;display:flex;flex-direction:column;gap:4px;width:min(300px,72vw);padding:10px 12px;border:.5px solid var(--dsw-alias-border-l1);border-radius:10px;background:var(--dsw-alias-bg-overlay);box-shadow:0 10px 30px color-mix(in srgb,var(--dsw-alias-label-primary) 16%,transparent);color:var(--dsw-alias-label-secondary);font-size:12px;font-weight:400;line-height:1.45;white-space:normal;text-align:left;}',
157
+ '.dsh-caps-tip strong{color:var(--dsw-alias-label-primary);font-weight:600;}',
158
+ '.dsh-caps-switch{position:relative;width:34px;height:20px;border:0;border-radius:10px;background:var(--dsw-alias-state-idle-primary);box-shadow:inset 0 0 0 1px var(--dsw-alias-border-l2);cursor:pointer;padding:0;flex:none;}',
159
+ '.dsh-caps-switch:after{content:"";position:absolute;left:3px;top:3px;width:14px;height:14px;border-radius:50%;background:var(--dsw-alias-switch-thumb);transition:transform .16s ease;box-shadow:0 0 0 .5px var(--dsw-alias-border-l1);}',
160
+ '.dsh-caps-switch[aria-checked=true]{background:var(--dsw-alias-state-success-primary);}.dsh-caps-switch[aria-checked=true]:after{transform:translateX(14px);}',
161
+ '.dsh-caps-status{display:inline-flex;align-items:center;gap:5px;color:var(--dsw-alias-label-secondary);font-size:12px;}.dsh-caps-dot{width:6px;height:6px;border-radius:50%;background:var(--dsw-alias-label-secondary);}',
162
+ '.dsh-caps-status[data-state=connected]{color:var(--dsw-alias-state-success-primary);}.dsh-caps-status[data-state=connected] .dsh-caps-dot{background:var(--dsw-alias-state-success-primary);}',
163
+ '.dsh-caps-status[data-state=failed]{color:var(--dsw-alias-state-error-primary);}.dsh-caps-status[data-state=failed] .dsh-caps-dot{background:var(--dsw-alias-state-error-primary);}',
164
+ '.dsh-caps-empty{padding:48px 20px;text-align:center;color:var(--dsw-alias-label-secondary);border:.5px dashed var(--dsw-alias-border-l1);border-radius:10px;}',
165
+ '.dsh-caps-import-list{display:flex;flex-direction:column;gap:8px;max-height:420px;overflow:auto;}.dsh-caps-import-row{display:flex;align-items:flex-start;gap:10px;padding:11px 12px;border:.5px solid var(--dsw-alias-border-l1);border-radius:8px;background:var(--dsw-alias-bg-layer-1);cursor:pointer;}.dsh-caps-import-row:has(input:disabled){cursor:default;opacity:.65;}.dsh-caps-import-row input{margin-top:4px;accent-color:var(--dsw-alias-brand-primary);}.dsh-caps-import-meta{min-width:0;flex:1;}.dsh-caps-import-source{font-size:11px;color:var(--dsw-alias-label-secondary);margin-top:3px;overflow-wrap:anywhere;}',
166
+ '.dsh-caps-notice{padding:10px 12px;border-radius:7px;margin-bottom:14px;background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-secondary);overflow-wrap:anywhere;}',
167
+ '.dsh-caps-error{color:var(--dsw-alias-state-error-primary);background:color-mix(in srgb,var(--dsw-alias-state-error-primary) 7%,transparent);}',
168
+ '.dsh-caps-foot{display:flex;gap:18px;flex-wrap:wrap;color:var(--dsw-alias-label-secondary);font-size:11px;margin-top:22px;overflow-wrap:anywhere;}',
169
+ '.dsh-caps-overlay{position:fixed;inset:0;z-index:1000;background:color-mix(in srgb,var(--dsw-alias-label-primary) 24%,transparent);display:flex;align-items:center;justify-content:center;padding:20px;}',
170
+ '.dsh-caps-modal{width:min(620px,100%);max-height:min(760px,calc(100vh - 40px));overflow:auto;background:var(--dsw-alias-bg-layer-1);border:.5px solid var(--dsw-alias-border-l1);border-radius:12px;box-shadow:0 18px 60px color-mix(in srgb,var(--dsw-alias-label-primary) 22%,transparent);padding:22px;}',
171
+ '.dsh-caps-modal-head{display:flex;align-items:center;justify-content:space-between;gap:16px;margin-bottom:20px;}.dsh-caps-modal-title{font-size:17px;font-weight:650;margin:0;}',
172
+ '.dsh-caps-form{display:flex;flex-direction:column;gap:14px;}.dsh-caps-field{display:flex;flex-direction:column;gap:6px;}.dsh-caps-label{font-weight:550;color:var(--dsw-alias-label-secondary);}',
173
+ '.dsh-caps-help{font-size:11px;color:var(--dsw-alias-label-secondary);}.dsh-caps-textarea{min-height:100px;resize:vertical;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px;}.dsh-caps-content{min-height:300px;}',
174
+ '.dsh-caps-check{display:flex;align-items:flex-start;gap:9px;color:var(--dsw-alias-label-secondary);cursor:pointer;}.dsh-caps-check input{margin-top:3px;accent-color:var(--dsw-alias-brand-primary);}',
175
+ '.dsh-caps-segment{display:flex;gap:2px;padding:2px;border-radius:8px;background:var(--dsw-alias-bg-layer-2);border:.5px solid var(--dsw-alias-border-l1);}',
176
+ '.dsh-caps-segment button{flex:1;min-height:28px;border:0;border-radius:6px;background:transparent;color:var(--dsw-alias-label-secondary);font:inherit;font-size:12px;cursor:pointer;padding:4px 10px;}',
177
+ '.dsh-caps-segment button[aria-pressed="true"]{background:var(--dsw-alias-bg-base);color:var(--dsw-alias-label-primary);font-weight:600;box-shadow:0 0 0 .5px var(--dsw-alias-border-l2);}',
178
+ '.dsh-caps-segment button:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-focus-ring-color,var(--dsw-alias-brand-primary));outline-offset:1px;}',
179
+ '.dsh-caps-workspace{display:flex;flex-direction:column;gap:11px;padding:12px;border:.5px solid var(--dsw-alias-border-l1);border-radius:9px;background:var(--dsw-alias-bg-layer-2);}',
180
+ '.dsh-caps-workspace-head{display:flex;align-items:flex-start;gap:9px;}.dsh-caps-workspace-icon{width:28px;height:28px;flex:0 0 28px;display:grid;place-items:center;border:.5px solid var(--dsw-alias-border-l1);border-radius:7px;background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-secondary);}',
181
+ '.dsh-caps-workspace-copy{display:flex;flex-direction:column;gap:2px;min-width:0;}.dsh-caps-workspace-fields{display:grid;grid-template-columns:1fr 1fr;gap:10px;}',
182
+ '.dsh-caps-json{min-height:240px;}',
183
+ '.dsh-caps-mcp-grid{display:grid;grid-template-columns:1fr 1fr;gap:10px;align-items:start;}.dsh-caps-mcp-small{min-height:72px;}',
184
+ '.dsh-caps-sync-mode-list{display:grid;grid-template-columns:1fr 1fr;gap:8px;}.dsh-caps-sync-mode{display:flex;align-items:flex-start;gap:9px;padding:10px 12px;border:.5px solid var(--dsw-alias-border-l1);border-radius:9px;background:var(--dsw-alias-bg-layer-1);cursor:pointer;}',
185
+ '.dsh-caps-sync-mode.is-selected{border-color:var(--dsw-alias-brand-primary);background:var(--dsw-alias-bg-layer-2);}',
186
+ '.dsh-caps-sync-mode input{margin:3px 0 0;accent-color:var(--dsw-alias-brand-primary);}',
187
+ '.dsh-caps-sync-mode-icon{display:grid;place-items:center;color:var(--dsw-alias-label-secondary);padding-top:1px;}.dsh-caps-sync-mode.is-selected .dsh-caps-sync-mode-icon{color:var(--dsw-alias-brand-primary);}',
188
+ '.dsh-caps-sync-mode-copy{display:flex;flex-direction:column;gap:2px;color:var(--dsw-alias-label-secondary);font-size:12px;line-height:1.4;}.dsh-caps-sync-mode-copy strong{color:var(--dsw-alias-label-primary);font-weight:600;}',
189
+ '.dsh-caps-modal-actions{display:flex;justify-content:flex-end;gap:8px;margin-top:22px;}.dsh-caps-spinner{color:var(--dsw-alias-label-secondary);padding:30px 0;text-align:center;}',
190
+ '@media(max-width:700px){.dsh-caps{--caps-pad:16px}.dsh-caps-shell{padding-top:20px}.dsh-caps-header{flex-direction:column}.dsh-caps-row{grid-template-columns:1fr}.dsh-caps-row-actions{justify-content:flex-start}.dsh-caps-toolbar{flex-wrap:wrap}.dsh-caps-search{flex-basis:100%}.dsh-caps-modal{padding:18px}.dsh-caps-workspace-fields,.dsh-caps-mcp-grid,.dsh-caps-sync-mode-list{grid-template-columns:1fr}}',
191
+ ].join('\n')
192
+
193
+ function Icon({ name, size = 16 }) {
194
+ const paths = {
195
+ search: h('path', { d: 'M8 3a5 5 0 1 0 0 10 5 5 0 0 0 0-10Zm4.2 9.2 3 3' }),
196
+ refresh: h('path', { d: 'M13.5 5.5A6 6 0 1 0 14 10m0-7v4h-4' }),
197
+ plus: h('path', { d: 'M8 3v10M3 8h10' }),
198
+ sync: h('path', { d: 'M13 8a5 5 0 1 1-2.2-4.1M13.2 2.2v3.2H10' }),
199
+ import: h('path', { d: 'M8 2v8m-3-3 3 3 3-3M3 11v3h10v-3' }),
200
+ settings: h('path', { d: 'M8 5.5A2.5 2.5 0 1 0 8 10a2.5 2.5 0 0 0 0-4.5ZM3 6.5l1 .5m8 2 1 .5M5.5 3l.5 1m4 8 .5 1M3 10l1-.5m8-3 1-.5M5.5 13l.5-1m4-8 .5-1' }),
201
+ workspace: h('path', { d: 'M2.5 5.5h4l1.1 1.5h5.9v6.5h-11zM2.5 5.5v8h11' }),
202
+ help: h('path', { d: 'M8 2.5a5.5 5.5 0 1 0 0 11 5.5 5.5 0 0 0 0-11ZM6.4 6.2a1.8 1.8 0 0 1 3.5.6c0 1.1-1.1 1.4-1.8 1.9M8 11.3v.2' }),
203
+ link: h('path', { d: 'M6.2 9.8 4.8 11.2a2.3 2.3 0 0 1-3.3-3.3l2.2-2.2a2.3 2.3 0 0 1 3.3 0M9.8 6.2l1.4-1.4a2.3 2.3 0 0 1 3.3 3.3l-2.2 2.2a2.3 2.3 0 0 1-3.3 0M5.5 10.5l5-5' }),
204
+ copy: h('path', { d: 'M5.5 2.5h6a2 2 0 0 1 2 2v6M3 5.5h7.5v8H3z' }),
205
+ close: h('path', { d: 'm4 4 8 8m0-8-8 8' }),
206
+ }
207
+ return h('svg', { width: size, height: size, viewBox: '0 0 16 16', fill: 'none', stroke: 'currentColor', strokeWidth: 1.4, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true }, paths[name] || paths.settings)
208
+ }
209
+
210
+ function BrandIcon({ size = 20 }) {
211
+ return h('svg', { width: size, height: size, viewBox: '0 0 24 24', fill: 'none', 'aria-hidden': true, style: { color: 'currentColor' } },
212
+ h('rect', { x: 3, y: 3, width: 7, height: 7, rx: 2, stroke: 'currentColor', strokeWidth: 1.6 }),
213
+ h('rect', { x: 14, y: 14, width: 7, height: 7, rx: 2, stroke: 'currentColor', strokeWidth: 1.6 }),
214
+ h('path', { d: 'M14 6.5h7M17.5 3v7M3 17.5h7M6.5 14v7', stroke: 'currentColor', strokeWidth: 1.6, strokeLinecap: 'round' }))
215
+ }
216
+
217
+ async function api(path, options = {}) {
218
+ const method = options.method || (options.body ? 'POST' : 'GET')
219
+ const requestPath = method === 'GET' ? path + (path.includes('?') ? '&' : '?') + '_=' + Date.now() : path
220
+ const headers = {}
221
+ if (options.body) headers['content-type'] = 'application/json'
222
+ if (activeSessionId) headers['x-dsh-session-id'] = activeSessionId
223
+ const response = await fetch(BASE + requestPath, {
224
+ method,
225
+ cache: 'no-store',
226
+ headers: Object.keys(headers).length ? headers : undefined,
227
+ body: options.body ? JSON.stringify(options.body) : undefined,
228
+ })
229
+ const data = await response.json().catch(() => ({ ok: false, error: 'Invalid server response' }))
230
+ if (!response.ok || (data.ok === false && options.allowFailure !== true)) throw new Error(data.error || ('HTTP ' + response.status))
231
+ return data
232
+ }
233
+
234
+ function Modal({ title, onClose, children, wide = false, error = '', returnFocus }) {
235
+ const dialogRef = React.useRef(null)
236
+ const closeRef = React.useRef(onClose)
237
+ closeRef.current = onClose
238
+ useEffect(() => {
239
+ const previous = returnFocus || document.activeElement
240
+ const node = dialogRef.current
241
+ const focusable = () => [...node.querySelectorAll('button:not(:disabled),input:not(:disabled),textarea:not(:disabled),select:not(:disabled),[tabindex="0"]')].filter(el => el.getClientRects().length > 0)
242
+ const first = node.querySelector('[data-autofocus]') || focusable()[0] || node
243
+ first.focus()
244
+ const listener = event => {
245
+ if (event.key === 'Escape') { event.preventDefault(); closeRef.current() }
246
+ if (event.key !== 'Tab') return
247
+ const items = focusable()
248
+ if (!items.length) { event.preventDefault(); node.focus(); return }
249
+ const firstItem = items[0], lastItem = items[items.length - 1]
250
+ if (event.shiftKey && document.activeElement === firstItem) { event.preventDefault(); lastItem.focus() }
251
+ else if (!event.shiftKey && document.activeElement === lastItem) { event.preventDefault(); firstItem.focus() }
252
+ }
253
+ window.addEventListener('keydown', listener)
254
+ return () => { window.removeEventListener('keydown', listener); if (previous?.focus) previous.focus() }
255
+ }, [])
256
+ useEffect(() => { if (error) dialogRef.current?.querySelector('[role="alert"]')?.focus() }, [error])
257
+ return h('div', { className: 'dsh-caps-overlay', onMouseDown: event => { if (event.target === event.currentTarget) onClose() } },
258
+ h('section', { ref: dialogRef, tabIndex: -1, className: 'dsh-caps-modal', role: 'dialog', 'aria-modal': true, 'aria-label': title, style: wide ? { width: 'min(760px,100%)' } : undefined },
259
+ h('div', { className: 'dsh-caps-modal-head' }, h('h2', { className: 'dsh-caps-modal-title' }, title), h('button', { className: 'dsh-caps-btn', 'aria-label': t('close'), onClick: () => onClose() }, h(Icon, { name: 'close' }))),
260
+ error ? h('div', { className: 'dsh-caps-notice dsh-caps-error', role: 'alert', tabIndex: -1 }, error) : null,
261
+ children))
262
+ }
263
+
264
+ function Field({ label, help, children }) {
265
+ return h('label', { className: 'dsh-caps-field' }, h('span', { className: 'dsh-caps-label' }, label), children, help ? h('span', { className: 'dsh-caps-help' }, help) : null)
266
+ }
267
+
268
+ function SkillCreate({ cwd, workspaces = [], onCancel, onSave, onDirtyChange, busy }) {
269
+ const workspaceOptions = useMemo(() => {
270
+ const rows = []
271
+ if (cwd) rows.push({ id: 'session', path: cwd, title: t('currentWorkspace') })
272
+ for (const workspace of workspaces) {
273
+ if (!rows.some(row => row.path === workspace.path)) rows.push(workspace)
274
+ }
275
+ return rows
276
+ }, [cwd, workspaces])
277
+ const [name, setName] = useState('')
278
+ const [description, setDescription] = useState('')
279
+ const [body, setBody] = useState('')
280
+ const [scope, setScope] = useState('user')
281
+ const [workspaceMode, setWorkspaceMode] = useState(workspaceOptions.length ? 'existing' : 'new')
282
+ const [workspacePath, setWorkspacePath] = useState(workspaceOptions[0]?.path || '')
283
+ const [workspaceName, setWorkspaceName] = useState('')
284
+ const [workspaceParent, setWorkspaceParent] = useState('~/Documents')
285
+ useEffect(() => {
286
+ if (workspaceOptions.length && !workspaceOptions.some(workspace => workspace.path === workspacePath)) {
287
+ setWorkspacePath(workspaceOptions[0].path)
288
+ }
289
+ }, [workspaceOptions, workspacePath])
290
+ useEffect(() => onDirtyChange(Boolean(name || description || body) || scope !== 'user' || workspaceName || workspaceParent !== '~/Documents'), [name, description, body, scope, workspaceName, workspaceParent, onDirtyChange])
291
+ const projectReady = scope !== 'project'
292
+ || (workspaceMode === 'existing' ? Boolean(workspacePath) : Boolean(workspaceName.trim() && workspaceParent.trim()))
293
+ const submit = async event => {
294
+ event.preventDefault()
295
+ if (!projectReady) return
296
+ const projectCwd = scope === 'project' && workspaceMode === 'existing' ? workspacePath : cwd
297
+ if (await onSave({ name, description, body, scope, cwd: projectCwd, workspaceMode, workspaceName: workspaceName.trim(), workspaceParent: workspaceParent.trim() })) onCancel(true)
298
+ }
299
+ const segment = (value, options, onChange, label) => h('div', { className: 'dsh-caps-segment', role: 'group', 'aria-label': label },
300
+ options.map(option => h('button', { key: option.value, type: 'button', 'aria-pressed': value === option.value, onClick: () => onChange(option.value) }, option.label)))
301
+ return h('form', { className: 'dsh-caps-form', onSubmit: submit },
302
+ h(Field, { label: t('scope') },
303
+ segment(scope, [{ value: 'user', label: t('userScope') }, { value: 'project', label: t('projectScope') }], setScope, t('scope'))),
304
+ scope === 'project' ? h('div', { className: 'dsh-caps-workspace' },
305
+ h('div', { className: 'dsh-caps-workspace-head' },
306
+ h('span', { className: 'dsh-caps-workspace-icon' }, h(Icon, { name: 'workspace', size: 16 })),
307
+ h('div', { className: 'dsh-caps-workspace-copy' }, h('span', { className: 'dsh-caps-label' }, t('workspace')), h('span', { className: 'dsh-caps-help' }, t('workspaceHelp')))),
308
+ segment(workspaceMode, [{ value: 'existing', label: t('existingWorkspace') }, { value: 'new', label: t('newWorkspace') }], setWorkspaceMode, t('workspace')),
309
+ workspaceMode === 'existing'
310
+ ? h(Field, { label: t('selectWorkspace') }, h('select', { className: 'dsh-caps-select', value: workspacePath, onChange: e => setWorkspacePath(e.target.value), required: true },
311
+ workspaceOptions.length ? workspaceOptions.map(workspace => h('option', { key: workspace.path, value: workspace.path }, workspace.title + ' · ' + workspace.path)) : h('option', { value: '' }, t('workspaceRequired'))))
312
+ : h('div', { className: 'dsh-caps-workspace-fields' },
313
+ h(Field, { label: t('workspaceName') }, h('input', { className: 'dsh-caps-input', value: workspaceName, onChange: e => setWorkspaceName(e.target.value), placeholder: 'my-workspace', required: true })),
314
+ h(Field, { label: t('workspaceParent'), help: t('workspaceParentHelp') }, h('input', { className: 'dsh-caps-input', value: workspaceParent, onChange: e => setWorkspaceParent(e.target.value), placeholder: '~/Documents', required: true }))),
315
+ workspaceMode === 'new' ? h('div', { className: 'dsh-caps-help' }, t('newWorkspaceHint')) : null) : null,
316
+ h(Field, { label: t('name'), help: t('skillNameHelp') }, h('input', { className: 'dsh-caps-input', value: name, onChange: e => setName(e.target.value), placeholder: 'my-skill', autoFocus: true, required: true })),
317
+ h(Field, { label: t('description') }, h('input', { className: 'dsh-caps-input', value: description, onChange: e => setDescription(e.target.value), required: true })),
318
+ h(Field, { label: t('body') }, h('textarea', { className: 'dsh-caps-textarea', value: body, onChange: e => setBody(e.target.value), placeholder: '# ' + (name || 'my-skill') })),
319
+ h('div', { className: 'dsh-caps-modal-actions' }, h('button', { type: 'button', className: 'dsh-caps-btn', onClick: () => onCancel() }, t('cancel')), h('button', { className: 'dsh-caps-btn dsh-caps-primary', disabled: busy || !projectReady }, busy ? t('creating') : t('create'))))
320
+ }
321
+
322
+ function SkillEdit({ item, onCancel, onSave, onDirtyChange, busy }) {
323
+ const [text, setText] = useState(item.text)
324
+ useEffect(() => onDirtyChange(text !== item.text), [text, item.text, onDirtyChange])
325
+ const submit = async event => { event.preventDefault(); if (await onSave(text)) onCancel(true) }
326
+ return h('form', { className: 'dsh-caps-form', onSubmit: submit },
327
+ item.crossWorkspace && item.writable ? h('div', { className: 'dsh-caps-notice' }, t('workspaceEditImpact', { workspace: item.workspaceTitle })) : null,
328
+ h('div', { className: 'dsh-caps-help' }, item.path),
329
+ h(Field, { label: t('content') }, h('textarea', { className: 'dsh-caps-textarea dsh-caps-content', value: text, onChange: e => setText(e.target.value), spellCheck: false, autoFocus: true, required: true })),
330
+ h('div', { className: 'dsh-caps-modal-actions' }, h('button', { type: 'button', className: 'dsh-caps-btn', onClick: () => onCancel() }, t('cancel')), h('button', { className: 'dsh-caps-btn dsh-caps-primary', disabled: busy }, t('save'))))
331
+ }
332
+
333
+ function mcpJsonText({ name, transport, command, args, cwd, env, url, headers, enabled, includeEnabled = true }) {
334
+ const server = transport === 'stdio'
335
+ ? { transport, command, args, env, cwd }
336
+ : { transport, url, headers }
337
+ const body = includeEnabled ? { ...server, enabled } : server
338
+ return JSON.stringify({ mcpServers: { [name || 'my-mcp']: body } }, null, 2)
339
+ }
340
+
341
+ function parseMcpServers(text, fallbackName, editingName) {
342
+ const value = JSON.parse(text)
343
+ if (value === null || typeof value !== 'object' || Array.isArray(value)) throw new Error(t('invalidJson'))
344
+ let entries
345
+ if (value.mcpServers !== undefined) {
346
+ if (value.mcpServers === null || typeof value.mcpServers !== 'object' || Array.isArray(value.mcpServers)) throw new Error(t('invalidJson'))
347
+ entries = Object.entries(value.mcpServers)
348
+ } else if (!value.transport && !value.type && !value.command && !value.url && Object.values(value).every(entry => entry && typeof entry === 'object' && !Array.isArray(entry))) {
349
+ entries = Object.entries(value)
350
+ } else {
351
+ entries = [[fallbackName, value]]
352
+ }
353
+ if (!entries.length) throw new Error(t('invalidJson'))
354
+ if (editingName && entries.length !== 1) throw new Error(t('jsonOneServer'))
355
+ return entries.map(([key, server]) => {
356
+ const name = editingName || (entries.length > 1 ? key : (fallbackName || key))
357
+ if (!name || !MCP_NAME.test(name)) throw new Error(t('mcpNameHelp'))
358
+ if (server === null || typeof server !== 'object' || Array.isArray(server)) throw new Error(t('invalidJson'))
359
+ const transport = server.transport || server.type || (server.url ? 'streamable-http' : 'stdio')
360
+ if (transport === 'http' || transport === 'sse') return { name, server: { ...server, transport: 'streamable-http' } }
361
+ return { name, server: { ...server, transport } }
362
+ })
363
+ }
364
+
365
+ function parseMcpJson(text, fallbackName, editingName) {
366
+ const servers = parseMcpServers(text, fallbackName, editingName)
367
+ if (servers.length !== 1) throw new Error(t('jsonOneServer'))
368
+ return servers[0]
369
+ }
370
+
371
+ function McpForm({ item, onCancel, onSave, onDirtyChange, busy }) {
372
+ const editing = Boolean(item)
373
+ const standalone = item?.source === 'standalone'
374
+ const [name, setName] = useState(item?.name || '')
375
+ const [transport, setTransport] = useState(item?.transport || 'stdio')
376
+ const [command, setCommand] = useState(item?.command || '')
377
+ const [args, setArgs] = useState((item?.args || []).join('\n'))
378
+ const [cwd, setCwd] = useState(item?.cwd || '')
379
+ const [env, setEnv] = useState(JSON.stringify(item?.env || {}, null, 2))
380
+ const [url, setUrl] = useState(item?.url || '')
381
+ const [headers, setHeaders] = useState(JSON.stringify(item?.headers || {}, null, 2))
382
+ const [enabled, setEnabled] = useState(item?.enabled !== false)
383
+ const [mode, setMode] = useState('form')
384
+ const [jsonText, setJsonText] = useState(() => mcpJsonText({ name: item?.name || '', transport: item?.transport || 'stdio', command: item?.command || '', args: item?.args || [], cwd: item?.cwd || '', env: item?.env || {}, url: item?.url || '', headers: item?.headers || {}, enabled: item?.enabled !== false, includeEnabled: !standalone }))
385
+ const [formError, setFormError] = useState('')
386
+ const original = useMemo(() => JSON.stringify({ name: item?.name || '', transport: item?.transport || 'stdio', command: item?.command || '', args: (item?.args || []).join('\n'), cwd: item?.cwd || '', env: JSON.stringify(item?.env || {}, null, 2), url: item?.url || '', headers: JSON.stringify(item?.headers || {}, null, 2), enabled: item?.enabled !== false }), [])
387
+ const originalJson = useMemo(() => mcpJsonText({ name: item?.name || '', transport: item?.transport || 'stdio', command: item?.command || '', args: item?.args || [], cwd: item?.cwd || '', env: item?.env || {}, url: item?.url || '', headers: item?.headers || {}, enabled: item?.enabled !== false, includeEnabled: !standalone }), [])
388
+ useEffect(() => onDirtyChange(mode === 'json' ? jsonText !== originalJson : JSON.stringify({ name, transport, command, args, cwd, env, url, headers, enabled }) !== original), [name, transport, command, args, cwd, env, url, headers, enabled, mode, jsonText, original, originalJson, onDirtyChange])
389
+ const parseObject = (text, label) => {
390
+ const value = JSON.parse(text || '{}')
391
+ if (value === null || typeof value !== 'object' || Array.isArray(value)) throw new Error(label)
392
+ return value
393
+ }
394
+ const currentJson = () => mcpJsonText({ name, transport, command, args: args.split(/\r?\n/).map(x => x.trim()).filter(Boolean), cwd, env: parseObject(env, t('env')), url, headers: parseObject(headers, t('headers')), enabled, includeEnabled: !standalone })
395
+ const applyServer = server => {
396
+ const requested = server.transport || server.type || (server.url ? 'streamable-http' : 'stdio')
397
+ const nextTransport = requested === 'http' || requested === 'sse' ? 'streamable-http' : requested
398
+ setTransport(nextTransport)
399
+ setCommand(String(server.command || ''))
400
+ setArgs(Array.isArray(server.args) ? server.args.join('\n') : '')
401
+ setCwd(String(server.cwd || ''))
402
+ setEnv(JSON.stringify(server.env || {}, null, 2))
403
+ setUrl(String(server.url || ''))
404
+ setHeaders(JSON.stringify(server.headers || {}, null, 2))
405
+ setEnabled(server.enabled !== false)
406
+ }
407
+ const switchMode = next => {
408
+ setFormError('')
409
+ if (next === 'json') {
410
+ try { setJsonText(currentJson()); setMode('json') } catch (error) { setFormError(t('invalidJson') + ': ' + error.message) }
411
+ return
412
+ }
413
+ try {
414
+ const parsed = parseMcpJson(jsonText, name.trim(), editing ? item?.name : undefined)
415
+ applyServer(parsed.server)
416
+ if (!name.trim()) setName(parsed.name)
417
+ setMode('form')
418
+ } catch (error) { setFormError(t('invalidJson') + ': ' + error.message) }
419
+ }
420
+ const submit = async event => {
421
+ event.preventDefault(); setFormError('')
422
+ let payload
423
+ if (mode === 'json') {
424
+ try {
425
+ const parsedServers = parseMcpServers(jsonText, name.trim(), editing ? item?.name : undefined)
426
+ const toPayload = parsed => {
427
+ const server = parsed.server
428
+ return { name: parsed.name, originalName: item?.name, transport: server.transport, command: String(server.command || ''), args: Array.isArray(server.args) ? server.args.map(String) : [], cwd: String(server.cwd || ''), env: server.env || {}, url: String(server.url || ''), headers: server.headers || {}, enabled: server.enabled !== false }
429
+ }
430
+ payload = !editing && parsedServers.length > 1 ? { servers: parsedServers.map(toPayload) } : toPayload(parsedServers[0])
431
+ } catch (error) { setFormError(t('invalidJson') + ': ' + error.message); return }
432
+ } else {
433
+ let envObject, headerObject
434
+ try { envObject = JSON.parse(env || '{}'); headerObject = JSON.parse(headers || '{}') } catch (error) { setFormError(t('invalidJson') + ': ' + error.message); return }
435
+ payload = { name, originalName: item?.name, transport, command, args: args.split(/\r?\n/).map(x => x.trim()).filter(Boolean), cwd, env: envObject, url, headers: headerObject, enabled }
436
+ }
437
+ if (await onSave(payload)) onCancel(true)
438
+ }
439
+ return h('form', { className: 'dsh-caps-form', onSubmit: submit },
440
+ h(Field, { label: t('mode') }, h('div', { className: 'dsh-caps-segment', role: 'group', 'aria-label': t('mode') },
441
+ h('button', { type: 'button', 'aria-pressed': mode === 'form', onClick: () => switchMode('form') }, t('formMode')),
442
+ h('button', { type: 'button', 'aria-pressed': mode === 'json', onClick: () => switchMode('json') }, t('jsonMode')))),
443
+ h(Field, { label: t('name'), help: t('mcpNameHelp') }, h('input', { className: 'dsh-caps-input', value: name, onChange: e => setName(e.target.value), disabled: editing, autoFocus: !editing, required: mode === 'form' })),
444
+ standalone ? h('div', { className: 'dsh-caps-help' }, t('standaloneEditHint')) : null,
445
+ mode === 'json' ? h(React.Fragment, null,
446
+ h(Field, { label: t('jsonMode'), help: t('jsonHelp') }, h('textarea', { className: 'dsh-caps-textarea dsh-caps-json', value: jsonText, onChange: e => setJsonText(e.target.value), spellCheck: false })))
447
+ : h(React.Fragment, null,
448
+ h(Field, { label: t('transport'), help: transport === 'streamable-http' ? t('transportHttpHelp') : null }, h('select', { className: 'dsh-caps-select', value: transport, onChange: e => setTransport(e.target.value) }, h('option', { value: 'stdio' }, 'stdio'), h('option', { value: 'streamable-http' }, t('transportHttp'))),
449
+ transport === 'stdio' ? h(React.Fragment, null,
450
+ h('div', { className: 'dsh-caps-mcp-grid' },
451
+ h(Field, { label: t('command') }, h('input', { className: 'dsh-caps-input', value: command, onChange: e => setCommand(e.target.value), placeholder: 'npx', required: true })),
452
+ h(Field, { label: t('cwd') }, h('input', { className: 'dsh-caps-input', value: cwd, onChange: e => setCwd(e.target.value) }))),
453
+ h('div', { className: 'dsh-caps-mcp-grid' },
454
+ h(Field, { label: t('args') }, h('textarea', { className: 'dsh-caps-textarea dsh-caps-mcp-small', value: args, onChange: e => setArgs(e.target.value), placeholder: '-y\n@modelcontextprotocol/server-filesystem' })),
455
+ h(Field, { label: t('env') }, h('textarea', { className: 'dsh-caps-textarea dsh-caps-mcp-small', value: env, onChange: e => setEnv(e.target.value), spellCheck: false }))))
456
+ : h('div', { className: 'dsh-caps-mcp-grid' },
457
+ h(Field, { label: t('url') }, h('input', { className: 'dsh-caps-input', type: 'url', value: url, onChange: e => setUrl(e.target.value), placeholder: 'https://example.com/mcp', required: true })),
458
+ h(Field, { label: t('headers') }, h('textarea', { className: 'dsh-caps-textarea dsh-caps-mcp-small', value: headers, onChange: e => setHeaders(e.target.value), spellCheck: false })))),
459
+ standalone ? null : h('label', { className: 'dsh-caps-check' }, h('input', { type: 'checkbox', checked: enabled, onChange: e => setEnabled(e.target.checked) }), t('enableNow'))),
460
+ formError ? h('div', { className: 'dsh-caps-notice dsh-caps-error', role: 'alert' }, formError) : null,
461
+ h('div', { className: 'dsh-caps-modal-actions' }, h('button', { type: 'button', className: 'dsh-caps-btn', onClick: () => onCancel() }, t('cancel')), h('button', { className: 'dsh-caps-btn dsh-caps-primary', disabled: busy }, t('save'))))
462
+ }
463
+
464
+ function McpImport({ onCancel, onImport, busy }) {
465
+ const [loading, setLoading] = useState(true)
466
+ const [servers, setServers] = useState([])
467
+ const [errors, setErrors] = useState([])
468
+ const [selected, setSelected] = useState(new Set())
469
+ const [enabled, setEnabled] = useState(false)
470
+ const [scanError, setScanError] = useState('')
471
+ const scan = useCallback(async () => {
472
+ setLoading(true); setScanError(''); setSelected(new Set())
473
+ try {
474
+ const result = await api('/mcp/imports')
475
+ setServers(result.servers || []); setErrors(result.errors || [])
476
+ } catch (error) { setScanError(error.message) } finally { setLoading(false) }
477
+ }, [])
478
+ useEffect(() => { scan() }, [scan])
479
+ const toggle = (item, checked) => setSelected(current => {
480
+ const next = new Set(current)
481
+ if (checked) {
482
+ for (const other of servers) if (other.name === item.name) next.delete(other.id)
483
+ next.add(item.id)
484
+ } else next.delete(item.id)
485
+ return next
486
+ })
487
+ const submit = async () => { if (await onImport([...selected], enabled)) onCancel(true) }
488
+ return h('div', { className: 'dsh-caps-form' },
489
+ h('p', { className: 'dsh-caps-help' }, t('importHelp')),
490
+ scanError ? h('div', { className: 'dsh-caps-notice dsh-caps-error', role: 'alert' }, h('span', null, t('scanFailed') + ': ' + scanError), h('button', { className: 'dsh-caps-btn', style: { marginLeft: '10px' }, onClick: scan }, t('retry'))) : null,
491
+ errors.map((error, index) => h('div', { className: 'dsh-caps-notice dsh-caps-error', role: 'alert', key: index }, (error.label || error.path) + ': ' + error.error)),
492
+ loading ? h('div', { className: 'dsh-caps-spinner' }, t('loading')) : null,
493
+ !loading && !servers.length ? h('div', { className: 'dsh-caps-empty' }, t('noImports')) : null,
494
+ !loading && servers.length ? h('div', { className: 'dsh-caps-import-list' }, servers.map(item => {
495
+ const summary = item.transport === 'stdio' ? [item.command, ...(item.args || [])].filter(Boolean).join(' ') : item.url
496
+ return h('label', { className: 'dsh-caps-import-row', key: item.id },
497
+ h('input', { type: 'checkbox', checked: selected.has(item.id), disabled: item.exists, onChange: event => toggle(item, event.target.checked) }),
498
+ h('div', { className: 'dsh-caps-import-meta' },
499
+ h('div', { className: 'dsh-caps-name-row' }, h('span', { className: 'dsh-caps-name' }, item.name), h('span', { className: 'dsh-caps-badge' }, item.transport === 'stdio' ? 'stdio' : 'HTTP'), item.conflict ? h('span', { className: 'dsh-caps-badge' }, t('conflict')) : null, item.exists ? h('span', { className: 'dsh-caps-badge' }, t('existing')) : null),
500
+ h('div', { className: 'dsh-caps-description' }, summary),
501
+ h('div', { className: 'dsh-caps-import-source' }, (item.sources || []).map(source => source.label).join(' · '))))
502
+ })) : null,
503
+ h('label', { className: 'dsh-caps-check' }, h('input', { type: 'checkbox', checked: enabled, onChange: event => setEnabled(event.target.checked) }), t('enableImports')),
504
+ enabled ? h('div', { className: 'dsh-caps-notice' }, t('importEnableHint')) : null,
505
+ h('div', { className: 'dsh-caps-modal-actions' }, h('button', { className: 'dsh-caps-btn', onClick: () => onCancel() }, t('cancel')), h('button', { className: 'dsh-caps-btn dsh-caps-primary', disabled: busy || !selected.size, onClick: submit }, t('importAction'))))
506
+ }
507
+
508
+ function SkillSync({ onCancel, onSync, busy }) {
509
+ const [loading, setLoading] = useState(true)
510
+ const [mode, setMode] = useState('symlink')
511
+ const [plan, setPlan] = useState(null)
512
+ const [selected, setSelected] = useState(new Set())
513
+ const [scanError, setScanError] = useState('')
514
+ const scan = useCallback(async () => {
515
+ setLoading(true); setScanError(''); setSelected(new Set())
516
+ try {
517
+ const result = await api('/skill/sync-preview?mode=' + mode)
518
+ setPlan(result)
519
+ setSelected(new Set((result.items || []).filter(item => item.action === 'import' || item.action === 'update').map(item => item.name)))
520
+ } catch (error) { setScanError(error.message) } finally { setLoading(false) }
521
+ }, [mode])
522
+ useEffect(() => { scan() }, [scan])
523
+ const items = plan?.items || []
524
+ const changes = items.filter(item => item.action !== 'skip')
525
+ const toggle = (name, checked) => setSelected(current => {
526
+ const next = new Set(current)
527
+ if (checked) next.add(name); else next.delete(name)
528
+ return next
529
+ })
530
+ const submit = async () => { if (await onSync([...selected], mode)) onCancel(true) }
531
+ return h('div', { className: 'dsh-caps-form' },
532
+ h('p', { className: 'dsh-caps-help' }, t('syncHelp')),
533
+ h('div', { className: 'dsh-caps-sync-mode-list', role: 'radiogroup', 'aria-label': t('syncMode') },
534
+ h('label', { className: 'dsh-caps-sync-mode' + (mode === 'symlink' ? ' is-selected' : '') },
535
+ h('input', { type: 'radio', name: 'skill-sync-mode', checked: mode === 'symlink', onChange: () => setMode('symlink') }),
536
+ h('span', { className: 'dsh-caps-sync-mode-icon' }, h(Icon, { name: 'link', size: 15 })),
537
+ h('span', { className: 'dsh-caps-sync-mode-copy' }, h('strong', null, t('symlinkMode')), h('span', null, t('symlinkHelp')))),
538
+ h('label', { className: 'dsh-caps-sync-mode' + (mode === 'copy' ? ' is-selected' : '') },
539
+ h('input', { type: 'radio', name: 'skill-sync-mode', checked: mode === 'copy', onChange: () => setMode('copy') }),
540
+ h('span', { className: 'dsh-caps-sync-mode-icon' }, h(Icon, { name: 'copy', size: 15 })),
541
+ h('span', { className: 'dsh-caps-sync-mode-copy' }, h('strong', null, t('copyMode')), h('span', null, t('copyHelp'))))),
542
+ mode === 'copy' ? h('p', { className: 'dsh-caps-help' }, t('copyImpact')) : null,
543
+ plan ? h('div', { className: 'dsh-caps-help' }, plan.sourceRoot + ' → ' + plan.targetRoot) : null,
544
+ plan ? h('div', { className: 'dsh-caps-help' }, t('backupLocation') + ': ' + plan.backupRoot) : null,
545
+ scanError ? h('div', { className: 'dsh-caps-notice dsh-caps-error', role: 'alert' }, h('span', null, t('scanFailed') + ': ' + scanError), h('button', { className: 'dsh-caps-btn', style: { marginLeft: '10px' }, onClick: scan }, t('retry'))) : null,
546
+ loading ? h('div', { className: 'dsh-caps-spinner' }, t('loading')) : null,
547
+ !loading && !changes.length ? h('div', { className: 'dsh-caps-empty' }, t('noChanges')) : null,
548
+ !loading && changes.length ? h('div', { className: 'dsh-caps-actions', style: { justifyContent: 'space-between' } },
549
+ h('span', { className: 'dsh-caps-help' }, t('selectedCount', { count: selected.size })),
550
+ h('div', { className: 'dsh-caps-actions' },
551
+ h('button', { className: 'dsh-caps-btn', onClick: () => setSelected(new Set(changes.filter(item => item.action === 'import' || item.action === 'update').map(item => item.name))) }, t('selectAll')),
552
+ h('button', { className: 'dsh-caps-btn', onClick: () => setSelected(new Set()) }, t('clearAll')))) : null,
553
+ !loading && changes.length ? h('div', { className: 'dsh-caps-import-list' }, changes.map(item => {
554
+ const actionKey = item.action === 'update' ? (mode === 'copy' ? 'updateCopy' : 'updateItem')
555
+ : item.action === 'local-edit' ? 'localEditItem'
556
+ : item.action === 'conflict' ? 'conflictItem'
557
+ : item.action === 'error' ? 'errorItem'
558
+ : (mode === 'copy' ? 'newCopy' : 'newItem')
559
+ const hint = item.action === 'local-edit' ? t('localEditHint') : item.action === 'conflict' ? t('conflictHint') : item.action === 'error' ? item.error : null
560
+ return h('label', { className: 'dsh-caps-import-row', key: item.name },
561
+ h('input', { type: 'checkbox', checked: selected.has(item.name), disabled: item.action === 'error', onChange: event => toggle(item.name, event.target.checked) }),
562
+ h('div', { className: 'dsh-caps-import-meta' }, h('div', { className: 'dsh-caps-name-row' }, h('span', { className: 'dsh-caps-name' }, item.name), h('span', { className: 'dsh-caps-badge' }, t(actionKey))), h('div', { className: 'dsh-caps-import-source' }, item.target),
563
+ hint ? h('div', { className: 'dsh-caps-help' }, hint) : null))
564
+ })) : null,
565
+ h('div', { className: 'dsh-caps-modal-actions' }, h('button', { className: 'dsh-caps-btn', onClick: () => onCancel() }, t('cancel')), h('button', { className: 'dsh-caps-btn dsh-caps-primary', disabled: busy || !selected.size, onClick: submit }, t('syncAction'))))
566
+ }
567
+
568
+ function Preferences({ value, onCancel, onSave, onDirtyChange, busy }) {
569
+ const [draft, setDraft] = useState(value)
570
+ const set = (key, next) => setDraft(old => ({ ...old, [key]: next }))
571
+ useEffect(() => onDirtyChange(JSON.stringify(draft) !== JSON.stringify(value)), [draft, value, onDirtyChange])
572
+ const submit = async event => { event.preventDefault(); if (await onSave(draft)) onCancel(true) }
573
+ return h('form', { className: 'dsh-caps-form', onSubmit: submit },
574
+ h('p', { className: 'dsh-caps-help' }, t('preferencesHint')),
575
+ h('label', { className: 'dsh-caps-check' }, h('input', { type: 'checkbox', checked: draft.sidebarVisible, onChange: e => set('sidebarVisible', e.target.checked) }), t('sidebarVisible')),
576
+ h(Field, { label: t('sidebarLabel') }, h('input', { className: 'dsh-caps-input', maxLength: 24, value: draft.sidebarLabel, onChange: e => set('sidebarLabel', e.target.value), required: true })),
577
+ h(Field, { label: t('defaultTab') }, h('select', { className: 'dsh-caps-select', value: draft.defaultTab, onChange: e => set('defaultTab', e.target.value) }, h('option', { value: 'skills' }, t('skills')), h('option', { value: 'mcp' }, t('mcp')))),
578
+ h('label', { className: 'dsh-caps-check' }, h('input', { type: 'checkbox', checked: draft.showDescriptions, onChange: e => set('showDescriptions', e.target.checked) }), t('showDescriptions')),
579
+ h('label', { className: 'dsh-caps-check' }, h('input', { type: 'checkbox', checked: draft.compactRows, onChange: e => set('compactRows', e.target.checked) }), t('compactRows')),
580
+ h('div', { className: 'dsh-caps-modal-actions' }, h('button', { type: 'button', className: 'dsh-caps-btn', onClick: () => onCancel() }, t('cancel')), h('button', { className: 'dsh-caps-btn dsh-caps-primary', disabled: busy }, t('save'))))
581
+ }
582
+
583
+ function Toggle({ checked, disabled, label, onChange }) {
584
+ return h('button', { type: 'button', className: 'dsh-caps-switch', role: 'switch', 'aria-checked': checked, 'aria-label': label, title: label, disabled, onClick: () => onChange(!checked) })
585
+ }
586
+
587
+ function InfoTip({ title, children }) {
588
+ const [open, setOpen] = useState(false)
589
+ const tipId = React.useId() + '-tip'
590
+ return h('span', { className: 'dsh-caps-info-wrap', onMouseEnter: () => setOpen(true), onMouseLeave: () => setOpen(false) },
591
+ h('button', { type: 'button', className: 'dsh-caps-info', 'aria-label': title, 'aria-expanded': open, 'aria-controls': tipId, 'aria-describedby': open ? tipId : undefined, onFocus: () => setOpen(true), onBlur: () => setOpen(false), onClick: event => { event.stopPropagation(); setOpen(value => !value) } }, h(Icon, { name: 'help', size: 14 })),
592
+ open ? h('span', { id: tipId, className: 'dsh-caps-tip', role: 'tooltip' }, h('strong', null, title), h('span', null, children)) : null)
593
+ }
594
+
595
+ function statusText(status) {
596
+ const state = status?.state || 'unknown'
597
+ const labels = { connected: 'connected', connecting: 'connecting', reconnecting: 'reconnecting', failed: 'failed', disabled: 'disabled', closed: 'closed', 'waiting-credentials': 'waiting' }
598
+ return t(labels[state] || 'unknownStatus')
599
+ }
600
+
601
+ function CapabilityPanel({ cwd, preferenceStore }) {
602
+ const prefs = React.useSyncExternalStore(preferenceStore.subscribe, preferenceStore.getSnapshot)
603
+ const [tab, setTab] = useState(prefs.defaultTab)
604
+ const [data, setData] = useState({ skills: [], mcp: [], workspaces: [], skillWarnings: [] })
605
+ const [query, setQuery] = useState('')
606
+ const [loading, setLoading] = useState(true)
607
+ const [error, setError] = useState('')
608
+ const [notice, setNotice] = useState('')
609
+ const [busy, setBusy] = useState('')
610
+ const [modal, setModal] = useState(null)
611
+ const [confirm, setConfirm] = useState(null)
612
+ const [modalError, setModalError] = useState('')
613
+ const [modalDirty, setModalDirty] = useState(false)
614
+ const returnFocusRef = React.useRef(null)
615
+
616
+ const load = useCallback(async (quiet = false) => {
617
+ if (!quiet) setLoading(true)
618
+ setError('')
619
+ try {
620
+ const params = new URLSearchParams()
621
+ if (cwd) params.set('cwd', cwd)
622
+ params.set('workspaces', tab === 'skills' ? '1' : '0')
623
+ const next = await api('/state?' + params.toString())
624
+ setData(next)
625
+ } catch (err) { setError(t('loadFailed') + ': ' + err.message) } finally { setLoading(false) }
626
+ }, [cwd, tab])
627
+ useEffect(() => { load() }, [load])
628
+
629
+ const perform = async (key, action, success, reload = true, errorTarget = 'page') => {
630
+ setBusy(key); setError(''); setModalError(''); setNotice('')
631
+ let result
632
+ try { result = await action() }
633
+ catch (err) { if (errorTarget === 'modal') setModalError(err.message); else setError(err.message); setBusy(''); return null }
634
+ // The mutation has succeeded. A later refresh problem is shown by load()
635
+ // in the page error area and must not make the user repeat the write.
636
+ if (reload) await load(true)
637
+ if (success) setNotice(typeof success === 'function' ? success(result) : success)
638
+ setBusy('')
639
+ return result || true
640
+ }
641
+
642
+ const filtered = useMemo(() => {
643
+ const needle = query.trim().toLowerCase()
644
+ if (!needle) return data[tab] || []
645
+ return (data[tab] || []).filter(item => [item.name, item.description, item.path, item.workspaceTitle, item.workspacePath, item.command, item.url, ...(item.args || [])].filter(Boolean).join(' ').toLowerCase().includes(needle))
646
+ }, [data, tab, query])
647
+
648
+ const openModal = next => {
649
+ returnFocusRef.current = document.activeElement
650
+ setModalDirty(false); setModalError(''); setModal(next)
651
+ }
652
+ const closeModal = (force = false) => {
653
+ if (force !== true && modalDirty && !window.confirm(t('discardChanges'))) return
654
+ setModal(null); setModalError(''); setModalDirty(false)
655
+ }
656
+ const skillCwd = item => item?.workspacePath || cwd
657
+ const openSkillEdit = item => perform('read:' + item.path, async () => {
658
+ const targetCwd = skillCwd(item)
659
+ const result = await api('/skill?path=' + encodeURIComponent(item.path) + (targetCwd ? '&cwd=' + encodeURIComponent(targetCwd) : ''))
660
+ openModal({ kind: 'skill-edit', item: { ...item, text: result.text } })
661
+ return true
662
+ }, '', false)
663
+ const askDelete = (kind, item) => { returnFocusRef.current = document.activeElement; setConfirm({ kind, item }) }
664
+ const doDelete = () => {
665
+ const target = confirm
666
+ setConfirm(null)
667
+ if (target.kind === 'skill') return perform('delete:' + target.item.path, () => api('/skill/delete', { body: { path: target.item.path, cwd: skillCwd(target.item), confirm: true } }), result => t(result.unlinked ? 'unlinked' : 'deleted') + ': ' + result.trash)
668
+ return perform('delete:' + target.item.name, () => api('/mcp/delete', { body: { name: target.item.name, confirm: true } }), result => t(result.standalone ? result.restartRequired ? 'mcpRemovedRestart' : 'mcpRemovedStandalone' : 'mcpDeleted'))
669
+ }
670
+
671
+ const renderSkill = item => {
672
+ const readOnly = !item.writable
673
+ return h('article', { className: 'dsh-caps-row' + (readOnly ? ' dsh-caps-row-readonly' : ''), key: item.id, 'aria-disabled': readOnly ? true : undefined },
674
+ h('div', { className: 'dsh-caps-main' },
675
+ h('div', { className: 'dsh-caps-name-row' }, h('span', { className: 'dsh-caps-name' }, item.name), h('span', { className: 'dsh-caps-badge' }, t(item.scope === 'project' ? (item.writable ? 'projectWritable' : 'projectReadonly') : 'user')), h('span', { className: 'dsh-caps-badge' }, t(item.form === 'file' ? 'file' : 'directory')), item.source === 'user-agents' ? h('span', { className: 'dsh-caps-badge' }, t('agentSource')) : item.source === 'user-dsh' ? h('span', { className: 'dsh-caps-badge' }, t('dshSource')) : null,
676
+ item.workspaceTitle ? h('span', { className: 'dsh-caps-badge', title: item.workspacePath }, item.workspaceTitle) : null,
677
+ item.crossWorkspace ? h(InfoTip, { title: t(item.writable ? 'workspaceImpactTitle' : 'workspaceReadonlyTitle') }, t(item.writable ? 'workspaceImpactHint' : 'workspaceReadonlyHint', { workspace: item.workspaceTitle })) : null),
678
+ prefs.showDescriptions ? h('div', { className: 'dsh-caps-description' }, item.description || t('empty')) : null,
679
+ item.error ? h('div', { className: 'dsh-caps-notice dsh-caps-error', role: 'alert' }, item.error) : null,
680
+ h('div', { className: 'dsh-caps-path', title: item.path }, item.path)),
681
+ h('div', { className: 'dsh-caps-row-actions' },
682
+ h('span', { className: 'dsh-caps-status', 'data-state': item.enabled ? 'connected' : 'disabled' }, h('span', { className: 'dsh-caps-dot' }), t(item.enabled ? 'enabled' : 'disabled')),
683
+ h(Toggle, { checked: item.enabled, disabled: !item.writable || Boolean(busy), label: t(item.enabled ? 'enabled' : 'disabled') + ': ' + item.name, onChange: enabled => perform('toggle:' + item.path, () => api('/skill/toggle', { body: { path: item.path, enabled, cwd: skillCwd(item) } }), t('updated')) }),
684
+ h('button', { className: 'dsh-caps-btn', disabled: !item.writable || !item.enabled || Boolean(busy), onClick: () => openSkillEdit(item) }, t('edit')),
685
+ h('button', { className: 'dsh-caps-btn dsh-caps-danger', disabled: !item.writable || Boolean(busy), onClick: () => askDelete('skill', item) }, t('remove'))))
686
+ }
687
+
688
+ const renderMcp = item => {
689
+ const standalone = item.source === 'standalone'
690
+ const descriptionId = 'dsh-caps-standalone-' + item.name
691
+ const state = item.status?.state || (item.enabled ? 'connecting' : 'disabled')
692
+ const summary = item.transport === 'stdio' ? [item.command, ...(item.args || [])].filter(Boolean).join(' ') : item.url
693
+ return h('article', { className: 'dsh-caps-row', key: item.name },
694
+ h('div', { className: 'dsh-caps-main' },
695
+ h('div', { className: 'dsh-caps-name-row' }, h('span', { className: 'dsh-caps-name' }, item.name), item.transport ? h('span', { className: 'dsh-caps-badge' }, item.transport === 'stdio' ? 'stdio' : 'HTTP') : null,
696
+ standalone ? h('span', { className: 'dsh-caps-badge' }, t('standalone')) : item.source === 'registered' ? h('span', { className: 'dsh-caps-badge', title: t('registeredHint') }, t('registered')) : null,
697
+ state !== 'unknown' ? h('span', { className: 'dsh-caps-status', 'data-state': state }, h('span', { className: 'dsh-caps-dot' }), statusText(item.status)) : null,
698
+ state === 'connected' ? h('span', { className: 'dsh-caps-badge' }, t('toolCount', { count: item.status.toolCount || 0 })) : null),
699
+ prefs.showDescriptions ? h('div', { className: 'dsh-caps-description' }, summary || t(item.source === 'registered' ? 'registeredHint' : 'empty')) : null,
700
+ standalone ? h('div', { className: 'dsh-caps-description', id: descriptionId }, t('standaloneHint')) : null,
701
+ item.status?.lastError ? h('div', { className: 'dsh-caps-path', title: item.status.lastError }, item.status.lastError) : null),
702
+ h('div', { className: 'dsh-caps-row-actions' }, h(React.Fragment, null,
703
+ h(Toggle, { checked: item.enabled, disabled: item.canToggle !== true || Boolean(busy), label: t(item.enabled ? 'enabled' : 'disabled') + ': ' + item.name, onChange: enabled => perform('toggle:' + item.name, () => api('/mcp/toggle', { body: { name: item.name, enabled } }), result => t(result.restartRequired ? 'mcpRestartRequired' : 'updated')) }),
704
+ standalone ? null : h('button', { className: 'dsh-caps-btn', disabled: Boolean(busy), onClick: () => perform('test:' + item.name, () => api('/mcp/test', { body: { name: item.name }, allowFailure: true }), result => {
705
+ if (result.ok) return t('testOk', { count: result.toolNames?.length || 0 })
706
+ setError(t('testFailed', { message: result.message || 'Unknown' }))
707
+ return ''
708
+ }, false) }, t('test')),
709
+ standalone ? null : h('button', { className: 'dsh-caps-btn', disabled: Boolean(busy), onClick: () => perform('restart:' + item.name, () => api('/mcp/restart', { body: { name: item.name } }), t('restarted'), false) }, t('restart')),
710
+ h('button', { className: 'dsh-caps-btn', disabled: !item.writable || Boolean(busy), onClick: () => openModal({ kind: 'mcp', item }) }, t('edit')),
711
+ h('button', { className: 'dsh-caps-btn dsh-caps-danger', disabled: item.canDelete !== true || Boolean(busy), onClick: () => askDelete('mcp', item) }, t('remove')))))
712
+ }
713
+
714
+ const modalProps = { error: modalError, onClose: closeModal, returnFocus: returnFocusRef.current }
715
+ const createSkillFromForm = async body => {
716
+ let targetCwd = body.cwd
717
+ if (body.scope === 'project' && body.workspaceMode === 'new') {
718
+ const created = await api('/workspace/create', { body: { name: body.workspaceName, parent: body.workspaceParent } })
719
+ targetCwd = created.workspace.path
720
+ }
721
+ return await api('/skill/create', { body: { ...body, cwd: targetCwd } })
722
+ }
723
+ const saveMcpFromForm = async body => {
724
+ if (!Array.isArray(body.servers)) return await api('/mcp/save', { body })
725
+ const saved = []
726
+ try {
727
+ for (const server of body.servers) saved.push(await api('/mcp/save', { body: server }))
728
+ } catch (error) {
729
+ await load(true)
730
+ throw error
731
+ }
732
+ return { saved }
733
+ }
734
+ const activeModal = modal?.kind === 'skill-create' ? h(Modal, { ...modalProps, title: t('createSkillTitle') }, h(SkillCreate, { cwd, workspaces: data.workspaces || [], busy: Boolean(busy), onCancel: closeModal, onDirtyChange: setModalDirty, onSave: body => perform('create-skill', () => createSkillFromForm(body), t('created'), true, 'modal') }))
735
+ : modal?.kind === 'skill-edit' ? h(Modal, { ...modalProps, title: t('editSkillTitle') + ': ' + modal.item.name, wide: true }, h(SkillEdit, { item: modal.item, busy: Boolean(busy), onCancel: closeModal, onDirtyChange: setModalDirty, onSave: text => perform('save-skill', () => api('/skill/update', { body: { path: modal.item.path, text, cwd: skillCwd(modal.item) } }), t('saved'), true, 'modal') }))
736
+ : modal?.kind === 'skill-sync' ? h(Modal, { ...modalProps, title: t('syncTitle'), wide: true }, h(SkillSync, { busy: Boolean(busy), onCancel: closeModal, onSync: (names, mode) => perform('skill-sync', () => api('/skill/sync', { body: { names, mode } }), result => t('syncDone', { added: result.imported.length, updated: result.updated.length, skipped: result.skipped.length, failed: result.failed.length }) + (result.failed.length ? ' · ' + result.failed.map(item => item.name + ': ' + item.error).join(';') : '') + (result.stateError ? t('syncStateError') + result.stateError : '') + (result.backupDir ? ' · ' + result.backupDir : '')) }))
737
+ : modal?.kind === 'mcp' ? h(Modal, { ...modalProps, title: t(modal.item ? 'editMcpTitle' : 'addMcpTitle') }, h(McpForm, { item: modal.item, busy: Boolean(busy), onCancel: closeModal, onDirtyChange: setModalDirty, onSave: body => perform('save-mcp', () => saveMcpFromForm(body), t('saved'), true, 'modal') }))
738
+ : modal?.kind === 'mcp-import' ? h(Modal, { ...modalProps, title: t('importTitle'), wide: true }, h(McpImport, { busy: Boolean(busy), onCancel: closeModal, onImport: (selections, enabled) => perform('import-mcp', () => api('/mcp/import', { body: { selections, enabled } }), result => t('importDone', { added: result.imported.length, skipped: result.skipped.length }) + (result.errors.length ? t('sourceErrors', { count: result.errors.length }) : ''), true, 'modal') }))
739
+ : null
740
+
741
+ return h('div', { className: 'dsh-caps' + (prefs.compactRows ? ' dsh-caps-compact' : '') },
742
+ h('style', null, CSS),
743
+ h('div', { className: 'dsh-caps-shell', inert: (modal || confirm) ? '' : undefined, 'aria-hidden': (modal || confirm) ? true : undefined },
744
+ h('header', { className: 'dsh-caps-header' },
745
+ h('div', null, h('h1', { className: 'dsh-caps-title' }, t('title')), h('p', { className: 'dsh-caps-subtitle' }, t('subtitle')))),
746
+ h('div', { className: 'dsh-caps-tabs' }, ['skills', 'mcp'].map(key => h('button', { key, 'aria-pressed': tab === key, className: 'dsh-caps-tab', onClick: () => setTab(key) }, t(key), h('span', { className: 'dsh-caps-count' }, (data[key] || []).length)))),
747
+ h('div', { className: 'dsh-caps-toolbar' },
748
+ h('div', { className: 'dsh-caps-search' }, h('span', { className: 'dsh-caps-search-icon' }, h(Icon, { name: 'search' })), h('input', { className: 'dsh-caps-input', type: 'search', value: query, onChange: e => setQuery(e.target.value), placeholder: t('search'), 'aria-label': t('search') })),
749
+ h('button', { className: 'dsh-caps-btn', onClick: () => load(), disabled: loading }, h(Icon, { name: 'refresh' }), t('refresh')),
750
+ tab === 'skills' ? h('button', { className: 'dsh-caps-btn', disabled: Boolean(busy), onClick: () => openModal({ kind: 'skill-sync' }) }, h(Icon, { name: 'sync' }), t('syncSkills'))
751
+ : h('button', { className: 'dsh-caps-btn', onClick: () => openModal({ kind: 'mcp-import' }) }, h(Icon, { name: 'import' }), t('importMcp')),
752
+ h('button', { className: 'dsh-caps-btn dsh-caps-primary', onClick: () => openModal(tab === 'skills' ? { kind: 'skill-create' } : { kind: 'mcp', item: null }) }, h(Icon, { name: 'plus' }), t(tab === 'skills' ? 'addSkill' : 'addMcp'))),
753
+ error ? h('div', { className: 'dsh-caps-notice dsh-caps-error', role: 'alert' }, error) : null,
754
+ notice ? h('div', { className: 'dsh-caps-notice', role: 'status' }, notice) : null,
755
+ data.mcpError && tab === 'mcp' ? h('div', { className: 'dsh-caps-notice dsh-caps-error', role: 'alert' }, data.mcpError) : null,
756
+ data.skillWarnings?.length && tab === 'skills' ? h('div', { className: 'dsh-caps-notice', role: 'status' }, t('workspaceScanWarnings') + ' ' + data.skillWarnings.map(item => item.workspaceTitle).join(', ')) : null,
757
+ tab === 'skills' ? h('div', { className: 'dsh-caps-help', style: { marginBottom: '8px' } }, t('takeoverHint')) : null,
758
+ tab === 'skills' && cwd ? h('div', { className: 'dsh-caps-help', style: { marginBottom: '12px' } }, t('readonlyHint')) : null,
759
+ loading ? h('div', { className: 'dsh-caps-spinner' }, t('loading'))
760
+ : h('div', { className: 'dsh-caps-list' }, filtered.length ? filtered.map(tab === 'skills' ? renderSkill : renderMcp) : (tab === 'mcp' && data.mcpError) ? null : h('div', { className: 'dsh-caps-empty' }, query ? t('noItems') : t(tab === 'skills' ? 'noSkills' : 'noMcp'))),
761
+ tab === 'skills' && data.userSkillsRoot ? h('footer', { className: 'dsh-caps-foot' },
762
+ h('span', { title: data.userSkillsRoot }, t('userSkillsDir') + ': ' + (data.home && data.userSkillsRoot.startsWith(data.home + '/') ? '~' + data.userSkillsRoot.slice(data.home.length) : data.userSkillsRoot))) : null),
763
+ activeModal,
764
+ confirm ? h(Modal, { title: t(confirm.kind === 'skill' ? 'deleteSkillTitle' : 'deleteMcpTitle'), onClose: () => setConfirm(null), returnFocus: returnFocusRef.current },
765
+ h('p', null, confirm.item.name), h('p', { className: 'dsh-caps-help' }, t(confirm.kind === 'skill' ? 'deleteSkillText' : 'deleteMcpText')),
766
+ confirm.kind === 'skill' && confirm.item.crossWorkspace ? h('div', { className: 'dsh-caps-notice' }, t('workspaceDeleteImpact', { workspace: confirm.item.workspaceTitle })) : null,
767
+ h('div', { className: 'dsh-caps-modal-actions' }, h('button', { className: 'dsh-caps-btn', onClick: () => setConfirm(null), 'data-autofocus': true }, t('cancel')), h('button', { className: 'dsh-caps-btn dsh-caps-danger', onClick: doDelete }, t('confirmDelete')))) : null)
768
+ }
769
+
770
+ function SessionPage(props) {
771
+ let cwd
772
+ let sessionId
773
+ if (typeof props.useSessions === 'function') {
774
+ cwd = props.useSessions(state => {
775
+ const current = state?.current
776
+ return current && state?.byId?.[current]?.cwd
777
+ })
778
+ sessionId = props.useSessions(state => state?.current)
779
+ }
780
+ activeSessionId = sessionId || null
781
+ useEffect(() => {
782
+ activeSessionId = sessionId || null
783
+ return () => { if (activeSessionId === sessionId) activeSessionId = null }
784
+ }, [sessionId])
785
+ return h(CapabilityPanel, { cwd, preferenceStore: props.preferenceStore })
786
+ }
787
+
788
+ function apply(ctx, config = {}) {
789
+ const preferenceStore = createPreferenceStore({
790
+ sidebarVisible: true,
791
+ sidebarLabel: '技能与MCP',
792
+ defaultTab: config.defaultTab === 'mcp' ? 'mcp' : 'skills',
793
+ showDescriptions: true,
794
+ compactRows: true,
795
+ })
796
+ ctx.effect(() => ctx.locale.register(NS, MESSAGES), 'capability-switch: locales')
797
+ translate = ctx.locale.bind(NS)
798
+ ctx.effect(() => {
799
+ const disposeMain = ctx.slots.inject('main', () => ctx.slots.register({ name: 'main', key: PANEL }, props => h(SessionPage, { ...props, preferenceStore })))
800
+ const disposeSidebar = ctx.slots.inject('sidebar.panellist', () => ctx.slots.register({ name: 'sidebar.panellist', id: PANEL, order: 6, label: '技能与MCP', locale: NS }, BrandIcon))
801
+ return () => { disposeMain(); disposeSidebar() }
802
+ }, 'capability-switch: slots')
803
+ }
804
+
805
+ return { apply, inject: ['slots', 'locale'] }
806
+ },
807
+ })
808
+