olakai-cli 0.6.6 → 0.7.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/{api-63UDJX5M.js → api-JBVSHCKY.js} +2 -2
- package/dist/chunk-75YQWZ4Q.js +2587 -0
- package/dist/chunk-75YQWZ4Q.js.map +1 -0
- package/dist/chunk-GXKHWBGO.js +691 -0
- package/dist/chunk-GXKHWBGO.js.map +1 -0
- package/dist/{chunk-GU4HEL24.js → chunk-KNGRF4XU.js} +7 -2
- package/dist/chunk-KNGRF4XU.js.map +1 -0
- package/dist/{chunk-2Q7JYGCK.js → chunk-KY6OHQZW.js} +2 -1
- package/dist/doctor-27VDFNP7.js +29 -0
- package/dist/index.js +313 -2396
- package/dist/index.js.map +1 -1
- package/dist/repair-WSBWAW2B.js +124 -0
- package/dist/repair-WSBWAW2B.js.map +1 -0
- package/dist/{status-USHUUHK6.js → status-IZCIMES2.js} +2 -2
- package/dist/status-IZCIMES2.js.map +1 -0
- package/package.json +1 -1
- package/dist/chunk-GU4HEL24.js.map +0 -1
- /package/dist/{api-63UDJX5M.js.map → api-JBVSHCKY.js.map} +0 -0
- /package/dist/{chunk-2Q7JYGCK.js.map → chunk-KY6OHQZW.js.map} +0 -0
- /package/dist/{status-USHUUHK6.js.map → doctor-27VDFNP7.js.map} +0 -0
|
@@ -0,0 +1,2587 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createAgent,
|
|
3
|
+
getCurrentUser,
|
|
4
|
+
listMyAgents,
|
|
5
|
+
regenerateAgentApiKey
|
|
6
|
+
} from "./chunk-KNGRF4XU.js";
|
|
7
|
+
import {
|
|
8
|
+
CLAUDE_DIR,
|
|
9
|
+
OLAKAI_DIR,
|
|
10
|
+
OLAKAI_HOOK_MARKER,
|
|
11
|
+
SETTINGS_FILE,
|
|
12
|
+
deleteClaudeCodeConfig,
|
|
13
|
+
findConfiguredWorkspace,
|
|
14
|
+
getClaudeCodeConfigPath,
|
|
15
|
+
getClaudeCodeStatus,
|
|
16
|
+
getClaudeDir,
|
|
17
|
+
getLegacyClaudeMonitorConfigPath,
|
|
18
|
+
getMonitorConfigPath,
|
|
19
|
+
getSettingsPath,
|
|
20
|
+
loadClaudeCodeConfig,
|
|
21
|
+
mergeHooksSettings,
|
|
22
|
+
readJsonFile,
|
|
23
|
+
writeClaudeCodeConfig,
|
|
24
|
+
writeJsonFile
|
|
25
|
+
} from "./chunk-KY6OHQZW.js";
|
|
26
|
+
import {
|
|
27
|
+
getBaseUrl,
|
|
28
|
+
getValidToken
|
|
29
|
+
} from "./chunk-AVB4N2UN.js";
|
|
30
|
+
|
|
31
|
+
// src/monitor/plugin.ts
|
|
32
|
+
var TOOL_IDS = [
|
|
33
|
+
"claude-code",
|
|
34
|
+
"codex",
|
|
35
|
+
"cursor"
|
|
36
|
+
];
|
|
37
|
+
var registry = /* @__PURE__ */ new Map();
|
|
38
|
+
function registerPlugin(plugin) {
|
|
39
|
+
registry.set(plugin.id, plugin);
|
|
40
|
+
}
|
|
41
|
+
function getPlugin(id) {
|
|
42
|
+
if (!isToolId(id)) {
|
|
43
|
+
throw new Error(
|
|
44
|
+
`Unknown tool: "${id}". Supported tools: ${TOOL_IDS.join(", ")}`
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
const plugin = registry.get(id);
|
|
48
|
+
if (!plugin) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
`Tool "${id}" is not registered. This is a CLI bug \u2014 please report it.`
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
return plugin;
|
|
54
|
+
}
|
|
55
|
+
function listPlugins() {
|
|
56
|
+
return Array.from(registry.values());
|
|
57
|
+
}
|
|
58
|
+
function isToolId(value) {
|
|
59
|
+
return TOOL_IDS.includes(value);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// src/monitor/registry.ts
|
|
63
|
+
import * as fs from "fs";
|
|
64
|
+
import * as os from "os";
|
|
65
|
+
import * as path from "path";
|
|
66
|
+
var REGISTRY_VERSION = 1;
|
|
67
|
+
var OLAKAI_HOME_DIRNAME = ".olakai";
|
|
68
|
+
var REGISTRY_FILENAME = "registry.json";
|
|
69
|
+
var TOOL_DESCRIPTORS = {
|
|
70
|
+
"claude-code": {
|
|
71
|
+
scope: "workspace",
|
|
72
|
+
hooksPath: (projectRoot) => path.join(projectRoot, ".claude", "settings.json"),
|
|
73
|
+
source: "CLAUDE_CODE"
|
|
74
|
+
},
|
|
75
|
+
codex: {
|
|
76
|
+
scope: "global",
|
|
77
|
+
hooksPath: (_projectRoot, homeDir) => path.join(homeDir, ".codex", "config.toml"),
|
|
78
|
+
source: "CODEX"
|
|
79
|
+
},
|
|
80
|
+
cursor: {
|
|
81
|
+
scope: "global",
|
|
82
|
+
hooksPath: (_projectRoot, homeDir) => path.join(homeDir, ".cursor", "hooks.json"),
|
|
83
|
+
source: "CURSOR"
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
function getToolScope(toolId) {
|
|
87
|
+
return TOOL_DESCRIPTORS[toolId].scope;
|
|
88
|
+
}
|
|
89
|
+
function getToolHooksPath(toolId, projectRoot, homeDir = os.homedir()) {
|
|
90
|
+
return TOOL_DESCRIPTORS[toolId].hooksPath(projectRoot, homeDir);
|
|
91
|
+
}
|
|
92
|
+
function getToolSource(toolId) {
|
|
93
|
+
return TOOL_DESCRIPTORS[toolId].source;
|
|
94
|
+
}
|
|
95
|
+
function getOlakaiHomeDir(homeDir) {
|
|
96
|
+
return path.join(homeDir, OLAKAI_HOME_DIRNAME);
|
|
97
|
+
}
|
|
98
|
+
function getRegistryPath(homeDir = os.homedir()) {
|
|
99
|
+
return path.join(getOlakaiHomeDir(homeDir), REGISTRY_FILENAME);
|
|
100
|
+
}
|
|
101
|
+
function emptyRegistry() {
|
|
102
|
+
return { version: REGISTRY_VERSION, workspaces: [] };
|
|
103
|
+
}
|
|
104
|
+
function isRegistryEntry(value) {
|
|
105
|
+
if (typeof value !== "object" || value === null) return false;
|
|
106
|
+
const e = value;
|
|
107
|
+
return typeof e.path === "string" && typeof e.tool === "string" && TOOL_IDS.includes(e.tool) && (e.scope === "workspace" || e.scope === "global") && typeof e.agentId === "string" && typeof e.agentName === "string" && typeof e.source === "string" && typeof e.configPath === "string" && typeof e.hooksPath === "string" && typeof e.monitoringEndpoint === "string" && typeof e.createdAt === "string";
|
|
108
|
+
}
|
|
109
|
+
function readRegistry(homeDir = os.homedir()) {
|
|
110
|
+
const filePath = getRegistryPath(homeDir);
|
|
111
|
+
try {
|
|
112
|
+
if (!fs.existsSync(filePath)) return emptyRegistry();
|
|
113
|
+
const raw = fs.readFileSync(filePath, "utf-8");
|
|
114
|
+
const parsed = JSON.parse(raw);
|
|
115
|
+
if (typeof parsed !== "object" || parsed === null || !Array.isArray(parsed.workspaces)) {
|
|
116
|
+
return emptyRegistry();
|
|
117
|
+
}
|
|
118
|
+
const workspaces = parsed.workspaces.filter(
|
|
119
|
+
isRegistryEntry
|
|
120
|
+
);
|
|
121
|
+
return { version: REGISTRY_VERSION, workspaces };
|
|
122
|
+
} catch {
|
|
123
|
+
return emptyRegistry();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function writeRegistry(registry2, homeDir = os.homedir()) {
|
|
127
|
+
const dir = getOlakaiHomeDir(homeDir);
|
|
128
|
+
const filePath = getRegistryPath(homeDir);
|
|
129
|
+
if (!fs.existsSync(dir)) {
|
|
130
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
131
|
+
}
|
|
132
|
+
const body = JSON.stringify(registry2, null, 2) + "\n";
|
|
133
|
+
const tmpPath = `${filePath}.${process.pid}.${Date.now()}.tmp`;
|
|
134
|
+
try {
|
|
135
|
+
fs.writeFileSync(tmpPath, body, { encoding: "utf-8", mode: 384 });
|
|
136
|
+
fs.renameSync(tmpPath, filePath);
|
|
137
|
+
} catch (err) {
|
|
138
|
+
try {
|
|
139
|
+
if (fs.existsSync(tmpPath)) fs.unlinkSync(tmpPath);
|
|
140
|
+
} catch {
|
|
141
|
+
}
|
|
142
|
+
throw err;
|
|
143
|
+
}
|
|
144
|
+
try {
|
|
145
|
+
fs.chmodSync(filePath, 384);
|
|
146
|
+
} catch {
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function sameKey(a, path_, tool) {
|
|
150
|
+
return a.path === path_ && a.tool === tool;
|
|
151
|
+
}
|
|
152
|
+
function upsertEntry(entry, homeDir = os.homedir()) {
|
|
153
|
+
const registry2 = readRegistry(homeDir);
|
|
154
|
+
const idx = registry2.workspaces.findIndex(
|
|
155
|
+
(e) => sameKey(e, entry.path, entry.tool)
|
|
156
|
+
);
|
|
157
|
+
if (idx >= 0) {
|
|
158
|
+
registry2.workspaces[idx] = entry;
|
|
159
|
+
} else {
|
|
160
|
+
registry2.workspaces.push(entry);
|
|
161
|
+
}
|
|
162
|
+
writeRegistry(registry2, homeDir);
|
|
163
|
+
return registry2;
|
|
164
|
+
}
|
|
165
|
+
function removeEntry(entryPath, tool, homeDir = os.homedir()) {
|
|
166
|
+
const registry2 = readRegistry(homeDir);
|
|
167
|
+
const next = registry2.workspaces.filter(
|
|
168
|
+
(e) => !sameKey(e, entryPath, tool)
|
|
169
|
+
);
|
|
170
|
+
if (next.length !== registry2.workspaces.length) {
|
|
171
|
+
registry2.workspaces = next;
|
|
172
|
+
writeRegistry(registry2, homeDir);
|
|
173
|
+
}
|
|
174
|
+
return registry2;
|
|
175
|
+
}
|
|
176
|
+
function readOnDiskConfig(filePath) {
|
|
177
|
+
try {
|
|
178
|
+
if (!fs.existsSync(filePath)) return null;
|
|
179
|
+
const raw = fs.readFileSync(filePath, "utf-8");
|
|
180
|
+
const parsed = JSON.parse(raw);
|
|
181
|
+
if (typeof parsed?.agentId !== "string" || typeof parsed?.agentName !== "string" || typeof parsed?.source !== "string" || typeof parsed?.monitoringEndpoint !== "string") {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
agentId: parsed.agentId,
|
|
186
|
+
agentName: parsed.agentName,
|
|
187
|
+
source: parsed.source,
|
|
188
|
+
monitoringEndpoint: parsed.monitoringEndpoint,
|
|
189
|
+
createdAt: typeof parsed.createdAt === "string" ? parsed.createdAt : void 0
|
|
190
|
+
};
|
|
191
|
+
} catch {
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function reconcileCurrentWorkspace(cwd, homeDir = os.homedir()) {
|
|
196
|
+
const root = findConfiguredWorkspace(cwd, TOOL_IDS);
|
|
197
|
+
if (!root) return [];
|
|
198
|
+
let registry2 = readRegistry(homeDir);
|
|
199
|
+
let mutated = false;
|
|
200
|
+
for (const toolId of TOOL_IDS) {
|
|
201
|
+
const configPath = getMonitorConfigPath(root, toolId);
|
|
202
|
+
const alreadyRegistered = registry2.workspaces.some(
|
|
203
|
+
(e) => sameKey(e, root, toolId)
|
|
204
|
+
);
|
|
205
|
+
if (alreadyRegistered) continue;
|
|
206
|
+
const config = readOnDiskConfig(configPath);
|
|
207
|
+
if (!config) continue;
|
|
208
|
+
const descriptor = TOOL_DESCRIPTORS[toolId];
|
|
209
|
+
const entry = {
|
|
210
|
+
path: root,
|
|
211
|
+
tool: toolId,
|
|
212
|
+
scope: descriptor.scope,
|
|
213
|
+
agentId: config.agentId,
|
|
214
|
+
agentName: config.agentName,
|
|
215
|
+
source: config.source,
|
|
216
|
+
configPath,
|
|
217
|
+
hooksPath: descriptor.hooksPath(root, homeDir),
|
|
218
|
+
monitoringEndpoint: config.monitoringEndpoint,
|
|
219
|
+
createdAt: config.createdAt ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
220
|
+
};
|
|
221
|
+
registry2.workspaces.push(entry);
|
|
222
|
+
mutated = true;
|
|
223
|
+
}
|
|
224
|
+
const legacyClaudePath = getLegacyClaudeMonitorConfigPath(root);
|
|
225
|
+
const claudeRegistered = registry2.workspaces.some(
|
|
226
|
+
(e) => sameKey(e, root, "claude-code")
|
|
227
|
+
);
|
|
228
|
+
if (!claudeRegistered) {
|
|
229
|
+
const legacyConfig = readOnDiskConfig(legacyClaudePath);
|
|
230
|
+
if (legacyConfig) {
|
|
231
|
+
const descriptor = TOOL_DESCRIPTORS["claude-code"];
|
|
232
|
+
registry2.workspaces.push({
|
|
233
|
+
path: root,
|
|
234
|
+
tool: "claude-code",
|
|
235
|
+
scope: descriptor.scope,
|
|
236
|
+
agentId: legacyConfig.agentId,
|
|
237
|
+
agentName: legacyConfig.agentName,
|
|
238
|
+
source: legacyConfig.source,
|
|
239
|
+
configPath: getMonitorConfigPath(root, "claude-code"),
|
|
240
|
+
hooksPath: descriptor.hooksPath(root, homeDir),
|
|
241
|
+
monitoringEndpoint: legacyConfig.monitoringEndpoint,
|
|
242
|
+
createdAt: legacyConfig.createdAt ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
243
|
+
});
|
|
244
|
+
mutated = true;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
let persisted = true;
|
|
248
|
+
if (mutated) {
|
|
249
|
+
try {
|
|
250
|
+
writeRegistry(registry2, homeDir);
|
|
251
|
+
} catch {
|
|
252
|
+
persisted = false;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
if (persisted) {
|
|
256
|
+
registry2 = readRegistry(homeDir);
|
|
257
|
+
}
|
|
258
|
+
return registry2.workspaces.filter((e) => e.path === root);
|
|
259
|
+
}
|
|
260
|
+
function formatRegistryTable(registry2, configExists = (p) => fs.existsSync(p)) {
|
|
261
|
+
if (registry2.workspaces.length === 0) {
|
|
262
|
+
return "No monitored workspaces recorded on this machine.\nRun 'olakai monitor init --tool <tool>' to start monitoring.";
|
|
263
|
+
}
|
|
264
|
+
const byTool = /* @__PURE__ */ new Map();
|
|
265
|
+
for (const entry of registry2.workspaces) {
|
|
266
|
+
const list = byTool.get(entry.tool) ?? [];
|
|
267
|
+
list.push(entry);
|
|
268
|
+
byTool.set(entry.tool, list);
|
|
269
|
+
}
|
|
270
|
+
const lines = [];
|
|
271
|
+
for (const toolId of TOOL_IDS) {
|
|
272
|
+
const entries = byTool.get(toolId);
|
|
273
|
+
if (!entries || entries.length === 0) continue;
|
|
274
|
+
lines.push(`${toolId} (${entries.length}):`);
|
|
275
|
+
for (const entry of entries) {
|
|
276
|
+
const missing = configExists(entry.configPath) ? "" : " (config missing)";
|
|
277
|
+
const verified = entry.lastVerifiedAt ? ` \xB7 verified ${entry.lastVerifiedAt}` : "";
|
|
278
|
+
lines.push(
|
|
279
|
+
` \u2022 ${entry.agentName} [${entry.scope}] \u2014 ${entry.path}${verified}${missing}`
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
lines.push("");
|
|
283
|
+
}
|
|
284
|
+
return lines.join("\n").trimEnd();
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// src/monitor/plugins/claude-code/index.ts
|
|
288
|
+
import * as fs5 from "fs";
|
|
289
|
+
import { spawnSync as spawnSync2 } from "child_process";
|
|
290
|
+
|
|
291
|
+
// src/commands/monitor-state.ts
|
|
292
|
+
import * as fs2 from "fs";
|
|
293
|
+
import * as os2 from "os";
|
|
294
|
+
import * as path2 from "path";
|
|
295
|
+
var STATE_DIR_SEGMENTS = [".olakai", "monitor-state"];
|
|
296
|
+
function getStateDir(homeDir) {
|
|
297
|
+
return path2.join(homeDir, ...STATE_DIR_SEGMENTS);
|
|
298
|
+
}
|
|
299
|
+
function getStateFile(sessionId, homeDir) {
|
|
300
|
+
return path2.join(getStateDir(homeDir), `${sessionId}.json`);
|
|
301
|
+
}
|
|
302
|
+
var debugLogger = null;
|
|
303
|
+
function setDebugLogger(logger) {
|
|
304
|
+
debugLogger = logger;
|
|
305
|
+
}
|
|
306
|
+
function log(label, data) {
|
|
307
|
+
if (debugLogger) {
|
|
308
|
+
try {
|
|
309
|
+
debugLogger(label, data);
|
|
310
|
+
} catch {
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
function loadSessionState(sessionId, homeDir = os2.homedir()) {
|
|
315
|
+
if (!sessionId) return null;
|
|
316
|
+
const filePath = getStateFile(sessionId, homeDir);
|
|
317
|
+
try {
|
|
318
|
+
if (!fs2.existsSync(filePath)) return null;
|
|
319
|
+
const raw = fs2.readFileSync(filePath, "utf-8");
|
|
320
|
+
const parsed = JSON.parse(raw);
|
|
321
|
+
if (typeof parsed?.lastUserTimestamp !== "string" || typeof parsed?.lastReportedAt !== "string" || typeof parsed?.numTurnsAtLastReport !== "number") {
|
|
322
|
+
return null;
|
|
323
|
+
}
|
|
324
|
+
return {
|
|
325
|
+
lastUserTimestamp: parsed.lastUserTimestamp,
|
|
326
|
+
lastReportedAt: parsed.lastReportedAt,
|
|
327
|
+
numTurnsAtLastReport: parsed.numTurnsAtLastReport
|
|
328
|
+
};
|
|
329
|
+
} catch (err) {
|
|
330
|
+
log("state-load-failed", {
|
|
331
|
+
sessionId,
|
|
332
|
+
error: err.message
|
|
333
|
+
});
|
|
334
|
+
return null;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
function saveSessionState(sessionId, state, homeDir = os2.homedir()) {
|
|
338
|
+
if (!sessionId) return;
|
|
339
|
+
const dir = getStateDir(homeDir);
|
|
340
|
+
const filePath = getStateFile(sessionId, homeDir);
|
|
341
|
+
try {
|
|
342
|
+
if (!fs2.existsSync(dir)) {
|
|
343
|
+
fs2.mkdirSync(dir, { recursive: true });
|
|
344
|
+
}
|
|
345
|
+
fs2.writeFileSync(filePath, JSON.stringify(state, null, 2) + "\n", "utf-8");
|
|
346
|
+
} catch (err) {
|
|
347
|
+
log("state-save-failed", {
|
|
348
|
+
sessionId,
|
|
349
|
+
error: err.message
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
function shouldReportTurn(existing, currentUserTimestamp) {
|
|
354
|
+
if (!currentUserTimestamp) return true;
|
|
355
|
+
if (!existing) return true;
|
|
356
|
+
return existing.lastUserTimestamp !== currentUserTimestamp;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// src/monitor/plugins/claude-code/install.ts
|
|
360
|
+
import * as fs3 from "fs";
|
|
361
|
+
|
|
362
|
+
// src/monitor/self-monitor-provision.ts
|
|
363
|
+
import path3 from "path";
|
|
364
|
+
|
|
365
|
+
// src/lib/git.ts
|
|
366
|
+
import { spawnSync } from "child_process";
|
|
367
|
+
function getGitConfigEmail() {
|
|
368
|
+
let result;
|
|
369
|
+
try {
|
|
370
|
+
result = spawnSync("git", ["config", "--global", "user.email"], {
|
|
371
|
+
encoding: "utf8",
|
|
372
|
+
// Cap stdout. A normal `user.email` value is well under 320 bytes
|
|
373
|
+
// (RFC 5321 max email length); 64KB leaves headroom for git config
|
|
374
|
+
// wrappers that print a banner without ever truncating real
|
|
375
|
+
// values. spawnSync sets `result.error` (ENOBUFS) on overflow
|
|
376
|
+
// rather than truncating silently — we check it below.
|
|
377
|
+
maxBuffer: 65536,
|
|
378
|
+
// Don't pipe stderr to our process; we treat any error as "no email".
|
|
379
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
380
|
+
});
|
|
381
|
+
} catch {
|
|
382
|
+
return null;
|
|
383
|
+
}
|
|
384
|
+
if (result.error) return null;
|
|
385
|
+
if (result.status !== 0) return null;
|
|
386
|
+
const raw = (result.stdout || "").toString().trim();
|
|
387
|
+
if (!raw) return null;
|
|
388
|
+
const EMAIL_RE = /^[^\s@.]+(?:\.[^\s@.]+)*@[^\s@.]+(?:\.[^\s@.]+)*\.[a-zA-Z]{2,}$/;
|
|
389
|
+
if (!EMAIL_RE.test(raw)) return null;
|
|
390
|
+
if (raw.length > 320) return null;
|
|
391
|
+
return raw;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// src/monitor/prompt.ts
|
|
395
|
+
import * as readline from "readline";
|
|
396
|
+
function promptUser(question) {
|
|
397
|
+
const rl = readline.createInterface({
|
|
398
|
+
input: process.stdin,
|
|
399
|
+
output: process.stdout
|
|
400
|
+
});
|
|
401
|
+
return new Promise((resolve) => {
|
|
402
|
+
rl.question(question, (answer) => {
|
|
403
|
+
rl.close();
|
|
404
|
+
resolve(answer.trim());
|
|
405
|
+
});
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
function isInteractive() {
|
|
409
|
+
return Boolean(process.stdin.isTTY && process.stdout.isTTY);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// src/monitor/self-monitor-provision.ts
|
|
413
|
+
async function provisionSelfMonitorAgent(opts) {
|
|
414
|
+
const me = await getCurrentUser();
|
|
415
|
+
const localPart = (me.email.split("@")[0] ?? "user").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
416
|
+
const workspaceName = path3.basename(opts.projectRoot).toLowerCase();
|
|
417
|
+
const defaultName = `${workspaceName}-${localPart}`;
|
|
418
|
+
let existing = [];
|
|
419
|
+
try {
|
|
420
|
+
existing = await listMyAgents({
|
|
421
|
+
source: opts.source,
|
|
422
|
+
name: defaultName
|
|
423
|
+
});
|
|
424
|
+
} catch (err) {
|
|
425
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
426
|
+
if (!message.includes("Failed to list your agents")) {
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
if (existing.length > 0) {
|
|
430
|
+
const found = existing[0];
|
|
431
|
+
console.log(
|
|
432
|
+
`
|
|
433
|
+
Found your existing ${opts.displayName} agent "${found.name}".`
|
|
434
|
+
);
|
|
435
|
+
console.log(
|
|
436
|
+
"Re-using it requires rotating its API key. Any other workspace currently using this agent will start failing on the next monitor request until it re-runs 'olakai monitor init'."
|
|
437
|
+
);
|
|
438
|
+
const ack = await promptUser("Rotate the API key and reuse? [y/N]: ");
|
|
439
|
+
if (ack.trim().toLowerCase() !== "y") {
|
|
440
|
+
console.error(
|
|
441
|
+
"Cancelled. To use this workspace without affecting the other workspace, run 'olakai monitor init' again and pick a different agent name when prompted."
|
|
442
|
+
);
|
|
443
|
+
process.exit(1);
|
|
444
|
+
}
|
|
445
|
+
const rotated = await regenerateAgentApiKey(found.id);
|
|
446
|
+
return {
|
|
447
|
+
id: found.id,
|
|
448
|
+
name: found.name,
|
|
449
|
+
description: found.description,
|
|
450
|
+
role: found.role,
|
|
451
|
+
// `source` on the listMyAgents response is the AgentSource enum
|
|
452
|
+
// string; the Agent type narrows it more loosely. Cast through
|
|
453
|
+
// the shared union.
|
|
454
|
+
source: found.source,
|
|
455
|
+
apiKey: {
|
|
456
|
+
id: rotated.id,
|
|
457
|
+
key: rotated.key,
|
|
458
|
+
keyMasked: rotated.keyMasked,
|
|
459
|
+
isActive: rotated.isActive
|
|
460
|
+
},
|
|
461
|
+
workflowId: null,
|
|
462
|
+
category: opts.category
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
const nameInput = await promptUser(
|
|
466
|
+
`Enter a descriptive name for this agent or accept the recommended name [${defaultName}]: `
|
|
467
|
+
);
|
|
468
|
+
const agentName = nameInput.trim() || defaultName;
|
|
469
|
+
const vcsEmailHint = getGitConfigEmail() ?? void 0;
|
|
470
|
+
try {
|
|
471
|
+
return await createAgent({
|
|
472
|
+
name: agentName,
|
|
473
|
+
description: `${opts.displayName} local agent for ${agentName}`,
|
|
474
|
+
role: "WORKER",
|
|
475
|
+
createApiKey: true,
|
|
476
|
+
source: opts.source,
|
|
477
|
+
...vcsEmailHint ? { vcsEmailHint } : {}
|
|
478
|
+
});
|
|
479
|
+
} catch (err) {
|
|
480
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
481
|
+
if (message.toLowerCase().includes("already exists") || message.toLowerCase().includes("conflict")) {
|
|
482
|
+
console.log(
|
|
483
|
+
`
|
|
484
|
+
An agent named "${agentName}" already exists on this account (created by someone else or an admin).`
|
|
485
|
+
);
|
|
486
|
+
const retry = await promptUser("Try a different name: ");
|
|
487
|
+
if (!retry.trim()) {
|
|
488
|
+
console.error("No name provided. Aborting.");
|
|
489
|
+
process.exit(1);
|
|
490
|
+
}
|
|
491
|
+
return createAgent({
|
|
492
|
+
name: retry.trim(),
|
|
493
|
+
description: `${opts.displayName} local agent for ${retry.trim()}`,
|
|
494
|
+
role: "WORKER",
|
|
495
|
+
createApiKey: true,
|
|
496
|
+
source: opts.source,
|
|
497
|
+
...vcsEmailHint ? { vcsEmailHint } : {}
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
throw err;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
// src/monitor/plugins/claude-code/install.ts
|
|
505
|
+
import path4 from "path";
|
|
506
|
+
var CLAUDE_CODE_SOURCE = "claude-code";
|
|
507
|
+
var CLAUDE_CODE_AGENT_SOURCE = "CLAUDE_CODE";
|
|
508
|
+
var CLAUDE_CODE_AGENT_CATEGORY = "CODING";
|
|
509
|
+
async function installClaudeCode(opts) {
|
|
510
|
+
const projectRoot = opts.projectRoot ?? process.cwd();
|
|
511
|
+
const token = getValidToken();
|
|
512
|
+
if (!token) {
|
|
513
|
+
console.error("Not logged in. Run 'olakai login' first.");
|
|
514
|
+
process.exit(1);
|
|
515
|
+
}
|
|
516
|
+
console.log("Setting up Claude Code monitoring for this workspace...\n");
|
|
517
|
+
const agent = await provisionSelfMonitorAgent({
|
|
518
|
+
projectRoot,
|
|
519
|
+
source: CLAUDE_CODE_AGENT_SOURCE,
|
|
520
|
+
displayName: "Claude Code",
|
|
521
|
+
category: CLAUDE_CODE_AGENT_CATEGORY
|
|
522
|
+
});
|
|
523
|
+
const monitoringEndpoint = `${getBaseUrl()}/api/monitoring/prompt`;
|
|
524
|
+
const apiKey = agent.apiKey?.key;
|
|
525
|
+
if (!apiKey) {
|
|
526
|
+
console.error(
|
|
527
|
+
"Internal error: agent provisioned but no API key returned. Please re-run 'olakai monitor init'."
|
|
528
|
+
);
|
|
529
|
+
process.exit(1);
|
|
530
|
+
}
|
|
531
|
+
const claudeDir = getClaudeDir(projectRoot);
|
|
532
|
+
if (!fs3.existsSync(claudeDir)) {
|
|
533
|
+
fs3.mkdirSync(claudeDir, { recursive: true });
|
|
534
|
+
}
|
|
535
|
+
const settingsPath = getSettingsPath(projectRoot);
|
|
536
|
+
const existingSettings = readJsonFile(settingsPath) ?? {};
|
|
537
|
+
const mergedHooks = mergeHooksSettings(existingSettings.hooks);
|
|
538
|
+
const updatedSettings = {
|
|
539
|
+
...existingSettings,
|
|
540
|
+
hooks: mergedHooks
|
|
541
|
+
};
|
|
542
|
+
writeJsonFile(settingsPath, updatedSettings);
|
|
543
|
+
const monitorConfig = {
|
|
544
|
+
agentId: agent.id,
|
|
545
|
+
apiKey,
|
|
546
|
+
agentName: agent.name,
|
|
547
|
+
source: CLAUDE_CODE_SOURCE,
|
|
548
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
549
|
+
monitoringEndpoint
|
|
550
|
+
};
|
|
551
|
+
writeClaudeCodeConfig(projectRoot, monitorConfig);
|
|
552
|
+
const configPath = getClaudeCodeConfigPath(projectRoot);
|
|
553
|
+
const configRel = path4.relative(projectRoot, configPath);
|
|
554
|
+
console.log("");
|
|
555
|
+
console.log(`\u2713 Agent "${agent.name}" configured (ID: ${agent.id})`);
|
|
556
|
+
if (agent.apiKey?.key) {
|
|
557
|
+
console.log("\u2713 API key generated");
|
|
558
|
+
}
|
|
559
|
+
console.log(
|
|
560
|
+
`\u2713 Claude Code hooks configured in ${CLAUDE_DIR}/${SETTINGS_FILE}`
|
|
561
|
+
);
|
|
562
|
+
console.log(`\u2713 Monitor config saved to ${configRel}`);
|
|
563
|
+
console.log("");
|
|
564
|
+
console.log(
|
|
565
|
+
"Congrats! Monitoring is now active. Claude Code will report activity to Olakai"
|
|
566
|
+
);
|
|
567
|
+
console.log(`on each turn.`);
|
|
568
|
+
console.log("");
|
|
569
|
+
console.log(
|
|
570
|
+
`\u26A0 Ensure ${OLAKAI_DIR}/ is in your .gitignore (it contains your API key)`
|
|
571
|
+
);
|
|
572
|
+
console.log("");
|
|
573
|
+
console.log("To check status: olakai monitor status --tool claude-code");
|
|
574
|
+
console.log("To disable: olakai monitor disable --tool claude-code");
|
|
575
|
+
return {
|
|
576
|
+
agentId: agent.id,
|
|
577
|
+
agentName: agent.name,
|
|
578
|
+
source: CLAUDE_CODE_SOURCE,
|
|
579
|
+
monitoringEndpoint
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
async function uninstallClaudeCode(opts) {
|
|
583
|
+
const projectRoot = opts.projectRoot ?? process.cwd();
|
|
584
|
+
const settingsPath = getSettingsPath(projectRoot);
|
|
585
|
+
const settings = readJsonFile(settingsPath);
|
|
586
|
+
if (settings?.hooks) {
|
|
587
|
+
const cleanedHooks = {};
|
|
588
|
+
for (const [event, entries] of Object.entries(settings.hooks)) {
|
|
589
|
+
const filtered = entries.filter(
|
|
590
|
+
(e) => !e.hooks.some((h) => h.command.includes(OLAKAI_HOOK_MARKER))
|
|
591
|
+
);
|
|
592
|
+
if (filtered.length > 0) {
|
|
593
|
+
cleanedHooks[event] = filtered;
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
if (Object.keys(cleanedHooks).length > 0) {
|
|
597
|
+
settings.hooks = cleanedHooks;
|
|
598
|
+
} else {
|
|
599
|
+
delete settings.hooks;
|
|
600
|
+
}
|
|
601
|
+
writeJsonFile(settingsPath, settings);
|
|
602
|
+
console.log(`\u2713 Olakai hooks removed from ${CLAUDE_DIR}/${SETTINGS_FILE}`);
|
|
603
|
+
} else {
|
|
604
|
+
console.log("No hooks found in settings.json.");
|
|
605
|
+
}
|
|
606
|
+
if (!opts.keepConfig) {
|
|
607
|
+
const configPath = getClaudeCodeConfigPath(projectRoot);
|
|
608
|
+
const configRel = path4.relative(projectRoot, configPath);
|
|
609
|
+
if (deleteClaudeCodeConfig(projectRoot)) {
|
|
610
|
+
console.log(`\u2713 Monitor config removed (${configRel})`);
|
|
611
|
+
}
|
|
612
|
+
} else {
|
|
613
|
+
const configPath = getClaudeCodeConfigPath(projectRoot);
|
|
614
|
+
const configRel = path4.relative(projectRoot, configPath);
|
|
615
|
+
console.log(`Monitor config retained at ${configRel}`);
|
|
616
|
+
}
|
|
617
|
+
console.log("");
|
|
618
|
+
console.log(
|
|
619
|
+
"Monitoring disabled. Run 'olakai monitor init --tool claude-code' to re-enable."
|
|
620
|
+
);
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
// src/monitor/plugins/claude-code/hook.ts
|
|
624
|
+
import * as fs4 from "fs";
|
|
625
|
+
|
|
626
|
+
// src/commands/monitor-transcript.ts
|
|
627
|
+
var FILE_EDITING_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
628
|
+
"Edit",
|
|
629
|
+
"Write",
|
|
630
|
+
"MultiEdit"
|
|
631
|
+
]);
|
|
632
|
+
var BASH_TOOL_NAME = "Bash";
|
|
633
|
+
var SKILL_REGEX = /^\/([\w-]+)(?:\s|$)/;
|
|
634
|
+
function detectSkill(userMessage) {
|
|
635
|
+
if (typeof userMessage !== "string") return void 0;
|
|
636
|
+
const trimmed = userMessage.trimStart();
|
|
637
|
+
if (!trimmed) return void 0;
|
|
638
|
+
const match = SKILL_REGEX.exec(trimmed);
|
|
639
|
+
if (!match) return void 0;
|
|
640
|
+
return match[1];
|
|
641
|
+
}
|
|
642
|
+
function extractTextContent(content) {
|
|
643
|
+
if (typeof content === "string") return content;
|
|
644
|
+
if (!Array.isArray(content)) return "";
|
|
645
|
+
const parts = [];
|
|
646
|
+
for (const block of content) {
|
|
647
|
+
if (block?.type === "text" && typeof block.text === "string") {
|
|
648
|
+
parts.push(block.text);
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
return parts.join("\n").trim();
|
|
652
|
+
}
|
|
653
|
+
function isMetaUserMessage(line, text) {
|
|
654
|
+
if (line.isMeta === true) return true;
|
|
655
|
+
if (!text) return true;
|
|
656
|
+
return text.includes("<command-name>") || text.includes("<local-command-caveat>") || text.includes("<command-message>");
|
|
657
|
+
}
|
|
658
|
+
function parseTimestamp(ts) {
|
|
659
|
+
if (typeof ts !== "string" || !ts) return NaN;
|
|
660
|
+
return Date.parse(ts);
|
|
661
|
+
}
|
|
662
|
+
function isCompactionEntry(line) {
|
|
663
|
+
if (line.type !== "system") return false;
|
|
664
|
+
const subtype = line.subtype ?? "";
|
|
665
|
+
return subtype === "compact_boundary" || subtype === "pre_compact" || subtype === "post_compact" || /compact/i.test(subtype);
|
|
666
|
+
}
|
|
667
|
+
function parseTranscript(raw) {
|
|
668
|
+
const empty = {
|
|
669
|
+
prompt: "",
|
|
670
|
+
response: "",
|
|
671
|
+
tokens: 0,
|
|
672
|
+
inputTokens: 0,
|
|
673
|
+
outputTokens: 0,
|
|
674
|
+
modelName: null,
|
|
675
|
+
numTurns: 0,
|
|
676
|
+
toolCallCount: 0,
|
|
677
|
+
filesEditedCount: 0,
|
|
678
|
+
bashCommandCount: 0
|
|
679
|
+
};
|
|
680
|
+
if (!raw) return empty;
|
|
681
|
+
const lines = raw.split("\n");
|
|
682
|
+
let lastUserText = "";
|
|
683
|
+
let lastUserTimestamp = NaN;
|
|
684
|
+
let lastUserTimestampRaw;
|
|
685
|
+
let lastAssistantText = "";
|
|
686
|
+
let lastAssistantTimestamp = NaN;
|
|
687
|
+
let lastAssistantModel = null;
|
|
688
|
+
let lastAssistantInputTokens = 0;
|
|
689
|
+
let lastAssistantOutputTokens = 0;
|
|
690
|
+
let numTurns = 0;
|
|
691
|
+
let currentTurnUserTimestamp = NaN;
|
|
692
|
+
let toolCallCount = 0;
|
|
693
|
+
let bashCommandCount = 0;
|
|
694
|
+
let editedFilePaths = /* @__PURE__ */ new Set();
|
|
695
|
+
for (const rawLine of lines) {
|
|
696
|
+
if (!rawLine) continue;
|
|
697
|
+
let parsed;
|
|
698
|
+
try {
|
|
699
|
+
parsed = JSON.parse(rawLine);
|
|
700
|
+
} catch {
|
|
701
|
+
continue;
|
|
702
|
+
}
|
|
703
|
+
if (isCompactionEntry(parsed)) continue;
|
|
704
|
+
if (parsed.isSidechain === true) continue;
|
|
705
|
+
if (parsed.type === "user" && parsed.message) {
|
|
706
|
+
const text = extractTextContent(parsed.message.content);
|
|
707
|
+
if (isMetaUserMessage(parsed, text)) continue;
|
|
708
|
+
lastUserText = text;
|
|
709
|
+
lastUserTimestamp = parseTimestamp(parsed.timestamp);
|
|
710
|
+
currentTurnUserTimestamp = lastUserTimestamp;
|
|
711
|
+
toolCallCount = 0;
|
|
712
|
+
bashCommandCount = 0;
|
|
713
|
+
editedFilePaths = /* @__PURE__ */ new Set();
|
|
714
|
+
lastUserTimestampRaw = typeof parsed.timestamp === "string" && parsed.timestamp ? parsed.timestamp : void 0;
|
|
715
|
+
} else if (parsed.type === "assistant" && parsed.message) {
|
|
716
|
+
const text = extractTextContent(parsed.message.content);
|
|
717
|
+
numTurns += 1;
|
|
718
|
+
if (text) lastAssistantText = text;
|
|
719
|
+
if (typeof parsed.message.model === "string") {
|
|
720
|
+
lastAssistantModel = parsed.message.model;
|
|
721
|
+
}
|
|
722
|
+
const content = parsed.message.content;
|
|
723
|
+
if (Array.isArray(content)) {
|
|
724
|
+
for (const block of content) {
|
|
725
|
+
try {
|
|
726
|
+
if (!block || block.type !== "tool_use") continue;
|
|
727
|
+
toolCallCount += 1;
|
|
728
|
+
const name = typeof block.name === "string" ? block.name : "";
|
|
729
|
+
if (name === BASH_TOOL_NAME) {
|
|
730
|
+
bashCommandCount += 1;
|
|
731
|
+
continue;
|
|
732
|
+
}
|
|
733
|
+
if (FILE_EDITING_TOOL_NAMES.has(name)) {
|
|
734
|
+
const input = block.input;
|
|
735
|
+
if (input !== null && typeof input === "object" && "file_path" in input) {
|
|
736
|
+
const filePath = input.file_path;
|
|
737
|
+
if (typeof filePath === "string" && filePath) {
|
|
738
|
+
editedFilePaths.add(filePath);
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
} catch {
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
const usage = parsed.message.usage;
|
|
747
|
+
if (usage) {
|
|
748
|
+
const input = (usage.input_tokens ?? 0) + (usage.cache_creation_input_tokens ?? 0) + (usage.cache_read_input_tokens ?? 0);
|
|
749
|
+
const output = usage.output_tokens ?? 0;
|
|
750
|
+
lastAssistantInputTokens = input;
|
|
751
|
+
lastAssistantOutputTokens = output;
|
|
752
|
+
}
|
|
753
|
+
const ts = parseTimestamp(parsed.timestamp);
|
|
754
|
+
if (!Number.isNaN(ts)) {
|
|
755
|
+
lastAssistantTimestamp = ts;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
const result = {
|
|
760
|
+
prompt: lastUserText,
|
|
761
|
+
response: lastAssistantText,
|
|
762
|
+
tokens: lastAssistantInputTokens + lastAssistantOutputTokens,
|
|
763
|
+
inputTokens: lastAssistantInputTokens,
|
|
764
|
+
outputTokens: lastAssistantOutputTokens,
|
|
765
|
+
modelName: lastAssistantModel,
|
|
766
|
+
numTurns,
|
|
767
|
+
toolCallCount,
|
|
768
|
+
filesEditedCount: editedFilePaths.size,
|
|
769
|
+
bashCommandCount
|
|
770
|
+
};
|
|
771
|
+
if (!Number.isNaN(currentTurnUserTimestamp) && !Number.isNaN(lastAssistantTimestamp) && lastAssistantTimestamp >= currentTurnUserTimestamp) {
|
|
772
|
+
result.latencyMs = Math.round(
|
|
773
|
+
lastAssistantTimestamp - currentTurnUserTimestamp
|
|
774
|
+
);
|
|
775
|
+
}
|
|
776
|
+
const skill = detectSkill(lastUserText);
|
|
777
|
+
if (skill) {
|
|
778
|
+
result.skill = skill;
|
|
779
|
+
}
|
|
780
|
+
if (lastUserTimestampRaw) {
|
|
781
|
+
result.userTurnTimestamp = lastUserTimestampRaw;
|
|
782
|
+
}
|
|
783
|
+
return result;
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
// src/monitor/plugins/claude-code/hook.ts
|
|
787
|
+
var noopDebug = () => {
|
|
788
|
+
};
|
|
789
|
+
function extractFromTranscript(transcriptPath, debugLog4 = noopDebug) {
|
|
790
|
+
const empty = {
|
|
791
|
+
prompt: "",
|
|
792
|
+
response: "",
|
|
793
|
+
tokens: 0,
|
|
794
|
+
inputTokens: 0,
|
|
795
|
+
outputTokens: 0,
|
|
796
|
+
modelName: null,
|
|
797
|
+
numTurns: 0,
|
|
798
|
+
toolCallCount: 0,
|
|
799
|
+
filesEditedCount: 0,
|
|
800
|
+
bashCommandCount: 0
|
|
801
|
+
};
|
|
802
|
+
if (!transcriptPath) return empty;
|
|
803
|
+
let raw;
|
|
804
|
+
try {
|
|
805
|
+
raw = fs4.readFileSync(transcriptPath, "utf-8");
|
|
806
|
+
} catch (err) {
|
|
807
|
+
debugLog4("transcript-read-failed", {
|
|
808
|
+
transcriptPath,
|
|
809
|
+
error: err.message
|
|
810
|
+
});
|
|
811
|
+
return empty;
|
|
812
|
+
}
|
|
813
|
+
return parseTranscript(raw);
|
|
814
|
+
}
|
|
815
|
+
function extractSubagentName(event) {
|
|
816
|
+
const candidates = [
|
|
817
|
+
event.agent_name,
|
|
818
|
+
event.subagent_type,
|
|
819
|
+
event.agent_type,
|
|
820
|
+
event.tool_input?.subagent_type
|
|
821
|
+
];
|
|
822
|
+
for (const value of candidates) {
|
|
823
|
+
if (typeof value === "string" && value.trim()) {
|
|
824
|
+
return value.trim();
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
return void 0;
|
|
828
|
+
}
|
|
829
|
+
function buildClaudeCodePayload(event, eventData, config) {
|
|
830
|
+
const sessionId = eventData.session_id ?? `claude-code-${Date.now()}`;
|
|
831
|
+
switch (event) {
|
|
832
|
+
case "stop":
|
|
833
|
+
case "subagent-stop": {
|
|
834
|
+
const extracted = extractFromTranscript(eventData.transcript_path);
|
|
835
|
+
const isSubagent = event === "subagent-stop";
|
|
836
|
+
const customData = {
|
|
837
|
+
hookEvent: eventData.hook_event_name ?? (isSubagent ? "SubagentStop" : "Stop"),
|
|
838
|
+
sessionId,
|
|
839
|
+
transcriptPath: eventData.transcript_path ?? "",
|
|
840
|
+
cwd: eventData.cwd ?? "",
|
|
841
|
+
stopHookActive: eventData.stop_hook_active ?? false,
|
|
842
|
+
inputTokens: extracted.inputTokens,
|
|
843
|
+
outputTokens: extracted.outputTokens,
|
|
844
|
+
numTurns: extracted.numTurns,
|
|
845
|
+
// Per-turn work signals for the Claude Code classifier (D-027).
|
|
846
|
+
// Always emitted as JSON numbers — the backend classifier and
|
|
847
|
+
// KPI formulas must see numeric 0, not missing keys or strings.
|
|
848
|
+
toolCallCount: extracted.toolCallCount,
|
|
849
|
+
filesEditedCount: extracted.filesEditedCount,
|
|
850
|
+
bashCommandCount: extracted.bashCommandCount
|
|
851
|
+
};
|
|
852
|
+
if (typeof extracted.latencyMs === "number") {
|
|
853
|
+
customData.latencyMs = extracted.latencyMs;
|
|
854
|
+
}
|
|
855
|
+
if (isSubagent) {
|
|
856
|
+
const subagent = extractSubagentName(eventData);
|
|
857
|
+
if (subagent) {
|
|
858
|
+
customData.subagent = subagent;
|
|
859
|
+
}
|
|
860
|
+
} else if (extracted.skill) {
|
|
861
|
+
customData.skill = extracted.skill;
|
|
862
|
+
}
|
|
863
|
+
const payloadAssistant = eventData.last_assistant_message;
|
|
864
|
+
const response = typeof payloadAssistant === "string" && payloadAssistant.trim() ? payloadAssistant : extracted.response;
|
|
865
|
+
return {
|
|
866
|
+
prompt: extracted.prompt,
|
|
867
|
+
response,
|
|
868
|
+
chatId: sessionId,
|
|
869
|
+
source: config.source,
|
|
870
|
+
modelName: extracted.modelName ?? void 0,
|
|
871
|
+
tokens: extracted.tokens,
|
|
872
|
+
customData
|
|
873
|
+
};
|
|
874
|
+
}
|
|
875
|
+
default:
|
|
876
|
+
return null;
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
// src/monitor/plugins/claude-code/index.ts
|
|
881
|
+
var TOOL_ID = "claude-code";
|
|
882
|
+
var SUPPORTED_HOOK_EVENTS = /* @__PURE__ */ new Set(["stop", "subagent-stop"]);
|
|
883
|
+
function debugLog(label, data) {
|
|
884
|
+
if (process.env.OLAKAI_MONITOR_DEBUG !== "1") return;
|
|
885
|
+
try {
|
|
886
|
+
const logPath = `/tmp/olakai-monitor-debug-${process.pid}.log`;
|
|
887
|
+
const line = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${label}: ${typeof data === "string" ? data : JSON.stringify(data, null, 2)}
|
|
888
|
+
`;
|
|
889
|
+
fs5.appendFileSync(logPath, line, "utf-8");
|
|
890
|
+
} catch {
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
function resolveProjectRootFromPayload(eventData, fallbackCwd) {
|
|
894
|
+
const payloadCwd = typeof eventData.cwd === "string" && eventData.cwd.trim() ? eventData.cwd : fallbackCwd;
|
|
895
|
+
return findConfiguredWorkspace(payloadCwd, [TOOL_ID]);
|
|
896
|
+
}
|
|
897
|
+
var claudeCodePlugin = {
|
|
898
|
+
id: TOOL_ID,
|
|
899
|
+
displayName: "Claude Code",
|
|
900
|
+
install(opts) {
|
|
901
|
+
return installClaudeCode(opts);
|
|
902
|
+
},
|
|
903
|
+
uninstall(opts) {
|
|
904
|
+
return uninstallClaudeCode(opts);
|
|
905
|
+
},
|
|
906
|
+
status(opts) {
|
|
907
|
+
return getClaudeCodeStatus(opts);
|
|
908
|
+
},
|
|
909
|
+
async handleHook(eventName, payloadJson) {
|
|
910
|
+
setDebugLogger(debugLog);
|
|
911
|
+
const event = eventName.trim();
|
|
912
|
+
if (!SUPPORTED_HOOK_EVENTS.has(event)) {
|
|
913
|
+
debugLog("hook-unknown-event", event);
|
|
914
|
+
return null;
|
|
915
|
+
}
|
|
916
|
+
const eventData = payloadJson ?? {};
|
|
917
|
+
debugLog("event-parsed", { event, eventData });
|
|
918
|
+
const projectRoot = resolveProjectRootFromPayload(
|
|
919
|
+
eventData,
|
|
920
|
+
process.cwd()
|
|
921
|
+
);
|
|
922
|
+
if (!projectRoot) {
|
|
923
|
+
debugLog("config-not-found", {
|
|
924
|
+
startDir: typeof eventData.cwd === "string" && eventData.cwd.trim() ? eventData.cwd : process.cwd()
|
|
925
|
+
});
|
|
926
|
+
return null;
|
|
927
|
+
}
|
|
928
|
+
const config = loadClaudeCodeConfig(projectRoot, () => {
|
|
929
|
+
});
|
|
930
|
+
if (!config) {
|
|
931
|
+
debugLog("config-load-failed", { projectRoot });
|
|
932
|
+
return null;
|
|
933
|
+
}
|
|
934
|
+
const payload = buildClaudeCodePayload(event, eventData, config);
|
|
935
|
+
if (!payload) return null;
|
|
936
|
+
debugLog("payload-built", payload);
|
|
937
|
+
const sessionId = typeof eventData.session_id === "string" && eventData.session_id || void 0;
|
|
938
|
+
const extracted = extractFromTranscript(
|
|
939
|
+
eventData.transcript_path,
|
|
940
|
+
debugLog
|
|
941
|
+
);
|
|
942
|
+
const userTurnTimestamp = extracted.userTurnTimestamp;
|
|
943
|
+
if (extracted.prompt.trim() === "" && extracted.response.trim() === "" && extracted.numTurns === 0) {
|
|
944
|
+
debugLog("empty-parse-skip", {
|
|
945
|
+
event,
|
|
946
|
+
sessionId,
|
|
947
|
+
transcriptPath: eventData.transcript_path
|
|
948
|
+
});
|
|
949
|
+
return null;
|
|
950
|
+
}
|
|
951
|
+
if (sessionId) {
|
|
952
|
+
const existingState = loadSessionState(sessionId);
|
|
953
|
+
if (!shouldReportTurn(existingState, userTurnTimestamp)) {
|
|
954
|
+
debugLog("turn-dedup-skip", { sessionId, userTurnTimestamp });
|
|
955
|
+
return null;
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
if (sessionId && userTurnTimestamp) {
|
|
959
|
+
saveSessionState(sessionId, {
|
|
960
|
+
lastUserTimestamp: userTurnTimestamp,
|
|
961
|
+
lastReportedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
962
|
+
numTurnsAtLastReport: extracted.numTurns
|
|
963
|
+
});
|
|
964
|
+
debugLog("state-saved", {
|
|
965
|
+
sessionId,
|
|
966
|
+
userTurnTimestamp,
|
|
967
|
+
numTurns: extracted.numTurns
|
|
968
|
+
});
|
|
969
|
+
}
|
|
970
|
+
return {
|
|
971
|
+
payload,
|
|
972
|
+
transport: {
|
|
973
|
+
endpoint: config.monitoringEndpoint,
|
|
974
|
+
apiKey: config.apiKey,
|
|
975
|
+
projectRoot
|
|
976
|
+
}
|
|
977
|
+
};
|
|
978
|
+
},
|
|
979
|
+
async detectInstalled(opts) {
|
|
980
|
+
const projectRoot = opts?.projectRoot ?? process.cwd();
|
|
981
|
+
try {
|
|
982
|
+
if (fs5.existsSync(getMonitorConfigPath(projectRoot, TOOL_ID))) {
|
|
983
|
+
return true;
|
|
984
|
+
}
|
|
985
|
+
if (fs5.existsSync(getLegacyClaudeMonitorConfigPath(projectRoot))) {
|
|
986
|
+
return true;
|
|
987
|
+
}
|
|
988
|
+
} catch {
|
|
989
|
+
}
|
|
990
|
+
return detectClaudeBinaryOnPath();
|
|
991
|
+
}
|
|
992
|
+
};
|
|
993
|
+
function detectClaudeBinaryOnPath() {
|
|
994
|
+
try {
|
|
995
|
+
const probe = spawnSync2(
|
|
996
|
+
process.platform === "win32" ? "where" : "which",
|
|
997
|
+
["claude"],
|
|
998
|
+
{
|
|
999
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
1000
|
+
timeout: 1e3
|
|
1001
|
+
}
|
|
1002
|
+
);
|
|
1003
|
+
if (probe.status === 0 && probe.stdout && probe.stdout.toString().trim()) {
|
|
1004
|
+
return true;
|
|
1005
|
+
}
|
|
1006
|
+
} catch {
|
|
1007
|
+
}
|
|
1008
|
+
return false;
|
|
1009
|
+
}
|
|
1010
|
+
registerPlugin(claudeCodePlugin);
|
|
1011
|
+
|
|
1012
|
+
// src/monitor/plugins/codex/index.ts
|
|
1013
|
+
import * as fs10 from "fs";
|
|
1014
|
+
import { spawnSync as spawnSync3 } from "child_process";
|
|
1015
|
+
|
|
1016
|
+
// src/monitor/plugins/codex/install.ts
|
|
1017
|
+
import * as fs7 from "fs";
|
|
1018
|
+
import * as path7 from "path";
|
|
1019
|
+
import * as TOML from "@iarna/toml";
|
|
1020
|
+
|
|
1021
|
+
// src/monitor/plugins/codex/paths.ts
|
|
1022
|
+
import * as os3 from "os";
|
|
1023
|
+
import * as path5 from "path";
|
|
1024
|
+
var CODEX_HOME_DIRNAME = ".codex";
|
|
1025
|
+
var CODEX_CONFIG_FILENAME = "config.toml";
|
|
1026
|
+
var CODEX_SESSIONS_DIRNAME = "sessions";
|
|
1027
|
+
function getCodexHomeDir() {
|
|
1028
|
+
return path5.join(os3.homedir(), CODEX_HOME_DIRNAME);
|
|
1029
|
+
}
|
|
1030
|
+
function getCodexConfigPath() {
|
|
1031
|
+
return path5.join(getCodexHomeDir(), CODEX_CONFIG_FILENAME);
|
|
1032
|
+
}
|
|
1033
|
+
function getCodexSessionsDir() {
|
|
1034
|
+
return path5.join(getCodexHomeDir(), CODEX_SESSIONS_DIRNAME);
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
// src/monitor/plugins/codex/hooks.ts
|
|
1038
|
+
var OLAKAI_HOOK_MARKER2 = "olakai monitor hook";
|
|
1039
|
+
var CODEX_HOOK_TIMEOUT_SECONDS = 5;
|
|
1040
|
+
var SUPPORTED_HOOK_EVENT_NAMES = ["Stop"];
|
|
1041
|
+
function buildOlakaiHookGroup(event) {
|
|
1042
|
+
return {
|
|
1043
|
+
hooks: [
|
|
1044
|
+
{
|
|
1045
|
+
type: "command",
|
|
1046
|
+
command: `olakai monitor hook --tool codex ${event}`,
|
|
1047
|
+
timeout: CODEX_HOOK_TIMEOUT_SECONDS
|
|
1048
|
+
}
|
|
1049
|
+
]
|
|
1050
|
+
};
|
|
1051
|
+
}
|
|
1052
|
+
function isOlakaiHandler(handler) {
|
|
1053
|
+
return typeof handler.command === "string" && handler.command.includes(OLAKAI_HOOK_MARKER2);
|
|
1054
|
+
}
|
|
1055
|
+
function groupContainsOlakaiHandler(group) {
|
|
1056
|
+
if (!Array.isArray(group.hooks)) return false;
|
|
1057
|
+
return group.hooks.some(isOlakaiHandler);
|
|
1058
|
+
}
|
|
1059
|
+
function mergeCodexHooks(existing, events = SUPPORTED_HOOK_EVENT_NAMES) {
|
|
1060
|
+
const merged = { ...existing ?? {} };
|
|
1061
|
+
for (const event of events) {
|
|
1062
|
+
const existingGroups = merged[event] ?? [];
|
|
1063
|
+
const hasOlakaiHook = existingGroups.some(groupContainsOlakaiHandler);
|
|
1064
|
+
if (hasOlakaiHook) {
|
|
1065
|
+
merged[event] = existingGroups;
|
|
1066
|
+
} else {
|
|
1067
|
+
merged[event] = [...existingGroups, buildOlakaiHookGroup(event)];
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
return merged;
|
|
1071
|
+
}
|
|
1072
|
+
function stripOlakaiHooks(existing) {
|
|
1073
|
+
if (!existing) return void 0;
|
|
1074
|
+
const cleaned = {};
|
|
1075
|
+
for (const [event, groups] of Object.entries(existing)) {
|
|
1076
|
+
if (!Array.isArray(groups)) continue;
|
|
1077
|
+
const filteredGroups = [];
|
|
1078
|
+
for (const group of groups) {
|
|
1079
|
+
const handlers = Array.isArray(group.hooks) ? group.hooks : [];
|
|
1080
|
+
const remaining = handlers.filter((h) => !isOlakaiHandler(h));
|
|
1081
|
+
if (remaining.length === 0 && handlers.length > 0) {
|
|
1082
|
+
continue;
|
|
1083
|
+
}
|
|
1084
|
+
if (remaining.length === handlers.length) {
|
|
1085
|
+
filteredGroups.push(group);
|
|
1086
|
+
} else {
|
|
1087
|
+
filteredGroups.push({ ...group, hooks: remaining });
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
if (filteredGroups.length > 0) {
|
|
1091
|
+
cleaned[event] = filteredGroups;
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
return Object.keys(cleaned).length > 0 ? cleaned : void 0;
|
|
1095
|
+
}
|
|
1096
|
+
function hasOlakaiHooksInstalled(parsed) {
|
|
1097
|
+
const hooks = parsed.hooks;
|
|
1098
|
+
if (!hooks) return false;
|
|
1099
|
+
for (const groups of Object.values(hooks)) {
|
|
1100
|
+
if (!Array.isArray(groups)) continue;
|
|
1101
|
+
for (const group of groups) {
|
|
1102
|
+
if (groupContainsOlakaiHandler(group)) return true;
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
return false;
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
// src/monitor/plugins/codex/config.ts
|
|
1109
|
+
import * as fs6 from "fs";
|
|
1110
|
+
import * as path6 from "path";
|
|
1111
|
+
function getCodexConfigPath2(projectRoot) {
|
|
1112
|
+
return getMonitorConfigPath(projectRoot, "codex");
|
|
1113
|
+
}
|
|
1114
|
+
function loadCodexConfig(projectRoot) {
|
|
1115
|
+
const filePath = getCodexConfigPath2(projectRoot);
|
|
1116
|
+
try {
|
|
1117
|
+
if (!fs6.existsSync(filePath)) return null;
|
|
1118
|
+
const raw = fs6.readFileSync(filePath, "utf-8");
|
|
1119
|
+
return JSON.parse(raw);
|
|
1120
|
+
} catch {
|
|
1121
|
+
return null;
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
function writeCodexConfig(projectRoot, config) {
|
|
1125
|
+
const filePath = getCodexConfigPath2(projectRoot);
|
|
1126
|
+
const dir = path6.dirname(filePath);
|
|
1127
|
+
if (!fs6.existsSync(dir)) {
|
|
1128
|
+
fs6.mkdirSync(dir, { recursive: true });
|
|
1129
|
+
}
|
|
1130
|
+
fs6.writeFileSync(filePath, JSON.stringify(config, null, 2) + "\n", "utf-8");
|
|
1131
|
+
try {
|
|
1132
|
+
fs6.chmodSync(filePath, 384);
|
|
1133
|
+
} catch {
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
function deleteCodexConfig(projectRoot) {
|
|
1137
|
+
const filePath = getCodexConfigPath2(projectRoot);
|
|
1138
|
+
if (!fs6.existsSync(filePath)) return false;
|
|
1139
|
+
try {
|
|
1140
|
+
fs6.unlinkSync(filePath);
|
|
1141
|
+
return true;
|
|
1142
|
+
} catch {
|
|
1143
|
+
return false;
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
// src/monitor/plugins/codex/install.ts
|
|
1148
|
+
var CODEX_SOURCE = "codex";
|
|
1149
|
+
var CODEX_AGENT_SOURCE = "CODEX";
|
|
1150
|
+
var CODEX_AGENT_CATEGORY = "CODING";
|
|
1151
|
+
async function installCodex(opts) {
|
|
1152
|
+
const projectRoot = opts.projectRoot ?? process.cwd();
|
|
1153
|
+
const token = getValidToken();
|
|
1154
|
+
if (!token) {
|
|
1155
|
+
console.error("Not logged in. Run 'olakai login' first.");
|
|
1156
|
+
process.exit(1);
|
|
1157
|
+
}
|
|
1158
|
+
console.log("Setting up Codex CLI monitoring for this workspace...\n");
|
|
1159
|
+
const agent = await provisionSelfMonitorAgent({
|
|
1160
|
+
projectRoot,
|
|
1161
|
+
source: CODEX_AGENT_SOURCE,
|
|
1162
|
+
displayName: "Codex CLI",
|
|
1163
|
+
category: CODEX_AGENT_CATEGORY
|
|
1164
|
+
});
|
|
1165
|
+
const monitoringEndpoint = `${getBaseUrl()}/api/monitoring/prompt`;
|
|
1166
|
+
const apiKey = agent.apiKey?.key;
|
|
1167
|
+
if (!apiKey) {
|
|
1168
|
+
console.error(
|
|
1169
|
+
"Internal error: agent provisioned but no API key returned. Please re-run 'olakai monitor init'."
|
|
1170
|
+
);
|
|
1171
|
+
process.exit(1);
|
|
1172
|
+
}
|
|
1173
|
+
const { configExisted: codexConfigExisted } = installCodexHooksConfig();
|
|
1174
|
+
const monitorConfig = {
|
|
1175
|
+
agentId: agent.id,
|
|
1176
|
+
apiKey,
|
|
1177
|
+
agentName: agent.name,
|
|
1178
|
+
source: CODEX_SOURCE,
|
|
1179
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1180
|
+
monitoringEndpoint
|
|
1181
|
+
};
|
|
1182
|
+
writeCodexConfig(projectRoot, monitorConfig);
|
|
1183
|
+
const configPath = getCodexConfigPath2(projectRoot);
|
|
1184
|
+
const configRel = path7.relative(projectRoot, configPath);
|
|
1185
|
+
console.log("");
|
|
1186
|
+
console.log(`\u2713 Agent "${agent.name}" configured (ID: ${agent.id})`);
|
|
1187
|
+
if (agent.apiKey?.key) {
|
|
1188
|
+
console.log("\u2713 API key generated");
|
|
1189
|
+
}
|
|
1190
|
+
console.log(
|
|
1191
|
+
`\u2713 Codex hooks configured in ~/${CODEX_HOME_DIRNAME}/${CODEX_CONFIG_FILENAME}`
|
|
1192
|
+
);
|
|
1193
|
+
console.log(`\u2713 Monitor config saved to ${configRel}`);
|
|
1194
|
+
console.log("");
|
|
1195
|
+
console.log(
|
|
1196
|
+
"Congrats! Monitoring is now active. Codex CLI will report activity to Olakai"
|
|
1197
|
+
);
|
|
1198
|
+
console.log(`on each turn.`);
|
|
1199
|
+
console.log("");
|
|
1200
|
+
console.log(
|
|
1201
|
+
`\u26A0 Ensure ${OLAKAI_DIR}/ is in your .gitignore (it contains your API key).`
|
|
1202
|
+
);
|
|
1203
|
+
console.log(
|
|
1204
|
+
`\u26A0 Codex hooks require codex >= 0.124.0. Earlier versions silently skip them.`
|
|
1205
|
+
);
|
|
1206
|
+
if (codexConfigExisted) {
|
|
1207
|
+
console.log(
|
|
1208
|
+
`\u26A0 Existing comments in ~/${CODEX_HOME_DIRNAME}/${CODEX_CONFIG_FILENAME} were not preserved (TOML serializer limitation).`
|
|
1209
|
+
);
|
|
1210
|
+
}
|
|
1211
|
+
console.log("");
|
|
1212
|
+
console.log("To check status: olakai monitor status --tool codex");
|
|
1213
|
+
console.log("To disable: olakai monitor disable --tool codex");
|
|
1214
|
+
return {
|
|
1215
|
+
agentId: agent.id,
|
|
1216
|
+
agentName: agent.name,
|
|
1217
|
+
source: CODEX_SOURCE,
|
|
1218
|
+
monitoringEndpoint
|
|
1219
|
+
};
|
|
1220
|
+
}
|
|
1221
|
+
function installCodexHooksConfig() {
|
|
1222
|
+
const homeDir = getCodexHomeDir();
|
|
1223
|
+
const configPath = getCodexConfigPath();
|
|
1224
|
+
if (!fs7.existsSync(homeDir)) {
|
|
1225
|
+
fs7.mkdirSync(homeDir, { recursive: true });
|
|
1226
|
+
}
|
|
1227
|
+
const configExisted = fs7.existsSync(configPath);
|
|
1228
|
+
const parsed = readCodexConfigToml(configPath);
|
|
1229
|
+
const merged = {
|
|
1230
|
+
...parsed,
|
|
1231
|
+
hooks: mergeCodexHooks(parsed.hooks, SUPPORTED_HOOK_EVENT_NAMES)
|
|
1232
|
+
};
|
|
1233
|
+
writeCodexConfigToml(configPath, merged);
|
|
1234
|
+
return { configExisted };
|
|
1235
|
+
}
|
|
1236
|
+
async function uninstallCodex(opts) {
|
|
1237
|
+
const projectRoot = opts.projectRoot ?? process.cwd();
|
|
1238
|
+
const removedHooks = stripCodexHooksConfig();
|
|
1239
|
+
if (removedHooks) {
|
|
1240
|
+
console.log(
|
|
1241
|
+
`\u2713 Olakai hooks removed from ~/${CODEX_HOME_DIRNAME}/${CODEX_CONFIG_FILENAME}`
|
|
1242
|
+
);
|
|
1243
|
+
} else {
|
|
1244
|
+
console.log("No Olakai hooks found in Codex config.");
|
|
1245
|
+
}
|
|
1246
|
+
if (!opts.keepConfig) {
|
|
1247
|
+
const configPath = getCodexConfigPath2(projectRoot);
|
|
1248
|
+
const configRel = path7.relative(projectRoot, configPath);
|
|
1249
|
+
if (deleteCodexConfig(projectRoot)) {
|
|
1250
|
+
console.log(`\u2713 Monitor config removed (${configRel})`);
|
|
1251
|
+
}
|
|
1252
|
+
} else {
|
|
1253
|
+
const configPath = getCodexConfigPath2(projectRoot);
|
|
1254
|
+
const configRel = path7.relative(projectRoot, configPath);
|
|
1255
|
+
console.log(`Monitor config retained at ${configRel}`);
|
|
1256
|
+
}
|
|
1257
|
+
console.log("");
|
|
1258
|
+
console.log(
|
|
1259
|
+
"Monitoring disabled. Run 'olakai monitor init --tool codex' to re-enable."
|
|
1260
|
+
);
|
|
1261
|
+
}
|
|
1262
|
+
function applyOlakaiStripToConfig(parsed) {
|
|
1263
|
+
const cleaned = stripOlakaiHooks(parsed.hooks);
|
|
1264
|
+
const next = { ...parsed };
|
|
1265
|
+
if (cleaned === void 0) {
|
|
1266
|
+
delete next.hooks;
|
|
1267
|
+
} else {
|
|
1268
|
+
next.hooks = cleaned;
|
|
1269
|
+
}
|
|
1270
|
+
return next;
|
|
1271
|
+
}
|
|
1272
|
+
function stripCodexHooksConfig() {
|
|
1273
|
+
const configPath = getCodexConfigPath();
|
|
1274
|
+
if (!fs7.existsSync(configPath)) return false;
|
|
1275
|
+
const parsed = readCodexConfigToml(configPath);
|
|
1276
|
+
if (!hasOlakaiHooksInstalled(parsed)) return false;
|
|
1277
|
+
const next = applyOlakaiStripToConfig(parsed);
|
|
1278
|
+
writeCodexConfigToml(configPath, next);
|
|
1279
|
+
return true;
|
|
1280
|
+
}
|
|
1281
|
+
function readCodexConfigToml(configPath) {
|
|
1282
|
+
try {
|
|
1283
|
+
if (!fs7.existsSync(configPath)) return {};
|
|
1284
|
+
const raw = fs7.readFileSync(configPath, "utf-8");
|
|
1285
|
+
if (!raw.trim()) return {};
|
|
1286
|
+
return TOML.parse(raw);
|
|
1287
|
+
} catch {
|
|
1288
|
+
return {};
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
function writeCodexConfigToml(configPath, data) {
|
|
1292
|
+
const dir = path7.dirname(configPath);
|
|
1293
|
+
if (!fs7.existsSync(dir)) {
|
|
1294
|
+
fs7.mkdirSync(dir, { recursive: true });
|
|
1295
|
+
}
|
|
1296
|
+
const serialized = TOML.stringify(data);
|
|
1297
|
+
fs7.writeFileSync(configPath, serialized, "utf-8");
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
// src/monitor/plugins/codex/status.ts
|
|
1301
|
+
import path8 from "path";
|
|
1302
|
+
import * as fs8 from "fs";
|
|
1303
|
+
async function getCodexStatus(opts) {
|
|
1304
|
+
const projectRoot = opts?.projectRoot ?? process.cwd();
|
|
1305
|
+
const configPath = getCodexConfigPath2(projectRoot);
|
|
1306
|
+
const config = loadCodexConfig(projectRoot);
|
|
1307
|
+
const hooksConfigured = isHooksBlockInstalled();
|
|
1308
|
+
if (!config) {
|
|
1309
|
+
return {
|
|
1310
|
+
toolId: "codex",
|
|
1311
|
+
configured: false,
|
|
1312
|
+
hooksConfigured,
|
|
1313
|
+
configPath,
|
|
1314
|
+
notes: hooksConfigured ? [
|
|
1315
|
+
`Codex hooks present in ~/${CODEX_HOME_DIRNAME}/${CODEX_CONFIG_FILENAME} but no monitor config in this workspace \u2014 re-run init.`
|
|
1316
|
+
] : []
|
|
1317
|
+
};
|
|
1318
|
+
}
|
|
1319
|
+
return {
|
|
1320
|
+
toolId: "codex",
|
|
1321
|
+
configured: true,
|
|
1322
|
+
hooksConfigured,
|
|
1323
|
+
agentId: config.agentId,
|
|
1324
|
+
agentName: config.agentName,
|
|
1325
|
+
source: config.source,
|
|
1326
|
+
apiKeyMasked: config.apiKey.slice(0, 12) + "...",
|
|
1327
|
+
monitoringEndpoint: config.monitoringEndpoint,
|
|
1328
|
+
configuredAt: config.createdAt,
|
|
1329
|
+
configPath
|
|
1330
|
+
};
|
|
1331
|
+
}
|
|
1332
|
+
function isHooksBlockInstalled() {
|
|
1333
|
+
const homeConfig = getCodexConfigPath();
|
|
1334
|
+
if (!fs8.existsSync(homeConfig)) return false;
|
|
1335
|
+
const parsed = readCodexConfigToml(homeConfig);
|
|
1336
|
+
return hasOlakaiHooksInstalled(parsed);
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
// src/monitor/plugins/codex/transcript.ts
|
|
1340
|
+
import * as fs9 from "fs";
|
|
1341
|
+
import * as path9 from "path";
|
|
1342
|
+
function emptyRollout() {
|
|
1343
|
+
return {
|
|
1344
|
+
prompt: "",
|
|
1345
|
+
response: "",
|
|
1346
|
+
modelName: null,
|
|
1347
|
+
inputTokens: 0,
|
|
1348
|
+
outputTokens: 0,
|
|
1349
|
+
cachedInputTokens: 0,
|
|
1350
|
+
reasoningOutputTokens: 0,
|
|
1351
|
+
tokens: 0,
|
|
1352
|
+
numTurns: 0
|
|
1353
|
+
};
|
|
1354
|
+
}
|
|
1355
|
+
var noopDebug2 = () => {
|
|
1356
|
+
};
|
|
1357
|
+
var DEFAULT_LIMITS = {
|
|
1358
|
+
maxDirs: 200,
|
|
1359
|
+
maxFiles: 5e3
|
|
1360
|
+
};
|
|
1361
|
+
function findRolloutPathForSession(sessionId, sessionsDir = getCodexSessionsDir(), limits = {}) {
|
|
1362
|
+
const merged = { ...DEFAULT_LIMITS, ...limits };
|
|
1363
|
+
if (!sessionId) return null;
|
|
1364
|
+
if (!fs9.existsSync(sessionsDir)) return null;
|
|
1365
|
+
const suffix = `-${sessionId}.jsonl`;
|
|
1366
|
+
const matches = [];
|
|
1367
|
+
let dirsScanned = 0;
|
|
1368
|
+
let filesScanned = 0;
|
|
1369
|
+
const queue = [sessionsDir];
|
|
1370
|
+
while (queue.length > 0) {
|
|
1371
|
+
const dir = queue.shift();
|
|
1372
|
+
if (dirsScanned++ > merged.maxDirs) break;
|
|
1373
|
+
let entries;
|
|
1374
|
+
try {
|
|
1375
|
+
entries = fs9.readdirSync(dir, { withFileTypes: true });
|
|
1376
|
+
} catch {
|
|
1377
|
+
continue;
|
|
1378
|
+
}
|
|
1379
|
+
for (const entry of entries) {
|
|
1380
|
+
if (filesScanned++ > merged.maxFiles) break;
|
|
1381
|
+
const full = path9.join(dir, entry.name);
|
|
1382
|
+
if (entry.isDirectory()) {
|
|
1383
|
+
queue.push(full);
|
|
1384
|
+
continue;
|
|
1385
|
+
}
|
|
1386
|
+
if (!entry.isFile()) continue;
|
|
1387
|
+
if (!entry.name.endsWith(suffix)) continue;
|
|
1388
|
+
if (!entry.name.startsWith("rollout-")) continue;
|
|
1389
|
+
try {
|
|
1390
|
+
const stat = fs9.statSync(full);
|
|
1391
|
+
matches.push({ path: full, mtimeMs: stat.mtimeMs });
|
|
1392
|
+
} catch {
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
if (matches.length === 0) return null;
|
|
1397
|
+
matches.sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
1398
|
+
return matches[0].path;
|
|
1399
|
+
}
|
|
1400
|
+
function parseRolloutContent(raw, debugLog4 = noopDebug2) {
|
|
1401
|
+
const result = emptyRollout();
|
|
1402
|
+
if (!raw) return result;
|
|
1403
|
+
const lines = raw.split("\n");
|
|
1404
|
+
let lastUserMessage = "";
|
|
1405
|
+
let lastAssistantMessage = "";
|
|
1406
|
+
let lastTokenUsage = null;
|
|
1407
|
+
let totalTokenUsage = null;
|
|
1408
|
+
let modelName = null;
|
|
1409
|
+
let userTurnCount = 0;
|
|
1410
|
+
for (const line of lines) {
|
|
1411
|
+
const trimmed = line.trim();
|
|
1412
|
+
if (!trimmed) continue;
|
|
1413
|
+
let parsed;
|
|
1414
|
+
try {
|
|
1415
|
+
parsed = JSON.parse(trimmed);
|
|
1416
|
+
} catch (err) {
|
|
1417
|
+
debugLog4("rollout-line-parse-failed", {
|
|
1418
|
+
line: trimmed.slice(0, 120),
|
|
1419
|
+
error: err.message
|
|
1420
|
+
});
|
|
1421
|
+
continue;
|
|
1422
|
+
}
|
|
1423
|
+
const type = parsed.type;
|
|
1424
|
+
const payload = parsed.payload;
|
|
1425
|
+
if (!type || !payload) continue;
|
|
1426
|
+
if (type === "session_meta") {
|
|
1427
|
+
continue;
|
|
1428
|
+
}
|
|
1429
|
+
if (type === "event_msg") {
|
|
1430
|
+
const ev = payload;
|
|
1431
|
+
const evType = ev.type;
|
|
1432
|
+
if (evType === "user_message" && typeof ev.message === "string") {
|
|
1433
|
+
lastUserMessage = ev.message;
|
|
1434
|
+
userTurnCount += 1;
|
|
1435
|
+
} else if (evType === "agent_message" && typeof ev.message === "string") {
|
|
1436
|
+
lastAssistantMessage = ev.message;
|
|
1437
|
+
} else if (evType === "token_count" && ev.info) {
|
|
1438
|
+
if (ev.info.last_token_usage) {
|
|
1439
|
+
lastTokenUsage = ev.info.last_token_usage;
|
|
1440
|
+
}
|
|
1441
|
+
if (ev.info.total_token_usage) {
|
|
1442
|
+
totalTokenUsage = ev.info.total_token_usage;
|
|
1443
|
+
}
|
|
1444
|
+
} else if (evType === "session_configured" && typeof ev.model === "string" && ev.model) {
|
|
1445
|
+
modelName = ev.model;
|
|
1446
|
+
}
|
|
1447
|
+
continue;
|
|
1448
|
+
}
|
|
1449
|
+
if (type === "response_item") {
|
|
1450
|
+
const ri = payload;
|
|
1451
|
+
if (ri.type === "message" && Array.isArray(ri.content)) {
|
|
1452
|
+
const text = extractTextFromContent(ri.content);
|
|
1453
|
+
if (!text) continue;
|
|
1454
|
+
if (ri.role === "user") {
|
|
1455
|
+
lastUserMessage = text;
|
|
1456
|
+
userTurnCount += 1;
|
|
1457
|
+
} else if (ri.role === "assistant") {
|
|
1458
|
+
lastAssistantMessage = text;
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
continue;
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
result.prompt = lastUserMessage;
|
|
1465
|
+
result.response = lastAssistantMessage;
|
|
1466
|
+
result.modelName = modelName;
|
|
1467
|
+
result.numTurns = userTurnCount;
|
|
1468
|
+
const tokenSource = lastTokenUsage ?? totalTokenUsage;
|
|
1469
|
+
if (tokenSource) {
|
|
1470
|
+
result.inputTokens = numberOrZero(tokenSource.input_tokens);
|
|
1471
|
+
result.outputTokens = numberOrZero(tokenSource.output_tokens);
|
|
1472
|
+
result.cachedInputTokens = numberOrZero(tokenSource.cached_input_tokens);
|
|
1473
|
+
result.reasoningOutputTokens = numberOrZero(
|
|
1474
|
+
tokenSource.reasoning_output_tokens
|
|
1475
|
+
);
|
|
1476
|
+
result.tokens = numberOrZero(tokenSource.total_tokens) || result.inputTokens + result.outputTokens;
|
|
1477
|
+
}
|
|
1478
|
+
return result;
|
|
1479
|
+
}
|
|
1480
|
+
function extractTextFromContent(content) {
|
|
1481
|
+
const parts = [];
|
|
1482
|
+
for (const block of content) {
|
|
1483
|
+
if (typeof block.text !== "string") continue;
|
|
1484
|
+
if (block.type === "output_text" || block.type === "input_text" || block.type === "text") {
|
|
1485
|
+
parts.push(block.text);
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
return parts.join("\n").trim();
|
|
1489
|
+
}
|
|
1490
|
+
function numberOrZero(value) {
|
|
1491
|
+
return typeof value === "number" && Number.isFinite(value) ? value : 0;
|
|
1492
|
+
}
|
|
1493
|
+
function loadRolloutForSession(sessionId, options = {}) {
|
|
1494
|
+
const debugLog4 = options.debugLog ?? noopDebug2;
|
|
1495
|
+
const sessionsDir = options.sessionsDir ?? getCodexSessionsDir();
|
|
1496
|
+
const result = emptyRollout();
|
|
1497
|
+
const rolloutPath = findRolloutPathForSession(sessionId, sessionsDir);
|
|
1498
|
+
if (!rolloutPath) {
|
|
1499
|
+
debugLog4("rollout-not-found", {
|
|
1500
|
+
sessionId,
|
|
1501
|
+
sessionsDir
|
|
1502
|
+
});
|
|
1503
|
+
return result;
|
|
1504
|
+
}
|
|
1505
|
+
let raw;
|
|
1506
|
+
try {
|
|
1507
|
+
raw = fs9.readFileSync(rolloutPath, "utf-8");
|
|
1508
|
+
} catch (err) {
|
|
1509
|
+
debugLog4("rollout-read-failed", {
|
|
1510
|
+
rolloutPath,
|
|
1511
|
+
error: err.message
|
|
1512
|
+
});
|
|
1513
|
+
return result;
|
|
1514
|
+
}
|
|
1515
|
+
const parsed = parseRolloutContent(raw, debugLog4);
|
|
1516
|
+
parsed.rolloutPath = rolloutPath;
|
|
1517
|
+
return parsed;
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1520
|
+
// src/monitor/plugins/codex/hook.ts
|
|
1521
|
+
var noopDebug3 = () => {
|
|
1522
|
+
};
|
|
1523
|
+
var SUPPORTED_EVENTS = /* @__PURE__ */ new Set(["Stop", "UserPromptSubmit"]);
|
|
1524
|
+
function isSupportedCodexEvent(eventName) {
|
|
1525
|
+
return SUPPORTED_EVENTS.has(eventName);
|
|
1526
|
+
}
|
|
1527
|
+
function buildCodexPayload(eventName, eventData, config, rollout = emptyRollout()) {
|
|
1528
|
+
if (!isSupportedCodexEvent(eventName)) return null;
|
|
1529
|
+
if (eventName === "UserPromptSubmit") return null;
|
|
1530
|
+
const sessionId = typeof eventData.session_id === "string" && eventData.session_id ? eventData.session_id : `codex-${Date.now()}`;
|
|
1531
|
+
const cwd = typeof eventData.cwd === "string" ? eventData.cwd : "";
|
|
1532
|
+
const turnId = typeof eventData.turn_id === "string" ? eventData.turn_id : "";
|
|
1533
|
+
const permissionMode = typeof eventData.permission_mode === "string" ? eventData.permission_mode : "";
|
|
1534
|
+
const transcriptPath = typeof eventData.transcript_path === "string" ? eventData.transcript_path : "";
|
|
1535
|
+
const modelName = (typeof eventData.model === "string" && eventData.model.trim() ? eventData.model : null) ?? rollout.modelName;
|
|
1536
|
+
const customData = {
|
|
1537
|
+
hookEvent: eventData.hook_event_name ?? eventName,
|
|
1538
|
+
sessionId,
|
|
1539
|
+
cwd,
|
|
1540
|
+
turnId,
|
|
1541
|
+
permissionMode,
|
|
1542
|
+
transcriptPath,
|
|
1543
|
+
inputTokens: rollout.inputTokens,
|
|
1544
|
+
outputTokens: rollout.outputTokens,
|
|
1545
|
+
cachedInputTokens: rollout.cachedInputTokens,
|
|
1546
|
+
reasoningOutputTokens: rollout.reasoningOutputTokens,
|
|
1547
|
+
numTurns: rollout.numTurns
|
|
1548
|
+
};
|
|
1549
|
+
if (rollout.rolloutPath) {
|
|
1550
|
+
customData.rolloutPath = rollout.rolloutPath;
|
|
1551
|
+
}
|
|
1552
|
+
if (typeof eventData.stop_hook_active === "boolean") {
|
|
1553
|
+
customData.stopHookActive = eventData.stop_hook_active;
|
|
1554
|
+
}
|
|
1555
|
+
const inlineAssistant = typeof eventData.last_assistant_message === "string" && eventData.last_assistant_message.trim() ? eventData.last_assistant_message : "";
|
|
1556
|
+
const response = inlineAssistant || rollout.response;
|
|
1557
|
+
return {
|
|
1558
|
+
prompt: rollout.prompt,
|
|
1559
|
+
response,
|
|
1560
|
+
chatId: sessionId,
|
|
1561
|
+
source: config.source,
|
|
1562
|
+
modelName: modelName ?? void 0,
|
|
1563
|
+
tokens: rollout.tokens,
|
|
1564
|
+
customData
|
|
1565
|
+
};
|
|
1566
|
+
}
|
|
1567
|
+
function handleCodexHook(eventName, payloadJson, config, options = {}) {
|
|
1568
|
+
const debugLog4 = options.debugLog ?? noopDebug3;
|
|
1569
|
+
if (!isSupportedCodexEvent(eventName)) {
|
|
1570
|
+
debugLog4("hook-unknown-event", eventName);
|
|
1571
|
+
return null;
|
|
1572
|
+
}
|
|
1573
|
+
if (eventName === "UserPromptSubmit") {
|
|
1574
|
+
debugLog4("user-prompt-submit-dropped", { eventName });
|
|
1575
|
+
return null;
|
|
1576
|
+
}
|
|
1577
|
+
const eventData = payloadJson ?? {};
|
|
1578
|
+
debugLog4("event-parsed", { eventName, eventData });
|
|
1579
|
+
const sessionId = typeof eventData.session_id === "string" ? eventData.session_id : "";
|
|
1580
|
+
let rollout = emptyRollout();
|
|
1581
|
+
if (eventName === "Stop" && sessionId) {
|
|
1582
|
+
rollout = loadRolloutForSession(sessionId, {
|
|
1583
|
+
debugLog: debugLog4,
|
|
1584
|
+
sessionsDir: options.sessionsDir
|
|
1585
|
+
});
|
|
1586
|
+
}
|
|
1587
|
+
const payload = buildCodexPayload(eventName, eventData, config, rollout);
|
|
1588
|
+
if (!payload) return null;
|
|
1589
|
+
if (!payload.prompt && !payload.response) {
|
|
1590
|
+
debugLog4("payload-empty", { eventName, sessionId });
|
|
1591
|
+
return null;
|
|
1592
|
+
}
|
|
1593
|
+
debugLog4("payload-built", payload);
|
|
1594
|
+
return payload;
|
|
1595
|
+
}
|
|
1596
|
+
|
|
1597
|
+
// src/monitor/plugins/codex/index.ts
|
|
1598
|
+
var TOOL_ID2 = "codex";
|
|
1599
|
+
function debugLog2(label, data) {
|
|
1600
|
+
if (process.env.OLAKAI_MONITOR_DEBUG !== "1") return;
|
|
1601
|
+
try {
|
|
1602
|
+
const logPath = `/tmp/olakai-monitor-debug-${process.pid}.log`;
|
|
1603
|
+
const line = `[${(/* @__PURE__ */ new Date()).toISOString()}] codex/${label}: ${typeof data === "string" ? data : JSON.stringify(data, null, 2)}
|
|
1604
|
+
`;
|
|
1605
|
+
fs10.appendFileSync(logPath, line, "utf-8");
|
|
1606
|
+
} catch {
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
function resolveCodexProjectRoot(eventData, fallbackCwd) {
|
|
1610
|
+
const payloadCwd = typeof eventData.cwd === "string" && eventData.cwd.trim() ? eventData.cwd : fallbackCwd;
|
|
1611
|
+
return findConfiguredWorkspace(payloadCwd, [TOOL_ID2]);
|
|
1612
|
+
}
|
|
1613
|
+
var codexPlugin = {
|
|
1614
|
+
id: TOOL_ID2,
|
|
1615
|
+
displayName: "OpenAI Codex CLI",
|
|
1616
|
+
install(opts) {
|
|
1617
|
+
return installCodex(opts);
|
|
1618
|
+
},
|
|
1619
|
+
uninstall(opts) {
|
|
1620
|
+
return uninstallCodex(opts);
|
|
1621
|
+
},
|
|
1622
|
+
status(opts) {
|
|
1623
|
+
return getCodexStatus(opts);
|
|
1624
|
+
},
|
|
1625
|
+
async handleHook(eventName, payloadJson) {
|
|
1626
|
+
const eventData = payloadJson ?? {};
|
|
1627
|
+
debugLog2("hook-fired", { eventName, hasPayload: payloadJson != null });
|
|
1628
|
+
const projectRoot = resolveCodexProjectRoot(eventData, process.cwd());
|
|
1629
|
+
if (!projectRoot) {
|
|
1630
|
+
debugLog2("config-not-found", {
|
|
1631
|
+
startDir: typeof eventData.cwd === "string" && eventData.cwd.trim() ? eventData.cwd : process.cwd()
|
|
1632
|
+
});
|
|
1633
|
+
return null;
|
|
1634
|
+
}
|
|
1635
|
+
const config = loadCodexConfig(projectRoot);
|
|
1636
|
+
if (!config) {
|
|
1637
|
+
debugLog2("monitor-config-missing", { projectRoot });
|
|
1638
|
+
return null;
|
|
1639
|
+
}
|
|
1640
|
+
const payload = handleCodexHook(eventName, eventData, config, {
|
|
1641
|
+
debugLog: debugLog2
|
|
1642
|
+
});
|
|
1643
|
+
if (!payload) return null;
|
|
1644
|
+
return {
|
|
1645
|
+
payload,
|
|
1646
|
+
transport: {
|
|
1647
|
+
endpoint: config.monitoringEndpoint,
|
|
1648
|
+
apiKey: config.apiKey,
|
|
1649
|
+
projectRoot
|
|
1650
|
+
}
|
|
1651
|
+
};
|
|
1652
|
+
},
|
|
1653
|
+
async detectInstalled(opts) {
|
|
1654
|
+
const projectRoot = opts?.projectRoot ?? process.cwd();
|
|
1655
|
+
try {
|
|
1656
|
+
if (fs10.existsSync(getCodexConfigPath2(projectRoot))) {
|
|
1657
|
+
return true;
|
|
1658
|
+
}
|
|
1659
|
+
} catch {
|
|
1660
|
+
}
|
|
1661
|
+
try {
|
|
1662
|
+
if (fs10.existsSync(getCodexConfigPath())) {
|
|
1663
|
+
return true;
|
|
1664
|
+
}
|
|
1665
|
+
if (fs10.existsSync(getCodexHomeDir())) {
|
|
1666
|
+
return true;
|
|
1667
|
+
}
|
|
1668
|
+
} catch {
|
|
1669
|
+
}
|
|
1670
|
+
return detectCodexBinaryOnPath();
|
|
1671
|
+
}
|
|
1672
|
+
};
|
|
1673
|
+
function detectCodexBinaryOnPath() {
|
|
1674
|
+
try {
|
|
1675
|
+
const probe = spawnSync3(
|
|
1676
|
+
process.platform === "win32" ? "where" : "which",
|
|
1677
|
+
["codex"],
|
|
1678
|
+
{
|
|
1679
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
1680
|
+
timeout: 1e3
|
|
1681
|
+
}
|
|
1682
|
+
);
|
|
1683
|
+
if (probe.status === 0 && probe.stdout && probe.stdout.toString().trim()) {
|
|
1684
|
+
return true;
|
|
1685
|
+
}
|
|
1686
|
+
} catch {
|
|
1687
|
+
}
|
|
1688
|
+
return false;
|
|
1689
|
+
}
|
|
1690
|
+
registerPlugin(codexPlugin);
|
|
1691
|
+
|
|
1692
|
+
// src/monitor/plugins/cursor/index.ts
|
|
1693
|
+
import * as fs15 from "fs";
|
|
1694
|
+
import * as os8 from "os";
|
|
1695
|
+
|
|
1696
|
+
// src/monitor/plugins/cursor/install.ts
|
|
1697
|
+
import * as fs12 from "fs";
|
|
1698
|
+
import * as os5 from "os";
|
|
1699
|
+
import * as path12 from "path";
|
|
1700
|
+
|
|
1701
|
+
// src/monitor/plugins/cursor/config.ts
|
|
1702
|
+
import * as fs11 from "fs";
|
|
1703
|
+
import * as path10 from "path";
|
|
1704
|
+
function getCursorConfigPath(projectRoot) {
|
|
1705
|
+
return getMonitorConfigPath(projectRoot, "cursor");
|
|
1706
|
+
}
|
|
1707
|
+
function loadCursorConfig(projectRoot) {
|
|
1708
|
+
const filePath = getCursorConfigPath(projectRoot);
|
|
1709
|
+
try {
|
|
1710
|
+
if (!fs11.existsSync(filePath)) return null;
|
|
1711
|
+
const raw = fs11.readFileSync(filePath, "utf-8");
|
|
1712
|
+
return JSON.parse(raw);
|
|
1713
|
+
} catch {
|
|
1714
|
+
return null;
|
|
1715
|
+
}
|
|
1716
|
+
}
|
|
1717
|
+
function writeCursorConfig(projectRoot, config) {
|
|
1718
|
+
const filePath = getCursorConfigPath(projectRoot);
|
|
1719
|
+
const dir = path10.dirname(filePath);
|
|
1720
|
+
if (!fs11.existsSync(dir)) {
|
|
1721
|
+
fs11.mkdirSync(dir, { recursive: true });
|
|
1722
|
+
}
|
|
1723
|
+
fs11.writeFileSync(filePath, JSON.stringify(config, null, 2) + "\n", "utf-8");
|
|
1724
|
+
try {
|
|
1725
|
+
fs11.chmodSync(filePath, 384);
|
|
1726
|
+
} catch {
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1729
|
+
function deleteCursorConfig(projectRoot) {
|
|
1730
|
+
const filePath = getCursorConfigPath(projectRoot);
|
|
1731
|
+
if (!fs11.existsSync(filePath)) return false;
|
|
1732
|
+
try {
|
|
1733
|
+
fs11.unlinkSync(filePath);
|
|
1734
|
+
return true;
|
|
1735
|
+
} catch {
|
|
1736
|
+
return false;
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
|
|
1740
|
+
// src/monitor/plugins/cursor/paths.ts
|
|
1741
|
+
import * as os4 from "os";
|
|
1742
|
+
import * as path11 from "path";
|
|
1743
|
+
var CURSOR_DIR_NAME = ".cursor";
|
|
1744
|
+
var CURSOR_HOOKS_FILE = "hooks.json";
|
|
1745
|
+
function getCursorUserDir(homeDir = os4.homedir()) {
|
|
1746
|
+
return path11.join(homeDir, CURSOR_DIR_NAME);
|
|
1747
|
+
}
|
|
1748
|
+
function getCursorHooksPath(homeDir = os4.homedir()) {
|
|
1749
|
+
return path11.join(getCursorUserDir(homeDir), CURSOR_HOOKS_FILE);
|
|
1750
|
+
}
|
|
1751
|
+
|
|
1752
|
+
// src/monitor/plugins/cursor/hooks-config.ts
|
|
1753
|
+
var OLAKAI_HOOK_MARKER3 = "olakai monitor hook --tool cursor";
|
|
1754
|
+
var CURSOR_HOOK_DEFINITIONS = {
|
|
1755
|
+
beforeSubmitPrompt: [
|
|
1756
|
+
{
|
|
1757
|
+
command: "olakai monitor hook --tool cursor beforeSubmitPrompt",
|
|
1758
|
+
timeout: 5
|
|
1759
|
+
}
|
|
1760
|
+
],
|
|
1761
|
+
afterAgentResponse: [
|
|
1762
|
+
{
|
|
1763
|
+
command: "olakai monitor hook --tool cursor afterAgentResponse",
|
|
1764
|
+
timeout: 5
|
|
1765
|
+
}
|
|
1766
|
+
],
|
|
1767
|
+
sessionEnd: [
|
|
1768
|
+
{
|
|
1769
|
+
command: "olakai monitor hook --tool cursor sessionEnd",
|
|
1770
|
+
timeout: 5
|
|
1771
|
+
}
|
|
1772
|
+
],
|
|
1773
|
+
stop: [
|
|
1774
|
+
{
|
|
1775
|
+
command: "olakai monitor hook --tool cursor stop",
|
|
1776
|
+
timeout: 5
|
|
1777
|
+
}
|
|
1778
|
+
]
|
|
1779
|
+
};
|
|
1780
|
+
var CURSOR_HOOKS_VERSION = 1;
|
|
1781
|
+
function mergeCursorHooks(existing, definitions = CURSOR_HOOK_DEFINITIONS) {
|
|
1782
|
+
const base = existing ? { ...existing } : {};
|
|
1783
|
+
if (typeof base.version !== "number") {
|
|
1784
|
+
base.version = CURSOR_HOOKS_VERSION;
|
|
1785
|
+
}
|
|
1786
|
+
const mergedHooks = {
|
|
1787
|
+
...base.hooks ?? {}
|
|
1788
|
+
};
|
|
1789
|
+
for (const [event, defaultEntries] of Object.entries(definitions)) {
|
|
1790
|
+
const existingEntries = mergedHooks[event] ?? [];
|
|
1791
|
+
const hasOlakaiEntry = existingEntries.some(
|
|
1792
|
+
(e) => typeof e?.command === "string" && e.command.includes(OLAKAI_HOOK_MARKER3)
|
|
1793
|
+
);
|
|
1794
|
+
if (hasOlakaiEntry) {
|
|
1795
|
+
mergedHooks[event] = existingEntries;
|
|
1796
|
+
} else {
|
|
1797
|
+
mergedHooks[event] = [...existingEntries, ...defaultEntries];
|
|
1798
|
+
}
|
|
1799
|
+
}
|
|
1800
|
+
return {
|
|
1801
|
+
...base,
|
|
1802
|
+
hooks: mergedHooks
|
|
1803
|
+
};
|
|
1804
|
+
}
|
|
1805
|
+
function removeOlakaiCursorHooks(existing) {
|
|
1806
|
+
const base = existing ? { ...existing } : {};
|
|
1807
|
+
const sourceHooks = base.hooks ?? {};
|
|
1808
|
+
const cleaned = {};
|
|
1809
|
+
for (const [event, entries] of Object.entries(sourceHooks)) {
|
|
1810
|
+
const filtered = entries.filter(
|
|
1811
|
+
(e) => typeof e?.command !== "string" || !e.command.includes(OLAKAI_HOOK_MARKER3)
|
|
1812
|
+
);
|
|
1813
|
+
if (filtered.length > 0) {
|
|
1814
|
+
cleaned[event] = filtered;
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1817
|
+
if (Object.keys(cleaned).length > 0) {
|
|
1818
|
+
base.hooks = cleaned;
|
|
1819
|
+
} else {
|
|
1820
|
+
delete base.hooks;
|
|
1821
|
+
}
|
|
1822
|
+
return base;
|
|
1823
|
+
}
|
|
1824
|
+
function hasOlakaiCursorHooks(config) {
|
|
1825
|
+
if (!config?.hooks) return false;
|
|
1826
|
+
return Object.values(config.hooks).some(
|
|
1827
|
+
(entries) => entries.some(
|
|
1828
|
+
(e) => typeof e?.command === "string" && e.command.includes(OLAKAI_HOOK_MARKER3)
|
|
1829
|
+
)
|
|
1830
|
+
);
|
|
1831
|
+
}
|
|
1832
|
+
|
|
1833
|
+
// src/monitor/plugins/cursor/install.ts
|
|
1834
|
+
var CURSOR_SOURCE = "cursor";
|
|
1835
|
+
var CURSOR_AGENT_SOURCE = "CURSOR";
|
|
1836
|
+
var CURSOR_AGENT_CATEGORY = "CODING";
|
|
1837
|
+
function readJsonFileTolerant(filePath) {
|
|
1838
|
+
try {
|
|
1839
|
+
if (!fs12.existsSync(filePath)) return null;
|
|
1840
|
+
const raw = fs12.readFileSync(filePath, "utf-8");
|
|
1841
|
+
return JSON.parse(raw);
|
|
1842
|
+
} catch {
|
|
1843
|
+
return null;
|
|
1844
|
+
}
|
|
1845
|
+
}
|
|
1846
|
+
function writeJsonFileWithDir(filePath, data) {
|
|
1847
|
+
const dir = path12.dirname(filePath);
|
|
1848
|
+
if (!fs12.existsSync(dir)) {
|
|
1849
|
+
fs12.mkdirSync(dir, { recursive: true });
|
|
1850
|
+
}
|
|
1851
|
+
fs12.writeFileSync(filePath, JSON.stringify(data, null, 2) + "\n", "utf-8");
|
|
1852
|
+
}
|
|
1853
|
+
async function installCursor(opts) {
|
|
1854
|
+
const projectRoot = opts.projectRoot ?? process.cwd();
|
|
1855
|
+
const homeDir = opts.homeDir ?? os5.homedir();
|
|
1856
|
+
const token = getValidToken();
|
|
1857
|
+
if (!token) {
|
|
1858
|
+
console.error("Not logged in. Run 'olakai login' first.");
|
|
1859
|
+
process.exit(1);
|
|
1860
|
+
}
|
|
1861
|
+
console.log("Setting up Cursor monitoring for this workspace...\n");
|
|
1862
|
+
console.log(
|
|
1863
|
+
"Note: Cursor hooks are installed globally per user (~/.cursor/hooks.json)."
|
|
1864
|
+
);
|
|
1865
|
+
console.log(
|
|
1866
|
+
`Activity from this workspace (${projectRoot}) will be associated with`
|
|
1867
|
+
);
|
|
1868
|
+
console.log("the agent you select below.\n");
|
|
1869
|
+
const agent = await provisionSelfMonitorAgent({
|
|
1870
|
+
projectRoot,
|
|
1871
|
+
source: CURSOR_AGENT_SOURCE,
|
|
1872
|
+
displayName: "Cursor",
|
|
1873
|
+
category: CURSOR_AGENT_CATEGORY
|
|
1874
|
+
});
|
|
1875
|
+
const monitoringEndpoint = `${getBaseUrl()}/api/monitoring/prompt`;
|
|
1876
|
+
const apiKey = agent.apiKey?.key;
|
|
1877
|
+
if (!apiKey) {
|
|
1878
|
+
console.error(
|
|
1879
|
+
"Internal error: agent provisioned but no API key returned. Please re-run 'olakai monitor init'."
|
|
1880
|
+
);
|
|
1881
|
+
process.exit(1);
|
|
1882
|
+
}
|
|
1883
|
+
const cursorDir = getCursorUserDir(homeDir);
|
|
1884
|
+
if (!fs12.existsSync(cursorDir)) {
|
|
1885
|
+
fs12.mkdirSync(cursorDir, { recursive: true });
|
|
1886
|
+
}
|
|
1887
|
+
const hooksPath = getCursorHooksPath(homeDir);
|
|
1888
|
+
const existingHooks = readJsonFileTolerant(hooksPath);
|
|
1889
|
+
const mergedHooks = mergeCursorHooks(existingHooks);
|
|
1890
|
+
writeJsonFileWithDir(hooksPath, mergedHooks);
|
|
1891
|
+
const monitorConfig = {
|
|
1892
|
+
agentId: agent.id,
|
|
1893
|
+
apiKey,
|
|
1894
|
+
agentName: agent.name,
|
|
1895
|
+
source: CURSOR_SOURCE,
|
|
1896
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1897
|
+
monitoringEndpoint
|
|
1898
|
+
};
|
|
1899
|
+
writeCursorConfig(projectRoot, monitorConfig);
|
|
1900
|
+
const configPath = getCursorConfigPath(projectRoot);
|
|
1901
|
+
const configRel = path12.relative(projectRoot, configPath);
|
|
1902
|
+
const hooksDisplay = `~/${path12.join(CURSOR_DIR_NAME, CURSOR_HOOKS_FILE)}`;
|
|
1903
|
+
console.log("");
|
|
1904
|
+
console.log(`\u2713 Agent "${agent.name}" configured (ID: ${agent.id})`);
|
|
1905
|
+
if (agent.apiKey?.key) {
|
|
1906
|
+
console.log("\u2713 API key generated");
|
|
1907
|
+
}
|
|
1908
|
+
console.log(`\u2713 Cursor hooks installed at ${hooksDisplay}`);
|
|
1909
|
+
console.log(`\u2713 Monitor config saved to ${configRel}`);
|
|
1910
|
+
console.log("");
|
|
1911
|
+
console.log(
|
|
1912
|
+
"Congrats! Monitoring is now active. Restart Cursor for the new hooks to take effect."
|
|
1913
|
+
);
|
|
1914
|
+
console.log("");
|
|
1915
|
+
console.log(
|
|
1916
|
+
`\u26A0 Ensure ${OLAKAI_DIR}/ is in your .gitignore (it contains your API key)`
|
|
1917
|
+
);
|
|
1918
|
+
console.log("");
|
|
1919
|
+
console.log("To check status: olakai monitor status --tool cursor");
|
|
1920
|
+
console.log("To disable: olakai monitor disable --tool cursor");
|
|
1921
|
+
return {
|
|
1922
|
+
agentId: agent.id,
|
|
1923
|
+
agentName: agent.name,
|
|
1924
|
+
source: CURSOR_SOURCE,
|
|
1925
|
+
monitoringEndpoint
|
|
1926
|
+
};
|
|
1927
|
+
}
|
|
1928
|
+
async function uninstallCursor(opts) {
|
|
1929
|
+
const projectRoot = opts.projectRoot ?? process.cwd();
|
|
1930
|
+
const homeDir = opts.homeDir ?? os5.homedir();
|
|
1931
|
+
const hooksPath = getCursorHooksPath(homeDir);
|
|
1932
|
+
const existingHooks = readJsonFileTolerant(hooksPath);
|
|
1933
|
+
if (existingHooks) {
|
|
1934
|
+
const cleaned = removeOlakaiCursorHooks(existingHooks);
|
|
1935
|
+
if (!cleaned.hooks || Object.keys(cleaned.hooks).length === 0) {
|
|
1936
|
+
const otherKeys = Object.keys(cleaned).filter(
|
|
1937
|
+
(k) => k !== "hooks" && k !== "version"
|
|
1938
|
+
);
|
|
1939
|
+
const onlyDefaults = otherKeys.length === 0 && (cleaned.version === 1 || cleaned.version === void 0);
|
|
1940
|
+
if (onlyDefaults) {
|
|
1941
|
+
try {
|
|
1942
|
+
fs12.unlinkSync(hooksPath);
|
|
1943
|
+
} catch {
|
|
1944
|
+
}
|
|
1945
|
+
} else {
|
|
1946
|
+
writeJsonFileWithDir(hooksPath, cleaned);
|
|
1947
|
+
}
|
|
1948
|
+
} else {
|
|
1949
|
+
writeJsonFileWithDir(hooksPath, cleaned);
|
|
1950
|
+
}
|
|
1951
|
+
console.log(
|
|
1952
|
+
`\u2713 Olakai hooks removed from ~/${path12.join(CURSOR_DIR_NAME, CURSOR_HOOKS_FILE)}`
|
|
1953
|
+
);
|
|
1954
|
+
} else {
|
|
1955
|
+
console.log("No Cursor hooks file found.");
|
|
1956
|
+
}
|
|
1957
|
+
if (!opts.keepConfig) {
|
|
1958
|
+
const configPath = getCursorConfigPath(projectRoot);
|
|
1959
|
+
const configRel = path12.relative(projectRoot, configPath);
|
|
1960
|
+
if (deleteCursorConfig(projectRoot)) {
|
|
1961
|
+
console.log(`\u2713 Monitor config removed (${configRel})`);
|
|
1962
|
+
}
|
|
1963
|
+
} else {
|
|
1964
|
+
const configPath = getCursorConfigPath(projectRoot);
|
|
1965
|
+
const configRel = path12.relative(projectRoot, configPath);
|
|
1966
|
+
console.log(`Monitor config retained at ${configRel}`);
|
|
1967
|
+
}
|
|
1968
|
+
console.log("");
|
|
1969
|
+
console.log(
|
|
1970
|
+
"Monitoring disabled. Run 'olakai monitor init --tool cursor' to re-enable."
|
|
1971
|
+
);
|
|
1972
|
+
console.log("Restart Cursor for the change to take effect.");
|
|
1973
|
+
}
|
|
1974
|
+
|
|
1975
|
+
// src/monitor/plugins/cursor/status.ts
|
|
1976
|
+
import * as fs13 from "fs";
|
|
1977
|
+
import * as os6 from "os";
|
|
1978
|
+
import * as path13 from "path";
|
|
1979
|
+
async function getCursorStatus(opts) {
|
|
1980
|
+
const projectRoot = opts?.projectRoot ?? process.cwd();
|
|
1981
|
+
const homeDir = opts?.homeDir ?? os6.homedir();
|
|
1982
|
+
const configPath = getCursorConfigPath(projectRoot);
|
|
1983
|
+
const config = loadCursorConfig(projectRoot);
|
|
1984
|
+
let hooksConfigured = false;
|
|
1985
|
+
const hooksPath = getCursorHooksPath(homeDir);
|
|
1986
|
+
if (fs13.existsSync(hooksPath)) {
|
|
1987
|
+
try {
|
|
1988
|
+
const raw = fs13.readFileSync(hooksPath, "utf-8");
|
|
1989
|
+
const parsed = JSON.parse(raw);
|
|
1990
|
+
hooksConfigured = hasOlakaiCursorHooks(parsed);
|
|
1991
|
+
} catch {
|
|
1992
|
+
}
|
|
1993
|
+
}
|
|
1994
|
+
if (!config) {
|
|
1995
|
+
return {
|
|
1996
|
+
toolId: "cursor",
|
|
1997
|
+
configured: false,
|
|
1998
|
+
hooksConfigured,
|
|
1999
|
+
configPath,
|
|
2000
|
+
notes: hooksConfigured ? [
|
|
2001
|
+
"Cursor hooks installed but no monitor config in this workspace \u2014 run 'olakai monitor init --tool cursor' to associate it with an agent."
|
|
2002
|
+
] : []
|
|
2003
|
+
};
|
|
2004
|
+
}
|
|
2005
|
+
return {
|
|
2006
|
+
toolId: "cursor",
|
|
2007
|
+
configured: true,
|
|
2008
|
+
hooksConfigured,
|
|
2009
|
+
agentId: config.agentId,
|
|
2010
|
+
agentName: config.agentName,
|
|
2011
|
+
source: config.source,
|
|
2012
|
+
apiKeyMasked: config.apiKey.slice(0, 12) + "...",
|
|
2013
|
+
monitoringEndpoint: config.monitoringEndpoint,
|
|
2014
|
+
configuredAt: config.createdAt,
|
|
2015
|
+
configPath
|
|
2016
|
+
};
|
|
2017
|
+
}
|
|
2018
|
+
|
|
2019
|
+
// src/monitor/plugins/cursor/hook.ts
|
|
2020
|
+
var SUPPORTED_CURSOR_EVENTS = /* @__PURE__ */ new Set([
|
|
2021
|
+
"beforeSubmitPrompt",
|
|
2022
|
+
"afterAgentResponse",
|
|
2023
|
+
"sessionEnd",
|
|
2024
|
+
"stop"
|
|
2025
|
+
]);
|
|
2026
|
+
function asString(value) {
|
|
2027
|
+
return typeof value === "string" && value.trim() ? value : void 0;
|
|
2028
|
+
}
|
|
2029
|
+
function asNumber(value) {
|
|
2030
|
+
if (typeof value !== "number") return 0;
|
|
2031
|
+
if (!Number.isFinite(value)) return 0;
|
|
2032
|
+
return value;
|
|
2033
|
+
}
|
|
2034
|
+
function extractCursorTokens(payload) {
|
|
2035
|
+
return {
|
|
2036
|
+
inputTokens: asNumber(payload.input_tokens),
|
|
2037
|
+
outputTokens: asNumber(payload.output_tokens),
|
|
2038
|
+
cacheReadTokens: asNumber(payload.cache_read_tokens),
|
|
2039
|
+
cacheWriteTokens: asNumber(payload.cache_write_tokens)
|
|
2040
|
+
};
|
|
2041
|
+
}
|
|
2042
|
+
function asStringArray(value) {
|
|
2043
|
+
if (!Array.isArray(value)) return void 0;
|
|
2044
|
+
const out = [];
|
|
2045
|
+
for (const item of value) {
|
|
2046
|
+
if (typeof item === "string" && item.trim()) out.push(item);
|
|
2047
|
+
}
|
|
2048
|
+
return out.length > 0 ? out : void 0;
|
|
2049
|
+
}
|
|
2050
|
+
function extractPromptText(payload) {
|
|
2051
|
+
if (typeof payload.prompt === "string") return payload.prompt;
|
|
2052
|
+
if (payload.prompt && typeof payload.prompt === "object" && typeof payload.prompt.text === "string") {
|
|
2053
|
+
return payload.prompt.text;
|
|
2054
|
+
}
|
|
2055
|
+
return "";
|
|
2056
|
+
}
|
|
2057
|
+
function extractResponseText(payload) {
|
|
2058
|
+
if (typeof payload.response === "string") return payload.response;
|
|
2059
|
+
if (payload.response && typeof payload.response === "object" && typeof payload.response.text === "string") {
|
|
2060
|
+
return payload.response.text;
|
|
2061
|
+
}
|
|
2062
|
+
if (typeof payload.text === "string") return payload.text;
|
|
2063
|
+
return "";
|
|
2064
|
+
}
|
|
2065
|
+
function extractAttachments(payload) {
|
|
2066
|
+
if (Array.isArray(payload.attachments)) return payload.attachments;
|
|
2067
|
+
if (payload.prompt && typeof payload.prompt === "object" && Array.isArray(payload.prompt.attachments)) {
|
|
2068
|
+
return payload.prompt.attachments;
|
|
2069
|
+
}
|
|
2070
|
+
return void 0;
|
|
2071
|
+
}
|
|
2072
|
+
function buildPairedPayload(inputs, config) {
|
|
2073
|
+
const customData = {
|
|
2074
|
+
hookEvent: "afterAgentResponse",
|
|
2075
|
+
conversationId: inputs.conversationId
|
|
2076
|
+
};
|
|
2077
|
+
if (inputs.generationId) customData.generationId = inputs.generationId;
|
|
2078
|
+
if (inputs.cursorVersion) customData.cursorVersion = inputs.cursorVersion;
|
|
2079
|
+
if (inputs.workspaceRoots) customData.workspaceRoots = inputs.workspaceRoots;
|
|
2080
|
+
if (inputs.transcriptPath) customData.transcriptPath = inputs.transcriptPath;
|
|
2081
|
+
if (inputs.attachments && inputs.attachments.length > 0) {
|
|
2082
|
+
customData.attachmentCount = inputs.attachments.length;
|
|
2083
|
+
}
|
|
2084
|
+
if (inputs.userEmail) customData.userEmail = inputs.userEmail;
|
|
2085
|
+
const inputTokens = asNumber(inputs.inputTokens);
|
|
2086
|
+
const outputTokens = asNumber(inputs.outputTokens);
|
|
2087
|
+
const cacheReadTokens = asNumber(inputs.cacheReadTokens);
|
|
2088
|
+
const cacheWriteTokens = asNumber(inputs.cacheWriteTokens);
|
|
2089
|
+
customData.inputTokens = inputTokens;
|
|
2090
|
+
customData.outputTokens = outputTokens;
|
|
2091
|
+
customData.cacheReadTokens = cacheReadTokens;
|
|
2092
|
+
customData.cacheWriteTokens = cacheWriteTokens;
|
|
2093
|
+
if (inputs.unknownFields && Object.keys(inputs.unknownFields).length > 0) {
|
|
2094
|
+
customData.unknownPayloadFields = inputs.unknownFields;
|
|
2095
|
+
}
|
|
2096
|
+
return {
|
|
2097
|
+
prompt: inputs.prompt,
|
|
2098
|
+
response: inputs.response,
|
|
2099
|
+
chatId: inputs.conversationId,
|
|
2100
|
+
source: config.source,
|
|
2101
|
+
modelName: inputs.model,
|
|
2102
|
+
tokens: inputTokens + outputTokens,
|
|
2103
|
+
customData
|
|
2104
|
+
};
|
|
2105
|
+
}
|
|
2106
|
+
function buildOrphanPayload(inputs, config, reason = "orphan-prompt") {
|
|
2107
|
+
const base = buildPairedPayload({ ...inputs, response: "" }, config);
|
|
2108
|
+
return {
|
|
2109
|
+
...base,
|
|
2110
|
+
customData: {
|
|
2111
|
+
...base.customData,
|
|
2112
|
+
hookEvent: "sessionEnd",
|
|
2113
|
+
partial: true,
|
|
2114
|
+
partialReason: reason
|
|
2115
|
+
}
|
|
2116
|
+
};
|
|
2117
|
+
}
|
|
2118
|
+
var KNOWN_PAYLOAD_KEYS = /* @__PURE__ */ new Set([
|
|
2119
|
+
"event",
|
|
2120
|
+
"conversation_id",
|
|
2121
|
+
"generation_id",
|
|
2122
|
+
"model",
|
|
2123
|
+
"cursor_version",
|
|
2124
|
+
"workspace_roots",
|
|
2125
|
+
"user_email",
|
|
2126
|
+
"transcript_path",
|
|
2127
|
+
"prompt",
|
|
2128
|
+
"response",
|
|
2129
|
+
"text",
|
|
2130
|
+
"attachments",
|
|
2131
|
+
"input_tokens",
|
|
2132
|
+
"output_tokens",
|
|
2133
|
+
"cache_read_tokens",
|
|
2134
|
+
"cache_write_tokens"
|
|
2135
|
+
]);
|
|
2136
|
+
function collectUnknownFields(payload) {
|
|
2137
|
+
const out = {};
|
|
2138
|
+
for (const key of Object.keys(payload)) {
|
|
2139
|
+
if (!KNOWN_PAYLOAD_KEYS.has(key)) {
|
|
2140
|
+
out[key] = payload[key];
|
|
2141
|
+
}
|
|
2142
|
+
}
|
|
2143
|
+
return Object.keys(out).length > 0 ? out : void 0;
|
|
2144
|
+
}
|
|
2145
|
+
function normalizeEventName(event) {
|
|
2146
|
+
const lower = event.trim();
|
|
2147
|
+
if (!lower) return null;
|
|
2148
|
+
const exact = lower;
|
|
2149
|
+
if (SUPPORTED_CURSOR_EVENTS.has(exact)) return exact;
|
|
2150
|
+
for (const known of SUPPORTED_CURSOR_EVENTS) {
|
|
2151
|
+
if (known.toLowerCase() === lower.toLowerCase()) return known;
|
|
2152
|
+
}
|
|
2153
|
+
return null;
|
|
2154
|
+
}
|
|
2155
|
+
function extractCursorMeta(payload) {
|
|
2156
|
+
return {
|
|
2157
|
+
conversationId: asString(payload.conversation_id),
|
|
2158
|
+
generationId: asString(payload.generation_id),
|
|
2159
|
+
model: asString(payload.model),
|
|
2160
|
+
cursorVersion: asString(payload.cursor_version),
|
|
2161
|
+
workspaceRoots: asStringArray(payload.workspace_roots),
|
|
2162
|
+
userEmail: asString(payload.user_email),
|
|
2163
|
+
transcriptPath: asString(payload.transcript_path)
|
|
2164
|
+
};
|
|
2165
|
+
}
|
|
2166
|
+
|
|
2167
|
+
// src/monitor/plugins/cursor/pairing-state.ts
|
|
2168
|
+
import * as fs14 from "fs";
|
|
2169
|
+
import * as os7 from "os";
|
|
2170
|
+
import * as path14 from "path";
|
|
2171
|
+
var STATE_DIR_SEGMENTS2 = [".olakai", "cursor-pairings"];
|
|
2172
|
+
function getPairingsDir(homeDir) {
|
|
2173
|
+
return path14.join(homeDir, ...STATE_DIR_SEGMENTS2);
|
|
2174
|
+
}
|
|
2175
|
+
function sanitizeKeyFragment(value) {
|
|
2176
|
+
return value.replace(/[^A-Za-z0-9._-]/g, "_");
|
|
2177
|
+
}
|
|
2178
|
+
function getPairingKey(conversationId, generationId) {
|
|
2179
|
+
const conv = sanitizeKeyFragment(conversationId);
|
|
2180
|
+
if (!generationId) return conv;
|
|
2181
|
+
return `${conv}__${sanitizeKeyFragment(generationId)}`;
|
|
2182
|
+
}
|
|
2183
|
+
function getPairingFile(conversationId, generationId, homeDir) {
|
|
2184
|
+
return path14.join(
|
|
2185
|
+
getPairingsDir(homeDir),
|
|
2186
|
+
`${getPairingKey(conversationId, generationId)}.json`
|
|
2187
|
+
);
|
|
2188
|
+
}
|
|
2189
|
+
function stashPendingPrompt(pending, homeDir = os7.homedir()) {
|
|
2190
|
+
if (!pending.conversationId) return;
|
|
2191
|
+
const dir = getPairingsDir(homeDir);
|
|
2192
|
+
try {
|
|
2193
|
+
if (!fs14.existsSync(dir)) {
|
|
2194
|
+
fs14.mkdirSync(dir, { recursive: true });
|
|
2195
|
+
}
|
|
2196
|
+
const filePath = getPairingFile(
|
|
2197
|
+
pending.conversationId,
|
|
2198
|
+
pending.generationId,
|
|
2199
|
+
homeDir
|
|
2200
|
+
);
|
|
2201
|
+
fs14.writeFileSync(
|
|
2202
|
+
filePath,
|
|
2203
|
+
JSON.stringify(pending, null, 2) + "\n",
|
|
2204
|
+
"utf-8"
|
|
2205
|
+
);
|
|
2206
|
+
} catch {
|
|
2207
|
+
}
|
|
2208
|
+
}
|
|
2209
|
+
function takePendingPrompt(conversationId, generationId, homeDir = os7.homedir()) {
|
|
2210
|
+
if (!conversationId) return null;
|
|
2211
|
+
const candidates = [];
|
|
2212
|
+
if (generationId) {
|
|
2213
|
+
candidates.push(getPairingFile(conversationId, generationId, homeDir));
|
|
2214
|
+
}
|
|
2215
|
+
candidates.push(getPairingFile(conversationId, void 0, homeDir));
|
|
2216
|
+
for (const filePath of candidates) {
|
|
2217
|
+
let raw;
|
|
2218
|
+
try {
|
|
2219
|
+
if (!fs14.existsSync(filePath)) continue;
|
|
2220
|
+
raw = fs14.readFileSync(filePath, "utf-8");
|
|
2221
|
+
} catch {
|
|
2222
|
+
continue;
|
|
2223
|
+
}
|
|
2224
|
+
try {
|
|
2225
|
+
fs14.unlinkSync(filePath);
|
|
2226
|
+
} catch {
|
|
2227
|
+
}
|
|
2228
|
+
try {
|
|
2229
|
+
const parsed = JSON.parse(raw);
|
|
2230
|
+
if (parsed && typeof parsed.conversationId === "string") {
|
|
2231
|
+
return parsed;
|
|
2232
|
+
}
|
|
2233
|
+
} catch {
|
|
2234
|
+
}
|
|
2235
|
+
}
|
|
2236
|
+
return null;
|
|
2237
|
+
}
|
|
2238
|
+
function listPendingPrompts(homeDir = os7.homedir()) {
|
|
2239
|
+
const dir = getPairingsDir(homeDir);
|
|
2240
|
+
if (!fs14.existsSync(dir)) return [];
|
|
2241
|
+
let files;
|
|
2242
|
+
try {
|
|
2243
|
+
files = fs14.readdirSync(dir);
|
|
2244
|
+
} catch {
|
|
2245
|
+
return [];
|
|
2246
|
+
}
|
|
2247
|
+
const result = [];
|
|
2248
|
+
for (const name of files) {
|
|
2249
|
+
if (!name.endsWith(".json")) continue;
|
|
2250
|
+
const filePath = path14.join(dir, name);
|
|
2251
|
+
try {
|
|
2252
|
+
const raw = fs14.readFileSync(filePath, "utf-8");
|
|
2253
|
+
const parsed = JSON.parse(raw);
|
|
2254
|
+
if (parsed && typeof parsed.conversationId === "string") {
|
|
2255
|
+
result.push(parsed);
|
|
2256
|
+
}
|
|
2257
|
+
} catch {
|
|
2258
|
+
}
|
|
2259
|
+
}
|
|
2260
|
+
return result;
|
|
2261
|
+
}
|
|
2262
|
+
function clearPendingPrompt(conversationId, generationId, homeDir = os7.homedir()) {
|
|
2263
|
+
if (!conversationId) return;
|
|
2264
|
+
const candidates = [];
|
|
2265
|
+
if (generationId) {
|
|
2266
|
+
candidates.push(getPairingFile(conversationId, generationId, homeDir));
|
|
2267
|
+
}
|
|
2268
|
+
candidates.push(getPairingFile(conversationId, void 0, homeDir));
|
|
2269
|
+
for (const filePath of candidates) {
|
|
2270
|
+
try {
|
|
2271
|
+
if (fs14.existsSync(filePath)) {
|
|
2272
|
+
fs14.unlinkSync(filePath);
|
|
2273
|
+
}
|
|
2274
|
+
} catch {
|
|
2275
|
+
}
|
|
2276
|
+
}
|
|
2277
|
+
}
|
|
2278
|
+
|
|
2279
|
+
// src/monitor/plugins/cursor/index.ts
|
|
2280
|
+
var TOOL_ID3 = "cursor";
|
|
2281
|
+
function debugLog3(label, data) {
|
|
2282
|
+
if (process.env.OLAKAI_MONITOR_DEBUG !== "1") return;
|
|
2283
|
+
try {
|
|
2284
|
+
const logPath = `/tmp/olakai-monitor-debug-${process.pid}.log`;
|
|
2285
|
+
const line = `[${(/* @__PURE__ */ new Date()).toISOString()}] cursor:${label}: ${typeof data === "string" ? data : JSON.stringify(data, null, 2)}
|
|
2286
|
+
`;
|
|
2287
|
+
fs15.appendFileSync(logPath, line, "utf-8");
|
|
2288
|
+
} catch {
|
|
2289
|
+
}
|
|
2290
|
+
}
|
|
2291
|
+
function resolveCursorProjectRoot(payload, fallbackCwd = process.cwd()) {
|
|
2292
|
+
const roots = Array.isArray(payload.workspace_roots) ? payload.workspace_roots.filter(
|
|
2293
|
+
(r) => typeof r === "string" && r.trim().length > 0
|
|
2294
|
+
) : [];
|
|
2295
|
+
const candidates = roots.length > 0 ? roots : [fallbackCwd];
|
|
2296
|
+
for (const candidate of candidates) {
|
|
2297
|
+
const found = findConfiguredWorkspace(candidate, [TOOL_ID3]);
|
|
2298
|
+
if (found) return found;
|
|
2299
|
+
}
|
|
2300
|
+
return null;
|
|
2301
|
+
}
|
|
2302
|
+
async function handleCursorHook(eventName, payloadJson, opts = {}) {
|
|
2303
|
+
const event = normalizeEventName(eventName);
|
|
2304
|
+
if (!event) {
|
|
2305
|
+
debugLog3("hook-unknown-event", eventName);
|
|
2306
|
+
return null;
|
|
2307
|
+
}
|
|
2308
|
+
const payload = payloadJson && typeof payloadJson === "object" ? payloadJson : {};
|
|
2309
|
+
debugLog3("event-parsed", { event, payload });
|
|
2310
|
+
const meta = extractCursorMeta(payload);
|
|
2311
|
+
const homeDir = opts.homeDir ?? os8.homedir();
|
|
2312
|
+
switch (event) {
|
|
2313
|
+
case "beforeSubmitPrompt": {
|
|
2314
|
+
if (!meta.conversationId) {
|
|
2315
|
+
debugLog3("missing-conversation-id", { event });
|
|
2316
|
+
return null;
|
|
2317
|
+
}
|
|
2318
|
+
stashPendingPrompt(
|
|
2319
|
+
{
|
|
2320
|
+
prompt: extractPromptText(payload),
|
|
2321
|
+
userEmail: meta.userEmail,
|
|
2322
|
+
model: meta.model,
|
|
2323
|
+
cursorVersion: meta.cursorVersion,
|
|
2324
|
+
conversationId: meta.conversationId,
|
|
2325
|
+
generationId: meta.generationId,
|
|
2326
|
+
workspaceRoots: meta.workspaceRoots,
|
|
2327
|
+
transcriptPath: meta.transcriptPath,
|
|
2328
|
+
attachments: extractAttachments(payload),
|
|
2329
|
+
stashedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2330
|
+
extra: collectUnknownFields(payload)
|
|
2331
|
+
},
|
|
2332
|
+
homeDir
|
|
2333
|
+
);
|
|
2334
|
+
return null;
|
|
2335
|
+
}
|
|
2336
|
+
case "afterAgentResponse": {
|
|
2337
|
+
if (!meta.conversationId) {
|
|
2338
|
+
debugLog3("missing-conversation-id", { event });
|
|
2339
|
+
return null;
|
|
2340
|
+
}
|
|
2341
|
+
const projectRoot = resolveCursorProjectRoot(
|
|
2342
|
+
payload,
|
|
2343
|
+
opts.projectRoot ?? process.cwd()
|
|
2344
|
+
);
|
|
2345
|
+
if (!projectRoot) {
|
|
2346
|
+
debugLog3("config-not-found", {
|
|
2347
|
+
workspaceRoots: meta.workspaceRoots,
|
|
2348
|
+
fallbackCwd: opts.projectRoot ?? process.cwd()
|
|
2349
|
+
});
|
|
2350
|
+
takePendingPrompt(meta.conversationId, meta.generationId, homeDir);
|
|
2351
|
+
return null;
|
|
2352
|
+
}
|
|
2353
|
+
const config = loadCursorConfig(projectRoot);
|
|
2354
|
+
if (!config) {
|
|
2355
|
+
debugLog3("config-load-failed", { projectRoot });
|
|
2356
|
+
takePendingPrompt(meta.conversationId, meta.generationId, homeDir);
|
|
2357
|
+
return null;
|
|
2358
|
+
}
|
|
2359
|
+
const stashed = takePendingPrompt(
|
|
2360
|
+
meta.conversationId,
|
|
2361
|
+
meta.generationId,
|
|
2362
|
+
homeDir
|
|
2363
|
+
);
|
|
2364
|
+
const responseText = extractResponseText(payload);
|
|
2365
|
+
const promptText = stashed?.prompt ?? extractPromptText(payload);
|
|
2366
|
+
const userEmail = meta.userEmail ?? stashed?.userEmail;
|
|
2367
|
+
const model = meta.model ?? stashed?.model;
|
|
2368
|
+
const cursorVersion = meta.cursorVersion ?? stashed?.cursorVersion;
|
|
2369
|
+
const workspaceRoots = meta.workspaceRoots ?? stashed?.workspaceRoots;
|
|
2370
|
+
const transcriptPath = meta.transcriptPath ?? stashed?.transcriptPath;
|
|
2371
|
+
const attachments = extractAttachments(payload) ?? stashed?.attachments;
|
|
2372
|
+
const tokens = extractCursorTokens(payload);
|
|
2373
|
+
const unknownFields = mergeUnknownFields(
|
|
2374
|
+
collectUnknownFields(payload),
|
|
2375
|
+
stashed?.extra
|
|
2376
|
+
);
|
|
2377
|
+
const built = buildPairedPayload(
|
|
2378
|
+
{
|
|
2379
|
+
conversationId: meta.conversationId,
|
|
2380
|
+
generationId: meta.generationId ?? stashed?.generationId,
|
|
2381
|
+
prompt: promptText,
|
|
2382
|
+
response: responseText,
|
|
2383
|
+
userEmail,
|
|
2384
|
+
model,
|
|
2385
|
+
cursorVersion,
|
|
2386
|
+
workspaceRoots,
|
|
2387
|
+
transcriptPath,
|
|
2388
|
+
attachments,
|
|
2389
|
+
inputTokens: tokens.inputTokens,
|
|
2390
|
+
outputTokens: tokens.outputTokens,
|
|
2391
|
+
cacheReadTokens: tokens.cacheReadTokens,
|
|
2392
|
+
cacheWriteTokens: tokens.cacheWriteTokens,
|
|
2393
|
+
unknownFields
|
|
2394
|
+
},
|
|
2395
|
+
config
|
|
2396
|
+
);
|
|
2397
|
+
const finalPayload = userEmail ? { ...built, email: userEmail } : built;
|
|
2398
|
+
debugLog3("payload-built", finalPayload);
|
|
2399
|
+
return {
|
|
2400
|
+
payload: finalPayload,
|
|
2401
|
+
transport: {
|
|
2402
|
+
endpoint: config.monitoringEndpoint,
|
|
2403
|
+
apiKey: config.apiKey,
|
|
2404
|
+
projectRoot
|
|
2405
|
+
}
|
|
2406
|
+
};
|
|
2407
|
+
}
|
|
2408
|
+
case "sessionEnd":
|
|
2409
|
+
case "stop": {
|
|
2410
|
+
const orphan = pickOrphanForFlush(meta.conversationId, homeDir);
|
|
2411
|
+
if (!orphan) return null;
|
|
2412
|
+
const projectRoot = resolveCursorProjectRoot(
|
|
2413
|
+
// Synthesize a payload-like for resolution — orphan carries
|
|
2414
|
+
// the workspace_roots from the stashed beforeSubmitPrompt.
|
|
2415
|
+
{
|
|
2416
|
+
workspace_roots: orphan.workspaceRoots
|
|
2417
|
+
},
|
|
2418
|
+
opts.projectRoot ?? process.cwd()
|
|
2419
|
+
);
|
|
2420
|
+
if (!projectRoot) {
|
|
2421
|
+
debugLog3("orphan-config-not-found", {
|
|
2422
|
+
conversationId: orphan.conversationId
|
|
2423
|
+
});
|
|
2424
|
+
clearPendingPrompt(
|
|
2425
|
+
orphan.conversationId,
|
|
2426
|
+
orphan.generationId,
|
|
2427
|
+
homeDir
|
|
2428
|
+
);
|
|
2429
|
+
return null;
|
|
2430
|
+
}
|
|
2431
|
+
const config = loadCursorConfig(projectRoot);
|
|
2432
|
+
if (!config) {
|
|
2433
|
+
debugLog3("orphan-config-load-failed", { projectRoot });
|
|
2434
|
+
clearPendingPrompt(
|
|
2435
|
+
orphan.conversationId,
|
|
2436
|
+
orphan.generationId,
|
|
2437
|
+
homeDir
|
|
2438
|
+
);
|
|
2439
|
+
return null;
|
|
2440
|
+
}
|
|
2441
|
+
clearPendingPrompt(
|
|
2442
|
+
orphan.conversationId,
|
|
2443
|
+
orphan.generationId,
|
|
2444
|
+
homeDir
|
|
2445
|
+
);
|
|
2446
|
+
const built = buildOrphanPayload(
|
|
2447
|
+
{
|
|
2448
|
+
conversationId: orphan.conversationId,
|
|
2449
|
+
generationId: orphan.generationId,
|
|
2450
|
+
prompt: orphan.prompt,
|
|
2451
|
+
response: "",
|
|
2452
|
+
userEmail: orphan.userEmail,
|
|
2453
|
+
model: orphan.model,
|
|
2454
|
+
cursorVersion: orphan.cursorVersion,
|
|
2455
|
+
workspaceRoots: orphan.workspaceRoots,
|
|
2456
|
+
transcriptPath: orphan.transcriptPath,
|
|
2457
|
+
attachments: orphan.attachments,
|
|
2458
|
+
unknownFields: orphan.extra
|
|
2459
|
+
},
|
|
2460
|
+
config,
|
|
2461
|
+
event === "sessionEnd" ? "session-end" : "orphan-prompt"
|
|
2462
|
+
);
|
|
2463
|
+
const finalPayload = orphan.userEmail ? { ...built, email: orphan.userEmail } : built;
|
|
2464
|
+
return {
|
|
2465
|
+
payload: finalPayload,
|
|
2466
|
+
transport: {
|
|
2467
|
+
endpoint: config.monitoringEndpoint,
|
|
2468
|
+
apiKey: config.apiKey,
|
|
2469
|
+
projectRoot
|
|
2470
|
+
}
|
|
2471
|
+
};
|
|
2472
|
+
}
|
|
2473
|
+
}
|
|
2474
|
+
}
|
|
2475
|
+
function mergeUnknownFields(primary, fallback) {
|
|
2476
|
+
if (!primary && !fallback) return void 0;
|
|
2477
|
+
return { ...fallback ?? {}, ...primary ?? {} };
|
|
2478
|
+
}
|
|
2479
|
+
function pickOrphanForFlush(conversationId, homeDir) {
|
|
2480
|
+
const pending = listPendingPrompts(homeDir);
|
|
2481
|
+
if (pending.length === 0) return null;
|
|
2482
|
+
if (conversationId) {
|
|
2483
|
+
const match = pending.find((p) => p.conversationId === conversationId);
|
|
2484
|
+
if (match) return match;
|
|
2485
|
+
}
|
|
2486
|
+
return pending.sort(
|
|
2487
|
+
(a, b) => (a.stashedAt || "").localeCompare(b.stashedAt || "")
|
|
2488
|
+
)[0];
|
|
2489
|
+
}
|
|
2490
|
+
var cursorPlugin = {
|
|
2491
|
+
id: TOOL_ID3,
|
|
2492
|
+
displayName: "Cursor",
|
|
2493
|
+
install(opts) {
|
|
2494
|
+
return installCursor(opts);
|
|
2495
|
+
},
|
|
2496
|
+
uninstall(opts) {
|
|
2497
|
+
return uninstallCursor(opts);
|
|
2498
|
+
},
|
|
2499
|
+
status(opts) {
|
|
2500
|
+
return getCursorStatus(opts);
|
|
2501
|
+
},
|
|
2502
|
+
handleHook(eventName, payloadJson, opts) {
|
|
2503
|
+
return handleCursorHook(eventName, payloadJson, opts);
|
|
2504
|
+
},
|
|
2505
|
+
async detectInstalled() {
|
|
2506
|
+
try {
|
|
2507
|
+
if (fs15.existsSync(getCursorUserDir())) return true;
|
|
2508
|
+
return whichCursorOnPath();
|
|
2509
|
+
} catch {
|
|
2510
|
+
return false;
|
|
2511
|
+
}
|
|
2512
|
+
}
|
|
2513
|
+
};
|
|
2514
|
+
function whichCursorOnPath() {
|
|
2515
|
+
const pathEnv = process.env.PATH;
|
|
2516
|
+
if (!pathEnv) return false;
|
|
2517
|
+
const sep = process.platform === "win32" ? ";" : ":";
|
|
2518
|
+
const exts = process.platform === "win32" ? (process.env.PATHEXT ?? ".EXE;.CMD;.BAT").split(";") : [""];
|
|
2519
|
+
for (const dir of pathEnv.split(sep)) {
|
|
2520
|
+
for (const ext of exts) {
|
|
2521
|
+
const candidate = `${dir}/cursor${ext.toLowerCase()}`;
|
|
2522
|
+
try {
|
|
2523
|
+
if (fs15.existsSync(candidate)) return true;
|
|
2524
|
+
} catch {
|
|
2525
|
+
}
|
|
2526
|
+
}
|
|
2527
|
+
}
|
|
2528
|
+
return false;
|
|
2529
|
+
}
|
|
2530
|
+
registerPlugin(cursorPlugin);
|
|
2531
|
+
|
|
2532
|
+
// src/monitor/install.ts
|
|
2533
|
+
async function runMonitorInstall(toolId, opts = {}) {
|
|
2534
|
+
const plugin = getPlugin(toolId);
|
|
2535
|
+
const projectRoot = opts.projectRoot ?? process.cwd();
|
|
2536
|
+
const result = await plugin.install({
|
|
2537
|
+
projectRoot,
|
|
2538
|
+
interactive: opts.interactive ?? true
|
|
2539
|
+
});
|
|
2540
|
+
recordInstall(toolId, projectRoot, result);
|
|
2541
|
+
return result;
|
|
2542
|
+
}
|
|
2543
|
+
function recordInstall(toolId, projectRoot, result) {
|
|
2544
|
+
try {
|
|
2545
|
+
const entry = {
|
|
2546
|
+
path: projectRoot,
|
|
2547
|
+
tool: toolId,
|
|
2548
|
+
scope: getToolScope(toolId),
|
|
2549
|
+
agentId: result.agentId,
|
|
2550
|
+
agentName: result.agentName,
|
|
2551
|
+
source: result.source,
|
|
2552
|
+
configPath: getMonitorConfigPath(projectRoot, toolId),
|
|
2553
|
+
hooksPath: getToolHooksPath(toolId, projectRoot),
|
|
2554
|
+
monitoringEndpoint: result.monitoringEndpoint,
|
|
2555
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
2556
|
+
};
|
|
2557
|
+
upsertEntry(entry);
|
|
2558
|
+
} catch {
|
|
2559
|
+
}
|
|
2560
|
+
}
|
|
2561
|
+
|
|
2562
|
+
export {
|
|
2563
|
+
promptUser,
|
|
2564
|
+
isInteractive,
|
|
2565
|
+
getCodexHomeDir,
|
|
2566
|
+
getCodexConfigPath,
|
|
2567
|
+
TOOL_IDS,
|
|
2568
|
+
getPlugin,
|
|
2569
|
+
listPlugins,
|
|
2570
|
+
isToolId,
|
|
2571
|
+
loadCodexConfig,
|
|
2572
|
+
writeCodexConfig,
|
|
2573
|
+
installCodexHooksConfig,
|
|
2574
|
+
loadCursorConfig,
|
|
2575
|
+
writeCursorConfig,
|
|
2576
|
+
getCursorHooksPath,
|
|
2577
|
+
mergeCursorHooks,
|
|
2578
|
+
getToolScope,
|
|
2579
|
+
getToolSource,
|
|
2580
|
+
readRegistry,
|
|
2581
|
+
upsertEntry,
|
|
2582
|
+
removeEntry,
|
|
2583
|
+
reconcileCurrentWorkspace,
|
|
2584
|
+
formatRegistryTable,
|
|
2585
|
+
runMonitorInstall
|
|
2586
|
+
};
|
|
2587
|
+
//# sourceMappingURL=chunk-75YQWZ4Q.js.map
|