@koriit/opencode-claude-bridge 0.1.8 → 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/logger.ts +53 -23
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/logger.ts
CHANGED
|
@@ -25,32 +25,62 @@ export interface Logger {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* Note: client.log() (HTTP POST to /log) was tried but is unreliable during
|
|
33
|
-
* the config hook because it fires during server bootstrap before the /log
|
|
34
|
-
* endpoint is ready. Direct stderr write is the safe, synchronous alternative.
|
|
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.
|
|
35
31
|
*/
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
interface CoreLog {
|
|
33
|
+
create(tags?: Record<string, unknown>): {
|
|
34
|
+
info(msg: string): void
|
|
35
|
+
warn(msg: string): void
|
|
36
|
+
}
|
|
37
|
+
}
|
|
39
38
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
|
47
59
|
}
|
|
60
|
+
}
|
|
48
61
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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)
|
|
52
82
|
}
|
|
53
|
-
}
|
|
83
|
+
}
|
|
54
84
|
|
|
55
85
|
/**
|
|
56
86
|
* Create a logger bound to the resolved `strict` flag. The hook itself is
|
|
@@ -61,13 +91,13 @@ export function createLogger(strict: boolean): Logger {
|
|
|
61
91
|
let warningCount = 0
|
|
62
92
|
return {
|
|
63
93
|
info(msg) {
|
|
64
|
-
|
|
94
|
+
void emit("INFO", msg)
|
|
65
95
|
},
|
|
66
96
|
warn(msg, opts) {
|
|
67
97
|
const fatalInStrict = opts?.fatalInStrict ?? true
|
|
68
98
|
warningCount++
|
|
69
99
|
if (strict && fatalInStrict) throw new BridgeError(msg)
|
|
70
|
-
|
|
100
|
+
void emit("WARN", msg)
|
|
71
101
|
},
|
|
72
102
|
hadWarnings() {
|
|
73
103
|
return warningCount > 0
|