@myclaw163/clawclaw-cli 0.6.65 → 0.6.67

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.
@@ -1,13 +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
- }
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
+ }
@@ -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
+ }