dsh-mcviseron-plugin 0.6.4 → 0.6.6
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/CHANGELOG.md +37 -5
- package/README.en.md +17 -5
- package/README.md +19 -7
- package/docs/auth-cookie.md +61 -0
- package/docs/auto-review-context.md +65 -0
- package/docs/automation-task.md +1 -1
- package/docs/release.md +3 -3
- package/docs/session-end.md +5 -2
- package/lib/auto-review-fix.js +253 -23
- package/lib/client.js +301 -171
- package/lib/index.js +606 -128
- package/package.json +3 -3
- package/src/api.ts +6 -0
- package/src/auth-cookie/index.ts +175 -0
- package/src/auto-review-fix/index.ts +9 -0
- package/src/client/ConfigForm.tsx +3 -0
- package/src/client/SessionEndControl.tsx +115 -165
- package/src/client/SessionEndGlobalNotice.ts +183 -0
- package/src/client/SettingsSection.tsx +4 -0
- package/src/client/index.ts +15 -0
- package/src/client/locales.ts +16 -2
- package/src/client/primitives.d.ts +37 -1
- package/src/components/auto-review-fix/index.ts +8 -0
- package/src/components/auto-review-fix/review-context.ts +285 -0
- package/src/index.ts +2 -0
- package/src/session-end/index.ts +146 -27
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-mcviseron-plugin",
|
|
3
|
-
"version": "0.6.
|
|
4
|
-
"description": "DeepSeek Harness (DSH) master plugin — one package hosting MCviseron's DSH components as separate bundle entries: a time-based light/dark Appearance schedule, an Auto-review fix (shutdown preset guard + Chinese approval-reason translation), and a todo plan guard that keeps multi-stage work advancing,
|
|
3
|
+
"version": "0.6.6",
|
|
4
|
+
"description": "DeepSeek Harness (DSH) master plugin — one package hosting MCviseron's DSH components as separate bundle entries: a time-based light/dark Appearance schedule, an Auto-review fix (shutdown preset guard + Chinese approval-reason translation), and a todo plan guard that keeps multi-stage work advancing, one-shot after-session restart/close actions with task-aware waiting, and automatic auth-cookie hygiene for repeated desktop restarts.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "MCviseron",
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"scripts": {
|
|
79
79
|
"build": "node build.mjs",
|
|
80
80
|
"typecheck": "tsc --noEmit",
|
|
81
|
-
"test": "node --experimental-strip-types test/schedule.test.ts && node --experimental-strip-types test/routes.test.ts && node --experimental-strip-types test/config.test.ts && node --experimental-strip-types test/auto-review-fix.test.ts && node --experimental-strip-types test/auto-review-fix-cordis.test.ts && node --experimental-strip-types test/task-guard.test.ts && node --experimental-strip-types test/task-guard-cordis.test.ts && node --experimental-strip-types test/session-end.test.ts && node --experimental-strip-types test/restart.test.ts && node --experimental-strip-types test/plugin.test.ts",
|
|
81
|
+
"test": "node --experimental-strip-types test/schedule.test.ts && node --experimental-strip-types test/routes.test.ts && node --experimental-strip-types test/config.test.ts && node --experimental-strip-types test/auto-review-fix.test.ts && node --experimental-strip-types test/auto-review-fix-cordis.test.ts && node --experimental-strip-types test/review-context.test.ts && node --experimental-strip-types test/global-notice.test.ts && node --experimental-strip-types test/task-guard.test.ts && node --experimental-strip-types test/task-guard-cordis.test.ts && node --experimental-strip-types test/session-end.test.ts && node --experimental-strip-types test/auth-cookie.test.ts && node --experimental-strip-types test/restart.test.ts && node --experimental-strip-types test/plugin.test.ts",
|
|
82
82
|
"check": "pnpm typecheck && pnpm test && pnpm build",
|
|
83
83
|
"prepare": "pnpm build",
|
|
84
84
|
"prepublishOnly": "pnpm check",
|
package/src/api.ts
CHANGED
|
@@ -8,4 +8,10 @@ export const MCVISERON_API = {
|
|
|
8
8
|
export const SESSION_END_API = {
|
|
9
9
|
state: '/api/dsh-mcviseron/session-end/state',
|
|
10
10
|
set: '/api/dsh-mcviseron/session-end/set',
|
|
11
|
+
global: '/api/dsh-mcviseron/session-end/global',
|
|
12
|
+
} as const
|
|
13
|
+
|
|
14
|
+
/** Auth-cookie hygiene shared by the index script and the client fallback. */
|
|
15
|
+
export const AUTH_COOKIE_API = {
|
|
16
|
+
prune: '/api/dsh-mcviseron/auth-cookies/prune',
|
|
11
17
|
} as const
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
import { appendFileSync } from 'node:fs'
|
|
3
|
+
import { tmpdir } from 'node:os'
|
|
4
|
+
import { join } from 'node:path'
|
|
5
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
6
|
+
import type { IncomingMessage, ServerResponse } from 'node:http'
|
|
7
|
+
import type { WebRoute } from '@deepseek-ai/dsh-host-webserver'
|
|
8
|
+
import { AUTH_COOKIE_API } from '../api.ts'
|
|
9
|
+
import { isLoopbackRequest } from '../loopback.ts'
|
|
10
|
+
|
|
11
|
+
export const AUTH_COOKIE_PREFIX = 'dsh-auth-'
|
|
12
|
+
const EXPIRED_AT = 'Thu, 01 Jan 1970 00:00:00 GMT'
|
|
13
|
+
|
|
14
|
+
function logPrune(authority: string, pruned: number): void {
|
|
15
|
+
try {
|
|
16
|
+
appendFileSync(
|
|
17
|
+
join(tmpdir(), 'dsh-mcviseron-auth-cookie.log'),
|
|
18
|
+
new Date().toISOString() + ' pruned=' + pruned + ' authority=' + authority + '\n',
|
|
19
|
+
'utf8',
|
|
20
|
+
)
|
|
21
|
+
} catch {
|
|
22
|
+
/* diagnostics must never break cookie hygiene */
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Mirror DSH's browser-auth cookie name for one request authority. */
|
|
27
|
+
export function authCookieName(authority: string): string {
|
|
28
|
+
return AUTH_COOKIE_PREFIX + createHash('sha256').update(authority).digest('base64url')
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Mirror dsh-client-connection's requestAudience: HTTP cookies are keyed by
|
|
33
|
+
* host:port, TLS cookies by the origin. Chromium itself ignores the port.
|
|
34
|
+
*/
|
|
35
|
+
export function requestAuthority(host: unknown, secure: boolean): string | undefined {
|
|
36
|
+
if (typeof host !== 'string' || host === '') return undefined
|
|
37
|
+
try {
|
|
38
|
+
const url = new URL((secure ? 'https:' : 'http:') + '//' + host)
|
|
39
|
+
return secure ? url.origin : url.host
|
|
40
|
+
} catch {
|
|
41
|
+
return undefined
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function validAuthCookieName(name: string): boolean {
|
|
46
|
+
if (!name.startsWith(AUTH_COOKIE_PREFIX)) return false
|
|
47
|
+
return /^[A-Za-z0-9_-]+$/.test(name.slice(AUTH_COOKIE_PREFIX.length))
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Extract only syntactically valid dsh-auth-* names from a Cookie header. */
|
|
51
|
+
export function authCookieNames(header: unknown): string[] {
|
|
52
|
+
if (typeof header !== 'string' || header === '') return []
|
|
53
|
+
const names = new Set<string>()
|
|
54
|
+
for (const segment of header.split(';')) {
|
|
55
|
+
const at = segment.indexOf('=')
|
|
56
|
+
const name = (at === -1 ? segment : segment.slice(0, at)).trim()
|
|
57
|
+
if (validAuthCookieName(name)) names.add(name)
|
|
58
|
+
}
|
|
59
|
+
return [...names]
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Names that are not the cookie this launch just minted. */
|
|
63
|
+
export function staleAuthCookieNames(header: unknown, currentName: string): string[] {
|
|
64
|
+
return authCookieNames(header).filter(name => name !== currentName)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** A deletion Set-Cookie matching the generated cookie's Path/host-only scope. */
|
|
68
|
+
export function expiredAuthCookie(name: string, secure: boolean): string {
|
|
69
|
+
return name + '=; Max-Age=0; Path=/; Expires=' + EXPIRED_AT
|
|
70
|
+
+ '; HttpOnly; SameSite=Strict' + (secure ? '; Secure' : '')
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Build the deletion headers for one request, keeping the current cookie. */
|
|
74
|
+
export function pruneCookieHeaders(req: IncomingMessage, secure: boolean): string[] {
|
|
75
|
+
const authority = requestAuthority(req.headers.host, secure)
|
|
76
|
+
if (authority === undefined) return []
|
|
77
|
+
const current = authCookieName(authority)
|
|
78
|
+
return staleAuthCookieNames(req.headers.cookie, current).map(name => expiredAuthCookie(name, secure))
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Head script: prune before the application's modules issue their own calls. */
|
|
82
|
+
export function pruneScript(): string {
|
|
83
|
+
return '(function(){try{fetch(' + JSON.stringify(AUTH_COOKIE_API.prune)
|
|
84
|
+
+ ',{method:"POST",credentials:"same-origin",cache:"no-store"}).catch(function(){})}catch(e){}})()'
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function json(res: ServerResponse, status: number, body: unknown, extra: Record<string, string | string[]> = {}): void {
|
|
88
|
+
res.writeHead(status, {
|
|
89
|
+
'content-type': 'application/json; charset=utf-8',
|
|
90
|
+
'cache-control': 'no-store',
|
|
91
|
+
...extra,
|
|
92
|
+
})
|
|
93
|
+
res.end(JSON.stringify(body))
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Host route used by the head script and the client fallback. */
|
|
97
|
+
export function makeAuthCookieRoutes(options: { secure: () => boolean }): WebRoute[] {
|
|
98
|
+
const route: WebRoute = {
|
|
99
|
+
kind: 'exact',
|
|
100
|
+
path: AUTH_COOKIE_API.prune,
|
|
101
|
+
handler: (req, res): void => {
|
|
102
|
+
if (req.method !== 'POST') {
|
|
103
|
+
json(res, 405, { ok: false, error: 'method-not-allowed' })
|
|
104
|
+
return
|
|
105
|
+
}
|
|
106
|
+
if (!isLoopbackRequest(req)) {
|
|
107
|
+
json(res, 403, { ok: false, error: 'forbidden' })
|
|
108
|
+
return
|
|
109
|
+
}
|
|
110
|
+
const secure = options.secure()
|
|
111
|
+
const authority = requestAuthority(req.headers.host, secure)
|
|
112
|
+
if (authority === undefined) {
|
|
113
|
+
json(res, 400, { ok: false, error: 'host-required' })
|
|
114
|
+
return
|
|
115
|
+
}
|
|
116
|
+
const stale = staleAuthCookieNames(req.headers.cookie, authCookieName(authority))
|
|
117
|
+
logPrune(authority, stale.length)
|
|
118
|
+
const extra: Record<string, string | string[]> = stale.length === 0
|
|
119
|
+
? {}
|
|
120
|
+
: { 'set-cookie': stale.map(name => expiredAuthCookie(name, secure)) }
|
|
121
|
+
json(res, 200, { ok: true, pruned: stale.length }, extra)
|
|
122
|
+
},
|
|
123
|
+
}
|
|
124
|
+
return [route]
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function eventBusOf(ctx: Context): { on?: (event: string, handler: (table: unknown) => void) => unknown } {
|
|
128
|
+
const root = (ctx as unknown as { root?: unknown }).root
|
|
129
|
+
return (root ?? ctx) as { on?: (event: string, handler: (table: unknown) => void) => unknown }
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function installIndexInjection(ctx: Context): void {
|
|
133
|
+
const bus = eventBusOf(ctx)
|
|
134
|
+
if (typeof bus.on !== 'function') return
|
|
135
|
+
try {
|
|
136
|
+
ctx.effect(() => {
|
|
137
|
+
const dispose = bus.on?.('webserver/index-inject', (table) => {
|
|
138
|
+
if (!Array.isArray(table)) return
|
|
139
|
+
table.push({ kind: 'script', placement: 'head', text: pruneScript() })
|
|
140
|
+
})
|
|
141
|
+
return () => {
|
|
142
|
+
if (typeof dispose === 'function') dispose()
|
|
143
|
+
}
|
|
144
|
+
}, 'mcviseron-auth-cookie: index injection')
|
|
145
|
+
} catch {
|
|
146
|
+
/* a host without effects still gets the route */
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export const inject = ['webServer']
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* DSH's per-launch dsh-auth-<hash(host:port)> cookie is host-scoped in
|
|
154
|
+
* Chromium, so every restart otherwise leaves another 30-day cookie behind.
|
|
155
|
+
* This component expires every old dsh-auth-* cookie while keeping the one for
|
|
156
|
+
* the current authority. It runs entirely inside the plugin and survives DSH
|
|
157
|
+
* upgrades; it does not change the desktop application.
|
|
158
|
+
*/
|
|
159
|
+
export function apply(ctx: Context): void {
|
|
160
|
+
const secure = (): boolean => {
|
|
161
|
+
try {
|
|
162
|
+
return ctx.webServer.protocol === 'https:'
|
|
163
|
+
} catch {
|
|
164
|
+
return false
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const routes = makeAuthCookieRoutes({ secure })
|
|
168
|
+
ctx.effect(() => {
|
|
169
|
+
const disposers = routes.map(route => ctx.webServer.register(route))
|
|
170
|
+
return () => {
|
|
171
|
+
for (const dispose of disposers) dispose()
|
|
172
|
+
}
|
|
173
|
+
}, 'mcviseron-auth-cookie: prune route')
|
|
174
|
+
installIndexInjection(ctx)
|
|
175
|
+
}
|
|
@@ -15,6 +15,9 @@ export const DEFAULT_AUTO_REVIEW_CONFIG = {
|
|
|
15
15
|
translateMaxChars: 4000,
|
|
16
16
|
translateProvider: '',
|
|
17
17
|
translateModel: '',
|
|
18
|
+
reviewContextGuard: true,
|
|
19
|
+
reviewMaxHistoryChars: 120000,
|
|
20
|
+
reviewKeepRecentEntries: 16,
|
|
18
21
|
} as const
|
|
19
22
|
|
|
20
23
|
export const Config = z.object({
|
|
@@ -24,6 +27,9 @@ export const Config = z.object({
|
|
|
24
27
|
translateMaxChars: z.number().min(100).max(20000).default(DEFAULT_AUTO_REVIEW_CONFIG.translateMaxChars).volatile(),
|
|
25
28
|
translateProvider: z.string().default(DEFAULT_AUTO_REVIEW_CONFIG.translateProvider).volatile(),
|
|
26
29
|
translateModel: z.string().default(DEFAULT_AUTO_REVIEW_CONFIG.translateModel).volatile(),
|
|
30
|
+
reviewContextGuard: z.boolean().default(DEFAULT_AUTO_REVIEW_CONFIG.reviewContextGuard).volatile(),
|
|
31
|
+
reviewMaxHistoryChars: z.number().min(20000).max(600000).default(DEFAULT_AUTO_REVIEW_CONFIG.reviewMaxHistoryChars).volatile(),
|
|
32
|
+
reviewKeepRecentEntries: z.number().min(4).max(64).default(DEFAULT_AUTO_REVIEW_CONFIG.reviewKeepRecentEntries).volatile(),
|
|
27
33
|
}).default(DEFAULT_AUTO_REVIEW_CONFIG)
|
|
28
34
|
|
|
29
35
|
export interface AutoReviewConfig {
|
|
@@ -33,6 +39,9 @@ export interface AutoReviewConfig {
|
|
|
33
39
|
translateMaxChars?: number
|
|
34
40
|
translateProvider?: string
|
|
35
41
|
translateModel?: string
|
|
42
|
+
reviewContextGuard?: boolean
|
|
43
|
+
reviewMaxHistoryChars?: number
|
|
44
|
+
reviewKeepRecentEntries?: number
|
|
36
45
|
}
|
|
37
46
|
|
|
38
47
|
/**
|
|
@@ -262,6 +262,9 @@ export function ConfigForm({ t, title, description, fields }: ConfigFormProps) {
|
|
|
262
262
|
|
|
263
263
|
/** Auto-review component fields. */
|
|
264
264
|
export const AUTO_REVIEW_FIELDS: readonly ConfigField[] = [
|
|
265
|
+
{ path: ['autoReviewFix', 'reviewContextGuard'], label: 'form.autoReview.reviewGuard', hint: 'form.autoReview.reviewGuardHint', kind: 'switch' },
|
|
266
|
+
{ path: ['autoReviewFix', 'reviewMaxHistoryChars'], label: 'form.autoReview.reviewMaxHistory', hint: 'form.autoReview.reviewMaxHistoryHint', kind: 'number', min: 20000, max: 600000 },
|
|
267
|
+
{ path: ['autoReviewFix', 'reviewKeepRecentEntries'], label: 'form.autoReview.reviewKeepRecent', kind: 'number', min: 4, max: 64 },
|
|
265
268
|
{ path: ['autoReviewFix', 'translateApprovalReason'], label: 'form.autoReview.translate', hint: 'form.autoReview.translateHint', kind: 'switch' },
|
|
266
269
|
{ path: ['autoReviewFix', 'keepPresetGuard'], label: 'form.autoReview.keepPreset', hint: 'form.autoReview.keepPresetHint', kind: 'switch' },
|
|
267
270
|
{ path: ['autoReviewFix', 'translateTimeoutMs'], label: 'form.autoReview.timeout', kind: 'number', min: 500, max: 60000 },
|
|
@@ -1,6 +1,15 @@
|
|
|
1
|
-
import { useEffect,
|
|
1
|
+
import { useEffect, useState, type CSSProperties } from 'react'
|
|
2
|
+
import {
|
|
3
|
+
IconChevronDownOutlineRegular,
|
|
4
|
+
IconClockOutlineRegular,
|
|
5
|
+
IconCloseCircleFillRegular,
|
|
6
|
+
IconRefreshOutlineRegular,
|
|
7
|
+
IconStopFillRegular,
|
|
8
|
+
Menu,
|
|
9
|
+
} from '@deepseek-ai/dsh-client-ui-primitives'
|
|
2
10
|
import type { PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots'
|
|
3
11
|
import { SESSION_END_API } from '../api.ts'
|
|
12
|
+
import { startSessionEndGlobalNotice } from './SessionEndGlobalNotice.ts'
|
|
4
13
|
import type { McviseronKey } from './locales.ts'
|
|
5
14
|
|
|
6
15
|
type Mode = 'off' | 'restart' | 'close' | 'shutdown'
|
|
@@ -26,6 +35,15 @@ const INITIAL: State = {
|
|
|
26
35
|
available: { restart: true, close: true, shutdown: true },
|
|
27
36
|
}
|
|
28
37
|
|
|
38
|
+
const TRIGGER_CSS = [
|
|
39
|
+
'.mcviseron-session-end-trigger:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover)}',
|
|
40
|
+
'.mcviseron-session-end-trigger:focus-visible{box-shadow:0 0 0 2px var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline:none}',
|
|
41
|
+
'.mcviseron-session-end-trigger:disabled{color:var(--dsw-alias-label-dimmed);cursor:default}',
|
|
42
|
+
'.mcviseron-session-end-trigger svg{width:14px;height:14px}',
|
|
43
|
+
'.mcviseron-session-end-chevron{display:inline-flex;transition:transform .12s;color:var(--dsw-alias-label-caption)}',
|
|
44
|
+
'.mcviseron-session-end-chevron.open{transform:rotate(180deg)}',
|
|
45
|
+
].join('\n')
|
|
46
|
+
|
|
29
47
|
export type SessionEndControlProps =
|
|
30
48
|
PropsRuntime<'conversation.input.left'>
|
|
31
49
|
& PropsLocale<'mcviseron'>
|
|
@@ -33,10 +51,10 @@ export type SessionEndControlProps =
|
|
|
33
51
|
const labelStyle: CSSProperties = {
|
|
34
52
|
display: 'inline-flex',
|
|
35
53
|
alignItems: 'center',
|
|
36
|
-
gap:
|
|
37
|
-
padding: '0
|
|
54
|
+
gap: 4,
|
|
55
|
+
padding: '0 4px',
|
|
38
56
|
height: 28,
|
|
39
|
-
borderRadius:
|
|
57
|
+
borderRadius: 'var(--dsw-radius-sm)',
|
|
40
58
|
fontSize: 12,
|
|
41
59
|
lineHeight: 1.3,
|
|
42
60
|
color: 'var(--dsw-alias-label-secondary)',
|
|
@@ -46,49 +64,20 @@ const labelStyle: CSSProperties = {
|
|
|
46
64
|
const triggerStyle: CSSProperties = {
|
|
47
65
|
display: 'inline-flex',
|
|
48
66
|
alignItems: 'center',
|
|
49
|
-
|
|
50
|
-
gap: 6,
|
|
67
|
+
gap: 4,
|
|
51
68
|
height: 28,
|
|
52
|
-
minWidth:
|
|
53
|
-
maxWidth:
|
|
54
|
-
|
|
55
|
-
border: '
|
|
56
|
-
|
|
57
|
-
color: 'var(--dsw-alias-label-primary)',
|
|
58
|
-
fontSize: 12,
|
|
59
|
-
lineHeight: 1.3,
|
|
60
|
-
padding: '0 8px',
|
|
61
|
-
cursor: 'pointer',
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const menuStyle: CSSProperties = {
|
|
65
|
-
position: 'fixed',
|
|
66
|
-
zIndex: 10000,
|
|
67
|
-
padding: 6,
|
|
68
|
-
display: 'flex',
|
|
69
|
-
flexDirection: 'column',
|
|
70
|
-
gap: 2,
|
|
71
|
-
borderRadius: 14,
|
|
72
|
-
border: '1px solid var(--dsw-alias-border-l3)',
|
|
73
|
-
background: 'var(--dsw-alias-bg-layer-2)',
|
|
74
|
-
boxShadow: '0 18px 44px rgba(0, 0, 0, 0.32)',
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const menuOptionStyle: CSSProperties = {
|
|
78
|
-
display: 'flex',
|
|
79
|
-
alignItems: 'center',
|
|
80
|
-
justifyContent: 'space-between',
|
|
81
|
-
gap: 10,
|
|
82
|
-
width: '100%',
|
|
83
|
-
border: 0,
|
|
84
|
-
borderRadius: 10,
|
|
69
|
+
minWidth: 0,
|
|
70
|
+
maxWidth: 220,
|
|
71
|
+
padding: '0 4px 0 8px',
|
|
72
|
+
border: 'none',
|
|
73
|
+
borderRadius: 'var(--dsw-radius-sm)',
|
|
85
74
|
background: 'transparent',
|
|
86
|
-
color: 'var(--dsw-alias-label-
|
|
75
|
+
color: 'var(--dsw-alias-label-secondary)',
|
|
76
|
+
cursor: 'pointer',
|
|
77
|
+
outline: 'none',
|
|
87
78
|
fontSize: 13,
|
|
79
|
+
fontWeight: 500,
|
|
88
80
|
lineHeight: '20px',
|
|
89
|
-
padding: '7px 10px',
|
|
90
|
-
textAlign: 'left',
|
|
91
|
-
cursor: 'pointer',
|
|
92
81
|
}
|
|
93
82
|
|
|
94
83
|
const noticeStyle: CSSProperties = {
|
|
@@ -113,12 +102,21 @@ const shutdownNoticeStyle: CSSProperties = {
|
|
|
113
102
|
color: 'var(--dsw-alias-state-error-primary)',
|
|
114
103
|
}
|
|
115
104
|
|
|
105
|
+
function triggerIcon(mode: Mode) {
|
|
106
|
+
if (mode === 'restart') return <IconRefreshOutlineRegular />
|
|
107
|
+
if (mode === 'close') return <IconCloseCircleFillRegular />
|
|
108
|
+
if (mode === 'shutdown') return <IconStopFillRegular />
|
|
109
|
+
return <IconClockOutlineRegular />
|
|
110
|
+
}
|
|
111
|
+
|
|
116
112
|
/**
|
|
117
113
|
* Composer control for the one-shot session-end action.
|
|
118
114
|
*
|
|
119
|
-
* The
|
|
120
|
-
*
|
|
121
|
-
*
|
|
115
|
+
* The trigger and menu are the official DSH primitives: the menu geometry,
|
|
116
|
+
* icons, check marker, portal placement, and keyboard handling therefore match
|
|
117
|
+
* the Auto-review permission selector. The dropdown is off by default; the
|
|
118
|
+
* server state is polled because the agent can arm it through
|
|
119
|
+
* set_session_end_action while a turn is running.
|
|
122
120
|
*/
|
|
123
121
|
export function SessionEndControl(props: SessionEndControlProps) {
|
|
124
122
|
const { t } = props
|
|
@@ -126,9 +124,6 @@ export function SessionEndControl(props: SessionEndControlProps) {
|
|
|
126
124
|
const [state, setState] = useState<State>(INITIAL)
|
|
127
125
|
const [busy, setBusy] = useState(false)
|
|
128
126
|
const [open, setOpen] = useState(false)
|
|
129
|
-
const [menu, setMenu] = useState({ left: 0, bottom: 0, minWidth: 0 })
|
|
130
|
-
const triggerRef = useRef<HTMLButtonElement>(null)
|
|
131
|
-
const menuRef = useRef<HTMLDivElement>(null)
|
|
132
127
|
|
|
133
128
|
useEffect(() => {
|
|
134
129
|
if (sessionId === undefined || sessionId === '') {
|
|
@@ -145,11 +140,7 @@ export function SessionEndControl(props: SessionEndControlProps) {
|
|
|
145
140
|
})
|
|
146
141
|
const body = await response.json() as Partial<State> & { ok?: boolean }
|
|
147
142
|
if (cancelled || body.ok !== true) return
|
|
148
|
-
setState(prev => ({
|
|
149
|
-
...prev,
|
|
150
|
-
...body,
|
|
151
|
-
available: body.available ?? prev.available,
|
|
152
|
-
}))
|
|
143
|
+
setState(prev => ({ ...prev, ...body, available: body.available ?? prev.available }))
|
|
153
144
|
} catch {
|
|
154
145
|
/* a transient poll failure leaves the last known state in place */
|
|
155
146
|
}
|
|
@@ -162,48 +153,10 @@ export function SessionEndControl(props: SessionEndControlProps) {
|
|
|
162
153
|
}
|
|
163
154
|
}, [sessionId])
|
|
164
155
|
|
|
165
|
-
useEffect(() =>
|
|
166
|
-
if (!open) return
|
|
167
|
-
const close = (): void => { setOpen(false) }
|
|
168
|
-
const onPointer = (event: MouseEvent): void => {
|
|
169
|
-
const target = event.target as Node
|
|
170
|
-
if (triggerRef.current?.contains(target) || menuRef.current?.contains(target)) return
|
|
171
|
-
setOpen(false)
|
|
172
|
-
}
|
|
173
|
-
const onKey = (event: KeyboardEvent): void => {
|
|
174
|
-
if (event.key === 'Escape') setOpen(false)
|
|
175
|
-
}
|
|
176
|
-
document.addEventListener('mousedown', onPointer)
|
|
177
|
-
document.addEventListener('keydown', onKey)
|
|
178
|
-
window.addEventListener('resize', close)
|
|
179
|
-
window.addEventListener('scroll', close, true)
|
|
180
|
-
return () => {
|
|
181
|
-
document.removeEventListener('mousedown', onPointer)
|
|
182
|
-
document.removeEventListener('keydown', onKey)
|
|
183
|
-
window.removeEventListener('resize', close)
|
|
184
|
-
window.removeEventListener('scroll', close, true)
|
|
185
|
-
}
|
|
186
|
-
}, [open])
|
|
156
|
+
useEffect(() => startSessionEndGlobalNotice(), [])
|
|
187
157
|
|
|
188
158
|
if (sessionId === undefined || sessionId === '') return null
|
|
189
159
|
|
|
190
|
-
|
|
191
|
-
const toggleMenu = (): void => {
|
|
192
|
-
if (open) {
|
|
193
|
-
setOpen(false)
|
|
194
|
-
return
|
|
195
|
-
}
|
|
196
|
-
const rect = triggerRef.current?.getBoundingClientRect()
|
|
197
|
-
if (rect === undefined) return
|
|
198
|
-
const minWidth = Math.max(rect.width, 176)
|
|
199
|
-
const left = Math.min(
|
|
200
|
-
Math.max(8, rect.left),
|
|
201
|
-
Math.max(8, window.innerWidth - minWidth - 8),
|
|
202
|
-
)
|
|
203
|
-
setMenu({ left, bottom: window.innerHeight - rect.top + 6, minWidth })
|
|
204
|
-
setOpen(true)
|
|
205
|
-
}
|
|
206
|
-
|
|
207
160
|
const change = (mode: Mode): void => {
|
|
208
161
|
setOpen(false)
|
|
209
162
|
if (mode === 'shutdown' && typeof window !== 'undefined' && typeof window.confirm === 'function') {
|
|
@@ -224,11 +177,7 @@ export function SessionEndControl(props: SessionEndControlProps) {
|
|
|
224
177
|
.then(async response => await response.json() as Partial<State> & { ok?: boolean })
|
|
225
178
|
.then(body => {
|
|
226
179
|
if (body.ok === true) {
|
|
227
|
-
setState(prev => ({
|
|
228
|
-
...prev,
|
|
229
|
-
...body,
|
|
230
|
-
available: body.available ?? prev.available,
|
|
231
|
-
}))
|
|
180
|
+
setState(prev => ({ ...prev, ...body, available: body.available ?? prev.available }))
|
|
232
181
|
}
|
|
233
182
|
})
|
|
234
183
|
.catch(() => { /* the next poll reconciles */ })
|
|
@@ -247,8 +196,65 @@ export function SessionEndControl(props: SessionEndControlProps) {
|
|
|
247
196
|
: state.waiting ? t('sessionEnd.aiWaiting') : t('sessionEnd.aiRestart')
|
|
248
197
|
: ''
|
|
249
198
|
|
|
199
|
+
const items = [
|
|
200
|
+
{ id: 'off', label: t('sessionEnd.off'), icon: <IconClockOutlineRegular /> },
|
|
201
|
+
{
|
|
202
|
+
id: 'restart',
|
|
203
|
+
label: t('sessionEnd.restart'),
|
|
204
|
+
icon: <IconRefreshOutlineRegular />,
|
|
205
|
+
disabled: !state.available.restart,
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
id: 'close',
|
|
209
|
+
label: t('sessionEnd.close'),
|
|
210
|
+
icon: <IconCloseCircleFillRegular />,
|
|
211
|
+
disabled: !state.available.close,
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
id: 'shutdown',
|
|
215
|
+
label: t('sessionEnd.shutdown'),
|
|
216
|
+
icon: <IconStopFillRegular />,
|
|
217
|
+
disabled: !state.available.shutdown,
|
|
218
|
+
danger: true,
|
|
219
|
+
},
|
|
220
|
+
]
|
|
221
|
+
|
|
222
|
+
const anchor = (
|
|
223
|
+
<button
|
|
224
|
+
type="button"
|
|
225
|
+
className="mcviseron-session-end-trigger"
|
|
226
|
+
aria-label={t('sessionEnd.label')}
|
|
227
|
+
aria-haspopup="menu"
|
|
228
|
+
aria-expanded={open}
|
|
229
|
+
title={t('sessionEnd.hint')}
|
|
230
|
+
style={triggerStyle}
|
|
231
|
+
disabled={busy}
|
|
232
|
+
onClick={() => { setOpen(value => !value) }}
|
|
233
|
+
>
|
|
234
|
+
<span style={{ display: 'inline-flex', flex: 'none' }}>{triggerIcon(state.mode)}</span>
|
|
235
|
+
<span style={{ minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
|
|
236
|
+
{t(
|
|
237
|
+
state.mode === 'off'
|
|
238
|
+
? 'sessionEnd.off'
|
|
239
|
+
: state.mode === 'restart'
|
|
240
|
+
? 'sessionEnd.restart'
|
|
241
|
+
: state.mode === 'close'
|
|
242
|
+
? 'sessionEnd.close'
|
|
243
|
+
: 'sessionEnd.shutdown',
|
|
244
|
+
)}
|
|
245
|
+
</span>
|
|
246
|
+
<span
|
|
247
|
+
className={open ? 'mcviseron-session-end-chevron open' : 'mcviseron-session-end-chevron'}
|
|
248
|
+
aria-hidden
|
|
249
|
+
>
|
|
250
|
+
<IconChevronDownOutlineRegular />
|
|
251
|
+
</span>
|
|
252
|
+
</button>
|
|
253
|
+
)
|
|
254
|
+
|
|
250
255
|
return (
|
|
251
256
|
<span style={{ display: 'inline-flex', alignItems: 'center', gap: 6, flexWrap: 'wrap' }}>
|
|
257
|
+
<style>{TRIGGER_CSS}</style>
|
|
252
258
|
{notice !== '' && (
|
|
253
259
|
<span
|
|
254
260
|
style={shutdown ? shutdownNoticeStyle : noticeStyle}
|
|
@@ -257,75 +263,19 @@ export function SessionEndControl(props: SessionEndControlProps) {
|
|
|
257
263
|
{notice}
|
|
258
264
|
</span>
|
|
259
265
|
)}
|
|
260
|
-
<style>{`
|
|
261
|
-
.mcviseron-session-end-trigger { transition: background 120ms ease, border-color 120ms ease; }
|
|
262
|
-
.mcviseron-session-end-trigger:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover, var(--dsw-alias-bg-layer-3)); }
|
|
263
|
-
.mcviseron-session-end-option { transition: background 120ms ease; }
|
|
264
|
-
.mcviseron-session-end-option:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover, var(--dsw-alias-bg-layer-3)); }
|
|
265
|
-
`}</style>
|
|
266
266
|
<span style={labelStyle} title={t('sessionEnd.hint')}>
|
|
267
267
|
<span>{t('sessionEnd.label')}</span>
|
|
268
|
-
<
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
}}
|
|
280
|
-
disabled={busy}
|
|
281
|
-
onClick={toggleMenu}
|
|
282
|
-
>
|
|
283
|
-
<span>{t(
|
|
284
|
-
state.mode === 'off'
|
|
285
|
-
? 'sessionEnd.off'
|
|
286
|
-
: state.mode === 'restart'
|
|
287
|
-
? 'sessionEnd.restart'
|
|
288
|
-
: state.mode === 'close'
|
|
289
|
-
? 'sessionEnd.close'
|
|
290
|
-
: 'sessionEnd.shutdown',
|
|
291
|
-
)}</span>
|
|
292
|
-
<span aria-hidden style={{ fontSize: 10, opacity: 0.75 }}>{open ? '▴' : '▾'}</span>
|
|
293
|
-
</button>
|
|
294
|
-
{open && (
|
|
295
|
-
<div
|
|
296
|
-
ref={menuRef}
|
|
297
|
-
role="listbox"
|
|
298
|
-
aria-label={t('sessionEnd.label')}
|
|
299
|
-
style={{ ...menuStyle, left: menu.left, bottom: menu.bottom, minWidth: menu.minWidth }}
|
|
300
|
-
>
|
|
301
|
-
{([
|
|
302
|
-
['off', 'sessionEnd.off', false],
|
|
303
|
-
['restart', 'sessionEnd.restart', !state.available.restart],
|
|
304
|
-
['close', 'sessionEnd.close', !state.available.close],
|
|
305
|
-
['shutdown', 'sessionEnd.shutdown', !state.available.shutdown],
|
|
306
|
-
] as const).map(([value, label, disabled]) => (
|
|
307
|
-
<button
|
|
308
|
-
key={value}
|
|
309
|
-
type="button"
|
|
310
|
-
role="option"
|
|
311
|
-
aria-selected={state.mode === value}
|
|
312
|
-
disabled={disabled}
|
|
313
|
-
className="mcviseron-session-end-option"
|
|
314
|
-
style={{
|
|
315
|
-
...menuOptionStyle,
|
|
316
|
-
color: state.mode === value ? 'var(--dsw-alias-brand-primary)' : menuOptionStyle.color,
|
|
317
|
-
fontWeight: state.mode === value ? 600 : 400,
|
|
318
|
-
opacity: disabled ? 0.45 : 1,
|
|
319
|
-
cursor: disabled ? 'default' : 'pointer',
|
|
320
|
-
}}
|
|
321
|
-
onClick={() => { if (!disabled) change(value) }}
|
|
322
|
-
>
|
|
323
|
-
<span>{t(label)}</span>
|
|
324
|
-
{state.mode === value ? <span aria-hidden>✓</span> : null}
|
|
325
|
-
</button>
|
|
326
|
-
))}
|
|
327
|
-
</div>
|
|
328
|
-
)}
|
|
268
|
+
<Menu
|
|
269
|
+
open={open}
|
|
270
|
+
anchor={anchor}
|
|
271
|
+
items={items}
|
|
272
|
+
selectedId={state.mode}
|
|
273
|
+
onSelect={id => { change(id as Mode) }}
|
|
274
|
+
onClose={() => { setOpen(false) }}
|
|
275
|
+
align="end"
|
|
276
|
+
side="top"
|
|
277
|
+
portal
|
|
278
|
+
/>
|
|
329
279
|
</span>
|
|
330
280
|
</span>
|
|
331
281
|
)
|