@h-ai/runner 0.0.0-stage → 1.0.0-beta.24

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,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [2026] [idealworld.group]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.en.md ADDED
@@ -0,0 +1,79 @@
1
+ # @h-ai/runner
2
+
3
+ Runner hosts managed agent and tool containers. API nodes submit work and read status. Executor nodes claim work and own the containers and connections. A shared database holds tasks, ownership, cancellation requests, and events. The application authenticates users and applies business authorization.
4
+
5
+ ## Start and submit
6
+
7
+ Initialize `@h-ai/reldb` before Runner. A single node can use SQLite. Multiple instances use shared PostgreSQL or MySQL with a stable nodeId per executor. API nodes can set `executor: false`. This example assumes the database is ready and uses a trusted server-side handler.
8
+
9
+ ```ts
10
+ import { core } from '@h-ai/core'
11
+ import { runner } from '@h-ai/runner'
12
+
13
+ const scope = { tenantId: 'studio', userId: 'alice' }
14
+ const started = await runner.init({ nodeId: 'worker-east' })
15
+ if (!started.success)
16
+ throw new Error(started.error.message)
17
+
18
+ try {
19
+ const registration = runner.register('report.v1', async (input, context) => {
20
+ const published = await context.emit({ phase: 'ready' })
21
+ if (!published.success)
22
+ throw new Error(published.error.message)
23
+ return { summary: input }
24
+ })
25
+ if (!registration.success)
26
+ throw new Error(registration.error.message)
27
+ const accepted = await runner.submit({
28
+ scope,
29
+ kind: 'report.v1',
30
+ idempotencyKey: 'report-2026-11',
31
+ input: 'Monthly report',
32
+ })
33
+ if (!accepted.success)
34
+ throw new Error(accepted.error.message)
35
+
36
+ const task = await runner.get(scope, accepted.data.id)
37
+ if (!task.success)
38
+ throw new Error(task.error.message)
39
+ void task.data.status
40
+ }
41
+ finally {
42
+ const closed = await runner.close()
43
+ if (!closed.success)
44
+ core.logger.error('Runner shutdown failed', { code: closed.error.code })
45
+ }
46
+ ```
47
+
48
+ Use `get` for status, `find` to recover a receipt by scope and idempotency key, `events` for paged sequence cursors, and `cancel` to request cancellation. The cancelled state is published after the container is stopped and cleanup is verified. A child task's `parentId` routes it to the node holding the connection. Child tasks have a separate control concurrency limit.
49
+
50
+ ## Container environments and resources
51
+
52
+ Each `environments` entry supplies an ID, a locally available image digest, CPU cores, memory MiB, PID count, and scratch MiB. Callers select the environment by `environmentId` and can request lower limits. Executors claim work and reserve resources in the same database transaction. Queue and concurrency limits apply by scope and node.
53
+
54
+ Reserve separate tool capacity with `toolCapacity` so tools can run while agent workers hold their slots. The default tool budget is 1 CPU core, 1024 MiB of memory, 128 PIDs and 512 MiB of scratch. `toolMaxRunning` defaults to 4. The host must support both partitions. Trusted callers select `capacityClass: "tool"` and can set a cross-node service cap with `concurrency: { key, limit }`.
55
+
56
+ Handlers use `context.start` to obtain process streams and exit information. Images require Linux cgroup v2 support, `/bin/sh`, and support for UID/GID 1000. The root filesystem is read-only. Runner assigns bounded tmpfs mounts at `/state`, `/workspace`, and `/tmp`, and copies launch files into `/state`. Networking is disabled by default. A registered internal network must pass the engine's internal-network check. Networked tasks should use a gateway configured for their trust boundary.
57
+
58
+ The executor holds credentials and native connections in memory. Inputs, events, and outputs accept bounded JSON. Pass business identifiers and object references in execution records. When an owner disappears or cleanup cannot be verified, Runner preserves the `unknown` state and resource reservation pending operator reconciliation.
59
+
60
+ Tool handlers can stage canonical Base64 files by basename in read-only `/input` using `inputs`. While the container is running, `artifact(name, maxBytes)` reads a regular file from `/output`. Total inputs and a single output are each limited to 50 MiB and remain subject to the scratch limit. Images that export artifacts provide `/usr/bin/python3`.
61
+
62
+ A trusted operator endpoint on the original execution node can call `runner.reconcileUnknown(scope, id, { operatorId, reason })`. Runner verifies the recorded engine and container, checks that the container is gone, and cleans up the recorded staging directory before releasing the reservation and reuse key. It records the operator decision and adds `reconciledAt` to the original `unknown` receipt. Executions without a reliable container receipt retain their reservations.
63
+
64
+ For a fixed offline tool, register the same `registerWarmPool({ key, kind, environmentId, minReady, maxRunning, maxTotal })` on API and executor nodes. `minReady` targets empty containers across the cluster. `maxTotal` counts starting, ready, running, cleaning and unreconciled instances. Trusted tool requests select `warmPool: true` with the matching service concurrency key. Runner stages authorized input only after claiming a clean instance. Each instance runs one job and is destroyed. The image provides `/usr/bin/python3`, and standby containers consume reserved tool resources.
65
+
66
+ ## Development
67
+
68
+ ```bash
69
+ pnpm --filter @h-ai/runner typecheck
70
+ pnpm --filter @h-ai/runner lint
71
+ pnpm --filter @h-ai/runner build
72
+ pnpm --filter @h-ai/runner test
73
+ ```
74
+
75
+ Tests use real SQLite, PostgreSQL, MySQL, and Docker/Podman containers. Set `HAI_TEST_CONTAINER_ENGINE` to select an engine. The PostgreSQL and MySQL tests use Testcontainers with that engine's Docker-compatible API.
76
+
77
+ ## License
78
+
79
+ Apache-2.0
package/README.ja.md ADDED
@@ -0,0 +1,79 @@
1
+ # @h-ai/runner
2
+
3
+ Runner はエージェントとツールのコンテナを管理します。API ノードはタスクを登録して状態を取得し、実行ノードはタスクを取得してコンテナと接続を管理します。タスク、所有権、キャンセル要求、イベントは共有データベースに保存します。認証と業務上の認可はアプリケーションが行います。
4
+
5
+ ## 起動とタスクの登録
6
+
7
+ Runner より先に `@h-ai/reldb` を初期化します。単一ノードでは SQLite を使用できます。複数ノードは共有 PostgreSQL または MySQL を使用し、実行ノードごとに固定の nodeId を設定します。API ノードは `executor: false` を指定できます。以下では、データベースが起動済みで、信頼できるサーバー側ハンドラーを使用します。
8
+
9
+ ```ts
10
+ import { core } from '@h-ai/core'
11
+ import { runner } from '@h-ai/runner'
12
+
13
+ const scope = { tenantId: 'studio', userId: 'alice' }
14
+ const started = await runner.init({ nodeId: 'worker-east' })
15
+ if (!started.success)
16
+ throw new Error(started.error.message)
17
+
18
+ try {
19
+ const registration = runner.register('report.v1', async (input, context) => {
20
+ const published = await context.emit({ phase: 'ready' })
21
+ if (!published.success)
22
+ throw new Error(published.error.message)
23
+ return { summary: input }
24
+ })
25
+ if (!registration.success)
26
+ throw new Error(registration.error.message)
27
+ const accepted = await runner.submit({
28
+ scope,
29
+ kind: 'report.v1',
30
+ idempotencyKey: 'report-2026-11',
31
+ input: 'Monthly report',
32
+ })
33
+ if (!accepted.success)
34
+ throw new Error(accepted.error.message)
35
+
36
+ const task = await runner.get(scope, accepted.data.id)
37
+ if (!task.success)
38
+ throw new Error(task.error.message)
39
+ void task.data.status
40
+ }
41
+ finally {
42
+ const closed = await runner.close()
43
+ if (!closed.success)
44
+ core.logger.error('Runner shutdown failed', { code: closed.error.code })
45
+ }
46
+ ```
47
+
48
+ `get` は状態を取得し、`find` は主体と冪等キーから受付済みタスクを検索します。`events` はカーソルでページングし、`cancel` はキャンセル要求を登録します。コンテナの停止と後処理を確認してからキャンセル済み状態を保存します。`parentId` を指定した子タスクは接続を持つノードで実行され、専用の同時実行枠を使用します。
49
+
50
+ ## コンテナ環境とリソース
51
+
52
+ `environments` には ID、取得済みのイメージダイジェスト、CPU コア数、メモリ MiB、PID 数、作業領域 MiB を指定します。`environmentId` で環境を選び、必要に応じてリソース上限を下げられます。実行ノードは、同じデータベーストランザクションでタスクを取得してリソースを確保します。
53
+
54
+ エージェントが実行枠を使用している間もツールを起動できるように、`toolCapacity` でツール専用の枠を確保します。既定値は CPU 1 コア、メモリ 1024 MiB、PID 128 個、作業領域 512 MiB です。`toolMaxRunning` の既定値は 4 です。ホストは両方の枠に対応する必要があります。信頼できる呼び出し元は `capacityClass: "tool"` を指定し、`concurrency: { key, limit }` でサービスのノード横断上限を設定できます。
55
+
56
+ ハンドラーは `context.start` でコンテナを起動し、標準ストリームと終了結果を取得します。Linux cgroup v2、`/bin/sh`、UID/GID 1000 での実行が必要です。ルートファイルシステムは読み取り専用で、`/state`、`/workspace`、`/tmp` は容量を制限した tmpfs です。起動ファイルは `/state` にコピーします。ネットワークは既定で無効です。使用する内部ネットワークは、実行エンジンで internal として設定し、信頼境界に応じたゲートウェイを用意します。
57
+
58
+ 資格情報と接続は実行ノードで管理します。入力、イベント、出力はサイズ制限付き JSON とし、実行記録には業務 ID とオブジェクト参照を渡します。所有者に接続できない場合や後処理を確認できない場合は `unknown` とし、運用者が確認するまでリソースを保持します。
59
+
60
+ ツールハンドラーは `inputs` に Base64 ファイルと単純なファイル名を指定し、読み取り専用の `/input` に配置できます。コンテナの実行中に `artifact(name, maxBytes)` で `/output` の通常ファイルを取得できます。入力の合計と単一の出力はそれぞれ 50 MiB 以内で、作業領域の上限も適用されます。成果物の取得にはイメージに `/usr/bin/python3` が必要です。
61
+
62
+ 元の実行ノード上の信頼できる管理エンドポイントは `runner.reconcileUnknown(scope, id, { operatorId, reason })` を呼び出せます。Runner は記録済みのエンジンとコンテナを確認し、コンテナが削除され、作業ディレクトリを後処理できた場合に実行枠と再利用キーを解放します。担当者の判断を記録し、元の `unknown` に `reconciledAt` を追加します。信頼できるコンテナの受付情報がなければ実行枠を保持します。
63
+
64
+ 固定のオフラインツールでは、API ノードと実行ノードに同じ `registerWarmPool({ key, kind, environmentId, minReady, maxRunning, maxTotal })` を登録します。`minReady` はクラスター全体の空コンテナの目標数です。`maxTotal` には起動、待機、実行、後処理、未確認のインスタンスが含まれます。信頼できるリクエストは、サービスの同時実行キーと `warmPool: true` を指定します。空のインスタンスを取得してから認可済み入力を配置し、1 回の実行後に破棄します。イメージには `/usr/bin/python3` が必要で、待機中もツール専用枠を使用します。
65
+
66
+ ## 開発とテスト
67
+
68
+ ```bash
69
+ pnpm --filter @h-ai/runner typecheck
70
+ pnpm --filter @h-ai/runner lint
71
+ pnpm --filter @h-ai/runner build
72
+ pnpm --filter @h-ai/runner test
73
+ ```
74
+
75
+ テストは実際の SQLite、PostgreSQL、MySQL と Docker/Podman コンテナを使用します。`HAI_TEST_CONTAINER_ENGINE` でエンジンを選びます。PostgreSQL と MySQL のテストは、エンジンの Docker 互換 API に Testcontainers で接続します。
76
+
77
+ ## ライセンス
78
+
79
+ Apache-2.0
package/README.md CHANGED
@@ -1,3 +1,79 @@
1
- # Temporary Holding Version
1
+ # @h-ai/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
+ Runner 用于运行受管的 Agent 和工具容器。API 节点提交任务和读取状态,执行节点领取任务,持有实际容器和连接。任务、归属、取消请求和事件保存在共享数据库中。应用负责身份验证和业务授权。
4
+
5
+ ## 启动和提交
6
+
7
+ 先初始化 `@h-ai/reldb`,再启动 runner。单机可以使用 SQLite。多实例使用共享 PostgreSQL 或 MySQL,并为每台执行节点分配稳定的 nodeId。API 节点可以设置 `executor: false`。以下示例使用已启动的数据库,仅运行可信服务器处理器。
8
+
9
+ ```ts
10
+ import { core } from '@h-ai/core'
11
+ import { runner } from '@h-ai/runner'
12
+
13
+ const scope = { tenantId: 'studio', userId: 'alice' }
14
+ const started = await runner.init({ nodeId: 'worker-east' })
15
+ if (!started.success)
16
+ throw new Error(started.error.message)
17
+
18
+ try {
19
+ const registration = runner.register('report.v1', async (input, context) => {
20
+ const published = await context.emit({ phase: 'ready' })
21
+ if (!published.success)
22
+ throw new Error(published.error.message)
23
+ return { summary: input }
24
+ })
25
+ if (!registration.success)
26
+ throw new Error(registration.error.message)
27
+ const accepted = await runner.submit({
28
+ scope,
29
+ kind: 'report.v1',
30
+ idempotencyKey: 'report-2026-11',
31
+ input: 'Monthly report',
32
+ })
33
+ if (!accepted.success)
34
+ throw new Error(accepted.error.message)
35
+
36
+ const task = await runner.get(scope, accepted.data.id)
37
+ if (!task.success)
38
+ throw new Error(task.error.message)
39
+ void task.data.status
40
+ }
41
+ finally {
42
+ const closed = await runner.close()
43
+ if (!closed.success)
44
+ core.logger.error('Runner shutdown failed', { code: closed.error.code })
45
+ }
46
+ ```
47
+
48
+ `get` 读取当前状态,`find` 按主体和幂等键恢复回执,`events` 按序号分页,`cancel` 记录取消请求。只有确认容器停止且清理成功后才发布取消终态。处理器的停止信号来自持久控制状态。父任务通过 `parentId` 将子任务路由到持有连接的节点,子任务使用单独的控制并发额度。
49
+
50
+ ## 容器环境与资源
51
+
52
+ 启动时配置 `environments`,每项提供 ID、已预拉取的镜像 digest、CPU 核数、内存 MiB、PID 数和临时盘 MiB。调用方通过 `environmentId` 选环境,并可请求更低的资源限制。执行节点在同一数据库事务内领取任务并预留资源。按主体和节点设置队列与并发上限。
53
+
54
+ 为防止 Agent Worker 占满节点后工具无法运行,使用 `toolCapacity` 独立预留工具资源。默认预留 1 核 CPU、1024 MiB 内存、128 个 PID 和 512 MiB 临时盘,`toolMaxRunning` 默认为 4。宿主总预算须覆盖两个分区。可信处理器通过 `capacityClass: "tool"` 使用该分区,`concurrency: { key, limit }` 为同一类服务设置跨节点并发上限。
55
+
56
+ 处理器通过 `context.start` 启动容器,取得标准输入、输出、错误流和退出结果。镜像应支持 Linux cgroup v2,使用 `/bin/sh`,并能以 UID/GID 1000 运行。根文件系统只读。`/state`、`/workspace` 和 `/tmp` 按任务分配受限 tmpfs。启动文件复制到 `/state`。节点上已登记的内部网络必须通过引擎的 internal 检查,默认完全禁用容器网络。联网任务应使用按信任域配置的内部网关。
57
+
58
+ 启动环境和原生连接留在执行节点。输入、事件、输出只接受有界 JSON。密钥由可信处理器在启动时解析,调用记录使用业务标识和对象引用。执行节点失联或清理无法确认时保留 `unknown` 状态和预留额度,待运维核实实际容器和外部副作用。
59
+
60
+ 工具处理器可用 `inputs` 将规范 Base64 文件按简单文件名写入只读 `/input`,并在容器仍运行时调用 `artifact(name, maxBytes)` 从 `/output` 读取普通文件。输入总量和输出各最多 50 MiB,同时受环境临时盘限制。用于产物导出的镜像应提供 `/usr/bin/python3`。
61
+
62
+ 原执行节点的可信管理入口可以调用 `runner.reconcileUnknown(scope, id, { operatorId, reason })`。Runner 读取启动前保存的容器及引擎身份,确认容器已经移除并清理同一暂存目录后才释放预算和复用键,同时保存审核记录。原回执仍为 `unknown`,并增加 `reconciledAt`。缺少可信容器回执的任务继续保留预算。
63
+
64
+ 固定离线工具可在 API 与执行节点登记相同的 `registerWarmPool({ key, kind, environmentId, minReady, maxRunning, maxTotal })`。`minReady` 是全体执行节点的空容器目标,`maxTotal` 包含启动、等待、执行、清理和未核验实例。可信工具请求同时指定 `warmPool: true` 和对应服务并发键。领取前容器没有用户输入,领取成功后才写入授权文件。每个实例只执行一个作业,之后销毁。镜像需提供 `/usr/bin/python3`;预热会消耗工具预留资源。
65
+
66
+ ## 开发测试
67
+
68
+ ```bash
69
+ pnpm --filter @h-ai/runner typecheck
70
+ pnpm --filter @h-ai/runner lint
71
+ pnpm --filter @h-ai/runner build
72
+ pnpm --filter @h-ai/runner test
73
+ ```
74
+
75
+ 测试包含真实 SQLite、PostgreSQL、MySQL 及 Docker/Podman 容器。通过 `HAI_TEST_CONTAINER_ENGINE` 指定容器引擎。PostgreSQL 与 MySQL 测试通过 Testcontainers 连接同一引擎提供的 Docker 兼容 API。
76
+
77
+ ## 许可证
78
+
79
+ Apache-2.0