Skip to content

Commit 5d73959

Browse files
authored
feat(claws): adopt portable profiles and native bootstrap
1 parent 06d5e44 commit 5d73959

35 files changed

Lines changed: 1718 additions & 149 deletions

‎docs/cli/claws.md‎

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ title: "Claws"
1111

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

1717
Claws are experimental. Their schema, command output, and lifecycle may change.
@@ -27,8 +27,8 @@ separate registry track and are not part of this command surface yet.
2727

2828
## Create a Claw package
2929

30-
A package contains `package.json`, a `CLAW.md` manifest, and any profiles or
31-
workspace sidecars referenced by that manifest:
30+
A package contains `package.json`, a `CLAW.md` manifest, and any conventional
31+
profiles, bootstrap instructions, or portable assets used by that manifest:
3232

3333
```json
3434
{
@@ -49,8 +49,6 @@ schemaVersion: 1
4949
agent:
5050
id: incident-triage
5151
name: Incident triage
52-
metadata:
53-
openclaw.config: profiles/openclaw.yml
5452
workspace:
5553
bootstrapFiles: {}
5654
packages: []
@@ -64,10 +62,13 @@ You review incoming incidents, identify severity and ownership, and leave a
6462
concise handoff with evidence.
6563
```
6664

67-
`metadata` is a string-to-string map for portable consumer hints. OpenClaw's
68-
`openclaw.config` key points to an optional, package-relative YAML profile. The
69-
exported default is `profiles/openclaw.yml`; the pointer is normative, so a
70-
package may choose another safe relative `.yml` or `.yaml` path.
65+
OpenClaw automatically discovers the optional `profiles/openclaw.yml` file.
66+
There is no manifest pointer. Other harnesses may discover their own
67+
conventional profile, such as `profiles/codex.yml`, without changing the
68+
portable manifest.
69+
70+
Experimental packages that used `metadata.openclaw.config` must move that file
71+
to `profiles/openclaw.yml` and remove the metadata entry.
7172

7273
```yaml
7374
schemaVersion: 1
@@ -87,13 +88,13 @@ agent:
8788
8889
This profile exists only inside the Claw package. OpenClaw validates and uses it
8990
while inspecting, adding, updating, and exporting that Claw; it is not copied
90-
to the user's normal OpenClaw configuration path. Other harnesses can ignore
91-
the namespaced metadata key and consume the portable manifest fields.
91+
to the user's normal OpenClaw configuration path. Other harnesses consume the
92+
portable manifest and interpret only their own conventional profile.
9293
9394
The same strict version 1 schema continues to accept grouped JSON manifests.
94-
Grouped JSON uses the same `metadata.openclaw.config` pointer rather than
95-
embedding a second copy of the OpenClaw profile. The remaining schema fragments
96-
on this page use JSON, with equivalent keys available in `CLAW.md` frontmatter.
95+
Grouped JSON discovers the same conventional profile rather than embedding a
96+
second copy of the OpenClaw settings. The remaining schema fragments on this
97+
page use JSON, with equivalent keys available in `CLAW.md` frontmatter.
9798

9899
The OpenClaw package profile may select any built-in tool profile registered by
99100
the running OpenClaw version, then refine it with `alsoAllow`, `deny`, and
@@ -105,7 +106,7 @@ and opt into cross-conversation memory with `rememberAcrossConversations`.
105106
Declaring the `sessions` source requires that opt-in.
106107
Host policy still constrains these settings, and Claws do not carry custom
107108
profile definitions, providers, credentials, bindings, or local memory paths.
108-
The referenced profile is limited to 256 KiB, must be JSON-compatible YAML, may
109+
The conventional profile is limited to 256 KiB, must be JSON-compatible YAML, may
109110
not use aliases, anchors, tags, or merge keys, and must be a regular,
110111
non-symlinked, non-hardlinked file inside the package.
111112

@@ -135,6 +136,21 @@ workspace-relative targets:
135136
}
136137
```
137138

