polygram 0.30.0 → 0.32.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.
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +5 -0
- package/config.example.json +2 -0
- package/lib/codex/diagnostics.js +1 -0
- package/lib/codex/runtime-controller.js +81 -20
- package/lib/codex/runtime-profile.js +6 -0
- package/lib/codex/spawn-context.js +13 -4
- package/lib/db/sessions.js +35 -11
- package/lib/db.js +233 -9
- package/lib/handlers/config-callback.js +361 -5
- package/lib/handlers/config-ui.js +74 -16
- package/lib/handlers/dispatcher.js +84 -13
- package/lib/ops/clean-resume.js +358 -0
- package/lib/ops/clean-shutdown.js +84 -0
- package/lib/ops/shutdown-disposition.js +13 -4
- package/lib/process/channels-tool-dispatcher.js +12 -3
- package/lib/runtime-config.js +46 -7
- package/lib/sdk/callbacks.js +2 -0
- package/lib/telegram/api.js +71 -3
- package/lib/telegram/delivery-barrier.js +117 -0
- package/lib/telegram/process-agent-reply.js +18 -2
- package/lib/telegram/rich-edit.js +16 -5
- package/lib/telegram/rich-media.js +18 -2
- package/migrations/018-clean-restart-resume.sql +24 -0
- package/package.json +2 -2
- package/polygram.js +562 -91
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://anthropic.com/claude-code/plugin.schema.json",
|
|
3
3
|
"name": "polygram",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.32.0",
|
|
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",
|
package/README.md
CHANGED
|
@@ -285,6 +285,11 @@ Per-bot flags:
|
|
|
285
285
|
- `replayWindowMs` (default 180000 = 3 min) — boot replay only
|
|
286
286
|
resurrects interrupted turns younger than this. Longer outages drop
|
|
287
287
|
the queue rather than re-dispatching ancient work.
|
|
288
|
+
- `resumeInterruptedCliTurns` (default false) — on a deliberate clean
|
|
289
|
+
restart, strictly resume an interrupted CLI session and send one tracked
|
|
290
|
+
`continue`. Keep this off until the pinned-CLI recovery gate passes for the
|
|
291
|
+
deployed Orchestra version. Crash recovery still re-dispatches the original
|
|
292
|
+
message.
|
|
288
293
|
|
|
289
294
|
See `config.example.json` for the full schema.
|
|
290
295
|
|
package/config.example.json
CHANGED
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
"attachmentConcurrency": 6,
|
|
17
17
|
"queueWarnThreshold": 20,
|
|
18
18
|
"replayWindowMs": 180000,
|
|
19
|
+
"_comment_resumeInterruptedCliTurns": "Temporary staged-rollout flag. Default false. When true, a deliberate clean restart may strictly resume an interrupted CLI session and send one tracked literal `continue`; crashes still replay the original message. Enable only after the exact pinned-CLI recovery gate passes for the installed Orchestra version.",
|
|
20
|
+
"resumeInterruptedCliTurns": false,
|
|
19
21
|
"_comment_chrome": "Opt-in to Claude Code's Chrome-extension browser-automation integration. Default false. Requires the 'Claude in Chrome' extension installed in the daemon-user's Chrome browser AND a live GUI session (Chrome must be running). See https://code.claude.com/docs/en/chrome. Per-chat override via `config.chats.<id>.chrome`.",
|
|
20
22
|
"chrome": false,
|
|
21
23
|
"_comment_pairedChatDefaults": "When a user sends /pair <CODE> from a private chat that isn't in config.chats yet, polygram auto-creates a chat entry using these defaults (merged over top-level `defaults`). Leave out `cwd` at your peril — without it, auto-onboarded DMs have no working directory and pairing will fail.",
|
package/lib/codex/diagnostics.js
CHANGED
|
@@ -133,6 +133,7 @@ function inspectCodexProfile(raw, profileId) {
|
|
|
133
133
|
new RegExp(`^default_permissions\\s*=\\s*"${escapedProfile}"\\s*$`, 'm'),
|
|
134
134
|
/^approval_policy\s*=\s*"never"\s*$/m,
|
|
135
135
|
/^web_search\s*=\s*"disabled"\s*$/m,
|
|
136
|
+
/^\[features\]\s*\ngoals\s*=\s*false\s*$/m,
|
|
136
137
|
new RegExp(
|
|
137
138
|
`^\\[permissions\\."${escapedProfile}"\\.network\\]\\s*\\n`
|
|
138
139
|
+ 'enabled\\s*=\\s*false\\s*$',
|
|
@@ -11,6 +11,7 @@ const {
|
|
|
11
11
|
} = require('./runtime-profile');
|
|
12
12
|
const {
|
|
13
13
|
createCodexRuntimeAvailability,
|
|
14
|
+
resolveCodexRuntimeCandidate,
|
|
14
15
|
resolveCodexRuntimeRequest,
|
|
15
16
|
resolveRuntimeConfig,
|
|
16
17
|
} = require('../runtime-config');
|
|
@@ -140,6 +141,7 @@ function createCodexRuntimeController({
|
|
|
140
141
|
attestCodexHome = orchestraDefault.attestPinnedCodexHome,
|
|
141
142
|
createAvailability = createCodexRuntimeAvailability,
|
|
142
143
|
resolveRuntime = resolveRuntimeConfig,
|
|
144
|
+
resolveCandidate = resolveCodexRuntimeCandidate,
|
|
143
145
|
resolveRequest = resolveCodexRuntimeRequest,
|
|
144
146
|
orchestra = orchestraDefault,
|
|
145
147
|
logger = console,
|
|
@@ -166,6 +168,7 @@ function createCodexRuntimeController({
|
|
|
166
168
|
|| typeof attestCodexHome !== 'function'
|
|
167
169
|
|| typeof createAvailability !== 'function'
|
|
168
170
|
|| typeof resolveRuntime !== 'function'
|
|
171
|
+
|| typeof resolveCandidate !== 'function'
|
|
169
172
|
|| typeof resolveRequest !== 'function'
|
|
170
173
|
|| typeof orchestra?.CodexAppServerClient !== 'function'
|
|
171
174
|
|| !Array.isArray(defaultDaemonSecretRoots)
|
|
@@ -370,17 +373,7 @@ function createCodexRuntimeController({
|
|
|
370
373
|
return state;
|
|
371
374
|
}
|
|
372
375
|
|
|
373
|
-
async function
|
|
374
|
-
boundedString(sessionKey, 'session key');
|
|
375
|
-
const state = requireAvailableInitialization();
|
|
376
|
-
const request = resolveRequest({
|
|
377
|
-
config,
|
|
378
|
-
chatId,
|
|
379
|
-
threadId,
|
|
380
|
-
defaultPm: 'sdk',
|
|
381
|
-
});
|
|
382
|
-
if (!request) return null;
|
|
383
|
-
|
|
376
|
+
async function prepareCodexRequest({ sessionKey, request, state }) {
|
|
384
377
|
const existing = receiptsBySession.get(sessionKey);
|
|
385
378
|
if (existing && sameProfileRequest(
|
|
386
379
|
existing.receipt.expectedStaticProfile,
|
|
@@ -403,7 +396,7 @@ function createCodexRuntimeController({
|
|
|
403
396
|
&& catalogAgeMs < catalogMaxAgeMs
|
|
404
397
|
&& catalogSupports(existing.catalog, request)
|
|
405
398
|
) {
|
|
406
|
-
return
|
|
399
|
+
return existing;
|
|
407
400
|
}
|
|
408
401
|
invalidatePreparedSession(sessionKey, existing);
|
|
409
402
|
}
|
|
@@ -472,7 +465,7 @@ function createCodexRuntimeController({
|
|
|
472
465
|
deploymentIdentity,
|
|
473
466
|
};
|
|
474
467
|
receiptsBySession.set(sessionKey, entry);
|
|
475
|
-
return
|
|
468
|
+
return entry;
|
|
476
469
|
})();
|
|
477
470
|
preparingByKey.set(key, promise);
|
|
478
471
|
try {
|
|
@@ -482,14 +475,42 @@ function createCodexRuntimeController({
|
|
|
482
475
|
}
|
|
483
476
|
}
|
|
484
477
|
|
|
485
|
-
async function
|
|
478
|
+
async function prepareCandidate({
|
|
486
479
|
sessionKey,
|
|
487
480
|
chatId,
|
|
488
481
|
threadId = null,
|
|
489
482
|
} = {}) {
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
const
|
|
483
|
+
boundedString(sessionKey, 'session key');
|
|
484
|
+
const state = requireAvailableInitialization();
|
|
485
|
+
const request = resolveCandidate({
|
|
486
|
+
config,
|
|
487
|
+
chatId,
|
|
488
|
+
threadId,
|
|
489
|
+
});
|
|
490
|
+
if (!request) return null;
|
|
491
|
+
const entry = await prepareCodexRequest({ sessionKey, request, state });
|
|
492
|
+
return Object.freeze({
|
|
493
|
+
request,
|
|
494
|
+
availability: entry.availability,
|
|
495
|
+
catalog: entry.catalog,
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
async function prepareSession({ sessionKey, chatId, threadId = null } = {}) {
|
|
500
|
+
boundedString(sessionKey, 'session key');
|
|
501
|
+
const state = requireAvailableInitialization();
|
|
502
|
+
const request = resolveRequest({
|
|
503
|
+
config,
|
|
504
|
+
chatId,
|
|
505
|
+
threadId,
|
|
506
|
+
defaultPm: 'sdk',
|
|
507
|
+
});
|
|
508
|
+
if (!request) return null;
|
|
509
|
+
const entry = await prepareCodexRequest({ sessionKey, request, state });
|
|
510
|
+
return prepareRuntimeView(entry, request, chatId, threadId);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
function runtimeCatalogView({ model, effort, catalog }) {
|
|
493
514
|
const models = Array.isArray(catalog.models)
|
|
494
515
|
? catalog.models.map((entry) => Object.freeze({
|
|
495
516
|
model: entry.model,
|
|
@@ -502,16 +523,54 @@ function createCodexRuntimeController({
|
|
|
502
523
|
: [];
|
|
503
524
|
return Object.freeze({
|
|
504
525
|
runtime: 'codex',
|
|
505
|
-
model
|
|
506
|
-
effort
|
|
526
|
+
model,
|
|
527
|
+
effort,
|
|
507
528
|
models: Object.freeze(models),
|
|
508
529
|
efforts: Object.freeze(
|
|
509
|
-
models.find((
|
|
530
|
+
models.find((entry) => entry.model === model)
|
|
510
531
|
?.supportedReasoningEfforts ?? [],
|
|
511
532
|
),
|
|
512
533
|
});
|
|
513
534
|
}
|
|
514
535
|
|
|
536
|
+
async function resolveCandidateRuntimeView({
|
|
537
|
+
sessionKey,
|
|
538
|
+
chatId,
|
|
539
|
+
threadId = null,
|
|
540
|
+
} = {}) {
|
|
541
|
+
const prepared = await prepareCandidate({ sessionKey, chatId, threadId });
|
|
542
|
+
if (!prepared) return Object.freeze({ runtime: 'claude' });
|
|
543
|
+
return runtimeCatalogView({
|
|
544
|
+
model: prepared.request.model,
|
|
545
|
+
effort: prepared.request.effort,
|
|
546
|
+
catalog: prepared.catalog,
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
function discardCandidateRuntime(sessionKey) {
|
|
551
|
+
boundedString(sessionKey, 'session key');
|
|
552
|
+
if (currentProcessBySession.has(sessionKey)) return false;
|
|
553
|
+
const entry = receiptsBySession.get(sessionKey);
|
|
554
|
+
if (!entry) return false;
|
|
555
|
+
receiptsBySession.delete(sessionKey);
|
|
556
|
+
return true;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
async function resolveRuntimeView({
|
|
560
|
+
sessionKey,
|
|
561
|
+
chatId,
|
|
562
|
+
threadId = null,
|
|
563
|
+
} = {}) {
|
|
564
|
+
const prepared = await prepareSession({ sessionKey, chatId, threadId });
|
|
565
|
+
if (!prepared) return Object.freeze({ runtime: 'claude' });
|
|
566
|
+
const { runtimeConfig, catalog } = prepared;
|
|
567
|
+
return runtimeCatalogView({
|
|
568
|
+
model: runtimeConfig.model,
|
|
569
|
+
effort: runtimeConfig.effort,
|
|
570
|
+
catalog,
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
|
|
515
574
|
function resolveReceipt(sessionKey, identity) {
|
|
516
575
|
const entry = receiptsBySession.get(sessionKey);
|
|
517
576
|
if (
|
|
@@ -1270,6 +1329,8 @@ function createCodexRuntimeController({
|
|
|
1270
1329
|
return Object.freeze({
|
|
1271
1330
|
initialize,
|
|
1272
1331
|
prepareSession,
|
|
1332
|
+
discardCandidateRuntime,
|
|
1333
|
+
resolveCandidateRuntimeView,
|
|
1273
1334
|
resolveRuntimeView,
|
|
1274
1335
|
resolveReceipt,
|
|
1275
1336
|
clientFactory,
|
|
@@ -303,6 +303,9 @@ function buildOwnedConfig({
|
|
|
303
303
|
approvals_reviewer: 'user',
|
|
304
304
|
web_search: 'disabled',
|
|
305
305
|
allow_login_shell: false,
|
|
306
|
+
features: {
|
|
307
|
+
goals: false,
|
|
308
|
+
},
|
|
306
309
|
shell_environment_policy: {
|
|
307
310
|
inherit: 'none',
|
|
308
311
|
ignore_default_excludes: false,
|
|
@@ -342,6 +345,9 @@ function renderOwnedConfig(config, {
|
|
|
342
345
|
'web_search = "disabled"',
|
|
343
346
|
'allow_login_shell = false',
|
|
344
347
|
'',
|
|
348
|
+
'[features]',
|
|
349
|
+
'goals = false',
|
|
350
|
+
'',
|
|
345
351
|
'[shell_environment_policy]',
|
|
346
352
|
'inherit = "none"',
|
|
347
353
|
'ignore_default_excludes = false',
|
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
const {
|
|
4
4
|
resolveProviderSessionForSpawn,
|
|
5
5
|
} = require('../db/sessions');
|
|
6
|
+
const {
|
|
7
|
+
processMatchesRuntime,
|
|
8
|
+
} = require('../runtime-config');
|
|
6
9
|
|
|
7
10
|
async function buildCodexSpawnContext({
|
|
8
11
|
sessionKey,
|
|
@@ -14,6 +17,7 @@ async function buildCodexSpawnContext({
|
|
|
14
17
|
runtimeController,
|
|
15
18
|
getSessionLabel,
|
|
16
19
|
logEvent,
|
|
20
|
+
mutateSessionOnDrift = true,
|
|
17
21
|
}) {
|
|
18
22
|
const prepared = await runtimeController.prepareSession({
|
|
19
23
|
sessionKey,
|
|
@@ -22,9 +26,13 @@ async function buildCodexSpawnContext({
|
|
|
22
26
|
});
|
|
23
27
|
const runtime = prepared.runtimeConfig;
|
|
24
28
|
let liveProcess = pm?.get(sessionKey) ?? null;
|
|
29
|
+
let liveCodexProcess = processMatchesRuntime(
|
|
30
|
+
liveProcess,
|
|
31
|
+
'codex',
|
|
32
|
+
'codex',
|
|
33
|
+
);
|
|
25
34
|
const replacementReason = (
|
|
26
|
-
|
|
27
|
-
&& !liveProcess.closed
|
|
35
|
+
liveCodexProcess
|
|
28
36
|
) ? runtimeController.processReplacementReason(
|
|
29
37
|
sessionKey,
|
|
30
38
|
liveProcess,
|
|
@@ -39,9 +47,10 @@ async function buildCodexSpawnContext({
|
|
|
39
47
|
});
|
|
40
48
|
await pm.kill(sessionKey, replacementReason);
|
|
41
49
|
liveProcess = null;
|
|
50
|
+
liveCodexProcess = false;
|
|
42
51
|
}
|
|
43
52
|
|
|
44
|
-
const isColdSpawn = !
|
|
53
|
+
const isColdSpawn = !liveCodexProcess;
|
|
45
54
|
let existingSessionId = null;
|
|
46
55
|
if (isColdSpawn) {
|
|
47
56
|
const resolved = resolveProviderSessionForSpawn(db, sessionKey, {
|
|
@@ -51,7 +60,7 @@ async function buildCodexSpawnContext({
|
|
|
51
60
|
cwd: runtime.cwd,
|
|
52
61
|
model: runtime.model,
|
|
53
62
|
effort: runtime.effort,
|
|
54
|
-
});
|
|
63
|
+
}, { mutateOnDrift: mutateSessionOnDrift });
|
|
55
64
|
existingSessionId = resolved.existingSessionId;
|
|
56
65
|
if (resolved.drift) {
|
|
57
66
|
logEvent('session-config-drift', {
|
package/lib/db/sessions.js
CHANGED
|
@@ -115,7 +115,12 @@ function getClaudeSessionId(db, sessionKey) {
|
|
|
115
115
|
return row?.claude_session_id || null;
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
function resolveProviderSessionForSpawn(
|
|
118
|
+
function resolveProviderSessionForSpawn(
|
|
119
|
+
db,
|
|
120
|
+
sessionKey,
|
|
121
|
+
resolved = {},
|
|
122
|
+
{ mutateOnDrift = true } = {},
|
|
123
|
+
) {
|
|
119
124
|
const namespace = sessionNamespaceFor(resolved);
|
|
120
125
|
if (!db) {
|
|
121
126
|
return {
|
|
@@ -126,7 +131,12 @@ function resolveProviderSessionForSpawn(db, sessionKey, resolved = {}) {
|
|
|
126
131
|
};
|
|
127
132
|
}
|
|
128
133
|
if (resolved.runtime !== 'codex') {
|
|
129
|
-
const legacy = resolveSessionForSpawn(
|
|
134
|
+
const legacy = resolveSessionForSpawn(
|
|
135
|
+
db,
|
|
136
|
+
sessionKey,
|
|
137
|
+
resolved,
|
|
138
|
+
{ mutateOnDrift },
|
|
139
|
+
);
|
|
130
140
|
const row = legacy.existingSessionId
|
|
131
141
|
? db.getProviderSession(sessionKey, namespace)
|
|
132
142
|
: null;
|
|
@@ -163,7 +173,9 @@ function resolveProviderSessionForSpawn(db, sessionKey, resolved = {}) {
|
|
|
163
173
|
after[field] != null && after[field] !== before[field]
|
|
164
174
|
));
|
|
165
175
|
if (fields.length > 0) {
|
|
166
|
-
|
|
176
|
+
if (mutateOnDrift) {
|
|
177
|
+
db.clearProviderSession(sessionKey, namespace);
|
|
178
|
+
}
|
|
167
179
|
return {
|
|
168
180
|
existingSessionId: null,
|
|
169
181
|
appServerSessionId: null,
|
|
@@ -238,25 +250,35 @@ const CODEX_SPAWN_IDENTITY_FIELDS = ['cwd'];
|
|
|
238
250
|
* or whether config drift means it must be dropped and re-spawned
|
|
239
251
|
* fresh.
|
|
240
252
|
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
*
|
|
253
|
+
* By default, drift deletes the stale row so the next spawn mints a fresh
|
|
254
|
+
* claude_session_id and `onInit` re-upserts it. Runtime-switch preparation
|
|
255
|
+
* can report the same drift without mutation so a failed replacement leaves
|
|
256
|
+
* the dormant session recoverable.
|
|
245
257
|
*
|
|
246
258
|
* @param {object|null} db — DB handle (null → fresh spawn)
|
|
247
259
|
* @param {string} sessionKey
|
|
248
260
|
* @param {object} resolved — freshly-resolved spawn config
|
|
261
|
+
* @param {object} [options]
|
|
262
|
+
* @param {boolean} [options.mutateOnDrift=true]
|
|
263
|
+
* Delete an incompatible stored row immediately. Runtime-switch
|
|
264
|
+
* preparation sets this false so a later replacement failure cannot erase
|
|
265
|
+
* the dormant session.
|
|
249
266
|
* @param {string} [resolved.agent]
|
|
250
267
|
* @param {string} [resolved.cwd]
|
|
251
268
|
* @param {string} [resolved.backend] — 'sdk' | 'tmux' (resolved by
|
|
252
269
|
* process/factory.js pickBackend); compared to the row's pm_backend
|
|
253
270
|
* @returns {{ existingSessionId: string|null, drift: object|null }}
|
|
254
271
|
* existingSessionId — pass to start() for --resume, or null for a
|
|
255
|
-
* fresh spawn (no stored row, or
|
|
272
|
+
* fresh spawn (no stored row, or incompatible stored row)
|
|
256
273
|
* drift — null when no drift; otherwise { fields, before, after }
|
|
257
274
|
* for the `session-config-drift` telemetry event
|
|
258
275
|
*/
|
|
259
|
-
function resolveSessionForSpawn(
|
|
276
|
+
function resolveSessionForSpawn(
|
|
277
|
+
db,
|
|
278
|
+
sessionKey,
|
|
279
|
+
resolved = {},
|
|
280
|
+
{ mutateOnDrift = true } = {},
|
|
281
|
+
) {
|
|
260
282
|
if (!db) return { existingSessionId: null, drift: null };
|
|
261
283
|
const row = db.getSession(sessionKey);
|
|
262
284
|
if (!row || !row.claude_session_id) {
|
|
@@ -321,8 +343,10 @@ function resolveSessionForSpawn(db, sessionKey, resolved = {}) {
|
|
|
321
343
|
return { existingSessionId: row.claude_session_id, drift: null };
|
|
322
344
|
}
|
|
323
345
|
|
|
324
|
-
//
|
|
325
|
-
|
|
346
|
+
// Normal cold spawns delete stale rows. Runtime-switch preparation leaves
|
|
347
|
+
// them intact so only a successful target initialization can supersede the
|
|
348
|
+
// active provider-session record.
|
|
349
|
+
if (mutateOnDrift) db.clearSessionId(sessionKey);
|
|
326
350
|
return {
|
|
327
351
|
existingSessionId: null,
|
|
328
352
|
drift: {
|