@myclaw163/clawclaw-cli 0.6.54
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/README.md +440 -0
- package/bin/clawclaw-cli.mjs +4 -0
- package/package.json +48 -0
- package/personas//347/220/206/346/231/272/346/270/251/345/222/214.md +23 -0
- package/personas//350/200/201/350/260/213/346/267/261/347/256/227.md +22 -0
- package/personas//350/257/232/346/201/263/347/233/264/347/216/207.md +22 -0
- package/personas//350/275/273/346/235/276/346/264/273/346/263/274.md +22 -0
- package/personas//351/207/216/346/200/247/345/217/233/351/200/206.md +23 -0
- package/scripts/postinstall.mjs +20 -0
- package/scripts/sync-bundled-skill.mjs +245 -0
- package/scripts/sync-bundled-skill.test.mjs +152 -0
- package/skills/clawclaw/SKILL.md +240 -0
- package/skills/clawclaw/references/CHATTERBOX.md +142 -0
- package/skills/clawclaw/references/COMMANDS.md +132 -0
- package/skills/clawclaw/references/GAME-MECHANICS.md +186 -0
- package/skills/clawclaw/references/HUB.md +48 -0
- package/skills/clawclaw/references/KNOWLEDGE.md +43 -0
- package/skills/clawclaw/references/STRATEGIES.md +57 -0
- package/skills/clawclaw/references/STREAM.md +58 -0
- package/skills/clawclaw/references/TACTICS.md +65 -0
- package/src/assets/clawclaw-ascii-map.txt +40 -0
- package/src/cli.ts +153 -0
- package/src/commands/_schema.ts +109 -0
- package/src/commands/account.ts +209 -0
- package/src/commands/config.ts +30 -0
- package/src/commands/do.test.ts +37 -0
- package/src/commands/do.ts +95 -0
- package/src/commands/events.ts +22 -0
- package/src/commands/game-map.test.ts +28 -0
- package/src/commands/game-start-plan.test.ts +142 -0
- package/src/commands/game.ts +882 -0
- package/src/commands/history-player.test.ts +102 -0
- package/src/commands/history.ts +573 -0
- package/src/commands/hub.test.ts +96 -0
- package/src/commands/hub.ts +234 -0
- package/src/commands/knowledge.test.ts +19 -0
- package/src/commands/knowledge.ts +168 -0
- package/src/commands/load.test.ts +51 -0
- package/src/commands/load.ts +13 -0
- package/src/commands/meeting-history.test.ts +106 -0
- package/src/commands/memory.ts +40 -0
- package/src/commands/peek.ts +38 -0
- package/src/commands/persona.ts +57 -0
- package/src/commands/setup/codex.ts +248 -0
- package/src/commands/setup/hermes.test.ts +96 -0
- package/src/commands/setup/hermes.ts +76 -0
- package/src/commands/setup/index.ts +13 -0
- package/src/commands/setup/openclaw.test.ts +114 -0
- package/src/commands/setup/openclaw.ts +147 -0
- package/src/commands/skill.ts +128 -0
- package/src/commands/state.ts +46 -0
- package/src/commands/strategy.test.ts +135 -0
- package/src/commands/strategy.ts +189 -0
- package/src/commands/tts.ts +128 -0
- package/src/commands/upgrade.test.ts +91 -0
- package/src/commands/upgrade.ts +154 -0
- package/src/commands/watch.test.ts +973 -0
- package/src/commands/watch.ts +709 -0
- package/src/lib/auth.test.ts +59 -0
- package/src/lib/auth.ts +186 -0
- package/src/lib/command-meta.ts +37 -0
- package/src/lib/game-client.ts +391 -0
- package/src/lib/host-config-patcher.test.ts +130 -0
- package/src/lib/host-config-patcher.ts +151 -0
- package/src/lib/http-keepalive.ts +15 -0
- package/src/lib/http-transport.test.ts +42 -0
- package/src/lib/http-transport.ts +113 -0
- package/src/lib/hub-client.test.ts +56 -0
- package/src/lib/hub-client.ts +88 -0
- package/src/lib/hub-install.test.ts +98 -0
- package/src/lib/hub-install.ts +121 -0
- package/src/lib/hub-reminder.ts +75 -0
- package/src/lib/hub-unzip.test.ts +69 -0
- package/src/lib/hub-unzip.ts +62 -0
- package/src/lib/init-command.test.ts +75 -0
- package/src/lib/init-command.ts +120 -0
- package/src/lib/knowledge-store.test.ts +180 -0
- package/src/lib/knowledge-store.ts +374 -0
- package/src/lib/load-context.test.ts +52 -0
- package/src/lib/load-context.ts +52 -0
- package/src/lib/match-state.test.ts +134 -0
- package/src/lib/match-state.ts +94 -0
- package/src/lib/netease-tts.ts +83 -0
- package/src/lib/normalize.ts +42 -0
- package/src/lib/persona.test.ts +41 -0
- package/src/lib/persona.ts +72 -0
- package/src/lib/server-registry.ts +152 -0
- package/src/lib/skill-version.test.ts +48 -0
- package/src/lib/skill-version.ts +19 -0
- package/src/lib/strategy-export.test.ts +232 -0
- package/src/lib/strategy-export.ts +242 -0
- package/src/lib/tts-keys.ts +7 -0
- package/src/lib/tts-speech.test.ts +63 -0
- package/src/lib/tts-speech.ts +76 -0
- package/src/lib/workspace-argv.test.ts +49 -0
- package/src/lib/workspace-argv.ts +44 -0
- package/src/perception/player-history-store.test.ts +87 -0
- package/src/perception/player-history-store.ts +194 -0
- package/src/pipeline/event-store.ts +124 -0
- package/src/pipeline/pipeline.ts +35 -0
- package/src/runtime/auto-upgrade.test.ts +66 -0
- package/src/runtime/auto-upgrade.ts +31 -0
- package/src/runtime/daemon.ts +100 -0
- package/src/runtime/event-daemon.test.ts +28 -0
- package/src/runtime/event-daemon.ts +371 -0
- package/src/runtime/opening-mover.ts +303 -0
- package/src/runtime/raw-ws-log.test.ts +33 -0
- package/src/runtime/raw-ws-log.ts +32 -0
- package/src/runtime/runtime-logger.ts +99 -0
- package/src/runtime/ws-client.test.ts +47 -0
- package/src/runtime/ws-client.ts +272 -0
- package/src/sdk/action.ts +166 -0
- package/src/sdk/index.ts +110 -0
- package/src/sdk/types.ts +146 -0
- package/src/strategies/avoid-lone.ts +11 -0
- package/src/strategies/avoid-players.knowledge.md +20 -0
- package/src/strategies/avoid-players.ts +15 -0
- package/src/strategies/corpse-patrol.ts +22 -0
- package/src/strategies/crab-sabotage.ts +21 -0
- package/src/strategies/custom-module.test.ts +269 -0
- package/src/strategies/find-player.ts +16 -0
- package/src/strategies/game-utils.test.ts +164 -0
- package/src/strategies/game-utils.ts +721 -0
- package/src/strategies/goals/avoid-lone-top.ts +168 -0
- package/src/strategies/goals/avoid-players-top.test.ts +83 -0
- package/src/strategies/goals/avoid-players-top.ts +121 -0
- package/src/strategies/goals/conversation-goal.ts +51 -0
- package/src/strategies/goals/corpse-patrol-top.ts +91 -0
- package/src/strategies/goals/crab-octopus-reflexes.ts +93 -0
- package/src/strategies/goals/crab-sabotage-top.ts +197 -0
- package/src/strategies/goals/emergency-hunt-goal.ts +28 -0
- package/src/strategies/goals/find-player-top.ts +93 -0
- package/src/strategies/goals/flee-players-goal.ts +53 -0
- package/src/strategies/goals/goal-manager.ts +41 -0
- package/src/strategies/goals/goal-root-strategy.ts +49 -0
- package/src/strategies/goals/goal.ts +28 -0
- package/src/strategies/goals/keep-away-goal.ts +206 -0
- package/src/strategies/goals/kill-frenzy-top.ts +80 -0
- package/src/strategies/goals/kill-lone-top.ts +160 -0
- package/src/strategies/goals/kill-target-goal.ts +59 -0
- package/src/strategies/goals/kill-target-top.ts +109 -0
- package/src/strategies/goals/leaf-goal.ts +25 -0
- package/src/strategies/goals/linger-corpse-goal.ts +79 -0
- package/src/strategies/goals/lone-kill-core.ts +82 -0
- package/src/strategies/goals/lone-kill-goal.ts +24 -0
- package/src/strategies/goals/lone-kill-task-top.test.ts +85 -0
- package/src/strategies/goals/lone-kill-task-top.ts +86 -0
- package/src/strategies/goals/move-room-goal.ts +60 -0
- package/src/strategies/goals/normal-shrimp-top.test.ts +80 -0
- package/src/strategies/goals/normal-shrimp-top.ts +242 -0
- package/src/strategies/goals/paradise-fish-top.test.ts +126 -0
- package/src/strategies/goals/paradise-fish-top.ts +219 -0
- package/src/strategies/goals/patrol-top.ts +57 -0
- package/src/strategies/goals/report-patrol-top.ts +80 -0
- package/src/strategies/goals/safe-task-goal.ts +102 -0
- package/src/strategies/goals/social-task-top.ts +161 -0
- package/src/strategies/goals/task-kill-report-top.ts +163 -0
- package/src/strategies/goals/task-only-top.ts +57 -0
- package/src/strategies/goals/task-or-patrol-goal.ts +41 -0
- package/src/strategies/goals/task-report-top.ts +57 -0
- package/src/strategies/goals/wander-task-goal.ts +33 -0
- package/src/strategies/goals/warrior-shrimp-top.test.ts +86 -0
- package/src/strategies/goals/warrior-shrimp-top.ts +248 -0
- package/src/strategies/greeting.ts +53 -0
- package/src/strategies/kill-frenzy.ts +12 -0
- package/src/strategies/kill-lone.knowledge.md +20 -0
- package/src/strategies/kill-lone.ts +13 -0
- package/src/strategies/kill-target.ts +18 -0
- package/src/strategies/loader.test.ts +678 -0
- package/src/strategies/loader.ts +172 -0
- package/src/strategies/lone-kill-task.ts +21 -0
- package/src/strategies/meeting-gate.test.ts +59 -0
- package/src/strategies/meeting-gate.ts +23 -0
- package/src/strategies/move-room.ts +15 -0
- package/src/strategies/new-events-backfill.ts +98 -0
- package/src/strategies/paradise-fish.knowledge.md +20 -0
- package/src/strategies/paradise-fish.ts +25 -0
- package/src/strategies/pathfind/clawclaw-walkable.bin +0 -0
- package/src/strategies/pathfind/distance-field.ts +150 -0
- package/src/strategies/pathfind/escape-planner.test.ts +197 -0
- package/src/strategies/pathfind/escape-planner.ts +348 -0
- package/src/strategies/pathfind/walkable-grid.ts +117 -0
- package/src/strategies/patrol.ts +11 -0
- package/src/strategies/player-targets.ts +13 -0
- package/src/strategies/report-patrol.ts +11 -0
- package/src/strategies/shrimp-memory.knowledge.md +20 -0
- package/src/strategies/shrimp-memory.ts +25 -0
- package/src/strategies/social-task.test.ts +28 -0
- package/src/strategies/social-task.ts +49 -0
- package/src/strategies/spawn.ts +71 -0
- package/src/strategies/speech-module.ts +123 -0
- package/src/strategies/strategy-loop.ts +757 -0
- package/src/strategies/task-kill-report.ts +17 -0
- package/src/strategies/task-only.ts +11 -0
- package/src/strategies/task-report.ts +22 -0
- package/src/strategies/types.ts +96 -0
- package/src/strategies/warrior-memory.knowledge.md +20 -0
- package/src/strategies/warrior-memory.ts +16 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { meetingHistoryCommandInternals } from './history.js';
|
|
3
|
+
|
|
4
|
+
const allSeats = [
|
|
5
|
+
{ name: 'A', seat: 1 },
|
|
6
|
+
{ name: 'B', seat: 2 },
|
|
7
|
+
{ name: 'C', seat: 3 },
|
|
8
|
+
];
|
|
9
|
+
|
|
10
|
+
describe('meeting history builder', () => {
|
|
11
|
+
it('outputs the compact meeting shape with found-in-meeting deaths and ordered speeches', () => {
|
|
12
|
+
const records = meetingHistoryCommandInternals.buildMeetingRecords([
|
|
13
|
+
{ type: 'meeting_start', tick: 10, actor_name: 'A' },
|
|
14
|
+
{ type: 'meeting_briefing', tick: 10, all_seats: allSeats },
|
|
15
|
+
{
|
|
16
|
+
type: 'meeting_state',
|
|
17
|
+
round: 1,
|
|
18
|
+
tick: 10,
|
|
19
|
+
sub_phase: 'entry',
|
|
20
|
+
speech_order: ['A', 'B'],
|
|
21
|
+
alive_players: ['A', 'B'],
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
type: 'meeting_state',
|
|
25
|
+
round: 1,
|
|
26
|
+
tick: 20,
|
|
27
|
+
sub_phase: 'vote',
|
|
28
|
+
speech_order: ['A', 'B'],
|
|
29
|
+
speeches: { B: '我没问题', A: '' },
|
|
30
|
+
speech_skipped: ['A'],
|
|
31
|
+
votes_submitted: ['A'],
|
|
32
|
+
alive_players: ['A', 'B'],
|
|
33
|
+
},
|
|
34
|
+
{ type: 'no_exile', tick: 30, votes: { A: 'skip', B: 'skip' } },
|
|
35
|
+
{ type: 'meeting_ended', tick: 31, result: 'skip', result_target: null },
|
|
36
|
+
]);
|
|
37
|
+
const [meeting] = meetingHistoryCommandInternals.allMeetingOutputs(records);
|
|
38
|
+
expect(Object.keys(meeting)).toEqual([
|
|
39
|
+
'round',
|
|
40
|
+
'tick',
|
|
41
|
+
'caller',
|
|
42
|
+
'corpses_found',
|
|
43
|
+
'state',
|
|
44
|
+
'exiled_player',
|
|
45
|
+
'players',
|
|
46
|
+
'votes',
|
|
47
|
+
'speeches',
|
|
48
|
+
]);
|
|
49
|
+
expect(meeting.corpses_found).toBeNull();
|
|
50
|
+
expect(meeting.state).toBe('ended');
|
|
51
|
+
expect(meeting.players).toEqual([
|
|
52
|
+
{ name: 'A', seat: 1, status: 'alive', death: null },
|
|
53
|
+
{ name: 'B', seat: 2, status: 'alive', death: null },
|
|
54
|
+
{ name: 'C', seat: 3, status: 'dead', death: { type: 'found_in_meeting', round: 1 } },
|
|
55
|
+
]);
|
|
56
|
+
expect(meeting.votes).toEqual({ A: 'skip', B: 'skip' });
|
|
57
|
+
expect(meeting.speeches).toEqual([
|
|
58
|
+
{ speaker: 'A', text: '', skipped: true },
|
|
59
|
+
{ speaker: 'B', text: '我没问题', skipped: false },
|
|
60
|
+
]);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('marks exiled players and carries death status into later meetings', () => {
|
|
64
|
+
const records = meetingHistoryCommandInternals.buildMeetingRecords([
|
|
65
|
+
{ type: 'meeting_start', tick: 10, actor_name: 'A' },
|
|
66
|
+
{ type: 'meeting_briefing', tick: 10, all_seats: allSeats },
|
|
67
|
+
{ type: 'meeting_state', round: 1, tick: 10, sub_phase: 'vote', alive_players: ['A', 'B', 'C'] },
|
|
68
|
+
{ type: 'exile', tick: 20, actor_name: 'B', votes: { A: 'B', C: 'B' } },
|
|
69
|
+
{ type: 'meeting_ended', tick: 21, result: 'exiled', result_target: 'B' },
|
|
70
|
+
{ type: 'meeting_start', tick: 100, actor_name: 'A' },
|
|
71
|
+
{ type: 'meeting_briefing', tick: 100, all_seats: allSeats },
|
|
72
|
+
{ type: 'meeting_state', round: 2, tick: 100, sub_phase: 'entry', alive_players: ['A', 'C'] },
|
|
73
|
+
]);
|
|
74
|
+
const meetings = meetingHistoryCommandInternals.allMeetingOutputs(records);
|
|
75
|
+
expect(meetings[0].players.find((player: any) => player.name === 'B')).toEqual({
|
|
76
|
+
name: 'B',
|
|
77
|
+
seat: 2,
|
|
78
|
+
status: 'dead',
|
|
79
|
+
death: { type: 'exiled', round: 1 },
|
|
80
|
+
});
|
|
81
|
+
expect(meetings[1].players.find((player: any) => player.name === 'B')?.death).toEqual({ type: 'exiled', round: 1 });
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('keeps current unfinished meeting state from meeting_state', () => {
|
|
85
|
+
const records = meetingHistoryCommandInternals.buildMeetingRecords([
|
|
86
|
+
{ type: 'meeting_start', tick: 10, actor_name: 'A' },
|
|
87
|
+
{ type: 'meeting_briefing', tick: 10, all_seats: allSeats },
|
|
88
|
+
{ type: 'meeting_state', round: 1, tick: 11, sub_phase: 'speech', current_speaker: 'B', alive_players: ['A', 'B', 'C'] },
|
|
89
|
+
]);
|
|
90
|
+
const [meeting] = meetingHistoryCommandInternals.allMeetingOutputs(records);
|
|
91
|
+
expect(meeting.state).toBe('speech');
|
|
92
|
+
expect(meeting.speeches).toEqual([]);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('marks an unfinished previous meeting interrupted when a new meeting starts', () => {
|
|
96
|
+
const records = meetingHistoryCommandInternals.buildMeetingRecords([
|
|
97
|
+
{ type: 'meeting_start', tick: 10, actor_name: 'A' },
|
|
98
|
+
{ type: 'meeting_briefing', tick: 10, all_seats: allSeats },
|
|
99
|
+
{ type: 'meeting_start', tick: 100, actor_name: 'C' },
|
|
100
|
+
{ type: 'meeting_briefing', tick: 100, all_seats: allSeats },
|
|
101
|
+
]);
|
|
102
|
+
const meetings = meetingHistoryCommandInternals.allMeetingOutputs(records);
|
|
103
|
+
expect(meetings[0].state).toBe('interrupted_or_missing_end');
|
|
104
|
+
expect(meetings[1].state).toBe('interrupted_or_missing_end');
|
|
105
|
+
});
|
|
106
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { existsSync, writeFileSync } from 'fs';
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import { AuthStore } from '../lib/auth.js';
|
|
4
|
+
import { getProfileMemoryFile } from '../lib/init-command.js';
|
|
5
|
+
import { loadMemorySnapshot } from '../lib/load-context.js';
|
|
6
|
+
|
|
7
|
+
function getMemoryFile(): string {
|
|
8
|
+
const profile = new AuthStore().getActive();
|
|
9
|
+
if (!profile) throw new Error('Not logged in.');
|
|
10
|
+
return getProfileMemoryFile(profile);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function ensureMemoryFile(path: string): void {
|
|
14
|
+
if (!existsSync(path)) writeFileSync(path, '');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function createMemoryCommand(): Command {
|
|
18
|
+
const memory = new Command('memory');
|
|
19
|
+
memory
|
|
20
|
+
.alias('mem')
|
|
21
|
+
.description('Persistent strategy and run memory');
|
|
22
|
+
|
|
23
|
+
memory
|
|
24
|
+
.command('path')
|
|
25
|
+
.description('Print the absolute memory file path')
|
|
26
|
+
.action(() => {
|
|
27
|
+
const path = getMemoryFile();
|
|
28
|
+
ensureMemoryFile(path);
|
|
29
|
+
console.log(JSON.stringify({ path }, null, 2));
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
memory
|
|
33
|
+
.command('load')
|
|
34
|
+
.description('Read the memory file')
|
|
35
|
+
.action(() => {
|
|
36
|
+
console.log(JSON.stringify(loadMemorySnapshot(), null, 2));
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return memory;
|
|
40
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import { AuthStore } from '../lib/auth.js';
|
|
4
|
+
import { getProfileStateDir } from '../lib/init-command.js';
|
|
5
|
+
import { snapshotOnce } from './watch.js';
|
|
6
|
+
|
|
7
|
+
export interface RunPeekOptions {
|
|
8
|
+
stdout: (line: string) => void;
|
|
9
|
+
stderr?: (line: string) => void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** One-shot snapshot of the local feed.json. Returns process exit code. */
|
|
13
|
+
export function runPeek(opts: RunPeekOptions): number {
|
|
14
|
+
const stderr = opts.stderr ?? ((s) => process.stderr.write(s));
|
|
15
|
+
const store = new AuthStore();
|
|
16
|
+
const profile = store.getActive();
|
|
17
|
+
if (!profile) {
|
|
18
|
+
opts.stdout(JSON.stringify({ exit_reason: ['not_logged_in'], error: 'Not logged in' }) + '\n');
|
|
19
|
+
return 0;
|
|
20
|
+
}
|
|
21
|
+
const feedPath = join(getProfileStateDir(profile), 'feed.json');
|
|
22
|
+
try {
|
|
23
|
+
snapshotOnce({ feedPath, stdout: opts.stdout });
|
|
24
|
+
return 0;
|
|
25
|
+
} catch (err: any) {
|
|
26
|
+
stderr((err?.message ?? String(err)) + '\n');
|
|
27
|
+
return 1;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function createPeekCommand(): Command {
|
|
32
|
+
return new Command('peek')
|
|
33
|
+
.description('Print a one-shot snapshot of current game state from the local feed (no HTTP, no streaming). Pairs with `ccl game start` for live updates and `ccl events` for history.')
|
|
34
|
+
.action(() => {
|
|
35
|
+
const code = runPeek({ stdout: (s) => process.stdout.write(s) });
|
|
36
|
+
if (code !== 0) process.exit(code);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import {
|
|
3
|
+
applyPersonaPreset,
|
|
4
|
+
ensurePersonaFile,
|
|
5
|
+
getActivePersonaFile,
|
|
6
|
+
listPersonaPresets,
|
|
7
|
+
} from '../lib/persona.js';
|
|
8
|
+
import { loadPersonaSnapshot } from '../lib/load-context.js';
|
|
9
|
+
|
|
10
|
+
export function createPersonaCommand(): Command {
|
|
11
|
+
const persona = new Command('persona');
|
|
12
|
+
persona
|
|
13
|
+
.alias('prs')
|
|
14
|
+
.description('Per-account roleplay persona notes');
|
|
15
|
+
|
|
16
|
+
persona
|
|
17
|
+
.command('list')
|
|
18
|
+
.description('List bundled persona presets')
|
|
19
|
+
.action(() => {
|
|
20
|
+
const presets = listPersonaPresets().map(({ id, name }) => ({ id, name }));
|
|
21
|
+
console.log(JSON.stringify({ presets }, null, 2));
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
persona
|
|
25
|
+
.command('path')
|
|
26
|
+
.description('Print the absolute persona file path for the active account')
|
|
27
|
+
.action(() => {
|
|
28
|
+
const path = getActivePersonaFile();
|
|
29
|
+
ensurePersonaFile(path);
|
|
30
|
+
console.log(JSON.stringify({ path }, null, 2));
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
persona
|
|
34
|
+
.command('load')
|
|
35
|
+
.description('Read the active account persona file')
|
|
36
|
+
.action(() => {
|
|
37
|
+
console.log(JSON.stringify(loadPersonaSnapshot(), null, 2));
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
persona
|
|
41
|
+
.command('use <preset>')
|
|
42
|
+
.description('Copy a bundled persona preset into the active account persona file')
|
|
43
|
+
.action((presetName: string) => {
|
|
44
|
+
const path = getActivePersonaFile();
|
|
45
|
+
const preset = applyPersonaPreset(presetName, path);
|
|
46
|
+
console.log(JSON.stringify({
|
|
47
|
+
path,
|
|
48
|
+
preset: {
|
|
49
|
+
id: preset.id,
|
|
50
|
+
name: preset.name,
|
|
51
|
+
},
|
|
52
|
+
message: `Persona "${preset.name}" copied to active account.`,
|
|
53
|
+
}, null, 2));
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
return persona;
|
|
57
|
+
}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ccl setup codex` — 使用 Codex 原生 `codex mcp add` 安装 ClawClaw MCP server
|
|
3
|
+
*
|
|
4
|
+
* 优先: codex mcp add clawclaw -- <启动命令>
|
|
5
|
+
* 回退: 直接写 ~/.codex/config.toml(codex 不可用时)
|
|
6
|
+
*
|
|
7
|
+
* 用法:
|
|
8
|
+
* ccl setup codex # dry-run 预览
|
|
9
|
+
* ccl setup codex -y # 应用
|
|
10
|
+
* ccl setup codex --print # 仅输出等价命令行
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { Command } from 'commander';
|
|
14
|
+
import { homedir } from 'os';
|
|
15
|
+
import { join } from 'path';
|
|
16
|
+
import { existsSync, readFileSync, appendFileSync, copyFileSync, readdirSync, statSync as fsStatSync } from 'fs';
|
|
17
|
+
import { spawnSync } from 'child_process';
|
|
18
|
+
|
|
19
|
+
// ─── 路径解析 ──────────────────────────────────────────────────
|
|
20
|
+
|
|
21
|
+
function resolveCodexConfigPath(): string {
|
|
22
|
+
const home = process.env.CODEX_HOME?.trim();
|
|
23
|
+
if (home) return join(home, 'config.toml');
|
|
24
|
+
return join(homedir(), '.codex', 'config.toml');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function resolveCodexClawclawEntry(): { command: string; args: string[] } | null {
|
|
28
|
+
const isWin = process.platform === 'win32';
|
|
29
|
+
const appData = process.env.APPDATA || join(homedir(), 'AppData', 'Roaming');
|
|
30
|
+
|
|
31
|
+
// 1. dist/mcp-server.js 优先(编译后的纯 JS,无 tsx stdout 污染,最可靠)
|
|
32
|
+
const distCandidates = [
|
|
33
|
+
join(appData, 'npm', 'node_modules', 'codex-clawclaw', 'dist', 'mcp-server.js'),
|
|
34
|
+
join('D:', 'codex-clawclaw', 'dist', 'mcp-server.js'),
|
|
35
|
+
];
|
|
36
|
+
for (const dist of distCandidates) {
|
|
37
|
+
try { if (existsSync(dist)) return { command: 'node', args: [dist] }; } catch { /* continue */ }
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// 2. .mjs 包装器(bin/codex-clawclaw.mjs, 自注册 tsx, 直接 node 运行)
|
|
41
|
+
const mjsCandidates = [
|
|
42
|
+
join(appData, 'npm', 'node_modules', 'codex-clawclaw', 'bin', 'codex-clawclaw.mjs'),
|
|
43
|
+
join('D:', 'codex-clawclaw', 'bin', 'codex-clawclaw.mjs'),
|
|
44
|
+
];
|
|
45
|
+
for (const mjs of mjsCandidates) {
|
|
46
|
+
try { if (existsSync(mjs)) return { command: process.execPath, args: [mjs] }; } catch { /* continue */ }
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// 3. PATH 上找 bin(.cmd)
|
|
50
|
+
const cmdNames = isWin
|
|
51
|
+
? ['codex-clawclaw.cmd', 'codex-clawclaw.ps1', 'codex-clawclaw']
|
|
52
|
+
: ['codex-clawclaw'];
|
|
53
|
+
const sep = isWin ? '\\' : '/';
|
|
54
|
+
const pathDirs = (process.env.PATH || '').split(isWin ? ';' : ':').filter(Boolean);
|
|
55
|
+
for (const dir of pathDirs) {
|
|
56
|
+
for (const name of cmdNames) {
|
|
57
|
+
const full = `${dir}${sep}${name}`;
|
|
58
|
+
try { if (existsSync(full)) return { command: full, args: [] }; } catch { /* continue */ }
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// 4. 旧版路径(src/mcp-server.ts, 需搭配 tsx)
|
|
63
|
+
const tsCandidates = [
|
|
64
|
+
join(appData, 'npm', 'node_modules', 'codex-clawclaw', 'src', 'mcp-server.ts'),
|
|
65
|
+
join('D:', 'codex-clawclaw', 'src', 'mcp-server.ts'),
|
|
66
|
+
];
|
|
67
|
+
for (const ts of tsCandidates) {
|
|
68
|
+
try { if (existsSync(ts)) return { command: process.execPath, args: [resolveTsxCli(), ts] }; } catch { /* continue */ }
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function resolveTsxCli(): string {
|
|
75
|
+
const appData = process.env.APPDATA || join(homedir(), 'AppData', 'Roaming');
|
|
76
|
+
const candidates = [
|
|
77
|
+
join(appData, 'npm', 'node_modules', 'tsx', 'dist', 'cli.mjs'),
|
|
78
|
+
join('D:', 'codex-clawclaw', 'node_modules', 'tsx', 'dist', 'cli.mjs'),
|
|
79
|
+
];
|
|
80
|
+
for (const c of candidates) {
|
|
81
|
+
try { if (existsSync(c)) return c; } catch { /* continue */ }
|
|
82
|
+
}
|
|
83
|
+
return 'tsx';
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** 解析 codex CLI 的可执行文件路径(直接 .exe,不依赖 shell shim) */
|
|
87
|
+
function resolveCodexExe(): string | null {
|
|
88
|
+
// 1. 从 config.toml 读取 CODEX_CLI_PATH(ccl 自己的全局配置)
|
|
89
|
+
const configPath = join(homedir(), '.clawclaw', 'config.json');
|
|
90
|
+
try {
|
|
91
|
+
if (existsSync(configPath)) {
|
|
92
|
+
const cfg = JSON.parse(readFileSync(configPath, 'utf-8'));
|
|
93
|
+
if (cfg.codexCliPath && existsSync(cfg.codexCliPath)) return cfg.codexCliPath;
|
|
94
|
+
}
|
|
95
|
+
} catch { /* ignore */ }
|
|
96
|
+
|
|
97
|
+
// 2. 从 ~/.codex/config.toml 读取 CODEX_CLI_PATH 环境变量
|
|
98
|
+
// 搜索 AppData\Local\OpenAI\Codex\bin\ 下最新的 codex.exe
|
|
99
|
+
const appData = process.env.LOCALAPPDATA || join(homedir(), 'AppData', 'Local');
|
|
100
|
+
const codexBinDir = join(appData, 'OpenAI', 'Codex', 'bin');
|
|
101
|
+
try {
|
|
102
|
+
if (existsSync(codexBinDir)) {
|
|
103
|
+
const dirs = readdirSync(codexBinDir).filter((d: string) => {
|
|
104
|
+
try { return fsStatSync(join(codexBinDir, d)).isDirectory(); } catch { return false; }
|
|
105
|
+
}).sort().reverse(); // 最新版本优先
|
|
106
|
+
for (const d of dirs) {
|
|
107
|
+
const exe = join(codexBinDir, d, 'codex.exe');
|
|
108
|
+
try { if (existsSync(exe)) return exe; } catch { /* continue */ }
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
} catch { /* ignore */ }
|
|
112
|
+
|
|
113
|
+
// 3. PATH 上找 codex.cmd(Windows)
|
|
114
|
+
const pathDirs = (process.env.PATH || '').split(';').filter(Boolean);
|
|
115
|
+
for (const dir of pathDirs) {
|
|
116
|
+
const full = join(dir, 'codex.cmd');
|
|
117
|
+
try { if (existsSync(full)) return full; } catch { /* continue */ }
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function codexMcpAvailable(): boolean {
|
|
124
|
+
const exe = resolveCodexExe();
|
|
125
|
+
if (!exe) return false;
|
|
126
|
+
try {
|
|
127
|
+
const r = spawnSync(exe, ['mcp', 'list', '--json'], {
|
|
128
|
+
env: { ...process.env, NO_COLOR: '1' },
|
|
129
|
+
windowsHide: true, timeout: 10_000, encoding: 'utf-8',
|
|
130
|
+
});
|
|
131
|
+
return r.status === 0;
|
|
132
|
+
} catch { return false; }
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function codexMcpAlreadyRegistered(): boolean {
|
|
136
|
+
const exe = resolveCodexExe();
|
|
137
|
+
if (!exe) return false;
|
|
138
|
+
try {
|
|
139
|
+
const r = spawnSync(exe, ['mcp', 'list', '--json'], {
|
|
140
|
+
env: { ...process.env, NO_COLOR: '1' },
|
|
141
|
+
windowsHide: true, timeout: 10_000, encoding: 'utf-8',
|
|
142
|
+
});
|
|
143
|
+
if (r.status !== 0 || !r.stdout) return false;
|
|
144
|
+
const servers = JSON.parse(r.stdout);
|
|
145
|
+
return Array.isArray(servers) && servers.some((s: any) => s.name === 'clawclaw');
|
|
146
|
+
} catch { return false; }
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// ─── Commander ─────────────────────────────────────────────────
|
|
150
|
+
|
|
151
|
+
export function createSetupCodexSubcommand(): Command {
|
|
152
|
+
return new Command('codex')
|
|
153
|
+
.description('使用 codex mcp add 安装 ClawClaw MCP server(codex 不可用时回退到写 config.toml)。')
|
|
154
|
+
.option('-y, --yes', '应用更改(默认 dry-run)')
|
|
155
|
+
.option('--print', '仅输出推荐命令')
|
|
156
|
+
.action((opts: { yes?: boolean; print?: boolean }) => {
|
|
157
|
+
const entry = resolveCodexClawclawEntry();
|
|
158
|
+
if (!entry) {
|
|
159
|
+
console.log('未找到 codex-clawclaw。');
|
|
160
|
+
console.log('发布后: npm install -g codex-clawclaw');
|
|
161
|
+
console.log('本地开发: 在 codex-clawclaw 目录下 npm link');
|
|
162
|
+
process.exit(1);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const addArgs = ['mcp', 'add', 'clawclaw', '--', entry.command, ...entry.args];
|
|
166
|
+
|
|
167
|
+
if (opts.print) {
|
|
168
|
+
console.log('# 推荐执行:');
|
|
169
|
+
console.log(`codex ${addArgs.join(' ')}`);
|
|
170
|
+
console.log('');
|
|
171
|
+
console.log('# 等价 config.toml:');
|
|
172
|
+
console.log('[mcp_servers.clawclaw]');
|
|
173
|
+
console.log(`command = '${entry.command.replace(/\\/g, '\\\\')}'`);
|
|
174
|
+
console.log(`args = ${JSON.stringify(entry.args)}`);
|
|
175
|
+
console.log('startup_timeout_sec = 30');
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (codexMcpAvailable() && codexMcpAlreadyRegistered()) {
|
|
180
|
+
console.log('ClawClaw MCP server 已注册。');
|
|
181
|
+
process.exit(0);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (!opts.yes) {
|
|
185
|
+
console.log('待执行:');
|
|
186
|
+
console.log(` codex ${addArgs.join(' ')}`);
|
|
187
|
+
if (!codexMcpAvailable()) {
|
|
188
|
+
console.log('');
|
|
189
|
+
console.log('(codex mcp 不可用,将回退到直接写 config.toml)');
|
|
190
|
+
}
|
|
191
|
+
console.log('');
|
|
192
|
+
console.log('Dry-run 模式。加 -y 以应用更改。');
|
|
193
|
+
process.exit(2);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// ── 应用: 优先 codex mcp add ──
|
|
197
|
+
if (codexMcpAvailable()) {
|
|
198
|
+
const r = spawnSync(resolveCodexExe()!, addArgs, {
|
|
199
|
+
env: { ...process.env, NO_COLOR: '1' },
|
|
200
|
+
windowsHide: true, timeout: 30_000, encoding: 'utf-8',
|
|
201
|
+
});
|
|
202
|
+
if (r.status !== 0) {
|
|
203
|
+
console.error('codex mcp add 失败:', r.stderr?.trim() || r.stdout?.trim() || `exit ${r.status}`);
|
|
204
|
+
process.exit(1);
|
|
205
|
+
}
|
|
206
|
+
console.log('已注册 ClawClaw MCP server(无需重启 Codex)。');
|
|
207
|
+
process.exit(0);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// ── 回退: 直接写 config.toml ──
|
|
211
|
+
const configPath = resolveCodexConfigPath();
|
|
212
|
+
if (!existsSync(configPath)) {
|
|
213
|
+
console.log('Codex config 未找到:', configPath);
|
|
214
|
+
console.log('请先运行 codex 完成初始化。');
|
|
215
|
+
process.exit(1);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
let raw: string;
|
|
219
|
+
try { raw = readFileSync(configPath, 'utf-8'); } catch (e: any) {
|
|
220
|
+
console.error('读取失败:', e?.message ?? e);
|
|
221
|
+
process.exit(1);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (/^\s*\[mcp_servers\.clawclaw\]/m.test(raw)) {
|
|
225
|
+
console.log('[mcp_servers.clawclaw] 已存在于 config.toml。');
|
|
226
|
+
process.exit(0);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const ts = new Date().toISOString().replace(/[:.]/g, '-');
|
|
230
|
+
copyFileSync(configPath, `${configPath}.bak.${ts}`);
|
|
231
|
+
|
|
232
|
+
const snippet = [
|
|
233
|
+
'',
|
|
234
|
+
'[mcp_servers.clawclaw]',
|
|
235
|
+
`command = '${entry.command.replace(/\\/g, '\\\\')}'`,
|
|
236
|
+
`args = ${JSON.stringify(entry.args)}`,
|
|
237
|
+
'startup_timeout_sec = 30',
|
|
238
|
+
'',
|
|
239
|
+
].join('\n');
|
|
240
|
+
appendFileSync(configPath, snippet, 'utf-8');
|
|
241
|
+
|
|
242
|
+
console.log(`已更新 ${configPath}(备份: config.toml.bak.${ts})`);
|
|
243
|
+
console.log('');
|
|
244
|
+
console.log('重启 Codex 后生效。可用工具:');
|
|
245
|
+
console.log(' clawclaw_game_start / clawclaw_game_stop / clawclaw_game_status');
|
|
246
|
+
console.log(' clawclaw_do / clawclaw_state / clawclaw_events / ...');
|
|
247
|
+
});
|
|
248
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { describe, expect, it, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { runHermesSetup } from './hermes.js';
|
|
3
|
+
import { spawnSync } from 'child_process';
|
|
4
|
+
|
|
5
|
+
vi.mock('child_process', () => ({
|
|
6
|
+
spawnSync: vi.fn(),
|
|
7
|
+
}));
|
|
8
|
+
|
|
9
|
+
const mockedSpawnSync = vi.mocked(spawnSync);
|
|
10
|
+
|
|
11
|
+
function mockSpawn(overrides: Array<{ status: number; stdout?: string; stderr?: string }>) {
|
|
12
|
+
mockedSpawnSync.mockImplementation((_cmd: any, _args?: any, _opts?: any): any => {
|
|
13
|
+
const next = overrides.shift();
|
|
14
|
+
if (!next) throw new Error('Unexpected spawnSync call');
|
|
15
|
+
return {
|
|
16
|
+
status: next.status,
|
|
17
|
+
stdout: next.stdout ?? '',
|
|
18
|
+
stderr: next.stderr ?? '',
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
vi.clearAllMocks();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe('runHermesSetup', () => {
|
|
28
|
+
it('returns error when hermes CLI is not found', () => {
|
|
29
|
+
mockSpawn([{ status: 1, stderr: 'command not found' }]);
|
|
30
|
+
const r = runHermesSetup({});
|
|
31
|
+
expect(r.exitCode).toBe(1);
|
|
32
|
+
expect(r.output.some((l) => l.includes('not found'))).toBe(true);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('reports already-enabled when clawclaw is in plugins list', () => {
|
|
36
|
+
mockSpawn([
|
|
37
|
+
{ status: 0 }, // --version
|
|
38
|
+
{ status: 0, stdout: 'clawclaw\nother-plugin' }, // plugins list
|
|
39
|
+
]);
|
|
40
|
+
const r = runHermesSetup({});
|
|
41
|
+
expect(r.exitCode).toBe(0);
|
|
42
|
+
expect(r.output.some((l) => l.includes('already enabled'))).toBe(true);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('dry-run shows pending message when not enabled', () => {
|
|
46
|
+
mockSpawn([
|
|
47
|
+
{ status: 0 }, // --version
|
|
48
|
+
{ status: 0, stdout: 'other-plugin' }, // plugins list
|
|
49
|
+
]);
|
|
50
|
+
const r = runHermesSetup({});
|
|
51
|
+
expect(r.exitCode).toBe(2);
|
|
52
|
+
expect(r.output.some((l) => l.includes('Dry-run'))).toBe(true);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('--print shows the command that would run', () => {
|
|
56
|
+
mockSpawn([
|
|
57
|
+
{ status: 0 }, // --version
|
|
58
|
+
{ status: 0, stdout: 'other-plugin' }, // plugins list
|
|
59
|
+
]);
|
|
60
|
+
const r = runHermesSetup({ print: true });
|
|
61
|
+
expect(r.exitCode).toBe(0);
|
|
62
|
+
expect(r.output.some((l) => l.includes('hermes plugins enable clawclaw'))).toBe(true);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('-y runs hermes plugins enable and succeeds', () => {
|
|
66
|
+
mockSpawn([
|
|
67
|
+
{ status: 0 }, // --version
|
|
68
|
+
{ status: 0, stdout: 'other-plugin' }, // plugins list
|
|
69
|
+
{ status: 0, stdout: 'plugin enabled' }, // plugins enable
|
|
70
|
+
]);
|
|
71
|
+
const r = runHermesSetup({ yes: true });
|
|
72
|
+
expect(r.exitCode).toBe(0);
|
|
73
|
+
expect(r.output.some((l) => l.includes('enabled'))).toBe(true);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('-y handles hermes plugins enable failure', () => {
|
|
77
|
+
mockSpawn([
|
|
78
|
+
{ status: 0 }, // --version
|
|
79
|
+
{ status: 0, stdout: 'other-plugin' }, // plugins list
|
|
80
|
+
{ status: 1, stderr: 'permission denied' }, // plugins enable
|
|
81
|
+
]);
|
|
82
|
+
const r = runHermesSetup({ yes: true });
|
|
83
|
+
expect(r.exitCode).toBe(1);
|
|
84
|
+
expect(r.output.some((l) => l.includes('Failed'))).toBe(true);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('already-enabled short-circuits --print', () => {
|
|
88
|
+
mockSpawn([
|
|
89
|
+
{ status: 0 }, // --version
|
|
90
|
+
{ status: 0, stdout: 'clawclaw' }, // plugins list
|
|
91
|
+
]);
|
|
92
|
+
const r = runHermesSetup({ print: true });
|
|
93
|
+
expect(r.exitCode).toBe(0);
|
|
94
|
+
expect(r.output.some((l) => l.includes('already enabled'))).toBe(true);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ccl setup hermes` — enable the clawclaw plugin in Hermes via `hermes plugins enable`.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { Command } from 'commander';
|
|
6
|
+
import { spawnSync } from 'child_process';
|
|
7
|
+
|
|
8
|
+
export const PLUGIN_ID = 'clawclaw';
|
|
9
|
+
|
|
10
|
+
export interface SetupHermesResult {
|
|
11
|
+
exitCode: number;
|
|
12
|
+
output: string[];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function runHermesSetup(flags: { yes?: boolean; print?: boolean }): SetupHermesResult {
|
|
16
|
+
const out: string[] = [];
|
|
17
|
+
|
|
18
|
+
// Check hermes is available
|
|
19
|
+
const which = spawnSync('hermes', ['--version'], { stdio: 'pipe', timeout: 5000 });
|
|
20
|
+
if (which.status !== 0) {
|
|
21
|
+
out.push('hermes CLI not found. Install it first, then re-run.');
|
|
22
|
+
return { exitCode: 1, output: out };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Check current plugin status
|
|
26
|
+
const list = spawnSync('hermes', ['plugins', 'list'], {
|
|
27
|
+
stdio: 'pipe',
|
|
28
|
+
timeout: 5000,
|
|
29
|
+
env: { ...process.env, HERMES_PLUGINS_DEBUG: '1' },
|
|
30
|
+
});
|
|
31
|
+
const listOutput = list.stdout?.toString() ?? '';
|
|
32
|
+
const alreadyEnabled = listOutput.includes(PLUGIN_ID) && !listOutput.includes(`${PLUGIN_ID} (disabled)`);
|
|
33
|
+
|
|
34
|
+
if (alreadyEnabled) {
|
|
35
|
+
out.push(`Plugin "${PLUGIN_ID}" is already enabled in Hermes.`);
|
|
36
|
+
return { exitCode: 0, output: out };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (flags.print) {
|
|
40
|
+
out.push(`# Will run: hermes plugins enable ${PLUGIN_ID}`);
|
|
41
|
+
return { exitCode: 0, output: out };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!flags.yes) {
|
|
45
|
+
out.push(`Pending: hermes plugins enable ${PLUGIN_ID}`);
|
|
46
|
+
out.push(``);
|
|
47
|
+
out.push(`Dry-run only. Re-run with -y to apply.`);
|
|
48
|
+
return { exitCode: 2, output: out };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const result = spawnSync('hermes', ['plugins', 'enable', PLUGIN_ID], {
|
|
52
|
+
stdio: 'pipe',
|
|
53
|
+
timeout: 10000,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
if (result.status !== 0) {
|
|
57
|
+
out.push(`Failed to enable plugin: ${result.stderr?.toString() ?? result.stdout?.toString() ?? 'unknown error'}`);
|
|
58
|
+
return { exitCode: 1, output: out };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
out.push(`Plugin "${PLUGIN_ID}" enabled in Hermes.`);
|
|
62
|
+
out.push(`Verify: HERMES_PLUGINS_DEBUG=1 hermes plugins list`);
|
|
63
|
+
return { exitCode: 0, output: out };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function createSetupHermesSubcommand(): Command {
|
|
67
|
+
return new Command('hermes')
|
|
68
|
+
.description('Enable the clawclaw plugin in Hermes via "hermes plugins enable".')
|
|
69
|
+
.option('-y, --yes', 'Apply changes (default is dry-run)')
|
|
70
|
+
.option('--print', 'Only print the command that would be run; do not execute')
|
|
71
|
+
.action((opts: { yes?: boolean; print?: boolean }) => {
|
|
72
|
+
const result = runHermesSetup({ yes: opts.yes, print: opts.print });
|
|
73
|
+
for (const line of result.output) console.log(line);
|
|
74
|
+
if (result.exitCode !== 0) process.exit(result.exitCode);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { createSetupOpenclawSubcommand } from './openclaw.js';
|
|
3
|
+
import { createSetupHermesSubcommand } from './hermes.js';
|
|
4
|
+
import { createSetupCodexSubcommand } from './codex.js';
|
|
5
|
+
|
|
6
|
+
export function createSetupCommand(): Command {
|
|
7
|
+
const setup = new Command('setup');
|
|
8
|
+
setup.description('Install recommended config snippets into agent host config files.');
|
|
9
|
+
setup.addCommand(createSetupOpenclawSubcommand());
|
|
10
|
+
setup.addCommand(createSetupHermesSubcommand());
|
|
11
|
+
setup.addCommand(createSetupCodexSubcommand());
|
|
12
|
+
return setup;
|
|
13
|
+
}
|