polygram 0.11.0-rc.6 → 0.11.0-rc.8

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.11.0-rc.6",
4
+ "version": "0.11.0-rc.8",
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",
@@ -365,33 +365,62 @@ class ChannelsProcess extends Process {
365
365
  '--dangerously-load-development-channels', 'server:polygram-bridge',
366
366
  ];
367
367
 
368
- // Parity audit P8: branch on existingSessionId. `--session-id <id>`
369
- // creates a NEW claude session with that id; `--resume <id>` resumes the
370
- // EXISTING conversation. Lazy-respawn after bridge-disconnect must use
371
- // --resume so conversation history is preserved. Mirrors
372
- // tmux-process.js:514-518.
368
+ // Resolve config FIRST so the --resume file-check below has the correct
369
+ // cwd (it picks up topic precedence). Other flags get pushed in order
370
+ // after this.
371
+ const topicConfig = opts.threadId && opts.chatConfig?.topics?.[opts.threadId];
372
+ const agent = topicConfig?.agent || opts.chatConfig?.agent || opts.agent;
373
+ const model = topicConfig?.model || opts.chatConfig?.model || opts.model;
374
+ const effort = topicConfig?.effort || opts.chatConfig?.effort || opts.effort;
375
+ const resolvedCwd = topicConfig?.cwd || opts.chatConfig?.cwd || opts.cwd;
376
+
377
+ // Parity audit P8 + rc.8 fs-guard (2026-05-26 shumorobot Music topic):
378
+ // `--session-id <id>` creates a NEW claude session with that id;
379
+ // `--resume <id>` resumes the EXISTING conversation. Lazy-respawn after
380
+ // bridge-disconnect must use --resume so conversation history is
381
+ // preserved. Mirrors tmux-process.js:514-518.
373
382
  //
