polygram 0.8.0-rc.17 → 0.8.0-rc.18
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/pm-interface.js +95 -0
- package/lib/process-manager-sdk.js +12 -0
- package/lib/process-manager.js +13 -0
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://anthropic.com/claude-code/plugin.schema.json",
|
|
3
3
|
"name": "polygram",
|
|
4
|
-
"version": "0.8.0-rc.
|
|
4
|
+
"version": "0.8.0-rc.18",
|
|
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 and a history skill.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"telegram",
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical Pm interface (JSDoc typedef).
|
|
3
|
+
*
|
|
4
|
+
* Both `lib/process-manager.js` (CLI pm) and `lib/process-manager-sdk.js`
|
|
5
|
+
* (SDK pm) implement this. `lib/pm-router.js`'s `createPmRouter()`
|
|
6
|
+
* forwards calls to one or the other based on per-chat policy.
|
|
7
|
+
*
|
|
8
|
+
* Optional methods are marked `?` — the router exposes them too but
|
|
9
|
+
* returns documented sentinels when the routed pm doesn't implement
|
|
10
|
+
* them. Sites that need to feature-detect should call
|
|
11
|
+
* `pm.pickFor(sessionKey)` and probe `typeof X === 'function'` on
|
|
12
|
+
* the returned pm instance, not on the router.
|
|
13
|
+
*
|
|
14
|
+
* @typedef {object} PmEntry
|
|
15
|
+
* The shape pm.get(sessionKey) returns. Different pms decorate it
|
|
16
|
+
* with their own internal fields; only the documented fields below
|
|
17
|
+
* are part of the public contract.
|
|
18
|
+
* @property {string} sessionKey
|
|
19
|
+
* @property {string|null} chatId
|
|
20
|
+
* @property {string|null} threadId
|
|
21
|
+
* @property {boolean} closed
|
|
22
|
+
* @property {boolean} inFlight
|
|
23
|
+
* @property {Array<object>} pendingQueue — array of pending sends
|
|
24
|
+
*
|
|
25
|
+
* @typedef {object} PmSendResult
|
|
26
|
+
* The shape pm.send() resolves with on success. Failure rejects.
|
|
27
|
+
* @property {string} text — final assistant text (may be '')
|
|
28
|
+
* @property {string|null} sessionId — Claude session id (for resume)
|
|
29
|
+
* @property {number} cost — total cost USD
|
|
30
|
+
* @property {number} duration — turn duration ms
|
|
31
|
+
* @property {string|null} error — error string or null on success
|
|
32
|
+
* @property {object} metrics — token / tool / msg counts
|
|
33
|
+
* @property {number} metrics.inputTokens
|
|
34
|
+
* @property {number} metrics.outputTokens
|
|
35
|
+
* @property {number} metrics.cacheCreationTokens
|
|
36
|
+
* @property {number} metrics.cacheReadTokens
|
|
37
|
+
* @property {number} metrics.numAssistantMessages
|
|
38
|
+
* @property {number} metrics.numToolUses
|
|
39
|
+
* @property {string|null} metrics.resultSubtype
|
|
40
|
+
*
|
|
41
|
+
* @typedef {object} PmSendOptions
|
|
42
|
+
* @property {number} [timeoutMs]
|
|
43
|
+
* @property {number} [maxTurnMs]
|
|
44
|
+
* @property {object} [context] — opaque per-turn state (streamer, reactor, sourceMsgId)
|
|
45
|
+
*
|
|
46
|
+
* @typedef {object} PmSpawnContext
|
|
47
|
+
* What polygram passes to spawnFn(sessionKey, ctx). Internal to
|
|
48
|
+
* each pm but documented here so callers know what's available.
|
|
49
|
+
* @property {string|null} chatId
|
|
50
|
+
* @property {string|null} threadId
|
|
51
|
+
* @property {string} label
|
|
52
|
+
*
|
|
53
|
+
* @typedef {object} Pm
|
|
54
|
+
* The unified ProcessManager interface. Both CLI and SDK pm
|
|
55
|
+
* implement these; the router forwards.
|
|
56
|
+
*
|
|
57
|
+
* Required (every pm has these):
|
|
58
|
+
* @property {(sessionKey: string) => boolean} has
|
|
59
|
+
* @property {(sessionKey: string) => PmEntry|null} get
|
|
60
|
+
* @property {(sessionKey: string, ctx: PmSpawnContext) => Promise<PmEntry>} getOrSpawn
|
|
61
|
+
* @property {(sessionKey: string, prompt: string, opts?: PmSendOptions) => Promise<PmSendResult>} send
|
|
62
|
+
* @property {(sessionKey: string) => Promise<void>} kill
|
|
63
|
+
* @property {(chatId: string|number) => Promise<void>} killChat
|
|
64
|
+
* — closes ALL sessions belonging to a chat (broadcast across topics).
|
|
65
|
+
* @property {() => Promise<void>} shutdown
|
|
66
|
+
* — graceful daemon-wide drain + close.
|
|
67
|
+
*
|
|
68
|
+
* Optional (only one of the two pms implements these — feature-detect):
|
|
69
|
+
* @property {((sessionKey: string, text: string, opts?: object) => boolean)=} steer
|
|
70
|
+
* — SDK pm only (rc.9 PostToolBatch hook drains buffer).
|
|
71
|
+
* @property {((sessionKey: string, model: string) => Promise<boolean>)=} setModel
|
|
72
|
+
* — SDK pm only (Query.setModel live).
|
|
73
|
+
* @property {((sessionKey: string, settings: {effortLevel?: string}) => Promise<boolean>)=} applyFlagSettings
|
|
74
|
+
* — SDK pm only (Query.applyFlagSettings live).
|
|
75
|
+
* @property {((sessionKey: string, mode: string) => Promise<boolean>)=} setPermissionMode
|
|
76
|
+
* — SDK pm only.
|
|
77
|
+
* @property {((sessionKey: string, reason?: string) => {killed: boolean, queued: number})=} requestRespawn
|
|
78
|
+
* — CLI pm only (drain pending queue then kill; respawn on next send).
|
|
79
|
+
* @property {((sessionKey: string, errCode: string) => number)=} drainQueue
|
|
80
|
+
* — SDK pm only (reject all queued pendings with errCode).
|
|
81
|
+
* @property {((sessionKey: string) => Promise<void>)=} interrupt
|
|
82
|
+
* — SDK pm only (Query.interrupt — non-destructive).
|
|
83
|
+
* @property {((sessionKey: string, opts?: {reason?: string}) => Promise<{closed: boolean, drainedPendings: number}>)=} resetSession
|
|
84
|
+
* — SDK pm only (close Query + clear sessionId from DB).
|
|
85
|
+
*
|
|
86
|
+
* Lifecycle introspection (for tests / debugging — not required
|
|
87
|
+
* to be present, but both current pms expose them):
|
|
88
|
+
* @property {() => string[]=} keys — sessionKey list
|
|
89
|
+
* @property {() => number=} size — number of live sessions
|
|
90
|
+
*/
|
|
91
|
+
|
|
92
|
+
// This file is JSDoc-only; no runtime exports. It exists so editors
|
|
93
|
+
// + the JSDoc-aware test mocks reference a single canonical type.
|
|
94
|
+
|
|
95
|
+
module.exports = {};
|
|
@@ -168,6 +168,18 @@ function makeInputController({ queueCap = DEFAULT_QUEUE_CAP } = {}) {
|
|
|
168
168
|
|
|
169
169
|
// ─── ProcessManager ────────────────────────────────────────────────
|
|
170
170
|
|
|
171
|
+
/**
|
|
172
|
+
* @anthropic-ai/claude-agent-sdk-backed ProcessManager. Implements
|
|
173
|
+
* the canonical Pm interface (`lib/pm-interface.js`). Optional
|
|
174
|
+
* methods exposed: `steer`, `setModel`, `applyFlagSettings`,
|
|
175
|
+
* `setPermissionMode`, `drainQueue`, `interrupt`, `resetSession`.
|
|
176
|
+
*
|
|
177
|
+
* Optional methods NOT implemented (CLI pm has this): `requestRespawn`.
|
|
178
|
+
* For mid-session config changes use `applyFlagSettings` (effort)
|
|
179
|
+
* or `setModel`.
|
|
180
|
+
*
|
|
181
|
+
* @implements {import('./pm-interface.js').Pm}
|
|
182
|
+
*/
|
|
171
183
|
class ProcessManagerSdk {
|
|
172
184
|
constructor({
|
|
173
185
|
cap = DEFAULT_CAP,
|
package/lib/process-manager.js
CHANGED
|
@@ -93,6 +93,19 @@ function sumUsage(usageByMessage) {
|
|
|
93
93
|
return out;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
/**
|
|
97
|
+
* Stream-json CLI-backed ProcessManager. Implements the canonical
|
|
98
|
+
* Pm interface (`lib/pm-interface.js`). Optional methods exposed:
|
|
99
|
+
* `requestRespawn` — drain queue and respawn process on next send
|
|
100
|
+
* (kept for parity with rc.6+ feature-detection at the router; SDK
|
|
101
|
+
* pm uses `applyFlagSettings` + `setModel` for the same UX).
|
|
102
|
+
*
|
|
103
|
+
* Optional methods NOT implemented (SDK pm has these): `steer`,
|
|
104
|
+
* `setModel`, `applyFlagSettings`, `setPermissionMode`,
|
|
105
|
+
* `drainQueue`, `interrupt`, `resetSession`.
|
|
106
|
+
*
|
|
107
|
+
* @implements {import('./pm-interface.js').Pm}
|
|
108
|
+
*/
|
|
96
109
|
class ProcessManager {
|
|
97
110
|
constructor({
|
|
98
111
|
cap = DEFAULT_CAP,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "polygram",
|
|
3
|
-
"version": "0.8.0-rc.
|
|
3
|
+
"version": "0.8.0-rc.18",
|
|
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": {
|