feat(plugin): open settings panels from the settings button, merge plugin logs into the app log (#182)
- The settings button now also appears for plugins that only contribute a settings.plugin panel; the panel opens in the settings dialog beside the declarative form instead of the bottom of the Plugins page. - Plugin stderr and non-routine audit entries are mirrored to the app log as plugin:<id>, rate limited per plugin; the per-plugin log window is removed. - The installed-plugin security scan button is removed; the scan verdict shows in the permissions tooltip. The pre-install archive scan is unchanged. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1433602f14
commit
3e5b0d7e6c
15 files changed
+141
-181
No files matched your search
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"group": "improvements",
|
||||
"order": 0,
|
||||
"authors": ["Nwflower"],
|
||||
"zh": "插件日志并入应用日志并标明插件包名,不再使用单独的日志窗口。",
|
||||
"en": "Show plugin logs in the app log, labeled with the plugin ID, instead of a separate log window."
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"group": "improvements",
|
||||
"order": 0,
|
||||
"authors": ["Nwflower"],
|
||||
"zh": "已安装插件的安全扫描结论改为在权限提示中显示。",
|
||||
"en": "Show the security scan result of installed plugins in their permissions tooltip."
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"group": "improvements",
|
||||
"order": 0,
|
||||
"authors": ["Nwflower"],
|
||||
"zh": "插件自带的设置面板改为从该插件的设置按钮打开,不再排在插件页底部。",
|
||||
"en": "Open a plugin's own settings panel from its settings button instead of the bottom of the Plugins page."
|
||||
}
|
||||
@@ -29,6 +29,7 @@ flowchart TB
|
||||
1. 除编译期内置扩展外,客户端不在主进程内加载动态库或运行第三方脚本(交互主题受信任脚本除外),用户也无需额外安装外部脚本运行时。
|
||||
2. Apache-2.0 客户端本体与外部组件仅通过独立子进程和协议交互,插件包、私有数据、缓存与日志全部隔离在数据目录的 `plugins/` 下。
|
||||
3. 插件无权读取硬件序列号、UUID、ROM 或 MAC 地址,无权静默触发管理员提权或系统重启,也无权直接改写 `vm.toml`;插件贡献的排障数据一律经宿主脱敏后才写入排障包。
|
||||
4. 插件的标准错误输出和异常审计记录在桌面端同时写入应用日志,来源标为 `plugin:<插件 ID>`,每个插件单独限流。成功的常规宿主调用只写入 `plugins/logs/` 下的插件日志文件。
|
||||
|
||||
内置虚拟机交互服务默认启用,通过宿主控制台代理串行处理每台虚拟机的 QMP 操作,每次操作后关闭连接,并与虚拟机生命周期操作共用锁。桌面文本输入期间暂停后台缩略图捕获。该服务不实现 MCP 协议。
|
||||
|
||||
@@ -56,7 +57,7 @@ Sidecar 的控制台 Host API 只接受 VM 引用,不接受 QMP 套接字或 V
|
||||
|
||||
已激活的外部主题在重启客户端和升级插件后自动保留,并在脚本变更重新批准后带版本哈希参数重载;仅停用或卸载所属主题插件时回退内置默认主题并清空当前配色方案,安全模式或命令行停用无关插件不会影响当前主题。从市场安装并启用主题插件时,仅当当前仍处于内置默认主题才自动切换为该插件的首个主题,不覆盖用户已选的其他外部主题。
|
||||
|
||||
自定义界面优先采用 JSON Schema 声明式设置(支持标记敏感项、全局或按虚拟机作用域及生效时机);确需自绘界面的插件使用 `sandbox="allow-scripts"` 且禁联网的沙箱 `iframe`,通过消息桥请求通知、通用虚拟机列表、插件自有命令与多语种词包,所有本地 HTTP 服务均拒绝来自沙箱 `iframe` 或空来源的跨站请求。`contributes.views` 可在侧栏、VM 标签页、全局设置页或对话框中挂载完整视图,视图随插件作用域注册和释放,停用后自动回退到对应内置页面。视图的 `when` 支持 `vmState==<状态>` 与 `theme==<light|dark>`,条件不满足时宿主隐藏入口和页面。`minWidth` 设置页面的最小宽度,空间不足时横向滚动。
|
||||
自定义界面优先采用 JSON Schema 声明式设置(支持标记敏感项、全局或按虚拟机作用域及生效时机);确需自绘界面的插件使用 `sandbox="allow-scripts"` 且禁联网的沙箱 `iframe`,通过消息桥请求通知、通用虚拟机列表、插件自有命令与多语种词包,所有本地 HTTP 服务均拒绝来自沙箱 `iframe` 或空来源的跨站请求。`settings.plugin` 槽位的面板与声明式设置一起显示在插件的设置弹窗中。`contributes.views` 可在侧栏、VM 标签页、全局设置页或对话框中挂载完整视图,视图随插件作用域注册和释放,停用后自动回退到对应内置页面。视图的 `when` 支持 `vmState==<状态>` 与 `theme==<light|dark>`,条件不满足时宿主隐藏入口和页面。`minWidth` 设置页面的最小宽度,空间不足时横向滚动。
|
||||
|
||||
页面可通过 `ui.confirm` 请求确认框,通过 `ui.showForm` 打开声明式表单,通过 `ui.copy` 复制文本,通过 `ui.openExternal` 打开经宿主校验的 HTTPS 外链,并使用 `ui.setTitle`、`ui.setBadge` 更新当前视图元数据。`ui.openView` 仅打开本插件声明的视图,`ui.close` 关闭当前视图或顶层对话框,`ui.navigate` 进入内置宿主页面;这些操作不会关闭应用窗口。确认框使用 `ui:notify` 权限,其他界面动作使用 `ui:slot` 权限。
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {
|
||||
AlertTriangle, CheckCircle2, ExternalLink, FolderOpen, PackagePlus, Palette,
|
||||
RefreshCw, Settings2, Shield, ShieldAlert, Sparkles, Terminal, Trash2,
|
||||
RefreshCw, Settings2, ShieldAlert, Sparkles, Trash2,
|
||||
} from 'lucide-react'
|
||||
import React, { useEffect, useMemo, useRef, useState } from 'react'
|
||||
import '../i18n/domains/plugins.gen'
|
||||
@@ -68,17 +68,14 @@ export const PluginsPage: React.FC<Props> = ({
|
||||
const settingsRuntimeWarning = plugins.find((p) => p.id === settingsTarget?.id)?.runtime_warning
|
||||
const [settingsValues, setSettingsValues] = useState<Record<string, unknown>>({})
|
||||
const settingsSaveQueuesRef = useRef(new Map<string, Promise<void>>())
|
||||
const [logTarget, setLogTarget] = useState<{ id: string; text: string } | null>(null)
|
||||
const [removeTarget, setRemoveTarget] = useState<PluginInfo | null>(null)
|
||||
const [disableTarget, setDisableTarget] = useState<PluginInfo | null>(null)
|
||||
const [deleteSchemeTarget, setDeleteSchemeTarget] = useState<CustomThemeScheme | null>(null)
|
||||
|
||||
// Static risk scan modal state (pre-install .zip preview or installed plugin scan)
|
||||
const [scanModal, setScanModal] = useState<{
|
||||
mode: 'archive' | 'installed'
|
||||
archivePath?: string
|
||||
report: ScanReport
|
||||
} | null>(null)
|
||||
// Static risk scan of a .zip, shown before it is installed
|
||||
const [scanModal, setScanModal] = useState<{ archivePath: string; report: ScanReport } | null>(null)
|
||||
// Scan verdicts of installed plugins by id, filled when their permission tooltip opens
|
||||
const [scanVerdicts, setScanVerdicts] = useState<Record<string, string>>({})
|
||||
const [scanBusy, setScanBusy] = useState(false)
|
||||
|
||||
// Mount the market (and touch the network) only after its tab is opened.
|
||||
@@ -100,6 +97,7 @@ export const PluginsPage: React.FC<Props> = ({
|
||||
api.GetActiveTheme(),
|
||||
])
|
||||
setPlugins(list ?? [])
|
||||
setScanVerdicts({})
|
||||
setContribs(ui)
|
||||
setActiveTheme(th)
|
||||
return { ui, th }
|
||||
@@ -224,7 +222,7 @@ export const PluginsPage: React.FC<Props> = ({
|
||||
if (!path) return
|
||||
setScanBusy(true)
|
||||
const report = await api.InspectPluginArchive(path)
|
||||
setScanModal({ mode: 'archive', archivePath: path, report })
|
||||
setScanModal({ archivePath: path, report })
|
||||
} catch (e) {
|
||||
onError(tr('pluginFailScan'), e)
|
||||
} finally {
|
||||
@@ -233,7 +231,7 @@ export const PluginsPage: React.FC<Props> = ({
|
||||
}
|
||||
|
||||
const confirmInstallScannedArchive = async () => {
|
||||
if (!scanModal || scanModal.mode !== 'archive' || !scanModal.archivePath || scanModal.report.hard_blocked) return
|
||||
if (!scanModal || scanModal.report.hard_blocked) return
|
||||
const archivePath = scanModal.archivePath
|
||||
setScanBusy(true)
|
||||
try {
|
||||
@@ -248,16 +246,15 @@ export const PluginsPage: React.FC<Props> = ({
|
||||
}
|
||||
}
|
||||
|
||||
const inspectInstalledPlugin = async (p: PluginInfo) => {
|
||||
setScanBusy(true)
|
||||
const loadScanVerdict = async (p: PluginInfo) => {
|
||||
if (scanVerdicts[p.id]) return
|
||||
let verdict = tr('pluginFailScan')
|
||||
try {
|
||||
const report = await api.ScanInstalledPlugin(p.id)
|
||||
setScanModal({ mode: 'installed', report })
|
||||
verdict = locText((await api.ScanInstalledPlugin(p.id)).headline, locale, verdict)
|
||||
} catch (e) {
|
||||
onError(tr('pluginFailScan'), e)
|
||||
} finally {
|
||||
setScanBusy(false)
|
||||
console.warn('[plugins] ScanInstalledPlugin failed:', p.id, e)
|
||||
}
|
||||
setScanVerdicts((current) => ({ ...current, [p.id]: verdict }))
|
||||
}
|
||||
|
||||
const linkDevDir = async () => {
|
||||
@@ -288,7 +285,7 @@ export const PluginsPage: React.FC<Props> = ({
|
||||
|
||||
const openPluginSettings = async (p: PluginInfo) => {
|
||||
try {
|
||||
const vals = await api.GetPluginSettings(p.id, '')
|
||||
const vals = hasAppSettings(p) ? await api.GetPluginSettings(p.id, '') : null
|
||||
setSettingsValues((vals ?? {}) as Record<string, unknown>)
|
||||
setSettingsTarget(p)
|
||||
} catch (e) {
|
||||
@@ -317,15 +314,6 @@ export const PluginsPage: React.FC<Props> = ({
|
||||
}
|
||||
}
|
||||
|
||||
const openPluginLog = async (p: PluginInfo) => {
|
||||
try {
|
||||
const txt = await api.ReadPluginLog(p.id)
|
||||
setLogTarget({ id: p.id, text: txt || tr('pluginLogEmpty') })
|
||||
} catch (e) {
|
||||
onError(tr('pluginFailReadLog'), e)
|
||||
}
|
||||
}
|
||||
|
||||
const selectTheme = async (themeID: string, schemeID = '') => {
|
||||
try {
|
||||
await api.SetActiveTheme(themeID, schemeID)
|
||||
@@ -386,7 +374,9 @@ export const PluginsPage: React.FC<Props> = ({
|
||||
const filteredBuiltins = useMemo(() => builtins.filter(matchesFilter), [builtins, q, locale])
|
||||
const filteredExternal = useMemo(() => external.filter(matchesFilter), [external, q, locale])
|
||||
const themes = contribs?.themes ?? []
|
||||
const settingsPanels = (contribs?.panels ?? []).filter((p) => p.slot === 'settings.plugin')
|
||||
const settingsPanelsOf = (id: string) => contribs?.asset_token
|
||||
? (contribs.panels ?? []).filter((panel) => panel.slot === 'settings.plugin' && panel.pluginId === id)
|
||||
: []
|
||||
const presetSchemes = activeTheme?.theme?.schemes ?? []
|
||||
const customSchemes = (activeTheme?.custom_schemes ?? []).filter((s) => s.theme_id === activeTheme?.theme_id)
|
||||
const activeCount = useMemo(() => plugins.filter((p) => p.state === 'active').length, [plugins])
|
||||
@@ -451,11 +441,16 @@ export const PluginsPage: React.FC<Props> = ({
|
||||
<div className="row-sub plugin-row-meta">
|
||||
<PluginTrustBadge locale={locale} trust={p.trust} publisher={p.publisher} />
|
||||
<span className="mono">v{p.version}</span>
|
||||
{perms.length > 0 && (
|
||||
<Tip label={tr('pluginPermissionsLabel', { list: perms.map((x) => x.name).join(', ') })}>
|
||||
<span>{tr('pluginPermCount', { count: perms.length })}</span>
|
||||
</Tip>
|
||||
)}
|
||||
<Tip
|
||||
label={[
|
||||
tr('pluginPermissionsLabel', { list: perms.map((x) => x.name).join(', ') || '—' }),
|
||||
scanVerdicts[p.id],
|
||||
].filter(Boolean).join('\n')}
|
||||
>
|
||||
<span tabIndex={0} onPointerEnter={() => void loadScanVerdict(p)} onFocus={() => void loadScanVerdict(p)}>
|
||||
{tr('pluginPermCount', { count: perms.length })}
|
||||
</span>
|
||||
</Tip>
|
||||
</div>
|
||||
)}
|
||||
{alert && (
|
||||
@@ -472,15 +467,9 @@ export const PluginsPage: React.FC<Props> = ({
|
||||
)}
|
||||
</div>
|
||||
<div className="row-right">
|
||||
{!isBuiltin && (
|
||||
<IconButton label={tr('pluginScanInspect')} icon={<Shield size={15} />} onClick={() => void inspectInstalledPlugin(p)} />
|
||||
)}
|
||||
{hasAppSettings(p) && (
|
||||
{(hasAppSettings(p) || settingsPanelsOf(p.id).length > 0) && (
|
||||
<IconButton label={tr('pluginSettings')} icon={<Settings2 size={15} />} onClick={() => void openPluginSettings(p)} />
|
||||
)}
|
||||
{p.log_path && (
|
||||
<IconButton label={tr('pluginViewLog')} icon={<Terminal size={15} />} onClick={() => void openPluginLog(p)} />
|
||||
)}
|
||||
{p.removable && (
|
||||
<IconButton
|
||||
disabled={p.in_use || busyID === p.id}
|
||||
@@ -828,30 +817,13 @@ export const PluginsPage: React.FC<Props> = ({
|
||||
</section>
|
||||
)}
|
||||
|
||||
{settingsPanels.length > 0 && contribs?.asset_token ? (
|
||||
<section className="section" data-rg-slot="settings.plugin">
|
||||
<div className="section-title">{tr('pluginPanelsSection')}</div>
|
||||
{settingsPanels.map((panel) => (
|
||||
<PluginPanelFrame
|
||||
key={`${panel.pluginId}:${panel.id}`}
|
||||
locale={locale}
|
||||
panel={panel}
|
||||
assetToken={contribs.asset_token!}
|
||||
appearance={appearance}
|
||||
onOpenView={onOpenView}
|
||||
onNavigate={onNavigate}
|
||||
/>
|
||||
))}
|
||||
</section>
|
||||
) : (
|
||||
<div className="rg-slot-anchor" data-rg-slot="settings.plugin" />
|
||||
)}
|
||||
<div className="rg-slot-anchor" data-rg-slot="settings.plugin" />
|
||||
</>
|
||||
)}
|
||||
|
||||
{scanModal && (
|
||||
<Modal
|
||||
title={scanModal.mode === 'archive' ? tr('pluginScanArchiveTitle') : tr('pluginScanModalTitle')}
|
||||
title={tr('pluginScanArchiveTitle')}
|
||||
subtitle={scanModal.report.plugin_id ? `${locText(scanModal.report.name, locale, scanModal.report.plugin_id)} · v${scanModal.report.version || '—'}` : scanModal.archivePath}
|
||||
closeLabel={tr('close')}
|
||||
onClose={() => { if (!scanBusy) setScanModal(null) }}
|
||||
@@ -864,20 +836,14 @@ export const PluginsPage: React.FC<Props> = ({
|
||||
{scanModal.report.tier ? `${scanModal.report.tier} · ${scanModal.report.trust || 'community'}` : ''}
|
||||
</span>
|
||||
<span className="hstack">
|
||||
{scanModal.mode === 'archive' ? (
|
||||
<>
|
||||
<Button variant="ghost" disabled={scanBusy} onClick={() => setScanModal(null)}>{tr('cancel')}</Button>
|
||||
<Button
|
||||
variant="primary"
|
||||
disabled={scanBusy || scanModal.report.hard_blocked}
|
||||
onClick={() => void confirmInstallScannedArchive()}
|
||||
>
|
||||
{scanModal.report.hard_blocked ? tr('pluginScanBlockedBtn') : tr('pluginScanInstallConfirm')}
|
||||
</Button>
|
||||
</>
|
||||
) : (
|
||||
<Button variant="primary" onClick={() => setScanModal(null)}>{tr('pluginDone')}</Button>
|
||||
)}
|
||||
<Button variant="ghost" disabled={scanBusy} onClick={() => setScanModal(null)}>{tr('cancel')}</Button>
|
||||
<Button
|
||||
variant="primary"
|
||||
disabled={scanBusy || scanModal.report.hard_blocked}
|
||||
onClick={() => void confirmInstallScannedArchive()}
|
||||
>
|
||||
{scanModal.report.hard_blocked ? tr('pluginScanBlockedBtn') : tr('pluginScanInstallConfirm')}
|
||||
</Button>
|
||||
</span>
|
||||
</div>
|
||||
</Modal>
|
||||
@@ -909,7 +875,7 @@ export const PluginsPage: React.FC<Props> = ({
|
||||
</Modal>
|
||||
)}
|
||||
|
||||
{settingsTarget && settingsTarget.settings && (
|
||||
{settingsTarget && (
|
||||
<Modal
|
||||
title={locText(settingsTarget.name, locale, settingsTarget.id)}
|
||||
subtitle={tr('pluginGlobalSettings')}
|
||||
@@ -923,13 +889,27 @@ export const PluginsPage: React.FC<Props> = ({
|
||||
<span>{settingsRuntimeWarning}</span>
|
||||
</div>
|
||||
)}
|
||||
<SchemaForm
|
||||
locale={locale}
|
||||
schema={settingsTarget.settings}
|
||||
values={settingsValues}
|
||||
scopeFilter="app"
|
||||
onChange={(_, patch) => void savePluginSettings(patch)}
|
||||
/>
|
||||
{hasAppSettings(settingsTarget) && (
|
||||
<SchemaForm
|
||||
locale={locale}
|
||||
schema={settingsTarget.settings!}
|
||||
values={settingsValues}
|
||||
scopeFilter="app"
|
||||
onChange={(_, patch) => void savePluginSettings(patch)}
|
||||
/>
|
||||
)}
|
||||
{settingsPanelsOf(settingsTarget.id).map((panel) => (
|
||||
<PluginPanelFrame
|
||||
key={panel.id}
|
||||
locale={locale}
|
||||
panel={panel}
|
||||
assetToken={contribs!.asset_token!}
|
||||
appearance={appearance}
|
||||
// Both lead out of this dialog, so it must not stay on top.
|
||||
onOpenView={onOpenView && ((view, vm) => { setSettingsTarget(null); onOpenView(view, vm) })}
|
||||
onNavigate={onNavigate && ((target) => { setSettingsTarget(null); onNavigate(target) })}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
<div className="dialog-foot">
|
||||
<span />
|
||||
@@ -987,18 +967,6 @@ export const PluginsPage: React.FC<Props> = ({
|
||||
/>
|
||||
)}
|
||||
|
||||
{logTarget && (
|
||||
<Modal
|
||||
title={tr('pluginLogTitle', { id: logTarget.id })}
|
||||
closeLabel={tr('close')}
|
||||
onClose={() => setLogTarget(null)}
|
||||
>
|
||||
<div className="dialog-body">
|
||||
<pre className="plugin-log-pre mono selectable">{logTarget.text}</pre>
|
||||
</div>
|
||||
</Modal>
|
||||
)}
|
||||
|
||||
{schemeEditorOpen && (
|
||||
<Modal
|
||||
title={tr('pluginSchemeModalTitle')}
|
||||
|
||||
@@ -34,7 +34,6 @@ export const pluginsZh: Record<string, string> = {
|
||||
"pluginFailLoadSettings": "读取插件设置失败",
|
||||
"pluginFailMarketInstall": "安装市场插件失败",
|
||||
"pluginFailMarketLoad": "加载插件市场失败",
|
||||
"pluginFailReadLog": "读取插件日志失败",
|
||||
"pluginFailRemove": "卸载插件失败",
|
||||
"pluginFailSaveScheme": "保存配色方案失败",
|
||||
"pluginFailSaveSettings": "保存插件设置失败",
|
||||
@@ -48,8 +47,6 @@ export const pluginsZh: Record<string, string> = {
|
||||
"pluginInUse": "使用中不可卸载",
|
||||
"pluginLinkDevBtn": "链接插件开发目录",
|
||||
"pluginLinkDevTitle": "链接本地开发插件目录",
|
||||
"pluginLogEmpty": "暂无日志记录",
|
||||
"pluginLogTitle": "{id} — 日志",
|
||||
"pluginMarketAlphaTag": "Alpha",
|
||||
"pluginMarketCurrentVersion": "当前已安装",
|
||||
"pluginMarketDownloading": "下载中",
|
||||
@@ -84,7 +81,6 @@ export const pluginsZh: Record<string, string> = {
|
||||
"pluginMarketWithdrawnInstalledWarn": "已安装插件 {id} 已从市场撤回:{reason}",
|
||||
"pluginMarketWithdrawnInstead": "建议改用:{target}",
|
||||
"pluginNewScheme": "新建配色方案",
|
||||
"pluginPanelsSection": "插件面板",
|
||||
"pluginPermCount": "{count, plural, other {# 项权限}}",
|
||||
"pluginPermissionsLabel": "权限:{list}",
|
||||
"pluginPublisherLicense": "发布者 / 许可",
|
||||
@@ -103,9 +99,7 @@ export const pluginsZh: Record<string, string> = {
|
||||
"pluginScanBlockedBtn": "已拦截,无法安装",
|
||||
"pluginScanCapabilitiesSection": "能力与权限说明",
|
||||
"pluginScanHardSection": "硬性拦截项(禁止安装)",
|
||||
"pluginScanInspect": "安全扫描",
|
||||
"pluginScanInstallConfirm": "确认导入安装",
|
||||
"pluginScanModalTitle": "插件静态安全报告",
|
||||
"pluginScanMoreItems": "另有 {count} 项已折叠",
|
||||
"pluginSchemeDefault": "默认",
|
||||
"pluginSchemeModalTitle": "新建配色方案",
|
||||
@@ -130,7 +124,6 @@ export const pluginsZh: Record<string, string> = {
|
||||
"pluginTrustDev": "开发",
|
||||
"pluginTrustOfficial": "官方",
|
||||
"pluginTrustVerified": "已审核",
|
||||
"pluginViewLog": "查看日志",
|
||||
}
|
||||
|
||||
export const pluginsEn: Record<string, string> = {
|
||||
@@ -166,7 +159,6 @@ export const pluginsEn: Record<string, string> = {
|
||||
"pluginFailLoadSettings": "Couldn’t load plugin settings",
|
||||
"pluginFailMarketInstall": "Couldn’t install plugin from market",
|
||||
"pluginFailMarketLoad": "Couldn’t load plugin market",
|
||||
"pluginFailReadLog": "Couldn’t read plugin log",
|
||||
"pluginFailRemove": "Couldn’t remove plugin",
|
||||
"pluginFailSaveScheme": "Couldn’t save color scheme",
|
||||
"pluginFailSaveSettings": "Couldn’t save plugin settings",
|
||||
@@ -180,8 +172,6 @@ export const pluginsEn: Record<string, string> = {
|
||||
"pluginInUse": "In use",
|
||||
"pluginLinkDevBtn": "Link plugin dev folder",
|
||||
"pluginLinkDevTitle": "Link local dev plugin folder",
|
||||
"pluginLogEmpty": "No log entries yet",
|
||||
"pluginLogTitle": "{id} — Log",
|
||||
"pluginMarketAlphaTag": "Alpha",
|
||||
"pluginMarketCurrentVersion": "Installed",
|
||||
"pluginMarketDownloading": "Downloading",
|
||||
@@ -216,7 +206,6 @@ export const pluginsEn: Record<string, string> = {
|
||||
"pluginMarketWithdrawnInstalledWarn": "Installed plugin {id} has been withdrawn: {reason}",
|
||||
"pluginMarketWithdrawnInstead": "Recommended replacement: {target}",
|
||||
"pluginNewScheme": "New scheme",
|
||||
"pluginPanelsSection": "Plugin panels",
|
||||
"pluginPermCount": "{count, plural, one {# permission} other {# permissions}}",
|
||||
"pluginPermissionsLabel": "Permissions: {list}",
|
||||
"pluginPublisherLicense": "Publisher / License",
|
||||
@@ -235,9 +224,7 @@ export const pluginsEn: Record<string, string> = {
|
||||
"pluginScanBlockedBtn": "Blocked — cannot install",
|
||||
"pluginScanCapabilitiesSection": "Capabilities \u0026 privileges",
|
||||
"pluginScanHardSection": "Hard blockers (install refused)",
|
||||
"pluginScanInspect": "Security scan",
|
||||
"pluginScanInstallConfirm": "Proceed with install",
|
||||
"pluginScanModalTitle": "Plugin security report",
|
||||
"pluginScanMoreItems": "...and {count} more",
|
||||
"pluginSchemeDefault": "Default",
|
||||
"pluginSchemeModalTitle": "New color scheme",
|
||||
@@ -262,7 +249,6 @@ export const pluginsEn: Record<string, string> = {
|
||||
"pluginTrustDev": "Dev",
|
||||
"pluginTrustOfficial": "Official",
|
||||
"pluginTrustVerified": "Verified",
|
||||
"pluginViewLog": "View log",
|
||||
}
|
||||
|
||||
registerBuiltinDomain(pluginsZh, pluginsEn)
|
||||
@@ -771,7 +771,6 @@ export type I18nKey =
|
||||
| "pluginFailLoadSettings"
|
||||
| "pluginFailMarketInstall"
|
||||
| "pluginFailMarketLoad"
|
||||
| "pluginFailReadLog"
|
||||
| "pluginFailRemove"
|
||||
| "pluginFailSaveScheme"
|
||||
| "pluginFailSaveSettings"
|
||||
@@ -785,8 +784,6 @@ export type I18nKey =
|
||||
| "pluginInUse"
|
||||
| "pluginLinkDevBtn"
|
||||
| "pluginLinkDevTitle"
|
||||
| "pluginLogEmpty"
|
||||
| "pluginLogTitle"
|
||||
| "pluginMarketAlphaTag"
|
||||
| "pluginMarketCurrentVersion"
|
||||
| "pluginMarketDownloading"
|
||||
@@ -821,7 +818,6 @@ export type I18nKey =
|
||||
| "pluginMarketWithdrawnInstalledWarn"
|
||||
| "pluginMarketWithdrawnInstead"
|
||||
| "pluginNewScheme"
|
||||
| "pluginPanelsSection"
|
||||
| "pluginPermCount"
|
||||
| "pluginPermissionsLabel"
|
||||
| "pluginPublisherLicense"
|
||||
@@ -841,9 +837,7 @@ export type I18nKey =
|
||||
| "pluginScanBlockedBtn"
|
||||
| "pluginScanCapabilitiesSection"
|
||||
| "pluginScanHardSection"
|
||||
| "pluginScanInspect"
|
||||
| "pluginScanInstallConfirm"
|
||||
| "pluginScanModalTitle"
|
||||
| "pluginScanMoreItems"
|
||||
| "pluginSchemeDefault"
|
||||
| "pluginSchemeModalTitle"
|
||||
@@ -868,7 +862,6 @@ export type I18nKey =
|
||||
| "pluginTrustDev"
|
||||
| "pluginTrustOfficial"
|
||||
| "pluginTrustVerified"
|
||||
| "pluginViewLog"
|
||||
| "qemuASLR"
|
||||
| "qemuASLRHint"
|
||||
| "quitFailed"
|
||||
|
||||
@@ -980,6 +980,7 @@ button.status-issue + .status-metric { margin-left: 6px; }
|
||||
border: 1px solid var(--border-strong); color: var(--text);
|
||||
font-size: var(--fs-12); box-shadow: 0 8px 22px rgba(15, 23, 42, 0.16);
|
||||
display: flex; gap: var(--sp-2); align-items: center;
|
||||
max-width: min(420px, calc(100vw - 16px)); white-space: pre-line; overflow-wrap: anywhere;
|
||||
transform-origin: var(--radix-tooltip-content-transform-origin);
|
||||
}
|
||||
.tooltip kbd { font-family: var(--font-sans); color: var(--text-3); }
|
||||
@@ -1946,10 +1947,6 @@ button.status-issue + .status-metric { margin-left: 6px; }
|
||||
|
||||
/* What a plugin can do, shown before enabling it */
|
||||
.plugin-enable-lead { margin: 0; font-size: var(--fs-13); color: var(--text-2); }
|
||||
.plugin-log-pre {
|
||||
margin: 0; font-size: var(--fs-12); line-height: 1.55;
|
||||
white-space: pre-wrap; word-break: break-word;
|
||||
}
|
||||
.plugin-risk-list {
|
||||
margin: 0; padding: 4px 0; list-style: none;
|
||||
background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r-lg);
|
||||
|
||||
Vendored
-2
@@ -216,8 +216,6 @@ export function PreviewCreate(arg1:reims.CreateOpts):Promise<string>;
|
||||
|
||||
export function QuitApp():Promise<void>;
|
||||
|
||||
export function ReadPluginLog(arg1:string):Promise<string>;
|
||||
|
||||
export function ReadVMLogs(arg1:string,arg2:string,arg3:boolean):Promise<string>;
|
||||
|
||||
export function RemovePlugin(arg1:string,arg2:boolean):Promise<void>;
|
||||
|
||||
@@ -410,10 +410,6 @@ export function QuitApp() {
|
||||
return window['go']['app']['App']['QuitApp']();
|
||||
}
|
||||
|
||||
export function ReadPluginLog(arg1) {
|
||||
return window['go']['app']['App']['ReadPluginLog'](arg1);
|
||||
}
|
||||
|
||||
export function ReadVMLogs(arg1, arg2, arg3) {
|
||||
return window['go']['app']['App']['ReadVMLogs'](arg1, arg2, arg3);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -124,6 +123,7 @@ func (a *App) initPlugins() {
|
||||
})
|
||||
mgr.Broker().SetVMExitHandler(func(string, string) { a.wakePoll() })
|
||||
|
||||
mgr.Broker().SetLogger(a.emitLog)
|
||||
mgr.Broker().SetNotifier(func(pluginID, title, body string) {
|
||||
a.emitLog("plugin:"+pluginID, title+": "+body)
|
||||
})
|
||||
@@ -919,43 +919,6 @@ func (a *App) CreateVMWithDriver(req driver.CreateRequest) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) ReadPluginLog(pluginID string) (string, error) {
|
||||
a.mu.Lock()
|
||||
mgr := a.pluginMgr
|
||||
a.mu.Unlock()
|
||||
if mgr == nil {
|
||||
return "", nil
|
||||
}
|
||||
if pluginID == "" || strings.ContainsAny(pluginID, `/\`) || strings.Contains(pluginID, "..") {
|
||||
return "", errors.New("invalid plugin id")
|
||||
}
|
||||
if _, ok := mgr.Registry().Info(pluginID); !ok {
|
||||
return "", fmt.Errorf("plugin %q not found", pluginID)
|
||||
}
|
||||
logsDir := filepath.Clean(mgr.Layout().LogsDir())
|
||||
logPath := filepath.Clean(mgr.Layout().LogPath(pluginID))
|
||||
if !strings.HasPrefix(strings.ToLower(logPath), strings.ToLower(logsDir+string(os.PathSeparator))) {
|
||||
return "", errors.New("invalid plugin log path")
|
||||
}
|
||||
f, err := os.Open(logPath)
|
||||
if err != nil {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
return "", nil
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
defer f.Close()
|
||||
const maxLogReadBytes = 2 << 20
|
||||
if st, statErr := f.Stat(); statErr == nil && st.Size() > maxLogReadBytes {
|
||||
_, _ = f.Seek(st.Size()-maxLogReadBytes, io.SeekStart)
|
||||
}
|
||||
raw, err := io.ReadAll(io.LimitReader(f, maxLogReadBytes))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return host.RedactText(string(raw)), nil
|
||||
}
|
||||
|
||||
// InspectPluginArchive runs the unified static security scanner on a local .zip
|
||||
// package before installing it so the UI can display hard blockers, capabilities,
|
||||
// and L3 native execution notices.
|
||||
|
||||
@@ -46,6 +46,7 @@ type Broker struct {
|
||||
// VMs being spawned right now, so two requests cannot both start one.
|
||||
spawning map[string]bool
|
||||
onNotify func(pluginID, title, body string)
|
||||
onLog func(source, line string)
|
||||
onVMExit func(driverID, vmName string)
|
||||
onVMState func(pluginID string, rep ReportedVMState) error
|
||||
}
|
||||
@@ -75,6 +76,10 @@ func (b *Broker) SetNotifier(fn func(pluginID, title, body string)) {
|
||||
b.mu.Unlock()
|
||||
}
|
||||
|
||||
// SetLogger registers the app log that Audit also writes to. Call it before any
|
||||
// plugin starts.
|
||||
func (b *Broker) SetLogger(fn func(source, line string)) { b.onLog = fn }
|
||||
|
||||
// SetVMExitHandler registers a callback fired once the last process of a
|
||||
// driver-spawned VM has exited (not merely its launcher).
|
||||
func (b *Broker) SetVMExitHandler(fn func(driverID, vmName string)) {
|
||||
@@ -271,13 +276,13 @@ func (b *Broker) AllowRate(pluginID string) error {
|
||||
// hostCallsPerSecond is how many Host API calls one plugin may make per second.
|
||||
const hostCallsPerSecond = 120
|
||||
|
||||
func (b *Broker) allowRate(pluginID string) bool {
|
||||
func (b *Broker) allowRate(key string) bool {
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
now := time.Now()
|
||||
rw := b.rates[pluginID]
|
||||
rw := b.rates[key]
|
||||
if rw == nil || now.Sub(rw.windowStart) >= time.Second {
|
||||
b.rates[pluginID] = &rateWindow{windowStart: now, count: 1}
|
||||
b.rates[key] = &rateWindow{windowStart: now, count: 1}
|
||||
return true
|
||||
}
|
||||
if rw.count >= hostCallsPerSecond {
|
||||
@@ -287,8 +292,15 @@ func (b *Broker) allowRate(pluginID string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// fileOnlyTags are audit entries left out of the app log: successful routine
|
||||
// calls would push everything else out of it, and notifications already reach it
|
||||
// through the notifier.
|
||||
var fileOnlyTags = map[string]bool{
|
||||
"HOST_API": true, "PANEL_CMD": true, "PANEL_UI": true, "CHANNEL_MESSAGE": true, "VM_STATE": true, "NOTIFY": true,
|
||||
}
|
||||
|
||||
// Audit appends a redacted audit or stderr line to `<DataRoot>/plugins/logs/<id>.log`
|
||||
// with automatic rotation at 2 MiB (§6.1).
|
||||
// with automatic rotation at 2 MiB (§6.1), and to the app log as `plugin:<id>`.
|
||||
func (b *Broker) Audit(pluginID, tag, msg string) {
|
||||
if b == nil || b.layout.Root == "" || pluginID == "" {
|
||||
return
|
||||
@@ -303,6 +315,12 @@ func (b *Broker) Audit(pluginID, tag, msg string) {
|
||||
safeMsg := b.redactFn(trimmed)
|
||||
line := fmt.Sprintf("%s [%s] %s\n", time.Now().UTC().Format(time.RFC3339), tag, safeMsg)
|
||||
|
||||
// The app log has its own rate window, so a chatty plugin can't flood it. Line
|
||||
// breaks are folded so plugin text can't pose as another source's entry.
|
||||
if b.onLog != nil && !fileOnlyTags[tag] && b.allowRate("log:"+pluginID) {
|
||||
b.onLog("plugin:"+pluginID, "["+tag+"] "+strings.NewReplacer("\r", "", "\n", " ").Replace(safeMsg))
|
||||
}
|
||||
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
if err := os.MkdirAll(b.layout.LogsDir(), 0o755); err != nil {
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAuditMirrorsPluginOutputToAppLog(t *testing.T) {
|
||||
layout := NewPluginsLayout(t.TempDir())
|
||||
broker := NewBroker(layout, nil, func(s string) string { return strings.ReplaceAll(s, "secret", "***") })
|
||||
var got []string
|
||||
broker.SetLogger(func(source, line string) { got = append(got, source+" "+line) })
|
||||
|
||||
broker.Audit("vendor.demo", "STDERR", "secret one\r\n12:00:00 [host] two")
|
||||
broker.Audit("vendor.demo", "HOST_API", "host/vm.list")
|
||||
|
||||
want := "plugin:vendor.demo [STDERR] *** one 12:00:00 [host] two"
|
||||
if len(got) != 1 || got[0] != want {
|
||||
t.Fatalf("app log = %q, want only %q", got, want)
|
||||
}
|
||||
file, err := os.ReadFile(layout.LogPath("vendor.demo"))
|
||||
if err != nil || !strings.Contains(string(file), "host/vm.list") {
|
||||
t.Fatalf("audit file must keep routine entries: %q, %v", file, err)
|
||||
}
|
||||
|
||||
for range 2 * hostCallsPerSecond {
|
||||
broker.Audit("vendor.demo", "STDERR", "spam")
|
||||
}
|
||||
if len(got) >= 2*hostCallsPerSecond {
|
||||
t.Fatalf("%d lines reached the app log; spam must be limited", len(got))
|
||||
}
|
||||
}
|
||||
@@ -12,8 +12,6 @@
|
||||
"pluginFailRemove": "Couldn’t remove plugin",
|
||||
"pluginFailLoadSettings": "Couldn’t load plugin settings",
|
||||
"pluginFailSaveSettings": "Couldn’t save plugin settings",
|
||||
"pluginLogEmpty": "No log entries yet",
|
||||
"pluginFailReadLog": "Couldn’t read plugin log",
|
||||
"pluginFailSwitchTheme": "Couldn’t switch theme",
|
||||
"pluginFailSaveScheme": "Couldn’t save color scheme",
|
||||
"pluginFailDeleteScheme": "Couldn’t delete color scheme",
|
||||
@@ -26,7 +24,6 @@
|
||||
"pluginStatePending": "Pending",
|
||||
"pluginPermissionsLabel": "Permissions: {list}",
|
||||
"pluginHighRiskNotice": "Contains high-risk permissions; approval required before enabling",
|
||||
"pluginViewLog": "View log",
|
||||
"pluginInUse": "In use",
|
||||
"pluginDisable": "Disable",
|
||||
"pluginDisableInUseTitle": "Disable a plugin that still has VMs",
|
||||
@@ -45,7 +42,6 @@
|
||||
"pluginSubmitBtn": "Submit plugin",
|
||||
"pluginImportBtn": "Import plugin",
|
||||
"pluginBuiltinSection": "Built-in plugins",
|
||||
"pluginPanelsSection": "Plugin panels",
|
||||
"pluginApproveTitle": "Approve high-risk permissions",
|
||||
"pluginApproveL3Warn": "This plugin runs native code (L3 Sidecar) and can perform arbitrary actions as your Windows user",
|
||||
"pluginApproveUIScriptWarn": "This plugin runs an interactive script (ui:script) inside the main window with full access to the interface; verify its source and SHA-256 before enabling",
|
||||
@@ -55,7 +51,6 @@
|
||||
"pluginApproveCheckbox": "I have reviewed the source and permissions and confirm enabling this plugin",
|
||||
"pluginApproveConfirm": "Confirm enable",
|
||||
"pluginDone": "Done",
|
||||
"pluginLogTitle": "{id} — Log",
|
||||
"pluginSchemeModalTitle": "New color scheme",
|
||||
"pluginSchemeName": "Scheme name",
|
||||
"pluginSchemePlaceholder": "e.g. Soft Blue",
|
||||
@@ -86,8 +81,6 @@
|
||||
"pluginMarketKindTool": "Tools",
|
||||
"pluginFailMarketLoad": "Couldn’t load plugin market",
|
||||
"pluginFailMarketInstall": "Couldn’t install plugin from market",
|
||||
"pluginScanInspect": "Security scan",
|
||||
"pluginScanModalTitle": "Plugin security report",
|
||||
"pluginScanArchiveTitle": "Pre-install security check",
|
||||
"pluginScanHardSection": "Hard blockers (install refused)",
|
||||
"pluginScanCapabilitiesSection": "Capabilities & privileges",
|
||||
|
||||
@@ -12,8 +12,6 @@
|
||||
"pluginFailRemove": "卸载插件失败",
|
||||
"pluginFailLoadSettings": "读取插件设置失败",
|
||||
"pluginFailSaveSettings": "保存插件设置失败",
|
||||
"pluginLogEmpty": "暂无日志记录",
|
||||
"pluginFailReadLog": "读取插件日志失败",
|
||||
"pluginFailSwitchTheme": "切换主题失败",
|
||||
"pluginFailSaveScheme": "保存配色方案失败",
|
||||
"pluginFailDeleteScheme": "删除配色方案失败",
|
||||
@@ -26,7 +24,6 @@
|
||||
"pluginStatePending": "等待依赖",
|
||||
"pluginPermissionsLabel": "权限:{list}",
|
||||
"pluginHighRiskNotice": "包含高危权限,启用前需确认",
|
||||
"pluginViewLog": "查看日志",
|
||||
"pluginInUse": "使用中不可卸载",
|
||||
"pluginDisable": "停用",
|
||||
"pluginDisableInUseTitle": "停用仍有虚拟机的插件",
|
||||
@@ -45,7 +42,6 @@
|
||||
"pluginSubmitBtn": "上架插件",
|
||||
"pluginImportBtn": "导入插件",
|
||||
"pluginBuiltinSection": "内置插件",
|
||||
"pluginPanelsSection": "插件面板",
|
||||
"pluginApproveTitle": "高危权限确认",
|
||||
"pluginApproveL3Warn": "此插件为原生可执行程序(L3 Sidecar),能够以当前 Windows 账户身份执行任意操作",
|
||||
"pluginApproveUIScriptWarn": "此插件包含交互界面脚本(ui:script),会在主窗口界面中运行并可访问页面内容,启用前务必核对来源与脚本 SHA-256",
|
||||
@@ -55,7 +51,6 @@
|
||||
"pluginApproveCheckbox": "我已核对来源与权限,确认启用此插件",
|
||||
"pluginApproveConfirm": "确认启用",
|
||||
"pluginDone": "完成",
|
||||
"pluginLogTitle": "{id} — 日志",
|
||||
"pluginSchemeModalTitle": "新建配色方案",
|
||||
"pluginSchemeName": "方案名称",
|
||||
"pluginSchemePlaceholder": "如:柔蓝",
|
||||
@@ -86,8 +81,6 @@
|
||||
"pluginMarketKindTool": "工具",
|
||||
"pluginFailMarketLoad": "加载插件市场失败",
|
||||
"pluginFailMarketInstall": "安装市场插件失败",
|
||||
"pluginScanInspect": "安全扫描",
|
||||
"pluginScanModalTitle": "插件静态安全报告",
|
||||
"pluginScanArchiveTitle": "导入前安全检查",
|
||||
"pluginScanHardSection": "硬性拦截项(禁止安装)",
|
||||
"pluginScanCapabilitiesSection": "能力与权限说明",
|
||||
|
||||
Reference in new issue
Block a user