-
-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathindex.ts
More file actions
66 lines (59 loc) · 2.28 KB
/
index.ts
File metadata and controls
66 lines (59 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import type { Plugin } from "@opencode-ai/plugin"
import { getConfig } from "./lib/config"
import { Logger } from "./lib/logger"
import { loadPrompt } from "./lib/prompt"
import { createSessionState } from "./lib/state"
import { createPruneTool } from "./lib/strategies"
import { createChatMessageTransformHandler, createEventHandler } from "./lib/hooks"
const plugin: Plugin = (async (ctx) => {
const config = getConfig(ctx)
if (!config.enabled) {
return {}
}
// Suppress AI SDK warnings
if (typeof globalThis !== 'undefined') {
(globalThis as any).AI_SDK_LOG_WARNINGS = false
}
// Initialize core components
const logger = new Logger(config.debug)
const state = createSessionState()
// Log initialization
logger.info("DCP initialized", {
strategies: config.strategies,
})
return {
"experimental.chat.system.transform": async (_input: unknown, output: { system: string[] }) => {
const syntheticPrompt = loadPrompt("synthetic")
output.system.push(syntheticPrompt)
},
"experimental.chat.messages.transform": createChatMessageTransformHandler(
ctx.client,
state,
logger,
config
),
tool: config.strategies.pruneTool.enabled ? {
prune: createPruneTool({
client: ctx.client,
state,
logger,
config,
workingDirectory: ctx.directory
}),
} : undefined,
config: async (opencodeConfig) => {
// Add prune to primary_tools by mutating the opencode config
// This works because config is cached and passed by reference
if (config.strategies.pruneTool.enabled) {
const existingPrimaryTools = opencodeConfig.experimental?.primary_tools ?? []
opencodeConfig.experimental = {
...opencodeConfig.experimental,
primary_tools: [...existingPrimaryTools, "prune"],
}
logger.info("Added 'prune' to experimental.primary_tools via config mutation")
}
},
event: createEventHandler(ctx.client, config, state, logger, ctx.directory),
}
}) satisfies Plugin
export default plugin