@downcity/plugins 1.0.64 → 1.0.71

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 (75) hide show
  1. package/bin/BuiltinPlugins.d.ts +0 -5
  2. package/bin/BuiltinPlugins.d.ts.map +1 -1
  3. package/bin/BuiltinPlugins.js +1 -5
  4. package/bin/BuiltinPlugins.js.map +1 -1
  5. package/bin/index.d.ts +0 -2
  6. package/bin/index.d.ts.map +1 -1
  7. package/bin/index.js +0 -1
  8. package/bin/index.js.map +1 -1
  9. package/bin/task/runtime/TaskRunnerRound.d.ts.map +1 -1
  10. package/bin/task/runtime/TaskRunnerRound.js +7 -2
  11. package/bin/task/runtime/TaskRunnerRound.js.map +1 -1
  12. package/bin/task/runtime/TaskRunnerSession.d.ts.map +1 -1
  13. package/bin/task/runtime/TaskRunnerSession.js +10 -3
  14. package/bin/task/runtime/TaskRunnerSession.js.map +1 -1
  15. package/package.json +4 -3
  16. package/scripts/unrestricted-sandbox-approval.test.mjs +184 -5
  17. package/src/BuiltinPlugins.ts +0 -9
  18. package/src/index.ts +0 -5
  19. package/src/task/runtime/TaskRunnerRound.ts +15 -5
  20. package/src/task/runtime/TaskRunnerSession.ts +11 -4
  21. package/bin/shell/Index.d.ts +0 -9
  22. package/bin/shell/Index.d.ts.map +0 -1
  23. package/bin/shell/Index.js +0 -9
  24. package/bin/shell/Index.js.map +0 -1
  25. package/bin/shell/ShellPlugin.d.ts +0 -65
  26. package/bin/shell/ShellPlugin.d.ts.map +0 -1
  27. package/bin/shell/ShellPlugin.js +0 -175
  28. package/bin/shell/ShellPlugin.js.map +0 -1
  29. package/bin/shell/ShellRuntimeTypes.d.ts +0 -145
  30. package/bin/shell/ShellRuntimeTypes.d.ts.map +0 -1
  31. package/bin/shell/ShellRuntimeTypes.js +0 -10
  32. package/bin/shell/ShellRuntimeTypes.js.map +0 -1
  33. package/bin/shell/runtime/Paths.d.ts +0 -12
  34. package/bin/shell/runtime/Paths.d.ts.map +0 -1
  35. package/bin/shell/runtime/Paths.js +0 -21
  36. package/bin/shell/runtime/Paths.js.map +0 -1
  37. package/bin/shell/runtime/ShellActionResponse.d.ts +0 -52
  38. package/bin/shell/runtime/ShellActionResponse.d.ts.map +0 -1
  39. package/bin/shell/runtime/ShellActionResponse.js +0 -73
  40. package/bin/shell/runtime/ShellActionResponse.js.map +0 -1
  41. package/bin/shell/runtime/ShellActionRuntime.d.ts +0 -70
  42. package/bin/shell/runtime/ShellActionRuntime.d.ts.map +0 -1
  43. package/bin/shell/runtime/ShellActionRuntime.js +0 -587
  44. package/bin/shell/runtime/ShellActionRuntime.js.map +0 -1
  45. package/bin/shell/runtime/ShellActionRuntimeSupport.d.ts +0 -88
  46. package/bin/shell/runtime/ShellActionRuntimeSupport.d.ts.map +0 -1
  47. package/bin/shell/runtime/ShellActionRuntimeSupport.js +0 -353
  48. package/bin/shell/runtime/ShellActionRuntimeSupport.js.map +0 -1
  49. package/bin/shell/runtime/ShellApprovalRuntime.d.ts +0 -57
  50. package/bin/shell/runtime/ShellApprovalRuntime.d.ts.map +0 -1
  51. package/bin/shell/runtime/ShellApprovalRuntime.js +0 -182
  52. package/bin/shell/runtime/ShellApprovalRuntime.js.map +0 -1
  53. package/bin/shell/runtime/ShellProcessEvents.d.ts +0 -22
  54. package/bin/shell/runtime/ShellProcessEvents.d.ts.map +0 -1
  55. package/bin/shell/runtime/ShellProcessEvents.js +0 -41
  56. package/bin/shell/runtime/ShellProcessEvents.js.map +0 -1
  57. package/bin/shell/runtime/ShellRuntimeEnvironment.d.ts +0 -21
  58. package/bin/shell/runtime/ShellRuntimeEnvironment.d.ts.map +0 -1
  59. package/bin/shell/runtime/ShellRuntimeEnvironment.js +0 -70
  60. package/bin/shell/runtime/ShellRuntimeEnvironment.js.map +0 -1
  61. package/bin/shell/types/ShellPluginOptions.d.ts +0 -103
  62. package/bin/shell/types/ShellPluginOptions.d.ts.map +0 -1
  63. package/bin/shell/types/ShellPluginOptions.js +0 -10
  64. package/bin/shell/types/ShellPluginOptions.js.map +0 -1
  65. package/src/shell/Index.ts +0 -9
  66. package/src/shell/ShellPlugin.ts +0 -239
  67. package/src/shell/ShellRuntimeTypes.ts +0 -152
  68. package/src/shell/runtime/Paths.ts +0 -28
  69. package/src/shell/runtime/ShellActionResponse.ts +0 -135
  70. package/src/shell/runtime/ShellActionRuntime.ts +0 -728
  71. package/src/shell/runtime/ShellActionRuntimeSupport.ts +0 -477
  72. package/src/shell/runtime/ShellApprovalRuntime.ts +0 -236
  73. package/src/shell/runtime/ShellProcessEvents.ts +0 -65
  74. package/src/shell/runtime/ShellRuntimeEnvironment.ts +0 -71
  75. package/src/shell/types/ShellPluginOptions.ts +0 -122
