@lapius/bin-cli 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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +92 -0
  3. package/bin/bin +39 -0
  4. package/package.json +39 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Lapius7
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,92 @@
1
+ # bin — bin.lapius7.com CLIクライアント
2
+
3
+ [LapBin](https://bin.lapius7.com/)(Lapountでログインできるコード共有サービス)を、ターミナルの`bin`コマンドから使うためのCLI。Go標準ライブラリのみ、依存パッケージなし。
4
+
5
+ ## インストール
6
+
7
+ npm(Linux / macOS / Windows):
8
+
9
+ ```bash
10
+ npm i -g @lapius/bin-cli
11
+ ```
12
+
13
+ OS/CPUに合ったビルド済みバイナリが入る(Linux/macOSでは初回の起動時にnodeのシムがネイティブバイナリに置き換わり、以後はnodeを経由しない)。更新は同じコマンドで行う。
14
+
15
+ npmがない場合:
16
+
17
+ ```bash
18
+ curl -fsSL https://bin.lapius7.com/install.sh | bash
19
+ ```
20
+
21
+ Goは不要。OS/CPUに合ったビルド済みバイナリを`~/.local/bin/bin`に置く(`BIN_INSTALL_DIR`で変更可)。Windowsは`https://bin.lapius7.com/cli/bin-windows-amd64.exe`を直接ダウンロードする。
22
+
23
+ ## 使い方
24
+
25
+ ```bash
26
+ bin login # ブラウザでLapountにログイン
27
+ bin login --device # SSH先など、手元でブラウザが開けない場合
28
+ bin create main.go util.go -d "説明" # 作成(既定は限定公開)。URLだけが標準出力に出る
29
+ cat build.log | bin create -f build.log --private
30
+ bin list # 自分のGist(-u <handle> で他人の公開Gist)
31
+ bin view <id> # 表示(-f <file> で1ファイルだけ生出力)
32
+ bin edit <id> main.go --remove old.go -t "新しいタイトル" --public
33
+ bin clone <id> [dir] # ファイルをダウンロード
34
+ bin fork <id> -t "派生版" # コピーして自分の新しいGistを作る(自分のGistも可、公開範囲は元のまま)
35
+ bin delete <id> # 削除(確認あり、-yで省略)
36
+ bin star <id> / bin starred # スター・スターしたGistの一覧
37
+ bin tag <id> python cli # タグを設定(bin list --tag python で絞り込み)
38
+ bin run <id> # スクリプトを実行(実行前に内容を表示して確認)
39
+ bin version # バージョン表示。配布中の最新版かどうかも確かめる
40
+ ```
41
+
42
+ `<id>`にはGistのURLもそのまま渡せる。
43
+
44
+ ### 手元のフォルダと同期
45
+
46
+ ```bash
47
+ bin clone <id> && cd <id> # .lapbin.json(取得した時点のリビジョンと各ファイルのSHA-256)も置かれる
48
+ bin status # 手元の変更と、Gist側に新しいリビジョンがあるか
49
+ bin pull # Gist側の変更を取り込む(両方で変えたファイルがあれば止まる。--forceでGist側を優先)
50
+ bin push -m "メモ" # 手元のフォルダの内容でGistを更新(Gist側が先に更新されていたら止まる)
51
+ bin sync # pull してから、手元の変更があれば push
52
+ ```
53
+
54
+ git でも取得できる(読み取り専用): `git clone https://bin.lapius7.com/<id>.git`。非公開のGistはパスワードにAPIトークン。
55
+
56
+ ### APIトークン(CI・スクリプト用)
57
+
58
+ ```bash
59
+ bin token create ci --expires 90 # 発行(トークンは標準出力にだけ出る。--read で読み取り専用)
60
+ BIN_TOKEN=lbt_… bin list # bin login の代わりに使う
61
+ bin token list / bin token revoke <id>
62
+ ```
63
+
64
+ トークンで使えるのはLapBinの操作だけ(bin-serverが許可リストで制限し、持ち主として動く短命のJWTに差し替えて中継する)。発行・失効は bin login したセッションからのみ。Webの /settings/tokens でも管理できる。
65
+
66
+ ## 仕組み
67
+
68
+ - ログインはsca-cliと同じ2方式。`bin login`はローカルにランダムポートの一時HTTPサーバーを立て、`oauth-connect-token`(mint)で`http://127.0.0.1:<port>/callback`向けの使い捨てトークンを発行して`/oauth/v2/authorize?token=...`を開いてもらう。`--device`はdevice code方式(`oauth-device-code`関数)
69
+ - 通信はすべて`https://bin.lapius7.com/api/`(bin-server内のリバースプロキシ)経由。ANON_KEYはプロキシだけが付与するので、このCLIには一切含まれない
70
+ - Gistの読み書きは`bin`スキーマのDB関数(`get_gist`/`list_gists`/`save_gist`/`delete_gist`)を呼ぶだけ。権限チェックはDB側(RLS+SECURITY DEFINER関数)で行われる
71
+ - セッションは`~/.config/bin/session.json`(0600)。アクセストークン失効時は保存済みのrefresh_tokenで自動更新する
72
+
73
+ ## ビルド・配布
74
+
75
+ ```bash
76
+ ./build.sh # 全OS/CPU向けにクロスコンパイルし、web/bin.lapius7.com/server/cli-dist/ へinstall.shと一緒に配置
77
+ ```
78
+
79
+ バージョンは`日付-コミットの短縮ハッシュ`(未コミットの変更があれば`-dirty`付き)。同時に`VERSION`と`build.json`(バージョン・ビルド日時・コミット・各バイナリのSHA-256)も書き出し、https://bin.lapius7.com/cli の「配布中の最新版」はこれを読んで表示する。インストーラーは最後に入ったバイナリの`bin version`を実行して、配布中の版と一致するか照合する。
80
+
81
+ bin-serverがそのディレクトリを`/install.sh`・`/cli/*`として配信するので、再起動は不要。
82
+
83
+ npm版は`v*`タグをpushするとGitHub Actions(`.github/workflows/release.yml`)が`npm/build.mjs`でビルドしてnpmに公開し、GitHub Releaseにもバイナリを添付する(npmのTrusted Publisherで認証するのでトークンは不要)。手元での確認は`node npm/build.mjs 0.0.0-dev --pack`。
84
+ npm版は`-X main.channel=npm`付きでビルドされ、`bin version`の最新版確認と更新方法の案内がnpm向けになる。
85
+
86
+ ## 表示言語
87
+
88
+ 日本語・英語・韓国語に対応。`BIN_LANG`(ja / en / ko)、無ければ `LC_ALL`・`LC_MESSAGES`・`LANG` から判断する(未設定・C・POSIXは日本語、それ以外の未対応言語は英語)。インストーラーも同じ規則。
89
+
90
+ 文言は日本語の文字列をそのままキーにして `T("…")` で包み(gettext方式)、英語・韓国語は `cmd/bin/messages.go` に持つ。新しい文言を足したら対応表にも追加すること(無いとその言語でも日本語のまま表示される)。英語の単数形は `Tn()` と `messagesOne`。
91
+
92
+ 開発中のサーバーに向けたい場合は`BIN_SUPABASE_URL`/`BIN_ANON_KEY`/`BIN_SITE_URL`(環境変数または`~/.config/bin/config.env`)で上書きできる。
package/bin/bin ADDED
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env node
2
+ // OS/CPU 別パッケージのネイティブバイナリを起動するシム。
3
+ // Linux/macOS では初回の起動時にこのファイル自体をネイティブバイナリで置き換え、次回からは node を経由しない。
4
+ // (npm 11 はインストールスクリプトが既定で動かないため postinstall は使わない)
5
+ 'use strict';
6
+ const fs = require('fs');
7
+ const { spawnSync } = require('child_process');
8
+
9
+ const pkg = `@lapius/bin-cli-${process.platform}-${process.arch}`;
10
+ const exe = 'bin' + (process.platform === 'win32' ? '.exe' : '');
11
+ let bin;
12
+ try {
13
+ bin = require.resolve(`${pkg}/bin/${exe}`);
14
+ } catch {
15
+ console.error(`bin: ${pkg} が見つかりません(未対応の環境か、optionalDependencies が省略されました)`);
16
+ console.error(' npm i -g @lapius/bin-cli で入れ直してください');
17
+ process.exit(1);
18
+ }
19
+
20
+ // Windows は npm が node 経由の .cmd を作るので置き換えない
21
+ if (process.platform !== 'win32') {
22
+ try {
23
+ const self = fs.realpathSync(__filename);
24
+ const tmp = `${self}.${process.pid}.tmp`;
25
+ fs.copyFileSync(bin, tmp);
26
+ fs.chmodSync(tmp, 0o755);
27
+ fs.renameSync(tmp, self);
28
+ } catch {
29
+ // 書き込めなければシムのまま動く
30
+ }
31
+ }
32
+
33
+ const r = spawnSync(bin, process.argv.slice(2), { stdio: 'inherit' });
34
+ if (r.error) {
35
+ console.error(`bin: ${bin} を起動できません: ${r.error.message}`);
36
+ process.exit(1);
37
+ }
38
+ if (r.signal) process.kill(process.pid, r.signal);
39
+ process.exit(r.status ?? 1);
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@lapius/bin-cli",
3
+ "version": "0.1.0",
4
+ "description": "bin.lapius7.com(LapBin)の CLI クライアント",
5
+ "keywords": [
6
+ "cli",
7
+ "gist",
8
+ "pastebin",
9
+ "lapbin"
10
+ ],
11
+ "homepage": "https://github.com/Lapius7/bin-cli",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/Lapius7/bin-cli.git"
15
+ },
16
+ "license": "MIT",
17
+ "bin": {
18
+ "bin": "bin/bin"
19
+ },
20
+ "files": [
21
+ "bin/bin"
22
+ ],
23
+ "os": [
24
+ "linux",
25
+ "darwin",
26
+ "win32"
27
+ ],
28
+ "cpu": [
29
+ "x64",
30
+ "arm64"
31
+ ],
32
+ "optionalDependencies": {
33
+ "@lapius/bin-cli-linux-x64": "0.1.0",
34
+ "@lapius/bin-cli-linux-arm64": "0.1.0",
35
+ "@lapius/bin-cli-darwin-x64": "0.1.0",
36
+ "@lapius/bin-cli-darwin-arm64": "0.1.0",
37
+ "@lapius/bin-cli-win32-x64": "0.1.0"
38
+ }
39
+ }