139+
Additional files are the portable asset mechanism. Authors may organize package
140+
sources under directories such as `assets/`, `schemas/`, `templates/`, and
141+
`examples/`, then map them into the new agent workspace with
142+
`workspace.files`. Apply records those destinations as managed files; update
143+
reconciles unchanged managed assets, and remove preserves modified or
144+
user-owned files.
145+
146+
An optional package-root `BOOTSTRAP.md` supplies conversational first-run
147+
instructions. OpenClaw seeds it into the new agent workspace and records
148+
progress through the native workspace bootstrap state. Once the agent consumes
149+
or removes it, Claw update does not recreate it. Root `BOOTSTRAP.md` therefore
150+
cannot also be declared through `workspace.files`. Claw removal deletes an
151+
unchanged, still-pending package bootstrap after verifying its recorded digest;
152+
it preserves edited bootstrap content and files created during onboarding.
153+
138154
Skills and plugins use exact ClawHub versions:
139155

140156
```json
@@ -236,10 +252,11 @@ defaults collide with local state. For disposable profiles and parallel validati
236252
pass an explicit `--workspace`; `OPENCLAW_STATE_DIR` relocates runtime state but
237253
does not change the default workspace location.
238254

239-
Adding a Claw creates the new agent and workspace configuration, writes declared
240-
workspace files, installs or reuses declared skill and plugin artifacts, and
241-
records package, MCP, and cron provenance. Existing files are not overwritten,
242-
and retries fail closed when owned content drifted.
255+
Adding a Claw creates the new agent and workspace configuration, seeds optional
256+
first-run instructions, writes declared workspace assets, installs or reuses
257+
declared skill and plugin artifacts, and records package, MCP, and cron
258+
provenance. Existing files are not overwritten, and retries fail closed when
259+
owned content drifted.
243260

244261
## Inspect installed state
245262

@@ -250,7 +267,8 @@ openclaw doctor
250267
```
251268

252269
`status` compares the installed agent and its recorded workspace, package, MCP,
253-
and cron provenance with current state. It reports incomplete installs, missing
270+
and cron provenance with current state. It also reports whether native
271+
first-run bootstrap remains pending. It reports incomplete installs, missing
254272
resources, and drift without changing local state. `openclaw doctor` adds
255273
Claw-specific diagnostics for incomplete ownership records, unsafe managed
256274
files, and cron jobs that cannot be corroborated with live Gateway inventory.

‎src/agents/workspace-state-store.test.ts‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import path from "node:path";
55
import { afterEach, beforeEach, describe, expect, it } from "vitest";
66
import {
77
closeOpenClawStateDatabaseForTest,
8+
openExistingOpenClawStateDatabaseReadOnly,
89
openOpenClawStateDatabase,
910
} from "../state/openclaw-state-db.js";
1011
import { resolveOpenClawStateSqlitePath } from "../state/openclaw-state-db.paths.js";
@@ -257,6 +258,57 @@ describe("workspace state store", () => {
257258
expect(clearExpiredWorkspaceStateForVanishedWorkspace(alias, 2_000)).toBe(false);
258259
});
259260

