Skip to content

Commit e9b3252

Browse files
authored
feat(claws): separate portable and OpenClaw profiles (#112773)
* feat(claws): add portable agent policy settings * fix(claws): align portable agent policy * fix(claws): preserve host policy boundaries * feat(claws): separate portable and OpenClaw profiles * test(claws): align profile fixtures with portable schema * fix(claws): align portable profile boundaries
1 parent 1564c07 commit e9b3252

24 files changed

Lines changed: 1315 additions & 192 deletions

‎docs/cli/claws.md‎

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ title: "Claws"
1010
# `openclaw claws`
1111

1212
A Claw is a versioned setup for one new OpenClaw agent. It can describe the
13-
agent configuration, workspace files, skills, plugins, MCP servers, and cron
14-
jobs that agent needs. A Claw does not replace or modify an existing agent.
13+
agent's portable identity, workspace files, skills, plugins, MCP servers, and
14+
cron jobs. Harness-specific agent settings may be carried in a referenced
15+
package profile. A Claw does not replace or modify an existing agent.
1516

1617
Claws are experimental. Their schema, command output, and lifecycle may change.
1718
Enable the command surface explicitly:
@@ -26,8 +27,8 @@ separate registry track and are not part of this command surface yet.
2627

2728
## Create a Claw package
2829

29-
A package contains `package.json`, a `CLAW.md` manifest, and any workspace
30-
sidecars referenced by the manifest:
30+
A package contains `package.json`, a `CLAW.md` manifest, and any profiles or
31+
workspace sidecars referenced by that manifest:
3132

3233
```json
3334
{
@@ -47,8 +48,8 @@ schemaVersion: 1
4748
agent:
4849
id: incident-triage
4950
name: Incident triage
50-
tools:
51-
deny: [exec]
51+
metadata:
52+
openclaw.config: profiles/openclaw.yml
5253
workspace:
5354
bootstrapFiles: {}
5455
packages: []
@@ -61,9 +62,50 @@ cronJobs: []
6162
Creates one agent for reviewing and routing incidents.
6263
```
6364

65+
`metadata` is a string-to-string map for portable consumer hints. OpenClaw's
66+
`openclaw.config` key points to an optional, package-relative YAML profile. The
67+
exported default is `profiles/openclaw.yml`; the pointer is normative, so a
68+
package may choose another safe relative `.yml` or `.yaml` path.
69+
70+
```yaml
71+
schemaVersion: 1
72+
agent:
73+
tools:
74+
profile: coding
75+
alsoAllow: [cron]
76+
deny: [exec]
77+
fs:
78+
workspaceOnly: true
79+
memory:
80+
search:
81+
enabled: true
82+
rememberAcrossConversations: true
83+
sources: [memory, sessions]
84+
```
85+
86+
This profile exists only inside the Claw package. OpenClaw validates and uses it
87+
while inspecting, adding, updating, and exporting that Claw; it is not copied
88+
to the user's normal OpenClaw configuration path. Other harnesses can ignore
89+
the namespaced metadata key and consume the portable manifest fields.
90+
6491
The same strict version 1 schema continues to accept grouped JSON manifests.
65-
The remaining schema fragments on this page use JSON, with equivalent keys
66-
available in `CLAW.md` frontmatter.
92+
Grouped JSON uses the same `metadata.openclaw.config` pointer rather than
93+
embedding a second copy of the OpenClaw profile. The remaining schema fragments
94+
on this page use JSON, with equivalent keys available in `CLAW.md` frontmatter.
95+
96+
The OpenClaw package profile may select any built-in tool profile registered by
97+
the running OpenClaw version, then refine it with `alsoAllow`, `deny`, and
98+
`tools.fs.workspaceOnly: true`. A Claw cannot set that field to `false` and
99+
weaken host filesystem confinement. `tools.allow` remains available as an
100+
explicit allowlist but cannot be combined with `alsoAllow`. A Claw may also set
101+
`memory.search.enabled`, choose the portable `memory` and `sessions` sources,
102+
and opt into cross-conversation memory with `rememberAcrossConversations`.
103+
Declaring the `sessions` source requires that opt-in.
104+
Host policy still constrains these settings, and Claws do not carry custom
105+
profile definitions, providers, credentials, bindings, or local memory paths.
106+
The referenced profile is limited to 256 KiB, must be JSON-compatible YAML, may
107+
not use aliases, anchors, tags, or merge keys, and must be a regular,
108+
non-symlinked, non-hardlinked file inside the package.
67109

68110
Package and workspace paths must remain inside the package root. Manifests are
69111
limited to 1 MiB, package metadata to 256 KiB, and workspace sources enforce

‎src/claws/export.test.ts‎

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { buildClawAddPlan } from "./lifecycle.js";
1111
import { installClawMcpServers } from "./mcp.js";
1212
import { persistClawPackageRef, updateClawInstallRecordStatus } from "./provenance.js";
1313
import { parseClawManifest } from "./schema.js";
14-
import type { ClawSourceIdentity } from "./types.js";
14+
import type { ClawOpenClawProfile, ClawSourceIdentity } from "./types.js";
1515

1616
const tempDirs = useAutoCleanupTempDirTracker(afterEach);
1717

@@ -42,8 +42,8 @@ async function installedFixture(
4242
id: "worker",
4343
name: "Worker",
4444
...(options.avatar ? { identity: { avatar: options.avatar } } : {}),
45-
tools: { deny: ["exec"] },
4645
},
46+
metadata: { "openclaw.config": "profiles/openclaw.yml" },
4747
workspace: {
4848
bootstrapFiles: { "SOUL.md": { source: "source/SOUL.md" } },
4949
files: [
@@ -75,6 +75,24 @@ async function installedFixture(
7575
if (!parsed.ok) {
7676
throw new Error(JSON.stringify(parsed.diagnostics));
7777
}
78+
const openClawProfile: ClawOpenClawProfile = {
79+
schemaVersion: 1,
80+
agent: {
81+
tools: {
82+
profile: "coding",
83+
alsoAllow: ["cron"],
84+
deny: ["exec"],
85+
fs: { workspaceOnly: true },
86+
},
87+
memory: {
88+
search: {
89+
enabled: true,
90+
rememberAcrossConversations: true,
91+
sources: ["memory", "sessions"],
92+
},
93+
},
94+
},
95+
};
7896
const source: ClawSourceIdentity = {
7997
kind: "package",
8098
name: "@acme/worker",
@@ -88,6 +106,7 @@ async function installedFixture(
88106
const plan = await buildClawAddPlan({
89107
manifest: parsed.manifest,
90108
source,
109+
openClawProfile,
91110
context: { workspace: join(root, "workspace-worker") },
92111
});
93112
let config: OpenClawConfig = {};
@@ -148,6 +167,17 @@ async function installedFixture(
148167
describe("exportClawAgent", () => {
149168
it("writes a grouped package from one installed agent", async () => {
150169
const fixture = await installedFixture({ withPackage: true });
170+
expect(fixture.plan.agent.config.memory?.search).toEqual({
171+
enabled: true,
172+
rememberAcrossConversations: true,
173+
sources: ["memory", "sessions"],
174+
});
175+
expect(fixture.config.agents?.entries?.worker?.memory?.search).toEqual({
176+
enabled: true,
177+
rememberAcrossConversations: true,
178+
sources: ["memory", "sessions"],
179+
});
180+
expect(fixture.config.agents?.entries?.worker).not.toHaveProperty("memorySearch");
151181
fixture.config.mcp!.servers!.docs!.env = {
152182
DOCS_TOKEN: "resolved-secret-must-not-be-exported",
153183
};
@@ -166,7 +196,8 @@ describe("exportClawAgent", () => {
166196
agentId: "worker",
167197
manifest: {
168198
schemaVersion: 1,
169-
agent: { id: "worker", name: "Worker", tools: { deny: ["exec"] } },
199+
agent: { id: "worker", name: "Worker" },
200+
metadata: { "openclaw.config": "profiles/openclaw.yml" },
170201
workspace: {
171202
bootstrapFiles: { "SOUL.md": { source: "workspace/SOUL.md" } },
172203
files: [{ source: "workspace/reference/policy.md", path: "reference/policy.md" }],
@@ -200,6 +231,24 @@ describe("exportClawAgent", () => {
200231
},
201232
],
202233
},
234+
openClawProfile: {
235+
schemaVersion: 1,
236+
agent: {
237+
tools: {
238+
profile: "coding",
239+
alsoAllow: ["cron"],
240+
deny: ["exec"],
241+
fs: { workspaceOnly: true },
242+
},
243+
memory: {
244+
search: {
245+
enabled: true,
246+
rememberAcrossConversations: true,
247+
sources: ["memory", "sessions"],
248+
},
249+
},
250+
},
251+
},
203252
});
204253
const packageJson = JSON.parse(await readFile(join(out, "package.json"), "utf8"));
205254
expect(packageJson).toMatchObject({
@@ -210,6 +259,9 @@ describe("exportClawAgent", () => {
210259
await expect(readFile(join(out, "CLAW.md"), "utf8")).resolves.not.toContain(
211260
"resolved-secret-must-not-be-exported",
212261
);
262+
await expect(readFile(join(out, "profiles", "openclaw.yml"), "utf8")).resolves.toContain(
263+
"profile: coding",
264+
);
213265
await expect(readFile(join(out, "workspace", "SOUL.md"), "utf8")).resolves.toBe(
214266
"managed soul\n",
215267
);

‎src/claws/export.ts‎

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ import { resolveUserPath } from "../utils.js";
1515
import { readClawStatus } from "./lifecycle-state.js";
1616
import type { PackageRemovalDeps } from "./package-remove.js";
1717
import { isPortableClawAvatar } from "./schema-portability.js";
18-
import { parseClawManifest } from "./schema.js";
18+
import { parseClawManifest, parseClawOpenClawProfile } from "./schema.js";
1919
import { MAX_MANAGED_WORKSPACE_BYTES } from "./source-limits.js";
2020
import {
2121
CLAW_BOOTSTRAP_FILE_NAMES,
2222
CLAW_OUTPUT_STABILITY,
2323
CLAW_SCHEMA_VERSION,
2424
type ClawManifest,
2525
type ClawMcpServer,
26+
type ClawOpenClawProfile,
2627
} from "./types.js";
2728

2829
export const CLAW_EXPORT_RESULT_SCHEMA_VERSION = "openclaw.clawExportResult.v1" as const;
@@ -37,6 +38,7 @@ type ClawExportResult = {
3738
agentId: string;
3839
outputDirectory: string;
3940
manifest: ClawManifest;
41+
openClawProfile?: ClawOpenClawProfile;
4042
filesWritten: string[];
4143
};
4244

@@ -57,15 +59,23 @@ function portableAgent(agent: AgentConfig, avatar: string | undefined): ClawMani
5759
...(agent.identity?.emoji ? { emoji: agent.identity.emoji } : {}),
5860
...(avatar ? { avatar } : {}),
5961
};
60-
const tools = {
61-
...(agent.tools?.allow?.length ? { allow: agent.tools.allow } : {}),
62-
...(agent.tools?.deny?.length ? { deny: agent.tools.deny } : {}),
63-
};
6462
return {
6563
id: agent.id,
6664
...(agent.name ? { name: agent.name } : {}),
6765
...(agent.description ? { description: agent.description } : {}),
6866
...(Object.keys(identity).length > 0 ? { identity } : {}),
67+
};
68+
}
69+
70+
function portableOpenClawProfile(agent: AgentConfig): ClawOpenClawProfile | undefined {
71+
const tools = {
72+
...(agent.tools?.profile ? { profile: agent.tools.profile } : {}),
73+
...(agent.tools?.allow?.length ? { allow: agent.tools.allow } : {}),
74+
...(agent.tools?.alsoAllow?.length ? { alsoAllow: agent.tools.alsoAllow } : {}),
75+
...(agent.tools?.deny?.length ? { deny: agent.tools.deny } : {}),
76+
...(agent.tools?.fs?.workspaceOnly === true ? { fs: { workspaceOnly: true as const } } : {}),
77+
};
78+
const settings = {
6979
...(agent.groupChat?.mentionPatterns?.length
7080
? { groupChat: { mentionPatterns: agent.groupChat.mentionPatterns } }
7181
: {}),
@@ -81,6 +91,25 @@ function portableAgent(agent: AgentConfig, avatar: string | undefined): ClawMani
8191
}
8292
: {}),
8393
...(Object.keys(tools).length > 0 ? { tools } : {}),
94+
...(agent.memory?.search
95+
? {
96+
memory: {
97+
search: {
98+
...(agent.memory.search.enabled !== undefined
99+
? { enabled: agent.memory.search.enabled }
100+
: {}),
101+
...(agent.memory.search.rememberAcrossConversations !== undefined
102+
? {
103+
rememberAcrossConversations: agent.memory.search.rememberAcrossConversations,
104+
}
105+
: {}),
106+
...(agent.memory.search.sources?.length
107+
? { sources: agent.memory.search.sources }
108+
: {}),
109+
},
110+
},
111+
}
112+
: {}),
84113
...(agent.heartbeat
85114
? {
86115
heartbeat: {
@@ -122,6 +151,7 @@ function portableAgent(agent: AgentConfig, avatar: string | undefined): ClawMani
122151
}
123152
: {}),
124153
};
154+
return Object.keys(settings).length > 0 ? { schemaVersion: 1, agent: settings } : undefined;
125155
}
126156

127157
function normalizedRelativePath(value: string): string {
@@ -334,9 +364,15 @@ export async function exportClawAgent(
334364
const configuredMcpServers = normalizeConfiguredMcpServers(
335365
options.sourceMcpServers ?? options.config.mcp?.servers,
336366
);
367+
const openClawProfile = portableOpenClawProfile(agent);
368+
const openClawProfilePath = "profiles/openclaw.yml";
369+
const openClawProfileRaw = openClawProfile
370+
? Buffer.from(stringifyYaml(openClawProfile))
371+
: undefined;
337372
const manifest: ClawManifest = {
338373
schemaVersion: CLAW_SCHEMA_VERSION,
339374
agent: portableAgent(agent, avatar.source),
375+
...(openClawProfile ? { metadata: { "openclaw.config": openClawProfilePath } } : {}),
340376
workspace: { bootstrapFiles, files },
341377
packages: record.packages
342378
.map((pkg) => ({
@@ -367,6 +403,15 @@ export async function exportClawAgent(
367403
parsed.diagnostics.map((diagnostic) => diagnostic.message).join("; "),
368404
);
369405
}
406+
if (openClawProfile) {
407+
const parsedProfile = parseClawOpenClawProfile(openClawProfile);
408+
if (!parsedProfile.ok) {
409+
throw new ClawExportError(
410+
"export_openclaw_profile_invalid",
411+
parsedProfile.diagnostics.map((diagnostic) => diagnostic.message).join("; "),
412+
);
413+
}
414+
}
370415

371416
const target = resolve(resolveUserPath(outputDirectory));
372417
await mkdir(dirname(target), { recursive: true });
@@ -390,9 +435,19 @@ export async function exportClawAgent(
390435
await output.write(path, file.content, { mkdir: true, overwrite: false });
391436
filesWritten.push(path);
392437
}
438+
if (openClawProfileRaw) {
439+
await output.write(openClawProfilePath, openClawProfileRaw, {
440+
mkdir: true,
441+
overwrite: false,
442+
});
443+
filesWritten.push(openClawProfilePath);
444+
}
393445
const packageJson = {
394446
name: `openclaw-claw-${record.install.agentId}`,
395-
version: derivativePackageVersion(manifest, contents),
447+
version: derivativePackageVersion(manifest, [
448+
...contents,
449+
...(openClawProfileRaw ? [{ path: openClawProfilePath, content: openClawProfileRaw }] : []),
450+
]),
396451
type: "module",
397452
openclaw: { claw: "CLAW.md" },
398453
};
@@ -422,6 +477,7 @@ export async function exportClawAgent(
422477
agentId,
423478
outputDirectory: target,
424479
manifest,
480+
...(openClawProfile ? { openClawProfile } : {}),
425481
filesWritten,
426482
};
427483
}

‎src/claws/fixtures/incident-response.claw.json‎

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,11 @@
77
"identity": {
88
"name": "Incident Response",
99
"emoji": "siren"
10-
},
11-
"groupChat": {
12-
"mentionPatterns": [
13-
"@incident-response"
14-
]
15-
},
16-
"sandbox": {
17-
"mode": "all",
18-
"scope": "agent",
19-
"workspaceAccess": "rw"
20-
},
21-
"tools": {
22-
"allow": [
23-
"read",
24-
"write",
25-
"web_fetch"
26-
],
27-
"deny": [
28-
"exec",
29-
"browser"
30-
]
31-
},
32-
"heartbeat": {
33-
"every": "30m",
34-
"lightContext": true,
35-
"isolatedSession": true,
36-
"skipWhenBusy": true,
37-
"timeoutSeconds": 120
3810
}
3911
},
12+
"metadata": {
13+
"openclaw.config": "profiles/incident-response.openclaw.yml"
14+
},
4015
"workspace": {
4116
"bootstrapFiles": {
4217
"SOUL.md": {

0 commit comments

Comments
 (0)