opencode-claude-code-acpbridge 0.7.0 → 0.9.0
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/CHANGELOG.md +183 -0
- package/README.md +135 -40
- package/dist/acp/claude-config.d.ts +23 -4
- package/dist/acp/claude-config.d.ts.map +1 -1
- package/dist/acp/claude-config.js +25 -10
- package/dist/acp/claude-config.js.map +1 -1
- package/dist/acp/mcp-host.d.ts +12 -1
- package/dist/acp/mcp-host.d.ts.map +1 -1
- package/dist/acp/mcp-host.js +18 -2
- package/dist/acp/mcp-host.js.map +1 -1
- package/dist/acp/mcp-runtime.js +98 -9
- package/dist/acp/mcp-runtime.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/plugin/bridge-rules.d.ts +22 -0
- package/dist/plugin/bridge-rules.d.ts.map +1 -0
- package/dist/plugin/bridge-rules.js +104 -0
- package/dist/plugin/bridge-rules.js.map +1 -0
- package/dist/plugin/catalog.d.ts +7 -0
- package/dist/plugin/catalog.d.ts.map +1 -1
- package/dist/plugin/catalog.js +42 -2
- package/dist/plugin/catalog.js.map +1 -1
- package/dist/plugin/index.d.ts +3 -13
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +243 -174
- package/dist/plugin/index.js.map +1 -1
- package/dist/plugin/sessions.d.ts +11 -1
- package/dist/plugin/sessions.d.ts.map +1 -1
- package/dist/plugin/sessions.js +36 -5
- package/dist/plugin/sessions.js.map +1 -1
- package/dist/provider/model.d.ts +93 -14
- package/dist/provider/model.d.ts.map +1 -1
- package/dist/provider/model.js +698 -213
- package/dist/provider/model.js.map +1 -1
- package/docs/DEVELOPMENT.md +50 -23
- package/examples/01-minimal.jsonc +9 -6
- package/examples/02-permisos-por-agente.jsonc +22 -17
- package/examples/03-fidelidad-opencode.jsonc +8 -7
- package/examples/04-modelo-y-esfuerzo.jsonc +29 -23
- package/examples/05-agentes-personalizados.jsonc +24 -14
- package/examples/06-ecosistema-claude.jsonc +12 -11
- package/examples/07-provider-manual.jsonc +12 -8
- package/examples/08-puente-permisos.jsonc +43 -25
- package/examples/README.md +10 -9
- package/package.json +6 -4
package/dist/plugin/catalog.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import { readFileSync, existsSync } from "node:fs";
|
|
8
8
|
import { homedir } from "node:os";
|
|
9
9
|
import { join } from "node:path";
|
|
10
|
+
import { Model, Provider } from "@opencode/plugin";
|
|
10
11
|
import { readCache, writeCache } from "./cache.js";
|
|
11
12
|
const MODELS_DEV_URL = process.env.OPENCODE_MODELS_URL
|
|
12
13
|
? `${process.env.OPENCODE_MODELS_URL}/api.json`
|
|
@@ -82,7 +83,6 @@ export function buildModels(agentModels, promptCaps, catalog) {
|
|
|
82
83
|
for (const am of agentModels) {
|
|
83
84
|
const cat = matchCatalog(am.id, catalog);
|
|
84
85
|
const is1m = /\[1m\]|1m/i.test(am.id);
|
|
85
|
-
const isDefault = am.id.toLowerCase() === "default"; // "default" = Opus 4.7 w/ 1M ctx
|
|
86
86
|
const reasoning = cat?.reasoning ?? true;
|
|
87
87
|
const variants = {};
|
|
88
88
|
if (reasoning)
|
|
@@ -98,7 +98,10 @@ export function buildModels(agentModels, promptCaps, catalog) {
|
|
|
98
98
|
? { input: cat.cost.input, output: cat.cost.output, cache_read: cat.cost.cache_read ?? 0, cache_write: cat.cost.cache_write ?? 0 }
|
|
99
99
|
: { input: 0, output: 0, cache_read: 0, cache_write: 0 },
|
|
100
100
|
limit: {
|
|
101
|
-
|
|
101
|
+
// Only the explicit `[1m]` variants get the 1M window. Advertising 1M for the
|
|
102
|
+
// plain model kept OpenCode's auto-compaction from ever triggering, so the
|
|
103
|
+
// conversation grew unbounded — report the catalogue's real window instead.
|
|
104
|
+
context: is1m ? Math.max(cat?.limit?.context ?? 0, 1_000_000) : cat?.limit?.context ?? 200_000,
|
|
102
105
|
output: cat?.limit?.output ?? 8192,
|
|
103
106
|
},
|
|
104
107
|
modalities: { input: [...input], output: ["text"] },
|
|
@@ -107,4 +110,41 @@ export function buildModels(agentModels, promptCaps, catalog) {
|
|
|
107
110
|
}
|
|
108
111
|
return out;
|
|
109
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* The same models as `buildModels`, in V2's `Model.Info` shape (what
|
|
115
|
+
* `ctx.provider.transform`'s editor.add expects). `buildModels` stays for the
|
|
116
|
+
* CLI/diagnostic path; this is the one the plugin registers.
|
|
117
|
+
*/
|
|
118
|
+
export function buildModelsInfo(agentModels, promptCaps, catalog, providerID) {
|
|
119
|
+
const pid = Provider.ID.make(providerID);
|
|
120
|
+
const built = buildModels(agentModels, promptCaps, catalog);
|
|
121
|
+
return agentModels.map((am) => {
|
|
122
|
+
const m = built[am.id];
|
|
123
|
+
const cat = matchCatalog(am.id, catalog);
|
|
124
|
+
const released = cat?.release_date ? Math.trunc(Date.parse(cat.release_date) / 1000) || 0 : 0;
|
|
125
|
+
return {
|
|
126
|
+
...Model.Info.default(pid, Model.ID.make(m.id)),
|
|
127
|
+
name: m.name,
|
|
128
|
+
...(cat?.family ? { family: Model.Family.make(cat.family) } : {}),
|
|
129
|
+
capabilities: { tools: !!m.tool_call, input: [...m.modalities.input], output: [...m.modalities.output] },
|
|
130
|
+
cost: [
|
|
131
|
+
{
|
|
132
|
+
input: m.cost.input,
|
|
133
|
+
output: m.cost.output,
|
|
134
|
+
cache: { read: m.cost.cache_read, write: m.cost.cache_write },
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
limit: { context: m.limit.context, output: m.limit.output },
|
|
138
|
+
time: { released },
|
|
139
|
+
status: "active",
|
|
140
|
+
enabled: true,
|
|
141
|
+
// Effort levels as variants: picking one merges `{ effort }` into the
|
|
142
|
+
// model's settings → `providerOptions.<providerID>.effort`.
|
|
143
|
+
variants: Object.keys(m.variants ?? {}).map((id) => ({
|
|
144
|
+
id: Model.VariantID.make(id),
|
|
145
|
+
settings: { effort: m.variants[id].effort },
|
|
146
|
+
})),
|
|
147
|
+
};
|
|
148
|
+
});
|
|
149
|
+
}
|
|
110
150
|
//# sourceMappingURL=catalog.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"catalog.js","sourceRoot":"","sources":["../../src/plugin/catalog.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,iFAAiF;AACjF,gFAAgF;AAChF,6EAA6E;AAC7E,yEAAyE;AACzE,sBAAsB;AACtB,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGnD,MAAM,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB;IACpD,CAAC,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,WAAW;IAC/C,CAAC,CAAC,6BAA6B,CAAC;AAClC,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC;AAC5E,MAAM,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAEhC,MAAM,KAAK,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC;AACtC,MAAM,GAAG,GAAG,CAAC,CAAS,EAAE,EAAE,GAAG,IAAI,KAAK;IAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAgBxF,sFAAsF;AACtF,MAAM,CAAC,KAAK,UAAU,oBAAoB;IACxC,IAAI,CAAC;QACH,IAAI,UAAU,CAAC,cAAc,CAAC,EAAE,CAAC;YAC/B,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAA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AC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE;YACxG,IAAI,EAAE;gBACJ;oBACE,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK;oBACnB,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM;oBACrB,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE;iBAC9D;aACF;YACD,KAAK,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE;YAC3D,IAAI,EAAE,EAAE,QAAQ,EAAE;YAClB,MAAM,EAAE,QAAiB;YACzB,OAAO,EAAE,IAAI;YACb,sEAAsE;YACtE,4DAA4D;YAC5D,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;gBACnD,EAAE,EAAE,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC5B,QAAQ,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE;aAC5C,CAAC,CAAC;SACJ,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/plugin/index.d.ts
CHANGED
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
* "plugin": [["opencode-claude-code-acpbridge", { "command": "claude-agent-acp" }]]
|
|
6
|
-
*
|
|
7
|
-
* The plugin discovers the agent's models (cached), pulls their metadata from
|
|
8
|
-
* models.dev, and injects `provider.acp` with the populated models — while the
|
|
9
|
-
* user keeps full control of every agent option via these plugin options.
|
|
10
|
-
*/
|
|
11
|
-
export declare const ACPPlugin: Plugin;
|
|
12
|
-
declare const acpPluginModule: PluginModule;
|
|
13
|
-
export default acpPluginModule;
|
|
1
|
+
import { Plugin } from "@opencode/plugin";
|
|
2
|
+
export declare const ACPPlugin: Plugin.Plugin;
|
|
3
|
+
export default ACPPlugin;
|
|
14
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugin/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugin/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,MAAM,EAAY,MAAM,kBAAkB,CAAC;AAmJlE,eAAO,MAAM,SAAS,eA+JpB,CAAC;AAEH,eAAe,SAAS,CAAC"}
|
package/dist/plugin/index.js
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Agent, Model, Plugin, Provider } from "@opencode/plugin";
|
|
2
2
|
import { fileURLToPath } from "node:url";
|
|
3
3
|
import { dirname, join } from "node:path";
|
|
4
4
|
import { discoverAgent } from "./discover.js";
|
|
5
|
-
import { loadAnthropicCatalog,
|
|
5
|
+
import { loadAnthropicCatalog, buildModelsInfo } from "./catalog.js";
|
|
6
6
|
import { readCacheKeyed, writeCache } from "./cache.js";
|
|
7
|
-
import { getLink } from "./sessions.js";
|
|
7
|
+
import { getLink, clearLink } from "./sessions.js";
|
|
8
|
+
import { publishAgentRules } from "./bridge-rules.js";
|
|
8
9
|
import { detectClaudeExecutable } from "../provider/factory.js";
|
|
9
10
|
const DEBUG = !!process.env.ACP_DEBUG;
|
|
10
11
|
const dbg = (m) => { if (DEBUG)
|
|
11
12
|
process.stderr.write(`[acp-plugin] ${m}\n`); };
|
|
12
13
|
const DISCOVERY_TTL = 60 * 60 * 1000; // 1h
|
|
14
|
+
/** Registro del provider en vuelo por providerId: si la config recarga dos veces
|
|
15
|
+
* en paralelo, la segunda reutiliza la promesa en vez de correr check+add en carrera. */
|
|
16
|
+
const providerRegisterInflight = new Map();
|
|
13
17
|
function hash(s) {
|
|
14
18
|
let h = 5381;
|
|
15
19
|
for (let i = 0; i < s.length; i++)
|
|
@@ -19,124 +23,138 @@ function hash(s) {
|
|
|
19
23
|
function isPlainObject(v) {
|
|
20
24
|
return v != null && typeof v === "object" && !Array.isArray(v);
|
|
21
25
|
}
|
|
22
|
-
/**
|
|
26
|
+
/** Clon profundo de valores (arrays / plain objects recursivos; escalares tal cual). */
|
|
27
|
+
function cloneValue(v) {
|
|
28
|
+
if (Array.isArray(v))
|
|
29
|
+
return v.map(cloneValue);
|
|
30
|
+
if (isPlainObject(v)) {
|
|
31
|
+
const o = {};
|
|
32
|
+
for (const k of Object.keys(v))
|
|
33
|
+
o[k] = cloneValue(v[k]);
|
|
34
|
+
return o;
|
|
35
|
+
}
|
|
36
|
+
return v;
|
|
37
|
+
}
|
|
38
|
+
/** Deep merge where `override` wins (arrays/scalars replace; plain objects recurse).
|
|
39
|
+
* Clona la estructura fusionada para no compartir referencias anidadas con `base`. */
|
|
23
40
|
function deepMerge(base, override) {
|
|
24
41
|
if (!isPlainObject(base) || !isPlainObject(override))
|
|
25
|
-
return override;
|
|
26
|
-
const out =
|
|
42
|
+
return cloneValue(override);
|
|
43
|
+
const out = cloneValue(base);
|
|
27
44
|
for (const k of Object.keys(override)) {
|
|
28
|
-
out[k] = k in base ? deepMerge(base[k], override[k]) : override[k];
|
|
45
|
+
out[k] = k in base ? deepMerge(base[k], override[k]) : cloneValue(override[k]);
|
|
29
46
|
}
|
|
30
47
|
return out;
|
|
31
48
|
}
|
|
32
|
-
/** Resolve the
|
|
49
|
+
/** Resolve the module spec OpenCode should load the provider factory from. */
|
|
33
50
|
function resolveNpmSpec(override) {
|
|
34
51
|
if (override)
|
|
35
52
|
return override;
|
|
36
53
|
const here = fileURLToPath(import.meta.url); // <root>/dist/plugin/index.js
|
|
37
54
|
if (here.includes("/node_modules/opencode-claude-code-acpbridge/"))
|
|
38
55
|
return "opencode-claude-code-acpbridge";
|
|
39
|
-
|
|
56
|
+
// dev / local install → the built entrypoint (importable from both Bun and Node,
|
|
57
|
+
// unlike the package directory which only Bun resolves)
|
|
58
|
+
return `file://${join(dirname(here), "..", "index.js")}`;
|
|
40
59
|
}
|
|
41
60
|
/** Strip plugin-only keys; the rest are the provider/agent options passed to the factory. */
|
|
42
61
|
function providerOptions(opts) {
|
|
43
|
-
const { name: _n, npm: _npm, providerId: _p, models: _m, ...rest } = opts;
|
|
62
|
+
const { name: _n, npm: _npm, providerId: _p, models: _m, agents: _a, agentModel: _am, ...rest } = opts;
|
|
44
63
|
return rest;
|
|
45
64
|
}
|
|
65
|
+
/** Native feature set shared by the Claude Code agents ("clean brain" + the reactivated
|
|
66
|
+
* native capabilities, all permission-bridged to OpenCode). CRUCIAL: `nativeSubagents`
|
|
67
|
+
* gives the agent Claude Code's OWN `Task` tool, so delegated work runs as a native
|
|
68
|
+
* subagent on the subscription. Without it the agent falls back to OpenCode's forwarded
|
|
69
|
+
* `task` tool, which spawns OpenCode subagents routed to OTHER providers — those fail
|
|
70
|
+
* when they're down/out-of-balance. IDENTICAL for both agents on purpose: they differ
|
|
71
|
+
* ONLY in the initial session mode, so a plan session can never end up half-restricted. */
|
|
72
|
+
const NATIVE_BASE = {
|
|
73
|
+
allowedTools: ["mcp__opencode"], // OpenCode's tools don't double-prompt (it owns them)
|
|
74
|
+
// Common native tools are covered by OpenCode → disable them so the agent doesn't try
|
|
75
|
+
// (and "approve") a native Bash/Write/… it can't actually run; it uses mcp__opencode__* instead.
|
|
76
|
+
disallowedTools: ["Bash", "Write", "Edit", "MultiEdit", "Glob", "Grep", "WebFetch", "TodoWrite"],
|
|
77
|
+
resourceSearch: true, // ListMcpResources / ReadMcpResource (superior to OpenCode)
|
|
78
|
+
nativeSubagents: true, // Task: native subagents that delegate to OpenCode's tools
|
|
79
|
+
// Gap tools OpenCode doesn't cover, plus the two that make plan mode work at all:
|
|
80
|
+
// ExitPlanMode (without it a plan-mode session has NO way out) and WebSearch.
|
|
81
|
+
nativeTools: ["NotebookEdit", "Read", "ExitPlanMode", "WebSearch"],
|
|
82
|
+
projectMemory: true, // CLAUDE.md/AGENTS.md (verified: keeps subscription)
|
|
83
|
+
nativeSkills: true, // ~/.claude/skills, hooks disabled (verified: keeps subscription)
|
|
84
|
+
};
|
|
85
|
+
/** Agent profiles: Claude session mode (the only difference between the two) + Claude
|
|
86
|
+
* native options. V2's `Agent.Info` has no `options` field, so these travel to the
|
|
87
|
+
* provider per call through the `context` hook (merged with `options.agents.<name>.options`). */
|
|
88
|
+
function agentDefs(opts) {
|
|
89
|
+
if (opts.agents && opts.agents !== true && isPlainObject(opts.agents))
|
|
90
|
+
return opts.agents;
|
|
91
|
+
if (opts.agents && opts.agents !== true && !isPlainObject(opts.agents)) {
|
|
92
|
+
dbg("agents config inválida — usando defaults");
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
"claude-code": {
|
|
96
|
+
name: "Claude Code",
|
|
97
|
+
description: "Claude Code (subscription) — native capabilities with permissions bridged to OpenCode",
|
|
98
|
+
model: opts.agentModel ?? "default",
|
|
99
|
+
options: { mode: "default", ...NATIVE_BASE },
|
|
100
|
+
},
|
|
101
|
+
"claude-code-plan": {
|
|
102
|
+
name: "Claude Code (plan)",
|
|
103
|
+
description: "Claude Code — plan mode (research & plan, no destructive edits)",
|
|
104
|
+
model: opts.agentModel ?? "default",
|
|
105
|
+
variant: "high",
|
|
106
|
+
options: { mode: "plan", ...NATIVE_BASE },
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/** `Model.Ref` for an agent: `"default"` → `<provider>/default`, a full ref passes through. */
|
|
111
|
+
function modelRef(value, providerID, variant) {
|
|
112
|
+
const ref = typeof value === "string"
|
|
113
|
+
? Model.Ref.parse(value.includes("/") || value.includes("#") ? value : `${providerID}/${value}`)
|
|
114
|
+
: value;
|
|
115
|
+
return { ...ref, ...(variant && !ref.variant ? { variant: Model.VariantID.make(variant) } : {}) };
|
|
116
|
+
}
|
|
46
117
|
/**
|
|
47
|
-
*
|
|
48
|
-
* when the Claude agent asks (via ACP `requestPermission`) to run a NATIVE tool;
|
|
49
|
-
* this surfaces OpenCode's own `ask` prompt with the native tool's details, and
|
|
50
|
-
* the verdict (approved / rejected) is the tool-result the provider maps back to
|
|
51
|
-
* allow/deny. Granularity per native tool comes from the `patterns` below, e.g.
|
|
52
|
-
* `permission: { claude_permission: { "Read*": "allow", "*": "ask" } }`.
|
|
53
|
-
*/
|
|
54
|
-
const claudePermissionTool = tool({
|
|
55
|
-
description: "Permission gate for a native Claude Code tool. Approve to let the agent run that native tool; reject to block it.",
|
|
56
|
-
args: {
|
|
57
|
-
tool: tool.schema.string().optional().describe("native tool requested (e.g. Write, Bash, NotebookEdit, Skill)"),
|
|
58
|
-
kind: tool.schema.string().optional().describe("execute|edit|read|delete|fetch|think|…"),
|
|
59
|
-
title: tool.schema.string().optional().describe("human label of the action"),
|
|
60
|
-
input: tool.schema.any().optional().describe("the native tool input"),
|
|
61
|
-
},
|
|
62
|
-
async execute(args, ctx) {
|
|
63
|
-
// Permission = the NATIVE tool name → the prompt reads "Call tool Skill /
|
|
64
|
-
// NotebookEdit / Bash …" and rules/"Allow always" are PER native tool.
|
|
65
|
-
const native = String(args.tool ?? args.title ?? "native tool").trim() || "native tool";
|
|
66
|
-
// Pattern = the action target (command / skill / path) so GLOB rules match,
|
|
67
|
-
// e.g. `permission: { Bash: { "git *": "allow" }, Skill: { "review*": "allow" }, "*": "ask" }`.
|
|
68
|
-
const inp = args.input && typeof args.input === "object" ? args.input : {};
|
|
69
|
-
const rawTarget = String((inp.command ?? inp.skill ?? inp.name ?? inp.notebook_path ?? inp.file_path ?? inp.path) ||
|
|
70
|
-
(typeof args.input === "string" ? args.input : "") || args.title || "").trim();
|
|
71
|
-
const target = rawTarget || "*";
|
|
72
|
-
// "Allow always" glob: ONLY collapse shell commands (kind=execute) to the first
|
|
73
|
-
// token (`git status` → `git *`); otherwise the exact target. With no real target
|
|
74
|
-
// offer NO always-glob — avoids persisting a broad "*" rule that would auto-approve
|
|
75
|
-
// everything for this native tool.
|
|
76
|
-
const always = args.kind === "execute" && rawTarget.includes(" ") ? `${rawTarget.split(/\s+/)[0]} *`
|
|
77
|
-
: rawTarget || undefined;
|
|
78
|
-
// ctx.ask surfaces OpenCode's prompt (default "ask" when no rule matches); throws
|
|
79
|
-
// PermissionRejectedError on reject → the provider denies the native tool.
|
|
80
|
-
await ctx.ask({
|
|
81
|
-
permission: native,
|
|
82
|
-
patterns: [target],
|
|
83
|
-
always: always ? [always] : [],
|
|
84
|
-
metadata: { kind: args.kind, title: args.title, input: args.input },
|
|
85
|
-
});
|
|
86
|
-
return `approved: ${native}`;
|
|
87
|
-
},
|
|
88
|
-
});
|
|
89
|
-
/**
|
|
90
|
-
* OpenCode plugin half. With the auto-register hook below, a minimal config is enough:
|
|
118
|
+
* OpenCode plugin half. Minimal config is enough:
|
|
91
119
|
*
|
|
92
|
-
* "
|
|
120
|
+
* "plugins": [{ "package": "opencode-claude-code-acpbridge",
|
|
121
|
+
* "options": { "command": "claude-agent-acp" } }]
|
|
93
122
|
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
123
|
+
* It discovers the agent's models (cached), pulls their metadata from models.dev,
|
|
124
|
+
* registers the `acp` provider with the populated `Model.Info[]`, injects the
|
|
125
|
+
* `claude-code` / `claude-code-plan` agents, and bridges every per-request value
|
|
126
|
+
* (session link, agent options) through the `context` hook.
|
|
97
127
|
*/
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
catch { /* ignore */ }
|
|
127
|
-
},
|
|
128
|
-
config: async (cfg) => {
|
|
128
|
+
/** ¿Está la tool `question` en el set de tools del agente? Soporta array / Set /
|
|
129
|
+
* Record (según cómo OpenCode lo haya convertido); sin info se asume que sí
|
|
130
|
+
* para conservar el comportamiento actual. */
|
|
131
|
+
function hasQuestionTool(item) {
|
|
132
|
+
const t = item?.tools;
|
|
133
|
+
if (t == null)
|
|
134
|
+
return true;
|
|
135
|
+
if (Array.isArray(t))
|
|
136
|
+
return t.includes("question");
|
|
137
|
+
if (t instanceof Set)
|
|
138
|
+
return t.has("question");
|
|
139
|
+
if (typeof t === "object") {
|
|
140
|
+
if ("question" in t)
|
|
141
|
+
return !!t.question;
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
export const ACPPlugin = Plugin.define({
|
|
147
|
+
id: "opencode-claude-code-acpbridge",
|
|
148
|
+
async setup(ctx) {
|
|
149
|
+
const opts = (ctx.options ?? {});
|
|
150
|
+
const providerId = opts.providerId ?? "acp";
|
|
151
|
+
const agentOptions = new Map();
|
|
152
|
+
if (!opts.command && !process.env.ACP_COMMAND) {
|
|
153
|
+
dbg("no `command` in plugin options — skipping auto-register (declare the provider manually)");
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
129
156
|
try {
|
|
130
|
-
if (!opts.command && !process.env.ACP_COMMAND) {
|
|
131
|
-
dbg("no `command` in plugin options — skipping auto-register (declare the provider manually)");
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
157
|
const command = opts.command ?? process.env.ACP_COMMAND;
|
|
135
|
-
cfg.provider ??= {};
|
|
136
|
-
if (cfg.provider[providerId]) {
|
|
137
|
-
dbg(`provider '${providerId}' already declared in config — leaving it untouched`);
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
158
|
// Resolve the native Claude binary the same way the provider factory does,
|
|
141
159
|
// so the ephemeral discovery agent can find it under a minimal config.
|
|
142
160
|
const claudeExecutable = opts.claudeExecutable ?? process.env.CLAUDE_CODE_EXECUTABLE ?? detectClaudeExecutable();
|
|
@@ -149,87 +167,138 @@ export const ACPPlugin = async (_input, options) => {
|
|
|
149
167
|
discovered = await discoverAgent(discOpts);
|
|
150
168
|
writeCache("discovery.json", discovered, key);
|
|
151
169
|
}
|
|
152
|
-
const agentModels = discovered?.models?.length
|
|
153
|
-
? discovered.models
|
|
154
|
-
: [{ id: "default", name: "Claude Code (ACP)" }];
|
|
170
|
+
const agentModels = discovered?.models?.length ? discovered.models : [{ id: "default", name: "Claude Code (ACP)" }];
|
|
155
171
|
const catalog = await loadAnthropicCatalog();
|
|
156
|
-
const models =
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
// so users see and rule on the actual action. Override per tool, e.g.
|
|
177
|
-
// `permission: { Skill: "allow", NotebookEdit: "ask" }`.
|
|
178
|
-
permission: { claude_permission: "allow" },
|
|
179
|
-
options: {
|
|
180
|
-
mode: "default", // not bypass → the agent asks → permission bridge
|
|
181
|
-
allowedTools: ["mcp__opencode"], // OpenCode's tools don't double-prompt (it owns them)
|
|
182
|
-
// Common native tools are covered by OpenCode → disable them so the agent
|
|
183
|
-
// doesn't try (and "approve") a native Bash/Write/… it can't actually run;
|
|
184
|
-
// it uses mcp__opencode__* instead. Native gap tools stay (see `nativeTools`).
|
|
185
|
-
disallowedTools: ["Bash", "Write", "Edit", "MultiEdit", "Glob", "Grep", "WebSearch", "WebFetch", "TodoWrite"],
|
|
186
|
-
resourceSearch: true, // ListMcpResources / ReadMcpResource (superior to OpenCode)
|
|
187
|
-
nativeSubagents: true, // Task: native subagents that delegate to OpenCode's tools
|
|
188
|
-
nativeTools: ["NotebookEdit", "Read"], // gap OpenCode doesn't cover + native Read (multimodal)
|
|
189
|
-
projectMemory: true, // CLAUDE.md/AGENTS.md (verified: keeps subscription)
|
|
190
|
-
nativeSkills: true, // ~/.claude/skills, hooks disabled (verified: keeps subscription)
|
|
172
|
+
const models = buildModelsInfo(agentModels, discovered?.promptCaps ?? {}, catalog, providerId);
|
|
173
|
+
const npmSpec = resolveNpmSpec(opts.npm);
|
|
174
|
+
// The provider no longer comes from `provider.<id>` in config (V2 resolves
|
|
175
|
+
// packages through `aisdk:<spec>`): the plugin registers it directly.
|
|
176
|
+
// Guard contra reloads paralelos: el check `get` + `add` no es atómico,
|
|
177
|
+
// así que se memoiza la promesa en vuelo por providerId y se reutiliza.
|
|
178
|
+
let registering = providerRegisterInflight.get(providerId);
|
|
179
|
+
if (!registering) {
|
|
180
|
+
const fresh = ctx.provider.transform((editor) => {
|
|
181
|
+
if (editor.get(providerId)) {
|
|
182
|
+
dbg(`provider '${providerId}' already declared — keeping the existing definition`);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
editor.add({
|
|
186
|
+
info: {
|
|
187
|
+
...Provider.Info.empty(Provider.ID.make(providerId)),
|
|
188
|
+
name: opts.name ?? "Claude Code (ACP)",
|
|
189
|
+
activation: "enabled",
|
|
190
|
+
package: `aisdk:${npmSpec}`,
|
|
191
|
+
settings: { ...discOpts },
|
|
191
192
|
},
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
193
|
+
models,
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
providerRegisterInflight.set(providerId, fresh);
|
|
197
|
+
// Solo se memoiza mientras está en vuelo: al asentarse se libera para
|
|
198
|
+
// que la próxima recarga (secuencial) use su propio `ctx`.
|
|
199
|
+
const done = () => {
|
|
200
|
+
if (providerRegisterInflight.get(providerId) === fresh)
|
|
201
|
+
providerRegisterInflight.delete(providerId);
|
|
198
202
|
};
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
203
|
+
fresh.then(done, done);
|
|
204
|
+
registering = fresh;
|
|
205
|
+
}
|
|
206
|
+
await registering;
|
|
207
|
+
dbg(`auto-registered provider '${providerId}' (aisdk:${npmSpec}) — models: ${models.map((m) => m.id).join(", ")}`);
|
|
208
|
+
if (opts.agents !== false) {
|
|
209
|
+
const defs = agentDefs(opts);
|
|
210
|
+
await ctx.agent.transform((editor) => {
|
|
211
|
+
for (const [name, raw] of Object.entries(defs)) {
|
|
212
|
+
const def = raw;
|
|
213
|
+
const user = isPlainObject(opts.agents) ? opts.agents[name] : undefined;
|
|
214
|
+
// V1-style per-agent Claude options, overridden by the user's copy.
|
|
215
|
+
agentOptions.set(name, deepMerge(def.options ?? {}, isPlainObject(user) ? user.options ?? {} : {}));
|
|
216
|
+
// A `model` the user already declared (config/other plugin) wins: only
|
|
217
|
+
// fill the field when it is missing, so the transform stays idempotent.
|
|
218
|
+
const model = modelRef((isPlainObject(user) && user.model) || def.model || "default", providerId, def.variant);
|
|
219
|
+
const description = (isPlainObject(user) && user.description) || def.description;
|
|
220
|
+
const questionRule = { action: "question", resource: "*", effect: "allow" };
|
|
221
|
+
editor.update(name, (item) => {
|
|
222
|
+
if (def.name)
|
|
223
|
+
item.name = Agent.Name.make(def.name);
|
|
224
|
+
if (description && !item.description)
|
|
225
|
+
item.description = description;
|
|
226
|
+
if (!item.model)
|
|
227
|
+
item.model = model;
|
|
228
|
+
// Solo tiene sentido permitir `question` si la tool existe en el agente.
|
|
229
|
+
if (hasQuestionTool(item) &&
|
|
230
|
+
!item.permissions.some((r) => r.action === "question" && r.resource === "*")) {
|
|
231
|
+
item.permissions.push(questionRule);
|
|
232
|
+
}
|
|
233
|
+
// Publish the rules the permission bridge evaluates against (the
|
|
234
|
+
// user's `permissions` included). `action:"*"` defaults are ignored
|
|
235
|
+
// at evaluation time — see bridge-rules.ts.
|
|
236
|
+
publishAgentRules(name, item.permissions);
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
dbg(`agents registered: ${Object.keys(defs).join(", ")}`);
|
|
219
241
|
}
|
|
220
242
|
}
|
|
221
243
|
catch (e) {
|
|
222
|
-
// Never break OpenCode boot: log and continue (user can declare
|
|
223
|
-
|
|
224
|
-
dbg(`auto-register failed: ${
|
|
244
|
+
// Never break OpenCode boot: log and continue (the user can still declare
|
|
245
|
+
// the provider manually, and the hooks below stay registered).
|
|
246
|
+
dbg(`auto-register failed: ${e instanceof Error ? e.stack || e.message : String(e)}`);
|
|
225
247
|
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
248
|
+
}
|
|
249
|
+
// Session link + agent options → the provider. V2 passes NO provider options
|
|
250
|
+
// from config, so everything the model needs per call is injected here
|
|
251
|
+
// (`SessionRequestOptions`: generation keys stay typed, the rest becomes
|
|
252
|
+
// `providerOptions.<providerID>`).
|
|
253
|
+
const context = await ctx.session.hook("context", (event) => {
|
|
254
|
+
if (event.model.providerID !== providerId)
|
|
255
|
+
return;
|
|
256
|
+
event.options.ocSession = event.sessionID;
|
|
257
|
+
event.options.ocAgent = String(event.agent);
|
|
258
|
+
const link = getLink(event.sessionID);
|
|
259
|
+
if (link?.acpSessionId) {
|
|
260
|
+
event.options.resumeId = link.acpSessionId;
|
|
261
|
+
event.options.resumeLen = link.sentHistoryLen;
|
|
262
|
+
// Seed the cumulative usage snapshot so per-turn deltas stay correct
|
|
263
|
+
// after a restart (ACP usage is cumulative per session).
|
|
264
|
+
if (link.lastUsage)
|
|
265
|
+
event.options.resumeLastUsage = link.lastUsage;
|
|
266
|
+
if (link.convKey)
|
|
267
|
+
event.options.resumeConvKey = link.convKey;
|
|
268
|
+
}
|
|
269
|
+
const extra = agentOptions.get(String(event.agent));
|
|
270
|
+
if (extra)
|
|
271
|
+
for (const [k, v] of Object.entries(extra))
|
|
272
|
+
event.options[k] = v;
|
|
273
|
+
}, { providerID: providerId });
|
|
274
|
+
// Rewinding a conversation truncates OpenCode's history, but the Claude Code
|
|
275
|
+
// session on the other side still remembers every undone turn. Drop the
|
|
276
|
+
// registry link so the next turn starts a clean agent session instead of
|
|
277
|
+
// resuming one that would resurrect it. The provider ALSO detects this from
|
|
278
|
+
// the prompt itself (history fingerprint), so programmatic use without the
|
|
279
|
+
// plugin stays correct.
|
|
280
|
+
const closed = new AbortController();
|
|
281
|
+
const events = (async () => {
|
|
282
|
+
try {
|
|
283
|
+
for await (const event of ctx.event.subscribe({ signal: closed.signal })) {
|
|
284
|
+
if (event.type !== "session.revert.committed" && event.type !== "session.revert.cleared")
|
|
285
|
+
continue;
|
|
286
|
+
const sessionID = event.data?.sessionID;
|
|
287
|
+
if (sessionID && clearLink(sessionID)) {
|
|
288
|
+
dbg(`session ${sessionID} rewound — link dropped, next turn starts fresh`);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
catch {
|
|
293
|
+
/* aborted on cleanup */
|
|
294
|
+
}
|
|
295
|
+
})();
|
|
296
|
+
return async () => {
|
|
297
|
+
closed.abort();
|
|
298
|
+
await context.dispose();
|
|
299
|
+
await events;
|
|
300
|
+
};
|
|
301
|
+
},
|
|
302
|
+
});
|
|
303
|
+
export default ACPPlugin;
|
|
235
304
|
//# sourceMappingURL=index.js.map
|