@botconnector/bccli 0.4.17 → 0.5.0-rc.4

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 (186) hide show
  1. package/LICENSE +203 -21
  2. package/THIRD_PARTY_NOTICES.md +9 -0
  3. package/branding.mjs +347 -0
  4. package/cli.mjs +120 -0
  5. package/core.mjs +260 -0
  6. package/credentials.mjs +52 -0
  7. package/gateway.mjs +2 -0
  8. package/model-command.mjs +61 -0
  9. package/package.json +35 -59
  10. package/provider-cli.mjs +77 -0
  11. package/providers.mjs +166 -0
  12. package/proxy.mjs +242 -0
  13. package/startup-menu.mjs +120 -0
  14. package/README.en.md +0 -253
  15. package/README.md +0 -250
  16. package/dist/abort.d.ts +0 -5
  17. package/dist/acp-HWHF25KU.js +0 -221
  18. package/dist/acp.d.ts +0 -44
  19. package/dist/agent.d.ts +0 -158
  20. package/dist/agents.d.ts +0 -4
  21. package/dist/args-XA77XUMD.js +0 -13
  22. package/dist/args.d.ts +0 -59
  23. package/dist/budget.d.ts +0 -26
  24. package/dist/checkpoints.d.ts +0 -35
  25. package/dist/chunk-2IP5F3EK.js +0 -56
  26. package/dist/chunk-5CVHTYBQ.js +0 -270
  27. package/dist/chunk-6LO6YRDY.js +0 -216
  28. package/dist/chunk-6PJRWKVI.js +0 -50
  29. package/dist/chunk-7OTFZK4B.js +0 -159
  30. package/dist/chunk-7U7CMKKI.js +0 -861
  31. package/dist/chunk-A3NBWIEQ.js +0 -2706
  32. package/dist/chunk-FY543EQW.js +0 -50
  33. package/dist/chunk-IDZLHEVL.js +0 -524
  34. package/dist/chunk-IF5RNXBI.js +0 -341
  35. package/dist/chunk-M5T4AM4I.js +0 -256
  36. package/dist/chunk-NGFWBVHD.js +0 -71
  37. package/dist/chunk-OCEQ2TRJ.js +0 -1075
  38. package/dist/chunk-OK2USAXX.js +0 -88
  39. package/dist/chunk-PSO7R5AD.js +0 -10
  40. package/dist/chunk-RLSQAZBT.js +0 -78
  41. package/dist/chunk-VPFCIUC6.js +0 -91
  42. package/dist/chunk-XP5MTJN2.js +0 -8
  43. package/dist/chunk-YGBTNDPK.js +0 -202
  44. package/dist/chunk-YYTFJUO2.js +0 -148
  45. package/dist/chunk-ZXWRLN7E.js +0 -378
  46. package/dist/cli.d.ts +0 -1
  47. package/dist/cli.js +0 -233
  48. package/dist/clipboardImage.d.ts +0 -17
  49. package/dist/commands.d.ts +0 -16
  50. package/dist/completion-IRVEVW6H.js +0 -125
  51. package/dist/completion.d.ts +0 -14
  52. package/dist/config-OVWCUVY7.js +0 -25
  53. package/dist/config-S3CZUIBB.js +0 -34
  54. package/dist/config.d.ts +0 -99
  55. package/dist/context.d.ts +0 -13
  56. package/dist/contextWindow.d.ts +0 -3
  57. package/dist/diff.d.ts +0 -7
  58. package/dist/exit.d.ts +0 -9
  59. package/dist/extensions.d.ts +0 -34
  60. package/dist/ghBotCli-FYKJDJOD.js +0 -680
  61. package/dist/ghBotCli.d.ts +0 -9
  62. package/dist/ghBotDispatch.d.ts +0 -68
  63. package/dist/ghBotRunner.d.ts +0 -82
  64. package/dist/ghBotServe.d.ts +0 -21
  65. package/dist/ghBotWebhook.d.ts +0 -45
  66. package/dist/hooks.d.ts +0 -27
  67. package/dist/i18n/id.d.ts +0 -1
  68. package/dist/i18n.d.ts +0 -16
  69. package/dist/integrationCli-GY73S2K7.js +0 -876
  70. package/dist/integrationCli.d.ts +0 -9
  71. package/dist/keybinds.d.ts +0 -22
  72. package/dist/login-KSN63EM4.js +0 -18
  73. package/dist/login.d.ts +0 -21
  74. package/dist/lsp.d.ts +0 -73
  75. package/dist/mcp/catalog.d.ts +0 -14
  76. package/dist/mcp/config.d.ts +0 -36
  77. package/dist/mcp/manager.d.ts +0 -52
  78. package/dist/mcp/oauth.d.ts +0 -82
  79. package/dist/mcpCli-VWSCCDWT.js +0 -113
  80. package/dist/mcpCli.d.ts +0 -3
  81. package/dist/mcpServer/serve.d.ts +0 -8
  82. package/dist/mcpServer/server.d.ts +0 -19
  83. package/dist/models.d.ts +0 -13
  84. package/dist/modelsCli-4Q6KFWV2.js +0 -36
  85. package/dist/modelsCli.d.ts +0 -15
  86. package/dist/npmRunner-LU43GM3W.js +0 -46
  87. package/dist/npmRunner.d.ts +0 -21
  88. package/dist/oauthLogin-JWXQZTMZ.js +0 -210
  89. package/dist/oauthLogin.d.ts +0 -47
  90. package/dist/permissions.d.ts +0 -30
  91. package/dist/pluginSpec.d.ts +0 -25
  92. package/dist/plugins.d.ts +0 -45
  93. package/dist/pluginsCli-7XWDLJEL.js +0 -288
  94. package/dist/pluginsCli.d.ts +0 -16
  95. package/dist/prCli-FH7N26D4.js +0 -94
  96. package/dist/prCli.d.ts +0 -46
  97. package/dist/presets.d.ts +0 -8
  98. package/dist/print.d.ts +0 -17
  99. package/dist/provider.d.ts +0 -145
  100. package/dist/providerCli-YMG4G56R.js +0 -15
  101. package/dist/providerCli.d.ts +0 -17
  102. package/dist/providers.d.ts +0 -6
  103. package/dist/reasoning.d.ts +0 -12
  104. package/dist/repomap.d.ts +0 -10
  105. package/dist/sdk.d.ts +0 -61
  106. package/dist/sdk.js +0 -6532
  107. package/dist/serve-HSFF6MGB.js +0 -178
  108. package/dist/serve-HUQNVOSP.js +0 -532
  109. package/dist/serve.d.ts +0 -37
  110. package/dist/serveHeartbeat.d.ts +0 -14
  111. package/dist/serveProtocol.d.ts +0 -47
  112. package/dist/session-YM36TGU7.js +0 -12
  113. package/dist/session.d.ts +0 -33
  114. package/dist/setup-3YB6EKYX.js +0 -24
  115. package/dist/setup.d.ts +0 -79
  116. package/dist/slash/copy.d.ts +0 -1
  117. package/dist/slash/diff.d.ts +0 -1
  118. package/dist/slash/doctor.d.ts +0 -18
  119. package/dist/slash/export.d.ts +0 -2
  120. package/dist/slash/info.d.ts +0 -46
  121. package/dist/slash/memory.d.ts +0 -10
  122. package/dist/statsCli-I4TSDU3X.js +0 -353
  123. package/dist/statsCli.d.ts +0 -62
  124. package/dist/textToolCalls.d.ts +0 -6
  125. package/dist/thinking.d.ts +0 -17
  126. package/dist/tokenBudget.d.ts +0 -22
  127. package/dist/tools/bash.d.ts +0 -54
  128. package/dist/tools/diagnostics.d.ts +0 -13
  129. package/dist/tools/edit.d.ts +0 -12
  130. package/dist/tools/fetch.d.ts +0 -41
  131. package/dist/tools/glob.d.ts +0 -5
  132. package/dist/tools/globSafety.d.ts +0 -7
  133. package/dist/tools/grep.d.ts +0 -25
  134. package/dist/tools/ignore.d.ts +0 -2
  135. package/dist/tools/index.d.ts +0 -12
  136. package/dist/tools/memory.d.ts +0 -13
  137. package/dist/tools/paths.d.ts +0 -4
  138. package/dist/tools/plan.d.ts +0 -10
  139. package/dist/tools/read.d.ts +0 -16
  140. package/dist/tools/repomap.d.ts +0 -2
  141. package/dist/tools/sandbox.d.ts +0 -15
  142. package/dist/tools/shell.d.ts +0 -18
  143. package/dist/tools/skill.d.ts +0 -3
  144. package/dist/tools/task.d.ts +0 -28
  145. package/dist/tools/todo.d.ts +0 -13
  146. package/dist/tools/types.d.ts +0 -52
  147. package/dist/tools/websearch.d.ts +0 -9
  148. package/dist/tools/write.d.ts +0 -5
  149. package/dist/transferCli-3B4LMOYI.js +0 -73
  150. package/dist/transferCli.d.ts +0 -23
  151. package/dist/ui/App.d.ts +0 -7
  152. package/dist/ui/DiffView.d.ts +0 -3
  153. package/dist/ui/EditableText.d.ts +0 -7
  154. package/dist/ui/LinePrompt.d.ts +0 -6
  155. package/dist/ui/ListPicker.d.ts +0 -11
  156. package/dist/ui/Markdown.d.ts +0 -8
  157. package/dist/ui/McpMenu.d.ts +0 -11
  158. package/dist/ui/ModelPicker.d.ts +0 -6
  159. package/dist/ui/PermissionPrompt.d.ts +0 -5
  160. package/dist/ui/PlanApproval.d.ts +0 -5
  161. package/dist/ui/PromptInput.d.ts +0 -20
  162. package/dist/ui/ProviderMenu.d.ts +0 -10
  163. package/dist/ui/Spinner.d.ts +0 -4
  164. package/dist/ui/StatusBar.d.ts +0 -14
  165. package/dist/ui/TodoList.d.ts +0 -4
  166. package/dist/ui/ToolBlock.d.ts +0 -14
  167. package/dist/ui/complete.d.ts +0 -8
  168. package/dist/ui/index.d.ts +0 -7
  169. package/dist/ui/lineEdit.d.ts +0 -42
  170. package/dist/ui/liveCap.d.ts +0 -29
  171. package/dist/ui/markdownLayout.d.ts +0 -23
  172. package/dist/ui/replay.d.ts +0 -4
  173. package/dist/ui/stdinFilter.d.ts +0 -18
  174. package/dist/ui/table.d.ts +0 -20
  175. package/dist/ui/theme.d.ts +0 -5
  176. package/dist/ui/thinkingMouse.d.ts +0 -38
  177. package/dist/ui/transcript.d.ts +0 -55
  178. package/dist/ui/tty.d.ts +0 -11
  179. package/dist/ui/vim.d.ts +0 -26
  180. package/dist/ui-TAZMRXRI.js +0 -3044
  181. package/dist/update-5V425FIK.js +0 -145
  182. package/dist/update.d.ts +0 -30
  183. package/dist/verify.d.ts +0 -16
  184. package/dist/version.d.ts +0 -1
  185. package/dist/webBudget.d.ts +0 -25
  186. package/dist/worktree.d.ts +0 -12
