mirror of
https://github.com/yexi-by/dsh-unrestricted.git
synced 2026-11-28 02:30:22 +08:00
精简:移除重复的插件更新器
This commit is contained in:
1 parent
35e3e7d9bc
commit
1b4d8b9205
18 files changed
+223
-1467
No files matched your search
@@ -1,8 +1,7 @@
|
||||
/**
|
||||
* The unrestricted settings view and plugin-detail badge:
|
||||
* The unrestricted settings view:
|
||||
* - Master toggle card with native Switch, status Tag, and scope boundary notes
|
||||
* - Per-preset coverage list with StateDot, Tag, preview drawer, and one-click copy
|
||||
* - Version & Updates card with automatic release check and one-click self-update
|
||||
*/
|
||||
import { useEffect, useState } from 'react'
|
||||
import {
|
||||
@@ -21,7 +20,6 @@ import type {
|
||||
UnrestrictedCardInjected,
|
||||
UnrestrictedModeState,
|
||||
UnrestrictedPreviewEntry,
|
||||
UnrestrictedUpdateInfo,
|
||||
} from './controller.ts'
|
||||
import type { UnrestrictedLocaleKey } from './locales.ts'
|
||||
|
||||
@@ -31,12 +29,6 @@ export type UnrestrictedCardProps =
|
||||
& PropsLocale<'settings.unrestricted'>
|
||||
& InjectFace<UnrestrictedCardInjected>
|
||||
|
||||
/** Detail badge props assembled by the Plugin Manager header slot renderer. */
|
||||
export type UnrestrictedDetailBadgeProps =
|
||||
PropsRuntime<'plugins.detail.badge'>
|
||||
& PropsLocale<'settings.unrestricted'>
|
||||
& InjectFace<UnrestrictedCardInjected>
|
||||
|
||||
/** Mode rows in display order, with their locale label and description keys. */
|
||||
const MODE_ROWS: ReadonlyArray<{
|
||||
id: string
|
||||
@@ -107,85 +99,17 @@ function localizePreviewError(
|
||||
: t('errorPreviewFailed')
|
||||
}
|
||||
|
||||
/** Friendly localized text for update errors. */
|
||||
function localizeUpdateError(
|
||||
update: UnrestrictedUpdateInfo,
|
||||
t: (key: UnrestrictedLocaleKey) => string,
|
||||
): string {
|
||||
switch (update.errorCode) {
|
||||
case 'update-check-failed':
|
||||
return t('errorUpdateCheckFailed')
|
||||
case 'update-no-profile':
|
||||
return t('errorUpdateNoProfile')
|
||||
case 'update-file-source-outdated':
|
||||
return t('errorUpdateFileOutdated')
|
||||
case 'update-install-failed':
|
||||
return `${t('errorUpdateInstallFailed')}${update.errorDetail ?? ''}`
|
||||
default:
|
||||
return update.errorDetail !== undefined && update.errorDetail !== ''
|
||||
? `${t('operationFailed')}${update.errorDetail}`
|
||||
: t('errorUpdateCheckFailed')
|
||||
}
|
||||
}
|
||||
|
||||
/** Friendly label for the installation source. */
|
||||
function installSourceLabel(
|
||||
source: UnrestrictedUpdateInfo['installSource'],
|
||||
t: (key: UnrestrictedLocaleKey) => string,
|
||||
): string {
|
||||
switch (source) {
|
||||
case 'github': return t('sourceGithub')
|
||||
case 'file': return t('sourceFile')
|
||||
case 'registry': return t('sourceRegistry')
|
||||
default: return t('sourceUnknown')
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Badge shown in the Plugin Manager detail header when an update is available
|
||||
* or waiting for a restart.
|
||||
*/
|
||||
export function UnrestrictedDetailBadge(props: UnrestrictedDetailBadgeProps) {
|
||||
const { subject, t, checkUpdate } = props
|
||||
const update = props.useView(snapshot => snapshot.update)
|
||||
const isTargetBundle = subject.kind === 'bundle' && subject.pkg.name === 'dsh-unrestricted'
|
||||
|
||||
useEffect(() => {
|
||||
if (isTargetBundle && update.state === 'idle') {
|
||||
void checkUpdate(false)
|
||||
}
|
||||
}, [isTargetBundle, update.state, checkUpdate])
|
||||
|
||||
if (!isTargetBundle) return null
|
||||
if (update.state === 'available') {
|
||||
const versionSuffix = update.latestVersion !== undefined ? ` v${update.latestVersion}` : ''
|
||||
return <Tag tone="info">{`${t('updateBadge')}${versionSuffix}`}</Tag>
|
||||
}
|
||||
if (update.state === 'updated' || update.restartRequired === true) {
|
||||
return <Tag tone="success">{t('updateRestartBadge')}</Tag>
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the unrestricted configuration cards.
|
||||
*/
|
||||
export function UnrestrictedCard(props: UnrestrictedCardProps) {
|
||||
const { t, loadPreview, checkUpdate } = props
|
||||
const { t, loadPreview } = props
|
||||
const view = props.useView(snapshot => snapshot)
|
||||
const status = view.status
|
||||
const update = view.update
|
||||
const [openPreview, setOpenPreview] = useState<string | null>(null)
|
||||
const [copiedPreset, setCopiedPreset] = useState<string | null>(null)
|
||||
const openEntry = openPreview === null ? undefined : view.previews[openPreview]
|
||||
|
||||
// Automatically check for updates once when the configuration view opens.
|
||||
useEffect(() => {
|
||||
if (update.state === 'idle') {
|
||||
void checkUpdate(false)
|
||||
}
|
||||
}, [update.state, checkUpdate])
|
||||
|
||||
// When a refresh/toggle invalidates the preview map while a preview drawer
|
||||
// is open, automatically reload that preset's preview.
|
||||
useEffect(() => {
|
||||
@@ -241,28 +165,8 @@ export function UnrestrictedCard(props: UnrestrictedCardProps) {
|
||||
.join(';')
|
||||
}
|
||||
|
||||
const updateBusy = update.state === 'checking' || update.state === 'updating'
|
||||
const updateTagTone: TagTone = update.state === 'available'
|
||||
? 'info'
|
||||
: update.state === 'updated'
|
||||
? 'success'
|
||||
: update.state === 'failed'
|
||||
? 'danger'
|
||||
: 'neutral'
|
||||
const updateTagKey: UnrestrictedLocaleKey = update.state === 'checking'
|
||||
? 'updateChecking'
|
||||
: update.state === 'updating'
|
||||
? 'updateInstalling'
|
||||
: update.state === 'available'
|
||||
? 'updateAvailable'
|
||||
: update.state === 'updated'
|
||||
? 'updateRestartBadge'
|
||||
: update.state === 'up-to-date'
|
||||
? 'updateUpToDate'
|
||||
: 'updateIdle'
|
||||
|
||||
return (
|
||||
<div className="dsh-unrestricted-root" aria-busy={view.busy || updateBusy}>
|
||||
<div className="dsh-unrestricted-root" aria-busy={view.busy}>
|
||||
{/* Card 1: Master Toggle */}
|
||||
<section className="dsh-unrestricted-card" aria-labelledby="dsh-unrestricted-main-title">
|
||||
<div className="dsh-unrestricted-header">
|
||||
@@ -387,86 +291,6 @@ export function UnrestrictedCard(props: UnrestrictedCardProps) {
|
||||
<p className="dsh-unrestricted-note">{t('subagentNote')}</p>
|
||||
</section>
|
||||
|
||||
{/* Card 3: Version & Updates */}
|
||||
<section className="dsh-unrestricted-card" aria-labelledby="dsh-unrestricted-update-title">
|
||||
<div className="dsh-unrestricted-header">
|
||||
<div className="dsh-unrestricted-headerTitle">
|
||||
<h4 id="dsh-unrestricted-update-title" className="dsh-unrestricted-subtitle">{t('updateTitle')}</h4>
|
||||
{update.state !== 'failed' && (
|
||||
<Tag tone={updateTagTone}>
|
||||
{update.state === 'available' && update.latestVersion !== undefined
|
||||
? `${t('updateAvailable')} v${update.latestVersion}`
|
||||
: t(updateTagKey)}
|
||||
</Tag>
|
||||
)}
|
||||
</div>
|
||||
<div className="dsh-unrestricted-headerControls">
|
||||
{update.releaseUrl !== undefined && (
|
||||
<a
|
||||
className="dsh-unrestricted-link"
|
||||
href={update.releaseUrl}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
>
|
||||
{t('viewRelease')}
|
||||
</a>
|
||||
)}
|
||||
{update.state === 'available' && (
|
||||
<Button
|
||||
variant="primary"
|
||||
size="sm"
|
||||
disabled={updateBusy}
|
||||
onClick={() => { void props.performUpdate() }}
|
||||
>
|
||||
{update.latestVersion !== undefined
|
||||
? `${t('installUpdate')} (v${update.latestVersion})`
|
||||
: t('installUpdate')}
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
disabled={updateBusy}
|
||||
onClick={() => { void props.checkUpdate(true) }}
|
||||
>
|
||||
{t('checkUpdate')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<dl className="dsh-unrestricted-metaGrid">
|
||||
<div className="dsh-unrestricted-metaItem">
|
||||
<dt>{t('currentVersion')}</dt>
|
||||
<dd className="dsh-unrestricted-mono">{`v${update.currentVersion}`}</dd>
|
||||
</div>
|
||||
<div className="dsh-unrestricted-metaItem">
|
||||
<dt>{t('latestVersion')}</dt>
|
||||
<dd className="dsh-unrestricted-mono">
|
||||
{update.latestVersion !== undefined ? `v${update.latestVersion}` : '—'}
|
||||
</dd>
|
||||
</div>
|
||||
<div className="dsh-unrestricted-metaItem">
|
||||
<dt>{t('installSource')}</dt>
|
||||
<dd title={update.dependencySpec}>{installSourceLabel(update.installSource, t)}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
|
||||
{update.state === 'updating' && (
|
||||
<p className="dsh-unrestricted-banner" data-tone="info" role="status">
|
||||
{t('updateInstalling')}
|
||||
</p>
|
||||
)}
|
||||
{(update.state === 'updated' || update.restartRequired === true) && (
|
||||
<p className="dsh-unrestricted-banner" data-tone="success" role="status">
|
||||
{t('updateInstalled')}
|
||||
</p>
|
||||
)}
|
||||
{update.state === 'failed' && (
|
||||
<p className="dsh-unrestricted-banner" data-tone="error" role="alert">
|
||||
{localizeUpdateError(update, t)}
|
||||
</p>
|
||||
)}
|
||||
</section>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
+2
-101
@@ -1,7 +1,6 @@
|
||||
/**
|
||||
* Browser-half controller for the unrestricted card: binds the `unrestricted`
|
||||
* settings namespace (the toggle), reads per-preset fusion state and previews,
|
||||
* and manages version checks and self-updates via the host half's private RPC.
|
||||
* settings namespace (the toggle) and reads per-preset state and previews.
|
||||
*/
|
||||
import type { Context } from '@deepseek-ai/cordis'
|
||||
import type { ConnectionHandle } from '@deepseek-ai/dsh-client-connection/client'
|
||||
@@ -21,30 +20,12 @@ export interface UnrestrictedModeState {
|
||||
issues: string[]
|
||||
}
|
||||
|
||||
/** Version and update status reported by the host half. */
|
||||
export interface UnrestrictedUpdateInfo {
|
||||
state: 'idle' | 'checking' | 'up-to-date' | 'available' | 'updating' | 'updated' | 'failed'
|
||||
currentVersion: string
|
||||
latestVersion?: string
|
||||
latestTag?: string
|
||||
updatedVersion?: string
|
||||
releaseUrl?: string
|
||||
publishedAt?: string
|
||||
checkedAt?: string
|
||||
installSource?: 'github' | 'file' | 'registry' | 'unknown'
|
||||
dependencySpec?: string
|
||||
restartRequired?: boolean
|
||||
errorCode?: string
|
||||
errorDetail?: string
|
||||
}
|
||||
|
||||
/** Host status endpoint payload. */
|
||||
export interface UnrestrictedStatus {
|
||||
enabled: boolean
|
||||
/** Current plugin version reported by the host half. */
|
||||
version?: string
|
||||
modes: Record<string, UnrestrictedModeState>
|
||||
update?: UnrestrictedUpdateInfo
|
||||
}
|
||||
|
||||
/** Deploy preview for one preset: what switching on would actually assemble. */
|
||||
@@ -81,8 +62,6 @@ export interface UnrestrictedViewSnapshot {
|
||||
settingsStatus: 'loading' | 'ready' | 'unavailable'
|
||||
/** Live host status; null until the first RPC answer. */
|
||||
status: UnrestrictedStatus | null
|
||||
/** Version and update check state. */
|
||||
update: UnrestrictedUpdateInfo
|
||||
/** presetId -> fetched deploy preview. */
|
||||
previews: Record<string, UnrestrictedPreviewEntry>
|
||||
/** Whether a settings write or status refresh is in flight. */
|
||||
@@ -100,7 +79,7 @@ export interface UnrestrictedViewSource {
|
||||
subscribe(listener: () => void): () => void
|
||||
}
|
||||
|
||||
/** Inject face handed to the card and detail badge at registration. */
|
||||
/** Inject face handed to the card at registration. */
|
||||
export interface UnrestrictedCardInjected {
|
||||
hooks: {
|
||||
/** Reactive card view. */
|
||||
@@ -114,15 +93,10 @@ export interface UnrestrictedCardInjected {
|
||||
refresh: () => Promise<void>
|
||||
/** Fetch the exact fused prompt this preset would deploy. */
|
||||
loadPreview: (presetId: string) => Promise<void>
|
||||
/** Check whether a newer plugin version is available. */
|
||||
checkUpdate: (force?: boolean) => Promise<void>
|
||||
/** Download and install the latest version into the active profile. */
|
||||
performUpdate: () => Promise<void>
|
||||
}
|
||||
|
||||
const RPC_CHANNEL = '/dsh-unrestricted'
|
||||
const SETTINGS_NS = 'unrestricted'
|
||||
const DEFAULT_VERSION = '0.2.6'
|
||||
|
||||
/** Human-readable error text for the banner. */
|
||||
function messageOf(error: unknown): string {
|
||||
@@ -143,11 +117,6 @@ export function createUnrestrictedController(ctx: Context) {
|
||||
writable: false,
|
||||
settingsStatus: 'loading',
|
||||
status: null,
|
||||
update: {
|
||||
state: 'idle',
|
||||
currentVersion: DEFAULT_VERSION,
|
||||
restartRequired: false,
|
||||
},
|
||||
previews: {},
|
||||
busy: false,
|
||||
}
|
||||
@@ -173,7 +142,6 @@ export function createUnrestrictedController(ctx: Context) {
|
||||
writable: settingsSnapshot.writable,
|
||||
settingsStatus: settingsSnapshot.status,
|
||||
status: snapshot.status,
|
||||
update: snapshot.update,
|
||||
previews: snapshot.previews,
|
||||
busy: pendingOperations > 0,
|
||||
message: snapshot.message,
|
||||
@@ -210,17 +178,9 @@ export function createUnrestrictedController(ctx: Context) {
|
||||
const status = await call<UnrestrictedStatus>(endpoint, {})
|
||||
if (generation !== statusGeneration) return
|
||||
if (clearPreviews) invalidatePreviews()
|
||||
const nextUpdate = status.update !== undefined
|
||||
&& (snapshot.update.state === 'idle' || status.update.state !== 'idle')
|
||||
? status.update
|
||||
: {
|
||||
...snapshot.update,
|
||||
currentVersion: status.version ?? snapshot.update.currentVersion,
|
||||
}
|
||||
snapshot = {
|
||||
...snapshot,
|
||||
status,
|
||||
update: nextUpdate,
|
||||
message: undefined,
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -285,63 +245,6 @@ export function createUnrestrictedController(ctx: Context) {
|
||||
publish()
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a newer version is available from GitHub or the local source directory.
|
||||
* @param force - bypass in-flight reuse and force a fresh check.
|
||||
*/
|
||||
async function checkUpdate(force = false): Promise<void> {
|
||||
if (snapshot.update.state === 'checking' || snapshot.update.state === 'updating') return
|
||||
snapshot = {
|
||||
...snapshot,
|
||||
update: { ...snapshot.update, state: 'checking', errorCode: undefined, errorDetail: undefined },
|
||||
}
|
||||
publish()
|
||||
try {
|
||||
const update = await call<UnrestrictedUpdateInfo>('check-update', { force })
|
||||
snapshot = { ...snapshot, update }
|
||||
} catch (error) {
|
||||
snapshot = {
|
||||
...snapshot,
|
||||
update: {
|
||||
...snapshot.update,
|
||||
state: 'failed',
|
||||
errorCode: 'update-check-failed',
|
||||
errorDetail: messageOf(error),
|
||||
},
|
||||
}
|
||||
}
|
||||
publish()
|
||||
}
|
||||
|
||||
/**
|
||||
* Download and install the latest version into the active profile.
|
||||
*/
|
||||
async function performUpdate(): Promise<void> {
|
||||
if (snapshot.update.state === 'updating') return
|
||||
snapshot = {
|
||||
...snapshot,
|
||||
update: { ...snapshot.update, state: 'updating', errorCode: undefined, errorDetail: undefined },
|
||||
}
|
||||
publish()
|
||||
try {
|
||||
const update = await call<UnrestrictedUpdateInfo>('perform-update', {
|
||||
targetTag: snapshot.update.latestTag,
|
||||
})
|
||||
snapshot = { ...snapshot, update }
|
||||
} catch (error) {
|
||||
snapshot = {
|
||||
...snapshot,
|
||||
update: {
|
||||
...snapshot.update,
|
||||
state: 'failed',
|
||||
errorCode: 'update-install-failed',
|
||||
errorDetail: messageOf(error),
|
||||
},
|
||||
}
|
||||
}
|
||||
publish()
|
||||
}
|
||||
|
||||
ctx.effect(
|
||||
() => settings.subscribe(publish),
|
||||
'dsh-unrestricted: settings mirror',
|
||||
@@ -362,8 +265,6 @@ export function createUnrestrictedController(ctx: Context) {
|
||||
recheck,
|
||||
refresh: () => refresh(true),
|
||||
loadPreview,
|
||||
checkUpdate,
|
||||
performUpdate,
|
||||
}),
|
||||
}
|
||||
}
|
||||
+4
-10
@@ -1,15 +1,15 @@
|
||||
/** 在本体的插件管理页面提供开关、各模式状态、部署预览以及版本更新提醒与手动更新。 */
|
||||
/** 在本体的插件管理页面提供开关、各模式状态和部署预览。 */
|
||||
import type {} from '@deepseek-ai/dsh-client-locale/client'
|
||||
import type {} from '@deepseek-ai/dsh-client-ui-settings/client'
|
||||
// Type-only: the renderer provides the ctx.slots service used for registration.
|
||||
import type {} from '@deepseek-ai/dsh-client-ui-renderer/client'
|
||||
// Type-only: 本插件配置及详情徽标所在的原生槽位。
|
||||
// Type-only: 本插件配置所在的原生槽位。
|
||||
import type {} from '@deepseek-ai/dsh-client-ui-plugin-manager/client'
|
||||
import type { Context } from '@deepseek-ai/cordis'
|
||||
import { createUnrestrictedController } from './controller.ts'
|
||||
import { en, NS, zh, type UnrestrictedLocaleKey } from './locales.ts'
|
||||
import { ensureStyles } from './styles.ts'
|
||||
import { UnrestrictedCard, UnrestrictedDetailBadge } from './UnrestrictedCard.tsx'
|
||||
import { UnrestrictedCard } from './UnrestrictedCard.tsx'
|
||||
|
||||
declare module '@deepseek-ai/dsh-client-ui-slots' {
|
||||
interface LocaleNamespaceMap {
|
||||
@@ -21,7 +21,7 @@ declare module '@deepseek-ai/dsh-client-ui-slots' {
|
||||
/** Services required by the registration and the controller. */
|
||||
export const inject = ['slots', 'locale', 'connection', 'remote', 'configForms']
|
||||
|
||||
/** 注册本插件的配置卡片与详情页更新徽标。 */
|
||||
/** 注册本插件的配置卡片。 */
|
||||
export function apply(ctx: Context): void {
|
||||
ensureStyles()
|
||||
ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'dsh-unrestricted: dictionaries')
|
||||
@@ -32,10 +32,4 @@ export function apply(ctx: Context): void {
|
||||
locale: NS,
|
||||
inject: () => controller.face(),
|
||||
}, UnrestrictedCard))
|
||||
ctx.slots.inject('plugins.detail.badge', () => ctx.slots.register({
|
||||
name: 'plugins.detail.badge',
|
||||
id: 'dsh-unrestricted:update-badge',
|
||||
locale: NS,
|
||||
inject: () => controller.face(),
|
||||
}, UnrestrictedDetailBadge))
|
||||
}
|
||||
@@ -43,33 +43,10 @@ export const zh = {
|
||||
settingsLoading: '正在读取配置…',
|
||||
operationFailed: '操作失败:',
|
||||
issuePersona: '未检测到预设角色前缀段落,已自动保留原版提示词',
|
||||
updateTitle: '版本与更新',
|
||||
currentVersion: '当前版本',
|
||||
latestVersion: '最新版本',
|
||||
installSource: '安装方式',
|
||||
sourceGithub: 'GitHub 仓库',
|
||||
sourceFile: '本地目录 (file:)',
|
||||
sourceRegistry: '软件包镜像',
|
||||
sourceUnknown: '当前 Profile',
|
||||
updateIdle: '尚未检查更新',
|
||||
updateChecking: '正在检查更新…',
|
||||
updateUpToDate: '已是最新版本',
|
||||
updateAvailable: '发现新版本',
|
||||
updateInstalling: '正在下载并安装更新,请稍候…',
|
||||
updateInstalled: '已安装新版本,重启 DSH Web 或桌面端后生效',
|
||||
updateBadge: '可更新',
|
||||
updateRestartBadge: '待重启生效',
|
||||
checkUpdate: '检查更新',
|
||||
installUpdate: '立即更新',
|
||||
viewRelease: '发布说明',
|
||||
errorRpcDisconnected: '无法连接宿主服务,请确认 DSH 正在运行后刷新重试。',
|
||||
errorUnsupportedPreset: '不支持该预设模式的提示词预览。',
|
||||
errorMissingPersona: '当前预设未包含角色前缀段落,已自动保留原版提示词。',
|
||||
errorPreviewFailed: '生成提示词预览失败,请稍后刷新重试。',
|
||||
errorUpdateCheckFailed: '检查更新失败,请确认网络连接正常后重试。',
|
||||
errorUpdateNoProfile: '当前运行环境未绑定可管理的 Profile 目录,无法执行自动更新。',
|
||||
errorUpdateFileOutdated: '当前通过本地目录 (file:) 安装,且本地目录版本低于远端最新版本,请先更新本地源码目录后再点更新。',
|
||||
errorUpdateInstallFailed: '安装更新失败:',
|
||||
} satisfies Record<string, string>
|
||||
|
||||
/** Unrestricted card locale key union. */
|
||||
@@ -118,33 +95,10 @@ export const en = {
|
||||
settingsLoading: 'Loading configuration…',
|
||||
operationFailed: 'Operation failed: ',
|
||||
issuePersona: 'Preset persona section not found — stock prompt kept',
|
||||
updateTitle: 'Version & Updates',
|
||||
currentVersion: 'Current version',
|
||||
latestVersion: 'Latest version',
|
||||
installSource: 'Install source',
|
||||
sourceGithub: 'GitHub repository',
|
||||
sourceFile: 'Local directory (file:)',
|
||||
sourceRegistry: 'Package registry',
|
||||
sourceUnknown: 'Active profile',
|
||||
updateIdle: 'Not checked yet',
|
||||
updateChecking: 'Checking for updates…',
|
||||
updateUpToDate: 'Up to date',
|
||||
updateAvailable: 'Update available',
|
||||
updateInstalling: 'Downloading and installing update…',
|
||||
updateInstalled: 'Update installed — restart DSH Web or Desktop to apply',
|
||||
updateBadge: 'Update available',
|
||||
updateRestartBadge: 'Restart to apply',
|
||||
checkUpdate: 'Check for updates',
|
||||
installUpdate: 'Update now',
|
||||
viewRelease: 'Release notes',
|
||||
errorRpcDisconnected: 'Cannot reach the host service. Please verify DSH is running and refresh.',
|
||||
errorUnsupportedPreset: 'Prompt preview is not supported for this preset.',
|
||||
errorMissingPersona: 'The preset is missing a persona prefix section; the stock prompt is kept.',
|
||||
errorPreviewFailed: 'Could not assemble the prompt preview. Please try refreshing.',
|
||||
errorUpdateCheckFailed: 'Could not check for updates. Please verify your network connection and try again.',
|
||||
errorUpdateNoProfile: 'This runtime does not expose a managed profile directory for self-update.',
|
||||
errorUpdateFileOutdated: 'Installed from a local file: directory whose version is older than the latest release. Update the local directory first.',
|
||||
errorUpdateInstallFailed: 'Failed to install update: ',
|
||||
} satisfies Record<UnrestrictedLocaleKey, string>
|
||||
|
||||
/** Dictionary namespace owned by this plugin. */
|
||||
|
||||
@@ -229,50 +229,6 @@ const CSS = `
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.dsh-unrestricted-metaGrid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
|
||||
gap: 10px 14px;
|
||||
margin: 0;
|
||||
border: 1px solid var(--dsw-alias-border-l2);
|
||||
border-radius: var(--dsw-radius-lg, 10px);
|
||||
padding: 11px 14px;
|
||||
background: var(--dsw-alias-bg-layer-2);
|
||||
}
|
||||
|
||||
.dsh-unrestricted-metaItem {
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.dsh-unrestricted-metaItem dt {
|
||||
font-size: 11px;
|
||||
line-height: 16px;
|
||||
color: var(--dsw-alias-label-tertiary);
|
||||
}
|
||||
|
||||
.dsh-unrestricted-metaItem dd {
|
||||
margin: 0;
|
||||
font-size: 13px;
|
||||
line-height: 19px;
|
||||
font-weight: 500;
|
||||
color: var(--dsw-alias-label-primary);
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.dsh-unrestricted-link {
|
||||
color: var(--dsw-alias-state-business-primary);
|
||||
font-size: 12px;
|
||||
line-height: 18px;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.dsh-unrestricted-link:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.dsh-unrestricted-card {
|
||||
padding: 14px;
|
||||
|
||||
+4
-443
@@ -1,7 +1,6 @@
|
||||
/**
|
||||
* dsh-unrestricted host half: fuses the unrestricted execution mode into each
|
||||
* preset's ORIGINAL system prompt at assembly time, and provides version check
|
||||
* and self-update support for both DSH Web and DSH Desktop profiles.
|
||||
* preset's ORIGINAL system prompt at assembly time and exposes read-only previews.
|
||||
*
|
||||
* Mechanism (public interfaces only):
|
||||
* - A root `system-prompt/assemble` waterfall listener receives every agent's
|
||||
@@ -23,19 +22,14 @@
|
||||
* (`ptc` when `tools:ptc-only` is present, otherwise `standard`) and fuses
|
||||
* their assemblies directly.
|
||||
*/
|
||||
import { execFile } from 'node:child_process'
|
||||
import fs from 'node:fs/promises'
|
||||
import path from 'node:path'
|
||||
import z from '@deepseek-ai/schemastery'
|
||||
import { renderPrompt } from '@deepseek-ai/dsh-system-prompt'
|
||||
import {
|
||||
ANCHORS,
|
||||
PRESETS,
|
||||
PRESET_RULES,
|
||||
compareSemver,
|
||||
fuseSections,
|
||||
fusedMinimalPrompt,
|
||||
normalizeVersion,
|
||||
renderPreview,
|
||||
} from './rules.js'
|
||||
|
||||
@@ -43,21 +37,12 @@ import {
|
||||
export const name = 'dsh-unrestricted'
|
||||
|
||||
/** Current plugin package version. */
|
||||
export const PLUGIN_VERSION = '0.2.6'
|
||||
|
||||
/** Canonical GitHub repository for release checks and git-based updates. */
|
||||
export const GITHUB_REPO = 'yexi-by/dsh-unrestricted'
|
||||
export const PLUGIN_VERSION = '0.2.7'
|
||||
|
||||
/** Services required by this plugin (all base-backed profiles provide these). */
|
||||
export const inject = ['settings', 'systemPrompt', 'loader']
|
||||
|
||||
const RPC_CHANNEL = '/dsh-unrestricted'
|
||||
const RELEASE_API_URL = `https://api.github.com/repos/${GITHUB_REPO}/releases/latest`
|
||||
const RAW_PACKAGE_URL = `https://raw.githubusercontent.com/${GITHUB_REPO}/master/package.json`
|
||||
const JSDELIVR_PACKAGE_URL = `https://cdn.jsdelivr.net/gh/${GITHUB_REPO}@master/package.json`
|
||||
const UPDATE_CHECK_TIMEOUT_MS = 10_000
|
||||
const PNPM_TIMEOUT_MS = 120_000
|
||||
|
||||
export const Config = z.object({
|
||||
enabled: z.boolean().default(false),
|
||||
}).default({ enabled: false }).volatile()
|
||||
@@ -72,59 +57,9 @@ function ok(value) {
|
||||
return { ok: true, value }
|
||||
}
|
||||
|
||||
/** Read and parse a JSON file, returning undefined when absent or unreadable. */
|
||||
async function readJsonFile(filePath) {
|
||||
try {
|
||||
const raw = await fs.readFile(filePath, 'utf8')
|
||||
return JSON.parse(raw)
|
||||
} catch {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
/** Run pnpm inside a profile directory using Desktop's bundled runtime or system pnpm. */
|
||||
function runPnpm(profileDir, args, packageManager) {
|
||||
const command = packageManager?.command ?? (process.platform === 'win32' ? 'pnpm.cmd' : 'pnpm')
|
||||
const fullArgs = [
|
||||
...(packageManager?.argsPrefix ?? []),
|
||||
'--dir',
|
||||
profileDir,
|
||||
'--config.confirmModulesPurge=false',
|
||||
...args,
|
||||
]
|
||||
const env = packageManager?.env !== undefined
|
||||
? { ...process.env, ...packageManager.env }
|
||||
: process.env
|
||||
const useShell = packageManager?.command === undefined && process.platform === 'win32'
|
||||
return new Promise((resolve, reject) => {
|
||||
execFile(
|
||||
command,
|
||||
fullArgs,
|
||||
{
|
||||
cwd: profileDir,
|
||||
env,
|
||||
shell: useShell,
|
||||
windowsHide: true,
|
||||
timeout: PNPM_TIMEOUT_MS,
|
||||
maxBuffer: 8 * 1024 * 1024,
|
||||
},
|
||||
(error, stdout, stderr) => {
|
||||
if (error) {
|
||||
const detail = [stderr, stdout, error.message]
|
||||
.map(part => String(part ?? '').trim())
|
||||
.find(part => part.length > 0) ?? 'pnpm exited with an error'
|
||||
reject(new Error(detail))
|
||||
return
|
||||
}
|
||||
resolve({ stdout, stderr })
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ctx - plugin context carrying settings, systemPrompt, loader, and
|
||||
* optional agentPresets / connection / profileContext services.
|
||||
* optional agentPresets / connection services.
|
||||
*/
|
||||
export function apply(ctx, config) {
|
||||
ctx.effect(() => ctx.settings.configure({ auto: false }, ctx.fiber))
|
||||
@@ -141,16 +76,6 @@ export function apply(ctx, config) {
|
||||
fusedMinimal: fusedMinimalPrompt(),
|
||||
/** presetId -> last successfully fused top-level live assembly (the deploy preview). */
|
||||
fusedText: new Map(),
|
||||
/** Latest update status snapshot. */
|
||||
update: {
|
||||
state: 'idle',
|
||||
currentVersion: PLUGIN_VERSION,
|
||||
restartRequired: false,
|
||||
},
|
||||
/** In-flight update check promise. */
|
||||
checkingUpdate: null,
|
||||
/** In-flight update installation promise. */
|
||||
performingUpdate: null,
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -291,362 +216,7 @@ export function apply(ctx, config) {
|
||||
state.fusedText.clear()
|
||||
}
|
||||
|
||||
/** Inspect how `dsh-unrestricted` is installed in the active profile. */
|
||||
async function inspectProfileInstall() {
|
||||
const profileContext = ctx.get('profileContext')
|
||||
const profileDir = profileContext?.dir
|
||||
if (typeof profileDir !== 'string' || profileDir === '') {
|
||||
return {
|
||||
profileDir: undefined,
|
||||
profileName: undefined,
|
||||
packageManager: undefined,
|
||||
installSource: 'unknown',
|
||||
dependencySpec: undefined,
|
||||
localSourceDir: undefined,
|
||||
}
|
||||
}
|
||||
const pkg = await readJsonFile(path.join(profileDir, 'package.json'))
|
||||
const spec = pkg?.dependencies?.[name]
|
||||
if (typeof spec !== 'string' || spec === '') {
|
||||
return {
|
||||
profileDir,
|
||||
profileName: profileContext?.name,
|
||||
packageManager: profileContext?.packageManager,
|
||||
installSource: 'unknown',
|
||||
dependencySpec: undefined,
|
||||
localSourceDir: undefined,
|
||||
}
|
||||
}
|
||||
if (spec.startsWith('file:') || spec.startsWith('link:')) {
|
||||
const prefix = spec.startsWith('file:') ? 'file:' : 'link:'
|
||||
const rawTarget = spec.slice(prefix.length)
|
||||
const localSourceDir = path.isAbsolute(rawTarget)
|
||||
? rawTarget
|
||||
: path.resolve(profileDir, rawTarget)
|
||||
return {
|
||||
profileDir,
|
||||
profileName: profileContext?.name,
|
||||
packageManager: profileContext?.packageManager,
|
||||
installSource: 'file',
|
||||
dependencySpec: spec,
|
||||
localSourceDir,
|
||||
}
|
||||
}
|
||||
if (spec.startsWith('github:') || spec.includes('github.com')) {
|
||||
return {
|
||||
profileDir,
|
||||
profileName: profileContext?.name,
|
||||
packageManager: profileContext?.packageManager,
|
||||
installSource: 'github',
|
||||
dependencySpec: spec,
|
||||
localSourceDir: undefined,
|
||||
}
|
||||
}
|
||||
return {
|
||||
profileDir,
|
||||
profileName: profileContext?.name,
|
||||
packageManager: profileContext?.packageManager,
|
||||
installSource: 'registry',
|
||||
dependencySpec: spec,
|
||||
localSourceDir: undefined,
|
||||
}
|
||||
}
|
||||
|
||||
/** Query GitHub Releases (with raw/jsDelivr fallback) for the latest published version. */
|
||||
async function fetchRemoteRelease() {
|
||||
const headers = {
|
||||
Accept: 'application/vnd.github+json',
|
||||
'User-Agent': 'dsh-unrestricted',
|
||||
}
|
||||
let lastError
|
||||
try {
|
||||
const response = await fetch(RELEASE_API_URL, {
|
||||
headers,
|
||||
signal: AbortSignal.timeout(UPDATE_CHECK_TIMEOUT_MS),
|
||||
})
|
||||
if (response.ok) {
|
||||
const data = await response.json()
|
||||
const version = normalizeVersion(data?.tag_name ?? data?.name)
|
||||
if (version !== undefined) {
|
||||
return {
|
||||
latestVersion: version,
|
||||
latestTag: typeof data.tag_name === 'string' && data.tag_name.trim() !== ''
|
||||
? data.tag_name.trim()
|
||||
: `v${version}`,
|
||||
releaseUrl: typeof data.html_url === 'string' && data.html_url.trim() !== ''
|
||||
? data.html_url.trim()
|
||||
: `https://github.com/${GITHUB_REPO}/releases/tag/v${version}`,
|
||||
publishedAt: typeof data.published_at === 'string' ? data.published_at : undefined,
|
||||
}
|
||||
}
|
||||
} else {
|
||||
lastError = new Error(`HTTP ${response.status}`)
|
||||
}
|
||||
} catch (error) {
|
||||
lastError = error
|
||||
}
|
||||
|
||||
for (const fallbackUrl of [RAW_PACKAGE_URL, JSDELIVR_PACKAGE_URL]) {
|
||||
try {
|
||||
const response = await fetch(fallbackUrl, {
|
||||
headers: { Accept: 'application/json', 'User-Agent': 'dsh-unrestricted' },
|
||||
signal: AbortSignal.timeout(UPDATE_CHECK_TIMEOUT_MS),
|
||||
})
|
||||
if (!response.ok) {
|
||||
lastError = new Error(`HTTP ${response.status}`)
|
||||
continue
|
||||
}
|
||||
const pkg = await response.json()
|
||||
const version = normalizeVersion(pkg?.version)
|
||||
if (version !== undefined) {
|
||||
return {
|
||||
latestVersion: version,
|
||||
latestTag: `v${version}`,
|
||||
releaseUrl: `https://github.com/${GITHUB_REPO}/releases/tag/v${version}`,
|
||||
publishedAt: undefined,
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
lastError = error
|
||||
}
|
||||
}
|
||||
|
||||
throw lastError ?? new Error('Unable to reach GitHub release metadata')
|
||||
}
|
||||
|
||||
/** Check whether a newer version is available from GitHub or the linked local directory. */
|
||||
async function checkUpdate({ force = false } = {}) {
|
||||
if (!force && state.checkingUpdate !== null) {
|
||||
return await state.checkingUpdate
|
||||
}
|
||||
const task = (async () => {
|
||||
const install = await inspectProfileInstall()
|
||||
let localVersion
|
||||
if (install.installSource === 'file' && install.localSourceDir !== undefined) {
|
||||
const localPkg = await readJsonFile(path.join(install.localSourceDir, 'package.json'))
|
||||
localVersion = normalizeVersion(localPkg?.version)
|
||||
}
|
||||
|
||||
let remote = null
|
||||
let remoteError = null
|
||||
try {
|
||||
remote = await fetchRemoteRelease()
|
||||
} catch (error) {
|
||||
remoteError = error
|
||||
}
|
||||
|
||||
if (remote === null && localVersion === undefined) {
|
||||
state.update = {
|
||||
...state.update,
|
||||
state: 'failed',
|
||||
currentVersion: PLUGIN_VERSION,
|
||||
installSource: install.installSource,
|
||||
dependencySpec: install.dependencySpec,
|
||||
checkedAt: new Date().toISOString(),
|
||||
errorCode: 'update-check-failed',
|
||||
errorDetail: messageOf(remoteError),
|
||||
}
|
||||
return state.update
|
||||
}
|
||||
|
||||
let latestVersion = remote?.latestVersion ?? localVersion
|
||||
let latestTag = remote?.latestTag ?? `v${latestVersion}`
|
||||
if (localVersion !== undefined && (latestVersion === undefined || compareSemver(localVersion, latestVersion) > 0)) {
|
||||
latestVersion = localVersion
|
||||
latestTag = `v${localVersion}`
|
||||
}
|
||||
|
||||
const baselineVersion = state.update.restartRequired && state.update.updatedVersion !== undefined
|
||||
? state.update.updatedVersion
|
||||
: PLUGIN_VERSION
|
||||
const hasNewer = compareSemver(latestVersion, baselineVersion) > 0
|
||||
|
||||
state.update = {
|
||||
state: hasNewer
|
||||
? 'available'
|
||||
: state.update.restartRequired
|
||||
? 'updated'
|
||||
: 'up-to-date',
|
||||
currentVersion: PLUGIN_VERSION,
|
||||
latestVersion,
|
||||
latestTag,
|
||||
releaseUrl: remote?.releaseUrl ?? `https://github.com/${GITHUB_REPO}/releases`,
|
||||
publishedAt: remote?.publishedAt,
|
||||
checkedAt: new Date().toISOString(),
|
||||
installSource: install.installSource,
|
||||
dependencySpec: install.dependencySpec,
|
||||
restartRequired: Boolean(state.update.restartRequired),
|
||||
updatedVersion: state.update.updatedVersion,
|
||||
}
|
||||
return state.update
|
||||
})()
|
||||
|
||||
state.checkingUpdate = task
|
||||
try {
|
||||
return await task
|
||||
} finally {
|
||||
if (state.checkingUpdate === task) {
|
||||
state.checkingUpdate = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Install the latest version into the active profile and mark restartRequired. */
|
||||
async function performUpdate({ targetTag } = {}) {
|
||||
if (state.performingUpdate !== null) {
|
||||
return await state.performingUpdate
|
||||
}
|
||||
const task = (async () => {
|
||||
const install = await inspectProfileInstall()
|
||||
if (install.profileDir === undefined) {
|
||||
state.update = {
|
||||
...state.update,
|
||||
state: 'failed',
|
||||
currentVersion: PLUGIN_VERSION,
|
||||
errorCode: 'update-no-profile',
|
||||
}
|
||||
return state.update
|
||||
}
|
||||
|
||||
if (state.update.latestVersion === undefined && targetTag === undefined) {
|
||||
await checkUpdate({ force: true })
|
||||
}
|
||||
|
||||
let targetSpec
|
||||
let expectedVersion = state.update.latestVersion
|
||||
|
||||
if (install.installSource === 'file' && install.localSourceDir !== undefined) {
|
||||
const localPkg = await readJsonFile(path.join(install.localSourceDir, 'package.json'))
|
||||
const localVersion = normalizeVersion(localPkg?.version)
|
||||
if (localVersion === undefined) {
|
||||
state.update = {
|
||||
...state.update,
|
||||
state: 'failed',
|
||||
currentVersion: PLUGIN_VERSION,
|
||||
installSource: install.installSource,
|
||||
dependencySpec: install.dependencySpec,
|
||||
errorCode: 'update-install-failed',
|
||||
errorDetail: `Cannot read package.json in ${install.localSourceDir}`,
|
||||
}
|
||||
return state.update
|
||||
}
|
||||
if (expectedVersion !== undefined && compareSemver(localVersion, expectedVersion) < 0) {
|
||||
state.update = {
|
||||
...state.update,
|
||||
state: 'failed',
|
||||
currentVersion: PLUGIN_VERSION,
|
||||
installSource: install.installSource,
|
||||
dependencySpec: install.dependencySpec,
|
||||
errorCode: 'update-file-source-outdated',
|
||||
errorDetail: `${localVersion} < ${expectedVersion}`,
|
||||
}
|
||||
return state.update
|
||||
}
|
||||
targetSpec = install.dependencySpec
|
||||
expectedVersion = localVersion
|
||||
} else {
|
||||
const resolvedTag = typeof targetTag === 'string' && targetTag.trim() !== ''
|
||||
? targetTag.trim()
|
||||
: (state.update.latestTag ?? (expectedVersion !== undefined ? `v${expectedVersion}` : 'master'))
|
||||
targetSpec = `github:${GITHUB_REPO}#${resolvedTag}`
|
||||
expectedVersion = normalizeVersion(resolvedTag) ?? expectedVersion ?? PLUGIN_VERSION
|
||||
}
|
||||
|
||||
const pkgPath = path.join(install.profileDir, 'package.json')
|
||||
const lockPath = path.join(install.profileDir, 'pnpm-lock.yaml')
|
||||
const backupPkg = await fs.readFile(pkgPath, 'utf8').catch(() => undefined)
|
||||
const backupLock = await fs.readFile(lockPath, 'utf8').catch(() => undefined)
|
||||
const parsedBefore = backupPkg !== undefined ? JSON.parse(backupPkg) : undefined
|
||||
const originalDsh = parsedBefore?.dsh
|
||||
|
||||
try {
|
||||
await runPnpm(install.profileDir, ['add', targetSpec], install.packageManager)
|
||||
|
||||
// Ensure file: installs refresh cached store copies when needed.
|
||||
const installedPkgPath = path.join(install.profileDir, 'node_modules', name, 'package.json')
|
||||
let installedPkg = await readJsonFile(installedPkgPath)
|
||||
let installedVersion = normalizeVersion(installedPkg?.version)
|
||||
if (
|
||||
install.installSource === 'file'
|
||||
&& expectedVersion !== undefined
|
||||
&& installedVersion !== expectedVersion
|
||||
) {
|
||||
await runPnpm(install.profileDir, ['remove', name], install.packageManager)
|
||||
await runPnpm(install.profileDir, ['add', targetSpec], install.packageManager)
|
||||
installedPkg = await readJsonFile(installedPkgPath)
|
||||
installedVersion = normalizeVersion(installedPkg?.version)
|
||||
}
|
||||
|
||||
// Preserve dsh.profile.bundles in package.json after pnpm mutations.
|
||||
const afterPkg = await readJsonFile(pkgPath)
|
||||
if (afterPkg !== undefined) {
|
||||
const dshBlock = afterPkg.dsh ?? originalDsh ?? {}
|
||||
const profileBlock = dshBlock.profile ?? originalDsh?.profile ?? {}
|
||||
const bundles = Array.isArray(profileBlock.bundles)
|
||||
? [...profileBlock.bundles]
|
||||
: Array.isArray(originalDsh?.profile?.bundles)
|
||||
? [...originalDsh.profile.bundles]
|
||||
: []
|
||||
if (!bundles.includes(name)) bundles.push(name)
|
||||
afterPkg.dsh = {
|
||||
...originalDsh,
|
||||
...dshBlock,
|
||||
profile: {
|
||||
...originalDsh?.profile,
|
||||
...profileBlock,
|
||||
bundles,
|
||||
},
|
||||
}
|
||||
await fs.writeFile(pkgPath, `${JSON.stringify(afterPkg, null, 2)}\n`, 'utf8')
|
||||
}
|
||||
|
||||
const finalVersion = installedVersion ?? expectedVersion ?? PLUGIN_VERSION
|
||||
state.update = {
|
||||
...state.update,
|
||||
state: 'updated',
|
||||
currentVersion: PLUGIN_VERSION,
|
||||
latestVersion: finalVersion,
|
||||
latestTag: `v${finalVersion}`,
|
||||
updatedVersion: finalVersion,
|
||||
installSource: install.installSource,
|
||||
dependencySpec: targetSpec,
|
||||
checkedAt: new Date().toISOString(),
|
||||
restartRequired: true,
|
||||
errorCode: undefined,
|
||||
errorDetail: undefined,
|
||||
}
|
||||
return state.update
|
||||
} catch (error) {
|
||||
if (backupPkg !== undefined) {
|
||||
await fs.writeFile(pkgPath, backupPkg, 'utf8').catch(() => {})
|
||||
}
|
||||
if (backupLock !== undefined) {
|
||||
await fs.writeFile(lockPath, backupLock, 'utf8').catch(() => {})
|
||||
}
|
||||
state.update = {
|
||||
...state.update,
|
||||
state: 'failed',
|
||||
currentVersion: PLUGIN_VERSION,
|
||||
installSource: install.installSource,
|
||||
dependencySpec: install.dependencySpec,
|
||||
errorCode: 'update-install-failed',
|
||||
errorDetail: messageOf(error),
|
||||
}
|
||||
return state.update
|
||||
}
|
||||
})()
|
||||
|
||||
state.performingUpdate = task
|
||||
try {
|
||||
return await task
|
||||
} finally {
|
||||
if (state.performingUpdate === task) {
|
||||
state.performingUpdate = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Current card view: toggle, version, per-preset state, and update state. */
|
||||
/** Current card view: toggle, version, and per-preset state. */
|
||||
function statusPayload() {
|
||||
const modes = {}
|
||||
for (const presetId of PRESETS) {
|
||||
@@ -662,7 +232,6 @@ export function apply(ctx, config) {
|
||||
enabled: state.enabled,
|
||||
version: PLUGIN_VERSION,
|
||||
modes,
|
||||
update: state.update,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -755,14 +324,6 @@ export function apply(ctx, config) {
|
||||
if (state.enabled) sweepAgents()
|
||||
return ok(statusPayload())
|
||||
}
|
||||
case 'check-update': {
|
||||
const force = Boolean(payload?.force ?? payload?.args?.force)
|
||||
return ok(await checkUpdate({ force }))
|
||||
}
|
||||
case 'perform-update': {
|
||||
const targetTag = payload?.targetTag ?? payload?.args?.targetTag
|
||||
return ok(await performUpdate({ targetTag }))
|
||||
}
|
||||
default:
|
||||
return {
|
||||
ok: false,
|
||||
|
||||
+1
-52
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* dsh-unrestricted fusion rules: pure functions that fuse the unrestricted
|
||||
* execution mode into each preset's system prompt sections by structural
|
||||
* section name, plus semver helpers for release update checks.
|
||||
* section name.
|
||||
*
|
||||
* @module dsh-unrestricted/rules
|
||||
*/
|
||||
@@ -198,54 +198,3 @@ export function fuseSections(sections, presetId, { isSubagent = false } = {}) {
|
||||
fused.splice(insertAt, 0, { name: BLOCK_SECTION, text: EXECUTION_MODE_BLOCK })
|
||||
return { sections: fused }
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize a version or Git tag string (e.g. `v0.2.6` -> `0.2.6`).
|
||||
* @param {unknown} raw
|
||||
* @returns {string | undefined}
|
||||
*/
|
||||
export function normalizeVersion(raw) {
|
||||
if (typeof raw !== 'string') return undefined
|
||||
const cleaned = raw.trim().replace(/^v/i, '')
|
||||
if (!/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/.test(cleaned)) {
|
||||
return undefined
|
||||
}
|
||||
return cleaned.split('+')[0]
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare two semantic versions (`1` if `a > b`, `-1` if `a < b`, `0` if equal).
|
||||
* @param {string} a
|
||||
* @param {string} b
|
||||
* @returns {number}
|
||||
*/
|
||||
export function compareSemver(a, b) {
|
||||
const va = normalizeVersion(a)
|
||||
const vb = normalizeVersion(b)
|
||||
if (va === undefined || vb === undefined) return 0
|
||||
const [coreA, preA] = va.split('-', 2)
|
||||
const [coreB, preB] = vb.split('-', 2)
|
||||
const partsA = coreA.split('.').map(Number)
|
||||
const partsB = coreB.split('.').map(Number)
|
||||
for (let i = 0; i < 3; i++) {
|
||||
if (partsA[i] !== partsB[i]) return partsA[i] > partsB[i] ? 1 : -1
|
||||
}
|
||||
if (preA === undefined && preB === undefined) return 0
|
||||
if (preA === undefined) return 1
|
||||
if (preB === undefined) return -1
|
||||
const segsA = preA.split('.')
|
||||
const segsB = preB.split('.')
|
||||
const len = Math.max(segsA.length, segsB.length)
|
||||
for (let i = 0; i < len; i++) {
|
||||
if (segsA[i] === undefined) return -1
|
||||
if (segsB[i] === undefined) return 1
|
||||
if (segsA[i] === segsB[i]) continue
|
||||
const numA = /^\d+$/.test(segsA[i]) ? Number(segsA[i]) : null
|
||||
const numB = /^\d+$/.test(segsB[i]) ? Number(segsB[i]) : null
|
||||
if (numA !== null && numB !== null) return numA > numB ? 1 : -1
|
||||
if (numA !== null) return -1
|
||||
if (numB !== null) return 1
|
||||
return segsA[i] > segsB[i] ? 1 : -1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
Reference in new issue
Block a user