@online-tools/agent-runner 0.0.0-stage → 0.0.1-alpha-2

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 tangpingchuan
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 CHANGED
@@ -1,3 +1,105 @@
1
- # Temporary Holding Version
1
+ # @online-tools/agent-runner
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ GitCode 在线工具的 Agent 执行机器:把「在线 Agent」里的 **PR 描述 / Issue**、**代码检视(全量 / 快速)** 放到你自己的机器上运行,不占网站服务器的资源。
4
+
5
+ 程序只**主动连出**到网站(HTTPS),适用于没有公网 IP、在 NAT 或公司代理后面的机器;网站从不主动连接你的机器。
6
+
7
+ ## 安装与首次运行
8
+
9
+ 需要 Linux 或 macOS 和 Node.js(npm)。程序本身要在 Node 22.21+(或 24.5+、25+)上运行;系统自带的 Node 更旧时(例如 Ubuntu 24.04 的 18、22.04 的 12、20.04 的 10),首次运行会提示下载 Node.js 官方的最新 LTS 版本(约 60 MB,nodejs.org,访问不了时用 npmmirror.com,均按 `SHASUMS256.txt` 校验 SHA-256),回车确认即可。下载的 Node 只给本程序用,不改动系统的 Node 和 PATH;以后运行(包括后台服务)自动使用它。不在终端里运行时(脚本、CI)不会自动下载,可以加 `--yes`。
10
+
11
+ ```bash
12
+ npm i -g @online-tools/agent-runner
13
+ gitcode-agent-runner # 首次运行:粘贴接入令牌 → 连接 → 检查并安装依赖 → 保持在线
14
+ gitcode-agent-runner service install # 可选:注册为后台服务,开机自启
15
+ ```
16
+
17
+ 接入令牌在网页「在线 Agent → 模型配置 → 接入令牌」里新建。粘贴后先向网站校验,通过才保存;以后启动直接连接。
18
+
19
+ 首次运行会检查依赖并列出要执行的安装命令,确认后才执行:
20
+
21
+ - `git`、`curl`、`python3`、`jq`、`sed`、`base64`:Skill 需要(各功能需要的不完全一样)
22
+ - `bubblewrap`、`socat`:Linux 上 Claude Code 沙箱需要(macOS 用系统自带的 Seatbelt)
23
+ - `claude`(`npm install -g @anthropic-ai/claude-code@latest`)
24
+
25
+ 拒绝安装或安装失败时程序照样接入,缺少的依赖只让用到它的功能不可用,网页上会显示原因。之后可以随时运行 `gitcode-agent-runner setup`。
26
+
27
+ 在网页「PR 描述 / Issue」「代码检视」页的「执行位置」里选择这台机器(或在「模型配置」里设为默认),任务就会在这里运行。
28
+
29
+ ## 命令
30
+
31
+ | 命令 | 作用 |
32
+ |---|---|
33
+ | `gitcode-agent-runner [start]` | 连接网站并等待任务 |
34
+ | `login [--new-id] [--token-stdin]` | 输入(更换)接入令牌,校验通过才保存。`--new-id` 重新生成机器标识;`--token-stdin` 从标准输入读令牌 |
35
+ | `logout` | 清除本机保存的令牌(机器标识保留) |
36
+ | `setup [--yes]` | 检查并安装缺少或版本过低的依赖(只在终端里运行;`--yes` 跳过确认) |
37
+ | `doctor [--json]` | 检查依赖、沙箱和各功能是否可用 |
38
+ | `status` | 网站地址、令牌前 12 位、机器标识、工作目录、服务状态和连接测试 |
39
+ | `service install \| uninstall \| status` | 后台服务:Linux 为 systemd 用户服务,macOS 为 launchd |
40
+ | `version` / `help` | — |
41
+
42
+ 全局选项:`--server <url>`(默认 `https://online-tools.closerouter.site`,会保存)、`--work-dir <dir>`(会保存)、`--allow-root`。
43
+
44
+ 文件位置:
45
+
46
+ - 配置:`${XDG_CONFIG_HOME:-~/.config}/gitcode-agent-runner/config.json`(0600)
47
+ - Skill 缓存:`${XDG_CACHE_HOME:-~/.cache}/gitcode-agent-runner/skills/`
48
+ - 自动下载的 Node(只有系统 Node 过旧时才有):`${XDG_DATA_HOME:-~/.local/share}/gitcode-agent-runner/node/`
49
+ - 工作目录:Linux `/var/tmp/gitcode-agent-runner-<uid>/`,macOS `$TMPDIR/gitcode-agent-runner/`。**不能在主目录之内**(沙箱不允许读取主目录)
50
+
51
+ ## 任务怎么运行
52
+
53
+ 网站只下发任务数据:任务文本、模型、你的模型 API Key、GitCode 授权、超时和 Skill 版本。claude 的命令行、环境变量、工具白名单和沙箱设置都由本程序生成,网站改不了。
54
+
55
+ 每个任务:
56
+
57
+ 1. 从网站下载这个版本的 Skill(逐个校验 sha256,缓存最近 3 个版本)
58
+ 2. 在工作目录下建立独立的运行目录
59
+ 3. 以独立进程组启动 `claude -p`,带上沙箱设置(`--settings`),超时由本程序执行
60
+ 4. 把 claude 的输出按顺序回传网站,结束后删除运行目录
61
+
62
+ 沙箱设置:
63
+
64
+ - 沙箱必须可用(`failIfUnavailable`),起不来时任务失败,**不会退化为不进沙箱运行**;模型要求「不进沙箱运行命令」一律被忽略
65
+ - 网络只允许 `gitcode.com`、`*.gitcode.com`(claude 自己访问模型 API 不受影响)
66
+ - 不能读写你的主目录(PATH 里位于主目录的目录除外,只读),不能改写 Skill 副本和设置;只能写本次任务的工作目录
67
+ - 沙箱里的命令看不到模型 API Key;hooks 一律关闭
68
+
69
+ ## 安全须知
70
+
71
+ - 选择执行机器运行任务时,你的**模型 API Key 和 GitCode 授权会发送到这台机器**,只注入本次任务的 claude 进程,不写入文件或日志。
72
+ - **建议用一个专用的低权限账号运行本程序**。沙箱之外、主目录之外的可读文件仍然可能被读到;GitCode 本身在网络白名单里。
73
+ - 程序拒绝以 root 运行(容器里确有需要时加 `--allow-root`)。
74
+ - 接入令牌只能用来接入机器,不能登录网页。**令牌泄露时在网页上删除它**,用它接入的机器会立即断开;之后新建令牌,在需要的机器上运行 `gitcode-agent-runner login`。网页上的「封禁」只针对单台机器,拿到令牌的人可以换个标识重新接入,所以防泄露要靠删除令牌。
75
+ - 有新机器接入时网页会提示;不是你的机器请封禁或删除令牌。
76
+ - 本程序没有任何依赖和安装脚本。
77
+
78
+ ## 日常维护
79
+
80
+ | 场景 | 操作 |
81
+ |---|---|
82
+ | 更新程序 | `npm i -g @online-tools/agent-runner@latest`,然后重启程序或服务(`systemctl --user restart gitcode-agent-runner`)。网页上会提示「有新版本」或「版本过低」 |
83
+ | 令牌泄露 | 在网页上删除该令牌,新建令牌后运行 `gitcode-agent-runner login` |
84
+ | 复制了配置 / 克隆了虚拟机 | 在复制出来的那台上运行 `gitcode-agent-runner login --new-id` |
85
+ | 退出登录后服务停止(Linux) | 让管理员执行一次 `loginctl enable-linger <用户名>` |
86
+ | 查看日志 | `journalctl --user -u gitcode-agent-runner -f`,或 macOS 的 `~/Library/Logs/gitcode-agent-runner.log` |
87
+
88
+ 退出码:0 正常退出;1 出错;78 需要人处理(没有令牌、令牌已删除、机器已封禁、同一配置在两台机器上运行、系统或 Node 不支持、以 root 运行、已有实例在运行),后台服务遇到 78 不会自动重启。
89
+
90
+ 沙箱不可用时请先运行 `gitcode-agent-runner setup`;在非特权容器或禁用了非特权 user namespace 的系统(例如开启了 AppArmor 限制的 Ubuntu 24.04+)上沙箱可能无法启动,详见 https://code.claude.com/docs/en/sandboxing 。
91
+
92
+ ## 卸载
93
+
94
+ ```bash
95
+ gitcode-agent-runner service uninstall
96
+ gitcode-agent-runner logout
97
+ npm rm -g @online-tools/agent-runner
98
+ rm -rf ~/.local/share/gitcode-agent-runner # 自动下载的 Node(如果有)
99
+ ```
100
+
101
+ 最后在网页「在线 Agent → 模型配置 → 执行机器」里移除这台机器。
102
+
103
+ ## 许可证
104
+
105
+ MIT
@@ -0,0 +1,139 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ // gitcode-agent-runner entry point. It makes sure the program (main.mjs) runs
4
+ // on a supported Node (22.21+ / 24.5+ / 25+). On an older one it uses the
5
+ // Node this program installed before, or — after asking — downloads the
6
+ // official LTS build (lib/node-runtime.cjs), then runs the same command again
7
+ // with it.
8
+ //
9
+ // Linux distributions ship old Node versions (Ubuntu 20.04: 10, 22.04: 12,
10
+ // 24.04: 18), and an ES module, `?.` or a `node:` name would fail there
11
+ // before any message could be shown. So this file and node-runtime.cjs are
12
+ // CommonJS that runs on Node 10 (tests/agent-runner-node.test.js checks the
13
+ // syntax).
14
+
15
+ const childProcess = require('child_process');
16
+ const os = require('os');
17
+ const readline = require('readline');
18
+
19
+ const runtime = require('../lib/node-runtime.cjs');
20
+
21
+ const ARGS = process.argv.slice(2);
22
+ // Tests stand in for an old Node with GC_RUNNER_TEST_NODE_VERSION (never passed on).
23
+ const CURRENT = process.env.GC_RUNNER_TEST_NODE_VERSION || process.versions.node;
24
+ const ATTENTION = 78; // EXIT_NEEDS_ATTENTION (lib/service.mjs): services do not restart on it
25
+ const VERSION_ARGS = ['version', '--version', '-v'];
26
+
27
+ function say(text) {
28
+ process.stdout.write(text + '\n');
29
+ }
30
+
31
+ // serviceExitCode() in lib/service.mjs (which old Node cannot load): launchd
32
+ // cannot exempt one exit code from KeepAlive, so 78 becomes 0 there.
33
+ function finish(code) {
34
+ const exitCode = code === ATTENTION && process.env.GC_RUNNER_SERVICE === 'launchd' ? 0 : code;
35
+ process.stdout.write('', () => process.exit(exitCode));
36
+ }
37
+
38
+ /** [Y/n]; an empty answer is yes, Ctrl+C / Ctrl+D no. */
39
+ function askYesNo(question) {
40
+ return new Promise((resolve) => {
41
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
42
+ let answered = false;
43
+ rl.on('close', () => {
44
+ if (answered) return;
45
+ process.stdout.write('\n');
46
+ resolve(false);
47
+ });
48
+ rl.question(question + ' [Y/n] ', (answer) => {
49
+ answered = true;
50
+ rl.close();
51
+ const value = String(answer || '').trim().toLowerCase();
52
+ resolve(!value || ['y', 'yes', '是', '好'].indexOf(value) !== -1);
53
+ });
54
+ });
55
+ }
56
+
57
+ function progressPrinter() {
58
+ if (!process.stdout.isTTY) return undefined;
59
+ let last = 0;
60
+ const mb = (bytes) => (bytes / 1048576).toFixed(1);
61
+ return (received, total) => {
62
+ const now = Date.now();
63
+ const done = total > 0 && received >= total;
64
+ if (now - last < 300 && !done) return;
65
+ last = now;
66
+ process.stdout.write('\r 已下载 ' + mb(received) + (total ? ' / ' + mb(total) : '') + ' MB');
67
+ if (done) process.stdout.write('\n');
68
+ };
69
+ }
70
+
71
+ /** A supported Node to run with: installed before, or downloaded now. Resolves { node } or { code }. */
72
+ async function supportedNode() {
73
+ const dataDir = runtime.nodeDataDir();
74
+ const installed = runtime.findManagedNode(dataDir);
75
+ if (installed) return { node: installed };
76
+ const yes = ARGS.indexOf('--yes') !== -1 || ARGS.indexOf('-y') !== -1;
77
+ const interactive = Boolean(process.stdin.isTTY && process.stdout.isTTY) && !process.env.GC_RUNNER_SERVICE;
78
+ say('当前 Node ' + CURRENT + ' 版本过低,本程序需要 Node ' + runtime.NODE_REQUIREMENT + '。');
79
+ if (!yes && !interactive) {
80
+ say('在终端里运行 gitcode-agent-runner 可以自动下载合适的 Node(脚本里可加 --yes),也可以自行升级 Node 后重试。');
81
+ return { code: ATTENTION };
82
+ }
83
+ say('可以下载 Node.js 官方的最新 LTS 版本(约 60 MB)到 ' + dataDir);
84
+ say('只供本程序使用,不改动系统里的 Node 和 PATH。');
85
+ if (!yes && !(await askYesNo('是否下载?'))) {
86
+ say('已取消。请自行安装 Node 22.21 以上版本(https://nodejs.org 或 nvm),然后重新运行。');
87
+ return { code: ATTENTION };
88
+ }
89
+ try {
90
+ const node = await runtime.installManagedNode({ dataDir, say: (text) => say(' ' + text), onProgress: progressPrinter() });
91
+ say('✓ 已安装 Node ' + node.version + '(' + node.nodePath + '),以后运行本程序会自动使用它');
92
+ return { node };
93
+ } catch (error) {
94
+ process.stderr.write(
95
+ '下载 Node 失败:' + error.message + '\n' +
96
+ '请检查网络(需要能访问 nodejs.org 或 npmmirror.com;公司代理请设置 HTTPS_PROXY),或自行安装 Node 22.21 以上版本。\n',
97
+ );
98
+ return { code: 1 };
99
+ }
100
+ }
101
+
102
+ /** Runs the same command with `node`; resolves with its exit code. */
103
+ function runWith(node) {
104
+ return new Promise((resolve) => {
105
+ const env = Object.assign({}, process.env, { GC_RUNNER_NODE_SWITCHED: node.nodePath });
106
+ delete env.GC_RUNNER_TEST_NODE_VERSION;
107
+ const child = childProcess.spawn(node.nodePath, [__filename].concat(ARGS), { stdio: 'inherit', env });
108
+ // The terminal signals both processes; the program stops its jobs itself.
109
+ for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) process.on(signal, () => child.kill(signal));
110
+ child.on('error', (error) => {
111
+ process.stderr.write('无法启动 ' + node.nodePath + ':' + error.message + '\n');
112
+ resolve(1);
113
+ });
114
+ child.on('exit', (code, signal) => resolve(code === null ? 128 + (os.constants.signals[signal] || 0) : code));
115
+ });
116
+ }
117
+
118
+ async function switchNode() {
119
+ if (process.env.GC_RUNNER_NODE_SWITCHED) {
120
+ process.stderr.write('已改用 ' + process.env.GC_RUNNER_NODE_SWITCHED + ',但它的版本 ' + CURRENT + ' 仍然不满足要求(需要 ' + runtime.NODE_REQUIREMENT + ')\n');
121
+ return ATTENTION;
122
+ }
123
+ const result = await supportedNode();
124
+ return result.node ? runWith(result.node) : result.code;
125
+ }
126
+
127
+ if (runtime.nodeSupported(CURRENT)) {
128
+ // require() of an ES module: every supported Node has it (main.mjs and its
129
+ // imports must not use top-level await).
130
+ require('./main.mjs');
131
+ } else if (ARGS.some((arg) => VERSION_ARGS.indexOf(arg) !== -1)) {
132
+ // The version needs no newer Node.
133
+ say(require('../package.json').version);
134
+ } else {
135
+ switchNode().then(finish, (error) => {
136
+ process.stderr.write('出错:' + (error && error.message ? error.message : error) + '\n');
137
+ finish(1);
138
+ });
139
+ }