-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcli.mjs
More file actions
executable file
·755 lines (704 loc) · 29 KB
/
cli.mjs
File metadata and controls
executable file
·755 lines (704 loc) · 29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
#!/usr/bin/env node
// SPDX-License-Identifier: AGPL-3.0-only
import { parseArgs } from 'node:util';
import { loadConfig } from '../src/config.mjs';
import { tmuxRun } from '../src/tmux-runner.mjs';
import { tailReceipts } from '../src/receipt.mjs';
import { startWebhookServer } from '../src/webhook-server.mjs';
import { emitJson } from '../src/emit.mjs';
import { watchQueue } from '../src/watch.mjs';
import { startRoomPoller } from '../src/room-poller.mjs';
import { memoryList, memoryGet, memorySet, memoryAppend, memoryDelete, memorySearch } from '../src/memory.mjs';
import { triggerAgent, healthCheck, healthDeep, agentsList, configGet, configPatch, gatewayRestart } from '../src/openclaw-gateway.mjs';
import { sessionsSend, sessionsSpawn, sessionsList, sessionsHistory, sessionsStatus } from '../src/openclaw-sessions.mjs';
import { execApprovalRequest, execApprovalWait, execApprovalResolve, execApprovalList } from '../src/openclaw-exec.mjs';
import { listHooks, createForwarderHook, deleteHook } from '../src/openclaw-hooks.mjs';
import { cronList, cronAdd, cronRemove, cronRun, cronStatus } from '../src/openclaw-cron.mjs';
import { keepaliveStart, keepaliveStop, keepaliveStatus } from '../src/session-keepalive.mjs';
const args = process.argv.slice(2);
const command = args[0];
const subcommand = args[1];
function usage() {
console.log(`IDE Agent Kit v0.2
Usage:
ide-agent-kit serve [--config <path>]
Start webhook relay server for inbound GitHub events.
ide-agent-kit tmux run --cmd <command> [--session <name>] [--cwd <path>] [--timeout-sec <sec>] [--config <path>]
Run an allowlisted command in a tmux session. Captures output + exit code, appends receipt.
ide-agent-kit emit --to <url> --json <file>
POST a receipt or event JSON to a webhook target.
ide-agent-kit receipt tail [--n <count>] [--config <path>]
Print the last N receipts as JSON.
ide-agent-kit watch [--config <path>]
Watch the event queue and nudge IDE tmux session on new events.
ide-agent-kit poll --rooms <room1,room2> --api-key <key> --handle <@handle> [--interval <sec>] [--config <path>]
Poll Ant Farm rooms directly and nudge IDE tmux session on new messages.
ide-agent-kit memory <list|get|set|append|delete|search> [options]
Manage agent memory (local or OpenClaw backend).
--backend local|openclaw --agent <name> --key <topic> --value <text>
search: --query <text> [--max-results <n>] [--min-score <n>]
ide-agent-kit gateway <health|health-deep|agents|config-get|config-patch|trigger|wake> [options]
OpenClaw gateway operations.
trigger: --agent <id> --message <text> [--model <model>] [--timeout <sec>]
wake: --text <text> [--mode now|next-heartbeat]
config-patch: --patch <json>
ide-agent-kit sessions <list|send|spawn|history|status> [options]
Agent-to-agent communication via OpenClaw gateway.
send: --agent <id> --message <text> [--timeout <sec>]
spawn: --task <text> [--agent <id>] [--model <model>] [--mode run|session]
list: [--kinds main,group,cron] [--limit <n>] [--active-minutes <n>]
history: --session-key <key> [--limit <n>]
status: --session-key <key>
ide-agent-kit exec <list|request|resolve> [options]
Execution approval governance (integrates with thinkoff-judge-core).
list: [--agent <id>] [--status pending|resolved|all]
request: --command <cmd> [--agent <id>] [--cwd <path>]
resolve: --request-id <id> --decision <allow-once|allow-always|deny> [--reason <text>]
ide-agent-kit hooks <list|create|delete> [options]
OpenClaw event hook management.
list: [--agent <name>]
create: --name <hook-name> --events <evt1,evt2> --webhook-url <url> [--agent <name>]
delete: --name <hook-name> [--agent <name>]
ide-agent-kit cron <list|add|remove|run|status> [options]
OpenClaw scheduled task management.
list: List all cron jobs
add: --name <name> --task <text> --schedule <cron-expr|interval-ms> [--agent <id>] [--mode main|isolated]
remove: --job-id <id>
run: --job-id <id> (trigger immediate execution)
status: Show cron system status
ide-agent-kit keepalive <start|stop|status> [options]
Prevent macOS display sleep and terminal freezes for VNC/remote sessions.
start: Start caffeinate -d -i -s [--heartbeat-sec <n>] [--pid-file <path>]
stop: Stop managed caffeinate + heartbeat processes
status: Show keepalive state, system caffeinate procs, and pmset settings
ide-agent-kit init [--ide <claude-code|codex|cursor|vscode|gemini>] [--profile <balanced|low-friction>]
Generate starter config for your IDE.
`);
}
function parseKV(args, after) {
const opts = {};
let i = args.indexOf(after) + 1;
if (i === 0) i = 0;
while (i < args.length) {
const arg = args[i];
if (arg.startsWith('--')) {
const key = arg.slice(2);
const val = args[i + 1] && !args[i + 1].startsWith('--') ? args[++i] : true;
opts[key] = val;
}
i++;
}
return opts;
}
function gwOpts(opts) {
return {
home: opts.home, ssh: opts.ssh, bin: opts.bin
};
}
async function main() {
if (!command || command === '--help' || command === '-h') {
usage();
process.exit(0);
}
if (command === 'serve') {
const opts = parseKV(args, 'serve');
const config = loadConfig(opts.config);
startWebhookServer(config, (event) => {
console.log(`Event queued: ${event.kind} (${event.trace_id})`);
});
return;
}
if (command === 'tmux' && subcommand === 'run') {
const opts = parseKV(args, 'run');
if (!opts.cmd) {
console.error('Error: --cmd is required');
process.exit(1);
}
const config = loadConfig(opts.config);
const receipt = await tmuxRun({
session: opts.session,
cmd: opts.cmd,
cwd: opts.cwd,
timeoutSec: opts['timeout-sec'] ? parseInt(opts['timeout-sec']) : undefined,
config
});
console.log(JSON.stringify(receipt, null, 2));
process.exit(receipt.status === 'ok' ? 0 : 1);
}
if (command === 'emit') {
const opts = parseKV(args, 'emit');
if (!opts.to || !opts.json) {
console.error('Error: --to <url> and --json <file> are required');
process.exit(1);
}
try {
const result = await emitJson(opts.to, opts.json);
console.log(`Emitted to ${opts.to}: ${result.status}`);
if (result.status >= 400) {
console.error(result.body);
process.exit(1);
}
} catch (e) {
console.error(`Emit failed: ${e.message}`);
process.exit(1);
}
return;
}
if (command === 'receipt' && subcommand === 'tail') {
const opts = parseKV(args, 'tail');
const config = loadConfig(opts.config);
const n = opts.n ? parseInt(opts.n) : 5;
const receipts = tailReceipts(config.receipts.path, n);
if (receipts.length === 0) {
console.log('No receipts found.');
} else {
receipts.forEach(r => console.log(JSON.stringify(r)));
}
return;
}
if (command === 'watch') {
const opts = parseKV(args, 'watch');
const config = loadConfig(opts.config);
watchQueue(config, (event) => {
const src = event.source || '?';
const actor = event.actor?.login || '?';
const room = event.room || '';
console.log(` → ${src} event from ${actor}${room ? ' in ' + room : ''}`);
});
process.on('SIGINT', () => { console.log('\nStopping watcher.'); process.exit(0); });
return;
}
if (command === 'poll') {
const opts = parseKV(args, 'poll');
if (!opts.rooms || !opts['api-key'] || !opts.handle) {
console.error('Error: --rooms, --api-key, and --handle are required');
console.error('Example: ide-agent-kit poll --rooms thinkoff-development,feature-admin-planning --api-key <key> --handle @claudemm');
process.exit(1);
}
const config = loadConfig(opts.config);
await startRoomPoller({
rooms: opts.rooms.split(','),
apiKey: opts['api-key'],
handle: opts.handle,
interval: opts.interval ? parseInt(opts.interval) : undefined,
config
});
return;
}
// ── Memory ──────────────────────────────────────────────
if (command === 'memory') {
const opts = parseKV(args, subcommand || 'memory');
const config = loadConfig(opts.config);
const memOpts = { backend: opts.backend, agent: opts.agent };
if (subcommand === 'list') {
const entries = memoryList(config, memOpts);
if (entries.length === 0) {
console.log('No memory entries. Use "ide-agent-kit memory set --key <topic> --value <text>" to create one.');
} else {
entries.forEach(e => console.log(` ${e.key} (${e.size} bytes)`));
}
return;
}
if (subcommand === 'get') {
if (!opts.key) { console.error('Error: --key is required'); process.exit(1); }
const result = memoryGet(config, opts.key, memOpts);
if (result.error) { console.error(`Not found: ${opts.key}`); process.exit(1); }
console.log(result.content);
return;
}
if (subcommand === 'set') {
if (!opts.key || !opts.value) { console.error('Error: --key and --value are required'); process.exit(1); }
const result = memorySet(config, opts.key, opts.value, memOpts);
console.log(`Set ${result.key} (${result.size} bytes) → ${result.path}`);
return;
}
if (subcommand === 'append') {
if (!opts.key || !opts.value) { console.error('Error: --key and --value are required'); process.exit(1); }
const result = memoryAppend(config, opts.key, opts.value, memOpts);
console.log(`Appended to ${result.key} (${result.size} bytes) → ${result.path}`);
return;
}
if (subcommand === 'delete') {
if (!opts.key) { console.error('Error: --key is required'); process.exit(1); }
const result = memoryDelete(config, opts.key, memOpts);
console.log(`${result.action}: ${result.key}`);
return;
}
if (subcommand === 'search') {
if (!opts.query) { console.error('Error: --query is required'); process.exit(1); }
const result = memorySearch(config, opts.query, {
...memOpts,
...gwOpts(opts),
maxResults: opts['max-results'] ? parseInt(opts['max-results']) : undefined,
minScore: opts['min-score'] ? parseFloat(opts['min-score']) : undefined
});
if (!result.ok) { console.error(`Search failed: ${result.error}`); process.exit(1); }
if (result.results.length === 0) {
console.log('No results found.');
} else {
result.results.forEach(r => {
console.log(` [${(r.score || 0).toFixed(3)}] ${r.path || '?'}:${r.line || '?'}`);
if (r.snippet) console.log(` ${r.snippet.slice(0, 120)}`);
});
}
return;
}
console.error('Usage: ide-agent-kit memory <list|get|set|append|delete|search> [options]');
process.exit(1);
}
// ── Gateway ─────────────────────────────────────────────
if (command === 'gateway') {
const opts = parseKV(args, subcommand || 'gateway');
const config = loadConfig(opts.config);
const gw = gwOpts(opts);
if (subcommand === 'health') {
const result = await healthCheck(config, gw);
console.log(JSON.stringify(result.data || result, null, 2));
return;
}
if (subcommand === 'health-deep') {
const result = await healthDeep(config, gw);
console.log(JSON.stringify(result.data || result, null, 2));
return;
}
if (subcommand === 'agents') {
const result = await agentsList(config, gw);
console.log(JSON.stringify(result.data || result, null, 2));
return;
}
if (subcommand === 'config-get') {
const result = await configGet(config, gw);
console.log(JSON.stringify(result.data || result, null, 2));
return;
}
if (subcommand === 'config-patch') {
if (!opts.patch) { console.error('Error: --patch <json> is required'); process.exit(1); }
const patch = JSON.parse(opts.patch);
const result = await configPatch(config, patch, gw);
console.log(JSON.stringify(result.data || result, null, 2));
return;
}
if (subcommand === 'trigger') {
if (!opts.agent || !opts.message) { console.error('Error: --agent and --message are required'); process.exit(1); }
const result = await triggerAgent(config, {
agentId: opts.agent,
message: opts.message,
model: opts.model,
timeoutSeconds: opts.timeout ? parseInt(opts.timeout) : undefined
}, gw);
console.log(JSON.stringify(result.data || result, null, 2));
return;
}
if (subcommand === 'restart') {
const result = await gatewayRestart(config, gw);
console.log(JSON.stringify(result.data || result, null, 2));
return;
}
console.error('Usage: ide-agent-kit gateway <health|health-deep|agents|config-get|config-patch|trigger|restart>');
process.exit(1);
}
// ── Sessions ────────────────────────────────────────────
if (command === 'sessions') {
const opts = parseKV(args, subcommand || 'sessions');
const config = loadConfig(opts.config);
const gw = gwOpts(opts);
if (subcommand === 'list') {
const result = await sessionsList(config, {
kinds: opts.kinds ? opts.kinds.split(',') : undefined,
limit: opts.limit ? parseInt(opts.limit) : undefined,
activeMinutes: opts['active-minutes'] ? parseInt(opts['active-minutes']) : undefined,
messageLimit: opts['message-limit'] !== undefined ? parseInt(opts['message-limit']) : undefined
}, gw);
console.log(JSON.stringify(result.data || result, null, 2));
return;
}
if (subcommand === 'send') {
if (!opts.agent || !opts.message) { console.error('Error: --agent and --message are required'); process.exit(1); }
const result = await sessionsSend(config, {
agentId: opts.agent,
message: opts.message,
timeoutSeconds: opts.timeout ? parseInt(opts.timeout) : undefined
}, gw);
console.log(JSON.stringify(result.data || result, null, 2));
return;
}
if (subcommand === 'spawn') {
if (!opts.task) { console.error('Error: --task is required'); process.exit(1); }
const result = await sessionsSpawn(config, {
task: opts.task,
agentId: opts.agent,
model: opts.model,
mode: opts.mode,
runTimeoutSeconds: opts.timeout ? parseInt(opts.timeout) : undefined
}, gw);
console.log(JSON.stringify(result.data || result, null, 2));
return;
}
if (subcommand === 'history') {
if (!opts['session-key']) { console.error('Error: --session-key is required'); process.exit(1); }
const result = await sessionsHistory(config, {
sessionKey: opts['session-key'],
limit: opts.limit ? parseInt(opts.limit) : undefined
}, gw);
console.log(JSON.stringify(result.data || result, null, 2));
return;
}
if (subcommand === 'status') {
if (!opts['session-key']) { console.error('Error: --session-key is required'); process.exit(1); }
const result = await sessionsStatus(config, { sessionKey: opts['session-key'] }, gw);
console.log(JSON.stringify(result.data || result, null, 2));
return;
}
console.error('Usage: ide-agent-kit sessions <list|send|spawn|history|status>');
process.exit(1);
}
// ── Exec Approvals ──────────────────────────────────────
if (command === 'exec') {
const opts = parseKV(args, subcommand || 'exec');
const config = loadConfig(opts.config);
const gw = gwOpts(opts);
if (subcommand === 'list') {
const result = await execApprovalList(config, {
agentId: opts.agent,
status: opts.status
}, gw);
console.log(JSON.stringify(result.data || result, null, 2));
return;
}
if (subcommand === 'request') {
if (!opts.command) { console.error('Error: --command is required'); process.exit(1); }
const result = await execApprovalRequest(config, {
command: opts.command,
agentId: opts.agent,
cwd: opts.cwd
}, gw);
console.log(JSON.stringify(result.data || result, null, 2));
return;
}
if (subcommand === 'resolve') {
if (!opts['request-id'] || !opts.decision) { console.error('Error: --request-id and --decision are required'); process.exit(1); }
const result = await execApprovalResolve(config, {
requestId: opts['request-id'],
decision: opts.decision,
reason: opts.reason
}, gw);
console.log(JSON.stringify(result.data || result, null, 2));
return;
}
console.error('Usage: ide-agent-kit exec <list|request|resolve>');
process.exit(1);
}
// ── Hooks ───────────────────────────────────────────────
if (command === 'hooks') {
const opts = parseKV(args, subcommand || 'hooks');
const config = loadConfig(opts.config);
if (subcommand === 'list') {
const hooks = listHooks(config, { agent: opts.agent });
if (hooks.length === 0) {
console.log('No hooks installed.');
} else {
hooks.forEach(h => {
console.log(` ${h.name} (${h.scope}) events: ${(h.events || []).join(', ') || '?'}`);
});
}
return;
}
if (subcommand === 'create') {
if (!opts.name || !opts.events || !opts['webhook-url']) {
console.error('Error: --name, --events, and --webhook-url are required');
process.exit(1);
}
const result = createForwarderHook(config, {
name: opts.name,
events: opts.events.split(','),
webhookUrl: opts['webhook-url'],
agent: opts.agent
});
console.log(`Created hook: ${result.name} → ${result.path}`);
console.log(` Events: ${result.events.join(', ')}`);
console.log(` Forwards to: ${result.webhookUrl}`);
return;
}
if (subcommand === 'delete') {
if (!opts.name) { console.error('Error: --name is required'); process.exit(1); }
const result = deleteHook(config, { name: opts.name, agent: opts.agent });
console.log(`${result.action}: ${result.name}`);
return;
}
console.error('Usage: ide-agent-kit hooks <list|create|delete>');
process.exit(1);
}
// ── Cron ────────────────────────────────────────────────
if (command === 'cron') {
const opts = parseKV(args, subcommand || 'cron');
const config = loadConfig(opts.config);
const gw = gwOpts(opts);
if (subcommand === 'list') {
const result = await cronList(config, gw);
console.log(JSON.stringify(result.data || result, null, 2));
return;
}
if (subcommand === 'add') {
if (!opts.name || !opts.task || !opts.schedule) {
console.error('Error: --name, --task, and --schedule are required');
process.exit(1);
}
// Parse schedule: could be cron expr or interval ms
let schedule;
if (/^\d+$/.test(opts.schedule)) {
schedule = { every: parseInt(opts.schedule) };
} else if (opts.schedule.includes(' ')) {
schedule = { cron: opts.schedule };
} else {
schedule = { at: opts.schedule };
}
const result = await cronAdd(config, {
name: opts.name,
task: opts.task,
schedule,
agentId: opts.agent,
mode: opts.mode
}, gw);
console.log(JSON.stringify(result.data || result, null, 2));
return;
}
if (subcommand === 'remove') {
if (!opts['job-id']) { console.error('Error: --job-id is required'); process.exit(1); }
const result = await cronRemove(config, { jobId: opts['job-id'] }, gw);
console.log(JSON.stringify(result.data || result, null, 2));
return;
}
if (subcommand === 'run') {
if (!opts['job-id']) { console.error('Error: --job-id is required'); process.exit(1); }
const result = await cronRun(config, { jobId: opts['job-id'] }, gw);
console.log(JSON.stringify(result.data || result, null, 2));
return;
}
if (subcommand === 'status') {
const result = await cronStatus(config, gw);
console.log(JSON.stringify(result.data || result, null, 2));
return;
}
console.error('Usage: ide-agent-kit cron <list|add|remove|run|status>');
process.exit(1);
}
// ── Keepalive ──────────────────────────────────────────
if (command === 'keepalive') {
const opts = parseKV(args, subcommand || 'keepalive');
const config = loadConfig(opts.config);
const kaOpts = { pidFile: opts['pid-file'], heartbeatSec: opts['heartbeat-sec'] ? parseInt(opts['heartbeat-sec']) : undefined };
if (subcommand === 'start') {
const result = keepaliveStart(config, kaOpts);
if (!result.ok) { console.error(`Failed: ${result.error}`); process.exit(1); }
if (result.action === 'already-running') {
console.log(`Keepalive already running (caffeinate PID ${result.caffeinate?.pid})`);
} else {
console.log(`Keepalive started:`);
console.log(` caffeinate PID: ${result.caffeinate?.pid}`);
if (result.heartbeat) console.log(` heartbeat PID: ${result.heartbeat.pid} (every ${result.heartbeat.intervalSec}s)`);
}
return;
}
if (subcommand === 'stop') {
const result = keepaliveStop(config, kaOpts);
if (result.action === 'not-running') {
console.log('Keepalive not running.');
} else {
console.log(`Stopped: ${result.killed.join(', ')}`);
}
return;
}
if (subcommand === 'status') {
const result = keepaliveStatus(config, kaOpts);
console.log('Keepalive status:');
if (result.caffeinate) {
const src = result.caffeinate.external ? ' (external)' : ' (managed)';
console.log(` caffeinate: PID ${result.caffeinate.pid} alive=${result.caffeinate.alive}${src}`);
} else {
console.log(' caffeinate: not running');
}
if (result.heartbeat) {
console.log(` heartbeat: PID ${result.heartbeat.pid} alive=${result.heartbeat.alive} interval=${result.heartbeat.intervalSec}s`);
}
if (result.pmset.displaysleep != null) {
console.log(` displaysleep: ${result.pmset.displaysleep} min${result.pmset.displaysleep === 0 ? ' (never)' : ''}`);
}
if (result.pmset.sleep != null) {
console.log(` system sleep: ${result.pmset.sleep} min${result.pmset.sleep === 0 ? ' (never)' : ''}`);
}
if (result.systemCaffeinateProcesses.length > 1) {
console.log(` note: ${result.systemCaffeinateProcesses.length} caffeinate processes running`);
}
return;
}
console.error('Usage: ide-agent-kit keepalive <start|stop|status>');
process.exit(1);
}
if (command === 'init') {
const opts = parseKV(args, 'init');
const ide = opts.ide || 'claude-code';
const profile = opts.profile || opts.friction || 'balanced';
await initIdeConfig(ide, profile);
return;
}
console.error(`Unknown command: ${command} ${subcommand || ''}`);
usage();
process.exit(1);
}
async function initIdeConfig(ide, profile = 'balanced') {
const { writeFileSync, existsSync, mkdirSync } = await import('node:fs');
const { resolve } = await import('node:path');
const defaultAllow = ['npm test', 'npm run build', 'pytest', 'git status', 'git diff'];
const lowFrictionAllow = [
...defaultAllow,
'npm run lint',
'npm run typecheck',
'npm run test',
'npm run test:',
'node --test',
'python3 -m pytest',
'python -m pytest',
'rg',
'ls',
'cat',
'sed',
'awk',
'jq',
'git log',
'git show',
'git branch',
'git fetch',
'git pull --ff-only'
];
const normalizedProfile = profile === 'low' ? 'low-friction' : profile;
if (!['balanced', 'low-friction'].includes(normalizedProfile)) {
console.error(`Unknown profile: ${profile}. Choose from: balanced, low-friction`);
process.exit(1);
}
const allowForProfile = normalizedProfile === 'low-friction' ? lowFrictionAllow : defaultAllow;
const configs = {
'claude-code': {
filename: 'ide-agent-kit.json',
config: {
listen: { host: '127.0.0.1', port: 8787 },
queue: { path: './ide-agent-queue.jsonl' },
receipts: { path: './ide-agent-receipts.jsonl', stdout_tail_lines: 80 },
tmux: {
default_session: 'iak-runner',
ide_session: 'claude',
nudge_text: 'check rooms',
allow: allowForProfile
},
github: { webhook_secret: '', event_kinds: ['pull_request', 'issue_comment'] },
outbound: { default_webhook_url: '' },
openclaw: { host: '127.0.0.1', port: 18791, token: '' }
},
notes: `# Claude Code IDE Agent Kit config
# Runner uses a dedicated tmux session (iak-runner) to avoid conflicting with your IDE
# Add commands to tmux.allow to permit them
# Set github.webhook_secret to verify inbound webhooks
# Set openclaw.token to connect to your OpenClaw gateway
# Profile: ${normalizedProfile}`
},
'codex': {
filename: 'ide-agent-kit.json',
config: {
listen: { host: '127.0.0.1', port: 8787 },
queue: { path: './ide-agent-queue.jsonl' },
receipts: { path: './ide-agent-receipts.jsonl', stdout_tail_lines: 80 },
tmux: {
default_session: 'iak-runner',
ide_session: 'claude',
nudge_text: 'check rooms',
allow: allowForProfile
},
github: { webhook_secret: '', event_kinds: ['pull_request', 'issue_comment'] },
outbound: { default_webhook_url: '' },
openclaw: { host: '127.0.0.1', port: 18791, token: '' }
},
notes: `# Codex IDE Agent Kit config
# For Codex: auto-approve can be configured via Codex's own settings
# This module handles the webhook + tmux layer underneath
# Profile: ${normalizedProfile}`
},
'cursor': {
filename: 'ide-agent-kit.json',
config: {
listen: { host: '127.0.0.1', port: 8787 },
queue: { path: './ide-agent-queue.jsonl' },
receipts: { path: './ide-agent-receipts.jsonl', stdout_tail_lines: 80 },
tmux: {
default_session: 'iak-runner',
ide_session: 'claude',
nudge_text: 'check rooms',
allow: allowForProfile
},
github: { webhook_secret: '', event_kinds: ['pull_request', 'issue_comment'] },
outbound: { default_webhook_url: '' },
openclaw: { host: '127.0.0.1', port: 18791, token: '' }
},
notes: `# Cursor IDE Agent Kit config
# Cursor agents can invoke tmux runner via CLI or consume the webhook queue
# Profile: ${normalizedProfile}`
},
'vscode': {
filename: 'ide-agent-kit.json',
config: {
listen: { host: '127.0.0.1', port: 8787 },
queue: { path: './ide-agent-queue.jsonl' },
receipts: { path: './ide-agent-receipts.jsonl', stdout_tail_lines: 80 },
tmux: {
default_session: 'iak-runner',
ide_session: 'claude',
nudge_text: 'check rooms',
allow: allowForProfile
},
github: { webhook_secret: '', event_kinds: ['pull_request', 'issue_comment'] },
outbound: { default_webhook_url: '' },
openclaw: { host: '127.0.0.1', port: 18791, token: '' }
},
notes: `# VS Code IDE Agent Kit config
# VS Code extensions or Copilot agents can consume the queue file and invoke tmux runner
# Profile: ${normalizedProfile}`
},
'gemini': {
filename: 'ide-agent-kit.json',
config: {
listen: { host: '127.0.0.1', port: 8787 },
queue: { path: './ide-agent-queue.jsonl' },
receipts: { path: './ide-agent-receipts.jsonl', stdout_tail_lines: 80 },
tmux: {
default_session: 'iak-runner',
ide_session: 'claude',
nudge_text: 'check rooms',
allow: allowForProfile
},
github: { webhook_secret: '', event_kinds: ['pull_request', 'issue_comment'] },
outbound: { default_webhook_url: '' },
openclaw: { host: '127.0.0.1', port: 18791, token: '' }
},
notes: `# Gemini IDE Agent Kit config
# Fast path via webhook push model or fallback loop via 'gemini' tmux session.
# Broaden 'tmux.allow' for read/build tasks to reduce manual 'yes' clicking,
# but keep destructive actions behind manual IDE approval barriers.
# Profile: ${normalizedProfile}`
}
};
const preset = configs[ide];
if (!preset) {
console.error(`Unknown IDE: ${ide}. Choose from: ${Object.keys(configs).join(', ')}`);
process.exit(1);
}
const outPath = resolve(preset.filename);
if (existsSync(outPath)) {
console.log(`Config already exists: ${outPath}`);
return;
}
writeFileSync(outPath, JSON.stringify(preset.config, null, 2) + '\n');
console.log(`Created ${outPath} for ${ide}`);
console.log(preset.notes);
}
main().catch(e => {
console.error(e);
process.exit(1);
});