package/cli.mjs ADDED
@@ -0,0 +1,120 @@
1
+ #!/usr/bin/env node
2
+ import { readFileSync } from 'node:fs'
3
+ import { DEFAULT_MODEL, assertCandidateRuntimeSupported, discoverModels, launchQwen, parseArgs, resolveQwenEntrypoint, resolveTrustedMcpConfig, selectModel } from './core.mjs'
4
+ import { prepareBrandedQwen } from './branding.mjs'
5
+ import { botConnectorCredentialStatus } from './credentials.mjs'
6
+ import { resolveProvider, selectedProvider, providerDefinition } from './providers.mjs'
7
+ import { runProviderCommand } from './provider-cli.mjs'
8
+ import { startupMenu, autoSelectStartup, PROVIDER_SWITCH_EXIT } from './startup-menu.mjs'
9
+
10
+ function help() {
11
+ console.log([
12
+ 'BCCLI | BotConnector Coding Agent',
13
+ 'Usage:',
14
+ ' bccli models [--json]',
15
+ ' bccli run --model MODEL "prompt" [--mcp-config OWNER_CONFIG_PATH]',
16
+ ' bccli -p "prompt" [-m MODEL] (text-only headless alias)',
17
+ ' bccli --version',
18
+ ' bccli chat [--model MODEL] [--mcp-config OWNER_CONFIG_PATH]',
19
+ ' bccli resume [--model MODEL] [prompt]',
20
+ ' bccli -c [-m MODEL] [prompt] (resume latest current-project session)',
21
+ ' bccli -r [SESSION_UUID] [-m MODEL] (native Qwen session picker or specific session)',
22
+ ' bccli auth status (offline; does not print API key)',
23
+ ' bccli provider list|add|use|remove [ID] (manage provider keys)',
24
+ ' bccli models --provider ID (list models for provider)',
25
+ ' bccli chat --provider ID --model MODEL_ID',
26
+ ' bccli (open chat directly with active provider and last model)',
27
+ ' bccli --choose (open provider/model picker explicitly)',
28
+ ' During chat: /provider or /auth to reopen provider and key picker.',
29
+ '',
30
+ 'Credentials: existing BotConnector login or encrypted per-user provider API keys (Windows).',
31
+ 'Provider choices: botconnector, openai, openrouter, deepseek, groq, xai.',
32
+ 'Key entry: bccli provider add openrouter (hidden terminal prompt).',
33
+ 'Model choice: --model; BotConnector defaults to ling-3.0-flash. Other providers need --model.',
34
+ 'Security: allowlisted provider endpoints, ephemeral local token, --bare and default approvals.',
35
+ 'MCP: explicit JSON only, directly under ~/.bccli-preview/ (no project configs).',
36
+ 'Text-only -p alias; public --output-format JSON/stream-json are not yet supported.',
37
+ 'Local new-engine RC; the public npm stable release is unchanged.',
38
+ ].join('\n'))
39
+ }
40
+
41
+ async function main() {
42
+ const argv = process.argv.slice(2)
43
+ if (argv.length === 0 && !process.stdin.isTTY) { help(); return 2 }
44
+ if (argv[0] === '--help' || argv[0] === '-h' || argv[0] === 'help') { help(); return 0 }
45
+ if (argv.length === 1 && (argv[0] === '--version' || argv[0] === '-v')) {
46
+ // Offline informational command: never inspect credentials or contact Gateway.
47
+ const pkg = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8'))
48
+ console.log(pkg.version)
49
+ return 0
50
+ }
51
+ const forceChoose = argv.length === 1 && argv[0] === '--choose'
52
+ const args = forceChoose ? { command: 'chat', prompt: '', model: undefined } : parseArgs(argv)
53
+ if (args.command === 'provider') return runProviderCommand(args.prompt.trim() ? args.prompt.trim().split(/\s+/) : [])
54
+ if (args.command === 'auth') {
55
+ const status = botConnectorCredentialStatus()
56
+ if (status.configured) {
57
+ console.log('BotConnector credential configured via ' +
58
+ (status.source === 'environment' ? 'BOTCONNECTOR_API_KEY environment variable.' : 'existing public BCCLI bc-cloud login.') +
59
+ ' Not verified online. No AI request was sent.')
60
+ return 0
61
+ }
62
+ console.error('BotConnector credential not configured or unreadable. ' +
63
+ 'Use the existing legacy login via "bccli-legacy login bc-cloud" or set BOTCONNECTOR_API_KEY. ' +
64
+ 'No credential was changed and no AI request was sent.')
65
+ return 1
66
+ }
67
+ if (args.command !== 'models') assertCandidateRuntimeSupported()
68
+ if (args.command === 'models') {
69
+ const profile = resolveProvider(args.provider ?? selectedProvider())
70
+ const models = await discoverModels({ key: profile.key, endpoint: profile.endpoint })
71
+ if (args.json) console.log(JSON.stringify({ data: models }, null, 2))
72
+ else models.forEach((item) => console.log(item.id))
73
+ return 0
74
+ }
75
+ if (!args.prompt && !process.stdin.isTTY) throw Error('Interactive mode requires a TTY; use -p "prompt".')
76
+ const mcpConfig = resolveTrustedMcpConfig(args.mcpConfig)
77
+ let chosen
78
+ const showPicker = args.command === 'chat' && !args.prompt && !args.model
79
+ if (showPicker) {
80
+ chosen = forceChoose ? undefined : await autoSelectStartup({
81
+ ...(args.provider ? { providerId: args.provider } : {}),
82
+ })
83
+ if (!chosen) chosen = await startupMenu({
84
+ ...(args.provider ? { currentProvider: () => args.provider } : {}),
85
+ })
86
+ } else {
87
+ const providerId = args.provider ?? selectedProvider()
88
+ const profile = resolveProvider(providerId)
89
+ const models = await discoverModels({ key: profile.key, endpoint: profile.endpoint })
90
+ const requested = args.model ??
91
+ (providerId === 'botconnector' ? (process.env.BOTCONNECTOR_MODEL_ID ?? DEFAULT_MODEL) : undefined)
92
+ if (!requested) throw Error('Use --model MODEL_ID for ' + providerId + '.')
93
+ chosen = { providerId, model: selectModel(models, requested), key: profile.key, endpoint: profile.endpoint }
94
+ }
95
+ const entrypoint = prepareBrandedQwen(resolveQwenEntrypoint())
96
+ let continueSession = args.command === 'resume'
97
+ let resumeSession = args.resumeSession
98
+ for (;;) {
99
+ console.log('BCCLI | ' + providerDefinition(chosen.providerId).name + ' | ' + chosen.model)
100
+ const code = await launchQwen({
101
+ key: chosen.key, model: chosen.model, prompt: args.prompt,
102
+ mcpConfig, entrypoint, upstream: chosen.endpoint,
103
+ providerId: chosen.providerId, continueSession, resumeSession,
104
+ })
105
+ if (code !== PROVIDER_SWITCH_EXIT) return code
106
+ if (args.prompt || !process.stdin.isTTY) throw Error('Provider menu requires an interactive terminal.')
107
+ // /provider and /auth close the current engine cleanly, then the parent
108
+ // asks for a key and model. Keys never enter the Qwen agent process.
109
+ resumeSession = undefined // Native picker is used only on the first launch.
110
+ const previousProvider = chosen.providerId
111
+ chosen = await startupMenu()
112
+ continueSession = previousProvider === chosen.providerId
113
+ }
114
+ }
115
+
116
+ main().then((code) => { process.exitCode = code }, (error) => {
117
+ // Error messages deliberately never contain credentials or raw HTTP response bodies.
118
+ console.error('BCCLI: ' + (error instanceof Error ? error.message : 'Unexpected error.'))
119
+ process.exitCode = 1
120
+ })
package/core.mjs ADDED
@@ -0,0 +1,260 @@
1
+ // BCCLI candidate adapter. Intentionally outside the Qwen Code engine.
2
+ import { spawn } from 'node:child_process'
3
+ import { createRequire } from 'node:module'
4
+ import { homedir } from 'node:os'
5
+ import { readFileSync, realpathSync, lstatSync } from 'node:fs'
6
+ import { dirname, join, isAbsolute } from 'node:path'
7
+ import { startGatewayProxy } from './proxy.mjs'
8
+ import { GATEWAY } from './gateway.mjs'
9
+
10
+ export { GATEWAY } from './gateway.mjs'
11
+ export const DEFAULT_MODEL = 'ling-3.0-flash'
12
+
13
+ // Qwen Code 0.26.3 Windows tool-loop exits cleanly with Node 24.22.1
14
+ // (GitHub Actions), but repeatedly crashes on Windows Node 24.18.0
15
+ // with libuv UV_HANDLE_CLOSING after delivering the tool result.
16
+ // This guard affects ONLY the isolated candidate, not public BCCLI.
17
+ export function assertCandidateRuntimeSupported({ platform = process.platform, nodeVersion = process.versions.node } = {}) {
18
+ const parts = /^(\d+)\.(\d+)\.(\d+)(?:$|[-+])/.exec(String(nodeVersion))
19
+ if (!parts) throw Error('Cannot verify the Node.js version for BCCLI candidate.')
20
+ const major = Number(parts[1]), minor = Number(parts[2]), patch = Number(parts[3])
21
+ if (platform === 'win32' && major === 24 && (minor < 22 || (minor === 22 && patch < 1))) {
22
+ throw Error('Windows Node.js ' + nodeVersion + ' may crash after coding tools. Use Node.js 24.22.1 or newer, or Node.js 22.23.4. Existing public BCCLI is unaffected.')
23
+ }
24
+ }
25
+ const MODEL_ID = /^[a-zA-Z0-9][a-zA-Z0-9._:/+-]{0,255}$/
26
+ const ALLOWED = new Set(['models', 'run', 'chat', 'resume', 'auth', 'provider'])
27
+ // Public BCCLI commands are not supported by this isolated candidate. Do
28
+ // not accidentally treat them as AI prompts, which could spend user credits.
29
+ const PUBLIC_ONLY_COMMANDS = new Set([
30
+ 'login', 'logout', 'mcp', 'connect', 'disconnect',
31
+ 'integrations', 'update', 'serve', 'acp', 'plugins', 'gh-bot',
32
+ 'completion', 'stats', 'export', 'import', 'pr',
33
+ ])
34
+
35
+ export function parseArgs(argv) {
36
+ const args = [...argv]
37
+ // Public BCCLI accepts options before subcommands. This candidate does
38
+ // not: reject those spellings rather than accidentally charging for a
39
+ // prompt such as "-m ling login" or "-m ling models".
40
+ if (!args.includes('-p') && !args.includes('--print') && !args.includes('-c') && !args.includes('--continue') && !ALLOWED.has(args[0])) {
41
+ let firstWord
42
+ for (let i = 0; i < args.length; i++) {
43
+ const flag = args[i]
44
+ if (flag === '--model' || flag === '-m' || flag === '--mcp-config') { i++; continue }
45
+ if (flag.startsWith('-')) continue
46
+ firstWord = flag
47
+ break
48
+ }
49
+ if (firstWord && (PUBLIC_ONLY_COMMANDS.has(firstWord) || ALLOWED.has(firstWord))) {
50
+ throw Error('Subcommand "' + firstWord + '" must come first in this candidate. No AI request was sent.')
51
+ }
52
+ }
53
+ // Check old public subcommands BEFORE rewriting -p to run: otherwise
54
+ // "login -p" might accidentally become a billable model prompt.
55
+ if (args.length && PUBLIC_ONLY_COMMANDS.has(args[0])) {
56
+ throw Error('Command "' + args[0] + '" is available only in public BCCLI 0.4.17, not this isolated candidate. No AI request was sent.')
57
+ }
58
+ // Qwen handles both -c and -r natively. Never combine the two session modes.
59
+ if (args.some(a => a === '-c' || a === '--continue') && args.some(a => a === '-r' || a === '--resume')) {
60
+ throw Error('Use either -c or -r, not both. No AI request was sent.')
61
+ }
62
+ // The public -c/--continue resumes the last *current-project* session.
63
+ // Candidate Qwen 'resume' already implements that behavior in isolation.
64
+ const continueFlags = args.filter(a => a === '-c' || a === '--continue')
65
+ if (continueFlags.length > 1) throw Error('Specify -c / --continue only once.')
66
+ if (continueFlags.length) {
67
+ if (args.some(a => a === '-p' || a === '--print')) throw Error('Combining -c with -p is not yet supported by the candidate.')
68
+ const otherArgs = args.filter(a => a !== continueFlags[0])
69
+ if (ALLOWED.has(otherArgs[0])) throw Error('-c / --continue is not compatible with an explicit subcommand; use resume directly.')
70
+ args.splice(args.indexOf(continueFlags[0]), 1)
71
+ args.unshift('resume')
72
+ }
73
+ // Keep public BCCLI's common noninteractive invocation as a safe alias.
74
+ // Do not imply parity with public JSON/stream-json.
75
+ const printIndexes = args.flatMap((arg, i) => arg === '-p' || arg === '--print' ? [i] : [])
76
+ if (printIndexes.length > 1) throw Error('Specify -p / --print only once.')
77
+ if (printIndexes.length === 1) {
78
+ args.splice(printIndexes[0], 1)
79
+ if (ALLOWED.has(args[0]) && args[0] !== 'run') {
80
+ throw Error('-p / --print only supports a single headless run, not ' + args[0] + '.')
81
+ }
82
+ if (args[0] !== 'run') args.unshift('run')
83
+ }
84
+ const command = ALLOWED.has(args[0]) ? args.shift() : 'chat'
85
+ let model, mcpConfig, provider, json = false, resumeSession
86
+ const prompt = []
87
+ while (args.length) {
88
+ const arg = args.shift()
89
+ if (arg === '-r' || arg === '--resume') {
90
+ if (command !== 'chat' || resumeSession !== undefined) throw Error('Use -r [SESSION_UUID] only once for interactive chat.')
91
+ const next = args[0]
92
+ if (next && !next.startsWith('-')) {
93
+ if (!/^[a-f\d]{8}-(?:[a-f\d]{4}-){3}[a-f\d]{12}$/i.test(next)) {
94
+ throw Error('Session ID must be a UUID. No AI request was sent.')
95
+ }
96
+ resumeSession = args.shift()
97
+ } else {
98
+ resumeSession = null // Native Qwen --resume with no ID opens its own session picker.
99
+ }
100
+ continue
101
+ }
102
+ if (arg === '--model' || arg === '-m') {
103
+ if (model !== undefined || !args.length) throw Error('Specify --model exactly once with an ID.')
104
+ model = args.shift()
105
+ continue
106
+ }
107
+ if (arg === '--provider') {
108
+ if (provider !== undefined || !args.length || args[0].startsWith('-')) throw Error('--provider requires exactly one provider ID.')
109
+ provider = args.shift()
110
+ continue
111
+ }
112
+ if (arg === '--mcp-config') {
113
+ if (mcpConfig !== undefined || !args.length || args[0].startsWith('-')) throw Error('--mcp-config requires exactly one absolute path.')
114
+ mcpConfig = args.shift()
115
+ continue
116
+ }
117
+ if (arg === '--json' && command === 'models') { json = true; continue }
118
+ if (arg.startsWith('-')) throw Error('Unsupported option. POC intentionally blocks passthrough flags.')
119
+ prompt.push(arg)
120
+ }
121
+ if (command === 'provider' && (model || mcpConfig || provider || json)) throw Error('Use: provider list | add ID | use ID | remove ID.')
122
+ if (command === 'auth' && (model || mcpConfig || json || prompt.join(' ') !== 'status')) throw Error('Use: auth status (offline and read-only).')
123
+ if (command === 'models' && (model || mcpConfig || prompt.length)) throw Error('Use: models [--json].')
124
+ if (resumeSession !== undefined && prompt.length) throw Error('Session picker cannot be combined with a prompt.')
125
+ if (command === 'run' && !prompt.length) throw Error('Use: run --model MODEL "prompt".')
126
+ return { command, model, json, prompt: prompt.join(' '), ...(mcpConfig ? { mcpConfig } : {}), ...(provider ? { provider } : {}), ...(resumeSession !== undefined ? { resumeSession } : {}) }
127
+ }
128
+
129
+ export async function discoverModels({ key, fetchImpl = fetch, endpoint = GATEWAY }) {
130
+ if (!key || !key.trim()) throw Error('BOTCONNECTOR_API_KEY is required (do not supply it as a CLI argument).')
131
+ let response
132
+ try {
133
+ response = await fetchImpl(endpoint + '/models', {
134
+ method: 'GET',
135
+ headers: { authorization: 'Bearer ' + key, accept: 'application/json' },
136
+ redirect: 'error',
137
+ signal: AbortSignal.timeout(12000),
138
+ })
139
+ } catch {
140
+ throw Error('Gateway model discovery failed; no fallback provider was used.')
141
+ }
142
+ if (!response.ok) throw Error('Gateway model discovery failed (HTTP ' + response.status + ').')
143
+ let payload
144
+ try { payload = await response.json() }
145
+ catch { throw Error('Gateway model discovery returned invalid JSON.') }
146
+ if (!Array.isArray(payload?.data)) throw Error('Gateway model discovery returned no model list.')
147
+ const models = new Map()
148
+ for (const item of payload.data) {
149
+ if (typeof item?.id === 'string' && MODEL_ID.test(item.id)) {
150
+ models.set(item.id, { id: item.id, name: typeof item.name === 'string' ? item.name : item.id })
151
+ }
152
+ }
153
+ if (!models.size) throw Error('No valid models available to this key.')
154
+ return [...models.values()]
155
+ }
156
+
157
+ export function selectModel(models, value) {
158
+ if (!value) throw Error('Select a model with --model ID or BOTCONNECTOR_MODEL_ID; run models first.')
159
+ if (!MODEL_ID.test(value)) throw Error('Invalid model ID.')
160
+ if (!models.some((item) => item.id === value)) throw Error('Model is not available for this BotConnector API key.')
161
+ return value
162
+ }
163
+
164
+ export function qwenArguments(model, prompt, endpoint = GATEWAY, { mcpConfig, continueSession = false, resumeSession } = {}) {
165
+ if (continueSession && resumeSession !== undefined) throw Error('Cannot combine native Qwen --continue with --resume.')
166
+ // --bare is security critical: project settings may otherwise override
167
+ // the provider baseUrl, forwarding an API key to an attacker-controlled endpoint.
168
+ const args = [
169
+ '--bare', '--auth-type', 'openai',
170
+ '--openai-base-url', endpoint,
171
+ '--model', model, '--approval-mode', 'default',
172
+ '--telemetry=false',
173
+ ]
174
+ // The active AI can change with /model. Do not embed the STARTUP model
175
+ // here: doing so would falsely identify a later selected model.
176
+ // The BotConnector local proxy adds the actual request model to each
177
+ // chat call, without forcing the AI to impersonate BCCLI.
178
+ args.push('--append-system-prompt',
179
+ 'Client application: BCCLI. The upstream coding engine is Qwen Code, which is software, not the AI model answering the user. Identify the responding AI using active_model_id from current-request runtime metadata (the model can change mid-session). If no current model ID is available, state that it is unknown. Do not call the assistant Qwen Code or BCCLI as if either were the AI model, and do not infer who developed the active model from the application or engine brand.')
180
+ if (mcpConfig) args.push('--mcp-config', mcpConfig)
181
+ if (continueSession) args.push('--continue')
182
+ if (resumeSession !== undefined) args.push('--resume', ...(resumeSession === null ? [] : [resumeSession]))
183
+ if (prompt) args.push(prompt)
184
+ return args
185
+ }
186
+
187
+ export function childEnvironment(base, key, model, { endpoint = GATEWAY, home, providerId = 'botconnector' } = {}) {
188
+ const env = { ...base }
189
+ // Prevent inherited cross-provider auth from becoming another route or key.
190
+ for (const name of [
191
+ 'QWEN_OAUTH', 'BOTCONNECTOR_API_KEY', 'OPENAI_API_KEY', 'OPENAI_BASE_URL', 'OPENAI_MODEL', 'QWEN_MODEL',
192
+ 'ANTHROPIC_API_KEY', 'ANTHROPIC_BASE_URL', 'GEMINI_API_KEY',
193
+ 'GOOGLE_API_KEY', 'OPENROUTER_API_KEY', 'QWENCLOUD_API_KEY',
194
+ 'QWENCLOUD_TOKEN_PLAN_API_KEY', 'DEEPSEEK_API_KEY', 'GROQ_API_KEY', 'XAI_API_KEY',
195
+ ]) delete env[name]
196
+ env.OPENAI_API_KEY = key
197
+ env.OPENAI_BASE_URL = endpoint
198
+ env.OPENAI_MODEL = model
199
+ env.QWEN_MODEL = model
200
+ env.QWEN_HOME = home ?? (providerId === 'botconnector' ? join(homedir(), '.bccli-preview') : join(homedir(), '.bccli-preview', 'sessions-' + providerId))
201
+ env.BCCLI_ACTIVE_PROVIDER = providerId
202
+ env.CLI_TITLE = 'BCCLI - ' + process.cwd().split(/[\\/]/).filter(Boolean).at(-1)
203
+ env.QWEN_CODE_SKIP_UPDATE_CHECK_ONCE = 'true' // Never query or install upstream Qwen releases.
204
+ return env
205
+ }
206
+
207
+ // Explicit MCP servers run local commands on startup, so they must originate
208
+ // from a config file the user deliberately placed outside any cloned project.
209
+ // There is no automatic project/user MCP discovery when Qwen runs --bare.
210
+ export function resolveTrustedMcpConfig(input, { home = join(homedir(), '.bccli-preview') } = {}) {
211
+ if (!input) return undefined
212
+ if (!isAbsolute(input)) throw Error('MCP config must use an absolute path.')
213
+ let realHome, file, stats
214
+ try {
215
+ realHome = realpathSync(home)
216
+ file = realpathSync(input)
217
+ stats = lstatSync(input)
218
+ } catch {
219
+ throw Error('MCP config must be a readable file in the owner config directory.')
220
+ }
221
+ if (stats.isSymbolicLink() || !stats.isFile() || dirname(file) !== realHome) {
222
+ throw Error('MCP config must be a regular file directly in the owner config directory.')
223
+ }
224
+ let config
225
+ try { config = JSON.parse(readFileSync(file, 'utf8')) }
226
+ catch { throw Error('MCP config must contain valid JSON.') }
227
+ if (!config || typeof config !== 'object' || Array.isArray(config) ||
228
+ !config.mcpServers || typeof config.mcpServers !== 'object' || Array.isArray(config.mcpServers)) {
229
+ throw Error('MCP config must contain mcpServers.')
230
+ }
231
+ if (Object.keys(config).some((name) => name !== 'mcpServers')) {
232
+ throw Error('MCP config may contain only mcpServers (no provider or credential overrides).')
233
+ }
234
+ if (!Object.keys(config.mcpServers).length) throw Error('MCP config must define at least one server.')
235
+ return file
236
+ }
237
+
238
+ export function resolveQwenEntrypoint() {
239
+ const require = createRequire(import.meta.url)
240
+ return join(dirname(require.resolve('@qwen-code/qwen-code/package.json')), 'cli-entry.js')
241
+ }
242
+
243
+ export async function launchQwen({ key, model, prompt, mcpConfig, continueSession = false, resumeSession, upstream = GATEWAY, providerId = 'botconnector', env = process.env, entrypoint = resolveQwenEntrypoint(), spawnImpl = spawn, proxyFactory = startGatewayProxy }) {
244
+ // The real API key never enters Qwen, its tools, or any MCP child process.
245
+ // Only this launcher retains it while the ephemeral proxy is running.
246
+ const proxy = await proxyFactory({ key, endpoint: upstream })
247
+ try {
248
+ const args = [entrypoint, ...qwenArguments(model, prompt, proxy.baseUrl, { mcpConfig, continueSession, resumeSession })]
249
+ const child = spawnImpl(process.execPath, args, {
250
+ cwd: process.cwd(), env: childEnvironment(env, proxy.token, model, { endpoint: proxy.baseUrl, providerId }),
251
+ stdio: 'inherit', windowsHide: false, shell: false,
252
+ })
253
+ return await new Promise((resolve, reject) => {
254
+ child.once('error', reject)
255
+ child.once('exit', (code, signal) => resolve(code ?? (signal ? 130 : 1)))
256
+ })
257
+ } finally {
258
+ await proxy.close()
259
+ }
260
+ }
@@ -0,0 +1,52 @@
1
+ // Credentials bridge: reuse an owner's existing BCCLI bc-cloud login without
2
+ // another provider account or a second credential store. Never log the key.
3
+ import { homedir } from 'node:os'
4
+ import { join, isAbsolute } from 'node:path'
5
+ import { lstatSync, readFileSync } from 'node:fs'
6
+
7
+ const MAX_CREDENTIAL_FILE_BYTES = 64 * 1024
8
+
9
+ export function botConnectorKey({ env = process.env, home = homedir() } = {}) {
10
+ if (typeof env.BOTCONNECTOR_API_KEY === 'string' && env.BOTCONNECTOR_API_KEY.trim()) {
11
+ return env.BOTCONNECTOR_API_KEY.trim()
12
+ }
13
+ const override = env.BCCLI_HOME
14
+ const base = override ? override : join(home, '.bccli')
15
+ if (!isAbsolute(base)) throw Error('BCCLI_HOME must be an absolute directory.')
16
+ const path = join(base, 'credentials')
17
+ let info
18
+ try { info = lstatSync(path) }
19
+ catch (error) {
20
+ if (error?.code === 'ENOENT') {
21
+ throw Error('No BotConnector login. Run bccli login to save your bc-cloud key, or set BOTCONNECTOR_API_KEY.')
22
+ }
23
+ throw Error('Cannot inspect the existing BCCLI credentials file.')
24
+ }
25
+ if (!info.isFile() || info.isSymbolicLink() || info.size > MAX_CREDENTIAL_FILE_BYTES) {
26
+ throw Error('Invalid BCCLI credentials file; do not follow symlinks or oversized files.')
27
+ }
28
+ let data
29
+ try { data = JSON.parse(readFileSync(path, 'utf8')) }
30
+ catch { throw Error('Existing BCCLI credentials are not valid JSON.') }
31
+ const key = data && typeof data === 'object' && !Array.isArray(data) ? data['bc-cloud'] : null
32
+ if (typeof key !== 'string' || !key.trim()) {
33
+ throw Error('No bc-cloud key saved. Run bccli login or set BOTCONNECTOR_API_KEY.')
34
+ }
35
+ return key.trim()
36
+ }
37
+
38
+ /**
39
+ * Offline, read-only status. Reuse the public BCCLI bc-cloud login; never
40
+ * duplicate, rewrite, mask-print, or migrate the long-lived secret.
41
+ * "configured" means a credential exists, not that Gateway accepted it.
42
+ */
43
+ export function botConnectorCredentialStatus({ env = process.env, home = homedir() } = {}) {
44
+ const viaEnvironment = typeof env.BOTCONNECTOR_API_KEY === 'string' && !!env.BOTCONNECTOR_API_KEY.trim()
45
+ try {
46
+ botConnectorKey({ env, home })
47
+ return { configured: true, source: viaEnvironment ? 'environment' : 'public-bccli' }
48
+ } catch (error) {
49
+ // All botConnectorKey errors are intentionally static; do not include keys.
50
+ return { configured: false, source: 'none', reason: error instanceof Error ? error.message : 'Credential inspection failed.' }
51
+ }
52
+ }
package/gateway.mjs ADDED
@@ -0,0 +1,2 @@
1
+ // Stable, audited BotConnector destination. Never accept this from a project settings file.
2
+ export const GATEWAY = 'https://api.botconnector.id/v1'
@@ -0,0 +1,61 @@
1
+ // Generated, version-pinned Qwen slash command overlay for /model.
2
+ // Fetches the authenticated model catalog from the existing local BotConnector
3
+ // proxy on each invocation. Selection changes Qwen Config in the current
4
+ // session; it never opens upstream provider settings or writes project config.
5
+ export const BCCLI_MODEL_COMMAND = String.raw`var bccliModelLastList=[];var modelCommand={name:"model",get description(){return "Choose an AI model from the active provider"},argumentHint:"[number|model-id|search WORD|page N]",kind:"built-in",supportedModes:["interactive","non_interactive","acp"],action:__name(async(context,argumentText)=>{
6
+ var response=(type,content)=>({type:"message",messageType:type,content});
7
+ try{
8
+ var base=process.env.OPENAI_BASE_URL||"";
9
+ var key=process.env.OPENAI_API_KEY||"";
10
+ if(!/^http:\/\/127\.0\.0\.1:[0-9]{1,5}\/v1$/.test(base)||!key){
11
+ return response("error","BCCLI requires an authenticated local provider session.");
12
+ }
13
+ var result=await fetch(base+"/models",{method:"GET",headers:{Authorization:"Bearer "+key,Accept:"application/json"},redirect:"error",signal:AbortSignal.timeout(10000)});
14
+ if(!result.ok)return response("error","Provider model catalog is unavailable (HTTP "+result.status+"). No provider fallback.");
15
+ var payload=await result.json();
16
+ if(!Array.isArray(payload?.data))return response("error","Invalid provider model catalog.");
17
+ var catalog=new Map();
18
+ for(var entry of payload.data){
19
+ if(typeof entry?.id==="string" && /^[a-zA-Z0-9][a-zA-Z0-9._:/+-]{0,255}$/.test(entry.id) && !catalog.has(entry.id)){
20
+ catalog.set(entry.id,{id:entry.id,name:typeof entry.name==="string"?entry.name.slice(0,90):entry.id});
21
+ }
22
+ }
23
+ var all=[...catalog.values()].sort((a,b)=>a.id.localeCompare(b.id));
24
+ if(!all.length)return response("error","No provider models available for this API key.");
25
+ var text=String(context.invocation?.args||argumentText||"").trim();
26
+ var config=context.services?.config;
27
+ if(!config||typeof config.setModel!=="function")return response("error","BCCLI model switch is unavailable in this session.");
28
+ var current=config.getModel?.()||process.env.OPENAI_MODEL||"(unknown)";
29
+ var list=(entries,page=1)=>{
30
+ bccliModelLastList=entries.map(x=>x.id);
31
+ var size=12;
32
+ var pages=Math.max(1,Math.ceil(entries.length/size));
33
+ if(!Number.isSafeInteger(page)||page<1||page>pages)return response("error","Invalid page. Use /model page 1 ... "+pages);
34
+ var start=(page-1)*size;
35
+ var rows=entries.slice(start,start+size).map((x,i)=>(start+i+1)+". "+x.id+(x.id===current?" [ACTIVE]":""));
36
+ return response("info","Provider AI models ("+entries.length+" available; page "+page+"/"+pages+")\nActive: "+current+"\n\n"+rows.join("\n")+"\n\nUse /model NUMBER or /model MODEL_ID to switch now; /model page N; /model search KEYWORD. To change providers, use bccli provider use PROVIDER before a new chat.");
37
+ };
38
+ if(!text)return list(all);
39
+ var page=text.match(/^page\s+([0-9]+)$/i);
40
+ if(page)return list(all,Number(page[1]));
41
+ var search=text.match(/^search\s+(.{1,80})$/i);
42
+ if(search)return list(all.filter(x=>x.id.toLowerCase().includes(search[1].toLowerCase())||x.name.toLowerCase().includes(search[1].toLowerCase())));
43
+ var item;
44
+ if(/^[0-9]+$/.test(text)){
45
+ var index=Number(text);
46
+ item=Number.isSafeInteger(index)&&index>=1?catalog.get(bccliModelLastList[index-1]||all[index-1]?.id):undefined;
47
+ }else if(/^[a-zA-Z0-9][a-zA-Z0-9._:/+-]{0,255}$/.test(text)){
48
+ item=catalog.get(text);
49
+ }
50
+ if(!item)return response("error","That model is not available in your active provider catalog. Run /model to view allowed models.");
51
+ if(item.id===current)return response("info","Already using "+item.id+" via the active provider.");
52
+ // Raw model IDs are supported by Config.setModel; this preserves OpenAI
53
+ // auth/loopback proxy instead of switching providers. It refreshes the
54
+ // live content generator, so the next message uses the new model.
55
+ await config.setModel(item.id,{reason:"bccli-gateway-model-picker"});
56
+ if(config.getModel?.()!==item.id)return response("error","Model switch did not take effect; previous model preserved.");
57
+ return response("info","Switched to "+item.id+" in the current session. Routing and billing remain with the active provider.");
58
+ }catch{
59
+ return response("error","Provider model selection failed; no upstream provider fallback was used.");
60
+ }
61
+ },"action")};`
package/package.json CHANGED
@@ -1,77 +1,53 @@
1
1
  {
2
2
  "name": "@botconnector/bccli",
3
- "version": "0.4.17",
4
- "description": "BCCLI — BotConnector AI coding agent for the terminal",
3
+ "version": "0.5.0-rc.4",
4
+ "description": "BCCLI | BotConnector coding agent powered by Qwen Code",
5
5
  "type": "module",
6
6
  "bin": {
7
- "bccli": "dist/cli.js"
7
+ "bccli": "./cli.mjs"
8
8
  },
9
- "files": [
10
- "dist"
11
- ],
12
9
  "engines": {
13
10
  "node": ">=22"
14
11
  },
15
- "repository": {
16
- "type": "git",
17
- "url": "git+https://github.com/farijarifriyanto-debug/bccli.git"
18
- },
19
- "license": "MIT",
20
- "scripts": {
21
- "build": "tsup && tsc -p tsconfig.build.json",
22
- "typecheck": "tsc --noEmit",
23
- "lint": "biome lint --error-on-warnings src test",
24
- "test": "vitest run",
25
- "coverage": "vitest run --coverage"
26
- },
27
12
  "dependencies": {
28
- "@modelcontextprotocol/sdk": "^1.32.1",
29
- "diff": "^9.0.0",
30
- "ink": "^8.0.0",
31
- "openai": "^7.27.0",
32
- "react": "^19.3.0",
33
- "undici": "^8.12.1",
34
- "ws": "^8.22.0",
35
- "yaml": "^2.9.1",
36
- "zod": "^4.6.5"
13
+ "@qwen-code/qwen-code": "0.26.3"
37
14
  },
38
- "devDependencies": {
39
- "@biomejs/biome": "^2.5.14",
40
- "@types/node": "^26.6.3",
41
- "@types/react": "^19.3.0",
42
- "@types/ws": "^8.18.2",
43
- "@vitest/coverage-v8": "^5.0.5",
44
- "ink-testing-library": "^4.0.0",
45
- "tsup": "^9.0.0",
46
- "typescript": "^7.0.2",
47
- "vitest": "^5.0.2"
15
+ "scripts": {
16
+ "test": "node --test test/*.test.mjs",
17
+ "test:security": "node --test test/security-e2e.test.mjs test/proxy-mcp-e2e.test.mjs test/trusted-mcp.test.mjs test/proxy.test.mjs",
18
+ "test:integration": "node --test test-integration/*.test.mjs",
19
+ "build": "node --check cli.mjs && node --check core.mjs && node --check proxy.mjs && node --check gateway.mjs && node --check branding.mjs && node --check credentials.mjs && node --check model-command.mjs && node --check providers.mjs && node --check provider-cli.mjs && node --check startup-menu.mjs",
20
+ "rebuild": "npm run build && npm test && npm pack --ignore-scripts"
48
21
  },
22
+ "license": "Apache-2.0",
49
23
  "overrides": {
50
- "esbuild": "0.28.2"
51
- },
52
- "main": "dist/sdk.js",
53
- "types": "dist/sdk.d.ts",
54
- "exports": {
55
- ".": {
56
- "types": "./dist/sdk.d.ts",
57
- "default": "./dist/sdk.js"
58
- }
24
+ "sharp": "0.35.5"
59
25
  },
60
- "keywords": [
61
- "bccli",
62
- "ai",
63
- "coding-agent",
64
- "agent",
65
- "cli",
66
- "tui",
67
- "terminal",
68
- "mcp",
69
- "openai",
70
- "indonesia"
26
+ "files": [
27
+ "LICENSE",
28
+ "THIRD_PARTY_NOTICES.md",
29
+ "cli.mjs",
30
+ "core.mjs",
31
+ "proxy.mjs",
32
+ "gateway.mjs",
33
+ "branding.mjs",
34
+ "credentials.mjs",
35
+ "model-command.mjs",
36
+ "providers.mjs",
37
+ "provider-cli.mjs",
38
+ "startup-menu.mjs"
71
39
  ],
72
- "author": "BotConnector (https://botconnector.id)",
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "git+https://github.com/farijarifriyanto-debug/bccli-qwen-engine.git"
43
+ },
44
+ "homepage": "https://github.com/farijarifriyanto-debug/bccli#readme",
73
45
  "bugs": {
74
46
  "url": "https://github.com/farijarifriyanto-debug/bccli/issues"
75
47
  },
76
- "homepage": "https://github.com/farijarifriyanto-debug/bccli#readme"
48
+ "author": "BICO Inovasi Digital / BotConnector",
49
+ "publishConfig": {
50
+ "access": "public",
51
+ "tag": "next"
52
+ }
77
53
  }