dsh-skill-pool 0.3.7 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRACTS-v3.md +129 -12
- package/README.md +173 -14
- package/client.js +341 -73
- package/index.js +58 -16
- package/package.json +8 -2
- package/src/activation.js +584 -115
- package/src/inventory.js +6 -1
- package/src/mount.js +9 -4
- package/src/rules.js +29 -0
- package/src/store.js +494 -28
- package/src/web-api.js +413 -69
package/client.js
CHANGED
|
@@ -70,6 +70,7 @@ window.__ModuleLoader__.load({
|
|
|
70
70
|
previewFailed: '解析失败',
|
|
71
71
|
rowModes: '模式',
|
|
72
72
|
rowWorkspaces: '工作区',
|
|
73
|
+
draftDiscarded: '以下未保存的修改因为对应资源已在别处删除而被丢弃;请先复制需要保留的内容:',
|
|
73
74
|
allModes: '全部模式',
|
|
74
75
|
allWorkspaces: '全部工作区',
|
|
75
76
|
editConditions: '设置条件',
|
|
@@ -210,8 +211,6 @@ window.__ModuleLoader__.load({
|
|
|
210
211
|
setEnabledHint: '关闭后完全不干预任何会话。',
|
|
211
212
|
setMcpGate: 'MCP 门控',
|
|
212
213
|
setMcpGateHint: '隐藏未命中条件的 MCP 工具。',
|
|
213
|
-
setInjectSummary: '注入资源摘要',
|
|
214
|
-
setInjectSummaryHint: '在系统提示中说明可用技能与 MCP。',
|
|
215
214
|
setGateDefaultSkills: '系统技能严格隐藏',
|
|
216
215
|
setGateDefaultSkillsHint: '暂未启用(系统技能始终可用)。',
|
|
217
216
|
stateFile: '状态文件',
|
|
@@ -272,6 +271,7 @@ window.__ModuleLoader__.load({
|
|
|
272
271
|
previewFailed: 'Resolve failed',
|
|
273
272
|
rowModes: 'Modes',
|
|
274
273
|
rowWorkspaces: 'Workspaces',
|
|
274
|
+
draftDiscarded: 'These unsaved edits were discarded because the matching resource was deleted elsewhere; copy anything you need to keep:',
|
|
275
275
|
allModes: 'All modes',
|
|
276
276
|
allWorkspaces: 'All workspaces',
|
|
277
277
|
editConditions: 'Conditions',
|
|
@@ -409,8 +409,6 @@ window.__ModuleLoader__.load({
|
|
|
409
409
|
setEnabledHint: 'Off leaves every session completely untouched.',
|
|
410
410
|
setMcpGate: 'MCP gate',
|
|
411
411
|
setMcpGateHint: 'Hide the tools of MCP servers that do not match.',
|
|
412
|
-
setInjectSummary: 'Inject resource summary',
|
|
413
|
-
setInjectSummaryHint: 'State the available skills and MCP servers in the system prompt.',
|
|
414
412
|
setGateDefaultSkills: 'Strictly hide system skills',
|
|
415
413
|
setGateDefaultSkillsHint: 'Not enabled yet (system skills are always available).',
|
|
416
414
|
stateFile: 'State file',
|
|
@@ -448,7 +446,6 @@ window.__ModuleLoader__.load({
|
|
|
448
446
|
const DEFAULT_SETTINGS = Object.freeze({
|
|
449
447
|
enabled: true,
|
|
450
448
|
mcpGate: true,
|
|
451
|
-
injectSummary: true,
|
|
452
449
|
gateDefaultSkills: false,
|
|
453
450
|
})
|
|
454
451
|
const EMPTY_INVENTORY = Object.freeze({
|
|
@@ -594,7 +591,7 @@ window.__ModuleLoader__.load({
|
|
|
594
591
|
|
|
595
592
|
function normalizeEntry(raw) {
|
|
596
593
|
const source = asObject(raw)
|
|
597
|
-
|
|
594
|
+
const entry = {
|
|
598
595
|
enabled: source.enabled !== false,
|
|
599
596
|
modes: asStringArray(source.modes),
|
|
600
597
|
workspaces: uniqueStrings(asArray(source.workspaces).map(normalizePath)),
|
|
@@ -604,6 +601,42 @@ window.__ModuleLoader__.load({
|
|
|
604
601
|
digest: asString(source.digest),
|
|
605
602
|
installedAt: asString(source.installedAt),
|
|
606
603
|
}
|
|
604
|
+
return entry
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
/** Build the `/item` request body for one pending row save. */
|
|
608
|
+
function buildItemSaveBody(job) {
|
|
609
|
+
const entry = asObject(job.entry)
|
|
610
|
+
return {
|
|
611
|
+
kind: job.kind,
|
|
612
|
+
name: job.name,
|
|
613
|
+
enabled: entry.enabled !== false,
|
|
614
|
+
modes: asStringArray(entry.modes),
|
|
615
|
+
workspaces: uniqueStrings(asArray(entry.workspaces).map(normalizePath)),
|
|
616
|
+
modesFrom: entry.modesFrom === 'self' ? 'self' : 'group',
|
|
617
|
+
workspacesFrom: entry.workspacesFrom === 'self' ? 'self' : 'group',
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
/**
|
|
622
|
+
* Parse the host's redacted re-application warning. Kept as a pure helper so
|
|
623
|
+
* the panel tests can assert it persists until explicitly dismissed.
|
|
624
|
+
*/
|
|
625
|
+
function activationWarningOf(payload) {
|
|
626
|
+
const warning = asObject(payload && payload.warning)
|
|
627
|
+
const message = asString(warning.message).trim()
|
|
628
|
+
if (message.length === 0) return null
|
|
629
|
+
return { code: asString(warning.code), message }
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
/** Merge a response warning without clearing an existing one on success. */
|
|
633
|
+
function mergeActivationWarning(current, payload) {
|
|
634
|
+
return activationWarningOf(payload) || current || null
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
/** An explicit close clears the banner; nothing time-based does. */
|
|
638
|
+
function dismissActivationWarning() {
|
|
639
|
+
return null
|
|
607
640
|
}
|
|
608
641
|
|
|
609
642
|
function normalizeSettings(raw) {
|
|
@@ -611,7 +644,6 @@ window.__ModuleLoader__.load({
|
|
|
611
644
|
return {
|
|
612
645
|
enabled: source.enabled !== false,
|
|
613
646
|
mcpGate: source.mcpGate !== false,
|
|
614
|
-
injectSummary: source.injectSummary !== false,
|
|
615
647
|
gateDefaultSkills: source.gateDefaultSkills === true,
|
|
616
648
|
}
|
|
617
649
|
}
|
|
@@ -890,6 +922,110 @@ window.__ModuleLoader__.load({
|
|
|
890
922
|
return { ...state, [key]: next }
|
|
891
923
|
}
|
|
892
924
|
|
|
925
|
+
/** Split a `kind:name` row key into its namespace and member name. */
|
|
926
|
+
function rowKeyOf(key) {
|
|
927
|
+
if (typeof key !== 'string') return null
|
|
928
|
+
if (key.startsWith('mcp:')) return { kind: MCP, name: key.slice(4) }
|
|
929
|
+
if (key.startsWith('skill:')) return { kind: 'skill', name: key.slice(6) }
|
|
930
|
+
return null
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
/** Whether the loaded document still contains this row. */
|
|
934
|
+
function hasLoadedMember(loadedState, key) {
|
|
935
|
+
const row = rowKeyOf(key)
|
|
936
|
+
if (row === null) return false
|
|
937
|
+
const bucket = row.kind === MCP ? loadedState.mcp : loadedState.skills
|
|
938
|
+
return bucket !== null && typeof bucket === 'object' && Object.hasOwn(bucket, row.name)
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
/**
|
|
942
|
+
* Drafts whose member is gone from the authoritative document.
|
|
943
|
+
*
|
|
944
|
+
* The panel surfaces these as a visible warning (with the unsaved text)
|
|
945
|
+
* instead of silently discarding them; they must never be rendered as rows.
|
|
946
|
+
*/
|
|
947
|
+
function orphanedDrafts(loadedState, drafts) {
|
|
948
|
+
const out = []
|
|
949
|
+
if (!drafts || typeof drafts[Symbol.iterator] !== 'function') return out
|
|
950
|
+
for (const [key, entry] of drafts) {
|
|
951
|
+
if (rowKeyOf(key) === null || entry === null || typeof entry !== 'object') continue
|
|
952
|
+
if (!hasLoadedMember(loadedState, key)) out.push({ key, entry })
|
|
953
|
+
}
|
|
954
|
+
return out
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
/**
|
|
958
|
+
* Overlay unsaved row drafts on a document loaded from the Host.
|
|
959
|
+
*
|
|
960
|
+
* A debounced/in-flight/failed save is a local draft that the server does
|
|
961
|
+
* not know yet; a GET response must not make the user's text disappear. A
|
|
962
|
+
* draft whose member is gone is skipped (never turned into a phantom row).
|
|
963
|
+
*/
|
|
964
|
+
function mergeRowDrafts(loadedState, drafts) {
|
|
965
|
+
let next = loadedState
|
|
966
|
+
if (!drafts || typeof drafts[Symbol.iterator] !== 'function') return next
|
|
967
|
+
for (const [key, entry] of drafts) {
|
|
968
|
+
const row = rowKeyOf(key)
|
|
969
|
+
if (row === null || entry === null || typeof entry !== 'object') continue
|
|
970
|
+
// Never resurrect a member the authoritative document no longer has:
|
|
971
|
+
// another tab may have deleted it while this draft was being typed.
|
|
972
|
+
if (!hasLoadedMember(loadedState, key)) continue
|
|
973
|
+
next = withEntry(next, row.kind, row.name, entry)
|
|
974
|
+
}
|
|
975
|
+
return next
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
/**
|
|
979
|
+
* Decide what a completed GET may replace.
|
|
980
|
+
*
|
|
981
|
+
* A load started at revision R may only apply its document when no local
|
|
982
|
+
* edit or save response landed meanwhile; otherwise it keeps the current
|
|
983
|
+
* rows and refreshes only the derived views. When the revision still
|
|
984
|
+
* matches, per-row drafts are merged over the server document so a
|
|
985
|
+
* failure-triggered reload cannot drop an unsaved edit.
|
|
986
|
+
*
|
|
987
|
+
* @param {object|null} current - board currently rendered.
|
|
988
|
+
* @param {{state: object, inventory: object, mounts: object, meta: object}} loaded - response.
|
|
989
|
+
* @param {{startedRevision: number, currentRevision: number, drafts: Map<string, object>}} options - race inputs.
|
|
990
|
+
* @returns {object} board to render.
|
|
991
|
+
*/
|
|
992
|
+
function applyLoadedBoard(current, loaded, options) {
|
|
993
|
+
if (!current) return loaded
|
|
994
|
+
const refreshed = { ...current, inventory: loaded.inventory, mounts: loaded.mounts, meta: loaded.meta }
|
|
995
|
+
if (options.startedRevision !== options.currentRevision) return refreshed
|
|
996
|
+
return { ...loaded, state: mergeRowDrafts(loaded.state, options.drafts) }
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
/**
|
|
1000
|
+
* Apply one save response to the current document.
|
|
1001
|
+
*
|
|
1002
|
+
* A save response is a snapshot from the moment that write completed; if the
|
|
1003
|
+
* member was deleted in another tab before the response was rendered, adding
|
|
1004
|
+
* it back would create a phantom row that every later save rejects with 400.
|
|
1005
|
+
*/
|
|
1006
|
+
function applyItemSave(currentState, kind, name, canonical) {
|
|
1007
|
+
const bucket = kind === MCP ? currentState.mcp : currentState.skills
|
|
1008
|
+
if (bucket === null || typeof bucket !== 'object' || !Object.hasOwn(bucket, name)) return currentState
|
|
1009
|
+
// No canonical member means no safe partial update; never fall back to the
|
|
1010
|
+
// response's whole document, which may still contain removed rows.
|
|
1011
|
+
return canonical ? withEntry(currentState, kind, name, canonical) : currentState
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
/** Visible warning text for drafts that lost their member while unsaved. */
|
|
1015
|
+
function draftLossMessage(orphans) {
|
|
1016
|
+
const parts = orphans.map((orphan) => {
|
|
1017
|
+
const row = rowKeyOf(orphan.key)
|
|
1018
|
+
const entry = asObject(orphan.entry)
|
|
1019
|
+
const text = JSON.stringify({
|
|
1020
|
+
enabled: entry.enabled !== false,
|
|
1021
|
+
modes: asStringArray(entry.modes),
|
|
1022
|
+
workspaces: asStringArray(entry.workspaces),
|
|
1023
|
+
})
|
|
1024
|
+
return `${row ? row.name : orphan.key}: ${text}`
|
|
1025
|
+
})
|
|
1026
|
+
return `${TEXT.draftDiscarded} ${parts.join(' | ')}`
|
|
1027
|
+
}
|
|
1028
|
+
|
|
893
1029
|
function summarizeList(values, allLabel, labeler, limit) {
|
|
894
1030
|
const list = asStringArray(values)
|
|
895
1031
|
if (list.length === 0) return allLabel
|
|
@@ -1056,6 +1192,20 @@ window.__ModuleLoader__.load({
|
|
|
1056
1192
|
padding: '7px 10px',
|
|
1057
1193
|
fontSize: '13px',
|
|
1058
1194
|
},
|
|
1195
|
+
activationWarning: {
|
|
1196
|
+
border: '1px solid var(--rp-warn, var(--dsw-alias-state-warn-primary))',
|
|
1197
|
+
background: 'var(--rp-card)',
|
|
1198
|
+
color: 'var(--rp-warn, var(--dsw-alias-state-warn-primary))',
|
|
1199
|
+
borderRadius: '8px',
|
|
1200
|
+
padding: '7px 10px',
|
|
1201
|
+
fontSize: '13px',
|
|
1202
|
+
lineHeight: 1.5,
|
|
1203
|
+
wordBreak: 'break-word',
|
|
1204
|
+
display: 'flex',
|
|
1205
|
+
alignItems: 'center',
|
|
1206
|
+
justifyContent: 'space-between',
|
|
1207
|
+
gap: '10px',
|
|
1208
|
+
},
|
|
1059
1209
|
noticeText: { fontSize: '13px', color: 'var(--dsw-alias-state-success-primary)', alignSelf: 'center' },
|
|
1060
1210
|
empty: { fontSize: '13px', color: 'var(--dsw-alias-label-secondary)', padding: '14px 4px', lineHeight: 1.6 },
|
|
1061
1211
|
loadingRow: { fontSize: '13px', color: 'var(--dsw-alias-label-secondary)' },
|
|
@@ -2061,6 +2211,7 @@ window.__ModuleLoader__.load({
|
|
|
2061
2211
|
const [loading, setLoading] = useState(true)
|
|
2062
2212
|
const [error, setError] = useState('')
|
|
2063
2213
|
const [notice, setNotice] = useState('')
|
|
2214
|
+
const [activationWarning, setActivationWarning] = useState(null)
|
|
2064
2215
|
const [tab, setTab] = useState('resources')
|
|
2065
2216
|
const [expanded, setExpanded] = useState({})
|
|
2066
2217
|
const [groupOpen, setGroupOpen] = useState({})
|
|
@@ -2078,6 +2229,11 @@ window.__ModuleLoader__.load({
|
|
|
2078
2229
|
const mounted = useRef(true)
|
|
2079
2230
|
const loadingRef = useRef(false)
|
|
2080
2231
|
const pendingRef = useRef(new Map())
|
|
2232
|
+
const editSeqRef = useRef(new Map())
|
|
2233
|
+
const writeChainsRef = useRef(new Map())
|
|
2234
|
+
const draftsRef = useRef(new Map())
|
|
2235
|
+
const removingRef = useRef(new Set())
|
|
2236
|
+
const boardRevisionRef = useRef(0)
|
|
2081
2237
|
const timersRef = useRef(new Map())
|
|
2082
2238
|
const groupTimersRef = useRef(new Map())
|
|
2083
2239
|
const noticeTimer = useRef(null)
|
|
@@ -2093,6 +2249,10 @@ window.__ModuleLoader__.load({
|
|
|
2093
2249
|
for (const timer of timersRef.current.values()) clearTimeout(timer)
|
|
2094
2250
|
timersRef.current.clear()
|
|
2095
2251
|
pendingRef.current.clear()
|
|
2252
|
+
editSeqRef.current.clear()
|
|
2253
|
+
writeChainsRef.current.clear()
|
|
2254
|
+
draftsRef.current.clear()
|
|
2255
|
+
removingRef.current.clear()
|
|
2096
2256
|
if (noticeTimer.current) clearTimeout(noticeTimer.current)
|
|
2097
2257
|
}
|
|
2098
2258
|
}, [])
|
|
@@ -2107,6 +2267,17 @@ window.__ModuleLoader__.load({
|
|
|
2107
2267
|
}, 3200)
|
|
2108
2268
|
}, [])
|
|
2109
2269
|
|
|
2270
|
+
/**
|
|
2271
|
+
* A successful write can still leave live sessions on their previous
|
|
2272
|
+
* gate (the host keeps the committed state). Show the server's redacted
|
|
2273
|
+
* warning instead of silently claiming every session was updated.
|
|
2274
|
+
*/
|
|
2275
|
+
const surfaceWarning = useCallback((payload) => {
|
|
2276
|
+
// Persistent and closable: a re-application failure must stay visible
|
|
2277
|
+
// even after the next successful request and beyond the 3.2s toast.
|
|
2278
|
+
setActivationWarning((current) => mergeActivationWarning(current, payload))
|
|
2279
|
+
}, [])
|
|
2280
|
+
|
|
2110
2281
|
const setBusyKey = useCallback((key, value) => {
|
|
2111
2282
|
const name = asString(key)
|
|
2112
2283
|
if (name.length === 0) return
|
|
@@ -2159,46 +2330,68 @@ window.__ModuleLoader__.load({
|
|
|
2159
2330
|
}
|
|
2160
2331
|
pendingRef.current.delete(key)
|
|
2161
2332
|
markSaving(key, true)
|
|
2162
|
-
const
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
workspaces: uniqueStrings(asArray(entry.workspaces).map(normalizePath)),
|
|
2172
|
-
modesFrom: entry.modesFrom === 'self' ? 'self' : 'group',
|
|
2173
|
-
workspacesFrom: entry.workspacesFrom === 'self' ? 'self' : 'group',
|
|
2174
|
-
},
|
|
2175
|
-
})
|
|
2333
|
+
const sequence = editSeqRef.current.get(key) ?? 0
|
|
2334
|
+
// Snapshot the request body now. A condition edit made *after* this
|
|
2335
|
+
// flush must travel with the newer queued save, never be squeezed into
|
|
2336
|
+
// this older request (whose entry may not even contain it).
|
|
2337
|
+
const body = buildItemSaveBody(job)
|
|
2338
|
+
// One in-flight save per member: an older request must never land after
|
|
2339
|
+
// a newer one and restore the previous conditions.
|
|
2340
|
+
const previous = writeChainsRef.current.get(key) ?? Promise.resolve()
|
|
2341
|
+
const run = previous.then(async () => {
|
|
2176
2342
|
if (!mounted.current) return
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2343
|
+
try {
|
|
2344
|
+
const payload = await request(`${API}/item`, { method: 'POST', body })
|
|
2345
|
+
if (!mounted.current) return
|
|
2346
|
+
surfaceWarning(payload)
|
|
2347
|
+
// The user kept typing while this request was in flight: the local
|
|
2348
|
+
// draft is newer than this response, so never replace it.
|
|
2349
|
+
const currentSequence = editSeqRef.current.get(key) ?? 0
|
|
2350
|
+
if (currentSequence !== sequence) return
|
|
2351
|
+
draftsRef.current.delete(key)
|
|
2352
|
+
// Any GET that started before this save response carries older
|
|
2353
|
+
// rows; let it refresh the derived views but keep this state.
|
|
2354
|
+
boardRevisionRef.current += 1
|
|
2355
|
+
clearRowError(key)
|
|
2356
|
+
if (payload.state) {
|
|
2357
|
+
const nextState = normalizeState(payload.state)
|
|
2358
|
+
const canonical = job.kind === MCP ? nextState.mcp[job.name] : nextState.skills[job.name]
|
|
2359
|
+
setBoard((current) => {
|
|
2360
|
+
if (!current) return current
|
|
2361
|
+
const state = applyItemSave(current.state, job.kind, job.name, canonical)
|
|
2362
|
+
return state === current.state ? current : { ...current, state }
|
|
2363
|
+
})
|
|
2364
|
+
}
|
|
2365
|
+
} catch (cause) {
|
|
2366
|
+
if (mounted.current && (editSeqRef.current.get(key) ?? 0) === sequence) {
|
|
2367
|
+
setRowError(key, messageOf(cause))
|
|
2368
|
+
if (loadBoardRef.current) void loadBoardRef.current({ silent: true })
|
|
2369
|
+
}
|
|
2370
|
+
} finally {
|
|
2371
|
+
// A queued newer save keeps the row marked as saving until it lands.
|
|
2372
|
+
if (
|
|
2373
|
+
mounted.current &&
|
|
2374
|
+
!pendingRef.current.has(key) &&
|
|
2375
|
+
(editSeqRef.current.get(key) ?? 0) === sequence
|
|
2376
|
+
) {
|
|
2377
|
+
markSaving(key, false)
|
|
2378
|
+
}
|
|
2190
2379
|
}
|
|
2191
|
-
}
|
|
2192
|
-
|
|
2193
|
-
|
|
2380
|
+
})
|
|
2381
|
+
writeChainsRef.current.set(key, run.catch(() => {}))
|
|
2382
|
+
// The chain is already settled for later saves; an unexpected local
|
|
2383
|
+
// rendering error must not surface as an unhandled rejection.
|
|
2384
|
+
await run.catch(() => {})
|
|
2194
2385
|
},
|
|
2195
|
-
[clearRowError, markSaving, setRowError],
|
|
2386
|
+
[clearRowError, markSaving, setRowError, surfaceWarning],
|
|
2196
2387
|
)
|
|
2197
2388
|
|
|
2198
2389
|
const queueItem = useCallback(
|
|
2199
2390
|
(kind, name, entry) => {
|
|
2200
2391
|
const key = `${kind}:${name}`
|
|
2201
2392
|
pendingRef.current.set(key, { kind, name, entry })
|
|
2393
|
+
editSeqRef.current.set(key, (editSeqRef.current.get(key) ?? 0) + 1)
|
|
2394
|
+
boardRevisionRef.current += 1
|
|
2202
2395
|
const timer = timersRef.current.get(key)
|
|
2203
2396
|
if (timer) clearTimeout(timer)
|
|
2204
2397
|
markSaving(key, true)
|
|
@@ -2252,6 +2445,7 @@ window.__ModuleLoader__.load({
|
|
|
2252
2445
|
if (pendingRef.current.size > 0) await flushPending()
|
|
2253
2446
|
if (loadingRef.current) return
|
|
2254
2447
|
loadingRef.current = true
|
|
2448
|
+
const startedRevision = boardRevisionRef.current
|
|
2255
2449
|
if (!silent) {
|
|
2256
2450
|
setLoading(true)
|
|
2257
2451
|
setError('')
|
|
@@ -2259,20 +2453,39 @@ window.__ModuleLoader__.load({
|
|
|
2259
2453
|
try {
|
|
2260
2454
|
const payload = await request(API, { method: 'GET' })
|
|
2261
2455
|
if (!mounted.current) return
|
|
2262
|
-
const
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
state: nextState,
|
|
2267
|
-
inventory: nextInventory,
|
|
2268
|
-
mounts: nextMounts,
|
|
2456
|
+
const loaded = {
|
|
2457
|
+
state: normalizeState(payload.state),
|
|
2458
|
+
inventory: normalizeInventory(payload.inventory),
|
|
2459
|
+
mounts: normalizeMount(payload.mounts || payload.mount),
|
|
2269
2460
|
meta: asObject(payload.meta),
|
|
2270
|
-
}
|
|
2461
|
+
}
|
|
2462
|
+
const currentRevision = boardRevisionRef.current
|
|
2463
|
+
if (startedRevision === currentRevision) {
|
|
2464
|
+
// The authoritative document no longer has these rows. Never show
|
|
2465
|
+
// them again; surface their unsaved text instead of dropping it
|
|
2466
|
+
// silently.
|
|
2467
|
+
const orphans = orphanedDrafts(loaded.state, draftsRef.current)
|
|
2468
|
+
if (orphans.length > 0) {
|
|
2469
|
+
for (const orphan of orphans) {
|
|
2470
|
+
draftsRef.current.delete(orphan.key)
|
|
2471
|
+
}
|
|
2472
|
+
setError(draftLossMessage(orphans))
|
|
2473
|
+
}
|
|
2474
|
+
}
|
|
2475
|
+
setBoard((current) =>
|
|
2476
|
+
applyLoadedBoard(current, loaded, {
|
|
2477
|
+
startedRevision,
|
|
2478
|
+
currentRevision,
|
|
2479
|
+
drafts: draftsRef.current,
|
|
2480
|
+
}),
|
|
2481
|
+
)
|
|
2271
2482
|
if (!previewInitialized.current) {
|
|
2272
2483
|
previewInitialized.current = true
|
|
2273
2484
|
const mode =
|
|
2274
|
-
asString(
|
|
2275
|
-
|
|
2485
|
+
asString(loaded.inventory.defaultMode) ||
|
|
2486
|
+
(loaded.inventory.modes[0] && loaded.inventory.modes[0].id) ||
|
|
2487
|
+
''
|
|
2488
|
+
const cwd = (loaded.inventory.workspaces[0] && loaded.inventory.workspaces[0].path) || ''
|
|
2276
2489
|
setPreviewMode(mode)
|
|
2277
2490
|
setPreviewCwd(cwd)
|
|
2278
2491
|
}
|
|
@@ -2422,11 +2635,19 @@ window.__ModuleLoader__.load({
|
|
|
2422
2635
|
|
|
2423
2636
|
const updateEntry = useCallback(
|
|
2424
2637
|
(kind, name, patch) => {
|
|
2638
|
+
const key = `${kind}:${name}`
|
|
2639
|
+
// Once removal owns this row, later edits must not schedule a save that
|
|
2640
|
+
// could recreate it; the row is disappearing.
|
|
2641
|
+
if (removingRef.current.has(key)) return
|
|
2642
|
+
// The local draft is newer than the last rendered document (a save may
|
|
2643
|
+
// be debounced or in flight), so an edit must build on it instead of
|
|
2644
|
+
// dropping unsaved conditions.
|
|
2645
|
+
const draft = draftsRef.current.get(key)
|
|
2425
2646
|
const source =
|
|
2426
2647
|
kind === MCP
|
|
2427
2648
|
? boardRef.current && boardRef.current.state.mcp[name]
|
|
2428
2649
|
: boardRef.current && boardRef.current.state.skills[name]
|
|
2429
|
-
const base = source || blankEntry()
|
|
2650
|
+
const base = draft || source || blankEntry()
|
|
2430
2651
|
const next = {
|
|
2431
2652
|
...base,
|
|
2432
2653
|
enabled: typeof patch.enabled === 'boolean' ? patch.enabled : base.enabled,
|
|
@@ -2441,8 +2662,9 @@ window.__ModuleLoader__.load({
|
|
|
2441
2662
|
? patch.workspacesFrom
|
|
2442
2663
|
: base.workspacesFrom,
|
|
2443
2664
|
}
|
|
2665
|
+
draftsRef.current.set(key, next)
|
|
2444
2666
|
setBoard((current) => (current ? { ...current, state: withEntry(current.state, kind, name, next) } : current))
|
|
2445
|
-
clearRowError(
|
|
2667
|
+
clearRowError(key)
|
|
2446
2668
|
queueItem(kind, name, next)
|
|
2447
2669
|
},
|
|
2448
2670
|
[clearRowError, queueItem],
|
|
@@ -2451,19 +2673,36 @@ window.__ModuleLoader__.load({
|
|
|
2451
2673
|
const removeItem = useCallback(
|
|
2452
2674
|
async (kind, name) => {
|
|
2453
2675
|
const key = `${kind}:${name}`
|
|
2454
|
-
if (
|
|
2455
|
-
|
|
2456
|
-
if (timer) {
|
|
2457
|
-
clearTimeout(timer)
|
|
2458
|
-
timersRef.current.delete(key)
|
|
2459
|
-
}
|
|
2460
|
-
pendingRef.current.delete(key)
|
|
2461
|
-
markSaving(key, false)
|
|
2676
|
+
if (removingRef.current.has(key)) return
|
|
2677
|
+
removingRef.current.add(key)
|
|
2462
2678
|
setBusyKey('remove:' + key, true)
|
|
2463
2679
|
setError('')
|
|
2464
2680
|
try {
|
|
2681
|
+
// Removal owns this row: discard its queued draft and ignore later
|
|
2682
|
+
// edits so no save can be scheduled once the delete is under way.
|
|
2683
|
+
editSeqRef.current.set(key, (editSeqRef.current.get(key) ?? 0) + 1)
|
|
2684
|
+
draftsRef.current.delete(key)
|
|
2685
|
+
const timer = timersRef.current.get(key)
|
|
2686
|
+
if (timer) {
|
|
2687
|
+
clearTimeout(timer)
|
|
2688
|
+
timersRef.current.delete(key)
|
|
2689
|
+
}
|
|
2690
|
+
pendingRef.current.delete(key)
|
|
2691
|
+
markSaving(key, false)
|
|
2692
|
+
|
|
2693
|
+
// Settle the row's last in-flight write before removing it. Without
|
|
2694
|
+
// this, the older `/item` request can be processed after the delete
|
|
2695
|
+
// and (on an older server) recreate the member.
|
|
2696
|
+
const inFlight = writeChainsRef.current.get(key)
|
|
2697
|
+
if (inFlight) await inFlight.catch(() => {})
|
|
2698
|
+
if (pendingRef.current.size > 0) await flushPending()
|
|
2699
|
+
// Any GET already running must not restore the row from older data.
|
|
2700
|
+
boardRevisionRef.current += 1
|
|
2701
|
+
|
|
2465
2702
|
const payload = await request(`${API}/item/remove`, { method: 'POST', body: { kind, name } })
|
|
2466
2703
|
if (!mounted.current) return
|
|
2704
|
+
surfaceWarning(payload)
|
|
2705
|
+
boardRevisionRef.current += 1
|
|
2467
2706
|
if (payload.state) {
|
|
2468
2707
|
setBoard((current) => (current ? { ...current, state: normalizeState(payload.state) } : current))
|
|
2469
2708
|
} else {
|
|
@@ -2478,12 +2717,15 @@ window.__ModuleLoader__.load({
|
|
|
2478
2717
|
else flash(TEXT.itemRemoved)
|
|
2479
2718
|
await loadBoard({ silent: true })
|
|
2480
2719
|
} catch (cause) {
|
|
2720
|
+
// The member is still present; let a stale reload refresh views only.
|
|
2721
|
+
boardRevisionRef.current += 1
|
|
2481
2722
|
if (mounted.current) setRowError(key, messageOf(cause))
|
|
2482
2723
|
} finally {
|
|
2724
|
+
removingRef.current.delete(key)
|
|
2483
2725
|
if (mounted.current) setBusyKey('remove:' + key, false)
|
|
2484
2726
|
}
|
|
2485
2727
|
},
|
|
2486
|
-
[clearRowError, flash, flushPending, loadBoard, markSaving, setBusyKey, setRowError],
|
|
2728
|
+
[clearRowError, flash, flushPending, loadBoard, markSaving, setBusyKey, setRowError, surfaceWarning],
|
|
2487
2729
|
)
|
|
2488
2730
|
|
|
2489
2731
|
const saveSettings = useCallback(
|
|
@@ -2504,6 +2746,7 @@ window.__ModuleLoader__.load({
|
|
|
2504
2746
|
)
|
|
2505
2747
|
}
|
|
2506
2748
|
flash(TEXT.settingsSaved)
|
|
2749
|
+
surfaceWarning(payload)
|
|
2507
2750
|
} catch (cause) {
|
|
2508
2751
|
if (mounted.current) {
|
|
2509
2752
|
setError(messageOf(cause))
|
|
@@ -2513,7 +2756,7 @@ window.__ModuleLoader__.load({
|
|
|
2513
2756
|
if (mounted.current) setBusyKey('settings', false)
|
|
2514
2757
|
}
|
|
2515
2758
|
},
|
|
2516
|
-
[flash, loadBoard, setBusyKey],
|
|
2759
|
+
[flash, loadBoard, setBusyKey, surfaceWarning],
|
|
2517
2760
|
)
|
|
2518
2761
|
|
|
2519
2762
|
/** Persist the pending scope of one group (debounced by `updateGroup`). */
|
|
@@ -2538,6 +2781,7 @@ window.__ModuleLoader__.load({
|
|
|
2538
2781
|
if (payload.state) {
|
|
2539
2782
|
setBoard((board) => (board ? { ...board, state: normalizeState(payload.state) } : board))
|
|
2540
2783
|
}
|
|
2784
|
+
surfaceWarning(payload)
|
|
2541
2785
|
} catch (cause) {
|
|
2542
2786
|
if (mounted.current) {
|
|
2543
2787
|
setError(messageOf(cause))
|
|
@@ -2547,7 +2791,7 @@ window.__ModuleLoader__.load({
|
|
|
2547
2791
|
if (mounted.current) setBusyKey('group:' + key, false)
|
|
2548
2792
|
}
|
|
2549
2793
|
},
|
|
2550
|
-
[setBusyKey],
|
|
2794
|
+
[setBusyKey, surfaceWarning],
|
|
2551
2795
|
)
|
|
2552
2796
|
|
|
2553
2797
|
/** Optimistically edit a group, then persist it once the user pauses. */
|
|
@@ -2614,6 +2858,7 @@ window.__ModuleLoader__.load({
|
|
|
2614
2858
|
: current,
|
|
2615
2859
|
)
|
|
2616
2860
|
}
|
|
2861
|
+
surfaceWarning(payload)
|
|
2617
2862
|
if (seg === 'mcp') {
|
|
2618
2863
|
if (mounted.current) void loadBoard({ silent: true })
|
|
2619
2864
|
}
|
|
@@ -2622,7 +2867,7 @@ window.__ModuleLoader__.load({
|
|
|
2622
2867
|
if (mounted.current) setBusyKey('import', false)
|
|
2623
2868
|
}
|
|
2624
2869
|
},
|
|
2625
|
-
[loadBoard, setBusyKey],
|
|
2870
|
+
[loadBoard, setBusyKey, surfaceWarning],
|
|
2626
2871
|
)
|
|
2627
2872
|
|
|
2628
2873
|
const pollMounts = useCallback(async () => {
|
|
@@ -2666,6 +2911,7 @@ window.__ModuleLoader__.load({
|
|
|
2666
2911
|
const upToDate = results.filter((row) => asString(row && row.status) === 'up-to-date').length
|
|
2667
2912
|
const failed = results.filter((row) => asString(row && row.status) === 'error').length
|
|
2668
2913
|
flash(tf('checkResult', { updated, upToDate, failed }))
|
|
2914
|
+
surfaceWarning(payload)
|
|
2669
2915
|
await loadBoard({ silent: true })
|
|
2670
2916
|
} catch (cause) {
|
|
2671
2917
|
if (mounted.current) setError(messageOf(cause))
|
|
@@ -2673,7 +2919,7 @@ window.__ModuleLoader__.load({
|
|
|
2673
2919
|
if (mounted.current) setBusyKey(busyKey, false)
|
|
2674
2920
|
}
|
|
2675
2921
|
},
|
|
2676
|
-
[flash, loadBoard, setBusyKey],
|
|
2922
|
+
[flash, loadBoard, setBusyKey, surfaceWarning],
|
|
2677
2923
|
)
|
|
2678
2924
|
|
|
2679
2925
|
const updateSource = useCallback(
|
|
@@ -2707,6 +2953,7 @@ window.__ModuleLoader__.load({
|
|
|
2707
2953
|
: TEXT.noticeSourceUpdated,
|
|
2708
2954
|
)
|
|
2709
2955
|
}
|
|
2956
|
+
surfaceWarning(payload)
|
|
2710
2957
|
await loadBoard({ silent: true })
|
|
2711
2958
|
} catch (cause) {
|
|
2712
2959
|
if (mounted.current) setError(messageOf(cause))
|
|
@@ -2714,7 +2961,7 @@ window.__ModuleLoader__.load({
|
|
|
2714
2961
|
if (mounted.current) setBusyKey('source:update:' + id, false)
|
|
2715
2962
|
}
|
|
2716
2963
|
},
|
|
2717
|
-
[flash, loadBoard, setBusyKey],
|
|
2964
|
+
[flash, loadBoard, setBusyKey, surfaceWarning],
|
|
2718
2965
|
)
|
|
2719
2966
|
|
|
2720
2967
|
/** Update every Git import of one repository group, one after another. */
|
|
@@ -2727,6 +2974,7 @@ window.__ModuleLoader__.load({
|
|
|
2727
2974
|
let installed = 0
|
|
2728
2975
|
let failures = 0
|
|
2729
2976
|
let changed = 0
|
|
2977
|
+
let warningPayload = null
|
|
2730
2978
|
try {
|
|
2731
2979
|
for (const id of list) {
|
|
2732
2980
|
try {
|
|
@@ -2735,6 +2983,7 @@ window.__ModuleLoader__.load({
|
|
|
2735
2983
|
if (payload.state) {
|
|
2736
2984
|
setBoard((current) => (current ? { ...current, state: normalizeState(payload.state) } : current))
|
|
2737
2985
|
}
|
|
2986
|
+
if (payload.warning) warningPayload = payload
|
|
2738
2987
|
if (payload.changed !== false) changed += 1
|
|
2739
2988
|
installed += asArray(payload.installed).length
|
|
2740
2989
|
failures += asArray(payload.failures).length
|
|
@@ -2747,12 +2996,13 @@ window.__ModuleLoader__.load({
|
|
|
2747
2996
|
if (failures === 0) {
|
|
2748
2997
|
flash(changed === 0 ? TEXT.noticeSourceUpToDate : tf('noticeGroupUpdated', { count: installed }))
|
|
2749
2998
|
}
|
|
2999
|
+
if (warningPayload) surfaceWarning(warningPayload)
|
|
2750
3000
|
await loadBoard({ silent: true })
|
|
2751
3001
|
} finally {
|
|
2752
3002
|
if (mounted.current) setBusyKey(busyKey, false)
|
|
2753
3003
|
}
|
|
2754
3004
|
},
|
|
2755
|
-
[flash, loadBoard, setBusyKey],
|
|
3005
|
+
[flash, loadBoard, setBusyKey, surfaceWarning],
|
|
2756
3006
|
)
|
|
2757
3007
|
|
|
2758
3008
|
const deleteSource = useCallback(
|
|
@@ -2772,6 +3022,7 @@ window.__ModuleLoader__.load({
|
|
|
2772
3022
|
? TEXT.noticeSourceDeleted + tf('sourceSkipped', { count: skipped.length })
|
|
2773
3023
|
: TEXT.noticeSourceDeleted,
|
|
2774
3024
|
)
|
|
3025
|
+
surfaceWarning(payload)
|
|
2775
3026
|
await loadBoard({ silent: true })
|
|
2776
3027
|
} catch (cause) {
|
|
2777
3028
|
if (mounted.current) setError(messageOf(cause))
|
|
@@ -2779,7 +3030,7 @@ window.__ModuleLoader__.load({
|
|
|
2779
3030
|
if (mounted.current) setBusyKey('source:delete:' + id, false)
|
|
2780
3031
|
}
|
|
2781
3032
|
},
|
|
2782
|
-
[flash, loadBoard, setBusyKey],
|
|
3033
|
+
[flash, loadBoard, setBusyKey, surfaceWarning],
|
|
2783
3034
|
)
|
|
2784
3035
|
|
|
2785
3036
|
// ----------------------------------------------------------- renderers
|
|
@@ -3726,13 +3977,6 @@ window.__ModuleLoader__.load({
|
|
|
3726
3977
|
disabled: savingSettings,
|
|
3727
3978
|
onChange: (value) => void saveSettings({ mcpGate: value }),
|
|
3728
3979
|
}),
|
|
3729
|
-
h(SwitchRow, {
|
|
3730
|
-
label: TEXT.setInjectSummary,
|
|
3731
|
-
hint: TEXT.setInjectSummaryHint,
|
|
3732
|
-
checked: settings.injectSummary === true,
|
|
3733
|
-
disabled: savingSettings,
|
|
3734
|
-
onChange: (value) => void saveSettings({ injectSummary: value }),
|
|
3735
|
-
}),
|
|
3736
3980
|
h(SwitchRow, {
|
|
3737
3981
|
label: `${TEXT.setGateDefaultSkills} · ${TEXT.notAvailable}`,
|
|
3738
3982
|
hint: TEXT.setGateDefaultSkillsHint,
|
|
@@ -3805,6 +4049,18 @@ window.__ModuleLoader__.load({
|
|
|
3805
4049
|
)
|
|
3806
4050
|
: null,
|
|
3807
4051
|
notice ? h('div', { style: S.notice, role: 'status' }, notice) : null,
|
|
4052
|
+
activationWarning
|
|
4053
|
+
? h(
|
|
4054
|
+
'div',
|
|
4055
|
+
{ style: S.activationWarning, role: 'alert' },
|
|
4056
|
+
h('span', { style: { minWidth: 0 } }, activationWarning.message),
|
|
4057
|
+
h(
|
|
4058
|
+
'button',
|
|
4059
|
+
{ type: 'button', style: S.buttonSmall, onClick: () => setActivationWarning(dismissActivationWarning()) },
|
|
4060
|
+
TEXT.close,
|
|
4061
|
+
),
|
|
4062
|
+
)
|
|
4063
|
+
: null,
|
|
3808
4064
|
board
|
|
3809
4065
|
? h(
|
|
3810
4066
|
React.Fragment,
|
|
@@ -4416,6 +4672,18 @@ window.__ModuleLoader__.load({
|
|
|
4416
4672
|
|
|
4417
4673
|
return {
|
|
4418
4674
|
inject: ['slots'],
|
|
4675
|
+
// Pure reconciliation used by `loadBoard`; exposed so the Node test can
|
|
4676
|
+
// exercise the production function without a browser renderer.
|
|
4677
|
+
boardState: {
|
|
4678
|
+
applyLoadedBoard,
|
|
4679
|
+
applyItemSave,
|
|
4680
|
+
draftLossMessage,
|
|
4681
|
+
orphanedDrafts,
|
|
4682
|
+
buildItemSaveBody,
|
|
4683
|
+
activationWarningOf,
|
|
4684
|
+
mergeActivationWarning,
|
|
4685
|
+
dismissActivationWarning,
|
|
4686
|
+
},
|
|
4419
4687
|
apply(ctx) {
|
|
4420
4688
|
ctx.slots.inject('settings.section', () =>
|
|
4421
4689
|
ctx.slots.register(
|