Skip to content

Commit 7774f9a

Browse files
authored
feat(claws): apply schema-v1 profile requirements (#115962)
* test(claws): model provenance columns in CLI state mock * fix(claws): normalize owned upgrade preflight * fix(claws): normalize owned upgrade preflight * fix(claws): normalize owned upgrade preflight * fix(claws): satisfy current validation gates
1 parent 67f1bae commit 7774f9a

64 files changed

Lines changed: 4807 additions & 625 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎docs/cli/claws.md‎

Lines changed: 58 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,17 @@ concise handoff with evidence.
6363
```
6464

6565
OpenClaw automatically discovers the optional `profiles/openclaw.yml` file.
66-
There is no manifest pointer. Other harnesses may discover their own
66+
No manifest pointer is required. Other harnesses may discover their own
6767
conventional profile, such as `profiles/codex.yml`, without changing the
6868
portable manifest.
6969

70-
Experimental packages that used `metadata.openclaw.config` must move that file
71-
to `profiles/openclaw.yml` and remove the metadata entry.
70+
The older `metadata.openclaw.config` pointer is deprecated but still read, so
71+
packages published against it keep working. Reading one reports a
72+
`deprecated_openclaw_profile_pointer` warning; move that file to
73+
`profiles/openclaw.yml` and remove the metadata entry. A pointer that is not a
74+
package-relative `.yml`/`.yaml` path is rejected, and a pointer that references
75+
a different file while `profiles/openclaw.yml` also exists is rejected as a
76+
conflict.
7277

7378
```yaml
7479
schemaVersion: 1
@@ -110,6 +115,35 @@ The conventional profile is limited to 256 KiB, must be JSON-compatible YAML, ma
110115
not use aliases, anchors, tags, or merge keys, and must be a regular,
111116
non-symlinked, non-hardlinked file inside the package.
112117

118+
An OpenClaw profile may also declare harness-specific extension requirements:
119+
120+
```yaml
121+
schemaVersion: 1
122+
agent: {}
123+
extensions:
124+
- id: incident-tools
125+
kind: plugin
126+
format: claude
127+
source: clawhub
128+
ref: "@acme/incident-tools"
129+
version: 2.0.0
130+
```
131+
132+
`format` asserts the artifact format that OpenClaw must detect (`openclaw`,
133+
`claude`, `codex`, or `cursor`). The canonical plugin preflight resolves the
134+
exact artifact and reports which components the current OpenClaw adapter maps
135+
and which remain unavailable. Missing identity, integrity, format detection, or
136+
adapter identity blocks apply. Extension-backed plugins use the existing
137+
plugin installer and ownership model; they are shared host requirements, not
138+
Claw-owned members or a second package system.
139+
140+
OpenClaw ignores foreign harness profiles during apply. Package integrity still
141+
covers every published package byte, while a development snapshot binds the
142+
portable manifest, bootstrap and workspace sources, and the selected OpenClaw
143+
profile. Status and doctor report adapter mapping drift or unavailable
144+
inspection. Export writes extension-backed plugins to `profiles/openclaw.yml`
145+
and does not duplicate them in the portable `packages` list.
146+
113147
Package and workspace paths must remain inside the package root. Manifests are
114148
limited to 1 MiB, package metadata to 256 KiB, and workspace sources enforce
115149
separate per-file and aggregate limits. Workspace sources also reject symlinked
@@ -174,10 +208,13 @@ Skills and plugins use exact ClawHub versions:
174208

175209
The dry run uses the existing skill and plugin preflight paths to resolve the
176210
exact artifact, integrity, and any ClawHub trust warning before consent. The
177-
warning remains visible in the integrity-bound plan. Apply installs missing artifacts
178-
or reuses matching ones and records whether the Claw introduced or referenced
179-
each resource. Plugins remain process-wide OpenClaw capabilities rather than
180-
per-agent installations.
211+
warning remains visible in the integrity-bound plan. Each requirement is shown
212+
as satisfied, missing-installable, conflicting, or setup-required. The exact
213+
plan consent approves missing installs; OpenClaw completes those canonical
214+
plugin actions before creating the agent or workspace. Apply reuses matching
215+
artifacts and records whether the Claw introduced or referenced each resource.
216+
Plugins remain process-wide OpenClaw capabilities rather than per-agent
217+
installations.
181218

182219
Cron jobs declare scheduled work for the new agent:
183220

@@ -222,7 +259,9 @@ removal follow the same ownership policy as other Claw resources.
222259

223260
## Inspect and preview
224261

225-
Validate the source without planning local changes:
262+
Validate the source without planning local changes. For OpenClaw profile
263+
extensions, inspect also performs the canonical read-only artifact probe and
264+
reports mapped and unavailable components:
226265

227266
```bash
228267
openclaw claws inspect ./incident-triage.claw.json
@@ -252,11 +291,11 @@ defaults collide with local state. For disposable profiles and parallel validati
252291
pass an explicit `--workspace`; `OPENCLAW_STATE_DIR` relocates runtime state but
253292
does not change the default workspace location.
254293

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.
294+
Adding a Claw first realizes consented shared plugin requirements, then creates
295+
the new agent and workspace configuration, seeds optional first-run
296+
instructions, writes declared workspace assets, realizes workspace skills, and
297+
records package, MCP, and cron provenance. Existing files are not overwritten,
298+
and retries fail closed when owned content drifted.
260299

261300
## Inspect installed state
262301

@@ -300,9 +339,9 @@ The plan compares current provenance and live state with the target manifest.
300339
It reports agent, workspace, package, MCP, cron, and ownership changes,
301340
including capability escalations and blockers. Capability escalations have
302341
separate machine-readable records and `!` lines with exact redacted effects in
303-
human output. Resolved package integrity, install identity, and any trust
304-
warning are included. Removing a package declaration releases this Claw's edge
305-
without uninstalling the artifact during update. The eventual
342+
human output. Resolved package integrity, install identity, trust warnings, and
343+
remaining local setup prerequisites are included. Removing a package declaration
344+
releases this Claw's edge without uninstalling the artifact during update. The eventual
306345
exact `planIntegrity` confirmation binds that disclosed set as well as ordinary
307346
content changes. Hosts may use the same records for a separate dialog or an
308347
aggregate multi-agent review. Apply the exact reviewed plan with explicit
@@ -339,8 +378,9 @@ The default removes eligible managed state and releases referenced state.
339378
Modified files and resources with another current owner are retained or
340379
blocked. Cleanup choices are part of the plan digest; `--yes` never broadens
341380
them. Globally installed plugins are retained while this Claw's reference is
342-
released; use the ordinary plugin lifecycle separately when you intend to
343-
uninstall a process-wide plugin.
381+
released. Removal reports which retained requirements Claw add introduced; use
382+
the ordinary plugin lifecycle separately when you intend to uninstall a
383+
process-wide plugin.
344384

345385
To remove unchanged Claw-introduced references that have no other current
346386
owner, include `--remove-unused` in both preview and apply. To select exact

‎scripts/check-kysely-guardrails.mjs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ const rawSqliteAllowPathGroups = {
7474
],
7575
"agent auth profile read-only bootstrap": ["src/agents/auth-profiles/sqlite.ts"],
7676
"read-only shared state database access": [
77+
"src/claws/package-resume.ts",
7778
"src/state/openclaw-agent-db-readonly.ts",
7879
"src/state/openclaw-state-db-readonly.ts",
7980
],

‎src/claws/add.ts‎

Lines changed: 140 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Applies the package, agent, workspace, and managed-file slices of a consented Claw add plan.
2+
import type { Stats } from "node:fs";
23
import { lstat, mkdir, rmdir } from "node:fs/promises";
34
import { dirname, resolve } from "node:path";
45
import { stableStringify } from "@openclaw/normalization-core";
@@ -107,6 +108,16 @@ function hasUnsupportedMutationActions(plan: ClawAddPlan): boolean {
107108
);
108109
}
109110

111+
function planWithPackageActions(
112+
plan: ClawAddPlan,
113+
predicate: (action: ClawAddPlan["actions"][number]) => boolean,
114+
): ClawAddPlan {
115+
return {
116+
...plan,
117+
actions: plan.actions.filter((action) => action.kind !== "package" || predicate(action)),
118+
};
119+
}
120+
110121
function statusAtLeast(status: ClawInstallStatus, phase: ClawInstallStatus): boolean {
111122
const order: Record<ClawInstallStatus, number> = {
112123
pending: 0,
@@ -224,38 +235,124 @@ export async function applyClawAddPlan(
224235
throw new ClawAddMutationError("provenance_failed", (error as Error).message);
225236
}
226237

227-
const installPackages = options.installPackages ?? installClawPackages;
228-
let packages: PersistedClawPackageRef[] = [];
229-
230238
const workspace = resolve(resolveUserPath(plan.agent.workspace));
231239
const workspacePhaseRecorded = statusAtLeast(installRecord.status, "workspace_ready");
232-
const workspaceState = workspacePhaseRecorded
233-
? await lstat(workspace).catch((error: unknown) => {
234-
if (
235-
typeof error === "object" &&
236-
error !== null &&
237-
"code" in error &&
238-
error.code === "ENOENT"
239-
) {
240-
return undefined;
241-
}
242-
throw error;
243-
})
244-
: undefined;
240+
let workspaceState: Stats | undefined;
241+
try {
242+
assertWorkspacePathUnchanged(workspace);
243+
workspaceState = await lstat(workspace).catch((error: unknown) => {
244+
if (
245+
typeof error === "object" &&
246+
error !== null &&
247+
"code" in error &&
248+
error.code === "ENOENT"
249+
) {
250+
return undefined;
251+
}
252+
throw error;
253+
});
254+
} catch (error) {
255+
clearUnownedInstallRecord(plan.agent.finalId, ["pending", "partial"], options);
256+
if (error instanceof ClawAddMutationError) {
257+
throw error;
258+
}
259+
throw new ClawAddMutationError(
260+
"workspace_parent_failed",
261+
`Could not inspect workspace ${JSON.stringify(workspace)}: ${(error as Error).message}`,
262+
);
263+
}
264+
265+
if (!workspacePhaseRecorded && workspaceState) {
266+
markInstallStatus(plan.agent.finalId, "partial", ["pending", "partial"], options);
267+
return partialResult({
268+
plan,
269+
installRecord,
270+
workspaceCreated: false,
271+
configCommitted: false,
272+
packages: [],
273+
error: {
274+
code: "workspace_collision",
275+
message: `Workspace ${JSON.stringify(workspace)} was created after planning.`,
276+
},
277+
nowMs: options.nowMs,
278+
});
279+
}
245280
if (workspaceState && !workspaceState.isDirectory()) {
246281
throw new ClawAddMutationError(
247282
"workspace_collision",
248283
`Workspace ${JSON.stringify(workspace)} is no longer a directory.`,
249284
);
250285
}
286+
251287
let workspaceCreated = workspaceState?.isDirectory() ?? false;
252288
let configCommitted = statusAtLeast(installRecord.status, "config_committed");
289+
const installPackages = options.installPackages ?? installClawPackages;
290+
let packages: PersistedClawPackageRef[] = [];
291+
const preserveRecordedPhaseOrMarkPartial = (): ClawInstallStatus => {
292+
if (workspacePhaseRecorded) {
293+
return installRecord.status;
294+
}
295+
markInstallStatus(plan.agent.finalId, "partial", ["pending", "partial"], options);
296+
return "partial";
297+
};
298+
299+
const hostRequirementPlan = planWithPackageActions(
300+
plan,
301+
(action) => action.details?.kind === "plugin",
302+
);
303+
const hostRequirementActions = hostRequirementPlan.actions.filter(
304+
(action) => action.kind === "package",
305+
);
306+
if (hostRequirementActions.length > 0) {
307+
try {
308+
packages = await installPackages(hostRequirementPlan, options);
309+
} catch (error) {
310+
const packageError =
311+
error instanceof ClawPackageInstallError
312+
? error
313+
: new ClawPackageInstallError(
314+
"package_install_failed",
315+
error instanceof Error ? error.message : String(error),
316+
packages,
317+
);
318+
const installStatus = preserveRecordedPhaseOrMarkPartial();
319+
return partialResult({
320+
plan,
321+
installRecord,
322+
workspaceCreated,
323+
configCommitted,
324+
packages: packageError.installedPackages,
325+
installStatus,
326+
error: { code: packageError.code, message: packageError.message },
327+
nowMs: options.nowMs,
328+
});
329+
}
330+
}
253331

254332
try {
255333
assertWorkspacePathUnchanged(workspace);
256334
await mkdir(dirname(workspace), { recursive: true });
257335
assertWorkspacePathUnchanged(workspace);
258336
} catch (error) {
337+
if (packages.length > 0) {
338+
const installStatus = preserveRecordedPhaseOrMarkPartial();
339+
return partialResult({
340+
plan,
341+
installRecord,
342+
workspaceCreated,
343+
configCommitted,
344+
packages,
345+
installStatus,
346+
error: {
347+
code: error instanceof ClawAddMutationError ? error.code : "workspace_parent_failed",
348+
message:
349+
error instanceof ClawAddMutationError
350+
? error.message
351+
: `Could not create parent directory for workspace ${JSON.stringify(workspace)}: ${(error as Error).message}`,
352+
},
353+
nowMs: options.nowMs,
354+
});
355+
}
259356
clearUnownedInstallRecord(plan.agent.finalId, ["pending", "partial"], options);
260357
if (error instanceof ClawAddMutationError) {
261358
throw error;
@@ -310,19 +407,32 @@ export async function applyClawAddPlan(
310407
}
311408
}
312409

410+
// Seed and attest the consented package bootstrap while the workspace is still
411+
// private. Committing the agent config first makes the agent routable, so a
412+
// concurrent `sessions.create` can stock-seed BOOTSTRAP.md and strand the add at
413+
// `config_committed` with a seed conflict that no retry can clear.
313414
try {
314415
await (options.seedPackageBootstrap ?? seedClawPackageBootstrap)(plan, {
315416
...options,
316417
...(options.nowMs !== undefined ? { nowMs: options.nowMs } : {}),
317418
});
318419
} catch (error) {
420+
const installStatus: ClawInstallStatus = configCommitted
421+
? "config_committed"
422+
: "workspace_ready";
423+
markInstallStatus(
424+
plan.agent.finalId,
425+
installStatus,
426+
configCommitted ? ["config_committed"] : ["workspace_ready", "config_committed"],
427+
options,
428+
);
319429
return partialResult({
320430
plan,
321431
installRecord,
322432
workspaceCreated,
323433
configCommitted,
324434
packages,
325-
installStatus: "workspace_ready",
435+
installStatus,
326436
error: {
327437
code: error instanceof ClawBootstrapWriteError ? error.code : "bootstrap_write_failed",
328438
message: error instanceof Error ? error.message : String(error),
@@ -472,23 +582,33 @@ export async function applyClawAddPlan(
472582
try {
473583
// Skills require their workspace. Recurring work is enabled only after all
474584
// package mutation succeeds.
475-
packages = await installPackages(plan, options);
585+
const workspacePackagePlan = planWithPackageActions(
586+
plan,
587+
(action) => action.details?.kind !== "plugin",
588+
);
589+
const workspacePackageActions = workspacePackagePlan.actions.filter(
590+
(action) => action.kind === "package",
591+
);
592+
if (workspacePackageActions.length > 0) {
593+
const workspacePackages = await installPackages(workspacePackagePlan, options);
594+
packages = [...packages, ...workspacePackages];
595+
}
476596
} catch (error) {
477597
const packageError =
478598
error instanceof ClawPackageInstallError
479599
? error
480600
: new ClawPackageInstallError(
481601
"package_install_failed",
482602
error instanceof Error ? error.message : String(error),
483-
packages,
603+
[],
484604
);
485605
return partialResult({
486606
plan,
487607
installRecord,
488608
workspaceCreated,
489609
configCommitted,
490610
workspaceFiles,
491-
packages: packageError.installedPackages,
611+
packages: [...packages, ...packageError.installedPackages],
492612
installStatus: "config_committed",
493613
error: { code: packageError.code, message: packageError.message },
494614
nowMs: options.nowMs,

0 commit comments

Comments
 (0)