@@ -1,65 +0,0 @@
1
- /**
2
- * Shell 子进程事件绑定辅助。
3
- *
4
- * 关键点(中文)
5
- * - 集中处理 stdout/stderr 追加、process error 与 close 事件。
6
- * - close 到达时先等待输出写入链 drain,再统一进入终态收口,避免尾部输出丢读。
7
- */
8
-
9
- import type { ShellPluginState, ShellSessionRuntimeState } from "@/shell/ShellRuntimeTypes.js";
10
- import {
11
- appendSessionOutput,
12
- finalizeExit,
13
- } from "./ShellActionRuntimeSupport.js";
14
-
15
- async function finalizeExitAfterOutputDrain(
16
- state: ShellPluginState,
17
- session: ShellSessionRuntimeState,
18
- exitCode: number,
19
- ): Promise<void> {
20
- // 关键点(中文)
21
- // - `close` 事件到达时,stdout / stderr 的异步 append 链可能刚刚开始收尾。
22
- // - 这里先让出一个事件循环 tick,再等待当前 writeChain,可显著降低“终态已到但尾部输出尚未可读”的竞态。
23
- await new Promise<void>((resolve) => {
24
- const timer = setImmediate(resolve);
25
- if (typeof timer.unref === "function") timer.unref();
26
- });
27
- await session.writeChain.catch(() => undefined);
28
- await finalizeExit(state, session, exitCode);
29
- }
30
-
31
- /**
32
- * 绑定 shell 子进程事件。
33
- */
34
- export function attachShellProcessEventHandlers(params: {
35
- /**
36
- * 当前 shell plugin runtime 状态。
37
- */
38
- state: ShellPluginState;
39
- /**
40
- * 当前 shell runtime session。
41
- */
42
- session: ShellSessionRuntimeState;
43
- }): void {
44
- const { state, session } = params;
45
- const { child } = session;
46
- child.stdout.on("data", (chunk: string | Buffer) => {
47
- void appendSessionOutput(state, session, String(chunk ?? "")).catch(() => undefined);
48
- });
49
- child.stderr.on("data", (chunk: string | Buffer) => {
50
- void appendSessionOutput(state, session, String(chunk ?? "")).catch(() => undefined);
51
- });
52
- child.on("error", (error: Error) => {
53
- void appendSessionOutput(state, session, `\n[process error] ${String(error)}\n`).catch(
54
- () => undefined,
55
- );
56
- void finalizeExitAfterOutputDrain(state, session, -1).catch(() => undefined);
57
- });
58
- child.on("close", (code: number | null) => {
59
- void finalizeExitAfterOutputDrain(
60
- state,
61
- session,
62
- typeof code === "number" ? code : -1,
63
- ).catch(() => undefined);
64
- });
65
- }
@@ -1,71 +0,0 @@
1
- /**
2
- * Shell action 运行环境解析辅助。
3
- *
4
- * 关键点(中文)
5
- * - 集中处理 shell 子进程 cwd、env 与 owner context 的解析。
6
- * - 这里只做输入归一化,不持有 shell session 状态。
7
- */
8
-
9
- import path from "node:path";
10
- import type { AgentContext } from "@downcity/agent/internal/types/runtime/agent/AgentContext.js";
11
- import { getSessionRunContext } from "@downcity/agent/internal/executor/SessionRunScope.js";
12
-
13
- function stripShellSecretEnv(env: NodeJS.ProcessEnv): void {
14
- delete env.DC_AUTH_TOKEN;
15
- delete env.DC_AGENT_TOKEN;
16
- }
17
-
18
- /**
19
- * 构造 shell 子进程环境变量。
20
- */
21
- export function buildShellEnv(context: AgentContext): NodeJS.ProcessEnv {
22
- const env: NodeJS.ProcessEnv = { ...process.env };
23
-
24
- // 关键点(中文)
25
- // - AgentContext.env 现在就是宿主已经整理好的最终 env 视图。
26
- // - shell 只消费这一份显式上下文,避免再次引入 platform/global env 隐式来源。
27
- for (const [key, value] of Object.entries(context.env || {})) {
28
- const normalizedKey = String(key || "").trim();
29
- const normalizedValue = String(value || "").trim();
30
- if (!normalizedKey || !normalizedValue) continue;
31
- env[normalizedKey] = normalizedValue;
32
- }
33
-
34
- const run_context = getSessionRunContext();
35
- const sessionId = String(run_context?.sessionId || "").trim();
36
- const agentPath = String(context.rootPath || "").trim();
37
- const configuredAgentId = String(context.config?.id || "").trim();
38
- const agentId = configuredAgentId || (agentPath ? path.basename(agentPath) : "");
39
-
40
- // 关键点(中文)
41
- // - agent 自己在 shell 里执行 `town <service> ...` 时,也需要显式知道“当前 agent 是谁”。
42
- // - 否则 service CLI 会退回到当前终端 cwd / registry 猜测,在多 agent 或外部工作目录下
43
- // 很容易把请求发到错误项目,最终误报 “Agent runtime 没启动”。
44
- if (agentPath) env.DC_AGENT_PATH = agentPath;
45
- if (agentId) env.DC_AGENT_ID = agentId;
46
- if (sessionId) env.DC_SESSION_ID = sessionId;
47
- if (process.env.DC_CITY_HOST) env.DC_CITY_HOST = process.env.DC_CITY_HOST;
48
- if (process.env.DC_CITY_PORT) env.DC_CITY_PORT = process.env.DC_CITY_PORT;
49
- stripShellSecretEnv(env);
50
-
51
- return env;
52
- }
53
-
54
- /**
55
- * 解析 shell 执行目录。
56
- */
57
- export function resolveShellCwd(context: AgentContext, cwd?: string): string {
58
- const raw = String(cwd || "").trim();
59
- if (!raw) return context.rootPath;
60
- return path.isAbsolute(raw) ? raw : path.resolve(context.rootPath, raw);
61
- }
62
-
63
- /**
64
- * 推断 shell 所属的 owner context。
65
- */
66
- export function resolveOwnerContextId(explicit?: string): string | undefined {
67
- const fromInput = String(explicit || "").trim();
68
- if (fromInput) return fromInput;
69
- const fromRequest = String(getSessionRunContext()?.sessionId || "").trim();
70
- return fromRequest || undefined;
71
- }
@@ -1,122 +0,0 @@
1
- /**
2
- * ShellPlugin constructor 参数类型。
3
- *
4
- * 关键点(中文)
5
- * - 所有字段都是可选 runtime 调参。
6
- * - 不传参数时保持 ShellPlugin 既有硬编码默认行为。
7
- * - 这些参数只影响 shell plugin runtime,不改变 sandbox 权限模型。
8
- */
9
-
10
- /**
11
- * ShellPlugin 可选运行参数。
12
- */
13
- export interface ShellPluginOptions {
14
- /**
15
- * 最大 in-memory shell session 数量。
16
- *
17
- * 超过该数量时,runtime 会优先清理已经结束的旧 session;如果仍然超限则拒绝启动新 shell。
18
- */
19
- maxActiveShells?: number;
20
-
21
- /**
22
- * 终态 shell session 在内存中保留多久后自动清理,单位毫秒。
23
- */
24
- cleanupDelayMs?: number;
25
-
26
- /**
27
- * 单个 shell session 在内存中保留的最大输出字符数。
28
- *
29
- * 超出的历史输出仍会写入持久化输出文件,但内存快照只保留尾部内容。
30
- */
31
- maxInMemoryOutputChars?: number;
32
-
33
- /**
34
- * shell 输出预览保留的最大字符数。
35
- */
36
- outputPreviewChars?: number;
37
-
38
- /**
39
- * wait/timeout 参数允许的最小毫秒数。
40
- */
41
- minWaitMs?: number;
42
-
43
- /**
44
- * wait/timeout 参数允许的最大毫秒数。
45
- */
46
- maxWaitMs?: number;
47
-
48
- /**
49
- * `shell.start` 默认内联等待时间,单位毫秒。
50
- */
51
- defaultInlineWaitMs?: number;
52
-
53
- /**
54
- * `shell.wait` 默认等待超时,单位毫秒。
55
- */
56
- defaultWaitTimeoutMs?: number;
57
-
58
- /**
59
- * `shell.exec` 默认总超时,单位毫秒。
60
- */
61
- defaultExecTimeoutMs?: number;
62
-
63
- /**
64
- * unrestricted sandbox 审批默认超时时间,单位毫秒。
65
- */
66
- defaultApprovalTimeoutMs?: number;
67
- }
68
-
69
- /**
70
- * ShellPlugin 归一化后的运行参数。
71
- */
72
- export interface ResolvedShellPluginOptions {
73
- /**
74
- * 最大 in-memory shell session 数量。
75
- */
76
- maxActiveShells: number;
77
-
78
- /**
79
- * 终态 shell session 在内存中保留多久后自动清理,单位毫秒。
80
- */
81
- cleanupDelayMs: number;
82
-
83
- /**
84
- * 单个 shell session 在内存中保留的最大输出字符数。
85
- */
86
- maxInMemoryOutputChars: number;
87
-
88
- /**
89
- * shell 输出预览保留的最大字符数。
90
- */
91
- outputPreviewChars: number;
92
-
93
- /**
94
- * wait/timeout 参数允许的最小毫秒数。
95
- */
96
- minWaitMs: number;
97
-
98
- /**
99
- * wait/timeout 参数允许的最大毫秒数。
100
- */
101
- maxWaitMs: number;
102
-
103
- /**
104
- * `shell.start` 默认内联等待时间,单位毫秒。
105
- */
106
- defaultInlineWaitMs: number;
107
-
108
- /**
109
- * `shell.wait` 默认等待超时,单位毫秒。
110
- */
111
- defaultWaitTimeoutMs: number;
112
-
113
- /**
114
- * `shell.exec` 默认总超时,单位毫秒。
115
- */
116
- defaultExecTimeoutMs: number;
117
-
118
- /**
119
- * unrestricted sandbox 审批默认超时时间,单位毫秒。
120
- */
121
- defaultApprovalTimeoutMs: number;
122
- }