@xioflow/kernel 0.1.4 → 0.2.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.
- package/README.md +27 -8
- package/dist/domain.d.ts +40 -6
- package/dist/domain.d.ts.map +1 -1
- package/dist/domain.js +388 -24
- package/dist/domain.js.map +1 -1
- package/dist/driver/node-driver.d.ts +11 -9
- package/dist/driver/node-driver.d.ts.map +1 -1
- package/dist/driver/node-driver.js +224 -225
- package/dist/driver/node-driver.js.map +1 -1
- package/dist/driver/process-facts.d.ts +25 -0
- package/dist/driver/process-facts.d.ts.map +1 -0
- package/dist/driver/process-facts.js +164 -0
- package/dist/driver/process-facts.js.map +1 -0
- package/dist/driver/sampler.d.ts +51 -0
- package/dist/driver/sampler.d.ts.map +1 -0
- package/dist/driver/sampler.js +224 -0
- package/dist/driver/sampler.js.map +1 -0
- package/dist/driver/types.d.ts +29 -1
- package/dist/driver/types.d.ts.map +1 -1
- package/dist/recovery/engine.d.ts +2 -0
- package/dist/recovery/engine.d.ts.map +1 -1
- package/dist/recovery/engine.js +137 -14
- package/dist/recovery/engine.js.map +1 -1
- package/dist/store/sqlite.d.ts +12 -0
- package/dist/store/sqlite.d.ts.map +1 -1
- package/dist/store/sqlite.js +162 -12
- package/dist/store/sqlite.js.map +1 -1
- package/dist/supervisor/supervisor.d.ts +15 -0
- package/dist/supervisor/supervisor.d.ts.map +1 -1
- package/dist/supervisor/supervisor.js +619 -214
- package/dist/supervisor/supervisor.js.map +1 -1
- package/dist/testing/contract-suite.d.ts.map +1 -1
- package/dist/testing/contract-suite.js +301 -11
- package/dist/testing/contract-suite.js.map +1 -1
- package/dist/types.d.ts +37 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +29 -0
- package/dist/types.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
# @xioflow/kernel
|
|
2
2
|
|
|
3
|
+
[](https://github.com/Xio-Shark/xioflow/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/@xioflow/kernel)
|
|
5
|
+
[](https://nodejs.org/)
|
|
6
|
+
[](./LICENSE)
|
|
7
|
+
[](./ARCHITECTURE.md)
|
|
8
|
+
|
|
3
9
|
A supervised execution kernel for AI agent runtimes. Zero runtime dependencies.
|
|
4
10
|
|
|
5
11
|
Agent runtimes usually call `spawn()` (or `exec()`) and hope for the best. When the host crashes mid-tool-call, or a cancel cannot be confirmed, they are left with orphan processes, double-applied side effects, and no honest record of what actually happened. This kernel makes those states first-class instead of silent.
|
|
6
12
|
|
|
13
|
+
[xiocode](https://github.com/Xio-Shark/xiocode), the reference distribution, runs its supervised commands on this kernel by default on Node 22.5+ — the equivalence suite below is what made that switch safe to make.
|
|
14
|
+
|
|
7
15
|
## Guarantees
|
|
8
16
|
|
|
9
17
|
| Guarantee | Mechanism |
|
|
@@ -34,7 +42,7 @@ npm install @xioflow/kernel
|
|
|
34
42
|
import { ExecutionDomain, NodePlatformDriver, ProcessSupervisor } from '@xioflow/kernel';
|
|
35
43
|
|
|
36
44
|
// The domain directory will hold domain.db, domain.lock and artifacts/.
|
|
37
|
-
const domain = ExecutionDomain.acquire('/path/to/workspace/.xioflow', 'my-domain');
|
|
45
|
+
const domain = ExecutionDomain.acquire('/path/to/workspace/.xioflow/kernel', 'my-domain');
|
|
38
46
|
const supervisor = new ProcessSupervisor(domain, new NodePlatformDriver());
|
|
39
47
|
|
|
40
48
|
// Every operation belongs to a Run, and every Run to a Task. Register them first:
|
|
@@ -88,7 +96,7 @@ After a restart, reacquire the domain and run the recovery engine:
|
|
|
88
96
|
```js
|
|
89
97
|
import { ExecutionDomain, NodePlatformDriver, RecoveryEngine } from '@xioflow/kernel';
|
|
90
98
|
|
|
91
|
-
const domain = ExecutionDomain.acquire('/path/to/workspace/.xioflow', 'my-domain');
|
|
99
|
+
const domain = ExecutionDomain.acquire('/path/to/workspace/.xioflow/kernel', 'my-domain');
|
|
92
100
|
const report = await new RecoveryEngine(domain, new NodePlatformDriver()).recover();
|
|
93
101
|
```
|
|
94
102
|
|
|
@@ -130,21 +138,32 @@ defineContractTestSuite('My Agent Runtime', async () => ({
|
|
|
130
138
|
- A spawn failure is reported both as `status: 'failed'`/`exitCode: 127` and as `spawnFailure` with the underlying error message, so embedders can tell "the binary could not start" apart from "the child exited 127".
|
|
131
139
|
- `onStreamChunk(stream, chunk)` forwards raw stdout/stderr chunks while the process runs, so a caller can render live output. A throwing callback never aborts the drain; the first error is recorded as `streamCallbackError`.
|
|
132
140
|
- Hard resource requests (`maxMemoryBytes`, `maxPids`, `maxCpuTimeMs` with `enforcement: 'hard'`) are rejected at admission with `UnsupportedCapabilityError` on platforms that cannot enforce them, instead of degrading silently. The remaining capability flags are reported truthfully for callers to inspect, but are not enforced by admission in 0.1.
|
|
133
|
-
- Protocol specification: [`ARCHITECTURE.md`](./ARCHITECTURE.md) (Chinese).
|
|
141
|
+
- Protocol specification: [`ARCHITECTURE.md`](./ARCHITECTURE.md) (Chinese). It describes the target design; the phased plan and the spec-vs-implementation gap table live in [`ROADMAP.md`](./ROADMAP.md).
|
|
134
142
|
|
|
135
143
|
## Status
|
|
136
144
|
|
|
137
|
-
0.1.
|
|
145
|
+
0.1.5, pre-1.0: the API may change. Not implemented yet: Linux cgroup v2 backend (hard memory/CPU/PID enforcement), enforced domain-wide memory budgets, artifact retrieval helpers. Known correctness gaps in 0.1.x and the plan toward a Rust core with snapshot/rollback and a daemon mode are tracked in [`ROADMAP.md`](./ROADMAP.md).
|
|
138
146
|
|
|
139
147
|
## Releasing
|
|
140
148
|
|
|
141
|
-
Releases are tag-driven
|
|
149
|
+
Releases are tag-driven. A tag always produces a GitHub Release; the npm upload is switched on separately, so a tag can never ship an artifact that is not traceable to this repository:
|
|
142
150
|
|
|
143
151
|
1. Bump `version` in `package.json`, commit, and push to `main`.
|
|
144
|
-
2. Push the matching tag, e.g. `git tag v0.1.
|
|
145
|
-
3. `.github/workflows/release.yml` re-runs typecheck, tests and the pack smoke test, refuses a tag that does not match `package.json`,
|
|
152
|
+
2. Push the matching tag, e.g. `git tag v0.1.5 && git push origin v0.1.5`.
|
|
153
|
+
3. `.github/workflows/release.yml` re-runs typecheck, tests and the pack smoke test, refuses a tag that does not match `package.json`, creates the GitHub Release with the packed tarball, `SHA256SUMS` and a build provenance attestation attached, and — only when the repository variable `NPM_TRUSTED_PUBLISHING_ENABLED` is `true` — publishes with `npm publish --provenance` and verifies the attestation.
|
|
154
|
+
|
|
155
|
+
One-time setup, in this order: (1) npmjs.com → package settings → Trusted Publisher → GitHub Actions: organization `Xio-Shark`, repository `xioflow`, workflow filename `release.yml`, environment left empty; (2) set the repository variable `NPM_TRUSTED_PUBLISHING_ENABLED=true`. Until both exist the publish job is skipped and the reason is printed in the `verify` job's log. npm's registry index can lag several minutes behind an upload, so the verification step polls and may need a job re-run.
|
|
156
|
+
|
|
157
|
+
To attach assets to an existing tag without publishing to npm, run the workflow manually: `gh workflow run release.yml -f tag=v0.1.5`. An asset that is already attached is kept if identical and fails the run if it differs; published assets are never overwritten.
|
|
146
158
|
|
|
147
|
-
|
|
159
|
+
### Verifying a release
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
gh release download v0.1.5 --repo Xio-Shark/xioflow
|
|
163
|
+
shasum -a 256 -c SHA256SUMS
|
|
164
|
+
gh attestation verify xioflow-kernel-0.1.5.tgz --repo Xio-Shark/xioflow
|
|
165
|
+
npm audit signatures # inside a project that installed @xioflow/kernel from npm
|
|
166
|
+
```
|
|
148
167
|
|
|
149
168
|
## License
|
|
150
169
|
|
package/dist/domain.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SqliteStore } from './store/sqlite.js';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { PlatformDriver } from './driver/types.js';
|
|
3
|
+
import { Operation, OwnerRecord, ResourceBudget, DomainBudget, DomainLockedError, ResourceConflictError, EpochFencedError, TerminationReason, AdjudicationRecord } from './types.js';
|
|
4
|
+
export { DomainLockedError, ResourceConflictError, EpochFencedError, AdjudicationRecord };
|
|
4
5
|
export declare class ExecutionDomain {
|
|
5
6
|
readonly domainPath: string;
|
|
6
7
|
readonly domainId: string;
|
|
@@ -9,8 +10,11 @@ export declare class ExecutionDomain {
|
|
|
9
10
|
private lockFd;
|
|
10
11
|
private ownerRecord;
|
|
11
12
|
private domainBudget?;
|
|
13
|
+
private driver?;
|
|
12
14
|
private inMemoryLockedResources;
|
|
15
|
+
private inMemoryAllocatedOps;
|
|
13
16
|
private inMemoryBudgets;
|
|
17
|
+
private waitQueue;
|
|
14
18
|
private heartbeatInterval;
|
|
15
19
|
private isFenced;
|
|
16
20
|
private constructor();
|
|
@@ -34,22 +38,52 @@ export declare class ExecutionDomain {
|
|
|
34
38
|
* 刷新租约心跳,若失败则触发代际栅栏与写凭证销毁
|
|
35
39
|
*/
|
|
36
40
|
renewHeartbeat(): void;
|
|
41
|
+
private getActiveOperationIds;
|
|
42
|
+
private diagnoseConflict;
|
|
37
43
|
/**
|
|
38
44
|
* 申请占用资源(支持隔离检查与配额校验)
|
|
39
45
|
*/
|
|
40
46
|
allocateResources(operationId: string, resources: string[], waitedDurationMs?: number, budget?: ResourceBudget): void;
|
|
41
47
|
/**
|
|
42
|
-
*
|
|
48
|
+
* 具备 FIFO 排队等待与诊断的异步资源分配 (P0-5, P0-13)
|
|
43
49
|
*/
|
|
44
|
-
allocateResourcesWithWait(operationId: string, resources: string[], maxWaitMs?: number, budget?: ResourceBudget): Promise<void>;
|
|
50
|
+
allocateResourcesWithWait(operationId: string, resources: string[], maxWaitMs?: number, budget?: ResourceBudget, isCancelled?: () => boolean): Promise<void>;
|
|
45
51
|
/**
|
|
46
|
-
*
|
|
52
|
+
* 取消在等待队列中的操作 (立即唤醒以完成取消协议)
|
|
47
53
|
*/
|
|
48
|
-
|
|
54
|
+
cancelWait(operationId: string): boolean;
|
|
55
|
+
private processWaitQueue;
|
|
56
|
+
setDriver(driver: PlatformDriver): void;
|
|
57
|
+
/**
|
|
58
|
+
* 内部私有资源释放(走代际栅栏并记录 RESOURCES_RELEASED 事件,§0.2 裁决 1 / N6)
|
|
59
|
+
* @internal 仅供 supervisor、recovery engine 与 adjudicate 等内核内部组件调用
|
|
60
|
+
*/
|
|
61
|
+
internalReleaseResources(operationId: string, resources?: string[]): void;
|
|
62
|
+
/**
|
|
63
|
+
* 人工裁决协议:对 indeterminate 状态进行有审计记录的唯一收口 (ARCHITECTURE §3.6 / P0-7)
|
|
64
|
+
*/
|
|
65
|
+
adjudicate(opId: string, verdict: 'confirmed_stopped' | 'abandon_with_residuals', actor: string, note?: string): Promise<AdjudicationRecord>;
|
|
66
|
+
/**
|
|
67
|
+
* Run 完成与取消协议 (ARCHITECTURE §3.3)
|
|
68
|
+
*/
|
|
69
|
+
reportRunCancelled(runId: string, reason?: TerminationReason): void;
|
|
70
|
+
reportRunSucceeded(runId: string): void;
|
|
71
|
+
reportRunFailed(runId: string, reason?: TerminationReason): void;
|
|
49
72
|
/**
|
|
50
73
|
* 意图登记协议:先持久化意图与占用,再允许驱动调用
|
|
51
74
|
*/
|
|
52
75
|
registerOperationIntent(op: Operation): void;
|
|
76
|
+
/**
|
|
77
|
+
* 产物回收防线 (ARCHITECTURE §4.3 / N7)
|
|
78
|
+
* 只回收已终态且未被引用的产物,严格拒绝回收未终结或 indeterminate 状态的产物。
|
|
79
|
+
*/
|
|
80
|
+
pruneArtifacts(filter?: {
|
|
81
|
+
olderThanMs?: number;
|
|
82
|
+
prefix?: string;
|
|
83
|
+
}): {
|
|
84
|
+
deleted: string[];
|
|
85
|
+
retained: string[];
|
|
86
|
+
};
|
|
53
87
|
isClosed(): boolean;
|
|
54
88
|
close(): void;
|
|
55
89
|
}
|
package/dist/domain.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"domain.d.ts","sourceRoot":"","sources":["../src/domain.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WA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