Skip to content

Commit f85f6f3

Browse files
authored
Merge pull request #482 from Opencode-DCP/dev
weird bullshit opencode esm module changes
2 parents e95c9ca + d28afa7 commit f85f6f3

File tree

7 files changed

+38
-39
lines changed

7 files changed

+38
-39
lines changed

index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ import {
1919
} from "./lib/hooks"
2020
import { configureClientAuth, isSecureMode } from "./lib/auth"
2121

22-
const plugin: Plugin = (async (ctx) => {
22+
const id = "opencode-dynamic-context-pruning"
23+
24+
const server: Plugin = (async (ctx) => {
2325
const config = getConfig(ctx)
2426

2527
if (!config.enabled) {
@@ -133,4 +135,7 @@ const plugin: Plugin = (async (ctx) => {
133135
}
134136
}) satisfies Plugin
135137

136-
export default plugin
138+
export default {
139+
id,
140+
server,
141+
}

lib/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { readFileSync, writeFileSync, existsSync, mkdirSync, statSync } from "fs"
22
import { join, dirname } from "path"
33
import { homedir } from "os"
4-
import * as jsoncParser from "jsonc-parser"
4+
import { parse } from "jsonc-parser/lib/esm/main.js"
55
import type { PluginInput } from "@opencode-ai/plugin"
66

77
type Permission = "ask" | "allow" | "deny"
@@ -773,7 +773,7 @@ function loadConfigFile(configPath: string): ConfigLoadResult {
773773
}
774774

775775
try {
776-
const parsed = jsoncParser.parse(fileContent, undefined, { allowTrailingComma: true })
776+
const parsed = parse(fileContent, undefined, { allowTrailingComma: true })
777777
if (parsed === undefined || parsed === null) {
778778
return { data: null, parseError: "Config file is empty or invalid" }
779779
}

lib/prompts/compress-message.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@ During general cleanup, compress all medium and high-priority messages that are
3939
Optimize for reducing context footprint, not for grouping messages by topic.
4040
Do not compress away still-active instructions, unresolved questions, or constraints that are likely to matter soon.
4141
Prioritize the earliest messages in the context as they will be the least relevant to the active task.
42+
General cleanup should be done periodically between other normal compression tool passes, not as the primary form of compression.
4243
`

lib/token-utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { SessionState, WithParts } from "./state"
22
import { AssistantMessage, UserMessage } from "@opencode-ai/sdk/v2"
33
import { Logger } from "./logger"
4-
import * as anthropicTokenizer from "@anthropic-ai/tokenizer"
4+
import * as _anthropicTokenizer from "@anthropic-ai/tokenizer"
5+
const anthropicCountTokens = (_anthropicTokenizer.countTokens ??
6+
(_anthropicTokenizer as any).default?.countTokens) as typeof _anthropicTokenizer.countTokens
57
import { getLastUserMessage } from "./messages/query"
68

79
export function getCurrentTokenUsage(state: SessionState, messages: WithParts[]): number {
@@ -67,7 +69,7 @@ export function getCurrentParams(
6769
export function countTokens(text: string): number {
6870
if (!text) return 0
6971
try {
70-
return anthropicTokenizer.countTokens(text)
72+
return anthropicCountTokens(text)
7173
} catch {
7274
return Math.round(text.length / 4)
7375
}

package-lock.json

Lines changed: 1 addition & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66
"description": "OpenCode plugin that optimizes token usage by pruning obsolete tool outputs from conversation context",
77
"main": "./dist/index.js",
88
"types": "./dist/index.d.ts",
9+
"exports": {
10+
".": {
11+
"types": "./dist/index.d.ts",
12+
"import": "./dist/index.js"
13+
},
14+
"./server": {
15+
"types": "./dist/index.d.ts",
16+
"import": "./dist/index.js"
17+
}
18+
},
919
"scripts": {
1020
"clean": "rm -rf dist",
1121
"build": "npm run clean && tsc",
@@ -39,12 +49,11 @@
3949
"author": "tarquinen",
4050
"license": "AGPL-3.0-or-later",
4151
"peerDependencies": {
42-
"@opencode-ai/plugin": ">=0.13.7"
52+
"@opencode-ai/plugin": ">=1.2.0"
4353
},
4454
"dependencies": {
4555
"@anthropic-ai/tokenizer": "^0.0.4",
4656
"@opencode-ai/sdk": "^1.3.2",
47-
"fuzzball": "^2.2.3",
4857
"jsonc-parser": "^3.3.1",
4958
"zod": "^4.3.6"
5059
},

scripts/verify-package.mjs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ function assertPackageJsonShape() {
6666
fail(`package.json main must remain ./dist/index.js, found ${pkg.main ?? "<missing>"}`)
6767
}
6868

69+
if (pkg.exports?.["."]?.import !== "./dist/index.js") {
70+
fail("expected package.json exports['.'].import to be './dist/index.js'")
71+
}
72+
73+
if (pkg.exports?.["./server"]?.import !== "./dist/index.js") {
74+
fail("expected package.json exports['./server'].import to be './dist/index.js'")
75+
}
76+
6977
const files = Array.isArray(pkg.files) ? pkg.files : []
7078
for (const entry of ["dist/", "README.md", "LICENSE"]) {
7179
if (!files.includes(entry)) {
@@ -177,6 +185,10 @@ function validateRuntimeImportGraph() {
177185
continue
178186
}
179187

188+
if (entry.specifier === "jsonc-parser/lib/esm/main.js") {
189+
continue
190+
}
191+
180192
const packageName = getPackageName(entry.specifier)
181193
if (builtinNames.has(packageName)) continue
182194

0 commit comments

Comments
 (0)