@orchbee/cli-win32-x64 0.0.0-stage → 0.1.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +4 -2
  3. package/package.json +22 -5
  4. package/release/agent-observation-adapters/.agents/plugins/marketplace.json +12 -0
  5. package/release/agent-observation-adapters/.claude-plugin/marketplace.json +13 -0
  6. package/release/agent-observation-adapters/README.md +363 -0
  7. package/release/agent-observation-adapters/bundle/.claude-plugin/plugin.json +8 -0
  8. package/release/agent-observation-adapters/bundle/.codex-plugin/plugin.json +7 -0
  9. package/release/agent-observation-adapters/bundle/.grok-plugin/plugin.json +7 -0
  10. package/release/agent-observation-adapters/bundle/.plugin/plugin.json +7 -0
  11. package/release/agent-observation-adapters/bundle/cline/orchbee-agent-observation.js +187 -0
  12. package/release/agent-observation-adapters/bundle/gemini/gemini-extension.json +5 -0
  13. package/release/agent-observation-adapters/bundle/gemini/hooks/hooks.json +118 -0
  14. package/release/agent-observation-adapters/bundle/hermes/plugin.py +40 -0
  15. package/release/agent-observation-adapters/bundle/hooks/codex.json +142 -0
  16. package/release/agent-observation-adapters/bundle/hooks/copilot.json +114 -0
  17. package/release/agent-observation-adapters/bundle/hooks/grok.json +170 -0
  18. package/release/agent-observation-adapters/bundle/hooks/hooks.json +244 -0
  19. package/release/agent-observation-adapters/bundle/kilo/orchbee-agent-observation.mjs +3 -0
  20. package/release/agent-observation-adapters/bundle/omp/orchbee-agent-observation.cjs +4 -0
  21. package/release/agent-observation-adapters/bundle/omp/orchbee-agent-observation.mjs +117 -0
  22. package/release/agent-observation-adapters/bundle/opencode/orchbee-agent-observation.mjs +13 -0
  23. package/release/agent-observation-adapters/bundle/package.json +25 -0
  24. package/release/agent-observation-adapters/bundle/pi/orchbee-agent-observation.cjs +4 -0
  25. package/release/agent-observation-adapters/bundle/pi/orchbee-agent-observation.mjs +112 -0
  26. package/release/agent-observation-adapters/bundle/qwen-code/qwen-extension.json +232 -0
  27. package/release/agent-observation-adapters/bundle/scripts/forward-hook.mjs +33 -0
  28. package/release/agent-observation-adapters/bundle/scripts/hook-sanitizers.mjs +571 -0
  29. package/release/agent-observation-adapters/bundle/scripts/observation-transport.mjs +549 -0
  30. package/release/agent-observation-adapters/bundle/scripts/opencode-family-observation.mjs +350 -0
  31. package/release/agent-observation-adapters/capsule.json +4 -0
  32. package/release/cohort.json +1 -0
  33. package/release/conpty/Microsoft.ConPTY-LICENSE.txt +21 -0
  34. package/release/conpty/OpenConsole.exe +0 -0
  35. package/release/conpty/conpty.dll +0 -0
  36. package/release/licenses/agent-detection/LICENSE +201 -0
  37. package/release/licenses/agent-detection/NOTICE +20 -0
  38. package/release/orchbee-launcher.exe +0 -0
  39. package/release/orchbee-server.exe +0 -0
  40. package/release/orchbee-terminal-host.exe +0 -0
  41. package/release/orchbee-worker.exe +0 -0
  42. package/release/orchbee.exe +4 -0
  43. package/release/release.json +1 -0
  44. package/release/release.json.sig +1 -0
