Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
Binary file added extensions/claude/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions extensions/claude/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "claude",
"displayName": "Claude Skills",
"description": "Registers skills from the Claude skills directory ($HOME/.claude/skills)",
"version": "0.0.1-next",
"icon": "icon.png",
"publisher": "kortex",
"license": "Apache-2.0",
"engines": {
"kortex": "^0.0.1"
},
"main": "./dist/extension.js",
"source": "./src/extension.ts",
"scripts": {
"build": "vite build && node ./scripts/build.js",
"test": "vitest run --coverage",
"test:watch": "vitest watch --coverage",
"watch": "vite build --watch"
},
"dependencies": {
"inversify": "^7.7.1"
},
"devDependencies": {
"@kortex-app/api": "workspace:*",
"adm-zip": "^0.5.16",
"mkdirp": "^3.0.1",
"vite": "^7.1.2",
"vitest": "^4.0.10"
}
}
46 changes: 46 additions & 0 deletions extensions/claude/scripts/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env node
/**********************************************************************
* Copyright (C) 2026 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
***********************************************************************/

const AdmZip = require('adm-zip');
const path = require('path');
const packageJson = require('../package.json');
const fs = require('fs');
const { mkdirp } = require('mkdirp');

const destFile = path.resolve(__dirname, `../${packageJson.name}.cdix`);
const builtinDirectory = path.resolve(__dirname, '../builtin');
const unzippedDirectory = path.resolve(builtinDirectory, `${packageJson.name}.cdix`);
// remove the .cdix file before zipping
if (fs.existsSync(destFile)) {
fs.rmSync(destFile);
}
// remove the builtin folder before zipping
if (fs.existsSync(builtinDirectory)) {
fs.rmSync(builtinDirectory, { recursive: true, force: true });
}

const zip = new AdmZip();
zip.addLocalFolder(path.resolve(__dirname, '../'));
zip.writeZip(destFile);

// create unzipped built-in
mkdirp(unzippedDirectory).then(() => {
const unzip = new AdmZip(destFile);
unzip.extractAllTo(unzippedDirectory);
});
63 changes: 63 additions & 0 deletions extensions/claude/src/claude-extension.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**********************************************************************
* Copyright (C) 2026 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
***********************************************************************/

import type { ExtensionContext } from '@kortex-app/api';
import type { Container } from 'inversify';
import { beforeEach, describe, expect, test, vi } from 'vitest';

import { ClaudeExtension } from '/@/claude-extension';
import { ClaudeSkillsManager } from '/@/manager/claude-skills-manager';

vi.mock(import('@kortex-app/api'));
vi.mock(import('/@/manager/claude-skills-manager'));

class TestClaudeExtension extends ClaudeExtension {
getContainer(): Container | undefined {
return super.getContainer();
}
}

describe('ClaudeExtension', () => {
let extensionContext: ExtensionContext;
let claudeExtension: TestClaudeExtension;

beforeEach(() => {
vi.resetAllMocks();
extensionContext = { subscriptions: [] } as unknown as ExtensionContext;
claudeExtension = new TestClaudeExtension(extensionContext);
});

test('activate', async () => {
await claudeExtension.activate();
expect(ClaudeSkillsManager.prototype.init).toHaveBeenCalled();
});

test('activate handles error during container creation', async () => {
const faultyGetAsync = vi.fn().mockRejectedValue(new Error('Container creation failed'));
vi.spyOn(claudeExtension, 'getContainer').mockReturnValue({
getAsync: faultyGetAsync,
} as unknown as Container);
await expect(claudeExtension.activate()).rejects.toThrow('Container creation failed');
});

test('deactivate disposes subscriptions', async () => {
await claudeExtension.activate();
await claudeExtension.deactivate();
expect(ClaudeSkillsManager.prototype.dispose).toHaveBeenCalled();
});
});
73 changes: 73 additions & 0 deletions extensions/claude/src/claude-extension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**********************************************************************
* Copyright (C) 2026 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
***********************************************************************/

import type { ExtensionContext } from '@kortex-app/api';
import { provider } from '@kortex-app/api';
import type { Container } from 'inversify';

import { InversifyBinding } from '/@/inject/inversify-binding';
import { ClaudeSkillsManager } from '/@/manager/claude-skills-manager';

