dsh-manual-compact-plugin 0.2.1 → 0.2.3

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.
Files changed (2) hide show
  1. package/lib/index.js +16 -4
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -129,12 +129,22 @@ function resolveAgent(agents, sessionId) {
129
129
  * Supports cancellation through `signal` and reports progress through
130
130
  * `onProgress`. Returns the outcome including a readable file path.
131
131
  */
132
- async function executeCompact(ctx, agents, request, signal, onProgress) {
132
+ async function executeCompact(ctx, agents, request, signal, onProgress, resolvedCompaction) {
133
133
  const resolved = resolveAgent(agents, request.sessionId)
134
134
  const agent = resolved.agent
135
- const compaction = agent && agent.ctx && agent.ctx.get('compaction')
135
+ // Prefer the compaction reference captured at plugin activation (the same
136
+ // seam `/compact` uses). Fall back to the agent's own context, then to a
137
+ // request-time lookup, and report exactly which source is available.
138
+ const rootCompaction = resolvedCompaction !== undefined
139
+ ? resolvedCompaction
140
+ : (ctx && typeof ctx.get === 'function' ? ctx.get('compaction') : undefined)
141
+ const agentCompaction = agent && agent.ctx && typeof agent.ctx.get === 'function' ? agent.ctx.get('compaction') : undefined
142
+ const compaction = rootCompaction || agentCompaction
136
143
  if (!agent || !compaction) {
137
- const diag = resolved.diagnostic || (agent ? '该会话的 agent 未提供 compaction 服务。' : '当前会话暂时没有可用的压缩服务。')
144
+ const diag = resolved.diagnostic
145
+ || (agent
146
+ ? `compaction 服务不可用(host 根:${rootCompaction ? '有' : '无'},agent ctx:${agentCompaction ? '有' : '无'})。`
147
+ : '当前会话暂时没有可用的压缩服务。')
138
148
  return { ok: false, shadowed: 0, message: diag, cancelled: false, file: '' }
139
149
  }
140
150
  const records = []
@@ -182,6 +192,8 @@ function apply(ctx, config) {
182
192
  let lastHandledNonce = null
183
193
  let handling = null
184
194
  const controllers = new Map() // sessionId -> AbortController
195
+ // Capture the compaction seam at activation, like `/compact` does.
196
+ const compactionAtApply = (typeof ctx.get === 'function') ? ctx.get('compaction') : undefined
185
197
 
186
198
  const handle = () => {
187
199
  const current = getter()
@@ -209,7 +221,7 @@ function apply(ctx, config) {
209
221
  const onProgress = async (p) => {
210
222
  try { await ctx.settings.update(NS, { progress: p }) } catch {}
211
223
  }
212
- const result = await executeCompact(ctx, ctx.agents, request, controller.signal, onProgress)
224
+ const result = await executeCompact(ctx, ctx.agents, request, controller.signal, onProgress, compactionAtApply)
213
225
  await ctx.settings.update(NS, {
214
226
  request: null,
215
227
  progress: null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-manual-compact-plugin",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Manual context compaction for DeepSeek Harness: keep the latest N conversation items with stop or batch mode and a per-session compaction archive — embedded in the context meter popup when the meter panel slot exists, or a composer button otherwise.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",