@myclaw163/clawclaw-cli 0.6.69 → 0.6.71
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/bin/clawclaw-cli.mjs +3 -3
- package/package.json +1 -1
- package/scripts/sync-bundled-skill.mjs +1 -1
- package/skills/clawclaw/references/STRATEGIES.md +5 -3
- package/src/commands/config.ts +30 -30
- package/src/commands/game.ts +8 -3
- package/src/commands/setup/hermes.test.ts +96 -96
- package/src/commands/setup/hermes.ts +76 -76
- package/src/commands/setup/index.ts +13 -13
- package/src/commands/setup/openclaw.test.ts +114 -114
- package/src/commands/setup/openclaw.ts +147 -147
- package/src/commands/strategy.test.ts +10 -0
- package/src/commands/strategy.ts +11 -10
- package/src/lib/host-config-patcher.test.ts +130 -130
- package/src/lib/host-config-patcher.ts +151 -151
- package/src/lib/hub-reminder.ts +19 -19
- package/src/strategies/avoid-lone.ts +1 -0
- package/src/strategies/avoid-players.ts +1 -0
- package/src/strategies/corpse-patrol.ts +1 -0
- package/src/strategies/crab-sabotage.ts +1 -0
- package/src/strategies/custom-module.test.ts +1 -0
- package/src/strategies/find-player.ts +1 -0
- package/src/strategies/hide.ts +1 -0
- package/src/strategies/kill-frenzy.ts +1 -0
- package/src/strategies/kill-lone.ts +1 -0
- package/src/strategies/kill-target.ts +1 -0
- package/src/strategies/loader.ts +9 -2
- package/src/strategies/lone-kill-task.ts +1 -0
- package/src/strategies/move-room.ts +1 -0
- package/src/strategies/paradise-fish.ts +1 -0
- package/src/strategies/patrol.ts +1 -0
- package/src/strategies/report-patrol.ts +1 -0
- package/src/strategies/shrimp-memory.ts +1 -0
- package/src/strategies/social-task.ts +1 -0
- package/src/strategies/task-kill-report.ts +1 -0
- package/src/strategies/task-only.ts +1 -0
- package/src/strategies/task-report.ts +1 -0
- package/src/strategies/types.ts +7 -0
- package/src/strategies/warrior-memory.ts +1 -0
|
@@ -1,114 +1,114 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { computeOpenclawPatch, resolveOpenclawConfigPath } from './openclaw.js';
|
|
3
|
-
|
|
4
|
-
describe('computeOpenclawPatch', () => {
|
|
5
|
-
it('on empty config creates plugins.allow, entries.enabled, tools.alsoAllow', () => {
|
|
6
|
-
const r = computeOpenclawPatch({}, {});
|
|
7
|
-
expect(r.warnings).toEqual([]);
|
|
8
|
-
expect(r.next).toEqual({
|
|
9
|
-
plugins: { allow: ['clawclaw'], entries: { clawclaw: { enabled: true } } },
|
|
10
|
-
tools: { alsoAllow: ['clawclaw'] },
|
|
11
|
-
});
|
|
12
|
-
expect(r.changes).toHaveLength(3);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('null/non-object current is treated as empty', () => {
|
|
16
|
-
const r1 = computeOpenclawPatch(null, {});
|
|
17
|
-
expect(r1.warnings).toEqual([]);
|
|
18
|
-
expect((r1.next as any).plugins.allow).toEqual(['clawclaw']);
|
|
19
|
-
const r2 = computeOpenclawPatch(['unexpected'], {});
|
|
20
|
-
expect(r2.warnings).toEqual([]);
|
|
21
|
-
expect((r2.next as any).plugins.allow).toEqual(['clawclaw']);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('no-op when everything already present', () => {
|
|
25
|
-
const current = {
|
|
26
|
-
plugins: { allow: ['clawclaw'], entries: { clawclaw: { enabled: true } } },
|
|
27
|
-
tools: { profile: 'coding', alsoAllow: ['clawclaw'] },
|
|
28
|
-
};
|
|
29
|
-
const r = computeOpenclawPatch(current, {});
|
|
30
|
-
expect(r.changes).toEqual([]);
|
|
31
|
-
expect(r.warnings).toEqual([]);
|
|
32
|
-
expect(r.next).toEqual(current);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('Set union into existing plugins.allow without dupes', () => {
|
|
36
|
-
const r = computeOpenclawPatch({ plugins: { allow: ['other'] } }, {});
|
|
37
|
-
expect((r.next as any).plugins.allow).toEqual(['other', 'clawclaw']);
|
|
38
|
-
expect(r.changes).toContain('add "clawclaw" to plugins.allow');
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('Set union into existing tools.alsoAllow without dupes', () => {
|
|
42
|
-
const r = computeOpenclawPatch({ tools: { profile: 'coding', alsoAllow: ['somethingElse'] } }, {});
|
|
43
|
-
expect((r.next as any).tools.alsoAllow).toEqual(['somethingElse', 'clawclaw']);
|
|
44
|
-
expect(r.changes).toContain('add "clawclaw" to tools.alsoAllow');
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('does not touch tools.profile, even when not coding', () => {
|
|
48
|
-
const r = computeOpenclawPatch({ tools: { profile: 'full' } }, {});
|
|
49
|
-
expect((r.next as any).tools.profile).toBe('full');
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('does not touch tools.profile when missing (no opinion-setting)', () => {
|
|
53
|
-
const r = computeOpenclawPatch({}, {});
|
|
54
|
-
expect((r.next as any).tools.profile).toBeUndefined();
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('warns and skips when plugins.allow is not an array', () => {
|
|
58
|
-
const r = computeOpenclawPatch({ plugins: { allow: 'oops' } }, {});
|
|
59
|
-
expect(r.warnings.some((w) => w.includes('plugins.allow'))).toBe(true);
|
|
60
|
-
// unchanged value
|
|
61
|
-
expect((r.next as any).plugins.allow).toBe('oops');
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('warns and skips when tools.alsoAllow is not an array', () => {
|
|
65
|
-
const r = computeOpenclawPatch({ tools: { alsoAllow: 'oops' } }, {});
|
|
66
|
-
expect(r.warnings.some((w) => w.includes('tools.alsoAllow'))).toBe(true);
|
|
67
|
-
expect((r.next as any).tools.alsoAllow).toBe('oops');
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('respects explicit enabled:false on entries.clawclaw', () => {
|
|
71
|
-
const r = computeOpenclawPatch(
|
|
72
|
-
{ plugins: { entries: { clawclaw: { enabled: false } } } },
|
|
73
|
-
{},
|
|
74
|
-
);
|
|
75
|
-
expect((r.next as any).plugins.entries.clawclaw.enabled).toBe(false);
|
|
76
|
-
expect(r.warnings.some((w) => w.includes('explicitly false'))).toBe(true);
|
|
77
|
-
// and we did not mark a change for it
|
|
78
|
-
expect(r.changes.some((c) => c.includes('enabled = true'))).toBe(false);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('--skip-plugins-allow leaves plugins untouched, still patches tools', () => {
|
|
82
|
-
const r = computeOpenclawPatch({}, { skipPluginsAllow: true });
|
|
83
|
-
expect((r.next as any).plugins).toBeUndefined();
|
|
84
|
-
expect((r.next as any).tools.alsoAllow).toEqual(['clawclaw']);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('--skip-tools-allow leaves tools untouched, still patches plugins', () => {
|
|
88
|
-
const r = computeOpenclawPatch({}, { skipToolsAllow: true });
|
|
89
|
-
expect((r.next as any).tools).toBeUndefined();
|
|
90
|
-
expect((r.next as any).plugins.allow).toEqual(['clawclaw']);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('preserves unrelated top-level keys', () => {
|
|
94
|
-
const r = computeOpenclawPatch(
|
|
95
|
-
{ models: { mode: 'replace' }, channels: { telegram: { enabled: true } } },
|
|
96
|
-
{},
|
|
97
|
-
);
|
|
98
|
-
expect((r.next as any).models).toEqual({ mode: 'replace' });
|
|
99
|
-
expect((r.next as any).channels).toEqual({ telegram: { enabled: true } });
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
describe('resolveOpenclawConfigPath', () => {
|
|
104
|
-
it('uses OPENCLAW_HOME when set', () => {
|
|
105
|
-
const p = resolveOpenclawConfigPath({ OPENCLAW_HOME: '/tmp/oc' });
|
|
106
|
-
expect(p.replace(/\\/g, '/')).toBe('/tmp/oc/openclaw.json');
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it('falls back to ~/.openclaw/openclaw.json', () => {
|
|
110
|
-
const p = resolveOpenclawConfigPath({});
|
|
111
|
-
expect(p.endsWith('openclaw.json')).toBe(true);
|
|
112
|
-
expect(p.includes('.openclaw')).toBe(true);
|
|
113
|
-
});
|
|
114
|
-
});
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { computeOpenclawPatch, resolveOpenclawConfigPath } from './openclaw.js';
|
|
3
|
+
|
|
4
|
+
describe('computeOpenclawPatch', () => {
|
|
5
|
+
it('on empty config creates plugins.allow, entries.enabled, tools.alsoAllow', () => {
|
|
6
|
+
const r = computeOpenclawPatch({}, {});
|
|
7
|
+
expect(r.warnings).toEqual([]);
|
|
8
|
+
expect(r.next).toEqual({
|
|
9
|
+
plugins: { allow: ['clawclaw'], entries: { clawclaw: { enabled: true } } },
|
|
10
|
+
tools: { alsoAllow: ['clawclaw'] },
|
|
11
|
+
});
|
|
12
|
+
expect(r.changes).toHaveLength(3);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('null/non-object current is treated as empty', () => {
|
|
16
|
+
const r1 = computeOpenclawPatch(null, {});
|
|
17
|
+
expect(r1.warnings).toEqual([]);
|
|
18
|
+
expect((r1.next as any).plugins.allow).toEqual(['clawclaw']);
|
|
19
|
+
const r2 = computeOpenclawPatch(['unexpected'], {});
|
|
20
|
+
expect(r2.warnings).toEqual([]);
|
|
21
|
+
expect((r2.next as any).plugins.allow).toEqual(['clawclaw']);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('no-op when everything already present', () => {
|
|
25
|
+
const current = {
|
|
26
|
+
plugins: { allow: ['clawclaw'], entries: { clawclaw: { enabled: true } } },
|
|
27
|
+
tools: { profile: 'coding', alsoAllow: ['clawclaw'] },
|
|
28
|
+
};
|
|
29
|
+
const r = computeOpenclawPatch(current, {});
|
|
30
|
+
expect(r.changes).toEqual([]);
|
|
31
|
+
expect(r.warnings).toEqual([]);
|
|
32
|
+
expect(r.next).toEqual(current);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('Set union into existing plugins.allow without dupes', () => {
|
|
36
|
+
const r = computeOpenclawPatch({ plugins: { allow: ['other'] } }, {});
|
|
37
|
+
expect((r.next as any).plugins.allow).toEqual(['other', 'clawclaw']);
|
|
38
|
+
expect(r.changes).toContain('add "clawclaw" to plugins.allow');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('Set union into existing tools.alsoAllow without dupes', () => {
|
|
42
|
+
const r = computeOpenclawPatch({ tools: { profile: 'coding', alsoAllow: ['somethingElse'] } }, {});
|
|
43
|
+
expect((r.next as any).tools.alsoAllow).toEqual(['somethingElse', 'clawclaw']);
|
|
44
|
+
expect(r.changes).toContain('add "clawclaw" to tools.alsoAllow');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('does not touch tools.profile, even when not coding', () => {
|
|
48
|
+
const r = computeOpenclawPatch({ tools: { profile: 'full' } }, {});
|
|
49
|
+
expect((r.next as any).tools.profile).toBe('full');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('does not touch tools.profile when missing (no opinion-setting)', () => {
|
|
53
|
+
const r = computeOpenclawPatch({}, {});
|
|
54
|
+
expect((r.next as any).tools.profile).toBeUndefined();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('warns and skips when plugins.allow is not an array', () => {
|
|
58
|
+
const r = computeOpenclawPatch({ plugins: { allow: 'oops' } }, {});
|
|
59
|
+
expect(r.warnings.some((w) => w.includes('plugins.allow'))).toBe(true);
|
|
60
|
+
// unchanged value
|
|
61
|
+
expect((r.next as any).plugins.allow).toBe('oops');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('warns and skips when tools.alsoAllow is not an array', () => {
|
|
65
|
+
const r = computeOpenclawPatch({ tools: { alsoAllow: 'oops' } }, {});
|
|
66
|
+
expect(r.warnings.some((w) => w.includes('tools.alsoAllow'))).toBe(true);
|
|
67
|
+
expect((r.next as any).tools.alsoAllow).toBe('oops');
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('respects explicit enabled:false on entries.clawclaw', () => {
|
|
71
|
+
const r = computeOpenclawPatch(
|
|
72
|
+
{ plugins: { entries: { clawclaw: { enabled: false } } } },
|
|
73
|
+
{},
|
|
74
|
+
);
|
|
75
|
+
expect((r.next as any).plugins.entries.clawclaw.enabled).toBe(false);
|
|
76
|
+
expect(r.warnings.some((w) => w.includes('explicitly false'))).toBe(true);
|
|
77
|
+
// and we did not mark a change for it
|
|
78
|
+
expect(r.changes.some((c) => c.includes('enabled = true'))).toBe(false);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('--skip-plugins-allow leaves plugins untouched, still patches tools', () => {
|
|
82
|
+
const r = computeOpenclawPatch({}, { skipPluginsAllow: true });
|
|
83
|
+
expect((r.next as any).plugins).toBeUndefined();
|
|
84
|
+
expect((r.next as any).tools.alsoAllow).toEqual(['clawclaw']);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('--skip-tools-allow leaves tools untouched, still patches plugins', () => {
|
|
88
|
+
const r = computeOpenclawPatch({}, { skipToolsAllow: true });
|
|
89
|
+
expect((r.next as any).tools).toBeUndefined();
|
|
90
|
+
expect((r.next as any).plugins.allow).toEqual(['clawclaw']);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('preserves unrelated top-level keys', () => {
|
|
94
|
+
const r = computeOpenclawPatch(
|
|
95
|
+
{ models: { mode: 'replace' }, channels: { telegram: { enabled: true } } },
|
|
96
|
+
{},
|
|
97
|
+
);
|
|
98
|
+
expect((r.next as any).models).toEqual({ mode: 'replace' });
|
|
99
|
+
expect((r.next as any).channels).toEqual({ telegram: { enabled: true } });
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe('resolveOpenclawConfigPath', () => {
|
|
104
|
+
it('uses OPENCLAW_HOME when set', () => {
|
|
105
|
+
const p = resolveOpenclawConfigPath({ OPENCLAW_HOME: '/tmp/oc' });
|
|
106
|
+
expect(p.replace(/\\/g, '/')).toBe('/tmp/oc/openclaw.json');
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('falls back to ~/.openclaw/openclaw.json', () => {
|
|
110
|
+
const p = resolveOpenclawConfigPath({});
|
|
111
|
+
expect(p.endsWith('openclaw.json')).toBe(true);
|
|
112
|
+
expect(p.includes('.openclaw')).toBe(true);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
@@ -1,147 +1,147 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `ccl setup openclaw` — install recommended OpenClaw config snippet.
|
|
3
|
-
*
|
|
4
|
-
* Pure function `computeOpenclawPatch` is exported for tests.
|
|
5
|
-
* IO / diff / atomic write / backup is delegated to lib/host-config-patcher.ts.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { Command } from 'commander';
|
|
9
|
-
import { homedir } from 'os';
|
|
10
|
-
import { join } from 'path';
|
|
11
|
-
import {
|
|
12
|
-
runHostConfigSetup,
|
|
13
|
-
unionArrayField,
|
|
14
|
-
type HostPatchResult,
|
|
15
|
-
} from '../../lib/host-config-patcher.js';
|
|
16
|
-
|
|
17
|
-
export const PLUGIN_ID = 'clawclaw';
|
|
18
|
-
|
|
19
|
-
export interface ComputeOpenclawPatchOpts {
|
|
20
|
-
skipPluginsAllow?: boolean;
|
|
21
|
-
skipToolsAllow?: boolean;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function resolveOpenclawConfigPath(env: NodeJS.ProcessEnv = process.env): string {
|
|
25
|
-
const home = env.OPENCLAW_HOME?.trim();
|
|
26
|
-
if (home) return join(home, 'openclaw.json');
|
|
27
|
-
return join(homedir(), '.openclaw', 'openclaw.json');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** Pure: compute the minimal additive patch to make `clawclaw` work under `coding` profile. */
|
|
31
|
-
export function computeOpenclawPatch(current: unknown, opts: ComputeOpenclawPatchOpts): HostPatchResult {
|
|
32
|
-
const changes: string[] = [];
|
|
33
|
-
const warnings: string[] = [];
|
|
34
|
-
const cfg: Record<string, unknown> =
|
|
35
|
-
current !== null && typeof current === 'object' && !Array.isArray(current)
|
|
36
|
-
? { ...(current as Record<string, unknown>) }
|
|
37
|
-
: {};
|
|
38
|
-
|
|
39
|
-
// ── plugins.allow + plugins.entries.clawclaw.enabled ──────────────────
|
|
40
|
-
if (!opts.skipPluginsAllow) {
|
|
41
|
-
const plugins: Record<string, unknown> =
|
|
42
|
-
cfg.plugins !== null && typeof cfg.plugins === 'object' && !Array.isArray(cfg.plugins)
|
|
43
|
-
? { ...(cfg.plugins as Record<string, unknown>) }
|
|
44
|
-
: {};
|
|
45
|
-
|
|
46
|
-
const allowResult = unionArrayField(plugins.allow, PLUGIN_ID);
|
|
47
|
-
if ('warning' in allowResult) {
|
|
48
|
-
warnings.push(`plugins.allow ${allowResult.warning}`);
|
|
49
|
-
} else {
|
|
50
|
-
if (allowResult.added) {
|
|
51
|
-
if (plugins.allow === undefined) {
|
|
52
|
-
changes.push(`create plugins.allow with ["${PLUGIN_ID}"]`);
|
|
53
|
-
} else {
|
|
54
|
-
changes.push(`add "${PLUGIN_ID}" to plugins.allow`);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
plugins.allow = allowResult.next;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const entries: Record<string, unknown> =
|
|
61
|
-
plugins.entries !== null && typeof plugins.entries === 'object' && !Array.isArray(plugins.entries)
|
|
62
|
-
? { ...(plugins.entries as Record<string, unknown>) }
|
|
63
|
-
: {};
|
|
64
|
-
const existingEntry =
|
|
65
|
-
entries[PLUGIN_ID] !== null && typeof entries[PLUGIN_ID] === 'object' && !Array.isArray(entries[PLUGIN_ID])
|
|
66
|
-
? { ...(entries[PLUGIN_ID] as Record<string, unknown>) }
|
|
67
|
-
: {};
|
|
68
|
-
|
|
69
|
-
if (existingEntry.enabled === false) {
|
|
70
|
-
warnings.push(
|
|
71
|
-
`plugins.entries.${PLUGIN_ID}.enabled is explicitly false; not flipping it on. Remove the line manually if you want it enabled.`,
|
|
72
|
-
);
|
|
73
|
-
} else if (existingEntry.enabled !== true) {
|
|
74
|
-
existingEntry.enabled = true;
|
|
75
|
-
entries[PLUGIN_ID] = existingEntry;
|
|
76
|
-
plugins.entries = entries;
|
|
77
|
-
changes.push(`set plugins.entries.${PLUGIN_ID}.enabled = true (equivalent to: openclaw plugins enable ${PLUGIN_ID})`);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
cfg.plugins = plugins;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// ── tools.alsoAllow ────────────────────────────────────────────────────
|
|
84
|
-
if (!opts.skipToolsAllow) {
|
|
85
|
-
const tools: Record<string, unknown> =
|
|
86
|
-
cfg.tools !== null && typeof cfg.tools === 'object' && !Array.isArray(cfg.tools)
|
|
87
|
-
? { ...(cfg.tools as Record<string, unknown>) }
|
|
88
|
-
: {};
|
|
89
|
-
|
|
90
|
-
const alsoAllowResult = unionArrayField(tools.alsoAllow, PLUGIN_ID);
|
|
91
|
-
if ('warning' in alsoAllowResult) {
|
|
92
|
-
warnings.push(`tools.alsoAllow ${alsoAllowResult.warning}`);
|
|
93
|
-
} else {
|
|
94
|
-
if (alsoAllowResult.added) {
|
|
95
|
-
if (tools.alsoAllow === undefined) {
|
|
96
|
-
changes.push(`create tools.alsoAllow with ["${PLUGIN_ID}"]`);
|
|
97
|
-
} else {
|
|
98
|
-
changes.push(`add "${PLUGIN_ID}" to tools.alsoAllow`);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
tools.alsoAllow = alsoAllowResult.next;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
cfg.tools = tools;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return { next: cfg, changes, warnings };
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export function createSetupOpenclawSubcommand(): Command {
|
|
111
|
-
return new Command('openclaw')
|
|
112
|
-
.description('Install recommended OpenClaw config (plugins.allow + tools.alsoAllow) for the clawclaw plugin.')
|
|
113
|
-
.option('-y, --yes', 'Apply changes (default is dry-run with diff preview)')
|
|
114
|
-
.option('--print', 'Only print the recommended JSON patch; do not read or write files')
|
|
115
|
-
.option('--config <path>', 'Override openclaw.json path (default: $OPENCLAW_HOME/openclaw.json or ~/.openclaw/openclaw.json)')
|
|
116
|
-
.option('--skip-plugins-allow', "Do not touch plugins.allow / plugins.entries.clawclaw")
|
|
117
|
-
.option('--skip-tools-allow', "Do not touch tools.alsoAllow")
|
|
118
|
-
.option('--no-backup', 'Do not write a timestamped .bak.* before applying')
|
|
119
|
-
.action((opts: {
|
|
120
|
-
yes?: boolean;
|
|
121
|
-
print?: boolean;
|
|
122
|
-
config?: string;
|
|
123
|
-
skipPluginsAllow?: boolean;
|
|
124
|
-
skipToolsAllow?: boolean;
|
|
125
|
-
backup?: boolean;
|
|
126
|
-
}) => {
|
|
127
|
-
const result = runHostConfigSetup(
|
|
128
|
-
{
|
|
129
|
-
hostName: 'OpenClaw',
|
|
130
|
-
resolveConfigPath: () => resolveOpenclawConfigPath(),
|
|
131
|
-
computePatch: (current, hostOpts) => computeOpenclawPatch(current, hostOpts),
|
|
132
|
-
},
|
|
133
|
-
{
|
|
134
|
-
skipPluginsAllow: opts.skipPluginsAllow,
|
|
135
|
-
skipToolsAllow: opts.skipToolsAllow,
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
yes: opts.yes,
|
|
139
|
-
print: opts.print,
|
|
140
|
-
configPath: opts.config,
|
|
141
|
-
backup: opts.backup,
|
|
142
|
-
},
|
|
143
|
-
);
|
|
144
|
-
for (const line of result.output) console.log(line);
|
|
145
|
-
if (result.exitCode !== 0) process.exit(result.exitCode);
|
|
146
|
-
});
|
|
147
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* `ccl setup openclaw` — install recommended OpenClaw config snippet.
|
|
3
|
+
*
|
|
4
|
+
* Pure function `computeOpenclawPatch` is exported for tests.
|
|
5
|
+
* IO / diff / atomic write / backup is delegated to lib/host-config-patcher.ts.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { Command } from 'commander';
|
|
9
|
+
import { homedir } from 'os';
|
|
10
|
+
import { join } from 'path';
|
|
11
|
+
import {
|
|
12
|
+
runHostConfigSetup,
|
|
13
|
+
unionArrayField,
|
|
14
|
+
type HostPatchResult,
|
|
15
|
+
} from '../../lib/host-config-patcher.js';
|
|
16
|
+
|
|
17
|
+
export const PLUGIN_ID = 'clawclaw';
|
|
18
|
+
|
|
19
|
+
export interface ComputeOpenclawPatchOpts {
|
|
20
|
+
skipPluginsAllow?: boolean;
|
|
21
|
+
skipToolsAllow?: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function resolveOpenclawConfigPath(env: NodeJS.ProcessEnv = process.env): string {
|
|
25
|
+
const home = env.OPENCLAW_HOME?.trim();
|
|
26
|
+
if (home) return join(home, 'openclaw.json');
|
|
27
|
+
return join(homedir(), '.openclaw', 'openclaw.json');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Pure: compute the minimal additive patch to make `clawclaw` work under `coding` profile. */
|
|
31
|
+
export function computeOpenclawPatch(current: unknown, opts: ComputeOpenclawPatchOpts): HostPatchResult {
|
|
32
|
+
const changes: string[] = [];
|
|
33
|
+
const warnings: string[] = [];
|
|
34
|
+
const cfg: Record<string, unknown> =
|
|
35
|
+
current !== null && typeof current === 'object' && !Array.isArray(current)
|
|
36
|
+
? { ...(current as Record<string, unknown>) }
|
|
37
|
+
: {};
|
|
38
|
+
|
|
39
|
+
// ── plugins.allow + plugins.entries.clawclaw.enabled ──────────────────
|
|
40
|
+
if (!opts.skipPluginsAllow) {
|
|
41
|
+
const plugins: Record<string, unknown> =
|
|
42
|
+
cfg.plugins !== null && typeof cfg.plugins === 'object' && !Array.isArray(cfg.plugins)
|
|
43
|
+
? { ...(cfg.plugins as Record<string, unknown>) }
|
|
44
|
+
: {};
|
|
45
|
+
|
|
46
|
+
const allowResult = unionArrayField(plugins.allow, PLUGIN_ID);
|
|
47
|
+
if ('warning' in allowResult) {
|
|
48
|
+
warnings.push(`plugins.allow ${allowResult.warning}`);
|
|
49
|
+
} else {
|
|
50
|
+
if (allowResult.added) {
|
|
51
|
+
if (plugins.allow === undefined) {
|
|
52
|
+
changes.push(`create plugins.allow with ["${PLUGIN_ID}"]`);
|
|
53
|
+
} else {
|
|
54
|
+
changes.push(`add "${PLUGIN_ID}" to plugins.allow`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
plugins.allow = allowResult.next;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const entries: Record<string, unknown> =
|
|
61
|
+
plugins.entries !== null && typeof plugins.entries === 'object' && !Array.isArray(plugins.entries)
|
|
62
|
+
? { ...(plugins.entries as Record<string, unknown>) }
|
|
63
|
+
: {};
|
|
64
|
+
const existingEntry =
|
|
65
|
+
entries[PLUGIN_ID] !== null && typeof entries[PLUGIN_ID] === 'object' && !Array.isArray(entries[PLUGIN_ID])
|
|
66
|
+
? { ...(entries[PLUGIN_ID] as Record<string, unknown>) }
|
|
67
|
+
: {};
|
|
68
|
+
|
|
69
|
+
if (existingEntry.enabled === false) {
|
|
70
|
+
warnings.push(
|
|
71
|
+
`plugins.entries.${PLUGIN_ID}.enabled is explicitly false; not flipping it on. Remove the line manually if you want it enabled.`,
|
|
72
|
+
);
|
|
73
|
+
} else if (existingEntry.enabled !== true) {
|
|
74
|
+
existingEntry.enabled = true;
|
|
75
|
+
entries[PLUGIN_ID] = existingEntry;
|
|
76
|
+
plugins.entries = entries;
|
|
77
|
+
changes.push(`set plugins.entries.${PLUGIN_ID}.enabled = true (equivalent to: openclaw plugins enable ${PLUGIN_ID})`);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
cfg.plugins = plugins;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// ── tools.alsoAllow ────────────────────────────────────────────────────
|
|
84
|
+
if (!opts.skipToolsAllow) {
|
|
85
|
+
const tools: Record<string, unknown> =
|
|
86
|
+
cfg.tools !== null && typeof cfg.tools === 'object' && !Array.isArray(cfg.tools)
|
|
87
|
+
? { ...(cfg.tools as Record<string, unknown>) }
|
|
88
|
+
: {};
|
|
89
|
+
|
|
90
|
+
const alsoAllowResult = unionArrayField(tools.alsoAllow, PLUGIN_ID);
|
|
91
|
+
if ('warning' in alsoAllowResult) {
|
|
92
|
+
warnings.push(`tools.alsoAllow ${alsoAllowResult.warning}`);
|
|
93
|
+
} else {
|
|
94
|
+
if (alsoAllowResult.added) {
|
|
95
|
+
if (tools.alsoAllow === undefined) {
|
|
96
|
+
changes.push(`create tools.alsoAllow with ["${PLUGIN_ID}"]`);
|
|
97
|
+
} else {
|
|
98
|
+
changes.push(`add "${PLUGIN_ID}" to tools.alsoAllow`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
tools.alsoAllow = alsoAllowResult.next;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
cfg.tools = tools;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return { next: cfg, changes, warnings };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function createSetupOpenclawSubcommand(): Command {
|
|
111
|
+
return new Command('openclaw')
|
|
112
|
+
.description('Install recommended OpenClaw config (plugins.allow + tools.alsoAllow) for the clawclaw plugin.')
|
|
113
|
+
.option('-y, --yes', 'Apply changes (default is dry-run with diff preview)')
|
|
114
|
+
.option('--print', 'Only print the recommended JSON patch; do not read or write files')
|
|
115
|
+
.option('--config <path>', 'Override openclaw.json path (default: $OPENCLAW_HOME/openclaw.json or ~/.openclaw/openclaw.json)')
|
|
116
|
+
.option('--skip-plugins-allow', "Do not touch plugins.allow / plugins.entries.clawclaw")
|
|
117
|
+
.option('--skip-tools-allow', "Do not touch tools.alsoAllow")
|
|
118
|
+
.option('--no-backup', 'Do not write a timestamped .bak.* before applying')
|
|
119
|
+
.action((opts: {
|
|
120
|
+
yes?: boolean;
|
|
121
|
+
print?: boolean;
|
|
122
|
+
config?: string;
|
|
123
|
+
skipPluginsAllow?: boolean;
|
|
124
|
+
skipToolsAllow?: boolean;
|
|
125
|
+
backup?: boolean;
|
|
126
|
+
}) => {
|
|
127
|
+
const result = runHostConfigSetup(
|
|
128
|
+
{
|
|
129
|
+
hostName: 'OpenClaw',
|
|
130
|
+
resolveConfigPath: () => resolveOpenclawConfigPath(),
|
|
131
|
+
computePatch: (current, hostOpts) => computeOpenclawPatch(current, hostOpts),
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
skipPluginsAllow: opts.skipPluginsAllow,
|
|
135
|
+
skipToolsAllow: opts.skipToolsAllow,
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
yes: opts.yes,
|
|
139
|
+
print: opts.print,
|
|
140
|
+
configPath: opts.config,
|
|
141
|
+
backup: opts.backup,
|
|
142
|
+
},
|
|
143
|
+
);
|
|
144
|
+
for (const line of result.output) console.log(line);
|
|
145
|
+
if (result.exitCode !== 0) process.exit(result.exitCode);
|
|
146
|
+
});
|
|
147
|
+
}
|
|
@@ -109,6 +109,15 @@ describe('strategy command', () => {
|
|
|
109
109
|
// knowledge might be null if no .knowledge.md file exists
|
|
110
110
|
});
|
|
111
111
|
|
|
112
|
+
it('should resolve a Chinese name and show its knowledge contract', async () => {
|
|
113
|
+
await run(['--info', '武士虾']);
|
|
114
|
+
|
|
115
|
+
const output = JSON.parse(logs[0]);
|
|
116
|
+
expect(output.id).toBe('warrior-memory');
|
|
117
|
+
expect(output.name).toBe('武士虾');
|
|
118
|
+
expect(output.knowledge).toContain('warrior-memory');
|
|
119
|
+
});
|
|
120
|
+
|
|
112
121
|
it('should reject non-existent strategies', async () => {
|
|
113
122
|
await expect(run(['--info', 'non-existent'])).rejects.toThrow('process.exit');
|
|
114
123
|
|
|
@@ -129,6 +138,7 @@ describe('strategy command', () => {
|
|
|
129
138
|
// Check that task-only is in the list
|
|
130
139
|
const taskOnly = output.strategies.find((s: any) => s.id === 'task-only');
|
|
131
140
|
expect(taskOnly).toBeDefined();
|
|
141
|
+
expect(taskOnly.name).toBe('纯任务');
|
|
132
142
|
expect(taskOnly.description).toBeDefined();
|
|
133
143
|
});
|
|
134
144
|
});
|
package/src/commands/strategy.ts
CHANGED
|
@@ -31,7 +31,7 @@ export function createStrategyCommand(): Command {
|
|
|
31
31
|
Custom strategies:
|
|
32
32
|
Place .ts or .js files in ${strategiesDir}
|
|
33
33
|
(or $CLAWCLAW_WORKSPACE_DIR/strategies/)
|
|
34
|
-
Each file must export a 'strategy' object with id, description, and create() function.
|
|
34
|
+
Each file must export a 'strategy' object with id, name (中文别名), description, and create() function.
|
|
35
35
|
Use 'import { ... } from "@myclaw163/clawclaw-cli"' to access Action, GameState, and utilities.
|
|
36
36
|
See docs/自定义策略.md for full API reference and examples.
|
|
37
37
|
`;
|
|
@@ -49,8 +49,8 @@ Custom strategies:
|
|
|
49
49
|
}, null, 2));
|
|
50
50
|
process.exit(1);
|
|
51
51
|
}
|
|
52
|
-
const knowledge = await getStrategyKnowledgeDoc(
|
|
53
|
-
console.log(JSON.stringify({ id:
|
|
52
|
+
const knowledge = await getStrategyKnowledgeDoc(entry.id);
|
|
53
|
+
console.log(JSON.stringify({ id: entry.id, name: entry.name ?? entry.id, description: entry.description, knowledge: knowledge ?? null }, null, 2));
|
|
54
54
|
return;
|
|
55
55
|
}
|
|
56
56
|
|
|
@@ -87,7 +87,7 @@ Custom strategies:
|
|
|
87
87
|
return;
|
|
88
88
|
}
|
|
89
89
|
console.log(JSON.stringify({
|
|
90
|
-
strategies: entries.map(e => ({ id: e.id, description: e.description })),
|
|
90
|
+
strategies: entries.map(e => ({ id: e.id, name: e.name ?? e.id, description: e.description })),
|
|
91
91
|
}, null, 2));
|
|
92
92
|
return;
|
|
93
93
|
}
|
|
@@ -120,7 +120,7 @@ Custom strategies:
|
|
|
120
120
|
console.error(JSON.stringify({
|
|
121
121
|
error: 'unknown_strategy',
|
|
122
122
|
message: `Unknown strategy '${name}'.`,
|
|
123
|
-
available: available.map(e => ({ id: e.id, description: e.description })),
|
|
123
|
+
available: available.map(e => ({ id: e.id, name: e.name ?? e.id, description: e.description })),
|
|
124
124
|
}, null, 2));
|
|
125
125
|
process.exit(1);
|
|
126
126
|
}
|
|
@@ -136,7 +136,7 @@ Custom strategies:
|
|
|
136
136
|
process.exit(1);
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
if (KILL_STRATEGIES.has(
|
|
139
|
+
if (KILL_STRATEGIES.has(entry.id)) {
|
|
140
140
|
try {
|
|
141
141
|
const client = GameClient.fromAuth();
|
|
142
142
|
await client.discoverGameServer();
|
|
@@ -146,8 +146,8 @@ Custom strategies:
|
|
|
146
146
|
if (role && !KILL_CAPABLE_ROLES.has(role)) {
|
|
147
147
|
console.error(JSON.stringify({
|
|
148
148
|
error: 'role_incompatible',
|
|
149
|
-
message: `Strategy '${
|
|
150
|
-
strategy:
|
|
149
|
+
message: `Strategy '${entry.id}' requires kill ability, but your role '${displayName}' (${role}) cannot kill. Use a non-kill strategy like task-report, patrol, or report-patrol.`,
|
|
150
|
+
strategy: entry.id,
|
|
151
151
|
role,
|
|
152
152
|
}, null, 2));
|
|
153
153
|
process.exit(1);
|
|
@@ -158,7 +158,7 @@ Custom strategies:
|
|
|
158
158
|
const profile = new AuthStore().getActive();
|
|
159
159
|
const response = profile
|
|
160
160
|
? await sendOwnerControlRequest(getProfileStateDir(profile), 'switch_strategy', {
|
|
161
|
-
strategy:
|
|
161
|
+
strategy: entry.id,
|
|
162
162
|
args: args.length > 0 ? args : undefined,
|
|
163
163
|
})
|
|
164
164
|
: null;
|
|
@@ -170,7 +170,8 @@ Custom strategies:
|
|
|
170
170
|
process.exit(1);
|
|
171
171
|
}
|
|
172
172
|
console.log(JSON.stringify({
|
|
173
|
-
message: `Strategy started: ${
|
|
173
|
+
message: `Strategy started: ${entry.id}`,
|
|
174
|
+
name: entry.name ?? entry.id,
|
|
174
175
|
description: entry.description,
|
|
175
176
|
pid: response.pid,
|
|
176
177
|
}, null, 2));
|