polygram 0.32.0 → 0.33.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.
- package/.claude-plugin/plugin.json +1 -1
- package/lib/codex/diagnostics.js +8 -5
- package/lib/codex/runtime-controller.js +115 -5
- package/lib/db/codex-failed-generation.js +490 -0
- package/lib/db/codex-input.js +26 -0
- package/lib/db/codex-reconciliation.js +184 -190
- package/lib/db/codex-retention.js +5 -18
- package/lib/db.js +30 -16
- package/lib/error/classify.js +1 -0
- package/lib/handlers/codex-reconciliation.js +4 -4
- package/lib/handlers/dispatcher.js +4 -1
- package/lib/telegram/composing-marker.js +53 -0
- package/lib/telegram/rich.js +36 -0
- package/lib/telegram/streamer.js +327 -26
- package/package.json +2 -2
- package/polygram.js +36 -4
package/polygram.js
CHANGED
|
@@ -68,6 +68,7 @@ const { createBuildSdkOptions } = require('./lib/sdk/build-options');
|
|
|
68
68
|
const { createSdkCallbacks } = require('./lib/sdk/callbacks');
|
|
69
69
|
const {
|
|
70
70
|
createCodexRuntimeController,
|
|
71
|
+
resolveCodexStartupRecovery,
|
|
71
72
|
} = require('./lib/codex/runtime-controller');
|
|
72
73
|
const {
|
|
73
74
|
buildCodexSpawnContext,
|
|
@@ -134,7 +135,7 @@ const { chunkMarkdownText } = require('./lib/telegram/chunk');
|
|
|
134
135
|
const {
|
|
135
136
|
toTelegramRichBlocks, resolveRichTextEnabled, isRichCapabilityError, isRichContentError,
|
|
136
137
|
isRichCapabilityErrorExplicit, isRichMessageFieldRejection, stripMediaMarkdown,
|
|
137
|
-
isRichLimitError,
|
|
138
|
+
isRichLimitError, blocksAreStyled,
|
|
138
139
|
} = require('./lib/telegram/rich');
|
|
139
140
|
const {
|
|
140
141
|
makeRichMediaResolver,
|
|
@@ -156,6 +157,7 @@ const { createRichSender, sendRichWithStylingRetry } = require('./lib/telegram/r
|
|
|
156
157
|
const { createRichDeliveryFactory } = require('./lib/telegram/rich-dispatch');
|
|
157
158
|
const { createRichEditStrategy } = require('./lib/telegram/rich-edit-dispatch');
|
|
158
159
|
const { composeDeliverTextFactories } = require('./lib/telegram/deliver-strategy');
|
|
160
|
+
const { composingMarker } = require('./lib/telegram/composing-marker');
|
|
159
161
|
const { buildPolygramDisplayHint } = require('./lib/telegram/display-hint');
|
|
160
162
|
const { redactBotToken, stripUrlCredentials } = require('./lib/error/net');
|
|
161
163
|
// F#23: shared agent-reply helper. parseResponse + sanitizer + chunked
|
|
@@ -1491,6 +1493,11 @@ async function handleMessage(sessionKey, chatId, msg, bot) {
|
|
|
1491
1493
|
// vertically. After the first send, the flag flips and subsequent
|
|
1492
1494
|
// initial-sends omit reply_parameters.
|
|
1493
1495
|
let firstBubbleSent = false;
|
|
1496
|
+
// The turn id the engine assigned at dispatch, published by its onTurnId
|
|
1497
|
+
// callback below. Declared at turn scope rather than beside the dispatch
|
|
1498
|
+
// because the streamer's own instrumentation — created before the dispatch —
|
|
1499
|
+
// needs to name the turn a snapshot belonged to.
|
|
1500
|
+
let dispatchedTurnId = null;
|
|
1494
1501
|
// Streaming is unconditional as of 0.4.0 — matches OpenClaw's model and
|
|
1495
1502
|
// eliminates the "stuck at 15min typing" complaint from the non-streaming
|
|
1496
1503
|
// code path. For short responses the streamer stays idle and we fall
|
|
@@ -1598,11 +1605,30 @@ async function handleMessage(sessionKey, chatId, msg, bot) {
|
|
|
1598
1605
|
// captures them. See stripInlineTagsForStreamer above.
|
|
1599
1606
|
transformText: stripInlineTagsForStreamer,
|
|
1600
1607
|
toRichPayload,
|
|
1608
|
+
// "Still writing" on the growing bubble. The marker matches the styling
|
|
1609
|
+
// of what it decorates rather than what the transport can carry: rich-edit
|
|
1610
|
+
// records a styling verdict for any payload blocksAreStyled() calls
|
|
1611
|
+
// styled, and a typed node on flat content would make those verdicts —
|
|
1612
|
+
// strike runs reset, flatten retries paid — be about polygram's own
|
|
1613
|
+
// decoration. Reading the latch instead is not enough: it says what is
|
|
1614
|
+
// POSSIBLE, and the content is what is actually there.
|
|
1615
|
+
toComposingMarker: ({ blocks }) => composingMarker({ styled: blocksAreStyled(blocks || []) }),
|
|
1601
1616
|
onRichUpgrade: () => {
|
|
1602
1617
|
// Record the visible transition when an existing plain bubble
|
|
1603
1618
|
// becomes rich during streaming.
|
|
1604
1619
|
logEvent('rich-streaming-upgrade', { chat_id: chatId, thread_id: threadId, bot: BOT_NAME });
|
|
1605
1620
|
},
|
|
1621
|
+
// A snapshot that lost text the reader had already seen. The streamer
|
|
1622
|
+
// refused it and kept the bubble on the last good one; this is the only
|
|
1623
|
+
// place that misuse becomes visible, since the tool ack stays ok either
|
|
1624
|
+
// way (an error there buys a retry loop, not a better snapshot).
|
|
1625
|
+
onNonCumulativeSnapshot: ({ prevLen, newLen }) => {
|
|
1626
|
+
logEvent('stream-noncumulative', {
|
|
1627
|
+
chat_id: chatId, thread_id: threadId, bot: BOT_NAME,
|
|
1628
|
+
session_key: sessionKey, turn_id: dispatchedTurnId,
|
|
1629
|
+
prev_len: prevLen, new_len: newLen,
|
|
1630
|
+
});
|
|
1631
|
+
},
|
|
1606
1632
|
send: async (payload) => {
|
|
1607
1633
|
const openRich = payload && typeof payload === 'object' && payload.rich;
|
|
1608
1634
|
const hadReplyAnchor = !firstBubbleSent;
|
|
@@ -2150,7 +2176,6 @@ async function handleMessage(sessionKey, chatId, msg, bot) {
|
|
|
2150
2176
|
// dispatchedTurnId is filled by the engine's onTurnId callback below,
|
|
2151
2177
|
// before any tool call for this turn can reach us; it lets a reply be
|
|
2152
2178
|
// checked against the turn it actually names.
|
|
2153
|
-
let dispatchedTurnId = null;
|
|
2154
2179
|
if (streamPreviewEnabled) {
|
|
2155
2180
|
releaseStreamerRegistration = streamerRegistry.register(sessionKey, {
|
|
2156
2181
|
streamer, chatId, deliveredTexts,
|
|
@@ -3486,6 +3511,12 @@ async function main() {
|
|
|
3486
3511
|
db = dbClient.open(DB_PATH);
|
|
3487
3512
|
console.log(`[db] opened ${DB_PATH}`);
|
|
3488
3513
|
try {
|
|
3514
|
+
const startupRecovery = await resolveCodexStartupRecovery(pidClaim, {
|
|
3515
|
+
claimThrowsOnSurvivingPredecessor:
|
|
3516
|
+
processGuard.CLAIM_PID_FILE_THROWS_ON_SURVIVING_PREDECESSOR === true,
|
|
3517
|
+
persistedLeaseStatus: db.getCodexLease()?.status ?? null,
|
|
3518
|
+
supervisorGraceMs: processGuard.CODEX_SUPERVISOR_GRACE_MS,
|
|
3519
|
+
});
|
|
3489
3520
|
codexRuntimeController = createCodexRuntimeController({
|
|
3490
3521
|
config,
|
|
3491
3522
|
db,
|
|
@@ -3496,6 +3527,7 @@ async function main() {
|
|
|
3496
3527
|
path.join(process.env.HOME || DATA_DIR, '.claude'),
|
|
3497
3528
|
],
|
|
3498
3529
|
logger: console,
|
|
3530
|
+
startupRecovery,
|
|
3499
3531
|
});
|
|
3500
3532
|
} catch (error) {
|
|
3501
3533
|
codexRuntimeController = null;
|
|
@@ -3507,9 +3539,9 @@ async function main() {
|
|
|
3507
3539
|
try {
|
|
3508
3540
|
const codexBoot = codexRuntimeController.initialize();
|
|
3509
3541
|
codexManagerOptions = codexBoot.managerOptions;
|
|
3510
|
-
if (codexBoot.recovery.status
|
|
3542
|
+
if (codexBoot.recovery.status !== 'clear') {
|
|
3511
3543
|
console.warn(
|
|
3512
|
-
`[codex] runtime
|
|
3544
|
+
`[codex] runtime recovery blocked at boot (${codexBoot.recovery.reason || 'unknown'})`,
|
|
3513
3545
|
);
|
|
3514
3546
|
}
|
|
3515
3547
|
} catch (error) {
|