polygram 0.8.0-rc.8 → 0.8.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.
@@ -9,7 +9,7 @@
9
9
  "plugins": [
10
10
  {
11
11
  "name": "polygram",
12
- "description": "Telegram integration for Claude Code that preserves the OpenClaw per-chat session model. Migration target for OpenClaw users. Bundles /polygram:status|logs|pair-code|approvals admin commands and a history skill.",
12
+ "description": "Telegram integration for Claude Code that preserves the OpenClaw per-chat session model. Migration target for OpenClaw users. 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.",
13
13
  "category": "integration",
14
14
  "source": "./",
15
15
  "homepage": "https://github.com/shumkov/polygram"
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "$schema": "https://anthropic.com/claude-code/plugin.schema.json",
3
3
  "name": "polygram",
4
- "version": "0.8.0-rc.8",
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 and a history skill.",
4
+ "version": "0.8.0",
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",
8
8
  "openclaw",
@@ -98,9 +98,17 @@
98
98
  "cwd": "/Users/you/admin-agent",
99
99
  "requireMention": true,
100
100
  "isolateTopics": true,
101
+ "_comment_topics": "rc.48: each topic entry is EITHER a string (legacy: just a label) OR an object with optional fields {name, agent, cwd, model, effort, permissionMode}. Object form lets a topic override chat-level config. Per-topic permissionMode overrides chat-level — typical use: scope one topic to permissionMode:'default' (so settings.json gates apply) while the rest of the chat stays on bypassPermissions. Object form requires isolateTopics: true (each topic gets its own SDK Query); polygram emits a startup warning otherwise.",
101
102
  "topics": {
102
103
  "100": "Customer A",
103
- "200": "Customer B"
104
+ "200": {
105
+ "name": "Customer B",
106
+ "agent": "customer-b-helper",
107
+ "cwd": "/Users/you/customer-b-projects",
108
+ "model": "opus",
109
+ "effort": "high",
110
+ "permissionMode": "default"
111
+ }
104
112
  }
105
113
  },
106
114
 
@@ -2,35 +2,72 @@
2
2
  * Detect "stop working on the current turn" signals in natural language.
3
3
  *
4
4
  * Mirrors OpenClaw's isAbortRequestText semantics: users should be able to
5
- * say "stop" / "подожди" / "cancel" / or just `/stop` and have polygram
5
+ * say "stop" / "стоп" / "cancel" / or just `/stop` and have polygram
6
6
  * interrupt the in-flight turn instead of queueing the message behind it.
7
7
  *
8
8
  * Conservative on purpose. False positives hijack user intent — "stop using
9
9
  * emoji" should NOT abort. So we require ONE of:
10
10
  * 1. The whole message (after stripping leading @-mention + trailing
11
- * punctuation) is an exact match against a known abort phrase, OR
11
+ * punctuation) is an exact match against a known abort phrase
12
+ * (HARD or SOFT phrases — see below), OR
12
13
  * 2. It starts with an explicit slash command: /stop, /abort, /cancel, OR
13
- * 3. The FIRST SENTENCE (split on . ! ?) is an exact abort phrase. This
14
- * catches "Stop. I'll ask in another session." — clear abort intent
15
- * with continuation explaining what comes next. Comma is not a split
16
- * character ("Stop, look here" is ambiguous and stays non-abort).
14
+ * 3. The FIRST SENTENCE (split on . ! ?) is an exact match against the
15
+ * HARD phrases ONLY. Catches "Stop. I'll ask in another session." —
16
+ * clear abort intent with continuation. Does NOT trigger on
17
+ * "Wait? Something is off..." (rc.41 false-positive fix soft words
18
+ * like "wait" / "hold on" are too conversational to abort on
19
+ * first-sentence alone).
20
+ *
21
+ * Hard phrases (whole-message OR first-sentence trigger):
22
+ * English: stop, cancel, abort, halt
23
+ * Russian: стоп, остановись, остановить, отмена, прекрати, прекращай,
24
+ * хватит, отставить
25
+ *
26
+ * Soft phrases (whole-message ONLY):
27
+ * English: wait, hold on, hold up, nevermind, never mind, nvm,
28
+ * forget it, forget that
29
+ * Russian: подожди, подожди-ка, забей, не надо, отмени
30
+ *
31
+ * The split exists because "wait", "hold on", "подожди" are commonly used
32
+ * as conversational openers ("Wait? There is something wrong..." — Ivan DM
33
+ * 2026-05-01 19:01) where the user is NOT asking the bot to stop, they're
34
+ * flagging an issue. Hard phrases ("stop", "cancel", "abort") are
35
+ * unambiguously about ending the current task.
17
36
  *
18
37
  * Not detected (on purpose):
19
38
  * - "stop using markdown" → first sentence is the whole thing, not exact
20
39
  * - "I said stop" → not at start / not exact match
40
+ * - "Wait? Something is wrong..." (rc.41) — soft word, multi-sentence
41
+ * - "Hold on, let me think" — same shape
21
42
  */
22
43
 
