@rimuruchan/ccb 0.1.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/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # ccb
2
+
3
+ Runs the official Claude Code through a claude-code-bridge gateway.
4
+
5
+ ```sh
6
+ npm install -g @rimuruchan/ccb
7
+ ccb login --gateway https://your-gateway
8
+ ccb
9
+ ```
10
+
11
+ npm installs the native ccb for your platform from an optional dependency, and a postinstall step puts it at `bin/ccb.exe` so `ccb` starts without Node. Update with `npm install -g @rimuruchan/ccb@latest`; `ccb update` keeps the Claude Code it downloaded up to date and prints that npm command for ccb itself.
12
+
13
+ If your npm configuration skips install scripts, run `node "$(npm root -g)/@rimuruchan/ccb/install.cjs"` once, or launch through `node "$(npm root -g)/@rimuruchan/ccb/cli-wrapper.cjs"`.
14
+
15
+ Claude Code is not part of this package. ccb uses `claude` from PATH, or downloads the official release from Anthropic and verifies its checksum.
package/bin/ccb.exe ADDED
@@ -0,0 +1,5 @@
1
+ echo "ccb: the native binary was not installed." >&2
2
+ echo "npm skipped the postinstall step (--ignore-scripts) or the platform package (--omit=optional)." >&2
3
+ echo "Reinstall without those options, or run the postinstall yourself:" >&2
4
+ echo " node \"\$(npm root -g)/@rimuruchan/ccb/install.cjs\"" >&2
5
+ exit 1
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env node
2
+ // Fallback launcher for installs where postinstall did not run
3
+ // (--ignore-scripts). It costs a Node process per launch; install.cjs avoids
4
+ // that by placing the native binary at bin/ccb.exe.
5
+ 'use strict'
6
+
7
+ const { spawnSync } = require('child_process')
8
+ const { constants } = require('os')
9
+ const path = require('path')
10
+ const { platformPackage, packageName } = require('./platform.cjs')
11
+
12
+ const native = platformPackage()
13
+ if (!native) {
14
+ console.error(`[${packageName}] ccb has no build for ${process.platform}-${process.arch}.`)
15
+ process.exit(1)
16
+ }
17
+ let binary
18
+ try {
19
+ binary = path.join(path.dirname(require.resolve(native.name + '/package.json')), native.bin)
20
+ } catch {
21
+ console.error(`[${packageName}] ${native.name} is not installed; reinstall ccb.`)
22
+ process.exit(1)
23
+ }
24
+ const result = spawnSync(binary, process.argv.slice(2), { stdio: 'inherit' })
25
+ if (result.error) {
26
+ console.error(`[${packageName}] could not start ${binary}: ${result.error.message}`)
27
+ process.exit(1)
28
+ }
29
+ process.exit(result.signal ? 128 + (constants.signals[result.signal] || 0) : result.status ?? 1)
package/install.cjs ADDED
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env node
2
+ // postinstall for the ccb npm package.
3
+ //
4
+ // npm installs exactly one platform package from optionalDependencies (each
5
+ // declares os and cpu). This script hard-links its native ccb over the
6
+ // bin/ccb.exe placeholder that package.json's "bin" points at, so running ccb
7
+ // executes the Go binary directly with no Node process in between. When the
8
+ // script cannot run or the platform package is missing, the placeholder stays
9
+ // and explains how to recover; cli-wrapper.cjs is the slower fallback.
10
+ 'use strict'
11
+
12
+ const fs = require('fs')
13
+ const path = require('path')
14
+ const { platformPackage, packageName } = require('./platform.cjs')
15
+
16
+ function place(source, target) {
17
+ const placeholder = fs.statSync(target).size < 4096 ? fs.readFileSync(target) : null
18
+ const temporary = target + '.tmp-' + process.pid
19
+ try {
20
+ try {
21
+ fs.linkSync(source, temporary)
22
+ } catch {
23
+ fs.copyFileSync(source, temporary)
24
+ }
25
+ if (process.platform !== 'win32') fs.chmodSync(temporary, 0o755)
26
+ fs.renameSync(temporary, target)
27
+ } catch (err) {
28
+ try { fs.unlinkSync(temporary) } catch {}
29
+ if (placeholder && !fs.existsSync(target)) fs.writeFileSync(target, placeholder, { mode: 0o755 })
30
+ throw err
31
+ }
32
+ }
33
+
34
+ function main() {
35
+ const native = platformPackage()
36
+ if (!native) {
37
+ console.error(`[${packageName}] ccb has no build for ${process.platform}-${process.arch}.`)
38
+ return
39
+ }
40
+ let source
41
+ try {
42
+ source = path.join(path.dirname(require.resolve(native.name + '/package.json')), native.bin)
43
+ } catch {
44
+ console.error(`[${packageName}] ${native.name} was not installed (--omit=optional or a failed download).`)
45
+ console.error(' Reinstall ccb, or run: node ' + path.join(__dirname, 'cli-wrapper.cjs'))
46
+ return
47
+ }
48
+ try {
49
+ place(source, path.join(__dirname, 'bin', 'ccb.exe'))
50
+ } catch (err) {
51
+ console.error(`[${packageName}] could not place the ccb binary: ${err.message}`)
52
+ console.error(' Fallback: node ' + path.join(__dirname, 'cli-wrapper.cjs'))
53
+ process.exitCode = 1
54
+ }
55
+ }
56
+
57
+ main()
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@rimuruchan/ccb",
3
+ "version": "0.1.0",
4
+ "license": "UNLICENSED",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "description": "Run the official Claude Code through a claude-code-bridge gateway",
9
+ "bin": {
10
+ "ccb": "bin/ccb.exe"
11
+ },
12
+ "scripts": {
13
+ "postinstall": "node install.cjs"
14
+ },
15
+ "engines": {
16
+ "node": ">=18"
17
+ },
18
+ "files": [
19
+ "bin/ccb.exe",
20
+ "install.cjs",
21
+ "cli-wrapper.cjs",
22
+ "platform.cjs"
23
+ ],
24
+ "optionalDependencies": {
25
+ "@rimuruchan/ccb-darwin-x64": "0.1.0",
26
+ "@rimuruchan/ccb-darwin-arm64": "0.1.0",
27
+ "@rimuruchan/ccb-linux-x64": "0.1.0",
28
+ "@rimuruchan/ccb-linux-arm64": "0.1.0",
29
+ "@rimuruchan/ccb-win32-x64": "0.1.0",
30
+ "@rimuruchan/ccb-win32-arm64": "0.1.0"
31
+ }
32
+ }
package/platform.cjs ADDED
@@ -0,0 +1,19 @@
1
+ 'use strict'
2
+ // Shared by install.cjs and cli-wrapper.cjs: which platform package holds the
3
+ // native ccb for this machine. ccb is a static Go binary, so one Linux build
4
+ // serves glibc and musl alike.
5
+
6
+ const manifest = require('./package.json')
7
+
8
+ const packageName = manifest.name
9
+ const SUPPORTED = new Set(['darwin-x64', 'darwin-arm64', 'linux-x64', 'linux-arm64', 'win32-x64', 'win32-arm64'])
10
+
11
+ function platformPackage() {
12
+ const key = process.platform + '-' + process.arch
13
+ if (!SUPPORTED.has(key)) return null
14
+ const name = packageName + '-' + key
15
+ if (!(manifest.optionalDependencies || {})[name]) return null
16
+ return { name, bin: process.platform === 'win32' ? 'ccb.exe' : 'ccb' }
17
+ }
18
+
19
+ module.exports = { packageName, platformPackage }