polygram 0.47.0 → 0.47.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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://anthropic.com/claude-code/plugin.schema.json",
3
3
  "name": "polygram",
4
- "version": "0.47.0",
4
+ "version": "0.47.1",
5
5
  "description": "Telegram integration for Claude Code that preserves the OpenClaw per-chat session model. Migration target for OpenClaw users. Multi-bot, multi-chat, per-topic isolation; SQLite transcripts; inline-keyboard approvals. Bundles /polygram:status|logs|pair-code|approvals admin commands plus history (transcript queries) and polygram-send (out-of-turn IPC sends with file-upload validation) skills.",
6
6
  "keywords": [
7
7
  "telegram",
@@ -231,23 +231,25 @@ function settleCodexFailedGeneration(rawDb, input) {
231
231
  ) {
232
232
  conflict('Codex provider session does not match the failed generation');
233
233
  }
234
- const deleted = rawDb.prepare(`
235
- DELETE FROM agent_runtime_sessions
236
- WHERE session_key = ?
237
- AND namespace = ?
238
- AND provider = 'codex'
239
- AND provider_session_id = ?
240
- AND app_server_session_id IS ?
241
- AND generation_id IS ?
242
- `).run(
243
- sessionKey,
244
- CODEX_APP_SERVER_NAMESPACE,
245
- providerSessionId,
246
- appServerSessionId,
247
- provider.generation_id,
248
- );
249
- if (deleted.changes !== 1) {
250
- conflict('Codex provider session changed during settlement');
234
+ if (reason !== 'thread-attach-outcome-unknown') {
235
+ const deleted = rawDb.prepare(`
236
+ DELETE FROM agent_runtime_sessions
237
+ WHERE session_key = ?
238
+ AND namespace = ?
239
+ AND provider = 'codex'
240
+ AND provider_session_id = ?
241
+ AND app_server_session_id IS ?
242
+ AND generation_id IS ?
243
+ `).run(
244
+ sessionKey,
245
+ CODEX_APP_SERVER_NAMESPACE,
246
+ providerSessionId,
247
+ appServerSessionId,
248
+ provider.generation_id,
249
+ );
250
+ if (deleted.changes !== 1) {
251
+ conflict('Codex provider session changed during settlement');
252
+ }
251
253
  }
252
254
  }
253
255
 
@@ -265,6 +265,8 @@ const CODEX_ERROR_CODES = {
265
265
  ], CODEX_ERROR_SHAPES.childExit),
266
266
  CODEX_RPC_NOT_SENT: CODEX_ERROR_SHAPES.notSent,
267
267
  CODEX_RPC_ERROR: CODEX_ERROR_SHAPES.providerError,
268
+ CODEX_THREAD_UNAVAILABLE: stableCodeShape('codexThreadUnavailable',
269
+ '⚠️ The saved Codex conversation is unavailable in this workspace. No message was sent. Use /new to start a fresh conversation after cleanup completes.'),
268
270
  CODEX_DAEMON_GENERATION_BUSY: CODEX_ERROR_SHAPES.busy,
269
271
  };
270
272
 
