Skip to content
Merged
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
2 changes: 2 additions & 0 deletions apps/server/src/serverLayers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { EnvironmentVariablesLive } from "./persistence/Services/EnvironmentVari

import { TerminalManagerLive } from "./terminal/Layers/Manager";
import { KeybindingsLive } from "./keybindings";
import { SkillServiceLive } from "./skills/SkillService";
import { GitManagerLive } from "./git/Layers/GitManager";
import { GitCoreLive } from "./git/Layers/GitCore";
import { GitHubCliLive } from "./git/Layers/GitHubCli";
Expand Down Expand Up @@ -159,5 +160,6 @@ export function makeServerRuntimeServicesLayer() {
prReviewLayer,
terminalLayer,
KeybindingsLive,
SkillServiceLive,
).pipe(Layer.provideMerge(NodeServices.layer));
}
184 changes: 184 additions & 0 deletions apps/server/src/skills/SkillService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
/**
* SkillService - Effect service for skill CRUD and search operations.
*
* Wraps the shared skill utilities from `@okcode/shared/skill` as an Effect
* service using the project's `ServiceMap.Service` pattern.
*
* @module SkillService
*/
import type {
SkillCreateResult,
SkillListResult,
SkillReadResult,
SkillSearchResult,
} from "@okcode/contracts";
import { Effect, Layer, Schema, ServiceMap } from "effect";
import {
listSkills,
readSkill,
searchSkills,
createSkill,
deleteSkill,
} from "@okcode/shared/skill";

/**
* SkillServiceError - Tagged error for skill service failures.
*/
export class SkillServiceError extends Schema.TaggedErrorClass<SkillServiceError>()(
"SkillServiceError",
{
operation: Schema.String,
detail: Schema.String,
cause: Schema.optional(Schema.Defect),
},
) {
override get message(): string {
return `Skill service error (${this.operation}): ${this.detail}`;
}
}

/**
* SkillServiceShape - Service API for skill CRUD and search operations.
*/
export interface SkillServiceShape {
/**
* List all installed skills.
*/
readonly list: (input: {
readonly cwd?: string | undefined;
}) => Effect.Effect<SkillListResult, SkillServiceError>;

/**
* Read a skill by name.
*/
readonly read: (input: {
readonly name: string;
readonly cwd?: string | undefined;
}) => Effect.Effect<SkillReadResult, SkillServiceError>;

/**
* Create a new skill with scaffold template.
*/
readonly create: (input: {
readonly name: string;
readonly description: string;
readonly scope: "global" | "project";
readonly cwd?: string | undefined;
}) => Effect.Effect<SkillCreateResult, SkillServiceError>;

/**
* Delete a skill.
*/
readonly delete: (input: {
readonly name: string;
readonly scope: "global" | "project";
readonly cwd?: string | undefined;
}) => Effect.Effect<void, SkillServiceError>;

/**
* Search skills by query.
*/
readonly search: (input: {
readonly query: string;
readonly cwd?: string | undefined;
}) => Effect.Effect<SkillSearchResult, SkillServiceError>;
}

/**
* SkillService - Service tag for skill CRUD and search operations.
*/
export class SkillService extends ServiceMap.Service<SkillService, SkillServiceShape>()(
"okcode/skills/SkillService",
) {}

export const SkillServiceLive = Layer.succeed(SkillService, {
list: (input) =>
Effect.try({
try: () => {
const entries = listSkills(input.cwd);
return {
skills: entries.map((e) => ({
name: e.name,
scope: e.scope,
description: e.description,
tags: e.tags,
path: e.path,
})),
};
},
catch: (cause) =>
new SkillServiceError({
operation: "list",
detail: cause instanceof Error ? cause.message : String(cause),
cause: cause instanceof Error ? cause : undefined,
}),
}),

read: (input) =>
Effect.try({
try: () => {
const result = readSkill(input.name, input.cwd);
if (!result) {
throw new Error(`Skill "${input.name}" not found`);
}
return {
name: result.name,
scope: result.scope,
description: result.description,
content: result.content.raw,
path: result.path,
tags: result.tags,
};
},
catch: (cause) =>
new SkillServiceError({
operation: "read",
detail: cause instanceof Error ? cause.message : String(cause),
cause: cause instanceof Error ? cause : undefined,
}),
}),

create: (input) =>
Effect.try({
try: () => createSkill(input.name, input.description, input.scope, input.cwd),
catch: (cause) =>
new SkillServiceError({
operation: "create",
detail: cause instanceof Error ? cause.message : String(cause),
cause: cause instanceof Error ? cause : undefined,
}),
}),

delete: (input) =>
Effect.try({
try: () => deleteSkill(input.name, input.scope, input.cwd),
catch: (cause) =>
new SkillServiceError({
operation: "delete",
detail: cause instanceof Error ? cause.message : String(cause),
cause: cause instanceof Error ? cause : undefined,
}),
}),

search: (input) =>
Effect.try({
try: () => {
const entries = searchSkills(input.query, input.cwd);
return {
skills: entries.map((e) => ({
name: e.name,
scope: e.scope,
description: e.description,
tags: e.tags,
path: e.path,
})),
};
},
catch: (cause) =>
new SkillServiceError({
operation: "search",
detail: cause instanceof Error ? cause.message : String(cause),
cause: cause instanceof Error ? cause : undefined,
}),
}),
} satisfies SkillServiceShape);
28 changes: 28 additions & 0 deletions apps/server/src/wsServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ import { decodeJsonResult, formatSchemaError } from "@okcode/shared/schemaJson";
import { PrReview } from "./prReview/Services/PrReview.ts";
import { GitActionExecutionError } from "./git/Errors.ts";
import { EnvironmentVariables } from "./persistence/Services/EnvironmentVariables.ts";
import { SkillService } from "./skills/SkillService.ts";
import { resolveRuntimeEnvironment } from "./runtimeEnvironment.ts";

/**
Expand Down Expand Up @@ -263,6 +264,7 @@ export type ServerRuntimeServices =
| PrReview
| TerminalManager
| Keybindings
| SkillService
| Open
| AnalyticsService
| EnvironmentVariables;
Expand Down Expand Up @@ -653,6 +655,7 @@ export const createServer = Effect.fn(function* (): Effect.fn.Return<
const prReview = yield* PrReview;
const { openInEditor } = yield* Open;
const environmentVariables = yield* EnvironmentVariables;
const skillService = yield* SkillService;

const subscriptionsScope = yield* Scope.make("sequential");
yield* Effect.addFinalizer(() => Scope.close(subscriptionsScope, Exit.void));
Expand Down Expand Up @@ -1177,6 +1180,31 @@ export const createServer = Effect.fn(function* (): Effect.fn.Return<
return { path: pickedPath };
}

case WS_METHODS.skillList: {
const body = stripRequestTag(request.body);
return yield* skillService.list(body);
}

case WS_METHODS.skillRead: {
const body = stripRequestTag(request.body);
return yield* skillService.read(body);
}

case WS_METHODS.skillCreate: {
const body = stripRequestTag(request.body);
return yield* skillService.create(body);
}

case WS_METHODS.skillDelete: {
const body = stripRequestTag(request.body);
return yield* skillService.delete(body);
}

case WS_METHODS.skillSearch: {
const body = stripRequestTag(request.body);
return yield* skillService.search(body);
}

default: {
const _exhaustiveCheck: never = request.body;
return yield* new RouteRequestError({
Expand Down
Loading
Loading