mirror of
https://github.com/rohitg00/skillkit.git
synced 2026-11-18 18:04:26 +00:00
refactor: deduplicate OpenClaw adapter, fix clawdbot config
Follow-up to #86 — cleanup without changing contributor attribution. - OpenClawAdapter extends ClawdbotAdapter (removes 80 lines of copy-paste) - Revert clawdbot config to legacy paths (.clawdbot/skills, AGENTS.md) - OpenClaw detection: ~/.openclaw or openclaw.json - Widen ClawdbotAdapter property types for extensibility - Fix tests: adapter count 44→45, remove stale detection assertions
This commit is contained in:
@@ -35,10 +35,10 @@ const ALL_AGENTS = AgentType.options;
|
||||
|
||||
describe('Agent Adapters', () => {
|
||||
describe('getAllAdapters', () => {
|
||||
it('should return all 44 registered adapters', () => {
|
||||
it('should return all 45 registered adapters', () => {
|
||||
const adapters = getAllAdapters();
|
||||
expect(adapters).toBeInstanceOf(Array);
|
||||
expect(adapters.length).toBe(44);
|
||||
expect(adapters.length).toBe(45);
|
||||
});
|
||||
|
||||
it('should include common agents', () => {
|
||||
|
||||
@@ -236,16 +236,6 @@ describe('ClawdbotAdapter', () => {
|
||||
});
|
||||
|
||||
describe('isDetected', () => {
|
||||
it('should detect Clawdbot from workspace skills directory', async () => {
|
||||
mockExistsSync.mockImplementation((path) => {
|
||||
return path === join(process.cwd(), 'skills');
|
||||
});
|
||||
|
||||
const detected = await adapter.isDetected();
|
||||
|
||||
expect(detected).toBe(true);
|
||||
});
|
||||
|
||||
it('should detect Clawdbot from global directory', async () => {
|
||||
mockExistsSync.mockImplementation((path) => {
|
||||
return path === join(homedir(), '.clawdbot');
|
||||
@@ -287,7 +277,6 @@ describe('ClawdbotAdapter', () => {
|
||||
|
||||
await adapter.isDetected();
|
||||
|
||||
expect(mockExistsSync).toHaveBeenCalledWith(join(process.cwd(), 'skills'));
|
||||
expect(mockExistsSync).toHaveBeenCalledWith(join(homedir(), '.clawdbot'));
|
||||
expect(mockExistsSync).toHaveBeenCalledWith(join(process.cwd(), 'clawdbot.json'));
|
||||
});
|
||||
|
||||
@@ -10,9 +10,9 @@ const config = AGENT_CONFIG.clawdbot;
|
||||
|
||||
export class ClawdbotAdapter implements AgentAdapter {
|
||||
readonly type: AgentType = 'clawdbot';
|
||||
readonly name = 'Clawdbot';
|
||||
readonly skillsDir = config.skillsDir;
|
||||
readonly configFile = config.configFile;
|
||||
readonly name: string = 'Clawdbot';
|
||||
readonly skillsDir: string = config.skillsDir;
|
||||
readonly configFile: string = config.configFile;
|
||||
|
||||
generateConfig(skills: Skill[]): string {
|
||||
const enabledSkills = skills.filter(s => s.enabled);
|
||||
|
||||
@@ -1,99 +1,22 @@
|
||||
import { existsSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { homedir } from 'node:os';
|
||||
import type { AgentAdapter } from './base.js';
|
||||
import { createSkillXml } from './base.js';
|
||||
import type { Skill, AgentType } from '@skillkit/core';
|
||||
import { ClawdbotAdapter } from './clawdbot.js';
|
||||
import type { AgentType } from '@skillkit/core';
|
||||
import { AGENT_CONFIG } from '@skillkit/core';
|
||||
|
||||
const config = AGENT_CONFIG.openclaw;
|
||||
|
||||
/**
|
||||
* OpenClaw Agent Adapter
|
||||
*
|
||||
* OpenClaw (formerly Clawdbot) is a local-first AI agent framework with a
|
||||
* persistent gateway daemon. Skills use an extended YAML frontmatter schema
|
||||
* with `permissions`, `triggers`, and `metadata.openclaw.requires` fields.
|
||||
*
|
||||
* Key differences from Claude Code:
|
||||
* - Skills dir: `skills/` (not `.claude/skills/`)
|
||||
* - Global skills: `~/.openclaw/skills/`
|
||||
* - Config: `~/.openclaw/openclaw.json`
|
||||
* - SKILL.md frontmatter includes: permissions, triggers, metadata.openclaw
|
||||
* - Gateway loads skills contextually per-agent at runtime
|
||||
* - Skills are organized by department: skills/<dept>/<name>/SKILL.md
|
||||
*/
|
||||
export class OpenClawAdapter implements AgentAdapter {
|
||||
readonly type: AgentType = 'openclaw';
|
||||
readonly name = 'OpenClaw';
|
||||
readonly skillsDir = config.skillsDir;
|
||||
readonly configFile = config.configFile;
|
||||
export class OpenClawAdapter extends ClawdbotAdapter {
|
||||
override readonly type: AgentType = 'openclaw';
|
||||
override readonly name = 'OpenClaw';
|
||||
override readonly skillsDir = config.skillsDir;
|
||||
override readonly configFile = config.configFile;
|
||||
|
||||
generateConfig(skills: Skill[]): string {
|
||||
const enabledSkills = skills.filter(s => s.enabled);
|
||||
|
||||
if (enabledSkills.length === 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const skillsXml = enabledSkills.map(createSkillXml).join('\n\n');
|
||||
|
||||
return `<skills_system priority="1">
|
||||
|
||||
## Available Skills
|
||||
|
||||
<!-- SKILLS_TABLE_START -->
|
||||
<usage>
|
||||
When users ask you to perform tasks, check if any of the available skills below can help complete the task more effectively. Skills provide specialized capabilities and domain knowledge.
|
||||
|
||||
How to use skills:
|
||||
- Invoke: \`skillkit read <skill-name>\` or \`npx skillkit read <skill-name>\`
|
||||
- The skill content will load with detailed instructions on how to complete the task
|
||||
- Base directory provided in output for resolving bundled resources (references/, scripts/, assets/)
|
||||
|
||||
Usage notes:
|
||||
- Only use skills listed in <available_skills> below
|
||||
- Do not invoke a skill that is already loaded in your context
|
||||
- Each skill invocation is stateless
|
||||
</usage>
|
||||
|
||||
<available_skills>
|
||||
|
||||
${skillsXml}
|
||||
|
||||
</available_skills>
|
||||
<!-- SKILLS_TABLE_END -->
|
||||
|
||||
</skills_system>`;
|
||||
}
|
||||
|
||||
parseConfig(content: string): string[] {
|
||||
const skillNames: string[] = [];
|
||||
const skillRegex = /<name>([^<]+)<\/name>/g;
|
||||
let match;
|
||||
|
||||
while ((match = skillRegex.exec(content)) !== null) {
|
||||
skillNames.push(match[1].trim());
|
||||
}
|
||||
|
||||
return skillNames;
|
||||
}
|
||||
|
||||
getInvokeCommand(skillName: string): string {
|
||||
return `skillkit read ${skillName}`;
|
||||
}
|
||||
|
||||
async isDetected(): Promise<boolean> {
|
||||
// OpenClaw workspace: skills/ dir at project root
|
||||
const projectSkills = join(process.cwd(), 'skills');
|
||||
// OpenClaw global config
|
||||
override async isDetected(): Promise<boolean> {
|
||||
const globalOpenClaw = join(homedir(), '.openclaw');
|
||||
// OpenClaw config file
|
||||
const openclawConfig = join(process.cwd(), 'openclaw.json');
|
||||
|
||||
return (
|
||||
(existsSync(projectSkills) && existsSync(globalOpenClaw)) ||
|
||||
existsSync(openclawConfig)
|
||||
);
|
||||
return existsSync(globalOpenClaw) || existsSync(openclawConfig);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,22 +111,15 @@ export const AGENT_CONFIG: Record<AgentType, AgentDirectoryConfig> = {
|
||||
supportsAutoDiscovery: true,
|
||||
},
|
||||
|
||||
// Clawdbot (legacy name for OpenClaw)
|
||||
clawdbot: {
|
||||
skillsDir: 'skills',
|
||||
configFile: 'CLAUDE.md',
|
||||
altSkillsDirs: ['.clawdbot/skills', '~/.openclaw/skills'],
|
||||
globalSkillsDir: '~/.openclaw/skills',
|
||||
skillsDir: '.clawdbot/skills',
|
||||
configFile: 'AGENTS.md',
|
||||
altSkillsDirs: ['skills', '~/.clawdbot/skills'],
|
||||
configFormat: 'xml',
|
||||
usesFrontmatter: true,
|
||||
frontmatterFields: [
|
||||
'name', 'description', 'version', 'scan_exempt',
|
||||
'permissions', 'triggers', 'metadata',
|
||||
],
|
||||
supportsAutoDiscovery: true,
|
||||
},
|
||||
|
||||
// OpenClaw (same as clawdbot — rebranded)
|
||||
openclaw: {
|
||||
skillsDir: 'skills',
|
||||
configFile: 'CLAUDE.md',
|
||||
|
||||
Reference in New Issue
Block a user