@downcity/agent 1.1.113 → 1.1.118

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.
Files changed (137) hide show
  1. package/bin/agent/local/Agent.d.ts +22 -0
  2. package/bin/agent/local/Agent.d.ts.map +1 -1
  3. package/bin/agent/local/Agent.js +31 -0
  4. package/bin/agent/local/Agent.js.map +1 -1
  5. package/bin/agent/local/services/AgentAssemblyService.d.ts +4 -0
  6. package/bin/agent/local/services/AgentAssemblyService.d.ts.map +1 -1
  7. package/bin/agent/local/services/AgentAssemblyService.js +18 -2
  8. package/bin/agent/local/services/AgentAssemblyService.js.map +1 -1
  9. package/bin/agent/local/services/AgentLifecycleService.d.ts +6 -0
  10. package/bin/agent/local/services/AgentLifecycleService.d.ts.map +1 -1
  11. package/bin/agent/local/services/AgentLifecycleService.js +4 -0
  12. package/bin/agent/local/services/AgentLifecycleService.js.map +1 -1
  13. package/bin/agent/remote/RemoteAgent.d.ts +18 -1
  14. package/bin/agent/remote/RemoteAgent.d.ts.map +1 -1
  15. package/bin/agent/remote/RemoteAgent.js +19 -1
  16. package/bin/agent/remote/RemoteAgent.js.map +1 -1
  17. package/bin/agent/remote/RemoteTransport.d.ts +11 -0
  18. package/bin/agent/remote/RemoteTransport.d.ts.map +1 -1
  19. package/bin/agent/remote/transports/HttpRemoteAgentTransport.d.ts +9 -0
  20. package/bin/agent/remote/transports/HttpRemoteAgentTransport.d.ts.map +1 -1
  21. package/bin/agent/remote/transports/HttpRemoteAgentTransport.js +28 -0
  22. package/bin/agent/remote/transports/HttpRemoteAgentTransport.js.map +1 -1
  23. package/bin/agent/remote/transports/RpcRemoteAgentTransport.d.ts +8 -0
  24. package/bin/agent/remote/transports/RpcRemoteAgentTransport.d.ts.map +1 -1
  25. package/bin/agent/remote/transports/RpcRemoteAgentTransport.js +9 -0
  26. package/bin/agent/remote/transports/RpcRemoteAgentTransport.js.map +1 -1
  27. package/bin/executor/Executor.d.ts.map +1 -1
  28. package/bin/executor/Executor.js +7 -1
  29. package/bin/executor/Executor.js.map +1 -1
  30. package/bin/index.d.ts +0 -1
  31. package/bin/index.d.ts.map +1 -1
  32. package/bin/index.js +0 -1
  33. package/bin/index.js.map +1 -1
  34. package/bin/rpc/Client.d.ts +13 -0
  35. package/bin/rpc/Client.d.ts.map +1 -1
  36. package/bin/rpc/Client.js +31 -0
  37. package/bin/rpc/Client.js.map +1 -1
  38. package/bin/rpc/server/InternalHandlers.d.ts.map +1 -1
  39. package/bin/rpc/server/InternalHandlers.js +30 -0
  40. package/bin/rpc/server/InternalHandlers.js.map +1 -1
  41. package/bin/rpc/server/ServerTypes.d.ts +5 -0
  42. package/bin/rpc/server/ServerTypes.d.ts.map +1 -1
  43. package/bin/types/agent/AgentOptions.d.ts +9 -0
  44. package/bin/types/agent/AgentOptions.d.ts.map +1 -1
  45. package/bin/types/config/DowncityConfig.d.ts +2 -2
  46. package/bin/types/config/DowncityConfig.d.ts.map +1 -1
  47. package/bin/types/rpc/RpcProtocol.d.ts +25 -0
  48. package/bin/types/rpc/RpcProtocol.d.ts.map +1 -1
  49. package/package.json +4 -3
  50. package/scripts/linux-bubblewrap-sandbox.test.mjs +1 -1
  51. package/scripts/shell-sandbox-preflight.test.mjs +1 -1
  52. package/src/agent/local/Agent.ts +38 -0
  53. package/src/agent/local/services/AgentAssemblyService.ts +23 -2
  54. package/src/agent/local/services/AgentLifecycleService.ts +11 -0
  55. package/src/agent/remote/RemoteAgent.ts +26 -1
  56. package/src/agent/remote/RemoteTransport.ts +10 -0
  57. package/src/agent/remote/transports/HttpRemoteAgentTransport.ts +45 -0
  58. package/src/agent/remote/transports/RpcRemoteAgentTransport.ts +16 -0
  59. package/src/executor/Executor.ts +12 -2
  60. package/src/index.ts +0 -1
  61. package/src/rpc/Client.ts +38 -0
  62. package/src/rpc/server/InternalHandlers.ts +31 -0
  63. package/src/rpc/server/ServerTypes.ts +5 -0
  64. package/src/types/agent/AgentOptions.ts +10 -0
  65. package/src/types/config/DowncityConfig.ts +2 -2
  66. package/src/types/rpc/RpcProtocol.ts +28 -0
  67. package/tsconfig.tsbuildinfo +1 -1
  68. package/bin/executor/tools/shell/ShellToolBridge.d.ts +0 -79
  69. package/bin/executor/tools/shell/ShellToolBridge.d.ts.map +0 -1
  70. package/bin/executor/tools/shell/ShellToolBridge.js +0 -320
  71. package/bin/executor/tools/shell/ShellToolBridge.js.map +0 -1
  72. package/bin/executor/tools/shell/ShellToolDefinition.d.ts +0 -116
  73. package/bin/executor/tools/shell/ShellToolDefinition.d.ts.map +0 -1
  74. package/bin/executor/tools/shell/ShellToolDefinition.js +0 -369
  75. package/bin/executor/tools/shell/ShellToolDefinition.js.map +0 -1
  76. package/bin/executor/tools/shell/ShellToolFormatting.d.ts +0 -17
  77. package/bin/executor/tools/shell/ShellToolFormatting.d.ts.map +0 -1
  78. package/bin/executor/tools/shell/ShellToolFormatting.js +0 -36
  79. package/bin/executor/tools/shell/ShellToolFormatting.js.map +0 -1
  80. package/bin/executor/tools/shell/ShellToolSchemas.d.ts +0 -61
  81. package/bin/executor/tools/shell/ShellToolSchemas.d.ts.map +0 -1
  82. package/bin/executor/tools/shell/ShellToolSchemas.js +0 -130
  83. package/bin/executor/tools/shell/ShellToolSchemas.js.map +0 -1
  84. package/bin/executor/tools/shell/types/Shell.d.ts +0 -115
  85. package/bin/executor/tools/shell/types/Shell.d.ts.map +0 -1
  86. package/bin/executor/tools/shell/types/Shell.js +0 -9
  87. package/bin/executor/tools/shell/types/Shell.js.map +0 -1
  88. package/bin/executor/tools/shell/types/ShellPlugin.d.ts +0 -258
  89. package/bin/executor/tools/shell/types/ShellPlugin.d.ts.map +0 -1
  90. package/bin/executor/tools/shell/types/ShellPlugin.js +0 -9
  91. package/bin/executor/tools/shell/types/ShellPlugin.js.map +0 -1
  92. package/bin/sandbox/LinuxBubblewrapSandbox.d.ts +0 -19
  93. package/bin/sandbox/LinuxBubblewrapSandbox.d.ts.map +0 -1
  94. package/bin/sandbox/LinuxBubblewrapSandbox.js +0 -186
  95. package/bin/sandbox/LinuxBubblewrapSandbox.js.map +0 -1
  96. package/bin/sandbox/MacOsSeatbeltSandbox.d.ts +0 -16
  97. package/bin/sandbox/MacOsSeatbeltSandbox.d.ts.map +0 -1
  98. package/bin/sandbox/MacOsSeatbeltSandbox.js +0 -154
  99. package/bin/sandbox/MacOsSeatbeltSandbox.js.map +0 -1
  100. package/bin/sandbox/SandboxConfigResolver.d.ts +0 -37
  101. package/bin/sandbox/SandboxConfigResolver.d.ts.map +0 -1
  102. package/bin/sandbox/SandboxConfigResolver.js +0 -130
  103. package/bin/sandbox/SandboxConfigResolver.js.map +0 -1
  104. package/bin/sandbox/SandboxPreflight.d.ts +0 -73
  105. package/bin/sandbox/SandboxPreflight.d.ts.map +0 -1
  106. package/bin/sandbox/SandboxPreflight.js +0 -122
  107. package/bin/sandbox/SandboxPreflight.js.map +0 -1
  108. package/bin/sandbox/SandboxRunner.d.ts +0 -61
  109. package/bin/sandbox/SandboxRunner.d.ts.map +0 -1
  110. package/bin/sandbox/SandboxRunner.js +0 -107
  111. package/bin/sandbox/SandboxRunner.js.map +0 -1
  112. package/bin/sandbox/UnrestrictedSandbox.d.ts +0 -16
  113. package/bin/sandbox/UnrestrictedSandbox.d.ts.map +0 -1
  114. package/bin/sandbox/UnrestrictedSandbox.js +0 -39
  115. package/bin/sandbox/UnrestrictedSandbox.js.map +0 -1
  116. package/bin/sandbox/types/Sandbox.d.ts +0 -130
  117. package/bin/sandbox/types/Sandbox.d.ts.map +0 -1
  118. package/bin/sandbox/types/Sandbox.js +0 -10
  119. package/bin/sandbox/types/Sandbox.js.map +0 -1
  120. package/bin/sandbox/types/SandboxRuntime.d.ts +0 -370
  121. package/bin/sandbox/types/SandboxRuntime.d.ts.map +0 -1
  122. package/bin/sandbox/types/SandboxRuntime.js +0 -10
  123. package/bin/sandbox/types/SandboxRuntime.js.map +0 -1
  124. package/src/executor/tools/shell/ShellToolBridge.ts +0 -412
  125. package/src/executor/tools/shell/ShellToolDefinition.ts +0 -524
  126. package/src/executor/tools/shell/ShellToolFormatting.ts +0 -34
  127. package/src/executor/tools/shell/ShellToolSchemas.ts +0 -139
  128. package/src/executor/tools/shell/types/Shell.ts +0 -123
  129. package/src/executor/tools/shell/types/ShellPlugin.ts +0 -278
  130. package/src/sandbox/LinuxBubblewrapSandbox.ts +0 -222
  131. package/src/sandbox/MacOsSeatbeltSandbox.ts +0 -191
  132. package/src/sandbox/SandboxConfigResolver.ts +0 -152
  133. package/src/sandbox/SandboxPreflight.ts +0 -205
  134. package/src/sandbox/SandboxRunner.ts +0 -151
  135. package/src/sandbox/UnrestrictedSandbox.ts +0 -53
  136. package/src/sandbox/types/Sandbox.ts +0 -144
  137. package/src/sandbox/types/SandboxRuntime.ts +0 -440