261+
it("registers missing aliases in the caller-selected state database", () => {
262+
const dir = workspaceDir();
263+
const alias = testState!.path("workspace-link");
264+
const env = {
265+
...process.env,
266+
OPENCLAW_STATE_DIR: testState!.path("custom-state"),
267+
};
268+
fs.symlinkSync(dir, alias, process.platform === "win32" ? "junction" : "dir");
269+
const identity = resolveWorkspaceStateIdentity(dir);
270+
mergeWorkspaceSetupState(dir, { bootstrapSeededAt: "2026-07-16T01:00:00.000Z" }, 1_000, {
271+
env,
272+
});
273+
274+
expect(readWorkspaceStateSnapshot(alias, { env }).identity).toStrictEqual(identity);
275+
fs.unlinkSync(alias);
276+
277+
expect(readWorkspaceStateSnapshot(alias, { env }).identity).toStrictEqual(identity);
278+
expect(readWorkspaceStateSnapshot(alias, { env }).setupExists).toBe(true);
279+
expect(resolveOpenClawStateSqlitePath(env)).not.toBe(resolveOpenClawStateSqlitePath());
280+
expect(readWorkspaceStateSnapshot(alias).setupExists).toBe(false);
281+
});
282+
283+
it("does not register missing aliases through a read-only database", async () => {
284+
const dir = workspaceDir();
285+
const alias = testState!.path("workspace-link");
286+
const env = {
287+
...process.env,
288+
OPENCLAW_STATE_DIR: testState!.path("custom-state"),
289+
};
290+
mergeWorkspaceSetupState(dir, { bootstrapSeededAt: "2026-07-16T01:00:00.000Z" }, 1_000, {
291+
env,
292+
});
293+
closeOpenClawStateDatabaseForTest();
294+
fs.symlinkSync(dir, alias, process.platform === "win32" ? "junction" : "dir");
295+
const database = await openExistingOpenClawStateDatabaseReadOnly({ env });
296+
if (!database) {
297+
throw new Error("expected read-only database");
298+
}
299+
300+
try {
301+
expect(readWorkspaceStateSnapshot(alias, { database, env, readOnly: true }).setupExists).toBe(
302+
true,
303+
);
304+
} finally {
305+
database.walMaintenance.close();
306+
}
307+
fs.unlinkSync(alias);
308+
309+
expect(readWorkspaceStateSnapshot(alias, { env }).setupExists).toBe(false);
310+
});
311+
260312
it("fails closed when a persisted symlink alias is repointed", () => {
261313
const dir = workspaceDir();
262314
const alias = testState!.path("workspace-link");

‎src/agents/workspace-state-store.ts‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type { DB as OpenClawStateKyselyDatabase } from "../state/openclaw-state-
1111
import {
1212
openOpenClawStateDatabase,
1313
runOpenClawStateWriteTransaction,
14+
type OpenClawStateDatabaseOptions,
1415
} from "../state/openclaw-state-db.js";
1516
import { resolveOpenClawStateSqlitePath } from "../state/openclaw-state-db.paths.js";
1617
import { resolveUserPath } from "../utils.js";
@@ -363,8 +364,11 @@ function readSnapshotFromDatabase(params: {
363364
};
364365
}
365366

366-
export function readWorkspaceStateSnapshot(workspaceDir: string): WorkspaceStateSnapshot {
367-
const database = openOpenClawStateDatabase();
367+
export function readWorkspaceStateSnapshot(
368+
workspaceDir: string,
369+
options: OpenClawStateDatabaseOptions = {},
370+
): WorkspaceStateSnapshot {
371+
const database = openOpenClawStateDatabase(options);
368372
const initial = runSqliteDeferredTransactionSync(database.db, () => {
369373
const resolution = resolveWorkspaceIdentityFromDatabase({ workspaceDir, database });
370374
return {
@@ -374,6 +378,7 @@ export function readWorkspaceStateSnapshot(workspaceDir: string): WorkspaceState
374378
});
375379
if (
376380
initial.resolution.missingAliasKeys.length === 0 ||
381+
options.readOnly ||
377382
(!initial.snapshot.setupExists && !initial.snapshot.attestation)
378383
) {
379384
return initial.snapshot;
@@ -408,13 +413,14 @@ export function readWorkspaceStateSnapshot(workspaceDir: string): WorkspaceState
408413
});
409414
}
410415
return snapshot;
411-
});
416+
}, options);
412417
}
413418

414419
export function mergeWorkspaceSetupState(
415420
workspaceDir: string,
416421
next: Partial<Omit<WorkspaceSetupState, "version">>,
417422
nowMs = Date.now(),
423+
options: OpenClawStateDatabaseOptions = {},
418424
): WorkspaceSetupState {
419425
assertCanonicalIntegerTimestamp(nowMs, "setup update");
420426
if (next.bootstrapSeededAt) {
@@ -464,7 +470,7 @@ export function mergeWorkspaceSetupState(
464470
updatedAtMs: nowMs,
465471
});
466472
return merged;
467-
});
473+
}, options);
468474
}
469475

470476
export function replaceWorkspaceAttestation(params: {

0 commit comments

Comments
 (0)