dsh-spec-collab 0.2.1 → 0.2.2

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.
@@ -9,6 +9,14 @@ const ACTIVE = 'data-dsh-spec-collab-active'
9
9
  const VIEW = '[data-dsh-spec-collab-view]'
10
10
  const ACTIVATE_EVENT = 'dsh-panel-activate'
11
11
  const CLOSE_EVENT = 'dsh-spec-collab-close'
12
+ const SIDEBAR_COLLAPSED = 'data-sidebar-collapsed'
13
+
14
+ function isSidebarChromeControl(target: Element | undefined): boolean {
15
+ const control = target?.closest<HTMLElement>('button, [role="button"]')
16
+ if (control === undefined || control === null) return false
17
+ const label = [control.getAttribute('aria-label'), control.getAttribute('title'), control.textContent].filter(Boolean).join(' ')
18
+ return /侧边栏|边栏|侧栏|sidebar/i.test(label) && /收起|折叠|展开|隐藏|显示|collapse|expand|toggle/i.test(label)
19
+ }
12
20
 
13
21
  export function mountWorkbench(api: SpecApi): () => void {
14
22
  let root: Root | undefined
@@ -34,12 +42,25 @@ export function mountWorkbench(api: SpecApi): () => void {
34
42
 
35
43
  export function mountSidebarEntry(): () => void {
36
44
  let row: HTMLButtonElement | undefined
45
+ let resizeObserver: ResizeObserver | undefined
46
+ const syncSidebarState = (): void => {
47
+ if (!row?.isConnected) return
48
+ const rect = row.getBoundingClientRect()
49
+ const hostCollapsed = document.body.hasAttribute('data-dsh-sidebar-collapsed') || Boolean(row.closest('[data-sidebar-collapsed="true"]'))
50
+ row.toggleAttribute('data-dsh-spec-collab-collapsed', rect.width > 0 ? rect.width < 64 : hostCollapsed)
51
+ }
37
52
  const close = (): void => { document.documentElement.removeAttribute(ACTIVE); row?.classList.remove(css.entryActive!) }
38
53
  const closeOnExternalNavigation = (event: MouseEvent): void => {
39
54
  if (!document.documentElement.hasAttribute(ACTIVE)) return
40
55
  const target = event.target instanceof Element ? event.target : undefined
41
56
  if (target?.closest(VIEW) || target?.closest('[data-dsh-spec-collab-entry]')) return
42
- close()
57
+ if (isSidebarChromeControl(target)) return
58
+ const sidebarCollapsedBefore = document.documentElement.getAttribute(SIDEBAR_COLLAPSED)
59
+ window.setTimeout(() => {
60
+ if (!document.documentElement.hasAttribute(ACTIVE)) return
61
+ if (document.documentElement.getAttribute(SIDEBAR_COLLAPSED) !== sidebarCollapsedBefore) return
62
+ close()
63
+ }, 0)
43
64
  }
44
65
  document.addEventListener('click', closeOnExternalNavigation, true)
45
66
  document.addEventListener(CLOSE_EVENT, close)
@@ -53,9 +74,10 @@ export function mountSidebarEntry(): () => void {
53
74
  document.dispatchEvent(new CustomEvent(ACTIVATE_EVENT, { detail: 'spec-collab' }))
54
75
  }
55
76
  row?.classList.toggle(css.entryActive!, opening)
77
+ syncSidebarState()
56
78
  }
57
79
  const ensure = (): void => {
58
- if (row?.isConnected) return
80
+ if (row?.isConnected) { syncSidebarState(); return }
59
81
  const anchor = findSidebarAnchor(document)
60
82
  if (anchor === undefined) return
61
83
  row = document.createElement('button')
@@ -67,9 +89,13 @@ export function mountSidebarEntry(): () => void {
67
89
  row.innerHTML = '<span aria-hidden="true">▤</span><span>需求讨论</span>'
68
90
  row.addEventListener('click', toggle)
69
91
  anchor.element[anchor.placement](row)
92
+ resizeObserver?.disconnect()
93
+ resizeObserver = typeof ResizeObserver === 'undefined' ? undefined : new ResizeObserver(syncSidebarState)
94
+ resizeObserver?.observe(row)
95
+ window.setTimeout(syncSidebarState, 0)
70
96
  }
71
- const observer = new MutationObserver(ensure)
72
- observer.observe(document.body, { childList: true, subtree: true })
97
+ const observer = new MutationObserver(() => { ensure(); syncSidebarState() })
98
+ observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['class', 'data-dsh-sidebar-collapsed', 'data-sidebar-collapsed'] })
73
99
  ensure()
74
- return () => { observer.disconnect(); document.removeEventListener('click', closeOnExternalNavigation, true); document.removeEventListener(CLOSE_EVENT, close); close(); row?.remove(); document.querySelector(VIEW)?.remove() }
100
+ return () => { observer.disconnect(); resizeObserver?.disconnect(); document.removeEventListener('click', closeOnExternalNavigation, true); document.removeEventListener(CLOSE_EVENT, close); close(); row?.remove(); document.querySelector(VIEW)?.remove() }
75
101
  }
@@ -1,17 +1,19 @@
1
1
  import MarkdownIt from 'markdown-it'
2
- import type { ReviewItem } from '../protocol.ts'
2
+ import type { CommentThread, ReviewItem } from '../protocol.ts'
3
3
 
4
4
  const parser = new MarkdownIt({ html: false })
5
5
  export const reviewBlockSelector = 'h1, h2, h3, h4, p, li, td, th, blockquote'
6
6
 
7
7
  export interface ReviewSourceSnippet {
8
8
  key: string
9
+ targetKey: string
9
10
  label: string
10
11
  markdown: string
11
12
  line?: number
12
13
  }
13
14
 
