dsh-aiterm 0.5.1 → 0.5.13
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.md +104 -22
- package/README.md +206 -26
- package/client/HistoryPanel.jsx +342 -29
- package/client/api.js +44 -3
- package/client/locale.js +40 -2
- package/cordis.patch.yml +1 -0
- package/lib/client.js +30 -30
- package/lib/host/autolog.js +107 -4
- package/lib/host/config.js +14 -0
- package/lib/host/disclosure.js +357 -0
- package/lib/host/exporter.js +447 -159
- package/lib/host/history-store.js +1735 -295
- package/lib/host/permission.js +13 -0
- package/lib/host/prompt.js +5 -2
- package/lib/host/registry.js +858 -76
- package/lib/host/routes.js +45 -2
- package/lib/host/tools.js +291 -22
- package/lib/index.js +4 -2
- package/package.json +2 -2
- package/scripts/smoke-client.mjs +193 -6
package/client/HistoryPanel.jsx
CHANGED
|
@@ -22,6 +22,9 @@ import {
|
|
|
22
22
|
historyExport,
|
|
23
23
|
historyQuery,
|
|
24
24
|
historySessions,
|
|
25
|
+
legacyHistoryExport,
|
|
26
|
+
legacyHistoryQuery,
|
|
27
|
+
legacyHistorySessions,
|
|
25
28
|
autologGet,
|
|
26
29
|
autologSet,
|
|
27
30
|
hostSearchValue,
|
|
@@ -85,7 +88,20 @@ export function HistoryPanel({ t, sessionId, onClose }) {
|
|
|
85
88
|
const [sessions, setSessions] = useState([])
|
|
86
89
|
const [listState, setListState] = useState('loading')
|
|
87
90
|
const [listError, setListError] = useState(null)
|
|
91
|
+
const [listTruncated, setListTruncated] = useState(false)
|
|
92
|
+
const [listTotal, setListTotal] = useState(0)
|
|
93
|
+
const [listSnapshot, setListSnapshot] = useState('')
|
|
94
|
+
const [listRawCount, setListRawCount] = useState(0)
|
|
95
|
+
const [listLimitReached, setListLimitReached] = useState(false)
|
|
96
|
+
const loadTokenRef = useRef(0)
|
|
97
|
+
const legacyModeRef = useRef(false)
|
|
98
|
+
const [loadMoreBusy, setLoadMoreBusy] = useState(false)
|
|
88
99
|
const [pickedId, setPickedId] = useState(null)
|
|
100
|
+
/** Exact incarnation address when several entries share one logical id. */
|
|
101
|
+
const [pickedHistoryId, setPickedHistoryId] = useState(null)
|
|
102
|
+
/** Explicit human-only view for pre-upgrade ownerless history. */
|
|
103
|
+
const [legacyMode, setLegacyMode] = useState(false)
|
|
104
|
+
const [legacyBusy, setLegacyBusy] = useState(false)
|
|
89
105
|
const [since, setSince] = useState('')
|
|
90
106
|
const [until, setUntil] = useState('')
|
|
91
107
|
const [search, setSearch] = useState('')
|
|
@@ -93,8 +109,10 @@ export function HistoryPanel({ t, sessionId, onClose }) {
|
|
|
93
109
|
const [result, setResult] = useState(null)
|
|
94
110
|
const [pattern, setPattern] = useState(null)
|
|
95
111
|
/** Auto-log (write every session to a file) state. */
|
|
96
|
-
const [autoLog, setAutoLog] = useState({ enabled: false, dir: '' })
|
|
112
|
+
const [autoLog, setAutoLog] = useState({ enabled: false, dir: '', needsReview: false })
|
|
97
113
|
const [autoLogBusy, setAutoLogBusy] = useState(false)
|
|
114
|
+
const [autoLogLoading, setAutoLogLoading] = useState(true)
|
|
115
|
+
const [autoLogError, setAutoLogError] = useState(null)
|
|
98
116
|
/**
|
|
99
117
|
* False when the running Host predates the export / auto-log RPCs. The
|
|
100
118
|
* client bundle updates on refresh but the Host only on restart, so a fresh
|
|
@@ -111,29 +129,39 @@ export function HistoryPanel({ t, sessionId, onClose }) {
|
|
|
111
129
|
const bodyRef = useRef(null)
|
|
112
130
|
const requestRef = useRef(0)
|
|
113
131
|
const aliveRef = useRef(true)
|
|
132
|
+
useEffect(() => {
|
|
133
|
+
legacyModeRef.current = legacyMode
|
|
134
|
+
}, [legacyMode])
|
|
114
135
|
|
|
115
136
|
useEffect(() => {
|
|
116
137
|
aliveRef.current = true
|
|
117
138
|
let cancelled = false
|
|
139
|
+
const token = ++loadTokenRef.current
|
|
118
140
|
const load = async () => {
|
|
119
|
-
if (!cancelled) {
|
|
141
|
+
if (!cancelled && token === loadTokenRef.current) {
|
|
120
142
|
setListState('loading')
|
|
121
143
|
setListError(null)
|
|
122
144
|
}
|
|
123
145
|
try {
|
|
124
146
|
const raw = await historySessions({ limit: 50 })
|
|
125
|
-
if (cancelled || !aliveRef.current) return
|
|
147
|
+
if (cancelled || !aliveRef.current || token !== loadTokenRef.current) return
|
|
126
148
|
const list = raw && Array.isArray(raw.sessions)
|
|
127
149
|
? raw.sessions.map(normalizeCatalogEntry).filter(Boolean)
|
|
128
150
|
: []
|
|
129
|
-
//
|
|
130
|
-
|
|
151
|
+
// Preserve the server's authoritative page order (live first, then
|
|
152
|
+
// closed sessions by activity); page 2 is appended in the same order.
|
|
131
153
|
setSessions(list)
|
|
132
154
|
setListState(list.length > 0 ? 'ready' : 'empty')
|
|
155
|
+
setListTruncated(raw?.truncated === true)
|
|
156
|
+
setListTotal(typeof raw?.total === 'number' ? raw.total : list.length)
|
|
157
|
+
setListSnapshot(typeof raw?.snapshot === 'string' ? raw.snapshot : '')
|
|
158
|
+
setListRawCount(list.length)
|
|
159
|
+
setListLimitReached(raw?.limitReached === true)
|
|
133
160
|
const preferred = list.find((entry) => entry.id === sessionId) || list[0]
|
|
134
161
|
setPickedId(preferred ? preferred.id : null)
|
|
162
|
+
setPickedHistoryId(preferred ? (preferred.historyId || null) : null)
|
|
135
163
|
} catch (error) {
|
|
136
|
-
if (cancelled || !aliveRef.current) return
|
|
164
|
+
if (cancelled || !aliveRef.current || token !== loadTokenRef.current) return
|
|
137
165
|
setListError(errorMessage(error))
|
|
138
166
|
setListState('error')
|
|
139
167
|
}
|
|
@@ -142,6 +170,7 @@ export function HistoryPanel({ t, sessionId, onClose }) {
|
|
|
142
170
|
return () => {
|
|
143
171
|
cancelled = true
|
|
144
172
|
aliveRef.current = false
|
|
173
|
+
loadTokenRef.current += 1
|
|
145
174
|
}
|
|
146
175
|
}, [])
|
|
147
176
|
|
|
@@ -152,7 +181,7 @@ export function HistoryPanel({ t, sessionId, onClose }) {
|
|
|
152
181
|
* @param id - catalog session id (defaults to the picked session).
|
|
153
182
|
* @param filters - the filter fields captured at call time.
|
|
154
183
|
*/
|
|
155
|
-
async function runQuery(id = pickedId, filters = { since, until, search, context }) {
|
|
184
|
+
async function runQuery(id = pickedId, historyId = pickedHistoryId, filters = { since, until, search, context }) {
|
|
156
185
|
if (!id) {
|
|
157
186
|
setQueryState('empty')
|
|
158
187
|
setQueryError(null)
|
|
@@ -180,14 +209,17 @@ export function HistoryPanel({ t, sessionId, onClose }) {
|
|
|
180
209
|
setPattern(highlightPattern(filters.search))
|
|
181
210
|
|
|
182
211
|
try {
|
|
183
|
-
const
|
|
212
|
+
const payload = {
|
|
184
213
|
sessionId: id,
|
|
185
214
|
since: sinceParsed.at,
|
|
186
215
|
until: untilParsed.at,
|
|
187
216
|
search: hostSearchValue(filters.search),
|
|
188
217
|
context: Number(filters.context) || 0,
|
|
189
218
|
maxMatches: 200,
|
|
190
|
-
}
|
|
219
|
+
}
|
|
220
|
+
const raw = legacyMode
|
|
221
|
+
? await legacyHistoryQuery(payload)
|
|
222
|
+
: await historyQuery({ ...payload, historyId: historyId || undefined })
|
|
191
223
|
if (requestRef.current !== token || !aliveRef.current) return
|
|
192
224
|
const normalized = normalizeHistoryQuery(raw)
|
|
193
225
|
setResult(normalized)
|
|
@@ -205,15 +237,18 @@ export function HistoryPanel({ t, sessionId, onClose }) {
|
|
|
205
237
|
// the user picks another one), honouring the filters typed so far.
|
|
206
238
|
useEffect(() => {
|
|
207
239
|
if (!pickedId) return
|
|
208
|
-
runQuery(pickedId, { since, until, search, context })
|
|
209
|
-
}, [pickedId])
|
|
210
|
-
|
|
211
|
-
const selectSession = (
|
|
212
|
-
|
|
213
|
-
|
|
240
|
+
runQuery(pickedId, pickedHistoryId, { since, until, search, context })
|
|
241
|
+
}, [pickedId, pickedHistoryId, legacyMode])
|
|
242
|
+
|
|
243
|
+
const selectSession = (entry) => {
|
|
244
|
+
const id = entry && typeof entry === 'object' && entry.id ? entry.id : entry
|
|
245
|
+
const historyId = entry && typeof entry === 'object' && typeof entry.historyId === 'string' ? entry.historyId : null
|
|
246
|
+
if (id === pickedId && historyId === pickedHistoryId) {
|
|
247
|
+
runQuery(id, historyId)
|
|
214
248
|
return
|
|
215
249
|
}
|
|
216
250
|
setPickedId(id)
|
|
251
|
+
setPickedHistoryId(historyId)
|
|
217
252
|
setResult(null)
|
|
218
253
|
setQueryState('idle')
|
|
219
254
|
setQueryError(null)
|
|
@@ -254,11 +289,15 @@ export function HistoryPanel({ t, sessionId, onClose }) {
|
|
|
254
289
|
setAutoLog({
|
|
255
290
|
enabled: state.enabled === true,
|
|
256
291
|
dir: typeof state.dir === 'string' ? state.dir : '',
|
|
292
|
+
needsReview: state.needsReview === true,
|
|
257
293
|
})
|
|
294
|
+
setAutoLogLoading(false)
|
|
258
295
|
})
|
|
259
296
|
.catch((error) => {
|
|
260
297
|
if (cancelled) return
|
|
298
|
+
setAutoLogLoading(false)
|
|
261
299
|
if (error && error.code === 'UNKNOWN_METHOD') setLogBackend(false)
|
|
300
|
+
else setAutoLogError(errorMessage(error))
|
|
262
301
|
})
|
|
263
302
|
return () => {
|
|
264
303
|
cancelled = true
|
|
@@ -279,11 +318,22 @@ export function HistoryPanel({ t, sessionId, onClose }) {
|
|
|
279
318
|
const params =
|
|
280
319
|
scope === 'all'
|
|
281
320
|
? { all: true }
|
|
282
|
-
: {
|
|
283
|
-
|
|
321
|
+
: {
|
|
322
|
+
sessionId: pickedId || (sessionId || undefined),
|
|
323
|
+
historyId: pickedHistoryId || undefined,
|
|
324
|
+
}
|
|
325
|
+
const result = legacyMode && scope !== 'all'
|
|
326
|
+
? await legacyHistoryExport({ sessionId: params.sessionId })
|
|
327
|
+
: await historyExport(params)
|
|
284
328
|
setExported(result || null)
|
|
285
329
|
const files = result && Array.isArray(result.files) ? result.files : []
|
|
286
|
-
|
|
330
|
+
const skipped = result && Array.isArray(result.skipped) ? result.skipped : []
|
|
331
|
+
const skippedTotal = result && Number.isInteger(result.skippedTotal) ? result.skippedTotal : skipped.length
|
|
332
|
+
notify(
|
|
333
|
+
files.length > 0
|
|
334
|
+
? fmt(t, 'historyExportDone', { count: files.length })
|
|
335
|
+
: (skippedTotal > 0 ? fmt(t, 'historyExportSkippedTitle', { count: skippedTotal }) : t('historyExportEmpty')),
|
|
336
|
+
)
|
|
287
337
|
} catch (error) {
|
|
288
338
|
if (error && error.code === 'UNKNOWN_METHOD') {
|
|
289
339
|
setLogBackend(false)
|
|
@@ -297,14 +347,19 @@ export function HistoryPanel({ t, sessionId, onClose }) {
|
|
|
297
347
|
}
|
|
298
348
|
|
|
299
349
|
/** Flip the Host auto-log switch. @returns {Promise<void>} resolves when applied. */
|
|
300
|
-
const toggleAutoLog = async () => {
|
|
301
|
-
if (autoLogBusy) return
|
|
350
|
+
const toggleAutoLog = async (explicitNext) => {
|
|
351
|
+
if (autoLogBusy || autoLogLoading || autoLogError !== null) return
|
|
352
|
+
// A legacy enabled setting may only be changed through the two explicit
|
|
353
|
+
// buttons (keep off / confirm old path); a stray toggle cannot enable it.
|
|
354
|
+
if (autoLog.needsReview && explicitNext !== false) return
|
|
302
355
|
setAutoLogBusy(true)
|
|
303
356
|
try {
|
|
304
|
-
const
|
|
357
|
+
const wanted = typeof explicitNext === 'boolean' ? explicitNext : !autoLog.enabled
|
|
358
|
+
const next = await autologSet({ enabled: wanted })
|
|
305
359
|
setAutoLog({
|
|
306
360
|
enabled: next && next.enabled === true,
|
|
307
361
|
dir: next && typeof next.dir === 'string' ? next.dir : autoLog.dir,
|
|
362
|
+
needsReview: next && typeof next.needsReview === 'boolean' ? next.needsReview : false,
|
|
308
363
|
})
|
|
309
364
|
notify(next && next.enabled === true ? t('historyAutoLogOn') : t('historyAutoLogOff'))
|
|
310
365
|
} catch (error) {
|
|
@@ -319,6 +374,199 @@ export function HistoryPanel({ t, sessionId, onClose }) {
|
|
|
319
374
|
}
|
|
320
375
|
}
|
|
321
376
|
|
|
377
|
+
/** Explicitly confirm a legacy enabled switch and its old directory. */
|
|
378
|
+
const confirmLegacyEnable = async () => {
|
|
379
|
+
if (autoLogBusy || autoLogLoading || autoLogError !== null) return
|
|
380
|
+
setAutoLogBusy(true)
|
|
381
|
+
try {
|
|
382
|
+
const next = await autologSet({ enabled: true, dir: autoLog.dir, confirmLegacy: true })
|
|
383
|
+
setAutoLog({
|
|
384
|
+
enabled: next && next.enabled === true,
|
|
385
|
+
dir: next && typeof next.dir === 'string' ? next.dir : autoLog.dir,
|
|
386
|
+
needsReview: false,
|
|
387
|
+
})
|
|
388
|
+
notify(next && next.enabled === true ? t('historyAutoLogOn') : t('historyAutoLogOffHint'))
|
|
389
|
+
} catch (error) {
|
|
390
|
+
if (error && error.code === 'UNKNOWN_METHOD') {
|
|
391
|
+
setLogBackend(false)
|
|
392
|
+
notify(t('historyExportNeedsRestart'))
|
|
393
|
+
} else {
|
|
394
|
+
notify(fmt(t, 'historyAutoLogFailed', { message: errorMessage(error) }))
|
|
395
|
+
}
|
|
396
|
+
} finally {
|
|
397
|
+
setAutoLogBusy(false)
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/** Load the normal owner-scoped list (also used when leaving legacy mode). */
|
|
402
|
+
const loadNormal = async () => {
|
|
403
|
+
const token = ++loadTokenRef.current
|
|
404
|
+
// Invalidate any in-flight legacy/normal query before the list reload so a
|
|
405
|
+
// late query cannot paint into the new source. Filters remain untouched.
|
|
406
|
+
requestRef.current += 1
|
|
407
|
+
setResult(null)
|
|
408
|
+
setQueryState('idle')
|
|
409
|
+
setQueryError(null)
|
|
410
|
+
setManualText(null)
|
|
411
|
+
setPattern(null)
|
|
412
|
+
setLoadMoreBusy(false)
|
|
413
|
+
setSessions([])
|
|
414
|
+
setListTruncated(false)
|
|
415
|
+
setListLimitReached(false)
|
|
416
|
+
setListTotal(0)
|
|
417
|
+
setListSnapshot('')
|
|
418
|
+
setListRawCount(0)
|
|
419
|
+
setListState('loading')
|
|
420
|
+
setListError(null)
|
|
421
|
+
try {
|
|
422
|
+
const raw = await historySessions({ limit: 50 })
|
|
423
|
+
if (!aliveRef.current || token !== loadTokenRef.current) return
|
|
424
|
+
const list = raw && Array.isArray(raw.sessions)
|
|
425
|
+
? raw.sessions.map(normalizeCatalogEntry).filter(Boolean)
|
|
426
|
+
: []
|
|
427
|
+
setSessions(list)
|
|
428
|
+
setListState(list.length > 0 ? 'ready' : 'empty')
|
|
429
|
+
setListTruncated(raw?.truncated === true)
|
|
430
|
+
setListTotal(typeof raw?.total === 'number' ? raw.total : list.length)
|
|
431
|
+
setListSnapshot(typeof raw?.snapshot === 'string' ? raw.snapshot : '')
|
|
432
|
+
setListRawCount(list.length)
|
|
433
|
+
setListLimitReached(raw?.limitReached === true)
|
|
434
|
+
const preferred = list.find((entry) => entry.id === sessionId) || list[0]
|
|
435
|
+
setPickedId(preferred ? preferred.id : null)
|
|
436
|
+
setPickedHistoryId(preferred ? (preferred.historyId || null) : null)
|
|
437
|
+
setResult(null)
|
|
438
|
+
setQueryState('idle')
|
|
439
|
+
setQueryError(null)
|
|
440
|
+
setManualText(null)
|
|
441
|
+
} catch (error) {
|
|
442
|
+
if (!aliveRef.current || token !== loadTokenRef.current) return
|
|
443
|
+
setListError(errorMessage(error))
|
|
444
|
+
setListState('error')
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/** Open the explicit human-only legacy view. */
|
|
449
|
+
const enterLegacy = async (force = false) => {
|
|
450
|
+
if (legacyBusy && force !== true) return
|
|
451
|
+
const token = ++loadTokenRef.current
|
|
452
|
+
setLoadMoreBusy(false)
|
|
453
|
+
setLegacyBusy(true)
|
|
454
|
+
requestRef.current += 1
|
|
455
|
+
setLegacyMode(true)
|
|
456
|
+
setSessions([])
|
|
457
|
+
setListTruncated(false)
|
|
458
|
+
setListLimitReached(false)
|
|
459
|
+
setListTotal(0)
|
|
460
|
+
setListSnapshot('')
|
|
461
|
+
setListRawCount(0)
|
|
462
|
+
// Drop the normal selection before switching sources so the query effect
|
|
463
|
+
// never runs the old owner-scoped id through the legacy RPC.
|
|
464
|
+
setPickedId(null)
|
|
465
|
+
setPickedHistoryId(null)
|
|
466
|
+
setListState('loading')
|
|
467
|
+
setListError(null)
|
|
468
|
+
setResult(null)
|
|
469
|
+
setQueryState('idle')
|
|
470
|
+
setQueryError(null)
|
|
471
|
+
setExported(null)
|
|
472
|
+
setExportError(null)
|
|
473
|
+
try {
|
|
474
|
+
const raw = await legacyHistorySessions({ limit: 50 })
|
|
475
|
+
if (!aliveRef.current || token !== loadTokenRef.current) return
|
|
476
|
+
const list = raw && Array.isArray(raw.sessions)
|
|
477
|
+
? raw.sessions.map(normalizeCatalogEntry).filter(Boolean)
|
|
478
|
+
: []
|
|
479
|
+
setSessions(list)
|
|
480
|
+
setListState(list.length > 0 ? 'ready' : 'empty')
|
|
481
|
+
setListTruncated(raw?.truncated === true)
|
|
482
|
+
setListTotal(typeof raw?.total === 'number' ? raw.total : list.length)
|
|
483
|
+
setListSnapshot(typeof raw?.snapshot === 'string' ? raw.snapshot : '')
|
|
484
|
+
setListRawCount(list.length)
|
|
485
|
+
setListLimitReached(raw?.limitReached === true)
|
|
486
|
+
setPickedId(list[0] ? list[0].id : null)
|
|
487
|
+
setPickedHistoryId(null)
|
|
488
|
+
} catch (error) {
|
|
489
|
+
if (!aliveRef.current || token !== loadTokenRef.current) return
|
|
490
|
+
setListError(errorMessage(error))
|
|
491
|
+
setListState('error')
|
|
492
|
+
} finally {
|
|
493
|
+
if (aliveRef.current && token === loadTokenRef.current) setLegacyBusy(false)
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/** Leave legacy mode and restore the normal owner-scoped list. */
|
|
498
|
+
const leaveLegacy = async () => {
|
|
499
|
+
if (legacyBusy) return
|
|
500
|
+
loadTokenRef.current += 1
|
|
501
|
+
setLoadMoreBusy(false)
|
|
502
|
+
setLegacyBusy(true)
|
|
503
|
+
requestRef.current += 1
|
|
504
|
+
setLegacyMode(false)
|
|
505
|
+
setSessions([])
|
|
506
|
+
setListTruncated(false)
|
|
507
|
+
setListLimitReached(false)
|
|
508
|
+
setListTotal(0)
|
|
509
|
+
setListSnapshot('')
|
|
510
|
+
setListRawCount(0)
|
|
511
|
+
setPickedId(null)
|
|
512
|
+
setPickedHistoryId(null)
|
|
513
|
+
setExported(null)
|
|
514
|
+
setExportError(null)
|
|
515
|
+
try {
|
|
516
|
+
await loadNormal()
|
|
517
|
+
} finally {
|
|
518
|
+
setLegacyBusy(false)
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
/** Fetch the next page for the current source, with snapshot/epoch guards. */
|
|
523
|
+
const loadMore = async () => {
|
|
524
|
+
if (loadMoreBusy || listLimitReached) return
|
|
525
|
+
const token = ++loadTokenRef.current
|
|
526
|
+
const modeAtStart = legacyMode
|
|
527
|
+
const snapshotAtStart = listSnapshot
|
|
528
|
+
const offsetAtStart = listRawCount
|
|
529
|
+
setLoadMoreBusy(true)
|
|
530
|
+
try {
|
|
531
|
+
const raw = modeAtStart
|
|
532
|
+
? await legacyHistorySessions({ limit: 50, offset: offsetAtStart, snapshot: snapshotAtStart })
|
|
533
|
+
: await historySessions({ limit: 50, offset: offsetAtStart, snapshot: snapshotAtStart })
|
|
534
|
+
if (!aliveRef.current || token !== loadTokenRef.current || modeAtStart !== legacyModeRef.current) return
|
|
535
|
+
if (raw?.stale === true) {
|
|
536
|
+
// The server's ordering/activity changed while paging. A stale offset
|
|
537
|
+
// could skip rows; reload from the first page instead of silently
|
|
538
|
+
// claiming the list is complete.
|
|
539
|
+
notify(t('historyStaleReload'))
|
|
540
|
+
if (modeAtStart) await enterLegacy(true)
|
|
541
|
+
else await loadNormal()
|
|
542
|
+
return
|
|
543
|
+
}
|
|
544
|
+
const more = raw && Array.isArray(raw.sessions)
|
|
545
|
+
? raw.sessions.map(normalizeCatalogEntry).filter(Boolean)
|
|
546
|
+
: []
|
|
547
|
+
const seen = new Set(sessions.map((entry) => entry.historyId || `${entry.id}:${entry.createdAt}`))
|
|
548
|
+
const appended = more.filter((entry) => {
|
|
549
|
+
const key = entry.historyId || `${entry.id}:${entry.createdAt}`
|
|
550
|
+
if (seen.has(key)) return false
|
|
551
|
+
seen.add(key)
|
|
552
|
+
return true
|
|
553
|
+
})
|
|
554
|
+
// The server already returns the authoritative page order (live first,
|
|
555
|
+
// then closed logs by activity). Preserve it; do not re-sort here.
|
|
556
|
+
setSessions([...sessions, ...appended])
|
|
557
|
+
setListTruncated(raw?.truncated === true)
|
|
558
|
+
setListTotal(typeof raw?.total === 'number' ? raw.total : listTotal)
|
|
559
|
+
setListSnapshot(typeof raw?.snapshot === 'string' ? raw.snapshot : snapshotAtStart)
|
|
560
|
+
setListRawCount(offsetAtStart + more.length)
|
|
561
|
+
setListLimitReached(raw?.limitReached === true)
|
|
562
|
+
} catch (error) {
|
|
563
|
+
if (!aliveRef.current || token !== loadTokenRef.current || modeAtStart !== legacyModeRef.current) return
|
|
564
|
+
notify(fmt(t, 'historySessionsFailed', { message: errorMessage(error) }))
|
|
565
|
+
} finally {
|
|
566
|
+
if (aliveRef.current && token === loadTokenRef.current) setLoadMoreBusy(false)
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
|
|
322
570
|
const footer = (
|
|
323
571
|
<>
|
|
324
572
|
<span style={{ minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis' }}>
|
|
@@ -348,8 +596,8 @@ export function HistoryPanel({ t, sessionId, onClose }) {
|
|
|
348
596
|
<Btn
|
|
349
597
|
onClick={() => runExport('all')}
|
|
350
598
|
busy={exportBusy === 'all'}
|
|
351
|
-
disabled={exportBusy !== '' || !logBackend}
|
|
352
|
-
title={logBackend ? t('historyExportAllHint') : t('historyExportNeedsRestart')}
|
|
599
|
+
disabled={exportBusy !== '' || !logBackend || legacyMode}
|
|
600
|
+
title={legacyMode ? t('historyLegacyHint') : (logBackend ? t('historyExportAllHint') : t('historyExportNeedsRestart'))}
|
|
353
601
|
>
|
|
354
602
|
{t('historyExportAll')}
|
|
355
603
|
</Btn>
|
|
@@ -363,29 +611,55 @@ export function HistoryPanel({ t, sessionId, onClose }) {
|
|
|
363
611
|
backLabel={t('historyPanelClose')}
|
|
364
612
|
footer={footer}
|
|
365
613
|
>
|
|
366
|
-
<div style={
|
|
614
|
+
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
|
|
615
|
+
<div style={S.sectionTitle}>{t('historySessionsTitle')}</div>
|
|
616
|
+
<span style={S.controlSpacer} />
|
|
617
|
+
<Btn
|
|
618
|
+
onClick={legacyMode ? leaveLegacy : enterLegacy}
|
|
619
|
+
busy={legacyBusy}
|
|
620
|
+
title={t('historyLegacyHint')}
|
|
621
|
+
>
|
|
622
|
+
{legacyMode ? t('historyLegacyBack') : t('historyLegacyEntry')}
|
|
623
|
+
</Btn>
|
|
624
|
+
</div>
|
|
625
|
+
{legacyMode ? <div style={S.hint}>{t('historyLegacyHint')}</div> : null}
|
|
367
626
|
|
|
368
|
-
{listState === 'loading' ? <div style={S.auditEmpty}>{t('
|
|
627
|
+
{legacyMode && listState === 'loading' ? <div style={S.auditEmpty}>{t('historyLegacyLoading')}</div> : null}
|
|
628
|
+
{listState === 'loading' && !legacyMode ? <div style={S.auditEmpty}>{t('historyLoadingSessions')}</div> : null}
|
|
369
629
|
{listState === 'error' ? (
|
|
370
630
|
<div style={S.formError} role="alert">{fmt(t, 'historySessionsFailed', { message: listError })}</div>
|
|
371
631
|
) : null}
|
|
372
632
|
{listState === 'empty' ? <div style={S.auditEmpty}>{t('historySessionsEmpty')}</div> : null}
|
|
373
633
|
|
|
634
|
+
{listTruncated ? (
|
|
635
|
+
<div style={S.actionRow}>
|
|
636
|
+
<span style={S.hint} role="status">
|
|
637
|
+
{listLimitReached
|
|
638
|
+
? fmt(t, 'historySessionsLimitReached', { shown: sessions.length, total: listTotal })
|
|
639
|
+
: fmt(t, 'historySessionsTruncated', { shown: sessions.length, total: listTotal })}
|
|
640
|
+
</span>
|
|
641
|
+
{listLimitReached ? null : (
|
|
642
|
+
<Btn onClick={loadMore} busy={loadMoreBusy} disabled={loadMoreBusy || legacyBusy}>
|
|
643
|
+
{t('historyLoadMore')}
|
|
644
|
+
</Btn>
|
|
645
|
+
)}
|
|
646
|
+
</div>
|
|
647
|
+
) : null}
|
|
374
648
|
{sessions.length > 0 ? (
|
|
375
649
|
<div style={S.listBox} role="listbox" aria-label={t('historySessionsTitle')}>
|
|
376
650
|
{sessions.map((entry) => {
|
|
377
|
-
const active = entry.id === pickedId
|
|
651
|
+
const active = entry.id === pickedId && (entry.historyId || null) === pickedHistoryId
|
|
378
652
|
const created = entry.createdAt > 0 ? formatStamp(entry.createdAt) : '—'
|
|
379
653
|
const closed = entry.closedAt ? formatStamp(entry.closedAt) : t('historyOngoing')
|
|
380
654
|
return (
|
|
381
655
|
<button
|
|
382
|
-
key={entry.id}
|
|
656
|
+
key={entry.historyId ? `h:${entry.historyId}` : `l:${entry.id}:${entry.createdAt}`}
|
|
383
657
|
type="button"
|
|
384
658
|
role="option"
|
|
385
659
|
aria-selected={active}
|
|
386
660
|
title={`${entry.title} · ${entry.host || entry.transport}`}
|
|
387
661
|
style={{ ...S.listRow, ...(active ? S.listRowActive : null) }}
|
|
388
|
-
onClick={() => selectSession(entry
|
|
662
|
+
onClick={() => selectSession(entry)}
|
|
389
663
|
>
|
|
390
664
|
<span style={S.listRowTitle}>{entry.title}</span>
|
|
391
665
|
<span style={S.listRowMeta}>
|
|
@@ -511,7 +785,7 @@ export function HistoryPanel({ t, sessionId, onClose }) {
|
|
|
511
785
|
<input
|
|
512
786
|
type="checkbox"
|
|
513
787
|
checked={autoLog.enabled}
|
|
514
|
-
disabled={autoLogBusy || !logBackend}
|
|
788
|
+
disabled={autoLogBusy || autoLogLoading || autoLogError !== null || !logBackend || autoLog.needsReview}
|
|
515
789
|
onChange={() => toggleAutoLog()}
|
|
516
790
|
style={S.pickBox}
|
|
517
791
|
/>
|
|
@@ -520,6 +794,28 @@ export function HistoryPanel({ t, sessionId, onClose }) {
|
|
|
520
794
|
<span style={S.hint}>
|
|
521
795
|
{autoLog.enabled ? fmt(t, 'historyAutoLogWhere', { dir: autoLog.dir }) : t('historyAutoLogOffHint')}
|
|
522
796
|
</span>
|
|
797
|
+
{autoLogLoading ? <div style={S.hint} role="status">{t('historyAutoLogLoading')}</div> : null}
|
|
798
|
+
{autoLogError !== null ? <div style={S.formError} role="alert">{fmt(t, 'historyAutoLogLoadFailed', { message: autoLogError })}</div> : null}
|
|
799
|
+
{autoLog.needsReview ? (
|
|
800
|
+
<div style={S.hint} role="status">
|
|
801
|
+
{t('historyAutoLogLegacyReview')}
|
|
802
|
+
</div>
|
|
803
|
+
) : null}
|
|
804
|
+
{autoLog.needsReview ? (
|
|
805
|
+
<div style={S.hint} role="status">
|
|
806
|
+
{fmt(t, 'historyAutoLogLegacyPath', { dir: autoLog.dir })}
|
|
807
|
+
</div>
|
|
808
|
+
) : null}
|
|
809
|
+
{autoLog.needsReview ? (
|
|
810
|
+
<div style={S.actionRow}>
|
|
811
|
+
<Btn onClick={() => toggleAutoLog(false)} disabled={autoLogBusy || autoLogLoading || autoLogError !== null || !logBackend}>
|
|
812
|
+
{t('historyAutoLogLegacyKeepOff')}
|
|
813
|
+
</Btn>
|
|
814
|
+
<Btn onClick={confirmLegacyEnable} disabled={autoLogBusy || autoLogLoading || autoLogError !== null || !logBackend}>
|
|
815
|
+
{t('historyAutoLogLegacyEnable')}
|
|
816
|
+
</Btn>
|
|
817
|
+
</div>
|
|
818
|
+
) : null}
|
|
523
819
|
|
|
524
820
|
{exportError ? (
|
|
525
821
|
<div style={S.formError} role="alert">
|
|
@@ -529,6 +825,23 @@ export function HistoryPanel({ t, sessionId, onClose }) {
|
|
|
529
825
|
{exported ? (
|
|
530
826
|
<div style={S.exportBox} role="status">
|
|
531
827
|
<div style={S.hint}>{fmt(t, 'historyExportWhere', { dir: exported.dir || '' })}</div>
|
|
828
|
+
{((Number.isInteger(exported.skippedTotal) ? exported.skippedTotal : (exported.skipped || []).length) > 0) ? (
|
|
829
|
+
<div style={S.hint}>
|
|
830
|
+
{fmt(t, 'historyExportSkipped', {
|
|
831
|
+
count: Number.isInteger(exported.skippedTotal) ? exported.skippedTotal : (exported.skipped || []).length,
|
|
832
|
+
sessions: (exported.skipped || []).map((entry) => entry.sessionId).join(', '),
|
|
833
|
+
})}
|
|
834
|
+
</div>
|
|
835
|
+
) : null}
|
|
836
|
+
{exported.omitted ? (
|
|
837
|
+
<div style={S.hint}>
|
|
838
|
+
{fmt(t, 'historyExportOmitted', {
|
|
839
|
+
count: exported.omitted.count,
|
|
840
|
+
reason: exported.omitted.reason,
|
|
841
|
+
limit: exported.omitted.limit,
|
|
842
|
+
})}
|
|
843
|
+
</div>
|
|
844
|
+
) : null}
|
|
532
845
|
{(exported.files || []).map((file) => (
|
|
533
846
|
<div key={file.path} style={S.exportRow}>
|
|
534
847
|
<span style={S.exportPath} title={file.path}>{file.path}</span>
|
package/client/api.js
CHANGED
|
@@ -59,9 +59,9 @@ export function currentOwner() {
|
|
|
59
59
|
/**
|
|
60
60
|
* Whether a method scopes its data to one AI session.
|
|
61
61
|
*
|
|
62
|
-
* Profiles, saved scripts and the auto-log switch are host-wide settings,
|
|
63
|
-
*
|
|
64
|
-
* never
|
|
62
|
+
* Profiles, saved scripts and the auto-log switch are host-wide settings, so
|
|
63
|
+
* those never receive an owner. History export is owner-scoped: `all` means
|
|
64
|
+
* every session owned by the current DSH session, never every journal on disk.
|
|
65
65
|
*
|
|
66
66
|
* @param method - RPC method name.
|
|
67
67
|
* @returns true when the owner should be attached.
|
|
@@ -70,6 +70,7 @@ function ownerScoped(method) {
|
|
|
70
70
|
return /^(sessions|permission|lock|read|audit)\./.test(method)
|
|
71
71
|
|| method === 'history.sessions'
|
|
72
72
|
|| method === 'history.query'
|
|
73
|
+
|| method === 'history.export'
|
|
73
74
|
|| method === 'batch.run'
|
|
74
75
|
}
|
|
75
76
|
|
|
@@ -613,6 +614,10 @@ export function historySessions(options = {}) {
|
|
|
613
614
|
if (since !== undefined) params.since = since
|
|
614
615
|
const until = definedNumber(options.until)
|
|
615
616
|
if (until !== undefined) params.until = until
|
|
617
|
+
const offset = definedNumber(options.offset)
|
|
618
|
+
if (offset !== undefined) params.offset = offset
|
|
619
|
+
const snapshot = definedString(options.snapshot)
|
|
620
|
+
if (snapshot !== undefined) params.snapshot = snapshot
|
|
616
621
|
return rpc('history.sessions', params)
|
|
617
622
|
}
|
|
618
623
|
|
|
@@ -638,6 +643,39 @@ export function historyExport(params = {}) {
|
|
|
638
643
|
return rpc('history.export', params)
|
|
639
644
|
}
|
|
640
645
|
|
|
646
|
+
/**
|
|
647
|
+
* List pre-upgrade, ownerless history for the explicit human legacy view.
|
|
648
|
+
*
|
|
649
|
+
* The GUI always injects an owner, so these entries need a dedicated human-only
|
|
650
|
+
* path. No model tool exposes these methods; the Host rejects non-human actors.
|
|
651
|
+
*
|
|
652
|
+
* @param params - `{ limit?, since?, until? }`.
|
|
653
|
+
* @returns `{ sessions: CatalogEntry[] }`.
|
|
654
|
+
*/
|
|
655
|
+
export function legacyHistorySessions(params = {}) {
|
|
656
|
+
return rpc('history.legacy.sessions', params)
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
/**
|
|
660
|
+
* Query one catalogue legacy journal (human legacy view only).
|
|
661
|
+
*
|
|
662
|
+
* @param params - `{ sessionId, since?, until?, search?, context?, maxMatches?, maxBytes? }`.
|
|
663
|
+
* @returns the normalized history query result.
|
|
664
|
+
*/
|
|
665
|
+
export function legacyHistoryQuery(params = {}) {
|
|
666
|
+
return rpc('history.legacy.query', params)
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
/**
|
|
670
|
+
* Export one catalogue legacy journal (human legacy view only).
|
|
671
|
+
*
|
|
672
|
+
* @param params - `{ sessionId, since?, until? }`.
|
|
673
|
+
* @returns `{ dir, files }`.
|
|
674
|
+
*/
|
|
675
|
+
export function legacyHistoryExport(params = {}) {
|
|
676
|
+
return rpc('history.legacy.export', params)
|
|
677
|
+
}
|
|
678
|
+
|
|
641
679
|
/**
|
|
642
680
|
* Read the auto-log (write-to-file) switch.
|
|
643
681
|
*
|
|
@@ -665,6 +703,8 @@ export function historyQuery(params = {}) {
|
|
|
665
703
|
const value = definedNumber(params[key])
|
|
666
704
|
if (value !== undefined) payload[key] = value
|
|
667
705
|
}
|
|
706
|
+
const historyId = definedString(params.historyId)
|
|
707
|
+
if (historyId !== undefined) payload.historyId = historyId
|
|
668
708
|
const search = definedString(params.search)
|
|
669
709
|
if (search !== undefined) payload.search = search
|
|
670
710
|
return rpc('history.query', payload)
|
|
@@ -782,6 +822,7 @@ export function normalizeCatalogEntry(raw) {
|
|
|
782
822
|
closedAt: asNumber(source.closedAt),
|
|
783
823
|
bytes: asNumber(source.bytes) ?? 0,
|
|
784
824
|
lastTs: asNumber(source.lastTs) ?? 0,
|
|
825
|
+
historyId: asString(source.historyId),
|
|
785
826
|
}
|
|
786
827
|
}
|
|
787
828
|
|