23
- const ABORT_PHRASES = new Set([
44
+ 'use strict';
45
+
46
+ // HARD phrases: unambiguous abort intent. Trigger on whole-message OR
47
+ // first-sentence match.
48
+ const HARD_ABORT_PHRASES = new Set([
24
49
  // English
25
- 'stop', 'wait', 'cancel', 'abort', 'halt',
26
- 'hold on', 'hold up', 'nevermind', 'never mind', 'nvm',
50
+ 'stop', 'cancel', 'abort', 'halt',
51
+ // Russian
52
+ 'стоп', 'остановись', 'остановить',
53
+ 'отмена', 'прекрати', 'прекращай', 'хватит', 'отставить',
54
+ ]);
55
+
56
+ // SOFT phrases: conversational filler that COULD mean abort but commonly
57
+ // doesn't. Whole-message match only.
58
+ const SOFT_ABORT_PHRASES = new Set([
59
+ // English
60
+ 'wait', 'hold on', 'hold up', 'nevermind', 'never mind', 'nvm',
27
61
  'forget it', 'forget that',
28
62
  // Russian
29
- 'стоп', 'подожди', 'подожди-ка', 'остановись', 'остановить',
30
- 'отмена', 'отставить', 'прекрати', 'прекращай', 'хватит',
31
- 'забей', 'не надо', 'отмени',
63
+ 'подожди', 'подожди-ка', 'забей', 'не надо', 'отмени',
32
64
  ]);
33
65
 
66
+ // Combined set for whole-message matching. Kept exported as ABORT_PHRASES
67
+ // for backward compatibility with any callers / tests that import it
68
+ // directly.
69
+ const ABORT_PHRASES = new Set([...HARD_ABORT_PHRASES, ...SOFT_ABORT_PHRASES]);
70
+
34
71
  const ABORT_SLASH_RE = /^\/(stop|abort|cancel)(\s|$|@)/i;
35
72
 
36
73
  // Strip leading @botname mentions ("@shumobot stop" → "stop"). Matches any
@@ -58,20 +95,28 @@ function isAbortRequest(text) {
58
95
  const n = normalize(text);
59
96
  if (!n) return false;
60
97
  // Whole-message exact match (capped — a long message that happens to
61
- // start with "stop" is real content, not an abort).
98
+ // start with "stop" is real content, not an abort). HARD or SOFT
99
+ // phrases both qualify here — the user typed JUST that word, which is
100
+ // unambiguous regardless of category.
62
101
  if (n.length <= 40 && ABORT_PHRASES.has(n)) return true;
63
102
 
64
103
  // First-sentence exact match. Splits on . ! ? (NOT comma — "Stop, look
65
- // here" is ambiguous and stays non-abort). The leading @-mention has
66
- // already been stripped by normalize but only on the whole string, so
67
- // we strip it again on the raw text before splitting.
104
+ // here" is ambiguous and stays non-abort). HARD phrases ONLY — soft
105
+ // phrases like "wait" or "hold on" are conversational openers ("Wait?
106
+ // There is something wrong...") and shouldn't hijack a message where
107
+ // the rest contains real content.
68
108
  const head = text.trim().replace(LEADING_MENTION_RE, '');
69
109
  const firstSentence = head.split(/[.!?]/, 1)[0]?.trim().toLowerCase();
70
- if (firstSentence && firstSentence.length <= 40 && ABORT_PHRASES.has(firstSentence)) {
110
+ if (firstSentence && firstSentence.length <= 40 && HARD_ABORT_PHRASES.has(firstSentence)) {
71
111
  return true;
72
112
  }
73
113
 
74
114
  return false;
75
115
  }
76
116
 
77
- module.exports = { isAbortRequest, ABORT_PHRASES };
117
+ module.exports = {
118
+ isAbortRequest,
119
+ ABORT_PHRASES,
120
+ HARD_ABORT_PHRASES,
121
+ SOFT_ABORT_PHRASES,
122
+ };
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Abort-grace tracker — per-session timestamps marking "user just
3
+ * /stop'd this session, suppress the next batch of generic error
4
+ * replies".
5
+ *
6
+ * Why this exists: when the user types /stop (or natural-language
7
+ * "стоп"), polygram calls pm.kill(sessionKey). The kill SIGTERM's
8
+ * the in-flight process — every pending in the queue rejects with
9
+ * "Process killed" or INTERRUPTED. WITHOUT abort-grace, polygram
10
+ * would post "💥 Hit a snag" for each rejected pending, even though
11
+ * the user already saw the /stop ack and these errors are caused
12
+ * by their own action.
13
+ *
14
+ * Timestamp model (vs the earlier "delete after first read" Set):
15
+ * a single /stop can drain many pendings, so we mark a TS and let
16
+ * every error within ABORT_GRACE_MS see "yes, aborted, stay quiet".
17
+ *
18
+ * Closes v6 plan §7.1 G11 unit gate.
19
+ */
20
+
21
+ 'use strict';
22
+
23
+ const DEFAULT_ABORT_GRACE_MS = 15_000;
24
+
25
+ /**
26
+ * @param {object} [opts]
27
+ * @param {number} [opts.windowMs] — grace window (default 15s)
28
+ * @param {() => number} [opts.now] — clock injection for tests
29
+ */
30
+ function createAbortGrace({ windowMs = DEFAULT_ABORT_GRACE_MS, now = () => Date.now() } = {}) {
31
+ const aborted = new Map(); // sessionKey → ts of abort
32
+
33
+ function mark(sessionKey) {
34
+ if (!sessionKey) return;
35
+ const ts = now();
36
+ aborted.set(sessionKey, ts);
37
+ // Sweep old entries opportunistically. Use 2× window so a
38
+ // session that's marked-and-checked at the boundary doesn't
39
+ // disappear before the check completes.
40
+ for (const [k, t] of aborted) {
41
+ if (ts - t > windowMs * 2) aborted.delete(k);
42
+ }
43
+ }
44
+
45
+ function isRecent(sessionKey) {
46
+ const ts = aborted.get(sessionKey);
47
+ return ts != null && (now() - ts) < windowMs;
48
+ }
49
+
50
+ function clear(sessionKey) {
51
+ aborted.delete(sessionKey);
52
+ }
53
+
54
+ return {
55
+ mark,
56
+ isRecent,
57
+ clear,
58
+ get size() { return aborted.size; },
59
+ };
60
+ }
61
+
62
+ module.exports = { createAbortGrace, DEFAULT_ABORT_GRACE_MS };