@qilin-agent/kylin-host-runner 0.0.0-stage → 3.1.3
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 +21 -0
- package/README.i18n.yaml +70 -0
- package/README.md +150 -2
- package/README.zh.md +151 -0
- package/lib/index.js +2619 -0
- package/lib/typert.host.d.ts +3 -0
- package/lib/typert.host.js +2483 -0
- package/lib/typert.remote-client.d.ts +56 -0
- package/lib/typert.remote-client.js +819 -0
- package/lib/types/guard.d.ts +71 -0
- package/lib/types/guard.js +766 -0
- package/lib/types/index.d.ts +280 -0
- package/lib/types/index.js +1150 -0
- package/lib/types/inspect-registry.d.ts +78 -0
- package/lib/types/inspect-registry.js +237 -0
- package/lib/types/lifecycle.d.ts +29 -0
- package/lib/types/lifecycle.js +49 -0
- package/lib/types/registry.d.ts +225 -0
- package/lib/types/registry.js +131 -0
- package/lib/types/sandbox.d.ts +99 -0
- package/lib/types/sandbox.js +251 -0
- package/lib/types/types.d.ts +363 -0
- package/lib/types/types.js +6 -0
- package/package.json +73 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 kkutysllb
|
|
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.i18n.yaml
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Bilingual-pair consistency record for README.md (docs/i18n/README.md): per heading
|
|
2
|
+
# section, a hash of its English and Chinese blocks outside code blocks and generated regions.
|
|
3
|
+
# After editing either side, bring the other along and re-record with:
|
|
4
|
+
# pnpm run verify-translation-pairing --write packages/extensions/kylin-host-runner/README.md
|
|
5
|
+
/:
|
|
6
|
+
en: 3de716c1fb132608
|
|
7
|
+
zh: 30dbce3949ce9f0c
|
|
8
|
+
/qilin-kylin-host-runner:
|
|
9
|
+
en: 2ea0888e4228e68d
|
|
10
|
+
zh: 53db72567ab651ad
|
|
11
|
+
/qilin-kylin-host-runner/summary:
|
|
12
|
+
en: db709f4d4f1f49ac
|
|
13
|
+
zh: 006317c8ac79e257
|
|
14
|
+
/qilin-kylin-host-runner/table-of-contents:
|
|
15
|
+
en: d152484eb41ac6b4
|
|
16
|
+
zh: 09388d293f9be9cb
|
|
17
|
+
/qilin-kylin-host-runner/use-this-package:
|
|
18
|
+
en: bdaba8036acf80c9
|
|
19
|
+
zh: 2dd8f972c3023a8a
|
|
20
|
+
/qilin-kylin-host-runner/use-this-package/minimal-configuration:
|
|
21
|
+
en: 07140d1c3c5643ab
|
|
22
|
+
zh: 3a1cfd7dda976c6d
|
|
23
|
+
/qilin-kylin-host-runner/use-this-package/client-inspection:
|
|
24
|
+
en: b4a2fe9e7aa9dee7
|
|
25
|
+
zh: 56f55558809970da
|
|
26
|
+
/qilin-kylin-host-runner/use-this-package/what-a-run-does:
|
|
27
|
+
en: a3c86c081974a710
|
|
28
|
+
zh: 180e1b7824c070d4
|
|
29
|
+
/qilin-kylin-host-runner/use-this-package/what-happens-to-definitions:
|
|
30
|
+
en: d1a8777f171d22bb
|
|
31
|
+
zh: 7f6aa4c2680557b1
|
|
32
|
+
/qilin-kylin-host-runner/use-this-package/trust-stance:
|
|
33
|
+
en: 3c83e56d1c7a026c
|
|
34
|
+
zh: f127c65922a51b92
|
|
35
|
+
/qilin-kylin-host-runner/understand-the-implementation:
|
|
36
|
+
en: b0a536c0d00cbdb8
|
|
37
|
+
zh: 08e5d813aa6a612a
|
|
38
|
+
/qilin-kylin-host-runner/understand-the-implementation/design-philosophy:
|
|
39
|
+
en: 2193b1c446b388fc
|
|
40
|
+
zh: f8c01188d5ca2a3b
|
|
41
|
+
/qilin-kylin-host-runner/understand-the-implementation/source-map:
|
|
42
|
+
en: f567eacc1072b96c
|
|
43
|
+
zh: 8747f8453fff9553
|
|
44
|
+
/qilin-kylin-host-runner/understand-the-implementation/how-a-run-flows:
|
|
45
|
+
en: 0dc7542abbfc613b
|
|
46
|
+
zh: 48ae64fd474adabf
|
|
47
|
+
/qilin-kylin-host-runner/further-exploration:
|
|
48
|
+
en: d7aef34e107e9dda
|
|
49
|
+
zh: 063bb361dc05bc07
|
|
50
|
+
/qilin-kylin-host-runner/model-experience:
|
|
51
|
+
en: 215e7ba838619b7b
|
|
52
|
+
zh: a311da3843709f90
|
|
53
|
+
/qilin-kylin-host-runner/model-experience/run-outcomes-refusals-and-diagnostics-relayed-to-the-owning-session:
|
|
54
|
+
en: f53130bb645f50df
|
|
55
|
+
zh: 603361c566527789
|
|
56
|
+
/qilin-kylin-host-runner/model-experience/run-outcomes-refusals-and-diagnostics-relayed-to-the-owning-session/what-the-model-sees:
|
|
57
|
+
en: 743dbef78fa3a8ad
|
|
58
|
+
zh: 2aa4e404e908cf22
|
|
59
|
+
/qilin-kylin-host-runner/model-experience/run-outcomes-refusals-and-diagnostics-relayed-to-the-owning-session/token-effect:
|
|
60
|
+
en: c7ef63dd8179a97e
|
|
61
|
+
zh: e66545088d00956a
|
|
62
|
+
/qilin-kylin-host-runner/model-experience/run-outcomes-refusals-and-diagnostics-relayed-to-the-owning-session/kv-cache-effect:
|
|
63
|
+
en: bbc4338c3035757a
|
|
64
|
+
zh: f51f4848786d5606
|
|
65
|
+
/qilin-kylin-host-runner/known-limitations-and-deferred-work:
|
|
66
|
+
en: 1f10688ae249a077
|
|
67
|
+
zh: c1a86dd36c92e05e
|
|
68
|
+
/qilin-kylin-host-runner/known-limitations-and-deferred-work/dev-note:
|
|
69
|
+
en: e67f633dc6fe7773
|
|
70
|
+
zh: 3bb0c20c93f16f98
|
package/README.md
CHANGED
|
@@ -1,3 +1,151 @@
|
|
|
1
|
-
|
|
1
|
+
---
|
|
2
|
+
description: "Host half of dynamic Kylin packages for agents and maintainers choosing, composing, or debugging the registry, sandbox, and run round trip."
|
|
3
|
+
kind: "package-reference"
|
|
4
|
+
---
|
|
2
5
|
|
|
3
|
-
|
|
6
|
+
# @qilin-agent/kylin-host-runner
|
|
7
|
+
|
|
8
|
+
English | [中文](README.zh.md)
|
|
9
|
+
|
|
10
|
+
## Summary
|
|
11
|
+
|
|
12
|
+
`dsh-kylin-host-runner` exposes runtime inspection and keeps process-local dynamic definitions available to programmatic callers and browser controls. Host halves run in a `node:vm` realm; browser halves use the Client runner and approval UI. Definitions disappear on restart. Agents discover APIs through `tool-kylin` and install persistent bundles through Plugin Manager; no model tool creates dynamic definitions.
|
|
13
|
+
|
|
14
|
+
## Table of Contents
|
|
15
|
+
|
|
16
|
+
- [Use this package](#use-this-package)
|
|
17
|
+
- [Understand the implementation](#understand-the-implementation)
|
|
18
|
+
- [Further Exploration](#further-exploration)
|
|
19
|
+
- [Model Experience](#model-experience)
|
|
20
|
+
- [Known Limitations and Deferred Work](#known-limitations-and-deferred-work)
|
|
21
|
+
- [Dev Note](#dev-note)
|
|
22
|
+
|
|
23
|
+
-----
|
|
24
|
+
|
|
25
|
+
<a id="use-this-package"></a>
|
|
26
|
+
## Use this package
|
|
27
|
+
|
|
28
|
+
Mount this plugin for the inspection registry or programmatic dynamic-package lifecycle. Browser lifecycle consumers also require the Client runner and UI package. The shipped Creator workflow uses installed bundles instead of this definition registry.
|
|
29
|
+
|
|
30
|
+
### Minimal configuration
|
|
31
|
+
|
|
32
|
+
```yaml
|
|
33
|
+
- name: '@qilin-agent/kylin-host-runner'
|
|
34
|
+
config:
|
|
35
|
+
vmTimeoutMs: 5000
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
| Field | Default | Meaning |
|
|
39
|
+
|---|---|---|
|
|
40
|
+
| `vmTimeoutMs` | `5000` | Milliseconds the synchronous portion of a host half may run in the vm before evaluation is aborted |
|
|
41
|
+
|
|
42
|
+
The generated [configuration catalog](../../../docs/config-catalog.md#qilin-agentkylin-host-runner) is the exhaustive source for every accepted field.
|
|
43
|
+
|
|
44
|
+
<a id="client-inspection"></a>
|
|
45
|
+
### Client inspection
|
|
46
|
+
|
|
47
|
+
When Gateway is mounted, a Client query with no live event stream fails before dispatch. This check does not subscribe to disconnections: queries already dispatched retain their original deadline. Standalone event transports without Gateway retain the same timeout behavior.
|
|
48
|
+
|
|
49
|
+
Client queries accept the first valid page response within `clientInspectTimeoutMs`. A failed page does not prevent another page from answering successfully. If no valid result arrives, the query rejects with the first Client failure or output-validation diagnostic; when no page answers, it asks the caller to open or reconnect the Harness page and retry. Cancellation and registry disposal also end pending queries. Reconnecting a page does not replay a missed request, so retry after the connection is restored. Host queries are unaffected by this timeout.
|
|
50
|
+
|
|
51
|
+
### What a run does
|
|
52
|
+
|
|
53
|
+
Programmatic callers use `define`, `run`, `stop`, and `undefine`; the browser panel operates existing definitions. Host-only packages activate in this process. A package with a browser half waits for approval or cancellation, then loads Host before Client. `mode: "run"` starts the current version; `mode: "update"` replaces it. Stop disposes the live effects and retains the definition; undefine also forgets it.
|
|
54
|
+
|
|
55
|
+
### What happens to definitions
|
|
56
|
+
|
|
57
|
+
Definitions are session-scoped and process-local: other sessions read them as absent, and restart clears them. Historical logs retain tool arguments and receipts but do not restore the registry. Reloading a browser page requires another explicit run to load its Client half.
|
|
58
|
+
|
|
59
|
+
### Trust stance
|
|
60
|
+
|
|
61
|
+
The sandbox isolates globals but is not a security boundary: Node globals are absent or redirect to Kylin services (`ctx.fs`, `ctx.web`, `ctx.bash`, the timer helpers), and a host half receives a façade without framework internals, yet the services it declares reach the live runtime. Treat a dynamic package like bash access — see the [self-referential toolset Agent Note](../../../.agents/notes/implemented/feature/2026-07-08-self-referential-cordis-toolset.md).
|
|
62
|
+
|
|
63
|
+
-----
|
|
64
|
+
|
|
65
|
+
<a id="understand-the-implementation"></a>
|
|
66
|
+
## Understand the implementation
|
|
67
|
+
|
|
68
|
+
<details>
|
|
69
|
+
<summary>Implementation internals — click to expand</summary>
|
|
70
|
+
|
|
71
|
+
This section explains the design behind the runner; the observable behavior is fully covered in [Use this package](#use-this-package).
|
|
72
|
+
|
|
73
|
+
### Design philosophy
|
|
74
|
+
|
|
75
|
+
The runner is built on two separations. **Registry and sandbox are one service.** The `DynamicCordisRunnerService` owns the definition registry, the vm sandbox, the host-half fiber lifecycle, and the invoke handler table, so a definition's whole life has one owner. **Versions are immutable packages.** A plugin holds packages that never change after `define`; `currentPackageId` and `nextPackageId` point at the running and target versions, and `mode: "run"` versus `"update"` encodes whether the target equals the current version. The browser round trip exists because a browser half can only be carried out by a page: the service emits a request, suspends, and is settled by the page's verdict, with the caller's `AbortSignal` as the only other exit.
|
|
76
|
+
|
|
77
|
+
### Source map
|
|
78
|
+
|
|
79
|
+
| File | Role |
|
|
80
|
+
|---|---|
|
|
81
|
+
| [`src/index.ts`](src/index.ts) | Service entry: `Config`, registry wiring, lifecycle verbs, steer messages |
|
|
82
|
+
| [`src/registry.ts`](src/registry.ts) | Definition store: plugin and package identities, run attempts, approval requests |
|
|
83
|
+
| [`src/sandbox.ts`](src/sandbox.ts) | `node:vm` evaluation: globals, Node-API traps, define-time syntax precheck |
|
|
84
|
+
| [`src/guard.ts`](src/guard.ts) | Registration boundary: schema normalization, the sandbox `ctx` façade, plugin-shape checks |
|
|
85
|
+
| [`src/lifecycle.ts`](src/lifecycle.ts) | Starting a host half under the `cordis-dynamic` fiber group |
|
|
86
|
+
| [`src/inspect-registry.ts`](src/inspect-registry.ts) | The `ctx.cordisInspect` registry: host providers plus the mirrored client manifest |
|
|
87
|
+
| [`src/types.ts`](src/types.ts) | Client-safe payload shapes for the `dynamicCordisRunner` remote namespace and forwarded events |
|
|
88
|
+
|
|
89
|
+
### How a run flows
|
|
90
|
+
|
|
91
|
+
`define` trims and requires the metadata, prechecks each half's syntax by compiling it (running nothing), mints the plugin and package ids, and records the definition against the session that asked. `run` resolves the target against `currentPackageId` and `nextPackageId`; a host-only package evaluates in the sandbox and commits immediately, while a browser-half package arms an approval request, emits `cordis/request-run`, and suspends. The answering page walks `runHostHalf`, `getClientCode`, then `resolveRequestRun`; a success naming the live revision commits the activation and sets `currentPackageId`, and `cordis/request-run-resolved` drops the pending affordance on every other page. `stop` retracts the live dispatch — handler disposers, fiber dispose, and the `cordis/dynamic-retract` broadcast — and leaves the definition runnable. Four forwarded events (`cordis/request-run`, `cordis/request-run-resolved`, `cordis/dynamic-package`, `cordis/dynamic-retract`) are declared on the client-safe `./types` subpath and allowlisted for delivery by `@qilin-agent/api-remotes`, which is what lets a browser reach them through `ctx.remote.$on`.
|
|
92
|
+
|
|
93
|
+
</details>
|
|
94
|
+
|
|
95
|
+
-----
|
|
96
|
+
|
|
97
|
+
<a id="further-exploration"></a>
|
|
98
|
+
## Further Exploration
|
|
99
|
+
|
|
100
|
+
Read these pages when the package-level contract is not enough. They move from the runner to the tools that call it, the browser half that answers it, and the generated surface.
|
|
101
|
+
|
|
102
|
+
- [Tool package](../tool-kylin/README.md) — the read-only tools that use its inspection registry.
|
|
103
|
+
- [Client runner](../kylin-client-runner/README.md) — the browser half that answers run requests and loads browser-half code.
|
|
104
|
+
- [UI package](../ui-kylin/README.md) — the panel users approve and operate runs with.
|
|
105
|
+
- [Generated configuration catalog](../../../docs/config-catalog.md#qilin-agentkylin-host-runner) — every accepted config field.
|
|
106
|
+
- [Extensions subsystem](../../../docs/subsystems/extensions.md) — the generated `ctx.cordisInspect` and `ctx.dynamicCordisRunner` API and `cordis/*` events.
|
|
107
|
+
- [Self-referential Kylin toolset Agent Note](../../../.agents/notes/implemented/feature/2026-07-08-self-referential-cordis-toolset.md) — sandbox semantics, lifecycle, and composition rationale.
|
|
108
|
+
|
|
109
|
+
-----
|
|
110
|
+
|
|
111
|
+
<a id="model-experience"></a>
|
|
112
|
+
## Model Experience
|
|
113
|
+
|
|
114
|
+
### Run outcomes, refusals, and diagnostics relayed to the owning session
|
|
115
|
+
|
|
116
|
+
#### What the model sees
|
|
117
|
+
|
|
118
|
+
This package registers no tool or prompt. Programmatic `run` calls and browser controls can steer the owning session with outcomes and diagnostics; stop and remove gestures inject a user message. Shipped model tools cannot create or update dynamic definitions.
|
|
119
|
+
|
|
120
|
+
#### Token effect
|
|
121
|
+
|
|
122
|
+
Conditional and data-dependent: messages arrive only when an event occurs, and each carries a bounded description of what happened; there is no fixed per-request cost.
|
|
123
|
+
|
|
124
|
+
#### KV Cache effect
|
|
125
|
+
|
|
126
|
+
None of its own. A host half that registers tools changes the next request's tool view, which invalidates prefix reuse from the first changed schema token; running or stopping a package with no tool registrations is prefix-neutral.
|
|
127
|
+
|
|
128
|
+
## Known Limitations and Deferred Work
|
|
129
|
+
|
|
130
|
+
<a id="known-limitations-and-deferred-work"></a>
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
These limits define when the runner needs special care. They are current package constraints, not a task backlog.
|
|
134
|
+
|
|
135
|
+
- **A successful run does not mean the UI rendered** — React renders after the load receipt; failures reach the owning session through steering and appear in the browser panel.
|
|
136
|
+
- **A browser-half package suspends where no page is connected** — headless and ACP deployments hold the run until the asking turn is cancelled; host-only packages are unaffected.
|
|
137
|
+
- **A suspended run request has no timeout** — it waits for a person until the asking turn is cancelled, so unattended automation cannot use packages with a browser half.
|
|
138
|
+
- **`vmTimeoutMs` bounds only synchronous evaluation** — an async host-half body escapes it, matching the toolset's cooperative trust stance.
|
|
139
|
+
- **A stale-success refusal leaves the request suspended** — when the answering page names a revision the registry has moved past, the resolution is refused (`accepted: false`) and the request stays answerable until another page answers or the caller cancels; the browser half does not read the acknowledgement.
|
|
140
|
+
- **The run announcement carries no service declarations** — a browser half's declared `inject` is read from the plugin it returns in the page, so `cordis/request-run` carries metadata only, never code or service lists.
|
|
141
|
+
- **`zod` is a runtime dependency of the generated Typert faces, not of `src`** — `./typert` and `./remote` resolve to unbundled `lib` files with a bare `import { z } from 'zod'`, so the package declares it even though nothing in `src` imports zod.
|
|
142
|
+
|
|
143
|
+
<a id="dev-note"></a>
|
|
144
|
+
### Dev Note
|
|
145
|
+
|
|
146
|
+
<details>
|
|
147
|
+
<summary>Working context for maintainers — click to expand</summary>
|
|
148
|
+
|
|
149
|
+
None.
|
|
150
|
+
|
|
151
|
+
</details>
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: "动态 Kylin 包的 host 半说明,供选择、组合或排查注册表、沙箱与运行往返的 agent(智能体)与维护者阅读。"
|
|
3
|
+
kind: "package-reference"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# @qilin-agent/kylin-host-runner
|
|
7
|
+
|
|
8
|
+
[English](README.md) | 中文
|
|
9
|
+
|
|
10
|
+
## 概述
|
|
11
|
+
|
|
12
|
+
`dsh-kylin-host-runner` 提供运行时检查,并为程序调用方和浏览器控件保留进程内动态定义。Host 部分在 `node:vm` 中运行;浏览器部分使用 Client runner 和审批 UI。定义在重启后消失。Agent 通过 `tool-kylin` 发现 API,通过 Plugin Manager 安装持久化 bundle;没有模型工具创建动态定义。
|
|
13
|
+
|
|
14
|
+
## 目录
|
|
15
|
+
|
|
16
|
+
- [使用本包](#use-this-package)
|
|
17
|
+
- [理解实现](#understand-the-implementation)
|
|
18
|
+
- [进一步探索](#further-exploration)
|
|
19
|
+
- [模型体验](#model-experience)
|
|
20
|
+
- [已知限制与延期工作](#known-limitations-and-deferred-work)
|
|
21
|
+
- [开发备注](#dev-note)
|
|
22
|
+
|
|
23
|
+
-----
|
|
24
|
+
|
|
25
|
+
<a id="use-this-package"></a>
|
|
26
|
+
## 使用本包
|
|
27
|
+
|
|
28
|
+
需要检查注册表或程序侧动态包生命周期时挂载此插件。浏览器生命周期消费者还需要 Client runner 和 UI 包。内置 Creator 流程使用已安装 bundle,不使用此定义注册表。
|
|
29
|
+
|
|
30
|
+
### 最小配置
|
|
31
|
+
|
|
32
|
+
```yaml
|
|
33
|
+
- name: '@qilin-agent/kylin-host-runner'
|
|
34
|
+
config:
|
|
35
|
+
vmTimeoutMs: 5000
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
| 字段 | 默认值 | 含义 |
|
|
39
|
+
|---|---|---|
|
|
40
|
+
| `vmTimeoutMs` | `5000` | host 半在 vm 中同步执行的那部分被中止求值前可运行的毫秒数 |
|
|
41
|
+
|
|
42
|
+
生成的[配置目录](../../../docs/config-catalog.zh.md#qilin-agentkylin-host-runner)是每个受支持字段的穷尽式真源。
|
|
43
|
+
|
|
44
|
+
<a id="client-inspection"></a>
|
|
45
|
+
### Client 检查
|
|
46
|
+
|
|
47
|
+
装载 Gateway 时,没有活动事件流的 Client 查询在发送前就会失败。此检查不订阅断连:已发送的查询仍沿用原期限。没有 Gateway 的独立事件传输保持相同的超时行为。
|
|
48
|
+
|
|
49
|
+
Client 查询在 `clientInspectTimeoutMs` 内接受首个有效页面响应。某个页面失败不会阻止其他页面成功回答。若没有有效结果,查询返回首个 Client 错误或输出校验诊断;若没有页面回答,则提示调用方打开或重新连接 Harness 页面后重试。取消和注册表卸载也会结束待处理查询。页面重连不会重放错过的请求,因此需在连接恢复后重试。Host 查询不受此超时影响。
|
|
50
|
+
|
|
51
|
+
### run 会做什么
|
|
52
|
+
|
|
53
|
+
程序调用方使用 `define`、`run`、`stop` 和 `undefine`;浏览器面板操作已有定义。仅含 Host 的包在本进程激活。带浏览器部分的包等待审批或取消,批准后先加载 Host 再加载 Client。`mode: "run"` 启动当前版本,`mode: "update"` 替换版本。Stop 释放运行中的 effect 并保留定义;undefine 还会移除定义。
|
|
54
|
+
|
|
55
|
+
### 定义的去向
|
|
56
|
+
|
|
57
|
+
定义按会话隔离且仅在进程内存在:其他会话无法读取,重启会清空。历史日志保留工具参数和回执,但不会恢复注册表。浏览器页面重载后,需要再次显式运行才能加载 Client 部分。
|
|
58
|
+
|
|
59
|
+
### 信任立场
|
|
60
|
+
|
|
61
|
+
沙箱隔离全局变量,但不是安全边界:Node 全局变量不存在,或重定向到 Kylin 服务(`ctx.fs`、`ctx.web`、`ctx.bash` 与定时器 helper),host 半收到的是不含框架内部机制的 façade,但它声明的服务仍会触达存活运行时。对待动态包要像对待 bash 访问一样,参见[自引用工具集 Agent Note](../../../.agents/notes/implemented/feature/2026-07-08-self-referential-cordis-toolset.zh.md)。
|
|
62
|
+
|
|
63
|
+
-----
|
|
64
|
+
|
|
65
|
+
<a id="understand-the-implementation"></a>
|
|
66
|
+
## 理解实现
|
|
67
|
+
|
|
68
|
+
<details>
|
|
69
|
+
<summary>实现细节——点击展开</summary>
|
|
70
|
+
|
|
71
|
+
本节解释 runner 背后的设计;可观察行为已在[使用本包](#use-this-package)中完整说明。
|
|
72
|
+
|
|
73
|
+
### 设计理念
|
|
74
|
+
|
|
75
|
+
runner 基于两项职责划分。**注册表与沙箱是同一个服务。** `DynamicKylinRunnerService` 拥有定义注册表、vm 沙箱、host 半 fiber 生命周期与 invoke handler 表,因此一个定义的整个生命周期只有一个 owner。**版本是不可变的包。** 插件持有 `define` 之后永不变化的包;`currentPackageId` 与 `nextPackageId` 指向运行中与目标版本,`mode: "run"` 与 `"update"` 编码目标是否等于当前版本。浏览器往返之所以存在,是因为浏览器半只能由页面执行:服务 emit 请求并挂起,由页面的结论结算,调用方的 `AbortSignal` 是唯一的另一条出路。
|
|
76
|
+
|
|
77
|
+
### 源码地图
|
|
78
|
+
|
|
79
|
+
| 文件 | 职责 |
|
|
80
|
+
|---|---|
|
|
81
|
+
| [`src/index.ts`](src/index.ts) | 服务入口:`Config`、注册表接线、生命周期动词、steering(中途引导)消息 |
|
|
82
|
+
| [`src/registry.ts`](src/registry.ts) | 定义存储:插件与包标识、运行尝试、审批请求 |
|
|
83
|
+
| [`src/sandbox.ts`](src/sandbox.ts) | `node:vm` 求值:全局变量、Node API 陷阱、define 时语法预检 |
|
|
84
|
+
| [`src/guard.ts`](src/guard.ts) | 注册边界:schema 规范化、沙箱 `ctx` façade、插件形态检查 |
|
|
85
|
+
| [`src/lifecycle.ts`](src/lifecycle.ts) | 在 `kylin-dynamic` fiber 组下启动 host 半 |
|
|
86
|
+
| [`src/inspect-registry.ts`](src/inspect-registry.ts) | `ctx.cordisInspect` 注册表:host 提供方加镜像的 client manifest(元数据清单) |
|
|
87
|
+
| [`src/types.ts`](src/types.ts) | `dynamicCordisRunner` remote namespace 与转发事件共享的 client 安全载荷形态 |
|
|
88
|
+
|
|
89
|
+
### 一次 run 的流程
|
|
90
|
+
|
|
91
|
+
`define` 对元数据做首尾去空白与必填校验,用编译预检每一半的语法(不执行任何代码),铸出插件与包标识,并把定义登记在发起调用的会话名下。`run` 对照 `currentPackageId` 与 `nextPackageId` 解析目标:纯 host 包在沙箱中求值并立即提交,带浏览器半的包则建立一次审批请求、emit `kylin/request-run` 并挂起。作答页面依次走 `runHostHalf`、`getClientCode` 与 `resolveRequestRun`;命名存活 revision 的成功会提交激活、设置 `currentPackageId`,`kylin/request-run-resolved` 让其他每个页面撤下待作答入口。`stop` 回退存活下发——handler disposer、fiber dispose(资源释放)与 `kylin/dynamic-retract` 广播——并让定义保持可运行。四条转发事件(`kylin/request-run`、`kylin/request-run-resolved`、`kylin/dynamic-package`、`kylin/dynamic-retract`)声明在 client 安全的 `./types` 子路径上,并由 `@qilin-agent/api-remotes` 的白名单准许投递——正是这一点让浏览器能经 `ctx.remote.$on` 收到它们。
|
|
92
|
+
|
|
93
|
+
</details>
|
|
94
|
+
|
|
95
|
+
-----
|
|
96
|
+
|
|
97
|
+
<a id="further-exploration"></a>
|
|
98
|
+
## 进一步探索
|
|
99
|
+
|
|
100
|
+
当包级约定不够用时阅读以下页面。它们从 runner 逐步进入调用它的工具、应答它的浏览器半与生成的表面。
|
|
101
|
+
|
|
102
|
+
- [工具包](../tool-kylin/README.zh.md)——使用其检查注册表的只读工具。
|
|
103
|
+
- [Client runner](../kylin-client-runner/README.zh.md)——应答运行请求并装载浏览器半代码的浏览器半。
|
|
104
|
+
- [UI 包](../ui-kylin/README.zh.md)——用户批准并操作运行的面板。
|
|
105
|
+
- [生成的配置目录](../../../docs/config-catalog.zh.md#qilin-agentkylin-host-runner)——每个受支持配置字段。
|
|
106
|
+
- [extensions 子系统](../../../docs/subsystems/extensions.zh.md)——生成的 `ctx.cordisInspect` 与 `ctx.dynamicCordisRunner` API 及 `kylin/*` 事件。
|
|
107
|
+
- [自引用 Kylin 工具集 Agent Note](../../../.agents/notes/implemented/feature/2026-07-08-self-referential-cordis-toolset.zh.md)——沙箱语义、生命周期与组合的理由。
|
|
108
|
+
|
|
109
|
+
-----
|
|
110
|
+
|
|
111
|
+
<a id="model-experience"></a>
|
|
112
|
+
## 模型体验
|
|
113
|
+
|
|
114
|
+
### 转达给所属会话的运行结果、拒绝与诊断
|
|
115
|
+
|
|
116
|
+
#### 模型看到的内容
|
|
117
|
+
|
|
118
|
+
本包不注册工具或提示。程序侧 `run` 调用和浏览器控件可向所属会话发送结果与诊断;停止和移除操作注入用户消息。内置模型工具无法创建或更新动态定义。
|
|
119
|
+
|
|
120
|
+
#### Token 影响
|
|
121
|
+
|
|
122
|
+
有条件且随数据而定:消息只在事件发生时到达,每条都携带一段有界的说明;没有固定的每请求成本。
|
|
123
|
+
|
|
124
|
+
#### KV Cache 影响
|
|
125
|
+
|
|
126
|
+
本包自身没有。注册工具的 host 半会改变下一次请求的工具视图,从第一个变化的 schema token 起使前缀复用失效;运行或停止一个不注册任何工具的包对前缀不产生影响。
|
|
127
|
+
|
|
128
|
+
## 已知限制与延期工作
|
|
129
|
+
|
|
130
|
+
<a id="known-limitations-and-deferred-work"></a>
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
这些限制说明 runner 何时需要特别小心。它们是当前包约束,不是任务积压。
|
|
134
|
+
|
|
135
|
+
- **运行成功不代表 UI 已渲染**——React 在加载回执之后渲染;失败通过 steering 发送到所属会话,并显示在浏览器面板中。
|
|
136
|
+
- **带浏览器半的包在没有页面连接的地方挂起**——headless 与 ACP(Agent Client Protocol)部署会把 run 一直挂到提问的轮次被取消;纯 host 包不受影响。
|
|
137
|
+
- **挂起的 run 请求没有超时**——它一直等人,直到提问的轮次被取消,因此无人值守的自动化用不了带浏览器半的包。
|
|
138
|
+
- **`vmTimeoutMs` 只约束同步求值**——async 的 host 半函数体会逃出该上限,这与工具集基于协作的信任立场一致。
|
|
139
|
+
- **陈旧成功的拒绝会让请求继续挂起**——作答页面点名的 revision 已被注册表越过时,该结论会被拒绝(`accepted: false`),请求保持可作答,直到另一个页面作答或调用方取消;浏览器半不读这个 ack。
|
|
140
|
+
- **运行播报不携带服务声明**——浏览器半声明的 `inject` 是从它在页面里返回的插件上读出的,因此 `kylin/request-run` 只携带元数据,绝无代码或服务清单。
|
|
141
|
+
- **`zod` 是生成的 Typert 契约面的运行时依赖,不是 `src` 的依赖**——`./typert` 与 `./remote` 解析到未打包的 `lib` 文件,其中带有裸的 `import { z } from 'zod'`,所以即使 `src` 里没有任何代码 import zod,本包也要声明它。
|
|
142
|
+
|
|
143
|
+
<a id="dev-note"></a>
|
|
144
|
+
### 开发备注
|
|
145
|
+
|
|
146
|
+
<details>
|
|
147
|
+
<summary>维护者的工作上下文——点击展开</summary>
|
|
148
|
+
|
|
149
|
+
无。
|
|
150
|
+
|
|
151
|
+
</details>
|