polygram 0.12.0-rc.1 → 0.12.0-rc.2
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/lib/process-manager.js +13 -0
- package/lib/sdk/callbacks.js +87 -0
- package/package.json +1 -1
package/lib/process-manager.js
CHANGED
|
@@ -123,6 +123,19 @@ const CALLBACK_TO_EVENT = {
|
|
|
123
123
|
// menu auto-dismissed by `_waitForReady`. Surfacing the event so
|
|
124
124
|
// soak can count how often aged-session resumes hit this path.
|
|
125
125
|
onSessionAgePromptDismissed: 'session-age-prompt-dismissed',
|
|
126
|
+
// 0.12 CliProcess observability — typed hook events from cli-process.js
|
|
127
|
+
// _handleHookEvent. Each gets its own callback so polygram can persist
|
|
128
|
+
// structured rows to the events DB for soak-time aggregate queries.
|
|
129
|
+
// - hook-lag-sample: Phase 1.8 — per-event lag_ms (target: median<2s, p99<5s)
|
|
130
|
+
// - tool-result: Phase 1.3 — PostToolUse durationMs per tool
|
|
131
|
+
// - subagent-start / subagent-done: Phase 1.3 — typed subagent lifecycle
|
|
132
|
+
// (we DO get tool-use='Agent' via onToolUse, but agent_type + durationMs
|
|
133
|
+
// only fire on these typed events). SDK backend never emits — hooks
|
|
134
|
+
// are CliProcess-specific (and were tmux-specific in 0.10–0.11).
|
|
135
|
+
onHookLagSample: 'hook-lag-sample',
|
|
136
|
+
onToolResult: 'tool-result',
|
|
137
|
+
onSubagentStart: 'subagent-start',
|
|
138
|
+
onSubagentDone: 'subagent-done',
|
|
126
139
|
};
|
|
127
140
|
|
|
128
141
|
class ProcessManager {
|
package/lib/sdk/callbacks.js
CHANGED
|
@@ -622,6 +622,93 @@ function createSdkCallbacks({
|
|
|
622
622
|
}
|
|
623
623
|
},
|
|
624
624
|
|
|
625
|
+
// 0.12 Phase 1.8 — hook-lag persistence for the soak gate (median<2s,
|
|
626
|
+
// p99<5s). Each row carries the hookEventName + lagMs so we can:
|
|
627
|
+
// SELECT json_extract(detail_json, '$.hook_event_name') AS evt,
|
|
628
|
+
// AVG(json_extract(detail_json, '$.lag_ms')) AS avg_lag,
|
|
629
|
+
// MAX(json_extract(detail_json, '$.lag_ms')) AS max_lag
|
|
630
|
+
// FROM events WHERE kind='hook-lag-sample' AND ts>...
|
|
631
|
+
// GROUP BY evt;
|
|
632
|
+
onHookLagSample: (sessionKey, payload /* , entry */) => {
|
|
633
|
+
try {
|
|
634
|
+
logEvent('hook-lag-sample', {
|
|
635
|
+
chat_id: getChatIdFromKey(sessionKey),
|
|
636
|
+
session_key: sessionKey,
|
|
637
|
+
backend: payload?.backend ?? 'cli',
|
|
638
|
+
hook_event_name: payload?.hookEventName ?? null,
|
|
639
|
+
lag_ms: payload?.lagMs ?? null,
|
|
640
|
+
tool_name: payload?.toolName ?? null,
|
|
641
|
+
});
|
|
642
|
+
} catch (err) {
|
|
643
|
+
logger.error?.(`[${botName}] hook-lag-sample handler: ${err.message}`);
|
|
644
|
+
}
|
|
645
|
+
},
|
|
646
|
+
|
|
647
|
+
// 0.12 Phase 1.3 — tool-result with durationMs. Pairs with the
|
|
648
|
+
// existing onToolUse row (which fires on PreToolUse) so the soak can
|
|
649
|
+
// compute per-tool average + p99 durations:
|
|
650
|
+
// SELECT json_extract(detail_json, '$.tool_name') AS tool,
|
|
651
|
+
// AVG(json_extract(detail_json, '$.duration_ms')) AS avg_ms,
|
|
652
|
+
// MAX(json_extract(detail_json, '$.duration_ms')) AS max_ms
|
|
653
|
+
// FROM events WHERE kind='tool-result' GROUP BY tool;
|
|
654
|
+
// isError captures the rare PostToolUse where the tool itself failed
|
|
655
|
+
// (vs the tool succeeding but claude deciding to retry).
|
|
656
|
+
onToolResult: (sessionKey, payload /* , entry */) => {
|
|
657
|
+
try {
|
|
658
|
+
logEvent('tool-result', {
|
|
659
|
+
chat_id: getChatIdFromKey(sessionKey),
|
|
660
|
+
session_key: sessionKey,
|
|
661
|
+
backend: payload?.backend ?? 'cli',
|
|
662
|
+
tool_name: payload?.name ?? null,
|
|
663
|
+
duration_ms: payload?.durationMs ?? null,
|
|
664
|
+
agent_id: payload?.agentId ?? null,
|
|
665
|
+
agent_type: payload?.agentType ?? null,
|
|
666
|
+
tool_use_id: payload?.toolUseId ?? null,
|
|
667
|
+
is_error: payload?.isError === true,
|
|
668
|
+
});
|
|
669
|
+
} catch (err) {
|
|
670
|
+
logger.error?.(`[${botName}] tool-result handler: ${err.message}`);
|
|
671
|
+
}
|
|
672
|
+
},
|
|
673
|
+
|
|
674
|
+
// 0.12 Phase 1.3 — subagent lifecycle. PreToolUse with name='Agent'
|
|
675
|
+
// synthesizes 'subagent-start' (no agent_id yet — claude doesn't
|
|
676
|
+
// hand one out until the inner SubagentStop). 'subagent-done' carries
|
|
677
|
+
// the agent_id + duration_ms so a soak can correlate the pair:
|
|
678
|
+
// SELECT s.detail_json AS start, d.detail_json AS done
|
|
679
|
+
// FROM events s JOIN events d
|
|
680
|
+
// ON json_extract(s.detail_json, '$.tool_use_id') =
|
|
681
|
+
// json_extract(d.detail_json, '$.tool_use_id')
|
|
682
|
+
// WHERE s.kind='subagent-start' AND d.kind='subagent-done';
|
|
683
|
+
onSubagentStart: (sessionKey, payload /* , entry */) => {
|
|
684
|
+
try {
|
|
685
|
+
logEvent('subagent-start', {
|
|
686
|
+
chat_id: getChatIdFromKey(sessionKey),
|
|
687
|
+
session_key: sessionKey,
|
|
688
|
+
backend: payload?.backend ?? 'cli',
|
|
689
|
+
agent_type: payload?.agentType ?? null,
|
|
690
|
+
tool_use_id: payload?.toolUseId ?? null,
|
|
691
|
+
});
|
|
692
|
+
} catch (err) {
|
|
693
|
+
logger.error?.(`[${botName}] subagent-start handler: ${err.message}`);
|
|
694
|
+
}
|
|
695
|
+
},
|
|
696
|
+
|
|
697
|
+
onSubagentDone: (sessionKey, payload /* , entry */) => {
|
|
698
|
+
try {
|
|
699
|
+
logEvent('subagent-done', {
|
|
700
|
+
chat_id: getChatIdFromKey(sessionKey),
|
|
701
|
+
session_key: sessionKey,
|
|
702
|
+
backend: payload?.backend ?? 'cli',
|
|
703
|
+
agent_type: payload?.agentType ?? null,
|
|
704
|
+
agent_id: payload?.agentId ?? null,
|
|
705
|
+
duration_ms: payload?.durationMs ?? null,
|
|
706
|
+
});
|
|
707
|
+
} catch (err) {
|
|
708
|
+
logger.error?.(`[${botName}] subagent-done handler: ${err.message}`);
|
|
709
|
+
}
|
|
710
|
+
},
|
|
711
|
+
|
|
625
712
|
onInjectFail: (sessionKey, payload /* , entry */) => {
|
|
626
713
|
try {
|
|
627
714
|
const msgId = payload?.msgId;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "polygram",
|
|
3
|
-
"version": "0.12.0-rc.
|
|
3
|
+
"version": "0.12.0-rc.2",
|
|
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": {
|