dsh-spec-collab 0.1.6 → 0.2.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/lib/client.js +838 -460
- package/lib/types/client/SpecWorkbench.d.ts.map +1 -1
- package/lib/types/client/workflow.d.ts +32 -0
- package/lib/types/client/workflow.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/client/SpecWorkbench.tsx +118 -61
- package/src/client/workbench.module.css +256 -190
- package/src/client/workflow.ts +138 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SpecWorkbench.d.ts","sourceRoot":"","sources":["../../../src/client/SpecWorkbench.tsx"],"names":[],"mappings":"AAGA,OAAO,kCAAkC,CAAA;AAGzC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAiCvC,wBAAgB,aAAa,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE;IAAE,GAAG,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,IAAI,CAAA;CAAE,+
|
|
1
|
+
{"version":3,"file":"SpecWorkbench.d.ts","sourceRoot":"","sources":["../../../src/client/SpecWorkbench.tsx"],"names":[],"mappings":"AAGA,OAAO,kCAAkC,CAAA;AAGzC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAiCvC,wBAAgB,aAAa,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE;IAAE,GAAG,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,IAAI,CAAA;CAAE,+BAoKpF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ParticipantRole, RequirementView, ReviewKind } from '../protocol.ts';
|
|
2
|
+
export type TaskView = 'review' | 'patches' | 'ready';
|
|
3
|
+
export type WorkflowCommand = {
|
|
4
|
+
kind: 'open';
|
|
5
|
+
view: TaskView;
|
|
6
|
+
} | {
|
|
7
|
+
kind: 'bind-workspace';
|
|
8
|
+
} | {
|
|
9
|
+
kind: 'request-review';
|
|
10
|
+
reviewKind: ReviewKind;
|
|
11
|
+
} | {
|
|
12
|
+
kind: 'advance';
|
|
13
|
+
} | {
|
|
14
|
+
kind: 'confirm';
|
|
15
|
+
role: ParticipantRole;
|
|
16
|
+
} | {
|
|
17
|
+
kind: 'generate-ready';
|
|
18
|
+
} | {
|
|
19
|
+
kind: 'none';
|
|
20
|
+
};
|
|
21
|
+
export interface WorkflowState {
|
|
22
|
+
eyebrow: string;
|
|
23
|
+
title: string;
|
|
24
|
+
detail: string;
|
|
25
|
+
actionLabel: string;
|
|
26
|
+
command: WorkflowCommand;
|
|
27
|
+
disabled?: boolean;
|
|
28
|
+
disabledReason?: string;
|
|
29
|
+
}
|
|
30
|
+
export declare function workflowState(requirement: RequirementView, participantRole: ParticipantRole): WorkflowState;
|
|
31
|
+
export declare function friendlyActionError(error: string): string;
|
|
32
|
+
//# sourceMappingURL=workflow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow.d.ts","sourceRoot":"","sources":["../../../src/client/workflow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAElF,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,OAAO,CAAA;AACrD,MAAM,MAAM,eAAe,GACvB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,GAChC;IAAE,IAAI,EAAE,gBAAgB,CAAA;CAAE,GAC1B;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,UAAU,EAAE,UAAU,CAAA;CAAE,GAClD;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GACnB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,eAAe,CAAA;CAAE,GAC1C;IAAE,IAAI,EAAE,gBAAgB,CAAA;CAAE,GAC1B;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAA;AAEpB,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,MAAM,CAAA;IACnB,OAAO,EAAE,eAAe,CAAA;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;AAID,wBAAgB,aAAa,CAAC,WAAW,EAAE,eAAe,EAAE,eAAe,EAAE,eAAe,GAAG,aAAa,CAmG3G;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAYzD"}
|
package/package.json
CHANGED
|
@@ -6,6 +6,7 @@ import { InputRule, inputRules } from 'prosemirror-inputrules'
|
|
|
6
6
|
import type { CollaborationAction, CommentResolution, MyActionItem, ParticipantRole, ParticipantSnapshot, RequirementStage, RequirementVersion, RequirementView, ReviewKind, ReviewWorkspaceSummary, SaveConflict } from '../protocol.ts'
|
|
7
7
|
import type { SpecApi } from './api.ts'
|
|
8
8
|
import { browserUuid } from './browser-uuid.ts'
|
|
9
|
+
import { friendlyActionError, workflowState, type TaskView, type WorkflowCommand, type WorkflowState } from './workflow.ts'
|
|
9
10
|
import css from './workbench.module.css'
|
|
10
11
|
|
|
11
12
|
const md = new MarkdownIt({ html: false, linkify: true })
|
|
@@ -20,7 +21,8 @@ const markdownShortcutsPlugin = () => ({ wysiwygPlugins: [() => inputRules({ rul
|
|
|
20
21
|
new InputRule(/^```\s$/, (state, _match, start, end) => state.tr.delete(start, end).setBlockType(start, start, state.schema.nodes.codeBlock!)),
|
|
21
22
|
inlineStyleRule(/\*\*([^*]+)\*\*$/, 'strong'), inlineStyleRule(/(?<!\*)\*([^*]+)\*$/, 'emph'), inlineStyleRule(/`([^`]+)`$/, 'code'),
|
|
22
23
|
] })] })
|
|
23
|
-
type
|
|
24
|
+
type PrimaryMode = 'tasks' | 'discussion' | 'records'
|
|
25
|
+
type RecordView = 'decisions' | 'versions'
|
|
24
26
|
type CommentAnchor = { quote: string; prefix: string; suffix: string; heading?: string }
|
|
25
27
|
function newParticipant(): ParticipantSnapshot { return { participantId: browserUuid(), nickname: '', role: 'product', kind: 'human' } }
|
|
26
28
|
function loadParticipant(): ParticipantSnapshot { try { const value = JSON.parse(localStorage.getItem('dsh-spec-collab.participant') ?? '') as ParticipantSnapshot; if (value.participantId) return { ...value, kind: 'human' } } catch {} return newParticipant() }
|
|
@@ -35,8 +37,6 @@ function currentPendingActions(requirement: RequirementView): RequirementView['a
|
|
|
35
37
|
])
|
|
36
38
|
return requirement.actionItems.filter(item => item.status === 'pending' && currentSourceIds.has(item.sourceId))
|
|
37
39
|
}
|
|
38
|
-
const tabLabel: Record<SideTab, string> = { review: '审核问题', discussion: '协作讨论', patches: '修改建议', decisions: '确认决策', items: '我的事项', versions: '版本记录', ready: '完成检查' }
|
|
39
|
-
|
|
40
40
|
export function SpecWorkbench({ api, onClose }: { api: SpecApi; onClose: () => void }) {
|
|
41
41
|
const [requirements, setRequirements] = useState<RequirementView[]>([])
|
|
42
42
|
const [reviewWorkspaces, setReviewWorkspaces] = useState<ReviewWorkspaceSummary[]>([])
|
|
@@ -58,7 +58,9 @@ export function SpecWorkbench({ api, onClose }: { api: SpecApi; onClose: () => v
|
|
|
58
58
|
const [documentsWidth, setDocumentsWidth] = useState(() => Number(localStorage.getItem('dsh-spec-collab.documents-width')) || 220)
|
|
59
59
|
const [reviewWidth, setReviewWidth] = useState(() => Number(localStorage.getItem('dsh-spec-collab.review-width')) || 430)
|
|
60
60
|
const [createForm, setCreateForm] = useState({ title: '', rawRequirement: '', sources: '', workspaceId: '' })
|
|
61
|
-
const [
|
|
61
|
+
const [primaryMode, setPrimaryMode] = useState<PrimaryMode>('tasks')
|
|
62
|
+
const [taskView, setTaskView] = useState<TaskView>('review')
|
|
63
|
+
const [recordView, setRecordView] = useState<RecordView>('decisions')
|
|
62
64
|
const [mobilePane, setMobilePane] = useState<'spec' | 'collab'>('spec')
|
|
63
65
|
const [draft, setDraft] = useState('')
|
|
64
66
|
const [summary, setSummary] = useState('')
|
|
@@ -74,18 +76,12 @@ export function SpecWorkbench({ api, onClose }: { api: SpecApi; onClose: () => v
|
|
|
74
76
|
const selected = requirements.find(item => item.id === selectedId) ?? visibleRequirements[0]
|
|
75
77
|
const manageTarget = requirements.find(item => item.id === manageTargetId)
|
|
76
78
|
const boundRole = participantBindings.find(item => item.participantId === participant.participantId)?.role
|
|
77
|
-
const productFirstRunning = selected?.aiRuns.some(run => run.kind === 'product-first' && run.commit === selected.currentCommit && ['queued', 'running'].includes(run.status)) ?? false
|
|
78
79
|
const currentMyItems = selected ? myItems.filter(item => item.requirementId === selected.id) : []
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
items: currentMyItems.length,
|
|
85
|
-
versions: 0,
|
|
86
|
-
ready: selected.readiness.filter(item => !item.passed).length,
|
|
87
|
-
} : { review: 0, discussion: 0, patches: 0, decisions: 0, items: 0, versions: 0, ready: 0 }
|
|
88
|
-
const renderSideTab = (tab: SideTab) => <button key={tab} className={sideTab === tab ? css.activeMode : ''} onClick={() => { setSideTab(tab); setMobilePane('collab') }}>{tabLabel[tab]}{tabCounts[tab] > 0 && <span className={css.tabBadge}>{tabCounts[tab]}</span>}</button>
|
|
80
|
+
const currentReviews = selected?.reviewItems.filter(item => item.commit === selected.currentCommit && !['resolved', 'invalidated', 'non-blocking-verify'].includes(item.status)) ?? []
|
|
81
|
+
const pendingPatches = selected?.patches.filter(item => item.baseCommit === selected.currentCommit && item.status === 'pending') ?? []
|
|
82
|
+
const openDiscussions = selected?.comments.filter(item => item.commit === selected.currentCommit && item.status === 'open').length ?? 0
|
|
83
|
+
const failedChecks = selected?.readiness.filter(item => !item.passed).length ?? 0
|
|
84
|
+
const workflow = selected ? workflowState(selected, participant.role) : undefined
|
|
89
85
|
|
|
90
86
|
const refresh = async (): Promise<void> => { try { const state = await api.state(); setRequirements(state.requirements); setParticipantBindings(state.participants); const binding = state.participants.find(item => item.participantId === participant.participantId); if (binding && binding.role !== participant.role) setParticipant(current => ({ ...current, role: binding.role })); setSelectedId(current => current && state.requirements.some(item => item.id === current) ? current : state.requirements[0]?.id) } catch (error) { setNotice(error instanceof Error ? error.message : String(error)) } }
|
|
91
87
|
useEffect(() => { void refresh(); void api.reviewWorkspaces().then(setReviewWorkspaces, error => setNotice(error instanceof Error ? error.message : String(error))); return api.events(() => { void refresh() }) }, [])
|
|
@@ -103,7 +99,7 @@ export function SpecWorkbench({ api, onClose }: { api: SpecApi; onClose: () => v
|
|
|
103
99
|
const result = await api.action(factory(participant))
|
|
104
100
|
if (!result.ok) {
|
|
105
101
|
if (result.conflict) { setSaveConflict(result.conflict); setMergeDraft(result.conflict.draftMarkdown); setNotice('检测到并发修改。请在三方对比中合并后再提交。'); return false }
|
|
106
|
-
setNotice(result.error); return false
|
|
102
|
+
setNotice(friendlyActionError(result.error)); return false
|
|
107
103
|
}
|
|
108
104
|
setSaveConflict(undefined); await refresh(); if (!result.deletedRequirementId) setSelectedId(result.requirement.id); return true
|
|
109
105
|
}
|
|
@@ -113,13 +109,30 @@ export function SpecWorkbench({ api, onClose }: { api: SpecApi; onClose: () => v
|
|
|
113
109
|
const create = async (): Promise<void> => {
|
|
114
110
|
const links = createForm.sources.split('\n').map(value => value.trim()).filter(Boolean)
|
|
115
111
|
const ok = await act(actor => ({ kind: 'requirement.create', participant: actor, title: createForm.title, rawRequirement: createForm.rawRequirement, workspaceId: createForm.workspaceId, sources: links.map((label, index) => ({ id: `source-${index + 1}`, sourceType: /^https?:/.test(label) ? 'link' : 'text', label, ...(/^https?:/.test(label) ? { stableId: label } : {}), accessStatus: /^https?:/.test(label) ? 'unverified' : 'available' })) }))
|
|
116
|
-
if (ok) { setCreateOpen(false); setCreateForm({ title: '', rawRequirement: '', sources: '', workspaceId: '' });
|
|
112
|
+
if (ok) { setCreateOpen(false); setCreateForm({ title: '', rawRequirement: '', sources: '', workspaceId: '' }); setPrimaryMode('tasks'); setTaskView('review') }
|
|
117
113
|
}
|
|
118
114
|
const bindWorkspace = async (): Promise<void> => { if (!selected || !bindWorkspaceId) return; if (await act(actor => ({ kind: 'requirement.bind-workspace', participant: actor, requirementId: selected.id, workspaceId: bindWorkspaceId }))) { setBindWorkspaceOpen(false); setBindWorkspaceId('') } }
|
|
119
115
|
const save = async (): Promise<void> => { if (!selected) return; const ok = await act(actor => ({ kind: 'version.save', participant: actor, requirementId: selected.id, baseCommit: selected.currentCommit, markdown: draft, summary })); if (ok) { setSummary(''); setNotice('已创建新的 Git commit,等待变更审核') } }
|
|
120
116
|
const requestReview = async (reviewKind: ReviewKind): Promise<void> => { if (!selected) return; await act(actor => ({ kind: 'review.request', participant: actor, requirementId: selected.id, reviewKind })) }
|
|
121
117
|
const confirm = async (role: ParticipantRole): Promise<void> => { if (!selected) return; await act(actor => ({ kind: 'confirmation.create', participant: actor, requirementId: selected.id, role, scope: 'version' })) }
|
|
122
118
|
const advance = async (): Promise<void> => { if (!selected) return; await act(actor => ({ kind: 'stage.advance', participant: actor, requirementId: selected.id })) }
|
|
119
|
+
const executeWorkflow = async (command: WorkflowCommand): Promise<void> => {
|
|
120
|
+
if (!selected || command.kind === 'none') return
|
|
121
|
+
if (command.kind === 'open') { setPrimaryMode('tasks'); setTaskView(command.view); setMobilePane('collab'); return }
|
|
122
|
+
if (command.kind === 'bind-workspace') { setBindWorkspaceOpen(true); void api.reviewWorkspaces().then(setReviewWorkspaces, error => setNotice(error instanceof Error ? error.message : String(error))); return }
|
|
123
|
+
if (command.kind === 'request-review') { setTaskView('review'); await requestReview(command.reviewKind); return }
|
|
124
|
+
if (command.kind === 'advance') { await advance(); return }
|
|
125
|
+
if (command.kind === 'confirm') { await confirm(command.role); return }
|
|
126
|
+
setTaskView('ready')
|
|
127
|
+
await act(actor => ({ kind: 'ready.generate', participant: actor, requirementId: selected.id }))
|
|
128
|
+
}
|
|
129
|
+
const openMyItem = (item: MyActionItem): void => {
|
|
130
|
+
if (item.target.tab === 'discussion') setPrimaryMode('discussion')
|
|
131
|
+
else if (item.target.tab === 'decisions') { setPrimaryMode('records'); setRecordView('decisions') }
|
|
132
|
+
else { setPrimaryMode('tasks'); setTaskView(item.target.tab === 'patches' ? 'patches' : item.target.tab === 'ready' ? 'ready' : 'review') }
|
|
133
|
+
setMobilePane('collab')
|
|
134
|
+
window.setTimeout(() => document.getElementById(`spec-object-${item.target.objectId}`)?.scrollIntoView({ block: 'center' }), 100)
|
|
135
|
+
}
|
|
123
136
|
const resizePane = (side: 'documents' | 'review', event: ReactPointerEvent<HTMLDivElement>): void => {
|
|
124
137
|
event.preventDefault()
|
|
125
138
|
const startX = event.clientX; const startWidth = side === 'documents' ? documentsWidth : reviewWidth
|
|
@@ -139,44 +152,82 @@ export function SpecWorkbench({ api, onClose }: { api: SpecApi; onClose: () => v
|
|
|
139
152
|
if (!draftSelection) return
|
|
140
153
|
setSelection(draftSelection)
|
|
141
154
|
setDraftSelection(undefined)
|
|
142
|
-
|
|
155
|
+
setPrimaryMode('discussion')
|
|
143
156
|
setMobilePane('collab')
|
|
144
157
|
}
|
|
145
158
|
const addComment = async (): Promise<void> => { if (!selected || !selection) return; const ok = await act(actor => ({ kind: 'comment.create', participant: actor, requirementId: selected.id, commit: selected.currentCommit, anchor: selection, body: commentText })); if (ok) { setSelection(undefined); setCommentText(''); setNotice('评论已提交,AI 正在自动分析理解、证据与关联影响') } }
|
|
146
159
|
|
|
147
160
|
return <div className={css.workbench}>
|
|
148
161
|
<header className={css.header}>
|
|
149
|
-
<div className={css.titleBlock}
|
|
162
|
+
<div className={css.titleBlock}>
|
|
163
|
+
<span className={css.productName}>需求共创</span>
|
|
164
|
+
<strong>{selected?.title ?? '把模糊需求变成可交付规范'}</strong>
|
|
165
|
+
{selected && <span>{reviewWorkspaces.find(workspace => workspace.workspaceId === selected.workspaceId)?.title ?? (selected.workspaceId ? '项目已关联' : '未关联项目')} · 版本 {selected.currentCommit.slice(0, 8)}</span>}
|
|
166
|
+
</div>
|
|
167
|
+
{selected && <StageRail stage={selected.stage}/>}
|
|
150
168
|
<div className={css.headerActions}>
|
|
151
|
-
<button onClick={onClose}>返回聊天</button>
|
|
152
|
-
{
|
|
153
|
-
{selected?.stage === 'product-review' && <><button disabled={productFirstRunning || !selected.workspaceId} title={!selected.workspaceId ? '请先绑定工作区' : productFirstRunning ? '初审进行中' : '启动智能初审'} onClick={() => void requestReview('product-first')}>智能初审</button><button disabled={!selected.workspaceId} onClick={() => void requestReview('product-second')}>智能复审</button><button className={css.execute} onClick={() => void advance()}>进入产品确认</button></>}
|
|
154
|
-
{selected?.stage === 'product-confirmation' && <><button onClick={() => void confirm('product')}>产品确认当前版本</button><button onClick={() => void advance()}>进入产研共审</button></>}
|
|
155
|
-
{selected?.stage === 'joint-review' && <><button disabled={!selected.workspaceId} onClick={() => void requestReview('engineering-precheck')}>研发智能预审</button><button onClick={() => void confirm(participant.role)}>以{participant.role === 'product' ? '产品' : '研发'}确认</button><button className={css.execute} onClick={() => selected && void act(actor => ({ kind: 'ready.generate', participant: actor, requirementId: selected.id }))}>生成就绪规范</button></>}
|
|
156
|
-
<button className={css.identity} onClick={() => setIdentityOpen(true)}>{registered ? `${participant.nickname} · ${participant.role === 'product' ? '产品' : '研发'}` : '匿名只读'}</button>
|
|
169
|
+
<button className={css.quietButton} aria-label="返回聊天" onClick={onClose}><span aria-hidden="true">←</span><span className={css.backLabel}>返回聊天</span></button>
|
|
170
|
+
<button className={css.identity} onClick={() => setIdentityOpen(true)}>{registered ? `${participant.nickname} · ${participant.role === 'product' ? '产品' : '研发'}` : '登记身份'}</button>
|
|
157
171
|
</div>
|
|
158
172
|
</header>
|
|
159
173
|
<div className={notice ? css.notice : css.noticeHidden}>{notice}<button aria-label="关闭" onClick={() => setNotice('')}>×</button></div>
|
|
160
|
-
<div className={css.mobileViewSwitch}><button className={mobilePane === 'spec' ? css.activeMode : ''} onClick={() => setMobilePane('spec')}
|
|
174
|
+
<div className={css.mobileViewSwitch}><button className={mobilePane === 'spec' ? css.activeMode : ''} onClick={() => setMobilePane('spec')}>需求正文</button><button className={mobilePane === 'collab' ? css.activeMode : ''} onClick={() => setMobilePane('collab')}>下一步{currentMyItems.length > 0 ? ` · ${currentMyItems.length}` : ''}</button></div>
|
|
161
175
|
<div className={`${css.grid} ${mobilePane === 'spec' ? css.mobileSpec : css.mobileCollab}`} style={{ '--documents-width': documentsOpen ? `${documentsWidth}px` : '0px', '--documents-handle': documentsOpen ? '6px' : '0px', '--review-width': reviewOpen ? `${reviewWidth}px` : '0px', '--review-handle': reviewOpen ? '6px' : '0px' } as CSSProperties}>
|
|
162
|
-
<aside className={`${css.documents} ${documentsOpen ? '' : css.paneClosed}`}
|
|
176
|
+
<aside className={`${css.documents} ${documentsOpen ? '' : css.paneClosed}`} aria-label="需求列表">
|
|
177
|
+
<div className={css.paneHead}><strong>{showArchived ? '已归档' : '需求'}</strong><div className={css.paneActions}><button onClick={() => { setShowArchived(value => !value); setSelectedId(undefined); setManageMenuId(undefined) }}>{showArchived ? '返回进行中' : '查看归档'}</button>{!showArchived && <button className={css.createButton} aria-label="新建需求" title="新建需求" onClick={() => { setCreateOpen(true); void api.reviewWorkspaces().then(setReviewWorkspaces, error => setNotice(error instanceof Error ? error.message : String(error))) }}>+</button>}<button className={css.iconButton} aria-label="收起需求栏" title="收起需求栏" onClick={() => setDocumentsOpen(false)}>‹</button></div></div>
|
|
178
|
+
<nav>{visibleRequirements.map(item => <div className={css.requirementRow} key={item.id}><button className={`${css.documentButton} ${item.id === selected?.id ? css.selectedDoc : ''}`} onClick={() => { setSelectedId(item.id); setPrimaryMode('tasks') }}><span>{item.title}</span><small><i className={`${css.statusDot} ${css[`stage_${item.stage}`]}`}/>{item.archivedAt ? `归档于 ${new Date(item.archivedAt).toLocaleDateString()}` : `${stageLabel(item.stage)}${item.stage !== 'ready' && currentPendingActions(item).filter(task => task.blocking).length > 0 ? ` · ${currentPendingActions(item).filter(task => task.blocking).length} 项待处理` : ''}`}</small></button><button className={css.rowMenuButton} aria-label={`${item.title} 更多操作`} title="更多操作" onClick={() => { setSelectedId(item.id); setManageMenuId(current => current === item.id ? undefined : item.id) }}>…</button>{manageMenuId === item.id && <div className={css.requirementMenu}><button onClick={() => { setManageTargetId(item.id); setRenameTitle(item.title); setRenameOpen(true); setManageMenuId(undefined) }}>重命名</button><button onClick={() => void archiveRequirement(item)}>{item.archivedAt ? '取消归档' : '归档需求'}</button><button className={css.dangerText} onClick={() => { setManageTargetId(item.id); setDeleteOpen(true); setManageMenuId(undefined) }}>删除需求</button></div>}</div>)}</nav>
|
|
179
|
+
{visibleRequirements.length === 0 && <div className={css.emptyList}><strong>{showArchived ? '还没有归档需求' : '从一个真实问题开始'}</strong><p>{showArchived ? '归档后的需求会出现在这里。' : '输入原始需求,AI 会先帮你找出缺口。'}</p>{!showArchived && <button onClick={() => { setCreateOpen(true); void api.reviewWorkspaces().then(setReviewWorkspaces, error => setNotice(error instanceof Error ? error.message : String(error))) }}>新建需求</button>}</div>}
|
|
180
|
+
</aside>
|
|
163
181
|
<div className={`${css.resizer} ${documentsOpen ? '' : css.resizerHidden}`} role="separator" aria-label="调整需求栏宽度" aria-orientation="vertical" onPointerDown={event => resizePane('documents', event)}/>
|
|
164
182
|
<main className={css.editorPane}>
|
|
165
|
-
<div className={css.toolbar}><div className={css.editorTitle}>{!documentsOpen && <button className={css.iconButton} aria-label="展开需求栏" title="展开需求栏" onClick={() => setDocumentsOpen(true)}
|
|
183
|
+
<div className={css.toolbar}><div className={css.editorTitle}>{!documentsOpen && <button className={css.iconButton} aria-label="展开需求栏" title="展开需求栏" onClick={() => setDocumentsOpen(true)}>›</button>}<div><span>正式需求</span><strong>需求正文</strong></div></div><div><span className={draft !== selected?.version.markdown ? css.unsaved : css.editorMeta}>{draft !== selected?.version.markdown ? '有未保存改动' : '所有改动已保存'}</span><input className={css.summaryInput} required aria-label="说明本次改动" value={summary} onChange={event => setSummary(event.target.value)} placeholder="简要说明本次改动"/><button className={css.saveButton} disabled={busy || !selected || draft === selected.version.markdown || !summary.trim()} onClick={() => void save()}>保存版本</button>{!reviewOpen && <button className={css.iconButton} aria-label="展开下一步面板" title="展开下一步面板" onClick={() => setReviewOpen(true)}>‹</button>}</div></div>
|
|
166
184
|
{draftSelection && <div className={css.editorContext}><div className={css.selectionPrompt}><span>已选 {draftSelection.quote.length} 字 · “{draftSelection.quote.replace(/\s+/g, ' ').slice(0, 48)}{draftSelection.quote.length > 48 ? '…' : ''}”</span><button className={css.commentAction} onClick={captureSelection}>添加评论</button><button aria-label="取消文字选择" title="取消文字选择" onClick={() => setDraftSelection(undefined)}>×</button></div></div>}
|
|
167
|
-
{!selected ? <div className={css.emptyMain}><button onClick={() => { setCreateOpen(true); void api.reviewWorkspaces().then(setReviewWorkspaces, error => setNotice(error instanceof Error ? error.message : String(error))) }}
|
|
185
|
+
{!selected ? <div className={css.emptyMain}><div><span>从问题到共识</span><h2>创建第一份需求</h2><p>写下用户问题和期望结果,AI 会协助补齐范围、规则与验收标准。</p><button className={css.execute} onClick={() => { setCreateOpen(true); void api.reviewWorkspaces().then(setReviewWorkspaces, error => setNotice(error instanceof Error ? error.message : String(error))) }}>新建需求</button></div></div> : <div className={css.editorBody}><RichMarkdownEditor key={`${selected.id}:${selected.currentCommit}`} markdown={draft} onChange={setDraft} onSelection={quote => setDraftSelection(quote ? { quote, prefix: '', suffix: '' } : undefined)}/></div>}
|
|
168
186
|
</main>
|
|
169
187
|
<div className={`${css.resizer} ${reviewOpen ? '' : css.resizerHidden}`} role="separator" aria-label="调整协作栏宽度" aria-orientation="vertical" onPointerDown={event => resizePane('review', event)}/>
|
|
170
|
-
<aside className={`${css.review} ${reviewOpen ? '' : css.paneClosed}`}>
|
|
171
|
-
<div className={css.
|
|
172
|
-
|
|
188
|
+
<aside className={`${css.review} ${reviewOpen ? '' : css.paneClosed}`} aria-label="需求协作">
|
|
189
|
+
<div className={css.primaryNav}><div role="tablist" aria-label="协作视图"><button role="tab" aria-selected={primaryMode === 'tasks'} className={primaryMode === 'tasks' ? css.activeMode : ''} onClick={() => setPrimaryMode('tasks')}>下一步{currentMyItems.length > 0 && <span className={css.tabBadge}>{currentMyItems.length}</span>}</button><button role="tab" aria-selected={primaryMode === 'discussion'} className={primaryMode === 'discussion' ? css.activeMode : ''} onClick={() => setPrimaryMode('discussion')}>讨论{openDiscussions > 0 && <span className={css.tabBadge}>{openDiscussions}</span>}</button><button role="tab" aria-selected={primaryMode === 'records'} className={primaryMode === 'records' ? css.activeMode : ''} onClick={() => setPrimaryMode('records')}>记录</button></div><button className={`${css.iconButton} ${css.collapseRight}`} aria-label="收起下一步面板" title="收起下一步面板" onClick={() => setReviewOpen(false)}>›</button></div>
|
|
190
|
+
{selected && primaryMode === 'tasks' && <>
|
|
191
|
+
{workflow && <WorkflowFocus state={workflow} pendingForMe={currentMyItems.length} onExecute={() => void executeWorkflow(workflow.command)}/>}
|
|
192
|
+
{currentMyItems.length > 0 && <TaskQueue items={currentMyItems} open={openMyItem}/>}
|
|
193
|
+
<div className={css.contextNav} role="tablist" aria-label="待处理内容"><button role="tab" aria-selected={taskView === 'review'} className={taskView === 'review' ? css.activeContext : ''} onClick={() => setTaskView('review')}>问题{currentReviews.length > 0 && <span>{currentReviews.length}</span>}</button><button role="tab" aria-selected={taskView === 'patches'} className={taskView === 'patches' ? css.activeContext : ''} onClick={() => setTaskView('patches')}>AI 建议{pendingPatches.length > 0 && <span>{pendingPatches.length}</span>}</button><button role="tab" aria-selected={taskView === 'ready'} className={taskView === 'ready' ? css.activeContext : ''} onClick={() => setTaskView('ready')}>完成条件{failedChecks > 0 && <span>{failedChecks}</span>}</button></div>
|
|
194
|
+
<div className={css.threadList}>{taskView === 'review' && <ReviewPanel requirement={selected} participant={participant} act={act} api={api}/>} {taskView === 'patches' && <PatchPanel requirement={selected} act={act}/>} {taskView === 'ready' && <ReadyPanel requirement={selected} act={act}/>}</div>
|
|
195
|
+
</>}
|
|
196
|
+
{selected && primaryMode === 'discussion' && <div className={css.threadList}><DiscussionPanel requirement={selected} selection={selection} text={commentText} setText={setCommentText} cancel={() => setSelection(undefined)} submit={addComment} participant={participant} act={act} api={api}/></div>}
|
|
197
|
+
{selected && primaryMode === 'records' && <><div className={css.contextNav} role="tablist" aria-label="需求记录"><button role="tab" aria-selected={recordView === 'decisions'} className={recordView === 'decisions' ? css.activeContext : ''} onClick={() => setRecordView('decisions')}>关键决策</button><button role="tab" aria-selected={recordView === 'versions'} className={recordView === 'versions' ? css.activeContext : ''} onClick={() => setRecordView('versions')}>版本历史</button></div><div className={css.threadList}>{recordView === 'decisions' && <DecisionPanel requirement={selected} act={act}/>} {recordView === 'versions' && <VersionPanel requirement={selected} api={api}/>}</div></>}
|
|
198
|
+
{!selected && <div className={css.emptyAside}><strong>等待创建需求</strong><p>创建后,下一步操作会显示在这里。</p></div>}
|
|
173
199
|
</aside>
|
|
174
200
|
</div>
|
|
175
|
-
<footer className={css.footer}><span>
|
|
201
|
+
<footer className={css.footer}><span>AI 可以检查和建议,最终版本始终由人确认</span><span>{selected ? `${stageLabel(selected.stage)} · ${selected.currentCommit.slice(0, 8)} · ${selected.aiRuns.at(-1)?.status === 'running' ? 'AI 分析中' : '版本已记录'}` : '从原始需求开始'}</span></footer>
|
|
176
202
|
{identityOpen && <IdentityDialog value={participant} {...(boundRole === undefined ? {} : { boundRole })} onChange={setParticipant} close={() => setIdentityOpen(false)}/>} {createOpen && <CreateDialog value={createForm} setValue={setCreateForm} workspaces={reviewWorkspaces} close={() => setCreateOpen(false)} submit={() => void create()} busy={busy}/>} {bindWorkspaceOpen && selected && <WorkspaceDialog value={bindWorkspaceId} setValue={setBindWorkspaceId} workspaces={reviewWorkspaces} close={() => { setBindWorkspaceOpen(false); setBindWorkspaceId('') }} submit={() => void bindWorkspace()} busy={busy}/>} {renameOpen && <RenameDialog title={renameTitle} setTitle={setRenameTitle} close={() => { setRenameOpen(false); setManageTargetId(undefined) }} submit={() => void renameRequirement()} busy={busy}/>} {deleteOpen && manageTarget && <DeleteDialog title={manageTarget.title} close={() => { setDeleteOpen(false); setManageTargetId(undefined) }} submit={() => void deleteRequirement()} busy={busy}/>} {saveConflict && <ConflictDialog conflict={saveConflict} value={mergeDraft} setValue={setMergeDraft} close={() => setSaveConflict(undefined)} busy={busy} submit={() => void act(actor => ({ kind: 'version.save', participant: actor, requirementId: saveConflict.requirementId, baseCommit: saveConflict.currentCommit, markdown: mergeDraft, summary })).then(ok => { if (ok) { setDraft(mergeDraft); setSummary(''); setSaveConflict(undefined); setNotice('冲突已合并并创建新的 Git commit') } })}/>}
|
|
177
203
|
</div>
|
|
178
204
|
}
|
|
179
205
|
|
|
206
|
+
const stageSteps: Array<{ stage: RequirementStage; label: string }> = [
|
|
207
|
+
{ stage: 'product-review', label: '澄清' },
|
|
208
|
+
{ stage: 'product-confirmation', label: '产品确认' },
|
|
209
|
+
{ stage: 'joint-review', label: '产研确认' },
|
|
210
|
+
{ stage: 'ready', label: '已就绪' },
|
|
211
|
+
]
|
|
212
|
+
function StageRail({ stage }: { stage: RequirementStage }) {
|
|
213
|
+
const activeIndex = stageSteps.findIndex(item => item.stage === stage)
|
|
214
|
+
return <ol className={css.stageRail} aria-label="需求进度">{stageSteps.map((item, index) => <li className={index < activeIndex ? css.stageDone : index === activeIndex ? css.stageCurrent : ''} key={item.stage} aria-current={index === activeIndex ? 'step' : undefined}><span>{index < activeIndex ? '✓' : index + 1}</span><b>{item.label}</b></li>)}</ol>
|
|
215
|
+
}
|
|
216
|
+
function WorkflowFocus({ state, pendingForMe, onExecute }: { state: WorkflowState; pendingForMe: number; onExecute: () => void }) {
|
|
217
|
+
return <section className={css.workflowFocus}>
|
|
218
|
+
<div className={css.workflowEyebrow}><span>{state.eyebrow}</span>{pendingForMe > 0 && <small>{pendingForMe} 项与你相关</small>}</div>
|
|
219
|
+
<h2>{state.title}</h2>
|
|
220
|
+
<p>{state.detail}</p>
|
|
221
|
+
<button className={css.execute} disabled={state.disabled} title={state.disabledReason} onClick={onExecute}>{state.command.kind === 'none' && state.disabled ? <span className={css.runningDot}/> : null}{state.actionLabel}<span aria-hidden="true">→</span></button>
|
|
222
|
+
{state.disabledReason && <small className={css.disabledReason}>{state.disabledReason}</small>}
|
|
223
|
+
</section>
|
|
224
|
+
}
|
|
225
|
+
const taskTypeLabel: Record<MyActionItem['type'], string> = { reply: '需要回复', confirm: '需要确认', review: '需要审核', reconfirm: '需要重新确认' }
|
|
226
|
+
function TaskQueue({ items, open }: { items: MyActionItem[]; open: (item: MyActionItem) => void }) {
|
|
227
|
+
const sorted = items.slice().sort((left, right) => Number(right.blocking) - Number(left.blocking) || right.updatedAt - left.updatedAt)
|
|
228
|
+
return <details className={css.taskQueue}><summary><span>与你相关的事项</span><b>{items.length}</b></summary><div>{sorted.map(item => <button key={item.id} onClick={() => open(item)}><span>{item.blocking ? '优先' : '普通'}</span><div><strong>{taskTypeLabel[item.type]}</strong><small>{new Date(item.updatedAt).toLocaleString()}</small></div><i aria-hidden="true">›</i></button>)}</div></details>
|
|
229
|
+
}
|
|
230
|
+
|
|
180
231
|
function RichMarkdownEditor({ markdown, onChange, onSelection }: { markdown: string; onChange: (markdown: string) => void; onSelection: (quote: string) => void }) {
|
|
181
232
|
const host = useRef<HTMLDivElement>(null)
|
|
182
233
|
const instance = useRef<ToastEditor>()
|
|
@@ -213,32 +264,40 @@ function RichMarkdownEditor({ markdown, onChange, onSelection }: { markdown: str
|
|
|
213
264
|
}
|
|
214
265
|
|
|
215
266
|
type Act = (factory: (actor: ParticipantSnapshot) => CollaborationAction) => Promise<boolean>
|
|
216
|
-
const reviewKindLabel: Record<ReviewKind, string> = { 'product-first': '
|
|
217
|
-
const statusLabel: Record<string, string> = { queued: '排队中', running: '分析中', completed: '已完成', failed: '失败', open: '待处理', 'joint-review': '
|
|
267
|
+
const reviewKindLabel: Record<ReviewKind, string> = { 'product-first': '需求缺口检查', 'product-second': '正文整理检查', 'engineering-precheck': '研发可行性检查', 'change-review': '改动影响检查' }
|
|
268
|
+
const statusLabel: Record<string, string> = { queued: '排队中', running: '分析中', completed: '已完成', failed: '失败', open: '待处理', 'joint-review': '待产研共议', 'non-blocking-verify': '保留待核对', resolved: '已解决', invalidated: '已失效', pending: '待确认', accepted: '已接受', rejected: '未采用', stale: '已过期', blocking: '阻塞', major: '重要', minor: '一般' }
|
|
218
269
|
const evidenceStatusLabel: Record<string, string> = { FACT: '已有依据', INFERENCE: '根据现有信息推断', ASSUMPTION: '暂定规则', TO_VERIFY: '待核对' }
|
|
219
270
|
function MarkdownBody({ text, className = '' }: { text: string; className?: string | undefined }) { return <div className={`${css.markdownBody} ${className}`} dangerouslySetInnerHTML={{ __html: md.render(text) }}/> }
|
|
220
271
|
function ReviewPanel({ requirement, act, api }: { requirement: RequirementView; participant: ParticipantSnapshot; act: Act; api: SpecApi }) {
|
|
221
|
-
const
|
|
272
|
+
const current = requirement.reviewItems.filter(item => item.commit === requirement.currentCommit).slice().sort((left, right) => Number(right.severity === 'blocking') - Number(left.severity === 'blocking') || right.updatedAt - left.updatedAt)
|
|
273
|
+
const historical = requirement.reviewItems.filter(item => item.commit !== requirement.currentCommit)
|
|
274
|
+
const active = current.filter(item => !['resolved', 'invalidated', 'non-blocking-verify'].includes(item.status))
|
|
275
|
+
const deferred = current.filter(item => item.status === 'non-blocking-verify')
|
|
276
|
+
const pendingCount = active.length
|
|
277
|
+
const currentRuns = requirement.aiRuns.filter(run => run.commit === requirement.currentCommit)
|
|
222
278
|
return <>
|
|
223
|
-
<div className={css.panelSummary}><div><strong>{pendingCount}
|
|
224
|
-
{
|
|
225
|
-
{
|
|
279
|
+
<div className={css.panelSummary}><div><strong>{pendingCount > 0 ? `${pendingCount} 个问题需要收敛` : '当前版本没有待回答问题'}</strong><span>{current.filter(item => item.severity === 'blocking' && !['resolved', 'invalidated', 'non-blocking-verify'].includes(item.status)).length} 个会阻塞下一阶段</span></div></div>
|
|
280
|
+
{currentRuns.length > 0 && <details className={css.runHistory}><summary>查看本轮 AI 检查记录({currentRuns.length})</summary>{currentRuns.slice().reverse().map(run => <div className={css.run} key={run.id}><div><strong>{reviewKindLabel[run.kind]}</strong><span>{statusLabel[run.status] ?? run.status}</span></div>{run.maturitySummary && <MarkdownBody text={run.maturitySummary}/>} {run.error && <p className={css.chatError}>{friendlyActionError(run.error)}</p>}{run.sessionId && <AiConversation api={api} requirementId={requirement.id} sessionId={run.sessionId}/>}</div>)}</details>}
|
|
281
|
+
{current.length === 0 && <div className={css.emptyPanel}><strong>等待 AI 完成检查</strong><p>检查结果会按优先级出现在这里。</p></div>}
|
|
282
|
+
{active.map((item, index) => <ReviewItemCard key={item.id} item={item} requirementId={requirement.id} act={act} initiallyOpen={index === 0}/>)}
|
|
283
|
+
{deferred.length > 0 && <details className={css.historyGroup}><summary>保留待核对 · {deferred.length}</summary><div>{deferred.map(item => <ReviewItemCard key={item.id} item={item} requirementId={requirement.id} act={act}/>)}</div></details>}
|
|
284
|
+
{historical.length > 0 && <details className={css.historyGroup}><summary>历史问题 · {historical.length}</summary><div>{historical.slice().reverse().map(item => <ReviewItemCard key={item.id} item={item} requirementId={requirement.id} act={act}/>)}</div></details>}
|
|
226
285
|
</>
|
|
227
286
|
}
|
|
228
|
-
function ReviewItemCard({ item, requirementId, act }: { item: RequirementView['reviewItems'][number]; requirementId: string; act: Act }) {
|
|
287
|
+
function ReviewItemCard({ item, requirementId, act, initiallyOpen = false }: { item: RequirementView['reviewItems'][number]; requirementId: string; act: Act; initiallyOpen?: boolean }) {
|
|
229
288
|
const ended = ['resolved', 'invalidated'].includes(item.status)
|
|
230
|
-
const content = <div className={css.reviewCardBody}><div className={css.badges}><b>{statusLabel[item.severity] ?? item.severity}</b><span>{evidenceStatusLabel[item.epistemicStatus] ?? item.epistemicStatus}</span></div><div className={css.reviewField}><span
|
|
231
|
-
return <details id={`spec-object-${item.id}`} className={`${css.reviewDetails} ${ended ? css.endedReview : css.pendingReview}`} open={!ended}><summary><span>{item.statement}</span><b>{statusLabel[item.status] ?? item.status}</b></summary>{content}</details>
|
|
289
|
+
const content = <div className={css.reviewCardBody}><div className={css.badges}><b>{statusLabel[item.severity] ?? item.severity}</b><span>{evidenceStatusLabel[item.epistemicStatus] ?? item.epistemicStatus}</span></div><div className={`${css.reviewField} ${css.questionField}`}><span>需要明确</span><MarkdownBody text={item.question}/></div><details className={css.impactDetails}><summary>为什么需要回答</summary><MarkdownBody text={item.impact}/></details><details className={css.evidence}><summary>依据与来源 · {item.evidence.length} 条</summary>{item.evidence.length === 0 ? <p>当前没有可核对的资料,可以先按业务判断回答或标记为待核对。</p> : item.evidence.map((evidence, index) => <div key={`${evidence.source}-${index}`}><code>{evidence.source}{evidence.version ? `@${evidence.version}` : ''}</code><MarkdownBody text={evidence.statement}/></div>)}</details>{!item.response && item.status === 'open' && <ReviewResponseForm requirementId={requirementId} reviewItemId={item.id} {...(item.recommendedOptions ? { options: item.recommendedOptions } : {})} act={act}/>} {item.response && <div className={css.humanResponse}><span>已回复</span><strong>{item.response.participant.nickname}</strong><MarkdownBody text={item.response.body}/></div>}</div>
|
|
290
|
+
return <details id={`spec-object-${item.id}`} className={`${css.reviewDetails} ${ended ? css.endedReview : css.pendingReview}`} open={initiallyOpen && !ended}><summary><span>{item.statement}</span><b>{statusLabel[item.status] ?? item.status}</b></summary>{content}</details>
|
|
232
291
|
}
|
|
233
|
-
const dispositionLabel = { context: '
|
|
234
|
-
function ReviewResponseForm({ requirementId, reviewItemId,
|
|
292
|
+
const dispositionLabel = { context: '补充我的判断', evidence: '补充依据或案例', accept: '这个结论可以直接采用', 'accept-modified': '采用,并同步修改正文', reject: '不采用,并说明原因', 'to-verify': '现在无法确认,保留待核对', 'joint-review': '交给产品和研发共同确认' } as const
|
|
293
|
+
function ReviewResponseForm({ requirementId, reviewItemId, options, act }: { requirementId: string; reviewItemId: string; options?: string[]; act: Act }) {
|
|
235
294
|
const [open, setOpen] = useState(false)
|
|
236
295
|
const [disposition, setDisposition] = useState<keyof typeof dispositionLabel>('context')
|
|
237
296
|
const [body, setBody] = useState('')
|
|
238
297
|
const recommendations = options?.map(option => option.trim()).filter(Boolean) ?? []
|
|
239
298
|
const choose = (option: string): void => { setBody(option); setDisposition('accept-modified'); setOpen(true) }
|
|
240
299
|
const submit = async (): Promise<void> => { if (await act(actor => ({ kind: 'review.respond', participant: actor, requirementId, reviewItemId, disposition, body }))) { setOpen(false); setBody('') } }
|
|
241
|
-
return <>{recommendations.length
|
|
300
|
+
return <>{recommendations.length > 0 && <div className={css.quickOptions}><span>可以直接选择一个方向</span>{recommendations.slice(0, 5).map(option => <button key={option} onClick={() => choose(option)}><span>{option}</span><b>选择</b></button>)}</div>}{open ? <div className={css.responseForm}><label>如何处理<select required value={disposition} onChange={event => setDisposition(event.target.value as keyof typeof dispositionLabel)}>{Object.entries(dispositionLabel).map(([value, label]) => <option key={value} value={value}>{label}</option>)}</select></label><label>你的结论<textarea required autoFocus value={body} onChange={event => setBody(event.target.value)} placeholder={disposition === 'evidence' ? '粘贴数据、案例或来源链接,并说明它支持什么结论' : '写下最终判断、规则或取舍'}/></label><div className={css.cardActions}><button onClick={() => setOpen(false)}>取消</button><button className={css.execute} disabled={!body.trim()} onClick={() => void submit()}>保存回答</button></div></div> : <div className={css.cardActions}><button className={css.answerButton} onClick={() => setOpen(true)}>写下我的回答</button><button onClick={() => void act(actor => ({ kind: 'review.respond', participant: actor, requirementId, reviewItemId, disposition: 'joint-review', body: '转产研共同决策' }))}>交给产研共议</button></div>}</>
|
|
242
301
|
}
|
|
243
302
|
function DiscussionPanel({ requirement, selection, text, setText, cancel, submit, act, api }: { requirement: RequirementView; selection: { quote: string } | undefined; text: string; setText: (value: string) => void; cancel: () => void; submit: () => Promise<void>; participant: ParticipantSnapshot; act: Act; api: SpecApi }) { return <>{selection && <section className={css.newThread}><blockquote>{selection.quote}</blockquote><label>评论内容(必填)<textarea required value={text} onChange={event => setText(event.target.value)} placeholder="输入实质评论;提交后智能助手自动分析"/></label><div><button onClick={cancel}>取消</button><button disabled={!text.trim()} onClick={() => void submit()}>提交并邀请智能助手</button></div></section>}{requirement.comments.slice().reverse().map(comment => <section id={`spec-object-${comment.id}`} key={comment.id}><blockquote>{comment.anchor.quote}</blockquote><strong>{comment.author.nickname}</strong><MarkdownBody text={comment.body}/><small>智能分析:{comment.aiStatus}{comment.aiSessionId ? ` · ${comment.aiSessionId.slice(0, 8)}` : ''}</small>{comment.aiSessionId && <AiConversation api={api} requirementId={requirement.id} sessionId={comment.aiSessionId}/>} {comment.replies.map(reply => <div className={css.reply} key={reply.id}><strong>{reply.author.nickname}{reply.author.kind === 'ai' ? ' · 智能助手' : ''}</strong><MarkdownBody text={reply.body}/></div>)}{comment.status === 'open' && <div>{(['written-back', 'decision', 'rejected', 'open-question'] as CommentResolution[]).map(resolution => <button key={resolution} onClick={() => void act(actor => ({ kind: 'comment.resolve', participant: actor, requirementId: requirement.id, commentId: comment.id, resolution }))}>{({ 'written-back': '已回写正文', decision: '形成决策', rejected: '不采纳', 'open-question': '转为开放问题' })[resolution]}</button>)}</div>}</section>)}</> }
|
|
244
303
|
function AiConversation({ api, requirementId, sessionId }: { api: SpecApi; requirementId: string; sessionId: string }) {
|
|
@@ -255,17 +314,20 @@ function AiConversation({ api, requirementId, sessionId }: { api: SpecApi; requi
|
|
|
255
314
|
function PatchPanel({ requirement, act }: { requirement: RequirementView; act: Act }) {
|
|
256
315
|
const [summaries, setSummaries] = useState<Record<string, string>>({})
|
|
257
316
|
const [submitting, setSubmitting] = useState<string>()
|
|
258
|
-
|
|
317
|
+
const current = requirement.patches.filter(patch => patch.baseCommit === requirement.currentCommit && patch.status === 'pending').slice().reverse()
|
|
318
|
+
const historical = requirement.patches.filter(patch => !current.some(item => item.id === patch.id)).slice().reverse()
|
|
319
|
+
const renderPatch = (patch: RequirementView['patches'][number]) => {
|
|
259
320
|
const chinese = /[\u3400-\u9fff]/.test(`${patch.summary}\n${patch.proposedMarkdown}`)
|
|
260
|
-
const commitSummary = summaries[patch.id] ??
|
|
321
|
+
const commitSummary = summaries[patch.id] ?? `合入 AI 建议:${patch.summary}`
|
|
261
322
|
return <article id={`spec-object-${patch.id}`} className={css.reviewCard} key={patch.id}>
|
|
262
|
-
<div className={css.badges}><b>{statusLabel[patch.status] ?? patch.status}</b><span>{reviewKindLabel[patch.reviewKind]}</span
|
|
323
|
+
<div className={css.badges}><b>{statusLabel[patch.status] ?? patch.status}</b><span>{reviewKindLabel[patch.reviewKind]}</span></div>
|
|
263
324
|
<MarkdownBody text={patch.summary} className={css.reviewTitle}/>
|
|
264
|
-
{!chinese && <div className={css.legacyWarning}><strong
|
|
265
|
-
<details className={css.patchDetails}><summary
|
|
266
|
-
{patch.status === 'pending' && (chinese ? <div className={css.patchAccept}><label
|
|
325
|
+
{!chinese && <div className={css.legacyWarning}><strong>旧建议无法使用</strong><p>这份建议生成于中文约束启用前,请重新运行 AI 检查。</p></div>}
|
|
326
|
+
<details className={css.patchDetails}><summary>查看修改后的完整正文</summary><MarkdownBody text={patch.proposedMarkdown}/></details>
|
|
327
|
+
{patch.status === 'pending' && (chinese ? <div className={css.patchAccept}><label>版本说明<input required value={commitSummary} onChange={event => setSummaries(currentValues => ({ ...currentValues, [patch.id]: event.target.value }))}/></label><div className={css.cardActions}><button className={css.execute} disabled={submitting === patch.id || !commitSummary.trim()} onClick={async () => { setSubmitting(patch.id); try { await act(actor => ({ kind: 'patch.accept', participant: actor, requirementId: requirement.id, patchId: patch.id, summary: commitSummary })) } finally { setSubmitting(undefined) } }}>{submitting === patch.id ? '正在写入…' : '接受并写入正文'}</button><button disabled={submitting === patch.id} onClick={() => void act(actor => ({ kind: 'patch.reject', participant: actor, requirementId: requirement.id, patchId: patch.id }))}>不采用</button></div></div> : <div className={css.cardActions}><button onClick={() => void act(actor => ({ kind: 'review.request', participant: actor, requirementId: requirement.id, reviewKind: patch.reviewKind }))}>重新生成建议</button><button onClick={() => void act(actor => ({ kind: 'patch.reject', participant: actor, requirementId: requirement.id, patchId: patch.id }))}>废弃旧建议</button></div>)}
|
|
267
328
|
</article>
|
|
268
|
-
}
|
|
329
|
+
}
|
|
330
|
+
return <>{current.length === 0 && <div className={css.emptyPanel}><strong>当前没有需要审核的 AI 建议</strong><p>AI 根据你的回答整理正文后,建议会出现在这里。</p></div>}{current.map(renderPatch)}{historical.length > 0 && <details className={css.historyGroup}><summary>历史建议 · {historical.length}</summary><div>{historical.map(renderPatch)}</div></details>}</>
|
|
269
331
|
}
|
|
270
332
|
function DecisionPanel({ requirement, act }: { requirement: RequirementView; act: Act }) {
|
|
271
333
|
const [open, setOpen] = useState(false)
|
|
@@ -289,18 +351,13 @@ function ReadyPanel({ requirement, act }: { requirement: RequirementView; act: A
|
|
|
289
351
|
if (ok) { setReturnOpen(false); setForm({ summary: '', sections: '', acceptanceIds: '', source: '', version: '', evidence: '' }) }
|
|
290
352
|
}
|
|
291
353
|
const passed = requirement.readiness.filter(check => check.passed).length
|
|
292
|
-
return <><div className={css.readyHead}><h3
|
|
293
|
-
}
|
|
294
|
-
const categoryLabel: Record<MyActionItem['category'], string> = { 'awaiting-my-response': '待我回复', 'awaiting-my-confirmation': '待我确认', 'initiated-by-me': '我发起的', 'possibly-mine-by-ip': '可能属于当前 IP' }
|
|
295
|
-
function MyItemsPanel({ items, open }: { items: MyActionItem[]; open: (item: MyActionItem) => void }) {
|
|
296
|
-
const categories = ['awaiting-my-response', 'awaiting-my-confirmation', 'initiated-by-me', 'possibly-mine-by-ip'] as const
|
|
297
|
-
return <div className={css.itemsPanel}>{categories.map(category => <section key={category}><h3>{categoryLabel[category]} · {items.filter(item => item.category === category).length}</h3>{items.filter(item => item.category === category).map(item => <button className={css.itemRow} key={`${category}-${item.id}`} onClick={() => open(item)}><span><b>{item.blocking ? '阻塞' : '普通'}</b> · {item.requirementTitle}</span><small>{item.type === 'reconfirm' ? '需要重新确认' : item.type === 'confirm' ? '等待确认' : '等待回复'} · {new Date(item.updatedAt).toLocaleString()}</small></button>)}{items.every(item => item.category !== category) && <p className={css.empty}>当前需求暂无事项</p>}</section>)}</div>
|
|
354
|
+
return <><div className={css.readyHead}><h3>交付条件</h3><span>{passed} / {requirement.readiness.length} 已满足</span></div><div className={css.checklist}>{requirement.readiness.map(check => <section className={`${css.checkItem} ${check.passed ? css.checkPassed : css.checkBlocked}`} key={check.key}><span className={css.checkIcon} aria-hidden="true">{check.passed ? '✓' : '!'}</span><div><strong>{readinessLabel[check.key] ?? check.key}</strong><small>{check.passed ? '已满足' : '需要补充'}</small>{check.reasons.map(reason => <MarkdownBody key={reason} text={reason}/>)}</div></section>)}</div>{requirement.readyPackage && <section><strong>交付需求 · {requirement.readyPackage.packageHash.slice(0, 12)}</strong><MarkdownBody text={requirement.readyPackage.markdown}/></section>}{requirement.stage === 'ready' && <section className={css.downstreamReturn}><button onClick={() => setReturnOpen(value => !value)}>{returnOpen ? '取消返回问题' : '反馈研发阶段发现的问题'}</button>{returnOpen && <div><label>问题摘要(必填)<textarea required value={form.summary} onChange={event => setForm({ ...form, summary: event.target.value })} placeholder="描述研发阶段发现的产品语义或验收问题"/></label><label>受影响章节(与 AC 至少填写一项)<input value={form.sections} onChange={event => setForm({ ...form, sections: event.target.value })} placeholder="业务术语与规则"/></label><label>受影响 AC IDs(与章节至少填写一项)<input value={form.acceptanceIds} onChange={event => setForm({ ...form, acceptanceIds: event.target.value })} placeholder="AC-RETRY-001"/></label><label>依据来源(选填)<input value={form.source} onChange={event => setForm({ ...form, source: event.target.value })} placeholder="测试报告、Issue 或代码位置"/></label><label>依据版本(选填)<input value={form.version} onChange={event => setForm({ ...form, version: event.target.value })} placeholder="commit SHA 或版本号"/></label><label>依据说明(选填)<textarea value={form.evidence} onChange={event => setForm({ ...form, evidence: event.target.value })}/></label><button className={css.execute} disabled={!form.summary.trim() || (!form.sections.trim() && !form.acceptanceIds.trim())} onClick={() => void submitReturn()}>重新打开受影响内容</button></div>}</section>}</>
|
|
298
355
|
}
|
|
299
356
|
function ConflictDialog({ conflict, value, setValue, close, submit, busy }: { conflict: SaveConflict; value: string; setValue: (value: string) => void; close: () => void; submit: () => void; busy: boolean }) {
|
|
300
357
|
return <div className={`${css.modal} ${css.conflictModal}`}><div className={css.conflictDialog}><div className={css.conflictHeader}><div><h2>解决保存冲突</h2><p>基线 {conflict.baseCommit.slice(0, 8)} 已被更新为 {conflict.currentCommit.slice(0, 8)}。Git 尚未写入你的草稿。</p></div><button aria-label="关闭冲突窗口" onClick={close}>×</button></div><div className={css.conflictColumns}><label>打开时的基线(只读)<textarea readOnly value={conflict.baseMarkdown}/></label><label>远端最新版本(只读)<textarea readOnly value={conflict.currentMarkdown}/></label><label>合并稿(必填)<textarea required value={value} onChange={event => setValue(event.target.value)}/></label></div><div className={css.conflictDiffs}><details><summary>基线 → 远端 Diff</summary><pre>{conflict.baseToCurrentDiff}</pre></details><details><summary>基线 → 本地草稿 Diff</summary><pre>{conflict.baseToDraftDiff}</pre></details></div><div className={css.conflictActions}><button onClick={close}>稍后处理</button><button className={css.execute} disabled={busy || !value.trim()} onClick={submit}>{busy ? '正在提交…' : '基于最新版本提交合并稿'}</button></div></div></div>
|
|
301
358
|
}
|
|
302
|
-
function IdentityDialog({ value, boundRole, onChange, close }: { value: ParticipantSnapshot; boundRole?: ParticipantRole; onChange: (value: ParticipantSnapshot) => void; close: () => void }) { return <div className={css.modal}><form onSubmit={event => { event.preventDefault(); if (value.nickname.trim().length >= 2) close() }}><h2
|
|
359
|
+
function IdentityDialog({ value, boundRole, onChange, close }: { value: ParticipantSnapshot; boundRole?: ParticipantRole; onChange: (value: ParticipantSnapshot) => void; close: () => void }) { return <div className={css.modal}><form onSubmit={event => { event.preventDefault(); if (value.nickname.trim().length >= 2) close() }}><h2>设置协作身份</h2><p>用于标记回答、决策和版本确认。同一浏览器首次参与后,角色会保持不变。</p><label>花名(必填)<input required autoFocus value={value.nickname} onChange={event => onChange({ ...value, nickname: event.target.value })}/></label><label>参与角色(必填)<select required disabled={boundRole !== undefined} value={boundRole ?? value.role} onChange={event => onChange({ ...value, role: event.target.value as ParticipantRole })}><option value="product">产品</option><option value="engineering">研发</option></select></label>{boundRole && <small>当前身份已固定为{boundRole === 'product' ? '产品' : '研发'}角色。</small>}<button type="submit" disabled={value.nickname.trim().length < 2}>保存身份</button></form></div> }
|
|
303
360
|
function RenameDialog({ title, setTitle, close, submit, busy }: { title: string; setTitle: (title: string) => void; close: () => void; submit: () => void; busy: boolean }) { return <div className={css.modal}><form onSubmit={event => { event.preventDefault(); submit() }}><h2>重命名需求</h2><label>需求名称(必填)<input required autoFocus value={title} onChange={event => setTitle(event.target.value)}/></label><div><button type="button" onClick={close}>取消</button><button type="submit" disabled={busy || !title.trim()}>保存名称</button></div></form></div> }
|
|
304
361
|
function DeleteDialog({ title, close, submit, busy }: { title: string; close: () => void; submit: () => void; busy: boolean }) { return <div className={css.modal}><form onSubmit={event => { event.preventDefault(); submit() }}><h2>删除需求</h2><p>将删除“{title}”及其协作记录,并创建 Git 删除提交。历史版本仍可从 Git 恢复。</p><div><button type="button" onClick={close}>取消</button><button type="submit" className={css.dangerButton} disabled={busy}>{busy ? '正在删除…' : '确认删除'}</button></div></form></div> }
|
|
305
|
-
function WorkspaceDialog({ value, setValue, workspaces, close, submit, busy }: { value: string; setValue: (value: string) => void; workspaces: ReviewWorkspaceSummary[]; close: () => void; submit: () => void; busy: boolean }) { return <div className={css.modal}><form onSubmit={event => { event.preventDefault(); submit() }}><h2
|
|
306
|
-
function CreateDialog({ value, setValue, workspaces, close, submit, busy }: { value: { title: string; rawRequirement: string; sources: string; workspaceId: string }; setValue: (value: { title: string; rawRequirement: string; sources: string; workspaceId: string }) => void; workspaces: ReviewWorkspaceSummary[]; close: () => void; submit: () => void; busy: boolean }) { return <div className={css.modal}><form onSubmit={event => { event.preventDefault(); submit() }}><h2
|
|
362
|
+
function WorkspaceDialog({ value, setValue, workspaces, close, submit, busy }: { value: string; setValue: (value: string) => void; workspaces: ReviewWorkspaceSummary[]; close: () => void; submit: () => void; busy: boolean }) { return <div className={css.modal}><form onSubmit={event => { event.preventDefault(); submit() }}><h2>关联项目</h2><p>AI 会从所选项目读取代码、规范和团队知识。关联后不能中途切换。</p><label>需求所在项目(必填)<select required autoFocus value={value} onChange={event => setValue(event.target.value)}><option value="" disabled>{workspaces.length > 0 ? '选择一个项目' : '当前没有可用项目'}</option>{workspaces.map(workspace => <option key={workspace.workspaceId} value={workspace.workspaceId}>{workspace.title} · {workspace.path}</option>)}</select></label><div><button type="button" onClick={close}>取消</button><button type="submit" disabled={busy || !value}>确认关联</button></div></form></div> }
|
|
363
|
+
function CreateDialog({ value, setValue, workspaces, close, submit, busy }: { value: { title: string; rawRequirement: string; sources: string; workspaceId: string }; setValue: (value: { title: string; rawRequirement: string; sources: string; workspaceId: string }) => void; workspaces: ReviewWorkspaceSummary[]; close: () => void; submit: () => void; busy: boolean }) { return <div className={css.modal}><form onSubmit={event => { event.preventDefault(); submit() }}><h2>新建需求</h2><p>先写清用户问题和期望结果,其余缺口交给 AI 检查。</p><label>需求标题(必填)<input required value={value.title} onChange={event => setValue({ ...value, title: event.target.value })}/></label><label>需求所在项目(必填)<select required value={value.workspaceId} onChange={event => setValue({ ...value, workspaceId: event.target.value })}><option value="" disabled>{workspaces.length > 0 ? '选择一个项目' : '当前没有可用项目'}</option>{workspaces.map(workspace => <option key={workspace.workspaceId} value={workspace.workspaceId}>{workspace.title} · {workspace.path}</option>)}</select></label><label>原始需求(必填)<textarea required value={value.rawRequirement} onChange={event => setValue({ ...value, rawRequirement: event.target.value })} placeholder="描述用户遇到的问题、期望结果、已有方案和已知限制"/></label><label>补充资料(选填,每行一项)<textarea value={value.sources} onChange={event => setValue({ ...value, sources: event.target.value })} placeholder="相关文档链接 历史决策 代码目录或组件"/></label><div><button type="button" onClick={close}>取消</button><button type="submit" disabled={busy || !value.title.trim() || !value.rawRequirement.trim() || !value.workspaceId}>创建并开始 AI 检查</button></div></form></div> }
|