Skip to content

Commit 3bc61f2

Browse files
authored
fix: keep always within OS compatibility (#123731)
Skill and hook status now preserve OS incompatibility when `always` bypasses runtime requirements, matching existing loader behavior and clarified documentation. Refs #122271 and #122331.
1 parent 6073567 commit 3bc61f2

8 files changed

Lines changed: 88 additions & 25 deletions

File tree

‎docs/automation/hooks.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ Detailed documentation goes here.
112112
| `export` | Named export to use (defaults to `"default"`) |
113113
| `os` | Required platforms (e.g., `["darwin", "linux"]`) |
114114
| `requires` | Required `bins`, `anyBins`, `env`, or `config` paths |
115-
| `always` | Bypass eligibility checks (boolean) |
115+
| `always` | Bypass `requires.*` checks on a compatible OS |
116116
| `hookKey` | Config key override (defaults to the hook name) |
117117
| `homepage` | Docs URL shown by `openclaw hooks info` |
118118
| `install` | Installation methods |

‎docs/tools/creating-skills.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ metadata: { "openclaw": { "requires": { "bins": ["gemini"] }, "primaryEnv": "GEM
141141
| `requires.env` | Each env var must exist in the process or config |
142142
| `requires.config` | Each `openclaw.json` path must be truthy |
143143
| `os` | Platform filter: `["darwin"]`, `["linux"]`, `["win32"]` |
144-
| `always` | Set `true` to skip all gates and always include the skill |
144+
| `always` | Include on a compatible OS even when `requires.*` checks fail |
145145

146146
Full reference: [Skills — Gating](/tools/skills#gating).
147147

‎docs/tools/skills.md‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,9 @@ metadata:
357357
```
358358

359359
<ParamField path="always" type="boolean">
360-
When `true`, always include the skill and skip all other gates.
360+
When `true`, include the skill whenever its `os` requirement is compatible,
361+
bypassing `requires.bins`, `requires.anyBins`, `requires.env`, and
362+
`requires.config`.
361363
</ParamField>
362364

363365
<ParamField path="emoji" type="string">
@@ -369,7 +371,9 @@ metadata:
369371
</ParamField>
370372

371373
<ParamField path="os" type='("darwin" | "linux" | "win32")[]'>
372-
Platform filter. When set, the skill is only eligible on a listed OS.
374+
Hard platform filter. When set, the skill is only eligible when the local
375+
host or a connected remote runtime matches a listed OS. `always` does not
376+
override this filter.
373377
</ParamField>
374378

375379
<ParamField path="requires.bins" type="string[]">

‎src/hooks/hooks-status.test.ts‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,45 @@ describe("hook status", () => {
4545
blockedReason: "no events defined",
4646
});
4747
});
48+
49+
it("keeps OS incompatibility visible for always-on hooks", () => {
50+
const mismatchedOs = process.platform === "darwin" ? "linux" : "darwin";
51+
const entry = createHookEntry({
52+
source: "openclaw-workspace",
53+
events: ["command:new"],
54+
});
55+
entry.metadata = {
56+
...entry.metadata,
57+
events: ["command:new"],
58+
always: true,
59+
os: [mismatchedOs],
60+
requires: { env: ["MISSING_HOOK_ENV"] },
61+
};
62+
63+
const report = buildWorkspaceHookStatus("/tmp/workspace", {
64+
entries: [entry],
65+
config: {
66+
hooks: {
67+
internal: {
68+
enabled: true,
69+
entries: { "session-memory": { enabled: true } },
70+
},
71+
},
72+
},
73+
});
74+
75+
expect(report.hooks[0]).toMatchObject({
76+
always: true,
77+
requirementsSatisfied: false,
78+
loadable: false,
79+
blockedReason: "missing requirements",
80+
missing: {
81+
bins: [],
82+
anyBins: [],
83+
env: [],
84+
config: [],
85+
os: [mismatchedOs],
86+
},
87+
});
88+
});
4889
});

‎src/shared/config-eval.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ function evaluateRuntimeRequires(params: RuntimeRequirementEvalParams): boolean
125125
return true;
126126
}
127127

128-
/** Evaluates OS gating and runtime requirements for skill/plugin entry eligibility. */
128+
/** Enforces OS compatibility before allowing `always` to bypass runtime requirements. */
129129
export function evaluateRuntimeEligibility(
130130
params: {
131131
os?: string[];

‎src/shared/requirements.test.ts‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ describe("requirements evaluation", () => {
121121
expect(result.eligible).toBe(false);
122122
});
123123

124-
it("clears missing requirements when always is true but preserves config checks", () => {
124+
it("clears runtime requirements when always is true on a compatible OS", () => {
125125
const result = evaluate({
126126
always: true,
127127
metadata: {
@@ -131,7 +131,7 @@ describe("requirements evaluation", () => {
131131
env: ["OPENAI_API_KEY"],
132132
config: ["browser.enabled"],
133133
},
134-
os: ["darwin"],
134+
os: ["linux"],
135135
},
136136
});
137137

@@ -140,6 +140,25 @@ describe("requirements evaluation", () => {
140140
expect(result.eligible).toBe(true);
141141
});
142142

143+
it("preserves OS incompatibility when always is true", () => {
144+
const result = evaluate({
145+
always: true,
146+
metadata: {
147+
requires: { bins: ["node"], env: ["OPENAI_API_KEY"] },
148+
os: ["darwin"],
149+
},
150+
});
151+
152+
expect(result.missing).toEqual({
153+
bins: [],
154+
anyBins: [],
155+
env: [],
156+
config: [],
157+
os: ["darwin"],
158+
});
159+
expect(result.eligible).toBe(false);
160+
});
161+
143162
it("defaults missing metadata to empty requirements", () => {
144163
const result = evaluate();
145164

‎src/shared/requirements.ts‎

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -162,24 +162,22 @@ function evaluateRequirements(
162162
});
163163
const missingConfig = configChecks.filter((check) => !check.satisfied).map((check) => check.path);
164164

165-
// `always` keeps diagnostics visible while making runtime eligibility unconditional.
166-
const missing = params.always
167-
? { bins: [], anyBins: [], env: [], config: [], os: [] }
168-
: {
169-
bins: missingBins,
170-
anyBins: missingAnyBins,
171-
env: missingEnv,
172-
config: missingConfig,
173-
os: missingOs,
174-
};
165+
// `always` bypasses runtime requirements, but OS remains a hard compatibility boundary.
166+
const missing = {
167+
bins: params.always ? [] : missingBins,
168+
anyBins: params.always ? [] : missingAnyBins,
169+
env: params.always ? [] : missingEnv,
170+
config: params.always ? [] : missingConfig,
171+
os: missingOs,
172+
};
175173

176174
const eligible =
177-
params.always ||
178-
(missing.bins.length === 0 &&
179-
missing.anyBins.length === 0 &&
180-
missing.env.length === 0 &&
181-
missing.config.length === 0 &&
182-
missing.os.length === 0);
175+
missing.os.length === 0 &&
176+
(params.always ||
177+
(missing.bins.length === 0 &&
178+
missing.anyBins.length === 0 &&
179+
missing.env.length === 0 &&
180+
missing.config.length === 0));
183181

184182
return { missing, eligible, configChecks };
185183
}

‎src/skills/discovery/status.test.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ describe("buildWorkspaceSkillStatus", () => {
383383
}),
384384
frontmatter: {},
385385
metadata: {
386+
always: true,
386387
os: [mismatchedOs],
387388
requires: { bins: ["fakebin"] },
388389
install: [
@@ -410,7 +411,7 @@ describe("buildWorkspaceSkillStatus", () => {
410411
primaryEnv: undefined,
411412
emoji: undefined,
412413
homepage: undefined,
413-
always: false,
414+
always: true,
414415
disabled: false,
415416
blockedByAllowlist: false,
416417
blockedByAgentFilter: false,
@@ -428,7 +429,7 @@ describe("buildWorkspaceSkillStatus", () => {
428429
},
429430
missing: {
430431
anyBins: [],
431-
bins: ["fakebin"],
432+
bins: [],
432433
config: [],
433434
env: [],
434435
os: [mismatchedOs],

0 commit comments

Comments
 (0)