@@ -0,0 +1,571 @@
1
+ const IDENTITY_PATTERN = /^[A-Za-z0-9._:-]{1,128}$/u;
2
+
3
+ export function sanitizeAgentHookInput(adapterId, value) {
4
+ if (!isRecord(value)) return null;
5
+ switch (adapterId) {
6
+ case 'hermes': {
7
+ if (
8
+ !['on_session_start', 'on_session_reset', 'pre_llm_call'].includes(value.event) ||
9
+ !['cli', 'tui', 'desktop', 'acp'].includes(value.platform) ||
10
+ (value.event === 'pre_llm_call' && value.platform !== 'cli')
11
+ )
12
+ return null;
13
+ const sessionKey = identity(value.session_id);
14
+ return sessionKey === null ? null : observation(sessionKey, 'session-identified');
15
+ }
16
+ case 'devin': {
17
+ if (
18
+ ![
19
+ 'SessionStart',
20
+ 'UserPromptSubmit',
21
+ 'PreToolUse',
22
+ 'PostToolUse',
23
+ 'PermissionRequest',
24
+ 'Stop',
25
+ ].includes(value.hook_event_name)
26
+ )
27
+ return null;
28
+ const sessionKey = identity(value.session_id);
29
+ return sessionKey === null ? null : observation(sessionKey, 'session-identified');
30
+ }
31
+ case 'letta': {
32
+ if (value.event_type !== 'SessionStart' || typeof value.is_new_session !== 'boolean')
33
+ return null;
34
+ let sessionKey = identity(value.conversation_id);
35
+ if (sessionKey === 'default') {
36
+ const agentKey = identity(value.agent_id);
37
+ sessionKey = agentKey === null ? null : identity(`default:${agentKey}`);
38
+ }
39
+ return sessionKey === null ? null : observation(sessionKey, 'session-identified');
40
+ }
41
+ case 'kimi': {
42
+ const sessionKey = identity(value.session_id);
43
+ if (sessionKey === null) return null;
44
+ if (value.hook_event_name === 'SessionStart')
45
+ return observation(sessionKey, 'session-identified');
46
+ if (value.hook_event_name === 'SessionEnd') return observation(sessionKey, 'session-ended');
47
+ return null;
48
+ }
49
+ case 'mastracode':
50
+ return sanitizeMastracodeHook(value);
51
+ case 'antigravity-cli': {
52
+ if (value.hook_event_name !== undefined && value.hook_event_name !== 'PreInvocation')
53
+ return null;
54
+ if (value.hookEventName !== undefined && value.hookEventName !== 'PreInvocation') return null;
55
+ const sessionKey = identity(value.conversationId);
56
+ return sessionKey === null ? null : observation(sessionKey, 'session-identified');
57
+ }
58
+ case 'droid':
59
+ case 'qodercli': {
60
+ const sessionKey = identity(value.session_id);
61
+ return value.hook_event_name === 'SessionStart' && sessionKey !== null
62
+ ? observation(sessionKey, 'session-identified')
63
+ : null;
64
+ }
65
+ case 'cursor':
66
+ return sanitizeCursorHook(value);
67
+ case 'claude-code':
68
+ return sanitizeClaudeCodeHook(value);
69
+ case 'codex':
70
+ return sanitizeCodexHook(value);
71
+ case 'grok':
72
+ return sanitizeGrokHook(value);
73
+ case 'gemini':
74
+ return sanitizeGeminiHook(value);
75
+ case 'github-copilot':
76
+ return sanitizeGitHubCopilotHook(value);
77
+ case 'qwen-code':
78
+ return sanitizeQwenCodeHook(value);
79
+ default:
80
+ return null;
81
+ }
82
+ }
83
+
84
+ function sanitizeMastracodeHook(value) {
85
+ const sessionKey = identity(value.session_id);
86
+ if (sessionKey === null) return null;
87
+ const event = value.hook_event_name;
88
+ if (event === 'SessionStart') return observation(sessionKey, 'session-identified');
89
+ if (event === 'SessionEnd') return observation(sessionKey, 'session-ended');
90
+ const turnKey = identity(value.run_id);
91
+ if (turnKey === null) return null;
92
+ switch (event) {
93
+ case 'AgentStart':
94
+ return observation(sessionKey, 'turn-started', { turnKey, activity: 'thinking' });
95
+ case 'AgentEnd': {
96
+ const outcome = { complete: 'turn-stopped', aborted: 'turn-canceled', error: 'turn-failed' };
97
+ return Object.hasOwn(outcome, value.stop_reason)
98
+ ? observation(sessionKey, outcome[value.stop_reason], { turnKey })
99
+ : null;
100
+ }
101
+ case 'PreToolUse':
102
+ case 'PostToolUse': {
103
+ if (identity(value.tool_name) === null) return null;
104
+ const operationKey = nullableIdentity(value.tool_call_id);
105
+ if (
106
+ operationKey === undefined ||
107
+ (value.tool_error !== undefined && typeof value.tool_error !== 'boolean')
108
+ )
109
+ return null;
110
+ return event === 'PreToolUse'
111
+ ? observation(sessionKey, 'tool-started', { turnKey, operationKey, activity: 'tool' })
112
+ : observation(sessionKey, value.tool_error === true ? 'tool-failed' : 'tool-finished', {
113
+ turnKey,
114
+ operationKey,
115
+ });
116
+ }
117
+ case 'PermissionRequest':
118
+ case 'PermissionResult': {
119
+ const operationKey = identity(value.tool_call_id);
120
+ if (
121
+ operationKey === null ||
122
+ !['tool_approval', 'sandbox_access', 'plan_approval'].includes(value.permission_kind)
123
+ )
124
+ return null;
125
+ if (
126
+ event === 'PermissionResult' &&
127
+ !['approved', 'declined', 'dismissed', 'auto_approved', 'auto_declined'].includes(
128
+ value.decision,
129
+ )
130
+ )
131
+ return null;
132
+ return observation(
133
+ sessionKey,
134
+ event === 'PermissionRequest' ? 'approval-requested' : 'attention-resolved',
135
+ { turnKey, operationKey },
136
+ );
137
+ }
138
+ case 'SubagentStart':
139
+ case 'SubagentEnd': {
140
+ const agentKey = identity(value.tool_call_id);
141
+ return agentKey === null
142
+ ? null
143
+ : observation(
144
+ sessionKey,
145
+ event === 'SubagentStart' ? 'subagent-started' : 'subagent-stopped',
146
+ { turnKey, agentKey },
147
+ );
148
+ }
149
+ default:
150
+ return null;
151
+ }
152
+ }
153
+
154
+ export function sanitizeCursorHook(value) {
155
+ if (!isRecord(value)) return null;
156
+ if (value.hook_event_name !== undefined && value.hook_event_name !== 'sessionStart') return null;
157
+ if (value.hookEventName !== undefined && value.hookEventName !== 'sessionStart') return null;
158
+ const supplied = [
159
+ value.session_id,
160
+ value.sessionId,
161
+ value.conversation_id,
162
+ value.conversationId,
163
+ ].filter((entry) => entry !== undefined);
164
+ if (supplied.length === 0) return null;
165
+ const sessionKey = identity(supplied[0]);
166
+ if (sessionKey === null || supplied.some((entry) => identity(entry) !== sessionKey)) return null;
167
+ return observation(sessionKey, 'session-identified');
168
+ }
169
+
170
+ export function sanitizeClaudeCodeHook(value) {
171
+ if (!isRecord(value)) return null;
172
+ const sessionKey = identity(value.session_id);
173
+ const eventName = hookEventName(value.hook_event_name);
174
+ const turnKey = nullableIdentity(value.turn_id);
175
+ if (sessionKey === null || eventName === null || turnKey === undefined) return null;
176
+ const toolName = identity(value.tool_name);
177
+ const toolUseId = identity(value.tool_use_id);
178
+ const agentKey = firstIdentity(value.agent_id, value.subagent_id);
179
+
180
+ switch (eventName) {
181
+ case 'sessionstart':
182
+ return observation(sessionKey, 'session-started', { turnKey });
183
+ case 'userpromptsubmit':
184
+ return observation(sessionKey, 'turn-started', { activity: 'thinking', turnKey });
185
+ case 'pretooluse':
186
+ if (toolName === 'AskUserQuestion') {
187
+ return observation(sessionKey, 'question-requested', {
188
+ operationKey: toolUseId,
189
+ turnKey,
190
+ });
191
+ }
192
+ if (toolName === 'ExitPlanMode') {
193
+ return observation(sessionKey, 'approval-requested', {
194
+ operationKey: toolUseId,
195
+ turnKey,
196
+ });
197
+ }
198
+ return observation(sessionKey, 'tool-started', {
199
+ activity: claudeCodeToolActivity(toolName),
200
+ operationKey: toolUseId,
201
+ turnKey,
202
+ });
203
+ case 'permissionrequest':
204
+ return observation(sessionKey, 'approval-requested', {
205
+ operationKey: toolUseId,
206
+ turnKey,
207
+ });
208
+ case 'posttooluse':
209
+ return observation(sessionKey, 'tool-finished', {
210
+ operationKey: toolUseId,
211
+ turnKey,
212
+ });
213
+ case 'posttoolusefailure':
214
+ return observation(sessionKey, 'tool-failed', {
215
+ operationKey: toolUseId,
216
+ turnKey,
217
+ });
218
+ case 'precompact':
219
+ return observation(sessionKey, 'compaction-started', { turnKey });
220
+ case 'postcompact':
221
+ return observation(sessionKey, 'compaction-finished', { turnKey });
222
+ case 'subagentstart':
223
+ return observation(sessionKey, 'subagent-started', { agentKey, turnKey });
224
+ case 'subagentstop':
225
+ return observation(sessionKey, 'subagent-stopped', { agentKey, turnKey });
226
+ case 'stop':
227
+ return observation(sessionKey, 'turn-stopped', { turnKey });
228
+ case 'stopfailure':
229
+ return observation(sessionKey, 'turn-failed', { turnKey });
230
+ case 'sessionend':
231
+ return observation(sessionKey, 'session-ended', { turnKey });
232
+ default:
233
+ return null;
234
+ }
235
+ }
236
+
237
+ export function sanitizeCodexHook(value) {
238
+ if (!isRecord(value)) return null;
239
+ const sessionKey = identity(value.session_id);
240
+ const eventName = hookEventName(value.hook_event_name);
241
+ const turnKey = nullableIdentity(value.turn_id);
242
+ if (sessionKey === null || eventName === null || turnKey === undefined) return null;
243
+ const toolName = identity(value.tool_name);
244
+ const operationKey = turnKey;
245
+ const agentKey = firstIdentity(value.agent_id, value.subagent_id);
246
+
247
+ switch (eventName) {
248
+ case 'sessionstart':
249
+ return value.source === 'compact'
250
+ ? null
251
+ : observation(sessionKey, 'session-started', { turnKey });
252
+ case 'userpromptsubmit':
253
+ return observation(sessionKey, 'turn-started', { activity: 'thinking', turnKey });
254
+ case 'pretooluse':
255
+ if (toolName === 'request_user_input' || toolName === 'AskUserQuestion') {
256
+ return observation(sessionKey, 'question-requested', { operationKey, turnKey });
257
+ }
258
+ return observation(sessionKey, 'tool-started', {
259
+ activity: codexToolActivity(toolName),
260
+ operationKey,
261
+ turnKey,
262
+ });
263
+ case 'permissionrequest':
264
+ return observation(sessionKey, 'approval-requested', { operationKey, turnKey });
265
+ case 'posttooluse':
266
+ return observation(sessionKey, 'tool-finished', { operationKey, turnKey });
267
+ case 'precompact':
268
+ return observation(sessionKey, 'compaction-started', { turnKey });
269
+ case 'postcompact':
270
+ return observation(sessionKey, 'compaction-finished', { turnKey });
271
+ case 'subagentstart':
272
+ return observation(sessionKey, 'subagent-started', { agentKey, turnKey });
273
+ case 'subagentstop':
274
+ return observation(sessionKey, 'subagent-stopped', { agentKey, turnKey });
275
+ case 'stop':
276
+ return observation(sessionKey, 'turn-stopped', { turnKey });
277
+ case 'sessionend':
278
+ return observation(sessionKey, 'session-ended', { turnKey });
279
+ default:
280
+ return null;
281
+ }
282
+ }
283
+
284
+ export function sanitizeGrokHook(value) {
285
+ if (!isRecord(value)) return null;
286
+ const sessionKey = identity(value.sessionId);
287
+ const eventName = hookEventName(value.hookEventName);
288
+ const turnKey = nullableIdentity(value.promptId);
289
+ if (sessionKey === null || eventName === null || turnKey === undefined) return null;
290
+ if (
291
+ identity(value.subagentType) !== null &&
292
+ eventName !== 'subagentstart' &&
293
+ eventName !== 'subagentstop'
294
+ ) {
295
+ return null;
296
+ }
297
+ const toolName = identity(value.toolName);
298
+ const toolUseId = identity(value.toolUseId);
299
+ const operationKey = toolUseId ?? turnKey;
300
+ const agentKey = firstIdentity(value.agentId, value.subagentId, value.promptId);
301
+
302
+ switch (eventName) {
303
+ case 'sessionstart':
304
+ return observation(sessionKey, 'session-started', { turnKey });
305
+ case 'userpromptsubmit':
306
+ return observation(sessionKey, 'turn-started', { activity: 'thinking', turnKey });
307
+ case 'pretooluse':
308
+ return observation(sessionKey, 'tool-started', {
309
+ activity: grokToolActivity(toolName),
310
+ operationKey,
311
+ turnKey,
312
+ });
313
+ case 'posttooluse':
314
+ return observation(sessionKey, 'tool-finished', { operationKey, turnKey });
315
+ case 'posttoolfailure':
316
+ case 'posttoolusefailure':
317
+ return observation(sessionKey, 'tool-failed', { operationKey, turnKey });
318
+ case 'permissiondenied':
319
+ return observation(sessionKey, 'attention-resolved', { operationKey, turnKey });
320
+ case 'notification':
321
+ switch (value.notificationType) {
322
+ case 'permission_prompt':
323
+ return observation(sessionKey, 'approval-requested', { operationKey, turnKey });
324
+ case 'idle_prompt':
325
+ return observation(sessionKey, 'session-idle', { turnKey });
326
+ case 'task_complete':
327
+ return observation(sessionKey, 'turn-stopped', { turnKey });
328
+ default:
329
+ return null;
330
+ }
331
+ case 'precompact':
332
+ return observation(sessionKey, 'compaction-started', { turnKey });
333
+ case 'postcompact':
334
+ return observation(sessionKey, 'compaction-finished', { turnKey });
335
+ case 'subagentstart':
336
+ return observation(sessionKey, 'subagent-started', { agentKey, turnKey });
337
+ case 'subagentstop':
338
+ return observation(sessionKey, 'subagent-stopped', { agentKey, turnKey });
339
+ case 'stop':
340
+ return value.reason === 'end_turn'
341
+ ? observation(sessionKey, 'turn-stopped', { turnKey })
342
+ : null;
343
+ case 'stopfailure':
344
+ return observation(sessionKey, 'turn-failed', { turnKey });
345
+ case 'stopcancelled':
346
+ case 'stopcanceled':
347
+ return observation(
348
+ sessionKey,
349
+ value.reason === 'user_interrupt' && value.cancelledBy === 'user'
350
+ ? 'turn-interrupted'
351
+ : 'turn-canceled',
352
+ { turnKey },
353
+ );
354
+ case 'sessionend':
355
+ return observation(sessionKey, 'session-ended', { turnKey });
356
+ default:
357
+ return null;
358
+ }
359
+ }
360
+
361
+ export function sanitizeGeminiHook(value) {
362
+ if (!isRecord(value)) return null;
363
+ const sessionKey = identity(value.session_id);
364
+ const eventName = hookEventName(value.hook_event_name);
365
+ if (sessionKey === null || eventName === null) return null;
366
+ const toolName = identity(value.tool_name);
367
+ const operationKey = sessionKey;
368
+
369
+ switch (eventName) {
370
+ case 'sessionstart':
371
+ return observation(sessionKey, 'session-started');
372
+ case 'beforeagent':
373
+ return observation(sessionKey, 'turn-started', { activity: 'thinking' });
374
+ case 'beforetool':
375
+ if (toolName === 'ask_user') {
376
+ return observation(sessionKey, 'question-requested', { operationKey });
377
+ }
378
+ return observation(sessionKey, 'tool-started', {
379
+ activity: geminiToolActivity(toolName),
380
+ operationKey,
381
+ });
382
+ case 'aftertool':
383
+ return observation(sessionKey, 'tool-finished', { operationKey });
384
+ case 'notification':
385
+ return value.notification_type === 'ToolPermission'
386
+ ? observation(sessionKey, 'approval-requested', { operationKey })
387
+ : null;
388
+ case 'precompress':
389
+ return observation(sessionKey, 'compaction-started');
390
+ case 'afteragent':
391
+ return observation(sessionKey, 'turn-stopped');
392
+ case 'sessionend':
393
+ return observation(sessionKey, 'session-ended');
394
+ default:
395
+ return null;
396
+ }
397
+ }
398
+
399
+ export function sanitizeGitHubCopilotHook(value) {
400
+ if (!isRecord(value)) return null;
401
+ const sessionKey = identity(value.session_id);
402
+ const eventName = hookEventName(value.hook_event_name);
403
+ if (sessionKey === null || eventName === null) return null;
404
+ const operationKey = sessionKey;
405
+
406
+ switch (eventName) {
407
+ case 'sessionstart':
408
+ return observation(sessionKey, 'session-started');
409
+ case 'userpromptsubmit':
410
+ return observation(sessionKey, 'turn-started', { activity: 'thinking' });
411
+ case 'posttooluse':
412
+ return observation(sessionKey, 'tool-finished', { operationKey });
413
+ case 'posttoolusefailure':
414
+ return observation(sessionKey, 'tool-failed', { operationKey });
415
+ case 'notification':
416
+ switch (value.notification_type) {
417
+ case 'permission_prompt':
418
+ return observation(sessionKey, 'approval-requested', { operationKey });
419
+ case 'elicitation_dialog':
420
+ return observation(sessionKey, 'question-requested', { operationKey });
421
+ default:
422
+ return null;
423
+ }
424
+ case 'precompact':
425
+ return observation(sessionKey, 'compaction-started');
426
+ case 'stop':
427
+ return observation(sessionKey, 'turn-stopped');
428
+ case 'erroroccurred':
429
+ return value.recoverable === false ? observation(sessionKey, 'turn-failed') : null;
430
+ case 'sessionend':
431
+ return observation(sessionKey, 'session-ended');
432
+ default:
433
+ return null;
434
+ }
435
+ }
436
+
437
+ export function sanitizeQwenCodeHook(value) {
438
+ if (!isRecord(value)) return null;
439
+ const sessionKey = identity(value.session_id);
440
+ const eventName = hookEventName(value.hook_event_name);
441
+ if (sessionKey === null || eventName === null) return null;
442
+ const toolName = identity(value.tool_name);
443
+ const operationKey = sessionKey;
444
+ const agentKey = identity(value.agent_id);
445
+
446
+ switch (eventName) {
447
+ case 'sessionstart':
448
+ return value.source === 'compact' ? null : observation(sessionKey, 'session-started');
449
+ case 'userpromptsubmit':
450
+ return typeof value.submitted_prompt === 'string'
451
+ ? observation(sessionKey, 'turn-started', { activity: 'thinking' })
452
+ : null;
453
+ case 'pretooluse':
454
+ if (toolName === 'ask_user_question') {
455
+ return observation(sessionKey, 'question-requested', { operationKey });
456
+ }
457
+ return observation(sessionKey, 'tool-started', {
458
+ activity: qwenCodeToolActivity(toolName),
459
+ operationKey,
460
+ });
461
+ case 'posttooluse':
462
+ return observation(sessionKey, 'tool-finished', { operationKey });
463
+ case 'posttoolusefailure':
464
+ return observation(sessionKey, 'tool-failed', { operationKey });
465
+ case 'permissionrequest':
466
+ return observation(sessionKey, 'approval-requested', { operationKey: sessionKey });
467
+ case 'permissiondenied':
468
+ return observation(sessionKey, 'attention-resolved', { operationKey: sessionKey });
469
+ case 'notification':
470
+ switch (value.notification_type) {
471
+ case 'permission_prompt':
472
+ return observation(sessionKey, 'approval-requested', {
473
+ operationKey: sessionKey,
474
+ });
475
+ case 'idle_prompt':
476
+ return observation(sessionKey, 'session-idle');
477
+ default:
478
+ return null;
479
+ }
480
+ case 'precompact':
481
+ return observation(sessionKey, 'compaction-started');
482
+ case 'postcompact':
483
+ return observation(sessionKey, 'compaction-finished');
484
+ case 'subagentstart':
485
+ return observation(sessionKey, 'subagent-started', { agentKey });
486
+ case 'subagentstop':
487
+ return observation(sessionKey, 'subagent-stopped', { agentKey });
488
+ case 'stop':
489
+ return observation(sessionKey, 'turn-stopped');
490
+ case 'stopfailure':
491
+ return observation(sessionKey, 'turn-failed');
492
+ case 'sessionend':
493
+ return observation(sessionKey, 'session-ended');
494
+ default:
495
+ return null;
496
+ }
497
+ }
498
+
499
+ function observation(sessionKey, event, fields = {}) {
500
+ return {
501
+ activity: fields.activity ?? null,
502
+ agentKey: fields.agentKey ?? null,
503
+ event,
504
+ operationKey: fields.operationKey ?? null,
505
+ sessionKey,
506
+ turnKey: fields.turnKey ?? null,
507
+ version: 1,
508
+ };
509
+ }
510
+
511
+ function claudeCodeToolActivity(toolName) {
512
+ if (toolName === 'Bash') return 'command';
513
+ if (toolName === 'Edit' || toolName === 'Write' || toolName === 'NotebookEdit') return 'editing';
514
+ if (toolName === 'Task' || toolName === 'Agent') return 'subagent';
515
+ return 'tool';
516
+ }
517
+
518
+ function codexToolActivity(toolName) {
519
+ if (toolName === 'exec_command' || toolName === 'write_stdin') return 'command';
520
+ if (toolName === 'apply_patch') return 'editing';
521
+ if (toolName === 'spawn_agent' || toolName === 'send_input') return 'subagent';
522
+ return 'tool';
523
+ }
524
+
525
+ function grokToolActivity(toolName) {
526
+ if (toolName === 'run_terminal_command') return 'command';
527
+ if (toolName === 'search_replace' || toolName === 'write_file') return 'editing';
528
+ if (toolName === 'spawn_subagent') return 'subagent';
529
+ return 'tool';
530
+ }
531
+
532
+ function geminiToolActivity(toolName) {
533
+ if (toolName === 'run_shell_command') return 'command';
534
+ if (toolName === 'replace' || toolName === 'write_file') return 'editing';
535
+ if (toolName === 'delegate_to_agent') return 'subagent';
536
+ return 'tool';
537
+ }
538
+
539
+ function qwenCodeToolActivity(toolName) {
540
+ if (toolName === 'run_shell_command') return 'command';
541
+ if (toolName === 'edit' || toolName === 'write_file') return 'editing';
542
+ if (toolName === 'task') return 'subagent';
543
+ return 'tool';
544
+ }
545
+
546
+ function hookEventName(value) {
547
+ if (typeof value !== 'string' || value.length === 0 || value.length > 64) return null;
548
+ return value.replaceAll(/[^A-Za-z]/gu, '').toLowerCase();
549
+ }
550
+
551
+ function firstIdentity(...values) {
552
+ for (const value of values) {
553
+ const result = identity(value);
554
+ if (result !== null) return result;
555
+ }
556
+ return null;
557
+ }
558
+
559
+ function nullableIdentity(value) {
560
+ if (value === undefined || value === null) return null;
561
+ const result = identity(value);
562
+ return result === null ? undefined : result;
563
+ }
564
+
565
+ function identity(value) {
566
+ return typeof value === 'string' && IDENTITY_PATTERN.test(value) ? value : null;
567
+ }
568
+
569
+ function isRecord(value) {
570
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
571
+ }