@luchenglong/cli-bridge 0.2.7 → 0.2.9

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.
Files changed (47) hide show
  1. package/CHANGELOG.md +97 -0
  2. package/PROVIDER-CONTRACT.md +53 -4
  3. package/README.md +12 -11
  4. package/docs/HANDOVER.md +9 -0
  5. package/docs/audits/2026-10-18-preset-0.2.1-contract-fix.md +160 -0
  6. package/docs/audits/README.md +15 -0
  7. package/dynamic/agy.host.js +1 -1
  8. package/dynamic/claude.host.js +1801 -0
  9. package/dynamic/claude.host.template.mjs +108 -0
  10. package/dynamic/codebuddy.host.js +1 -1
  11. package/dynamic/codex.host.js +1955 -0
  12. package/dynamic/codex.host.template.mjs +137 -0
  13. package/dynamic/mimo.host.js +1 -1
  14. package/dynamic/opencode.host.js +1 -1
  15. package/home-plugin/cli-bridge-indicator/lib/client.js +600 -606
  16. package/home-plugin/cli-bridge-indicator/lib/preset-declarations.mjs +87 -9
  17. package/mcp/cli-bridge-mcp.mjs +6 -4
  18. package/mcp/providers/claude.mjs +231 -0
  19. package/mcp/providers/codex.mjs +239 -0
  20. package/package.json +10 -6
  21. package/preset/agy-first/agent.cordis.yml +0 -5
  22. package/preset/agy-first/plugin-list.mjs +4 -1
  23. package/preset/claude-first/agent.cordis.yml +136 -0
  24. package/preset/claude-first/cli-bridge.mjs +131 -0
  25. package/preset/claude-first/plugin-list.mjs +28 -0
  26. package/preset/claude-first/preset.yml +3 -0
  27. package/preset/codebuddy-first/agent.cordis.yml +0 -5
  28. package/preset/codex-first/agent.cordis.yml +136 -0
  29. package/preset/codex-first/cli-bridge.mjs +160 -0
  30. package/preset/codex-first/plugin-list.mjs +28 -0
  31. package/preset/codex-first/preset.yml +3 -0
  32. package/preset/mimo-first/agent.cordis.yml +1 -7
  33. package/preset/mimo-first/plugin-list.mjs +18 -12
  34. package/preset/mimo-member/plugin-list.mjs +49 -0
  35. package/preset/opencode-first/agent.cordis.yml +0 -5
  36. package/preset/opencode-first/plugin-list.mjs +4 -2
  37. package/preset/standard-base.mjs +18 -6
  38. package/providers/claude-exe.mjs +112 -0
  39. package/providers/claude-models.mjs +334 -0
  40. package/providers/claude-policy.mjs +37 -0
  41. package/providers/claude.mjs +508 -0
  42. package/providers/codex-cli.mjs +471 -0
  43. package/providers/codex-models.mjs +107 -0
  44. package/providers/codex.mjs +544 -0
  45. package/providers/registry.mjs +25 -1
  46. package/scripts/build.mjs +1 -2
  47. package/scripts/verify.mjs +8 -2