@@ -1,107 +0,0 @@
1
- /**
2
- * SandboxRunner 入口。
3
- *
4
- * 关键点(中文)
5
- * - 这里不实现完整的 session/read/write 协议,只负责本地子进程创建时统一进入 agent sandbox backend。
6
- * - 当前版本接入 macOS seatbelt 与 Linux bubblewrap backend。
7
- * - 本地命令不再允许回退到宿主机普通子进程执行。
8
- */
9
- import { resolveSandboxConfig, resolveSandboxCwd } from "../sandbox/SandboxConfigResolver.js";
10
- import { spawnMacOsSeatbeltSandbox } from "../sandbox/MacOsSeatbeltSandbox.js";
11
- import { spawnLinuxBubblewrapSandbox } from "../sandbox/LinuxBubblewrapSandbox.js";
12
- import { spawnUnrestrictedSandbox } from "../sandbox/UnrestrictedSandbox.js";
13
- /**
14
- * 启动 shell 子进程。
15
- */
16
- export async function spawnShellProcess(params) {
17
- return spawnInSandbox({
18
- context: params.context,
19
- executionId: params.shellId,
20
- executionDir: params.shellDir,
21
- cmd: params.cmd,
22
- cwd: params.cwd,
23
- shellPath: params.shellPath,
24
- login: params.login,
25
- baseEnv: params.baseEnv,
26
- sandboxMode: params.sandboxMode,
27
- });
28
- }
29
- /**
30
- * 在当前 agent sandbox 中启动本地子进程。
31
- */
32
- export async function spawnInSandbox(params) {
33
- if (params.sandboxMode === "unrestricted") {
34
- return spawnUnrestrictedSandbox({
35
- executionId: params.executionId,
36
- executionDir: params.executionDir,
37
- cmd: params.cmd,
38
- cwd: params.cwd,
39
- shellPath: params.shellPath,
40
- login: params.login,
41
- baseEnv: params.baseEnv,
42
- actualCwd: params.cwd,
43
- });
44
- }
45
- const config = resolveSandboxConfig(params.context);
46
- const actualCwd = resolveSandboxCwd({
47
- rootPath: config.rootPath,
48
- requestedCwd: params.cwd,
49
- context: params.context,
50
- });
51
- const spawnParams = {
52
- executionId: params.executionId,
53
- executionDir: params.executionDir,
54
- cmd: params.cmd,
55
- cwd: params.cwd,
56
- shellPath: params.shellPath,
57
- login: params.login,
58
- baseEnv: params.baseEnv,
59
- config,
60
- actualCwd,
61
- };
62
- if (config.backend === "macos-seatbelt") {
63
- return spawnMacOsSeatbeltSandbox(spawnParams);
64
- }
65
- if (config.backend === "linux-bubblewrap") {
66
- return spawnLinuxBubblewrapSandbox(spawnParams);
67
- }
68
- throw new Error(`unsupported sandbox backend: ${config.backend}`);
69
- }
70
- /**
71
- * 执行一次 one-shot sandbox 命令并等待结束。
72
- *
73
- * 关键点(中文)
74
- * - 供 task script 这类“直接执行命令但不需要 shell session 管理”的路径复用。
75
- * - 非零退出码会直接抛错,行为与原先 `execa(..., { reject: true })` 保持一致。
76
- */
77
- export async function runSandboxCommand(params) {
78
- const spawn = await spawnInSandbox(params);
79
- const stdoutChunks = [];
80
- const stderrChunks = [];
81
- spawn.child.stdout.on("data", (chunk) => {
82
- stdoutChunks.push(String(chunk ?? ""));
83
- });
84
- spawn.child.stderr.on("data", (chunk) => {
85
- stderrChunks.push(String(chunk ?? ""));
86
- });
87
- const exitCode = await new Promise((resolve, reject) => {
88
- spawn.child.on("error", (error) => reject(error));
89
- spawn.child.on("close", (code) => resolve(typeof code === "number" ? code : -1));
90
- });
91
- const stdout = stdoutChunks.join("");
92
- const stderr = stderrChunks.join("");
93
- if (exitCode !== 0) {
94
- const message = [stdout.trim(), stderr.trim()]
95
- .filter(Boolean)
96
- .join("\n")
97
- .trim();
98
- throw new Error(message || `Sandbox command failed with exit code ${exitCode}`);
99
- }
100
- return {
101
- stdout,
102
- stderr,
103
- exitCode,
104
- spawn,
105
- };
106
- }
107
- //# sourceMappingURL=SandboxRunner.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SandboxRunner.js","sourceRoot":"","sources":["../../src/sandbox/SandboxRunner.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAC7F,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAC;AAClF,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAE5E;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,MAUvC;IACC,OAAO,cAAc,CAAC;QACpB,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,WAAW,EAAE,MAAM,CAAC,OAAO;QAC3B,YAAY,EAAE,MAAM,CAAC,QAAQ;QAC7B,GAAG,EAAE,MAAM,CAAC,GAAG;QACf,GAAG,EAAE,MAAM,CAAC,GAAG;QACf,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,WAAW,EAAE,MAAM,CAAC,WAAW;KAChC,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,MAUpC;IACC,IAAI,MAAM,CAAC,WAAW,KAAK,cAAc,EAAE,CAAC;QAC1C,OAAO,wBAAwB,CAAC;YAC9B,WAAW,EAAE,MAAM,CAAC,WAAW;YAC/B,YAAY,EAAE,MAAM,CAAC,YAAY;YACjC,GAAG,EAAE,MAAM,C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AO,IAAI,yCAAyC,QAAQ,EAAE,CAAC,CAAC;IAClF,CAAC;IAED,OAAO;QACL,MAAM;QACN,MAAM;QACN,QAAQ;QACR,KAAK;KACN,CAAC;AACJ,CAAC"}
@@ -1,16 +0,0 @@
1
- /**
2
- * Unrestricted sandbox backend。
3
- *
4
- * 关键点(中文)
5
- * - 这是 Downcity Runtime 管理的高权限执行环境,不是 agent 直接访问宿主 shell。
6
- * - 进程继承宿主可见文件系统与环境边界,但必须由上层 approval 流程批准后才能调用。
7
- * - 本 backend 只负责 spawn,不做审批、审计或风险判断。
8
- */
9
- import type { SandboxSpawnParams, SandboxSpawnResult } from "../sandbox/types/SandboxRuntime.js";
10
- /**
11
- * 在 unrestricted sandbox 中启动 shell 子进程。
12
- */
13
- export declare function spawnUnrestrictedSandbox(params: Omit<SandboxSpawnParams, "config"> & {
14
- actualCwd: string;
15
- }): Promise<SandboxSpawnResult>;
16
- //# sourceMappingURL=UnrestrictedSandbox.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"UnrestrictedSandbox.d.ts","sourceRoot":"","sources":["../../src/sandbox/UnrestrictedSandbox.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EACV,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,mCAAmC,CAAC;AAE3C;;GAEG;AACH,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,IAAI,CAAC,kBAAkB,EAAE,QAAQ,CAAC,GAAG;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,GACjE,OAAO,CAAC,kBAAkB,CAAC,CA+B7B"}
@@ -1,39 +0,0 @@
1
- /**
2
- * Unrestricted sandbox backend。
3
- *
4
- * 关键点(中文)
5
- * - 这是 Downcity Runtime 管理的高权限执行环境,不是 agent 直接访问宿主 shell。
6
- * - 进程继承宿主可见文件系统与环境边界,但必须由上层 approval 流程批准后才能调用。
7
- * - 本 backend 只负责 spawn,不做审批、审计或风险判断。
8
- */
9
- import { spawn } from "node:child_process";
10
- import fs from "fs-extra";
11
- /**
12
- * 在 unrestricted sandbox 中启动 shell 子进程。
13
- */
14
- export async function spawnUnrestrictedSandbox(params) {
15
- await fs.ensureDir(params.executionDir);
16
- const child = spawn(params.shellPath, [
17
- params.login ? "-lc" : "-c",
18
- params.cmd,
19
- ], {
20
- cwd: params.actualCwd,
21
- stdio: "pipe",
22
- env: params.baseEnv,
23
- });
24
- child.stdout.setEncoding("utf8");
25
- child.stderr.setEncoding("utf8");
26
- return {
27
- child,
28
- cwd: params.actualCwd,
29
- sandboxed: false,
30
- sandboxMode: "unrestricted",
31
- backend: "unrestricted-host",
32
- networkMode: "full",
33
- sandboxDir: "",
34
- homeDir: String(params.baseEnv.HOME || ""),
35
- tmpDir: String(params.baseEnv.TMPDIR || "/tmp"),
36
- cacheDir: String(params.baseEnv.XDG_CACHE_HOME || ""),
37
- };
38
- }
39
- //# sourceMappingURL=UnrestrictedSandbox.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"UnrestrictedSandbox.js","sourceRoot":"","sources":["../../src/sandbox/UnrestrictedSandbox.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,MAAM,UAAU,CAAC;AAM1B;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,MAAkE;IAElE,MAAM,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IAExC,MAAM,KAAK,GAAG,KAAK,CACjB,MAAM,CAAC,SAAS,EAChB;QACE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;QAC3B,MAAM,CAAC,GAAG;KACX,EACD;QACE,GAAG,EAAE,MAAM,CAAC,SAAS;QACrB,KAAK,EAAE,MAAM;QACb,GAAG,EAAE,MAAM,CAAC,OAAO;KACpB,CACF,CAAC;IAEF,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IACjC,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAEjC,OAAO;QACL,KAAK;QACL,GAAG,EAAE,MAAM,CAAC,SAAS;QACrB,SAAS,EAAE,KAAK;QAChB,WAAW,EAAE,cAAc;QAC3B,OAAO,EAAE,mBAAmB;QAC5B,WAAW,EAAE,MAAM;QACnB,UAAU,EAAE,EAAE;QACd,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,EAAE,CAAC;QAC1C,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,IAAI,MAAM,CAAC;QAC/C,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,cAAc,IAAI,EAAE,CAAC;KACtD,CAAC;AACJ,CAAC"}
@@ -1,130 +0,0 @@
1
- /**
2
- * Sandbox 共享类型定义。
3
- *
4
- * 关键点(中文)
5
- * - 这里放的是 console 模块与 agent 执行层都会使用的最小 sandbox 协议。
6
- * - 当前版本不引入复杂 profile / binding / permission 模型,只表达“命令执行边界”。
7
- * - 运行时句柄与状态化 session 类型放在 `src/sandbox/types/`。
8
- */
9
- /**
10
- * Sandbox 网络模式。
11
- *
12
- * 说明(中文)
13
- * - `off`:完全禁止网络访问。
14
- * - `restricted`:允许受限网络访问(后续实现白名单时再细化)。
15
- * - `full`:允许完整网络访问。
16
- */
17
- export type SandboxNetworkMode = "off" | "restricted" | "full";
18
- /**
19
- * Sandbox 路径访问模式。
20
- *
21
- * 说明(中文)
22
- * - `ro`:只读。
23
- * - `rw`:可读写。
24
- */
25
- export type SandboxPathAccessMode = "ro" | "rw";
26
- /**
27
- * 单条路径边界规则。
28
- */
29
- export interface SandboxPathRule {
30
- /**
31
- * 宿主机上的绝对路径。
32
- */
33
- path: string;
34
- /**
35
- * 当前路径在 sandbox 中的访问模式。
36
- */
37
- access: SandboxPathAccessMode;
38
- /**
39
- * 当前规则的说明文本。
40
- */
41
- reason?: string;
42
- }
43
- /**
44
- * sandbox 最小配置。
45
- *
46
- * 说明(中文)
47
- * - 当前只表达命令执行边界,不表达 chat 用户授权与审批流。
48
- * - `rootPath` 是默认工作根目录。
49
- * - `writablePaths` 决定哪些路径允许写入。
50
- * - `envAllowlist` 决定哪些环境变量允许导出到 sandbox。
51
- */
52
- export interface SandboxConfig {
53
- /**
54
- * 当前 sandbox 的默认根目录。
55
- */
56
- rootPath: string;
57
- /**
58
- * 允许导出的环境变量名集合。
59
- *
60
- * 说明(中文)
61
- * - 这里仅声明允许导出的 key,不在共享配置层直接保存明文值。
62
- */
63
- envAllowlist: string[];
64
- /**
65
- * 允许写入的路径集合。
66
- *
67
- * 说明(中文)
68
- * - 路径可以是绝对路径,也可以是相对 `rootPath` 的相对路径。
69
- * - 运行时会统一解析为绝对路径,并限制在 `rootPath` 范围内。
70
- */
71
- writablePaths: string[];
72
- /**
73
- * 当前 sandbox 的网络模式。
74
- */
75
- networkMode: SandboxNetworkMode;
76
- }
77
- /**
78
- * 项目级 sandbox 配置。
79
- *
80
- * 说明(中文)
81
- * - 这是 `downcity.json` 中面向用户暴露的最小配置。
82
- * - 当前版本只服务 CLI / shell 执行边界,不扩展到审批或用户权限系统。
83
- */
84
- export interface SandboxProjectConfig {
85
- /**
86
- * 允许导出的环境变量名集合。
87
- *
88
- * 说明(中文)
89
- * - 这里只声明允许导出的 key,不直接保存变量值。
90
- * - 运行时仍会注入少量必需变量,例如隔离后的 `HOME`、`TMPDIR`。
91
- */
92
- envAllowlist?: string[];
93
- /**
94
- * 允许写入的路径集合。
95
- *
96
- * 说明(中文)
97
- * - 路径可以是绝对路径,也可以是相对 `rootPath` 的相对路径。
98
- * - 当前版本会把越出 `rootPath` 的路径裁掉,避免把宿主文件系统重新暴露回去。
99
- */
100
- writablePaths?: string[];
101
- /**
102
- * 当前 sandbox 的网络模式。
103
- *
104
- * 说明(中文)
105
- * - 默认建议使用 `off`。
106
- * - `restricted` 先保留为受限网络语义占位,当前实现会按保守策略处理。
107
- */
108
- networkMode?: SandboxNetworkMode;
109
- }
110
- /**
111
- * console 模块中保存的 agent sandbox 配置记录。
112
- */
113
- export interface AgentSandboxConfigRecord {
114
- /**
115
- * 当前 agent 的稳定标识。
116
- *
117
- * 说明(中文)
118
- * - 当前建议直接使用 agent 项目根目录绝对路径。
119
- */
120
- agentId: string;
121
- /**
122
- * 当前 agent 使用的 sandbox 配置。
123
- */
124
- config: SandboxConfig;
125
- /**
126
- * 最近更新时间(ISO8601)。
127
- */
128
- updatedAt: string;
129
- }
130
- //# sourceMappingURL=Sandbox.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Sandbox.d.ts","sourceRoot":"","sources":["../../../src/sandbox/types/Sandbox.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;;;GAOG;AACH,MAAM,MAAM,kBAAkB,GAAG,KAAK,GAAG,YAAY,GAAG,MAAM,CAAC;AAE/D;;;;;;GAMG;AACH,MAAM,MAAM,qBAAqB,GAAG,IAAI,GAAG,IAAI,CAAC;AAEhD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,MAAM,EAAE,qBAAqB,CAAC;IAE9B;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;;;OAKG;IACH,YAAY,EAAE,MAAM,EAAE,CAAC;IAEvB;;;;;;OAMG;IACH,aAAa,EAAE,MAAM,EAAE,CAAC;IAExB;;OAEG;IACH,WAAW,EAAE,kBAAkB,CAAC;CACjC;AAED;;;;;;GAMG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IAExB;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IAEzB;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,kBAAkB,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC;;;;;OAKG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,MAAM,EAAE,aAAa,CAAC;IAEtB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;CACnB"}
@@ -1,10 +0,0 @@
1
- /**
2
- * Sandbox 共享类型定义。
3
- *
4
- * 关键点(中文)
5
- * - 这里放的是 console 模块与 agent 执行层都会使用的最小 sandbox 协议。
6
- * - 当前版本不引入复杂 profile / binding / permission 模型,只表达“命令执行边界”。
7
- * - 运行时句柄与状态化 session 类型放在 `src/sandbox/types/`。
8
- */
9
- export {};
10
- //# sourceMappingURL=Sandbox.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Sandbox.js","sourceRoot":"","sources":["../../../src/sandbox/types/Sandbox.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
@@ -1,370 +0,0 @@
1
- /**
2
- * SandboxRuntime 类型定义。
3
- *
4
- * 关键点(中文)
5
- * - 这里放的是 agent 执行层内部使用的最小 sandbox 运行时类型。
6
- * - 当前只围绕 agent 级 sandbox spawn 设计,不引入复杂 provider / policy / binding 对象。
7
- * - 目标是让 shell、task script 等本地执行入口都能复用同一个 agent sandbox 边界。
8
- */
9
- import type { ChildProcessWithoutNullStreams } from "node:child_process";
10
- import type { SandboxConfig } from "../../sandbox/types/Sandbox.js";
11
- import type { SandboxNetworkMode } from "../../sandbox/types/Sandbox.js";
12
- /**
13
- * 当前内置支持的 sandbox backend。
14
- */
15
- export type SandboxBackend = "macos-seatbelt" | "linux-bubblewrap" | "unrestricted-host";
16
- /**
17
- * sandbox 会话状态。
18
- *
19
- * 说明(中文)
20
- * - `shell_exec` 这类 one-shot 命令通常会很快走到终态。
21
- * - `shell_start` 则会维持一个状态化 sandbox session。
22
- */
23
- export type SandboxSessionStatus = "starting" | "running" | "completed" | "failed" | "killed" | "expired";
24
- /**
25
- * 单个 sandbox session 快照。
26
- */
27
- export interface SandboxSessionSnapshot {
28
- /**
29
- * sandbox 唯一标识。
30
- */
31
- sandboxId: string;
32
- /**
33
- * 原始命令文本。
34
- */
35
- cmd: string;
36
- /**
37
- * 当前 sandbox 实际工作目录。
38
- */
39
- cwd: string;
40
- /**
41
- * 当前 sandbox 状态。
42
- */
43
- status: SandboxSessionStatus;
44
- /**
45
- * 进程 pid。
46
- *
47
- * 说明(中文)
48
- * - 某些 backend 可能拿不到宿主 pid,这时为空。
49
- */
50
- pid?: number;
51
- /**
52
- * 创建时间戳(毫秒)。
53
- */
54
- startedAt: number;
55
- /**
56
- * 最近更新时间戳(毫秒)。
57
- */
58
- updatedAt: number;
59
- /**
60
- * 结束时间戳(毫秒)。
61
- */
62
- endedAt?: number;
63
- /**
64
- * 退出码。
65
- */
66
- exitCode?: number;
67
- /**
68
- * 最近输出预览。
69
- */
70
- lastOutputPreview?: string;
71
- /**
72
- * 累计输出字符数。
73
- */
74
- outputChars: number;
75
- /**
76
- * 版本号。
77
- *
78
- * 说明(中文)
79
- * - 任意状态或输出变化都递增,供 wait/read 增量判断使用。
80
- */
81
- version: number;
82
- }
83
- /**
84
- * sandbox 输出块。
85
- */
86
- export interface SandboxOutputChunk {
87
- /**
88
- * 当前输出块所属 sandbox 标识。
89
- */
90
- sandboxId: string;
91
- /**
92
- * 输出文本。
93
- */
94
- output: string;
95
- /**
96
- * 起始游标。
97
- */
98
- startCursor: number;
99
- /**
100
- * 结束游标。
101
- */
102
- endCursor: number;
103
- /**
104
- * 原始输出字符数。
105
- */
106
- originalChars: number;
107
- /**
108
- * 是否还有更多输出未读。
109
- */
110
- hasMoreOutput: boolean;
111
- }
112
- /**
113
- * one-shot 命令执行请求。
114
- */
115
- export interface SandboxExecRequest {
116
- /**
117
- * 最终使用的 sandbox 配置。
118
- */
119
- config: SandboxConfig;
120
- /**
121
- * 要执行的命令文本。
122
- */
123
- cmd: string;
124
- /**
125
- * 可选工作目录。
126
- */
127
- cwd?: string;
128
- /**
129
- * 可选 shell 可执行文件。
130
- */
131
- shell?: string;
132
- /**
133
- * 是否以 login shell 语义执行。
134
- */
135
- login?: boolean;
136
- }
137
- /**
138
- * 状态化 sandbox session 启动请求。
139
- */
140
- export interface SandboxStartRequest extends SandboxExecRequest {
141
- }
142
- /**
143
- * sandbox 会话读取请求。
144
- */
145
- export interface SandboxReadRequest {
146
- /**
147
- * 目标 sandbox 标识。
148
- */
149
- sandboxId: string;
150
- /**
151
- * 从哪个游标开始增量读取。
152
- */
153
- fromCursor?: number;
154
- }
155
- /**
156
- * sandbox 会话写入请求。
157
- */
158
- export interface SandboxWriteRequest {
159
- /**
160
- * 目标 sandbox 标识。
161
- */
162
- sandboxId: string;
163
- /**
164
- * 要写入 stdin 的原始文本。
165
- */
166
- chars: string;
167
- }
168
- /**
169
- * sandbox 会话等待请求。
170
- */
171
- export interface SandboxWaitRequest {
172
- /**
173
- * 目标 sandbox 标识。
174
- */
175
- sandboxId: string;
176
- /**
177
- * 仅当版本号大于该值时才立即返回。
178
- */
179
- afterVersion?: number;
180
- /**
181
- * 最长等待毫秒数。
182
- */
183
- timeoutMs?: number;
184
- }
185
- /**
186
- * sandbox 会话关闭请求。
187
- */
188
- export interface SandboxCloseRequest {
189
- /**
190
- * 目标 sandbox 标识。
191
- */
192
- sandboxId: string;
193
- /**
194
- * 是否强制关闭。
195
- */
196
- force?: boolean;
197
- }
198
- /**
199
- * `SandboxRunner` 最小接口。
200
- *
201
- * 说明(中文)
202
- * - `exec` 用于 one-shot 命令。
203
- * - `start/read/write/wait/close` 用于状态化 shell session。
204
- */
205
- export interface SandboxRunner {
206
- /**
207
- * 执行一次 one-shot 命令并等待完成。
208
- */
209
- exec(request: SandboxExecRequest): Promise<{
210
- snapshot: SandboxSessionSnapshot;
211
- chunk: SandboxOutputChunk;
212
- }>;
213
- /**
214
- * 启动一个状态化 sandbox session。
215
- */
216
- start(request: SandboxStartRequest): Promise<{
217
- snapshot: SandboxSessionSnapshot;
218
- chunk: SandboxOutputChunk;
219
- }>;
220
- /**
221
- * 读取 sandbox 输出。
222
- */
223
- read(request: SandboxReadRequest): Promise<{
224
- snapshot: SandboxSessionSnapshot;
225
- chunk: SandboxOutputChunk;
226
- }>;
227
- /**
228
- * 向 sandbox stdin 写入内容。
229
- */
230
- write(request: SandboxWriteRequest): Promise<{
231
- snapshot: SandboxSessionSnapshot;
232
- }>;
233
- /**
234
- * 等待 sandbox 状态变化。
235
- */
236
- wait(request: SandboxWaitRequest): Promise<{
237
- snapshot: SandboxSessionSnapshot;
238
- chunk: SandboxOutputChunk;
239
- }>;
240
- /**
241
- * 关闭 sandbox session。
242
- */
243
- close(request: SandboxCloseRequest): Promise<{
244
- snapshot: SandboxSessionSnapshot;
245
- }>;
246
- }
247
- /**
248
- * 运行时归一化后的 sandbox 配置。
249
- *
250
- * 说明(中文)
251
- * - 这里的路径都已经解析成绝对路径。
252
- * - 当前版本强制要求 shell 命令走 sandbox,不再允许回退到宿主机普通子进程执行。
253
- */
254
- export interface ResolvedSandboxConfig extends SandboxConfig {
255
- /**
256
- * 当前运行时选中的 backend。
257
- */
258
- backend: SandboxBackend;
259
- /**
260
- * 当前 Downcity sandbox 模式。
261
- */
262
- sandboxMode?: "safe" | "unrestricted";
263
- /**
264
- * 当前 agent 级 sandbox 的持久目录。
265
- *
266
- * 说明(中文)
267
- * - 该目录不属于某个 shellId,而属于当前 agent 项目。
268
- * - shell、task script 等所有 sandbox 子进程共享它作为 HOME/cache 根。
269
- */
270
- sandboxDir: string;
271
- /**
272
- * sandbox 子进程使用的 HOME。
273
- */
274
- homeDir: string;
275
- /**
276
- * sandbox 子进程使用的临时目录。
277
- */
278
- tmpDir: string;
279
- /**
280
- * sandbox 子进程使用的 XDG cache 目录。
281
- */
282
- cacheDir: string;
283
- }
284
- /**
285
- * 单次 shell 启动时传给 sandbox backend 的归一化参数。
286
- */
287
- export interface SandboxSpawnParams {
288
- /**
289
- * 当前执行记录标识。
290
- *
291
- * 说明(中文)
292
- * - shell plugin 传入 shellId,task script 可以传入自己的 executionId。
293
- * - 它只用于日志与诊断,不参与 sandbox HOME/cache/权限边界的计算。
294
- */
295
- executionId: string;
296
- /**
297
- * 当前执行记录目录。
298
- */
299
- executionDir: string;
300
- /**
301
- * 要执行的原始命令文本。
302
- */
303
- cmd: string;
304
- /**
305
- * 最终工作目录。
306
- */
307
- cwd: string;
308
- /**
309
- * shell 可执行文件路径。
310
- */
311
- shellPath: string;
312
- /**
313
- * 是否使用 login shell 语义。
314
- */
315
- login: boolean;
316
- /**
317
- * sandbox 生效前的基础环境变量。
318
- */
319
- baseEnv: NodeJS.ProcessEnv;
320
- /**
321
- * 当前请求最终使用的 sandbox 配置。
322
- */
323
- config: ResolvedSandboxConfig;
324
- }
325
- /**
326
- * sandbox backend 返回的进程启动结果。
327
- */
328
- export interface SandboxSpawnResult {
329
- /**
330
- * 已启动的子进程句柄。
331
- */
332
- child: ChildProcessWithoutNullStreams;
333
- /**
334
- * 当前子进程实际使用的工作目录。
335
- */
336
- cwd: string;
337
- /**
338
- * 当前进程是否实际运行在 sandbox 中。
339
- */
340
- sandboxed: boolean;
341
- /**
342
- * 当前 Downcity sandbox 模式。
343
- */
344
- sandboxMode?: "safe" | "unrestricted";
345
- /**
346
- * 当前使用的 backend 名称。
347
- */
348
- backend: SandboxBackend;
349
- /**
350
- * 当前实际采用的网络模式。
351
- */
352
- networkMode: SandboxNetworkMode;
353
- /**
354
- * 当前 agent 级 sandbox 的持久目录。
355
- */
356
- sandboxDir: string;
357
- /**
358
- * 当前子进程使用的 HOME。
359
- */
360
- homeDir: string;
361
- /**
362
- * 当前子进程使用的临时目录。
363
- */
364
- tmpDir: string;
365
- /**
366
- * 当前子进程使用的 XDG cache 目录。
367
- */
368
- cacheDir: string;
369
- }
370
- //# sourceMappingURL=SandboxRuntime.d.ts.map