Skip to content

armgit / Orkas

Public Imported from GitHub
0

Orkas is an open-source (MIT), local-first AI team for your desktop: a Commander turns your goal into to-dos and coordinates 16 built-in specialist agents plus Claude Code, Codex, OpenCode, OpenClaw and Hermes, with projects, scheduled automations and connectors. Free app for macOS & Windows; built-in models or your own keys.

fix(quality): honor operator rule scan targets

Harbor404e939435e8dfc
diff --git a/src/main/quality/README.md b/src/main/quality/README.md
index 98173b11..a4eb832d 100644
--- a/src/main/quality/README.md
+++ b/src/main/quality/README.md
@@ -52,7 +52,10 @@ rules as `operatorRules` to `validateSkillFile` / `validateSkillDir` /
The built-in rules stay the security floor: operator rules are additive only
— they never suppress, downgrade or rewrite a built-in finding, and a
colliding id is rejected. Their findings carry `source: 'operator-policy'`.
-Still not a sandbox. Field reference lives in `rules/operator-policy.ts`.
+`appliesTo` scopes operator rules by artifact: `skill_md` means executable
+fenced blocks in `SKILL.md`, `script` means standalone script files,
+`skill_meta` means `_meta.json`, and `agent_json` means an Agent spec. Still
+not a sandbox. Field reference lives in `rules/operator-policy.ts`.
## Levels
diff --git a/src/main/quality/index.ts b/src/main/quality/index.ts
index 826cf744..057a7e3e 100644
--- a/src/main/quality/index.ts
+++ b/src/main/quality/index.ts
@@ -83,6 +83,11 @@ export function validateSkillFile(args: {
violations.push(..._scanSkillMd(args.content, args.relpath, {}, true, false, args.operatorRules));
} else if (kind === 'skill_meta') {
violations.push(..._scanSkillMeta(args.content));
+ violations.push(..._policyScan(args.operatorRules, {
+ content: args.content,
+ kind: 'skill_meta',
+ field: args.relpath,
+ }));
} else if (kind === 'script') {
const scanArgs: RuleScanArgs = {
content: args.content,
@@ -146,16 +151,16 @@ export function validateSkillDir(
return _finalize(violations);
}
- // Walk all other recognized files (scripts).
+ // Walk all other recognized files (scripts and _meta.json policy targets).
for (const rel of _walkFiles(skillDir, '')) {
if (rel.toUpperCase() === 'SKILL.MD') continue;
- if (rel === '_meta.json') continue;
const kind = detectSkillFileKind(rel);
- if (kind !== 'script') continue;
+ if (kind !== 'script' && kind !== 'skill_meta') continue;
+ if (kind === 'skill_meta' && !options.operatorRules?.length) continue;
try {
const content = fs.readFileSync(path.join(skillDir, rel), 'utf8');
- const scanArgs: RuleScanArgs = { content, kind: 'script', field: rel };
- violations.push(...scanRedFlags(scanArgs));
+ const scanArgs: RuleScanArgs = { content, kind, field: rel };
+ if (kind === 'script') violations.push(...scanRedFlags(scanArgs));
violations.push(..._policyScan(options.operatorRules, scanArgs));
} catch {
// unreadable file (binary / permission) — skip; no violation surfaced
@@ -250,7 +255,8 @@ function _policyScan(
rules: ReadonlyArray<RuleDef> | undefined,
args: RuleScanArgs,
): Violation[] {
- return scanRuleSet(rules ?? [], args, 'operator-policy');
+ if (!rules?.length) return [];
+ return scanRuleSet(rules, args, 'operator-policy');
}
function detectSkillFileKind(relpath: string): ScanKind {
@@ -301,7 +307,7 @@ function _scanSkillMd(
field: `${field}:${block.startLine} (\`\`\`${block.lang})`,
};
violations.push(...scanRedFlags(scanArgs));
- violations.push(..._policyScan(operatorRules, scanArgs));
+ violations.push(..._policyScan(operatorRules, { ...scanArgs, kind: 'skill_md' }));
}
return violations;
diff --git a/test/main/quality/operator-policy.test.ts b/test/main/quality/operator-policy.test.ts
index 86b2c8eb..4700e385 100644
--- a/test/main/quality/operator-policy.test.ts
+++ b/test/main/quality/operator-policy.test.ts
@@ -3,8 +3,7 @@ import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
-import { validateSkillFile, validateSkillDir } from '../../../src/main/quality';
-import { parseOperatorPolicy } from '../../../src/main/quality/rules/operator-policy';
+import { validateSkillFile, validateSkillDir, parseOperatorPolicy } from '../../../src/main/quality';
type Rules = ReturnType<typeof parseOperatorPolicy>['rules'];
@@ -66,6 +65,7 @@ describe('quality › operator policy rules', () => {
expect(parseOperatorPolicy('{}').errors[0]).toMatch(/"rules" array/);
const cases: Array<[unknown, RegExp]> = [
[{ id: 'no_credential_path_read', level: 'LOW', pattern: 'x' }, /collides with a built-in rule/],
+ [{ id: 'other_only', level: 'LOW', pattern: 'x', appliesTo: ['other'] }, /"appliesTo" must be a non-empty array/],
];
for (const [rule, expected] of cases) {
const parsed = parseOperatorPolicy(JSON.stringify({ rules: [rule] }));
@@ -74,6 +74,34 @@ describe('quality › operator policy rules', () => {
}
});
+ it('honours skill_md rules on executable blocks and keeps script rules scoped to scripts', () => {
+ const content = md('```bash\necho acme-secret\n```\n');
+ const onlyMd = parseOperatorPolicy(JSON.stringify({ rules: [
+ { id: 'skill_md_only', level: 'MEDIUM', pattern: 'acme-secret', appliesTo: ['skill_md'] }] })).rules;
+ const onlyScript = parseOperatorPolicy(JSON.stringify({ rules: [
+ { id: 'script_only', level: 'MEDIUM', pattern: 'acme-secret', appliesTo: ['script'] }] })).rules;
+
+ expect(validateSkillFile({ relpath: 'SKILL.md', content, operatorRules: onlyMd }).violations)
+ .toEqual(expect.arrayContaining([expect.objectContaining({ rule: 'skill_md_only', source: 'operator-policy' })]));
+ expect(validateSkillFile({ relpath: 'SKILL.md', content, operatorRules: onlyScript }).violations)
+ .not.toEqual(expect.arrayContaining([expect.objectContaining({ rule: 'script_only' })]));
+ });
+
+ it('applies skill_meta rules to file- and directory-level sidecar validation', () => {
+ const content = JSON.stringify({ category: 'acme-secret' });
+ const { rules } = parseOperatorPolicy(JSON.stringify({ rules: [
+ { id: 'meta_secret', level: 'MEDIUM', pattern: 'acme-secret', appliesTo: ['skill_meta'] }] }));
+
+ expect(validateSkillFile({ relpath: '_meta.json', content, operatorRules: rules }).violations)
+ .toEqual(expect.arrayContaining([expect.objectContaining({ rule: 'meta_secret', field: '_meta.json:1' })]));
+
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'quality-op-meta-'));
+ fs.writeFileSync(path.join(dir, 'SKILL.md'), md('No executable content.'));
+ fs.writeFileSync(path.join(dir, '_meta.json'), content);
+ expect(validateSkillDir(dir, { operatorRules: rules }).violations)
+ .toEqual(expect.arrayContaining([expect.objectContaining({ rule: 'meta_secret', field: '_meta.json:1' })]));
+ });
+
it('scans on-disk scripts, honours appliesTo, and never flips the floor verdict', () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'quality-op-'));
fs.writeFileSync(path.join(dir, 'SKILL.md'), md('See scripts/report.sh.'));