dsh-efm-integration 0.4.6 → 0.5.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/README.md CHANGED
@@ -16,7 +16,7 @@ upstream DeepSeek Harness checkout.
16
16
  | `skill-guard` | Denies configured tools until their required skills have been loaded. |
17
17
  | `command-guard` | Refuses long foreground sleeps and filesystem-root scans before execution. |
18
18
  | `bundled-skill` | Ships the `powershell-usage` skill and exposes it without a user-directory copy. |
19
- | `archive-cleaner` | Adds a sidebar page that permanently deletes archived Sessions and their descendants. |
19
+ | `archive-cleaner` | Adds a sidebar page for safe or forced deletion of archived roots and their subagent descendants; live Sessions finish after a restart. |
20
20
  | `lsp-servers` | Owns the DSH LSP stack and adds a sidebar page to enable or disable language servers without restarting. |
21
21
 
22
22
  All host plugins are mounted by `cordis.patch.yml`. `client.js` provides the web
@@ -119,11 +119,16 @@ A saved prompt activates **pure mode** for its target:
119
119
  routing, MCP instructions, tool guidance, and other plugins' sections are not
120
120
  sent.
121
121
  - `skill-router` stops injecting user-role messages for those sessions.
122
- - Runtime-context snapshots are stripped entirely — including the required
123
- working-directory snapshot that plain suppression keeps. A session that
124
- already retained a snapshot records one "runtime context: none" reminder when
125
- pure mode starts applying; snapshots already committed to history are never
126
- rewritten.
122
+ - Runtime-context snapshots are stripped entirely — including every required
123
+ context that plain suppression keeps (the working-directory snapshot, the
124
+ subagent identity, and any other plugin's required context). The time-context
125
+ plugin's per-step timestamp message is filtered out of the entering messages
126
+ as well. A session that already retained a snapshot records one
127
+ "runtime context: none" reminder when pure mode starts applying; snapshots
128
+ already committed to history are never rewritten.
129
+ - Presets whose persona is a complete prompt (for example the bundled
130
+ `minimal` preset) are overridden as well: the persona section is shadowed in
131
+ the session's scope, so the saved prompt stays the only system prompt.
127
132
  - Tools are denied for agents using the target preset (or for every agent with
128
133
  the all-presets target), so the model receives no tool schemas and cannot
129
134
  execute tools.
@@ -230,22 +235,47 @@ explicit `timeoutMs`, or a narrower path.
230
235
 
231
236
  ## Clear archived Sessions
232
237
 
233
- The web sidebar includes **清空全部存档会话**. It counts the archived root
234
- Sessions and all of their descendant Sessions. Deleting them requires browser
235
- confirmation and the server-side header
236
- `x-dsh-efm-integration-confirm: DELETE_ALL_ARCHIVED`.
238
+ The web sidebar includes **清空全部存档会话**. It shows each archived root as a
239
+ group with its subagent descendants. Ordinary forks are independent Sessions and
240
+ are never included in a root's deletion group.
241
+
242
+ Two actions are available:
243
+
244
+ - **永久删除可删除的会话** uses
245
+ `x-dsh-efm-integration-confirm: DELETE_ALL_ARCHIVED`. It deletes only groups
246
+ with no live Agent and no running turn, subagent, job, or schedule. One busy
247
+ group does not block the other groups.
248
+ - **强制删除全部存档会话** uses
249
+ `x-dsh-efm-integration-confirm: FORCE_DELETE_ARCHIVED`. It first requests a stop
250
+ for every non-blocked group. Groups that become quiescent are deleted
251
+ immediately. Groups that still have a live Agent are queued in
252
+ `$DSH_HOME/plugins/dsh-efm-integration/pending-deletions.json` and finalized
253
+ when DSH next starts, after the Agent and its write handle are released.
237
254
 
238
255
  Deletion removes:
239
256
 
240
- - JSONL Session log directories for archived roots and their descendants;
257
+ - JSONL Session log directories for archived roots and their subagent
258
+ descendants;
241
259
  - the Sessions' Workspace accounting;
242
260
  - their entries in the global archive set.
243
261
 
244
- The operation refuses the whole batch if any target is running or has a live
245
- Agent, if persistence is not JSONL, or if a stored path does not follow the
246
- per-Session `session-*` directory convention. Workspace source files and shared
247
- attachments are preserved. After success the page reloads so the sidebar reflects
248
- the new Session catalog.
262
+ Both actions require DSH authentication and a same-origin POST; force does not
263
+ require the owner principal. Both still refuse non-JSONL persistence, an unknown
264
+ sessions root, or a path outside the per-Session `session-*` directory
265
+ convention; force does not bypass those checks. Workspace source files and shared attachments are preserved.
266
+ After a safe deletion the page reloads; a forced deletion that queued live groups
267
+ shows the restart requirement instead.
268
+
269
+ The route defaults to `dshHomePath('sessions')` and accepts plugin config when
270
+ the JSONL backend uses another root:
271
+
272
+ ```yaml
273
+ - id: dsh-efm-integration-archive-cleaner
274
+ name: 'dsh-efm-integration/archive-cleaner'
275
+ config:
276
+ sessionsRoot: 'D:/dsh-home/sessions'
277
+ forceStopTimeoutMs: 5000
278
+ ```
249
279
 
250
280
  ## Language servers (LSP)
251
281
 
package/README.zh.md CHANGED
@@ -15,7 +15,7 @@ DeepSeek Harness 代码。
15
15
  | `skill-guard` | 在所需技能加载完成之前拒绝被配置的工具。 |
16
16
  | `command-guard` | 在执行前拒绝长时间前台 sleep 与文件系统根目录扫描。 |
17
17
  | `bundled-skill` | 随包提供 `powershell-usage` 技能,无需复制到用户目录。 |
18
- | `archive-cleaner` | 增加一个可永久删除归档会话及其子会话的侧栏页面。 |
18
+ | `archive-cleaner` | 增加侧栏页面,可安全或强制删除归档根及其 subagent 子会话;live 会话在重启后完成删除。 |
19
19
  | `lsp-servers` | 接管 DSH 的 LSP 栈,并提供无需重启即可启停语言服务器的侧栏页面。 |
20
20
 
21
21
  所有宿主插件都由 `cordis.patch.yml` 挂载,`client.js` 提供 Web 侧栏页面。包内的
@@ -103,8 +103,12 @@ DSH。**恢复默认**会删除该文件并恢复本包的执行契约。文本
103
103
  - 该文本成为唯一发送给模型的 system prompt;harness 身份、技能路由、MCP 说明、工具指引以及其他
104
104
  插件的小节全部不发送。
105
105
  - 这些会话中 `skill-router` 停止注入 user 角色消息。
106
- - 运行时上下文快照被整体剥离——包括普通抑制拦不住的必需工作目录快照。已经保留过快照的会话,在
107
- 纯净模式开始生效时会记录一条「运行时上下文:无」的提醒;已提交进历史的快照不会被改写。
106
+ - 运行时上下文快照被整体剥离——包括普通抑制拦不住的各类必需上下文(工作目录快照、subagent 身份,
107
+ 以及其他插件注册的必需条目);time-context 插件每一步追加的时间戳消息也会从进入消息中过滤掉。
108
+ 已经保留过快照的会话,在纯净模式开始生效时会记录一条「运行时上下文:无」的提醒;已提交进历史的
109
+ 快照不会被改写。
110
+ - persona 本身是完整提示词的预设(例如内置的 `minimal`)同样会被覆盖:该 persona 段会在会话
111
+ 作用域内被遮蔽,保存的替换文本仍是唯一的 system prompt。
108
112
  - 使用目标预设的 agent 的工具会被拒绝(选择「全部预设」时则对所有 agent 生效),因此模型看不到
109
113
  工具 schema,也无法执行工具。
110
114
 
@@ -199,19 +203,40 @@ node scripts/repair-reasoning-replay.mjs "$env:USERPROFILE\.dsh\sessions"
199
203
 
200
204
  ## 清空归档会话
201
205
 
202
- Web 侧栏包含 **清空全部存档会话**。它会统计归档根会话及其全部子会话。删除需要浏览器
203
- 确认,以及服务端要求的请求头
204
- `x-dsh-efm-integration-confirm: DELETE_ALL_ARCHIVED`。
206
+ Web 侧栏包含 **清空全部存档会话**。它按归档根分组显示会话及其 subagent 子会话。普通 fork
207
+ 是独立会话,不会被算进某个根的删除组。
208
+
209
+ 页面提供两个操作:
210
+
211
+ - **永久删除可删除的会话**:请求头为
212
+ `x-dsh-efm-integration-confirm: DELETE_ALL_ARCHIVED`。只删除没有 live Agent、也没有
213
+ 运行中的 turn、subagent、后台任务或计划的组。一个忙碌组不会阻塞其他组。
214
+ - **强制删除全部存档会话**:请求头为
215
+ `x-dsh-efm-integration-confirm: FORCE_DELETE_ARCHIVED`。先对所有未阻止的组请求停止;
216
+ 静默下来的组立即删除。仍有 live Agent 的组会排入
217
+ `$DSH_HOME/plugins/dsh-efm-integration/pending-deletions.json`,在下次启动 DSH、Agent
218
+ 及其写句柄释放后完成删除。
205
219
 
206
220
  删除内容包括:
207
221
 
208
- - 归档根及其子会话的 JSONL 会话日志目录;
222
+ - 归档根及其 subagent 子会话的 JSONL 会话日志目录;
209
223
  - 这些会话的 Workspace 记账;
210
224
  - 它们在全局归档集合中的条目。
211
225
 
212
- 只要批次中有任一目标是运行中的会话、仍有可用 Agent 的会话、非 JSONL 持久化,或存储路径
213
- 不符合每会话 `session-*` 目录约定,整个操作就会被拒绝。Workspace 源码文件与共享附件会被
214
- 保留。成功后页面会重新加载,使侧栏反映新的会话目录。
226
+ 两种操作都需要 DSH 认证和同源 POST;强制删除不要求 owner principal。两种操作都会拒绝非
227
+ JSONL 持久化、未知会话根,或不符合每会话 `session-*` 目录约定的路径;强制删除不会绕过这些
228
+ 检查。Workspace 源码文件与共享附件会被保留。安全删除成功后页面会重新
229
+ 加载;如果强制删除有排队中的 live 会话,页面会显示需要重启 DSH。
230
+
231
+ 路由默认使用 `dshHomePath('sessions')`;JSONL 后端使用其他根目录时可通过插件配置覆盖:
232
+
233
+ ```yaml
234
+ - id: dsh-efm-integration-archive-cleaner
235
+ name: 'dsh-efm-integration/archive-cleaner'
236
+ config:
237
+ sessionsRoot: 'D:/dsh-home/sessions'
238
+ forceStopTimeoutMs: 5000
239
+ ```
215
240
 
216
241
  ## 语言服务器(LSP)
217
242
 
package/client.js CHANGED
@@ -59,51 +59,96 @@ window.__ModuleLoader__.load({
59
59
  }
60
60
 
61
61
  function ArchiveCleanerPage() {
62
- const [state, setState] = useState({ loading: true, count: 0, archivedCount: 0, blocked: [], error: '' })
62
+ const empty = {
63
+ loading: true, count: 0, archivedCount: 0, blocked: [], groups: [], queuedRoots: [],
64
+ restartRequired: false, sessionsRoot: '', pendingError: '', error: '', notice: '',
65
+ }
66
+ const [state, setState] = useState(empty)
63
67
  const [busy, setBusy] = useState(false)
64
68
 
65
- useEffect(() => {
66
- const controller = new AbortController()
67
- fetch(ARCHIVE_ENDPOINT, { signal: controller.signal, headers: { accept: 'application/json' } })
69
+ const load = (signal) => {
70
+ fetch(ARCHIVE_ENDPOINT, { signal, headers: { accept: 'application/json' } })
68
71
  .then(async response => {
69
72
  const body = await response.json()
70
73
  if (!response.ok) throw new Error(body.error || '无法读取存档会话')
71
- setState({ loading: false, count: body.count, archivedCount: body.archivedCount, blocked: body.blocked || [], error: '' })
74
+ setState({
75
+ loading: false,
76
+ count: body.count || 0,
77
+ archivedCount: body.archivedCount || 0,
78
+ blocked: body.blocked || [],
79
+ groups: body.groups || [],
80
+ queuedRoots: body.queuedRoots || [],
81
+ restartRequired: body.restartRequired === true,
82
+ sessionsRoot: body.sessionsRoot || '',
83
+ pendingError: body.pendingError || '',
84
+ error: '',
85
+ notice: '',
86
+ })
72
87
  })
73
88
  .catch(error => {
74
- if (controller.signal.aborted) return
89
+ if (signal?.aborted) return
75
90
  setState(current => ({ ...current, loading: false, error: String(error.message || error) }))
76
91
  })
92
+ }
93
+
94
+ useEffect(() => {
95
+ const controller = new AbortController()
96
+ load(controller.signal)
77
97
  return () => controller.abort()
78
98
  }, [])
79
99
 
80
- const clear = async () => {
81
- if (state.count === 0) return
82
- const confirmed = window.confirm(
83
- `将永久删除 ${state.count} 个存档会话(含子会话),删除后无法恢复。\n\n共享附件和工作区文件会保留。确定继续吗?`,
84
- )
100
+ const submit = async (mode) => {
101
+ if (state.count === 0 && state.archivedCount === 0) return
102
+ const confirmed = window.confirm(mode === 'force'
103
+ ? `将强制停止所有相关会话的 turn、子 Agent、后台任务和计划,并删除 ${state.archivedCount} 个归档根及其子会话。\n\n仍有 live Agent 的会话会在下次启动 DSH 时完成删除;共享附件和工作区文件会保留。确定继续吗?`
104
+ : `将永久删除可删除的 ${state.archivedCount} 个归档根及其子会话,删除后无法恢复。\n\n共享附件和工作区文件会保留。确定继续吗?`)
85
105
  if (!confirmed) return
106
+ if (mode === 'force') {
107
+ const typed = window.prompt('输入“强制删除”以确认强制删除:')
108
+ if (typed !== '强制删除') return
109
+ }
86
110
  setBusy(true)
87
- setState(current => ({ ...current, error: '' }))
111
+ setState(current => ({ ...current, error: '', notice: '' }))
88
112
  try {
89
113
  const response = await fetch(ARCHIVE_ENDPOINT, {
90
114
  method: 'POST',
91
115
  headers: {
92
116
  accept: 'application/json',
93
117
  'content-type': 'application/json',
94
- 'x-dsh-efm-integration-confirm': 'DELETE_ALL_ARCHIVED',
118
+ 'x-dsh-efm-integration-confirm': mode === 'force' ? 'FORCE_DELETE_ARCHIVED' : 'DELETE_ALL_ARCHIVED',
95
119
  },
96
120
  body: '{}',
97
121
  })
98
122
  const body = await response.json()
99
- if (!response.ok || (body.failures && body.failures.length > 0)) {
123
+ if (!response.ok) {
100
124
  throw new Error(
101
125
  body.error
102
- || body.blocked?.map(reason => `暂不能删除:${reason}`).join('\n')
126
+ || body.blocked?.join('\n')
103
127
  || body.failures?.map(failure => `${failure.sessionId}: ${failure.message}`).join('\n')
104
128
  || '删除失败',
105
129
  )
106
130
  }
131
+ if (body.restartRequired) {
132
+ setBusy(false)
133
+ setState(current => ({
134
+ ...current,
135
+ notice: `已停止相关会话;重启 DSH 后将删除排队中的 ${body.queuedRoots?.length || body.queuedSessionIds?.length || 0} 个归档根。`,
136
+ blocked: body.blocked || [],
137
+ restartRequired: true,
138
+ }))
139
+ return
140
+ }
141
+ if ((body.failures && body.failures.length > 0) || (body.blocked && body.blocked.length > 0)) {
142
+ setBusy(false)
143
+ setState(current => ({
144
+ ...current,
145
+ error: [
146
+ ...(body.blocked || []),
147
+ ...(body.failures || []).map(failure => `${failure.sessionId}: ${failure.message}`),
148
+ ].join('\n'),
149
+ }))
150
+ return
151
+ }
107
152
  window.location.reload()
108
153
  } catch (error) {
109
154
  setBusy(false)
@@ -111,29 +156,73 @@ window.__ModuleLoader__.load({
111
156
  }
112
157
  }
113
158
 
159
+ const ready = state.groups.filter(group => group.status === 'ready').length
160
+ const queued = state.groups.filter(group => group.status === 'queued').length
161
+ const statusLabel = status => status === 'ready' ? '可删除'
162
+ : status === 'busy' ? '运行中'
163
+ : status === 'queued' ? '等待重启'
164
+ : '已阻止'
165
+
114
166
  return React.createElement('main', { style: pageStyle }, React.createElement('section', {
115
- style: { ...cardStyle, maxWidth: '640px' },
167
+ style: { ...cardStyle, maxWidth: '760px' },
116
168
  },
117
169
  React.createElement('h1', { style: { margin: '0 0 12px', fontSize: '24px' } }, '清空全部存档会话'),
118
170
  React.createElement('p', { style: { color: '#aaa', lineHeight: 1.7 } },
119
- '永久删除所有归档会话及其子 Agent 日志。共享附件和工作区文件不会被删除,操作无法撤销。'),
171
+ '永久删除归档根会话及其子 Agent 日志。安全删除只处理空闲会话;强制删除会先停止 turn、子 Agent、后台任务和计划,仍有 live Agent 的会话会在下次启动 DSH 时完成删除。共享附件和工作区文件不会被删除。'),
120
172
  React.createElement('p', { style: { fontSize: '18px', fontWeight: 600 } },
121
- state.loading ? '正在统计…' : `当前共有 ${state.count} 个会话(${state.archivedCount} 个归档根会话)`),
173
+ state.loading ? '正在统计…' : `当前共有 ${state.count} 个会话(${state.archivedCount} 个归档根)`),
174
+ React.createElement('p', { style: { color: '#999', fontSize: '13px' } },
175
+ `可删除 ${ready} 组 · 等待重启 ${queued} 组 · 会话根目录:${state.sessionsRoot || '未配置'}`),
176
+ state.restartRequired && React.createElement('div', { style: noticeStyle },
177
+ '有会话已排队等待删除。请重启 DSH,启动时会自动完成删除并清理归档条目。'),
178
+ state.notice && React.createElement('div', { style: noticeStyle }, state.notice),
179
+ state.pendingError && React.createElement('div', { style: noticeStyle }, `待删除清单无法读取:${state.pendingError}`),
122
180
  state.blocked.length > 0 && React.createElement('div', { style: noticeStyle },
123
- '暂不能删除:', React.createElement('ul', null, state.blocked.map((item, index) => React.createElement('li', { key: index }, item)))),
181
+ '部分组暂不能删除:', React.createElement('ul', null, state.blocked.map((item, index) => React.createElement('li', { key: index }, item)))),
124
182
  state.error && React.createElement('pre', {
125
183
  style: { color: '#ff8989', whiteSpace: 'pre-wrap', background: '#f003', padding: '12px', borderRadius: '10px' },
126
184
  }, state.error),
127
- React.createElement('button', {
128
- type: 'button',
129
- disabled: busy || state.loading || state.count === 0 || state.blocked.length > 0,
130
- onClick: clear,
131
- style: {
132
- appearance: 'none', border: 0, borderRadius: '10px', background: '#d94747', color: 'white',
133
- cursor: 'pointer', fontSize: '15px', fontWeight: 600, opacity: busy || state.count === 0 ? 0.45 : 1,
134
- padding: '12px 18px', marginTop: '10px',
135
- },
136
- }, busy ? '正在永久删除…' : '永久删除全部存档会话'),
185
+ React.createElement('h2', { style: { fontSize: '18px', margin: '20px 0 8px' } }, '归档组'),
186
+ state.groups.length === 0
187
+ ? React.createElement('p', { style: { color: '#888' } }, state.loading ? '正在读取…' : '没有归档会话。')
188
+ : React.createElement('ul', { style: { listStyle: 'none', padding: 0, margin: 0 } },
189
+ state.groups.map(group => React.createElement('li', {
190
+ key: group.rootSessionId,
191
+ style: { borderBottom: '1px solid #5553', padding: '10px 0' },
192
+ },
193
+ React.createElement('div', { style: { display: 'flex', gap: '10px', alignItems: 'baseline' } },
194
+ React.createElement('strong', null, group.rootSessionId),
195
+ React.createElement('span', {
196
+ style: {
197
+ color: group.status === 'ready' ? '#7fd08a' : group.status === 'blocked' ? '#ff8989' : '#e0a06b',
198
+ fontSize: '13px',
199
+ },
200
+ }, `${statusLabel(group.status)} · ${group.members.length} 个会话`)),
201
+ group.reasons.length > 0 && React.createElement('div', { style: { color: '#e0a06b', fontSize: '13px' } },
202
+ group.reasons.join('; ')))),
203
+ ),
204
+ React.createElement('div', { style: { display: 'flex', flexWrap: 'wrap', gap: '10px', marginTop: '14px' } },
205
+ React.createElement('button', {
206
+ type: 'button',
207
+ disabled: busy || state.loading || ready === 0,
208
+ onClick: () => submit('safe'),
209
+ style: {
210
+ appearance: 'none', border: 0, borderRadius: '10px', background: '#1f6f43', color: 'white',
211
+ cursor: 'pointer', fontSize: '15px', fontWeight: 600,
212
+ opacity: busy || ready === 0 ? 0.45 : 1, padding: '12px 18px',
213
+ },
214
+ }, busy ? '正在处理…' : '永久删除可删除的会话'),
215
+ React.createElement('button', {
216
+ type: 'button',
217
+ disabled: busy || state.loading || (state.count === 0 && state.archivedCount === 0),
218
+ onClick: () => submit('force'),
219
+ style: {
220
+ appearance: 'none', border: 0, borderRadius: '10px', background: '#d94747', color: 'white',
221
+ cursor: 'pointer', fontSize: '15px', fontWeight: 600,
222
+ opacity: busy || (state.count === 0 && state.archivedCount === 0) ? 0.45 : 1, padding: '12px 18px',
223
+ },
224
+ }, busy ? '正在处理…' : '强制删除全部存档会话'),
225
+ ),
137
226
  ))
138
227
  }
139
228
 
package/cordis.patch.yml CHANGED
@@ -4,6 +4,11 @@
4
4
 
5
5
  - id: dsh-efm-integration-archive-cleaner
6
6
  name: 'dsh-efm-integration/archive-cleaner'
7
+ config:
8
+ # Defaults to dshHomePath('sessions'); set an absolute path when the
9
+ # JSONL session backend uses a custom root.
10
+ # sessionsRoot: 'D:/dsh-home/sessions'
11
+ forceStopTimeoutMs: 5000
7
12
 
8
13
  - id: dsh-efm-integration-prompt
9
14
  name: 'dsh-efm-integration/prompt'
@@ -1,37 +1,108 @@
1
- export interface DeletionSessionSummary {
1
+ import type { LocationValidation, SessionLocation } from './paths.js';
2
+ export type { LocationValidation, SessionLocation } from './paths.js';
3
+ /** Whether a deletion request may stop running work or must refuse it. */
4
+ export type DeletionMode = 'safe' | 'force';
5
+ /** How one archived root group currently behaves. */
6
+ export type ArchiveGroupStatus = 'ready' | 'busy' | 'queued' | 'blocked';
7
+ /** One live or stored Session known to the roster. */
8
+ export interface RosterSession {
2
9
  readonly sessionId: string;
3
10
  readonly parentSessionId?: string;
11
+ readonly origin?: 'subagent';
12
+ readonly isSeeded?: boolean;
4
13
  readonly running: boolean;
14
+ readonly live: boolean;
5
15
  readonly agentAvailable: boolean;
16
+ readonly location?: SessionLocation;
6
17
  }
7
- export interface SessionLocation {
8
- readonly kind: string;
9
- readonly path: string;
18
+ /** One member of an archive root's deletion group. */
19
+ export interface ArchiveMemberInspection {
20
+ readonly sessionId: string;
21
+ readonly parentSessionId?: string;
22
+ readonly origin?: 'subagent';
23
+ readonly running: boolean;
24
+ readonly live: boolean;
25
+ readonly agentAvailable: boolean;
26
+ readonly activity: readonly string[];
27
+ readonly directory?: string;
28
+ readonly missing: boolean;
29
+ readonly reasons: readonly string[];
30
+ }
31
+ /** One archived root and every subagent descendant that must go with it. */
32
+ export interface ArchiveGroupInspection {
33
+ readonly rootSessionId: string;
34
+ readonly members: readonly ArchiveMemberInspection[];
35
+ readonly status: ArchiveGroupStatus;
36
+ readonly reasons: readonly string[];
10
37
  }
38
+ /** Dependencies needed to inspect archived roots without mutating anything. */
11
39
  export interface ArchiveCleanerDependencies {
12
40
  readonly archivedSessionIds: readonly string[];
13
- readonly summaries: readonly DeletionSessionSummary[];
14
- readonly statSession: (sessionId: string) => Promise<{
15
- readonly location?: SessionLocation;
16
- } | undefined>;
41
+ readonly roster: readonly RosterSession[];
42
+ readonly queuedRoots: readonly string[];
43
+ readonly activityOf: (sessionId: string) => Promise<readonly string[]>;
44
+ readonly validateLocation: (location: SessionLocation | undefined) => Promise<LocationValidation>;
45
+ readonly removeDirectory: (directory: string) => Promise<void>;
17
46
  readonly detachSession: (sessionId: string) => Promise<void>;
18
47
  readonly unarchiveSession: (sessionId: string) => Promise<void>;
19
48
  }
20
- export interface ArchiveDeletionPlan {
21
- readonly sessionIds: readonly string[];
22
- readonly archivedSessionIds: readonly string[];
23
- readonly sessionDirectories: readonly string[];
24
- readonly blocked: readonly string[];
49
+ /** Dependencies needed to execute a forced deletion. */
50
+ export interface ArchiveDeletionDependencies extends ArchiveCleanerDependencies {
51
+ readonly stopActivity: (sessionId: string) => Promise<void>;
52
+ readonly waitQuiescent: (sessionIds: readonly string[], timeoutMs: number) => Promise<boolean>;
53
+ /** Final synchronous liveness check immediately before removing files. */
54
+ readonly isLive: (sessionId: string) => boolean;
25
55
  }
56
+ /** Outcome for one archived root group. */
57
+ export interface GroupDeletionResult {
58
+ readonly rootSessionId: string;
59
+ readonly status: 'deleted' | 'queued' | 'blocked' | 'failed';
60
+ readonly deletedSessionIds: readonly string[];
61
+ readonly queuedSessionIds: readonly string[];
62
+ readonly reasons: readonly string[];
63
+ }
64
+ /** One group-level failure, retained for the existing API shape. */
26
65
  export interface ArchiveDeletionFailure {
27
66
  readonly sessionId: string;
28
67
  readonly message: string;
29
68
  }
69
+ /** Complete result of one safe or force deletion request. */
30
70
  export interface ArchiveDeletionResult {
71
+ readonly mode: DeletionMode;
72
+ readonly groups: readonly GroupDeletionResult[];
31
73
  readonly deletedSessionIds: readonly string[];
74
+ readonly queuedSessionIds: readonly string[];
32
75
  readonly blocked: readonly string[];
33
76
  readonly failures: readonly ArchiveDeletionFailure[];
77
+ readonly restartRequired: boolean;
78
+ }
79
+ /** Options for executing a deletion plan. */
80
+ export interface ArchiveDeletionOptions {
81
+ readonly mode: DeletionMode;
82
+ readonly forceStopTimeoutMs?: number;
34
83
  }
35
- export declare function inspectArchivedSessions(deps: ArchiveCleanerDependencies): Promise<ArchiveDeletionPlan>;
36
- export declare function clearArchivedSessions(deps: ArchiveCleanerDependencies): Promise<ArchiveDeletionResult>;
84
+ /**
85
+ * Build the archived-root groups and classify each one. The closure follows
86
+ * only `origin === 'subagent'` children: ordinary forks keep their own log and
87
+ * must never be deleted with the source conversation.
88
+ * @param deps - roster, activity, and path-validation seams.
89
+ * @returns one group per archived root id, in archive order.
90
+ */
91
+ export declare function inspectArchiveGroups(deps: ArchiveCleanerDependencies): Promise<ArchiveGroupInspection[]>;
92
+ /**
93
+ * Execute safe or forced deletion over inspected groups. Safe refuses any
94
+ * group with live work; force stops every non-blocked group first, deletes the
95
+ * quiescent groups, and queues groups that still have a live Session.
96
+ * @param deps - inspection plus stop/wait seams.
97
+ * @param groups - inspected groups from {@link inspectArchiveGroups}.
98
+ * @param options - safe/force mode and the force stop deadline.
99
+ * @returns per-group results and flattened compatibility fields.
100
+ */
101
+ export declare function deleteArchiveGroups(deps: ArchiveDeletionDependencies, groups: readonly ArchiveGroupInspection[], options: ArchiveDeletionOptions): Promise<ArchiveDeletionResult>;
102
+ /**
103
+ * Remove one per-Session directory. `ENOENT` means an earlier attempt already
104
+ * finished; Windows sharing violations are retried by Node's `rm` options.
105
+ * @param directory - validated real Session directory.
106
+ */
107
+ export declare function removeSessionDirectory(directory: string): Promise<void>;
37
108
  //# sourceMappingURL=core.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/archive-cleaner/core.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,SAAS,EAAE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