Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/cli/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2062,6 +2062,9 @@ export async function loadCliConfig(
disabledSlashCommands.length > 0 ? disabledSlashCommands : undefined,
disabledSkillNamesProvider:
bareMode || safeMode ? undefined : disabledSkillNamesProvider,
customSkillDirs: (settings.skills?.directories ?? [])
.filter((d): d is string => typeof d === 'string' && d.trim().length > 0)
.map((d) => d.trim()),
disabledTools: disabledTools.length > 0 ? disabledTools : undefined,
visibleTools: visibleTools.length > 0 ? visibleTools : undefined,
// New unified permissions (PermissionManager source of truth).
Expand Down
15 changes: 15 additions & 0 deletions packages/cli/src/config/settingsSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1953,6 +1953,21 @@ const SETTINGS_SCHEMA = {
showInDialog: false,
mergeStrategy: MergeStrategy.UNION,
},
directories: {
type: 'array',
label: 'Skill Directories',
category: 'Advanced',
requiresRestart: true,
default: undefined as string[] | undefined,
description:
'Additional directories to scan for skills (SKILL.md files). ' +
'Paths support ~ expansion. Each directory is scanned one level ' +
'deep for subdirectories containing a SKILL.md file. Skills from ' +
'these directories are loaded at user level, after the default ' +
'~/.qwen/skills/ directory.',
showInDialog: false,
mergeStrategy: MergeStrategy.UNION,
},
},
},
Comment on lines +1973 to 1976

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Suggestion] skills.directories uses MergeStrategy.UNION, which means a trusted workspace's .qwen/settings.json can UNION-merge additional entries into the effective skill directory list. Those workspace-injected directories are then loaded at user level in SkillManager.getSkillsBaseDirs('user') — visible across all workspaces, not scoped to the originating one.

This diverges from the MCP server handling: tagMcpServerScope(workspace, 'workspace') stamps workspace MCP servers with scope: 'workspace', so downstream consumers can distinguish user-configured from workspace-injected servers. Skill directories pass through the merge with no provenance tracking.

Concrete scenario: a user trusts a workspace (e.g., to use its MCP servers). That workspace includes {"skills":{"directories":["/tmp/shared-skills"]}}. Skills in that directory are loaded globally with hook execution capability (PreToolUse/PostToolUse via child_process.spawn). The schema description warns about trusting the location, but the asymmetry with MCP server provenance tracking means the system could make scope-aware decisions here and currently doesn't.

Possible approaches:

  • Track provenance (analogous to tagMcpServerScope) and load workspace-sourced dirs at project level
  • Use REPLACE instead of UNION for workspace scope
  • Log a warning when workspace settings contribute to skills.directories

— qwen3.7-max via Qwen Code /review


