opencode-acp-provider 1.1.0 → 1.1.1

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.
package/src/prompt.ts CHANGED
@@ -18,12 +18,29 @@ export function isAuxiliaryRequest(kind: unknown) {
18
18
  return kind === "title" || kind === "generate" || kind === "compaction"
19
19
  }
20
20
 
21
+ /**
22
+ * OpenCode injects harness blocks such as `<system-reminder>` (plan mode,
23
+ * opened-file notes) and `<system-update>` into user text. ACP agents run on
24
+ * their own instructions, so drop them. Only whole blocks that start and end
25
+ * on their own lines match, so a user mentioning a tag inline is untouched.
26
+ */
27
+ const SYSTEM_BLOCK = /(^|\n)[ \t]*<(system(?:[-_][a-z]+)*)(?:\s[^>]*)?>[\s\S]*?<\/\2>[ \t]*(?=\n|$)/gi
28
+
29
+ export function stripSystemBlocks(text: string): string {
30
+ if (!text.includes("<system")) return text
31
+ const stripped = text.replace(SYSTEM_BLOCK, "$1")
32
+ return stripped === text ? text : stripped.replace(/\n{3,}/g, "\n\n").trim()
33
+ }
34
+
21
35
  export function textOf(message: ChatMessage): string {
22
- if (typeof message.content === "string") return message.content
23
- if (!Array.isArray(message.content)) return ""
24
- return message.content
25
- .flatMap((part) => part?.type === "text" && typeof part.text === "string" && part.text ? [part.text] : [])
26
- .join("\n")
36
+ const text = typeof message.content === "string"
37
+ ? message.content
38
+ : Array.isArray(message.content)
39
+ ? message.content
40
+ .flatMap((part) => part?.type === "text" && typeof part.text === "string" && part.text ? [part.text] : [])
41
+ .join("\n")
42
+ : ""
43
+ return message.role === "user" ? stripSystemBlocks(text) : text
27
44
  }
28
45
 
29
46
  const conversational = (message: ChatMessage) => message.role === "user" || message.role === "assistant"