@bash0816/opencode-termux 2.0.19 → 2.0.23
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 +120 -34
- package/bin/opencode-termux +28 -22
- package/config/opencode-candidate-version.json +5 -5
- package/config/opencode-verified-versions.json +6 -6
- package/lib/argv-route.js +13 -0
- package/lib/self-update.js +66 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,11 +7,24 @@ Termux 向け OpenCode CLI wrapper package です。
|
|
|
7
7
|
> **This project is not affiliated with, endorsed by, or sponsored by SST / the OpenCode project.**
|
|
8
8
|
> このプロジェクトは OpenCode プロジェクト(SST)と無関係です。公式から承認・提携・保証されたものではありません。
|
|
9
9
|
|
|
10
|
-
OpenCode is released under the [MIT License](https://github.com/anomalyco/opencode/blob/
|
|
11
|
-
This wrapper
|
|
12
|
-
|
|
13
|
-
OpenCode 本体は [MIT ライセンス](https://github.com/anomalyco/opencode/blob/
|
|
14
|
-
本ラッパーは公式 upstream バイナリをダウンロードし、Termux/Android
|
|
10
|
+
OpenCode is released under the [MIT License](https://github.com/anomalyco/opencode/blob/dev/LICENSE).
|
|
11
|
+
This wrapper downloads the official upstream binary and adjusts it to run on Termux/Android. It handles `update`, `upgrade`, and `uninstall` only when one of those is the first argument; all other argv, including flags before a management word, go unchanged to upstream.
|
|
12
|
+
|
|
13
|
+
OpenCode 本体は [MIT ライセンス](https://github.com/anomalyco/opencode/blob/dev/LICENSE) で公開されています。
|
|
14
|
+
本ラッパーは公式 upstream バイナリをダウンロードし、Termux/Android 上で動作するよう調整します。argv[0] が `update`・`upgrade`・`uninstall` の場合だけラッパーが処理します。flag が先頭にある場合を含むその他の argv は変更せず upstream に渡します。
|
|
15
|
+
|
|
16
|
+
> **Notice: updating from 2.0.18 / 2.0.19 / 更新に関するお知らせ**
|
|
17
|
+
> Versions 2.0.18 and 2.0.19 have a bug in OpenCode's built-in update command (`opencode update`). This is fixed in 2.0.22. If you are on 2.0.18 or 2.0.19, update with npm:
|
|
18
|
+
> `npm install -g @bash0816/opencode-termux@latest`
|
|
19
|
+
> If you installed with a custom prefix, add the same `--prefix <prefix>` you used at install time. If something goes wrong after updating, reinstall a specific version (this reinstalls the package; it is not a guaranteed fix for every problem):
|
|
20
|
+
> `npm install -g @bash0816/opencode-termux@2.0.22`
|
|
21
|
+
> (or `@2.0.19` to go back; note that 2.0.19 still has the update bug, so keep updating with npm there). From 2.0.22 on, `opencode update` works. Releases were slower than usual; thank you for your patience.
|
|
22
|
+
>
|
|
23
|
+
> 2.0.18 と 2.0.19 には、OpenCode 組み込みのアップデート機能(`opencode update`)に不具合があります。2.0.22 で修正されました。2.0.18 / 2.0.19 を使用中の場合は npm で更新してください:
|
|
24
|
+
> `npm install -g @bash0816/opencode-termux@latest`
|
|
25
|
+
> 独自の prefix にインストールしている場合は、インストール時と同じ `--prefix <prefix>` を付けてください。更新後に不具合が出た場合は、バージョンを指定して入れ直してください(パッケージの再インストールであり、あらゆる不具合の復旧を保証するものではありません):
|
|
26
|
+
> `npm install -g @bash0816/opencode-termux@2.0.22`
|
|
27
|
+
> (元に戻す場合は `@2.0.19`。2.0.19 では更新の不具合が残るため、更新は引き続き npm で行ってください)。2.0.22 以降は `opencode update` が使えます。リリースが通常より遅れ、ご迷惑をおかけしました。
|
|
15
28
|
|
|
16
29
|
## What this does / 仕組み
|
|
17
30
|
|
|
@@ -34,13 +47,32 @@ Termux/Android using a glibc runtime, instead of Android's default bionic libc.
|
|
|
34
47
|
- 書き換えの目的は Termux/Android 実行環境への互換性確保のみです。
|
|
35
48
|
認証・ライセンス・課金・アクセス制御・利用制限の回避を意図するものではありません。
|
|
36
49
|
|
|
50
|
+
## OpenCode 1.x and 2.x / OpenCode の 1系と2系
|
|
51
|
+
|
|
52
|
+
OpenCode has two separate npm distribution lines: 1.x (`opencode-ai`) and 2.x.
|
|
53
|
+
The official npm package for 2.x is [`@opencode/cli`](https://www.npmjs.com/package/@opencode/cli);
|
|
54
|
+
`@opencode/cli-linux-arm64` is its Linux ARM64 binary package. This package supports
|
|
55
|
+
only the 2.x line (`@opencode/cli-linux-arm64`), not the 1.x line (`opencode-ai`).
|
|
56
|
+
For the official documentation, see [OpenCode 1.x](https://opencode.ai/docs) and
|
|
57
|
+
[OpenCode 2.x](https://opencode.ai/v2/docs).
|
|
58
|
+
|
|
59
|
+
OpenCode には npm 上で別系統の配布ラインが 2 つあります。1系は `opencode-ai`、
|
|
60
|
+
2系の公式 npm パッケージは [`@opencode/cli`](https://www.npmjs.com/package/@opencode/cli) です。
|
|
61
|
+
`@opencode/cli-linux-arm64` はその Linux ARM64 用バイナリパッケージです。
|
|
62
|
+
本パッケージが対応するのは2系 (`@opencode/cli-linux-arm64`) のみで、1系
|
|
63
|
+
(`opencode-ai`) には対応していません。公式ドキュメントは[1系](https://opencode.ai/docs)、
|
|
64
|
+
[2系](https://opencode.ai/v2/docs)を参照してください。
|
|
65
|
+
|
|
37
66
|
## Prerequisites / 前提条件
|
|
38
67
|
|
|
39
68
|
```sh
|
|
40
69
|
pkg install glibc-repo && pkg install glibc
|
|
41
70
|
pkg install patchelf
|
|
71
|
+
pkg install llvm
|
|
42
72
|
```
|
|
43
73
|
|
|
74
|
+
readelf は llvm パッケージが提供します / readelf is provided by the llvm package
|
|
75
|
+
|
|
44
76
|
## Install / インストール
|
|
45
77
|
|
|
46
78
|
```sh
|
|
@@ -59,44 +91,97 @@ for this device. Subsequent runs reuse the cached, verified installation.
|
|
|
59
91
|
|
|
60
92
|
## Update / 更新
|
|
61
93
|
|
|
94
|
+
OpenCode 2.0.22 以降では `opencode update` と `opencode upgrade` がこの npm wrapper 自体を更新します。更新先は npm の `latest` です。明示した version への更新は `opencode update 2.0.22` のように指定できます。更新後の OpenCode バイナリは次回起動時に取得されます。wrapper の npm prefix を検出できない場合は更新を中止し、prefix を指定した npm コマンドを案内します。
|
|
95
|
+
|
|
96
|
+
TUI 内の `/update`(更新ダイアログの Update)は Termux では使えません。「Installation method not found」と表示され、更新は実行されません。シェルで `opencode update` を実行してください。
|
|
97
|
+
|
|
98
|
+
利用者が自動更新環境変数を設定していない場合、通常の起動時自動更新チェックを停止します。これは OpenCode のすべての更新経路を無効にする説明ではありません。
|
|
99
|
+
|
|
100
|
+
2.0.18 / 2.0.19 を使用中の場合、`opencode update` は利用できません。次のコマンドで wrapper を更新してください:
|
|
101
|
+
|
|
102
|
+
```sh
|
|
103
|
+
npm install -g @bash0816/opencode-termux@latest
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
npm 更新に成功した後、次回起動で setup に失敗した場合は、同じ prefix を指定して以前の wrapper version を再インストールしてください:
|
|
107
|
+
|
|
108
|
+
```sh
|
|
109
|
+
npm install -g --prefix <prefix> @bash0816/opencode-termux@<previous-version>
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
`package.json` の version は対応する upstream `@opencode/cli-linux-arm64` の version です。
|
|
113
|
+
|
|
114
|
+
OpenCode 2.0.22 and later route `opencode update` and `opencode upgrade` to update this npm wrapper to the registry's `latest` version. To request a specific version, use `opencode update 2.0.22`. The new OpenCode binary is fetched on the next launch. If the wrapper's npm prefix cannot be detected, the update stops and prints an npm command with an explicit prefix.
|
|
115
|
+
|
|
116
|
+
The TUI `/update` command (Update in the update dialog) is unavailable on Termux. It displays “Installation method not found” and does not perform an update. Run `opencode update` in the shell instead.
|
|
117
|
+
|
|
118
|
+
When the user has not set `OPENCODE_DISABLE_AUTOUPDATE`, the wrapper disables the normal startup update check. This does not describe every possible update path as disabled.
|
|
119
|
+
|
|
120
|
+
Users on 2.0.18 / 2.0.19 cannot use `opencode update`; update the wrapper directly:
|
|
121
|
+
|
|
122
|
+
```sh
|
|
123
|
+
npm install -g @bash0816/opencode-termux@latest
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
If setup fails on the next launch after npm successfully updates the wrapper, reinstall the previous wrapper version using the same prefix:
|
|
127
|
+
|
|
62
128
|
```sh
|
|
63
|
-
npm
|
|
129
|
+
npm install -g --prefix <prefix> @bash0816/opencode-termux@<previous-version>
|
|
64
130
|
```
|
|
65
131
|
|
|
66
|
-
|
|
67
|
-
|
|
132
|
+
実体配置は標準 npm 配置である必要があります。package または `lib/` の実体配置が標準配置と不整合な構成には対応していません。標準配置にある package への symlink は利用できます。
|
|
133
|
+
|
|
134
|
+
The package must resolve to the standard npm layout, and its `lib/` realpath must match that layout. Nonstandard real locations or inconsistent package and library realpaths are unsupported. A symlink to a package in the standard layout is supported.
|
|
135
|
+
|
|
136
|
+
The `package.json` version is the corresponding upstream `@opencode/cli-linux-arm64` version.
|
|
68
137
|
|
|
69
|
-
|
|
70
|
-
|
|
138
|
+
## Uninstall / アンインストール
|
|
139
|
+
|
|
140
|
+
`opencode uninstall` は OpenCode のデータ・設定・認証・セッション・cache・state を削除する可能性があるため実行せず、案内を表示して終了します。wrapper を削除するには次を実行し、キャッシュ `~/.opencode-termux` も削除してください。prefix を特定できない場合は、インストール時の prefix を `<prefix>` に指定してください。
|
|
141
|
+
|
|
142
|
+
```sh
|
|
143
|
+
npm uninstall -g --prefix <prefix> @bash0816/opencode-termux
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
OpenCode 自身の設定・認証・セッションデータはこの手順では削除されません。保存先は削除前に `opencode debug paths` で確認してください。
|
|
147
|
+
|
|
148
|
+
`opencode uninstall` is not run because it may delete OpenCode data, settings, authentication, sessions, cache, and state. The wrapper prints removal instructions and exits. Remove this wrapper and its cache with:
|
|
149
|
+
|
|
150
|
+
```sh
|
|
151
|
+
npm uninstall -g --prefix <prefix> @bash0816/opencode-termux
|
|
152
|
+
rm -rf ~/.opencode-termux
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Use the prefix from installation. Before removing the wrapper, check OpenCode data locations with `opencode debug paths`.
|
|
71
156
|
|
|
72
157
|
## Authentication / 認証
|
|
73
158
|
|
|
74
|
-
Before using OpenCode, log in to a provider
|
|
75
|
-
|
|
159
|
+
Before using OpenCode, log in to a provider. Requirements such as billing information,
|
|
160
|
+
credits, and API keys vary by provider; see the official
|
|
161
|
+
[Console instructions](https://opencode.ai/v2/docs/console/models/):
|
|
76
162
|
|
|
77
|
-
OpenCode
|
|
78
|
-
|
|
163
|
+
OpenCode を使う前に、プロバイダへログインしてください。請求情報・クレジット・APIキー等の
|
|
164
|
+
必要な手順はプロバイダごとに異なるため、公式の
|
|
165
|
+
[Console 手順](https://opencode.ai/v2/docs/console/models/)を参照してください:
|
|
79
166
|
|
|
80
167
|
```sh
|
|
81
168
|
opencode auth login opencode
|
|
82
169
|
```
|
|
83
170
|
|
|
84
|
-
This starts
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
Once connected, run `opencode auth list` to see saved credentials.
|
|
171
|
+
This starts the login process. Follow the on-screen instructions to complete it.
|
|
172
|
+
Run `opencode auth list` to check saved authentication. For details, see
|
|
173
|
+
`opencode auth login --help`.
|
|
88
174
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
完了してください。接続後は `opencode auth list` で保存済みの認証情報を確認できます。
|
|
175
|
+
`opencode auth login opencode` でログインを開始し、画面の案内に従って完了してください。
|
|
176
|
+
保存済み認証は `opencode auth list` で確認できます。詳細は
|
|
177
|
+
`opencode auth login --help` を参照してください。
|
|
93
178
|
|
|
94
179
|
To use a different provider (Anthropic, OpenAI, etc.), see
|
|
95
180
|
`opencode auth login --help` and the
|
|
96
|
-
[OpenCode provider documentation](https://opencode.ai/docs/providers
|
|
181
|
+
[OpenCode provider documentation](https://opencode.ai/v2/docs/providers).
|
|
97
182
|
|
|
98
183
|
他のプロバイダ(Anthropic・OpenAI 等)を使う場合は `opencode auth login --help` と
|
|
99
|
-
[OpenCode プロバイダ ドキュメント](https://opencode.ai/docs/providers
|
|
184
|
+
[OpenCode プロバイダ ドキュメント](https://opencode.ai/v2/docs/providers) を参照してください。
|
|
100
185
|
|
|
101
186
|
## Usage / 使い方
|
|
102
187
|
|
|
@@ -106,15 +191,15 @@ opencode run "your prompt here"
|
|
|
106
191
|
opencode run --model opencode/<model-id> "your prompt here"
|
|
107
192
|
```
|
|
108
193
|
|
|
109
|
-
Run `opencode models` to list available models
|
|
110
|
-
|
|
194
|
+
Run `opencode models` to list available models. Availability and requirements vary
|
|
195
|
+
by provider; see the official [Console instructions](https://opencode.ai/v2/docs/console/models/).
|
|
111
196
|
|
|
112
|
-
利用可能なモデル一覧は `opencode models`
|
|
113
|
-
|
|
197
|
+
利用可能なモデル一覧は `opencode models` で確認できます。提供状況や利用条件は
|
|
198
|
+
プロバイダごとに異なるため、公式の[Console 手順](https://opencode.ai/v2/docs/console/models/)を参照してください。
|
|
114
199
|
|
|
115
|
-
For available commands, see the [OpenCode documentation](https://opencode.ai/docs/).
|
|
200
|
+
For available commands, see the [OpenCode documentation](https://opencode.ai/v2/docs/cli/commands).
|
|
116
201
|
|
|
117
|
-
利用可能なコマンドは [OpenCode ドキュメント](https://opencode.ai/docs/) を参照してください。
|
|
202
|
+
利用可能なコマンドは [OpenCode ドキュメント](https://opencode.ai/v2/docs/cli/commands) を参照してください。
|
|
118
203
|
|
|
119
204
|
## License / ライセンス
|
|
120
205
|
|
|
@@ -169,6 +254,8 @@ functionality.
|
|
|
169
254
|
|
|
170
255
|
## Rollback / ロールバック手順
|
|
171
256
|
|
|
257
|
+
**(For package maintainers / パッケージ管理者向けの手順です)**
|
|
258
|
+
|
|
172
259
|
If a critical issue is discovered after promoting a new version to `latest`, you can
|
|
173
260
|
immediately roll back to the previous version using the following command:
|
|
174
261
|
|
|
@@ -179,8 +266,7 @@ immediately roll back to the previous version using the following command:
|
|
|
179
266
|
npm dist-tag add @bash0816/opencode-termux@<previous known-good version> latest
|
|
180
267
|
```
|
|
181
268
|
|
|
182
|
-
This
|
|
183
|
-
|
|
269
|
+
This moves the `latest` tag to a previous known-good version. The change applies to
|
|
270
|
+
subsequent new installations and updates.
|
|
184
271
|
|
|
185
|
-
これにより `latest`
|
|
186
|
-
ステーブル版を配布します。
|
|
272
|
+
これにより `latest` タグが指す版が変わり、以降の新規インストール・更新に反映されます。
|
package/bin/opencode-termux
CHANGED
|
@@ -4,30 +4,36 @@ const path = require('path');
|
|
|
4
4
|
const { execFileSync } = require('child_process');
|
|
5
5
|
const { setup } = require('../lib/setup');
|
|
6
6
|
const { GLIBC_LIB_DIR } = require('../lib/patcher');
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
const { route, withAutoUpdateEnv } = require('../lib/argv-route');
|
|
8
|
+
const { runUpdate, uninstallMessage, detectInstallPrefix } = require('../lib/self-update');
|
|
9
|
+
const packageRoot = path.resolve(__dirname, '..');
|
|
10
10
|
const pkg = require('../package.json');
|
|
11
11
|
const TARGET_VERSION = pkg.version;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
async function main(deps = {}) {
|
|
13
|
+
const args = deps.args || process.argv.slice(2), routed = route(args);
|
|
14
|
+
const setupFn = deps.setup || setup;
|
|
15
|
+
const execFn = deps.execFileSync || execFileSync;
|
|
16
|
+
const output = deps.write || (s => process.stderr.write(s));
|
|
17
|
+
const exit = deps.exit || (c => process.exit(c));
|
|
18
|
+
const fs = deps.fs || require('fs');
|
|
19
|
+
const child = deps.childProcess || require('child_process');
|
|
20
|
+
if (routed.kind === 'update') {
|
|
21
|
+
await (deps.runUpdate || runUpdate)(routed.rest, { fs, currentVersion: pkg.version,
|
|
22
|
+
spawnSync: deps.spawnSync || child.spawnSync, registryGet: deps.registryGet, packageRoot: deps.packageRoot || packageRoot, libPath: deps.libPath || path.resolve(__dirname, '..', 'lib'),
|
|
23
|
+
write: output, exit }); return;
|
|
21
24
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
execFileSync(binPath, args, { stdio: 'inherit', env });
|
|
28
|
-
} catch (e) {
|
|
29
|
-
process.exit(e.status || 1);
|
|
25
|
+
if (routed.kind === 'uninstall') {
|
|
26
|
+
let prefix = null;
|
|
27
|
+
try { prefix = detectInstallPrefix(fs, deps.packageRoot || packageRoot, deps.libPath || path.resolve(__dirname, '..', 'lib')); } catch (_) {}
|
|
28
|
+
output(uninstallMessage(prefix)); exit(1); return;
|
|
30
29
|
}
|
|
30
|
+
let target;
|
|
31
|
+
try { target = await setupFn(TARGET_VERSION); }
|
|
32
|
+
catch (e) { output(`opencode-termux: setup failed: ${e.message}\nTry running the command again, or check your network connection.\n`); exit(1); return; }
|
|
33
|
+
const binPath = path.join(target, 'bin', 'opencode');
|
|
34
|
+
const env = withAutoUpdateEnv({ ...(deps.env || process.env), LD_PRELOAD: '', LD_LIBRARY_PATH: deps.glibcLibDir || GLIBC_LIB_DIR });
|
|
35
|
+
try { execFn(binPath, args, { stdio: 'inherit', env }); }
|
|
36
|
+
catch (e) { exit(e.status || 1); }
|
|
31
37
|
}
|
|
32
|
-
|
|
33
|
-
main
|
|
38
|
+
if (require.main === module) main();
|
|
39
|
+
module.exports = { main };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.0.
|
|
3
|
-
"download_url": "https://registry.npmjs.org/@opencode/cli-linux-arm64/-/cli-linux-arm64-2.0.
|
|
4
|
-
"sha256_tar": "
|
|
5
|
-
"integrity": "sha512-
|
|
2
|
+
"version": "2.0.23",
|
|
3
|
+
"download_url": "https://registry.npmjs.org/@opencode/cli-linux-arm64/-/cli-linux-arm64-2.0.23.tgz",
|
|
4
|
+
"sha256_tar": "7978c15155c974173b95f842b544c8e2c2a344dd2da15cda51c117ac8c9d4e94",
|
|
5
|
+
"integrity": "sha512-kuLDSOpFFGCdCS/fdaHZ2yMqXsP4jwYfS0yV4ilYxaB7c0PJ84eY1b/bl2N9JXELXU13I2OFDI+NWzXhyXrxOQ==",
|
|
6
6
|
"patchelf_verified": true,
|
|
7
7
|
"source_repo": "anomalyco/opencode",
|
|
8
8
|
"upstream_package": "@opencode/cli-linux-arm64",
|
|
9
|
-
"detected_date": "2026-
|
|
9
|
+
"detected_date": "2026-10-06",
|
|
10
10
|
"status": "pending_device_verification"
|
|
11
11
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.0.
|
|
3
|
-
"download_url": "https://registry.npmjs.org/@opencode/cli-linux-arm64/-/cli-linux-arm64-2.0.
|
|
4
|
-
"sha256_tar": "
|
|
5
|
-
"integrity": "sha512-
|
|
2
|
+
"version": "2.0.23",
|
|
3
|
+
"download_url": "https://registry.npmjs.org/@opencode/cli-linux-arm64/-/cli-linux-arm64-2.0.23.tgz",
|
|
4
|
+
"sha256_tar": "7978c15155c974173b95f842b544c8e2c2a344dd2da15cda51c117ac8c9d4e94",
|
|
5
|
+
"integrity": "sha512-kuLDSOpFFGCdCS/fdaHZ2yMqXsP4jwYfS0yV4ilYxaB7c0PJ84eY1b/bl2N9JXELXU13I2OFDI+NWzXhyXrxOQ==",
|
|
6
6
|
"patchelf_verified": true,
|
|
7
7
|
"source_repo": "anomalyco/opencode",
|
|
8
8
|
"upstream_package": "@opencode/cli-linux-arm64",
|
|
9
|
-
"verified_date": "2026-
|
|
9
|
+
"verified_date": "2026-10-08",
|
|
10
10
|
"release_state": "stable",
|
|
11
|
-
"notes": "
|
|
11
|
+
"notes": "Updated to 2.0.23 on 2026-10-08."
|
|
12
12
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
function withAutoUpdateEnv(env) {
|
|
3
|
+
const result = { ...env };
|
|
4
|
+
if (result.OPENCODE_DISABLE_AUTOUPDATE === undefined) result.OPENCODE_DISABLE_AUTOUPDATE = '1';
|
|
5
|
+
return result;
|
|
6
|
+
}
|
|
7
|
+
function route(argv) {
|
|
8
|
+
const first = argv[0];
|
|
9
|
+
if (first === 'update' || first === 'upgrade') return { kind: 'update', rest: argv.slice(1) };
|
|
10
|
+
if (first === 'uninstall') return { kind: 'uninstall', rest: [] };
|
|
11
|
+
return { kind: 'passthrough', rest: [] };
|
|
12
|
+
}
|
|
13
|
+
module.exports = { route, withAutoUpdateEnv };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const PACKAGE = '@bash0816/opencode-termux';
|
|
3
|
+
const REGISTRY = 'https://registry.npmjs.org';
|
|
4
|
+
const path = require('path');
|
|
5
|
+
function parseArgs(args) {
|
|
6
|
+
if (args.length === 0) return { kind: 'latest' };
|
|
7
|
+
if (args.length === 1 && (args[0] === '--help' || args[0] === '-h')) return { kind: 'help' };
|
|
8
|
+
if (args.length !== 1) return { kind: 'error', message: '余分な引数があります / Unexpected argument.' };
|
|
9
|
+
const arg = args[0];
|
|
10
|
+
if (arg.startsWith('-')) return { kind: 'error', message: 'この方式には非対応です / This option is not supported.' };
|
|
11
|
+
const version = arg.replace(/^v/, '');
|
|
12
|
+
if (!validVersion(version)) return { kind: 'error', message: 'バージョン形式が不正です / Invalid version.' };
|
|
13
|
+
return { kind: 'version', version };
|
|
14
|
+
}
|
|
15
|
+
function compare(a, b) { const x=a.split('.').map(Number), y=b.split('.').map(Number); for(let i=0;i<3;i++) if(x[i]!==y[i]) return x[i]<y[i]?-1:1; return 0; }
|
|
16
|
+
function detectPrefix(realPath) {
|
|
17
|
+
const parts = realPath.split('/').filter(Boolean), suffix = ['lib','node_modules','@bash0816','opencode-termux','lib'];
|
|
18
|
+
if (parts.length <= suffix.length || !suffix.every((v,i)=>parts[parts.length-suffix.length+i]===v)) return null;
|
|
19
|
+
return '/' + parts.slice(0,-suffix.length).join('/');
|
|
20
|
+
}
|
|
21
|
+
function detectInstallPrefix(fs = require('fs'), packageRoot = path.resolve(__dirname, '..'), libPath = __dirname) {
|
|
22
|
+
const pkg = fs.realpathSync(packageRoot);
|
|
23
|
+
const lib = fs.realpathSync(libPath);
|
|
24
|
+
const ownPackage = fs.realpathSync(path.resolve(libPath, '..'));
|
|
25
|
+
const fromPackage = detectPrefix(path.join(pkg, 'lib'));
|
|
26
|
+
const fromOwnPackage = detectPrefix(path.join(ownPackage, 'lib'));
|
|
27
|
+
const fromLib = detectPrefix(lib);
|
|
28
|
+
return fromPackage && fromPackage === fromOwnPackage && fromOwnPackage === fromLib &&
|
|
29
|
+
pkg === ownPackage && lib === path.join(pkg, 'lib') ? fromPackage : null;
|
|
30
|
+
}
|
|
31
|
+
function validVersion(v) {
|
|
32
|
+
const m = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/.exec(v);
|
|
33
|
+
return !!m && m.slice(1).every(x => Number.isSafeInteger(Number(x)));
|
|
34
|
+
}
|
|
35
|
+
function registryGet(url, timeoutMs, https = require('https')) {
|
|
36
|
+
return new Promise((resolve,reject)=>{
|
|
37
|
+
let settled=false;
|
|
38
|
+
const timer=setTimeout(()=>req.destroy(new Error('request timeout')),timeoutMs);
|
|
39
|
+
const finish=(fn,value)=>{if(settled)return;settled=true;clearTimeout(timer);fn(value);};
|
|
40
|
+
const req=https.get(url,res=>{ const chunks=[]; res.on('data',c=>chunks.push(c)); res.on('error',e=>finish(reject,e)); res.on('aborted',()=>finish(reject,new Error('response aborted'))); res.on('end',()=>finish(resolve,{statusCode:res.statusCode,body:Buffer.concat(chunks).toString('utf8')})); });
|
|
41
|
+
req.on('error',e=>finish(reject,e));
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
async function runUpdate(args, deps) {
|
|
45
|
+
const {write=()=>{},exit=()=>{},fs,registryGet:get=registryGet,spawnSync,currentVersion}=deps;
|
|
46
|
+
const parsed=parseArgs(args);
|
|
47
|
+
if(parsed.kind==='help'){write('Usage: opencode update [version]\n');exit(0);return;}
|
|
48
|
+
if(parsed.kind==='error'){write(parsed.message+'\n');exit(2);return;}
|
|
49
|
+
let prefix=null; try{prefix=detectInstallPrefix(fs, deps.packageRoot || path.resolve(__dirname, '..'), deps.libPath || __dirname);}catch(_){}
|
|
50
|
+
if(!prefix){write('インストール先を特定できないため更新しません。`npm install -g --prefix <インストール時のprefix> @bash0816/opencode-termux@latest` を実行してください。\nCould not detect the installation prefix. Run `npm install -g --prefix <installation prefix> @bash0816/opencode-termux@latest`.\n');exit(1);return;}
|
|
51
|
+
const requested=parsed.kind==='version'?parsed.version:'latest'; let meta;
|
|
52
|
+
try{const res=await get(`${REGISTRY}/${PACKAGE.replace('/', '%2F')}/${requested}`,5000);if(res.statusCode!==200)throw Error('http');meta=JSON.parse(res.body);if(!meta||typeof meta.version!=='string'||!validVersion(meta.version))throw Error('version');if(parsed.kind==='version'&&meta.version!==parsed.version)throw Error('mismatch');}catch(_){write('npm registry から有効なバージョン情報を取得できませんでした。\nCould not retrieve valid version information from the npm registry.\n');exit(1);return;}
|
|
53
|
+
const cmp=compare(meta.version,currentVersion);
|
|
54
|
+
if(cmp===0){write(`Already on latest version: ${currentVersion}\n`);exit(0);return;}
|
|
55
|
+
if(cmp<0&&parsed.kind!=='version'){write(`現在のバージョン ${currentVersion} は ${meta.version} より新しいため、変更しません。\nCurrent version ${currentVersion} is newer than ${meta.version}; no change made.\n`);exit(0);return;}
|
|
56
|
+
const result=spawnSync('npm',['install','-g','--prefix',prefix,`${PACKAGE}@${meta.version}`],{stdio:'inherit'});
|
|
57
|
+
if(result.error||result.signal||result.status===null){write('npm install を実行できませんでした。\nCould not run npm install.\n');exit(1);return;}
|
|
58
|
+
if(result.status!==0){exit(result.status);return;}
|
|
59
|
+
write('次回起動時に新しい OpenCode を取得します。\nThe new OpenCode binary will be fetched on the next launch.\n');exit(0);
|
|
60
|
+
}
|
|
61
|
+
function uninstallMessage(prefix) {
|
|
62
|
+
const quote = value => "'" + String(value).replace(/'/g, "'\\''") + "'";
|
|
63
|
+
const install=prefix?`npm uninstall -g --prefix ${quote(prefix)} ${PACKAGE}`:`npm uninstall -g --prefix <インストール時のprefix> ${PACKAGE}`;
|
|
64
|
+
return 'このラッパー環境では opencode uninstall は対応していません。OpenCode のデータ・設定・認証・セッション・cache・state が削除される可能性があるため実行しません。\n削除するには `' + install + '` を実行し、キャッシュ `~/.opencode-termux` を削除してください。prefix を特定できない場合は <インストール時のprefix> を実際の prefix に置き換えてください。OpenCode 自身の設定・認証・セッションデータは削除されません。保存先は削除前に `opencode debug paths` で確認してください。\n\nThe wrapper does not support opencode uninstall and will not run it because it may delete OpenCode data, settings, authentication, sessions, cache, and state.\nTo remove this wrapper, run `' + install + '` and delete `~/.opencode-termux`. If the prefix is unknown, replace <インストール時のprefix> with the prefix used during installation. OpenCode settings, authentication, and session data are retained. Before removing the wrapper, check their locations with `opencode debug paths`.\n';
|
|
65
|
+
}
|
|
66
|
+
module.exports={runUpdate,parseArgs,compare,detectPrefix,detectInstallPrefix,uninstallMessage,validVersion,registryGet,PACKAGE};
|