dsh-manual-compact-plugin 0.2.0 → 0.2.1

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 +29 -2
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -99,16 +99,43 @@ const ERROR_MESSAGES = {
99
99
  persistence: '摘要生成完成,但保存会话失败。',
100
100
  }
101
101
 
102
+ /** Resolve a live agent for a client-provided session id. */
103
+ function resolveAgent(agents, sessionId) {
104
+ if (!agents) return { agent: undefined, diagnostic: '' }
105
+ try {
106
+ let agent = agents.get(String(sessionId))
107
+ if (!agent) {
108
+ // Fall back to scanning the registry by session.$id / session.id.
109
+ const wanted = String(sessionId)
110
+ for (const a of agents.list()) {
111
+ const sess = a && a.session
112
+ const sid = sess && (sess.$id !== undefined ? String(sess.$id) : sess.id !== undefined ? String(sess.id) : '')
113
+ if (sid === wanted) { agent = a; break }
114
+ }
115
+ }
116
+ if (agent) return { agent, diagnostic: '' }
117
+ const ids = (agents.list() || []).map((a) => {
118
+ const sess = a && a.session
119
+ return sess && sess.$id !== undefined ? String(sess.$id) : sess && sess.id !== undefined ? String(sess.id) : '?'
120
+ })
121
+ return { agent: undefined, diagnostic: `未能找到 id=${String(sessionId)} 的活跃会话(当前活跃 agent 数=${(agents.list() || []).length},其 session id:${ids.length ? ids.join(', ') : '无'})。` }
122
+ } catch (error) {
123
+ return { agent: undefined, diagnostic: `解析会话失败:${error && error.message ? error.message : String(error)}。` }
124
+ }
125
+ }
126
+
102
127
  /**
103
128
  * Run one manual compaction request against the requesting session.
104
129
  * Supports cancellation through `signal` and reports progress through
105
130
  * `onProgress`. Returns the outcome including a readable file path.
106
131
  */
107
132
  async function executeCompact(ctx, agents, request, signal, onProgress) {
108
- const agent = agents.get(request.sessionId)
133
+ const resolved = resolveAgent(agents, request.sessionId)
134
+ const agent = resolved.agent
109
135
  const compaction = agent && agent.ctx && agent.ctx.get('compaction')
110
136
  if (!agent || !compaction) {
111
- return { ok: false, shadowed: 0, message: '当前会话暂时没有可用的压缩服务。', cancelled: false, file: '' }
137
+ const diag = resolved.diagnostic || (agent ? '该会话的 agent 未提供 compaction 服务。' : '当前会话暂时没有可用的压缩服务。')
138
+ return { ok: false, shadowed: 0, message: diag, cancelled: false, file: '' }
112
139
  }
113
140
  const records = []
114
141
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-manual-compact-plugin",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
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",