@rotifer/playground 0.19.1 → 0.19.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.
@@ -0,0 +1,44 @@
1
+ import type { NativeBinding } from "./binding.js";
2
+ /**
3
+ * L0 门控的判定结果。
4
+ *
5
+ * 关键在于把两件事分开——它们的正确应对完全不同:
6
+ *
7
+ * - `violation`:门控**跑了**,并且判定这个基因不该执行。这是安全结论,
8
+ * 硬拒绝,没有逃生阀。
9
+ * - `unavailable`:门控**跑不了**(原生插件缺失、phenotype 读不出来)。
10
+ * 这是环境/数据问题,不是关于这个基因的安全结论——把它当成违规一律拒绝,
11
+ * 代价是整个 CLI 在拿不到预编译二进制的平台上彻底不可用。
12
+ */
13
+ export type L0Outcome = {
14
+ kind: "pass";
15
+ } | {
16
+ kind: "violation";
17
+ detail: string;
18
+ } | {
19
+ kind: "unavailable";
20
+ detail: string;
21
+ };
22
+ /**
23
+ * 对一个基因的 phenotype 跑 L0 门控。
24
+ *
25
+ * 三条 unavailable 分支都不抛异常:Rust 侧 `Phenotype` 的 domain / inputSchema /
26
+ * outputSchema / version 没有 serde default,是真必填;而 CLI 侧 `phenotype` 是
27
+ * `any`、解析后从不做结构校验。一个 phenotype 还没写完整的开发中基因会让 napi
28
+ * 反序列化失败并抛出去——调用点若不接,用户看到的是暴露内部路径的 Node 栈跟踪,
29
+ * TryPool 那种本该故障转移的场景还会整个进程崩掉。
30
+ */
31
+ export declare function evaluateL0(binding: NativeBinding | null, phenotype: Record<string, unknown>): L0Outcome;
32
+ /**
33
+ * 门控跑不了时,这个基因还能不能放行——取决于它是谁写的。
34
+ *
35
+ * 外部来源的基因(装过来的、带 `.cloud-manifest.json`)一律拒绝:代码不是用户
36
+ * 写的,没有沙箱也没有门控就以宿主全权限跑它,正是这次修复要堵的东西。
37
+ *
38
+ * 本地源码基因放行并警告:代码就在用户自己的项目里、可读可改,而降级路径下的
39
+ * L0 本来也只查元数据、拦不住实际行为,所以这里的安全损失有限;反过来,拒绝它
40
+ * 的代价是 `rotifer run` / `agent run` 在任何拿不到原生插件的环境里彻底不可用
41
+ * (不受支持的平台、optional dependency 装失败、发布分支 CI 的锁文件窗口)。
42
+ */
43
+ export declare function isExternallySourced(geneDir: string): boolean;
44
+ //# sourceMappingURL=l0-gate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"l0-gate.d.ts","sourceRoot":"","sources":["../../src/utils/l0-gate.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD;;;;;;;;;;GAUG;AACH,MAAM,MAAM,SAAS,GACjB;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAChB;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACrC;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAE5C;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CACxB,OAAO,EAAE,aAAa,GAAG,IAAI,EAC7B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACjC,SAAS,CAaX;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAE5D"}
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.evaluateL0 = evaluateL0;
4
+ exports.isExternallySourced = isExternallySourced;
5
+ const node_fs_1 = require("node:fs");
6
+ const node_path_1 = require("node:path");
7
+ /**
8
+ * 对一个基因的 phenotype 跑 L0 门控。
9
+ *
10
+ * 三条 unavailable 分支都不抛异常:Rust 侧 `Phenotype` 的 domain / inputSchema /
11
+ * outputSchema / version 没有 serde default,是真必填;而 CLI 侧 `phenotype` 是
12
+ * `any`、解析后从不做结构校验。一个 phenotype 还没写完整的开发中基因会让 napi
13
+ * 反序列化失败并抛出去——调用点若不接,用户看到的是暴露内部路径的 Node 栈跟踪,
14
+ * TryPool 那种本该故障转移的场景还会整个进程崩掉。
15
+ */
16
+ function evaluateL0(binding, phenotype) {
17
+ if (!binding) {
18
+ return { kind: "unavailable", detail: "native addon failed to load" };
19
+ }
20
+ try {
21
+ const { irHash: _strip, ...phenotypeForL0 } = phenotype;
22
+ const result = binding.l0Check(JSON.stringify(phenotypeForL0));
23
+ return result.passed
24
+ ? { kind: "pass" }
25
+ : { kind: "violation", detail: result.violations.join("; ") };
26
+ }
27
+ catch (err) {
28
+ return { kind: "unavailable", detail: `phenotype unreadable (${err?.message ?? err})` };
29
+ }
30
+ }
31
+ /**
32
+ * 门控跑不了时,这个基因还能不能放行——取决于它是谁写的。
33
+ *
34
+ * 外部来源的基因(装过来的、带 `.cloud-manifest.json`)一律拒绝:代码不是用户
35
+ * 写的,没有沙箱也没有门控就以宿主全权限跑它,正是这次修复要堵的东西。
36
+ *
37
+ * 本地源码基因放行并警告:代码就在用户自己的项目里、可读可改,而降级路径下的
38
+ * L0 本来也只查元数据、拦不住实际行为,所以这里的安全损失有限;反过来,拒绝它
39
+ * 的代价是 `rotifer run` / `agent run` 在任何拿不到原生插件的环境里彻底不可用
40
+ * (不受支持的平台、optional dependency 装失败、发布分支 CI 的锁文件窗口)。
41
+ */
42
+ function isExternallySourced(geneDir) {
43
+ return (0, node_fs_1.existsSync)((0, node_path_1.join)(geneDir, ".cloud-manifest.json"));
44
+ }
45
+ //# sourceMappingURL=l0-gate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"l0-gate.js","sourceRoot":"","sources":["../../src/utils/l0-gate.ts"],"names":[],"mappings":";;AA6BA,gCAgBC;AAaD,kDAEC;AA5DD,qCAAqC;AACrC,yCAAiC;AAmBjC;;;;;;;;GAQG;AACH,SAAgB,UAAU,CACxB,OAA6B,EAC7B,SAAkC;IAElC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,6BAA6B,EAAE,CAAC;IACxE,CAAC;IACD,IAAI,CAAC;QACH,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,cAAc,EAAE,GAAG,SAAS,CAAC;QACxD,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,CAAC;QAC/D,OAAO,MAAM,CAAC,MAAM;YAClB,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE;YAClB,CAAC,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;IAClE,CAAC;IAAC,OAAO,GAAQ,EAAE,CAAC;QAClB,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,yBAAyB,GAAG,EAAE,OAAO,IAAI,GAAG,GAAG,EAAE,CAAC;IAC1F,CAAC;AACH,CAAC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,mBAAmB,CAAC,OAAe;IACjD,OAAO,IAAA,oBAAU,EAAC,IAAA,gBAAI,EAAC,OAAO,EAAE,sBAAsB,CAAC,CAAC,CAAC;AAC3D,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rotifer/playground",
3
- "version": "0.19.1",
3
+ "version": "0.19.2",
4
4
  "description": "Rotifer Protocol Playground — local development environment for gene development, Arena competition, and protocol simulation",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Rotifer Protocol Contributors",
@@ -87,10 +87,10 @@
87
87
  },
88
88
  "optionalDependencies": {
89
89
  "@rolldown/binding-linux-x64-gnu": "1.1.1",
90
- "@rotifer/playground-darwin-arm64": "0.19.1",
91
- "@rotifer/playground-darwin-x64": "0.19.1",
92
- "@rotifer/playground-linux-x64-gnu": "0.19.1",
93
- "@rotifer/playground-win32-x64-msvc": "0.19.1"
90
+ "@rotifer/playground-darwin-arm64": "0.19.2",
91
+ "@rotifer/playground-darwin-x64": "0.19.2",
92
+ "@rotifer/playground-linux-x64-gnu": "0.19.2",
93
+ "@rotifer/playground-win32-x64-msvc": "0.19.2"
94
94
  },
95
95
  "engines": {
96
96
  "node": ">=20.0.0"