polygram 0.22.0 → 0.23.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.
Files changed (47) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/README.md +5 -3
  3. package/config.example.json +23 -1
  4. package/lib/codex/binary.js +287 -0
  5. package/lib/codex/delivery-finalizer.js +97 -0
  6. package/lib/codex/diagnostics.js +483 -0
  7. package/lib/codex/event-normalizer.js +50 -0
  8. package/lib/codex/host-identity.js +103 -0
  9. package/lib/codex/model-catalog.js +359 -0
  10. package/lib/codex/retention-scheduler.js +59 -0
  11. package/lib/codex/runtime-controller.js +1292 -0
  12. package/lib/codex/runtime-profile.js +888 -0
  13. package/lib/codex/spawn-context.js +87 -0
  14. package/lib/db/auto-resume.js +77 -9
  15. package/lib/db/codex-reconciliation.js +490 -0
  16. package/lib/db/codex-retention.js +139 -0
  17. package/lib/db/sessions.js +102 -1
  18. package/lib/db.js +3418 -19
  19. package/lib/error/classify.js +140 -0
  20. package/lib/handlers/abort.js +143 -5
  21. package/lib/handlers/autosteer.js +256 -1
  22. package/lib/handlers/codex-reconciliation.js +230 -0
  23. package/lib/handlers/config-callback.js +324 -89
  24. package/lib/handlers/config-ui.js +401 -39
  25. package/lib/handlers/dispatcher.js +71 -8
  26. package/lib/handlers/edit-correction.js +11 -1
  27. package/lib/handlers/edit-redelivery.js +230 -4
  28. package/lib/handlers/gate-inbound.js +7 -0
  29. package/lib/handlers/replay-disposition.js +133 -11
  30. package/lib/handlers/slash-commands.js +443 -37
  31. package/lib/ipc/client.js +22 -12
  32. package/lib/ipc/runtime-directory.js +208 -0
  33. package/lib/ipc/server.js +18 -12
  34. package/lib/model-costs.js +4 -3
  35. package/lib/pm-interface.js +33 -0
  36. package/lib/prompt.js +15 -9
  37. package/lib/rewind/rewind.js +21 -1
  38. package/lib/runtime-config.js +605 -0
  39. package/lib/sdk/build-options.js +4 -1
  40. package/lib/sdk/callbacks.js +46 -3
  41. package/migrations/015-agent-runtime-sessions.sql +50 -0
  42. package/migrations/016-agent-turn-attempts.sql +211 -0
  43. package/migrations/017-config-runtime-changes.sql +46 -0
  44. package/ops/README.md +57 -0
  45. package/package.json +2 -2
  46. package/polygram.js +697 -48
  47. package/scripts/doctor.js +37 -8
package/scripts/doctor.js CHANGED
@@ -17,15 +17,19 @@
17
17
  * 2 bad invocation / missing args
18
18
  *
19
19
  * Extended from OpenClaw's doctor.ts pattern: config, token, reachability,
20
- * membership checks, recent-error trail. Safe to run against a live bot
21
- * (no state changes) unless --roundtrip is passed, which posts a single
22
- * disable_notification=true message.
20
+ * membership checks, recent-error trail, and offline Codex deployment
21
+ * diagnostics. Safe to run against a live bot (no state changes) unless
22
+ * --roundtrip is passed, which posts a single disable_notification=true
23
+ * message. Codex checks never start app-server or run authenticated preflight.
23
24
  */
24
25
 
25
26
  const fs = require('fs');
26
27
  const path = require('path');
27
28
  const Database = require('better-sqlite3');
28
29
 
30
+ const {
31
+ collectCodexDoctorChecks,
32
+ } = require('../lib/codex/diagnostics');
29
33
  const {
30
34
  call, tell, socketPathFor, readSecret,
31
35
  } = require('../lib/ipc/client');
@@ -139,9 +143,21 @@ function checkDb() {
139
143
  }
140
144
 
141
145
  async function checkIpc() {
146
+ let ipcPath;
147
+ try {
148
+ ipcPath = socketPathFor(botName);
149
+ } catch (error) {
150
+ push(
151
+ 'ipc-root',
152
+ 'fail',
153
+ 'runtime directory invalid',
154
+ { code: typeof error?.code === 'string' ? error.code : null },
155
+ );
156
+ return false;
157
+ }
142
158
  try {
143
159
  const res = await call({
144
- path: socketPathFor(botName),
160
+ path: ipcPath,
145
161
  op: 'ping',
146
162
  callTimeoutMs: timeoutMs,
147
163
  });
@@ -149,14 +165,19 @@ async function checkIpc() {
149
165
  push('ipc', 'ok', `socket responsive, bot=${res.bot}`);
150
166
  return true;
151
167
  }
152
- push('ipc', 'fail', JSON.stringify(res));
168
+ push('ipc', 'fail', 'socket returned an invalid ping response');
153
169
  return false;
154
170
  } catch (err) {
155
171
  // Distinguish "no socket" (bot not running) from "socket dead"
156
- if (/ENOENT|ECONNREFUSED/.test(err.message)) {
157
- push('ipc', 'warn', `bot not running — IPC socket absent at ${socketPathFor(botName)}`);
172
+ if (['ENOENT', 'ECONNREFUSED'].includes(err?.code)) {
173
+ push('ipc', 'warn', 'bot not running; IPC socket absent');
158
174
  } else {
159
- push('ipc', 'fail', err.message);
175
+ push(
176
+ 'ipc',
177
+ 'fail',
178
+ 'socket health check failed',
179
+ { code: typeof err?.code === 'string' ? err.code : null },
180
+ );
160
181
  }
161
182
  return false;
162
183
  }
@@ -258,6 +279,13 @@ function checkApprovals(db) {
258
279
  }
259
280
  }
260
281
 
282
+ async function checkCodex(cfg, db) {
283
+ const codexChecks = await collectCodexDoctorChecks({ config: cfg, db });
284
+ for (const item of codexChecks) {
285
+ push(item.name, item.status, item.detail, item.extra);
286
+ }
287
+ }
288
+
261
289
  async function checkRoundtrip() {
262
290
  if (!doRoundtrip) return;
263
291
  const marker = `polygram-doctor:${Date.now()}`;
@@ -300,6 +328,7 @@ async function checkRoundtrip() {
300
328
  async function main() {
301
329
  const cfg = checkConfig();
302
330
  const db = checkDb();
331
+ await checkCodex(cfg, db);
303
332
  await checkIpc();
304
333
  await checkTelegram(cfg);
305
334
  checkRecentErrors(db);