dsh-auto-review 0.4.0
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 +91 -0
- package/LICENSE +201 -0
- package/README.es.md +226 -0
- package/README.hi.md +226 -0
- package/README.md +226 -0
- package/README.pt.md +226 -0
- package/README.zh.md +226 -0
- package/cordis.patch.yml +27 -0
- package/lib/client.js +494 -0
- package/lib/client.js.map +1 -0
- package/lib/events-CFl6CHZi.js +344 -0
- package/lib/index.js +5305 -0
- package/lib/invariant.js +223 -0
- package/lib/types/client/ReviewPanel.d.ts +29 -0
- package/lib/types/client/ReviewPanel.d.ts.map +1 -0
- package/lib/types/client/ReviewPanel.js +63 -0
- package/lib/types/client/ReviewPanel.js.map +1 -0
- package/lib/types/client/index.d.ts +31 -0
- package/lib/types/client/index.d.ts.map +1 -0
- package/lib/types/client/index.js +51 -0
- package/lib/types/client/index.js.map +1 -0
- package/lib/types/client/locales.d.ts +49 -0
- package/lib/types/client/locales.d.ts.map +1 -0
- package/lib/types/client/locales.js +82 -0
- package/lib/types/client/locales.js.map +1 -0
- package/lib/types/client/present.d.ts +25 -0
- package/lib/types/client/present.d.ts.map +1 -0
- package/lib/types/client/present.js +36 -0
- package/lib/types/client/present.js.map +1 -0
- package/lib/types/client/styles.d.ts +9 -0
- package/lib/types/client/styles.d.ts.map +1 -0
- package/lib/types/client/styles.js +130 -0
- package/lib/types/client/styles.js.map +1 -0
- package/lib/types/config.d.ts +200 -0
- package/lib/types/config.d.ts.map +1 -0
- package/lib/types/config.js +154 -0
- package/lib/types/config.js.map +1 -0
- package/lib/types/events.d.ts +347 -0
- package/lib/types/events.d.ts.map +1 -0
- package/lib/types/events.js +369 -0
- package/lib/types/events.js.map +1 -0
- package/lib/types/index.d.ts +26 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +26 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/invariant.d.ts +28 -0
- package/lib/types/invariant.d.ts.map +1 -0
- package/lib/types/invariant.js +306 -0
- package/lib/types/invariant.js.map +1 -0
- package/lib/types/messages.d.ts +38 -0
- package/lib/types/messages.d.ts.map +1 -0
- package/lib/types/messages.js +65 -0
- package/lib/types/messages.js.map +1 -0
- package/lib/types/projection-types.d.ts +61 -0
- package/lib/types/projection-types.d.ts.map +1 -0
- package/lib/types/projection-types.js +8 -0
- package/lib/types/projection-types.js.map +1 -0
- package/lib/types/projection.d.ts +93 -0
- package/lib/types/projection.d.ts.map +1 -0
- package/lib/types/projection.js +197 -0
- package/lib/types/projection.js.map +1 -0
- package/lib/types/review.d.ts +141 -0
- package/lib/types/review.d.ts.map +1 -0
- package/lib/types/review.js +389 -0
- package/lib/types/review.js.map +1 -0
- package/lib/types/runtime.d.ts +160 -0
- package/lib/types/runtime.d.ts.map +1 -0
- package/lib/types/runtime.js +486 -0
- package/lib/types/runtime.js.map +1 -0
- package/package.json +132 -0
- package/src/client/ReviewPanel.tsx +164 -0
- package/src/client/index.ts +72 -0
- package/src/client/locales.ts +87 -0
- package/src/client/present.ts +58 -0
- package/src/client/styles.ts +131 -0
- package/src/config.ts +346 -0
- package/src/events.ts +553 -0
- package/src/index.ts +28 -0
- package/src/invariant.ts +326 -0
- package/src/messages.ts +91 -0
- package/src/projection-types.ts +61 -0
- package/src/projection.ts +224 -0
- package/src/review.ts +428 -0
- package/src/runtime.ts +562 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The session-header review panel: a button in the conversation header that
|
|
3
|
+
* opens a popover with this session's auto-review state — the on/off switch,
|
|
4
|
+
* budgets, cumulative statistics (including hard-disable rejections), the
|
|
5
|
+
* circuit trip, recent verdicts, and one-shot approve buttons for recent
|
|
6
|
+
* denials. Data arrives through the `autoReview` session projection;
|
|
7
|
+
* switches and approves execute the `/auto-review` command through the
|
|
8
|
+
* commands Remote.
|
|
9
|
+
* @module dsh-auto-review/client/ReviewPanel
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { useRef, useState, type ReactNode } from 'react'
|
|
13
|
+
import type { InjectFace, PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots'
|
|
14
|
+
import type { AutoReviewProjection } from '../projection-types.ts'
|
|
15
|
+
import { presentVerdict } from './present.ts'
|
|
16
|
+
import { NS } from './locales.ts'
|
|
17
|
+
|
|
18
|
+
/** Registration-side injected face: the approve action for one recent denial. */
|
|
19
|
+
export interface ReviewPanelInjected {
|
|
20
|
+
/** Approve the n-th most recent denial (1 = most recent); resolves with the command result text. */
|
|
21
|
+
approve: (n: number) => Promise<string>
|
|
22
|
+
/** Switch the session's auto-review on/off (`/auto-review on|off`); resolves with the command result text. */
|
|
23
|
+
setEnabled: (enabled: boolean) => Promise<string>
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Full component props assembled by the session-header slot renderer. */
|
|
27
|
+
export type ReviewPanelProps =
|
|
28
|
+
PropsRuntime<'conversation.session.header.actions'>
|
|
29
|
+
& PropsLocale<typeof NS>
|
|
30
|
+
& InjectFace<ReviewPanelInjected>
|
|
31
|
+
|
|
32
|
+
/** Compact verdict-row badge label for the panel. */
|
|
33
|
+
function verdictBadge(
|
|
34
|
+
value: AutoReviewProjection | undefined,
|
|
35
|
+
t: ReviewPanelProps['t'],
|
|
36
|
+
): ReactNode {
|
|
37
|
+
if (value === undefined) return t('unavailable')
|
|
38
|
+
const fallback = (kind: string): string => t('fallbackLabel').replace('{kind}', kind)
|
|
39
|
+
const labels = {
|
|
40
|
+
allow: t('decisionAllow'),
|
|
41
|
+
deny: t('decisionDeny'),
|
|
42
|
+
fallback,
|
|
43
|
+
escalation: t('escalationLabel'),
|
|
44
|
+
}
|
|
45
|
+
return value.recent.map(verdict => presentVerdict(verdict, labels)).map(row => (
|
|
46
|
+
<div key={row.reviewId} data-dsh-auto-review-verdict>
|
|
47
|
+
<span data-dsh-auto-review-muted>{row.toolName}</span>
|
|
48
|
+
<span data-dsh-auto-review={`tone-${row.tone}`}>{row.label}</span>
|
|
49
|
+
<span data-dsh-auto-review-muted>{row.detail}</span>
|
|
50
|
+
</div>
|
|
51
|
+
))
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Render the review panel action.
|
|
56
|
+
* @param props - framework kit (sessionId, useProjection), locale, and the approve face.
|
|
57
|
+
* @returns the header button with its popover.
|
|
58
|
+
*/
|
|
59
|
+
export function ReviewPanel({ useProjection, approve, setEnabled, t }: ReviewPanelProps): ReactNode {
|
|
60
|
+
const value = useProjection('autoReview')
|
|
61
|
+
const [open, setOpen] = useState(false)
|
|
62
|
+
const [notice, setNotice] = useState<string | null>(null)
|
|
63
|
+
const anchor = useRef<HTMLDivElement | null>(null)
|
|
64
|
+
const toggle = (): void => setOpen(previous => !previous)
|
|
65
|
+
const runApprove = async (n: number): Promise<void> => {
|
|
66
|
+
try {
|
|
67
|
+
const text = await approve(n)
|
|
68
|
+
setNotice(t('approveResult').replace('{text}', text))
|
|
69
|
+
} catch (error: unknown) {
|
|
70
|
+
setNotice(t('approveFailed').replace('{text}', error instanceof Error ? error.message : String(error)))
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const runSwitch = async (enabled: boolean): Promise<void> => {
|
|
74
|
+
try {
|
|
75
|
+
const text = await setEnabled(enabled)
|
|
76
|
+
setNotice(t('switchedResult').replace('{text}', text))
|
|
77
|
+
} catch (error: unknown) {
|
|
78
|
+
setNotice(t('switchFailed').replace('{text}', error instanceof Error ? error.message : String(error)))
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return (
|
|
82
|
+
<div data-dsh-auto-review ref={anchor}>
|
|
83
|
+
<button type="button" data-dsh-auto-review-button onClick={toggle}>
|
|
84
|
+
{t('label')}
|
|
85
|
+
</button>
|
|
86
|
+
{open && (
|
|
87
|
+
<div data-dsh-auto-review-panel>
|
|
88
|
+
<div data-dsh-auto-review-title>{t('title')}</div>
|
|
89
|
+
{value === undefined
|
|
90
|
+
? <div data-dsh-auto-review-muted>{t('unavailable')}</div>
|
|
91
|
+
: (
|
|
92
|
+
<div>
|
|
93
|
+
<div data-dsh-auto-review-row>
|
|
94
|
+
<span>{t('state')}</span>
|
|
95
|
+
<span>{value.enabled ? t('stateOn') : t('stateOff')}</span>
|
|
96
|
+
</div>
|
|
97
|
+
<div data-dsh-auto-review-row>
|
|
98
|
+
<span>{t('enable')} / {t('disable')}</span>
|
|
99
|
+
<span>
|
|
100
|
+
<button
|
|
101
|
+
type="button"
|
|
102
|
+
data-dsh-auto-review-switch
|
|
103
|
+
disabled={value.enabled}
|
|
104
|
+
onClick={() => void runSwitch(true)}
|
|
105
|
+
>
|
|
106
|
+
{t('enable')}
|
|
107
|
+
</button>
|
|
108
|
+
<button
|
|
109
|
+
type="button"
|
|
110
|
+
data-dsh-auto-review-switch
|
|
111
|
+
disabled={!value.enabled}
|
|
112
|
+
onClick={() => void runSwitch(false)}
|
|
113
|
+
>
|
|
114
|
+
{t('disable')}
|
|
115
|
+
</button>
|
|
116
|
+
</span>
|
|
117
|
+
</div>
|
|
118
|
+
<div data-dsh-auto-review-row>
|
|
119
|
+
<span>{t('verdicts')}</span>
|
|
120
|
+
<span>{value.verdictsUsed}</span>
|
|
121
|
+
</div>
|
|
122
|
+
<div data-dsh-auto-review-row>
|
|
123
|
+
<span>{t('failures')}</span>
|
|
124
|
+
<span>{value.failuresUsed}</span>
|
|
125
|
+
</div>
|
|
126
|
+
<div data-dsh-auto-review-row>
|
|
127
|
+
<span>{t('allTime')}</span>
|
|
128
|
+
<span>
|
|
129
|
+
{value.allows} {t('allows')} · {value.denies} {t('denies')} · {value.fallbacks} {t('fallbacks')} · {value.neverRejects} {t('neverRejects')} · {t('avg')} {value.avgDurationMs} {t('ms')}
|
|
130
|
+
</span>
|
|
131
|
+
</div>
|
|
132
|
+
{value.circuit !== null && (
|
|
133
|
+
<div data-dsh-auto-review-circuit>
|
|
134
|
+
{t('circuit')} — {t('circuitDetail')
|
|
135
|
+
.replace('{kind}', value.circuit.trip.kind)
|
|
136
|
+
.replace('{count}', String(value.circuit.trip.count))
|
|
137
|
+
.replace('{action}', value.circuit.action)}
|
|
138
|
+
</div>
|
|
139
|
+
)}
|
|
140
|
+
{value.recentDenies.length > 0 && (
|
|
141
|
+
<div data-dsh-auto-review-section>
|
|
142
|
+
<div data-dsh-auto-review-title>{t('denyList')}</div>
|
|
143
|
+
{value.recentDenies.map((deny, index) => (
|
|
144
|
+
<div key={deny.reviewId} data-dsh-auto-review-row>
|
|
145
|
+
<span data-dsh-auto-review-muted>{deny.toolName}</span>
|
|
146
|
+
<button type="button" data-dsh-auto-review-approve onClick={() => void runApprove(index + 1)}>
|
|
147
|
+
{t('approve')} #{index + 1}
|
|
148
|
+
</button>
|
|
149
|
+
</div>
|
|
150
|
+
))}
|
|
151
|
+
</div>
|
|
152
|
+
)}
|
|
153
|
+
<div data-dsh-auto-review-section>
|
|
154
|
+
<div data-dsh-auto-review-title>{t('recent')}</div>
|
|
155
|
+
{value.recent.length === 0 ? <div data-dsh-auto-review-muted>{t('empty')}</div> : verdictBadge(value, t)}
|
|
156
|
+
</div>
|
|
157
|
+
</div>
|
|
158
|
+
)}
|
|
159
|
+
{notice !== null && <div data-dsh-auto-review-muted>{notice}</div>}
|
|
160
|
+
</div>
|
|
161
|
+
)}
|
|
162
|
+
</div>
|
|
163
|
+
)
|
|
164
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `dsh-auto-review`, browser half: registers the locale dictionaries, the
|
|
3
|
+
* scoped stylesheet, and the session-header review panel action. All data
|
|
4
|
+
* arrives through the `autoReview` session projection; the approve buttons
|
|
5
|
+
* execute the `/auto-review approve [n]` command through the commands
|
|
6
|
+
* Remote namespace.
|
|
7
|
+
*
|
|
8
|
+
* @module dsh-auto-review/client
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { ClientContext, SessionId } from '@deepseek-ai/dsh-client-runtime/client'
|
|
12
|
+
import type {} from '@deepseek-ai/dsh-client-locale/client'
|
|
13
|
+
// Type-only: pulls the 'conversation.session.header.actions' SlotMap
|
|
14
|
+
// declaration into this program so the registration typechecks.
|
|
15
|
+
import type {} from '@deepseek-ai/dsh-client-ui-conversation/client'
|
|
16
|
+
// Type-only: merges the commands namespace onto ctx.remote.
|
|
17
|
+
import type {} from '@deepseek-ai/dsh-api-remotes/client'
|
|
18
|
+
import type {} from '../projection-types.ts'
|
|
19
|
+
import { ReviewPanel, type ReviewPanelInjected } from './ReviewPanel.tsx'
|
|
20
|
+
import { en, NS, zh, type ReviewPanelLocaleKey } from './locales.ts'
|
|
21
|
+
import { installPanelStyles } from './styles.ts'
|
|
22
|
+
|
|
23
|
+
declare module '@deepseek-ai/dsh-client-ui-slots' {
|
|
24
|
+
interface LocaleNamespaceMap {
|
|
25
|
+
/** Review panel copy. */
|
|
26
|
+
'autoReviewPanel': ReviewPanelLocaleKey
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type { ReviewPanelProps, ReviewPanelInjected } from './ReviewPanel.tsx'
|
|
31
|
+
export type { ReviewPanelLocaleKey } from './locales.ts'
|
|
32
|
+
export { presentVerdict, type PresentedVerdict, type VerdictTone } from './present.ts'
|
|
33
|
+
|
|
34
|
+
/** Plugin name: matches the package name, the graph row id, and the bundle id. */
|
|
35
|
+
export const name = 'dsh-auto-review'
|
|
36
|
+
|
|
37
|
+
/** Services the panel reads; `remote.commands` is mounted by the api-remotes client. */
|
|
38
|
+
export const inject = ['slots', 'locale', 'remote', 'remote.commands']
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Browser plugin body: dictionaries, the scoped stylesheet, and the
|
|
42
|
+
* session-header action registration.
|
|
43
|
+
* @param ctx - client root context.
|
|
44
|
+
*/
|
|
45
|
+
export function apply(ctx: ClientContext): void {
|
|
46
|
+
ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'dsh-auto-review: dictionaries')
|
|
47
|
+
ctx.effect(() => installPanelStyles(), 'dsh-auto-review: stylesheet')
|
|
48
|
+
ctx.slots.inject(
|
|
49
|
+
'conversation.session.header.actions',
|
|
50
|
+
() => ctx.slots.register({
|
|
51
|
+
name: 'conversation.session.header.actions',
|
|
52
|
+
id: 'auto-review',
|
|
53
|
+
order: 40,
|
|
54
|
+
locale: NS,
|
|
55
|
+
inject: (sessionId: SessionId): ReviewPanelInjected => {
|
|
56
|
+
const executeCommand = async (line: string): Promise<string> => {
|
|
57
|
+
const result = await ctx.remote.commands.execute(sessionId, line)
|
|
58
|
+
if (!result.ok) throw new Error(`${result.error.code}: ${result.error.message}`)
|
|
59
|
+
if (result.value === undefined) throw new Error('unknown command: /auto-review')
|
|
60
|
+
const command = result.value.result
|
|
61
|
+
if (command === undefined) throw new Error('/auto-review produced no command result')
|
|
62
|
+
const text = command.text ?? ''
|
|
63
|
+
return command.kind === 'success' ? text : `${command.kind}: ${text}`
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
approve: async (n: number): Promise<string> => executeCommand(`/auto-review approve ${n}`),
|
|
67
|
+
setEnabled: async (enabled: boolean): Promise<string> => executeCommand(`/auto-review ${enabled ? 'on' : 'off'}`),
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
}, ReviewPanel),
|
|
71
|
+
)
|
|
72
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copy dictionaries for the auto-review session-header panel (en/zh — the
|
|
3
|
+
* harness locale registry accepts these two UI language codes today).
|
|
4
|
+
* @module dsh-auto-review/client/locales
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** Simplified Chinese dictionary and key source of truth. */
|
|
8
|
+
export const zh = {
|
|
9
|
+
label: 'AI 审查',
|
|
10
|
+
title: 'AI 自动审查',
|
|
11
|
+
state: '状态',
|
|
12
|
+
stateOn: '已开启',
|
|
13
|
+
stateOff: '已关闭',
|
|
14
|
+
enable: '开启',
|
|
15
|
+
disable: '关闭',
|
|
16
|
+
verdicts: '本回合 AI 裁决',
|
|
17
|
+
failures: '本回合失败',
|
|
18
|
+
allTime: '累计',
|
|
19
|
+
allows: '放行',
|
|
20
|
+
denies: '拒绝',
|
|
21
|
+
fallbacks: '失败',
|
|
22
|
+
neverRejects: '硬禁用拒绝',
|
|
23
|
+
avg: '平均耗时',
|
|
24
|
+
circuit: '拒绝熔断器已触发',
|
|
25
|
+
circuitDetail: '触发类型:{kind},计数 {count},动作 {action}',
|
|
26
|
+
empty: '本会话暂无 AI 审查裁决。',
|
|
27
|
+
recent: '最近裁决',
|
|
28
|
+
denyList: '可批准的重试',
|
|
29
|
+
approve: '批准重试',
|
|
30
|
+
approveResult: '已授权:{text}',
|
|
31
|
+
approveFailed: '批准失败:{text}',
|
|
32
|
+
switchedResult: '已切换:{text}',
|
|
33
|
+
switchFailed: '切换失败:{text}',
|
|
34
|
+
unavailable: '审查面板不可用(宿主未提供会话投影能力)。',
|
|
35
|
+
decisionAllow: '放行',
|
|
36
|
+
decisionDeny: '拒绝',
|
|
37
|
+
fallbackLabel: '失败({kind})',
|
|
38
|
+
escalationLabel: '风险策略升级',
|
|
39
|
+
riskLow: '低风险',
|
|
40
|
+
riskMedium: '中风险',
|
|
41
|
+
riskHigh: '高风险',
|
|
42
|
+
ms: 'ms',
|
|
43
|
+
} satisfies Record<string, string>
|
|
44
|
+
|
|
45
|
+
/** Auto-review panel locale key union. */
|
|
46
|
+
export type ReviewPanelLocaleKey = keyof typeof zh
|
|
47
|
+
|
|
48
|
+
/** English dictionary checked against the Chinese key set. */
|
|
49
|
+
export const en: Record<ReviewPanelLocaleKey, string> = {
|
|
50
|
+
label: 'AI Review',
|
|
51
|
+
title: 'AI Auto-Review',
|
|
52
|
+
state: 'State',
|
|
53
|
+
stateOn: 'ON',
|
|
54
|
+
stateOff: 'OFF',
|
|
55
|
+
enable: 'Enable',
|
|
56
|
+
disable: 'Disable',
|
|
57
|
+
verdicts: 'AI verdicts this turn',
|
|
58
|
+
failures: 'Failures this turn',
|
|
59
|
+
allTime: 'All-time',
|
|
60
|
+
allows: 'allows',
|
|
61
|
+
denies: 'denies',
|
|
62
|
+
fallbacks: 'fallbacks',
|
|
63
|
+
neverRejects: 'never rejects',
|
|
64
|
+
avg: 'avg',
|
|
65
|
+
circuit: 'Rejection circuit breaker tripped',
|
|
66
|
+
circuitDetail: '{kind}: {count} denials, action {action}',
|
|
67
|
+
empty: 'No AI review verdicts in this session yet.',
|
|
68
|
+
recent: 'Recent verdicts',
|
|
69
|
+
denyList: 'Approvable retries',
|
|
70
|
+
approve: 'Approve retry',
|
|
71
|
+
approveResult: 'Authorized: {text}',
|
|
72
|
+
approveFailed: 'Approve failed: {text}',
|
|
73
|
+
switchedResult: 'Switched: {text}',
|
|
74
|
+
switchFailed: 'Switch failed: {text}',
|
|
75
|
+
unavailable: 'The review panel is unavailable (the host does not provide the session-projection capability).',
|
|
76
|
+
decisionAllow: 'allow',
|
|
77
|
+
decisionDeny: 'deny',
|
|
78
|
+
fallbackLabel: 'fallback ({kind})',
|
|
79
|
+
escalationLabel: 'risk-policy escalation',
|
|
80
|
+
riskLow: 'low risk',
|
|
81
|
+
riskMedium: 'medium risk',
|
|
82
|
+
riskHigh: 'high risk',
|
|
83
|
+
ms: 'ms',
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Dictionary namespace owned by this plugin. */
|
|
87
|
+
export const NS = 'autoReviewPanel'
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure presentation for the review panel: verdict rows and badges as plain
|
|
3
|
+
* strings and tone codes — no I/O, clock, or randomness. The component
|
|
4
|
+
* owns layout and interaction; this module owns the text.
|
|
5
|
+
* @module dsh-auto-review/client/present
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { AutoReviewVerdictView } from '../projection-types.ts'
|
|
9
|
+
|
|
10
|
+
/** Badge tones the component maps to scoped styles. */
|
|
11
|
+
export type VerdictTone = 'allow' | 'deny' | 'fallback' | 'escalation'
|
|
12
|
+
|
|
13
|
+
/** One presented verdict row. */
|
|
14
|
+
export interface PresentedVerdict {
|
|
15
|
+
readonly reviewId: string
|
|
16
|
+
readonly toolName: string
|
|
17
|
+
readonly label: string
|
|
18
|
+
readonly detail: string
|
|
19
|
+
readonly tone: VerdictTone
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Present one verdict row (the component supplies the localized label texts). */
|
|
23
|
+
export function presentVerdict(
|
|
24
|
+
verdict: AutoReviewVerdictView,
|
|
25
|
+
labels: {
|
|
26
|
+
readonly allow: string
|
|
27
|
+
readonly deny: string
|
|
28
|
+
readonly fallback: (kind: string) => string
|
|
29
|
+
readonly escalation: string
|
|
30
|
+
},
|
|
31
|
+
): PresentedVerdict {
|
|
32
|
+
if (verdict.fallback !== undefined) {
|
|
33
|
+
return {
|
|
34
|
+
reviewId: verdict.reviewId,
|
|
35
|
+
toolName: verdict.toolName,
|
|
36
|
+
label: labels.fallback(verdict.fallback),
|
|
37
|
+
detail: `${verdict.durationMs} ms`,
|
|
38
|
+
tone: 'fallback',
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (verdict.escalation === 'risk-policy') {
|
|
42
|
+
return {
|
|
43
|
+
reviewId: verdict.reviewId,
|
|
44
|
+
toolName: verdict.toolName,
|
|
45
|
+
label: labels.escalation,
|
|
46
|
+
detail: verdict.reason ?? '',
|
|
47
|
+
tone: 'escalation',
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const label = verdict.decision === 'deny' ? labels.deny : labels.allow
|
|
51
|
+
return {
|
|
52
|
+
reviewId: verdict.reviewId,
|
|
53
|
+
toolName: verdict.toolName,
|
|
54
|
+
label,
|
|
55
|
+
detail: verdict.reason ?? `${verdict.durationMs} ms`,
|
|
56
|
+
tone: verdict.decision === 'deny' ? 'deny' : 'allow',
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scoped stylesheet for the review panel. Standalone bundles cannot use the
|
|
3
|
+
* in-repo CSS-module pipeline, so the panel injects one `<style>` element
|
|
4
|
+
* whose selectors are all scoped under `[data-dsh-auto-review]`.
|
|
5
|
+
* @module dsh-auto-review/client/styles
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const STYLE_ID = 'dsh-auto-review-panel-styles'
|
|
9
|
+
|
|
10
|
+
const CSS = `
|
|
11
|
+
[data-dsh-auto-review] {
|
|
12
|
+
--ar-allow: var(--dsw-color-success, #16a34a);
|
|
13
|
+
--ar-deny: var(--dsw-color-danger, #dc2626);
|
|
14
|
+
--ar-fallback: var(--dsw-color-warning, #d97706);
|
|
15
|
+
--ar-escalation: var(--dsw-color-warning, #d97706);
|
|
16
|
+
--ar-border: var(--dsw-color-border, rgba(128, 128, 128, 0.3));
|
|
17
|
+
--ar-bg: var(--dsw-color-surface, #ffffff);
|
|
18
|
+
--ar-fg: var(--dsw-color-text, #1f2328);
|
|
19
|
+
--ar-muted: var(--dsw-color-text-muted, #6b7280);
|
|
20
|
+
font-family: inherit;
|
|
21
|
+
color: var(--ar-fg);
|
|
22
|
+
}
|
|
23
|
+
[data-dsh-auto-review-panel] {
|
|
24
|
+
position: absolute;
|
|
25
|
+
z-index: 40;
|
|
26
|
+
min-width: 320px;
|
|
27
|
+
max-width: 420px;
|
|
28
|
+
max-height: 70vh;
|
|
29
|
+
overflow-y: auto;
|
|
30
|
+
background: var(--ar-bg);
|
|
31
|
+
border: 1px solid var(--ar-border);
|
|
32
|
+
border-radius: 8px;
|
|
33
|
+
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
|
|
34
|
+
padding: 12px;
|
|
35
|
+
font-size: 12px;
|
|
36
|
+
line-height: 1.5;
|
|
37
|
+
}
|
|
38
|
+
[data-dsh-auto-review-button] {
|
|
39
|
+
display: inline-flex;
|
|
40
|
+
align-items: center;
|
|
41
|
+
gap: 4px;
|
|
42
|
+
cursor: pointer;
|
|
43
|
+
background: transparent;
|
|
44
|
+
border: 1px solid var(--ar-border);
|
|
45
|
+
border-radius: 6px;
|
|
46
|
+
padding: 3px 8px;
|
|
47
|
+
font-size: 12px;
|
|
48
|
+
color: var(--ar-fg);
|
|
49
|
+
}
|
|
50
|
+
[data-dsh-auto-review-button]:hover {
|
|
51
|
+
background: rgba(128, 128, 128, 0.12);
|
|
52
|
+
}
|
|
53
|
+
[data-dsh-auto-review-section] {
|
|
54
|
+
margin: 8px 0;
|
|
55
|
+
border-top: 1px solid var(--ar-border);
|
|
56
|
+
padding-top: 8px;
|
|
57
|
+
}
|
|
58
|
+
[data-dsh-auto-review-title] {
|
|
59
|
+
font-weight: 600;
|
|
60
|
+
margin-bottom: 6px;
|
|
61
|
+
}
|
|
62
|
+
[data-dsh-auto-review-row] {
|
|
63
|
+
display: flex;
|
|
64
|
+
justify-content: space-between;
|
|
65
|
+
gap: 8px;
|
|
66
|
+
padding: 2px 0;
|
|
67
|
+
align-items: baseline;
|
|
68
|
+
}
|
|
69
|
+
[data-dsh-auto-review-muted] {
|
|
70
|
+
color: var(--ar-muted);
|
|
71
|
+
}
|
|
72
|
+
[data-dsh-auto-review-verdict] {
|
|
73
|
+
display: flex;
|
|
74
|
+
justify-content: space-between;
|
|
75
|
+
gap: 8px;
|
|
76
|
+
padding: 3px 0;
|
|
77
|
+
border-bottom: 1px dashed var(--ar-border);
|
|
78
|
+
}
|
|
79
|
+
[data-dsh-auto-review-tone-allow] { color: var(--ar-allow); }
|
|
80
|
+
[data-dsh-auto-review-tone-deny] { color: var(--ar-deny); }
|
|
81
|
+
[data-dsh-auto-review-tone-fallback] { color: var(--ar-fallback); }
|
|
82
|
+
[data-dsh-auto-review-tone-escalation] { color: var(--ar-escalation); }
|
|
83
|
+
[data-dsh-auto-review-approve] {
|
|
84
|
+
cursor: pointer;
|
|
85
|
+
border: 1px solid var(--ar-border);
|
|
86
|
+
border-radius: 4px;
|
|
87
|
+
background: transparent;
|
|
88
|
+
color: var(--ar-fg);
|
|
89
|
+
padding: 1px 6px;
|
|
90
|
+
font-size: 11px;
|
|
91
|
+
}
|
|
92
|
+
[data-dsh-auto-review-approve]:hover {
|
|
93
|
+
background: rgba(128, 128, 128, 0.12);
|
|
94
|
+
}
|
|
95
|
+
[data-dsh-auto-review-switch] {
|
|
96
|
+
cursor: pointer;
|
|
97
|
+
border: 1px solid var(--ar-border);
|
|
98
|
+
border-radius: 4px;
|
|
99
|
+
background: transparent;
|
|
100
|
+
color: var(--ar-fg);
|
|
101
|
+
padding: 1px 6px;
|
|
102
|
+
font-size: 11px;
|
|
103
|
+
}
|
|
104
|
+
[data-dsh-auto-review-switch] + [data-dsh-auto-review-switch] {
|
|
105
|
+
margin-left: 4px;
|
|
106
|
+
}
|
|
107
|
+
[data-dsh-auto-review-switch]:hover:not(:disabled) {
|
|
108
|
+
background: rgba(128, 128, 128, 0.12);
|
|
109
|
+
}
|
|
110
|
+
[data-dsh-auto-review-approve]:disabled,
|
|
111
|
+
[data-dsh-auto-review-switch]:disabled {
|
|
112
|
+
opacity: 0.45;
|
|
113
|
+
cursor: default;
|
|
114
|
+
}
|
|
115
|
+
[data-dsh-auto-review-circuit] {
|
|
116
|
+
color: var(--ar-deny);
|
|
117
|
+
font-weight: 600;
|
|
118
|
+
}
|
|
119
|
+
`
|
|
120
|
+
|
|
121
|
+
/** Install the scoped stylesheet once per plugin fiber. */
|
|
122
|
+
export function installPanelStyles(): () => void {
|
|
123
|
+
if (document.getElementById(STYLE_ID) !== null) return () => undefined
|
|
124
|
+
const element = document.createElement('style')
|
|
125
|
+
element.id = STYLE_ID
|
|
126
|
+
element.textContent = CSS
|
|
127
|
+
document.head.appendChild(element)
|
|
128
|
+
return () => {
|
|
129
|
+
element.remove()
|
|
130
|
+
}
|
|
131
|
+
}
|