dsh-memory-bond 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/LICENSE +21 -0
- package/README.md +181 -2
- package/README.zh-CN.md +180 -0
- package/SECURITY.md +29 -0
- package/client/memory-icon.svg +21 -0
- package/cordis.patch.yml +3 -0
- package/dist/audit.js +286 -0
- package/dist/automatic.js +16 -0
- package/dist/cache.js +40 -0
- package/dist/client.js +2035 -0
- package/dist/command-scope.js +123 -0
- package/dist/commands.js +156 -0
- package/dist/consolidation-store.js +357 -0
- package/dist/consolidation.js +182 -0
- package/dist/domain.js +245 -0
- package/dist/encoder.js +138 -0
- package/dist/export-files.js +161 -0
- package/dist/file-import-store.js +120 -0
- package/dist/file-import.js +265 -0
- package/dist/foreground-attempts.js +91 -0
- package/dist/guidance.js +242 -0
- package/dist/host.js +19 -0
- package/dist/index-policy.js +191 -0
- package/dist/index.js +349 -0
- package/dist/knowledge-hooks.js +398 -0
- package/dist/knowledge.js +359 -0
- package/dist/maintenance-episodes.js +73 -0
- package/dist/maintenance-import.js +92 -0
- package/dist/maintenance-store.js +738 -0
- package/dist/maintenance.js +376 -0
- package/dist/model-review.js +16 -0
- package/dist/personal.js +60 -0
- package/dist/policy.js +382 -0
- package/dist/prompt-copy.js +93 -0
- package/dist/proposal-receipts.js +70 -0
- package/dist/proposal-review.js +656 -0
- package/dist/propose-contract.js +38 -0
- package/dist/question-answers.js +176 -0
- package/dist/retrieval.js +126 -0
- package/dist/scope-narrowing.js +49 -0
- package/dist/search-index.js +164 -0
- package/dist/search-words.js +5 -0
- package/dist/semantic.js +157 -0
- package/dist/service.js +1473 -0
- package/dist/sharing.js +289 -0
- package/dist/sources.js +149 -0
- package/dist/store.js +1578 -0
- package/dist/tool-experience.js +87 -0
- package/dist/turn-review-store.js +159 -0
- package/dist/turn-review.js +459 -0
- package/dist/ui.js +346 -0
- package/dist/vector-index.js +232 -0
- package/docs/architecture.zh-CN.md +52 -0
- package/docs/benchmark.zh-CN.md +60 -0
- package/docs/benchmarks/repository-tasks.json +5355 -0
- package/docs/images/bond-memory-principle-en.svg +644 -0
- package/docs/images/bond-memory-principle-zh.svg +644 -0
- package/docs/images/bond-memory-principle.drawio +644 -0
- package/docs/images/memory-settings-en.png +0 -0
- package/docs/images/memory-settings-zh.png +0 -0
- package/docs/images/memory-turn-recalled-en.png +0 -0
- package/docs/images/memory-turn-recalled-zh.png +0 -0
- package/docs/images/memory-turn-saved-en.png +0 -0
- package/docs/images/memory-turn-saved-zh.png +0 -0
- package/docs/media/memory-bond-name-en.gif +0 -0
- package/docs/media/memory-bond-name-en.mp4 +0 -0
- package/docs/media/memory-bond-name-zh.gif +0 -0
- package/docs/media/memory-bond-name-zh.mp4 +0 -0
- package/locale/detail.en.md +13 -0
- package/locale/detail.zh.md +13 -0
- package/locale/en.json +345 -0
- package/locale/zh.json +345 -0
- package/native/embeddings/NOTICE.md +12 -0
- package/package.json +117 -4
- package/scripts/benchmark-bond.mjs +72 -0
- package/scripts/benchmark-conditions.mjs +144 -0
- package/scripts/benchmark-example.mjs +37 -0
- package/scripts/benchmark-scale.mjs +119 -0
- package/scripts/benchmark-scenarios.mjs +57 -0
- package/scripts/benchmark-tasks.mjs +244 -0
- package/src/audit.ts +286 -0
- package/src/automatic.ts +21 -0
- package/src/cache.ts +38 -0
- package/src/command-scope.ts +125 -0
- package/src/commands.ts +159 -0
- package/src/consolidation-store.ts +350 -0
- package/src/consolidation.ts +176 -0
- package/src/domain.ts +254 -0
- package/src/encoder.ts +142 -0
- package/src/export-files.ts +178 -0
- package/src/file-import-store.ts +139 -0
- package/src/file-import.ts +256 -0
- package/src/foreground-attempts.ts +97 -0
- package/src/guidance.ts +265 -0
- package/src/host.ts +119 -0
- package/src/index-policy.ts +231 -0
- package/src/index.ts +333 -0
- package/src/knowledge-hooks.ts +456 -0
- package/src/knowledge.ts +432 -0
- package/src/maintenance-episodes.ts +76 -0
- package/src/maintenance-import.ts +107 -0
- package/src/maintenance-store.ts +868 -0
- package/src/maintenance.ts +380 -0
- package/src/model-review.ts +27 -0
- package/src/personal.ts +68 -0
- package/src/policy.ts +508 -0
- package/src/prompt-copy.ts +99 -0
- package/src/proposal-receipts.ts +59 -0
- package/src/proposal-review.ts +614 -0
- package/src/propose-contract.ts +39 -0
- package/src/question-answers.ts +181 -0
- package/src/retrieval.ts +133 -0
- package/src/scope-narrowing.ts +58 -0
- package/src/search-index.ts +177 -0
- package/src/search-words.ts +6 -0
- package/src/semantic.ts +178 -0
- package/src/service.ts +1488 -0
- package/src/sharing.ts +349 -0
- package/src/sources.ts +150 -0
- package/src/store.ts +1829 -0
- package/src/tool-experience.ts +93 -0
- package/src/turn-review-store.ts +158 -0
- package/src/turn-review.ts +418 -0
- package/src/ui.ts +385 -0
- package/src/vector-index.ts +228 -0
package/dist/client.js
ADDED
|
@@ -0,0 +1,2035 @@
|
|
|
1
|
+
(function loadMemoryClient(dictionaries) {
|
|
2
|
+
window.__ModuleLoader__.load({
|
|
3
|
+
id: 'dsh-memory-bond',
|
|
4
|
+
factory(require) {
|
|
5
|
+
const React = require('react')
|
|
6
|
+
return { inject: ['connection', 'slots', 'locale', 'sessions', 'workspaces', 'uiWorkspace'], apply: ctx => apply(ctx, React) }
|
|
7
|
+
},
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
function apply(ctx, React) {
|
|
11
|
+
const section = 'dsh-memory-bond'
|
|
12
|
+
ctx.effect(() => ctx.locale.register(section, dictionaries))
|
|
13
|
+
const t = ctx.locale.bind(section)
|
|
14
|
+
const h = React.createElement
|
|
15
|
+
const { useEffect, useState, useSyncExternalStore } = React
|
|
16
|
+
const CloseSettings = React.createContext(null)
|
|
17
|
+
const channel = '/api'
|
|
18
|
+
const empty = Object.freeze({ proposals: [], rules: [], saved: [], ready: false })
|
|
19
|
+
const guidanceLabels = {
|
|
20
|
+
mandatory: 'guidance.mandatory', duplicate: 'guidance.duplicate', unavailable: 'guidance.unavailable',
|
|
21
|
+
review_required: 'guidance.review_required', ambiguous: 'guidance.ambiguous', permitted: 'guidance.permitted',
|
|
22
|
+
}
|
|
23
|
+
const fieldStyle = { display: 'grid', gap: '.15rem', marginBlock: '.35rem' }
|
|
24
|
+
const actionStyle = { display: 'flex', gap: '.75rem', marginBlockStart: '.5rem', flexWrap: 'wrap' }
|
|
25
|
+
|
|
26
|
+
function controller(connection, sessionId) {
|
|
27
|
+
const viewMethod = sessionId === undefined ? 'get-settings' : 'view'
|
|
28
|
+
let snapshot = empty
|
|
29
|
+
let active
|
|
30
|
+
let detach
|
|
31
|
+
const listeners = new Set()
|
|
32
|
+
const publish = value => {
|
|
33
|
+
snapshot = value
|
|
34
|
+
for (const listener of listeners) listener()
|
|
35
|
+
}
|
|
36
|
+
async function call(method, payload = {}, signal) {
|
|
37
|
+
const args = sessionId === undefined ? payload : { ...payload, sessionId }
|
|
38
|
+
const response = await connection.rpc.call(channel, 'project-memory-ui/' + method, args, signal)
|
|
39
|
+
if (!response.ok) throw Object.assign(Error(response.error.message), { code: response.error.code })
|
|
40
|
+
return response.value
|
|
41
|
+
}
|
|
42
|
+
function refresh(current) {
|
|
43
|
+
active?.abort()
|
|
44
|
+
const run = new AbortController()
|
|
45
|
+
active = run
|
|
46
|
+
if (current) publish({ ...current, ready: true })
|
|
47
|
+
const observe = async () => {
|
|
48
|
+
let version = current?.version
|
|
49
|
+
let lease = current?.lease
|
|
50
|
+
while (!run.signal.aborted) {
|
|
51
|
+
try {
|
|
52
|
+
const result = await call(viewMethod, { version, lease }, run.signal)
|
|
53
|
+
if (run.signal.aborted) return
|
|
54
|
+
version = result.version
|
|
55
|
+
lease = result.lease
|
|
56
|
+
// Open receipt/source details still reauthorize on renewal. Reuse already
|
|
57
|
+
// received collections when the server certifies the session projection.
|
|
58
|
+
publish(result.unchanged ? { ...snapshot, version, lease } : { ...result, ready: true })
|
|
59
|
+
} catch (e) {
|
|
60
|
+
if (run.signal.aborted) return
|
|
61
|
+
// Reconnect/query failures close this view until the host reauthorizes it.
|
|
62
|
+
publish({ ...empty, error: uiError(e) })
|
|
63
|
+
version = undefined
|
|
64
|
+
lease = undefined
|
|
65
|
+
await new Promise(resolve => setTimeout(resolve, 1500))
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
void observe()
|
|
70
|
+
}
|
|
71
|
+
function generationChanged() {
|
|
72
|
+
active?.abort()
|
|
73
|
+
publish(empty)
|
|
74
|
+
if (connection.generation?.getSnapshot()) refresh()
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
call, refresh, refreshIfObserved: current => { if (listeners.size) refresh(current) },
|
|
78
|
+
getSnapshot: () => snapshot,
|
|
79
|
+
subscribe: listener => {
|
|
80
|
+
listeners.add(listener)
|
|
81
|
+
if (listeners.size === 1) {
|
|
82
|
+
detach = connection.generation?.subscribe(generationChanged)
|
|
83
|
+
if (!connection.generation || connection.generation.getSnapshot()) refresh()
|
|
84
|
+
}
|
|
85
|
+
return () => {
|
|
86
|
+
listeners.delete(listener)
|
|
87
|
+
if (listeners.size) return
|
|
88
|
+
detach?.()
|
|
89
|
+
active?.abort()
|
|
90
|
+
snapshot = empty
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function label(text, control) { return h('label', { style: fieldStyle }, text, control) }
|
|
96
|
+
function field(name, value, text, options = {}) {
|
|
97
|
+
return label(text, h('input', { name, defaultValue: value || '', maxLength: 4096, ...options }))
|
|
98
|
+
}
|
|
99
|
+
function pathsFrom(text) {
|
|
100
|
+
return String(text).split('\n').map(p => p.trim()).filter(Boolean)
|
|
101
|
+
}
|
|
102
|
+
// A review answers with a receipt: its state is confirmed or rejected.
|
|
103
|
+
function assertAccepted(result) {
|
|
104
|
+
const outcome = result?.state ?? result?.status
|
|
105
|
+
if (outcome && !['pending', 'confirmed', 'rejected', 'duplicate'].includes(outcome))
|
|
106
|
+
throw Object.assign(Error(result.message || result.reason || outcome), { code: result.reason || outcome })
|
|
107
|
+
return result
|
|
108
|
+
}
|
|
109
|
+
function reviewBlocked(item) {
|
|
110
|
+
return ['mandatory', 'duplicate', 'unavailable'].includes(item.guidance?.status)
|
|
111
|
+
}
|
|
112
|
+
function ReviewRelationships({ index, item, related, projectRules }) {
|
|
113
|
+
const [search, setSearch] = useState('')
|
|
114
|
+
const ids = new Set(related.map(r => r.id))
|
|
115
|
+
const other = projectRules.filter(r => !ids.has(r.id))
|
|
116
|
+
const choices = other.filter(r => [r.id, r.topic, r.when, r.action, ...(r.paths || [])]
|
|
117
|
+
.join(' ').toLowerCase().includes(search.toLowerCase()))
|
|
118
|
+
const description = rule => rule.usage === 'on_demand' && rule.topic
|
|
119
|
+
? t('rule.onDemand', { topic: rule.topic }) : [rule.when, rule.action].filter(Boolean).join(' → ')
|
|
120
|
+
const option = rule => h('option', { key: rule.id, value: rule.id + '@' + rule.rev },
|
|
121
|
+
t('rule.replace', { ref: rule.id + '@' + rule.rev, description: description(rule) }))
|
|
122
|
+
return h(React.Fragment, null,
|
|
123
|
+
related.length > 0 && h('ul', { 'aria-label': t('review.related') }, related.map(r =>
|
|
124
|
+
h('li', { key: r.id }, description(r)))),
|
|
125
|
+
other.length > 0 && label(t('review.findOthers'), h('input', { type: 'search', value: search,
|
|
126
|
+
onChange: e => setSearch(e.target.value) })),
|
|
127
|
+
label(t('review.relationship'), h('select', { name: index + '-relationship',
|
|
128
|
+
defaultValue: item.replace ? item.replace.id + '@' + item.replace.rev : '' },
|
|
129
|
+
h('option', { value: '' }, t('review.choose')), h('option', { value: 'coexist' }, t('review.coexist')),
|
|
130
|
+
related.length > 0 && h('optgroup', { label: t('review.related') }, related.map(option)),
|
|
131
|
+
choices.length > 0 && h('optgroup', { label: t('review.others') }, choices.map(option)))))
|
|
132
|
+
}
|
|
133
|
+
// Imported Markdown stays literal in the editor and receipt. Render common inline
|
|
134
|
+
// formatting as text and React elements; link destinations remain inspectable.
|
|
135
|
+
function importPreview(text, query) {
|
|
136
|
+
const tokens = /(`+)([^\n]+?)\1|\*\*([^*\n]+)\*\*|\[([^\]\n]+)\]\(([^()\s]+)\)/gu
|
|
137
|
+
const parts = []
|
|
138
|
+
let end = 0
|
|
139
|
+
for (const match of text.matchAll(tokens)) {
|
|
140
|
+
parts.push(highlight(text.slice(end, match.index), query))
|
|
141
|
+
const [, ticks, code, bold, label, destination] = match
|
|
142
|
+
parts.push(ticks ? h('code', { key: match.index }, highlight(code, query)) :
|
|
143
|
+
bold ? h('strong', { key: match.index }, highlight(bold, query)) :
|
|
144
|
+
h(React.Fragment, { key: match.index }, highlight(label, query), ' (',
|
|
145
|
+
h('code', null, highlight(destination, query)), ')'))
|
|
146
|
+
end = match.index + match[0].length
|
|
147
|
+
}
|
|
148
|
+
parts.push(highlight(text.slice(end), query))
|
|
149
|
+
return parts
|
|
150
|
+
}
|
|
151
|
+
function Row({ item, index, rules, source, batch, scope, projectName, query, readOnly, error }) {
|
|
152
|
+
const manual = source?.origin === 'manual'
|
|
153
|
+
const file = source?.fileImport
|
|
154
|
+
const key = name => index + '-' + name
|
|
155
|
+
const id = React.useId()
|
|
156
|
+
const { guidance } = item
|
|
157
|
+
const blocked = reviewBlocked(item)
|
|
158
|
+
const local = guidance?.status === 'permitted'
|
|
159
|
+
const checkGuidance = ['review_required', 'ambiguous'].includes(guidance?.status)
|
|
160
|
+
const [selected, setSelected] = useState(!blocked)
|
|
161
|
+
// Mount the optional fields on first edit and keep the draft if the editor closes.
|
|
162
|
+
const [panel, setPanel] = useState(null)
|
|
163
|
+
const editing = panel === 'edit'
|
|
164
|
+
const [preview, setPreview] = useState(item)
|
|
165
|
+
const related = file ? [] : (item.related ?? []).filter(r => r.scope !== 'profile')
|
|
166
|
+
const hasRelation = related.length > 0 || Boolean(item.replace)
|
|
167
|
+
const relationships = () => h(ReviewRelationships, { index, item, related, projectRules: rules })
|
|
168
|
+
useEffect(() => {
|
|
169
|
+
if (selected && !blocked && ['needs_clarification', 'needs_resolution', 'repo_guidance_review_required'].includes(error?.code))
|
|
170
|
+
setPanel('edit')
|
|
171
|
+
}, [error])
|
|
172
|
+
const exceptionFields = () => h(React.Fragment, null,
|
|
173
|
+
field(key('environment'), '', t('review.environment'), { required: local }),
|
|
174
|
+
field(key('scope'), '', t('review.exceptionScope'), { required: local }),
|
|
175
|
+
field(key('present'), '', t('review.presentCommands')),
|
|
176
|
+
field(key('absent'), '', t('review.absentCommands')))
|
|
177
|
+
const guidanceCheck = () => h('label', { className: 'dpm-review-check' },
|
|
178
|
+
h('input', { name: key('guidanceReviewed'), type: 'checkbox', required: checkGuidance }), t('review.guidanceReviewed'))
|
|
179
|
+
function toggleEdit(event) {
|
|
180
|
+
if (!editing) { setPanel('edit'); return }
|
|
181
|
+
const form = event.currentTarget.form
|
|
182
|
+
const action = form.elements.namedItem(key('action'))
|
|
183
|
+
if (!action.reportValidity()) return
|
|
184
|
+
const fields = new FormData(form)
|
|
185
|
+
setPreview({ action: action.value, when: fields.get(key('when')), exceptions: fields.get(key('exceptions')),
|
|
186
|
+
paths: pathsFrom(fields.get(key('paths'))), hard: { branch: fields.get(key('branch')) } })
|
|
187
|
+
setPanel('preview')
|
|
188
|
+
}
|
|
189
|
+
const title = h('span', { className: 'dpm-review-title' }, file ? importPreview(preview.action, query) : highlight(preview.action, query))
|
|
190
|
+
const constraints = [
|
|
191
|
+
preview.when && [t('detail.when'), preview.when],
|
|
192
|
+
preview.exceptions && [t('review.exceptions'), preview.exceptions],
|
|
193
|
+
preview.paths?.length > 0 && [t('detail.paths'), preview.paths.join(t('listSeparator'))],
|
|
194
|
+
preview.hard?.branch && [t('review.branch'), preview.hard.branch],
|
|
195
|
+
].filter(Boolean)
|
|
196
|
+
return h('div', { className: 'dpm-review-item' },
|
|
197
|
+
batch ? h('label', { className: 'dpm-review-check' },
|
|
198
|
+
h('input', { type: 'checkbox', name: 'selected', value: String(index), checked: selected, disabled: blocked || readOnly,
|
|
199
|
+
onChange: event => setSelected(event.target.checked) }), title)
|
|
200
|
+
: h(React.Fragment, null, h('input', { type: 'hidden', name: 'selected', value: String(index), disabled: blocked }), title),
|
|
201
|
+
!batch && h('p', { className: 'dpm-meta' }, h(ScopeLabel, { scope, projectName })),
|
|
202
|
+
constraints.length > 0 && !editing && h('dl', { className: 'dpm-review-conditions' }, constraints.map(([name, text]) =>
|
|
203
|
+
h(React.Fragment, { key: name }, h('dt', null, name), h('dd', null, highlight(text, query))))),
|
|
204
|
+
guidanceLabels[guidance?.status] && h('p', { className: 'dpm-review-note', role: 'note' }, t(guidanceLabels[guidance.status]),
|
|
205
|
+
guidance.path ? ' · ' + guidance.path : '', guidance.excerpt ? ' · ' + guidance.excerpt : ''),
|
|
206
|
+
h('fieldset', { className: 'dpm-review-fields', disabled: !selected || blocked || readOnly, 'aria-label': t('review.title') },
|
|
207
|
+
checkGuidance && guidanceCheck(),
|
|
208
|
+
local && exceptionFields(),
|
|
209
|
+
hasRelation && relationships(),
|
|
210
|
+
h('div', { className: 'dpm-review-tools' },
|
|
211
|
+
!blocked && h('button', { type: 'button', className: 'dpm-tool', 'aria-expanded': editing,
|
|
212
|
+
'aria-controls': id, onClick: toggleEdit }, t(editing ? 'review.done' : 'edit')),
|
|
213
|
+
h('details', { className: 'dpm-review-source', 'data-review-source': true },
|
|
214
|
+
h('summary', null, t('review.source')),
|
|
215
|
+
h('div', { className: 'dpm-review-evidence' },
|
|
216
|
+
file ? h('p', null, t('source.fileImport', file)) :
|
|
217
|
+
h(React.Fragment, null,
|
|
218
|
+
h('p', null, source?.toolResult ? t('source.toolResult', source.toolResult) :
|
|
219
|
+
manual ? t('source.manual') : t('source.excerpt')),
|
|
220
|
+
source?.turnId != null && h('p', { className: 'dpm-meta' }, t('turn', { number: source.turnId }),
|
|
221
|
+
source.sessionId && ' · ' + t('session', { id: source.sessionId }))),
|
|
222
|
+
!source?.toolResult && item.user_quote && h('blockquote', null, item.user_quote),
|
|
223
|
+
item.actionInferred && !file && !manual && !source?.toolResult && item.action !== item.user_quote &&
|
|
224
|
+
h('p', null, t('review.verifyAction')),
|
|
225
|
+
guidance?.files?.filter(f => f.path !== file?.path || f.hash !== file?.sha256)
|
|
226
|
+
.map(f => h('p', { key: f.path, className: 'dpm-meta' }, f.path, ' · ', f.hash))))),
|
|
227
|
+
h('div', { className: 'dpm-review-editor', id, hidden: !editing },
|
|
228
|
+
panel && h(React.Fragment, null,
|
|
229
|
+
label(t('content'), h('textarea', { name: key('action'), required: true, defaultValue: item.action, maxLength: 4096, rows: 2 })),
|
|
230
|
+
field(key('when'), item.when, t('review.when')),
|
|
231
|
+
h('details', null, h('summary', null, t('review.moreConditions')),
|
|
232
|
+
field(key('exceptions'), item.exceptions, t('review.exceptions')),
|
|
233
|
+
label(t('review.paths'), h('textarea', { name: key('paths'), rows: 2, defaultValue: item.paths.join('\n') })),
|
|
234
|
+
field(key('branch'), item.hard?.branch, t('review.onlyBranch'))),
|
|
235
|
+
!source?.toolResult && !file && label(manual ? t('review.manualQuote') : t('review.quote'),
|
|
236
|
+
h('textarea', { name: key('user_quote'), rows: 2, defaultValue: item.user_quote, maxLength: 4096 })),
|
|
237
|
+
!checkGuidance && guidance?.files?.length > 0 && guidanceCheck(),
|
|
238
|
+
!local && (file || checkGuidance) && h('details', { 'data-file-exception': true, open: error?.code === 'needs_clarification' || undefined },
|
|
239
|
+
h('summary', null, t('review.fileException')), exceptionFields()),
|
|
240
|
+
!file && !hasRelation && rules.length > 0 && h('details', { 'data-review-relationship': true, open: error?.code === 'needs_resolution' || undefined },
|
|
241
|
+
h('summary', null, t('review.related')), relationships())))))
|
|
242
|
+
}
|
|
243
|
+
function reviewRows(data, items) {
|
|
244
|
+
return data.getAll('selected').map(value => {
|
|
245
|
+
const index = Number(value)
|
|
246
|
+
const original = items[index]
|
|
247
|
+
const get = (name, fallback = '') => String(data.get(index + '-' + name) ?? fallback).trim()
|
|
248
|
+
const quote = data.get(index + '-user_quote')
|
|
249
|
+
// Textareas normalize line endings. Keep the exact evidence when its displayed text is unchanged.
|
|
250
|
+
const userQuote = quote === null || quote === original.user_quote.replace(/\r\n?/g, '\n') ? original.user_quote : String(quote)
|
|
251
|
+
const relation = get('relationship')
|
|
252
|
+
const split = relation.lastIndexOf('@')
|
|
253
|
+
return { index, changes: {
|
|
254
|
+
when: get('when', original.when), action: get('action', original.action), user_quote: userQuote,
|
|
255
|
+
exceptions: get('exceptions', original.exceptions), paths: pathsFrom(get('paths', original.paths.join('\n'))),
|
|
256
|
+
}, branch: get('branch', original.hard?.branch) || null, ...(relation === 'coexist' ? { coexist: true } : {}),
|
|
257
|
+
...(split < 0 ? {} : { replace: { id: relation.slice(0, split), rev: Number(relation.slice(split + 1)) } }),
|
|
258
|
+
...(get('guidanceReviewed') && { guidanceReviewed: true }),
|
|
259
|
+
...(get('environment') ? { exception: { environment: get('environment'), scope: get('scope'),
|
|
260
|
+
commands: { present: get('present').split(/\s+/u).filter(Boolean), absent: get('absent').split(/\s+/u).filter(Boolean) } } } : {}) }
|
|
261
|
+
})
|
|
262
|
+
}
|
|
263
|
+
function Card({ ctl, proposal, rules, memoryEnabled, scope, projectName, query, readOnly, announce }) {
|
|
264
|
+
const batch = proposal.items.length > 1
|
|
265
|
+
const [seenRevision, setSeenRevision] = useState(proposal.revision)
|
|
266
|
+
const changed = seenRevision !== proposal.revision
|
|
267
|
+
const [busy, setBusy] = useState(false)
|
|
268
|
+
const [error, setError] = useState(null)
|
|
269
|
+
async function submit(event) {
|
|
270
|
+
event.preventDefault()
|
|
271
|
+
const form = event.currentTarget
|
|
272
|
+
const reject = event.nativeEvent.submitter?.value === 'reject'
|
|
273
|
+
const selections = reject ? [] : reviewRows(new FormData(form), proposal.items)
|
|
274
|
+
if (!reject && changed) return
|
|
275
|
+
if (!reject && selections.length === 0) { setError({ message: t('review.empty') }); return }
|
|
276
|
+
if (busy || readOnly) return
|
|
277
|
+
setBusy(true)
|
|
278
|
+
setError(null)
|
|
279
|
+
try {
|
|
280
|
+
assertAccepted(await ctl.call('review', {
|
|
281
|
+
id: proposal.id, revision: proposal.revision, digest: proposal.digest, selections,
|
|
282
|
+
}))
|
|
283
|
+
announce(t(reject ? 'review.ignored' : 'review.remembered', { count: reject ? proposal.items.length : selections.length }))
|
|
284
|
+
} catch (e) {
|
|
285
|
+
const code = e.code === 'review_failed' ? e.message : e.code || e.message
|
|
286
|
+
setError({ message: uiError(e), code })
|
|
287
|
+
} finally { setBusy(false); ctl.refresh() }
|
|
288
|
+
}
|
|
289
|
+
return h('form', { onSubmit: submit, tabIndex: -1, 'aria-label': t('review.title'), 'data-memory-card': proposal.id },
|
|
290
|
+
batch && h('div', { className: 'dpm-review-batch' },
|
|
291
|
+
h('p', { className: 'dpm-meta' }, h(ScopeLabel, { scope, projectName })),
|
|
292
|
+
h('p', null, t('review.batchHint'))),
|
|
293
|
+
memoryEnabled === false && h('p', { role: 'note' }, t('review.enable')),
|
|
294
|
+
changed && h('p', { role: 'alert' }, t('review.changed'), ' ',
|
|
295
|
+
h('button', { type: 'button', onClick: () => setSeenRevision(proposal.revision) }, t('review.checked'))),
|
|
296
|
+
proposal.items.map((item, index) => h(Row, { key: proposal.digest + ':' + index, index, item,
|
|
297
|
+
rules, source: proposal.source, batch, scope, projectName, query, readOnly: readOnly || busy, error })),
|
|
298
|
+
error && h('p', { role: 'alert' }, error.message),
|
|
299
|
+
h('footer', { className: 'dpm-actions dpm-review-actions' },
|
|
300
|
+
h('button', { type: 'submit', value: 'accept', disabled: readOnly || busy || changed || proposal.items.every(reviewBlocked) },
|
|
301
|
+
t(batch ? 'review.confirmBatch' : 'review.confirm')),
|
|
302
|
+
h('button', { type: 'submit', formNoValidate: true, value: 'reject', disabled: readOnly || busy },
|
|
303
|
+
t(batch ? 'review.rejectBatch' : 'review.reject'))))
|
|
304
|
+
}
|
|
305
|
+
// The DSH settings shell shares its root store between the sidebar and shortcut.
|
|
306
|
+
let requestedReview
|
|
307
|
+
function Inbox({ ctl, sessionId }) {
|
|
308
|
+
const view = useSyncExternalStore(ctl.subscribe, ctl.getSnapshot)
|
|
309
|
+
if (!view.ready) return null
|
|
310
|
+
const pending = view.proposals.filter(p => p.state === 'pending')
|
|
311
|
+
if (!pending.length) return null
|
|
312
|
+
const count = pending.reduce((total, p) => total + p.count, 0)
|
|
313
|
+
const message = t(count === 1 ? 'review.hintOne' : 'review.hintMany', { count })
|
|
314
|
+
const shell = (ctx.slots.entriesOfSlot?.('sidebar.settings') || ctx.slots.entries('sidebar.settings'))[0]
|
|
315
|
+
const openSection = shell?.store?.create?.()?.actions?.openSection
|
|
316
|
+
return openSection ? h('button', { type: 'button', 'data-memory-inbox': true, className: 'dpm-review-hint',
|
|
317
|
+
onClick: () => {
|
|
318
|
+
requestedReview = { sessionId, root: view.context.root, projectKey: view.context.projectKey, id: pending[0].id }
|
|
319
|
+
openSection(section)
|
|
320
|
+
} }, message, ' · ', h('span', null, t('review.hintOpen'))) :
|
|
321
|
+
h('span', { className: 'dpm-review-hint' }, message, ' · ', t('review.hintPath'))
|
|
322
|
+
}
|
|
323
|
+
function topicLabel(topic) {
|
|
324
|
+
return topic
|
|
325
|
+
}
|
|
326
|
+
function subjectLabel(subject) {
|
|
327
|
+
if (subject === 'self') return t('subject.self')
|
|
328
|
+
if (subject === 'project') return t('subject.project')
|
|
329
|
+
return subject
|
|
330
|
+
}
|
|
331
|
+
// All chat footers share one stylesheet, including when a long conversation is restored.
|
|
332
|
+
ctx.effect(() => {
|
|
333
|
+
const style = document.createElement('style')
|
|
334
|
+
style.textContent = `
|
|
335
|
+
.dpm-review-hint {
|
|
336
|
+
-webkit-app-region:no-drag;color:var(--dsw-alias-label-secondary, GrayText);
|
|
337
|
+
font:inherit;font-size:12px;line-height:1.5;
|
|
338
|
+
}
|
|
339
|
+
button.dpm-review-hint {border:0;background:none;padding:4px 6px;border-radius:4px;cursor:pointer}
|
|
340
|
+
.dpm-review-hint span {text-decoration:underline;text-underline-offset:3px}
|
|
341
|
+
.dpm-review-hint:focus-visible {outline:2px solid currentColor}
|
|
342
|
+
.dpm-turn-panel {
|
|
343
|
+
--turn-ink: var(--dsw-alias-label-primary, CanvasText);
|
|
344
|
+
--turn-muted: var(--dsw-alias-label-secondary, GrayText);
|
|
345
|
+
box-sizing:border-box;max-inline-size:36rem;min-inline-size:0;margin-block:4px;
|
|
346
|
+
padding:0;border:0;background:transparent;color:var(--turn-ink);font:inherit;font-size:13px;line-height:1.55;
|
|
347
|
+
}
|
|
348
|
+
.dpm-turn-panel:not([open]) {inline-size:fit-content;max-inline-size:100%}
|
|
349
|
+
.dpm-turn-panel :is(p,ul) {margin:0}
|
|
350
|
+
.dpm-turn-panel>summary {
|
|
351
|
+
display:flex;align-items:center;gap:7px;inline-size:fit-content;max-inline-size:100%;min-block-size:28px;
|
|
352
|
+
box-sizing:border-box;padding:2px 4px;border-radius:4px;color:var(--turn-muted);
|
|
353
|
+
cursor:pointer;list-style:none;font-weight:550;
|
|
354
|
+
}
|
|
355
|
+
.dpm-turn-panel>summary::-webkit-details-marker {display:none}
|
|
356
|
+
.dpm-turn-panel>summary svg {flex:none}
|
|
357
|
+
.dpm-turn-counts {font-size:12px;font-weight:400}
|
|
358
|
+
.dpm-turn-panel>summary::after {
|
|
359
|
+
content:"";flex:none;width:6px;height:6px;border:solid currentColor;border-width:0 1.5px 1.5px 0;
|
|
360
|
+
transform:rotate(-45deg);
|
|
361
|
+
}
|
|
362
|
+
.dpm-turn-panel[open]>summary::after {transform:rotate(45deg)}
|
|
363
|
+
.dpm-turn-panel summary:hover,.dpm-turn-panel button:hover {color:var(--turn-ink)}
|
|
364
|
+
.dpm-turn-panel :is(summary,button):focus-visible {outline:2px solid currentColor;outline-offset:1px}
|
|
365
|
+
.dpm-turn-body {padding-block:2px 6px;padding-inline:29px 4px;overflow-wrap:anywhere}
|
|
366
|
+
.dpm-turn-body>p {color:var(--turn-muted);margin-block:4px}
|
|
367
|
+
.dpm-turn-body>[data-memory-saved]:not(:first-child) {margin-block-start:14px}
|
|
368
|
+
.dpm-turn-body [data-memory-saved]>strong {font-size:12px;font-weight:600}
|
|
369
|
+
.dpm-turn-body [data-memory-saved-entry] {margin-block-start:5px}
|
|
370
|
+
.dpm-saved-head {
|
|
371
|
+
display:flex;align-items:baseline;flex-wrap:wrap;column-gap:10px;
|
|
372
|
+
}
|
|
373
|
+
.dpm-saved-head>span {font-weight:550}
|
|
374
|
+
.dpm-turn-body .dpm-saved-content {margin-block-start:2px;white-space:pre-wrap}
|
|
375
|
+
.dpm-turn-panel button {
|
|
376
|
+
min-block-size:24px;padding:0 2px;border:0;border-radius:3px;background:transparent;
|
|
377
|
+
font:inherit;font-size:12px;color:var(--turn-muted);cursor:pointer;text-decoration:underline;text-underline-offset:3px;
|
|
378
|
+
}
|
|
379
|
+
.dpm-turn-panel button:disabled {opacity:.5;cursor:default}
|
|
380
|
+
.dpm-receipt-list {margin-block-start:8px}
|
|
381
|
+
.dpm-receipt-item {margin:0;padding:0;border:0;background:transparent;min-width:0}
|
|
382
|
+
.dpm-receipt-item>summary {
|
|
383
|
+
display:grid;grid-template-columns:minmax(0,1fr) auto 7px;align-items:center;column-gap:8px;
|
|
384
|
+
padding:6px 4px 6px 0;list-style:none;cursor:pointer;border-radius:3px;
|
|
385
|
+
}
|
|
386
|
+
.dpm-receipt-item>summary::-webkit-details-marker {display:none}
|
|
387
|
+
.dpm-receipt-item>summary::after {
|
|
388
|
+
content:"";width:5px;height:5px;box-sizing:border-box;border:solid var(--turn-muted);
|
|
389
|
+
border-width:0 1.5px 1.5px 0;transform:rotate(-45deg);
|
|
390
|
+
}
|
|
391
|
+
.dpm-receipt-item[open]>summary::after {transform:rotate(45deg)}
|
|
392
|
+
.dpm-receipt-item>summary strong {font-weight:600}
|
|
393
|
+
.dpm-receipt-item-meta,.dpm-request-count,.dpm-request-ref {font-size:12px;color:var(--turn-muted)}
|
|
394
|
+
.dpm-receipt-item-meta {display:block}
|
|
395
|
+
.dpm-request-count {white-space:nowrap}
|
|
396
|
+
.dpm-receipt-history {list-style:none;margin:0;padding:0;padding-inline-start:12px}
|
|
397
|
+
.dpm-receipt-history li {margin-block:4px 8px}
|
|
398
|
+
.dpm-receipt-history strong {font-size:12px;font-weight:600}
|
|
399
|
+
.dpm-turn-body .dpm-request-ref {margin-block:4px 10px;padding-inline-start:12px}
|
|
400
|
+
.dpm-turn-body code {font:inherit;font-family:ui-monospace,monospace}
|
|
401
|
+
`
|
|
402
|
+
document.head.append(style)
|
|
403
|
+
return () => style.remove()
|
|
404
|
+
})
|
|
405
|
+
function SavedContent({ ctl, id, rev }) {
|
|
406
|
+
const [reply, setReply] = useState()
|
|
407
|
+
const [retry, setRetry] = useState(0)
|
|
408
|
+
useEffect(() => {
|
|
409
|
+
const abort = new AbortController()
|
|
410
|
+
ctl.call('manage', { op: 'read', args: { id, rev } }, abort.signal)
|
|
411
|
+
.then(({ result }) => {
|
|
412
|
+
if (result?.status) throw Error(result.status)
|
|
413
|
+
if (!abort.signal.aborted) setReply({ ctl, id, rev, action: result.action })
|
|
414
|
+
})
|
|
415
|
+
.catch(error => { if (!abort.signal.aborted) setReply({ ctl, id, rev, error }) })
|
|
416
|
+
return () => abort.abort()
|
|
417
|
+
}, [ctl, id, rev, retry])
|
|
418
|
+
if (reply?.ctl !== ctl || reply.id !== id || reply.rev !== rev)
|
|
419
|
+
return h('p', { role: 'status' }, t('loading'))
|
|
420
|
+
if (reply.error) return h('p', { role: 'alert' }, uiError(reply.error), ' ',
|
|
421
|
+
h('button', { type: 'button', onClick: () => setRetry(n => n + 1) }, t('reload')))
|
|
422
|
+
return h('p', { className: 'dpm-saved-content' }, reply.action)
|
|
423
|
+
}
|
|
424
|
+
function Saved({ ctl, items, open, readOnly, memoryEnabled }) {
|
|
425
|
+
const [busy, setBusy] = useState(() => new Set())
|
|
426
|
+
const [error, setError] = useState('')
|
|
427
|
+
const mark = (id, on) => setBusy(current => {
|
|
428
|
+
const next = new Set(current)
|
|
429
|
+
if (on) next.add(id)
|
|
430
|
+
else next.delete(id)
|
|
431
|
+
return next
|
|
432
|
+
})
|
|
433
|
+
async function undo(item, button) {
|
|
434
|
+
if (busy.has(item.id)) return
|
|
435
|
+
const summary = button.matches(':focus-visible') && button.closest('details')?.querySelector('summary')
|
|
436
|
+
mark(item.id, true)
|
|
437
|
+
setError('')
|
|
438
|
+
try {
|
|
439
|
+
await ctl.call('manage', { op: 'undo', args: { id: item.id, rev: item.rev } })
|
|
440
|
+
if (summary?.isConnected && (document.activeElement === document.body || document.activeElement === button))
|
|
441
|
+
summary.focus({ preventScroll: true })
|
|
442
|
+
} catch (e) {
|
|
443
|
+
setError(uiError(e))
|
|
444
|
+
} finally {
|
|
445
|
+
mark(item.id, false)
|
|
446
|
+
ctl.refresh()
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
return h('section', { 'data-memory-saved': true, 'aria-label': t('turnReceipts.savedHeading') },
|
|
450
|
+
h('strong', null, t('turnReceipts.savedHeading')),
|
|
451
|
+
items.map(item => {
|
|
452
|
+
const topic = item.topic || t('memory')
|
|
453
|
+
const undoLabel = item.hasPrevious ? t('saved.restore') : t('withdraw')
|
|
454
|
+
const scope = item.scope === 'profile' ? t('scope.global') : t('scope.project')
|
|
455
|
+
const detail = scope + ' · ' + (!memoryEnabled ? t('memoryDisabled') : item.usage === 'on_demand' ? t('usage.onDemand') : t('usage.proactive'))
|
|
456
|
+
return h('div', { key: item.id + '@' + item.rev, 'data-memory-saved-entry': item.id },
|
|
457
|
+
h('div', { className: 'dpm-saved-head' },
|
|
458
|
+
h('span', { title: detail }, t(item.rev === 1 ? 'saved.remembered' : 'saved.updated', { topic })),
|
|
459
|
+
!item.reviewed && h('button', { type: 'button', disabled: readOnly || busy.has(item.id),
|
|
460
|
+
'data-memory-undo': item.id, 'aria-label': t('saved.undo', { action: undoLabel, topic }),
|
|
461
|
+
'aria-description': detail, onClick: event => undo(item, event.currentTarget) }, undoLabel)),
|
|
462
|
+
open && h(SavedContent, { ctl, id: item.id, rev: item.rev }))
|
|
463
|
+
}),
|
|
464
|
+
error ? h('p', { role: 'alert' }, error) : null)
|
|
465
|
+
}
|
|
466
|
+
const receiptSignals = ['hint', 'body', 'cited', 'executed']
|
|
467
|
+
function ReceiptList({ requests, rules }) {
|
|
468
|
+
const byVersion = new Map()
|
|
469
|
+
for (const { step, retry, entries } of requests) {
|
|
470
|
+
for (const entry of entries) {
|
|
471
|
+
const ref = entry.id + '@' + entry.rev
|
|
472
|
+
if (!byVersion.has(ref)) byVersion.set(ref, { id: entry.id, rev: entry.rev, ref, signals: new Set(), history: [] })
|
|
473
|
+
const item = byVersion.get(ref)
|
|
474
|
+
if (entry.body && entry.topic) item.title = entry.topic
|
|
475
|
+
const signals = receiptSignals.filter(key => entry[key])
|
|
476
|
+
for (const key of signals) item.signals.add(key)
|
|
477
|
+
item.history.push({ step, retry, signals })
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
// Older or restricted revisions may have no display title. Never label them from a newer revision.
|
|
481
|
+
const rulesByVersion = new Map(rules.map(rule => [rule.id + '@' + rule.rev, rule]))
|
|
482
|
+
const titleCounts = new Map()
|
|
483
|
+
for (const item of byVersion.values()) {
|
|
484
|
+
const rule = rulesByVersion.get(item.ref)
|
|
485
|
+
if (!item.title && item.signals.has('body') && rule?.usage === 'proactive' && rule.sensitive === false && rule.action) {
|
|
486
|
+
const characters = Array.from(rule.action.trim().replace(/\s+/gu, ' '))
|
|
487
|
+
item.title = characters.slice(0, 64).join('') + (characters.length > 64 ? '…' : '')
|
|
488
|
+
}
|
|
489
|
+
item.shortId = item.id.replace(/^mem-/, '').slice(0, 8)
|
|
490
|
+
item.title ||= t('turnReceipts.unnamed', { id: item.shortId })
|
|
491
|
+
titleCounts.set(item.title, (titleCounts.get(item.title) || 0) + 1)
|
|
492
|
+
}
|
|
493
|
+
return h('div', { className: 'dpm-receipt-list' }, Array.from(byVersion.values(), item => {
|
|
494
|
+
const count = item.history.length
|
|
495
|
+
const summary = [t('turnReceipts.version', { rev: item.rev })]
|
|
496
|
+
if (titleCounts.get(item.title) > 1) summary.push(item.shortId)
|
|
497
|
+
summary.push(t(item.signals.has('body') ? 'turnReceipts.summary.body' : 'turnReceipts.summary.hint'))
|
|
498
|
+
for (const key of ['cited', 'executed'])
|
|
499
|
+
if (item.signals.has(key)) summary.push(t('turnReceipts.summary.' + key))
|
|
500
|
+
return h('details', { key: item.ref, className: 'dpm-receipt-item', 'data-memory-ref': item.ref },
|
|
501
|
+
h('summary', null,
|
|
502
|
+
h('span', null, h('strong', null, item.title), h('span', { className: 'dpm-receipt-item-meta' }, summary.join(' · '))),
|
|
503
|
+
h('span', { className: 'dpm-request-count' }, t(count === 1 ? 'turnReceipts.requests.one' : 'turnReceipts.requests.many', { count }))),
|
|
504
|
+
h('ol', { className: 'dpm-receipt-history' }, item.history.map(({ step, retry, signals }) =>
|
|
505
|
+
h('li', { key: step + '-' + retry, 'data-memory-request': step + '-' + retry },
|
|
506
|
+
h('strong', null, t(retry ? 'turnReceipts.retry' : 'turnReceipts.step', { step, retry })),
|
|
507
|
+
signals.map(key => h('div', { key, 'data-memory-signal': key }, t('turnReceipts.' + key)))))),
|
|
508
|
+
h('p', { className: 'dpm-request-ref' }, t('turnReceipts.revision'), ' ', h('code', null, item.ref)))
|
|
509
|
+
}))
|
|
510
|
+
}
|
|
511
|
+
function RequestReceipts({ ctl, answerSeq, view }) {
|
|
512
|
+
const [reply, setReply] = useState()
|
|
513
|
+
const [reload, setReload] = useState(0)
|
|
514
|
+
useEffect(() => {
|
|
515
|
+
const abort = new AbortController()
|
|
516
|
+
ctl.call('turn-receipts', { answerSeq }, abort.signal)
|
|
517
|
+
.then(({ requests, writes }) => {
|
|
518
|
+
if (!abort.signal.aborted) setReply({ ctl, answerSeq, view, requests, writes })
|
|
519
|
+
})
|
|
520
|
+
.catch(error => {
|
|
521
|
+
if (!abort.signal.aborted) setReply({ ctl, answerSeq, view, error })
|
|
522
|
+
})
|
|
523
|
+
return () => abort.abort()
|
|
524
|
+
}, [ctl, answerSeq, view, reload])
|
|
525
|
+
if (reply?.ctl !== ctl || reply.answerSeq !== answerSeq || reply.view !== view)
|
|
526
|
+
return h('p', { role: 'status' }, t('turnReceipts.loading'))
|
|
527
|
+
if (reply.error)
|
|
528
|
+
return h('p', { role: 'alert' }, uiError(reply.error), ' ',
|
|
529
|
+
h('button', { type: 'button', onClick: () => setReload(i => i + 1) }, t('reload')))
|
|
530
|
+
const writes = reply.writes
|
|
531
|
+
return h(React.Fragment, null,
|
|
532
|
+
writes && h('section', { 'data-memory-write-attempts': writes.attempts },
|
|
533
|
+
h('strong', null, t('turnReceipts.attempts', { count: writes.attempts })),
|
|
534
|
+
writes.measured > 0 && h('div', null, t('turnReceipts.comparisons', {
|
|
535
|
+
count: writes.interpretation + writes.repositoryGuidance, interpretation: writes.interpretation, guidance: writes.repositoryGuidance })),
|
|
536
|
+
writes.measured < writes.attempts && h('div', null, t('turnReceipts.unmeasured', { count: writes.attempts - writes.measured })),
|
|
537
|
+
writes.failures.length > 0 && h('ul', null, writes.failures.map(({ attempt, item, reason }) =>
|
|
538
|
+
h('li', { key: attempt + '/' + item }, t(item ? 'turnReceipts.failedItem' : 'turnReceipts.failedCall',
|
|
539
|
+
{ attempt, item, reason: t('turnReceipts.reason.' + reason) }))))),
|
|
540
|
+
reply.requests.length ? h(ReceiptList, { requests: reply.requests, rules: view.rules })
|
|
541
|
+
: h('p', { role: 'status' }, t('turnReceipts.empty')))
|
|
542
|
+
}
|
|
543
|
+
function TurnReceipts({ ctl, answerSeq, view, saved }) {
|
|
544
|
+
const [open, setOpen] = useState(false)
|
|
545
|
+
const added = saved.filter(item => item.rev === 1)
|
|
546
|
+
const updated = saved.filter(item => item.rev > 1)
|
|
547
|
+
const counts = [
|
|
548
|
+
added.length && t('turnReceipts.added', { count: added.length }),
|
|
549
|
+
updated.length && t('turnReceipts.updated', { count: updated.length }),
|
|
550
|
+
].filter(Boolean).join(' · ')
|
|
551
|
+
return h('details', { className: 'dpm-turn-panel', 'data-memory-turn-receipts': answerSeq ?? '',
|
|
552
|
+
onToggle: e => setOpen(e.currentTarget.open) },
|
|
553
|
+
h('summary', null, h(MemorySettingsIcon, { size: 18 }), h('span', null, t('turnReceipts.title')),
|
|
554
|
+
counts && h('span', { className: 'dpm-turn-counts' }, counts)),
|
|
555
|
+
h('div', { className: 'dpm-turn-body' },
|
|
556
|
+
open && answerSeq !== undefined && h(React.Fragment, null,
|
|
557
|
+
h('p', null, t('turnReceipts.description')),
|
|
558
|
+
h(RequestReceipts, { ctl, answerSeq, view })),
|
|
559
|
+
saved.length > 0 && h(Saved, { ctl, items: updated.concat(added), open,
|
|
560
|
+
readOnly: view.context?.readOnly, memoryEnabled: view.memoryEnabled })))
|
|
561
|
+
}
|
|
562
|
+
function Tail({ turn, seq, ctl }) {
|
|
563
|
+
const view = useSyncExternalStore(ctl.subscribe, ctl.getSnapshot)
|
|
564
|
+
if (!view.ready || !turn.end) return null
|
|
565
|
+
const saved = (view.saved || []).filter(item => Number(item.turnId) === turn.turn)
|
|
566
|
+
for (const proposal of view.proposals) {
|
|
567
|
+
if (proposal.state !== 'confirmed' || Number(proposal.turnId) !== turn.turn) continue
|
|
568
|
+
for (const entry of proposal.entries) {
|
|
569
|
+
const rule = view.rules.find(rule => rule.id === entry.id && rule.rev === entry.rev)
|
|
570
|
+
if (rule) saved.push({ id: rule.id, rev: rule.rev, scope: rule.scope, topic: rule.topic, usage: rule.usage, reviewed: true })
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
// Without a durable closing reply, DSH passes the turn-end sequence in this same slot.
|
|
574
|
+
const finalNode = turn.data?.get('turn-tail')?.closing?.finalNode
|
|
575
|
+
const hasAnswer = finalNode?.messageId !== undefined && finalNode.seq === seq
|
|
576
|
+
if (!saved.length && !hasAnswer) return null
|
|
577
|
+
return h('div', { 'data-project-memory-turn': turn.turn },
|
|
578
|
+
h(TurnReceipts, { key: seq, ctl, answerSeq: hasAnswer ? seq : undefined, view, saved }))
|
|
579
|
+
}
|
|
580
|
+
// Small monochrome interface glyphs inherit the host palette and text size.
|
|
581
|
+
function memoryIcon(name) {
|
|
582
|
+
return h('span', { className: 'dpm-icon dpm-icon-' + name, 'aria-hidden': true })
|
|
583
|
+
}
|
|
584
|
+
const managerCss = `
|
|
585
|
+
.dpm-settings {
|
|
586
|
+
--dpm-ink: var(--dsw-alias-label-primary, CanvasText);
|
|
587
|
+
--dpm-muted: var(--dsw-alias-label-tertiary, GrayText);
|
|
588
|
+
--dpm-line: var(--dsw-alias-border-l2, color-mix(in srgb, CanvasText 14%, Canvas));
|
|
589
|
+
--dpm-soft: var(--dsw-alias-bg-module-platform, color-mix(in srgb, CanvasText 5%, Canvas));
|
|
590
|
+
--dpm-hover: var(--dsw-alias-interactive-bg-hover, color-mix(in srgb, CanvasText 9%, Canvas));
|
|
591
|
+
--dpm-surface: var(--dsw-alias-bg-layer-2, Canvas);
|
|
592
|
+
--dpm-primary: var(--dsw-alias-brand-primary, CanvasText);
|
|
593
|
+
--dpm-on-primary: var(--dsw-alias-label-primary-inverted, Canvas);
|
|
594
|
+
--dpm-danger: var(--dsw-alias-state-error-primary, light-dark(#a13635, #ffada7));
|
|
595
|
+
--dpm-divider: var(--dsh-hairline-width, 1px) solid var(--dpm-line);
|
|
596
|
+
--dpm-radius: var(--dsw-radius-md, 12px);
|
|
597
|
+
--dpm-radius-sm: var(--dsw-radius-sm, 8px);
|
|
598
|
+
min-width: 0;
|
|
599
|
+
color: var(--dpm-ink);
|
|
600
|
+
font: inherit;
|
|
601
|
+
font-size: 14px;
|
|
602
|
+
line-height: 22px;
|
|
603
|
+
container-type: inline-size;
|
|
604
|
+
}
|
|
605
|
+
.dpm-manager, .dpm-pane, .dpm-manage {width:100%;min-width:0}
|
|
606
|
+
.dpm-pages {display:flex;align-items:center;justify-content:center;gap:12px;padding-block:12px;font-size:13px}
|
|
607
|
+
.dpm-manager *, .dpm-manager *::before, .dpm-manager *::after {box-sizing:border-box}
|
|
608
|
+
.dpm-manager :is(h2,h3,h4,p,ul) {margin:0}
|
|
609
|
+
.dpm-manager ul {list-style:none;padding:0}
|
|
610
|
+
.dpm-manager :is(button,summary,input,select,textarea) {font:inherit;color:inherit}
|
|
611
|
+
.dpm-manager button, .dpm-manager summary, .dpm-manager select {cursor:pointer}
|
|
612
|
+
.dpm-manager button {
|
|
613
|
+
display:inline-flex;align-items:center;justify-content:center;gap:6px;min-height:32px;padding:4px 11px;
|
|
614
|
+
border:0;border-radius:var(--dpm-radius-sm);background:var(--dpm-soft);font-size:13px;line-height:20px;
|
|
615
|
+
}
|
|
616
|
+
.dpm-manager :is(button,input,select,textarea,summary):focus-visible {
|
|
617
|
+
outline:2px solid var(--dsw-alias-border-selected, currentColor);outline-offset:2px;
|
|
618
|
+
}
|
|
619
|
+
.dpm-manager button:disabled, .dpm-manager input:disabled {opacity:.5;cursor:default}
|
|
620
|
+
.dpm-manager :is(.dpm-primary,[data-memory-card] button[value=accept]) {
|
|
621
|
+
background:var(--dpm-primary);color:var(--dpm-on-primary);
|
|
622
|
+
}
|
|
623
|
+
.dpm-manager .dpm-danger, .dpm-manager [role=alert] {color:var(--dpm-danger)}
|
|
624
|
+
.dpm-manager [role=alert] {font-size:13px}
|
|
625
|
+
.dpm-manager select, .dpm-manager textarea, .dpm-manager [data-memory-card] input:not([type=checkbox]) {
|
|
626
|
+
min-width:0;max-width:100%;padding:6px 10px;border:var(--dpm-divider);border-radius:var(--dpm-radius-sm);
|
|
627
|
+
background:var(--dpm-surface);color:var(--dpm-ink);
|
|
628
|
+
}
|
|
629
|
+
.dpm-setting-row {
|
|
630
|
+
display:flex;align-items:center;justify-content:space-between;gap:16px;
|
|
631
|
+
padding:16px 0;border-bottom:var(--dpm-divider);
|
|
632
|
+
}
|
|
633
|
+
.dpm-setting-copy {flex:1;min-width:0}
|
|
634
|
+
.dpm-setting-title, .dpm-text {display:block;font-size:14px;font-weight:400;line-height:22px}
|
|
635
|
+
.dpm-setting-desc, .dpm-muted, .dpm-meta {
|
|
636
|
+
color:var(--dpm-muted);font-size:12px;line-height:18px;overflow-wrap:anywhere;
|
|
637
|
+
}
|
|
638
|
+
.dpm-setting-desc {display:block;margin-top:4px}
|
|
639
|
+
.dpm-comparison {display:grid;gap:8px;padding-block:10px}
|
|
640
|
+
.dpm-comparison label {display:flex;align-items:baseline;gap:8px;cursor:pointer}
|
|
641
|
+
.dpm-comparison input {flex:none}
|
|
642
|
+
.dpm-pane {padding-top:24px}
|
|
643
|
+
.dpm-records-card {min-width:0}
|
|
644
|
+
.dpm-records-toolbar {
|
|
645
|
+
display:flex;align-items:center;gap:10px;min-width:0;padding:8px 16px;
|
|
646
|
+
border-bottom:var(--dpm-divider);
|
|
647
|
+
}
|
|
648
|
+
.dpm-records-toolbar .dpm-picker {flex:none;max-width:min(38%, 16rem)}
|
|
649
|
+
.dpm-records-count {flex:none;color:var(--dpm-muted);font-size:12px;line-height:18px;font-variant-numeric:tabular-nums}
|
|
650
|
+
.dpm-manage {padding-inline:16px}
|
|
651
|
+
.dpm-records-card > :is([role=alert],[role=status]) {margin:12px 16px}
|
|
652
|
+
.dpm-manage > p[role=status], .dpm-list > p[role=alert] {padding-block:10px}
|
|
653
|
+
.dpm-list > section:last-child > ul > li:last-child {border-bottom:0}
|
|
654
|
+
.dpm-picker {--dpm-picker-ink:var(--dpm-muted);display:inline-flex;align-items:center;position:relative;min-width:0;max-width:100%}
|
|
655
|
+
.dpm-setting-row .dpm-picker {max-width:58%}
|
|
656
|
+
.dpm-picker > .dpm-icon {position:absolute;z-index:1;inset-inline-start:11px;font-size:15px;color:var(--dpm-picker-ink);pointer-events:none}
|
|
657
|
+
.dpm-picker::after {
|
|
658
|
+
content:"";position:absolute;inset-inline-end:12px;top:50%;width:6px;height:6px;
|
|
659
|
+
border-right:1.5px solid var(--dpm-picker-ink);border-bottom:1.5px solid var(--dpm-picker-ink);
|
|
660
|
+
transform:translateY(-75%) rotate(45deg);pointer-events:none;
|
|
661
|
+
}
|
|
662
|
+
.dpm-manager .dpm-picker select {
|
|
663
|
+
appearance:none;field-sizing:content;height:36px;max-width:100%;padding:0 29px 0 11px;
|
|
664
|
+
border:var(--dpm-divider);border-radius:var(--dpm-radius-sm);background:var(--dpm-surface);
|
|
665
|
+
align-items:center;overflow:hidden;white-space:nowrap;font-size:13px;font-weight:500;text-overflow:ellipsis;
|
|
666
|
+
}
|
|
667
|
+
.dpm-manager .dpm-picker:has(> .dpm-icon) select {padding-inline-start:33px}
|
|
668
|
+
.dpm-records-toolbar .dpm-picker select {height:32px;border:0;border-radius:5px;background:transparent;box-shadow:none}
|
|
669
|
+
.dpm-records-toolbar .dpm-picker > .dpm-icon {inset-inline-start:1px}
|
|
670
|
+
.dpm-records-toolbar .dpm-picker:has(> .dpm-icon) select {padding-inline-start:23px}
|
|
671
|
+
.dpm-records-toolbar .dpm-picker:has(> select:open) {--dpm-picker-ink:var(--dpm-ink)}
|
|
672
|
+
.dpm-records-toolbar .dpm-picker:has(> select:open)::after {transform:translateY(-25%) rotate(225deg)}
|
|
673
|
+
@supports (appearance:base-select) {
|
|
674
|
+
.dpm-manager .dpm-picker select.dpm-scope-select, .dpm-scope-select::picker(select) {appearance:base-select}
|
|
675
|
+
.dpm-scope-select::picker-icon {display:none}
|
|
676
|
+
.dpm-manager .dpm-scope-select > button {all:unset;display:block;min-width:0;max-width:100%;pointer-events:none}
|
|
677
|
+
.dpm-scope-select selectedcontent {display:block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
678
|
+
.dpm-scope-select::picker(select) {
|
|
679
|
+
position-area:block-end span-inline-end;
|
|
680
|
+
position-try-fallbacks:block-start span-inline-end,block-end span-inline-start,block-start span-inline-start;
|
|
681
|
+
min-inline-size:max(anchor-size(width), 12rem);max-inline-size:min(24rem, 90vw);max-block-size:min(22rem, 65vh);
|
|
682
|
+
overflow:auto;margin-block:4px;padding:5px;border:var(--dpm-divider);border-radius:var(--dpm-radius);
|
|
683
|
+
background:var(--dpm-surface);color:var(--dpm-ink);box-shadow:0 6px 20px rgb(0 0 0 / .12);
|
|
684
|
+
font-size:13px;line-height:20px;
|
|
685
|
+
}
|
|
686
|
+
.dpm-scope-select {--check-width:14px;--check-gap:8px;--option-inset:9px}
|
|
687
|
+
.dpm-scope-select hr {margin:4px var(--option-inset);border:0;border-block-start:var(--dpm-divider)}
|
|
688
|
+
.dpm-scope-select optgroup {margin:2px 0 0;padding:0;font:inherit}
|
|
689
|
+
.dpm-scope-select legend {
|
|
690
|
+
padding:5px var(--option-inset);padding-inline-start:calc(var(--option-inset) + var(--check-width) + var(--check-gap));
|
|
691
|
+
color:var(--dsw-alias-label-secondary,var(--dpm-ink));font:inherit;font-weight:400;
|
|
692
|
+
}
|
|
693
|
+
.dpm-scope-select option {gap:var(--check-gap);min-height:32px;padding:5px var(--option-inset);border-radius:6px;white-space:normal;overflow-wrap:anywhere}
|
|
694
|
+
.dpm-scope-select option::checkmark {inline-size:var(--check-width);flex:none;text-align:center}
|
|
695
|
+
.dpm-scope-select optgroup option {column-gap:calc(var(--check-gap) + 16px)}
|
|
696
|
+
.dpm-scope-select option:checked {background:var(--dpm-soft);font-weight:600}
|
|
697
|
+
.dpm-scope-select option:is(:hover,:focus-visible) {background:var(--dpm-hover)}
|
|
698
|
+
}
|
|
699
|
+
.dpm-preferences, .dpm-records-card {
|
|
700
|
+
border:var(--dpm-divider);border-radius:var(--dpm-radius);background:var(--dpm-surface);
|
|
701
|
+
}
|
|
702
|
+
.dpm-preferences .dpm-setting-row {align-items:flex-start;padding:12px 16px}
|
|
703
|
+
.dpm-preferences .dpm-setting-row:first-child {border-radius:var(--dpm-radius) var(--dpm-radius) 0 0}
|
|
704
|
+
.dpm-preferences .dpm-setting-row:last-of-type {border:0;border-radius:0 0 var(--dpm-radius) var(--dpm-radius)}
|
|
705
|
+
.dpm-preferences .dpm-setting-title {font-weight:600}
|
|
706
|
+
.dpm-preferences .dpm-setting-desc {margin-top:2px;color:var(--dsw-alias-label-secondary,var(--dpm-muted))}
|
|
707
|
+
.dpm-preferences .dpm-setting-row:has(.dpm-switch:disabled) .dpm-setting-title {color:var(--dpm-muted)}
|
|
708
|
+
.dpm-setting-saving {margin-inline-start:8px;color:var(--dpm-muted);font-size:12px;font-weight:400}
|
|
709
|
+
.dpm-setting-note {
|
|
710
|
+
display:flex;align-items:flex-start;gap:6px;margin-top:6px;color:var(--dpm-muted);
|
|
711
|
+
font-size:12px;line-height:18px;overflow-wrap:anywhere;
|
|
712
|
+
}
|
|
713
|
+
.dpm-setting-note .dpm-icon-clock {font-size:12px;margin-top:3px}
|
|
714
|
+
.dpm-icon-clock::before {content:"";inset:0;border:1px solid;border-radius:50%}
|
|
715
|
+
.dpm-icon-clock::after {content:"";left:46%;top:23%;width:26%;height:33%;border-left:1px solid;border-bottom:1px solid}
|
|
716
|
+
.dpm-setting-feedback {padding:8px 16px;border-top:var(--dpm-divider);font-size:12px;color:var(--dpm-muted)}
|
|
717
|
+
.dpm-switch-control {position:relative;flex:none;width:38px;height:22px}
|
|
718
|
+
.dpm-manager .dpm-switch {
|
|
719
|
+
position:absolute;inset:0;z-index:1;width:100%;height:100%;margin:0;opacity:0;cursor:pointer;
|
|
720
|
+
}
|
|
721
|
+
.dpm-manager .dpm-switch:disabled {opacity:0;cursor:default}
|
|
722
|
+
.dpm-manager .dpm-switch[aria-disabled=true]:enabled {cursor:progress}
|
|
723
|
+
.dpm-switch-track {
|
|
724
|
+
display:block;position:absolute;inset:0;border-radius:999px;corner-shape:round;pointer-events:none;
|
|
725
|
+
background:color-mix(in srgb,var(--dpm-ink) 54%,var(--dpm-surface));transition:background-color .14s ease;
|
|
726
|
+
}
|
|
727
|
+
.dpm-switch-track::after {
|
|
728
|
+
content:"";position:absolute;inset-block-start:3px;inset-inline-start:3px;width:16px;height:16px;
|
|
729
|
+
border-radius:50%;corner-shape:round;background:var(--dpm-on-primary);transition:inset-inline-start .14s ease;
|
|
730
|
+
}
|
|
731
|
+
.dpm-switch:checked + .dpm-switch-track {background:var(--dpm-primary)}
|
|
732
|
+
.dpm-switch:checked + .dpm-switch-track::after {inset-inline-start:19px}
|
|
733
|
+
.dpm-switch:disabled + .dpm-switch-track {filter:grayscale(1);opacity:.4}
|
|
734
|
+
.dpm-switch:focus-visible + .dpm-switch-track {
|
|
735
|
+
outline:2px solid var(--dsw-alias-border-selected,currentColor);outline-offset:3px;
|
|
736
|
+
}
|
|
737
|
+
@media (prefers-reduced-motion:reduce) {
|
|
738
|
+
.dpm-switch-track,.dpm-switch-track::after {transition:none}
|
|
739
|
+
}
|
|
740
|
+
.dpm-manager > [role=status], .dpm-pane > :is([role=alert],[role=status]) {margin-block:16px}
|
|
741
|
+
.dpm-search-wrap {position:relative;display:flex;align-items:center;flex:0 1 14rem;min-width:0;margin-inline-start:auto}
|
|
742
|
+
.dpm-search-wrap > .dpm-icon {position:absolute;inset-inline-start:12px;color:var(--dpm-muted);pointer-events:none}
|
|
743
|
+
.dpm-manager .dpm-search {
|
|
744
|
+
appearance:none;width:100%;min-width:0;height:32px;border:var(--dpm-divider);border-radius:var(--dpm-radius-sm);
|
|
745
|
+
padding:5px 9px;padding-inline-start:35px;background:var(--dpm-surface);font-size:13px;line-height:20px;
|
|
746
|
+
}
|
|
747
|
+
.dpm-search::placeholder {color:var(--dpm-muted)}
|
|
748
|
+
.dpm-search::-webkit-search-cancel-button {display:none}
|
|
749
|
+
.dpm-search-wrap:has(.dpm-clear-search) .dpm-search {padding-inline-end:36px}
|
|
750
|
+
.dpm-search-wrap:has(.dpm-kbd) .dpm-search {padding-inline-end:54px}
|
|
751
|
+
.dpm-kbd {
|
|
752
|
+
position:absolute;inset-inline-end:10px;display:inline-flex;align-items:center;height:21px;padding:0 5px;
|
|
753
|
+
border:var(--dpm-divider);border-radius:5px;font:inherit;font-size:11px;color:var(--dpm-muted);pointer-events:none;
|
|
754
|
+
}
|
|
755
|
+
.dpm-search-wrap:focus-within .dpm-kbd {visibility:hidden}
|
|
756
|
+
@container (max-width:480px) {
|
|
757
|
+
.dpm-kbd {display:none}
|
|
758
|
+
.dpm-search-wrap:has(.dpm-kbd) .dpm-search {padding-inline-end:8px}
|
|
759
|
+
}
|
|
760
|
+
@container (max-width:380px) {
|
|
761
|
+
.dpm-records-toolbar {gap:6px}
|
|
762
|
+
.dpm-records-toolbar .dpm-picker {max-width:36%}
|
|
763
|
+
.dpm-records-count {font-size:11px}
|
|
764
|
+
.dpm-search-wrap > .dpm-icon {inset-inline-start:8px}
|
|
765
|
+
.dpm-manager .dpm-search {padding-inline-start:27px}
|
|
766
|
+
}
|
|
767
|
+
@container (max-width:285px) {
|
|
768
|
+
.dpm-records-toolbar {flex-wrap:wrap}
|
|
769
|
+
.dpm-records-toolbar .dpm-picker {max-width:60%}
|
|
770
|
+
.dpm-search-wrap {flex:1 0 100%}
|
|
771
|
+
}
|
|
772
|
+
.dpm-manager .dpm-clear-search {position:absolute;inset-inline-end:4px;width:28px;min-height:28px;padding:0;background:transparent}
|
|
773
|
+
.dpm-clear-search .dpm-icon {font-size:13px}
|
|
774
|
+
|
|
775
|
+
.dpm-section {padding-block-start:8px}
|
|
776
|
+
.dpm-section + .dpm-section {padding-block-start:18px}
|
|
777
|
+
.dpm-section-head {display:flex;align-items:center;gap:7px;padding-block:4px 7px;border-bottom:var(--dpm-divider)}
|
|
778
|
+
.dpm-section-head h4 {font-size:13px;font-weight:600;line-height:20px}
|
|
779
|
+
.dpm-section-head small {
|
|
780
|
+
min-width:19px;padding-inline:5px;border-radius:5px;background:var(--dpm-soft);color:var(--dpm-muted);
|
|
781
|
+
text-align:center;font-size:11px;line-height:18px;font-variant-numeric:tabular-nums;
|
|
782
|
+
}
|
|
783
|
+
.dpm-row, .dpm-pending {padding:12px 0;border-bottom:var(--dpm-divider);overflow-wrap:anywhere}
|
|
784
|
+
.dpm-memory-head {display:flex;align-items:flex-start;justify-content:space-between;gap:8px}
|
|
785
|
+
.dpm-row-copy {min-width:0;flex:1}
|
|
786
|
+
.dpm-text {white-space:pre-wrap;overflow-wrap:anywhere}
|
|
787
|
+
.dpm-row[data-memory-rule], .dpm-row[data-invalid-memory] {padding:0;--dpm-row-indent:20px}
|
|
788
|
+
.dpm-memory-head {padding-block:8px}
|
|
789
|
+
.dpm-manager .dpm-row-toggle {
|
|
790
|
+
display:grid;grid-template-columns:var(--dpm-row-indent) minmax(0,1fr);gap:0;align-items:start;
|
|
791
|
+
flex:1;min-width:0;padding:5px 0;
|
|
792
|
+
background:transparent;text-align:start;color:var(--dpm-ink);
|
|
793
|
+
}
|
|
794
|
+
.dpm-row-toggle::before {
|
|
795
|
+
content:"";width:7px;height:7px;margin:7px 0 0 3px;color:var(--dpm-muted);
|
|
796
|
+
border:solid currentColor;border-width:0 1.5px 1.5px 0;transform:rotate(-45deg);
|
|
797
|
+
}
|
|
798
|
+
.dpm-row-toggle[aria-expanded=true]::before {transform:translateY(-1px) rotate(45deg)}
|
|
799
|
+
.dpm-row-toggle .dpm-row-copy {display:flex;flex-wrap:wrap;align-items:baseline;gap:2px 10px}
|
|
800
|
+
.dpm-row-toggle[aria-expanded=true] .dpm-row-copy {display:grid;grid-template-columns:minmax(0,1fr)}
|
|
801
|
+
.dpm-row-toggle .dpm-text {min-width:0;font-size:15px;font-weight:500;line-height:22px}
|
|
802
|
+
.dpm-scope-meta {display:flex;flex-wrap:wrap;align-items:baseline;gap:0 5px;font-size:12px}
|
|
803
|
+
.dpm-scope-label {
|
|
804
|
+
display:inline-block;min-width:0;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
|
|
805
|
+
vertical-align:bottom;
|
|
806
|
+
}
|
|
807
|
+
.dpm-row-detail {margin-inline-start:var(--dpm-row-indent);font-size:13px;line-height:20px}
|
|
808
|
+
.dpm-row-detail blockquote {margin:6px 0;padding:3px 0 3px 10px;
|
|
809
|
+
border-inline-start:2px solid var(--dpm-line);white-space:pre-wrap;overflow-wrap:anywhere}
|
|
810
|
+
.dpm-row-detail .dpm-profile-quote {margin:0;padding:0;border:0}
|
|
811
|
+
.dpm-profile-quote::before {content:open-quote}
|
|
812
|
+
.dpm-profile-quote::after {content:close-quote}
|
|
813
|
+
.dpm-row-detail code {font:12px/1.55 ui-monospace,monospace;overflow-wrap:anywhere}
|
|
814
|
+
.dpm-detail-fields, .dpm-usage-fields {
|
|
815
|
+
display:grid;grid-template-columns:minmax(66px,max-content) minmax(0,1fr);align-items:baseline;gap:9px 10px;margin:0;
|
|
816
|
+
}
|
|
817
|
+
.dpm-detail-fields {padding-block:0 12px}
|
|
818
|
+
.dpm-row-detail :is(.dpm-detail-fields,.dpm-usage-fields) > dt {
|
|
819
|
+
max-inline-size:7.5em;color:var(--dsw-alias-label-secondary,var(--dpm-muted));font-size:13px;font-weight:400;
|
|
820
|
+
}
|
|
821
|
+
.dpm-row-detail :is(.dpm-detail-fields,.dpm-usage-fields) > dd {min-width:0;margin:0}
|
|
822
|
+
.dpm-source-line {display:flex;flex-wrap:wrap;align-items:baseline;gap:1px 16px}
|
|
823
|
+
.dpm-source-origin {display:inline-flex;align-items:baseline;flex-wrap:wrap;gap:0 5px;color:var(--dpm-muted);font-size:12px}
|
|
824
|
+
.dpm-manager .dpm-source-link {
|
|
825
|
+
min-height:24px;padding:0;border-radius:3px;background:transparent;
|
|
826
|
+
color:var(--dsw-alias-link,LinkText);font-size:13px;font-weight:500;
|
|
827
|
+
text-decoration:underline;text-underline-offset:3px;
|
|
828
|
+
}
|
|
829
|
+
.dpm-source-link:hover {text-decoration-thickness:2px}
|
|
830
|
+
.dpm-source-link[aria-busy=true] {cursor:progress}
|
|
831
|
+
.dpm-source :is(.dpm-evidence-label,.dpm-meta), .dpm-quote-disclosure > summary {
|
|
832
|
+
color:var(--dsw-alias-label-secondary,var(--dpm-muted));font-size:13px;font-weight:400;
|
|
833
|
+
}
|
|
834
|
+
.dpm-source-line + .dpm-evidence-label {display:block;margin-top:5px}
|
|
835
|
+
.dpm-quote-disclosure[open] {flex-basis:100%}
|
|
836
|
+
.dpm-quote-disclosure > summary, .dpm-usage > summary {
|
|
837
|
+
display:flex;align-items:center;gap:8px;min-height:24px;list-style:none;border-radius:3px;
|
|
838
|
+
}
|
|
839
|
+
.dpm-quote-disclosure > summary {width:fit-content}
|
|
840
|
+
:is(.dpm-quote-disclosure,.dpm-usage) > summary::-webkit-details-marker {display:none}
|
|
841
|
+
:is(.dpm-quote-disclosure,.dpm-usage) > summary::before {
|
|
842
|
+
content:"";flex:none;width:6px;height:6px;border:solid currentColor;border-width:0 1.5px 1.5px 0;transform:rotate(-45deg);
|
|
843
|
+
}
|
|
844
|
+
:is(.dpm-quote-disclosure,.dpm-usage)[open] > summary::before {transform:translateY(-2px) rotate(45deg)}
|
|
845
|
+
.dpm-usage {border-top:var(--dpm-divider)}
|
|
846
|
+
.dpm-usage > summary {min-height:36px;padding-block:6px;font-size:13px;font-weight:500}
|
|
847
|
+
.dpm-usage-count {margin-inline-start:auto;color:var(--dpm-muted);font-size:12px;font-weight:400;text-align:end}
|
|
848
|
+
.dpm-usage-fields {padding:0 0 15px 14px;gap:5px 10px;font-size:13px}
|
|
849
|
+
.dpm-row-detail > :is(p,strong,blockquote) {display:block;margin-block:10px}
|
|
850
|
+
.dpm-row-detail .dpm-editor {margin:0;padding:14px 0;background:transparent}
|
|
851
|
+
.dpm-row-detail .dpm-editor .dpm-actions, .dpm-row-confirm .dpm-actions {justify-content:flex-end}
|
|
852
|
+
.dpm-row-confirm {display:flex;align-items:center;flex-wrap:wrap;gap:8px 12px;
|
|
853
|
+
margin-block:12px;padding:10px;border:var(--dpm-divider);border-radius:var(--dpm-radius-sm);background:var(--dpm-soft)}
|
|
854
|
+
.dpm-row-confirm p {flex:1 1 14rem}
|
|
855
|
+
.dpm-row-confirm .dpm-actions {margin-inline-start:auto}
|
|
856
|
+
.dpm-row-confirm .dpm-danger {background:color-mix(in srgb,var(--dpm-danger) 9%,var(--dpm-surface))}
|
|
857
|
+
.dpm-actions {display:flex;flex-wrap:wrap;align-items:center;gap:4px}
|
|
858
|
+
.dpm-manager .dpm-tool {
|
|
859
|
+
min-height:30px;padding:4px 6px;background:transparent;color:var(--dsw-alias-label-secondary, var(--dpm-muted));
|
|
860
|
+
font-size:12px;white-space:nowrap;
|
|
861
|
+
}
|
|
862
|
+
.dpm-manager .dpm-row-menu-trigger {flex:none;width:32px;min-height:32px;padding:0}
|
|
863
|
+
.dpm-manager .dpm-row-menu-trigger[aria-expanded=true] {color:var(--dpm-ink);background:var(--dpm-soft)}
|
|
864
|
+
.dpm-row-menu {
|
|
865
|
+
position:fixed;inset:auto;margin:0;min-width:min(10rem, calc(100vw - 16px));max-width:calc(100vw - 16px);
|
|
866
|
+
max-height:min(22rem, 65vh);overflow:auto;padding:4px;border:var(--dpm-divider);border-radius:var(--dpm-radius);
|
|
867
|
+
background:var(--dpm-surface);color:var(--dpm-ink);box-shadow:0 6px 20px rgb(0 0 0 / .12);
|
|
868
|
+
}
|
|
869
|
+
@supports (position-area:block-end span-inline-start) {
|
|
870
|
+
.dpm-row-menu {position-area:block-end span-inline-start;justify-self:end;margin-block:4px;
|
|
871
|
+
max-block-size:min(22rem, 65vh, calc(100% - 8px));position-try-order:most-block-size;
|
|
872
|
+
position-try-fallbacks:flip-block,flip-inline,flip-block flip-inline}
|
|
873
|
+
}
|
|
874
|
+
.dpm-manager .dpm-row-menu button {
|
|
875
|
+
display:flex;width:100%;justify-content:flex-start;padding:5px 10px;border-radius:5px;background:transparent;
|
|
876
|
+
text-align:start;font-weight:400;
|
|
877
|
+
}
|
|
878
|
+
.dpm-row-menu button:focus-visible {outline-offset:-2px;background:var(--dpm-soft)}
|
|
879
|
+
.dpm-row-menu hr {margin:3px 4px;border:0;border-block-start:var(--dpm-divider)}
|
|
880
|
+
.dpm-row-menu button[data-destructive] {color:var(--dpm-danger)}
|
|
881
|
+
.dpm-extra, .dpm-editor {
|
|
882
|
+
margin-top:10px;padding:12px;border-radius:var(--dpm-radius-sm);background:var(--dpm-soft);font-size:13px;
|
|
883
|
+
}
|
|
884
|
+
.dpm-extra p+p, .dpm-extra .dpm-actions, .dpm-extra .dpm-meta {margin-top:6px}
|
|
885
|
+
.dpm-extra blockquote {margin:8px 0;padding-inline:12px;border-inline-start:2px solid var(--dpm-muted);white-space:pre-wrap;overflow-wrap:anywhere}
|
|
886
|
+
.dpm-extra code {font-size:12px;overflow-wrap:anywhere}
|
|
887
|
+
.dpm-editor label {display:block;margin-bottom:8px}
|
|
888
|
+
.dpm-manager textarea {display:block;width:100%;resize:vertical;min-height:60px;margin-top:4px}
|
|
889
|
+
.dpm-manager fieldset {min-inline-size:0}
|
|
890
|
+
.dpm-manager [data-memory-card] {display:grid;gap:8px;font-size:13px;line-height:20px;overflow-wrap:anywhere}
|
|
891
|
+
.dpm-review-item, .dpm-review-fields {display:grid;gap:4px;min-width:0}
|
|
892
|
+
.dpm-review-item + .dpm-review-item {border-block-start:var(--dpm-divider);padding-top:10px}
|
|
893
|
+
.dpm-review-title {font-size:15px;font-weight:500;line-height:22px;white-space:pre-wrap}
|
|
894
|
+
.dpm-review-title code {font:.9em ui-monospace,monospace;padding:1px 3px;border-radius:3px;background:var(--dpm-soft)}
|
|
895
|
+
.dpm-review-note, .dpm-review-batch {color:var(--dsw-alias-label-secondary,var(--dpm-muted))}
|
|
896
|
+
.dpm-review-conditions {display:grid;grid-template-columns:fit-content(9em) minmax(0,1fr);gap:2px 8px;margin:2px 0}
|
|
897
|
+
.dpm-review-conditions dt {color:var(--dpm-muted)}
|
|
898
|
+
.dpm-review-conditions dd {margin:0}
|
|
899
|
+
.dpm-review-fields {border:0;margin:0;padding:0}
|
|
900
|
+
.dpm-review-check {display:flex;align-items:baseline;gap:8px}
|
|
901
|
+
.dpm-review-check input {flex:none;align-self:flex-start;margin:4px 0 0}
|
|
902
|
+
.dpm-review-tools {display:flex;flex-wrap:wrap;align-items:baseline;gap:0 12px}
|
|
903
|
+
.dpm-review-tools > button.dpm-tool, .dpm-review-source > summary {
|
|
904
|
+
min-height:26px;padding:2px 0;font-size:12px;color:var(--dsw-alias-label-secondary,var(--dpm-muted));
|
|
905
|
+
}
|
|
906
|
+
.dpm-review-source[open] {flex-basis:100%}
|
|
907
|
+
.dpm-review-source > summary {width:fit-content}
|
|
908
|
+
.dpm-review-evidence, .dpm-review-editor {margin-block:4px;padding:10px 12px;border-radius:var(--dpm-radius-sm);background:var(--dpm-soft)}
|
|
909
|
+
.dpm-review-evidence blockquote {white-space:pre-wrap;margin:6px 0;padding-inline-start:10px;border-inline-start:2px solid var(--dpm-line)}
|
|
910
|
+
.dpm-review-editor summary {padding-block:4px}
|
|
911
|
+
.dpm-review-actions {gap:8px}
|
|
912
|
+
.dpm-review-actions button {min-width:4em}
|
|
913
|
+
.dpm-review-fields > label, .dpm-review-editor label {min-width:0}
|
|
914
|
+
.dpm-manager [data-memory-card] :is(input:not([type=checkbox]),select) {width:100%}
|
|
915
|
+
.dpm-manager [data-memory-card] input[type=checkbox] {accent-color:var(--dpm-primary)}
|
|
916
|
+
.dpm-mark {padding:0 1px;border-radius:2px;background:var(--dpm-hover);color:inherit;font-weight:600}
|
|
917
|
+
|
|
918
|
+
.dpm-empty {
|
|
919
|
+
display:grid;justify-items:center;align-content:center;gap:6px;min-height:160px;padding:24px 8px;text-align:center;
|
|
920
|
+
}
|
|
921
|
+
.dpm-empty-icon {
|
|
922
|
+
display:grid;place-items:center;width:36px;height:36px;margin-bottom:4px;border-radius:var(--dpm-radius);
|
|
923
|
+
background:var(--dpm-soft);color:var(--dpm-muted);
|
|
924
|
+
}
|
|
925
|
+
.dpm-empty-icon .dpm-icon {font-size:18px}
|
|
926
|
+
.dpm-empty-title {font-size:14px;line-height:22px;font-weight:500}
|
|
927
|
+
.dpm-empty-copy {max-width:34rem;color:var(--dpm-muted);font-size:12px;line-height:18px}
|
|
928
|
+
.dpm-empty-action {margin-top:6px}
|
|
929
|
+
.dpm-loading {display:flex;align-items:center;gap:8px;padding-block:18px;color:var(--dpm-muted);font-size:13px}
|
|
930
|
+
.dpm-spinner {
|
|
931
|
+
width:12px;height:12px;border:1.5px solid var(--dpm-line);border-top-color:var(--dpm-primary);
|
|
932
|
+
border-radius:50%;animation:dpm-spin .8s linear infinite;
|
|
933
|
+
}
|
|
934
|
+
@keyframes dpm-spin {to{transform:rotate(360deg)}}
|
|
935
|
+
@media (prefers-reduced-motion:reduce) {.dpm-spinner {animation:none}}
|
|
936
|
+
.dpm-toast {
|
|
937
|
+
position:sticky;bottom:12px;width:fit-content;max-width:100%;margin:8px auto 0;padding:6px 12px;
|
|
938
|
+
border-radius:var(--dpm-radius-sm);background:var(--dpm-primary);color:var(--dpm-on-primary);
|
|
939
|
+
overflow-wrap:anywhere;font-size:13px;line-height:20px;pointer-events:none;
|
|
940
|
+
}
|
|
941
|
+
@media (hover:hover) {
|
|
942
|
+
.dpm-manager button:enabled:hover:where(:not(.dpm-row-toggle,.dpm-scope-select > button,.dpm-source-link)), .dpm-manager summary:hover {background:var(--dpm-hover)}
|
|
943
|
+
.dpm-records-toolbar .dpm-picker:hover {--dpm-picker-ink:var(--dpm-ink)}
|
|
944
|
+
.dpm-row-toggle:hover:not([aria-disabled=true])::before {color:var(--dpm-ink)}
|
|
945
|
+
.dpm-manager :is(.dpm-primary,[data-memory-card] button[value=accept]):enabled:hover {background:var(--dpm-primary);opacity:.88}
|
|
946
|
+
}
|
|
947
|
+
.dpm-icon{display:inline-grid;position:relative;width:1em;height:1em;flex:none;place-items:center;font-size:16px;line-height:1}
|
|
948
|
+
.dpm-icon::before,.dpm-icon::after{position:absolute;box-sizing:border-box}
|
|
949
|
+
.dpm-icon-all::before{content:"";inset:2px 1px;border:1.5px solid;border-radius:2px;background:linear-gradient(currentColor,currentColor) center/100% 1.5px no-repeat}
|
|
950
|
+
.dpm-icon-global::before,.dpm-icon-global::after{content:"";border:1.5px solid;border-radius:50%}
|
|
951
|
+
.dpm-icon-global::before{inset:1px;background:linear-gradient(currentColor,currentColor) center/100% 1px no-repeat}
|
|
952
|
+
.dpm-icon-global::after{inset:1px 30%}
|
|
953
|
+
.dpm-icon-project::before{content:"";inset:27% 1px 7%;border:1.5px solid;border-radius:2px 3px 3px 3px}
|
|
954
|
+
.dpm-icon-project::after{content:"";inset:12% 51% 72% 1px;border:1.5px solid;border-bottom:0;border-radius:2px 3px 0 0}
|
|
955
|
+
.dpm-icon-search::before{content:"";left:1px;top:1px;width:64%;height:64%;border:1.5px solid;border-radius:50%}
|
|
956
|
+
.dpm-icon-search::after{content:"";width:40%;bottom:22%;right:0;border-bottom:1.5px solid;transform:rotate(45deg)}
|
|
957
|
+
.dpm-icon-close::before,.dpm-icon-close::after{content:"";width:78%;border-top:1.5px solid;transform:rotate(45deg)}
|
|
958
|
+
.dpm-icon-close::after{transform:rotate(-45deg)}
|
|
959
|
+
.dpm-icon-more::before{content:"";width:3px;height:3px;background:currentColor;border-radius:50%;box-shadow:-5px 0,5px 0}
|
|
960
|
+
@container (max-width:380px) {
|
|
961
|
+
.dpm-setting-row {gap:10px}
|
|
962
|
+
.dpm-memory-head {gap:6px}
|
|
963
|
+
.dpm-detail-fields,.dpm-usage-fields {grid-template-columns:minmax(54px,max-content) minmax(0,1fr);column-gap:7px}
|
|
964
|
+
.dpm-row-detail :is(.dpm-detail-fields,.dpm-usage-fields) > dt {max-inline-size:6em}
|
|
965
|
+
.dpm-source-line {column-gap:10px}
|
|
966
|
+
}
|
|
967
|
+
@container (max-width:260px) {
|
|
968
|
+
.dpm-setting-row:has(select) {align-items:stretch;flex-direction:column;gap:6px}
|
|
969
|
+
.dpm-setting-row .dpm-picker {max-width:100%;align-self:flex-start}
|
|
970
|
+
}
|
|
971
|
+
@media (forced-colors:active) {
|
|
972
|
+
.dpm-manager .dpm-switch, .dpm-manager .dpm-switch:disabled {appearance:auto;opacity:1}
|
|
973
|
+
.dpm-switch-track {display:none}
|
|
974
|
+
.dpm-manager .dpm-picker select, .dpm-manager .dpm-picker select.dpm-scope-select {appearance:auto}
|
|
975
|
+
.dpm-picker::after, .dpm-picker > .dpm-icon {display:none}
|
|
976
|
+
.dpm-manager .dpm-picker:has(> .dpm-icon) select {padding-inline:8px}
|
|
977
|
+
.dpm-scope-select::picker(select) {appearance:auto}
|
|
978
|
+
.dpm-toast {background:Canvas;color:CanvasText;border:1px solid}
|
|
979
|
+
}
|
|
980
|
+
`
|
|
981
|
+
const evidenceLabels = {
|
|
982
|
+
verified_user_quote: 'source.verified',
|
|
983
|
+
retained_quote: 'source.retained',
|
|
984
|
+
confirmed_wording: 'source.confirmed',
|
|
985
|
+
tool_result: 'source.toolEvidence',
|
|
986
|
+
manual: 'source.manual',
|
|
987
|
+
edited: 'source.edited',
|
|
988
|
+
redacted: 'source.redacted',
|
|
989
|
+
receipt: 'source.receipt',
|
|
990
|
+
}
|
|
991
|
+
const kindLabels = {
|
|
992
|
+
preference: 'kind.preference',
|
|
993
|
+
rule: 'kind.rule',
|
|
994
|
+
fact: 'kind.fact',
|
|
995
|
+
episode: 'kind.episode',
|
|
996
|
+
reference: 'kind.reference',
|
|
997
|
+
runbook: 'kind.runbook',
|
|
998
|
+
guard: 'kind.guard',
|
|
999
|
+
}
|
|
1000
|
+
const proofLabels = {
|
|
1001
|
+
anchored: 'proof.anchored',
|
|
1002
|
+
unverified: 'proof.unverified',
|
|
1003
|
+
pointer: 'proof.pointer',
|
|
1004
|
+
observed_success: 'proof.success',
|
|
1005
|
+
user_reported: 'proof.reported',
|
|
1006
|
+
user_confirmed: 'proof.confirmed',
|
|
1007
|
+
}
|
|
1008
|
+
function uiError(error) {
|
|
1009
|
+
const code = error.code && error.code !== 'review_failed' ? error.code : error.message
|
|
1010
|
+
for (const key of ['error.' + code, 'reason.' + code]) {
|
|
1011
|
+
if (Object.hasOwn(dictionaries.en, key)) return t(key)
|
|
1012
|
+
}
|
|
1013
|
+
return t('error.failed', { code })
|
|
1014
|
+
}
|
|
1015
|
+
function KnowledgeDetail({ knowledge }) {
|
|
1016
|
+
if (!knowledge) return null
|
|
1017
|
+
const stages = { locate: t('stage.locate'), diagnose: t('stage.diagnose'), repair: t('stage.repair'), verify: t('stage.verify'), basis: t('stage.basis') }
|
|
1018
|
+
return h(
|
|
1019
|
+
React.Fragment,
|
|
1020
|
+
null,
|
|
1021
|
+
knowledge.verification && h('p', null, proofLabels[knowledge.verification] ? t(proofLabels[knowledge.verification]) : knowledge.verification),
|
|
1022
|
+
knowledge.source && h('p', null, t('knowledge.source'), knowledge.source),
|
|
1023
|
+
knowledge.anchors?.length
|
|
1024
|
+
? h(
|
|
1025
|
+
'ul',
|
|
1026
|
+
{ 'aria-label': t('knowledge.anchors') },
|
|
1027
|
+
knowledge.anchors.map((a) =>
|
|
1028
|
+
h(
|
|
1029
|
+
'li',
|
|
1030
|
+
{ key: a.path + ':' + (a.symbol || '') },
|
|
1031
|
+
h('code', null, a.path),
|
|
1032
|
+
a.symbol ? ' · ' + a.symbol : '',
|
|
1033
|
+
a.digest &&
|
|
1034
|
+
h('span', { className: 'dpm-muted', title: a.digest }, ' · ', a.digest.slice(0, 12)),
|
|
1035
|
+
),
|
|
1036
|
+
),
|
|
1037
|
+
)
|
|
1038
|
+
: null,
|
|
1039
|
+
knowledge.match &&
|
|
1040
|
+
h('p', null, t('knowledge.command'), h('code', null, knowledge.match.command), ' · ', knowledge.match.workdir),
|
|
1041
|
+
knowledge.steps &&
|
|
1042
|
+
h(
|
|
1043
|
+
'dl',
|
|
1044
|
+
null,
|
|
1045
|
+
Object.entries(stages)
|
|
1046
|
+
.filter(([key]) => knowledge.steps[key])
|
|
1047
|
+
.map(([key, name]) =>
|
|
1048
|
+
h(React.Fragment, { key }, h('dt', null, name), h('dd', null, knowledge.steps[key])),
|
|
1049
|
+
),
|
|
1050
|
+
),
|
|
1051
|
+
knowledge.proof &&
|
|
1052
|
+
h('p', null, t('knowledge.success'), h('code', null, knowledge.proof.command), ' · ', knowledge.proof.workdir),
|
|
1053
|
+
)
|
|
1054
|
+
}
|
|
1055
|
+
function sourceLinkState(id) {
|
|
1056
|
+
const sessions = ctx.sessions.list.getSnapshot()
|
|
1057
|
+
const workspaces = ctx.workspaces.list.getSnapshot()
|
|
1058
|
+
if (workspaces.state === 'error') return 'unavailable'
|
|
1059
|
+
if (sessions.phase === 'pending' || workspaces.phase === 'pending') return 'loading'
|
|
1060
|
+
if (workspaces.archivedSessionIds.includes(id)) return 'archived'
|
|
1061
|
+
return sessions.ids.includes(id) ? 'available' : 'unavailable'
|
|
1062
|
+
}
|
|
1063
|
+
function subscribeSourceLinks(listener) {
|
|
1064
|
+
const unsubscribeSessions = ctx.sessions.list.subscribe(listener)
|
|
1065
|
+
const unsubscribeWorkspaces = ctx.workspaces.list.subscribe(listener)
|
|
1066
|
+
return () => { unsubscribeSessions(); unsubscribeWorkspaces() }
|
|
1067
|
+
}
|
|
1068
|
+
function SourceConversation({ source, ctl, id, rev, headRev = rev, profileQuote, onRead }) {
|
|
1069
|
+
const close = React.useContext(CloseSettings)
|
|
1070
|
+
const sessionId = source.session_id
|
|
1071
|
+
const turnLabel = React.useId()
|
|
1072
|
+
const availability = useSyncExternalStore(subscribeSourceLinks, () => sourceLinkState(sessionId))
|
|
1073
|
+
const pending = React.useRef(null)
|
|
1074
|
+
const [opening, setOpening] = useState(false)
|
|
1075
|
+
const [error, setError] = useState(false)
|
|
1076
|
+
useEffect(() => () => pending.current?.abort(), [ctl, id, rev, headRev, sessionId, source.seq, source.turn, profileQuote])
|
|
1077
|
+
async function open(event) {
|
|
1078
|
+
if (pending.current || !close || sourceLinkState(sessionId) !== 'available') return
|
|
1079
|
+
const request = new AbortController()
|
|
1080
|
+
const trigger = event.currentTarget
|
|
1081
|
+
pending.current = request
|
|
1082
|
+
setError(false)
|
|
1083
|
+
setOpening(true)
|
|
1084
|
+
try {
|
|
1085
|
+
const args = rev === headRev ? { id, rev } : { id, rev: headRev, sourceRev: rev }
|
|
1086
|
+
const { result } = await ctl.call('manage', { op: 'source', args }, request.signal)
|
|
1087
|
+
if (request.signal.aborted) return
|
|
1088
|
+
onRead(result, document.activeElement === trigger)
|
|
1089
|
+
if (result?.evidence !== 'verified_user_quote' || result.id !== id || result.rev !== rev ||
|
|
1090
|
+
result.source?.session_id !== sessionId || result.source.seq !== source.seq || result.source.turn !== source.turn ||
|
|
1091
|
+
(profileQuote !== undefined && result.quote !== profileQuote) ||
|
|
1092
|
+
sourceLinkState(sessionId) !== 'available') return
|
|
1093
|
+
ctx.uiWorkspace.openSession(sessionId)
|
|
1094
|
+
close()
|
|
1095
|
+
} catch (err) {
|
|
1096
|
+
if (!request.signal.aborted) {
|
|
1097
|
+
if (profileQuote !== undefined && ['unavailable', 'conflict', 'not_found'].includes(err.code))
|
|
1098
|
+
onRead({ status: err.code }, document.activeElement === trigger)
|
|
1099
|
+
else setError(true)
|
|
1100
|
+
}
|
|
1101
|
+
} finally {
|
|
1102
|
+
pending.current = null
|
|
1103
|
+
if (!request.signal.aborted) setOpening(false)
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
const available = availability === 'available' && typeof close === 'function'
|
|
1107
|
+
if (profileQuote !== undefined && !available) return null
|
|
1108
|
+
return h(React.Fragment, null,
|
|
1109
|
+
h('span', { className: 'dpm-source-origin' },
|
|
1110
|
+
available ? h('button', { type: 'button', className: 'dpm-source-link', onClick: open,
|
|
1111
|
+
'aria-describedby': source.turn == null ? undefined : turnLabel,
|
|
1112
|
+
'aria-busy': opening || undefined, 'aria-disabled': opening || undefined }, t('source.openConversation')) :
|
|
1113
|
+
h('span', { role: 'status' }, t(availability === 'archived' ? 'source.conversationArchived'
|
|
1114
|
+
: availability === 'loading' ? 'source.loading' : 'source.conversationUnavailable')),
|
|
1115
|
+
source.turn != null && h(React.Fragment, null, h('span', { 'aria-hidden': true }, '·'),
|
|
1116
|
+
h('span', { id: turnLabel }, t('turn', { number: source.turn })))),
|
|
1117
|
+
error && available && h('p', { role: 'alert' }, t('source.openFailed')))
|
|
1118
|
+
}
|
|
1119
|
+
function detailField(label, value) {
|
|
1120
|
+
return h(React.Fragment, null, h('dt', null, t(label)), h('dd', null, value))
|
|
1121
|
+
}
|
|
1122
|
+
function ProfileQuote({ data, ctl, headRev = data.rev, onRead }) {
|
|
1123
|
+
return h(React.Fragment, null,
|
|
1124
|
+
data.evidence === 'verified_user_quote' && data.source?.session_id &&
|
|
1125
|
+
h(SourceConversation, { source: data.source, id: data.id, rev: data.rev, headRev, ctl,
|
|
1126
|
+
profileQuote: data.quote, onRead }),
|
|
1127
|
+
h('blockquote', { className: 'dpm-profile-quote' }, data.quote))
|
|
1128
|
+
}
|
|
1129
|
+
function RuleDetail({ data, ctl, onRead, sourceError, sourceLoading }) {
|
|
1130
|
+
const source = data.source
|
|
1131
|
+
const verified = data.evidence === 'verified_user_quote'
|
|
1132
|
+
const duplicate = verified && data.quote && data.quote.trim() === data.action?.trim()
|
|
1133
|
+
const retainedProject = data.scope === 'project' && data.evidence === 'retained_quote'
|
|
1134
|
+
const evidenceLabel = evidenceLabels[data.evidence] || (data.quote ? 'source.excerpt' : undefined)
|
|
1135
|
+
let profileEvidence
|
|
1136
|
+
if (data.scope === 'profile' && data.quote && (verified || data.evidence === 'retained_quote')) {
|
|
1137
|
+
profileEvidence = h(ProfileQuote, { data, ctl, onRead })
|
|
1138
|
+
} else if (data.scope === 'profile' && data.evidence === 'receipt') {
|
|
1139
|
+
profileEvidence = data.manualEdit
|
|
1140
|
+
? h(React.Fragment, null, h('span', null, t('source.manualEdit')), ' · ',
|
|
1141
|
+
h('span', { className: 'dpm-meta' }, t('source.version', { rev: data.rev })))
|
|
1142
|
+
: h('span', { className: 'dpm-muted' }, t('source.none'))
|
|
1143
|
+
}
|
|
1144
|
+
return h(React.Fragment, null,
|
|
1145
|
+
h('dl', { className: 'dpm-detail-fields' },
|
|
1146
|
+
data.when && detailField('detail.when', data.when),
|
|
1147
|
+
data.paths?.length > 0 && detailField('detail.paths',
|
|
1148
|
+
data.paths.map(path => h('div', { key: path }, h('code', null, path)))),
|
|
1149
|
+
h('dt', null, t('source')), h('dd', { className: 'dpm-source' }, sourceError ?
|
|
1150
|
+
h('p', { role: 'alert' }, sourceError) : sourceLoading ?
|
|
1151
|
+
h('p', { className: 'dpm-muted', role: 'status' }, t('source.loading')) : h(React.Fragment, null,
|
|
1152
|
+
profileEvidence || h(React.Fragment, null,
|
|
1153
|
+
verified && h('div', { className: 'dpm-source-line' },
|
|
1154
|
+
source?.session_id && h(SourceConversation, { source, ctl, id: data.id, rev: data.rev, onRead }),
|
|
1155
|
+
duplicate && h('details', { className: 'dpm-quote-disclosure', key: data.rev },
|
|
1156
|
+
h('summary', null, t('source.verifiedShort')), h('blockquote', null, data.quote))),
|
|
1157
|
+
!duplicate && evidenceLabel && h('span', { className: 'dpm-evidence-label' }, t(evidenceLabel))),
|
|
1158
|
+
data.fileImport && h('p', null, t('source.fileImport', data.fileImport)),
|
|
1159
|
+
data.toolResult && h('p', null, t('source.toolResult', data.toolResult)),
|
|
1160
|
+
!profileEvidence && !duplicate && data.quote && h('blockquote', null, data.quote),
|
|
1161
|
+
!profileEvidence && !data.quote && !data.toolResult && h('p', { className: 'dpm-muted' },
|
|
1162
|
+
t(data.hasRetainedQuote ? 'source.historical' : 'source.none')),
|
|
1163
|
+
data.formSelection && h('p', null, t('source.formSelection', data.formSelection)),
|
|
1164
|
+
retainedProject && h('p', { className: 'dpm-meta', role: 'status' }, t('source.conversationUnavailable')),
|
|
1165
|
+
!profileEvidence && !verified && !retainedProject && source?.session_id && h('p', { className: 'dpm-meta' }, t('session', { id: source.session_id }),
|
|
1166
|
+
source.turn == null ? '' : ' · ' + t('turn', { number: source.turn })),
|
|
1167
|
+
data.scopeClarification && h('p', { className: 'dpm-meta' },
|
|
1168
|
+
t('source.scopeClarification', { turn: data.scopeClarification.turnId })))),
|
|
1169
|
+
data.exceptions && detailField('review.exceptions', data.exceptions),
|
|
1170
|
+
data.localException && detailField('detail.localException', [data.localException.environment, data.localException.scope].join(' · '))),
|
|
1171
|
+
h(KnowledgeDetail, { knowledge: data.knowledge }))
|
|
1172
|
+
}
|
|
1173
|
+
function HistoricalQuote({ ctl, id, headRev, sourceRev, focusTarget }) {
|
|
1174
|
+
const [source, setSource] = useState(null)
|
|
1175
|
+
useEffect(() => {
|
|
1176
|
+
const request = new AbortController()
|
|
1177
|
+
ctl.call('manage', { op: 'source', args: { id, rev: headRev, sourceRev } }, request.signal)
|
|
1178
|
+
.then(({ result }) => { if (!request.signal.aborted) setSource(result) })
|
|
1179
|
+
.catch(err => { if (!request.signal.aborted) setSource({ status: err.code || err.message }) })
|
|
1180
|
+
return () => request.abort()
|
|
1181
|
+
}, [ctl, id, headRev, sourceRev])
|
|
1182
|
+
if (!source) return h('span', { className: 'dpm-muted', role: 'status' }, t('source.loading'))
|
|
1183
|
+
if (source.id !== id || source.rev !== sourceRev || source.scope !== 'profile' || !source.quote ||
|
|
1184
|
+
!['verified_user_quote', 'retained_quote'].includes(source.evidence))
|
|
1185
|
+
return h('span', { role: 'status', className: 'dpm-muted' }, source.status && source.status !== 'not_found'
|
|
1186
|
+
? uiError(Error(source.status)) : t('source.none'))
|
|
1187
|
+
function update(result, linkHadFocus) {
|
|
1188
|
+
if (linkHadFocus && result?.evidence !== 'verified_user_quote') focusTarget.current?.focus({ preventScroll: true })
|
|
1189
|
+
setSource(result || { status: 'not_found' })
|
|
1190
|
+
}
|
|
1191
|
+
return h(ProfileQuote, { data: source, headRev, ctl, onRead: update })
|
|
1192
|
+
}
|
|
1193
|
+
function VersionSource({ ctl, rule, sourceRev, single, usageToggle }) {
|
|
1194
|
+
const [open, setOpen] = useState(false)
|
|
1195
|
+
const toggle = React.useRef(null)
|
|
1196
|
+
const quote = (single || open) && h(HistoricalQuote, { ctl, id: rule.id, headRev: rule.rev,
|
|
1197
|
+
sourceRev, focusTarget: single ? usageToggle : toggle })
|
|
1198
|
+
return h(React.Fragment, null, h('dt', null, t('source.versionQuote', { rev: sourceRev })),
|
|
1199
|
+
h('dd', { 'data-memory-source-rev': sourceRev }, single ? quote :
|
|
1200
|
+
h('details', { className: 'dpm-quote-disclosure', onToggle: event => setOpen(event.currentTarget.open) },
|
|
1201
|
+
h('summary', { ref: toggle }, t('viewSource')), quote)))
|
|
1202
|
+
}
|
|
1203
|
+
function UsageSummary({ rule, memoryEnabled, withheld, ctl, sourceRevisions }) {
|
|
1204
|
+
const [open, setOpen] = useState(false)
|
|
1205
|
+
const toggle = React.useRef(null)
|
|
1206
|
+
const usage = rule.usageSignals
|
|
1207
|
+
const count = usage?.delivered
|
|
1208
|
+
return h('details', { className: 'dpm-usage', 'data-memory-usage': true,
|
|
1209
|
+
onToggle: event => { if (event.target === event.currentTarget) setOpen(event.currentTarget.open) } },
|
|
1210
|
+
h('summary', { ref: toggle }, h('span', null, t('signals.details')),
|
|
1211
|
+
count != null && h('span', { className: 'dpm-usage-count' }, count === 0 ? t('signals.empty') :
|
|
1212
|
+
t(count === 1 ? 'signals.delivered.one' : 'signals.delivered.many', { count }))),
|
|
1213
|
+
h('dl', { className: 'dpm-usage-fields' },
|
|
1214
|
+
!withheld && rule.delivered !== undefined && detailField('signals.session', t(rule.delivered ? 'delivered' : 'undelivered')),
|
|
1215
|
+
usage?.opened != null && detailField('signals.opened',
|
|
1216
|
+
t(usage.opened === 1 ? 'signals.count.one' : 'signals.count.many', { count: usage.opened })),
|
|
1217
|
+
usage?.lastDelivery != null && detailField('signals.last', new Date(usage.lastDelivery).toLocaleDateString(t('language'))),
|
|
1218
|
+
!withheld && memoryEnabled && rule.usage === 'proactive' && detailField('detail.index', t(rule.indexed ? 'indexed' : 'overBudget')),
|
|
1219
|
+
!withheld && rule.subject && detailField('detail.subject', subjectLabel(rule.subject)),
|
|
1220
|
+
!withheld && rule.topic && detailField('detail.topic', topicLabel(rule.topic)),
|
|
1221
|
+
detailField('turnReceipts.revision', h('code', null, rule.id, '@', String(rule.rev))),
|
|
1222
|
+
open && sourceRevisions?.map(sourceRev => h(VersionSource, { key: rule.rev + '/' + sourceRev,
|
|
1223
|
+
ctl, rule, sourceRev, single: sourceRevisions.length === 1, usageToggle: toggle }))))
|
|
1224
|
+
}
|
|
1225
|
+
function RowMenu({ disabled, actions, trigger }) {
|
|
1226
|
+
const id = React.useId()
|
|
1227
|
+
const menu = React.useRef(null)
|
|
1228
|
+
const openAtEnd = React.useRef(false)
|
|
1229
|
+
const [open, setOpen] = useState(false)
|
|
1230
|
+
const items = () => Array.from(menu.current.querySelectorAll('[role=menuitem]:enabled'))
|
|
1231
|
+
useEffect(() => {
|
|
1232
|
+
const list = menu.current
|
|
1233
|
+
function opening(event) {
|
|
1234
|
+
if (event.newState !== 'open') return
|
|
1235
|
+
// The browser focuses this item while opening, before the deferred toggle event.
|
|
1236
|
+
list.querySelector('[autofocus]')?.removeAttribute('autofocus')
|
|
1237
|
+
items().at(openAtEnd.current ? -1 : 0)?.setAttribute('autofocus', '')
|
|
1238
|
+
openAtEnd.current = false
|
|
1239
|
+
}
|
|
1240
|
+
function toggled() {
|
|
1241
|
+
const showing = list.matches(':popover-open')
|
|
1242
|
+
setOpen(showing)
|
|
1243
|
+
if (!showing) return
|
|
1244
|
+
const rect = trigger.current.getBoundingClientRect()
|
|
1245
|
+
const below = innerHeight - rect.bottom - 8
|
|
1246
|
+
if (CSS.supports('position-area:block-end span-inline-start')) {
|
|
1247
|
+
list.style.positionTryOrder = below >= list.scrollHeight + 2 ? 'normal' : 'most-block-size'
|
|
1248
|
+
} else {
|
|
1249
|
+
list.style.maxHeight = ''
|
|
1250
|
+
const above = rect.top - 8
|
|
1251
|
+
const openAbove = below < list.offsetHeight && above > below
|
|
1252
|
+
list.style.maxHeight = Math.max(1, Math.min(list.offsetHeight, openAbove ? above : below)) + 'px'
|
|
1253
|
+
list.style.left = Math.max(4, Math.min(innerWidth - list.offsetWidth - 4, rect.right - list.offsetWidth)) + 'px'
|
|
1254
|
+
list.style.top = (openAbove ? rect.top - list.offsetHeight - 4 : rect.bottom + 4) + 'px'
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
list.addEventListener('beforetoggle', opening)
|
|
1258
|
+
list.addEventListener('toggle', toggled)
|
|
1259
|
+
return () => {
|
|
1260
|
+
list.removeEventListener('beforetoggle', opening)
|
|
1261
|
+
list.removeEventListener('toggle', toggled)
|
|
1262
|
+
}
|
|
1263
|
+
}, [])
|
|
1264
|
+
function close() {
|
|
1265
|
+
menu.current.hidePopover()
|
|
1266
|
+
trigger.current.focus({ preventScroll: true })
|
|
1267
|
+
}
|
|
1268
|
+
function navigate(event) {
|
|
1269
|
+
if (event.key === 'Tab' || event.key === 'Escape') {
|
|
1270
|
+
close()
|
|
1271
|
+
if (event.key === 'Tab') return
|
|
1272
|
+
} else {
|
|
1273
|
+
const options = items()
|
|
1274
|
+
const current = options.indexOf(document.activeElement)
|
|
1275
|
+
let next
|
|
1276
|
+
switch (event.key) {
|
|
1277
|
+
case 'ArrowDown': next = (current + 1) % options.length; break
|
|
1278
|
+
case 'ArrowUp': next = (current - 1 + options.length) % options.length; break
|
|
1279
|
+
case 'Home': next = 0; break
|
|
1280
|
+
case 'End': next = options.length - 1; break
|
|
1281
|
+
default: return
|
|
1282
|
+
}
|
|
1283
|
+
options[next]?.focus()
|
|
1284
|
+
}
|
|
1285
|
+
event.preventDefault()
|
|
1286
|
+
event.stopPropagation()
|
|
1287
|
+
}
|
|
1288
|
+
return h(React.Fragment, null,
|
|
1289
|
+
h('button', { type: 'button', ref: trigger, className: 'dpm-tool dpm-row-menu-trigger', disabled,
|
|
1290
|
+
popoverTarget: id, title: t('more'), 'aria-label': t('more'), 'aria-haspopup': 'menu', 'aria-controls': id,
|
|
1291
|
+
'aria-expanded': open, onKeyDown: event => {
|
|
1292
|
+
if (event.key === 'Escape' && menu.current.matches(':popover-open')) return navigate(event)
|
|
1293
|
+
if (event.key !== 'ArrowDown' && event.key !== 'ArrowUp') return
|
|
1294
|
+
event.preventDefault()
|
|
1295
|
+
openAtEnd.current = event.key === 'ArrowUp'
|
|
1296
|
+
if (!menu.current.matches(':popover-open')) trigger.current.click()
|
|
1297
|
+
} }, memoryIcon('more')),
|
|
1298
|
+
h('div', { id, ref: menu, role: 'menu', 'aria-label': t('more'), popover: 'auto', className: 'dpm-row-menu',
|
|
1299
|
+
onKeyDown: navigate }, actions.map(({ label, run, danger }, index) =>
|
|
1300
|
+
h(React.Fragment, { key: label },
|
|
1301
|
+
danger && index > 0 && !actions[index - 1].danger && h('hr', { role: 'separator' }),
|
|
1302
|
+
h('button', { type: 'button', role: 'menuitem', tabIndex: -1, 'data-destructive': danger || undefined, onClick: () => { close(); run() } }, label)))))
|
|
1303
|
+
}
|
|
1304
|
+
function ScopeLabel({ scope, projectName }) {
|
|
1305
|
+
const label = scope === 'profile' ? t('scope.rowGlobal')
|
|
1306
|
+
: projectName ? t('scope.rowProject', { name: projectName }) : t('scope.project')
|
|
1307
|
+
return h('span', { className: 'dpm-scope-label', 'data-memory-scope': scope, title: label }, label)
|
|
1308
|
+
}
|
|
1309
|
+
function ManageRow({ rule, scope, projectName, ctl, readOnly, perform, reload, announce, query, memoryEnabled, renewal, withheld = false }) {
|
|
1310
|
+
const [expanded, setExpanded] = useState(false)
|
|
1311
|
+
const [panel, setPanel] = useState(null)
|
|
1312
|
+
const [draft, setDraft] = useState('')
|
|
1313
|
+
const [error, setError] = useState('')
|
|
1314
|
+
const [busy, setBusy] = useState(false)
|
|
1315
|
+
const [loaded, setLoaded] = useState(null)
|
|
1316
|
+
const sourceRequest = React.useRef(null)
|
|
1317
|
+
const disclosure = React.useRef(null)
|
|
1318
|
+
const menuTrigger = React.useRef(null)
|
|
1319
|
+
const restoreMenuFocus = React.useRef(false)
|
|
1320
|
+
const openedForAction = React.useRef(false)
|
|
1321
|
+
const detailsId = React.useId()
|
|
1322
|
+
const source = expanded && loaded?.rule === rule && loaded.renewal === renewal ? loaded : null
|
|
1323
|
+
const stale = panel != null && panel.rev !== rule.rev
|
|
1324
|
+
useEffect(() => {
|
|
1325
|
+
// Withheld entries expose only the summary supplied by list/search for this scope.
|
|
1326
|
+
if (!expanded || withheld) return
|
|
1327
|
+
const abort = new AbortController()
|
|
1328
|
+
sourceRequest.current = abort
|
|
1329
|
+
ctl.call('manage', { op: 'source', args: { id: rule.id, rev: rule.rev } }, abort.signal)
|
|
1330
|
+
.then(({ result }) => {
|
|
1331
|
+
if (result?.status) throw Error(result.status)
|
|
1332
|
+
if (!abort.signal.aborted) setLoaded({ rule, renewal, result })
|
|
1333
|
+
})
|
|
1334
|
+
.catch(e => { if (!abort.signal.aborted) setLoaded({ rule, renewal, error: uiError(e) }) })
|
|
1335
|
+
return () => abort.abort()
|
|
1336
|
+
}, [ctl, rule, expanded, withheld, renewal])
|
|
1337
|
+
React.useLayoutEffect(() => {
|
|
1338
|
+
if (panel || !restoreMenuFocus.current) return
|
|
1339
|
+
const target = menuTrigger.current ?? disclosure.current
|
|
1340
|
+
target?.focus({ preventScroll: true })
|
|
1341
|
+
restoreMenuFocus.current = false
|
|
1342
|
+
}, [panel])
|
|
1343
|
+
function collapseRow() {
|
|
1344
|
+
sourceRequest.current?.abort()
|
|
1345
|
+
setLoaded(null)
|
|
1346
|
+
setExpanded(false)
|
|
1347
|
+
}
|
|
1348
|
+
function toggle() {
|
|
1349
|
+
if (busy) return
|
|
1350
|
+
setError('')
|
|
1351
|
+
if (expanded) {
|
|
1352
|
+
collapseRow()
|
|
1353
|
+
setPanel(null)
|
|
1354
|
+
} else setExpanded(true)
|
|
1355
|
+
}
|
|
1356
|
+
function updateSource(result, linkHadFocus) {
|
|
1357
|
+
if (result?.evidence !== 'verified_user_quote' && linkHadFocus) disclosure.current?.focus({ preventScroll: true })
|
|
1358
|
+
setLoaded(result?.id === rule.id && result.rev === rule.rev ? { rule, renewal, result } :
|
|
1359
|
+
{ rule, renewal, error: uiError(Error(result?.status || 'not_found')) })
|
|
1360
|
+
}
|
|
1361
|
+
function select(op) {
|
|
1362
|
+
if (op === 'revise') setDraft(rule.action)
|
|
1363
|
+
openedForAction.current = !expanded
|
|
1364
|
+
setExpanded(true)
|
|
1365
|
+
setError('')
|
|
1366
|
+
setPanel({ op, rev: rule.rev })
|
|
1367
|
+
}
|
|
1368
|
+
function cancel() {
|
|
1369
|
+
restoreMenuFocus.current = true
|
|
1370
|
+
if (openedForAction.current) collapseRow()
|
|
1371
|
+
setPanel(null)
|
|
1372
|
+
setError('')
|
|
1373
|
+
}
|
|
1374
|
+
async function action(op) {
|
|
1375
|
+
if (busy || readOnly || stale || (withheld && op !== 'forget')) return
|
|
1376
|
+
const button = disclosure.current
|
|
1377
|
+
const row = button.closest('li')
|
|
1378
|
+
const nextFocus = op === 'forget' ? row.nextElementSibling?.querySelector('.dpm-row-toggle')
|
|
1379
|
+
|| row.previousElementSibling?.querySelector('.dpm-row-toggle')
|
|
1380
|
+
|| row.closest('.dpm-pane')?.querySelector('input[type=search]') : button
|
|
1381
|
+
setBusy(true)
|
|
1382
|
+
setError('')
|
|
1383
|
+
try {
|
|
1384
|
+
const answer = await perform(op, { id: rule.id, rev: panel?.rev ?? rule.rev,
|
|
1385
|
+
...(op === 'revise' ? { action: draft.trim() } : {}),
|
|
1386
|
+
...(op === 'usage' ? { usage: rule.usage === 'proactive' ? 'on_demand' : 'proactive' } : {}) })
|
|
1387
|
+
if (row.contains(document.activeElement) || document.activeElement === document.body)
|
|
1388
|
+
nextFocus?.focus({ preventScroll: true })
|
|
1389
|
+
if (panel && openedForAction.current) collapseRow()
|
|
1390
|
+
setPanel(null)
|
|
1391
|
+
announce(answer?.status === 'pending' ? t('notice.pending') : t({
|
|
1392
|
+
revise: 'notice.revise', forget: 'notice.forget',
|
|
1393
|
+
usage: 'notice.usage',
|
|
1394
|
+
}[op]))
|
|
1395
|
+
reload()
|
|
1396
|
+
} catch (e) {
|
|
1397
|
+
setExpanded(true)
|
|
1398
|
+
setError(uiError(e))
|
|
1399
|
+
} finally {
|
|
1400
|
+
setBusy(false)
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
const onDemand = rule.usage !== 'proactive'
|
|
1404
|
+
const kind = kindLabels[rule.kind] ? t(kindLabels[rule.kind]) : rule.kind
|
|
1405
|
+
const showFactTopic = scope === 'profile' && rule.kind === 'fact' && Boolean(rule.topic)
|
|
1406
|
+
const labels = showFactTopic ? [subjectLabel(rule.subject), topicLabel(rule.topic)] : [kind]
|
|
1407
|
+
const title = rule.action || t(rule.scope === 'profile' ? 'withheld.profile' : 'withheld.project', { kind: kind || t('memory') })
|
|
1408
|
+
const usageLabel = onDemand ? (rule.kind === 'fact' ? '' : t('usage.onDemand')) : t('usage.proactive')
|
|
1409
|
+
const meta = withheld ? rule.reasonText || t('reason.unavailable') : [...labels, usageLabel,
|
|
1410
|
+
rule.pinned && !onDemand ? t('pinned') : ''].filter(Boolean).join(' · ')
|
|
1411
|
+
const actions = [
|
|
1412
|
+
!withheld && { label: t('edit'), run: () => select('revise') },
|
|
1413
|
+
!withheld && rule.canChangeUsage && { label: onDemand ? t('switchProactive') : t('switchOnDemand'), run: () => action('usage') },
|
|
1414
|
+
{ label: t('withdraw'), run: () => select('forget'), danger: true },
|
|
1415
|
+
].filter(Boolean)
|
|
1416
|
+
const editing = panel?.op === 'revise'
|
|
1417
|
+
return h('li', { className: 'dpm-row', [withheld ? 'data-invalid-memory' : 'data-memory-rule']: rule.id },
|
|
1418
|
+
h('div', { className: 'dpm-memory-head' },
|
|
1419
|
+
h('button', { ref: disclosure, type: 'button', className: 'dpm-row-toggle', onClick: toggle,
|
|
1420
|
+
'aria-label': title, 'aria-describedby': detailsId + '-meta',
|
|
1421
|
+
'aria-expanded': expanded, 'aria-controls': expanded ? detailsId : undefined, 'aria-disabled': busy || undefined },
|
|
1422
|
+
h('span', { className: 'dpm-row-copy' },
|
|
1423
|
+
h('span', { className: 'dpm-text' }, highlight(title, query)),
|
|
1424
|
+
h('span', { id: detailsId + '-meta', className: 'dpm-meta dpm-scope-meta' },
|
|
1425
|
+
h(ScopeLabel, { scope, projectName }), meta && ' · ', meta))),
|
|
1426
|
+
!readOnly && h(RowMenu, { disabled: busy || Boolean(panel), actions, trigger: menuTrigger })),
|
|
1427
|
+
expanded && h('div', { id: detailsId, className: 'dpm-row-detail',
|
|
1428
|
+
onKeyDown: event => {
|
|
1429
|
+
if (!panel || event.key !== 'Escape') return
|
|
1430
|
+
event.preventDefault()
|
|
1431
|
+
event.stopPropagation()
|
|
1432
|
+
if (!busy) cancel()
|
|
1433
|
+
} },
|
|
1434
|
+
editing ? h('form', { className: 'dpm-editor', onSubmit: e => {
|
|
1435
|
+
e.preventDefault()
|
|
1436
|
+
if (draft.trim() && draft.trim() !== rule.action) void action('revise')
|
|
1437
|
+
} },
|
|
1438
|
+
label(t('content'), h('textarea', { value: draft, required: true, maxLength: 4096,
|
|
1439
|
+
'aria-describedby': showFactTopic ? detailsId + '-meta' : undefined,
|
|
1440
|
+
autoFocus: true, readOnly: readOnly || busy, onChange: e => setDraft(e.target.value) })),
|
|
1441
|
+
h('div', { className: 'dpm-actions' },
|
|
1442
|
+
h('button', { type: 'button', onClick: cancel, disabled: busy }, t('cancel')),
|
|
1443
|
+
h('button', { type: 'submit', className: 'dpm-primary',
|
|
1444
|
+
disabled: busy || stale || readOnly || !draft.trim() || draft.trim() === rule.action }, t('saveEdit')))) :
|
|
1445
|
+
h(React.Fragment, null,
|
|
1446
|
+
panel?.op === 'forget' && h('div', { className: 'dpm-row-confirm', role: 'group', 'aria-describedby': detailsId + '-confirm' },
|
|
1447
|
+
h('p', { id: detailsId + '-confirm' }, t(rule.scope === 'profile' ? 'withdraw.global' : 'withdraw.project')),
|
|
1448
|
+
h('div', { className: 'dpm-actions' },
|
|
1449
|
+
h('button', { type: 'button', autoFocus: true, disabled: busy, onClick: cancel }, t('cancel')),
|
|
1450
|
+
h('button', { type: 'button', className: 'dpm-danger', disabled: readOnly || busy || stale,
|
|
1451
|
+
onClick: () => action('forget') }, t('withdraw.confirm')))),
|
|
1452
|
+
withheld ? h(React.Fragment, null,
|
|
1453
|
+
rule.quote && h(React.Fragment, null, h('strong', null, t('source.savedExcerpt')), h('blockquote', null, rule.quote)),
|
|
1454
|
+
rule.time != null && h('p', { className: 'dpm-muted' }, new Date(rule.time).toLocaleString(t('language')))) :
|
|
1455
|
+
h(RuleDetail, { data: { ...rule, ...source?.result }, ctl, onRead: updateSource,
|
|
1456
|
+
sourceError: source?.error, sourceLoading: !source }),
|
|
1457
|
+
h(UsageSummary, { rule, memoryEnabled, withheld, ctl,
|
|
1458
|
+
sourceRevisions: !withheld && scope === 'profile' ? source?.result?.sourceRevisions : undefined })),
|
|
1459
|
+
(stale || error) && h('p', { role: 'alert' }, stale ? t('error.conflict') : error)))
|
|
1460
|
+
}
|
|
1461
|
+
function Section({ title, label = title, items, count = items.length, render }) {
|
|
1462
|
+
const [limit, setLimit] = useState(50)
|
|
1463
|
+
if (!items.length) return null
|
|
1464
|
+
return h('section', { className: title ? 'dpm-section' : undefined, 'aria-label': label },
|
|
1465
|
+
title && h('div', { className: 'dpm-section-head' }, h('h4', null, title), h('small', null, count)),
|
|
1466
|
+
h('ul', null, items.slice(0, limit).map(render)),
|
|
1467
|
+
items.length > limit && h('button', { type: 'button', onClick: () => setLimit(limit + 50) },
|
|
1468
|
+
t('records.showMore', { count: Math.min(50, items.length - limit) })))
|
|
1469
|
+
}
|
|
1470
|
+
// Search hits are marked in place, so a long rule stays readable in context.
|
|
1471
|
+
function highlight(text, query) {
|
|
1472
|
+
const value = String(text ?? '')
|
|
1473
|
+
const words = [...new Set(String(query || '').trim().split(/\s+/).filter(Boolean))]
|
|
1474
|
+
.sort((a, b) => b.length - a.length).slice(0, 8)
|
|
1475
|
+
if (!words.length) return value
|
|
1476
|
+
const pattern = words.map(word => word.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('|')
|
|
1477
|
+
return value.split(new RegExp('(' + pattern + ')', 'gi')).map((part, index) => index % 2
|
|
1478
|
+
? h('mark', { key: index, className: 'dpm-mark' }, part)
|
|
1479
|
+
: part)
|
|
1480
|
+
}
|
|
1481
|
+
const shortcutKey = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform || navigator.userAgent)
|
|
1482
|
+
? '⌘K' : 'Ctrl K'
|
|
1483
|
+
function SettingRow({ as = 'div', title, description, descriptionId, note, saving, children }) {
|
|
1484
|
+
return h(as, { className: 'dpm-setting-row' },
|
|
1485
|
+
h('span', { className: 'dpm-setting-copy' },
|
|
1486
|
+
h('span', { className: 'dpm-setting-title' }, title,
|
|
1487
|
+
saving && h('small', { className: 'dpm-setting-saving' }, t('settings.saving'))),
|
|
1488
|
+
h('span', { className: 'dpm-setting-desc', id: descriptionId }, description),
|
|
1489
|
+
note && h('span', { className: 'dpm-setting-note', id: descriptionId + '-note' }, memoryIcon('clock'), note)),
|
|
1490
|
+
children)
|
|
1491
|
+
}
|
|
1492
|
+
function SettingSwitch({ title, description, note, checked, disabled, busy, saving, onChange }) {
|
|
1493
|
+
const descriptionId = React.useId()
|
|
1494
|
+
return h(SettingRow, { title, description, descriptionId, note, saving },
|
|
1495
|
+
h('span', { className: 'dpm-switch-control' },
|
|
1496
|
+
h('input', { className: 'dpm-switch', type: 'checkbox', role: 'switch', 'aria-label': title,
|
|
1497
|
+
'aria-describedby': note ? descriptionId + ' ' + descriptionId + '-note' : descriptionId,
|
|
1498
|
+
'aria-disabled': busy || undefined, checked, disabled, onChange: event => onChange(event.target.checked) }),
|
|
1499
|
+
h('span', { className: 'dpm-switch-track', 'aria-hidden': true })))
|
|
1500
|
+
}
|
|
1501
|
+
const consolidationOutcomes = {
|
|
1502
|
+
duplicate: 'consolidation.duplicate', distinct: 'consolidation.distinct',
|
|
1503
|
+
stale: 'consolidation.stale', failed: 'consolidation.failed',
|
|
1504
|
+
}
|
|
1505
|
+
function ProfileSwitches({ ctl }) {
|
|
1506
|
+
const settings = useSyncExternalStore(ctl.subscribe, ctl.getSnapshot)
|
|
1507
|
+
const state = settings.consolidation
|
|
1508
|
+
const [pending, setPending] = useState(null)
|
|
1509
|
+
const writing = React.useRef(false)
|
|
1510
|
+
const [error, setError] = useState(null)
|
|
1511
|
+
async function change(method, enabled) {
|
|
1512
|
+
const before = ctl.getSnapshot()
|
|
1513
|
+
if (writing.current || !before.ready || before.readOnly || (method === 'set-consolidation' && !before.memoryEnabled)) return
|
|
1514
|
+
writing.current = true
|
|
1515
|
+
setPending({ method, enabled })
|
|
1516
|
+
setError(null)
|
|
1517
|
+
try {
|
|
1518
|
+
const updated = await ctl.call(method, { enabled })
|
|
1519
|
+
// A newer observation can arrive while the write response is in flight.
|
|
1520
|
+
const current = ctl.getSnapshot()
|
|
1521
|
+
ctl.refreshIfObserved(current === before || current.version === updated.version ? updated : undefined)
|
|
1522
|
+
} catch (e) {
|
|
1523
|
+
setError({ method, cause: e })
|
|
1524
|
+
ctl.refreshIfObserved()
|
|
1525
|
+
} finally {
|
|
1526
|
+
writing.current = false
|
|
1527
|
+
setPending(null)
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
if (!settings.ready) return settings.error
|
|
1531
|
+
? h('p', { role: 'alert' }, settings.error)
|
|
1532
|
+
: h('p', { className: 'dpm-muted', role: 'status' }, t('settings.loading'))
|
|
1533
|
+
const savingMemory = pending?.method === 'set-memory-enabled'
|
|
1534
|
+
const savingReview = pending?.method === 'set-consolidation'
|
|
1535
|
+
const memoryEnabled = savingMemory ? pending.enabled : settings.memoryEnabled
|
|
1536
|
+
const reviewEnabled = savingReview ? pending.enabled : state.enabled
|
|
1537
|
+
const last = state.lastRun
|
|
1538
|
+
const formatTime = at => new Date(at).toLocaleString(document.documentElement.lang, {
|
|
1539
|
+
year: 'numeric', month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit',
|
|
1540
|
+
})
|
|
1541
|
+
let note
|
|
1542
|
+
if (memoryEnabled && reviewEnabled) {
|
|
1543
|
+
if (last) note = t('consolidation.last', { date: formatTime(last.at), outcome: t(consolidationOutcomes[last.outcome]) })
|
|
1544
|
+
else if (state.lastScanAt) note = t('consolidation.scan', { date: formatTime(state.lastScanAt) })
|
|
1545
|
+
else note = t('consolidation.wait')
|
|
1546
|
+
}
|
|
1547
|
+
const description = memoryEnabled ? t('consolidation.description')
|
|
1548
|
+
: t(reviewEnabled ? 'consolidation.paused' : 'consolidation.enableFirst')
|
|
1549
|
+
return h('div', { className: 'dpm-preferences', role: 'group', 'aria-label': t('settings.group'), 'aria-busy': Boolean(pending) },
|
|
1550
|
+
h(SettingSwitch, { title: t('settings.enable'), description: t(memoryEnabled ? 'settings.description' : 'settings.off'),
|
|
1551
|
+
checked: memoryEnabled, disabled: settings.readOnly, busy: Boolean(pending), saving: savingMemory,
|
|
1552
|
+
onChange: enabled => change('set-memory-enabled', enabled) }),
|
|
1553
|
+
h(SettingSwitch, { title: t('consolidation.title'), description, note, checked: reviewEnabled,
|
|
1554
|
+
disabled: settings.readOnly || !memoryEnabled, busy: Boolean(pending), saving: savingReview,
|
|
1555
|
+
onChange: enabled => change('set-consolidation', enabled) }),
|
|
1556
|
+
settings.readOnly && h('p', { className: 'dpm-setting-feedback' }, t('settings.readOnly')),
|
|
1557
|
+
error && h('p', { className: 'dpm-setting-feedback', role: 'alert' }, t('settings.saveFailed', {
|
|
1558
|
+
setting: t(error.method === 'set-memory-enabled' ? 'settings.enable' : 'consolidation.title'), reason: uiError(error.cause),
|
|
1559
|
+
})))
|
|
1560
|
+
}
|
|
1561
|
+
function SuggestionRow({ pair, scope, projectName, decide, readOnly }) {
|
|
1562
|
+
const [keep, choose] = useState('')
|
|
1563
|
+
const [busy, setBusy] = useState(false)
|
|
1564
|
+
const name = React.useId()
|
|
1565
|
+
async function submit(keepId) {
|
|
1566
|
+
if (busy) return
|
|
1567
|
+
setBusy(true)
|
|
1568
|
+
try { await decide(pair, keepId) }
|
|
1569
|
+
finally { setBusy(false) }
|
|
1570
|
+
}
|
|
1571
|
+
return h('li', { className: 'dpm-pending' },
|
|
1572
|
+
h('p', { className: 'dpm-meta' }, h(ScopeLabel, { scope, projectName })),
|
|
1573
|
+
h('div', { className: 'dpm-comparison', role: 'radiogroup', 'aria-label': t('consolidation.select') },
|
|
1574
|
+
[pair.left, pair.right].map(rule => h('label', { key: rule.id },
|
|
1575
|
+
h('input', { type: 'radio', name, value: rule.id, checked: keep === rule.id, disabled: readOnly || busy,
|
|
1576
|
+
onChange: () => choose(rule.id) }),
|
|
1577
|
+
h('span', { className: 'dpm-row-copy' },
|
|
1578
|
+
h('strong', { className: 'dpm-text' }, [subjectLabel(rule.subject), rule.topic].filter(Boolean).join(' · ')),
|
|
1579
|
+
h('span', { className: 'dpm-text' }, rule.action),
|
|
1580
|
+
h('span', { className: 'dpm-meta' }, [rule.usage === 'proactive' ? t('usage.proactive') : t('usage.onDemand'),
|
|
1581
|
+
rule.when && t('consolidation.when', { text: rule.when }), rule.exceptions && t('consolidation.exception', { text: rule.exceptions }), ...rule.paths].filter(Boolean).join(' · ')))))),
|
|
1582
|
+
h('div', { style: actionStyle },
|
|
1583
|
+
h('button', { type: 'button', disabled: !keep || readOnly || busy, onClick: () => submit(keep) }, t('consolidation.keepOne')),
|
|
1584
|
+
h('button', { type: 'button', disabled: readOnly || busy, onClick: () => submit(null) }, t('consolidation.keepBoth'))))
|
|
1585
|
+
}
|
|
1586
|
+
function useManagerResults(targets, controllerFor, live, text) {
|
|
1587
|
+
const [reply, setReply] = useState()
|
|
1588
|
+
const [version, setVersion] = useState(0)
|
|
1589
|
+
const reload = React.useCallback(() => setVersion(v => v + 1), [])
|
|
1590
|
+
// Keep a row's source, review and mutations on the same authorized session as its list.
|
|
1591
|
+
const targetKey = JSON.stringify(targets)
|
|
1592
|
+
const owners = React.useMemo(() => JSON.parse(targetKey).map(target => {
|
|
1593
|
+
const { root, cwd, projectKey } = target.context
|
|
1594
|
+
const expectedContext = { root, cwd, projectKey }
|
|
1595
|
+
const session = controllerFor(target.sessionId)
|
|
1596
|
+
return { ...target, key: JSON.stringify([target.scope, target.sessionId, expectedContext]), ctl: {
|
|
1597
|
+
call: (method, payload, signal) => session.call(method, { ...payload, scope: target.scope, expectedContext }, signal),
|
|
1598
|
+
refresh() { session.refreshIfObserved(); reload() },
|
|
1599
|
+
} }
|
|
1600
|
+
}), [targetKey, controllerFor, reload])
|
|
1601
|
+
const locale = t('language')
|
|
1602
|
+
// Locale renews server-translated results in place. Rows from the same authorized
|
|
1603
|
+
// scope, filter and page keep their focus, disclosure and unsaved edit state.
|
|
1604
|
+
const key = JSON.stringify([targetKey, text])
|
|
1605
|
+
const [selection, setSelection] = useState({ key, page: 0 })
|
|
1606
|
+
const page = selection.key === key ? selection.page : 0
|
|
1607
|
+
const pageSize = 50
|
|
1608
|
+
const resultKey = JSON.stringify([key, page])
|
|
1609
|
+
const previousSizes = React.useRef({ key, values: new Map() })
|
|
1610
|
+
const refreshOnLease = React.useRef(null)
|
|
1611
|
+
useEffect(() => {
|
|
1612
|
+
const abort = new AbortController()
|
|
1613
|
+
const words = text.normalize('NFKC').toLocaleLowerCase().split(/\s+/u)
|
|
1614
|
+
if (previousSizes.current.key !== key) previousSizes.current = { key, values: new Map() }
|
|
1615
|
+
const sizes = previousSizes.current.values
|
|
1616
|
+
const received = new Map()
|
|
1617
|
+
let running = false
|
|
1618
|
+
function windowAt(base, total = Infinity) {
|
|
1619
|
+
const start = Math.max(0, Math.min(total, page * pageSize - base))
|
|
1620
|
+
const end = Math.max(0, Math.min(total, (page + 1) * pageSize - base))
|
|
1621
|
+
return { offset: start, limit: end - start }
|
|
1622
|
+
}
|
|
1623
|
+
async function load(owner, window) {
|
|
1624
|
+
const previous = received.get(owner.key)
|
|
1625
|
+
try {
|
|
1626
|
+
const lease = previous?.offset === window.offset && previous.limit === window.limit ? previous.lease : undefined
|
|
1627
|
+
const data = await owner.ctl.call('manage', { op: text && !owner.pendingOnly ? 'search' : 'list', details: true,
|
|
1628
|
+
args: { query: text, locale }, page: owner.pendingOnly ? { offset: 0, limit: 0 } : window, lease }, abort.signal)
|
|
1629
|
+
if (data.unchanged && previous) return previous
|
|
1630
|
+
const pending = data.proposals.filter(p => {
|
|
1631
|
+
if (p.state !== 'pending') return false
|
|
1632
|
+
const fields = [t('section.pending'), t('scope.project'), owner.projectName,
|
|
1633
|
+
...p.items.flatMap(item => [item.action, item.when, item.user_quote])]
|
|
1634
|
+
const searchable = fields.join(' ').normalize('NFKC').toLocaleLowerCase()
|
|
1635
|
+
return words.every(word => searchable.includes(word))
|
|
1636
|
+
})
|
|
1637
|
+
const result = { ...owner, ...window, lease: data.lease, total: owner.pendingOnly ? 0 : data.total,
|
|
1638
|
+
rows: data.result.rules, invalid: data.result.needs_review, pending,
|
|
1639
|
+
suggestions: owner.pendingOnly ? [] : data.suggestions, reviewRules: data.reviewRules,
|
|
1640
|
+
readOnly: data.readOnly, memoryEnabled: data.memoryEnabled }
|
|
1641
|
+
received.set(owner.key, result)
|
|
1642
|
+
return result
|
|
1643
|
+
} catch (e) {
|
|
1644
|
+
received.delete(owner.key)
|
|
1645
|
+
return { ...owner, total: 0, error: uiError(e) }
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1648
|
+
async function refresh() {
|
|
1649
|
+
if (running) return
|
|
1650
|
+
running = true
|
|
1651
|
+
try {
|
|
1652
|
+
let base = 0
|
|
1653
|
+
let complete = true
|
|
1654
|
+
// Projects after this page return counts and review queues only. Counts can change
|
|
1655
|
+
// between requests, so correct a later project's window before displaying its rows.
|
|
1656
|
+
for (let i = 0; i < owners.length && !abort.signal.aborted; i += 4) {
|
|
1657
|
+
let estimated = base
|
|
1658
|
+
const results = await Promise.all(owners.slice(i, i + 4).map(owner => {
|
|
1659
|
+
const size = sizes.get(owner.key)
|
|
1660
|
+
const window = windowAt(estimated, size)
|
|
1661
|
+
estimated += size ?? 0
|
|
1662
|
+
return load(owner, window)
|
|
1663
|
+
}))
|
|
1664
|
+
const batch = new Map()
|
|
1665
|
+
for (let j = 0; j < results.length && !abort.signal.aborted; j++) {
|
|
1666
|
+
const owner = owners[i + j]
|
|
1667
|
+
let entry = results[j]
|
|
1668
|
+
let window = windowAt(base, entry.total)
|
|
1669
|
+
if (window.limit && (window.offset < entry.offset || window.offset + window.limit > entry.offset + entry.limit)) {
|
|
1670
|
+
entry = await load(owner, window)
|
|
1671
|
+
window = windowAt(base, entry.total)
|
|
1672
|
+
}
|
|
1673
|
+
sizes.set(owner.key, entry.total)
|
|
1674
|
+
base += entry.total
|
|
1675
|
+
if (!entry.error) {
|
|
1676
|
+
const begin = Math.max(0, window.offset - entry.offset)
|
|
1677
|
+
const end = begin + window.limit
|
|
1678
|
+
batch.set(owner.key, { ...entry, rows: entry.rows.slice(begin, end),
|
|
1679
|
+
invalid: entry.invalid.slice(Math.max(0, begin - entry.rows.length), Math.max(0, end - entry.rows.length)) })
|
|
1680
|
+
} else {
|
|
1681
|
+
complete = false
|
|
1682
|
+
batch.set(owner.key, entry)
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1685
|
+
if (!abort.signal.aborted) setReply(previous => {
|
|
1686
|
+
const entries = new Map(previous?.key === resultKey ? previous.entries : [])
|
|
1687
|
+
for (const [id, entry] of batch) entries.set(id, entry)
|
|
1688
|
+
return { key: resultKey, entries }
|
|
1689
|
+
})
|
|
1690
|
+
}
|
|
1691
|
+
if (complete && !abort.signal.aborted && page && page * pageSize >= base)
|
|
1692
|
+
setSelection({ key, page: Math.max(0, Math.ceil(base / pageSize) - 1) })
|
|
1693
|
+
} finally { running = false }
|
|
1694
|
+
}
|
|
1695
|
+
const timer = setTimeout(() => { refreshOnLease.current = refresh; void refresh() }, text ? 140 : 0)
|
|
1696
|
+
return () => { clearTimeout(timer); refreshOnLease.current = null; abort.abort() }
|
|
1697
|
+
}, [owners, key, resultKey, page, locale, text, version])
|
|
1698
|
+
useEffect(() => { void refreshOnLease.current?.() }, [live])
|
|
1699
|
+
const entries = reply?.key === resultKey ? reply.entries : new Map()
|
|
1700
|
+
const groups = owners.map(owner => entries.get(owner.key)).filter(Boolean)
|
|
1701
|
+
const pages = Math.ceil(groups.reduce((sum, group) => sum + group.total, 0) / pageSize)
|
|
1702
|
+
return { groups, page, pages, selectPage: page => setSelection({ key, page }),
|
|
1703
|
+
loading: entries.size < owners.length, reload }
|
|
1704
|
+
}
|
|
1705
|
+
function ManagerList({ scope, text, view, clearSearch, incomplete, retry, children }) {
|
|
1706
|
+
const { groups, loading } = view
|
|
1707
|
+
const [status, announce] = useState('')
|
|
1708
|
+
useEffect(() => { announce('') }, [text])
|
|
1709
|
+
useEffect(() => {
|
|
1710
|
+
if (!status) return
|
|
1711
|
+
const timer = setTimeout(() => announce(''), 4000)
|
|
1712
|
+
return () => clearTimeout(timer)
|
|
1713
|
+
}, [status])
|
|
1714
|
+
async function perform(owner, op, args) {
|
|
1715
|
+
const { result } = await owner.ctl.call('manage', { op, args })
|
|
1716
|
+
if (['conflict', 'not_found', 'unavailable', 'read_only'].includes(result?.status))
|
|
1717
|
+
throw Error(result.status)
|
|
1718
|
+
return result
|
|
1719
|
+
}
|
|
1720
|
+
async function decide(owner, pair, keepId) {
|
|
1721
|
+
const ref = ({ id, rev }) => ({ id, rev })
|
|
1722
|
+
const left = ref(pair.left), right = ref(pair.right)
|
|
1723
|
+
try {
|
|
1724
|
+
await owner.ctl.call('decide-consolidation', { root: owner.context.root, left, right,
|
|
1725
|
+
keep: keepId === null ? null : left.id === keepId ? left : right })
|
|
1726
|
+
announce(keepId === null ? t('consolidation.keptBoth') : t('consolidation.keptOne'))
|
|
1727
|
+
} catch (e) { announce(uiError(e)) }
|
|
1728
|
+
owner.ctl.refresh()
|
|
1729
|
+
}
|
|
1730
|
+
const errors = groups.filter(owner => owner.error)
|
|
1731
|
+
const available = groups.filter(owner => !owner.error)
|
|
1732
|
+
const items = field => available.flatMap(owner => owner[field].map(item => ({ owner, item })))
|
|
1733
|
+
const rows = items('rows'), invalid = items('invalid'), pending = items('pending'), suggestions = items('suggestions')
|
|
1734
|
+
function renderRule({ owner, item: rule }, withheld = false) {
|
|
1735
|
+
return h(ManageRow, { key: owner.key + rule.id, rule, withheld, scope: owner.scope, projectName: owner.projectName,
|
|
1736
|
+
ctl: owner.ctl, perform: (op, args) => perform(owner, op, args), reload: owner.ctl.refresh,
|
|
1737
|
+
readOnly: owner.readOnly, memoryEnabled: owner.memoryEnabled, renewal: owner, announce, query: text })
|
|
1738
|
+
}
|
|
1739
|
+
const noResults = !incomplete && !loading && !errors.length && !rows.length && !invalid.length && !pending.length && !suggestions.length
|
|
1740
|
+
const name = scope === 'profile' ? 'global' : scope
|
|
1741
|
+
return h('div', { className: 'dpm-manage' },
|
|
1742
|
+
children,
|
|
1743
|
+
h('div', { className: 'dpm-list' },
|
|
1744
|
+
errors.map(owner => h('p', { key: owner.key, role: 'alert' },
|
|
1745
|
+
t('scope.loadFailed', { name: owner.projectName || t('scope.global'), reason: owner.error }), ' ',
|
|
1746
|
+
h('button', { type: 'button', onClick: retry }, t('reload')))),
|
|
1747
|
+
loading && h('div', { className: 'dpm-loading', role: 'status' },
|
|
1748
|
+
h('span', { className: 'dpm-spinner', 'aria-hidden': true }), t('loading')),
|
|
1749
|
+
h(Section, { title: t('section.pending'), items: pending, count: pending.reduce((n, row) => n + row.item.items.length, 0),
|
|
1750
|
+
render: ({ owner, item: proposal }) => h('li', { className: 'dpm-pending', key: owner.key + proposal.id },
|
|
1751
|
+
h(Card, { ctl: owner.ctl, proposal, rules: owner.reviewRules, memoryEnabled: owner.memoryEnabled,
|
|
1752
|
+
scope: owner.scope, projectName: owner.projectName, query: text, readOnly: owner.readOnly, announce })) }),
|
|
1753
|
+
h(Section, { label: t('scope.' + name), items: rows, render: entry => renderRule(entry) }),
|
|
1754
|
+
h(Section, { title: t('section.duplicates'), items: suggestions, render: ({ owner, item: pair }) => h(SuggestionRow, {
|
|
1755
|
+
key: owner.key + pair.left.id + '@' + pair.left.rev + '/' + pair.right.id + '@' + pair.right.rev,
|
|
1756
|
+
pair, scope: owner.scope, projectName: owner.projectName, readOnly: owner.readOnly, decide: (p, keep) => decide(owner, p, keep) }) }),
|
|
1757
|
+
['section.inactive', 'section.inapplicable'].map(key => h(Section, { key, title: t(key),
|
|
1758
|
+
items: invalid.filter(({ item }) => item.statusKey === key), render: entry => renderRule(entry, true) })),
|
|
1759
|
+
!loading && !incomplete && !errors.length && view.pages > 1 && h('nav', { className: 'dpm-pages', 'aria-label': t('records.pages') },
|
|
1760
|
+
h('button', { type: 'button', disabled: view.page === 0, onClick: () => view.selectPage(view.page - 1) }, t('records.previous')),
|
|
1761
|
+
h('span', { role: 'status' }, t('records.page', { page: view.page + 1, pages: view.pages })),
|
|
1762
|
+
h('button', { type: 'button', disabled: view.page + 1 >= view.pages, onClick: () => view.selectPage(view.page + 1) }, t('records.next'))),
|
|
1763
|
+
noResults && h('div', { className: 'dpm-empty', role: 'status' },
|
|
1764
|
+
h('span', { className: 'dpm-empty-icon' }, memoryIcon(text ? 'search' : name)),
|
|
1765
|
+
h('strong', { className: 'dpm-empty-title' }, t(text ? 'empty.results' : 'empty.' + name)),
|
|
1766
|
+
(text || (name !== 'all' && available.some(owner => owner.memoryEnabled))) && h('p', { className: 'dpm-empty-copy' },
|
|
1767
|
+
t(text ? 'empty.searchHint' : 'empty.' + name + 'Hint')),
|
|
1768
|
+
text && h('button', { type: 'button', className: 'dpm-empty-action', onClick: clearSearch }, t('empty.clear')))),
|
|
1769
|
+
status && h('div', { className: 'dpm-toast', role: 'status', 'aria-live': 'polite' }, status))
|
|
1770
|
+
}
|
|
1771
|
+
function folderName(path) {
|
|
1772
|
+
return path?.split(/[/\\]/).filter(Boolean).pop() || path
|
|
1773
|
+
}
|
|
1774
|
+
// The host checks session visibility before returning a directory. Resolve only
|
|
1775
|
+
// while the settings page is mounted, in small batches, and abort on exit.
|
|
1776
|
+
function useDirectory(choices, controllerFor, retry) {
|
|
1777
|
+
const [directory, setDirectory] = useState()
|
|
1778
|
+
const key = JSON.stringify(choices.map(s => [s.id, s.cwd]).sort(([a], [b]) => a.localeCompare(b)))
|
|
1779
|
+
useEffect(() => {
|
|
1780
|
+
const abort = new AbortController()
|
|
1781
|
+
const sessions = JSON.parse(key)
|
|
1782
|
+
const contexts = new Map()
|
|
1783
|
+
let incomplete = false
|
|
1784
|
+
async function load() {
|
|
1785
|
+
for (let i = 0; i < sessions.length && !abort.signal.aborted; i += 6) {
|
|
1786
|
+
await Promise.all(sessions.slice(i, i + 6).map(async ([id]) => {
|
|
1787
|
+
try {
|
|
1788
|
+
const ctx = await controllerFor(id).call('context', { includePending: true }, abort.signal)
|
|
1789
|
+
contexts.set(id, ctx)
|
|
1790
|
+
} catch (error) {
|
|
1791
|
+
// Closed and inaccessible sessions are intentionally absent from the picker.
|
|
1792
|
+
if (error.code !== 'unavailable') incomplete = true
|
|
1793
|
+
}
|
|
1794
|
+
}))
|
|
1795
|
+
}
|
|
1796
|
+
if (!abort.signal.aborted) setDirectory({ key, retry, contexts, incomplete })
|
|
1797
|
+
}
|
|
1798
|
+
void load()
|
|
1799
|
+
return () => abort.abort()
|
|
1800
|
+
}, [key, controllerFor, retry])
|
|
1801
|
+
return directory?.key === key && directory.retry === retry ? directory : null
|
|
1802
|
+
}
|
|
1803
|
+
function ProjectSessions({ sessions, selected, onSelect }) {
|
|
1804
|
+
if (sessions.length < 2) return null
|
|
1805
|
+
return h(SettingRow, { as: 'label', title: t('scope.session'), description: t('scope.sessionDescription') },
|
|
1806
|
+
h('span', { className: 'dpm-picker' }, h('select', { value: selected, 'aria-label': t('scope.session'),
|
|
1807
|
+
onChange: e => onSelect(e.target.value) }, sessions.map(({ session, context }) => h('option', { key: session.id, value: session.id },
|
|
1808
|
+
session.displayTitle || session.title || session.id,
|
|
1809
|
+
context.root !== context.cwd ? ' · ' + context.cwd : '',
|
|
1810
|
+
context.readOnly ? ' · ' + t('scope.readOnly') : '')))))
|
|
1811
|
+
}
|
|
1812
|
+
function ScopeBrowser({ choices, controllerFor, reviewTarget }) {
|
|
1813
|
+
const [openedFrom] = useState(() => (choices.find(s => s.retainedBy?.mainView) || choices[0]).id)
|
|
1814
|
+
const [selected, setSelected] = useState(() => reviewTarget
|
|
1815
|
+
? { scope: 'project', sessionId: reviewTarget.sessionId, root: reviewTarget.root, projectKey: reviewTarget.projectKey }
|
|
1816
|
+
: { scope: 'all' })
|
|
1817
|
+
const focusReview = React.useRef(reviewTarget?.id)
|
|
1818
|
+
const preferredSessions = React.useRef(new Map())
|
|
1819
|
+
const [retry, setRetry] = useState(0)
|
|
1820
|
+
const directory = useDirectory(choices, controllerFor, retry)
|
|
1821
|
+
const origin = choices.find(s => s.id === openedFrom) || choices[0]
|
|
1822
|
+
const reader = directory && !directory.contexts.has(origin.id) ? choices.find(s => directory.contexts.has(s.id)) || origin : origin
|
|
1823
|
+
const chosen = choices.find(s => s.id === selected.sessionId) || reader
|
|
1824
|
+
const ctl = controllerFor(chosen.id)
|
|
1825
|
+
const live = useSyncExternalStore(ctl.subscribe, ctl.getSnapshot)
|
|
1826
|
+
const context = live.context
|
|
1827
|
+
const { scope, root: selectedRoot } = selected
|
|
1828
|
+
const listKey = JSON.stringify([scope, selectedRoot, chosen.id, context?.root, context?.cwd, context?.projectKey])
|
|
1829
|
+
const [search, setSearch] = useState(null)
|
|
1830
|
+
const searchInput = React.useRef(null)
|
|
1831
|
+
const query = search?.key === listKey ? search.value : ''
|
|
1832
|
+
function clearSearch() {
|
|
1833
|
+
setSearch(null)
|
|
1834
|
+
searchInput.current?.focus()
|
|
1835
|
+
}
|
|
1836
|
+
const projects = new Map()
|
|
1837
|
+
const domains = new Map()
|
|
1838
|
+
for (const session of choices) {
|
|
1839
|
+
const ctx = session.id === chosen.id ? context : directory?.contexts.get(session.id)
|
|
1840
|
+
if (!ctx?.root) continue
|
|
1841
|
+
for (const [map, key] of [[projects, ctx.root], [domains, ctx.projectKey || ctx.root]]) {
|
|
1842
|
+
if (!map.has(key)) map.set(key, [])
|
|
1843
|
+
map.get(key).push({ session, context: ctx })
|
|
1844
|
+
}
|
|
1845
|
+
}
|
|
1846
|
+
const roots = [...projects.keys()].sort((a, b) => folderName(a).localeCompare(folderName(b)) || a.localeCompare(b))
|
|
1847
|
+
const nameCounts = new Map()
|
|
1848
|
+
for (const root of roots) nameCounts.set(folderName(root), (nameCounts.get(folderName(root)) || 0) + 1)
|
|
1849
|
+
const projectName = root => nameCounts.get(folderName(root)) > 1 ? root : folderName(root)
|
|
1850
|
+
function representative(group) {
|
|
1851
|
+
const ctx = group[0].context
|
|
1852
|
+
const id = preferredSessions.current.get(ctx.projectKey || ctx.root)
|
|
1853
|
+
return group.find(entry => entry.session.id === id) || group.find(entry => entry.session.id === origin.id) || group[0]
|
|
1854
|
+
}
|
|
1855
|
+
function chooseSession(root, sessionId) {
|
|
1856
|
+
const entry = projects.get(root)?.find(e => e.session.id === sessionId)
|
|
1857
|
+
if (!entry) return
|
|
1858
|
+
preferredSessions.current.set(entry.context.projectKey || root, sessionId)
|
|
1859
|
+
setSearch(null)
|
|
1860
|
+
setSelected({ scope: 'project', root, sessionId, projectKey: entry.context.projectKey })
|
|
1861
|
+
}
|
|
1862
|
+
const name = scope === 'profile' ? 'global' : scope
|
|
1863
|
+
const projectHeading = t('scope.project')
|
|
1864
|
+
const scopePicker = h('span', { className: 'dpm-picker' }, memoryIcon(name),
|
|
1865
|
+
h('select', { className: 'dpm-scope-select', 'aria-label': t('scope'), title: selectedRoot || t('scope.' + name),
|
|
1866
|
+
value: selectedRoot || (scope === 'all' ? 'all' : ''),
|
|
1867
|
+
onKeyDown: event => {
|
|
1868
|
+
// Give an open native picker the first Escape before the settings dialog.
|
|
1869
|
+
if (event.key === 'Escape' && CSS.supports('selector(select:open)') && event.currentTarget.matches(':open'))
|
|
1870
|
+
event.stopPropagation()
|
|
1871
|
+
},
|
|
1872
|
+
onChange: event => {
|
|
1873
|
+
const value = event.target.value
|
|
1874
|
+
if (projects.has(value)) chooseSession(value, representative(projects.get(value)).session.id)
|
|
1875
|
+
else { setSearch(null); setSelected({ scope: value === 'all' ? 'all' : 'profile' }) }
|
|
1876
|
+
} },
|
|
1877
|
+
h('button', { type: 'button', 'aria-hidden': true }, h('selectedcontent')),
|
|
1878
|
+
h('option', { value: 'all' }, t('scope.all')),
|
|
1879
|
+
h('hr', { 'aria-hidden': true }),
|
|
1880
|
+
h('option', { value: '' }, t('scope.global')),
|
|
1881
|
+
(roots.length > 0 || selectedRoot) && h('optgroup', { label: projectHeading, 'aria-label': projectHeading },
|
|
1882
|
+
h('legend', { 'aria-hidden': true }, projectHeading),
|
|
1883
|
+
selectedRoot && !projects.has(selectedRoot) && h('option', { value: selectedRoot, disabled: true }, selectedRoot),
|
|
1884
|
+
roots.map(root => h('option', { key: root, value: root }, projectName(root))))))
|
|
1885
|
+
|
|
1886
|
+
const scopeChanged = scope === 'project' && (selectedRoot !== context?.root || selected.sessionId !== chosen.id
|
|
1887
|
+
|| selected.projectKey !== context?.projectKey)
|
|
1888
|
+
const searchable = Boolean(live.ready && !live.error && context && !scopeChanged && (scope !== 'all' || directory))
|
|
1889
|
+
const targets = []
|
|
1890
|
+
function add(scope, sessionId, ctx, pendingOnly = false) {
|
|
1891
|
+
const { root, cwd, projectKey, readOnly } = ctx
|
|
1892
|
+
targets.push({ scope, sessionId, pendingOnly, projectName: scope === 'project' ? projectName(root) : null,
|
|
1893
|
+
context: { root, cwd, projectKey, readOnly } })
|
|
1894
|
+
}
|
|
1895
|
+
if (searchable) {
|
|
1896
|
+
if (scope !== 'project') add('profile', chosen.id, context)
|
|
1897
|
+
if (scope === 'project') add('project', chosen.id, context)
|
|
1898
|
+
if (scope === 'all') {
|
|
1899
|
+
const byRoot = new Map([...domains.values()].map(group => {
|
|
1900
|
+
const entry = representative(group)
|
|
1901
|
+
return [entry.context.root, entry]
|
|
1902
|
+
}))
|
|
1903
|
+
const listed = new Set()
|
|
1904
|
+
for (const root of roots) {
|
|
1905
|
+
const entry = byRoot.get(root)
|
|
1906
|
+
if (entry) {
|
|
1907
|
+
add('project', entry.session.id, entry.context)
|
|
1908
|
+
listed.add(entry.session.id)
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
// Saved entries are shared by a project. A pending decision belongs to its source session.
|
|
1912
|
+
for (const [sessionId, ctx] of directory.contexts) {
|
|
1913
|
+
if (ctx.hasPending && !listed.has(sessionId)) add('project', sessionId, ctx, true)
|
|
1914
|
+
}
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
const text = query.trim()
|
|
1918
|
+
const view = useManagerResults(targets, controllerFor, live, text)
|
|
1919
|
+
useEffect(() => {
|
|
1920
|
+
if (!focusReview.current || !searchable || view.loading) return
|
|
1921
|
+
const card = document.querySelector('.dpm-settings [data-memory-card="' + CSS.escape(focusReview.current) + '"]')
|
|
1922
|
+
if (card) card.focus()
|
|
1923
|
+
focusReview.current = undefined
|
|
1924
|
+
}, [searchable, view.loading, view.groups])
|
|
1925
|
+
const incomplete = scope === 'all' && directory?.incomplete
|
|
1926
|
+
const countsReady = searchable && !incomplete && !view.loading && view.groups.every(group => !group.error)
|
|
1927
|
+
const savedCount = countsReady ? view.groups.reduce((n, g) => n + g.total, 0) : 0
|
|
1928
|
+
const resultCount = countsReady ? view.groups.reduce((n, g) => g.pending.reduce((total, proposal) => total + proposal.items.length, n), savedCount) : 0
|
|
1929
|
+
function retryLoad() {
|
|
1930
|
+
setRetry(v => v + 1)
|
|
1931
|
+
ctl.refresh()
|
|
1932
|
+
view.reload()
|
|
1933
|
+
}
|
|
1934
|
+
let content
|
|
1935
|
+
if (live.error) {
|
|
1936
|
+
content = h('p', { role: 'alert' }, live.error, ' ', h('button', { type: 'button', onClick: retryLoad }, t('reload')))
|
|
1937
|
+
} else if (!live.ready || (scope === 'all' && !directory)) {
|
|
1938
|
+
content = h('p', { className: 'dpm-muted', role: 'status' }, t('loading'))
|
|
1939
|
+
} else if (!context) {
|
|
1940
|
+
content = h('p', { role: 'status' }, t('scope.unavailable'))
|
|
1941
|
+
} else if (scopeChanged) {
|
|
1942
|
+
content = h('p', { role: 'status' }, t('scope.changed'))
|
|
1943
|
+
} else {
|
|
1944
|
+
content = h(ManagerList, { key: listKey, scope, text, view, clearSearch, incomplete, retry: retryLoad },
|
|
1945
|
+
incomplete && h('p', { role: 'alert' }, t('scope.incomplete'), ' ',
|
|
1946
|
+
h('button', { type: 'button', onClick: retryLoad }, t('reload'))),
|
|
1947
|
+
scope === 'project' && h(ProjectSessions, { sessions: projects.get(selectedRoot) || [], selected: chosen.id,
|
|
1948
|
+
onSelect: sessionId => chooseSession(selectedRoot, sessionId) }),
|
|
1949
|
+
scope !== 'all' && context.readOnly && h('p', { className: 'dpm-muted', role: 'status' }, t('scope.readOnlyNotice')))
|
|
1950
|
+
}
|
|
1951
|
+
return h('div', { className: 'dpm-records-card' },
|
|
1952
|
+
h('div', { className: 'dpm-records-toolbar', role: 'search', 'aria-label': t('records') },
|
|
1953
|
+
scopePicker,
|
|
1954
|
+
h('span', { className: 'dpm-records-count', 'data-memory-count': true, 'aria-live': 'polite', 'aria-atomic': true },
|
|
1955
|
+
countsReady && (text
|
|
1956
|
+
? t(resultCount === 1 ? 'records.foundOne' : 'records.foundMany', { count: resultCount })
|
|
1957
|
+
: t('records.savedCount', { count: savedCount }))),
|
|
1958
|
+
h('div', { className: 'dpm-search-wrap' }, memoryIcon('search'),
|
|
1959
|
+
h('input', { className: 'dpm-search', type: 'search', ref: searchInput,
|
|
1960
|
+
'aria-label': t('search'), placeholder: t('search'), disabled: !searchable,
|
|
1961
|
+
value: query, maxLength: 2048, onChange: e => setSearch({ key: listKey, value: e.target.value }) }),
|
|
1962
|
+
!query && searchable && h('kbd', { className: 'dpm-kbd', 'aria-hidden': true }, shortcutKey),
|
|
1963
|
+
query && h('button', { className: 'dpm-clear-search', type: 'button', 'aria-label': t('search.clear'),
|
|
1964
|
+
onClick: clearSearch }, memoryIcon('close')))),
|
|
1965
|
+
content)
|
|
1966
|
+
}
|
|
1967
|
+
function MemorySettings({ useSessions, controllerFor, settings, close }) {
|
|
1968
|
+
const list = useSessions(state => state)
|
|
1969
|
+
const [reviewTarget] = useState(() => requestedReview)
|
|
1970
|
+
useEffect(() => { requestedReview = undefined }, [])
|
|
1971
|
+
const page = React.useRef(null)
|
|
1972
|
+
useEffect(() => {
|
|
1973
|
+
const dialog = page.current.closest('[role="dialog"]')
|
|
1974
|
+
function focusSearch(event) {
|
|
1975
|
+
if (!(event.metaKey || event.ctrlKey) || event.key.toLowerCase() !== 'k') return
|
|
1976
|
+
const input = page.current.querySelector('.dpm-search:not(:disabled)')
|
|
1977
|
+
if (!input) return
|
|
1978
|
+
event.preventDefault()
|
|
1979
|
+
input.focus()
|
|
1980
|
+
input.select()
|
|
1981
|
+
}
|
|
1982
|
+
dialog?.addEventListener('keydown', focusSearch)
|
|
1983
|
+
return () => dialog?.removeEventListener('keydown', focusSearch)
|
|
1984
|
+
}, [])
|
|
1985
|
+
const choices = list.ids.map(id => list.byId[id])
|
|
1986
|
+
.filter(session => session && session.origin !== 'subagent')
|
|
1987
|
+
.sort((a, b) => b.updatedAt - a.updatedAt)
|
|
1988
|
+
return h('div', { className: 'dpm-settings', ref: page },
|
|
1989
|
+
h('style', null, managerCss),
|
|
1990
|
+
h('div', { className: 'dpm-manager' }, h(ProfileSwitches, { ctl: settings }),
|
|
1991
|
+
h('section', { className: 'dpm-pane', 'aria-label': t('records') }, choices.length ?
|
|
1992
|
+
h(CloseSettings.Provider, { value: close }, h(ScopeBrowser, { choices, controllerFor, reviewTarget }))
|
|
1993
|
+
: h('p', { className: 'dpm-muted', role: 'status' }, list.phase === 'pending'
|
|
1994
|
+
? t('sessions.loading') : t('sessions.empty')))))
|
|
1995
|
+
}
|
|
1996
|
+
function MemorySettingsIcon({ size }) {
|
|
1997
|
+
const crossing = React.useId()
|
|
1998
|
+
// Match the packaged memory-icon.svg while inheriting the menu text color.
|
|
1999
|
+
return h('svg', { width: size, height: size, viewBox: '0 0 128 128', 'aria-hidden': true },
|
|
2000
|
+
h('defs', null, h('mask', { id: crossing, maskUnits: 'userSpaceOnUse', x: 0, y: 0, width: 128, height: 128 },
|
|
2001
|
+
h('rect', { width: 128, height: 128, fill: 'white' }),
|
|
2002
|
+
h('path', { d: 'M58 68.67 70 51.33', fill: 'none', stroke: 'black', strokeWidth: 16 }))),
|
|
2003
|
+
h('g', { mask: 'url(#' + crossing + ')' },
|
|
2004
|
+
h('path', { d: 'M21.7 81.4v14.1q0 .8.7.3l17.4-12.3z M106.3 81.4v14.1q0 .8-.7.3L88.2 83.5z', fill: 'currentColor' }),
|
|
2005
|
+
h('path', { d: 'M64 60 54 45.6Q49.5 39 41.2 39H28.5C18.5 39 12 46 12 56v8c0 10 6.7 17 17 17h12.2c6.2 0 9.7-2.5 13.8-8l18-26c4.1-5.5 7.6-8 13.8-8H99c10.3 0 17 7 17 17v8c0 10-6.5 17-16.5 17H86.8q-8.3 0-12.8-6.6L64 60Z',
|
|
2006
|
+
fill: 'none', stroke: 'currentColor', strokeWidth: 11.5, strokeLinejoin: 'round' })),
|
|
2007
|
+
h('path', { d: 'M55 73 73 47', fill: 'none', stroke: 'currentColor', strokeWidth: 11.5 }))
|
|
2008
|
+
}
|
|
2009
|
+
const sessions = new Map()
|
|
2010
|
+
const settings = controller(ctx.connection)
|
|
2011
|
+
// A session shares one live projection across its hint and turn receipts.
|
|
2012
|
+
// DSH may retain the injected binding after its component unmounts.
|
|
2013
|
+
function controllerFor(sessionId) {
|
|
2014
|
+
let ctl = sessions.get(sessionId)?.deref()
|
|
2015
|
+
if (!ctl) {
|
|
2016
|
+
for (const [key, ref] of sessions) if (!ref.deref()) sessions.delete(key)
|
|
2017
|
+
ctl = controller(ctx.connection, sessionId)
|
|
2018
|
+
sessions.set(sessionId, new WeakRef(ctl))
|
|
2019
|
+
}
|
|
2020
|
+
return ctl
|
|
2021
|
+
}
|
|
2022
|
+
const inject = sessionId => ({ ctl: controllerFor(sessionId), sessionId })
|
|
2023
|
+
for (const [name, id, component] of [
|
|
2024
|
+
['conversation.chat.turnTail', 'dsh-memory-bond/review', Tail],
|
|
2025
|
+
['conversation.session.header.utilities', 'dsh-memory-bond/inbox', Inbox],
|
|
2026
|
+
]) ctx.slots.inject(name, () => ctx.slots.register({ name, id, inject, locale: section }, component))
|
|
2027
|
+
ctx.slots.inject('settings.section', () => ctx.slots.register({
|
|
2028
|
+
name: 'settings.section', id: section, order: 30, label: () => t('nav'), locale: section,
|
|
2029
|
+
inject: () => ({ controllerFor, settings }),
|
|
2030
|
+
}, MemorySettings))
|
|
2031
|
+
ctx.slots.inject('settings.section.icon', () => ctx.slots.register({
|
|
2032
|
+
name: 'settings.section.icon', id: section,
|
|
2033
|
+
}, MemorySettingsIcon))
|
|
2034
|
+
}
|
|
2035
|
+
})({"en":{"language":"en","nav":"Memory","guidance.review_required":"Review the applicable repository instructions","review.guidanceReviewed":"I checked the repository instructions. This memory follows them or uses a local exception they allow.","review.presentCommands":"Executables required on this machine (space-separated)","review.absentCommands":"Executables which must be absent (space-separated)","reason.repo_guidance_review_required":"Review the applicable repository instructions before saving","guidance.mandatory":"Repository instructions prohibit this rule","guidance.duplicate":"Already covered by repository instructions","guidance.unavailable":"Repository instructions have not been checked","guidance.ambiguous":"Clarify the repository default","guidance.permitted":"Confirm this local exception","turnReceipts.title":"Memory receipts for this turn","turnReceipts.added":"{count} added","turnReceipts.updated":"{count} updated","turnReceipts.savedHeading":"Saved this turn","turnReceipts.description":"Each memory version appears once. Expand a memory to see what reached the model on each request, what the assistant cited and which matching commands it ran.","turnReceipts.unnamed":"Memory {id}","turnReceipts.version":"Version {rev}","turnReceipts.requests.one":"{count} request","turnReceipts.requests.many":"{count} requests","turnReceipts.summary.hint":"Hint only","turnReceipts.summary.body":"Full text delivered","turnReceipts.summary.cited":"Cited by the assistant","turnReceipts.summary.executed":"Matching command ran","turnReceipts.loading":"Loading receipts…","turnReceipts.empty":"No delivery records are available to confirm which memories the model received for this reply.","turnReceipts.step":"Model request · step {step}","turnReceipts.retry":"Model request · step {step}, retry {retry}","turnReceipts.hint":"The model received only a hint it could use to look up the full memory.","turnReceipts.body":"The model received the full text of this memory.","turnReceipts.cited":"The assistant cited this revision in its reply.","turnReceipts.executed":"The assistant ran a matching command. See the tool output for the result.","turnReceipts.revision":"Memory revision","turnReceipts.attempts":"Foreground save attempts: {count}","turnReceipts.comparisons":"Recorded plugin comparisons: {count} (meaning {interpretation}, repository instructions {guidance})","turnReceipts.unmeasured":"Comparison counts are unavailable for {count} save attempts.","turnReceipts.failedItem":"Unsaved · Attempt {attempt}, item {item} · {reason}","turnReceipts.failedCall":"Unsaved · Attempt {attempt} · {reason}","turnReceipts.reason.insufficient_evidence":"The user’s words do not support this conclusion.","turnReceipts.reason.topic_mismatch":"The topic differs from the selected memory.","turnReceipts.reason.stale_revision":"The selected version is out of date.","turnReceipts.reason.replacement_required":"The existing memory requires an explicit replacement.","turnReceipts.reason.protected_revision":"The existing revision requires manual review before it can be replaced.","turnReceipts.reason.invalid_item":"The proposed memory is invalid.","turnReceipts.reason.ambiguous_topic":"The target memory could not be identified uniquely.","turnReceipts.reason.subject_mismatch":"The subject differs from the selected memory.","turnReceipts.reason.kind_mismatch":"The memory types differ.","turnReceipts.reason.context_mismatch":"The conditions for applying the memories differ.","turnReceipts.reason.target_not_found":"The selected memory is unavailable.","turnReceipts.reason.candidate_set_changed":"The candidate memories changed during comparison.","turnReceipts.reason.stale_guidance":"The repository instructions changed during review.","turnReceipts.reason.source_unavailable":"The original source is unavailable.","turnReceipts.reason.stale_source":"The original source is out of date.","turnReceipts.reason.invalid_source":"The source quote could not be verified.","turnReceipts.reason.source_quote_required":"An excerpt from the original message is required.","turnReceipts.reason.one_time_request":"The request applies only to this occasion.","turnReceipts.reason.opted_out":"The user requested that this information not be saved.","turnReceipts.reason.ineligible":"The item is ineligible for automatic saving.","turnReceipts.reason.invalid_scope":"The selected scope is invalid.","turnReceipts.reason.invalid_input":"The save request is invalid.","turnReceipts.reason.invalid_model_result":"The plugin could not validate the comparison result.","turnReceipts.reason.retry_limit_reached":"Bond stopped retrying this excerpt for this turn. You can clarify what to remember in a new message.","turnReceipts.reason.model_review_unavailable":"The comparison model was unavailable.","turnReceipts.reason.review_input_too_large":"The material exceeds the comparison limit.","turnReceipts.reason.needs_review":"The item needs human review.","turnReceipts.reason.repo_guidance_review_required":"The applicable repository instructions need review.","turnReceipts.reason.needs_clarification":"The conditions for the exception need clarification.","turnReceipts.reason.outside_command_scope":"The command falls outside the allowed scope.","turnReceipts.reason.outside_path":"The current path is outside the applicable scope.","turnReceipts.reason.outside_branch":"The rule does not apply to the current branch.","turnReceipts.reason.outside_environment":"The local environment conditions do not match.","turnReceipts.reason.local_conditions_review_required":"The local conditions require review.","turnReceipts.reason.memory_disabled":"Memory was turned off.","turnReceipts.reason.unavailable":"The memory operation was unavailable.","turnReceipts.reason.read_only":"The session was read-only.","turnReceipts.reason.conflict":"The save conflicted with the current memory state.","turnReceipts.reason.storage_full":"The disk has insufficient space.","turnReceipts.reason.write_failed":"The write failed.","turnReceipts.reason.storage_or_validation_error":"Storage or validation failed.","turnReceipts.reason.tool_failed":"The host reported a tool execution error.","turnReceipts.reason.unspecified":"No specific reason is available.","listSeparator":", ","rule.onDemand":"{topic} (on demand)","rule.always":"Always","rule.replace":"Replace or merge {ref} · {description}","review.selectItem":"Select item {number}","source.fileImport":"Imported from {path}, line {line} · SHA-256 {sha256}","source.manual":"Entered by the user","review.verifyAction":"Check that the action matches the quoted wording.","review.when":"When this applies (optional)","review.action":"Action","review.exceptions":"Exceptions","review.paths":"Applicable paths (one per line)","review.manualQuote":"Retained wording (edit or remove)","review.quote":"Retained quote (leave blank to keep only the receipt)","review.branch":"Branch restrictions","review.onlyBranch":"Apply only on this Git branch","review.environment":"Local environment","review.fileException":"Local exception for edited wording","error.stale_import":"The source file changed. Import it again to review the current wording.","review.exceptionScope":"Where this exception applies","review.related":"Related rules","review.findOthers":"Find other rules","review.relationship":"Relationship to existing rules","review.choose":"Choose how to proceed","review.coexist":"Keep both under different conditions","review.others":"Other rules","review.empty":"Select at least one suggestion to remember.","review.title":"Review memory suggestions","review.enable":"Turn on memory to save new suggestions. You can still ignore suggestions or update existing memories.","review.changed":"The project rules changed and this suggestion was refreshed. Check its current wording and reapply any unsaved edits.","review.checked":"I have reviewed the changes","review.confirm":"Remember","review.reject":"Ignore","review.confirmBatch":"Remember selected","review.rejectBatch":"Ignore all","review.batchHint":"Select the suggestions to remember. The rest will be ignored when you save.","review.remembered":"Saved to memory · {count}","review.ignored":"Suggestions ignored · {count}","review.done":"Done editing","review.source":"View source","review.moreConditions":"Exceptions, paths and branch","close":"Close","turn":"Turn {number}","review.hintOne":"{count} memory suggestion","review.hintMany":"{count} memory suggestions","review.hintOpen":"View","review.hintPath":"Settings → Memory","memory":"Memory","saved.restore":"Restore previous version","withdraw":"Withdraw","scope.all":"All memories","scope.incomplete":"Some projects could not be loaded.","scope.loadFailed":"Could not load {name}. {reason}","scope.global":"Global memory","scope.project":"Project memory","scope.rowGlobal":"Global","scope.rowProject":"Project {name}","memoryDisabled":"Memory disabled","usage.onDemand":"On demand","usage.proactive":"Automatic","subject.self":"You","subject.project":"This project","saved.updated":"Updated {topic}","saved.remembered":"Remembered {topic}","saved.undo":"{action}: {topic}","source.verified":"Verified user quote","source.verifiedShort":"Verified quote","source.retained":"Retained quote (original event unverified)","source.savedExcerpt":"Saved excerpt","source.manualEdit":"Edited manually","source.version":"Version {rev}","source.versionQuote":"Quote from version {rev}","source.openConversation":"Open original conversation","source.conversationUnavailable":"Original conversation unavailable","source.conversationArchived":"Original conversation archived","source.openFailed":"Couldn’t open the original conversation. Try again.","source.confirmed":"User-confirmed wording","source.toolEvidence":"Observed Bash execution","source.formSelection":"Submitted form option for “{question}”: {label}","source.scopeClarification":"In turn {turn}, the user limited this agreement to this project.","source.toolResult":"Bash ran {command} in {workdir} and returned exit code {exitCode} (call event {callSeq}, result event {resultSeq}).","source.edited":"Edited wording","source.redacted":"Redacted","source.receipt":"Action receipt","kind.preference":"Preference","kind.rule":"Rule","kind.fact":"Fact","kind.episode":"Episode","kind.reference":"Reference","kind.runbook":"Runbook","kind.guard":"Command guard","proof.anchored":"The source file is unchanged. The user supplied this statement.","proof.unverified":"Unverified","proof.pointer":"Source pointer","proof.success":"Successful execution observed","proof.reported":"Reported by the user","proof.confirmed":"Confirmed by the user","error.conflict":"This memory has changed. Reopen it and try again.","error.read_only":"Changes are unavailable in read-only mode.","error.unavailable":"This session is unavailable.","error.not_found":"This version was withdrawn or is no longer available. Refresh the list.","error.memory_disabled":"Enable memory in Settings to save a memory.","error.invalid_input":"Check the value and try again.","error.needs_resolution":"Choose a related rule to replace, or keep both under different conditions.","error.invalid_selection":"Check the selected items and try again.","error.storage_full":"There is not enough disk space to save this memory.","error.invalid_item":"Check the wording and try again.","error.failed":"Memory operation failed ({code}).","stage.locate":"Locate","stage.diagnose":"Diagnose","stage.repair":"Repair","stage.verify":"Verify","stage.basis":"Evidence","knowledge.source":"Reference: ","knowledge.anchors":"Source files","knowledge.command":"Applicable command: ","knowledge.success":"Successful command: ","source.excerpt":"Source excerpt","source":"Source","detail.when":"Applies when","detail.paths":"Paths","detail.index":"Index status","detail.subject":"Applies to","detail.topic":"Topic","detail.localException":"Local exception","source.historical":"A previous version or plugin backup retains source evidence.","source.none":"No source evidence available.","session":"Session {id}","exception":"Exception: {text}","exception.local":"Local exception: {environment} · {scope}","source.loading":"Loading source…","notice.pending":"Your edit is under Pending review in Memory settings.","notice.revise":"Changes saved.","notice.forget":"Memory withdrawn.","notice.usage":"Usage updated.","pinned":"Pinned","indexed":"Indexed","overBudget":"Outside the index budget","delivered":"Received current version","undelivered":"Has yet to receive this version","signals.details":"Usage and version","signals.empty":"No usage yet","signals.delivered.one":"Delivered to {count} session","signals.delivered.many":"Delivered to {count} sessions","signals.session":"This session","signals.opened":"Opened in full","signals.count.one":"{count} session","signals.count.many":"{count} sessions","signals.last":"Last delivered","viewSource":"View source","edit":"Edit","more":"More actions","switchProactive":"Use automatically","switchOnDemand":"Use on demand","content":"Memory content","saveEdit":"Save changes","cancel":"Cancel","withdraw.global":"Withdrawing this memory stops its use in every project and session in this profile.","withdraw.project":"Withdrawing this memory stops its use in every session in this project.","withdraw.confirm":"Confirm withdrawal","withheld.profile":"Global {kind}","withheld.project":"Project memory ({kind})","withheld.quote":"Quote: “{quote}”","details":"View details","originalQuote":"Original quote","items.one":"{count} item","items.many":"{count} items","collapse":"Collapse","review.open":"Review","consolidation.duplicate":"Possible duplicate found","consolidation.distinct":"Both memories kept","consolidation.stale":"Candidates changed and the result was skipped","consolidation.failed":"The model request did not finish","settings.loading":"Loading memory settings…","settings.group":"Memory settings","settings.saving":"Saving…","settings.readOnly":"Memory settings are read-only in this profile.","settings.saveFailed":"Couldn’t save the change to “{setting}”. {reason}","consolidation.description":"When a project session is idle, find possible duplicates across sessions for you to review. The model compares at most one pair of summaries per project per hour.","consolidation.paused":"Review is paused while memory is off. It resumes when you enable memory.","consolidation.enableFirst":"Enable memory to turn on cross-session review.","settings.enable":"Enable memory","settings.description":"Let the assistant save and use memories in conversations. You can still manage saved records when memory is off.","settings.off":"The assistant has stopped saving and using memories. You can still manage your saved records below.","consolidation.title":"Cross-session review","consolidation.last":"Last model review · {outcome} · {date}","consolidation.scan":"Last scan · {date}","consolidation.wait":"Waiting for an idle project session to run the first scan","consolidation.select":"Choose which memory to keep","consolidation.when":"When: {text}","consolidation.exception":"Exception: {text}","consolidation.keepOne":"Keep selected and withdraw the other","consolidation.keepBoth":"Keep both","consolidation.keptBoth":"Both memories kept.","consolidation.keptOne":"Selected memory kept. The other memory was withdrawn.","section.pending":"Pending review","search":"Search memories","search.clear":"Clear search","reload":"Reload","loading":"Loading memories…","section.duplicates":"Possible duplicates","section.inactive":"Inactive","section.inapplicable":"Currently inapplicable","empty.results":"No matching memories","empty.all":"No saved memories yet","empty.global":"No global memories yet","empty.project":"No project memories yet","empty.searchHint":"Try another keyword or clear the search to see all memories.","empty.globalHint":"Tell the assistant “Call me Alex from now on” to use that name across projects.","empty.projectHint":"Tell the assistant “Run tests before committing in this project.” The saved rule will appear here.","empty.clear":"Clear search","scope.session":"Session","scope.sessionDescription":"View project memories using this session's working directory and permissions.","scope.readOnly":"Read-only","records":"Memory records","records.savedCount":"{count} saved","records.showMore":"Show {count} more","records.page":"Page {page} of {pages}","records.pages":"Memory list pages","records.previous":"Previous","records.next":"Next","records.foundOne":"{count} result","records.foundMany":"{count} results","scope":"Memory scope","scope.unavailable":"Open an accessible workspace session to view its memories.","scope.changed":"This session's project has changed. Select the memory scope again.","scope.readOnlyNotice":"This session is read-only.","sessions.loading":"Loading local sessions…","sessions.empty":"Open a workspace session to view memory records.","reason.outside_branch":"Does not apply to the current Git branch","reason.outside_path":"Does not apply to the current path","reason.outside_command_scope":"Command is outside the project","reason.local_conditions_review_required":"Review the local exception and specify its executable checks.","reason.outside_environment":"Does not apply to this machine or environment","reason.stale_guidance":"Repository instructions have changed","reason.needs_clarification":"Repository instructions need clarification","reason.needs_review":"A file, build target or other condition has changed","reason.anchor_changed":"The source file has changed","reason.anchor_unavailable":"The source file cannot be read","reason.invalid_anchor":"The source file is no longer valid","reason.invalid_anchors":"File evidence is incomplete","reason.symbol_missing":"The symbol is missing from the source","reason.invalid_reference":"The reference is no longer valid","reason.invalid_workdir":"The working directory is no longer valid","reason.invalid_match":"The applicable command is no longer valid","reason.unconfirmed_guard":"The command guard is unconfirmed","reason.unavailable":"This project cannot verify this memory","error.invalid_branch":"Enter a valid Git branch name.","error.duplicate":"This memory is already present.","error.invalid_source":"The source quote could not be verified.","error.fact_on_demand":"Facts are looked up when needed.","error.on_demand":"Only memories set to automatic use can be pinned.","error.repo_guidance_review_required":"Check that the rule is compatible with the listed repository instructions.","error.needs_clarification":"Check the repository instructions and specify where the local exception applies."},"zh":{"language":"zh","nav":"记忆","guidance.review_required":"请核对适用的仓库指令","review.guidanceReviewed":"我已核对仓库指令。这条记忆符合指令,或使用了指令允许的本机例外。","review.presentCommands":"本机必须存在的可执行程序(空格分隔)","review.absentCommands":"本机必须不存在的可执行程序(空格分隔)","reason.repo_guidance_review_required":"保存前需要核对适用的仓库指令","guidance.mandatory":"仓库指令禁止此项","guidance.duplicate":"已在仓库指令中声明","guidance.unavailable":"仓库指令尚未核对","guidance.ambiguous":"需要澄清仓库默认项","guidance.permitted":"需确认本机例外","turnReceipts.title":"本轮记忆回执","turnReceipts.added":"新增 {count} 条","turnReceipts.updated":"更新 {count} 条","turnReceipts.savedHeading":"本轮保存","turnReceipts.description":"同一版本在多次模型请求中只列一次。展开一条记忆,可查看每次请求的送达、引用和命令执行记录。","turnReceipts.unnamed":"记忆 {id}","turnReceipts.version":"第 {rev} 版","turnReceipts.requests.one":"{count} 次请求","turnReceipts.requests.many":"{count} 次请求","turnReceipts.summary.hint":"仅提供线索","turnReceipts.summary.body":"正文已送达","turnReceipts.summary.cited":"助手已引用","turnReceipts.summary.executed":"已执行匹配命令","turnReceipts.loading":"正在读取回执…","turnReceipts.empty":"这次回答没有可查看的送达记录,无法据此确认模型收到了哪些记忆。","turnReceipts.step":"模型请求 · 第 {step} 步","turnReceipts.retry":"模型请求 · 第 {step} 步,第 {retry} 次重试","turnReceipts.hint":"模型只收到了查阅线索,可按编号读取具体内容。","turnReceipts.body":"模型收到了这条记忆的正文。","turnReceipts.cited":"助手在回复中引用了这条记忆的版本号。","turnReceipts.executed":"助手运行了与这条约定匹配的命令,执行结果见工具输出。","turnReceipts.revision":"记忆版本","turnReceipts.attempts":"前台保存尝试 {count} 次","turnReceipts.comparisons":"已记录插件比较 {count} 次(语义 {interpretation} 次,仓库指令 {guidance} 次)","turnReceipts.unmeasured":"有 {count} 次保存尝试未记录比较次数。","turnReceipts.failedItem":"未保存 · 第 {attempt} 次提交,第 {item} 条 · {reason}","turnReceipts.failedCall":"未保存 · 第 {attempt} 次提交 · {reason}","turnReceipts.reason.insufficient_evidence":"原话不足以支持这条结论。","turnReceipts.reason.topic_mismatch":"主题与目标记忆不匹配。","turnReceipts.reason.stale_revision":"目标版本已过期。","turnReceipts.reason.replacement_required":"已有记忆需要明确指定替换。","turnReceipts.reason.protected_revision":"替换这条受保护的记忆需要人工审核。","turnReceipts.reason.invalid_item":"提议的记忆条目无效。","turnReceipts.reason.ambiguous_topic":"无法唯一确定目标记忆。","turnReceipts.reason.subject_mismatch":"主体与目标记忆不匹配。","turnReceipts.reason.kind_mismatch":"记忆类型不匹配。","turnReceipts.reason.context_mismatch":"记忆的适用条件不匹配。","turnReceipts.reason.target_not_found":"目标记忆不可用。","turnReceipts.reason.candidate_set_changed":"比较期间候选记忆已变更。","turnReceipts.reason.stale_guidance":"审核期间仓库指令已变更。","turnReceipts.reason.source_unavailable":"原始来源不可用。","turnReceipts.reason.stale_source":"原始来源已过期。","turnReceipts.reason.invalid_source":"无法核验来源原话。","turnReceipts.reason.source_quote_required":"需要提供可核验的原话片段。","turnReceipts.reason.one_time_request":"请求仅适用于本次。","turnReceipts.reason.opted_out":"用户要求跳过保存。","turnReceipts.reason.ineligible":"该条目不符合自动保存条件。","turnReceipts.reason.invalid_scope":"所选作用域无效。","turnReceipts.reason.invalid_input":"保存请求的参数无效。","turnReceipts.reason.invalid_model_result":"插件无法验证比较结果。","turnReceipts.reason.retry_limit_reached":"本轮已停止用这段原话重试。你可以在新消息中补充要记住的内容。","turnReceipts.reason.model_review_unavailable":"比较模型不可用。","turnReceipts.reason.review_input_too_large":"待比较内容超过大小限制。","turnReceipts.reason.needs_review":"该条目需要人工审核。","turnReceipts.reason.repo_guidance_review_required":"需要核对适用的仓库指令。","turnReceipts.reason.needs_clarification":"需要澄清例外的适用条件。","turnReceipts.reason.outside_command_scope":"命令超出允许的范围。","turnReceipts.reason.outside_path":"当前路径不在适用范围内。","turnReceipts.reason.outside_branch":"规则不适用于当前分支。","turnReceipts.reason.outside_environment":"本机环境不符合适用条件。","turnReceipts.reason.local_conditions_review_required":"本机适用条件需要审核。","turnReceipts.reason.memory_disabled":"记忆已关闭。","turnReceipts.reason.unavailable":"记忆操作不可用。","turnReceipts.reason.read_only":"当前会话处于只读模式。","turnReceipts.reason.conflict":"保存与当前记忆状态冲突。","turnReceipts.reason.storage_full":"磁盘空间不足。","turnReceipts.reason.write_failed":"写入失败。","turnReceipts.reason.storage_or_validation_error":"存储或校验失败。","turnReceipts.reason.tool_failed":"宿主报告工具执行失败。","turnReceipts.reason.unspecified":"没有可显示的具体原因。","listSeparator":"、","rule.onDemand":"{topic}(按需查阅)","rule.always":"始终","rule.replace":"替代或合并 {ref} · {description}","review.selectItem":"选择第 {number} 项","source.fileImport":"文件来源:{path},第 {line} 行 · SHA-256 {sha256}","source.manual":"用户手动表述","review.verifyAction":"请核对动作与原话是否一致。","review.when":"适用条件(选填)","review.action":"动作","review.exceptions":"例外","review.paths":"适用路径(每行一个)","review.manualQuote":"保留的手动表述(可删改)","review.quote":"保留的原话(可删改,留空只保留回执)","review.branch":"分支限制","review.onlyBranch":"仅在此 Git 分支适用","review.environment":"本机环境","review.fileException":"为修改后的表述指定本机例外","error.stale_import":"来源文件已变更。请重新导入并审核当前表述。","review.exceptionScope":"例外适用边界","review.related":"相关规则","review.findOthers":"查找其他规则","review.relationship":"与现行规则的关系","review.choose":"选择处理方式","review.coexist":"按不同条件并存","review.others":"其他规则","review.empty":"请至少选一条要记住的建议。","review.title":"审阅记忆建议","review.enable":"启用记忆后即可保存新建议。你仍可忽略建议或修改已有记忆。","review.changed":"项目规则有更新,建议已刷新。请重新核对内容,并重新填写尚未保存的修改。","review.checked":"已核对更新","review.confirm":"记住","review.reject":"忽略","review.confirmBatch":"记住所选","review.rejectBatch":"全部忽略","review.batchHint":"勾选要记住的建议。保存时,其余建议会被忽略。","review.remembered":"已记住 {count} 条","review.ignored":"已忽略 {count} 条建议","review.done":"完成编辑","review.source":"查看来源","review.moreConditions":"例外、路径和分支","close":"关闭","turn":"第 {number} 轮","review.hintOne":"有 {count} 条记忆建议","review.hintMany":"有 {count} 条记忆建议","review.hintOpen":"查看","review.hintPath":"设置 → 记忆","memory":"记忆","saved.restore":"恢复上一版","withdraw":"撤回","scope.all":"全部记忆","scope.incomplete":"部分项目暂时无法加载。","scope.loadFailed":"无法读取「{name}」。{reason}","scope.global":"全局记忆","scope.project":"项目记忆","scope.rowGlobal":"全局","scope.rowProject":"项目 {name}","memoryDisabled":"记忆已停用","usage.onDemand":"按需查阅","usage.proactive":"自动使用","subject.self":"本人","subject.project":"本项目","saved.updated":"已更新「{topic}」","saved.remembered":"已记住「{topic}」","saved.undo":"{action}:{topic}","source.verified":"已核验的用户原话","source.verifiedShort":"已核验原话","source.retained":"留存引文(未核验原始事件)","source.savedExcerpt":"保存的引文","source.manualEdit":"手动编辑","source.version":"第 {rev} 版","source.versionQuote":"第 {rev} 版原话","source.openConversation":"查看原对话","source.conversationUnavailable":"原对话不可用","source.conversationArchived":"原对话已归档","source.openFailed":"暂时无法打开原对话,请重试。","source.confirmed":"用户确认的表述","source.toolEvidence":"实测 Bash 执行记录","source.formSelection":"表单问题「{question}」中提交的选项:{label}","source.scopeClarification":"用户在第 {turn} 轮将这条约定限定为仅适用于本项目。","source.toolResult":"Bash 在 {workdir} 执行 {command},退出码 {exitCode}(调用事件 {callSeq},结果事件 {resultSeq})。","source.edited":"编辑后的表述","source.redacted":"已脱敏","source.receipt":"操作回执","kind.preference":"偏好","kind.rule":"规则","kind.fact":"事实","kind.episode":"经历","kind.reference":"参考资料","kind.runbook":"操作手册","kind.guard":"命令约束","proof.anchored":"依据文件存在且未变更,内容为用户陈述","proof.unverified":"未经核验","proof.pointer":"来源指引","proof.success":"已观察到成功执行","proof.reported":"用户报告","proof.confirmed":"用户已确认","error.conflict":"条目版本已更新,请重新打开后再操作。","error.read_only":"当前会话处于只读模式。","error.unavailable":"当前会话不可访问。","error.not_found":"该版本已撤回或失效,请刷新列表。","error.memory_disabled":"记忆已关闭。请先在设置中启用记忆。","error.invalid_input":"设置值无效,请检查后重试。","error.needs_resolution":"已有相关规则,请选择替代条目,或明确按不同条件并存。","error.invalid_selection":"选择无效,请重新核对所选项。","error.storage_full":"磁盘空间不足,项目记忆写入失败。","error.invalid_item":"表述无效,请检查后重试。","error.failed":"记忆操作失败({code})。","stage.locate":"定位","stage.diagnose":"诊断","stage.repair":"修复","stage.verify":"验证","stage.basis":"依据","knowledge.source":"参考来源:","knowledge.anchors":"文件依据","knowledge.command":"适用命令:","knowledge.success":"成功执行:","source.excerpt":"来源摘录","source":"来源","detail.when":"适用时机","detail.paths":"适用路径","detail.index":"索引状态","detail.subject":"适用对象","detail.topic":"主题","detail.localException":"本机例外","source.historical":"历史版本或插件备份中仍有来源证据。","source.none":"暂无可查看的来源证据。","session":"会话 {id}","exception":"例外:{text}","exception.local":"本机例外:{environment} · {scope}","source.loading":"正在读取来源…","notice.pending":"修改已放入记忆设置的「待确认」列表。","notice.revise":"修改已保存","notice.forget":"记忆已撤回","notice.usage":"用途已更新","pinned":"已置顶","indexed":"已选入索引","overBudget":"超出索引预算","delivered":"已收到当前版本","undelivered":"尚未收到当前版本","signals.details":"使用记录与版本","signals.empty":"暂无使用记录","signals.delivered.one":"已送达 {count} 个会话","signals.delivered.many":"已送达 {count} 个会话","signals.session":"本会话","signals.opened":"查阅正文","signals.count.one":"{count} 个会话","signals.count.many":"{count} 个会话","signals.last":"最近送达","viewSource":"查看来源","edit":"编辑","more":"更多操作","switchProactive":"设为自动使用","switchOnDemand":"改为按需查阅","content":"记忆内容","saveEdit":"保存修改","cancel":"取消","withdraw.global":"撤回后,当前配置下的所有项目和会话都会停止使用这条记忆。","withdraw.project":"撤回后,这个项目的所有会话都会停止使用这条记忆。","withdraw.confirm":"确认撤回","withheld.profile":"全局{kind}","withheld.project":"项目{kind}","withheld.quote":"原话:「{quote}」","details":"查看详情","originalQuote":"来源原话","items.one":"{count} 项","items.many":"{count} 项","collapse":"收起","review.open":"处理","consolidation.duplicate":"发现疑似重复记忆","consolidation.distinct":"两条记忆分别保留","consolidation.stale":"候选已变化,本次结果已跳过","consolidation.failed":"模型请求未完成","settings.loading":"正在读取记忆设置…","settings.group":"记忆设置","settings.saving":"正在保存…","settings.readOnly":"当前配置为只读,无法更改记忆设置。","settings.saveFailed":"未能保存「{setting}」的更改。{reason}","consolidation.description":"会话空闲时,查找同一项目不同会话中可能重复的记忆,供你确认。每个项目每小时最多请模型比较一对摘要。","consolidation.paused":"整理已暂停。重新启用记忆后会自动恢复。","consolidation.enableFirst":"先启用记忆,即可开启跨会话整理。","settings.enable":"启用记忆","settings.description":"允许助手在对话中保存和使用记忆。关闭后仍可管理已有记录。","settings.off":"助手已暂停保存和使用记忆。你仍可在下方管理已有记录。","consolidation.title":"跨会话整理","consolidation.last":"上次模型整理 · {outcome} · {date}","consolidation.scan":"最近筛选于 {date}","consolidation.wait":"等待项目会话空闲后首次筛选","consolidation.select":"选择要保留的记忆","consolidation.when":"适用条件 {text}","consolidation.exception":"例外 {text}","consolidation.keepOne":"保留所选,撤回另一条","consolidation.keepBoth":"两条都保留","consolidation.keptBoth":"已保留两条记忆","consolidation.keptOne":"已保留所选记忆,并撤回另一条","section.pending":"待确认","search":"搜索记忆","search.clear":"清空搜索","reload":"重新加载","loading":"正在读取记忆…","section.duplicates":"疑似重复","section.inactive":"已停用","section.inapplicable":"当前不适用","empty.results":"没有匹配的记忆","empty.all":"还没有已保存的记忆","empty.global":"还没有全局记忆","empty.project":"还没有项目记忆","empty.searchHint":"换个关键词试试,或清除搜索查看全部记忆。","empty.globalHint":"在对话里说「以后叫我小林」,就能在其他项目沿用这个称呼。","empty.projectHint":"在此项目的对话中说「本项目提交前先运行测试」,保存后就会出现在这里。","empty.clear":"清除搜索","scope.session":"使用会话","scope.sessionDescription":"按所选会话的工作目录和权限查看项目记忆。","scope.readOnly":"只读","records":"记忆记录","records.savedCount":"已保存 {count} 条","records.showMore":"再显示 {count} 条","records.page":"第 {page} 页,共 {pages} 页","records.pages":"记忆列表分页","records.previous":"上一页","records.next":"下一页","records.foundOne":"找到 {count} 条","records.foundMany":"找到 {count} 条","scope":"记忆范围","scope.unavailable":"无法读取此会话的记忆。请打开一个可访问的工作区会话。","scope.changed":"此会话的项目已更改。请重新选择记忆范围。","scope.readOnlyNotice":"当前会话为只读。","sessions.loading":"正在读取本机会话…","sessions.empty":"请打开一个工作区会话以查看记忆记录。","reason.outside_branch":"当前 Git 分支不适用","reason.outside_path":"当前路径不适用","reason.outside_command_scope":"命令超出项目范围","reason.local_conditions_review_required":"请重新核对本机例外,并填写适用的程序检查条件。","reason.outside_environment":"当前机器或环境不适用","reason.stale_guidance":"仓库指令已变更","reason.needs_clarification":"需要澄清仓库指令","reason.needs_review":"文件、构建目标或其他适用条件已变化","reason.anchor_changed":"依据文件内容已变更","reason.anchor_unavailable":"依据文件无法读取","reason.invalid_anchor":"依据文件已失效","reason.invalid_anchors":"文件依据不完整","reason.symbol_missing":"依据中的符号已消失","reason.invalid_reference":"参考来源已失效","reason.invalid_workdir":"工作目录已失效","reason.invalid_match":"适用命令已失效","reason.unconfirmed_guard":"命令约束未确认","reason.unavailable":"当前项目无法核验此条记忆","error.invalid_branch":"请输入有效的 Git 分支名。","error.duplicate":"该项目记忆已存在。","error.invalid_source":"无法核验来源原话。","error.fact_on_demand":"事实在需要时查阅。","error.on_demand":"只有设为自动使用的记忆可以置顶。","error.repo_guidance_review_required":"请核对列出的仓库指令并确认编辑后的内容与其相容。","error.needs_clarification":"请核对仓库指令,并说明本机例外的适用范围。"}})
|