14
15
  export interface ReviewAnchorTerm {
16
+ key: string
15
17
  kind: 'quote' | 'acceptance' | 'section'
16
18
  label: string
17
19
  value: string
@@ -23,27 +25,73 @@ export function normalizeReviewText(value: string): string {
23
25
 
24
26
  export function reviewAnchorTerms(item: ReviewItem): ReviewAnchorTerm[] {
25
27
  const terms: ReviewAnchorTerm[] = []
26
- for (const anchor of item.sourceAnchors ?? []) {
27
- if (anchor.quote.trim()) terms.push({ kind: 'quote', label: anchor.heading?.trim() || '正文引用', value: anchor.quote.trim() })
28
+ for (const [index, anchor] of (item.sourceAnchors ?? []).entries()) {
29
+ const quote = anchor.quote.trim()
30
+ if (quote) terms.push({ key: `quote-${index}`, kind: 'quote', label: anchor.heading?.trim() || '正文引用', value: quote })
31
+ }
32
+ for (const [index, id] of item.affectedAcceptanceIds.entries()) {
33
+ const value = id.trim()
34
+ if (value) terms.push({ key: `acceptance-${index}-${value}`, kind: 'acceptance', label: value, value })
35
+ }
36
+ for (const [index, section] of item.affectedSections.entries()) {
37
+ const value = section.trim()
38
+ if (value) terms.push({ key: `section-${index}-${value}`, kind: 'section', label: value, value })
28
39
  }
29
- for (const id of item.affectedAcceptanceIds) if (id.trim()) terms.push({ kind: 'acceptance', label: id.trim(), value: id.trim() })
30
- for (const section of item.affectedSections) if (section.trim()) terms.push({ kind: 'section', label: section.trim(), value: section.trim() })
31
40
  return terms
32
41
  }
33
42
 
34
- export function reviewTargetElements(root: HTMLElement, item: ReviewItem): HTMLElement[] {
43
+ export function reviewTargetElements(root: HTMLElement, item: ReviewItem, targetKey?: string): HTMLElement[] {
35
44
  const blocks = Array.from(root.querySelectorAll<HTMLElement>(reviewBlockSelector))
45
+ const terms = reviewAnchorTerms(item)
36
46
  const targets: HTMLElement[] = []
37
- for (const term of reviewAnchorTerms(item)) {
47
+ const addTermTarget = (term: ReviewAnchorTerm): void => {
38
48
  const candidates = (term.kind === 'section' ? blocks.filter(block => /^H[1-4]$/.test(block.tagName)) : blocks)
39
49
  .filter(block => normalizeReviewText(block.textContent ?? '').includes(normalizeReviewText(term.value)))
40
50
  .sort((left, right) => (left.textContent?.length ?? 0) - (right.textContent?.length ?? 0))
41
51
  const target = candidates[0]
42
52
  if (target && !targets.includes(target)) targets.push(target)
43
53
  }
54
+ if (targetKey) {
55
+ terms.filter(term => term.key === targetKey).forEach(addTermTarget)
56
+ if (targets.length > 0) return targets
57
+ }
58
+ terms.forEach(addTermTarget)
44
59
  return targets
45
60
  }
46
61
 
62
+ function previousHeadingText(root: HTMLElement, block: HTMLElement): string {
63
+ const headings = Array.from(root.querySelectorAll<HTMLElement>('h1, h2, h3, h4'))
64
+ return headings.filter(heading => Boolean(heading.compareDocumentPosition(block) & Node.DOCUMENT_POSITION_FOLLOWING)).at(-1)?.textContent?.trim() ?? ''
65
+ }
66
+
67
+ export function commentTargetElements(root: HTMLElement, anchor: CommentThread['anchor']): HTMLElement[] {
68
+ const blocks = Array.from(root.querySelectorAll<HTMLElement>(reviewBlockSelector))
69
+ const quote = anchor.quote.trim()
70
+ const normalizedQuote = normalizeReviewText(quote)
71
+ const heading = normalizeReviewText(anchor.heading ?? '')
72
+ const prefix = normalizeReviewText(anchor.prefix ?? '')
73
+ const suffix = normalizeReviewText(anchor.suffix ?? '')
74
+ const context = normalizeReviewText(`${anchor.prefix ?? ''}${quote}${anchor.suffix ?? ''}`)
75
+ const candidates = normalizedQuote
76
+ ? blocks.filter(block => normalizeReviewText(block.textContent ?? '').includes(normalizedQuote))
77
+ : []
78
+
79
+ const score = (block: HTMLElement): number => {
80
+ const text = normalizeReviewText(block.textContent ?? '')
81
+ let value = block.textContent?.length ?? 0
82
+ if (heading) value += normalizeReviewText(previousHeadingText(root, block)).includes(heading) ? -10000 : 2500
83
+ if (context && text.includes(context)) value -= 3000
84
+ if (prefix && text.includes(prefix.slice(Math.max(0, prefix.length - 32)))) value -= 900
85
+ if (suffix && text.includes(suffix.slice(0, 32))) value -= 900
86
+ return value
87
+ }
88
+
89
+ const targets = candidates.sort((left, right) => score(left) - score(right))
90
+ if (targets.length > 0) return targets
91
+ if (!heading) return []
92
+ return blocks.filter(block => /^H[1-4]$/.test(block.tagName) && normalizeReviewText(block.textContent ?? '').includes(heading))
93
+ }
94
+
47
95
  export function reviewSourceSnippets(markdown: string, item: ReviewItem): ReviewSourceSnippet[] {
48
96
  const lines = markdown.split('\n')
49
97
  const tokens = parser.parse(markdown, {})
@@ -56,30 +104,29 @@ export function reviewSourceSnippets(markdown: string, item: ReviewItem): Review
56
104
  snippets.push(snippet)
57
105
  }
58
106
 
59
- for (const [index, anchor] of (item.sourceAnchors ?? []).entries()) {
60
- const quote = anchor.quote.trim()
61
- if (!quote || !normalizeReviewText(markdown).includes(normalizeReviewText(quote))) continue
62
- const exactLine = lines.findIndex(line => normalizeReviewText(line).includes(normalizeReviewText(quote)))
63
- add({ key: `quote-${index}`, label: anchor.heading?.trim() || '正文引用', markdown: quote, ...(exactLine < 0 ? {} : { line: exactLine + 1 }) })
107
+ for (const term of reviewAnchorTerms(item).filter(term => term.kind === 'quote')) {
108
+ if (!normalizeReviewText(markdown).includes(normalizeReviewText(term.value))) continue
109
+ const exactLine = lines.findIndex(line => normalizeReviewText(line).includes(normalizeReviewText(term.value)))
110
+ add({ key: term.key, targetKey: term.key, label: term.label, markdown: term.value, ...(exactLine < 0 ? {} : { line: exactLine + 1 }) })
64
111
  }
65
112
 
66
- for (const acceptanceId of item.affectedAcceptanceIds) {
67
- const token = tokens.find(candidate => candidate.type === 'inline' && candidate.map && normalizeReviewText(candidate.content).includes(normalizeReviewText(acceptanceId)))
113
+ for (const term of reviewAnchorTerms(item).filter(term => term.kind === 'acceptance')) {
114
+ const token = tokens.find(candidate => candidate.type === 'inline' && candidate.map && normalizeReviewText(candidate.content).includes(normalizeReviewText(term.value)))
68
115
  if (!token?.map) continue
69
116
  const [start, end] = token.map
70
- add({ key: `acceptance-${acceptanceId}`, label: acceptanceId, markdown: lines.slice(start, end).join('\n').trim(), line: start + 1 })
117
+ add({ key: term.key, targetKey: term.key, label: term.label, markdown: lines.slice(start, end).join('\n').trim(), line: start + 1 })
71
118
  }
72
119
 
73
120
  if (snippets.length === 0) {
74
- for (const section of item.affectedSections) {
75
- const headingIndex = tokens.findIndex((token, index) => token.type === 'heading_open' && tokens[index + 1]?.type === 'inline' && normalizeReviewText(tokens[index + 1]!.content).includes(normalizeReviewText(section)))
121
+ for (const term of reviewAnchorTerms(item).filter(term => term.kind === 'section')) {
122
+ const headingIndex = tokens.findIndex((token, index) => token.type === 'heading_open' && tokens[index + 1]?.type === 'inline' && normalizeReviewText(tokens[index + 1]!.content).includes(normalizeReviewText(term.value)))
76
123
  const heading = tokens[headingIndex]
77
124
  if (headingIndex < 0 || !heading?.map) continue
78
125
  const level = Number(heading.tag.slice(1))
79
126
  const nextHeading = tokens.slice(headingIndex + 1).find(token => token.type === 'heading_open' && Number(token.tag.slice(1)) <= level && token.map)
80
127
  const start = heading.map[0]
81
128
  const end = Math.min(nextHeading?.map?.[0] ?? lines.length, start + 9)
82
- add({ key: `section-${section}`, label: section, markdown: lines.slice(start, end).join('\n').trim(), line: start + 1 })
129
+ add({ key: term.key, targetKey: term.key, label: term.label, markdown: lines.slice(start, end).join('\n').trim(), line: start + 1 })
83
130
  }
84
131
  }
85
132
 
@@ -93,12 +93,40 @@ button:disabled { cursor: default; opacity: .52; }
93
93
  .editorMeta, .unsaved { color: var(--muted); font-size: 11px; white-space: nowrap; }
94
94
  .unsaved { color: var(--amber); font-weight: 650; }
95
95
  .saveButton:not(:disabled) { border-color: var(--green); color: var(--green-deep); font-weight: 700; }
96
+ .editorCollabBar { min-width: 0; min-height: 48px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid #d3ddd8; padding: 7px 12px; background: #f7faf8; }
97
+ .collabBarState { min-width: 0; display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 10px; font-weight: 690; }
98
+ .collabStateSaved, .collabStateDirty, .collabStateRunning { display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--line); border-radius: 999px; padding: 3px 8px; background: var(--paper); white-space: nowrap; }
99
+ .collabStateSaved { color: var(--green-deep); }
100
+ .collabStateDirty { border-color: #e0bb82; background: var(--amber-soft); color: #834714; }
101
+ .collabStateRunning { border-color: #b5d2dc; background: var(--blue-soft); color: var(--blue); }
102
+ .collabBarActions { min-width: 0; display: flex; align-items: stretch; gap: 5px; overflow-x: auto; scrollbar-width: none; }
103
+ .collabMetric { min-width: 88px; min-height: 34px; display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 0 6px; border-color: transparent; padding: 4px 8px; background: transparent; text-align: left; }
104
+ .collabMetric b { grid-row: 1 / span 2; min-width: 24px; color: var(--ink); font: 720 18px/1 ui-monospace, SFMono-Regular, Menlo, monospace; text-align: right; }
105
+ .collabMetric span { overflow: hidden; color: var(--muted); font-size: 10px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
106
+ .collabMetric small { overflow: hidden; color: var(--amber); font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
107
+ .collabMetric:hover, .collabMetricActive { border-color: #bad3ca; background: var(--paper); }
108
+ .collabMetricActive b, .collabMetricActive span { color: var(--green-deep); }
109
+ .collabMetricWarn b { color: var(--amber); }
96
110
  .editorContext { min-width: 0; min-height: 42px; display: flex; align-items: center; justify-content: flex-end; gap: 10px; border-bottom: 1px solid #cfe0da; padding: 5px 12px; background: #f1f8f5; }
97
- .selectionPrompt { position: fixed; z-index: 22; box-sizing: border-box; width: min(380px, calc(100vw - 24px)); min-width: 0; display: flex; align-items: center; gap: 6px; border: 1px solid #9dbbb0; border-radius: 6px; padding: 6px; background: var(--paper); box-shadow: 0 8px 24px rgba(23,33,29,.18); }
98
- .selectionPrompt span { min-width: 0; flex: 1; overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
99
- .selectionPrompt button { min-height: 28px; padding: 3px 8px; }
100
- .selectionPrompt button:last-child { width: 28px; border: 0; padding: 0; background: transparent; }
101
- .commentAction { border-color: var(--green) !important; background: var(--mint) !important; color: var(--green-deep) !important; font-weight: 650; }
111
+ .selectionPrompt { position: fixed; z-index: 22; box-sizing: border-box; width: min(360px, calc(100vw - 24px)); min-width: 0; display: grid; gap: 8px; border: 1px solid #8ab3a6; border-radius: 8px; padding: 10px; background: var(--paper); box-shadow: 0 12px 30px rgba(23,33,29,.2); }
112
+ .selectionPrompt::before { content: ''; position: absolute; left: 24px; width: 10px; height: 10px; border: 1px solid #8ab3a6; background: var(--paper); transform: rotate(45deg); }
113
+ .selectionPromptBelow::before { top: -6px; border-right: 0; border-bottom: 0; }
114
+ .selectionPromptAbove::before { bottom: -6px; border-top: 0; border-left: 0; }
115
+ .selectionPromptHead { min-width: 0; display: flex; align-items: flex-start; gap: 8px; }
116
+ .selectionPromptHead > div { min-width: 0; flex: 1; display: grid; gap: 2px; overflow: hidden; }
117
+ .selectionPrompt b { overflow: hidden; color: var(--green-deep); font-size: 10px; line-height: 1.4; text-overflow: ellipsis; white-space: nowrap; }
118
+ .selectionPrompt small { color: var(--muted); font-size: 11px; line-height: 1.5; }
119
+ .selectionPromptHead small { overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
120
+ .selectionPrompt textarea { box-sizing: border-box; width: 100%; min-height: 74px; max-height: 150px; resize: vertical; border: 1px solid var(--line-strong); border-radius: 6px; padding: 8px; color: var(--ink); line-height: 1.55; }
121
+ .selectionPrompt textarea:focus { border-color: #3f8b72; outline: 0; box-shadow: inset 0 0 0 1px #3f8b72; }
122
+ .selectionPromptClose { flex: 0 0 24px; width: 24px; min-height: 24px !important; border: 0 !important; padding: 0 !important; background: transparent !important; color: var(--muted) !important; font-size: 17px; line-height: 1; }
123
+ .selectionPromptActions { min-width: 0; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
124
+ .selectionPromptActions small { min-width: 0; flex: 1; }
125
+ .selectionPromptButtons { flex: 0 0 auto; display: flex; align-items: center; gap: 6px; }
126
+ .selectionPromptCancel, .selectionPromptSubmit { min-height: 28px; padding: 3px 9px; font-size: 12px; }
127
+ .selectionPromptCancel { border-color: transparent; color: var(--muted); }
128
+ .selectionPromptSubmit { border-color: var(--green); background: var(--green); color: #fff; font-weight: 700; }
129
+ .selectionPromptSubmit:hover { border-color: var(--green-deep); background: var(--green-deep); }
102
130
  .editorBody { min-width: 0; min-height: 0; flex: 1; overflow: auto; background: var(--paper); }
103
131
  .emptyMain { height: 100%; display: grid; place-items: center; padding: 24px; background: var(--paper); }
104
132
  .emptyMain > div { width: min(460px, 100%); text-align: center; }
@@ -116,12 +144,24 @@ button:disabled { cursor: default; opacity: .52; }
116
144
  .richEditor :global(.toastui-editor-contents h2) { margin: 36px 0 14px; border-bottom: 1px solid var(--line); padding-bottom: 8px; color: var(--ink); font-size: 20px; line-height: 1.4; }
117
145
  .richEditor :global(.toastui-editor-contents h3) { margin: 26px 0 10px; color: var(--ink); font-size: 16px; line-height: 1.4; }
118
146
  .richEditor :global(.toastui-editor-contents p) { margin: 10px 0; }
119
- .richEditor .reviewSourceSelected { border-radius: 3px; background: #fff3df; box-shadow: -4px 0 #c9792a; }
120
- .reviewAnchorLayer { position: absolute; inset: 0; z-index: 5; overflow: hidden; pointer-events: none; }
121
- .documentReviewAnchor { position: absolute; box-sizing: border-box; width: 23px; height: 23px; min-height: 23px; display: grid; place-items: center; border: 1px solid #8eaaa0; border-radius: 50%; padding: 0; background: var(--paper); color: var(--green-deep); font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace; pointer-events: auto; box-shadow: 0 2px 6px rgba(23,33,29,.12); }
147
+ .richEditor :global([data-annotation-kind]), .richEditor .reviewSourceSelected, .richEditor .commentSourceSelected { border-radius: 4px; }
148
+ .richEditor :global([data-annotation-kind="review"]) { background: linear-gradient(90deg, rgba(255,243,223,.95), rgba(255,249,239,.72)); box-shadow: -3px 0 rgba(201,121,42,.7); }
149
+ .richEditor :global([data-annotation-kind="comment"]) { background: linear-gradient(90deg, rgba(237,247,251,.96), rgba(245,251,253,.74)); box-shadow: -3px 0 rgba(87,148,168,.7); }
150
+ .richEditor :global([data-annotation-kind="mixed"]) { background: linear-gradient(90deg, rgba(255,243,223,.95), rgba(237,247,251,.86)); box-shadow: -3px 0 #9d9a63; }
151
+ .richEditor .reviewSourceSelected { background: #fff0d6; box-shadow: -5px 0 #c9792a, 0 0 0 1px rgba(201,121,42,.22); }
152
+ .richEditor .commentSourceSelected { background: #e7f4f8; box-shadow: -5px 0 #5794a8, 0 0 0 1px rgba(87,148,168,.22); }
153
+ .reviewAnchorLayer { position: absolute; inset: 0; z-index: 21; overflow: hidden; pointer-events: none; }
154
+ .documentAnchorHighlight { position: absolute; z-index: 0; box-sizing: border-box; border-radius: 5px; pointer-events: none; }
155
+ .documentReviewHighlight { background: rgba(255, 243, 223, .72); box-shadow: inset 3px 0 rgba(201,121,42,.72); }
156
+ .documentCommentHighlight { background: rgba(237,247,251,.78); box-shadow: inset 3px 0 rgba(87,148,168,.72); }
157
+ .documentReviewHighlightBlocking { background: rgba(255, 237, 208, .82); box-shadow: inset 3px 0 #c9792a; }
158
+ .documentAnchorHighlightSelected { outline: 1px solid rgba(23,107,80,.22); background: rgba(255, 239, 214, .9); }
159
+ .documentReviewAnchor, .documentCommentAnchor { position: absolute; box-sizing: border-box; width: 25px; height: 22px; min-height: 22px; display: grid; place-items: center; border: 1px solid #8eaaa0; border-radius: 4px; padding: 0; background: var(--paper); color: var(--green-deep); font: 760 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace; pointer-events: auto; box-shadow: 0 2px 6px rgba(23,33,29,.12); }
122
160
  .documentReviewAnchor:hover { border-color: var(--green); background: var(--mint); }
161
+ .documentCommentAnchor { border-color: #8fb7c5; background: var(--blue-soft); color: var(--blue); font-family: Inter, "PingFang SC", ui-sans-serif, system-ui, sans-serif; }
162
+ .documentCommentAnchor:hover { border-color: var(--blue); background: #e3f1f5; }
123
163
  .documentReviewAnchorBlocking { border-color: #c7863f; background: var(--amber-soft); color: #834714; }
124
- .documentReviewAnchorSelected { border-color: var(--green); background: var(--green); color: #fff; }
164
+ .documentAnchorSelected, .documentReviewAnchorSelected { border-color: var(--green); background: var(--green); color: #fff; }
125
165
 
126
166
  .primaryNav { flex: 0 0 auto; min-height: 44px; display: flex; align-items: center; gap: 4px; border-bottom: 1px solid var(--line); padding: 5px 7px; background: var(--paper); }
127
167
  .primaryNav > div { min-width: 0; display: flex; align-items: center; gap: 2px; overflow-x: auto; scrollbar-width: none; }
@@ -222,15 +262,32 @@ button:disabled { cursor: default; opacity: .52; }
222
262
  .threadList p, .threadList blockquote, .threadList strong { overflow-wrap: anywhere; }
223
263
  .threadList section > small { display: block; margin: 6px 0; color: var(--muted); font-size: 11px; }
224
264
  .threadList blockquote { margin: 7px 0; border-left: 3px solid #8fb7c5; padding: 6px 8px; background: var(--blue-soft); }
225
- .newThread { display: grid; gap: 10px; background: #f8faf9; }
226
- .newThread header { display: grid; gap: 2px; }
227
- .newThread header span { color: var(--green); font-size: 9px; font-weight: 750; }
228
- .newThread header strong { color: var(--ink); font-size: 14px; }
229
- .newThread label { display: grid; gap: 5px; color: var(--muted); font-size: 11px; font-weight: 650; }
230
- .newThread textarea { box-sizing: border-box; width: 100%; min-height: 112px; resize: vertical; border: 1px solid var(--line-strong); border-radius: 5px; padding: 8px; }
231
- .newThread > small { margin: 0 !important; color: var(--muted); font-size: 10px; line-height: 1.5; }
232
- .newThread > div:last-child { display: flex; justify-content: flex-end; gap: 7px; }
233
- .reply { margin-top: 8px; padding: 8px; background: var(--blue-soft); }
265
+ .discussionPanel { min-width: 0; display: grid; }
266
+ .discussionSummary { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 10px; border-bottom: 1px solid var(--line); padding: 11px 14px; background: #f8faf9; }
267
+ .discussionSummary > div { min-width: 0; display: grid; gap: 1px; }
268
+ .discussionSummary strong { font-size: 12px; }
269
+ .discussionSummary span { overflow: hidden; color: var(--blue); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
270
+ .discussionSummary b { min-width: 26px; border-radius: 999px; padding: 2px 7px; background: var(--blue-soft); color: var(--blue); font: 720 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; text-align: center; }
271
+ .threadStack { display: grid; }
272
+ .commentThread { display: grid; gap: 10px; border-bottom: 1px solid var(--line); padding: 14px 16px; background: var(--paper); }
273
+ .commentThreadClosed { background: #fafbfa; }
274
+ .commentThreadSelected { position: relative; z-index: 1; background: #f6fbfc; box-shadow: inset 3px 0 var(--blue); }
275
+ .commentThreadHead { min-width: 0; display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
276
+ .commentGlyph { flex: 0 0 23px; width: 23px; height: 23px; display: grid; place-items: center; border: 1px solid #8fb7c5; border-radius: 4px; background: var(--blue-soft); color: var(--blue); font-size: 10px; font-weight: 760; }
277
+ .commentThreadMeta { min-width: 0; flex: 1; display: grid; gap: 5px; }
278
+ .commentThreadMeta strong { color: var(--ink); font-size: 12px; }
279
+ .threadPills { min-width: 0; display: flex; flex-wrap: wrap; gap: 4px; }
280
+ .threadPills span { border: 1px solid var(--line); border-radius: 999px; padding: 1px 6px; color: var(--muted); font-size: 9px; line-height: 1.5; }
281
+ .locateSourceButton { flex: 0 0 auto; min-height: 28px; border-color: transparent; padding: 3px 6px; color: var(--green-deep); font-size: 10px; font-weight: 700; }
282
+ .commentSourceButton { box-sizing: border-box; width: 100%; height: auto; min-height: 0; display: grid; gap: 4px; border-color: transparent; border-left: 3px solid #8fb7c5; border-radius: 0 5px 5px 0; padding: 8px 10px; background: var(--blue-soft); text-align: left; white-space: normal; }
283
+ .commentSourceButton span { color: var(--blue); font-size: 9px; font-weight: 730; }
284
+ .commentSourceButton q { overflow-wrap: anywhere; color: var(--ink); font-size: 12px; line-height: 1.55; quotes: none; }
285
+ .commentSourceButton q::before, .commentSourceButton q::after { content: ''; }
286
+ .commentBody { color: var(--ink); }
287
+ .commentActions { display: flex; flex-wrap: wrap; gap: 6px; border-top: 1px solid var(--line); padding-top: 9px; }
288
+ .commentActions button { min-height: 28px; padding: 3px 8px; font-size: 10px; }
289
+ .replyStack { display: grid; gap: 6px; }
290
+ .reply { padding: 8px; background: var(--blue-soft); }
234
291
  .aiConversation { margin-top: 4px; border-top: 1px solid var(--line); padding-top: 7px; }
235
292
  .chatToggle { width: 100%; border-color: #a8c4ce; color: var(--blue); }
236
293
  .collapseChat { width: 30px; min-height: 26px; justify-self: end; padding: 0; font-size: 16px; }
@@ -326,7 +383,9 @@ button:disabled { cursor: default; opacity: .52; }
326
383
  .decisionSectionHead button { min-height: 28px; border-color: transparent; padding: 3px 6px; color: var(--green-deep); font-size: 10px; font-weight: 700; }
327
384
  .decisionSourceList { display: grid; gap: 8px; }
328
385
  .decisionSource { border-left: 3px solid #7ea7b6; padding: 10px 12px; background: var(--blue-soft); }
329
- .decisionSource > span { display: block; margin-bottom: 4px; color: var(--blue); font-size: 9px; font-weight: 730; }
386
+ .decisionSourceHead { min-width: 0; display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
387
+ .decisionSourceHead span { min-width: 0; overflow-wrap: anywhere; color: var(--blue); font-size: 9px; font-weight: 730; }
388
+ .decisionSourceHead button { flex: 0 0 auto; min-height: 26px; border-color: transparent; padding: 3px 6px; color: var(--green-deep); font-size: 10px; font-weight: 700; }
330
389
  .decisionSource .markdownBody { color: var(--ink); font-size: 12px; line-height: 1.55; }
331
390
  .decisionSource .markdownBody > :first-child { margin-top: 0; }
332
391
  .decisionSource .markdownBody > :last-child { margin-bottom: 0; }
@@ -348,7 +407,7 @@ button:disabled { cursor: default; opacity: .52; }
348
407
  .decisionOptions .selectedDecisionOption b { color: var(--green); }
349
408
  .decisionForm { display: grid; gap: 12px; }
350
409
  .decisionForm label { display: grid; gap: 5px; margin: 0; color: var(--muted); font-size: 10px; font-weight: 680; }
351
- .decisionForm select, .decisionForm textarea { color: var(--ink); background: var(--paper); }
410
+ .decisionForm input, .decisionForm select, .decisionForm textarea { color: var(--ink); background: var(--paper); }
352
411
  .decisionForm textarea { min-height: 190px; line-height: 1.6; resize: vertical; }
353
412
  .decisionModeHint { margin: -6px 0 0; color: var(--muted); font-size: 10px; line-height: 1.5; }
354
413
  .decisionActions { position: sticky; bottom: -28px; display: flex; justify-content: space-between; gap: 8px; margin: 20px -22px -28px; border-top: 1px solid var(--line); padding: 13px 22px; background: #f7f9f8; }
@@ -358,15 +417,61 @@ button:disabled { cursor: default; opacity: .52; }
358
417
  .decisionResponse > strong { color: var(--ink); font-size: 14px; }
359
418
  .decisionResponse > small { color: var(--muted); font-size: 10px; }
360
419
  .decisionResponse > p { margin: 0; }
420
+ .inlineReviewPrompt { position: fixed; z-index: 24; box-sizing: border-box; width: min(520px, calc(100vw - 24px)); max-height: calc(100vh - 24px); overflow: auto; display: grid; gap: 12px; border: 1px solid #c58d53; border-radius: 8px; padding: 13px; background: var(--paper); box-shadow: 0 14px 34px rgba(23,33,29,.22); font-size: 13px; }
421
+ .inlineReviewPrompt::before { content: ''; position: absolute; left: 26px; width: 10px; height: 10px; border: 1px solid #c58d53; background: var(--paper); transform: rotate(45deg); }
422
+ .inlineReviewPrompt.selectionPromptBelow::before { top: -6px; border-right: 0; border-bottom: 0; }
423
+ .inlineReviewPrompt.selectionPromptAbove::before { bottom: -6px; border-top: 0; border-left: 0; }
424
+ .inlineReviewHead { min-width: 0; display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
425
+ .inlineReviewHead > div { min-width: 0; display: grid; gap: 7px; }
426
+ .inlineReviewHead .decisionTags > * { font-size: 11px; }
427
+ .inlineReviewHead strong { overflow-wrap: anywhere; color: var(--ink); font-size: 15px; line-height: 1.55; }
428
+ .inlineReviewHead > button { flex: 0 0 24px; width: 24px; min-height: 24px; border: 0; padding: 0; background: transparent; color: var(--muted); font-size: 18px; line-height: 1; }
429
+ .inlineReviewQuestion { display: grid; gap: 5px; border-left: 3px solid var(--amber); padding: 10px 12px; background: var(--amber-soft); }
430
+ .inlineReviewQuestion > span { color: #834714; font-size: 11px; font-weight: 760; }
431
+ .inlineReviewQuestion .markdownBody { color: var(--ink); font-size: 14px; font-weight: 650; line-height: 1.65; }
432
+ .inlineReviewQuestion .markdownBody p { margin: 0; color: var(--ink); }
433
+ .inlineReviewSource { box-sizing: border-box; width: 100%; height: auto; min-height: 0; display: grid; gap: 5px; border-color: transparent; border-left: 3px solid #8fb7c5; border-radius: 0 5px 5px 0; padding: 9px 11px; background: var(--blue-soft); text-align: left; white-space: normal; }
434
+ .inlineReviewSource span { color: var(--blue); font-size: 11px; font-weight: 730; }
435
+ .inlineReviewSource q { overflow-wrap: anywhere; color: var(--ink); font-size: 13px; line-height: 1.55; quotes: none; }
436
+ .inlineReviewSource q::before, .inlineReviewSource q::after { content: ''; }
437
+ .inlineDecisionOptions { gap: 7px; margin-bottom: 0; }
438
+ .inlineDecisionOptions legend { margin-bottom: 5px; font-size: 12px; }
439
+ .inlineDecisionOptions button { grid-template-columns: minmax(0, 1fr) auto; min-height: 44px; gap: 12px; padding: 9px 11px; }
440
+ .inlineDecisionOptions button span { font-size: 13px; line-height: 1.5; }
441
+ .inlineDecisionOptions button b { min-width: 32px; white-space: nowrap; font-size: 11px; text-align: right; }
442
+ .inlineDecisionOptions .selectedDecisionOption b { min-width: 46px; border-radius: 999px; padding: 3px 7px; background: rgba(23,107,80,.12); color: var(--green-deep); text-align: center; }
443
+ .inlineDecisionForm { gap: 10px; padding: 0; }
444
+ .inlineDecisionForm label { gap: 6px; font-size: 12px; }
445
+ .inlineDecisionForm select, .inlineDecisionForm textarea { font-size: 13px; }
446
+ .inlineDecisionForm textarea { min-height: 112px; max-height: 210px; resize: vertical; }
447
+ .inlineDecisionForm .decisionModeHint { font-size: 12px; }
448
+ .inlineReviewDetails { border-top: 1px solid var(--line); padding-top: 9px; color: var(--muted); font-size: 12px; }
449
+ .inlineReviewDetails summary { cursor: pointer; font-weight: 700; }
450
+ .inlineReviewDetails section { display: grid; gap: 6px; margin-top: 10px; }
451
+ .inlineReviewDetails h3 { margin: 0; color: var(--ink); font-size: 12px; }
452
+ .inlineReviewDetails p { margin: 0; overflow-wrap: anywhere; }
453
+ .inlineReviewActions { position: sticky; bottom: -13px; display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 2px -13px -13px; border-top: 1px solid var(--line); padding: 10px 13px; background: #f7f9f8; }
454
+ .inlineReviewActions > div { display: flex; justify-content: flex-end; gap: 6px; }
455
+ .inlineReviewActions button { min-height: 32px; padding: 5px 11px; font-size: 13px; }
361
456
 
362
457
  .footer { grid-row: 5; display: flex; align-items: center; justify-content: space-between; gap: 10px; overflow: hidden; border-top: 1px solid var(--line); padding: 0 10px; background: var(--paper); color: var(--muted); font-size: 10px; white-space: nowrap; }
363
458
  .footer span { overflow: hidden; text-overflow: ellipsis; }
364
- .entry { box-sizing: border-box; width: 100%; overflow: hidden; }
459
+ .entry { box-sizing: border-box; width: 100%; display: flex !important; align-items: center !important; justify-content: flex-start !important; gap: 6px !important; overflow: hidden; }
365
460
  .entryActive { background: rgba(23,107,80,.1) !important; color: var(--green, #176b50) !important; }
366
- .entry span:first-child { flex: 0 0 20px; text-align: center; }
367
- .entry span:last-child { flex: none; white-space: nowrap; }
368
- :global([data-sidebar-collapsed="true"]) .entry { justify-content: center; gap: 0; padding-inline: 0; }
369
- :global([data-sidebar-collapsed="true"]) .entry span:last-child { display: none !important; }
461
+ .entry span:first-child { width: 14px; flex: 0 0 14px; display: inline-flex; align-items: center; justify-content: center; margin: 0 !important; text-align: center; }
462
+ .entry span:last-child { flex: none; margin: 0 !important; white-space: nowrap; }
463
+ .entry[data-dsh-spec-collab-collapsed] {
464
+ justify-content: center !important;
465
+ gap: 0 !important;
466
+ border-radius: 7px !important;
467
+ padding-inline: 0 !important;
468
+ text-align: center !important;
469
+ }
470
+ .entry[data-dsh-spec-collab-collapsed] span:first-child {
471
+ width: 100% !important;
472
+ flex-basis: 100% !important;
473
+ }
474
+ .entry[data-dsh-spec-collab-collapsed] span:last-child { display: none !important; }
370
475
 
371
476
  @media (max-width: 1080px) {
372
477
  .header { grid-template-columns: minmax(200px, 1fr) auto; }
@@ -377,6 +482,9 @@ button:disabled { cursor: default; opacity: .52; }
377
482
  .workbench { grid-template-rows: auto auto auto minmax(0, 1fr) 28px; }
378
483
  .toolbar { align-items: flex-start; flex-direction: column; }
379
484
  .toolbar > div:last-child { width: 100%; justify-content: flex-start; }
485
+ .editorCollabBar { align-items: flex-start; flex-direction: column; gap: 7px; }
486
+ .collabBarActions { width: 100%; }
487
+ .collabMetric { min-width: 96px; }
380
488
  .summaryInput { flex: 1 1 120px; width: auto; }
381
489
  .selectionPrompt { max-width: calc(100vw - 24px); }
382
490
  }
@@ -397,6 +505,11 @@ button:disabled { cursor: default; opacity: .52; }
397
505
  .mobileCollab .editorPane { display: none; }
398
506
  .review { border-left: 0; }
399
507
  .richEditor :global(.toastui-editor-contents) { padding: 28px 20px 90px; }
508
+ .selectionPromptActions { align-items: stretch; flex-direction: column; }
509
+ .selectionPromptButtons { width: 100%; justify-content: flex-end; }
510
+ .inlineReviewPrompt { width: calc(100vw - 24px); }
511
+ .inlineReviewActions { align-items: stretch; flex-direction: column; }
512
+ .inlineReviewActions > div { width: 100%; flex-wrap: wrap; justify-content: flex-end; }
400
513
  .footer span:first-child { display: none; }
401
514
  .conflictDialog { height: 100%; overflow: auto; grid-template-rows: auto auto auto auto; }
402
515
  .conflictColumns, .conflictDiffs, .compareColumns { grid-template-columns: 1fr; }
package/src/engine.ts CHANGED
@@ -12,6 +12,7 @@ export interface AiCoordinator {
12
12
  const emptyState = (): CollaborationState => ({ schemaVersion: SCHEMA_VERSION, revision: 0, participants: [], requirements: [] })
13
13
 
14
14
  type EngineResult = ActionResult
15
+ type DecisionSourceAnchor = NonNullable<Extract<CollaborationAction, { kind: 'decision.create' }>['sourceAnchors']>[number]
15
16
 
16
17
  export class CollaborationEngine {
17
18
  private state: CollaborationState
@@ -170,7 +171,7 @@ export class CollaborationEngine {
170
171
  const version = this.versions.save({ requirementId: record.id, baseCommit: action.baseCommit, markdown: action.markdown, participant: action.participant, summary: action.summary })
171
172
  const impact = changedScopes(before, action.markdown)
172
173
  record.currentCommit = version.commit; record.updatedAt = now; delete record.readyPackage
173
- invalidateAffected(record, impact.sections, impact.acceptanceIds)
174
+ invalidateAffected(record, impact.sections, impact.acceptanceIds, action.markdown)
174
175
  record.patches.filter(item => item.status === 'pending').forEach(item => { item.status = 'stale' })
175
176
  if (record.stage === 'ready') record.stage = 'joint-review'
176
177
  this.persist()
@@ -216,8 +217,11 @@ export class CollaborationEngine {
216
217
  const patch = record.patches.find(item => item.id === action.patchId)
217
218
  if (patch === undefined || patch.status !== 'pending') throw new Error('pending patch not found')
218
219
  const version = this.versions.save({ requirementId: record.id, baseCommit: patch.baseCommit, markdown: patch.proposedMarkdown, participant: action.participant, summary: action.summary })
220
+ const before = this.versions.read(record.id, record.currentCommit).markdown
221
+ const impact = changedScopes(before, patch.proposedMarkdown)
219
222
  record.currentCommit = version.commit; patch.status = 'accepted'; record.updatedAt = now
220
223
  for (const id of patch.affectedReviewItemIds) { const item = record.reviewItems.find(candidate => candidate.id === id); if (item !== undefined) { item.status = 'resolved'; item.updatedAt = now } }
224
+ invalidateAffected(record, impact.sections, impact.acceptanceIds, patch.proposedMarkdown)
221
225
  record.actionItems.filter(task => task.sourceId === patch.id && task.status === 'pending').forEach(task => { task.status = 'handled'; task.updatedAt = now }); this.persist()
222
226
  this.enqueueReview(record, action.participant, 'change-review')
223
227
  } else if (action.kind === 'patch.reject') {
@@ -225,7 +229,9 @@ export class CollaborationEngine {
225
229
  const patch = record.patches.find(item => item.id === action.patchId); if (patch === undefined) throw new Error('patch not found'); patch.status = 'rejected'; this.persist()
226
230
  } else if (action.kind === 'decision.create') {
227
231
  requireHuman(action.participant)
228
- record.decisions.push({ id: randomUUID(), requirementId: record.id, commit: record.currentCommit, question: action.question, options: action.options, decision: action.decision, rationale: action.rationale, confirmer: action.participant, affectedSections: action.affectedSections, affectedAcceptanceIds: action.affectedAcceptanceIds, createdAt: now, status: 'active' }); this.persist()
232
+ const sourceAnchors = [...(action.sourceAnchors ?? []), ...decisionScopeAnchors(this.versions.read(record.id, record.currentCommit).markdown, action.affectedSections, action.affectedAcceptanceIds)]
233
+ .filter((anchor, index, anchors) => anchor.quote.trim() !== '' && anchors.findIndex(candidate => normalizeAnchorText(candidate.quote) === normalizeAnchorText(anchor.quote) && normalizeAnchorText(candidate.heading ?? '') === normalizeAnchorText(anchor.heading ?? '')) === index)
234
+ record.decisions.push({ id: randomUUID(), requirementId: record.id, commit: record.currentCommit, question: action.question, options: action.options, decision: action.decision, rationale: action.rationale, confirmer: action.participant, affectedSections: action.affectedSections, affectedAcceptanceIds: action.affectedAcceptanceIds, ...(sourceAnchors.length > 0 ? { sourceAnchors } : {}), createdAt: now, status: 'active' }); this.persist()
229
235
  } else if (action.kind === 'confirmation.create') {
230
236
  requireHuman(action.participant)
231
237
  if (action.participant.role !== action.role) throw new Error(`${action.role} role is required`)
@@ -333,7 +339,43 @@ function sections(markdown: string): Map<string, string> { const result = new Ma
333
339
  function acceptance(markdown: string): Map<string, string> { const result = new Map<string, string>(); for (const match of markdown.matchAll(/\*\*(AC-[A-Za-z0-9-]+)(?:\s+[^*]+)?\*\*\s*[::]\s*(.+)/g)) result.set(match[1]!, match[2]!.trim()); return result }
334
340
  function changedScopes(before: string, after: string): { sections: string[]; acceptanceIds: string[] } { const a = sections(before); const b = sections(after); const sectionNames = new Set([...a.keys(), ...b.keys()]); const acA = acceptance(before); const acB = acceptance(after); const acNames = new Set([...acA.keys(), ...acB.keys()]); return { sections: [...sectionNames].filter(key => a.get(key) !== b.get(key)), acceptanceIds: [...acNames].filter(key => acA.get(key) !== acB.get(key)) } }
335
341
  function intersects(left: string[], right: string[]): boolean { return left.some(item => right.includes(item)) }
336
- function invalidateAffected(record: RequirementRecord, changedSections: string[], changedAcceptanceIds: string[]): void {
342
+ function normalizeAnchorText(value: string): string { return value.replace(/[`*_>#\[\]()~-]/g, '').replace(/\s+/g, '').toLocaleLowerCase() }
343
+ function headingForLine(lines: string[], index: number): string | undefined {
344
+ for (let cursor = index; cursor >= 0; cursor -= 1) {
345
+ const match = /^#{1,4}\s+(.+)$/.exec(lines[cursor] ?? '')
346
+ if (match?.[1]) return match[1].trim()
347
+ }
348
+ return undefined
349
+ }
350
+ function decisionScopeAnchors(markdown: string, affectedSections: string[], affectedAcceptanceIds: string[]): DecisionSourceAnchor[] {
351
+ const anchors: DecisionSourceAnchor[] = []
352
+ const sectionMap = sections(markdown)
353
+ for (const section of affectedSections.map(value => value.trim()).filter(Boolean)) {
354
+ const quote = sectionMap.get(section)?.split('\n').map(line => line.trim()).find(line => line && !/^#+\s+/.test(line))
355
+ if (quote) anchors.push({ heading: section, quote })
356
+ }
357
+ const lines = markdown.split('\n')
358
+ for (const acceptanceId of affectedAcceptanceIds.map(value => value.trim()).filter(Boolean)) {
359
+ const index = lines.findIndex(line => normalizeAnchorText(line).includes(normalizeAnchorText(acceptanceId)))
360
+ if (index >= 0) {
361
+ const heading = headingForLine(lines, index)
362
+ anchors.push({ ...(heading ? { heading } : {}), quote: lines[index]!.trim() })
363
+ }
364
+ }
365
+ return anchors
366
+ }
367
+ function decisionAnchorStillExists(markdown: string, anchor: DecisionSourceAnchor): boolean {
368
+ const quote = normalizeAnchorText(anchor.quote)
369
+ if (!quote) return false
370
+ const sectionMap = sections(markdown)
371
+ const candidates = anchor.heading?.trim() ? [sectionMap.get(anchor.heading.trim()) ?? ''] : [markdown]
372
+ const context = normalizeAnchorText(`${anchor.prefix ?? ''}${anchor.quote}${anchor.suffix ?? ''}`)
373
+ return candidates.some(candidate => {
374
+ const normalized = normalizeAnchorText(candidate)
375
+ return normalized.includes(context) || normalized.includes(quote)
376
+ })
377
+ }
378
+ function invalidateAffected(record: RequirementRecord, changedSections: string[], changedAcceptanceIds: string[], currentMarkdown?: string): void {
337
379
  for (const confirmation of record.confirmations) {
338
380
  if (confirmation.status !== 'active') continue
339
381
  const affected = confirmation.scope === 'version' || (confirmation.scope === 'section' && confirmation.scopeId !== undefined && changedSections.includes(confirmation.scopeId)) || (confirmation.scope === 'acceptance-criterion' && confirmation.scopeId !== undefined && changedAcceptanceIds.includes(confirmation.scopeId))
@@ -341,6 +383,7 @@ function invalidateAffected(record: RequirementRecord, changedSections: string[]
341
383
  }
342
384
  record.reviewItems.filter(item => item.status === 'resolved' && (intersects(item.affectedSections, changedSections) || intersects(item.affectedAcceptanceIds, changedAcceptanceIds))).forEach(item => { item.status = 'invalidated'; item.updatedAt = Date.now() })
343
385
  record.decisions.filter(item => item.status === 'active' && (intersects(item.affectedSections, changedSections) || intersects(item.affectedAcceptanceIds, changedAcceptanceIds))).forEach(item => { item.status = 'invalidated' })
386
+ if (currentMarkdown !== undefined) record.decisions.filter(item => item.status === 'active' && item.sourceAnchors?.some(anchor => !decisionAnchorStillExists(currentMarkdown, anchor))).forEach(item => { item.status = 'invalidated' })
344
387
  }
345
388
  export function readiness(markdown: string, record: RequirementRecord): ReadinessCheck[] {
346
389
  const sectionMap = sections(markdown); const ac = acceptance(markdown)
package/src/protocol.ts CHANGED
@@ -41,7 +41,7 @@ export interface CandidatePatch {
41
41
  }
42
42
  export interface Decision {
43
43
  id: string; requirementId: string; commit: string; question: string; options: string[]; decision: string; rationale: string
44
- confirmer: ParticipantSnapshot; affectedSections: string[]; affectedAcceptanceIds: string[]; createdAt: number; status: 'active' | 'invalidated'
44
+ confirmer: ParticipantSnapshot; affectedSections: string[]; affectedAcceptanceIds: string[]; sourceAnchors?: Array<CommentThread['anchor']>; createdAt: number; status: 'active' | 'invalidated'
45
45
  }
46
46
  export interface Confirmation { id: string; requirementId: string; commit: string; role: ParticipantRole; participant: ParticipantSnapshot; scope: ConfirmationScope; scopeId?: string; status: 'active' | 'invalidated'; createdAt: number }
47
47
  export interface ActionItem {
@@ -83,7 +83,7 @@ export type CollaborationAction =
83
83
  | { kind: 'comment.resolve'; participant: ParticipantSnapshot; requirementId: string; commentId: string; resolution: CommentResolution }
84
84
  | { kind: 'patch.accept'; participant: ParticipantSnapshot; requirementId: string; patchId: string; summary: string }
85
85
  | { kind: 'patch.reject'; participant: ParticipantSnapshot; requirementId: string; patchId: string }
86
- | { kind: 'decision.create'; participant: ParticipantSnapshot; requirementId: string; question: string; options: string[]; decision: string; rationale: string; affectedSections: string[]; affectedAcceptanceIds: string[] }
86
+ | { kind: 'decision.create'; participant: ParticipantSnapshot; requirementId: string; question: string; options: string[]; decision: string; rationale: string; affectedSections: string[]; affectedAcceptanceIds: string[]; sourceAnchors?: Array<CommentThread['anchor']> }
87
87
  | { kind: 'confirmation.create'; participant: ParticipantSnapshot; requirementId: string; role: ParticipantRole; scope: ConfirmationScope; scopeId?: string }
88
88
  | { kind: 'stage.advance'; participant: ParticipantSnapshot; requirementId: string }
89
89
  | { kind: 'ready.generate'; participant: ParticipantSnapshot; requirementId: string }