374
- // rc.6 note: pre-channels session ids (created by sdk/tmux backends and
375
- // persisted in polygram's DB) are NOT cross-backend compatible claude
376
- // indexes session files under a cwd-derived projects dir that may not
377
- // match what channels-mode passes, leading to silent "No conversation
378
- // found" exit. The fix lives at the data layer, not here: operator
379
- // clears pre-channels session ids from polygram's sessions table before
380
- // flipping a chat to channels (see ops/migrate-to-channels.sql).
381
- if (opts.existingSessionId) {
383
+ // rc.8 ghost-session guard: polygram persists claude_session_id to its
384
+ // DB as soon as the bridge handshakes (onInit), but claude only writes
385
+ // the JSONL after a successful turn. If an early channels attempt fails
386
+ // before claude completes any turn, polygram's DB ends up with a
387
+ // claude_session_id that has NO corresponding file under claude's
388
+ // projects dir. Subsequent `--resume <ghost-id>` makes claude exit
389
+ // clean with "No conversation found" exactly the Music topic stall
390
+ // observed at 04:04:29 (session_id=567c72db never persisted; rc.4
391
+ // pane snapshot proved it).
392
+ //
393
+ // Fix: before passing --resume, verify the session JSONL actually
394
+ // exists under the launch cwd. If not, drop the ghost id and use
395
+ // --session-id with the freshly-generated uuid — claude creates a
396
+ // fresh session and onInit re-upserts the DB row.
397
+ //
398
+ // Resume cases preserved:
399
+ // - in-daemon lazy respawn (file written after first successful turn)
400
+ // - daemon restart on a chat that completed at least one turn
401
+ // Resume cases correctly dropped:
402
+ // - cross-backend stale ids (different cwd → different projects dir)
403
+ // - ghost ids from failed-before-first-turn attempts
404
+ let canResume = false;
405
+ let resumePath = null;
406
+ if (opts.existingSessionId && resolvedCwd) {
407
+ // claude's projects dir naming: cwd with '/' → '-'.
408
+ // Verified live at ~/.claude/projects/-Users-ivanshumkov-Music-rekordbox/
409
+ const cwdMangled = resolvedCwd.replace(/\//g, '-');
410
+ resumePath = path.join(os.homedir(), '.claude', 'projects', cwdMangled, `${opts.existingSessionId}.jsonl`);
411
+ try { canResume = fs.statSync(resumePath).isFile(); } catch { canResume = false; }
412
+ }
413
+ if (canResume) {
382
414
  claudeArgs.push('--resume', opts.existingSessionId);
383
415
  } else {
384
416
  claudeArgs.push('--session-id', this.claudeSessionId);
417
+ if (opts.existingSessionId) {
418
+ this.logger.warn?.(
419
+ `[${this.label}] channels: dropping DB session ${opts.existingSessionId} — ` +
420
+ `no local file at ${resumePath || '<unknown cwd>'}. Starting fresh with ${this.claudeSessionId}.`,
421
+ );
422
+ }
385
423
  }
386
-
387
- // Parity audit P4: per-chat / per-topic agent flag. Without this, chats
388
- // configured with agent='music-curation' / 'shumabit' silently fall back
389
- // to claude's default. Mirrors tmux-process.js:527.
390
- // Topic precedence over chat — same as tmux pattern (parity audit P7).
391
- const topicConfig = opts.threadId && opts.chatConfig?.topics?.[opts.threadId];
392
- const agent = topicConfig?.agent || opts.chatConfig?.agent || opts.agent;
393
- const model = topicConfig?.model || opts.chatConfig?.model || opts.model;
394
- const effort = topicConfig?.effort || opts.chatConfig?.effort || opts.effort;
395
424
  if (agent) claudeArgs.push('--agent', agent);
396
425
  if (model) claudeArgs.unshift('--model', model);
397
426
  if (effort) claudeArgs.push('--effort', effort);
@@ -416,25 +445,19 @@ class ChannelsProcess extends Process {
416
445
  claudeArgs.push('--dangerously-skip-permissions');
417
446
  }
418
447
 
419
- // Parity audit P3: append display-hint so Claude knows it's replying
420
- // through Telegram. Prevents canned strings like "No response requested."
421
- // from leaking as user-visible messages (shumorobot 2026-05-15 incident).
422
- claudeArgs.push('--append-system-prompt', POLYGRAM_DISPLAY_HINT);
423
-
424
- // rc.6 (2026-05-25 shumorobot diagnosis): channels-mode contract is
425
- // NOT obvious to the agent. The bridge's MCP `instructions:` field tells
426
- // claude to use the reply tool, but that's seen only during MCP init and
427
- // gets buried under the agent's own system prompt. Observed live: the
428
- // music-curator agent received user messages via the channel and wrote
429
- // replies INLINE to its TUI instead of calling `mcp__polygram-bridge__reply`,
430
- // so polygram never saw them and every turn timed out after 3 minutes.
431
- //
432
- // Append a SECOND, explicit directive that overrides the agent's default
433
- // conversational behavior. Phrased as a hard rule so it survives whatever
434
- // the agent's system prompt says. Future tuning may move this to a
435
- // shared lib/telegram/channels-protocol-hint.js if it grows; for now
436
- // inline is fine since it's tied to the channels backend implementation.
448
+ // Parity audit P3 + rc.7 (2026-05-26 shumorobot diagnosis): combined
449
+ // system-prompt suffix carrying BOTH the Telegram display rules AND the
450
+ // channels-mode reply-tool contract. Merged into a single
451
+ // --append-system-prompt block — passing two separate
452
+ // --append-system-prompt flags caused MCP server registration to fail
453
+ // (live shumorobot tmux banner: "server:polygram-bridge · no MCP server
454
+ // configured with that name"; claude received no channel messages).
455
+ // Suspected: --append-system-prompt is variadic in claude's CLI and the
456
+ // second flag was eating the subsequent --setting-sources / --mcp-config
457
+ // arguments. Single combined block sidesteps the issue.
437
458
  claudeArgs.push('--append-system-prompt', [
459
+ POLYGRAM_DISPLAY_HINT,
460
+ '',
438
461
  '## polygram channels mode — HARD CONTRACT',
439
462
  '',
440
463
  'You are running inside polygram with the channels backend. Your stdout/TUI',
@@ -472,8 +495,8 @@ class ChannelsProcess extends Process {
472
495
  // --mcp-config MUST be last (variadic flag)
473
496
  claudeArgs.push('--mcp-config', this.mcpConfigPath); // P0 #1: file path, not inline JSON
474
497
 
475
- const cwd = topicConfig?.cwd || opts.chatConfig?.cwd || opts.cwd;
476
- if (cwd) claudeArgs.unshift('--add-dir', cwd);
498
+ // resolvedCwd was computed above (line ~375) for the --resume file-check.
499
+ if (resolvedCwd) claudeArgs.unshift('--add-dir', resolvedCwd);
477
500
 
478
501
  // rc.5 (2026-05-25 shumorobot diagnosis): the launch cwd MUST be the
479
502
  // resolved topic/chat cwd, not just opts.cwd. claude's TUI indexes
@@ -492,7 +515,7 @@ class ChannelsProcess extends Process {
492
515
  // Real tmuxRunner.spawn signature: {name, cwd, command, args, envExtras, paneWidth}
493
516
  await this.runner.spawn({
494
517
  name: tmuxName,
495
- cwd: cwd || opts.cwd || process.cwd(),
518
+ cwd: resolvedCwd || opts.cwd || process.cwd(),
496
519
  command: this.claudeBin,
497
520
  args: claudeArgs,
498
521
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polygram",
3
- "version": "0.11.0-rc.6",
3
+ "version": "0.11.0-rc.8",
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": {