@koriit/opencode-claude-bridge 0.1.10 → 0.1.11
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/package.json +1 -1
- package/src/index.ts +0 -3
- package/src/logger.ts +53 -20
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koriit/opencode-claude-bridge",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
4
4
|
"description": "An OpenCode plugin that bridges enabled Claude Code plugins (commands, agents, skills, MCP, LSP) into OpenCode at runtime, namespaced so they never shadow your existing items.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
package/src/index.ts
CHANGED
|
@@ -51,9 +51,6 @@ export const server: Plugin = async (_input, options) => {
|
|
|
51
51
|
|
|
52
52
|
return {
|
|
53
53
|
config: async (cfg) => {
|
|
54
|
-
// TEMPORARY DIAGNOSTIC — remove before next release
|
|
55
|
-
process.stderr.write(`[ocb-debug] process.argv=${JSON.stringify(process.argv)}\n`)
|
|
56
|
-
process.stderr.write(`[ocb-debug] has --print-logs: ${process.argv.includes("--print-logs")}\n`)
|
|
57
54
|
const logger = createLogger(bridge.strict)
|
|
58
55
|
try {
|
|
59
56
|
// Replay parse-time validation warnings (strict-promotable).
|
package/src/logger.ts
CHANGED
|
@@ -25,29 +25,62 @@ export interface Logger {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* Gated on --print-logs to match OpenCode's own log-visibility behaviour.
|
|
28
|
+
* Minimal duck-type for the OpenCode core logger service we resolve at runtime.
|
|
29
|
+
* `@opencode-ai/core` is private/unpublished; we access it via dynamic import
|
|
30
|
+
* against the Bun module registry that the host worker already populated.
|
|
32
31
|
*/
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
interface CoreLog {
|
|
33
|
+
create(tags?: Record<string, unknown>): {
|
|
34
|
+
info(msg: string): void
|
|
35
|
+
warn(msg: string): void
|
|
36
|
+
}
|
|
37
|
+
}
|
|
36
38
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Resolve the core log module at runtime by hitting Bun's module registry.
|
|
41
|
+
* The Bun Worker that hosts plugins already executed
|
|
42
|
+
* `import * as Log from "@opencode-ai/core/util/log"`
|
|
43
|
+
* and called `Log.init({ print: ... })`, so the registry holds a fully
|
|
44
|
+
* configured instance. A dynamic import of the same specifier returns it.
|
|
45
|
+
*
|
|
46
|
+
* Falls back to a plain stderr writer if the import fails (tests, non-OpenCode
|
|
47
|
+
* environments) — in that case output is always emitted so tests can capture it.
|
|
48
|
+
*/
|
|
49
|
+
async function resolveCoreLog(): Promise<CoreLog | null> {
|
|
50
|
+
try {
|
|
51
|
+
// @opencode-ai/core is a private package bundled into the OpenCode binary.
|
|
52
|
+
// The dynamic import resolves against Bun's module registry at runtime —
|
|
53
|
+
// the host worker already loaded and initialized it.
|
|
54
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
55
|
+
// @ts-ignore — not in node_modules; resolved from the Bun bundle at runtime
|
|
56
|
+
return await import("@opencode-ai/core/util/log") as CoreLog
|
|
57
|
+
} catch {
|
|
58
|
+
return null
|
|
44
59
|
}
|
|
60
|
+
}
|
|
45
61
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
62
|
+
// Kick off resolution immediately so it's ready before the first log call.
|
|
63
|
+
const coreLogPromise = resolveCoreLog()
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Fallback writer used when the core log module is unavailable.
|
|
67
|
+
* Always writes to stderr — correct for test environments.
|
|
68
|
+
*/
|
|
69
|
+
function fallbackWrite(level: "INFO" | "WARN", msg: string): void {
|
|
70
|
+
const ts = new Date().toISOString().split(".")[0]
|
|
71
|
+
process.stderr.write(`${level.padEnd(5)} ${ts} service=opencode-claude-bridge ${msg}\n`)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async function emit(level: "INFO" | "WARN", msg: string): Promise<void> {
|
|
75
|
+
const core = await coreLogPromise
|
|
76
|
+
if (core) {
|
|
77
|
+
const svc = core.create({ service: "opencode-claude-bridge" })
|
|
78
|
+
if (level === "INFO") svc.info(msg)
|
|
79
|
+
else svc.warn(msg)
|
|
80
|
+
} else {
|
|
81
|
+
fallbackWrite(level, msg)
|
|
49
82
|
}
|
|
50
|
-
}
|
|
83
|
+
}
|
|
51
84
|
|
|
52
85
|
/**
|
|
53
86
|
* Create a logger bound to the resolved `strict` flag. The hook itself is
|
|
@@ -58,13 +91,13 @@ export function createLogger(strict: boolean): Logger {
|
|
|
58
91
|
let warningCount = 0
|
|
59
92
|
return {
|
|
60
93
|
info(msg) {
|
|
61
|
-
|
|
94
|
+
void emit("INFO", msg)
|
|
62
95
|
},
|
|
63
96
|
warn(msg, opts) {
|
|
64
97
|
const fatalInStrict = opts?.fatalInStrict ?? true
|
|
65
98
|
warningCount++
|
|
66
99
|
if (strict && fatalInStrict) throw new BridgeError(msg)
|
|
67
|
-
|
|
100
|
+
void emit("WARN", msg)
|
|
68
101
|
},
|
|
69
102
|
hadWarnings() {
|
|
70
103
|
return warningCount > 0
|