@encoredigitalgroup/opencode 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,6 +10,9 @@ export declare class SkillCommands {
10
10
  skill: string;
11
11
  };
12
12
  };
13
- private static isSkill;
13
+ static commandTemplate(skillName: string): string;
14
14
  static getTemplate(serverUrl: URL, directory: string, skillName: string): Promise<string>;
15
+ static expandCommandTemplate(output: {
16
+ parts: unknown[];
17
+ }, template: (skillName: string) => Promise<string>): Promise<void>;
15
18
  }
@@ -386,7 +386,7 @@ class FilePickerCommands {
386
386
  }
387
387
 
388
388
  // src/lib/SkillCommands.ts
389
- import { readFile } from "fs/promises";
389
+ var skillMarker = "<encoredigitalgroup-opencode-skill:";
390
390
 
391
391
  class SkillCommands {
392
392
  static getCommands(config) {
@@ -401,8 +401,8 @@ class SkillCommands {
401
401
  }
402
402
  };
403
403
  }
404
- static isSkill(value) {
405
- return typeof value === "object" && value !== null && "location" in value && typeof value.location === "string" && "name" in value && typeof value.name === "string";
404
+ static commandTemplate(skillName) {
405
+ return `${skillMarker}${skillName}>`;
406
406
  }
407
407
  static async getTemplate(serverUrl, directory, skillName) {
408
408
  const url = new URL("/api/skill", serverUrl);
@@ -413,12 +413,22 @@ class SkillCommands {
413
413
  throw new Error(`Unable to list OpenCode skills: ${response.status} ${response.statusText}`);
414
414
  }
415
415
  const responseBody = await response.json();
416
- const skills = typeof responseBody === "object" && responseBody !== null && "data" in responseBody && Array.isArray(responseBody.data) ? responseBody.data.filter(SkillCommands.isSkill) : [];
416
+ const skills = typeof responseBody === "object" && responseBody !== null && "data" in responseBody && Array.isArray(responseBody.data) ? responseBody.data.filter((value) => typeof value === "object" && value !== null && ("content" in value) && typeof value.content === "string" && ("name" in value) && typeof value.name === "string") : [];
417
417
  const skill = skills.find((candidate) => candidate.name === skillName);
418
418
  if (skill === undefined) {
419
419
  throw new Error(`OpenCode skill "${skillName}" is not available.`);
420
420
  }
421
- return readFile(skill.location, "utf8");
421
+ return skill.content;
422
+ }
423
+ static async expandCommandTemplate(output, template) {
424
+ for (const part of output.parts) {
425
+ if (typeof part !== "object" || part === null || !("type" in part) || part.type !== "text" || !("text" in part) || typeof part.text !== "string" || !part.text.startsWith(skillMarker) || !part.text.endsWith(">")) {
426
+ continue;
427
+ }
428
+ const skillName = part.text.slice(skillMarker.length, -1);
429
+ part.text = await template(skillName);
430
+ return;
431
+ }
422
432
  }
423
433
  }
424
434
 
@@ -434,11 +444,14 @@ var plugin = {
434
444
  for (const [command, route] of Object.entries(SkillCommands.getCommands(pluginConfig))) {
435
445
  config.command[command] = {
436
446
  description: route.description,
437
- template: await template(route.skill)
447
+ template: SkillCommands.commandTemplate(route.skill)
438
448
  };
439
449
  }
440
450
  },
441
- "chat.message": async (_input, output) => FilePickerCommands.expand(output, template, pluginConfig)
451
+ "chat.message": async (_input, output) => {
452
+ await SkillCommands.expandCommandTemplate(output, template);
453
+ await FilePickerCommands.expand(output, template, pluginConfig);
454
+ }
442
455
  };
443
456
  }
444
457
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@encoredigitalgroup/opencode",
3
3
  "type": "module",
4
- "version": "0.1.1",
4
+ "version": "0.1.2",
5
5
  "description": "OpenCode file-picker commands for planning skills.",
6
6
  "publishConfig": {
7
7
  "access": "public"