@@ -0,0 +1,108 @@
1
+ // dynamic/claude.host.template.mjs — claude 动态沙箱宿主模板(cordis_define code.host 源)。
2
+ //
3
+ // 构建(node scripts/build.mjs --only=claude)把 core/bridge-kit.mjs、providers/claude.mjs、
4
+ // providers/claude-*.mjs 片文件(含 claude-policy.mjs)与 core/scheduling.mjs 分别内联进下方
5
+ // 四个占位标记行(各占一行、行内仅此标记),生成 dynamic/claude.host.js。
6
+ // 注意:标记字面量绝不能出现在本注释里 —— 构建做全局替换,注释中出现同样会被替换成正文
7
+ // 代码而炸掉语法。
8
+ // 沙箱纪律(旧仓 dynamic/host.js 头注 verbatim 精神):
9
+ // - 禁 import/require、无 TypeScript;无 AbortController/process 裸引用/Buffer/原生定时器
10
+ // —— process 只经 typeof 守卫探测;宿主能力全部来自注入的 harness.*/ctx。
11
+ // - 顶层 return { inject, apply } 为动态宿主约定形态(生成物是 .js/CJS 包装,顶层 return
12
+ // 合法;本模板文件是 .mjs,不要直接 node --check 模板本身,只 check 生成物)。
13
+ // - 无 ctx.emit:状态经 ctx.get('cliBridgeCollector').mergeSnapshot('claude', snap) 推给
14
+ // 家级灯(旧 claudeCollector 别名保留兼容);动态形态不宣告 mode。
15
+ /*__KIT__*/
16
+ /*__PROVIDER__*/
17
+ /*__EXTRA__*/
18
+ /*__SCHED__*/
19
+
20
+ return {
21
+ inject: ['tools', 'subprocess', 'systemPrompt', 'timer'],
22
+ apply(ctx) {
23
+ // 调度门禁:设置面板关掉 claude → 本形态不注册工具/政策段;fail-open。
24
+ if (!isBridgeEnabled('claude', SCHED_ALL_IDS)) return
25
+ const subprocess = ctx.subprocess
26
+ const sandboxPolicy = ctx.get('sandboxPolicy')
27
+ // 沙箱可能运行在无 process 的环境:typeof 守卫读 env(旧仓 dynamic 的等价面)。
28
+ const env = (typeof process !== 'undefined' && process.env) ? process.env : {}
29
+
30
+ const provider = defineProvider({ env })
31
+
32
+ function publish(snapshot) {
33
+ try {
34
+ const collector = ctx.get('cliBridgeCollector')
35
+ if (collector && typeof collector.mergeSnapshot === 'function') { collector.mergeSnapshot('claude', snapshot); return }
36
+ } catch (e) { /* fall through to legacy alias */ }
37
+ try {
38
+ const legacy = ctx.get('claudeCollector')
39
+ if (legacy && typeof legacy.mergeSnapshot === 'function') legacy.mergeSnapshot(snapshot)
40
+ } catch (e) { /* 灯数据尽力而为 */ }
41
+ }
42
+
43
+ // exe 优先级(与描述符同一套):env CLAUDE_BIN/CLAUDE_CLI/CLAUDE_CODE_BIN > 已知本地安装
44
+ // > PATH 名 claude(subprocess.resolveExecutable 兜底)。动态沙箱拿不到设置面板值。
45
+ const exeCandidates = claudeExeCandidates(env, '')
46
+ async function resolveExe(backend, signal) {
47
+ for (const c of exeCandidates) {
48
+ if (!c) continue
49
+ if (/\.(mjs|cjs|js)$/i.test(c) && typeof process !== 'undefined' && process.execPath) return [process.execPath, c]
50
+ return c
51
+ }
52
+ return await subprocess.resolveExecutable('claude', undefined, signal)
53
+ }
54
+
55
+ // cwd 兜底:CLAUDE_MCP_CWD > sandboxPolicy.workspaceRoot > process.cwd() > '.'。
56
+ function getCwdFallback() {
57
+ if (env.CLAUDE_MCP_CWD) return String(env.CLAUDE_MCP_CWD)
58
+ if (sandboxPolicy && typeof sandboxPolicy.workspaceRoot === 'string' && sandboxPolicy.workspaceRoot) return sandboxPolicy.workspaceRoot
59
+ if (typeof process !== 'undefined' && typeof process.cwd === 'function') { try { return process.cwd() } catch (e) {} }
60
+ return '.'
61
+ }
62
+
63
+ provider.attach({ ctx, subprocess, resolveExe, getCwdFallback, publish })
64
+
65
+ const OUTPUT_SCHEMA = { type: 'object', additionalProperties: true }
66
+
67
+ harness.registerTool(ctx, harness.defineTool({
68
+ name: provider.tools.run.name,
69
+ description: provider.tools.run.description,
70
+ parameters: provider.tools.run.inputSchema,
71
+ output: { schema: OUTPUT_SCHEMA, render: function (args, value) { return renderResult(value, provider) } },
72
+ execute: function (args, exec) { return provider.runToolLogic(args, exec) }
73
+ }))
74
+ harness.registerTool(ctx, harness.defineTool({
75
+ name: provider.tools.continue.name,
76
+ description: provider.tools.continue.description,
77
+ parameters: provider.tools.continue.inputSchema,
78
+ output: { schema: OUTPUT_SCHEMA, render: function (args, value) { return renderResult(value, provider) } },
79
+ execute: function (args, exec) { return provider.continueToolLogic(args, exec) }
80
+ }))
81
+ harness.registerTool(ctx, harness.defineTool({
82
+ name: provider.tools.status.name,
83
+ description: provider.tools.status.description,
84
+ parameters: provider.tools.status.inputSchema,
85
+ output: { schema: OUTPUT_SCHEMA, render: function (args, value) { return renderStatus(value, provider) } },
86
+ execute: function (args) { return provider.statusToolLogic(args) }
87
+ }))
88
+ // 附加工具(claude_models):render 适配 harness 契约 render(args, value)。
89
+ for (const et of (provider.extraTools || [])) {
90
+ harness.registerTool(ctx, harness.defineTool({
91
+ name: et.name,
92
+ description: et.description,
93
+ parameters: et.inputSchema,
94
+ output: { schema: OUTPUT_SCHEMA, render: function (args, value) { return et.render ? et.render(args, value) : renderResult(value, provider) } },
95
+ execute: function (args, exec) { return et.logic(args, exec) }
96
+ }))
97
+ }
98
+
99
+ // 浏览器指示灯轮询的 RPC 面(旧 dynamic handle('<id>_status') verbatim 语义)。
100
+ harness.handle('claude_status', function () { return provider.statusToolLogic({}) })
101
+
102
+ ctx.systemPrompt.section({
103
+ name: 'claude:policy',
104
+ order: (typeof ctx.systemPrompt.getSectionOrder === 'function' ? ctx.systemPrompt.getSectionOrder('TOOL_SUBAGENT') : 2800) + 10,
105
+ text: POLICY_TEXT
106
+ })
107
+ }
108
+ }
@@ -2105,7 +2105,7 @@ function isBridgeEnabled(selfId, ids, io) {
2105
2105
  }
2106
2106
 
2107
2107
 
2108
- const SCHED_ALL_IDS = ["agy","codebuddy","mimo","opencode"]
2108
+ const SCHED_ALL_IDS = ["agy","codebuddy","mimo","opencode","claude","codex"]
2109
2109
 
2110
2110
 
2111
2111
  return {