Expand Down
17 changes: 17 additions & 0 deletions packages/core/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,12 @@ export interface ConfigParameters {
* Names returned must be lower-cased; consumers compare case-insensitively.
*/
disabledSkillNamesProvider?: () => ReadonlySet<string>;
/**
* Additional directories to scan for skills (SKILL.md files).
* Sourced from `settings.skills.directories`. Paths are raw
* (unexpanded); `SkillManager.getSkillsBaseDirs` handles `~` expansion.
*/
customSkillDirs?: readonly string[];
/**
* Tool names hidden from the registry at construction time. Unlike
* `permissions.deny` (which keeps the tool registered and rejects
Expand Down Expand Up @@ -1675,6 +1681,7 @@ export class Config {
private readonly disabledSkillNamesProvider:
| (() => ReadonlySet<string>)
| null;
private readonly customSkillDirs: readonly string[];
// `disabledTools` is set at construction
// time but can be re-synced by the daemon mutation surface
// (`setWorkspaceToolEnabled` propagates through ACP) so a subsequent
Expand Down Expand Up @@ -1940,6 +1947,7 @@ export class Config {
...(params.disabledSlashCommands ?? []),
]);
this.disabledSkillNamesProvider = params.disabledSkillNamesProvider ?? null;
this.customSkillDirs = Object.freeze([...(params.customSkillDirs ?? [])]);
this.disabledTools = new Set(params.disabledTools ?? []);
this.visibleTools = new Set(
(params.visibleTools ?? []).filter(
Expand Down Expand Up @@ -4520,6 +4528,15 @@ export class Config {
return this.disabledSkillNamesProvider?.() ?? EMPTY_DISABLED_SKILL_NAMES;
}

/**
* Returns additional skill directories from `settings.skills.directories`.
* Paths are raw (unexpanded); consumers must handle `~` expansion
* (see `SkillManager.getSkillsBaseDirs`).
*/
getCustomSkillDirs(): readonly string[] {
return this.customSkillDirs;
}

/**
* Returns the read-only set of tool names hidden from this Config's
* ToolRegistry. Consulted by `ToolRegistry.registerTool` and
Expand Down
44 changes: 44 additions & 0 deletions packages/core/src/skills/skill-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,50 @@ Body`);
'Extension skills do not have a base directory',
);
});

it('should append custom skill dirs with ~ expansion to user-level dirs', () => {
const defaultDirs = manager.getSkillsBaseDirs('user');
const customConfig = makeFakeConfig({
customSkillDirs: ['~/custom-skills', '/abs/skills'],
});
Comment thread
qwen-code-dev-bot marked this conversation as resolved.
Resolved
vi.spyOn(customConfig, 'getProjectRoot').mockReturnValue('/test/project');
const customManager = new SkillManager(customConfig);

const baseDirs = customManager.getSkillsBaseDirs('user');

expect(baseDirs).toHaveLength(defaultDirs.length + 2);
expect(baseDirs.slice(0, defaultDirs.length)).toEqual(defaultDirs);
expect(baseDirs).toContain(
path.resolve(path.join(os.homedir(), 'custom-skills')),
);
expect(baseDirs).toContain(path.resolve('/abs/skills'));
});

it('should deduplicate custom dirs against default dirs', () => {
const defaultDirs = manager.getSkillsBaseDirs('user');
const customConfig = makeFakeConfig({
customSkillDirs: [defaultDirs[0], '/unique/dir'],
});
vi.spyOn(customConfig, 'getProjectRoot').mockReturnValue('/test/project');
const customManager = new SkillManager(customConfig);

const baseDirs = customManager.getSkillsBaseDirs('user');

expect(baseDirs).toHaveLength(defaultDirs.length + 1);
expect(baseDirs.filter((d) => d === defaultDirs[0])).toHaveLength(1);
expect(baseDirs).toContain(path.resolve('/unique/dir'));
});

it('should not crash when config lacks getCustomSkillDirs', () => {
const partialConfig = {
getProjectRoot: () => '/test/project',
} as Config;
const partialManager = new SkillManager(partialConfig);

const baseDirs = partialManager.getSkillsBaseDirs('user');

expect(baseDirs).toHaveLength(2);
});
});

describe('bundled skills', () => {
Expand Down
13 changes: 11 additions & 2 deletions packages/core/src/skills/skill-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
} from './skill-activation.js';
import { createDebugLogger } from '../utils/debugLogger.js';
import { normalizeContent } from '../utils/textUtils.js';
import { expandHomeDir } from '../utils/paths.js';
import {
QWEN_DIR,
SKILL_PROVIDER_CONFIG_DIRS,
Expand Down Expand Up @@ -900,12 +901,20 @@ export class SkillManager {
return SKILL_PROVIDER_CONFIG_DIRS.map((v) =>
path.join(this.config.getProjectRoot(), v, SKILLS_CONFIG_DIR),
);
case 'user':
return SKILL_PROVIDER_CONFIG_DIRS.map((v) =>
case 'user': {
const dirs = SKILL_PROVIDER_CONFIG_DIRS.map((v) =>
v === QWEN_DIR
? path.join(Storage.getGlobalQwenDir(), SKILLS_CONFIG_DIR)
: path.join(os.homedir(), v, SKILLS_CONFIG_DIR),
);
for (const customDir of this.config.getCustomSkillDirs?.() ?? []) {
const expanded = path.resolve(expandHomeDir(customDir));
if (!dirs.includes(expanded)) {
dirs.push(expanded);
}
}
return dirs;
}
case 'bundled':
return [this.bundledSkillsDir];
case 'extension':
Expand Down
7 changes: 7 additions & 0 deletions packages/vscode-ide-companion/schemas/settings.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,13 @@
"items": {
"type": "string"
}
},
"directories": {
"description": "Additional directories to scan for skills (SKILL.md files). Paths support ~ expansion. Each directory is scanned one level deep for subdirectories containing a SKILL.md file. Skills from these directories are loaded at user level, after the default ~/.qwen/skills/ directory.",
"type": "array",
"items": {
"type": "string"
}
}
}
},
Expand Down
Loading