@@ -267,54 +267,78 @@ function createSlashCommands({
267
267
 
268
268
  // /new + /reset + /clear — fresh session (all synonyms)
269
269
  if (botAllowsCommands && (text === '/new' || text === '/reset' || text === '/clear')) {
270
- let runtimeView = null;
271
- if (typeof resolveRuntimeView === 'function') {
270
+ const releaseIntent = await intentLock.acquire(sessionKey);
271
+ try {
272
+ let runtimeView = null;
273
+ if (typeof resolveRuntimeView === 'function') {
274
+ try {
275
+ runtimeView = await resolveRuntimeView({
276
+ sessionKey,
277
+ chatId,
278
+ threadId: threadIdStr,
279
+ });
280
+ } catch (error) {
281
+ logger.error?.(
282
+ `[${label}] ${text} runtime view failed: `
283
+ + `${error?.code || error?.name || 'unknown'}`,
284
+ );
285
+ await sendReply(
286
+ 'Runtime status is temporarily unavailable; the active session was not changed.',
287
+ );
288
+ return true;
289
+ }
290
+ }
291
+ const codex = isCodexRuntimeView(runtimeView);
292
+ let drained = 0;
272
293
  try {
273
- runtimeView = await resolveRuntimeView({
274
- sessionKey,
275
- chatId,
276
- threadId: threadIdStr,
277
- });
278
- } catch (error) {
279
- logger.error?.(
280
- `[${label}] ${text} runtime view failed: `
281
- + `${error?.code || error?.name || 'unknown'}`,
282
- );
294
+ // A fresh session retires the process that owns any open question.
295
+ // Deliberately before the reset: if the reset then fails, the safe
296
+ // outcome is still that nothing exact was kept.
297
+ await retireQuestionSession?.(sessionKey);
298
+ const contained = codex ? pm.get(sessionKey) : null;
299
+ if (contained?.containmentClosePromise) {
300
+ await contained.containmentClosePromise;
301
+ const status = await pm.getModelSettingsStatus(sessionKey);
302
+ if (status.outcome !== 'not-loaded') {
303
+ throw new Error('Codex containment ownership is not released');
304
+ }
305
+ }
306
+ const r = await pm.resetSession(sessionKey, { reason: text.slice(1) });
307
+ if (codex) {
308
+ const status = await pm.getModelSettingsStatus(sessionKey);
309
+ const lease = db.getCodexLease();
310
+ if (status.outcome !== 'not-loaded' || (lease && lease.status !== 'clear')) {
311
+ throw new Error('Codex reset ownership is not released');
312
+ }
313
+ db.clearProviderSession(sessionKey, 'codex:app-server');
314
+ if (db.getProviderSession(sessionKey, 'codex:app-server') != null) {
315
+ throw new Error('Codex saved conversation pointer was not cleared');
316
+ }
317
+ }
318
+ drained = r?.drainedPendings ?? 0;
319
+ } catch (err) {
320
+ logger.error?.(`[${label}] resetSession ${text}: ${err.message}`);
283
321
  await sendReply(
284
- 'Runtime status is temporarily unavailable; the active session was not changed.',
322
+ codex
323
+ ? '✨ Couldn’t start a fresh Codex thread because cleanup was not proven; the prior Codex thread may be unchanged.'
324
+ : '✨ Couldn’t start a fresh Claude session; the prior session may be unchanged.',
285
325
  );
286
326
  return true;
287
327
  }
288
- }
289
- const codex = isCodexRuntimeView(runtimeView);
290
- let drained = 0;
291
- try {
292
- // A fresh session retires the process that owns any open question.
293
- // Deliberately before the reset: if the reset then fails, the safe
294
- // outcome is still that nothing exact was kept.
295
- await retireQuestionSession?.(sessionKey);
296
- const r = await pm.resetSession(sessionKey, { reason: text.slice(1) });
297
- drained = r?.drainedPendings ?? 0;
298
- } catch (err) {
299
- logger.error?.(`[${label}] resetSession ${text}: ${err.message}`);
328
+ contextHintShown.delete(sessionKey);
329
+ logEvent('session-reset-command', {
330
+ chat_id: chatId, command: commandVerb(), drained_pendings: drained,
331
+ user_id: cmdUserId,
332
+ });
300
333
  await sendReply(
301
334
  codex
302
- ? '✨ Couldn’t start a fresh Codex thread because cleanup was not proven; the prior Codex thread may be unchanged.'
303
- : '✨ Couldn’t start a fresh Claude session; the prior session may be unchanged.',
335
+ ? '✨ Started a fresh Codex thread.'
336
+ : '✨ Started a fresh session.',
304
337
  );
305
338
  return true;
339
+ } finally {
340
+ releaseIntent();
306
341
  }
307
- contextHintShown.delete(sessionKey);
308
- logEvent('session-reset-command', {
309
- chat_id: chatId, command: commandVerb(), drained_pendings: drained,
310
- user_id: cmdUserId,
311
- });
312
- await sendReply(
313
- codex
314
- ? '✨ Started a fresh Codex thread.'
315
- : '✨ Started a fresh session.',
316
- );
317
- return true;
318
342
  }
319
343
 
320
344
  // SDK pm applies model/effort changes live via setModel /
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polygram",
3
- "version": "0.47.0",
3
+ "version": "0.47.1",
4
4
  "description": "Telegram daemon for Claude Code that preserves the OpenClaw per-chat session model. Migration path for OpenClaw users moving to Claude Code.",
5
5
  "main": "lib/ipc/client.js",
6
6
  "bin": {
@@ -71,7 +71,7 @@
71
71
  "dependencies": {
72
72
  "@anthropic-ai/claude-agent-sdk": "0.3.322",
73
73
  "@modelcontextprotocol/sdk": "^1.29.0",
74
- "@shumkov/orchestra": "0.12.2",
74
+ "@shumkov/orchestra": "0.12.3",
75
75
  "acorn": "8.18.0",
76
76
  "better-sqlite3": "^12.9.0",
77
77
  "grammy": "^1.42.0",