@dlacaille/opencode-copilot-instructions 0.2.0 → 0.3.0

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.ts +19 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dlacaille/opencode-copilot-instructions",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "OpenCode plugin that loads GitHub Copilot custom instruction files",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/index.ts CHANGED
@@ -28,6 +28,24 @@ function getRepoRelativePath(
28
28
  return relative;
29
29
  }
30
30
 
31
+ function appendInstructions<Content>(
32
+ result: { content?: string | ReadonlyArray<Content>; output?: unknown },
33
+ text: string,
34
+ ): string | ReadonlyArray<Content | { type: "text"; text: string }> {
35
+ const { content, output } = result;
36
+ if (Array.isArray(content)) return [...content, { type: "text", text }];
37
+ // Without content, the model would otherwise see only the output, so keep it in the text.
38
+ const existing =
39
+ typeof content === "string"
40
+ ? content
41
+ : output === undefined
42
+ ? ""
43
+ : typeof output === "string"
44
+ ? output
45
+ : JSON.stringify(output, null, 2);
46
+ return existing ? `${existing}\n\n${text}` : text;
47
+ }
48
+
31
49
  export default Plugin.define({
32
50
  id: "copilot-instructions",
33
51
  async setup(ctx) {
@@ -101,11 +119,9 @@ export default Plugin.define({
101
119
  if (!text) return;
102
120
  if (event.status !== "completed") return;
103
121
 
104
- const existing =
105
- typeof event.result.content === "string" ? event.result.content : "";
106
122
  event.result = {
107
123
  ...event.result,
108
- content: existing ? `${existing}\n\n${text}` : text,
124
+ content: appendInstructions(event.result, text),
109
125
  };
110
126
  });
111
127