dsh-memory-bond 0.0.0-stage → 0.3.0-beta.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 +11 -0
- package/LICENSE +21 -0
- package/README.md +147 -2
- package/README.zh-CN.md +150 -0
- package/client/index.js +1186 -0
- package/client/memory-icon.svg +21 -0
- package/cordis.patch.yml +3 -0
- package/design/dsh-memory-plugin-design.md +46 -0
- package/design/dsh-memory-plugin-evaluation.md +135 -0
- package/design/evaluations/locomo-conv-26-2026-12-03.json +252 -0
- package/design/evaluations/locomo-conv-26-paired-2026-12-03.json +549 -0
- package/design/evaluations/locomo-conv-26-write-replay-2026-12-03.json +289 -0
- package/design/evaluations/project-memory-tasks-2026-12-03.json +1059 -0
- package/design/memory-lifecycle-consolidation.excalidraw +1212 -0
- package/design/memory-lifecycle-consolidation.mobile.excalidraw +1083 -0
- package/design/memory-lifecycle-consolidation.mobile.svg +2 -0
- package/design/memory-lifecycle-consolidation.mobile.zh-CN.excalidraw +1083 -0
- package/design/memory-lifecycle-consolidation.mobile.zh-CN.svg +94 -0
- package/design/memory-lifecycle-consolidation.svg +2 -0
- package/design/memory-lifecycle-consolidation.zh-CN.excalidraw +1212 -0
- package/design/memory-lifecycle-consolidation.zh-CN.svg +94 -0
- package/design/memory-lifecycle.excalidraw +2105 -0
- package/design/memory-lifecycle.mobile.excalidraw +1896 -0
- package/design/memory-lifecycle.mobile.svg +95 -0
- package/design/memory-lifecycle.mobile.zh-CN.excalidraw +1896 -0
- package/design/memory-lifecycle.mobile.zh-CN.svg +97 -0
- package/design/memory-lifecycle.svg +95 -0
- package/design/memory-lifecycle.zh-CN.excalidraw +2105 -0
- package/design/memory-lifecycle.zh-CN.svg +97 -0
- package/dist/audit.js +211 -0
- package/dist/automatic.js +8 -0
- package/dist/cache.js +40 -0
- package/dist/command-scope.js +123 -0
- package/dist/commands.js +150 -0
- package/dist/consolidation-store.js +290 -0
- package/dist/consolidation.js +186 -0
- package/dist/domain.js +241 -0
- package/dist/encoder.js +97 -0
- package/dist/export-files.js +161 -0
- package/dist/guidance.js +201 -0
- package/dist/host.js +6 -0
- package/dist/index-policy.js +148 -0
- package/dist/index.js +287 -0
- package/dist/knowledge-hooks.js +355 -0
- package/dist/knowledge.js +360 -0
- package/dist/maintenance-episodes.js +73 -0
- package/dist/maintenance-import.js +92 -0
- package/dist/maintenance-store.js +704 -0
- package/dist/maintenance.js +352 -0
- package/dist/model-review.js +16 -0
- package/dist/personal.js +23 -0
- package/dist/policy.js +384 -0
- package/dist/propose-contract.js +42 -0
- package/dist/question-answers.js +119 -0
- package/dist/retrieval.js +109 -0
- package/dist/search-index.js +84 -0
- package/dist/search-words.js +5 -0
- package/dist/semantic.js +295 -0
- package/dist/service.js +1044 -0
- package/dist/sharing.js +295 -0
- package/dist/sources.js +124 -0
- package/dist/store.js +1242 -0
- package/dist/turn-review-store.js +92 -0
- package/dist/turn-review.js +363 -0
- package/dist/ui.js +244 -0
- package/dist/vector-index.js +196 -0
- package/locale/detail.en.md +9 -0
- package/locale/detail.zh.md +9 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/native/embeddings/LICENSE +21 -0
- package/native/embeddings/NOTICE.md +12 -0
- package/native/embeddings/en/model.onnx +4 -0
- package/native/embeddings/en/vocab.txt +30522 -0
- package/native/embeddings/runtime/LICENSE +21 -0
- package/native/embeddings/runtime/ThirdPartyNotices.txt +6156 -0
- package/native/embeddings/runtime/ort-wasm-simd-threaded.mjs +70 -0
- package/native/embeddings/runtime/ort-wasm-simd-threaded.wasm +0 -0
- package/native/embeddings/runtime/ort.wasm.min.mjs +7 -0
- package/native/embeddings/worker.mjs +97 -0
- package/native/embeddings/zh/model.onnx +0 -0
- package/native/embeddings/zh/vocab.txt +21128 -0
- package/package.json +97 -4
- package/src/audit.ts +227 -0
- package/src/automatic.ts +11 -0
- package/src/cache.ts +38 -0
- package/src/command-scope.ts +125 -0
- package/src/commands.ts +155 -0
- package/src/consolidation-store.ts +288 -0
- package/src/consolidation.ts +180 -0
- package/src/domain.ts +249 -0
- package/src/encoder.ts +102 -0
- package/src/export-files.ts +178 -0
- package/src/guidance.ts +229 -0
- package/src/host.ts +99 -0
- package/src/index-policy.ts +184 -0
- package/src/index.ts +289 -0
- package/src/knowledge-hooks.ts +414 -0
- package/src/knowledge.ts +433 -0
- package/src/maintenance-episodes.ts +76 -0
- package/src/maintenance-import.ts +107 -0
- package/src/maintenance-store.ts +835 -0
- package/src/maintenance.ts +360 -0
- package/src/model-review.ts +27 -0
- package/src/personal.ts +32 -0
- package/src/policy.ts +505 -0
- package/src/propose-contract.ts +43 -0
- package/src/question-answers.ts +111 -0
- package/src/retrieval.ts +116 -0
- package/src/search-index.ts +97 -0
- package/src/search-words.ts +6 -0
- package/src/semantic.ts +299 -0
- package/src/service.ts +1103 -0
- package/src/sharing.ts +356 -0
- package/src/sources.ts +128 -0
- package/src/store.ts +1492 -0
- package/src/turn-review-store.ts +87 -0
- package/src/turn-review.ts +336 -0
- package/src/ui.ts +290 -0
- package/src/vector-index.ts +200 -0
package/client/index.js
ADDED
|
@@ -0,0 +1,1186 @@
|
|
|
1
|
+
// DSH browser module. React is shared with the conversation renderer.
|
|
2
|
+
window.__ModuleLoader__.load({
|
|
3
|
+
id: 'dsh-memory-bond',
|
|
4
|
+
factory(require) {
|
|
5
|
+
const React = require('react')
|
|
6
|
+
const h = React.createElement
|
|
7
|
+
const { useEffect, useState, useSyncExternalStore } = React
|
|
8
|
+
const channel = '/api'
|
|
9
|
+
const empty = Object.freeze({ proposals: [], rules: [], saved: [], ready: false })
|
|
10
|
+
const statusLabels = { confirmed: '已确认', rejected: '已拒绝', expired: '已过期', cancelled: '已取消' }
|
|
11
|
+
const guidanceLabels = {
|
|
12
|
+
mandatory: '仓库指令禁止此项', duplicate: '已在仓库指令中声明', unavailable: '仓库指令尚未核对',
|
|
13
|
+
ambiguous: '需要澄清仓库默认项', permitted: '需确认本机例外',
|
|
14
|
+
}
|
|
15
|
+
const fieldStyle = { display: 'grid', gap: '.15rem', marginBlock: '.35rem' }
|
|
16
|
+
const formStyle = { padding: '.75rem', marginBlock: '.5rem', border: '1px solid currentColor', borderRadius: '.5rem' }
|
|
17
|
+
const actionStyle = { display: 'flex', gap: '.75rem', marginBlockStart: '.5rem', flexWrap: 'wrap' }
|
|
18
|
+
|
|
19
|
+
function controller(connection, sessionId) {
|
|
20
|
+
const viewMethod = sessionId === undefined ? 'get-settings' : 'view'
|
|
21
|
+
let snapshot = empty
|
|
22
|
+
let active
|
|
23
|
+
let reviewing
|
|
24
|
+
let detach
|
|
25
|
+
const listeners = new Set()
|
|
26
|
+
const publish = value => {
|
|
27
|
+
if (reviewing && !value.proposals.some(p => p.id === reviewing)) reviewing = undefined
|
|
28
|
+
snapshot = { ...value, reviewing }
|
|
29
|
+
for (const listener of listeners) listener()
|
|
30
|
+
}
|
|
31
|
+
async function call(method, payload = {}, signal) {
|
|
32
|
+
const args = sessionId === undefined ? payload : { ...payload, sessionId }
|
|
33
|
+
const response = await connection.rpc.call(channel, 'project-memory-ui/' + method, args, signal)
|
|
34
|
+
if (!response.ok) throw Error(response.error.message)
|
|
35
|
+
return response.value
|
|
36
|
+
}
|
|
37
|
+
function refresh(current) {
|
|
38
|
+
active?.abort()
|
|
39
|
+
const run = new AbortController()
|
|
40
|
+
active = run
|
|
41
|
+
if (current) publish({ ...current, ready: true })
|
|
42
|
+
const observe = async () => {
|
|
43
|
+
let version = current?.version
|
|
44
|
+
while (!run.signal.aborted) {
|
|
45
|
+
try {
|
|
46
|
+
const result = await call(viewMethod, { version }, run.signal)
|
|
47
|
+
if (run.signal.aborted) return
|
|
48
|
+
version = result.version
|
|
49
|
+
publish({ ...result, ready: true })
|
|
50
|
+
} catch (e) {
|
|
51
|
+
if (run.signal.aborted) return
|
|
52
|
+
// Reconnect/query failures close this view until the host reauthorizes it.
|
|
53
|
+
publish({ ...empty, error: uiError(e) })
|
|
54
|
+
version = undefined
|
|
55
|
+
await new Promise(resolve => setTimeout(resolve, 1500))
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
void observe()
|
|
60
|
+
}
|
|
61
|
+
function generationChanged() {
|
|
62
|
+
active?.abort()
|
|
63
|
+
publish(empty)
|
|
64
|
+
if (connection.generation?.getSnapshot()) refresh()
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
call, refresh, refreshIfObserved: current => { if (listeners.size) refresh(current) },
|
|
68
|
+
reviewInInbox: id => { reviewing = id; publish(snapshot) },
|
|
69
|
+
getSnapshot: () => snapshot,
|
|
70
|
+
subscribe: listener => {
|
|
71
|
+
listeners.add(listener)
|
|
72
|
+
if (listeners.size === 1) {
|
|
73
|
+
detach = connection.generation?.subscribe(generationChanged)
|
|
74
|
+
if (!connection.generation || connection.generation.getSnapshot()) refresh()
|
|
75
|
+
}
|
|
76
|
+
return () => {
|
|
77
|
+
listeners.delete(listener)
|
|
78
|
+
if (listeners.size) return
|
|
79
|
+
detach?.()
|
|
80
|
+
active?.abort()
|
|
81
|
+
snapshot = empty
|
|
82
|
+
reviewing = undefined
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function label(text, control) { return h('label', { style: fieldStyle }, text, control) }
|
|
88
|
+
function field(name, value, text, options = {}) {
|
|
89
|
+
return label(text, h('input', { name, defaultValue: value || '', maxLength: 4096, ...options }))
|
|
90
|
+
}
|
|
91
|
+
function pathsFrom(text) {
|
|
92
|
+
return String(text).split('\n').map(p => p.trim()).filter(Boolean)
|
|
93
|
+
}
|
|
94
|
+
// A review answers with a receipt: its state is confirmed or rejected.
|
|
95
|
+
function assertAccepted(result) {
|
|
96
|
+
const outcome = result?.state ?? result?.status
|
|
97
|
+
if (outcome && !['pending', 'confirmed', 'rejected', 'duplicate'].includes(outcome))
|
|
98
|
+
throw Error(result.message || result.reason || outcome)
|
|
99
|
+
return result
|
|
100
|
+
}
|
|
101
|
+
function Receipt({ proposal, rules, memoryEnabled }) {
|
|
102
|
+
return h('section', { 'data-memory-receipt': proposal.id, 'aria-live': 'polite', style: formStyle },
|
|
103
|
+
h('strong', null, '项目记忆 · ', statusLabels[proposal.state] || proposal.state),
|
|
104
|
+
(proposal.receipt?.entries || []).map(entry => {
|
|
105
|
+
const rule = rules.find(rule => rule.id === entry.id && rule.rev === entry.rev)
|
|
106
|
+
const indexed = rule?.indexed ?? entry.indexed
|
|
107
|
+
if (rule?.usage === 'on_demand' && rule.topic) return h('p', { key: entry.id }, topicLabel(rule.topic), memoryEnabled && ' · 按需使用')
|
|
108
|
+
return h('p', { key: entry.id }, entry.id, '@', String(entry.rev),
|
|
109
|
+
memoryEnabled && (rule === undefined ? ' · 此版本当前不可用' : indexed === undefined ? '' : indexed ? ' · 当前配置将进索引' : ' · 仅可搜索'))
|
|
110
|
+
}),
|
|
111
|
+
memoryEnabled && proposal.receipt?.displaced?.length ? h('p', null,
|
|
112
|
+
'因索引预算移出:', proposal.receipt.displaced.map(x => x.id || x).join('、'), '。可用 /project-memory pin 置顶。') : null)
|
|
113
|
+
}
|
|
114
|
+
function Row({ item, index, rules, manual }) {
|
|
115
|
+
const key = name => index + '-' + name
|
|
116
|
+
const { guidance } = item
|
|
117
|
+
const blocked = ['mandatory', 'duplicate', 'unavailable'].includes(guidance?.status)
|
|
118
|
+
const local = ['permitted', 'ambiguous'].includes(guidance?.status)
|
|
119
|
+
const [selected, setSelected] = useState(!blocked)
|
|
120
|
+
const [search, setSearch] = useState('')
|
|
121
|
+
const projectRules = rules.filter(r => r.scope !== 'profile')
|
|
122
|
+
const related = (item.related ?? []).filter(r => r.scope !== 'profile')
|
|
123
|
+
const ids = new Set(related.map(r => r.id))
|
|
124
|
+
const choices = projectRules.filter(r => !ids.has(r.id) &&
|
|
125
|
+
[r.id, r.topic, r.when, r.action, ...(r.paths || [])].join(' ').toLowerCase().includes(search.toLowerCase()))
|
|
126
|
+
const description = rule => rule.action === undefined
|
|
127
|
+
? rule.topic + '(按需查阅)' : (rule.when || '始终') + ' → ' + rule.action
|
|
128
|
+
const option = rule => h('option', { key: rule.id, value: rule.id + '@' + rule.rev },
|
|
129
|
+
'替代或合并 ' + rule.id + '@' + rule.rev + ' · ' + description(rule))
|
|
130
|
+
const fingerprints = guidance?.files?.map(f => f.path + ' ' + f.hash?.slice(0, 12)).join('、')
|
|
131
|
+
return h('fieldset', null,
|
|
132
|
+
h('legend', null, label('选择第 ' + (index + 1) + ' 项', h('input', { type: 'checkbox',
|
|
133
|
+
name: 'selected', value: String(index), checked: selected, disabled: blocked,
|
|
134
|
+
onChange: e => setSelected(e.target.checked) }))),
|
|
135
|
+
manual ? h('p', null, '用户手动表述') : item.actionInferred && item.action !== item.user_quote
|
|
136
|
+
? h('p', null, '请核对动作与原话是否一致。') : null,
|
|
137
|
+
guidanceLabels[guidance?.status] ? h('p', { role: 'note' }, guidanceLabels[guidance.status],
|
|
138
|
+
guidance.path ? ' · ' + guidance.path : '', guidance.excerpt ? ' · ' + guidance.excerpt : '',
|
|
139
|
+
fingerprints ? ' · ' + fingerprints : '') : null,
|
|
140
|
+
h('fieldset', { disabled: !selected || blocked, style: { border: 0, padding: 0 } },
|
|
141
|
+
field(key('when'), item.when, '适用条件(不限时留空)'),
|
|
142
|
+
field(key('action'), item.action, '动作', { required: true }),
|
|
143
|
+
field(key('exceptions'), item.exceptions, '例外'),
|
|
144
|
+
label('适用路径(每行一个)', h('textarea', { name: key('paths'), rows: 2, defaultValue: item.paths.join('\n') })),
|
|
145
|
+
label(manual ? '保留的手动表述(可删改)' : '保留的原话(可删改,留空只保留回执)', h('textarea', { name: key('user_quote'), rows: 2,
|
|
146
|
+
defaultValue: item.user_quote, maxLength: 4096 })),
|
|
147
|
+
h('details', null, h('summary', null, '分支限制'), field(key('branch'), item.hard?.branch, '仅在此 Git 分支适用')),
|
|
148
|
+
local ? h(React.Fragment, null,
|
|
149
|
+
field(key('environment'), '', '本机环境', { required: true }), field(key('scope'), '', '例外适用边界', { required: true })) : null,
|
|
150
|
+
projectRules.length || related.length ? h(React.Fragment, null,
|
|
151
|
+
related.length ? h('ul', { 'aria-label': '相关规则' }, related.map(r => h('li', { key: r.id },
|
|
152
|
+
r.id, '@', String(r.rev), ' · ', description(r)))) : null,
|
|
153
|
+
projectRules.some(r => !ids.has(r.id)) ? label('查找其他规则', h('input', { type: 'search', value: search,
|
|
154
|
+
onChange: e => setSearch(e.target.value) })) : null,
|
|
155
|
+
label('与现行规则的关系', h('select', { name: key('relationship'), defaultValue: item.replace ? item.replace.id + '@' + item.replace.rev : '' },
|
|
156
|
+
h('option', { value: '' }, '选择处理方式'), h('option', { value: 'coexist' }, '按不同条件并存'),
|
|
157
|
+
related.length ? h('optgroup', { label: '相关规则' }, related.map(option)) : null,
|
|
158
|
+
choices.length ? h('optgroup', { label: '其他规则' }, choices.map(option)) : null))) : null))
|
|
159
|
+
}
|
|
160
|
+
function reviewRows(data) {
|
|
161
|
+
return data.getAll('selected').map(value => {
|
|
162
|
+
const index = Number(value)
|
|
163
|
+
const get = name => String(data.get(index + '-' + name) ?? '').trim()
|
|
164
|
+
const relation = get('relationship')
|
|
165
|
+
const split = relation.lastIndexOf('@')
|
|
166
|
+
return { index, changes: {
|
|
167
|
+
when: get('when'), action: get('action'), user_quote: get('user_quote'),
|
|
168
|
+
exceptions: get('exceptions'), paths: pathsFrom(get('paths')),
|
|
169
|
+
}, branch: get('branch') || null, ...(relation === 'coexist' ? { coexist: true } : {}),
|
|
170
|
+
...(split < 0 ? {} : { replace: { id: relation.slice(0, split), rev: Number(relation.slice(split + 1)) } }),
|
|
171
|
+
...(get('environment') ? { exception: { environment: get('environment'), scope: get('scope') } } : {}) }
|
|
172
|
+
})
|
|
173
|
+
}
|
|
174
|
+
function Card({ ctl, proposal, rules, memoryEnabled, inManager }) {
|
|
175
|
+
const [seenRevision, setSeenRevision] = useState(proposal.revision)
|
|
176
|
+
const changed = seenRevision !== proposal.revision
|
|
177
|
+
const [busy, setBusy] = useState(false)
|
|
178
|
+
const [error, setError] = useState('')
|
|
179
|
+
async function submit(event) {
|
|
180
|
+
event.preventDefault()
|
|
181
|
+
const form = event.currentTarget
|
|
182
|
+
const reject = event.nativeEvent.submitter?.value === 'reject'
|
|
183
|
+
const selections = reject ? [] : reviewRows(new FormData(form))
|
|
184
|
+
if (!reject && changed) return
|
|
185
|
+
if (!reject && selections.length === 0) { setError('请至少勾选一项,或拒绝整批。'); return }
|
|
186
|
+
if (busy) return
|
|
187
|
+
setBusy(true)
|
|
188
|
+
setError('')
|
|
189
|
+
try {
|
|
190
|
+
assertAccepted(await ctl.call('review', {
|
|
191
|
+
id: proposal.id, revision: proposal.revision, digest: proposal.digest, selections,
|
|
192
|
+
}))
|
|
193
|
+
} catch (e) { setError(uiError(e)) }
|
|
194
|
+
finally { setBusy(false); ctl.refresh() }
|
|
195
|
+
}
|
|
196
|
+
return h('form', { onSubmit: submit, tabIndex: -1, id: inManager ? undefined : 'project-memory-review-' + proposal.id, 'aria-label': '审阅项目记忆', 'data-memory-card': proposal.id, style: inManager ? undefined : formStyle },
|
|
197
|
+
!inManager && h('strong', null, '审阅项目记忆'),
|
|
198
|
+
memoryEnabled === false && h('p', { role: 'note' }, '新增记录前请先启用记忆。你仍可拒绝提议或更正已有记录。'),
|
|
199
|
+
changed && h('p', { role: 'alert' }, '项目规则已变更。请重新核对下列条件、动作和相关规则。 ',
|
|
200
|
+
h('button', { type: 'button', onClick: () => setSeenRevision(proposal.revision) }, '已核对更新')),
|
|
201
|
+
proposal.items.map((item, index) => h(Row, { key: proposal.digest + ':' + index, index, item, rules, manual: proposal.source?.origin === 'manual' })),
|
|
202
|
+
error && h('p', { role: 'alert' }, error),
|
|
203
|
+
h('footer', { style: actionStyle },
|
|
204
|
+
h('button', { type: 'submit', value: 'accept', disabled: busy || changed }, '确认所选项'),
|
|
205
|
+
h('button', { type: 'submit', formNoValidate: true, value: 'reject', disabled: busy }, '拒绝整批')))
|
|
206
|
+
}
|
|
207
|
+
// A global proposal can be a name, a personal fact or a preference.
|
|
208
|
+
function ReviewDialog({ ctl, proposal, pending, rules, memoryEnabled }) {
|
|
209
|
+
const dialog = React.useRef(null)
|
|
210
|
+
useEffect(() => {
|
|
211
|
+
const node = dialog.current
|
|
212
|
+
node.showModal()
|
|
213
|
+
return () => { node.close() }
|
|
214
|
+
}, [])
|
|
215
|
+
const title = '待审项目记忆'
|
|
216
|
+
return h('dialog', { ref: dialog, 'aria-label': title,
|
|
217
|
+
onCancel: () => ctl.reviewInInbox(undefined),
|
|
218
|
+
style: { maxWidth: 'min(42rem, 94vw)', width: '100%', maxHeight: '85vh', overflow: 'auto',
|
|
219
|
+
WebkitAppRegion: 'no-drag', borderRadius: '.55rem', padding: '1rem' } },
|
|
220
|
+
h('header', { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center' } },
|
|
221
|
+
h('strong', null, title),
|
|
222
|
+
h('button', { type: 'button', onClick: () => ctl.reviewInInbox(undefined) }, '关闭')),
|
|
223
|
+
proposal.state === 'pending' && pending.length > 1 ? label('选择提案', h('select', { value: proposal.id, onChange: e => ctl.reviewInInbox(e.target.value) },
|
|
224
|
+
pending.map(p => h('option', { value: p.id, key: p.id }, '第 ' + p.turnId + ' 轮 · ' + p.items[0].action)))) : null,
|
|
225
|
+
proposal.state === 'pending' ? h(Card, { key: proposal.id, proposal, rules, ctl, memoryEnabled })
|
|
226
|
+
: h(Receipt, { proposal, rules, memoryEnabled }))
|
|
227
|
+
}
|
|
228
|
+
function Inbox({ ctl }) {
|
|
229
|
+
const view = useSyncExternalStore(ctl.subscribe, ctl.getSnapshot)
|
|
230
|
+
useEffect(() => () => ctl.reviewInInbox(undefined), [ctl])
|
|
231
|
+
if (!view.ready) return null
|
|
232
|
+
const pending = view.proposals.filter(p => p.state === 'pending')
|
|
233
|
+
const selected = view.proposals.find(p => p.id === view.reviewing)
|
|
234
|
+
if (!pending.length && !selected) return null
|
|
235
|
+
function open() {
|
|
236
|
+
const first = pending[0]
|
|
237
|
+
// Keep edits made in an already mounted single-row review surface.
|
|
238
|
+
const inline = pending.length === 1 && document.getElementById('project-memory-review-' + first.id)
|
|
239
|
+
if (inline && inline.getClientRects().length) {
|
|
240
|
+
inline.scrollIntoView({ block: 'center' })
|
|
241
|
+
inline.focus({ preventScroll: true })
|
|
242
|
+
} else ctl.reviewInInbox(first.id)
|
|
243
|
+
}
|
|
244
|
+
return h(React.Fragment, null, pending.length ? h('button', { type: 'button', 'data-memory-inbox': true,
|
|
245
|
+
onClick: open, style: { WebkitAppRegion: 'no-drag' } }, '待审记忆 (' + pending.length + ')') : null,
|
|
246
|
+
selected ? h(ReviewDialog, { ctl, proposal: selected, pending, rules: view.rules, memoryEnabled: view.memoryEnabled }) : null)
|
|
247
|
+
}
|
|
248
|
+
function topicLabel(topic) {
|
|
249
|
+
return topic
|
|
250
|
+
}
|
|
251
|
+
const savedStyle = { display: 'flex', flexWrap: 'wrap', alignItems: 'baseline', gap: '.5rem', margin: '.25rem 0',
|
|
252
|
+
fontSize: '.86em', color: 'GrayText' }
|
|
253
|
+
const undoStyle = { font: 'inherit', color: 'inherit', background: 'none', border: 0, padding: 0,
|
|
254
|
+
textDecoration: 'underline', cursor: 'pointer' }
|
|
255
|
+
// What was saved without a card stays visible on the turn that said it, with one click to take it back.
|
|
256
|
+
function Saved({ ctl, items, readOnly, memoryEnabled }) {
|
|
257
|
+
const [busy, setBusy] = useState(() => new Set())
|
|
258
|
+
const [error, setError] = useState('')
|
|
259
|
+
const mark = (id, on) => setBusy(current => {
|
|
260
|
+
const next = new Set(current)
|
|
261
|
+
if (on) next.add(id)
|
|
262
|
+
else next.delete(id)
|
|
263
|
+
return next
|
|
264
|
+
})
|
|
265
|
+
async function undo(item) {
|
|
266
|
+
if (busy.has(item.id)) return
|
|
267
|
+
mark(item.id, true)
|
|
268
|
+
setError('')
|
|
269
|
+
try {
|
|
270
|
+
await ctl.call('manage', { op: 'undo', args: { id: item.id, rev: item.rev } })
|
|
271
|
+
} catch (e) {
|
|
272
|
+
setError(uiError(e))
|
|
273
|
+
} finally {
|
|
274
|
+
mark(item.id, false)
|
|
275
|
+
ctl.refresh()
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return h('div', { 'data-memory-saved': true, 'aria-live': 'polite' },
|
|
279
|
+
items.map(item => {
|
|
280
|
+
const topic = item.topic || '记忆'
|
|
281
|
+
const undoLabel = item.hasPrevious ? '恢复上一版' : '撤回'
|
|
282
|
+
const scope = item.scope === 'profile' ? '全局记忆' : '项目记忆'
|
|
283
|
+
const detail = scope + ' · ' + (!memoryEnabled ? '记忆已停用' : item.usage === 'on_demand' ? '按需查阅' : '主动遵守')
|
|
284
|
+
return h('p', { key: item.id + '@' + item.rev, style: savedStyle, 'data-memory-saved-entry': item.id },
|
|
285
|
+
h('span', { title: detail }, (item.hasPrevious ? '已更新' : '已记住') + topic),
|
|
286
|
+
h('button', { type: 'button', style: undoStyle, disabled: readOnly || busy.has(item.id), 'data-memory-undo': item.id,
|
|
287
|
+
'aria-label': undoLabel + ':' + topic, 'aria-description': detail, onClick: () => undo(item) }, undoLabel))
|
|
288
|
+
}),
|
|
289
|
+
error ? h('p', { role: 'alert' }, error) : null)
|
|
290
|
+
}
|
|
291
|
+
function Tail({ turn, ctl }) {
|
|
292
|
+
const view = useSyncExternalStore(ctl.subscribe, ctl.getSnapshot)
|
|
293
|
+
if (!view.ready || !turn.end) return null
|
|
294
|
+
const current = view.proposals.filter(p => Number(p.turnId) === turn.turn &&
|
|
295
|
+
p.receipt?.channel !== 'automatic' && p.id !== view.reviewing)
|
|
296
|
+
const saved = (view.saved || []).filter(item => Number(item.turnId) === turn.turn)
|
|
297
|
+
if (!current.length && !saved.length) return null
|
|
298
|
+
return h('div', { 'data-project-memory-turn': turn.turn },
|
|
299
|
+
saved.length ? h(Saved, { ctl, items: saved, readOnly: view.context?.readOnly, memoryEnabled: view.memoryEnabled }) : null,
|
|
300
|
+
current.map(p => p.state === 'pending' ? h(Card, { key: p.id, ctl, proposal: p, rules: view.rules, memoryEnabled: view.memoryEnabled })
|
|
301
|
+
: h(Receipt, { key: p.id, proposal: p, rules: view.rules, memoryEnabled: view.memoryEnabled })))
|
|
302
|
+
}
|
|
303
|
+
// Small monochrome interface glyphs inherit the host palette and text size.
|
|
304
|
+
function memoryIcon(name) {
|
|
305
|
+
return h('span', { className: 'dpm-icon dpm-icon-' + name, 'aria-hidden': true })
|
|
306
|
+
}
|
|
307
|
+
const managerCss = `
|
|
308
|
+
.dpm-settings {
|
|
309
|
+
--dpm-ink: var(--dsw-alias-label-primary, CanvasText);
|
|
310
|
+
--dpm-muted: var(--dsw-alias-label-tertiary, GrayText);
|
|
311
|
+
--dpm-line: var(--dsw-alias-border-l2, color-mix(in srgb, CanvasText 14%, Canvas));
|
|
312
|
+
--dpm-soft: var(--dsw-alias-bg-module-platform, color-mix(in srgb, CanvasText 5%, Canvas));
|
|
313
|
+
--dpm-hover: var(--dsw-alias-interactive-bg-hover, color-mix(in srgb, CanvasText 9%, Canvas));
|
|
314
|
+
--dpm-surface: var(--dsw-alias-bg-layer-2, Canvas);
|
|
315
|
+
--dpm-primary: var(--dsw-alias-brand-primary, CanvasText);
|
|
316
|
+
--dpm-on-primary: var(--dsw-alias-label-primary-inverted, Canvas);
|
|
317
|
+
--dpm-danger: var(--dsw-alias-state-error-primary, light-dark(#a13635, #ffada7));
|
|
318
|
+
--dpm-divider: var(--dsh-hairline-width, 1px) solid var(--dpm-line);
|
|
319
|
+
--dpm-radius: var(--dsw-radius-md, 12px);
|
|
320
|
+
--dpm-radius-sm: var(--dsw-radius-sm, 8px);
|
|
321
|
+
min-width: 0;
|
|
322
|
+
color: var(--dpm-ink);
|
|
323
|
+
font: inherit;
|
|
324
|
+
font-size: 14px;
|
|
325
|
+
line-height: 22px;
|
|
326
|
+
container-type: inline-size;
|
|
327
|
+
}
|
|
328
|
+
.dpm-manager, .dpm-pane, .dpm-manage {width:100%;min-width:0}
|
|
329
|
+
.dpm-manager *, .dpm-manager *::before, .dpm-manager *::after {box-sizing:border-box}
|
|
330
|
+
.dpm-manager :is(h2,h3,h4,p,ul) {margin:0}
|
|
331
|
+
.dpm-manager ul {list-style:none;padding:0}
|
|
332
|
+
.dpm-manager :is(button,summary,input,select,textarea) {font:inherit;color:inherit}
|
|
333
|
+
.dpm-manager button, .dpm-manager summary, .dpm-manager select {cursor:pointer}
|
|
334
|
+
.dpm-manager button {
|
|
335
|
+
display:inline-flex;align-items:center;justify-content:center;gap:6px;min-height:32px;padding:4px 11px;
|
|
336
|
+
border:0;border-radius:var(--dpm-radius-sm);background:var(--dpm-soft);font-size:13px;line-height:20px;
|
|
337
|
+
}
|
|
338
|
+
.dpm-manager :is(button,input,select,textarea,summary):focus-visible {
|
|
339
|
+
outline:2px solid var(--dsw-alias-border-selected, currentColor);outline-offset:2px;
|
|
340
|
+
}
|
|
341
|
+
.dpm-manager button:disabled, .dpm-manager input:disabled {opacity:.5;cursor:default}
|
|
342
|
+
.dpm-manager :is(.dpm-primary,[data-memory-card] button[value=accept]) {
|
|
343
|
+
background:var(--dpm-primary);color:var(--dpm-on-primary);
|
|
344
|
+
}
|
|
345
|
+
.dpm-manager .dpm-danger, .dpm-manager [role=alert] {color:var(--dpm-danger)}
|
|
346
|
+
.dpm-manager [role=alert] {font-size:13px}
|
|
347
|
+
.dpm-manager select, .dpm-manager textarea, .dpm-manager [data-memory-card] input:not([type=checkbox]) {
|
|
348
|
+
min-width:0;max-width:100%;padding:6px 10px;border:var(--dpm-divider);border-radius:var(--dpm-radius-sm);
|
|
349
|
+
background:var(--dpm-surface);color:var(--dpm-ink);
|
|
350
|
+
}
|
|
351
|
+
.dpm-setting-row {
|
|
352
|
+
display:flex;align-items:center;justify-content:space-between;gap:16px;
|
|
353
|
+
padding:16px 0;border-bottom:var(--dpm-divider);
|
|
354
|
+
}
|
|
355
|
+
.dpm-setting-copy {flex:1;min-width:0}
|
|
356
|
+
.dpm-setting-title, .dpm-text {display:block;font-size:14px;font-weight:400;line-height:22px}
|
|
357
|
+
.dpm-setting-desc, .dpm-muted, .dpm-meta {
|
|
358
|
+
color:var(--dpm-muted);font-size:12px;line-height:18px;overflow-wrap:anywhere;
|
|
359
|
+
}
|
|
360
|
+
.dpm-setting-desc {display:block;margin-top:4px}
|
|
361
|
+
.dpm-comparison {display:grid;gap:8px;padding-block:10px}
|
|
362
|
+
.dpm-comparison label {display:flex;align-items:baseline;gap:8px;cursor:pointer}
|
|
363
|
+
.dpm-comparison input {flex:none}
|
|
364
|
+
.dpm-pane {padding-top:20px}
|
|
365
|
+
.dpm-records-head {display:flex;align-items:center;justify-content:space-between;gap:12px}
|
|
366
|
+
.dpm-pane h3 {font-size:15px;font-weight:600;line-height:24px}
|
|
367
|
+
:is(.dpm-setting-row,.dpm-records-head):has(.dpm-scope-select) {position:relative}
|
|
368
|
+
:is(.dpm-setting-row,.dpm-records-head):has(.dpm-scope-select)::after {
|
|
369
|
+
content:"";position:absolute;inset-inline-end:14px;top:50%;width:7px;height:7px;
|
|
370
|
+
border-right:1.25px solid var(--dpm-muted);border-bottom:1.25px solid var(--dpm-muted);
|
|
371
|
+
transform:translateY(-75%) rotate(45deg);pointer-events:none;
|
|
372
|
+
}
|
|
373
|
+
.dpm-manager select.dpm-scope-select {
|
|
374
|
+
appearance:none;field-sizing:content;flex:0 1 auto;width:auto;min-width:min(6rem,48%);max-width:48%;
|
|
375
|
+
height:36px;padding-inline:14px 36px;
|
|
376
|
+
border:0;border-radius:var(--dpm-radius);background-color:var(--dpm-soft);text-overflow:ellipsis;
|
|
377
|
+
}
|
|
378
|
+
.dpm-setting-row:has(.dpm-switch:disabled) .dpm-setting-title {color:var(--dpm-muted)}
|
|
379
|
+
.dpm-manager .dpm-switch {
|
|
380
|
+
appearance:none;position:relative;flex:none;width:40px;height:24px;margin:0;padding:0;border:0;
|
|
381
|
+
border-radius:12px;background:var(--dsw-alias-border-l4, GrayText);
|
|
382
|
+
}
|
|
383
|
+
.dpm-manager .dpm-switch:enabled {cursor:pointer}
|
|
384
|
+
.dpm-manager .dpm-switch::after {
|
|
385
|
+
content:"";position:absolute;inset-block-start:2px;inset-inline-start:2px;width:20px;height:20px;
|
|
386
|
+
border-radius:50%;background:var(--dsw-alias-switch-thumb, Canvas);
|
|
387
|
+
}
|
|
388
|
+
.dpm-manager .dpm-switch:checked {background:var(--dpm-primary)}
|
|
389
|
+
.dpm-manager .dpm-switch:checked::after {inset-inline-start:18px}
|
|
390
|
+
.dpm-manager > [role=status], .dpm-pane > :is([role=alert],[role=status]) {margin-block:16px}
|
|
391
|
+
.dpm-toolbar {padding:12px 0}
|
|
392
|
+
.dpm-search-wrap {position:relative;display:flex;align-items:center}
|
|
393
|
+
.dpm-search-wrap > .dpm-icon {position:absolute;inset-inline-start:12px;color:var(--dpm-muted);pointer-events:none}
|
|
394
|
+
.dpm-manager .dpm-search {
|
|
395
|
+
appearance:none;width:100%;min-width:0;height:36px;border:0;border-radius:var(--dpm-radius);
|
|
396
|
+
padding:7px 12px;padding-inline-start:38px;background:var(--dpm-soft);font-size:14px;line-height:22px;
|
|
397
|
+
}
|
|
398
|
+
.dpm-search::placeholder {color:var(--dpm-muted)}
|
|
399
|
+
.dpm-search::-webkit-search-cancel-button {display:none}
|
|
400
|
+
.dpm-search-wrap:has(.dpm-clear-search) .dpm-search {padding-inline-end:36px}
|
|
401
|
+
.dpm-search-wrap:has(.dpm-kbd) .dpm-search {padding-inline-end:54px}
|
|
402
|
+
.dpm-kbd {
|
|
403
|
+
position:absolute;inset-inline-end:10px;display:inline-flex;align-items:center;height:21px;padding:0 5px;
|
|
404
|
+
border:var(--dpm-divider);border-radius:5px;font:inherit;font-size:11px;color:var(--dpm-muted);pointer-events:none;
|
|
405
|
+
}
|
|
406
|
+
.dpm-search-wrap:focus-within .dpm-kbd {visibility:hidden}
|
|
407
|
+
.dpm-manager .dpm-clear-search {position:absolute;inset-inline-end:4px;width:28px;min-height:28px;padding:0;background:transparent}
|
|
408
|
+
.dpm-clear-search .dpm-icon {font-size:13px}
|
|
409
|
+
|
|
410
|
+
.dpm-section {padding-block-start:6px}
|
|
411
|
+
.dpm-section + .dpm-section {padding-block-start:18px}
|
|
412
|
+
.dpm-section-head {display:flex;align-items:baseline;gap:8px;padding-block:6px}
|
|
413
|
+
.dpm-section-head h4 {font-size:13px;font-weight:600;line-height:20px}
|
|
414
|
+
.dpm-section-head small {font-size:12px;color:var(--dpm-muted);font-variant-numeric:tabular-nums}
|
|
415
|
+
.dpm-row, .dpm-pending {padding:13px 0;border-bottom:var(--dpm-divider);overflow-wrap:anywhere}
|
|
416
|
+
.dpm-row-head, .dpm-pending-head {display:flex;align-items:flex-start;justify-content:space-between;gap:12px}
|
|
417
|
+
.dpm-row-copy {min-width:0;flex:1}
|
|
418
|
+
.dpm-text {white-space:pre-wrap;overflow-wrap:anywhere}
|
|
419
|
+
.dpm-row-copy .dpm-meta {margin-top:4px}
|
|
420
|
+
.dpm-tag {display:inline-block;margin-inline-end:6px;padding:0 5px;border-radius:4px;background:var(--dpm-soft);font-size:11px}
|
|
421
|
+
.dpm-actions, .dpm-record-tools, .dpm-inline-tools {display:flex;flex-wrap:wrap;align-items:center;gap:4px}
|
|
422
|
+
.dpm-record-tools {flex:none;gap:2px}
|
|
423
|
+
.dpm-manager .dpm-tool {
|
|
424
|
+
min-height:30px;padding:4px 6px;background:transparent;color:var(--dsw-alias-label-secondary, var(--dpm-muted));
|
|
425
|
+
font-size:12px;white-space:nowrap;
|
|
426
|
+
}
|
|
427
|
+
.dpm-manager .dpm-icon-button {width:30px}
|
|
428
|
+
.dpm-manager :is(.dpm-tool[aria-expanded=true],.dpm-pending-toggle) {color:var(--dpm-ink);background:var(--dpm-soft)}
|
|
429
|
+
.dpm-extra, .dpm-editor, .dpm-inline-tools, .dpm-pending-body {
|
|
430
|
+
margin-top:10px;padding:12px;border-radius:var(--dpm-radius-sm);background:var(--dpm-soft);font-size:13px;
|
|
431
|
+
}
|
|
432
|
+
.dpm-inline-tools {padding:6px}
|
|
433
|
+
.dpm-extra p+p, .dpm-extra .dpm-actions, .dpm-extra .dpm-meta {margin-top:6px}
|
|
434
|
+
.dpm-extra blockquote {margin:8px 0;padding-inline:12px;border-inline-start:2px solid var(--dpm-muted);white-space:pre-wrap}
|
|
435
|
+
.dpm-extra code {font-size:12px;overflow-wrap:anywhere}
|
|
436
|
+
.dpm-source-footer {margin-top:6px}
|
|
437
|
+
.dpm-editor label {display:block;margin-bottom:8px}
|
|
438
|
+
.dpm-manager textarea {display:block;width:100%;resize:vertical;min-height:60px;margin-top:4px}
|
|
439
|
+
.dpm-manager fieldset {min-inline-size:0}
|
|
440
|
+
.dpm-manager [data-memory-card] {font-size:13px;overflow-wrap:anywhere}
|
|
441
|
+
.dpm-manager [data-memory-card] fieldset {border:var(--dpm-divider);border-radius:var(--dpm-radius-sm)}
|
|
442
|
+
.dpm-manager [data-memory-card] :is(input:not([type=checkbox]),select) {width:100%}
|
|
443
|
+
.dpm-manager [data-memory-card] input[type=checkbox] {accent-color:var(--dpm-primary)}
|
|
444
|
+
.dpm-mark {padding:0 1px;border-radius:2px;background:var(--dpm-hover);color:inherit;font-weight:600}
|
|
445
|
+
|
|
446
|
+
.dpm-empty {
|
|
447
|
+
display:grid;justify-items:center;align-content:center;gap:6px;min-height:160px;padding:24px 8px;text-align:center;
|
|
448
|
+
}
|
|
449
|
+
.dpm-empty-icon {
|
|
450
|
+
display:grid;place-items:center;width:36px;height:36px;margin-bottom:4px;border-radius:var(--dpm-radius);
|
|
451
|
+
background:var(--dpm-soft);color:var(--dpm-muted);
|
|
452
|
+
}
|
|
453
|
+
.dpm-empty-icon .dpm-icon {font-size:18px}
|
|
454
|
+
.dpm-empty-title {font-size:14px;line-height:22px;font-weight:500}
|
|
455
|
+
.dpm-empty-copy {max-width:34rem;color:var(--dpm-muted);font-size:12px;line-height:18px}
|
|
456
|
+
.dpm-empty-action {margin-top:6px}
|
|
457
|
+
.dpm-loading {display:flex;align-items:center;gap:8px;padding-block:18px;color:var(--dpm-muted);font-size:13px}
|
|
458
|
+
.dpm-spinner {
|
|
459
|
+
width:12px;height:12px;border:1.5px solid var(--dpm-line);border-top-color:var(--dpm-primary);
|
|
460
|
+
border-radius:50%;animation:dpm-spin .8s linear infinite;
|
|
461
|
+
}
|
|
462
|
+
@keyframes dpm-spin {to{transform:rotate(360deg)}}
|
|
463
|
+
@media (prefers-reduced-motion:reduce) {.dpm-spinner {animation:none}}
|
|
464
|
+
.dpm-toast {
|
|
465
|
+
position:sticky;bottom:12px;width:fit-content;max-width:100%;margin:8px auto 0;padding:6px 12px;
|
|
466
|
+
border-radius:var(--dpm-radius-sm);background:var(--dpm-primary);color:var(--dpm-on-primary);
|
|
467
|
+
overflow-wrap:anywhere;font-size:13px;line-height:20px;pointer-events:none;
|
|
468
|
+
}
|
|
469
|
+
@media (hover:hover) {
|
|
470
|
+
.dpm-manager button:enabled:hover, .dpm-manager .dpm-scope-select:hover, .dpm-manager summary:hover {background:var(--dpm-hover)}
|
|
471
|
+
.dpm-manager :is(.dpm-primary,[data-memory-card] button[value=accept]):enabled:hover {background:var(--dpm-primary);opacity:.88}
|
|
472
|
+
}
|
|
473
|
+
.dpm-icon{display:inline-grid;position:relative;width:1em;height:1em;flex:none;place-items:center;font-size:16px;line-height:1}
|
|
474
|
+
.dpm-icon::before,.dpm-icon::after{position:absolute;box-sizing:border-box}
|
|
475
|
+
.dpm-icon-global::before,.dpm-icon-global::after{content:"";border:1.5px solid;border-radius:50%}
|
|
476
|
+
.dpm-icon-global::before{inset:1px;background:linear-gradient(currentColor,currentColor) center/100% 1px no-repeat}
|
|
477
|
+
.dpm-icon-global::after{inset:1px 30%}
|
|
478
|
+
.dpm-icon-project::before{content:"";inset:27% 1px 7%;border:1.5px solid;border-radius:2px 3px 3px 3px}
|
|
479
|
+
.dpm-icon-project::after{content:"";inset:12% 51% 72% 1px;border:1.5px solid;border-bottom:0;border-radius:2px 3px 0 0}
|
|
480
|
+
.dpm-icon-source::before{content:"";inset:4% 12%;border:1.5px solid;border-radius:2px}
|
|
481
|
+
.dpm-icon-source::after{content:"";width:38%;height:23%;border-block:1px solid;top:35%;left:31%}
|
|
482
|
+
.dpm-icon-edit::before{content:"";width:4px;height:12px;border:1.5px solid;border-radius:2px 2px 1px 1px;transform:rotate(40deg)}
|
|
483
|
+
.dpm-icon-edit::after{content:"";width:6px;bottom:1px;right:0;border-bottom:1.5px solid}
|
|
484
|
+
.dpm-icon-search::before{content:"";left:1px;top:1px;width:64%;height:64%;border:1.5px solid;border-radius:50%}
|
|
485
|
+
.dpm-icon-search::after{content:"";width:40%;bottom:22%;right:0;border-bottom:1.5px solid;transform:rotate(45deg)}
|
|
486
|
+
.dpm-icon-close::before,.dpm-icon-close::after{content:"";width:78%;border-top:1.5px solid;transform:rotate(45deg)}
|
|
487
|
+
.dpm-icon-close::after{transform:rotate(-45deg)}
|
|
488
|
+
.dpm-icon-more::before{content:"";width:3px;height:3px;background:currentColor;border-radius:50%;box-shadow:-5px 0,5px 0}
|
|
489
|
+
@container (max-width:380px) {
|
|
490
|
+
.dpm-setting-row {gap:10px}
|
|
491
|
+
.dpm-row-head {flex-wrap:wrap;gap:6px}
|
|
492
|
+
.dpm-row-copy {flex:1 1 10rem}
|
|
493
|
+
.dpm-record-tools {margin-inline-start:auto}
|
|
494
|
+
}
|
|
495
|
+
@container (max-width:260px) {
|
|
496
|
+
.dpm-setting-row:has(select) {align-items:stretch;flex-direction:column}
|
|
497
|
+
.dpm-setting-row:has(.dpm-scope-select)::after {top:calc(100% - 34px)}
|
|
498
|
+
.dpm-manager .dpm-setting-row select.dpm-scope-select {width:100%;max-width:100%}
|
|
499
|
+
}
|
|
500
|
+
@media (forced-colors:active) {
|
|
501
|
+
.dpm-manager .dpm-switch, .dpm-manager select.dpm-scope-select {appearance:auto}
|
|
502
|
+
.dpm-manager .dpm-switch::after, :is(.dpm-setting-row,.dpm-records-head):has(.dpm-scope-select)::after {display:none}
|
|
503
|
+
.dpm-toast {background:Canvas;color:CanvasText;border:1px solid}
|
|
504
|
+
}
|
|
505
|
+
`
|
|
506
|
+
const evidenceLabels = {
|
|
507
|
+
verified_user_quote: '已核验的用户原话',
|
|
508
|
+
retained_quote: '留存引文(未核验原始事件)',
|
|
509
|
+
confirmed_wording: '用户确认的表述',
|
|
510
|
+
manual: '用户手动表述',
|
|
511
|
+
edited: '编辑后的表述',
|
|
512
|
+
redacted: '已脱敏',
|
|
513
|
+
receipt: '操作回执',
|
|
514
|
+
}
|
|
515
|
+
const kindLabels = {
|
|
516
|
+
preference: '偏好',
|
|
517
|
+
rule: '规则',
|
|
518
|
+
fact: '事实',
|
|
519
|
+
episode: '经历',
|
|
520
|
+
reference: '参考资料',
|
|
521
|
+
runbook: '操作手册',
|
|
522
|
+
guard: '命令约束',
|
|
523
|
+
}
|
|
524
|
+
const proofLabels = {
|
|
525
|
+
anchored: '依据文件存在且未变更,内容为用户陈述',
|
|
526
|
+
unverified: '未经核验',
|
|
527
|
+
pointer: '来源指引',
|
|
528
|
+
observed_success: '已观察到成功执行',
|
|
529
|
+
user_reported: '用户报告',
|
|
530
|
+
user_confirmed: '用户已确认',
|
|
531
|
+
}
|
|
532
|
+
function uiError(e) {
|
|
533
|
+
return (
|
|
534
|
+
{
|
|
535
|
+
conflict: '条目版本已更新,请重新打开后再操作。',
|
|
536
|
+
read_only: '当前会话处于只读模式。',
|
|
537
|
+
unavailable: '当前会话不可访问。',
|
|
538
|
+
not_found: '该版本已撤回或失效,请刷新列表。',
|
|
539
|
+
memory_disabled: '记忆已关闭。请先在设置中启用记忆。',
|
|
540
|
+
invalid_input: '设置值无效,请检查后重试。',
|
|
541
|
+
}[e.message] || e.message
|
|
542
|
+
)
|
|
543
|
+
}
|
|
544
|
+
function KnowledgeDetail({ knowledge }) {
|
|
545
|
+
if (!knowledge) return null
|
|
546
|
+
const stages = { locate: '定位', diagnose: '诊断', repair: '修复', verify: '验证', basis: '依据' }
|
|
547
|
+
return h(
|
|
548
|
+
React.Fragment,
|
|
549
|
+
null,
|
|
550
|
+
knowledge.verification && h('p', null, proofLabels[knowledge.verification] || knowledge.verification),
|
|
551
|
+
knowledge.source && h('p', null, '参考来源:', knowledge.source),
|
|
552
|
+
knowledge.anchors?.length
|
|
553
|
+
? h(
|
|
554
|
+
'ul',
|
|
555
|
+
{ 'aria-label': '文件依据' },
|
|
556
|
+
knowledge.anchors.map((a) =>
|
|
557
|
+
h(
|
|
558
|
+
'li',
|
|
559
|
+
{ key: a.path + ':' + (a.symbol || '') },
|
|
560
|
+
h('code', null, a.path),
|
|
561
|
+
a.symbol ? ' · ' + a.symbol : '',
|
|
562
|
+
a.digest &&
|
|
563
|
+
h('span', { className: 'dpm-muted', title: a.digest }, ' · ', a.digest.slice(0, 12)),
|
|
564
|
+
),
|
|
565
|
+
),
|
|
566
|
+
)
|
|
567
|
+
: null,
|
|
568
|
+
knowledge.match &&
|
|
569
|
+
h('p', null, '适用命令:', h('code', null, knowledge.match.command), ' · ', knowledge.match.workdir),
|
|
570
|
+
knowledge.steps &&
|
|
571
|
+
h(
|
|
572
|
+
'dl',
|
|
573
|
+
null,
|
|
574
|
+
Object.entries(stages)
|
|
575
|
+
.filter(([key]) => knowledge.steps[key])
|
|
576
|
+
.map(([key, name]) =>
|
|
577
|
+
h(React.Fragment, { key }, h('dt', null, name), h('dd', null, knowledge.steps[key])),
|
|
578
|
+
),
|
|
579
|
+
),
|
|
580
|
+
knowledge.proof &&
|
|
581
|
+
h('p', null, '成功执行:', h('code', null, knowledge.proof.command), ' · ', knowledge.proof.workdir),
|
|
582
|
+
)
|
|
583
|
+
}
|
|
584
|
+
function RuleDetail({ data }) {
|
|
585
|
+
const source = data.source
|
|
586
|
+
return h(
|
|
587
|
+
'div',
|
|
588
|
+
{ className: 'dpm-extra' },
|
|
589
|
+
h('strong', null, evidenceLabels[data.evidence] || (data.quote ? '来源摘录' : '来源')),
|
|
590
|
+
data.quote ? h('blockquote', null, data.quote) : h('p', { className: 'dpm-muted' },
|
|
591
|
+
data.hasRetainedQuote ? '当前版本没有原话。历史版本或插件备份中仍有原话。' : '未保留原话。'),
|
|
592
|
+
source?.session_id &&
|
|
593
|
+
h(
|
|
594
|
+
'div',
|
|
595
|
+
{ className: 'dpm-meta' },
|
|
596
|
+
'会话 ',
|
|
597
|
+
source.session_id,
|
|
598
|
+
source.turn == null ? '' : ' · 第 ' + source.turn + ' 轮',
|
|
599
|
+
),
|
|
600
|
+
data.exceptions && h('div', null, '例外:', data.exceptions),
|
|
601
|
+
data.localException &&
|
|
602
|
+
h('div', null, '本机例外:', data.localException.environment, ' · ', data.localException.scope),
|
|
603
|
+
h(KnowledgeDetail, { knowledge: data.knowledge }),
|
|
604
|
+
h('div', { className: 'dpm-meta' }, data.id, '@', String(data.rev)),
|
|
605
|
+
)
|
|
606
|
+
}
|
|
607
|
+
function SourcePanel({ rule, ctl, readOnly, clear }) {
|
|
608
|
+
const [loaded, setLoaded] = useState()
|
|
609
|
+
useEffect(() => {
|
|
610
|
+
const abort = new AbortController()
|
|
611
|
+
ctl.call('manage', { op: 'source', args: { id: rule.id, rev: rule.rev } }, abort.signal)
|
|
612
|
+
.then(({ result }) => {
|
|
613
|
+
if (result?.status) throw Error(result.status)
|
|
614
|
+
if (!abort.signal.aborted) setLoaded({ rule, result })
|
|
615
|
+
})
|
|
616
|
+
.catch(e => { if (!abort.signal.aborted) setLoaded({ rule, error: uiError(e) }) })
|
|
617
|
+
return () => abort.abort()
|
|
618
|
+
}, [ctl, rule])
|
|
619
|
+
if (loaded?.rule !== rule) return h('p', { className: 'dpm-muted' }, '正在读取来源…')
|
|
620
|
+
if (loaded.error) return h('p', { role: 'alert' }, loaded.error)
|
|
621
|
+
return h(React.Fragment, null, h(RuleDetail, { data: { ...rule, ...loaded.result } }),
|
|
622
|
+
loaded.result.hasRetainedQuote && !readOnly && h('button', { type: 'button', className: 'dpm-source-footer dpm-danger',
|
|
623
|
+
onClick: clear }, '清除来源原话'))
|
|
624
|
+
}
|
|
625
|
+
function ManageRow({ rule, ctl, readOnly, perform, reload, announce, query, memoryEnabled }) {
|
|
626
|
+
const [panel, setPanel] = useState('')
|
|
627
|
+
const [draft, setDraft] = useState(rule.action)
|
|
628
|
+
const [error, setError] = useState('')
|
|
629
|
+
const [busy, setBusy] = useState(false)
|
|
630
|
+
const ref = { id: rule.id, rev: rule.rev }
|
|
631
|
+
async function action(op) {
|
|
632
|
+
if (busy) return
|
|
633
|
+
setBusy(true)
|
|
634
|
+
setError('')
|
|
635
|
+
try {
|
|
636
|
+
const answer = await perform(op, { ...ref, ...(op === 'revise' ? { action: draft.trim() } : {}),
|
|
637
|
+
...(op === 'usage' ? { usage: rule.usage === 'proactive' ? 'on_demand' : 'proactive' } : {}) })
|
|
638
|
+
setPanel('')
|
|
639
|
+
announce(
|
|
640
|
+
answer?.status === 'pending'
|
|
641
|
+
? '修改已进入当前会话的待审记忆。'
|
|
642
|
+
: {
|
|
643
|
+
revise: '修改已保存。',
|
|
644
|
+
forget: '记忆已撤回。',
|
|
645
|
+
'clear-quote': '来源原话已清除。',
|
|
646
|
+
usage: '用途已更新。',
|
|
647
|
+
pin: '已置顶。',
|
|
648
|
+
unpin: '已取消置顶。',
|
|
649
|
+
}[op],
|
|
650
|
+
)
|
|
651
|
+
reload()
|
|
652
|
+
} catch (e) {
|
|
653
|
+
setError(uiError(e))
|
|
654
|
+
} finally {
|
|
655
|
+
setBusy(false)
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
function select(next) {
|
|
659
|
+
setError('')
|
|
660
|
+
if (next === panel) {
|
|
661
|
+
setPanel('')
|
|
662
|
+
return
|
|
663
|
+
}
|
|
664
|
+
if (next === 'edit') setDraft(rule.action)
|
|
665
|
+
setPanel(next)
|
|
666
|
+
}
|
|
667
|
+
const button = (text, click, disabled = false, cls) =>
|
|
668
|
+
h('button', { type: 'button', onClick: click, disabled: disabled || busy, className: cls }, text)
|
|
669
|
+
const tool = (name, icon, target, disabled = false, caption) =>
|
|
670
|
+
h('button', { type: 'button', className: caption ? 'dpm-tool' : 'dpm-tool dpm-icon-button', title: name, 'aria-label': name,
|
|
671
|
+
'aria-expanded': panel === target, disabled: busy || disabled, onClick: () => select(target) },
|
|
672
|
+
memoryIcon(icon), caption)
|
|
673
|
+
const condition = rule.when
|
|
674
|
+
const onDemand = rule.usage !== 'proactive'
|
|
675
|
+
const metadata = [rule.subject, rule.topic && topicLabel(rule.topic), condition, ...(rule.paths || []),
|
|
676
|
+
rule.pinned && !onDemand ? '已置顶' : '', onDemand ? '按需查阅' : '主动遵守',
|
|
677
|
+
!onDemand && memoryEnabled ? (rule.indexed ? '已选入索引' : '超出索引预算') : '',
|
|
678
|
+
rule.delivered ? '本会话已投递此版本' : '本会话尚未投递此版本'].filter(Boolean).join(' · ')
|
|
679
|
+
return h(
|
|
680
|
+
'li',
|
|
681
|
+
{ className: 'dpm-row', 'data-memory-rule': rule.id },
|
|
682
|
+
h('div', { className: 'dpm-row-head' },
|
|
683
|
+
h('div', { className: 'dpm-row-copy' },
|
|
684
|
+
h('span', { className: 'dpm-text' }, highlight(rule.action, query)),
|
|
685
|
+
h('p', { className: 'dpm-meta' },
|
|
686
|
+
h('span', { className: 'dpm-tag' }, kindLabels[rule.kind] || rule.kind), metadata)),
|
|
687
|
+
h('div', { className: 'dpm-record-tools' },
|
|
688
|
+
tool('查看来源', 'source', 'source', false, '来源'),
|
|
689
|
+
tool('编辑', 'edit', 'edit', readOnly),
|
|
690
|
+
tool('更多操作', 'more', 'more'))),
|
|
691
|
+
panel === 'more' && h('div', { className: 'dpm-inline-tools', role: 'group', 'aria-label': '更多操作' },
|
|
692
|
+
rule.canChangeUsage &&
|
|
693
|
+
button(onDemand ? '改为主动遵守' : '改为按需查阅', () => action('usage'), readOnly),
|
|
694
|
+
!onDemand && button(rule.pinned ? '取消置顶' : '置顶', () => action(rule.pinned ? 'unpin' : 'pin'), readOnly),
|
|
695
|
+
button('撤回', () => select('forget'), readOnly, 'dpm-danger')),
|
|
696
|
+
panel === 'source' && h(SourcePanel, { rule, ctl, readOnly, clear: () => select('clear-quote') }),
|
|
697
|
+
panel === 'edit' &&
|
|
698
|
+
h(
|
|
699
|
+
'form',
|
|
700
|
+
{
|
|
701
|
+
className: 'dpm-editor',
|
|
702
|
+
onSubmit: (e) => {
|
|
703
|
+
e.preventDefault()
|
|
704
|
+
void action('revise')
|
|
705
|
+
},
|
|
706
|
+
},
|
|
707
|
+
label(
|
|
708
|
+
'记忆内容',
|
|
709
|
+
h('textarea', {
|
|
710
|
+
value: draft,
|
|
711
|
+
required: true,
|
|
712
|
+
maxLength: 4096,
|
|
713
|
+
onChange: (e) => setDraft(e.target.value),
|
|
714
|
+
autoFocus: true,
|
|
715
|
+
}),
|
|
716
|
+
),
|
|
717
|
+
h(
|
|
718
|
+
'div',
|
|
719
|
+
{ className: 'dpm-actions' },
|
|
720
|
+
h(
|
|
721
|
+
'button',
|
|
722
|
+
{
|
|
723
|
+
type: 'submit',
|
|
724
|
+
className: 'dpm-primary',
|
|
725
|
+
disabled: busy || readOnly || !draft.trim() || draft.trim() === rule.action,
|
|
726
|
+
},
|
|
727
|
+
'保存修改',
|
|
728
|
+
),
|
|
729
|
+
button('取消', () => setPanel('')),
|
|
730
|
+
),
|
|
731
|
+
),
|
|
732
|
+
(panel === 'forget' || panel === 'clear-quote') &&
|
|
733
|
+
h(
|
|
734
|
+
'div',
|
|
735
|
+
{ className: 'dpm-extra' },
|
|
736
|
+
h(
|
|
737
|
+
'p',
|
|
738
|
+
null,
|
|
739
|
+
panel === 'forget'
|
|
740
|
+
? (rule.scope === 'profile'
|
|
741
|
+
? '撤回后,当前配置下的所有项目和会话都会停止使用这条记忆。'
|
|
742
|
+
: '撤回后,这个项目的所有会话都会停止使用这条记忆。')
|
|
743
|
+
: '清除该条目各版本及插件备份中保留的原话,保留记忆内容。',
|
|
744
|
+
),
|
|
745
|
+
h(
|
|
746
|
+
'div',
|
|
747
|
+
{ className: 'dpm-actions' },
|
|
748
|
+
button(panel === 'forget' ? '确认撤回' : '确认清除', () => action(panel), readOnly, 'dpm-danger'),
|
|
749
|
+
button('取消', () => setPanel('')),
|
|
750
|
+
),
|
|
751
|
+
),
|
|
752
|
+
error && h('p', { role: 'alert' }, error),
|
|
753
|
+
)
|
|
754
|
+
}
|
|
755
|
+
function WithheldRow({ rule, readOnly, perform, reload, announce, query }) {
|
|
756
|
+
const [expanded, setExpanded] = useState(false)
|
|
757
|
+
const [confirming, setConfirming] = useState(false)
|
|
758
|
+
const [busy, setBusy] = useState(false)
|
|
759
|
+
const [error, setError] = useState('')
|
|
760
|
+
const title = rule.action || '项目' + (kindLabels[rule.kind] || '记忆')
|
|
761
|
+
const preview = rule.quote ? rule.quote.slice(0, 80) : ''
|
|
762
|
+
async function withdraw() {
|
|
763
|
+
if (busy) return
|
|
764
|
+
setBusy(true)
|
|
765
|
+
setError('')
|
|
766
|
+
try {
|
|
767
|
+
await perform('forget', { id: rule.id, rev: rule.rev })
|
|
768
|
+
announce('记忆已撤回。')
|
|
769
|
+
reload()
|
|
770
|
+
} catch (e) { setError(uiError(e)) }
|
|
771
|
+
finally { setBusy(false) }
|
|
772
|
+
}
|
|
773
|
+
return h('li', {
|
|
774
|
+
className: 'dpm-row', 'data-invalid-memory': rule.id,
|
|
775
|
+
},
|
|
776
|
+
h('div', { className: 'dpm-row-head' },
|
|
777
|
+
h('div', { className: 'dpm-row-copy' },
|
|
778
|
+
h('span', { className: 'dpm-text' }, highlight(title, query)),
|
|
779
|
+
h('p', { className: 'dpm-meta' }, rule.reasonText || '当前无法核验这条记忆。'),
|
|
780
|
+
preview && h('p', { className: 'dpm-meta' }, '原话:「', preview, preview === rule.quote ? '」' : '…」')),
|
|
781
|
+
h('button', { type: 'button', className: 'dpm-tool', 'aria-expanded': expanded,
|
|
782
|
+
onClick: () => { setExpanded(!expanded); setConfirming(false) } }, '查看详情')),
|
|
783
|
+
expanded && h('div', { className: 'dpm-extra' },
|
|
784
|
+
rule.quote && preview !== rule.quote && h(React.Fragment, null, h('strong', null, '来源原话'), h('blockquote', null, rule.quote)),
|
|
785
|
+
rule.time != null && h('p', { className: 'dpm-muted' }, new Date(rule.time).toLocaleString()),
|
|
786
|
+
h('code', { className: 'dpm-meta' }, rule.id, '@', String(rule.rev)),
|
|
787
|
+
h('div', { className: 'dpm-actions' },
|
|
788
|
+
h('button', { type: 'button', className: 'dpm-danger', disabled: busy || readOnly,
|
|
789
|
+
onClick: () => confirming ? withdraw() : setConfirming(true) },
|
|
790
|
+
confirming ? '确认撤回' : '撤回'),
|
|
791
|
+
confirming && h('button', { type: 'button', disabled: busy, onClick: () => setConfirming(false) }, '取消'))),
|
|
792
|
+
error && h('p', { role: 'alert' }, error))
|
|
793
|
+
}
|
|
794
|
+
function Section({ title, label = title, items, render }) {
|
|
795
|
+
if (!items.length) return null
|
|
796
|
+
return h('section', { className: 'dpm-section', 'aria-label': label },
|
|
797
|
+
h('div', { className: 'dpm-section-head' }, h('h4', null, title), h('small', null, items.length)),
|
|
798
|
+
h('ul', null, items.map(render)))
|
|
799
|
+
}
|
|
800
|
+
// Search hits are marked in place, so a long rule stays readable in context.
|
|
801
|
+
function highlight(text, query) {
|
|
802
|
+
const value = String(text ?? '')
|
|
803
|
+
const words = [...new Set(String(query || '').trim().split(/\s+/).filter(Boolean))]
|
|
804
|
+
.sort((a, b) => b.length - a.length).slice(0, 8)
|
|
805
|
+
if (!words.length) return value
|
|
806
|
+
const pattern = words.map(word => word.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('|')
|
|
807
|
+
return value.split(new RegExp('(' + pattern + ')', 'gi')).map((part, index) => index % 2
|
|
808
|
+
? h('mark', { key: index, className: 'dpm-mark' }, part)
|
|
809
|
+
: part)
|
|
810
|
+
}
|
|
811
|
+
const shortcutKey = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform || navigator.userAgent)
|
|
812
|
+
? '⌘K' : 'Ctrl K'
|
|
813
|
+
// A pending batch stays scannable in the list; the full review form opens on demand.
|
|
814
|
+
function PendingSummary({ ctl, proposal, rules, readOnly, query, memoryEnabled }) {
|
|
815
|
+
const [open, setOpen] = useState(false)
|
|
816
|
+
const preview = proposal.items.slice(0, 2).map(item => item.action).join('、')
|
|
817
|
+
const meta = [proposal.items.length + ' 项', proposal.turnId != null ? '第 ' + proposal.turnId + ' 轮' : '', preview]
|
|
818
|
+
.filter(Boolean).join(' · ')
|
|
819
|
+
return h('li', { className: 'dpm-pending' },
|
|
820
|
+
h('div', { className: 'dpm-pending-head' },
|
|
821
|
+
h('div', { className: 'dpm-row-copy' },
|
|
822
|
+
h('span', { className: 'dpm-text' }, '审阅项目记忆'),
|
|
823
|
+
h('p', { className: 'dpm-meta dpm-pending-meta' }, highlight(meta, query))),
|
|
824
|
+
h('button', { type: 'button', className: 'dpm-tool dpm-pending-toggle', 'aria-expanded': open,
|
|
825
|
+
onClick: () => setOpen(value => !value) }, open ? '收起' : '处理')),
|
|
826
|
+
open && h('div', { className: 'dpm-pending-body' },
|
|
827
|
+
h('fieldset', { disabled: readOnly, style: { border: 0, margin: 0, padding: 0 } },
|
|
828
|
+
h(Card, { ctl, proposal, rules, memoryEnabled, inManager: true }))))
|
|
829
|
+
}
|
|
830
|
+
function SettingRow({ as = 'div', title, description, descriptionId, children }) {
|
|
831
|
+
return h(as, { className: 'dpm-setting-row' },
|
|
832
|
+
h('span', { className: 'dpm-setting-copy' },
|
|
833
|
+
h('span', { className: 'dpm-setting-title' }, title),
|
|
834
|
+
h('span', { className: 'dpm-setting-desc', id: descriptionId }, description)),
|
|
835
|
+
children)
|
|
836
|
+
}
|
|
837
|
+
function SettingSwitch({ title, description, checked, disabled, onChange }) {
|
|
838
|
+
const descriptionId = React.useId()
|
|
839
|
+
return h(SettingRow, { title, description, descriptionId },
|
|
840
|
+
h('input', { className: 'dpm-switch', type: 'checkbox', role: 'switch', 'aria-label': title,
|
|
841
|
+
'aria-describedby': descriptionId, checked, disabled, onChange: event => onChange(event.target.checked) }))
|
|
842
|
+
}
|
|
843
|
+
const consolidationOutcomes = {
|
|
844
|
+
duplicate: '发现疑似重复记忆', distinct: '两条记忆分别保留',
|
|
845
|
+
stale: '候选已变化,本次结果已跳过', failed: '模型请求未完成',
|
|
846
|
+
}
|
|
847
|
+
function ProfileSwitches({ ctl }) {
|
|
848
|
+
const settings = useSyncExternalStore(ctl.subscribe, ctl.getSnapshot)
|
|
849
|
+
const state = settings.consolidation
|
|
850
|
+
const [busy, setBusy] = useState(false)
|
|
851
|
+
const [error, setError] = useState('')
|
|
852
|
+
const disabled = busy || settings.readOnly
|
|
853
|
+
async function change(method, enabled) {
|
|
854
|
+
if (disabled || (method === 'set-consolidation' && !settings.memoryEnabled)) return
|
|
855
|
+
setBusy(true)
|
|
856
|
+
setError('')
|
|
857
|
+
try {
|
|
858
|
+
const updated = await ctl.call(method, { enabled })
|
|
859
|
+
ctl.refreshIfObserved(updated)
|
|
860
|
+
} catch (e) {
|
|
861
|
+
setError(uiError(e))
|
|
862
|
+
ctl.refreshIfObserved()
|
|
863
|
+
}
|
|
864
|
+
finally { setBusy(false) }
|
|
865
|
+
}
|
|
866
|
+
if (!settings.ready) return settings.error
|
|
867
|
+
? h('p', { role: 'alert' }, settings.error)
|
|
868
|
+
: h('p', { className: 'dpm-muted', role: 'status' }, '正在读取记忆设置…')
|
|
869
|
+
const last = state.lastRun
|
|
870
|
+
let description = '项目会话空闲时定期筛选不同会话留下的记忆。发现疑似重复时,请模型比较两条摘要,每个项目每小时最多一次。'
|
|
871
|
+
if (!settings.memoryEnabled) description = state.enabled
|
|
872
|
+
? '记忆已关闭,整理已暂停。重新启用记忆后将自动恢复。'
|
|
873
|
+
: '先启用记忆,即可开启跨会话整理。'
|
|
874
|
+
return h(React.Fragment, null,
|
|
875
|
+
h(SettingSwitch, { title: '启用记忆', description: '允许助手在对话中保存和使用记忆。关闭后,仍可在下方查看和管理已有记录。',
|
|
876
|
+
checked: settings.memoryEnabled, disabled, onChange: enabled => change('set-memory-enabled', enabled) }),
|
|
877
|
+
h(SettingSwitch, { title: '跨会话整理', description, checked: settings.memoryEnabled && state.enabled,
|
|
878
|
+
disabled: disabled || !settings.memoryEnabled, onChange: enabled => change('set-consolidation', enabled) }),
|
|
879
|
+
(last || state.lastScanAt || (settings.memoryEnabled && state.enabled)) && h('p', { className: 'dpm-meta' }, last
|
|
880
|
+
? '上次模型整理 · ' + new Date(last.at).toLocaleString() + ' · ' + consolidationOutcomes[last.outcome]
|
|
881
|
+
: state.lastScanAt ? '最近筛选 · ' + new Date(state.lastScanAt).toLocaleString() + ' · 尚无模型整理结果'
|
|
882
|
+
: '等待项目会话空闲后整理。'),
|
|
883
|
+
error && h('p', { role: 'alert' }, error))
|
|
884
|
+
}
|
|
885
|
+
function SuggestionRow({ pair, decide, readOnly }) {
|
|
886
|
+
const [keep, choose] = useState('')
|
|
887
|
+
const [busy, setBusy] = useState(false)
|
|
888
|
+
const name = React.useId()
|
|
889
|
+
async function submit(keepId) {
|
|
890
|
+
if (busy) return
|
|
891
|
+
setBusy(true)
|
|
892
|
+
try { await decide(pair, keepId) }
|
|
893
|
+
finally { setBusy(false) }
|
|
894
|
+
}
|
|
895
|
+
return h('li', { className: 'dpm-pending' },
|
|
896
|
+
h('div', { className: 'dpm-comparison', role: 'radiogroup', 'aria-label': '选择要保留的记忆' },
|
|
897
|
+
[pair.left, pair.right].map(rule => h('label', { key: rule.id },
|
|
898
|
+
h('input', { type: 'radio', name, value: rule.id, checked: keep === rule.id, disabled: readOnly || busy,
|
|
899
|
+
onChange: () => choose(rule.id) }),
|
|
900
|
+
h('span', { className: 'dpm-row-copy' },
|
|
901
|
+
h('strong', { className: 'dpm-text' }, [rule.subject, rule.topic].filter(Boolean).join(' · ')),
|
|
902
|
+
h('span', { className: 'dpm-text' }, rule.action),
|
|
903
|
+
h('span', { className: 'dpm-meta' }, [rule.usage === 'proactive' ? '主动遵守' : '按需查阅',
|
|
904
|
+
rule.when && '适用条件 ' + rule.when, rule.exceptions && '例外 ' + rule.exceptions, ...rule.paths].filter(Boolean).join(' · ')))))),
|
|
905
|
+
h('div', { style: actionStyle },
|
|
906
|
+
h('button', { type: 'button', disabled: !keep || readOnly || busy, onClick: () => submit(keep) }, '保留所选,撤回另一条'),
|
|
907
|
+
h('button', { type: 'button', disabled: readOnly || busy, onClick: () => submit(null) }, '两条都保留')))
|
|
908
|
+
}
|
|
909
|
+
function ManagerList({ ctl, live, scope, children }) {
|
|
910
|
+
const [query, setQuery] = useState('')
|
|
911
|
+
const [reply, setReply] = useState()
|
|
912
|
+
const [status, announce] = useState('')
|
|
913
|
+
const [version, setVersion] = useState(0)
|
|
914
|
+
const searchInput = React.useRef(null)
|
|
915
|
+
const text = query.trim()
|
|
916
|
+
const context = live.context
|
|
917
|
+
const global = scope === 'profile'
|
|
918
|
+
const heading = global ? '全局记忆' : '项目记忆'
|
|
919
|
+
const contextKey = JSON.stringify([scope, context.root, context.cwd, context.readOnly])
|
|
920
|
+
const clearSearch = () => { setQuery(''); announce(''); searchInput.current?.focus() }
|
|
921
|
+
useEffect(() => {
|
|
922
|
+
if (!status) return
|
|
923
|
+
const timer = setTimeout(() => announce(''), 4000)
|
|
924
|
+
return () => clearTimeout(timer)
|
|
925
|
+
}, [status])
|
|
926
|
+
const reload = () => {
|
|
927
|
+
setVersion(v => v + 1)
|
|
928
|
+
ctl.refreshIfObserved()
|
|
929
|
+
}
|
|
930
|
+
useEffect(() => {
|
|
931
|
+
const abort = new AbortController()
|
|
932
|
+
const timer = setTimeout(async () => {
|
|
933
|
+
try {
|
|
934
|
+
const [{ result, readOnly }, review] = await Promise.all([
|
|
935
|
+
ctl.call('manage', { op: text ? 'search' : 'list', scope, args: text ? { query: text } : {} }, abort.signal),
|
|
936
|
+
global || text ? { suggestions: [] } : ctl.call('consolidation-suggestions', { scope, root: context.root }, abort.signal),
|
|
937
|
+
])
|
|
938
|
+
if (!abort.signal.aborted) setReply({ result, suggestions: review.suggestions, readOnly, text, contextKey })
|
|
939
|
+
} catch (e) {
|
|
940
|
+
if (!abort.signal.aborted) setReply({ error: uiError(e), text, contextKey })
|
|
941
|
+
}
|
|
942
|
+
}, text ? 140 : 0)
|
|
943
|
+
return () => { clearTimeout(timer); abort.abort() }
|
|
944
|
+
}, [ctl, text, version, live.version, context])
|
|
945
|
+
async function perform(op, args) {
|
|
946
|
+
const { result } = await ctl.call('manage', { op, args })
|
|
947
|
+
if (['conflict', 'not_found', 'unavailable', 'read_only'].includes(result?.status))
|
|
948
|
+
throw Error(result.status)
|
|
949
|
+
return result
|
|
950
|
+
}
|
|
951
|
+
const current = reply?.text === text && reply.contextKey === contextKey
|
|
952
|
+
const data = current && reply.result
|
|
953
|
+
const error = current && reply.error
|
|
954
|
+
const readOnly = context.readOnly || reply?.readOnly
|
|
955
|
+
const suggestions = (current && reply.suggestions) || []
|
|
956
|
+
async function decide(pair, keepId) {
|
|
957
|
+
const ref = ({ id, rev }) => ({ id, rev })
|
|
958
|
+
const left = ref(pair.left), right = ref(pair.right)
|
|
959
|
+
try {
|
|
960
|
+
await ctl.call('decide-consolidation', { scope, root: context.root, left, right,
|
|
961
|
+
keep: keepId === null ? null : left.id === keepId ? left : right })
|
|
962
|
+
announce(keepId === null ? '已保留两条记忆。' : '已保留所选记忆,并撤回另一条。')
|
|
963
|
+
} catch (e) { announce(uiError(e)) }
|
|
964
|
+
reload()
|
|
965
|
+
}
|
|
966
|
+
// Rules carry their scope. Project review cards omit it on this wire format.
|
|
967
|
+
const inScope = row => (row.scope === 'profile' ? 'profile' : 'project') === scope
|
|
968
|
+
const rows = (data?.rules || []).filter(inScope)
|
|
969
|
+
const invalid = (data?.needs_review || []).filter(inScope)
|
|
970
|
+
const words = text.normalize('NFKC').toLocaleLowerCase().split(/\s+/u)
|
|
971
|
+
const pending = live.proposals.filter(p => {
|
|
972
|
+
if (p.state !== 'pending' || !inScope(p)) return false
|
|
973
|
+
const fields = ['待确认', heading, ...p.items.flatMap(item => [item.action, item.when, item.user_quote])]
|
|
974
|
+
const searchable = fields.join(' ').normalize('NFKC').toLocaleLowerCase()
|
|
975
|
+
return words.every(word => searchable.includes(word))
|
|
976
|
+
})
|
|
977
|
+
const rowProps = { ctl, perform, readOnly, reload, announce, query: text, memoryEnabled: live.memoryEnabled }
|
|
978
|
+
const withheld = (rule) => h(WithheldRow, { key: rule.id + '@' + rule.rev, rule, ...rowProps })
|
|
979
|
+
const noResults = !rows.length && !invalid.length && !pending.length && !suggestions.length
|
|
980
|
+
return h('div', { className: 'dpm-manage' },
|
|
981
|
+
h('div', { className: 'dpm-toolbar' },
|
|
982
|
+
h('div', { className: 'dpm-search-wrap' }, memoryIcon('search'),
|
|
983
|
+
h('input', { className: 'dpm-search', type: 'search', ref: searchInput,
|
|
984
|
+
placeholder: global ? '搜索全局记忆' : '搜索此项目的记忆', 'aria-label': '搜索记忆',
|
|
985
|
+
value: query, maxLength: 2048, onChange: e => { setQuery(e.target.value); announce('') } }),
|
|
986
|
+
!query && h('kbd', { className: 'dpm-kbd', 'aria-hidden': true }, shortcutKey),
|
|
987
|
+
query && h('button', { className: 'dpm-clear-search', type: 'button', 'aria-label': '清空搜索',
|
|
988
|
+
onClick: clearSearch }, memoryIcon('close')))),
|
|
989
|
+
children,
|
|
990
|
+
h('div', { className: 'dpm-list' },
|
|
991
|
+
error && h('p', { role: 'alert' }, error, ' ', h('button', { type: 'button', onClick: reload }, '重新加载')),
|
|
992
|
+
!data && !error && h('div', { className: 'dpm-loading', role: 'status' },
|
|
993
|
+
h('span', { className: 'dpm-spinner', 'aria-hidden': true }), '正在读取记忆…'),
|
|
994
|
+
data && h(React.Fragment, null,
|
|
995
|
+
h(Section, { title: '疑似重复', items: suggestions, render: pair => h(SuggestionRow, {
|
|
996
|
+
key: pair.left.id + '@' + pair.left.rev + '/' + pair.right.id + '@' + pair.right.rev, pair, decide, readOnly }) }),
|
|
997
|
+
h(Section, { title: '待确认', items: pending, render: proposal => h(PendingSummary, {
|
|
998
|
+
key: proposal.id, proposal, ctl, rules: live.rules.filter(inScope), readOnly, memoryEnabled: live.memoryEnabled, query: text }) }),
|
|
999
|
+
h(Section, { title: text ? '搜索结果' : '已保存', label: heading, items: rows,
|
|
1000
|
+
render: rule => h(ManageRow, { key: rule.id + '@' + rule.rev, rule, ...rowProps }) }),
|
|
1001
|
+
['已停用', '当前不适用'].map(title => h(Section, { key: title, title,
|
|
1002
|
+
items: invalid.filter(r => r.statusLabel === title), render: rule => withheld(rule) })),
|
|
1003
|
+
noResults && h('div', { className: 'dpm-empty', role: 'status' },
|
|
1004
|
+
h('span', { className: 'dpm-empty-icon' }, memoryIcon(text ? 'search' : global ? 'global' : 'project')),
|
|
1005
|
+
h('strong', { className: 'dpm-empty-title' }, text ? '没有匹配的记忆' : '还没有' + heading),
|
|
1006
|
+
(text || live.memoryEnabled) && h('p', { className: 'dpm-empty-copy' }, text
|
|
1007
|
+
? '换个关键词试试,或清除搜索查看全部记忆。'
|
|
1008
|
+
: global
|
|
1009
|
+
? '在对话里说「以后叫我小林」,就能在其他项目沿用这个称呼。'
|
|
1010
|
+
: '在此项目的对话中说「本项目提交前先运行测试」,保存后就会出现在这里。'),
|
|
1011
|
+
text && h('button', { type: 'button', className: 'dpm-empty-action', onClick: clearSearch }, '清除搜索')))),
|
|
1012
|
+
status && h('div', { className: 'dpm-toast', role: 'status', 'aria-live': 'polite' }, status))
|
|
1013
|
+
}
|
|
1014
|
+
function folderName(path) {
|
|
1015
|
+
return path?.split(/[/\\]/).filter(Boolean).pop() || path
|
|
1016
|
+
}
|
|
1017
|
+
// The host checks session visibility before returning a directory. Resolve only
|
|
1018
|
+
// while the settings page is mounted, in small batches, and abort on exit.
|
|
1019
|
+
function useDirectory(choices, controllerFor, retry) {
|
|
1020
|
+
const [directory, setDirectory] = useState(new Map())
|
|
1021
|
+
const key = JSON.stringify(choices.map(s => [s.id, s.cwd]).sort(([a], [b]) => a.localeCompare(b)))
|
|
1022
|
+
useEffect(() => {
|
|
1023
|
+
const abort = new AbortController()
|
|
1024
|
+
const sessions = JSON.parse(key)
|
|
1025
|
+
const contexts = new Map()
|
|
1026
|
+
async function load() {
|
|
1027
|
+
for (let i = 0; i < sessions.length && !abort.signal.aborted; i += 6) {
|
|
1028
|
+
await Promise.all(sessions.slice(i, i + 6).map(async ([id]) => {
|
|
1029
|
+
try {
|
|
1030
|
+
const ctx = await controllerFor(id).call('context', {}, abort.signal)
|
|
1031
|
+
contexts.set(id, ctx)
|
|
1032
|
+
} catch { /* A session can close or lose access while the manager is open. */ }
|
|
1033
|
+
}))
|
|
1034
|
+
if (!abort.signal.aborted) setDirectory(new Map(contexts))
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
void load()
|
|
1038
|
+
return () => abort.abort()
|
|
1039
|
+
}, [key, controllerFor, retry])
|
|
1040
|
+
return directory
|
|
1041
|
+
}
|
|
1042
|
+
function ProjectSessions({ sessions, selected, onSelect }) {
|
|
1043
|
+
if (sessions.length < 2) return null
|
|
1044
|
+
return h(SettingRow, { as: 'label', title: '使用会话', description: '按所选会话的工作目录和权限查看项目记忆。' },
|
|
1045
|
+
h('select', { className: 'dpm-scope-select', value: selected, 'aria-label': '使用会话',
|
|
1046
|
+
onChange: e => onSelect(e.target.value) }, sessions.map(({ session, context }) => h('option', { key: session.id, value: session.id },
|
|
1047
|
+
session.displayTitle || session.title || session.id,
|
|
1048
|
+
context.root !== context.cwd ? ' · ' + context.cwd : '',
|
|
1049
|
+
context.readOnly ? ' · 只读' : ''))))
|
|
1050
|
+
}
|
|
1051
|
+
function ScopeBrowser({ choices, controllerFor }) {
|
|
1052
|
+
const [openedFrom] = useState(() => (choices.find(s => s.retainedBy?.mainView) || choices[0]).id)
|
|
1053
|
+
const [selected, setSelected] = useState(null)
|
|
1054
|
+
const preferredSessions = React.useRef(new Map())
|
|
1055
|
+
const [retry, setRetry] = useState(0)
|
|
1056
|
+
const directory = useDirectory(choices, controllerFor, retry)
|
|
1057
|
+
const origin = choices.find(s => s.id === openedFrom) || choices[0]
|
|
1058
|
+
const chosen = choices.find(s => s.id === selected?.sessionId) || origin
|
|
1059
|
+
const ctl = controllerFor(chosen.id)
|
|
1060
|
+
const live = useSyncExternalStore(ctl.subscribe, ctl.getSnapshot)
|
|
1061
|
+
const context = live.context
|
|
1062
|
+
const selectedRoot = selected?.root
|
|
1063
|
+
const global = selected === null
|
|
1064
|
+
const projects = new Map()
|
|
1065
|
+
for (const session of choices) {
|
|
1066
|
+
const ctx = session.id === chosen.id && (live.ready || live.error) ? context : directory.get(session.id)
|
|
1067
|
+
if (!ctx?.root) continue
|
|
1068
|
+
if (!projects.has(ctx.root)) projects.set(ctx.root, [])
|
|
1069
|
+
projects.get(ctx.root).push({ session, context: ctx })
|
|
1070
|
+
}
|
|
1071
|
+
const roots = [...projects.keys()].sort((a, b) => folderName(a).localeCompare(folderName(b)) || a.localeCompare(b))
|
|
1072
|
+
const nameCounts = new Map()
|
|
1073
|
+
for (const root of roots) nameCounts.set(folderName(root), (nameCounts.get(folderName(root)) || 0) + 1)
|
|
1074
|
+
function chooseSession(root, sessionId) {
|
|
1075
|
+
preferredSessions.current.set(root, sessionId)
|
|
1076
|
+
setSelected({ root, sessionId })
|
|
1077
|
+
}
|
|
1078
|
+
function chooseProject(root) {
|
|
1079
|
+
const group = projects.get(root)
|
|
1080
|
+
const preferredId = preferredSessions.current.get(root)
|
|
1081
|
+
const preferred = group.find(entry => entry.session.id === preferredId)
|
|
1082
|
+
|| group.find(entry => entry.session.id === origin.id) || group[0]
|
|
1083
|
+
chooseSession(root, preferred.session.id)
|
|
1084
|
+
}
|
|
1085
|
+
const scopePicker = h('header', { className: 'dpm-records-head' }, h('h3', null, '记忆记录'),
|
|
1086
|
+
h('select', { className: 'dpm-scope-select', 'aria-label': '记忆范围', title: selectedRoot || '全局记忆', value: selectedRoot || '',
|
|
1087
|
+
onChange: event => event.target.value ? chooseProject(event.target.value) : setSelected(null) },
|
|
1088
|
+
h('option', { value: '' }, '全局记忆'),
|
|
1089
|
+
selectedRoot && !projects.has(selectedRoot) && h('option', { value: selectedRoot, disabled: true }, selectedRoot),
|
|
1090
|
+
roots.length > 0 && h('optgroup', { label: '项目' }, roots.map(root => {
|
|
1091
|
+
const name = folderName(root)
|
|
1092
|
+
return h('option', { key: root, value: root }, nameCounts.get(name) > 1 ? root : name)
|
|
1093
|
+
}))))
|
|
1094
|
+
let content
|
|
1095
|
+
if (live.error) {
|
|
1096
|
+
content = h('p', { role: 'alert' }, live.error, ' ', h('button', { type: 'button', onClick: () => {
|
|
1097
|
+
setRetry(v => v + 1); ctl.refresh()
|
|
1098
|
+
} }, '重新加载'))
|
|
1099
|
+
} else if (!live.ready) {
|
|
1100
|
+
content = h('p', { className: 'dpm-muted', role: 'status' }, '正在读取记忆…')
|
|
1101
|
+
} else if (!context) {
|
|
1102
|
+
content = h('p', { role: 'status' }, '无法读取此会话的记忆。请打开一个可访问的工作区会话。')
|
|
1103
|
+
} else if (!global && (selectedRoot !== context.root || selected.sessionId !== chosen.id)) {
|
|
1104
|
+
content = h('p', { role: 'status' }, '此会话的项目已更改。请重新选择记忆范围。')
|
|
1105
|
+
} else {
|
|
1106
|
+
const scope = global ? 'profile' : 'project'
|
|
1107
|
+
content = h(ManagerList, { key: JSON.stringify([scope, chosen.id, context.root, context.cwd]), ctl, live, scope },
|
|
1108
|
+
!global && h(ProjectSessions, { sessions: projects.get(selectedRoot) || [], selected: chosen.id,
|
|
1109
|
+
onSelect: sessionId => chooseSession(selectedRoot, sessionId) }),
|
|
1110
|
+
context.readOnly && h('p', { className: 'dpm-muted', role: 'status' }, '当前会话为只读。'))
|
|
1111
|
+
}
|
|
1112
|
+
return h(React.Fragment, null, scopePicker, content)
|
|
1113
|
+
}
|
|
1114
|
+
function MemorySettings({ useSessions, controllerFor, settings }) {
|
|
1115
|
+
const list = useSessions(state => state)
|
|
1116
|
+
const page = React.useRef(null)
|
|
1117
|
+
useEffect(() => {
|
|
1118
|
+
const dialog = page.current.closest('[role="dialog"]')
|
|
1119
|
+
function focusSearch(event) {
|
|
1120
|
+
if (!(event.metaKey || event.ctrlKey) || event.key.toLowerCase() !== 'k') return
|
|
1121
|
+
const input = page.current.querySelector('.dpm-search')
|
|
1122
|
+
if (!input) return
|
|
1123
|
+
event.preventDefault()
|
|
1124
|
+
input.focus()
|
|
1125
|
+
input.select()
|
|
1126
|
+
}
|
|
1127
|
+
dialog?.addEventListener('keydown', focusSearch)
|
|
1128
|
+
return () => dialog?.removeEventListener('keydown', focusSearch)
|
|
1129
|
+
}, [])
|
|
1130
|
+
const choices = list.ids.map(id => list.byId[id])
|
|
1131
|
+
.filter(session => session && session.origin !== 'subagent')
|
|
1132
|
+
.sort((a, b) => b.updatedAt - a.updatedAt)
|
|
1133
|
+
return h('div', { className: 'dpm-settings', ref: page },
|
|
1134
|
+
h('style', null, managerCss),
|
|
1135
|
+
h('div', { className: 'dpm-manager' }, h(ProfileSwitches, { ctl: settings }),
|
|
1136
|
+
h('section', { className: 'dpm-pane', 'aria-label': '记忆记录' }, choices.length ? h(ScopeBrowser, { choices, controllerFor })
|
|
1137
|
+
: h(React.Fragment, null, h('h3', null, '记忆记录'),
|
|
1138
|
+
h('p', { className: 'dpm-muted', role: 'status' }, list.phase === 'pending'
|
|
1139
|
+
? '正在读取本机会话…' : '请打开一个工作区会话以查看记忆记录。')))))
|
|
1140
|
+
}
|
|
1141
|
+
function MemorySettingsIcon({ size }) {
|
|
1142
|
+
const crossing = React.useId()
|
|
1143
|
+
// Match the packaged memory-icon.svg while inheriting the menu text color.
|
|
1144
|
+
return h('svg', { width: size, height: size, viewBox: '0 0 128 128', 'aria-hidden': true },
|
|
1145
|
+
h('defs', null, h('mask', { id: crossing, maskUnits: 'userSpaceOnUse', x: 0, y: 0, width: 128, height: 128 },
|
|
1146
|
+
h('rect', { width: 128, height: 128, fill: 'white' }),
|
|
1147
|
+
h('path', { d: 'M58 68.67 70 51.33', fill: 'none', stroke: 'black', strokeWidth: 16 }))),
|
|
1148
|
+
h('g', { mask: 'url(#' + crossing + ')' },
|
|
1149
|
+
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' }),
|
|
1150
|
+
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',
|
|
1151
|
+
fill: 'none', stroke: 'currentColor', strokeWidth: 11.5, strokeLinejoin: 'round' })),
|
|
1152
|
+
h('path', { d: 'M55 73 73 47', fill: 'none', stroke: 'currentColor', strokeWidth: 11.5 }))
|
|
1153
|
+
}
|
|
1154
|
+
function apply(ctx) {
|
|
1155
|
+
const sessions = new Map()
|
|
1156
|
+
const settings = controller(ctx.connection)
|
|
1157
|
+
// Both slots must claim the same review through the same session controller.
|
|
1158
|
+
// DSH may retain the injected binding after its component unmounts.
|
|
1159
|
+
function controllerFor(sessionId) {
|
|
1160
|
+
let ctl = sessions.get(sessionId)?.deref()
|
|
1161
|
+
if (!ctl) {
|
|
1162
|
+
for (const [key, ref] of sessions) if (!ref.deref()) sessions.delete(key)
|
|
1163
|
+
ctl = controller(ctx.connection, sessionId)
|
|
1164
|
+
sessions.set(sessionId, new WeakRef(ctl))
|
|
1165
|
+
}
|
|
1166
|
+
return ctl
|
|
1167
|
+
}
|
|
1168
|
+
const inject = sessionId => ({ ctl: controllerFor(sessionId) })
|
|
1169
|
+
for (const [name, id, component] of [
|
|
1170
|
+
['conversation.chat.turnTail', 'dsh-memory-bond/review', Tail],
|
|
1171
|
+
['conversation.session.header.utilities', 'dsh-memory-bond/inbox', Inbox],
|
|
1172
|
+
]) ctx.slots.inject(name, () => ctx.slots.register({ name, id, inject }, component))
|
|
1173
|
+
const section = 'dsh-memory-bond'
|
|
1174
|
+
ctx.effect(() => ctx.locale.register(section, { zh: { nav: '记忆' }, en: { nav: 'Memory' } }))
|
|
1175
|
+
const t = ctx.locale.bind(section)
|
|
1176
|
+
ctx.slots.inject('settings.section', () => ctx.slots.register({
|
|
1177
|
+
name: 'settings.section', id: section, order: 30, label: () => t('nav'), locale: section,
|
|
1178
|
+
inject: () => ({ controllerFor, settings }),
|
|
1179
|
+
}, MemorySettings))
|
|
1180
|
+
ctx.slots.inject('settings.section.icon', () => ctx.slots.register({
|
|
1181
|
+
name: 'settings.section.icon', id: section,
|
|
1182
|
+
}, MemorySettingsIcon))
|
|
1183
|
+
}
|
|
1184
|
+
return { inject: ['connection', 'slots', 'locale'], apply }
|
|
1185
|
+
},
|
|
1186
|
+
})
|