export class ClaudeExtension {
#extensionContext: ExtensionContext;

#inversifyBinding: InversifyBinding | undefined;
#container: Container | undefined;
#claudeSkillsManager: ClaudeSkillsManager | undefined;

constructor(extensionContext: ExtensionContext) {
this.#extensionContext = extensionContext;
}

async activate(): Promise<void> {
const claudeProvider = provider.createProvider({
name: 'Claude',
status: 'unknown',
id: 'claude',
images: {
icon: './icon.png',
logo: {
dark: './icon.png',
light: './icon.png',
},
},
});

this.#inversifyBinding = new InversifyBinding(claudeProvider, this.#extensionContext);
this.#container = await this.#inversifyBinding.initBindings();

try {
this.#claudeSkillsManager = await this.getContainer()?.getAsync(ClaudeSkillsManager);
} catch (e) {
console.error('Error while creating the Claude skills manager', e);
throw e;
}

await this.#claudeSkillsManager?.init();
}

protected getContainer(): Container | undefined {
return this.#container;
}

async deactivate(): Promise<void> {
await this.#inversifyBinding?.dispose();
this.#claudeSkillsManager?.dispose();
this.#claudeSkillsManager = undefined;
}
}
48 changes: 48 additions & 0 deletions extensions/claude/src/extension.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**********************************************************************
* Copyright (C) 2026 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
***********************************************************************/

import type { ExtensionContext } from '@kortex-app/api';
import { beforeEach, expect, test, vi } from 'vitest';

import { ClaudeExtension } from './claude-extension';
import { activate, deactivate } from './extension';

let extensionContextMock: ExtensionContext;

vi.mock(import('./claude-extension'));

beforeEach(() => {
vi.restoreAllMocks();
vi.resetAllMocks();

extensionContextMock = {} as ExtensionContext;
});

test('should initialize and activate the ClaudeExtension when activate is called', async () => {
await activate(extensionContextMock);

expect(ClaudeExtension.prototype.activate).toHaveBeenCalled();
});

test('should call deactivate when deactivate is called', async () => {
await activate(extensionContextMock);

await deactivate();

expect(ClaudeExtension.prototype.deactivate).toHaveBeenCalled();
});
33 changes: 33 additions & 0 deletions extensions/claude/src/extension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**********************************************************************
* Copyright (C) 2026 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
***********************************************************************/

import type { ExtensionContext } from '@kortex-app/api';

import { ClaudeExtension } from './claude-extension';

let claudeExtension: ClaudeExtension | undefined;

export async function activate(extensionContext: ExtensionContext): Promise<void> {
claudeExtension ??= new ClaudeExtension(extensionContext);
await claudeExtension.activate();
}

export async function deactivate(): Promise<void> {
await claudeExtension?.deactivate();
claudeExtension = undefined;
}
63 changes: 63 additions & 0 deletions extensions/claude/src/inject/inversify-binding.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**********************************************************************
* Copyright (C) 2026 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
***********************************************************************/

import type { ExtensionContext, Provider } from '@kortex-app/api';
import { Container } from 'inversify';
import { beforeEach, describe, expect, test, vi } from 'vitest';

import { managersModule } from '/@/manager/_manager-module';
import { ClaudeSkillsManager } from '/@/manager/claude-skills-manager';

import { InversifyBinding } from './inversify-binding';
import { ClaudeProviderSymbol, ExtensionContextSymbol } from './symbol';

let inversifyBinding: InversifyBinding;

const providerMock = {} as Provider;
const extensionContextMock = {} as ExtensionContext;

vi.mock(import('inversify'));

describe('InversifyBinding', () => {
beforeEach(() => {
vi.resetAllMocks();
inversifyBinding = new InversifyBinding(providerMock, extensionContextMock);
vi.mocked(Container.prototype.bind).mockReturnValue({
toConstantValue: vi.fn(),
} as unknown as ReturnType<typeof Container.prototype.bind>);
});

test('should initialize bindings correctly', async () => {
const container = await inversifyBinding.initBindings();

await container.getAsync(ClaudeSkillsManager);

expect(vi.mocked(Container.prototype.bind)).toHaveBeenCalledWith(ExtensionContextSymbol);
expect(vi.mocked(Container.prototype.bind)).toHaveBeenCalledWith(ClaudeProviderSymbol);

expect(vi.mocked(Container.prototype.load)).toHaveBeenCalledWith(managersModule);
});

test('should dispose of the container', async () => {
const container = await inversifyBinding.initBindings();

await inversifyBinding.dispose();

expect(container.unbindAll).toHaveBeenCalled();
});
});
Loading
Loading