omoclaw 2.2.2 → 2.4.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/dist/config.d.ts +2 -0
- package/dist/index.js +16 -3
- package/package.json +3 -3
package/dist/config.d.ts
CHANGED
|
@@ -17,6 +17,8 @@ export interface MonitorConfig {
|
|
|
17
17
|
/** Full session key override — if set, channelType/channel/chatType/agentId are ignored */
|
|
18
18
|
sessionKey: string;
|
|
19
19
|
};
|
|
20
|
+
/** Label to identify the host machine (e.g. "MainPC", "32w2"). Auto-detected from hostname if omitted. */
|
|
21
|
+
hostLabel: string;
|
|
20
22
|
staleTimeoutMs: number;
|
|
21
23
|
permissionReminderMs: number;
|
|
22
24
|
dedupTtlMs: number;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// src/index.ts
|
|
3
3
|
import fs3 from "fs";
|
|
4
|
+
import os2 from "os";
|
|
5
|
+
import path2 from "path";
|
|
4
6
|
|
|
5
7
|
// src/config.ts
|
|
6
8
|
import fs from "fs";
|
|
@@ -18,6 +20,7 @@ var DEFAULT_CONFIG = {
|
|
|
18
20
|
agentId: "main",
|
|
19
21
|
sessionKey: ""
|
|
20
22
|
},
|
|
23
|
+
hostLabel: "",
|
|
21
24
|
staleTimeoutMs: 900000,
|
|
22
25
|
permissionReminderMs: 120000,
|
|
23
26
|
dedupTtlMs: 30000,
|
|
@@ -57,6 +60,7 @@ function loadConfig() {
|
|
|
57
60
|
agentId: typeof webhook?.agentId === "string" ? webhook.agentId : DEFAULT_CONFIG.webhook.agentId,
|
|
58
61
|
sessionKey: typeof webhook?.sessionKey === "string" ? webhook.sessionKey : DEFAULT_CONFIG.webhook.sessionKey
|
|
59
62
|
},
|
|
63
|
+
hostLabel: typeof root.hostLabel === "string" ? root.hostLabel : DEFAULT_CONFIG.hostLabel,
|
|
60
64
|
staleTimeoutMs: typeof root.staleTimeoutMs === "number" ? root.staleTimeoutMs : DEFAULT_CONFIG.staleTimeoutMs,
|
|
61
65
|
permissionReminderMs: typeof root.permissionReminderMs === "number" ? root.permissionReminderMs : DEFAULT_CONFIG.permissionReminderMs,
|
|
62
66
|
dedupTtlMs: typeof root.dedupTtlMs === "number" ? root.dedupTtlMs : DEFAULT_CONFIG.dedupTtlMs,
|
|
@@ -225,9 +229,11 @@ function handleSessionStatusEvent(event, dedup, state, timers, webhookFn, debugL
|
|
|
225
229
|
state.transition(sessionID, "error");
|
|
226
230
|
timers.clearStaleTimer(sessionID);
|
|
227
231
|
const errorName = event.properties.error?.name ?? "UnknownError";
|
|
232
|
+
const errorMessage = event.properties.error?.data?.message ?? "";
|
|
233
|
+
const errorDetail = errorMessage ? `${errorName}: ${errorMessage.slice(0, 200)}` : errorName;
|
|
228
234
|
const dedupKey = `error:${sessionID}:${errorName}`;
|
|
229
235
|
if (dedup.shouldSend(dedupKey)) {
|
|
230
|
-
webhookFn(`[OpenCode] Error: ${
|
|
236
|
+
webhookFn(`[OpenCode] Error: ${errorDetail} (${shortSessionID2(sessionID)})`);
|
|
231
237
|
}
|
|
232
238
|
}
|
|
233
239
|
}
|
|
@@ -435,8 +441,14 @@ function sendWebhook(config, text) {
|
|
|
435
441
|
|
|
436
442
|
// src/index.ts
|
|
437
443
|
var DEBUG_LOG_PATH = "/tmp/opencode-monitor-debug.log";
|
|
444
|
+
function buildPrefix(config) {
|
|
445
|
+
const host = config.hostLabel || os2.hostname();
|
|
446
|
+
const project = path2.basename(process.cwd());
|
|
447
|
+
return `[OpenCode@${host}:${project}]`;
|
|
448
|
+
}
|
|
438
449
|
var SessionMonitorPlugin = async (_ctx) => {
|
|
439
450
|
const config = loadConfig();
|
|
451
|
+
const prefix = buildPrefix(config);
|
|
440
452
|
const debugLog = config.debug ? (msg) => {
|
|
441
453
|
const line = `[${new Date().toISOString()}] ${msg}
|
|
442
454
|
`;
|
|
@@ -457,8 +469,9 @@ var SessionMonitorPlugin = async (_ctx) => {
|
|
|
457
469
|
const dedup = new DedupEngine(config.dedupTtlMs);
|
|
458
470
|
const state = new SessionStateTracker;
|
|
459
471
|
const webhookFn = (text) => {
|
|
460
|
-
|
|
461
|
-
|
|
472
|
+
const tagged = text.startsWith("[OpenCode]") ? prefix + text.slice("[OpenCode]".length) : `${prefix} ${text}`;
|
|
473
|
+
debugLog?.(`WEBHOOK: ${tagged}`);
|
|
474
|
+
sendWebhook(config, tagged);
|
|
462
475
|
};
|
|
463
476
|
const timers = new TimerManager(config, webhookFn);
|
|
464
477
|
debugLog?.("Plugin loaded successfully. Waiting for events...");
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "omoclaw",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "OpenCode session monitor plugin
|
|
3
|
+
"version": "2.4.0",
|
|
4
|
+
"description": "OpenCode session monitor plugin \u2014 native event-driven webhook notifications for session state changes",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"type": "module",
|
|
@@ -33,4 +33,4 @@
|
|
|
33
33
|
"bun-types": "^1.3.6",
|
|
34
34
|
"typescript": "^5.7.3"
|
|
35
35
|
}
|
|
36
|
-
}
|
|
36
|
+
}
|